Brooklyn

brooklyn.location.basic
[Java] Class SshMachineLocation

java.lang.Object
  brooklyn.location.basic.AbstractLocation
      brooklyn.location.basic.SshMachineLocation
All Implemented Interfaces:
MachineLocation, PortSupplier, WithMutexes

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 Logger LOG

static java.util.Collection NON_SSH_PROPS

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 java.util.Collection SSH_PROPS

properties which are passed to ssh

static Logger logSsh

protected boolean previouslyConnected

 
Fields inherited from class AbstractLocation
LOG, hostGeoInfo, leftoverProperties, name
 
Constructor Summary
SshMachineLocation()

SshMachineLocation(java.util.Map properties)

 
Method Summary
void acquireMutex(java.lang.String mutexId, java.lang.String description)

void configure()

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.util.Map props, 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 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 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)

java.net.InetAddress getAddress()

java.util.Map getConfig()

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)

deprecated:
in 1.4.1,
@see execCommand and execScript

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)

 
Methods inherited from class AbstractLocation
addChildLocation, configure, configure, containsLocation, equals, findLocationProperty, getChildLocations, getHostGeoInfo, getId, getLocationProperty, getName, getParentLocation, hasLocationProperty, hashCode, removeChildLocation, setHostGeoInfo, setParentLocation, string, toString
 

Field Detail

LOG

public static final Logger LOG


NON_SSH_PROPS

public static final java.util.Collection NON_SSH_PROPS


SSHCONFIG_PREFIX

public static final 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. (SSHCONFIG_PREFIX+"."+"StrictHostKeyChecking"):"yes"


SSH_PROPS

public static final java.util.Collection SSH_PROPS
properties which are passed to ssh


logSsh

public static final Logger logSsh


previouslyConnected

protected boolean previouslyConnected


 
Constructor Detail

SshMachineLocation

public SshMachineLocation()


SshMachineLocation

public SshMachineLocation(java.util.Map properties)


 
Method Detail

acquireMutex

@Override
public void acquireMutex(java.lang.String mutexId, java.lang.String description)


configure

public void configure()


configure

public void configure(java.util.Map properties)


connectSsh

protected SshTool connectSsh()


connectSsh

protected SshTool connectSsh(java.util.Map props)


copyFrom

public int copyFrom(java.lang.String remote, java.lang.String local)


copyFrom

public int copyFrom(java.util.Map props, java.lang.String remote, java.lang.String local)


copyTo

public int copyTo(java.io.File src, java.io.File destination)


copyTo

public int copyTo(java.util.Map props, java.io.File src, java.io.File destination)


copyTo

public int copyTo(java.io.File src, java.lang.String destination)


copyTo

public int copyTo(java.util.Map props, java.io.File src, java.lang.String destination)


copyTo

public int copyTo(java.io.Reader src, java.lang.String destination)


copyTo

public int copyTo(java.util.Map props, java.io.Reader src, java.lang.String destination)


copyTo

public int copyTo(java.io.InputStream src, java.lang.String destination)


copyTo

public int copyTo(java.util.Map props, java.io.InputStream src, java.lang.String destination)


copyTo

public int copyTo(java.io.InputStream src, long filesize, java.lang.String destination)


copyTo

public int copyTo(java.util.Map props, java.io.InputStream src, long filesize, java.lang.String destination)


exec

public int exec(java.util.List commands)
Convenience for running commands using ssh {
literal:
exec} mode.
deprecated:
in 1.4.1,
See Also:
execCommand


exec

public int exec(java.util.Map props, java.util.List commands)


exec

public int exec(java.util.List commands, java.util.Map env)


exec

public int exec(java.util.Map props, java.util.List commands, java.util.Map env)


execCommands

public int execCommands(java.lang.String summaryForLogging, java.util.List commands)
executes a set of commands, directly on the target machine (no wrapping in script). joined using ' ; ' by default.

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 1
 
It 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.)


execCommands

public int execCommands(java.util.Map props, java.lang.String summaryForLogging, java.util.List commands)


execCommands

public int execCommands(java.lang.String summaryForLogging, java.util.List commands, java.util.Map env)


execCommands

public int execCommands(java.util.Map props, java.lang.String summaryForLogging, java.util.List commands, java.util.Map env)


execScript

public int execScript(java.lang.String summaryForLogging, java.util.List commands)
executes a set of commands, wrapped as a script sent to the remote machine.

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'.


execScript

public int execScript(java.util.Map props, java.lang.String summaryForLogging, java.util.List commands)


execScript

public int execScript(java.lang.String summaryForLogging, java.util.List commands, java.util.Map env)


execScript

public int execScript(java.util.Map props, java.lang.String summaryForLogging, java.util.List commands, java.util.Map env)


execWithLogging

protected int execWithLogging(java.util.Map props, java.lang.String summaryForLogging, java.util.List commands, java.util.Map env, groovy.lang.Closure execCommand)


execWithLogging

protected int execWithLogging(java.util.Map props, java.lang.String summaryForLogging, java.util.List commands, java.util.Map env, SshMachineLocation.ExecRunner execCommand)


getAddress

public java.net.InetAddress getAddress()


getConfig

public java.util.Map getConfig()


getOsDetails

@Override
public OsDetails getOsDetails()


getUser

public java.lang.String getUser()


hasMutex

@Override
public boolean hasMutex(java.lang.String mutexId)


installTo

public int installTo(ResourceUtils loader, java.lang.String url, java.lang.String destination)
installs the given URL at the indicated destination. attempts to curl the sourceUrl on the remote machine, then if that fails, loads locally (from classpath or file) and transfers.

accepts either a path (terminated with /) or filename for the destination.


isSshable

public boolean isSshable()


newMutexSupport

protected WithMutexes newMutexSupport()


obtainPort

public int obtainPort(PortRange range)


obtainSpecificPort

public boolean obtainSpecificPort(int portNumber)
See Also:
obtainPort(PortRange)
BasicPortRange#ANY_HIGH_PORT#ANY_HIGH_PORT


releaseMutex

@Override
public void releaseMutex(java.lang.String mutexId)


releasePort

public void releasePort(int portNumber)


run

public int run(java.lang.String command)


run

public int run(java.util.Map props, java.lang.String command)


run

public int run(java.lang.String command, java.util.Map env)


run

public int run(java.util.Map props, java.lang.String command, java.util.Map env)


run

public int run(java.util.List commands)
deprecated:
in 1.4.1,
See Also:
execCommand


run

public int run(java.util.Map props, java.util.List commands)


run

public int run(java.util.List commands, java.util.Map env)


run

public int run(java.util.Map props, java.util.List commands, java.util.Map env)


toString

@Override
public java.lang.String toString()


tryAcquireMutex

@Override
public boolean tryAcquireMutex(java.lang.String mutexId, java.lang.String description)


 

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