API-Eulerian

 view release on metacpan or  search on metacpan

README.md  view on Meta::CPAN

# Eulerian API module for Perl

# Eulerian DataWare House

# Eulerian Measurement Protocol - import data in real-time

examples/edw/Rest.pl  view on Meta::CPAN

=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.

examples/edw/Thin.pl  view on Meta::CPAN

my $status;
my $peer;
my $cmd;

# Read command from File
$status = Eulerian::File->read( $path );
if( $status->error() ) {
  $status->dump();
} else {
  # Get command from file
  $cmd = $status->{ data };
  # Create Peer instance
  $peer = new API::Eulerian::EDW::Peer( \%setup );
  # Send Command, call hook
  $status = $peer->request( $cmd );
  if( $status->error() ) {
    $status->dump();
  } else {
    # Dump stages durations
    $status->{ bench }->dump();
    # Cancel the command

examples/edw/get_csv_file.pl  view on Meta::CPAN

=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.

lib/API/Eulerian/EDW/Authority.pm  view on Meta::CPAN

  # Get URL used to request API::Eulerian::EDW Authority for Token.
  $status = $class->_url( $kind, $platform, $grid, $ip, $token );
  # Handle errors
  if( ! $status->error() ) {
    # Request API::Eulerian::EDW Authority
    $status = API::Eulerian::EDW::Request->get( $status->{ url } );
    # Get HTTP response
    $response = $status->{ response };
    # Get HTTP response code
    $code = $response->code;
    # We expect JSON reply data
    $json = API::Eulerian::EDW::Request->json( $response );
    if( $json && ( $code == 200 ) ) {
      $status = $json->{ error } ?
        $class->_error( $code, $json->{ error_msg } ) :
        $class->_success( $kind, $json );
    } else {
      $status = $class->_error(
        $code, $json ?
          encode_json( $json ) :
          $response->decoded_content

lib/API/Eulerian/EDW/Authority.pm  view on Meta::CPAN

# @param $class - API::Eulerian::EDW::Authority class.
# @param $kind - Token kind.
# @param $json - Json reply.
#
# @return API::Eulerian::EDW::Status
#
sub _success
{
  my ( $class, $kind, $json ) = @_;
  my $status = API::Eulerian::EDW::Status->new();
  my $row = $json->{ data }->{ rows }->[ 0 ];
  $status->{ bearer } = 'bearer ' . $row->{ $kind . '_token' };
  return $status;
}
#
# End up perl module properly
#
1;

__END__

lib/API/Eulerian/EDW/File.pm  view on Meta::CPAN

# @brief Read file content.
#
# @param path - File path.
#
# @return API::Eulerian::EDW::Status
#
sub read
{
  my $status = API::Eulerian::EDW::Status->new();
  my ( $class, $path ) = @_;
  my $data;
  my $fd;
  # Open file for reading
  open $fd, "<", $path or do {
    $status->error( 1 );
    $status->code( -1 );
    $status->msg( "Opening file : $path for reading failed. $!" );
    return $status;
  };
  # Read file content
  $data = do { local $/; <$fd> };
  # Close file
  close $fd;
  # Save content
  $status->{ data } = $data;
  return $status;
}
#
# @brief Test if given path is writable.
#
# @param $class - API::Eulerian::EDW::File class.
# @param $path - Filesystem path.
#
# @return 0 - Path isnt writable.
# @return 1 - Path is writable.

lib/API/Eulerian/EDW/File.pm  view on Meta::CPAN

=over 4

=item * File path

=back

=head3 output

=over 4

=item * Instance of an API::Eulerian::EDW::Status. On success, a new entry named 'data' is inserted into
the Status.

=back

=head2 writable()

I<Test if a given path is writable.>

=head3 input

lib/API/Eulerian/EDW/Hook.pm  view on Meta::CPAN

#/usr/bin/env perl
###############################################################################
#
# @file Hook.pm
#
# @brief Eulerian Data Warehouse Peer Hook Base class Module definition.
#
# This module is aimed to provide callback hooks userfull to process reply data.
# Library user can create is own Hook class conforming to this module interface
# to handle reply data in specific manner.
#
# @author Thorillon Xavier:x.thorillon@eulerian.com
#
# @date 26/11/2021
#
# @version 1.0
#
###############################################################################
#
# Setup module name

lib/API/Eulerian/EDW/Hook.pm  view on Meta::CPAN


=pod

=head1  NAME

API::Eulerian::EDW::Hook - Eulerian Data Warehouse Peer Hook module.

=head1 DESCRIPTION

This module provides callback hooks interface used to process analysis reply
data. Library user can create their own derived class matching this module
interface. It permits to process reply data in a specific manner.

=head1 METHODS

=head2 new()

I<Create a new instance of Eulerian Data Warehouse Peer Hook>

=head3 input

=over 4

lib/API/Eulerian/EDW/Parser/CSV.pm  view on Meta::CPAN

  my ( $self, $hooks ) = @_;
  my $parser = $self->parser();
  my $file = $self->file();
  my $uuid = $self->uuid();
  my @headers = ();
  my $start = 0;
  my $end = 0;
  my @rows;
  my $line;

  # in case of Noop - do not do any treatment on returned data - exit
  if ( $hooks eq 'API::Eulerian::EDW::Hook::Noop' ) {
    return;
  }

  # Process Headers line
  $line = <$file>; chomp $line;
  if( $parser->parse( $line ) ) {
    foreach my $field ( $parser->fields() ) {
      push @headers, [ 'UNKNOWN', $field ];
    }

lib/API/Eulerian/EDW/Peer/Rest.pm  view on Meta::CPAN

    my $url = $self->url() . '/edw/jobs';

    # Post Job create request to remote host
    $status = API::Eulerian::EDW::Request->post(
      $url, $status->{ headers }, $self->body( $command )
      );
    if( ! $status->error() ) {
      $self->uuid(
        API::Eulerian::EDW::Request->json(
          $status->{ response }
        )->{ data }->[ 0 ]
      );
    }

  }

  return $status;
}
#
# @brief Get Eulerian Data Warehouse Job Status.
#
# @param $self - Eulerian Data Warehouse Rest Peer.
# @param $reply - Eulerian Data Warehouse Platform Reply.
#
# @return Job Reply status.
#
sub status
{
  my ( $self, $status ) = @_;
  my $response = $status->{ response };
  my $url = API::Eulerian::EDW::Request->json(
    $response )->{ data }->[ 1 ];

  $status = $self->headers();
  if( ! $status->error() ) {
    $status = API::Eulerian::EDW::Request->get(
      $url, $status->{ headers }
      );
  }

  return $status;
}

lib/API/Eulerian/EDW/Peer/Rest.pm  view on Meta::CPAN

#
# @return Local file path.
#
sub path
{
  my ( $self, $response ) = @_;
  my $encoding = $self->encoding();
  my $json = API::Eulerian::EDW::Request->json( $response );
  my $pattern = '([0-9]*)\.(json|csv|parquet)';
  my $status = API::Eulerian::EDW::Status->new();
  my $url = $json->{ data }->[ 1 ];
  my $wdir = $self->wdir();
  my %rc = ();

  if( ! $wdir ) {
    $status->error( 1 );
    $status->code( 400 );
    $status->msg( "Working directory isn't set" );
  } elsif( ! API::Eulerian::EDW::File->writable( $wdir ) ) {
    $status->error( 1 );
    $status->code( 400 );

lib/API/Eulerian/EDW/Request.pm  view on Meta::CPAN

# @brief Get JSON object from HTTP response.
#
# @param $class - API::Eulerian::EDW::Request class.
# @param $response - HTTP response.
#
# @return JSON object.
#
sub json
{
  my ( $class, $response ) = @_;
  my $data = undef;

  if( $class->is_json( $response ) ) {
    $data = $response->decoded_content;
    if( defined( $data ) ) {
      chomp( $data );
      if( length( $data ) > 0 ) {
        $data = encode( 'utf-8', $data );
        $data = decode_json( $data );
       } else {
        $data = undef;
       }
    }
  }

  return $data;
}
#
# @brief Do HTTP Get on given URL.
#
# @param $class - API::Eulerian::EDW::HTTP class.
# @param $url - Remote URL.
# @param $headers - HTTP::Headers.
# @param $file - Local file path.
#
# @return API::Eulerian::EDW::Status instance.

lib/API/Eulerian/EDW/WebSocket.pm  view on Meta::CPAN

# @return Remote Port.
#
sub port
{
  return shift->socket()->peerport();
}
#
# @brief On write Websocket handler.
#
# @param $self - WebSocket.
# @param $data - Data to be writen
#
# @return Writen Size.
#
sub _on_write
{
  my ( $peer, $buf ) = @_;
  $peer->{ _WS }->{ _SOCKET }->syswrite( $buf );
}
#
# @brief On read Websocket handler.



( run in 0.367 second using v1.01-cache-2.11-cpan-8d75d55dd25 )