Search in sources :

Example 51 with DockerException

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

the class ContainerCommandProcess method waitFor.

@Override
public synchronized int waitFor() throws InterruptedException {
    if (done) {
        return 0;
    }
    try {
        if (!threadDone) {
            while (!threadStarted) {
                Thread.sleep(200);
            }
        }
        IDockerContainerExit exit = connection.waitForContainer(containerId);
        done = true;
        // give logging thread at most 5 seconds to finish
        int i = 0;
        while (!threadDone && i++ < 10) {
            Thread.sleep(500);
        }
        if (!threadDone) {
            // we are stuck
            try {
                Activator.logWarningMessage(LaunchMessages.getFormattedString(// $NON-NLS-1$
                "ContainerLoggingNotResponding.msg", containerId.substring(0, 8)));
                this.stdout.close();
                this.stderr.close();
            } catch (IOException e) {
            // do nothing
            }
        }
        if (!containerRemoved) {
            connection.stopLoggingThread(containerId);
        }
        if (!containerRemoved && !keepContainer) {
            exitValue = exitValue();
            containerRemoved = true;
            connection.removeContainer(containerId);
        }
        if (!((DockerConnection) connection).isLocal()) {
            CopyVolumesFromImageJob job = new CopyVolumesFromImageJob(connection, imageName, remoteVolumes);
            job.schedule();
            job.join();
        }
        return exit.statusCode();
    } catch (DockerException e) {
        return -1;
    }
}
Also used : DockerException(org.eclipse.linuxtools.docker.core.DockerException) IOException(java.io.IOException) IDockerContainerExit(org.eclipse.linuxtools.docker.core.IDockerContainerExit)

Example 52 with DockerException

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

the class DockerComposeUpShortcut method launch.

@Override
protected void launch(IResource resource, String mode) {
    // the predicate to apply on the launch configuration to find the
    // matching candidates
    final Predicate<ILaunchConfiguration> predicate = config -> {
        try {
            final String sourcePath = config.getAttribute(IDockerComposeLaunchConfigurationConstants.WORKING_DIR, // $NON-NLS-1$
            "");
            final boolean workspaceRelative = config.getAttribute(IDockerComposeLaunchConfigurationConstants.WORKING_DIR_WORKSPACE_RELATIVE_LOCATION, false);
            final IPath dockerfilePath = getPath(sourcePath, workspaceRelative);
            return dockerfilePath.equals(resource.getLocation().removeLastSegments(1));
        } catch (CoreException e) {
            Activator.log(e);
            return false;
        }
    };
    final ILaunchConfiguration config = findLaunchConfiguration(IDockerComposeLaunchConfigurationConstants.CONFIG_TYPE_ID, resource, predicate);
    if (config != null) {
        DebugUITools.launch(config, mode);
    } else {
        Activator.log(new DockerException(LaunchMessages.getString(// $NON-NLS-1$
        "DockerComposeUpShortcut.launchconfig.error")));
    }
}
Also used : PlatformUI(org.eclipse.ui.PlatformUI) Predicate(java.util.function.Predicate) DockerComposeUpDialog(org.eclipse.linuxtools.internal.docker.ui.wizards.DockerComposeUpDialog) DockerConnectionManager(org.eclipse.linuxtools.docker.core.DockerConnectionManager) Activator(org.eclipse.linuxtools.docker.ui.Activator) NewDockerConnection(org.eclipse.linuxtools.internal.docker.ui.wizards.NewDockerConnection) CoreException(org.eclipse.core.runtime.CoreException) IDialogConstants(org.eclipse.jface.dialogs.IDialogConstants) Display(org.eclipse.swt.widgets.Display) DebugUITools(org.eclipse.debug.ui.DebugUITools) ILaunchConfiguration(org.eclipse.debug.core.ILaunchConfiguration) ILaunchShortcut(org.eclipse.debug.ui.ILaunchShortcut) IPath(org.eclipse.core.runtime.IPath) IResource(org.eclipse.core.resources.IResource) DockerException(org.eclipse.linuxtools.docker.core.DockerException) CommandUtils(org.eclipse.linuxtools.internal.docker.ui.commands.CommandUtils) MessageDialog(org.eclipse.jface.dialogs.MessageDialog) DockerException(org.eclipse.linuxtools.docker.core.DockerException) ILaunchConfiguration(org.eclipse.debug.core.ILaunchConfiguration) IPath(org.eclipse.core.runtime.IPath) CoreException(org.eclipse.core.runtime.CoreException)

Example 53 with DockerException

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

the class RunImageLaunchConfigurationTabGroup method createTabs.

