line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
################################################################################ |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# $Id: Rerun.pm 219 2009-06-09 03:30:29Z aijaz $ |
4
|
|
|
|
|
|
|
# |
5
|
|
|
|
|
|
|
################################################################################ |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 NAME |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
TaskForest::Rerun - Functions related to rerunning a job |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 SYNOPSIS |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
use TaskForest::Rerun; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
&TaskForest::Rerun::rerun($family_name, $job_name) |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 DOCUMENTATION |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
If you're just looking to use the taskforest application, the only |
20
|
|
|
|
|
|
|
documentation you need to read is that for TaskForest. You can do this |
21
|
|
|
|
|
|
|
either of the two ways: |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
perldoc TaskForest |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
OR |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
man TaskForest |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=head1 DESCRIPTION |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
This is a simple package that provides a location for the rerun |
32
|
|
|
|
|
|
|
function, so that it can be used in the test scripts as well. |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=head1 METHODS |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=cut |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
package TaskForest::Rerun; |
39
|
7
|
|
|
7
|
|
9203
|
use strict; |
|
7
|
|
|
|
|
19
|
|
|
7
|
|
|
|
|
254
|
|
40
|
7
|
|
|
7
|
|
40
|
use warnings; |
|
7
|
|
|
|
|
15
|
|
|
7
|
|
|
|
|
183
|
|
41
|
7
|
|
|
7
|
|
37
|
use Carp; |
|
7
|
|
|
|
|
15
|
|
|
7
|
|
|
|
|
407
|
|
42
|
7
|
|
|
7
|
|
43
|
use File::Copy; |
|
7
|
|
|
|
|
28
|
|
|
7
|
|
|
|
|
417
|
|
43
|
7
|
|
|
7
|
|
41
|
use TaskForest::Family; |
|
7
|
|
|
|
|
22
|
|
|
7
|
|
|
|
|
223
|
|
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
BEGIN { |
46
|
7
|
|
|
7
|
|
37
|
use vars qw($VERSION); |
|
7
|
|
|
|
|
14
|
|
|
7
|
|
|
|
|
304
|
|
47
|
7
|
|
|
7
|
|
8535
|
$VERSION = '1.30'; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------ |
52
|
|
|
|
|
|
|
=pod |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=over 4 |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=item rerun() |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
Usage : rerun($family_name, $job_name, $log_dir) |
59
|
|
|
|
|
|
|
Purpose : Rerun the specified job. The existing job files will be |
60
|
|
|
|
|
|
|
renamed to $family_name.$job_name--Orig_$n--.* where $n |
61
|
|
|
|
|
|
|
is the next sequence number (starting from 1). |
62
|
|
|
|
|
|
|
Returns : Nothing |
63
|
|
|
|
|
|
|
Arguments : $family_name - the family name |
64
|
|
|
|
|
|
|
$job_name - the job name |
65
|
|
|
|
|
|
|
$log_dir - the root log directory |
66
|
|
|
|
|
|
|
Throws : Nothing |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=back |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=cut |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------ |
73
|
|
|
|
|
|
|
sub rerun { |
74
|
0
|
|
|
0
|
1
|
|
my ($family_name, $job_name, $log_dir, $cascade, $dependents_only, $family_dir, $quiet) = @_; |
75
|
|
|
|
|
|
|
|
76
|
0
|
|
|
|
|
|
my $jobs; |
77
|
|
|
|
|
|
|
|
78
|
0
|
0
|
0
|
|
|
|
if ($cascade or $dependents_only) { |
79
|
0
|
0
|
|
|
|
|
$ENV{TF_JOB_DIR} = 'unnecessary' unless $ENV{TF_JOB_DIR}; |
80
|
0
|
0
|
|
|
|
|
$ENV{TF_RUN_WRAPPER} = 'unnecessary' unless $ENV{TF_RUN_WRAPPER}; |
81
|
0
|
0
|
|
|
|
|
$ENV{TF_LOG_DIR} = $log_dir unless $ENV{TF_LOG_DIR}; |
82
|
0
|
0
|
|
|
|
|
$ENV{TF_FAMILY_DIR} = $family_dir unless $ENV{TF_FAMILY_DIR}; |
83
|
|
|
|
|
|
|
|
84
|
0
|
|
|
|
|
|
my $family = TaskForest::Family->new(name => $family_name); |
85
|
|
|
|
|
|
|
|
86
|
0
|
|
|
|
|
|
$jobs = $family->findDependentJobs($job_name); |
87
|
|
|
|
|
|
|
|
88
|
0
|
0
|
|
|
|
|
if ($cascade) { |
89
|
0
|
|
|
|
|
|
push (@$jobs, $job_name); |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
else { |
94
|
0
|
|
|
|
|
|
$jobs = [$job_name]; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
0
|
0
|
|
|
|
|
unless (@$jobs) { |
98
|
0
|
|
|
|
|
|
print STDERR "There are no jobs to rerun. Did you misspell the job name?\n"; |
99
|
0
|
|
|
|
|
|
exit 1; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
0
|
|
|
|
|
|
foreach my $job (@$jobs) { |
103
|
0
|
|
|
|
|
|
rerunHelp($family_name, $job, $log_dir, $quiet); |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
sub rerunHelp { |
109
|
0
|
|
|
0
|
0
|
|
my ($family_name, $job_name, $log_dir, $quiet) = @_; |
110
|
|
|
|
|
|
|
|
111
|
0
|
|
|
|
|
|
my $rc = 0; |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
|
114
|
0
|
0
|
|
|
|
|
print "Making job $family_name $job_name available for rerun.\n" unless $quiet; |
115
|
|
|
|
|
|
|
|
116
|
0
|
|
|
|
|
|
my $rc_file = "$log_dir/$family_name.$job_name.0"; |
117
|
0
|
|
|
|
|
|
my $pid_file = "$log_dir/$family_name.$job_name.pid"; |
118
|
0
|
|
|
|
|
|
my $started_file = "$log_dir/$family_name.$job_name.started"; |
119
|
0
|
|
|
|
|
|
my $actual_start; |
120
|
|
|
|
|
|
|
my $pid; |
121
|
|
|
|
|
|
|
|
122
|
0
|
0
|
|
|
|
|
if (!(-e $pid_file)) { |
123
|
0
|
|
|
|
|
|
confess("The pid file $pid_file is missing. You will need to rerun the job manually. See rerun --help for instructions."); |
124
|
|
|
|
|
|
|
} |
125
|
0
|
0
|
|
|
|
|
if (!(-e $started_file)) { |
126
|
0
|
|
|
|
|
|
confess("The started file $started_file is missing. You will need to rerun the job manually. See rerun --help for instructions."); |
127
|
|
|
|
|
|
|
} |
128
|
0
|
0
|
|
|
|
|
if (!(-e $rc_file)) { |
129
|
0
|
|
|
|
|
|
$rc = 1; |
130
|
0
|
|
|
|
|
|
substr($rc_file, -1, 1) = "1"; |
131
|
0
|
0
|
|
|
|
|
if (!(-e $rc_file)) { |
132
|
0
|
|
|
|
|
|
substr($rc_file, -1, 1) = "[01]"; |
133
|
0
|
|
|
|
|
|
confess("The rc file $rc_file is missing. This means that the job is currently running or has been terminated abnormally. You will need to rerun the job manually. See rerun --help for instructions."); |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
|
137
|
0
|
0
|
|
|
|
|
open (S, $pid_file) || confess ("Can't open $started_file: $!"); |
138
|
0
|
|
|
|
|
|
while () { |
139
|
0
|
0
|
|
|
|
|
if (/^actual_start: (\d+)/) { |
140
|
0
|
|
|
|
|
|
$actual_start = $1; |
141
|
|
|
|
|
|
|
} |
142
|
0
|
0
|
|
|
|
|
if (/^pid: (\d+)/) { |
143
|
0
|
|
|
|
|
|
$pid = $1; |
144
|
|
|
|
|
|
|
} |
145
|
0
|
0
|
0
|
|
|
|
last if ($actual_start && $pid); |
146
|
|
|
|
|
|
|
} |
147
|
0
|
|
|
|
|
|
close (S); |
148
|
0
|
|
|
|
|
|
my $log_file = "$log_dir/$family_name.$job_name.$pid.$actual_start.stdout"; |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
|
151
|
0
|
|
|
|
|
|
my @origs = glob("$log_dir/$family_name.$job_name"."--Orig_*--.pid"); |
152
|
0
|
|
|
|
|
|
my $next_id = 1; |
153
|
0
|
0
|
|
|
|
|
if (@origs) { |
154
|
0
|
|
|
|
|
|
my @ids = sort {$a <=> $b} map { /--Orig_(\d+)--/; $1 } @origs; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
155
|
0
|
|
|
|
|
|
my $max = pop(@ids); |
156
|
0
|
|
|
|
|
|
$next_id = $max + 1; |
157
|
|
|
|
|
|
|
} |
158
|
|
|
|
|
|
|
|
159
|
0
|
|
|
|
|
|
my $new_rc_file = "$log_dir/$family_name.$job_name--Orig_$next_id--.$rc"; |
160
|
0
|
|
|
|
|
|
my $new_pid_file = "$log_dir/$family_name.$job_name--Orig_$next_id--.pid"; |
161
|
0
|
|
|
|
|
|
my $new_started_file = "$log_dir/$family_name.$job_name--Orig_$next_id--.started"; |
162
|
0
|
|
|
|
|
|
my $new_log_file = "$log_dir/$family_name.$job_name--Orig_$next_id--.$pid.$actual_start.stdout"; |
163
|
|
|
|
|
|
|
|
164
|
0
|
0
|
|
|
|
|
move($pid_file, $new_pid_file) || confess ("couldn't move $pid_file to $new_pid_file: $!"); |
165
|
0
|
0
|
|
|
|
|
move($started_file, $new_started_file) || confess ("couldn't move $started_file to $new_started_file: $!"); |
166
|
0
|
0
|
|
|
|
|
move($rc_file, $new_rc_file) || confess ("couldn't move $rc_file to $new_rc_file: $!"); |
167
|
0
|
0
|
|
|
|
|
if (-e $log_file) { |
168
|
0
|
0
|
|
|
|
|
move($log_file, $new_log_file) || confess ("couldn't move $log_file to $new_log_file: $!"); |
169
|
|
|
|
|
|
|
} |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
} |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
1; |