use of org.eclipse.che.api.machine.server.exception.MachineException in project che by eclipse.
the class JschSshProcess method start.
// todo how to manage disconnections due to network failures?
@Override
public void start(LineConsumer output) throws MachineException {
try (PipedOutputStream pipedOS = new PipedOutputStream();
PipedInputStream pipedIS = new PipedInputStream(pipedOS);
BufferedReader outReader = new BufferedReader(new InputStreamReader(pipedIS))) {
exec.setOutputStream(pipedOS);
exec.setExtOutputStream(pipedOS);
exec.connect();
String outLine;
while ((outLine = outReader.readLine()) != null) {
output.writeLine(outLine);
}
} catch (IOException | JSchException e) {
throw new MachineException("Ssh machine command execution error:" + e.getLocalizedMessage());
} finally {
exec.disconnect();
}
}
use of org.eclipse.che.api.machine.server.exception.MachineException in project che by eclipse.
the class AbstractAgentLauncherTest method shouldLogAgentStartLogsIfMachineExceptionOccurs.
@Test(expectedExceptions = ServerException.class, expectedExceptionsMessageRegExp = "An error on agent start")
public void shouldLogAgentStartLogsIfMachineExceptionOccurs() throws Exception {
// given
doThrow(new MachineException("An error on agent start")).when(launcher).start(any(Instance.class), any(Agent.class), any(LineConsumer.class));
// when
launcher.launch(machine, agent);
// then
verify(launcher).logAsErrorAgentStartLogs(anyString(), anyString());
}
use of org.eclipse.che.api.machine.server.exception.MachineException in project che by eclipse.
the class AbstractAgentLauncherTest method shouldLogAgentStartLogsIfMachineExceptionOccursAfterAgentStartTimeoutHadReached.
@Test(expectedExceptions = ServerException.class, expectedExceptionsMessageRegExp = "An error on process kill")
public void shouldLogAgentStartLogsIfMachineExceptionOccursAfterAgentStartTimeoutHadReached() throws Exception {
// given
launcher = spy(new TestAgentLauncher(-1, 100, agentChecker));
when(agentChecker.isLaunched(any(Agent.class), any(InstanceProcess.class), any(Instance.class))).thenReturn(false);
doReturn(process).when(launcher).start(any(Instance.class), any(Agent.class), any(LineConsumer.class));
doThrow(new MachineException("An error on process kill")).when(process).kill();
// when
launcher.launch(machine, agent);
// then
verify(launcher).logAsErrorAgentStartLogs(anyString(), anyString());
}
use of org.eclipse.che.api.machine.server.exception.MachineException in project che by eclipse.
the class CommandExistsAgentChecker method isLaunched.
@Override
public boolean isLaunched(Agent agent, InstanceProcess process, Instance machine) throws MachineException {
Command command = new CommandImpl(format("Wait for %s, try %d", agent.getId(), ++counter), checkingCommand, "test");
try (ListLineConsumer lineConsumer = new ListLineConsumer()) {
InstanceProcess waitProcess = machine.createProcess(command, null);
waitProcess.start(lineConsumer);
return lineConsumer.getText().endsWith("[STDOUT] 0");
} catch (ConflictException e) {
throw new MachineException(e.getServiceError());
}
}
use of org.eclipse.che.api.machine.server.exception.MachineException in project che by eclipse.
the class ProcessIsLaunchedChecker method isLaunched.
@Override
public boolean isLaunched(Agent agent, InstanceProcess process, Instance machine) throws MachineException {
Command command = new CommandImpl(format("Wait for %s, try %d", agent.getId(), ++counter), format(CHECK_COMMAND, processNameToWait), "test");
try (ListLineConsumer lineConsumer = new ListLineConsumer()) {
InstanceProcess waitProcess = machine.createProcess(command, null);
waitProcess.start(lineConsumer);
return lineConsumer.getText().endsWith("[STDOUT] 0");
} catch (ConflictException e) {
throw new MachineException(e.getServiceError());
}
}
Aggregations