Commit f68756be authored by Leigh B. Stoller's avatar Leigh B. Stoller

Various fixes to the history code.

parent 4a7073f7
......@@ -166,6 +166,7 @@ CREATE TABLE `geni_crls` (
`created` datetime default NULL,
`expires` datetime default NULL,
`cert` text,
`DN` text,
PRIMARY KEY (`uuid`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
......@@ -255,12 +256,19 @@ CREATE TABLE `aggregate_history` (
`creator_hrn` varchar(256) NOT NULL default '',
`created` datetime default NULL,
`destroyed` datetime default NULL,
`aggregate_uuid` varchar(40) default NULL,
PRIMARY KEY (`idx`),
UNIQUE KEY `uuid` (`uuid`),
INDEX `slice_uuid` (`slice_uuid`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
CREATE TABLE `manifest_history` (
`idx` int(10) unsigned NOT NULL auto_increment,
`aggregate_uuid` varchar(40) NOT NULL default '',
`created` datetime default NULL,
`manifest` text,
PRIMARY KEY (`idx`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
DROP TABLE IF EXISTS `ticket_history`;
CREATE TABLE `ticket_history` (
`idx` mediumint(8) unsigned NOT NULL default '0',
......@@ -268,9 +276,7 @@ CREATE TABLE `ticket_history` (
`owner_uuid` varchar(40) NOT NULL default '',
`owner_hrn` varchar(256) NOT NULL default '',
`slice_uuid` varchar(40) NOT NULL default '',
`target_uuid` varchar(40) NOT NULL default '',
`slice_hrn` varchar(256) NOT NULL default '',
`target_hrn` varchar(256) NOT NULL default '',
`created` datetime default NULL,
`redeemed` datetime default NULL,
`expired` datetime default NULL,
......
......@@ -33,6 +33,7 @@ use GeniUser;
use GeniRegistry;
use GeniUtil;
use GeniHRN;
use GeniUsage;
use libtestbed qw(SENDMAIL);
use emutil;
# Hate to import all this crap; need a utility library.
......@@ -370,7 +371,6 @@ sub GetTicket($;$)
return GeniResponse->Create(GENIRESPONSE_ERROR, undef,
"Could not create GeniTicket object");
}
$ticket->SetSlice($credential->target_uuid());
}
return GetTicketAux($credential,
$rspecstr, $isupdate, $impotent, 0, 1, $ticket);
......@@ -503,6 +503,9 @@ sub GetTicketAuxAux($$$$$$$$)
if (defined($ticket) && $ticket->stored() && $ticket->Lock() != 0) {
return GeniResponse->BusyResponse("ticket");
}
if (defined($ticket)) {
$ticket->SetSlice($slice);
}
#
#
......@@ -1201,7 +1204,7 @@ sub GetTicketAuxAux($$$$$$$$)
"Could not create GeniTicket object");
goto bad;
}
$newticket->SetSlice($slice->uuid());
$newticket->SetSlice($slice);
if ($newticket->Sign()) {
$response = GeniResponse->Create(GENIRESPONSE_ERROR, undef,
......@@ -1409,7 +1412,7 @@ sub SliverWorkAux($$$$$$$)
"Already have an aggregate for slice");
}
}
$ticket->SetSlice($slice_uuid)
$ticket->SetSlice($slice)
if (defined($ticket));
if ($slice->Lock() != 0) {
......@@ -2109,6 +2112,10 @@ sub SliverWorkAux($$$$$$$)
" manifest=". DBQuoteSpecial($manifest) . ", " .
" idx=NULL, slice_uuid='$slice_uuid', created=now()");
if (GeniUsage->NewManifest($aggregate, $rspec)) {
print STDERR "GeniUsage->NewManifest($aggregate) failed\n";
}
#
# The API states we return a credential to control the aggregate.
#
......@@ -2324,7 +2331,13 @@ sub ReleaseTicket($)
return GeniResponse->Create(GENIRESPONSE_ERROR, undef,
"Could not create GeniCredential object");
}
$ticket->SetSlice($credential->target_uuid());
my $slice_uuid = $credential->target_uuid();
my $slice = GeniSlice->Lookup($slice_uuid);
if (!defined($slice)) {
return GeniResponse->Create(GENIRESPONSE_ERROR, undef,
"No slice record for $slice_uuid");
}
$ticket->SetSlice($slice);
#
# Make sure the ticket was issued to the caller.
......
......@@ -413,7 +413,7 @@ sub DeleteSliver($)
$response = GeniResponse->Create(GENIRESPONSE_ERROR);
goto bad;
}
$ticket->SetSlice($slice->uuid());
$ticket->SetSlice($slice);
if ($ticket->Sign()) {
$ticket->Delete();
......
......@@ -492,7 +492,7 @@ sub GetTicket($$$$)
print STDERR $response->value() . "\n";
return -1;
}
$newticket->SetSlice($slice->uuid());
$newticket->SetSlice($slice);
if ($newticket->Store(TICKET_NOSTATS) != 0) {
print STDERR "*** Could not store $newticket\n";
return -1;
......
......@@ -154,7 +154,7 @@ sub Create($$$$)
$self->{'seqno'} = $seqno;
$self->{'ticket_string'} = undef;
$self->{'component'} = undef;
$self->{'slice_uuid'} = undef;
$self->{'slice'} = undef;
$self->{'stored'} = 0; # Stored to the DB.
$self->{'LOCKED'} = 0;
......@@ -198,7 +198,10 @@ sub redeemed($ ) { return field($_[0], "redeemed"); }
sub component_uuid($) { return field($_[0], "component_uuid"); }
sub component($) { return field($_[0], "component"); }
sub stored($) { return field($_[0], "stored"); }
sub slice_uuid($) { return field($_[0], "slice_uuid"); }
sub slice($) { return $_[0]->{'slice'}; }
sub slice_uuid($) { return $_[0]->slice()->uuid(); }
sub slice_hrn($) { return $_[0]->slice()->hrn(); }
sub slice_urn($) { return $_[0]->slice()->urn(); }
sub LOCKED($) { return $_[0]->{'LOCKED'}; }
......@@ -398,7 +401,7 @@ sub CreateFromSignedTicket($$;$$)
$self->{'seqno'} = $seqno;
$self->{'expires'} = $expires;
$self->{'stored'} = 0;
$self->{'slice_uuid'} = undef;
$self->{'slice'} = undef;
$self->{'LOCKED'} = 0;
#
......@@ -411,12 +414,24 @@ sub CreateFromSignedTicket($$;$$)
if ($query_result && $query_result->numrows) {
my $row = $query_result->fetchrow_hashref();
$self->{'redeem_before'} = $row->{'redeem_before'};
$self->{'slice_uuid'} = $row->{'slice_uuid'};
$self->{'idx'} = $seqno;
$self->{'stored'} = 1;
#
# Older tickets might not have the slice set. The CM will
# set it later though.
#
if (defined($row->{'slice_uuid'})) {
my $slice_uuid = $row->{'slice_uuid'};
my $slice = GeniSlice->Lookup($slice_uuid);
if (!defined($slice)) {
print STDERR
"Could not locate slice for ticket from $slice_uuid\n";
return undef;
}
$self->{'slice'} = $slice;
}
}
bless($self, $class);
return $self;
}
......@@ -519,9 +534,9 @@ sub UnLock($)
sub SetSlice($$)
{
my ($self, $slice_uuid) = @_;
my ($self, $slice) = @_;
$self->{'slice_uuid'} = $slice_uuid;
$self->{'slice'} = $slice;
return 0;
}
......
......@@ -187,16 +187,16 @@ sub NewTicket($$)
my $ticket_idx = $ticket->idx();
my $ticket_uuid = $ticket->uuid();
my $target_uuid = $ticket->target_uuid();
my $target_hrn = $ticket->target_hrn();
my $slice_uuid = $ticket->slice_uuid();
my $slice_hrn = $ticket->slice_hrn();
my $owner_uuid = $ticket->owner_uuid();
my $owner_hrn = $ticket->owner_hrn();
# Now tack on other stuff we need.
push(@insert_data, "idx='$ticket_idx'");
push(@insert_data, "uuid='$ticket_uuid'");
push(@insert_data, "target_uuid=" . DBQuoteSpecial($target_uuid));
push(@insert_data, "target_hrn=" . DBQuoteSpecial($target_hrn));
push(@insert_data, "slice_uuid=" . DBQuoteSpecial($slice_uuid));
push(@insert_data, "slice_hrn=" . DBQuoteSpecial($slice_hrn));
push(@insert_data, "owner_uuid=" . DBQuoteSpecial($owner_uuid));
push(@insert_data, "owner_hrn=" . DBQuoteSpecial($owner_hrn));
push(@insert_data, "created=now()");
......@@ -300,3 +300,25 @@ sub ListTickets($$)
@$pref = @result;
return 0;
}
#
# Create an entry in the manifest history table.
#
sub NewManifest($$$)
{
my ($class, $aggregate, $manifest) = @_;
my @insert_data = ();
my $aggregate_uuid = $aggregate->uuid();
my $manifest_string = XMLout($manifest, RootName => "manifest");
my $safe_manifest = DBQuoteSpecial($manifest_string);
# Insert into DB.
if (!DBQueryWarn("insert into manifest_history set " .
" idx=NULL, aggregate_uuid='$aggregate_uuid', ".
" created=now(), manifest=$safe_manifest")) {
return -1;
}
return 0;
}
......@@ -105,6 +105,16 @@ GeniUtil::FlipToGeniUser();
sub DoCM()
{
#
# Need an RPC context for this to work.
#
my $certificate = GeniCertificate->LoadFromFile("$TB/etc/genicm.pem");
fatal("Could not load CM certificate")
if (!defined($certificate));
Genixmlrpc->SetContext(Genixmlrpc->Context($certificate));
$ENV{'MYUUID'} = $certificate->uuid();
$ENV{'MYURN'} = "urn:publicid:IDN+@OURDOMAIN@+authority+cm";
if (GeniCM::CleanupDeadSlice($slice) != 0) {
fatal("Could not clean up slice $slice");
}
......@@ -126,6 +136,8 @@ sub DoSA()
fatal("Could not load SA certificate")
if (!defined($certificate));
Genixmlrpc->SetContext(Genixmlrpc->Context($certificate));
$ENV{'MYUUID'} = $certificate->uuid();
$ENV{'MYURN'} = "urn:publicid:IDN+@OURDOMAIN@+authority+sa";
if ($slice->UnRegister()) {
print STDERR "Could not unregister $slice from clearinghouse!\n";
......
......@@ -25,6 +25,7 @@ my $optlist = "";
my $TB = "@prefix@";
my $TBOPS = "@TBOPSEMAIL@";
my $TBLOGS = "@TBLOGSEMAIL@";
my $EMULAB_PEMFILE = "$TB/etc/genicm.pem";
# un-taint path
$ENV{'PATH'} = '/bin:/usr/bin:/usr/local/bin:/usr/site/bin';
......@@ -68,6 +69,16 @@ if (!$this_user->IsAdmin()) {
# Connect to the proper DB.
DBConnect(GENICM_DBNAME());
#
# So we know who/what we are acting as.
#
my $certificate = GeniCertificate->LoadFromFile($EMULAB_PEMFILE);
if (!defined($certificate)) {
fatal("Could not get uuid/urn from $EMULAB_PEMFILE\n");
}
$ENV{'MYUUID'} = $certificate->uuid();
$ENV{'MYURN'} = "urn:publicid:IDN+@OURDOMAIN@+authority+cm";
my $ticket = GeniTicket->Lookup($token);
if (!defined($ticket)) {
fatal("No such ticket for $token");
......
#
# Tweaks to history code.
#
use strict;
use GeniDB;
sub DoUpdate($$$)
{
my ($dbhandle, $dbname, $version) = @_;
DBSetDefault($dbhandle);
if (!DBSlotExists("geni_crls", "DN")) {
DBQueryFatal("alter table geni_crls add `DN` text");
}
if (!DBSlotExists("ticket_history", "target_uuid")) {
DBQueryFatal("alter table ticket_history drop target_uuid");
}
if (!DBSlotExists("ticket_history", "target_hrn")) {
DBQueryFatal("alter table ticket_history drop target_hrn");
}
if (!DBSlotExists("aggregate_history", "aggregate_uuid")) {
DBQueryFatal("alter table aggregate_history drop aggregate_uuid");
}
if (!DBTableExists("manifest_history")) {
DBQueryFatal("CREATE TABLE `manifest_history` ( ".
" `idx` int(10) unsigned NOT NULL auto_increment, ".
" `aggregate_uuid` varchar(40) NOT NULL default '', ".
" `created` datetime default NULL, ".
" `manifest` text, ".
" PRIMARY KEY (`idx`) ".
") ENGINE=MyISAM DEFAULT CHARSET=latin1");
}
return 0;
}
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