diff options
author | Xavier Coulon | 2015-05-26 17:03:51 +0000 |
---|---|---|
committer | Roland Grunberg | 2015-06-02 20:57:50 +0000 |
commit | 7ed517266b9db13e2ccd5f1c62eb7a367dcdaec9 (patch) | |
tree | a7f061e4bd734778003cbdbaff44bb9af52f7cd5 /containers/org.eclipse.linuxtools.docker.core/src/org/eclipse | |
parent | b06f083ba67b1c957732df6e9034637994f076f4 (diff) | |
download | org.eclipse.linuxtools-7ed517266b9db13e2ccd5f1c62eb7a367dcdaec9.tar.gz org.eclipse.linuxtools-7ed517266b9db13e2ccd5f1c62eb7a367dcdaec9.tar.xz org.eclipse.linuxtools-7ed517266b9db13e2ccd5f1c62eb7a367dcdaec9.zip |
Bug 468607 - Refactor the wizard to run a container
Change-Id: Ie41be59b3326e9521833f25c3fe91ac565adf6d5
Signed-off-by: Xavier Coulon <xcoulon@redhat.com>
Reviewed-on: https://git.eclipse.org/r/48939
Tested-by: Hudson CI
Reviewed-by: Roland Grunberg <rgrunber@redhat.com>
Tested-by: Roland Grunberg <rgrunber@redhat.com>
Diffstat (limited to 'containers/org.eclipse.linuxtools.docker.core/src/org/eclipse')
11 files changed, 440 insertions, 131 deletions
diff --git a/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/IDockerConnection.java b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/IDockerConnection.java index 1ec98f1c3e..bf49dc092a 100644 --- a/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/IDockerConnection.java +++ b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/IDockerConnection.java @@ -150,8 +150,20 @@ public interface IDockerConnection { */ public IDockerConnectionInfo getInfo() throws DockerException; + /** + * Retrieves/refreshes the {@link IDockerImage} on the Docker daemon and + * applies 'dangling' and 'intermediate' flags on each of them. Also + * notifies {@link IDockerConnection} listeners with the list of Images. + * + * @return the {@link List} of existing {@link IDockerImage} + * @throws DockerException + */ + public List<IDockerImage> listImages() throws DockerException; + void pullImage(String id, IDockerProgressHandler handler) throws DockerException, InterruptedException; + public List<IDockerImageSearchResult> searchImages(final String term) throws DockerException; + void pushImage(String name, IDockerProgressHandler handler) throws DockerException, InterruptedException; void tagImage(String name, String newTag) throws DockerException, InterruptedException; @@ -159,7 +171,12 @@ public interface IDockerConnection { String buildImage(IPath path, String name, IDockerProgressHandler handler) throws DockerException, InterruptedException; - String createContainer(IDockerContainerConfig c) throws DockerException, InterruptedException; + String createContainer(IDockerContainerConfig c) + throws DockerException, InterruptedException; + + public String createContainer(final IDockerContainerConfig config, + final String containerName) + throws DockerException, InterruptedException; void stopContainer(String id) throws DockerException, InterruptedException; @@ -167,26 +184,34 @@ public interface IDockerConnection { void pauseContainer(String id) throws DockerException, InterruptedException; - void unpauseContainer(String id, OutputStream stream) throws DockerException, InterruptedException; + void unpauseContainer(String id, OutputStream stream) + throws DockerException, InterruptedException; - void removeContainer(String id) throws DockerException, InterruptedException; + void removeContainer(String id) + throws DockerException, InterruptedException; - void startContainer(String id, OutputStream stream) throws DockerException, InterruptedException; + void startContainer(String id, OutputStream stream) + throws DockerException, InterruptedException; - void startContainer(String id, IDockerHostConfig config, OutputStream stream) + void startContainer(String id, IDockerHostConfig config, + OutputStream stream) throws DockerException, InterruptedException; - void startContainer(String id, String loggingId, IDockerHostConfig config, OutputStream stream) + void startContainer(String id, String loggingId, IDockerHostConfig config, + OutputStream stream) throws DockerException, InterruptedException; - void commitContainer(String id, String repo, String tag, String comment, String author) throws DockerException; + void commitContainer(String id, String repo, String tag, String comment, + String author) throws DockerException; void stopLoggingThread(String id); - void logContainer(String id, OutputStream stream) throws DockerException, InterruptedException; + void logContainer(String id, OutputStream stream) + throws DockerException, InterruptedException; void removeImage(String name) throws DockerException, InterruptedException; void removeTag(String tag) throws DockerException, InterruptedException; + } diff --git a/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/IDockerContainer.java b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/IDockerContainer.java index fd5cb04009..89573f3836 100644 --- a/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/IDockerContainer.java +++ b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/IDockerContainer.java @@ -48,5 +48,12 @@ public interface IDockerContainer { */ public IDockerConnection getConnection(); + /** + * @return the {@link IDockerContainerInfo} by calling the Docker daemon + * using the {@link IDockerConnection} associated with this + * {@link IDockerContainer}. + */ + public IDockerContainerInfo info(); + } diff --git a/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/IDockerContainerConfig.java b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/IDockerContainerConfig.java index e72a074e82..f4791e1a45 100644 --- a/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/IDockerContainerConfig.java +++ b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/IDockerContainerConfig.java @@ -29,21 +29,21 @@ public interface IDockerContainerConfig { public String cpuset(); - public Boolean attachStdin(); + public boolean attachStdin(); - public Boolean attachStdout(); + public boolean attachStdout(); - public Boolean attachStderr(); + public boolean attachStderr(); public List<String> portSpecs(); public Set<String> exposedPorts(); - public Boolean tty(); + public boolean tty(); - public Boolean openStdin(); + public boolean openStdin(); - public Boolean stdinOnce(); + public boolean stdinOnce(); public List<String> env(); @@ -57,7 +57,7 @@ public interface IDockerContainerConfig { public List<String> entrypoint(); - public Boolean networkDisabled(); + public boolean networkDisabled(); public List<String> onBuild(); diff --git a/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/IDockerHostConfig.java b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/IDockerHostConfig.java index 5a976b95b8..9652787229 100644 --- a/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/IDockerHostConfig.java +++ b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/IDockerHostConfig.java @@ -21,13 +21,13 @@ public interface IDockerHostConfig { public List<IDockerConfParameter> lxcConf(); - public Boolean privileged(); + public boolean privileged(); public Map<String, List<IDockerPortBinding>> portBindings(); public List<String> links(); - public Boolean publishAllPorts(); + public boolean publishAllPorts(); public List<String> dns(); diff --git a/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/IDockerImageSearchResult.java b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/IDockerImageSearchResult.java new file mode 100644 index 0000000000..bfd44454ae --- /dev/null +++ b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/IDockerImageSearchResult.java @@ -0,0 +1,30 @@ +package org.eclipse.linuxtools.docker.core; + +public interface IDockerImageSearchResult { + + /** + * @return the image description + */ + String getDescription(); + + /** + * @return the official image flag + */ + boolean isOfficial(); + + /** + * @return the automated build flag + */ + boolean isAutomated(); + + /** + * @return the image name + */ + String getName(); + + /** + * @return the star count + */ + int getStarCount(); + +}
\ No newline at end of file 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 bb54ba1597..e6b090d954 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 @@ -68,8 +68,8 @@ import org.eclipse.linuxtools.docker.core.IDockerHostConfig; import org.eclipse.linuxtools.docker.core.IDockerImage; import org.eclipse.linuxtools.docker.core.IDockerImageInfo; import org.eclipse.linuxtools.docker.core.IDockerImageListener; +import org.eclipse.linuxtools.docker.core.IDockerImageSearchResult; import org.eclipse.linuxtools.docker.core.IDockerPortBinding; -import org.eclipse.linuxtools.docker.core.IDockerPortMapping; import org.eclipse.linuxtools.docker.core.IDockerProgressHandler; import org.eclipse.linuxtools.docker.core.ILogger; import org.eclipse.linuxtools.docker.core.Messages; @@ -93,6 +93,7 @@ import com.spotify.docker.client.messages.HostConfig; import com.spotify.docker.client.messages.HostConfig.LxcConfParameter; import com.spotify.docker.client.messages.Image; import com.spotify.docker.client.messages.ImageInfo; +import com.spotify.docker.client.messages.ImageSearchResult; import com.spotify.docker.client.messages.Info; import com.spotify.docker.client.messages.PortBinding; import com.spotify.docker.client.messages.Version; @@ -241,7 +242,8 @@ public class DockerConnection implements IDockerConnection { // log what happened if the process did not end as expected final InputStream processErrorStream = process .getErrorStream(); - final String errorMessage = streamToString(processErrorStream); + final String errorMessage = streamToString( + processErrorStream); Activator.log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, errorMessage)); } @@ -324,8 +326,8 @@ public class DockerConnection implements IDockerConnection { } private String streamToString(InputStream stream) { - BufferedReader buff = new BufferedReader(new InputStreamReader( - stream)); + BufferedReader buff = new BufferedReader( + new InputStreamReader(stream)); StringBuffer res = new StringBuffer(); String line = ""; try { @@ -425,7 +427,7 @@ public class DockerConnection implements IDockerConnection { public Builder tcpCertPath(final String tcpCertPath) { this.tcpCertPath = tcpCertPath; - if (tcpCertPath != null) { + if (this.tcpHost != null) { this.tcpHost = tcpHost.replace("http://", "https://"); } return this; @@ -555,7 +557,7 @@ public class DockerConnection implements IDockerConnection { addContainerListener(dcrm); } } - } catch (Exception e) { + } catch (DockerCertificateException e) { throw new DockerException(Messages.Open_Connection_Failure, e); } } @@ -656,8 +658,7 @@ public class DockerConnection implements IDockerConnection { } - public void notifyContainerListeners(DockerConnection manager, - List<IDockerContainer> list) { + public void notifyContainerListeners(List<IDockerContainer> list) { if (containerListeners != null) { Object[] listeners = containerListeners.getListeners(); for (int i = 0; i < listeners.length; ++i) { @@ -822,12 +823,6 @@ public class DockerConnection implements IDockerConnection { // core format in case we decide to change the underlying engine // in the future. for (Container c : list) { - final List<Container.PortMapping> ports = c.ports(); - final List<IDockerPortMapping> portMappings = new ArrayList<>(); - for (Container.PortMapping port : ports) { - final DockerPortMapping portMapping = new DockerPortMapping(port.getPrivatePort(), port.getPublicPort(), port.getType(), port.getIp()); - portMappings.add(portMapping); - } // For containers that have exited, make sure we aren't tracking // them with a logging thread. if (c.status().startsWith(Messages.Exited_specifier)) { @@ -836,15 +831,13 @@ public class DockerConnection implements IDockerConnection { loggingThreads.remove(c.id()); } } - dclist.add(new DockerContainer(this, c.id(), c.image(), c - .command(), c.created(), c.status(), c.sizeRw(), c - .sizeRootFs(), portMappings, c.names())); + dclist.add(new DockerContainer(this, c)); } containers = dclist; } // perform notification outside of containerLock so we don't have a View // causing a deadlock - notifyContainerListeners(this, dclist); + notifyContainerListeners(dclist); return dclist; } @@ -903,8 +896,7 @@ public class DockerConnection implements IDockerConnection { imageListeners.remove(listener); } - public void notifyImageListeners(DockerConnection manager, - List<IDockerImage> list) { + public void notifyImageListeners(List<IDockerImage> list) { if (imageListeners != null) { Object[] listeners = imageListeners.getListeners(); for (int i = 0; i < listeners.length; ++i) { @@ -944,7 +936,8 @@ public class DockerConnection implements IDockerConnection { return imagesLoaded; } - private List<IDockerImage> listImages() throws DockerException { + @Override + public List<IDockerImage> listImages() throws DockerException { final List<IDockerImage> dilist = new ArrayList<>(); synchronized (imageLock) { List<Image> rawImages = null; @@ -972,17 +965,24 @@ public class DockerConnection implements IDockerConnection { && imageParentIds.contains(rawImage.id()); final boolean danglingImage = !taggedImage && !intermediateImage; - dilist.add(new DockerImage(this, rawImage - .repoTags(), rawImage.id(), rawImage.parentId(), - rawImage.created(), rawImage.size(), rawImage - .virtualSize(), intermediateImage, - danglingImage)); + // FIXME: if an image with a unique ID belongs to multiple repos, we should + // probably have multiple instances of IDockerImage + final Map<String, List<String>> repoTags = DockerImage.extractTagsByRepo(rawImage.repoTags()); + for(Entry<String, List<String>> entry : repoTags.entrySet()) { + final String repo = entry.getKey(); + final List<String> tags = entry.getValue(); + dilist.add(new DockerImage(this, rawImage + .repoTags(), repo, tags, rawImage.id(), rawImage.parentId(), + rawImage.created(), rawImage.size(), rawImage + .virtualSize(), intermediateImage, + danglingImage)); + } } images = dilist; } // Perform notification outside of lock so that listener doesn't cause a // deadlock to occur - notifyImageListeners(this, dilist); + notifyImageListeners(dilist); return dilist; } @@ -999,6 +999,22 @@ public class DockerConnection implements IDockerConnection { throw f; } } + + @Override + public List<IDockerImageSearchResult> searchImages(final String term) throws DockerException { + try { + final List<ImageSearchResult> searchResults = client.searchImages(term); + final List<IDockerImageSearchResult> results = new ArrayList<>(); + for(ImageSearchResult r : searchResults) { + results.add(new DockerImageSearchResult(r.getDescription(), r.isOfficial(), r.isAutomated(), r.getName(), r.getStarCount())); + } + return results; + } catch (com.spotify.docker.client.DockerException | InterruptedException e) { + throw new DockerException(e); + } + } + + @Override public void pushImage(final String name, final IDockerProgressHandler handler) @@ -1075,41 +1091,59 @@ public class DockerConnection implements IDockerConnection { DockerConnectionManager.getInstance().saveConnections(); } + @Override public String createContainer(final IDockerContainerConfig c) throws DockerException, InterruptedException { + return createContainer(c, null); + } + + @Override + public String createContainer(final IDockerContainerConfig c, + final String containerName) + throws DockerException, InterruptedException { ContainerConfig.Builder builder = ContainerConfig.builder() .hostname(c.hostname()).domainname(c.domainname()) - .user(c.user()).memory(c.memory()).memorySwap(c.memorySwap()) - .cpuShares(c.cpuShares()).cpuset(c.cpuset()) - .attachStdin(c.attachStdin()).attachStdout(c.attachStdout()) + .user(c.user()).memory(c.memory()) + .memorySwap(c.memorySwap()).cpuShares(c.cpuShares()) + .cpuset(c.cpuset()).attachStdin(c.attachStdin()) + .attachStdout(c.attachStdout()) .attachStderr(c.attachStderr()).tty(c.tty()) - .openStdin(c.openStdin()).stdinOnce(c.stdinOnce()).cmd(c.cmd()) - .image(c.image()).workingDir(c.workingDir()) + .openStdin(c.openStdin()).stdinOnce(c.stdinOnce()) + .cmd(c.cmd()).image(c.image()) + .workingDir(c.workingDir()) .networkDisabled(c.networkDisabled()); // For those fields that are Collections and not set, they will be null. // We can't use their values to set the builder's fields as they are // expecting non-null Collections to copy over. In those cases, we just // don't set those fields in the builder. - if (c.portSpecs() != null) + if (c.portSpecs() != null) { builder = builder.portSpecs(c.portSpecs()); - if (c.exposedPorts() != null) + } + if (c.exposedPorts() != null) { builder = builder.exposedPorts(c.exposedPorts()); - if (c.env() != null) + } + if (c.env() != null) { builder = builder.env(c.env()); - if (c.volumes() != null) + } + if (c.volumes() != null) { builder = builder.volumes(c.volumes()); - if (c.entrypoint() != null) + } + if (c.entrypoint() != null) { builder = builder.entrypoint(c.entrypoint()); - if (c.onBuild() != null) + } + if (c.onBuild() != null) { builder = builder.onBuild(c.onBuild()); - - final ContainerConfig config = builder.build(); + } try { // create container with default random name - final ContainerCreation creation = client.createContainer(config); + final ContainerCreation creation = client + .createContainer(builder.build(), + containerName); final String id = creation.id(); + // force a refresh of the current containers to include the new one + listContainers(); return id; } catch (com.spotify.docker.client.DockerRequestException e) { throw new DockerException(e.message()); @@ -1132,7 +1166,7 @@ public class DockerConnection implements IDockerConnection { } } // list of containers needs to be updated once the given container is stopped, to reflect it new state. - listContainers(); + listContainers(); } catch (ContainerNotFoundException e) { throw new DockerContainerNotFoundException(e); } catch (com.spotify.docker.client.DockerRequestException e) { @@ -1316,13 +1350,14 @@ public class DockerConnection implements IDockerConnection { // start container with host config client.startContainer(id, builder.build()); // Log the started container based on user preference + // Log the started container based on user preference + // Log the started container based on user preference IEclipsePreferences preferences = InstanceScope.INSTANCE .getNode("org.eclipse.linuxtools.docker.ui"); //$NON-NLS-1$ boolean autoLog = preferences.getBoolean("autoLogOnStart", true); //$NON-NLS-1$ if (autoLog && !getContainerInfo(id).config().tty()) { - // display logs for container synchronized (loggingThreads) { LogThread t = loggingThreads.get(loggingId); if (t == null || !t.isAlive()) { @@ -1353,6 +1388,7 @@ public class DockerConnection implements IDockerConnection { client.commitContainer(id, repo, tag, info.config(), comment, author); // update images list + listImages(); getImages(true); } catch (com.spotify.docker.client.DockerRequestException e) { throw new DockerException(e.message()); diff --git a/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DockerContainer.java b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DockerContainer.java index 9a4d0cf814..ef5c42f871 100644 --- a/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DockerContainer.java +++ b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DockerContainer.java @@ -13,12 +13,16 @@ package org.eclipse.linuxtools.internal.docker.core; import java.util.ArrayList; import java.util.List; +import org.eclipse.linuxtools.docker.core.IDockerConnection; import org.eclipse.linuxtools.docker.core.IDockerContainer; +import org.eclipse.linuxtools.docker.core.IDockerContainerInfo; import org.eclipse.linuxtools.docker.core.IDockerPortMapping; +import com.spotify.docker.client.messages.Container; + public class DockerContainer implements IDockerContainer { - private DockerConnection parent; + private IDockerConnection parent; private String id; private List<String> names; private String image; @@ -29,30 +33,36 @@ public class DockerContainer implements IDockerContainer { private Long sizeRw; private Long sizeRootFs; - public DockerContainer(DockerConnection parent, String id, String image, - String command, Long created, String status, Long sizeRw, - Long sizeRootFs, List<IDockerPortMapping> ports, List<String> names) { - this.parent = parent; - this.id = id; - this.image = image; - this.command = command; - this.created = created; - this.status = status; + public DockerContainer(final IDockerConnection connection, + Container container) { + this.parent = connection; + this.id = container.id(); + this.image = container.image(); + this.command = container.command(); + this.created = container.created(); + this.status = container.status(); this.names = new ArrayList<>(); - for(String name : names) { - if(name.startsWith("/")) { + for (String name : container.names()) { + if (name.startsWith("/")) { this.names.add(name.substring(1)); } else { this.names.add(name); } } - this.sizeRw = sizeRw; - this.sizeRootFs = sizeRootFs; - this.ports = ports; + this.sizeRw = container.sizeRw(); + this.sizeRootFs = container.sizeRootFs(); + this.ports = new ArrayList<>(); + for (Container.PortMapping port : container.ports()) { + final DockerPortMapping portMapping = new DockerPortMapping( + port.getPrivatePort(), port.getPublicPort(), port.getType(), + port.getIp()); + ports.add(portMapping); + } + // TODO: include volumes } @Override - public DockerConnection getConnection() { + public IDockerConnection getConnection() { return parent; } @@ -107,6 +117,11 @@ public class DockerContainer implements IDockerContainer { } @Override + public IDockerContainerInfo info() { + return this.parent.getContainerInfo(id); + } + + @Override public String toString() { return "Container: id=" + id() + "\n" + " image=" + image() + "\n" + " created=" + created() + "\n" + " command=" + command() 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 0cbfb6fe7d..9e40a431b1 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 @@ -12,6 +12,7 @@ package org.eclipse.linuxtools.internal.docker.core; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.List; import java.util.Set; import java.util.TreeSet; @@ -29,21 +30,21 @@ public class DockerContainerConfig implements IDockerContainerConfig { private final Long memorySwap; private final Long cpuShares; private final String cpuset; - private final Boolean attachStdin; - private final Boolean attachStdout; - private final Boolean attachStderr; + private final boolean attachStdin; + private final boolean attachStdout; + private final boolean attachStderr; private final List<String> portSpecs; private final Set<String> exposedPorts; - private final Boolean tty; - private final Boolean openStdin; - private final Boolean stdinOnce; + private final boolean tty; + private final boolean openStdin; + private final boolean stdinOnce; private final List<String> env; private final List<String> cmd; private final String image; private final Set<String> volumes; private final String workingDir; private final List<String> entrypoint; - private final Boolean networkDisabled; + private final boolean networkDisabled; private final List<String> onBuild; public DockerContainerConfig(final ContainerConfig containerConfig) { @@ -54,21 +55,28 @@ public class DockerContainerConfig implements IDockerContainerConfig { this.memorySwap = containerConfig.memorySwap(); this.cpuShares = containerConfig.cpuShares(); this.cpuset = containerConfig.cpuset(); - this.attachStdin = containerConfig.attachStdin(); - this.attachStdout = containerConfig.attachStdout(); - this.attachStderr = containerConfig.attachStderr(); + this.attachStdin = containerConfig.attachStdin() != null + ? containerConfig.attachStdin() : false; + this.attachStdout = containerConfig.attachStdout() != null + ? containerConfig.attachStdout() : false; + this.attachStderr = containerConfig.attachStderr() != null + ? containerConfig.attachStderr() : false; this.portSpecs = containerConfig.portSpecs(); this.exposedPorts = containerConfig.exposedPorts(); - this.tty = containerConfig.tty(); - this.openStdin = containerConfig.openStdin(); - this.stdinOnce = containerConfig.stdinOnce(); + this.tty = containerConfig.tty() != null ? containerConfig.tty() + : false; + this.openStdin = containerConfig.openStdin() != null + ? containerConfig.openStdin() : false; + this.stdinOnce = 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(); + this.networkDisabled = containerConfig.networkDisabled() != null + ? containerConfig.networkDisabled() : false; this.onBuild = containerConfig.onBuild(); } @@ -80,21 +88,25 @@ public class DockerContainerConfig implements IDockerContainerConfig { this.memorySwap = builder.memorySwap; this.cpuShares = builder.cpuShares; this.cpuset = builder.cpuset; - this.attachStdin = builder.attachStdin; - this.attachStdout = builder.attachStdout; - this.attachStderr = builder.attachStderr; + this.attachStdin = builder.attachStdin != null ? builder.attachStdin + : false; + this.attachStdout = builder.attachStdout != null ? builder.attachStdout + : false; + this.attachStderr = builder.attachStderr != null ? builder.attachStderr + : false; this.portSpecs = builder.portSpecs; this.exposedPorts = builder.exposedPorts; - this.tty = builder.tty; - this.openStdin = builder.openStdin; - this.stdinOnce = builder.stdinOnce; + this.tty = builder.tty != null ? builder.tty : false; + this.openStdin = builder.openStdin != null ? builder.openStdin : false; + this.stdinOnce = builder.stdinOnce != null ? builder.stdinOnce : false; this.env = builder.env; this.cmd = builder.cmd; this.image = builder.image; this.volumes = builder.volumes; this.workingDir = builder.workingDir; this.entrypoint = builder.entrypoint; - this.networkDisabled = builder.networkDisabled; + this.networkDisabled = builder.networkDisabled != null + ? builder.networkDisabled : false; this.onBuild = builder.onBuild; } @@ -134,52 +146,64 @@ public class DockerContainerConfig implements IDockerContainerConfig { } @Override - public Boolean attachStdin() { + public boolean attachStdin() { return attachStdin; } @Override - public Boolean attachStdout() { + public boolean attachStdout() { return attachStdout; } @Override - public Boolean attachStderr() { + public boolean attachStderr() { return attachStderr; } @Override public List<String> portSpecs() { + if (portSpecs == null) { + return Collections.emptyList(); + } return portSpecs; } @Override public Set<String> exposedPorts() { + if (exposedPorts == null) { + return Collections.emptySet(); + } return exposedPorts; } @Override - public Boolean tty() { + public boolean tty() { return tty; } @Override - public Boolean openStdin() { + public boolean openStdin() { return openStdin; } @Override - public Boolean stdinOnce() { + public boolean stdinOnce() { return stdinOnce; } @Override public List<String> env() { + if (env == null) { + return Collections.emptyList(); + } return env; } @Override public List<String> cmd() { + if (cmd == null) { + return Collections.emptyList(); + } return cmd; } @@ -190,6 +214,9 @@ public class DockerContainerConfig implements IDockerContainerConfig { @Override public Set<String> volumes() { + if (volumes == null) { + return Collections.emptySet(); + } return volumes; } @@ -200,16 +227,22 @@ public class DockerContainerConfig implements IDockerContainerConfig { @Override public List<String> entrypoint() { + if (entrypoint == null) { + return Collections.emptyList(); + } return entrypoint; } @Override - public Boolean networkDisabled() { + public boolean networkDisabled() { return networkDisabled; } @Override public List<String> onBuild() { + if (onBuild == null) { + return Collections.emptyList(); + } return onBuild; } @@ -330,7 +363,6 @@ public class DockerContainerConfig implements IDockerContainerConfig { } public Builder portSpecs(final List<String> portSpecs) { - this.portSpecs = new ArrayList<>(portSpecs); return this; } @@ -400,12 +432,18 @@ public class DockerContainerConfig implements IDockerContainerConfig { } public Builder cmd(final List<String> cmd) { - this.cmd = new ArrayList<>(cmd); + this.cmd = cmd; return this; } public Builder cmd(final String... cmd) { - this.cmd = Arrays.asList(cmd); + return cmd(Arrays.asList(cmd)); + } + + public Builder cmd(final String cmd) { + if (cmd != null && !cmd.isEmpty()) { + return cmd(cmd.split(" ")); + } return this; } @@ -446,12 +484,22 @@ public class DockerContainerConfig implements IDockerContainerConfig { } public Builder entryPoint(final List<String> entrypoint) { - this.entrypoint = new ArrayList<>(entrypoint); + if (entrypoint != null && !entrypoint.isEmpty()) { + this.entrypoint = new ArrayList<>(entrypoint); + } return this; } public Builder entryPoint(final String... entrypoint) { - this.entrypoint = Arrays.asList(entrypoint); + return entryPoint(Arrays.asList(entrypoint)); + } + + public Builder entryPoint(final String entrypoint) { + if (entrypoint != null && !entrypoint.isEmpty()) { + return entryPoint(entrypoint.split(" ")); + } else { + this.entrypoint = null; + } return this; } diff --git a/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DockerHostConfig.java b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DockerHostConfig.java index a4649ee2ec..28696080f7 100644 --- a/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DockerHostConfig.java +++ b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DockerHostConfig.java @@ -30,10 +30,10 @@ public class DockerHostConfig implements IDockerHostConfig { private final List<String> binds; private final String containerIDFile; private final List<IDockerConfParameter> lxcConf; - private final Boolean privileged; + private final boolean privileged; private final Map<String, List<IDockerPortBinding>> portBindings; private final List<String> links; - private final Boolean publishAllPorts; + private final boolean publishAllPorts; private final List<String> dns; private final List<String> dnsSearch; private final List<String> volumesFrom; @@ -48,7 +48,8 @@ public class DockerHostConfig implements IDockerHostConfig { this.lxcConf.add(new DockerConfParameter(lxcConfParameter)); } } - this.privileged = hostConfig.privileged(); + this.privileged = hostConfig.privileged() != null + ? hostConfig.privileged() : false; this.portBindings = new HashMap<>(); if(hostConfig != null && hostConfig.portBindings() != null) { for(Entry<String, List<PortBinding>> entry : hostConfig.portBindings().entrySet()) { @@ -60,7 +61,8 @@ public class DockerHostConfig implements IDockerHostConfig { } } this.links = hostConfig.links(); - this.publishAllPorts = hostConfig.publishAllPorts(); + this.publishAllPorts = hostConfig.publishAllPorts() != null + ? hostConfig.publishAllPorts() : false; this.dns = hostConfig.dns(); this.dnsSearch = hostConfig.dnsSearch(); this.volumesFrom = hostConfig.volumesFrom(); @@ -71,10 +73,12 @@ public class DockerHostConfig implements IDockerHostConfig { this.binds = builder.binds; this.containerIDFile = builder.containerIDFile; this.lxcConf = builder.lxcConf; - this.privileged = builder.privileged; + this.privileged = builder.privileged != null ? builder.privileged + : false; this.portBindings = builder.portBindings; this.links = builder.links; - this.publishAllPorts = builder.publishAllPorts; + this.publishAllPorts = builder.publishAllPorts != null + ? builder.publishAllPorts : false; this.dns = builder.dns; this.dnsSearch = builder.dnsSearch; this.volumesFrom = builder.volumesFrom; @@ -97,7 +101,7 @@ public class DockerHostConfig implements IDockerHostConfig { } @Override - public Boolean privileged() { + public boolean privileged() { return privileged; } @@ -112,7 +116,7 @@ public class DockerHostConfig implements IDockerHostConfig { } @Override - public Boolean publishAllPorts() { + public boolean publishAllPorts() { return publishAllPorts; } diff --git a/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DockerImage.java b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DockerImage.java index 80cdd1e54c..4bb3444096 100644 --- a/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DockerImage.java +++ b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DockerImage.java @@ -14,7 +14,9 @@ import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Collections; import java.util.Date; +import java.util.HashMap; import java.util.List; +import java.util.Map; import org.eclipse.linuxtools.docker.core.IDockerImage; @@ -43,13 +45,13 @@ public class DockerImage implements IDockerImage { private final boolean intermediateImage; private final boolean danglingImage; - public DockerImage(final DockerConnection parent, final List<String> repoTags, + public DockerImage(final DockerConnection parent, @Deprecated final List<String> repoTags, final String repo, final List<String> tags, final String id, final String parentId, final String created, final Long size, final Long virtualSize, final boolean intermediateImage, final boolean danglingImage) { this.parent = parent; this.repoTags = repoTags; - this.repo = extractRepo(repoTags); - this.tags = extractTags(repoTags); + this.repo = repo; + this.tags = tags; this.id = id; this.parentId = parentId; this.created = created; @@ -61,21 +63,24 @@ public class DockerImage implements IDockerImage { } /** - * Extracts the org/repo from the list of repo tags, assuming that the given repoTags elements have the following format: + * Extracts the org/repo and all the associated tags from the given {@code repoTags}, assuming that the given repoTags elements have the following format: * <pre>org/repo:tag</pre> or <pre>repo:tag</pre>. * @param repoTags the list of repo/tags to analyze - * @return the repo or org/repo name or {@code null} if none was found. + * @return the tags indexed by org/repo */ - public static String extractRepo(final List<String> repoTags) { - if(repoTags.isEmpty()) { - return null; - } - final String firstRepoTag = repoTags.get(0); - final int indexOfColonChar = firstRepoTag.indexOf(':'); - if(indexOfColonChar == -1) { - return firstRepoTag; + public static Map<String, List<String>> extractTagsByRepo(final List<String> repoTags) { + final Map<String, List<String>> results = new HashMap<>(); + for(String entry : repoTags) { + final int indexOfColonChar = entry.indexOf(':'); + final String repo = (indexOfColonChar > -1) ? entry.substring(0, indexOfColonChar) : entry; + if(!results.containsKey(repo)) { + results.put(repo, new ArrayList<String>()); + } + if(indexOfColonChar > -1) { + results.get(repo).add(entry.substring(indexOfColonChar+1)); + } } - return firstRepoTag.substring(0, indexOfColonChar); + return results; } /** diff --git a/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DockerImageSearchResult.java b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DockerImageSearchResult.java new file mode 100644 index 0000000000..35b1ee9740 --- /dev/null +++ b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DockerImageSearchResult.java @@ -0,0 +1,139 @@ +/******************************************************************************* + * Copyright (c) 2014 Red Hat. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Red Hat - Initial Contribution + */ +package org.eclipse.linuxtools.internal.docker.core; + +import org.eclipse.linuxtools.docker.core.IDockerImageSearchResult; + +/** + * @author xcoulon + * + */ +public class DockerImageSearchResult implements IDockerImageSearchResult { + + /** the image description. */ + private final String description; + /** official image flag. */ + private final boolean official; + /** automated build flag */ + private final boolean automated; + /** image name */ + private final String name; + /** star count */ + private final int starCount; + + /** + * Full constructor + * @param description the image description + * @param official official image flag + * @param automated automated build flag + * @param name image name (org/repo) + * @param starCount star count + */ + public DockerImageSearchResult(String description, boolean official, boolean automated, String name, + int starCount) { + this.description = description; + this.official = official; + this.automated = automated; + this.name = name; + this.starCount = starCount; + } + + /* (non-Javadoc) + * @see org.eclipse.linuxtools.internal.docker.core.IDockerImageSearchResult#getDescription() + */ + @Override + public String getDescription() { + return description; + } + + /* (non-Javadoc) + * @see org.eclipse.linuxtools.internal.docker.core.IDockerImageSearchResult#isOfficial() + */ + @Override + public boolean isOfficial() { + return official; + } + + /* (non-Javadoc) + * @see org.eclipse.linuxtools.internal.docker.core.IDockerImageSearchResult#isAutomated() + */ + @Override + public boolean isAutomated() { + return automated; + } + + /* (non-Javadoc) + * @see org.eclipse.linuxtools.internal.docker.core.IDockerImageSearchResult#getName() + */ + @Override + public String getName() { + return name; + } + + /* (non-Javadoc) + * @see org.eclipse.linuxtools.internal.docker.core.IDockerImageSearchResult#getStarCount() + */ + @Override + public int getStarCount() { + return starCount; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + (automated ? 1231 : 1237); + result = prime * result + ((description == null) ? 0 : description.hashCode()); + result = prime * result + ((name == null) ? 0 : name.hashCode()); + result = prime * result + (official ? 1231 : 1237); + result = prime * result + starCount; + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final DockerImageSearchResult other = (DockerImageSearchResult) obj; + if (automated != other.automated) { + return false; + } + if (description == null) { + if (other.description != null) { + return false; + } + } else if (!description.equals(other.description)) { + return false; + } + if (name == null) { + if (other.name != null) { + return false; + } + } else if (!name.equals(other.name)) { + return false; + } + if (official != other.official) { + return false; + } + if (starCount != other.starCount) { + return false; + } + return true; + } + +} |