Repository: jclouds-labs-google Updated Branches: refs/heads/master 1e86ef644 -> 8b5d3d3ce
Use images from all public projects and filter deprecated ones Project: http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/repo Commit: http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/commit/8b5d3d3c Tree: http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/tree/8b5d3d3c Diff: http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/diff/8b5d3d3c Branch: refs/heads/master Commit: 8b5d3d3cea7dd051e7fc30f92d4450e5e5852ab7 Parents: 1e86ef6 Author: Ignasi Barrera <[email protected]> Authored: Tue Nov 4 16:02:20 2014 +0100 Committer: Ignasi Barrera <[email protected]> Committed: Wed Nov 5 18:15:29 2014 +0100 ---------------------------------------------------------------------- google-compute-engine/pom.xml | 2 +- .../GoogleComputeEngineApiMetadata.java | 2 ++ .../GoogleComputeEngineConstants.java | 10 +++--- .../GoogleComputeEngineServiceAdapter.java | 37 +++++++++++++------- ...GoogleComputeEngineServiceContextModule.java | 10 ++++++ .../GoogleComputeEngineServiceExpectTest.java | 2 ++ 6 files changed, 46 insertions(+), 17 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/8b5d3d3c/google-compute-engine/pom.xml ---------------------------------------------------------------------- diff --git a/google-compute-engine/pom.xml b/google-compute-engine/pom.xml index 31c7de3..ac45197 100644 --- a/google-compute-engine/pom.xml +++ b/google-compute-engine/pom.xml @@ -39,7 +39,7 @@ </test.google-compute-engine.credential> <test.google-compute-engine.api-version>v1</test.google-compute-engine.api-version> <test.google-compute-engine.build-version/> - <test.google-compute-engine.template>imageId=debian-7-wheezy-v20131120,locationId=us-central1-a,minRam=2048</test.google-compute-engine.template> + <test.google-compute-engine.template>imageNameMatches=debian-7-wheezy-v[0-9]*,locationId=us-central1-a,minRam=2048</test.google-compute-engine.template> </properties> <dependencies> http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/8b5d3d3c/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/GoogleComputeEngineApiMetadata.java ---------------------------------------------------------------------- diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/GoogleComputeEngineApiMetadata.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/GoogleComputeEngineApiMetadata.java index 0b7bed7..6584d18 100644 --- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/GoogleComputeEngineApiMetadata.java +++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/GoogleComputeEngineApiMetadata.java @@ -18,6 +18,7 @@ package org.jclouds.googlecomputeengine; import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL; import static org.jclouds.compute.config.ComputeServiceProperties.TEMPLATE; +import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.GCE_IMAGE_PROJECTS; import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.GCE_PROVIDER_NAME; import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.OPERATION_COMPLETE_INTERVAL; import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.OPERATION_COMPLETE_TIMEOUT; @@ -66,6 +67,7 @@ public class GoogleComputeEngineApiMetadata extends BaseHttpApiMetadata<GoogleCo properties.setProperty(TEMPLATE, "osFamily=DEBIAN,osVersionMatches=7\\..*,locationId=us-central1-a,loginUser=jclouds"); properties.put(OPERATION_COMPLETE_INTERVAL, 500); properties.put(OPERATION_COMPLETE_TIMEOUT, 600000); + properties.put(GCE_IMAGE_PROJECTS, "centos-cloud,debian-cloud,rhel-cloud,suse-cloud,opensuse-cloud,gce-nvme,coreos-cloud"); return properties; } http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/8b5d3d3c/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/GoogleComputeEngineConstants.java ---------------------------------------------------------------------- diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/GoogleComputeEngineConstants.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/GoogleComputeEngineConstants.java index d20ff98..16c68a8 100644 --- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/GoogleComputeEngineConstants.java +++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/GoogleComputeEngineConstants.java @@ -31,10 +31,6 @@ public final class GoogleComputeEngineConstants { */ public static final String GOOGLE_PROJECT = "google"; - public static final String CENTOS_PROJECT = "centos-cloud"; - - public static final String DEBIAN_PROJECT = "debian-cloud"; - public static final String COMPUTE_SCOPE = "https://www.googleapis.com/auth/compute"; public static final String COMPUTE_READONLY_SCOPE = "https://www.googleapis.com/auth/compute.readonly"; @@ -59,6 +55,12 @@ public final class GoogleComputeEngineConstants { public static final Location GOOGLE_PROVIDER_LOCATION = new LocationBuilder().scope(LocationScope.PROVIDER).id (GCE_PROVIDER_NAME).description(GCE_PROVIDER_NAME).build(); + /** + * The list of projects that will be scanned looking for images. + */ + @Beta + public static final String GCE_IMAGE_PROJECTS = "jclouds.google-compute-engine.image-projects"; + /** * The key we look for in instance metadata for the URI for the image the instance was created from. http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/8b5d3d3c/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/GoogleComputeEngineServiceAdapter.java ---------------------------------------------------------------------- diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/GoogleComputeEngineServiceAdapter.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/GoogleComputeEngineServiceAdapter.java index bedace7..c330eda 100644 --- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/GoogleComputeEngineServiceAdapter.java +++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/GoogleComputeEngineServiceAdapter.java @@ -22,12 +22,12 @@ import static com.google.common.collect.Iterables.contains; import static com.google.common.collect.Iterables.filter; import static com.google.common.collect.Iterables.transform; import static com.google.common.collect.Iterables.tryFind; +import static com.google.common.collect.Lists.newArrayList; import static java.util.concurrent.TimeUnit.MILLISECONDS; -import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.CENTOS_PROJECT; -import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.DEBIAN_PROJECT; import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.GCE_BOOT_DISK_SUFFIX; import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.GCE_DELETE_BOOT_DISK_METADATA_KEY; import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.GCE_IMAGE_METADATA_KEY; +import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.GCE_IMAGE_PROJECTS; import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.OPERATION_COMPLETE_INTERVAL; import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.OPERATION_COMPLETE_TIMEOUT; import static org.jclouds.googlecomputeengine.domain.Instance.NetworkInterface.AccessConfig.Type; @@ -39,6 +39,7 @@ import java.net.URI; import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.NoSuchElementException; import java.util.Set; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference; @@ -75,7 +76,6 @@ import org.jclouds.googlecomputeengine.features.InstanceApi; import org.jclouds.googlecomputeengine.options.DiskCreationOptions; import com.google.common.base.Function; -import com.google.common.base.Objects; import com.google.common.base.Predicate; import com.google.common.base.Supplier; import com.google.common.collect.FluentIterable; @@ -97,6 +97,7 @@ public final class GoogleComputeEngineServiceAdapter implements ComputeServiceAd private final long operationCompleteCheckInterval; private final long operationCompleteCheckTimeout; private final FirewallTagNamingConvention.Factory firewallTagNamingConvention; + private final List<String> imageProjects; @Inject GoogleComputeEngineServiceAdapter(GoogleComputeEngineApi api, @UserProject Supplier<String> userProject, @@ -106,7 +107,8 @@ public final class GoogleComputeEngineServiceAdapter implements ComputeServiceAd @Named(OPERATION_COMPLETE_INTERVAL) Long operationCompleteCheckInterval, @Named(OPERATION_COMPLETE_TIMEOUT) Long operationCompleteCheckTimeout, @Memoized Supplier<Map<URI, ? extends Location>> zones, - FirewallTagNamingConvention.Factory firewallTagNamingConvention) { + FirewallTagNamingConvention.Factory firewallTagNamingConvention, + @Named(GCE_IMAGE_PROJECTS) List<String> imageProjects) { this.api = api; this.userProject = userProject; this.metatadaFromTemplateOptions = metatadaFromTemplateOptions; @@ -116,6 +118,7 @@ public final class GoogleComputeEngineServiceAdapter implements ComputeServiceAd operationCompleteCheckInterval, TimeUnit.MILLISECONDS); this.zones = zones; this.firewallTagNamingConvention = firewallTagNamingConvention; + this.imageProjects = imageProjects; } @Override @@ -261,19 +264,29 @@ public final class GoogleComputeEngineServiceAdapter implements ComputeServiceAd @Override public Iterable<Image> listImages() { - return Iterables.concat( // - concat(api.getImageApi(userProject.get()).list()), // - concat(api.getImageApi(DEBIAN_PROJECT).list()), // - concat(api.getImageApi(CENTOS_PROJECT).list())); + List<Iterable<Image>> images = newArrayList(); + + images.add(concat(api.getImageApi(userProject.get()).list())); + + for (String project : imageProjects) { + images.add(concat(api.getImageApi(project).list())); + } + + return Iterables.concat(images); } - @SuppressWarnings("deprecation") @Override public Image getImage(String id) { - return Objects.firstNonNull(api.getImageApi(userProject.get()).get(id), - Objects.firstNonNull(api.getImageApi(DEBIAN_PROJECT).get(id), - api.getImageApi(CENTOS_PROJECT).get(id))); + Image image = api.getImageApi(userProject.get()).get(id); + for (int i = 0; i < imageProjects.size() && image == null; i++) { + image = api.getImageApi(imageProjects.get(i)).get(id); + } + + if (image == null) { + throw new NoSuchElementException("No image found with id: " + id); + } + return image; } @Override http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/8b5d3d3c/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/config/GoogleComputeEngineServiceContextModule.java ---------------------------------------------------------------------- diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/config/GoogleComputeEngineServiceContextModule.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/config/GoogleComputeEngineServiceContextModule.java index 70c2b23..c75d3e2 100644 --- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/config/GoogleComputeEngineServiceContextModule.java +++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/config/GoogleComputeEngineServiceContextModule.java @@ -20,8 +20,10 @@ import static com.google.common.collect.Iterables.transform; import static com.google.common.collect.Maps.uniqueIndex; import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL; import static org.jclouds.googlecomputeengine.internal.ListPages.concat; +import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.GCE_IMAGE_PROJECTS; import java.net.URI; +import java.util.List; import java.util.Map; import java.util.Set; import java.util.concurrent.TimeUnit; @@ -81,6 +83,7 @@ import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Function; import com.google.common.base.Optional; import com.google.common.base.Predicate; +import com.google.common.base.Splitter; import com.google.common.base.Supplier; import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheLoader; @@ -281,4 +284,11 @@ public class GoogleComputeEngineServiceContextModule protected Map<Instance.Status, NodeMetadata.Status> toPortableNodeStatus() { return toPortableNodeStatus; } + + @Singleton + @Provides + @Named(GCE_IMAGE_PROJECTS) + protected List<String> imageProjects(@Named(GCE_IMAGE_PROJECTS) String imageProjects) { + return Splitter.on(',').splitToList(imageProjects); + } } http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/8b5d3d3c/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/compute/GoogleComputeEngineServiceExpectTest.java ---------------------------------------------------------------------- diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/compute/GoogleComputeEngineServiceExpectTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/compute/GoogleComputeEngineServiceExpectTest.java index c765a81..0fc1771 100644 --- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/compute/GoogleComputeEngineServiceExpectTest.java +++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/compute/GoogleComputeEngineServiceExpectTest.java @@ -20,6 +20,7 @@ import static com.google.common.collect.Iterables.getOnlyElement; import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_READONLY_SCOPE; import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_SCOPE; import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.GCE_BOOT_DISK_SUFFIX; +import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.GCE_IMAGE_PROJECTS; import static org.jclouds.googlecomputeengine.features.GlobalOperationApiExpectTest.GET_GLOBAL_OPERATION_REQUEST; import static org.jclouds.googlecomputeengine.features.GlobalOperationApiExpectTest.GET_GLOBAL_OPERATION_RESPONSE; import static org.jclouds.googlecomputeengine.features.ImageApiExpectTest.LIST_CENTOS_IMAGES_REQUEST; @@ -217,6 +218,7 @@ public class GoogleComputeEngineServiceExpectTest extends BaseGoogleComputeEngin protected Properties setupProperties() { Properties overrides = super.setupProperties(); overrides.put("google-compute-engine.identity", "myproject"); + overrides.put(GCE_IMAGE_PROJECTS, "debian-cloud,centos-cloud"); try { overrides.put("google-compute-engine.credential", toStringAndClose(getClass().getResourceAsStream("/testpk.pem"))); } catch (IOException e) {
