-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathuslims_jobs.php
1231 lines (1056 loc) · 36.4 KB
/
uslims_jobs.php
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
# user defines
$us3lims = exec( "ls -d ~us3/lims" );
$ll_base_dir = "$us3lims/etc/joblog";
$udplogf = "$us3lims/etc/udp.log";
$us3bin = "$us3lims/bin";
$cwd = getcwd();
$getrunbdir = "$cwd/getrun";
include "$us3bin/listen-config.php";
if ( file_exists( $class_dir_p . "job_details.php" ) ) {
include $class_dir_p . "job_details.php";
}
$global_config_file = $class_dir_p . "../global_config.php";
include $global_config_file;
# end user defines
# developer defines
$logging_level = 2;
# end of developer defines
$self = __FILE__;
$notes = <<<__EOD
usage: $self {options} {db_config_file}
information about submitted jobs
Options
--help : print this information and exit
--db name : select database to report (required for most options)
--reqid id : provide information on the specific HPCAnalysisRequestID
--gfacid id : provide information on the specific gfacID
--onlygfac : just return the gfacid for a request id
--full : display all field data (normally truncates multiline outputs to last line)
--queue-messages : include queue message detail
--monitor : monitor the output (requires --gfacid)
--running : report on all running jobs (gfac.analysis & active jobmonitor.php)
--restart : restart jobmonitors if needed (e.g. after a system reboot)
--check-log : checks the log (requires --gfacid & exclusive of --monitor)
--getrundir : gets running directory for airavata jobs
--getrun : collects running info from rundir into $getrunbdir/db/HPCAnalysisRequestID
--runinfo : displays various debugging info for airavata jobs
--copyrun queue : gets running info and sends to remote cluster for testing
--ga-times : reports timings for ga mc jobs (experimental)
--pmg n : report timings for specific pmg # (default 0), use 'all' do show all, 'most-recent' for just most recent, 'max-gen' for details about pmg with maximum generation
--airavata-details : get current airavata job details (requires --gfacid)
--maxrss : maximum memory used report for selected database
__EOD;
require "utility.php";
$u_argv = $argv;
array_shift( $u_argv ); # first element is program name
$db = false;
$reqid = false;
$gfacid = false;
$onlygfac = false;
$anyargs = false;
$fullrpt = false;
$qmesgs = false;
$monitor = false;
$running = false;
$restart = false;
$checklog = false;
$getrundir = false;
$getrun = false;
$runinfo = false;
$copyrun = false;
$gatimes = false;
$adetails = false;
$pmg = 0;
$maxrss = false;
while( count( $u_argv ) && substr( $u_argv[ 0 ], 0, 1 ) == "-" ) {
$anyargs = true;
switch( $arg = $u_argv[ 0 ] ) {
case "--help": {
echo $notes;
exit;
}
case "--db": {
array_shift( $u_argv );
if ( !count( $u_argv ) ) {
error_exit( "ERROR: option '$arg' requires an argument\n$notes" );
}
$db = array_shift( $u_argv );
break;
}
case "--pmg": {
array_shift( $u_argv );
if ( !count( $u_argv ) ) {
error_exit( "ERROR: option '$arg' requires an argument\n$notes" );
}
$pmg = array_shift( $u_argv );
break;
}
case "--getrundir": {
array_shift( $u_argv );
$getrundir = true;
break;
}
case "--getrun": {
array_shift( $u_argv );
$getrun = true;
break;
}
case "--runinfo": {
array_shift( $u_argv );
$runinfo = true;
break;
}
case "--ga-times": {
array_shift( $u_argv );
$gatimes = true;
break;
}
case "--copyrun": {
array_shift( $u_argv );
if ( !count( $u_argv ) ) {
error_exit( "ERROR: option '$arg' requires an argument\n$notes" );
}
$copyrun = array_shift( $u_argv );
break;
}
case "--reqid": {
array_shift( $u_argv );
if ( !count( $u_argv ) ) {
error_exit( "ERROR: option '$arg' requires an argument\n$notes" );
}
$reqid = array_shift( $u_argv );
break;
}
case "--gfacid": {
array_shift( $u_argv );
if ( !count( $u_argv ) ) {
error_exit( "ERROR: option '$arg' requires an argument\n$notes" );
}
$gfacid = array_shift( $u_argv );
break;
}
case "--onlygfac": {
array_shift( $u_argv );
$onlygfac = true;
break;
}
case "--full": {
array_shift( $u_argv );
$fullrpt = true;
break;
}
case "--queue-messages": {
array_shift( $u_argv );
$qmesgs = true;
break;
}
case "--monitor": {
array_shift( $u_argv );
$monitor = true;
break;
}
case "--running": {
array_shift( $u_argv );
$running = true;
break;
}
case "--restart": {
array_shift( $u_argv );
$restart = true;
break;
}
case "--check-log": {
array_shift( $u_argv );
$checklog = true;
break;
}
case "--airavata-details": {
array_shift( $u_argv );
$adetails = true;
break;
}
case "--maxrss": {
array_shift( $u_argv );
$maxrss = true;
break;
}
default:
error_exit( "\nUnknown option '$u_argv[0]'\n\n$notes" );
}
}
$config_file = "db_config.php";
if ( count( $u_argv ) ) {
$use_config_file = array_shift( $u_argv );
} else {
$use_config_file = $config_file;
}
if ( !$anyargs || count( $u_argv ) ) {
echo $notes;
exit;
}
if ( !file_exists( $use_config_file ) ) {
fwrite( STDERR, "$self:
$use_config_file does not exist
to fix:
cp ${config_file}.template $use_config_file
and edit with appropriate values
")
;
exit(-1);
}
file_perms_must_be( $use_config_file );
require $use_config_file;
if ( !$db && !$running && !$restart ) {
error_exit( "ERROR: no database specified" );
}
if ( $reqid && $gfacid ) {
error_exit( "ERROR: only one id option can be specified" );
}
if ( $monitor && !$gfacid ) {
error_exit( "ERROR: --monitor requires --gfacid" );
}
if ( $checklog && !$gfacid ) {
error_exit( "ERROR: --checklog requires --gfacid" );
}
if ( $checklog && $monitor ) {
error_exit( "ERROR: --checklog and --monitor can not both be specified" );
}
if (
( $getrundir && $getrun )
|| ( $getrundir && $copyrun )
|| ( $getrun && $copyrun )
) {
error_exit( "ERROR: --getrundir --getrun --copyrun are mutually exclusive" );
}
if ( $getrundir && !$reqid ) {
error_exit( "ERROR: --getrundir requires --reqid" );
}
if ( $getrun && !$reqid ) {
error_exit( "ERROR: --getrun requires --reqid" );
}
if ( $copyrun && !$reqid ) {
error_exit( "ERROR: --copyrun requires --reqid" );
}
if ( $runinfo && !$getrun ) {
error_exit( "ERROR: --runinfo requires --getrun" );
}
if ( $gatimes && !$getrun ) {
error_exit( "ERROR: --ga-times requires --getrun" );
}
if ( $adetails && ( !$gfacid || !$db ) ) {
error_exit( "ERROR: --airavata-details requires --gfacid and --db" );
}
function jm_only_report( $jm_active ) {
$out = "";
if ( count( $jm_active ) ) {
foreach ( $jm_active as $k => $v ) {
$jm_key_parts = explode( ":", $k );
$us3_db = $jm_key_parts[0];
$gfacid = $jm_key_parts[1];
$out .=
sprintf(
"%-20s | %-20s | %-45s | %-12s | %s\n"
, "*no gfac.analysis*"
, $us3_db
, $gfacid
, "*unknown*"
, $v
)
;
}
}
return $out;
}
if ( $adetails ) {
if ( !is_aira_job( $gfacid ) ) {
error_exit( "$gfacid does not appear to be a valid id for an Airavata managed job" );
}
$jobDetails = getJobDetails( $gfacid );
if ( $jobDetails ) {
if ( $jobDetails === ' No Job Details ' ) {
$jdstdout = $jobDetails;
$jdstderr = $jobDetails;
} else {
$jdstdout = isset( $jobDetails->stdOut ) ? trim( $jobDetails->stdOut ) : "n/a";
$jdstderr = isset( $jobDetails->stdErr ) ? trim( $jobDetails->stdErr ) : "n/a";
}
} else {
$jdstdout = "failed to get job details";
$jdstderr = "failed to get job details";
}
$aira_details =
sprintf( " Airavata stdout : %s\n", $jdstdout )
. sprintf( " Airavata stderr : %s\n", $jdstderr )
;
echo $aira_details;
exit;
}
if ( $running || $restart ) {
$jms = explode( "\n", trim( run_cmd( 'ps -efww | grep jobmonitor.php | grep -v grep | awk \'{ print $2 " " $10 " " $11 }\'' ) ) );
$jm_active = [];
foreach ( $jms as $v ) {
$jm_row = explode( " ", $v );
if ( count( $jm_row ) == 3 ) {
$jm_active[ $jm_row[1] . ":" . $jm_row[2] ] = $jm_row[0];
}
}
open_db();
$res = db_obj_result( $db_handle, "select * from gfac.analysis order by cluster,us3_db,gfacid", true, true );
$breakline = echoline( '-', 20 + 3 + 45 + 3 + 20 + 3 + 12 + 3 + 6 + 3 + 20, false );
$out =
$breakline
. sprintf(
"%-20s | %-20s | %-6s | %-45s | %-12s | %s\n"
, 'cluster'
, 'db'
, 'reqid'
, 'gfacid'
, 'status'
, 'job monitor pid'
)
. $breakline
;
if ( !$res ) {
if ( count( $jm_active ) ) {
$out .=
jm_only_report( $jm_active )
. $breakline
;
echo $out;
} else {
echo "no currently active jobs\n";
}
exit;
}
$jm_restart_db = [];
$jm_restart_gfacid = [];
$jm_restart_hpcreqid = [];
while( $row = mysqli_fetch_array($res) ) {
$db = $row[ 'us3_db' ];
$gfacid = $row[ 'gfacID' ];
$jm_key = "$db:$gfacid";
$reshpc =
db_obj_result(
$db_handle
,"select HPCAnalysisRequestID from $db.HPCAnalysisResult where gfacID=\"$gfacid\" limit 1"
, false
, false
);
if ( $reshpc ) {
$reqid = $reshpc->{ "HPCAnalysisRequestID" };
} else {
$reqid = "unknown";
}
if ( array_key_exists( $jm_key, $jm_active ) ) {
$jm_pid = $jm_active[ $jm_key ];
unset( $jm_active[ $jm_key ] );
} else {
$jm_pid = "not running";
$jm_restart_db [] = $db;
$jm_restart_gfacid [] = $gfacid;
$jm_restart_hpcreqid[] = $reqid;
}
$out .=
sprintf(
"%-20s | %-20s | %-6s | %-45s | %-12s | %s\n"
, $row[ 'cluster' ]
, $db
, $reqid
, $gfacid
, $row[ 'status' ]
, $jm_pid
)
;
}
$out .=
jm_only_report( $jm_active )
. $breakline
;
if ( $running ) {
echo $out;
}
if ( !$restart ) {
exit;
}
if ( !count( $jm_restart_db ) ) {
echo "no gfac.analysis found that need restarting\n";
exit;
}
foreach ( $jm_restart_db as $index => $db ) {
$gfacid = $jm_restart_gfacid [ $index ];
$hpcreqid = $jm_restart_hpcreqid[ $index ];
$cmd = "php $us3bin/jobmonitor/jobmonitor.php $db $gfacid $hpcreqid";
echo "restarting: $cmd\n";
run_cmd( $cmd );
}
exit;
}
$existing_dbs = existing_dbs();
if ( !in_array( $db, $existing_dbs ) ) {
error_exit( "ERROR: database '$db' does not exist" );
}
if ( $maxrss ) {
open_db();
$query =
"
SELECT (HPCAnalysisResult.max_rss/1024) AS 'maxrss', HPCAnalysisRequest.analType
FROM ${db}.HPCAnalysisResult
JOIN ${db}.HPCAnalysisRequest ON HPCAnalysisResult.HPCAnalysisRequestID=HPCAnalysisRequest.HPCAnalysisRequestID
WHERE HPCAnalysisResult.max_rss > 0
ORDER BY HPCAnalysisRequest.analType, HPCAnalysisResult.max_rss
";
$fmt = "%12s | %s\n";
$fmtlen = 30;
echoline( "-", $fmtlen );
echo sprintf(
$fmt
,"MaxRSS MB"
,"Analysis Type"
);
echoline( "-", $fmtlen );
$res = db_obj_result( $db_handle, $query, true, true );
while( $row = mysqli_fetch_array($res) ) {
echo sprintf(
$fmt
,sprintf( "%.2f", $row['maxrss'] )
,$row['analType']
);
}
echoline( "-", $fmtlen );
exit;
}
if ( !$reqid && !$gfacid ) {
# summary info for db
$res = db_obj_result( $db_handle, "select HPCAnalysisRequestID from $db.HPCAnalysisRequest", True );
$hpcreqs = 0;
$hpcress = 0;
while( $row = mysqli_fetch_array($res) ) {
$hpcreqid = $row['HPCAnalysisRequestID'];
if ( $hpcreqs ) {
if ( $hpcreqmin > $hpcreqid ) {
$hpcreqmin = $hpcreqid;
}
if ( $hpcreqmax < $hpcreqid ) {
$hpcreqmax = $hpcreqid;
}
} else {
$hpcreqmin = $hpcreqid;
$hpcreqmax = $hpcreqid;
}
$hpcreqs++;
}
$res = db_obj_result( $db_handle, "select HPCAnalysisResultID from $db.HPCAnalysisResult", True );
while( $row = mysqli_fetch_array($res) ) {
$hpcresid = $row['HPCAnalysisResultID'];
if ( $hpcress ) {
if ( $hpcresmin > $hpcresid ) {
$hpcresmin = $hpcresid;
}
if ( $hpcresmax < $hpcresid ) {
$hpcresmax = $hpcresid;
}
} else {
$hpcresmin = $hpcresid;
$hpcresmax = $hpcresid;
}
$hpcress++;
}
if ( $hpcreqs ) {
echo "HPCAnalysisRequest count $hpcreqs id range $hpcreqmin:$hpcreqmax\n";
} else {
echo "HPCAnalysisRequest count $hpcreqs\n";
}
if ( $hpcreqs ) {
echo "HPCAnalysisResult count $hpcress id range $hpcresmin:$hpcresmax\n";
} else {
echo "HPCAnalysisResult count $hpcress\n";
}
exit(0);
}
function gfacqmout( $id ) {
global $fullrpt;
global $db;
global $db_handle;
$res = db_obj_result( $db_handle, "select * from gfac.queue_messages where analysisID=\"$id\" order by messageID", true, true );
$out =
echoline( '-', 80, false )
;
if ( !$res ) {
return $out . "gfac.queue_messages [currently none]\n";
}
$out .=
"gfac.queue_messages\n"
;
$out .= echoline( '-', 80, false );
$fmt = "%-9s | %-19s | %s\n";
$out .= sprintf( $fmt
,"messageID"
,"time"
,"message" );
$out .= echoline( '-', 80, false );
while( $row = mysqli_fetch_array($res) ) {
$out .=
sprintf(
$fmt
, $row[ 'messageID' ]
, $row[ 'time' ]
, $row[ 'message' ]
)
;
}
return $out;
}
function gfacanalysisout( $gfacid ) {
global $fullrpt;
global $qmesgs;
global $db;
global $db_handle;
$res = db_obj_result( $db_handle, "select * from gfac.analysis where gfacID=\"$gfacid\"", true, true );
$out =
echoline( '-', 80, false )
;
if ( !$res ) {
return $out . "gfac.analysis [currently none]\n";
}
$out .=
"gfac.analysis\n"
;
while( $row = mysqli_fetch_array($res) ) {
if ( !$fullrpt ) {
$tmp = explode( "\n", trim( $row[ 'stdout' ] ) ); $row[ 'stdout' ] = end( $tmp );
$tmp = explode( "\n", trim( $row[ 'stderr' ] ) ); $row[ 'stderr' ] = end( $tmp );
# $tmp = explode( "\n", trim( $row[ 'tarfile' ] ) ); $row[ 'tarfile' ] = end( $tmp );
}
$out .=
echoline( '-', 80, false )
. sprintf(
"id %s\n"
. "gfacID %s\n"
. "cluster %s\n"
. "us3_db %s\n"
. "autoflowAnalysisID %s\n"
. "stdout %s\n"
. "stderr %s\n"
# . "tarfile %s\n"
. "status %s\n"
. "queue_msg %s\n"
. "time %s\n"
, $row[ 'id' ]
, $row[ 'gfacID' ]
, $row[ 'cluster' ]
, $row[ 'us3_db' ]
, $row[ 'autoflowAnalysisID' ]
, $row[ 'stdout' ]
, $row[ 'stderr' ]
# , $row[ 'tarfile' ]
, $row[ 'status' ]
, $row[ 'queue_msg' ]
, $row[ 'time' ]
)
;
if ( $qmesgs ) {
$out .= gfacqmout( $row[ 'id' ] );
}
}
return $out;
}
function hpcreqout( $reqid ) {
global $fullrpt;
global $db;
global $db_handle;
$res = db_obj_result( $db_handle, "select * from $db.HPCAnalysisRequest where HPCAnalysisRequestID=\"$reqid\"" );
if ( !$fullrpt ) {
$tmp = explode( "\n", trim( $res->{ 'requestXMLFile' } ) ); $res->{ 'requestXMLFile' } = end( $tmp );
}
return
echoline( '-', 80, false )
. "HPCAnalysisRequest\n"
. echoline( '-', 80, false )
. sprintf(
"HPCAnalysisRequestID %s\n"
. "HPCAnalysisRequestGUID %s\n"
. "investigatorGUID %s\n"
. "submitterGUID %s\n"
. "email %s\n"
. "experimentID %s\n"
. "requestXMLFile %s\n"
. "editXMLFilename %s\n"
. "submitTime %s\n"
. "clusterName %s\n"
. "method %s\n"
. "analType %s\n"
, $res->{ 'HPCAnalysisRequestID' }
, $res->{ 'HPCAnalysisRequestGUID' }
, $res->{ 'investigatorGUID' }
, $res->{ 'submitterGUID' }
, $res->{ 'email' }
, $res->{ 'experimentID' }
, $res->{ 'requestXMLFile' }
, $res->{ 'editXMLFilename' }
, $res->{ 'submitTime' }
, $res->{ 'clusterName' }
, $res->{ 'method' }
, $res->{ 'analType' }
)
;
}
function hpcresbyreqout( $reqid, $reqisgfac = false ) {
global $fullrpt;
global $db;
global $db_handle;
$out =
echoline( '-', 80, false )
. "HPCAnalysisResult(s)\n"
;
if ( $reqisgfac ) {
$res = db_obj_result( $db_handle, "select * from $db.HPCAnalysisResult where gfacID=\"$reqid\"", True );
} else {
$res = db_obj_result( $db_handle, "select * from $db.HPCAnalysisResult where HPCAnalysisRequestID=\"$reqid\"", True );
}
while( $row = mysqli_fetch_array($res) ) {
if ( !$fullrpt ) {
$tmp = explode( "\n", trim( $row[ 'jobfile' ] ) ); $row[ 'jobfile' ] = end( $tmp );
$tmp = explode( "\n", trim( $row[ 'stderr' ] ) ); $row[ 'stderr' ] = end( $tmp );
$tmp = explode( "\n", trim( $row[ 'stdout' ] ) ); $row[ 'stdout' ] = end( $tmp );
}
# debug_json( "row", $row );
$out .=
echoline( '-', 80, false )
. sprintf(
"HPCAnalysisResultID %s\n"
. "HPCAnalysisRequestID %s\n"
. "startTime %s\n"
. "endTime %s\n"
. "queueStatus %s\n"
. "lastMessage %s\n"
. "updateTime %s\n"
. "gfacID %s\n"
. "jobfile %s\n"
. "wallTime %s\n"
. "CPUTime %s\n"
. "CPUCount %s\n"
. "mgroupcount %s\n"
. "max_rss %s\n"
. "calculatedData %s\n"
. "stderr %s\n"
. "stdout %s\n"
, $row[ 'HPCAnalysisResultID' ]
, $row[ 'HPCAnalysisRequestID' ]
, $row[ 'startTime' ]
, $row[ 'endTime' ]
, $row[ 'queueStatus' ]
, $row[ 'lastMessage' ]
, $row[ 'updateTime' ]
, $row[ 'gfacID' ]
, $row[ 'jobfile' ]
, $row[ 'wallTime' ]
, $row[ 'CPUTime' ]
, $row[ 'CPUCount' ]
, $row[ 'mgroupcount' ]
, $row[ 'max_rss' ]
, $row[ 'calculatedData' ]
, $row[ 'stderr' ]
, $row[ 'stdout' ]
)
;
if ( !$reqisgfac ) {
$out .= gfacanalysisout( $row[ 'gfacID' ] );
} else {
$out .= hpcreqout( $row[ 'HPCAnalysisRequestID' ] );
}
}
return $out;
}
if ( $reqid && $onlygfac ) {
$res = db_obj_result( $db_handle, "select * from $db.HPCAnalysisResult where HPCAnalysisRequestID=\"$reqid\"", True );
while( $row = mysqli_fetch_array($res) ) {
echo $row[ 'gfacID' ] . "\n";
}
exit;
}
if ( $reqid && !$getrundir && !$getrun && !$copyrun) {
$out = "";
$out .= hpcreqout( $reqid );
$out .= hpcresbyreqout( $reqid );
echo $out;
exit(0);
}
function is_aira_job( $gfacID ) {
return preg_match( "/US3-A/i", $gfacID ) ? true : false;
}
if ( $gfacid ) {
$out = "";
$out .= gfacanalysisout( $gfacid );
if ( is_aira_job( $gfacid ) ) {
$out .= echoline( '-', 80, false );
$jobDetails = getJobDetails( $gfacid );
if ( $jobDetails ) {
if ( $jobDetails === ' No Job Details ' ) {
$jdstdout = $jobDetails;
$jdstderr = $jobDetails;
} else {
$jdstdout = isset( $jobDetails->stdOut ) ? trim( $jobDetails->stdOut ) : "n/a";
$jdstderr = isset( $jobDetails->stdErr ) ? trim( $jobDetails->stdErr ) : "n/a";
}
} else {
$jdstdout = "failed to get job details";
$jdstderr = "failed to get job details";
}
$out .=
sprintf( "Airavata job stdout %s\n", $jdstdout )
. sprintf( "Airavata job stderr %s\n", $jdstderr )
;
}
$out .= hpcresbyreqout( $gfacid, true );
echo $out;
$lock_dir = "$ll_base_dir/$db/$gfacid";
$logfile = "$lock_dir/log.txt";
echoline();
echo "logfile $logfile\n";
if ( $checklog ) {
check_log( $logfile );
exit(0);
}
if ( $monitor ) {
if ( !file_exists( $logfile ) ) {
error_exit( "can not monitor, $logfile does not exist\n" );
}
$lockfile = "$ll_base_dir/$db/$gfacid/jobmonitor.php.lock";
if ( !file_exists( $lockfile ) ) {
echoline();
echo "jobmonitor.php is not running for this job\n";
echo "logfile contents:\n";
echoline();
echo `cat $logfile`;
echoline();
exit(0);
}
echo "output of tail -f $logfile\n";
echo "*** use control-C to quit ***\n";
echoline();
passthru( "tail -f $logfile" );
}
exit(0);
}
## check log functions
function log_str_date( $l ) {
$date = substr( $l, 0, 19 );
return $date;
}
function log_date( $l ) {
return date_create_from_format('Y-m-d H:i:s', log_str_date( $l ) );
}
function check_log( $fname ) {
$find = [ "terminated", "error", "exit" ];
$findmsg = "\t" . implode( "\n\t", $find ) . "\n";
$max_duration = 1;
$notes = "checks logs for lines matching:\n$findmsg\nand time gaps greater than $max_duration\n";
if ( !file_exists( $fname ) ) {
error_exit( "file $fname does not exist" );
}
$ls = explode( "\n", file_get_contents( $fname ) );
$lc = count( $ls );
echo "log file opened with $lc lines\n";
$out = [];
# check for keywords
foreach ( $find as $v ) {
$found = preg_grep( "/$v/i", $ls );
if ( count( $found ) ) {
foreach ( $found as $vf ) {
$out[] = $vf;
}
}
}
# check for time gaps
$start = true;
foreach ( $ls as $l ) {
if ( $start ) {
$start = false;
$sdate = log_date( $l );
$sline = $l;
continue;
}
if ( ! ( $edate = log_date( $l ) ) ) {
$edate = $sdate;
}
if ( dt_duration_minutes( $sdate, $edate ) > $max_duration ) {
$out[] = $sline;
$out[] = sprintf( "%s->%s : time gap of %d minutes", log_str_date( $sline), log_str_date( $l ), dt_duration_minutes( $sdate, $edate ) );
$out[] = $l;
}
$sdate = $edate;
$sline = $l;
}
sort( $out );
echo implode( "\n", $out ) . "\n";
}
if ( $getrundir || $getrun || $copyrun ) {
## get run dir
## possibly a better way via airavata call
## get full info
global $db;
global $db_handle;
$res = db_obj_result( $db_handle, "select * from $db.HPCAnalysisRequest where HPCAnalysisRequestID=\"$reqid\"" );
$cluster = $res->{ 'clusterName' };
$method = $res->{ 'method' };
$analType = $res->{ 'analType' };
# echo "cluster $cluster\n";
## we don't have the queue name :( look it up
$queue = false;
$login = false;
$workdir = false;
foreach ( $cluster_details as $k => $v ) {
if (
$v['name'] == $cluster &&
isset( $v['login'] ) &&
isset( $v['workdir'] )
) {
$queue = $k;
$login = $v['login'];
$workdir = $v['workdir'];
break;
}
}
if ( !$queue ) {
error_exit( "could not find any queue with login defined in $global_config_file for cluster $cluster" );
}
if ( !isset( $cluster_details[$queue]['airavata'] ) ||
!$cluster_details[$queue]['airavata'] ) {
error_exit( "cluster $queue not marked as airavata in $global_config_file" );
}
# echo "queue $queue\n";
# echo "login $login\n";
# echo "workdir $workdir\n";
$padreqid = str_pad( $reqid, 5, '0', STR_PAD_LEFT );
$inputfile = "hpcinput-localhost-$db-$padreqid.tar";
$cmd = "runuser -l us3 -c \"ssh $login ls $workdir/PROCESS_*/$inputfile\" | grep PROCESS";
$res = run_cmd( $cmd, false, true );
# echo "cmd $cmd\n";
if ( count( $res ) != 1 ) {
error_exit( "error attempting to retrieve rundir, multiple results:\n" . implode( "\n", $res ) );
}
$rundir = preg_replace( '/\/hpcinput.*tar/', '', $res[0] );
echoline();
echo "$login:$rundir\n";
if ( $getrundir ) {
exit(0);
}
## mkdir
$tdir = "$getrunbdir/$db/$reqid";
if ( !is_dir( $tdir ) ) {
mkdir( $tdir, 0777, true );
if ( !is_dir( $tdir ) ) {
error_exit( "Could not make directory $tdir" );
}
}
## make sure directory is owned by us3
$cmd = "chown -R us3:us3 $getrunbdir";
run_cmd( $cmd );
## get info
$reqxmlf = "hpcrequest-localhost-$db-$padreqid.xml";
$getfiles = [
"job_*.slurm"
,$inputfile
,"Ultrascan.stdout"
,"Ultrascan.stderr"
,$reqxmlf
,"output/analysis-results.tar"
];
$cmd = "runuser -l us3 -c \"rsync -avz $login:$rundir/{" . implode(",",$getfiles) . "} " . $tdir . "\"";
echoline();