line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HPC::Runner::Command::execute_job::Logger::JSON; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
622
|
use Moose::Role; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
11
|
|
4
|
1
|
|
|
1
|
|
5112
|
use namespace::autoclean; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
11
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
with 'HPC::Runner::Command::execute_job::Logger::Lock'; |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
91
|
use JSON; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
11
|
|
9
|
1
|
|
|
1
|
|
132
|
use File::Spec; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
24
|
|
10
|
1
|
|
|
1
|
|
5
|
use DateTime; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
18
|
|
11
|
1
|
|
|
1
|
|
4
|
use Try::Tiny; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
65
|
|
12
|
1
|
|
|
1
|
|
5
|
use Data::UUID; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
53
|
|
13
|
1
|
|
|
1
|
|
5
|
use File::Path qw(make_path remove_tree); |
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
49
|
|
14
|
1
|
|
|
1
|
|
5
|
use File::Slurp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
55
|
|
15
|
1
|
|
|
1
|
|
5
|
use Cwd; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
49
|
|
16
|
1
|
|
|
1
|
|
8
|
use Data::Dumper; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
35
|
|
17
|
1
|
|
|
1
|
|
5
|
use Time::HiRes; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
10
|
|
18
|
1
|
|
|
1
|
|
70
|
use Capture::Tiny ':all'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
921
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
has 'task_json' => ( |
21
|
|
|
|
|
|
|
is => 'rw', |
22
|
|
|
|
|
|
|
isa => 'Str', |
23
|
|
|
|
|
|
|
default => '', |
24
|
|
|
|
|
|
|
required => 0, |
25
|
|
|
|
|
|
|
); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
has 'task_jobname' => ( |
28
|
|
|
|
|
|
|
is => 'rw', |
29
|
|
|
|
|
|
|
isa => 'Str', |
30
|
|
|
|
|
|
|
required => 0, |
31
|
|
|
|
|
|
|
); |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub parse_meta_str { |
34
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
35
|
|
|
|
|
|
|
|
36
|
0
|
|
|
|
|
|
my $job_meta = {}; |
37
|
0
|
0
|
|
|
|
|
if ( $self->metastr ) { |
38
|
0
|
|
|
|
|
|
$job_meta = decode_json( $self->metastr ); |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
0
|
0
|
0
|
|
|
|
if ( !$job_meta || !exists $job_meta->{jobname} ) { |
42
|
|
|
|
|
|
|
##TO account for single_node mode |
43
|
0
|
|
|
|
|
|
$job_meta->{jobname} = $self->jobname; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
0
|
|
|
|
|
|
$self->task_jobname( $job_meta->{jobname} ); |
47
|
0
|
|
|
|
|
|
return $job_meta; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub create_json_task { |
51
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
52
|
0
|
|
|
|
|
|
my $cmdpid = shift; |
53
|
|
|
|
|
|
|
|
54
|
0
|
|
|
|
|
|
my $job_meta = $self->parse_meta_str; |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
my $task_obj = { |
57
|
|
|
|
|
|
|
pid => $cmdpid, |
58
|
|
|
|
|
|
|
start_time => $self->table_data->{start_time}, |
59
|
|
|
|
|
|
|
jobname => $job_meta->{jobname}, |
60
|
0
|
|
|
|
|
|
task_id => $self->counter, |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
# submission_uuid => $self->submission_uuid, |
63
|
|
|
|
|
|
|
# task_uuid => $uuid, |
64
|
|
|
|
|
|
|
# job_meta => $job_meta, |
65
|
|
|
|
|
|
|
}; |
66
|
|
|
|
|
|
|
|
67
|
0
|
0
|
|
|
|
|
$task_obj->{scheduler_id} = $self->job_scheduler_id |
68
|
|
|
|
|
|
|
if $self->can('scheduler_id'); |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
# We are rolling back this functionality for a future release |
71
|
|
|
|
|
|
|
# my $basename = $self->data_tar->basename('.tar.gz'); |
72
|
|
|
|
|
|
|
# my $data_dir = File::Spec->catdir( $basename, $job_meta->{jobname} ); |
73
|
|
|
|
|
|
|
# |
74
|
|
|
|
|
|
|
# if ( !$self->no_log_json ) { |
75
|
|
|
|
|
|
|
# $self->check_lock; |
76
|
|
|
|
|
|
|
# $self->write_lock; |
77
|
|
|
|
|
|
|
# |
78
|
|
|
|
|
|
|
# $self->add_to_running( $data_dir, $task_obj ); |
79
|
|
|
|
|
|
|
# |
80
|
|
|
|
|
|
|
# $self->lock_file->remove; |
81
|
|
|
|
|
|
|
# } |
82
|
|
|
|
|
|
|
|
83
|
0
|
|
|
|
|
|
return $task_obj; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
## keep this or no? |
87
|
|
|
|
|
|
|
##TODO Create Mem profile file |
88
|
|
|
|
|
|
|
sub create_task_file { |
89
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
90
|
0
|
|
|
|
|
|
my $data_dir = shift; |
91
|
0
|
|
|
|
|
|
my $json_obj = shift; |
92
|
|
|
|
|
|
|
|
93
|
0
|
|
|
|
|
|
my $t_file = File::Spec->catfile( $data_dir, $self->counter . '.json' ); |
94
|
0
|
|
|
|
|
|
$self->write_json( $t_file, $json_obj ); |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub add_to_running { |
98
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
99
|
0
|
|
|
|
|
|
my $data_dir = shift; |
100
|
0
|
|
|
|
|
|
my $task_data = shift; |
101
|
|
|
|
|
|
|
|
102
|
0
|
|
|
|
|
|
my $r_file = File::Spec->catfile( $data_dir, 'running.json' ); |
103
|
|
|
|
|
|
|
|
104
|
0
|
|
|
|
|
|
my $json_obj = $self->read_json($r_file); |
105
|
0
|
|
|
|
|
|
$json_obj->{ $self->counter } = $task_data; |
106
|
|
|
|
|
|
|
|
107
|
0
|
|
|
|
|
|
$self->write_json( $r_file, $json_obj ); |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
sub remove_from_running { |
111
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
112
|
0
|
|
|
|
|
|
my $data_dir = shift; |
113
|
|
|
|
|
|
|
|
114
|
0
|
|
|
|
|
|
my $r_file = File::Spec->catfile( $data_dir, 'running.json' ); |
115
|
0
|
|
|
|
|
|
my $json_obj = $self->read_json($r_file); |
116
|
|
|
|
|
|
|
|
117
|
0
|
|
|
|
|
|
delete $json_obj->{ $self->table_data->{task_id} }; |
118
|
0
|
|
|
|
|
|
$self->write_json( $r_file, $json_obj ); |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
sub get_from_running { |
122
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
123
|
0
|
|
|
|
|
|
my $data_dir = shift; |
124
|
|
|
|
|
|
|
|
125
|
0
|
|
|
|
|
|
my $r_file = File::Spec->catfile( $data_dir, 'running.json' ); |
126
|
0
|
|
|
|
|
|
my $json_obj = $self->read_json($r_file); |
127
|
|
|
|
|
|
|
|
128
|
0
|
|
|
|
|
|
return $json_obj->{ $self->table_data->{task_id} }; |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
##TODO Once we add to the complete |
132
|
|
|
|
|
|
|
## Get all the for the tasks |
133
|
|
|
|
|
|
|
## Compute mean, min, max of all tasks |
134
|
|
|
|
|
|
|
sub update_json_task { |
135
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
# my @stats = ( 'vmpeak', 'vmrss', 'vmsize', 'vmhwm' ); |
138
|
|
|
|
|
|
|
# my $job_meta = $self->parse_meta_str; |
139
|
|
|
|
|
|
|
# my $basename = $self->data_tar->basename('.tar.gz'); |
140
|
|
|
|
|
|
|
# my $data_dir = File::Spec->catdir( $basename, $job_meta->{jobname} ); |
141
|
|
|
|
|
|
|
|
142
|
0
|
|
|
|
|
|
my $tags = ""; |
143
|
0
|
0
|
|
|
|
|
if ( exists $self->table_data->{task_tags} ) { |
144
|
0
|
|
|
|
|
|
my $task_tags = $self->table_data->{task_tags}; |
145
|
0
|
0
|
|
|
|
|
if ($task_tags) { |
146
|
0
|
|
|
|
|
|
$tags = $task_tags; |
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
# my $task_obj = $self->get_from_running($data_dir); |
151
|
0
|
|
|
|
|
|
my $task_obj = {}; |
152
|
|
|
|
|
|
|
|
153
|
0
|
|
|
|
|
|
$task_obj->{exit_time} = $self->table_data->{exit_time}; |
154
|
0
|
|
|
|
|
|
$task_obj->{duration} = $self->table_data->{duration}; |
155
|
0
|
|
|
|
|
|
$task_obj->{exit_code} = $self->table_data->{exitcode}; |
156
|
0
|
|
|
|
|
|
$task_obj->{task_tags} = $tags; |
157
|
0
|
|
|
|
|
|
$task_obj->{pid} = $self->table_data->{cmdpid}; |
158
|
0
|
|
|
|
|
|
$task_obj->{cmdpid} = $self->table_data->{cmdpid}; |
159
|
0
|
|
|
|
|
|
$task_obj->{start_time} = $self->table_data->{start_time}; |
160
|
0
|
|
|
|
|
|
$task_obj->{start_time_dt} = $self->table_data->{start_time_dt}; |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
# $task_obj->{memory_profile} = {}; |
163
|
|
|
|
|
|
|
# |
164
|
|
|
|
|
|
|
# foreach my $stat (@stats) { |
165
|
|
|
|
|
|
|
# $task_obj->{memory_profile}->{$stat}->{low} = |
166
|
|
|
|
|
|
|
# $self->task_mem_data->{low}->{$stat}; |
167
|
|
|
|
|
|
|
# $task_obj->{memory_profile}->{$stat}->{high} = |
168
|
|
|
|
|
|
|
# $self->task_mem_data->{high}->{$stat}; |
169
|
|
|
|
|
|
|
# $task_obj->{memory_profile}->{$stat}->{mean} = |
170
|
|
|
|
|
|
|
# $self->task_mem_data->{mean}->{$stat}; |
171
|
|
|
|
|
|
|
# $task_obj->{memory_profile}->{$stat}->{count} = |
172
|
|
|
|
|
|
|
# $self->task_mem_data->{count}->{$stat}; |
173
|
|
|
|
|
|
|
# } |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
# if ( !$self->no_log_json ) { |
176
|
|
|
|
|
|
|
# $self->check_lock; |
177
|
|
|
|
|
|
|
# $self->write_lock; |
178
|
|
|
|
|
|
|
# |
179
|
|
|
|
|
|
|
# $self->remove_from_running($data_dir); |
180
|
|
|
|
|
|
|
# ##TODO Add in mem for job |
181
|
|
|
|
|
|
|
# $self->add_to_complete( $data_dir, $task_obj ); |
182
|
|
|
|
|
|
|
# $self->lock_file->remove; |
183
|
|
|
|
|
|
|
# } |
184
|
|
|
|
|
|
|
|
185
|
0
|
|
|
|
|
|
return $task_obj; |
186
|
|
|
|
|
|
|
} |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
sub add_to_complete { |
189
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
190
|
0
|
|
|
|
|
|
my $data_dir = shift; |
191
|
0
|
|
|
|
|
|
my $task_data = shift; |
192
|
|
|
|
|
|
|
|
193
|
0
|
|
|
|
|
|
my $c_file = File::Spec->catfile( $data_dir, 'complete.json' ); |
194
|
0
|
|
|
|
|
|
my $json_obj = $self->read_json($c_file); |
195
|
|
|
|
|
|
|
|
196
|
0
|
|
|
|
|
|
$json_obj->{ $self->counter } = $task_data; |
197
|
0
|
|
|
|
|
|
$self->write_json( $c_file, $json_obj ); |
198
|
|
|
|
|
|
|
|
199
|
0
|
|
|
|
|
|
return $json_obj; |
200
|
|
|
|
|
|
|
} |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
##Going to have to update these for creating the archive |
203
|
|
|
|
|
|
|
sub read_json { |
204
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
205
|
0
|
|
|
|
|
|
my $file = shift; |
206
|
|
|
|
|
|
|
|
207
|
0
|
|
|
|
|
|
my $json_obj; |
208
|
|
|
|
|
|
|
my $text; |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
capture { |
211
|
0
|
|
|
0
|
|
|
$self->archive->read( $self->data_tar ); |
212
|
0
|
|
|
|
|
|
}; |
213
|
0
|
0
|
|
|
|
|
if ( $self->archive->contains_file($file) ) { |
214
|
0
|
|
|
|
|
|
$text = $self->archive->get_content($file); |
215
|
0
|
0
|
|
|
|
|
$json_obj = decode_json($text) if $text; |
216
|
|
|
|
|
|
|
} |
217
|
|
|
|
|
|
|
else { |
218
|
0
|
|
|
|
|
|
$json_obj = {}; |
219
|
|
|
|
|
|
|
} |
220
|
|
|
|
|
|
|
|
221
|
0
|
|
|
|
|
|
return $json_obj; |
222
|
|
|
|
|
|
|
} |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
sub write_json { |
225
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
226
|
0
|
|
|
|
|
|
my $file = shift; |
227
|
0
|
|
|
|
|
|
my $json_obj = shift; |
228
|
|
|
|
|
|
|
|
229
|
0
|
0
|
|
|
|
|
return unless $json_obj; |
230
|
|
|
|
|
|
|
|
231
|
0
|
|
|
|
|
|
my $json_text = encode_json($json_obj); |
232
|
|
|
|
|
|
|
capture { |
233
|
0
|
|
|
0
|
|
|
$self->archive->read( $self->data_tar ); |
234
|
0
|
|
|
|
|
|
}; |
235
|
0
|
0
|
|
|
|
|
if ( $self->archive->contains_file($file) ) { |
236
|
0
|
|
|
|
|
|
$self->archive->replace_content( $file, $json_text ); |
237
|
|
|
|
|
|
|
} |
238
|
|
|
|
|
|
|
else { |
239
|
0
|
0
|
|
|
|
|
$self->archive->add_data( $file, $json_text ) |
240
|
|
|
|
|
|
|
|| $self->command_log->warn( |
241
|
|
|
|
|
|
|
'We were not able to add ' . $file . ' to the archive' ); |
242
|
|
|
|
|
|
|
} |
243
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
capture { |
245
|
0
|
0
|
|
0
|
|
|
$self->archive->write( $self->data_tar, 1 ) |
246
|
|
|
|
|
|
|
|| $self->command_log->warn( |
247
|
|
|
|
|
|
|
'We were not able to write ' . $file . ' to the archive' ); |
248
|
0
|
|
|
|
|
|
}; |
249
|
|
|
|
|
|
|
} |
250
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
1; |