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();
}
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;
}
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;
}
Aggregations