YARN/Roles/Common.pm

filter: Statementstmt 34.1% 57 / 167 Branchbran 0.0% 0 / 70 Conditioncond 0.0% 0 / 54 MC/DCmcdc 0.0% 0 / 26 Subroutinesub 45.7% 16 / 35 Podpod n/a totaltotal 20.7% 73 / 352 CC 58 SCAR 65.0
CC
58
Cov
20%
_request
1560.0
_check_servers
42.0
__ANON__
20.0
CRAP 667.1
« YARN/ResourceManager/Scheduler/UserApps.pm ↑ Summary YARN/NameNode/JMX.pm »
1 package Net::Hadoop::YARN::Roles::Common;
2 12 $Net::Hadoop::YARN::Roles::Common::VERSION = '0.203';
3 12 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 12 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 12 ▶use 5.10.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 12 ▶use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 12 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 12 ▶use HTTP::Request;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 12 ▶use JSON::XS;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 12 ▶use HTML::PullParser;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 12 ▶use LWP::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 12 ▶use Regexp::Common qw( net );
Subroutine BEGIN: called CC=1 SCAR=0.0
15 12 ▶use Scalar::Util qw( blessed );
Subroutine BEGIN: called CC=1 SCAR=0.0
16 12 ▶use Socket;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 12 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 12 ▶use Text::Trim qw( trim );
Subroutine BEGIN: called CC=1 SCAR=0.0
19 12 ▶use URI;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 12 ▶use XML::LibXML::Simple;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 has no_http_redirect => (
23 is => 'rw',
24 0 ▶ default => sub { 0 },
Subroutine __ANON__: not called CC=1 SCAR=6.9
25 12 lazy => 1,
26 );
27  
28 has _json => (
29 is => 'rw',
30 lazy => 1,
31 0 ▶ default => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
32 0 return JSON::XS->new->pretty(1)->canonical(1);
33 },
34 0 ▶ isa => sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
35 0 my $json = shift;
36 0 ▶ if ( ! blessed $json
Branch: 1 branch
BranchTrueFalseTotal
if (not builtin::blessed($json) && $json->isa("JSON::XS") && $json->can("decode")) 0 0 0
Condition0%0/6
builtin::blessed($json) && $json->isa('JSON::XS') && $json->can('decode')
!ll&&!rl&&r
000
builtin::blessed($json) and $json->isa("JSON::XS")
!ll&&!rl&&r
000
MC/DC0%0/3
builtin::blessed($json) && $json->isa('JSON::XS') && $json->can('decode')
builtin::blessed($json) $json->isa("JSON::XS") $json->can('decode')
Truth table0%0/4
A and B && C
A= builtin::blessed($json)B= $json->isa("JSON::XS")C= $json->can('decode')
ABCresult
0XX0
10X0
1100
1111
37 || ! $json->isa('JSON::XS')
38 || ! $json->can('decode')
39 ) {
40 0 die "Not a JSON object"
41 }
42 },
43 12 );
44  
45 has debug => (
46 is => 'rw',
47 0 ▶ default => sub { $ENV{NET_HADOOP_YARN_DEBUG} || 0 },
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
$ENV{"NET_HADOOP_YARN_DEBUG"} or 0 0 0 0
48 0 ▶ isa => sub { die 'debug should be an integer' if $_[0] !~ /^[0-9]$/ },
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
if not $_[0] =~ /^[0-9]$/ 0 0 0
49 12 lazy => 1,
50 );
51  
52 has ua => (
53 is => 'rw',
54 0 ▶ default => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
55 0 ▶ return LWP::UserAgent->new(
Branch: 1 branch
BranchTrueFalseTotal
$_[0]->no_http_redirect ? : 0 0 0
56 env_proxy => 0,
57 timeout => $_[0]->timeout,
58 ( $_[0]->no_http_redirect ? (
59 max_redirect => 0,
60 ):()),
61 );
62 },
63 0 ▶ isa => sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
64 0 my $ua = shift;
65 0 ▶ if ( ! blessed( $ua ) || ! $ua->isa("LWP::UserAgent") ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not builtin::blessed($ua) && $ua->isa("LWP::UserAgent")) 0 0 0
Condition0%0/3
builtin::blessed($ua) && $ua->isa('LWP::UserAgent')
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($ua) && $ua->isa('LWP::UserAgent')
builtin::blessed($ua) $ua->isa('LWP::UserAgent')
Truth table0%0/3
A && B
A= builtin::blessed($ua)B= $ua->isa('LWP::UserAgent')
ABresult
0X0
100
111
66 0 die "'ua' isn't a LWP::UserAgent";
67 }
68 },
69 12 lazy => 1,
70 );
71  
72 has timeout => (
73 is => 'rw',
74 0 ▶ default => sub {30},
Subroutine __ANON__: not called CC=1 SCAR=6.9
75 lazy => 1,
76 0 ▶ isa => sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
77 0 ▶ if ( $_[0] !~ /^[0-9]+$/ || $_[0] <= 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $_[0] =~ /^[0-9]+$/ or $_[0] <= 0) 0 0 0
Condition0%0/3
not $_[0] =~ /^[0-9]+$/ or $_[0] <= 0
l!l&&r!l&&!r
000
MC/DC0%0/2
not $_[0] =~ /^[0-9]+$/ or $_[0] <= 0
not $_[0] =~ /^[0-9]+$/ $_[0] <= 0
Truth table0%0/3
not(A) or B
A= not $_[0] =~ /^[0-9]+$/B= $_[0] <= 0
ABresult
1X1
011
000
78 0 die "timeout must be an integer"
79 }
80 },
81 12 );
82  
83 has servers => (
84 is => 'rw',
85 0 ▶ isa => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
86 0 ▶ die "Incorrect server list" if ! _check_servers(@_);
Branch: 1 branch
BranchTrueFalseTotal
if not _check_servers(@_) 0 0 0
87 },
88 12 lazy => 1,
89 );
90  
91 has add_host_key => (
92 is => 'rw',
93 0 ▶ default => sub { 0 },
Subroutine __ANON__: not called CC=1 SCAR=6.9
94 12 lazy => 1,
95 );
96  
97 has host_key => (
98 is => 'rw',
99 0 ▶ default => sub { '__RESTHost' },
Subroutine __ANON__: not called CC=1 SCAR=6.9
100 12 lazy => 1,
101 );
102  
103 0 ▶sub _check_host {
Subroutine _check_host: not called CC=3 SCAR=24.8
104 0 my $host = shift;
105 0 return !!( eval { inet_aton($host) }
106 || $host =~ $RE{net}{IPv4}
107 0 ▶ || $host =~ $RE{net}{IPv6} );
Condition0%0/6
eval { do { inet_aton($host) } } || $host =~ /$Net::Hadoop::YARN::Roles::Common::RE{'net'}{'IPv4'}/ || $host =~ /$Net::Hadoop::YARN::Roles::Common::RE{'net'}{'IPv6'}/
l!l&&r!l&&!r
000
eval { do { inet_aton($host) } } or $host =~ /$Net::Hadoop::YARN::Roles::Common::RE{"net"}{"IPv4"}/
l!l&&r!l&&!r
000
MC/DC0%0/3
eval { do { inet_aton($host) } } || $host =~ /$Net::Hadoop::YARN::Roles::Common::RE{'net'}{'IPv4'}/ || $host =~ /$Net::Hadoop::YARN::Roles::Common::RE{'net'}{'IPv6'}/
eval { do { inet_aton($host) } } $host =~ /$Net::Hadoop::YARN::Roles::Common::RE{"net"}{"IPv4"}/ $host =~ /$Net::Hadoop::YARN::Roles::Common::RE{'net'}{'IPv6'}/
Truth table0%0/4
A or B || C
A= eval { do { inet_aton($host) } }B= $host =~ /$Net::Hadoop::YARN::Roles::Common::RE{"net"}{"IPv4"}/C= $host =~ /$Net::Hadoop::YARN::Roles::Common::RE{'net'}{'IPv6'}/
ABCresult
1XX1
01X1
0011
0000
108 }
109  
110 0 ▶sub _check_servers {
Subroutine _check_servers: not called CC=6 SCAR=37.4
111 0 for my $server (@{+shift}) {
112 0 my ($host, $port) = split /:/, $server, 2;
113 0 ▶ if ( ! _check_host($host)
Branch: 1 branch
BranchTrueFalseTotal
if (not _check_host($host) && $port =~ /^[0-9]+$/ or $port < 1 or $port > 19888) 0 0 0
Condition0%0/9
not _check_host($host) && $port =~ /^[0-9]+$/ or $port < 1 or $port > 19888
l!l&&r!l&&!r
000
not _check_host($host) && $port =~ /^[0-9]+$/ or $port < 1
l!l&&r!l&&!r
000
_check_host($host) && $port =~ /^[0-9]+$/
!ll&&!rl&&r
000
MC/DC0%0/4
not _check_host($host) && $port =~ /^[0-9]+$/ or $port < 1 or $port > 19888
_check_host($host) $port =~ /^[0-9]+$/ $port < 1 $port > 19888
Truth table0%0/5
not(A && B) or C or D
A= _check_host($host)B= $port =~ /^[0-9]+$/C= $port < 1D= $port > 19888
ABCDresult
0XXX1
10XX1
111X1
11011
11000
114 || $port !~ /^[0-9]+$/
115 || $port < 1
116 || $port > 19888
117 ) {
118 0 die "server $server bad host (port=$port)";
119 }
120 }
121 0 return 1;
122 }
123  
124 0 ▶sub _mk_uri {
Subroutine _mk_uri: not called CC=2 SCAR=17.9
125 0 my $self = shift;
126 0 my ( $server, $path, $params ) = @_;
127 0 my $uri = $server . "/ws/v1/" . $path;
128 0 $uri =~ s#//+#/#g;
129 0 $uri = URI->new("http://" . $uri);
130 0 ▶ if ( $params ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($params) 0 0 0
131 0 $uri->query_form($params);
132 }
133 0 return $uri;
134 }
135  
136 # http://hadoop.apache.org/docs/r2.2.0/hadoop-yarn/hadoop-yarn-site/WebServicesIntro.html
137  
138 0 ▶sub _get {
Subroutine _get: not called CC=1 SCAR=6.9
139 0 shift->_request( 'GET', @_ );
140 }
141  
142 0 ▶sub _put {
Subroutine _put: not called CC=1 SCAR=6.9
143 0 shift->_request( 'PUT', @_ );
144 }
145  
146 0 ▶sub _post {
Subroutine _post: not called CC=1 SCAR=6.9
147 0 shift->_request( 'POST', @_ );
148 }
149  
150 0 ▶sub _request {
Subroutine _request: not called CC=39 SCAR=73.5
151 0 my $self = shift;
152 0 my ( $method, $path, $extra, $server ) = @_;
153  
154 0 my $host_key = $self->host_key;
155 0 ▶ my @servers = $server ? ( $server ) : @{ $self->servers };
Branch: 1 branch
BranchTrueFalseTotal
$server ? : 0 0 0
156 0 my $maxtries = @servers;
157  
158 0 my ($eval_error, $ret);
159 0 my $n = 0;
160  
161 # get a copy, don't mess with the global setting
162 #
163 0 my @banned_servers;
164 my $selected_server;
165  
166 0 my $e_non_html = "Response doesn't look like XML: ";
167  
168 0 ▶ TRY: while ( $n < $maxtries ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n < $maxtries) 0 0 0
169 0 my $redo;
170  
171 0 $n++;
172  
173 0 ▶ if ( ! @servers ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@servers) 0 0 0
174 0 ▶ $eval_error = sprintf "No servers left in the queue. Banned servers: '%s'",
Branch: 1 branch
BranchTrueFalseTotal
@banned_servers ? : 0 0 0
175 @banned_servers
176 ? join( q{', '}, @banned_servers)
177 : '[none]',
178 ;
179 0 last TRY;
180 }
181  
182 0 $selected_server = $servers[0];
183 eval {
184 0 $eval_error = undef;
185  
186 my $uri = $self->_mk_uri(
187 $selected_server,
188 $path,
189 0 ▶ $method eq 'GET' ? $extra->{params} : (),
Branch: 1 branch
BranchTrueFalseTotal
$method eq 'GET' ? : 0 0 0
190 );
191  
192 0 ▶ print STDERR "====> $uri\n" if $self->debug;
Branch: 1 branch
BranchTrueFalseTotal
if $self->debug 0 0 0
193  
194 0 my $req = HTTP::Request->new( uc($method), $uri );
195 0 $req->header( "Accept-Encoding", "gzip" );
196 #$req->header( "Accept", "application/json" );
197 0 $req->header( "Accept", "application/xml" );
198  
199 0 my $response = $self->ua->request($req);
200  
201 0 ▶ if ( $response->code == 500 ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($response->code == 500) { } 0 0 0
elsif ($response->code == 401) { } 0 0 0
202 0 die "Bad request: $uri";
203 } elsif ( $response->code == 401 ) {
204 my $extramsg = ( $response->headers->{'www-authenticate'} || '' ) eq 'Negotiate'
205 0 ▶ ? eval { require LWP::Authen::Negotiate; 1; }
Branch: 2 branches
BranchTrueFalseTotal
($response->headers->{'www-authenticate'} || '') eq 'Negotiate' ? : 0 0 0
eval { do { require LWP::Authen::Negotiate; 1 } } ? : 0 0 0
Condition0%0/2
$response->headers->{'www-authenticate'} || ''
l!l
00
MC/DC0%0/1
$response->headers->{'www-authenticate'} || ''
$response->headers->{'www-authenticate'}
Truth table0%0/2
A
A= $response->headers->{'www-authenticate'}
Aresult
11
00
206 ? q{ (Did you forget to run kinit?) }
207 : q{ (LWP::Authen::Negotiate doesn't seem available) }
208 : '';
209 0 croak "SecurityError$extramsg";
210 }
211  
212 # found out the json support is buggy at least in the scheduler
213 # info (overwrites child queues instead of making a list), revert
214 # to XML (see YARN-2336)
215  
216 0 my $res;
217 eval {
218 0 ▶ my $content = $response->decoded_content
Condition0%0/2
$response->decoded_content || die('No response from the server!')
l!l
00
MC/DC0%0/1
$response->decoded_content || die('No response from the server!')
$response->decoded_content
Truth table0%0/2
A
A= $response->decoded_content
Aresult
11
00
219 || die 'No response from the server!';
220  
221 0 ▶ if ( $content !~ m{ \A ( \s+ )? <[?]xml }xms ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($content =~ / \A ( \s+ )? <[?]xml /msx) 0 0 0
222 0 ▶ if ( $content =~ m{
Branch: 1 branch
BranchTrueFalseTotal
if ($content =~ / This\ is\ standby\ RM\.\ Redirecting\ to\ the\ current\ active\ RM /msx) 0 0 0
223 \QThis is standby RM. Redirecting to the current active RM\E
224 }xms ) {
225 0 push @banned_servers, shift @servers;
226 0 $redo++;
227 0 die "Hit the standby with $selected_server";
228 }
229 0 die $e_non_html . $content;
230 }
231  
232 0 ▶ $res = XMLin(
Condition0%0/2
XMLin($content, 'KeepRoot', 0, 'KeyAttr', scalar [], 'ForceArray', ['app', 'appAttempt', 'container', 'counterGroup', 'job', 'jobAttempt', 'task', 'taskAttempt']) || die('Failed to parse XML!')
l!l
00
MC/DC0%0/1
XMLin($content, 'KeepRoot', 0, 'KeyAttr', scalar [], 'ForceArray', ['app', 'appAttempt', 'container', 'counterGroup', 'job', 'jobAttempt', 'task', 'taskAttempt']) || die('Failed to parse XML!')
XMLin($content, 'KeepRoot', 0, 'KeyAttr', scalar [], 'ForceArray', ['app', 'appAttempt', 'container', 'counterGroup', 'job', 'jobAttempt', 'task', 'taskAttempt'])
Truth table0%0/2
A
A= XMLin($content, 'KeepRoot', 0, 'KeyAttr', scalar [], 'ForceArray', ['app', 'appAttempt', 'container', 'counterGroup', 'job', 'jobAttempt', 'task', 'taskAttempt'])
Aresult
11
00
233 $content,
234 KeepRoot => 0,
235 KeyAttr => [],
236 ForceArray => [qw(
237 app
238 appAttempt
239 container
240 counterGroup
241 job
242 jobAttempt
243 task
244 taskAttempt
245 )],
246 ) || die "Failed to parse XML!";
247 0 1;
248 0 ▶ } or do {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { my $content = $response->decoded_content || die("No response from the server!"); unless ($content =~ / \A ( \s+ )? <[?]xml /msx) { if ($content =~ / This\ is\ standby\ RM\.\ Redirecting\ to\ the\ current\ active\ RM /msx) { push @banned_servers, shift @servers; ++$redo; die "Hit the standby with $selected_server"; } ; die $e_non_html . $content; } ; $res = XMLin($content, "KeepRoot", 0, "KeyAttr", scalar [], "ForceArray", ["app", "appAttempt", "container", "counterGroup", "job", "jobAttempt", "task", "taskAttempt"]) || die("Failed to parse XML!"); 1 } } or do { my $is_html = $response->content_type eq "text/html"; my $decode_error = $@ || "Zombie error"; if ($is_html) { (my $str_to_parse = $decode_error) =~ s/ \Q$e_non_html\E //msx; my $parser = "HTML::PullParser"->new("doc", \$str_to_parse, "text", "dtext") || Carp::confess("Can't parse HTML received from the API: $!"); my(%link, @txt_error); while (my $token = $parser->get_token) { do { my $txt = trim($token->[0]) or next; push @txt_error, $txt }; } ; $decode_error = 'Decoded error: ' . join(" ", @txt_error); } ; my $will_fail_again = $decode_error =~ / could\ not\ be\ found\,\ please\ try\ the\ history\ server /msx; $n = $maxtries if $will_fail_again; my $msg = $response->redirects ? "server response wasn't valid (possibly buggy redirect to HTML instead of JSON or XML)" : "server response wasn't valid JSON or XML"; die "$msg - $uri ($n/$maxtries): $decode_error" } 0 0 0
249 0 my $is_html = $response->content_type eq 'text/html';
250 0 ▶ my $decode_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
251  
252 0 ▶ if ( $is_html ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_html) 0 0 0
253 0 (my $str_to_parse = $decode_error) =~ s{ \Q$e_non_html\E }{}xms;
254 0 ▶ my $parser = HTML::PullParser->new(
Condition0%0/2
'HTML::PullParser'->new('doc', \$str_to_parse, 'text', 'dtext') || Carp::confess("Can't parse HTML received from the API: $!")
l!l
00
MC/DC0%0/1
'HTML::PullParser'->new('doc', \$str_to_parse, 'text', 'dtext') || Carp::confess("Can't parse HTML received from the API: $!")
'HTML::PullParser'->new('doc', \$str_to_parse, 'text', 'dtext')
Truth table0%0/2
A
A= 'HTML::PullParser'->new('doc', \$str_to_parse, 'text', 'dtext')
Aresult
11
00
255 doc => \$str_to_parse,
256 text => 'dtext',
257 ) || Carp::confess "Can't parse HTML received from the API: $!";
258 0 my %link;
259 my @txt_error;
260 0 ▶ while ( my $token = $parser->get_token ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $token = $parser->get_token) 0 0 0
261 0 ▶ my $txt = trim $token->[0] or next;
Branch: 1 branch
BranchTrueFalseTotal
my $txt = trim($token->[0]) or next 0 0 0
262 0 push @txt_error, $txt;
263 }
264 0 $decode_error = 'Decoded error: ' . join q{ }, @txt_error;
265 };
266  
267 0 my $will_fail_again = $decode_error =~ m{
268 \Qcould not be found, please try the history server\E
269 }xms;
270  
271 0 ▶ $n = $maxtries if $will_fail_again;
Branch: 1 branch
BranchTrueFalseTotal
if $will_fail_again 0 0 0
272  
273 # when redirected to the history server, a bug present in hadoop 2.5.1
274 # sends to an HTML page, ignoring the Accept-Type header
275 0 ▶ my $msg = $response->redirects
Branch: 1 branch
BranchTrueFalseTotal
$response->redirects ? : 0 0 0
276 ? q{server response wasn't valid (possibly buggy redirect to HTML instead of JSON or XML)}
277 : q{server response wasn't valid JSON or XML}
278 ;
279  
280 0 die "$msg - $uri ($n/$maxtries): $decode_error";
281 };
282  
283 0 ▶ print STDERR Dumper $res if $self->debug;
Branch: 1 branch
BranchTrueFalseTotal
if $self->debug 0 0 0
284  
285 0 ▶ if ( $response->is_success ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($response->is_success) 0 0 0
286 0 $ret = $res;
287 0 return 1;
288 }
289  
290 0 my $e = $res->{RemoteException};
291  
292 die sprintf "%s (%s in %s) for URI: %s",
293 $e->{message} || $res->{message} || '[unknown message]',
294 $e->{exception} || $res->{exception} || '[unknown exception]',
295 0 ▶ $e->{javaClassName} || $res->{javaClassName} || '[unknown javaClassName]',
Condition0%0/15
$e->{'message'} || $res->{'message'} || '[unknown message]'
l!l
00
$e->{"message"} or $res->{"message"}
l!l&&r!l&&!r
000
$e->{'exception'} || $res->{'exception'} || '[unknown exception]'
l!l
00
$e->{"exception"} or $res->{"exception"}
l!l&&r!l&&!r
000
$e->{'javaClassName'} || $res->{'javaClassName'} || '[unknown javaClassName]'
l!l
00
$e->{"javaClassName"} or $res->{"javaClassName"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$e->{'message'} || $res->{'message'} || '[unknown message]'
$e->{"message"} $res->{"message"}
MC/DC0%0/2
$e->{'exception'} || $res->{'exception'} || '[unknown exception]'
$e->{"exception"} $res->{"exception"}
MC/DC0%0/2
$e->{'javaClassName'} || $res->{'javaClassName'} || '[unknown javaClassName]'
$e->{"javaClassName"} $res->{"javaClassName"}
Truth table0%0/3
A or B
A= $e->{"message"}B= $res->{"message"}
ABresult
1X1
011
000
Truth table0%0/3
A or B
A= $e->{"exception"}B= $res->{"exception"}
ABresult
1X1
011
000
Truth table0%0/3
A or B
A= $e->{"javaClassName"}B= $res->{"javaClassName"}
ABresult
1X1
011
000
296 $uri,
297 ;
298  
299 0 1;
300 0 ▶ } or do {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { $eval_error = undef; my $uri = $self->_mk_uri($selected_server, $path, $method eq "GET" ? $extra->{"params"} : ()); print STDERR "====> $uri\n" if $self->debug; my $req = "HTTP::Request"->new(uc $method, $uri); $req->header("Accept-Encoding", "gzip"); $req->header("Accept", "application/xml"); my $response = $self->ua->request($req); if ($response->code == 500) { die "Bad request: $uri"; } elsif ($response->code == 401) { my $extramsg = ($response->headers->{"www-authenticate"} || "") eq "Negotiate" ? eval { do { require LWP::Authen::Negotiate; 1 } } ? " (Did you forget to run kinit?) " : " (LWP::Authen::Negotiate doesn't seem available) " : ""; croak("SecurityError$extramsg"); } ; my $res; eval { do { my $content = $response->decoded_content || die("No response from the server!"); unless ($content =~ / \A ( \s+ )? <[?]xml /msx) { if ($content =~ / This\ is\ standby\ RM\.\ Redirecting\ to\ the\ current\ active\ RM /msx) { push @banned_servers, shift @servers; ++$redo; die "Hit the standby with $selected_server"; } ; die $e_non_html . $content; } ; $res = XMLin($content, "KeepRoot", 0, "KeyAttr", scalar [], "ForceArray", ["app", "appAttempt", "container", "counterGroup", "job", "jobAttempt", "task", "taskAttempt"]) || die("Failed to parse XML!"); 1 } } or do { my $is_html = $response->content_type eq "text/html"; my $decode_error = $@ || "Zombie error"; if ($is_html) { (my $str_to_parse = $decode_error) =~ s/ \Q$e_non_html\E //msx; my $parser = "HTML::PullParser"->new("doc", \$str_to_parse, "text", "dtext") || Carp::confess("Can't parse HTML received from the API: $!"); my(%link, @txt_error); while (my $token = $parser->get_token) { do { my $txt = trim($token->[0]) or next; push @txt_error, $txt }; } ; $decode_error = 'Decoded error: ' . join(" ", @txt_error); } ; my $will_fail_again = $decode_error =~ / could\ not\ be\ found\,\ please\ try\ the\ history\ server /msx; $n = $maxtries if $will_fail_again; my $msg = $response->redirects ? "server response wasn't valid (possibly buggy redirect to HTML instead of JSON or XML)" : "server response wasn't valid JSON or XML"; die "$msg - $uri ($n/$maxtries): $decode_error" }; print STDERR Dumper($res) if $self->debug; if ($response->is_success) { $ret = $res; return 1; } ; my $e = $res->{"RemoteException"}; die sprintf("%s (%s in %s) for URI: %s", $e->{"message"} || $res->{"message"} || "[unknown message]", $e->{"exception"} || $res->{"exception"} || "[unknown exception]", $e->{"javaClassName"} || $res->{"javaClassName"} || "[unknown javaClassName]", $uri); 1 } } or do { $eval_error = $@ || "Zombie error"; redo TRY if $redo; push @servers, shift @servers if @servers > 1 } 0 0 0
301 # store the error for later; will be displayed if this is the last
302 # iteration. also use the next server in the list in case of retry,
303 # or reset the list for the next call (we went a full circle)
304 0 ▶ $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
305 0 ▶ redo TRY if $redo;
Branch: 1 branch
BranchTrueFalseTotal
if $redo 0 0 0
306 0 ▶ push @servers, shift @servers if @servers > 1;
Branch: 1 branch
BranchTrueFalseTotal
if @servers > 1 0 0 0
307 };
308  
309 0 ▶ if ( $ret ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ret) 0 0 0
310 0 ▶ if ( $self->add_host_key ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->add_host_key) 0 0 0
311 # mark where we've been
312 0 $ret->{ $host_key } = $selected_server;
313 }
314 0 last TRY;
315 }
316  
317 } # retry as many times as there are servers
318  
319 0 ▶ if ( $eval_error ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($eval_error) 0 0 0
320 0 die "Final error ($n/$maxtries): $eval_error";
321 }
322  
323 0 return $ret;
324 }
325  
326 12 1;
327  
328 __END__
« YARN/ResourceManager/Scheduler/UserApps.pm ↑ Summary YARN/NameNode/JMX.pm »