remapexp.php3 3.74 KB
Newer Older
1 2 3
<?php
#
# EMULAB-COPYRIGHT
4
# Copyright (c) 2000-2007 University of Utah and the Flux Group.
5 6 7 8 9 10 11
# All rights reserved.
#
include("defs.php3");

#
# Only known and logged in users can do this.
#
12 13 14
$this_user = CheckLoginOrDie();
$uid       = $this_user->uid();
$isadmin   = ISADMIN();
15 16

#
17
# Verify page arguments.
18
#
19 20 21 22 23 24 25 26 27 28 29 30 31
$reqargs = RequiredPageArguments("experiment",   PAGEARG_EXPERIMENT);
$optargs = OptionalPageArguments("canceled",     PAGEARG_STRING,
				 "reboot",       PAGEARG_BOOLEAN,
				 "eventrestart", PAGEARG_BOOLEAN,
				 "confirmed",    PAGEARG_STRING);

#
# Need these below
#
$pid = $experiment->pid();
$eid = $experiment->eid();
$unix_gid = $experiment->UnixGID();
$expstate = $experiment->state();
32

33 34 35
if (!$experiment->AccessCheck($this_user, $TB_EXPT_MODIFY)) {
    USERERROR("You do not have permission to run remap on $pid/$eid!", 1);
}
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50

if (strcmp($expstate, $TB_EXPTSTATE_ACTIVE) &&
    strcmp($expstate, $TB_EXPTSTATE_SWAPPED)) {
    USERERROR("You cannot remap an experiment in transition.", 1);
}

if (!strcmp($expstate, $TB_EXPTSTATE_ACTIVE)) {
	$reboot = 1;
	$eventrestart = 1;
}
else {
	$reboot = 0;
	$eventrestart = 0;
}

51 52
PAGEHEADER("Remap Virtual Nodes");

53
if (isset($canceled) && $canceled) {
54 55 56 57 58 59 60 61
    echo "<center><h3><br>
          Operation canceled!
          </h3></center>\n";
    
    PAGEFOOTER();
    return;
}

62 63 64
if (!isset($confirmed)) {
    echo $experiment->PageHeader();
    echo "<br>\n";
65 66 67 68 69

    echo "<center><font size=+2><br>
              Are you sure you want to remap your experiment?
              </font>\n";

70
    $experiment->Show(1);
71

72
    $url = CreateURL("remapexp", $experiment);
73

74
    echo "<form action='$url' method=post>";
75 76 77 78 79 80 81 82 83
    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";
    echo "</center>\n";

    PAGEFOOTER();
    return;
}

84 85 86 87 88 89
#
# Need to pass out the NS data.
#
if (! ($nsdata = $experiment->NSFile())) {
    # XXX what to do...
    $nsdata = "";
90 91 92 93 94 95 96 97 98 99 100 101 102 103
}

list($usec, $sec) = explode(' ', microtime());
srand((float) $sec + ((float) $usec * 100000));
$foo = rand();
$nsfile = "/tmp/$uid-$foo.nsfile";

if (! ($fp = fopen($nsfile, "w"))) {
    TBERROR("Could not create temporary file $nsfile", 1);
}
fwrite($fp, $nsdata);
fclose($fp);
chmod($nsfile, 0666);

104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
#	
# Avoid SIGPROF in child.
# 
set_time_limit(0);

# optargs.
$optargs = "";
if (isset($reboot) && $reboot) {
     $optargs .= " -r ";
}
if (isset($eventrestart) && $eventrestart) {
     $optargs .= " -e ";
}

STARTBUSY("Starting experiment remap");
119
$retval = SUEXEC($uid, "$pid,$unix_gid",
120
		 "webswapexp $optargs -s modify $pid $eid $nsfile",
121
		 SUEXEC_ACTION_IGNORE);
122
CLEARBUSY();
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
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) {
    SUEXECERROR(SUEXEC_ACTION_DIE);
    #
    # Never returns ...
    #
    die("");
}

echo "<br>\n";
if ($retval) {
    echo "<h3>Experiment remap could not proceed: $retval</h3>";
    echo "<blockquote><pre>$suexec_output<pre></blockquote>";
}
else {
143 144
    $showlog_url = CreateURL("showlogfile", $experiment);
    
145
    #
146
    # Exit status 0 means the experiment is remapping.
147 148 149 150 151 152 153 154 155 156 157 158 159
    #
    echo "<br>";
    echo "Your experiment is being remapped!<br><br>";

    echo "You will be notified via email when the experiment has ".
	"finished remapping 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 ".
160
	"<a href='$url'>realtime</a>.\n";
161 162 163 164 165 166 167
}

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