brooklyn-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From grkvlt <...@git.apache.org>
Subject [GitHub] incubator-brooklyn pull request: Feature/async ssh
Date Mon, 01 Dec 2014 16:01:58 GMT
Github user grkvlt commented on a diff in the pull request:

    https://github.com/apache/incubator-brooklyn/pull/358#discussion_r21097514
  
    --- Diff: core/src/main/java/brooklyn/util/internal/ssh/ShellAbstractTool.java ---
    @@ -262,7 +264,112 @@ public ToolAbstractExecScript(Map<String,?> props) {
                 return cmds.build();
             }
     
    +        protected String getSummary() {
    +            String summary = getOptionalVal(props, PROP_SUMMARY);
    +            return (summary != null) ? summary : scriptPath; 
    +        }
    +
             public abstract int run();
         }
         
    +    protected abstract class ToolAbstractAsyncExecScript extends ToolAbstractExecScript
{
    +        protected final String stdoutPath;
    +        protected final String stderrPath;
    +        protected final String exitStatusPath;
    +        protected final String pidPath;
    +
    +        public ToolAbstractAsyncExecScript(Map<String,?> props) {
    +            super(props);
    +
    +            stdoutPath = Os.mergePathsUnix(scriptDir, scriptNameWithoutExtension + ".stdout");
    +            stderrPath = Os.mergePathsUnix(scriptDir, scriptNameWithoutExtension + ".stderr");
    +            exitStatusPath = Os.mergePathsUnix(scriptDir, scriptNameWithoutExtension
+ ".exitstatus");
    +            pidPath = Os.mergePathsUnix(scriptDir, scriptNameWithoutExtension + ".pid");
    +        }
    +
    +        /**
    +         * Builds the command to run the given script, asynchronously.
    +         * The executed command will return immediately, but the output from the script
    +         * will continue to be written 
    +         * note that some modes require \$RESULT passed in order to access a variable,
whereas most just need $ */
    +        protected List<String> buildRunScriptCommand() {
    +            // TODO 
    +            String touchCmd = String.format("touch %s; touch %s; touch %s; touch %s",
stdoutPath, stderrPath, exitStatusPath, pidPath);
    +            String cmd = String.format("( %s > %s 2> %s < /dev/null ; echo $?
> %s ) & disown", scriptPath, stdoutPath, stderrPath, exitStatusPath);
    +            MutableList.Builder<String> cmds = MutableList.<String>builder()
    +                    .add((runAsRoot ? BashCommands.sudo(touchCmd) : touchCmd))
    +                    .add((runAsRoot ? BashCommands.sudo(cmd) : cmd))
    +                    .add("echo $! > "+pidPath)
    +                    .add("RESULT=$?");
    +            if (noExtraOutput==null || !noExtraOutput) {
    +                cmds.add("echo Executing async "+scriptPath);
    +            }
    +            cmds.add("exit $RESULT");
    +            return cmds.build();
    +        }
    +
    +        /**
    +         * Builds the command to retrieve the exit status of the command, written to
stdout.
    +         */
    +        protected List<String> buildRetrieveStatusCommand() {
    +            String cmd = 
    +                    "if test -s "+exitStatusPath+"; then"+"\n"+
    +                    "    cat "+exitStatusPath+"\n"+
    +                    "elif test -s "+pidPath+"; then"+"\n"+
    +                    "    pid=`cat "+pidPath+"`"+"\n"+
    +                    "    if ! ps -p $pid > /dev/null < /dev/null; then"+"\n"+
    +                    "        # no exit status, and not executing; give a few seconds
grace in case just about to write exit status"+"\n"+
    +                    "        sleep 3"+"\n"+
    +                    "        if test -s "+exitStatusPath+"; then"+"\n"+
    +                    "            cat "+exitStatusPath+""+"\n"+
    +                    "        else"+"\n"+
    +                    "            echo \"No exit status in a.exitstatus, and pid in a.pid
($pid) not executing\""+"\n"+
    --- End diff --
    
    are `a.exitstatus` and `a.pid` meant to be variable interpolations?


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message