swapexp.php3 4.73 KB
Newer Older
1
<?php
Leigh B. Stoller's avatar
Leigh B. Stoller committed
2
3
4
5
6
#
# EMULAB-COPYRIGHT
# Copyright (c) 2000-2002 University of Utah and the Flux Group.
# All rights reserved.
#
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
include("defs.php3");

#
# Standard Testbed Header
#
PAGEHEADER("Swap an Experiment");

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

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

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

if (!isset($inout) ||
    (strcmp($inout, "in") && strcmp($inout, "out"))) {
  USERERROR("The swap direction must be either in or out!", 1);
}

$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) {
  USERERROR("The experiment $exp_eid is not a valid experiment ".
            "in project $exp_pid.", 1);
}
$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)) {
    USERERROR("You do not have permission to swap experiment $exp_eid!", 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><br>
          Experiment swap$inout canceled!
          </h2></center>\n";
    
    PAGEFOOTER();
    return;
}

if (!$confirmed) {
    echo "<center><h2><br>
          Are you sure you want to swap$inout experiment '$exp_eid?'
          </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";
    echo "</form>\n";
100
101
102
    echo "<p>
          <a href='$TBDOCBASE/faq.php3#UTT-Swapping'>
             (Information on experiment swapping)</a>\n";
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
    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>";
echo "<h2>Starting experiment swap$inout. Please wait a moment ...
      </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. 
#
132
133
134
135
# Avoid SIGPROF in child.
# 
set_time_limit(0);

136
137
138
139
140
141
$output = array();
$retval = 0;
$result = exec("$TBSUEXEC_PATH $uid $unix_gid ".
	       "webswapexp -s $inout $exp_pid $exp_eid",
 	       $output, $retval);

142
if ($retval) {
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
    echo "<br><br><h2>
          Swap Failure($retval): Output as follows:
          </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) {
162
    if (strcmp($inout, "in") == 0)
163
	$howlong = "two to ten";
164
165
166
    else
	$howlong = "less than two";
    
167
168
169
170
    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>
          is swapping $inout.
171
172
          <br><br>
          You will be notified via email when the experiment has finished
173
174
          swapping. This typically takes $howlong minutes, depending on the
          number of nodes in the experiment. 
175
          If you do not receive email notification within a reasonable amount
176
177
178
179
180
          of time, please contact $TBMAILADDR.
          <br><br>
          While you are waiting, you can watch the log of experiment swap
          in <a target=_blank href=spewlogfile.php3?pid=$exp_pid&eid=$exp_eid>
          realtime</a>.\n";
181
182
183
184
185
186
187
188
}
echo "</h3>\n";

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