Commit 808f43ec authored by Leigh Stoller's avatar Leigh Stoller

Change how the archive stuff is presented in the template instance and

run display pages.

* Add new code to archive_control and libarchive to create tags (in
  optional subdirs) of the tags directory. These tags are simply tags
  on the current trunk at the time.

* Change to template instantiate and start/top run code to create a
  "runs" directory. Within the runs directory are subdirs named for
  each runid, and within this directory are start and stop run tags.
  Eventually add some other tags when doing swapmods, but do not have
  that figured out yet.

* Change the viewcvs code to add an "embedded" view of an archive.
  This is just an alternate view that has no header/footer goo, but
  only the actual svn contents. The main reason for this change is
  that the header and footers take up a huge amount of space and
  contribute nothing. Smaller means its easier to add to the instance
  and run show pages.

* Add the above mentioned embedded archive view to the instance and
  run show pages. On the instance page you see the directory of all
  runids, and on the show run page you see the subdir for that run.
parent cc7098af
......@@ -491,16 +491,18 @@ sub Stringify($)
}
#
# Check permissions
# Check permissions. Allow for either uid or a user ref until all code
# updated.
#
sub AccessCheck($$$)
{
my ($self, $uid, $access_type) = @_;
my ($self, $user, $access_type) = @_;
# Must be a real reference.
return -1
if (! ref($self));
my $uid = (ref($user) ? $user->uid() : $user);
my $pid = $self->pid();
my $eid = $self->eid();
......
#!/usr/bin/perl -wT
#
# EMULAB-COPYRIGHT
# Copyright (c) 2005, 2006 University of Utah and the Flux Group.
# Copyright (c) 2005-2007 University of Utah and the Flux Group.
# All rights reserved.
#
use English;
......@@ -15,10 +15,11 @@ sub usage()
print STDERR
"Usage: archive_control [-f] [-t tag [-u]] [-m file] commit <pid> <eid>\n".
" archive_control [-f] [-a] addfile <pid> <eid> [files ...]\n".
" archive_control tag [-u] [-s subdir] <pid> <eid> <tag>\n".
" archive_control checktag <pid> <eid> <tag>\n";
exit(-1);
}
my $optlist = "dfat:m:u";
my $optlist = "dfat:m:us:";
my $debug = 0;
my $force = 0;
my $dbuid;
......@@ -51,15 +52,17 @@ use libdb;
use libtestbed;
use libaudit;
use libArchive;
use User;
use Experiment;
my $SHAREROOT = SHAREROOT();
#
# Verify user and get his DB uid.
# Map invoking user to object.
#
if (! UNIX2DBUID($UID, \$dbuid)) {
die("*** $0:\n".
" You do not exist in the Emulab Database!\n");
my $this_user = User->ThisUser();
if (! defined($this_user)) {
fatal("You ($UID) do not exist!");
}
#
......@@ -86,7 +89,7 @@ my $eid = shift(@ARGV);
#
# Untaint args.
#
if ($action =~ /^(commit|addfile|checktag|list|missing|addtoarchive)$/) {
if ($action =~ /^(commit|addfile|checktag|tag|list|missing|addtoarchive)$/) {
$action = $1;
}
else {
......@@ -105,15 +108,16 @@ else {
die("Bad data in eid: $eid.");
}
if (! ($expstate = ExpState($pid, $eid))) {
my $experiment = Experiment->Lookup($pid, $eid);
if (! $experiment) {
fatal("No such experiment $pid/$eid!");
}
$expstate = $experiment->state();
#
# Check permission. Only people with permission to destroy the experiment
# can do this.
# Check permission.
#
if (! TBExptAccessCheck($UID, $pid, $eid, TB_EXPT_UPDATE)) {
if (! $experiment->AccessCheck($this_user, TB_EXPT_UPDATE)) {
fatal("You do not have permission to control the archive for $pid/$eid!");
}
......@@ -225,6 +229,43 @@ if ($action eq "commit") {
fatal("Failed to commit experiment archive!");
}
}
elsif ($action eq "tag") {
usage()
if (! @ARGV);
my $tag = $ARGV[0];
if (! TBcheck_dbslot($tag, "archive_tags", "tag",
TBDB_CHECKDBSLOT_WARN|TBDB_CHECKDBSLOT_ERROR)) {
fatal("Illegal characters in tag");
}
# Force a taint check; the library will escape it for the shell.
$tag =~ /(.*)/;
$tag = $1;
my $usertag = 0;
if (defined($options{"u"})) {
$usertag = 1;
}
# Subdir to place the tag into.
my $subdir = undef;
if (defined($options{"s"})) {
$subdir = $options{"s"};
if ($subdir =~ /^([-\w\/]+)$/) {
$subdir = $1;
}
else {
fatal("Illegal characters in subdir");
}
}
print "Adding tag $tag to the experiment archive ...\n";
if (libArchive::TBTagExperimentArchive($pid, $eid, $tag,
$usertag, $subdir) < 0) {
fatal("Failed to tag experiment archive!");
}
}
elsif ($action eq "addfile") {
my $exact = 0;
......
#!/usr/bin/perl -wT
#
# EMULAB-COPYRIGHT
# Copyright (c) 2005, 2006 University of Utah and the Flux Group.
# Copyright (c) 2005, 2006, 2007 University of Utah and the Flux Group.
# All rights reserved.
#
# XXX Need to deal with locking at some point ...
......@@ -413,7 +413,7 @@ sub ArchiveAdd($$;$$$)
# files in the target that are not present in the source).
#
if (! -e "$checkin/$rootdir") {
mysystem("$MKDIR $checkin/$rootdir") == 0 or return -1;
mysystem("$MKDIR $checkin/$rootdir") == 0 or return -1
}
if (-f "/${sourcedir}/${sourcefile}" || !$exact) {
......@@ -547,6 +547,108 @@ sub ArchiveSavePoint($;$$$)
return -1;
}
#
# Add an informational tag to an archive, in the tags directory. This just
# does a copy of the current trunk, and is intended to allow users to add
# their own named tags as they like.
#
sub ArchiveTag($;$$$)
{
my ($archive_idx, $savetag, $subdir, $view) = @_;
my $cwd;
$view = $defaultview
if (!defined($view));
return -1
if (TBScriptLock("archive_${archive_idx}", 0, 120) !=
TBSCRIPTLOCK_OKAY());
#
# See if the archive exists and if it does, get the pathname to it.
#
my $directory;
if (GetArchiveDirectory($archive_idx, \$directory) < 0) {
print STDERR "ArchiveTag: ".
"Archive '$archive_idx' does not exist in the DB!\n";
goto bad;
}
if (! -d $directory || ! -w $directory) {
print STDERR "ArchiveTag: $directory cannot be written!\n";
goto bad;
}
my $repodir = "$directory/repo";
# Need to remember where we came from!
chomp($cwd = `pwd`);
# Must do the taint check too.
if ($cwd =~ /^([-\w\.\/]+)$/) {
$cwd = $1;
}
else {
print STDERR "ArchiveTag: Bad data in $cwd!\n";
goto bad;
}
# Tags must start with a letter.
if ($savetag =~ /^\d+/) {
$savetag = "T" . $savetag;
}
#
# Check to see if the subdir needs to be created. I cannot find a
# better way then the svn list command ...
#
if (defined($subdir)) {
my @tokens = split("/", $subdir);
my $path = "";
while (@tokens) {
my $token = shift(@tokens);
$path = "$path/$token";
mysystem("$SVN list file://$repodir/$view/tags${path} ".
" > /dev/null");
if ($?) {
mysystem("$SVN mkdir $svnopt -m 'ArchiveTag mkdir' ".
" file://$repodir/$view/tags${path}")
== 0 or goto bad;
}
}
# Prepend subdir to tag
$savetag = "$subdir/$savetag";
}
# Check to make sure the complete path does not already exist
mysystem("$SVN list file://$repodir/$view/tags/${savetag} > /dev/null");
if (! $?) {
print STDERR "ArchiveTag: tag already exists!\n";
goto bad;
}
#
# Create the tag ...
#
mysystem("$SVN copy $svnopt -m 'ArchiveTag' ".
" file://$repodir/$view/trunk ".
" file://$repodir/$view/tags/${savetag}")
== 0 or goto bad;
okay:
TBScriptUnlock();
chdir($cwd)
if (defined($cwd));
return 0;
bad:
TBScriptUnlock();
chdir($cwd)
if (defined($cwd));
return -1;
}
#
# Commit the current contents of the temporary store to the archive.
# Returns -1 if any error. Otherwise return 0.
......@@ -1952,6 +2054,56 @@ sub TBCommitExperimentArchive($$$;$$)
return 0;
}
#
# Tag an experiment archive.
#
sub TBTagExperimentArchive($$$;$$)
{
my ($pid, $eid, $tagext, $usertagged, $subdir) = @_;
my ($archive_idx, $view);
return 0
if (!doarchiving($pid));
my $rval = TBExperimentArchiveInfo($pid, $eid, \$archive_idx, \$view);
return 0
if ($rval > 0);
return -1
if ($rval < 0);
#
# Need this below.
#
my $query_result =
DBQueryWarn("select s.rsrcidx from experiments as e ".
"left join experiment_stats as s on e.idx=s.exptidx ".
"where e.pid='$pid' and e.eid='$eid'");
if (!$query_result || !$query_result->numrows) {
return -1;
}
my ($rsrcidx) = $query_result->fetchrow_array();
#
# Derive a tag, unless its a user specified tag. In that case it
# has to be unique cause we are going to use the whole thing as is.
#
my $newtag;
if (! $usertagged) {
my ($seconds, $microseconds) = gettimeofday();
$newtag = POSIX::strftime("T20%y%m%d-%H%M%S-", localtime());
$newtag .= int($microseconds / 1000);
$newtag .= "_${tagext}";
}
else {
$newtag = $tagext;
}
return -1
if (ArchiveTag($archive_idx, $newtag, $subdir, $view) != 0);
return 0;
}
#
# Checkout a copy of an experiment archive, optionally at a branch.
#
......
#!/usr/bin/perl -wT
#
# EMULAB-COPYRIGHT
# Copyright (c) 2006 University of Utah and the Flux Group.
# Copyright (c) 2006, 2007 University of Utah and the Flux Group.
# All rights reserved.
#
use English;
......@@ -469,6 +469,15 @@ if (defined($instance->runidx())) {
$instance->FinalizeCurrentRun() == 0
or fatal(-1, "Could not finalize experiment run for $instance!");
#
# And create a tag (and subdir) for this. This is primarily a
# convenience function for the web interface. The tag is simply an
# alias to the current trunk and does not cause a savepoint or a
# commit.
#
system("$archcontrol -d -u -s runs/$this_runid tag $pid $eid stoprun")
== 0 or fatal(-1, "Could not tag archive!");
print "Experiment run '$this_runid' has been stopped.\n";
}
......@@ -604,6 +613,14 @@ $experiment->CopyLogFiles()
# We lose the log info for this commit.
system("$archcontrol -d -t startrun_${runid} commit $pid $eid");
#
# And create a tag (and subdir) for this. This is primarily a
# convenience function for the web interface. The tag is simply an
# alias to the current trunk and does not cause a savepoint or a
# commit.
#
system("$archcontrol -d -u -s runs/$runid tag $pid $eid startrun");
# Stop the web interface from spewing.
TBExptCloseLogFile($pid, $eid)
if (defined($logname));
......
#!/usr/bin/perl -wT
#
# EMULAB-COPYRIGHT
# Copyright (c) 2006 University of Utah and the Flux Group.
# Copyright (c) 2006, 2007 University of Utah and the Flux Group.
# All rights reserved.
#
use English;
......@@ -386,6 +386,16 @@ if (!defined($run)) {
fatal(-1, "Could not create new experiment run for $instance!");
}
#
# And create a tag (and subdir) for this run. This is primarily a convenience
# function for the web interface. The tag is simply an alias to the current
# trunk and does not cause a savepoint or a commit.
#
system("$archcontrol -u -s runs/$eid tag $pid $eid startrun");
if ($?) {
fatal(-1, "Could not commit archive!");
}
#
# And the bindings for the default run ...
#
......
......@@ -22,20 +22,37 @@ CONF_PATHNAME = r"/usr/testbed/viewcvs-1.0/viewcvs.conf"
import sys
import os
import re
import getopt
sys.path.insert(0, LIBRARY_DIR)
#
# We must get a -repo argument.
#
if len(sys.argv) != 3:
repodir = False;
embedded = False;
try:
# Parse the options,
opts, req_args = getopt.getopt(sys.argv[1:], "",
[ "repo=", "embedded"])
# ... act on them appropriately, and
for opt, val in opts:
if opt == "--repo":
repodir = val
pass
elif opt == "--embedded":
embedded = True;
pass
pass
pass
except getopt.error, e:
sys.exit(1)
pass
if sys.argv[1] != "-repo":
if repodir == False:
sys.exit(1)
pass
repodir = sys.argv[2]
# go do the work
import sapi
......@@ -47,6 +64,8 @@ viewcvs._legal_params['eid'] = re.compile('^[-_a-zA-Z0-9]+$')
viewcvs._sticky_vars.append('eid')
viewcvs._legal_params['pid'] = viewcvs._re_validate_number
viewcvs._sticky_vars.append('pid')
viewcvs._legal_params['embedded'] = viewcvs._re_validate_number
viewcvs._sticky_vars.append('embedded')
server = sapi.CgiServer()
cfg = viewcvs.load_config(CONF_PATHNAME, server)
......@@ -60,4 +79,8 @@ cfg.options.generate_etags = 1
cfg.options.use_localtime = 1
cfg.general.address = "<a href='mailto:@TBOPSEMAIL_NOSLASH@'>@TBOPSEMAIL_NOSLASH@</a>"
if embedded:
cfg.templates.directory = "templates/dir_emulab.ezt"
pass
viewcvs.main(server, cfg)
<?php
#
# EMULAB-COPYRIGHT
# Copyright (c) 2000-2002, 2005, 2006 University of Utah and the Flux Group.
# Copyright (c) 2000-2002, 2005, 2006, 2007 University of Utah and the Flux Group.
# All rights reserved.
#
......@@ -206,11 +206,12 @@ $shellcmd = "env PATH=./cvsweb/ QUERY_STRING=$query PATH_INFO=$path " .
"HTTP_ACCEPT_ENCODING=$encoding ";
if (isset($repodir)) {
$prog = ($use_viewvc ? webviewvc : webcvsweb);
$prog = ($use_viewvc ? webviewvc : webcvsweb);
$embed = ($embedded ? "--embedded" : "");
# I know, I added an argument to a script that is not supposed to
# take any. So be it; it was easy.
$shellcmd .= "$TBSUEXEC_PATH $uid $pid $prog -repo $repodir";
$shellcmd .= "$TBSUEXEC_PATH $uid $pid $prog $embed --repo=$repodir";
}
else {
$shellcmd .= "$script";
......
<?php
#
# EMULAB-COPYRIGHT
# Copyright (c) 2006 University of Utah and the Flux Group.
# Copyright (c) 2006, 2007 University of Utah and the Flux Group.
# All rights reserved.
#
include("defs.php3");
......
<?php
#
# EMULAB-COPYRIGHT
# Copyright (c) 2006 University of Utah and the Flux Group.
# Copyright (c) 2006, 2007 University of Utah and the Flux Group.
# All rights reserved.
#
#
......@@ -1135,6 +1135,17 @@ class TemplateInstance
if ($detailed) {
$this->ShowRunList(1);
}
if ($detailed) {
$archive_url =
"cvsweb/cvsweb.php3/$exptidx/tags/runs/?exptidx=$exptidx".
"&embedded=1";
echo "<br>
<iframe width=100% height=300
scrolling=yes src='$archive_url' border=0>".
"</iframe>\n";
}
}
#
......@@ -1297,8 +1308,6 @@ class TemplateInstance
echo "<table align=center border=1 cellpadding=5 cellspacing=2>\n";
echo "<tr>
<th align=center>Show</th>
<th align=center>Archive</th>
<th>RunID</th>
<th>ID</th>
<th>Start Time</th>
......@@ -1346,10 +1355,8 @@ class TemplateInstance
MakeLink("run",
"guid=$guid&version=$vers".
"&exptidx=$exptidx&runidx=$runidx",
"<img border=0 alt='i' src='greenball.gif'>");
"$runid");
echo " </td>
<td align=center>$archive_link</td>
<td>$runid</td>
<td>$runidx</td>
<td>$start</td>
<td>$stop</td>
......@@ -1394,6 +1401,7 @@ class TemplateInstance
$row = mysql_fetch_array($query_result);
$start = $row['start_time'];
$stop = $row['stop_time'];
$runid = $row['runid'];
$start_tag = $row['starting_archive_tag'];
$end_tag = $row['ending_archive_tag'];
$description = $row['description'];
......@@ -1478,6 +1486,15 @@ class TemplateInstance
}
echo "</tr>\n";
echo "</table>\n";
$archive_url =
"cvsweb/cvsweb.php3/$exptidx/tags/runs/$runid/?exptidx=$exptidx".
"&embedded=1";
echo "<br>
<iframe width=100% height=300
scrolling=yes src='$archive_url' border=0>".
"</iframe>\n";
}
#
......
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