[JCLOUDS-550] fix for obsolete machineTypes

This commit is contained in:
Andrea Turli 2014-04-25 15:23:04 +02:00
parent 40b65c5d39
commit 8fd946c93d
4 changed files with 81 additions and 11 deletions

View File

@ -32,7 +32,6 @@ import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.OPERA
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;
@ -260,6 +259,12 @@ public class GoogleComputeEngineServiceAdapter implements ComputeServiceAdapter<
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
@ -285,7 +290,7 @@ public class GoogleComputeEngineServiceAdapter implements ComputeServiceAdapter<
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)));
}

View File

@ -98,8 +98,7 @@ public class InstanceInZoneToNodeMetadata implements Function<InstanceInZone, No
.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())

View File

@ -18,15 +18,18 @@ package org.jclouds.googlecomputeengine.domain;
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;
/**
@ -44,14 +47,17 @@ public final class MachineType extends Resource {
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);
@ -60,6 +66,7 @@ public final class MachineType extends Resource {
this.maximumPersistentDisks = checkNotNull(maximumPersistentDisks, "maximumPersistentDisks of %s", name);
this.maximumPersistentDisksSizeGb = maximumPersistentDisksSizeGb;
this.zone = checkNotNull(zone, "zone of %s", name);
this.deprecated = fromNullable(deprecated);
}
/**
@ -111,6 +118,13 @@ public final class MachineType extends Resource {
return zone;
}
/**
* @return the deprecation information for this machine type
*/
public Optional<Deprecated> getDeprecated() {
return deprecated;
}
/**
* {@inheritDoc}
*/
@ -135,7 +149,8 @@ public final class MachineType extends Resource {
.add("scratchDisks", scratchDisks)
.add("maximumPersistentDisks", maximumPersistentDisks)
.add("maximumPersistentDisksSizeGb", maximumPersistentDisksSizeGb)
.add("zone", zone);
.add("zone", zone)
.add("deprecated", deprecated.orNull());
}
/**
@ -163,6 +178,7 @@ public final class MachineType extends Resource {
private Integer maximumPersistentDisks;
private Long maximumPersistentDisksSizeGb;
private String zone;
private Deprecated deprecated;
/**
* @see MachineType#getGuestCpus()
@ -228,6 +244,14 @@ public final class MachineType extends Resource {
return this;
}
/**
* @see MachineType#getDeprecated()
*/
public Builder deprecated(Deprecated deprecated) {
this.deprecated = deprecated;
return this;
}
@Override
protected Builder self() {
return this;
@ -236,15 +260,15 @@ public final class MachineType extends Resource {
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());
}
}

View File

@ -16,23 +16,65 @@
*/
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;
@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)
*/