showpool.php 5.82 KB
Newer Older
1 2
<?php
#
3
# Copyright (c) 2009-2012 University of Utah and the Flux Group.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
# 
# {{{EMULAB-LICENSE
# 
# This file is part of the Emulab network testbed software.
# 
# This file is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or (at
# your option) any later version.
# 
# This file is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public
# License for more details.
# 
# You should have received a copy of the GNU Affero General Public License
# along with this file.  If not, see <http://www.gnu.org/licenses/>.
# 
# }}}
23 24
#
include("defs.php3");
25 26
include("showstuff.php3");
include("table_defs.php");
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43

#
# Only known and logged in users can look at experiments.
#
$this_user = CheckLoginOrDie();
$uid       = $this_user->uid();
$isadmin   = ISADMIN();

#
# Verify page arguments.
#
$optargs = OptionalPageArguments("sortby",     PAGEARG_STRING);

if (!isset($sortby)) {
    $sortby = "";
}

44 45
PAGEHEADER("Shared Pool");

46 47 48 49 50 51 52 53 54 55
$experiment = Experiment::LookupByPidEid("emulab-ops", "shared-nodes");
if (!$experiment) {
    $experiment = Experiment::LookupByPidEid("emulab-ops", "shared-node");
}
if (!$experiment) {
    USERERROR("No shared pool experiment!", 1);
}
$pid = $experiment->pid();
$eid = $experiment->eid();
$counts = array();
56
$nodes  = array();
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74

#
# Get the counts per node.
#
$query_result =
    DBQueryFatal("select phys_nodeid,count(phys_nodeid) as vcount ".
		 "  from reserved as r ".
		 "left join nodes as n on n.node_id=r.node_id ".
		 "where n.node_id!=n.phys_nodeid and ".
		 "      r.sharing_mode is not null ".
		 "group by phys_nodeid");
while ($row = mysql_fetch_array($query_result)) {
    $node_id  = $row["phys_nodeid"];
    $count    = $row["vcount"];
    
    $counts[$node_id] = $count;
}

75 76 77 78 79 80
#
# Get the distinct set of nodes using the shared nodes.
#
$query_result =
    DBQueryFatal("select r.node_id from reserved as r ".
		 "left join nodes as n on n.node_id=r.node_id ".
81
		 "left join reserved as r2 on r2.node_id=n.phys_nodeid ".
82
		 "where n.node_id!=n.phys_nodeid and ".
83
		 "      r.sharing_mode is not null and " .
84 85 86
		 "      r2.pid='$pid' and ".
		 "      (r2.eid='$eid' or r2.eid='shared-pcpg') ".
		 "order by node_id");
87 88 89 90 91 92
while ($row = mysql_fetch_array($query_result)) {
    $node_id  = $row["node_id"];
    
    $nodes[$node_id] = $node_id;
}

93
$query_result =
94
    DBQueryFatal("select ru.*,r.node_id,n.type,n.def_boot_osid,o.osname, ".
95 96 97 98 99 100 101 102
		 " ns.status as nodestatus, ".
		 " date_format(rsrv_time,\"%Y-%m-%d&nbsp;%T\") as rsrvtime ".
		 "from reserved as r ".
		 "left join nodes as n on n.node_id=r.node_id ".
		 "left join node_types as nt on nt.type=n.type ".
		 "left join node_status as ns on ns.node_id=r.node_id ".
		 "left join node_rusage as ru on ru.node_id=r.node_id ".
		 "left join os_info as o on o.osid=n.def_boot_osid ".
103
		 "where r.pid='$pid' and (r.eid='$eid' or r.eid='shared-pcpg') ".
104 105
		 "order BY rsrvtime");

106 107 108
$url = CreateURL("showexp", $experiment);

echo "These are the nodes in the <a href='$url'>shared pool</a>. ";
Leigh Stoller's avatar
Leigh Stoller committed
109
echo "Please see the <a href='$WIKIDOCURL/SharedNodes'>documentation</a> ";
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
echo "on how to use shared nodes in your experiment.<br>";

echo "<table width=\"100%\" border=2 cellpadding=1 cellspacing=2 
       id='pooltable' align='center'>\n";
echo "<thead class='sort'>";
echo "<tr>
          <th>NodeID</th>
	  <th>Type</th>
          <th>Reserved</th>
          <th>Default OSID</th>
          <th>Count</th>
          <th>Node<br>Status</th>
          <th>Load Avg<br>1min/5min</th>\n";
echo "</tr>\n";
echo "</thead>\n";

while ($row = mysql_fetch_array($query_result)) {
    $node_id   = $row["node_id"];
    $rsrvtime  = $row["rsrvtime"];
    $type      = $row["type"];
    $status    = $row["nodestatus"];
    $osname    = $row["osname"];
    $osid      = $row["def_boot_osid"];
    $loadavg1  = $row["load_1min"];
    $loadavg5  = $row["load_5min"];
Leigh Stoller's avatar
Leigh Stoller committed
135
    $vcount    = 0;
136

Leigh Stoller's avatar
Leigh Stoller committed
137 138 139
    if (array_key_exists($node_id, $counts)) {
	$vcount = $counts[$node_id];
    }
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163

    echo "<tr>";

    if ($isadmin) {
	$url = CreateURL("shownode", URLARG_NODEID, $node_id);
	echo "<td><a href='$url'>$node_id</a></td>\n";
    }
    else {
	echo "<td>$node_id</td>\n";
    }	
    echo "<td><a href='shownodetype.php3?node_type=$type'>$type</a></td>\n";
    echo "<td>$rsrvtime</td>\n";
    
    $url = CreateURL("showosinfo", URLARG_OSID, $osid);
    echo "<td><a href='$url'>$osname</a></td>\n";
    echo "<td>$vcount</td>\n";
    echo "<td>$status</td>\n";
    echo "<td>$loadavg1/$loadavg5</td>\n";
    echo "</tr>\n";
}
echo "</table>\n";

# Sort initialized later when page fully loaded.
AddSortedTable('pooltable');
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203

#
#
#
if ($isadmin) {
    $table = array('#id'       => "Containers",
		   '#title'    => "Containers",
		   '#sortable' => 1,
		   '#headings' => array("node_id"      => "node_id",
					"PID"          => "PID",
					"EID"          => "EID",
					"Status"       => "Status",
					));

    $rows = array();
    
    foreach ($nodes as $node_id) {
	$node = Node::Lookup($node_id);
	if (! $node)
	    continue;

	$status     = $node->RealNodeStatus();
	$experiment = $node->Reservation();
	$pid       = $experiment->pid();
	$eid       = $experiment->eid();
	$creator   = $experiment->creator();
	$nodeurl   = CreateURL("shownode", $node);
	$nodehref  = "<a href='$nodeurl'>$node_id</a>";
	$expurl    = CreateURL("showexp", $experiment);
	$exphref   = "<a href='$expurl'>$eid</a>";

	$rows[$node_id] = array("node_id"   => $nodehref,
				"PID"       => $pid,
				"EID"       => $exphref,
				"Status"    => $status,
                               );
    }
    list ($html, $button) = TableRender($table, $rows);
    echo $html;
}
204 205 206 207 208 209
    
#
# Standard Testbed Footer
# 
PAGEFOOTER();
?>