Search in sources :

Example 21 with IDockerImage

use of org.eclipse.linuxtools.docker.core.IDockerImage in project jbosstools-openshift by jbosstools.

the class DeployImageWizardModelTest method imagesFromDockerConnectionAreReturned.

@Test
public void imagesFromDockerConnectionAreReturned() {
    IDockerImage image = mock(IDockerImage.class);
    when(image.repoTags()).thenReturn(Collections.singletonList("image:latest"));
    when(dockerConnection.getImages()).thenReturn(Collections.singletonList(image));
    model.setDockerConnection(dockerConnection);
    assertThat(model.getImageNames()).isEqualTo(Collections.singletonList("image:latest"));
}
Also used : IDockerImage(org.eclipse.linuxtools.docker.core.IDockerImage) Test(org.junit.Test)

Example 22 with IDockerImage

use of org.eclipse.linuxtools.docker.core.IDockerImage in project jbosstools-openshift by jbosstools.

the class DeployImageHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    Connection connection = null;
    IProject project = null;
    ISelection selection = HandlerUtil.getCurrentSelection(event);
    final IDockerImage image = UIUtils.getFirstElement(selection, IDockerImage.class);
    if (image == null || OpenShiftUIUtils.hasOpenShiftExplorerSelection()) {
        selection = OpenShiftUIUtils.getOpenShiftExplorerSelection();
        project = ResourceUtils.getProject(UIUtils.getFirstElement(selection, IResource.class));
        if (project != null) {
            connection = ConnectionsRegistryUtil.getConnectionFor(project);
        } else {
            connection = UIUtils.getFirstElement(selection, Connection.class);
        }
    }
    if (connection == null) {
        connection = OpenShiftUIUtils.getExplorerDefaultConnection(Connection.class);
    }
    IDockerConnection dockerConnection = null;
    if (image != null) {
        dockerConnection = image.getConnection();
    } else if (OpenShiftUIUtils.hasDockerExplorerSelection()) {
        ISelection dockerSelection = OpenShiftUIUtils.getDockerExplorerSelection();
        dockerConnection = UIUtils.getFirstElement(dockerSelection, IDockerConnection.class);
        if (dockerConnection == null) {
            // Action is originated from OpenShift Explorer, do the best to pick up Docker connection from the current selection in Docker Explorer.
            IDockerImage selectedImage = UIUtils.getFirstElement(dockerSelection, IDockerImage.class);
            if (selectedImage != null) {
                dockerConnection = selectedImage.getConnection();
            }
        }
    }
    runWizard(HandlerUtil.getActiveWorkbenchWindow(event).getShell(), dockerConnection, image, project, connection);
    return null;
}
Also used : Connection(org.jboss.tools.openshift.core.connection.Connection) IDockerConnection(org.eclipse.linuxtools.docker.core.IDockerConnection) ISelection(org.eclipse.jface.viewers.ISelection) IDockerConnection(org.eclipse.linuxtools.docker.core.IDockerConnection) IDockerImage(org.eclipse.linuxtools.docker.core.IDockerImage) IProject(com.openshift.restclient.model.IProject)

Example 23 with IDockerImage

use of org.eclipse.linuxtools.docker.core.IDockerImage 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 24 with IDockerImage

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

the class EditDockerConnectionSWTBotTest method configureRunImageLaunchConfiguration.

private String configureRunImageLaunchConfiguration(final IDockerConnection connection, final String networkMode) {
    final IDockerImage image = MockDockerImageFactory.name("images").connection(connection).build();
    final DockerContainerConfig containerConfig = MockDockerContainerConfigFactory.cmd("cmd").build();
    final IDockerHostConfig hostConfig = MockDockerHostConfigFactory.publishAllPorts(true).networkMode(networkMode).build();
    final ILaunchConfiguration runImageLaunchConfiguration = LaunchConfigurationUtils.createRunImageLaunchConfiguration(image, containerConfig, hostConfig, "some_container", false);
    return runImageLaunchConfiguration.getName();
}
Also used : ILaunchConfiguration(org.eclipse.debug.core.ILaunchConfiguration) DockerContainerConfig(org.eclipse.linuxtools.internal.docker.core.DockerContainerConfig) IDockerHostConfig(org.eclipse.linuxtools.docker.core.IDockerHostConfig) IDockerImage(org.eclipse.linuxtools.docker.core.IDockerImage)

Example 25 with IDockerImage

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

the class ImageRunSWTBotTest method configureRunImageLaunchConfiguration.

private String configureRunImageLaunchConfiguration(final IDockerConnection connection, final String networkMode) {
    final IDockerImage image = MockDockerImageFactory.name("images").connection(connection).build();
    final DockerContainerConfig containerConfig = MockDockerContainerConfigFactory.cmd("cmd").build();
    final IDockerHostConfig hostConfig = MockDockerHostConfigFactory.publishAllPorts(true).networkMode(networkMode).build();
    final ILaunchConfiguration runImageLaunchConfiguration = LaunchConfigurationUtils.createRunImageLaunchConfiguration(image, containerConfig, hostConfig, "some_container", false);
    return runImageLaunchConfiguration.getName();
}
Also used : ILaunchConfiguration(org.eclipse.debug.core.ILaunchConfiguration) DockerContainerConfig(org.eclipse.linuxtools.internal.docker.core.DockerContainerConfig) IDockerHostConfig(org.eclipse.linuxtools.docker.core.IDockerHostConfig) IDockerImage(org.eclipse.linuxtools.docker.core.IDockerImage)

Aggregations

IDockerImage (org.eclipse.linuxtools.docker.core.IDockerImage)41 IDockerConnection (org.eclipse.linuxtools.docker.core.IDockerConnection)16 DockerException (org.eclipse.linuxtools.docker.core.DockerException)10 ArrayList (java.util.ArrayList)9 Test (org.junit.Test)8 IDockerImageHierarchyNode (org.eclipse.linuxtools.docker.core.IDockerImageHierarchyNode)7 List (java.util.List)6 CoreException (org.eclipse.core.runtime.CoreException)6 IDockerHostConfig (org.eclipse.linuxtools.docker.core.IDockerHostConfig)6 ILaunchConfiguration (org.eclipse.debug.core.ILaunchConfiguration)5 IDockerContainer (org.eclipse.linuxtools.docker.core.IDockerContainer)5 DockerConnection (org.eclipse.linuxtools.internal.docker.core.DockerConnection)5 IWorkbenchPart (org.eclipse.ui.IWorkbenchPart)5 HashMap (java.util.HashMap)4 Map (java.util.Map)3 Job (org.eclipse.core.runtime.jobs.Job)3 ColumnLabelProvider (org.eclipse.jface.viewers.ColumnLabelProvider)3 IDockerContainerConfig (org.eclipse.linuxtools.docker.core.IDockerContainerConfig)3 IDockerImageInfo (org.eclipse.linuxtools.docker.core.IDockerImageInfo)3 DockerContainerConfig (org.eclipse.linuxtools.internal.docker.core.DockerContainerConfig)3