use of org.eclipse.che.api.core.model.machine.Command in project che by eclipse.
the class DefaultWorkspaceValidator method validateConfig.
@Override
public void validateConfig(WorkspaceConfig config) throws BadRequestException, ServerException {
// configuration object itself
checkNotNull(config.getName(), "Workspace name required");
checkArgument(WS_NAME.matcher(config.getName()).matches(), "Incorrect workspace name, it must be between 3 and 20 characters and may contain digits, " + "latin letters, underscores, dots, dashes and should start and end only with digits, " + "latin letters or underscores");
//environments
checkArgument(!isNullOrEmpty(config.getDefaultEnv()), "Workspace default environment name required");
checkNotNull(config.getEnvironments(), "Workspace should contain at least one environment");
checkArgument(config.getEnvironments().containsKey(config.getDefaultEnv()), "Workspace default environment configuration required");
for (Map.Entry<String, ? extends Environment> envEntry : config.getEnvironments().entrySet()) {
try {
environmentValidator.validate(envEntry.getKey(), envEntry.getValue());
} catch (IllegalArgumentException e) {
throw new BadRequestException(e.getLocalizedMessage());
}
}
//commands
for (Command command : config.getCommands()) {
checkArgument(!isNullOrEmpty(command.getName()), "Workspace %s contains command with null or empty name", config.getName());
checkArgument(!isNullOrEmpty(command.getCommandLine()), "Command line required for command '%s' in workspace '%s'", command.getName(), config.getName());
}
//projects
//TODO
}
use of org.eclipse.che.api.core.model.machine.Command in project che by eclipse.
the class DefaultAgentLauncher method launch.
@Override
public void launch(Instance machine, Agent agent) throws ServerException {
if (isNullOrEmpty(agent.getScript())) {
return;
}
final Command command = new CommandImpl(agent.getId(), agent.getScript(), "agent");
final InstanceProcess process = machine.createProcess(command, null);
final LineConsumer lineConsumer = new AbstractLineConsumer() {
@Override
public void writeLine(String line) throws IOException {
machine.getLogger().writeLine(line);
}
};
try {
process.start(lineConsumer);
} catch (ConflictException e) {
try {
machine.getLogger().writeLine(format("[ERROR] %s", e.getMessage()));
} catch (IOException ignored) {
}
} finally {
try {
lineConsumer.close();
} catch (IOException ignored) {
}
}
}
use of org.eclipse.che.api.core.model.machine.Command in project che by eclipse.
the class DefaultAgentLauncherTest method shouldLaunchAgent.
@Test
public void shouldLaunchAgent() throws Exception {
ArgumentCaptor<Command> commandCaptor = ArgumentCaptor.forClass(Command.class);
agentLauncher.launch(machine, agent);
verify(machine).createProcess(commandCaptor.capture(), (String) isNull());
Command command = commandCaptor.getValue();
assertEquals(command.getCommandLine(), "script1");
verify(instanceProcess).start(any());
}
use of org.eclipse.che.api.core.model.machine.Command in project che by eclipse.
the class SshProcessLaunchedChecker method isLaunched.
public boolean isLaunched(Agent agent, SshMachineInstance 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()) {
SshMachineProcess 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 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;
}
Aggregations