Search in sources :

Example 1 with IDockerImageHierarchyNode

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

the class DockerImageHierarchyNodeUtils method resolveChildrenImageNodes.

private static void resolveChildrenImageNodes(final List<IDockerImage> images, final List<IDockerContainer> containers, final String imageId, final List<String> imageRepoTags, final IDockerImageHierarchyNode parentNode) {
    // recursively find all parents and build associated
    // IDockerImageHierarchyNode instances
    images.stream().filter(image -> image.parentId() != null && image.parentId().equals(imageId)).forEach(image -> {
        final DockerImageHierarchyNode childNode = new DockerImageHierarchyImageNode(image, parentNode);
        resolveChildrenImageNodes(images, containers, image.id(), image.repoTags(), childNode);
    });
    containers.stream().filter(container -> container.image() != null && imageRepoTags.contains(container.image())).forEach(container -> new DockerImageHierarchyContainerNode(container, parentNode));
}
Also used : List(java.util.List) IDockerImage(org.eclipse.linuxtools.docker.core.IDockerImage) IDockerContainer(org.eclipse.linuxtools.docker.core.IDockerContainer) IDockerImageHierarchyNode(org.eclipse.linuxtools.docker.core.IDockerImageHierarchyNode) IDockerImageHierarchyNode(org.eclipse.linuxtools.docker.core.IDockerImageHierarchyNode)

Example 2 with IDockerImageHierarchyNode

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

the class DockerImageHierarchyNodeUtils method getDockerImageHierarchyNode.

private static DockerImageHierarchyNode getDockerImageHierarchyNode(final List<IDockerImage> images, final List<IDockerContainer> containers, final IDockerImage image, final IDockerImageHierarchyNode parentImageNode) {
    final DockerImageHierarchyNode imageNode = new DockerImageHierarchyImageNode(image, parentImageNode);
    // also includes all children images/containers, recursively
    resolveChildrenImageNodes(images, containers, image.id(), image.repoTags(), imageNode);
    return imageNode;
}
Also used : IDockerImageHierarchyNode(org.eclipse.linuxtools.docker.core.IDockerImageHierarchyNode)

Example 3 with IDockerImageHierarchyNode

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

the class DockerImageHierarchyNodeUtils method resolveImageHierarchy.

public static IDockerImageHierarchyNode resolveImageHierarchy(final List<IDockerImage> images, final IDockerContainer container) {
    final IDockerImageHierarchyNode parentImageNode = getContainerParentImageNode(images, container.image());
    final DockerImageHierarchyNode dockerImageHierarchyNode = getDockerImageHierarchyNode(container, parentImageNode);
    return dockerImageHierarchyNode;
}
Also used : IDockerImageHierarchyNode(org.eclipse.linuxtools.docker.core.IDockerImageHierarchyNode) IDockerImageHierarchyNode(org.eclipse.linuxtools.docker.core.IDockerImageHierarchyNode)

Example 4 with IDockerImageHierarchyNode

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

the class DockerImageHierarchyViewAssertions method hasSelectedElement.

public void hasSelectedElement(final IDockerImage expectedSelection) {
    notNullValue();
    final IStructuredSelection selection = (IStructuredSelection) actual.getCommonViewer().getSelection();
    if (selection.size() != 1) {
        failWithMessage("Expected Docker Image Hierarchy view to have <%s> selected elements, but there was <%s>", 1, selection.size());
    }
    final Object selectedElement = ((IDockerImageHierarchyNode) selection.getFirstElement()).getElement();
    if (selectedElement instanceof IDockerImage) {
        final IDockerImage selectedImage = (IDockerImage) selectedElement;
        if (!selectedImage.id().equals(expectedSelection.id())) {
            failWithMessage("Expected Docker Image Hierarchy view to have a Docker images with id <%s> as the selected element, but it was <%s>", expectedSelection.id(), ((IDockerImage) selectedElement).id());
        }
    } else {
        failWithMessage("Expected Docker Image Hierarchy view to have a Docker Image as the selected element, but it was a <%s>", selectedElement.getClass());
    }
}
Also used : IDockerImageHierarchyNode(org.eclipse.linuxtools.docker.core.IDockerImageHierarchyNode) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IDockerImage(org.eclipse.linuxtools.docker.core.IDockerImage)

Example 5 with IDockerImageHierarchyNode

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

the class DockerImageHierarchyViewSWTBotTest method shouldRetrieveImageHierarchyFromLeafImage.

@Test
public void shouldRetrieveImageHierarchyFromLeafImage() {
    // given
    final IDockerImage fooImage2 = this.connection.getImage("sha256:foo_image2");
    // when
    final IDockerImageHierarchyNode fooImage2Hierarchy = this.connection.resolveImageHierarchy(fooImage2);
    // then
    assertThat(fooImage2Hierarchy).isNotNull();
    assertThat(fooImage2Hierarchy.getElement()).isEqualTo(fooImage2);
    // 2 containers: foo_container21 and foo_container22
    assertThat(fooImage2Hierarchy.getChildren()).hasSize(2);
    assertThat((IDockerContainer) fooImage2Hierarchy.getChild("sha256:foo_container21").getElement()).isNotNull();
    final IDockerImageHierarchyNode fooImage1Hierarchy = fooImage2Hierarchy.getParent();
    final IDockerImage fooImage = (IDockerImage) fooImage1Hierarchy.getElement();
    assertThat(fooImage.id()).isEqualTo("sha256:foo_image1");
    // in this case, intermediate images shows a single child
    assertThat(fooImage1Hierarchy.getChildren()).hasSize(1);
    assertThat(fooImage1Hierarchy.getChildren()).containsExactly(fooImage2Hierarchy);
}
Also used : IDockerContainer(org.eclipse.linuxtools.docker.core.IDockerContainer) IDockerImageHierarchyNode(org.eclipse.linuxtools.docker.core.IDockerImageHierarchyNode) IDockerImage(org.eclipse.linuxtools.docker.core.IDockerImage) Test(org.junit.Test)

Aggregations

IDockerImageHierarchyNode (org.eclipse.linuxtools.docker.core.IDockerImageHierarchyNode)10 IDockerImage (org.eclipse.linuxtools.docker.core.IDockerImage)7 Test (org.junit.Test)5 IDockerContainer (org.eclipse.linuxtools.docker.core.IDockerContainer)4 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 List (java.util.List)1