Net-Hadoop-YARN

 view release on metacpan or  search on metacpan

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

        return wantarray ? @rv : $rv[0];
    };
}

sub _collect_from_history {
    my $self  = shift;
    my $args  = shift;
    my $name  = shift;
    my $error = shift || Carp::confess "No error message specified!";

    my $hist_method = $app_to_hist{ $name } || [ $name ];
    my($hmethod, $hregex) = @{ $hist_method };

    if ( DEBUG ) {
        print STDERR "Received HTML from the API. ",
                      "I will now attempt to collect the information from the history server\n";
        printf STDERR "The error was: %s\n", $error
            if DEBUG > 1;
    }

    my @hist_param;
    if ( $error =~ RE_ARCHIVED_ERROR && ( $name eq 'jobs' || $name eq 'job' ) ) {
        print STDERR "Job was archived\n" if DEBUG;
        @hist_param = (
            map {
                (my $c = $_) =~ s{ \bapplication_ }{job_}xms;
                $c;
            } @{ $args }
        );
    }
    else {
        print STDERR "Job was not available from he RM\n" if DEBUG;
        @hist_param = (
            $hregex
                ? grep { $_ =~ $hregex }
                    $self->_extract_ids_from_error_html( $error )
                : ()
        );
    }

    my @rv;
    eval {
        @rv = $self->history_object->$hmethod( @hist_param );
        1;
    } or do {
        my $eval_error_hist = $@ || 'Zombie error';
        Carp::confess "Received HTML from the API and attempting to map that to a historical job failed: $error\n$eval_error_hist\n";
    };

    foreach my $thing ( @rv ) {
        next if ! Ref::Util::is_hashref $thing;
        $thing->{__from_history} = 1;
    }

    return @rv;
}

sub _extract_ids_from_error_html {
    my $self  = shift;
    my $error = shift || Carp::confess "No error message specified!";
    my(undef, $html) = split m{\Q<!DOCTYPE\E}xms, $error, 2;
    $html = '<!DOCTYPE' . $html;
    my $parser = HTML::PullParser->new(
                    doc         => \$html,
                    start       => 'event, tagname, @attr',
                    report_tags => [qw( a )],
                ) || Carp::confess "Can't parse HTML received from the API: $!";
    my %link;
    while ( my $token = $parser->get_token ) {
        next if $token->[0] ne 'start';
        my($type, $tag, %attr) = @{ $token };
        my $link = $attr{href} || next;
        $link{ $link }++;
    }
    my %id;
    for my $link ( keys %link ) {
        $id{ $_ }++ for $self->_extract_valid_params( $link );
    }
    return keys %id;
}

sub info {
    my $self = shift;
    $self->mapreduce(@_);
}

sub mapreduce {
    my $self   = shift;
    my $app_id = shift;
    my $res    = $self->_get("{appid}/ws/v1/mapreduce/info");
    return $res->{info};
}

sub tasks {
    my $self = shift;
    $self->_get_tasks(@_);
}

1;

__END__

=pod

=encoding UTF-8

=head1 NAME

Net::Hadoop::YARN::ApplicationMaster

=head1 VERSION

version 0.203

=head1 NAME

Net::Hadoop::YARN::ApplicationMaster

Implementation of the REST API described in
L<http://hadoop.apache.org/docs/r2.5.1/hadoop-mapreduce-client/hadoop-mapreduce-client-core/MapredAppMasterRest.html>



( run in 1.343 second using v1.01-cache-2.11-cpan-71847e10f99 )