Commit 3b539cbc authored by Leigh Stoller's avatar Leigh Stoller

Flyspray #126: Add ability to delete a preview instance.

parent 74e080e3
......@@ -1721,12 +1721,11 @@ sub Create($$)
my $query = "insert into experiment_template_instances set ".
join(",", map("$_='" . $argref->{$_} . "'", keys(%{$argref})));
# Give it an initial start time; updated later.
$query .= ", "
if (defined($argref) && scalar(keys%{$argref}));
$query .= "start_time=now(),continue_time=now() ";
$query .= ",description=$description"
if (defined($description));
if (defined($description)) {
$query .= ", "
if (defined($argref) && scalar(keys%{$argref}));
$query .= "description=$description";
}
my $query_result = DBQueryWarn($query);
return undef
......@@ -2019,7 +2018,7 @@ sub Experiment($)
#
# Delete a template instance record.
#
sub Delete($$$)
sub Delete($)
{
my ($self) = @_;
......
......@@ -454,6 +454,9 @@ if (!$batch && !$template_mode) {
}
TBdbfork();
}
# Give the web page a chance to start looking at the log file before
# the entire experiment is gone.
sleep(1);
#
# When in waitmode, must put ourselves in another process group so that
......
......@@ -63,6 +63,7 @@ my $logname;
my $exptidx;
my $template;
my $instance;
my $neveractive = 0;
# For the END block below.
my $cleaning = 0;
my $justexit = 1;
......@@ -178,6 +179,7 @@ if (! $batchmode) {
system("$swapexp -x -s out $pid $eid");
exit($? >> 8);
}
# Check for a pre-loaded instance (never active).
}
#
......@@ -247,6 +249,9 @@ if (! $batchmode) {
}
TBdbfork();
}
# Give the web page a chance to start looking at the log file before
# the entire experiment is gone.
sleep(1);
#
# When in waitmode, must put ourselves in another process group so that
......@@ -257,19 +262,21 @@ if ($waitmode) {
}
#
# Stop the current run.
# Stop the current run, but only if the instance was actually instantiated.
#
my $opt = ($force ? "-i" : "");
if (defined($instance->start_time())) {
my $opt = ($force ? "-i" : "");
system("$endrun $opt -a stop -f -e $eid $guid/$version") == 0
or fatal(-1, "Could not stop the current run!");
system("$endrun $opt -a stop -f -e $eid $guid/$version") == 0
or fatal(-1, "Could not stop the current run!");
# This sets the stop time.
$instance->Stop() == 0
or fatal(-1, "Could not stop experiment instance!");
# This sets the stop time.
$instance->Stop() == 0
or fatal(-1, "Could not stop experiment instance!");
}
#
# Now do the swapout.
# Now do the swapout (or just the termination).
#
# Note special -x option.
#
......@@ -283,9 +290,17 @@ system(@arguments);
fatal($? >> 8, "Could not terminate template instance")
if ($?);
# Reminder; instance records are not deleted!
$instance->Finalize() == 0
or fatal(-1, "Could not finalize experiment instance!");
if (defined($instance->start_time())) {
# Reminder; instance records are not deleted.
$instance->Finalize() == 0
or fatal(-1, "Could not finalize experiment instance!");
}
else {
# Okay, we *do* delete if the instance was never instantiated.
print("Deleting instance since it was never swapped in!\n");
$instance->Delete() == 0
or fatal(-1, "Could not delete instance!");
}
exit(0);
......
......@@ -117,6 +117,7 @@ include("dbdefs.php3");
include("user_defs.php");
include("group_defs.php");
include("project_defs.php");
include("experiment_defs.php");
#
# Control how error messages are returned to the user. If the session is
......
......@@ -17,20 +17,20 @@ LOGGEDINORDIE($uid);
include("showlogfile_sup.php3");
#
# Must provide the EID!
# Must provide the pid,eid
#
if (!isset($pid) ||
strcmp($pid, "") == 0) {
if (!isset($pid) || $pid == "") {
USERERROR("The project ID was not provided!", 1);
}
if (!isset($eid) ||
strcmp($eid, "") == 0) {
if (!isset($eid) || $eid == "") {
USERERROR("The experiment ID was not provided!", 1);
}
$exp_eid = $eid;
$exp_pid = $pid;
if (!TBvalid_pid($pid)) {
PAGEARGERROR("Invalid project ID.");
}
if (!TBvalid_eid($eid)) {
PAGEARGERROR("Invalid experiment ID.");
}
# Canceled operation redirects back to showexp page. See below.
if ($canceled) {
......@@ -44,31 +44,31 @@ if ($canceled) {
PAGEHEADER("Terminate Experiment");
#
# Check to make sure thats this is a valid PID/EID, while getting the
# experiment GID.
# Check to make sure thats this is a valid pid,eid.
#
if (! TBExptGroup($exp_pid, $exp_eid, $exp_gid)) {
USERERROR("The experiment $exp_eid is not a valid experiment ".
"in project $exp_pid.", 1);
$experiment = Experiment::LookupByPidEid($pid, $eid);
if (! $experiment) {
USERERROR("The experiment $pid/$eid is not a valid experiment!", 1);
}
$query_result =
DBQueryFatal("select lockdown FROM experiments WHERE ".
"eid='$exp_eid' and pid='$exp_pid'");
$row = mysql_fetch_array($query_result);
$lockdown = $row["lockdown"];
$lockdown = $experiment->lockdown();
$exptidx = $experiment->idx();
#
# Verify permissions.
#
if (! TBExptAccessCheck($uid, $exp_pid, $exp_eid, $TB_EXPT_DESTROY)) {
USERERROR("You do not have permission to end experiment $exp_eid!", 1);
if (! $experiment->AccessCheck($uid, $TB_EXPT_DESTROY)) {
USERERROR("You do not have permission to end experiment $pid/$eid!", 1);
}
echo "<font size=+2>Experiment <b>".
"<a href='showproject.php3?pid=$exp_pid'>$exp_pid</a>/".
"<a href='showexp.php3?pid=$exp_pid&eid=$exp_eid'>$exp_eid</a>".
"</b></font><br>\n";
# 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";
# A locked down experiment means just that!
if ($lockdown) {
......@@ -83,17 +83,14 @@ if ($lockdown) {
# browser back up a level.
#
if (!$confirmed) {
echo "<center><br><font size=+2>
Are you <b>REALLY</b>
sure you want to terminate Experiment '$exp_eid?'
</font>\n";
echo "<br>(This will <b>completely</b> destroy all trace of the
experiment)<br><br>\n";
SHOWEXP($exp_pid, $exp_eid, 1);
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";
SHOWEXP($pid, $eid, 1);
echo "<form action='endexp.php3?pid=$exp_pid&eid=$exp_eid' method=post>";
echo "<input type=hidden name=exp_pideid value=\"$exp_pideid\">\n";
echo "<form action='endexp.php3?pid=$pid&eid=$eid' method=post>";
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";
......@@ -102,20 +99,31 @@ if (!$confirmed) {
PAGEFOOTER();
return;
}
flush();
#
# We need the unix gid for the project for running the scripts below.
# Note usage of default group in project.
#
TBGroupUnixInfo($exp_pid, $exp_gid, $unix_gid, $unix_name);
$unix_gid = $experiment->UnixGID();
flush();
if ($instance) {
$guid = $instance->guid();
$vers = $instance->vers();
$command = "webtemplate_swapout -e $eid $guid/$vers";
}
else {
$command = "webendexp $pid $eid";
}
STARTBUSY("Terminating " . ($instance ? "Instance." : "Experiment."));
#
# Run the backend script.
#
$retval = SUEXEC($uid, "$exp_pid,$unix_gid", "webendexp $exp_pid $exp_eid",
SUEXEC_ACTION_IGNORE);
$retval = SUEXEC($uid, "$pid,$unix_gid", $command, SUEXEC_ACTION_IGNORE);
CLEARBUSY();
#
# Fatal Error. Report to the user, even though there is not much he can
......@@ -147,7 +155,7 @@ else {
If you do not receive email notification within a reasonable amount
of time, please contact $TBMAILADDR.\n";
echo "<br><br>\n";
STARTLOG($exp_pid, $exp_eid);
STARTLOG($pid, $eid);
}
#
......
......@@ -368,6 +368,10 @@ if ($expstate) {
WRITESUBMENUBUTTON("Terminate Experiment",
"endexp.php3?pid=$exp_pid&eid=$exp_eid");
}
elseif ($instance && $expstate == $TB_EXPTSTATE_SWAPPED) {
WRITESUBMENUBUTTON("Terminate Instance",
"endexp.php3?pid=$exp_pid&eid=$exp_eid");
}
# Batch experiments can be modifed only when paused.
if (!$instance && ($expstate == $TB_EXPTSTATE_SWAPPED ||
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment