Search in sources :

Example 26 with DockerException

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

the class EditDockerConnectionPage method onTestConnectionButtonSelection.

/**
 * Verifies that the given connection settings work by trying to connect to
 * the target Docker daemon
 *
 * @return
 */
private SelectionListener onTestConnectionButtonSelection() {
    return new SelectionAdapter() {

        @Override
        public void widgetSelected(final SelectionEvent event) {
            try {
                getWizard().getContainer().run(true, false, monitor -> {
                    monitor.beginTask(WizardMessages.getString(// $NON-NLS-1$
                    "DockerConnectionPage.pingTask"), IProgressMonitor.UNKNOWN);
                    try {
                        final DockerConnection dockerConnection = getDockerConnection();
                        dockerConnection.open(false);
                        dockerConnection.close();
                        // ping succeeded
                        displaySuccessDialog();
                    } catch (DockerException e) {
                        // only log if there's an underlying cause.
                        if (e.getCause() != null) {
                            displayErrorDialog(e.getCause());
                        } else {
                            displayErrorDialog(e);
                        }
                    }
                });
            } catch (InvocationTargetException | InterruptedException o_O) {
                Activator.log(o_O);
            }
        }

        private void displaySuccessDialog() {
            displayDialog(WizardMessages.getString(// $NON-NLS-1$
            "DockerConnectionPage.success"), WizardMessages.getString(// $NON-NLS-1$
            "DockerConnectionPage.pingSuccess"), SWT.ICON_INFORMATION, new String[] { WizardMessages.getString(// $NON-NLS-1$
            "DockerConnectionPage.ok") });
        }

        private void displayErrorDialog(final Throwable cause) {
            displayDialog(WizardMessages.getString(// $NON-NLS-1$
            "DockerConnectionPage.failure"), WizardMessages.getFormattedString(// $NON-NLS-1$
            "DockerConnectionPage.pingFailure", cause.getMessage()), SWT.ICON_ERROR, new String[] { WizardMessages.getString(// $NON-NLS-1$
            "DockerConnectionPage.ok") });
        }

        private void displayDialog(final String dialogTitle, final String dialogMessage, final int icon, final String[] buttonLabels) {
            Display.getDefault().syncExec(() -> new MessageDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), dialogTitle, null, dialogMessage, icon, buttonLabels, 0).open());
        }
    };
}
Also used : IDockerConnection(org.eclipse.linuxtools.docker.core.IDockerConnection) DockerConnection(org.eclipse.linuxtools.internal.docker.core.DockerConnection) DockerException(org.eclipse.linuxtools.docker.core.DockerException) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) SelectionEvent(org.eclipse.swt.events.SelectionEvent) MessageDialog(org.eclipse.jface.dialogs.MessageDialog) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 27 with DockerException

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

the class ImageTagSelectionPage method searchTags.

