remapexp.php3 4.5 KB
Newer Older
1 2
<?php
#
3
# Copyright (c) 2000-2011 University of Utah and the Flux Group.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
# 
# {{{EMULAB-LICENSE
# 
# This file is part of the Emulab network testbed software.
# 
# This file is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or (at
# your option) any later version.
# 
# This file is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public
# License for more details.
# 
# You should have received a copy of the GNU Affero General Public License
# along with this file.  If not, see <http://www.gnu.org/licenses/>.
# 
# }}}
23 24 25 26 27 28
#
include("defs.php3");

#
# Only known and logged in users can do this.
#
29 30 31
$this_user = CheckLoginOrDie();
$uid       = $this_user->uid();
$isadmin   = ISADMIN();
32 33

#
34
# Verify page arguments.
35
#
36 37 38 39 40 41 42 43 44 45 46 47 48
$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();
49 50
$project  = $experiment->Project();
$unix_pid = $project->unix_gid();
51

52 53 54
if (!$experiment->AccessCheck($this_user, $TB_EXPT_MODIFY)) {
    USERERROR("You do not have permission to run remap on $pid/$eid!", 1);
}
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69

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;
}

70 71
PAGEHEADER("Remap Virtual Nodes");

72
if (isset($canceled) && $canceled) {
73 74 75 76 77 78 79 80
    echo "<center><h3><br>
          Operation canceled!
          </h3></center>\n";
    
    PAGEFOOTER();
    return;
}

81 82 83
if (!isset($confirmed)) {
    echo $experiment->PageHeader();
    echo "<br>\n";
84 85 86 87 88

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

89
    $experiment->Show(1);
90

91
    $url = CreateURL("remapexp", $experiment);
92

93
    echo "<form action='$url' method=post>";
94 95 96 97 98 99 100 101 102
    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;
}

103 104 105 106 107 108
#
# Need to pass out the NS data.
#
if (! ($nsdata = $experiment->NSFile())) {
    # XXX what to do...
    $nsdata = "";
109 110 111 112 113 114 115 116 117 118 119 120 121 122
}

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);

123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
#	
# 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");
138
$retval = SUEXEC($uid, "$unix_pid,$unix_gid",
139
		 "webswapexp $optargs -s modify $pid $eid $nsfile",
140
		 SUEXEC_ACTION_IGNORE);
141
CLEARBUSY();
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
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 {
162 163
    $showlog_url = CreateURL("showlogfile", $experiment);
    
164
    #
165
    # Exit status 0 means the experiment is remapping.
166 167 168 169 170 171 172 173 174 175 176 177 178
    #
    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 ".
179
	"<a href='$url'>realtime</a>.\n";
180 181 182 183 184 185 186
}

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