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

Beef up Create() routine, used from the Protogeni cooked mode to

create "proxy" nodes for remote geni nodes.

Clean up method access to reserved table slots.

Changes/Fixes to CreateVnodes() to support cooked mode Protogeni
nodes.
parent b8a25ce0
...@@ -253,6 +253,11 @@ sub AUTOLOAD { ...@@ -253,6 +253,11 @@ sub AUTOLOAD {
# #
# Create a new node. # Create a new node.
# #
# The list of table we have to clear if anything goes wrong.
my @cleantables = ("nodes", "node_hostkeys", "node_status",
"node_activity", "node_utilization",
"node_auxtypes", "reserved", "widearea_nodeinfo");
sub Create($$$$) sub Create($$$$)
{ {
my ($class, $node_id, $experiment, $argref) = @_; my ($class, $node_id, $experiment, $argref) = @_;
...@@ -286,30 +291,56 @@ sub Create($$$$) ...@@ -286,30 +291,56 @@ sub Create($$$$)
print STDERR "*** No virtnode_capacity for $type! Using zero.\n"; print STDERR "*** No virtnode_capacity for $type! Using zero.\n";
$virtnode_capacity = 0; $virtnode_capacity = 0;
} }
if ($typeinfo->adminmfs_osid(\$adminmfs_osid)) { if ($isremote) {
print STDERR "*** No adminmfs osid for $type!\n"; $osid = 0;
return undef; $opmode = "";
}
# Find object for the adminfs. if (defined($typeinfo->default_osid())) {
if (defined($adminmfs_osid)) { $osid = $typeinfo->default_osid();
$adminmfs = OSinfo->Lookup($adminmfs_osid);
my $osinfo = OSinfo->Lookup($osid);
if (!defined($osinfo)) {
print STDERR
"*** Could not find OSinfo object for $osid!\n";
return undef;
}
$osid = $osinfo->osid();
$opmode = $osinfo->op_mode();
}
} }
else { else {
$adminmfs = OSinfo->Lookup(TBOPSPID(), $MFS_INITIAL); if ($typeinfo->adminmfs_osid(\$adminmfs_osid)) {
} print STDERR "*** No adminmfs osid for $type!\n";
if (!defined($adminmfs)) { return undef;
print STDERR "*** Could not find OSinfo object for adminmfs!\n"; }
return undef; # Find object for the adminfs.
if (defined($adminmfs_osid)) {
$adminmfs = OSinfo->Lookup($adminmfs_osid);
}
else {
$adminmfs = OSinfo->Lookup(TBOPSPID(), $MFS_INITIAL);
}
if (!defined($adminmfs)) {
print STDERR
"*** Could not find OSinfo object for adminmfs!\n";
return undef;
}
$osid = $adminmfs->osid();
$opmode = $adminmfs->op_mode();
} }
$osid = $adminmfs->osid();
$opmode = $adminmfs->op_mode();
} }
else { else {
$osid = 0; $osid = 0;
$opmode = ""; $opmode = "";
} }
$state = $STATE_INITIAL; $state = $STATE_INITIAL;
#
# Lock the tables to prevent concurrent creation
#
DBQueryWarn("lock tables nodes write, widearea_nodeinfo write")
or return -1;
# #
# Make up a priority (just used for sorting) # Make up a priority (just used for sorting)
# #
...@@ -319,21 +350,35 @@ sub Create($$$$) ...@@ -319,21 +350,35 @@ sub Create($$$$)
else { else {
$priority = 1; $priority = 1;
} }
# The list of table we have to clear if anything goes wrong.
my @cleantables = ("nodes", "node_hostkeys", "node_status", if (!DBQueryWarn("insert into nodes set ".
"node_activity", "node_utilization", " node_id='$node_id', type='$type', " .
"node_auxtypes", "reserved"); " phys_nodeid='$node_id', role='$role', ".
" priority=$priority, " .
DBQueryWarn("insert into nodes set ". " eventstate='$state', op_mode='$opmode', " .
" node_id='$node_id', type='$type', " . " def_boot_osid='$osid', " .
" phys_nodeid='$node_id', role='$role', ". " inception=now(), uuid=$uuid, ".
" priority=$priority, " . " state_timestamp=unix_timestamp(NOW()), " .
" eventstate='$state', op_mode='$opmode', " . " op_mode_timestamp=unix_timestamp(NOW())")) {
" def_boot_osid='$osid', " . DBQueryWarn("unlock tables");
" inception=now(), uuid=$uuid, ". return undef;
" state_timestamp=unix_timestamp(NOW()), " . }
" op_mode_timestamp=unix_timestamp(NOW())") if ($isremote) {
or goto bad; my $hostname = $argref->{'hostname'};
my $external = $argref->{'external_node_id'};
my $IP = $argref->{'IP'};
if (!DBQueryWarn("replace into widearea_nodeinfo ".
" (node_id, contact_uid, contact_idx, hostname," .
" external_node_id, IP) ".
" values ('$node_id', 'nobody', '0', ".
" '$hostname', '$external', '$IP')")) {
DBQueryWarn("delete from nodes where node_id='$node_id'");
DBQueryWarn("unlock tables");
return undef;
}
}
DBQueryWarn("unlock tables");
if ($role eq "testnode") { if ($role eq "testnode") {
DBQueryWarn("insert into node_hostkeys (node_id) ". DBQueryWarn("insert into node_hostkeys (node_id) ".
...@@ -399,6 +444,20 @@ sub Create($$$$) ...@@ -399,6 +444,20 @@ sub Create($$$$)
return undef; return undef;
} }
#
# Only use this for Create() errors.
#
sub Delete($)
{
my ($self) = @_;
my $node_id = $self->node_id();
foreach my $table (@cleantables) {
DBQueryWarn("delete from $table where node_id='$node_id'");
}
return 0;
}
# #
# Refresh a class instance by reloading from the DB. # Refresh a class instance by reloading from the DB.
# #
...@@ -984,43 +1043,29 @@ sub HasVirtualNodes($) ...@@ -984,43 +1043,29 @@ sub HasVirtualNodes($)
return $query_result->numrows; return $query_result->numrows;
} }
# Need to create a set of access methods for the reservation. #
sub vname($) # Access methods for the reservation.
{ #
my ($self) = @_; sub __reservation($$)
return undef
if (! ref($self));
return undef
if (! $self->IsReserved());
return $self->{"RSRV"}->{'vname'};
}
sub sharing_mode($)
{ {
my ($self) = @_; my ($self, $slotname) = @_;
return undef return undef
if (! ref($self)); if (! ref($self));
return undef return undef
if (! $self->IsReserved()); if (! $self->IsReserved());
return $self->{"RSRV"}->{'sharing_mode'};
}
sub erole($)
{
my ($self) = @_;
return undef return undef
if (! ref($self)); if (! exists($self->{"RSRV"}->{$slotname}));
return undef return $self->{"RSRV"}->{$slotname};
if (! $self->IsReserved());
return $self->{"RSRV"}->{'erole'};
} }
sub vname($) { return __reservation($_[0], 'vname'); }
sub sharing_mode($) { return __reservation($_[0], 'sharing_mode'); }
sub erole($) { return __reservation($_[0], 'erole'); }
sub external_resource_index($) {
return __reservation($_[0], 'external_resource_index'); }
sub external_resource_id($) {
return __reservation($_[0], 'external_resource_id'); }
# #
# Lookup a specific attribute in the node_attributes table, # Lookup a specific attribute in the node_attributes table,
...@@ -1174,7 +1219,8 @@ sub Update($$) ...@@ -1174,7 +1219,8 @@ sub Update($$)
my $val = $argref->{$key}; my $val = $argref->{$key};
# Treat NULL special. # Treat NULL special.
push (@sets, "${key}=" . ($val eq "NULL" ? "NULL" : "'$val'")); push (@sets, "${key}=" . ($val eq "NULL" ?
"NULL" : DBQuoteSpecial($val)));
} }
my $query = "update nodes set " . join(",", @sets) . my $query = "update nodes set " . join(",", @sets) .
...@@ -1534,8 +1580,9 @@ sub CreateVnodes($$) ...@@ -1534,8 +1580,9 @@ sub CreateVnodes($$)
print STDERR "*** CreateVnodes: Not a dynamic node type: '$vtype'\n"; print STDERR "*** CreateVnodes: Not a dynamic node type: '$vtype'\n";
return -1; return -1;
} }
my $isremote = $nodetype->isremotenode(); my $isremote = $nodetype->isremotenode();
my $isjailed = $nodetype->isjailed(); my $isjailed = $nodetype->isjailed();
my $isfednode = $nodetype->isfednode();
# #
# Make up a priority (just used for sorting). We need the name prefix # Make up a priority (just used for sorting). We need the name prefix
...@@ -1544,7 +1591,13 @@ sub CreateVnodes($$) ...@@ -1544,7 +1591,13 @@ sub CreateVnodes($$)
my $nodeprefix; my $nodeprefix;
my $nodenum; my $nodenum;
my $ipbase; my $ipbase;
if ($pnode =~ /^(.*\D)(\d+)$/) {
if ($isfednode) {
$nodeprefix = $nodetype->type();
$nodenum = "";
$ipbase = 0;
}
elsif ($pnode =~ /^(.*\D)(\d+)$/) {
$nodeprefix = $1; $nodeprefix = $1;
$nodenum = $2; $nodenum = $2;
$ipbase = $nodenum; $ipbase = $nodenum;
...@@ -1553,25 +1606,29 @@ sub CreateVnodes($$) ...@@ -1553,25 +1606,29 @@ sub CreateVnodes($$)
$nodeprefix = $pnode; $nodeprefix = $pnode;
$nodenum = ""; $nodenum = "";
# if ($isjailed) {
# Determine ipbase from the control IP. #
# # Determine ipbase from the control IP (jailed nodes).
my $interface = Interface->LookupControl($node); #
if (!defined($interface)) { my $interface = Interface->LookupControl($node);
print STDERR "*** CreateVnodes: No control interface for $node\n"; if (!defined($interface)) {
return -1; print STDERR
} "*** CreateVnodes: No control interface for $node\n";
my $ctrlip = $interface->IP(); return -1;
if (!defined($ctrlip) || $ctrlip eq "") { }
print STDERR "*** CreateVnodes: No control IP for $interface\n"; my $ctrlip = $interface->IP();
return -1; if (!defined($ctrlip) || $ctrlip eq "") {
} print STDERR
my $tmp = ~inet_aton($CONTROL_NETMASK) & inet_aton($ctrlip); "*** CreateVnodes: No control IP for $interface\n";
$ipbase = unpack("N", $tmp); return -1;
if ($ipbase == 0 || $ipbase < 0 || $ipbase > 0x3fff) { }
print STDERR my $tmp = ~inet_aton($CONTROL_NETMASK) & inet_aton($ctrlip);
"*** CreateVnodes: Bad ipbase '$ipbase' for $interface\n"; $ipbase = unpack("N", $tmp);
return -1; if ($ipbase == 0 || $ipbase < 0 || $ipbase > 0x3fff) {
print STDERR
"*** CreateVnodes: Bad ipbase '$ipbase' for $interface\n";
return -1;
}
} }
} }
...@@ -1632,7 +1689,7 @@ sub CreateVnodes($$) ...@@ -1632,7 +1689,7 @@ sub CreateVnodes($$)
$node->FlushReserved(); $node->FlushReserved();
my $sharing_mode = $node->sharing_mode(); my $sharing_mode = $node->sharing_mode();
if (!$impotent) { if (! ($impotent || $isfednode)) {
my $reservation = $node->Reservation(); my $reservation = $node->Reservation();
if (!defined($reservation)) { if (!defined($reservation)) {
print STDERR "*** CreateVnodes: no reservation for $node!\n"; print STDERR "*** CreateVnodes: no reservation for $node!\n";
...@@ -1688,33 +1745,36 @@ sub CreateVnodes($$) ...@@ -1688,33 +1745,36 @@ sub CreateVnodes($$)
# #
# Create a bunch. # Create a bunch.
# #
foreach my $i (@tocreate) { foreach my $n (@tocreate) {
my $vpriority = 10000000 + ($ipbase * 1000) + $i; my $vpriority = 10000000 + ($ipbase * 1000) + $n;
my $vnodeid = $nodeprefix . "vm" . $nodenum . "-" . $i; my $vnodeid = $nodeprefix . "vm" . $nodenum . "-" . $n;
my $jailip;
#
# Construct the vnode IP. The general form is: if ($isjailed) {
# <IPBASE1>.<IPBASE2>.<pnode>.<vnode> #
# but if <pnode> is greater than 254 we have to increment # Construct the vnode IP. The general form is:
# IPBASE2. # <IPBASE1>.<IPBASE2>.<pnode>.<vnode>
# # but if <pnode> is greater than 254 we have to increment
# XXX at Utah our second big cluster of nodes starts at # IPBASE2.
# nodenum=201 and I would like our vnode IPs to align #
# at that boundary, so 254 becomes 200. # XXX at Utah our second big cluster of nodes starts at
# # nodenum=201 and I would like our vnode IPs to align
my $nodenumlimit = $ISUTAH ? 200 : 254; # at that boundary, so 254 becomes 200.
my $pnet = $IPBASE2; #
my $pnode2 = int($ipbase); my $nodenumlimit = $ISUTAH ? 200 : 254;
while ($pnode2 > $nodenumlimit) { my $pnet = $IPBASE2;
$pnet++; my $pnode2 = int($ipbase);
$pnode2 -= $nodenumlimit; while ($pnode2 > $nodenumlimit) {
$pnet++;
$pnode2 -= $nodenumlimit;
}
$jailip = "${IPBASE1}.${pnet}.${pnode2}.${n}";
} }
my $jailip = "${IPBASE1}.${pnet}.${pnode2}.${i}";
# Need to keep the UUIDs consistent across regression mode. # Need to keep the UUIDs consistent across regression mode.
my $uuid; my $uuid;
if ($regression) { if ($regression) {
$uuid = "${pnode2}${i}-1111-2222-3333-44444444"; $uuid = "0000${n}-1111-2222-3333-44444444";
} }
else { else {
$uuid = (@uuids ? shift(@uuids) : NewUUID()); $uuid = (@uuids ? shift(@uuids) : NewUUID());
...@@ -1725,7 +1785,9 @@ sub CreateVnodes($$) ...@@ -1725,7 +1785,9 @@ sub CreateVnodes($$)
} }
if ($verbose) { if ($verbose) {
print STDERR "Jail IP for $vnodeid is $jailip\n"; print STDERR "Jail IP for $vnodeid is $jailip\n"
if ($jailip);
if ($impotent) { if ($impotent) {
print STDERR print STDERR
"Would allocate $vnodeid on $pnode ($vtype, $osid)\n"; "Would allocate $vnodeid on $pnode ($vtype, $osid)\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