Commit 0c1b1a23 authored by Leigh Stoller's avatar Leigh Stoller

Okay, now we can view graphs from the historical data (template record).

A couple of things to note:

* When requesting a graph, we have to have a checkout of the archive
  (the DB dump file) so that we can create a temporary DB with the data.
  This is done on demand, and the DB is left in place since its a
  fairly time consuming operation to do the checkout and the dbload.
  I do not delete the DBs though; we will need to age them out as needed.

* Even so, when returning to a page we end up getting the graphs
  again, and that still takes more time then I like to wait. Perhaps
  add a refresh button so that the user has to force a redraw. Might
  need to add a time/date stamp to the graph.
parent 5f413b47
......@@ -2125,6 +2125,29 @@ sub RunList($$)
return 0;
}
#
# Return the last run for an instance, after the instance is gone.
#
sub LastRun($)
{
my ($self) = @_;
# Must be a real reference.
return -1
if (! ref($self));
my $exptidx = $self->exptidx();
my $query_result =
DBQueryWarn("select * from experiment_runs ".
"where exptidx='$exptidx' order by idx desc limit 1");
return undef
if (!$query_result);
return $query_result->fetchrow_hashref();
}
#
# Binding records for each Run.
#
......
......@@ -27,19 +27,20 @@ use Data::Dumper;
sub usage()
{
print(STDERR
"Usage: template_export [-q] [-s] -i <exptidx> <guid/vers>\n".
"Usage: template_analyze [-q] [-s] [-r runidx] -i <exptidx> <guid/vers>\n".
"switches and arguments:\n".
"-q - be less chatty\n".
"-i <exptidx> - Experiment index to work on\n".
"<guid/vers> - GUID and version\n");
exit(-1);
}
my $optlist = "qi:d";
my $optlist = "qi:dr:";
my %options = ();
my $quiet = 0;
my $debug = 0;
my $eid;
my $exptidx;
my $runidx;
my $guid;
my $version;
......@@ -178,8 +179,8 @@ LogStart(0);
#
foreach my $name (keys(%runlist)) {
my $rowref = $runlist{$name};
my $runidx = $rowref->{"idx"};
my $dir = "$checkout/run${runidx}";
my $idx = $rowref->{"idx"};
my $dir = "$checkout/run${idx}";
my $subdir = "archive/dbdata";
my $tag = $rowref->{"archive_tag"};
my $dbdump = "$dir/dbdump.gz";
......@@ -187,6 +188,10 @@ foreach my $name (keys(%runlist)) {
# This could happen if template is still instantiated (last run).
next
if (!defined($tag) || $tag eq "");
# A specific run?
next
if (defined($runidx) && $runidx != $idx);
system("mkdir -p $dir") == 0
or fatal(-1, "Could not mkdir $dir");
......@@ -200,7 +205,7 @@ foreach my $name (keys(%runlist)) {
#
# Now we need to create a DB on ops to hold the DB dump.
#
my $dbname = "${guid},${version}," . $instance->idx() . ",$runidx";
my $dbname = "${guid},${version}," . $instance->idx() . ",$idx";
if (system("$dbcontrol deltempdb $dbname")) {
fatal(-1, "$dbcontrol deltempdb failed!");
......@@ -265,6 +270,22 @@ sub ParseArgs()
tbdie("You must supply the -i option!");
}
if (defined($options{"r"})) {
$runidx = $options{"r"};
if (! TBcheck_dbslot($exptidx, "default", "int",
TBDB_CHECKDBSLOT_WARN|TBDB_CHECKDBSLOT_ERROR)) {
tbdie("Improper run index!");
}
# real check.
if ($runidx =~ /^([\w]*)$/) {
$runidx = $1;
}
else {
tbdie("Bad data in argument: $runidx");
}
}
if (defined($options{"q"})) {
$quiet = 1;
}
......
......@@ -62,6 +62,7 @@ my $TBBASE = "@TBBASE@";
my $CONTROL = "@USERNODE@";
my $checkquota = "$TB/sbin/checkquota";
my $dbcontrol = "$TB/sbin/opsdb_control";
my $tempanalyze = "$TB/bin/template_analyze";
# Locals
my $dbuid;
......@@ -164,9 +165,11 @@ if (! keys(%runlist)) {
exit(1);
}
my $dbname;
my $optargs = "";
if ($instance->Instantiated()) {
my $experiment = Experiment->Lookup($instance->pid(), $instance->eid());
my $eid = $instance->eid();
fatal(-1, "Could not get experiment object from $instance!")
if (!defined($experiment));
......@@ -174,54 +177,88 @@ if ($instance->Instantiated()) {
fatal(-1, "No experiment database in use!")
if (! $experiment->dpdb() || !$experiment->dpdbname());
my $dbname = $experiment->dpdbname();
my $optargs = "";
$dbname = $experiment->dpdbname();
$eid = $instance->eid();
}
else {
#
# We need to use a database from the archive. We do not want to check
# this out multiple times, so look to see if a temp DB already exists.
#
# Note that we just want the last run since that will include the
# accumulated data.
#
my $rowref = $instance->LastRun();
fatal(-1, "Could not get last run for instance $instance!")
if (! defined($rowref));
my $idx = $rowref->{'idx'};
$dbname = "${guid},${version}," . $instance->idx() . ",$idx";
my $query_result =
DBQueryFatal("select * from datapository_databases ".
"where dbname='$dbname'");
if (! $query_result->numrows) {
system("$tempanalyze -i $exptidx -r $idx $guid/$version") == 0 or
fatal(-1, "Could not check out database for run $idx!");
}
#
# For a specific run, figure out the start and end times of the run
# and pass those along as options to the graphing code.
# Since there is no current instance experiment, use the eid from the
# template for the lookups below. This is not quite correct though, since
# an instance might actually have a different topology or number of nodes,
# or be different in some other manner. Needs more thought.
#
if (defined($runidx)) {
my $rowref = $runlist{$runidx};
my $start = $rowref->{"start_time"};
my $stop = $rowref->{"stop_time"};
$eid = $template->eid();
}
if (defined($stop)) {
$optargs = "-r " . str2time($start) . ":" . str2time($stop);
}
else {
$optargs = "-r " . str2time($start) . ":0";
}
#
# For a specific run, figure out the start and end times of the run
# and pass those along as options to the graphing code.
#
if (defined($runidx)) {
my $rowref = $runlist{$runidx};
my $start = $rowref->{"start_time"};
my $stop = $rowref->{"stop_time"};
if (defined($stop)) {
$optargs = "-r " . str2time($start) . ":" . str2time($stop);
}
else {
$optargs = "-r " . str2time($start) . ":0";
}
}
if (defined($srcvnode)) {
my $query_result =
DBQueryFatal("select ip from virt_lans ".
"where vname='$srclan' and vnode='$srcvnode' and ".
" pid='$pid' and eid='$eid'");
if ($query_result->numrows) {
my ($ip) = $query_result->fetchrow_array();
$optargs .= " -s $ip";
}
# Specific source link/node
if (defined($srcvnode)) {
my $query_result =
DBQueryFatal("select ip from virt_lans ".
"where vname='$srclan' and vnode='$srcvnode' and ".
" pid='$pid' and eid='$eid'");
if ($query_result->numrows) {
my ($ip) = $query_result->fetchrow_array();
$optargs .= " -s $ip";
}
}
if (defined($dstvnode)) {
my $query_result =
DBQueryFatal("select ip from virt_lans ".
"where vname='$dstlan' and vnode='$dstvnode' and ".
" pid='$pid' and eid='$eid'");
if ($query_result->numrows) {
my ($ip) = $query_result->fetchrow_array();
$optargs .= " -t $ip";
}
# Specific destination link/node
if (defined($dstvnode)) {
my $query_result =
DBQueryFatal("select ip from virt_lans ".
"where vname='$dstlan' and vnode='$dstvnode' and ".
" pid='$pid' and eid='$eid'");
if ($query_result->numrows) {
my ($ip) = $query_result->fetchrow_array();
$optargs .= " -t $ip";
}
# SENDMAIL($TBOPS, "foo", "$dbname $graphtype $optargs");
system("$dbcontrol graphdb $dbname $graphtype $optargs") == 0 or
fatal(-1, "Failed to generate requested graph!");
}
# SENDMAIL($TBOPS, "foo", "$dbname $graphtype $optargs");
system("$dbcontrol graphdb $dbname $graphtype $optargs") == 0 or
fatal(-1, "Failed to generate requested graph!");
exit(0);
#
......@@ -289,6 +326,13 @@ sub ParseArgs()
TBDB_CHECKDBSLOT_WARN|TBDB_CHECKDBSLOT_ERROR)) {
tbdie("Improper run index!");
}
# real check.
if ($runidx =~ /^([\w]*)$/) {
$runidx = $1;
}
else {
tbdie("Bad data in argument: $runidx");
}
}
# These are really linkname/vnode ... so we can find exact IP addr.
......
......@@ -30,6 +30,7 @@ $instance = TemplateInstance::LookupByExptidx($exptidx);
if (!$instance) {
USERERROR("The instance $exptidx is not a valid instance!", 1);
}
$template = $instance->template();
# Optional runidx for graphing just a specific run.
$runarg = "";
......@@ -67,6 +68,7 @@ if (isset($dstvnode) && $dstvnode != "") {
#
$eid = $instance->eid();
$pid = $instance->pid();
$gid = $template->gid();
$guid = $instance->guid();
$vers = $instance->vers();
$which = "pps";
......@@ -81,9 +83,6 @@ if (isset($graphtype) && $graphtype != "") {
$which = $graphtype;
}
if (!TBExptGroup($pid, $eid, $gid)) {
TBERROR("No such experiment $pid/$eid!", 1);
}
TBGroupUnixInfo($pid, $gid, $unix_gid, $unix_name);
if ($fp = popen("$TBSUEXEC_PATH $uid $unix_name webtemplate_linkgraph " .
......
......@@ -946,6 +946,17 @@ class TemplateInstance
return (is_null($this->instance) ? -1 : $this->template);
}
# Is instance actually running (current experiment).
function Instantiated() {
$exptidx = $this->exptidx();
$query_result =
DBQueryFatal("select pid,eid from experiments ".
"where idx='$exptidx'");
return mysql_num_rows($query_result);
}
#
# Show an instance.
#
......@@ -1293,7 +1304,14 @@ class TemplateInstance
# Make the link unique to force reload on the client side.
$now = time();
$pid = $this->pid();
$eid = $this->eid();
if ($this->Instantiated()) {
$eid = $this->eid();
}
else {
$template = $this->template();
$eid = $template->eid();
}
#
# Lets check args!
......
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