Commit 5eacf3fd authored by Leigh B. Stoller's avatar Leigh B. Stoller

Checkpoint more stuff ...

parent 47a82473
...@@ -679,6 +679,7 @@ CREATE TABLE experiment_templates ( ...@@ -679,6 +679,7 @@ CREATE TABLE experiment_templates (
uid varchar(8) NOT NULL default '', uid varchar(8) NOT NULL default '',
description mediumtext, description mediumtext,
eid varchar(32) NOT NULL default '', eid varchar(32) NOT NULL default '',
archive_idx int(10) unsigned default NULL,
created datetime default NULL, created datetime default NULL,
modified datetime default NULL, modified datetime default NULL,
locked datetime default NULL, locked datetime default NULL,
......
...@@ -3273,3 +3273,5 @@ last_net_act,last_cpu_act,last_ext_act); ...@@ -3273,3 +3273,5 @@ last_net_act,last_cpu_act,last_ext_act);
alter table experiments add column instance_idx int(10) \ alter table experiments add column instance_idx int(10) \
unsigned NOT NULL default '0' AFTER locpiper_port; unsigned NOT NULL default '0' AFTER locpiper_port;
4.46: Changes to templates.sql. Skip this revision for now.
...@@ -32,8 +32,10 @@ CREATE TABLE experiment_templates ( ...@@ -32,8 +32,10 @@ CREATE TABLE experiment_templates (
uid varchar(8) NOT NULL default '', uid varchar(8) NOT NULL default '',
-- Eric says these are really metadata. Probably true. -- Eric says these are really metadata. Probably true.
description mediumtext, description mediumtext,
-- EID of the underlying parsed experiment. I think this is temporary. -- EID of the underlying parsed experiment.
eid varchar(32) NOT NULL default '', eid varchar(32) NOT NULL default '',
-- The Archive for the template. This is shared with derived templates.
archive_idx int(10) unsigned default NULL,
-- These are all mirrors of what is in the existing experiments table -- These are all mirrors of what is in the existing experiments table
created datetime default NULL, created datetime default NULL,
modified datetime default NULL, modified datetime default NULL,
......
...@@ -151,6 +151,23 @@ sub NewTemplateRecord($) ...@@ -151,6 +151,23 @@ sub NewTemplateRecord($)
return 0; return 0;
} }
#
# Update a template record
#
sub UpdateTemplateRecord($$$)
{
my ($guid, $vers, $args) = @_;
my $query = "update experiment_templates set ".
join(",", map("$_='" . $args->{$_} . "'", keys(%{$args})));
$query .= " where guid='$guid' and vers='$vers'";
return -1
if (! DBQueryWarn($query));
return 0;
}
# #
# Delete a template (all tables). # Delete a template (all tables).
# #
...@@ -561,6 +578,7 @@ sub DeleteTemplateInputFiles($$) ...@@ -561,6 +578,7 @@ sub DeleteTemplateInputFiles($$)
DBQueryWarn("lock tables experiment_template_inputs as i write, ". DBQueryWarn("lock tables experiment_template_inputs as i write, ".
" experiment_template_inputs as j write, ". " experiment_template_inputs as j write, ".
" experiment_template_inputs write, ".
" experiment_template_input_data write") " experiment_template_input_data write")
or return -1; or return -1;
......
...@@ -58,7 +58,7 @@ sub CheckCopyArgs(); ...@@ -58,7 +58,7 @@ sub CheckCopyArgs();
sub CopyInArchive(); sub CopyInArchive();
sub fatal($); sub fatal($);
my $optlist = "iE:g:e:p:S:L:a:l:sfwqt:nzc:bxy:"; my $optlist = "iE:g:e:p:S:L:a:l:sfwqt:nzc:bx:y:";
my $batchmode= 1; my $batchmode= 1;
my $frontend = 0; my $frontend = 0;
my $waitmode = 0; my $waitmode = 0;
...@@ -69,6 +69,7 @@ my $zeeopt = ""; # To pass along. ...@@ -69,6 +69,7 @@ my $zeeopt = ""; # To pass along.
my $savestate= 0; my $savestate= 0;
my $template_mode = 0; # New stuff; experiment templates. my $template_mode = 0; # New stuff; experiment templates.
my $instance_idx = 0; # New stuff; experiment templates. my $instance_idx = 0; # New stuff; experiment templates.
my $archive_eid; # New stuff; experiment templates.
# All of these are for experiment dup and branch. Really mucks things up. # All of these are for experiment dup and branch. Really mucks things up.
# These globals are set when we parse the -c argument, but used later # These globals are set when we parse the -c argument, but used later
my $copybranch = 0; # A branch instead of a duplicate my $copybranch = 0; # A branch instead of a duplicate
...@@ -407,7 +408,13 @@ chdir("$workdir") or ...@@ -407,7 +408,13 @@ chdir("$workdir") or
# Create a new archive, which might actually be a branch of an existing one # Create a new archive, which might actually be a branch of an existing one
# when doing an experiment branch (fork). # when doing an experiment branch (fork).
# #
if ($copybranch) { if ($template_mode && defined($archive_eid)) {
fatal("Could not create experiment archive!")
if (libArchive::TBForkExperimentArchive($pid, $eid,
$pid, $archive_eid, undef)
< 0);
}
elsif ($copybranch) {
# Currently, support branching from existing experiment only. # Currently, support branching from existing experiment only.
fatal("Could not create experiment archive!") fatal("Could not create experiment archive!")
if (libArchive::TBForkExperimentArchive($pid, $eid, if (libArchive::TBForkExperimentArchive($pid, $eid,
...@@ -1107,6 +1114,17 @@ sub ParseArgs() ...@@ -1107,6 +1114,17 @@ sub ParseArgs()
} }
if (defined($options{"x"})) { if (defined($options{"x"})) {
$template_mode = 1; $template_mode = 1;
if ($options{"x"} ne "-") {
$archive_eid = $options{"x"};
if ($archive_eid =~ /^([-\w]+)$/) {
$archive_eid = $1;
}
else {
tbdie("Bad data in argument: $archive_eid.");
}
}
if (defined($options{"y"})) { if (defined($options{"y"})) {
$instance_idx = $options{"y"}; $instance_idx = $options{"y"};
......
...@@ -151,6 +151,23 @@ sub NewTemplateRecord($) ...@@ -151,6 +151,23 @@ sub NewTemplateRecord($)
return 0; return 0;
} }
#
# Update a template record
#
sub UpdateTemplateRecord($$$)
{
my ($guid, $vers, $args) = @_;
my $query = "update experiment_templates set ".
join(",", map("$_='" . $args->{$_} . "'", keys(%{$args})));
$query .= " where guid='$guid' and vers='$vers'";
return -1
if (! DBQueryWarn($query));
return 0;
}
# #
# Delete a template (all tables). # Delete a template (all tables).
# #
...@@ -561,6 +578,7 @@ sub DeleteTemplateInputFiles($$) ...@@ -561,6 +578,7 @@ sub DeleteTemplateInputFiles($$)
DBQueryWarn("lock tables experiment_template_inputs as i write, ". DBQueryWarn("lock tables experiment_template_inputs as i write, ".
" experiment_template_inputs as j write, ". " experiment_template_inputs as j write, ".
" experiment_template_inputs write, ".
" experiment_template_input_data write") " experiment_template_input_data write")
or return -1; or return -1;
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
# #
# EMULAB-COPYRIGHT # EMULAB-COPYRIGHT
# Copyright (c) 2000-2005 University of Utah and the Flux Group. # Copyright (c) 2000-2006 University of Utah and the Flux Group.
# All rights reserved. # All rights reserved.
# #
...@@ -361,10 +361,14 @@ sub TBScriptLock($;$$) ...@@ -361,10 +361,14 @@ sub TBScriptLock($;$$)
if (!defined($global)); if (!defined($global));
$lockname = "/var/tmp/testbed_${token}_lockfile"; $lockname = "/var/tmp/testbed_${token}_lockfile";
my $oldmask = umask(0000);
if (! open(LOCK, ">>$lockname")) { if (! open(LOCK, ">>$lockname")) {
print STDERR "Could not open $lockname!\n"; print STDERR "Could not open $lockname!\n";
umask($oldmask);
return TBSCRIPTLOCK_FAILED(); return TBSCRIPTLOCK_FAILED();
} }
umask($oldmask);
if (! $global) { if (! $global) {
# #
......
...@@ -69,6 +69,7 @@ my $user_email; ...@@ -69,6 +69,7 @@ my $user_email;
my $dbuid; my $dbuid;
my $guid; my $guid;
my $version = 1; my $version = 1;
my $archive_idx = 0;
# For the END block below. # For the END block below.
my $cleaning = 0; my $cleaning = 0;
my $exptcreated = 0; my $exptcreated = 0;
...@@ -90,6 +91,7 @@ use lib "@prefix@/lib"; ...@@ -90,6 +91,7 @@ use lib "@prefix@/lib";
use libdb; use libdb;
use libtestbed; use libtestbed;
use libtblog; use libtblog;
use libArchive;
use libTemplates; use libTemplates;
# Be careful not to exit on transient error # Be careful not to exit on transient error
...@@ -256,8 +258,9 @@ if (libTemplates::NewTemplateRecord(\%args) < 0) { ...@@ -256,8 +258,9 @@ if (libTemplates::NewTemplateRecord(\%args) < 0) {
DBQueryFatal("unlock tables"); DBQueryFatal("unlock tables");
# Now invoke batchexp to preload the experiment. Note special -x option. # Now invoke batchexp to preload the experiment. Note special -x option.
system("$batchexp -x -q -i -f ". system("$batchexp ".
"-E 'Experiment Template Preload $guid/$version' ". "-x " . ($modify ? "T${parent_guid}-${parent_vers}" : "-") . " " .
"-q -i -f -E 'Experiment Template Preload $guid/$version' ".
"-p $pid -e $eid $inputfile"); "-p $pid -e $eid $inputfile");
fatal($? >> 8, "Oops") fatal($? >> 8, "Oops")
if ($?); if ($?);
...@@ -269,6 +272,42 @@ $exptcreated = 1; ...@@ -269,6 +272,42 @@ $exptcreated = 1;
exit(-1) exit(-1)
if (libTemplates::AddTemplateInputFile($guid, $version, $inputfile) < 0); if (libTemplates::AddTemplateInputFile($guid, $version, $inputfile) < 0);
# #
# Grab archive index for new templates.
#
if (!$modify) {
libArchive::TBExperimentArchiveInfo($pid, $eid, \$archive_idx, undef)
>= 0 or fatal(-1, "Could not get archive index for new template!");
# Do a commit point on the template archive since it does not actually
# change after it is created (instances are branches).
libArchive::TBCommitExperimentArchive($pid, $eid, "TemplateCreate")
>= 0 or fatal(-1, "Failed to commit experiment archive!");
}
else {
#
# Grab the archive index for the parent; the archive is shared.
#
libArchive::TBExperimentArchiveInfo($pid,
"T${parent_guid}-${parent_vers}",
\$archive_idx, undef)
>= 0 or fatal(-1, "Could not get archive index for parent!");
# Do a commit point on the template archive since it does not actually
# change after it is created (instances are branches).
libArchive::TBCommitExperimentArchive($pid,
"T${parent_guid}-${parent_vers}",
"TemplateCreate")
>= 0 or fatal(-1, "Failed to commit experiment archive!");
}
# And update the record.
%args = ();
$args{'archive_idx'} = $archive_idx;
libTemplates::UpdateTemplateRecord($guid, $version, \%args) == 0
or fatal(-1, "Could not update template record!");
#
# Generate the graph for the template. # Generate the graph for the template.
# #
system("$makegraph $guid"); system("$makegraph $guid");
......
...@@ -85,6 +85,7 @@ my $justexit = 1; ...@@ -85,6 +85,7 @@ my $justexit = 1;
# Programs we need # Programs we need
my $checkquota = "$TB/sbin/checkquota"; my $checkquota = "$TB/sbin/checkquota";
my $archcontrol = "$TB/bin/archive_control";
# Protos # Protos
sub ParseArgs(); sub ParseArgs();
...@@ -178,8 +179,8 @@ if (! libTemplates::IsTemplateInstanceExperiment($exptidx)) { ...@@ -178,8 +179,8 @@ if (! libTemplates::IsTemplateInstanceExperiment($exptidx)) {
# #
# And get the instance info, # And get the instance info,
# #
if (libTemplates::TemplateInstanceInfoByExptidx($exptidx, if (libTemplates::TemplateInstanceInfoByExptidx($exptidx, \$currunidx,
\$currunidx, \$instidx) < 0) { undef, \$instidx) < 0) {
fatal(-1, "Could not get current experiment run index!"); fatal(-1, "Could not get current experiment run index!");
} }
...@@ -251,8 +252,14 @@ if (defined($currunidx)) { ...@@ -251,8 +252,14 @@ if (defined($currunidx)) {
fatal(-1, "Could not finalize experiment run index $currunidx!"); fatal(-1, "Could not finalize experiment run index $currunidx!");
} }
} }
#
# Commit the archive.
#
system("$archcontrol -t $runid commit $pid $eid");
goto done goto done
if ($action eq "stop") ; if ($action eq "stop");
# #
# Generate a new run. # Generate a new run.
......
...@@ -278,7 +278,7 @@ my $copyeid = "${pid},T${guid}-${version}"; ...@@ -278,7 +278,7 @@ my $copyeid = "${pid},T${guid}-${version}";
# Note special -x option. # Note special -x option.
# #
my @arguments = my @arguments =
($batchexp, "-x", "-y", $instidx, "-q", "-i", "-f", ($batchexp, "-x", "T${guid}-${version}", "-y", $instidx, "-q", "-i", "-f",
"-p", $pid, "-e", $eid, "-g", $gid, "-p", $pid, "-e", $eid, "-g", $gid,
"-E", "'Experiment Template Instantiation $guid/$version' ", "-E", "'Experiment Template Instantiation $guid/$version' ",
"-c" , $copyeid); "-c" , $copyeid);
......
...@@ -278,7 +278,7 @@ my $copyeid = "${pid},T${guid}-${version}"; ...@@ -278,7 +278,7 @@ my $copyeid = "${pid},T${guid}-${version}";
# Note special -x option. # Note special -x option.
# #
my @arguments = my @arguments =
($batchexp, "-x", "-y", $instidx, "-q", "-i", "-f", ($batchexp, "-x", "T${guid}-${version}", "-y", $instidx, "-q", "-i", "-f",
"-p", $pid, "-e", $eid, "-g", $gid, "-p", $pid, "-e", $eid, "-g", $gid,
"-E", "'Experiment Template Instantiation $guid/$version' ", "-E", "'Experiment Template Instantiation $guid/$version' ",
"-c" , $copyeid); "-c" , $copyeid);
......
...@@ -478,7 +478,7 @@ function SHOWTEMPLATEHISTORY($guid, $version) ...@@ -478,7 +478,7 @@ function SHOWTEMPLATEHISTORY($guid, $version)
if (mysql_num_rows($query_result)) { if (mysql_num_rows($query_result)) {
echo "<center> echo "<center>
<h3>Template History</h3> <h3>Template History (Swapins)</h3>
</center> </center>
<table align=center border=1 cellpadding=5 cellspacing=2>\n"; <table align=center border=1 cellpadding=5 cellspacing=2>\n";
...@@ -488,6 +488,7 @@ function SHOWTEMPLATEHISTORY($guid, $version) ...@@ -488,6 +488,7 @@ function SHOWTEMPLATEHISTORY($guid, $version)
<th>UID</th> <th>UID</th>
<th>Start Time</th> <th>Start Time</th>
<th>Stop Time</th> <th>Stop Time</th>
<th align=center>Archive</th>
</tr>\n"; </tr>\n";
$idlemark = "<b>*</b>"; $idlemark = "<b>*</b>";
...@@ -515,6 +516,9 @@ function SHOWTEMPLATEHISTORY($guid, $version) ...@@ -515,6 +516,9 @@ function SHOWTEMPLATEHISTORY($guid, $version)
<td>$uid</td> <td>$uid</td>
<td>$start</td> <td>$start</td>
<td>$stop</td> <td>$stop</td>
<td align=center>
<a href=cvsweb/cvswebwrap.php3/$exptidx/?exptidx=$exptidx>
<img border=0 alt='i' src='greenball.gif'></a></td>
</tr>\n"; </tr>\n";
} }
echo "</table>\n"; echo "</table>\n";
...@@ -571,6 +575,7 @@ function SHOWTEMPLATEINSTANCE($guid, $version, $exptidx, $withruns) ...@@ -571,6 +575,7 @@ function SHOWTEMPLATEINSTANCE($guid, $version, $exptidx, $withruns)
echo "<tr> echo "<tr>
<th align=center>Expand</th> <th align=center>Expand</th>
<th align=center>Archive</th>
<th>RunID</th> <th>RunID</th>
<th>ID</th> <th>ID</th>
<th>Start Time</th> <th>Start Time</th>
...@@ -583,6 +588,7 @@ function SHOWTEMPLATEINSTANCE($guid, $version, $exptidx, $withruns) ...@@ -583,6 +588,7 @@ function SHOWTEMPLATEINSTANCE($guid, $version, $exptidx, $withruns)
$runid = $rrow['runid']; $runid = $rrow['runid'];
$start = $rrow['start_time']; $start = $rrow['start_time'];
$stop = $rrow['stop_time']; $stop = $rrow['stop_time'];
$exptidx = $rrow['exptidx'];
$description = $rrow['description']; $description = $rrow['description'];
if (! isset($stop)) { if (! isset($stop)) {
...@@ -596,6 +602,11 @@ function SHOWTEMPLATEINSTANCE($guid, $version, $exptidx, $withruns) ...@@ -596,6 +602,11 @@ function SHOWTEMPLATEINSTANCE($guid, $version, $exptidx, $withruns)
"&exptidx=$exptidx&runidx=$runidx", "&exptidx=$exptidx&runidx=$runidx",
"<img border=0 alt='i' src='greenball.gif'>"); "<img border=0 alt='i' src='greenball.gif'>");
echo " </td> echo " </td>
<td align=center>
<a href=cvsweb/cvswebwrap.php3".
"/$exptidx/history/$runid/?exptidx=$exptidx>
<img border=0 alt='i'
src='greenball.gif'></a></td>
<td>$runid</td> <td>$runid</td>
<td>$runidx</td> <td>$runidx</td>
<td>$start</td> <td>$start</td>
...@@ -848,9 +859,8 @@ function TBTemplateCurrentExperimentRun($guid, $version, $exptidx, &$runidx) ...@@ -848,9 +859,8 @@ function TBTemplateCurrentExperimentRun($guid, $version, $exptidx, &$runidx)
function TBTemplateNextExperimentRun($guid, $version, $exptidx, &$runidx) function TBTemplateNextExperimentRun($guid, $version, $exptidx, &$runidx)
{ {
$query_result = $query_result =
DBQueryFatal("select MAX(runidx) from experiment_template_instances ". DBQueryFatal("select MAX(idx) from experiment_runs ".
"where parent_guid='$guid' and parent_vers='$version' ". "where exptidx='$exptidx'");
" and exptidx='$exptidx'");
if (mysql_num_rows($query_result) == 0) { if (mysql_num_rows($query_result) == 0) {
return 0; return 0;
......
...@@ -45,6 +45,7 @@ if (! TBValidExperimentTemplate($guid, $version)) { ...@@ -45,6 +45,7 @@ if (! TBValidExperimentTemplate($guid, $version)) {
USERERROR("The experiment template $guid/$version is not a valid ". USERERROR("The experiment template $guid/$version is not a valid ".
"experiment template!", 1); "experiment template!", 1);
} }
TBTemplatePidEid($guid, $version, $pid, $eid);
# #
# Verify Permission. # Verify Permission.
...@@ -76,6 +77,9 @@ WRITESUBMENUBUTTON("Add Metadata", ...@@ -76,6 +77,9 @@ WRITESUBMENUBUTTON("Add Metadata",
"template_metadata.php?action=add&". "template_metadata.php?action=add&".
"guid=$guid&version=$version"); "guid=$guid&version=$version");
WRITESUBMENUBUTTON("Template Archive",
"archive_view.php3?pid=$pid&eid=$eid");
WRITESUBMENUBUTTON("Template History", WRITESUBMENUBUTTON("Template History",
"template_history.php?guid=$guid&version=$version"); "template_history.php?guid=$guid&version=$version");
...@@ -84,7 +88,6 @@ SUBMENUEND_2A(); ...@@ -84,7 +88,6 @@ SUBMENUEND_2A();
# #
# Ick. # Ick.
# #
TBTemplatePidEid($guid, $version, $pid, $eid);
$rsrcidx = TBrsrcIndex($pid, $eid); $rsrcidx = TBrsrcIndex($pid, $eid);
echo "<br> echo "<br>
......
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