Commit c7acad6c authored by Leigh Stoller's avatar Leigh Stoller

Some small changes:

1. Add WebTask support for communicating back to the web interface and
   the Geni interface. Especially helpful for the case that a dataset
   needs admin approval.

2. Some changes related to above to make it easier to pass back the
   reason for nor approving.

3. Small semantic change to -C (always create) which I added for the
   Geni path a while back. It now means always create but respect the
   approval decision. In other words, if a dataset would need approval
   cause it is too big, create the dataset but mark it as needing
   approval and send mail. -C used to mean always create and approve.
   The new approach is a better fit for the Portal/Geni path.
parent 2cef4a54
...@@ -54,7 +54,7 @@ sub usage() ...@@ -54,7 +54,7 @@ sub usage()
print STDERR " name Name (in the form <pid>/<id> or <pid>/<gid>/<id>)\n"; print STDERR " name Name (in the form <pid>/<id> or <pid>/<gid>/<id>)\n";
exit(-1); exit(-1);
} }
my $optlist = "dhUo:s:t:e:a:f:bCR:W:I:"; my $optlist = "dhUo:s:t:e:a:f:bCR:W:I:T:";
my $debug = 0; my $debug = 0;
my $background = 0; my $background = 0;
my $pid; my $pid;
...@@ -71,6 +71,10 @@ my $attrstr = ""; ...@@ -71,6 +71,10 @@ my $attrstr = "";
my %attrs = (); my %attrs = ();
my $read_access; my $read_access;
my $write_access; my $write_access;
my $needapproval = 0;
my $unapproved_reason;
my $webtask_id;
my $webtask;
my $qprefix = "global_"; my $qprefix = "global_";
my $quota; my $quota;
...@@ -112,6 +116,7 @@ use Group; ...@@ -112,6 +116,7 @@ use Group;
use User; use User;
use Image; # For datasets use Image; # For datasets
use Node; use Node;
use WebTask;
# #
# Turn off line buffering on output # Turn off line buffering on output
...@@ -202,6 +207,14 @@ if (defined($options{"W"})) { ...@@ -202,6 +207,14 @@ if (defined($options{"W"})) {
usage(); usage();
} }
} }
if (defined($options{"T"})) {
$webtask_id = $options{"T"};
$webtask = WebTask->Lookup($webtask_id);
if (!defined($webtask)) {
fatal("Could not get webtask object");
}
$webtask->AutoStore(1);
}
if (@ARGV != 1) { if (@ARGV != 1) {
print STDERR "Must specify dataset name\n"; print STDERR "Must specify dataset name\n";
...@@ -305,17 +318,12 @@ my $vars = Lease->SiteVars($dstype); ...@@ -305,17 +318,12 @@ my $vars = Lease->SiteVars($dstype);
if ($size <= 0) { if ($size <= 0) {
fatal("Size must be greater than zero."); fatal("Size must be greater than zero.");
} }
if ($approveme && $vars->{"maxsize"} > 0 && $size > $vars->{"maxsize"}) { if ($vars->{"maxsize"} > 0 && $size > $vars->{"maxsize"}) {
print STDERR if ($approveme) {
"Requested size ($size) is larger than allowed by default (" . $unapproved_reason =
$vars->{"maxsize"} . ").\n"; "Requested size ($size) is larger than allowed by default (" .
if (!$alwayscreate) { $vars->{"maxsize"} . ").";
print STDERR $needapproval = 1;
"Try again with '-U' option and request special approval by testbed-ops.\n"
if (!$background);
exit($POLICY_FAIL);
} else {
print STDERR "WARNING: creating anyway!\n";
} }
} }
...@@ -325,7 +333,6 @@ if ($approveme && $vars->{"maxsize"} > 0 && $size > $vars->{"maxsize"}) { ...@@ -325,7 +333,6 @@ if ($approveme && $vars->{"maxsize"} > 0 && $size > $vars->{"maxsize"}) {
# If the user did not specify a value, we use the system max value. # If the user did not specify a value, we use the system max value.
# #
my $now = time(); my $now = time();
my $needapproval = 0;
if (!defined($expire)) { if (!defined($expire)) {
# no user specified expiration, use default max (which may be unlimited) # no user specified expiration, use default max (which may be unlimited)
if ($vars->{"maxlease"} > 0) { if ($vars->{"maxlease"} > 0) {
...@@ -337,7 +344,7 @@ if (!defined($expire)) { ...@@ -337,7 +344,7 @@ if (!defined($expire)) {
# user specified unlimited, requires approval unless max is also unlimited # user specified unlimited, requires approval unless max is also unlimited
if ($vars->{"maxlease"} > 0) { if ($vars->{"maxlease"} > 0) {
if ($approveme) { if ($approveme) {
print STDERR "Unlimited expiration not allowed by default.\n"; $unapproved_reason = "Unlimited expiration not allowed by default.";
$needapproval = 1; $needapproval = 1;
} }
} }
...@@ -349,18 +356,25 @@ if (!defined($expire)) { ...@@ -349,18 +356,25 @@ if (!defined($expire)) {
if ($approveme && ($expire - $now) > $vars->{"maxlease"}) { if ($approveme && ($expire - $now) > $vars->{"maxlease"}) {
my $mdate = localtime($now + $vars->{"maxlease"}); my $mdate = localtime($now + $vars->{"maxlease"});
my $rdate = localtime($expire); my $rdate = localtime($expire);
print STDERR "Expiration is beyond the maximum allowed by default ". $unapproved_reason =
"($rdate > $mdate).\n"; "Expiration is beyond the maximum allowed by default ".
"($rdate > $mdate).";
$needapproval = 1; $needapproval = 1;
} }
} }
if ($needapproval) { if ($needapproval) {
print STDERR $unapproved_reason . "\n";
if (!$alwayscreate) { if (!$alwayscreate) {
print STDERR print STDERR
"Try again with '-U' to request special approval by testbed-ops.\n" "Try again with '-U' to request special approval by testbed-ops.\n"
if (!$background); if (!$background);
if (defined($webtask)) {
$webtask->output($unapproved_reason);
$webtask->Exited($POLICY_FAIL);
}
exit($POLICY_FAIL); exit($POLICY_FAIL);
} else { } else {
$approveme = 0;
print STDERR "WARNING: creating anyway!\n"; print STDERR "WARNING: creating anyway!\n";
} }
} }
...@@ -460,15 +474,20 @@ if ($vars->{"usequotas"}) { ...@@ -460,15 +474,20 @@ if ($vars->{"usequotas"}) {
$allocated += $lsize; $allocated += $lsize;
} }
if ($allocated + $size > $qsize) { if ($allocated + $size > $qsize) {
print STDERR $unapproved_reason =
"Allocation of $size would put $pid over quota ($qsize).\n"; "Allocation of $size would put $pid over quota ($qsize).";
if (!$alwayscreate) { if (!$alwayscreate) {
print STDERR print STDERR
"Try again with '-U' to request special approval by testbed-ops.\n" "Try again with '-U' to request special approval by testbed-ops.\n"
if (!$background); if (!$background);
$quota->Unlock(); $quota->Unlock();
if (defined($webtask)) {
$webtask->output($unapproved_reason);
$webtask->Exited($POLICY_FAIL);
}
exit($POLICY_FAIL); exit($POLICY_FAIL);
} else { } else {
$approveme = 0;
print STDERR "WARNING: creating anyway!\n"; print STDERR "WARNING: creating anyway!\n";
} }
} }
...@@ -587,9 +606,18 @@ if (!$approveme) { ...@@ -587,9 +606,18 @@ if (!$approveme) {
# Note that the lease daemon sends out periodic email about # Note that the lease daemon sends out periodic email about
# unapproved leases. # unapproved leases.
SENDMAIL($TBOPS, "Lease approval required", SENDMAIL($TBOPS, "Lease approval required",
"Lease '$pid/$gid/$lname' requires approval. You can view it at\n". "Lease '$pid/$gid/$lname' requires approval.\n".
(defined($unapproved_reason) ? "$unapproved_reason\n\n" : "\n") .
"You can view it at\n".
"$TBBASE/show-dataset.php?uuid=$lease_uuid\n\n"); "$TBBASE/show-dataset.php?uuid=$lease_uuid\n\n");
print "NOTE: lease must still be approved before it can be used\n"; print "NOTE: lease must still be approved before it can be used\n";
# Tell the web server the reason for not being approved.
if (defined($webtask)) {
$webtask->needapproval(1);
$webtask->unapproved_reason($unapproved_reason)
if (defined($unapproved_reason));
}
} }
exit(0); exit(0);
...@@ -708,6 +736,11 @@ sub fatal($) ...@@ -708,6 +736,11 @@ sub fatal($)
$quota->Unlock() $quota->Unlock()
if (defined($quota)); if (defined($quota));
if (defined($webtask)) {
$webtask->output($mesg);
$webtask->Exited(-1);
}
die("*** $0:\n". die("*** $0:\n".
" $mesg\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