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