Commit 66520f7a authored by Jonathon Duerig's avatar Jonathon Duerig

Add status ajax call to get the health status of all CL and federated clusters.

parent fd9bd976
......@@ -23,6 +23,10 @@
#
#
# Set this variable when fetching health status of portal
# aggregates instead of using them.
$PORTAL_HEALTH = 0;
#
# This needs to go into the DB.
#
......@@ -184,19 +188,24 @@ class Aggregate
# Return the list of allowed aggregates based on the portal in use.
#
function DefaultAggregateList() {
global $PORTAL_GENESIS;
global $PORTAL_GENESIS, $PORTAL_HEALTH;
$genesis = $PORTAL_GENESIS;
if ($PORTAL_HEALTH)
{
$genesis = "cloudlab";
}
$am_array = array();
$query_result =
DBQueryFatal("select urn,name,adminonly from apt_aggregates ".
"where disabled=0 and ".
" FIND_IN_SET('$PORTAL_GENESIS', portals)");
" FIND_IN_SET('$genesis', portals)");
while ($row = mysql_fetch_array($query_result)) {
$urn = $row["urn"];
$adminonly = $row["adminonly"];
if ($adminonly && !(ISADMIN() || STUDLY())) {
if ($adminonly && !(ISADMIN() || STUDLY() || $PORTAL_HEALTH)) {
continue;
}
if (! ($aggregate = Aggregate::Lookup($urn))) {
......
......@@ -900,4 +900,51 @@ class ExtensionInfo
}
}
# $amlist, $fedlist, and $status are all output arrays
function CalculateAggregateStatus(&$amlist, &$fedlist, &$status) {
$am_array = Instance::DefaultAggregateList();
while (list($ignore, $aggregate) = each($am_array)) {
$urn = $aggregate->urn();
$am = $aggregate->name();
$amlist[$urn] = $am;
#
# We need to mark federated sites for the cluster dropdown.
#
if ($aggregate->isfederate()) {
$fedlist[] = "'" . $aggregate->name() . "'";
}
#
# generate the status blob.
#
if ($aggregate->status()) {
$status[$urn] = array(
"rawPCsAvailable" => $aggregate->pfree(),
"rawPCsTotal" => $aggregate->pcount(),
"VMsAvailable" => "0",
"VMsTotal" => $aggregate->vcount(),
"health" => ($aggregate->status() == "up" ? 100 :
($aggregate->status() == "down" ?
0 : 50)),
"status" => ($aggregate->status() != "down" ?
"SUCCESS" : "FAILED"));
}
}
}
function SpitAggregateStatus() {
$amlist = array();
$fedlist = array();
$status = array();
CalculateAggregateStatus($amlist, $fedlist, $status);
echo "<script type='text/plain' id='amlist-json'>\n";
echo htmlentities(json_encode($amlist));
echo "</script>\n";
echo "<script type='text/plain' id='amstatus-json'>\n";
echo htmlentities(json_encode($status));
echo "</script>\n";
echo "<script type='text/javascript'>\n";
echo " window.FEDERATEDLIST = [". implode(",", $fedlist) . "];\n";
echo "</script>\n";
}
?>
......@@ -124,7 +124,6 @@ else {
$profile_default) = explode(',', $portal_default_profile);
}
$profile_array = array();
$am_array = Instance::DefaultAggregateList();
#
# if using the super secret URL, make sure the profile exists, and
......@@ -317,12 +316,9 @@ $profile_array = $tmp_array;
function SPITFORM($formfields, $newuser, $errors)
{
global $TBBASE, $APTMAIL, $ISAPT, $ISCLOUD, $ISPNET, $PORTAL_NAME;
global $profile_array, $this_user, $profilename, $profile, $am_array;
global $profile_array, $this_user, $profilename, $profile;
global $projlist, $skipfirststep, $TBMAINSITE;
$amlist = array();
$fedlist = array();
$status = array();
$showabout = ($ISAPT && !$this_user ? 1 : 0);
$registered = (isset($this_user) ? "true" : "false");
# We use webonly to mark users that have no project membership
......@@ -380,42 +376,7 @@ function SPITFORM($formfields, $newuser, $errors)
# And AM list if that is allowed.
#
if (isset($this_user) && !$this_user->webonly() && !$ISAPT && !$ISPNET) {
$am_options = "";
while (list($ignore, $aggregate) = each($am_array)) {
$urn = $aggregate->urn();
$am = $aggregate->name();
$amlist[$urn] = $am;
#
# We need to mark federated sites for the cluster dropdown.
#
if ($aggregate->isfederate()) {
$fedlist[] = "'" . $aggregate->name() . "'";
}
#
# generate the status blob.
#
if ($aggregate->status()) {
$status[$urn] = array(
"rawPCsAvailable" => $aggregate->pfree(),
"rawPCsTotal" => $aggregate->pcount(),
"VMsAvailable" => "0",
"VMsTotal" => $aggregate->vcount(),
"health" => ($aggregate->status() == "up" ? 100 :
($aggregate->status() == "down" ?
0 : 50)),
"status" => ($aggregate->status() != "down" ?
"SUCCESS" : "FAILED"));
}
}
echo "<script type='text/plain' id='amlist-json'>\n";
echo htmlentities(json_encode($amlist));
echo "</script>\n";
echo "<script type='text/plain' id='amstatus-json'>\n";
echo htmlentities(json_encode($status));
echo "</script>\n";
echo "<script type='text/javascript'>\n";
echo " window.FEDERATEDLIST = [". implode(",", $fedlist) . "];\n";
echo "</script>\n";
SpitAggregateStatus();
}
SpitOopsModal("oops");
echo "<script type='text/javascript'>\n";
......
......@@ -163,7 +163,9 @@ $routing = array("myprofiles" =>
"MaxExtension" =>
"Do_MaxExtension",
"dismissExtensionDenied" =>
"Do_DismissExtensionDenied")),
"Do_DismissExtensionDenied",
"GetHealthStatus" =>
"Do_GetHealthStatus")),
"approveuser" =>
array("file" => "approveuser.ajax",
"guest" => false,
......
......@@ -1919,6 +1919,19 @@ function Do_MaxExtension()
SPITAJAX_RESPONSE($blob);
}
# Fetch overall cluster aggregate health status.
# Can be done without logging in (for front page status).
function Do_GetHealthStatus()
{
global $ajax_args, $PORTAL_HEALTH;
$amlist = array();
$fedlist = array();
$status = array();
$PORTAL_HEALTH = 1;
CalculateAggregateStatus($amlist, $fedlist, $status);
SPITAJAX_RESPONSE($status);
}
# Local Variables:
# mode:php
# End:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment