File Coverage

blib/lib/TaskForest/Hold.pm
Criterion Covered Total %
statement 19 57 33.3
branch 0 32 0.0
condition 0 6 0.0
subroutine 7 11 63.6
pod 1 4 25.0
total 27 110 24.5


line stmt bran cond sub pod time code
1             ################################################################################
2             #
3             # $Id: Hold.pm 271 2010-02-12 04:49:25Z aijaz $
4             #
5             ################################################################################
6              
7             =head1 NAME
8              
9             TaskForest::Hold - Functions related to releasing all dependencies of a job.
10              
11             =head1 SYNOPSIS
12              
13             use TaskForest::Hold;
14              
15             &TaskForest::Hold::hold($family_name, $job_name, $log_dir, $cascade, $dependents_only, $family_dir)
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 hold
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::Hold;
39 5     5   16355 use strict;
  5         11  
  5         175  
40 5     5   28 use warnings;
  5         9  
  5         120  
41 5     5   28 use Carp;
  5         7  
  5         1453  
42 5     5   46 use File::Copy;
  5         10  
  5         298  
43 5     5   5152 use TaskForest::Family;
  5         18  
  5         283  
44              
45             BEGIN {
46 5     5   55 use vars qw($VERSION);
  5         14  
  5         251  
47 5     5   3117 $VERSION = '1.34';
48             }
49              
50              
51             # ------------------------------------------------------------------------------
52             =pod
53              
54             =over 4
55              
56             =item hold()
57              
58             Usage : hold($family_name, $job_name, $log_dir)
59             Purpose : Hold the specified job as success or failure. This job
60             creates a special file that's used to override the logic that
61             determines whether or not a job is ready to run.
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 hold {
74 0     0 1   my ($family_name, $job_name, $log_dir, $family_dir, $quiet) = @_;
75              
76 0           my $jobs;
77              
78              
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 0           $family->getCurrent();
86            
87 0 0 0       if ($family->{jobs}->{$job_name} && $family->{jobs}->{$job_name}->{status} eq 'Waiting') {
88 0           holdHelp($family_name, $job_name, $log_dir, $quiet);
89             }
90             else {
91 0           carp "Cannot hold job ${family_name}::$job_name since it is not in the 'Waiting' state - it's in the ".
92             $family->{jobs}->{$job_name}->{status}.
93             " state.\n";
94             }
95            
96            
97             }
98              
99              
100             sub releaseHold {
101 0     0 0   my ($family_name, $job_name, $log_dir, $family_dir, $quiet) = @_;
102              
103 0           my $jobs;
104              
105              
106 0 0         $ENV{TF_JOB_DIR} = 'unnecessary' unless $ENV{TF_JOB_DIR};
107 0 0         $ENV{TF_RUN_WRAPPER} = 'unnecessary' unless $ENV{TF_RUN_WRAPPER};
108 0 0         $ENV{TF_LOG_DIR} = $log_dir unless $ENV{TF_LOG_DIR};
109 0 0         $ENV{TF_FAMILY_DIR} = $family_dir unless $ENV{TF_FAMILY_DIR};
110            
111 0           my $family = TaskForest::Family->new(name => $family_name);
112 0           $family->getCurrent();
113            
114 0 0 0       if ($family->{jobs}->{$job_name} && $family->{jobs}->{$job_name}->{status} eq 'Hold') {
115 0           releaseHoldHelp($family_name, $job_name, $log_dir, $quiet);
116             }
117             else {
118 0           carp "Cannot release hold on job ${family_name}::$job_name since it is not in the 'Hold' state - it's in the ".
119             $family->{jobs}->{$job_name}->{status}.
120             " state.\n";
121             }
122            
123            
124             }
125              
126              
127             sub holdHelp {
128 0     0 0   my ($family_name, $job_name, $log_dir, $quiet) = @_;
129              
130 0 0         print "Holding job $family_name","::","$job_name\n" unless $quiet;
131            
132 0           my $hold_file = "$log_dir/$family_name.$job_name.hold";
133            
134 0 0         if (-e $hold_file) {
135 0           carp("$family_name.$job_name is already on hold. Not doing anything.");
136             }
137             else {
138 0 0         open (F, ">$hold_file") || croak "Cannot touch file $hold_file";
139            
140 0           print F "\n";;
141            
142 0           close F;
143             }
144            
145             }
146            
147             sub releaseHoldHelp {
148 0     0 0   my ($family_name, $job_name, $log_dir, $quiet) = @_;
149              
150 0 0         print "Releasing hold on job $family_name","::","$job_name\n" unless $quiet;
151            
152 0           my $hold_file = "$log_dir/$family_name.$job_name.hold";
153            
154 0 0         if (-e $hold_file) {
155 0           my $num_deleted = unlink $hold_file;
156 0 0         if ($num_deleted == 1) {
157             # we're ok
158             }
159             else {
160 0           croak ("ERROR: Cannot delete hold file $hold_file\n");
161             }
162             }
163             else {
164 0           carp ("Hold file doesn't exist. The Hold may have already been released.");
165             }
166             }
167            
168             1;