Search in sources :

Example 21 with MachineException

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();
    }
}
Also used : JSchException(com.jcraft.jsch.JSchException) InputStreamReader(java.io.InputStreamReader) MachineException(org.eclipse.che.api.machine.server.exception.MachineException) BufferedReader(java.io.BufferedReader) PipedOutputStream(java.io.PipedOutputStream) PipedInputStream(java.io.PipedInputStream) IOException(java.io.IOException)

Example 22 with MachineException

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());
}
Also used : Agent(org.eclipse.che.api.agent.shared.model.Agent) LineConsumer(org.eclipse.che.api.core.util.LineConsumer) Instance(org.eclipse.che.api.machine.server.spi.Instance) MachineException(org.eclipse.che.api.machine.server.exception.MachineException) Test(org.testng.annotations.Test)

Example 23 with MachineException

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());
}
Also used : Agent(org.eclipse.che.api.agent.shared.model.Agent) LineConsumer(org.eclipse.che.api.core.util.LineConsumer) Instance(org.eclipse.che.api.machine.server.spi.Instance) MachineException(org.eclipse.che.api.machine.server.exception.MachineException) InstanceProcess(org.eclipse.che.api.machine.server.spi.InstanceProcess) Test(org.testng.annotations.Test)

Example 24 with MachineException

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());
    }
}
Also used : CommandImpl(org.eclipse.che.api.machine.server.model.impl.CommandImpl) ListLineConsumer(org.eclipse.che.api.core.util.ListLineConsumer) Command(org.eclipse.che.api.core.model.machine.Command) ConflictException(org.eclipse.che.api.core.ConflictException) MachineException(org.eclipse.che.api.machine.server.exception.MachineException) InstanceProcess(org.eclipse.che.api.machine.server.spi.InstanceProcess)

Example 25 with MachineException

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());
    }
}
Also used : CommandImpl(org.eclipse.che.api.machine.server.model.impl.CommandImpl) ListLineConsumer(org.eclipse.che.api.core.util.ListLineConsumer) Command(org.eclipse.che.api.core.model.machine.Command) ConflictException(org.eclipse.che.api.core.ConflictException) MachineException(org.eclipse.che.api.machine.server.exception.MachineException) InstanceProcess(org.eclipse.che.api.machine.server.spi.InstanceProcess)

Aggregations

MachineException (org.eclipse.che.api.machine.server.exception.MachineException)35 IOException (java.io.IOException)17 ListLineConsumer (org.eclipse.che.api.core.util.ListLineConsumer)7 ConflictException (org.eclipse.che.api.core.ConflictException)6 ServerException (org.eclipse.che.api.core.ServerException)6 InstanceProcess (org.eclipse.che.api.machine.server.spi.InstanceProcess)6 JSchException (com.jcraft.jsch.JSchException)5 File (java.io.File)5 LineConsumer (org.eclipse.che.api.core.util.LineConsumer)5 Instance (org.eclipse.che.api.machine.server.spi.Instance)5 Test (org.testng.annotations.Test)5 Agent (org.eclipse.che.api.agent.shared.model.Agent)4 Command (org.eclipse.che.api.core.model.machine.Command)4 CommandImpl (org.eclipse.che.api.machine.server.model.impl.CommandImpl)4 Exec (org.eclipse.che.plugin.docker.client.Exec)4 URL (java.net.URL)3 NotFoundException (org.eclipse.che.api.core.NotFoundException)3 AbstractLineConsumer (org.eclipse.che.api.core.util.AbstractLineConsumer)3 ChannelExec (com.jcraft.jsch.ChannelExec)2 ChannelSftp (com.jcraft.jsch.ChannelSftp)2