JCLOUDS-1463: Do not return MachineTypes from zones that are not available for deploy

This commit is contained in:
Ignasi Barrera 2018-10-23 22:04:36 +02:00
parent 767240f360
commit 9dd50b39c9
3 changed files with 29 additions and 3 deletions

View File

@ -18,12 +18,15 @@ package org.jclouds.googlecomputeengine.compute;
import static com.google.common.base.Preconditions.checkNotNull;
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.transform;
import static java.lang.String.format;
import static org.jclouds.googlecloud.internal.ListPages.concat;
import static org.jclouds.googlecomputeengine.compute.domain.internal.RegionAndName.fromRegionAndName;
import static org.jclouds.googlecomputeengine.compute.strategy.CreateNodesWithGroupEncodedIntoNameThenAddToSet.nameFromNetworkString;
import static org.jclouds.googlecomputeengine.config.GoogleComputeEngineProperties.IMAGE_PROJECTS;
import static org.jclouds.location.predicates.LocationPredicates.isZone;
import java.net.URI;
import java.util.List;
@ -216,10 +219,17 @@ public final class GoogleComputeEngineServiceAdapter
}
@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>() {
@Override
public boolean apply(MachineType input) {
return input.deprecated() == null;
return input.deprecated() == null && contains(zones, input.zone());
}
});
}

View File

@ -47,6 +47,7 @@ public class GoogleComputeEngineServiceMockTest extends BaseGoogleComputeEngineA
server.enqueue(singleRegionSingleZoneResponse());
server.enqueue(jsonResponse("/image_list.json"));
server.enqueue(jsonResponse("/image_list_debian.json")); // per IMAGE_PROJECTS = "debian-cloud"
server.enqueue(singleRegionSingleZoneResponse());
server.enqueue(jsonResponse("/aggregated_machinetype_list.json"));
ComputeService computeService = computeService();
@ -60,7 +61,7 @@ public class GoogleComputeEngineServiceMockTest extends BaseGoogleComputeEngineA
Hardware fastest = computeService.templateBuilder().fastest().build().getHardware();
assertNotNull(fastest);
assertEquals(computeService.listHardwareProfiles().size(), 3);
assertEquals(computeService.listHardwareProfiles().size(), 2);
Template toMatch = computeService.templateBuilder().imageId(template.getImage().getId()).build();
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/global/images");
assertSent(server, "GET", "/projects/debian-cloud/global/images");
assertSent(server, "GET", "/projects/party/regions");
assertSent(server, "GET", "/projects/party/aggregated/machineTypes");
}
@ -76,6 +78,7 @@ public class GoogleComputeEngineServiceMockTest extends BaseGoogleComputeEngineA
server.enqueue(singleRegionSingleZoneResponse());
server.enqueue(jsonResponse("/disk_get_with_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("/operation.json")); // instance delete
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/zones/us-central1-a/disks/test");
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, "DELETE", "/jclouds/zones/us-central1-a/instances/test-delete-1"); // instance delete
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(jsonResponse("/disk_get_with_source_image.json"));
server.enqueue(jsonResponse("/image_get_for_source_image.json"));
server.enqueue(singleRegionSingleZoneResponse());
server.enqueue(jsonResponse("/aggregated_machinetype_list.json"));
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/zones/us-central1-a/disks/test");
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");
}
@ -152,6 +158,7 @@ public class GoogleComputeEngineServiceMockTest extends BaseGoogleComputeEngineA
server.enqueue(aggregatedListWithInstanceNetworkAndStatus("test-0", "test-network", RUNNING));
server.enqueue(singleRegionSingleZoneResponse());
server.enqueue(jsonResponse("/disk_get_with_source_snapshot.json"));
server.enqueue(singleRegionSingleZoneResponse());
server.enqueue(jsonResponse("/aggregated_machinetype_list.json"));
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/regions");
assertSent(server, "GET", "/projects/party/zones/us-central1-a/disks/test");
assertSent(server, "GET", "/projects/party/regions");
assertSent(server, "GET", "/projects/party/aggregated/machineTypes");
}
@ -171,6 +179,7 @@ public class GoogleComputeEngineServiceMockTest extends BaseGoogleComputeEngineA
server.enqueue(singleRegionSingleZoneResponse());
server.enqueue(jsonResponse("/image_list.json"));
server.enqueue(jsonResponse("/image_list_debian.json")); // per IMAGE_PROJECTS = "debian-cloud"
server.enqueue(singleRegionSingleZoneResponse());
server.enqueue(jsonResponse("/aggregated_machinetype_list.json"));
server.enqueue(new MockResponse().setResponseCode(404)); // Get Subnet
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/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/regions/us-central1/subnetworks/default");
assertSent(server, "GET", "/projects/party/global/networks/default");
@ -219,6 +229,7 @@ public class GoogleComputeEngineServiceMockTest extends BaseGoogleComputeEngineA
server.enqueue(singleRegionSingleZoneResponse());
server.enqueue(jsonResponse("/image_list.json"));
server.enqueue(jsonResponse("/image_list_debian.json")); // per IMAGE_PROJECTS = "debian-cloud"
server.enqueue(singleRegionSingleZoneResponse());
server.enqueue(jsonResponse("/aggregated_machinetype_list.json"));
server.enqueue(new MockResponse().setResponseCode(404)); // Get Subnet
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/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/regions/us-central1/subnetworks/default");
assertSent(server, "GET", "/projects/party/global/networks/default");
@ -271,6 +283,7 @@ public class GoogleComputeEngineServiceMockTest extends BaseGoogleComputeEngineA
server.enqueue(singleRegionSingleZoneResponse());
server.enqueue(jsonResponse("/image_list.json"));
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("/subnetwork_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/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/regions/us-central1/subnetworks/jclouds-test");
assertSent(server, "GET", "/projects/party/global/networks/mynetwork");
@ -323,6 +337,7 @@ public class GoogleComputeEngineServiceMockTest extends BaseGoogleComputeEngineA
server.enqueue(singleRegionSingleZoneResponse());
server.enqueue(jsonResponse("/image_list.json"));
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("/subnetwork_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/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/regions/us-central1/subnetworks/jclouds-test");
assertSent(server, "GET", "/projects/party/global/networks/mynetwork");

View File

@ -50,7 +50,7 @@
],
"maximumPersistentDisks": 16,
"maximumPersistentDisksSizeGb": "1024",
"zone": "us-central1-a"
"zone": "asia-east2-a"
}
]
}