Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeff Johnston2018-05-07 17:40:13 -0400
committerJeff Johnston2018-05-07 18:38:48 -0400
commit113a98ff02dafb4dd2699ca691b57c574a8adc3f (patch)
treedf14efa98345ee54f83616e249534089fbd42baa
parent8416bc6dcae7b1d9027bab9b6275ce37b5f39e1a (diff)
downloadorg.eclipse.linuxtools-113a98ff02dafb4dd2699ca691b57c574a8adc3f.tar.gz
org.eclipse.linuxtools-113a98ff02dafb4dd2699ca691b57c574a8adc3f.tar.xz
org.eclipse.linuxtools-113a98ff02dafb4dd2699ca691b57c574a8adc3f.zip
Bug 534367 - have RunDockerImage Delegate attach an IProcess
- fix DockerConnection startContainer() methods to ignore error 304 which means the Container is already started - have RunConsole attachToTerminal check out stream for null before using to notify - change RunImageCommandHandler runCommand() to accept an ILaunch parameter and to create a ContainerCommandProcess to start the Container. If the ILaunch parameter is non-null, then wrap the ContainerCommandProcess with a RuntimeProcess which will be registered with the ILaunch - pass ILaunch to RunImageCommandHandler runImage() method from RunDockerImageLaunchConfigurationDelegate - modify ContainerCommandProcess constructor to take an extra OutputStream parameter to pass to the startContainer() call - in ContainerCommandProcess waitFor() method verify there are remoteVolumes before creating a CopyVolumesJob - fix bug in ContainerLauncher that tries to reference invalid char position when volume equals dir - when creating a new ContainerCommandProcess in ContainerLauncher, pass null OutputStream as extra parameter so startContainer() will use default console Change-Id: I2a07a529019a34dd32e65160cf74b4db5a3bfbce Reviewed-on: https://git.eclipse.org/r/122282 Tested-by: CI Bot Reviewed-by: Jeff Johnston <jjohnstn@redhat.com>
-rw-r--r--containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DockerConnection.java8
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/docker/ui/launch/ContainerLauncher.java6
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/commands/RunImageCommandHandler.java25
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/consoles/RunConsole.java8
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/launch/ContainerCommandProcess.java6
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/launch/RunDockerImageLaunchConfigurationDelegate.java1
6 files changed, 40 insertions, 14 deletions
diff --git a/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DockerConnection.java b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DockerConnection.java
index 8f074a4ece..c97494d470 100644
--- a/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DockerConnection.java
+++ b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DockerConnection.java
@@ -1750,7 +1750,9 @@ public class DockerConnection
throw new DockerException(DockerMessages.getFormattedString(
"DockerStartContainer.error", getCmdString(containerInfo))); //$NON-NLS-1$
} catch (com.spotify.docker.client.exceptions.DockerRequestException e) {
- throw new DockerException(e.message());
+ if (e.status() != 304) {
+ throw new DockerException(e.getMessage());
+ }
} catch (com.spotify.docker.client.exceptions.DockerException e) {
throw new DockerException(e.getMessage(), e.getCause());
}
@@ -1795,7 +1797,9 @@ public class DockerConnection
throw new DockerException(DockerMessages.getFormattedString(
"DockerStartContainer.error", getCmdString(containerInfo))); //$NON-NLS-1$
} catch (com.spotify.docker.client.exceptions.DockerRequestException e) {
- throw new DockerException(e.message());
+ if (e.status() != 304) {
+ throw new DockerException(e.getMessage());
+ }
} catch (com.spotify.docker.client.exceptions.DockerException e) {
throw new DockerException(e);
}
diff --git a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/docker/ui/launch/ContainerLauncher.java b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/docker/ui/launch/ContainerLauncher.java
index 06a5b14a7a..919ab15ca1 100644
--- a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/docker/ui/launch/ContainerLauncher.java
+++ b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/docker/ui/launch/ContainerLauncher.java
@@ -290,8 +290,9 @@ public class ContainerLauncher {
for (String volume : volumes) {
boolean excluded = false;
for (String dir : excludedDirs) {
- if (volume.startsWith(dir) && volume.charAt(
- dir.length()) == File.separatorChar) {
+ if (volume.equals(dir) || (volume.startsWith(dir)
+ && volume.charAt(dir
+ .length()) == File.separatorChar)) {
excluded = true;
break;
}
@@ -1696,6 +1697,7 @@ public class ContainerLauncher {
remoteDataVolumes.remove(readonly);
}
return new ContainerCommandProcess(connection, imageName, containerId,
+ null,
remoteDataVolumes,
keepContainer);
}
diff --git a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/commands/RunImageCommandHandler.java b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/commands/RunImageCommandHandler.java
index 56520df349..a129d2d4ea 100644
--- a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/commands/RunImageCommandHandler.java
+++ b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/commands/RunImageCommandHandler.java
@@ -13,6 +13,8 @@ package org.eclipse.linuxtools.internal.docker.ui.commands;
import static org.eclipse.linuxtools.internal.docker.ui.commands.CommandUtils.getRunConsole;
+import java.io.OutputStream;
+
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.runtime.CoreException;
@@ -21,6 +23,8 @@ import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.debug.core.ILaunch;
+import org.eclipse.debug.core.model.RuntimeProcess;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.linuxtools.docker.core.DockerContainerNotFoundException;
import org.eclipse.linuxtools.docker.core.DockerException;
@@ -33,6 +37,7 @@ import org.eclipse.linuxtools.docker.core.IDockerImage;
import org.eclipse.linuxtools.docker.ui.Activator;
import org.eclipse.linuxtools.internal.docker.core.DockerConnection;
import org.eclipse.linuxtools.internal.docker.ui.consoles.RunConsole;
+import org.eclipse.linuxtools.internal.docker.ui.launch.ContainerCommandProcess;
import org.eclipse.linuxtools.internal.docker.ui.launch.LaunchConfigurationUtils;
import org.eclipse.linuxtools.internal.docker.ui.views.DVMessages;
import org.eclipse.linuxtools.internal.docker.ui.wizards.ImageRun;
@@ -69,7 +74,7 @@ public class RunImageCommandHandler extends AbstractHandler {
.getDockerContainerConfig();
final IDockerHostConfig hostConfig = wizard
.getDockerHostConfig();
- runImage(selectedImage, containerConfig,
+ runImage(selectedImage, containerConfig, null,
hostConfig, wizard.getDockerContainerName(),
wizard.removeWhenExits());
}
@@ -91,6 +96,7 @@ public class RunImageCommandHandler extends AbstractHandler {
*/
public static void runImage(final IDockerImage image,
final IDockerContainerConfig containerConfig,
+ final ILaunch launch,
final IDockerHostConfig hostConfig, final String containerName,
final boolean removeWhenExits) {
final IDockerConnection connection = image.getConnection();
@@ -140,14 +146,21 @@ public class RunImageCommandHandler extends AbstractHandler {
startContainerMonitor.beginTask(DVMessages
.getString("RunImageStartingContainerTask.msg"), 1); //$NON-NLS-1$
console = getRunConsole(connection, container);
+ OutputStream outputStream = null;
if (console != null) {
// if we are auto-logging, show the console
console.showConsole();
- ((DockerConnection) connection).startContainer(
- containerId, console.getOutputStream());
- } else {
- ((DockerConnection) connection)
- .startContainer(containerId, null);
+ outputStream = console.getOutputStream();
+ }
+ // Start the Container and create a process we can wrap with
+ // a RuntimeProcess and set into the ILaunch
+ ContainerCommandProcess commandProcess = new ContainerCommandProcess(
+ connection, container.image(), containerId,
+ outputStream, null,
+ true);
+ if (launch != null) {
+ new RuntimeProcess(launch, commandProcess,
+ container.name(), null);
}
startContainerMonitor.done();
// create a launch configuration from the container
diff --git a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/consoles/RunConsole.java b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/consoles/RunConsole.java
index b9e2bdc3d6..b5d6ffe79f 100644
--- a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/consoles/RunConsole.java
+++ b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/consoles/RunConsole.java
@@ -198,13 +198,17 @@ public class RunConsole extends IOConsole {
} else {
// notify any console listener that there is no more output
// going to follow
- out.notifyConsoleListeners(new byte[] { 0 }, 0, 0);
+ if (out != null) {
+ 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);
+ if (out != null) {
+ out.notifyConsoleListeners(new byte[] { 0 }, 0, 0);
+ }
}
});
t.start();
diff --git a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/launch/ContainerCommandProcess.java b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/launch/ContainerCommandProcess.java
index fca3163677..d02194de61 100644
--- a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/launch/ContainerCommandProcess.java
+++ b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/launch/ContainerCommandProcess.java
@@ -60,6 +60,7 @@ public class ContainerCommandProcess extends Process {
public ContainerCommandProcess(IDockerConnection connection,
String imageName, String containerId,
+ OutputStream outputStream,
Map<String, String> remoteVolumes,
boolean keepContainer) {
this.connection = connection;
@@ -80,7 +81,7 @@ public class ContainerCommandProcess extends Process {
.getOperationToken()) {
pipedOut = pipedStdout;
pipedErr = pipedStderr;
- connection.startContainer(containerId, null);
+ connection.startContainer(containerId, outputStream);
threadStarted = true;
((DockerConnection) connection).attachLog(token, containerId,
pipedStdout, pipedStderr);
@@ -213,7 +214,8 @@ public class ContainerCommandProcess extends Process {
containerRemoved = true;
connection.removeContainer(containerId);
}
- if (!((DockerConnection) connection).isLocal()) {
+ if (!((DockerConnection) connection).isLocal()
+ && remoteVolumes != null && !remoteVolumes.isEmpty()) {
CopyVolumesFromImageJob job = new CopyVolumesFromImageJob(
connection, imageName, remoteVolumes);
job.schedule();
diff --git a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/launch/RunDockerImageLaunchConfigurationDelegate.java b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/launch/RunDockerImageLaunchConfigurationDelegate.java
index 2f0913b94a..bdeae5dd0f 100644
--- a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/launch/RunDockerImageLaunchConfigurationDelegate.java
+++ b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/launch/RunDockerImageLaunchConfigurationDelegate.java
@@ -65,6 +65,7 @@ public class RunDockerImageLaunchConfigurationDelegate
final IDockerImage image = getDockerImage(config, connection);
RunImageCommandHandler.runImage(image,
containerConfig,
+ launch,
hostConfig,
config.getAttribute(
IRunDockerImageLaunchConfigurationConstants.CONTAINER_NAME,

Back to the top