swapexp.php3 8.58 KB
Newer Older
1
<?php
Leigh B. Stoller's avatar
Leigh B. Stoller committed
2 3
#
# EMULAB-COPYRIGHT
4
# Copyright (c) 2000-2004 University of Utah and the Flux Group.
Leigh B. Stoller's avatar
Leigh B. Stoller committed
5 6
# All rights reserved.
#
7
include("defs.php3");
8
include("showstuff.php3");
9 10 11 12 13 14 15 16 17 18 19 20

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

#
# Must provide the EID!
# 
if (!isset($pid) ||
    strcmp($pid, "") == 0) {
21
    USERERROR("The project ID was not provided!", 1);
22 23 24 25
}

if (!isset($eid) ||
    strcmp($eid, "") == 0) {
26
    USERERROR("The experiment ID was not provided!", 1);
27 28 29
}

if (!isset($inout) ||
30
    (strcmp($inout, "in") && strcmp($inout, "out") &&
31 32 33
     strcmp($inout, "pause") && strcmp($inout, "restart") &&
     strcmp($inout, "instop"))) {
    USERERROR("Improper inout argument!", 1);
34 35
}

36 37 38 39 40 41 42 43 44 45 46
# Canceled operation redirects back to showexp page. See below.
if ($canceled) {
    header("Location: showexp.php3?pid=$pid&eid=$eid");
    return;
}

#
# Standard Testbed Header, after cancel above.
#
PAGEHEADER("Swap Control");

47 48 49 50 51 52 53 54
#
# Only admins can issue a force swapout
# 
if (isset($force) && $force == 1) {
	if (! ISADMIN($uid)) {
		USERERROR("Only testbed administrators can forcibly swap ".
			  "an experiment out!", 1);
	}
55 56
	if (!isset($idleswap)) { $idleswap=0; }
	if (!isset($autoswap)) { $autoswap=0; }
57 58 59
	if (!isset($forcetype)){ $forcetype="force"; }
	if ($forcetype=="idleswap") { $idleswap=1; }
	if ($forcetype=="autoswap") { $autoswap=1; }
60 61 62
}
else {
	$force = 0;
63 64
	$idleswap=0;
	$autoswap=0;
65 66
}

67 68 69 70 71 72 73 74 75 76
$exp_eid = $eid;
$exp_pid = $pid;

#
# Check to make sure thats this is a valid PID/EID tuple.
#
$query_result =
    DBQueryFatal("SELECT * FROM experiments WHERE ".
		 "eid='$exp_eid' and pid='$exp_pid'");
if (mysql_num_rows($query_result) == 0) {
77 78
    USERERROR("The experiment $exp_eid is not a valid experiment ".
	      "in project $exp_pid.", 1);
79
}
80 81 82
$row           = mysql_fetch_array($query_result);
$exp_gid       = $row[gid];
$isbatch       = $row[batchmode];
83
$state         = $row[state];
84 85 86 87
$swappable     = $row[swappable];
$idleswap_bit  = $row[idleswap];
$idleswap_time = $row[idleswap_timeout];
$idlethresh    = min($idleswap_time/60.0,TBGetSiteVar("idle/threshold"));
88 89 90 91 92

#
# Verify permissions.
#
if (! TBExptAccessCheck($uid, $exp_pid, $exp_eid, $TB_EXPT_MODIFY)) {
93
    USERERROR("You do not have permission for $exp_eid!", 1);
94 95
}

96 97 98 99 100 101 102 103 104
# Convert inout to informative text.
if (!strcmp($inout, "in")) {
    if ($isbatch) 
	$action = "queue";
    else
	$action = "swapin";
}
elseif (!strcmp($inout, "out")) {
    if ($isbatch) 
105
	$action = "swapout and dequeue";
106
    else {
107
	if ($state == $TB_EXPTSTATE_ACTIVATING) {
108 109 110 111 112 113
	    $action = "cancel";
	}
	else {
	    $action = "swapout";
	}
    }
114 115 116
}
elseif (!strcmp($inout, "pause")) {
    if (!$isbatch)
117
	USERERROR("Only batch experiments can be dequeued!", 1);
118
    $action = "dequeue";
119 120 121 122 123
}
elseif (!strcmp($inout, "restart")) {
    $action = "restart";
}

124 125 126 127
echo "<font size=+2>Experiment <b>".
     "<a href='showproject.php3?pid=$pid'>$pid</a>/".
     "<a href='showexp.php3?pid=$pid&eid=$eid'>$eid</a></b></font>\n";

