From dd89ad3068087df368f569d0af67e007382e2e7f Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Sun, 23 Oct 2011 04:38:25 +0200 Subject: [PATCH] backfilled tests and refactored most of org.jclouds.location.suppliers package --- .../cloudwatch/CloudWatchAsyncClientTest.java | 20 +++- .../EC2BindComputeSuppliersByClass.java | 4 +- .../OrgAndVDCToLocationSupplier.java | 2 +- .../OrgAndVDCToLocationSupplier.java | 2 +- .../config/RegionsLocationModule.java | 4 +- .../location/functions/ToIdAndScope.java | 41 +++++++ .../predicates/LocationPredicates.java | 101 ++++++++++++++++++ .../location/suppliers/JustProvider.java | 6 +- ...irstRegionOptionallyMatchingRegionId.java} | 57 +++------- .../suppliers/OnlyLocationOrFirstZone.java | 34 +++--- .../RegionToProviderOrJustProvider.java | 2 +- .../location/suppliers/JustProviderTest.java | 48 +++++++++ ...tRegionOptionallyMatchingRegionIdTest.java | 94 ++++++++++++++++ .../OnlyLocationOrFirstZoneTest.java | 78 ++++++++++++++ .../BindLoadBalancerSuppliersByClass.java | 4 +- ...stnameAndBindAsHostPrefixIfConfigured.java | 18 ++-- .../jclouds/aws/s3/AWSS3AsyncClientTest.java | 31 +++++- ...meAndBindAsHostPrefixIfConfiguredTest.java | 84 +++++++++++++++ .../CloudLoadBalancersRestClientModule.java | 36 +++++-- ...BaseCloudLoadBalancersAsyncClientTest.java | 20 +++- .../suppliers/GoGridLocationSupplier.java | 2 +- .../RimuHostingLocationSupplier.java | 2 +- .../functions/DatacenterToLocationTest.java | 6 +- 23 files changed, 590 insertions(+), 106 deletions(-) create mode 100644 core/src/main/java/org/jclouds/location/functions/ToIdAndScope.java create mode 100644 core/src/main/java/org/jclouds/location/predicates/LocationPredicates.java rename core/src/main/java/org/jclouds/location/suppliers/{OnlyLocationOrFirstZoneOrRegionMatchingRegionId.java => OnlyLocationOrFirstRegionOptionallyMatchingRegionId.java} (54%) create mode 100644 core/src/test/java/org/jclouds/location/suppliers/JustProviderTest.java create mode 100644 core/src/test/java/org/jclouds/location/suppliers/OnlyLocationOrFirstRegionOptionallyMatchingRegionIdTest.java create mode 100644 core/src/test/java/org/jclouds/location/suppliers/OnlyLocationOrFirstZoneTest.java create mode 100644 providers/aws-s3/src/test/java/org/jclouds/aws/s3/binders/AssignCorrectHostnameAndBindAsHostPrefixIfConfiguredTest.java diff --git a/apis/cloudwatch/src/test/java/org/jclouds/cloudwatch/CloudWatchAsyncClientTest.java b/apis/cloudwatch/src/test/java/org/jclouds/cloudwatch/CloudWatchAsyncClientTest.java index 4ed613b2b7..72b549aed7 100644 --- a/apis/cloudwatch/src/test/java/org/jclouds/cloudwatch/CloudWatchAsyncClientTest.java +++ b/apis/cloudwatch/src/test/java/org/jclouds/cloudwatch/CloudWatchAsyncClientTest.java @@ -22,12 +22,15 @@ import static org.testng.Assert.assertEquals; import java.io.IOException; import java.lang.reflect.Method; +import java.net.URI; import java.util.Date; +import java.util.Map; import java.util.Properties; import javax.inject.Named; import org.jclouds.Constants; +import org.jclouds.aws.domain.Region; import org.jclouds.aws.filters.FormSigner; import org.jclouds.cloudwatch.config.CloudWatchRestClientModule; import org.jclouds.cloudwatch.xml.GetMetricStatisticsResponseHandler; @@ -42,6 +45,7 @@ import org.jclouds.rest.RestContextSpec; import org.jclouds.rest.internal.RestAnnotationProcessor; import org.testng.annotations.Test; +import com.google.common.collect.ImmutableMap; import com.google.inject.Module; import com.google.inject.TypeLiteral; @@ -50,7 +54,8 @@ import com.google.inject.TypeLiteral; * * @author Adrian Cole */ -// NOTE:without testName, this will not call @Before* and fail w/NPE during surefire +// NOTE:without testName, this will not call @Before* and fail w/NPE during +// surefire @Test(groups = "unit", testName = "CloudWatchAsyncClientTest") public class CloudWatchAsyncClientTest extends RestClientTest { @@ -95,6 +100,19 @@ public class CloudWatchAsyncClientTest extends RestClientTest> { + @Override + public Map get() { + return ImmutableMap. of(Region.EU_WEST_1, URI.create("https://ec2.eu-west-1.amazonaws.com"), + Region.US_EAST_1, URI.create("https://ec2.us-east-1.amazonaws.com"), Region.US_WEST_1, + URI.create("https://ec2.us-west-1.amazonaws.com")); + } + } + @Override protected String provideTimeStamp(final DateService dateService, @Named(Constants.PROPERTY_SESSION_INTERVAL) int expiration) { diff --git a/apis/ec2/src/main/java/org/jclouds/ec2/compute/config/EC2BindComputeSuppliersByClass.java b/apis/ec2/src/main/java/org/jclouds/ec2/compute/config/EC2BindComputeSuppliersByClass.java index 2e515e221b..7591ef88ff 100644 --- a/apis/ec2/src/main/java/org/jclouds/ec2/compute/config/EC2BindComputeSuppliersByClass.java +++ b/apis/ec2/src/main/java/org/jclouds/ec2/compute/config/EC2BindComputeSuppliersByClass.java @@ -26,7 +26,7 @@ import org.jclouds.compute.config.BindComputeSuppliersByClass; import org.jclouds.compute.domain.Hardware; import org.jclouds.compute.domain.Image; import org.jclouds.domain.Location; -import org.jclouds.location.suppliers.OnlyLocationOrFirstZoneOrRegionMatchingRegionId; +import org.jclouds.location.suppliers.OnlyLocationOrFirstRegionOptionallyMatchingRegionId; import org.jclouds.location.suppliers.ZoneToRegionToProviderOrJustProvider; import com.google.common.base.Supplier; @@ -46,7 +46,7 @@ public class EC2BindComputeSuppliersByClass extends BindComputeSuppliersByClass @Override protected Class> defineDefaultLocationSupplier() { - return OnlyLocationOrFirstZoneOrRegionMatchingRegionId.class; + return OnlyLocationOrFirstRegionOptionallyMatchingRegionId.class; } @Override diff --git a/apis/vcloud/src/main/java/org/jclouds/vcloud/compute/suppliers/OrgAndVDCToLocationSupplier.java b/apis/vcloud/src/main/java/org/jclouds/vcloud/compute/suppliers/OrgAndVDCToLocationSupplier.java index def06114c8..273a478c03 100644 --- a/apis/vcloud/src/main/java/org/jclouds/vcloud/compute/suppliers/OrgAndVDCToLocationSupplier.java +++ b/apis/vcloud/src/main/java/org/jclouds/vcloud/compute/suppliers/OrgAndVDCToLocationSupplier.java @@ -55,7 +55,7 @@ public class OrgAndVDCToLocationSupplier extends JustProvider { OrgAndVDCToLocationSupplier(@Iso3166 Set isoCodes, @Provider String providerName, @Provider URI endpoint, @org.jclouds.vcloud.endpoints.Org Supplier> orgNameToResource, Supplier> orgNameToVDCResource, @Iso3166 Map> isoCodesById) { - super(isoCodes, providerName, endpoint); + super(providerName, endpoint, isoCodes); this.orgNameToResource = checkNotNull(orgNameToResource, "orgNameToResource"); this.orgNameToVDCResource = checkNotNull(orgNameToVDCResource, "orgNameToVDCResource"); this.isoCodesById = checkNotNull(isoCodesById, "isoCodesById"); diff --git a/common/trmk/src/main/java/org/jclouds/trmk/vcloud_0_8/compute/suppliers/OrgAndVDCToLocationSupplier.java b/common/trmk/src/main/java/org/jclouds/trmk/vcloud_0_8/compute/suppliers/OrgAndVDCToLocationSupplier.java index 5246b9732b..53555388bd 100644 --- a/common/trmk/src/main/java/org/jclouds/trmk/vcloud_0_8/compute/suppliers/OrgAndVDCToLocationSupplier.java +++ b/common/trmk/src/main/java/org/jclouds/trmk/vcloud_0_8/compute/suppliers/OrgAndVDCToLocationSupplier.java @@ -55,7 +55,7 @@ public class OrgAndVDCToLocationSupplier extends JustProvider { OrgAndVDCToLocationSupplier(@Iso3166 Set isoCodes, @Provider String providerName, @Provider URI endpoint, @org.jclouds.trmk.vcloud_0_8.endpoints.Org Supplier> orgNameToResource, Supplier> orgNameToVDCResource, @Iso3166 Map> isoCodesById) { - super(isoCodes, providerName, endpoint); + super(providerName, endpoint, isoCodes); this.orgNameToResource = checkNotNull(orgNameToResource, "orgNameToResource"); this.orgNameToVDCResource = checkNotNull(orgNameToVDCResource, "orgNameToVDCResource"); this.isoCodesById = checkNotNull(isoCodesById, "isoCodesById"); diff --git a/core/src/main/java/org/jclouds/location/config/RegionsLocationModule.java b/core/src/main/java/org/jclouds/location/config/RegionsLocationModule.java index 4ff28bb68d..db5c321656 100644 --- a/core/src/main/java/org/jclouds/location/config/RegionsLocationModule.java +++ b/core/src/main/java/org/jclouds/location/config/RegionsLocationModule.java @@ -21,7 +21,7 @@ package org.jclouds.location.config; import java.util.Set; import org.jclouds.domain.Location; -import org.jclouds.location.suppliers.OnlyLocationOrFirstZoneOrRegionMatchingRegionId; +import org.jclouds.location.suppliers.OnlyLocationOrFirstRegionOptionallyMatchingRegionId; import org.jclouds.location.suppliers.RegionToProviderOrJustProvider; import com.google.common.base.Supplier; @@ -39,7 +39,7 @@ public class RegionsLocationModule extends LocationModule { bind(new TypeLiteral>>() { }).to(RegionToProviderOrJustProvider.class); bind(new TypeLiteral>() { - }).to(OnlyLocationOrFirstZoneOrRegionMatchingRegionId.class); + }).to(OnlyLocationOrFirstRegionOptionallyMatchingRegionId.class); super.configure(); } diff --git a/core/src/main/java/org/jclouds/location/functions/ToIdAndScope.java b/core/src/main/java/org/jclouds/location/functions/ToIdAndScope.java new file mode 100644 index 0000000000..b3030f8a31 --- /dev/null +++ b/core/src/main/java/org/jclouds/location/functions/ToIdAndScope.java @@ -0,0 +1,41 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds 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.functions; + +import org.jclouds.domain.Location; + +import com.google.common.base.Function; + +/** + * + * @author Adrian Cole + * + */ +public enum ToIdAndScope implements Function { + INSTANCE; + @Override + public String apply(Location input) { + return input.getId() + ":" + input.getScope(); + } + + @Override + public String toString() { + return "toIdAndScope()"; + } +} \ No newline at end of file diff --git a/core/src/main/java/org/jclouds/location/predicates/LocationPredicates.java b/core/src/main/java/org/jclouds/location/predicates/LocationPredicates.java new file mode 100644 index 0000000000..f56ca8683f --- /dev/null +++ b/core/src/main/java/org/jclouds/location/predicates/LocationPredicates.java @@ -0,0 +1,101 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds 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.predicates; + +import static com.google.common.base.Preconditions.checkNotNull; + +import javax.inject.Singleton; + +import org.jclouds.domain.Location; +import org.jclouds.domain.LocationScope; + +import com.google.common.base.Predicate; + +/** + * + * @author Adrian Cole + */ +public class LocationPredicates { + + public static Predicate isZone() { + return IsZone.INSTANCE; + } + + @Singleton + static enum IsZone implements Predicate { + INSTANCE; + @Override + public boolean apply(Location input) { + return input.getScope() == LocationScope.ZONE; + } + + @Override + public String toString() { + return "isZone()"; + } + } + + public static Predicate isRegion() { + return IsRegion.INSTANCE; + } + + static enum IsRegion implements Predicate { + INSTANCE; + @Override + public boolean apply(Location input) { + return input.getScope() == LocationScope.REGION; + } + + @Override + public String toString() { + return "isRegion()"; + } + } + + public static Predicate isZoneOrRegionWhereRegionIdEquals(String region) { + return new IsZoneOrRegionWhereRegionIdEquals(region); + } + + static class IsZoneOrRegionWhereRegionIdEquals implements Predicate { + + private final String region; + + IsZoneOrRegionWhereRegionIdEquals(String region) { + this.region = checkNotNull(region, "region"); + } + + @Override + public boolean apply(Location input) { + switch (input.getScope()) { + case ZONE: + return input.getParent().getId().equals(region); + case REGION: + return input.getId().equals(region); + default: + return false; + } + } + + @Override + public String toString() { + return "isRegionAndIdEqualsOrIsZoneParentIdEquals(" + region + ")"; + } + } + +} \ No newline at end of file diff --git a/core/src/main/java/org/jclouds/location/suppliers/JustProvider.java b/core/src/main/java/org/jclouds/location/suppliers/JustProvider.java index 2c4c6403c6..f42551d0a3 100644 --- a/core/src/main/java/org/jclouds/location/suppliers/JustProvider.java +++ b/core/src/main/java/org/jclouds/location/suppliers/JustProvider.java @@ -46,7 +46,7 @@ public class JustProvider implements Supplier> { private final Set isoCodes; @Inject - public JustProvider(@Iso3166 Set isoCodes, @Provider String providerName, @Provider URI endpoint) { + public JustProvider(@Provider String providerName, @Provider URI endpoint, @Iso3166 Set isoCodes) { this.providerName = checkNotNull(providerName, "providerName"); this.endpoint = checkNotNull(endpoint, "endpoint"); this.isoCodes = checkNotNull(isoCodes, "isoCodes"); @@ -54,8 +54,8 @@ public class JustProvider implements Supplier> { @Override public Set get() { - return ImmutableSet.of(new LocationBuilder().scope(LocationScope.PROVIDER).id(providerName).description( - endpoint.toASCIIString()).iso3166Codes(isoCodes).build()); + return ImmutableSet.of(new LocationBuilder().scope(LocationScope.PROVIDER).id(providerName) + .description(endpoint.toASCIIString()).iso3166Codes(isoCodes).build()); } } \ No newline at end of file diff --git a/core/src/main/java/org/jclouds/location/suppliers/OnlyLocationOrFirstZoneOrRegionMatchingRegionId.java b/core/src/main/java/org/jclouds/location/suppliers/OnlyLocationOrFirstRegionOptionallyMatchingRegionId.java similarity index 54% rename from core/src/main/java/org/jclouds/location/suppliers/OnlyLocationOrFirstZoneOrRegionMatchingRegionId.java rename to core/src/main/java/org/jclouds/location/suppliers/OnlyLocationOrFirstRegionOptionallyMatchingRegionId.java index a9a58e4006..56585aeb51 100644 --- a/core/src/main/java/org/jclouds/location/suppliers/OnlyLocationOrFirstZoneOrRegionMatchingRegionId.java +++ b/core/src/main/java/org/jclouds/location/suppliers/OnlyLocationOrFirstRegionOptionallyMatchingRegionId.java @@ -20,10 +20,15 @@ package org.jclouds.location.suppliers; import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.collect.Iterables.getOnlyElement; +import static com.google.common.collect.Iterables.transform; +import static org.jclouds.location.predicates.LocationPredicates.isRegion; +import static org.jclouds.location.predicates.LocationPredicates.isZone; +import static org.jclouds.location.predicates.LocationPredicates.isZoneOrRegionWhereRegionIdEquals; import java.util.NoSuchElementException; import java.util.Set; +import javax.annotation.Nullable; import javax.inject.Inject; import javax.inject.Singleton; @@ -31,53 +36,27 @@ import org.jclouds.collect.Memoized; import org.jclouds.domain.Location; import org.jclouds.domain.LocationScope; import org.jclouds.location.Region; +import org.jclouds.location.functions.ToIdAndScope; import com.google.common.base.Predicate; +import com.google.common.base.Predicates; import com.google.common.base.Supplier; import com.google.common.collect.Iterables; -import com.google.inject.Injector; -import com.google.inject.Key; /** * @author Adrian Cole */ @Singleton -public class OnlyLocationOrFirstZoneOrRegionMatchingRegionId implements Supplier { - @Singleton - public static final class IsRegionAndIdEqualsOrIsZoneParentIdEquals implements Predicate { +public class OnlyLocationOrFirstRegionOptionallyMatchingRegionId implements Supplier { - private final String region; - - @Inject - IsRegionAndIdEqualsOrIsZoneParentIdEquals(@Region String region) { - this.region = checkNotNull(region, "region"); - } - - @Override - public boolean apply(Location input) { - switch (input.getScope()) { - case ZONE: - return input.getParent().getId().equals(region); - case REGION: - return input.getId().equals(region); - default: - return false; - } - } - - @Override - public String toString() { - return "isRegionAndIdEqualsOrIsZoneParentIdEquals(" + region + ")"; - } - } - - private final Injector injector; + private final Predicate locationPredicate; private final Supplier> locationsSupplier; @Inject - OnlyLocationOrFirstZoneOrRegionMatchingRegionId(Injector injector, - @Memoized Supplier> locationsSupplier) { - this.injector = checkNotNull(injector, "injector"); + OnlyLocationOrFirstRegionOptionallyMatchingRegionId(@Nullable @Region String region, + @Memoized Supplier> locationsSupplier) { + this.locationPredicate = region == null ? Predicates.or(isZone(), isRegion()) + : isZoneOrRegionWhereRegionIdEquals(region); this.locationsSupplier = checkNotNull(locationsSupplier, "locationsSupplier"); } @@ -87,16 +66,12 @@ public class OnlyLocationOrFirstZoneOrRegionMatchingRegionId implements Supplier Set locations = locationsSupplier.get(); if (locationsSupplier.get().size() == 1) return getOnlyElement(locationsSupplier.get()); - IsRegionAndIdEqualsOrIsZoneParentIdEquals matcher = null; try { - String region = injector.getInstance(Key.get(String.class, Region.class)); - if (region == null) - return Iterables.get(locationsSupplier.get(), 0); - matcher = injector.getInstance(IsRegionAndIdEqualsOrIsZoneParentIdEquals.class); - Location toReturn = Iterables.find(locations, matcher); + Location toReturn = Iterables.find(locations, locationPredicate); return toReturn.getScope() == LocationScope.REGION ? toReturn : toReturn.getParent(); } catch (NoSuchElementException e) { - throw new IllegalStateException(String.format("region %s not found in %s", matcher, locations)); + throw new NoSuchElementException(String.format("couldn't find region matching %s in %s", locationPredicate, + transform(locations, ToIdAndScope.INSTANCE))); } } } \ No newline at end of file diff --git a/core/src/main/java/org/jclouds/location/suppliers/OnlyLocationOrFirstZone.java b/core/src/main/java/org/jclouds/location/suppliers/OnlyLocationOrFirstZone.java index c3a59bb99c..77f44b1ac5 100644 --- a/core/src/main/java/org/jclouds/location/suppliers/OnlyLocationOrFirstZone.java +++ b/core/src/main/java/org/jclouds/location/suppliers/OnlyLocationOrFirstZone.java @@ -21,7 +21,10 @@ package org.jclouds.location.suppliers; import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.collect.Iterables.find; import static com.google.common.collect.Iterables.getOnlyElement; +import static com.google.common.collect.Iterables.transform; +import static org.jclouds.location.predicates.LocationPredicates.isZone; +import java.util.NoSuchElementException; import java.util.Set; import javax.inject.Inject; @@ -29,9 +32,8 @@ import javax.inject.Singleton; import org.jclouds.collect.Memoized; import org.jclouds.domain.Location; -import org.jclouds.domain.LocationScope; +import org.jclouds.location.functions.ToIdAndScope; -import com.google.common.base.Predicate; import com.google.common.base.Supplier; /** @@ -41,33 +43,25 @@ import com.google.common.base.Supplier; */ @Singleton public class OnlyLocationOrFirstZone implements Supplier { - @Singleton - public static final class IsZone implements Predicate { - @Override - public boolean apply(Location input) { - return input.getScope() == LocationScope.ZONE; - } - - @Override - public String toString() { - return "isZone()"; - } - } private final Supplier> locationsSupplier; - private final IsZone isZone; @Inject - OnlyLocationOrFirstZone(@Memoized Supplier> locationsSupplier, IsZone isZone) { + OnlyLocationOrFirstZone(@Memoized Supplier> locationsSupplier) { this.locationsSupplier = checkNotNull(locationsSupplier, "locationsSupplierSupplier"); - this.isZone = checkNotNull(isZone, "isZone"); } @Override public Location get() { - if (locationsSupplier.get().size() == 1) - return getOnlyElement(locationsSupplier.get()); - return find(locationsSupplier.get(), isZone); + Set locations = locationsSupplier.get(); + if (locations.size() == 1) + return getOnlyElement(locations); + try { + return find(locations, isZone()); + } catch (NoSuchElementException e) { + throw new NoSuchElementException("none to of the locations are scope ZONE: " + + transform(locations, ToIdAndScope.INSTANCE)); + } } } \ No newline at end of file diff --git a/core/src/main/java/org/jclouds/location/suppliers/RegionToProviderOrJustProvider.java b/core/src/main/java/org/jclouds/location/suppliers/RegionToProviderOrJustProvider.java index 54639bde09..b3eee0a442 100644 --- a/core/src/main/java/org/jclouds/location/suppliers/RegionToProviderOrJustProvider.java +++ b/core/src/main/java/org/jclouds/location/suppliers/RegionToProviderOrJustProvider.java @@ -50,7 +50,7 @@ public class RegionToProviderOrJustProvider extends JustProvider { @Inject public RegionToProviderOrJustProvider(@Iso3166 Set isoCodes, @Provider String providerName, @Provider URI endpoint, @Region Set regions, @Iso3166 Map> isoCodesById) { - super(isoCodes, providerName, endpoint); + super(providerName, endpoint, isoCodes); this.regions = checkNotNull(regions, "regions"); this.isoCodesById = checkNotNull(isoCodesById, "isoCodesById"); } diff --git a/core/src/test/java/org/jclouds/location/suppliers/JustProviderTest.java b/core/src/test/java/org/jclouds/location/suppliers/JustProviderTest.java new file mode 100644 index 0000000000..35c5d75df8 --- /dev/null +++ b/core/src/test/java/org/jclouds/location/suppliers/JustProviderTest.java @@ -0,0 +1,48 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds 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; + +import static org.testng.Assert.assertEquals; + +import java.net.URI; + +import org.jclouds.domain.LocationBuilder; +import org.jclouds.domain.LocationScope; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableSet; + +/** + * Tests behavior of {@code JustProvider} + * + * @author Adrian Cole + */ +@Test(groups = "unit", testName = "JustProviderTest") +public class JustProviderTest { + + @Test + public void test() throws SecurityException, NoSuchMethodException { + JustProvider fn = new JustProvider("servo", URI.create("http://servo"), ImmutableSet.of("US")); + assertEquals( + fn.get(), + ImmutableSet.of(new LocationBuilder().scope(LocationScope.PROVIDER).id("servo").description("http://servo") + .iso3166Codes(ImmutableSet.of("US")).build())); + } + +} diff --git a/core/src/test/java/org/jclouds/location/suppliers/OnlyLocationOrFirstRegionOptionallyMatchingRegionIdTest.java b/core/src/test/java/org/jclouds/location/suppliers/OnlyLocationOrFirstRegionOptionallyMatchingRegionIdTest.java new file mode 100644 index 0000000000..960ab9d507 --- /dev/null +++ b/core/src/test/java/org/jclouds/location/suppliers/OnlyLocationOrFirstRegionOptionallyMatchingRegionIdTest.java @@ -0,0 +1,94 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds 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; + +import static org.testng.Assert.assertEquals; + +import java.util.NoSuchElementException; +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.ImmutableSet; + +/** + * Tests behavior of {@code OnlyLocationOrFirstRegionOptionallyMatchingRegionId} + * + * @author Adrian Cole + */ +@Test(groups = "unit", testName = "OnlyLocationOrFirstRegionOptionallyMatchingRegionIdTest") +public class OnlyLocationOrFirstRegionOptionallyMatchingRegionIdTest { + Location provider = new LocationBuilder().scope(LocationScope.PROVIDER).id("servo").description("http://servo") + .build(); + Location region = new LocationBuilder().scope(LocationScope.REGION).id("servo-r1").description("http://r1.servo") + .parent(provider).build(); + Location region2 = new LocationBuilder().scope(LocationScope.REGION).id("servo-r2").description("http://r2.servo") + .parent(provider).build(); + Location zone = new LocationBuilder().scope(LocationScope.ZONE).id("servo-z").description("http://z.r.servo") + .parent(region).build(); + + @Test + public void testDidntMatchRegionIdThrowsNSEEWithReasonableMessage() { + Supplier> supplier = Suppliers.> ofInstance(ImmutableSet + . of(provider, region, region2, zone)); + OnlyLocationOrFirstRegionOptionallyMatchingRegionId fn = new OnlyLocationOrFirstRegionOptionallyMatchingRegionId( + "foo", supplier); + + try { + fn.get(); + assert false; + } catch (NoSuchElementException e) { + assertEquals( + e.getMessage(), + "couldn't find region matching isRegionAndIdEqualsOrIsZoneParentIdEquals(foo) in [servo:PROVIDER, servo-r1:REGION, servo-r2:REGION, servo-z:ZONE]"); + } + } + + @Test + public void testNoRegionUsesProvider() { + Supplier> supplier = Suppliers.> ofInstance(ImmutableSet + . of(provider)); + OnlyLocationOrFirstRegionOptionallyMatchingRegionId fn = new OnlyLocationOrFirstRegionOptionallyMatchingRegionId( + null, supplier); + assertEquals(fn.get(), provider); + } + + @Test + public void testFirstRegion() { + Supplier> supplier = Suppliers.> ofInstance(ImmutableSet + . of(provider, region, region2, zone)); + OnlyLocationOrFirstRegionOptionallyMatchingRegionId fn = new OnlyLocationOrFirstRegionOptionallyMatchingRegionId( + null, supplier); + assertEquals(fn.get(), region); + } + + @Test + public void testFindRegion() { + Supplier> supplier = Suppliers.> ofInstance(ImmutableSet + . of(provider, region, region2, zone)); + OnlyLocationOrFirstRegionOptionallyMatchingRegionId fn = new OnlyLocationOrFirstRegionOptionallyMatchingRegionId( + region2.getId(), supplier); + assertEquals(fn.get(), region2); + } +} diff --git a/core/src/test/java/org/jclouds/location/suppliers/OnlyLocationOrFirstZoneTest.java b/core/src/test/java/org/jclouds/location/suppliers/OnlyLocationOrFirstZoneTest.java new file mode 100644 index 0000000000..60edd13bfd --- /dev/null +++ b/core/src/test/java/org/jclouds/location/suppliers/OnlyLocationOrFirstZoneTest.java @@ -0,0 +1,78 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds 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; + +import static org.testng.Assert.assertEquals; + +import java.util.NoSuchElementException; +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.ImmutableSet; + +/** + * Tests behavior of {@code OnlyLocationOrFirstZone} + * + * @author Adrian Cole + */ +@Test(groups = "unit", testName = "OnlyLocationOrFirstZoneTest") +public class OnlyLocationOrFirstZoneTest { + Location provider = new LocationBuilder().scope(LocationScope.PROVIDER).id("servo").description("http://servo") + .build(); + Location region = new LocationBuilder().scope(LocationScope.REGION).id("servo-r").description("http://r.servo") + .parent(provider).build(); + Location zone = new LocationBuilder().scope(LocationScope.ZONE).id("servo-z").description("http://z.r.servo") + .parent(region).build(); + + @Test + public void testDidntFindZoneThrowsNSEEWithReasonableMessage() { + Supplier> supplier = Suppliers.> ofInstance(ImmutableSet + . of(provider, region)); + OnlyLocationOrFirstZone fn = new OnlyLocationOrFirstZone(supplier); + + try { + fn.get(); + assert false; + } catch (NoSuchElementException e) { + assertEquals(e.getMessage(), "none to of the locations are scope ZONE: [servo:PROVIDER, servo-r:REGION]"); + } + } + + @Test + public void testNoZoneUsesProvider() { + Supplier> supplier = Suppliers.> ofInstance(ImmutableSet + . of(provider)); + OnlyLocationOrFirstZone fn = new OnlyLocationOrFirstZone(supplier); + assertEquals(fn.get(), provider); + } + + @Test + public void testFirstZone() { + Supplier> supplier = Suppliers.> ofInstance(ImmutableSet + . of(provider, region, zone)); + OnlyLocationOrFirstZone fn = new OnlyLocationOrFirstZone(supplier); + assertEquals(fn.get(), zone); + } +} diff --git a/loadbalancer/src/main/java/org/jclouds/loadbalancer/config/BindLoadBalancerSuppliersByClass.java b/loadbalancer/src/main/java/org/jclouds/loadbalancer/config/BindLoadBalancerSuppliersByClass.java index 7b22f2d8ff..419612714a 100644 --- a/loadbalancer/src/main/java/org/jclouds/loadbalancer/config/BindLoadBalancerSuppliersByClass.java +++ b/loadbalancer/src/main/java/org/jclouds/loadbalancer/config/BindLoadBalancerSuppliersByClass.java @@ -26,7 +26,7 @@ import javax.inject.Singleton; import org.jclouds.compute.domain.Hardware; import org.jclouds.compute.domain.Image; import org.jclouds.domain.Location; -import org.jclouds.location.suppliers.OnlyLocationOrFirstZoneOrRegionMatchingRegionId; +import org.jclouds.location.suppliers.OnlyLocationOrFirstRegionOptionallyMatchingRegionId; import com.google.common.base.Supplier; import com.google.inject.AbstractModule; @@ -66,7 +66,7 @@ public abstract class BindLoadBalancerSuppliersByClass extends AbstractModule { } protected Class> defineDefaultLocationSupplier() { - return OnlyLocationOrFirstZoneOrRegionMatchingRegionId.class; + return OnlyLocationOrFirstRegionOptionallyMatchingRegionId.class; } protected void bindImageSupplier(Class>> clazz) { diff --git a/providers/aws-s3/src/main/java/org/jclouds/aws/s3/binders/AssignCorrectHostnameAndBindAsHostPrefixIfConfigured.java b/providers/aws-s3/src/main/java/org/jclouds/aws/s3/binders/AssignCorrectHostnameAndBindAsHostPrefixIfConfigured.java index bce033bb2b..ca0c31e9e4 100644 --- a/providers/aws-s3/src/main/java/org/jclouds/aws/s3/binders/AssignCorrectHostnameAndBindAsHostPrefixIfConfigured.java +++ b/providers/aws-s3/src/main/java/org/jclouds/aws/s3/binders/AssignCorrectHostnameAndBindAsHostPrefixIfConfigured.java @@ -18,20 +18,17 @@ */ package org.jclouds.aws.s3.binders; -import static org.jclouds.s3.reference.S3Constants.PROPERTY_S3_SERVICE_PATH; -import static org.jclouds.s3.reference.S3Constants.PROPERTY_S3_VIRTUAL_HOST_BUCKETS; +import static org.jclouds.http.utils.ModifyRequest.endpoint; import java.net.URI; import java.util.Map; import javax.inject.Inject; -import javax.inject.Named; import javax.inject.Provider; import javax.inject.Singleton; import javax.ws.rs.core.UriBuilder; import org.jclouds.http.HttpRequest; -import org.jclouds.http.utils.ModifyRequest; import org.jclouds.location.functions.RegionToEndpointOrProviderIfNull; import org.jclouds.rest.binders.BindAsHostPrefix; import org.jclouds.s3.Bucket; @@ -48,10 +45,9 @@ public class AssignCorrectHostnameAndBindAsHostPrefixIfConfigured extends BindAs @Inject public AssignCorrectHostnameAndBindAsHostPrefixIfConfigured(BindAsHostPrefix bindAsHostPrefix, - @Named(PROPERTY_S3_VIRTUAL_HOST_BUCKETS) boolean isVhostStyle, - @Named(PROPERTY_S3_SERVICE_PATH) String servicePath, RegionToEndpointOrProviderIfNull r2, - Provider uriBuilderProvider, @Bucket Map bucketToRegion) { - super(bindAsHostPrefix, isVhostStyle, servicePath, uriBuilderProvider); + RegionToEndpointOrProviderIfNull r2, Provider uriBuilderProvider, + @Bucket Map bucketToRegion) { + super(bindAsHostPrefix, true, "/", uriBuilderProvider); this.bucketToRegion = bucketToRegion; this.r2 = r2; } @@ -62,10 +58,8 @@ public class AssignCorrectHostnameAndBindAsHostPrefixIfConfigured extends BindAs String region = bucketToRegion.get(bucket); if (region != null) { URI endpoint = r2.apply(region); - request = ModifyRequest.endpoint( - request, - uriBuilderProvider.get().uri(endpoint).path(request.getEndpoint().getPath()) - .replaceQuery(request.getEndpoint().getQuery()).build()); + request = endpoint(request, uriBuilderProvider.get().uri(endpoint).path(request.getEndpoint().getPath()) + .replaceQuery(request.getEndpoint().getQuery()).build()); } return super.bindToRequest(request, payload); } diff --git a/providers/aws-s3/src/test/java/org/jclouds/aws/s3/AWSS3AsyncClientTest.java b/providers/aws-s3/src/test/java/org/jclouds/aws/s3/AWSS3AsyncClientTest.java index 1a86fa46a3..a2af01bb2a 100644 --- a/providers/aws-s3/src/test/java/org/jclouds/aws/s3/AWSS3AsyncClientTest.java +++ b/providers/aws-s3/src/test/java/org/jclouds/aws/s3/AWSS3AsyncClientTest.java @@ -19,7 +19,6 @@ package org.jclouds.aws.s3; import java.io.IOException; -import java.lang.reflect.Array; import java.lang.reflect.Method; import java.net.URI; import java.util.Map; @@ -29,6 +28,7 @@ import java.util.concurrent.ConcurrentMap; import org.jclouds.aws.s3.config.AWSS3RestClientModule; import org.jclouds.aws.s3.functions.ETagFromHttpResponseViaRegex; import org.jclouds.aws.s3.functions.UploadIdFromHttpResponseViaRegex; +import org.jclouds.blobstore.binders.BindBlobToMultipartFormTest; import org.jclouds.date.TimeStamp; import org.jclouds.http.HttpRequest; import org.jclouds.http.RequiresHttp; @@ -45,6 +45,7 @@ import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404; import org.jclouds.rest.internal.RestAnnotationProcessor; import org.jclouds.s3.domain.ObjectMetadata; import org.jclouds.s3.domain.ObjectMetadataBuilder; +import org.jclouds.s3.domain.S3Object; import org.jclouds.s3.functions.ReturnFalseIfBucketAlreadyOwnedByYouOrIllegalState; import org.jclouds.s3.options.PutBucketOptions; import org.jclouds.s3.options.PutObjectOptions; @@ -84,6 +85,26 @@ public class AWSS3AsyncClientTest extends org.jclouds.s3.S3AsyncClientTest uriBuilderProvider = new Provider() { + + @Override + public UriBuilder get() { + return new UriBuilderImpl(); + } + + }; + + public void testWhenNoBucketRegionMappingInCache() { + HttpRequest request = new HttpRequest("GET", URI.create("https://s3.amazonaws.com")); + + AssignCorrectHostnameAndBindAsHostPrefixIfConfigured binder = new AssignCorrectHostnameAndBindAsHostPrefixIfConfigured( + new BindAsHostPrefix(uriBuilderProvider), new RegionToEndpointOrProviderIfNull("aws-s3", + URI.create("https://s3.amazonaws.com"), ImmutableMap.of("us-standard", + URI.create("https://s3.amazonaws.com"), "us-west-1", + URI.create("https://s3-us-west-1.amazonaws.com"))), uriBuilderProvider, + ImmutableMap. of()); + + request = binder.bindToRequest(request, "bucket"); + assertEquals(request.getRequestLine(), "GET https://bucket.s3.amazonaws.com HTTP/1.1"); + + } + + public void testWhenBucketRegionMappingInCache() { + HttpRequest request = new HttpRequest("GET", URI.create("https://s3.amazonaws.com")); + + AssignCorrectHostnameAndBindAsHostPrefixIfConfigured binder = new AssignCorrectHostnameAndBindAsHostPrefixIfConfigured( + new BindAsHostPrefix(uriBuilderProvider), new RegionToEndpointOrProviderIfNull("aws-s3", + URI.create("https://s3.amazonaws.com"), ImmutableMap.of("us-standard", + URI.create("https://s3.amazonaws.com"), "us-west-1", + URI.create("https://s3-us-west-1.amazonaws.com"))), uriBuilderProvider, + ImmutableMap. of("bucket", "us-west-1")); + + request = binder.bindToRequest(request, "bucket"); + assertEquals(request.getRequestLine(), "GET https://bucket.s3-us-west-1.amazonaws.com HTTP/1.1"); + + } +} diff --git a/providers/cloudloadbalancers-us/src/main/java/org/jclouds/cloudloadbalancers/config/CloudLoadBalancersRestClientModule.java b/providers/cloudloadbalancers-us/src/main/java/org/jclouds/cloudloadbalancers/config/CloudLoadBalancersRestClientModule.java index a5b78d5f9e..902c4f6669 100644 --- a/providers/cloudloadbalancers-us/src/main/java/org/jclouds/cloudloadbalancers/config/CloudLoadBalancersRestClientModule.java +++ b/providers/cloudloadbalancers-us/src/main/java/org/jclouds/cloudloadbalancers/config/CloudLoadBalancersRestClientModule.java @@ -18,6 +18,8 @@ */ package org.jclouds.cloudloadbalancers.config; +import static com.google.common.collect.Iterables.get; + import java.net.URI; import java.util.Map; import java.util.Set; @@ -37,10 +39,13 @@ import org.jclouds.http.RequiresHttp; import org.jclouds.http.annotation.ClientError; import org.jclouds.http.annotation.Redirection; import org.jclouds.http.annotation.ServerError; +import org.jclouds.javax.annotation.Nullable; import org.jclouds.json.config.GsonModule.DateAdapter; import org.jclouds.json.config.GsonModule.Iso8601DateAdapter; +import org.jclouds.location.Provider; import org.jclouds.location.Region; import org.jclouds.location.config.ProvideRegionToURIViaProperties; +import org.jclouds.logging.Logger.LoggerFactory; import org.jclouds.openstack.OpenStackAuthAsyncClient.AuthenticationResponse; import org.jclouds.openstack.config.OpenStackAuthenticationModule; import org.jclouds.openstack.reference.AuthHeaders; @@ -48,6 +53,7 @@ import org.jclouds.rest.ConfiguresRestClient; import org.jclouds.rest.config.RestClientModule; import com.google.common.base.Supplier; +import com.google.common.collect.ImmutableBiMap; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Multimap; @@ -64,11 +70,11 @@ import com.google.inject.TypeLiteral; @RequiresHttp @ConfiguresRestClient public class CloudLoadBalancersRestClientModule extends - RestClientModule { + RestClientModule { public static final Map, Class> DELEGATE_MAP = ImmutableMap., Class> builder()// - .put(LoadBalancerClient.class, LoadBalancerAsyncClient.class)// - .build(); + .put(LoadBalancerClient.class, LoadBalancerAsyncClient.class)// + .build(); public CloudLoadBalancersRestClientModule() { super(CloudLoadBalancersClient.class, CloudLoadBalancersAsyncClient.class, DELEGATE_MAP); @@ -83,8 +89,8 @@ public class CloudLoadBalancersRestClientModule extends @Inject protected ProvideRegionToURIViaPropertiesWithAccountID(Injector injector, - @Named("CONSTANTS") Multimap constants, - @Named(RackspaceConstants.PROPERTY_ACCOUNT_ID) String accountID) { + @Named("CONSTANTS") Multimap constants, + @Named(RackspaceConstants.PROPERTY_ACCOUNT_ID) String accountID) { super(injector, constants); constants.replaceValues(RackspaceConstants.PROPERTY_ACCOUNT_ID, ImmutableSet.of(accountID)); } @@ -118,14 +124,28 @@ public class CloudLoadBalancersRestClientModule extends return endpoints.keySet(); } + @Provides + @Singleton + @Nullable + @Region + protected String getDefaultRegion(@Provider URI uri, @Region Map map, LoggerFactory logFactory) { + String region = ImmutableBiMap.copyOf(map).inverse().get(uri); + if (region == null && map.size() > 0) { + logFactory.getLogger(getClass().getName()).warn( + "failed to find region for current endpoint %s in %s; choosing first: %s", uri, map, region); + region = get(map.keySet(), 0); + } + return region; + } + @Override protected void bindErrorHandlers() { bind(HttpErrorHandler.class).annotatedWith(Redirection.class).to( - ParseCloudLoadBalancersErrorFromHttpResponse.class); + ParseCloudLoadBalancersErrorFromHttpResponse.class); bind(HttpErrorHandler.class).annotatedWith(ClientError.class).to( - ParseCloudLoadBalancersErrorFromHttpResponse.class); + ParseCloudLoadBalancersErrorFromHttpResponse.class); bind(HttpErrorHandler.class).annotatedWith(ServerError.class).to( - ParseCloudLoadBalancersErrorFromHttpResponse.class); + ParseCloudLoadBalancersErrorFromHttpResponse.class); } } diff --git a/providers/cloudloadbalancers-us/src/test/java/org/jclouds/cloudloadbalancers/features/BaseCloudLoadBalancersAsyncClientTest.java b/providers/cloudloadbalancers-us/src/test/java/org/jclouds/cloudloadbalancers/features/BaseCloudLoadBalancersAsyncClientTest.java index 3962edf5e7..f1ce6f06c9 100644 --- a/providers/cloudloadbalancers-us/src/test/java/org/jclouds/cloudloadbalancers/features/BaseCloudLoadBalancersAsyncClientTest.java +++ b/providers/cloudloadbalancers-us/src/test/java/org/jclouds/cloudloadbalancers/features/BaseCloudLoadBalancersAsyncClientTest.java @@ -21,6 +21,8 @@ package org.jclouds.cloudloadbalancers.features; import static org.testng.Assert.assertEquals; import java.io.IOException; +import java.net.URI; +import java.util.Map; import java.util.Properties; import org.jclouds.cloudloadbalancers.CloudLoadBalancersAsyncClient; @@ -40,6 +42,7 @@ import org.testng.annotations.BeforeClass; import com.google.common.base.Supplier; import com.google.common.base.Throwables; +import com.google.common.collect.ImmutableMap; import com.google.inject.Module; /** @@ -50,6 +53,19 @@ public abstract class BaseCloudLoadBalancersAsyncClientTest extends RestClien @RequiresHttp @ConfiguresRestClient public static class CloudLoadBalancersRestClientModuleExtension extends CloudLoadBalancersRestClientModule { + + protected void bindRegionsToProvider() { + bindRegionsToProvider(Regions.class); + } + + static class Regions implements javax.inject.Provider> { + @Override + public Map get() { + return ImmutableMap. of("DFW", + URI.create("https://dfw.loadbalancers.api.rackspacecloud.com/v1.0/1234")); + } + } + @Override protected String accountID(Supplier in) { return "1234"; @@ -79,8 +95,8 @@ public abstract class BaseCloudLoadBalancersAsyncClientTest extends RestClien super.setupFactory(); try { processor.setCaller(new ClassMethodArgs(CloudLoadBalancersAsyncClient.class, - CloudLoadBalancersAsyncClient.class.getMethod("getLoadBalancerClient", String.class), - new Object[] { Region.DFW })); + CloudLoadBalancersAsyncClient.class.getMethod("getLoadBalancerClient", String.class), + new Object[] { Region.DFW })); } catch (Exception e) { Throwables.propagate(e); } diff --git a/providers/gogrid/src/main/java/org/jclouds/gogrid/compute/suppliers/GoGridLocationSupplier.java b/providers/gogrid/src/main/java/org/jclouds/gogrid/compute/suppliers/GoGridLocationSupplier.java index c08c42fe24..4e78d6cee2 100644 --- a/providers/gogrid/src/main/java/org/jclouds/gogrid/compute/suppliers/GoGridLocationSupplier.java +++ b/providers/gogrid/src/main/java/org/jclouds/gogrid/compute/suppliers/GoGridLocationSupplier.java @@ -53,7 +53,7 @@ public class GoGridLocationSupplier extends JustProvider { @Inject GoGridLocationSupplier(@Iso3166 Set isoCodes, @Provider String providerName, @Provider URI endpoint, GoGridClient sync, @Iso3166 Map> isoCodesById) { - super(isoCodes, providerName, endpoint); + super(providerName, endpoint, isoCodes); this.sync = checkNotNull(sync, "sync"); this.isoCodesById = checkNotNull(isoCodesById, "isoCodesById"); } diff --git a/providers/rimuhosting/src/main/java/org/jclouds/rimuhosting/miro/compute/suppliers/RimuHostingLocationSupplier.java b/providers/rimuhosting/src/main/java/org/jclouds/rimuhosting/miro/compute/suppliers/RimuHostingLocationSupplier.java index 0b0a5adfe8..293cc47f08 100644 --- a/providers/rimuhosting/src/main/java/org/jclouds/rimuhosting/miro/compute/suppliers/RimuHostingLocationSupplier.java +++ b/providers/rimuhosting/src/main/java/org/jclouds/rimuhosting/miro/compute/suppliers/RimuHostingLocationSupplier.java @@ -56,7 +56,7 @@ public class RimuHostingLocationSupplier extends JustProvider { @Inject RimuHostingLocationSupplier(@Iso3166 Set isoCodes, @Provider String providerName, @Provider URI endpoint, RimuHostingClient sync, @Iso3166 Map> isoCodesById) { - super(isoCodes, providerName, endpoint); + super(providerName, endpoint, isoCodes); this.sync = checkNotNull(sync, "sync"); this.isoCodesById = checkNotNull(isoCodesById, "isoCodesById"); } diff --git a/providers/softlayer/src/test/java/org/jclouds/softlayer/compute/functions/DatacenterToLocationTest.java b/providers/softlayer/src/test/java/org/jclouds/softlayer/compute/functions/DatacenterToLocationTest.java index 6bb8e8761e..dcba566676 100644 --- a/providers/softlayer/src/test/java/org/jclouds/softlayer/compute/functions/DatacenterToLocationTest.java +++ b/providers/softlayer/src/test/java/org/jclouds/softlayer/compute/functions/DatacenterToLocationTest.java @@ -40,8 +40,8 @@ import com.google.common.collect.ImmutableSet; @Test(singleThreaded = true, groups = "unit") public class DatacenterToLocationTest { - static DatacenterToLocation function = new DatacenterToLocation(new JustProvider(ImmutableSet. of(), "softlayer", - URI.create("foo")));; + static DatacenterToLocation function = new DatacenterToLocation(new JustProvider("softlayer", URI.create("foo"), + ImmutableSet. of())); @Test public void testDatacenterToLocation() { @@ -85,7 +85,7 @@ public class DatacenterToLocationTest { @Test public void testGetIso3166CodeWhitespaceTrimmer() { Address address = Address.builder().country(" US ").state(" TX ").description("This is spaced out Texas") - .build(); + .build(); Datacenter datacenter = Datacenter.builder().id(1).longName("Nowhere").locationAddress(address).build();