Brooklyn

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

java.lang.Object
  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

 
Field Summary
protected BackoffLimitedRetryHandler backoffLimitedRetryHandler

protected int sshTries

protected int sshTriesTimeout

 
Fields inherited from class SshAbstractTool
allocatePTY, host, localTempDir, password, port, privateKeyData, privateKeyFile, privateKeyPassphrase, strictHostKeyChecking, toString, user
 
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.Builder 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)

int createFile(java.util.Map props, java.lang.String pathAndFileOnRemoteServer, java.io.InputStream input, long size)

int createFile(java.util.Map props, java.lang.String pathAndFileOnRemoteServer, java.lang.String contents)

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

void disconnect()

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

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

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

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 execShell(java.util.Map props, java.util.List commands)

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

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

boolean isConnected()

protected SshAction newSessionAction()

int transferFileFrom(java.util.Map props, java.lang.String pathAndFileOnRemoteServer, java.lang.String pathAndFileOnLocalServer)

int transferFileTo(java.util.Map props, java.io.InputStream input, java.lang.String pathAndFileOnRemoteServer)

 
Methods inherited from class SshAbstractTool
SshAbstractTool, closeWhispering, getHostAddress, getMandatoryVal, getMandatoryVal, getOptionalVal, getOptionalVal, getOptionalVal, getUsername, hasVal, propagate, toCommandSequence, toScript, toString, 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.Builder builder()


checkConnected

protected void checkConnected()


connect

@Override
public void connect()


connect

@Override
public void connect(int maxAttempts)


copyFromServer

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


copyToServer

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


copyToServer

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


copyToServer

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


createFile

@Override
public int createFile(java.util.Map props, java.lang.String pathAndFileOnRemoteServer, java.io.InputStream input, long size)


createFile

@Override
public int createFile(java.util.Map props, java.lang.String pathAndFileOnRemoteServer, java.lang.String contents)


createFile

@Override
public int createFile(java.util.Map props, java.lang.String pathAndFileOnRemoteServer, byte[] contents)


disconnect

@Override
public void disconnect()


execCommands

@Override
public int execCommands(java.util.Map props, java.util.List commands)


execCommands

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


execScript

@Override
public int execScript(java.util.Map props, java.util.List commands)


execScript

@Override
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!


execShell

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


execShell

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


execShellDirect

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


isConnected

@Override
public boolean isConnected()


newSessionAction

protected SshAction newSessionAction()


transferFileFrom

@Override
public int transferFileFrom(java.util.Map props, java.lang.String pathAndFileOnRemoteServer, java.lang.String pathAndFileOnLocalServer)


transferFileTo

@Override
public int transferFileTo(java.util.Map props, java.io.InputStream input, java.lang.String pathAndFileOnRemoteServer)


 

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