Search in sources :

Example 6 with IDockerContainer

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

the class DockerImagesView method setConnection.

private void setConnection(final IDockerConnection connection) {
    if (connection != null && connection.equals(this.connection)) {
        return;
    }
    if (this.connection != null) {
        this.connection.removeImageListener(this);
    }
    this.connection = connection;
    if (this.viewer != null && this.connection != null) {
        final Job refreshJob = new Job(DVMessages.getString("ImagesRefresh.msg")) {

            @Override
            protected IStatus run(IProgressMonitor monitor) {
                connection.getImages(true);
                connection.addImageListener(DockerImagesView.this);
                Display.getDefault().asyncExec(() -> {
                    if (!viewer.getControl().isDisposed()) {
                        viewer.setInput(connection);
                        refreshViewTitle();
                    }
                });
                return Status.OK_STATUS;
            }
        };
        refreshJob.schedule();
    } else if (this.viewer != null) {
        viewer.setInput(new IDockerContainer[0]);
        form.setText(DVMessages.getString(NoConnectionSelected));
    }
}
Also used : IDockerContainer(org.eclipse.linuxtools.docker.core.IDockerContainer) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Job(org.eclipse.core.runtime.jobs.Job)

Example 7 with IDockerContainer

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

Example 8 with IDockerContainer

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

the class DockerImageHierarchyViewSWTBotTest method shouldRetrieveImageHierarchyFromContainerBasedOnLeafImage.

@Test
public void shouldRetrieveImageHierarchyFromContainerBasedOnLeafImage() {
    // given
    // when
    final IDockerContainer barContainer1 = this.connection.getContainer("sha256:bar_container1");
    final IDockerImageHierarchyNode barContainer1Hierarchy = this.connection.resolveImageHierarchy(barContainer1);
    // then
    assertThat(barContainer1Hierarchy).isNotNull();
    assertThat(barContainer1Hierarchy.getElement()).isEqualTo(barContainer1);
    assertThat(barContainer1Hierarchy.getChildren()).isEmpty();
    final IDockerImage barImageElement = (IDockerImage) barContainer1Hierarchy.getParent().getElement();
    assertThat(barImageElement.id()).isEqualTo("sha256:bar_image1");
}
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)

Example 9 with IDockerContainer

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

the class DockerImageHierarchyViewSWTBotTest method shouldRetrieveImageHierarchyFromContainerBasedOnIntermediateImage.

@Test
public void shouldRetrieveImageHierarchyFromContainerBasedOnIntermediateImage() {
    // given
    final IDockerContainer fooContainer1 = this.connection.getContainer("sha256:foo_container1");
    // when
    final IDockerImageHierarchyNode fooContainer1Hierarchy = this.connection.resolveImageHierarchy(fooContainer1);
    // then
    assertThat(fooContainer1Hierarchy).isNotNull();
    assertThat(fooContainer1Hierarchy.getElement()).isEqualTo(fooContainer1);
    assertThat(fooContainer1Hierarchy.getChildren()).isEmpty();
    final IDockerImage fooImage1 = (IDockerImage) fooContainer1Hierarchy.getParent().getElement();
    assertThat(fooImage1.id()).isEqualTo("sha256:foo_image1");
    // parent images hierarchy only shows the selected container as its
    // child.
    assertThat(fooContainer1Hierarchy.getParent().getChildren()).containsExactly(fooContainer1Hierarchy);
}
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)

Example 10 with IDockerContainer

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

the class BaseContainersCommandHandler method execute.

@Override
public Object execute(ExecutionEvent event) {
    final IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
    final List<IDockerContainer> selectedContainers = getSelectedContainers(activePart);
    final IDockerConnection connection = getCurrentConnection(activePart);
    if (connection == null || selectedContainers.isEmpty()) {
        return null;
    }
    final Job job = new Job(getJobName(selectedContainers)) {

        @Override
        protected IStatus run(final IProgressMonitor monitor) {
            if (confirmed(selectedContainers)) {
                monitor.beginTask(getJobName(selectedContainers), selectedContainers.size());
                for (final IDockerContainer container : selectedContainers) {
                    monitor.setTaskName(getTaskName(container));
                    executeInJob(container, connection);
                    monitor.worked(1);
                }
            }
            monitor.done();
            return Status.OK_STATUS;
        }
    };
    // job.setPriority(Job.LONG);
    job.setUser(true);
    job.schedule();
    return null;
}
Also used : IDockerContainer(org.eclipse.linuxtools.docker.core.IDockerContainer) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) IDockerConnection(org.eclipse.linuxtools.docker.core.IDockerConnection) Job(org.eclipse.core.runtime.jobs.Job)

Aggregations

IDockerContainer (org.eclipse.linuxtools.docker.core.IDockerContainer)25 IDockerConnection (org.eclipse.linuxtools.docker.core.IDockerConnection)9 IDockerImage (org.eclipse.linuxtools.docker.core.IDockerImage)8 Job (org.eclipse.core.runtime.jobs.Job)7 IWorkbenchPart (org.eclipse.ui.IWorkbenchPart)7 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)6 IDockerContainerInfo (org.eclipse.linuxtools.docker.core.IDockerContainerInfo)4 IDockerImageHierarchyNode (org.eclipse.linuxtools.docker.core.IDockerImageHierarchyNode)4 Test (org.junit.Test)4 DockerException (org.eclipse.linuxtools.docker.core.DockerException)3 RunConsole (org.eclipse.linuxtools.internal.docker.ui.consoles.RunConsole)3 DockerClient (com.spotify.docker.client.DockerClient)2 Container (com.spotify.docker.client.messages.Container)2 OutputStream (java.io.OutputStream)2 ArrayList (java.util.ArrayList)2 DockerContainerNotFoundException (org.eclipse.linuxtools.docker.core.DockerContainerNotFoundException)2 EnumDockerLoggingStatus (org.eclipse.linuxtools.docker.core.EnumDockerLoggingStatus)2 EnumDockerStatus (org.eclipse.linuxtools.docker.core.EnumDockerStatus)2 IDockerHostConfig (org.eclipse.linuxtools.docker.core.IDockerHostConfig)2 IDockerPortBinding (org.eclipse.linuxtools.docker.core.IDockerPortBinding)2