| 1 | package Net::Hadoop::Oozie::Role::LWP; | ||||||||||||||||||||||||||||||||||||
| 2 | 1 | $Net::Hadoop::Oozie::Role::LWP::VERSION = '0.114'; | |||||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use 5.010; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use Carp qw( confess ); | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use Constant::FromGlobal DEBUG => { int => 1, default => 0, env => 1 }; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use JSON::XS; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use LWP::UserAgent; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use Moo::Role; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use Scalar::Util qw( blessed ); | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||
| 14 | 1 | with 'Net::Hadoop::YARN::Roles::Common'; | |||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||
| 16 | 1 | my $json = JSON::XS->new->pretty(1)->canonical(1); | |||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||
| 18 | # TODO: use the one from YARN or migrate there | ||||||||||||||||||||||||||||||||||||
| 19 | sub agent_request { | ||||||||||||||||||||||||||||||||||||
| 20 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||
|
Subroutine
agent_request: not called CC=18 SCAR=58.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 21 | 0 | my ($uri, $method, $payload) = @_; | |||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||
| 23 | 0 | print "OOZIE URI: $uri\n" if DEBUG; | |||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||
| 25 | 0 | my $response; | |||||||||||||||||||||||||||||||||||
| 26 | 0 | ▶ | if (!$method || $method eq 'get') { | ||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition0%0/3
not $method or $method eq "get"
MC/DC0%0/2
not $method or $method eq "get"
not $method
$method eq "get"
Truth table0%0/3
not(A) or B
A= not $methodB= $method eq "get"
| |||||||||||||||||||||||||||||||||||||
| 27 | 0 | $response = $self->ua->get($uri); | |||||||||||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||||||||||
| 29 | elsif ($method eq 'post') { | ||||||||||||||||||||||||||||||||||||
| 30 | 0 | $response = $self->ua->post( | |||||||||||||||||||||||||||||||||||
| 31 | $uri, | ||||||||||||||||||||||||||||||||||||
| 32 | 'Content-Type' => "application/xml;charset=UTF-8", | ||||||||||||||||||||||||||||||||||||
| 33 | Content => $payload | ||||||||||||||||||||||||||||||||||||
| 34 | ); | ||||||||||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||||||||||
| 36 | elsif ($method eq 'put') { | ||||||||||||||||||||||||||||||||||||
| 37 | 0 | $response = $self->ua->put( $uri, | |||||||||||||||||||||||||||||||||||
| 38 | 'Content-Type' => "application/xml;charset=UTF-8", | ||||||||||||||||||||||||||||||||||||
| 39 | ); | ||||||||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||||||
| 41 | else { | ||||||||||||||||||||||||||||||||||||
| 42 | 0 | die "Unknown method"; | |||||||||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||
| 45 | 0 | ▶ | my $content = $response->decoded_content || ''; | ||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$response->decoded_content || ''
MC/DC0%0/1
$response->decoded_content || ''
$response->decoded_content
Truth table0%0/2
A
A= $response->decoded_content
| |||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||
| 47 | 0 | ▶ | if ( $response->is_success ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||
| 49 | 0 | ▶ | return {} if !$content; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||
| 51 | 0 | ▶ | my $type = $response->header('content-type') || q{}; | ||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$response->header('content-type') || ''
MC/DC0%0/1
$response->header('content-type') || ''
$response->header('content-type')
Truth table0%0/2
A
A= $response->header('content-type')
| |||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||
| 53 | 0 | ▶ | return { response => $content } if index( lc $type, 'json' ) == -1; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||
| 55 | 0 | my $res; | |||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||
| 57 | eval { | ||||||||||||||||||||||||||||||||||||
| 58 | 0 | $res = $json->decode($content); | |||||||||||||||||||||||||||||||||||
| 59 | 0 | 1; | |||||||||||||||||||||||||||||||||||
| 60 | 0 | ▶ | } or do { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 61 | 0 | ▶ | my $eval_error = $@ || 'Zombie error'; | ||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$@ || 'Zombie error'
MC/DC0%0/1
$@ || 'Zombie error'
$@
Truth table0%0/2
A
A= $@
| |||||||||||||||||||||||||||||||||||||
| 62 | 0 | confess q{server response wasn't valid JSON: } . $eval_error; | |||||||||||||||||||||||||||||||||||
| 63 | }; | ||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||
| 65 | 0 | return $res; | |||||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||
| 68 | 0 | my $headers = $response->headers; | |||||||||||||||||||||||||||||||||||
| 69 | 0 | my $code = $response->code; | |||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||
| 71 | # collect additional error info | ||||||||||||||||||||||||||||||||||||
| 72 | 0 | my @msg; | |||||||||||||||||||||||||||||||||||
| 73 | 0 | ▶ | push @msg, $1 | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 74 | if $content =~ m{\Q<b>description</b>\E\s+<u>(.+?)</u>}xmsi; | ||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||
| 76 | push @msg, $headers->{'oozie-error-message'} | ||||||||||||||||||||||||||||||||||||
| 77 | 0 | ▶ | if $headers->{'oozie-error-message'}; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||
| 79 | 0 | push @msg, eval { require LWP::Authen::Negotiate; 1; } | |||||||||||||||||||||||||||||||||||
| 80 | ? q{(Did you forget to run kinit?)} | ||||||||||||||||||||||||||||||||||||
| 81 | : q{(LWP::Authen::Negotiate doesn't seem available)} | ||||||||||||||||||||||||||||||||||||
| 82 | if $code == 401 | ||||||||||||||||||||||||||||||||||||
| 83 | 0 | ▶ | && ( $headers->{'www-authenticate'} || '' ) eq 'Negotiate'; | ||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/5
$code == 401 and ($headers->{"www-authenticate"} || "") eq "Negotiate"
$headers->{'www-authenticate'} || ''
MC/DC0%0/2
$code == 401 and ($headers->{"www-authenticate"} || "") eq "Negotiate"
$code == 401
$headers->{'www-authenticate'}
Truth table0%0/3
A and B
A= $code == 401B= $headers->{'www-authenticate'}
| |||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||
| 85 | 0 | confess sprintf '%s %s -> %s', "@msg", $response->status_line, $uri; | |||||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||
| 88 | 1 | 1; | |||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||
| 90 | __END__ | ||||||||||||||||||||||||||||||||||||