File Coverage

blib/lib/Siebel/Srvrmgr/ListParser/Output/Tabular/ListComp.pm
Criterion Covered Total %
statement 46 48 95.8
branch 6 10 60.0
condition 5 9 55.5
subroutine 9 9 100.0
pod 1 1 100.0
total 67 77 87.0


line stmt bran cond sub pod time code
1             package Siebel::Srvrmgr::ListParser::Output::Tabular::ListComp;
2              
3             =pod
4              
5             =head1 NAME
6              
7             Siebel::Srvrmgr::ListParser::Output::Tabular::ListComp - subclass that parses list comp commands output of srvrmgr.
8              
9             =cut
10              
11 13     13   386591 use Moose;
  13         686030  
  13         79  
12 13     13   64464 use namespace::autoclean;
  13         3231  
  13         95  
13 13     13   4887 use Siebel::Srvrmgr::ListParser::Output::ListComp::Server;
  13         2924  
  13         446  
14 13     13   79 use Siebel::Srvrmgr::ListParser::Output::ListComp::Comp;
  13         17  
  13         6521  
15              
16             =head1 SYNOPSIS
17              
18             See L<Siebel::Srvrmgr::ListParser::Output::Tabular>.
19              
20             =cut
21              
22             extends 'Siebel::Srvrmgr::ListParser::Output::Tabular';
23              
24             =pod
25              
26             =head1 DESCRIPTION
27              
28             This class extends L<Siebel::Srvrmgr::ListParser::Output::Tabular> base class adding support for parsing C<list comp> commands.
29              
30             The module is capable of identifying output of several servers configured in the enterprise and organizes the components
31             found for each server.
32              
33             It is expected that the C<srvrmgr> program has a proper configuration for the C<list comp> command. The configuration
34             can see below:
35              
36             srvrmgr> configure list comp
37             SV_NAME (31): Server name
38             CC_ALIAS (31): Component alias
39             CC_NAME (76): Component name
40             CT_ALIAS (31): Component type alias
41             CG_ALIAS (31): Component Group Alias
42             CC_RUNMODE (31): Component run mode (enum)
43             CP_DISP_RUN_STATE (61): Component display run state
44             CP_NUM_RUN_TASKS (11): Current number of running tasks
45             CP_MAX_TASKS (11): Maximum tasks configured
46             CP_ACTV_MTS_PROCS (11): Active MTS control processes
47             CP_MAX_MTS_PROCS (11): Maximum MTS control processes
48             CP_START_TIME (21): Component start time
49             CP_END_TIME (21): Component end time
50             CP_STATUS (251): Component-reported status
51             CC_INCARN_NO (23): Incarnation Number
52             CC_DESC_TEXT (251): Component description
53              
54             This output above should be the default but it will be necessary to have the configuration below
55             (check the difference of size for each column):
56              
57             srvrmgr> configure list comp
58             SV_NAME (31): Server name
59             CC_ALIAS (31): Component alias
60             CC_NAME (76): Component name
61             CT_ALIAS (31): Component type alias
62             CG_ALIAS (31): Component GRoup Alias
63             CC_RUNMODE (31): Component run mode (enum)
64             CP_DISP_RUN_STATE (61): Component display run state
65             CP_NUM_RUN_TASKS (16): Current number of running tasks
66             CP_MAX_TASKS (12): Maximum tasks configured
67             CP_ACTV_MTS_PROCS (17): Active MTS control processes
68             CP_MAX_MTS_PROCS (16): Maximum MTS control processes
69             CP_START_TIME (21): Component start time
70             CP_END_TIME (21): Component end time
71             CP_STATUS (251): Component-reported status
72             CC_INCARN_NO (23): Incarnation Number
73             CC_DESC_TEXT (251): Component description
74              
75             because L<Siebel::Srvrmgr::ListParser::Output::Tabular::ListComp::Comp> will expect to have all columns names without being
76             truncated. This class will check those columns names and order and it will raise an exception if it found something different
77             from the expected.
78              
79             To enable that, execute the following commands in the C<srvrmgr> program:
80              
81             set ColumnWidth true
82            
83             configure list components show SV_NAME(31), CC_ALIAS(31), CC_NAME(76), CT_ALIAS(31), CG_ALIAS(31), CC_RUNMODE(31), CP_DISP_RUN_STATE(61),\
84             CP_NUM_RUN_TASKS(16), CP_MAX_TASKS(12), CP_ACTV_MTS_PROCS(17), CP_MAX_MTS_PROCS(16), CP_START_TIME(21), CP_END_TIME(21),\
85             CP_STATUS(251), CC_INCARN_NO(23), CC_DESC_TEXT(251)
86              
87             Saving this configuration as a preference and loading it everytime is a good idea too.
88              
89             =head1 ATTRIBUTES
90              
91             =head2 last_server
92              
93             A string that represents the last associated server from the list of components read from output.
94              
95             By default, the value of it is an empty string.
96              
97             This attribute is used during parsing of C<list comp> command and is a read-only attribute.
98              
99             =cut
100              
101             has 'last_server' => (
102             is => 'ro',
103             isa => 'Str',
104             reader => 'get_last_server',
105             writer => '__set_last_server',
106             default => '',
107             init_arg => undef
108             );
109              
110             =pod
111              
112             =head2 comp_attribs
113              
114             An array reference with the components attributes. This is a read-only attribute.
115              
116             =cut
117              
118             has 'comp_attribs' => (
119             is => 'ro',
120             isa => 'ArrayRef',
121             reader => 'get_comp_attribs',
122             builder => '_build_comp_attribs',
123             writer => '_set_comp_attribs',
124             );
125              
126             =pod
127              
128             =head2 servers
129              
130             This is an array reference with the servers found during processing of the C<list components> output.
131              
132             =cut
133              
134             has 'servers' => (
135             is => 'rw',
136             isa => 'ArrayRef',
137             reader => 'get_servers',
138             default => sub { return [] }
139             );
140              
141             =pod
142              
143             =head1 METHODS
144              
145             =cut
146              
147             sub _build_expected {
148              
149 38     38   63 my $self = shift;
150              
151 38         1555 $self->_set_expected_fields(
152             [
153             'SV_NAME',,
154             'CC_ALIAS', 'CC_NAME',
155             'CT_ALIAS', 'CG_ALIAS',
156             'CC_RUNMODE', 'CP_DISP_RUN_STATE',
157             'CP_NUM_RUN_TASKS', 'CP_MAX_TASKS',
158             'CP_ACTV_MTS_PROCS', 'CP_MAX_MTS_PROCS',
159             'CP_START_TIME', 'CP_END_TIME',
160             'CP_STATUS', 'CC_INCARN_NO',
161             'CC_DESC_TEXT'
162             ]
163             );
164              
165             }
166              
167             sub _build_comp_attribs {
168              
169 38     38   229 my $self = shift;
170              
171 38         1682 $self->_set_comp_attribs(
172             [
173             'CC_NAME', 'CT_ALIAS',
174             'CG_ALIAS', 'CC_RUNMODE',
175             'CP_DISP_RUN_STATE', 'CP_NUM_RUN_TASKS',
176             'CP_MAX_TASKS', 'CP_ACTV_MTS_PROCS',
177             'CP_MAX_MTS_PROCS', 'CP_START_TIME',
178             'CP_END_TIME', 'CP_STATUS',
179             'CC_INCARN_NO', 'CC_DESC_TEXT'
180             ]
181             );
182              
183             }
184              
185             =pod
186              
187             =head2 get_comp_attribs
188              
189             Returns the value of C<comp_attribs> attribute.
190              
191             =head2 get_last_server
192              
193             Returns the C<last_server> attribute.
194              
195             =head2 get_servers
196              
197             Returns the value of C<servers> attribute.
198              
199             =head2 get_server
200              
201             Expects as parameter the name of a server which output was parsed.
202              
203             If the server exists in the C<servers> attribute, it returns a L<Siebel::Srvrmgr::ListParser::Output::Tabular::ListComp::Server>
204             object. Otherwise it will return C<undef>.
205              
206             =cut
207              
208             sub get_server {
209              
210 29     29 1 72 my $self = shift;
211 29         51 my $servername = shift;
212              
213 29 50       952 if ( exists( $self->get_data_parsed()->{$servername} ) ) {
214              
215 29         843 return Siebel::Srvrmgr::ListParser::Output::ListComp::Server->new(
216             {
217             name => $servername,
218             data => $self->get_data_parsed()->{$servername},
219             comp_attribs => $self->get_comp_attribs()
220             }
221             );
222              
223             }
224             else {
225              
226 0         0 return undef;
227              
228             }
229              
230             }
231              
232             sub _set_last_server {
233              
234 45     45   73 my $self = shift;
235 45         61 my $server = shift;
236              
237 45         1606 $self->__set_last_server($server);
238 45         53 push( @{ $self->get_servers() }, $server );
  45         1651  
239              
240             }
241              
242             sub _consume_data {
243              
244 1317     1317   1024 my $self = shift;
245 1317         899 my $fields_ref = shift;
246 1317         865 my $parsed_ref = shift;
247              
248 1317         2619 confess 'invalid fields parameter'
249             unless ( ( defined($fields_ref) )
250             and ( ( ref($fields_ref) ) eq 'ARRAY' )
251 1317 50 33     3986 and ( ( scalar( @{$fields_ref} ) ) > 0 ) );
      33        
252              
253 1317         922 my $server = shift( @{$fields_ref} );
  1317         1441  
254              
255             # do not need the servername again
256 1317 100 100     45963 if ( ( $self->get_last_server() eq '' )
257             or ( $self->get_last_server() ne $server ) )
258             {
259              
260 45         160 $self->_set_last_server($server);
261              
262             }
263              
264 1317         1101 my $comp_alias = shift( @{$fields_ref} );
  1317         1434  
265              
266 1317         897 my $list_len = scalar( @{$fields_ref} );
  1317         1041  
267              
268             # :TODO :08/05/2013 18:19:48:: replace comp_attribs with header_cols? seems to be the same thing
269 1317         43702 my $columns_ref = $self->get_comp_attribs();
270              
271 1317 50       1751 confess "Cannot continue without defining fields names"
272             unless ( defined($columns_ref) );
273              
274 1317 50       874 if ( @{$fields_ref} ) {
  1317         1831  
275              
276 1317         43007 my $server = $self->get_last_server();
277              
278 1317         2223 for ( my $i = 0 ; $i < $list_len ; $i++ ) {
279              
280             # :TODO :02-12-2013 07:56:56:: we already know the sequence names of fields of a component, we can
281             # make lazy instantiation of object using this information, so an array here would use less memory instead of using a
282             # hash reference to keep column_name => value
283 18438         36941 $parsed_ref->{$server}->{$comp_alias}->{ $columns_ref->[$i] } =
284             $fields_ref->[$i];
285              
286             }
287              
288 1317         5164 return 1;
289              
290             }
291             else {
292              
293 0           return 0;
294              
295             }
296              
297             }
298              
299             =pod
300              
301             =head1 SEE ALSO
302              
303             =over
304              
305             =item *
306              
307             L<Moose>
308              
309             =item *
310              
311             L<Siebel::Srvrmgr::ListParser::Output::Tabular>
312              
313             =item *
314              
315             L<Siebel::Srvrmgr::ListParser::Output::ListComp::Server>
316              
317             =item *
318              
319             L<Siebel::Srvrmgr::ListParser::Output::ListComp::Comp>
320              
321             =item *
322              
323             L<Siebel::Srvrmgr::ListParser::Output::ToString>
324              
325             =back
326              
327             =head1 AUTHOR
328              
329             Alceu Rodrigues de Freitas Junior, E<lt>arfreitas@cpan.orgE<gt>.
330              
331             =head1 COPYRIGHT AND LICENSE
332              
333             This software is copyright (c) 2012 of Alceu Rodrigues de Freitas Junior, E<lt>arfreitas@cpan.orgE<gt>.
334              
335             This file is part of Siebel Monitoring Tools.
336              
337             Siebel Monitoring Tools is free software: you can redistribute it and/or modify
338             it under the terms of the GNU General Public License as published by
339             the Free Software Foundation, either version 3 of the License, or
340             (at your option) any later version.
341              
342             Siebel Monitoring Tools is distributed in the hope that it will be useful,
343             but WITHOUT ANY WARRANTY; without even the implied warranty of
344             MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
345             GNU General Public License for more details.
346              
347             You should have received a copy of the GNU General Public License
348             along with Siebel Monitoring Tools. If not, see L<http://www.gnu.org/licenses/>.
349              
350             =cut
351              
352             __PACKAGE__->meta->make_immutable;
353