Search in sources :

Example 1 with DockerException

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

the class StartContainersCommandHandler method executeInJob.

@Override
void executeInJob(final IDockerContainer container, final IDockerConnection connection) {
    try {
        final RunConsole console = getRunConsole(connection, container);
        if (console != null) {
            // if we are auto-logging, show the console
            console.showConsole();
            // Start the container
            ((DockerConnection) connection).startContainer(container.id(), console.getOutputStream());
        } else {
            ((DockerConnection) connection).startContainer(container.id(), null);
        }
        ((DockerConnection) connection).getContainers(true);
    } catch (DockerException | InterruptedException e) {
        final String errorMessage = DVMessages.getFormattedString(CONTAINER_START_ERROR_MSG, container.id());
        openError(errorMessage, e);
    }
}
Also used : IDockerConnection(org.eclipse.linuxtools.docker.core.IDockerConnection) DockerConnection(org.eclipse.linuxtools.internal.docker.core.DockerConnection) DockerException(org.eclipse.linuxtools.docker.core.DockerException) CommandUtils.getRunConsole(org.eclipse.linuxtools.internal.docker.ui.commands.CommandUtils.getRunConsole) RunConsole(org.eclipse.linuxtools.internal.docker.ui.consoles.RunConsole)

Example 2 with DockerException

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

the class UnpauseContainersCommandHandler method executeInJob.

@Override
void executeInJob(final IDockerContainer container, final IDockerConnection connection) {
    try {
        final RunConsole console = getRunConsole(connection, container);
        if (console != null) {
            // if we are auto-logging, show the console
            console.showConsole();
            // Start the container
            connection.unpauseContainer(container.id(), console.getOutputStream());
        } else {
            connection.unpauseContainer(container.id(), null);
        }
    } catch (DockerException | InterruptedException e) {
        final String errorMessage = DVMessages.getFormattedString(CONTAINER_UNPAUSE_ERROR_MSG, container.id());
        openError(errorMessage, e);
    }
}
Also used : DockerException(org.eclipse.linuxtools.docker.core.DockerException) CommandUtils.getRunConsole(org.eclipse.linuxtools.internal.docker.ui.commands.CommandUtils.getRunConsole) RunConsole(org.eclipse.linuxtools.internal.docker.ui.consoles.RunConsole)

Example 3 with DockerException

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

the class BuildDockerImageJob method run.

@Override
protected IStatus run(final IProgressMonitor progressMonitor) {
    try {
        this.progressMonitor = progressMonitor;
        final IPath pathToDockerfile = path.addTrailingSeparator().append(// $NON-NLS-1$
        "Dockerfile");
        if (verifyPathToDockerfile(pathToDockerfile)) {
            final int numberOfBuildOperations = countLines(// $NON-NLS-1$
            pathToDockerfile.toOSString());
            if (numberOfBuildOperations == 0) {
                Activator.log(new Status(IStatus.WARNING, Activator.PLUGIN_ID, JobMessages.getString(SKIP_EMPTY_DOCKERFILE)));
            } else {
                this.console.clearConsole();
                this.console.activate();
                this.progressMonitor.beginTask(JobMessages.getString(BUILD_IMAGE_JOB_TITLE), numberOfBuildOperations + 1);
                if (repoName == null) {
                    // Give the Image a default name so it can be tagged
                    // later.
                    // Otherwise, the Image will be treated as an
                    // intermediate
                    // Image
                    // by the view filters and Tag Image action will be
                    // disabled.
                    // Use the current time in milliseconds to make it
                    // unique.
                    final String name = // $NON-NLS-1$
                    "dockerfile:" + Long.toHexString(System.currentTimeMillis());
                    ((DockerConnection) connection).buildImage(this.path, name, this, this.buildOptions);
                } else {
                    ((DockerConnection) connection).buildImage(this.path, this.repoName, this, this.buildOptions);
                }
                connection.getImages(true);
            }
        }
    } catch (DockerException | InterruptedException e) {
        Display.getDefault().syncExec(() -> MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), JobMessages.getString(BUILD_IMAGE_ERROR_MESSAGE), e.getMessage()));
    } finally {
        // make sure the progress monitor is 'done' even if the build failed
        // or
        // timed out.
        this.progressMonitor.done();
    }
    return Status.OK_STATUS;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IDockerConnection(org.eclipse.linuxtools.docker.core.IDockerConnection) DockerConnection(org.eclipse.linuxtools.internal.docker.core.DockerConnection) DockerException(org.eclipse.linuxtools.docker.core.DockerException) IPath(org.eclipse.core.runtime.IPath)

Example 4 with DockerException

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

the class DockerComposeUpJob method run.

