Commit 95357b8a authored by Leigh Stoller's avatar Leigh 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';
use libdb;
use libtestbed;
use libtblog;
use User;
use Project;
use Group;
use English;
......@@ -111,13 +112,18 @@ sub Lookup($$;$)
if (exists($experiments{"$idx"}));
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
if (!$query_result || !$query_result->numrows);
my $self = {};
$self->{'EXPT'} = $query_result->fetchrow_hashref();
# An Instance?
$self->{'ISINSTANCE'} = defined($self->{'EXPT'}->{'parent_guid'});
$query_result =
DBQueryWarn("select * from experiment_stats where exptidx='$idx'");
......@@ -1314,6 +1320,20 @@ sub SetSwapper($$)
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.
#
......@@ -1743,6 +1763,19 @@ sub DU($$)
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...
1;
......@@ -2,7 +2,7 @@
#
# 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.
#
......@@ -652,7 +652,7 @@ sub cancelexp($)
system("$template_swapout -b -e $eid $guid/$vers");
}
else {
system("$endexp -b $pid $eid");
system("$endexp -b $pid,$eid");
}
if ($?) {
#
......
......@@ -225,7 +225,7 @@ MAINLOOP: while(1) {
# Locked waiting for human intervention...
if (ExpState($TBOPSPID, $eid) eq EXPTSTATE_SWAPPED) {
# Swapped out...
system("$TB/bin/endexp $TBOPSPID $eid");
system("$TB/bin/endexp $TBOPSPID,$eid");
}
elsif (!ExptExists($TBOPSPID, $eid)) {
UpdateCheckupState($object, $ctype, $mtype,
......
#!/usr/bin/perl -wT
#
# 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.
#
use English;
use Getopt::Std;
use POSIX qw(isatty setsid);
use strict;
#
# This gets invoked from the Web interface. Terminate an experiment.
......@@ -24,12 +23,11 @@ use POSIX qw(isatty setsid);
sub usage()
{
print(STDERR
"Usage: endexp [-q] [-b | -w] <pid> <eid>\n".
"Usage: endexp [-q] [-b | -w] <eid>\n".
"switches and arguments:\n".
"-w - wait for non-batchmode experiment terminate\n".
"-q - be less chatty\n".
"<pid> - The project the experiment belongs to\n".
"<eid> - The experiment name (id)\n");
"<eid> - The experiment id\n");
exit(-1);
}
......@@ -81,22 +79,15 @@ use libdb;
use libtestbed;
use libtblog;
use libArchive;
use User;
use Template;
use Experiment;
# Be careful not to exit on transient error; 0 means infinite retry.
$libdb::DBQUERY_MAXTRIES = 0;
my $tbdir = "$TB/bin/";
my $tbdata = "tbdata";
my $archcontrol = "$TB/bin/archive_control";
my $nextstate;
my $logname;
my $dbuid;
my $user_name;
my $user_email;
my @row;
my $isadmin;
#
# Untaint the path
......@@ -113,15 +104,13 @@ $| = 1;
# Parse command arguments. Once we return from getopts, all that should
# left are the required arguments.
#
%options = ();
my %options = ();
if (! getopts($optlist, \%options)) {
usage();
}
if (@ARGV != 2) {
if (@ARGV != 1) {
usage();
}
my $pid = $ARGV[0];
my $eid = $ARGV[1];
if (defined($options{"b"})) {
$batch = 1;
}
......@@ -137,68 +126,42 @@ if (defined($options{"x"})) {
usage()
if ($waitmode && $batch);
#
# Untaint the arguments.
#
if ($pid =~ /^([-\w\.]+)$/) {
$pid = $1;
}
else {
die("Tainted argument $pid!\n");
}
if ($eid =~ /^([-\w\.]+)$/) {
$eid = $1;
}
else {
die("Tainted argument $eid!\n");
# Map invoking user to object.
my $this_user = User->ThisUser();
if (! defined($this_user)) {
fatal("You ($UID) do not exist!");
}
my $isadmin = TBAdmin();
my $user_name = $this_user->name();
my $user_email = $this_user->email();
my $user_uid = $this_user->uid();
#
# Grab the experiment.
#
my $experiment = Experiment->Lookup($pid, $eid);
my $experiment = Experiment->Lookup($ARGV[0]);
if (! $experiment) {
die("*** $0:\n".
" No such experiment $pid/$eid in the Emulab Database.\n");
" No such experiment in the Emulab Database.\n");
}
my $workdir = $experiment->WorkDir();
my $userdir = $experiment->UserDir();
my $pid = $experiment->pid();
my $eid = $experiment->eid();
my $swapper = $experiment->GetSwapper();
#
# 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.
#
if (my $instance = Template::Instance->LookupByExptidx($experiment->idx())) {
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)) {
if ($experiment->IsInstance() && !$template_mode) {
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.
# Note that any script down the line has to do an admin check also.
#
if ($UID && !$isadmin &&
! $experiment->AccessCheck($dbuid, TB_EXPT_DESTROY)) {
! $experiment->AccessCheck($this_user, TB_EXPT_DESTROY)) {
die("*** $0:\n".
" You do not have permission to end this experiment!\n");
}
......@@ -388,15 +351,8 @@ $experiment->UnLockTables();
# the person who is actually terminating the experiment, since its polite
# to let the original creator know whats going on.
#
my $expt_head_name;
my $expt_head_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;
}
my $expt_head_name = $swapper->name();
my $expt_head_email = $swapper->email();
#
# If not in batch mode, go into the background. Parent exits.
......@@ -426,7 +382,7 @@ if (!$batch && !$template_mode) {
print("Waiting for experiment $eid to finish terminating.\n")
if (! $quiet);
if (isatty(STDIN) && !$quiet) {
if (-t && !$quiet) {
print("You may type ^C at anytime; you will be notified via email.".
"\n".
"You will not actually interrupt the experiment itself.\n");
......@@ -470,7 +426,7 @@ if ($waitmode) {
# Sanity check states in case someone changes something.
#
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);
if ($experiment->Swap("out") != 0) {
......@@ -487,7 +443,7 @@ if ($estate eq EXPTSTATE_ACTIVE) {
#
# 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.
system("$archcontrol -t endexp commit $pid $eid");
......@@ -495,7 +451,7 @@ if ($estate eq EXPTSTATE_ACTIVE) {
if ($estate eq EXPTSTATE_SWAPPED ||
$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);
if ($experiment->End() != 0) {
......@@ -509,7 +465,7 @@ if ($estate eq EXPTSTATE_SWAPPED ||
#
# 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 ...
......
......@@ -588,7 +588,7 @@ sub cleanup()
exit(-1)
if (!TBExptIDX($pid, $eid, \$exptidx));
system("$endexp -x -q -w $pid $eid");
system("$endexp -x -q -w $exptidx");
exit(-1)
if ($?);
......
#!/usr/bin/perl -wT
#
# 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.
#
use English;
......@@ -210,7 +210,7 @@ foreach my $template (@templates) {
# This is the hidden experiment under the template.
if (ExpState($pid, $eid)) {
system("$endexp -x -q -w $pid $eid");
system("$endexp -x -q -w $pid,$eid");
exit(-1)
if ($?);
}
......
......@@ -784,7 +784,7 @@ sub cleanup()
# Before killing it, save off the user directory for debugging.
$experiment->BackupUserData();
system("$endexp -x -q -w $pid $eid");
system("$endexp -x -q -w $exptidx");
exit(-1)
if ($?);
}
......
......@@ -103,7 +103,7 @@ if ($instance) {
$command = "webtemplate_swapout -e $eid $guid/$vers";
}
else {
$command = "webendexp $pid $eid";
$command = "webendexp $exptidx";
}
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