Search in sources :

Example 6 with Exec

use of org.eclipse.che.plugin.docker.client.Exec 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)

Aggregations

IOException (java.io.IOException)6 Exec (org.eclipse.che.plugin.docker.client.Exec)6 MachineException (org.eclipse.che.api.machine.server.exception.MachineException)5 ListLineConsumer (org.eclipse.che.api.core.util.ListLineConsumer)2 SocketTimeoutException (java.net.SocketTimeoutException)1 LinkedList (java.util.LinkedList)1 Matcher (java.util.regex.Matcher)1 ConflictException (org.eclipse.che.api.core.ConflictException)1 NotFoundException (org.eclipse.che.api.core.NotFoundException)1 ValueHolder (org.eclipse.che.api.core.util.ValueHolder)1 InstanceProcess (org.eclipse.che.api.machine.server.spi.InstanceProcess)1