Search in sources :

Example 21 with DockerException

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

the class DockerConnection method pullImage.

@Override
public void pullImage(final String imageId, final IRegistryAccount info, final IDockerProgressHandler handler) throws DockerException, InterruptedException, DockerCertificateException {
    try {
        final DockerClient client = dockerClientFactory.getClient(this.connectionSettings, info);
        final DockerProgressHandler d = new DockerProgressHandler(handler);
        client.pull(imageId, d);
        listImages();
    } catch (com.spotify.docker.client.exceptions.DockerRequestException e) {
        throw new DockerException(e.message());
    } catch (com.spotify.docker.client.exceptions.DockerException e) {
        DockerException f = new DockerException(e);
        throw f;
    }
}
Also used : DockerException(org.eclipse.linuxtools.docker.core.DockerException) IDockerProgressHandler(org.eclipse.linuxtools.docker.core.IDockerProgressHandler) DockerClient(com.spotify.docker.client.DockerClient)

Example 22 with DockerException

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

the class DockerConnection method containerChanges.

@Override
public List<IDockerContainerChange> containerChanges(final String id) throws DockerException, InterruptedException {
    List<IDockerContainerChange> containerChanges = new ArrayList<>();
    try {
        DockerClient copy = getClientCopy();
        List<ContainerChange> changes = copy.inspectContainerChanges(id);
        for (ContainerChange change : changes) {
            containerChanges.add(new DockerContainerChange(change.path(), change.kind()));
        }
    } catch (com.spotify.docker.client.exceptions.DockerException e) {
        throw new DockerException(e.getMessage(), e.getCause());
    }
    return containerChanges;
}
Also used : DockerException(org.eclipse.linuxtools.docker.core.DockerException) DockerClient(com.spotify.docker.client.DockerClient) IDockerContainerChange(org.eclipse.linuxtools.docker.core.IDockerContainerChange) ArrayList(java.util.ArrayList) ContainerChange(com.spotify.docker.client.messages.ContainerChange) IDockerContainerChange(org.eclipse.linuxtools.docker.core.IDockerContainerChange) IDockerContainerChange(org.eclipse.linuxtools.docker.core.IDockerContainerChange)

Example 23 with DockerException

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

the class DockerConnection method getContainerIdsWithLabels.

public Set<String> getContainerIdsWithLabels(Map<String, String> labels) throws DockerException {
    Set<String> labelSet = new HashSet<>();
    try {
        final List<Container> nativeContainers = new ArrayList<>();
        synchronized (clientLock) {
            // containers list left in the queue
            if (client == null) {
                // there's no client.
                return Collections.emptySet();
            }
            DockerClient clientCopy = getClientCopy();
            DockerClient.ListContainersParam[] parms = new DockerClient.ListContainersParam[2];
            parms[0] = DockerClient.ListContainersParam.allContainers();
            // DockerClient doesn't support multiple labels with its
            // ListContainersParam so we have
            // to do a kludge and put in control chars ourselves and pretend
            // we have a label with no value.
            // $NON-NLS-1$
            String separator = "";
            StringBuffer labelString = new StringBuffer();
            for (Entry<String, String> entry : labels.entrySet()) {
                labelString.append(separator);
                if (// $NON-NLS-1$
                entry.getValue() == null || "".equals(entry.getValue()))
                    labelString.append(entry.getKey());
                else {
                    labelString.append(// $NON-NLS-1$
                    entry.getKey() + "=" + entry.getValue());
                }
                // $NON-NLS-1$
                separator = "\",\"";
            }
            parms[1] = DockerClient.ListContainersParam.withLabel(labelString.toString());
            nativeContainers.addAll(clientCopy.listContainers(parms));
        }
        // Containers
        for (Container nativeContainer : nativeContainers) {
            labelSet.add(nativeContainer.id());
        }
    } catch (DockerTimeoutException e) {
        if (isOpen()) {
            Activator.log(new Status(IStatus.WARNING, Activator.PLUGIN_ID, Messages.Docker_Connection_Timeout, e));
            close();
        }
    } catch (com.spotify.docker.client.exceptions.DockerException | InterruptedException e) {
        if (isOpen() && e.getCause() != null && e.getCause().getCause() != null && e.getCause().getCause() instanceof ProcessingException) {
            close();
        } else {
            throw new DockerException(e.getMessage());
        }
    }
    return labelSet;
}
Also used : Status(org.eclipse.core.runtime.Status) EnumDockerLoggingStatus(org.eclipse.linuxtools.docker.core.EnumDockerLoggingStatus) IStatus(org.eclipse.core.runtime.IStatus) DockerException(org.eclipse.linuxtools.docker.core.DockerException) DockerClient(com.spotify.docker.client.DockerClient) DockerTimeoutException(com.spotify.docker.client.exceptions.DockerTimeoutException) ArrayList(java.util.ArrayList) IDockerContainer(org.eclipse.linuxtools.docker.core.IDockerContainer) Container(com.spotify.docker.client.messages.Container) HashSet(java.util.HashSet) ProcessingException(javax.ws.rs.ProcessingException)

Example 24 with DockerException

use of org.eclipse.linuxtools.docker.core.DockerException 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 25 with DockerException

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

the class DockerConnection method attachLog.

@Override
public void attachLog(final String id, final OutputStream out, final OutputStream err) throws DockerException, InterruptedException, IOException {
    DockerClient copyClient;
    try {
        copyClient = getClientCopy();
        LogStream stream = copyClient.logs(id, LogsParam.follow(), LogsParam.stdout(), LogsParam.stderr());
        stream.attach(out, err);
        stream.close();
    } catch (com.spotify.docker.client.exceptions.DockerException e) {
        throw new DockerException(e.getMessage(), e.getCause());
    }
}
Also used : DockerException(org.eclipse.linuxtools.docker.core.DockerException) DockerClient(com.spotify.docker.client.DockerClient) LogStream(com.spotify.docker.client.LogStream)

Aggregations

DockerException (org.eclipse.linuxtools.docker.core.DockerException)80 IDockerConnection (org.eclipse.linuxtools.docker.core.IDockerConnection)27 DockerConnection (org.eclipse.linuxtools.internal.docker.core.DockerConnection)19 Job (org.eclipse.core.runtime.jobs.Job)17 IOException (java.io.IOException)16 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)16 DockerContainerNotFoundException (org.eclipse.linuxtools.docker.core.DockerContainerNotFoundException)16 ContainerNotFoundException (com.spotify.docker.client.exceptions.ContainerNotFoundException)15 ArrayList (java.util.ArrayList)14 DockerClient (com.spotify.docker.client.DockerClient)13 IDockerContainerInfo (org.eclipse.linuxtools.docker.core.IDockerContainerInfo)10 IDockerImage (org.eclipse.linuxtools.docker.core.IDockerImage)9 DockerCertificateException (com.spotify.docker.client.exceptions.DockerCertificateException)8 DockerTimeoutException (com.spotify.docker.client.exceptions.DockerTimeoutException)7 ProcessingException (javax.ws.rs.ProcessingException)7 IPath (org.eclipse.core.runtime.IPath)7 RunConsole (org.eclipse.linuxtools.internal.docker.ui.consoles.RunConsole)7 LogStream (com.spotify.docker.client.LogStream)6 File (java.io.File)6 HashMap (java.util.HashMap)6