-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from EulerianTechnologies/reorg
add Hook::Noop + sample for download direct download of csv file + generic wrapper
- Loading branch information
Showing
11 changed files
with
406 additions
and
164 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
############################################################################### | ||
# | ||
# @file Rest.pl | ||
# | ||
# @brief Example of Eulerian Data Warehouse Peer performing an Analysis using | ||
# Rest Protocol. | ||
# | ||
# @author Thorillon Xavier:[email protected] | ||
# | ||
# @date 25/11/2021 | ||
# | ||
# @version 1.0 | ||
# | ||
############################################################################### | ||
|
||
use strict; | ||
|
||
use lib qw( ./lib ); | ||
|
||
use File::Slurp(); | ||
use Pod::Usage(); | ||
use Getopt::Long(); | ||
use HTTP::Tiny(); | ||
|
||
use API::Eulerian::EDW(); | ||
|
||
my ($grid,$ip,$token,$help,$site,$query) = ('','','','','',0); | ||
|
||
Getopt::Long::GetOptions( | ||
"grid=s" => \$grid, | ||
"ip=s" => \$ip, | ||
"token=s" => \$token, | ||
"site=s" => \$site, | ||
"query=s" => \$query, | ||
"help|?" => \$help | ||
); | ||
Pod::Usage::pod2usage(1) if ( $help ); | ||
|
||
my %h_setup = ( | ||
grid => $grid, | ||
ip => $ip, | ||
token => $token, | ||
site => $site, | ||
query => $query | ||
); | ||
|
||
# get local IP | ||
if ( !defined $h_setup{ip} || !length $h_setup{ip} ) { | ||
my $response = HTTP::Tiny->new->get('http://monip.org/'); | ||
unless ( $response->{success} ) { | ||
print STDERR "\tunable to reach external network to get IP address.\n"; | ||
exit(1); | ||
} | ||
($h_setup{ip}) = ($response->{content} =~ /IP\s:\s(\d+\.\d+\.\d+\.\d+)/gm); | ||
} | ||
|
||
foreach my $p ( qw/ grid ip token site query / ) { | ||
if ( !defined $h_setup{$p} || !length $h_setup{$p} ) { | ||
print STDERR "\tmissing $p parameter, check help.\n"; | ||
exit(1); | ||
} | ||
} | ||
delete $h_setup{$_} for ( qw/ site query / ); | ||
|
||
# get query to send | ||
my $qfile = './examples/edw/sql/'.$query.'.sql'; | ||
if ( !-e $qfile ) { | ||
print STDERR "\trequested query $query does not exists.\n"; | ||
exit(1); | ||
} | ||
my $date_from = time() - 24 * 3600; | ||
my $date_to = time(); | ||
|
||
my $cmd = File::Slurp::slurp($qfile); | ||
$cmd =~ s/\[% SITE %\]/$site/gm; | ||
$cmd =~ s/\[% DATE_FROM %\]/$date_from/gm; | ||
$cmd =~ s/\[% DATE_TO %\]/$date_to/gm; | ||
|
||
|
||
# | ||
# Create a user specific Hook used to handle Analysis replies. | ||
# | ||
|
||
my $edw = new API::Eulerian::EDW(); | ||
my $rh_ret = $edw->get_csv_file( \%h_setup, $cmd ); | ||
|
||
use Data::Dumper; | ||
print Dumper($rh_ret); | ||
|
||
1; | ||
__END__ | ||
=head1 NAME | ||
get_csv_file.pl - Sample EDW script for querying through REST and get a CSV file | ||
=head1 SYNOPSIS | ||
Rest.pl [optinos] | ||
Options : | ||
-help brief help message | ||
=head1 OPTIONS | ||
=over 8 | ||
=item B<-help> | ||
Print a brief help message and exists | ||
=item B<--grid> | ||
Name of the grid on which your data is hosted. | ||
=item B<--ip> | ||
The IP from which the call is going to be made and that will reach the EDW server. | ||
If not provided, will try to guess it through an external call. | ||
=item B<--token> | ||
Authorization token provided through the Eulerian interface for accessing the Eulerian API. | ||
=item B<--site> | ||
Name of the site as shown in the Eulerian Interface. | ||
=item B<--query> | ||
Name of the query to send, needs to exist in examples/edw/sql/*.sql | ||
=back | ||
=head1 DESCRIPTION | ||
Query the EDW with the REST API. | ||
=cut |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package API::Eulerian::EDW; | ||
|
||
|
||
use strict; | ||
use API::Eulerian::EDW::Peer::Rest(); | ||
|
||
sub new { | ||
my $proto = shift(); | ||
my $class = ref($proto) || $proto; | ||
return bless({}, $class); | ||
} | ||
|
||
sub get_csv_file { | ||
my ($self, $rh_p, $query) = @_; | ||
|
||
$rh_p ||= {}; | ||
$rh_p->{accept} = 'text/csv'; | ||
$rh_p->{hook} = 'API::Eulerian::EDW::Hook::Noop'; | ||
|
||
$query ||= ''; | ||
|
||
my $peer = new API::Eulerian::EDW::Peer::Rest( $rh_p ); | ||
if ( !defined $peer ) { | ||
return { error => 1, error_msg => 'unable to build object' }; | ||
} | ||
|
||
my $status = $peer->request( $query ); | ||
|
||
if ( $status->error() ) { | ||
return { | ||
error => 1, | ||
error_msg => $status->msg() | ||
}; | ||
} | ||
|
||
# kill request at EDW for clean-up | ||
$peer->cancel(); | ||
|
||
return { error => 0, path2file => $status->path() }; | ||
} | ||
|
||
1; | ||
__END__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
#/usr/bin/env perl | ||
############################################################################### | ||
# | ||
# @file Print.pm | ||
# | ||
# @brief Eulerian Data Warehouse Peer Print Hook class Module definition. | ||
# | ||
# This module is aimed to print Eulerian Data Warehouse Analytics Results into | ||
# the terminal. | ||
# | ||
# @author Thorillon Xavier:[email protected] | ||
# | ||
# @date 26/11/2021 | ||
# | ||
# @version 1.0 | ||
# | ||
############################################################################### | ||
package API::Eulerian::EDW::Hook::Noop; | ||
use strict; | ||
# | ||
# Inherited interface from API::Eulerian::EDW::Hook | ||
# | ||
#use parent 'API::Eulerian::EDW::Hook'; | ||
|
||
use API::Eulerian::EDW::Hook(); | ||
|
||
our @ISA = qw/ API::Eulerian::EDW::Hook /; | ||
|
||
# | ||
# @brief Allocate a new Eulerian Data Warehouse Peer Hook. | ||
# | ||
# @param $class - Eulerian Data Warehouse Peer Hook Class. | ||
# @param $setup - Setup attributes. | ||
# | ||
# @return Eulerian Data Warehouse Peer Hook instance. | ||
# | ||
sub new | ||
{ | ||
my ( $class, $setup ) = @_; | ||
return $class->SUPER::new( $setup ); | ||
} | ||
# | ||
# @brief Setup Eulerian Data Warehouse Peer Hook. | ||
# | ||
# @param $self - Eulerian Data Warehouse Peer Hook. | ||
# @param $setup - Setup entries. | ||
# | ||
sub setup | ||
{ | ||
my ( $self, $setup ) = @_; | ||
return $self; | ||
} | ||
# | ||
# @brief Start a new Analysis. | ||
# | ||
# @param $self - Eulerian Data Warehouse Peer Hook. | ||
# @param $uuid - UUID of Eulerian Analytics Analysis. | ||
# @param $start - Timerange begin. | ||
# @param $end - Timerange end. | ||
# @param $columns - Array of Columns definitions. | ||
# | ||
sub on_headers | ||
{ | ||
my ( $self, $uuid, $start, $end, $columns ) = @_; | ||
return $self; | ||
} | ||
# | ||
# @brief Analysis reply rows on Row outputs analysis. | ||
# | ||
# @param $self - Eulerian Data Warehouse Peer Hook. | ||
# @param $uuid - UUID of Eulerian Analytics Analysis. | ||
# @param $rows - Array of Array of Columns values. | ||
# | ||
sub on_add | ||
{ | ||
my ( $self, $uuid, $rows ) = @_; | ||
return $self; | ||
} | ||
# | ||
# @brief Analysis reply rows on Distinct/Pivot analysis. | ||
# | ||
# @param $self - Eulerian Data Warehouse Peer Hook. | ||
# @param $uuid - UUID of Eulerian Analytics Analysis. | ||
# @param $rows - Array of Array of Columns values. | ||
# | ||
sub on_replace | ||
{ | ||
my ( $self, $uuid, $rows ) = @_; | ||
return $self; | ||
|
||
} | ||
# | ||
# @brief Analysis progression callback. | ||
# | ||
# @param $self - Eulerian Data Warehouse Peer Hook. | ||
# @param $uuid - UUID of Eulerian Analytics Analysis. | ||
# @param $progress - Progression value. | ||
# | ||
sub on_progress | ||
{ | ||
my ( $self, $uuid, $progress ) = @_; | ||
return $self; | ||
} | ||
# | ||
# @brief End of Eulerian Data Warehouse Analysis. | ||
# | ||
# @param $self - Eulerian Data Warehouse Peer Hook. | ||
# @param $uuid - UUID of Eulerian Analytics Analysis. | ||
# @param $token - AES Token or Bearer. | ||
# @param $errnum - Error number. | ||
# @param $err - Error description. | ||
# @param $updated - Count of updates on server. | ||
# | ||
sub on_status | ||
{ | ||
my ( $self, $uuid, $token, $errnum, $err, $updated ) = @_; | ||
return $self; | ||
} | ||
|
||
# | ||
# Endup module properly | ||
# | ||
1; |
Oops, something went wrong.