source: trunk/cleanup_gfac.php@ 36

Last change on this file since 36 was 35, checked in by gegorbet, 7 years ago

mods mostly for use of mysqli

  • Property svn:keywords set to LastChangedDate Author
File size: 22.4 KB
RevLine 
[7]1<?php
2/*
3 * cleanup_gfac.php
4 *
5 * functions relating to copying results and cleaning up the gfac DB
6 *
7 */
8
[18]9$us3bin = exec( "ls -d ~us3/lims/bin" );
[7]10include_once "$us3bin/listen-config.php";
11$me = 'cleanup_gfac.php';
12$email_address = '';
13$queuestatus = '';
14$jobtype = '';
15$db = '';
16$editXMLFilename = '';
17$status = '';
18
19function gfac_cleanup( $us3_db, $reqID, $gfac_link )
20{
21 global $dbhost;
22 global $user;
23 global $passwd;
24 global $db;
25 global $guser;
26 global $gpasswd;
27 global $gDB;
28 global $me;
29 global $work;
30 global $email_address;
31 global $queuestatus;
32 global $jobtype;
33 global $editXMLFilename;
34 global $submittime;
35 global $status;
36 global $stdout;
37 global $requestID;
38
39 $requestID = $reqID;
40 $db = $us3_db;
41 write_log( "$me: debug db=$db; requestID=$requestID" );
42
[35]43 $us3_link = mysqli_connect( $dbhost, $user, $passwd, $db );
[7]44
45 if ( ! $us3_link )
46 {
[35]47 write_log( "$me: could not connect: $dbhost, $user, $passwd, $db" );
48 mail_to_user( "fail", "Internal Error $requestID\nCould not connect to DB $db" );
[7]49 return( -1 );
50 }
51
52 // First get basic info for email messages
53 $query = "SELECT email, investigatorGUID, editXMLFilename FROM HPCAnalysisRequest " .
54 "WHERE HPCAnalysisRequestID=$requestID";
[35]55 $result = mysqli_query( $us3_link, $query );
[7]56
57 if ( ! $result )
58 {
59 write_log( "$me: Bad query: $query" );
[35]60 mail_to_user( "fail", "Internal Error $requestID\n$query\n" . mysqli_error( $us3_link ) );
[7]61 return( -1 );
62 }
63
[35]64 list( $email_address, $investigatorGUID, $editXMLFilename ) = mysqli_fetch_array( $result );
[7]65
66 $query = "SELECT personID FROM people " .
67 "WHERE personGUID='$investigatorGUID'";
[35]68 $result = mysqli_query( $us3_link, $query );
[7]69
[35]70 list( $personID ) = mysqli_fetch_array( $result );
[7]71
72 /*
73 $query = "SELECT clusterName, submitTime, queueStatus, method " .
74 "FROM HPCAnalysisRequest h LEFT JOIN HPCAnalysisResult " .
75 "ON h.HPCAnalysisRequestID=HPCAnalysisResult.HPCAnalysisRequestID " .
76 "WHERE h.HPCAnalysisRequestID=$requestID";
77 */
78 $query = "SELECT clusterName, submitTime, queueStatus, method " .
79 "FROM HPCAnalysisRequest h, HPCAnalysisResult r " .
80 "WHERE h.HPCAnalysisRequestID=$requestID " .
81 "AND h.HPCAnalysisRequestID=r.HPCAnalysisRequestID";
82
[35]83 $result = mysqli_query( $us3_link, $query );
[7]84
85 if ( ! $result )
86 {
[35]87 write_log( "$me: Bad query:\n$query\n" . mysqli_error( $us3_link ) );
[7]88 return( -1 );
89 }
90
[35]91 if ( mysqli_num_rows( $result ) == 0 )
[7]92 {
93 write_log( "$me: US3 Table error - No records for requestID: $requestID" );
94 return( -1 );
95 }
96
[35]97 list( $cluster, $submittime, $queuestatus, $jobtype ) = mysqli_fetch_array( $result );
[7]98
99 // Get the GFAC ID
100 $query = "SELECT HPCAnalysisResultID, gfacID FROM HPCAnalysisResult " .
101 "WHERE HPCAnalysisRequestID=$requestID";
102
[35]103 $result = mysqli_query( $us3_link, $query );
[7]104
105 if ( ! $result )
106 {
107 write_log( "$me: Bad query: $query" );
[35]108 mail_to_user( "fail", "Internal Error $requestID\n$query\n" . mysqli_error( $us3_link ) );
[7]109 return( -1 );
110 }
111
[35]112 list( $HPCAnalysisResultID, $gfacID ) = mysqli_fetch_array( $result );
[7]113
114 ////////
115 // Get data from global GFAC DB and insert it into US3 DB
[35]116 $gfac_link = mysqli_connect( $dbhost, $guser, $gpasswd, $gDB );
[7]117
[35]118 if ( ! $gfac_link )
[7]119 {
[35]120 write_log( "$me: Could not connect to DB $dbhost : $gDB" );
[7]121 mail_to_user( "fail", "Internal Error $requestID\nCould not connect to DB $gDB" );
122 return( -1 );
123 }
124
125 $query = "SELECT status, cluster, id FROM analysis " .
126 "WHERE gfacID='$gfacID'";
127
[35]128 $result = mysqli_query( $gfac_link, $query );
[7]129 if ( ! $result )
130 {
131 write_log( "$me: Could not select GFAC status for $gfacID" );
132 mail_to_user( "fail", "Could not select GFAC status for $gfacID" );
133 return( -1 );
134 }
135
[35]136 $num_rows = mysqli_num_rows( $result );
[7]137 if ( $num_rows == 0 )
138 {
139 write_log( "$me: Cleanup analysis query found 0 entries for $gfacID" );
140 return( 0 );
141 }
142//else
143//{
144//write_log( "$me: db=$db; num_rows=$num_rows; queuestatus=$queuestatus" );
145//}
146
[35]147 list( $status, $cluster, $id ) = mysqli_fetch_array( $result );
[7]148//write_log( "$me: db=$db; requestID=$requestID; status=$status; cluster=$cluster" );
149
[25]150// if ( $cluster == 'bcf-local' || $cluster == 'alamo-local' )
151 if ( preg_match( "/\-local/", $cluster ) ||
152 preg_match( "/us3iab/", $cluster ) )
[7]153 {
[25]154// $clushost = $cluster;
155// $clushost = preg_replace( "/\-local/", "", $clushost );
156 $parts = explode( "-", $cluster );
157 $clushost = $parts[ 0 ];
[7]158 get_local_files( $gfac_link, $clushost, $requestID, $id, $gfacID );
[25]159write_log( "$me: clushost=$clushost reqID=$requestID get_local_files() gfacID=$gfacID" );
[7]160 }
[25]161else
162write_log( "$me: NO get_local_files()" );
[7]163
164 $query = "SELECT id, stderr, stdout, tarfile FROM analysis " .
165 "WHERE gfacID='$gfacID'";
166
[35]167 $result = mysqli_query( $gfac_link, $query );
[7]168
169 if ( ! $result )
170 {
[35]171 write_log( "$me: Bad query:\n$query\n" . mysqli_error( $gfac_link ) );
172 mail_to_user( "fail", "Internal error " . mysqli_error( $gfac_link ) );
[7]173 return( -1 );
174 }
175
[35]176 $num_rows = mysqli_num_rows( $result );
[7]177 if ( $num_rows == 0 )
178 {
179 write_log( "$me: Cleanup analysis query found 0 entries for $gfacID" );
180 return( 0 );
181 }
182
[35]183 list( $analysisID, $stderr, $stdout, $tarfile ) = mysqli_fetch_array( $result );
[7]184
185 if ( strlen( $tarfile ) > 0 )
186 { // Log success at fetch attempt
187 write_log( "$me: Successful data fetch: $requestID $gfacID" );
188 }
189 else
190 { // Log failure at fetch attempt
191 write_log( "$me: Failed data fetch: $requestID $gfacID" );
192 if ( $analysisID == '' )
193 $analysisID = '0';
194 }
195
196 // Save queue messages for post-mortem analysis
197 $query = "SELECT message, time FROM queue_messages " .
198 "WHERE analysisID = $analysisID " .
199 "ORDER BY time ";
[35]200 $result = mysqli_query( $gfac_link, $query );
[7]201
202 if ( ! $result )
203 {
204 // Just log it and continue
[35]205 write_log( "$me: Bad query:\n$query\n" . mysqli_error( $gfac_link ) );
[7]206 }
207
208 $now = date( 'Y-m-d H:i:s' );
209 $message_log = "US3 DB: $db\n" .
210 "RequestID: $requestID\n" .
211 "GFAC ID: $gfacID\n" .
212 "Processed: $now\n\n" .
213 "Queue Messages\n\n" ;
214
215 $need_finish = ( $status == 'COMPLETE' );
216
[35]217 if ( mysqli_num_rows( $result ) > 0 )
[7]218 {
219 $time_msg = time();
[35]220 while ( list( $message, $time ) = mysqli_fetch_array( $result ) )
[7]221 {
222//write_log( "$me: message=$message" );
223 $message_log .= "$time $message\n";
224 if ( preg_match( "/^Finished/i", $message ) )
225 $need_finish = false;
226 $time_msg = strtotime( $time );
227 }
228
229 if ( $need_finish )
230 { // No 'Finished' yet: forget if too much time has passed
231 $time_now = time();
232 $tdelta = $time_now - $time_msg;
233write_log( "$me: no-Finish time: tnow=$time_now, tmsg=$time_msg, tdelt=$tdelta" );
234 if ( $tdelta > 600 )
235 $need_finish = false;
236 }
237//write_log( "$me: no-Finish time: tnow=$time_now, tmsg=$time_msg, tdelt=$tdelta" );
238 }
239 else
240 {
241 write_log( "$me: No messages for analysisID=$analysisID ." );
242 $need_finish = false;
243 }
244
245 if ( $need_finish )
246 {
247 write_log( "$me: Cleanup has not yet found 'Finished' for $gfacID" );
248 return( 0 );
249 }
250
251 $query = "DELETE FROM queue_messages " .
252 "WHERE analysisID = $analysisID ";
253
[35]254 $result = mysqli_query( $gfac_link, $query );
[7]255
256 if ( ! $result )
257 {
258 // Just log it and continue
[35]259 write_log( "$me: Bad query:\n$query\n" . mysqli_error( $gfac_link ) );
[7]260 }
261
262 // Save stdout, stderr, etc. for message log
263 $query = "SELECT stdout, stderr, status, queue_msg FROM analysis " .
264 "WHERE gfacID='$gfacID' ";
[35]265 $result = mysqli_query( $gfac_link, $query );
[7]266 try
267 {
268 // What if this is too large?
[35]269 list( $stdout, $stderr, $status, $queue_msg ) = mysqli_fetch_array( $result );
[7]270 }
271 catch ( Exception $e )
272 {
[35]273 write_log( "$me: stdout + stderr larger than 128M - $gfacID\n" . mysqli_error( $gfac_link ) );
[7]274 // Just go ahead and clean up
275 }
276
277 // But let's allow for investigation of other large stdout and/or stderr
278 if ( strlen( $stdout ) > 20480000 ||
279 strlen( $stderr ) > 20480000 )
280 write_log( "$me: stdout + stderr larger than 20M - $gfacID\n" );
281
282 $message_log .= "\n\n\nStdout Contents\n\n" .
283 $stdout .
284 "\n\n\nStderr Contents\n\n" .
285 $stderr .
286 "\n\n\nGFAC Status: $status\n" .
287 "GFAC message field: $queue_msg\n";
288
289 // Delete data from GFAC DB
290 $query = "DELETE from analysis WHERE gfacID='$gfacID'";
291
[35]292 $result = mysqli_query( $gfac_link, $query );
[7]293
294 if ( ! $result )
295 {
296 // Just log it and continue
[35]297 write_log( "$me: Bad query:\n$query\n" . mysqli_error( $gfac_link ) );
[7]298 }
299write_log( "$me: GFAC DB entry deleted" );
300
301 // Copy queue messages to LIMS submit directory (files there are deleted after 7 days)
302 global $submit_dir;
303
304 // Get the request guid (LIMS submit dir name)
305 $query = "SELECT HPCAnalysisRequestGUID FROM HPCAnalysisRequest " .
306 "WHERE HPCAnalysisRequestID = $requestID ";
[35]307 $result = mysqli_query( $us3_link, $query );
[7]308
309 if ( ! $result )
310 {
[35]311 write_log( "$me: Bad query:\n$query\n" . mysqli_error( $us3_link ) );
[7]312 }
313
[35]314 list( $requestGUID ) = mysqli_fetch_array( $result );
[7]315 $output_dir = "$submit_dir/$requestGUID";
316write_log( "$me: Output dir determined: $output_dir" );
317
318 // Try to create it if necessary, and write the file
319 // Let's use FILE_APPEND, in case this is the second time around and the
320 // GFAC job status was INSERTed, rather than UPDATEd
321 if ( ! is_dir( $output_dir ) )
322 mkdir( $output_dir, 0775, true );
323 $message_filename = "$output_dir/$db-$requestID-messages.txt";
324 file_put_contents( $message_filename, $message_log, FILE_APPEND );
[35]325 // mysqli_close( $gfac_link );
[25]326write_log( "$me: *messages.txt written" );
[7]327
328 /////////
329 // Insert data into HPCAnalysis
330
331 $query = "UPDATE HPCAnalysisResult SET " .
[35]332 "stderr='" . mysqli_real_escape_string( $us3_link, $stderr ) . "', " .
333 "stdout='" . mysqli_real_escape_string( $us3_link, $stdout ) . "' " .
[7]334 "WHERE HPCAnalysisResultID=$HPCAnalysisResultID";
335
[35]336 $result = mysqli_query( $us3_link, $query );
[7]337
338 if ( ! $result )
339 {
[35]340 write_log( "$me: Bad query:\n$query\n" . mysqli_error( $us3_link ) );
341 mail_to_user( "fail", "Bad query:\n$query\n" . mysqli_error( $us3_link ) );
[7]342 return( -1 );
343 }
344
345 // Save the tarfile and expand it
346
347 if ( strlen( $tarfile ) == 0 )
348 {
349 write_log( "$me: No tarfile" );
350 mail_to_user( "fail", "No results" );
351 return( -1 );
352 }
353
354 // Shouldn't happen
355 if ( ! is_dir( "$work" ) )
356 {
357 write_log( "$me: $work directory does not exist" );
358 mail_to_user( "fail", "$work directory does not exist" );
359 return( -1 );
360 }
361
362 if ( ! is_dir( "$work/$gfacID" ) ) mkdir( "$work/$gfacID", 0770 );
363 chdir( "$work/$gfacID" );
364
[25]365 $f = fopen( "analysis-results.tar", "w" );
[7]366 fwrite( $f, $tarfile );
367 fclose( $f );
[25]368//write_log( "$me: analysis-results.tar file written to work dir" );
[7]369
370 $tar_out = array();
[25]371 exec( "tar -xf analysis-results.tar 2>&1", $tar_out, $err );
[7]372
373 if ( $err != 0 )
374 {
375 chdir( $work );
376 exec( "rm -r $gfacID" );
377 $output = implode( "\n", $tar_out );
378
379 write_log( "$me: Bad output tarfile: $output" );
380 mail_to_user( "fail", "Bad output file" );
381 return( -1 );
382 }
383//write_log( "$me: tar files extracted" );
384
385 // Insert the model files and noise files
386 $files = file( "analysis_files.txt", FILE_IGNORE_NEW_LINES );
387 $noiseIDs = array();
388 $modelGUIDs = array();
389 $mrecsIDs = array();
390 $rmodlGUIDs = array();
391
392 foreach ( $files as $file )
393 {
394 $split = explode( ";", $file );
395
396 if ( count( $split ) > 1 )
397 {
398 list( $fn, $meniscus, $mc_iteration, $variance ) = explode( ";", $file );
399
400 list( $other, $mc_iteration ) = explode( "=", $mc_iteration );
401 list( $other, $variance ) = explode( "=", $variance );
402 list( $other, $meniscus ) = explode( "=", $meniscus );
403 }
404 else
405 $fn = $file;
406
407 if ( preg_match( "/mdl.tmp$/", $fn ) )
408 continue;
409
410 if ( filesize( $fn ) < 100 )
411 {
412 write_log( "$me:fn is invalid $fn" );
413 mail_to_user( "fail", "Internal error\n$fn is invalid" );
414 return( -1 );
415 }
416//write_log( "$me: handling file: $fn" );
417
418 if ( preg_match( "/^job_statistics\.xml$/", $fn ) ) // Job statistics file
419 {
420 $xml = file_get_contents( $fn );
421 $statistics = parse_xml( $xml, 'statistics' );
422 $otherdata = parse_xml( $xml, 'id' );
423
424 $query = "UPDATE HPCAnalysisResult SET " .
425 "wallTime = {$statistics['walltime']}, " .
426 "CPUTime = {$statistics['cputime']}, " .
427 "CPUCount = {$statistics['cpucount']}, " .
428 "max_rss = {$statistics['maxmemory']}, " .
429 "startTime = '{$otherdata['starttime']}', " .
430 "endTime = '{$otherdata['endtime']}', " .
431 "mgroupcount = {$otherdata['groupcount']} " .
432 "WHERE HPCAnalysisResultID=$HPCAnalysisResultID";
[35]433 $result = mysqli_query( $us3_link, $query );
[7]434
435 if ( ! $result )
436 {
[35]437 write_log( "$me: Bad query:\n$query\n" . mysqli_error( $us3_link ) );
[7]438 }
439
440 file_put_contents( "$output_dir/$fn", $xml ); // Copy to submit dir
441 $file_type = "job_stats";
442//write_log( "$me: job_statistics file updated in Result and written" );
443
444 }
445
446 else if ( preg_match( "/\.noise/", $fn ) > 0 ) // It's a noise file
447 {
448 $xml = file_get_contents( $fn );
449 $noise_data = parse_xml( $xml, "noise" );
450 $type = ( $noise_data[ 'type' ] == "ri" ) ? "ri_noise" : "ti_noise";
451 $desc = $noise_data[ 'description' ];
452 $modelGUID = $noise_data[ 'modelGUID' ];
453 $noiseGUID = $noise_data[ 'noiseGUID' ];
[35]454 $editGUID = '00000000-0000-0000-0000-000000000000';
455 if ( isset( $model_data[ 'editGUID' ] ) )
456 $editGUID = $model_data[ 'editGUID' ];
[7]457
458 $query = "INSERT INTO noise SET " .
459 "noiseGUID='$noiseGUID'," .
460 "modelGUID='$modelGUID'," .
[35]461 "editedDataID=" .
462 "(SELECT editedDataID FROM editedData WHERE editGUID='$editGUID')," .
[7]463 "modelID=1, " .
464 "noiseType='$type'," .
465 "description='$desc'," .
[35]466 "xml='" . mysqli_real_escape_string( $us3_link, $xml ) . "'";
[7]467
468 // Add later after all files are processed: editDataID, modelID
469
[35]470 $result = mysqli_query( $us3_link, $query );
[7]471
472 if ( ! $result )
473 {
[35]474 write_log( "$me: Bad query:\n$query\n" . mysqli_error( $us3_link ) );
475 mail_to_user( "fail", "Internal error\n$query\n" . mysqli_error( $us3_link ) );
[7]476 return( -1 );
477 }
478
[35]479 $id = mysqli_insert_id( $us3_link );
[7]480 $file_type = "noise";
481 $noiseIDs[] = $id;
482
483 // Keep track of modelGUIDs for later, when we replace them
484 $modelGUIDs[ $id ] = $modelGUID;
[35]485//write_log( "$me: noise file inserted into DB : id=$id modelGUID=$modelGUID" );
[7]486
487 }
488
489 else if ( preg_match( "/\.mrecs/", $fn ) > 0 ) // It's an mrecs file
490 {
491 $xml = file_get_contents( $fn );
492 $mrecs_data = parse_xml( $xml, "modelrecords" );
493 $desc = $mrecs_data[ 'description' ];
494 $editGUID = $mrecs_data[ 'editGUID' ];
495write_log( "$me: mrecs file editGUID=$editGUID" );
496 if ( strlen( $editGUID ) < 36 )
497 $editGUID = "12345678-0123-5678-0123-567890123456";
498 $mrecGUID = $mrecs_data[ 'mrecGUID' ];
499 $modelGUID = $mrecs_data[ 'modelGUID' ];
500
501 $query = "INSERT INTO pcsa_modelrecs SET " .
502 "editedDataID=" .
503 "(SELECT editedDataID FROM editedData WHERE editGUID='$editGUID')," .
504 "modelID=0, " .
505 "mrecsGUID='$mrecGUID'," .
506 "description='$desc'," .
[35]507 "xml='" . mysqli_real_escape_string( $us3_link, $xml ) . "'";
[7]508
509 // Add later after all files are processed: editDataID, modelID
510
[35]511 $result = mysqli_query( $us3_link, $query );
[7]512
513 if ( ! $result )
514 {
[35]515 write_log( "$me: Bad query:\n$query\n" . mysqli_error( $us3_link ) );
516 mail_to_user( "fail", "Internal error\n$query\n" . mysqli_error( $us3_link ) );
[7]517 return( -1 );
518 }
519
[35]520 $id = mysqli_insert_id( $us3_link );
[7]521 $file_type = "mrecs";
522 $mrecsIDs[] = $id;
523
524 // Keep track of modelGUIDs for later, when we replace them
525 $rmodlGUIDs[ $id ] = $modelGUID;
526//write_log( "$me: mrecs file inserted into DB : id=$id" );
527 }
528
[23]529 else if ( preg_match( "/\.model/", $fn ) > 0 ) // It's a model file
[7]530 {
531 $xml = file_get_contents( $fn );
532 $model_data = parse_xml( $xml, "model" );
533 $description = $model_data[ 'description' ];
534 $modelGUID = $model_data[ 'modelGUID' ];
535 $editGUID = $model_data[ 'editGUID' ];
536
537 if ( $mc_iteration > 1 )
538 {
539//write_log( "$me: MODELUpd: mc_iteration=$mc_iteration" );
540 $miter = sprintf( "_mcN%03d", $mc_iteration );
541//write_log( "$me: MODELUpd: miter=$miter" );
542//write_log( "$me: MODELUpd: I:description=$description" );
543 $description = preg_replace( "/_mc[0-9]+/", $miter, $description );
544write_log( "$me: MODELUpd: O:description=$description" );
545 }
546
547 $query = "INSERT INTO model SET " .
548 "modelGUID='$modelGUID'," .
549 "editedDataID=" .
550 "(SELECT editedDataID FROM editedData WHERE editGUID='$editGUID')," .
551 "description='$description'," .
552 "MCIteration='$mc_iteration'," .
553 "meniscus='$meniscus'," .
554 "variance='$variance'," .
[35]555 "xml='" . mysqli_real_escape_string( $us3_link, $xml ) . "'";
[7]556
[35]557 $result = mysqli_query( $us3_link, $query );
[7]558
559 if ( ! $result )
560 {
[35]561 write_log( "$me: Bad query:\n$query " . mysqli_error( $us3_link ) );
562 mail_to_user( "fail", "Internal error\n$query\n" . mysqli_error( $us3_link ) );
[7]563 return( -1 );
564 }
565
[35]566 $modelID = mysqli_insert_id( $us3_link );
[7]567 $id = $modelID;
568 $file_type = "model";
569
570 $query = "INSERT INTO modelPerson SET " .
571 "modelID=$modelID, personID=$personID";
[35]572 $result = mysqli_query( $us3_link, $query );
[7]573//write_log( "$me: model file inserted into DB : id=$id" );
574 }
575
576 $query = "INSERT INTO HPCAnalysisResultData SET " .
577 "HPCAnalysisResultID='$HPCAnalysisResultID', " .
578 "HPCAnalysisResultType='$file_type', " .
579 "resultID=$id";
580
[35]581 $result = mysqli_query( $us3_link, $query );
[7]582
583 if ( ! $result )
584 {
[35]585 write_log( "$me: Bad query:\n$query\n" . mysqli_error( $us3_link ) );
586 mail_to_user( "fail", "Internal error\n$query\n" . mysqli_error( $us3_link ) );
[7]587 return( -1 );
588 }
589//write_log( "$me: ResultData updated : file_type=$file_type" );
590 }
591
592 // Now fix up noise entries
593 // For noise files, there is, at most two: ti_noise and ri_noise
594 // In this case there will only be one modelID
595
596 foreach ( $noiseIDs as $noiseID )
597 {
598 $modelGUID = $modelGUIDs[ $noiseID ];
599 $query = "UPDATE noise SET " .
600 "editedDataID=" .
601 "(SELECT editedDataID FROM model WHERE modelGUID='$modelGUID')," .
602 "modelID=" .
603 "(SELECT modelID FROM model WHERE modelGUID='$modelGUID')" .
604 "WHERE noiseID=$noiseID";
605
[35]606 $result = mysqli_query( $us3_link, $query );
[7]607
608 if ( ! $result )
609 {
[35]610 write_log( "$me: Bad query:\n$query\n" . mysqli_error( $us3_link ) );
611 mail_to_user( "fail", "Bad query\n$query\n" . mysqli_error( $us3_link ) );
[7]612 return( -1 );
613 }
614//write_log( "$me: noise entry updated : noiseID=$noiseID" );
615 }
616//write_log( "$me: noise entries updated" );
617
618 // Now possibly fix up mrecs entries
619
620 foreach ( $mrecsIDs as $mrecsID )
621 {
622 $modelGUID = $rmodlGUIDs[ $mrecsID ];
623 $query = "UPDATE pcsa_modelrecs SET " .
624 "modelID=" .
625 "(SELECT modelID FROM model WHERE modelGUID='$modelGUID')" .
626 "WHERE mrecsID=$mrecsID";
627
[35]628 $result = mysqli_query( $us3_link, $query );
[7]629
630 if ( ! $result )
631 {
[35]632 write_log( "$me: Bad query:\n$query\n" . mysqli_error( $us3_link ) );
633 mail_to_user( "fail", "Bad query\n$query\n" . mysqli_error( $us3_link ) );
[7]634 return( -1 );
635 }
636//write_log( "$me: mrecs entry updated : mrecsID=$mrecsID" );
637 }
638//write_log( "$me: mrecs entries updated" );
639
640 // Copy results to LIMS submit directory (files there are deleted after 7 days)
641 global $submit_dir; // LIMS submit files dir
642
643 // Get the request guid (LIMS submit dir name)
644 $query = "SELECT HPCAnalysisRequestGUID FROM HPCAnalysisRequest " .
645 "WHERE HPCAnalysisRequestID = $requestID ";
[35]646 $result = mysqli_query( $us3_link, $query );
[7]647
648 if ( ! $result )
649 {
[35]650 write_log( "$me: Bad query:\n$query\n" . mysqli_error( $us3_link ) );
[7]651 }
652
[35]653 list( $requestGUID ) = mysqli_fetch_array( $result );
[7]654
655 chdir( "$submit_dir/$requestGUID" );
656 $f = fopen( "analysis.tar", "w" );
657 fwrite( $f, $tarfile );
658 fclose( $f );
659
660 // Clean up
661 chdir ( $work );
662 // exec( "rm -rf $gfacID" );
663
[35]664 mysqli_close( $us3_link );
[7]665
666 /////////
667 // Send email
668
669 mail_to_user( "success", "" );
670}
671?>
Note: See TracBrowser for help on using the repository browser.