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

10
11
12
13
14
#
# Standard Testbed Header
#
PAGEHEADER("Show Experiment Information");

15
16
17
#
# Only known and logged in users can end experiments.
#
18
$uid = GETLOGIN();
19
LOGGEDINORDIE($uid);
Leigh B. Stoller's avatar
Leigh B. Stoller committed
20
21

#
Leigh B. Stoller's avatar
Leigh B. Stoller committed
22
# Verify page arguments.
23
# 
Leigh B. Stoller's avatar
Leigh B. Stoller committed
24
25
26
if (!isset($pid) ||
    strcmp($pid, "") == 0) {
    USERERROR("You must provide a Project ID.", 1);
27
28
}

Leigh B. Stoller's avatar
Leigh B. Stoller committed
29
30
31
32
33
34
if (!isset($eid) ||
    strcmp($eid, "") == 0) {
    USERERROR("You must provide an Experiment ID.", 1);
}
$exp_eid = $eid;
$exp_pid = $pid;
35

Leigh B. Stoller's avatar
Leigh B. Stoller committed
36
#
Leigh B. Stoller's avatar
Leigh B. Stoller committed
37
# Check to make sure this is a valid PID/EID tuple.
Leigh B. Stoller's avatar
Leigh B. Stoller committed
38
#
39
if (! TBValidExperiment($exp_pid, $exp_eid)) {
40
41
  USERERROR("The experiment $exp_eid is not a valid experiment ".
            "in project $exp_pid.", 1);
Leigh B. Stoller's avatar
Leigh B. Stoller committed
42
43
}

44
#
Leigh B. Stoller's avatar
Leigh B. Stoller committed
45
# Verify Permission.
46
#
Leigh B. Stoller's avatar
Leigh B. Stoller committed
47
48
if (! TBExptAccessCheck($uid, $exp_pid, $exp_eid, $TB_EXPT_READINFO)) {
    USERERROR("You do not have permission to view experiment $exp_eid!", 1);
Leigh B. Stoller's avatar
Leigh B. Stoller committed
49
50
}

51
52
53
54
#
# Need some DB info.
#
$query_result =
55
    DBQueryFatal("select e.idx,e.state,e.batchmode,e.batchstate,s.rsrcidx ".
56
57
58
		 "  from experiments as e ".
		 "left join experiment_stats as s on s.exptidx=e.idx ".
		 "where e.eid='$eid' and e.pid='$pid'");
59
60
61
62
63
64
$row        = mysql_fetch_array($query_result);
$expindex   = $row["idx"];
$expstate   = $row["state"];
$rsrcidx    = $row["rsrcidx"];
$isbatch    = $row["batchmode"];
$batchstate = $row["batchstate"];
Chad Barb's avatar
   
Chad Barb committed
65

Chad Barb's avatar
   
Chad Barb committed
66
echo "<font size=+2>Experiment <b>".
Chad Barb's avatar
   
Chad Barb committed
67
     "<a href='showproject.php3?pid=$pid'>$pid</a>/".
68
     "<a href='showexp.php3?pid=$pid&eid=$eid'>$eid</a></b></font>\n";
Chad Barb's avatar
   
Chad Barb committed
69
echo "<br /><br />\n";
70
SUBPAGESTART();
Chad Barb's avatar
   
Chad Barb committed
71

72
SUBMENUSTART("Experiment Options");
73

