use of org.eclipse.che.api.machine.server.spi.InstanceProcess 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.machine.server.spi.InstanceProcess in project che by eclipse.
the class DockerInstance method createProcess.
@Override
public InstanceProcess createProcess(Command command, String outputChannel) throws MachineException {
final Integer pid = pidSequence.getAndIncrement();
final InstanceProcess process = dockerMachineFactory.createProcess(command, container, outputChannel, String.format(PID_FILE_TEMPLATE, pid), pid);
machineProcesses.put(pid, process);
return process;
}
use of org.eclipse.che.api.machine.server.spi.InstanceProcess in project che by eclipse.
the class DockerInstance method getProcesses.
@Override
public List<InstanceProcess> getProcesses() throws MachineException {
List<InstanceProcess> processes = new LinkedList<>();
try {
final Exec exec = docker.createExec(CreateExecParams.create(container, new String[] { "/bin/sh", "-c", GET_ALIVE_PROCESSES_COMMAND }).withDetach(false));
docker.startExec(StartExecParams.create(exec.getId()), logMessage -> {
final String pidFilePath = logMessage.getContent().trim();
final Matcher matcher = PID_FILE_PATH_PATTERN.matcher(pidFilePath);
if (matcher.matches()) {
final int virtualPid = Integer.parseInt(matcher.group(1));
final InstanceProcess dockerProcess = machineProcesses.get(virtualPid);
if (dockerProcess != null) {
processes.add(dockerProcess);
} else {
LOG.warn("Machine process {} exists in container but missing in processes map", virtualPid);
}
}
});
return processes;
} catch (IOException e) {
throw new MachineException(e);
}
}
use of org.eclipse.che.api.machine.server.spi.InstanceProcess in project che by eclipse.
the class MachineProcessManager method stopProcess.
/**
* Stop process in machine
*
* @param machineId
* if of the machine where process should be stopped
* @param pid
* id of the process that should be stopped in machine
* @throws NotFoundException
* if machine or process with specified id not found
* @throws ForbiddenException
* if process is finished already
* @throws MachineException
* if other error occur
*/
public void stopProcess(String workspaceId, String machineId, int pid) throws NotFoundException, MachineException, ForbiddenException {
final InstanceProcess process = environmentEngine.getMachine(workspaceId, machineId).getProcess(pid);
if (!process.isAlive()) {
throw new ForbiddenException("Process finished already");
}
process.kill();
eventService.publish(newDto(MachineProcessEvent.class).withEventType(MachineProcessEvent.EventType.STOPPED).withMachineId(machineId).withProcessId(pid));
}
Aggregations