Commit be0c285a authored by Leigh Stoller's avatar Leigh Stoller

Record dynamic virtual nodes in the node_history table.

This includes the control net ip and physical host, via create and
destroy records.
Also minor fixes to the shownodehistory.php3 web page.
parent 06a6404c
......@@ -166,7 +166,7 @@ use vars qw(@ISA @EXPORT);
TBDB_SECLEVEL_ORANGE TBDB_SECLEVEL_RED TBDB_SECLEVEL_ZAPDISK
TB_NODEHISTORY_OP_FREE TB_NODEHISTORY_OP_ALLOC TB_NODEHISTORY_OP_MOVE
PROTOUSER
PROTOUSER TB_NODEHISTORY_OP_CREATE TB_NODEHISTORY_OP_DESTROY
);
use English;
......@@ -364,6 +364,8 @@ sub TB_DEFAULT_NODELOGTYPE() { TB_NODELOGTYPE_MISC(); }
sub TB_NODEHISTORY_OP_FREE { "free"; }
sub TB_NODEHISTORY_OP_ALLOC { "alloc"; }
sub TB_NODEHISTORY_OP_MOVE { "move"; }
sub TB_NODEHISTORY_OP_CREATE { "create"; }
sub TB_NODEHISTORY_OP_DESTROY { "destroy"; }
# Reload Types.
sub TB_RELOADTYPE_NETDISK() { "netdisk"; }
......
......@@ -1944,6 +1944,7 @@ sub CreateVnodes($$$)
$options->{'regression'};
my $sharedokay = defined($options->{'sharedokay'}) &&
$options->{'sharedokay'};
my $user = $options->{'user'} if (exists($options->{'user'}));
my $pid = $options->{'pid'};
my $eid = $options->{'eid'};
my $count = $options->{'count'};
......@@ -2330,6 +2331,21 @@ sub CreateVnodes($$$)
push(@interfaces, $interface);
}
#
# Finally, add the history records.
#
if (!$impotent) {
foreach my $vnodeid (@created) {
my $node = Node->Lookup($vnodeid);
if (!defined($node)) {
print STDERR
"*** CreateVnodes: Could not lookup $vnodeid\n";
next;
}
$node->SetNodeHistory(TB_NODEHISTORY_OP_CREATE(),
$user, $experiment);
}
}
@$rptr = @created;
return 0;
......@@ -2387,6 +2403,8 @@ sub SetNodeHistory($$$$)
my $exptidx = $experiment->idx();
my $nodeid = $self->node_id();
my $cnet_ip;
my $phys_nodeid;
my $now = time();
my $uid;
my $uid_idx;
......@@ -2436,10 +2454,46 @@ sub SetNodeHistory($$$$)
}
}
}
elsif ($op eq TB_NODEHISTORY_OP_CREATE()) {
#
# No need to waste space on cnet_IP for phys nodes, or on
# the destroy op. Ditto the phys_nodeid.
#
require Interface;
# Lets make sure no one calls this for a real node.
if (! $self->isvirtnode()) {
print STDERR
"*** SetNodeHistory: '$op' issued for phys node $self\n";
return -1;
}
my $interface = Interface->LookupControl($self);
if (!defined($interface)) {
print STDERR
"*** SetNodeHistory: No control interface for $self\n";
}
$cnet_ip = $interface->IP();
if (!defined($cnet_ip) || $cnet_ip eq "") {
print STDERR "*** SetNodeHistory: No control IP for $interface\n";
}
$phys_nodeid = $self->phys_nodeid();
}
elsif ($op eq TB_NODEHISTORY_OP_DESTROY()) {
# Lets make sure no one calls this for a real node.
if (! $self->isvirtnode()) {
print STDERR
"*** SetNodeHistory: '$op' issued for phys node $self\n";
return -1;
}
}
return DBQueryWarn("insert into node_history set ".
" history_id=0, node_id='$nodeid', op='$op', ".
" uid='$uid', uid_idx='$uid_idx', ".
" stamp=$now, exptidx=$exptidx");
" history_id=0, node_id='$nodeid', op='$op', ".
" uid='$uid', uid_idx='$uid_idx', ".
(defined($cnet_ip) ? "cnet_IP='$cnet_ip'," : "").
(defined($phys_nodeid) ? "phys_nodeid='$phys_nodeid'," : "").
" stamp=$now, exptidx=$exptidx");
}
#
......
#!/usr/bin/perl -w
#
# EMULAB-COPYRIGHT
# Copyright (c) 2000-2011 University of Utah and the Flux Group.
# Copyright (c) 2000-2012 University of Utah and the Flux Group.
# All rights reserved.
#
use strict;
......@@ -434,6 +434,8 @@ foreach my $node (@freed_nodes) {
# We will call into the Node library to delete it.
#
if ($isvirt && $isdynamic) {
$node->SetNodeHistory(TB_NODEHISTORY_OP_DESTROY, $this_user,
$experiment);
push(@dynanodes, $node);
next;
}
......
......@@ -51,7 +51,7 @@ sub usage {
exit(1);
}
my $optlist = "ARS:aln:rswvd:";
my $optlist = "ARS:aln:rswvd:i:";
my $warnme = 0;
my $verbose = 0;
my $showall = 0;
......@@ -61,6 +61,7 @@ my $summary = 0;
my $raw = 0;
my $numrecs = 0;
my $datetime;
my $ip;
#
# Sort stuff. sortby value should correspond to record field format:
......@@ -139,6 +140,10 @@ if (defined($options{"d"})) {
$datetime = timelocal(strptime($options{"d"}));
$summary = 0;
}
if (defined($options{"i"})) {
$ip = $options{"i"};
$summary = 0;
}
if (defined($options{"w"})) {
$warnme = 1;
}
......@@ -162,12 +167,16 @@ my $querymod = "";
if (@nodes == 1) {
$querymod = " AND node_id='$nodes[0]'";
}
elsif (defined($ip)) {
$querymod = " AND cnet_ip='$ip'";
}
# XXX maybe it would be better to sort them here in perl, outside the DB?
my $orderby = " ORDER BY stamp ASC";
my $query_result =
DBQueryFatal("SELECT node_id,stamp,op,uid,pid,eid,experiment_stats.exptidx ".
DBQueryFatal("SELECT node_id,stamp,op,uid,pid,eid, ".
" experiment_stats.exptidx,cnet_ip,phys_nodeid ".
"FROM node_history,experiment_stats ".
"WHERE node_history.exptidx=experiment_stats.exptidx ".
"$querymod $orderby");
......@@ -227,6 +236,22 @@ while (my %row = $query_result->fetchhash()) {
}
$nodeinfo{$node} = [ $pideid, $exptidx, $stamp, $uid ];
}
elsif ($row{op} eq "create") {
if ($opideid ne "") {
print STDERR "$node: dup alloc: already allocated to $opideid\n"
if ($warnme);
# XXX possibly missing state in the DB.
}
$nodeinfo{$node} = [ $pideid, $exptidx, $stamp, $uid ];
}
elsif ($row{op} eq "destroy") {
if ($opideid ne $pideid) {
print STDERR "$node: mismatched create,destroy records: ".
"$opideid,$pideid\n"
if ($warnme);
}
$nodeinfo{$node} = [ "", undef, $stamp, $uid ];
}
# save off the record
push(@records, [ $node, $opideid, $oidx, $ouid, $ostamp, $elapsed ]);
......
......@@ -1308,7 +1308,8 @@ class Node
# Show history.
#
function ShowNodeHistory($node = null,
$showall = 0, $count = 20, $reverse = 1, $date = null) {
$showall = 0, $count = 20, $reverse = 1,
$date = null, $IP = null) {
global $TBSUEXEC_PATH;
global $PROTOGENI;
$atime = 0;
......@@ -1338,6 +1339,9 @@ function ShowNodeHistory($node = null,
if ($date) {
$opt = " -d " . escapeshellarg($date);
}
if ($IP) {
$opt = " -i " . escapeshellarg($IP);
}
if ($fp = popen("$TBSUEXEC_PATH nobody nobody ".
" webnode_history $opt $node_id", "r")) {
if (!$showall) {
......
......@@ -46,14 +46,23 @@ if (!isset($datetime)) {
$datetime = "";
}
if (isset($IP)) {
if (! preg_match('/^[0-9\.]+$/', $IP)) {
USERERROR("Does not look like a valid IP address.", 1);
}
$node = Node::LookupByIP($IP);
if (! $node) {
USERERROR("Cannot map $IP to a node", 1);
#
# No record might mean the node does not exist, or that it
# is a virtual node. We are going to pass IP through to the
# backend in either case.
#
if ($node && $node->isremotenode()) {
unset($node);
}
}
$node_id = (isset($node) ? $node->node_id() : "");
$node_id = (isset($node) ? $node->node_id() : "");
$node_opt = (isset($node) ? "&node_id=$node_id" : "");
$opts="node_id=$node_id&count=$count&reverse=$reverse";
$opts="count=$count&reverse=$reverse$node_opt";
echo "<b>Show records:</b> ";
if ($showall) {
echo "<a href='shownodehistory.php3?$opts'>allocated only</a>,
......@@ -63,7 +72,7 @@ if ($showall) {
<a href='shownodehistory.php3?$opts&showall=1'>all</a>";
}
$opts="node_id=$node_id&count=$count&showall=$showall";
$opts="count=$count&showall=$showall$node_opt";
echo "<br><b>Order by:</b> ";
if ($reverse == 0) {
echo "<a href='shownodehistory.php3?$opts&reverse=1'>lastest first</a>,
......@@ -73,7 +82,7 @@ if ($reverse == 0) {
<a href='shownodehistory.php3?$opts&reverse=0'>earliest first</a>";
}
$opts="node_id=$node_id&showall=$showall&reverse=$reverse";
$opts="showall=$showall&reverse=$reverse$node_opt";
echo "<br><b>Show number:</b> ";
if ($count != 20) {
echo "<a href='shownodehistory.php3?$opts&count=20'>first 20</a>, ";
......@@ -97,6 +106,7 @@ if ($count != 0) {
if ($datetime == "") {
$datetime = "mm/dd/yy HH:MM";
}
# Only display search form for a specific node.
if ($node_id != "") {
echo "<br>";
echo "<form action=shownodehistory.php3?$opts method=post>
......@@ -111,14 +121,15 @@ if ($node_id != "") {
if ($node_id != "" && $datetime != "" && $datetime != "mm/dd/yy HH:MM") {
if (strtotime($datetime)) {
ShowNodeHistory($node, 1, 1, 0, $datetime);
ShowNodeHistory($node, 1, 1, 0, $datetime, $IP);
}
else {
USERERROR("Invalid date specified", 1);
}
}
else {
ShowNodeHistory((isset($node) ? $node : null), $showall, $count, $reverse);
ShowNodeHistory((isset($node) ? $node : null),
$showall, $count, $reverse, null, $IP);
}
#
......
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