modifyexp.php3 7.96 KB
Newer Older
Chad Barb's avatar
   
Chad Barb committed
1
2
3
<?php
#
# EMULAB-COPYRIGHT
4
# Copyright (c) 2000-2005 University of Utah and the Flux Group.
Chad Barb's avatar
   
Chad Barb committed
5
6
7
8
9
10
11
12
13
14
15
16
# All rights reserved.
#
include("defs.php3");
include("showstuff.php3");

$parser   = "$TB/libexec/ns2ir/parse-ns";

#
# Standard Testbed Header
#
PAGEHEADER("Modify Experiment");

Chad Barb's avatar
   
Chad Barb committed
17
# the following hack is a page for Netbuild to
18
# point the users browser at after a successful modify.
Chad Barb's avatar
   
Chad Barb committed
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# this does no error checking.
if ($justsuccess) {
    echo "<br /><br />";
    echo "<font size=+1>
	  <p>Experiment
          <a href='showexp.php3?pid=$pid&eid=$eid'>$eid</a>
          in project <A href='showproject.php3?pid=$pid'>$pid</A>
          is being modified!</p><br />
	  <p>You will be notified via email when the operation is complete.
          This could take one to ten minutes, depending on
          whether nodes were added to the experiments, and whether
          disk images had to be loaded.</p>
          <p>While you are waiting, you can watch the log 
          in <a target=_blank href=spewlogfile.php3?pid=$pid&eid=$eid>
          realtime</a>.</p></font>\n";
    PAGEFOOTER();
    return;
}

Chad Barb's avatar
   
Chad Barb committed
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
#
# Only known and logged in users can modify experiments.
#
$uid = GETLOGIN();
LOGGEDINORDIE($uid);

$isadmin = ISADMIN($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);
}

#
# Be paranoid.
#
$pid = addslashes($pid);
$eid = addslashes($eid);

#
65
66
67
68
69
70
71
# Check to make sure this is a valid experiment.
#
if (! TBValidExperiment($pid, $eid)) {
    # Netbuild requires the following line.
    echo "\n\n<!-- NetBuild! Experiment does not exist -->\n\n";	
    USERERROR("The experiment $eid is not a valid experiment ".
	      "in project $pid.", 1);
Chad Barb's avatar
   
Chad Barb committed
72
73
}

74
75
76
77
if (! TBExptAccessCheck($uid, $pid, $eid, $TB_EXPT_MODIFY)) {
    # Netbuild requires the following line.
    echo "\n\n<!-- NetBuild! No permission to modify -->\n\n";	
    USERERROR("You do not have permission to modify this experiment.", 1);
Chad Barb's avatar
   
Chad Barb committed
78
79
}

80
81
82
83
84
85
if (TBExptLockedDown($pid, $eid)) {
    # Netbuild requires the following line.
    echo "\n\n<!-- NetBuild! No permission to modify -->\n\n";	
    USERERROR("Cannot proceed; experiment is locked down!", 1);
}

86
87
$expstate = TBExptState($pid, $eid);

Chad Barb's avatar
   
Chad Barb committed
88
89
if (strcmp($expstate, $TB_EXPTSTATE_ACTIVE) &&
    strcmp($expstate, $TB_EXPTSTATE_SWAPPED)) {
90
91
92
    # Netbuild requires the following line.
    echo "\n\n<!-- NetBuild! Experiment is in transition. -->\n\n";	
    USERERROR("You cannot modify an experiment in transition.", 1);
Chad Barb's avatar
   
Chad Barb committed
93
94
}

95
96
97
98
99
# Okay, start.
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";
echo "<br><br>\n";
Chad Barb's avatar
   
Chad Barb committed
100

101
102
103
#
# Put up the modify form on first load.
# 
Chad Barb's avatar
   
Chad Barb committed
104
if (! isset($go)) {
105
106
107
108
109
110
111
112
113
114
115
116
    echo "<a href='faq.php3#UTT-Modify'>".
	 "Modify Experiment Documentation (FAQ)</a></h3>";
    echo "<br>";

    #
    # Unreleased option?
    # 
    if ($isadmin) {
	echo "<font size='+1'>You can ".
	    "<a href='buildui/bui.php3?action=modify&pid=$pid&eid=$eid'>".
	    "modify this experiment with NetBuild</a>, ".
	    "or edit the NS directly:</font>";
Chad Barb's avatar
   
Chad Barb committed
117
	echo "<br>";
118
119
120
121
    }

    echo "<form action='modifyexp.php3' method='post'>";
    echo "<textarea cols='100' rows='40' name='nsdata'>";
Chad Barb's avatar
   
Chad Barb committed
122

123
124
125
126
127
128
    $query_result =
	DBQueryFatal("SELECT nsfile from nsfiles ".
		     "where pid='$pid' and eid='$eid'");
    if (mysql_num_rows($query_result)) {
	$row    = mysql_fetch_array($query_result);
	$nsfile = stripslashes($row[nsfile]);
Chad Barb's avatar
   
Chad Barb committed
129
	    
130
131
132
133
134
	echo "$nsfile";
    }
    else {
	echo "# There was no stored NS file for $pid/$eid.\n";
    }
Chad Barb's avatar
   
Chad Barb committed
135
	
136
137
138
139
    echo "</textarea>";
    echo "<br>";
    if (!strcmp($expstate, $TB_EXPTSTATE_ACTIVE)) {
	echo "<p><b>Note!</b> It is recommended that you 
Chad Barb's avatar
   
Chad Barb committed
140
	      reboot all nodes in your experiment by checking the box below.
141
142
143
144
	      This is especially important if changing your experiment
              topology (adding or removing nodes, links, and LANs).
	      If adding/removing a delay to/from an existing link, or
              replacing a lost node <i>without modifying the experiment
145
146
147
148
              topology</i>, this won't be necessary. Restarting the
	      event system is also highly recommended since the same nodes
	      in your virtual topology may get mapped to different physical
	      nodes.</p>";
149
	echo "<input type='checkbox' name='reboot' value='1' checked='1'>
Chad Barb's avatar
   
Chad Barb committed
150
	      Reboot nodes in experiment (Highly Recommended)</input>";
151
152
	echo "<br><input type='checkbox' name='eventrestart' value='1' checked='1'>
	      Restart Event System in experiment (Highly Recommended)</input>";
153
154
155
156
157
158
159
160
161
    }
    echo "<br>";
    echo "<input type='hidden' name='pid' value='$pid'>";
    echo "<input type='hidden' name='eid' value='$eid'>";
    echo "<input type='submit' name='go' value='Modify'>";
    echo "</form>\n";
    PAGEFOOTER();
    exit();
}
Chad Barb's avatar
   
