Search in sources :

Example 36 with IDockerImage

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

the class RemoveImagesCommandHandler method confirmed.

@Override
boolean confirmed(List<IDockerImage> selectedImages) {
    // ask for confirmation before deleting images
    List<String> imagesToRemove = new ArrayList<>();
    for (IDockerImage image : selectedImages) {
        // think this will ever cause an issue
        if (!image.isDangling() && !image.isIntermediateImage())
            imagesToRemove.add(image.repoTags().get(0));
        else
            imagesToRemove.add(image.id().substring(0, 8));
    }
    final List<String> names = imagesToRemove;
    final DialogResponse response = new DialogResponse();
    Display.getDefault().syncExec(() -> {
        boolean result = MessageDialog.openConfirm(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), DVMessages.getString(IMAGE_DELETE_CONFIRM), DVMessages.getFormattedString(IMAGE_DELETE_LIST, names.toString()));
        response.setResponse(result);
    });
    return response.getResponse();
}
Also used : ArrayList(java.util.ArrayList) IDockerImage(org.eclipse.linuxtools.docker.core.IDockerImage)

Example 37 with IDockerImage

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

the class RunImageCommandHandler method execute.

@Override
public Object execute(final ExecutionEvent event) {
    final IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
    final IDockerImage selectedImage = CommandUtils.getSelectedImage(activePart);
    if (selectedImage == null) {
        Activator.log(new DockerException(// $NON-NLS-1$
        DVMessages.getString("RunImageUnableToRetrieveError.msg")));
    } else {
        try {
            final ImageRun wizard = new ImageRun(selectedImage);
            final boolean runImage = CommandUtils.openWizard(wizard, HandlerUtil.getActiveShell(event));
            if (runImage) {
                final IDockerContainerConfig containerConfig = wizard.getDockerContainerConfig();
                final IDockerHostConfig hostConfig = wizard.getDockerHostConfig();
                runImage(selectedImage, containerConfig, hostConfig, wizard.getDockerContainerName(), wizard.removeWhenExits());
            }
        } catch (DockerException | CoreException e) {
            Activator.log(e);
        }
    }
    return null;
}
Also used : DockerException(org.eclipse.linuxtools.docker.core.DockerException) IDockerContainerConfig(org.eclipse.linuxtools.docker.core.IDockerContainerConfig) CoreException(org.eclipse.core.runtime.CoreException) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) IDockerHostConfig(org.eclipse.linuxtools.docker.core.IDockerHostConfig) IDockerImage(org.eclipse.linuxtools.docker.core.IDockerImage) ImageRun(org.eclipse.linuxtools.internal.docker.ui.wizards.ImageRun)

Example 38 with IDockerImage

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

the class TagImageCommandHandler method execute.

@Override
public Object execute(final ExecutionEvent event) {
    final IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
    final List<IDockerImage> selectedImages = CommandUtils.getSelectedImages(activePart);
    final IDockerConnection connection = CommandUtils.getCurrentConnection(activePart);
    if (selectedImages.size() != 1 || connection == null) {
        Activator.log(new DockerException(CommandMessages.getString(// $NON-NLS-1$
        "Command.missing.selection.failure")));
        return null;
    }
    final IDockerImage image = selectedImages.get(0);
    // TODO: remove the cast to DockerImage once the 'shortId' method has
    // been added in the API
    final ImageTag wizard = new ImageTag(((DockerImage) image).shortId());
    final boolean tagImage = CommandUtils.openWizard(wizard, HandlerUtil.getActiveShell(event));
    if (tagImage) {
        performTagImage(connection, image, wizard.getTag());
    }
    return null;
}
Also used : DockerException(org.eclipse.linuxtools.docker.core.DockerException) ImageTag(org.eclipse.linuxtools.internal.docker.ui.wizards.ImageTag) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) IDockerConnection(org.eclipse.linuxtools.docker.core.IDockerConnection) IDockerImage(org.eclipse.linuxtools.docker.core.IDockerImage)

Example 39 with IDockerImage

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

the class ListDockerImagesWizardModel method setDockerImages.

public void setDockerImages(final List<IDockerImage> dockerImages) {
    final List<IDockerImage> topLevelImages = dockerImages.stream().filter(image -> !image.isDangling() && !image.isIntermediateImage()).collect(Collectors.toList());
    final List<DockerImageTag> imageTags = new ArrayList<>();
    for (IDockerImage topLevelImage : topLevelImages) {
        final Map<String, List<String>> repoTags = DockerImageUtils.extractTagsByRepo(topLevelImage.repoTags());
        for (Entry<String, List<String>> entry : repoTags.entrySet()) {
            final String repo = entry.getKey();
            final List<String> tags = entry.getValue();
            for (String tag : tags) {
                imageTags.add(new DockerImageTag(topLevelImage.id(), repo, tag));
            }
        }
    }
    Collections.sort(imageTags, new Comparator<DockerImageTag>() {

        @Override
        public int compare(DockerImageTag image1, DockerImageTag image2) {
            return image1.getRepoName().compareTo(image2.getRepoName());
        }
    });
    firePropertyChange(DOCKER_IMAGES, this.dockerImages, this.dockerImages = imageTags);
}
Also used : IDockerConnection(org.eclipse.linuxtools.docker.core.IDockerConnection) ObservablePojo(org.jboss.tools.common.databinding.ObservablePojo) List(java.util.List) IDockerImage(org.eclipse.linuxtools.docker.core.IDockerImage) Map(java.util.Map) Entry(java.util.Map.Entry) WizardPage(org.eclipse.jface.wizard.WizardPage) DockerImageUtils(org.jboss.tools.openshift.internal.core.docker.DockerImageUtils) Comparator(java.util.Comparator) Collections(java.util.Collections) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) IDockerImage(org.eclipse.linuxtools.docker.core.IDockerImage)

Example 40 with IDockerImage

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

the class DockerImageUtils method hasImage.

/**
 * Checks if an image with the given {@code repo} and {@code tag} exists in
 * the given {@code dockerConnection}
 * <p>
 * Workaround until https://bugs.eclipse.org/bugs/show_bug.cgi?id=495243 is
 * fixed.
 * </p>
 *
 * @param dockerConnection
 *            the {@link IDockerConnection}
 * @param repoName
 *            the repository/name of the image to look-up
 * @param tag
 *            the image tag
 * @return <code>true</code> if match found, <code>false</code> otherwise
 */
public static boolean hasImage(final IDockerConnection dockerConnection, final String repoName, final String tag) {
    for (IDockerImage image : dockerConnection.getImages()) {
        final Map<String, List<String>> repoTags = extractTagsByRepo(image.repoTags());
        for (Entry<String, List<String>> entry : repoTags.entrySet()) {
            final String repo = entry.getKey();
            final List<String> tags = entry.getValue();
            if (repo != null && repo.equals(repoName) && tags != null && tags.contains(tag)) {
                return true;
            }
        }
    }
    return false;
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) 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