Changeset 35 for trunk/gridctl.php
- Timestamp:
- Apr 8, 2018, 4:41:57 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gridctl.php
r32 r35 20 20 21 21 // Get data from global GFAC DB 22 $gLink = mysql _connect( $dbhost, $guser, $gpasswd);23 24 if ( ! mysql_select_db( $gDB, $gLink ))25 { 26 write_log( "$self: Could not select DB $gDB - " . mysql _error() );22 $gLink = mysqli_connect( $dbhost, $guser, $gpasswd, $gDB ); 23 24 if ( ! $gLink ) 25 { 26 write_log( "$self: Could not select DB $gDB - " . mysqli_error() ); 27 27 mail_to_admin( "fail", "Internal Error: Could not select DB $gDB" ); 28 sleep(300); 28 29 exit(); 29 30 } … … 31 32 $query = "SELECT gfacID, us3_db, cluster, status, queue_msg, " . 32 33 "UNIX_TIMESTAMP(time), time from analysis"; 33 $result = mysql _query( $query, $gLink);34 $result = mysqli_query( $gLink, $query ); 34 35 35 36 if ( ! $result ) 36 37 { 37 write_log( "$self: Query failed $query - " . mysql _error( $gLink ) );38 mail_to_admin( "fail", "Query failed $query\n" . mysql _error( $gLink ) );38 write_log( "$self: Query failed $query - " . mysqli_error( $gLink ) ); 39 mail_to_admin( "fail", "Query failed $query\n" . mysqli_error( $gLink ) ); 39 40 exit(); 40 41 } 41 42 42 if ( mysql _num_rows( $result ) == 0 )43 if ( mysqli_num_rows( $result ) == 0 ) 43 44 { 44 45 //write_log( "$self: analysis read got numrows==0" ); 45 46 exit(); // Nothing to do 46 47 } 48 //write_log( "$loghdr gfac-analysis rows $nrows" ); 47 49 48 50 $me_devel = preg_match( "/class_devel/", $class_dir ); 51 //echo "me_devel=$me_devel class_dir=$class_dir\n"; 49 52 50 53 while ( list( $gfacID, $us3_db, $cluster, $status, $queue_msg, $time, $updateTime ) 51 = mysql _fetch_array( $result ) )54 = mysqli_fetch_array( $result ) ) 52 55 { 53 56 // If this entry does not match class/class_devel, skip processing 57 //echo " gfacID=$gfacID gf_status=$status\n"; 54 58 55 59 if ( preg_match( "/US3-A/i", $gfacID ) ) 56 60 { // For thrift, job and gridctl must match 57 61 $job_devel = preg_match( "/US3-ADEV/i", $gfacID ); 62 //echo " THR: job_devel=$job_devel\n"; 58 63 if ( ( $me_devel && !$job_devel ) || 59 64 ( !$me_devel && $job_devel ) ) … … 65 70 else if ( $me_devel ) 66 71 { // Local (us3iab/-local) and class_devel: skip processing 72 //echo " LOC: me_devel=$me_devel\n"; 67 73 continue; 68 74 } … … 99 105 //write_log( "$loghdr status_in=$status_in" ); 100 106 $status = aira_status( $gfacID, $status_in ); 107 //echo "$loghdr status_in=$status_in status_ex=$status\n"; 101 108 if($status != $status_in ) 102 109 write_log( "$loghdr Set to $status from $status_in" ); … … 110 117 if ( $status_gw == 'COMPLETE' ) 111 118 $status = $status_gw; 119 //echo "$loghdr status_gw=$status_gw status=$status\n"; 112 120 //write_log( "$loghdr non-AThrift status=$status status_gw=$status_gw" ); 113 121 } … … 119 127 if ( $status_gw == 'COMPLETE' || $status == 'UNKNOWN' ) 120 128 $status = $status_gw; 129 //echo "$loghdr status_lo=$status\n"; 121 130 //write_log( "$loghdr Local status=$status status_gw=$status_gw" ); 122 131 } … … 130 139 131 140 $query2 = "UPDATE analysis SET status='ERROR' WHERE gfacID='$gfacID'"; 132 $result2 = mysql _query( $query2, $gLink);141 $result2 = mysqli_query( $gLink, $query2 ); 133 142 $status = 'ERROR'; 134 143 135 144 if ( ! $result2 ) 136 write_log( "$loghdr Query failed $query2 - " . mysql _error( $gLink ) );145 write_log( "$loghdr Query failed $query2 - " . mysqli_error( $gLink ) ); 137 146 138 147 } … … 200 209 } 201 210 } 211 mysqli_close( $gLink ); 202 212 203 213 exit(); … … 235 245 mail_to_admin( "hang", "$message - id: $gfacID" ); 236 246 $query = "UPDATE analysis SET status='SUBMIT_TIMEOUT' WHERE gfacID='$gfacID'"; 237 $result = mysql _query( $query, $gLink);247 $result = mysqli_query( $gLink, $query ); 238 248 239 249 if ( ! $result ) 240 write_log( "$self: Query failed $query - " . mysql _error( $gLink ) );250 write_log( "$self: Query failed $query - " . mysqli_error( $gLink ) ); 241 251 242 252 update_queue_messages( $message ); … … 271 281 mail_to_admin( "hang", "$message - id: $gfacID" ); 272 282 $query = "UPDATE analysis SET status='FAILED' WHERE gfacID='$gfacID'"; 273 $result = mysql _query( $query, $gLink);283 $result = mysqli_query( $gLink, $query ); 274 284 275 285 if ( ! $result ) 276 write_log( "$self: Query failed $query - " . mysql _error( $gLink ) );286 write_log( "$self: Query failed $query - " . mysqli_error( $gLink ) ); 277 287 278 288 update_queue_messages( $message ); … … 311 321 mail_to_admin( "hang", "$message - id: $gfacID" ); 312 322 $query = "UPDATE analysis SET status='RUN_TIMEOUT' WHERE gfacID='$gfacID'"; 313 $result = mysql _query( $query, $gLink);323 $result = mysqli_query( $gLink, $query ); 314 324 315 325 if ( ! $result ) 316 write_log( "$self: Query failed $query - " . mysql _error( $gLink ) );326 write_log( "$self: Query failed $query - " . mysqli_error( $gLink ) ); 317 327 318 328 update_queue_messages( $message ); … … 349 359 mail_to_admin( "hang", "$message - id: $gfacID" ); 350 360 $query = "UPDATE analysis SET status='FAILED' WHERE gfacID='$gfacID'"; 351 $result = mysql _query( $query, $gLink);361 $result = mysqli_query( $gLink, $query ); 352 362 353 363 if ( ! $result ) 354 write_log( "$self: Query failed $query - " . mysql _error( $gLink ) );364 write_log( "$self: Query failed $query - " . mysqli_error( $gLink ) ); 355 365 356 366 update_queue_messages( $message ); … … 397 407 mail_to_admin( "hang", "$message - id: $gfacID" ); 398 408 $query = "UPDATE analysis SET status='DATA_TIMEOUT' WHERE gfacID='$gfacID'"; 399 $result = mysql _query( $query, $gLink);409 $result = mysqli_query( $gLink, $query ); 400 410 401 411 if ( ! $result ) 402 write_log( "$self: Query failed $query - " . mysql _error( $gLink ) );412 write_log( "$self: Query failed $query - " . mysqli_error( $gLink ) ); 403 413 404 414 update_queue_messages( $message ); … … 445 455 mail_to_admin( "hang", "$message - id: $gfacID" ); 446 456 $query = "UPDATE analysis SET status='FAILED' WHERE gfacID='$gfacID'"; 447 $result = mysql _query( $query, $gLink);457 $result = mysqli_query( $gLink, $query ); 448 458 449 459 if ( ! $result ) 450 write_log( "$self: Query failed $query - " . mysql _error( $gLink ) );460 write_log( "$self: Query failed $query - " . mysqli_error( $gLink ) ); 451 461 452 462 update_queue_messages( $message ); … … 477 487 // Double check that the gfacID exists 478 488 $query = "SELECT count(*) FROM analysis WHERE gfacID='$gfacID'"; 479 $result = mysql _query( $query, $gLink);489 $result = mysqli_query( $gLink, $query ); 480 490 481 491 if ( ! $result ) 482 492 { 483 write_log( "$self: Query failed $query - " . mysql _error( $gLink ) );484 mail_to_admin( "fail", "Query failed $query\n" . mysql _error( $gLink ) );485 return; 486 } 487 488 list( $count ) = mysql _fetch_array( $result );489 490 if ($count==0)491 write_log( "$loghdr count = $count gfacID = $gfacID" );493 write_log( "$self: Query failed $query - " . mysqli_error( $gLink ) ); 494 mail_to_admin( "fail", "Query failed $query\n" . mysqli_error( $gLink ) ); 495 return; 496 } 497 498 list( $count ) = mysqli_fetch_array( $result ); 499 500 //if ($count==0) 501 //write_log( "$loghdr count = $count gfacID = $gfacID" ); 492 502 if ( $count == 0 ) return; 493 503 … … 597 607 } 598 608 599 $result = mysql _query( $query, $gLink);609 $result = mysqli_query( $gLink, $query ); 600 610 if ( ! $result ) 601 write_log( "$loghdr Query failed $query - " . mysql _error( $gLink ) );611 write_log( "$loghdr Query failed $query - " . mysqli_error( $gLink ) ); 602 612 603 613 if ( $message != 'NONE' ) … … 619 629 global $loghdr; 620 630 621 $us3_link = mysql _connect( $dbhost, $user, $passwd);631 $us3_link = mysqli_connect( $dbhost, $user, $passwd, $us3_db ); 622 632 623 633 if ( ! $us3_link ) 624 634 { 625 write_log( "$loghdr could not connect: $dbhost, $user, $passwd" ); 626 mail_to_admin( "fail", "Could not connect to $dbhost" ); 627 return 0; 628 } 629 630 631 $result = mysql_select_db( $us3_db, $us3_link ); 632 633 if ( ! $result ) 634 { 635 write_log( "$loghdr could not select DB $us3_db" ); 636 mail_to_admin( "fail", "Could not select DB $us3_db, $dbhost, $user, $passwd" ); 635 write_log( "$loghdr could not connect: $dbhost, $user, $passwd, $us3_db" ); 636 mail_to_admin( "fail", "Could not connect to $dbhost : $us3_db" ); 637 637 return 0; 638 638 } … … 640 640 $query = "SELECT HPCAnalysisRequestID, UNIX_TIMESTAMP(updateTime) " . 641 641 "FROM HPCAnalysisResult WHERE gfacID='$gfacID'"; 642 $result = mysql _query( $query, $us3_link);642 $result = mysqli_query( $us3_link, $query ); 643 643 644 644 if ( ! $result ) 645 645 { 646 write_log( "$self: Query failed $query - " . mysql _error( $us3_link ) );647 mail_to_admin( "fail", "Query failed $query\n" . mysql _error( $us3_link ) );646 write_log( "$self: Query failed $query - " . mysqli_error( $us3_link ) ); 647 mail_to_admin( "fail", "Query failed $query\n" . mysqli_error( $us3_link ) ); 648 648 return 0; 649 649 } 650 650 651 list( $requestID, $updateTime ) = mysql _fetch_array( $result );652 mysql _close( $us3_link );651 list( $requestID, $updateTime ) = mysqli_fetch_array( $result ); 652 mysqli_close( $us3_link ); 653 653 654 654 return $requestID; … … 859 859 //write_log( "$self result: $result" ); 860 860 861 ///////////////////////////////////////////////////////////////////862 861 $secwait = 2; 863 862 $num_try = 0; … … 870 869 write_log( "$me: num_try=$num_try secwait=$secwait" ); 871 870 } 872 /////////////////////////////////////////////////////////////////// 873 // if ( $result == "" || 874 // preg_match( "/^qstat: Unknown/", $result ) || 875 // preg_match( "/ssh_exchange_id/", $result ) ) 871 876 872 if ( preg_match( "/^qstat: Unknown/", $result ) || 877 873 preg_match( "/ssh_exchange_id/", $result ) ) 878 874 { 879 write_log( "$self get_local_status: Local job $gfacID unknown" ); 880 //write_log( "$self get_local_status: result=$result" ); 875 write_log( "$self get_local_status: Local job $gfacID unknown result=$result" ); 881 876 return 'UNKNOWN'; 882 877 } … … 937 932 $query = "SELECT id FROM analysis " . 938 933 "WHERE gfacID = '$gfacID' "; 939 $result = mysql _query( $query, $gLink);934 $result = mysqli_query( $gLink, $query ); 940 935 if ( ! $result ) 941 936 { 942 write_log( "$self: Query failed $query - " . mysql _error( $gLink ) );943 return; 944 } 945 list( $analysisID ) = mysql _fetch_array( $result );937 write_log( "$self: Query failed $query - " . mysqli_error( $gLink ) ); 938 return; 939 } 940 list( $analysisID ) = mysqli_fetch_array( $result ); 946 941 947 942 // Insert message into queue_message table 948 943 $query = "INSERT INTO queue_messages SET " . 949 "message = '" . mysql _real_escape_string( $message, $gLink) . "', " .944 "message = '" . mysqli_real_escape_string( $gLink, $message ) . "', " . 950 945 "analysisID = '$analysisID' "; 951 $result = mysql _query( $query, $gLink);946 $result = mysqli_query( $gLink, $query ); 952 947 if ( ! $result ) 953 948 { 954 write_log( "$self: Query failed $query - " . mysql _error( $gLink ) );949 write_log( "$self: Query failed $query - " . mysqli_error( $gLink ) ); 955 950 return; 956 951 } … … 966 961 global $us3_db; 967 962 968 $us3_link = mysql _connect( $dbhost, $user, $passwd);963 $us3_link = mysqli_connect( $dbhost, $user, $passwd, $us3_db ); 969 964 970 965 if ( ! $us3_link ) 971 966 { 972 967 write_log( "$self: could not connect: $dbhost, $user, $passwd" ); 973 mail_to_admin( "fail", "Could not connect to $dbhost " );968 mail_to_admin( "fail", "Could not connect to $dbhost : $us3_db" ); 974 969 return 0; 975 970 } 976 971 977 978 $result = mysql_select_db( $us3_db, $us3_link );979 980 if ( ! $result )981 {982 write_log( "$self: could not select DB $us3_db" );983 mail_to_admin( "fail", "Could not select DB $us3_db, $dbhost, $user, $passwd" );984 return 0;985 }986 987 972 $query = "UPDATE HPCAnalysisResult SET " . 988 "lastMessage='" . mysql _real_escape_string( $message, $us3_link) . "'" .973 "lastMessage='" . mysqli_real_escape_string( $us3_link, $message ) . "'" . 989 974 "WHERE gfacID = '$gfacID' "; 990 975 991 mysql _query( $query, $us3_link);992 mysql _close( $us3_link );976 mysqli_query( $us3_link, $query ); 977 mysqli_close( $us3_link ); 993 978 } 994 979 … … 1173 1158 } 1174 1159 1160 //if ( $status != 'SUBMITTED' ) 1175 1161 //write_log( "$loghdr status/_in/_gw/_ex=$status/$status_in/$status_gw/$status_ex" ); 1176 1162 if ( $status != $status_gw )
Note:
See TracChangeset
for help on using the changeset viewer.