use of org.eclipse.linuxtools.docker.core.IDockerConnection in project linuxtools by eclipse.
the class StartContainersCommandHandler method executeInJob.
@Override
void executeInJob(final IDockerContainer container, final IDockerConnection connection) {
try {
final RunConsole console = getRunConsole(connection, container);
if (console != null) {
// if we are auto-logging, show the console
console.showConsole();
// Start the container
((DockerConnection) connection).startContainer(container.id(), console.getOutputStream());
} else {
((DockerConnection) connection).startContainer(container.id(), null);
}
((DockerConnection) connection).getContainers(true);
} catch (DockerException | InterruptedException e) {
final String errorMessage = DVMessages.getFormattedString(CONTAINER_START_ERROR_MSG, container.id());
openError(errorMessage, e);
}
}
use of org.eclipse.linuxtools.docker.core.IDockerConnection 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.IDockerConnection 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.IDockerConnection in project linuxtools by eclipse.
the class BuildDockerImageLaunchConfigurationDelegate method launch.
@Override
public void launch(final ILaunchConfiguration configuration, final String mode, final ILaunch launch, final IProgressMonitor monitor) throws CoreException {
final String sourcePathLocation = configuration.getAttribute(SOURCE_PATH_LOCATION, (String) null);
final boolean sourcePathWorkspaceRelativeLocation = configuration.getAttribute(SOURCE_PATH_WORKSPACE_RELATIVE_LOCATION, false);
final IPath sourcePath = BuildDockerImageUtils.getPath(sourcePathLocation, sourcePathWorkspaceRelativeLocation);
final String connectionName = configuration.getAttribute(DOCKER_CONNECTION, (String) null);
final String repoName = configuration.getAttribute(REPO_NAME, (String) null);
final IDockerConnection connection = DockerConnectionManager.getInstance().getConnectionByName(connectionName);
final Map<String, Object> buildOptions = new HashMap<>();
buildOptions.put(QUIET_BUILD, configuration.getAttribute(QUIET_BUILD, false));
buildOptions.put(NO_CACHE, configuration.getAttribute(NO_CACHE, false));
buildOptions.put(RM_INTERMEDIATE_CONTAINERS, configuration.getAttribute(RM_INTERMEDIATE_CONTAINERS, true));
buildOptions.put(FORCE_RM_INTERMEDIATE_CONTAINERS, configuration.getAttribute(FORCE_RM_INTERMEDIATE_CONTAINERS, false));
if (connection != null && sourcePath != null) {
final Job buildImageJob = new BuildDockerImageJob(connection, sourcePath, repoName, buildOptions);
buildImageJob.schedule();
} else {
final ILaunchGroup launchGroup = DebugUITools.getLaunchGroup(configuration, // $NON-NLS-1$
"run");
// prompt the user with the launch configuration editor
Display.getDefault().syncExec(() -> DebugUITools.openLaunchConfigurationDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), configuration, launchGroup.getIdentifier(), null));
}
}
use of org.eclipse.linuxtools.docker.core.IDockerConnection in project linuxtools by eclipse.
the class DockerComposeUpLaunchConfigurationDelegate method launch.
@Override
public void launch(final ILaunchConfiguration configuration, final String mode, final ILaunch launch, final IProgressMonitor monitor) throws CoreException {
final String sourcePathLocation = configuration.getAttribute(WORKING_DIR, (String) null);
final boolean sourcePathWorkspaceRelativeLocation = configuration.getAttribute(WORKING_DIR_WORKSPACE_RELATIVE_LOCATION, false);
final IPath sourcePath = BuildDockerImageUtils.getPath(sourcePathLocation, sourcePathWorkspaceRelativeLocation);
final String connectionName = configuration.getAttribute(DOCKER_CONNECTION, (String) null);
final IDockerConnection connection = DockerConnectionManager.getInstance().getConnectionByName(connectionName);
if (connection != null && sourcePath != null) {
final Job dockerComposeUpJob = new DockerComposeUpJob(connection, sourcePath.toOSString(), configuration);
dockerComposeUpJob.schedule();
} else {
final ILaunchGroup launchGroup = DebugUITools.getLaunchGroup(configuration, // $NON-NLS-1$
"run");
// prompt the user with the launch configuration editor
Display.getDefault().syncExec(() -> DebugUITools.openLaunchConfigurationDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), configuration, launchGroup.getIdentifier(), null));
}
}
Aggregations