Riak Linux - Move the utility methods to the appropriate BashCommands class
Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/bddb4311 Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/bddb4311 Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/bddb4311 Branch: refs/heads/master Commit: bddb4311c3c1892b2ef2a64bb55e618e9be030d7 Parents: f3e0430 Author: Valentin Aitken <[email protected]> Authored: Sat Mar 14 23:58:38 2015 +0200 Committer: Valentin Aitken <[email protected]> Committed: Sat Mar 14 23:58:38 2015 +0200 ---------------------------------------------------------------------- .../entity/nosql/riak/RiakNodeSshDriver.java | 31 ----------------- .../java/brooklyn/util/ssh/BashCommands.java | 35 ++++++++++++++++++-- 2 files changed, 33 insertions(+), 33 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/bddb4311/software/nosql/src/main/java/brooklyn/entity/nosql/riak/RiakNodeSshDriver.java ---------------------------------------------------------------------- diff --git a/software/nosql/src/main/java/brooklyn/entity/nosql/riak/RiakNodeSshDriver.java b/software/nosql/src/main/java/brooklyn/entity/nosql/riak/RiakNodeSshDriver.java index aed7ceb..37ddc1f 100644 --- a/software/nosql/src/main/java/brooklyn/entity/nosql/riak/RiakNodeSshDriver.java +++ b/software/nosql/src/main/java/brooklyn/entity/nosql/riak/RiakNodeSshDriver.java @@ -201,37 +201,6 @@ public class RiakNodeSshDriver extends AbstractSoftwareProcessSshDriver implemen .build(); } - private static String addSbinPathCommand() { - return "export PATH=$PATH:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"; - } - - /** - * Returns a command which - * executes <code>statement</code> only if <code>command</code> is NOT found in <code>$PATH</code> - * - * @param command - * @param statement - * @return command - */ - private static String ifNotExecutable(String command, String statement) { - return String.format("{ { test ! -z `which %s`; } || { %s; } }", command, statement); - } - - private static String ifExecutableElse(String command, String ifTrue, String otherwise) { - return com.google.common.base.Joiner.on('\n').join( - ifExecutableElse(command, ImmutableList.<String>of(ifTrue), ImmutableList.<String>of(otherwise))); - } - - private static ImmutableList<String> ifExecutableElse(String command, List<String> ifTrue, List<String> otherwise) { - return ImmutableList.<String>builder() - .add(String.format("if test -z `which %s`; then", command)) - .addAll(ifTrue) - .add("else") - .addAll(otherwise) - .add("fi") - .build(); - } - protected List<String> installMac() { String saveAs = resolver.getFilename(); String url = entity.getAttribute(RiakNode.DOWNLOAD_URL_MAC).toString(); http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/bddb4311/utils/common/src/main/java/brooklyn/util/ssh/BashCommands.java ---------------------------------------------------------------------- diff --git a/utils/common/src/main/java/brooklyn/util/ssh/BashCommands.java b/utils/common/src/main/java/brooklyn/util/ssh/BashCommands.java index b59d973..21b87d1 100644 --- a/utils/common/src/main/java/brooklyn/util/ssh/BashCommands.java +++ b/utils/common/src/main/java/brooklyn/util/ssh/BashCommands.java @@ -138,6 +138,10 @@ public class BashCommands { // return "{ sudo -n -S -i -u "+user+" -- "+BashStringEscapes.wrapBash(command)+" ; }"; // } + public static String addSbinPathCommand() { + return "export PATH=$PATH:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"; + } + /** executes a command, then as user tees the output to the given file. * useful e.g. for appending to a file which is only writable by root or a priveleged user. */ public static String executeCommandThenAsUserTeeOutputToFile(String commandWhoseOutputToWrite, String user, String file) { @@ -200,14 +204,41 @@ public class BashCommands { } /** + * Returns a command which + * executes <code>statement</code> only if <code>command</code> is NOT found in <code>$PATH</code> + * + * @param command + * @param statement + * @return command + */ + public static String ifNotExecutable(String command, String statement) { + return String.format("{ { test ! -z `which %s`; } || { %s; } }", command, statement); + } + + /** * Returns a command that runs only if the specified executable exists on the path (using `which`). * if the command runs and fails that exit is preserved (but if the executable is not on the path exit code is zero). - * @see #ifFileExistsElse0(String, String) for implementation discussion, using <code>{ { test -z `which executable` && true ; } || command ; } + * @see #ifFileExistsElse0(String, String) for implementation discussion, using <code>{ { test -z `which executable` && true ; } || command ; } */ public static String onlyIfExecutableMissing(String executable, String command) { return alternativesGroup(format("which %s", executable), command); } - + + public static String ifExecutableElse(String command, String ifTrue, String otherwise) { + return com.google.common.base.Joiner.on('\n').join( + ifExecutableElse(command, ImmutableList.<String>of(ifTrue), ImmutableList.<String>of(otherwise))); + } + + public static ImmutableList<String> ifExecutableElse(String command, List<String> ifTrue, List<String> otherwise) { + return ImmutableList.<String>builder() + .add(String.format("if test -z `which %s`; then", command)) + .addAll(ifTrue) + .add("else") + .addAll(otherwise) + .add("fi") + .build(); + } + /** * Returns a sequence of chained commands that runs until one of them fails (i.e. joined by '&&') * This currently runs as a subshell (so exits are swallowed) but behaviour may be changed imminently.
