Commit 10383734 authored by Leigh Stoller's avatar Leigh Stoller

When searching for an IP on the history page, lets also show a matching

current experiment if there is one. This is convenient.
parent 74258700
......@@ -31,16 +31,18 @@ use Date::Parse;
#
sub usage()
{
print STDERR "Usage: searchip [-h [-s min] [-e max]] ipv4\n";
print STDERR "Usage: searchip [-h | -b [-s min] [-e max]] ipv4\n";
print STDERR "Options:\n";
print STDERR " -h - Search historical instances instead of current.\n";
print STDERR " -b - Search both current and historical instances.\n";
print STDERR " -s - Start search timestamp for -h option.\n";
print STDERR " -e - End search timestamp for -h option.\n";
exit(-1);
}
my $optlist = "dt:hs:e:";
my $optlist = "dt:hs:e:b";
my $debug = 0;
my $historical = 0;
my $both = 0;
my $webtask_id;
my $webtask;
my $start;
......@@ -95,6 +97,10 @@ if (defined($options{"d"})) {
if (defined($options{"h"})) {
$historical = 1;
}
if (defined($options{"b"})) {
$historical = 1;
$both = 1;
}
if (defined($options{"s"})) {
$start = $options{"s"};
if ($start !~ /^\d+$/) {
......@@ -162,11 +168,7 @@ sub SearchCurrent()
}
if (!$found) {
print "No matching instance for IP\n";
if (defined($webtask)) {
$webtask->output("No matching instance for IP");
$webtask->Exited(1);
}
exit(1);
return undef;
}
my $instance = $found->instance();
my $pid = $instance->pid();
......@@ -180,13 +182,8 @@ sub SearchCurrent()
my $mesg = "Found IP: $pid/$name - $cluster_name";
print $mesg . "\n";
if (defined($webtask)) {
$webtask->instance($instance->uuid);
$webtask->aggregate_urn($aggregate_urn);
$webtask->output($mesg);
$webtask->Exited(0);
}
exit(0);
return $instance->uuid();
}
sub SearchHistory()
......@@ -283,11 +280,32 @@ sub SearchManifest($)
}
return 0;
}
if ($historical) {
SearchHistory();
if ($historical || $both) {
if ($both) {
my $uuid = SearchCurrent();
if (defined($webtask)) {
$webtask->instance($uuid);
}
}
my @list = SearchHistory();
if (defined($webtask)) {
$webtask->instancelist(\@list);
$webtask->Exited(0);
}
}
else {
SearchCurrent();
my $uuid = SearchCurrent();
if (!defined($uuid)) {
if (defined($webtask)) {
$webtask->output("No matching instance for IP");
$webtask->Exited(1);
}
exit(1);
}
if (defined($webtask)) {
$webtask->instance($uuid);
$webtask->Exited(0);
}
}
exit(0);
......
......@@ -209,7 +209,7 @@ function Do_Search()
function SearchForIP($ip, $min, $max)
{
global $this_user, $portals;
global $this_user, $portals, $urn_mapping;
$this_uid = $this_user->uid();
$results = array();
......@@ -220,7 +220,7 @@ function SearchForIP($ip, $min, $max)
$webtask = WebTask::CreateAnonymous();
$retval = SUEXEC($this_uid, "nobody",
"websearchip -t " . $webtask->task_id() .
" -s $min -e $max -h $ip",
" -s $min -e $max -b $ip",
SUEXEC_ACTION_IGNORE);
$webtask->Refresh();
......@@ -235,9 +235,66 @@ function SearchForIP($ip, $min, $max)
$webtask->Delete();
return;
}
$current = $webtask->TaskValue("instance");
$instances = $webtask->TaskValue("instancelist");
$webtask->Delete();
if ($current) {
#
# This is a bit hokey, but it lets us show a current experiment
# in the activity list when searching for an IP, which is handy.
#
$instance = Instance::Lookup($current);
error_log("foo: $min, $max, " . strtotime($instance->started()));
if ($instance &&
(strtotime($instance->started()) > $min &&
strtotime($instance->started()) < $max)) {
$uuid = $instance->uuid();
$iname = $instance->name();
$pproj = $instance->pid();
$created = DateStringGMT($instance->created());
$started = DateStringGMT($instance->started());
$destroyed = null;
$creator = $instance->creator();
$pcount = $instance->physnode_count();
$vcount = $instance->virtnode_count();
$portal = $portals[$instance->servername()];
$phours = round(pcount *
((time() -
strtotime($instance->created())) / 3600.0));
# Profile Info.
$profile = Profile::Lookup($instance->profile_id(),
$instance->profile_version());
if ($profile) {
$pname = $profile->name();
$puuid = $profile->uuid();
}
$clusters = array();
foreach ($instance->slivers() as $sliver) {
$abbreviation = $urn_mapping[$sliver->aggregate_urn()];
$clusters[] = $abbreviation;
}
$clusters = join(",", $clusters);
# Backwards compat.
if (!isset($pproj)) {
$pproj = "";
}
if (!isset($iname)) {
$iname = "&nbsp;";
}
# Save space with array instead of hash.
$instance =
array($pname, $pproj, $puuid, $pcount, $vcount,
$creator, $started, $destroyed, $phours, $iname,
$uuid, $created, $portal, $clusters);
$results[] = $instance;
}
}
foreach ($instances as $uuid) {
$instance = InstanceHistory::Lookup($uuid);
if (!$instance) {
......@@ -265,8 +322,8 @@ function SearchForIP($ip, $min, $max)
}
$clusters = array();
foreach ($instance->slivers() as $sliver) {
$aggregate = Aggregate::Lookup($sliver["aggregate_urn"]);
$clusters[] = $aggregate->abbreviation();
$abbreviation = $urn_mapping[$sliver["aggregate_urn"]];
$clusters[] = $abbreviation;
}
$clusters = join(",", $clusters);
......
......@@ -64,7 +64,11 @@
<td class='format-date'><%- instance[6] %></td>
<td class='format-date'><%- instance[7] %></td>
<td class="text-center">
<a href='memlane.php?uuid=<%- instance[10] %>' target="_blank">
<% if (instance[7]) { %>
<a href='memlane.php?uuid=<%- instance[10] %>' target="_blank">
<% } else { %>
<a href='status.php?uuid=<%- instance[10] %>' target="_blank">
<% } %>
<span class="align-center-inline
glyphicon glyphicon-eye-open"></span></a>
</td>
......
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