Search in sources :

Example 1 with IDockerContainerState

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

the class RunConsole method attachToTerminal.

public static void attachToTerminal(final IDockerConnection connection, final String containerId, final DockerConsoleOutputStream out) {
    Thread t = new Thread(() -> {
        try {
            DockerConnection conn = (DockerConnection) connection;
            IDockerContainerState state = conn.getContainerInfo(containerId).state();
            do {
                if (!state.running() && (state.finishDate() == null || state.finishDate().before(state.startDate()))) {
                    Thread.sleep(300);
                }
                state = conn.getContainerInfo(containerId).state();
            } while (!state.running() && (state.finishDate() == null || state.finishDate().before(state.startDate())));
            // Pause as there appears to be some timing issue with regards
            // to the Container saying it is running, but an exception
            // thrown when we try and attach.
            Thread.sleep(300);
            state = conn.getContainerInfo(containerId).state();
            if (state.running()) {
                conn.attachCommand(containerId, null, out);
            } else {
                // notify any console listener that there is no more output
                // going to follow
                out.notifyConsoleListeners(new byte[] { 0 }, 0, 0);
            }
        } catch (Exception e) {
            Activator.log(e);
            // notify any console listener that there is no more output
            // going to follow
            out.notifyConsoleListeners(new byte[] { 0 }, 0, 0);
        }
    });
    t.start();
}
Also used : IDockerConnection(org.eclipse.linuxtools.docker.core.IDockerConnection) DockerConnection(org.eclipse.linuxtools.internal.docker.core.DockerConnection) IDockerContainerState(org.eclipse.linuxtools.docker.core.IDockerContainerState) IOException(java.io.IOException)

Example 2 with IDockerContainerState

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

the class RunConsole method attachToConsole.

/**
 * The console will be attached to the underlying container.
 *
 * @param connection
 *            The connection associated with this console.
 */
public void attachToConsole(final IDockerConnection connection) {
    final InputStream in = getInputStream();
    Thread t = new Thread(() -> {
        try {
            DockerConnection conn = (DockerConnection) connection;
            if (conn.getContainerInfo(containerId).config().openStdin()) {
                IDockerContainerState state = conn.getContainerInfo(containerId).state();
                do {
                    if (!state.running() && (state.finishDate() == null || state.finishDate().before(state.startDate()))) {
                        Thread.sleep(300);
                    }
                    state = conn.getContainerInfo(containerId).state();
                } while (!state.running() && (state.finishDate() == null || state.finishDate().before(state.startDate())));
                Thread.sleep(300);
                state = conn.getContainerInfo(containerId).state();
                if (state.running()) {
                    conn.attachCommand(containerId, in, null);
                }
            }
        } catch (Exception e) {
            Activator.log(e);
        }
    });
    t.start();
    attached = true;
}
Also used : IDockerConnection(org.eclipse.linuxtools.docker.core.IDockerConnection) DockerConnection(org.eclipse.linuxtools.internal.docker.core.DockerConnection) InputStream(java.io.InputStream) IDockerContainerState(org.eclipse.linuxtools.docker.core.IDockerContainerState) IOException(java.io.IOException)

Example 3 with IDockerContainerState

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

the class ContainerInspectContentProvider method getChildren.

