Commit d5c3202e authored by Leigh Stoller's avatar Leigh Stoller

Allow a geni slice to be a placeholder slice; not quite a slice. This

is used in the vlan tag reservation code; when another CM tries to
reserve a tag for a slice we have not seen yet, we need to create
enough local state to make it work. Later when the local CM sees a
real getticket, we turn it from a placeholder slice into a real slice.
parent 72c9008f
...@@ -60,6 +60,7 @@ CREATE TABLE `geni_slices` ( ...@@ -60,6 +60,7 @@ CREATE TABLE `geni_slices` (
`sa_uuid` varchar(40) NOT NULL default '', `sa_uuid` varchar(40) NOT NULL default '',
`registered` tinyint(1) NOT NULL default '0', `registered` tinyint(1) NOT NULL default '0',
`needsfirewall` tinyint(1) NOT NULL default '0', `needsfirewall` tinyint(1) NOT NULL default '0',
`isplaceholder` tinyint(1) NOT NULL default '0',
PRIMARY KEY (`idx`), PRIMARY KEY (`idx`),
UNIQUE KEY `hrn` (`hrn`), UNIQUE KEY `hrn` (`hrn`),
UNIQUE KEY `uuid` (`uuid`) UNIQUE KEY `uuid` (`uuid`)
......
...@@ -165,7 +165,6 @@ sub Create($$$$;$$) ...@@ -165,7 +165,6 @@ sub Create($$$$;$$)
# Now tack on other stuff we need. # Now tack on other stuff we need.
push(@insert_data, "created=now()"); push(@insert_data, "created=now()");
push(@insert_data, "expires=DATE_ADD(now(), INTERVAL 6 HOUR)"); push(@insert_data, "expires=DATE_ADD(now(), INTERVAL 6 HOUR)");
push(@insert_data, "idx='$idx'");
push(@insert_data, "sa_uuid='$sa_uuid'"); push(@insert_data, "sa_uuid='$sa_uuid'");
push(@insert_data, "exptidx=$exptidx") push(@insert_data, "exptidx=$exptidx")
if (defined($exptidx)); if (defined($exptidx));
...@@ -174,23 +173,77 @@ sub Create($$$$;$$) ...@@ -174,23 +173,77 @@ sub Create($$$$;$$)
my $safe_hrn = DBQuoteSpecial($certificate->hrn()); my $safe_hrn = DBQuoteSpecial($certificate->hrn());
my $safe_uuid = DBQuoteSpecial($certificate->uuid()); my $safe_uuid = DBQuoteSpecial($certificate->uuid());
my $safe_cuuid = DBQuoteSpecial($creator->uuid());
my $safe_curn = DBQuoteSpecial($creator->urn());
push(@insert_data, "hrn=$safe_hrn"); push(@insert_data, "hrn=$safe_hrn");
push(@insert_data, "uuid=$safe_uuid"); push(@insert_data, "uuid=$safe_uuid");
push(@insert_data, "creator_uuid=$safe_cuuid");
push(@insert_data, "creator_urn=$safe_curn"); if (defined($creator)) {
my $safe_cuuid = DBQuoteSpecial($creator->uuid());
my $safe_curn = DBQuoteSpecial($creator->urn());
push(@insert_data, "creator_uuid=$safe_cuuid");
push(@insert_data, "creator_urn=$safe_curn");
}
else {
# No creator means this did not come from the actual user.
push(@insert_data, "creator_uuid=''");
push(@insert_data, "isplaceholder='1'");
}
if ($certificate->Store() != 0) { if ($certificate->Store() != 0) {
print STDERR "Could not store certificate for new slice.\n"; print STDERR "Could not store certificate for new slice.\n";
return undef; return undef;
} }
# Insert into DB. #
return undef # Lock the table and look for an existing entry. If there is one,
if (! DBQueryWarn("insert into geni_slices set " . # and it is the placeholder entry, overwrite it.
join(",", @insert_data))); #
DBQueryWarn("lock tables geni_slices write")
or return undef;
my $query_result =
DBQueryWarn("select idx,isplaceholder from geni_slices " .
"where uuid=$safe_uuid or hrn=$safe_hrn");
if (!$query_result) {
DBQueryWarn("unlock tables");
return undef;
}
if ($query_result->numrows) {
if ($query_result->numrows != 1) {
my $urn = $certificate->urn();
my $uuid = $certificate->uuid();
my $hrn = $certificate->hrn();
print STDERR "Too many rows for $uuid/$hrn/$urn\n";
DBQueryWarn("unlock tables");
return undef;
}
my ($curidx,$isplaceholder) = $query_result->fetchrow_array();
#
# If the existing entry is a placeholder, and we got the creator,
# then replace the existing entry to make it a non-placeholder.
#
if ($isplaceholder && defined($creator)) {
push(@insert_data, "idx='$curidx'");
if (! DBQueryWarn("replace into geni_slices set " .
" isplaceholder=0, ".
join(",", @insert_data))) {
DBQueryWarn("unlock tables");
return undef;
}
$idx = $curidx;
goto didit;
}
}
# Do this after above code since we might need to overwrite entry.
push(@insert_data, "idx='$idx'");
# Insert into DB.
if (! DBQueryWarn("insert into geni_slices set " .
join(",", @insert_data))) {
DBQueryWarn("unlock tables");
return undef;
}
didit:
DBQueryWarn("unlock tables");
my $slice = GeniSlice->Lookup($idx); my $slice = GeniSlice->Lookup($idx);
return undef return undef
if (!defined($slice)); if (!defined($slice));
...@@ -213,6 +266,7 @@ sub sa_uuid($) { return field($_[0], "sa_uuid"); } ...@@ -213,6 +266,7 @@ sub sa_uuid($) { return field($_[0], "sa_uuid"); }
sub exptidx($) { return field($_[0], "exptidx"); } sub exptidx($) { return field($_[0], "exptidx"); }
sub needsfirewall($) { return field($_[0], "needsfirewall"); } sub needsfirewall($) { return field($_[0], "needsfirewall"); }
sub registered($) { return field($_[0], "registered"); } sub registered($) { return field($_[0], "registered"); }
sub isplaceholder($) { return field($_[0], "isplaceholder"); }
sub cert($) { return $_[0]->{'CERT'}->cert(); } sub cert($) { return $_[0]->{'CERT'}->cert(); }
sub GetCertificate($) { return $_[0]->{'CERT'}; } sub GetCertificate($) { return $_[0]->{'CERT'}; }
sub LOCKED($) { return $_[0]->{'LOCKED'}; } sub LOCKED($) { return $_[0]->{'LOCKED'}; }
...@@ -782,6 +836,30 @@ sub SetRegisteredFlag($$) ...@@ -782,6 +836,30 @@ sub SetRegisteredFlag($$)
return 0; return 0;
} }
#
# Convert from placeholder to real slice. Caller will have it locked.
#
sub ConvertPlaceholder($$)
{
my ($self, $user) = @_;
my $uuid = $self->uuid();
my $safe_cuuid = DBQuoteSpecial($user->uuid());
my $safe_curn = DBQuoteSpecial($user->urn());
my $query_result =
DBQueryWarn("update geni_slices set isplaceholder=0, " .
" creator_uuid=$safe_cuuid, creator_urn=$safe_curn ".
"where uuid='$uuid'");
return -1
if (!$query_result);
$self->{'SLICE'}->{'isplaceholder'} = 0;
$self->{'SLICE'}->{'creator_urn'} = $user->urn();
$self->{'SLICE'}->{'creator_uuid'} = $user->uuid();
return 0;
}
# #
# Delete all slices for an authority. # Delete all slices for an authority.
# #
......
#
# Add isplaceholder slot to geni_slices
#
use strict;
use GeniDB;
sub DoUpdate($$$)
{
my ($dbhandle, $dbname, $version) = @_;
DBSetDefault($dbhandle);
if (!DBSlotExists("geni_slices", "isplaceholder")) {
DBQueryFatal("alter table geni_slices ".
" add `isplaceholder` tinyint(1) NOT NULL default '0'");
}
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