blib/lib/HPC/Runner/Command/submit_jobs/Utils/Scheduler/Files.pm

filter: Statementstmt 41.5% 22 / 53 Branchbran 0.0% 0 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 50.0% 6 / 12 Podpod 80.0% 4 / 5 totaltotal 39.0% 32 / 82 CC 7 SCAR 17.7
CC
7
Cov
34%
prepare_sched_file
12.0
prepare_batch_files_array
12.0
resolve_project
6.0
CRAP 5.9
« blib/lib/HPC/Runner/Command/stats/Logger/JSON/Long/TableOutput.pm ↑ Summary blib/lib/HPC/Runner/Command/archive.pm »
1 package HPC::Runner::Command::submit_jobs::Utils::Scheduler::Files;
2  
3 1 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use IO::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 #Travis test fails without this
7 1 ▶use IO::Interactive;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use File::Path qw(make_path remove_tree);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use File::Copy;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 =head1 HPC::Runner::Command::submit_jobs::Utils::Scheduler::Files
13  
14 Take care of all file operations
15  
16 =cut
17  
18 =head2 Attributes
19  
20 =cut
21  
22 =head3 cmdfile
23  
24 File of commands for mcerunner
25 Is cleared at the end of each slurm submission
26  
27 =cut
28  
29 1 has 'cmdfile' => (
30 traits => ['String'],
31 default => q{},
32 is => 'rw',
33 isa => 'Str',
34 required => 0,
35 handles => { clear_cmdfile => 'clear', },
36 );
37  
38 =head3 slurmfile
39  
40 File generated from slurm template
41  
42 Job submission file
43  
44 =cut
45  
46 1 has 'slurmfile' => (
47 traits => ['String'],
48 default => q{},
49 is => 'rw',
50 isa => 'Str',
51 required => 0,
52 handles => { clear_slurmfile => 'clear', },
53 );
54  
55 has job_files => (
56 is => 'rw',
57 isa => 'HashRef',
58 default => sub {
59 0 ▶ return {};
Subroutine __ANON__: not called CC=1 SCAR=6.9
60 }
61 1 );
62  
63 =head2 Subroutines
64  
65 =cut
66  
67 =head3 resolve_project
68  
69 =cut
70  
71 sub resolve_project {
72 0 ▶ my $self = shift;
Subroutine resolve_project: not called CC=2 SCAR=17.9
Pod documented
73 0 my $counter = shift;
74  
75 0 my $jobname;
76  
77 0 ▶ if ( $self->has_project ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_project) { } 0 0 0
78 0 $jobname = $self->project . "_" . $counter . "_" . $self->current_job;
79 }
80 else {
81 0 $jobname = $counter . "_" . $self->current_job;
82 }
83  
84 0 return $jobname;
85 }
86  
87 =head3 prepare_files
88  
89 =cut
90  
91 #TODO I think we will get rid of this
92  
93 sub prepare_files {
94 0 ▶ my $self = shift;
Subroutine prepare_files: not called CC=2 SCAR=17.9
Pod documented
95  
96 0 ▶ make_path( $self->outdir ) unless -d $self->outdir;
Branch: 1 branch
BranchTrueFalseTotal
unless -d $self->outdir 0 0 0
97  
98 0 $self->prepare_sched_file;
99 }
100  
101 =head3 prepare_counter
102  
103 Prepare the counter. It is 001, 002, etc instead of 1, 2 etc
104  
105 =cut
106  
107 sub prepare_counter {
108 0 ▶ my $self = shift;
Subroutine prepare_counter: not called CC=1 SCAR=6.9
Pod documented
109  
110 0 my $batch_counter = $self->batch_counter;
111 0 $batch_counter = sprintf( "%03d", $batch_counter );
112  
113 0 my $job_counter = $self->job_counter;
114 0 $job_counter = sprintf( "%03d", $job_counter );
115  
116 0 return ( $batch_counter, $job_counter );
117 }
118  
119 =head3 prepare_sched_files
120  
121 =cut
122  
123 sub prepare_sched_file {
124 0 ▶ my $self = shift;
Subroutine prepare_sched_file: not called CC=3 SCAR=24.8
Pod undocumented
125  
126 #$DB::single = 2;
127  
128 0 my ( $batch_counter, $job_counter ) = $self->prepare_counter;
129  
130 0 ▶ make_path( $self->outdir ) unless -d $self->outdir;
Branch: 1 branch
BranchTrueFalseTotal
unless -d $self->outdir 0 0 0
131  
132 #If we are using job arrays there will only be one per batch
133  
134 0 my $jobname = $self->resolve_project($job_counter);
135  
136 0 ▶ if ( $self->use_batches ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->use_batches) { } 0 0 0
137 0 $self->slurmfile(
138 $self->outdir . "/$jobname" . "_" . $batch_counter . ".sh" );
139 }
140 else {
141 0 $self->slurmfile( $self->outdir . "/$jobname" . ".sh" );
142 }
143 }
144  
145 =head3 prepare_batch_files_array
146  
147 Write out the batch files
148  
149 Old method
150  
151 For job arrays this is 1 per array element
152  
153 For (legacy) batches 1 file per batch
154  
155 New method
156  
157 One file per job - and we just have a counter to make sure we are on the right task
158  
159 =cut
160  
161 sub prepare_batch_files_array {
162 0 ▶ my $self = shift;
Subroutine prepare_batch_files_array: not called CC=3 SCAR=24.8
Pod documented
163  
164 # my $job_counter = sprintf( "%03d", $self->job_counter );
165  
166 0 my $job_counter = "000";
167 0 my $jobname = $self->resolve_project($job_counter);
168 0 my $outfile = File::Spec->catfile( $self->outdir, $jobname . '.in' );
169  
170 0 ▶ if ( !-e $outfile ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-e $outfile) 0 0 0
171 0 ▶ copy( $self->job_files->{ $self->current_job }->filename, $outfile )
Branch: 1 branch
BranchTrueFalseTotal
copy($self->job_files->{$self->current_job}->filename, $outfile) or die print("ERROR COPYING $!") 0 0 0
172 or die print "ERROR COPYING $!";
173 }
174  
175 0 $self->cmdfile($outfile);
176 }
177  
178 #TODO Write a file per job - not per task
179 # sub write_batch_file {
180 # my $self = shift;
181 # my $command = shift;
182 #
183 # make_path( $self->outdir ) unless -d $self->outdir;
184 #
185 # my $fh = IO::File->new( $self->cmdfile, q{>} )
186 # or die print "Error opening file " . $self->cmdfile . " " . $! . "\n";
187 #
188 # print $fh $command if defined $fh && defined $command;
189 # $fh->close;
190 # }
191  
192 1 1;
« blib/lib/HPC/Runner/Command/stats/Logger/JSON/Long/TableOutput.pm ↑ Summary blib/lib/HPC/Runner/Command/archive.pm »