Commit 1e00ecc5 authored by Leigh Stoller's avatar Leigh Stoller

Return recent activity per project along with reservation list so we can

determine if reservations are being used. Work in progress.
parent 502b028b
......@@ -993,5 +993,62 @@ sub UpdateExports($)
return 0;
}
#
# Return usage records for experiments that have terminated (were running)
# between two dates.
#
sub Usage($$$)
{
my ($self, $start, $end) = @_;
my $pid_idx = $self->pid_idx();
my @results = ();
my $query_result =
DBQueryWarn("select s.eid,r.idx,s.nonlocal_id, ".
" r.swapin_time,r.swapout_time,r.pnodes,n.type, ".
" count(n.type) ".
" from experiment_resources as r ".
"left join experiment_stats as s on ".
" s.exptidx=r.exptidx ".
"left join node_history as h on ".
" h.exptidx=r.exptidx and h.op='alloc' and ".
" h.stamp >= r.swapin_time - 120 and ".
" (r.swapout_time=0 or ".
" h.stamp < r.swapout_time) ".
"left join nodes as n on n.node_id=h.node_id ".
"where s.pid_idx='$pid_idx' and ".
" r.swapin_time!=0 and ".
" ((r.swapin_time >= $start and ".
" r.swapin_time <= $end) or ".
" (r.swapout_time > $start and ".
" r.swapout_time < $end)) ".
"group by s.eid,r.idx,s.nonlocal_id, ".
" r.swapin_time,r.swapout_time,r.pnodes,n.type ".
"order by r.swapin_time desc");
return undef
if (!defined($query_result));
my @summary = ();
my $lastin = 0;
while (my ($eid,$idx,$urn,$swapin_time,$swapout_time,$count,$type) =
$query_result->fetchrow_array()) {
# The order by clause is important.
if ($swapin_time != $lastin) {
unshift(@summary, {"eid" => $eid,
"urn" => $urn || "",
"start" => $swapin_time,
"end" => $swapout_time || "",
"types" => {$type => {"count" => $count}}});
$lastin = $swapin_time;
next;
}
my $blob = $summary[0];
$blob->{"types"}->{$type} = {"count" => $count};
}
return \@summary;
}
# _Always_ make sure that this 1 is at the end of the file...
1;
......@@ -1031,6 +1031,8 @@ sub Reservations($)
# Current reservations by pid,type so we can tell the caller
# how many are actually reserved now.
my %current = ();
# Project usage numbers;
my %history = ();
while (my $row = $query_result->fetchrow_hashref()) {
my $blob = {};
......@@ -1046,6 +1048,8 @@ sub Reservations($)
print STDERR "Reservations: No such project $pid\n";
next;
}
my $projurn = $project->nonlocalurn();
my $user = User->Lookup($uid);
if (!defined($user)) {
print STDERR "Reservations: No such user $uid\n";
......@@ -1075,7 +1079,7 @@ sub Reservations($)
$blob->{"idx"} = $idx;
$blob->{"uuid"} = $uuid;
$blob->{"project"} = $project->nonlocalurn();
$blob->{"project"} = $projurn,
$blob->{"user"} = $user->nonlocalurn();
$blob->{"nodes"} = $row->{'nodes'};
$blob->{"type"} = $type;
......@@ -1086,9 +1090,14 @@ sub Reservations($)
$blob->{"notes"} = $row->{'notes'} || "";
$blob->{"approved"} = $row->{'approved'} || "";
$results{"$idx"} = $blob;
if (!exists($history{$projurn})) {
$history{$projurn} = $project->Usage(time() - (3600 * 48), time());
}
}
my $blob = {"api_version" => $API_VERSION,
"reservations" => \%results,
"history" => \%history,
};
return GeniResponse->Create(GENIRESPONSE_SUCCESS, $blob);
}
......
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