- Timestamp:
- Aug 12, 2014, 3:55:38 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20140717/ippScripts/scripts/sc_remote_exec.pl
-
Property svn:mergeinfo
set to (toggle deleted branches)
/branches/eam_branches/ipp-20140423/ippScripts/scripts/sc_remote_exec.pl merged eligible /branches/eam_branches/ipp-20140610/ippScripts/scripts/sc_remote_exec.pl merged eligible /branches/eam_branches/ipp-ops-20130712/ippScripts/scripts/sc_remote_exec.pl merged eligible /tags/ipp-pv3-20140717/ippScripts/scripts/sc_remote_exec.pl merged eligible /trunk/ippScripts/scripts/sc_remote_exec.pl merged eligible /tags/ipp-20130712/ippScripts/scripts/sc_remote_exec.pl 35815-37063
r36844 r37242 16 16 # Hard coded values 17 17 my $DMZ_HOST = 'wtrw'; 18 my $SEC_HOST = 'mu-fe 4';18 my $SEC_HOST = 'mu-fe'; 19 19 my $IPP_PATH = '/turquoise/usr/projects/cosmo/mswarren/ipp/'; 20 20 my $remote_root = '/scratch3/watersc1/'; … … 31 31 } 32 32 33 34 33 # Options 35 my ($remote_id,$path_base,$policy,$poll,$job_id,$dbname,$verbose,$no_update,$camera); 36 34 my ($remote_id,$path_base,$policy,$poll,$force,$job_id,$dbname,$verbose,$no_update,$camera); 35 $force = 0; 36 $verbose = 0; 37 37 GetOptions( 38 38 'remote_id=s' => \$remote_id, … … 41 41 'policy=s' => \$policy, 42 42 'poll' => \$poll, 43 'force-poll' => \$force, 43 44 'camera=s' => \$camera, 44 45 'dbname=s' => \$dbname, … … 53 54 54 55 my $ipprc = PS::IPP::Config->new( $camera ) or my_die( "Unable to set up", $remote_id); 55 56 56 my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files 57 57 … … 61 61 62 62 print "passed authentication challenge.\n"; 63 64 # Phase 1.5: Grab the information about this run; 65 my $rt_cmd = "$remotetool -listrun -remote_id $remote_id "; 66 $rt_cmd .= " -dbname $dbname " if defined($dbname); 67 my ( $rt_success, $rt_error_code, $rt_full_buf, $rt_stdout_buf, $rt_stderr_buf ) = 68 run(command => $rt_cmd, verbose => $verbose); 69 unless ($rt_success) { 70 $rt_error_code = (($rt_error_code >> 8) or $PS_EXIT_PROG_ERROR); 71 &my_die("UNable to run remotetool to determine remote run status", 72 $remote_id,$rt_error_code); 73 } 74 my $rrData = $mdcParser->parse(join "", @$rt_stdout_buf) or 75 &my_die("UNable to run remotetool to determine remote run status", 76 $remote_id,$rt_error_code); 77 my $rrData2 = parse_md_list($rrData); 78 my $runData = ${ $rrData2 }[0]; # There should be only one 63 79 64 80 # These are operations we only need to do on the first call, not on subsequent poll operations. … … 92 108 my (undef,$remote_check) = uri_convert($uri_check); 93 109 my (undef,$remote_transfer)= uri_convert($uri_transfer); 94 # my $ssh_check_stdout = ssh_exec_command("${remote_root}/sc_validate_files.pl --check_list $remote_check --transfer_list $remote_transfer"); 110 95 111 my $ssh_check_stdout = ssh_exec_command("${remote_root}/sc_transfer_tool.pl --input $remote_check --fetch $remote_transfer"); 96 112 # We no longer need to parse this output, as it retrieves files itself. … … 130 146 # Poll the job status? 131 147 my $poll_count = 0; 132 my $poll_max = 5;148 my $poll_max = 1; # If it isn't finished now, it's unlikely to magically finish in the next five minutes. 133 149 my $poll_sleep = 60; 134 150 my $poll_response = 0; 135 while (($poll_count < $poll_max)&&($poll_response != 1)&&($poll_response != -1)) { 151 my $poll_word = "nothing"; 152 153 if ($force) { 154 $poll_response = 1; 155 $poll_word = "Completed"; 156 } 157 158 while (($poll_count < $poll_max)&&($poll_response != 1)&&($poll_response != -1)&&($force != 1)) { 136 159 if ($verbose) { 137 160 print "Polling code. Sleeping. $poll_count of $poll_max $poll_response\n"; … … 140 163 sleep($poll_sleep); 141 164 } 142 $poll_response= poll_job($job_id);165 ($poll_response,$poll_word) = poll_job($job_id); 143 166 144 167 if ($poll_response == 1) { # This job has completed … … 146 169 } 147 170 elsif ($poll_response == -1) { # This job has an error 148 &my_die("The job exited incorrectly.",$remote_id, $PS_EXIT_PROG_ERROR); 171 warn("The job exited incorrectly: $remote_id $job_id $poll_word. Attempting to recover what we can."); 172 $poll_response = 1; # To fool the check later into proceding 149 173 } 150 174 $poll_count++; … … 156 180 &my_die("Job hasn't completed. Ending polling.", $remote_id, 0, "run", $job_id); 157 181 } 158 # Retrieve validation summary 159 my $fault = 0; 182 160 183 161 184 # Initialize the remote side to sync things … … 165 188 my $uri_return = $path_base . ".return"; 166 189 my ($ipp_return,$remote_return) = uri_convert($uri_return); 167 scp_get($remote_return,$ipp_return); 168 # Feed teh return list into the 169 my $return_push_output = ssh_exec_command("${remote_root}/sc_transfer_tool.pl --input $remote_return"); 170 print "$return_push_output\n"; 171 172 190 # We shouldn't need to get this file. We made that file. 191 #scp_get($remote_return,$ipp_return); 192 193 # Construct list of dbinfo files we'll need to execute. 194 my @returned_files = (); 195 my @dbinfo_files = (); 196 my @dbindex = (); 197 my $iter = 0; 173 198 open(RETURN, "$ipp_return") || &my_die("Couldn't open file? $ipp_return", $remote_id,$PS_EXIT_SYS_ERROR); 174 while (<RETURN>) {199 while (<RETURN>) { 175 200 chomp; 201 push @returned_files, $_; 176 202 if ($_ =~ /dbinfo/) { 177 my $file = $_; 178 # $file =~ s/${remote_root}.tmp//; THis shouldn't be needed, as the transfer tool munges the files on that side. 179 open(DBF,"$file") || warn "Missing file $file\n"; 180 my $cmd = <DBF>; 181 chomp($cmd); 182 $cmd =~ s/-/ -/g; # This is just a safety check for missing space. 183 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 184 run(command => $cmd, verbose => $verbose); 185 unless ($success) { 186 # This shouldn't fail, but we also can't suddenly abort if something does fail. Maybe retry if this looks to be a continuing issue? 187 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 188 warn("The command that shouldn't fail has failed: $cmd $remote_id $error_code");##,$remote_id,$error_code); 203 push @dbinfo_files, $_; 204 push @dbindex, $iter; 205 } 206 $iter++; 207 208 } 209 close(RETURN); 210 print STDERR "Expect $#dbinfo_files dbinfo files\n"; 211 212 my $first = 0; 213 my $last = $#dbinfo_files; 214 my $mid = 0; 215 my $range = 20; # How wide of a chunk to look through to catch threading drops 216 my $offset = 0; # Offset to start from. 217 218 # Feed the return list into the transfer tool 219 # If this fails, we should go to an auth wait point. 220 if ($poll_word eq 'Completed') { 221 # We're complete. All files should exist on disk 222 my $iter = 0; 223 my $transfer_success = 1; 224 do { 225 $transfer_success = 1; 226 $iter++; 227 check_ssh_connection(); 228 my $return_push_output = ssh_exec_command("${remote_root}/sc_transfer_tool.pl --input $remote_return --offset $offset"); 229 my $return_push_output_print = join "\n", @{ $return_push_output }; 230 if ($return_push_output_print =~ /exited with value 255/) { $transfer_success = 0; } 231 print "$return_push_output_print\n"; 232 } while (($transfer_success != 1) && ($iter < 10)); # Try harder; 233 } 234 else { 235 # Just try and fetch things, because we didn't complete correctly, it seems. 236 my $return_push_output = ssh_exec_command("${remote_root}/sc_transfer_tool.pl --input $remote_return --offset $offset"); 237 my $return_push_output_print = join "\n", @{ $return_push_output }; 238 print "$return_push_output_print\n"; 239 } 240 241 foreach my $file (@dbinfo_files) { 242 open(DBF,"$file") || warn "Missing file $file\n"; 243 my $cmd = <DBF>; 244 close(DBF); 245 chomp($cmd); 246 # print STDERR "$file $cmd\n"; 247 $cmd =~ s/-/ -/g; # This is just a safety check for missing space. 248 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 249 run(command => $cmd, verbose => $verbose); 250 unless ($success) { 251 252 # This shouldn't fail, but we also can't suddenly abort if something does fail. 253 # Now we're going to drop the component that owns this dbinfo, which should force a retry. 254 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 255 warn("The command that shouldn't fail has failed: $file $cmd $remote_id $error_code"); 256 if ($poll_word ne 'Completed') { # If the job claims it completed, then we're fighting the network. 257 drop_component($remote_id,$cmd,$file); 189 258 } 190 close(DBF); 191 } 192 } 193 close(RETURN); 259 } 260 261 } 194 262 195 263 # We're done, so set the state and exit. 196 264 &my_die("Finished",$remote_id,0,"full"); 197 198 265 199 266 … … 209 276 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 210 277 &my_die("Authorization check failed.",$remote_id,0,'auth'); 211 212 # my $update_command = "$remotetool -updaterun -remote_id $remote_id ";213 # $update_command .= " -set_state auth ";214 # $update_command .= " -dbname $dbname " if defined $dbname;215 # system($update_command);216 # exit(0); # This isn't an error. It's a state we monitor and move to automatically.217 278 } 218 279 } … … 250 311 sub ssh_exec_command { 251 312 my $cmd = shift; 252 $cmd = "$ssh $DMZ_HOST ssh ${SEC_HOST} $cmd"; 313 $cmd = "$ssh $DMZ_HOST ssh ${SEC_HOST} $cmd"; 314 print "EXEC: $cmd\n"; 253 315 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 254 316 run(command => $cmd, verbose => $verbose); 255 317 unless ($success) { 256 318 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 319 # If we failed, see if we failed due to authorization. 320 check_ssh_connection(); 257 321 &my_die("Failed to execute command: >>$cmd<<"); 258 322 } … … 266 330 267 331 if ($response =~ /State: Running/) { 268 return(0 );332 return(0,"Running"); 269 333 } 270 334 elsif ($response =~ /State: Completed/) { 271 return(1 );335 return(1,"Completed"); 272 336 } 273 337 elsif ($response =~ /State: Idle/) { 274 return(-2 );338 return(-2,"Idle"); 275 339 } 276 340 else { 277 return(-1); 341 my $response_word = $response; 342 $response_word =~ s/.*State: //; 343 $response_word =~ s/\n.*//; 344 return(-1,$response_word); 278 345 } 279 346 } … … 324 391 return($local_uri); 325 392 } 393 394 sub drop_component { 395 my $remote_id = shift; 396 my $cmd = shift; 397 my $file = shift; 398 399 if ($cmd eq '') { 400 # Zero byte file. This dbinfo was never constructed properly. 401 402 # Steal the stage_id from the filename. This isn't something I'm happy about. 403 my $stage = $runData->{stage}; 404 my $stage_id = $file; 405 if ($stage eq 'chip') { 406 $stage_id =~ s/^.*ch\.//; 407 } 408 elsif ($stage eq 'camera') { 409 $stage_id =~ s/^.*cm\.//; 410 } 411 elsif ($stage eq 'warp') { 412 $stage_id =~ s/^.*wrp\.//; 413 } 414 elsif ($stage eq 'stack') { 415 $stage_id =~ s/^.*stk\.//; 416 } 417 $stage_id =~ s/\..*$//; 418 419 # Drop this from the database 420 my $drop_cmd = "$remotetool -dropcomponent -remote_id $remote_id -stage_id $stage_id "; 421 $drop_cmd .= " -dbname $dbname " if defined($dbname); 422 system($drop_cmd); 423 } 424 425 } 426 326 427 sub my_die { 327 428 my $msg = shift; … … 347 448 } 348 449 349 # I don't think I need this anymore, but I don't want to burn it until I"m sure.350 351 # exit(1);352 # # Read this as a metadata object353 # my $ssh_exec_stdout = ssh_exec_command("sc_validate_processing.pl ${path_base}.out");354 # my $retrieveData = $mdcParser->parse(join "", @$ssh_exec_stdout);355 # my $retrieveData2= parse_md_list($retrieveData);356 357 # foreach my $retrieveEntry (@$retrieveData2) {358 # my $process_fault = $retrieveEntry->{fault};359 # my $dbcommand = $retrieveEntry->{dbcommand};360 # my $filelist = $retrieveEntry->{filelist};361 362 # scp_get("${filelist}",${filelist});363 # open(FL,${filelist});364 # while(<FL>) {365 # chomp;366 # my $f = $_;367 # scp_get("${f}",$f);368 # }369 # close(FL);370 371 # my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =372 # run(command => $dbcommand, verbose => $verbose);373 # unless ($success) {374 # $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);375 # &my_die("The database command returned did not execute correctly. $dbcommand $process_fault",376 # $remote_id,$error_code);377 # }378 379 # if ($process_fault != 0) {380 # $fault = 1;381 # }382 # }383 384 # if (($policy ne 'ignore')&&($fault != 0)) {385 # &my_die("This job exited without all components finishing successfully. Halting.",386 # $remote_id,$fault,"halt");387 # }388 # else {389 # print "This job exited without all components finishing successfully. $fault\n" if $fault;390 # &my_die("This job finished. Setting remote job to full.",391 # $remote_id,0,"full");392 # }393 394 # Promote to finished.395 #&my_die(); # Not really, but I don't have the tool interface finished, so these are all just placeholders.396 450 # Quick review: 397 451 # new -> pending -> run -> full -
Property svn:mergeinfo
set to (toggle deleted branches)
Note:
See TracChangeset
for help on using the changeset viewer.
