Search in sources :

Example 1 with EnumDockerLoggingStatus

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

the class DisplayContainerLogCommandHandler method execute.

@Override
public Object execute(final ExecutionEvent event) {
    final IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
    final IDockerConnection connection = CommandUtils.getCurrentConnection(activePart);
    final List<IDockerContainer> selectedContainers = CommandUtils.getSelectedContainers(activePart);
    if (selectedContainers.size() != 1 || connection == null) {
        return null;
    }
    final IDockerContainer container = selectedContainers.get(0);
    final String id = container.id();
    final String name = container.name();
    if (connection.getContainerInfo(id).config().tty()) {
        RunConsole.attachToTerminal(connection, id, null);
        return null;
    }
    try {
        final RunConsole rc = RunConsole.findConsole(id);
        if (rc != null) {
            if (!rc.isAttached()) {
                rc.attachToConsole(connection);
            }
            Display.getDefault().syncExec(() -> rc.setTitle(DVMessages.getFormattedString(CONTAINER_LOG_TITLE, name)));
            OutputStream stream = rc.getOutputStream();
            // Only bother to ask for a log if
            // one isn't currently active
            EnumDockerLoggingStatus status = ((DockerConnection) connection).loggingStatus(id);
            if (status != EnumDockerLoggingStatus.LOGGING_ACTIVE && !((DockerConnection) connection).getContainerInfo(id).config().tty()) {
                rc.clearConsole();
                ((DockerConnection) connection).logContainer(id, stream);
            }
            rc.showConsole();
        }
    } catch (DockerException | InterruptedException e) {
        Display.getDefault().syncExec(() -> MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), DVMessages.getFormattedString(ERROR_LOGGING_CONTAINER, id), e.getMessage()));
    }
    return null;
}
Also used : IDockerContainer(org.eclipse.linuxtools.docker.core.IDockerContainer) IDockerConnection(org.eclipse.linuxtools.docker.core.IDockerConnection) DockerConnection(org.eclipse.linuxtools.internal.docker.core.DockerConnection) DockerException(org.eclipse.linuxtools.docker.core.DockerException) RunConsole(org.eclipse.linuxtools.internal.docker.ui.consoles.RunConsole) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) OutputStream(java.io.OutputStream) IDockerConnection(org.eclipse.linuxtools.docker.core.IDockerConnection) EnumDockerLoggingStatus(org.eclipse.linuxtools.docker.core.EnumDockerLoggingStatus)

Aggregations

OutputStream (java.io.OutputStream)1 DockerException (org.eclipse.linuxtools.docker.core.DockerException)1 EnumDockerLoggingStatus (org.eclipse.linuxtools.docker.core.EnumDockerLoggingStatus)1 IDockerConnection (org.eclipse.linuxtools.docker.core.IDockerConnection)1 IDockerContainer (org.eclipse.linuxtools.docker.core.IDockerContainer)1 DockerConnection (org.eclipse.linuxtools.internal.docker.core.DockerConnection)1 RunConsole (org.eclipse.linuxtools.internal.docker.ui.consoles.RunConsole)1 IWorkbenchPart (org.eclipse.ui.IWorkbenchPart)1