Commit ab3f977b authored by Leigh B Stoller's avatar Leigh B Stoller
Browse files

Have the CH daemon download an advertisement for working CM,

and stash that into a directory in /usr/testbed/www/protogeni.
Needed for the protogeni flash client.
parent 36b8a791
......@@ -547,6 +547,60 @@ sub Resolve($$)
return $response->value();
}
#
# Discover resources at an authority (CM).
#
sub DiscoverResources($$)
{
my ($self, $urn) = @_;
my $manager_version = $self->Version();
return undef
if (!defined($manager_version));
#
# Need a credential to make this call.
#
if (!defined(Genixmlrpc->GetContext())) {
print STDERR "Need an RPC context to generate a self credential\n";
return undef;
}
my $context = Genixmlrpc->GetContext();
my $me = GeniAuthority->Lookup($context->certificate()->uuid());
if (!defined($me)) {
print STDERR "Could not find my own authority for $context\n";
return undef;
}
my $credential = GeniCredential->GetSelfCredential($me);
if (!defined($credential)) {
print STDERR "Could not create self credential for $me\n";
return undef;
}
my $method_args;
if ($manager_version == 2.0) {
$method_args->{'credentials'} = [$credential->asString()];
$method_args->{'available'} = 1;
}
else {
print STDERR "GeniAuthority::Discover: Unknown version at $self\n";
return undef;
}
my $response =
Genixmlrpc::CallMethod($self->url(), undef,
"DiscoverResources", $method_args);
if (!defined($response)) {
print STDERR "*** Internal error discovering resources at $self\n";
return undef;
}
if ($response->code() != GENIRESPONSE_SUCCESS) {
print STDERR "Could not discover resources at $self Error:";
print STDERR " " . $response->output() . "\n";
return undef;
}
return $response->value();
}
# _Always_ make sure that this 1 is at the end of the file...
1;
#!/usr/bin/perl -w
#
# GENIPUBLIC-COPYRIGHT
# Copyright (c) 2008-2010 University of Utah and the Flux Group.
# Copyright (c) 2008-2011 University of Utah and the Flux Group.
# All rights reserved.
#
use strict;
......@@ -17,7 +17,8 @@ sub usage()
print "Usage: ch_daemon [-d] [-n]\n";
exit(1);
}
my $optlist = "dn";
my $optlist = "dns";
my $oneshot = 0;
my $debug = 0;
my $impotent = 0;
......@@ -30,6 +31,7 @@ my $TBLOGS = "@TBLOGSEMAIL@";
my $PGENIDOMAIN = "@PROTOGENI_DOMAIN@";
my $PGENISUPPORT = @PROTOGENI_SUPPORT@;
my $PGENICLRHOUSE = @PROTOGENI_CLEARINGHOUSE@;
my $ADDIR = "$TB/www/protogeni/advertisements";
my $LOGFILE = "$TB/log/ch_daemon.log";
my $EMULAB_PEMFILE = "$TB/etc/genich.pem";
my $SLEEP_INTERVAL = 60;
......@@ -77,6 +79,9 @@ if (defined($options{"d"})) {
if (defined($options{"n"})) {
$impotent = 1;
}
if (defined($options{"s"})) {
$oneshot = 1;
}
# Do this early so that we talk to the right DB.
use vars qw($GENI_DBNAME);
......@@ -106,17 +111,19 @@ Genixmlrpc->SetTimeout(10);
$ENV{'MYUUID'} = $certificate->uuid();
$ENV{'MYURN'} = "urn:publicid:IDN+@OURDOMAIN@+authority+ch";
if (CheckDaemonRunning("ch_daemon")) {
fatal("Not starting another ch daemon!");
}
# Go to ground.
if (! $debug) {
if (TBBackGround($LOGFILE)) {
exit(0);
if (!$oneshot) {
if (CheckDaemonRunning("ch_daemon")) {
fatal("Not starting another ch daemon!");
}
# Go to ground.
if (! $debug) {
if (TBBackGround($LOGFILE)) {
exit(0);
}
}
if (MarkDaemonRunning("ch_daemon")) {
fatal("Could not mark daemon as running!");
}
}
if (MarkDaemonRunning("ch_daemon")) {
fatal("Could not mark daemon as running!");
}
#
# Setup a signal handler for newsyslog.
......@@ -130,7 +137,7 @@ sub handler()
$EUID = $SAVEEUID;
}
$SIG{HUP} = \&handler
if (!$debug);
if (! ($debug || $oneshot));
GeniUtil::FlipToGeniUser();
......@@ -146,6 +153,7 @@ sub ProbeCMs()
my $up = "Up:\n";
my $down = "Down:\n";
my $disabled = "Disabled:\n";
my %ads = ();
if (GeniAuthority->ListAll(\@authorities)) {
fatal("Could not get authorities list from the DB");
......@@ -166,12 +174,43 @@ sub ProbeCMs()
if (!defined($version)) {
print "Error getting version from $urn\n";
$down .= "$urn\n";
next;
}
print " Running version $version\n";
$up .= "$urn, version $version\n";
#
# Discover resources and cache; for the map client.
# Returns a string of xml.
#
my $resources = $authority->DiscoverResources();
# Errors will go to the log.
next
if (!defined($resources));
if (open(OUT, "> $ADDIR/$urn")) {
print OUT $resources;
print OUT "\n";
close(OUT);
# Save the name so we can write the text file at the end.
$ads{$urn} = $urn;
}
else {
print " Running version $version\n";
$up .= "$urn, version $version\n";
notify("Could not open $ADDIR/$urn for output\n");
next;
}
}
if (open(MAP, "> $ADDIR/list.txt")) {
foreach my $urn (keys(%ads)) {
print MAP "$urn\n";
}
close(MAP);
}
else {
notify("Could not open $ADDIR/list.txt for output\n");
next;
}
SENDMAIL("geni-dev-utah\@flux.utah.edu",
"ClearingHouse Daemon Message",
"This is an automated message from the ClearingHouse Daemon\n\n".
......@@ -202,6 +241,12 @@ sub ExpireSlices()
# (see below).
}
if ($oneshot) {
ProbeCMs();
ExpireSlices();
exit(0);
}
while (1) {
if (NoLogins()) {
sleep(5);
......@@ -237,7 +282,9 @@ sub fatal($)
$msg,
$TBOPS);
MarkDaemonStopped("ch_daemon");
MarkDaemonStopped("ch_daemon")
if (!$oneshot);
die("*** $0:\n".
" $msg\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