Search in sources :

Example 1 with DockerImageQualifier

use of org.eclipse.linuxtools.internal.docker.core.DockerImage.DockerImageQualifier 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)

Aggregations

DockerTimeoutException (com.spotify.docker.client.exceptions.DockerTimeoutException)1 Image (com.spotify.docker.client.messages.Image)1 ArrayList (java.util.ArrayList)1 ProcessingException (javax.ws.rs.ProcessingException)1 IStatus (org.eclipse.core.runtime.IStatus)1 Status (org.eclipse.core.runtime.Status)1 DockerException (org.eclipse.linuxtools.docker.core.DockerException)1 EnumDockerLoggingStatus (org.eclipse.linuxtools.docker.core.EnumDockerLoggingStatus)1 IDockerImage (org.eclipse.linuxtools.docker.core.IDockerImage)1 DockerImageQualifier (org.eclipse.linuxtools.internal.docker.core.DockerImage.DockerImageQualifier)1