Apache-Hadoop-WebHDFS

 view release on metacpan or  search on metacpan

lib/Apache/Hadoop/WebHDFS.pm  view on Meta::CPAN

#!/usr/bin/perl
package Apache::Hadoop::WebHDFS;
our $VERSION = "0.04";      
use warnings;
use strict;
use lib '.';
use parent 'WWW::Mechanize';
use Carp;
use File::Map 'map_file';

# ###################
# WWW::Mech calls we care about
# $m -> get('http://url.com')  Does a get on that url
# $m -> put('http://blah.com', content=$content)
#
# $m -> success()  boolean if last request was success
# $m -> content()  content of request, which can be formated
# $m -> ct()       content type returned, ie: 'application/json'
# $m -> status()   HTTP status code of response

sub redirect_ok {
    # need to allow 'put' to follow redirect on 307 requests, per RFC 2616 section 10.3.8
    # redirect_ok is part of LWP::UserAgent which is subclassed 
    # by WWW:Mech and finally Apache::Hadoop::WebHDFS. 
    return 1;    # always return true.
}

sub new {
	# Create new WebHDFS object
    my $class = shift;
	my $namenode =  'localhost';
	my $namenodeport= 50070;
	my $authmethod = 'gssapi';                # 3 values: gssapi, unsecure, doas
	my ($url, $urlpre, $urlauth, $user, $doas_user)  = undef;
    
	if ($_[0]->{'doas_user'}) { $doas_user =  $_[0]->{'doas_user'}; }
	if ($_[0]->{'namenode'}) { $namenode =  $_[0]->{'namenode'}; }
	if ($_[0]->{'namenodeport'}) { $namenodeport =  $_[0]->{'namenodeport'}; }
    if ($_[0]->{'authmethod'}) { $authmethod =  $_[0]->{'authmethod'}; }
    if ($_[0]->{'user'}) { $user =  $_[0]->{'user'}; }

    # stack_depth set to 0 so we don't blow-up ram by saving content with each request.
    my $self = $class-> SUPER::new( agent=>"Apache_Hadoop_WebHDFS",
                                    stack_depth=>"0", 
    );

	$self->{'namenode'} = $namenode;
	$self->{'namenodeport'} = $namenodeport;
	$self->{'authmethod'} = $authmethod;
	$self->{'user'} = $user;
	$self->{'doas_user'} = $doas_user;
	return $self;
}

sub getdelegationtoken {
    # Fetch delegation token and store in object
    my ( $self ) = shift; 
    my $token = '';
	my $url = 'http://' . $self->{'namenode'} . ':' . $self->{'namenodeport'} . '/webhdfs/v1/?op=GETDELEGATIONTOKEN&renewer=' . $self->{'user'};
	if ($self->{'authmethod'} eq 'gssapi') {
      $self->get( $url );
      if ( $self->success() ) { 
        $token = substr ($self->content(), 23 , -3);
      }
      $self->{'webhdfstoken'}=$token;
	} else {



( run in 4.504 seconds using v1.01-cache-2.11-cpan-5837b0d9d2c )