swapexp.php3 8.76 KB
Newer Older
1
<?php
Leigh B. Stoller's avatar
Leigh B. Stoller committed
2
3
#
# EMULAB-COPYRIGHT
4
# Copyright (c) 2000-2005 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
$lockdown      = $row["lockdown"];
89
90
91
92
93

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

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

125
126
127
128
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";

129
130
131
132
133
134
# A locked down experiment means just that!
if ($lockdown) {
    echo "<br><br>\n";
    USERERROR("Cannot proceed; the experiment is locked down!", 1);
}

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

152
153
    echo "<form action='swapexp.php3?inout=$inout&pid=$exp_pid&eid=$exp_eid'
                method=post>";
154
155

    if ($force) {
156
157
158
	if (!$swappable) {
	    echo "<h2>Note: This experiment is <em>NOT</em> swappable!</h2>\n";
	}
159
160
161
162
163
164
165
166
	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";
167
168
169
	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";
170
171
    }
    
172
173
    echo "<b><input type=submit name=confirmed value=Confirm></b>\n";
    echo "<b><input type=submit name=canceled value=Cancel></b>\n";
174
    echo "</form>\n";
175

176
    if ($inout!="out" && $idleswap_bit) {
177
178
179
180
	if ($idleswap_time / 60.0 != $idlethresh) {
	    echo "<p>Note: The Idle-Swap time for your experiment will be
		 reset to $idlethresh hours.</p>\n";
	}
181
182
    }
    
183
184
185
186
187
188
189
190
191
192
    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";
    }
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
    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>
#
211
212
echo "<center>";
echo "<h2>Starting experiment state change. Please wait a moment ...
213
214
215
216
217
218
219
220
221
      </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. 
#
222
223
224
225
# Avoid SIGPROF in child.
# 
set_time_limit(0);

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

230
$retval = SUEXEC($uid, "$exp_pid,$unix_gid",
231
232
233
234
		 ($force ?
		  "webidleswap $args $exp_pid $exp_eid" :
		  "webswapexp -s $inout $exp_pid $exp_eid"),
		 SUEXEC_ACTION_IGNORE);
235

236
237
238
239
240
241
242
243
244
#
# 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 ...
    #
245
246
247
248
249
250
    die("");
}

#
# Exit status 0 means the experiment is swapping, or will be.
#
251
252
253
254
255
256
echo "<br>\n";
if ($retval) {
    echo "<h3>Experiment $action could not proceed</h3>";
    echo "<blockquote><pre>$suexec_output<pre></blockquote>";
}
else {
257
258
259
260
261
262
263
264
265
266
    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) {
267

268
269
270
271
272
273
274
275
276
277
	    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) {
278
	    echo "Your experiment has been dequeued. You may requeue your
279
280
		  experiment at any time.\n";
	}
281
282
    }
    else {
283
	if (strcmp($inout, "out") == 0 &&
284
	    strcmp($state, $TB_EXPTSTATE_ACTIVATING) == 0) {
285
286
287
288
289
290
291
292
293
294
295
296

	    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";
297
    
298
299
300
301
302
303
304
305
306
307
308
309
310
311
	    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";
312
    }
313
314
315
316
317
318
319
}

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