public class SshMachineLocation extends AbstractLocation implements MachineLocation, PortSupplier, WithMutexes, java.io.Closeable
We expose two ways of running scripts. The execCommands method passes lines to bash and is lightweight but fragile. The execScript method creates a script on the remote machine. It is 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).
BrooklynObject.TagSupportConfigurable.ConfigurationSupportBrooklynObjectInternal.ConfigurationSupportInternal| Modifier and Type | Field and Description |
|---|---|
static java.util.Set<java.lang.String> |
ALL_SSH_CONFIG_KEY_NAMES |
static java.util.Set<ConfigKey.HasConfigKey<?>> |
ALL_SSH_CONFIG_KEYS |
static ConfigKey<java.lang.Boolean> |
ALLOCATE_PTY |
static ConfigKey<java.lang.Boolean> |
CLOSE_CONNECTION |
static ConfigKey<java.lang.Boolean> |
DETECT_MACHINE_DETAILS |
static ConfigKey<java.lang.String> |
LOCAL_TEMP_DIR |
static org.slf4j.Logger |
LOG
Deprecated.
since 0.7.0 shouldn't be public
|
static ConfigKey<java.lang.String> |
LOG_PREFIX |
static org.slf4j.Logger |
logSsh
Deprecated.
since 0.7.0 shouldn't be public
|
static ConfigKey<MachineDetails> |
MACHINE_DETAILS |
static ConfigKey<java.lang.Boolean> |
NO_STDERR_LOGGING |
static ConfigKey<java.lang.Boolean> |
NO_STDOUT_LOGGING |
static ConfigKey<java.lang.String> |
PASSWORD |
static ConfigKey<java.lang.String> |
PRIVATE_KEY_DATA |
static ConfigKey<java.lang.String> |
PRIVATE_KEY_FILE |
static ConfigKey<java.lang.String> |
PRIVATE_KEY_PASSPHRASE |
static java.util.Set<ConfigKey<?>> |
REUSABLE_SSH_PROPS
Specifies config keys where a change in the value does not require a new SshTool instance,
i.e.
|
static ConfigKey<java.lang.String> |
SCP_EXECUTABLE |
static ConfigKey<java.lang.String> |
SCRIPT_DIR |
static ConfigKey<Duration> |
SSH_CACHE_EXPIRY_DURATION |
static java.util.Set<ConfigKey<?>> |
SSH_CONFIG_GIVEN_TO_PROPS
The set of config keys on this location which become default values for properties when invoking an SSH
operation.
|
static ConfigKey<java.util.Map<java.lang.String,java.lang.Object>> |
SSH_ENV_MAP |
static ConfigKey<java.lang.String> |
SSH_EXECUTABLE |
static ConfigKey<java.lang.String> |
SSH_HOST |
static ConfigKey<java.lang.Integer> |
SSH_PORT |
static ConfigKey<java.io.OutputStream> |
STDERR |
static ConfigKey<java.io.OutputStream> |
STDOUT |
static ConfigKey<java.lang.String> |
UNIQUE_ID |
PARENT_LOCATION, TEMPORARY_LOCATIONFINAL_SPEC, NAMED_SPEC_NAME, ORIGINAL_SPEC| Constructor and Description |
|---|
SshMachineLocation() |
SshMachineLocation(java.util.Map properties) |
| Modifier and Type | Method and Description |
|---|---|
void |
acquireMutex(java.lang.String mutexId,
java.lang.String description)
acquires a mutex, if available, otherwise blocks on its becoming available;
caller must release after use
|
void |
close() |
SshMachineLocation |
configure(java.util.Map<?,?> properties)
Will set fields from flags, and put the remaining ones into the 'leftovers' map.
|
int |
copyFrom(java.util.Map<java.lang.String,?> props,
java.lang.String remote,
java.lang.String local) |
int |
copyFrom(java.lang.String remote,
java.lang.String local) |
int |
copyTo(java.io.File src,
java.io.File destination) |
int |
copyTo(java.io.File src,
java.lang.String destination) |
int |
copyTo(java.io.InputStream src,
long filesize,
java.lang.String destination) |
int |
copyTo(java.io.InputStream src,
java.lang.String destination) |
int |
copyTo(java.util.Map<java.lang.String,?> props,
java.io.File src,
java.io.File destination) |
int |
copyTo(java.util.Map<java.lang.String,?> props,
java.io.File src,
java.lang.String destination) |
int |
copyTo(java.util.Map<java.lang.String,?> props,
java.io.InputStream src,
long filesize,
java.lang.String destination) |
int |
copyTo(java.util.Map<java.lang.String,?> props,
java.io.InputStream src,
java.lang.String destination) |
int |
copyTo(java.util.Map<java.lang.String,?> props,
java.io.Reader src,
java.lang.String destination) |
int |
copyTo(java.io.Reader src,
java.lang.String destination) |
int |
execCommands(java.util.Map<java.lang.String,?> props,
java.lang.String summaryForLogging,
java.util.List<java.lang.String> commands) |
int |
execCommands(java.util.Map<java.lang.String,?> props,
java.lang.String summaryForLogging,
java.util.List<java.lang.String> commands,
java.util.Map<java.lang.String,?> env) |
int |
execCommands(java.lang.String summaryForLogging,
java.util.List<java.lang.String> commands)
Executes a set of commands, directly on the target machine (no wrapping in script).
|
int |
execCommands(java.lang.String summaryForLogging,
java.util.List<java.lang.String> commands,
java.util.Map<java.lang.String,?> env) |
int |
execScript(java.util.Map<java.lang.String,?> props,
java.lang.String summaryForLogging,
java.util.List<java.lang.String> commands) |
int |
execScript(java.util.Map<java.lang.String,?> props,
java.lang.String summaryForLogging,
java.util.List<java.lang.String> commands,
java.util.Map<java.lang.String,?> env) |
int |
execScript(java.lang.String summaryForLogging,
java.util.List<java.lang.String> commands)
Executes a set of commands, wrapped as a script sent to the remote machine.
|
int |
execScript(java.lang.String summaryForLogging,
java.util.List<java.lang.String> commands,
java.util.Map<java.lang.String,?> env) |
java.security.KeyPair |
findKeyPair()
returns the un-passphrased key-pair info if a key is being used, or else null
|
java.lang.String |
findPassword()
returns the password being used to log in, if a password is being used, or else null
|
java.net.InetAddress |
getAddress()
Return the single most appropriate address for this location.
|
java.lang.String |
getHostname()
note
|
MachineDetails |
getMachineDetails() |
OsDetails |
getOsDetails() |
int |
getPort()
port for SSHing
|
java.util.Set<java.lang.String> |
getPrivateAddresses()
All private IP addresses.
|
java.util.Set<java.lang.String> |
getPublicAddresses()
All public IP addresses, potentially including shared ips.
|
com.google.common.net.HostAndPort |
getSshHostAndPort() |
java.lang.String |
getUser() |
boolean |
hasMutex(java.lang.String mutexId)
returns true if the calling thread has the mutex with the given ID
|
int |
installTo(java.util.Map<java.lang.String,?> props,
java.lang.String url,
java.lang.String destPath) |
int |
installTo(ResourceUtils utils,
java.util.Map<java.lang.String,?> props,
java.lang.String url,
java.lang.String destPath)
Installs the given URL at the indicated destination path.
|
int |
installTo(ResourceUtils loader,
java.lang.String url,
java.lang.String destPath) |
int |
installTo(java.lang.String url,
java.lang.String destPath) |
boolean |
isSshable() |
int |
obtainPort(PortRange range)
Reserve a port for your application, with a port number in a specific range.
|
boolean |
obtainSpecificPort(int portNumber)
Reserve a specific port for an application.
|
void |
releaseMutex(java.lang.String mutexId)
releases a mutex, triggering another thread to use it or cleaning it up if no one else is waiting;
this should only be called by the mutex owner (thread)
|
void |
releasePort(int portNumber)
Release a previously reserved port.
|
java.lang.String |
toString()
Default String representation is simplified name of class, together with selected fields.
|
java.lang.String |
toVerboseString() |
boolean |
tryAcquireMutex(java.lang.String mutexId,
java.lang.String description)
acquires a mutex and returns true, if available; otherwise immediately returns false;
caller must release after use if this returns true
|
addChild, addExtension, config, containsLocation, equals, getAllConfig, getAllConfigBag, getChildren, getConfig, getConfig, getDisplayName, getExtension, getHostGeoInfo, getLocalConfigBag, getParent, getRawLocalConfigBag, getRebindSupport, hasConfig, hasExtension, hashCode, isManaged, onManagementStarted, onManagementStopped, removeChild, setConfig, setDisplayName, setHostGeoInfo, setManagementContext, setName, setParent, setParent, toMetadataRecordgetCatalogItemId, getId, getManagementContext, getTagSupport, init, rebind, setCatalogItemId, tagscontainsLocation, getAllConfig, getChildren, getConfig, getConfig, getDisplayName, getExtension, getId, getParent, hasConfig, hasExtension, setParentgetCatalogItemId, getTagSupport, tagsconfig, setConfiggetManagementContextsetCatalogItemIdpublic static final org.slf4j.Logger LOG
public static final org.slf4j.Logger logSsh
public static final ConfigKey<MachineDetails> MACHINE_DETAILS
public static final ConfigKey<java.lang.Boolean> DETECT_MACHINE_DETAILS
public static final ConfigKey<java.lang.String> SSH_HOST
public static final ConfigKey<java.lang.Integer> SSH_PORT
public static final ConfigKey<java.lang.String> SSH_EXECUTABLE
public static final ConfigKey<java.lang.String> SCP_EXECUTABLE
public static final ConfigKey<java.lang.String> PASSWORD
public static final ConfigKey<java.lang.String> PRIVATE_KEY_FILE
public static final ConfigKey<java.lang.String> PRIVATE_KEY_DATA
public static final ConfigKey<java.lang.String> PRIVATE_KEY_PASSPHRASE
public static final ConfigKey<java.lang.String> SCRIPT_DIR
public static final ConfigKey<java.util.Map<java.lang.String,java.lang.Object>> SSH_ENV_MAP
public static final ConfigKey<java.lang.Boolean> ALLOCATE_PTY
public static final ConfigKey<java.io.OutputStream> STDOUT
public static final ConfigKey<java.io.OutputStream> STDERR
public static final ConfigKey<java.lang.Boolean> NO_STDOUT_LOGGING
public static final ConfigKey<java.lang.Boolean> NO_STDERR_LOGGING
public static final ConfigKey<java.lang.String> LOG_PREFIX
public static final ConfigKey<java.lang.String> LOCAL_TEMP_DIR
public static final ConfigKey<java.lang.Boolean> CLOSE_CONNECTION
public static final ConfigKey<java.lang.String> UNIQUE_ID
public static final java.util.Set<ConfigKey<?>> REUSABLE_SSH_PROPS
public static final java.util.Set<ConfigKey.HasConfigKey<?>> ALL_SSH_CONFIG_KEYS
public static final java.util.Set<java.lang.String> ALL_SSH_CONFIG_KEY_NAMES
@Beta public static final java.util.Set<ConfigKey<?>> SSH_CONFIG_GIVEN_TO_PROPS
public SshMachineLocation()
public SshMachineLocation(java.util.Map properties)
public SshMachineLocation configure(java.util.Map<?,?> properties)
AbstractBrooklynObjectConfigBag.getUnusedConfig().
To be overridden by AbstractEntity, AbstractLoation, AbstractPolicy, AbstractEnricher, etc.
But should not be overridden by specific entity types. If you do, the entity may break in subsequent releases. Also note that if you require fields to be initialized you must do that in this method. You must *not* rely on field initializers because they may not run until *after* this method (this method is invoked by the constructor in this class, so initializers in subclasses will not have run when this overridden method is invoked.)
configure in class AbstractLocationpublic void close()
throws java.io.IOException
close in interface java.io.Closeableclose in interface java.lang.AutoCloseablejava.io.IOExceptionpublic java.net.InetAddress getAddress()
AddressableLocationgetAddress in interface AddressableLocationgetAddress in interface MachineLocationpublic java.lang.String getHostname()
HasNetworkAddressesgetHostname in interface HasNetworkAddressespublic java.util.Set<java.lang.String> getPublicAddresses()
HasNetworkAddressesgetPublicAddresses in interface HasNetworkAddressespublic java.util.Set<java.lang.String> getPrivateAddresses()
HasNetworkAddressesgetPrivateAddresses in interface HasNetworkAddressespublic com.google.common.net.HostAndPort getSshHostAndPort()
public java.lang.String getUser()
public int getPort()
public int execCommands(java.lang.String summaryForLogging,
java.util.List<java.lang.String> 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<java.lang.String,?> props,
java.lang.String summaryForLogging,
java.util.List<java.lang.String> commands)
public int execCommands(java.lang.String summaryForLogging,
java.util.List<java.lang.String> commands,
java.util.Map<java.lang.String,?> env)
public int execCommands(java.util.Map<java.lang.String,?> props,
java.lang.String summaryForLogging,
java.util.List<java.lang.String> commands,
java.util.Map<java.lang.String,?> env)
public int execScript(java.lang.String summaryForLogging,
java.util.List<java.lang.String> 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<java.lang.String,?> props,
java.lang.String summaryForLogging,
java.util.List<java.lang.String> commands)
public int execScript(java.lang.String summaryForLogging,
java.util.List<java.lang.String> commands,
java.util.Map<java.lang.String,?> env)
public int execScript(java.util.Map<java.lang.String,?> props,
java.lang.String summaryForLogging,
java.util.List<java.lang.String> commands,
java.util.Map<java.lang.String,?> env)
public int copyTo(java.io.File src,
java.io.File destination)
public int copyTo(java.util.Map<java.lang.String,?> 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<java.lang.String,?> 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<java.lang.String,?> 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<java.lang.String,?> props,
java.io.InputStream src,
long filesize,
java.lang.String destination)
public int copyTo(java.util.Map<java.lang.String,?> props,
java.io.InputStream src,
java.lang.String destination)
public int copyFrom(java.lang.String remote,
java.lang.String local)
public int copyFrom(java.util.Map<java.lang.String,?> props,
java.lang.String remote,
java.lang.String local)
public int installTo(java.lang.String url,
java.lang.String destPath)
public int installTo(java.util.Map<java.lang.String,?> props,
java.lang.String url,
java.lang.String destPath)
public int installTo(ResourceUtils loader, java.lang.String url, java.lang.String destPath)
public int installTo(ResourceUtils utils, java.util.Map<java.lang.String,?> props, java.lang.String url, java.lang.String destPath)
Attempts to curl the source URL on the remote machine, then if that fails, loads locally (from classpath or file) and transfers.
Use ArchiveUtils to handle directories and their contents properly.
TODO allow s3://bucket/file URIs for AWS S3 resources
TODO use PAX-URL style URIs for maven artifacts
TODO use subtasks here for greater visibility?; deprecate in favour of SshTasks.installFromUrl?
utils - A ResourceUtils that can resolve the source URLsurl - The source URL to be installeddestPath - The file to be created on the destinationArchiveUtils.deploy(String, SshMachineLocation, String),
ArchiveUtils.deploy(String, SshMachineLocation, String, String),
ResourceUtils.getResourceFromUrl(String)public java.lang.String toString()
AbstractLocationtoString in class AbstractLocationpublic java.lang.String toVerboseString()
toVerboseString in interface LocationtoVerboseString in class AbstractLocationpublic boolean obtainSpecificPort(int portNumber)
PortSupplierobtainSpecificPort in interface PortSupplierportNumber - the required port number.true if the port was successfully reserved; false if it has been previously reserved.obtainPort(PortRange),
PortRanges.ANY_HIGH_PORTpublic int obtainPort(PortRange range)
PortSupplierobtainPort in interface PortSupplierrange - the range of acceptable port numbers.public void releasePort(int portNumber)
PortSupplierreleasePort in interface PortSupplierportNumber - the port number from a call to PortSupplier.obtainPort(PortRange) or PortSupplier.obtainSpecificPort(int)public boolean isSshable()
public OsDetails getOsDetails()
getOsDetails in interface MachineLocationpublic MachineDetails getMachineDetails()
getMachineDetails in interface MachineLocationpublic void acquireMutex(java.lang.String mutexId,
java.lang.String description)
throws RuntimeInterruptedException
WithMutexesacquireMutex in interface WithMutexesRuntimeInterruptedExceptionpublic boolean tryAcquireMutex(java.lang.String mutexId,
java.lang.String description)
WithMutexestryAcquireMutex in interface WithMutexespublic void releaseMutex(java.lang.String mutexId)
WithMutexesreleaseMutex in interface WithMutexespublic boolean hasMutex(java.lang.String mutexId)
WithMutexeshasMutex in interface WithMutexespublic java.security.KeyPair findKeyPair()
public java.lang.String findPassword()