File Coverage

blib/lib/YARN.pm
Criterion Covered Total %
statement 22 55 40.0
branch 0 4 0.0
condition 0 6 0.0
subroutine 8 17 47.0
pod 6 8 75.0
total 36 90 40.0


line stmt bran cond sub pod time code
1             package YARN;
2              
3             # TODO: Write better/more test cases
4              
5 1     1   16276 use 5.006;
  1         4  
  1         40  
6 1     1   5 use strict;
  1         1  
  1         35  
7 1     1   4 use warnings;
  1         8  
  1         24  
8              
9 1     1   577 use REST::Client;
  1         63322  
  1         26  
10 1     1   674 use JSON;
  1         9271  
  1         4  
11              
12 1     1   696 use Data::Dumper;
  1         5347  
  1         72  
13              
14 1     1   399 use YARN::YarnClient;
  1         2  
  1         31  
15              
16             BEGIN {
17 1     1   367 $YARN::VERSION = '0.1';
18             }
19              
20             our $client = '';
21              
22             my %apis = (
23             info => 'clusterInfo',
24             metrics => 'clusterMetrics',
25             scheduler => 'scheduler',
26             apps => 'apps',
27             );
28              
29             sub new {
30 0     0 1   my ($this, %opts) = @_;
31            
32 0   0       my $self = +{
      0        
      0        
33             host => $opts{host} || 'localhost',
34             port => $opts{port} || 8088,
35             endpoint => $opts{endpoint} || '/ws/v1/cluster',
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             sub __req_api {
45 0     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 0         if (defined $element) {
51 0           return $self->findElementInJSON( $rest, $apis{$api}, $element );
52             } else {
53 0           return $rest;
54             }
55             }
56              
57 0     0 1   sub info { shift->__req_api( 'info', @_ ); }
58 0     0 1   sub metrics { shift->__req_api( 'metrics', @_ ); }
59 0     0 1   sub scheduler { shift->__req_api( 'scheduler', 'schedulerInfo', @_ ); }
60              
61             sub getAllQueues {
62 0     0 1   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             my @allQueues;
75              
76             sub recurse {
77 0     0 0   my ($self, $req, $element, $parent) = @_;
78            
79 0 0         if ( defined $req->{$element} ) {
80 0           my @queues = @{ $req->{$element}->{'queue'} };
  0            
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             sub getRootQueueInfos {
95 0     0 1   my $self = shift;
96            
97 0           my $req = $self->scheduler();
98             }
99              
100             sub findElementInJSON {
101 0     0 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<< >>
220              
221             =head1 BUGS
222              
223             Please report any bugs or feature requests to C, or through
224             the web interface at L. 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
243              
244             =item * AnnoCPAN: Annotated CPAN documentation
245              
246             L
247              
248             =item * CPAN Ratings
249              
250             L
251              
252             =item * Search CPAN
253              
254             L
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
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; # End of YARN