blib/lib/Hadoop/Admin.pm

filter: Statementstmt 68.9% 120 / 174 Branchbran 47.5% 19 / 40 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 65.0% 13 / 20 Podpod 50.0% 7 / 14 totaltotal 64.8% 164 / 253 CC 32 SCAR 19.9
CC
32
Cov
65%
BUILD
13.5
gather_nn_jmx
12.0
gather_jt_jmx
12.0
CRAP 7.3
↑ Summary
1 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 package Hadoop::Admin;
3 {
4 5 $Hadoop::Admin::VERSION = '0.4';
5 }
6 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 5 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 5 ▶use LWP::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 5 ▶use JSON -support_by_pp;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 5 has 'namenode' => (
12 is => 'ro',
13 isa => 'Str',
14 reader => 'get_namenode',
15 predicate => 'has_namenode',
16 );
17  
18 5 has 'namenode_port' => (
19 is => 'ro',
20 isa => 'Int',
21 default => '50070',
22 reader => 'get_namenode_port',
23 predicate => 'has_namenode_port',
24 );
25  
26 5 has 'jobtracker' => (
27 is => 'ro',
28 isa => 'Str',
29 reader => 'get_jobtracker',
30 predicate => 'has_jobtracker',
31 );
32  
33 5 has 'jobtracker_port' => (
34 is => 'ro',
35 isa => 'Int',
36 default => '50030',
37 reader => 'get_jobtracker_port',
38 predicate => 'has_jobtracker_port',
39 );
40  
41 5 has 'secondarynamenode' => (
42 is => 'ro',
43 isa => 'Str',
44 reader => 'get_secondarynamenode',
45 predicate => 'has_secondarynamenode',
46 );
47  
48 5 has 'resourcemanager' => (
49 is => 'ro',
50 isa => 'Str',
51 reader => 'get_resourcemanager',
52 predicate => 'has_resourcemanager',
53 );
54  
55 5 has 'resourcemanager_port' => (
56 is => 'ro',
57 isa => 'Int',
58 default => '8088',
59 reader => 'get_resourcemanager_port',
60 predicate => 'has_resourcemanager_port',
61 );
62  
63 5 has 'socksproxy' => (
64 is => 'ro',
65 isa => 'Str',
66 reader => 'get_socksproxy',
67 predicate => 'has_socksproxy',
68 );
69  
70 5 has 'socksproxy_port' => (
71 is => 'ro',
72 isa => 'Int',
73 default => '1080',
74 reader => 'get_socksproxy_port',
75 predicate => 'has_socksproxy_port',
76 );
77  
78 5 has 'ua' => (
79 is => 'rw',
80 isa => 'Object',
81 predicate => 'has_ua',
82 );
83  
84 5 has '_test_namenodeinfo' => (
85 is => 'ro',
86 isa => 'Str',
87 );
88  
89 5 has '_test_jobtrackerinfo' => (
90 is => 'ro',
91 isa => 'Str',
92 );
93  
94 5 has '_test_resourcemanagerinfo' => (
95 is => 'ro',
96 isa => 'Str',
97 );
98  
99 # ABSTRACT: Module for administration of Hadoop clusters
100  
101  
102 7 ▶sub BUILD{
Subroutine BUILD: called CC=13 SCAR=26.0
Pod undocumented
103  
104 7 my $self=shift;
105  
106 7 ▶ if ( $self->has_resourcemanager && $self->has_jobtracker ){
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_resourcemanager and $self->has_jobtracker) 1 6 7
Condition100%3/3
$self->has_resourcemanager and $self->has_jobtracker
!ll&&!rl&&r
511
MC/DC100%2/2
$self->has_resourcemanager and $self->has_jobtracker
$self->has_resourcemanager $self->has_jobtracker
Truth table100%3/3
A and B
A= $self->has_resourcemanagerB= $self->has_jobtracker
ABresult
0X0
100
111
107 1 die "Can't have both ResourceManager and JobTracker\n";
108 }
109  
110 6 $self->ua(new LWP::UserAgent());
111 6 ▶ if ( defined $self->get_socksproxy ){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->get_socksproxy) 1 5 6
112 1 $self->ua->proxy([qw(http https)] => 'socks://'.$self->get_socksproxy.':1080');
113 }
114 ## Hooks for testing during builds. Doesn't connect to a real cluster.
115 6 ▶ if ( defined $self->_test_namenodeinfo ){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->_test_namenodeinfo) { } 4 2 6
116 4 my $test_nn_string;
117 {
118 4 local $/=undef;
119 4 ▶ open (my $fh, '<', $self->_test_namenodeinfo) or die "Couldn't open file: $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $self->_test_namenodeinfo or die "Couldn't open file: $!" 4 0 4
120 4 $test_nn_string = <$fh>;
121 4 close $fh;
122 }
123 4 $self->parse_nn_jmx($test_nn_string);
124 }else{
125 2 ▶ if ( defined $self->get_namenode ){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->get_namenode) 0 2 2
126 0 $self->gather_nn_jmx('NameNodeInfo');
127 }
128 }
129 ## Hooks for testing during builds. Doesn't connect to a real cluster.
130 6 ▶ if ( defined $self->_test_jobtrackerinfo ){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->_test_jobtrackerinfo) { } 3 3 6
131 3 my $test_jt_string;
132 {
133 3 local $/=undef;
134 3 ▶ open(my $fh, '<', $self->_test_jobtrackerinfo) or die "Couldn't open file: $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $self->_test_jobtrackerinfo or die "Couldn't open file: $!" 3 0 3
135 3 $test_jt_string = <$fh>;
136 3 close $fh;
137 }
138 3 $self->parse_jt_jmx($test_jt_string);
139 }else{
140 3 ▶ if ( defined $self->get_jobtracker ){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->get_jobtracker) 0 3 3
141 0 $self->gather_jt_jmx('JobTrackerInfo');
142 }
143 }
144
145 ## Hooks for testing during builds. Doesn't connect to a real cluster.
146 6 ▶ if ( defined $self->_test_resourcemanagerinfo ){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->_test_resourcemanagerinfo) { } 3 3 6
147 3 my $test_rm_string;
148 {
149 3 local $/=undef;
150 3 ▶ open(my $fh, '<', $self->_test_resourcemanagerinfo) or die "Couldn't open file: $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $self->_test_resourcemanagerinfo or die "Couldn't open file: $!" 3 0 3
151 3 $test_rm_string = <$fh>;
152 3 close $fh;
153 }
154 3 $self->parse_rm_jmx($test_rm_string);
155 }else{
156 3 ▶ if ( defined $self->get_resourcemanager ){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->get_resourcemanager) 0 3 3
157 0 $self->gather_rm_jmx('RMNMInfo');
158 }
159 }
160
161 6 return $self;
162 }
163  
164 2 ▶sub datanode_live_list{
Subroutine datanode_live_list: called CC=1 SCAR=0.0
Pod documented
165 2 my $self=shift;
166 2 return keys %{$self->{'NameNodeInfo_LiveNodes'}};
167 }
168  
169 0 ▶sub datanode_dead_list{
Subroutine datanode_dead_list: not called CC=1 SCAR=6.9
Pod documented
170 0 my $self=shift;
171 0 return keys %{$self->{'NameNodeInfo_DeadNodes'}};
172 }
173  
174 0 ▶sub datanode_decom_list{
Subroutine datanode_decom_list: not called CC=1 SCAR=6.9
Pod documented
175 0 my $self=shift;
176 0 return keys %{$self->{'NameNodeInfo_DecomNodes'}};
177 }
178  
179  
180 1 ▶sub nodemanager_live_list{
Subroutine nodemanager_live_list: called CC=2 SCAR=6.9
Pod documented
181 1 my $self=shift;
182 1 my @returnValue=();
183 1 foreach my $hostref ( @{$self->{'RMNMInfo_LiveNodeManagers'}} ) {
184 314 push @returnValue, $hostref->{'HostName'};
185 }
186 1 return @returnValue;
187 }
188  
189 1 ▶sub tasktracker_live_list{
Subroutine tasktracker_live_list: called CC=2 SCAR=6.9
Pod documented
190 1 my $self=shift;
191 1 my @returnValue=();
192 5 ▶ use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
193 1 foreach my $hostref ( @{$self->{'JobTrackerInfo_AliveNodesInfoJson'}} ) {
194 451 push @returnValue, $hostref->{'hostname'};
195 }
196 1 return @returnValue;
197 }
198  
199 0 ▶sub tasktracker_blacklist_list{
Subroutine tasktracker_blacklist_list: not called CC=2 SCAR=17.9
Pod documented
200 0 my $self=shift;
201 0 my @returnValue=();
202 0 foreach my $hostref ( @{$self->{'JobTrackerInfo_BlacklistedNodesInfoJson'}} ) {
203 0 push @returnValue, $hostref->{'hostname'};
204 }
205 0 return @returnValue;
206 }
207  
208 0 ▶sub tasktracker_graylist_list{
Subroutine tasktracker_graylist_list: not called CC=2 SCAR=17.9
Pod documented
209 0 my $self=shift;
210 0 my @returnValue=();
211 0 foreach my $hostref ( @{$self->{'JobTrackerInfo_BlacklistedNodesInfoJson'}} ) {
212 0 push @returnValue, $hostref->{'hostname'};
213 }
214 0 return @returnValue;
215 }
216  
217 0 ▶sub gather_nn_jmx{
Subroutine gather_nn_jmx: not called CC=3 SCAR=24.8
Pod undocumented
218 0 my $self=shift;
219 0 my $bean=shift;
220 0 my $qry;
221 0 ▶ if ($bean eq 'NameNodeInfo'){
Branch: 1 branch
BranchTrueFalseTotal
if ($bean eq "NameNodeInfo") 0 0 0
222 0 $qry='Hadoop%3Aservice%3DNameNode%2Cname%3DNameNodeInfo';
223 }
224 0 my $jmx_url= "http://".$self->get_namenode.":".$self->get_namenode_port."/jmx?qry=$qry";
225 0 my $response = $self->{'ua'}->get($jmx_url);
226 0 ▶ if (! $response->is_success) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($response->is_success) 0 0 0
227 0 print "Can't get JMX data from Namenode: $@";
228 0 exit(1);
229 }
230 0 $self->parse_nn_jmx($response->decoded_content);
231 }
232  
233 4 ▶sub parse_nn_jmx{
Subroutine parse_nn_jmx: called CC=4 SCAR=13.9
Pod undocumented
234 4 my $self=shift;
235 4 my $nn_content=shift;
236 4 my $json=new JSON();
237 4 my $json_text = $json->allow_nonref->utf8->relaxed->escape_slash->loose->allow_singlequote->allow_barekey->pretty->decode($nn_content);
238 4 foreach my $bean (@{$json_text->{beans}}){
239 4 ▶ if ($bean->{name} eq "Hadoop:service=NameNode,name=NameNodeInfo"){
Branch: 1 branch
BranchTrueFalseTotal
if ($bean->{"name"} eq "Hadoop:service=NameNode,name=NameNodeInfo") 4 0 4
240 4 foreach my $var (keys %{$bean}){
241 76 $self->{"NameNodeInfo_$var"}=$bean->{$var};
242 }
243 4 $self->{'NameNodeInfo_LiveNodes'}=$json->allow_nonref->utf8->relaxed->escape_slash->loose->allow_singlequote->allow_barekey->pretty->decode($bean->{LiveNodes});
244 4 $self->{'NameNodeInfo_DeadNodes'}=$json->allow_nonref->utf8->relaxed->escape_slash->loose->allow_singlequote->allow_barekey->pretty->decode($bean->{DeadNodes});
245 4 $self->{'NameNodeInfo_DecomNodes'}=$json->allow_nonref->utf8->relaxed->escape_slash->loose->allow_singlequote->allow_barekey->pretty->decode($bean->{DecomNodes});
246 }
247
248 }
249 }
250  
251 0 ▶sub gather_jt_jmx{
Subroutine gather_jt_jmx: not called CC=3 SCAR=24.8
Pod undocumented
252 0 my $self=shift;
253 0 my $bean=shift;
254 0 my $qry;
255 0 ▶ if ($bean eq "JobTrackerInfo"){
Branch: 1 branch
BranchTrueFalseTotal
if ($bean eq "JobTrackerInfo") 0 0 0
256 0 $qry='Hadoop%3Aservice%3DJobTracker%2Cname%3DJobTrackerInfo';
257 }
258 0 my $jmx_url= "http://".$self->get_jobtracker.":".$self->get_jobtracker_port."/jmx?qry=$qry";
259 0 my $response = $self->{'ua'}->get($jmx_url);
260 0 ▶ if (! $response->is_success) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($response->is_success) 0 0 0
261 0 print "Can't get JMX data from JobTracker: $@";
262 0 exit(1);
263 }
264 0 $self->parse_jt_jmx($response->decoded_content);
265  
266 }
267  
268 3 ▶sub parse_jt_jmx{
Subroutine parse_jt_jmx: called CC=4 SCAR=13.9
Pod undocumented
269 3 my $self=shift;
270 3 my $jt_content=shift;
271 3 my $json=JSON->new();
272 3 my $json_text = $json->allow_nonref->utf8->relaxed->escape_slash->loose->allow_singlequote->allow_barekey->pretty->decode($jt_content);
273 3 foreach my $bean (@{$json_text->{beans}}){
274 3 foreach my $var (keys %{$bean}){
275 33 $self->{"JobTrackerInfo_$var"}=$bean->{$var};
276 }
277 3 ▶ if ($bean->{name} eq "Hadoop:service=JobTracker,name=JobTrackerInfo"){
Branch: 1 branch
BranchTrueFalseTotal
if ($bean->{"name"} eq "Hadoop:service=JobTracker,name=JobTrackerInfo") 3 0 3
278 3 $self->{'JobTrackerInfo_AliveNodesInfoJson'}=$json->allow_nonref->utf8->relaxed->escape_slash->loose->allow_singlequote->allow_barekey->pretty->decode($bean->{AliveNodesInfoJson});
279 3 $self->{'JobTrackerInfo_BlacklistedNodesInfoJson'}=$json->allow_nonref->utf8->relaxed->escape_slash->loose->allow_singlequote->allow_barekey->pretty->decode($bean->{BlacklistedNodesInfoJson});
280 3 $self->{'JobTrackerInfo_GraylistedNodesInfoJson'}=$json->allow_nonref->utf8->relaxed->escape_slash->loose->allow_singlequote->allow_barekey->pretty->decode($bean->{GraylistedNodesInfoJson});
281 }
282
283 }
284 }
285 0 ▶sub gather_rm_jmx{
Subroutine gather_rm_jmx: not called CC=3 SCAR=24.8
Pod undocumented
286 0 my $self=shift;
287 0 my $bean=shift;
288 0 my $qry;
289 0 ▶ if ($bean eq "RMNMInfo"){
Branch: 1 branch
BranchTrueFalseTotal
if ($bean eq "RMNMInfo") 0 0 0
290 0 $qry='Hadoop%3Aservice%3DResourceManager%2Cname%3DRMNMInfo';
291 }
292 0 my $jmx_url= "http://".$self->get_resourcemanager.":".$self->get_resourcemanager_port."/jmx?qry=$qry";
293 0 my $response = $self->{'ua'}->get($jmx_url);
294 0 ▶ if (! $response->is_success) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($response->is_success) 0 0 0
295 0 print "Can't get JMX data from ResourceManager: $@";
296 0 exit(1);
297 }
298 0 $self->parse_rm_jmx($response->decoded_content);
299 }
300  
301 3 ▶sub parse_rm_jmx{
Subroutine parse_rm_jmx: called CC=4 SCAR=13.9
Pod undocumented
302 3 my $self=shift;
303 3 my $rm_content=shift;
304 3 my $json=JSON->new();
305 3 my $json_text = $json->allow_nonref->utf8->relaxed->escape_slash->loose->allow_singlequote->allow_barekey->pretty->decode($rm_content);
306 3 foreach my $bean (@{$json_text->{beans}}){
307 3 foreach my $var (keys %{$bean}){
308 9 $self->{"RMNMInfo_$var"}=$bean->{$var};
309 }
310 3 ▶ if ($bean->{name} eq "Hadoop:service=ResourceManager,name=RMNMInfo"){
Branch: 1 branch
BranchTrueFalseTotal
if ($bean->{"name"} eq "Hadoop:service=ResourceManager,name=RMNMInfo") 3 0 3
311 3 $self->{'RMNMInfo_LiveNodeManagers'}=$json->allow_nonref->utf8->relaxed->escape_slash->loose->allow_singlequote->allow_barekey->pretty->decode($bean->{LiveNodeManagers});
312 }
313
314 }
315 }
316  
317 5 1;
318  
319  
320 __END__
↑ Summary