mirror of https://github.com/apache/jclouds.git
[JCLOUDS-550] fix for obsolete machineTypes
This commit is contained in:
parent
40b65c5d39
commit
8fd946c93d
|
@ -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.domain.Instance.NetworkInterface.AccessConfig.Type;
|
||||||
import static org.jclouds.googlecomputeengine.predicates.InstancePredicates.isBootDisk;
|
import static org.jclouds.googlecomputeengine.predicates.InstancePredicates.isBootDisk;
|
||||||
import static org.jclouds.util.Predicates2.retry;
|
import static org.jclouds.util.Predicates2.retry;
|
||||||
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -260,6 +259,12 @@ public class GoogleComputeEngineServiceAdapter implements ComputeServiceAdapter<
|
||||||
builder.addAll(api.getMachineTypeApiForProject(userProject.get())
|
builder.addAll(api.getMachineTypeApiForProject(userProject.get())
|
||||||
.listInZone(zone.getId())
|
.listInZone(zone.getId())
|
||||||
.concat()
|
.concat()
|
||||||
|
.filter(new Predicate<MachineType>() {
|
||||||
|
@Override
|
||||||
|
public boolean apply(MachineType input) {
|
||||||
|
return !input.getDeprecated().isPresent();
|
||||||
|
}
|
||||||
|
})
|
||||||
.transform(new Function<MachineType, MachineTypeInZone>() {
|
.transform(new Function<MachineType, MachineTypeInZone>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -285,7 +290,7 @@ public class GoogleComputeEngineServiceAdapter implements ComputeServiceAdapter<
|
||||||
public Image getImage(String id) {
|
public Image getImage(String id) {
|
||||||
return Objects.firstNonNull(api.getImageApiForProject(userProject.get()).get(id),
|
return Objects.firstNonNull(api.getImageApiForProject(userProject.get()).get(id),
|
||||||
Objects.firstNonNull(api.getImageApiForProject(DEBIAN_PROJECT).get(id),
|
Objects.firstNonNull(api.getImageApiForProject(DEBIAN_PROJECT).get(id),
|
||||||
api.getImageApiForProject(CENTOS_PROJECT).get(id)));
|
api.getImageApiForProject(CENTOS_PROJECT).get(id)));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -98,8 +98,7 @@ public class InstanceInZoneToNodeMetadata implements Function<InstanceInZone, No
|
||||||
.providerId(input.getId())
|
.providerId(input.getId())
|
||||||
.hostname(input.getName())
|
.hostname(input.getName())
|
||||||
.location(checkNotNull(locations.get().get(input.getZone()), "location for %s", input.getZone()))
|
.location(checkNotNull(locations.get().get(input.getZone()), "location for %s", input.getZone()))
|
||||||
.hardware(checkNotNull(hardwares.get().get(input.getMachineType()), "hardware type for %s",
|
.hardware(hardwares.get().get(input.getMachineType()))
|
||||||
input.getMachineType().toString()))
|
|
||||||
.status(toPortableNodeStatus.get(input.getStatus()))
|
.status(toPortableNodeStatus.get(input.getStatus()))
|
||||||
.tags(tags)
|
.tags(tags)
|
||||||
.uri(input.getSelfLink())
|
.uri(input.getSelfLink())
|
||||||
|
|
|
@ -18,15 +18,18 @@ package org.jclouds.googlecomputeengine.domain;
|
||||||
|
|
||||||
import static com.google.common.base.Objects.equal;
|
import static com.google.common.base.Objects.equal;
|
||||||
import static com.google.common.base.Objects.toStringHelper;
|
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 static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
import java.beans.ConstructorProperties;
|
import java.beans.ConstructorProperties;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.jclouds.javax.annotation.Nullable;
|
||||||
|
|
||||||
import com.google.common.annotations.Beta;
|
import com.google.common.annotations.Beta;
|
||||||
import com.google.common.base.Objects;
|
import com.google.common.base.Objects;
|
||||||
|
import com.google.common.base.Optional;
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -44,14 +47,17 @@ public final class MachineType extends Resource {
|
||||||
private final Integer maximumPersistentDisks;
|
private final Integer maximumPersistentDisks;
|
||||||
private final Long maximumPersistentDisksSizeGb;
|
private final Long maximumPersistentDisksSizeGb;
|
||||||
private final String zone;
|
private final String zone;
|
||||||
|
private final Optional<Deprecated> deprecated;
|
||||||
|
|
||||||
@ConstructorProperties({
|
@ConstructorProperties({
|
||||||
"id", "creationTimestamp", "selfLink", "name", "description", "guestCpus", "memoryMb",
|
"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,
|
private MachineType(String id, Date creationTimestamp, URI selfLink, String name, String description,
|
||||||
int guestCpus, int memoryMb, int imageSpaceGb, List<ScratchDisk> scratchDisks,
|
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);
|
super(Kind.MACHINE_TYPE, id, creationTimestamp, selfLink, name, description);
|
||||||
this.guestCpus = checkNotNull(guestCpus, "guestCpus of %s", name);
|
this.guestCpus = checkNotNull(guestCpus, "guestCpus of %s", name);
|
||||||
this.memoryMb = checkNotNull(memoryMb, "memoryMb 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.maximumPersistentDisks = checkNotNull(maximumPersistentDisks, "maximumPersistentDisks of %s", name);
|
||||||
this.maximumPersistentDisksSizeGb = maximumPersistentDisksSizeGb;
|
this.maximumPersistentDisksSizeGb = maximumPersistentDisksSizeGb;
|
||||||
this.zone = checkNotNull(zone, "zone of %s", name);
|
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 zone;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the deprecation information for this machine type
|
||||||
|
*/
|
||||||
|
public Optional<Deprecated> getDeprecated() {
|
||||||
|
return deprecated;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
|
@ -135,7 +149,8 @@ public final class MachineType extends Resource {
|
||||||
.add("scratchDisks", scratchDisks)
|
.add("scratchDisks", scratchDisks)
|
||||||
.add("maximumPersistentDisks", maximumPersistentDisks)
|
.add("maximumPersistentDisks", maximumPersistentDisks)
|
||||||
.add("maximumPersistentDisksSizeGb", maximumPersistentDisksSizeGb)
|
.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 Integer maximumPersistentDisks;
|
||||||
private Long maximumPersistentDisksSizeGb;
|
private Long maximumPersistentDisksSizeGb;
|
||||||
private String zone;
|
private String zone;
|
||||||
|
private Deprecated deprecated;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see MachineType#getGuestCpus()
|
* @see MachineType#getGuestCpus()
|
||||||
|
@ -228,6 +244,14 @@ public final class MachineType extends Resource {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see MachineType#getDeprecated()
|
||||||
|
*/
|
||||||
|
public Builder deprecated(Deprecated deprecated) {
|
||||||
|
this.deprecated = deprecated;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Builder self() {
|
protected Builder self() {
|
||||||
return this;
|
return this;
|
||||||
|
@ -236,15 +260,15 @@ public final class MachineType extends Resource {
|
||||||
public MachineType build() {
|
public MachineType build() {
|
||||||
return new MachineType(id, creationTimestamp, selfLink, name, description, guestCpus, memoryMb,
|
return new MachineType(id, creationTimestamp, selfLink, name, description, guestCpus, memoryMb,
|
||||||
imageSpaceGb, scratchDisks.build(), maximumPersistentDisks, maximumPersistentDisksSizeGb,
|
imageSpaceGb, scratchDisks.build(), maximumPersistentDisks, maximumPersistentDisksSizeGb,
|
||||||
zone);
|
zone, deprecated);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Builder fromMachineType(MachineType in) {
|
public Builder fromMachineType(MachineType in) {
|
||||||
return super.fromResource(in).memoryMb(in.getMemoryMb()).imageSpaceGb(in.getImageSpaceGb()).scratchDisks(in
|
return super.fromResource(in).memoryMb(in.getMemoryMb()).imageSpaceGb(in.getImageSpaceGb()).scratchDisks(in
|
||||||
.getScratchDisks()).maximumPersistentDisks(in.getMaximumPersistentDisks())
|
.getScratchDisks()).maximumPersistentDisks(in.getMaximumPersistentDisks())
|
||||||
.maximumPersistentDisksSizeGb(in.getMaximumPersistentDisksSizeGb()).zone(in
|
.maximumPersistentDisksSizeGb(in.getMaximumPersistentDisksSizeGb()).zone(in.getZone())
|
||||||
.getZone());
|
.deprecated(in.getDeprecated().orNull());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,23 +16,65 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.googlecomputeengine.compute;
|
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 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.domain.NodeMetadata;
|
||||||
import org.jclouds.compute.internal.BaseComputeServiceLiveTest;
|
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.jclouds.sshj.config.SshjSshClientModule;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
import com.google.common.base.Supplier;
|
||||||
import com.google.common.collect.ImmutableMap;
|
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.Module;
|
||||||
|
import com.google.inject.TypeLiteral;
|
||||||
|
|
||||||
@Test(groups = "live", singleThreaded = true)
|
@Test(groups = "live", singleThreaded = true)
|
||||||
public class GoogleComputeEngineServiceLiveTest extends BaseComputeServiceLiveTest {
|
public class GoogleComputeEngineServiceLiveTest extends BaseComputeServiceLiveTest {
|
||||||
|
|
||||||
|
protected static final String DEFAULT_ZONE_NAME = "us-central1-a";
|
||||||
|
|
||||||
public GoogleComputeEngineServiceLiveTest() {
|
public GoogleComputeEngineServiceLiveTest() {
|
||||||
provider = "google-compute-engine";
|
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)
|
* Nodes may have additional metadata entries (particularly they may have an "sshKeys" entry)
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue