mirror of https://github.com/apache/jclouds.git
JCLOUDS-1463: Do not return MachineTypes from zones that are not available for deploy
This commit is contained in:
parent
9142af74b8
commit
53c011a3bc
|
@ -18,12 +18,15 @@ package org.jclouds.googlecomputeengine.compute;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
import static com.google.common.base.Preconditions.checkState;
|
import static com.google.common.base.Preconditions.checkState;
|
||||||
|
import static com.google.common.collect.Iterables.contains;
|
||||||
import static com.google.common.collect.Iterables.filter;
|
import static com.google.common.collect.Iterables.filter;
|
||||||
|
import static com.google.common.collect.Iterables.transform;
|
||||||
import static java.lang.String.format;
|
import static java.lang.String.format;
|
||||||
import static org.jclouds.googlecloud.internal.ListPages.concat;
|
import static org.jclouds.googlecloud.internal.ListPages.concat;
|
||||||
import static org.jclouds.googlecomputeengine.compute.domain.internal.RegionAndName.fromRegionAndName;
|
import static org.jclouds.googlecomputeengine.compute.domain.internal.RegionAndName.fromRegionAndName;
|
||||||
import static org.jclouds.googlecomputeengine.compute.strategy.CreateNodesWithGroupEncodedIntoNameThenAddToSet.nameFromNetworkString;
|
import static org.jclouds.googlecomputeengine.compute.strategy.CreateNodesWithGroupEncodedIntoNameThenAddToSet.nameFromNetworkString;
|
||||||
import static org.jclouds.googlecomputeengine.config.GoogleComputeEngineProperties.IMAGE_PROJECTS;
|
import static org.jclouds.googlecomputeengine.config.GoogleComputeEngineProperties.IMAGE_PROJECTS;
|
||||||
|
import static org.jclouds.location.predicates.LocationPredicates.isZone;
|
||||||
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -216,10 +219,17 @@ public final class GoogleComputeEngineServiceAdapter
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public Iterable<MachineType> listHardwareProfiles() {
|
@Override public Iterable<MachineType> listHardwareProfiles() {
|
||||||
|
// JCLOUDS-1463: Only return the machine types that belong to zones that are actually available
|
||||||
|
final Iterable<String> zones = transform(filter(listLocations(), isZone()), new Function<Location, String>() {
|
||||||
|
public String apply(Location input) {
|
||||||
|
return input.getId();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
return filter(concat(api.aggregatedList().machineTypes()), new Predicate<MachineType>() {
|
return filter(concat(api.aggregatedList().machineTypes()), new Predicate<MachineType>() {
|
||||||
@Override
|
@Override
|
||||||
public boolean apply(MachineType input) {
|
public boolean apply(MachineType input) {
|
||||||
return input.deprecated() == null;
|
return input.deprecated() == null && contains(zones, input.zone());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,6 +47,7 @@ public class GoogleComputeEngineServiceMockTest extends BaseGoogleComputeEngineA
|
||||||
server.enqueue(singleRegionSingleZoneResponse());
|
server.enqueue(singleRegionSingleZoneResponse());
|
||||||
server.enqueue(jsonResponse("/image_list.json"));
|
server.enqueue(jsonResponse("/image_list.json"));
|
||||||
server.enqueue(jsonResponse("/image_list_debian.json")); // per IMAGE_PROJECTS = "debian-cloud"
|
server.enqueue(jsonResponse("/image_list_debian.json")); // per IMAGE_PROJECTS = "debian-cloud"
|
||||||
|
server.enqueue(singleRegionSingleZoneResponse());
|
||||||
server.enqueue(jsonResponse("/aggregated_machinetype_list.json"));
|
server.enqueue(jsonResponse("/aggregated_machinetype_list.json"));
|
||||||
|
|
||||||
ComputeService computeService = computeService();
|
ComputeService computeService = computeService();
|
||||||
|
@ -60,7 +61,7 @@ public class GoogleComputeEngineServiceMockTest extends BaseGoogleComputeEngineA
|
||||||
Hardware fastest = computeService.templateBuilder().fastest().build().getHardware();
|
Hardware fastest = computeService.templateBuilder().fastest().build().getHardware();
|
||||||
assertNotNull(fastest);
|
assertNotNull(fastest);
|
||||||
|
|
||||||
assertEquals(computeService.listHardwareProfiles().size(), 3);
|
assertEquals(computeService.listHardwareProfiles().size(), 2);
|
||||||
|
|
||||||
Template toMatch = computeService.templateBuilder().imageId(template.getImage().getId()).build();
|
Template toMatch = computeService.templateBuilder().imageId(template.getImage().getId()).build();
|
||||||
assertEquals(toMatch.getImage(), template.getImage());
|
assertEquals(toMatch.getImage(), template.getImage());
|
||||||
|
@ -68,6 +69,7 @@ public class GoogleComputeEngineServiceMockTest extends BaseGoogleComputeEngineA
|
||||||
assertSent(server, "GET", "/projects/party/regions");
|
assertSent(server, "GET", "/projects/party/regions");
|
||||||
assertSent(server, "GET", "/projects/party/global/images");
|
assertSent(server, "GET", "/projects/party/global/images");
|
||||||
assertSent(server, "GET", "/projects/debian-cloud/global/images");
|
assertSent(server, "GET", "/projects/debian-cloud/global/images");
|
||||||
|
assertSent(server, "GET", "/projects/party/regions");
|
||||||
assertSent(server, "GET", "/projects/party/aggregated/machineTypes");
|
assertSent(server, "GET", "/projects/party/aggregated/machineTypes");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,6 +78,7 @@ public class GoogleComputeEngineServiceMockTest extends BaseGoogleComputeEngineA
|
||||||
server.enqueue(singleRegionSingleZoneResponse());
|
server.enqueue(singleRegionSingleZoneResponse());
|
||||||
server.enqueue(jsonResponse("/disk_get_with_source_image.json"));
|
server.enqueue(jsonResponse("/disk_get_with_source_image.json"));
|
||||||
server.enqueue(jsonResponse("/image_get_for_source_image.json"));
|
server.enqueue(jsonResponse("/image_get_for_source_image.json"));
|
||||||
|
server.enqueue(singleRegionSingleZoneResponse());
|
||||||
server.enqueue(jsonResponse("/aggregated_machinetype_list.json")); // Why are we getting machineTypes to delete an instance?
|
server.enqueue(jsonResponse("/aggregated_machinetype_list.json")); // Why are we getting machineTypes to delete an instance?
|
||||||
server.enqueue(jsonResponse("/operation.json")); // instance delete
|
server.enqueue(jsonResponse("/operation.json")); // instance delete
|
||||||
server.enqueue(jsonResponse("/zone_operation.json"));
|
server.enqueue(jsonResponse("/zone_operation.json"));
|
||||||
|
@ -92,6 +95,7 @@ public class GoogleComputeEngineServiceMockTest extends BaseGoogleComputeEngineA
|
||||||
assertSent(server, "GET", "/projects/party/regions");
|
assertSent(server, "GET", "/projects/party/regions");
|
||||||
assertSent(server, "GET", "/projects/party/zones/us-central1-a/disks/test");
|
assertSent(server, "GET", "/projects/party/zones/us-central1-a/disks/test");
|
||||||
assertSent(server, "GET", "/projects/debian-cloud/global/images/debian-7-wheezy-v20140718");
|
assertSent(server, "GET", "/projects/debian-cloud/global/images/debian-7-wheezy-v20140718");
|
||||||
|
assertSent(server, "GET", "/projects/party/regions");
|
||||||
assertSent(server, "GET", "/projects/party/aggregated/machineTypes"); // Why are we getting machineTypes to delete an instance?
|
assertSent(server, "GET", "/projects/party/aggregated/machineTypes"); // Why are we getting machineTypes to delete an instance?
|
||||||
assertSent(server, "DELETE", "/jclouds/zones/us-central1-a/instances/test-delete-1"); // instance delete
|
assertSent(server, "DELETE", "/jclouds/zones/us-central1-a/instances/test-delete-1"); // instance delete
|
||||||
assertSent(server, "GET", "/projects/party/zones/us-central1-a/operations/operation-1354084865060");
|
assertSent(server, "GET", "/projects/party/zones/us-central1-a/operations/operation-1354084865060");
|
||||||
|
@ -133,6 +137,7 @@ public class GoogleComputeEngineServiceMockTest extends BaseGoogleComputeEngineA
|
||||||
server.enqueue(singleRegionSingleZoneResponse());
|
server.enqueue(singleRegionSingleZoneResponse());
|
||||||
server.enqueue(jsonResponse("/disk_get_with_source_image.json"));
|
server.enqueue(jsonResponse("/disk_get_with_source_image.json"));
|
||||||
server.enqueue(jsonResponse("/image_get_for_source_image.json"));
|
server.enqueue(jsonResponse("/image_get_for_source_image.json"));
|
||||||
|
server.enqueue(singleRegionSingleZoneResponse());
|
||||||
server.enqueue(jsonResponse("/aggregated_machinetype_list.json"));
|
server.enqueue(jsonResponse("/aggregated_machinetype_list.json"));
|
||||||
|
|
||||||
Set<? extends ComputeMetadata> nodes = computeService().listNodes();
|
Set<? extends ComputeMetadata> nodes = computeService().listNodes();
|
||||||
|
@ -144,6 +149,7 @@ public class GoogleComputeEngineServiceMockTest extends BaseGoogleComputeEngineA
|
||||||
assertSent(server, "GET", "/projects/party/regions");
|
assertSent(server, "GET", "/projects/party/regions");
|
||||||
assertSent(server, "GET", "/projects/party/zones/us-central1-a/disks/test");
|
assertSent(server, "GET", "/projects/party/zones/us-central1-a/disks/test");
|
||||||
assertSent(server, "GET", "/projects/debian-cloud/global/images/debian-7-wheezy-v20140718");
|
assertSent(server, "GET", "/projects/debian-cloud/global/images/debian-7-wheezy-v20140718");
|
||||||
|
assertSent(server, "GET", "/projects/party/regions");
|
||||||
assertSent(server, "GET", "/projects/party/aggregated/machineTypes");
|
assertSent(server, "GET", "/projects/party/aggregated/machineTypes");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -152,6 +158,7 @@ public class GoogleComputeEngineServiceMockTest extends BaseGoogleComputeEngineA
|
||||||
server.enqueue(aggregatedListWithInstanceNetworkAndStatus("test-0", "test-network", RUNNING));
|
server.enqueue(aggregatedListWithInstanceNetworkAndStatus("test-0", "test-network", RUNNING));
|
||||||
server.enqueue(singleRegionSingleZoneResponse());
|
server.enqueue(singleRegionSingleZoneResponse());
|
||||||
server.enqueue(jsonResponse("/disk_get_with_source_snapshot.json"));
|
server.enqueue(jsonResponse("/disk_get_with_source_snapshot.json"));
|
||||||
|
server.enqueue(singleRegionSingleZoneResponse());
|
||||||
server.enqueue(jsonResponse("/aggregated_machinetype_list.json"));
|
server.enqueue(jsonResponse("/aggregated_machinetype_list.json"));
|
||||||
|
|
||||||
Set<? extends ComputeMetadata> nodes = computeService().listNodes();
|
Set<? extends ComputeMetadata> nodes = computeService().listNodes();
|
||||||
|
@ -162,6 +169,7 @@ public class GoogleComputeEngineServiceMockTest extends BaseGoogleComputeEngineA
|
||||||
assertSent(server, "GET", "/projects/party/aggregated/instances");
|
assertSent(server, "GET", "/projects/party/aggregated/instances");
|
||||||
assertSent(server, "GET", "/projects/party/regions");
|
assertSent(server, "GET", "/projects/party/regions");
|
||||||
assertSent(server, "GET", "/projects/party/zones/us-central1-a/disks/test");
|
assertSent(server, "GET", "/projects/party/zones/us-central1-a/disks/test");
|
||||||
|
assertSent(server, "GET", "/projects/party/regions");
|
||||||
assertSent(server, "GET", "/projects/party/aggregated/machineTypes");
|
assertSent(server, "GET", "/projects/party/aggregated/machineTypes");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -171,6 +179,7 @@ public class GoogleComputeEngineServiceMockTest extends BaseGoogleComputeEngineA
|
||||||
server.enqueue(singleRegionSingleZoneResponse());
|
server.enqueue(singleRegionSingleZoneResponse());
|
||||||
server.enqueue(jsonResponse("/image_list.json"));
|
server.enqueue(jsonResponse("/image_list.json"));
|
||||||
server.enqueue(jsonResponse("/image_list_debian.json")); // per IMAGE_PROJECTS = "debian-cloud"
|
server.enqueue(jsonResponse("/image_list_debian.json")); // per IMAGE_PROJECTS = "debian-cloud"
|
||||||
|
server.enqueue(singleRegionSingleZoneResponse());
|
||||||
server.enqueue(jsonResponse("/aggregated_machinetype_list.json"));
|
server.enqueue(jsonResponse("/aggregated_machinetype_list.json"));
|
||||||
server.enqueue(new MockResponse().setResponseCode(404)); // Get Subnet
|
server.enqueue(new MockResponse().setResponseCode(404)); // Get Subnet
|
||||||
server.enqueue(jsonResponse("/network_get_default.json"));
|
server.enqueue(jsonResponse("/network_get_default.json"));
|
||||||
|
@ -198,6 +207,7 @@ public class GoogleComputeEngineServiceMockTest extends BaseGoogleComputeEngineA
|
||||||
assertSent(server, "GET", "/projects/party/regions");
|
assertSent(server, "GET", "/projects/party/regions");
|
||||||
assertSent(server, "GET", "/projects/party/global/images");
|
assertSent(server, "GET", "/projects/party/global/images");
|
||||||
assertSent(server, "GET", "/projects/debian-cloud/global/images");
|
assertSent(server, "GET", "/projects/debian-cloud/global/images");
|
||||||
|
assertSent(server, "GET", "/projects/party/regions");
|
||||||
assertSent(server, "GET", "/projects/party/aggregated/machineTypes");
|
assertSent(server, "GET", "/projects/party/aggregated/machineTypes");
|
||||||
assertSent(server, "GET", "/projects/party/regions/us-central1/subnetworks/default");
|
assertSent(server, "GET", "/projects/party/regions/us-central1/subnetworks/default");
|
||||||
assertSent(server, "GET", "/projects/party/global/networks/default");
|
assertSent(server, "GET", "/projects/party/global/networks/default");
|
||||||
|
@ -219,6 +229,7 @@ public class GoogleComputeEngineServiceMockTest extends BaseGoogleComputeEngineA
|
||||||
server.enqueue(singleRegionSingleZoneResponse());
|
server.enqueue(singleRegionSingleZoneResponse());
|
||||||
server.enqueue(jsonResponse("/image_list.json"));
|
server.enqueue(jsonResponse("/image_list.json"));
|
||||||
server.enqueue(jsonResponse("/image_list_debian.json")); // per IMAGE_PROJECTS = "debian-cloud"
|
server.enqueue(jsonResponse("/image_list_debian.json")); // per IMAGE_PROJECTS = "debian-cloud"
|
||||||
|
server.enqueue(singleRegionSingleZoneResponse());
|
||||||
server.enqueue(jsonResponse("/aggregated_machinetype_list.json"));
|
server.enqueue(jsonResponse("/aggregated_machinetype_list.json"));
|
||||||
server.enqueue(new MockResponse().setResponseCode(404)); // Get Subnet
|
server.enqueue(new MockResponse().setResponseCode(404)); // Get Subnet
|
||||||
server.enqueue(jsonResponse("/network_get_default.json"));
|
server.enqueue(jsonResponse("/network_get_default.json"));
|
||||||
|
@ -249,6 +260,7 @@ public class GoogleComputeEngineServiceMockTest extends BaseGoogleComputeEngineA
|
||||||
assertSent(server, "GET", "/projects/party/regions");
|
assertSent(server, "GET", "/projects/party/regions");
|
||||||
assertSent(server, "GET", "/projects/party/global/images");
|
assertSent(server, "GET", "/projects/party/global/images");
|
||||||
assertSent(server, "GET", "/projects/debian-cloud/global/images");
|
assertSent(server, "GET", "/projects/debian-cloud/global/images");
|
||||||
|
assertSent(server, "GET", "/projects/party/regions");
|
||||||
assertSent(server, "GET", "/projects/party/aggregated/machineTypes");
|
assertSent(server, "GET", "/projects/party/aggregated/machineTypes");
|
||||||
assertSent(server, "GET", "/projects/party/regions/us-central1/subnetworks/default");
|
assertSent(server, "GET", "/projects/party/regions/us-central1/subnetworks/default");
|
||||||
assertSent(server, "GET", "/projects/party/global/networks/default");
|
assertSent(server, "GET", "/projects/party/global/networks/default");
|
||||||
|
@ -271,6 +283,7 @@ public class GoogleComputeEngineServiceMockTest extends BaseGoogleComputeEngineA
|
||||||
server.enqueue(singleRegionSingleZoneResponse());
|
server.enqueue(singleRegionSingleZoneResponse());
|
||||||
server.enqueue(jsonResponse("/image_list.json"));
|
server.enqueue(jsonResponse("/image_list.json"));
|
||||||
server.enqueue(jsonResponse("/image_list_debian.json")); // per IMAGE_PROJECTS = "debian-cloud"
|
server.enqueue(jsonResponse("/image_list_debian.json")); // per IMAGE_PROJECTS = "debian-cloud"
|
||||||
|
server.enqueue(singleRegionSingleZoneResponse());
|
||||||
server.enqueue(jsonResponse("/aggregated_machinetype_list.json"));
|
server.enqueue(jsonResponse("/aggregated_machinetype_list.json"));
|
||||||
server.enqueue(jsonResponse("/subnetwork_get.json"));
|
server.enqueue(jsonResponse("/subnetwork_get.json"));
|
||||||
server.enqueue(jsonResponse("/network_get.json"));
|
server.enqueue(jsonResponse("/network_get.json"));
|
||||||
|
@ -301,6 +314,7 @@ public class GoogleComputeEngineServiceMockTest extends BaseGoogleComputeEngineA
|
||||||
assertSent(server, "GET", "/projects/party/regions");
|
assertSent(server, "GET", "/projects/party/regions");
|
||||||
assertSent(server, "GET", "/projects/party/global/images");
|
assertSent(server, "GET", "/projects/party/global/images");
|
||||||
assertSent(server, "GET", "/projects/debian-cloud/global/images");
|
assertSent(server, "GET", "/projects/debian-cloud/global/images");
|
||||||
|
assertSent(server, "GET", "/projects/party/regions");
|
||||||
assertSent(server, "GET", "/projects/party/aggregated/machineTypes");
|
assertSent(server, "GET", "/projects/party/aggregated/machineTypes");
|
||||||
assertSent(server, "GET", "/projects/party/regions/us-central1/subnetworks/jclouds-test");
|
assertSent(server, "GET", "/projects/party/regions/us-central1/subnetworks/jclouds-test");
|
||||||
assertSent(server, "GET", "/projects/party/global/networks/mynetwork");
|
assertSent(server, "GET", "/projects/party/global/networks/mynetwork");
|
||||||
|
@ -323,6 +337,7 @@ public class GoogleComputeEngineServiceMockTest extends BaseGoogleComputeEngineA
|
||||||
server.enqueue(singleRegionSingleZoneResponse());
|
server.enqueue(singleRegionSingleZoneResponse());
|
||||||
server.enqueue(jsonResponse("/image_list.json"));
|
server.enqueue(jsonResponse("/image_list.json"));
|
||||||
server.enqueue(jsonResponse("/image_list_debian.json")); // per IMAGE_PROJECTS = "debian-cloud"
|
server.enqueue(jsonResponse("/image_list_debian.json")); // per IMAGE_PROJECTS = "debian-cloud"
|
||||||
|
server.enqueue(singleRegionSingleZoneResponse());
|
||||||
server.enqueue(jsonResponse("/aggregated_machinetype_list.json"));
|
server.enqueue(jsonResponse("/aggregated_machinetype_list.json"));
|
||||||
server.enqueue(jsonResponse("/subnetwork_get.json"));
|
server.enqueue(jsonResponse("/subnetwork_get.json"));
|
||||||
server.enqueue(jsonResponse("/network_get.json"));
|
server.enqueue(jsonResponse("/network_get.json"));
|
||||||
|
@ -353,6 +368,7 @@ public class GoogleComputeEngineServiceMockTest extends BaseGoogleComputeEngineA
|
||||||
assertSent(server, "GET", "/projects/party/regions");
|
assertSent(server, "GET", "/projects/party/regions");
|
||||||
assertSent(server, "GET", "/projects/party/global/images");
|
assertSent(server, "GET", "/projects/party/global/images");
|
||||||
assertSent(server, "GET", "/projects/debian-cloud/global/images");
|
assertSent(server, "GET", "/projects/debian-cloud/global/images");
|
||||||
|
assertSent(server, "GET", "/projects/party/regions");
|
||||||
assertSent(server, "GET", "/projects/party/aggregated/machineTypes");
|
assertSent(server, "GET", "/projects/party/aggregated/machineTypes");
|
||||||
assertSent(server, "GET", "/projects/party/regions/us-central1/subnetworks/jclouds-test");
|
assertSent(server, "GET", "/projects/party/regions/us-central1/subnetworks/jclouds-test");
|
||||||
assertSent(server, "GET", "/projects/party/global/networks/mynetwork");
|
assertSent(server, "GET", "/projects/party/global/networks/mynetwork");
|
||||||
|
|
|
@ -50,7 +50,7 @@
|
||||||
],
|
],
|
||||||
"maximumPersistentDisks": 16,
|
"maximumPersistentDisks": 16,
|
||||||
"maximumPersistentDisksSizeGb": "1024",
|
"maximumPersistentDisksSizeGb": "1024",
|
||||||
"zone": "us-central1-a"
|
"zone": "asia-east2-a"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue