Commit 95357b8a authored by Leigh B. Stoller's avatar Leigh B. Stoller

Some cleanup in endexp, and change how its called from pid eid to eid.

parent 31f4616f
...@@ -18,6 +18,7 @@ use lib '@prefix@/lib'; ...@@ -18,6 +18,7 @@ use lib '@prefix@/lib';
use libdb; use libdb;
use libtestbed; use libtestbed;
use libtblog; use libtblog;
use User;
use Project; use Project;
use Group; use Group;
use English; use English;
...@@ -111,13 +112,18 @@ sub Lookup($$;$) ...@@ -111,13 +112,18 @@ sub Lookup($$;$)
if (exists($experiments{"$idx"})); if (exists($experiments{"$idx"}));
my $query_result = my $query_result =
DBQueryWarn("select * from experiments where idx='$idx'"); DBQueryWarn("select e.*,i.parent_guid from experiments as e ".
"left join experiment_template_instances as i on ".
" i.exptidx=e.idx ".
"where e.idx='$idx'");
return undef return undef
if (!$query_result || !$query_result->numrows); if (!$query_result || !$query_result->numrows);
my $self = {}; my $self = {};
$self->{'EXPT'} = $query_result->fetchrow_hashref(); $self->{'EXPT'} = $query_result->fetchrow_hashref();
# An Instance?
$self->{'ISINSTANCE'} = defined($self->{'EXPT'}->{'parent_guid'});
$query_result = $query_result =
DBQueryWarn("select * from experiment_stats where exptidx='$idx'"); DBQueryWarn("select * from experiment_stats where exptidx='$idx'");
...@@ -1314,6 +1320,20 @@ sub SetSwapper($$) ...@@ -1314,6 +1320,20 @@ sub SetSwapper($$)
return $self->Refresh(); return $self->Refresh();
} }
#
# Get swapper (user) object.
#
sub GetSwapper($)
{
my ($self) = @_;
# Must be a real reference.
return undef
if (! ref($self));
return User->Lookup($self->swapper_idx());
}
# #
# Just the swap time. # Just the swap time.
# #
...@@ -1743,6 +1763,19 @@ sub DU($$) ...@@ -1743,6 +1763,19 @@ sub DU($$)
return -1; return -1;
} }
#
# Is this experiment a Template instance?
#
sub IsInstance($)
{
my ($self) = @_;
# Must be a real reference.
return 0
if (! ref($self));
return $self->{'ISINSTANCE'};
}
# _Always_ make sure that this 1 is at the end of the file... # _Always_ make sure that this 1 is at the end of the file...
1; 1;
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
# #
# EMULAB-COPYRIGHT # EMULAB-COPYRIGHT
# Copyright (c) 2000-2006 University of Utah and the Flux Group. # Copyright (c) 2000-2007 University of Utah and the Flux Group.
# All rights reserved. # All rights reserved.
# #
...@@ -652,7 +652,7 @@ sub cancelexp($) ...@@ -652,7 +652,7 @@ sub cancelexp($)
system("$template_swapout -b -e $eid $guid/$vers"); system("$template_swapout -b -e $eid $guid/$vers");
} }
else { else {
system("$endexp -b $pid $eid"); system("$endexp -b $pid,$eid");
} }
if ($?) { if ($?) {
# #
......
...@@ -225,7 +225,7 @@ MAINLOOP: while(1) { ...@@ -225,7 +225,7 @@ MAINLOOP: while(1) {
# Locked waiting for human intervention... # Locked waiting for human intervention...
if (ExpState($TBOPSPID, $eid) eq EXPTSTATE_SWAPPED) { if (ExpState($TBOPSPID, $eid) eq EXPTSTATE_SWAPPED) {
# Swapped out... # Swapped out...
system("$TB/bin/endexp $TBOPSPID $eid"); system("$TB/bin/endexp $TBOPSPID,$eid");
} }
elsif (!ExptExists($TBOPSPID, $eid)) { elsif (!ExptExists($TBOPSPID, $eid)) {
UpdateCheckupState($object, $ctype, $mtype, UpdateCheckupState($object, $ctype, $mtype,
......
#!/usr/bin/perl -wT #!/usr/bin/perl -wT
# #
# EMULAB-COPYRIGHT # EMULAB-COPYRIGHT
# Copyright (c) 2000-2006 University of Utah and the Flux Group. # Copyright (c) 2000-2007 University of Utah and the Flux Group.
# All rights reserved. # All rights reserved.
# #
use English; use English;
use Getopt::Std; use Getopt::Std;
use POSIX qw(isatty setsid); use POSIX qw(isatty setsid);
use strict;
# #
# This gets invoked from the Web interface. Terminate an experiment. # This gets invoked from the Web interface. Terminate an experiment.
...@@ -24,12 +23,11 @@ use POSIX qw(isatty setsid); ...@@ -24,12 +23,11 @@ use POSIX qw(isatty setsid);
sub usage() sub usage()
{ {
print(STDERR print(STDERR
"Usage: endexp [-q] [-b | -w] <pid> <eid>\n". "Usage: endexp [-q] [-b | -w] <eid>\n".
"switches and arguments:\n". "switches and arguments:\n".
"-w - wait for non-batchmode experiment terminate\n". "-w - wait for non-batchmode experiment terminate\n".
"-q - be less chatty\n". "-q - be less chatty\n".
"<pid> - The project the experiment belongs to\n". "<eid> - The experiment id\n");
"<eid> - The experiment name (id)\n");
exit(-1); exit(-1);
} }
...@@ -81,22 +79,15 @@ use libdb; ...@@ -81,22 +79,15 @@ use libdb;
use libtestbed; use libtestbed;
use libtblog; use libtblog;
use libArchive; use libArchive;
use User;
use Template; use Template;
use Experiment; use Experiment;
# Be careful not to exit on transient error; 0 means infinite retry.
$libdb::DBQUERY_MAXTRIES = 0;
my $tbdir = "$TB/bin/"; my $tbdir = "$TB/bin/";
my $tbdata = "tbdata"; my $tbdata = "tbdata";
my $archcontrol = "$TB/bin/archive_control"; my $archcontrol = "$TB/bin/archive_control";
my $nextstate; my $nextstate;
my $logname; my $logname;
my $dbuid;
my $user_name;
my $user_email;
my @row;
my $isadmin;
# #
# Untaint the path # Untaint the path
...@@ -113,15 +104,13 @@ $| = 1; ...@@ -113,15 +104,13 @@ $| = 1;
# Parse command arguments. Once we return from getopts, all that should # Parse command arguments. Once we return from getopts, all that should
# left are the required arguments. # left are the required arguments.
# #
%options = (); my %options = ();
if (! getopts($optlist, \%options)) { if (! getopts($optlist, \%options)) {
usage(); usage();
} }
if (@ARGV != 2) { if (@ARGV != 1) {
usage(); usage();
} }
my $pid = $ARGV[0];
my $eid = $ARGV[1];
if (defined($options{"b"})) { if (defined($options{"b"})) {
$batch = 1; $batch = 1;
} }
...@@ -137,68 +126,42 @@ if (defined($options{"x"})) { ...@@ -137,68 +126,42 @@ if (defined($options{"x"})) {
usage() usage()
if ($waitmode && $batch); if ($waitmode && $batch);
# # Map invoking user to object.
# Untaint the arguments. my $this_user = User->ThisUser();
# if (! defined($this_user)) {
if ($pid =~ /^([-\w\.]+)$/) { fatal("You ($UID) do not exist!");
$pid = $1;
}
else {
die("Tainted argument $pid!\n");
}
if ($eid =~ /^([-\w\.]+)$/) {
$eid = $1;
}
else {
die("Tainted argument $eid!\n");
} }
my $isadmin = TBAdmin();
my $user_name = $this_user->name();
my $user_email = $this_user->email();
my $user_uid = $this_user->uid();
# #
# Grab the experiment. # Grab the experiment.
# #
my $experiment = Experiment->Lookup($pid, $eid); my $experiment = Experiment->Lookup($ARGV[0]);
if (! $experiment) { if (! $experiment) {
die("*** $0:\n". die("*** $0:\n".
" No such experiment $pid/$eid in the Emulab Database.\n"); " No such experiment in the Emulab Database.\n");
} }
my $pid = $experiment->pid();
my $workdir = $experiment->WorkDir(); my $eid = $experiment->eid();
my $userdir = $experiment->UserDir(); my $swapper = $experiment->GetSwapper();
# #
# See if this is a template instance; error if the -x option not provided, # See if this is a template instance; error if the -x option not provided,
# since that means user is trying to self-terminate; not in the program. # since that means user is trying to self-terminate; not in the program.
# #
if (my $instance = Template::Instance->LookupByExptidx($experiment->idx())) { if ($experiment->IsInstance() && !$template_mode) {
if (! $template_mode) {
die("*** $0:\n".
" $pid/$eid is a template instance; use another command\n");
}
}
#
# Verify user and get his DB uid.
#
if (! UNIX2DBUID($UID, \$dbuid)) {
die("*** $0:\n".
" You do not exist in the Emulab Database.\n");
}
$isadmin = TBAdmin($UID);
#
# Get email info for user.
#
if (! UserDBInfo($dbuid, \$user_name, \$user_email)) {
die("*** $0:\n". die("*** $0:\n".
" Cannot determine your name and email address.\n"); " $pid/$eid is a template instance; use another command!\n");
} }
# #
# Verify that this person is allowed to end the experiment. # Verify that this person is allowed to end the experiment.
# Note that any script down the line has to do an admin check also.
# #
if ($UID && !$isadmin && if ($UID && !$isadmin &&
! $experiment->AccessCheck($dbuid, TB_EXPT_DESTROY)) { ! $experiment->AccessCheck($this_user, TB_EXPT_DESTROY)) {
die("*** $0:\n". die("*** $0:\n".
" You do not have permission to end this experiment!\n"); " You do not have permission to end this experiment!\n");
} }
...@@ -388,15 +351,8 @@ $experiment->UnLockTables(); ...@@ -388,15 +351,8 @@ $experiment->UnLockTables();
# the person who is actually terminating the experiment, since its polite # the person who is actually terminating the experiment, since its polite
# to let the original creator know whats going on. # to let the original creator know whats going on.
# #
my $expt_head_name; my $expt_head_name = $swapper->name();
my $expt_head_email; my $expt_head_email = $swapper->email();
if (! UserDBInfo($expt_head_login, \$expt_head_name, \$expt_head_email)) {
print "*** WARNING: ".
"Could not determine name/email for $expt_head_login.\n";
$expt_head_name = "TBOPS";
$expt_head_email = $TBOPS;
}
# #
# If not in batch mode, go into the background. Parent exits. # If not in batch mode, go into the background. Parent exits.
...@@ -426,7 +382,7 @@ if (!$batch && !$template_mode) { ...@@ -426,7 +382,7 @@ if (!$batch && !$template_mode) {
print("Waiting for experiment $eid to finish terminating.\n") print("Waiting for experiment $eid to finish terminating.\n")
if (! $quiet); if (! $quiet);
if (isatty(STDIN) && !$quiet) { if (-t && !$quiet) {
print("You may type ^C at anytime; you will be notified via email.". print("You may type ^C at anytime; you will be notified via email.".
"\n". "\n".
"You will not actually interrupt the experiment itself.\n"); "You will not actually interrupt the experiment itself.\n");
...@@ -470,7 +426,7 @@ if ($waitmode) { ...@@ -470,7 +426,7 @@ if ($waitmode) {
# Sanity check states in case someone changes something. # Sanity check states in case someone changes something.
# #
if ($estate eq EXPTSTATE_ACTIVE) { if ($estate eq EXPTSTATE_ACTIVE) {
GatherSwapStats($pid, $eid, $dbuid, TBDB_STATS_SWAPOUT, 0, GatherSwapStats($pid, $eid, $user_uid, TBDB_STATS_SWAPOUT, 0,
TBDB_STATS_FLAGS_START); TBDB_STATS_FLAGS_START);
if ($experiment->Swap("out") != 0) { if ($experiment->Swap("out") != 0) {
...@@ -487,7 +443,7 @@ if ($estate eq EXPTSTATE_ACTIVE) { ...@@ -487,7 +443,7 @@ if ($estate eq EXPTSTATE_ACTIVE) {
# #
# Gather statistics for the swapout. # Gather statistics for the swapout.
# #
GatherSwapStats($pid, $eid, $dbuid, TBDB_STATS_SWAPOUT, 0); GatherSwapStats($pid, $eid, $user_uid, TBDB_STATS_SWAPOUT, 0);
# Commit the archive after swapout. Easier to use the script. # Commit the archive after swapout. Easier to use the script.
system("$archcontrol -t endexp commit $pid $eid"); system("$archcontrol -t endexp commit $pid $eid");
...@@ -495,7 +451,7 @@ if ($estate eq EXPTSTATE_ACTIVE) { ...@@ -495,7 +451,7 @@ if ($estate eq EXPTSTATE_ACTIVE) {
if ($estate eq EXPTSTATE_SWAPPED || if ($estate eq EXPTSTATE_SWAPPED ||
$estate eq EXPTSTATE_QUEUED) { $estate eq EXPTSTATE_QUEUED) {
GatherSwapStats($pid, $eid, $dbuid, TBDB_STATS_TERMINATE, 0, GatherSwapStats($pid, $eid, $user_uid, TBDB_STATS_TERMINATE, 0,
TBDB_STATS_FLAGS_START); TBDB_STATS_FLAGS_START);
if ($experiment->End() != 0) { if ($experiment->End() != 0) {
...@@ -509,7 +465,7 @@ if ($estate eq EXPTSTATE_SWAPPED || ...@@ -509,7 +465,7 @@ if ($estate eq EXPTSTATE_SWAPPED ||
# #
# Gather statistics for the swapout. # Gather statistics for the swapout.
# #
GatherSwapStats($pid, $eid, $dbuid, TBDB_STATS_TERMINATE, 0); GatherSwapStats($pid, $eid, $user_uid, TBDB_STATS_TERMINATE, 0);
} }
# We better be here ... # We better be here ...
......
...@@ -588,7 +588,7 @@ sub cleanup() ...@@ -588,7 +588,7 @@ sub cleanup()
exit(-1) exit(-1)
if (!TBExptIDX($pid, $eid, \$exptidx)); if (!TBExptIDX($pid, $eid, \$exptidx));
system("$endexp -x -q -w $pid $eid"); system("$endexp -x -q -w $exptidx");
exit(-1) exit(-1)
if ($?); if ($?);
......
#!/usr/bin/perl -wT #!/usr/bin/perl -wT
# #
# EMULAB-COPYRIGHT # EMULAB-COPYRIGHT
# Copyright (c) 2006 University of Utah and the Flux Group. # Copyright (c) 2006, 2007 University of Utah and the Flux Group.
# All rights reserved. # All rights reserved.
# #
use English; use English;
...@@ -210,7 +210,7 @@ foreach my $template (@templates) { ...@@ -210,7 +210,7 @@ foreach my $template (@templates) {
# This is the hidden experiment under the template. # This is the hidden experiment under the template.
if (ExpState($pid, $eid)) { if (ExpState($pid, $eid)) {
system("$endexp -x -q -w $pid $eid"); system("$endexp -x -q -w $pid,$eid");
exit(-1) exit(-1)
if ($?); if ($?);
} }
......
...@@ -784,7 +784,7 @@ sub cleanup() ...@@ -784,7 +784,7 @@ sub cleanup()
# Before killing it, save off the user directory for debugging. # Before killing it, save off the user directory for debugging.
$experiment->BackupUserData(); $experiment->BackupUserData();
system("$endexp -x -q -w $pid $eid"); system("$endexp -x -q -w $exptidx");
exit(-1) exit(-1)
if ($?); if ($?);
} }
......
...@@ -103,7 +103,7 @@ if ($instance) { ...@@ -103,7 +103,7 @@ if ($instance) {
$command = "webtemplate_swapout -e $eid $guid/$vers"; $command = "webtemplate_swapout -e $eid $guid/$vers";
} }
else { else {
$command = "webendexp $pid $eid"; $command = "webendexp $exptidx";
} }
STARTBUSY("Terminating " . ($instance ? "Instance." : "Experiment.")); STARTBUSY("Terminating " . ($instance ? "Instance." : "Experiment."));
......
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