Commit f7219346 authored by Leigh Stoller's avatar Leigh Stoller

"improvements" to prereserve:

New option -s datetime to specify a starting time for the pre-reserve.
New option -e datetime to specify a ending time for the pre-reserve.

The idea is that you can schedule a pre-reserve to begin sometime later,
and you can optionally specify a time for a prereserve to terminate.
There is a new script that runs from cron that checks for pre-reserves
that need to be started or terminated.

For example:

boss> wap prereserve -s '2012-09-14 09:08:15' -e '2012-09-15' emulab-ops 50

You can use any datetime string that is valid for str2time. At some point
it would be nice to allow natural language dates ("tomorrow") but that
requires a another bunch of perl packages and I didn't want to bother.

NOTE: when using -e, -r is implied; in other words, when the
pre-reserve is terminated, the table entry is cleared *and* the
reserved_pid of all of the nodes is cleared. Any experiments using
those nodes is left alone, although if the user does a swapmod, they
could easily lose the nodes if another pre-reserve is set up that
promises those nodes to another project.
parent 43e9f520
......@@ -3335,7 +3335,7 @@ sub CheckPreReserve($$)
# not look in the object ($self) since it might be stale.
#
my $query_result =
DBQueryWarn("select reserved_pid,count from nodes ".
DBQueryWarn("select reserved_pid,count,active from nodes ".
"left join node_reservations on ".
" node_reservations.pid=nodes.reserved_pid ".
"where nodes.node_id='$node_id'");
......@@ -3348,10 +3348,10 @@ sub CheckPreReserve($$)
# if the reervation request is still active. If not, we can clear it,
# which will allow it to be set again below, if needed.
#
my ($pid,$count) = $query_result->fetchrow_array();
my ($pid,$count,$active) = $query_result->fetchrow_array();
if (defined($pid)) {
goto done
if (defined($count));
if (defined($count) && $active);
DBQueryWarn("update nodes set reserved_pid=null ".
"where node_id='$node_id'");
......@@ -3360,10 +3360,11 @@ sub CheckPreReserve($$)
print "Clearing pre reserve for $node_id\n";
}
}
# Find only active unfilled reservations.
$query_result =
DBQueryWarn("select pid,count from node_reservations ".
"where count>0 and ".
"where active=1 and count>0 and ".
" (types is null or ".
" FIND_IN_SET('$type', types)) ".
"order by priority desc, created asc ".
......@@ -3386,7 +3387,7 @@ sub CheckPreReserve($$)
if ($count == 1) {
SENDMAIL($TBOPS, "Pre Reservation for $pid has completed",
"The pre reservation request for project $pid, ".
"has been fullfilled\n");
"has been fullfilled\n", $TBOPS);
}
}
}
......
......@@ -2476,6 +2476,9 @@ CREATE TABLE `node_reservations` (
`creator` varchar(8) NOT NULL default '',
`creator_idx` mediumint(8) unsigned NOT NULL default '0',
`created` datetime default NULL,
`start` datetime default NULL,
`end` datetime default NULL,
`active` tinyint(1) NOT NULL default '0',
PRIMARY KEY (`pid_idx`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
......
#
# Add stuff to handle importing images from other locations.
#
use strict;
use libdb;
sub DoUpdate($$$)
{
my ($dbhandle, $dbname, $version) = @_;
if (!DBSlotExists("node_reservations", "start")) {
DBQueryFatal("alter table node_reservations add ".
" `start` datetime default NULL");
}
if (!DBSlotExists("node_reservations", "end")) {
DBQueryFatal("alter table node_reservations add ".
" `end` datetime default NULL");
}
if (!DBSlotExists("node_reservations", "active")) {
DBQueryFatal("alter table node_reservations add ".
" `active` tinyint(1) NOT NULL default '0'");
}
DBQueryFatal("update node_reservations set active=1 ".
"where start is null");
return 0;
}
1;
# Local Variables:
# mode:perl
# End:
......@@ -30,7 +30,8 @@ SBIN_SCRIPTS = vlandiff vlansync withadminprivs export_tables cvsupd.pl \
prereserve grantimage getimages localize_mfs \
management_iface sharevlan check-shared-bw \
addspecialdevice addspecialiface imagehash clone_image \
addvpubaddr imageinfo ctrladdr image_import
addvpubaddr imageinfo ctrladdr image_import \
prereserve_check
WEB_SBIN_SCRIPTS= webnewnode webdeletenode webspewconlog webarchive_list \
webwanodecheckin webspewimage webdumpdescriptor
......
This diff is collapsed.
#!/usr/bin/perl -w
#
# EMULAB-COPYRIGHT
# Copyright (c) 2003-2012 University of Utah and the Flux Group.
# All rights reserved.
#
use strict;
use English;
use Getopt::Std;
#
# Look for pending pre-reserves that need to be activated.
#
sub usage()
{
print STDERR "Usage: prereserve_check [-d] [-n]\n";
exit(-1);
}
my $optlist = "dn";
my $debug = 0;
my $impotent = 0;
# Protos
sub fatal($);
#
# Configure variables
#
my $TB = "@prefix@";
my $PRERESERVE = "$TB/sbin/prereserve";
my $TBOPS = "@TBOPSEMAIL@";
#
# Testbed Support libraries
#
use lib "@prefix@/lib";
use emdb;
use libtestbed;
use emutil;
#
# Turn off line buffering on output
#
$| = 1;
#
# Untaint the path
#
$ENV{'PATH'} = "/bin:/sbin:/usr/bin:";
#
# Parse command arguments. Once we return from getopts, all that should be
# left are the required arguments.
#
my %options = ();
if (! getopts($optlist, \%options)) {
usage();
}
if (defined($options{"d"})) {
$debug = 1;
}
if (defined($options{"n"})) {
$impotent = 1;
}
usage()
if (@ARGV);
#
# Look for active pre reserves that need to be terminated.
#
my $query_result =
DBQueryFatal("select * from node_reservations ".
"where end is not null and ".
" UNIX_TIMESTAMP(end) < UNIX_TIMESTAMP(now())");
while (my $row = $query_result->fetchrow_hashref()) {
my $pid = $row->{'pid'};
if ($debug) {
print "Terminating pre-reserve for project $pid\n";
}
if (!$impotent) {
my $output = emutil::ExecQuiet("$PRERESERVE -c -r $pid");
if ($?) {
print STDERR "Error terminating pre reservation for $pid!\n";
SENDMAIL($TBOPS, "Error Terminating pre reservation for $pid",
"The pre reservation request for project $pid, ".
"could not be terminated!\n\n" . $output . "\n", $TBOPS);
}
else {
SENDMAIL($TBOPS, "Pre Reservation for $pid has been terminated",
"The pre reservation request for project $pid, ".
"has been terminated\n", $TBOPS);
}
}
}
#
# Look for inactive pre reserves that need to be activated.
#
$query_result =
DBQueryFatal("select * from node_reservations ".
"where active=0 and start is not null and ".
" UNIX_TIMESTAMP(start) >= UNIX_TIMESTAMP(now()) ".
"order by priority desc, created asc");
while (my $row = $query_result->fetchrow_hashref()) {
my $pid = $row->{'pid'};
if ($debug) {
print "Activating pre-reserve for project $pid\n";
}
if (!$impotent) {
my $output = emutil::ExecQuiet("$PRERESERVE -a $pid");
if ($?) {
print STDERR "Error activating pre reservation for $pid!\n";
SENDMAIL($TBOPS, "Error activating pre reservation for $pid",
"The pre reservation request for project $pid, ".
"could not be activated!\n\n" . $output . "\n", $TBOPS);
}
}
}
sub fatal($)
{
my ($mesg) = $_[0];
die("*** $0:\n".
" $mesg\n");
}
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