Brooklyn

brooklyn.util.internal.ssh.sshj
[Java] Class SshjTool

java.lang.Object
  brooklyn.util.internal.ssh.ShellAbstractTool
      brooklyn.util.internal.ssh.SshAbstractTool
          brooklyn.util.internal.ssh.sshj.SshjTool
All Implemented Interfaces:
SshTool

public class SshjTool
extends SshAbstractTool

For ssh and scp-style commands, using the sshj library.

The implementation is based on a combination of the existing brooklyn SshJschTool, and the jclouds SshjSshClient.

Not thread-safe. Use a different SshjTool for each concurrent thread. If passing from one thread to another, ensure code goes through a synchronized block.


Nested Class Summary
static class SshjTool.Builder

static class SshjTool.SshjToolBuilder

 
Field Summary
protected BackoffLimitedRetryHandler backoffLimitedRetryHandler

protected int sshTries

protected int sshTriesTimeout

 
Fields inherited from class SshAbstractTool
allocatePTY, host, password, port, privateKeyData, privateKeyFile, privateKeyPassphrase, strictHostKeyChecking, toString, user
 
Fields inherited from class ShellAbstractTool
localTempDir
 
Method Summary
java.lang.Object SshjTool(java.util.Map map)

protected java.lang.Object SshjTool(SshjTool.Builder builder)

protected java.lang.Object acquire(C connection)

protected void allocatePTY(Session s)

protected void backoffForAttempt(int retryAttempt, java.lang.String message)

static SshjTool.SshjToolBuilder builder()

protected void checkConnected()

void connect()

void connect(int maxAttempts)

int copyFromServer(java.util.Map props, java.lang.String pathAndFileOnRemoteServer, java.io.File localFile)

int copyToServer(java.util.Map props, byte[] contents, java.lang.String pathAndFileOnRemoteServer)

int copyToServer(java.util.Map props, java.io.InputStream contents, java.lang.String pathAndFileOnRemoteServer)

int copyToServer(java.util.Map props, java.io.File localFile, java.lang.String pathAndFileOnRemoteServer)

void disconnect()

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

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

This creates a script containing the user's commands, copies it to the remote server, and executes the script.

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

boolean isConnected()

protected SshAction newSessionAction()

 
Methods inherited from class SshAbstractTool
SshAbstractTool, getHostAddress, getUsername, propagate, toString
 
Methods inherited from class ShellAbstractTool
asInt, buildRunScriptCommand, closeWhispering, closeWhispering, execCommands, execScript, getMandatoryVal, getMandatoryVal, getOptionalVal, getOptionalVal, getOptionalVal, hasVal, toCommandSequence, toScript, warnOnDeprecated, writeTempFile, writeTempFile, writeTempFile
 

Field Detail

backoffLimitedRetryHandler

protected final BackoffLimitedRetryHandler backoffLimitedRetryHandler


sshTries

protected final int sshTries


sshTriesTimeout

protected final int sshTriesTimeout


 
Method Detail

SshjTool

public java.lang.Object SshjTool(java.util.Map map)


SshjTool

protected java.lang.Object SshjTool(SshjTool.Builder builder)


acquire

protected java.lang.Object acquire(C connection)


allocatePTY

protected void allocatePTY(Session s)


backoffForAttempt

protected void backoffForAttempt(int retryAttempt, java.lang.String message)


builder

public static SshjTool.SshjToolBuilder builder()


checkConnected

protected void checkConnected()


connect

try {
public void connect()


connect

connect(); // FIXME Should callers instead configure sshTries? But that would apply to all ssh attempts
public void connect(int maxAttempts)


copyFromServer

Files.copy(new InputStreamSupplier(contents), localFile);
public int copyFromServer(java.util.Map props, java.lang.String pathAndFileOnRemoteServer, java.io.File localFile)


copyToServer

}
public int copyToServer(java.util.Map props, byte[] contents, java.lang.String pathAndFileOnRemoteServer)


copyToServer

*   1) to know the length of the InputStream to copy the file to perform copy; and
public int copyToServer(java.util.Map props, java.io.InputStream contents, java.lang.String pathAndFileOnRemoteServer)


copyToServer

}
public int copyToServer(java.util.Map props, java.io.File localFile, java.lang.String pathAndFileOnRemoteServer)


disconnect

try {
public void disconnect()


execCommands

OutputStream out = getOptionalVal(props, PROP_OUT_STREAM);
public int execCommands(java.util.Map props, java.util.List commands, java.util.Map env)


execScript

Boolean noExtraOutput = getOptionalVal(props, PROP_NO_EXTRA_OUTPUT);
public int execScript(java.util.Map props, java.util.List commands, java.util.Map env)
This creates a script containing the user's commands, copies it to the remote server, and executes the script. The script is then deleted.

Executing commands directly is fraught with dangers! Here are other options, and their problems:

So on balance, the script-based approach seems most reliable, even if there is an overhead of separate message(s) for copying the file!


execShellDirect

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


isConnected

}
public boolean isConnected()


newSessionAction

protected SshAction newSessionAction()


 

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