use of org.apache.sshd.common.RuntimeSshException in project platformlayer by platformlayer.
the class MinaSshConnection method sshExecute0.
@Override
protected ProcessExecution sshExecute0(String command, TimeSpan timeout) throws SshException, IOException, InterruptedException {
try {
ByteArrayOutputStream stdoutBinary = new ByteArrayOutputStream();
ByteArrayOutputStream stderrBinary = new ByteArrayOutputStream();
int exitCode = sshExecute(command, stdoutBinary, stderrBinary, null, timeout);
ProcessExecution processExecution = new ProcessExecution(command, exitCode, stdoutBinary.toByteArray(), stderrBinary.toByteArray());
return processExecution;
} catch (RuntimeSshException e) {
throw new SshException("Unexpected SSH error", e);
}
}
use of org.apache.sshd.common.RuntimeSshException in project platformlayer by platformlayer.
the class MinaSshConnection method sshReadFile0.
@Override
protected byte[] sshReadFile0(String remoteFile, boolean sudo) throws IOException, InterruptedException, SshException {
MinaSshConnectionWrapper sshConnection = ensureConnected();
MinaScpClient scp = new MinaScpClient(sshConnection);
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
TimeSpan timeout = TimeSpan.FIVE_MINUTES;
scp.get(remoteFile, baos, timeout, sudo);
return baos.toByteArray();
} catch (IOException ioException) {
throw new SshException("Cannot read file", ioException);
} catch (SshException sshException) {
String message = sshException.getMessage();
if (message != null && message.endsWith(": No such file or directory")) {
return null;
}
throw sshException;
} catch (RuntimeSshException e) {
throw new SshException("Error reading file", e);
}
}
use of org.apache.sshd.common.RuntimeSshException in project karaf by apache.
the class Main method connectWithRetries.
private static ClientSession connectWithRetries(SshClient client, ClientConfig config) throws Exception {
ClientSession session = null;
int retries = 0;
do {
ConnectFuture future = client.connect(config.getUser(), config.getHost(), config.getPort());
future.await();
try {
session = future.getSession();
} catch (RuntimeSshException ex) {
if (retries++ < config.getRetryAttempts()) {
Thread.sleep(config.getRetryDelay() * 1000);
System.out.println("retrying (attempt " + retries + ") ...");
} else {
throw ex;
}
}
} while (session == null);
return session;
}
use of org.apache.sshd.common.RuntimeSshException in project karaf by apache.
the class DeployMojo method connect.
private ClientSession connect(SshClient client) throws IOException, InterruptedException {
int retries = 0;
ClientSession session = null;
do {
final ConnectFuture future = client.connect(user, host, port);
future.await();
try {
session = future.getSession();
} catch (RuntimeSshException ex) {
if (retries++ < attempts) {
Thread.sleep(TimeUnit.SECONDS.toMillis(delay));
getLog().info("retrying (attempt " + retries + ") ...");
} else {
throw ex;
}
}
} while (session == null);
return session;
}
use of org.apache.sshd.common.RuntimeSshException in project platformlayer by platformlayer.
the class MinaSshConnection method sshCopyData0.
@Override
protected void sshCopyData0(InputStream fileData, long dataLength, String remoteFile, String mode, boolean sudo) throws IOException, InterruptedException, SshException {
int lastSlash = remoteFile.lastIndexOf('/');
if (lastSlash == -1) {
throw new IllegalArgumentException("Expected dest file to be absolute path: " + remoteFile);
}
MinaSshConnectionWrapper sshConnection = ensureConnected();
MinaScpClient scp = new MinaScpClient(sshConnection);
String remoteDir = remoteFile.substring(0, lastSlash);
String filename = remoteFile.substring(lastSlash + 1);
try {
TimeSpan timeout = TimeSpan.FIVE_MINUTES;
scp.put(fileData, dataLength, filename, remoteDir, mode, timeout, sudo);
} catch (IOException ioException) {
throw new SshException("Cannot doing scp on file", ioException);
} catch (RuntimeSshException e) {
throw new SshException("Error doing scp on file", e);
}
}
Aggregations