source: trunk/cleanup.php@ 4

Last change on this file since 4 was 4, checked in by us3, 12 years ago

Fixed status calculation and added GFAC message to email

File size: 23.7 KB
Line 
1<?php
2/*
3 * cleanup.php
4 *
5 * functions relating to copying results and cleaning up the gfac DB
6 *
7 */
8
9include_once "/home/us3/bin/listen-config.php";
10$me = 'cleanup.php';
11$email_address = '';
12$queuestatus = '';
13$jobtype = '';
14$db = '';
15$editXMLFilename = '';
16$status = '';
17
18function gfac_cleanup( $us3_db, $requestID, $gfac_link )
19{
20 global $dbhost;
21 global $user;
22 global $passwd;
23 global $db;
24 global $guser;
25 global $gpasswd;
26 global $gDB;
27 global $me;
28 global $work;
29 global $email_address;
30 global $queuestatus;
31 global $jobtype;
32 global $editXMLFilename;
33 global $submittime;
34 global $status;
35
36 $db = $us3_db;
37 write_log( "$me: debug db=$db; requestID=$requestID" );
38
39 $us3_link = mysql_connect( $dbhost, $user, $passwd );
40
41 if ( ! $us3_link )
42 {
43 write_log( "$me: could not connect: $dbhost, $user, $passwd" );
44 mail_to_user( "fail", "Internal Error $requestID\nCould not connect to DB" );
45 return( -1 );
46 }
47
48 $result = mysql_select_db( $db, $us3_link );
49
50 if ( ! $result )
51 {
52 write_log( "$me: could not select DB $db" );
53 mail_to_user( "fail", "Internal Error $requestID\n$could not select DB $db" );
54 return( -1 );
55 }
56
57 // First get basic info for email messages
58 $query = "SELECT email, investigatorGUID, editXMLFilename FROM HPCAnalysisRequest " .
59 "WHERE HPCAnalysisRequestID=$requestID";
60 $result = mysql_query( $query, $us3_link );
61
62 if ( ! $result )
63 {
64 write_log( "$me: Bad query: $query" );
65 mail_to_user( "fail", "Internal Error $requestID\n$query\n" . mysql_error( $us3_link ) );
66 return( -1 );
67 }
68
69 list( $email_address, $investigatorGUID, $editXMLFilename ) = mysql_fetch_array( $result );
70
71 $query = "SELECT personID FROM people " .
72 "WHERE personGUID='$investigatorGUID'";
73 $result = mysql_query( $query, $us3_link );
74
75 list( $personID ) = mysql_fetch_array( $result );
76
77 /*
78 $query = "SELECT clusterName, submitTime, queueStatus, method " .
79 "FROM HPCAnalysisRequest h LEFT JOIN HPCAnalysisResult " .
80 "ON h.HPCAnalysisRequestID=HPCAnalysisResult.HPCAnalysisRequestID " .
81 "WHERE h.HPCAnalysisRequestID=$requestID";
82 */
83 $query = "SELECT clusterName, submitTime, queueStatus, method " .
84 "FROM HPCAnalysisRequest h, HPCAnalysisResult r " .
85 "WHERE h.HPCAnalysisRequestID=$requestID " .
86 "AND h.HPCAnalysisRequestID=r.HPCAnalysisRequestID";
87
88 $result = mysql_query( $query, $us3_link );
89
90 if ( ! $result )
91 {
92 write_log( "$me: Bad query:\n$query\n" . mysql_error( $us3_link ) );
93 return( -1 );
94 }
95
96 if ( mysql_num_rows( $result ) == 0 )
97 {
98 write_log( "$me: US3 Table error - No records for requestID: $requestID" );
99 return( -1 );
100 }
101
102 list( $cluster, $submittime, $queuestatus, $jobtype ) = mysql_fetch_array( $result );
103
104 // Get the GFAC ID
105 $query = "SELECT HPCAnalysisResultID, gfacID FROM HPCAnalysisResult " .
106 "WHERE HPCAnalysisRequestID=$requestID";
107
108 $result = mysql_query( $query, $us3_link );
109
110 if ( ! $result )
111 {
112 write_log( "$me: Bad query: $query" );
113 mail_to_user( "fail", "Internal Error $requestID\n$query\n" . mysql_error( $us3_link ) );
114 return( -1 );
115 }
116
117 list( $HPCAnalysisResultID, $gfacID ) = mysql_fetch_array( $result );
118
119 ////////
120 // Get data from global GFAC DB and insert it into US3 DB
121 // $gfac_link = mysql_connect( $dbhost, $guser, $gpasswd );
122
123 $result = mysql_select_db( $gDB, $gfac_link );
124
125 if ( ! $result )
126 {
127 write_log( "$me: Could not connect to DB $gDB" );
128 mail_to_user( "fail", "Internal Error $requestID\nCould not connect to DB $gDB" );
129 return( -1 );
130 }
131
132 $query = "SELECT status, cluster, id FROM analysis " .
133 "WHERE gfacID='$gfacID'";
134
135 $result = mysql_query( $query, $gfac_link );
136 if ( ! $result )
137 {
138 write_log( "$me: Could not select GFAC status for $gfacID" );
139 mail_to_user( "fail", "Could not select GFAC status for $gfacID" );
140 return( -1 );
141 }
142
143 list( $status, $cluster, $id ) = mysql_fetch_array( $result );
144
145 if ( $cluster == 'bcf-local' || $cluster == 'alamo-local' )
146 {
147 $clushost = $cluster;
148 $clushost = preg_replace( "/\-local/", "", $clushost );
149 get_local_files( $gfac_link, $clushost, $requestID, $id, $gfacID );
150 }
151
152 $query = "SELECT id, stderr, stdout, tarfile FROM analysis " .
153 "WHERE gfacID='$gfacID'";
154
155 $result = mysql_query( $query, $gfac_link );
156
157 if ( ! $result )
158 {
159 write_log( "$me: Bad query:\n$query\n" . mysql_error( $gfac_link ) );
160 mail_to_user( "fail", "Internal error " . mysql_error( $gfac_link ) );
161 return( -1 );
162 }
163
164 list( $analysisID, $stderr, $stdout, $tarfile ) = mysql_fetch_array( $result );
165
166 // Save queue messages for post-mortem analysis
167 $query = "SELECT message, time FROM queue_messages " .
168 "WHERE analysisID = $analysisID " .
169 "ORDER BY time ";
170 $result = mysql_query( $query, $gfac_link );
171
172 if ( ! $result )
173 {
174 // Just log it and continue
175 write_log( "$me: Bad query:\n$query\n" . mysql_error( $gfac_link ) );
176 }
177
178 $now = date( 'Y-m-d H:i:s' );
179 $message_log = "US3 DB: $db\n" .
180 "RequestID: $requestID\n" .
181 "GFAC ID: $gfacID\n" .
182 "Processed: $now\n\n" .
183 "Queue Messages\n\n" ;
184 if ( mysql_num_rows( $result ) > 0 )
185 {
186 while ( list( $message, $time ) = mysql_fetch_array( $result ) )
187 $message_log .= "$time $message\n";
188 }
189
190 $query = "DELETE FROM queue_messages " .
191 "WHERE analysisID = $analysisID ";
192
193 $result = mysql_query( $query, $gfac_link );
194
195 if ( ! $result )
196 {
197 // Just log it and continue
198 write_log( "$me: Bad query:\n$query\n" . mysql_error( $gfac_link ) );
199 }
200
201 // Save stdout, stderr, etc. for message log
202 $query = "SELECT stdout, stderr, status, queue_msg FROM analysis " .
203 "WHERE gfacID='$gfacID' ";
204 $result = mysql_query( $query, $gfac_link );
205 try
206 {
207 // What if this is too large?
208 list( $stdout, $stderr, $status, $queue_msg ) = mysql_fetch_array( $result );
209 }
210 catch ( Exception $e )
211 {
212 write_log( "$me: stdout + stderr larger than 128M - $gfacID\n" . mysql_error( $gfac_link ) );
213 // Just go ahead and clean up
214 }
215
216 // But let's allow for investigation of other large stdout and/or stderr
217 if ( strlen( $stdout ) > 20480000 ||
218 strlen( $stderr ) > 20480000 )
219 write_log( "$me: stdout + stderr larger than 20M - $gfacID\n" );
220
221 $message_log .= "\n\n\nStdout Contents\n\n" .
222 $stdout .
223 "\n\n\nStderr Contents\n\n" .
224 $stderr .
225 "\n\n\nGFAC Status: $status\n" .
226 "GFAC message field: $queue_msg\n";
227
228 // Delete data from GFAC DB
229 $query = "DELETE from analysis WHERE gfacID='$gfacID'";
230
231 $result = mysql_query( $query, $gfac_link );
232
233 if ( ! $result )
234 {
235 // Just log it and continue
236 write_log( "$me: Bad query:\n$query\n" . mysql_error( $gfac_link ) );
237 }
238
239 // Copy queue messages to LIMS submit directory (files there are deleted after 7 days)
240 global $submit_dir;
241
242 // Get the request guid (LIMS submit dir name)
243 $query = "SELECT HPCAnalysisRequestGUID FROM HPCAnalysisRequest " .
244 "WHERE HPCAnalysisRequestID = $requestID ";
245 $result = mysql_query( $query, $us3_link );
246
247 if ( ! $result )
248 {
249 write_log( "$me: Bad query:\n$query\n" . mysql_error( $us3_link ) );
250 }
251
252 list( $requestGUID ) = mysql_fetch_array( $result );
253 $output_dir = "$submit_dir/$requestGUID";
254
255 // Try to create it if necessary, and write the file
256 // Let's use FILE_APPEND, in case this is the second time around and the
257 // GFAC job status was INSERTed, rather than UPDATEd
258 if ( ! is_dir( $output_dir ) )
259 mkdir( $output_dir, 0775, true );
260 $message_filename = "$output_dir/$db-$requestID-messages.txt";
261 file_put_contents( $message_filename, $message_log, FILE_APPEND );
262 // mysql_close( $gfac_link );
263
264 /////////
265 // Insert data into HPCAnalysis
266
267 $query = "UPDATE HPCAnalysisResult SET " .
268 "stderr='" . mysql_real_escape_string( $stderr, $us3_link ) . "', " .
269 "stdout='" . mysql_real_escape_string( $stdout, $us3_link ) . "' " .
270 "WHERE HPCAnalysisResultID=$HPCAnalysisResultID";
271
272 $result = mysql_query( $query, $us3_link );
273
274 if ( ! $result )
275 {
276 write_log( "$me: Bad query:\n$query\n" . mysql_error( $us3_link ) );
277 mail_to_user( "fail", "Bad query:\n$query\n" . mysql_error( $us3_link ) );
278 return( -1 );
279 }
280
281 // Save the tarfile and expand it
282
283 if ( strlen( $tarfile ) == 0 )
284 {
285 write_log( "$me: No tarfile" );
286 mail_to_user( "fail", "No results" );
287 return( -1 );
288 }
289
290 // Shouldn't happen
291 if ( ! is_dir( "$work" ) )
292 {
293 write_log( "$me: $work directory does not exist" );
294 mail_to_user( "fail", "$work directory does not exist" );
295 return( -1 );
296 }
297
298 if ( ! is_dir( "$work/$gfacID" ) ) mkdir( "$work/$gfacID", 0770 );
299 chdir( "$work/$gfacID" );
300
301 $f = fopen( "analysis.tar", "w" );
302 fwrite( $f, $tarfile );
303 fclose( $f );
304
305 $tar_out = array();
306 exec( "tar -xf analysis.tar 2>&1", $tar_out, $err );
307
308 if ( $err != 0 )
309 {
310 chdir( $work );
311 exec( "rm -r $gfacID" );
312 $output = implode( "\n", $tar_out );
313
314 write_log( "$me: Bad output tarfile: $output" );
315 mail_to_user( "fail", "Bad output file" );
316 return( -1 );
317 }
318
319 // Insert the model files and noise files
320 $files = file( "analysis_files.txt", FILE_IGNORE_NEW_LINES );
321 $noiseIDs = array();
322 $modelGUIDs = array();
323
324 foreach ( $files as $file )
325 {
326 $split = explode( ";", $file );
327
328 if ( count( $split ) > 1 )
329 {
330 list( $fn, $meniscus, $mc_iteration, $variance ) = explode( ";", $file );
331
332 list( $other, $mc_iteration ) = explode( "=", $mc_iteration );
333 list( $other, $variance ) = explode( "=", $variance );
334 list( $other, $meniscus ) = explode( "=", $meniscus );
335 }
336 else
337 $fn = $file;
338
339 if ( filesize( $fn ) < 100 )
340 {
341 write_log( "$me:fn is invalid $fn" );
342 mail_to_user( "fail", "Internal error\n$fn is invalid" );
343 return( -1 );
344 }
345
346 if ( preg_match( "/^job_statistics\.xml$/", $fn ) ) // Job statistics file
347 {
348 $xml = file_get_contents( $fn );
349 $statistics = parse_xml( $xml, 'statistics' );
350 $otherdata = parse_xml( $xml, 'id' );
351
352 $query = "UPDATE HPCAnalysisResult SET " .
353 "wallTime = {$statistics['walltime']}, " .
354 "CPUTime = {$statistics['cputime']}, " .
355 "CPUCount = {$statistics['cpucount']}, " .
356 "max_rss = {$statistics['maxmemory']}, " .
357 "startTime = '{$otherdata['starttime']}', " .
358 "endTime = '{$otherdata['endtime']}', " .
359 "mgroupcount = {$otherdata['groupcount']} " .
360 "WHERE HPCAnalysisResultID=$HPCAnalysisResultID";
361 $result = mysql_query( $query, $us3_link );
362
363 if ( ! $result )
364 {
365 write_log( "$me: Bad query:\n$query\n" . mysql_error( $us3_link ) );
366 }
367
368 file_put_contents( "$output_dir/$fn", $xml ); // Copy to submit dir
369
370 }
371
372 else if ( preg_match( "/\.noise/", $fn ) > 0 ) // It's a noise file
373 {
374 $xml = file_get_contents( $fn );
375 $noise_data = parse_xml( $xml, "noise" );
376 $type = ( $noise_data[ 'type' ] == "ri" ) ? "ri_noise" : "ti_noise";
377 $desc = $noise_data[ 'description' ];
378 $modelGUID = $noise_data[ 'modelGUID' ];
379 $noiseGUID = $noise_data[ 'noiseGUID' ];
380
381 $query = "INSERT INTO noise SET " .
382 "noiseGUID='$noiseGUID'," .
383 "modelGUID='$modelGUID'," .
384 "editedDataID=1, " .
385 "modelID=1, " .
386 "noiseType='$type'," .
387 "description='$desc'," .
388 "xml='" . mysql_real_escape_string( $xml, $us3_link ) . "'";
389
390 // Add later after all files are processed: editDataID, modelID
391
392 $result = mysql_query( $query, $us3_link );
393
394 if ( ! $result )
395 {
396 write_log( "$me: Bad query:\n$query\n" . mysql_error( $us3_link ) );
397 mail_to_user( "fail", "Internal error\n$query\n" . mysql_error( $us3_link ) );
398 return( -1 );
399 }
400
401 $id = mysql_insert_id( $us3_link );
402 $file_type = "noise";
403 $noiseIDs[] = $id;
404
405 // Keep track of modelGUIDs for later, when we replace them
406 $modelGUIDs[ $id ] = $modelGUID;
407
408 }
409 else // It's a model file
410 {
411 $xml = file_get_contents( $fn );
412 $model_data = parse_xml( $xml, "model" );
413 $description = $model_data[ 'description' ];
414 $modelGUID = $model_data[ 'modelGUID' ];
415 $editGUID = $model_data[ 'editGUID' ];
416
417 $query = "INSERT INTO model SET " .
418 "modelGUID='$modelGUID'," .
419 "editedDataID=" .
420 "(SELECT editedDataID FROM editedData WHERE editGUID='$editGUID')," .
421 "description='$description'," .
422 "MCIteration='$mc_iteration'," .
423 "meniscus='$meniscus'," .
424 "variance='$variance'," .
425 "xml='" . mysql_real_escape_string( $xml, $us3_link ) . "'";
426
427 $result = mysql_query( $query, $us3_link );
428
429 if ( ! $result )
430 {
431 write_log( "$me: Bad query:\n$query " . mysql_error( $us3_link ) );
432 mail_to_user( "fail", "Internal error\n$query\n" . mysql_error( $us3_link ) );
433 return( -1 );
434 }
435
436 $modelID = mysql_insert_id( $us3_link );
437 $id = $modelID;
438 $file_type = "model";
439
440 $query = "INSERT INTO modelPerson SET " .
441 "modelID=$modelID, personID=$personID";
442 $result = mysql_query( $query, $us3_link );
443 }
444
445 $query = "INSERT INTO HPCAnalysisResultData SET " .
446 "HPCAnalysisResultID='$HPCAnalysisResultID', " .
447 "HPCAnalysisResultType='$file_type', " .
448 "resultID=$id";
449
450 $result = mysql_query( $query, $us3_link );
451
452 if ( ! $result )
453 {
454 write_log( "$me: Bad query:\n$query\n" . mysql_error( $us3_link ) );
455 mail_to_user( "fail", "Internal error\n$query\n" . mysql_error( $us3_link ) );
456 return( -1 );
457 }
458 }
459
460 // Now fix up noise entries
461 // For noise files, there is, at most two: ti_noise and ri_noise
462 // In this case there will only be one modelID
463
464 foreach ( $noiseIDs as $noiseID )
465 {
466 $modelGUID = $modelGUIDs[ $noiseID ];
467 $query = "UPDATE noise SET " .
468 "editedDataID=" .
469 "(SELECT editedDataID FROM editedData WHERE editGUID='$editGUID')," .
470 "modelID=" .
471 "(SELECT modelID FROM model WHERE modelGUID='$modelGUID')" .
472 "WHERE noiseID=$noiseID";
473
474 $result = mysql_query( $query, $us3_link );
475
476 if ( ! $result )
477 {
478 write_log( "$me: Bad query:\n$query\n" . mysql_error( $us3_link ) );
479 mail_to_user( "fail", "Bad query\n$query\n" . mysql_error( $us3_link ) );
480 return( -1 );
481 }
482 }
483
484 // Copy results to LIMS submit directory (files there are deleted after 7 days)
485 global $submit_dir; // LIMS submit files dir
486
487 // Get the request guid (LIMS submit dir name)
488 $query = "SELECT HPCAnalysisRequestGUID FROM HPCAnalysisRequest " .
489 "WHERE HPCAnalysisRequestID = $requestID ";
490 $result = mysql_query( $query, $us3_link );
491
492 if ( ! $result )
493 {
494 write_log( "$me: Bad query:\n$query\n" . mysql_error( $us3_link ) );
495 }
496
497 list( $requestGUID ) = mysql_fetch_array( $result );
498
499 chdir( "$submit_dir/$requestGUID" );
500 $f = fopen( "analysis.tar", "w" );
501 fwrite( $f, $tarfile );
502 fclose( $f );
503
504 // Clean up
505 chdir ( $work );
506 // exec( "rm -rf $gfacID" );
507
508 mysql_close( $us3_link );
509
510 /////////
511 // Send email
512
513 mail_to_user( "success", "" );
514}
515
516function mail_to_user( $type, $msg )
517{
518 // Note to me. Just changed subject line to include a modified $status instead
519 // of the $type variable passed. More informative than just "fail" or "success."
520 // See how it works for awhile and then consider removing $type parameter from
521 // function.
522 global $email_address;
523 global $submittime;
524 global $queuestatus;
525 global $status;
526 global $cluster;
527 global $jobtype;
528 global $org_name;
529 global $admin_email;
530 global $dbhost;
531 global $requestID;
532 global $gfacID;
533 global $editXMLFilename;
534
535global $me;
536write_log( "$me mail_to_user(): sending email to $email_address for $gfacID" );
537
538 // Get GFAC status and message
539 // function get_gfac_message() also sets global $status
540 $gfac_message = get_gfac_message( $gfacID );
541 if ( $gfac_message === false ) $gfac_message = "";
542
543 // Create a status to put in the subject line
544 switch ( $status )
545 {
546 case "COMPLETE":
547 $subj_status = 'completed';
548 break;
549
550 case "CANCELLED":
551 case "CANCELED":
552 $subj_status = 'canceled';
553 break;
554
555 case "FAILED":
556 $subj_status = 'failed';
557 break;
558
559 case "ERROR":
560 $subj_status = 'unknown error';
561 break;
562
563 default:
564 $subj_status = $status; // For now
565 break;
566
567 }
568
569 // Parse the editXMLFilename
570 list( $runID, $editID, $dataType, $cell, $channel, $wl, $ext ) =
571 explode( ".", $editXMLFilename );
572
573 $headers = "From: $org_name Admin<$admin_email>" . "\n";
574 $headers .= "Cc: $org_name Admin<$admin_email>" . "\n";
575
576 // Set the reply address
577 $headers .= "Reply-To: $org_name<$admin_email>" . "\n";
578 $headers .= "Return-Path: $org_name<$admin_email>" . "\n";
579
580 // Try to avoid spam filters
581 $now = time();
582 $headers .= "Message-ID: <" . $now . "cleanup@$dbhost>\n";
583 $headers .= "X-Mailer: PHP v" . phpversion() . "\n";
584 $headers .= "MIME-Version: 1.0" . "\n";
585 $headers .= "Content-Transfer-Encoding: 8bit" . "\n";
586
587 $subject = "UltraScan Job Notification - $subj_status - " . substr( $gfacID, 0, 16 );
588 $message = "
589 Your UltraScan job is complete:
590
591 Submission Time : $submittime
592 Analysis ID : $gfacID
593 RunID : $runID
594 EditID : $editID
595 Data Type : $dataType
596 Cell/Channel/Wl : $cell / $channel / $wl
597 Status : $queuestatus
598 Cluster : $cluster
599 Job Type : $jobtype
600 GFAC Status : $status
601 GFAC Message : $gfac_message
602 ";
603
604 if ( $type != "success" ) $message .= "Grid Ctrl Error : $msg\n";
605
606 // Handle the error case where an error occurs before fetching the
607 // user's email address
608 if ( $email_address == "" ) $email_address = $admin_email;
609
610 mail( $email_address, $subject, $message, $headers );
611}
612
613function parse_xml( $xml, $type )
614{
615 $parser = new XMLReader();
616 $parser->xml( $xml );
617
618 $results = array();
619
620 while ( $parser->read() )
621 {
622 if ( $parser->name == $type )
623 {
624 while ( $parser->moveToNextAttribute() )
625 {
626 $results[ $parser->name ] = $parser->value;
627 }
628
629 break;
630 }
631 }
632
633 $parser->close();
634 return $results;
635}
636
637// Function to get information about the current job GFAC
638function get_gfac_message( $gfacID )
639{
640 global $serviceURL;
641 global $me;
642
643 $hex = "[0-9a-fA-F]";
644 if ( ! preg_match( "/^US3-Experiment/i", $gfacID ) &&
645 ! preg_match( "/^US3-$hex{8}-$hex{4}-$hex{4}-$hex{4}-$hex{12}$/", $gfacID ) )
646 {
647 // Then it's not a GFAC job
648 return false;
649 }
650
651 $url = "$serviceURL/jobstatus/$gfacID";
652 try
653 {
654 $post = new HttpRequest( $url, HttpRequest::METH_GET );
655 $http = $post->send();
656 $xml = $post->getResponseBody();
657 }
658 catch ( HttpException $e )
659 {
660 write_log( "$me: Job status not available - $gfacID" );
661 return false;
662 }
663
664 // Parse the result
665 $gfac_message = parse_message( $xml );
666
667 return $gfac_message;
668}
669
670function parse_message( $xml )
671{
672 global $status;
673 $status = "";
674 $gfac_message = "";
675
676 $parser = new XMLReader();
677 $parser->xml( $xml );
678
679 $results = array();
680
681 while( $parser->read() )
682 {
683 $type = $parser->nodeType;
684
685 if ( $type == XMLReader::ELEMENT )
686 $name = $parser->name;
687
688 else if ( $type == XMLReader::TEXT )
689 {
690 if ( $name == "status" )
691 $status = $parser->value;
692 else
693 $gfac_message = $parser->value;
694 }
695 }
696
697 $parser->close();
698 return $gfac_message;
699}
700
701function get_local_files( $gfac_link, $cluster, $requestID, $id, $gfacID )
702{
703 global $work;
704 global $work_remote;
705 global $me;
706 global $db;
707 global $status;
708
709 // Figure out local working directory
710 if ( ! is_dir( "$work/$gfacID" ) ) mkdir( "$work/$gfacID", 0770 );
711 $pwd = chdir( "$work/$gfacID" );
712
713 // Figure out remote directory
714 $remoteDir = sprintf( "$work_remote/$db-%06d", $requestID );
715
716 // Get stdout, stderr, output/analysis-results.tar
717 $output = array();
718// $cmd = "scp us3@$cluster.uthscsa.edu:$remoteDir/stdout . 2>&1";
719//
720// exec( $cmd, $output, $stat );
721// if ( $stat != 0 )
722// write_log( "$me: Bad exec:\n$cmd\n" . implode( "\n", $output ) );
723//
724// $cmd = "scp us3@$cluster.uthscsa.edu:$remoteDir/stderr . 2>&1";
725// exec( $cmd, $output, $stat );
726// if ( $stat != 0 )
727// write_log( "$me: Bad exec:\n$cmd\n" . implode( "\n", $output ) );
728
729 $cmd = "scp us3@$cluster.uthscsa.edu:$remoteDir/output/analysis-results.tar . 2>&1";
730 exec( $cmd, $output, $stat );
731 if ( $stat != 0 )
732 write_log( "$me: Bad exec:\n$cmd\n" . implode( "\n", $output ) );
733
734 $cmd = "scp us3@$cluster.uthscsa.edu:$remoteDir/stdout . 2>&1";
735 exec( $cmd, $output, $stat );
736 if ( $stat != 0 )
737 {
738 write_log( "$me: Bad exec:\n$cmd\n" . implode( "\n", $output ) );
739 sleep( 10 );
740 write_log( "$me: RETRY" );
741 exec( $cmd, $output, $stat );
742 if ( $stat != 0 )
743 write_log( "$me: Bad exec:\n$cmd\n" . implode( "\n", $output ) );
744 }
745
746 $cmd = "scp us3@$cluster.uthscsa.edu:$remoteDir/stderr . 2>&1";
747 exec( $cmd, $output, $stat );
748 if ( $stat != 0 )
749 {
750 write_log( "$me: Bad exec:\n$cmd\n" . implode( "\n", $output ) );
751 sleep( 10 );
752 write_log( "$me: RETRY" );
753 exec( $cmd, $output, $stat );
754 if ( $stat != 0 )
755 write_log( "$me: Bad exec:\n$cmd\n" . implode( "\n", $output ) );
756 }
757
758 // Write the files to gfacDB
759
760 if ( file_exists( "stderr" ) ) $stderr = file_get_contents( "stderr" );
761 if ( file_exists( "stdout" ) ) $stdout = file_get_contents( "stdout" );
762 if ( file_exists( "analysis-results.tar" ) )
763 $tarfile = file_get_contents( "analysis-results.tar" );
764
765 $query = "UPDATE analysis SET " .
766 "stderr='" . mysql_real_escape_string( $stderr, $gfac_link ) . "'," .
767 "stdout='" . mysql_real_escape_string( $stdout, $gfac_link ) . "'," .
768 "tarfile='" . mysql_real_escape_string( $tarfile, $gfac_link ) . "'";
769
770 $result = mysql_query( $query, $gfac_link );
771
772 if ( ! $result )
773 {
774 write_log( "$me: Bad query:\n$query\n" . mysql_error( $gfac_link ) );
775 echo "Bad query\n";
776 return( -1 );
777 }
778}
779?>
Note: See TracBrowser for help on using the repository browser.