Changeset 6 for trunk/gridctl.php


Ignore:
Timestamp:
Apr 22, 2015, 10:27:05 PM (10 years ago)
Author:
gegorbet
Message:

changes since 2013, mostly for airvata/thrift

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gridctl.php

    r3 r6  
    11<?php
    22
    3 include_once "/home/us3/bin/listen-config.php";
    4 include "/home/us3/bin/cleanup.php";
     3$us3bin = exec( "ls -d ~us3/bin" );
     4include_once "$us3bin/listen-config.php";
     5include "$us3bin/cleanup_aira.php";
     6include "$us3bin/cleanup_gfac.php";
    57
    68// Global variables
     
    1012$cluster    = '';
    1113
     14//global $self;
     15
    1216// Produce some output temporarily, so cron will send me message
    1317$now = time();
    14 //echo "Time started: " . date( 'Y-m-d H:i:s', $now ) . "\n";
     18echo "Time started: " . date( 'Y-m-d H:i:s', $now ) . "\n";
    1519
    1620// Get data from global GFAC DB
     
    3640
    3741if ( mysql_num_rows( $result ) == 0 )
     42{
     43//write_log( "$self: analysis read got numrows==0" );
    3844   exit();  // Nothing to do
     45}
    3946
    4047while ( list( $gfacID, $us3_db, $cluster, $status, $queue_msg, $time, $updateTime )
     
    4249{
    4350   // Checking we need to do for each entry
     51echo "us3db=$us3_db  gfid=$gfacID\n";
     52   switch ( $us3_db )
     53   {
     54      case 'Xuslims3_cauma3' :
     55      case 'Xuslims3_cauma3d' :
     56      case 'Xuslims3_HHU' :
     57      case 'Xuslims3_Uni_KN' :
     58         $serviceURL  = "http://gridfarm005.ucs.indiana.edu:9090/ogce-rest/job";
     59         break;
     60
     61      default :
     62//         $serviceURL  = "http://gridfarm005.ucs.indiana.edu:8080/ogce-rest/job";
     63         break;
     64   }
     65
     66   $awork = array();
     67   $awork = explode( "-", $gfacID );
     68   $gfacLabl = $awork[0] . "-" . $awork[1] . "-" . $awork[2];
     69   $loghdr   = $self . ":" . $gfacLabl . "...:";
     70
     71   // If entry is for Airvata/Thrift, get the true current status
     72
     73   if ( is_aira_job( $gfacID ) )
     74   {
     75      $status_in  = $status;
     76//write_log( "$loghdr status_in=$status_in" );
     77      $status     = aira_status( $gfacID, $status_in );
     78if($status != $status_in )
     79write_log( "$loghdr Set to $status from $status_in" );
     80   }
     81   else
     82   {
     83      $status_gw  = $status;
     84      $status     = get_gfac_status( $gfacID );
     85      //if ( $status == 'FINISHED' )
     86      if ( $status_gw == 'COMPLETE' )
     87         $status     = $status_gw;
     88write_log( "$loghdr non-AThrift status=$status status_gw=$status_gw" );
     89   }
    4490
    4591   // Sometimes during testing, the us3_db entry is not set
     
    4793   if ( strlen( $us3_db ) == 0 && $status != 'ERROR' )
    4894   {
    49       write_log( "$self: GFAC DB is NULL - $gfacID" );
     95      write_log( "$loghdr GFAC DB is NULL - $gfacID" );
    5096      mail_to_admin( "fail", "GFAC DB is NULL\n$gfacID" );
    5197
     
    55101
    56102      if ( ! $result2 )
    57          write_log( "$self: Query failed $query2 - " .  mysql_error( $gLink ) );
    58 
    59    }
    60 
     103         write_log( "$loghdr Query failed $query2 - " .  mysql_error( $gLink ) );
     104
     105   }
     106
     107//echo "  st=$status\n";
    61108   switch ( $status )
    62109   {
     
    76123
    77124      case "RUNNING":
     125      case "STARTED":
     126      case "STAGING":
     127      case "ACTIVE":
    78128         running( $time );
    79129         break;
     
    84134
    85135      case "DATA":
     136      case "RESULTS_GEN":
    86137         wait_data( $time );
    87138         break;
     
    91142         break;
    92143
     144      case "COMPLETED":
    93145      case "COMPLETE":
    94146         complete();
     
    101153         break;
    102154
     155      case "FINISHED":
     156      case "DONE":
     157         if ( is_aira_job( $gfacID ) )
     158         {
     159            complete();
     160         }
     161      case "PROCESSING":
    103162      default:
    104163         break;
     
    113172   global $gLink;
    114173   global $gfacID;
     174   global $loghdr;
    115175
    116176   $now = time();
     
    127187
    128188      if ( ! in_array( $job_status, array( 'SUBMITTED', 'INITIALIZED', 'PENDING' ) ) )
     189      {
     190write_log( "$loghdr submitted:job_status=$job_status" );
    129191         update_job_status( $job_status, $gfacID );
     192      }
    130193
    131194      return;
     
    150213   global $gLink;
    151214   global $gfacID;
     215   global $loghdr;
    152216
    153217   if ( ( $job_status = get_gfac_status( $gfacID ) ) === false )
     
    185249   global $gLink;
    186250   global $gfacID;
     251   global $loghdr;
    187252
    188253   $now = time();
     
    200265         return;
    201266
    202       if ( $job_status != 'ACTIVE' )
     267      if ( ! in_array( $job_status, array( 'ACTIVE', 'RUNNING', 'STARTED' ) ) )
    203268         update_job_status( $job_status, $gfacID );
    204269
     
    224289   global $gLink;
    225290   global $gfacID;
     291   global $loghdr;
    226292
    227293   if ( ( $job_status = get_gfac_status( $gfacID ) ) === false )
     
    231297      return;
    232298
    233    if ( $job_status != 'ACTIVE' )
     299   if ( ! in_array( $job_status, array( 'ACTIVE', 'RUNNING', 'STARTED' ) ) )
    234300   {
    235301      update_job_status( $job_status, $gfacID );
     
    261327   global $gLink;
    262328   global $gfacID;
     329   global $loghdr;
    263330
    264331   $now = time();
     
    308375   global $gLink;
    309376   global $gfacID;
     377   global $loghdr;
    310378
    311379   if ( ( $job_status = get_gfac_status( $gfacID ) ) === false )
     
    368436   global $gfacID;
    369437   global $us3_db;
     438   global $loghdr;
    370439
    371440   // Double check that the gfacID exists
     
    382451   list( $count ) = mysql_fetch_array( $result );
    383452
     453if ($count==0)
     454write_log( "$loghdr count = $count  gfacID = $gfacID" );
    384455   if ( $count == 0 ) return;
    385456
    386457   // Now check the us3 instance
    387458   $requestID = get_us3_data();
     459//write_log( "$loghdr requestID = $requestID  gfacID = $gfacID" );
    388460   if ( $requestID == 0 ) return;
    389461
    390    gfac_cleanup( $us3_db, $requestID, $gLink );
     462   if ( preg_match( "/US3-AIRA/i", $gfacID ) )
     463   {
     464//write_log( "$loghdr CALLING aira_cleanup()" );
     465      aira_cleanup( $us3_db, $requestID, $gLink );
     466//write_log( "$loghdr RTN FR aira_cleanup()" );
     467   }
     468   else
     469   {
     470//write_log( "$loghdr CALLING gfac_cleanup()" );
     471      gfac_cleanup( $us3_db, $requestID, $gLink );
     472   }
    391473}
    392474
     
    395477{
    396478  global $gLink;
     479  global $query;
     480  global $self;
     481  global $loghdr;
    397482 
    398483  switch ( $job_status )
     
    401486    case 'SUBMITED'    :
    402487    case 'INITIALIZED' :
     488    case 'UPDATING'    :
    403489    case 'PENDING'     :
    404490      $query   = "UPDATE analysis SET status='SUBMITTED' WHERE gfacID='$gfacID'";
     
    406492      break;
    407493
     494    case 'STARTED'     :
     495    case 'RUNNING'     :
    408496    case 'ACTIVE'      :
    409497      $query   = "UPDATE analysis SET status='RUNNING' WHERE gfacID='$gfacID'";
     
    411499      break;
    412500
     501    case 'FINISHED'    :
     502      $query   = "UPDATE analysis SET status='FINISHED' WHERE gfacID='$gfacID'";
     503      $message = "NONE";
     504      break;
     505
     506    case 'DONE'        :
     507      $query   = "UPDATE analysis SET status='DONE' WHERE gfacID='$gfacID'";
     508      $message = "NONE";
     509      break;
     510
    413511    case 'COMPLETED'   :
    414     case 'DONE'   :
     512    case 'COMPLETE'   :
    415513      $query   = "UPDATE analysis SET status='COMPLETE' WHERE gfacID='$gfacID'";
    416       $message = "Job status request reports job is COMPLETE";
     514      $message = "Job status request reports job is COMPLETED";
    417515      break;
    418516
    419     case 'DATA'   :
     517    case 'DATA'        :
    420518      $query   = "UPDATE analysis SET status='DATA' WHERE gfacID='$gfacID'";
    421519      $message = "Job status request reports job is COMPLETE, waiting for data";
     
    423521
    424522    case 'CANCELED'    :
    425     case 'CANCELLED'    :
     523    case 'CANCELLED'   :
    426524      $query   = "UPDATE analysis SET status='CANCELED' WHERE gfacID='$gfacID'";
    427525      $message = "Job status request reports job is CANCELED";
     
    434532
    435533    case 'UNKNOWN'     :
    436       // $query   = "UPDATE analysis SET status='ERROR' WHERE gfacID='$gfacID'";
     534write_log( "$loghdr job_status='UNKNOWN', reset to 'ERROR' " );
     535      $query   = "UPDATE analysis SET status='ERROR' WHERE gfacID='$gfacID'";
    437536      $message = "Job status request reports job is not in the queue";
    438537      break;
     
    440539    default            :
    441540      // We shouldn't ever get here
    442       $query   = "";
     541      $query   = "UPDATE analysis SET status='ERROR' WHERE gfacID='$gfacID'";
    443542      $message = "Job status was not recognized - $job_status";
    444       write_log( "$self - update_job_status: " .
     543      write_log( "$loghdr update_job_status: " .
    445544                 "Job status was not recognized - $job_status\n" .
    446545                 "gfacID = $gfacID\n" );
     
    451550   $result =  mysql_query( $query, $gLink );
    452551   if ( ! $result )
    453       write_log( "$self: Query failed $query - " .  mysql_error( $gLink ) );
    454 
    455    update_queue_messages( $message );
    456    update_db( $message );
     552      write_log( "$loghdr Query failed $query - " .  mysql_error( $gLink ) );
     553
     554   if ( $message != 'NONE' )
     555   {
     556      update_queue_messages( $message );
     557      update_db( $message );
     558   }
    457559}
    458560
     
    466568   global $us3_db;
    467569   global $updateTime;
     570   global $loghdr;
    468571
    469572   $us3_link = mysql_connect( $dbhost, $user, $passwd );
     
    471574   if ( ! $us3_link )
    472575   {
    473       write_log( "$self: could not connect: $dbhost, $user, $passwd" );
     576      write_log( "$loghdr could not connect: $dbhost, $user, $passwd" );
    474577      mail_to_admin( "fail", "Could not connect to $dbhost" );
    475578      return 0;
     
    481584   if ( ! $result )
    482585   {
    483       write_log( "$self: could not select DB $us3_db" );
     586      write_log( "$loghdr could not select DB $us3_db" );
    484587      mail_to_admin( "fail", "Could not select DB $us3_db, $dbhost, $user, $passwd" );
    485588      return 0;
     
    503606}
    504607
    505 // Function to determine if this is a gfac job or a local job
     608// Function to determine if this is a gfac job or not
    506609function is_gfac_job( $gfacID )
    507610{
     
    517620}
    518621
     622// Function to determine if this is an airavata/thrift job or not
     623function is_aira_job( $gfacID )
     624{
     625   global $cluster;
     626
     627   if ( preg_match( "/US3-AIRA/i", $gfacID )  &&
     628        ! preg_match( "/juropa/i", $cluster ) )
     629   {
     630      // Then it's an Airavata/Thrift job
     631      return true;
     632   }
     633
     634   return false;
     635}
     636
    519637// Function to get the current job status from GFAC
    520638function get_gfac_status( $gfacID )
    521639{
    522640   global $serviceURL;
    523 
    524    if ( ! is_gfac_job( $gfacID ) )
     641   global $self;
     642   global $loghdr;
     643   global $cluster;
     644
     645   if ( is_aira_job( $gfacID ) )
     646   {
     647      $status_ex    = getExperimentStatus( $gfacID );
     648      $gfac_status  = standard_status( $status_ex );
     649      return $gfac_status;
     650   }
     651
     652   else if ( ! is_gfac_job( $gfacID ) )
    525653      return false;
    526654
     
    534662   catch ( HttpException $e )
    535663   {
    536       write_log( "$self: Status not available - marking failed -  $gfacID" );
     664      write_log( "$loghdr Status not available - marking failed -  $gfacID" );
    537665      return 'GFAC_STATUS_UNAVAILABLE';
    538666   }
     
    547675                         'INITIALIZED',
    548676                         'PENDING',
     677                         'RUNNING',
    549678                         'ACTIVE',
     679                         'STARTED',
    550680                         'COMPLETED',
     681                         'FINISHED',
    551682                         'DONE',
    552683                         'DATA',
     684                         'RESULTS_GEN',
    553685                         'CANCELED',
    554686                         'CANCELLED',
    555687                         'FAILED',
     688                         'STAGING',
    556689                         'UNKNOWN');
    557690   if ( ! in_array( $gfac_status, $status_types ) )
     
    560693                              "Status: /$gfac_status/\n" );
    561694
     695   if ( in_array( $gfac_status, array( 'DONE', 'DATA', 'RESULTS_GEN' ) ) )
     696      $gfac_status = 'DATA';
     697
    562698   return $gfac_status;
    563699}
     
    567703{
    568704   global $serviceURL;
     705   global $self;
    569706
    570707   // Make sure it's a GFAC job and status is appropriate for this call
     
    575712   }
    576713
    577    if ( ! in_array( $job_status, array( 'DONE', 'FAILED', 'COMPLETE' ) ) )
     714   if ( ! in_array( $job_status, array( 'DONE', 'FAILED', 'COMPLETE', 'FINISHED' ) ) )
    578715   {
    579716      // Then it's not appropriate to request data
     
    637774{
    638775   global $cluster;
     776   global $self;
    639777
    640778   $system = "$cluster.uthscsa.edu";
     
    697835   // Insert message into queue_message table
    698836   $query  = "INSERT INTO queue_messages SET " .
    699              "message = '" . mysql_real_escape_string( $message, $gLink ) . "'," .
    700              "analysisID = $analysisID ";
     837             "message = '" . mysql_real_escape_string( $message, $gLink ) . "', " .
     838             "analysisID = '$analysisID' ";
    701839   $result = mysql_query( $query, $gLink );
    702840   if ( ! $result )
     
    755893   $headers  = "From: $org_name Admin<$admin_email>"     . "\n";
    756894   $headers .= "Cc: $org_name Admin<$admin_email>"       . "\n";
    757    $headers .= "Bcc: Dan Zollars<dzollars@gmail.com>"    . "\n";     // make sure
     895   $headers .= "Bcc: Gary Gorbet<gegorbet@gmail.com>"    . "\n";     // make sure
    758896
    759897   // Set the reply address
     
    781919   mail( $admin_email, $subject, $message, $headers );
    782920}
     921
     922// Convert a status string to one of the standard DB status strings
     923function standard_status( $status_in )
     924{
     925   switch ( $status_in )
     926   {  // Map variations to standard gateway status values
     927      case 'QUEUED' :
     928      case 'LAUNCHED' :
     929      case 'CREATED' :
     930      case 'VALIDATED' :
     931      case 'SCHEDULED' :
     932      case 'submitted' :
     933      case '' :
     934         $status      = 'SUBMITTED';
     935         break;
     936
     937      case 'EXECUTING' :
     938      case 'ACTIVE' :
     939      case 'running' :
     940      case 'executing' :
     941         $status      = 'RUNNING';
     942         break;
     943
     944      case 'PENDING' :
     945      case 'CANCELING' :
     946         $status      = 'UPDATING';
     947         break;
     948
     949      case 'CANCELLED' :
     950      case 'canceled' :
     951         $status      = 'CANCELED';
     952         break;
     953
     954         $status      = 'DATA';
     955         break;
     956
     957      case 'COMPLETED' :
     958      case 'completed' :
     959         $status      = 'COMPLETE';
     960         break;
     961
     962      case 'FAILED_DATA' :
     963      case 'SUBMIT_TIMEOUT' :
     964      case 'RUN_TIMEOUT' :
     965      case 'DATA_TIMEOUT' :
     966         $status      = 'FAILED';
     967         break;
     968
     969      case 'COMPLETE' :
     970         $status      = 'DONE';
     971         break;
     972
     973      case 'UNKNOWN' :
     974         $status      = 'ERROR';
     975         break;
     976
     977      // Where already standard value, retain value
     978      case 'ERROR' :
     979      case 'RUNNING' :
     980      case 'SUBMITTED' :
     981      case 'UPDATING' :
     982      case 'CANCELED' :
     983      case 'DATA' :
     984      case 'FAILED' :
     985      case 'DONE' :
     986      case 'FINISHED' :
     987      default :
     988         $status   = $status_in;
     989         break;
     990   }
     991
     992   return $status;
     993}
     994
     995function aira_status( $gfacID, $status_in )
     996{
     997   global $self;
     998   global $loghdr;
     999//echo "a_st: st_in$status_in : $gfacID\n";
     1000   //$status_gw = standard_status( $status_in );
     1001   $status_gw = $status_in;
     1002//echo "a_st:  st_db=$status_gw\n";
     1003   $status    = $status_gw;
     1004
     1005   if ( preg_match( "/US3-AIRA/i", $gfacID ) )
     1006   {
     1007      $status_ex = getExperimentStatus( $gfacID );
     1008
     1009      if ( $status_ex == 'COMPLETED' )
     1010      {  // Experiment is COMPLETED: check for 'FINISHED' or 'DONE'
     1011         if ( $status_gw == 'FINISHED'  ||  $status_gw == 'DONE' )
     1012         {  // COMPLETED + FINISHED/DONE : gateway status is now COMPLETE
     1013            $status    = 'COMPLETE';
     1014         }
     1015
     1016         else
     1017         {  // COMPLETED + NOT-FINISHED/DONE:  gw status now DONE
     1018            $status    = 'DONE';
     1019         }
     1020      }
     1021
     1022      else if ( $status_gw == 'FINISHED'  ||  $status_gw == 'DONE' )
     1023      {  // Gfac status == FINISHED/DONE:  leave as is (unless FAILED)
     1024         $status    = $status_gw;
     1025         if ( $status_ex == 'FAILED' )
     1026         {
     1027            sleep( 10 );
     1028            $status_ex = getExperimentStatus( $gfacID );
     1029            if ( $status_ex == 'FAILED' )
     1030            {
     1031               write_log( "$loghdr status still 'FAILED' after 10-second delay" );
     1032               sleep( 10 );
     1033               $status_ex = getExperimentStatus( $gfacID );
     1034               if ( $status_ex == 'FAILED' )
     1035                  write_log( "$loghdr status still 'FAILED' after 20-second delay" );
     1036               else
     1037                  write_log( "$loghdr status is $status_ex after 20-second delayed retry" );
     1038            }
     1039            write_log( "$loghdr status reset to 'COMPLETE'" );
     1040            $status    = 'COMPLETE';
     1041         }
     1042      }
     1043
     1044      else
     1045      {  // Experiment not COMPLETED/FINISHED/DONE: use experiment status
     1046         $status    = standard_status( $status_ex );
     1047      }
     1048
     1049write_log( "$loghdr status/_in/_gw/_ex=$status/$status_in/$status_gw/$status_ex" );
     1050      if ( $status != $status_gw )
     1051      {
     1052         update_job_status( $status, $gfacID );
     1053      }
     1054   }
     1055
     1056   return $status;
     1057}
     1058
    7831059?>
Note: See TracChangeset for help on using the changeset viewer.