@Override
protected IStatus run(final IProgressMonitor monitor) {
    final String dockerComposeInstallDir = Activator.getDefault().getPreferenceStore().getString(PreferenceConstants.DOCKER_COMPOSE_INSTALLATION_DIRECTORY);
    final Thread commandThread = new Thread(() -> {
        // open console view
        ConsolePlugin.getDefault().getConsoleManager().showConsoleView(dockerComposeConsole);
        try {
            // run the 'docker-compose up' command
            final Process dockerComposeSystemProcess = DockerCompose.getInstance().up(this.connection, dockerComposeInstallDir, this.workingDir);
            final ILaunch launch = new Launch(launchConfiguration, ILaunchManager.RUN_MODE, null);
            final IProcess dockerComposeProcess = DebugPlugin.newProcess(launch, dockerComposeSystemProcess, // $NON-NLS-1$
            "docker-compose up");
            dockerComposeConsole.setDockerComposeProcess(// $NON-NLS-1$
            dockerComposeProcess);
            final int exitCode = dockerComposeSystemProcess.waitFor();
            if (exitCode != 0) {
                Display.getDefault().asyncExec(() -> MessageDialog.openError(Display.getDefault().getActiveShell(), JobMessages.getString(// $NON-NLS-1$
                "DockerCompose.dialog.title"), JobMessages.getString(// $NON-NLS-1$
                "DockerComposeUp.start.error")));
            }
        } catch (DockerCommandNotFoundException e) {
            // just display the error to the user, there's no need to report
            // an error in the log and in AERI for that.
            Display.getDefault().asyncExec(() -> MessageDialog.openError(Display.getCurrent().getActiveShell(), JobMessages.getString(// $NON-NLS-1$
            "DockerCompose.dialog.title"), e.getMessage()));
        } catch (DockerException | InterruptedException e) {
            Display.getDefault().asyncExec(() -> MessageDialog.openError(Display.getCurrent().getActiveShell(), JobMessages.getString(// $NON-NLS-1$
            "DockerCompose.dialog.title"), e.getMessage()));
            Activator.log(e);
        }
    });
    commandThread.start();
    return Status.OK_STATUS;
}
Also used : DockerException(org.eclipse.linuxtools.docker.core.DockerException) DockerCommandNotFoundException(org.eclipse.linuxtools.docker.core.DockerCommandNotFoundException) ILaunch(org.eclipse.debug.core.ILaunch) IProcess(org.eclipse.debug.core.model.IProcess) Launch(org.eclipse.debug.core.Launch) ILaunch(org.eclipse.debug.core.ILaunch) IProcess(org.eclipse.debug.core.model.IProcess)

Example 5 with DockerException

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

the class NewDockerConnectionPage method onSearchButtonSelection.

