[JCLOUDS-550] fix for obsolete machineTypes
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 62d3914..b1249d6 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
@@ -32,7 +32,6 @@
import static org.jclouds.googlecomputeengine.domain.Instance.NetworkInterface.AccessConfig.Type;
import static org.jclouds.googlecomputeengine.predicates.InstancePredicates.isBootDisk;
import static org.jclouds.util.Predicates2.retry;
-
import java.net.URI;
import java.util.List;
import java.util.Map;
@@ -263,6 +262,12 @@
builder.addAll(api.getMachineTypeApiForProject(userProject.get())
.listInZone(zone.getId())
.concat()
+ .filter(new Predicate<MachineType>() {
+ @Override
+ public boolean apply(MachineType input) {
+ return !input.getDeprecated().isPresent();
+ }
+ })
.transform(new Function<MachineType, MachineTypeInZone>() {
@Override
@@ -288,7 +293,7 @@
public Image getImage(String id) {
return Objects.firstNonNull(api.getImageApiForProject(userProject.get()).get(id),
Objects.firstNonNull(api.getImageApiForProject(DEBIAN_PROJECT).get(id),
- api.getImageApiForProject(CENTOS_PROJECT).get(id)));
+ api.getImageApiForProject(CENTOS_PROJECT).get(id)));
}
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/functions/InstanceInZoneToNodeMetadata.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/functions/InstanceInZoneToNodeMetadata.java
index 3bd9296..a018534 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/functions/InstanceInZoneToNodeMetadata.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/functions/InstanceInZoneToNodeMetadata.java
@@ -100,8 +100,7 @@
.providerId(input.getId())
.hostname(input.getName())
.location(checkNotNull(locations.get().get(input.getZone()), "location for %s", input.getZone()))
- .hardware(checkNotNull(hardwares.get().get(input.getMachineType()), "hardware type for %s",
- input.getMachineType().toString()))
+ .hardware(hardwares.get().get(input.getMachineType()))
.status(toPortableNodeStatus.get(input.getStatus()))
.tags(tags)
.uri(input.getSelfLink())
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/MachineType.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/MachineType.java
index c18ec58..a214f94 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/MachineType.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/MachineType.java
@@ -18,15 +18,18 @@
import static com.google.common.base.Objects.equal;
import static com.google.common.base.Objects.toStringHelper;
+import static com.google.common.base.Optional.fromNullable;
import static com.google.common.base.Preconditions.checkNotNull;
-
import java.beans.ConstructorProperties;
import java.net.URI;
import java.util.Date;
import java.util.List;
+import org.jclouds.javax.annotation.Nullable;
+
import com.google.common.annotations.Beta;
import com.google.common.base.Objects;
+import com.google.common.base.Optional;
import com.google.common.collect.ImmutableList;
/**
@@ -45,14 +48,17 @@
private final Integer maximumPersistentDisks;
private final Long maximumPersistentDisksSizeGb;
private final String zone;
+ private final Optional<Deprecated> deprecated;
@ConstructorProperties({
"id", "creationTimestamp", "selfLink", "name", "description", "guestCpus", "memoryMb",
- "imageSpaceGb", "scratchDisks", "maximumPersistentDisks", "maximumPersistentDisksSizeGb", "zone"
+ "imageSpaceGb", "scratchDisks", "maximumPersistentDisks", "maximumPersistentDisksSizeGb", "zone",
+ "deprecated"
})
private MachineType(String id, Date creationTimestamp, URI selfLink, String name, String description,
int guestCpus, int memoryMb, int imageSpaceGb, List<ScratchDisk> scratchDisks,
- int maximumPersistentDisks, long maximumPersistentDisksSizeGb, String zone) {
+ int maximumPersistentDisks, long maximumPersistentDisksSizeGb, String zone,
+ @Nullable Deprecated deprecated) {
super(Kind.MACHINE_TYPE, id, creationTimestamp, selfLink, name, description);
this.guestCpus = checkNotNull(guestCpus, "guestCpus of %s", name);
this.memoryMb = checkNotNull(memoryMb, "memoryMb of %s", name);
@@ -61,6 +67,7 @@
this.maximumPersistentDisks = checkNotNull(maximumPersistentDisks, "maximumPersistentDisks of %s", name);
this.maximumPersistentDisksSizeGb = maximumPersistentDisksSizeGb;
this.zone = checkNotNull(zone, "zone of %s", name);
+ this.deprecated = fromNullable(deprecated);
}
/**
@@ -113,6 +120,13 @@
}
/**
+ * @return the deprecation information for this machine type
+ */
+ public Optional<Deprecated> getDeprecated() {
+ return deprecated;
+ }
+
+ /**
* {@inheritDoc}
*/
@Override
@@ -136,7 +150,8 @@
.add("scratchDisks", scratchDisks)
.add("maximumPersistentDisks", maximumPersistentDisks)
.add("maximumPersistentDisksSizeGb", maximumPersistentDisksSizeGb)
- .add("zone", zone);
+ .add("zone", zone)
+ .add("deprecated", deprecated.orNull());
}
/**
@@ -164,6 +179,7 @@
private Integer maximumPersistentDisks;
private Long maximumPersistentDisksSizeGb;
private String zone;
+ private Deprecated deprecated;
/**
* @see MachineType#getGuestCpus()
@@ -229,6 +245,14 @@
return this;
}
+ /**
+ * @see MachineType#getDeprecated()
+ */
+ public Builder deprecated(Deprecated deprecated) {
+ this.deprecated = deprecated;
+ return this;
+ }
+
@Override
protected Builder self() {
return this;
@@ -237,15 +261,15 @@
public MachineType build() {
return new MachineType(id, creationTimestamp, selfLink, name, description, guestCpus, memoryMb,
imageSpaceGb, scratchDisks.build(), maximumPersistentDisks, maximumPersistentDisksSizeGb,
- zone);
+ zone, deprecated);
}
public Builder fromMachineType(MachineType in) {
return super.fromResource(in).memoryMb(in.getMemoryMb()).imageSpaceGb(in.getImageSpaceGb()).scratchDisks(in
.getScratchDisks()).maximumPersistentDisks(in.getMaximumPersistentDisks())
- .maximumPersistentDisksSizeGb(in.getMaximumPersistentDisksSizeGb()).zone(in
- .getZone());
+ .maximumPersistentDisksSizeGb(in.getMaximumPersistentDisksSizeGb()).zone(in.getZone())
+ .deprecated(in.getDeprecated().orNull());
}
}
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/compute/GoogleComputeEngineServiceLiveTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/compute/GoogleComputeEngineServiceLiveTest.java
index fbcd355..b28fcff 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/compute/GoogleComputeEngineServiceLiveTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/compute/GoogleComputeEngineServiceLiveTest.java
@@ -16,15 +16,28 @@
*/
package org.jclouds.googlecomputeengine.compute;
+import static com.google.common.collect.Iterables.contains;
+import static org.jclouds.oauth.v2.OAuthTestUtils.setCredentialFromPemFile;
+import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertTrue;
+import java.util.Properties;
+import java.util.Set;
+import org.jclouds.compute.domain.Hardware;
import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.internal.BaseComputeServiceLiveTest;
+import org.jclouds.googlecomputeengine.GoogleComputeEngineApi;
+import org.jclouds.googlecomputeengine.config.UserProject;
+import org.jclouds.googlecomputeengine.domain.MachineType;
import org.jclouds.sshj.config.SshjSshClientModule;
import org.testng.annotations.Test;
+import com.google.common.base.Supplier;
import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.ImmutableSet;
+import com.google.inject.Key;
import com.google.inject.Module;
+import com.google.inject.TypeLiteral;
/**
* @author David Alves
@@ -32,10 +45,39 @@
@Test(groups = "live", singleThreaded = true)
public class GoogleComputeEngineServiceLiveTest extends BaseComputeServiceLiveTest {
+ protected static final String DEFAULT_ZONE_NAME = "us-central1-a";
+
public GoogleComputeEngineServiceLiveTest() {
provider = "google-compute-engine";
}
+ @Override
+ protected Properties setupProperties() {
+ Properties props = super.setupProperties();
+ setCredentialFromPemFile(props, provider + ".credential");
+ return props;
+ }
+
+ public void testListHardwareProfiles() throws Exception {
+ GoogleComputeEngineApi api = client.getContext().unwrapApi(GoogleComputeEngineApi.class);
+ Supplier<String> userProject = context.utils().injector().getInstance(Key.get(new TypeLiteral<Supplier<String>>() {
+ }, UserProject.class));
+ ImmutableSet.Builder<String> deprecatedMachineTypes = ImmutableSet.builder();
+ for (MachineType machine : api.getMachineTypeApiForProject(userProject.get())
+ .listInZone(DEFAULT_ZONE_NAME).concat()) {
+ if (machine.getDeprecated().isPresent()) {
+ deprecatedMachineTypes.add(machine.getId());
+ }
+ }
+ ImmutableSet<String> deprecatedMachineTypeIds = deprecatedMachineTypes.build();
+ Set<? extends Hardware> hardwareProfiles = client.listHardwareProfiles();
+ System.out.println(hardwareProfiles.size());
+ for (Hardware hardwareProfile : hardwareProfiles) {
+ System.out.println(hardwareProfile);
+ assertFalse(contains(deprecatedMachineTypeIds, hardwareProfile.getId()));
+ }
+ }
+
/**
* Nodes may have additional metadata entries (particularly they may have an "sshKeys" entry)
*/