Package org.opennms.smoketest.utils
Class SshClient
- java.lang.Object
-
- org.opennms.smoketest.utils.SshClient
-
- All Implemented Interfaces:
AutoCloseable
public class SshClient extends Object implements AutoCloseable
A simple SSH client wrapper used to run shell commands.- Author:
- jwhite
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classSshClient.Streams
-
Field Summary
Fields Modifier and Type Field Description static intDEFAULT_TIMEOUT_MS
-
Constructor Summary
Constructors Constructor Description SshClient(InetSocketAddress addr, String username, String password)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static Callable<Boolean>canConnectViaSsh(InetSocketAddress addr, String username, String password)voidclose()InetSocketAddressgetAddr()StringgetStderr()StringgetStdout()StringgetStdoutOrNull()SshClient.StreamsgetStreams()booleanisShellClosed()Checks if the shell's channel is closed.Callable<Boolean>isShellClosedCallable()PrintStreamopenShell()voidsetTimeout(int timeoutInMs)
-
-
-
Field Detail
-
DEFAULT_TIMEOUT_MS
public static final int DEFAULT_TIMEOUT_MS
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
SshClient
public SshClient(InetSocketAddress addr, String username, String password)
-
-
Method Detail
-
openShell
public PrintStream openShell() throws Exception
- Throws:
Exception
-
getStdout
public String getStdout() throws IOException
- Throws:
IOException
-
getStdoutOrNull
public String getStdoutOrNull()
-
getStderr
public String getStderr() throws IOException
- Throws:
IOException
-
setTimeout
public void setTimeout(int timeoutInMs)
-
getAddr
public InetSocketAddress getAddr()
-
close
public void close() throws Exception- Specified by:
closein interfaceAutoCloseable- Throws:
Exception
-
isShellClosed
public boolean isShellClosed()
Checks if the shell's channel is closed. Can be used to make sure that stdout/stderr get fully populated after an exit/logout command is issued in the shell.
-
getStreams
public SshClient.Streams getStreams()
-
canConnectViaSsh
public static Callable<Boolean> canConnectViaSsh(InetSocketAddress addr, String username, String password)
-
-