Commit bf3fb9f0 authored by Leigh Stoller's avatar Leigh Stoller

Backend and command line part of asking the reservation system for the

max possible extension permitted. For a multisite experiment, return the
smaller of the dates.
parent 46fd3a20
......@@ -2681,5 +2681,32 @@ sub CheckReservation($$)
return undef;
}
#
# Ask the cluster for the maximum extension allowed; return a GMT of
#
sub MaxExtension($$)
{
my ($self, $pmax) = @_;
my $authority = $self->GetGeniAuthority();
my $context = APT_Geni::RootContext();
my $slice = $self->instance()->GetGeniSlice();
return undef
if (! (defined($authority) && defined($context) &&
defined($slice)));
my $args = {
"slice_urn" => $slice->urn(),
};
my $cmurl = $authority->url();
$cmurl =~ s/\/cm$/\/cluster/;
$cmurl = devurl($cmurl) if ($usemydevtree);
my $response = Genixmlrpc::CallMethod($cmurl, $context,
"SliceMaxExtension", $args);
return $response;
bad:
return undef;
}
# _Always_ make sure that this 1 is at the end of the file...
1;
......@@ -53,6 +53,7 @@ sub usage()
print("Usage: manage_instance extend instance [-m message] days [filename]\n");
print("Usage: manage_instance denyextension instance [-m message] [filename]\n");
print("Usage: manage_instance checkreservation instance days\n");
print("Usage: manage_instance maxextension instance\n");
print("Usage: manage_instance moreinfo instance [-m message] [filename]\n");
print("Usage: manage_instance extendold instance [-f] seconds\n");
print("Usage: manage_instance utilization instance\n");
......@@ -136,6 +137,7 @@ sub DoIdleData();
sub DoOpenstack();
sub DoCheckReservation();
sub CheckReservationInternal($$$);
sub DoMaxExtension();
sub WriteCredentials();
sub StartMonitor();
sub StartMonitorInternal(;$@);
......@@ -252,6 +254,9 @@ elsif ($action eq "openstackstats") {
elsif ($action eq "checkreservation") {
DoCheckReservation()
}
elsif ($action eq "maxextension") {
DoMaxExtension()
}
else {
usage();
}
......@@ -1817,6 +1822,116 @@ sub CheckReservationInternal($$$)
$$perrmsg = $errmsg;
return $errcode;
}
#
# Ask the reservation system for the maximum date to which this experiment
# can be extended.
#
sub DoMaxExtension()
{
my $slice = $instance->GetGeniSlice();
my $errcode = -1;
my $errmsg;
my $newmax;
#
# Create the webtask object; the web interface gave us an anonymous
# webtask, so we can use it before lock.
#
if (defined($webtask_id)) {
$webtask = WebTask->Lookup($webtask_id);
fatal("Could not lookup webtask object")
if (!defined($webtask));
# Convenient.
$webtask->AutoStore(1);
}
if ($slice->Lock()) {
print STDERR "Experiment is busy, cannot lock it. Try again later.\n";
exit(GENIRESPONSE_BUSY);
}
my $coderef = sub {
my ($sliver) = @_;
my $webtask = $sliver->webtask();
my $domain = $sliver->domain();
my $errmsg;
return 0
if ($sliver->isAL2S());
my $response = $sliver->MaxExtension();
if (!defined($response)) {
$errmsg = "Internal error calling MaxExtension at $domain";
goto bad;
}
if ($response->code() != GENIRESPONSE_SUCCESS) {
$errmsg = "Failed to get max extension at $domain: ".
$response->output();
# This is something the user should see.
if ($response->code() == GENIRESPONSE_REFUSED ||
$response->code() == GENIRESPONSE_SERVER_UNAVAILABLE ||
$response->code() == GENIRESPONSE_BUSY) {
$webtask->output($errmsg);
$webtask->Exited($response->code());
return 1;
}
goto bad;
}
$webtask->MaxExtension($response->value());
return 0;
bad:
print STDERR "$errmsg\n";
$webtask->output($errmsg);
$webtask->Exited(-1);
return -1;
};
my @return_codes = ();
my @agglist = $instance->AggregateList();
if (ParRun({"maxwaittime" => 99999,
"maxchildren" => scalar(@agglist)},
\@return_codes, $coderef, @agglist)) {
#
# The parent caught a signal. Leave things intact so that we can
# kill things cleanly later.
#
$errmsg = "Internal error calling MaxExtension\n";
goto bad;
}
#
# Check the exit codes.
#
foreach my $agg (@agglist) {
my $code = shift(@return_codes);
$agg->webtask()->Refresh();
if ($code) {
$errmsg = $agg->webtask()->output();
$errcode = $agg->webtask()->exitcode();
goto bad;
}
my $max = str2time($agg->webtask()->MaxExtension());
$newmax = $max
if (!defined($newmax));
$newmax = $max
if ($max < $newmax);
}
if ($debug) {
print "Max extension: " . TBDateStringLocal($newmax) . "\n";
}
if (defined($webtask)) {
$webtask->MaxExtension(TBDateStringGMT($newmax));
$webtask->Exited(0);
}
$slice->UnLock();
exit(0);
bad:
$slice->UnLock();
if (defined($webtask)) {
$webtask->output($errmsg);
$webtask->Exited($errcode);
}
exit($errcode);
}
#
# Deny extension, sending optional email to user (which is also saved in
......
......@@ -540,5 +540,34 @@ sub SliceCheckReservation($)
Reservation->FlushAll();
return GeniResponse->Create(GENIRESPONSE_SUCCESS);
}
#
# Get maximum allowed extension for a slice.
#
sub SliceMaxExtension($)
{
my ($argref) = @_;
my $slice_urn = $argref->{'slice_urn'};
my %blob = ();
my $max;
my $reserror;
my $hasperm = CheckPermission();
return $hasperm
if (GeniResponse::IsError($hasperm));
my $slice = GeniSlice->Lookup($slice_urn);
return GeniResponse->Create(GENIRESPONSE_SEARCHFAILED)
if (!defined($slice));
if (Reservation->MaxSliceExtension($slice, \$max, \$reserror)) {
Reservation->FlushAll();
return GeniResponse->Create(GENIRESPONSE_REFUSED, undef, $reserror);
}
Reservation->FlushAll();
$max = TBDateStringGMT($max);
return GeniResponse->Create(GENIRESPONSE_SUCCESS, $max);
}
# _Always_ make sure that this 1 is at the end of the file...
1;
......@@ -245,6 +245,7 @@ ProtoGeniDefs::AddModule("cluster",
"SliceIdleData" => \&GeniCluster::SliceIdleData,
"SliceOpenstackData" => \&GeniCluster::SliceOpenstackData,
"SliceCheckReservation"=> \&GeniCluster::SliceCheckReservation,
"SliceMaxExtension" => \&GeniCluster::SliceMaxExtension,
}},
});
......
......@@ -50,6 +50,7 @@ $GENI_METHODS = {
"SliceIdleData" => \&GeniCluster::SliceIdleData,
"SliceOpenstackData" => \&GeniCluster::SliceOpenstackData,
"SliceCheckReservation"=> \&GeniCluster::SliceCheckReservation,
"SliceMaxExtension" => \&GeniCluster::SliceMaxExtension,
};
1;
......
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