Commit d3c74dc7 authored by Leigh B Stoller's avatar Leigh B Stoller
Browse files

Add ReadHistoryRecords() API to download the aggregate history

from the CH database.

Requires a credential (possibly delegated) with the "readhistory"
privilege.

   ReadHistoryRecords(credential, int index, int count);

where index and count are optional, but to be useful you will want to
track the index and ask for "count" records at a time until you get
back an error saying there are no more to give you. You are limited to
max 100 (the default is 10) time at a time.

The return value is a list of records, where each record is an array
of the data in the aggregate_history table and the manifest. There
might be multiple records if the slice was updated, since there will
be multiple manifests. I won't describe it, you can just print out a
record and see it, it is all pretty obvious.
parent a25b7973
......@@ -1285,6 +1285,87 @@ sub List($)
return GeniResponse->Create(GENIRESPONSE_SUCCESS, \@results);
}
#
# Read the history records. Only a CH or delegated CH credential
# is allowed to do this.
#
sub ReadHistoryRecords($)
{
my ($argref) = @_;
my $cred = $argref->{'credential'};
my $index = $argref->{'index'};
my $count = $argref->{'count'};
if (! (defined($cred))) {
return GeniResponse->MalformedArgsResponse("credential");
}
if (defined($count)) {
if (! (($count =~ /^\d*$/) && $count > 0 && $count <= 100)) {
return GeniResponse->MalformedArgsResponse("count");
}
}
else {
$count = 10;
}
if (defined($index)) {
if (! (($index =~ /^\d*$/) && $index > 0)) {
return GeniResponse->MalformedArgsResponse("index");
}
}
else {
$index = 10;
}
my $authority = GeniAuthority->Lookup($ENV{'MYURN'});
if (!defined($authority)) {
print STDERR "Could not find local authority object\n";
return GeniResponse->Create(GENIRESPONSE_ERROR);
}
my $credential = CheckCredential($cred, $authority);
return $credential
if (GeniResponse::IsResponse($credential));
$credential->HasPrivilege("readhistory") or
return GeniResponse->Create( GENIRESPONSE_FORBIDDEN, undef,
"Insufficient privilege" );
my $query_result =
DBQueryWarn("select a.*,m.manifest from aggregate_history as a ".
"left join manifest_history as m on ".
" m.aggregate_urn=a.urn ".
"where a.idx>=$index limit $count");
return GeniResponse->Create(GENIRESPONSE_ERROR)
if (!$query_result);
return GeniResponse->Create(GENIRESPONSE_SEARCHFAILED, undef,
"Mo matching records")
if (! $query_result->numrows);
my @results = ();
while (my $row = $query_result->fetchrow_hashref()) {
my %blob = ();
$row->{'slice_urn'} = $row->{'slice_hrn'}
if (!defined($row->{'slice_urn'}));
$blob{'index'} = $row->{'idx'};
$blob{'uuid'} = $row->{'uuid'};
$blob{'urn'} = $row->{'urn'};
$blob{'slice_urn'} = $row->{'slice_urn'};
$blob{'slice_uuid'} = $row->{'slice_uuid'};
$blob{'creator_urn'} = $row->{'creator_urn'};
$blob{'creator_uuid'} = $row->{'creator_uuid'};
$blob{'created'} = $row->{'created'};
$blob{'destroyed'} = $row->{'destroyed'};
$blob{'manifest'} = $row->{'manifest'};
push(@results, \%blob);
}
return GeniResponse->Create(GENIRESPONSE_SUCCESS, \@results);
}
#
# Initial credential check.
#
......
......@@ -36,6 +36,7 @@ $GENI_METHODS = {
"List" => \&GeniCH::List,
"WhoAmI" => \&GeniCH::WhoAmI,
"PostHistoryRecord" => \&GeniCH::PostHistoryRecord,
"ReadHistoryRecords" => \&GeniCH::ReadHistoryRecords,
};
1;
......
Supports Markdown
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