|
Brooklyn | |||||||
FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectbrooklyn.location.basic.AbstractLocation
brooklyn.location.basic.SshMachineLocation
public class SshMachineLocation extends AbstractLocation
Operations on a machine that is accessible via ssh.
We expose two ways of running scripts. One (execCommands) passes lines to bash, that is lightweight but fragile. Another (execScript) creates a script on the remote machine, more portable but heavier.
Additionally there are routines to copyTo, copyFrom; and installTo (which tries a curl, and falls back to copyTo in event the source is accessible by the caller only).
Nested Class Summary | |
---|---|
protected interface |
SshMachineLocation.ExecRunner
|
Field Summary | |
---|---|
static ConfigKey |
ALLOCATE_PTY
|
static java.util.Set |
ALL_SSH_CONFIG_KEYS
|
static java.util.Set |
ALL_SSH_CONFIG_KEY_NAMES
|
static ConfigKey |
LOCAL_TEMP_DIR
|
static Logger |
LOG
|
static ConfigKey |
LOG_PREFIX
|
static ConfigKey |
NO_STDERR_LOGGING
|
static ConfigKey |
NO_STDOUT_LOGGING
|
static ConfigKey |
PASSWORD
|
static ConfigKey |
PRIVATE_KEY_DATA
|
static ConfigKey |
PRIVATE_KEY_FILE
|
static ConfigKey |
PRIVATE_KEY_PASSPHRASE
|
static java.util.Set |
REUSABLE_SSH_PROPS
specifies config keys where a change in the value does not require a new SshTool instance, i.e. these can be specified per command on the tool |
static ConfigKey |
SCP_EXECUTABLE
|
static ConfigKey |
SCRIPT_DIR
|
static java.lang.String |
SSHCONFIG_PREFIX
any property that should be passed as ssh config (connection-time) can be prefixed with this and . and will be passed through (with the prefix removed), e.g. |
static ConfigKey |
SSH_ENV_MAP
|
static ConfigKey |
SSH_EXECUTABLE
|
static ConfigKey |
SSH_HOST
|
static ConfigKey |
SSH_PORT
|
static ConfigKey |
STDERR
|
static ConfigKey |
STDOUT
|
static Logger |
logSsh
|
protected boolean |
previouslyConnected
|
Fields inherited from class AbstractLocation | |
---|---|
LOG, PARENT_LOCATION, hostGeoInfo, name |
Constructor Summary | |
SshMachineLocation()
|
|
SshMachineLocation(java.util.Map properties)
|
Method Summary | |
---|---|
void
|
acquireMutex(java.lang.String mutexId, java.lang.String description)
|
void
|
addConfig(java.util.Map vals)
@deprecated temporary Beta method introduced in 0.5.0 |
void
|
close()
|
void
|
configure(java.util.Map properties)
|
protected SshTool
|
connectSsh()
|
protected SshTool
|
connectSsh(java.util.Map props)
|
int
|
copyFrom(java.lang.String remote, java.lang.String local)
|
int
|
copyFrom(java.util.Map props, java.lang.String remote, java.lang.String local)
|
int
|
copyTo(java.io.File src, java.io.File destination)
|
int
|
copyTo(java.util.Map props, java.io.File src, java.io.File destination)
|
int
|
copyTo(java.io.File src, java.lang.String destination)
|
int
|
copyTo(java.util.Map props, java.io.File src, java.lang.String destination)
|
int
|
copyTo(java.io.Reader src, java.lang.String destination)
|
int
|
copyTo(java.util.Map props, java.io.Reader src, java.lang.String destination)
|
int
|
copyTo(java.io.InputStream src, java.lang.String destination)
|
int
|
copyTo(java.io.InputStream src, long filesize, java.lang.String destination)
|
int
|
copyTo(java.util.Map props, java.io.InputStream src, long filesize, java.lang.String destination)
|
int
|
copyTo(java.util.Map props, java.io.InputStream src, java.lang.String destination)
|
int
|
exec(java.util.List commands)
Convenience for running commands using ssh {@literal exec} mode. |
int
|
exec(java.util.Map props, java.util.List commands)
|
int
|
exec(java.util.List commands, java.util.Map env)
|
int
|
exec(java.util.Map props, java.util.List commands, java.util.Map env)
|
int
|
execCommands(java.lang.String summaryForLogging, java.util.List commands)
executes a set of commands, directly on the target machine (no wrapping in script). |
int
|
execCommands(java.util.Map props, java.lang.String summaryForLogging, java.util.List commands)
|
int
|
execCommands(java.lang.String summaryForLogging, java.util.List commands, java.util.Map env)
|
int
|
execCommands(java.util.Map props, java.lang.String summaryForLogging, java.util.List commands, java.util.Map env)
|
int
|
execScript(java.lang.String summaryForLogging, java.util.List commands)
executes a set of commands, wrapped as a script sent to the remote machine. |
int
|
execScript(java.util.Map props, java.lang.String summaryForLogging, java.util.List commands)
|
int
|
execScript(java.lang.String summaryForLogging, java.util.List commands, java.util.Map env)
|
int
|
execScript(java.util.Map props, java.lang.String summaryForLogging, java.util.List commands, java.util.Map env)
|
protected java.lang.Object
|
execSsh(java.util.Map props, Function task)
|
protected int
|
execWithLogging(java.util.Map props, java.lang.String summaryForLogging, java.util.List commands, java.util.Map env, groovy.lang.Closure execCommand)
|
protected int
|
execWithLogging(java.util.Map props, java.lang.String summaryForLogging, java.util.List commands, java.util.Map env, SshMachineLocation.ExecRunner execCommand)
|
protected void
|
finalize()
|
java.net.InetAddress
|
getAddress()
|
OsDetails
|
getOsDetails()
|
java.lang.String
|
getUser()
|
boolean
|
hasMutex(java.lang.String mutexId)
|
int
|
installTo(ResourceUtils loader, java.lang.String url, java.lang.String destination)
installs the given URL at the indicated destination. |
boolean
|
isSshable()
|
protected WithMutexes
|
newMutexSupport()
|
int
|
obtainPort(PortRange range)
|
boolean
|
obtainSpecificPort(int portNumber)
@see #obtainPort(PortRange) |
void
|
releaseMutex(java.lang.String mutexId)
|
void
|
releasePort(int portNumber)
|
int
|
run(java.lang.String command)
|
int
|
run(java.util.Map props, java.lang.String command)
|
int
|
run(java.lang.String command, java.util.Map env)
|
int
|
run(java.util.Map props, java.lang.String command, java.util.Map env)
|
int
|
run(java.util.List commands)
|
int
|
run(java.util.Map props, java.util.List commands)
|
int
|
run(java.util.List commands, java.util.Map env)
|
int
|
run(java.util.Map props, java.util.List commands, java.util.Map env)
|
java.lang.String
|
toString()
|
boolean
|
tryAcquireMutex(java.lang.String mutexId, java.lang.String description)
|
Field Detail |
---|
public static final ConfigKey ALLOCATE_PTY
public static final java.util.Set ALL_SSH_CONFIG_KEYS
public static final java.util.Set ALL_SSH_CONFIG_KEY_NAMES
public static final ConfigKey LOCAL_TEMP_DIR
public static final Logger LOG
public static final ConfigKey LOG_PREFIX
public static final ConfigKey NO_STDERR_LOGGING
public static final ConfigKey NO_STDOUT_LOGGING
public static final ConfigKey PASSWORD
public static final ConfigKey PRIVATE_KEY_DATA
public static final ConfigKey PRIVATE_KEY_FILE
public static final ConfigKey PRIVATE_KEY_PASSPHRASE
public static final java.util.Set REUSABLE_SSH_PROPS
public static final ConfigKey SCP_EXECUTABLE
public static final ConfigKey SCRIPT_DIR
@Deprecated public static final java.lang.String SSHCONFIG_PREFIX
public static final ConfigKey SSH_ENV_MAP
public static final ConfigKey SSH_EXECUTABLE
public static final ConfigKey SSH_HOST
public static final ConfigKey SSH_PORT
public static final ConfigKey STDERR
public static final ConfigKey STDOUT
public static final Logger logSsh
protected boolean previouslyConnected
Constructor Detail |
---|
public SshMachineLocation()
public SshMachineLocation(java.util.Map properties)
Method Detail |
---|
@Override public void acquireMutex(java.lang.String mutexId, java.lang.String description)
public void addConfig(java.util.Map vals)
@Override public void close()
public void configure(java.util.Map properties)
protected SshTool connectSsh()
protected SshTool connectSsh(java.util.Map props)
public int copyFrom(java.lang.String remote, java.lang.String local)
public int copyFrom(java.util.Map props, java.lang.String remote, java.lang.String local)
public int copyTo(java.io.File src, java.io.File destination)
public int copyTo(java.util.Map props, java.io.File src, java.io.File destination)
public int copyTo(java.io.File src, java.lang.String destination)
public int copyTo(java.util.Map props, java.io.File src, java.lang.String destination)
public int copyTo(java.io.Reader src, java.lang.String destination)
public int copyTo(java.util.Map props, java.io.Reader src, java.lang.String destination)
public int copyTo(java.io.InputStream src, java.lang.String destination)
public int copyTo(java.io.InputStream src, long filesize, java.lang.String destination)
public int copyTo(java.util.Map props, java.io.InputStream src, long filesize, java.lang.String destination)
public int copyTo(java.util.Map props, java.io.InputStream src, java.lang.String destination)
public int exec(java.util.List commands)
public int exec(java.util.Map props, java.util.List commands)
public int exec(java.util.List commands, java.util.Map env)
public int exec(java.util.Map props, java.util.List commands, java.util.Map env)
public int execCommands(java.lang.String summaryForLogging, java.util.List commands)
Stdout and stderr will be logged automatically to brooklyn.SSH logger, unless the flags 'noStdoutLogging' and 'noStderrLogging' are set. To set a logging prefix, use the flag 'logPrefix'.
Currently runs the commands in an interactive/login shell by passing each as a line to bash. To terminate early, use:
foo || exit 1It may be desirable instead, in some situations, to wrap as:
{ line1 ; } && { line2 ; } ...and run as a single command (possibly not as an interacitve/login shell) causing the script to exit on the first command which fails.
Currently this has to be done by the caller. (If desired we can add a flag exitIfAnyNonZero to support this mode, and/or commandPrepend and commandAppend similar to (currently supported in SshjTool) separator.)
public int execCommands(java.util.Map props, java.lang.String summaryForLogging, java.util.List commands)
public int execCommands(java.lang.String summaryForLogging, java.util.List commands, java.util.Map env)
public int execCommands(java.util.Map props, java.lang.String summaryForLogging, java.util.List commands, java.util.Map env)
public int execScript(java.lang.String summaryForLogging, java.util.List commands)
Stdout and stderr will be logged automatically to brooklyn.SSH logger, unless the flags 'noStdoutLogging' and 'noStderrLogging' are set. To set a logging prefix, use the flag 'logPrefix'.
public int execScript(java.util.Map props, java.lang.String summaryForLogging, java.util.List commands)
public int execScript(java.lang.String summaryForLogging, java.util.List commands, java.util.Map env)
public int execScript(java.util.Map props, java.lang.String summaryForLogging, java.util.List commands, java.util.Map env)
protected java.lang.Object execSsh(java.util.Map props, Function task)
protected int execWithLogging(java.util.Map props, java.lang.String summaryForLogging, java.util.List commands, java.util.Map env, groovy.lang.Closure execCommand)
@SuppressWarnings("resource") protected int execWithLogging(java.util.Map props, java.lang.String summaryForLogging, java.util.List commands, java.util.Map env, SshMachineLocation.ExecRunner execCommand)
@Override protected void finalize()
public java.net.InetAddress getAddress()
@Override public OsDetails getOsDetails()
public java.lang.String getUser()
@Override public boolean hasMutex(java.lang.String mutexId)
public int installTo(ResourceUtils loader, java.lang.String url, java.lang.String destination)
accepts either a path (terminated with /) or filename for the destination.
public boolean isSshable()
protected WithMutexes newMutexSupport()
public int obtainPort(PortRange range)
public boolean obtainSpecificPort(int portNumber)
@Override public void releaseMutex(java.lang.String mutexId)
public void releasePort(int portNumber)
public int run(java.lang.String command)
public int run(java.util.Map props, java.lang.String command)
public int run(java.lang.String command, java.util.Map env)
public int run(java.util.Map props, java.lang.String command, java.util.Map env)
public int run(java.util.List commands)
public int run(java.util.Map props, java.util.List commands)
public int run(java.util.List commands, java.util.Map env)
public int run(java.util.Map props, java.util.List commands, java.util.Map env)
@Override public java.lang.String toString()
@Override public boolean tryAcquireMutex(java.lang.String mutexId, java.lang.String description)
Brooklyn Multi-Cloud Application Management Platform
brooklyncentral.github.com. Apache License. © 2012.