request_idleinfo.php3 4.49 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
<?php
#
# EMULAB-COPYRIGHT
# Copyright (c) 2005 University of Utah and the Flux Group.
# All rights reserved.
#
include("defs.php3");
include("showstuff.php3");

#
# Standard Testbed Header
#
PAGEHEADER("Request info about possibly Idle experiment");

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

#
# Verify page arguments.
# 
if (!isset($pid) ||
    strcmp($pid, "") == 0) {
    USERERROR("You must provide a Project ID.", 1);
}

if (!isset($eid) ||
    strcmp($eid, "") == 0) {
    USERERROR("You must provide an Experiment ID.", 1);
}

#
# Only admins can do this!
#
if (! ISADMIN($uid)) {
    USERERROR("Only TB admins can do this!", 1);
}

#
# Check to make sure this is a valid PID/EID tuple.
#
if (! TBValidExperiment($pid, $eid)) {
    USERERROR("The experiment $eid is not a valid experiment ".
	      "in project $pid.", 1);
}

#
# We run this twice. The first time we are checking for a confirmation
# by putting up a form. The next time through the confirmation will be
# set. Or, the user can hit the cancel button, in which case we should
# probably redirect the browser back up a level.
#
if ($canceled) {
    echo "<center><h2>Idle info request canceled!</h2>
          <br><br>
          <a href='showexp.php3?pid=$pid&eid=$eid'>
             Back to experiment $pid/$eid</a>
          </center>\n";
    PAGEFOOTER();
    return;
}

#
# See how many PCs the experiment is holding.
# 
$query_result =
    DBQueryFatal("select count(*) as count 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 nt.class='pc' and pid='$pid' and eid='$eid'");

if (!mysql_num_rows($query_result)) {
    echo "<center><h2>Idle info request canceled cause there are no PCs!</h2>
          <br><br>
          <a href='showexp.php3?pid=$pid&eid=$eid'>
             Back to experiment $pid/$eid</a>
          </center>\n";
    PAGEFOOTER();
    return;
}
$row = mysql_fetch_array($query_result);
$pcs = $row["count"];

if (!$confirmed) {
    echo "<br><center><h3>
          Are your <b>SURE</b> you want to send an Idle Info request
          email message to the swapper of $pid/$eid?
          </h3></center>\n";

    #
    # Dump experiment record.
    # 
    SHOWEXP($pid, $eid);
    
    echo "<form action='request_idleinfo.php3?pid=$pid&eid=$eid' method=post>";
    echo "<input type=submit name=confirmed value=Confirm>\n";
    echo "<input type=submit name=canceled value=Cancel>\n";
    echo "</form>\n";
    echo "</center>\n";

    PAGEFOOTER();
    return;
}

# Info about experiment.
$query_result =
109 110
    DBQueryFatal("select e.gid,e.expt_swap_uid as swapper, ".
		 "       e.expt_head_uid as creator, ".
111 112 113 114 115 116 117 118 119
		 "       UNIX_TIMESTAMP(now())-UNIX_TIMESTAMP(e.expt_swapped)".
		 "   as swapseconds, r.pnodes ".
		 " from experiments as e ".
		 "left join experiment_stats as s on s.exptidx=e.idx ".
		 "left join experiment_resources as r on ".
		 "     s.rsrcidx=r.idx ".
		 "where e.pid='$pid' and e.eid='$eid'");

$row = mysql_fetch_array($query_result);
120
$gid     = $row["gid"];
121
$swapper = $row["swapper"];
122
$creator = $row["creator"];
123 124 125 126
$pcs     = $row["pnodes"];
$seconds = $row["swapseconds"];
$hours   = intval($seconds / 3600);

127 128 129 130 131 132 133 134 135 136 137
# Lots of email addresses!
$allleaders    = TBLeaderMailList($pid, $gid);
$swapper_name  = "";
$swapper_email = "";
TBUserInfo($swapper, $swapper_name, $swapper_email);
$creator_name  = "";
$creator_email = "";
if ($swapper != $creator) {
    TBUserInfo($creator, $creator_name, $creator_email);
    $allleaders .= ", \"$creator_name\" <$creator_email>";
}
138 139

# And send email
140
TBMAIL("$swapper_name <$swapper_email>",
141
       "Please tell us about your experiment",
142 143 144 145 146
       "Hi. We noticed that your experiment '$pid/$eid' has been\n".
       "swapped in for $hours hours and is using $pcs nodes.\n".
       "\n".
       "Such long running experiments are unusual so we want to make sure\n".
       "this experiment is still doing useful work.\n".
147 148 149 150 151 152
       "\n".
       "Please respond to this message letting us know; if we do not hear\n".
       "from you within a couple of hours, we will be forced to swap your\n".
       "experiment out so that others can use the nodes.\n\n".
       "Thanks very much!\n",
       "From: $TBMAIL_OPS\n".
153
       "Cc: $allleaders\n".
154
       "Cc: $TBMAIL_OPS\n".
155 156 157 158 159 160 161 162 163 164 165 166
       "Errors-To: $TBMAIL_WWW");

echo "<center><h2>Message sent!</h2>
      <br><br>
      <a href='showexp.php3?pid=$pid&eid=$eid'>Back to experiment $pid/$eid</a>
      </center>\n";

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