Search in sources :

Example 36 with DockerException

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

the class DockerConnection method commitContainer.

@Override
public void commitContainer(final String id, final String repo, final String tag, final String comment, final String author) throws DockerException {
    ContainerInfo info;
    try {
        info = client.inspectContainer(id);
        client.commitContainer(id, repo, tag, info.config(), comment, author);
        // update images list
        // FIXME: are we refreshing the list of images twice ?
        listImages();
        getImages(true);
    } catch (com.spotify.docker.client.exceptions.DockerRequestException e) {
        throw new DockerException(e.message());
    } catch (com.spotify.docker.client.exceptions.DockerException | InterruptedException e) {
        throw new DockerException(e.getMessage(), e.getCause());
    }
}
Also used : DockerException(org.eclipse.linuxtools.docker.core.DockerException) ContainerInfo(com.spotify.docker.client.messages.ContainerInfo) IDockerContainerInfo(org.eclipse.linuxtools.docker.core.IDockerContainerInfo)

Example 37 with DockerException

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

the class DockerConnection method waitForContainer.

@Override
public IDockerContainerExit waitForContainer(final String id) throws DockerException, InterruptedException {
    try {
        // wait for container to exit
        DockerClient copy = getClientCopy();
        ContainerExit x = copy.waitContainer(id);
        DockerContainerExit exit = new DockerContainerExit(x.statusCode());
        // update container list
        listContainers();
        // dispose of copy now we are finished
        copy.close();
        return exit;
    } 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) DockerClient(com.spotify.docker.client.DockerClient) ContainerExit(com.spotify.docker.client.messages.ContainerExit) IDockerContainerExit(org.eclipse.linuxtools.docker.core.IDockerContainerExit) IDockerContainerExit(org.eclipse.linuxtools.docker.core.IDockerContainerExit) ContainerNotFoundException(com.spotify.docker.client.exceptions.ContainerNotFoundException) DockerContainerNotFoundException(org.eclipse.linuxtools.docker.core.DockerContainerNotFoundException)

Example 38 with DockerException

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

the class DockerConnection method listImages.

// TODO: remove this method from the API
@Override
public List<IDockerImage> listImages() throws DockerException {
    final List<IDockerImage> tempImages = new ArrayList<>();
    synchronized (imageLock) {
        try {
            final List<Image> nativeImages = new ArrayList<>();
            synchronized (clientLock) {
                // containers list left in the queue
                if (client == null) {
                    // there's no client.
                    return Collections.emptyList();
                }
                nativeImages.addAll(client.listImages(DockerClient.ListImagesParam.allImages()));
            }
            // images.
            for (Image nativeImage : nativeImages) {
                final DockerImageQualifier imageQualifier = resolveQualifier(nativeImage, nativeImages);
                // return one IDockerImage per raw image
                final List<String> repoTags = (nativeImage.repoTags() != null) ? new ArrayList<>(nativeImage.repoTags()) : new ArrayList<>();
                Collections.sort(repoTags);
                if (repoTags.isEmpty()) {
                    // $NON-NLS-1$
                    repoTags.add("<none>:<none>");
                }
                final String repo = DockerImage.extractRepo(repoTags.get(0));
                final List<String> tags = Arrays.asList(DockerImage.extractTag(repoTags.get(0)));
                tempImages.add(new DockerImage(this, repoTags, repo, tags, nativeImage.id(), nativeImage.parentId(), nativeImage.created(), nativeImage.size(), nativeImage.virtualSize(), imageQualifier));
            }
        } catch (com.spotify.docker.client.exceptions.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.DockerRequestException e) {
            throw new DockerException(e.message());
        } 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(NLS.bind(Messages.List_Docker_Images_Failure, this.getName()), e);
            }
        } finally {
            this.images = tempImages;
        }
    }
    // Perform notification outside of lock so that listener doesn't cause a
    // deadlock to occur
    notifyImageListeners(tempImages);
    return tempImages;
}
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) DockerImageQualifier(org.eclipse.linuxtools.internal.docker.core.DockerImage.DockerImageQualifier) ArrayList(java.util.ArrayList) IDockerImage(org.eclipse.linuxtools.docker.core.IDockerImage) Image(com.spotify.docker.client.messages.Image) DockerTimeoutException(com.spotify.docker.client.exceptions.DockerTimeoutException) IDockerImage(org.eclipse.linuxtools.docker.core.IDockerImage) IDockerImage(org.eclipse.linuxtools.docker.core.IDockerImage) ProcessingException(javax.ws.rs.ProcessingException)

Example 39 with DockerException

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

the class DockerConnection method copyContainer.

@Override
public InputStream copyContainer(final String id, final String path) throws DockerException, InterruptedException {
    InputStream stream;
    try {
        DockerClient copy = getClientCopy();
        stream = copy.archiveContainer(id, path);
    } catch (com.spotify.docker.client.exceptions.DockerException e) {
        throw new DockerException(e.getMessage(), e.getCause());
    }
    return stream;
}
Also used : DockerException(org.eclipse.linuxtools.docker.core.DockerException) DockerClient(com.spotify.docker.client.DockerClient) InputStream(java.io.InputStream)

Example 40 with DockerException

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

the class DockerConnection method execShell.

public void execShell(final String id) throws DockerException {
    try {
        final ExecCreation execCreation = client.execCreate(id, // $NON-NLS-1$
        new String[] { "/bin/sh" }, ExecCreateParam.attachStdout(), ExecCreateParam.attachStderr(), ExecCreateParam.attachStdin(), ExecCreateParam.tty());
        final String execId = execCreation.id();
        final LogStream pty_stream = client.execStart(execId, DockerClient.ExecStartParameter.TTY);
        final IDockerContainerInfo info = getContainerInfo(id);
        // $NON-NLS-1$
        openTerminal(pty_stream, info.name() + " [shell]", null);
    } catch (Exception e) {
        throw new DockerException(e.getMessage(), e.getCause());
    }
}
Also used : DockerException(org.eclipse.linuxtools.docker.core.DockerException) ExecCreation(com.spotify.docker.client.messages.ExecCreation) LogStream(com.spotify.docker.client.LogStream) IDockerContainerInfo(org.eclipse.linuxtools.docker.core.IDockerContainerInfo) DockerPingConnectionException(org.eclipse.linuxtools.docker.core.DockerPingConnectionException) DockerTimeoutException(com.spotify.docker.client.exceptions.DockerTimeoutException) ProcessingException(javax.ws.rs.ProcessingException) ContainerNotFoundException(com.spotify.docker.client.exceptions.ContainerNotFoundException) DockerCertificateException(com.spotify.docker.client.exceptions.DockerCertificateException) SocketException(java.net.SocketException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) StorageException(org.eclipse.equinox.security.storage.StorageException) DockerContainerNotFoundException(org.eclipse.linuxtools.docker.core.DockerContainerNotFoundException) DockerException(org.eclipse.linuxtools.docker.core.DockerException) DockerOpenConnectionException(org.eclipse.linuxtools.docker.core.DockerOpenConnectionException)

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