YARN/ApplicationMaster.pm

filter: Statementstmt 44.1% 53 / 120 Branchbran 0.0% 0 / 20 Conditioncond 0.0% 0 / 28 MC/DCmcdc 0.0% 0 / 15 Subroutinesub 59.0% 13 / 22 Podpod 100% 3 / 3 totaltotal 33.1% 69 / 208 CC 26 SCAR 39.1
CC
26
Cov
32%
_collect_from_history
132.0
_extract_ids_from_error_html
72.0
__ANON__
37.5
CRAP 50.1
« YARN/Roles/AppMasterHistoryServer.pm ↑ Summary YARN/ResourceManager.pm »
1 package Net::Hadoop::YARN::ApplicationMaster;
2 3 $Net::Hadoop::YARN::ApplicationMaster::VERSION = '0.203';
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use 5.10.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 3 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 RE_ARCHIVED_ERROR => qr{
9 Application .+?
10 \Qcould not be found, please try the history server\E
11 }xms,
12 3 };
13  
14 3 ▶use Constant::FromGlobal DEBUG => { int => 1, default => 0, env => 1 };
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 3 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
17 3 ▶use Clone ();
Subroutine BEGIN: called CC=1 SCAR=0.0
18 3 ▶use HTML::PullParser;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 3 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 3 ▶use Ref::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
21 3 ▶use Scalar::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 3 ▶use Net::Hadoop::YARN::HistoryServer;
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 3 with 'Net::Hadoop::YARN::Roles::AppMasterHistoryServer';
26 3 with 'Net::Hadoop::YARN::Roles::Common';
27  
28 has '+servers' => (
29 0 ▶ default => sub {["localhost:8088"]},
Subroutine __ANON__: not called CC=1 SCAR=6.9
30 3 );
31  
32 has history_object => (
33 is => 'rw',
34 0 ▶ isa => sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
35 0 ▶ my $o = shift || return; # this is optional
Condition0%0/2
shift() || (return)
l!l
00
MC/DC0%0/1
shift() || (return)
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
36 0 ▶ if ( ! Scalar::Util::blessed $o
Branch: 1 branch
BranchTrueFalseTotal
if (not builtin::blessed($o) && $o->isa("Net::Hadoop::YARN::HistoryServer")) 0 0 0
Condition0%0/3
builtin::blessed($o) && $o->isa('Net::Hadoop::YARN::HistoryServer')
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($o) && $o->isa('Net::Hadoop::YARN::HistoryServer')
builtin::blessed($o) $o->isa('Net::Hadoop::YARN::HistoryServer')
Truth table0%0/3
A && B
A= builtin::blessed($o)B= $o->isa('Net::Hadoop::YARN::HistoryServer')
ABresult
0X0
100
111
37 || ! $o->isa('Net::Hadoop::YARN::HistoryServer')
38 ) {
39 0 Carp::confess "$o is not a Net::Hadoop::YARN::HistoryServer";
40 }
41 },
42 lazy => 1,
43 0 ▶ default => sub { },
Subroutine __ANON__: not called CC=1 SCAR=0.0
44 3 );
45  
46 3 my $PREFIX = '_' x 4;
47  
48 #<<<
49 3 my $methods_urls = {
50 jobs => ['/proxy/{appid}/ws/v1/mapreduce/jobs', 'job' ],
51 job => ['/proxy/{appid}/ws/v1/mapreduce/jobs/{jobid}', '' ],
52 jobconf => ['/proxy/{appid}/ws/v1/mapreduce/jobs/{jobid}/conf', '' ],
53 jobcounters => ['/proxy/{appid}/ws/v1/mapreduce/jobs/{jobid}/counters', 'counterGroup' ],
54 jobattempts => ['/proxy/{appid}/ws/v1/mapreduce/jobs/{jobid}/jobattempts', 'jobAttempt' ],
55 _get_tasks => ['/proxy/{appid}/ws/v1/mapreduce/jobs/{jobid}/tasks', 'task' ],
56 task => ['/proxy/{appid}/ws/v1/mapreduce/jobs/{jobid}/tasks/{taskid}', '' ],
57 taskcounters => ['/proxy/{appid}/ws/v1/mapreduce/jobs/{jobid}/tasks/{taskid}/counters', 'taskCounterGroup' ],
58 taskattempts => ['/proxy/{appid}/ws/v1/mapreduce/jobs/{jobid}/tasks/{taskid}/attempts', 'taskAttempt' ],
59 taskattempt => ['/proxy/{appid}/ws/v1/mapreduce/jobs/{jobid}/tasks/{taskid}/attempts/{attemptid}', '' ],
60 taskattemptcounters => ['/proxy/{appid}/ws/v1/mapreduce/jobs/{jobid}/tasks/{taskid}/attempts/{attemptid}/counters', 'taskAttemptCounterGroup' ],
61 };
62 #>>>
63  
64 # For each of the keys, at startup:
65 # - make a method, adding the path
66 # - pass the path and variables to a validation and substitution engine
67 # - execute the request
68 # - return the proper fragment of the JSON tree
69  
70 3 _mk_subs($methods_urls, { prefix => $PREFIX } );
71  
72 3 my %app_to_hist = (
73 jobs => [ job => qr{ \A job_[0-9]+ }xms ],
74 );
75  
76 3 foreach my $name ( keys %{ $methods_urls } ) {
77 33 my $base = $PREFIX . $name;
78 3 ▶ no strict qw( refs );
Subroutine BEGIN: called CC=1 SCAR=0.0
79 33 ▶ *{ $name } = sub {
Subroutine __ANON__: not called CC=6 SCAR=36.2
80 0 my $self = shift;
81 0 my $args = Clone::clone( \@_ );
82 0 my @rv;
83  
84 eval {
85 0 @rv = $self->$base( @_ );
86 0 1;
87 0 ▶ } or do {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { @rv = $self->$base(@_); 1 } } or do { my $eval_error = $@ || "Zombie error"; if ($eval_error =~ / Application .+? could\ not\ be\ found\,\ please\ try\ the\ history\ server /msx and $self->history_object) { @rv = $self->_collect_from_history($args, $name, $eval_error); } else { Carp::confess($eval_error); } } 0 0 0
88 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
89 0 ▶ if ( $eval_error =~ RE_ARCHIVED_ERROR && $self->history_object ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($eval_error =~ / Application .+? could\ not\ be\ found\,\ please\ try\ the\ history\ server /msx and $self->history_object) { } 0 0 0
Condition0%0/3
$eval_error =~ / Application .+? could\ not\ be\ found\,\ please\ try\ the\ history\ server /msx and $self->history_object
!ll&&!rl&&r
000
MC/DC0%0/2
$eval_error =~ / Application .+? could\ not\ be\ found\,\ please\ try\ the\ history\ server /msx and $self->history_object
$eval_error =~ / Application .+? could\ not\ be\ found\,\ please\ try\ the\ history\ server /msx $self->history_object
Truth table0%0/3
A and B
A= $eval_error =~ / Application .+? could\ not\ be\ found\,\ please\ try\ the\ history\ server /msxB= $self->history_object
ABresult
0X0
100
111
90 0 @rv = $self->_collect_from_history(
91 $args,
92 $name,
93 $eval_error,
94 );
95 }
96 else {
97 0 Carp::confess $eval_error;
98 }
99 };
100  
101 0 ▶ return wantarray ? @rv : $rv[0];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
102 33 };
103 }
104  
105 0 ▶sub _collect_from_history {
Subroutine _collect_from_history: not called CC=11 SCAR=48.8
106 0 my $self = shift;
107 0 my $args = shift;
108 0 my $name = shift;
109 0 ▶ my $error = shift || Carp::confess "No error message specified!";
Condition0%0/2
shift() || Carp::confess('No error message specified!')
l!l
00
MC/DC0%0/1
shift() || Carp::confess('No error message specified!')
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
110  
111 0 ▶ my $hist_method = $app_to_hist{ $name } || [ $name ];
Condition0%0/2
$app_to_hist{$name} || [$name]
l!l
00
MC/DC0%0/1
$app_to_hist{$name} || [$name]
$app_to_hist{$name}
Truth table0%0/2
A
A= $app_to_hist{$name}
Aresult
11
00
112 0 my($hmethod, $hregex) = @{ $hist_method };
113  
114 0 if ( DEBUG ) {
115 print STDERR "Received HTML from the API. ",
116 "I will now attempt to collect the information from the history server\n";
117 printf STDERR "The error was: %s\n", $error
118 if DEBUG > 1;
119 }
120  
121 0 my @hist_param;
122 0 ▶ if ( $error =~ RE_ARCHIVED_ERROR && ( $name eq 'jobs' || $name eq 'job' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($error =~ / Application .+? could\ not\ be\ found\,\ please\ try\ the\ history\ server /msx and $name eq 'jobs' || $name eq 'job') { } 0 0 0
Condition0%0/6
$error =~ / Application .+? could\ not\ be\ found\,\ please\ try\ the\ history\ server /msx and $name eq "jobs" || $name eq "job"
!ll&&!rl&&r
000
$name eq "jobs" or $name eq "job"
l!l&&r!l&&!r
000
MC/DC0%0/3
$error =~ / Application .+? could\ not\ be\ found\,\ please\ try\ the\ history\ server /msx and $name eq "jobs" || $name eq "job"
$error =~ / Application .+? could\ not\ be\ found\,\ please\ try\ the\ history\ server /msx $name eq "jobs" $name eq "job"
Truth table0%0/4
A and B or C
A= $error =~ / Application .+? could\ not\ be\ found\,\ please\ try\ the\ history\ server /msxB= $name eq "jobs"C= $name eq "job"
ABCresult
0XX0
1000
11X1
1011
123 0 print STDERR "Job was archived\n" if DEBUG;
124 @hist_param = (
125 map {
126 0 (my $c = $_) =~ s{ \bapplication_ }{job_}xms;
127 0 $c;
128 0 } @{ $args }
129 );
130 }
131 else {
132 0 print STDERR "Job was not available from he RM\n" if DEBUG;
133 @hist_param = (
134 $hregex
135 0 ▶ ? grep { $_ =~ $hregex }
Branch: 1 branch
BranchTrueFalseTotal
$hregex ? : 0 0 0
136 $self->_extract_ids_from_error_html( $error )
137 : ()
138 );
139 }
140  
141 0 my @rv;
142 eval {
143 0 @rv = $self->history_object->$hmethod( @hist_param );
144 0 1;
145 0 ▶ } or do {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { @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") } 0 0 0
146 0 ▶ my $eval_error_hist = $@ || '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
147 0 Carp::confess "Received HTML from the API and attempting to map that to a historical job failed: $error\n$eval_error_hist\n";
148 };
149  
150 0 foreach my $thing ( @rv ) {
151 0 ▶ next if ! Ref::Util::is_hashref $thing;
Branch: 1 branch
BranchTrueFalseTotal
unless Ref::Util::XS::is_hashref($thing) 0 0 0
152 0 $thing->{__from_history} = 1;
153 }
154  
155 0 return @rv;
156 }
157  
158 0 ▶sub _extract_ids_from_error_html {
Subroutine _extract_ids_from_error_html: not called CC=8 SCAR=42.8
159 0 my $self = shift;
160 0 ▶ my $error = shift || Carp::confess "No error message specified!";
Condition0%0/2
shift() || Carp::confess('No error message specified!')
l!l
00
MC/DC0%0/1
shift() || Carp::confess('No error message specified!')
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
161 0 my(undef, $html) = split m{\Q<!DOCTYPE\E}xms, $error, 2;
162 0 $html = '<!DOCTYPE' . $html;
163 0 ▶ my $parser = HTML::PullParser->new(
Condition0%0/2
'HTML::PullParser'->new('doc', \$html, 'start', 'event, tagname, @attr', 'report_tags', ['a']) || Carp::confess("Can't parse HTML received from the API: $!")
l!l
00
MC/DC0%0/1
'HTML::PullParser'->new('doc', \$html, 'start', 'event, tagname, @attr', 'report_tags', ['a']) || Carp::confess("Can't parse HTML received from the API: $!")
'HTML::PullParser'->new('doc', \$html, 'start', 'event, tagname, @attr', 'report_tags', ['a'])
Truth table0%0/2
A
A= 'HTML::PullParser'->new('doc', \$html, 'start', 'event, tagname, @attr', 'report_tags', ['a'])
Aresult
11
00
164 doc => \$html,
165 start => 'event, tagname, @attr',
166 report_tags => [qw( a )],
167 ) || Carp::confess "Can't parse HTML received from the API: $!";
168 0 my %link;
169 0 ▶ while ( my $token = $parser->get_token ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $token = $parser->get_token) 0 0 0
170 0 ▶ next if $token->[0] ne 'start';
Branch: 1 branch
BranchTrueFalseTotal
if $token->[0] ne "start" 0 0 0
171 0 my($type, $tag, %attr) = @{ $token };
172 0 ▶ my $link = $attr{href} || next;
Condition0%0/2
$attr{'href'} || (next)
l!l
00
MC/DC0%0/1
$attr{'href'} || (next)
$attr{'href'}
Truth table0%0/2
A
A= $attr{'href'}
Aresult
11
00
173 0 $link{ $link }++;
174 }
175 0 my %id;
176 0 for my $link ( keys %link ) {
177 0 $id{ $_ }++ for $self->_extract_valid_params( $link );
178 }
179 0 return keys %id;
180 }
181  
182 0 ▶sub info {
Subroutine info: not called CC=1 SCAR=6.9
Pod documented
183 0 my $self = shift;
184 0 $self->mapreduce(@_);
185 }
186  
187 0 ▶sub mapreduce {
Subroutine mapreduce: not called CC=1 SCAR=6.9
Pod documented
188 0 my $self = shift;
189 0 my $app_id = shift;
190 0 my $res = $self->_get("{appid}/ws/v1/mapreduce/info");
191 0 return $res->{info};
192 }
193  
194 0 ▶sub tasks {
Subroutine tasks: not called CC=1 SCAR=6.9
Pod documented
195 0 my $self = shift;
196 0 $self->_get_tasks(@_);
197 }
198  
199 3 1;
200  
201 __END__
« YARN/Roles/AppMasterHistoryServer.pm ↑ Summary YARN/ResourceManager.pm »