74
if ($expstate) {
75
    if (TBExptLogFile($exp_pid, $exp_eid)) {
76
	WRITESUBMENUBUTTON("View Activity Logfile",
77
78
79
			   "spewlogfile.php3?pid=$exp_pid&eid=$exp_eid");
    }
      
80
    if (strcmp($expstate, $TB_EXPTSTATE_ACTIVE) == 0) {
Jay Lepreau's avatar
Jay Lepreau committed
81
	WRITESUBMENUBUTTON("Visualization, NS File, Mapping",
82
83
84
			   "shownsfile.php3?pid=$exp_pid&eid=$exp_eid");
    }
    else {
85
	WRITESUBMENUBUTTON("Visualization and NS File",
86
87
			   "shownsfile.php3?pid=$exp_pid&eid=$exp_eid");
    }
Leigh B. Stoller's avatar
Leigh B. Stoller committed
88
89
    WRITESUBMENUBUTTON("Download NS File",
		       "spitnsdata.php3?pid=$exp_pid&eid=$exp_eid");
90
91

    # Swap option.
92
93
94
95
96
97
98
99
100
101
102
103
104
    if ($isbatch) {
	if (strcmp($batchstate, TBDB_BATCHSTATE_PAUSED) == 0) {
	    WRITESUBMENUBUTTON("Queue Batch Experiment",
			"swapexp.php3?inout=in&pid=$exp_pid&eid=$exp_eid");
	}
	elseif (strcmp($batchstate, TBDB_BATCHSTATE_RUNNING) == 0) {
	    WRITESUBMENUBUTTON("Stop Batch Experiment",
			"swapexp.php3?inout=out&pid=$exp_pid&eid=$exp_eid");
	}
	elseif (strcmp($batchstate, TBDB_BATCHSTATE_POSTED) == 0) {
	    WRITESUBMENUBUTTON("Pause Batch Experiment",
			"swapexp.php3?inout=pause&pid=$exp_pid&eid=$exp_eid");
	}
105
    }
106
107
108
109
110
111
112
113
114
115
116
117
118
119
    else {
	if (strcmp($expstate, $TB_EXPTSTATE_SWAPPED) == 0) {
	    WRITESUBMENUBUTTON("Swap Experiment In",
			"swapexp.php3?inout=in&pid=$exp_pid&eid=$exp_eid");
	}
	elseif (strcmp($expstate, $TB_EXPTSTATE_ACTIVE) == 0) {
	    WRITESUBMENUBUTTON("Swap Experiment Out",
			"swapexp.php3?inout=out&pid=$exp_pid&eid=$exp_eid");
	}
    }
    WRITESUBMENUBUTTON("Terminate Experiment",
		       "endexp.php3?pid=$exp_pid&eid=$exp_eid");
    
    if (strcmp($expstate, $TB_EXPTSTATE_ACTIVE) == 0) {
120
	WRITESUBMENUBUTTON("Modify Traffic Shaping",
121
			   "delaycontrol.php3?pid=$exp_pid&eid=$exp_eid");
Chad Barb's avatar
   
Chad Barb committed
122
    }
123
124
}

125
$editflip = ($edit ? 0 : 1);
Jay Lepreau's avatar
Jay Lepreau committed
126
WRITESUBMENUBUTTON("Edit Experiment Metadata",
127
		   "showexp.php3?pid=$exp_pid&eid=$exp_eid&edit=$editflip");
128

129
130
131
132
133
134
135
136
#
# Admin and project/experiment leader get this option.
#
if (TBExptAccessCheck($uid, $exp_pid, $exp_eid, $TB_EXPT_UPDATEACCOUNTS)) {
    WRITESUBMENUBUTTON("Update Mounts/Accounts",
		       "updateaccounts.php3?pid=$exp_pid&eid=$exp_eid");
}

137
138
# Reboot option
if (TBExptAccessCheck($uid, $exp_pid, $exp_eid, $TB_EXPT_MODIFY)) {
139
    WRITESUBMENUBUTTON("Reboot All Nodes",
140
		       "boot.php3?pid=$exp_pid&eid=$exp_eid");
141
142
143
144
145
    # Batch experiments can be modifed only when paused.
    if (! ($isbatch && strcmp($batchstate, TBDB_BATCHSTATE_PAUSED))) {
	WRITESUBMENUBUTTON("Modify Experiment",
			   "modifyexp.php3?pid=$exp_pid&eid=$exp_eid");
    }
146
147
}

148
149
150
151
# History
WRITESUBMENUBUTTON("Show History",
		   "showstats.php3?showby=expt&which=$expindex");

