All new accounts created on Gitlab now require administrator approval. If you invite any collaborators, please let Flux staff know so they can approve the accounts.

Commit 17649161 authored by mac's avatar mac

Added locking.

parent 995ef733
......@@ -5,7 +5,7 @@ use English;
#
# Configure variables
#
my $TB = "@prefix@/bin";
my $TB = "@prefix@/libexec";
my $DBNAME = "@TBDBNAME@";
my $dbh = Mysql->connect("localhost",$DBNAME,"script","none");
......@@ -17,9 +17,8 @@ my $error = 0;
my $pid = shift;
my $eid = shift;
my @node_names=@ARGV;
my @machines = @node_names;
foreach my $m (@machines) { $m = "node_id='".$m."'"; }
my $list= join(" or ",@machines);
my @vals = ();
my @nodes= ();
my $cmd = "";
my $sth = "";
......@@ -34,6 +33,11 @@ if ( ($sth->numrows < 1) && ($UID != 0) && ($EUID != 0)) {
die("You are not a member of experiment '$eid' in project '$pid'.\n");
}
print "Locking tables.\n";
$cmd = "lock tables nodes read, reserved write";
$sth = $dbh->query($cmd)
|| die("Locking error:\n$cmd\nError string is:".$dbh->errstr."\n");
foreach my $n (@node_names) {
$sth = $dbh->query("select * from reserved where node_id='$n'");
if ($sth->numrows > 0) {
......@@ -53,15 +57,32 @@ foreach my $n (@node_names) {
print "Node '$n' does not exist.\n";
$error++;
next;
} else {
# No one has reserved it, and it exists, so add it to my list
push(@vals,"('$n','$pid','$eid')");
push(@nodes,"$n");
}
}
print "Reserving node '$n'...";
$cmd = "insert into reserved (node_id,pid,eid) values ('$n','$pid','$eid')";
$sth = $dbh->query($cmd) && print "Succeeded.\n"
|| (print "Failed Command:\n$cmd\nError string is:".$dbh->errstr."\n"
&& $error++);
system("$consetup $n") == 0 or
print STDERR "WARNING: $consetup $n failed!";
}
if (!$error && @vals) {
print "Reserving nodes...";
$cmd = "insert into reserved (node_id,pid,eid) values ".join(",",@vals);
if ($sth = $dbh->query($cmd)) {
print "Succeeded.\n";
foreach $n ( @nodes ) {
system("$consetup $n") == 0 or
print STDERR "WARNING: $consetup $n failed!\n";
}
} else {
print "Failed Command:\n$cmd\nError string is:".$dbh->errstr."\n";
$error++;
}
}
print "Unlocking tables.\n";
$cmd = "unlock tables";
$sth = $dbh->query($cmd)
|| die("Locking error:\n$cmd\nError string is:".$dbh->errstr."\n");
exit($error);
......@@ -4,7 +4,7 @@ use Mysql;
#
# Configure variables
#
my $TB = "@prefix@/bin";
my $TB = "@prefix@";
my $DBNAME = "@TBDBNAME@";
my $dbh = Mysql->connect("localhost",$DBNAME,"script","none");
......@@ -16,8 +16,8 @@ if ($#ARGV < 1) {
}
my $error = 0;
my $consetup="$TB/console_setup";
my $osload="$TB/os_load";
my $consetup="$TB/libexec/console_setup";
my $osload="$TB/bin/os_load";
my $reloadpid="testbed";
my $reloadeid="reloading";
my $pid = shift;
......@@ -36,6 +36,12 @@ if ($sth->numrows < 1) {
die("There is no experiment '$eid' in project '$pid'.\n");
}
print "Locking tables.\n";
$cmd = "lock tables nodes read, node_types read, reloads read, ".
"interfaces write, reserved write";
$sth = $dbh->query($cmd)
|| die("Locking error:\n$cmd\nError string is:".$dbh->errstr."\n");
# If list is empty, put in all the nodes
if ($#node_names == -1) {
print "Releasing all nodes from experiment '$eid' in project '$pid'...\n";
......@@ -100,8 +106,9 @@ foreach my $n (@node_names) {
if (! ($n =~ /^tbsh/)) { #If its not a shark
# Find the control net interface for this node type
$sth = $dbh->query("select control_net from node_types as t left join ".
"nodes as n on n.type=t.type where node_id='$n'");
$sth =
$dbh->query("select control_net from node_types left join ".
"nodes on nodes.type=node_types.type where node_id='$n'");
my @row= $sth->fetchrow_array();
my $control= $row[0];
# Clean out all IPs except the control net
......@@ -113,9 +120,14 @@ foreach my $n (@node_names) {
}
system("$consetup $n") == 0 or
print STDERR "WARNING: $consetup $n failed!";
print STDERR "WARNING: $consetup $n failed!\n";
}
print "Unlocking tables.\n";
$cmd = "unlock tables";
$sth = $dbh->query($cmd)
|| die("Locking error:\n$cmd\nError string is:".$dbh->errstr."\n");
foreach $reload ( keys(%reloads)) {
@list = @{$reloads{$reload}};
# Call os_load to start the reload
......
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