Search in sources :

Example 1 with DockerContainerNotFoundException

use of org.eclipse.linuxtools.docker.core.DockerContainerNotFoundException in project linuxtools by eclipse.

the class DockerConnection method removeContainer.

@Override
public void removeContainer(final String id) throws DockerException, InterruptedException {
    try {
        // kill container
        client.removeContainer(id);
        // update container list
        listContainers();
    } catch (ContainerNotFoundException e) {
        throw new DockerContainerNotFoundException(e);
    } catch (com.spotify.docker.client.exceptions.DockerRequestException e) {
        throw new DockerException(e.message());
    } catch (com.spotify.docker.client.exceptions.DockerException e) {
        throw new DockerException(e.getMessage(), e.getCause());
    }
}
Also used : DockerException(org.eclipse.linuxtools.docker.core.DockerException) DockerContainerNotFoundException(org.eclipse.linuxtools.docker.core.DockerContainerNotFoundException) ContainerNotFoundException(com.spotify.docker.client.exceptions.ContainerNotFoundException) DockerContainerNotFoundException(org.eclipse.linuxtools.docker.core.DockerContainerNotFoundException)

Example 2 with DockerContainerNotFoundException

use of org.eclipse.linuxtools.docker.core.DockerContainerNotFoundException in project linuxtools by eclipse.

the class DockerConnection method createContainer.

