Changeset 25 for trunk/cleanup.php


Ignore:
Timestamp:
Jan 13, 2017, 1:30:29 PM (8 years ago)
Author:
gegorbet
Message:

merge us3iab/airavata gridctl code

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/cleanup.php

    r24 r25  
    1717function aira_cleanup( $us3_db, $reqID, $gfac_link )
    1818{
     19   global $org_domain;
    1920   global $dbhost;
    2021   global $user;
     
    141142   list( $status, $cluster, $id ) = mysql_fetch_array( $result );
    142143
    143    if ( $cluster == 'bcf-local'  || $cluster == 'alamo-local' )
     144   $is_us3iab  = preg_match( "/us3iab/", $cluster );
     145   $is_local   = preg_match( "/-local/", $cluster );
     146
     147   if ( $is_us3iab  ||  $is_local )
    144148   {
    145149         $clushost = $cluster;
     
    191195   $fn_tarfile = "analysis-results.tar";
    192196   $num_try    = 0;
     197$len1 = strlen( $fn_tarfile );
     198write_log( "$me: fn_tarfile=$fn_tarfile  len(tar)=$len1" );
    193199   while ( ! file_exists( $fn_tarfile ) && $num_try < 3 )
    194200   {
    195201      sleep( 10 );
    196202      $num_try++;
     203write_log( "$me:  tar-exists: num_try=$num_try" );
    197204   }
    198205
     
    200207   foreach ( $ofiles as $ofile )
    201208   {
    202       if ( preg_match( "/.*stderr$/", $ofile ) )
     209      if ( preg_match( "/^" . $gfacID . ".*stderr$/", $ofile ) )
    203210         $fn_stderr  = $ofile;
    204       if ( preg_match( "/.*stdout$/", $ofile ) )
     211      if ( preg_match( "/^" . $gfacID . ".*stdout$/", $ofile ) )
    205212         $fn_stdout  = $ofile;
    206213//write_log( "$me:    ofile=$ofile" );
     
    654661   global $editXMLFilename;
    655662   global $stdout;
     663   global $org_domain;
    656664
    657665global $me;
     
    697705   $limshost    = $dbhost;
    698706   if ( $limshost == 'localhost' )
     707   {
    699708      $limshost    = gethostname();
     709      if ( ! preg_match( "/\./", $limshost ) )
     710         $limshost    = $limshost . $org_domain;
     711   }
    700712
    701713   // Parse the editXMLFilename
     
    841853   global $db;
    842854   global $status;
    843 
    844    // Figure out local working directory
    845    if ( ! is_dir( "$work/$gfacID" ) ) mkdir( "$work/$gfacID", 0770 );
    846    $pwd = chdir( "$work/$gfacID" );
     855   $is_us3iab  = preg_match( "/us3iab/", $cluster );
    847856
    848857   // Figure out remote directory
    849858   $remoteDir = sprintf( "$work_remote/$db-%06d", $requestID );
     859write_log( "$me: is_us3iab=$is_us3iab  remoteDir=$remoteDir" );
    850860
    851861   // Get stdout, stderr, output/analysis-results.tar
    852862   $output = array();
    853 //   $cmd = "scp us3@$cluster.uthscsa.edu:$remoteDir/stdout . 2>&1";
    854 //
    855 //   exec( $cmd, $output, $stat );
    856 //   if ( $stat != 0 )
    857 //      write_log( "$me: Bad exec:\n$cmd\n" . implode( "\n", $output ) );
    858 //     
    859 //   $cmd = "scp us3@$cluster.uthscsa.edu:$remoteDir/stderr . 2>&1";
    860 //   exec( $cmd, $output, $stat );
    861 //   if ( $stat != 0 )
    862 //      write_log( "$me: Bad exec:\n$cmd\n" . implode( "\n", $output ) );
    863 
    864    $cmd = "scp us3@$cluster.uthscsa.edu:$remoteDir/output/analysis-results.tar . 2>&1";
    865    exec( $cmd, $output, $stat );
    866    if ( $stat != 0 )
    867       write_log( "$me: Bad exec:\n$cmd\n" . implode( "\n", $output ) );
    868 
    869    $cmd = "scp us3@$cluster.uthscsa.edu:$remoteDir/stdout . 2>&1";
    870    exec( $cmd, $output, $stat );
    871    if ( $stat != 0 )
    872    {
    873       write_log( "$me: Bad exec:\n$cmd\n" . implode( "\n", $output ) );
    874       sleep( 10 );
    875       write_log( "$me: RETRY" );
     863
     864   if ( $is_us3iab == 0 )
     865   {
     866      // Figure out local working directory
     867      if ( ! is_dir( "$work/$gfacID" ) ) mkdir( "$work/$gfacID", 0770 );
     868      $pwd = chdir( "$work/$gfacID" );
     869
     870      $cmd = "scp us3@$cluster.uthscsa.edu:$remoteDir/output/analysis-results.tar . 2>&1";
     871
    876872      exec( $cmd, $output, $stat );
    877       if ( $stat != 0 ) 
     873      if ( $stat != 0 )
    878874         write_log( "$me: Bad exec:\n$cmd\n" . implode( "\n", $output ) );
    879    }
    880      
    881    $cmd = "scp us3@$cluster.uthscsa.edu:$remoteDir/stderr . 2>&1";
    882    exec( $cmd, $output, $stat );
    883    if ( $stat != 0 )
    884    {
    885       write_log( "$me: Bad exec:\n$cmd\n" . implode( "\n", $output ) );
    886       sleep( 10 );
    887       write_log( "$me: RETRY" );
     875
     876      $cmd = "scp us3@$cluster.uthscsa.edu:$remoteDir/stdout . 2>&1";
     877
    888878      exec( $cmd, $output, $stat );
    889       if ( $stat != 0 )
     879      if ( $stat != 0 )
     880      {
    890881         write_log( "$me: Bad exec:\n$cmd\n" . implode( "\n", $output ) );
    891    }
     882         sleep( 10 );
     883         write_log( "$me: RETRY" );
     884         exec( $cmd, $output, $stat );
     885         if ( $stat != 0 )
     886            write_log( "$me: Bad exec:\n$cmd\n" . implode( "\n", $output ) );
     887      }
     888
     889      $cmd = "scp us3@$cluster.uthscsa.edu:$remoteDir/stderr . 2>&1";
     890
     891      exec( $cmd, $output, $stat );
     892      if ( $stat != 0 )
     893      {
     894         write_log( "$me: Bad exec:\n$cmd\n" . implode( "\n", $output ) );
     895         sleep( 10 );
     896         write_log( "$me: RETRY" );
     897         exec( $cmd, $output, $stat );
     898         if ( $stat != 0 )
     899            write_log( "$me: Bad exec:\n$cmd\n" . implode( "\n", $output ) );
     900      }
     901   }
     902   else
     903   {
     904      $pwd = chdir( "$remoteDir" );
     905write_log( "$me: IS US3IAB: pwd=$pwd $remoteDir");
     906   }
     907
    892908
    893909   // Write the files to gfacDB
    894910
    895    if ( file_exists( "stderr" ) ) $stderr  = file_get_contents( "stderr" );
     911   if ( file_exists( "stderr"  ) )
     912   {  // Filter stderr to not have libnnls debug lines
     913      exec( "mv stderr stderr+nnls", $output, $stat );
     914      exec( "grep -vi nnls stderr+nnls >stderr", $output, $stat );
     915      $stderr  = file_get_contents( "stderr" );
     916   }
     917   else
     918      $stderr  = "";
    896919   if ( file_exists( "stdout" ) ) $stdout  = file_get_contents( "stdout" );
    897    if ( file_exists( "analysis-results.tar" ) )
    898       $tarfile = file_get_contents( "analysis-results.tar" );
    899 
     920   $fn1_tarfile = "analysis-results.tar";
     921   $fn2_tarfile = "output/" . $fn1_tarfile;
     922   if ( file_exists( $fn1_tarfile ) )
     923      $tarfile = file_get_contents( $fn1_tarfile );
     924   else if ( file_exists( $fn2_tarfile ) )
     925      $tarfile = file_get_contents( $fn2_tarfile );
     926
     927   $lense = strlen( $stderr );
     928   if ( $lense > 1000000 )
     929   { // Replace exceptionally large stderr with smaller version
     930      exec( "mv stderr stderr-orig", $output, $stat );
     931      exec( "head -n 5000 stderr-orig >stderr-h", $output, $stat );
     932      exec( "tail -n 5000 stderr-orig >stderr-t", $output, $stat );
     933      exec( "cat stderr-h stderr-t >stderr", $output, $stat );
     934      $stderr  = file_get_contents( "stderr" );
     935   }
     936$lent = strlen( $tarfile );
     937write_log( "$me: tarfile size: $lent");
     938$lene = strlen( $stderr );
     939write_log( "$me: stderr size: $lene  (was $lense)");
     940$leno = strlen( $stdout );
     941write_log( "$me: stdout size: $leno");
     942$estarf=mysql_real_escape_string($tarfile,$gfac_link);
     943$lenf = strlen($estarf);
     944write_log( "$me: es-tarfile size: $lenf");
     945$esstdo=mysql_real_escape_string($stdout,$gfac_link);
     946$leno = strlen($esstdo);
     947write_log( "$me: es-stdout size: $leno");
     948$esstde=mysql_real_escape_string($stderr,$gfac_link);
     949$lene = strlen($esstde);
     950write_log( "$me: es-stderr size: $lene");
    900951   $query = "UPDATE analysis SET " .
    901952            "stderr='"  . mysql_real_escape_string( $stderr,  $gfac_link ) . "'," .
Note: See TracChangeset for help on using the changeset viewer.