| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# |
|
2
|
|
|
|
|
|
|
# CA::WAAE - Perl Interface to CA's Workflow Automation AutoSys Edition job control. |
|
3
|
|
|
|
|
|
|
# |
|
4
|
|
|
|
|
|
|
# Original CA::AutoSys code: |
|
5
|
|
|
|
|
|
|
# Copyright (c) 2007 Sinisa Susnjar |
|
6
|
|
|
|
|
|
|
# See LICENSE for terms of distribution. |
|
7
|
|
|
|
|
|
|
# |
|
8
|
|
|
|
|
|
|
# This library is free software; you can redistribute it and/or |
|
9
|
|
|
|
|
|
|
# modify it under the terms of the GNU Lesser General Public |
|
10
|
|
|
|
|
|
|
# License as published by the Free Software Foundation; either |
|
11
|
|
|
|
|
|
|
# version 2.1 of the License, or (at your option) any later version. |
|
12
|
|
|
|
|
|
|
# |
|
13
|
|
|
|
|
|
|
# This library is distributed in the hope that it will be useful, |
|
14
|
|
|
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15
|
|
|
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
16
|
|
|
|
|
|
|
# Lesser General Public License for more details. |
|
17
|
|
|
|
|
|
|
# |
|
18
|
|
|
|
|
|
|
# You should have received a copy of the GNU Lesser General Public |
|
19
|
|
|
|
|
|
|
# License along with this library; if not, write to the Free Software |
|
20
|
|
|
|
|
|
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
21
|
|
|
|
|
|
|
# |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
package CA::WAAE::JobList; |
|
24
|
|
|
|
|
|
|
|
|
25
|
1
|
|
|
1
|
|
5
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
32
|
|
|
26
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
388
|
|
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
my $debug = 0; |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub new { |
|
33
|
0
|
|
|
0
|
|
|
my $self = {}; |
|
34
|
0
|
|
|
|
|
|
my $class = shift(); |
|
35
|
|
|
|
|
|
|
|
|
36
|
0
|
0
|
|
|
|
|
if (@_) { |
|
37
|
0
|
|
|
|
|
|
my %args = @_; |
|
38
|
0
|
0
|
|
|
|
|
$self->{parent} = $args{parent} ? $args{parent} : undef; |
|
39
|
0
|
0
|
|
|
|
|
$self->{dbh} |
|
40
|
|
|
|
|
|
|
= $args{database_handle} ? $args{database_handle} : undef; |
|
41
|
0
|
0
|
|
|
|
|
$self->{sth} |
|
42
|
|
|
|
|
|
|
= $args{statement_handle} ? $args{statement_handle} : undef; |
|
43
|
0
|
0
|
|
|
|
|
$self->{parent_job} = $args{parent_job} ? $args{parent_job} : undef; |
|
44
|
0
|
0
|
|
|
|
|
$self->{table_prefix} |
|
45
|
|
|
|
|
|
|
= $args{table_prefix} ? $args{table_prefix} : undef; |
|
46
|
|
|
|
|
|
|
} |
|
47
|
|
|
|
|
|
|
|
|
48
|
0
|
0
|
|
|
|
|
if ($debug) { printf( "DEBUG: Job(%s) created.\n", $self ); } |
|
|
0
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
|
|
50
|
0
|
|
|
|
|
|
bless($self); |
|
51
|
0
|
|
|
|
|
|
return $self; |
|
52
|
|
|
|
|
|
|
} # new() |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub _fetch_next { |
|
55
|
0
|
|
|
0
|
|
|
my $self = shift; |
|
56
|
0
|
0
|
|
|
|
|
if ($debug) { printf( "DEBUG: Job(%s): _fetch_next()\n", $self ); } |
|
|
0
|
|
|
|
|
|
|
|
57
|
0
|
0
|
|
|
|
|
if ( my $h = $self->{sth}->fetchrow_hashref('NAME_lc') ) { |
|
58
|
0
|
|
|
|
|
|
return CA::WAAE::Job->new( %$self, %$h ); |
|
59
|
|
|
|
|
|
|
} |
|
60
|
|
|
|
|
|
|
else { |
|
61
|
0
|
|
|
|
|
|
$self->{sth}->finish(); |
|
62
|
0
|
|
|
|
|
|
delete $self->{sth}; |
|
63
|
0
|
|
|
|
|
|
return undef; |
|
64
|
|
|
|
|
|
|
} |
|
65
|
|
|
|
|
|
|
} # _fetch_next() |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub next_job { |
|
68
|
0
|
|
|
0
|
|
|
my $self = shift(); |
|
69
|
0
|
0
|
|
|
|
|
if ($debug) { printf( "DEBUG: Job(%s): next_job()\n", $self ); } |
|
|
0
|
|
|
|
|
|
|
|
70
|
0
|
|
|
|
|
|
return $self->_fetch_next(); |
|
71
|
|
|
|
|
|
|
} # next_job() |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub next_child { |
|
74
|
0
|
|
|
0
|
|
|
my $self = shift(); |
|
75
|
0
|
0
|
|
|
|
|
if ($debug) { printf( "DEBUG: Job(%s): next_child()\n", $self ); } |
|
|
0
|
|
|
|
|
|
|
|
76
|
0
|
|
|
|
|
|
return $self->_fetch_next(); |
|
77
|
|
|
|
|
|
|
} # next_child() |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
package CA::WAAE::Job; |
|
80
|
|
|
|
|
|
|
|
|
81
|
1
|
|
|
1
|
|
1098
|
use Time::Piece qw(localtime); |
|
|
1
|
|
|
|
|
15158
|
|
|
|
1
|
|
|
|
|
7
|
|
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
our %status_names = ( |
|
84
|
|
|
|
|
|
|
0 => ' ', # *empty* |
|
85
|
|
|
|
|
|
|
1 => 'RU', # running |
|
86
|
|
|
|
|
|
|
2 => ' 2', # *not defined* |
|
87
|
|
|
|
|
|
|
3 => 'ST', # starting |
|
88
|
|
|
|
|
|
|
4 => 'SU', # success |
|
89
|
|
|
|
|
|
|
5 => 'FA', # failure |
|
90
|
|
|
|
|
|
|
6 => 'TE', # terminated |
|
91
|
|
|
|
|
|
|
7 => 'OI', # on ice |
|
92
|
|
|
|
|
|
|
8 => 'IN', # inactive |
|
93
|
|
|
|
|
|
|
9 => 'AC', # activated |
|
94
|
|
|
|
|
|
|
10 => 'RE', # restart |
|
95
|
|
|
|
|
|
|
11 => 'OH', # on hold |
|
96
|
|
|
|
|
|
|
12 => 'QW', # queue wait |
|
97
|
|
|
|
|
|
|
13 => '13', # *not defined* |
|
98
|
|
|
|
|
|
|
14 => 'RD', # refresh dependencies |
|
99
|
|
|
|
|
|
|
15 => 'RF', # refresh filewatcher |
|
100
|
|
|
|
|
|
|
); |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
use constant { |
|
103
|
1
|
|
|
|
|
332
|
NONE => 0, |
|
104
|
|
|
|
|
|
|
RUNNING => 1, |
|
105
|
|
|
|
|
|
|
UNDEF_2 => 2, |
|
106
|
|
|
|
|
|
|
STARTING => 3, |
|
107
|
|
|
|
|
|
|
SUCCESS => 4, |
|
108
|
|
|
|
|
|
|
FAILURE => 5, |
|
109
|
|
|
|
|
|
|
TERMINATED => 6, |
|
110
|
|
|
|
|
|
|
ON_ICE => 7, |
|
111
|
|
|
|
|
|
|
INACTIVE => 8, |
|
112
|
|
|
|
|
|
|
ACTIVATED => 9, |
|
113
|
|
|
|
|
|
|
RESTART => 10, |
|
114
|
|
|
|
|
|
|
ON_HOLD => 11, |
|
115
|
|
|
|
|
|
|
QUEUE_WAIT => 12, |
|
116
|
|
|
|
|
|
|
UNDEF_13 => 13, |
|
117
|
|
|
|
|
|
|
REFRESH_DEP => 14, |
|
118
|
|
|
|
|
|
|
REFRESH_FW => 15 |
|
119
|
1
|
|
|
1
|
|
145
|
}; |
|
|
1
|
|
|
|
|
2
|
|
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
our %long_status = ( |
|
122
|
|
|
|
|
|
|
0 => "NONE", |
|
123
|
|
|
|
|
|
|
1 => "RUNNING", |
|
124
|
|
|
|
|
|
|
2 => "UNDEF_2", |
|
125
|
|
|
|
|
|
|
3 => "STARTING", |
|
126
|
|
|
|
|
|
|
4 => "SUCCESS", |
|
127
|
|
|
|
|
|
|
5 => "FAILURE", |
|
128
|
|
|
|
|
|
|
6 => "TERMINATED", |
|
129
|
|
|
|
|
|
|
7 => "ON_ICE", |
|
130
|
|
|
|
|
|
|
8 => "INACTIVE", |
|
131
|
|
|
|
|
|
|
9 => "ACTIVATED", |
|
132
|
|
|
|
|
|
|
10 => "RESTART", |
|
133
|
|
|
|
|
|
|
11 => "ON_HOLD", |
|
134
|
|
|
|
|
|
|
12 => "QUEUE_WAIT", |
|
135
|
|
|
|
|
|
|
13 => "UNDEF_13", |
|
136
|
|
|
|
|
|
|
14 => "REFRESH_DEP", |
|
137
|
|
|
|
|
|
|
15 => "REFRESH_FW" |
|
138
|
|
|
|
|
|
|
); |
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
sub new { |
|
141
|
0
|
|
|
0
|
0
|
|
my $class = shift; |
|
142
|
0
|
|
|
|
|
|
my %args = @_; |
|
143
|
0
|
|
|
|
|
|
my $self = bless {%args}, $class; |
|
144
|
0
|
|
|
|
|
|
return $self; |
|
145
|
|
|
|
|
|
|
} |
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
my @command_attr = qw( |
|
148
|
|
|
|
|
|
|
chk_files |
|
149
|
|
|
|
|
|
|
command |
|
150
|
|
|
|
|
|
|
envvars |
|
151
|
|
|
|
|
|
|
heartbeat_interval |
|
152
|
|
|
|
|
|
|
interactive |
|
153
|
|
|
|
|
|
|
is_script |
|
154
|
|
|
|
|
|
|
over_num |
|
155
|
|
|
|
|
|
|
shell |
|
156
|
|
|
|
|
|
|
std_err_file |
|
157
|
|
|
|
|
|
|
std_in_file |
|
158
|
|
|
|
|
|
|
std_out_file |
|
159
|
|
|
|
|
|
|
ulimit |
|
160
|
|
|
|
|
|
|
userid |
|
161
|
|
|
|
|
|
|
elevated |
|
162
|
|
|
|
|
|
|
criteria |
|
163
|
|
|
|
|
|
|
dbtype |
|
164
|
|
|
|
|
|
|
dburl |
|
165
|
|
|
|
|
|
|
dbuserid |
|
166
|
|
|
|
|
|
|
dbuserrole |
|
167
|
|
|
|
|
|
|
monitor_condition |
|
168
|
|
|
|
|
|
|
monitor_type |
|
169
|
|
|
|
|
|
|
obj_name |
|
170
|
|
|
|
|
|
|
params |
|
171
|
|
|
|
|
|
|
params_num |
|
172
|
|
|
|
|
|
|
rtn_type |
|
173
|
|
|
|
|
|
|
trig_condition |
|
174
|
|
|
|
|
|
|
trig_type |
|
175
|
|
|
|
|
|
|
); |
|
176
|
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
for my $attr (@command_attr) { |
|
178
|
1
|
|
|
1
|
|
5
|
no strict 'refs'; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
690
|
|
|
179
|
|
|
|
|
|
|
*$attr = sub { |
|
180
|
0
|
|
|
0
|
|
|
my $self = shift; |
|
181
|
0
|
0
|
|
|
|
|
my $data = $self->get_data() or return; |
|
182
|
0
|
|
|
|
|
|
$data->{$attr}; |
|
183
|
|
|
|
|
|
|
}; |
|
184
|
|
|
|
|
|
|
} |
|
185
|
|
|
|
|
|
|
|
|
186
|
0
|
|
|
0
|
1
|
|
sub job_type { $_[0]->{job_type_name} } |
|
187
|
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
my %job_table = ( |
|
189
|
|
|
|
|
|
|
CMD => 'command_job', |
|
190
|
|
|
|
|
|
|
SQL => 'sql_job', |
|
191
|
|
|
|
|
|
|
); |
|
192
|
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
sub get_data { |
|
194
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
195
|
0
|
|
|
|
|
|
my $job_type = $self->job_type(); |
|
196
|
0
|
0
|
|
|
|
|
my $table = $job_table{$job_type} or return; |
|
197
|
0
|
0
|
|
|
|
|
return $self->{JOB} if $self->{JOB}; |
|
198
|
|
|
|
|
|
|
|
|
199
|
0
|
0
|
|
|
|
|
my $job_id = $self->{joid} or return; |
|
200
|
0
|
0
|
|
|
|
|
return unless defined $job_id; |
|
201
|
0
|
|
0
|
|
|
|
my $prefix = $self->{table_prefix} || ''; |
|
202
|
0
|
|
|
|
|
|
my $sql = <
|
|
203
|
|
|
|
|
|
|
select * |
|
204
|
|
|
|
|
|
|
from ${prefix}$table |
|
205
|
|
|
|
|
|
|
where joid = ? |
|
206
|
|
|
|
|
|
|
SQL |
|
207
|
0
|
|
|
|
|
|
my $sth = $self->{dbh}->prepare($sql); |
|
208
|
0
|
|
|
|
|
|
$sth->execute($job_id); |
|
209
|
0
|
0
|
|
|
|
|
my $command_data = $sth->fetchrow_hashref('NAME_lc') or return; |
|
210
|
0
|
|
|
|
|
|
$sth->finish; |
|
211
|
0
|
|
|
|
|
|
$self->{JOB} = $command_data; |
|
212
|
|
|
|
|
|
|
} |
|
213
|
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
sub find_children { |
|
215
|
0
|
|
|
0
|
1
|
|
my $self = shift(); |
|
216
|
0
|
0
|
|
|
|
|
if ($debug) { printf( "DEBUG: Job(%s): find_children()\n", $self ); } |
|
|
0
|
|
|
|
|
|
|
|
217
|
0
|
|
|
|
|
|
my $query = $self->{parent}->_query() . <
|
|
218
|
|
|
|
|
|
|
where j.box_joid = $self->{joid} |
|
219
|
|
|
|
|
|
|
order by j.joid |
|
220
|
|
|
|
|
|
|
SQL |
|
221
|
0
|
|
|
|
|
|
my $sth = $self->{dbh}->prepare($query); |
|
222
|
0
|
0
|
|
|
|
|
if ($debug) { |
|
223
|
0
|
|
|
|
|
|
printf( "DEBUG: Job(%s): selecting children for joid %d\n", |
|
224
|
|
|
|
|
|
|
$self, $self->{joid} ); |
|
225
|
|
|
|
|
|
|
} |
|
226
|
0
|
|
|
|
|
|
$sth->execute(); |
|
227
|
0
|
|
|
|
|
|
return CA::WAAE::JobList->new( |
|
228
|
|
|
|
|
|
|
parent => $self->{parent}, |
|
229
|
|
|
|
|
|
|
database_handle => $self->{dbh}, |
|
230
|
|
|
|
|
|
|
statement_handle => $sth, |
|
231
|
|
|
|
|
|
|
parent_job => $self |
|
232
|
|
|
|
|
|
|
); |
|
233
|
|
|
|
|
|
|
} |
|
234
|
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
sub children { |
|
236
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
237
|
0
|
|
|
|
|
|
my $h = $self->find_children(); |
|
238
|
0
|
|
|
|
|
|
my @list; |
|
239
|
0
|
|
|
|
|
|
while ( my $job = $h->next_job() ) { |
|
240
|
0
|
|
|
|
|
|
push @list, $job; |
|
241
|
|
|
|
|
|
|
} |
|
242
|
0
|
0
|
|
|
|
|
return wantarray ? @list : \@list; |
|
243
|
|
|
|
|
|
|
} |
|
244
|
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
sub status { |
|
246
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
247
|
0
|
|
0
|
|
|
|
my $status = shift || $self->{status}; |
|
248
|
0
|
|
|
|
|
|
return $status_names{$status}; |
|
249
|
|
|
|
|
|
|
} |
|
250
|
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
sub long_status { |
|
252
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
253
|
0
|
|
0
|
|
|
|
my $status = shift || $self->{status}; |
|
254
|
0
|
|
|
|
|
|
return $long_status{$status}; |
|
255
|
|
|
|
|
|
|
} |
|
256
|
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
sub time { |
|
258
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
259
|
0
|
|
|
|
|
|
my $tm = shift; |
|
260
|
0
|
0
|
0
|
|
|
|
$tm = $self->{$tm} if defined($tm) and $tm =~ /\D/; |
|
261
|
0
|
0
|
0
|
|
|
|
return if !defined($tm) || $tm == 999999999; |
|
262
|
0
|
|
|
|
|
|
localtime($tm); |
|
263
|
|
|
|
|
|
|
} |
|
264
|
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
sub strftime { |
|
266
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
267
|
0
|
|
|
|
|
|
my $time = shift; |
|
268
|
0
|
|
0
|
|
|
|
my $fmt = shift || "%Y-%m-%d %H:%M:%S"; |
|
269
|
0
|
0
|
|
|
|
|
my $tm = $self->time($time) or return; |
|
270
|
0
|
|
|
|
|
|
return $tm->strftime($fmt); |
|
271
|
|
|
|
|
|
|
} |
|
272
|
|
|
|
|
|
|
|
|
273
|
|
|
|
|
|
|
1; |
|
274
|
|
|
|
|
|
|
|
|
275
|
|
|
|
|
|
|
__END__ |