128 129 130
#
# 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
131 132
# set. Or, the user can hit the cancel button, in which case we 
# redirect the browser back to the experiment page (see above).
133 134 135
#
if (!$confirmed) {
    echo "<center><h2><br>
136 137
          Are you sure you want to ";
    if ($force) {
138
	echo "<font color=red><br>forcibly</br></font> ";
139
    }
140
    echo "$action experiment '$exp_eid?'
141 142
          </h2>\n";
    
143 144
    SHOWEXP($exp_pid, $exp_eid, 1);

145 146
    echo "<form action='swapexp.php3?inout=$inout&pid=$exp_pid&eid=$exp_eid'
                method=post>";
147 148

    if ($force) {
149 150 151
	if (!$swappable) {
	    echo "<h2>Note: This experiment is <em>NOT</em> swappable!</h2>\n";
	}
152 153 154 155 156 157 158 159
	echo "Force Type: <select name=forcetype>\n";
	echo "<option value=force ".($forcetype=="force"?"selected":"").
	    ">Forced Swap</option>\n";
	echo "<option value=idleswap ".($forcetype=="idleswap"?"selected":"").
	    ">Idle-Swap</option>\n";
	echo "<option value=autoswap ".($forcetype=="autoswap"?"selected":"").
	    ">Auto-Swap</option>\n";
	echo "</select><br><br>\n";
160 161 162
	echo "<input type=hidden name=force value=$force>\n";
	echo "<input type=hidden name=idleswap value=$idleswap>\n";
	echo "<input type=hidden name=autoswap value=$autoswap>\n";
163 164
    }
    
165 166
    echo "<b><input type=submit name=confirmed value=Confirm></b>\n";
    echo "<b><input type=submit name=canceled value=Cancel></b>\n";
167
    echo "</form>\n";
168

169
    if ($inout!="out" && $idleswap_bit) {
170 171 172 173
	if ($idleswap_time / 60.0 != $idlethresh) {
	    echo "<p>Note: The Idle-Swap time for your experiment will be
		 reset to $idlethresh hours.</p>\n";
	}
174 175
    }
    
176 177 178 179 180 181 182 183 184 185
    if (!strcmp($inout, "restart")) {
	echo "<p>
              <a href='$TBDOCBASE/faq.php3#UTT-Restart'>
                 (Information on experiment restart)</a>\n";
    }
    else {
	echo "<p>
              <a href='$TBDOCBASE/faq.php3#UTT-Swapping'>
                 (Information on experiment swapping)</a>\n";
    }
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203
    echo "</center>\n";

    PAGEFOOTER();
    return;
}

#
# We need the unix gid for the project for running the scripts below.
# Note usage of default group in project.
#
TBGroupUnixInfo($exp_pid, $exp_gid, $unix_gid, $unix_name);

#
# We run a wrapper script that does all the work of terminating the
# experiment. 
#
#   tbstopit <pid> <eid>
#
204 205
echo "<center>";
echo "<h2>Starting experiment state change. Please wait a moment ...
206 207 208 209 210 211 212 213 214
      </h2></center>";

flush();

#
# Run the scripts. We use a script wrapper to deal with changing
# to the proper directory and to keep some of these details out
# of this. 
#
215 216 217 218
# Avoid SIGPROF in child.
# 
set_time_limit(0);

219 220
# Args for idleswap It passes them on to swapexp, or if it is just a
# plain force swap, it passes -f for us.
221
$args = ($idleswap ? "-i" : ($autoswap ? "-a" : ""));
222

223
$retval = SUEXEC($uid, "$exp_pid,$unix_gid",
224 225 226 227
		 ($force ?
		  "webidleswap $args $exp_pid $exp_eid" :
		  "webswapexp -s $inout $exp_pid $exp_eid"),
		 SUEXEC_ACTION_IGNORE);
228

229 230 231 232 233 234 235 236 237
#
# Fatal Error. Report to the user, even though there is not much he can
# do with the error. Also reports to tbops.
# 
if ($retval < 0) {
    SUEXECERROR(SUEXEC_ACTION_DIE);
    #
    # Never returns ...
    #
238 239 240 241 242 243
    die("");
}

#
# Exit status 0 means the experiment is swapping, or will be.
#
244 245 246 247 248 249
echo "<br>\n";
if ($retval) {
    echo "<h3>Experiment $action could not proceed</h3>";
    echo "<blockquote><pre>$suexec_output<pre></blockquote>";
}
else {
250 251 252 253 254 255 256 257 258 259
    if ($isbatch) {
	if (strcmp($inout, "in") == 0) {
	    echo "Batch Mode experiments will be run when enough resources
                  become available. This might happen immediately, or it
                  may take hours or days. You will be notified via email
                  when the experiment has been run. In the meantime, you can
                  check the web page to see how many attempts have been made,
                  and when the last attempt was.\n";
	}
	elseif (strcmp($inout, "out") == 0) {
260

261 262 263 264 265 266 267 268 269 270
	    echo "Batch mode experiments take a few moments to stop. Once
                  it does, the experiment will enter the 'paused' state.
                  You can requeue the batch experiment at that time.\n";

	    echo "<br><br>
                  If you do not receive
                  email notification within a reasonable amount of time,
                  please contact $TBMAILADDR.\n";
	}
	elseif (strcmp($inout, "pause") == 0) {
271
	    echo "Your experiment has been dequeued. You may requeue your
272 273
		  experiment at any time.\n";
	}
274 275
    }
    else {
276
	if (strcmp($inout, "out") == 0 &&
277
	    strcmp($state, $TB_EXPTSTATE_ACTIVATING) == 0) {
278 279 280 281 282 283 284 285 286 287 288 289

	    echo "Your experiment swapin has been marked for cancelation.
                  It typically takes a few minutes for this to be recognized,
                  assuming you made your request early enough. You will
                  be notified via email when the original swapin request has
                  either aborted or finished.\n";
	}
	else {
	    if (strcmp($inout, "in") == 0)
		$howlong = "two to ten";
	    else
		$howlong = "less than two";
290
    
291 292 293 294 295 296 297 298 299 300 301 302 303 304
	    echo "Your experiment has started its $action.
                 You will be notified via email when the operation is complete.
                 This typically takes $howlong minutes, depending on the
                 number of nodes in the experiment.\n";
	}
	echo "<br><br>
              If you do not receive
              email notification within a reasonable amount of time,
              please contact $TBMAILADDR.\n";

	echo "<br><br>
              While you are waiting, you can watch the log in
              <a target=_blank href=spewlogfile.php3?pid=$exp_pid&eid=$exp_eid>
              realtime</a>.\n";
305
    }
306 307 308 309 310 311 312
}

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