Commit 4e5e88a1 authored by Leigh Stoller's avatar Leigh Stoller

Some minor cleanup of queries.

parent 66fa5890
......@@ -17,6 +17,7 @@ class Experiment
var $group;
var $project;
var $isinstance = false;
var $resources;
#
# Constructor by lookup on unique index.
......@@ -48,6 +49,7 @@ class Experiment
# Load lazily;
$this->group = null;
$this->project = null;
$this->resources = null;
}
# Hmm, how does one cause an error in a php constructor?
......@@ -121,11 +123,13 @@ class Experiment
$this->experiment = NULL;
$this->group = null;
$this->project = null;
$this->resources = null;
return -1;
}
$this->experiment = mysql_fetch_array($query_result);
$this->group = null;
$this->project = null;
$this->resources = null;
return 0;
}
......@@ -186,6 +190,9 @@ class Experiment
function GetStats() {
return ExperimentStats::Lookup($this->idx());
}
function GetResources() {
return ExperimentResources::Lookup($this->idx());
}
# accessors
function field($name) {
......@@ -229,6 +236,8 @@ class Experiment
function linktest_pid() { return $this->field('linktest_pid'); }
function logfile() { return $this->field('logfile'); }
function keyhash() { return $this->field('keyhash'); }
function paniced() { return $this->field('paniced'); }
function panic_date() { return $this->field('panic_date'); }
#
# Access Check. Project level check since this might not be a current
......@@ -1079,6 +1088,54 @@ class ExperimentStats
}
}
class ExperimentResources
{
var $resources;
#
# Constructor by lookup on unique index for current resources
#
function ExperimentResources($exptidx) {
$safe_exptidx = addslashes($exptidx);
$query_result =
DBQueryWarn("select r.* from experiment_stats as s ".
"left join experiment_resources as r on ".
" s.rsrcidx=r.idx ".
"where s.exptidx='$safe_exptidx'");
if (!$query_result || !mysql_num_rows($query_result)) {
$this->resources = null;
return;
}
$this->resources = mysql_fetch_array($query_result);
}
# Hmm, how does one cause an error in a php constructor?
function IsValid() {
return !is_null($this->resources);
}
# Lookup by exptidx.
function Lookup($exptidx) {
$foo = new ExperimentResources($exptidx);
if ($foo->IsValid())
return $foo;
return null;
}
# accessors
function field($name) {
return (is_null($this->resources) ? -1 : $this->resources[$name]);
}
function idx() { return $this->field('idx'); }
function exptidx() { return $this->field('exptidx'); }
function lastidx() { return $this->field('lastidx'); }
function wirelesslans() { return $this->field('wirelesslans'); }
}
#
# Class function to show a listing of experiments by user/pid/gid
#
......
......@@ -210,15 +210,8 @@ function Show($which, $arg1, $arg2)
$html .= "Full Screen</button>\n";
}
elseif ($which == "nsfile") {
$nsdata = "";
$nsdata = $experiment->NSFile();
$query_result =
DBQueryFatal("select nsfile from nsfiles ".
"where pid='$pid' and eid='$eid'");
if (mysql_num_rows($query_result)) {
$row = mysql_fetch_array($query_result);
$nsdata = htmlentities($row["nsfile"]);
}
$html = "<pre><div align=left class=\"showexp_codeblock\">".
"$nsdata</div></pre>\n";
......@@ -259,24 +252,17 @@ include_once("template_defs.php");
#
# Need some DB info.
#
$query_result =
DBQueryFatal("select e.idx,e.state,e.batchmode,e.linktest_pid,".
" e.paniced,e.panic_date,s.rsrcidx,r.wirelesslans, ".
" e.lockdown ".
" from experiments as e ".
"left join experiment_stats as s on s.exptidx=e.idx ".
"left join experiment_resources as r on s.rsrcidx=r.idx ".
"where e.eid='$eid' and e.pid='$pid'");
$row = mysql_fetch_array($query_result);
$expindex = $row["idx"];
$expstate = $row["state"];
$rsrcidx = $row["rsrcidx"];
$isbatch = $row["batchmode"];
$wireless = $row["wirelesslans"];
$linktest_running = $row["linktest_pid"];
$paniced = $row["paniced"];
$panic_date = $row["panic_date"];
$lockdown = $row["lockdown"];
$expindex = $experiment->idx();
$expstate = $experiment->state();
$isbatch = $experiment->batchmode();
$linktest_running = $experiment->linktest_pid();
$paniced = $experiment->paniced();
$panic_date = $experiment->panic_date();
$lockdown = $experiment->lockdown();
$experiment_stats = $experiment->GetStats();
$rsrcidx = $experiment_stats->rsrcidx();
$experiment_resources = $experiment->GetResources();
$wireless = $experiment_resources->wirelesslans();
#
# Standard Testbed Header.
......
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