YARN/ResourceManager.pm

filter: Statementstmt 25.7% 26 / 101 Branchbran 0.0% 0 / 44 Conditioncond 0.0% 0 / 41 MC/DCmcdc 0.0% 0 / 24 Subroutinesub 36.8% 7 / 19 Podpod 100% 8 / 8 totaltotal 17.3% 41 / 237 CC 39 SCAR 36.3
CC
39
Cov
14%
active_rm
56.0
apps
56.0
appstatistics
56.0
CRAP 37.8
« YARN/ApplicationMaster.pm ↑ Summary YARN/DataNode/JMX.pm »
1 package Net::Hadoop::YARN::ResourceManager;
2 7 $Net::Hadoop::YARN::ResourceManager::VERSION = '0.203';
3 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 7 ▶use 5.10.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 7 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 7 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 7 ▶use Ref::Util qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
10 is_ref
11 is_arrayref
12 is_hashref
13 7 );
14 7 ▶use Scalar::Util qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
15 refaddr
16 7 );
17  
18 7 with 'Net::Hadoop::YARN::Roles::Common';
19  
20 has '+servers' => (
21 0 ▶ default => sub { ["localhost:8088"] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
22 7 );
23  
24 0 ▶has '+add_host_key' => ( default => sub { 1 } );
Subroutine __ANON__: not called CC=1 SCAR=1.2
25  
26 # After CDH 5.8.2, The RM properly issues a 302 redirect, but losing any query
27 # string in the original request, thus making the filters and any other parameter
28 # a no-op and returning huge responses including "everything" instead of a subset.
29 #
30 # eg: { queue: "root.whatever" } filter will be lost after the redirect.
31 #
32 # We can't use active_rm() in here or in the Common role, as it will trigger a
33 # deep recursion due to the fact that the HTTP calls are shared from there.
34 #
35 # Possibly needs to be revisited again in the future.
36 #
37 0 ▶has '+no_http_redirect' => ( default => sub { 1 } );
Subroutine __ANON__: not called CC=1 SCAR=1.2
38  
39 0 ▶sub active_rm {
Subroutine active_rm: not called CC=7 SCAR=40.3
Pod documented
40 0 my $self = shift;
41 0 ▶ my $opt = is_hashref $_[0] ? shift @_ : {};
Branch: 1 branch
BranchTrueFalseTotal
is_hashref($_[0]) ? : 0 0 0
42 0 my $rv;
43  
44 0 foreach my $server ( @{ $self->servers } ) {
45 0 my $info = $self->info({ server => $server });
46 0 ▶ my $haState = $info->{haState} || next;
Condition0%0/2
$info->{'haState'} || (next)
l!l
00
MC/DC0%0/1
$info->{'haState'} || (next)
$info->{'haState'}
Truth table0%0/2
A
A= $info->{'haState'}
Aresult
11
00
47 0 ▶ if ( $haState eq 'ACTIVE' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($haState eq "ACTIVE") 0 0 0
48 0 $rv = $server;
49 0 last;
50 }
51 }
52  
53 0 ▶ if ( ! $rv ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($rv) 0 0 0
54 die sprintf "Failed to locate the active YARN Resource Manager from these hosts: %s",
55 0 join( q{, }, @{ $self->servers } ),
56 ;
57 }
58  
59 0 ▶ if ( $opt->{hostname_only} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt->{"hostname_only"}) 0 0 0
60 0 return +( split m{[:]}xms, $rv )[0];
61 }
62  
63 0 return $rv;
64 }
65  
66 0 ▶sub info {
Subroutine info: not called CC=4 SCAR=30.0
Pod documented
67 0 my $self = shift;
68 0 ▶ my $opt = is_hashref $_[0] ? shift @_ : {};
Branch: 1 branch
BranchTrueFalseTotal
is_hashref($_[0]) ? : 0 0 0
69  
70 my $res = $self->_get(
71 "cluster/info",
72 undef,
73 0 ▶ ( $opt->{server} or () ),
Condition0%0/3
$opt->{'server'} || ()
l!l&&r!l&&!r
000
MC/DC0%0/2
$opt->{'server'} || ()
$opt->{'server'} ()
Truth table0%0/3
A || B
A= $opt->{'server'}B= ()
ABresult
1X1
011
000
74 );
75  
76 return $self->_apply_host_key(
77 $res,
78 0 ▶ $res->{clusterInfo} || $res,
Condition0%0/3
$res->{'clusterInfo'} || $res
l!l&&r!l&&!r
000
MC/DC0%0/2
$res->{'clusterInfo'} || $res
$res->{'clusterInfo'} $res
Truth table0%0/3
A || B
A= $res->{'clusterInfo'}B= $res
ABresult
1X1
011
000
79 );
80 }
81  
82 0 ▶sub metrics {
Subroutine metrics: not called CC=4 SCAR=30.0
Pod documented
83 0 my $self = shift;
84 0 ▶ my $opt = is_hashref $_[0] ? shift @_ : {};
Branch: 1 branch
BranchTrueFalseTotal
is_hashref($_[0]) ? : 0 0 0
85 my $res = $self->_get(
86 "cluster/metrics",
87 undef,
88 0 ▶ ( $opt->{server} or () ),
Condition0%0/3
$opt->{'server'} || ()
l!l&&r!l&&!r
000
MC/DC0%0/2
$opt->{'server'} || ()
$opt->{'server'} ()
Truth table0%0/3
A || B
A= $opt->{'server'}B= ()
ABresult
1X1
011
000
89 );
90  
91 return $self->_apply_host_key(
92 $res,
93 0 ▶ $res->{clusterMetrics} || $res,
Condition0%0/3
$res->{'clusterMetrics'} || $res
l!l&&r!l&&!r
000
MC/DC0%0/2
$res->{'clusterMetrics'} || $res
$res->{'clusterMetrics'} $res
Truth table0%0/3
A || B
A= $res->{'clusterMetrics'}B= $res
ABresult
1X1
011
000
94 );
95 }
96  
97 0 ▶sub scheduler {
Subroutine scheduler: not called CC=2 SCAR=17.9
Pod documented
98 0 my $self = shift;
99 0 my $res = $self->_get("cluster/scheduler");
100 return $self->_apply_host_key(
101 $res,
102 0 ▶ $res->{schedulerInfo} || $res,
Condition0%0/3
$res->{'schedulerInfo'} || $res
l!l&&r!l&&!r
000
MC/DC0%0/2
$res->{'schedulerInfo'} || $res
$res->{'schedulerInfo'} $res
Truth table0%0/3
A || B
A= $res->{'schedulerInfo'}B= $res
ABresult
1X1
011
000
103 );
104 }
105  
106 0 ▶sub apps {
Subroutine apps: not called CC=7 SCAR=40.3
Pod documented
107 0 my $self = shift;
108 0 my $app_id;
109 my $options;
110 0 ▶ if ( @_ == 1 ) {
Branch: 2 branches
BranchTrueFalseTotal
if (@_ == 1) { } 0 0 0
elsif (@_ > 1) { } 0 0 0
111 0 ▶ if ( !ref $_[0] ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $_[0]) { } 0 0 0
112 0 $app_id = shift;
113 }
114 else {
115 0 $options = shift;
116 }
117 }
118 elsif ( @_ > 1 ) {
119 0 $options = {@_};
120 }
121 0 ▶ my $res = $self->_get(
Branch: 1 branch
BranchTrueFalseTotal
$app_id ? : 0 0 0
122 $app_id ? "cluster/apps/$app_id" : ( "cluster/apps", { params => $options } )
123 );
124  
125 return $self->_apply_host_key(
126 $res,
127 0 ▶ $res->{apps}{app} || $res->{app} || $res,
Condition0%0/6
$res->{'apps'}{'app'} || $res->{'app'} || $res
l!l&&r!l&&!r
000
$res->{"apps"}{"app"} or $res->{"app"}
l!l&&r!l&&!r
000
MC/DC0%0/3
$res->{'apps'}{'app'} || $res->{'app'} || $res
$res->{"apps"}{"app"} $res->{"app"} $res
Truth table0%0/4
A or B || C
A= $res->{"apps"}{"app"}B= $res->{"app"}C= $res
ABCresult
1XX1
01X1
0011
0000
128 );
129 }
130  
131 0 ▶sub appattempts {
Subroutine appattempts: not called CC=2 SCAR=17.9
Pod documented
132 0 my $self = shift;
133 0 ▶ my $app_id = shift or die "No app ID provided";
Branch: 1 branch
BranchTrueFalseTotal
my $app_id = shift() or die "No app ID provided" 0 0 0
134 0 my $res = $self->_get( "cluster/apps/$app_id/appattempts" );
135 0 return $res;
136 }
137  
138 # TODO check all states and add filter (validation)
139  
140 0 ▶sub appstatistics {
Subroutine appstatistics: not called CC=7 SCAR=40.3
Pod documented
141 0 my $self = shift;
142 0 my $options;
143 0 ▶ if ( @_ == 1 && ref $_[0] ) {
Branch: 2 branches
BranchTrueFalseTotal
if (@_ == 1 and ref $_[0]) { } 0 0 0
elsif (@_ > 1) { } 0 0 0
Condition0%0/3
@_ == 1 and ref $_[0]
!ll&&!rl&&r
000
MC/DC0%0/2
@_ == 1 and ref $_[0]
@_ == 1 ref $_[0]
Truth table0%0/3
A and B
A= @_ == 1B= ref $_[0]
ABresult
0X0
100
111
144 0 $options = shift;
145 }
146 elsif ( @_ > 1 ) {
147 0 $options = {@_};
148 }
149 0 ▶ my $res = $self->_get(
Branch: 1 branch
BranchTrueFalseTotal
$options ? : 0 0 0
150 "cluster/appstatistics",
151 ( $options ? {
152 params => $options,
153 } : () ),
154 );
155  
156 0 ▶ if ($res) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res) 0 0 0
157 return $self->_apply_host_key(
158 $res,
159 $res->{appStatInfo}{statItem} || $res->{statItem},
160 0 ▶ );
Condition0%0/3
$res->{'appStatInfo'}{'statItem'} || $res->{'statItem'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$res->{'appStatInfo'}{'statItem'} || $res->{'statItem'}
$res->{'appStatInfo'}{'statItem'} $res->{'statItem'}
Truth table0%0/3
A || B
A= $res->{'appStatInfo'}{'statItem'}B= $res->{'statItem'}
ABresult
1X1
011
000
161 }
162  
163 0 return;
164 }
165  
166 0 ▶sub nodes {
Subroutine nodes: not called CC=7 SCAR=40.3
Pod documented
167 0 my $self = shift;
168 0 my $node_id;
169 my $options;
170 0 ▶ if ( @_ == 1 ) {
Branch: 2 branches
BranchTrueFalseTotal
if (@_ == 1) { } 0 0 0
elsif (@_ > 1) { } 0 0 0
171 0 ▶ if ( !ref $_[0] ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $_[0]) { } 0 0 0
172 0 $node_id = shift;
173 }
174 else {
175 0 $options = shift;
176 }
177 }
178 elsif ( @_ > 1 ) {
179 0 $options = {@_};
180 }
181 0 ▶ my $res = $self->_get(
Branch: 1 branch
BranchTrueFalseTotal
$node_id ? : 0 0 0
182 $node_id ? "cluster/nodes/$node_id"
183 : (
184 "cluster/nodes",
185 { params => $options },
186 )
187 );
188  
189  
190 return $self->_apply_host_key(
191 $res,
192 0 ▶ $res->{nodes}{node} || $res->{node} || $res,
Condition0%0/6
$res->{'nodes'}{'node'} || $res->{'node'} || $res
l!l&&r!l&&!r
000
$res->{"nodes"}{"node"} or $res->{"node"}
l!l&&r!l&&!r
000
MC/DC0%0/3
$res->{'nodes'}{'node'} || $res->{'node'} || $res
$res->{"nodes"}{"node"} $res->{"node"} $res
Truth table0%0/4
A or B || C
A= $res->{"nodes"}{"node"}B= $res->{"node"}C= $res
ABCresult
1XX1
01X1
0011
0000
193 );
194  
195 }
196  
197 0 ▶sub _apply_host_key {
Subroutine _apply_host_key: not called CC=7 SCAR=40.3
198 0 my $self = shift;
199 0 my $res = shift;
200 0 my $rv = shift;
201  
202  
203 0 ▶ if ( is_ref( $res )
Branch: 1 branch
BranchTrueFalseTotal
if (is_ref($res) and is_ref($rv) and builtin::refaddr($res) eq builtin::refaddr($rv)) 0 0 0
Condition0%0/6
is_ref($res) and is_ref($rv) and builtin::refaddr($res) eq builtin::refaddr($rv)
!ll&&!rl&&r
000
is_ref($res) and is_ref($rv)
!ll&&!rl&&r
000
MC/DC0%0/3
is_ref($res) and is_ref($rv) and builtin::refaddr($res) eq builtin::refaddr($rv)
is_ref($res) is_ref($rv) builtin::refaddr($res) eq builtin::refaddr($rv)
Truth table0%0/4
A and B and C
A= is_ref($res)B= is_ref($rv)C= builtin::refaddr($res) eq builtin::refaddr($rv)
ABCresult
0XX0
10X0
1100
1111
204 && is_ref( $rv )
205 && ( refaddr $res eq refaddr $rv )
206 ) {
207 0 return $rv;
208 }
209  
210 0 my $host_key = $self->host_key;
211 0 my $this_host = $res->{ $host_key };
212  
213 0 ▶ if ( is_hashref $rv ) {
Branch: 2 branches
BranchTrueFalseTotal
if (is_hashref($rv)) { } 0 0 0
elsif (is_arrayref($rv)) { } 0 0 0
214 0 $rv->{ $host_key } = $this_host;
215 }
216 elsif ( is_arrayref $rv ) {
217 0 foreach my $e ( @{ $rv } ) {
218 0 $e->{ $host_key } = $this_host;
219 }
220 }
221 else {
222 0 die "Got unknown data: $rv";
223 }
224  
225 0 return $rv;
226 }
227  
228 7 1;
229  
230 __END__
« YARN/ApplicationMaster.pm ↑ Summary YARN/DataNode/JMX.pm »