Commit bb996961 authored by Leigh Stoller's avatar Leigh Stoller

By popular demand, give user a choice of where to get the next set of

(initial) parameters for a new run. Three choices right now; from the
template itself, from the instance, or from the previous run. On the
web interface this is presented as three buttons. On ops, it is the
the -y option, which takes one of template,instance,lastrun as its
argument (you can of course combine the -y option with an XML file to
override specific params).

At present, there is no default. Lets give it a chance to sink in
before I pick something that will annoy 50% of the people 75% of the
time.
parent 471d1d26
......@@ -2362,14 +2362,17 @@ sub LastRun($)
my $exptidx = $self->exptidx();
my $query_result =
DBQueryWarn("select * from experiment_runs ".
DBQueryWarn("select idx from experiment_runs ".
"where exptidx='$exptidx' order by idx desc limit 1");
return undef
if (!$query_result);
return $query_result->fetchrow_hashref();
my $runidx = ($query_result->fetchrow_array())[0];
return Template::Instance::Run->LookupByID($exptidx, $runidx);
}
sub FirstRun($)
{
my ($self) = @_;
......@@ -2524,7 +2527,7 @@ sub NewRunID($$)
else {
my $last_run = $self->LastRun();
$lastname = $last_run->{"runid"};
$lastname = $last_run->runid();
}
#
......
......@@ -43,7 +43,7 @@ sub usage()
"<guid/vers> - GUID and version to swapin\n");
exit(-1);
}
my $optlist = "qwx:p:E:a:r:e:dscft:im";
my $optlist = "qwx:p:E:a:r:e:dscft:imy:";
my %options = ();
my $quiet = 0;
my $waitmode = 0;
......@@ -52,6 +52,7 @@ my $foreground = 0;
my $ignoreerrors = 0;
my $clean = 0;
my $doswapmod = 0;
my $paramwhich;
my $paramfile;
my %parameters = ();
my %deadnodes = ();
......@@ -256,11 +257,41 @@ elsif ($action eq "start" && !defined($runid)) {
# them in the DB for this experiment. Note that these override existing
# values, so we start with those first.
#
# XXX Do we keep these values in the DB forever? Or just keep the XML file
# around and archived?
# Start with the requested set of params, and then let the XML file override
# them as needed.
#
$instance->BindingList(\%parameters) == 0
or tbdie("Could not get binding list for $instance");
if (defined($paramwhich)) {
if ($paramwhich eq "template") {
$template->FormalParameterList(\%parameters) == 0
or tbdie("Could not get formal parameters for $template");
}
elsif ($paramwhich eq "instance") {
$instance->BindingList(\%parameters) == 0
or tbdie("Could not get binding list for $instance");
}
elsif ($paramwhich eq "lastrun") {
my $lastrun;
if (defined($instance->runidx())) {
$lastrun =
Template::Instance::Run->LookupByID($instance->exptidx(),
$instance->runidx());
}
else {
$lastrun = $instance->LastRun();
}
defined($lastrun)
or tbdie("Could not get run for $instance");
$lastrun->BindingList(\%parameters) == 0
or tbdie("Could not get binding list for $run");
}
}
else {
# Default to the instance bindings.
$instance->BindingList(\%parameters) == 0
or tbdie("Could not get binding list for $instance");
}
if (defined($paramfile)) {
my $donebad = 0;
......@@ -700,6 +731,18 @@ sub ParseArgs()
}
$description = $options{"E"};
}
if (defined($options{"y"})) {
$paramwhich = $options{"y"};
if ($paramwhich ne "template" && $paramwhich ne "instance" &&
$paramwhich ne "lastrun") {
tbdie("Improper -y argument: $paramwhich");
}
# Need the equiv of a taint check.
if ($paramwhich =~ /^([\w]+)$/) {
$paramwhich = $1;
}
}
if (defined($options{"x"})) {
my $inputfile = $options{"x"};
......
......@@ -188,11 +188,11 @@ else {
# Note that we just want the last run since that will include the
# accumulated data.
#
my $rowref = $instance->LastRun();
my $lastrun = $instance->LastRun();
fatal(-1, "Could not get last run for instance $instance!")
if (! defined($rowref));
if (! defined($lastrun));
my $idx = $rowref->{'idx'};
my $idx = $lastrun->idx();
$dbname = "${guid},${version}," . $instance->idx() . ",$idx";
my $query_result =
......
......@@ -100,13 +100,9 @@ if (! TBExptAccessCheck($uid, $exp_pid, $exp_eid, $TB_EXPT_MODIFY)) {
}
# Template Instance Experiments get special treatment in this page.
$instance = NULL;
if ($EXPOSETEMPLATES) {
$instance = TemplateInstance::LookupByExptidx($exptidx);
if (! is_null($instance) && $inout != "out") {
PAGEARGERROR("Invalid action for template instance");
}
$instance = TemplateInstance::LookupByExptidx($exptidx);
if ($instance && $inout != "out") {
PAGEARGERROR("Invalid action for template instance");
}
# Convert inout to informative text.
......
......@@ -1394,6 +1394,25 @@ class TemplateInstance
}
return 0;
}
#
# Return in the index of the most recent run.
#
function LastRunIdx() {
$exptidx = $this->exptidx();
$query_result =
DBQueryFatal("select idx from experiment_runs ".
"where exptidx='$exptidx' ".
"order by idx desc limit 1");
if (!mysql_num_rows($query_result)) {
return 0;
}
$row = mysql_fetch_array($query_result);
return $row[0];
}
#
# Show graph stuff, either for entire instance or for a run. Very hacky.
......
......@@ -224,11 +224,51 @@ function SPITFORM($instance, $formfields, $parameters, $errors)
echo "</table><br>\n";
}
#
# Get the default params for the template, instance and the previous run.
# These go out for the user to select via a button, which will provide an
# initial setting for the parameters.
#
$template->FormalParameters($formal_parameters);
$instance->Bindings($instance_parameters);
$instance->RunBindings($instance->LastRunIdx(), $lastrun_parameters);
#
# Spit out some inline script. Its not as if there will be hundreds
# of parameters, right?
#
echo "<script type='text/javascript' language='javascript' ".
" src='template_sup.js'>\n";
echo "</script>\n";
echo "<script language=JavaScript>\n";
echo "var formal_names = new Array();\n";
echo "var template_values = new Array();\n";
echo "var instance_values = new Array();\n";
echo "var lastrun_values = new Array();\n";
$i = 0;
while (list ($name, $value) = each ($formal_parameters)) {
echo "formal_names[$i] = '$name';\n";
echo "template_values[$i] = '$value';\n";
$i++;
}
$i = 0;
while (list ($name, $value) = each ($instance_parameters)) {
echo "instance_values[$i] = '$value';\n";
$i++;
}
$i = 0;
while (list ($name, $value) = each ($lastrun_parameters)) {
echo "lastrun_values[$i] = '$value';\n";
$i++;
}
echo "</script>\n";
echo "<form action=template_exprun.php".
"?action=start&guid=$guid&version=$version&eid=$eid ".
" method=post>\n";
echo "<table align=center border=1>\n";
#
# RunID:
#
......@@ -301,6 +341,22 @@ function SPITFORM($instance, $formfields, $parameters, $errors)
<td class='pad4'>Formal Parameters:</td>
<td>
<table cellpadding=0 cellspacing=0 border=0>\n";
echo "<tr><td>Choose Values:</td><td>";
echo "<table cellpadding=0 cellspacing=0 border=0>\n";
echo "<tr><td>\n";
echo " <button name=formals type=button value=Formals ";
echo " onclick=\"SetRunParams(formal_names, template_values);\">";
echo "Template</button>\n";
echo "</td><td>\n";
echo " <button name=instance type=button value=Instance ";
echo " onclick=\"SetRunParams(formal_names, instance_values);\">";
echo "Instance</button>\n";
echo "</td><td>\n";
echo " <button name=lastrun type=button value='Previous Run' ";
echo " onclick=\"SetRunParams(formal_names, lastrun_values);\">";
echo "Previous Run</button>\n";
echo "</tr></table>\n";
while (list ($name, $value) = each ($parameters)) {
if (!isset($value))
......@@ -310,8 +366,9 @@ function SPITFORM($instance, $formfields, $parameters, $errors)
<td class='pad4'>$name</td>
<td class='pad4' class=left>
<input type=text
id='parameter_$name'
name=\"parameters[$name]\"
value=\"" . $value . "\"
value=\"\"
size=60
maxlength=1024>
</td>
......
......@@ -35,3 +35,20 @@ function SetActiveTemplate(img_name, div_name, area_name)
template_div.style['width'] = width + "px";
template_div.style['visibility'] = "visible";
}
/*
* For initializing template run params
*/
function SetRunParams(names, values)
{
for (i = 0; i < names.length; i++) {
var name = names[i];
var value = values[i];
var field = document.getElementById("parameter_" + name);
if (field) {
field.value = value;
}
}
}
......@@ -4785,6 +4785,10 @@ class template:
argstr += " -m "
pass
pass
elif opt == "params":
argstr += " -y "
argstr += escapeshellarg(val)
pass
elif opt == "xmlfilepath":
# Backend script will verify this local path.
xmlfilename = escapeshellarg(val)
......
......@@ -2097,7 +2097,7 @@ class template_startrun:
def apply(self):
try:
opts, req_args = getopt.getopt(self.argv, "we:E:r:p:cx:m",
opts, req_args = getopt.getopt(self.argv, "we:E:r:p:cx:my:",
[ "help" ]);
pass
except getopt.error, e:
......@@ -2129,6 +2129,9 @@ class template_startrun:
elif opt == "-r":
params["runid"] = val
pass
elif opt == "-y":
params["params"] = val
pass
elif opt == "-p":
pid = val
pass
......@@ -2178,6 +2181,7 @@ class template_startrun:
print "where:";
print " -E - A pithy sentence describing your run";
print " -x - XML file of parameter bindings";
print " -y - Default params, one of template,instance,lastrun";
print " -r - A token (id) for the run";
print " -e - Instance ID (aka eid)";
print " guid - Template GUID";
......
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