Github user grkvlt commented on a diff in the pull request:

    https://github.com/apache/incubator-brooklyn/pull/358#discussion_r21098000
  
    --- Diff: core/src/main/java/brooklyn/util/internal/ssh/sshj/SshjTool.java 
---
    @@ -299,16 +302,134 @@ public int copyFromServer(Map<String,?> props, 
String pathAndFileOnRemoteServer,
          * 
          * So on balance, the script-based approach seems most reliable, even 
if there is an overhead
          * of separate message(s) for copying the file!
    +     * 
    +     * Another consideration is long-running scripts. On some clouds when 
executing a script that takes 
    +     * several minutes, we have seen it fail with -1 (e.g. 1 in 20 times). 
This suggests the ssh connection
    +     * is being dropped. To avoid this problem, we can execute the script 
asynchronously, writing to files
    +     * the stdout/stderr/pid/exitStatus. We then periodically poll to 
retrieve the contents of these files.
    +     * Use {@link #PROP_EXEC_ASYNC} to force this mode of execution.
          */
         @Override
         public int execScript(final Map<String,?> props, final List<String> 
commands, final Map<String,?> env) {
    -        return new ToolAbstractExecScript(props) {
    +        Boolean execAsync = getOptionalVal(props, PROP_EXEC_ASYNC);
    +        if (Boolean.TRUE.equals(execAsync)) {
    +            return execScriptAsyncAndPoll(props, commands, env);
    +        } else {
    +            return new ToolAbstractExecScript(props) {
    +                public int run() {
    +                    String scriptContents = toScript(props, commands, env);
    +                    if (LOG.isTraceEnabled()) LOG.trace("Running shell 
command at {} as script: {}", host, scriptContents);
    +                    copyToServer(ImmutableMap.of("permissions", "0700"), 
scriptContents.getBytes(), scriptPath);
    +                    
    +                    return asInt(acquire(new 
ShellAction(buildRunScriptCommand(), out, err)), -1);                
    +                }
    +            }.run();
    +        }
    +    }
    +
    +    protected int execScriptAsyncAndPoll(final Map<String,?> props, final 
List<String> commands, final Map<String,?> env) {
    --- End diff --
    
    Complex, but looks good.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to