From 37d2649ecfb7c125b489f52be18a3c16700d9b53 Mon Sep 17 00:00:00 2001 From: "Leigh B. Stoller" Date: Tue, 16 May 2006 22:24:58 +0000 Subject: [PATCH] Convert all of the new template code to PHP "classes." This was not as much "fun" as the Perl conversion, but nothing about PHP is as much fun as it is in perl. --- tbsetup/template_create.in | 5 +- www/experimentrun_show.php | 26 +- www/instance_show.php | 24 +- www/showexp.php3 | 32 +- www/showlogfile_sup.php3 | 5 +- www/showstuff.php3 | 12 +- www/showuser.php3 | 2 +- www/spitnsdata.php3 | 16 +- www/swapexp.php3 | 28 +- www/template_create.php | 24 +- www/template_defs.php | 1803 ++++++++++++++++++------------------ www/template_exprun.php | 90 +- www/template_graph.php | 44 +- www/template_history.php | 15 +- www/template_metadata.php | 123 +-- www/template_modify.php | 47 +- www/template_show.php | 138 +-- www/template_swapin.php | 55 +- 18 files changed, 1190 insertions(+), 1299 deletions(-) diff --git a/tbsetup/template_create.in b/tbsetup/template_create.in index 998bfc725..7ebe147b7 100644 --- a/tbsetup/template_create.in +++ b/tbsetup/template_create.in @@ -34,7 +34,7 @@ sub usage() "-E - A pithy sentence describing the template\n". "-g - The group in which to create the experiment\n". " - The project in which to create the experiment\n". - " - The template name (unique, alphanumeric, no blanks)\n". + " - The template name (alphanumeric, no blanks)\n". " - Input file for experiment.\n"); exit(-1); } @@ -305,6 +305,9 @@ system("$makegraph $guid"); fatal(-1, "Error generating template graph.") if ($?); +# Web interface depends on this line. Bad; need another way to send +# back the newly generated guid/version. +print "Template $guid/$vers has been created\n"; exit(0); # diff --git a/www/experimentrun_show.php b/www/experimentrun_show.php index c7955b6d1..db86c237d 100644 --- a/www/experimentrun_show.php +++ b/www/experimentrun_show.php @@ -5,7 +5,7 @@ # All rights reserved. # include("defs.php3"); -include("template_defs.php"); +include_once("template_defs.php"); # # Only known and logged in users ... @@ -52,28 +52,26 @@ if (!TBvalid_integer($runidx)) { PAGEHEADER("Experiment Run"); # -# Check to make sure this is a valid template. +# Check to make sure this is a valid template and user has permission. # -if (! TBValidExperimentTemplate($guid, $version)) { +$template = Template::Lookup($guid, $version); +if (!$template) { USERERROR("The experiment template $guid/$version is not a valid ". "experiment template!", 1); } -if (! TBIsTemplateInstanceExperiment($exptidx)) { +if (! $template->AccessCheck($uid, $TB_EXPT_READINFO)) { + USERERROR("You do not have permission to view experiment template ". + "$guid/$version!", 1); +} +$instance = TemplateInstance::LookupByExptidx($exptidx); +if (!$instance) { USERERROR("The instance $exptidx is not a valid instance in ". "template $guid/$version!", 1); } -if (! TBValidExperimentRun($exptidx, $runidx)) { +if (! $instance->ValidRun($runidx)) { USERERROR("The run $runidx is not a valid experiment run!", 1); } -# -# Verify Permission. -# -if (! TBExptTemplateAccessCheck($uid, $guid, $TB_EXPT_READINFO)) { - USERERROR("You do not have permission to view experiment template ". - "$guid/$version!", 1); -} - echo "Experiment Run " . MakeLink("instance", "guid=$guid&version=$version&exptidx=$exptidx", @@ -82,7 +80,7 @@ echo "Experiment Run " . echo "

\n"; -SHOWEXPERIMENTRUN($exptidx, $runidx); +$instance->ShowRun($runidx); # # Standard Testbed Footer diff --git a/www/instance_show.php b/www/instance_show.php index 91da197ea..42bd9dd45 100644 --- a/www/instance_show.php +++ b/www/instance_show.php @@ -5,7 +5,7 @@ # All rights reserved. # include("defs.php3"); -include("template_defs.php"); +include_once("template_defs.php"); # # Only known and logged in users ... @@ -45,24 +45,22 @@ if (!TBvalid_integer($exptidx)) { PAGEHEADER("Template Instance"); # -# Check to make sure this is a valid template. +# Check to make sure this is a valid template and user has permission. # -if (! TBValidExperimentTemplate($guid, $version)) { +$template = Template::Lookup($guid, $version); +if (!$template) { USERERROR("The experiment template $guid/$version is not a valid ". "experiment template!", 1); } -if (! TBIsTemplateInstanceExperiment($exptidx)) { - USERERROR("The instance $exptidx is not a valid instance in ". - "template $guid/$version!", 1); -} - -# -# Verify Permission. -# -if (! TBExptTemplateAccessCheck($uid, $guid, $TB_EXPT_READINFO)) { +if (! $template->AccessCheck($uid, $TB_EXPT_READINFO)) { USERERROR("You do not have permission to view experiment template ". "$guid/$version!", 1); } +$instance = TemplateInstance::LookupByExptidx($exptidx); +if (!$instance) { + USERERROR("The instance $exptidx is not a valid instance in ". + "template $guid/$version!", 1); +} echo "Template Instance " . MakeLink("template", @@ -70,7 +68,7 @@ echo "Template Instance " . "\n"; echo "

