-
Notifications
You must be signed in to change notification settings - Fork 514
Expand file tree
/
Copy pathsubmit.php
More file actions
1166 lines (1093 loc) · 36.1 KB
/
submit.php
File metadata and controls
1166 lines (1093 loc) · 36.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
// This file is part of BOINC.
// http://boinc.berkeley.edu
// Copyright (C) 2024 University of California
//
// BOINC is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License
// as published by the Free Software Foundation,
// either version 3 of the License, or (at your option) any later version.
//
// BOINC is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
// See the GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
// remote job submission functions.
//
// A 'remote app' is one where jobs are submitted remotely:
// - via web RPCs
// - via forms on the project web site
//
// In both cases only users with permission can submit; either
// - a user_submit record with submit_all set
// - a user_submit_app record
//
// These apps are described in $remote_apps in project.inc
//
// This page provides several functions involving remote apps
// ('me' means logged-in user)
//
// show_all_batches
// show list of batches visible to me, possibly filtered by
// submitting user
// app
// state (in progress, completed etc.)
// show_user_batches
// show my batches
// show_batches_admin_app
// show all batches for a given app to admin
// admin_all
// show all batches to admin
// batch_stats
// show WSS, disk usage stats for a batch
// query_batch
// show list of jobs in a batch
// query_job
// show job details and instances
// retire_batch
// retire a batch
// retire_multi
// retire multiple batches
// abort_batch
// abort a batch
// admin
// show index of admin functions
// update_only_own
// control whether my jobs should run only on my computers
require_once("../inc/submit_db.inc");
require_once("../inc/util.inc");
require_once("../inc/result.inc");
require_once("../inc/submit_util.inc");
require_once("../project/project.inc");
require_once('../project/remote_apps.inc');
display_errors();
// in general, if there can be lots of something,
// show this many and a link to show all.
// TODO: jobs in a batch
//
define("PAGE_SIZE", 20);
function return_link() {
echo "<p><a href=submit.php?action=show_user_batches>Return to batches page</a>\n";
}
// return subset of batches in given state
//
function batches_in_state($all_batches, $state) {
$batches = [];
foreach ($all_batches as $batch) {
if ($batch->state != $state) continue;
$batches[] = $batch;
}
return $batches;
}
function sort_batches(&$batches, $order) {
switch ($order) {
case 'sub_asc':
$f = function($a, $b) {
return (int)($a->create_time - $b->create_time);
};
break;
case 'sub_desc':
$f = function($a, $b) {
return (int)($b->create_time - $a->create_time);
};
break;
case 'comp_asc':
$f = function($a, $b) {
return (int)($a->completion_time - $b->completion_time);
};
break;
case 'comp_desc':
$f = function($a, $b) {
return (int)($b->completion_time - $a->completion_time);
};
break;
}
usort($batches, $f);
}
// in progress batches don't have completion time
//
function in_progress_order($order) {
switch ($order) {
case 'comp_asc': return 'sub_asc';
case 'comp_desc': return 'sub_desc';
}
return $order;
}
// show order options
// sub_asc, sub_desc: submission time ( = ID order)
// comp_asc, comp_desc: completion time
function order_options($url_args, $order) {
$url = "submit.php?$url_args";
echo sprintf(
'Order by: submission time (%s, %s) or completion time (%s, %s)',
order_item($url, $order, 'sub_asc', 'ascending'),
order_item($url, $order, 'sub_desc', 'descending'),
order_item($url, $order, 'comp_asc', 'ascending'),
order_item($url, $order, 'comp_desc', 'descending')
);
}
function order_item($url, $cur_order, $order, $label) {
if ($cur_order == $order) {
return $label;
} else {
$url .= "&order=$order";
return "<a href=$url>$label</a>";
}
}
function get_order() {
$order = get_str('order', true);
if (!$order) $order = 'sub_desc';
return $order;
}
function state_count($batches, $state) {
$n = 0;
foreach ($batches as $batch) {
if ($batch->state == $state) $n++;
}
return $n;
}
function show_all_batches_link($batches, $state, $limit, $user, $app) {
$n = state_count($batches, $state);
if ($n > $limit) {
if ($user) $userid = $user->id;
else $userid = 0;
if ($app) $appid = $app->id;
else $appid = 0;
echo "Showing the most recent $limit of $n batches.
<a href=submit.php?action=show_all_batches&state=$state&userid=$userid&appid=$appid>Show all $n</a>
<p>
";
}
}
// show in-progress batches.
//
function show_in_progress($all_batches, $order, $limit, $user, $app) {
$batches = batches_in_state($all_batches, BATCH_STATE_IN_PROGRESS);
sort_batches($batches, in_progress_order($order));
echo sprintf('<h3>Batches in progress (%d)</h3>', count($batches));
$first = true;
$n = 0;
foreach ($batches as $batch) {
if ($limit && $n == $limit) break;
$n++;
if ($first) {
$first = false;
if ($limit) {
show_all_batches_link(
$batches, BATCH_STATE_IN_PROGRESS, $limit, $user, $app
);
}
form_start('submit.php');
form_input_hidden('action', 'abort_selected');
start_table('table-striped');
$x = [
"Name",
"ID",
"User",
"App",
"# jobs",
"Progress",
"Submitted"
];
row_heading_array($x);
}
$pct_done = (int)($batch->fraction_done*100);
$x = [
"<a href=submit.php?action=query_batch&batch_id=$batch->id>$batch->name</a>",
"<a href=submit.php?action=query_batch&batch_id=$batch->id>$batch->id</a>",
$batch->user_name,
$batch->app_name,
$batch->njobs,
"$pct_done%",
local_time_str($batch->create_time)
];
row_array($x);
}
if ($first) {
echo "<p>None.\n";
} else {
end_table();
form_end();
}
}
function show_complete($all_batches, $order, $limit, $user, $app) {
$batches = batches_in_state($all_batches, BATCH_STATE_COMPLETE);
sort_batches($batches, $order);
echo sprintf('<h3>Completed batches (%d)</h3>', count($batches));
$first = true;
$n = 0;
foreach ($batches as $batch) {
if ($limit && $n == $limit) break;
$n++;
if ($first) {
$first = false;
if ($limit) {
show_all_batches_link($batches, BATCH_STATE_COMPLETE, $limit, $user, $app);
}
form_start('submit.php', 'get');
form_input_hidden('action', 'retire_multi');
start_table('table-striped');
table_header(
"Name", "ID", "User", "App", "# Jobs", "Submitted", "Completed", "Select"
);
}
table_row(
"<a href=submit.php?action=query_batch&batch_id=$batch->id>$batch->name</a>",
"<a href=submit.php?action=query_batch&batch_id=$batch->id>$batch->id</a>",
$batch->user_name,
$batch->app_name,
$batch->njobs,
local_time_str($batch->create_time),
local_time_str($batch->completion_time),
sprintf('<input type=checkbox name=retire_%d>', $batch->id)
);
}
if ($first) {
echo "<p>None.\n";
} else {
end_table();
form_submit('Retire selected batches');
form_end();
}
}
function show_aborted($all_batches, $order, $limit, $user, $app) {
$batches = batches_in_state($all_batches, BATCH_STATE_ABORTED);
if (!$batches) return;
sort_batches($batches, $order);
echo sprintf('<h3>Aborted batches (%d)</h3>', count($batches));
$first = true;
$n = 0;
foreach ($batches as $batch) {
if ($limit && $n == $limit) break;
$n++;
if ($first) {
$first = false;
if ($limit) {
show_all_batches_link($batches, BATCH_STATE_ABORTED, $limit, $user, $app);
}
form_start('submit.php', 'get');
form_input_hidden('action', 'retire_multi');
start_table();
table_header("Name", "ID", "User", "App", "# Jobs", "Submitted", "Aborted", 'Select');
}
table_row(
"<a href=submit.php?action=query_batch&batch_id=$batch->id>$batch->name</a>",
"<a href=submit.php?action=query_batch&batch_id=$batch->id>$batch->id</a>",
$batch->user_name,
$batch->app_name,
$batch->njobs,
local_time_str($batch->create_time),
local_time_str($batch->completion_time),
sprintf('<input type=checkbox name=retire_%d>', $batch->id)
);
}
if (!$first) {
end_table();
form_submit('Retire selected batches');
form_end();
}
}
// fill in the app and user names in list of batches
//
function fill_in_app_and_user_names(&$batches) {
$apps = [];
$users = [];
foreach ($batches as $batch) {
if (array_key_exists($batch->app_id, $apps)) {
$app = $apps[$batch->app_id];
} else {
$app = BoincApp::lookup_id($batch->app_id);
$apps[$batch->app_id] = $app;
}
if ($app) {
$batch->app_name = $app->name;
if ($batch->description) {
$batch->app_name .= " ($batch->description)";
}
} else {
$batch->app_name = "unknown";
}
if (array_key_exists($batch->user_id, $users)) {
$user = $users[$batch->user_id];
} else {
$user = BoincUser::lookup_id($batch->user_id);
$users[$batch->user_id] = $user;
}
if ($user) {
$batch->user_name = $user->name;
} else {
$batch->user_name = "missing user $batch->user_id";
}
}
}
// show a set of batches: in progress, then completed, then aborted
//
function show_batches($batches, $order, $limit, $user, $app) {
fill_in_app_and_user_names($batches);
$batches = get_batches_params($batches);
show_in_progress($batches, $order, $limit, $user, $app);
show_complete($batches, $order, $limit, $user, $app);
show_aborted($batches, $order, $limit, $user, $app);
}
// show links to per-app job submission forms
//
function show_submit_links($user) {
global $remote_apps;
$user_submit = BoincUserSubmit::lookup_userid($user->id);
if (!$user_submit) {
error_page("Ask the project admins for permission to submit jobs");
}
page_head("Submit jobs");
// show links to per-app job submission pages
//
foreach ($remote_apps as $area => $apps) {
panel($area,
function() use ($apps) {
foreach ($apps as $app) {
if (empty($app->form)) continue;
// show app logo if available
if (!empty($app->logo)) {
echo sprintf(
'<a href=%s><img width=100 src=%s></a> ',
$app->form, $app->logo
);
} else {
echo sprintf(
'<a href=%s>%s</a><p>',
$app->form, $app->long_name
);
}
}
}
);
}
form_start('submit.php');
form_input_hidden('action', 'update_only_own');
form_radio_buttons(
'Jobs you submit can run', 'only_own',
[
[0, 'on any computer'],
[1, 'only on your computers (and no other jobs will run there)']
],
$user->seti_id
);
form_submit('Update');
form_end();
page_tail();
}
// show batches of logged in user.
// They have manage access to these batches.
//
function handle_show_user_batches($user) {
page_head("Your batches");
$order = get_order();
order_options('action=show_user_batches', $order);
$batches = BoincBatch::enum("user_id = $user->id");
show_batches($batches, $order, PAGE_SIZE, $user, null);
page_tail();
}
function handle_update_only_own($user) {
if (!parse_bool(get_config(), 'enable_assignment')) {
error_page(
'Job assignment is not enabled in the project config file.
Please ask the project admins to enable it.'
);
return;
}
$val = get_int('only_own');
if ($val) {
if (BoincHost::count("userid=$user->id") == 0) {
error_page(
"You don't have any computers running BOINC and attached to this project."
);
}
}
$user->update("seti_id=$val");
header("Location: submit.php");
}
// get list of app names of remote apps
//
function get_remote_app_names() {
global $remote_apps;
$x = [];
foreach ($remote_apps as $category => $apps) {
foreach ($apps as $app) {
$x[] = $app->app_name;
}
}
return array_unique($x);
}
// show links for everything the user has admin access to
//
function handle_admin($user) {
$user_submit = BoincUserSubmit::lookup_userid($user->id);
if (!$user_submit) error_page('no access');
if ($user_submit->manage_all) {
// user can administer all apps
//
page_head("Job submission: manage all apps");
echo '<ul>';
echo "<li> <a href=submit.php?action=admin_all>View/manage all batches</a>
";
$app_names = get_remote_app_names();
foreach ($app_names as $app_name) {
$app_name = BoincDb::escape_string($app_name);
$app = BoincApp::lookup("name='$app_name'");
echo "
<li>$app->user_friendly_name<br>
<ul>
<li><a href=submit.php?action=show_batches_admin_app&app_id=$app->id>View/manage batches</a>
";
if ($app_name == 'buda') {
echo "
<li> <a href=buda.php>Manage BUDA apps and variants</a>
";
} else {
echo "
<li> <a href=manage_app.php?app_id=$app->id&action=app_version_form>Manage app versions</a>
";
}
echo "
</ul>
";
}
} else {
// see if user can administer specific apps
//
page_head("Job submission: manage apps");
echo '<ul>';
$usas = BoincUserSubmitApp::enum("user_id=$user->id");
foreach ($usas as $usa) {
$app = BoincApp::lookup_id($usa->app_id);
echo "<li>$app->user_friendly_name<br>
<a href=submit.php?action=show_batches_admin_app&app_id=$app->id>Batches</a>
";
if ($usa->manage) {
echo "·
<a href=manage_app.php?app_id=$app->id&action=app_version_form>Versions</a>
";
}
}
}
echo "</ul>\n";
page_tail();
}
// show all batches for given app to administrator
//
function show_batches_admin_app($user) {
$app_id = get_int("app_id");
$app = BoincApp::lookup_id($app_id);
if (!$app) error_page("no such app");
if (!has_manage_access($user, $app_id)) {
error_page('no access');
}
$order = get_order();
page_head("Manage batches for $app->user_friendly_name");
order_options("action=show_batches_admin_app&app_id=$app_id", $order);
$batches = BoincBatch::enum("app_id = $app_id");
show_batches($batches, $order, PAGE_SIZE, null, $app);
page_tail();
}
function handle_admin_all($user) {
$order = get_order();
page_head("Administer batches (all apps and users)");
order_options("action=admin_all", $order);
$batches = BoincBatch::enum('');
show_batches($batches, $order, PAGE_SIZE, null, null);
page_tail();
}
// show the statics of mem/disk usage of jobs in a batch
//
function handle_batch_stats($user) {
$batch_id = get_int('batch_id');
$batch = BoincBatch::lookup_id($batch_id);
$results = BoincResult::enum_fields(
'peak_working_set_size, peak_swap_size, peak_disk_usage',
sprintf('batch = %d and outcome=%d',
$batch->id, RESULT_OUTCOME_SUCCESS
)
);
page_head("Statistics for batch $batch_id");
$n = 0;
$wss_sum = 0;
$swap_sum = 0;
$disk_sum = 0;
$wss_max = 0;
$swap_max = 0;
$disk_max = 0;
foreach ($results as $r) {
// pre-7.3.16 clients don't report usage info
//
if ($r->peak_working_set_size == 0) {
continue;
}
$n++;
$wss_sum += $r->peak_working_set_size;
if ($r->peak_working_set_size > $wss_max) {
$wss_max = $r->peak_working_set_size;
}
$swap_sum += $r->peak_swap_size;
if ($r->peak_swap_size > $swap_max) {
$swap_max = $r->peak_swap_size;
}
$disk_sum += $r->peak_disk_usage;
if ($r->peak_disk_usage > $disk_max) {
$disk_max = $r->peak_disk_usage;
}
}
if ($n == 0) {
echo "No qualifying results.";
page_tail();
return;
}
text_start(800);
start_table('table-striped');
row2("qualifying results", $n);
row2("mean WSS", size_string($wss_sum/$n));
row2("max WSS", size_string($wss_max));
row2("mean swap", size_string($swap_sum/$n));
row2("max swap", size_string($swap_max));
row2("mean disk usage", size_string($disk_sum/$n));
row2("max disk usage", size_string($disk_max));
end_table();
text_end();
page_tail();
}
define('COLOR_SUCCESS', 'green');
define('COLOR_FAIL', 'red');
define('COLOR_IN_PROGRESS', 'deepskyblue');
define('COLOR_UNSENT', 'gray');
// return HTML for a color-coded batch progress bar
//
function progress_bar($batch, $wus, $width) {
$nsuccess = $batch->njobs_success;
$nerror = $batch->nerror_jobs;
$nin_prog = $batch->njobs_in_prog;
$nunsent = $batch->njobs - $nsuccess - $nerror - $nin_prog;
$w_success = $width*$nsuccess/$batch->njobs;
$w_fail = $width*$nerror/$batch->njobs;
$w_prog = $width*$nin_prog/$batch->njobs;
$w_unsent = $width*$nunsent/$batch->njobs;
$x = '<table height=20><tr>';
if ($w_fail) {
$x .= sprintf('<td width=%d bgcolor=%s></td>', $w_fail, COLOR_FAIL);
}
if ($w_success) {
$x .= sprintf('<td width=%d bgcolor=%s></td>', $w_success, COLOR_SUCCESS);
}
if ($w_prog) {
$x .= sprintf('<td width=%d bgcolor=%s></td>', $w_prog, COLOR_IN_PROGRESS);
}
if ($w_unsent) {
$x .= sprintf('<td width=%d bgcolor=%s></td>', $w_unsent, COLOR_UNSENT);
}
$x .= sprintf('</tr></table>
<strong>
<font color=%s>%d failed</font> ·
<font color=%s>%d completed</font> ·
<font color=%s>%d in progress</font> ·
<font color=%s>%d unsent</font>
</strong>',
COLOR_FAIL, $nerror,
COLOR_SUCCESS, $nsuccess,
COLOR_IN_PROGRESS, $nin_prog,
COLOR_UNSENT, $nunsent
);
return $x;
}
// see if the batch's output files are gzipped
//
function is_batch_gzipped($wus) {
foreach ($wus as $wu) {
if ($wu->canonical_resultid == 0) continue;
$result = BoincResult::lookup_id($wu->canonical_resultid);
if (!$result) return false;
[, $gzip] = get_outfile_log_names($result);
foreach ($gzip as $flag) {
if ($flag) return true;
}
return false;
}
return false;
}
// show the details of an existing batch.
// $user has access to abort/retire the batch
// and to get its output files
//
function handle_query_batch($user) {
$batch_id = get_int('batch_id');
$status = get_int('status', true);
$batch = BoincBatch::lookup_id($batch_id);
if (!$batch) {
error_page('no batch');
}
$app = BoincApp::lookup_id($batch->app_id);
$wus = BoincWorkunit::enum_fields(
'id, name, rsc_fpops_est, canonical_credit, canonical_resultid, error_mask',
"batch = $batch->id"
);
$batch = get_batch_params($batch, $wus);
if ($batch->user_id == $user->id) {
$owner = $user;
} else {
$owner = BoincUser::lookup_id($batch->user_id);
}
$is_assim_move = is_assim_move($app);
page_head("Batch $batch_id");
text_start(800);
start_table();
row2("Batch name", $batch->name);
if ($batch->description) {
row2('Description', $batch->description);
}
if ($owner) {
row2('Submitter',
"<a href=show_user.php?userid=$owner->id>$owner->name</a>"
);
}
row2("Submitted", time_str($batch->create_time));
row2("Application", $app?$app->name:'---');
row2("State", batch_state_string($batch->state));
//row2("# jobs", $batch->njobs);
//row2("# error jobs", $batch->nerror_jobs);
//row2("logical end time", time_str($batch->logical_end_time));
if ($batch->expire_time) {
row2("Median turnaround time", time_diff($batch->expire_time));
}
if ($batch->njobs) {
row2('Progress', progress_bar($batch, $wus, 600));
}
if ($batch->completion_time) {
row2("Completed", local_time_str($batch->completion_time));
}
row2("GFLOP/hours, estimated", number_format(credit_to_gflop_hours($batch->credit_estimate), 2));
row2("GFLOP/hours, actual", number_format(credit_to_gflop_hours($batch->credit_canonical), 2));
if (!$is_assim_move) {
row2("Total size of output files",
size_string(batch_output_file_size($batch->id))
);
}
end_table();
echo "<p>";
if ($is_assim_move) {
//if (is_batch_gzipped($wus)) {
if (true) {
$url = "get_output3.php?action=get_batch_tar&batch_id=$batch->id";
show_button($url, "Get tarred output files");
} else {
$url = "get_output3.php?action=get_batch_zip&batch_id=$batch->id";
show_button($url, "Get zipped output files");
}
} else {
$url = "get_output2.php?cmd=batch&batch_id=$batch->id";
show_button($url, "Get zipped output files");
}
echo "<p>";
switch ($batch->state) {
case BATCH_STATE_IN_PROGRESS:
case BATCH_STATE_INIT:
show_button(
"submit.php?action=abort_batch&batch_id=$batch_id",
"Abort batch"
);
break;
case BATCH_STATE_COMPLETE:
case BATCH_STATE_ABORTED:
show_button(
"submit.php?action=retire_batch&batch_id=$batch_id",
"Retire batch"
);
break;
}
echo "<p>
<h3>Completed jobs</h3>
<ul>
<li>
<a href=submit_stats.php?action=graphs&batch_id=$batch_id>Job runtimes</a>
<li>
<a href=submit.php?action=batch_stats&batch_id=$batch_id>Memory/disk usage</a>
<li>
<a href=submit_stats.php?action=show_hosts&batch_id=$batch_id>Grouped by host</a>
</ul>
<h3>Failed jobs</h3>
<ul>
<li>
<a href=submit_stats.php?action=err_host&batch_id=$batch_id>Grouped by host</a>
<li>
<a href=submit_stats.php?action=err_code&batch_id=$batch_id>Grouped by exit code</a>
</ul>
";
echo "<h2>Jobs</h2>\n";
$url = "submit.php?action=query_batch&batch_id=$batch_id";
echo "Show: ";
echo sprintf('
<a href=%s&status=%d>failed</a> ·
<a href=%s&status=%d>completed</a> ·
<a href=%s&status=%d>in progress</a> ·
<a href=%s&status=%d>unsent</a> ·
<a href=%s>all</a>
<p>',
$url, WU_ERROR,
$url, WU_SUCCESS,
$url, WU_IN_PROGRESS,
$url, WU_UNSENT,
$url
);
start_table('table-striped');
$x = [
"Name <br><small>click for details</small>",
"status",
"GFLOPS-hours"
];
row_heading_array($x);
foreach($wus as $wu) {
if ($status && $wu->status != $status) continue;
$y = '';
$c = '---';
switch($wu->status) {
case WU_SUCCESS:
$resultid = $wu->canonical_resultid;
$y = sprintf('<font color="%s">completed</font>', COLOR_SUCCESS);
$c = number_format(
credit_to_gflop_hours($wu->canonical_credit), 2
);
break;
case WU_ERROR:
$y = sprintf('<font color="%s">failed</font>', COLOR_FAIL);
break;
case WU_IN_PROGRESS:
$y = sprintf('<font color="%s">in progress</font>', COLOR_IN_PROGRESS);
break;
case WU_UNSENT:
$y = sprintf('<font color="%s">unsent</font>', COLOR_UNSENT);
break;
}
$x = [
"<a href=submit.php?action=query_job&wuid=$wu->id>$wu->name</a>",
$y,
$c
];
row_array($x);
}
end_table();
return_link();
text_end();
page_tail();
}
// Does the assimilator for the given app move output files
// to a results/<batchid>/ directory?
// This info is stored in the $remote_apps data structure in project.inc
//
function is_assim_move($app) {
global $remote_apps;
foreach ($remote_apps as $category => $apps) {
foreach ($apps as $web_app) {
if ($web_app->app_name == $app->name) {
return $web_app->is_assim_move;
}
}
}
return false;
}
// show the details of a job, including links to see the output files
//
function handle_query_job($user) {
$wuid = get_int('wuid');
$wu = BoincWorkunit::lookup_id($wuid);
if (!$wu) error_page("no such job");
$app = BoincApp::lookup_id($wu->appid);
$is_assim_move = is_assim_move($app);
page_head("Job '$wu->name'");
echo "
<ul>
<li><a href=workunit.php?wuid=$wuid>Job details</a>
<p>
<li><a href=submit.php?action=query_batch&batch_id=$wu->batch>Batch details</a>
</ul>
";
$d = "<foo>$wu->xml_doc</foo>";
$x = simplexml_load_string($d);
$x = $x->workunit;
//echo "foo: $x->command_line";
echo "<h2>Job instances</h2>\n";
start_table('table-striped');
table_header(
"ID<br><small>click for details and stderr</small>",
"State",
'Sent',
'Received',
'Priority',
"Output files"
);
$results = BoincResult::enum("workunitid=$wuid");
$upload_dir = parse_config(get_config(), "<upload_dir>");
$fanout = parse_config(get_config(), "<uldl_dir_fanout>");
foreach ($results as $result) {
$x = [
"<a href=result.php?resultid=$result->id>$result->id</a>",
state_string($result),
time_str($result->sent_time),
time_str($result->received_time),
$result->priority
];
$files = [];
if ($is_assim_move) {
if ($result->id == $wu->canonical_resultid) {
[$log_names, $gzip] = get_outfile_log_names($result);
$nfiles = count($log_names);
for ($i=0; $i<$nfiles; $i++) {
$name = $log_names[$i];
$path = assim_move_outfile_path($wu, $i, $log_names, $gzip);
if (file_exists($path)) {
$y = sprintf('%s (%s): ',
$name, size_string(filesize($path))
);
// don't show 'view' link if it's zipped
if (!strstr($name, '.zip') && !$gzip[$i]) {
$y .= sprintf(
'<a href=get_output3.php?action=get_file&result_id=%d&index=%d>view</a> · ',
$result->id, $i
);
}
$y .= sprintf(
'<a href=get_output3.php?action=get_file&result_id=%d&index=%d&download=1>download</a>',
$result->id, $i
);
} else {
$y = sprintf('%s: MISSING', $name);
}
$files[] = $y;
}
} else {
$files[] = '---';
}
} else {
if ($result->server_state == RESULT_SERVER_STATE_OVER) {
$phys_names = get_outfile_phys_names($result);
[$log_names,] = get_outfile_log_names($result);
$nfiles = count($log_names);
for ($i=0; $i<$nfiles; $i++) {
$path = dir_hier_path(
$phys_names[$i], $upload_dir, $fanout
);
if (file_exists($path)) {
$url = sprintf(
'get_output2.php?cmd=result&result_id=%d&file_num=%d',
$result->id, $i
);
$s = stat($path);
$size = $s['size'];
$files[] = sprintf('<a href=%s>%s</a> (%s bytes)<br/>',
$url,
$log_names[$i],
number_format($size)
);
} else {
$files[] = sprintf("file '%s' is missing", $log_names[$i]);
}
}
} else {
$files[] = '---';
}
}
$x[] = implode('<br>', $files);
row_array($x);
}
end_table();
// show input files
//
echo "<h2>Input files</h2>\n";
$x = "<in>".$wu->xml_doc."</in>";
$x = simplexml_load_string($x);
if ($x->workunit->file_ref) {
start_table('table-striped');
table_header("Name<br><small>(click to view)</small>", "Size (bytes)");
foreach ($x->workunit->file_ref as $fr) {
$pname = (string)$fr->file_name;
$lname = (string)$fr->open_name;
foreach ($x->file_info as $fi) {
if ((string)$fi->name == $pname) {
table_row(
"<a href=$fi->url>$lname</a>",
$fi->nbytes
);
break;
}
}
}
end_table();
} else {
echo "The job has no input files.<p>";
}
return_link();
page_tail();
}
// is user allowed to retire or abort this batch?
//
function has_access($user, $batch) {
if ($user->id == $batch->user_id) return true;
$user_submit = BoincUserSubmit::lookup_userid($user->id);
if ($user_submit->manage_all) return true;
$usa = BoincUserSubmitApp::lookup("user_id=$user->id and app_id=$batch->app_id");
if ($usa->manage) return true;
return false;
}
function handle_abort_batch($user) {
$batch_id = get_int('batch_id');
$batch = BoincBatch::lookup_id($batch_id);
if (!$batch) error_page("no such batch");
if (!has_access($user, $batch)) {
error_page("no access");
}