Commit 8d8baac3 authored by Mac Newbold's avatar Mac Newbold

Added pids, checks for experiment existence, and freeing all nodes in an...

Added pids, checks for experiment existence, and freeing all nodes in an experiment without naming them.
parent 4d305e1d
......@@ -3,8 +3,9 @@ use Mysql;
my $dbh = Mysql->connect("localhost","tbdb","script","none");
if ($#ARGV < 1) {die("Usage: nalloc <eid> <node> <node> <...>\n");}
if ($#ARGV < 1) {die("Usage: nalloc <pid> <eid> <node> <node> <...>\n");}
my $pid = shift;
my $eid = shift;
my @node_names=@ARGV;
my @machines = @node_names;
......@@ -13,27 +14,33 @@ my $list= join(" or ",@machines);
my $cmd = "";
my $sth = "";
$cmd = "select * from experiments where eid='$eid' and pid='$pid'";
$sth = $dbh->query($cmd);
if ($sth->numrows < 1) {
die("There is no experiment '$eid' in project '$pid'.\n");
}
foreach my $n (@node_names) {
$sth = $dbh->query("select * from reserved where node_id='$n'");
if ($sth->numrows > 0) {
$sth = $dbh->
query("select * from reserved where node_id='$n' and eid='$eid'");
if ($sth->numrows > 0) {
print "You have already reserved node '$n'.\n";
} else {
print "Someone else has already reserved node '$n'.\n";
}
next;
$sth = $dbh->query("select * from reserved where node_id='$n'");
if ($sth->numrows > 0) {
$cmd="select * from reserved where node_id='$n' and eid='$eid' and pid='$pid'";
$sth = $dbh->query($cmd);
if ($sth->numrows > 0) {
print "You have already reserved node '$n'.\n";
} else {
$sth = $dbh->query("select * from nodes where node_id='$n'");
if ($sth->numrows < 1) {
print "Node '$n' does not exist.\n";
next;
}
print "Someone else has already reserved node '$n'.\n";
}
next;
} else {
$sth = $dbh->query("select * from nodes where node_id='$n'");
if ($sth->numrows < 1) {
print "Node '$n' does not exist.\n";
next;
}
print "Reserving node '$n'...";
$cmd = "insert into reserved (node_id,eid) values ('$n','$eid')";
$sth = $dbh->query($cmd) && print "Succeeded.\n"
|| print "Failed Command:\n$cmd\nError string is:".$dbh->errstr."\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";
}
......@@ -3,8 +3,13 @@ use Mysql;
my $dbh = Mysql->connect("localhost","tbdb","script","none");
if ($#ARGV < 1) {die("Usage: nfree <eid> <node> <node> <...>\n");}
if ($#ARGV < 1) {
die("Usage: nfree <pid> <eid> [<node> <node> <...>]\n".
"Releases all nodes in the specified experiment. If nodes are listed,\n".
"nfree releases only the listed nodes.\n");
}
my $pid = shift;
my $eid = shift;
my @node_names=@ARGV;
my @machines = @node_names;
......@@ -14,11 +19,27 @@ my $list= join(" or ",@machines);
my $cmd = "";
my $sth = "";
$cmd = "select * from experiments where eid='$eid' and pid='$pid'";
$sth = $dbh->query($cmd);
if ($sth->numrows < 1) {
die("There is no experiment '$eid' in project '$pid'.\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";
$sth = $dbh->
query("select node_id from reserved where pid='$pid' and eid='$eid'");
while (@row = $sth->fetchrow_array()) {
push(@node_names, $row[0]);
}
}
foreach my $n (@node_names) {
$sth = $dbh->query("select * from reserved where node_id='$n' ".
"and eid='$eid'");
if ($sth->numrows == 0) {
print "Node '$n' is not reserved by you.\n";
print "Node '$n' is not reserved by your experiment.\n";
next;
}
print "Releasing node '$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