Search in sources :

Example 1 with ITerminalService

use of org.eclipse.tm.terminal.view.core.interfaces.ITerminalService 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 2 with ITerminalService

use of org.eclipse.tm.terminal.view.core.interfaces.ITerminalService in project linuxtools by eclipse.

the class DockerConnection method openTerminal.

private void openTerminal(LogStream pty_stream, String name, DockerConsoleOutputStream out) throws DockerException {
    try {
        OutputStream tout = noBlockingOutputStream(HttpHijackWorkaround.getOutputStream(pty_stream, getUri()));
        InputStream tin = HttpHijackWorkaround.getInputStream(pty_stream);
        TerminalOutputMonitorListener monitor = new TerminalOutputMonitorListener(out);
        // org.eclipse.tm.terminal.connector.ssh.controls.SshWizardConfigurationPanel
        Map<String, Object> properties = new HashMap<>();
        properties.put(ITerminalsConnectorConstants.PROP_DELEGATE_ID, // $NON-NLS-1$
        "org.eclipse.tm.terminal.connector.streams.launcher.streams");
        properties.put(ITerminalsConnectorConstants.PROP_TERMINAL_CONNECTOR_ID, // $NON-NLS-1$
        "org.eclipse.tm.terminal.connector.streams.StreamsConnector");
        properties.put(ITerminalsConnectorConstants.PROP_TITLE, name);
        properties.put(ITerminalsConnectorConstants.PROP_LOCAL_ECHO, false);
        properties.put(ITerminalsConnectorConstants.PROP_FORCE_NEW, true);
        properties.put(ITerminalsConnectorConstants.PROP_STREAMS_STDIN, tout);
        properties.put(ITerminalsConnectorConstants.PROP_STREAMS_STDOUT, tin);
        properties.put(ITerminalsConnectorConstants.PROP_STDERR_LISTENERS, new ITerminalServiceOutputStreamMonitorListener[] { monitor });
        properties.put(ITerminalsConnectorConstants.PROP_STDOUT_LISTENERS, new ITerminalServiceOutputStreamMonitorListener[] { monitor });
        properties.put(ITerminalsConnectorConstants.PROP_DATA, pty_stream);
        /*
			 * The JVM will call finalize() on 'pty_stream' (LogStream)
			 * since we hold no references to it (although we do hold
			 * references to one of its heavily nested fields. The
			 * LogStream overrides finalize() to close the stream being
			 * used so we must preserve a reference to it.
			 */
        // $NON-NLS-1$
        properties.put("PREVENT_JVM_GC_FINALIZE", pty_stream);
        // save properties to remove terminal later
        if (out != null) {
            out.setTerminalProperties(properties);
        }
        ITerminalService service = TerminalServiceFactory.getService();
        service.openConsole(properties, null);
    } catch (Exception e) {
        throw new DockerException(e.getMessage(), e.getCause());
    }
}
Also used : DockerException(org.eclipse.linuxtools.docker.core.DockerException) HashMap(java.util.HashMap) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) ITerminalService(org.eclipse.tm.terminal.view.core.interfaces.ITerminalService) 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)

Aggregations

HashMap (java.util.HashMap)2 ITerminalService (org.eclipse.tm.terminal.view.core.interfaces.ITerminalService)2 ContainerNotFoundException (com.spotify.docker.client.exceptions.ContainerNotFoundException)1 DockerCertificateException (com.spotify.docker.client.exceptions.DockerCertificateException)1 DockerTimeoutException (com.spotify.docker.client.exceptions.DockerTimeoutException)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 SocketException (java.net.SocketException)1 UnknownHostException (java.net.UnknownHostException)1 ProcessingException (javax.ws.rs.ProcessingException)1 StorageException (org.eclipse.equinox.security.storage.StorageException)1 DockerContainerNotFoundException (org.eclipse.linuxtools.docker.core.DockerContainerNotFoundException)1 DockerException (org.eclipse.linuxtools.docker.core.DockerException)1 DockerOpenConnectionException (org.eclipse.linuxtools.docker.core.DockerOpenConnectionException)1 DockerPingConnectionException (org.eclipse.linuxtools.docker.core.DockerPingConnectionException)1 IDockerContainer (org.eclipse.linuxtools.docker.core.IDockerContainer)1 IDockerContainerInfo (org.eclipse.linuxtools.docker.core.IDockerContainerInfo)1 RunConsole (org.eclipse.linuxtools.internal.docker.ui.consoles.RunConsole)1 DockerContainersView (org.eclipse.linuxtools.internal.docker.ui.views.DockerContainersView)1