line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# |
2
|
|
|
|
|
|
|
# (C) 2015, Snehasis Sinha |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
package Apache::Hadoop::Watcher::Yarn; |
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
21832
|
use 5.010001; |
|
1
|
|
|
|
|
4
|
|
7
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
21
|
|
8
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
31
|
|
9
|
1
|
|
|
1
|
|
1051
|
use JSON; |
|
1
|
|
|
|
|
15815
|
|
|
1
|
|
|
|
|
5
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
require Apache::Hadoop::Watcher::Base; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our @ISA = qw(); |
14
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
# Preloaded methods go here. |
18
|
|
|
|
|
|
|
sub new { |
19
|
0
|
|
|
0
|
0
|
|
my $class = shift; |
20
|
0
|
|
|
|
|
|
my %args = @_; |
21
|
|
|
|
|
|
|
my $self = { |
22
|
|
|
|
|
|
|
host => $args{'host'} || 'localhost', |
23
|
|
|
|
|
|
|
qlist => { |
24
|
|
|
|
|
|
|
resourcemanager => { |
25
|
|
|
|
|
|
|
port => 8088, |
26
|
|
|
|
|
|
|
baseurl => '/ws/v1/cluster/', |
27
|
|
|
|
|
|
|
context => { |
28
|
|
|
|
|
|
|
info => 'info', |
29
|
|
|
|
|
|
|
metrics => 'metrics', |
30
|
|
|
|
|
|
|
scheduler => 'scheduler', |
31
|
|
|
|
|
|
|
apps => 'apps', |
32
|
|
|
|
|
|
|
appstatistics => 'appstatistics', |
33
|
|
|
|
|
|
|
nodes => 'nodes', |
34
|
|
|
|
|
|
|
}, |
35
|
|
|
|
|
|
|
}, |
36
|
|
|
|
|
|
|
nodemanager => { |
37
|
|
|
|
|
|
|
port => 8042, |
38
|
|
|
|
|
|
|
baseurl => '/ws/v1/node/', |
39
|
|
|
|
|
|
|
context => { |
40
|
|
|
|
|
|
|
info => 'info', |
41
|
|
|
|
|
|
|
apps => 'apps', |
42
|
|
|
|
|
|
|
containers => 'containers', |
43
|
|
|
|
|
|
|
}, |
44
|
|
|
|
|
|
|
}, |
45
|
|
|
|
|
|
|
appmaster => { |
46
|
|
|
|
|
|
|
port => 8888, |
47
|
|
|
|
|
|
|
baseurl => '/proxy/{appid}/ws/v1/mapreduce/', |
48
|
|
|
|
|
|
|
context => { |
49
|
|
|
|
|
|
|
info => 'info', |
50
|
|
|
|
|
|
|
jobs => 'jobs', |
51
|
|
|
|
|
|
|
}, |
52
|
|
|
|
|
|
|
}, |
53
|
|
|
|
|
|
|
historyserver => { |
54
|
|
|
|
|
|
|
port => 19888, |
55
|
|
|
|
|
|
|
baseurl => '/ws/v1/history/', |
56
|
|
|
|
|
|
|
context => { |
57
|
|
|
|
|
|
|
info => 'info', |
58
|
|
|
|
|
|
|
jobs => 'mapreduce/jobs', |
59
|
|
|
|
|
|
|
}, |
60
|
|
|
|
|
|
|
}, |
61
|
|
|
|
|
|
|
}, |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
out => undef, |
64
|
0
|
|
0
|
|
|
|
debug => $args{'debug'} || 1, |
|
|
|
0
|
|
|
|
|
65
|
|
|
|
|
|
|
}; |
66
|
0
|
|
|
|
|
|
bless $self, $class; |
67
|
0
|
|
|
|
|
|
return $self; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
# set context: service, context |
71
|
|
|
|
|
|
|
sub _mkurl { |
72
|
0
|
|
|
0
|
|
|
my ($self, %opts) = (@_); |
73
|
0
|
|
|
|
|
|
my $url; |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
$url = 'http://'.$self->{'host'}. |
76
|
|
|
|
|
|
|
':'.$self->{'qlist'}->{$opts{'service'}}->{'port'}. |
77
|
|
|
|
|
|
|
$self->{'qlist'}->{$opts{'service'}}->{'baseurl'}. |
78
|
0
|
|
|
|
|
|
$self->{'qlist'}->{$opts{'service'}}->{'context'}->{$opts{'context'}}; |
79
|
0
|
|
|
|
|
|
return $url; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
# dumps output hashref |
83
|
|
|
|
|
|
|
sub print { |
84
|
0
|
|
|
0
|
0
|
|
my ($self) = (@_); |
85
|
0
|
|
|
|
|
|
Apache::Hadoop::Watcher::Base->new->_print ( output=>$self->{'out'} ); |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
# returns list of services |
89
|
|
|
|
|
|
|
sub options { |
90
|
0
|
|
|
0
|
0
|
|
my ($self, %opts) = (@_); |
91
|
|
|
|
|
|
|
$self->{'out'} = (defined $opts{'service'}) |
92
|
|
|
|
|
|
|
? $self->{'qlist'}->{$opts{'service'}}->{'context'} |
93
|
0
|
0
|
|
|
|
|
: $self->{'qlist'}; |
94
|
0
|
|
|
|
|
|
return $self; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
# returns output hashref |
98
|
|
|
|
|
|
|
sub get { |
99
|
0
|
|
|
0
|
0
|
|
my ($self) = (@_); |
100
|
0
|
|
|
|
|
|
return $self->{'out'}; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
# check valid service, context and appid as applicable |
104
|
|
|
|
|
|
|
sub _isvalid { |
105
|
0
|
|
|
0
|
|
|
my ($self, %opts) = (@_); |
106
|
0
|
0
|
|
|
|
|
unless (defined $self->{'qlist'}->{$opts{'service'}}->{'context'}->{$opts{'context'}}) { |
107
|
0
|
|
|
|
|
|
my $error = "invalid service or context!"; |
108
|
0
|
|
|
|
|
|
$self->{'out'} = $error; |
109
|
|
|
|
|
|
|
#print $error,"\n" if $self->{'debug'}; |
110
|
0
|
|
|
|
|
|
return undef; |
111
|
|
|
|
|
|
|
} |
112
|
0
|
|
|
|
|
|
return 1; |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
sub request { |
116
|
0
|
|
|
0
|
0
|
|
my ($self, %opts) = (@_); |
117
|
0
|
|
|
|
|
|
my $base = Apache::Hadoop::Watcher::Base->new; |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
# check validity |
120
|
0
|
0
|
|
|
|
|
return $self unless defined $self->_isvalid (%opts); |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
# construct url |
123
|
|
|
|
|
|
|
my $url = $self->_mkurl ( |
124
|
|
|
|
|
|
|
service=>$opts{'service'}, |
125
|
|
|
|
|
|
|
context=>$opts{'context'}, |
126
|
0
|
|
|
|
|
|
appid =>$opts{'appid'}, |
127
|
|
|
|
|
|
|
); |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
# appid for appmaster |
130
|
0
|
0
|
|
|
|
|
if ( $opts{'service'} eq 'appmaster' ) { |
131
|
0
|
|
|
|
|
|
$url =~ s/{appid}/$opts{'appid'}/g; |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
# print url |
135
|
0
|
0
|
|
|
|
|
print $url,"\n" if $self->{'debug'}; |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
# actual work |
138
|
0
|
|
|
|
|
|
$self->{'out'} = (decode_json $base->_wget (url=>$url)); #->{'nodeInfo'}; |
139
|
0
|
|
|
|
|
|
$base->_jsontr ( $self->{'out'} ); |
140
|
0
|
|
|
|
|
|
return $self; |
141
|
|
|
|
|
|
|
} |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
1; |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
__END__ |