\n"; -SHOWTEMPLATEINSTANCE($guid, $version, $exptidx, 1); +$instance->Show(1); # # Standard Testbed Footer diff --git a/www/showexp.php3 b/www/showexp.php3 index a64165a19..ff4546cac 100644 --- a/www/showexp.php3 +++ b/www/showexp.php3 @@ -72,7 +72,7 @@ sajax_handle_client_request(); # Faster to do this after the sajax stuff include("showstuff.php3"); -include("template_defs.php"); +include_once("template_defs.php"); # # Need some DB info. @@ -97,11 +97,15 @@ $panic_date = $row["panic_date"]; $lockdown = $row["lockdown"]; # Template Instance Experiments get special treatment in this page. -$isinstance = ($EXPOSETEMPLATES && - TBIsTemplateInstanceExperiment($expindex) ? 1 : 0); -if ($isinstance) { - $tag = "Template Instance"; - TBPidEid2Template($pid, $eid, $guid, $version, $instance_idx); +$instance = NULL; +if ($EXPOSETEMPLATES) { + $instance = TemplateInstance::LookupByExptidx($expindex); + + if (! is_null($instance)) { + $tag = "Template Instance"; + $guid = $instance->guid(); + $vers = $instance->vers(); + } } # @@ -189,7 +193,7 @@ if ($expstate) { } elseif ($expstate == $TB_EXPTSTATE_ACTIVE || ($expstate == $TB_EXPTSTATE_PANICED && $isadmin)) { - WRITESUBMENUBUTTON(($isinstance ? + WRITESUBMENUBUTTON(($instance ? "Terminate Instance" : "Swap Experiment Out"), "swapexp.php3?inout=out&pid=$exp_pid&eid=$exp_eid"); @@ -201,23 +205,23 @@ if ($expstate) { } } - if (!$isinstance && $expstate != $TB_EXPTSTATE_PANICED) { + if (!$instance && $expstate != $TB_EXPTSTATE_PANICED) { WRITESUBMENUBUTTON("Terminate Experiment", "endexp.php3?pid=$exp_pid&eid=$exp_eid"); } # Batch experiments can be modifed only when paused. - if (!$isinstance && ($expstate == $TB_EXPTSTATE_SWAPPED || + if (!$instance && ($expstate == $TB_EXPTSTATE_SWAPPED || (!$isbatch && $expstate == $TB_EXPTSTATE_ACTIVE))) { WRITESUBMENUBUTTON("Modify Experiment", "modifyexp.php3?pid=$exp_pid&eid=$exp_eid"); } } - if ($isinstance && $expstate == $TB_EXPTSTATE_ACTIVE) { + if ($instance && $expstate == $TB_EXPTSTATE_ACTIVE) { WRITESUBMENUBUTTON("Start New Experiment Run", "template_exprun.php?action=start&guid=$guid". - "&version=$version&eid=$exp_eid"); + "&version=$vers&eid=$exp_eid"); } if ($expstate == $TB_EXPTSTATE_ACTIVE) { @@ -293,7 +297,7 @@ WRITESUBMENUDIVIDER(); WRITESUBMENUBUTTON("Show History", "showstats.php3?showby=expt&which=$expindex"); -if (!$isinstance && STUDLY()) { +if (!$instance && STUDLY()) { WRITESUBMENUBUTTON("Duplicate Experiment", "beginexp_html.php3?copyid=${exp_pid},${exp_eid}"); } @@ -408,11 +412,11 @@ if (TBExptFirewall($exp_pid, $exp_eid) && } SUBPAGEEND(); -if ($isinstance && +if ($instance && ($expstate == $TB_EXPTSTATE_ACTIVE || $expstate == $TB_EXPTSTATE_PANICED || $expstate == $TB_EXPTSTATE_ACTIVATING)) { - SHOWTEMPLATEINSTANCEBINDINGS($guid, $version, $instance_idx); + $instance->ShowBindings(); } # diff --git a/www/showlogfile_sup.php3 b/www/showlogfile_sup.php3 index ce7d3ca96..1d2669229 100644 --- a/www/showlogfile_sup.php3 +++ b/www/showlogfile_sup.php3 @@ -129,7 +129,10 @@ function STARTLOG($pid, $eid) \n"; echo "
\n"; - echo " Loading..."; + echo "
\n"; + echo " + Working ..."; + echo "
\n"; echo "
\n"; echo "