YARN.pm

filter: Statementstmt 43.1% 25 / 58 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 47.0% 8 / 17 Podpod 75.0% 6 / 8 totaltotal 40.6% 39 / 96 CC 7 SCAR 18.6
CC
7
Cov
37%
new
20.0
recurse
12.0
__req_api
6.0
CRAP 6.4
↑ Summary yarn.pl »
1 package YARN;
2  
3 # TODO: Write better/more test cases
4  
5 1 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 ▶use REST::Client;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use JSON;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 1 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 1 ▶use YARN::YarnClient;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 1 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 $YARN::VERSION = '0.1';
18 }
19  
20 1 our $client = '';
21  
22 1 my %apis = (
23 info => 'clusterInfo',
24 metrics => 'clusterMetrics',
25 scheduler => 'scheduler',
26 apps => 'apps',
27 );
28  
29 0 ▶sub new {
Subroutine new: not called CC=4 SCAR=30.0
Pod documented
30 0 my ($this, %opts) = @_;
31
32 my $self = +{
33 host => $opts{host} || 'localhost',
34 port => $opts{port} || 8088,
35 0 ▶ endpoint => $opts{endpoint} || '/ws/v1/cluster',
Condition0%0/6
$opts{'host'} || 'localhost'
l!l
00
$opts{'port'} || 8088
l!l
00
$opts{'endpoint'} || '/ws/v1/cluster'
l!l
00
MC/DC0%0/1
$opts{'host'} || 'localhost'
$opts{'host'}
MC/DC0%0/1
$opts{'port'} || 8088
$opts{'port'}
MC/DC0%0/1
$opts{'endpoint'} || '/ws/v1/cluster'
$opts{'endpoint'}
Truth table0%0/2
A
A= $opts{'host'}
Aresult
11
00
Truth table0%0/2
A
A= $opts{'port'}
Aresult
11
00
Truth table0%0/2
A
A= $opts{'endpoint'}
Aresult
11
00
36 };
37
38 0 $client = YARN::YarnClient->createYarnClient( $self );
39
40 0 return bless $self, $this;
41 }
42  
43 # TODO: Rename below method to something meaningful
44 0 ▶sub __req_api {
Subroutine __req_api: not called CC=2 SCAR=17.9
45 0 my ($self, $api, $element) = @_;
46
47 0 my $req = $client->connect( $self );
48 0 my $rest = $req->GET( $client->api_path( $self, $api ) )->responseContent();
49
50 0 ▶ if (defined $element) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $element) { } 0 0 0
51 0 return $self->findElementInJSON( $rest, $apis{$api}, $element );
52 } else {
53 0 return $rest;
54 }
55 }
56  
57 0 ▶sub info { shift->__req_api( 'info', @_ ); }
Subroutine info: not called CC=1 SCAR=6.9
Pod documented
58 0 ▶sub metrics { shift->__req_api( 'metrics', @_ ); }
Subroutine metrics: not called CC=1 SCAR=6.9
Pod documented
59 0 ▶sub scheduler { shift->__req_api( 'scheduler', 'schedulerInfo', @_ ); }
Subroutine scheduler: not called CC=1 SCAR=6.9
Pod documented
60  
61 0 ▶sub getAllQueues {
Subroutine getAllQueues: not called CC=1 SCAR=6.9
Pod documented
62 0 my $self = shift;
63
64 0 my $req = $self->scheduler();
65
66 0 my @queues;
67 0 $queues[0] = $req->{'queueName'};
68
69 0 push @queues, $self->recurse( $req, 'queues', $req->{'queueName'} );
70
71 0 return @queues;
72 }
73  
74 1 my @allQueues;
75  
76 0 ▶sub recurse {
Subroutine recurse: not called CC=3 SCAR=24.8
Pod undocumented
77 0 my ($self, $req, $element, $parent) = @_;
78
79 0 ▶ if ( defined $req->{$element} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $req->{$element}) 0 0 0
80 0 my @queues = @{ $req->{$element}->{'queue'} };
81
82 0 foreach my $queue ( @queues ) {
83 0 my $queueName = $parent . "." . $queue->{'queueName'};
84
85 0 push @allQueues, $queueName;
86
87 0 $self->recurse( $queue, 'queues', $queueName );
88 }
89 }
90
91 0 return @allQueues;
92 }
93  
94 0 ▶sub getRootQueueInfos {
Subroutine getRootQueueInfos: not called CC=1 SCAR=6.9
Pod documented
95 0 my $self = shift;
96
97 0 my $req = $self->scheduler();
98 }
99  
100 0 ▶sub findElementInJSON {
Subroutine findElementInJSON: not called CC=1 SCAR=6.9
Pod undocumented
101 0 my ($self, $rest, $root, $element) = @_;
102
103 0 my $res = decode_json $rest;
104
105 0 return $res->{$root}->{$element};
106 }
107  
108 =head1 NAME
109  
110 YARN - short for Yet Another Resource Negotiator (or if you prefer recursive acronyms, YARN Application Resource Negotiator).
111  
112 =head2 VERSION
113  
114 Version 0.01
115  
116 =head1 SYNOPSIS
117  
118 use YARN;
119  
120 my $yarn = YARN->new( host => "hadoop-master.example.com" );
121
122 print $client->info('id');
123  
124 =head1 Methods
125  
126 =head2 Construction and setup
127  
128 =head3 new
129  
130 Construct a new YARN.
131  
132 =head2 ResourceManager REST API's
133  
134 The ResourceManager REST API's allow the user to get information about the cluster - status on the cluster, metrics on the cluster, scheduler information, information about nodes in the cluster, and information about applications on the cluster.
135  
136 =head3 info
137  
138 The cluster information resource provides overall information about the cluster. Use this method to get general information about the cluster.
139
140 # Returns a JSON String with the elements of the clusterInfo object
141 $client->info();
142
143 # Returns the value of an element from the clusterInfo object
144 $client->info('id');
145  
146 =head3 metrics
147  
148 The cluster metrics resource provides some overall metrics about the cluster. Use this method to get metrics about the cluster.
149  
150 # Returns a JSON String with the elements of the clusterMetrics object
151 $client->metrics();
152
153 # Returns the value of an element from the metrics object
154 $client->metrics('totalNodes');
155  
156 =head3 scheduler
157  
158 A scheduler resource contains information about the current scheduler configured in a cluster. It currently supports both the Fifo and Capacity Scheduler.
159 You will get different information depending on which scheduler is configured so be sure to look at the type information.
160  
161 # TODO: Fix 4 lines below
162 # Returns a JSON String with the elements of the scheduler object
163 $client->scheduler();
164
165 # Returns the value of an element from the scheduler object
166 $client->scheduler('XXX');
167  
168 =head3 apps
169  
170 With the Applications API, you can obtain a collection of resources, each of which represents an application. When you run a GET operation on this resource, you obtain a collection of Application Objects.
171  
172 # Returns a JSON String with the elements of the apps object
173 $client->apps();
174
175 # Returns the value of an element from the apps object
176 $client->apps('XXX');
177  
178 =head3 nodes
179  
180 With the Nodes API, you can obtain a collection of resources, each of which represents a node. When you run a GET operation on this resource, you obtain a collection of Node Objects.
181 Use this method to get a report of all nodes in the cluster.
182  
183 # Returns a JSON String with the elements of the nodes object
184 $client->nodes();
185
186 # Returns the value of an element from the nodes object
187 $client->nodes('XXX');
188  
189 =head3 node
190  
191 A node resource contains information about a node in the cluster. Use this method to get a report of a node in the cluster.
192  
193 # Returns a JSON String with the elements of the node object
194 $client->node();
195
196 # Returns the value of an element from the node object
197 $client->node('XXX');
198  
199 =head3 getAllQueues
200  
201 Returns an array with all queues defined in the scheduler.
202
203 print Dumper $client->getAllQueues();
204 $VAR1 = 'root';
205 $VAR2 = 'root.parent1';
206 $VAR3 = 'root.parent1.child1';
207 $VAR5 = 'root.foo';
208 $VAR6 = 'root.foo.f1';
209 $VAR7 = 'root.foo.f2';
210 $VAR8 = 'root.foo.f718';
211 $VAR9 = 'root.bar';
212  
213 =head3 getRootQueueInfos
214  
215 Get information about top level queues.
216  
217 =head1 AUTHOR
218  
219 Ahmed Ossama, C<< <ahmed at aossama.com> >>
220  
221 =head1 BUGS
222  
223 Please report any bugs or feature requests to C<bug-yarn at rt.cpan.org>, or through
224 the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=YARN>. I will be notified, and then you'll
225 automatically be notified of progress on your bug as I make changes.
226  
227  
228  
229 =head1 SUPPORT
230  
231 You can find documentation for this module with the perldoc command.
232  
233 perldoc YARN
234  
235  
236 You can also look for information at:
237  
238 =over 4
239  
240 =item * RT: CPAN's request tracker (report bugs here)
241  
242 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=YARN>
243  
244 =item * AnnoCPAN: Annotated CPAN documentation
245  
246 L<http://annocpan.org/dist/YARN>
247  
248 =item * CPAN Ratings
249  
250 L<http://cpanratings.perl.org/d/YARN>
251  
252 =item * Search CPAN
253  
254 L<http://search.cpan.org/dist/YARN/>
255  
256 =back
257  
258  
259 =head1 LICENSE AND COPYRIGHT
260  
261 Copyright 2015 Ahmed Ossama.
262  
263 Licensed under the Apache License, Version 2.0 (the "License");
264 you may not use this file except in compliance with the License.
265 You may obtain a copy of the License at
266  
267 L<http://www.apache.org/licenses/LICENSE-2.0>
268  
269 Unless required by applicable law or agreed to in writing, software
270 distributed under the License is distributed on an "AS IS" BASIS,
271 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
272 See the License for the specific language governing permissions and
273 limitations under the License.
274  
275  
276 =cut
277  
278 1 1; # End of YARN
↑ Summary yarn.pl »