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