Commit 23d317e8 authored by Leigh B Stoller's avatar Leigh B Stoller

Bug Fix: Okay not really a bug fix, but this has to go in before the

push to stable. These changes properly record URNs in the aggregate
and manifest history tables.
parent ceef427b
......@@ -6,6 +6,7 @@ CREATE TABLE `geni_users` (
`uuid` varchar(40) NOT NULL default '',
`created` datetime default NULL,
`expires` datetime default NULL,
`last_activity` datetime default NULL,
`locked` datetime default NULL,
`archived` datetime default NULL,
`status` enum('active','archived','frozen') NOT NULL default 'frozen',
......@@ -278,33 +279,48 @@ CREATE TABLE `aggregate_history` (
`idx` mediumint(8) unsigned NOT NULL default '0',
`uuid` varchar(40) NOT NULL default '',
`hrn` varchar(256) NOT NULL default '',
`urn` tinytext,
`type` varchar(40) NOT NULL default '',
`exptidx` int(11) NOT NULL default '0',
`slice_urn` tinytext,
`slice_uuid` varchar(40) NOT NULL default '',
`slice_hrn` varchar(256) NOT NULL default '',
`creator_uuid` varchar(40) NOT NULL default '',
`creator_hrn` varchar(256) NOT NULL default '',
`creator_uuid` varchar(40) NOT NULL default '',
`creator_urn` tinytext,
`created` datetime default NULL,
`destroyed` datetime default NULL,
`reported` datetime default NULL,
PRIMARY KEY (`idx`),
UNIQUE KEY `uuid` (`uuid`),
INDEX `slice_uuid` (`slice_uuid`)
INDEX `slice_uuid` (`slice_uuid`),
INDEX `slice_urn` (`slice_urn`(255)),
INDEX `slice` (`slice_uuid`,`slice_urn`(255)),
INDEX `urn` (`urn`(255)),
INDEX `aggregate` (`uuid`,`urn`(255))
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
CREATE TABLE `manifest_history` (
`idx` int(10) unsigned NOT NULL auto_increment,
`aggregate_uuid` varchar(40) NOT NULL default '',
`aggregate_urn` tinytext,
`created` datetime default NULL,
`reported` datetime default NULL,
`rspec` text,
`manifest` text,
PRIMARY KEY (`idx`)
PRIMARY KEY (`idx`),
INDEX `aggregate_urn` (`aggregate_urn`(255)),
KEY `created` (`created`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
DROP TABLE IF EXISTS `ticket_history`;
CREATE TABLE `ticket_history` (
`idx` mediumint(8) unsigned NOT NULL default '0',
`uuid` varchar(40) NOT NULL default '',
`owner_urn` tinytext,
`owner_uuid` varchar(40) NOT NULL default '',
`owner_hrn` varchar(256) NOT NULL default '',
`slice_urn` tinytext,
`slice_uuid` varchar(40) NOT NULL default '',
`slice_hrn` varchar(256) NOT NULL default '',
`created` datetime default NULL,
......@@ -316,7 +332,9 @@ CREATE TABLE `ticket_history` (
`rspec_string` text,
PRIMARY KEY (`idx`),
UNIQUE KEY `uuid` (`uuid`),
INDEX `slice_uuid` (`slice_uuid`)
INDEX `slice_uuid` (`slice_uuid`),
INDEX `slice_urn` (`slice_urn`(255)),
INDEX `slice` (`slice_uuid`,`slice_urn`(255))
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
DROP TABLE IF EXISTS `client_slivers`;
......
#!/usr/bin/perl -wT
#
# GENIPUBLIC-COPYRIGHT
# Copyright (c) 2008-2011 University of Utah and the Flux Group.
# Copyright (c) 2008-2012 University of Utah and the Flux Group.
# All rights reserved.
#
package GeniAggregate;
......@@ -214,10 +214,6 @@ sub Create($$$$$$)
return undef
if (!defined($aggregate));
if (GeniUsage->NewAggregate($aggregate, $slice, $owner)) {
print STDERR "GeniAggregate::Create: ".
"GeniUsage->NewAggregate($aggregate) failed\n";
}
return $aggregate;
}
# accessors
......
......@@ -469,6 +469,9 @@ sub GetTicketAux($$$$$$$)
my $user = CreateUserFromCertificate($credential);
return $user
if (GeniResponse::IsResponse($user));
# Bump activity. Does not matter if request fails ...
$user->BumpActivity();
#
# Create slice from the certificate.
......@@ -2512,6 +2515,9 @@ sub SliverWorkAux($$$$$$$)
return $owner
if (GeniResponse::IsResponse($owner));
# Bump activity. Does not matter if request fails ...
$owner->BumpActivity();
# And the experiment.
my $experiment = GeniExperiment($slice, $owner);
if (GeniResponse::IsResponse($experiment)) {
......@@ -3524,18 +3530,6 @@ sub SliverWorkAux($$$$$$$)
}
}
#
# Move this elsewhere.
#
my $manifest_string = GeniXML::Serialize($manifest);
DBQueryWarn("replace into geni_manifests set ".
" manifest=". DBQuoteSpecial($manifest_string) . ", " .
" 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.
#
......@@ -3545,6 +3539,27 @@ sub SliverWorkAux($$$$$$$)
$message = "Could not create credential";
goto bad;
}
#
# Record all manifests (including updates) in the history.
#
if (GeniUsage->NewManifest($aggregate, $manifest, $rspec)) {
print STDERR "GeniUsage->NewManifest($aggregate) failed\n";
}
#
# Each new aggregate gets a history record.
#
if (!$isupdate &&
GeniUsage->NewAggregate($aggregate, $slice, $owner)) {
print STDERR "GeniUsage->NewAggregate($aggregate) failed\n";
}
# This should move someplace else?
my $manifest_string = GeniXML::Serialize($manifest);
DBQueryWarn("replace into geni_manifests set ".
" manifest=". DBQuoteSpecial($manifest_string) . ", " .
" idx=NULL, slice_uuid='$slice_uuid', created=now()");
#
# Cache the credential for subsequent requests. See GetSliver().
# Okay if this fails.
......@@ -3657,9 +3672,6 @@ sub SliverWorkAux($$$$$$$)
}
}
$aggregate->Delete(GENI_PURGEFLAG)
if (defined($aggregate) && !$isupdate);
$slice->UnLock();
$ticket->UnLock()
if (defined($ticket));
......@@ -4361,7 +4373,7 @@ sub ListUsage($)
return GeniResponse->Create(GENIRESPONSE_ERROR);
}
# The caller has to match the clearinghouse.
# The caller (owner) has to match the clearinghouse.
if ($credential->owner_urn() ne $certificate->urn()) {
return GeniResponse->Create(GENIRESPONSE_ERROR, undef,
"Only the clearinghouse can do this!");
......@@ -4423,8 +4435,8 @@ sub ListUsage($)
sub ListHistory($)
{
my ($argref) = @_;
my $cred = $argref->{'credential'};
my $type = $argref->{'type'};
my $cred = $argref->{'credential'};
my $type = $argref->{'type'};
if (! (defined($cred))) {
return GeniResponse->MalformedArgsResponse();
......@@ -4439,12 +4451,11 @@ sub ListHistory($)
return GeniResponse->Create(GENIRESPONSE_ERROR);
}
# The caller has to match the clearinghouse.
# The caller (owner) has to match the clearinghouse.
if ($credential->owner_urn() ne $certificate->urn()) {
return GeniResponse->Create(GENIRESPONSE_ERROR, undef,
"Only the clearinghouse can do this!");
}
my @tickets;
if (GeniUsage->ListTickets(\@tickets) != 0) {
return GeniResponse->Create(GENIRESPONSE_ERROR);
......
......@@ -122,20 +122,26 @@ sub NewAggregate($$$$)
my $aggregate_idx = $aggregate->idx();
my $aggregate_uuid = $aggregate->uuid();
my $aggregate_hrn = $aggregate->hrn();
my $aggregate_urn = $aggregate->urn();
my $aggregate_type = $aggregate->type();
my $slice_uuid = $slice->uuid();
my $slice_hrn = $slice->hrn();
my $slice_urn = $slice->urn();
my $exptidx = $slice->exptidx();
my $owner_uuid = $owner->uuid();
my $owner_hrn = $owner->hrn();
my $owner_urn = $owner->urn();
# Now tack on other stuff we need.
push(@insert_data, "idx='$aggregate_idx'");
push(@insert_data, "uuid='$aggregate_uuid'");
push(@insert_data, "hrn=" . DBQuoteSpecial($aggregate_hrn));
push(@insert_data, "urn=" . DBQuoteSpecial($aggregate_urn));
push(@insert_data, "type='$aggregate_type'");
push(@insert_data, "slice_uuid='$slice_uuid'");
push(@insert_data, "slice_hrn=" . DBQuoteSpecial($slice_hrn));
push(@insert_data, "slice_urn=" . DBQuoteSpecial($slice_urn));
push(@insert_data, "creator_urn=" . DBQuoteSpecial($owner_urn));
push(@insert_data, "creator_uuid='$owner_uuid'");
push(@insert_data, "creator_hrn=" . DBQuoteSpecial($owner_hrn));
push(@insert_data, "created=now()");
......@@ -170,9 +176,12 @@ sub DeleteAggregate($$)
#
# Update the destroyed/shutdown times for an aggregate.
#
sub DestroyAggregate($$)
sub DestroyAggregate($$$)
{
my ($class, $aggregate) = @_;
my ($class, $aggregate, $purge) = @_;
return GeniAggregate->DeleteAggregate($aggregate)
if ($purge);
my $aggregate_idx = $aggregate->idx();
......@@ -195,16 +204,20 @@ sub NewTicket($$)
my $ticket_uuid = $ticket->uuid();
my $slice_uuid = $ticket->slice_uuid();
my $slice_hrn = $ticket->slice_hrn();
my $slice_urn = $ticket->slice_urn();
my $owner_uuid = $ticket->owner_uuid();
my $owner_hrn = $ticket->owner_hrn();
my $owner_urn = $ticket->owner_urn();
# Now tack on other stuff we need.
push(@insert_data, "idx='$ticket_idx'");
push(@insert_data, "uuid='$ticket_uuid'");
push(@insert_data, "slice_uuid=" . DBQuoteSpecial($slice_uuid));
push(@insert_data, "slice_hrn=" . DBQuoteSpecial($slice_hrn));
push(@insert_data, "slice_urn=" . DBQuoteSpecial($slice_urn));
push(@insert_data, "owner_uuid=" . DBQuoteSpecial($owner_uuid));
push(@insert_data, "owner_hrn=" . DBQuoteSpecial($owner_hrn));
push(@insert_data, "owner_urn=" . DBQuoteSpecial($owner_urn));
push(@insert_data, "created=now()");
if (defined($ticket->rspec())) {
......@@ -299,19 +312,22 @@ sub ListTickets($$)
#
# Create an entry in the manifest history table.
#
sub NewManifest($$$)
sub NewManifest($$$$)
{
my ($class, $aggregate, $manifest) = @_;
my ($class, $aggregate, $manifest, $rspec) = @_;
my @insert_data = ();
my $aggregate_uuid = $aggregate->uuid();
my $manifest_string = GeniXML::Serialize($manifest);
my $safe_manifest = DBQuoteSpecial($manifest_string);
my $rspec_string = GeniXML::Serialize($rspec);
my $safe_rspec = DBQuoteSpecial($rspec_string);
# Insert into DB.
if (!DBQueryWarn("insert into manifest_history set " .
" idx=NULL, aggregate_uuid='$aggregate_uuid', ".
" created=now(), manifest=$safe_manifest")) {
" created=now(), ".
" manifest=$safe_manifest, rspec=$safe_rspec")) {
return -1;
}
return 0;
......
#!/usr/bin/perl -wT
#
# GENIPUBLIC-COPYRIGHT
# Copyright (c) 2008-2011 University of Utah and the Flux Group.
# Copyright (c) 2008-2012 University of Utah and the Flux Group.
# All rights reserved.
#
package GeniUser;
......@@ -201,6 +201,7 @@ sub uid($) { return field($_[0], "uid"); }
sub hrn($) { return field($_[0], "hrn"); }
sub uuid($) { return field($_[0], "uuid"); }
sub expires($) { return field($_[0], "expires"); }
sub last_activity($) { return field($_[0], "last_activity"); }
sub status($) { return field($_[0], "status"); }
sub created($) { return field($_[0], "created"); }
sub archived($) { return field($_[0], "archived"); }
......@@ -454,6 +455,25 @@ sub Archive($)
return 0;
}
#
# Bump activity.
#
sub BumpActivity($)
{
my ($self) = @_;
return 0
if (! ref($self));
my $idx = $self->idx();
DBQueryWarn("update geni_users set last_activity=now() ".
"where idx='$idx'")
or return -1;
return 0;
}
#
# Is this a local user.
#
......
#
# Add more cross referencing between geni and emulab DBs.
#
use strict;
use GeniDB;
use GeniUser;
use GeniHRN;
sub DoUpdate($$$)
{
my ($dbhandle, $dbname, $version) = @_;
DBSetDefault($dbhandle);
if (!DBSlotExists("aggregate_history", "urn")) {
DBQueryFatal("ALTER TABLE aggregate_history ADD ".
" `urn` tinytext ".
"after hrn");
}
if (!DBSlotExists("aggregate_history", "slice_urn")) {
DBQueryFatal("ALTER TABLE aggregate_history ADD ".
" `slice_urn` tinytext ".
"after exptidx");
}
if (!DBSlotExists("aggregate_history", "creator_urn")) {
DBQueryFatal("ALTER TABLE aggregate_history ADD ".
" `creator_urn` tinytext ".
"after slice_hrn");
}
if (!DBSlotExists("aggregate_history", "reported")) {
DBQueryFatal("ALTER TABLE aggregate_history ADD ".
" `reported` datetime default NULL ".
"after destroyed");
}
if (! DBKeyExists("aggregate_history", "slice_urn")) {
DBQueryFatal("ALTER TABLE `aggregate_history` " .
"add index `slice_urn` (`slice_urn`(255))");
}
if (! DBKeyExists("aggregate_history", "slice")) {
DBQueryFatal("ALTER TABLE `aggregate_history` " .
"add index `slice` (`slice_uuid`,`slice_urn`(255))");
}
if (! DBKeyExists("aggregate_history", "urn")) {
DBQueryFatal("ALTER TABLE `aggregate_history` " .
"add index `urn` (`urn`(255))");
}
if (! DBKeyExists("aggregate_history", "aggregate")) {
DBQueryFatal("ALTER TABLE `aggregate_history` " .
"add index `aggregate` (`uuid`,`urn`(255))");
}
#
# The manifest history table needs a urn too, since the clearinghouse
# is going to store these for all CMs.
#
if (!DBSlotExists("manifest_history", "aggregate_urn")) {
DBQueryFatal("ALTER TABLE manifest_history ADD ".
" `aggregate_urn` tinytext ".
"after aggregate_uuid");
}
if (!DBSlotExists("manifest_history", "reported")) {
DBQueryFatal("ALTER TABLE manifest_history ADD ".
" `reported` datetime default NULL ".
"after created");
}
# Also store original rspec.
if (!DBSlotExists("manifest_history", "rspec")) {
DBQueryFatal("ALTER TABLE manifest_history ADD ".
" `rspec` text ".
"after reported");
}
if (! DBKeyExists("manifest_history", "aggregate_urn")) {
DBQueryFatal("ALTER TABLE `manifest_history` " .
"add index `aggregate_urn` (`aggregate_urn`(255))");
}
if (! DBKeyExists("manifest_history", "uuid")) {
DBQueryFatal("ALTER TABLE `manifest_history` " .
"add KEY `created` (`created`)");
}
#
# Also the ticket_history table.
#
if (!DBSlotExists("ticket_history", "slice_urn")) {
DBQueryFatal("ALTER TABLE ticket_history ADD ".
" `slice_urn` tinytext ".
"after owner_hrn");
}
if (!DBSlotExists("ticket_history", "owner_urn")) {
DBQueryFatal("ALTER TABLE ticket_history ADD ".
" `owner_urn` tinytext ".
"after uuid");
}
if (! DBKeyExists("ticket_history", "slice_urn")) {
DBQueryFatal("ALTER TABLE `ticket_history` " .
"add index `slice_urn` (`slice_urn`(255))");
}
if (! DBKeyExists("ticket_history", "slice")) {
DBQueryFatal("ALTER TABLE `ticket_history` " .
"add index `slice` (`slice_uuid`,`slice_urn`(255))");
}
#
# Add last activity to geni users. This is just to record the last time
# the user created a slice, nothing else.
#
if (!DBSlotExists("geni_users", "last_activity")) {
DBQueryFatal("ALTER TABLE geni_users ADD ".
" `last_activity` datetime default NULL ".
"after expires");
}
#
# In the CM database, try to match up users so we can set the creator_urn.
# Not really possible to do the slice_urn since we do not store that
# in any of the history tables. It just so happens that we do not delete
# users from the geni_users table.
#
if ($dbname eq "geni-cm") {
my $query_result =
DBQueryFatal("select idx,slice_uuid,creator_uuid ".
" from aggregate_history");
while (my ($idx,$slice_uuid,$creator_uuid) =
$query_result->fetchrow_array()) {
# We want to include local users.
my $geniuser = GeniUser->Lookup($creator_uuid, 1);
next
if (!defined($geniuser));
my $creator_urn = $geniuser->urn();
next
if (! GeniHRN::IsValid($creator_urn));
my $safe_urn = DBQuoteSpecial($creator_urn);
DBQueryFatal("update aggregate_history set creator_urn=$safe_urn ".
"where idx='$idx'");
}
$query_result =
DBQueryFatal("select idx,slice_uuid,owner_uuid ".
" from ticket_history");
while (my ($idx,$slice_uuid,$owner_uuid) =
$query_result->fetchrow_array()) {
# We want to include local users.
my $geniuser = GeniUser->Lookup($owner_uuid, 1);
next
if (!defined($geniuser));
my $owner_urn = $geniuser->urn();
next
if (! GeniHRN::IsValid($owner_urn));
my $safe_urn = DBQuoteSpecial($owner_urn);
DBQueryFatal("update ticket_history set owner_urn=$safe_urn ".
"where idx='$idx'");
}
}
return 0;
}
1;
# Local Variables:
# mode:perl
# End:
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