Index: /tags/ipp-pv3-20140717/ippScripts/scripts/sc_remote_exec.pl
===================================================================
--- /tags/ipp-pv3-20140717/ippScripts/scripts/sc_remote_exec.pl	(revision 37288)
+++ /tags/ipp-pv3-20140717/ippScripts/scripts/sc_remote_exec.pl	(revision 37289)
@@ -32,14 +32,9 @@
 
 # Options
-my ($remote_id,$path_base,$policy,$poll,$force,$job_id,$dbname,$verbose,$no_update,$camera);
-$force = 0;
+my ($remote_id,$path_base,$dbname,$verbose,$no_update,$camera);
 $verbose = 0;
 GetOptions(
     'remote_id=s'   => \$remote_id,
-    'job_id=s'      => \$job_id,
     'path_base=s'   => \$path_base,
-    'policy=s'      => \$policy,
-    'poll'          => \$poll,
-    'force-poll'    => \$force,
     'camera=s'      => \$camera,
     'dbname=s'      => \$dbname,
@@ -78,194 +73,60 @@
 my $runData = ${ $rrData2 }[0]; # There should be only one
 
-# These are operations we only need to do on the first call, not on subsequent poll operations.
-unless ($poll) {
+my ($remote_path) = uri_convert($path_base);
+print "REMOTE PATH: $remote_path\n";
+
 # Phase 2: Ensure files are in place:
 # Copy command files
-    my @files = ();
-
-    my $uri_command = $path_base . ".cmd";
-    my $uri_transfer= $path_base . ".transfer";
-    my $uri_check   = $path_base . ".check";
-    my $uri_config  = $path_base . ".config";
-    my $uri_generate= $path_base . ".generate";
-    my $uri_return  = $path_base . ".return";
-
-    my $disk_command = $ipprc->file_resolve($uri_command);
-    my $disk_transfer= $ipprc->file_resolve($uri_transfer);
-    my $disk_check   = $ipprc->file_resolve($uri_check);
-    my $disk_config  = $ipprc->file_resolve($uri_config);
-    my $disk_generate= $ipprc->file_resolve($uri_generate);
-    my $disk_return  = $ipprc->file_resolve($uri_return);
-
-    scp_put($disk_command,uri_local_to_remote($uri_command));
-    scp_put($disk_transfer,uri_local_to_remote($uri_transfer));
-    scp_put($disk_check,uri_local_to_remote($uri_check));
-    scp_put($disk_config,uri_local_to_remote($uri_config));
-    scp_put($disk_generate,uri_local_to_remote($uri_generate));
-    scp_put($disk_return, uri_local_to_remote($uri_return));
+my @files = ();
+
+my $uri_command = $path_base . ".cmd";
+my $uri_transfer= $path_base . ".transfer";
+my $uri_check   = $path_base . ".check";
+my $uri_config  = $path_base . ".config";
+my $uri_generate= $path_base . ".generate";
+my $uri_return  = $path_base . ".return";
+
+my $disk_command = $ipprc->file_resolve($uri_command);
+my $disk_transfer= $ipprc->file_resolve($uri_transfer);
+my $disk_check   = $ipprc->file_resolve($uri_check);
+my $disk_config  = $ipprc->file_resolve($uri_config);
+my $disk_generate= $ipprc->file_resolve($uri_generate);
+my $disk_return  = $ipprc->file_resolve($uri_return);
+
+scp_put($disk_command,uri_local_to_remote($uri_command));
+scp_put($disk_transfer,uri_local_to_remote($uri_transfer));
+scp_put($disk_check,uri_local_to_remote($uri_check));
+scp_put($disk_config,uri_local_to_remote($uri_config));
+scp_put($disk_generate,uri_local_to_remote($uri_generate));
+scp_put($disk_return, uri_local_to_remote($uri_return));
 
 # Run check command
-    my (undef,$remote_check) = uri_convert($uri_check);
-    my (undef,$remote_transfer)= uri_convert($uri_transfer);
-
-    my $ssh_check_stdout = ssh_exec_command("${remote_root}/sc_transfer_tool.pl --input $remote_check --fetch $remote_transfer");
-    # We no longer need to parse this output, as it retrieves files itself.
-    foreach my $l (split /\n/, (join '', @$ssh_check_stdout)) {
-        print "$l\n";
-    }
+# my (undef,$remote_check) = uri_convert($uri_check);
+# my (undef,$remote_transfer)= uri_convert($uri_transfer);
+
+my $ssh_check_stdout = ssh_exec_command("${remote_root}/sc_transfer_tool.pl --input $remote_path --fetch");
+
+# We no longer need to parse this output, as it retrieves files itself.
+foreach my $l (split /\n/, (join '', @$ssh_check_stdout)) {
+    print "$l\n";
+}
 
 # Run real command
-    my (undef,$remote_command) = uri_convert($uri_command);
-    my $ssh_exec_stdout = ssh_exec_command("msub -V $remote_command");
-    if ($#{ $ssh_exec_stdout } != -1) { # Parse the output
-        $job_id = ${ $ssh_exec_stdout }[0];
-        chomp($job_id);
-        $job_id =~ s/\s+//g;
-    }
-
-    unless(defined($job_id)) { # If we don't have a job_id from this command, it didn't run correctly.
-        &my_die("No job_id returned.  Sorry.",$remote_id,$PS_EXIT_PROG_ERROR);
-    }
-
-    # Notify the database that this entry is currently running.
-    my $command = "$remotetool -updaterun -remote_id $remote_id ";
-    $command .= " -set_state run ";
-    $command .= " -job_id $job_id ";
-    $command .= " -dbname $dbname " if defined $dbname;
-
-    print STDERR "$command\n";
-    system($command);
-
-} # End of exec phase
-
-# Check that we have a valid job_id, either from the command line, or from the msub command.
+my (undef,$remote_command) = uri_convert($uri_command);
+my $ssh_exec_stdout = ssh_exec_command("msub -V $remote_command");
+if ($#{ $ssh_exec_stdout } != -1) { # Parse the output
+    $job_id = ${ $ssh_exec_stdout }[0];
+    chomp($job_id);
+    $job_id =~ s/\s+//g;
+}
+
 unless(defined($job_id)) { # If we don't have a job_id from this command, it didn't run correctly.
     &my_die("No job_id returned.  Sorry.",$remote_id,$PS_EXIT_PROG_ERROR);
 }
 
-
-# Poll the job status?
-my $poll_count = 0;
-my $poll_max   = 1; # If it isn't finished now, it's unlikely to magically finish in the next five minutes.
-my $poll_sleep = 60;
-my $poll_response = 0;
-my $poll_word  = "nothing";
-
-if ($force) {
-    $poll_response = 1;
-    $poll_word     = "Completed";
-}
-
-while (($poll_count < $poll_max)&&($poll_response != 1)&&($poll_response != -1)&&($force != 1)) {
-    if ($verbose) {
-        print "Polling code.  Sleeping.  $poll_count of $poll_max $poll_response\n";
-    }
-    unless ($poll_count == 0) {
-        sleep($poll_sleep);
-    }
-    ($poll_response,$poll_word) = poll_job($job_id);
-
-    if ($poll_response == 1) { # This job has completed
-        last;
-    }
-    elsif ($poll_response == -1) { # This job has an error
-        warn("The job exited incorrectly: $remote_id $job_id $poll_word.  Attempting to recover what we can.");
-        $poll_response = 1; # To fool the check later into proceding
-    }
-    $poll_count++;
-}
-if ($verbose) {
-    print "Stopped Polling code.  $poll_count of $poll_max $poll_response\n";
-}
-if ($poll_response != 1) {
-    &my_die("Job hasn't completed.  Ending polling.", $remote_id, 0, "run", $job_id);
-}
-
-
-# Initialize the remote side to sync things
-
-# Once sync completes, execute all the database commands
-# Grab the return list
-my $uri_return  = $path_base . ".return";
-my ($ipp_return,$remote_return) = uri_convert($uri_return);
-# We shouldn't need to get this file.  We made that file.
-#scp_get($remote_return,$ipp_return);
-
-# Construct list of dbinfo files we'll need to execute.
-my @returned_files = ();
-my @dbinfo_files   = ();
-my @dbindex        = ();
-my $iter           = 0;
-open(RETURN,   "$ipp_return") || &my_die("Couldn't open file? $ipp_return", $remote_id,$PS_EXIT_SYS_ERROR);
-while (<RETURN>) {
-    chomp;
-    push @returned_files, $_;
-    if ($_ =~ /dbinfo/) {
-        push @dbinfo_files, $_;
-        push @dbindex, $iter;
-    }
-    $iter++;
-
-}
-close(RETURN);
-print STDERR "Expect $#dbinfo_files dbinfo files\n";
-
-my $first = 0;
-my $last  = $#dbinfo_files;
-my $mid   = 0;
-my $range = 20;  # How wide of a chunk to look through to catch threading drops
-my $offset = 0;  # Offset to start from.
-
-# Feed the return list into the transfer tool
-# If this fails, we should go to an auth wait point.
-if ($poll_word eq 'Completed') {
-    # We're complete.  All files should exist on disk
-    my $iter = 0;
-    my $transfer_success = 1;
-    do {
-        $transfer_success = 1;
-        $iter++;
-        check_ssh_connection();
-        my $return_push_output = ssh_exec_command("${remote_root}/sc_transfer_tool.pl --input $remote_return --offset $offset");
-        my $return_push_output_print = join "\n", @{ $return_push_output };
-        if ($return_push_output_print =~ /exited with value 255/) { $transfer_success = 0; }
-        print "$return_push_output_print\n";
-    } while (($transfer_success != 1) &&  ($iter < 10));  # Try harder;
-}
-else {
-    # Just try and fetch things, because we didn't complete correctly, it seems.
-    my $return_push_output = ssh_exec_command("${remote_root}/sc_transfer_tool.pl --input $remote_return --offset $offset");
-    my $return_push_output_print = join "\n", @{ $return_push_output };
-    print "$return_push_output_print\n";
-}
-
-foreach my $file (@dbinfo_files) {
-    open(DBF,"$file") || warn "Missing file $file\n";
-    my $cmd = <DBF>;
-    close(DBF);
-    chomp($cmd);
-#    print STDERR "$file $cmd\n";
-    $cmd =~ s/-/ -/g; # This is just a safety check for missing space.
-    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
-        run(command => $cmd, verbose => $verbose);
-    unless ($success) {
-
-        # This shouldn't fail, but we also can't suddenly abort if something does fail.
-        # Now we're going to drop the component that owns this dbinfo, which should force a retry.
-        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
-        warn("The command that shouldn't fail has failed: $file $cmd $remote_id $error_code");
-        if ($poll_word ne 'Completed') {  # If the job claims it completed, then we're fighting the network.
-            drop_component($remote_id,$cmd,$file);
-        }
-    }
-
-}
-
-# We're done, so set the state and exit.
-&my_die("Finished",$remote_id,0,"full");
-
+# Notify the database that this entry is currently running.
+&my_die("Finished",$remote_id,0,"run",$job_id);
 
 # END PROGRAM
-
 
 sub check_ssh_connection {
