File Coverage

blib/lib/Siebel/Srvrmgr/ListParser/Output/Tabular/ListComp.pm
Criterion Covered Total %
statement 42 44 95.4
branch 6 10 60.0
condition 5 9 55.5
subroutine 9 9 100.0
pod 1 1 100.0
total 63 73 86.3


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