Changeset 35 for trunk/gridctl.php


Ignore:
Timestamp:
Apr 8, 2018, 4:41:57 PM (7 years ago)
Author:
gegorbet
Message:

mods mostly for use of mysqli

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gridctl.php

    r32 r35  
    2020
    2121// 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
     24if ( ! $gLink )
     25{
     26   write_log( "$self: Could not select DB $gDB - " . mysqli_error() );
    2727   mail_to_admin( "fail", "Internal Error: Could not select DB $gDB" );
     28   sleep(300);
    2829   exit();
    2930}
     
    3132$query = "SELECT gfacID, us3_db, cluster, status, queue_msg, " .
    3233                "UNIX_TIMESTAMP(time), time from analysis";
    33 $result = mysql_query( $query, $gLink );
     34$result = mysqli_query( $gLink, $query );
    3435
    3536if ( ! $result )
    3637{
    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 ) );
    3940   exit();
    4041}
    4142
    42 if ( mysql_num_rows( $result ) == 0 )
     43if ( mysqli_num_rows( $result ) == 0 )
    4344{
    4445//write_log( "$self: analysis read got numrows==0" );
    4546   exit();  // Nothing to do
    4647}
     48//write_log( "$loghdr    gfac-analysis rows $nrows" );
    4749
    4850$me_devel  = preg_match( "/class_devel/", $class_dir );
     51//echo "me_devel=$me_devel class_dir=$class_dir\n";
    4952
    5053while ( list( $gfacID, $us3_db, $cluster, $status, $queue_msg, $time, $updateTime )
    51             = mysql_fetch_array( $result ) )
     54            = mysqli_fetch_array( $result ) )
    5255{
    5356   // If this entry does not match class/class_devel, skip processing
     57//echo "  gfacID=$gfacID gf_status=$status\n";
    5458
    5559   if ( preg_match( "/US3-A/i", $gfacID ) )
    5660   {  // For thrift, job and gridctl must match
    5761      $job_devel = preg_match( "/US3-ADEV/i", $gfacID );
     62//echo "   THR: job_devel=$job_devel\n";
    5863      if ( (  $me_devel  &&  !$job_devel )  ||
    5964           ( !$me_devel  &&   $job_devel ) )
     
    6570   else if ( $me_devel )
    6671   {  // Local (us3iab/-local) and class_devel:  skip processing
     72//echo "   LOC: me_devel=$me_devel\n";
    6773      continue;
    6874   }
     
    99105//write_log( "$loghdr status_in=$status_in" );
    100106      $status     = aira_status( $gfacID, $status_in );
     107//echo "$loghdr status_in=$status_in  status_ex=$status\n";
    101108if($status != $status_in )
    102109 write_log( "$loghdr Set to $status from $status_in" );
     
    110117      if ( $status_gw == 'COMPLETE' )
    111118         $status     = $status_gw;
     119//echo "$loghdr status_gw=$status_gw  status=$status\n";
    112120//write_log( "$loghdr non-AThrift status=$status status_gw=$status_gw" );
    113121   }
     
    119127      if ( $status_gw == 'COMPLETE'  ||  $status == 'UNKNOWN' )
    120128         $status     = $status_gw;
     129//echo "$loghdr status_lo=$status\n";
    121130//write_log( "$loghdr Local status=$status status_gw=$status_gw" );
    122131   }
     
    130139
    131140      $query2  = "UPDATE analysis SET status='ERROR' WHERE gfacID='$gfacID'";
    132       $result2 = mysql_query( $query2, $gLink );
     141      $result2 = mysqli_query( $gLink, $query2 );
    133142      $status  = 'ERROR';
    134143
    135144      if ( ! $result2 )
    136          write_log( "$loghdr Query failed $query2 - " .  mysql_error( $gLink ) );
     145         write_log( "$loghdr Query failed $query2 - " .  mysqli_error( $gLink ) );
    137146
    138147   }
     
    200209   }
    201210}
     211mysqli_close( $gLink );
    202212
    203213exit();
     
    235245   mail_to_admin( "hang", "$message - id: $gfacID" );
    236246   $query = "UPDATE analysis SET status='SUBMIT_TIMEOUT' WHERE gfacID='$gfacID'";
    237    $result = mysql_query( $query, $gLink );
     247   $result = mysqli_query( $gLink, $query );
    238248
    239249   if ( ! $result )
    240       write_log( "$self: Query failed $query - " .  mysql_error( $gLink ) );
     250      write_log( "$self: Query failed $query - " .  mysqli_error( $gLink ) );
    241251
    242252   update_queue_messages( $message );
     
    271281   mail_to_admin( "hang", "$message - id: $gfacID" );
    272282   $query = "UPDATE analysis SET status='FAILED' WHERE gfacID='$gfacID'";
    273    $result = mysql_query( $query, $gLink );
     283   $result = mysqli_query( $gLink, $query );
    274284
    275285   if ( ! $result )
    276       write_log( "$self: Query failed $query - " .  mysql_error( $gLink ) );
     286      write_log( "$self: Query failed $query - " .  mysqli_error( $gLink ) );
    277287
    278288   update_queue_messages( $message );
     
    311321   mail_to_admin( "hang", "$message - id: $gfacID" );
    312322   $query = "UPDATE analysis SET status='RUN_TIMEOUT' WHERE gfacID='$gfacID'";
    313    $result = mysql_query( $query, $gLink );
     323   $result = mysqli_query( $gLink, $query );
    314324
    315325   if ( ! $result )
    316       write_log( "$self: Query failed $query - " .  mysql_error( $gLink ) );
     326      write_log( "$self: Query failed $query - " .  mysqli_error( $gLink ) );
    317327
    318328   update_queue_messages( $message );
     
    349359   mail_to_admin( "hang", "$message - id: $gfacID" );
    350360   $query = "UPDATE analysis SET status='FAILED' WHERE gfacID='$gfacID'";
    351    $result = mysql_query( $query, $gLink );
     361   $result = mysqli_query( $gLink, $query );
    352362
    353363   if ( ! $result )
    354       write_log( "$self: Query failed $query - " .  mysql_error( $gLink ) );
     364      write_log( "$self: Query failed $query - " .  mysqli_error( $gLink ) );
    355365
    356366   update_queue_messages( $message );
     
    397407   mail_to_admin( "hang", "$message - id: $gfacID" );
    398408   $query = "UPDATE analysis SET status='DATA_TIMEOUT' WHERE gfacID='$gfacID'";
    399    $result = mysql_query( $query, $gLink );
     409   $result = mysqli_query( $gLink, $query );
    400410
    401411   if ( ! $result )
    402       write_log( "$self: Query failed $query - " .  mysql_error( $gLink ) );
     412      write_log( "$self: Query failed $query - " .  mysqli_error( $gLink ) );
    403413
    404414   update_queue_messages( $message );
     
    445455   mail_to_admin( "hang", "$message - id: $gfacID" );
    446456   $query = "UPDATE analysis SET status='FAILED' WHERE gfacID='$gfacID'";
    447    $result = mysql_query( $query, $gLink );
     457   $result = mysqli_query( $gLink, $query );
    448458
    449459   if ( ! $result )
    450       write_log( "$self: Query failed $query - " .  mysql_error( $gLink ) );
     460      write_log( "$self: Query failed $query - " .  mysqli_error( $gLink ) );
    451461
    452462   update_queue_messages( $message );
     
    477487   // Double check that the gfacID exists
    478488   $query  = "SELECT count(*) FROM analysis WHERE gfacID='$gfacID'";
    479    $result = mysql_query( $query, $gLink );
     489   $result = mysqli_query( $gLink, $query );
    480490 
    481491   if ( ! $result )
    482492   {
    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" );
    492502   if ( $count == 0 ) return;
    493503
     
    597607  }
    598608
    599    $result =  mysql_query( $query, $gLink );
     609   $result =  mysqli_query( $gLink, $query );
    600610   if ( ! $result )
    601       write_log( "$loghdr Query failed $query - " .  mysql_error( $gLink ) );
     611      write_log( "$loghdr Query failed $query - " .  mysqli_error( $gLink ) );
    602612
    603613   if ( $message != 'NONE' )
     
    619629   global $loghdr;
    620630
    621    $us3_link = mysql_connect( $dbhost, $user, $passwd );
     631   $us3_link = mysqli_connect( $dbhost, $user, $passwd, $us3_db );
    622632
    623633   if ( ! $us3_link )
    624634   {
    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" );
    637637      return 0;
    638638   }
     
    640640   $query = "SELECT HPCAnalysisRequestID, UNIX_TIMESTAMP(updateTime) " .
    641641            "FROM HPCAnalysisResult WHERE gfacID='$gfacID'";
    642    $result = mysql_query( $query, $us3_link );
     642   $result = mysqli_query( $us3_link, $query );
    643643
    644644   if ( ! $result )
    645645   {
    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 ) );
    648648      return 0;
    649649   }
    650650
    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 );
    653653
    654654   return $requestID;
     
    859859//write_log( "$self  result: $result" );
    860860
    861 ///////////////////////////////////////////////////////////////////
    862861   $secwait    = 2;
    863862   $num_try    = 0;
     
    870869write_log( "$me:   num_try=$num_try  secwait=$secwait" );
    871870   }
    872 ///////////////////////////////////////////////////////////////////
    873 //   if ( $result == ""  ||
    874 //        preg_match( "/^qstat: Unknown/", $result )  ||
    875 //        preg_match( "/ssh_exchange_id/", $result ) )
     871
    876872   if ( preg_match( "/^qstat: Unknown/", $result )  ||
    877873        preg_match( "/ssh_exchange_id/", $result ) )
    878874   {
    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" );
    881876      return 'UNKNOWN';
    882877   }
     
    937932   $query  = "SELECT id FROM analysis " .
    938933             "WHERE gfacID = '$gfacID' ";
    939    $result = mysql_query( $query, $gLink );
     934   $result = mysqli_query( $gLink, $query );
    940935   if ( ! $result )
    941936   {
    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 );
    946941
    947942   // Insert message into queue_message table
    948943   $query  = "INSERT INTO queue_messages SET " .
    949              "message = '" . mysql_real_escape_string( $message, $gLink ) . "', " .
     944             "message = '" . mysqli_real_escape_string( $gLink, $message ) . "', " .
    950945             "analysisID = '$analysisID' ";
    951    $result = mysql_query( $query, $gLink );
     946   $result = mysqli_query( $gLink, $query );
    952947   if ( ! $result )
    953948   {
    954       write_log( "$self: Query failed $query - " .  mysql_error( $gLink ) );
     949      write_log( "$self: Query failed $query - " .  mysqli_error( $gLink ) );
    955950      return;
    956951   }
     
    966961   global $us3_db;
    967962
    968    $us3_link = mysql_connect( $dbhost, $user, $passwd );
     963   $us3_link = mysqli_connect( $dbhost, $user, $passwd, $us3_db );
    969964
    970965   if ( ! $us3_link )
    971966   {
    972967      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" );
    974969      return 0;
    975970   }
    976971
    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 
    987972   $query = "UPDATE HPCAnalysisResult SET " .
    988             "lastMessage='" . mysql_real_escape_string( $message, $us3_link ) . "'" .
     973            "lastMessage='" . mysqli_real_escape_string( $us3_link, $message ) . "'" .
    989974            "WHERE gfacID = '$gfacID' ";
    990975
    991    mysql_query( $query, $us3_link );
    992    mysql_close( $us3_link );
     976   mysqli_query( $us3_link, $query );
     977   mysqli_close( $us3_link );
    993978}
    994979
     
    11731158      }
    11741159
     1160//if ( $status != 'SUBMITTED' )
    11751161//write_log( "$loghdr status/_in/_gw/_ex=$status/$status_in/$status_gw/$status_ex" );
    11761162      if ( $status != $status_gw )
Note: See TracChangeset for help on using the changeset viewer.