Brooklyn

brooklyn.util.ssh
[Java] Class CommonCommands

java.lang.Object
  brooklyn.util.ssh.CommonCommands

public class CommonCommands

Field Summary
static java.lang.String INSTALL_CURL

static java.lang.String INSTALL_TAR

static java.lang.String INSTALL_WGET

static java.lang.String INSTALL_ZIP

 
Method Summary
static java.lang.String alternatives(java.util.Collection commands, java.lang.String failure)

Returns a sequence of alternative commands that runs until one of the commands succeeds

static java.lang.String chain(java.util.Collection commands)

Returns a sequence of chained commands that runs until one of them fails

static java.lang.String dontRequireTtyForSudo()

some machines require a tty for sudo; brooklyn by default does not use a tty (so that it can get separate error+stdout streams); you can enable a tty as an option to every ssh command, or you can do it once and modify the machine so that a tty is not subsequently required.

static java.util.List downloadUrlAs(java.lang.String url, java.lang.String entityVersionPath, java.lang.String pathlessFilenameToSaveAs)

@see downloadUrlAs(Map, String, String, String)

static java.util.List downloadUrlAs(java.util.Map flags, java.lang.String url, java.lang.String entityVersionPath, java.lang.String pathlessFilenameToSaveAs)

/** Returns command for downloading from a url and saving to a file; currently using curl.

static java.util.List downloadUrlAs(java.util.List urls, java.lang.String saveAs)

Returns command to download the URL, saving as the given file.

static java.lang.String exists(java.lang.String executable, java.lang.String... commands)

Returns a command that runs only if the specified executable is in the path.

static java.lang.String file(java.lang.String path, java.lang.String command)

Returns a command that runs only if the specified executable is in the path

static java.lang.String formatIfNotNull(java.lang.String pattern, java.lang.Object arg)

returns the pattern formatted with the given arg if the arg is not null, otherwise returns null

static java.lang.String installExecutable(java.util.Map flags, java.lang.String executable)

Returns a string for checking whether the given executable is available, and installing it if necessary.

static java.lang.String installExecutable(java.lang.String executable)

static java.lang.String installJava6()

Returns the command that installs Java 1.6.

static java.lang.String installPackage(java.util.Map flags, java.lang.String packageDefaultName)

Returns a command for installing the given package.

static java.lang.String installPackage(java.lang.String packageDefaultName)

static java.lang.String missing(java.lang.String executable, java.lang.String command)

Returns a command that runs only if the specified executable is NOT in the path

static java.lang.String ok(java.lang.String command)

Returns a command that always exits successfully

static java.lang.String on(java.lang.String osName, java.lang.String command)

Returns a command that runs only 1f the operating system is as specified; Checks /etc/issue for the specified name

static java.lang.String quiet(java.lang.String command)

Returns a command with all output redirected to /dev/null

static java.lang.String simpleDownloadUrlAs(java.util.List urls, java.lang.String saveAs)

Same as downloadUrlAs(java.util.List, java.lang.String), except does not install curl, and does not exit on failure.

static java.lang.String sudo(java.lang.String command)

Returns a command for safely running as root, using sudo.

 
Methods inherited from class java.lang.Object
java.lang.Object#wait(), java.lang.Object#wait(long), java.lang.Object#wait(long, int), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll()
 

Field Detail

INSTALL_CURL

public static final java.lang.String INSTALL_CURL


INSTALL_TAR

public static final java.lang.String INSTALL_TAR


INSTALL_WGET

public static final java.lang.String INSTALL_WGET


INSTALL_ZIP

public static final java.lang.String INSTALL_ZIP


 
Method Detail

alternatives

public static java.lang.String alternatives(java.util.Collection commands, java.lang.String failure)
Returns a sequence of alternative commands that runs until one of the commands succeeds


chain

public static java.lang.String chain(java.util.Collection commands)
Returns a sequence of chained commands that runs until one of them fails


dontRequireTtyForSudo

public static java.lang.String dontRequireTtyForSudo()
some machines require a tty for sudo; brooklyn by default does not use a tty (so that it can get separate error+stdout streams); you can enable a tty as an option to every ssh command, or you can do it once and modify the machine so that a tty is not subsequently required.

this command must be run with allocatePTY set as a flag to ssh.

(having a tty for sudo seems like another case of imaginary security which is just irritating. like water restrictions at airport security.)


downloadUrlAs

public static java.util.List downloadUrlAs(java.lang.String url, java.lang.String entityVersionPath, java.lang.String pathlessFilenameToSaveAs)
deprecated:
Use downloadUrlAs(List, java.lang.String), and rely on DownloadResolverManager to include the local-repo
See Also:
downloadUrlAs(java.util.Map, java.lang.String, java.lang.String, java.lang.String)


downloadUrlAs

@Deprecated
public static java.util.List downloadUrlAs(java.util.Map flags, java.lang.String url, java.lang.String entityVersionPath, java.lang.String pathlessFilenameToSaveAs)
/** Returns command for downloading from a url and saving to a file; currently using curl.

Will read from a local repository, if files have been copied there (cp -r /tmp/brooklyn/installs/ ~/.brooklyn/repository//) unless skipLocalRepo is {

literal:
true}.

Ideally use a blobstore staging area.

deprecated:
Use downloadUrlAs(java.util.List, java.lang.String), and rely on DownloadResolverManager to include the local-repo


downloadUrlAs

public static java.util.List downloadUrlAs(java.util.List urls, java.lang.String saveAs)
Returns command to download the URL, saving as the given file. Will try each URL in turn until one is successful (see `curl -f` documentation).


exists

public static java.lang.String exists(java.lang.String executable, java.lang.String... commands)
Returns a command that runs only if the specified executable is in the path. If command is null, no command runs (and the script component this creates will return true if the executable).


file

public static java.lang.String file(java.lang.String path, java.lang.String command)
Returns a command that runs only if the specified executable is in the path


formatIfNotNull

public static java.lang.String formatIfNotNull(java.lang.String pattern, java.lang.Object arg)
returns the pattern formatted with the given arg if the arg is not null, otherwise returns null


installExecutable

public static java.lang.String installExecutable(java.util.Map flags, java.lang.String executable)
Returns a string for checking whether the given executable is available, and installing it if necessary.

Uses installPackage and accepts the same flags e.g. for apt, yum, rpm.


installExecutable

public static java.lang.String installExecutable(java.lang.String executable)


installJava6

public static java.lang.String installJava6()
Returns the command that installs Java 1.6.
Returns:
the command that install Java 1.6.


installPackage

public static java.lang.String installPackage(java.util.Map flags, java.lang.String packageDefaultName)
Returns a command for installing the given package.

Flags can contain common overrides for deb, apt, yum, rpm and port as the package names can be different for each of those:

 installPackage("libssl-devel", yum:"openssl-devel", apt:"openssl libssl-dev zlib1g-dev")
 


installPackage

public static java.lang.String installPackage(java.lang.String packageDefaultName)


missing

public static java.lang.String missing(java.lang.String executable, java.lang.String command)
Returns a command that runs only if the specified executable is NOT in the path


ok

public static java.lang.String ok(java.lang.String command)
Returns a command that always exits successfully


on

public static java.lang.String on(java.lang.String osName, java.lang.String command)
Returns a command that runs only 1f the operating system is as specified; Checks /etc/issue for the specified name


quiet

public static java.lang.String quiet(java.lang.String command)
Returns a command with all output redirected to /dev/null


simpleDownloadUrlAs

public static java.lang.String simpleDownloadUrlAs(java.util.List urls, java.lang.String saveAs)
Same as downloadUrlAs(java.util.List, java.lang.String), except does not install curl, and does not exit on failure.


sudo

public static java.lang.String sudo(java.lang.String command)
Returns a command for safely running as root, using sudo.

Ensuring non-blocking if password not set by using -n which means to exit if password required, and (perhaps unnecessarily ?) -S which reads from stdin (routed to /dev/null, it was claimed here previously, though I'm not sure?).

Also specify -E to pass the parent environment in.

If already root, simply runs the command, wrapped in brackets in case it is backgrounded.

The command is not quoted or escaped in any ways. If you are doing privileged redirect you may need to pass e.g. "bash -c 'echo hi > file'".

If null is supplied, it is returned (sometimes used to indicate no command desired).


 

Brooklyn Multi-Cloud Application Management Platform
brooklyncentral.github.com. Apache License. © 2012.