use of org.platformlayer.ops.ssh.SshException in project platformlayer by platformlayer.
the class SshOpsTarget method doUpload.
@Override
public void doUpload(FileUpload upload) throws OpsException {
InputStream dataStream;
try {
dataStream = upload.data.getInputStream();
} catch (IOException e) {
throw new OpsException("Error opening data stream", e);
}
long dataLength = upload.data.getLength();
try {
log.info("Uploading file over ssh: " + upload.path);
sshConnection.sshCopyData(dataStream, dataLength, upload.path.getPath(), upload.mode, needSudo());
} catch (IOException e) {
throw new OpsException("Error during file upload", e);
} catch (InterruptedException e) {
ExceptionUtils.handleInterrupted(e);
throw new OpsException("Error during file upload", e);
} catch (SshException e) {
throw new OpsException("Error during file upload", e);
}
}
use of org.platformlayer.ops.ssh.SshException 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.platformlayer.ops.ssh.SshException 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.platformlayer.ops.ssh.SshException in project platformlayer by platformlayer.
the class MinaSshConnectionWrapper method connect.
public void connect(TimeSpan connectTimeout) throws SshException {
if (state != SshConnectionState.NotConnected) {
throw new IllegalStateException();
}
try {
SshClient client = sshContext.client;
System.out.println("New SSH connection to " + connectionInfo.getHost());
ConnectFuture connect = client.connect(connectionInfo.getSocketAddress());
if (!connect.await(connectTimeout.getTotalMilliseconds())) {
connect.cancel();
throw new SshException("Timeout while waiting for SSH connection to " + connectionInfo.getHost());
}
this.sshClientSession = connect.getSession();
if (this.sshClientSession == null) {
throw new IllegalStateException();
}
this.state = SshConnectionState.Connected;
} catch (Exception e) {
ExceptionUtils.handleInterrupted(e);
throw new SshException("Error connecting to SSH server @" + connectionInfo.getSocketAddress(), e);
}
}
use of org.platformlayer.ops.ssh.SshException in project platformlayer by platformlayer.
the class MinaSshConnectionWrapper method openSession.
public ChannelSession openSession(String command) throws SshException {
try {
boolean useAgentForwarding = sshContext.isAgentForwarding();
ChannelSession clientChannel = BugFixChannelExec.createExecChannel(sshClientSession, command, useAgentForwarding);
return clientChannel;
} catch (Exception e) {
ExceptionUtils.handleInterrupted(e);
throw new SshException("Error creating channel", e);
}
}
Aggregations