Repository: jclouds Updated Branches: refs/heads/master af077af2d -> d2f566d72
Consider the zone id filter in the location supplier Project: http://git-wip-us.apache.org/repos/asf/jclouds/repo Commit: http://git-wip-us.apache.org/repos/asf/jclouds/commit/d2f566d7 Tree: http://git-wip-us.apache.org/repos/asf/jclouds/tree/d2f566d7 Diff: http://git-wip-us.apache.org/repos/asf/jclouds/diff/d2f566d7 Branch: refs/heads/master Commit: d2f566d7255ff1c62dfd9bbbf59a73236bbb2578 Parents: af077af Author: Ignasi Barrera <[email protected]> Authored: Fri Apr 13 09:24:40 2018 +0200 Committer: Ignasi Barrera <[email protected]> Committed: Tue Apr 17 10:41:11 2018 +0200 ---------------------------------------------------------------------- .../ZoneToRegionToProviderOrJustProvider.java | 5 +- ...oneToRegionToProviderOrJustProviderTest.java | 82 ++++++++++++++++++++ 2 files changed, 86 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/jclouds/blob/d2f566d7/core/src/main/java/org/jclouds/location/suppliers/all/ZoneToRegionToProviderOrJustProvider.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/jclouds/location/suppliers/all/ZoneToRegionToProviderOrJustProvider.java b/core/src/main/java/org/jclouds/location/suppliers/all/ZoneToRegionToProviderOrJustProvider.java index a657636..339216a 100644 --- a/core/src/main/java/org/jclouds/location/suppliers/all/ZoneToRegionToProviderOrJustProvider.java +++ b/core/src/main/java/org/jclouds/location/suppliers/all/ZoneToRegionToProviderOrJustProvider.java @@ -113,7 +113,10 @@ public class ZoneToRegionToProviderOrJustProvider implements LocationsSupplier { provider = region.getParent(); if (regionIdToZoneIds.containsKey(region.getId())) { for (String zoneId : regionIdToZoneIds.get(region.getId()).get()) - zoneIdToParent.put(zoneId, region); + // Just consider the zones provided by the zone supplier (zones can be filtered) + if (zoneIds.contains(zoneId)) { + zoneIdToParent.put(zoneId, region); + } } else { logger.debug("no zones configured for region: %s", region); } http://git-wip-us.apache.org/repos/asf/jclouds/blob/d2f566d7/core/src/test/java/org/jclouds/location/suppliers/all/ZoneToRegionToProviderOrJustProviderTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/jclouds/location/suppliers/all/ZoneToRegionToProviderOrJustProviderTest.java b/core/src/test/java/org/jclouds/location/suppliers/all/ZoneToRegionToProviderOrJustProviderTest.java new file mode 100644 index 0000000..8d2d72a --- /dev/null +++ b/core/src/test/java/org/jclouds/location/suppliers/all/ZoneToRegionToProviderOrJustProviderTest.java @@ -0,0 +1,82 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.location.suppliers.all; + +import static org.testng.Assert.assertEquals; + +import java.net.URI; +import java.util.Map; +import java.util.Set; + +import org.jclouds.domain.Location; +import org.jclouds.domain.LocationBuilder; +import org.jclouds.domain.LocationScope; +import org.testng.annotations.Test; + +import com.google.common.base.Supplier; +import com.google.common.base.Suppliers; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; + +@Test(groups = "unit", testName = "ZoneToRegionToProviderOrJustProviderTest") +public class ZoneToRegionToProviderOrJustProviderTest { + Location provider = new LocationBuilder().scope(LocationScope.PROVIDER).id("provider").description("provider") + .iso3166Codes(ImmutableSet.of("US")).build(); + JustProvider justProvider = new JustProvider("provider", Suppliers.ofInstance(URI.create("http://localhost")), ImmutableSet.of("US")); + + Supplier<Map<String, Supplier<Set<String>>>> regionToZones = Suppliers.<Map<String, Supplier<Set<String>>>>ofInstance( + ImmutableMap.of( + "region1", Suppliers.<Set<String>>ofInstance(ImmutableSet.of("zone1")), + "region2", Suppliers.<Set<String>>ofInstance(ImmutableSet.of("zone2", "zone3")) + )); + Supplier<Map<String, Supplier<Set<String>>>> locationToIsoCodes = Suppliers.<Map<String, Supplier<Set<String>>>>ofInstance( + ImmutableMap.of( + "region1", Suppliers.<Set<String>>ofInstance(ImmutableSet.of("US")), + "region2", Suppliers.<Set<String>>ofInstance(ImmutableSet.of("US")), + "zone1", Suppliers.<Set<String>>ofInstance(ImmutableSet.of("US-CA")), + "zone2", Suppliers.<Set<String>>ofInstance(ImmutableSet.of("US-VA")), + "zone3", Suppliers.<Set<String>>ofInstance(ImmutableSet.of("US-AK")) + )); + + Location region1 = new LocationBuilder().scope(LocationScope.REGION).id("region1").description("region1").iso3166Codes(ImmutableSet.of("US")).parent(provider).build(); + Location region2 = new LocationBuilder().scope(LocationScope.REGION).id("region2").description("region2").iso3166Codes(ImmutableSet.of("US")).parent(provider).build(); + Location zone1 = new LocationBuilder().scope(LocationScope.ZONE).id("zone1").description("zone1").iso3166Codes(ImmutableSet.of("US-CA")).parent(region1).build(); + Location zone2 = new LocationBuilder().scope(LocationScope.ZONE).id("zone2").description("zone2").iso3166Codes(ImmutableSet.of("US-VA")).parent(region2).build(); + Location zone3 = new LocationBuilder().scope(LocationScope.ZONE).id("zone3").description("zone3").iso3166Codes(ImmutableSet.of("US-AK")).parent(region2).build(); + + @Test + public void testGetAll() { + Supplier<Set<String>> regionIdsSupplier = Suppliers.<Set<String>> ofInstance(ImmutableSet.of("region1", "region2")); + Supplier<Set<String>> zoneIdsSupplier = Suppliers.<Set<String>> ofInstance(ImmutableSet.of("zone1", "zone2", "zone3")); + + RegionToProviderOrJustProvider regionToProviderOrJustProvider = new RegionToProviderOrJustProvider(justProvider, regionIdsSupplier, locationToIsoCodes); + ZoneToRegionToProviderOrJustProvider fn = new ZoneToRegionToProviderOrJustProvider(regionToProviderOrJustProvider, zoneIdsSupplier, locationToIsoCodes, regionToZones); + + assertEquals(fn.get(), ImmutableSet.of(region1, region2, zone1, zone2, zone3)); + } + + @Test + public void testRegionAndZoneFilter() { + Supplier<Set<String>> regionIdsSupplier = Suppliers.<Set<String>> ofInstance(ImmutableSet.of("region2")); + Supplier<Set<String>> zoneIdsSupplier = Suppliers.<Set<String>> ofInstance(ImmutableSet.<String> of("zone2")); + + RegionToProviderOrJustProvider regionToProviderOrJustProvider = new RegionToProviderOrJustProvider(justProvider, regionIdsSupplier, locationToIsoCodes); + ZoneToRegionToProviderOrJustProvider fn = new ZoneToRegionToProviderOrJustProvider(regionToProviderOrJustProvider, zoneIdsSupplier, locationToIsoCodes, regionToZones); + + assertEquals(fn.get(), ImmutableSet.of(region2, zone2)); + } +}
