endexp.php3 4.91 KB
Newer Older
Leigh Stoller's avatar
Leigh Stoller committed
1
<?php
Leigh Stoller's avatar
Leigh Stoller committed
2
#
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/>.
# 
# }}}
Leigh Stoller's avatar
Leigh Stoller committed
23
#
Leigh Stoller's avatar
Leigh Stoller committed
24
include("defs.php3");
Leigh Stoller's avatar
Leigh Stoller committed
25
include_once("template_defs.php");
26

Leigh Stoller's avatar
Leigh Stoller committed
27 28 29
#
# Only known and logged in users can end experiments.
#
30 31 32
$this_user = CheckLoginOrDie();
$uid       = $this_user->uid();
$isadmin   = ISADMIN();
Leigh Stoller's avatar
Leigh Stoller committed
33

34 35 36
# This will not return if its a sajax request.
include("showlogfile_sup.php3");

Leigh Stoller's avatar
Leigh Stoller committed
37
#
38 39 40 41 42 43
# Verify Page Arguments.
#
$reqargs = RequiredPageArguments("experiment", PAGEARG_EXPERIMENT);
$optargs = OptionalPageArguments("canceled",   PAGEARG_STRING,
				 "confirmed",  PAGEARG_STRING);
				 
44
# Canceled operation redirects back to showexp page. See below.
45 46
if (isset($canceled) && $canceled) {
    header("Location: ". CreateURL("showexp", $experiment));
47 48 49
    return;
}

50
#
51
# Standard Testbed Header, after checking for cancel above.
Leigh Stoller's avatar
Leigh Stoller committed
52
#
53
PAGEHEADER("Terminate Experiment");
54

55
# Need these below.
56
$lockdown = $experiment->lockdown();
57
$geniflags = $experiment->geniflags();
58
$exptidx  = $experiment->idx();
59 60
$pid      = $experiment->pid();
$eid      = $experiment->eid();
61

62 63 64 65 66 67
# Must go through the geni interfaces.
if ($geniflags) {
    USERERROR("You must terminate ProtoGeni experiments via the ".
	      "the ProtoGeni APIs!", 1);
}

68
#
Leigh Stoller's avatar
Leigh Stoller committed
69
# Verify permissions.
70
#
71
if (! $experiment->AccessCheck($this_user, $TB_EXPT_DESTROY)) {
72
    USERERROR("You do not have permission to end experiment $pid/$eid!", 1);
Leigh Stoller's avatar
Leigh Stoller committed
73 74
}

75 76 77 78 79 80 81 82 83
# Template Instance Experiments get special treatment in this page.
$instance = TemplateInstance::LookupByExptidx($exptidx);
if ($instance && ($experiment->state() != $TB_EXPTSTATE_SWAPPED)) {
    PAGEARGERROR("Invalid action for template instance");
}

# Spit experiment pid/eid at top of page.
echo $experiment->PageHeader();
echo "<br>\n";
84 85 86 87 88 89 90

# A locked down experiment means just that!
if ($lockdown) {
    echo "<br><br>\n";
    USERERROR("Cannot proceed; the experiment is locked down!", 1);
}
   
91 92 93
#
# 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
94 95
# set. Or, the user can hit the cancel button, in which case redirect the
# browser back up a level.
96
#
97
if (!isset($confirmed)) {
98 99 100 101 102
    echo "<center><br><font size=+2>Are you <b>REALLY</b> sure ";
    echo "you want to terminate " . ($instance ? "Instance " : "Experiment ");
    echo "'$eid?' </font>\n";
    echo "<br>(This will <b>completely</b> destroy all trace)<br><br>\n";

103 104 105
    $experiment->Show(1);

    $url = CreateURL("endexp", $experiment);
106
    
107
    echo "<form action='$url' method=post>";
108 109 110 111 112 113 114 115
    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;
}
116
flush();
117

Leigh Stoller's avatar
Leigh Stoller committed
118
#
119
# We need the unix gid for the project for running the scripts below.
Leigh Stoller's avatar
Leigh Stoller committed
120
#
121
$unix_gid = $experiment->UnixGID();
122 123
$project  = $experiment->Project();
$unix_pid = $project->unix_gid();
124

125 126 127 128 129 130 131
if ($instance) {
    $guid = $instance->guid();
    $vers = $instance->vers();
    
    $command = "webtemplate_swapout -e $eid $guid/$vers";
}
else {
132
    $command = "webendexp $exptidx";
133 134 135
}

STARTBUSY("Terminating " . ($instance ? "Instance." : "Experiment."));
Leigh Stoller's avatar
Leigh Stoller committed
136 137

#
138
# Run the backend script.
Leigh Stoller's avatar
Leigh Stoller committed
139
#
140
$retval = SUEXEC($uid, "$unix_pid,$unix_gid", $command, SUEXEC_ACTION_IGNORE);
141

142
HIDEBUSY();
143

144 145 146 147
#
# Fatal Error. Report to the user, even though there is not much he can
# do with the error. Also reports to tbops.
# 
148
if ($retval < 0) {
149 150 151 152
    SUEXECERROR(SUEXEC_ACTION_DIE);
    #
    # Never returns ...
    #
Leigh Stoller's avatar
Leigh Stoller committed
153 154 155
    die("");
}

156
#
157 158
# Exit status >0 means the operation could not proceed.
# Exit status =0 means the experiment is terminating in the background.
159 160
#
if ($retval) {
161
    echo "<h3>Termination could not proceed</h3>";
162
    echo "<blockquote><pre>$suexec_output<pre></blockquote>";
163 164
}
else {
165 166 167
    echo "<b>Termination has started!</b> 
          You will be notified via email when termination has completed
	  and you can reuse the name.
168
          This typically takes less than two minutes, depending on the
169
          number of nodes.
170 171
          If you do not receive email notification within a reasonable amount
          of time, please contact $TBMAILADDR.\n";
172
    echo "<br><br>\n";
173
    STARTLOG($experiment);
174
}
Leigh Stoller's avatar
Leigh Stoller committed
175

176 177 178 179
#
# Standard Testbed Footer
# 
PAGEFOOTER();
Leigh Stoller's avatar
Leigh Stoller committed
180
?>