Commit 373387a4 authored by Leigh Stoller's avatar Leigh Stoller

Convert thumbnail stuff from directory of thumbs, to a thumb stashed

in the experiment_resources table as a BLOB. The advantages are no
more special directory and permission problems, and an archive of
pretty pictures of experiments (including per-modified experiments).
parent d6af9632
......@@ -139,7 +139,7 @@ use Exporter;
TBNodeUpdateAccountsByUID
TBSaveExpLogFiles TBExptWorkDir TBExptUserDir TBExptLogDir
TBExptDestroy TBIPtoNodeID TBNodeBootReset TBNodeStateWait
TBLeaderMailList ExpGroup TBExptSetSwapUID
TBLeaderMailList ExpGroup TBExptSetSwapUID TBExptSetThumbNail
TBExptRemoveVirtualState TBExptBackupVirtualState
TBExptRestoreVirtualState
......@@ -2509,7 +2509,8 @@ sub TBExptBackupVirtualState($$$)
if (! $errors) {
foreach $table (@virtualTables) {
DBQueryWarn("SELECT * FROM $table WHERE pid='$pid' AND eid='$eid' ".
DBQueryWarn("SELECT * FROM $table ".
"WHERE pid='$pid' AND eid='$eid' ".
"INTO OUTFILE '$backupDir/$table' ")
or $errors++;
}
......@@ -2598,6 +2599,29 @@ sub TBExptSetSwapUID($$$)
"where pid='$pid' and eid='$eid'");
}
#
# Set the thumbnail for an experiment. Comes in as a binary string, which
# must be quoted before DB insertion.
#
sub TBExptSetThumbNail($$$)
{
my ($pid, $eid, $bindata) = @_;
$bindata = DBQuoteSpecial($bindata);
# Need the resource ID first.
my $query_result =
DBQueryFatal("select rsrcidx from experiments as e ".
"left join experiment_stats as s on e.idx=s.exptidx ".
"where e.pid='$pid' and e.eid='$eid'");
my ($rsrcidx) = $query_result->fetchrow_array();
# Now do the insert.
return
DBQueryFatal("update experiment_resources set thumbnail=$bindata ".
"where idx=$rsrcidx");
}
#
# Get the control network IP for a node (underlying physical node!).
#
......
......@@ -188,6 +188,7 @@ CREATE TABLE experiment_resources (
shapedlans smallint(5) unsigned default '0',
minlinks tinyint(3) unsigned default '0',
maxlinks tinyint(3) unsigned default '0',
thumbnail mediumblob,
PRIMARY KEY (idx),
KEY exptidx (exptidx),
KEY lastidx (lastidx)
......@@ -1477,17 +1478,6 @@ CREATE TABLE virt_vtypes (
members text
) TYPE=MyISAM;
--
-- Table structure for table 'vis_experiments'
--
CREATE TABLE vis_experiments (
eid varchar(32) NOT NULL default '',
pid varchar(12) NOT NULL default '',
thumb_hash varchar(64) NOT NULL default '',
PRIMARY KEY (eid,pid)
) TYPE=MyISAM;
--
-- Table structure for table 'vis_nodes'
--
......
......@@ -393,7 +393,6 @@ REPLACE INTO testsuite_preentables VALUES ('node_activity','clean');
REPLACE INTO testsuite_preentables VALUES ('portmap','clean');
REPLACE INTO testsuite_preentables VALUES ('webnews','clean');
REPLACE INTO testsuite_preentables VALUES ('vis_nodes','clean');
REPLACE INTO testsuite_preentables VALUES ('vis_experiments','clean');
REPLACE INTO testsuite_preentables VALUES ('group_stats','clean');
REPLACE INTO testsuite_preentables VALUES ('project_stats','clean');
REPLACE INTO testsuite_preentables VALUES ('user_stats','clean');
......
......@@ -743,4 +743,17 @@ last_net_act,last_cpu_act,last_ext_act);
alter table experiment_stats drop shapedlans;
alter table experiment_stats drop minlinks;
alter table experiment_stats drop maxlinks;
\ No newline at end of file
1.160: Put the thumbnail into the resources table.
alter table experiment_resources add thumbnail mediumblob
after maxlinks;
Then create the thumbs in the DB
prerender_all -t
Also remove the vis_experiments table, since no longer needed.
drop table vis_experiments;
#
# EMULAB-COPYRIGHT
# Copyright (c) 2000-2002 University of Utah and the Flux Group.
# Copyright (c) 2000-2003 University of Utah and the Flux Group.
# All rights reserved.
#
......@@ -29,8 +29,6 @@ install: \
$(addprefix $(INSTALL_LIBEXECDIR)/vis/, $(LIBEXEC_VIS))
post-install:
chgrp tbvis $(INSTALL_LIBEXECDIR)/vis/prerender
chmod g+s $(INSTALL_LIBEXECDIR)/vis/prerender
$(INSTALL_LIBEXECDIR)/vis/%: %
@echo "Installing $<"
......
......@@ -49,6 +49,7 @@ if (!getopts($optlist, \%options)) { usage; }
if (@ARGV != 2) { usage; }
my $debug = 0;
my $thumb = 0;
if ( defined($options{"v"}) ) {
$debug++;
......@@ -56,46 +57,22 @@ if ( defined($options{"v"}) ) {
$THUMB_CMD .= " -v";
}
if ( defined($options{"t"}) ) {
$thumb++;
}
#my ($pid) = $ARGV[0];
#my ($eid) = $ARGV[1];
my ($pid) = $ARGV[0] =~ /([0-9a-zA-Z_\-]+)/;
my ($eid) = $ARGV[1] =~ /([0-9a-zA-Z_\-]+)/;
if ( defined($options{"t"}) ) {
my $result = DBQueryFatal("SELECT thumb_hash FROM vis_experiments " .
"WHERE pid='$pid' AND eid='$eid'");
($thumb) = $result->fetchrow;
if (!$thumb) {
if (defined($options{"r"})) {
print STDERR "Warning! No thumbnail found to remove.\n";
} else {
# If we're not removing the experiment, we need to generate a thumbhash.
# Hash a lot of random junk.
$thumb = md5_hex( rand(99999) . "-$$-$pid-$eid-XYzzY" );
DBQueryFatal("INSERT INTO vis_experiments (pid,eid,thumb_hash) VALUES ".
"('$pid','$eid','$thumb')");
}
}
if ($thumb) {
dprint "Thumb hash is '$thumb'.\n";
} else {
dprint "No thumb hash.\n";
}
}
# for the mungeName function, below.
$mungeUID = 0;
### If they specified -r, meaning they just wanted to remove vis info
### from the DB, we do it and quit.
if (defined($options{"r"})) {
if ($thumb) {
system("/bin/rm @prefix@/www/thumbs/tn$thumb.png");
}
DBQueryFatal("DELETE FROM vis_nodes WHERE pid='$pid' AND eid='$eid'");
DBQueryFatal("DELETE FROM vis_experiments WHERE pid='$pid' AND eid='$eid'");
exit 0;
}
......@@ -430,16 +407,18 @@ foreach $node (keys %nodes) {
}
# Generate thumbnail, if called for. The .png file is put into the work
# directory, so it is copied off to the users and the archive directory.
# directory, so it is copied off to the users directory. We take that
# file and stash it in the DB, since that is where the system will read
# it from.
if ($thumb) {
my $workdir = TBExptWorkDir($pid, $eid);
my $fname = "$workdir/$eid.png";
if (system("$THUMB_CMD $pid $eid > $fname")) {
if (system("nice $THUMB_CMD $pid $eid > $fname")) {
print STDERR "Error generating thumbnail.\n";
}
system("cp -pf $fname @prefix@/www/thumbs/tn$thumb.png");
TBExptSetThumbNail($pid, $eid, `cat $fname`);
}
### Success!!
......
......@@ -113,7 +113,6 @@ install: $(addprefix $(INSTALL_WWWDIR)/, $(ALLFILES)) \
$(addprefix $(INSTALL_WWWDIR)/buildui/, $(ALLBUI)) \
$(addprefix $(INSTALL_WWWDIR)/autostatus-icons/, $(ALLICONS)) \
$(addprefix $(INSTALL_WWWDIR)/cvsweb/, $(ALLCVSWEB))
-mkdir -p -m 771 $(INSTALL_WWWDIR)/thumbs
$(INSTALL_DATA) $(TESTBED_SRCDIR)/doc/ChangeLog \
$(INSTALL_WWWDIR)/doc/ChangeLog.txt
cd $(INSTALL_WWWDIR) && \
......@@ -130,7 +129,7 @@ install: $(addprefix $(INSTALL_WWWDIR)/, $(ALLFILES)) \
$(INSTALL_CVSWEBCGI)
post-install:
chgrp tbvis $(INSTALL_WWWDIR)/thumbs
$(INSTALL_WWWDIR)/%: %
@echo "Installing $<"
......
......@@ -30,12 +30,11 @@ function GENPLIST ($which, $query_result)
$pid = $row["pid"];
$eid = $row["eid"];
$pnodes = $row["pnodes"];
$thumb_hash = $row["thumb_hash"];
$swapdate = $row["swapdate"];
$state = $row["state"];
$rsrcidx = $row["rsrcidx"];
if ($pid == $TBOPSPID || $pnodes == 0 ||
!isset($thumb_hash)) {
if ($pid == $TBOPSPID || $pnodes == 0) {
continue;
}
if ($state == $TB_EXPTSTATE_ACTIVE) {
......@@ -47,7 +46,7 @@ function GENPLIST ($which, $query_result)
echo "<td align=center>";
echo "<img border=1 width=128 height=128 class='stealth' ".
" src='thumbs/tn$thumb_hash.png'>".
" src='showthumb.php3?idx=$rsrcidx'>".
" $swapdate" .
"</td>";
......@@ -63,14 +62,12 @@ function GENPLIST ($which, $query_result)
# Active Experiments.
#
$query_result =
DBQueryFatal("select e.pid,e.eid,e.state,rs.pnodes,ve.thumb_hash, ".
DBQueryFatal("select e.pid,e.eid,e.state,s.rsrcidx,rs.pnodes, ".
" s.swapin_last as swapdate ".
" from experiments as e ".
"left join vis_experiments as ve on ".
" ve.pid=e.pid and ve.eid=e.eid ".
"left join experiment_stats as s on s.exptidx=e.idx ".
"left join experiment_resources as rs on rs.idx=s.rsrcidx ".
"where rs.pnodes>0 and ".
"where rs.pnodes>0 and rs.thumbnail is not null and ".
" e.state='" . $TB_EXPTSTATE_ACTIVE . "' and " .
" e.pid!='emulab-ops' and ".
" not (e.pid='ron' and e.eid='all') ".
......@@ -82,14 +79,13 @@ if (mysql_num_rows($query_result)) {
}
$query_result =
DBQueryFatal("select e.pid,e.eid,e.state,rs.pnodes,ve.thumb_hash, ".
DBQueryFatal("select e.pid,e.eid,e.state,s.rsrcidx,rs.pnodes, ".
" s.swapout_last as swapdate ".
" from experiments as e ".
"left join vis_experiments as ve on ".
" ve.pid=e.pid and ve.eid=e.eid ".
"left join experiment_stats as s on s.exptidx=e.idx ".
"left join experiment_resources as rs on rs.idx=s.rsrcidx ".
"where rs.pnodes-rs.delaynodes>2 and ".
" rs.thumbnail is not null and ".
" e.state='" . $TB_EXPTSTATE_SWAPPED . "' " .
"order by s.swapout_last desc ".
"limit 200");
......
......@@ -62,16 +62,6 @@ if ($showtype != "all") {
echo "</b><br />\n";
#echo "<b>Show:
# <a class='static' href='showexp_list.php3?showtype=active&sortby=$sortby&thumb=$thumb'>active</a>,
# <a class='static' href='showexp_list.php3?showtype=batch&sortby=$sortby&thumb=$thumb'>batch</a>,";
#if ($isadmin)
# echo "\n<a class='static' href='showexp_list.php3?showtype=idle&sortby=$sortby&thumb=$thumb'".
# ">idle</a>,";
#
#echo "\n <a class='static' href='showexp_list.php3?showtype=all&sortby=$sortby&thumb=$thumb'>all</a>.
# </b><br />\n";
# Default value for showlastlogin is 1 for admins
$showlastlogin = $isadmin;
# Note: setting this to 1 for non-admins still doesn't make the column
......@@ -190,18 +180,8 @@ if ($thumb && !$idle) {
echo "</b><br />\n";
}
# if (!$thumb) {
# echo "<b><a class='static' href='showexp_list.php3?showtype=$showtype&sortby=$sortby&thumb=1'>".
# "Switch to Thumbnail view".
# "</a></b><br />";
# } else {
# echo "<b><a class='static' href='showexp_list.php3?showtype=$showtype&sortby=$sortby&thumb=0'>".
# "Switch to List view".
# "</a></b><br />";
# }
}
echo "<br />\n";
#
......@@ -247,11 +227,10 @@ count(r.node_id) as ncount, swap_requests,
round((unix_timestamp(now())-unix_timestamp(last_swap_req))/3600,1) as lastreq,
(unix_timestamp(now()) - unix_timestamp(max(greatest(
last_tty_act,last_net_act,last_cpu_act,last_ext_act)))) as idlesec,
(max(last_report) is not null) as canbeidle,
ve.thumb_hash as thumb_hash
(max(last_report) is not null) as canbeidle, s.rsrcidx
from experiments as e
left join vis_experiments as ve on ve.pid=e.pid and ve.eid=e.eid
left join reserved as r on e.pid=r.pid and e.eid=r.eid
left join reserved as r on e.pid=r.pid and e.eid=r.eid
left join experiment_stats as s on e.idx=s.exptidx
left join nodes as n on r.node_id=n.node_id
left join node_activity as na on r.node_id=na.node_id
where (n.type!='dnard' or n.type is null) $clause
......@@ -264,11 +243,10 @@ select distinct e.*, date_format(expt_swapped,'%Y-%m-%d') as d,
date_format(expt_swapped,'%c/%e') as dshort, count(r.node_id) as ncount,
(unix_timestamp(now()) - unix_timestamp(max(greatest(
last_tty_act,last_net_act,last_cpu_act,last_ext_act)))) as idlesec,
(max(last_report) is not null) as canbeidle,
ve.thumb_hash as thumb_hash
(max(last_report) is not null) as canbeidle, s.rsrcidx
from group_membership as g
left join experiments as e on g.pid=e.pid and g.pid=g.gid
left join vis_experiments as ve on ve.pid=e.pid and ve.eid=e.eid
left join experiment_stats as s on e.idx=s.exptidx
left join reserved as r on e.pid=r.pid and e.eid=r.eid
left join nodes as n on r.node_id=n.node_id
left join node_activity as na on r.node_id=na.node_id
......@@ -349,35 +327,17 @@ if ($thumb && !$idle) {
$huid = $row["expt_head_uid"];
$name = stripslashes($row["expt_name"]);
$date = $row["dshort"];
$thumb_hash = $row["thumb_hash"];
$rsrcidx = $row["rsrcidx"];
if ($idle && ($str=="&nbsp;" || !$pcs)) { continue; }
if ($TBMAINSITE) {
# if image is not in thumbs dir, render it!
if ($thumb_hash && !file_exists ($TBDIR . "www/thumbs/tn$thumb_hash.png")) {
# we'll be paranoid, and escape pid and eid.
$prerender_cmd = $TBDIR . "libexec/vis/prerender -t " .
escapeshellcmd($pid) . " " . escapeshellcmd($eid) .
" > /dev/null";
#echo "<!-- rerendered $pid $eid -->";
system( $prerender_cmd );
}
}
# echo "<table style=\"float: none;\" width=256 height=192><tr><td>".
# echo "And<table align=left width=256 height=192><tr width=256><td height=192>".
# echo "<table width=256 height=192><tr><td>".
# echo "<td width=50%>".
# echo "<tr
if ($thumb == 2) {
if ($pid != "emulab-ops") {
echo "<td align=center>".
"<a href='shownsfile.php3?pid=$pid&eid=$eid'>".
"<img border=1 width=128 height=128 class='stealth' ".
" src='thumbs/tn$thumb_hash.png' />".
"<br />\n".
" src='showthumb.php3?idx=$rsrcidx'>".
"<br>\n".
"<b>".
"<a href='showproject.php3?pid=$pid'>$pid</a>/<br />".
"<a href='showexp.php3?pid=$pid&eid=$eid'>$eid</a>".
......@@ -395,9 +355,7 @@ if ($thumb && !$idle) {
"<td width=128 align=center>".
"<a href='shownsfile.php3?pid=$pid&eid=$eid'>".
"<img border=1 width=128 height=128 class='stealth' ".
# " src='top2image.php3?pid=$pid&eid=$eid&thumb=128' />".
# " src='thumbs/$pid.$eid.png' />".
" src='thumbs/tn$thumb_hash.png' />".
" src='showthumb.php3?idx=$rsrcidx'>".
"</a>".
"</td>".
"<td align=left class='paddedcell'>".
......
......@@ -2072,6 +2072,9 @@ function SHOWEXPTSTATS($pid, $eid) {
echo "<table align=center border=1>\n";
foreach($row as $key => $value) {
if ($key == "thumbnail")
continue;
echo "<tr>
<td>$key:</td>
<td>$value</td>
......
<?php
#
# EMULAB-COPYRIGHT
# Copyright (c) 2000-2003 University of Utah and the Flux Group.
# All rights reserved.
#
include("defs.php3");
#
# This script generates the contents of an image. No headers or footers,
# just spit back an image. The thumbs are public, so no checking is done.
# To obfuscate, do not use pid/eid, but rather use the resource index.
#
#
# Verify page arguments.
#
if (!isset($idx) ||
strcmp($idx, "") == 0) {
USERERROR("You must provide an ID.", 1);
}
#
# Get the thumb from the DB.
#
$query_result =
DBQueryFatal("select thumbnail from experiment_resources ".
"where idx='$idx'");
if (!$query_result || (mysql_num_rows($query_result) == 0)) {
USERERROR("No such thumbnail on file!", 1);
}
$row = mysql_fetch_array($query_result);
$data = $row[thumbnail];
header("Content-type: image/png");
echo "$data";
#
# No Footer!
#
?>
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