private void searchTags() {
    try {
        final BlockingQueue<List<DockerImageTagSearchResult>> searchResultQueue = new ArrayBlockingQueue<>(1);
        ImageTagSelectionPage.this.getContainer().run(true, true, monitor -> {
            monitor.beginTask(WizardMessages.getString(// $NON-NLS-1$
            "ImageTagSelectionPage.searchTask"), 2);
            final String selectedImageName = ImageTagSelectionPage.this.model.getSelectedImage().getName();
            try {
                final List<IRepositoryTag> repositoryTags = registry.getTags(selectedImageName);
                // we have to convert to list of RepositoryTag which
                // can be sorted
                final List<RepositoryTag> tags = repositoryTags.stream().map(c -> (RepositoryTag) c).collect(Collectors.toList());
                Collections.sort(tags);
                monitor.worked(1);
                final IDockerConnection connection = model.getSelectedConnection();
                final List<DockerImageTagSearchResult> searchResults = repositoryTags.stream().map(t -> new DockerImageTagSearchResult(selectedImageName, t, connection.hasImage(selectedImageName, t.getName()))).collect(Collectors.toList());
                monitor.worked(1);
                searchResultQueue.offer(searchResults);
            } catch (DockerException e) {
            } finally {
                monitor.done();
            }
        });
        List<DockerImageTagSearchResult> res = searchResultQueue.poll(10, TimeUnit.SECONDS);
        final List<DockerImageTagSearchResult> searchResult = (res == null) ? new ArrayList<>() : res;
        Display.getCurrent().asyncExec(() -> {
            ImageTagSelectionPage.this.model.setImageTagSearchResult(searchResult);
            // refresh the wizard buttons
            getWizard().getContainer().updateButtons();
        });
        // display a warning in the title area if the search result is empty
        if (searchResult.isEmpty()) {
            this.setMessage(WizardMessages.getString(// $NON-NLS-1$
            "ImageTagSelectionPage.noTagWarning"), WARNING);
        } else if (searchResult.size() == 1) {
            this.setMessage(WizardMessages.getString(// $NON-NLS-1$
            "ImageTagSelectionPage.oneTagMatched"), INFORMATION);
        } else {
            this.setMessage(WizardMessages.getFormattedString(// $NON-NLS-1$
            "ImageTagSelectionPage.tagsMatched", Integer.toString(searchResult.size())), INFORMATION);
        }
    } catch (InvocationTargetException | InterruptedException e) {
        Activator.log(e);
    }
}
Also used : IRepositoryTag(org.eclipse.linuxtools.docker.core.IRepositoryTag) TableViewer(org.eclipse.jface.viewers.TableViewer) Activator(org.eclipse.linuxtools.docker.ui.Activator) TableColumn(org.eclipse.swt.widgets.TableColumn) DataBindingContext(org.eclipse.core.databinding.DataBindingContext) ObservableListContentProvider(org.eclipse.jface.databinding.viewers.ObservableListContentProvider) Table(org.eclipse.swt.widgets.Table) ArrayList(java.util.ArrayList) IObservableList(org.eclipse.core.databinding.observable.list.IObservableList) RepositoryTag(org.eclipse.linuxtools.internal.docker.core.RepositoryTag) Composite(org.eclipse.swt.widgets.Composite) DockerException(org.eclipse.linuxtools.docker.core.DockerException) IconColumnLabelProvider(org.eclipse.linuxtools.internal.docker.ui.wizards.ImageSearchPage.IconColumnLabelProvider) WizardPage(org.eclipse.jface.wizard.WizardPage) GridDataFactory(org.eclipse.jface.layout.GridDataFactory) ViewerProperties(org.eclipse.jface.databinding.viewers.ViewerProperties) BlockingQueue(java.util.concurrent.BlockingQueue) IRegistry(org.eclipse.linuxtools.docker.core.IRegistry) Display(org.eclipse.swt.widgets.Display) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) Collectors(java.util.stream.Collectors) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn) GridLayoutFactory(org.eclipse.jface.layout.GridLayoutFactory) InvocationTargetException(java.lang.reflect.InvocationTargetException) CellLabelProvider(org.eclipse.jface.viewers.CellLabelProvider) TimeUnit(java.util.concurrent.TimeUnit) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) IDockerConnection(org.eclipse.linuxtools.docker.core.IDockerConnection) List(java.util.List) SWTImagesFactory(org.eclipse.linuxtools.internal.docker.ui.SWTImagesFactory) BeanProperties(org.eclipse.core.databinding.beans.BeanProperties) SWT(org.eclipse.swt.SWT) RepositoryTagV2(org.eclipse.linuxtools.internal.docker.core.RepositoryTagV2) Collections(java.util.Collections) IRepositoryTag(org.eclipse.linuxtools.docker.core.IRepositoryTag) DockerException(org.eclipse.linuxtools.docker.core.DockerException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) IDockerConnection(org.eclipse.linuxtools.docker.core.IDockerConnection) RepositoryTag(org.eclipse.linuxtools.internal.docker.core.RepositoryTag) IRepositoryTag(org.eclipse.linuxtools.docker.core.IRepositoryTag) ArrayList(java.util.ArrayList) IObservableList(org.eclipse.core.databinding.observable.list.IObservableList) List(java.util.List)

