blib/lib/HPC/Runner/Command/submit_jobs/Logger/JSON.pm

filter: Statementstmt 30.8% 29 / 94 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 75.0% 9 / 12 Podpod 100% 3 / 3 totaltotal 33.3% 41 / 123 CC 8 SCAR 34.3
CC
8
Cov
27%
gen_hpc_meta
72.0
create_json_submission
2.0
update_json_submission
2.0
CRAP 31.0
« blib/lib/HPC/Runner/Command/submit_jobs/Plugin/Slurm.pm ↑ Summary blib/lib/HPC/Runner/Command/submit_jobs/Utils/Plugin.pm »
1 package HPC::Runner::Command::submit_jobs::Logger::JSON;
2  
3 1 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 with 'HPC::Runner::Command::execute_job::Logger::Lock';
7  
8 1 ▶use JSON;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Data::UUID;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use File::Path qw(make_path remove_tree);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use File::Slurp;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use DateTime;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use Capture::Tiny ':all';
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 =head3 create_json_submission
17  
18 Create the data for the json submission
19  
20 =cut
21  
22 sub create_json_submission {
23 0 ▶ my $self = shift;
Subroutine create_json_submission: not called CC=1 SCAR=6.9
Pod documented
24  
25 0 make_path($self->data_dir);
26 0 $self->logger('app_log');
27 0 my $hpc_meta = $self->gen_hpc_meta;
28  
29 # my $json_text = encode_json $hpc_meta;
30 # write_file(File::Spec->catdir($self->data_dir, 'submission.json'), $json_text);
31  
32 0 return $hpc_meta;
33 }
34  
35 =head3 update_json_submission
36  
37 Take the initial submission and update it to contain the hpcmeta
38  
39 We only rerun this here to get the submission status
40  
41 =cut
42  
43 sub update_json_submission {
44 0 ▶ my $self = shift;
Subroutine update_json_submission: not called CC=1 SCAR=6.9
Pod documented
45  
46 0 make_path($self->data_dir);
47 0 my $hpc_meta = $self->gen_hpc_meta;
48 0 my $json_text = encode_json $hpc_meta;
49  
50 0 my $file_name = File::Spec->catdir( $self->logdir, 'submission.json' );
51 0 $self->_make_the_dirs( $self->logdir );
52  
53 0 write_file($file_name, $json_text);
54 0 write_file(File::Spec->catdir($self->data_dir, 'submission.json'), $json_text);
55  
56 0 return $hpc_meta;
57 }
58  
59 =head3 gen_hpc_meta
60  
61 Generate the HPC meta from the submission
62  
63 #TODO Check for batches
64  
65 =cut
66  
67 sub gen_hpc_meta {
68 0 ▶ my $self = shift;
Subroutine gen_hpc_meta: not called CC=8 SCAR=42.8
Pod documented
69  
70 0 my $hpc_meta = {};
71 0 $hpc_meta->{uuid} = $self->submission_uuid;
72 0 ▶ $hpc_meta->{project} = $self->project if $self->has_project;
Branch: 1 branch
BranchTrueFalseTotal
if $self->has_project 0 0 0
73 0 my $dt = DateTime->now( time_zone => 'local' );
74 0 $hpc_meta->{submission_time} = "$dt";
75 0 $hpc_meta->{jobs} = [];
76 0 $hpc_meta->{submissions} = {};
77 0 $hpc_meta->{schedule} = $self->schedule;
78  
79 0 foreach my $job ( $self->all_schedules ) {
80 0 my $job_obj = {};
81  
82 #Dependencies
83 0 my $ref = $self->graph_job_deps->{$job};
84 0 my $depstring = join( ", ", @{$ref} );
85 0 my $count_cmd = $self->jobs->{$job}->cmd_counter;
86 0 my $mem = $self->jobs->{$job}->mem;
87 0 my $cpus = $self->jobs->{$job}->cpus_per_task;
88 0 my $walltime = $self->jobs->{$job}->walltime;
89 0 my $cmd_start = $self->jobs->{$job}->{cmd_start};
90 0 ▶ my $submission_stat = $self->jobs->{$job}->submission_failure || 0;
Condition0%0/2
$self->jobs->{$job}->submission_failure || 0
l!l
00
MC/DC0%0/1
$self->jobs->{$job}->submission_failure || 0
$self->jobs->{$job}->submission_failure
Truth table0%0/2
A
A= $self->jobs->{$job}->submission_failure
Aresult
11
00
91  
92 0 $job_obj->{job} = $job;
93 0 $job_obj->{deps} = $depstring;
94 0 $job_obj->{total_tasks} = $count_cmd;
95 0 $job_obj->{walltime} = $walltime;
96 0 $job_obj->{cpus_per_task} = $cpus;
97 0 $job_obj->{mem} = $mem;
98 0 $job_obj->{cmd_start} = $cmd_start;
99 0 $job_obj->{cmd_end} = $cmd_start + $count_cmd;
100 0 $job_obj->{schedule} = [];
101  
102 #I think this should be scheduler_ids
103 0 ▶ for ( my $x = 0 ; $x < $self->jobs->{$job}->{num_job_arrays} ; $x++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($x < $self->jobs->{$job}{"num_job_arrays"}) 0 0 0
104  
105 0 my $obj = {};
106  
107 #index start, index end
108 0 ▶ next unless $self->jobs->{$job}->batch_indexes->[$x];
Branch: 1 branch
BranchTrueFalseTotal
unless $self->jobs->{$job}->batch_indexes->[$x] 0 0 0
109  
110 my $batch_start =
111 0 $self->jobs->{$job}->batch_indexes->[$x]->{'batch_index_start'};
112 my $batch_end =
113 0 $self->jobs->{$job}->batch_indexes->[$x]->{'batch_index_end'};
114 0 my $len = ( $batch_end - $batch_start ) + 1;
115  
116 0 my $logname = $self->jobs->{$job}->lognames->[$x];
117 0 ▶ if ($logname) {
Branch: 1 branch
BranchTrueFalseTotal
if ($logname) 0 0 0
118 ##TASK IDS ARE 0 INDEXED
119 0 $hpc_meta->{submissions}->{$logname}->{jobname} = $job;
120 ##The entire job
121 $hpc_meta->{submissions}->{$logname}->{job_task_index_start} =
122 0 $cmd_start + 0;
123 $hpc_meta->{submissions}->{$logname}->{job_task_index_end} =
124 0 $cmd_start + $count_cmd - 1;
125  
126 ##This particular batch
127 ##These are 1 indexed to match the command line parameters 1
128 ##TODO clean up 0/1 indexed!!
129 $hpc_meta->{submissions}->{$logname}->{batch_index_start} =
130 0 $batch_start;
131 $hpc_meta->{submissions}->{$logname}->{batch_index_end} =
132 0 $batch_end;
133 }
134  
135 0 ▶ my $scheduler_id = $self->jobs->{$job}->scheduler_ids->[$x] || '0';
Condition0%0/2
$self->jobs->{$job}->scheduler_ids->[$x] || '0'
l!l
00
MC/DC0%0/1
$self->jobs->{$job}->scheduler_ids->[$x] || '0'
$self->jobs->{$job}->scheduler_ids->[$x]
Truth table0%0/2
A
A= $self->jobs->{$job}->scheduler_ids->[$x]
Aresult
11
00
136 0 $obj->{task_indices} = "$batch_start-$batch_end";
137 0 $obj->{total_tasks} = $len;
138 0 $obj->{scheduler_id} = $scheduler_id;
139  
140 0 push( @{ $job_obj->{schedule} }, $obj );
141 }
142  
143 0 push( @{ $hpc_meta->{jobs} }, $job_obj );
144 }
145  
146 0 return $hpc_meta;
147 }
148  
149 1 1;
« blib/lib/HPC/Runner/Command/submit_jobs/Plugin/Slurm.pm ↑ Summary blib/lib/HPC/Runner/Command/submit_jobs/Utils/Plugin.pm »