152
if (ISADMIN($uid)) {
Chad Barb's avatar
   
Chad Barb committed
153
    if (strcmp($expstate, $TB_EXPTSTATE_ACTIVE) == 0) {		
154
	SUBMENUSECTION("Beta-Test Options");
155
	WRITESUBMENUBUTTON("Restart Experiment",
Chad Barb's avatar
   
Chad Barb committed
156
157
158
			   "swapexp.php3?inout=restart&pid=$exp_pid".
			   "&eid=$exp_eid");

159
160
161
162
163
164
165
166
167
	SUBMENUSECTION("Admin Options");
	
	WRITESUBMENUBUTTON("Send a Swap Request",
			   "request_swapexp.php3?".
			   "&pid=$exp_pid&eid=$exp_eid");
	
	WRITESUBMENUBUTTON("Force Swap Out (Idle-Swap)",
			   "swapexp.php3?inout=out&force=1".
			   "&pid=$exp_pid&eid=$exp_eid");
Chad Barb's avatar
Chad Barb committed
168
	
169
170
171
172
	SUBMENUSECTIONEND();
    }
}
    
Chad Barb's avatar
   
Chad Barb committed
173
174
SUBMENUEND_2A();

175
176
echo "<br>
      <a href='shownsfile.php3?pid=$exp_pid&eid=$exp_eid'>
177
178
         <img border=1 alt='experiment vis'
              src='showthumb.php3?idx=$rsrcidx'></a>\n";
Chad Barb's avatar
   
Chad Barb committed
179
180

SUBMENUEND_2B();
181