Example 28 with DockerException

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

the class ConnectionInfoPropertySection method updateConnectionInfo.

private void updateConnectionInfo(final IDockerConnection connection) {
    // Set the tree empty while we wait for the real data
    if (getTreeViewer() != null) {
        getTreeViewer().setInput(null);
        getTreeViewer().expandAll();
    }
    final Job loadConnectionInfoJob = new Job(DVMessages.getString(LoadingConnectionInfo)) {

        @Override
        protected IStatus run(final IProgressMonitor monitor) {
            monitor.beginTask(DVMessages.getString(LoadingConnectionInfo), 1);
            if (connection.getState() != EnumDockerConnectionState.ESTABLISHED) {
                return Status.OK_STATUS;
            }
            try {
                final IDockerConnectionInfo info = connection.getInfo();
                Display.getDefault().asyncExec(() -> {
                    if (info != null && getTreeViewer() != null) {
                        getTreeViewer().setInput(info);
                        getTreeViewer().expandAll();
                    }
                });
            } catch (DockerException e) {
                Activator.log(e);
            }
            monitor.done();
            return Status.OK_STATUS;
        }
    };
    loadConnectionInfoJob.schedule();
}
Also used : DockerException(org.eclipse.linuxtools.docker.core.DockerException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IDockerConnectionInfo(org.eclipse.linuxtools.docker.core.IDockerConnectionInfo) Job(org.eclipse.core.runtime.jobs.Job)

Example 29 with DockerException

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

the class ContainerLauncher method launch.

/**
 * Perform a launch of a command in a container and output stdout/stderr to
 * console.
 *
 * @param id
 *            - id of caller to use to distinguish console owner
 * @param listener
 *            - optional listener of the run console
 * @param connectionUri
 *            - the specified connection to use
 * @param image
 *            - the image to use
 * @param cmdList
 *            - command to run as list of String
 * @param workingDir
 *            - working directory or null
 * @param additionalDirs
 *            - additional directories to mount or null
 * @param origEnv
 *            - original environment if we are appending to our existing
 *            environment
 * @param envMap
 *            - map of environment variable settings
 * @param ports
 *            - ports to expose
 * @param keep
 *            - keep container after running
 * @param stdinSupport
 *            - true if stdin support is required, false otherwise
 * @param privilegedMode
 *            - true if privileged mode is required, false otherwise
 * @param labels
 *            - Map of labels for the container
 * @param seccomp
 *            - seccomp profile
 * @since 4.0
 */
public void launch(String id, IContainerLaunchListener listener, final String connectionUri, String image, List<String> cmdList, String workingDir, List<String> additionalDirs, Map<String, String> origEnv, Map<String, String> envMap, List<String> ports, boolean keep, boolean stdinSupport, boolean privilegedMode, Map<String, String> labels, String seccomp) {
    // $NON-NLS-1$
    final String LAUNCH_TITLE = "ContainerLaunch.title";
    // $NON-NLS-1$
    final String LAUNCH_EXITED_TITLE = "ContainerLaunchExited.title";
    final List<String> env = new ArrayList<>();
    env.addAll(toList(origEnv));
    env.addAll(toList(envMap));
    final Set<String> exposedPorts = new HashSet<>();
    final Map<String, List<IDockerPortBinding>> portBindingsMap = new HashMap<>();
    if (ports != null) {
        for (String port : ports) {
            port = port.trim();
            if (port.length() > 0) {
                // $NON-NLS-1$
                String[] segments = port.split(":");
                if (segments.length == 1) {
                    // containerPort
                    exposedPorts.add(segments[0]);
                    portBindingsMap.put(segments[0], Arrays.asList((IDockerPortBinding) new DockerPortBinding("", // $NON-NLS-1$ //$NON-NLS-2$
                    "")));
                } else if (segments.length == 2) {
                    // hostPort:containerPort
                    exposedPorts.add(segments[1]);
                    portBindingsMap.put(segments[1], Arrays.asList((IDockerPortBinding) new DockerPortBinding("", // $NON-NLS-1$ //$NON-NLS-2$
                    segments[0])));
                } else if (segments.length == 3) {
                    // either
                    // ip:hostPort:containerPort
                    // or ip::containerPort
                    exposedPorts.add(segments[1]);
                    if (segments[1].isEmpty()) {
                        portBindingsMap.put(segments[2], Arrays.asList((IDockerPortBinding) new DockerPortBinding("", // $NON-NLS-1$ //$NON-NLS-2$
                        segments[0])));
                    } else {
                        portBindingsMap.put(segments[2], Arrays.asList((IDockerPortBinding) new DockerPortBinding(segments[0], // $NON-NLS-1$ //$NON-NLS-2$
                        segments[1])));
                    }
                }
            }
        }
    }
    // Note we only pass volumes to the config if we have a
    // remote daemon. Local mounted volumes are passed
    // via the HostConfig binds setting
    DockerContainerConfig.Builder builder = new DockerContainerConfig.Builder().openStdin(stdinSupport).cmd(cmdList).image(image).workingDir(workingDir);
    // option
    if (listener != null && listener.getClass().getName().equals("org.eclipse.cdt.internal.docker.launcher.ContainerLaunchConfigurationDelegate$StartGdbServerJob")) {
        builder = builder.tty(true);
    }
    // add any exposed ports as needed
    if (exposedPorts.size() > 0)
        builder = builder.exposedPorts(exposedPorts);
    // add any labels if specified
    if (labels != null)
        builder = builder.labels(labels);
    if (!DockerConnectionManager.getInstance().hasConnections()) {
        Display.getDefault().syncExec(() -> MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), DVMessages.getString(ERROR_LAUNCHING_CONTAINER), DVMessages.getString(ERROR_NO_CONNECTIONS)));
        return;
    }
    // Try and use the specified connection that was used before,
    // otherwise, open an error
    final IDockerConnection connection = DockerConnectionManager.getInstance().getConnectionByUri(connectionUri);
    if (connection == null) {
        Display.getDefault().syncExec(() -> MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), DVMessages.getString(ERROR_LAUNCHING_CONTAINER), DVMessages.getFormattedString(ERROR_NO_CONNECTION_WITH_URI, connectionUri)));
        return;
    }
    // if connection is not open, force it to be by fetching images
    if (!connection.isOpen()) {
        connection.getImages();
    }
    DockerHostConfig.Builder hostBuilder = new DockerHostConfig.Builder().privileged(privilegedMode);
    // ptrace with gdbserver
    if (seccomp != null) {
        hostBuilder.securityOpt(seccomp);
    }
    final Map<String, String> remoteVolumes = new HashMap<>();
    if (!((DockerConnection) connection).isLocal()) {
        @SuppressWarnings("rawtypes") final Map<String, Map> volumes = new HashMap<>();
        // the host data over before starting.
        if (additionalDirs != null) {
            for (String dir : additionalDirs) {
                remoteVolumes.put(dir, dir);
                volumes.put(dir, new HashMap<>());
            }
        }
        if (workingDir != null) {
            // $NON-NLS-1$
            remoteVolumes.put(workingDir, workingDir);
            volumes.put(workingDir, new HashMap<>());
        }
        builder = builder.volumes(volumes);
    } else {
        // Running daemon on local host.
        // Add mounts for any directories we need to run the executable.
        // When we add mount points, we need entries of the form:
        // hostname:mountname:Z.
        // In our case, we want all directories mounted as-is so the
        // executable will run as the user expects.
        final List<String> volumes = new ArrayList<>();
        if (additionalDirs != null) {
            for (String dir : additionalDirs) {
                // $NON-NLS-1$ //$NON-NLS-2$
                volumes.add(dir + ":" + dir + ":Z");
            }
        }
        if (workingDir != null) {
            // $NON-NLS-1$ //$NON-NLS-2$
            volumes.add(workingDir + ":" + workingDir + ":Z");
        }
        hostBuilder = hostBuilder.binds(volumes);
    }
    final DockerContainerConfig config = builder.build();
    // add any port bindings if specified
    if (portBindingsMap.size() > 0)
        hostBuilder = hostBuilder.portBindings(portBindingsMap);
    final IDockerHostConfig hostConfig = hostBuilder.build();
    final String imageName = image;
    final boolean keepContainer = keep;
    final String consoleId = id;
    final IContainerLaunchListener containerListener = listener;
    Thread t = new Thread(() -> {
        // create the container
        String containerId = null;
        try {
            containerId = ((DockerConnection) connection).createContainer(config, hostConfig, null);
            if (!((DockerConnection) connection).isLocal()) {
                // data over from the host.
                if (!remoteVolumes.isEmpty()) {
                    CopyVolumesJob job = new CopyVolumesJob(remoteVolumes, connection, containerId);
                    job.schedule();
                    job.join();
                    if (job.getResult() != Status.OK_STATUS)
                        return;
                }
            }
            if (config.tty()) {
                // We need tty support to handle issue with Docker daemon
                // not always outputting in time (e.g. we might get an
                // output line after the process has exited which can be
                // too late to show or it might get displayed in a wrong
                // order in relation to other output. We also want the
                // output to ultimately show up in the Console View.
                OutputStream stream = null;
                RunConsole oldConsole = getConsole();
                final RunConsole rc = RunConsole.findConsole(containerId, consoleId);
                setConsole(rc);
                rc.clearConsole();
                if (oldConsole != null)
                    RunConsole.removeConsole(oldConsole);
                Display.getDefault().syncExec(() -> rc.setTitle(Messages.getFormattedString(LAUNCH_TITLE, new String[] { cmdList.get(0), imageName })));
                if (rc != null) {
                    stream = rc.getOutputStream();
                }
                // We want terminal support, but we want to output to the
                // RunConsole.
                // To do this, we create a DockerConsoleOutputStream which
                // we
                // hook into the TM Terminal via stdout and stderr output
                // listeners.
                // These listeners will output to the
                // DockerConsoleOutputStream which
                // will in turn output to the RunConsole. See
                // DockerConnection.openTerminal().
                DockerConsoleOutputStream out = new DockerConsoleOutputStream(stream);
                RunConsole.attachToTerminal(connection, containerId, out);
                if (containerListener != null) {
                    out.addConsoleListener(new RunConsoleListenerBridge(containerListener));
                }
                ((DockerConnection) connection).startContainer(containerId, null, null);
                IDockerContainerInfo info = ((DockerConnection) connection).getContainerInfo(containerId);
                if (containerListener != null) {
                    containerListener.containerInfo(info);
                }
                // Wait for the container to finish
                final IDockerContainerExit status = ((DockerConnection) connection).waitForContainer(containerId);
                Display.getDefault().syncExec(() -> {
                    rc.setTitle(Messages.getFormattedString(LAUNCH_EXITED_TITLE, new String[] { status.statusCode().toString(), cmdList.get(0), imageName }));
                    rc.showConsole();
                    // We used a TM Terminal to receive the output of the
                    // session and
                    // then sent the output to the RunConsole. Remove the
                    // terminal
                    // tab that got created now that we are finished and all
                    // data is shown
                    // in Console View.
                    IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
                    IViewPart terminalView = page.findView("org.eclipse.tm.terminal.view.ui.TerminalsView");
                    CTabFolder ctabfolder = terminalView.getAdapter(CTabFolder.class);
                    if (ctabfolder != null) {
                        CTabItem[] items = ctabfolder.getItems();
                        for (CTabItem item : items) {
                            if (item.getText().endsWith(info.name())) {
                                item.dispose();
                                break;
                            }
                        }
                    }
                });
                // finished
                if (containerListener != null)
                    containerListener.done();
                if (!keepContainer) {
                    ((DockerConnection) connection).removeContainer(containerId);
                }
            } else {
                OutputStream stream = null;
                RunConsole oldConsole = getConsole();
                final RunConsole rc = RunConsole.findConsole(containerId, consoleId);
                setConsole(rc);
                rc.clearConsole();
                if (oldConsole != null)
                    RunConsole.removeConsole(oldConsole);
                Display.getDefault().syncExec(() -> rc.setTitle(Messages.getFormattedString(LAUNCH_TITLE, new String[] { cmdList.get(0), imageName })));
                // if (!rc.isAttached()) {
                rc.attachToConsole(connection, containerId);
                // }
                if (rc != null) {
                    stream = rc.getOutputStream();
                    if (containerListener != null) {
                        ((ConsoleOutputStream) stream).addConsoleListener(containerListener);
                    }
                }
                // Create a unique logging thread id which has container id
                // and console id
                String loggingId = containerId + "." + consoleId;
                ((DockerConnection) connection).startContainer(containerId, loggingId, stream);
                if (rc != null)
                    rc.showConsole();
                if (containerListener != null) {
                    IDockerContainerInfo info = ((DockerConnection) connection).getContainerInfo(containerId);
                    containerListener.containerInfo(info);
                }
                // Wait for the container to finish
                final IDockerContainerExit status = ((DockerConnection) connection).waitForContainer(containerId);
                Display.getDefault().syncExec(() -> {
                    rc.setTitle(Messages.getFormattedString(LAUNCH_EXITED_TITLE, new String[] { status.statusCode().toString(), cmdList.get(0), imageName }));
                    rc.showConsole();
                });
                // finished
                if (containerListener != null)
                    containerListener.done();
                if (!keepContainer) {
                    // Drain the logging thread before we remove the
                    // container (we need to use the logging id)
                    Thread.sleep(1000);
                    ((DockerConnection) connection).stopLoggingThread(loggingId);
                    // Look for any Display Log console that the user may
                    // have opened which would be
                    // separate and make sure it is removed as well
                    RunConsole rc2 = RunConsole.findConsole(((DockerConnection) connection).getContainer(containerId));
                    if (rc2 != null)
                        RunConsole.removeConsole(rc2);
                    ((DockerConnection) connection).removeContainer(containerId);
                }
            }
        } catch (final DockerException e2) {
            // error in creation, try and remove Container if possible
            if (!keepContainer && containerId != null) {
                try {
                    ((DockerConnection) connection).removeContainer(containerId);
                } catch (DockerException | InterruptedException e1) {
                // ignore exception
                }
            }
            Display.getDefault().syncExec(() -> MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), DVMessages.getFormattedString(ERROR_CREATING_CONTAINER, imageName), e2.getMessage()));
        } catch (InterruptedException e3) {
        // for now
        // do nothing
        }
        ((DockerConnection) connection).getContainers(true);
    });
    t.start();
}
Also used : IViewPart(org.eclipse.ui.IViewPart) CTabFolder(org.eclipse.swt.custom.CTabFolder) HashMap(java.util.HashMap) DockerConsoleOutputStream(org.eclipse.linuxtools.internal.docker.core.DockerConsoleOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) OutputStream(java.io.OutputStream) ConsoleOutputStream(org.eclipse.linuxtools.internal.docker.ui.consoles.ConsoleOutputStream) FileOutputStream(java.io.FileOutputStream) ArrayList(java.util.ArrayList) IDockerHostConfig(org.eclipse.linuxtools.docker.core.IDockerHostConfig) IDockerContainerExit(org.eclipse.linuxtools.docker.core.IDockerContainerExit) CTabItem(org.eclipse.swt.custom.CTabItem) IDockerConnection(org.eclipse.linuxtools.docker.core.IDockerConnection) DockerConnection(org.eclipse.linuxtools.internal.docker.core.DockerConnection) RunConsole(org.eclipse.linuxtools.internal.docker.ui.consoles.RunConsole) IDockerPortBinding(org.eclipse.linuxtools.docker.core.IDockerPortBinding) IDockerConnection(org.eclipse.linuxtools.docker.core.IDockerConnection) List(java.util.List) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) IDockerHostConfig(org.eclipse.linuxtools.docker.core.IDockerHostConfig) DockerHostConfig(org.eclipse.linuxtools.internal.docker.core.DockerHostConfig) DockerException(org.eclipse.linuxtools.docker.core.DockerException) IDockerPortBinding(org.eclipse.linuxtools.docker.core.IDockerPortBinding) DockerPortBinding(org.eclipse.linuxtools.internal.docker.core.DockerPortBinding) DockerConsoleOutputStream(org.eclipse.linuxtools.internal.docker.core.DockerConsoleOutputStream) ConsoleOutputStream(org.eclipse.linuxtools.internal.docker.ui.consoles.ConsoleOutputStream) DockerContainerConfig(org.eclipse.linuxtools.internal.docker.core.DockerContainerConfig) IDockerContainerConfig(org.eclipse.linuxtools.docker.core.IDockerContainerConfig) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IDockerContainerInfo(org.eclipse.linuxtools.docker.core.IDockerContainerInfo) Map(java.util.Map) HashMap(java.util.HashMap) DockerConsoleOutputStream(org.eclipse.linuxtools.internal.docker.core.DockerConsoleOutputStream)

