Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorXavier Coulon2015-08-10 12:44:29 +0000
committerRoland Grunberg2015-08-19 17:40:58 +0000
commitc2a2ca8efb3c3fd1825f412e49810f2a84cc62f9 (patch)
tree3e2582f9a9067d792a3704959d286c2cb1452685 /containers/org.eclipse.linuxtools.docker.core/src/org/eclipse
parent0df4a22f0ed5cb48dab2c27308f6dc99119c791c (diff)
downloadorg.eclipse.linuxtools-c2a2ca8efb3c3fd1825f412e49810f2a84cc62f9.tar.gz
org.eclipse.linuxtools-c2a2ca8efb3c3fd1825f412e49810f2a84cc62f9.tar.xz
org.eclipse.linuxtools-c2a2ca8efb3c3fd1825f412e49810f2a84cc62f9.zip
Bug 474606 - Allow for search and pull images from the Docker Explorer view
Added a view in page in the SearchImage wizard to specify the image tag to pull: - the list of image tags is retrieved from a new class called DockerHubRegistry (in the core module) - the DockerHubRegistry#getTags(String) sends an HTTP request to list the tags for a given repository on Docker Hub, using a specific/known endpoint. This is not part of the docker-client because the Docker client deals with CLI commands on the Docker daemon/engine and this operation is out of scope. This might need to be refactored/opened in the future, when support for third-party registries will be implemented. - Pull image command is available at the connection level in the Docker Explorer view, too. Other bits in this commit: - refactored the DVMessages class to support varargs instead of an array of arguments, which makes the API more convenient to use - removed unused classes - reformatted blocks of code badly indented - removed author name in some classes/added copyright where found missing Change-Id: I83c086c4aa8a8e73c3364a885cefcdb2d36cb7f8 Signed-off-by: Xavier Coulon <xcoulon@redhat.com> Reviewed-on: https://git.eclipse.org/r/53481 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')
-rw-r--r--containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/IDockerConnection.java28
-rw-r--r--containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/IDockerImageSearchResult.java10
-rw-r--r--containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/IDockerRegistry.java36
-rw-r--r--containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/IRepositoryTag.java28
-rw-r--r--containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/Messages.java1
-rw-r--r--containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/Messages.properties3
-rw-r--r--containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DockerConnection.java16
-rw-r--r--containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DockerHubRegistry.java84
-rw-r--r--containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DockerImageSearchResult.java44
-rw-r--r--containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/RepositoryTag.java72
10 files changed, 282 insertions, 40 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 bd5372394f..14203a3f50 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
@@ -85,22 +85,34 @@ public interface IDockerConnection {
public List<IDockerImage> getImages();
/**
+ * Checks if an entry in the current list of {@link IDockerImage} exists
+ * with the same <code>name</code> and <code>tag</code>
+ *
+ * @param repository
+ * the repository of the {@link IDockerImage} to find
+ * @param tag
+ * the tag of the {@link IDockerImage} to find
+ * @return <code>true</code> if an {@link IDockerImage} was found,
+ * <code>false</code> otherwise.
+ */
+ public boolean hasImage(String repository, String tag);
+
+ /**
+ * @return Boolean flag to indicate if the list of {@link IDockerImage} has
+ * already been loaded ({@code true}) or not ({@code false}).
+ */
+ public boolean isImagesLoaded();
+
+ /**
* Get the list of {@link IDockerImage} of the remote Docker daemon.
*
* @param force
* {@code true} to force a new retrieval of the list of
- * {@link IDockerImage}, {@code false} to use the cached
- * list.
+ * {@link IDockerImage}, {@code false} to use the cached list.
* @return an unmodifiable list of {@link IDockerImage} or
* {@link Collections#emptyList()} if no container exists yet.
*/
public List<IDockerImage> getImages(final boolean force);
-
- /**
- * @return Boolean flag to indicate if the list of {@link IDockerImage}
- * has already been loaded ({@code true}) or not ({@code false}).
- */
- public boolean isImagesLoaded();
public String getName();
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
index bfd44454ae..2d29e39147 100644
--- 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
@@ -1,3 +1,13 @@
+/*******************************************************************************
+ * Copyright (c) 2015 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.docker.core;
public interface IDockerImageSearchResult {
diff --git a/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/IDockerRegistry.java b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/IDockerRegistry.java
new file mode 100644
index 0000000000..a755a73c00
--- /dev/null
+++ b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/IDockerRegistry.java
@@ -0,0 +1,36 @@
+/*******************************************************************************
+ * Copyright (c) 2015 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.docker.core;
+
+import java.util.List;
+import java.util.concurrent.ExecutionException;
+
+import com.spotify.docker.client.DockerRequestException;
+
+/**
+ * An interface for Docker registries.
+ */
+public interface IDockerRegistry {
+
+ /**
+ * @return the {@link List} of available {@link IDockerImageTagSearchResult}
+ * for the given repository on this IDockerRegistry.
+ * @param repository
+ * the image repository
+ * @throws InterruptedException
+ * @throws DockerRequestException
+ * @throws ExecutionException
+ */
+ List<IRepositoryTag> getTags(String repository)
+ throws InterruptedException, ExecutionException, DockerException;
+
+}
diff --git a/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/IRepositoryTag.java b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/IRepositoryTag.java
new file mode 100644
index 0000000000..16a8ed1f0c
--- /dev/null
+++ b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/IRepositoryTag.java
@@ -0,0 +1,28 @@
+/*******************************************************************************
+ * Copyright (c) 2015 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.docker.core;
+
+/**
+ * A tag (or version) for a given repository.
+ */
+public interface IRepositoryTag {
+
+ /**
+ * @return Name of the tag.
+ */
+ String getName();
+
+ /**
+ * @return The corresponding image layer for this specific tag
+ */
+ String getLayer();
+}
diff --git a/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/Messages.java b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/Messages.java
index 19b6cbe46e..abab16b1e2 100644
--- a/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/Messages.java
+++ b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/Messages.java
@@ -32,6 +32,7 @@ public class Messages extends NLS {
public static String List_Docker_Containers_Failure;
public static String Docker_General_Info_Failure;
public static String Docker_No_Settings_Description_Script;
+ public static String Registry_Version_Mismatch;
static {
// Initialize resource bundle.
diff --git a/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/Messages.properties b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/Messages.properties
index 5a6fd27dc0..76642a6864 100644
--- a/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/Messages.properties
+++ b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/Messages.properties
@@ -25,4 +25,5 @@ Docker_Daemon_Ping_Failure=Failed to ping the Docker daemon
Retrieve_Docker_Certificates_Failure=Unable to retrieve certificates to connect to the Docker daemon
List_Docker_Containers_Failure=Failed to load list of Docker containers from {0}
Docker_General_Info_Failure=Failed to get Docker connection info
-Docker_No_Settings_Description_Script=There is no settings detection script for this OS \ No newline at end of file
+Docker_No_Settings_Description_Script=There is no settings detection script for this OS
+Registry_Version_Mismatch=Target Docker registry located at {0} does not support API v1 \ 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 cfdb7d5a2f..e205a6b6a1 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
@@ -1009,6 +1009,20 @@ public class DockerConnection implements IDockerConnection {
}
@Override
+ public boolean hasImage(final String repository, final String tag) {
+ for (IDockerImage image : getImages()) {
+ if (image.repo().equals(repository)) {
+ for (String imageTag : image.tags()) {
+ if (imageTag.startsWith(tag)) {
+ return true;
+ }
+ }
+ }
+ }
+ return false;
+ }
+
+ @Override
public void pullImage(final String id, final IDockerProgressHandler handler)
throws DockerException, InterruptedException {
try {
@@ -1036,8 +1050,6 @@ public class DockerConnection implements IDockerConnection {
}
}
-
-
@Override
public void pushImage(final String name, final IDockerProgressHandler handler)
throws DockerException, InterruptedException {
diff --git a/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DockerHubRegistry.java b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DockerHubRegistry.java
new file mode 100644
index 0000000000..23b40730af
--- /dev/null
+++ b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DockerHubRegistry.java
@@ -0,0 +1,84 @@
+/*******************************************************************************
+ * Copyright (c) 2015 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 static javax.ws.rs.HttpMethod.GET;
+import static javax.ws.rs.core.MediaType.APPLICATION_JSON_TYPE;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.concurrent.ExecutionException;
+
+import javax.ws.rs.client.Client;
+import javax.ws.rs.client.ClientBuilder;
+import javax.ws.rs.client.WebTarget;
+import javax.ws.rs.core.GenericType;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.Status;
+
+import org.eclipse.linuxtools.docker.core.Activator;
+import org.eclipse.linuxtools.docker.core.DockerException;
+import org.eclipse.linuxtools.docker.core.IDockerRegistry;
+import org.eclipse.linuxtools.docker.core.IRepositoryTag;
+import org.eclipse.linuxtools.docker.core.Messages;
+import org.eclipse.osgi.util.NLS;
+import org.glassfish.jersey.client.ClientConfig;
+import org.glassfish.jersey.jackson.JacksonFeature;
+
+import com.spotify.docker.client.ObjectMapperProvider;
+
+/**
+ * The default implementation is the Docker Hub registry (running Docker
+ * registry version 0.6.3)
+ */
+public class DockerHubRegistry implements IDockerRegistry {
+
+ private static final String REGISTRY_LOCATION = "https://registry.hub.docker.com/"; //$NON-NLS-1$
+
+ @Override
+ public List<IRepositoryTag> getTags(final String repository)
+ throws InterruptedException, ExecutionException, DockerException {
+ // check that the registry supports the version 1 API
+ // see
+ // https://github.com/docker/docker-registry/blob/master/docker_registry/app.py
+ final ClientConfig DEFAULT_CONFIG = new ClientConfig(
+ ObjectMapperProvider.class, JacksonFeature.class);
+
+ final Client client = ClientBuilder.newClient(DEFAULT_CONFIG);
+ final WebTarget pingApiv1Resource = client.target(REGISTRY_LOCATION)
+ .path("v1").path("_ping"); //$NON-NLS-1$ //$NON-NLS-2$
+ try {
+ final Response response = pingApiv1Resource
+ .request(APPLICATION_JSON_TYPE).async().get().get();
+ if (response.getStatus() != Status.OK.getStatusCode()) {
+ throw new DockerException(
+ NLS.bind(Messages.List_Docker_Containers_Failure,
+ REGISTRY_LOCATION));
+ }
+ } catch (ExecutionException e) {
+ Activator.log(e);
+ return Collections.emptyList();
+ }
+ // now, query the registry
+ final WebTarget queryTagsResource = client.target(REGISTRY_LOCATION)
+ .path("v1").path("repositories").path(repository).path("tags"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ final GenericType<List<RepositoryTag>> REPOSITORY_TAGS_RESULT_LIST = new GenericType<List<RepositoryTag>>() {
+ };
+ final List<RepositoryTag> result = queryTagsResource
+ .request(APPLICATION_JSON_TYPE).async()
+ .method(GET, REPOSITORY_TAGS_RESULT_LIST).get();
+
+ return new ArrayList<IRepositoryTag>(result);
+ }
+
+}
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
index 22a9f4448d..f0d1b39b64 100644
--- 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
@@ -13,10 +13,10 @@ package org.eclipse.linuxtools.internal.docker.core;
import org.eclipse.linuxtools.docker.core.IDockerImageSearchResult;
/**
- * @author xcoulon
*
*/
-public class DockerImageSearchResult implements IDockerImageSearchResult {
+public class DockerImageSearchResult
+ implements IDockerImageSearchResult {
/** the image description. */
private final String description;
@@ -31,14 +31,20 @@ public class DockerImageSearchResult implements IDockerImageSearchResult {
/**
* 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
+ *
+ * @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) {
+ public DockerImageSearchResult(String description, boolean official,
+ boolean automated, String name, int starCount) {
this.description = description;
this.official = official;
this.automated = automated;
@@ -75,11 +81,7 @@ public class DockerImageSearchResult implements IDockerImageSearchResult {
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;
}
@@ -95,16 +97,6 @@ public class DockerImageSearchResult implements IDockerImageSearchResult {
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;
@@ -112,12 +104,6 @@ public class DockerImageSearchResult implements IDockerImageSearchResult {
} else if (!name.equals(other.name)) {
return false;
}
- if (official != other.official) {
- return false;
- }
- if (starCount != other.starCount) {
- return false;
- }
return true;
}
diff --git a/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/RepositoryTag.java b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/RepositoryTag.java
new file mode 100644
index 0000000000..657a2a95ae
--- /dev/null
+++ b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/RepositoryTag.java
@@ -0,0 +1,72 @@
+/*******************************************************************************
+ * 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 static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.ANY;
+import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.NONE;
+
+import org.eclipse.linuxtools.docker.core.IRepositoryTag;
+
+import com.fasterxml.jackson.annotation.JsonAutoDetect;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.google.common.base.Objects;
+
+/**
+ * Repository tag retrieved from Docker Registry version 0.6.3
+ *
+ */
+@JsonAutoDetect(fieldVisibility = ANY, getterVisibility = NONE, setterVisibility = NONE)
+public class RepositoryTag implements IRepositoryTag {
+
+ @JsonProperty("layer") //$NON-NLS-1$
+ private String layer;
+ @JsonProperty("name") //$NON-NLS-1$
+ private String name;
+
+ /**
+ * @return the layer
+ */
+ @Override
+ public String getLayer() {
+ return layer;
+ }
+
+ /**
+ * @param layer
+ * the layer to set
+ */
+ public void setLayer(String layer) {
+ this.layer = layer;
+ }
+
+ /**
+ * @return the name
+ */
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * @param name
+ * the name to set
+ */
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ @Override
+ public String toString() {
+ return Objects.toStringHelper(this).add("name", getName()) //$NON-NLS-1$
+ .add("layer", getLayer()).toString(); //$NON-NLS-1$
+ }
+
+}

Back to the top