showexp_list.php3 14 KB
Newer Older
1
<?php
Leigh B. Stoller's avatar
Leigh B. Stoller committed
2 3
#
# EMULAB-COPYRIGHT
4
# Copyright (c) 2000-2003 University of Utah and the Flux Group.
Leigh B. Stoller's avatar
Leigh B. Stoller committed
5 6
# All rights reserved.
#
7 8 9 10 11
include("defs.php3");

#
# Standard Testbed Header
#
12
PAGEHEADER("Experiment Information Listing");
13 14 15 16 17 18 19

#
# Only known and logged in users can end experiments.
#
$uid = GETLOGIN();
LOGGEDINORDIE($uid);

20
$isadmin     = ISADMIN($uid);
21 22
$clause      = 0;
$having      = "";
Mac Newbold's avatar
Mac Newbold committed
23 24
$active      = 0;
$idle        = 0;
25

Leigh B. Stoller's avatar
Leigh B. Stoller committed
26 27
if (! isset($showtype))
    $showtype="active";
28 29
if (! isset($sortby))
    $sortby = "normal";
Chad Barb's avatar
 
Chad Barb committed
30 31
if (! isset($thumb)) 
    $thumb = 0;
32

Leigh B. Stoller's avatar
Leigh B. Stoller committed
33
echo "<b>Show:
Chad Barb's avatar
 
Chad Barb committed
34 35
         <a href='showexp_list.php3?showtype=active&sortby=$sortby&thumb=$thumb'>active</a>,
         <a href='showexp_list.php3?showtype=batch&sortby=$sortby&thumb=$thumb'>batch</a>,";
36
if ($isadmin) 
Chad Barb's avatar
 
Chad Barb committed
37
     echo "\n<a href='showexp_list.php3?showtype=idle&sortby=$sortby&thumb=$thumb'".
38
       ">idle</a>,";
39

Chad Barb's avatar
 
Chad Barb committed
40 41 42
echo "\n       <a href='showexp_list.php3?showtype=all&sortby=$sortby&thumb=$thumb'>all</a>.
      </b><br />\n";

Leigh B. Stoller's avatar
Leigh B. Stoller committed
43 44 45 46 47 48 49 50

#
# Handle showtype
# 
if (! strcmp($showtype, "all")) {
    $title  = "All";
}
elseif (! strcmp($showtype, "active")) {
51 52
    # Active is now defined as "having nodes reserved" - we just depend on
    # the fact that we skip expts with no nodes further down...
Leigh B. Stoller's avatar
Leigh B. Stoller committed
53
    $title  = "Active";
54
    $having = "having (ncount>0)";
55
    $active = 1;
Leigh B. Stoller's avatar
Leigh B. Stoller committed
56 57 58 59
}
elseif (! strcmp($showtype, "batch")) {
    $clause = "e.batchmode=1";
    $title  = "Batch";
60
}
61
elseif ((!strcmp($showtype, "idle")) && $isadmin ) {
62
    # Do not put active in the clause for same reason as active
63
    $title  = "Idle";
64 65
    #$having = "having (lastswap>=1)"; # At least one day since swapin
    $having = "having (lastswap>=0)";
66
    $idle = 1;
67
}
68
else {
69
    # See active above
Leigh B. Stoller's avatar
Leigh B. Stoller committed
70
    $title  = "Active";
71
    $having = "having (ncount>0)";
72
    $active = 1;
73
}
74

Chad Barb's avatar
 
Chad Barb committed
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90


if (!$idle) {
    if (!$thumb) {
	echo "<b><a href='showexp_list.php3?showtype=$showtype&sortby=pid&thumb=1'>".
             "Switch to Thumbnail view".
	     "</a></b><br />";
    } else {
	echo "<b><a href='showexp_list.php3?showtype=$showtype&sortby=pid&thumb=0'>".
             "Switch to List view".
	     "</a></b><br />";
    }
}

echo "<br />\n";

Leigh B. Stoller's avatar
Leigh B. Stoller committed
91 92 93
#
# Handle sortby.
# 
94 95 96 97 98 99 100 101 102
if (! strcmp($sortby, "normal") ||
    ! strcmp($sortby, "pid"))
    $order = "e.pid,e.eid";
elseif (! strcmp($sortby, "eid"))
    $order = "e.eid,e.expt_head_uid";