@Override
public void createTabs(ILaunchConfigurationDialog dialog, String mode) {
    runSelectionModel = null;
    runVolumesModel = null;
    runNetworkModel = null;
    if (DockerConnectionManager.getInstance().hasConnections()) {
        runSelectionModel = new ImageRunSelectionModel(CommandUtils.getCurrentConnection(null));
        runNetworkModel = new ImageRunNetworkModel(CommandUtils.getCurrentConnection(null));
        try {
            runVolumesModel = new ImageRunResourceVolumesVariablesModel(CommandUtils.getCurrentConnection(null));
        } catch (DockerException e) {
        // do nothing
        }
    }
    setTabs(new AbstractLaunchConfigurationTab[] { new RunImageMainTab(runSelectionModel, runVolumesModel, runNetworkModel), new RunImageVolumesTab(runVolumesModel), new RunImagePortsTab(runSelectionModel), new RunImageLinksTab(runSelectionModel), new RunImageNetworkTab(runNetworkModel), new RunImageEnvironmentTab(runVolumesModel), new RunImageLabelsTab(runVolumesModel), new RunImageResourcesTab(runVolumesModel), new org.eclipse.debug.ui.CommonTab() });
}
Also used : DockerException(org.eclipse.linuxtools.docker.core.DockerException) ImageRunResourceVolumesVariablesModel(org.eclipse.linuxtools.internal.docker.ui.wizards.ImageRunResourceVolumesVariablesModel) ImageRunNetworkModel(org.eclipse.linuxtools.internal.docker.ui.wizards.ImageRunNetworkModel) ImageRunSelectionModel(org.eclipse.linuxtools.internal.docker.ui.wizards.ImageRunSelectionModel)

Example 54 with DockerException

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

the class DockerContainersView method setLabelFilterIds.

private void setLabelFilterIds() {
    IEclipsePreferences preferences = InstanceScope.INSTANCE.getNode(Activator.PLUGIN_ID);
    boolean filterLabels = preferences.getBoolean(FILTER_WITH_LABELS_PREFERENCE, Boolean.FALSE);
    if (filterLabels) {
        String filterLabelString = preferences.get(CONTAINER_FILTER_LABELS, // $NON-NLS-1$
        "");
        if (filterLabelString.isEmpty()) {
            containersWithLabelsViewerFilter.setIds(null);
        } else {
            // $NON-NLS-1$
            String[] labels = filterLabelString.split("\u00a0");
            LinkedHashMap<String, String> labelMap = new LinkedHashMap<>();
            for (String label : labels) {
                if (label.length() > 1) {
                    // $NON-NLS-1$
                    String[] tokens = label.split("=");
                    String key = tokens[0];
                    // $NON-NLS-1$
                    String value = "";
                    if (tokens.length > 1)
                        value = tokens[1];
                    labelMap.put(key, value);
                }
            }
            Set<String> filterIds = new HashSet<>();
            try {
                filterIds = ((DockerConnection) connection).getContainerIdsWithLabels(labelMap);
            } catch (DockerException e) {
                Activator.log(e);
            }
            containersWithLabelsViewerFilter.setIds(filterIds);
        }
    }
}
Also used : DockerException(org.eclipse.linuxtools.docker.core.DockerException) IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences) LinkedHashMap(java.util.LinkedHashMap) HashSet(java.util.HashSet)

Example 55 with DockerException

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

the class DockerExplorerContentProvider method openRetry.

/**
 * Call the {@link IDockerConnection#open(boolean)} in a background job to
 * continually retry opening the connection and avoid blocking the UI.
 *
 * @param connection
 *            the connection to open/ping
 */
private void openRetry(final IDockerConnection connection) {
    final Job openRetryJob = new LoadingJob(// $NON-NLS-1$
    DVMessages.getFormattedString(// $NON-NLS-1$
    "PingJob2.msg", connection.getName(), connection.getUri()), connection) {

        @Override
        protected IStatus run(final IProgressMonitor monitor) {
            setMonitor(monitor);
            long totalSleep = 0;
            // 3 second default
            long sleepTime = 3000;
            for (; ; ) {
                try {
                    // check if Connection is removed or cancelled
                    if (monitor.isCanceled() || DockerConnectionManager.getInstance().getConnectionByUri(connection.getUri()) == null) {
                        synchronized (openRetryJobs) {
                            openRetryJobs.remove(connection);
                        }
                        return Status.CANCEL_STATUS;
                    }
                    connection.open(true);
                    connection.ping();
                    synchronized (openRetryJobs) {
                        openRetryJobs.remove(connection);
                    }
                    return Status.OK_STATUS;
                } catch (DockerException e) {
                // ignore
                }
                try {
                    Thread.sleep(sleepTime);
                    totalSleep += sleepTime;
                    // we never use.
                    if (totalSleep > 300000) {
                        // prevent a future overflow
                        totalSleep = 0;
                        sleepTime = Platform.getPreferencesService().getLong(// $NON-NLS-1$
                        "org.eclipse.linuxtools.docker.ui", // $NON-NLS-1$
                        "containerRefreshTime", // $NON-NLS-1$
                        15000, null);
                    }
                } catch (InterruptedException e) {
                    synchronized (openRetryJobs) {
                        openRetryJobs.remove(connection);
                    }
                    return Status.CANCEL_STATUS;
                }
            }
        }
    };
    synchronized (openRetryJobs) {
        openRetryJobs.put(connection, openRetryJob);
    }
    openRetryJob.setSystem(true);
    openRetryJob.schedule();
}
Also used : DockerException(org.eclipse.linuxtools.docker.core.DockerException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Job(org.eclipse.core.runtime.jobs.Job)

Aggregations

DockerException (org.eclipse.linuxtools.docker.core.DockerException)78 IDockerConnection (org.eclipse.linuxtools.docker.core.IDockerConnection)26 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