@Override
public Object[] getChildren(Object parentElement) {
    final Object propertyValue = ((Object[]) parentElement)[1];
    if (propertyValue instanceof IDockerContainerState) {
        final IDockerContainerState containerState = (IDockerContainerState) propertyValue;
        return new Object[] { // $NON-NLS-1$
        new Object[] { "ExitCode", containerState.exitCode() }, // $NON-NLS-1$
        new Object[] { "Finished at", LabelProviderUtils.toFinishedDate(containerState.finishDate()) }, // $NON-NLS-1$
        new Object[] { "Running", containerState.running() }, // $NON-NLS-1$
        new Object[] { "Paused", containerState.paused() }, // $NON-NLS-1$
        new Object[] { "Pid", containerState.pid() } };
    } else if (propertyValue instanceof IDockerHostConfig) {
        final DockerHostConfig hostConfig = (DockerHostConfig) propertyValue;
        return new Object[] { // $NON-NLS-1$
        new Object[] { "Binds", LabelProviderUtils.reduce(hostConfig.binds()) }, // $NON-NLS-1$
        new Object[] { "CapAdd", hostConfig.capAdd() }, // $NON-NLS-1$
        new Object[] { "CapDrop", hostConfig.capDrop() }, // $NON-NLS-1$
        new Object[] { "ContainerIDFile", hostConfig.containerIDFile() }, // $NON-NLS-1$
        new Object[] { "Dns", LabelProviderUtils.reduce(hostConfig.dns()) }, // $NON-NLS-1$
        new Object[] { "DnsSearch", LabelProviderUtils.reduce(hostConfig.dnsSearch()) }, // $NON-NLS-1$
        new Object[] { "Links", splitLinks(hostConfig.links()) }, // $NON-NLS-1$
        new Object[] { "LxcConf", hostConfig.lxcConf() }, // $NON-NLS-1$
        new Object[] { "NetworkMode", hostConfig.networkMode() }, // $NON-NLS-1$
        new Object[] { "PortBindings", LabelProviderUtils.reduce(hostConfig.portBindings()) }, // $NON-NLS-1$
        new Object[] { "Privileged", hostConfig.privileged() }, // $NON-NLS-1$
        new Object[] { "PublishAllPorts", hostConfig.publishAllPorts() }, new Object[] { // $NON-NLS-1$
        "ReadonlyRootfs", hostConfig.readonlyRootfs() }, // $NON-NLS-1$
        new Object[] { "SecurityOpt", hostConfig.securityOpt() }, // $NON-NLS-1$
        new Object[] { "Tmpfs", hostConfig.tmpfs() }, // $NON-NLS-1$
        new Object[] { "VolumesFrom", LabelProviderUtils.reduce(hostConfig.volumesFrom()) } };
    } else if (propertyValue instanceof IDockerContainerConfig) {
        final IDockerContainerConfig config = (IDockerContainerConfig) propertyValue;
        return new Object[] { // $NON-NLS-1$
        new Object[] { "AttachStderr", config.attachStderr() }, // $NON-NLS-1$
        new Object[] { "AttachStdin", config.attachStdin() }, // $NON-NLS-1$
        new Object[] { "AttachStdout", config.attachStdout() }, // $NON-NLS-1$
        new Object[] { "Cmd", LabelProviderUtils.reduce(config.cmd()) }, // $NON-NLS-1$
        new Object[] { "CpuSet", config.cpuset() }, // $NON-NLS-1$
        new Object[] { "CpuShares", config.cpuShares() }, // $NON-NLS-1$
        new Object[] { "Domainname", config.domainname() }, // $NON-NLS-1$
        new Object[] { "Entrypoint", LabelProviderUtils.reduce(config.entrypoint()) }, // $NON-NLS-1$
        new Object[] { "Env", LabelProviderUtils.reduce(config.env()) }, // $NON-NLS-1$
        new Object[] { "ExposedPorts", LabelProviderUtils.reduce(config.exposedPorts()) }, // $NON-NLS-1$
        new Object[] { "Hostname", config.hostname() }, // $NON-NLS-1$
        new Object[] { "Image", config.image() }, new Object[] { // $NON-NLS-1$
        "Labels", ((DockerContainerConfig) config).labels() }, // $NON-NLS-1$
        new Object[] { "Memory", config.memory() }, // $NON-NLS-1$
        new Object[] { "MemorySwap", config.memorySwap() }, // $NON-NLS-1$
        new Object[] { "NetworkDisabled", config.networkDisabled() }, // $NON-NLS-1$
        new Object[] { "OnBuild", config.onBuild() }, // $NON-NLS-1$
        new Object[] { "OpenStdin", config.openStdin() }, // $NON-NLS-1$
        new Object[] { "PortSpecs", LabelProviderUtils.reduce(config.portSpecs()) }, // $NON-NLS-1$
        new Object[] { "StdinOnce", config.stdinOnce() }, // $NON-NLS-1$
        new Object[] { "Tty", config.tty() }, new Object[] { // $NON-NLS-1$
        "Volumes", LabelProviderUtils.reduce(config.volumes().keySet()) }, // $NON-NLS-1$
        new Object[] { "WorkingDir", config.workingDir() } };
    } else if (propertyValue instanceof IDockerPortBinding) {
        final IDockerPortBinding portBinding = (IDockerPortBinding) propertyValue;
        return new Object[] { // $NON-NLS-1$
        new Object[] { "Host IP/Port", LabelProviderUtils.toString(portBinding) } };
    } else if (propertyValue instanceof IDockerNetworkSettings) {
        final IDockerNetworkSettings networkSettings = (IDockerNetworkSettings) propertyValue;
        return new Object[] { // $NON-NLS-1$
        new Object[] { "Bridge", networkSettings.bridge() }, // $NON-NLS-1$
        new Object[] { "Gateway", networkSettings.gateway() }, // $NON-NLS-1$
        new Object[] { "IPAddress", networkSettings.ipAddress() }, // $NON-NLS-1$
        new Object[] { "IPPrefixLen", networkSettings.ipPrefixLen() }, // $NON-NLS-1$
        new Object[] { "PortMapping", networkSettings.portMapping() }, // $NON-NLS-1$
        new Object[] { "Ports", LabelProviderUtils.reduce(networkSettings.ports()) } };
    } else if (propertyValue instanceof List<?>) {
        @SuppressWarnings("unchecked") final List<Object> propertyValues = (List<Object>) propertyValue;
        final Object[] result = new Object[propertyValues.size()];
        for (int i = 0; i < propertyValues.size(); i++) {
            // $NON-NLS-1$
            result[i] = new Object[] { "", LabelProviderUtils.toString(propertyValues.get(i)) };
        }
        return result;
    } else if (propertyValue instanceof Set<?>) {
        @SuppressWarnings("unchecked") final Set<Object> propertyValues = (Set<Object>) propertyValue;
        final Object[] result = new Object[propertyValues.size()];
        Iterator<Object> iterator = propertyValues.iterator();
        for (int i = 0; i < propertyValues.size(); i++) {
            result[i] = new Object[] { // $NON-NLS-1$
            "", LabelProviderUtils.toString(iterator.next()) };
        }
        return result;
    } else if (propertyValue instanceof Map<?, ?>) {
        final Map<?, ?> propertyValues = (Map<?, ?>) propertyValue;
        final Object[] result = new Object[propertyValues.size()];
        int i = 0;
        for (Entry<?, ?> entry : propertyValues.entrySet()) {
            result[i] = new Object[] { entry.getKey(), entry.getValue() };
            i++;
        }
        return result;
    }
    return EMPTY;
}
Also used : IDockerHostConfig(org.eclipse.linuxtools.docker.core.IDockerHostConfig) DockerHostConfig(org.eclipse.linuxtools.internal.docker.core.DockerHostConfig) IDockerNetworkSettings(org.eclipse.linuxtools.docker.core.IDockerNetworkSettings) IDockerContainerConfig(org.eclipse.linuxtools.docker.core.IDockerContainerConfig) Set(java.util.Set) IDockerHostConfig(org.eclipse.linuxtools.docker.core.IDockerHostConfig) IDockerPortBinding(org.eclipse.linuxtools.docker.core.IDockerPortBinding) Entry(java.util.Map.Entry) DockerContainerConfig(org.eclipse.linuxtools.internal.docker.core.DockerContainerConfig) IDockerContainerConfig(org.eclipse.linuxtools.docker.core.IDockerContainerConfig) List(java.util.List) IDockerContainerState(org.eclipse.linuxtools.docker.core.IDockerContainerState) Map(java.util.Map)

Aggregations

IDockerContainerState (org.eclipse.linuxtools.docker.core.IDockerContainerState)3 IOException (java.io.IOException)2 IDockerConnection (org.eclipse.linuxtools.docker.core.IDockerConnection)2 DockerConnection (org.eclipse.linuxtools.internal.docker.core.DockerConnection)2 InputStream (java.io.InputStream)1 List (java.util.List)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 Set (java.util.Set)1 IDockerContainerConfig (org.eclipse.linuxtools.docker.core.IDockerContainerConfig)1 IDockerHostConfig (org.eclipse.linuxtools.docker.core.IDockerHostConfig)1 IDockerNetworkSettings (org.eclipse.linuxtools.docker.core.IDockerNetworkSettings)1 IDockerPortBinding (org.eclipse.linuxtools.docker.core.IDockerPortBinding)1 DockerContainerConfig (org.eclipse.linuxtools.internal.docker.core.DockerContainerConfig)1 DockerHostConfig (org.eclipse.linuxtools.internal.docker.core.DockerHostConfig)1