Formatting with the suggested coding style and added support for...

Formatting with the suggested coding style and added support for max_components policy and its exception credentials.
parent a47a532e
......@@ -237,8 +237,8 @@ sub DiscoverResourcesAux($$$)
#
my $allow_externalusers = 0;
if (!TBGetSiteVar('protogeni/allow_externalusers', \$allow_externalusers)){
# Cannot get the value, say no.
$allow_externalusers = 0;
# Cannot get the value, say no.
$allow_externalusers = 0;
}
# Figure out if user has a credentials that exempts him
......@@ -247,7 +247,7 @@ sub DiscoverResourcesAux($$$)
# then he should get access.
my $isExempted = 0;
foreach my $credential (@$credentials) {
if (1 == GeniXML::PolicyExists('allow_externalusers', $credential)) {
if (GeniXML::PolicyExists('allow_externalusers', $credential) == 1) {
$isExempted = 1;
last;
}
......@@ -505,19 +505,19 @@ sub GetTicketAuxAux($$$$$$$$$)
#
my $max_sliver_lifetime = 0;
if (!TBGetSiteVar('protogeni/max_sliver_lifetime', \$max_sliver_lifetime)){
# Cannot get the value, default it to 90 days.
$max_sliver_lifetime = 90;
# Cannot get the value, default it to 90 days.
$max_sliver_lifetime = 90;
}
# Check if the user has a credential that lets him obtain slivers
# with extended sliver lifetime. If so allow him to get sliver.
foreach my $credential (@$credentials) {
my $nodes = GeniXML::FindNodesNS("//n:max_sliver_lifetime",
$credential->extensions(), $GeniUtil::EXTENSIONS_NS);
if (0 < $nodes->size) {
$max_sliver_lifetime = int($nodes->pop()->string_value);
last;
}
my $nodes = GeniXML::FindNodesNS("//n:max_sliver_lifetime",
$credential->extensions(), $GeniUtil::EXTENSIONS_NS);
if ($nodes->size > 0) {
$max_sliver_lifetime = int($nodes->pop()->string_value);
last;
}
}
my $diff = $when - time();
if ($diff < (60 * 5) || $diff > (3600 * 24 * $max_sliver_lifetime)) {
......@@ -1939,7 +1939,35 @@ sub SliverWorkAux($$$$$$$)
GeniResponse->Create(GENIRESPONSE_ERROR, $logstuff, $message);
goto bad;
}
# Check to see if experiment is using more than what is limited by CM.
# protogeni/max_components sitevar controls number of nodes that can
# be allocated to an experiment.
my $max_components = 0;
if (!TBGetSiteVar('protogeni/max_components', \$max_components)) {
# Cannot get the value, default it to -1. Which means there is no limit.
$max_components = -1;
}
# Check if the user has a credential that lets him obtain slivers
# with extended sliver lifetime. If so allow him to get sliver.
foreach my $credential (@$credentials) {
my $nodes = GeniXML::FindNodesNS("//n:max_components",
$credential->extensions(), $GeniUtil::EXTENSIONS_NS);
if ($nodes->size > 0) {
$max_components = int($nodes->pop()->getAttribute("limit"));
last;
}
}
if ($max_components != -1 && $experiment->maximum_nodes() > $max_components) {
$message = "Experiment needs nodes(" . $experiment->maximum_nodes()
. ") that are more than the limit(" . $max_components
. ") imposed by CM.";
print STDERR $message;
goto bad;
}
#
# Must do this after the mapper runs.
#
......@@ -2541,7 +2569,7 @@ sub RenewSliverAux($$)
foreach my $credential (@$credentials) {
my $nodes = GeniXML::FindNodesNS("//n:max_sliver_lifetime",
$credential->extensions(), $GeniUtil::EXTENSIONS_NS);
if (0 < $nodes->size) {
if ($nodes->size > 0) {
$max_sliver_lifetime = int($nodes->pop()->string_value);
last;
}
......
......@@ -252,9 +252,9 @@ sub DiscoverResources($)
my $credential_objects = [];
foreach my $credstr (@$credentials) {
my $cred = CheckCredential($credstr);
push(@$credential_objects, $cred)
if(!GeniResponse::IsResponse($cred));
my $cred = CheckCredential($credstr);
push(@$credential_objects, $cred)
if(!GeniResponse::IsResponse($cred));
}
return GeniCM::DiscoverResourcesAux($available, $compress,
$credential_objects);
......@@ -914,9 +914,9 @@ sub RenewSlice($)
}
my $credential_objects = [];
foreach my $credstr (@$credentials) {
my $cred = CheckCredential($credstr);
push(@$credential_objects, $cred)
if(!GeniResponse::IsResponse($cred));
my $cred = CheckCredential($credstr);
push(@$credential_objects, $cred)
if(!GeniResponse::IsResponse($cred));
}
return GeniCM::RenewSliverAux($credential_objects, $valid_until);
}
......@@ -1072,9 +1072,9 @@ sub UpdateTicket($)
}
my $credential_objects = [];
foreach my $credstr (@$credentials) {
my $cred = CheckCredential($credstr);
push(@$credential_objects, $cred)
if(!GeniResponse::IsResponse($cred));
my $cred = CheckCredential($credstr);
push(@$credential_objects, $cred)
if(!GeniResponse::IsResponse($cred));
}
return GeniCM::GetTicketAuxAux($slice, $user,
$rspecstr, 1, $impotent, 1, 1, $ticket, $credential_objects);
......@@ -1146,9 +1146,9 @@ sub UpdateSliver($)
}
my $credential_objects = [];
foreach my $credstr (@$credentials) {
my $cred = CheckCredential($credstr);
push(@$credential_objects, $cred)
if(!GeniResponse::IsResponse($cred));
my $cred = CheckCredential($credstr);
push(@$credential_objects, $cred)
if(!GeniResponse::IsResponse($cred));
}
return GeniCM::GetTicketAuxAux($slice, $user,
$rspecstr, 1, $impotent, 1, 1, undef, $credential_objects);
......
......@@ -188,16 +188,18 @@ sub AddExtension
my $self = shift;
my $elem = undef;
return -1
if (!ref($self));
if (1 == @_) {
# it means xml element is specified.
$elem = shift;
}elsif (2 == @_){
# it means key/value pair is specified.
$elem = XML::LibXML::Element->new($_[0]);
$elem->appendText($_[1]);
}else {
return -1;
if (!ref($self));
if (@_ == 1) {
# it means xml element is specified.
$elem = shift;
}
elsif (@_ == 2) {
# it means key/value pair is specified.
$elem = XML::LibXML::Element->new($_[0]);
$elem->appendText($_[1]);
}
else {
return -1;
}
my $root = $self->extensions();
......@@ -280,7 +282,7 @@ sub CreateFromSigned($$;$)
my ($extensions) = GeniXML::FindNodes('//n:extensions',
$root)->get_nodelist;
return undef
if (!defined($extensions));
if (!defined($extensions));
# UUID of the credential.
my ($uuid_node) = $doc->getElementsByTagName("uuid");
return undef
......
......@@ -322,24 +322,24 @@ sub RemoveChild($$)
# credential.
sub PolicyExists($$)
{
my ($policy, $credential) = @_;
my $exists = 0;
my ($policy, $credential) = @_;
my $exists = 0;
return 0
if (!ref($credential) or !defined($policy));
my $extensions_elem = $credential->extensions();
return 0
if (!defined($extensions_elem));
my $policies = GeniXML::FindNodesNS("//n:policy_exceptions/*",
return 0
if (!ref($credential) or !defined($policy));
my $extensions_elem = $credential->extensions();
return 0
if (!defined($extensions_elem));
my $policies = GeniXML::FindNodesNS("//n:policy_exceptions/*",
$extensions_elem, $GeniUtil::EXTENSIONS_NS);
foreach my $epolicy ($policies->get_nodelist) {
if ($policy eq $epolicy->string_value) {
$exists = 1;
last;
}
}
foreach my $epolicy ($policies->get_nodelist) {
if ($policy eq $epolicy->string_value) {
$exists = 1;
last;
}
}
return $exists;
return $exists;
}
# _Always_ make sure that this 1 is at the end of the file...
......
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