Net-Hadoop-YARN

 view release on metacpan or  search on metacpan

lib/Net/Hadoop/YARN/ResourceManager.pm  view on Meta::CPAN

package Net::Hadoop::YARN::ResourceManager;
$Net::Hadoop::YARN::ResourceManager::VERSION = '0.203';
use strict;
use warnings;
use 5.10.0;

use Data::Dumper;
use Moo;
use Ref::Util qw(
    is_ref
    is_arrayref
    is_hashref
);
use Scalar::Util qw(
    refaddr
);

with 'Net::Hadoop::YARN::Roles::Common';

has '+servers' => (
    default => sub { ["localhost:8088"] },
);

has '+add_host_key' => ( default => sub { 1 } );

# After CDH 5.8.2, The RM properly issues a 302 redirect, but losing any query
# string in the original request, thus making the filters and any other parameter
# a no-op and returning huge responses including "everything" instead of a subset.
#
# eg: { queue: "root.whatever" } filter will be lost after the redirect.
#
# We can't use active_rm() in here or in the Common role, as it will trigger a
# deep recursion due to the fact that the HTTP calls are shared from there.
#
# Possibly needs to be revisited again in the future.
#
has '+no_http_redirect' => ( default => sub { 1 } );

sub active_rm {
    my $self = shift;
    my $opt  = is_hashref $_[0] ? shift @_ : {};
    my $rv;

    foreach my $server ( @{ $self->servers } ) {
        my $info = $self->info({ server => $server });
        my $haState = $info->{haState} || next;
        if ( $haState eq 'ACTIVE' ) {
            $rv = $server;
            last;
        }
    }

    if ( ! $rv ) {
        die sprintf "Failed to locate the active YARN Resource Manager from these hosts: %s",
                        join( q{, }, @{ $self->servers } ),
        ;
    }

    if ( $opt->{hostname_only} ) {
        return +( split m{[:]}xms, $rv )[0];
    }

    return $rv;
}

sub info {
    my $self = shift;
    my $opt  = is_hashref $_[0] ? shift @_ : {};



( run in 1.450 second using v1.01-cache-2.11-cpan-0d23b851a93 )