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

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

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