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 @@ ...@@ -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. # This needs to go into the DB.
# #
...@@ -184,19 +188,24 @@ class Aggregate ...@@ -184,19 +188,24 @@ class Aggregate
# Return the list of allowed aggregates based on the portal in use. # Return the list of allowed aggregates based on the portal in use.
# #
function DefaultAggregateList() { function DefaultAggregateList() {
global $PORTAL_GENESIS; global $PORTAL_GENESIS, $PORTAL_HEALTH;
$genesis = $PORTAL_GENESIS;
if ($PORTAL_HEALTH)
{
$genesis = "cloudlab";
}
$am_array = array(); $am_array = array();
$query_result = $query_result =
DBQueryFatal("select urn,name,adminonly from apt_aggregates ". DBQueryFatal("select urn,name,adminonly from apt_aggregates ".
"where disabled=0 and ". "where disabled=0 and ".
" FIND_IN_SET('$PORTAL_GENESIS', portals)"); " FIND_IN_SET('$genesis', portals)");
while ($row = mysql_fetch_array($query_result)) { while ($row = mysql_fetch_array($query_result)) {
$urn = $row["urn"]; $urn = $row["urn"];
$adminonly = $row["adminonly"]; $adminonly = $row["adminonly"];
if ($adminonly && !(ISADMIN() || STUDLY())) { if ($adminonly && !(ISADMIN() || STUDLY() || $PORTAL_HEALTH)) {
continue; continue;
} }
if (! ($aggregate = Aggregate::Lookup($urn))) { if (! ($aggregate = Aggregate::Lookup($urn))) {
......
...@@ -900,4 +900,51 @@ class ExtensionInfo ...@@ -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 { ...@@ -124,7 +124,6 @@ else {
$profile_default) = explode(',', $portal_default_profile); $profile_default) = explode(',', $portal_default_profile);
} }
$profile_array = array(); $profile_array = array();
$am_array = Instance::DefaultAggregateList();
# #
# if using the super secret URL, make sure the profile exists, and # if using the super secret URL, make sure the profile exists, and
...@@ -317,12 +316,9 @@ $profile_array = $tmp_array; ...@@ -317,12 +316,9 @@ $profile_array = $tmp_array;
function SPITFORM($formfields, $newuser, $errors) function SPITFORM($formfields, $newuser, $errors)
{ {
global $TBBASE, $APTMAIL, $ISAPT, $ISCLOUD, $ISPNET, $PORTAL_NAME; 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; global $projlist, $skipfirststep, $TBMAINSITE;
$amlist = array();
$fedlist = array();
$status = array();
$showabout = ($ISAPT && !$this_user ? 1 : 0); $showabout = ($ISAPT && !$this_user ? 1 : 0);
$registered = (isset($this_user) ? "true" : "false"); $registered = (isset($this_user) ? "true" : "false");
# We use webonly to mark users that have no project membership # We use webonly to mark users that have no project membership
...@@ -380,42 +376,7 @@ function SPITFORM($formfields, $newuser, $errors) ...@@ -380,42 +376,7 @@ function SPITFORM($formfields, $newuser, $errors)
# And AM list if that is allowed. # And AM list if that is allowed.
# #
if (isset($this_user) && !$this_user->webonly() && !$ISAPT && !$ISPNET) { if (isset($this_user) && !$this_user->webonly() && !$ISAPT && !$ISPNET) {
$am_options = ""; SpitAggregateStatus();
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";
} }
SpitOopsModal("oops"); SpitOopsModal("oops");
echo "<script type='text/javascript'>\n"; echo "<script type='text/javascript'>\n";
......
...@@ -163,7 +163,9 @@ $routing = array("myprofiles" => ...@@ -163,7 +163,9 @@ $routing = array("myprofiles" =>
"MaxExtension" => "MaxExtension" =>
"Do_MaxExtension", "Do_MaxExtension",
"dismissExtensionDenied" => "dismissExtensionDenied" =>
"Do_DismissExtensionDenied")), "Do_DismissExtensionDenied",
"GetHealthStatus" =>
"Do_GetHealthStatus")),
"approveuser" => "approveuser" =>
array("file" => "approveuser.ajax", array("file" => "approveuser.ajax",
"guest" => false, "guest" => false,
......
...@@ -1919,6 +1919,19 @@ function Do_MaxExtension() ...@@ -1919,6 +1919,19 @@ function Do_MaxExtension()
SPITAJAX_RESPONSE($blob); 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: # Local Variables:
# mode:php # mode:php
# End: # 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