Search in sources :

Example 6 with IDockerContainerInfo

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

the class RemoveContainerLogCommandHandler method execute.

@Override
public Object execute(final ExecutionEvent event) {
    final IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
    List<IDockerContainer> selectedContainers = CommandUtils.getSelectedContainers(activePart);
    if (activePart instanceof DockerContainersView) {
        connection = ((DockerContainersView) activePart).getConnection();
    }
    if (selectedContainers.size() != 1 || connection == null)
        return null;
    container = selectedContainers.get(0);
    IDockerContainerInfo info = connection.getContainerInfo(container.id());
    if (info.config().tty()) {
        Map<String, Object> properties = new HashMap<>();
        properties.put(ITerminalsConnectorConstants.PROP_DELEGATE_ID, "org.eclipse.tm.terminal.connector.streams.launcher.streams");
        properties.put(ITerminalsConnectorConstants.PROP_TERMINAL_CONNECTOR_ID, "org.eclipse.tm.terminal.connector.streams.StreamsConnector");
        properties.put(ITerminalsConnectorConstants.PROP_TITLE, info.name());
        ITerminalService service = TerminalServiceFactory.getService();
        service.closeConsole(properties, null);
        return null;
    }
    final RunConsole rc = RunConsole.findConsole(container);
    if (rc != null) {
        RunConsole.removeConsole(rc);
    }
    return null;
}
Also used : IDockerContainer(org.eclipse.linuxtools.docker.core.IDockerContainer) RunConsole(org.eclipse.linuxtools.internal.docker.ui.consoles.RunConsole) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) HashMap(java.util.HashMap) ITerminalService(org.eclipse.tm.terminal.view.core.interfaces.ITerminalService) DockerContainersView(org.eclipse.linuxtools.internal.docker.ui.views.DockerContainersView) IDockerContainerInfo(org.eclipse.linuxtools.docker.core.IDockerContainerInfo)

Example 7 with IDockerContainerInfo

use of org.eclipse.linuxtools.docker.core.IDockerContainerInfo 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 8 with IDockerContainerInfo

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

the class DockerConnection method execShell.

public void execShell(final String id) throws DockerException {
    try {
        final ExecCreation execCreation = client.execCreate(id, // $NON-NLS-1$
        new String[] { "/bin/sh" }, ExecCreateParam.attachStdout(), ExecCreateParam.attachStderr(), ExecCreateParam.attachStdin(), ExecCreateParam.tty());
        final String execId = execCreation.id();
        final LogStream pty_stream = client.execStart(execId, DockerClient.ExecStartParameter.TTY);
        final IDockerContainerInfo info = getContainerInfo(id);
        // $NON-NLS-1$
        openTerminal(pty_stream, info.name() + " [shell]", null);
    } catch (Exception e) {
        throw new DockerException(e.getMessage(), e.getCause());
    }
}
Also used : DockerException(org.eclipse.linuxtools.docker.core.DockerException) ExecCreation(com.spotify.docker.client.messages.ExecCreation) LogStream(com.spotify.docker.client.LogStream) IDockerContainerInfo(org.eclipse.linuxtools.docker.core.IDockerContainerInfo) DockerPingConnectionException(org.eclipse.linuxtools.docker.core.DockerPingConnectionException) DockerTimeoutException(com.spotify.docker.client.exceptions.DockerTimeoutException) ProcessingException(javax.ws.rs.ProcessingException) ContainerNotFoundException(com.spotify.docker.client.exceptions.ContainerNotFoundException) DockerCertificateException(com.spotify.docker.client.exceptions.DockerCertificateException) SocketException(java.net.SocketException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) StorageException(org.eclipse.equinox.security.storage.StorageException) DockerContainerNotFoundException(org.eclipse.linuxtools.docker.core.DockerContainerNotFoundException) DockerException(org.eclipse.linuxtools.docker.core.DockerException) DockerOpenConnectionException(org.eclipse.linuxtools.docker.core.DockerOpenConnectionException)