182
183
# if we got a submission of changes, update the db now...
if ($submit) {
184
185
    # Find out our limit
    $idlethresh = TBGetSiteVar("idle/threshold");
186
187
188
    $exp_name = addslashes(str_replace('"',"",$exp_name));
    $noswap = addslashes(str_replace('"',"",$noswap));
    $noidleswap = addslashes(str_replace('"',"",$noidleswap));
189
    $mail=0;
190
191
192
193
194
195
196
197
198
    $strs = array();
    $errors = array();
    if (isset($exp_name)) {
	if ($exp_name!="") {
	    $strs[] = "expt_name=\"$exp_name\"";
	} else {
	    $errors['Expt. Name'] = "Missing/Blank Field";
	}
    }
199
    if (isset($noswap)) {
200
	$strs[] = "noswap_reason=\"$noswap\"";
201
	$mail=1;
202
    }
203
    if (isset($noidleswap)) {
204
	$strs[].= "noidleswap_reason=\"$noidleswap\"";
205
	$mail=1;
206
    }
207
208
209
210
211
212
213
    if (isset($idleswap)) {
	if ($idleswap>0 && $idleswap <= $idlethresh && $idleswap !="") {
	    $strs[] = "idleswap_timeout=\"".(60*$idleswap)."\"";
	    $mail=1;
	} else {
	    $errors['Idle-Swap'] ="Time must be non-zero and <= $idlethresh";
	}
214
    }
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
    if (isset($autoswap)) {
	if ($autoswap>=0 && $autoswap !="") {
	    $strs[] = "autoswap_timeout=\"".(60*$autoswap)."\"";
	    $mail=1;
	} else {
	    $errors['Max Duration'] = "Time must be non-zero";
	}
    }
    if ($errors) {
	echo "<table class=nogrid
                     align=center border=0 cellpadding=6 cellspacing=0>
              <tr>
                 <th align=center colspan=2>
                   <font size=+1 color=red>
                      &nbsp;Oops, please fix the following errors!&nbsp;
                   </font>
                 </td>
              </tr>\n";

	while (list ($name, $message) = each ($errors)) {
	    echo "<tr>
                     <td align=right>
                       <font color=red>$name:&nbsp;</font></td>
                     <td align=left>
                       <font color=red>$message</font></td>
                  </tr>\n";
	}
	echo "</table><br>\n";
	# Jump back into edit mode
	$edit=1;
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
	$mail=0;
    } else {
	$q = DBQueryFatal("select * from experiments ".
			  "where pid='$pid' and eid='$eid'");
	$r = mysql_fetch_array($q);
	$olds = ($r[swappable] ? "Yes" : "No");
	$oldsr= $r[noswap_reason];
	$oldi = ($r[idleswap] ? "Yes" : "No");
	$oldit= $r[idleswap_timeout] / 60.0;
	$oldir= $r[noidleswap_reason];
	$olda = ($r[autoswap] ? "Yes" : "No");
	$oldat= $r[autoswap_timeout] / 60.0;
	if (count($strs)>0) {
	    $str = implode(",",$strs);
	    DBQueryWarn("update experiments set $str ".
			"where pid='$pid' and eid='$eid'");
	}
262
    }
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
    if ($mail) {
	$q = DBQueryFatal("select * from experiments ".
			  "where pid='$pid' and eid='$eid'");
	$r = mysql_fetch_array($q);
	$s = ($r[swappable] ? "Yes" : "No");
	$sr= $r[noswap_reason];
	$i = ($r[idleswap] ? "Yes" : "No");
	$it= $r[idleswap_timeout] / 60.0;
	$ir= $r[noidleswap_reason];
	$a = ($r[autoswap] ? "Yes" : "No");
	$at= $r[autoswap_timeout] / 60.0;
	$cuid = $r[expt_head_uid];
	$suid= $r[expt_swap_uid];
	TBUserInfo($uid, $user_name, $user_email);
	TBUserInfo($cuid, $cname, $cemail);
	TBUserInfo($suid, $sname, $semail);
279
280
281
282
283
284
285
286
	# Do not send this email if the user is an administrator
	# (adminmode does not matter), and is changing an expt
	# he created or swapped in. Pointless email.
	if (! (ISADMINISTRATOR() &&
	       (!strcmp($uid, $cuid) || !strcmp($uid, $suid)))) {
	    TBMAIL($TBMAIL_OPS,"$pid/$eid swap settings changed",
		   "\nThe swap settings for $pid/$eid have changed.\n".
		   "\nThe reasons and/or timeouts have changed.\n".
287
288
289
290
		   "\nThe old settings were:\n".
		  #"Swappable:\t$olds\t($oldsr)\n".
		   "Idleswap:\t$oldi\t(after $oldit hrs)\t($oldir)\n".
		   "MaxDuration:\t$olda\t(after $oldat hrs)\n".
291
292
293
		   "\nThe new settings are:\n".
		  #"Swappable:\t$s\t($sr)\n".
		   "Idleswap:\t$i\t(after $it hrs)\t($ir)\n".
294
		   "MaxDuration:\t$a\t(after $at hrs)\n".
295
296
297
298
299
300
301
302
303
304
		   "\nCreator:\t$cuid ($cname <$cemail>)\n".
		   "Swapper:\t$suid ($sname <$semail>)\n".
		   "\nIf it is necessary to change these settings, ".
		   "please reply to this message \nto notify the user, ".
		   "then change the settings here:\n\n".
		   "$TBBASE/showexp.php3?pid=$pid&eid=$eid\n\n".
		   "Thanks,\nTestbed WWW\n",
		   "From: $user_name <$user_email>\n".
		   "Errors-To: $TBMAIL_WWW");
	}
305
    }
306
307
308
309
310
}

# Dump (possibly updated) experiment record.
if (!isset($edit)) { $edit=0; }
SHOWEXP($exp_pid, $exp_eid, $edit);
311

312
SUBPAGEEND();
313
314
315
316
317
318

#
# Dump the node information.
#
SHOWNODES($exp_pid, $exp_eid);

319
320
321
322
323
324
325
326
if (ISADMIN($uid)) {
    echo "<center>
          <h3>Experiment Stats</h3>
         </center>\n";

    SHOWEXPTSTATS($exp_pid, $exp_eid);
}

327
328
329
330
#
# Standard Testbed Footer
# 
PAGEFOOTER();
331
?>