Example 30 with DockerException

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

the class RemoveTagCommandHandler 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);
    final ImageRemoveTag wizard = new ImageRemoveTag(image);
    final boolean removeTag = CommandUtils.openWizard(wizard, HandlerUtil.getActiveShell(event));
    if (removeTag) {
        performRemoveTagImage(connection, wizard.getTag());
    }
    return null;
}
Also used : DockerException(org.eclipse.linuxtools.docker.core.DockerException) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) IDockerConnection(org.eclipse.linuxtools.docker.core.IDockerConnection) IDockerImage(org.eclipse.linuxtools.docker.core.IDockerImage) ImageRemoveTag(org.eclipse.linuxtools.internal.docker.ui.wizards.ImageRemoveTag)

Aggregations

DockerException (org.eclipse.linuxtools.docker.core.DockerException)80 IDockerConnection (org.eclipse.linuxtools.docker.core.IDockerConnection)27 DockerConnection (org.eclipse.linuxtools.internal.docker.core.DockerConnection)19 Job (org.eclipse.core.runtime.jobs.Job)17 IOException (java.io.IOException)16 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)16 DockerContainerNotFoundException (org.eclipse.linuxtools.docker.core.DockerContainerNotFoundException)16 ContainerNotFoundException (com.spotify.docker.client.exceptions.ContainerNotFoundException)15 ArrayList (java.util.ArrayList)14 DockerClient (com.spotify.docker.client.DockerClient)13 IDockerContainerInfo (org.eclipse.linuxtools.docker.core.IDockerContainerInfo)10 IDockerImage (org.eclipse.linuxtools.docker.core.IDockerImage)9 DockerCertificateException (com.spotify.docker.client.exceptions.DockerCertificateException)8 DockerTimeoutException (com.spotify.docker.client.exceptions.DockerTimeoutException)7 ProcessingException (javax.ws.rs.ProcessingException)7 IPath (org.eclipse.core.runtime.IPath)7 RunConsole (org.eclipse.linuxtools.internal.docker.ui.consoles.RunConsole)7 LogStream (com.spotify.docker.client.LogStream)6 File (java.io.File)6 HashMap (java.util.HashMap)6