elseif (! strcmp($sortby, "uid"))
    $order = "e.expt_head_uid,e.pid,e.eid";
elseif (! strcmp($sortby, "name"))
    $order = "e.expt_name";
103 104
elseif (! strcmp($sortby, "pcs"))
    $order = "ncount DESC";
105 106 107
else 
    $order = "e.pid,e.eid";

108 109 110 111 112
#
# Show a menu of all experiments for all projects that this uid
# is a member of. Or, if an admin type person, show them all!
#
if ($isadmin) {
Leigh B. Stoller's avatar
Leigh B. Stoller committed
113
    if ($clause)
114
	$clause = "and ($clause)";
Leigh B. Stoller's avatar
Leigh B. Stoller committed
115 116
    else
        $clause = "";
117

Leigh B. Stoller's avatar
Leigh B. Stoller committed
118
    $experiments_result =
119
	DBQueryFatal("select e.*,".
120
		     "date_format(expt_swapped,\"%Y-%m-%d\") as d, ".
121
		     "(to_days(now())-to_days(expt_swapped)) as lastswap, ".
122
                     "count(r.node_id) as ncount, swap_requests, ".
123 124
		     "round((unix_timestamp(now()) - ".
		     "unix_timestamp(last_swap_req))/3600,1) as lastreq ".
125 126 127 128 129 130
		     "from experiments as e ".
                     "left join reserved as r on e.pid=r.pid and e.eid=r.eid ".
                     "left join nodes as n on r.node_id=n.node_id ".
                     "where (n.type!='dnard' or n.type is null) $clause ".
                     "group by e.pid,e.eid ".
		     "$having ".
131
		     "order by $order");
132 133 134
    if ($idle) {
      # Run idlecheck and get the info
      #print "<pre>Running idlecheck\n";
135
      $x=exec("$TBSUEXEC_PATH $uid $TBADMINGROUP webidlecheck -s -u",
136 137 138 139 140 141 142 143 144 145 146 147
	      $l, $rv);
      reset($l);
      while(list($index,$i) = each ($l)) {
	list($ipid,$ieid,$word1, $word2, $word3) = split("[ \t/]+",$i);
	#print "$ipid + $ieid + $word1 + $word2 + $word3\n";
	$expt = "$ipid/$ieid";
	$set = array($word1,$word2,$word3);
	while(list($index,$tag) = each($set)) {
	  if ($tag == "") { break; }
	  if ($tag == "inactive") { $inactive[$expt]=1; }
	  elseif ($tag == "stale") { $stale[$expt]=1; }
	  elseif ($tag == "unswappable") { $unswap[$expt]=1; }
148 149 150 151
	  else {
	    if (defined($other[$expt])) { $other[$expt].=$tag; }
	    else {$other[$expt]=$tag; }
	  }
152 153 154 155 156 157
	}
	
      }
      #print "\nDone idlechecking...\n</pre>";
    }
      
158 159
}
else {
Leigh B. Stoller's avatar
Leigh B. Stoller committed
160 161 162 163
    if ($clause)
	$clause = "and ($clause)";
    else
        $clause = "";
164
    
Leigh B. Stoller's avatar
Leigh B. Stoller committed
165
    $experiments_result =
166 167 168 169 170 171 172 173 174
	DBQueryFatal("select distinct e.*, ".
                     "date_format(expt_swapped,'%Y-%m-%d') as d, ".
                     "count(r.node_id) as ncount ".
                     "from group_membership as g ".
                     "left join experiments as e on ".
                     "  g.pid=e.pid and g.pid=g.gid ".
                     "left join reserved as r on e.pid=r.pid and e.eid=r.eid ".
                     "left join nodes as n on r.node_id=n.node_id ".
                     "where (n.type!='dnard' or n.type is null) and ".
175 176
                     " g.uid='$uid' and e.pid is not null ".
		     "and e.eid is not null $clause ".
177 178 179
                     "group by e.pid,e.eid ".
		     "$having ".
                     "order by $order");
180
}
181
if (! mysql_num_rows($experiments_result)) {
182 183
    USERERROR("There are no experiments running in any of the projects ".
              "you are a member of.", 1);
184 185
}

