File Coverage

blib/lib/Siebel/Srvrmgr/ListParser/Output/Tabular/ListTasks.pm
Criterion Covered Total %
statement 54 60 90.0
branch 15 18 83.3
condition 2 3 66.6
subroutine 10 11 90.9
pod 3 3 100.0
total 84 95 88.4


line stmt bran cond sub pod time code
1             package Siebel::Srvrmgr::ListParser::Output::Tabular::ListTasks;
2              
3 4     4   8260 use Moose;
  4         186116  
  4         27  
4 4     4   19642 use Siebel::Srvrmgr::ListParser::Output::ListTasks::Task;
  4         8641  
  4         153  
5 4     4   25 use namespace::autoclean;
  4         5  
  4         25  
6 4     4   260 use Siebel::Srvrmgr::Regexes qw(SIEBEL_SERVER);
  4         5  
  4         2114  
7              
8             =pod
9              
10             =head1 NAME
11              
12             Siebel::Srvrmgr::ListParser::Output::Tabular::ListTasks - subclass to parse list tasks command
13              
14             =cut
15              
16             extends 'Siebel::Srvrmgr::ListParser::Output::Tabular';
17              
18             =pod
19              
20             =head1 SYNOPSIS
21              
22             See L<Siebel::Srvrmgr::ListParser::Output::Tabular> for examples.
23              
24             =head1 DESCRIPTION
25              
26             This subclass of L<Siebel::Srvrmgr::ListParser::Output::Tabular> parses the output of the command C<list tasks>.
27              
28             It is expected that the C<srvrmgr> program has a proper configuration for the C<list tasks> command. The default configuration
29             can be seen below:
30              
31             srvrmgr> configure list tasks
32             SV_NAME (31): Server name
33             CC_ALIAS (31): Component alias
34             TK_TASKID (11): Internal task id
35             TK_PID (11): Task process id
36             TK_DISP_RUNSTATE (61): Task run state
37             CC_RUNMODE (31): Task run mode
38             TK_START_TIME (21): Task start time
39             TK_END_TIME (21): Task end time
40             TK_STATUS (251): Task-reported status
41             CG_ALIAS (31): Component group alias
42             TK_PARENT_TASKNUM (11): Parent task id
43             CC_INCARN_NO (23): Incarnation Number
44             TK_LABEL (76): Task Label
45             TK_TASKTYPE (31): Task Type
46             TK_PING_TIME (11): Last ping time for task
47              
48             If you want to use fixed width configuration from C<srvrmgr> this will be the expected configuration:
49              
50             srvrmgr> configure list tasks
51             SV_NAME (31): Server name
52             CC_ALIAS (31): Component alias
53             TK_TASKID (11): Internal task id
54             TK_PID (11): Task process id
55             TK_DISP_RUNSTATE (61): Task run state
56              
57             If you want to use the field delimited output from C<srvrmgr> then this the expected configuration:
58              
59             srvrmgr> configure list tasks
60             SV_NAME (31): Server name
61             CC_ALIAS (31): Component alias
62             TK_TASKID (11): Internal task id
63             TK_PID (11): Task process id
64             TK_DISP_RUNSTATE (61): Task run state
65             CC_RUNMODE (31): Task run mode
66             TK_START_TIME (21): Task start time
67             TK_END_TIME (21): Task end time
68             TK_STATUS (251): Task-reported status
69             CG_ALIAS (31): Component group alias
70             TK_PARENT_TASKNUM (18): Parent task id
71             CC_INCARN_NO (23): Incarnation Number
72             TK_LABEL (76): Task Label
73             TK_TASKTYPE (31): Task Type
74             TK_PING_TIME (12): Last ping time for task
75              
76             The order of the fields is important too: everytime those fields are parsed, if they do not follow the order above an exception
77             will be raised.
78              
79             =cut
80              
81             sub _build_expected {
82              
83 16     16   27 my $self = shift;
84              
85 16 100       461 if ( $self->get_type() eq 'delimited' ) {
86              
87 7         256 $self->_set_expected_fields(
88             [
89             'SV_NAME', 'CC_ALIAS',
90             'TK_TASKID', 'TK_PID',
91             'TK_DISP_RUNSTATE', 'CC_RUNMODE',
92             'TK_START_TIME', 'TK_END_TIME',
93             'TK_STATUS', 'CG_ALIAS',
94             'TK_PARENT_TASKNUM', 'CC_INCARN_NO',
95             'TK_LABEL', 'TK_TASKTYPE',
96             'TK_PING_TIME'
97             ]
98             );
99              
100             }
101             else {
102              
103 9         315 $self->_set_expected_fields(
104             [
105             'SV_NAME', 'CC_ALIAS', 'TK_TASKID', 'TK_PID',
106             'TK_DISP_RUNSTATE'
107             ]
108             );
109              
110             }
111              
112             }
113              
114             =pod
115              
116             =head1 METHODS
117              
118             Some methods from the parent classes are overrided.
119              
120             =head2 get_servers
121              
122             Returns a list of the Siebel Server names from the parsed output.
123              
124             =cut
125              
126             sub get_servers {
127              
128 2     2 1 17 my $self = shift;
129              
130 2         4 return keys( %{ $self->get_data_parsed() } );
  2         109  
131              
132             }
133              
134             =pod
135              
136             =head2 count_tasks
137              
138             Returns an integer representing the number of tasks recovered from the parsed output.
139              
140             Expects a string as parameter being the Siebel Server name, so the number of tasks are those related to the
141             server passed as argument.
142              
143             =cut
144              
145             sub count_tasks {
146              
147 0     0 1 0 my $self = shift;
148 0         0 my $server = shift;
149              
150 0         0 my $server_ref = $self->_val_tasks_server($server);
151              
152 0         0 return scalar( @{$server_ref} );
  0         0  
153              
154             }
155              
156             sub _val_tasks_server {
157              
158 8     8   8 my $self = shift;
159 8         9 my $server = shift;
160              
161 8 100 66     84 confess 'Siebel Server name parameter is required and must be valid'
162             unless ( ( defined($server) ) and ( $server =~ SIEBEL_SERVER ) );
163              
164 4         214 my $data_ref = $self->get_data_parsed;
165              
166 4 100       36 confess "servername '$server' is not available in the output parsed"
167             unless ( exists( $data_ref->{$server} ) );
168              
169 2         6 return $data_ref->{$server};
170              
171             }
172              
173             =pod
174              
175             =head2 get_tasks
176              
177             Returns an iterator to iterate over the list of tasks of a Siebel Server given as argument.
178              
179             At each invocation of the iterator, a instance of L<Siebel::Srvrmgr::ListParser::Output::ListTasks::Task> is return,
180             or C<undef> in the case that there are no more tasks to return.
181              
182             Beware that depending on the type of output parsed, the returned instances will have more or less attributes with
183             values.
184              
185             To be compatible with the role L<Siebel::Srvrmgr::ListParser::Output::Duration>, fixed width output data will have a default
186             value of '2000-00-00 00:00:00' for C<start_datetime> attribute, which is basically useless if you that kind of information.
187             You should use delimited data for that.
188              
189             =cut
190              
191             sub get_tasks {
192              
193 8     8 1 207 my $self = shift;
194 8         11 my $server = shift;
195 8         8 my $counter = 0;
196              
197 8         17 my $server_ref = $self->_val_tasks_server($server);
198              
199 2         3 my $total = scalar( @{$server_ref} ) - 1;
  2         6  
200              
201             return sub {
202              
203 41 100   41   950 if ( $counter <= $total ) {
204              
205 39         81 my $fields_ref = $server_ref->[$counter];
206              
207 39         49 $counter++;
208              
209 39 100       1525 if ( $self->get_type() eq 'fixed' ) {
210              
211 20         867 return Siebel::Srvrmgr::ListParser::Output::ListTasks::Task
212             ->new(
213             {
214             server_name => $fields_ref->[0],
215             comp_alias => $fields_ref->[1],
216             id => $fields_ref->[2],
217             pid => $fields_ref->[3],
218             run_state => $fields_ref->[4],
219             start_datetime => '2000-00-00 00:00:00'
220             }
221             );
222              
223             }
224             else {
225              
226 19         301 my %params = (
227             server_name => $fields_ref->[0],
228             comp_alias => $fields_ref->[1],
229             id => $fields_ref->[2],
230             pid => $fields_ref->[3],
231             run_state => $fields_ref->[4],
232             run_mode => $fields_ref->[5],
233             start_datetime => $fields_ref->[6],
234             end_datetime => $fields_ref->[7],
235             status => $fields_ref->[8],
236             group_alias => $fields_ref->[9],
237             label => $fields_ref->[12],
238             type => $fields_ref->[13],
239             ping_time => $fields_ref->[14]
240             );
241              
242 19 50       71 $params{parent_id} = $fields_ref->[10]
243             unless ( $fields_ref->[10] eq '' );
244 19 50       98 $params{incarn_no} = $fields_ref->[11]
245             unless ( $fields_ref->[11] eq '' );
246              
247 19         755 return Siebel::Srvrmgr::ListParser::Output::ListTasks::Task
248             ->new( \%params );
249              
250             }
251              
252             }
253             else {
254              
255 2         7 return undef;
256              
257             }
258              
259             } # end of sub block
260 2         17 }
261              
262             sub _consume_data {
263              
264 1478     1478   1079 my $self = shift;
265 1478         882 my $fields_ref = shift;
266 1478         860 my $parsed_ref = shift;
267              
268 1478         932 my $list_len = scalar( @{$fields_ref} );
  1478         1079  
269 1478         1249 my $server_name = $fields_ref->[0];
270              
271 1478 100       2009 $parsed_ref->{$server_name} = []
272             unless ( exists( $parsed_ref->{$server_name} ) );
273              
274 1478 50       857 if ( @{$fields_ref} ) {
  1478         1640  
275              
276 1478         866 push( @{ $parsed_ref->{$server_name} }, $fields_ref );
  1478         1641  
277              
278 1478         3684 return 1;
279              
280             }
281             else {
282              
283 0           return 0;
284              
285             }
286              
287             }
288              
289             =pod
290              
291             =head1 CAVEATS
292              
293             Unfornately the results of C<list tasks> command does not works as expected if a fixed width output type is selected due a bug with
294             the C<srvrmgr> itself in recent versions of Siebel (8 and beyond).
295              
296             Even though a L<Siebel::Srvrmgr::ListParser> instance is capable of identifying a C<list tasks> command output, this class is
297             not being able to properly parse the output from the command.
298              
299             The problem is that the output is not following the expected fixed width as setup with the
300             C<configure list tasks show...> command: with that, the output width is resized depending on the content of each
301             column and thus impossible to predict how to parse it correctly.
302              
303             That said, this class will make all the fields available from C<list tasks> if a field delimited output was
304             configured within srvrmgr.
305              
306             This problems does not happens when a delimited output is selected, so all fields will be available.
307              
308             =head1 SEE ALSO
309              
310             =over
311              
312             =item *
313              
314             L<Siebel::Srvrmgr::ListParser::Output::Tabular>
315              
316             =item *
317              
318             L<Moose>
319              
320             =item *
321              
322             L<Siebel::Srvrmgr::ListParser::Output::ListTasks::Task>
323              
324             =item *
325              
326             L<Siebel::Srvrmgr::ListParser::Output::ToString>
327              
328             =item *
329              
330             L<Siebel::Srvrmgr::ListParser::Output::Duration>
331              
332             =back
333              
334             =head1 AUTHOR
335              
336             Alceu Rodrigues de Freitas Junior, E<lt>arfreitas@cpan.orgE<gt>.
337              
338             =head1 COPYRIGHT AND LICENSE
339              
340             This software is copyright (c) 2013 of Alceu Rodrigues de Freitas Junior, E<lt>arfreitas@cpan.orgE<gt>.
341              
342             This file is part of Siebel Monitoring Tools.
343              
344             Siebel Monitoring Tools is free software: you can redistribute it and/or modify
345             it under the terms of the GNU General Public License as published by
346             the Free Software Foundation, either version 3 of the License, or
347             (at your option) any later version.
348              
349             Siebel Monitoring Tools is distributed in the hope that it will be useful,
350             but WITHOUT ANY WARRANTY; without even the implied warranty of
351             MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
352             GNU General Public License for more details.
353              
354             You should have received a copy of the GNU General Public License
355             along with Siebel Monitoring Tools. If not, see L<http://www.gnu.org/licenses/>.
356              
357             =cut
358              
359             __PACKAGE__->meta->make_immutable;