|
1
|
|
|
<?php |
|
2
|
|
|
// This file is part of BOINC. |
|
3
|
|
|
// https://boinc.berkeley.edu |
|
4
|
|
|
// Copyright (C) 2024 University of California |
|
5
|
|
|
// |
|
6
|
|
|
// BOINC is free software; you can redistribute it and/or modify it |
|
7
|
|
|
// under the terms of the GNU Lesser General Public License |
|
8
|
|
|
// as published by the Free Software Foundation, |
|
9
|
|
|
// either version 3 of the License, or (at your option) any later version. |
|
10
|
|
|
// |
|
11
|
|
|
// BOINC is distributed in the hope that it will be useful, |
|
12
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
14
|
|
|
// See the GNU Lesser General Public License for more details. |
|
15
|
|
|
// |
|
16
|
|
|
// You should have received a copy of the GNU Lesser General Public License |
|
17
|
|
|
// along with BOINC. If not, see <http://www.gnu.org/licenses/>. |
|
18
|
|
|
|
|
19
|
|
|
// web interface for submitting BUDA jobs |
|
20
|
|
|
|
|
21
|
|
|
require_once('../inc/util.inc'); |
|
22
|
|
|
require_once('../inc/submit_util.inc'); |
|
23
|
|
|
require_once('../inc/sandbox.inc'); |
|
24
|
|
|
require_once('../inc/buda.inc'); |
|
25
|
|
|
require_once('../inc/kw_prefs.inc'); |
|
26
|
|
|
|
|
27
|
|
|
display_errors(); |
|
28
|
|
|
|
|
29
|
|
|
function submit_form($user) { |
|
30
|
|
|
$sbitems_zip = sandbox_select_items($user, '/.zip$/'); |
|
31
|
|
|
if (!$sbitems_zip) { |
|
32
|
|
|
error_page("No .zip files in your sandbox."); |
|
33
|
|
|
} |
|
34
|
|
|
$app = get_str('app'); |
|
35
|
|
|
if (!is_valid_filename($app)) die('bad arg'); |
|
|
|
|
|
|
36
|
|
|
$variant = get_str('variant'); |
|
37
|
|
|
if (!is_valid_filename($variant)) die('bad arg'); |
|
|
|
|
|
|
38
|
|
|
|
|
39
|
|
|
$desc = "<br><small> |
|
40
|
|
|
A zip file with one directory per job. |
|
41
|
|
|
Each directory contains the input file(s) for that job |
|
42
|
|
|
and an optional file <code>cmdline</code> |
|
43
|
|
|
containing command-line arguments. |
|
44
|
|
|
<a href=https://github.com/BOINC/boinc/wiki/BUDA-job-submission>Details</a></small>. |
|
45
|
|
|
"; |
|
46
|
|
|
page_head("BUDA: Submit jobs to $app ($variant)"); |
|
47
|
|
|
form_start('buda_submit.php'); |
|
48
|
|
|
form_input_hidden('action', 'submit'); |
|
49
|
|
|
form_input_hidden('app', $app); |
|
50
|
|
|
form_input_hidden('variant', $variant); |
|
51
|
|
|
form_select("Batch zip file $desc", 'batch_file', $sbitems_zip); |
|
52
|
|
|
form_input_text( |
|
53
|
|
|
'Command-line arguments<br><small>Passed to all jobs in the batch</small>', |
|
54
|
|
|
'cmdline' |
|
55
|
|
|
); |
|
56
|
|
|
form_input_text( |
|
57
|
|
|
'Max job runtime (days) on a typical (4.3 GFLOPS) computer. |
|
58
|
|
|
<br><small> |
|
59
|
|
|
The runtime limit will be scaled for faster/slower computers. |
|
60
|
|
|
<br> |
|
61
|
|
|
Jobs that reach this limit will be aborted. |
|
62
|
|
|
</small>' |
|
63
|
|
|
, |
|
64
|
|
|
'max_runtime_days', 1 |
|
65
|
|
|
); |
|
66
|
|
|
form_input_text( |
|
67
|
|
|
'Expected job runtime (days) on a typical (4.3 GFLOPS) computer. |
|
68
|
|
|
<br><small> |
|
69
|
|
|
This determines how many jobs are sent to each host, |
|
70
|
|
|
and how "fraction done" is computed. |
|
71
|
|
|
</small> |
|
72
|
|
|
', |
|
73
|
|
|
'exp_runtime_days', .5 |
|
74
|
|
|
); |
|
75
|
|
|
form_checkbox( |
|
76
|
|
|
"Enable debugging output <br><small>Write Docker commands and output to stderr. Not recommended for long-running jobs.</small>.", |
|
77
|
|
|
'wrapper_verbose' |
|
78
|
|
|
); |
|
79
|
|
|
form_submit('OK'); |
|
80
|
|
|
form_end(); |
|
81
|
|
|
page_tail(); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
// unzip batch file into a temp dir; return dir name |
|
85
|
|
|
// |
|
86
|
|
|
function unzip_batch_file($user, $batch_file) { |
|
87
|
|
|
@mkdir("../../buda_batches"); |
|
|
|
|
|
|
88
|
|
|
for ($i=0; $i<1000; $i++) { |
|
89
|
|
|
$batch_dir = "../../buda_batches/$i"; |
|
90
|
|
|
$batch_dir_name = $i; |
|
91
|
|
|
$ret = @mkdir($batch_dir); |
|
92
|
|
|
if ($ret) break; |
|
93
|
|
|
} |
|
94
|
|
|
if (!$ret) error_page("can't create batch dir"); |
|
|
|
|
|
|
95
|
|
|
$sb_dir = sandbox_dir($user); |
|
96
|
|
|
if (!file_exists("$sb_dir/$batch_file")) { |
|
97
|
|
|
error_page("no batch file $batch_file"); |
|
98
|
|
|
} |
|
99
|
|
|
system("cd $batch_dir; unzip $sb_dir/$batch_file > /dev/null", $ret); |
|
|
|
|
|
|
100
|
|
|
if ($ret) { |
|
101
|
|
|
error_page("unzip error: $ret"); |
|
102
|
|
|
} |
|
103
|
|
|
return $batch_dir_name; |
|
|
|
|
|
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
// Scan a batch dir. |
|
107
|
|
|
// Check its validity: |
|
108
|
|
|
// - optional dir 'shared_input_files' has shared input files |
|
109
|
|
|
// - other dirs (job dirs) can have only remaining infiles and possibly cmdline |
|
110
|
|
|
// |
|
111
|
|
|
// Return a structure describing its contents, and the md5/size of files |
|
112
|
|
|
// |
|
113
|
|
|
function parse_batch_dir($batch_dir, $variant_desc) { |
|
114
|
|
|
$input_files = $variant_desc->input_file_names; |
|
115
|
|
|
sort($input_files); |
|
116
|
|
|
$shared_files = []; |
|
117
|
|
|
$shared_file_infos = []; |
|
118
|
|
|
if (is_dir("$batch_dir/shared_input_files")) { |
|
119
|
|
|
foreach (scandir("$batch_dir/shared_input_files") as $fname) { |
|
120
|
|
|
if ($fname[0] == '.') continue; |
|
121
|
|
|
if (!in_array($fname, $input_files)) { |
|
122
|
|
|
error_page("$fname is not an input file name"); |
|
123
|
|
|
} |
|
124
|
|
|
$shared_files[] = $fname; |
|
125
|
|
|
$shared_file_infos[] = get_file_info("$batch_dir/shared_input_files/$fname"); |
|
126
|
|
|
} |
|
127
|
|
|
} |
|
128
|
|
|
$unshared_files = array_diff($input_files, $shared_files); |
|
129
|
|
|
sort($unshared_files); |
|
130
|
|
|
$jobs = []; |
|
131
|
|
|
foreach (scandir($batch_dir) as $fname) { |
|
132
|
|
|
if ($fname[0] == '.') continue; |
|
133
|
|
|
if ($fname == 'shared_input_files') continue; |
|
134
|
|
|
if (!is_dir("$batch_dir/$fname")) { |
|
135
|
|
|
error_page("$batch_dir/$fname is not a directory"); |
|
136
|
|
|
} |
|
137
|
|
|
$job_files = []; |
|
138
|
|
|
$cmdline = ''; |
|
139
|
|
|
foreach(scandir("$batch_dir/$fname") as $f2) { |
|
140
|
|
|
if ($f2[0] == '.') continue; |
|
141
|
|
|
if ($f2 == 'cmdline') { |
|
142
|
|
|
$cmdline = trim(file_get_contents("$batch_dir/$fname/cmdline")); |
|
143
|
|
|
continue; |
|
144
|
|
|
} |
|
145
|
|
|
if (!in_array($f2, $unshared_files)) { |
|
146
|
|
|
error_page("$fname/$f2 is not an input file name"); |
|
147
|
|
|
} |
|
148
|
|
|
$job_files[] = $f2; |
|
149
|
|
|
} |
|
150
|
|
|
if (array_values($job_files) != array_values($unshared_files)) { |
|
151
|
|
|
error_page("$fname doesn't have all input files"); |
|
152
|
|
|
} |
|
153
|
|
|
|
|
154
|
|
|
$file_infos = []; |
|
155
|
|
|
foreach ($unshared_files as $f2) { |
|
156
|
|
|
$file_infos[] = get_file_info("$batch_dir/$fname/$f2"); |
|
157
|
|
|
} |
|
158
|
|
|
|
|
159
|
|
|
$job = new StdClass; |
|
160
|
|
|
$job->dir = $fname; |
|
161
|
|
|
$job->cmdline = $cmdline; |
|
162
|
|
|
$job->file_infos = $file_infos; |
|
163
|
|
|
$jobs[] = $job; |
|
164
|
|
|
} |
|
165
|
|
|
$batch_desc = new StdClass; |
|
166
|
|
|
$batch_desc->shared_files = $shared_files; |
|
167
|
|
|
$batch_desc->shared_file_infos = $shared_file_infos; |
|
168
|
|
|
$batch_desc->unshared_files = $unshared_files; |
|
169
|
|
|
$batch_desc->jobs = $jobs; |
|
170
|
|
|
return $batch_desc; |
|
171
|
|
|
} |
|
172
|
|
|
|
|
173
|
|
|
function create_batch($user, $njobs, $app, $variant) { |
|
174
|
|
|
global $buda_boinc_app; |
|
175
|
|
|
$now = time(); |
|
176
|
|
|
$batch_name = sprintf('buda_%d_%d', $user->id, $now); |
|
177
|
|
|
$description = "$app ($variant)"; |
|
178
|
|
|
$batch_id = BoincBatch::insert(sprintf( |
|
179
|
|
|
"(user_id, create_time, logical_start_time, logical_end_time, est_completion_time, njobs, fraction_done, nerror_jobs, state, completion_time, credit_estimate, credit_canonical, credit_total, name, app_id, project_state, description, expire_time) values (%d, %d, 0, 0, 0, %d, 0, 0, %d, 0, 0, 0, 0, '%s', %d, 0, '%s', 0)", |
|
180
|
|
|
$user->id, $now, $njobs, BATCH_STATE_INIT, $batch_name, $buda_boinc_app->id, |
|
181
|
|
|
$description |
|
182
|
|
|
)); |
|
183
|
|
|
return BoincBatch::lookup_id($batch_id); |
|
184
|
|
|
} |
|
185
|
|
|
|
|
186
|
|
|
function stage_input_files($batch_dir, $batch_desc, $batch_id) { |
|
187
|
|
|
$n = count($batch_desc->shared_files); |
|
188
|
|
|
$batch_desc->shared_files_phys_names = []; |
|
189
|
|
|
for ($i=0; $i<$n; $i++) { |
|
190
|
|
|
$path = sprintf('%s/%s', $batch_dir, $batch_desc->shared_files[$i]); |
|
191
|
|
|
[$md5, $size] = $batch_desc->shared_file_infos[$i]; |
|
192
|
|
|
$phys_name = sprintf('batch_%d_%s', $batch_id, $md5); |
|
193
|
|
|
stage_file_aux($path, $md5, $size, $phys_name); |
|
194
|
|
|
$batch_desc->shared_files_phys_names[] = $phys_name; |
|
195
|
|
|
} |
|
196
|
|
|
foreach ($batch_desc->jobs as $job) { |
|
197
|
|
|
$n = count($batch_desc->unshared_files); |
|
198
|
|
|
$job->phys_names = []; |
|
199
|
|
|
for ($i=0; $i<$n; $i++) { |
|
200
|
|
|
$path = sprintf('%s/%s/%s', |
|
201
|
|
|
$batch_dir, $job->dir, $batch_desc->unshared_files[$i] |
|
202
|
|
|
); |
|
203
|
|
|
[$md5, $size] = $job->file_infos[$i]; |
|
204
|
|
|
$phys_name = sprintf('batch_%d_%s', $batch_id, $md5); |
|
205
|
|
|
stage_file_aux($path, $md5, $size, $phys_name); |
|
206
|
|
|
$job->phys_names[] = $phys_name; |
|
207
|
|
|
} |
|
208
|
|
|
} |
|
209
|
|
|
} |
|
210
|
|
|
|
|
211
|
|
|
// run bin/create_work to create the jobs. |
|
212
|
|
|
// Use --stdin, where each job is described by a line |
|
213
|
|
|
// |
|
214
|
|
|
function create_jobs( |
|
215
|
|
|
$app, $app_desc, $variant, $variant_desc, |
|
|
|
|
|
|
216
|
|
|
$batch_desc, $batch_id, $batch_dir_name, |
|
|
|
|
|
|
217
|
|
|
$wrapper_verbose, $cmdline, $max_fpops, $exp_fpops, |
|
|
|
|
|
|
218
|
|
|
$keywords |
|
219
|
|
|
) { |
|
220
|
|
|
global $buda_boinc_app; |
|
221
|
|
|
|
|
222
|
|
|
// get list of physical names of app files |
|
223
|
|
|
// |
|
224
|
|
|
$app_file_names = $variant_desc->dockerfile_phys; |
|
225
|
|
|
foreach ($variant_desc->app_files_phys as $pname) { |
|
226
|
|
|
$app_file_names .= " $pname"; |
|
227
|
|
|
} |
|
228
|
|
|
|
|
229
|
|
|
// make per-job lines to pass as stdin |
|
230
|
|
|
// |
|
231
|
|
|
$job_cmds = ''; |
|
232
|
|
|
foreach ($batch_desc->jobs as $job) { |
|
233
|
|
|
$job_cmd = sprintf('--wu_name batch_%d__job_%s', $batch_id, $job->dir); |
|
234
|
|
|
if ($job->cmdline) { |
|
235
|
|
|
$job_cmd .= sprintf(' --command_line "%s"', $job->cmdline); |
|
236
|
|
|
} |
|
237
|
|
|
$job_cmd .= " $app_file_names"; |
|
238
|
|
|
foreach ($batch_desc->shared_files_phys_names as $x) { |
|
239
|
|
|
$job_cmd .= " $x"; |
|
240
|
|
|
} |
|
241
|
|
|
foreach ($job->phys_names as $x) { |
|
242
|
|
|
$job_cmd .= " $x"; |
|
243
|
|
|
} |
|
244
|
|
|
$job_cmds .= "$job_cmd\n"; |
|
245
|
|
|
} |
|
246
|
|
|
$wrapper_cmdline = sprintf('"--dockerfile %s %s %s"', |
|
247
|
|
|
$variant_desc->dockerfile, |
|
248
|
|
|
$wrapper_verbose?'--verbose':'', |
|
249
|
|
|
$cmdline |
|
250
|
|
|
); |
|
251
|
|
|
$cmd = sprintf( |
|
252
|
|
|
'cd ../..; bin/create_work --appname %s --sub_appname "%s" --batch %d --stdin --command_line %s --wu_template %s --result_template %s --rsc_fpops_bound %f --rsc_fpops_est %f', |
|
253
|
|
|
$buda_boinc_app->name, |
|
254
|
|
|
$app_desc->long_name, |
|
255
|
|
|
$batch_id, |
|
256
|
|
|
$wrapper_cmdline, |
|
257
|
|
|
"buda_apps/$app/$variant/template_in", |
|
258
|
|
|
"buda_apps/$app/$variant/template_out", |
|
259
|
|
|
$max_fpops, $exp_fpops |
|
260
|
|
|
); |
|
261
|
|
|
if ($keywords) { |
|
262
|
|
|
$cmd .= " --keywords '$keywords'"; |
|
263
|
|
|
} |
|
264
|
|
|
$cmd .= sprintf(' > %s 2<&1', "buda_batches/errfile"); |
|
265
|
|
|
|
|
266
|
|
|
$h = popen($cmd, "w"); |
|
267
|
|
|
if (!$h) error_page('create_work launch failed'); |
|
|
|
|
|
|
268
|
|
|
fwrite($h, $job_cmds); |
|
269
|
|
|
$ret = pclose($h); |
|
270
|
|
|
if ($ret) { |
|
271
|
|
|
echo "<pre>create_work failed.\n"; |
|
272
|
|
|
echo "command: $cmd\n\n"; |
|
273
|
|
|
echo "job lines:\n$job_cmds\n\n"; |
|
274
|
|
|
echo "error file:\n"; |
|
275
|
|
|
readfile("../../buda_batches/errfile"); |
|
276
|
|
|
exit; |
|
|
|
|
|
|
277
|
|
|
} |
|
278
|
|
|
} |
|
279
|
|
|
|
|
280
|
|
|
function handle_submit($user) { |
|
281
|
|
|
global $buda_root; |
|
282
|
|
|
|
|
283
|
|
|
$app = get_str('app'); |
|
284
|
|
|
if (!is_valid_filename($app)) die('bad arg'); |
|
|
|
|
|
|
285
|
|
|
$variant = get_str('variant'); |
|
286
|
|
|
if (!is_valid_filename($variant)) die('bad arg'); |
|
|
|
|
|
|
287
|
|
|
$batch_file = get_str('batch_file'); |
|
288
|
|
|
if (!is_valid_filename($batch_file)) die('bad arg'); |
|
|
|
|
|
|
289
|
|
|
$wrapper_verbose = get_str('wrapper_verbose', true); |
|
290
|
|
|
$cmdline = get_str('cmdline'); |
|
291
|
|
|
|
|
292
|
|
|
$max_runtime_days = get_str('max_runtime_days'); |
|
293
|
|
|
if (!is_numeric($max_runtime_days)) error_page('bad runtime limit'); |
|
294
|
|
|
$max_runtime_days = (double)$max_runtime_days; |
|
295
|
|
|
if ($max_runtime_days <= 0) error_page('bad runtime limit'); |
|
296
|
|
|
if ($max_runtime_days > 100) error_page('bad runtime limit'); |
|
297
|
|
|
$max_fpops = $max_runtime_days * 4.3e9 * 86400; |
|
298
|
|
|
|
|
299
|
|
|
$exp_runtime_days = get_str('exp_runtime_days'); |
|
300
|
|
|
if (!is_numeric($exp_runtime_days)) error_page('bad expected runtime'); |
|
301
|
|
|
$exp_runtime_days = (double)$exp_runtime_days; |
|
302
|
|
|
if ($exp_runtime_days <= 0) error_page('bad expected runtime'); |
|
303
|
|
|
if ($exp_runtime_days > 100) error_page('bad expected runtime'); |
|
304
|
|
|
if ($exp_runtime_days > $max_runtime_days) { |
|
305
|
|
|
error_page('exp must be < max runtime'); |
|
306
|
|
|
} |
|
307
|
|
|
$exp_fpops = $exp_runtime_days * 4.3e9 * 86400; |
|
308
|
|
|
|
|
309
|
|
|
$app_desc = get_buda_desc($app); |
|
310
|
|
|
|
|
311
|
|
|
$variant_dir = "$buda_root/$app/$variant"; |
|
312
|
|
|
$variant_desc = json_decode( |
|
313
|
|
|
file_get_contents("$variant_dir/variant.json") |
|
314
|
|
|
); |
|
315
|
|
|
|
|
316
|
|
|
// unzip batch file into temp dir |
|
317
|
|
|
$batch_dir_name = unzip_batch_file($user, $batch_file); |
|
318
|
|
|
$batch_dir = "../../buda_batches/$batch_dir_name"; |
|
319
|
|
|
|
|
320
|
|
|
// scan batch dir; validate and return struct |
|
321
|
|
|
$batch_desc = parse_batch_dir($batch_dir, $variant_desc); |
|
322
|
|
|
|
|
323
|
|
|
$batch = create_batch( |
|
324
|
|
|
$user, count($batch_desc->jobs), $app, $variant |
|
325
|
|
|
); |
|
326
|
|
|
|
|
327
|
|
|
// stage input files and record the physical names |
|
328
|
|
|
// |
|
329
|
|
|
stage_input_files($batch_dir, $batch_desc, $batch->id); |
|
330
|
|
|
|
|
331
|
|
|
// get job keywords: user keywords plus BUDA app keywords |
|
332
|
|
|
// |
|
333
|
|
|
[$yes, $no] = read_kw_prefs($user); |
|
334
|
|
|
$keywords = array_merge($yes, $app_desc->sci_kw, $app_desc->loc_kw); |
|
335
|
|
|
$keywords = array_unique($keywords); |
|
336
|
|
|
$keywords = implode(' ', $keywords); |
|
337
|
|
|
|
|
338
|
|
|
create_jobs( |
|
339
|
|
|
$app, $app_desc, $variant, $variant_desc, |
|
340
|
|
|
$batch_desc, $batch->id, $batch_dir_name, |
|
341
|
|
|
$wrapper_verbose, $cmdline, $max_fpops, $exp_fpops, $keywords |
|
342
|
|
|
); |
|
343
|
|
|
|
|
344
|
|
|
// mark batch as in progress |
|
345
|
|
|
// |
|
346
|
|
|
$batch->update(sprintf('state=%d', BATCH_STATE_IN_PROGRESS)); |
|
347
|
|
|
|
|
348
|
|
|
// clean up batch dir |
|
349
|
|
|
// |
|
350
|
|
|
//system("rm -rf $batch_dir"); |
|
351
|
|
|
|
|
352
|
|
|
header("Location: submit.php?action=query_batch&batch_id=$batch->id"); |
|
353
|
|
|
} |
|
354
|
|
|
|
|
355
|
|
|
function show_list() { |
|
356
|
|
|
page_head('BUDA job submission'); |
|
357
|
|
|
$apps = get_buda_apps(); |
|
358
|
|
|
echo 'Select app and variant:<p><br>'; |
|
359
|
|
|
foreach ($apps as $app) { |
|
360
|
|
|
$desc = get_buda_desc($app); |
|
361
|
|
|
$vars = get_buda_variants($app); |
|
362
|
|
|
echo "$desc->long_name |
|
363
|
|
|
<ul> |
|
364
|
|
|
"; |
|
365
|
|
|
foreach ($vars as $var) { |
|
366
|
|
|
echo sprintf('<li><a href=buda_submit.php?action=form&app=%s&variant=%s>%s</a>', |
|
367
|
|
|
$app, $var, $var |
|
368
|
|
|
); |
|
369
|
|
|
} |
|
370
|
|
|
echo "</ul>\n"; |
|
371
|
|
|
} |
|
372
|
|
|
page_tail(); |
|
373
|
|
|
} |
|
374
|
|
|
|
|
375
|
|
|
$user = get_logged_in_user(); |
|
|
|
|
|
|
376
|
|
|
$buda_boinc_app = BoincApp::lookup("name='buda'"); |
|
377
|
|
|
if (!$buda_boinc_app) error_page('no buda app'); |
|
378
|
|
|
if (!has_submit_access($user, $buda_boinc_app->id)) { |
|
379
|
|
|
error_page('no access'); |
|
380
|
|
|
} |
|
381
|
|
|
$action = get_str('action', true); |
|
382
|
|
|
if ($action == 'submit') { |
|
383
|
|
|
handle_submit($user); |
|
384
|
|
|
} else if ($action == 'form') { |
|
385
|
|
|
submit_form($user); |
|
386
|
|
|
} else { |
|
387
|
|
|
show_list(); |
|
|
|
|
|
|
388
|
|
|
} |
|
389
|
|
|
|
|
390
|
|
|
?> |
|
391
|
|
|
|
In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.