Search in sources :

Example 1 with DockerContainer

use of org.eclipse.linuxtools.internal.docker.core.DockerContainer in project linuxtools by eclipse.

the class DockerExplorerContentProvider method loadContainerInfo.

/**
 * Call the {@link IDockerConnection#getContainers(boolean)} in a background
 * job to avoid blocking the UI.
 *
 * @param container
 *            the selected {@link DockerContainersCategory}
 */
private void loadContainerInfo(final IDockerContainer container) {
    final Job loadContainersJob = new LoadingJob(// $NON-NLS-1$
    DVMessages.getString("ContainerInfoLoadJob.msg"), // $NON-NLS-1$
    container) {

        @Override
        protected IStatus run(final IProgressMonitor monitor) {
            ((DockerContainer) container).info(true);
            return Status.OK_STATUS;
        }
    };
    loadContainersJob.schedule();
}
Also used : IDockerContainer(org.eclipse.linuxtools.docker.core.IDockerContainer) DockerContainer(org.eclipse.linuxtools.internal.docker.core.DockerContainer) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Job(org.eclipse.core.runtime.jobs.Job)

Example 2 with DockerContainer

use of org.eclipse.linuxtools.internal.docker.core.DockerContainer in project linuxtools by eclipse.

the class DockerExplorerContentProvider method getChildren.

@Override
public Object[] getChildren(final Object parentElement) {
    if (parentElement instanceof IDockerConnection) {
        // check the connection availability before returning the
        // 'containers' and 'images' child nodes.
        final IDockerConnection connection = (IDockerConnection) parentElement;
        if (connection.isOpen()) {
            return new Object[] { new DockerImagesCategory(connection), new DockerContainersCategory(connection) };
        } else if (connection.getState() == EnumDockerConnectionState.UNKNOWN) {
            open(connection);
            return new Object[] { new LoadingStub(connection) };
        } else if (connection.getState() == EnumDockerConnectionState.CLOSED) {
            synchronized (openRetryJobs) {
                Job job = openRetryJobs.get(connection);
                if (job == null) {
                    openRetry(connection);
                }
            }
            return new Object[] { new LoadingStub(connection) };
        }
        return new Object[0];
    } else if (parentElement instanceof DockerContainersCategory) {
        final DockerContainersCategory containersCategory = (DockerContainersCategory) parentElement;
        final IDockerConnection connection = containersCategory.getConnection();
        if (connection.isContainersLoaded()) {
            return connection.getContainers().toArray();
        }
        loadContainers(containersCategory);
        return new Object[] { new LoadingStub(containersCategory) };
    } else if (parentElement instanceof DockerImagesCategory) {
        final DockerImagesCategory imagesCategory = (DockerImagesCategory) parentElement;
        final IDockerConnection connection = imagesCategory.getConnection();
        if (connection.isImagesLoaded()) {
            // here we duplicate the images to show one org/repo with all
            // its tags per node in the tree
            final List<IDockerImage> allImages = connection.getImages();
            final List<IDockerImage> explorerImages = splitImageTagsByRepo(allImages);
            return explorerImages.toArray();
        }
        loadImages(imagesCategory);
        return new Object[] { new LoadingStub(imagesCategory) };
    } else if (parentElement instanceof IDockerContainer) {
        final DockerContainer container = (DockerContainer) parentElement;
        if (container.isInfoLoaded()) {
            final IDockerContainerInfo info = container.info();
            final IDockerNetworkSettings networkSettings = (info != null) ? info.networkSettings() : null;
            final IDockerHostConfig hostConfig = (info != null) ? info.hostConfig() : null;
            return new Object[] { new DockerContainerPortMappingsCategory(container, (networkSettings != null) ? networkSettings.ports() : Collections.<String, List<IDockerPortBinding>>emptyMap()), new DockerContainerVolumesCategory(container, (hostConfig != null) ? hostConfig.binds() : Collections.<String>emptyList()), new DockerContainerLinksCategory(container, (hostConfig != null) ? hostConfig.links() : Collections.<String>emptyList()) };
        }
        loadContainerInfo(container);
        return new Object[] { new LoadingStub(container) };
    } else if (parentElement instanceof DockerContainerLinksCategory) {
        final DockerContainerLinksCategory linksCategory = (DockerContainerLinksCategory) parentElement;
        return linksCategory.getLinks().toArray();
    } else if (parentElement instanceof DockerContainerPortMappingsCategory) {
        final DockerContainerPortMappingsCategory portMappingsCategory = (DockerContainerPortMappingsCategory) parentElement;
        return portMappingsCategory.getPortMappings().toArray();
    } else if (parentElement instanceof DockerContainerVolumesCategory) {
        final DockerContainerVolumesCategory volumesCategory = (DockerContainerVolumesCategory) parentElement;
        return volumesCategory.getVolumes().toArray();
    }
    return EMPTY;
}
Also used : IDockerContainer(org.eclipse.linuxtools.docker.core.IDockerContainer) IDockerContainer(org.eclipse.linuxtools.docker.core.IDockerContainer) DockerContainer(org.eclipse.linuxtools.internal.docker.core.DockerContainer) IDockerNetworkSettings(org.eclipse.linuxtools.docker.core.IDockerNetworkSettings) IDockerHostConfig(org.eclipse.linuxtools.docker.core.IDockerHostConfig) IDockerPortBinding(org.eclipse.linuxtools.docker.core.IDockerPortBinding) IDockerConnection(org.eclipse.linuxtools.docker.core.IDockerConnection) IDockerImage(org.eclipse.linuxtools.docker.core.IDockerImage) IDockerContainerInfo(org.eclipse.linuxtools.docker.core.IDockerContainerInfo) Job(org.eclipse.core.runtime.jobs.Job)

Aggregations

Job (org.eclipse.core.runtime.jobs.Job)2 IDockerContainer (org.eclipse.linuxtools.docker.core.IDockerContainer)2 DockerContainer (org.eclipse.linuxtools.internal.docker.core.DockerContainer)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 IDockerConnection (org.eclipse.linuxtools.docker.core.IDockerConnection)1 IDockerContainerInfo (org.eclipse.linuxtools.docker.core.IDockerContainerInfo)1 IDockerHostConfig (org.eclipse.linuxtools.docker.core.IDockerHostConfig)1 IDockerImage (org.eclipse.linuxtools.docker.core.IDockerImage)1 IDockerNetworkSettings (org.eclipse.linuxtools.docker.core.IDockerNetworkSettings)1 IDockerPortBinding (org.eclipse.linuxtools.docker.core.IDockerPortBinding)1