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