YARN/NameNode/JMX.pm

filter: Statementstmt 27.5% 19 / 69 Branchbran 0.0% 0 / 28 Conditioncond 0.0% 0 / 12 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 55.5% 5 / 9 Podpod 100% 2 / 2 totaltotal 20.4% 26 / 127 CC 21 SCAR 50.4
CC
21
Cov
17%
active_namenode
272.0
startupProgress
20.0
__ANON__
12.0
CRAP 154.3
« YARN/Roles/Common.pm ↑ Summary YARN/Roles/JMX.pm »
1 package Net::Hadoop::YARN::NameNode::JMX;
2 1 $Net::Hadoop::YARN::NameNode::JMX::VERSION = '0.203';
3 1 ▶use 5.10.0;
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 1 ▶use Ref::Util qw( is_arrayref );
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 my $RE_TIMEOUT = qr{ \Q500 read timeout\E }xms;
11 1 my $RE_DEAD = qr{ \Q500 Can't connect to\E .+? \QConnection refused\E }xms;
12  
13 has namenodes => (
14 is => 'rw',
15 0 ▶ default => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
16 0 die "namenodes not specified";
17 },
18 0 ▶ isa => sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
19 0 ▶ if ( ! is_arrayref $_[0] ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (is_arrayref($_[0])) 0 0 0
20 0 die "namenodes needs to be an ARRAY";
21 }
22 0 ▶ if ( ! @{ $_[0] } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not @{$_[0];}) 0 0 0
23 0 die "namenodes needs at least one element";
24 }
25 },
26 1 );
27  
28 0 ▶sub active_namenode {
Subroutine active_namenode: not called CC=16 SCAR=56.1
Pod documented
29 0 my $self = shift;
30 0 ▶ my $opt = ref $_[0] eq 'HASH' ? shift @_ : {};
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'HASH' ? : 0 0 0
31 0 my($rv, $try);
32 NN_TRY: {
33 0 NN_PROBE: foreach my $nn ( @{ $self->namenodes } ) {
34 0 my $uri = sprintf 'http://%s/jmx?qry=Hadoop:service=NameNode,name=FSNamesystem', $nn;
35 0 my $jmx;
36 eval {
37 0 $jmx = $self->agent_request( $uri );
38 0 1;
39 0 ▶ } or do {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { $jmx = $self->agent_request($uri); 1 } } or do { my $eval_error = $@ || "Zombie error"; if ($eval_error =~ /$RE_TIMEOUT/ or $eval_error =~ /$RE_DEAD/) { next NN_PROBE; } ; die sprintf("Error while probing the name node `%s`: %s", (split(/ [:] /msx, $nn, 2))[0], $eval_error) } 0 0 0
40 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
41 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($eval_error =~ /$RE_TIMEOUT/ or $eval_error =~ /$RE_DEAD/) 0 0 0
Condition0%0/3
$eval_error =~ /$RE_TIMEOUT/ or $eval_error =~ /$RE_DEAD/
l!l&&r!l&&!r
000
MC/DC0%0/2
$eval_error =~ /$RE_TIMEOUT/ or $eval_error =~ /$RE_DEAD/
$eval_error =~ /$RE_TIMEOUT/ $eval_error =~ /$RE_DEAD/
Truth table0%0/3
A or B
A= $eval_error =~ /$RE_TIMEOUT/B= $eval_error =~ /$RE_DEAD/
ABresult
1X1
011
000
42 $eval_error =~ $RE_TIMEOUT
43 || $eval_error =~ $RE_DEAD
44 ) {
45 0 next NN_PROBE;
46 }
47 0 die sprintf 'Error while probing the name node `%s`: %s',
48 ( split m{ [:] }xms, $nn, 2 )[0],
49 $eval_error,
50 ;
51 };
52 0 ▶ next NN_PROBE if ref $jmx ne 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $jmx ne "HASH" 0 0 0
53 0 my $status = $jmx->{beans}[0]{'tag.HAState'};
54 0 ▶ next NN_PROBE if ! $status || $status ne 'active';
Branch: 1 branch
BranchTrueFalseTotal
if not $status or $status ne "active" 0 0 0
Condition0%0/3
not $status or $status ne "active"
l!l&&r!l&&!r
000
MC/DC0%0/2
not $status or $status ne "active"
not $status $status ne "active"
Truth table0%0/3
not(A) or B
A= not $statusB= $status ne "active"
ABresult
1X1
011
000
55  
56 0 ▶ if ( $opt->{real_hostname} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt->{'real_hostname'}) { } 0 0 0
57 0 ▶ $rv = $jmx->{beans}[0]{'tag.Hostname'} || die "Unable to locate tag.Hostname from JMX";
Condition0%0/2
$jmx->{'beans'}[0]{'tag.Hostname'} || die('Unable to locate tag.Hostname from JMX')
l!l
00
MC/DC0%0/1
$jmx->{'beans'}[0]{'tag.Hostname'} || die('Unable to locate tag.Hostname from JMX')
$jmx->{'beans'}[0]{'tag.Hostname'}
Truth table0%0/2
A
A= $jmx->{'beans'}[0]{'tag.Hostname'}
Aresult
11
00
58 0 ▶ if ( ! $opt->{hostname_only} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($opt->{"hostname_only"}) 0 0 0
59 0 $rv .= ':' . (split m{ [:] }xms, $nn )[1]
60 }
61 }
62 else {
63 0 $rv = $nn;
64 }
65  
66 0 last NN_PROBE;
67 }
68 0 ▶ if ( ! $rv ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($rv) 0 0 0
69 0 ▶ if ( ++$try <= 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (++$try <= 1) 0 0 0
70 0 sleep 1;
71 0 redo NN_TRY;
72 }
73 0 die sprintf 'Failed to locate the active namenode (tried %s times)', $try;
74 }
75 }
76  
77 0 ▶ return $opt->{hostname_only} ? (split m{ [:] }xms, $rv )[0] : $rv;
Branch: 1 branch
BranchTrueFalseTotal
$opt->{'hostname_only'} ? : 0 0 0
78 }
79  
80 0 ▶sub startupProgress {
Subroutine startupProgress: not called CC=4 SCAR=30.0
Pod documented
81 0 my $self = shift;
82 0 my @nn = @{ $self->namenodes };
83 0 my $uri_tmpl = 'http://%s/%s';
84  
85 0 ▶ NAME_NODE: while ( my $nn = shift @nn ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $nn = shift @nn) 0 0 0
86 0 my $uri = sprintf $uri_tmpl, $nn, 'startupProgress';
87 0 my $resp;
88 eval {
89 0 $resp = $self->agent_request( $uri );
90 0 1;
91 0 ▶ } or do {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { $resp = $self->agent_request($uri); 1 } } or do { my $eval_error = $@ || "Zombie error"; my $msg = "Error from ${nn}: $eval_error"; die $msg } 0 0 0
92 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
93 0 my $msg = "Error from $nn: $eval_error";
94  
95 # TODO:
96 # if ( $eval_error =~ $failover_or_passive_or_whatever ) {
97 # warn $msg; @rv = (); next NAME_NODE;
98 # }
99 #
100  
101 0 die $msg;
102 };
103  
104 0 return $resp;
105 }
106 }
107  
108 1 1;
109  
110 __END__
« YARN/Roles/Common.pm ↑ Summary YARN/Roles/JMX.pm »