Chad Barb committed
162

163
164
165
166
167
168
#
# Okay, form has been submitted.
#
if (! isset($nsdata)) {
    USERERROR("NSdata CGI variable missing (How did that happen?)",1);
}
Chad Barb's avatar
   
Chad Barb committed
169

170
171
172
173
174
175
176
177
178
179
#
# Generate a hopefully unique filename that is hard to guess.
# See backend scripts.
# 
list($usec, $sec) = explode(' ', microtime());
srand((float) $sec + ((float) $usec * 100000));
$foo = rand();
    
$nsfile = "/tmp/$uid-$foo.nsfile";

180
181
182
183
184
185
186
if (! ($fp = fopen($nsfile, "w"))) {
    TBERROR("Could not create temporary file $nsfile", 1);
}
$nsdata_string = $nsdata;
fwrite($fp, $nsdata_string);
fclose($fp);
chmod($nsfile, 0666);
187

188
189
190
191
192
193
194
195
196
#
# Get exp group so we can get the unix_gid.
#
TBExptGroup($pid, $eid, $gid);
TBGroupUnixInfo($pid, $gid, $unix_gid, $unix_name);

#
# Do an initial parse test.
#
197
$retval = SUEXEC($uid, "$pid,$unix_gid", "webnscheck $nsfile",
198
199
200
201
202
203
204
205
		 SUEXEC_ACTION_IGNORE);

if ($retval != 0) {
    unlink($nsfile);
    
    # Send error to tbops.
    if ($retval < 0) {
	SUEXECERROR(SUEXEC_ACTION_CONTINUE);
Chad Barb's avatar
   
Chad Barb committed
206
    }
207
208
    # Netbuild requires the following line.
    echo "\n\n<!-- NetBuild! Modifed NS file contains syntax errors -->\n\n";
209
210
211
212
213
214
215

    echo "<br>";
    echo "<h3>Modified NS file contains syntax errors</h3>";
    echo "<blockquote><pre>$suexec_output<pre></blockquote>";

    PAGEFOOTER();
    exit();
216
217
218
219
220
221
222
223
224
225
226
227
228
229
}

echo "<center>";
echo "<h2>Starting experiment modify. Please wait a moment ...
      </h2></center>";

flush();

#	
# Avoid SIGPROF in child.
# 
set_time_limit(0);

# Run the script.
230
$retval = SUEXEC($uid, "$pid,$unix_gid",
231
		 "webswapexp $rebootswitch " . ($reboot ? "-r " : "") .
232
		 ($eventrestart ? "-e " : "") .
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
		 "-s modify $pid $eid $nsfile",
		 SUEXEC_ACTION_IGNORE);
		 
# It has been copied out by the program!
unlink($nsfile);

#
# 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) {
    # the following line is required for Netbuild interaction.
    echo "\n\n<!-- Netbuild! Modify failed -->\n\n";

    SUEXECERROR(SUEXEC_ACTION_DIE);
    #
    # Never returns ...
    #
    die("");
}

#
# Exit status 0 means the experiment is swapping, or will be.
#
echo "<br>\n";
if ($retval) {
    echo "<h3>Experiment modify could not proceed</h3>";
    echo "<blockquote><pre>$suexec_output<pre></blockquote>";
    # the following line is required for Netbuild interaction.
    echo "\n\n<!-- Netbuild! Modify failed -->\n\n";
}
else {
    #
    # Exit status 0 means the experiment is modifying.
    #
    echo "<br>";
    echo "Your experiment is being modified!<br><br>";

    echo "You will be notified via email when the experiment has ".
	"finished modifying and you are able to proceed. This ".
	"typically takes less than 10 minutes, depending on the ".
	"number of nodes in the experiment. ".
	"If you do not receive email notification within a ".
	"reasonable amount time, please contact $TBMAILADDR. ".
	"<br><br>".
	"While you are waiting, you can watch the log of experiment ".
	"modification in ".
	"<a target=_blank href=spewlogfile.php3?pid=$pid&eid=$eid> ".
	"realtime</a>.\n";
	    
    # the following line is required for Netbuild.
    echo "\n\n<!-- Netbuild! success -->\n\n";
}

Chad Barb's avatar
   
Chad Barb committed
287
288
289
290
291
292
293
#
# Standard Testbed Footer
# 
PAGEFOOTER();
?>