@Override
public String createContainer(final IDockerContainerConfig c, IDockerHostConfig hc, final String containerName) throws DockerException, InterruptedException {
    try {
        HostConfig.Builder hbuilder = HostConfig.builder().containerIdFile(hc.containerIDFile()).publishAllPorts(hc.publishAllPorts()).privileged(hc.privileged()).networkMode(hc.networkMode()).readonlyRootfs(((DockerHostConfig) hc).readonlyRootfs());
        if (((DockerHostConfig) hc).tmpfs() != null) {
            hbuilder.tmpfs(ImmutableMap.copyOf(((DockerHostConfig) hc).tmpfs()));
        }
        if (((DockerHostConfig) hc).capAdd() != null) {
            hbuilder.capAdd(((DockerHostConfig) hc).capAdd());
        }
        if (((DockerHostConfig) hc).capDrop() != null) {
            hbuilder.capDrop(((DockerHostConfig) hc).capDrop());
        }
        if (hc.binds() != null)
            hbuilder.binds(hc.binds());
        if (hc.dns() != null)
            hbuilder.dns(hc.dns());
        if (hc.dnsSearch() != null)
            hbuilder.dnsSearch(hc.dnsSearch());
        if (hc.links() != null)
            hbuilder.links(hc.links());
        if (hc.lxcConf() != null) {
            List<IDockerConfParameter> lxcconf = hc.lxcConf();
            ArrayList<LxcConfParameter> lxcreal = new ArrayList<>();
            for (IDockerConfParameter param : lxcconf) {
            // TODO: Fix This
            }
            hbuilder.lxcConf(lxcreal);
        }
        if (hc.portBindings() != null) {
            Map<String, List<IDockerPortBinding>> bindings = hc.portBindings();
            HashMap<String, List<PortBinding>> realBindings = new HashMap<>();
            for (Entry<String, List<IDockerPortBinding>> entry : bindings.entrySet()) {
                String key = entry.getKey();
                List<IDockerPortBinding> bindingList = entry.getValue();
                ArrayList<PortBinding> newList = new ArrayList<>();
                for (IDockerPortBinding binding : bindingList) {
                    newList.add(PortBinding.of(binding.hostIp(), binding.hostPort()));
                }
                realBindings.put(key, newList);
            }
            hbuilder.portBindings(realBindings);
        }
        if (hc.volumesFrom() != null) {
            hbuilder.volumesFrom(hc.volumesFrom());
        }
        if (hc.securityOpt() != null) {
            hbuilder.securityOpt(hc.securityOpt());
        }
        // interface
        if (((DockerHostConfig) hc).memory() != null) {
            hbuilder.memory(((DockerHostConfig) hc).memory());
        }
        // interface
        if (((DockerHostConfig) hc).cpuShares() != null && ((DockerHostConfig) hc).cpuShares().longValue() > 0) {
            hbuilder.cpuShares(((DockerHostConfig) hc).cpuShares());
        }
        ContainerConfig.Builder builder = ContainerConfig.builder().hostname(c.hostname()).domainname(c.domainname()).user(c.user()).attachStdin(c.attachStdin()).attachStdout(c.attachStdout()).attachStderr(c.attachStderr()).tty(c.tty()).openStdin(c.openStdin()).stdinOnce(c.stdinOnce()).cmd(c.cmd()).image(c.image()).hostConfig(hbuilder.build()).workingDir(c.workingDir()).labels(c.labels()).networkDisabled(c.networkDisabled());
        // don't set those fields in the builder.
        if (c.portSpecs() != null) {
            builder = builder.portSpecs(c.portSpecs());
        }
        if (c.exposedPorts() != null) {
            builder = builder.exposedPorts(c.exposedPorts());
        }
        if (c.env() != null) {
            builder = builder.env(c.env());
        }
        if (c.volumes() != null) {
            builder = builder.volumes(c.volumes());
        }
        if (c.entrypoint() != null) {
            builder = builder.entrypoint(c.entrypoint());
        }
        if (c.onBuild() != null) {
            builder = builder.onBuild(c.onBuild());
        }
        // create container with default random name if an empty/null
        // containerName argument was passed
        final ContainerCreation creation = client.createContainer(builder.build(), (containerName != null && !containerName.isEmpty()) ? containerName : null);
        final String id = creation.id();
        // force a refresh of the current containers to include the new one
        listContainers();
        return id;
    } catch (ContainerNotFoundException e) {
        throw new DockerContainerNotFoundException(e);
    } catch (com.spotify.docker.client.exceptions.DockerRequestException e) {
        throw new DockerException(e.message());
    } catch (com.spotify.docker.client.exceptions.DockerException e) {
        throw new DockerException(e);
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ContainerConfig(com.spotify.docker.client.messages.ContainerConfig) IDockerContainerConfig(org.eclipse.linuxtools.docker.core.IDockerContainerConfig) IDockerPortBinding(org.eclipse.linuxtools.docker.core.IDockerPortBinding) IDockerHostConfig(org.eclipse.linuxtools.docker.core.IDockerHostConfig) HostConfig(com.spotify.docker.client.messages.HostConfig) LxcConfParameter(com.spotify.docker.client.messages.HostConfig.LxcConfParameter) ListenerList(org.eclipse.core.runtime.ListenerList) ArrayList(java.util.ArrayList) List(java.util.List) ContainerNotFoundException(com.spotify.docker.client.exceptions.ContainerNotFoundException) DockerContainerNotFoundException(org.eclipse.linuxtools.docker.core.DockerContainerNotFoundException) IDockerHostConfig(org.eclipse.linuxtools.docker.core.IDockerHostConfig) DockerException(org.eclipse.linuxtools.docker.core.DockerException) DockerContainerNotFoundException(org.eclipse.linuxtools.docker.core.DockerContainerNotFoundException) IDockerConfParameter(org.eclipse.linuxtools.docker.core.IDockerConfParameter) ContainerCreation(com.spotify.docker.client.messages.ContainerCreation) IDockerPortBinding(org.eclipse.linuxtools.docker.core.IDockerPortBinding) PortBinding(com.spotify.docker.client.messages.PortBinding)

Example 3 with DockerContainerNotFoundException

use of org.eclipse.linuxtools.docker.core.DockerContainerNotFoundException in project linuxtools by eclipse.

the class DockerConnection method pauseContainer.

@Override
public void pauseContainer(final String id) throws DockerException, InterruptedException {
    try {
        // pause container
        client.pauseContainer(id);
        // update container list
        listContainers();
    } catch (ContainerNotFoundException e) {
        throw new DockerContainerNotFoundException(e);
    } catch (com.spotify.docker.client.exceptions.DockerRequestException e) {
        throw new DockerException(e.message());
    } catch (com.spotify.docker.client.exceptions.DockerException e) {
        throw new DockerException(e.getMessage(), e.getCause());
    }
}
Also used : DockerException(org.eclipse.linuxtools.docker.core.DockerException) DockerContainerNotFoundException(org.eclipse.linuxtools.docker.core.DockerContainerNotFoundException) ContainerNotFoundException(com.spotify.docker.client.exceptions.ContainerNotFoundException) DockerContainerNotFoundException(org.eclipse.linuxtools.docker.core.DockerContainerNotFoundException)

Example 4 with DockerContainerNotFoundException

use of org.eclipse.linuxtools.docker.core.DockerContainerNotFoundException in project linuxtools by eclipse.

the class DockerConnection method logContainer.

@Override
public void logContainer(final String id, final OutputStream stream) throws DockerException, InterruptedException {
    try {
        // or keep running
        synchronized (loggingThreads) {
            ContainerInfo info = client.inspectContainer(id);
            LogThread t = loggingThreads.get(id);
            if (t == null || !t.isAlive()) {
                t = new LogThread(id, getClientCopy(), info.state().running());
                loggingThreads.put(id, t);
                t.setOutputStream(stream);
                t.start();
            } else {
                // we aren't going to use the stream given...close it
                try {
                    stream.close();
                } catch (IOException e) {
                // do nothing...we tried to close the stream
                }
            }
        }
    } catch (ContainerNotFoundException e) {
        throw new DockerContainerNotFoundException(e);
    } catch (com.spotify.docker.client.exceptions.DockerRequestException e) {
        throw new DockerException(e.message());
    } catch (com.spotify.docker.client.exceptions.DockerException e) {
        throw new DockerException(e.getMessage(), e.getCause());
    }
}
Also used : DockerException(org.eclipse.linuxtools.docker.core.DockerException) DockerContainerNotFoundException(org.eclipse.linuxtools.docker.core.DockerContainerNotFoundException) ContainerInfo(com.spotify.docker.client.messages.ContainerInfo) IDockerContainerInfo(org.eclipse.linuxtools.docker.core.IDockerContainerInfo) IOException(java.io.IOException) ContainerNotFoundException(com.spotify.docker.client.exceptions.ContainerNotFoundException) DockerContainerNotFoundException(org.eclipse.linuxtools.docker.core.DockerContainerNotFoundException)

Example 5 with DockerContainerNotFoundException

use of org.eclipse.linuxtools.docker.core.DockerContainerNotFoundException in project linuxtools by eclipse.

the class DockerConnection method killContainer.

@Override
public void killContainer(final String id) throws DockerException, InterruptedException {
    try {
        // kill container
        client.killContainer(id);
        synchronized (loggingThreads) {
            if (loggingThreads.containsKey(id)) {
                loggingThreads.get(id).kill();
                loggingThreads.remove(id);
            }
        }
        // update container list
        listContainers();
    } catch (ContainerNotFoundException e) {
        throw new DockerContainerNotFoundException(e);
    } catch (com.spotify.docker.client.exceptions.DockerRequestException e) {
    // Permit kill to fail silently even on non-running containers
    } catch (com.spotify.docker.client.exceptions.DockerException e) {
        throw new DockerException(e.getMessage(), e.getCause());
    }
}
Also used : DockerException(org.eclipse.linuxtools.docker.core.DockerException) DockerContainerNotFoundException(org.eclipse.linuxtools.docker.core.DockerContainerNotFoundException) ContainerNotFoundException(com.spotify.docker.client.exceptions.ContainerNotFoundException) DockerContainerNotFoundException(org.eclipse.linuxtools.docker.core.DockerContainerNotFoundException)

Aggregations

DockerContainerNotFoundException (org.eclipse.linuxtools.docker.core.DockerContainerNotFoundException)10 DockerException (org.eclipse.linuxtools.docker.core.DockerException)10 ContainerNotFoundException (com.spotify.docker.client.exceptions.ContainerNotFoundException)9 IOException (java.io.IOException)2 IDockerContainerInfo (org.eclipse.linuxtools.docker.core.IDockerContainerInfo)2 DockerClient (com.spotify.docker.client.DockerClient)1 ContainerConfig (com.spotify.docker.client.messages.ContainerConfig)1 ContainerCreation (com.spotify.docker.client.messages.ContainerCreation)1 ContainerExit (com.spotify.docker.client.messages.ContainerExit)1 ContainerInfo (com.spotify.docker.client.messages.ContainerInfo)1 HostConfig (com.spotify.docker.client.messages.HostConfig)1 LxcConfParameter (com.spotify.docker.client.messages.HostConfig.LxcConfParameter)1 PortBinding (com.spotify.docker.client.messages.PortBinding)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 CoreException (org.eclipse.core.runtime.CoreException)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 ListenerList (org.eclipse.core.runtime.ListenerList)1 SubMonitor (org.eclipse.core.runtime.SubMonitor)1