Search in sources :

Example 11 with CommandImpl

use of org.eclipse.che.api.machine.server.model.impl.CommandImpl in project che by eclipse.

the class AbstractAgentLauncherTest method shouldStartMachineProcessWithAgentScriptExecution.

@Test
public void shouldStartMachineProcessWithAgentScriptExecution() throws Exception {
    // given
    String agentId = "testAgentId";
    String agentScript = "testAgentScript";
    when(agent.getId()).thenReturn(agentId);
    when(agent.getScript()).thenReturn(agentScript);
    when(launcher.start(any(Instance.class), any(Agent.class), any(LineConsumer.class))).thenCallRealMethod();
    // when
    launcher.launch(machine, agent);
    // then
    verify(machine).createProcess(eq(new CommandImpl(agentId, agentScript, "agent")), eq(null));
}
Also used : CommandImpl(org.eclipse.che.api.machine.server.model.impl.CommandImpl) 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) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.testng.annotations.Test)

Example 12 with CommandImpl

use of org.eclipse.che.api.machine.server.model.impl.CommandImpl in project che by eclipse.

the class AbstractAgentLauncher method start.

protected InstanceProcess start(Instance machine, Agent agent, LineConsumer lineConsumer) throws ServerException {
    Command command = new CommandImpl(agent.getId(), agent.getScript(), "agent");
    InstanceProcess process = machine.createProcess(command, null);
    CountDownLatch countDownLatch = new CountDownLatch(1);
    executor.execute(ThreadLocalPropagateContext.wrap(() -> {
        try {
            countDownLatch.countDown();
            process.start(lineConsumer);
        } catch (ConflictException | MachineException e) {
            try {
                machine.getLogger().writeLine(format("[ERROR] %s", e.getMessage()));
            } catch (IOException ignored) {
            }
        }
    }));
    try {
        // ensure that code inside of task submitted to executor is called before end of this method
        countDownLatch.await();
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
    }
    return process;
}
Also used : CommandImpl(org.eclipse.che.api.machine.server.model.impl.CommandImpl) Command(org.eclipse.che.api.core.model.machine.Command) InstanceProcess(org.eclipse.che.api.machine.server.spi.InstanceProcess) IOException(java.io.IOException) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 13 with CommandImpl

use of org.eclipse.che.api.machine.server.model.impl.CommandImpl 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 14 with CommandImpl

use of org.eclipse.che.api.machine.server.model.impl.CommandImpl 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)

Example 15 with CommandImpl

use of org.eclipse.che.api.machine.server.model.impl.CommandImpl in project che by eclipse.

the class SshMachineExecAgentLauncher method start.

protected SshMachineProcess start(SshMachineInstance machine, Agent agent) throws ServerException {
    Command command = new CommandImpl(agent.getId(), agent.getScript(), "agent");
    SshMachineProcess process = machine.createProcess(command, null);
    LineConsumer lineConsumer = new AbstractLineConsumer() {

        @Override
        public void writeLine(String line) throws IOException {
            machine.getLogger().writeLine(line);
        }
    };
    CountDownLatch countDownLatch = new CountDownLatch(1);
    executor.execute(ThreadLocalPropagateContext.wrap(() -> {
        try {
            countDownLatch.countDown();
            process.start(lineConsumer);
        } catch (ConflictException | MachineException e) {
            try {
                machine.getLogger().writeLine(format("[ERROR] %s", e.getMessage()));
            } catch (IOException ignored) {
            }
        } finally {
            try {
                lineConsumer.close();
            } catch (IOException ignored) {
            }
        }
    }));
    try {
        // ensure that code inside of task submitted to executor is called before end of this method
        countDownLatch.await();
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
    }
    return process;
}
Also used : CommandImpl(org.eclipse.che.api.machine.server.model.impl.CommandImpl) ListLineConsumer(org.eclipse.che.api.core.util.ListLineConsumer) LineConsumer(org.eclipse.che.api.core.util.LineConsumer) AbstractLineConsumer(org.eclipse.che.api.core.util.AbstractLineConsumer) Command(org.eclipse.che.api.core.model.machine.Command) AbstractLineConsumer(org.eclipse.che.api.core.util.AbstractLineConsumer) SshMachineProcess(org.eclipse.che.plugin.machine.ssh.SshMachineProcess) IOException(java.io.IOException) CountDownLatch(java.util.concurrent.CountDownLatch)

Aggregations

CommandImpl (org.eclipse.che.api.machine.server.model.impl.CommandImpl)17 Command (org.eclipse.che.api.core.model.machine.Command)7 ConflictException (org.eclipse.che.api.core.ConflictException)6 ListLineConsumer (org.eclipse.che.api.core.util.ListLineConsumer)5 EnvironmentImpl (org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl)5 MachineException (org.eclipse.che.api.machine.server.exception.MachineException)4 ProjectConfigImpl (org.eclipse.che.api.workspace.server.model.impl.ProjectConfigImpl)4 WorkspaceConfigImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl)4 WorkspaceImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl)4 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 NotFoundException (org.eclipse.che.api.core.NotFoundException)3 ServerException (org.eclipse.che.api.core.ServerException)3 InstanceProcess (org.eclipse.che.api.machine.server.spi.InstanceProcess)3 EnvironmentRecipeImpl (org.eclipse.che.api.workspace.server.model.impl.EnvironmentRecipeImpl)3 ExtendedMachineImpl (org.eclipse.che.api.workspace.server.model.impl.ExtendedMachineImpl)3 ServerConf2Impl (org.eclipse.che.api.workspace.server.model.impl.ServerConf2Impl)3 SourceStorageImpl (org.eclipse.che.api.workspace.server.model.impl.SourceStorageImpl)3 SshMachineProcess (org.eclipse.che.plugin.machine.ssh.SshMachineProcess)3 Test (org.testng.annotations.Test)3