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

Checkpoint more stuff ...

parent 47a82473
......@@ -679,6 +679,7 @@ CREATE TABLE experiment_templates (
uid varchar(8) NOT NULL default '',
description mediumtext,
eid varchar(32) NOT NULL default '',
archive_idx int(10) unsigned default NULL,
created datetime default NULL,
modified datetime default NULL,
locked datetime default NULL,
......
......@@ -3273,3 +3273,5 @@ last_net_act,last_cpu_act,last_ext_act);
alter table experiments add column instance_idx int(10) \
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 (
uid varchar(8) NOT NULL default '',
-- Eric says these are really metadata. Probably true.
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 '',
-- 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
created datetime default NULL,
modified datetime default NULL,
......
......@@ -151,6 +151,23 @@ sub NewTemplateRecord($)
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).
#
......@@ -561,6 +578,7 @@ sub DeleteTemplateInputFiles($$)
DBQueryWarn("lock tables experiment_template_inputs as i write, ".
" experiment_template_inputs as j write, ".
" experiment_template_inputs write, ".
" experiment_template_input_data write")
or return -1;
......
......@@ -58,7 +58,7 @@ sub CheckCopyArgs();
sub CopyInArchive();
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 $frontend = 0;
my $waitmode = 0;
......@@ -69,6 +69,7 @@ my $zeeopt = ""; # To pass along.
my $savestate= 0;
my $template_mode = 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.
# These globals are set when we parse the -c argument, but used later
my $copybranch = 0; # A branch instead of a duplicate
......@@ -407,7 +408,13 @@ chdir("$workdir") or
# Create a new archive, which might actually be a branch of an existing one
# 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.
fatal("Could not create experiment archive!")
if (libArchive::TBForkExperimentArchive($pid, $eid,
......@@ -1107,6 +1114,17 @@ sub ParseArgs()
}
if (defined($options{"x"})) {
$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"})) {
$instance_idx = $options{"y"};
......
......@@ -151,6 +151,23 @@ sub NewTemplateRecord($)
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).
#
......@@ -561,6 +578,7 @@ sub DeleteTemplateInputFiles($$)
DBQueryWarn("lock tables experiment_template_inputs as i write, ".
" experiment_template_inputs as j write, ".
" experiment_template_inputs write, ".
" experiment_template_input_data write")
or return -1;
......
......@@ -2,7 +2,7 @@
#
# 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.
#
......@@ -361,10 +361,14 @@ sub TBScriptLock($;$$)
if (!defined($global));
$lockname = "/var/tmp/testbed_${token}_lockfile";
my $oldmask = umask(0000);
if (! open(LOCK, ">>$lockname")) {
print STDERR "Could not open $lockname!\n";
umask($oldmask);
return TBSCRIPTLOCK_FAILED();
}
umask($oldmask);
if (! $global) {
#
......
......@@ -69,6 +69,7 @@ my $user_email;
my $dbuid;
my $guid;
my $version = 1;
my $archive_idx = 0;
# For the END block below.
my $cleaning = 0;
my $exptcreated = 0;
......@@ -90,6 +91,7 @@ use lib "@prefix@/lib";
use libdb;
use libtestbed;
use libtblog;
use libArchive;
use libTemplates;
# Be careful not to exit on transient error
......@@ -256,8 +258,9 @@ if (libTemplates::NewTemplateRecord(\%args) < 0) {
DBQueryFatal("unlock tables");
# Now invoke batchexp to preload the experiment. Note special -x option.
system("$batchexp -x -q -i -f ".
"-E 'Experiment Template Preload $guid/$version' ".
system("$batchexp ".
"-x " . ($modify ? "T${parent_guid}-${parent_vers}" : "-") . " " .
"-q -i -f -E 'Experiment Template Preload $guid/$version' ".
"-p $pid -e $eid $inputfile");
fatal($? >> 8, "Oops")
if ($?);
......@@ -269,6 +272,42 @@ $exptcreated = 1;
exit(-1)
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.
#
system("$makegraph $guid");
......
......@@ -85,6 +85,7 @@ my $justexit = 1;
# Programs we need
my $checkquota = "$TB/sbin/checkquota";
my $archcontrol = "$TB/bin/archive_control";
# Protos
sub ParseArgs();
......@@ -178,8 +179,8 @@ if (! libTemplates::IsTemplateInstanceExperiment($exptidx)) {
#
# And get the instance info,
#
if (libTemplates::TemplateInstanceInfoByExptidx($exptidx,
\$currunidx, \$instidx) < 0) {
if (libTemplates::TemplateInstanceInfoByExptidx($exptidx, \$currunidx,
undef, \$instidx) < 0) {
fatal(-1, "Could not get current experiment run index!");
}
......@@ -251,8 +252,14 @@ if (defined($currunidx)) {
fatal(-1, "Could not finalize experiment run index $currunidx!");
}
}
#
# Commit the archive.
#
system("$archcontrol -t $runid commit $pid $eid");
goto done
if ($action eq "stop") ;
if ($action eq "stop");
#
# Generate a new run.
......
......@@ -278,7 +278,7 @@ my $copyeid = "${pid},T${guid}-${version}";
# Note special -x option.
#
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,
"-E", "'Experiment Template Instantiation $guid/$version' ",
"-c" , $copyeid);
......
......@@ -278,7 +278,7 @@ my $copyeid = "${pid},T${guid}-${version}";
# Note special -x option.
#
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,
"-E", "'Experiment Template Instantiation $guid/$version' ",
"-c" , $copyeid);
......
......@@ -478,7 +478,7 @@ function SHOWTEMPLATEHISTORY($guid, $version)
if (mysql_num_rows($query_result)) {
echo "<center>
<h3>Template History</h3>
<h3>Template History (Swapins)</h3>
</center>
<table align=center border=1 cellpadding=5 cellspacing=2>\n";
......@@ -488,6 +488,7 @@ function SHOWTEMPLATEHISTORY($guid, $version)
<th>UID</th>
<th>Start Time</th>
<th>Stop Time</th>
<th align=center>Archive</th>
</tr>\n";
$idlemark = "<b>*</b>";
......@@ -515,6 +516,9 @@ function SHOWTEMPLATEHISTORY($guid, $version)
<td>$uid</td>
<td>$start</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";
}
echo "</table>\n";
......@@ -571,6 +575,7 @@ function SHOWTEMPLATEINSTANCE($guid, $version, $exptidx, $withruns)
echo "<tr>
<th align=center>Expand</th>
<th align=center>Archive</th>
<th>RunID</th>
<th>ID</th>
<th>Start Time</th>
......@@ -583,6 +588,7 @@ function SHOWTEMPLATEINSTANCE($guid, $version, $exptidx, $withruns)
$runid = $rrow['runid'];
$start = $rrow['start_time'];
$stop = $rrow['stop_time'];
$exptidx = $rrow['exptidx'];
$description = $rrow['description'];
if (! isset($stop)) {
......@@ -596,6 +602,11 @@ function SHOWTEMPLATEINSTANCE($guid, $version, $exptidx, $withruns)
"&exptidx=$exptidx&runidx=$runidx",
"<img border=0 alt='i' src='greenball.gif'>");
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>$runidx</td>
<td>$start</td>
......@@ -848,9 +859,8 @@ function TBTemplateCurrentExperimentRun($guid, $version, $exptidx, &$runidx)
function TBTemplateNextExperimentRun($guid, $version, $exptidx, &$runidx)
{
$query_result =
DBQueryFatal("select MAX(runidx) from experiment_template_instances ".
"where parent_guid='$guid' and parent_vers='$version' ".
" and exptidx='$exptidx'");
DBQueryFatal("select MAX(idx) from experiment_runs ".
"where exptidx='$exptidx'");
if (mysql_num_rows($query_result) == 0) {
return 0;
......
......@@ -45,6 +45,7 @@ if (! TBValidExperimentTemplate($guid, $version)) {
USERERROR("The experiment template $guid/$version is not a valid ".
"experiment template!", 1);
}
TBTemplatePidEid($guid, $version, $pid, $eid);
#
# Verify Permission.
......@@ -76,6 +77,9 @@ WRITESUBMENUBUTTON("Add Metadata",
"template_metadata.php?action=add&".
"guid=$guid&version=$version");
WRITESUBMENUBUTTON("Template Archive",
"archive_view.php3?pid=$pid&eid=$eid");
WRITESUBMENUBUTTON("Template History",
"template_history.php?guid=$guid&version=$version");
......@@ -84,7 +88,6 @@ SUBMENUEND_2A();
#
# Ick.
#
TBTemplatePidEid($guid, $version, $pid, $eid);
$rsrcidx = TBrsrcIndex($pid, $eid);
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