Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorXavier Coulon2015-12-01 13:39:19 +0000
committerJeff Johnston2015-12-01 22:13:04 +0000
commitf2ae1586a47ff9a00081860773503b5ec9fa97d0 (patch)
treef5a4fa8b6588316d233fddf8a13cb442bd1e7af9 /containers/org.eclipse.linuxtools.docker.core/src/org/eclipse
parentd8bb903edd7d75d61e3055f3dfd6760607623bc7 (diff)
downloadorg.eclipse.linuxtools-f2ae1586a47ff9a00081860773503b5ec9fa97d0.tar.gz
org.eclipse.linuxtools-f2ae1586a47ff9a00081860773503b5ec9fa97d0.tar.xz
org.eclipse.linuxtools-f2ae1586a47ff9a00081860773503b5ec9fa97d0.zip
Bug 480401 - Create a launch configuration when running an image from wizard
Creating a LaunchConfiguration when the container starts, adding a creation_date attribute to be able to find the latest launch config for a given image name, when the user selects the image again to run another container. Protecting the domain class initialization by checking that retrieved info from the client are not null. Retrieving last launch configuration for the selected image name to prefill the wizard (some refactoring was required to pass the last launch configuration and fill the page models) Added SWTBot tests Change-Id: If24e0c1b7f7aea838f86a3c37fec42ae2bfe03f7 Signed-off-by: Xavier Coulon <xcoulon@redhat.com> Reviewed-on: https://git.eclipse.org/r/61494 Tested-by: Hudson CI Reviewed-by: Jeff Johnston <jjohnstn@redhat.com> (cherry picked from commit 6c859255f4bca47dfc8ace839ba28d07a9a2cc37) Reviewed-on: https://git.eclipse.org/r/61698
Diffstat (limited to 'containers/org.eclipse.linuxtools.docker.core/src/org/eclipse')
-rw-r--r--containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DockerConnection.java70
-rw-r--r--containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DockerContainerConfig.java56
-rw-r--r--containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DockerContainerInfo.java14
3 files changed, 83 insertions, 57 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 6212ce1904..226e07fae3 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
@@ -11,11 +11,9 @@
package org.eclipse.linuxtools.internal.docker.core;
import java.io.Closeable;
-import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
-import java.net.URI;
import java.nio.ByteBuffer;
import java.nio.channels.WritableByteChannel;
import java.nio.file.FileSystems;
@@ -68,9 +66,7 @@ import org.eclipse.tm.terminal.view.core.interfaces.ITerminalService;
import org.eclipse.tm.terminal.view.core.interfaces.constants.ITerminalsConnectorConstants;
import com.spotify.docker.client.ContainerNotFoundException;
-import com.spotify.docker.client.DefaultDockerClient;
import com.spotify.docker.client.DockerCertificateException;
-import com.spotify.docker.client.DockerCertificates;
import com.spotify.docker.client.DockerClient;
import com.spotify.docker.client.DockerClient.AttachParameter;
import com.spotify.docker.client.DockerClient.BuildParameter;
@@ -352,28 +348,13 @@ public class DockerConnection implements IDockerConnection, Closeable {
* @see DockerConnection#open(boolean)
*/
private DockerClient getClientCopy() throws DockerException {
- if (this.socketPath != null) {
- return DefaultDockerClient.builder().uri(socketPath).build();
- } else if (this.tcpHost != null) {
- if (this.tcpCertPath != null) {
- try {
- return DefaultDockerClient
- .builder()
- .uri(URI.create(tcpHost))
- .dockerCertificates(
- new DockerCertificates(
- new File(tcpCertPath).toPath()))
- .build();
- } catch (DockerCertificateException e) {
- throw new DockerException(Messages.Retrieve_Docker_Certificates_Failure, e);
- }
- } else {
- return DefaultDockerClient.builder().uri(URI.create(tcpHost))
- .build();
- }
+ try {
+ return dockerClientFactory.getClient(this.socketPath, this.tcpHost,
+ this.tcpCertPath);
+ } catch (DockerCertificateException e) {
+ throw new DockerException(
+ NLS.bind(Messages.Open_Connection_Failure, this.name));
}
- throw new DockerException(Messages.Missing_Settings);
-
}
public void notifyContainerListeners(List<IDockerContainer> list) {
@@ -639,6 +620,23 @@ public class DockerConnection implements IDockerConnection, Closeable {
return getImages(false);
}
+ /**
+ * @return the {@link IDockerImage} identified by the given {@code id} or
+ * <code>null</code> if none was found.
+ * @param id
+ * the {@link IDockerImage} id
+ */
+ // TODO: declare the method in the interface to make it part of the API.
+ public IDockerImage getImage(String id) {
+ List<IDockerImage> images = getImages();
+ for (IDockerImage image : images) {
+ if (image.id().equals(id)) {
+ return image;
+ }
+ }
+ return null;
+ }
+
@Override
public List<IDockerImage> getImages(final boolean force) {
List<IDockerImage> latestImages;
@@ -1020,12 +1018,13 @@ public class DockerConnection implements IDockerConnection, Closeable {
builder = builder.onBuild(c.onBuild());
}
- // create container with default random name
+ // create container with default random name if an empty/null
+ // containerName argument was passed
final ContainerCreation creation = client
.createContainer(builder.build(),
- containerName);
-
- final String id = creation != null ? creation.id() : null;
+ (containerName != null && !containerName.isEmpty())
+ ? containerName : null);
+ final String id = creation.id();
// force a refresh of the current containers to include the new one
listContainers();
return id;
@@ -1172,7 +1171,10 @@ public class DockerConnection implements IDockerConnection, Closeable {
// start container
client.startContainer(id);
// Log the started container if a stream is provided
- if (stream != null && !getContainerInfo(id).config().tty()) {
+ 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);
@@ -1268,6 +1270,14 @@ public class DockerConnection implements IDockerConnection, Closeable {
if (t != null)
t.requestStop();
}
+ while (loggingStatus(id) == EnumDockerLoggingStatus.LOGGING_ACTIVE) {
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException e) {
+ Activator.log(e);
+ }
+ }
+
}
@Override
diff --git a/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DockerContainerConfig.java b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DockerContainerConfig.java
index f87481812a..caa4d39378 100644
--- a/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DockerContainerConfig.java
+++ b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DockerContainerConfig.java
@@ -49,37 +49,53 @@ public class DockerContainerConfig implements IDockerContainerConfig {
private final List<String> onBuild;
public DockerContainerConfig(final ContainerConfig containerConfig) {
- HostConfig hc = containerConfig.hostConfig();
- this.hostname = containerConfig.hostname();
- this.domainname = containerConfig.domainname();
- this.user = containerConfig.user();
+ this.hostname = containerConfig != null ? containerConfig.hostname()
+ : null;
+ this.domainname = containerConfig != null ? containerConfig.domainname()
+ : null;
+ this.user = containerConfig != null ? containerConfig.user() : null;
+ final HostConfig hc = containerConfig != null
+ ? containerConfig.hostConfig() : null;
this.memory = hc != null ? hc.memory() : null;
this.memorySwap = hc != null ? hc.memorySwap() : null;
this.cpuShares = hc != null ? hc.cpuShares() : null;
this.cpuset = hc != null ? hc.cpusetCpus() : null;
- this.attachStdin = containerConfig.attachStdin() != null
+ this.attachStdin = containerConfig != null
+ && containerConfig.attachStdin() != null
? containerConfig.attachStdin() : false;
- this.attachStdout = containerConfig.attachStdout() != null
+ this.attachStdout = containerConfig != null
+ && containerConfig.attachStdout() != null
? containerConfig.attachStdout() : false;
- this.attachStderr = containerConfig.attachStderr() != null
+ this.attachStderr = containerConfig != null
+ && containerConfig.attachStderr() != null
? containerConfig.attachStderr() : false;
- this.portSpecs = containerConfig.portSpecs();
- this.exposedPorts = containerConfig.exposedPorts();
- this.tty = containerConfig.tty() != null ? containerConfig.tty()
+ this.portSpecs = containerConfig != null ? containerConfig.portSpecs()
+ : null;
+ this.exposedPorts = containerConfig != null
+ ? containerConfig.exposedPorts() : null;
+ this.tty = containerConfig != null && containerConfig.tty() != null
+ ? containerConfig.tty()
: false;
- this.openStdin = containerConfig.openStdin() != null
+ this.openStdin = containerConfig != null
+ && containerConfig.openStdin() != null
? containerConfig.openStdin() : false;
- this.stdinOnce = containerConfig.stdinOnce() != null
+ this.stdinOnce = containerConfig != null
+ && containerConfig.stdinOnce() != null
? containerConfig.stdinOnce() : false;
- this.env = containerConfig.env();
- this.cmd = containerConfig.cmd();
- this.image = containerConfig.image();
- this.volumes = containerConfig.volumes();
- this.workingDir = containerConfig.workingDir();
- this.entrypoint = containerConfig.entrypoint();
- this.networkDisabled = containerConfig.networkDisabled() != null
+ this.env = containerConfig != null ? containerConfig.env() : null;
+ this.cmd = containerConfig != null ? containerConfig.cmd() : null;
+ this.image = containerConfig != null ? containerConfig.image() : null;
+ this.volumes = containerConfig != null ? containerConfig.volumes()
+ : null;
+ this.workingDir = containerConfig != null ? containerConfig.workingDir()
+ : null;
+ this.entrypoint = containerConfig != null ? containerConfig.entrypoint()
+ : null;
+ this.networkDisabled = containerConfig != null
+ && containerConfig.networkDisabled() != null
? containerConfig.networkDisabled() : false;
- this.onBuild = containerConfig.onBuild();
+ this.onBuild = containerConfig != null ? containerConfig.onBuild()
+ : null;
}
private DockerContainerConfig(final Builder builder) {
diff --git a/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DockerContainerInfo.java b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DockerContainerInfo.java
index f40f68cbe9..54b2822d96 100644
--- a/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DockerContainerInfo.java
+++ b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DockerContainerInfo.java
@@ -49,14 +49,14 @@ public class DockerContainerInfo implements IDockerContainerInfo {
this.created = info != null ? info.created() : null;
this.path = info != null ? info.path() : null;
this.args = info != null ? info.args() : null;
- this.config = info != null ? new DockerContainerConfig(info.config())
- : null;
- this.hostConfig = info != null ? new DockerHostConfig(info.hostConfig())
- : null;
- this.state = info != null ? new DockerContainerState(info.state())
- : null;
+ this.config = info != null && info.config() != null
+ ? new DockerContainerConfig(info.config()) : null;
+ this.hostConfig = info != null && info.hostConfig() != null
+ ? new DockerHostConfig(info.hostConfig()) : null;
+ this.state = info != null && info.state() != null
+ ? new DockerContainerState(info.state()) : null;
this.image = info != null ? info.image() : null;
- this.networkSettings = info != null
+ this.networkSettings = info != null && info.networkSettings() != null
? new DockerNetworkSettings(info.networkSettings()) : null;
this.resolvConfPath = info != null ? info.resolvConfPath() : null;
this.hostnamePath = info != null ? info.hostnamePath() : null;

Back to the top