Commit b680ae67 authored by Leigh B. Stoller's avatar Leigh B. Stoller

Objectify eventsys_control.

parent 780b9777
...@@ -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.
# #
...@@ -20,7 +20,7 @@ use POSIX ":sys_wait_h"; ...@@ -20,7 +20,7 @@ use POSIX ":sys_wait_h";
sub usage() sub usage()
{ {
print STDOUT print STDOUT
"Usage: eventsys_control [-f] <start|stop|replay> <pid> <eid>\n"; "Usage: eventsys_control [-f] <start|stop|replay> <eid>\n";
exit(-1); exit(-1);
} }
my $optlist = "dfa"; my $optlist = "dfa";
...@@ -62,6 +62,8 @@ use lib "@prefix@/lib"; ...@@ -62,6 +62,8 @@ use lib "@prefix@/lib";
use libdb; use libdb;
use libtestbed; use libtestbed;
use libtblog; use libtblog;
use Experiment;
use User;
use Template; use Template;
# #
...@@ -77,9 +79,6 @@ my $proxy = "$TB/sbin/eventsys.proxy"; ...@@ -77,9 +79,6 @@ my $proxy = "$TB/sbin/eventsys.proxy";
my $debug = 1; my $debug = 1;
my $force = 0; my $force = 0;
my $agent = 0; my $agent = 0;
my $expstate;
my $exptidx;
my $dbuid;
# #
# Parse command arguments. Once we return from getopts, all that should be # Parse command arguments. Once we return from getopts, all that should be
...@@ -89,7 +88,7 @@ my $dbuid; ...@@ -89,7 +88,7 @@ my $dbuid;
if (! getopts($optlist, \%options)) { if (! getopts($optlist, \%options)) {
usage(); usage();
} }
if (@ARGV != 3) { if (@ARGV != 2) {
usage(); usage();
} }
if (defined($options{"d"})) { if (defined($options{"d"})) {
...@@ -102,8 +101,6 @@ if (defined($options{"a"})) { ...@@ -102,8 +101,6 @@ if (defined($options{"a"})) {
$agent = 1; $agent = 1;
} }
my $action = $ARGV[0]; my $action = $ARGV[0];
my $pid = $ARGV[1];
my $eid = $ARGV[2];
# #
# Untaint args. # Untaint args.
...@@ -114,32 +111,34 @@ if ($action =~ /^(start|stop|replay)$/) { ...@@ -114,32 +111,34 @@ if ($action =~ /^(start|stop|replay)$/) {
else { else {
usage(); usage();
} }
if ($pid =~ /^([-\@\w]+)$/) {
$pid = $1;
}
else {
die("Bad data in pid: $pid.");
}
if ($eid =~ /^([-\@\w]+)$/) {
$eid = $1;
}
else {
die("Bad data in eid: $eid.");
}
if (! ($expstate = ExpState($pid, $eid))) { #
tbdie("No such experiment $pid/$eid!"); # Verify user and get his DB uid and other info for later.
#
my $this_user = User->ThisUser();
if (! defined($this_user)) {
tbdie("You ($UID) do not exist!");
} }
my $user_uid = $this_user->uid();
my $isadmin = TBAdmin();
if (! UNIX2DBUID($UID, \$dbuid)) { #
tbdie("You do not exist in the Emulab Database!"); # Grab the experiment.
#
my $experiment = Experiment->Lookup($ARGV[1]);
if (! $experiment) {
die("*** $0:\n".
" No such experiment in the Emulab Database.\n");
} }
my $pid = $experiment->pid();
my $eid = $experiment->eid();
my $expstate = $experiment->state();
# #
# Check permission. Only people with permission to destroy the experiment # Check permission. Only people with permission to destroy the experiment
# can do this. # can do this.
# #
if (! TBExptAccessCheck($UID, $pid, $eid, TB_EXPT_DESTROY)) { if (! $experiment->AccessCheck($this_user, TB_EXPT_DESTROY)) {
tbdie("You do not have permission to control the event system!"); tbdie("You do not have permission to control the event system!");
} }
...@@ -151,7 +150,7 @@ if ($expstate ne EXPTSTATE_ACTIVE && ...@@ -151,7 +150,7 @@ if ($expstate ne EXPTSTATE_ACTIVE &&
$expstate ne EXPTSTATE_ACTIVATING && $expstate ne EXPTSTATE_ACTIVATING &&
$expstate ne EXPTSTATE_MODIFY_RESWAP && $expstate ne EXPTSTATE_MODIFY_RESWAP &&
$expstate ne EXPTSTATE_SWAPPING) { $expstate ne EXPTSTATE_SWAPPING) {
tbdie("Experiment $pid/$eid must be active (or swapping)!"); tbdie("$experiment must be active (or swapping)!");
} }
# #
...@@ -159,8 +158,7 @@ if ($expstate ne EXPTSTATE_ACTIVE && ...@@ -159,8 +158,7 @@ if ($expstate ne EXPTSTATE_ACTIVE &&
# the experiment, balk unless force mode is on. # the experiment, balk unless force mode is on.
# #
if ($action eq "start" && !$force && !ExpNodes($pid, $eid)) { if ($action eq "start" && !$force && !ExpNodes($pid, $eid)) {
tbnotice("There are no nodes in $pid/$eid. ". tbnotice("There are no nodes in $experiment. Not starting a scheduler.");
"Not starting a scheduler.");
exit(0); exit(0);
} }
...@@ -185,16 +183,9 @@ if ($action ne "stop" && ! $agent) { ...@@ -185,16 +183,9 @@ if ($action ne "stop" && ! $agent) {
} }
# Need the unix_gid info to pass to boss. # Need the unix_gid info to pass to boss.
my $gid = ExpGroup($pid, $eid); my $group = $experiment->GetGroup();
my ($unix_gid, $unix_gidname); if (!defined($group)) {
tbdie("Could not get unix group info for $experiment!");
if (! TBGroupUnixInfo($pid, $gid, \$unix_gid, \$unix_gidname)) {
tbdie("Could not get unix group info for $pid/$gid!");
}
# Need this to see if its a template experiment.
if (! TBExptIDX($pid, $eid, \$exptidx)) {
tbdie("Could not get experiment index for $pid/$gid!");
} }
# #
...@@ -207,13 +198,13 @@ $cmd .= " -d" ...@@ -207,13 +198,13 @@ $cmd .= " -d"
if ($debug); if ($debug);
$cmd .= " -a" $cmd .= " -a"
if ($agent); if ($agent);
$cmd .= " -t " . TBExptUserDir($pid, $eid) . "/logs/events" $cmd .= " -t " . $experiment->UserDir() . "/logs/events"
if (Template::Instance->LookupByExptidx($exptidx)); if ($experiment->IsInstance());
$cmd .= " -l " . TBExptUserDir($pid, $eid) . "/logs/event-sched.log"; $cmd .= " -l " . $experiment->UserDir() . "/logs/event-sched.log";
$cmd .= " -k " . TBDB_EVENTKEY($pid, $eid); $cmd .= " -k " . $experiment->EventKeyPath();
$cmd .= " -g " . $unix_gidname; $cmd .= " -g " . $group->unix_name();
$cmd .= " -e $pid/$eid"; $cmd .= " -e $pid/$eid";
$cmd .= " -u $dbuid"; $cmd .= " -u $user_uid";
$cmd .= " $action"; $cmd .= " $action";
$UID=0; $UID=0;
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
# #
# EMULAB-COPYRIGHT # EMULAB-COPYRIGHT
# Copyright (c) 2000-2002, 2004 University of Utah and the Flux Group. # Copyright (c) 2000-2002, 2004, 2007 University of Utah and the Flux Group.
# All rights reserved. # All rights reserved.
# #
...@@ -120,7 +120,7 @@ while (($pid, $eid, $uid, $gid) = $query_result->fetchrow_array()) { ...@@ -120,7 +120,7 @@ while (($pid, $eid, $uid, $gid) = $query_result->fetchrow_array()) {
$ENV{'USER'} = $uid; $ENV{'USER'} = $uid;
print "Starting event scheduler for $pid/$eid ...\n"; print "Starting event scheduler for $pid/$eid ...\n";
system("$evcontrol start $pid $eid"); system("$evcontrol start $pid,$eid");
if ($?) { if ($?) {
failed("$evcontrol failed, status=$?", $pid, $eid); failed("$evcontrol failed, status=$?", $pid, $eid);
} else { } else {
......
...@@ -538,7 +538,7 @@ sub evsysctrl($) ...@@ -538,7 +538,7 @@ sub evsysctrl($)
if (system("$locpiper $lpflag $REPOSPID $REPOSEID")) { if (system("$locpiper $lpflag $REPOSPID $REPOSEID")) {
notify("Failed to $action locpiper\n"); notify("Failed to $action locpiper\n");
} }
elsif (system("$evsys $action $REPOSPID $REPOSEID")) { elsif (system("$evsys $action $REPOSPID,$REPOSEID")) {
notify("Failed to $action event system\n"); notify("Failed to $action event system\n");
} }
else { else {
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
# #
# EMULAB-COPYRIGHT # EMULAB-COPYRIGHT
# Copyright (c) 2000-2004 University of Utah and the Flux Group. # Copyright (c) 2000-2004, 2007 University of Utah and the Flux Group.
# All rights reserved. # All rights reserved.
# #
...@@ -91,7 +91,7 @@ if ($state ne EXPTSTATE_ACTIVE) { ...@@ -91,7 +91,7 @@ if ($state ne EXPTSTATE_ACTIVE) {
if (!$DISABLE_EVENTS) { if (!$DISABLE_EVENTS) {
print "Stopping the event system.\n"; print "Stopping the event system.\n";
TBDebugTimeStamp("eventsys_control started"); TBDebugTimeStamp("eventsys_control started");
if (system("eventsys_control stop $pid $eid")) { if (system("eventsys_control stop $pid,$eid")) {
die("*** $0:\n". die("*** $0:\n".
" Failed to stop the event system.\n"); " Failed to stop the event system.\n");
} }
...@@ -171,7 +171,7 @@ if ($failed) { ...@@ -171,7 +171,7 @@ if ($failed) {
if (!$DISABLE_EVENTS) { if (!$DISABLE_EVENTS) {
print "Starting the event system.\n"; print "Starting the event system.\n";
TBDebugTimeStamp("eventsys_control started"); TBDebugTimeStamp("eventsys_control started");
if (system("eventsys_control start $pid $eid")) { if (system("eventsys_control start $pid,$eid")) {
die("*** $0:\n". die("*** $0:\n".
" Failed to start the event system.\n"); " Failed to start the event system.\n");
} }
......
...@@ -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.
# #
use English; use English;
...@@ -463,7 +463,7 @@ sub doSwapout($) { ...@@ -463,7 +463,7 @@ sub doSwapout($) {
if ($type >= RETRY || if ($type >= RETRY ||
($update_Eventsys_restart && $type == UPDATE) ) { ($update_Eventsys_restart && $type == UPDATE) ) {
print "Stopping the event system\n"; print "Stopping the event system\n";
if (system("eventsys_control stop $pid $eid")) { if (system("eventsys_control stop $pid,$eid")) {
tberror({type => 'secondary', severity => SEV_SECONDARY, tberror({type => 'secondary', severity => SEV_SECONDARY,
error => ['eventsys_stop_failed']}, error => ['eventsys_stop_failed']},
"Failed to stop the event system."); "Failed to stop the event system.");
...@@ -1282,7 +1282,7 @@ sub doSwapin($) { ...@@ -1282,7 +1282,7 @@ sub doSwapin($) {
($type != UPDATE && $type != UPDATE_RECOVER) ) { ($type != UPDATE && $type != UPDATE_RECOVER) ) {
print "Starting the event system.\n"; print "Starting the event system.\n";
TBDebugTimeStamp("eventsys_control started"); TBDebugTimeStamp("eventsys_control started");
if (system("eventsys_control start $pid $eid")) { if (system("eventsys_control start $pid,$eid")) {
tberror({type => 'secondary', severity => SEV_SECONDARY, tberror({type => 'secondary', severity => SEV_SECONDARY,
error => ['eventsys_start_failed']}, error => ['eventsys_start_failed']},
"Failed to start the event system."); "Failed to start the event system.");
......
...@@ -613,7 +613,7 @@ SignalProgAgents("RELOAD") == 0 ...@@ -613,7 +613,7 @@ SignalProgAgents("RELOAD") == 0
# Restart the event stream from the beginning. # Restart the event stream from the beginning.
# #
print "Asking the event system to replay events ...\n"; print "Asking the event system to replay events ...\n";
system("$eventcontrol replay $pid $eid") == 0 system("$eventcontrol replay $pid,$eid") == 0
or fatal(-1, "Could not restart the event system!"); or fatal(-1, "Could not restart the event system!");
# We lose the log info for this commit if we do not copy it out to the # We lose the log info for this commit if we do not copy it out to the
......
...@@ -79,7 +79,7 @@ set_time_limit(0); ...@@ -79,7 +79,7 @@ set_time_limit(0);
STARTBUSY("Starting event replay"); STARTBUSY("Starting event replay");
$retval = SUEXEC($uid, "$pid,$unix_gid", $retval = SUEXEC($uid, "$pid,$unix_gid",
"webeventsys_control replay $pid $eid", "webeventsys_control replay $pid,$eid",
SUEXEC_ACTION_DIE); SUEXEC_ACTION_DIE);
STOPBUSY(); STOPBUSY();
......
...@@ -2600,6 +2600,7 @@ class experiment: ...@@ -2600,6 +2600,7 @@ class experiment:
argstr = "" argstr = ""
argstr += " " + escapeshellarg(argdict["action"]) argstr += " " + escapeshellarg(argdict["action"])
argstr += " " + escapeshellarg(argdict["proj"]) argstr += " " + escapeshellarg(argdict["proj"])
argstr += ","
argstr += " " + escapeshellarg(argdict["exp"]) argstr += " " + escapeshellarg(argdict["exp"])
(exitval, output) = runcommand(TBDIR + "/bin/eventsys_control " (exitval, output) = runcommand(TBDIR + "/bin/eventsys_control "
......
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