Example 9 with IDockerContainerInfo

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

the class DockerConnection method restartContainer.

public void restartContainer(final String id, int secondsToWait, final OutputStream stream) throws DockerException, InterruptedException {
    try {
        // restart container
        client.restartContainer(id, secondsToWait);
        // Log the started container if a stream is provided
        final IDockerContainerInfo containerInfo = getContainerInfo(id);
        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) {
        throw new DockerContainerNotFoundException(e);
    } 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) DockerContainerNotFoundException(org.eclipse.linuxtools.docker.core.DockerContainerNotFoundException) IDockerContainerInfo(org.eclipse.linuxtools.docker.core.IDockerContainerInfo) ContainerNotFoundException(com.spotify.docker.client.exceptions.ContainerNotFoundException) DockerContainerNotFoundException(org.eclipse.linuxtools.docker.core.DockerContainerNotFoundException)

Example 10 with IDockerContainerInfo

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

the class ContainerInspectPropertySection method getContainerInfo.

/**
 * @return the {@link IDockerContainerInfo} for the given
 *         {@link IDockerConnection} and {@link IDockerContainer}, or
 *         <code>null</code> if none was found or if an underlying problem
 *         occurred.
 * @param connection the current {@link IDockerConnection}.
 * @param container the {@link IDockerContainer} to inspect.
 */
private IDockerContainerInfo getContainerInfo(final IDockerConnection connection, final IDockerContainer container) {
    final BlockingQueue<IDockerContainerInfo> result = new ArrayBlockingQueue<>(1);
    final Job loadConnectionInfoJob = new Job(DVMessages.getString(PropertiesLoadingContainerInfo)) {

        @Override
        protected IStatus run(final IProgressMonitor monitor) {
            monitor.beginTask(DVMessages.getString(PropertiesLoadingContainerInfo), 1);
            final IDockerContainerInfo containerInfo = connection.getContainerInfo(container.id());
            if (containerInfo != null) {
                result.add(containerInfo);
            }
            monitor.done();
            return Status.OK_STATUS;
        }
    };
    loadConnectionInfoJob.schedule();
    try {
        return result.poll(2, TimeUnit.SECONDS);
    } catch (InterruptedException e) {
        Activator.log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, DVMessages.getFormattedString(PropertiesInfoError, connection.getName()), e));
        return null;
    }
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) IDockerContainerInfo(org.eclipse.linuxtools.docker.core.IDockerContainerInfo) Job(org.eclipse.core.runtime.jobs.Job)

Aggregations

IDockerContainerInfo (org.eclipse.linuxtools.docker.core.IDockerContainerInfo)13 DockerException (org.eclipse.linuxtools.docker.core.DockerException)6 ContainerNotFoundException (com.spotify.docker.client.exceptions.ContainerNotFoundException)4 DockerContainerNotFoundException (org.eclipse.linuxtools.docker.core.DockerContainerNotFoundException)4 HashMap (java.util.HashMap)3 IDockerConnection (org.eclipse.linuxtools.docker.core.IDockerConnection)3 IDockerContainer (org.eclipse.linuxtools.docker.core.IDockerContainer)3 LogStream (com.spotify.docker.client.LogStream)2 DockerCertificateException (com.spotify.docker.client.exceptions.DockerCertificateException)2 DockerTimeoutException (com.spotify.docker.client.exceptions.DockerTimeoutException)2 File (java.io.File)2 IOException (java.io.IOException)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 SocketException (java.net.SocketException)2 UnknownHostException (java.net.UnknownHostException)2 ArrayList (java.util.ArrayList)2 ProcessingException (javax.ws.rs.ProcessingException)2 Job (org.eclipse.core.runtime.jobs.Job)2 StorageException (org.eclipse.equinox.security.storage.StorageException)2 ProgressMonitorDialog (org.eclipse.jface.dialogs.ProgressMonitorDialog)2