private SelectionListener onSearchButtonSelection() {
    return new SelectionAdapter() {

        private String getVMDriverInstallDir() {
            return Activator.getDefault().getPreferenceStore().getString(PreferenceConstants.VM_DRIVER_INSTALLATION_DIRECTORY);
        }

        private String getDockerMachineInstallDir() {
            return Activator.getDefault().getPreferenceStore().getString(PreferenceConstants.DOCKER_MACHINE_INSTALLATION_DIRECTORY);
        }

        @Override
        public void widgetSelected(SelectionEvent e) {
            if (!checkDockerMachineInstallDirs()) {
                return;
            }
            final String dockerMachineInstallDir = getDockerMachineInstallDir();
            final String vmDriverInstallDir = getVMDriverInstallDir();
            final Map<String, Boolean> allMachineStates = retrieveDockerMachineNames(dockerMachineInstallDir, vmDriverInstallDir);
            final List<String> activeMachineNames = allMachineStates.entrySet().stream().filter((machineEntry) -> machineEntry.getValue().booleanValue()).map((machineEntry) -> machineEntry.getKey()).collect(Collectors.toList());
            if (activeMachineNames.size() > 0) {
                ListDialog connPrompt = new ListDialog(getShell());
                connPrompt.setContentProvider(new ConnectionSelectionContentProvider());
                connPrompt.setLabelProvider(new ConnectionSelectionLabelProvider());
                connPrompt.setTitle(WizardMessages.getString(// $NON-NLS-1$
                "DockerConnectionPage.searchDialog.title"));
                connPrompt.setMessage(WizardMessages.getString(// $NON-NLS-1$
                "DockerConnectionPage.searchDialog.message"));
                connPrompt.setInput(activeMachineNames.toArray(new String[0]));
                if (connPrompt.open() == 0 && connPrompt.getResult().length > 0) {
                    final String name = ((String) connPrompt.getResult()[0]);
                    model.setBindingMode(EnumDockerConnectionSettings.TCP_CONNECTION);
                    model.setConnectionName(name);
                    model.setUnixSocketPath(null);
                    try {
                        final String host = DockerMachine.getInstance().getHost(name, dockerMachineInstallDir, vmDriverInstallDir);
                        model.setTcpHost(host);
                    } catch (DockerException e1) {
                        Activator.log(e1);
                    }
                    try {
                        final String certPath = DockerMachine.getInstance().getCertPath(name, dockerMachineInstallDir, vmDriverInstallDir);
                        if (certPath != null) {
                            model.setTcpTLSVerify(true);
                            model.setTcpCertPath(certPath);
                        } else {
                            model.setTcpTLSVerify(false);
                            model.setTcpCertPath(null);
                        }
                    } catch (DockerException e1) {
                        Activator.log(e1);
                    }
                }
            } else {
                if (allMachineStates.size() == 1) {
                    MessageDialog.openInformation(getShell(), WizardMessages.getString(// $NON-NLS-1$
                    "DockerConnectionPage.searchDialog.discovery.title"), WizardMessages.getFormattedString(// $NON-NLS-1$
                    "DockerConnectionPage.searchDialog.discovery.innactive.single", allMachineStates.entrySet().iterator().next().getKey()));
                } else if (allMachineStates.size() > 1) {
                    final String allMachineNames = allMachineStates.entrySet().stream().map((machineEntry) -> machineEntry.getKey()).collect(Collectors.joining(", "));
                    MessageDialog.openInformation(getShell(), WizardMessages.getString(// $NON-NLS-1$
                    "DockerConnectionPage.searchDialog.discovery.title"), WizardMessages.getFormattedString(// $NON-NLS-1$
                    "DockerConnectionPage.searchDialog.discovery.innactive.multiple", allMachineNames));
                } else {
                    MessageDialog.openInformation(getShell(), WizardMessages.getString(// $NON-NLS-1$
                    "DockerConnectionPage.searchDialog.discovery.title"), WizardMessages.getString(// $NON-NLS-1$
                    "DockerConnectionPage.searchDialog.discovery.empty"));
                }
            }
        }

        /**
         * Verifies that the install dirs for Docker Machine and its driver
         * are valid, otherwise offers to open the preference page to fix
         * the settings.
         *
         * @return <code>true</code> if the settings are valid,
         *         <code>false</code> otherwise.
         */
        private boolean checkDockerMachineInstallDirs() {
            if (!validDockerMachineInstallDirs()) {
                final boolean confirm = MessageDialog.openConfirm(getShell(), WizardMessages.getString(// $NON-NLS-1$
                "DockerMachineSupport.title"), WizardMessages.getString(// $NON-NLS-1$
                "DockerMachineSupport.message"));
                if (confirm) {
                    PreferencesUtil.createPreferenceDialogOn(getShell(), DOCKER_MACHINE_PREFERENCE_PAGE_ID, new String[] { DOCKER_MACHINE_PREFERENCE_PAGE_ID }, null).open();
                    // after user input data, check again
                    if (!validDockerMachineInstallDirs()) {
                        MessageDialog.openError(getShell(), WizardMessages.getString(// $NON-NLS-1$
                        "DockerMachineSupport.title"), WizardMessages.getString(// $NON-NLS-1$
                        "DockerMachineSupport.message.invalid"));
                        return false;
                    }
                } else {
                    return false;
                }
            }
            return true;
        }

        /**
         * @return <code>true</code> if the install dirs for Docker Machine
         *         and its drivers are valid, <code>false</code> otherwise.
         */
        private boolean validDockerMachineInstallDirs() {
            return DockerMachine.getInstance().checkPathToDockerMachine(getDockerMachineInstallDir()) && // $NON-NLS-1$
            !getVMDriverInstallDir().equals("");
        }

        /**
         * Retrieves the docker machine names along with a boolean flag to
         * indicate if it is running or not.
         *
         * @param dockerMachineInstallDir
         * @param vmDriverInstallDir
         * @return
         */
        private Map<String, Boolean> retrieveDockerMachineNames(final String dockerMachineInstallDir, final String vmDriverInstallDir) {
            try {
                final String[] dmNames = DockerMachine.getInstance().getNames(dockerMachineInstallDir);
                return java.util.stream.Stream.of(dmNames).collect(Collectors.toMap(name -> name, name -> {
                    try {
                        return DockerMachine.getInstance().getHost(name, dockerMachineInstallDir, vmDriverInstallDir) != null;
                    } catch (DockerException e) {
                        Activator.log(e);
                        return false;
                    }
                }));
            } catch (DockerException e) {
                Activator.log(e);
                return Collections.emptyMap();
            }
        }
    };
}
Also used : WizardPageSupport(org.eclipse.jface.databinding.wizard.WizardPageSupport) URISyntaxException(java.net.URISyntaxException) Activator(org.eclipse.linuxtools.docker.ui.Activator) IChangeListener(org.eclipse.core.databinding.observable.IChangeListener) DND(org.eclipse.swt.dnd.DND) DockerMachine(org.eclipse.linuxtools.internal.docker.core.DockerMachine) WritableList(org.eclipse.core.databinding.observable.list.WritableList) Point(org.eclipse.swt.graphics.Point) Clipboard(org.eclipse.swt.dnd.Clipboard) IObservableList(org.eclipse.core.databinding.observable.list.IObservableList) ValidationStatus(org.eclipse.core.databinding.validation.ValidationStatus) IStatus(org.eclipse.core.runtime.IStatus) Composite(org.eclipse.swt.widgets.Composite) Map(java.util.Map) URI(java.net.URI) MessageDialog(org.eclipse.jface.dialogs.MessageDialog) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Text(org.eclipse.swt.widgets.Text) EnumDockerConnectionSettings(org.eclipse.linuxtools.docker.core.EnumDockerConnectionSettings) Button(org.eclipse.swt.widgets.Button) PlatformUI(org.eclipse.ui.PlatformUI) DockerConnectionManager(org.eclipse.linuxtools.docker.core.DockerConnectionManager) PreferencesUtil(org.eclipse.ui.dialogs.PreferencesUtil) Display(org.eclipse.swt.widgets.Display) ListDialog(org.eclipse.ui.dialogs.ListDialog) Collectors(java.util.stream.Collectors) GridLayoutFactory(org.eclipse.jface.layout.GridLayoutFactory) InvocationTargetException(java.lang.reflect.InvocationTargetException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ILabelProvider(org.eclipse.jface.viewers.ILabelProvider) List(java.util.List) ILabelProviderListener(org.eclipse.jface.viewers.ILabelProviderListener) BeanProperties(org.eclipse.core.databinding.beans.BeanProperties) SWT(org.eclipse.swt.SWT) DirectoryDialog(org.eclipse.swt.widgets.DirectoryDialog) Label(org.eclipse.swt.widgets.Label) TCPConnectionSettings(org.eclipse.linuxtools.internal.docker.core.TCPConnectionSettings) SelectionListener(org.eclipse.swt.events.SelectionListener) DockerCertificateException(com.spotify.docker.client.exceptions.DockerCertificateException) IValueChangeListener(org.eclipse.core.databinding.observable.value.IValueChangeListener) IDockerConnectionSettings(org.eclipse.linuxtools.docker.core.IDockerConnectionSettings) Image(org.eclipse.swt.graphics.Image) DataBindingContext(org.eclipse.core.databinding.DataBindingContext) IObservableValue(org.eclipse.core.databinding.observable.value.IObservableValue) WidgetProperties(org.eclipse.jface.databinding.swt.WidgetProperties) StringTokenizer(java.util.StringTokenizer) IStructuredContentProvider(org.eclipse.jface.viewers.IStructuredContentProvider) DockerException(org.eclipse.linuxtools.docker.core.DockerException) TextTransfer(org.eclipse.swt.dnd.TextTransfer) WizardPage(org.eclipse.jface.wizard.WizardPage) PreferenceConstants(org.eclipse.linuxtools.internal.docker.ui.preferences.PreferenceConstants) DefaultDockerConnectionSettingsFinder(org.eclipse.linuxtools.internal.docker.core.DefaultDockerConnectionSettingsFinder) Viewer(org.eclipse.jface.viewers.Viewer) FileDialog(org.eclipse.swt.widgets.FileDialog) GridDataFactory(org.eclipse.jface.layout.GridDataFactory) BindingType(org.eclipse.linuxtools.docker.core.IDockerConnectionSettings.BindingType) Group(org.eclipse.swt.widgets.Group) File(java.io.File) MultiValidator(org.eclipse.core.databinding.validation.MultiValidator) DockerConnection(org.eclipse.linuxtools.internal.docker.core.DockerConnection) SWTImagesFactory(org.eclipse.linuxtools.internal.docker.ui.SWTImagesFactory) UnixSocketConnectionSettings(org.eclipse.linuxtools.internal.docker.core.UnixSocketConnectionSettings) UNIX_SOCKET(org.eclipse.linuxtools.docker.core.EnumDockerConnectionSettings.UNIX_SOCKET) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) Collections(java.util.Collections) Control(org.eclipse.swt.widgets.Control) DockerException(org.eclipse.linuxtools.docker.core.DockerException) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ListDialog(org.eclipse.ui.dialogs.ListDialog)

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