Commit bb67bf1e authored by Leigh Stoller's avatar Leigh Stoller

Add routine to check the status of an aggregate; is it enabled and

can we connect to it (using GetVersion()).
parent dff1a01e
#!/usr/bin/perl -wT
#
# Copyright (c) 2007-2017 University of Utah and the Flux Group.
# Copyright (c) 2007-2018 University of Utah and the Flux Group.
#
# {{{EMULAB-LICENSE
#
......@@ -270,5 +270,34 @@ sub LookupByNickname($$)
return Lookup($class, $aggregate_urn);
}
#
# Check status of aggregate.
#
sub CheckStatus($$;$)
{
my ($self, $perrmsg, $portalrpc) = @_;
require APT_Geni;
if (0 || $self->disabled()) {
$$perrmsg = "The " . $self->name() . " cluster ".
"is currently offline, please try again later.";
return 1;
}
# Ping test. If we cannot get to the aggregate right now, bail.
my $retval = APT_Geni::PingAggregate($self, $perrmsg, $portalrpc);
if ($retval) {
if ($retval < 0) {
$$perrmsg = "Internal error contacting the ".
$self->name() . " cluster: " . $perrmsg;
}
else {
$$perrmsg = "The " . $self->name() . " cluster ".
"is currently unreachable, please try again later.";
}
return 1;
}
return 0;
}
# _Always_ make sure that this 1 is at the end of the file...
1;
#!/usr/bin/perl -wT
#
# Copyright (c) 2007-2017 University of Utah and the Flux Group.
# Copyright (c) 2007-2018 University of Utah and the Flux Group.
#
# {{{EMULAB-LICENSE
#
......@@ -523,26 +523,62 @@ sub PortalRPC($$$@)
if ($usemydevtree) {
$cmurl =~ s/protogeni/protogeni\/stoller/;
}
#
# We use the root context to talk to the Cluster RPC server
#
if (!defined($context)) {
$context = RootContext();
if (!defined($context)) {
return GeniResponse->Create(GENIRESPONSE_RPCERROR(), undef,
return GeniResponse->Create(GENIRESPONSE_ERROR(), undef,
"Could not get root context for RPC");
}
}
my $response = Genixmlrpc::CallMethod($cmurl, $context, $method, @args);
if ($response->code() != GENIRESPONSE_SUCCESS()) {
if (!defined($response->output())) {
$response->output("Operation failed, returned " .
$response->code());
$response->output(GENIRESPONSE_STRING($response->code()));
}
}
return $response;
}
#
# Ping an aggregate to see if its alive, using getversion.
#
sub PingAggregate($$;$)
{
my ($aggregate, $perrmsg, $portalrpc) = @_;
my $authority = GetAuthority($aggregate->urn());
my $context = RootContext();
if (!defined($authority)) {
$$perrmsg = "Could not lookup authority for $aggregate!";
return -1;
}
if (!defined($context)) {
$$perrmsg = "Could generate root context!";
return -1;
}
my $cmurl = $authority->url();
if (defined($portalrpc)) {
$cmurl =~ s/\/cm$/\/cluster/;
}
if ($usemydevtree) {
$cmurl =~ s/protogeni/protogeni\/stoller/;
}
my $oldto = Genixmlrpc->SetTimeout(10);
my $response = Genixmlrpc::CallMethod($cmurl, $context, "GetVersion");
Genixmlrpc->SetTimeout($oldto);
# Success is good!
return 0
if ($response->code() == GENIRESPONSE_SUCCESS());
#print STDERR Dumper($response);
$$perrmsg = $response->error();
return $response->code();
}
# _Always_ make sure that this 1 is at the end of the file...
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