186 187
if (mysql_num_rows($experiments_result)) {
    echo "<center>
Leigh B. Stoller's avatar
Leigh B. Stoller committed
188
           <h2>$title Experiments</h2>
189
          </center>\n";
190

Mac Newbold's avatar
Mac Newbold committed
191
    if ($idle) {
Chad Barb's avatar
 
Chad Barb committed
192
      echo "<p><center><b>Experiments that have been idle at least 24 hours</b></center></p><br />\n";
Mac Newbold's avatar
Mac Newbold committed
193
    }
194
    
195
    $idlemark = "<b>*</b>";
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224
    #
    # Okay, I decided to do this as one big query instead of a zillion
    # per-exp queries in the loop below. No real reason, except my personal
    # desire not to churn the DB.
    # 
    $total_usage  = array();
    $perexp_usage = array();

    #
    # Geta all the classes of nodes each experiment is using, and create
    # a two-D array with their counts.
    # 
    $usage_query =
	DBQueryFatal("select r.pid,r.eid,nt.class, ".
		     "  count(nt.class) as ncount ".
		     "from reserved as r ".
		     "left join nodes as n on r.node_id=n.node_id ".
		     "left join node_types as nt on n.type=nt.type ".
		     "where n.type!='dnard' ".
		     "group by r.pid,r.eid,nt.class");

    while ($row = mysql_fetch_array($usage_query)) {
	$pid   = $row[0];
	$eid   = $row[1];
	$class = $row[2];
	$count = $row[3];
	
	$perexp_usage["$pid:$eid"][$class] = $count;
    }
225 226 227 228

    #
    # Now shove out the column headers.
    #
Chad Barb's avatar
 
Chad Barb committed
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279
if ($thumb && !$idle) {
    echo "<table border=2 cols=0
                 cellpadding=0 cellspacing=2 align=center><tr>";

    $thumbCount = 0;
 
    while ($row = mysql_fetch_array($experiments_result)) {	
	$pid  = $row["pid"];
	$eid  = $row["eid"]; 
	$huid = $row["expt_head_uid"];
	$name = stripslashes($row["expt_name"]);
	$date = $row["d"];
	
	if ($idle && ($str=="&nbsp;" || !$pcs)) { continue; }

	echo "<td width=33%><img src='top2image.php3?pid=$pid&eid=$eid&thumb=128' align=center><br />\n" .
	     "<b><a href='showproject.php3?pid=$pid'>$pid</a>/".
             "<a href='showexp.php3?pid=$pid&eid=$eid'>$eid</a></b></h4><br />\n".
	     "<font size=-1>$name</font><br />\n";

	# echo "<font size=-2>Using 69 PCs</font>\n";

	if ($isadmin) {
	    $swappable= $row["swappable"];
	    $swapreq=$row["swap_requests"];
	    $lastswapreq=$row["lastreq"];
	    $lastlogin = "";
	    if ($lastexpnodelogins = TBExpUidLastLogins($pid, $eid)) {
	        $daysidle=$lastexpnodelogins["daysidle"];
	        #if ($idle && $daysidle < 1)
		#  continue;
		$lastlogin .= $lastexpnodelogins["date"] . " " .
		 "(" . $lastexpnodelogins["uid"] . ")";
	    } elseif ($state=="active") {
	        $daysidle=$row["lastswap"];
	        $lastlogin .= "$date Swapped In";
	    }
	    # if ($lastlogin=="") { $lastlogin="<td>&nbsp;</td>\n"; }
	    if ($lastlogin != "") {
		echo "<font size=-2>Last Login: $lastlogin</font><br />\n";
	    }
	}	

	echo "</td>\n";

	$thumbcount++;
	if (($thumbcount % 3) == 0) { echo "</tr><tr>\n"; }
    }

    echo "</tr></table>";
} else {
280 281 282
    echo "<table border=2 cols=0
                 cellpadding=0 cellspacing=2 align=center>
            <tr>
Chad Barb's avatar
 
Chad Barb committed
283
              <th width=8%>
284
               <a href='showexp_list.php3?showtype=$showtype&sortby=pid'>
Chad Barb's avatar
 
Chad Barb committed
285
                  PID</a></th>
Chad Barb's avatar
 
Chad Barb committed
286
              <th width=8%>
287
               <a href='showexp_list.php3?showtype=$showtype&sortby=eid'>
Chad Barb's avatar
 
Chad Barb committed
288
                  EID</a></th>
Chad Barb's avatar
 
Chad Barb committed
289
              <th align=center width=3%>
290
               <a href='showexp_list.php3?showtype=$showtype&sortby=pcs'>
Chad Barb's avatar
 
Chad Barb committed
291
                  PCs</a><br>[<b>1</b>]</th>\n";
292
    
293
    if ($isadmin && !$idle)
Chad Barb's avatar
 
Chad Barb committed
294
        echo "<th width=17% align=center>Last Login</th>\n";
295
    if ($idle)
Chad Barb's avatar
 
Chad Barb committed
296 297
        #      "<th width=4% align=center>Days Idle</th>\n";
	echo "<th width=4% align=center>Slothd Info</th>
Chad Barb's avatar
 
Chad Barb committed
298
              <th width=4% align=center colspan=2>Swap Request</th>\n";
299

Chad Barb's avatar
 
Chad Barb committed
300
    echo "    <th width=60%>
301
               <a href='showexp_list.php3?showtype=$showtype&sortby=name'>
Chad Barb's avatar
 
Chad Barb committed
302
                  Name</a></th>
Chad Barb's avatar
 
Chad Barb committed
303
              <th width=4%>
304
               <a href='showexp_list.php3?showtype=$showtype&sortby=uid'>
Chad Barb's avatar
 
Chad Barb committed
305
                  Head UID</a></th>
306 307
            </tr>\n";

308
    while ($row = mysql_fetch_array($experiments_result)) {
309 310 311
	$pid  = $row["pid"];
	$eid  = $row["eid"]; 
	$huid = $row["expt_head_uid"];
Leigh B. Stoller's avatar
Leigh B. Stoller committed
312
	$name = stripslashes($row["expt_name"]);
313 314
	$date = $row["d"];
	$state= $row["state"];
315
	$isidle = $row["swap_requests"];
316 317
	$daysidle=0;
	
318
	if ($isadmin) {
319 320 321 322
	    $swappable= $row["swappable"];
	    $swapreq=$row["swap_requests"];
	    $lastswapreq=$row["lastreq"];
	    $lastlogin = "<td>";
323
	    if ($lastexpnodelogins = TBExpUidLastLogins($pid, $eid)) {
324
	        $daysidle=$lastexpnodelogins["daysidle"];
325 326
	        #if ($idle && $daysidle < 1)
		#  continue;
327
		$lastlogin .= $lastexpnodelogins["date"] . " " .
328
		 "(" . $lastexpnodelogins["uid"] . ")";
329
	    } elseif ($state=="active") {
330 331
	        $daysidle=$row["lastswap"];
	        $lastlogin .= "$date Swapped In";
332
	    }
333 334
	    $lastlogin.="</td>\n";
	    if ($lastlogin=="<td></td>\n") { $lastlogin="<td>&nbsp;</td>\n"; }
335 336
	}

337
	if ($idle) {
338 339
	    #$lastlogin .= "<td align=center>$daysidle</td>\n";
	    $foo = "<td align=left>";
340 341 342
	    $expt = "$pid/$eid";
	    $str="";
	    if ($inactive[$expt]==1) {
343
	      if ($stale[$expt]==1) {
344
		$str .= "possibly&nbsp;inactive, ";
345
	      } elseif  ($unswap[$expt]==1) {
346
		$str .= "<b>probably&nbsp;inactive, unswappable</b>";
347 348 349
	      } else {
		$str .= "<b>inactive</b>";
	      }
350
	      if ($other[$expt]) { $str .= " ($other[$expt]) "; }
351
	    }
352
	    if ($stale[$expt]==1) { $str .= "<b>no&nbsp;report</b> "; }
353 354 355 356
	    # For now, don't show this tag, it's redundant
            #if ($unswap[$expt]==1) { $str .= "unswappable"; }
	    if ($str=="") { $str="&nbsp;"; }
	    # sanity check
357
	    $slothderr=0;
358
	    if ($daysidle==0 && $inactive[$expt]==1 && $stale[$expt]==0) {
359
	      $str .= " (recently logged into)\n";
360
	      $slothderr=1;
361
	    }
362 363 364 365 366
	    $foo .= "$str</td>\n";
	    if (isset($perexp_usage["$pid:$eid"]) &&
		isset($perexp_usage["$pid:$eid"]["pc"])) {
	      $pcs = $perexp_usage["$pid:$eid"]["pc"];
	    } else { $pcs=0; }
367
	    $foo .= "<td align=center valign=center>\n";
368 369
 	    if ($inactive[$expt]==1 && $stale[$expt]!=1 &&
	        !$slothderr && $pcs) {
Chad Barb's avatar
 
Chad Barb committed
370 371
	      $fooswap = "<td><a href=\"request_swapexp.php3?pid=$pid&eid=$eid\">".
			 "<img border=0 src=\"redball.gif\"></a></td>\n" ;
372
	    } else {
Chad Barb's avatar
 
Chad Barb committed
373
	      $fooswap = "<td></td>";
374 375 376 377
	      if (!$pcs) { $foo .= "(no PCs)\n"; }
	      else { $foo .="&nbsp;"; }
	    }
	    if ($swapreq > 0) {
Chad Barb's avatar
 
Chad Barb committed
378 379
	      $foo .= "&nbsp;$swapreq&nbsp;sent<br />".
	              "<font size=-2>(${lastswapreq}&nbsp;hours&nbsp;ago)</font>\n";
380
	    }
Chad Barb's avatar
 
Chad Barb committed
381
	    $foo .= "</td>" . $fooswap . "\n"; 
382
	}
383

384 385
	if ($idle && ($str=="&nbsp;" || !$pcs)) { continue; }

386 387
	$nodes   = 0;
	$special = 0;
388 389 390 391
	reset($perexp_usage);
	if (isset($perexp_usage["$pid:$eid"])) {
	    while (list ($class, $count) = each($perexp_usage["$pid:$eid"])) {
		$nodes += $count;
392
		if (strcmp($class, "pc")) {
393
		    $special = 1;
394 395 396 397
		} else {
		    $pcs = $count;
		}

398 399 400 401 402 403 404

		# Summary counts for just the experiments in the projects
		# the user is a member of.
		if (!isset($total_usage[$class]))
		    $total_usage[$class] = 0;
			
		$total_usage[$class] += $count;
405
	    }
406
	}
407 408 409

	# in idle or active, skip experiments with no nodes.
	if (($idle || $active) && $nodes == 0) { continue; }
410 411
	if ($nodes==0) { $nodes = "&nbsp;"; }
	
412 413
	echo "<tr>
                <td><A href='showproject.php3?pid=$pid'>$pid</A></td>
Leigh B. Stoller's avatar
Leigh B. Stoller committed
414
                <td><A href='showexp.php3?pid=$pid&eid=$eid'>
415
                       $eid</A></td>\n";
416 417
	
	if ($isidle) { $nodes = $nodes.$idlemark; }
418 419 420 421 422
	# If multiple classes, then hightlight the number.
	if ($special)
            echo "<td><font color=red>$nodes</font></td>\n";
	else
            echo "<td>$nodes</td>\n";
423

424 425
	if ($isadmin && !$idle) echo "$lastlogin\n";
	if ($idle) echo "$foo\n";
426 427

        echo "<td>$name</td>
428 429
                <td><A href='showuser.php3?target_uid=$huid'>
                       $huid</A></td>
430 431 432
               </tr>\n";
    }
    echo "</table>\n";
433

Chad Barb's avatar
 
Chad Barb committed
434 435
}

436 437
    echo "<ol>
             <li><font color=red>Red</font> indicates nodes other than PCs.
438 439
                 A $idlemark mark by the node count indicates that the
                 experiment is currently considered idle.
440 441 442
          </ol>\n";
    
    echo "<center><b>Node Totals</b></center>\n";
443 444 445
    echo "<table border=0
                 cellpadding=1 cellspacing=1 align=center>\n";
    $total = 0;
446
    ksort($total_usage);
447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466
    while (list($type, $count) = each($total_usage)) {
	    $total += $count;
	    echo "<tr>
                    <td align=right>${type}:</td>
                    <td>&nbsp &nbsp &nbsp &nbsp</td>
                    <td align=center>$count</td>
                  </tr>\n";
    }
    echo "<tr>
             <td align=right><hr></td>
             <td>&nbsp &nbsp &nbsp &nbsp</td>
             <td align=center><hr></td>
          </tr>\n";
    echo "<tr>
             <td align=right><b>Total</b>:</td>
             <td>&nbsp &nbsp &nbsp &nbsp</td>
             <td align=center>$total</td>
          </tr>\n";
    
    echo "</table>\n";
467 468 469 470 471 472 473
}

#
# Standard Testbed Footer
# 
PAGEFOOTER();
?>