-
Notifications
You must be signed in to change notification settings - Fork 2
/
cleanup_gfac.php
695 lines (577 loc) · 24.6 KB
/
cleanup_gfac.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
<?php
/*
* cleanup_gfac.php
*
* functions relating to copying results and cleaning up the gfac DB
*
*/
$us3bin = exec( "ls -d ~us3/lims/bin" );
include_once "$us3bin/listen-config.php";
$me = 'cleanup_gfac.php';
$email_address = '';
$queuestatus = '';
$jobtype = '';
$db = '';
$editXMLFilename = '';
$status = '';
function gfac_cleanup( $us3_db, $reqID, $gfac_link )
{
global $dbhost;
global $user;
global $passwd;
global $db;
global $guser;
global $gpasswd;
global $gDB;
global $me;
global $work;
global $email_address;
global $queuestatus;
global $jobtype;
global $editXMLFilename;
global $submittime;
global $endtime;
global $status;
global $stdout;
global $requestID;
$requestID = $reqID;
$db = $us3_db;
write_log( "$me: debug db=$db; requestID=$requestID" );
$us3_link = mysqli_connect( $dbhost, $user, $passwd, $db );
if ( ! $us3_link )
{
write_log( "$me: could not connect: $dbhost, $user, $passwd, $db" );
mail_to_user( "fail", "Internal Error $requestID\nCould not connect to DB $db" );
update_autoflow_status( 'FAILED', "Internal error - cleanup could not connect to DB $db" );
return( -1 );
}
// First get basic info for email messages
$query = "SELECT email, investigatorGUID, editXMLFilename FROM HPCAnalysisRequest " .
"WHERE HPCAnalysisRequestID=$requestID";
$result = mysqli_query( $us3_link, $query );
if ( ! $result )
{
write_log( "$me: Bad query: $query" );
mail_to_user( "fail", "Internal Error $requestID\n$query\n" . mysqli_error( $us3_link ) );
update_autoflow_status( 'FAILED', "Internal error - query failed: $query" . mysqli_error( $us3_link ) );
return( -1 );
}
list( $email_address, $investigatorGUID, $editXMLFilename ) = mysqli_fetch_array( $result );
$query = "SELECT personID FROM people " .
"WHERE personGUID='$investigatorGUID'";
$result = mysqli_query( $us3_link, $query );
list( $personID ) = mysqli_fetch_array( $result );
/*
$query = "SELECT clusterName, submitTime, queueStatus, method " .
"FROM HPCAnalysisRequest h LEFT JOIN HPCAnalysisResult " .
"ON h.HPCAnalysisRequestID=HPCAnalysisResult.HPCAnalysisRequestID " .
"WHERE h.HPCAnalysisRequestID=$requestID";
*/
$query = "SELECT clusterName, submitTime, queueStatus, analType " .
"FROM HPCAnalysisRequest h, HPCAnalysisResult r " .
"WHERE h.HPCAnalysisRequestID=$requestID " .
"AND h.HPCAnalysisRequestID=r.HPCAnalysisRequestID";
$result = mysqli_query( $us3_link, $query );
if ( ! $result )
{
write_log( "$me: Bad query:\n$query\n" . mysqli_error( $us3_link ) );
update_autoflow_status( 'FAILED', "Internal error - query failed: $query" . mysqli_error( $us3_link ) );
return( -1 );
}
if ( mysqli_num_rows( $result ) == 0 )
{
write_log( "$me: US3 Table error - No records for requestID: $requestID" );
update_autoflow_status( 'FAILED', "US3 Table error - No recoreds for requestID: $requestID" );
return( -1 );
}
list( $cluster, $submittime, $queuestatus, $jobtype ) = mysqli_fetch_array( $result );
// Get the GFAC ID
$query = "SELECT HPCAnalysisResultID, gfacID, endTime FROM HPCAnalysisResult " .
"WHERE HPCAnalysisRequestID=$requestID";
$result = mysqli_query( $us3_link, $query );
if ( ! $result )
{
write_log( "$me: Bad query: $query" );
mail_to_user( "fail", "Internal Error $requestID\n$query\n" . mysqli_error( $us3_link ) );
update_autoflow_status( 'FAILED', "Internal error - query failed: $query" . mysqli_error( $us3_link ) );
return( -1 );
}
list( $HPCAnalysisResultID, $gfacID, $endtime ) = mysqli_fetch_array( $result );
////////
// Get data from global GFAC DB and insert it into US3 DB
$gfac_link = mysqli_connect( $dbhost, $guser, $gpasswd, $gDB );
if ( ! $gfac_link )
{
write_log( "$me: Could not connect to DB $dbhost : $gDB" );
mail_to_user( "fail", "Internal Error $requestID\nCould not connect to DB $gDB" );
update_autoflow_status( 'FAILED', "Internal error - Could not connect to DB $gDB" );
return( -1 );
}
$query = "SELECT status, cluster, id FROM analysis " .
"WHERE gfacID='$gfacID'";
$result = mysqli_query( $gfac_link, $query );
if ( ! $result )
{
write_log( "$me: Could not select GFAC status for $gfacID" );
mail_to_user( "fail", "Could not select GFAC status for $gfacID" );
update_autoflow_status( 'FAILED', "Could not select GFAC status for $gfacID" );
return( -1 );
}
$num_rows = mysqli_num_rows( $result );
if ( $num_rows == 0 )
{
write_log( "$me: Cleanup analysis query found 0 entries for $gfacID" );
update_autoflow_status( 'FAILED', "Cleanup analysis query found 0 entries for $gfacID" );
return( 0 );
}
//else
//{
//write_log( "$me: db=$db; num_rows=$num_rows; queuestatus=$queuestatus" );
//}
list( $status, $cluster, $id ) = mysqli_fetch_array( $result );
//write_log( "$me: db=$db; requestID=$requestID; status=$status; cluster=$cluster" );
// if ( $cluster == 'bcf-local' || $cluster == 'alamo-local' )
if ( preg_match( "/\-local/", $cluster ) ||
preg_match( "/us3iab/", $cluster ) )
{
// $clushost = $cluster;
// $clushost = preg_replace( "/\-local/", "", $clushost );
$parts = explode( "-", $cluster );
$clushost = $parts[ 0 ];
get_local_files( $gfac_link, $clushost, $requestID, $id, $gfacID );
write_log( "$me: clushost=$clushost reqID=$requestID get_local_files() gfacID=$gfacID" );
}
else
write_log( "$me: NO get_local_files()" );
$query = "SELECT id, stderr, stdout, tarfile FROM analysis " .
"WHERE gfacID='$gfacID'";
$result = mysqli_query( $gfac_link, $query );
if ( ! $result )
{
write_log( "$me: Bad query:\n$query\n" . mysqli_error( $gfac_link ) );
mail_to_user( "fail", "Internal error " . mysqli_error( $gfac_link ) );
update_autoflow_status( 'FAILED', "Internal error - query failed: $query" . mysqli_error( $gfac_link ) );
return( -1 );
}
$num_rows = mysqli_num_rows( $result );
if ( $num_rows == 0 )
{
write_log( "$me: Cleanup analysis query found 0 entries for $gfacID" );
update_autoflow_status( 'FAILED', "Cleanup analysis query found 0 entries for $gfacID" );
return( 0 );
}
list( $analysisID, $stderr, $stdout, $tarfile ) = mysqli_fetch_array( $result );
if ( strlen( $tarfile ) > 0 )
{ // Log success at fetch attempt
write_log( "$me: Successful data fetch: $requestID $gfacID" );
}
else
{ // Log failure at fetch attempt
update_autoflow_status( 'FAILED', "Failed data fetch" );
write_log( "$me: Failed data fetch: $requestID $gfacID" );
if ( $analysisID == '' )
$analysisID = '0';
}
// Save queue messages for post-mortem analysis
$query = "SELECT message, time FROM queue_messages " .
"WHERE analysisID = $analysisID " .
"ORDER BY time ";
$result = mysqli_query( $gfac_link, $query );
if ( ! $result )
{
// Just log it and continue
write_log( "$me: Bad query:\n$query\n" . mysqli_error( $gfac_link ) );
}
$now = date( 'Y-m-d H:i:s' );
$message_log = "US3 DB: $db\n" .
"RequestID: $requestID\n" .
"GFAC ID: $gfacID\n" .
"Processed: $now\n\n" .
"Queue Messages\n\n" ;
$need_finish = ( $status == 'COMPLETE' );
if ( mysqli_num_rows( $result ) > 0 )
{
$time_msg = time();
while ( list( $message, $time ) = mysqli_fetch_array( $result ) )
{
//write_log( "$me: message=$message" );
$message_log .= "$time $message\n";
if ( preg_match( "/^Finished/i", $message ) )
$need_finish = false;
$time_msg = strtotime( $time );
}
if ( $need_finish )
{ // No 'Finished' yet: forget if too much time has passed
$time_now = time();
$tdelta = $time_now - $time_msg;
write_log( "$me: no-Finish time: tnow=$time_now, tmsg=$time_msg, tdelt=$tdelta" );
if ( $tdelta > 600 )
$need_finish = false;
}
//write_log( "$me: no-Finish time: tnow=$time_now, tmsg=$time_msg, tdelt=$tdelta" );
}
else
{
write_log( "$me: No messages for analysisID=$analysisID ." );
$need_finish = false;
}
if ( $need_finish )
{
write_log( "$me: Cleanup has not yet found 'Finished' for $gfacID" );
return( 0 );
}
$query = "DELETE FROM queue_messages " .
"WHERE analysisID = $analysisID ";
$result = mysqli_query( $gfac_link, $query );
if ( ! $result )
{
// Just log it and continue
write_log( "$me: Bad query:\n$query\n" . mysqli_error( $gfac_link ) );
}
// Save stdout, stderr, etc. for message log
$query = "SELECT stdout, stderr, status, queue_msg, autoflowAnalysisID FROM analysis " .
"WHERE gfacID='$gfacID' ";
$result = mysqli_query( $gfac_link, $query );
try
{
// What if this is too large?
list( $stdout, $stderr, $status, $queue_msg, $autoflowID ) = mysqli_fetch_array( $result );
}
catch ( Exception $e )
{
write_log( "$me: stdout + stderr larger than 128M - $gfacID\n" . mysqli_error( $gfac_link ) );
// Just go ahead and clean up
}
// But let's allow for investigation of other large stdout and/or stderr
if ( strlen( $stdout ) > 20480000 ||
strlen( $stderr ) > 20480000 )
write_log( "$me: stdout + stderr larger than 20M - $gfacID\n" );
$message_log .= "\n\n\nStdout Contents\n\n" .
$stdout .
"\n\n\nStderr Contents\n\n" .
$stderr .
"\n\n\nGFAC Status: $status\n" .
"GFAC message field: $queue_msg\n";
update_autoflow_status( $status, $queue_msg );
// Delete data from GFAC DB
$query = "DELETE from analysis WHERE gfacID='$gfacID'";
$result = mysqli_query( $gfac_link, $query );
if ( ! $result )
{
// Just log it and continue
write_log( "$me: Bad query:\n$query\n" . mysqli_error( $gfac_link ) );
}
write_log( "$me: GFAC DB entry deleted" );
// Copy queue messages to LIMS submit directory (files there are deleted after 7 days)
global $submit_dir;
// Get the request guid (LIMS submit dir name)
$query = "SELECT HPCAnalysisRequestGUID FROM HPCAnalysisRequest " .
"WHERE HPCAnalysisRequestID = $requestID ";
$result = mysqli_query( $us3_link, $query );
if ( ! $result )
{
write_log( "$me: Bad query:\n$query\n" . mysqli_error( $us3_link ) );
}
list( $requestGUID ) = mysqli_fetch_array( $result );
$output_dir = "$submit_dir/$requestGUID";
write_log( "$me: Output dir determined: $output_dir" );
// Try to create it if necessary, and write the file
// Let's use FILE_APPEND, in case this is the second time around and the
// GFAC job status was INSERTed, rather than UPDATEd
if ( ! is_dir( $output_dir ) )
mkdir( $output_dir, 0775, true );
$message_filename = "$output_dir/$db-$requestID-messages.txt";
file_put_contents( $message_filename, $message_log, FILE_APPEND );
// mysqli_close( $gfac_link );
write_log( "$me: *messages.txt written" );
/////////
// Insert data into HPCAnalysis
$query = "UPDATE HPCAnalysisResult SET " .
"stderr='" . mysqli_real_escape_string( $us3_link, $stderr ) . "', " .
"stdout='" . mysqli_real_escape_string( $us3_link, $stdout ) . "' " .
"WHERE HPCAnalysisResultID=$HPCAnalysisResultID";
$result = mysqli_query( $us3_link, $query );
if ( ! $result )
{
update_autoflow_status( 'FAILED', "Could not insert data into HPCAnalysis" );
write_log( "$me: Bad query:\n$query\n" . mysqli_error( $us3_link ) );
mail_to_user( "fail", "Bad query:\n$query\n" . mysqli_error( $us3_link ) );
return( -1 );
}
// Save the tarfile and expand it
if ( strlen( $tarfile ) == 0 )
{
write_log( "$me: No tarfile" );
update_autoflow_status( 'FAILED', "Empty results tarfile" );
mail_to_user( "fail", "No results" );
return( -1 );
}
// Shouldn't happen
if ( ! is_dir( "$work" ) )
{
update_autoflow_status( 'FAILED', "$work directory does not exist" );
write_log( "$me: $work directory does not exist" );
mail_to_user( "fail", "$work directory does not exist" );
return( -1 );
}
if ( ! is_dir( "$work/$gfacID" ) ) mkdir( "$work/$gfacID", 0770 );
chdir( "$work/$gfacID" );
$f = fopen( "analysis-results.tar", "w" );
fwrite( $f, $tarfile );
fclose( $f );
//write_log( "$me: analysis-results.tar file written to work dir" );
$tar_out = array();
exec( "tar -xf analysis-results.tar 2>&1", $tar_out, $err );
if ( $err != 0 )
{
chdir( $work );
exec( "rm -r $gfacID" );
$output = implode( "\n", $tar_out );
update_autoflow_status( 'FAILED', "Bad output tarfile: $output" );
write_log( "$me: Bad output tarfile: $output" );
mail_to_user( "fail", "Bad output file" );
return( -1 );
}
//write_log( "$me: tar files extracted" );
// Insert the model files and noise files
$files = file( "analysis_files.txt", FILE_IGNORE_NEW_LINES );
$noiseIDs = array();
$modelGUIDs = array();
$mrecsIDs = array();
$rmodlGUIDs = array();
foreach ( $files as $file )
{
$split = explode( ";", $file );
if ( count( $split ) > 1 )
{
list( $fn, $meniscus, $mc_iteration, $variance ) = explode( ";", $file );
list( $other, $mc_iteration ) = explode( "=", $mc_iteration );
list( $other, $variance ) = explode( "=", $variance );
list( $other, $meniscus ) = explode( "=", $meniscus );
}
else
$fn = $file;
if ( preg_match( "/mdl.tmp$/", $fn ) )
continue;
if ( filesize( $fn ) < 100 )
{
update_autoflow_status( 'FAILED', "Internal error - $fn is invalid" );
write_log( "$me:fn is invalid $fn" );
mail_to_user( "fail", "Internal error\n$fn is invalid" );
return( -1 );
}
//write_log( "$me: handling file: $fn" );
if ( preg_match( "/^job_statistics\.xml$/", $fn ) ) // Job statistics file
{
$xml = file_get_contents( $fn );
$statistics = parse_xml( $xml, 'statistics' );
$otherdata = parse_xml( $xml, 'id' );
$query = "UPDATE HPCAnalysisResult SET " .
"wallTime = {$statistics['walltime']}, " .
"CPUTime = {$statistics['cputime']}, " .
"CPUCount = {$statistics['cpucount']}, " .
"max_rss = {$statistics['maxmemory']}, " .
"startTime = '{$otherdata['starttime']}', " .
"endTime = '{$otherdata['endtime']}', " .
"mgroupcount = {$otherdata['groupcount']} " .
"WHERE HPCAnalysisResultID=$HPCAnalysisResultID";
$result = mysqli_query( $us3_link, $query );
if ( ! $result )
{
write_log( "$me: Bad query:\n$query\n" . mysqli_error( $us3_link ) );
}
file_put_contents( "$output_dir/$fn", $xml ); // Copy to submit dir
$file_type = "job_stats";
//write_log( "$me: job_statistics file updated in Result and written" );
}
else if ( preg_match( "/\.noise/", $fn ) > 0 ) // It's a noise file
{
$xml = file_get_contents( $fn );
$noise_data = parse_xml( $xml, "noise" );
$type = ( $noise_data[ 'type' ] == "ri" ) ? "ri_noise" : "ti_noise";
$desc = $noise_data[ 'description' ];
$modelGUID = $noise_data[ 'modelGUID' ];
$noiseGUID = $noise_data[ 'noiseGUID' ];
$editGUID = '00000000-0000-0000-0000-000000000000';
if ( isset( $model_data[ 'editGUID' ] ) )
$editGUID = $model_data[ 'editGUID' ];
$query = "INSERT INTO noise SET " .
"noiseGUID='$noiseGUID'," .
"modelGUID='$modelGUID'," .
"editedDataID=" .
"(SELECT editedDataID FROM editedData WHERE editGUID='$editGUID')," .
"modelID=1, " .
"noiseType='$type'," .
"description='$desc'," .
"xml='" . mysqli_real_escape_string( $us3_link, $xml ) . "'";
// Add later after all files are processed: editDataID, modelID
$result = mysqli_query( $us3_link, $query );
if ( ! $result )
{
write_log( "$me: Bad query:\n$query\n" . mysqli_error( $us3_link ) );
mail_to_user( "fail", "Internal error\n$query\n" . mysqli_error( $us3_link ) );
update_autoflow_status( 'FAILED', "Internal error - bad query $query " . mysqli_error( $us3_link ) );
return( -1 );
}
$id = mysqli_insert_id( $us3_link );
$file_type = "noise";
$noiseIDs[] = $id;
// Keep track of modelGUIDs for later, when we replace them
$modelGUIDs[ $id ] = $modelGUID;
//write_log( "$me: noise file inserted into DB : id=$id modelGUID=$modelGUID" );
}
else if ( preg_match( "/\.mrecs/", $fn ) > 0 ) // It's an mrecs file
{
$xml = file_get_contents( $fn );
$mrecs_data = parse_xml( $xml, "modelrecords" );
$desc = $mrecs_data[ 'description' ];
$editGUID = $mrecs_data[ 'editGUID' ];
write_log( "$me: mrecs file editGUID=$editGUID" );
if ( strlen( $editGUID ) < 36 )
$editGUID = "12345678-0123-5678-0123-567890123456";
$mrecGUID = $mrecs_data[ 'mrecGUID' ];
$modelGUID = $mrecs_data[ 'modelGUID' ];
$query = "INSERT INTO pcsa_modelrecs SET " .
"editedDataID=" .
"(SELECT editedDataID FROM editedData WHERE editGUID='$editGUID')," .
"modelID=0, " .
"mrecsGUID='$mrecGUID'," .
"description='$desc'," .
"xml='" . mysqli_real_escape_string( $us3_link, $xml ) . "'";
// Add later after all files are processed: editDataID, modelID
$result = mysqli_query( $us3_link, $query );
if ( ! $result )
{
write_log( "$me: Bad query:\n$query\n" . mysqli_error( $us3_link ) );
mail_to_user( "fail", "Internal error\n$query\n" . mysqli_error( $us3_link ) );
update_autoflow_status( 'FAILED', "Internal error - bad query $query " . mysqli_error( $us3_link ) );
return( -1 );
}
$id = mysqli_insert_id( $us3_link );
$file_type = "mrecs";
$mrecsIDs[] = $id;
// Keep track of modelGUIDs for later, when we replace them
$rmodlGUIDs[ $id ] = $modelGUID;
//write_log( "$me: mrecs file inserted into DB : id=$id" );
}
else if ( preg_match( "/\.model/", $fn ) > 0 ) // It's a model file
{
$xml = file_get_contents( $fn );
$model_data = parse_xml( $xml, "model" );
$description = $model_data[ 'description' ];
$modelGUID = $model_data[ 'modelGUID' ];
$editGUID = $model_data[ 'editGUID' ];
if ( $mc_iteration > 1 )
{
//write_log( "$me: MODELUpd: mc_iteration=$mc_iteration" );
$miter = sprintf( "_mcN%03d", $mc_iteration );
//write_log( "$me: MODELUpd: miter=$miter" );
//write_log( "$me: MODELUpd: I:description=$description" );
$description = preg_replace( "/_mc[0-9]+/", $miter, $description );
write_log( "$me: MODELUpd: O:description=$description" );
}
$query = "INSERT INTO model SET " .
"modelGUID='$modelGUID'," .
"editedDataID=" .
"(SELECT editedDataID FROM editedData WHERE editGUID='$editGUID')," .
"description='$description'," .
"MCIteration='$mc_iteration'," .
"meniscus='$meniscus'," .
"variance='$variance'," .
"xml='" . mysqli_real_escape_string( $us3_link, $xml ) . "'";
$result = mysqli_query( $us3_link, $query );
if ( ! $result )
{
write_log( "$me: Bad query:\n$query " . mysqli_error( $us3_link ) );
mail_to_user( "fail", "Internal error\n$query\n" . mysqli_error( $us3_link ) );
update_autoflow_status( 'FAILED', "Internal error - bad query $query " . mysqli_error( $us3_link ) );
return( -1 );
}
$modelID = mysqli_insert_id( $us3_link );
$id = $modelID;
$file_type = "model";
$query = "INSERT INTO modelPerson SET " .
"modelID=$modelID, personID=$personID";
$result = mysqli_query( $us3_link, $query );
//write_log( "$me: model file inserted into DB : id=$id" );
}
$query = "INSERT INTO HPCAnalysisResultData SET " .
"HPCAnalysisResultID='$HPCAnalysisResultID', " .
"HPCAnalysisResultType='$file_type', " .
"resultID=$id";
$result = mysqli_query( $us3_link, $query );
if ( ! $result )
{
write_log( "$me: Bad query:\n$query\n" . mysqli_error( $us3_link ) );
mail_to_user( "fail", "Internal error\n$query\n" . mysqli_error( $us3_link ) );
update_autoflow_status( 'FAILED', "Internal error - bad query $query " . mysqli_error( $us3_link ) );
return( -1 );
}
//write_log( "$me: ResultData updated : file_type=$file_type" );
}
// Now fix up noise entries
// For noise files, there is, at most two: ti_noise and ri_noise
// In this case there will only be one modelID
foreach ( $noiseIDs as $noiseID )
{
$modelGUID = $modelGUIDs[ $noiseID ];
$query = "UPDATE noise SET " .
"editedDataID=" .
"(SELECT editedDataID FROM model WHERE modelGUID='$modelGUID')," .
"modelID=" .
"(SELECT modelID FROM model WHERE modelGUID='$modelGUID')" .
"WHERE noiseID=$noiseID";
$result = mysqli_query( $us3_link, $query );
if ( ! $result )
{
write_log( "$me: Bad query:\n$query\n" . mysqli_error( $us3_link ) );
mail_to_user( "fail", "Bad query\n$query\n" . mysqli_error( $us3_link ) );
update_autoflow_status( 'FAILED', "Internal error - bad query $query " . mysqli_error( $us3_link ) );
return( -1 );
}
//write_log( "$me: noise entry updated : noiseID=$noiseID" );
}
//write_log( "$me: noise entries updated" );
// Now possibly fix up mrecs entries
foreach ( $mrecsIDs as $mrecsID )
{
$modelGUID = $rmodlGUIDs[ $mrecsID ];
$query = "UPDATE pcsa_modelrecs SET " .
"modelID=" .
"(SELECT modelID FROM model WHERE modelGUID='$modelGUID')" .
"WHERE mrecsID=$mrecsID";
$result = mysqli_query( $us3_link, $query );
if ( ! $result )
{
write_log( "$me: Bad query:\n$query\n" . mysqli_error( $us3_link ) );
mail_to_user( "fail", "Bad query\n$query\n" . mysqli_error( $us3_link ) );
update_autoflow_status( 'FAILED', "Internal error - bad query $query " . mysqli_error( $us3_link ) );
return( -1 );
}
//write_log( "$me: mrecs entry updated : mrecsID=$mrecsID" );
}
//write_log( "$me: mrecs entries updated" );
// Copy results to LIMS submit directory (files there are deleted after 7 days)
global $submit_dir; // LIMS submit files dir
// Get the request guid (LIMS submit dir name)
$query = "SELECT HPCAnalysisRequestGUID FROM HPCAnalysisRequest " .
"WHERE HPCAnalysisRequestID = $requestID ";
$result = mysqli_query( $us3_link, $query );
if ( ! $result )
{
write_log( "$me: Bad query:\n$query\n" . mysqli_error( $us3_link ) );
}
list( $requestGUID ) = mysqli_fetch_array( $result );
chdir( "$submit_dir/$requestGUID" );
$f = fopen( "analysis.tar", "w" );
fwrite( $f, $tarfile );
fclose( $f );
// Clean up
chdir ( $work );
// exec( "rm -rf $gfacID" );
mysqli_close( $us3_link );
/////////
// Send email
mail_to_user( "success", "" );
}
?>