Search in sources :

Example 6 with Command

use of org.eclipse.che.api.core.model.machine.Command 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 7 with Command

use of org.eclipse.che.api.core.model.machine.Command 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 8 with Command

use of org.eclipse.che.api.core.model.machine.Command 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 9 with Command

use of org.eclipse.che.api.core.model.machine.Command in project che by eclipse.

the class DockerProcessTest method shouldThrowErrorWithRealPIDIfSocketTimeoutExceptionHappens.

/**
     * This test requires TCP access to docker API to get timeout exception.<br>
     * If default access to docker is UNIX socket try to reconfigure docker connector for this test.<br>
     * This test may fail if system doesn't allow such access.
     */
@Test(expectedExceptions = MachineException.class, expectedExceptionsMessageRegExp = "Command output read timeout is reached. Process is still running and has id \\d+ inside machine")
public void shouldThrowErrorWithRealPIDIfSocketTimeoutExceptionHappens() throws Exception {
    DockerConnectorConfiguration dockerConnectorConfiguration = this.dockerConnectorConfiguration;
    DockerConnector docker = this.docker;
    if ("unix".equals(dockerConnectorConfiguration.getDockerDaemonUri().getScheme())) {
        // access through unix socket - reconfigure to use tcp
        dockerConnectorConfiguration = new DockerConnectorConfiguration(new URI("http://localhost:2375"), null, new InitialAuthConfig(), new DefaultNetworkFinder());
        docker = new DockerConnector(dockerConnectorConfiguration, new DockerConnectionFactory(dockerConnectorConfiguration), new DockerRegistryAuthResolver(null, null), new DockerApiVersionPathPrefixProvider(""));
    }
    Command command = new CommandImpl("tailf", "tail -f /dev/null", "mvn");
    final DockerProcess dockerProcess = new DockerProcess(dockerConnectorProvider, command, container, "outputChannel", "/tmp/chetests", pidGenerator.incrementAndGet());
    dockerProcess.start(new SOUTLineConsumer());
}
Also used : CommandImpl(org.eclipse.che.api.machine.server.model.impl.CommandImpl) DockerRegistryAuthResolver(org.eclipse.che.plugin.docker.client.DockerRegistryAuthResolver) DockerConnector(org.eclipse.che.plugin.docker.client.DockerConnector) Command(org.eclipse.che.api.core.model.machine.Command) DockerConnectorConfiguration(org.eclipse.che.plugin.docker.client.DockerConnectorConfiguration) InitialAuthConfig(org.eclipse.che.plugin.docker.client.InitialAuthConfig) DockerApiVersionPathPrefixProvider(org.eclipse.che.plugin.docker.client.DockerApiVersionPathPrefixProvider) DefaultNetworkFinder(org.eclipse.che.plugin.docker.client.helper.DefaultNetworkFinder) DockerProcess(org.eclipse.che.plugin.docker.machine.DockerProcess) URI(java.net.URI) DockerConnectionFactory(org.eclipse.che.plugin.docker.client.connection.DockerConnectionFactory) Test(org.testng.annotations.Test)

Aggregations

Command (org.eclipse.che.api.core.model.machine.Command)9 CommandImpl (org.eclipse.che.api.machine.server.model.impl.CommandImpl)7 ConflictException (org.eclipse.che.api.core.ConflictException)4 ListLineConsumer (org.eclipse.che.api.core.util.ListLineConsumer)4 InstanceProcess (org.eclipse.che.api.machine.server.spi.InstanceProcess)4 IOException (java.io.IOException)3 MachineException (org.eclipse.che.api.machine.server.exception.MachineException)3 CountDownLatch (java.util.concurrent.CountDownLatch)2 AbstractLineConsumer (org.eclipse.che.api.core.util.AbstractLineConsumer)2 LineConsumer (org.eclipse.che.api.core.util.LineConsumer)2 SshMachineProcess (org.eclipse.che.plugin.machine.ssh.SshMachineProcess)2 Test (org.testng.annotations.Test)2 URI (java.net.URI)1 Map (java.util.Map)1 BadRequestException (org.eclipse.che.api.core.BadRequestException)1 DockerApiVersionPathPrefixProvider (org.eclipse.che.plugin.docker.client.DockerApiVersionPathPrefixProvider)1 DockerConnector (org.eclipse.che.plugin.docker.client.DockerConnector)1 DockerConnectorConfiguration (org.eclipse.che.plugin.docker.client.DockerConnectorConfiguration)1 DockerRegistryAuthResolver (org.eclipse.che.plugin.docker.client.DockerRegistryAuthResolver)1 InitialAuthConfig (org.eclipse.che.plugin.docker.client.InitialAuthConfig)1