Search in sources :

Example 31 with DockerException

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

the class RestartContainersCommandHandler method executeInJob.

@Override
void executeInJob(final IDockerContainer container, final IDockerConnection connection) {
    try {
        final RunConsole console = getRunConsole(connection, container);
        long waitTime = Platform.getPreferencesService().getLong(// $NON-NLS-1$
        "org.eclipse.linuxtools.docker.ui", PreferenceConstants.RESTART_WAIT_TIME, DEFAULT_WAIT_TIME, null);
        if (console != null) {
            // if we are auto-logging, show the console
            console.showConsole();
            // Start the container
            ((DockerConnection) connection).restartContainer(container.id(), (int) waitTime, console.getOutputStream());
        } else {
            ((DockerConnection) connection).restartContainer(container.id(), (int) waitTime, null);
        }
        connection.getContainers(true);
    } catch (DockerException | InterruptedException e) {
        final String errorMessage = DVMessages.getFormattedString(CONTAINER_RESTART_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 32 with DockerException

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

the class ShowInSystemExplorerCommandHandler method execute.

@Override
public Object execute(final ExecutionEvent event) {
    final IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
    final List<DockerContainerVolume> volumes = CommandUtils.getSelectedVolumes(activePart);
    if (volumes == null || volumes.isEmpty()) {
        return null;
    }
    final DockerContainerVolume selectedVolume = volumes.get(0);
    final File hostFile = new File(selectedVolume.getHostPath());
    final String launchCmd = getShowInSystemExplorerCommand(hostFile);
    if (launchCmd == null) {
        return null;
    }
    final Job job = new Job(CommandMessages.getString("command.showIn.systemExplorer")) {

        // $NON-NLS-1$
        @Override
        protected IStatus run(final IProgressMonitor monitor) {
            try {
                final Process p = getLaunchProcess(launchCmd, hostFile);
                final int retCode = p.waitFor();
                if (retCode != 0 && !Util.isWindows()) {
                    Activator.log(new DockerException(CommandMessages.getFormattedString(// $NON-NLS-1$
                    "command.showIn.systemExplorer.failure.command.execute", launchCmd, Integer.toString(retCode))));
                }
            } catch (IOException | InterruptedException e) {
                Activator.logErrorMessage(CommandMessages.getFormattedString(// $NON-NLS-1$
                "command.showIn.systemExplorer.failure", launchCmd), e);
            } finally {
                monitor.done();
            }
            return Status.OK_STATUS;
        }
    };
    job.setUser(true);
    job.schedule();
    return null;
}
Also used : DockerException(org.eclipse.linuxtools.docker.core.DockerException) IOException(java.io.IOException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) DockerContainerVolume(org.eclipse.linuxtools.internal.docker.ui.views.DockerExplorerContentProvider.DockerContainerVolume) Job(org.eclipse.core.runtime.jobs.Job) File(java.io.File)

Example 33 with DockerException

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

the class PushImageToRegistryJob method doRun.

@Override
protected IStatus doRun(final IProgressMonitor monitor) {
    monitor.beginTask("Pushing image to registry", 1);
    final String tmpImageName = getPushToRegistryImageName();
    try {
        // first, we need to tag the image with the OpenShift target
        // project
        this.dockerConnection.tagImage(imageName, tmpImageName);
        // then we can push that image with the new name
        this.dockerConnection.pushImage(tmpImageName, registryAccount, getPushProgressHandler(tmpImageName));
    // FIXME: needs more fined tuned error handling once Neon.0 is no longer supported:
    // catch (DockerException | InterruptedException e) {
    // see https://issues.jboss.org/browse/JBIDE-22764
    } catch (Exception e) {
        return new Status(IStatus.ERROR, OpenShiftCoreActivator.PLUGIN_ID, "Failed to push the selected Docker image into OpenShift registry", e);
    } finally {
        // we need to untag the image, even if the push operation failed
        try {
            this.dockerConnection.removeTag(tmpImageName);
        } catch (DockerException | InterruptedException e) {
            return new Status(IStatus.WARNING, OpenShiftCoreActivator.PLUGIN_ID, "Pushed the selected Docker image into OpenShift registry but failed to untag it afterwards", e);
        }
        monitor.done();
    }
    return Status.OK_STATUS;
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) DockerException(org.eclipse.linuxtools.docker.core.DockerException) MalformedURLException(java.net.MalformedURLException) DockerException(org.eclipse.linuxtools.docker.core.DockerException)

Example 34 with DockerException

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

the class DockerConnection method startContainer.

@Override
public void startContainer(final String id, final OutputStream stream) throws DockerException, InterruptedException {
    final IDockerContainerInfo containerInfo = getContainerInfo(id);
    if (containerInfo == null) {
        throw new DockerException(DockerMessages.getFormattedString("DockerContainerNotFound.error", // $NON-NLS-1$
        id));
    }
    try {
        // start container
        client.startContainer(id);
        // Log the started container if a stream is provided
        if (stream != null && containerInfo != null && containerInfo.config() != null && !containerInfo.config().tty()) {
            // display logs for container
            synchronized (loggingThreads) {
                LogThread t = loggingThreads.get(id);
                if (t == null || !t.isAlive()) {
                    t = new LogThread(id, getClientCopy(), true);
                    loggingThreads.put(id, t);
                    t.setOutputStream(stream);
                    t.start();
                }
            }
        }
        // list of containers needs to be refreshed once the container started, to reflect it new state.
        listContainers();
    } catch (ContainerNotFoundException e) {
        // clearly stated so report there was a problem starting the command
        throw new DockerException(DockerMessages.getFormattedString("DockerStartContainer.error", // $NON-NLS-1$
        getCmdString(containerInfo)));
    } catch (com.spotify.docker.client.exceptions.DockerRequestException e) {
        throw new DockerException(e.message());
    } catch (com.spotify.docker.client.exceptions.DockerException e) {
        throw new DockerException(e.getMessage(), e.getCause());
    }
}
Also used : DockerException(org.eclipse.linuxtools.docker.core.DockerException) IDockerContainerInfo(org.eclipse.linuxtools.docker.core.IDockerContainerInfo) ContainerNotFoundException(com.spotify.docker.client.exceptions.ContainerNotFoundException) DockerContainerNotFoundException(org.eclipse.linuxtools.docker.core.DockerContainerNotFoundException)

Example 35 with DockerException

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

the class DockerConnection method killContainer.

@Override
public void killContainer(final String id) throws DockerException, InterruptedException {
    try {
        // kill container
        client.killContainer(id);
        synchronized (loggingThreads) {
            if (loggingThreads.containsKey(id)) {
                loggingThreads.get(id).kill();
                loggingThreads.remove(id);
            }
        }
        // update container list
        listContainers();
    } catch (ContainerNotFoundException e) {
        throw new DockerContainerNotFoundException(e);
    } catch (com.spotify.docker.client.exceptions.DockerRequestException e) {
    // Permit kill to fail silently even on non-running containers
    } catch (com.spotify.docker.client.exceptions.DockerException e) {
        throw new DockerException(e.getMessage(), e.getCause());
    }
}
Also used : DockerException(org.eclipse.linuxtools.docker.core.DockerException) DockerContainerNotFoundException(org.eclipse.linuxtools.docker.core.DockerContainerNotFoundException) ContainerNotFoundException(com.spotify.docker.client.exceptions.ContainerNotFoundException) DockerContainerNotFoundException(org.eclipse.linuxtools.docker.core.DockerContainerNotFoundException)

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