- Timestamp:
- Sep 19, 2014, 4:05:27 PM (12 years ago)
- Location:
- branches/eam_branches/ps2-tc3-20130727
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
ippScripts/scripts/sc_remote_exec.pl (modified) (20 diffs, 1 prop)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ps2-tc3-20130727
- Property svn:mergeinfo changed
-
branches/eam_branches/ps2-tc3-20130727/ippScripts/scripts/sc_remote_exec.pl
- Property svn:mergeinfo set to (toggle deleted branches)
r36680 r37403 24 24 my $ssh = can_run('ssh') or (warn "Can't find ssh" and $missing_tools = 1); 25 25 my $scp = can_run('scp') or (warn "Can't find scp" and $missing_tools = 1); 26 my $remotetool = can_run(' echo') or (warn "Can't find remotetool" and $missing_tools = 1);26 my $remotetool = can_run('remotetool') or (warn "Can't find remotetool" and $missing_tools = 1); 27 27 28 28 if ($missing_tools) { … … 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. … … 72 88 my $uri_check = $path_base . ".check"; 73 89 my $uri_config = $path_base . ".config"; 90 my $uri_generate= $path_base . ".generate"; 91 my $uri_return = $path_base . ".return"; 74 92 75 93 my $disk_command = $ipprc->file_resolve($uri_command); … … 77 95 my $disk_check = $ipprc->file_resolve($uri_check); 78 96 my $disk_config = $ipprc->file_resolve($uri_config); 97 my $disk_generate= $ipprc->file_resolve($uri_generate); 98 my $disk_return = $ipprc->file_resolve($uri_return); 79 99 80 100 scp_put($disk_command,uri_local_to_remote($uri_command)); … … 82 102 scp_put($disk_check,uri_local_to_remote($uri_check)); 83 103 scp_put($disk_config,uri_local_to_remote($uri_config)); 104 scp_put($disk_generate,uri_local_to_remote($uri_generate)); 105 scp_put($disk_return, uri_local_to_remote($uri_return)); 84 106 85 107 # Run check command 86 108 my (undef,$remote_check) = uri_convert($uri_check); 87 my $ssh_check_stdout = ssh_exec_command("${remote_root}/sc_validate_files.pl --check_list $remote_check"); 88 89 # Parse stdout for files to transfer. 90 if ($#{ $ssh_check_stdout } != -1) { # There were files not found. 91 # Someone was missing. Use the check and transfer lists to identify the local version, and send it. 92 # What was missing? 93 my %missing_files = (); 94 foreach my $l (split /\n/, (join '', @$ssh_check_stdout)) { 95 print "Missing!: $l\n"; 96 $missing_files{$l} = 1; 97 } 98 99 # Do we have that file? 100 my @check_files = (); 101 open(CHECK,$disk_check); 102 while(<CHECK>) { 103 chomp; 104 push @check_files, $_; 105 } 106 close(CHECK); 107 108 my @trans_files = (); 109 open(TRANS,$disk_transfer); 110 while(<TRANS>) { 111 chomp; 112 push @trans_files, $_; 113 } 114 close(TRANS); 115 116 if ($#trans_files != $#check_files) { &my_die("The transfer file list and check file list are different sizes", 117 $remote_id,$PS_EXIT_DATA_ERROR); } 118 119 for (my $i = 0; $i <= $#check_files; $i++) { 120 if (exists($missing_files{$check_files[$i]})) { 121 if ($trans_files[$i] ne "REMOTE_ONLY") { 122 scp_put($trans_files[$i],"$check_files[$i]"); 123 } 124 else { 125 &my_die("There is a file that should be there, but the file isn't there, and I don't have a copy of that file here. The file is: $check_files[$i]", 126 $remote_id,$PS_EXIT_DATA_ERROR); # This seems a bit harsh. 127 } 128 } 129 } 130 } 131 109 my (undef,$remote_transfer)= uri_convert($uri_transfer); 110 111 my $ssh_check_stdout = ssh_exec_command("${remote_root}/sc_transfer_tool.pl --input $remote_check --fetch $remote_transfer"); 112 # We no longer need to parse this output, as it retrieves files itself. 113 foreach my $l (split /\n/, (join '', @$ssh_check_stdout)) { 114 print "$l\n"; 115 } 132 116 133 117 # Run real command … … 147 131 my $command = "$remotetool -updaterun -remote_id $remote_id "; 148 132 $command .= " -set_state run "; 149 $command .= " - set_job_id $job_id ";133 $command .= " -job_id $job_id "; 150 134 $command .= " -dbname $dbname " if defined $dbname; 151 135 152 136 system($command); 153 137 154 } 138 } # End of exec phase 155 139 156 140 # Check that we have a valid job_id, either from the command line, or from the msub command. … … 162 146 # Poll the job status? 163 147 my $poll_count = 0; 164 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. 165 149 my $poll_sleep = 60; 166 150 my $poll_response = 0; 167 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)) { 168 159 if ($verbose) { 169 160 print "Polling code. Sleeping. $poll_count of $poll_max $poll_response\n"; … … 172 163 sleep($poll_sleep); 173 164 } 174 $poll_response= poll_job($job_id);165 ($poll_response,$poll_word) = poll_job($job_id); 175 166 176 167 if ($poll_response == 1) { # This job has completed … … 178 169 } 179 170 elsif ($poll_response == -1) { # This job has an error 180 &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 181 173 } 182 174 $poll_count++; … … 185 177 print "Stopped Polling code. $poll_count of $poll_max $poll_response\n"; 186 178 } 187 # Retrieve validation summary 188 my $fault = 0; 189 190 exit(1); 191 # Read this as a metadata object 192 my $ssh_exec_stdout = ssh_exec_command("sc_validate_processing.pl ${path_base}.out"); 193 my $retrieveData = $mdcParser->parse(join "", @$ssh_exec_stdout); 194 my $retrieveData2= parse_md_list($retrieveData); 195 196 foreach my $retrieveEntry (@$retrieveData2) { 197 my $process_fault = $retrieveEntry->{fault}; 198 my $dbcommand = $retrieveEntry->{dbcommand}; 199 my $filelist = $retrieveEntry->{filelist}; 200 201 scp_get("${filelist}",${filelist}); 202 open(FL,${filelist}); 203 while(<FL>) { 204 chomp; 205 my $f = $_; 206 scp_get("${f}",$f); 207 } 208 close(FL); 209 179 if ($poll_response != 1) { 180 &my_die("Job hasn't completed. Ending polling.", $remote_id, 0, "run", $job_id); 181 } 182 183 184 # Initialize the remote side to sync things 185 186 # Once sync completes, execute all the database commands 187 # Grab the return list 188 my $uri_return = $path_base . ".return"; 189 my ($ipp_return,$remote_return) = uri_convert($uri_return); 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; 198 open(RETURN, "$ipp_return") || &my_die("Couldn't open file? $ipp_return", $remote_id,$PS_EXIT_SYS_ERROR); 199 while (<RETURN>) { 200 chomp; 201 push @returned_files, $_; 202 if ($_ =~ /dbinfo/) { 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. 210 248 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 211 run(command => $ dbcommand, verbose => $verbose);249 run(command => $cmd, verbose => $verbose); 212 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. 213 254 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 214 &my_die("The database command returned did not execute correctly. $dbcommand $process_fault", 215 $remote_id,$error_code); 216 } 217 218 if ($process_fault != 0) { 219 $fault = 1; 220 } 221 } 222 223 if (($policy ne 'ignore')&&($fault != 0)) { 224 &my_die("This job exited without all components finishing successfully. Halting.", 225 $remote_id,$fault,"halt"); 226 } 227 else { 228 print "This job exited without all components finishing successfully. $fault\n" if $fault; 229 &my_die("This job finished. Setting remote job to full.", 230 $remote_id,0,"full"); 231 } 232 233 # Promote to finished. 234 &my_die(); # Not really, but I don't have the tool interface finished, so these are all just placeholders. 235 # Quick review: 236 # new -> pending -> run -> full 237 # auth 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); 258 } 259 } 260 261 } 262 263 # We're done, so set the state and exit. 264 &my_die("Finished",$remote_id,0,"full"); 265 238 266 239 267 # END PROGRAM … … 248 276 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 249 277 &my_die("Authorization check failed.",$remote_id,0,'auth'); 250 251 # my $update_command = "$remotetool -updaterun -remote_id $remote_id ";252 # $update_command .= " -set_state auth ";253 # $update_command .= " -dbname $dbname " if defined $dbname;254 # system($update_command);255 # exit(0); # This isn't an error. It's a state we monitor and move to automatically.256 278 } 257 279 } … … 289 311 sub ssh_exec_command { 290 312 my $cmd = shift; 291 $cmd = "$ssh $DMZ_HOST ssh ${SEC_HOST} $cmd"; 313 $cmd = "$ssh $DMZ_HOST ssh ${SEC_HOST} $cmd"; 314 print "EXEC: $cmd\n"; 292 315 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 293 316 run(command => $cmd, verbose => $verbose); 294 317 unless ($success) { 295 318 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 296 &my_die(); 319 # If we failed, see if we failed due to authorization. 320 check_ssh_connection(); 321 &my_die("Failed to execute command: >>$cmd<<"); 297 322 } 298 323 return ($stdout_buf); … … 305 330 306 331 if ($response =~ /State: Running/) { 307 return(0 );332 return(0,"Running"); 308 333 } 309 334 elsif ($response =~ /State: Completed/) { 310 return(1 );335 return(1,"Completed"); 311 336 } 312 337 elsif ($response =~ /State: Idle/) { 313 return(-2 );338 return(-2,"Idle"); 314 339 } 315 340 else { 316 return(-1); 341 my $response_word = $response; 342 $response_word =~ s/.*State: //; 343 $response_word =~ s/\n.*//; 344 return(-1,$response_word); 317 345 } 318 346 } … … 363 391 return($local_uri); 364 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 365 427 sub my_die { 366 428 my $msg = shift; … … 368 430 my $exit_code = shift; 369 431 my $exit_state = shift; 370 432 my $jobid = shift; 371 433 $exit_code = $PS_EXIT_PROG_ERROR unless defined $exit_code; 372 434 … … 374 436 375 437 if (defined $id and not $no_update) { 376 my $command = "$remotetool -updaterun - stage_id $id";438 my $command = "$remotetool -updaterun -remote_id $id"; 377 439 $command .= " -fault $exit_code " if defined $exit_code; 440 $command .= " -job_id $job_id " if defined $jobid; 378 441 $command .= " -set_state $exit_state " if defined $exit_state; 379 442 $command .= " -dbname $dbname " if defined $dbname; … … 384 447 exit($exit_code); 385 448 } 449 450 # Quick review: 451 # new -> pending -> run -> full 452 # auth
Note:
See TracChangeset
for help on using the changeset viewer.
