Oozie/Role/LWP.pm

filter: Statementstmt 50.0% 30 / 60 Branchbran 0.0% 0 / 22 Conditioncond 0.0% 0 / 14 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 90.0% 9 / 10 Podpod 100% 1 / 1 totaltotal 35.0% 40 / 114 CC 18 SCAR 54.3
CC
18
Cov
31%
agent_request
342.0
BEGIN
1.0
BEGIN
1.0
CRAP 228.3
« Oozie/SLA.pm ↑ Summary Oozie/Constants.pm »
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
BranchTrueFalseTotal
if (not $method or $method eq 'get') { } 0 0 0
elsif ($method eq 'post') { } 0 0 0
elsif ($method eq 'put') { } 0 0 0
Condition0%0/3
not $method or $method eq "get"
l!l&&r!l&&!r
000
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"
ABresult
1X1
011
000
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 || ''
l!l
00
MC/DC0%0/1
$response->decoded_content || ''
$response->decoded_content
Truth table0%0/2
A
A= $response->decoded_content
Aresult
11
00
46  
47 0 ▶ if ( $response->is_success ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($response->is_success) 0 0 0
48  
49 0 ▶ return {} if !$content;
Branch: 1 branch
BranchTrueFalseTotal
unless $content 0 0 0
50  
51 0 ▶ my $type = $response->header('content-type') || q{};
Condition0%0/2
$response->header('content-type') || ''
l!l
00
MC/DC0%0/1
$response->header('content-type') || ''
$response->header('content-type')
Truth table0%0/2
A
A= $response->header('content-type')
Aresult
11
00
52  
53 0 ▶ return { response => $content } if index( lc $type, 'json' ) == -1;
Branch: 1 branch
BranchTrueFalseTotal
if index(lc $type, "json") == -1 0 0 0
54  
55 0 my $res;
56  
57 eval {
58 0 $res = $json->decode($content);
59 0 1;
60 0 ▶ } or do {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { $res = $json->decode($content); 1 } } or do { my $eval_error = $@ || "Zombie error"; confess(q[server response wasn't valid JSON: ] . $eval_error) } 0 0 0
61 0 ▶ my $eval_error = $@ || 'Zombie error';
Condition0%0/2
$@ || 'Zombie error'
l!l
00
MC/DC0%0/1
$@ || 'Zombie error'
$@
Truth table0%0/2
A
A= $@
Aresult
11
00
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
BranchTrueFalseTotal
if $content =~ m[\<b\>description\<\/b\>\s+<u>(.+?)</u>]imsx 0 0 0
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
BranchTrueFalseTotal
if $headers->{"oozie-error-message"} 0 0 0
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
BranchTrueFalseTotal
if $code == 401 and ($headers->{"www-authenticate"} || "") eq "Negotiate" 0 0 0
eval { do { require LWP::Authen::Negotiate; 1 } } ? : 0 0 0
Condition0%0/5
$code == 401 and ($headers->{"www-authenticate"} || "") eq "Negotiate"
!ll&&!rl&&r
000
$headers->{'www-authenticate'} || ''
l!l
00
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'}
ABresult
0X0
100
111
84  
85 0 confess sprintf '%s %s -> %s', "@msg", $response->status_line, $uri;
86 }
87  
88 1 1;
89  
90 __END__
« Oozie/SLA.pm ↑ Summary Oozie/Constants.pm »