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;
}
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());
}
}
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());
}
}
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());
}
Aggregations