Changeset 35 for trunk/cleanup_gfac.php
- Timestamp:
- Apr 8, 2018, 4:41:57 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/cleanup_gfac.php
r25 r35 41 41 write_log( "$me: debug db=$db; requestID=$requestID" ); 42 42 43 $us3_link = mysql _connect( $dbhost, $user, $passwd);43 $us3_link = mysqli_connect( $dbhost, $user, $passwd, $db ); 44 44 45 45 if ( ! $us3_link ) 46 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" ); 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" ); 58 49 return( -1 ); 59 50 } … … 62 53 $query = "SELECT email, investigatorGUID, editXMLFilename FROM HPCAnalysisRequest " . 63 54 "WHERE HPCAnalysisRequestID=$requestID"; 64 $result = mysql _query( $query, $us3_link);55 $result = mysqli_query( $us3_link, $query ); 65 56 66 57 if ( ! $result ) 67 58 { 68 59 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 );60 mail_to_user( "fail", "Internal Error $requestID\n$query\n" . mysqli_error( $us3_link ) ); 61 return( -1 ); 62 } 63 64 list( $email_address, $investigatorGUID, $editXMLFilename ) = mysqli_fetch_array( $result ); 74 65 75 66 $query = "SELECT personID FROM people " . 76 67 "WHERE personGUID='$investigatorGUID'"; 77 $result = mysql _query( $query, $us3_link);78 79 list( $personID ) = mysql _fetch_array( $result );68 $result = mysqli_query( $us3_link, $query ); 69 70 list( $personID ) = mysqli_fetch_array( $result ); 80 71 81 72 /* … … 90 81 "AND h.HPCAnalysisRequestID=r.HPCAnalysisRequestID"; 91 82 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 )83 $result = mysqli_query( $us3_link, $query ); 84 85 if ( ! $result ) 86 { 87 write_log( "$me: Bad query:\n$query\n" . mysqli_error( $us3_link ) ); 88 return( -1 ); 89 } 90 91 if ( mysqli_num_rows( $result ) == 0 ) 101 92 { 102 93 write_log( "$me: US3 Table error - No records for requestID: $requestID" ); … … 104 95 } 105 96 106 list( $cluster, $submittime, $queuestatus, $jobtype ) = mysql _fetch_array( $result );97 list( $cluster, $submittime, $queuestatus, $jobtype ) = mysqli_fetch_array( $result ); 107 98 108 99 // Get the GFAC ID … … 110 101 "WHERE HPCAnalysisRequestID=$requestID"; 111 102 112 $result = mysql _query( $query, $us3_link);103 $result = mysqli_query( $us3_link, $query ); 113 104 114 105 if ( ! $result ) 115 106 { 116 107 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 );108 mail_to_user( "fail", "Internal Error $requestID\n$query\n" . mysqli_error( $us3_link ) ); 109 return( -1 ); 110 } 111 112 list( $HPCAnalysisResultID, $gfacID ) = mysqli_fetch_array( $result ); 122 113 123 114 //////// 124 115 // 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" ); 116 $gfac_link = mysqli_connect( $dbhost, $guser, $gpasswd, $gDB ); 117 118 if ( ! $gfac_link ) 119 { 120 write_log( "$me: Could not connect to DB $dbhost : $gDB" ); 132 121 mail_to_user( "fail", "Internal Error $requestID\nCould not connect to DB $gDB" ); 133 122 return( -1 ); … … 137 126 "WHERE gfacID='$gfacID'"; 138 127 139 $result = mysql _query( $query, $gfac_link);128 $result = mysqli_query( $gfac_link, $query ); 140 129 if ( ! $result ) 141 130 { … … 145 134 } 146 135 147 $num_rows = mysql _num_rows( $result );136 $num_rows = mysqli_num_rows( $result ); 148 137 if ( $num_rows == 0 ) 149 138 { … … 156 145 //} 157 146 158 list( $status, $cluster, $id ) = mysql _fetch_array( $result );147 list( $status, $cluster, $id ) = mysqli_fetch_array( $result ); 159 148 //write_log( "$me: db=$db; requestID=$requestID; status=$status; cluster=$cluster" ); 160 149 … … 176 165 "WHERE gfacID='$gfacID'"; 177 166 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 );167 $result = mysqli_query( $gfac_link, $query ); 168 169 if ( ! $result ) 170 { 171 write_log( "$me: Bad query:\n$query\n" . mysqli_error( $gfac_link ) ); 172 mail_to_user( "fail", "Internal error " . mysqli_error( $gfac_link ) ); 173 return( -1 ); 174 } 175 176 $num_rows = mysqli_num_rows( $result ); 188 177 if ( $num_rows == 0 ) 189 178 { … … 192 181 } 193 182 194 list( $analysisID, $stderr, $stdout, $tarfile ) = mysql _fetch_array( $result );183 list( $analysisID, $stderr, $stdout, $tarfile ) = mysqli_fetch_array( $result ); 195 184 196 185 if ( strlen( $tarfile ) > 0 ) … … 209 198 "WHERE analysisID = $analysisID " . 210 199 "ORDER BY time "; 211 $result = mysql _query( $query, $gfac_link);200 $result = mysqli_query( $gfac_link, $query ); 212 201 213 202 if ( ! $result ) 214 203 { 215 204 // Just log it and continue 216 write_log( "$me: Bad query:\n$query\n" . mysql _error( $gfac_link ) );205 write_log( "$me: Bad query:\n$query\n" . mysqli_error( $gfac_link ) ); 217 206 } 218 207 … … 226 215 $need_finish = ( $status == 'COMPLETE' ); 227 216 228 if ( mysql _num_rows( $result ) > 0 )217 if ( mysqli_num_rows( $result ) > 0 ) 229 218 { 230 219 $time_msg = time(); 231 while ( list( $message, $time ) = mysql _fetch_array( $result ) )220 while ( list( $message, $time ) = mysqli_fetch_array( $result ) ) 232 221 { 233 222 //write_log( "$me: message=$message" ); … … 263 252 "WHERE analysisID = $analysisID "; 264 253 265 $result = mysql _query( $query, $gfac_link);254 $result = mysqli_query( $gfac_link, $query ); 266 255 267 256 if ( ! $result ) 268 257 { 269 258 // Just log it and continue 270 write_log( "$me: Bad query:\n$query\n" . mysql _error( $gfac_link ) );259 write_log( "$me: Bad query:\n$query\n" . mysqli_error( $gfac_link ) ); 271 260 } 272 261 … … 274 263 $query = "SELECT stdout, stderr, status, queue_msg FROM analysis " . 275 264 "WHERE gfacID='$gfacID' "; 276 $result = mysql _query( $query, $gfac_link);265 $result = mysqli_query( $gfac_link, $query ); 277 266 try 278 267 { 279 268 // What if this is too large? 280 list( $stdout, $stderr, $status, $queue_msg ) = mysql _fetch_array( $result );269 list( $stdout, $stderr, $status, $queue_msg ) = mysqli_fetch_array( $result ); 281 270 } 282 271 catch ( Exception $e ) 283 272 { 284 write_log( "$me: stdout + stderr larger than 128M - $gfacID\n" . mysql _error( $gfac_link ) );273 write_log( "$me: stdout + stderr larger than 128M - $gfacID\n" . mysqli_error( $gfac_link ) ); 285 274 // Just go ahead and clean up 286 275 } … … 301 290 $query = "DELETE from analysis WHERE gfacID='$gfacID'"; 302 291 303 $result = mysql _query( $query, $gfac_link);292 $result = mysqli_query( $gfac_link, $query ); 304 293 305 294 if ( ! $result ) 306 295 { 307 296 // Just log it and continue 308 write_log( "$me: Bad query:\n$query\n" . mysql _error( $gfac_link ) );297 write_log( "$me: Bad query:\n$query\n" . mysqli_error( $gfac_link ) ); 309 298 } 310 299 write_log( "$me: GFAC DB entry deleted" ); … … 316 305 $query = "SELECT HPCAnalysisRequestGUID FROM HPCAnalysisRequest " . 317 306 "WHERE HPCAnalysisRequestID = $requestID "; 318 $result = mysql _query( $query, $us3_link);307 $result = mysqli_query( $us3_link, $query ); 319 308 320 309 if ( ! $result ) 321 310 { 322 write_log( "$me: Bad query:\n$query\n" . mysql _error( $us3_link ) );311 write_log( "$me: Bad query:\n$query\n" . mysqli_error( $us3_link ) ); 323 312 } 324 313 325 list( $requestGUID ) = mysql _fetch_array( $result );314 list( $requestGUID ) = mysqli_fetch_array( $result ); 326 315 $output_dir = "$submit_dir/$requestGUID"; 327 316 write_log( "$me: Output dir determined: $output_dir" ); … … 334 323 $message_filename = "$output_dir/$db-$requestID-messages.txt"; 335 324 file_put_contents( $message_filename, $message_log, FILE_APPEND ); 336 // mysql _close( $gfac_link );325 // mysqli_close( $gfac_link ); 337 326 write_log( "$me: *messages.txt written" ); 338 327 … … 341 330 342 331 $query = "UPDATE HPCAnalysisResult SET " . 343 "stderr='" . mysql _real_escape_string( $stderr, $us3_link) . "', " .344 "stdout='" . mysql _real_escape_string( $stdout, $us3_link) . "' " .332 "stderr='" . mysqli_real_escape_string( $us3_link, $stderr ) . "', " . 333 "stdout='" . mysqli_real_escape_string( $us3_link, $stdout ) . "' " . 345 334 "WHERE HPCAnalysisResultID=$HPCAnalysisResultID"; 346 335 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 ) );336 $result = mysqli_query( $us3_link, $query ); 337 338 if ( ! $result ) 339 { 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 ) ); 353 342 return( -1 ); 354 343 } … … 442 431 "mgroupcount = {$otherdata['groupcount']} " . 443 432 "WHERE HPCAnalysisResultID=$HPCAnalysisResultID"; 444 $result = mysql _query( $query, $us3_link);433 $result = mysqli_query( $us3_link, $query ); 445 434 446 435 if ( ! $result ) 447 436 { 448 write_log( "$me: Bad query:\n$query\n" . mysql _error( $us3_link ) );437 write_log( "$me: Bad query:\n$query\n" . mysqli_error( $us3_link ) ); 449 438 } 450 439 … … 463 452 $modelGUID = $noise_data[ 'modelGUID' ]; 464 453 $noiseGUID = $noise_data[ 'noiseGUID' ]; 454 $editGUID = '00000000-0000-0000-0000-000000000000'; 455 if ( isset( $model_data[ 'editGUID' ] ) ) 456 $editGUID = $model_data[ 'editGUID' ]; 465 457 466 458 $query = "INSERT INTO noise SET " . 467 459 "noiseGUID='$noiseGUID'," . 468 460 "modelGUID='$modelGUID'," . 469 "editedDataID=2, " . 461 "editedDataID=" . 462 "(SELECT editedDataID FROM editedData WHERE editGUID='$editGUID')," . 470 463 "modelID=1, " . 471 464 "noiseType='$type'," . 472 465 "description='$desc'," . 473 "xml='" . mysql _real_escape_string( $xml, $us3_link) . "'";466 "xml='" . mysqli_real_escape_string( $us3_link, $xml ) . "'"; 474 467 475 468 // Add later after all files are processed: editDataID, modelID 476 469 477 $result = mysql _query( $query, $us3_link);470 $result = mysqli_query( $us3_link, $query ); 478 471 479 472 if ( ! $result ) 480 473 { 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 ) );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 ) ); 483 476 return( -1 ); 484 477 } 485 478 486 $id = mysql _insert_id( $us3_link );479 $id = mysqli_insert_id( $us3_link ); 487 480 $file_type = "noise"; 488 481 $noiseIDs[] = $id; … … 490 483 // Keep track of modelGUIDs for later, when we replace them 491 484 $modelGUIDs[ $id ] = $modelGUID; 492 //write_log( "$me: noise file inserted into DB : id=$id " );485 //write_log( "$me: noise file inserted into DB : id=$id modelGUID=$modelGUID" ); 493 486 494 487 } … … 512 505 "mrecsGUID='$mrecGUID'," . 513 506 "description='$desc'," . 514 "xml='" . mysql _real_escape_string( $xml, $us3_link) . "'";507 "xml='" . mysqli_real_escape_string( $us3_link, $xml ) . "'"; 515 508 516 509 // Add later after all files are processed: editDataID, modelID 517 510 518 $result = mysql _query( $query, $us3_link);511 $result = mysqli_query( $us3_link, $query ); 519 512 520 513 if ( ! $result ) 521 514 { 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 ) );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 ) ); 524 517 return( -1 ); 525 518 } 526 519 527 $id = mysql _insert_id( $us3_link );520 $id = mysqli_insert_id( $us3_link ); 528 521 $file_type = "mrecs"; 529 522 $mrecsIDs[] = $id; … … 560 553 "meniscus='$meniscus'," . 561 554 "variance='$variance'," . 562 "xml='" . mysql _real_escape_string( $xml, $us3_link) . "'";563 564 $result = mysql _query( $query, $us3_link);555 "xml='" . mysqli_real_escape_string( $us3_link, $xml ) . "'"; 556 557 $result = mysqli_query( $us3_link, $query ); 565 558 566 559 if ( ! $result ) 567 560 { 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 ) );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 ) ); 570 563 return( -1 ); 571 564 } 572 565 573 $modelID = mysql _insert_id( $us3_link );566 $modelID = mysqli_insert_id( $us3_link ); 574 567 $id = $modelID; 575 568 $file_type = "model"; … … 577 570 $query = "INSERT INTO modelPerson SET " . 578 571 "modelID=$modelID, personID=$personID"; 579 $result = mysql _query( $query, $us3_link);572 $result = mysqli_query( $us3_link, $query ); 580 573 //write_log( "$me: model file inserted into DB : id=$id" ); 581 574 } … … 586 579 "resultID=$id"; 587 580 588 $result = mysql _query( $query, $us3_link);581 $result = mysqli_query( $us3_link, $query ); 589 582 590 583 if ( ! $result ) 591 584 { 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 ) );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 ) ); 594 587 return( -1 ); 595 588 } … … 611 604 "WHERE noiseID=$noiseID"; 612 605 613 $result = mysql _query( $query, $us3_link);606 $result = mysqli_query( $us3_link, $query ); 614 607 615 608 if ( ! $result ) 616 609 { 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 ) );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 ) ); 619 612 return( -1 ); 620 613 } … … 633 626 "WHERE mrecsID=$mrecsID"; 634 627 635 $result = mysql _query( $query, $us3_link);628 $result = mysqli_query( $us3_link, $query ); 636 629 637 630 if ( ! $result ) 638 631 { 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 ) );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 ) ); 641 634 return( -1 ); 642 635 } … … 651 644 $query = "SELECT HPCAnalysisRequestGUID FROM HPCAnalysisRequest " . 652 645 "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 );646 $result = mysqli_query( $us3_link, $query ); 647 648 if ( ! $result ) 649 { 650 write_log( "$me: Bad query:\n$query\n" . mysqli_error( $us3_link ) ); 651 } 652 653 list( $requestGUID ) = mysqli_fetch_array( $result ); 661 654 662 655 chdir( "$submit_dir/$requestGUID" ); … … 669 662 // exec( "rm -rf $gfacID" ); 670 663 671 mysql _close( $us3_link );664 mysqli_close( $us3_link ); 672 665 673 666 /////////
Note:
See TracChangeset
for help on using the changeset viewer.