Commit 3484af9e authored by Leigh B Stoller's avatar Leigh B Stoller
Browse files

Add a call to refresh the manifest from the remote CM.

Clean up sliver action stuff, and add stop and restart.
parent 349dbd8c
......@@ -270,6 +270,7 @@ sub Refresh($)
$self->{'DBROW'} = $query_result->fetchrow_hashref();
$self->{'NEWTICKET'} = undef;
$self->{'MANIFEST'} = undef;
return 0;
}
......@@ -843,6 +844,112 @@ sub RedeemTicket($$)
return 0;
}
#
# Update the manifest.
#
sub GetManifest($$)
{
my ($self, $user) = @_;
my $response;
# Always clear for caller.
$self->{'last_rpc_error'} = 0;
$self->{'last_rpc_output'} = undef;
$self->{'last_rpc_value'} = undef;
my $slice = GeniSlice->Lookup($self->slice_idx());
if (!defined($slice)) {
print STDERR "*** GetManifest: No slice for $self\n";
return -1;
}
my $manager_urn = $self->manager_urn();
my $authority = GeniAuthority->CreateFromRegistry("cm", $manager_urn);
if (!defined($authority)) {
print STDERR "*** Could not find $manager_urn at ClearingHouse\n";
return -1;
}
my $manager_version = $self->ManagerVersion();
#
# Create a Geni user from current user doing the operation.
#
my $geniuser = GeniUser->CreateFromLocal($user);
if (!defined($geniuser)) {
print STDERR "*** Could not create a geni user from $user\n";
return -1;
}
my $usercontext = Genixmlrpc->UserContext($geniuser);
if (!defined($usercontext)) {
print STDERR "*** Could not create user context from $geniuser\n";
return -1;
}
#
# Load sliver credential.
#
if (!$self->credential_idx()) {
print STDERR "*** No credential defined for $self.\n";
return -1;
}
my $sliver_credential = GeniCredential->Lookup($self->credential_idx());
if (!defined($sliver_credential)) {
print STDERR "*** Could not get sliver credential for $self.\n";
return -1;
}
#
# Doit it.
#
my $method_name = "Resolve";
my $method_args = { 'credentials' => [$sliver_credential->asString()],
'urn' => $sliver_credential->target_urn(),
};
$response =
Genixmlrpc::CallMethod($authority->url(), $usercontext,
$method_name, $method_args);
if (!defined($response)) {
$self->{'last_rpc_error'} = GENIRESPONSE_RPCERROR();
print STDERR
"*** Internal error getting manifest for $self\n";
return -1;
}
$self->{'last_rpc_error'} = $response->code();
$self->{'last_rpc_output'} = $response->output();
$self->{'last_rpc_value'} = $response->value();
if ($response->code() != GENIRESPONSE_SUCCESS) {
print STDERR "Could not get manifest for $self. Error: ";
print STDERR " " . $response->output() . "\n";
return -1;
}
#
# Okay, so that worked. Store the new manifest.
#
my $manifest = $response->value()->{'manifest'};
#
# Move this elsewhere.
#
my $manifest_idx = ($self->manifest_idx() ?
$self->manifest_idx() : "NULL");
my $sliver_uuid = $sliver_credential->uuid();
my $query_result =
DBQueryWarn("replace into geni_manifests set ".
" manifest=". DBQuoteSpecial($manifest) . ", " .
" idx=$manifest_idx, slice_uuid='$sliver_uuid', ".
" created=now()");
return -1
if (!defined($query_result));
if (!$self->manifest_idx()) {
$manifest_idx = $query_result->insertid;
$self->Update({"manifest_idx" => $manifest_idx});
}
return 0;
}
#
# Clear all resources.
#
......@@ -1181,11 +1288,11 @@ sub Purge($$)
}
#
# Start a sliver. Optionally one part of it, but ignoring that for now.
# Start/Stop/Restart a sliver.
#
sub StartSliver($$$)
sub SliverAction($$$$)
{
my ($self, $user, $urn) = @_;
my ($self, $action, $user, $urn) = @_;
my $response;
# Always clear for caller.
......@@ -1256,7 +1363,7 @@ sub StartSliver($$$)
#
# Do it.
#
my $method_name = "StartSliver";
my $method_name = "${action}Sliver";
my $method_args = { "manifest" => $self->{'MANIFESTSTR'} };
if ($manager_version == 1.0) {
......@@ -1268,7 +1375,7 @@ sub StartSliver($$$)
}
else {
print STDERR
"GeniResource::StartSliver Unknown version at $authority\n";
"GeniResource::${action}Sliver Unknown version at $authority\n";
return -1;
}
$response =
......@@ -1277,26 +1384,44 @@ sub StartSliver($$$)
if (!defined($response)) {
$self->{'last_rpc_error'} = GENIRESPONSE_RPCERROR();
print STDERR
"*** Internal error starting sliver for $self\n";
"*** Internal error ${action}ing sliver for $self\n";
return -1;
}
$self->{'last_rpc_error'} = $response->code();
$self->{'last_rpc_output'} = $response->output();
$self->{'last_rpc_value'} = $response->value();
if ($response->code() != GENIRESPONSE_SUCCESS) {
print STDERR "Could not start sliver $sliver_credential Error: ";
print STDERR "Could not ${action} sliver $sliver_credential Error: ";
print STDERR " " . $response->output() . "\n";
return -1;
}
return 0;
}
sub StartSliver($$)
{
my ($self, $user) = @_;
return $self->SliverAction("Start", $user);
}
sub StopSliver($$)
{
my ($self, $user) = @_;
return $self->SliverAction("Stop", $user);
}
sub RestartSliver($$)
{
my ($self, $user) = @_;
return $self->SliverAction("Restart", $user);
}
#
# Call the sliver status function, returning an array.
#
sub SliverStatus($$$$)
sub SliverStatus($$$)
{
my ($self, $user, $pref, $urn) = @_;
my ($self, $user, $pref) = @_;
my ($response);
# Always clear for caller.
......
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