From c388fc41b4eb7b8f6cf98d2e7845bd8b4f11c105 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Fri, 3 Feb 2012 13:50:10 -0800 Subject: [PATCH] Issue 826: removed eager supplier of @Provider endpoint --- .../org/jclouds/atmos/filters/ShareUrl.java | 7 ++++--- .../SupplyFromProviderURIOrNodesProperty.java | 14 +++++++++---- .../config/CloudStackRestClientModule.java | 20 +++++++++++++++---- .../compute/functions/ZoneToLocationTest.java | 4 +++- .../compute/functions/RealmToLocation.java | 7 ++++--- .../DescribeRegionsResponseHandlerTest.java | 7 +++++-- .../location/OrgAndVDCToLocationSupplier.java | 3 ++- .../internal/VCloudLoginAsyncClientTest.java | 4 ++-- .../blobstore/TransientBlobRequestSigner.java | 16 ++++++++------- .../location/OrgAndVDCToLocationSupplier.java | 2 +- .../TerremarkVCloudLoginAsyncClientTest.java | 5 ++--- .../location/suppliers/all/JustProvider.java | 6 +++--- .../config/BindPropertiesToAnnotations.java | 9 --------- .../internal/RestAnnotationProcessor.java | 2 +- .../rest/internal/RestContextImpl.java | 7 ++++--- .../suppliers/all/JustProviderTest.java | 4 ++-- .../admin/StartVBoxIfNotAlreadyRunning.java | 7 ++++--- .../StartVBoxIfNotAlreadyRunningTest.java | 10 +++++----- .../location/RimuHostingLocationSupplier.java | 2 +- .../compute/functions/NetworkToLocation.java | 7 ++++--- .../functions/DatacenterToLocationTest.java | 5 +++-- 21 files changed, 85 insertions(+), 63 deletions(-) diff --git a/apis/atmos/src/main/java/org/jclouds/atmos/filters/ShareUrl.java b/apis/atmos/src/main/java/org/jclouds/atmos/filters/ShareUrl.java index 41f3e24933..4fdf7a7cee 100644 --- a/apis/atmos/src/main/java/org/jclouds/atmos/filters/ShareUrl.java +++ b/apis/atmos/src/main/java/org/jclouds/atmos/filters/ShareUrl.java @@ -39,6 +39,7 @@ import org.jclouds.location.Provider; import org.jclouds.logging.Logger; import com.google.common.base.Function; +import com.google.common.base.Supplier; /** * Signs the EMC Atmos Online Storage request. @@ -52,7 +53,7 @@ public class ShareUrl implements Function { private final String uid; private final byte[] key; - private final URI provider; + private final Supplier provider; private final javax.inject.Provider timeStampProvider; private final javax.inject.Provider uriBuilders; private final Crypto crypto; @@ -66,7 +67,7 @@ public class ShareUrl implements Function { @Inject public ShareUrl(@Named(PROPERTY_IDENTITY) String uid, @Named(PROPERTY_CREDENTIAL) String encodedKey, - @Provider URI provider, @TimeStamp javax.inject.Provider timeStampProvider, + @Provider Supplier provider, @TimeStamp javax.inject.Provider timeStampProvider, javax.inject.Provider uriBuilders, Crypto crypto) { this.uid = uid; this.key = CryptoStreams.base64(encodedKey); @@ -81,7 +82,7 @@ public class ShareUrl implements Function { String requestedResource = new StringBuilder().append("/rest/namespace/").append(path).toString(); long expires = timeStampProvider.get(); String signature = signString(createStringToSign(requestedResource, expires)); - return uriBuilders.get().uri(provider).path(requestedResource).queryParam("uid", uid).queryParam("expires", + return uriBuilders.get().uri(provider.get()).path(requestedResource).queryParam("uid", uid).queryParam("expires", expires).queryParam("signature", signature).build(); } diff --git a/apis/byon/src/main/java/org/jclouds/byon/suppliers/SupplyFromProviderURIOrNodesProperty.java b/apis/byon/src/main/java/org/jclouds/byon/suppliers/SupplyFromProviderURIOrNodesProperty.java index 91829d53e4..106a7efed8 100644 --- a/apis/byon/src/main/java/org/jclouds/byon/suppliers/SupplyFromProviderURIOrNodesProperty.java +++ b/apis/byon/src/main/java/org/jclouds/byon/suppliers/SupplyFromProviderURIOrNodesProperty.java @@ -33,6 +33,7 @@ import org.jclouds.util.Strings2; import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Function; import com.google.common.base.Supplier; +import com.google.common.base.Suppliers; import com.google.common.base.Throwables; import com.google.inject.Inject; import com.google.inject.name.Named; @@ -43,15 +44,20 @@ import com.google.inject.name.Named; public class SupplyFromProviderURIOrNodesProperty implements Supplier, Function { @Resource protected Logger logger = Logger.NULL; - private final URI url; + private final Supplier url; @Inject(optional = true) @Named("byon.nodes") @VisibleForTesting String nodes; - + + @VisibleForTesting + public SupplyFromProviderURIOrNodesProperty(URI url) { + this(Suppliers.ofInstance(checkNotNull(url, "url"))); + } + @Inject - public SupplyFromProviderURIOrNodesProperty(@Provider URI url) { + public SupplyFromProviderURIOrNodesProperty(@Provider Supplier url) { this.url = checkNotNull(url, "url"); } @@ -59,7 +65,7 @@ public class SupplyFromProviderURIOrNodesProperty implements Supplier uriBuilder) { - return uriBuilder.get().scheme(normal.getScheme()).host(normal.getHost()).path("/").port(port).build(); + protected Supplier providesIntegrationEndpoint(@Provider final Supplier provider, + @Named("jclouds.cloudstack.integration-api-port") final int port, + final com.google.inject.Provider uriBuilder) { + return Suppliers.compose(new Function() { + + @Override + public URI apply(URI input) { + URI normal = provider.get(); + return uriBuilder.get().scheme(normal.getScheme()).host(normal.getHost()).path("/").port(port).build(); + } + + public String toString(){ + return "getIntegrationEndpoint()"; + } + }, provider); } @Singleton diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/compute/functions/ZoneToLocationTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/compute/functions/ZoneToLocationTest.java index a2712e9411..155b99bc2e 100644 --- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/compute/functions/ZoneToLocationTest.java +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/compute/functions/ZoneToLocationTest.java @@ -31,6 +31,7 @@ import org.jclouds.domain.LocationScope; import org.jclouds.location.suppliers.all.JustProvider; import org.testng.annotations.Test; +import com.google.common.base.Suppliers; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; @@ -42,7 +43,8 @@ import com.google.common.collect.Iterables; @Test(singleThreaded = true, groups = "unit") public class ZoneToLocationTest { - static JustProvider justProvider = new JustProvider("cloudstack", URI.create("foo"), ImmutableSet. of()); + static JustProvider justProvider = new JustProvider("cloudstack", Suppliers.ofInstance(URI.create("foo")), + ImmutableSet. of()); static ZoneToLocation function = new ZoneToLocation(justProvider); static Location one = new LocationBuilder().parent(Iterables.get(justProvider.get(), 0)).scope(LocationScope.ZONE) .description("San Jose 1").id("1").build(); diff --git a/apis/deltacloud/src/main/java/org/jclouds/deltacloud/compute/functions/RealmToLocation.java b/apis/deltacloud/src/main/java/org/jclouds/deltacloud/compute/functions/RealmToLocation.java index 96b8146d99..1c0ce6a36d 100644 --- a/apis/deltacloud/src/main/java/org/jclouds/deltacloud/compute/functions/RealmToLocation.java +++ b/apis/deltacloud/src/main/java/org/jclouds/deltacloud/compute/functions/RealmToLocation.java @@ -34,6 +34,7 @@ import org.jclouds.location.Iso3166; import org.jclouds.location.Provider; import com.google.common.base.Function; +import com.google.common.base.Supplier; /** * @author Adrian Cole @@ -42,11 +43,11 @@ import com.google.common.base.Function; public class RealmToLocation implements Function { private final String providerName; - private final URI endpoint; + private final Supplier endpoint; private final Set isoCodes; @Inject - public RealmToLocation(@Iso3166 Set isoCodes, @Provider String providerName, @Provider URI endpoint) { + public RealmToLocation(@Iso3166 Set isoCodes, @Provider String providerName, @Provider Supplier endpoint) { this.providerName = checkNotNull(providerName, "providerName"); this.endpoint = checkNotNull(endpoint, "endpoint"); this.isoCodes = checkNotNull(isoCodes, "isoCodes"); @@ -56,6 +57,6 @@ public class RealmToLocation implements Function { public Location apply(Realm from) { return new LocationBuilder().scope(LocationScope.ZONE).id(from.getHref().toASCIIString()).description(from.getName()).parent( new LocationBuilder().scope(LocationScope.PROVIDER).iso3166Codes(isoCodes).id(providerName).description( - endpoint.toASCIIString()).parent(null).build()).build(); + endpoint.get().toASCIIString()).parent(null).build()).build(); } } diff --git a/apis/ec2/src/test/java/org/jclouds/ec2/xml/DescribeRegionsResponseHandlerTest.java b/apis/ec2/src/test/java/org/jclouds/ec2/xml/DescribeRegionsResponseHandlerTest.java index 2807ed5265..a9a037bfb3 100644 --- a/apis/ec2/src/test/java/org/jclouds/ec2/xml/DescribeRegionsResponseHandlerTest.java +++ b/apis/ec2/src/test/java/org/jclouds/ec2/xml/DescribeRegionsResponseHandlerTest.java @@ -33,9 +33,12 @@ import org.jclouds.util.Strings2; import org.testng.annotations.BeforeTest; 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.inject.AbstractModule; import com.google.inject.Guice; +import com.google.inject.TypeLiteral; /** * Tests behavior of {@code DescribeRegionsResponseHandler} @@ -52,8 +55,8 @@ public class DescribeRegionsResponseHandlerTest extends BaseHandlerTest { @Override protected void configure() { - bind(URI.class).annotatedWith(Provider.class).toInstance( - URI.create("https://booya")); + bind(new TypeLiteral>(){}).annotatedWith(Provider.class).toInstance( + Suppliers.ofInstance(URI.create("https://booya"))); } }); diff --git a/apis/vcloud/src/main/java/org/jclouds/vcloud/location/OrgAndVDCToLocationSupplier.java b/apis/vcloud/src/main/java/org/jclouds/vcloud/location/OrgAndVDCToLocationSupplier.java index d41168178d..4fad340262 100644 --- a/apis/vcloud/src/main/java/org/jclouds/vcloud/location/OrgAndVDCToLocationSupplier.java +++ b/apis/vcloud/src/main/java/org/jclouds/vcloud/location/OrgAndVDCToLocationSupplier.java @@ -53,7 +53,8 @@ public class OrgAndVDCToLocationSupplier extends JustProvider implements Locatio private final Supplier>>> isoCodesByIdSupplier; @Inject - OrgAndVDCToLocationSupplier(@Iso3166 Set isoCodes, @Provider String providerName, @Provider URI endpoint, + OrgAndVDCToLocationSupplier(@Iso3166 Set isoCodes, @Provider String providerName, + @Provider Supplier endpoint, @org.jclouds.vcloud.endpoints.Org Supplier> orgNameToResource, Supplier> orgNameToVDCResource, @Iso3166 Supplier>>> isoCodesByIdSupplier) { diff --git a/apis/vcloud/src/test/java/org/jclouds/vcloud/internal/VCloudLoginAsyncClientTest.java b/apis/vcloud/src/test/java/org/jclouds/vcloud/internal/VCloudLoginAsyncClientTest.java index 01f527854f..e6b3b1a725 100644 --- a/apis/vcloud/src/test/java/org/jclouds/vcloud/internal/VCloudLoginAsyncClientTest.java +++ b/apis/vcloud/src/test/java/org/jclouds/vcloud/internal/VCloudLoginAsyncClientTest.java @@ -91,8 +91,8 @@ public class VCloudLoginAsyncClientTest extends RestClientTest provideURI(@Provider URI uri) { - return Suppliers.ofInstance(uri); + Supplier provideURI(@Provider Supplier uri) { + return uri; } }; diff --git a/blobstore/src/main/java/org/jclouds/blobstore/TransientBlobRequestSigner.java b/blobstore/src/main/java/org/jclouds/blobstore/TransientBlobRequestSigner.java index c81302f81a..3a6767b997 100644 --- a/blobstore/src/main/java/org/jclouds/blobstore/TransientBlobRequestSigner.java +++ b/blobstore/src/main/java/org/jclouds/blobstore/TransientBlobRequestSigner.java @@ -33,6 +33,8 @@ import org.jclouds.http.HttpUtils; import org.jclouds.http.filters.BasicAuthentication; import org.jclouds.location.Provider; +import com.google.common.base.Supplier; + /** * * @author Adrian Cole @@ -42,25 +44,25 @@ public class TransientBlobRequestSigner implements BlobRequestSigner { private final BasicAuthentication basicAuth; private final BlobToHttpGetOptions blob2HttpGetOptions; - private final String endpoint; + private final Supplier endpoint; @Inject - public TransientBlobRequestSigner(BasicAuthentication basicAuth, BlobToHttpGetOptions blob2HttpGetOptions, @Provider URI endpoint) { + public TransientBlobRequestSigner(BasicAuthentication basicAuth, BlobToHttpGetOptions blob2HttpGetOptions, @Provider Supplier endpoint) { this.basicAuth = checkNotNull(basicAuth, "basicAuth"); this.blob2HttpGetOptions = checkNotNull(blob2HttpGetOptions, "blob2HttpGetOptions"); - this.endpoint = endpoint.toString(); + this.endpoint = endpoint; } @Override public HttpRequest signGetBlob(String container, String name) { - HttpRequest request = new HttpRequest("GET", URI.create(String.format("%s/%s/%s", endpoint, container, name))); + HttpRequest request = new HttpRequest("GET", URI.create(String.format("%s/%s/%s", endpoint.get(), container, name))); return basicAuth.filter(request); } @Override public HttpRequest signPutBlob(String container, Blob blob) { HttpRequest request = HttpRequest.builder().method("PUT").endpoint( - URI.create(String.format("%s/%s/%s", endpoint, container, blob.getMetadata().getName()))).payload( + URI.create(String.format("%s/%s/%s", endpoint.get(), container, blob.getMetadata().getName()))).payload( blob.getPayload()).headers( HttpUtils.getContentHeadersFromMetadata(blob.getMetadata().getContentMetadata())).build(); return basicAuth.filter(request); @@ -68,7 +70,7 @@ public class TransientBlobRequestSigner implements BlobRequestSigner { @Override public HttpRequest signRemoveBlob(String container, String name) { - HttpRequest request = new HttpRequest("DELETE", URI.create(String.format("%s/%s/%s", endpoint, container, + HttpRequest request = new HttpRequest("DELETE", URI.create(String.format("%s/%s/%s", endpoint.get(), container, name))); return basicAuth.filter(request); } @@ -76,7 +78,7 @@ public class TransientBlobRequestSigner implements BlobRequestSigner { @Override public HttpRequest signGetBlob(String container, String name, GetOptions options) { HttpRequest request = HttpRequest.builder().method("GET").endpoint( - URI.create(String.format("%s/%s/%s", endpoint, container, name))).headers( + URI.create(String.format("%s/%s/%s", endpoint.get(), container, name))).headers( blob2HttpGetOptions.apply(options).buildRequestHeaders()).build(); return basicAuth.filter(request); } diff --git a/common/trmk/src/main/java/org/jclouds/trmk/vcloud_0_8/location/OrgAndVDCToLocationSupplier.java b/common/trmk/src/main/java/org/jclouds/trmk/vcloud_0_8/location/OrgAndVDCToLocationSupplier.java index b8cc48a92d..54d29527d6 100644 --- a/common/trmk/src/main/java/org/jclouds/trmk/vcloud_0_8/location/OrgAndVDCToLocationSupplier.java +++ b/common/trmk/src/main/java/org/jclouds/trmk/vcloud_0_8/location/OrgAndVDCToLocationSupplier.java @@ -53,7 +53,7 @@ public class OrgAndVDCToLocationSupplier extends JustProvider implements Locatio private final Supplier>>> isoCodesByIdSupplier; @Inject - OrgAndVDCToLocationSupplier(@Iso3166 Set isoCodes, @Provider String providerName, @Provider URI endpoint, + OrgAndVDCToLocationSupplier(@Iso3166 Set isoCodes, @Provider String providerName, @Provider Supplier endpoint, @org.jclouds.trmk.vcloud_0_8.endpoints.Org Supplier> orgNameToResource, Supplier> orgNameToVDCResource, @Iso3166 Supplier>>> isoCodesByIdSupplier) { diff --git a/common/trmk/src/test/java/org/jclouds/trmk/vcloud_0_8/internal/TerremarkVCloudLoginAsyncClientTest.java b/common/trmk/src/test/java/org/jclouds/trmk/vcloud_0_8/internal/TerremarkVCloudLoginAsyncClientTest.java index 89516be5ea..89a9ba2178 100644 --- a/common/trmk/src/test/java/org/jclouds/trmk/vcloud_0_8/internal/TerremarkVCloudLoginAsyncClientTest.java +++ b/common/trmk/src/test/java/org/jclouds/trmk/vcloud_0_8/internal/TerremarkVCloudLoginAsyncClientTest.java @@ -38,7 +38,6 @@ import org.jclouds.trmk.vcloud_0_8.functions.ParseLoginResponseFromHeaders; import org.testng.annotations.Test; import com.google.common.base.Supplier; -import com.google.common.base.Suppliers; import com.google.inject.Binder; import com.google.inject.Module; import com.google.inject.Provides; @@ -91,8 +90,8 @@ public class TerremarkVCloudLoginAsyncClientTest extends RestClientTest provideURI(@Provider URI uri) { - return Suppliers.ofInstance(uri); + Supplier provideURI(@Provider Supplier uri) { + return uri; } }; diff --git a/core/src/main/java/org/jclouds/location/suppliers/all/JustProvider.java b/core/src/main/java/org/jclouds/location/suppliers/all/JustProvider.java index a249aefee9..1dd70dcb2f 100644 --- a/core/src/main/java/org/jclouds/location/suppliers/all/JustProvider.java +++ b/core/src/main/java/org/jclouds/location/suppliers/all/JustProvider.java @@ -42,11 +42,11 @@ import com.google.common.collect.ImmutableSet; @Singleton public class JustProvider implements Supplier> { private final String providerName; - private final URI endpointSupplier; + private final Supplier endpointSupplier; private final Set isoCodesSupplier; @Inject - public JustProvider(@Provider String providerName, @Provider URI endpointSupplier, @Iso3166 Set isoCodesSupplier) { + public JustProvider(@Provider String providerName, @Provider Supplier endpointSupplier, @Iso3166 Set isoCodesSupplier) { this.providerName = checkNotNull(providerName, "providerName"); this.endpointSupplier = checkNotNull(endpointSupplier, "endpoint"); this.isoCodesSupplier = checkNotNull(isoCodesSupplier, "isoCodes"); @@ -55,7 +55,7 @@ public class JustProvider implements Supplier> { @Override public Set get() { return ImmutableSet.of(new LocationBuilder().scope(LocationScope.PROVIDER).id(providerName) - .description(endpointSupplier.toASCIIString()).iso3166Codes(isoCodesSupplier).build()); + .description(endpointSupplier.get().toASCIIString()).iso3166Codes(isoCodesSupplier).build()); } } \ No newline at end of file diff --git a/core/src/main/java/org/jclouds/rest/config/BindPropertiesToAnnotations.java b/core/src/main/java/org/jclouds/rest/config/BindPropertiesToAnnotations.java index 855fc44fec..76c8a954b9 100644 --- a/core/src/main/java/org/jclouds/rest/config/BindPropertiesToAnnotations.java +++ b/core/src/main/java/org/jclouds/rest/config/BindPropertiesToAnnotations.java @@ -26,13 +26,11 @@ import static org.jclouds.Constants.PROPERTY_API; import static org.jclouds.Constants.PROPERTY_API_VERSION; import static org.jclouds.Constants.PROPERTY_BUILD_VERSION; import static org.jclouds.Constants.PROPERTY_CREDENTIAL; -import static org.jclouds.Constants.PROPERTY_ENDPOINT; import static org.jclouds.Constants.PROPERTY_IDENTITY; import static org.jclouds.Constants.PROPERTY_ISO3166_CODES; import static org.jclouds.Constants.PROPERTY_PROVIDER; import static org.jclouds.Constants.PROPERTY_TIMEOUTS_PREFIX; -import java.net.URI; import java.util.Map; import java.util.Set; @@ -100,13 +98,6 @@ public class BindPropertiesToAnnotations extends ConfigurationModule { protected String bindProvider(@Named(PROPERTY_PROVIDER) String in){ return in; } - - @Provides - @Singleton - @Provider - protected URI bindProviderEndpoint(@Named(PROPERTY_ENDPOINT) String in){ - return URI.create(in); - } @Provides @Singleton diff --git a/core/src/main/java/org/jclouds/rest/internal/RestAnnotationProcessor.java b/core/src/main/java/org/jclouds/rest/internal/RestAnnotationProcessor.java index 10cd1eeb54..d0872e7a10 100644 --- a/core/src/main/java/org/jclouds/rest/internal/RestAnnotationProcessor.java +++ b/core/src/main/java/org/jclouds/rest/internal/RestAnnotationProcessor.java @@ -429,7 +429,7 @@ public class RestAnnotationProcessor { } } catch (IllegalStateException e) { logger.trace("looking up default endpoint for %s", cma); - endpoint = injector.getInstance(Key.get(URI.class, org.jclouds.location.Provider.class)); + endpoint = injector.getInstance(Key.get(uriSupplierLiteral, org.jclouds.location.Provider.class)).get(); logger.trace("using default endpoint %s for %s", endpoint, cma); } GeneratedHttpRequest.Builder requestBuilder; diff --git a/core/src/main/java/org/jclouds/rest/internal/RestContextImpl.java b/core/src/main/java/org/jclouds/rest/internal/RestContextImpl.java index 5c8f2f3d3d..aff8b644cf 100644 --- a/core/src/main/java/org/jclouds/rest/internal/RestContextImpl.java +++ b/core/src/main/java/org/jclouds/rest/internal/RestContextImpl.java @@ -40,6 +40,7 @@ import org.jclouds.rest.annotations.BuildVersion; import org.jclouds.rest.annotations.Identity; import com.google.common.base.Objects; +import com.google.common.base.Supplier; import com.google.common.collect.ImmutableMap; import com.google.inject.Injector; import com.google.inject.Key; @@ -57,7 +58,7 @@ public class RestContextImpl implements RestContext { private final A asyncApi; private final S syncApi; private final Closer closer; - private final URI endpoint; + private final Supplier endpoint; private final String identity; private final String provider; private final String apiVersion; @@ -68,7 +69,7 @@ public class RestContextImpl implements RestContext { @Inject protected RestContextImpl(Closer closer, Map credentialStore, Utils utils, Injector injector, - TypeLiteral syncApi, TypeLiteral asyncApi, @Provider URI endpoint, @Provider String provider, + TypeLiteral syncApi, TypeLiteral asyncApi, @Provider Supplier endpoint, @Provider String provider, @Identity String identity, @ApiVersion String apiVersion, @BuildVersion String buildVersion, @Iso3166 Set iso3166Codes) { this.credentialStore = credentialStore; @@ -115,7 +116,7 @@ public class RestContextImpl implements RestContext { @Override public URI getEndpoint() { - return endpoint; + return endpoint.get(); } @Override diff --git a/core/src/test/java/org/jclouds/location/suppliers/all/JustProviderTest.java b/core/src/test/java/org/jclouds/location/suppliers/all/JustProviderTest.java index dc7b1e8837..5080ff986c 100644 --- a/core/src/test/java/org/jclouds/location/suppliers/all/JustProviderTest.java +++ b/core/src/test/java/org/jclouds/location/suppliers/all/JustProviderTest.java @@ -24,9 +24,9 @@ import java.net.URI; import org.jclouds.domain.LocationBuilder; import org.jclouds.domain.LocationScope; -import org.jclouds.location.suppliers.all.JustProvider; import org.testng.annotations.Test; +import com.google.common.base.Suppliers; import com.google.common.collect.ImmutableSet; /** @@ -39,7 +39,7 @@ public class JustProviderTest { @Test public void test() throws SecurityException, NoSuchMethodException { - JustProvider fn = new JustProvider("servo", URI.create("http://servo"), ImmutableSet.of("US")); + JustProvider fn = new JustProvider("servo", Suppliers.ofInstance(URI.create("http://servo")), ImmutableSet.of("US")); assertEquals( fn.get(), ImmutableSet.of(new LocationBuilder().scope(LocationScope.PROVIDER).id("servo").description("http://servo") diff --git a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/admin/StartVBoxIfNotAlreadyRunning.java b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/admin/StartVBoxIfNotAlreadyRunning.java index 91edfcd3bb..ee3bdf994b 100644 --- a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/admin/StartVBoxIfNotAlreadyRunning.java +++ b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/admin/StartVBoxIfNotAlreadyRunning.java @@ -57,7 +57,7 @@ public class StartVBoxIfNotAlreadyRunning implements Supplier private final Factory runScriptOnNodeFactory; private final RetryIfSocketNotYetOpen socketTester; private final Supplier host; - private final URI provider; + private final Supplier providerSupplier; private final String identity; private final String credential; private final Function, VirtualBoxManager> managerForNode; @@ -67,11 +67,11 @@ public class StartVBoxIfNotAlreadyRunning implements Supplier @Inject public StartVBoxIfNotAlreadyRunning(Function, VirtualBoxManager> managerForNode, Factory runScriptOnNodeFactory, RetryIfSocketNotYetOpen socketTester, Supplier host, - @Provider URI provider, @Identity String identity, @Credential String credential) { + @Provider Supplier providerSupplier, @Identity String identity, @Credential String credential) { this.runScriptOnNodeFactory = checkNotNull(runScriptOnNodeFactory, "runScriptOnNodeFactory"); this.socketTester = checkNotNull(socketTester, "socketTester"); this.host = checkNotNull(host, "host"); - this.provider = checkNotNull(provider, "endpoint to virtualbox websrvd is needed"); + this.providerSupplier = checkNotNull(providerSupplier, "endpoint to virtualbox websrvd is needed"); this.identity = checkNotNull(identity, "identity"); this.credential = checkNotNull(credential, "credential"); this.managerForNode = checkNotNull(managerForNode, "managerForNode"); @@ -79,6 +79,7 @@ public class StartVBoxIfNotAlreadyRunning implements Supplier @PostConstruct public void start() { + URI provider = providerSupplier.get(); if (!socketTester.apply(new IPSocket(provider.getHost(), provider.getPort()))) { logger.debug("disabling password access"); runScriptOnNodeFactory.create(host.get(), Statements.exec("VBoxManage setproperty websrvauthlibrary null"), diff --git a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/admin/StartVBoxIfNotAlreadyRunningTest.java b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/admin/StartVBoxIfNotAlreadyRunningTest.java index 6151e04969..5c75110204 100644 --- a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/admin/StartVBoxIfNotAlreadyRunningTest.java +++ b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/admin/StartVBoxIfNotAlreadyRunningTest.java @@ -19,10 +19,10 @@ package org.jclouds.virtualbox.functions.admin; +import static org.easymock.EasyMock.createMock; import static org.easymock.EasyMock.expect; -import static org.easymock.classextension.EasyMock.createMock; -import static org.easymock.classextension.EasyMock.replay; -import static org.easymock.classextension.EasyMock.verify; +import static org.easymock.EasyMock.replay; +import static org.easymock.EasyMock.verify; import static org.jclouds.compute.options.RunScriptOptions.Builder.runAsRoot; import java.net.URI; @@ -65,7 +65,7 @@ public class StartVBoxIfNotAlreadyRunningTest { replay(manager, runScriptOnNodeFactory, client); new StartVBoxIfNotAlreadyRunning((Function) Functions.constant(manager), runScriptOnNodeFactory, client, - Suppliers.ofInstance(host), provider, identity, credential).start(); + Suppliers.ofInstance(host), Suppliers.ofInstance(provider), identity, credential).start(); verify(manager, runScriptOnNodeFactory, client); @@ -103,7 +103,7 @@ public class StartVBoxIfNotAlreadyRunningTest { replay(manager, runScriptOnNodeFactory, runScriptOnNode, client); new StartVBoxIfNotAlreadyRunning((Function) Functions.constant(manager), runScriptOnNodeFactory, client, - Suppliers.ofInstance(host), provider, identity, credential).start(); + Suppliers.ofInstance(host), Suppliers.ofInstance(provider), identity, credential).start(); verify(manager, runScriptOnNodeFactory, runScriptOnNode, client); } diff --git a/providers/rimuhosting/src/main/java/org/jclouds/rimuhosting/miro/location/RimuHostingLocationSupplier.java b/providers/rimuhosting/src/main/java/org/jclouds/rimuhosting/miro/location/RimuHostingLocationSupplier.java index 9c2cd32eba..dd10add093 100644 --- a/providers/rimuhosting/src/main/java/org/jclouds/rimuhosting/miro/location/RimuHostingLocationSupplier.java +++ b/providers/rimuhosting/src/main/java/org/jclouds/rimuhosting/miro/location/RimuHostingLocationSupplier.java @@ -56,7 +56,7 @@ public class RimuHostingLocationSupplier extends JustProvider implements Locatio private final Supplier>>> isoCodesByIdSupplier; @Inject - RimuHostingLocationSupplier(@Iso3166 Set isoCodes, @Provider String providerName, @Provider URI endpoint, + RimuHostingLocationSupplier(@Iso3166 Set isoCodes, @Provider String providerName, @Provider Supplier endpoint, RimuHostingClient sync, @Iso3166 Supplier>>> isoCodesByIdSupplier) { super(providerName, endpoint, isoCodes); this.sync = checkNotNull(sync, "sync"); diff --git a/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/compute/functions/NetworkToLocation.java b/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/compute/functions/NetworkToLocation.java index c2808bdde8..bd4a7c6a04 100644 --- a/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/compute/functions/NetworkToLocation.java +++ b/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/compute/functions/NetworkToLocation.java @@ -39,6 +39,7 @@ import org.jclouds.savvis.vpdc.domain.Org; import org.jclouds.savvis.vpdc.domain.VDC; import com.google.common.base.Function; +import com.google.common.base.Supplier; /** * @author Adrian Cole @@ -49,12 +50,12 @@ public class NetworkToLocation implements Function { public static final Pattern netPattern = Pattern.compile(".*org/([0-9.]+)/vdc/([0-9.]+)/network/(.*)$"); private final String providerName; - private final URI endpoint; + private final Supplier endpoint; private final Set isoCodes; private VPDCClient client; @Inject - public NetworkToLocation(@Iso3166 Set isoCodes, @Provider String providerName, @Provider URI endpoint, + public NetworkToLocation(@Iso3166 Set isoCodes, @Provider String providerName, @Provider Supplier endpoint, VPDCClient client) { this.providerName = checkNotNull(providerName, "providerName"); this.endpoint = checkNotNull(endpoint, "endpoint"); @@ -67,7 +68,7 @@ public class NetworkToLocation implements Function { Matcher matcher = netPattern.matcher(from.getHref().toASCIIString()); if (matcher.find()) { Location provider = new LocationBuilder().scope(LocationScope.PROVIDER).id(providerName).description( - endpoint.toASCIIString()).iso3166Codes(isoCodes).build(); + endpoint.get().toASCIIString()).iso3166Codes(isoCodes).build(); Org org = client.getBrowsingClient().getOrg(matcher.group(1)); 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 966c2d878f..4c41a66d6a 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 @@ -30,6 +30,7 @@ import org.jclouds.softlayer.domain.Address; import org.jclouds.softlayer.domain.Datacenter; import org.testng.annotations.Test; +import com.google.common.base.Suppliers; import com.google.common.collect.ImmutableSet; /** @@ -40,8 +41,8 @@ import com.google.common.collect.ImmutableSet; @Test(singleThreaded = true, groups = "unit") public class DatacenterToLocationTest { - static DatacenterToLocation function = new DatacenterToLocation(new JustProvider("softlayer", URI.create("foo"), - ImmutableSet. of())); + static DatacenterToLocation function = new DatacenterToLocation(new JustProvider("softlayer", Suppliers + .ofInstance(URI.create("foo")), ImmutableSet. of())); @Test public void testDatacenterToLocation() {