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

#
# Standard Testbed Header
#
12
PAGEHEADER("Swap/Restart an Experiment");
13 14 15 16 17 18 19 20 21 22 23 24

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

#
# Must provide the EID!
# 
if (!isset($pid) ||
    strcmp($pid, "") == 0) {
25
    USERERROR("The project ID was not provided!", 1);
26 27 28 29
}

if (!isset($eid) ||
    strcmp($eid, "") == 0) {
30
    USERERROR("The experiment ID was not provided!", 1);
31 32 33
}

if (!isset($inout) ||
34 35 36
    (strcmp($inout, "in") && strcmp($inout, "out") &&
     strcmp($inout, "restart"))) {
    USERERROR("The argument must be either in, out, or restart!", 1);
37 38
}

39 40 41 42 43 44 45 46 47 48 49 50 51
#
# 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);
	}
}
else {
	$force = 0;
}

52 53 54
$exp_eid = $eid;
$exp_pid = $pid;

55 56 57 58 59 60 61 62 63 64
if (!strcmp($inout, "in")) {
    $action = "swapin";
}
elseif (!strcmp($inout, "out")) {
    $action = "swapout";
}
elseif (!strcmp($inout, "restart")) {
    $action = "restart";
}

65 66 67 68 69 70 71
#
# 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) {
72 73
    USERERROR("The experiment $exp_eid is not a valid experiment ".
	      "in project $exp_pid.", 1);
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
}
$row = mysql_fetch_array($query_result);
$exp_gid = $row[gid];
$batch   = $row[batchmode];

#
# Look for transition in progress and exit with error. 
#
$expt_locked = $row[expt_locked];
if ($expt_locked) {
    USERERROR("It appears that experiment $exp_eid went into transition at ".
	      "$expt_locked.<br>".
	      "You must wait until the experiment is no longer in transition.".
	      "<br><br>".
	      "When the transition has completed, a notification will be ".
	      "sent via email to the user that initiated it.", 1);
}

#
# Verify permissions.
#
if (! TBExptAccessCheck($uid, $exp_pid, $exp_eid, $TB_EXPT_MODIFY)) {
96
    USERERROR("You do not have permission for $exp_eid!", 1);
97 98 99 100 101 102 103 104 105 106
}

#
# 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><br>
107
          Experiment $action canceled!
108 109 110 111 112 113 114 115
          </h2></center>\n";
    
    PAGEFOOTER();
    return;
}

if (!$confirmed) {
    echo "<center><h2><br>
116 117 118 119 120
          Are you sure you want to ";
    if ($force) {
	    echo "<font color=red><br>forcibly</br></font> ";
    }
    echo "$action experiment '$exp_eid?'
121 122 123 124 125 126
          </h2>\n";
    
    echo "<form action='swapexp.php3?inout=$inout&pid=$exp_pid&eid=$exp_eid'
                method=post>";
    echo "<b><input type=submit name=confirmed value=Confirm></b>\n";
    echo "<b><input type=submit name=canceled value=Cancel></b>\n";
127 128 129 130 131

    if ($force) {
	    echo "<input type=hidden name=force value=$force>\n";
    }
    
132
    echo "</form>\n";
133 134 135 136 137 138 139 140 141 142 143

    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";
    }
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
    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>
#
echo "<center><br>";
163
echo "<h2>Starting experiment $action. Please wait a moment ...
164 165 166 167 168 169 170 171 172
      </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. 
#
173 174 175 176
# Avoid SIGPROF in child.
# 
set_time_limit(0);

177 178 179
$output = array();
$retval = 0;
$result = exec("$TBSUEXEC_PATH $uid $unix_gid ".
180 181 182
	       ($force ?
		"webidleswap $exp_pid $exp_eid" :
		"webswapexp -s $inout $exp_pid $exp_eid"),
183 184
 	       $output, $retval);

185
if ($retval) {
186
    echo "<br><br><h2>
187
          $action failure($retval): Output as follows:
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204
          </h2>
          <br>
          <XMP>\n";
          for ($i = 0; $i < count($output); $i++) {
              echo "$output[$i]\n";
          }
    echo "</XMP>\n";

    PAGEFOOTER();
    die("");
}

#
# Exit status 0 means the experiment is swapping, or will be.
#
echo "<br><br><h3>\n";
if ($retval == 0) {
205
    if (strcmp($inout, "in") == 0)
206
	$howlong = "two to ten";
207 208 209
    else
	$howlong = "less than two";
    
210 211 212
    echo "Experiment
	  <a href='showexp.php3?pid=$exp_pid&eid=$exp_eid'>$exp_eid</a>
          in project <A href='showproject.php3?pid=$exp_pid'>$exp_pid</A>
213
          has started its $action.
214
          <br><br>
215 216
          You will be notified via email when the operation is complete.
          This typically takes $howlong minutes, depending on the
217
          number of nodes in the experiment. 
218
          If you do not receive email notification within a reasonable amount
219 220
          of time, please contact $TBMAILADDR.
          <br><br>
221
          While you are waiting, you can watch the log
222 223
          in <a target=_blank href=spewlogfile.php3?pid=$exp_pid&eid=$exp_eid>
          realtime</a>.\n";
224 225 226 227 228 229 230 231
}
echo "</h3>\n";

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