Commit 9c966b49 authored by Leigh B Stoller's avatar Leigh B Stoller

Add target cluster argument to page, use a webtask, show RPC errors

and a spinner while waiting.
parent 0fb706ab
<?php <?php
# #
# Copyright (c) 2000-2017 University of Utah and the Flux Group. # Copyright (c) 2000-2018 University of Utah and the Flux Group.
# #
# {{{EMULAB-LICENSE # {{{EMULAB-LICENSE
# #
...@@ -22,9 +22,11 @@ ...@@ -22,9 +22,11 @@
# }}} # }}}
# #
chdir(".."); chdir("..");
include_once("webtask.php");
include_once("geni_defs.php"); include_once("geni_defs.php");
chdir("apt"); chdir("apt");
include_once("instance_defs.php"); include_once("instance_defs.php");
include_once("aggregate_defs.php");
# #
# Server side of getting dashboard stats. # Server side of getting dashboard stats.
...@@ -34,6 +36,7 @@ function Do_GetStatus() ...@@ -34,6 +36,7 @@ function Do_GetStatus()
global $ajax_args, $this_user, $geni_response_codes, $urn_mapping; global $ajax_args, $this_user, $geni_response_codes, $urn_mapping;
global $TBSUEXEC_PATH, $TBBASE, $TB_PROJECT_CREATEEXPT, $OURDOMAIN; global $TBSUEXEC_PATH, $TBBASE, $TB_PROJECT_CREATEEXPT, $OURDOMAIN;
global $TB_PROJECT_READINFO, $DEFAULT_AGGREGATE_URN; global $TB_PROJECT_READINFO, $DEFAULT_AGGREGATE_URN;
global $TBADMINGROUP;
$isadmin = 0; $isadmin = 0;
$autoextend_maxage = TBGetSiteVar("aptui/autoextend_maxage"); $autoextend_maxage = TBGetSiteVar("aptui/autoextend_maxage");
...@@ -49,27 +52,41 @@ function Do_GetStatus() ...@@ -49,27 +52,41 @@ function Do_GetStatus()
SPITAJAX_ERROR(1, "Not a valid cluster URN"); SPITAJAX_ERROR(1, "Not a valid cluster URN");
return; return;
} }
$aggregate = Aggregate::Lookup($cluster);
if (!$aggregate) {
SPITAJAX_ERROR(1, "No such cluster");
return;
}
if ($aggregate->adminonly() && !$isadmin) {
SPITAJAX_ERROR(1, "No permission to view cluster");
return;
}
$isus = ($cluster == $DEFAULT_AGGREGATE_URN ? 1 : 0); $isus = ($cluster == $DEFAULT_AGGREGATE_URN ? 1 : 0);
$cluster = escapeshellarg($cluster); $cluster = escapeshellarg($cluster);
$fp = popen("$TBSUEXEC_PATH elabman tbadmin ". $webtask = WebTask::CreateAnonymous();
"webportal_xmlrpc -a $cluster InUse", "r"); $webtask_id = $webtask->task_id();
$string = "";
while (!feof($fp)) { $retval = SUEXEC("elabman", $TBADMINGROUP,
$string .= fgets($fp, 1024); "webportal_xmlrpc -t $webtask_id -a $cluster InUse",
} SUEXEC_ACTION_IGNORE);
pclose($fp); $webtask->Refresh();
$results = json_decode($string);
if ($retval != 0) {
if (gettype($results) == "object") { if (!$webtask->exited() || $retval < 0) {
$inuse = $results->details; SUEXECERROR(SUEXEC_ACTION_CONTINUE);
if (property_exists($results, "typeinfo")) { SPITAJAX_ERROR(-1, "Internal error getting info from cluster");
$typeinfo = $results->typeinfo;
} }
else {
SPITAJAX_ERROR(1, "Unable to get info at ".
"time: ". $webtask->output());
}
$webtask->Delete();
return;
} }
else { $results = $webtask->TaskDataObject()->results;
# Backwards compat? $inuse = $results->details;
$inuse = $results; $typeinfo = $results->typeinfo;
} $webtask->Delete();
# #
# Grab local project list for mere users, so we can use it to determine # Grab local project list for mere users, so we can use it to determine
...@@ -272,13 +289,14 @@ function Do_GetStatus() ...@@ -272,13 +289,14 @@ function Do_GetStatus()
$blob = array(); $blob = array();
$blob["totals"] = $typecounts; $blob["totals"] = $typecounts;
$blob["inuse"] = $nodeinfo; $blob["inuse"] = $nodeinfo;
$blob["url"] = $aggregate->weburl();
SPITAJAX_RESPONSE($blob); SPITAJAX_RESPONSE($blob);
} }
function Do_GetPreReservations() function Do_GetPreReservations()
{ {
global $ajax_args, $geni_response_codes, $urn_mapping, $TBBASE; global $ajax_args, $geni_response_codes, $urn_mapping, $TBBASE;
global $TBSUEXEC_PATH; global $TBSUEXEC_PATH, $TBADMINGROUP;
if (! (ISADMIN() || ISFOREIGN_ADMIN())) { if (! (ISADMIN() || ISFOREIGN_ADMIN())) {
SPITAJAX_ERROR(1, "Not enough permission"); SPITAJAX_ERROR(1, "Not enough permission");
...@@ -291,17 +309,29 @@ function Do_GetPreReservations() ...@@ -291,17 +309,29 @@ function Do_GetPreReservations()
$cluster = $ajax_args["cluster"] . ".cm"; $cluster = $ajax_args["cluster"] . ".cm";
} }
$inuse = array(); $inuse = array();
$fp = popen("$TBSUEXEC_PATH elabman tbadmin ". $webtask = WebTask::CreateAnonymous();
"webportal_xmlrpc -a $cluster PreReservations", "r"); $webtask_id = $webtask->task_id();
$string = "";
while (!feof($fp)) { $retval = SUEXEC("elabman", $TBADMINGROUP,
$string .= fgets($fp, 1024); "webportal_xmlrpc -t $webtask_id ".
} " -a $cluster PreReservations",
pclose($fp); SUEXEC_ACTION_IGNORE);
$inuse = json_decode($string); $webtask->Refresh();
if (gettype($inuse) == "object") {
$inuse = $inuse->details; if ($retval != 0) {
if (!$webtask->exited() || $retval < 0) {
SUEXECERROR(SUEXEC_ACTION_CONTINUE);
SPITAJAX_ERROR(-1, "Internal error getting info from cluster");
}
else {
SPITAJAX_ERROR(1, "Unable to get info at ".
"time: ". $webtask->output());
}
$webtask->Delete();
return;
} }
$results = $webtask->TaskDataObject()->results;
$inuse = $results->details;
SPITAJAX_RESPONSE($inuse); SPITAJAX_RESPONSE($inuse);
} }
......
<?php <?php
# #
# Copyright (c) 2000-2017 University of Utah and the Flux Group. # Copyright (c) 2000-2018 University of Utah and the Flux Group.
# #
# {{{EMULAB-LICENSE # {{{EMULAB-LICENSE
# #
...@@ -38,13 +38,32 @@ $this_user = CheckLoginOrRedirect(); ...@@ -38,13 +38,32 @@ $this_user = CheckLoginOrRedirect();
$isadmin = (ISADMIN() ? 1 : 0); $isadmin = (ISADMIN() ? 1 : 0);
$isfadmin = (ISFOREIGN_ADMIN() ? 1 : 0); $isfadmin = (ISFOREIGN_ADMIN() ? 1 : 0);
#
# Verify page arguments. Cluster is a domain that we turn into a URN.
#
$optargs = OptionalPageArguments("cluster", PAGEARG_STRING);
if (isset($cluster)) {
$aggregate = Aggregate::LookupByNickname($cluster);
if (!$aggregate) {
SPITUSERERROR("No such cluster: $cluster");
exit();
}
if ($aggregate->adminonly() && !($isadmin || $isfadmin)) {
SPITUSERERROR("No permission to view cluster: $cluster");
exit();
}
}
SPITHEADER(1); SPITHEADER(1);
# #
# The apt_aggregates table should tell us what clusters, but for # The apt_aggregates table should tell us what clusters, but for
# now it is always the local cluster # now it is always the local cluster
# #
if ($TBMAINSITE && $ISCLOUD) { if (isset($aggregate)) {
$aggregates = array($aggregate->nickname() => $aggregate->urn());
}
elseif ($TBMAINSITE && $ISCLOUD) {
$aggregates = $aggregates =
array("Emulab" => "urn:publicid:IDN+emulab.net+authority+cm", array("Emulab" => "urn:publicid:IDN+emulab.net+authority+cm",
"APT" => "urn:publicid:IDN+apt.emulab.net+authority+cm", "APT" => "urn:publicid:IDN+apt.emulab.net+authority+cm",
......
...@@ -40,6 +40,11 @@ $(function () ...@@ -40,6 +40,11 @@ $(function ()
console.log(json); console.log(json);
if (json.code) { if (json.code) {
console.log("Could not get cluster data: " + json.value); console.log("Could not get cluster data: " + json.value);
$('#cluster-status-' + name + ' .cluster-status-error')
.html(json.value)
.removeClass("hidden");
$('#cluster-status-' + name + ' .resgraph-spinner')
.addClass("hidden");
return; return;
} }
var inuse = json.value.inuse; var inuse = json.value.inuse;
...@@ -50,9 +55,18 @@ $(function () ...@@ -50,9 +55,18 @@ $(function ()
if (_.has(value, "type")) { if (_.has(value, "type")) {
type = value.type; type = value.type;
} }
html = html + "<tr>" + html = html + "<tr><td>";
"<td>" + value.node_id + "</td>" + if (isadmin) {
"<td>" + type + "</td>"; var url = json.value.url +
"/shownode.php3?node_id=" + value.node_id;
html +=
"<a href='" + url + "' target=_blank>" +
value.node_id + "</a></td>";
}
else {
html += value.node_id + "</td>";
}
html += "<td>" + type + "</td>";
if (isadmin) { if (isadmin) {
var expires = ""; var expires = "";
...@@ -118,6 +132,8 @@ $(function () ...@@ -118,6 +132,8 @@ $(function ()
// We reference the totals table in InitTable(); // We reference the totals table in InitTable();
InitTable(name); InitTable(name);
$('#cluster-status-' + name + ' .resgraph-spinner')
.addClass("hidden");
} }
var xmlthing = sup.CallServerMethod(null, "cluster-status", var xmlthing = sup.CallServerMethod(null, "cluster-status",
"GetStatus", "GetStatus",
...@@ -134,6 +150,9 @@ $(function () ...@@ -134,6 +150,9 @@ $(function ()
console.log("Could not get prereserve data: " + json.value); console.log("Could not get prereserve data: " + json.value);
return; return;
} }
if (json.value == null) {
return;
}
var expando_class = "expando-" + name; var expando_class = "expando-" + name;
var html = preresTemplate({ var html = preresTemplate({
......
...@@ -51,7 +51,7 @@ ...@@ -51,7 +51,7 @@
</div> </div>
<% } %> <% } %>
<% _.each(amlist, function(urn, name) { %> <% _.each(amlist, function(urn, name) { %>
<div class='row'> <div class='row' id='cluster-status-<%- name %>'>>
<div <div
<% if (isadmin) { %> <% if (isadmin) { %>
class='col-sm-3' class='col-sm-3'
...@@ -68,6 +68,10 @@ ...@@ -68,6 +68,10 @@
</div> </div>
</div> </div>
</div> </div>
<div class='resgraph-spinner'>
<center>
<img src='images/spinner.gif' /></center>
</div>
</div> </div>
<div <div
<% if (isadmin) { %> <% if (isadmin) { %>
...@@ -90,7 +94,6 @@ ...@@ -90,7 +94,6 @@
<div class="row"> <div class="row">
<div class='col-sm-6'> <div class='col-sm-6'>
<input class='form-control search' <input class='form-control search'
type='search' data-column='all' type='search' data-column='all'
id='inuse-search-<%- name %>' id='inuse-search-<%- name %>'
placeholder='Search <%- name %>'> placeholder='Search <%- name %>'>
...@@ -122,6 +125,9 @@ ...@@ -122,6 +125,9 @@
<tbody id='<%- name %>-tbody'> <tbody id='<%- name %>-tbody'>
</tbody> </tbody>
</table> </table>
<center style="margin-top: 10px;"
class='cluster-status-error
align-center text-danger hidden'></center>
</div> </div>
</div> </div>
</div> </div>
......
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