Search in sources :

Example 6 with InstanceProcess

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

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;
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) InstanceProcess(org.eclipse.che.api.machine.server.spi.InstanceProcess)

Example 8 with InstanceProcess

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);
    }
}
Also used : Exec(org.eclipse.che.plugin.docker.client.Exec) Matcher(java.util.regex.Matcher) MachineException(org.eclipse.che.api.machine.server.exception.MachineException) InstanceProcess(org.eclipse.che.api.machine.server.spi.InstanceProcess) IOException(java.io.IOException) LinkedList(java.util.LinkedList)

Example 9 with InstanceProcess

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));
}
Also used : ForbiddenException(org.eclipse.che.api.core.ForbiddenException) InstanceProcess(org.eclipse.che.api.machine.server.spi.InstanceProcess)

Aggregations

InstanceProcess (org.eclipse.che.api.machine.server.spi.InstanceProcess)9 IOException (java.io.IOException)5 Command (org.eclipse.che.api.core.model.machine.Command)4 MachineException (org.eclipse.che.api.machine.server.exception.MachineException)4 CommandImpl (org.eclipse.che.api.machine.server.model.impl.CommandImpl)4 ConflictException (org.eclipse.che.api.core.ConflictException)3 LineConsumer (org.eclipse.che.api.core.util.LineConsumer)3 ListLineConsumer (org.eclipse.che.api.core.util.ListLineConsumer)3 AbstractLineConsumer (org.eclipse.che.api.core.util.AbstractLineConsumer)2 LinkedList (java.util.LinkedList)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Matcher (java.util.regex.Matcher)1 ForbiddenException (org.eclipse.che.api.core.ForbiddenException)1 ServerException (org.eclipse.che.api.core.ServerException)1 CompositeLineConsumer (org.eclipse.che.api.core.util.CompositeLineConsumer)1 FileLineConsumer (org.eclipse.che.api.core.util.FileLineConsumer)1 WebsocketLineConsumer (org.eclipse.che.api.core.util.WebsocketLineConsumer)1 Instance (org.eclipse.che.api.machine.server.spi.Instance)1 MachineProcessEvent (org.eclipse.che.api.machine.shared.dto.event.MachineProcessEvent)1