diff --git a/antcontrib/src/main/java/org/jclouds/tools/ant/taskdefs/compute/ComputeTaskUtils.java b/antcontrib/src/main/java/org/jclouds/tools/ant/taskdefs/compute/ComputeTaskUtils.java index 9e67de8d7f..0c4b3c2a3b 100644 --- a/antcontrib/src/main/java/org/jclouds/tools/ant/taskdefs/compute/ComputeTaskUtils.java +++ b/antcontrib/src/main/java/org/jclouds/tools/ant/taskdefs/compute/ComputeTaskUtils.java @@ -18,8 +18,6 @@ */ package org.jclouds.tools.ant.taskdefs.compute; -import static org.jclouds.rest.RestContextFactory.getPropertiesFromResource; - import java.io.IOException; import java.net.URI; import java.util.NoSuchElementException; @@ -73,13 +71,13 @@ public class ComputeTaskUtils { @SuppressWarnings("unchecked") @Override public ComputeServiceContext load(URI from) { - Properties props = getPropertiesFromResource("/rest.properties"); + Properties props = new Properties(); props.putAll(projectProvider.get().getProperties()); // adding the properties to the factory will allow us to pass // alternate endpoints String provider = from.getHost(); Credentials creds = Credentials.parse(from); - return new ComputeServiceContextFactory(props).createContext(provider, creds.identity, creds.credential, + return new ComputeServiceContextFactory().createContext(provider, creds.identity, creds.credential, ImmutableSet.of((Module) new AntLoggingModule(projectProvider.get(), ComputeServiceConstants.COMPUTE_LOGGER), new JschSshClientModule()), props); diff --git a/apis/atmos/pom.xml b/apis/atmos/pom.xml index 5a794c889f..eac3f8804e 100644 --- a/apis/atmos/pom.xml +++ b/apis/atmos/pom.xml @@ -34,8 +34,7 @@ bundle - org.jclouds.atmos.blobstore.integration.AtmosStorageTestInitializer - https://accesspoint.atmos.com + https://accesspoint.atmosonline.com 1.3.0 FIXME diff --git a/apis/atmos/src/main/java/org/jclouds/atmos/AtmosApiMetadata.java b/apis/atmos/src/main/java/org/jclouds/atmos/AtmosApiMetadata.java index 20fe7cd5e3..1dd282eff9 100644 --- a/apis/atmos/src/main/java/org/jclouds/atmos/AtmosApiMetadata.java +++ b/apis/atmos/src/main/java/org/jclouds/atmos/AtmosApiMetadata.java @@ -18,50 +18,75 @@ */ package org.jclouds.atmos; +import static org.jclouds.blobstore.reference.BlobStoreConstants.PROPERTY_USER_METADATA_PREFIX; +import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGIONS; + import java.net.URI; +import java.util.Properties; import org.jclouds.apis.ApiMetadata; -import org.jclouds.apis.ApiType; -import org.jclouds.apis.BaseApiMetadata; +import org.jclouds.blobstore.BlobStoreContext; +import org.jclouds.blobstore.internal.BaseBlobStoreApiMetadata; + +import com.google.common.reflect.TypeToken; /** - * Implementation of {@link ApiMetadata} for EMC's Atmos API. + * Implementation of {@link ApiMetadata} for Rackspace Cloud Files API * * @author Adrian Cole */ -public class AtmosApiMetadata extends BaseApiMetadata { - - public AtmosApiMetadata() { - this(builder() - .id("atmos") - .type(ApiType.BLOBSTORE) - .name("EMC's Atmos API") - .identityName("Subtenant ID (UID)") - .credentialName("Shared Secret") - .documentation(URI.create("https://community.emc.com/docs/DOC-10508"))); +public class AtmosApiMetadata + extends + BaseBlobStoreApiMetadata, AtmosApiMetadata> { + private static Builder builder() { + return new Builder(); } - // below are so that we can reuse builders, toString, hashCode, etc. - // we have to set concrete classes here, as our base class cannot be - // concrete due to serviceLoader - protected AtmosApiMetadata(Builder builder) { + @Override + public Builder toBuilder() { + return builder().fromApiMetadata(this); + } + + public AtmosApiMetadata() { + this(builder()); + } + + protected AtmosApiMetadata(Builder builder) { super(builder); } - private static class ConcreteBuilder extends Builder { + protected static Properties defaultProperties() { + Properties properties = BaseBlobStoreApiMetadata.Builder.defaultProperties(); + properties.setProperty(PROPERTY_REGIONS, "DEFAULT"); + properties.setProperty(PROPERTY_USER_METADATA_PREFIX, "X-Object-Meta-"); + return properties; + } + + public static class Builder + extends + BaseBlobStoreApiMetadata.Builder, AtmosApiMetadata> { + protected Builder() { + id("atmos") + .name("EMC's Atmos API") + .identityName("Subtenant ID (UID)") + .credentialName("Shared Secret") + .documentation(URI.create("https://community.emc.com/docs/DOC-10508")) + .version("1.4.0") + .defaultEndpoint("https://accesspoint.atmosonline.com") + .contextBuilder(TypeToken.of(AtmosContextBuilder.class)) + .defaultProperties(AtmosApiMetadata.defaultProperties()) + .javaApi(AtmosClient.class, AtmosAsyncClient.class); + } @Override public AtmosApiMetadata build() { return new AtmosApiMetadata(this); } - } - public static ConcreteBuilder builder() { - return new ConcreteBuilder(); - } - - @Override - public ConcreteBuilder toBuilder() { - return builder().fromApiMetadata(this); + @Override + public Builder fromApiMetadata(AtmosApiMetadata in) { + super.fromApiMetadata(in); + return this; + } } } \ No newline at end of file diff --git a/apis/atmos/src/main/java/org/jclouds/atmos/AtmosContextBuilder.java b/apis/atmos/src/main/java/org/jclouds/atmos/AtmosContextBuilder.java index 19c7a16d7a..6856023dee 100644 --- a/apis/atmos/src/main/java/org/jclouds/atmos/AtmosContextBuilder.java +++ b/apis/atmos/src/main/java/org/jclouds/atmos/AtmosContextBuilder.java @@ -19,35 +19,45 @@ package org.jclouds.atmos; import java.util.List; -import java.util.Properties; import org.jclouds.atmos.blobstore.config.AtmosBlobStoreContextModule; import org.jclouds.atmos.config.AtmosRestClientModule; +import org.jclouds.blobstore.BlobStoreContext; import org.jclouds.blobstore.BlobStoreContextBuilder; import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule; import org.jclouds.logging.jdk.config.JDKLoggingModule; +import org.jclouds.providers.ProviderMetadata; import com.google.inject.Injector; import com.google.inject.Module; /** - * Creates {@link AtmosBlobStoreContext} or {@link Injector} instances based on the most commonly - * requested arguments. + * Creates {@link AtmosStoreContext} or {@link Injector} instances based on + * the most commonly requested arguments. *

- * Note that Threadsafe objects will be bound as singletons to the Injector or Context provided. + * Note that Threadsafe objects will be bound as singletons to the Injector or + * Context provided. *

*

- * If no Modules are specified, the default {@link JDKLoggingModule logging} and - * {@link JavaUrlHttpCommandExecutorServiceModule http transports} will be installed. + * If no Modules are specified, the default + * {@link JDKLoggingModule logging} and + * {@link JavaUrlHttpCommandExecutorServiceModule http transports} will be + * installed. * * @author Adrian Cole, Andrew Newdigate - * @see AtmosBlobStoreContext + * @see AtmosStoreContext */ -public class AtmosContextBuilder extends - BlobStoreContextBuilder { +public class AtmosContextBuilder + extends + BlobStoreContextBuilder, AtmosApiMetadata> { - public AtmosContextBuilder(Properties props) { - super(AtmosClient.class, AtmosAsyncClient.class, props); + public AtmosContextBuilder( + ProviderMetadata, AtmosApiMetadata> providerMetadata) { + super(providerMetadata); + } + + public AtmosContextBuilder(AtmosApiMetadata apiMetadata) { + super(apiMetadata); } @Override diff --git a/apis/atmos/src/main/java/org/jclouds/atmos/blobstore/AtmosAsyncBlobStore.java b/apis/atmos/src/main/java/org/jclouds/atmos/blobstore/AtmosAsyncBlobStore.java index 18c1b084be..7c5db767a6 100644 --- a/apis/atmos/src/main/java/org/jclouds/atmos/blobstore/AtmosAsyncBlobStore.java +++ b/apis/atmos/src/main/java/org/jclouds/atmos/blobstore/AtmosAsyncBlobStore.java @@ -85,7 +85,7 @@ public class AtmosAsyncBlobStore extends BaseAsyncBlobStore { private final LoadingCache isPublic; @Inject - AtmosAsyncBlobStore(BlobStoreContext context, BlobUtils blobUtils, + AtmosAsyncBlobStore(@SuppressWarnings("rawtypes") BlobStoreContext context, BlobUtils blobUtils, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService service, Supplier defaultLocation, @Memoized Supplier> locations, AtmosAsyncClient async, AtmosClient sync, ObjectToBlob object2Blob, ObjectToBlobMetadata object2BlobMd, BlobToObject blob2Object, diff --git a/apis/atmos/src/main/java/org/jclouds/atmos/blobstore/AtmosBlobStore.java b/apis/atmos/src/main/java/org/jclouds/atmos/blobstore/AtmosBlobStore.java index 4ba8c4b63b..5dafd49b28 100644 --- a/apis/atmos/src/main/java/org/jclouds/atmos/blobstore/AtmosBlobStore.java +++ b/apis/atmos/src/main/java/org/jclouds/atmos/blobstore/AtmosBlobStore.java @@ -73,7 +73,7 @@ public class AtmosBlobStore extends BaseBlobStore { private final LoadingCache isPublic; @Inject - AtmosBlobStore(BlobStoreContext context, BlobUtils blobUtils, Supplier defaultLocation, + AtmosBlobStore(@SuppressWarnings("rawtypes") BlobStoreContext context, BlobUtils blobUtils, Supplier defaultLocation, @Memoized Supplier> locations, AtmosClient sync, ObjectToBlob object2Blob, ObjectToBlobMetadata object2BlobMd, BlobToObject blob2Object, BlobStoreListOptionsToListOptions container2ContainerListOptions, diff --git a/apis/atmos/src/test/java/org/jclouds/atmos/AtmosApiMetadataTest.java b/apis/atmos/src/test/java/org/jclouds/atmos/AtmosApiMetadataTest.java index 9f5f407922..c9fedebe65 100644 --- a/apis/atmos/src/test/java/org/jclouds/atmos/AtmosApiMetadataTest.java +++ b/apis/atmos/src/test/java/org/jclouds/atmos/AtmosApiMetadataTest.java @@ -18,8 +18,7 @@ */ package org.jclouds.atmos; -import org.jclouds.apis.ApiType; -import org.jclouds.apis.BaseApiMetadataTest; +import org.jclouds.blobstore.internal.BaseBlobStoreApiMetadataTest; import org.testng.annotations.Test; /** @@ -27,9 +26,9 @@ import org.testng.annotations.Test; * @author Adrian Cole */ @Test(groups = "unit", testName = "AtmosApiMetadataTest") -public class AtmosApiMetadataTest extends BaseApiMetadataTest { +public class AtmosApiMetadataTest extends BaseBlobStoreApiMetadataTest { public AtmosApiMetadataTest() { - super(new AtmosApiMetadata(), ApiType.BLOBSTORE); + super(new AtmosApiMetadata()); } } diff --git a/apis/atmos/src/test/java/org/jclouds/atmos/AtmosAsyncClientTest.java b/apis/atmos/src/test/java/org/jclouds/atmos/AtmosAsyncClientTest.java index 7f41fe9b34..6722aeffc4 100644 --- a/apis/atmos/src/test/java/org/jclouds/atmos/AtmosAsyncClientTest.java +++ b/apis/atmos/src/test/java/org/jclouds/atmos/AtmosAsyncClientTest.java @@ -22,10 +22,10 @@ import static org.testng.Assert.assertEquals; import java.io.IOException; import java.lang.reflect.Method; -import java.util.Properties; import javax.ws.rs.core.HttpHeaders; +import org.jclouds.apis.ApiMetadata; import org.jclouds.atmos.blobstore.functions.BlobToObject; import org.jclouds.atmos.config.AtmosRestClientModule; import org.jclouds.atmos.domain.AtmosObject; @@ -47,12 +47,10 @@ import org.jclouds.http.functions.ParseURIFromListOrLocationHeaderIf20x; import org.jclouds.http.functions.ReleasePayloadAndReturn; import org.jclouds.http.options.GetOptions; import org.jclouds.rest.ConfiguresRestClient; -import org.jclouds.rest.RestClientTest; -import org.jclouds.rest.RestContextFactory; -import org.jclouds.rest.RestContextSpec; import org.jclouds.rest.functions.ReturnFalseOnNotFoundOr404; import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404; +import org.jclouds.rest.internal.BaseAsyncClientTest; import org.jclouds.rest.internal.RestAnnotationProcessor; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; @@ -68,7 +66,7 @@ import com.google.inject.TypeLiteral; */ // NOTE:without testName, this will not call @Before* and fail w/NPE during surefire @Test(groups = "unit", testName = "AtmosAsyncClientTest") -public class AtmosAsyncClientTest extends RestClientTest { +public class AtmosAsyncClientTest extends BaseAsyncClientTest { private BlobToObject blobToObject; @@ -339,10 +337,8 @@ public class AtmosAsyncClientTest extends RestClientTest { protected String provider = "atmos"; @Override - public RestContextSpec createContextSpec() { - Properties props = new Properties(); - props.setProperty(provider + ".endpoint", "https://accesspoint.atmosonline.com"); - return new RestContextFactory().createContextSpec(provider, "identity", "credential", props); + public ApiMetadata createApiMetadata() { + return new AtmosApiMetadata(); } } diff --git a/apis/atmos/src/test/java/org/jclouds/atmos/blobstore/AtmosBlobRequestSignerTest.java b/apis/atmos/src/test/java/org/jclouds/atmos/blobstore/AtmosBlobRequestSignerTest.java index 44c1a03591..c4f2d593be 100644 --- a/apis/atmos/src/test/java/org/jclouds/atmos/blobstore/AtmosBlobRequestSignerTest.java +++ b/apis/atmos/src/test/java/org/jclouds/atmos/blobstore/AtmosBlobRequestSignerTest.java @@ -21,8 +21,9 @@ package org.jclouds.atmos.blobstore; import static org.testng.Assert.assertEquals; import java.io.IOException; -import java.util.Properties; +import org.jclouds.apis.ApiMetadata; +import org.jclouds.atmos.AtmosApiMetadata; import org.jclouds.atmos.AtmosAsyncClient; import org.jclouds.atmos.config.AtmosRestClientModule; import org.jclouds.atmos.filters.SignRequest; @@ -33,9 +34,7 @@ import org.jclouds.date.TimeStamp; import org.jclouds.http.HttpRequest; import org.jclouds.http.RequiresHttp; import org.jclouds.rest.ConfiguresRestClient; -import org.jclouds.rest.RestClientTest; -import org.jclouds.rest.RestContextFactory; -import org.jclouds.rest.RestContextSpec; +import org.jclouds.rest.internal.BaseAsyncClientTest; import org.jclouds.rest.internal.RestAnnotationProcessor; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; @@ -51,7 +50,7 @@ import com.google.inject.TypeLiteral; */ // NOTE:without testName, this will not call @Before* and fail w/NPE during surefire @Test(groups = "unit", testName = "AtmosBlobRequestSignerTest") -public class AtmosBlobRequestSignerTest extends RestClientTest { +public class AtmosBlobRequestSignerTest extends BaseAsyncClientTest { private BlobRequestSigner signer; private Factory blobFactory; @@ -144,8 +143,8 @@ public class AtmosBlobRequestSignerTest extends RestClientTest } @Override - public RestContextSpec createContextSpec() { - return new RestContextFactory().createContextSpec("atmos", "identity", "credential", new Properties()); + public ApiMetadata createApiMetadata() { + return new AtmosApiMetadata(); } } diff --git a/apis/atmos/src/test/java/org/jclouds/atmos/blobstore/config/AtmosBlobStoreModuleTest.java b/apis/atmos/src/test/java/org/jclouds/atmos/blobstore/config/AtmosBlobStoreModuleTest.java index 7c87d6eeb9..ccf9a5c840 100644 --- a/apis/atmos/src/test/java/org/jclouds/atmos/blobstore/config/AtmosBlobStoreModuleTest.java +++ b/apis/atmos/src/test/java/org/jclouds/atmos/blobstore/config/AtmosBlobStoreModuleTest.java @@ -20,13 +20,14 @@ package org.jclouds.atmos.blobstore.config; import static org.testng.Assert.assertEquals; +import org.jclouds.atmos.AtmosApiMetadata; import org.jclouds.atmos.blobstore.strategy.FindMD5InUserMetadata; import org.jclouds.blobstore.BlobStoreContext; +import org.jclouds.blobstore.BlobStoreContextBuilder; import org.jclouds.blobstore.internal.BlobStoreContextImpl; import org.jclouds.blobstore.strategy.ContainsValueInListStrategy; import org.jclouds.logging.config.NullLoggingModule; -import org.jclouds.rest.BaseRestClientTest.MockModule; -import org.jclouds.rest.RestContextFactory; +import org.jclouds.rest.internal.BaseRestClientTest.MockModule; import org.testng.annotations.Test; import com.google.common.collect.ImmutableSet; @@ -40,15 +41,19 @@ import com.google.inject.Module; public class AtmosBlobStoreModuleTest { Injector createInjector() { - return new RestContextFactory().createContextBuilder("atmos", "uid", "key", - ImmutableSet. of(new MockModule(), new NullLoggingModule())).buildInjector(); + return BlobStoreContextBuilder + .newBuilder(new AtmosApiMetadata()) + .credentials("uid", "key") + .modules( + ImmutableSet. of(new MockModule(),new NullLoggingModule())) + .buildInjector(); } @Test void testContextImpl() { Injector injector = createInjector(); - BlobStoreContext handler = injector.getInstance(BlobStoreContext.class); + BlobStoreContext handler = injector.getInstance(BlobStoreContext.class); assertEquals(handler.getClass(), BlobStoreContextImpl.class); ContainsValueInListStrategy valueList = injector .getInstance(ContainsValueInListStrategy.class); diff --git a/apis/atmos/src/test/java/org/jclouds/atmos/blobstore/integration/AtmosBlobSignerLiveTest.java b/apis/atmos/src/test/java/org/jclouds/atmos/blobstore/integration/AtmosBlobSignerLiveTest.java index df8da0418c..8521358067 100644 --- a/apis/atmos/src/test/java/org/jclouds/atmos/blobstore/integration/AtmosBlobSignerLiveTest.java +++ b/apis/atmos/src/test/java/org/jclouds/atmos/blobstore/integration/AtmosBlobSignerLiveTest.java @@ -27,5 +27,7 @@ import org.testng.annotations.Test; */ @Test(groups = { "live" }) public class AtmosBlobSignerLiveTest extends BaseBlobSignerLiveTest { - + public AtmosBlobSignerLiveTest() { + provider = "atmos"; + } } diff --git a/apis/atmos/src/test/java/org/jclouds/atmos/blobstore/integration/AtmosContainerIntegrationLiveTest.java b/apis/atmos/src/test/java/org/jclouds/atmos/blobstore/integration/AtmosContainerIntegrationLiveTest.java index a2f31c766b..a134e0fab6 100644 --- a/apis/atmos/src/test/java/org/jclouds/atmos/blobstore/integration/AtmosContainerIntegrationLiveTest.java +++ b/apis/atmos/src/test/java/org/jclouds/atmos/blobstore/integration/AtmosContainerIntegrationLiveTest.java @@ -31,7 +31,9 @@ import org.testng.annotations.Test; */ @Test(groups = "live") public class AtmosContainerIntegrationLiveTest extends BaseContainerIntegrationTest { - + public AtmosContainerIntegrationLiveTest() { + provider = "atmos"; + } @Override public void testListContainerMaxResults() throws InterruptedException { // Not currently working diff --git a/apis/atmos/src/test/java/org/jclouds/atmos/blobstore/integration/AtmosContainerLiveTest.java b/apis/atmos/src/test/java/org/jclouds/atmos/blobstore/integration/AtmosContainerLiveTest.java index 57a690d067..90c28d9b7a 100644 --- a/apis/atmos/src/test/java/org/jclouds/atmos/blobstore/integration/AtmosContainerLiveTest.java +++ b/apis/atmos/src/test/java/org/jclouds/atmos/blobstore/integration/AtmosContainerLiveTest.java @@ -26,5 +26,7 @@ import org.testng.annotations.Test; */ @Test(groups = { "live" }) public class AtmosContainerLiveTest extends BaseContainerLiveTest { - + public AtmosContainerLiveTest() { + provider = "atmos"; + } } diff --git a/apis/atmos/src/test/java/org/jclouds/atmos/blobstore/integration/AtmosInputStreamMapIntegrationLiveTest.java b/apis/atmos/src/test/java/org/jclouds/atmos/blobstore/integration/AtmosInputStreamMapIntegrationLiveTest.java index 5e8cfd49ea..ec4fcf4e57 100644 --- a/apis/atmos/src/test/java/org/jclouds/atmos/blobstore/integration/AtmosInputStreamMapIntegrationLiveTest.java +++ b/apis/atmos/src/test/java/org/jclouds/atmos/blobstore/integration/AtmosInputStreamMapIntegrationLiveTest.java @@ -29,7 +29,10 @@ import org.testng.annotations.Test; */ @Test(groups = "live") public class AtmosInputStreamMapIntegrationLiveTest extends BaseInputStreamMapIntegrationTest { - + public AtmosInputStreamMapIntegrationLiveTest() { + provider = "atmos"; + } + @Override @Test(enabled = false) public void testContainsBytesValue() throws InterruptedException, ExecutionException, diff --git a/apis/atmos/src/test/java/org/jclouds/atmos/blobstore/integration/AtmosIntegrationLiveTest.java b/apis/atmos/src/test/java/org/jclouds/atmos/blobstore/integration/AtmosIntegrationLiveTest.java index aad3085662..56246296de 100644 --- a/apis/atmos/src/test/java/org/jclouds/atmos/blobstore/integration/AtmosIntegrationLiveTest.java +++ b/apis/atmos/src/test/java/org/jclouds/atmos/blobstore/integration/AtmosIntegrationLiveTest.java @@ -35,7 +35,9 @@ import org.testng.annotations.Test; */ @Test(groups = { "integration", "live" }) public class AtmosIntegrationLiveTest extends BaseBlobIntegrationTest { - + public AtmosIntegrationLiveTest() { + provider = "atmos"; + } @DataProvider(name = "delete") // no unicode support @Override diff --git a/apis/atmos/src/test/java/org/jclouds/atmos/blobstore/integration/AtmosLiveTest.java b/apis/atmos/src/test/java/org/jclouds/atmos/blobstore/integration/AtmosLiveTest.java index 06cf5c12c6..4c17e48f31 100644 --- a/apis/atmos/src/test/java/org/jclouds/atmos/blobstore/integration/AtmosLiveTest.java +++ b/apis/atmos/src/test/java/org/jclouds/atmos/blobstore/integration/AtmosLiveTest.java @@ -29,6 +29,9 @@ import org.testng.annotations.Test; */ @Test(groups = { "live" }) public class AtmosLiveTest extends BaseBlobLiveTest { + public AtmosLiveTest() { + provider = "atmos"; + } protected void checkMD5(String container, String name, byte[] md5) { // atmos does not support content-md5 yet assertEquals(context.getBlobStore().blobMetadata(container, name).getContentMetadata().getContentMD5(), null); diff --git a/apis/atmos/src/test/java/org/jclouds/atmos/blobstore/integration/AtmosMapIntegrationLiveTest.java b/apis/atmos/src/test/java/org/jclouds/atmos/blobstore/integration/AtmosMapIntegrationLiveTest.java index ada6ffb7b3..86d9dc5680 100644 --- a/apis/atmos/src/test/java/org/jclouds/atmos/blobstore/integration/AtmosMapIntegrationLiveTest.java +++ b/apis/atmos/src/test/java/org/jclouds/atmos/blobstore/integration/AtmosMapIntegrationLiveTest.java @@ -30,7 +30,9 @@ import org.testng.annotations.Test; */ @Test(groups = "live") public class AtmosMapIntegrationLiveTest extends BaseBlobMapIntegrationTest { - + public AtmosMapIntegrationLiveTest() { + provider = "atmos"; + } @Override // NO support for Content-MD5, so contains cannot work public void testContains() throws InterruptedException, ExecutionException, TimeoutException, IOException { diff --git a/apis/atmos/src/test/java/org/jclouds/atmos/blobstore/integration/AtmosServiceIntegrationLiveTest.java b/apis/atmos/src/test/java/org/jclouds/atmos/blobstore/integration/AtmosServiceIntegrationLiveTest.java index 47e58e83cc..a36d98e76e 100644 --- a/apis/atmos/src/test/java/org/jclouds/atmos/blobstore/integration/AtmosServiceIntegrationLiveTest.java +++ b/apis/atmos/src/test/java/org/jclouds/atmos/blobstore/integration/AtmosServiceIntegrationLiveTest.java @@ -26,5 +26,7 @@ import org.testng.annotations.Test; */ @Test(groups = "live") public class AtmosServiceIntegrationLiveTest extends BaseServiceIntegrationTest { - + public AtmosServiceIntegrationLiveTest() { + provider = "atmos"; + } } diff --git a/apis/atmos/src/test/java/org/jclouds/atmos/blobstore/integration/AtmosTestInitializer.java b/apis/atmos/src/test/java/org/jclouds/atmos/blobstore/integration/AtmosTestInitializer.java deleted file mode 100644 index 1cc02f150e..0000000000 --- a/apis/atmos/src/test/java/org/jclouds/atmos/blobstore/integration/AtmosTestInitializer.java +++ /dev/null @@ -1,47 +0,0 @@ -/** - * 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.atmos.blobstore.integration; - -import java.io.IOException; - -import org.jclouds.blobstore.BlobStoreContext; -import org.jclouds.blobstore.BlobStoreContextFactory; -import org.jclouds.blobstore.integration.TransientBlobStoreTestInitializer; -import org.jclouds.logging.log4j.config.Log4JLoggingModule; - -import com.google.common.collect.ImmutableSet; -import com.google.inject.Module; - -/** - * - * @author Adrian Cole - */ -public class AtmosTestInitializer extends TransientBlobStoreTestInitializer { - public AtmosTestInitializer() { - provider = "synaptic"; - } - - @Override - protected BlobStoreContext createLiveContext(Module configurationModule, String endpoint, String apiVersion, - String buildVersion, String app, String identity, String credential) throws IOException { - return new BlobStoreContextFactory().createContext(provider, ImmutableSet.of(configurationModule, - new Log4JLoggingModule()), setupProperties(endpoint, apiVersion, buildVersion, identity, credential)); - } - -} diff --git a/apis/atmos/src/test/java/org/jclouds/atmos/filters/SignRequestTest.java b/apis/atmos/src/test/java/org/jclouds/atmos/filters/SignRequestTest.java index 8e4caeb019..dc07a557d8 100644 --- a/apis/atmos/src/test/java/org/jclouds/atmos/filters/SignRequestTest.java +++ b/apis/atmos/src/test/java/org/jclouds/atmos/filters/SignRequestTest.java @@ -24,20 +24,19 @@ import java.io.IOException; import java.net.URI; import java.security.InvalidKeyException; import java.security.NoSuchAlgorithmException; -import java.util.Properties; import javax.ws.rs.core.HttpHeaders; import javax.ws.rs.core.MediaType; import org.jclouds.atmos.config.AtmosRestClientModule; import org.jclouds.atmos.reference.AtmosHeaders; +import org.jclouds.blobstore.BlobStoreContextBuilder; import org.jclouds.date.TimeStamp; import org.jclouds.http.HttpRequest; import org.jclouds.http.RequiresHttp; import org.jclouds.logging.config.NullLoggingModule; -import org.jclouds.rest.BaseRestClientTest.MockModule; import org.jclouds.rest.ConfiguresRestClient; -import org.jclouds.rest.RestContextFactory; +import org.jclouds.rest.internal.BaseRestClientTest.MockModule; import org.jclouds.util.Strings2; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; @@ -98,13 +97,12 @@ public class SignRequestTest { @BeforeClass protected void createFilter() { - Injector injector = new RestContextFactory() - .createContextBuilder( - "atmos", - UID, - KEY, - ImmutableSet. of(new MockModule(), new TestAtmosRestClientModule(), - new NullLoggingModule()), new Properties()).buildInjector(); + Injector injector = BlobStoreContextBuilder + .newBuilder("atmos") + .credentials(UID, KEY) + .modules( + ImmutableSet. of(new MockModule(), new TestAtmosRestClientModule(), new NullLoggingModule())) + .buildInjector(); filter = injector.getInstance(SignRequest.class); diff --git a/apis/byon/src/main/java/org/jclouds/byon/BYONApiMetadata.java b/apis/byon/src/main/java/org/jclouds/byon/BYONApiMetadata.java index b818a6ef33..a094713c0b 100644 --- a/apis/byon/src/main/java/org/jclouds/byon/BYONApiMetadata.java +++ b/apis/byon/src/main/java/org/jclouds/byon/BYONApiMetadata.java @@ -19,49 +19,74 @@ package org.jclouds.byon; import java.net.URI; +import java.util.Properties; +import org.jclouds.JcloudsVersion; import org.jclouds.apis.ApiMetadata; -import org.jclouds.apis.ApiType; -import org.jclouds.apis.BaseApiMetadata; +import org.jclouds.compute.ComputeServiceContext; +import org.jclouds.compute.internal.BaseComputeServiceApiMetadata; + +import com.google.common.base.Supplier; +import com.google.common.reflect.TypeToken; /** * Implementation of {@link ApiMetadata} for jclouds BYON API * + *

note

+ * + * This class is not setup to allow a subclasses to override the type of api, + * asyncapi, or context. This is an optimization for s. + * * @author Adrian Cole */ -public class BYONApiMetadata extends BaseApiMetadata { +@SuppressWarnings("rawtypes") +public class BYONApiMetadata extends BaseComputeServiceApiMetadata, BYONApiMetadata> { - public BYONApiMetadata() { - this(builder() - .id("byon") - .type(ApiType.COMPUTE) - .name("Bring Your Own Node (BYON) API") - .identityName("Unused") - .documentation(URI.create("https://github.com/jclouds/jclouds/tree/master/apis/byon"))); + @Override + public Builder toBuilder() { + return new Builder().fromApiMetadata(this); } - // below are so that we can reuse builders, toString, hashCode, etc. - // we have to set concrete classes here, as our base class cannot be - // concrete due to serviceLoader - protected BYONApiMetadata(Builder builder) { + public BYONApiMetadata() { + this(new Builder()); + } + + protected BYONApiMetadata(Builder builder) { super(builder); } - private static class ConcreteBuilder extends Builder { + protected static Properties defaultProperties() { + return BaseComputeServiceApiMetadata.Builder.defaultProperties(); + } + + public static class Builder extends BaseComputeServiceApiMetadata.Builder, BYONApiMetadata> { + + protected Builder() { + id("byon") + .name("Bring Your Own Node (BYON) API") + .identityName("Unused") + .defaultIdentity("foo") + .defaultCredential("bar") + .defaultEndpoint("file://byon.yaml") + .documentation(URI.create("https://github.com/jclouds/jclouds/tree/master/apis/byon")) + .version(String.format("%s.%s", JcloudsVersion.get().majorVersion, JcloudsVersion.get().minorVersion)) + .buildVersion(JcloudsVersion.get().toString()) + .defaultProperties(BYONApiMetadata.defaultProperties()) + .javaApi(Supplier.class, Supplier.class) + .contextBuilder(TypeToken.of(BYONComputeServiceContextBuilder.class)); + } @Override public BYONApiMetadata build() { return new BYONApiMetadata(this); } - } - public static ConcreteBuilder builder() { - return new ConcreteBuilder(); - } + @Override + public Builder fromApiMetadata(BYONApiMetadata in) { + super.fromApiMetadata(in); + return this; + } - @Override - public ConcreteBuilder toBuilder() { - return builder().fromApiMetadata(this); } } \ No newline at end of file diff --git a/apis/byon/src/main/java/org/jclouds/byon/BYONComputeServiceContextBuilder.java b/apis/byon/src/main/java/org/jclouds/byon/BYONComputeServiceContextBuilder.java index 15bdb626a9..2def88a0d3 100644 --- a/apis/byon/src/main/java/org/jclouds/byon/BYONComputeServiceContextBuilder.java +++ b/apis/byon/src/main/java/org/jclouds/byon/BYONComputeServiceContextBuilder.java @@ -19,12 +19,13 @@ package org.jclouds.byon; import java.util.List; -import java.util.Properties; import org.jclouds.byon.config.BYONComputeServiceContextModule; import org.jclouds.byon.config.ConfiguresNodeStore; import org.jclouds.byon.config.YamlNodeStoreModule; +import org.jclouds.compute.ComputeServiceContext; import org.jclouds.compute.StandaloneComputeServiceContextBuilder; +import org.jclouds.providers.ProviderMetadata; import com.google.common.base.Predicate; import com.google.common.base.Supplier; @@ -36,12 +37,17 @@ import com.google.inject.Module; * @author Adrian Cole */ @SuppressWarnings("rawtypes") -public class BYONComputeServiceContextBuilder extends StandaloneComputeServiceContextBuilder { +public class BYONComputeServiceContextBuilder extends StandaloneComputeServiceContextBuilder, BYONApiMetadata> { - public BYONComputeServiceContextBuilder(Properties props) { - super(Supplier.class, props); + public BYONComputeServiceContextBuilder( + ProviderMetadata, BYONApiMetadata> providerMetadata) { + super(providerMetadata); } - + + public BYONComputeServiceContextBuilder(BYONApiMetadata apiMetadata) { + super(apiMetadata); + } + @Override protected void addContextModule(List modules) { modules.add(new BYONComputeServiceContextModule()); diff --git a/apis/byon/src/main/java/org/jclouds/byon/BYONPropertiesBuilder.java b/apis/byon/src/main/java/org/jclouds/byon/BYONPropertiesBuilder.java deleted file mode 100644 index 5965595704..0000000000 --- a/apis/byon/src/main/java/org/jclouds/byon/BYONPropertiesBuilder.java +++ /dev/null @@ -1,48 +0,0 @@ -/** - * 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.byon; - -import static org.jclouds.Constants.PROPERTY_API_VERSION; -import static org.jclouds.Constants.PROPERTY_CREDENTIAL; -import static org.jclouds.Constants.PROPERTY_IDENTITY; - -import java.util.Properties; - -import org.jclouds.PropertiesBuilder; - -/** - * Builds properties used in byon Clients - * - * @author Adrian Cole - */ -public class BYONPropertiesBuilder extends PropertiesBuilder { - @Override - protected Properties defaultProperties() { - Properties properties = super.defaultProperties(); - properties.setProperty(PROPERTY_API_VERSION, "1.0"); - properties.setProperty(PROPERTY_IDENTITY, "foo"); - properties.setProperty(PROPERTY_CREDENTIAL, "bar"); - return properties; - } - - public BYONPropertiesBuilder(Properties properties) { - super(properties); - } - -} diff --git a/apis/byon/src/test/java/org/jclouds/byon/BYONApiMetadataTest.java b/apis/byon/src/test/java/org/jclouds/byon/BYONApiMetadataTest.java index 6265ff3c0e..2e0fb1bd98 100644 --- a/apis/byon/src/test/java/org/jclouds/byon/BYONApiMetadataTest.java +++ b/apis/byon/src/test/java/org/jclouds/byon/BYONApiMetadataTest.java @@ -18,8 +18,7 @@ */ package org.jclouds.byon; -import org.jclouds.apis.ApiType; -import org.jclouds.apis.BaseApiMetadataTest; +import org.jclouds.compute.internal.BaseComputeServiceApiMetadataTest; import org.testng.annotations.Test; /** @@ -27,9 +26,9 @@ import org.testng.annotations.Test; * @author Adrian Cole */ @Test(groups = "unit", testName = "BYONApiMetadataTest") -public class BYONApiMetadataTest extends BaseApiMetadataTest { +public class BYONApiMetadataTest extends BaseComputeServiceApiMetadataTest { public BYONApiMetadataTest() { - super(new BYONApiMetadata(), ApiType.COMPUTE); + super(new BYONApiMetadata()); } } diff --git a/apis/byon/src/test/java/org/jclouds/byon/BYONComputeServiceLiveTest.java b/apis/byon/src/test/java/org/jclouds/byon/BYONComputeServiceLiveTest.java index 60b1a286d2..4668ad7a45 100644 --- a/apis/byon/src/test/java/org/jclouds/byon/BYONComputeServiceLiveTest.java +++ b/apis/byon/src/test/java/org/jclouds/byon/BYONComputeServiceLiveTest.java @@ -28,10 +28,10 @@ import java.util.Map.Entry; import java.util.Properties; import org.jclouds.compute.ComputeServiceContext; -import org.jclouds.compute.ComputeServiceContextFactory; import org.jclouds.compute.domain.ExecResponse; import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.logging.log4j.config.Log4JLoggingModule; +import org.jclouds.rest.internal.ContextBuilder; import org.jclouds.scriptbuilder.domain.OsFamily; import org.jclouds.sshj.config.SshjSshClientModule; import org.testng.annotations.AfterClass; @@ -49,7 +49,7 @@ import com.google.inject.Module; @Test(groups = "live") public class BYONComputeServiceLiveTest { - private ComputeServiceContext context; + private ComputeServiceContext context; @BeforeClass(groups = "live") public void setup() throws FileNotFoundException, IOException { @@ -72,9 +72,8 @@ public class BYONComputeServiceLiveTest { .append("\n"); contextProperties.setProperty("byon.nodes", nodes.toString()); - - context = new ComputeServiceContextFactory().createContext("byon", "foo", "bar", ImmutableSet. of( - new SshjSshClientModule(), new Log4JLoggingModule()), contextProperties); + context = ContextBuilder.newBuilder(new BYONApiMetadata()).overrides(contextProperties) + .modules(ImmutableSet. of(new SshjSshClientModule(), new Log4JLoggingModule())).build(); } public void testCanRunCommandAsCurrentUser() throws Exception { diff --git a/apis/byon/src/test/java/org/jclouds/byon/BYONComputeServiceTest.java b/apis/byon/src/test/java/org/jclouds/byon/BYONComputeServiceTest.java index 2a86fb13d0..ded60ea37f 100644 --- a/apis/byon/src/test/java/org/jclouds/byon/BYONComputeServiceTest.java +++ b/apis/byon/src/test/java/org/jclouds/byon/BYONComputeServiceTest.java @@ -24,15 +24,15 @@ import static org.jclouds.byon.functions.NodeToNodeMetadataTest.zoneCalled; import static org.testng.Assert.assertEquals; import java.net.URI; -import java.util.Properties; import org.jclouds.byon.config.CacheNodeStoreModule; import org.jclouds.byon.functions.NodesFromYamlTest; import org.jclouds.compute.ComputeServiceContext; -import org.jclouds.compute.ComputeServiceContextFactory; import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.domain.Location; import org.jclouds.domain.LoginCredentials; +import org.jclouds.rest.AnonymousProviderMetadata; +import org.jclouds.rest.internal.ContextBuilder; import org.testng.annotations.Test; import com.google.common.base.Supplier; @@ -68,13 +68,13 @@ public class BYONComputeServiceTest { } private void assertNodesParse(String endpoint, Iterable modules) { - ComputeServiceContext context = null; + ComputeServiceContext context = null; try { Location providerLocation = expectedProviderLocationFromResource(endpoint); - Properties props = new Properties(); - props.setProperty("byon.endpoint", endpoint); - context = new ComputeServiceContextFactory().createContext("byon", "foo", "bar", modules, props); + context = ContextBuilder.newBuilder( + AnonymousProviderMetadata.forApiWithEndpoint(new BYONApiMetadata(), endpoint)) + .modules(modules).build(); assertEquals(context.getProviderSpecificContext().getEndpoint(), URI.create(endpoint)); @@ -96,13 +96,11 @@ public class BYONComputeServiceTest { } public void testNodesWithLocations() { - ComputeServiceContext context = null; + ComputeServiceContext context = null; try { String endpoint = "file://" + getClass().getResource("/test_location.yaml").getPath(); - Properties props = new Properties(); - props.setProperty("byon.endpoint", endpoint); - context = new ComputeServiceContextFactory().createContext("byon", "foo", "bar", ImmutableSet. of(), - props); + context = ContextBuilder.newBuilder( + AnonymousProviderMetadata.forApiWithEndpoint(new BYONApiMetadata(), endpoint)).build(); assertEquals(context.getProviderSpecificContext().getEndpoint(), URI.create(endpoint)); diff --git a/apis/cloudfiles/pom.xml b/apis/cloudfiles/pom.xml index a7bb4b0e4a..13bb997d70 100644 --- a/apis/cloudfiles/pom.xml +++ b/apis/cloudfiles/pom.xml @@ -34,7 +34,6 @@ bundle - org.jclouds.cloudfiles.blobstore.integration.CloudFilesTestInitializer https://auth.api.rackspacecloud.com 1.0 @@ -107,7 +106,6 @@ - ${test.initializer} ${jclouds.blobstore.httpstream.url} ${jclouds.blobstore.httpstream.md5} ${test.cloudfiles.endpoint} diff --git a/apis/cloudfiles/src/main/java/org/jclouds/cloudfiles/CloudFilesApiMetadata.java b/apis/cloudfiles/src/main/java/org/jclouds/cloudfiles/CloudFilesApiMetadata.java index 654c040c04..5d7cf50a69 100644 --- a/apis/cloudfiles/src/main/java/org/jclouds/cloudfiles/CloudFilesApiMetadata.java +++ b/apis/cloudfiles/src/main/java/org/jclouds/cloudfiles/CloudFilesApiMetadata.java @@ -18,51 +18,75 @@ */ package org.jclouds.cloudfiles; +import static org.jclouds.blobstore.reference.BlobStoreConstants.PROPERTY_USER_METADATA_PREFIX; +import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGIONS; + import java.net.URI; +import java.util.Properties; import org.jclouds.apis.ApiMetadata; -import org.jclouds.apis.ApiType; -import org.jclouds.apis.BaseApiMetadata; +import org.jclouds.blobstore.BlobStoreContext; +import org.jclouds.blobstore.internal.BaseBlobStoreApiMetadata; +import org.jclouds.openstack.OpenStackAuthAsyncClient; + +import com.google.common.reflect.TypeToken; /** * Implementation of {@link ApiMetadata} for Rackspace Cloud Files API * - * @author Dan Lo Bianco + * @author Adrian Cole */ -public class CloudFilesApiMetadata extends BaseApiMetadata { - - public CloudFilesApiMetadata() { - this(builder() - .id("cloudfiles") - .type(ApiType.BLOBSTORE) - .name("Rackspace Cloud Files API") - .identityName("Username") - .credentialName("API Key") - .documentation(URI.create("http://docs.rackspacecloud.com/files/api/v1/cfdevguide_d5/content/ch01.html"))); +public class CloudFilesApiMetadata + extends + BaseBlobStoreApiMetadata, CloudFilesApiMetadata> { + private static Builder builder() { + return new Builder(); } - // below are so that we can reuse builders, toString, hashCode, etc. - // we have to set concrete classes here, as our base class cannot be - // concrete due to serviceLoader - protected CloudFilesApiMetadata(Builder builder) { + @Override + public Builder toBuilder() { + return builder().fromApiMetadata(this); + } + + public CloudFilesApiMetadata() { + this(builder()); + } + + protected CloudFilesApiMetadata(Builder builder) { super(builder); } - private static class ConcreteBuilder extends Builder { + protected static Properties defaultProperties() { + Properties properties = BaseBlobStoreApiMetadata.Builder.defaultProperties(); + properties.setProperty(PROPERTY_REGIONS, "DEFAULT"); + properties.setProperty(PROPERTY_USER_METADATA_PREFIX, "X-Object-Meta-"); + return properties; + } + + public static class Builder + extends + BaseBlobStoreApiMetadata.Builder, CloudFilesApiMetadata> { + protected Builder() { + id("cloudfiles") + .name("Rackspace Cloud Files API") + .identityName("Username") + .credentialName("API Key") + .documentation(URI.create("http://docs.rackspacecloud.com/files/api/v1/cfdevguide_d5/content/ch01.html")) + .version(OpenStackAuthAsyncClient.VERSION) + .contextBuilder(TypeToken.of(CloudFilesContextBuilder.class)) + .defaultProperties(CloudFilesApiMetadata.defaultProperties()) + .javaApi(CloudFilesClient.class, CloudFilesAsyncClient.class); + } @Override public CloudFilesApiMetadata build() { return new CloudFilesApiMetadata(this); } - } - public static ConcreteBuilder builder() { - return new ConcreteBuilder(); + @Override + public Builder fromApiMetadata(CloudFilesApiMetadata in) { + super.fromApiMetadata(in); + return this; + } } - - @Override - public ConcreteBuilder toBuilder() { - return builder().fromApiMetadata(this); - } - } \ No newline at end of file diff --git a/apis/cloudfiles/src/main/java/org/jclouds/cloudfiles/CloudFilesContextBuilder.java b/apis/cloudfiles/src/main/java/org/jclouds/cloudfiles/CloudFilesContextBuilder.java index 05f95822f4..84f966e358 100644 --- a/apis/cloudfiles/src/main/java/org/jclouds/cloudfiles/CloudFilesContextBuilder.java +++ b/apis/cloudfiles/src/main/java/org/jclouds/cloudfiles/CloudFilesContextBuilder.java @@ -19,34 +19,45 @@ package org.jclouds.cloudfiles; import java.util.List; -import java.util.Properties; +import org.jclouds.blobstore.BlobStoreContext; import org.jclouds.blobstore.BlobStoreContextBuilder; import org.jclouds.cloudfiles.blobstore.config.CloudFilesBlobStoreContextModule; import org.jclouds.cloudfiles.config.CloudFilesRestClientModule; import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule; import org.jclouds.logging.jdk.config.JDKLoggingModule; +import org.jclouds.providers.ProviderMetadata; import com.google.inject.Injector; import com.google.inject.Module; /** - * Creates {@link CloudFilesBlobStoreContext} or {@link Injector} instances based on the most - * commonly requested arguments. + * Creates {@link CloudFilesStoreContext} or {@link Injector} instances based on + * the most commonly requested arguments. *

- * Note that Threadsafe objects will be bound as singletons to the Injector or Context provided. + * Note that Threadsafe objects will be bound as singletons to the Injector or + * Context provided. *

*

- * If no Modules are specified, the default {@link JDKLoggingModule logging} and - * {@link JavaUrlHttpCommandExecutorServiceModule http transports} will be installed. + * If no Modules are specified, the default + * {@link JDKLoggingModule logging} and + * {@link JavaUrlHttpCommandExecutorServiceModule http transports} will be + * installed. * * @author Adrian Cole, Andrew Newdigate - * @see CloudFilesBlobStoreContext + * @see CloudFilesStoreContext */ -public class CloudFilesContextBuilder extends BlobStoreContextBuilder { +public class CloudFilesContextBuilder + extends + BlobStoreContextBuilder, CloudFilesApiMetadata> { - public CloudFilesContextBuilder(Properties props) { - super(CloudFilesClient.class, CloudFilesAsyncClient.class, props); + public CloudFilesContextBuilder( + ProviderMetadata, CloudFilesApiMetadata> providerMetadata) { + super(providerMetadata); + } + + public CloudFilesContextBuilder(CloudFilesApiMetadata apiMetadata) { + super(apiMetadata); } @Override diff --git a/apis/cloudfiles/src/main/java/org/jclouds/cloudfiles/blobstore/CloudFilesAsyncBlobStore.java b/apis/cloudfiles/src/main/java/org/jclouds/cloudfiles/blobstore/CloudFilesAsyncBlobStore.java index 34b61b03de..af064f61c1 100644 --- a/apis/cloudfiles/src/main/java/org/jclouds/cloudfiles/blobstore/CloudFilesAsyncBlobStore.java +++ b/apis/cloudfiles/src/main/java/org/jclouds/cloudfiles/blobstore/CloudFilesAsyncBlobStore.java @@ -59,7 +59,7 @@ public class CloudFilesAsyncBlobStore extends SwiftAsyncBlobStore { private final EnableCDNAndCache enableCDNAndCache; @Inject - protected CloudFilesAsyncBlobStore(BlobStoreContext context, BlobUtils blobUtils, + protected CloudFilesAsyncBlobStore(@SuppressWarnings("rawtypes") BlobStoreContext context, BlobUtils blobUtils, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService service, Supplier defaultLocation, @Memoized Supplier> locations, CloudFilesClient sync, CloudFilesAsyncClient async, ContainerToResourceMetadata container2ResourceMd, diff --git a/apis/cloudfiles/src/main/java/org/jclouds/cloudfiles/blobstore/CloudFilesBlobStore.java b/apis/cloudfiles/src/main/java/org/jclouds/cloudfiles/blobstore/CloudFilesBlobStore.java index 42be6d884c..d7309f99bc 100644 --- a/apis/cloudfiles/src/main/java/org/jclouds/cloudfiles/blobstore/CloudFilesBlobStore.java +++ b/apis/cloudfiles/src/main/java/org/jclouds/cloudfiles/blobstore/CloudFilesBlobStore.java @@ -53,7 +53,7 @@ public class CloudFilesBlobStore extends SwiftBlobStore { private EnableCDNAndCache enableCDNAndCache; @Inject - protected CloudFilesBlobStore(BlobStoreContext context, BlobUtils blobUtils, Supplier defaultLocation, + protected CloudFilesBlobStore(@SuppressWarnings("rawtypes") BlobStoreContext context, BlobUtils blobUtils, Supplier defaultLocation, @Memoized Supplier> locations, CommonSwiftClient sync, ContainerToResourceMetadata container2ResourceMd, BlobStoreListContainerOptionsToListContainerOptions container2ContainerListOptions, diff --git a/apis/cloudfiles/src/test/java/org/jclouds/cloudfiles/CloudFilesApiMetadataTest.java b/apis/cloudfiles/src/test/java/org/jclouds/cloudfiles/CloudFilesApiMetadataTest.java index 2672d7e980..ba6a4d55c9 100644 --- a/apis/cloudfiles/src/test/java/org/jclouds/cloudfiles/CloudFilesApiMetadataTest.java +++ b/apis/cloudfiles/src/test/java/org/jclouds/cloudfiles/CloudFilesApiMetadataTest.java @@ -18,8 +18,7 @@ */ package org.jclouds.cloudfiles; -import org.jclouds.apis.ApiType; -import org.jclouds.apis.BaseApiMetadataTest; +import org.jclouds.blobstore.internal.BaseBlobStoreApiMetadataTest; import org.testng.annotations.Test; /** @@ -27,9 +26,9 @@ import org.testng.annotations.Test; * @author Adrian Cole */ @Test(groups = "unit", testName = "CloudFilesApiMetadataTest") -public class CloudFilesApiMetadataTest extends BaseApiMetadataTest { +public class CloudFilesApiMetadataTest extends BaseBlobStoreApiMetadataTest { public CloudFilesApiMetadataTest() { - super(new CloudFilesApiMetadata(), ApiType.BLOBSTORE); + super(new CloudFilesApiMetadata()); } } diff --git a/apis/cloudfiles/src/test/java/org/jclouds/cloudfiles/CloudFilesClientLiveTest.java b/apis/cloudfiles/src/test/java/org/jclouds/cloudfiles/CloudFilesClientLiveTest.java index 7c5706a761..91bd107f73 100644 --- a/apis/cloudfiles/src/test/java/org/jclouds/cloudfiles/CloudFilesClientLiveTest.java +++ b/apis/cloudfiles/src/test/java/org/jclouds/cloudfiles/CloudFilesClientLiveTest.java @@ -41,6 +41,10 @@ import com.google.common.collect.Iterables; @Test(groups = "live") public class CloudFilesClientLiveTest extends CommonSwiftClientLiveTest { + public CloudFilesClientLiveTest(){ + provider = "cloudfiles"; + } + @Override public CloudFilesClient getApi() { return (CloudFilesClient) context.getProviderSpecificContext().getApi(); diff --git a/apis/cloudfiles/src/test/java/org/jclouds/cloudfiles/blobstore/integration/CloudFilesBlobIntegrationLiveTest.java b/apis/cloudfiles/src/test/java/org/jclouds/cloudfiles/blobstore/integration/CloudFilesBlobIntegrationLiveTest.java index 5dc7f166eb..ce04b4f47e 100644 --- a/apis/cloudfiles/src/test/java/org/jclouds/cloudfiles/blobstore/integration/CloudFilesBlobIntegrationLiveTest.java +++ b/apis/cloudfiles/src/test/java/org/jclouds/cloudfiles/blobstore/integration/CloudFilesBlobIntegrationLiveTest.java @@ -28,6 +28,10 @@ import org.testng.annotations.Test; */ @Test(groups = "live") public class CloudFilesBlobIntegrationLiveTest extends SwiftBlobIntegrationLiveTest { + public CloudFilesBlobIntegrationLiveTest(){ + provider = "cloudfiles"; + } + @Override protected void checkContentDisposition(Blob blob, String contentDisposition) { assert blob.getPayload().getContentMetadata().getContentDisposition().startsWith(contentDisposition) : blob diff --git a/apis/cloudfiles/src/test/java/org/jclouds/cloudfiles/blobstore/integration/CloudFilesBlobLiveTest.java b/apis/cloudfiles/src/test/java/org/jclouds/cloudfiles/blobstore/integration/CloudFilesBlobLiveTest.java index cb66f7c794..edae3c1abf 100644 --- a/apis/cloudfiles/src/test/java/org/jclouds/cloudfiles/blobstore/integration/CloudFilesBlobLiveTest.java +++ b/apis/cloudfiles/src/test/java/org/jclouds/cloudfiles/blobstore/integration/CloudFilesBlobLiveTest.java @@ -27,5 +27,7 @@ import org.testng.annotations.Test; */ @Test(groups = { "live" }) public class CloudFilesBlobLiveTest extends SwiftBlobLiveTest { - + public CloudFilesBlobLiveTest(){ + provider = "cloudfiles"; + } } diff --git a/apis/cloudfiles/src/test/java/org/jclouds/cloudfiles/blobstore/integration/CloudFilesBlobMapIntegrationLiveTest.java b/apis/cloudfiles/src/test/java/org/jclouds/cloudfiles/blobstore/integration/CloudFilesBlobMapIntegrationLiveTest.java index ff7a240fee..e091cc1642 100644 --- a/apis/cloudfiles/src/test/java/org/jclouds/cloudfiles/blobstore/integration/CloudFilesBlobMapIntegrationLiveTest.java +++ b/apis/cloudfiles/src/test/java/org/jclouds/cloudfiles/blobstore/integration/CloudFilesBlobMapIntegrationLiveTest.java @@ -26,5 +26,7 @@ import org.testng.annotations.Test; */ @Test(groups = "live") public class CloudFilesBlobMapIntegrationLiveTest extends SwiftBlobMapIntegrationLiveTest { - + public CloudFilesBlobMapIntegrationLiveTest(){ + provider = "cloudfiles"; + } } diff --git a/apis/cloudfiles/src/test/java/org/jclouds/cloudfiles/blobstore/integration/CloudFilesBlobSignerLiveTest.java b/apis/cloudfiles/src/test/java/org/jclouds/cloudfiles/blobstore/integration/CloudFilesBlobSignerLiveTest.java index 1437aa506e..7add9a211d 100644 --- a/apis/cloudfiles/src/test/java/org/jclouds/cloudfiles/blobstore/integration/CloudFilesBlobSignerLiveTest.java +++ b/apis/cloudfiles/src/test/java/org/jclouds/cloudfiles/blobstore/integration/CloudFilesBlobSignerLiveTest.java @@ -27,5 +27,7 @@ import org.testng.annotations.Test; */ @Test(groups = { "live" }) public class CloudFilesBlobSignerLiveTest extends SwiftBlobSignerLiveTest { - + public CloudFilesBlobSignerLiveTest(){ + provider = "cloudfiles"; + } } diff --git a/apis/cloudfiles/src/test/java/org/jclouds/cloudfiles/blobstore/integration/CloudFilesContainerIntegrationLiveTest.java b/apis/cloudfiles/src/test/java/org/jclouds/cloudfiles/blobstore/integration/CloudFilesContainerIntegrationLiveTest.java index f55abb8f77..c9dc3f6cf0 100644 --- a/apis/cloudfiles/src/test/java/org/jclouds/cloudfiles/blobstore/integration/CloudFilesContainerIntegrationLiveTest.java +++ b/apis/cloudfiles/src/test/java/org/jclouds/cloudfiles/blobstore/integration/CloudFilesContainerIntegrationLiveTest.java @@ -26,5 +26,7 @@ import org.testng.annotations.Test; */ @Test(groups = "live") public class CloudFilesContainerIntegrationLiveTest extends SwiftContainerIntegrationLiveTest { - + public CloudFilesContainerIntegrationLiveTest(){ + provider = "cloudfiles"; + } } diff --git a/apis/cloudfiles/src/test/java/org/jclouds/cloudfiles/blobstore/integration/CloudFilesContainerLiveTest.java b/apis/cloudfiles/src/test/java/org/jclouds/cloudfiles/blobstore/integration/CloudFilesContainerLiveTest.java index 86b7a471e5..11217a5c10 100644 --- a/apis/cloudfiles/src/test/java/org/jclouds/cloudfiles/blobstore/integration/CloudFilesContainerLiveTest.java +++ b/apis/cloudfiles/src/test/java/org/jclouds/cloudfiles/blobstore/integration/CloudFilesContainerLiveTest.java @@ -26,5 +26,7 @@ import org.testng.annotations.Test; */ @Test(groups = { "live" }) public class CloudFilesContainerLiveTest extends BaseContainerLiveTest { - + public CloudFilesContainerLiveTest(){ + provider = "cloudfiles"; + } } diff --git a/apis/cloudfiles/src/test/java/org/jclouds/cloudfiles/blobstore/integration/CloudFilesInputStreamMapIntegrationLiveTest.java b/apis/cloudfiles/src/test/java/org/jclouds/cloudfiles/blobstore/integration/CloudFilesInputStreamMapIntegrationLiveTest.java index c4f99d274e..1fd19dc1cc 100644 --- a/apis/cloudfiles/src/test/java/org/jclouds/cloudfiles/blobstore/integration/CloudFilesInputStreamMapIntegrationLiveTest.java +++ b/apis/cloudfiles/src/test/java/org/jclouds/cloudfiles/blobstore/integration/CloudFilesInputStreamMapIntegrationLiveTest.java @@ -26,5 +26,7 @@ import org.testng.annotations.Test; */ @Test(groups = "live") public class CloudFilesInputStreamMapIntegrationLiveTest extends SwiftInputStreamMapIntegrationLiveTest { - + public CloudFilesInputStreamMapIntegrationLiveTest(){ + provider = "cloudfiles"; + } } diff --git a/apis/cloudfiles/src/test/java/org/jclouds/cloudfiles/blobstore/integration/CloudFilesServiceIntegrationLiveTest.java b/apis/cloudfiles/src/test/java/org/jclouds/cloudfiles/blobstore/integration/CloudFilesServiceIntegrationLiveTest.java index 1265764550..c89574c8e6 100644 --- a/apis/cloudfiles/src/test/java/org/jclouds/cloudfiles/blobstore/integration/CloudFilesServiceIntegrationLiveTest.java +++ b/apis/cloudfiles/src/test/java/org/jclouds/cloudfiles/blobstore/integration/CloudFilesServiceIntegrationLiveTest.java @@ -26,5 +26,7 @@ import org.testng.annotations.Test; */ @Test(groups = "live") public class CloudFilesServiceIntegrationLiveTest extends SwiftServiceIntegrationLiveTest { - + public CloudFilesServiceIntegrationLiveTest(){ + provider = "cloudfiles"; + } } diff --git a/apis/cloudloadbalancers/src/main/java/org/jclouds/cloudloadbalancers/CloudLoadBalancersApiMetadata.java b/apis/cloudloadbalancers/src/main/java/org/jclouds/cloudloadbalancers/CloudLoadBalancersApiMetadata.java index 4885acb21d..0cadebfbc6 100644 --- a/apis/cloudloadbalancers/src/main/java/org/jclouds/cloudloadbalancers/CloudLoadBalancersApiMetadata.java +++ b/apis/cloudloadbalancers/src/main/java/org/jclouds/cloudloadbalancers/CloudLoadBalancersApiMetadata.java @@ -19,50 +19,71 @@ package org.jclouds.cloudloadbalancers; import java.net.URI; +import java.util.Properties; import org.jclouds.apis.ApiMetadata; import org.jclouds.apis.ApiType; -import org.jclouds.apis.BaseApiMetadata; +import org.jclouds.loadbalancer.LoadBalancerServiceContext; +import org.jclouds.loadbalancer.internal.BaseLoadBalancerServiceApiMetadata; +import org.jclouds.openstack.OpenStackAuthAsyncClient; + +import com.google.common.reflect.TypeToken; /** - * Implementation of {@link ApiMetadata} for Rackspace Cloud Load Balancers API + * Implementation of {@link ApiMetadata} for CloudLoadBalancers 1.0 API * - * @author Dan Lo Bianco + * @author Adrian Cole */ -public class CloudLoadBalancersApiMetadata extends BaseApiMetadata { +public class CloudLoadBalancersApiMetadata + extends + BaseLoadBalancerServiceApiMetadata, CloudLoadBalancersApiMetadata> { - public CloudLoadBalancersApiMetadata() { - this(builder() - .id("cloudloadbalancers") - .type(ApiType.LOADBALANCER) - .name("Rackspace Cloud Load Balancers API") - .identityName("Username") - .credentialName("API Key") - .documentation(URI.create("http://docs.rackspacecloud.com/loadbalancers/api/v1.0/clb-devguide/content/ch01.html"))); + @Override + public Builder toBuilder() { + return new Builder().fromApiMetadata(this); } - // below are so that we can reuse builders, toString, hashCode, etc. - // we have to set concrete classes here, as our base class cannot be - // concrete due to serviceLoader - protected CloudLoadBalancersApiMetadata(Builder builder) { + public CloudLoadBalancersApiMetadata() { + this(new Builder()); + } + + protected CloudLoadBalancersApiMetadata(Builder builder) { super(builder); } - private static class ConcreteBuilder extends Builder { + protected static Properties defaultProperties() { + Properties properties = BaseLoadBalancerServiceApiMetadata.Builder.defaultProperties(); + return properties; + } + + public static class Builder + extends + BaseLoadBalancerServiceApiMetadata.Builder, CloudLoadBalancersApiMetadata> { + + protected Builder() { + id("cloudloadbalancers") + .name("Rackspace Cloud Load Balancers API") + .identityName("Username") + .credentialName("API Key") + .documentation(URI.create("http://docs.rackspacecloud.com/loadbalancers/api/v1.0/clb-devguide/content/ch01.html")) + .version(OpenStackAuthAsyncClient.VERSION) + .defaultEndpoint("https://auth.api.rackspacecloud.com") + .javaApi(CloudLoadBalancersClient.class, CloudLoadBalancersAsyncClient.class) + .defaultProperties(CloudLoadBalancersApiMetadata.defaultProperties()) + .contextBuilder(TypeToken.of(CloudLoadBalancersContextBuilder.class)); + } @Override public CloudLoadBalancersApiMetadata build() { return new CloudLoadBalancersApiMetadata(this); } - } - public static ConcreteBuilder builder() { - return new ConcreteBuilder(); - } + @Override + public Builder fromApiMetadata(CloudLoadBalancersApiMetadata in) { + super.fromApiMetadata(in); + return this; + } - @Override - public ConcreteBuilder toBuilder() { - return builder().fromApiMetadata(this); } } \ No newline at end of file diff --git a/apis/cloudloadbalancers/src/main/java/org/jclouds/cloudloadbalancers/CloudLoadBalancersContextBuilder.java b/apis/cloudloadbalancers/src/main/java/org/jclouds/cloudloadbalancers/CloudLoadBalancersContextBuilder.java index 93b51fc864..2e4c8e7827 100644 --- a/apis/cloudloadbalancers/src/main/java/org/jclouds/cloudloadbalancers/CloudLoadBalancersContextBuilder.java +++ b/apis/cloudloadbalancers/src/main/java/org/jclouds/cloudloadbalancers/CloudLoadBalancersContextBuilder.java @@ -19,11 +19,12 @@ package org.jclouds.cloudloadbalancers; import java.util.List; -import java.util.Properties; import org.jclouds.cloudloadbalancers.config.CloudLoadBalancersRestClientModule; import org.jclouds.cloudloadbalancers.loadbalancer.config.CloudLoadBalancersLoadBalancerContextModule; +import org.jclouds.loadbalancer.LoadBalancerServiceContext; import org.jclouds.loadbalancer.LoadBalancerServiceContextBuilder; +import org.jclouds.providers.ProviderMetadata; import com.google.inject.Module; @@ -31,11 +32,17 @@ import com.google.inject.Module; * * @author Adrian Cole */ -public class CloudLoadBalancersContextBuilder extends - LoadBalancerServiceContextBuilder { +public class CloudLoadBalancersContextBuilder + extends + LoadBalancerServiceContextBuilder, CloudLoadBalancersApiMetadata> { - public CloudLoadBalancersContextBuilder(Properties props) { - super(CloudLoadBalancersClient.class, CloudLoadBalancersAsyncClient.class, props); + public CloudLoadBalancersContextBuilder( + ProviderMetadata, CloudLoadBalancersApiMetadata> providerMetadata) { + super(providerMetadata); + } + + public CloudLoadBalancersContextBuilder(CloudLoadBalancersApiMetadata apiMetadata) { + super(apiMetadata); } @Override @@ -47,4 +54,4 @@ public class CloudLoadBalancersContextBuilder extends modules.add(new CloudLoadBalancersRestClientModule()); } -} +} \ No newline at end of file diff --git a/apis/cloudloadbalancers/src/main/java/org/jclouds/cloudloadbalancers/CloudLoadBalancersPropertiesBuilder.java b/apis/cloudloadbalancers/src/main/java/org/jclouds/cloudloadbalancers/CloudLoadBalancersPropertiesBuilder.java deleted file mode 100644 index fe8c881636..0000000000 --- a/apis/cloudloadbalancers/src/main/java/org/jclouds/cloudloadbalancers/CloudLoadBalancersPropertiesBuilder.java +++ /dev/null @@ -1,44 +0,0 @@ -/** - * 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.cloudloadbalancers; - -import static org.jclouds.Constants.PROPERTY_API_VERSION; - -import java.util.Properties; - -import org.jclouds.PropertiesBuilder; - -/** - * Builds properties used inRackspace Cloud Load Balancers Clients - * - * @author Dan Lo Bianco - */ -public class CloudLoadBalancersPropertiesBuilder extends PropertiesBuilder { - @Override - protected Properties defaultProperties() { - Properties properties = super.defaultProperties(); - properties.setProperty(PROPERTY_API_VERSION, "1.0"); - return properties; - } - - public CloudLoadBalancersPropertiesBuilder(Properties properties) { - super(properties); - } - - } diff --git a/apis/cloudloadbalancers/src/test/java/org/jclouds/cloudloadbalancers/CloudLoadBalancersApiMetadataTest.java b/apis/cloudloadbalancers/src/test/java/org/jclouds/cloudloadbalancers/CloudLoadBalancersApiMetadataTest.java index 77aa57b660..a31007e3d9 100644 --- a/apis/cloudloadbalancers/src/test/java/org/jclouds/cloudloadbalancers/CloudLoadBalancersApiMetadataTest.java +++ b/apis/cloudloadbalancers/src/test/java/org/jclouds/cloudloadbalancers/CloudLoadBalancersApiMetadataTest.java @@ -18,8 +18,7 @@ */ package org.jclouds.cloudloadbalancers; -import org.jclouds.apis.ApiType; -import org.jclouds.apis.BaseApiMetadataTest; +import org.jclouds.loadbalancer.internal.BaseLoadBalancerServiceApiMetadataTest; import org.testng.annotations.Test; /** @@ -27,9 +26,9 @@ import org.testng.annotations.Test; * @author Adrian Cole */ @Test(groups = "unit", testName = "CloudLoadBalancersApiMetadataTest") -public class CloudLoadBalancersApiMetadataTest extends BaseApiMetadataTest { +public class CloudLoadBalancersApiMetadataTest extends BaseLoadBalancerServiceApiMetadataTest { public CloudLoadBalancersApiMetadataTest() { - super(new CloudLoadBalancersApiMetadata(), ApiType.LOADBALANCER); + super(new CloudLoadBalancersApiMetadata()); } } diff --git a/apis/cloudloadbalancers/src/test/java/org/jclouds/cloudloadbalancers/features/LoadBalancerClientLiveTest.java b/apis/cloudloadbalancers/src/test/java/org/jclouds/cloudloadbalancers/features/LoadBalancerClientLiveTest.java index e11bda0e72..b95b023667 100644 --- a/apis/cloudloadbalancers/src/test/java/org/jclouds/cloudloadbalancers/features/LoadBalancerClientLiveTest.java +++ b/apis/cloudloadbalancers/src/test/java/org/jclouds/cloudloadbalancers/features/LoadBalancerClientLiveTest.java @@ -46,8 +46,8 @@ public class LoadBalancerClientLiveTest extends BaseCloudLoadBalancersClientLive private Set lbs = Sets.newLinkedHashSet(); @Override - public void setupClient() { - super.setupClient(); + public void setupContext() { + super.setupContext(); assertEquals(client.getConfiguredRegions(), Arrays.asList(regions)); Logger.getAnonymousLogger().info("running against regions " + client.getConfiguredRegions()); } diff --git a/apis/cloudloadbalancers/src/test/java/org/jclouds/cloudloadbalancers/internal/BaseCloudLoadBalancersAsyncClientTest.java b/apis/cloudloadbalancers/src/test/java/org/jclouds/cloudloadbalancers/internal/BaseCloudLoadBalancersAsyncClientTest.java index eb8aa9132a..3ddb2f6e45 100644 --- a/apis/cloudloadbalancers/src/test/java/org/jclouds/cloudloadbalancers/internal/BaseCloudLoadBalancersAsyncClientTest.java +++ b/apis/cloudloadbalancers/src/test/java/org/jclouds/cloudloadbalancers/internal/BaseCloudLoadBalancersAsyncClientTest.java @@ -31,12 +31,10 @@ import java.util.Properties; import javax.inject.Singleton; +import org.jclouds.apis.ApiMetadata; +import org.jclouds.cloudloadbalancers.CloudLoadBalancersApiMetadata; import org.jclouds.cloudloadbalancers.CloudLoadBalancersAsyncClient; -import org.jclouds.cloudloadbalancers.CloudLoadBalancersContextBuilder; -import org.jclouds.cloudloadbalancers.CloudLoadBalancersPropertiesBuilder; import org.jclouds.cloudloadbalancers.config.CloudLoadBalancersRestClientModule; -import org.jclouds.cloudloadbalancers.features.LoadBalancerAsyncClient; -import org.jclouds.cloudloadbalancers.features.LoadBalancerClient; import org.jclouds.cloudloadbalancers.reference.Region; import org.jclouds.domain.Credentials; import org.jclouds.http.HttpRequest; @@ -48,13 +46,10 @@ import org.jclouds.openstack.keystone.v1_1.config.AuthenticationServiceModule.Ge import org.jclouds.openstack.keystone.v1_1.domain.Auth; import org.jclouds.openstack.keystone.v1_1.parse.ParseAuthTest; import org.jclouds.rest.ConfiguresRestClient; -import org.jclouds.rest.RestClientTest; -import org.jclouds.rest.RestContextFactory; -import org.jclouds.rest.RestContextSpec; +import org.jclouds.rest.internal.BaseAsyncClientTest; import org.testng.annotations.BeforeClass; import com.google.common.base.Throwables; -import com.google.common.collect.ImmutableSet; import com.google.inject.AbstractModule; import com.google.inject.Module; import com.google.inject.Provides; @@ -62,7 +57,7 @@ import com.google.inject.Provides; /** * @author Adrian Cole */ -public abstract class BaseCloudLoadBalancersAsyncClientTest extends RestClientTest { +public abstract class BaseCloudLoadBalancersAsyncClientTest extends BaseAsyncClientTest { protected String provider; @@ -131,15 +126,9 @@ public abstract class BaseCloudLoadBalancersAsyncClientTest extends RestClien return overrides; } - /** - * this is only here as "cloudloadbalancers" is not in rest.properties - */ - @SuppressWarnings( { "unchecked", "rawtypes" }) @Override - public RestContextSpec createContextSpec() { - return RestContextFactory. contextSpec(provider, "https://auth", - "1.0", "", "", "identity", "credential", LoadBalancerClient.class, LoadBalancerAsyncClient.class, - (Class) CloudLoadBalancersPropertiesBuilder.class, (Class) CloudLoadBalancersContextBuilder.class, - ImmutableSet. of()); + protected ApiMetadata createApiMetadata() { + return new CloudLoadBalancersApiMetadata(); } + } \ No newline at end of file diff --git a/apis/cloudloadbalancers/src/test/java/org/jclouds/cloudloadbalancers/internal/BaseCloudLoadBalancersClientLiveTest.java b/apis/cloudloadbalancers/src/test/java/org/jclouds/cloudloadbalancers/internal/BaseCloudLoadBalancersClientLiveTest.java index b8a1fdd898..fc178ac0f7 100644 --- a/apis/cloudloadbalancers/src/test/java/org/jclouds/cloudloadbalancers/internal/BaseCloudLoadBalancersClientLiveTest.java +++ b/apis/cloudloadbalancers/src/test/java/org/jclouds/cloudloadbalancers/internal/BaseCloudLoadBalancersClientLiveTest.java @@ -18,7 +18,6 @@ */ package org.jclouds.cloudloadbalancers.internal; -import java.util.Properties; import java.util.concurrent.TimeUnit; import org.jclouds.cloudloadbalancers.CloudLoadBalancersAsyncClient; @@ -26,32 +25,33 @@ import org.jclouds.cloudloadbalancers.CloudLoadBalancersClient; import org.jclouds.cloudloadbalancers.domain.LoadBalancer; import org.jclouds.cloudloadbalancers.predicates.LoadBalancerActive; import org.jclouds.cloudloadbalancers.predicates.LoadBalancerDeleted; -import org.jclouds.loadbalancer.LoadBalancerServiceContextFactory; +import org.jclouds.loadbalancer.LoadBalancerServiceContext; import org.jclouds.logging.log4j.config.Log4JLoggingModule; import org.jclouds.net.IPSocket; import org.jclouds.predicates.RetryablePredicate; -import org.jclouds.rest.BaseRestClientLiveTest; import org.jclouds.rest.RestContext; +import org.jclouds.rest.internal.BaseContextLiveTest; import org.testng.annotations.AfterGroups; import org.testng.annotations.BeforeGroups; import com.google.common.base.Predicate; -import com.google.common.collect.ImmutableSet; import com.google.inject.Guice; import com.google.inject.Injector; -import com.google.inject.Module; /** * * @author Adrian Cole */ -public class BaseCloudLoadBalancersClientLiveTest extends BaseRestClientLiveTest { +public class BaseCloudLoadBalancersClientLiveTest + extends + BaseContextLiveTest> { + public BaseCloudLoadBalancersClientLiveTest() { provider = "cloudloadbalancers"; } protected CloudLoadBalancersClient client; - protected RestContext context; + protected RestContext lbContext; protected String[] regions = {}; protected Predicate socketTester; protected RetryablePredicate loadBalancerActive; @@ -59,15 +59,13 @@ public class BaseCloudLoadBalancersClientLiveTest extends BaseRestClientLiveTest protected Injector injector; + @BeforeGroups(groups = { "integration", "live" }) + @Override + public void setupContext() { + super.setupContext(); + lbContext = context.getProviderSpecificContext(); - @BeforeGroups(groups = "live") - public void setupClient() { - setupCredentials(); - Properties overrides = setupProperties(); - context = new LoadBalancerServiceContextFactory().createContext(provider, ImmutableSet. of(new Log4JLoggingModule()), - overrides).getProviderSpecificContext(); - - client = context.getApi(); + client = lbContext.getApi(); injector = Guice.createInjector(new Log4JLoggingModule()); loadBalancerActive = new RetryablePredicate(new LoadBalancerActive(client), 300, 1, 1, @@ -80,8 +78,8 @@ public class BaseCloudLoadBalancersClientLiveTest extends BaseRestClientLiveTest @AfterGroups(groups = "live") protected void tearDown() { - if (context != null) - context.close(); + if (lbContext != null) + lbContext.close(); } } diff --git a/apis/cloudservers/src/main/java/org/jclouds/cloudservers/CloudServersApiMetadata.java b/apis/cloudservers/src/main/java/org/jclouds/cloudservers/CloudServersApiMetadata.java index c41c0a1aba..7ab3010dec 100644 --- a/apis/cloudservers/src/main/java/org/jclouds/cloudservers/CloudServersApiMetadata.java +++ b/apis/cloudservers/src/main/java/org/jclouds/cloudservers/CloudServersApiMetadata.java @@ -19,50 +19,70 @@ package org.jclouds.cloudservers; import java.net.URI; +import java.util.Properties; import org.jclouds.apis.ApiMetadata; -import org.jclouds.apis.ApiType; -import org.jclouds.apis.BaseApiMetadata; +import org.jclouds.compute.ComputeServiceContext; +import org.jclouds.compute.internal.BaseComputeServiceApiMetadata; +import org.jclouds.openstack.OpenStackAuthAsyncClient; + +import com.google.common.reflect.TypeToken; /** - * Implementation of {@link ApiMetadata} for Rackspace Cloud Servers API + * Implementation of {@link ApiMetadata} for CloudServers 1.0 API * * @author Adrian Cole */ -public class CloudServersApiMetadata extends BaseApiMetadata { +public class CloudServersApiMetadata + extends + BaseComputeServiceApiMetadata, CloudServersApiMetadata> { - public CloudServersApiMetadata() { - this(builder() - .id("cloudservers") - .type(ApiType.COMPUTE) - .name("Rackspace Cloud Servers API") - .identityName("Username") - .credentialName("API Key") - .documentation(URI.create("http://docs.rackspacecloud.com/servers/api/v1.0/cs-devguide/content/ch01.html"))); + @Override + public Builder toBuilder() { + return new Builder().fromApiMetadata(this); } - // below are so that we can reuse builders, toString, hashCode, etc. - // we have to set concrete classes here, as our base class cannot be - // concrete due to serviceLoader - protected CloudServersApiMetadata(Builder builder) { + public CloudServersApiMetadata() { + this(new Builder()); + } + + protected CloudServersApiMetadata(Builder builder) { super(builder); } - private static class ConcreteBuilder extends Builder { + protected static Properties defaultProperties() { + Properties properties = BaseComputeServiceApiMetadata.Builder.defaultProperties(); + return properties; + } + + public static class Builder + extends + BaseComputeServiceApiMetadata.Builder, CloudServersApiMetadata> { + + protected Builder() { + id("cloudservers") + .name("Rackspace Cloud Servers API") + .identityName("Username") + .credentialName("API Key") + .documentation(URI.create("http://docs.rackspacecloud.com/servers/api/v1.0/cs-devguide/content/ch01.html")) + .version(OpenStackAuthAsyncClient.VERSION) + .defaultEndpoint("https://auth.api.rackspacecloud.com") + .javaApi(CloudServersClient.class, CloudServersAsyncClient.class) + .defaultProperties(CloudServersApiMetadata.defaultProperties()) + .contextBuilder(TypeToken.of(CloudServersContextBuilder.class)); + } @Override public CloudServersApiMetadata build() { return new CloudServersApiMetadata(this); } - } - public static ConcreteBuilder builder() { - return new ConcreteBuilder(); - } + @Override + public Builder fromApiMetadata(CloudServersApiMetadata in) { + super.fromApiMetadata(in); + return this; + } - @Override - public ConcreteBuilder toBuilder() { - return builder().fromApiMetadata(this); } } \ No newline at end of file diff --git a/apis/cloudservers/src/main/java/org/jclouds/cloudservers/CloudServersContextBuilder.java b/apis/cloudservers/src/main/java/org/jclouds/cloudservers/CloudServersContextBuilder.java index 9c322927d5..52e43a7d3a 100644 --- a/apis/cloudservers/src/main/java/org/jclouds/cloudservers/CloudServersContextBuilder.java +++ b/apis/cloudservers/src/main/java/org/jclouds/cloudservers/CloudServersContextBuilder.java @@ -19,35 +19,30 @@ package org.jclouds.cloudservers; import java.util.List; -import java.util.Properties; import org.jclouds.cloudservers.compute.config.CloudServersComputeServiceContextModule; import org.jclouds.cloudservers.config.CloudServersRestClientModule; +import org.jclouds.compute.ComputeServiceContext; import org.jclouds.compute.ComputeServiceContextBuilder; -import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule; -import org.jclouds.logging.jdk.config.JDKLoggingModule; +import org.jclouds.providers.ProviderMetadata; -import com.google.inject.Injector; import com.google.inject.Module; /** - * Creates {@link CloudServersComputeServiceContext} or {@link Injector} instances based on the most - * commonly requested arguments. - *

- * Note that Threadsafe objects will be bound as singletons to the Injector or Context provided. - *

- *

- * If no Modules are specified, the default {@link JDKLoggingModule logging} and - * {@link JavaUrlHttpCommandExecutorServiceModule http transports} will be installed. * * @author Adrian Cole - * @see CloudServersComputeServiceContext */ -public class CloudServersContextBuilder extends - ComputeServiceContextBuilder { +public class CloudServersContextBuilder + extends + ComputeServiceContextBuilder, CloudServersApiMetadata> { - public CloudServersContextBuilder(Properties props) { - super(CloudServersClient.class, CloudServersAsyncClient.class, props); + public CloudServersContextBuilder( + ProviderMetadata, CloudServersApiMetadata> providerMetadata) { + super(providerMetadata); + } + + public CloudServersContextBuilder(CloudServersApiMetadata apiMetadata) { + super(apiMetadata); } @Override @@ -55,9 +50,8 @@ public class CloudServersContextBuilder extends modules.add(new CloudServersComputeServiceContextModule()); } - @Override protected void addClientModule(List modules) { modules.add(new CloudServersRestClientModule()); } -} +} \ No newline at end of file diff --git a/apis/cloudservers/src/main/java/org/jclouds/cloudservers/CloudServersPropertiesBuilder.java b/apis/cloudservers/src/main/java/org/jclouds/cloudservers/CloudServersPropertiesBuilder.java deleted file mode 100644 index b4af167dbe..0000000000 --- a/apis/cloudservers/src/main/java/org/jclouds/cloudservers/CloudServersPropertiesBuilder.java +++ /dev/null @@ -1,45 +0,0 @@ -/** - * 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.cloudservers; - -import static org.jclouds.Constants.PROPERTY_API_VERSION; - -import java.util.Properties; - -import org.jclouds.PropertiesBuilder; -import org.jclouds.openstack.OpenStackAuthAsyncClient; - -/** - * - * @author Dan Lo Bianco - */ -public class CloudServersPropertiesBuilder extends PropertiesBuilder { - - @Override - protected Properties defaultProperties() { - Properties properties = super.defaultProperties(); - properties.setProperty(PROPERTY_API_VERSION, OpenStackAuthAsyncClient.VERSION); - return properties; - } - - public CloudServersPropertiesBuilder(Properties properties) { - super(properties); - } - -} diff --git a/apis/cloudservers/src/test/java/org/jclouds/cloudservers/CloudServersApiMetadataTest.java b/apis/cloudservers/src/test/java/org/jclouds/cloudservers/CloudServersApiMetadataTest.java index f4d822af98..6587b5ab3c 100644 --- a/apis/cloudservers/src/test/java/org/jclouds/cloudservers/CloudServersApiMetadataTest.java +++ b/apis/cloudservers/src/test/java/org/jclouds/cloudservers/CloudServersApiMetadataTest.java @@ -18,8 +18,7 @@ */ package org.jclouds.cloudservers; -import org.jclouds.apis.ApiType; -import org.jclouds.apis.BaseApiMetadataTest; +import org.jclouds.compute.internal.BaseComputeServiceApiMetadataTest; import org.testng.annotations.Test; /** @@ -27,9 +26,9 @@ import org.testng.annotations.Test; * @author Adrian Cole */ @Test(groups = "unit", testName = "CloudServersApiMetadataTest") -public class CloudServersApiMetadataTest extends BaseApiMetadataTest { +public class CloudServersApiMetadataTest extends BaseComputeServiceApiMetadataTest { public CloudServersApiMetadataTest() { - super(new CloudServersApiMetadata(), ApiType.COMPUTE); + super(new CloudServersApiMetadata()); } } diff --git a/apis/cloudservers/src/test/java/org/jclouds/cloudservers/CloudServersAsyncClientTest.java b/apis/cloudservers/src/test/java/org/jclouds/cloudservers/CloudServersAsyncClientTest.java index 50713095c9..829b7a8cef 100644 --- a/apis/cloudservers/src/test/java/org/jclouds/cloudservers/CloudServersAsyncClientTest.java +++ b/apis/cloudservers/src/test/java/org/jclouds/cloudservers/CloudServersAsyncClientTest.java @@ -38,6 +38,7 @@ import java.util.Properties; import javax.inject.Singleton; import javax.ws.rs.core.MediaType; +import org.jclouds.apis.ApiMetadata; import org.jclouds.cloudservers.config.CloudServersRestClientModule; import org.jclouds.cloudservers.domain.BackupSchedule; import org.jclouds.cloudservers.domain.DailyBackup; @@ -60,14 +61,12 @@ import org.jclouds.openstack.keystone.v1_1.config.AuthenticationServiceModule.Ge import org.jclouds.openstack.keystone.v1_1.domain.Auth; import org.jclouds.openstack.keystone.v1_1.parse.ParseAuthTest; import org.jclouds.rest.ConfiguresRestClient; -import org.jclouds.rest.RestClientTest; -import org.jclouds.rest.RestContextFactory; -import org.jclouds.rest.RestContextSpec; import org.jclouds.rest.functions.MapHttp4xxCodesToExceptions; import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404; import org.jclouds.rest.functions.ReturnFalseOnNotFoundOr404; import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404; +import org.jclouds.rest.internal.BaseAsyncClientTest; import org.jclouds.rest.internal.RestAnnotationProcessor; import org.testng.annotations.Test; @@ -84,7 +83,7 @@ import com.google.inject.TypeLiteral; // NOTE:without testName, this will not call @Before* and fail w/NPE during // surefire @Test(groups = "unit", singleThreaded = true, testName = "CloudServersAsyncClientTest") -public class CloudServersAsyncClientTest extends RestClientTest { +public class CloudServersAsyncClientTest extends BaseAsyncClientTest { private static final Class listOptionsVarargsClass = new ListOptions[] {}.getClass(); private static final Class createServerOptionsVarargsClass = new CreateServerOptions[] {} .getClass(); @@ -910,8 +909,8 @@ public class CloudServersAsyncClientTest extends RestClientTest createContextSpec() { - return new RestContextFactory(setupRestProperties()).createContextSpec(provider, "user", "password", setupProperties()); + protected ApiMetadata createApiMetadata() { + return new CloudServersApiMetadata(); } @Override diff --git a/apis/cloudservers/src/test/java/org/jclouds/cloudservers/CloudServersClientLiveTest.java b/apis/cloudservers/src/test/java/org/jclouds/cloudservers/CloudServersClientLiveTest.java index 7835e6beee..3618a2c58e 100644 --- a/apis/cloudservers/src/test/java/org/jclouds/cloudservers/CloudServersClientLiveTest.java +++ b/apis/cloudservers/src/test/java/org/jclouds/cloudservers/CloudServersClientLiveTest.java @@ -29,7 +29,6 @@ import java.io.IOException; import java.lang.reflect.UndeclaredThrowableException; import java.security.SecureRandom; import java.util.Map; -import java.util.Properties; import java.util.Set; import java.util.concurrent.TimeUnit; @@ -45,19 +44,17 @@ import org.jclouds.cloudservers.domain.ServerStatus; import org.jclouds.cloudservers.domain.SharedIpGroup; import org.jclouds.cloudservers.domain.WeeklyBackup; import org.jclouds.cloudservers.options.RebuildServerOptions; -import org.jclouds.compute.BaseVersionedServiceLiveTest; +import org.jclouds.compute.ComputeServiceContext; import org.jclouds.compute.domain.ExecResponse; +import org.jclouds.compute.internal.BaseComputeServiceContextLiveTest; import org.jclouds.domain.LoginCredentials; import org.jclouds.http.HttpResponseException; import org.jclouds.io.Payload; -import org.jclouds.logging.log4j.config.Log4JLoggingModule; import org.jclouds.net.IPSocket; import org.jclouds.predicates.RetryablePredicate; import org.jclouds.predicates.SocketOpen; -import org.jclouds.rest.RestContextFactory; import org.jclouds.ssh.SshClient; import org.jclouds.ssh.SshException; -import org.jclouds.sshj.config.SshjSshClientModule; import org.jclouds.util.Strings2; import org.testng.annotations.AfterTest; import org.testng.annotations.BeforeGroups; @@ -66,10 +63,8 @@ import org.testng.annotations.Test; import com.google.common.base.Predicate; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; import com.google.inject.Injector; -import com.google.inject.Module; /** * Tests behavior of {@code CloudServersClient} @@ -77,7 +72,10 @@ import com.google.inject.Module; * @author Adrian Cole */ @Test(groups = "live", singleThreaded = true, testName = "CloudServersClientLiveTest") -public class CloudServersClientLiveTest extends BaseVersionedServiceLiveTest { +public class CloudServersClientLiveTest + extends + BaseComputeServiceContextLiveTest> { + public CloudServersClientLiveTest() { provider = "cloudservers"; } @@ -86,15 +84,11 @@ public class CloudServersClientLiveTest extends BaseVersionedServiceLiveTest { protected SshClient.Factory sshFactory; protected Predicate socketTester; - @BeforeGroups(groups = { "live" }) - public void setupClient() { - setupCredentials(); - Properties overrides = setupProperties(); - - Injector injector = new RestContextFactory().createContextBuilder(provider, - ImmutableSet. of(new Log4JLoggingModule(), new SshjSshClientModule()), overrides) - .buildInjector(); - + @BeforeGroups(groups = { "integration", "live" }) + @Override + public void setupContext() { + super.setupContext(); + Injector injector = context.utils().injector(); client = injector.getInstance(CloudServersClient.class); sshFactory = injector.getInstance(SshClient.Factory.class); SocketOpen socketOpen = injector.getInstance(SocketOpen.class); diff --git a/apis/cloudservers/src/test/java/org/jclouds/cloudservers/compute/CloudServersComputeServiceLiveTest.java b/apis/cloudservers/src/test/java/org/jclouds/cloudservers/compute/CloudServersComputeServiceLiveTest.java index c725549435..d7af173018 100644 --- a/apis/cloudservers/src/test/java/org/jclouds/cloudservers/compute/CloudServersComputeServiceLiveTest.java +++ b/apis/cloudservers/src/test/java/org/jclouds/cloudservers/compute/CloudServersComputeServiceLiveTest.java @@ -24,11 +24,10 @@ import java.io.IOException; import org.jclouds.cloudservers.CloudServersAsyncClient; import org.jclouds.cloudservers.CloudServersClient; -import org.jclouds.compute.BaseComputeServiceLiveTest; -import org.jclouds.compute.ComputeServiceContextFactory; +import org.jclouds.compute.ComputeServiceContext; import org.jclouds.compute.domain.NodeMetadata; +import org.jclouds.compute.internal.BaseComputeServiceLiveTest; import org.jclouds.domain.LocationScope; -import org.jclouds.rest.RestContext; import org.jclouds.sshj.config.SshjSshClientModule; import org.testng.annotations.Test; @@ -41,7 +40,10 @@ import com.google.inject.Module; * @author Adrian Cole */ @Test(groups = "live", enabled = true, singleThreaded = true, testName = "CloudServersComputeServiceLiveTest") -public class CloudServersComputeServiceLiveTest extends BaseComputeServiceLiveTest { +public class CloudServersComputeServiceLiveTest + extends + BaseComputeServiceLiveTest> { + public CloudServersComputeServiceLiveTest() { provider = "cloudservers"; } @@ -51,12 +53,6 @@ public class CloudServersComputeServiceLiveTest extends BaseComputeServiceLiveTe return new SshjSshClientModule(); } - public void testAssignability() throws Exception { - @SuppressWarnings("unused") - RestContext tmContext = new ComputeServiceContextFactory() - .createContext(provider, identity, credential).getProviderSpecificContext(); - } - @Override protected void checkNodes(Iterable nodes, String group, String task) throws IOException { super.checkNodes(nodes, group, task); diff --git a/apis/cloudservers/src/test/java/org/jclouds/cloudservers/internal/BaseCloudServersRestClientExpectTest.java b/apis/cloudservers/src/test/java/org/jclouds/cloudservers/internal/BaseCloudServersRestClientExpectTest.java index fd1e37bd06..71cc584289 100644 --- a/apis/cloudservers/src/test/java/org/jclouds/cloudservers/internal/BaseCloudServersRestClientExpectTest.java +++ b/apis/cloudservers/src/test/java/org/jclouds/cloudservers/internal/BaseCloudServersRestClientExpectTest.java @@ -23,9 +23,9 @@ import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGIONS; import java.util.Date; import java.util.Properties; +import org.jclouds.apis.ApiMetadata; +import org.jclouds.cloudservers.CloudServersApiMetadata; import org.jclouds.cloudservers.CloudServersClient; -import org.jclouds.cloudservers.CloudServersContextBuilder; -import org.jclouds.cloudservers.CloudServersPropertiesBuilder; import org.jclouds.cloudservers.config.CloudServersRestClientModule; import org.jclouds.date.internal.SimpleDateFormatDateService; import org.jclouds.http.RequiresHttp; @@ -47,14 +47,18 @@ public class BaseCloudServersRestClientExpectTest extends BaseKeystoneRestClient public BaseCloudServersRestClientExpectTest() { provider = "cloudservers"; } + + @Override + protected ApiMetadata createApiMetadata() { + return new CloudServersApiMetadata(); + } + @Override - protected Properties setupRestProperties() { + protected Properties setupProperties() { Properties overrides = new Properties(); overrides.setProperty(PROPERTY_REGIONS, "US"); overrides.setProperty(provider + ".endpoint", endpoint); - overrides.setProperty(provider + ".contextbuilder", CloudServersContextBuilder.class.getName()); - overrides.setProperty(provider + ".propertiesbuilder", CloudServersPropertiesBuilder.class.getName()); return overrides; } diff --git a/apis/cloudsigma/src/main/java/org/jclouds/cloudsigma/CloudSigmaApiMetadata.java b/apis/cloudsigma/src/main/java/org/jclouds/cloudsigma/CloudSigmaApiMetadata.java index 7d9a7f992e..96cfb3893a 100644 --- a/apis/cloudsigma/src/main/java/org/jclouds/cloudsigma/CloudSigmaApiMetadata.java +++ b/apis/cloudsigma/src/main/java/org/jclouds/cloudsigma/CloudSigmaApiMetadata.java @@ -18,51 +18,77 @@ */ package org.jclouds.cloudsigma; +import static org.jclouds.cloudsigma.reference.CloudSigmaConstants.PROPERTY_VNC_PASSWORD; + import java.net.URI; +import java.util.Properties; import org.jclouds.apis.ApiMetadata; -import org.jclouds.apis.ApiType; -import org.jclouds.apis.BaseApiMetadata; +import org.jclouds.compute.ComputeServiceContext; +import org.jclouds.compute.internal.BaseComputeServiceApiMetadata; + +import com.google.common.reflect.TypeToken; /** * Implementation of {@link ApiMetadata} for the Cloud Sigma API * * @author Adrian Cole */ -public class CloudSigmaApiMetadata extends BaseApiMetadata { +public class CloudSigmaApiMetadata + extends + BaseComputeServiceApiMetadata, CloudSigmaApiMetadata> { - public CloudSigmaApiMetadata() { - this(builder() - .id("cloudsigma") - .type(ApiType.COMPUTE) - .name("CloudSigma API") - .identityName("Email") - .credentialName("Password") - .documentation(URI.create("http://cloudsigma.com/en/platform-details/the-api"))); + @Override + public Builder toBuilder() { + return new Builder().fromApiMetadata(this); } - // below are so that we can reuse builders, toString, hashCode, etc. - // we have to set concrete classes here, as our base class cannot be - // concrete due to serviceLoader - protected CloudSigmaApiMetadata(Builder builder) { + public CloudSigmaApiMetadata() { + this(new Builder()); + } + + protected CloudSigmaApiMetadata(Builder builder) { super(builder); } - private static class ConcreteBuilder extends Builder { + protected static Properties defaultProperties() { + Properties properties = BaseComputeServiceApiMetadata.Builder.defaultProperties(); + properties.setProperty(PROPERTY_VNC_PASSWORD, "IL9vs34d"); + // passwords are set post-boot, so auth failures are possible + // from a race condition applying the password set script + properties.setProperty("jclouds.ssh.max-retries", "7"); + properties.setProperty("jclouds.ssh.retry-auth", "true"); + return properties; + } + + public static class Builder + extends + BaseComputeServiceApiMetadata.Builder, CloudSigmaApiMetadata> { + + protected Builder() { + id("cloudsigma") + .name("CloudSigma API") + .identityName("Email") + .credentialName("Password") + .documentation(URI.create("http://cloudsigma.com/en/platform-details/the-api")) + .version("1.0") + .defaultEndpoint("https://api.cloudsigma.com") + .defaultProperties(CloudSigmaApiMetadata.defaultProperties()) + .javaApi(CloudSigmaClient.class, CloudSigmaAsyncClient.class) + .contextBuilder(TypeToken.of(CloudSigmaContextBuilder.class)); + } @Override public CloudSigmaApiMetadata build() { return new CloudSigmaApiMetadata(this); } - } - public static ConcreteBuilder builder() { - return new ConcreteBuilder(); - } + @Override + public Builder fromApiMetadata(CloudSigmaApiMetadata in) { + super.fromApiMetadata(in); + return this; + } - @Override - public ConcreteBuilder toBuilder() { - return builder().fromApiMetadata(this); } } \ No newline at end of file diff --git a/apis/cloudsigma/src/main/java/org/jclouds/cloudsigma/CloudSigmaContextBuilder.java b/apis/cloudsigma/src/main/java/org/jclouds/cloudsigma/CloudSigmaContextBuilder.java index c777e0e408..222e790707 100644 --- a/apis/cloudsigma/src/main/java/org/jclouds/cloudsigma/CloudSigmaContextBuilder.java +++ b/apis/cloudsigma/src/main/java/org/jclouds/cloudsigma/CloudSigmaContextBuilder.java @@ -19,11 +19,12 @@ package org.jclouds.cloudsigma; import java.util.List; -import java.util.Properties; import org.jclouds.cloudsigma.compute.config.CloudSigmaComputeServiceContextModule; import org.jclouds.cloudsigma.config.CloudSigmaRestClientModule; +import org.jclouds.compute.ComputeServiceContext; import org.jclouds.compute.ComputeServiceContextBuilder; +import org.jclouds.providers.ProviderMetadata; import com.google.inject.Module; @@ -31,10 +32,17 @@ import com.google.inject.Module; * * @author Adrian Cole */ -public class CloudSigmaContextBuilder extends ComputeServiceContextBuilder { +public class CloudSigmaContextBuilder + extends + ComputeServiceContextBuilder, CloudSigmaApiMetadata> { - public CloudSigmaContextBuilder(Properties props) { - super(CloudSigmaClient.class, CloudSigmaAsyncClient.class, props); + public CloudSigmaContextBuilder( + ProviderMetadata, CloudSigmaApiMetadata> providerMetadata) { + super(providerMetadata); + } + + public CloudSigmaContextBuilder(CloudSigmaApiMetadata apiMetadata) { + super(apiMetadata); } @Override diff --git a/apis/cloudsigma/src/main/java/org/jclouds/cloudsigma/CloudSigmaPropertiesBuilder.java b/apis/cloudsigma/src/main/java/org/jclouds/cloudsigma/CloudSigmaPropertiesBuilder.java deleted file mode 100644 index bf13f88b68..0000000000 --- a/apis/cloudsigma/src/main/java/org/jclouds/cloudsigma/CloudSigmaPropertiesBuilder.java +++ /dev/null @@ -1,50 +0,0 @@ -/** - * 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.cloudsigma; - -import static org.jclouds.Constants.PROPERTY_API_VERSION; -import static org.jclouds.cloudsigma.reference.CloudSigmaConstants.PROPERTY_VNC_PASSWORD; - -import java.util.Properties; - -import org.jclouds.PropertiesBuilder; - -/** - * Builds properties used in CloudSigma Clients - * - * @author Adrian Cole - */ -public class CloudSigmaPropertiesBuilder extends PropertiesBuilder { - @Override - protected Properties defaultProperties() { - Properties properties = super.defaultProperties(); - properties.setProperty(PROPERTY_API_VERSION, "1.0"); - properties.setProperty(PROPERTY_VNC_PASSWORD, "IL9vs34d"); - // passwords are set post-boot, so auth failures are possible - // from a race condition applying the password set script - properties.setProperty("jclouds.ssh.max-retries", "7"); - properties.setProperty("jclouds.ssh.retry-auth", "true"); - return properties; - } - - public CloudSigmaPropertiesBuilder(Properties properties) { - super(properties); - } - -} diff --git a/apis/cloudsigma/src/test/java/org/jclouds/cloudsigma/CloudSigmaApiMetadataTest.java b/apis/cloudsigma/src/test/java/org/jclouds/cloudsigma/CloudSigmaApiMetadataTest.java index f5a9898fd0..3394075e41 100644 --- a/apis/cloudsigma/src/test/java/org/jclouds/cloudsigma/CloudSigmaApiMetadataTest.java +++ b/apis/cloudsigma/src/test/java/org/jclouds/cloudsigma/CloudSigmaApiMetadataTest.java @@ -18,8 +18,7 @@ */ package org.jclouds.cloudsigma; -import org.jclouds.apis.ApiType; -import org.jclouds.apis.BaseApiMetadataTest; +import org.jclouds.compute.internal.BaseComputeServiceApiMetadataTest; import org.testng.annotations.Test; /** @@ -27,9 +26,9 @@ import org.testng.annotations.Test; * @author Adrian Cole */ @Test(groups = "unit", testName = "CloudSigmaApiMetadataTest") -public class CloudSigmaApiMetadataTest extends BaseApiMetadataTest { +public class CloudSigmaApiMetadataTest extends BaseComputeServiceApiMetadataTest { public CloudSigmaApiMetadataTest() { - super(new CloudSigmaApiMetadata(), ApiType.COMPUTE); + super(new CloudSigmaApiMetadata()); } } diff --git a/apis/cloudsigma/src/test/java/org/jclouds/cloudsigma/CloudSigmaAsyncClientTest.java b/apis/cloudsigma/src/test/java/org/jclouds/cloudsigma/CloudSigmaAsyncClientTest.java index 526ba3ef94..d7fafbaf17 100644 --- a/apis/cloudsigma/src/test/java/org/jclouds/cloudsigma/CloudSigmaAsyncClientTest.java +++ b/apis/cloudsigma/src/test/java/org/jclouds/cloudsigma/CloudSigmaAsyncClientTest.java @@ -22,8 +22,8 @@ import static org.testng.Assert.assertEquals; import java.io.IOException; import java.lang.reflect.Method; -import java.util.Properties; +import org.jclouds.apis.ApiMetadata; import org.jclouds.cloudsigma.binders.BindServerToPlainTextStringTest; import org.jclouds.cloudsigma.domain.CreateDriveRequest; import org.jclouds.cloudsigma.domain.Drive; @@ -44,12 +44,10 @@ import org.jclouds.cloudsigma.options.CloneDriveOptions; import org.jclouds.http.HttpRequest; import org.jclouds.http.filters.BasicAuthentication; import org.jclouds.http.functions.ReleasePayloadAndReturn; -import org.jclouds.rest.RestClientTest; -import org.jclouds.rest.RestContextFactory; -import org.jclouds.rest.RestContextSpec; import org.jclouds.rest.functions.MapHttp4xxCodesToExceptions; import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404; +import org.jclouds.rest.internal.BaseAsyncClientTest; import org.jclouds.rest.internal.RestAnnotationProcessor; import org.testng.annotations.Test; @@ -64,7 +62,7 @@ import com.google.inject.TypeLiteral; */ // NOTE:without testName, this will not call @Before* and fail w/NPE during surefire @Test(groups = "unit", testName = "CloudSigmaAsyncClientTest") -public class CloudSigmaAsyncClientTest extends RestClientTest { +public class CloudSigmaAsyncClientTest extends BaseAsyncClientTest { public void testGetProfileInfo() throws SecurityException, NoSuchMethodException, IOException { Method method = CloudSigmaAsyncClient.class.getMethod("getProfileInfo"); @@ -243,7 +241,7 @@ public class CloudSigmaAsyncClientTest extends RestClientTest createContextSpec() { - Properties props = new Properties(); - props.setProperty("cloudsigma.endpoint", "https://api.cloudsigma.com"); - return new RestContextFactory().createContextSpec("cloudsigma", "foo", "bar", props); + protected ApiMetadata createApiMetadata() { + return new CloudSigmaApiMetadata(); } + } diff --git a/apis/cloudsigma/src/test/java/org/jclouds/cloudsigma/CloudSigmaClientLiveTest.java b/apis/cloudsigma/src/test/java/org/jclouds/cloudsigma/CloudSigmaClientLiveTest.java index babe31da6a..874a59309e 100644 --- a/apis/cloudsigma/src/test/java/org/jclouds/cloudsigma/CloudSigmaClientLiveTest.java +++ b/apis/cloudsigma/src/test/java/org/jclouds/cloudsigma/CloudSigmaClientLiveTest.java @@ -22,7 +22,6 @@ import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNotNull; import java.io.IOException; -import java.util.Properties; import java.util.Set; import java.util.concurrent.TimeUnit; import java.util.logging.Logger; @@ -44,12 +43,10 @@ import org.jclouds.cloudsigma.domain.VLANInfo; import org.jclouds.cloudsigma.options.CloneDriveOptions; import org.jclouds.cloudsigma.predicates.DriveClaimed; import org.jclouds.cloudsigma.util.Servers; -import org.jclouds.compute.BaseVersionedServiceLiveTest; import org.jclouds.compute.ComputeServiceContext; -import org.jclouds.compute.ComputeServiceContextFactory; import org.jclouds.compute.domain.ExecResponse; +import org.jclouds.compute.internal.BaseComputeServiceContextLiveTest; import org.jclouds.domain.LoginCredentials; -import org.jclouds.logging.log4j.config.Log4JLoggingModule; import org.jclouds.net.IPSocket; import org.jclouds.predicates.InetSocketAddressConnect; import org.jclouds.predicates.RetryablePredicate; @@ -67,7 +64,6 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import com.google.gson.Gson; import com.google.inject.Guice; -import com.google.inject.Module; /** * Tests behavior of {@code CloudSigmaClient} @@ -75,37 +71,37 @@ import com.google.inject.Module; * @author Adrian Cole */ @Test(groups = "live", singleThreaded = true, testName = "CloudSigmaClientLiveTest") -public class CloudSigmaClientLiveTest extends BaseVersionedServiceLiveTest { +public class CloudSigmaClientLiveTest + extends + BaseComputeServiceContextLiveTest> { + public CloudSigmaClientLiveTest() { provider = "cloudsigma"; } - + protected long driveSize = 8 * 1024 * 1024 * 1024l; protected int maxDriveImageTime = 300; protected String vncPassword = "Il0veVNC"; protected CloudSigmaClient client; - protected RestContext context; + protected RestContext cloudSigmaContext; protected Predicate socketTester; protected Predicate driveNotClaimed; - protected ComputeServiceContext computeContext; + + @BeforeGroups(groups = { "integration", "live" }) + @Override + public void setupContext() { + super.setupContext(); + cloudSigmaContext = context.getProviderSpecificContext(); - @BeforeGroups(groups = "live") - public void setupClient() { - setupCredentials(); - Properties overrides = setupProperties(); - computeContext = new ComputeServiceContextFactory().createContext(provider, - ImmutableSet. of(new Log4JLoggingModule()), overrides); - context = computeContext.getProviderSpecificContext(); - - client = context.getApi(); + client = cloudSigmaContext.getApi(); driveNotClaimed = new RetryablePredicate(Predicates.not(new DriveClaimed(client)), maxDriveImageTime, 1, TimeUnit.SECONDS); socketTester = new RetryablePredicate(new InetSocketAddressConnect(), maxDriveImageTime, 1, TimeUnit.SECONDS); - + if (Strings.emptyToNull(imageId) == null) { - imageId = computeContext.getComputeService().templateBuilder().build().getImage().getId(); + imageId = context.getComputeService().templateBuilder().build().getImage().getId(); } } @@ -259,7 +255,7 @@ public class CloudSigmaClientLiveTest extends BaseVersionedServiceLiveTest { String prefix2 = prefix + "2"; vlan = client.renameVLAN(vlan.getUuid(), prefix2); - assertEquals(vlan.getName(),prefix2); + assertEquals(vlan.getName(), prefix2); } finally { client.destroyVLAN(id); } @@ -354,7 +350,8 @@ public class CloudSigmaClientLiveTest extends BaseVersionedServiceLiveTest { assertEquals(client.getServerInfo(server.getUuid()).getStatus(), ServerStatus.ACTIVE); client.shutdownServer(server.getUuid()); - // behavior on shutdown depends on how your server OS is set up to respond to an ACPI power + // behavior on shutdown depends on how your server OS is set up to respond + // to an ACPI power // button signal assert (client.getServerInfo(server.getUuid()).getStatus() == ServerStatus.ACTIVE || client.getServerInfo( server.getUuid()).getStatus() == ServerStatus.STOPPED); @@ -415,8 +412,8 @@ public class CloudSigmaClientLiveTest extends BaseVersionedServiceLiveTest { client.destroyServer(server.getUuid()); if (server != null) client.destroyDrive(drive.getUuid()); - if (context != null) - context.close(); + if (cloudSigmaContext != null) + cloudSigmaContext.close(); } @Test @@ -444,13 +441,10 @@ public class CloudSigmaClientLiveTest extends BaseVersionedServiceLiveTest { protected void prepareDrive() { client.destroyDrive(drive.getUuid()); drive = client.cloneDrive(imageId, drive.getName(), - new CloneDriveOptions() - .size(driveSize) - .tags("cat:mouse", "monkey:banana") - ); + new CloneDriveOptions().size(driveSize).tags("cat:mouse", "monkey:banana")); // Block until the async clone operation has completed. assert driveNotClaimed.apply(drive) : client.getDriveInfo(drive.getUuid()); - + DriveInfo clonedDrive = client.getDriveInfo(drive.getUuid()); System.err.println("after prepare" + clonedDrive); assertEquals(clonedDrive.getTags(), ImmutableSet.of("cat:mouse", "monkey:banana")); diff --git a/apis/cloudsigma/src/test/java/org/jclouds/cloudsigma/compute/CloudSigmaComputeServiceLiveTest.java b/apis/cloudsigma/src/test/java/org/jclouds/cloudsigma/compute/CloudSigmaComputeServiceLiveTest.java index 3410c37a60..7022468935 100644 --- a/apis/cloudsigma/src/test/java/org/jclouds/cloudsigma/compute/CloudSigmaComputeServiceLiveTest.java +++ b/apis/cloudsigma/src/test/java/org/jclouds/cloudsigma/compute/CloudSigmaComputeServiceLiveTest.java @@ -18,9 +18,12 @@ */ package org.jclouds.cloudsigma.compute; -import org.jclouds.compute.BaseComputeServiceLiveTest; +import org.jclouds.cloudsigma.CloudSigmaAsyncClient; +import org.jclouds.cloudsigma.CloudSigmaClient; +import org.jclouds.compute.ComputeServiceContext; import org.jclouds.compute.domain.ExecResponse; import org.jclouds.compute.domain.NodeMetadata; +import org.jclouds.compute.internal.BaseComputeServiceLiveTest; import org.jclouds.sshj.config.SshjSshClientModule; import org.testng.annotations.Test; @@ -31,7 +34,10 @@ import com.google.inject.Module; * @author Adrian Cole */ @Test(groups = "live") -public class CloudSigmaComputeServiceLiveTest extends BaseComputeServiceLiveTest { +public class CloudSigmaComputeServiceLiveTest + extends + BaseComputeServiceLiveTest> { + public CloudSigmaComputeServiceLiveTest() { provider = "cloudsigma"; } diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/CloudStackApiMetadata.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/CloudStackApiMetadata.java index d1b30a7e45..80f97b45cf 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/CloudStackApiMetadata.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/CloudStackApiMetadata.java @@ -19,50 +19,81 @@ package org.jclouds.cloudstack; import java.net.URI; +import java.util.Properties; import org.jclouds.apis.ApiMetadata; -import org.jclouds.apis.ApiType; -import org.jclouds.apis.BaseApiMetadata; +import org.jclouds.compute.internal.BaseComputeServiceApiMetadata; + +import com.google.common.reflect.TypeToken; /** - * Implementation of {@link ApiMetadata} for Citrix CloudStack API + * Implementation of {@link ApiMetadata} for Citrix/Apache CloudStack api. + * + *

note

+ *

+ * This class allows overriding of types {@code S}(client) and {@code A} + * (asyncClient), so that children can add additional methods not declared here, + * such as new features from AWS. + *

+ * + * As this is a popular api, we also allow overrides for type {@code C} + * (context). This allows subtypes to add in new feature groups or extensions, + * not present in the base api. For example, you could make a subtype for + * context, that exposes admin operations. * * @author Adrian Cole */ -public class CloudStackApiMetadata extends BaseApiMetadata { +public class CloudStackApiMetadata extends BaseComputeServiceApiMetadata +{ - public CloudStackApiMetadata() { - this(builder() - .id("cloudstack") - .type(ApiType.COMPUTE) - .name("Citrix CloudStack API") - .identityName("API Key") - .credentialName("Secret Key") - .documentation(URI.create("http://download.cloud.com/releases/2.2.0/api_2.2.12/TOC_User.html"))); + @Override + public Builder toBuilder() { + return new Builder().fromApiMetadata(this); } - // below are so that we can reuse builders, toString, hashCode, etc. - // we have to set concrete classes here, as our base class cannot be - // concrete due to serviceLoader - protected CloudStackApiMetadata(Builder builder) { + public CloudStackApiMetadata() { + this(new Builder()); + } + + protected CloudStackApiMetadata(Builder builder) { super(builder); } - private static class ConcreteBuilder extends Builder { + protected static Properties defaultProperties() { + Properties properties = BaseComputeServiceApiMetadata.Builder.defaultProperties(); + properties.setProperty("jclouds.ssh.max-retries", "7"); + properties.setProperty("jclouds.ssh.retry-auth", "true"); + return properties; + } + public static class Builder + extends BaseComputeServiceApiMetadata.Builder { + + protected Builder() { + id("cloudstack") + .name("Citrix CloudStack API") + .identityName("API Key") + .credentialName("Secret Key") + .documentation(URI.create("http://download.cloud.com/releases/2.2.0/api_2.2.12/TOC_User.html")) + .defaultEndpoint("http://localhost:8080/client/api") + .version("2.2") + .defaultProperties(CloudStackApiMetadata.defaultProperties()) + .javaApi(CloudStackClient.class, CloudStackAsyncClient.class) + .context(TypeToken.of(CloudStackContext.class)) + .contextBuilder(TypeToken.of(CloudStackContextBuilder.class)); + } + @Override public CloudStackApiMetadata build() { return new CloudStackApiMetadata(this); } - } + + @Override + public Builder fromApiMetadata(CloudStackApiMetadata in) { + super.fromApiMetadata(in); + return this; + } - public static ConcreteBuilder builder() { - return new ConcreteBuilder(); - } - - @Override - public ConcreteBuilder toBuilder() { - return builder().fromApiMetadata(this); } } \ No newline at end of file diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/CloudStackContext.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/CloudStackContext.java index 1eb716f5a4..add5192c58 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/CloudStackContext.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/CloudStackContext.java @@ -31,9 +31,8 @@ import com.google.inject.ImplementedBy; * */ @ImplementedBy(CloudStackContextImpl.class) -public interface CloudStackContext extends ComputeServiceContext { +public interface CloudStackContext extends ComputeServiceContext { - @SuppressWarnings("unchecked") @Override RestContext getProviderSpecificContext(); diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/CloudStackContextBuilder.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/CloudStackContextBuilder.java index f1fa6232e9..904972e5ac 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/CloudStackContextBuilder.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/CloudStackContextBuilder.java @@ -23,24 +23,26 @@ import java.util.Properties; import org.jclouds.cloudstack.compute.config.CloudStackComputeServiceContextModule; import org.jclouds.cloudstack.config.CloudStackRestClientModule; -import org.jclouds.cloudstack.internal.CloudStackContextImpl; import org.jclouds.compute.ComputeServiceContextBuilder; +import org.jclouds.providers.ProviderMetadata; +import com.google.common.annotations.VisibleForTesting; import com.google.inject.Module; /** * * @author Adrian Cole */ -public class CloudStackContextBuilder extends ComputeServiceContextBuilder { +public class CloudStackContextBuilder extends + ComputeServiceContextBuilder { - public CloudStackContextBuilder(Properties props) { - super(CloudStackClient.class, CloudStackAsyncClient.class, props); + public CloudStackContextBuilder( + ProviderMetadata providerMetadata) { + super(providerMetadata); } - @Override - protected void addContextModule(List modules) { - modules.add(new CloudStackComputeServiceContextModule()); + public CloudStackContextBuilder(CloudStackApiMetadata apiMetadata) { + super(apiMetadata); } @Override @@ -49,7 +51,13 @@ public class CloudStackContextBuilder extends ComputeServiceContextBuilder modules) { + modules.add(new CloudStackComputeServiceContextModule()); } + + @VisibleForTesting + public Properties getOverrides() { + return overrides; + } + } diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/CloudStackPropertiesBuilder.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/CloudStackPropertiesBuilder.java deleted file mode 100644 index a271e36510..0000000000 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/CloudStackPropertiesBuilder.java +++ /dev/null @@ -1,48 +0,0 @@ -/** - * 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.cloudstack; - -import static org.jclouds.Constants.PROPERTY_API_VERSION; -import static org.jclouds.Constants.PROPERTY_ENDPOINT; - -import java.util.Properties; - -import org.jclouds.PropertiesBuilder; - -/** - * Builds properties used in cloudstack Clients - * - * @author Adrian Cole - */ -public class CloudStackPropertiesBuilder extends PropertiesBuilder { - @Override - protected Properties defaultProperties() { - Properties properties = super.defaultProperties(); - properties.setProperty(PROPERTY_ENDPOINT, "http://localhost:8080/client/api"); - properties.setProperty(PROPERTY_API_VERSION, "2.2"); - properties.setProperty("jclouds.ssh.max-retries", "7"); - properties.setProperty("jclouds.ssh.retry-auth", "true"); - return properties; - } - - public CloudStackPropertiesBuilder(Properties properties) { - super(properties); - } - -} diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/config/CloudStackProperties.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/config/CloudStackProperties.java index 3995f1cfd7..4508246b79 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/config/CloudStackProperties.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/config/CloudStackProperties.java @@ -18,7 +18,7 @@ */ package org.jclouds.cloudstack.config; -import org.jclouds.compute.ComputeServiceContextFactory; +import org.jclouds.compute.ComputeServiceContextBuilder; /** * Configuration properties and constants used in CloudStack connections. @@ -28,7 +28,7 @@ import org.jclouds.compute.ComputeServiceContextFactory; public interface CloudStackProperties { /** - * Type of credentials specified during {@link ComputeServiceContextFactory#createContext}. If + * Type of credentials specified during {@link ComputeServiceContextBuilder#overrides}. If * {@link CredentialType#API_ACCESS_KEY_CREDENTIALS}, the request signing is used. If * {@link CredentialType#PASSWORD_CREDENTIALS}, login will happen and a session will be * persisted. diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/internal/CloudStackContextImpl.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/internal/CloudStackContextImpl.java index 34b8e7077d..2be7231dd2 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/internal/CloudStackContextImpl.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/internal/CloudStackContextImpl.java @@ -57,7 +57,6 @@ public class CloudStackContextImpl extends ComputeServiceContextImpl getProviderSpecificContext() { return providerSpecificContext; diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/util/ApiKeyPairs.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/util/ApiKeyPairs.java index 4e9ee91773..1683fd9524 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/util/ApiKeyPairs.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/util/ApiKeyPairs.java @@ -26,24 +26,19 @@ import java.util.Properties; import java.util.Set; import org.jclouds.Constants; +import org.jclouds.cloudstack.CloudStackApiMetadata; import org.jclouds.cloudstack.CloudStackClient; +import org.jclouds.cloudstack.CloudStackContext; import org.jclouds.cloudstack.domain.Account; import org.jclouds.cloudstack.domain.ApiKeyPair; import org.jclouds.cloudstack.domain.User; -import org.jclouds.compute.ComputeServiceContext; -import org.jclouds.compute.ComputeServiceContextFactory; -import org.jclouds.rest.RestContextFactory; - -import com.google.common.collect.ImmutableSet; -import com.google.inject.Module; +import org.jclouds.compute.ComputeServiceContextBuilder; /** * @author Andrei Savu */ public class ApiKeyPairs { - private final static String PROVIDER = "cloudstack"; - /** * Retrieve the API key pair for a given CloudStack user * @@ -60,10 +55,17 @@ public class ApiKeyPairs { */ public static ApiKeyPair loginToEndpointAsUsernameInDomainWithPasswordAndReturnApiKeyPair( URI endpoint, String username, String password, String domain) { - ComputeServiceContext context = null; + CloudStackContext context = null; try { - context = new ComputeServiceContextFactory(setupRestProperties()). - createContext(PROVIDER, ImmutableSet.of(), setupProperties(endpoint, username, password, domain)); + Properties overrides = new Properties(); + overrides.put(Constants.PROPERTY_TRUST_ALL_CERTS, "true"); + overrides.put(Constants.PROPERTY_RELAX_HOSTNAME, "true"); + overrides.put("jclouds.cloudstack.credential-type", "passwordCredentials"); + + context = ComputeServiceContextBuilder.newBuilder(new CloudStackApiMetadata()) + .endpoint(checkNotNull(endpoint, "endpoint").toASCIIString()) + .credentials(String.format("%s/%s", checkNotNull(domain, "domain"), checkNotNull(username, "username")), password) + .overrides(overrides).build(); CloudStackClient client = CloudStackClient.class.cast(context.getProviderSpecificContext().getApi()); Set listOfAccounts = client.getAccountClient().listAccounts(); @@ -85,23 +87,4 @@ public class ApiKeyPairs { } } - private static Properties setupRestProperties() { - return RestContextFactory.getPropertiesFromResource("/rest.properties"); - } - - private static Properties setupProperties(URI endpoint, String username, String password, String domain) { - Properties overrides = new Properties(); - - overrides.put(Constants.PROPERTY_TRUST_ALL_CERTS, "true"); - overrides.put(Constants.PROPERTY_RELAX_HOSTNAME, "true"); - - overrides.put("jclouds.cloudstack.credential-type", "passwordCredentials"); - - overrides.put(PROVIDER + ".endpoint", checkNotNull(endpoint, "endpoint").toASCIIString()); - overrides.put(PROVIDER + ".identity", - String.format("%s/%s", checkNotNull(domain, "domain"), checkNotNull(username, "username"))); - overrides.put(PROVIDER + ".credential", checkNotNull(password, "password")); - - return overrides; - } } diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/CloudStackApiMetadataTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/CloudStackApiMetadataTest.java index d2d5676dad..81c9746861 100644 --- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/CloudStackApiMetadataTest.java +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/CloudStackApiMetadataTest.java @@ -18,8 +18,7 @@ */ package org.jclouds.cloudstack; -import org.jclouds.apis.ApiType; -import org.jclouds.apis.BaseApiMetadataTest; +import org.jclouds.compute.internal.BaseComputeServiceApiMetadataTest; import org.testng.annotations.Test; /** @@ -27,9 +26,9 @@ import org.testng.annotations.Test; * @author Adrian Cole */ @Test(groups = "unit", testName = "CloudStackApiMetadataTest") -public class CloudStackApiMetadataTest extends BaseApiMetadataTest { +public class CloudStackApiMetadataTest extends BaseComputeServiceApiMetadataTest { public CloudStackApiMetadataTest() { - super(new CloudStackApiMetadata(), ApiType.COMPUTE); + super(new CloudStackApiMetadata()); } } diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/compute/CloudStackComputeServiceAdapterLiveTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/compute/CloudStackComputeServiceAdapterLiveTest.java index 791e1d9047..8dad16187e 100644 --- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/compute/CloudStackComputeServiceAdapterLiveTest.java +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/compute/CloudStackComputeServiceAdapterLiveTest.java @@ -23,9 +23,7 @@ import static com.google.inject.name.Names.bindProperties; import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertFalse; -import static org.testng.Assert.fail; -import java.io.IOException; import java.util.Map; import java.util.Random; import java.util.Set; @@ -97,21 +95,21 @@ public class CloudStackComputeServiceAdapterLiveTest extends BaseCloudStackClien Map credentialStore = Maps.newLinkedHashMap(); @BeforeGroups(groups = { "live" }) - public void setupClient() { - super.setupClient(); + public void setupContext() { + super.setupContext(); Module module = new AbstractModule() { @Override protected void configure() { bindProperties(binder(), setupProperties()); - bind(String.class).annotatedWith(Identity.class).toInstance(identity); + bind(String.class).annotatedWith(Identity.class).toInstance(context.getProviderSpecificContext().getIdentity()); bind(new TypeLiteral>() { }).annotatedWith(Memoized.class).to(GetCurrentUser.class).in(Scopes.SINGLETON); bind(new TypeLiteral>>() { }).annotatedWith(Memoized.class).to(NetworksForCurrentUser.class).in(Scopes.SINGLETON); bind(new TypeLiteral>() { }).toInstance(credentialStore); - bind(CloudStackClient.class).toInstance(context.getApi()); + bind(CloudStackClient.class).toInstance(cloudStackContext.getApi()); bind(new TypeLiteral>() {}). toInstance(new CloudStackComputeServiceContextModule().optionsConverters()); bind(Long.class).annotatedWith(Names.named(PROPERTY_SESSION_INTERVAL)).toInstance(60L); @@ -141,15 +139,10 @@ public class CloudStackComputeServiceAdapterLiveTest extends BaseCloudStackClien CloudStackComputeServiceAdapter.class); keyPairName = prefix + "-adapter-test-keypair"; - try { - keyPair = ComputeTestUtils.setupKeyPair(); + keyPair = ComputeTestUtils.setupKeyPair(); - client.getSSHKeyPairClient().deleteSSHKeyPair(keyPairName); - client.getSSHKeyPairClient().registerSSHKeyPair(keyPairName, keyPair.get("public")); - - } catch (IOException e) { - fail("Unable to create keypair", e); - } + client.getSSHKeyPairClient().deleteSSHKeyPair(keyPairName); + client.getSSHKeyPairClient().registerSSHKeyPair(keyPairName, keyPair.get("public")); } @Test @@ -164,7 +157,7 @@ public class CloudStackComputeServiceAdapterLiveTest extends BaseCloudStackClien public void testCreateNodeWithGroupEncodedIntoName() throws InterruptedException { String group = prefix + "-foo"; String name = group + "-node-" + new Random().nextInt(); - Template template = computeContext.getComputeService().templateBuilder().build(); + Template template = context.getComputeService().templateBuilder().build(); if (!client .getTemplateClient() diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/compute/CloudStackComputeServiceLiveTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/compute/CloudStackComputeServiceLiveTest.java index 68b94e17ab..a0ae087295 100644 --- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/compute/CloudStackComputeServiceLiveTest.java +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/compute/CloudStackComputeServiceLiveTest.java @@ -20,15 +20,14 @@ package org.jclouds.cloudstack.compute; import org.jclouds.cloudstack.CloudStackAsyncClient; import org.jclouds.cloudstack.CloudStackClient; -import org.jclouds.compute.BaseComputeServiceLiveTest; -import org.jclouds.compute.ComputeServiceContextFactory; +import org.jclouds.cloudstack.CloudStackContext; import org.jclouds.compute.domain.NodeMetadata; +import org.jclouds.compute.internal.BaseComputeServiceLiveTest; import org.jclouds.rest.RestContext; import org.jclouds.sshj.config.SshjSshClientModule; import org.testng.annotations.Test; import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableSet; import com.google.inject.Module; /** @@ -38,7 +37,8 @@ import com.google.inject.Module; * @author Adrian Cole */ @Test(groups = "live", enabled = true, singleThreaded = true) -public class CloudStackComputeServiceLiveTest extends BaseComputeServiceLiveTest { +public class CloudStackComputeServiceLiveTest extends + BaseComputeServiceLiveTest { public CloudStackComputeServiceLiveTest() { provider = "cloudstack"; } @@ -50,9 +50,7 @@ public class CloudStackComputeServiceLiveTest extends BaseComputeServiceLiveTest public void testAssignability() throws Exception { @SuppressWarnings("unused") - RestContext tmContext = new ComputeServiceContextFactory( - setupRestProperties()).createContext(provider, identity, credential, ImmutableSet. of(), - setupProperties()).getProviderSpecificContext(); + RestContext tmContext = context.getProviderSpecificContext(); } // cloudstack does not support metadata diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/compute/CloudStackExperimentLiveTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/compute/CloudStackExperimentLiveTest.java index c99cb8bdfe..c8c8445bb7 100644 --- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/compute/CloudStackExperimentLiveTest.java +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/compute/CloudStackExperimentLiveTest.java @@ -90,9 +90,9 @@ public class CloudStackExperimentLiveTest extends BaseCloudStackClientLiveTest { Network network = null; Set nodes = null; try { - assert computeContext.getComputeService().listAssignableLocations().size() > 0; + assert context.getComputeService().listAssignableLocations().size() > 0; - Template template = computeContext.getComputeService().templateBuilder().build(); + Template template = context.getComputeService().templateBuilder().build(); // get the zone we are launching into long zoneId = Long.parseLong(template.getLocation().getId()); @@ -102,7 +102,7 @@ public class CloudStackExperimentLiveTest extends BaseCloudStackClientLiveTest { // find a network offering that supports vlans in our zone long offeringId = get( - context.getApi().getOfferingClient().listNetworkOfferings(specifyVLAN(true).zoneId(zoneId)), 0).getId(); + cloudStackContext.getApi().getOfferingClient().listNetworkOfferings(specifyVLAN(true).zoneId(zoneId)), 0).getId(); // create an arbitrary network network = domainAdminContext.getApi() @@ -115,7 +115,7 @@ public class CloudStackExperimentLiveTest extends BaseCloudStackClientLiveTest { template.getOptions().as(CloudStackTemplateOptions.class).networkId(network.getId()); // launch the VM - nodes = computeContext.getComputeService().createNodesInGroup(group, 1, template); + nodes = context.getComputeService().createNodesInGroup(group, 1, template); assert nodes.size() > 0; @@ -124,7 +124,7 @@ public class CloudStackExperimentLiveTest extends BaseCloudStackClientLiveTest { nodes = newTreeSet(concat(e.getSuccessfulNodes(), e.getNodeErrors().keySet())); } finally { if (nodes != null) - computeContext.getComputeService().destroyNodesMatching(NodePredicates.inGroup(group)); + context.getComputeService().destroyNodesMatching(NodePredicates.inGroup(group)); if (network != null) domainAdminContext.getApi().getNetworkClient().deleteNetwork(network.getId()); } @@ -143,14 +143,14 @@ public class CloudStackExperimentLiveTest extends BaseCloudStackClientLiveTest { SshKeyPair keyPair = client.getSSHKeyPairClient().createSSHKeyPair(keyPairName); String group = prefix + "-windows-test"; - Template template = computeContext.getComputeService().templateBuilder() + Template template = context.getComputeService().templateBuilder() .imageId("290").locationId("1") .options(new CloudStackTemplateOptions().setupStaticNat(false).keyPair(keyPairName)) .build(); NodeMetadata node = null; try { - node = getOnlyElement(computeContext.getComputeService() + node = getOnlyElement(context.getComputeService() .createNodesInGroup(group, 1, template)); String encryptedPassword = client.getVirtualMachineClient() @@ -165,7 +165,7 @@ public class CloudStackExperimentLiveTest extends BaseCloudStackClientLiveTest { } finally { if (node != null) { - computeContext.getComputeService().destroyNode(node.getId()); + context.getComputeService().destroyNode(node.getId()); } } diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/BaseCloudStackAsyncClientTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/BaseCloudStackAsyncClientTest.java index 709601b2c1..e0484cef19 100644 --- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/BaseCloudStackAsyncClientTest.java +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/BaseCloudStackAsyncClientTest.java @@ -20,25 +20,22 @@ package org.jclouds.cloudstack.features; import static org.testng.Assert.assertEquals; -import java.util.Properties; - -import org.jclouds.cloudstack.CloudStackAsyncClient; -import org.jclouds.cloudstack.CloudStackClient; +import org.jclouds.cloudstack.CloudStackApiMetadata; import org.jclouds.cloudstack.config.CloudStackRestClientModule; import org.jclouds.cloudstack.filters.QuerySigner; import org.jclouds.http.HttpRequest; import org.jclouds.http.RequiresHttp; +import org.jclouds.providers.ProviderMetadata; +import org.jclouds.rest.AnonymousProviderMetadata; import org.jclouds.rest.ConfiguresRestClient; -import org.jclouds.rest.RestClientTest; -import org.jclouds.rest.RestContextFactory; -import org.jclouds.rest.RestContextSpec; +import org.jclouds.rest.internal.BaseAsyncClientTest; import com.google.inject.Module; /** * @author Adrian Cole */ -public abstract class BaseCloudStackAsyncClientTest extends RestClientTest { +public abstract class BaseCloudStackAsyncClientTest extends BaseAsyncClientTest { @RequiresHttp @ConfiguresRestClient @@ -58,10 +55,9 @@ public abstract class BaseCloudStackAsyncClientTest extends RestClientTest } @Override - public RestContextSpec createContextSpec() { - Properties props = new Properties(); - props.setProperty("cloudstack.endpoint", "http://localhost:8080/client/api"); - return new RestContextFactory().createContextSpec("cloudstack", "apiKey", "secretKey", props); + protected ProviderMetadata createProviderMetadata() { + return AnonymousProviderMetadata.forApiWithEndpoint(new CloudStackApiMetadata(), + "http://localhost:8080/client/api"); } } \ No newline at end of file diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/BaseCloudStackClientLiveTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/BaseCloudStackClientLiveTest.java index f46a1923eb..db2510239e 100644 --- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/BaseCloudStackClientLiveTest.java +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/BaseCloudStackClientLiveTest.java @@ -18,7 +18,6 @@ */ package org.jclouds.cloudstack.features; -import static com.google.common.base.Strings.emptyToNull; import static com.google.common.collect.Iterables.filter; import static com.google.common.collect.Iterables.get; import static org.testng.Assert.assertEquals; @@ -50,11 +49,9 @@ import org.jclouds.cloudstack.predicates.UserPredicates; import org.jclouds.cloudstack.predicates.VirtualMachineDestroyed; import org.jclouds.cloudstack.predicates.VirtualMachineRunning; import org.jclouds.cloudstack.strategy.BlockUntilJobCompletesAndReturnResult; -import org.jclouds.compute.BaseVersionedServiceLiveTest; import org.jclouds.compute.ComputeService; -import org.jclouds.compute.ComputeServiceContextFactory; import org.jclouds.compute.domain.ExecResponse; -import org.jclouds.logging.log4j.config.Log4JLoggingModule; +import org.jclouds.compute.internal.BaseComputeServiceContextLiveTest; import org.jclouds.net.IPSocket; import org.jclouds.predicates.InetSocketAddressConnect; import org.jclouds.predicates.RetryablePredicate; @@ -76,7 +73,8 @@ import com.google.inject.Module; * * @author Adrian Cole */ -public class BaseCloudStackClientLiveTest extends BaseVersionedServiceLiveTest { +public class BaseCloudStackClientLiveTest extends + BaseComputeServiceContextLiveTest { protected String domainAdminIdentity; protected String domainAdminCredential; protected String globalAdminIdentity; @@ -87,12 +85,13 @@ public class BaseCloudStackClientLiveTest extends BaseVersionedServiceLiveTest { } @Override - protected void setupCredentials() { - super.setupCredentials(); - domainAdminIdentity = emptyToNull(System.getProperty("test." + provider + ".domainAdminIdentity")); - domainAdminCredential = emptyToNull(System.getProperty("test." + provider + ".domainAdminCredential")); - globalAdminIdentity = emptyToNull(System.getProperty("test." + provider + ".globalAdminIdentity")); - globalAdminCredential = emptyToNull(System.getProperty("test." + provider + ".globalAdminCredential")); + protected Properties setupProperties() { + Properties overrides = super.setupProperties(); + domainAdminIdentity = setIfTestSystemPropertyPresent(overrides, provider + ".domainAdminIdentity"); + domainAdminCredential = setIfTestSystemPropertyPresent(overrides, provider + ".domainAdminCredential"); + globalAdminIdentity = setIfTestSystemPropertyPresent(overrides, provider + ".globalAdminIdentity"); + globalAdminCredential = setIfTestSystemPropertyPresent(overrides, provider + ".globalAdminCredential"); + return overrides; } protected Properties setupDomainAdminProperties() { @@ -146,9 +145,8 @@ public class BaseCloudStackClientLiveTest extends BaseVersionedServiceLiveTest { protected String prefix = System.getProperty("user.name"); - protected CloudStackContext computeContext; protected ComputeService computeClient; - protected RestContext context; + protected RestContext cloudStackContext; protected CloudStackClient client; protected CloudStackClient adminClient; protected User user; @@ -192,23 +190,18 @@ public class BaseCloudStackClientLiveTest extends BaseVersionedServiceLiveTest { } } - @BeforeGroups(groups = "live") - public void setupClient() { - setupCredentials(); - - computeContext = CloudStackContext.class.cast(new ComputeServiceContextFactory(setupRestProperties()). - createContext(provider, ImmutableSet. of( - new Log4JLoggingModule(), new SshjSshClientModule()), setupProperties())); - computeClient = computeContext.getComputeService(); - context = computeContext.getProviderSpecificContext(); - client = context.getApi(); - user = verifyCurrentUserIsOfType(context, Account.Type.USER); + @BeforeGroups(groups = { "integration", "live" }) + @Override + public void setupContext() { + super.setupContext(); + computeClient = context.getComputeService(); + cloudStackContext = context.getProviderSpecificContext(); + client = cloudStackContext.getApi(); + user = verifyCurrentUserIsOfType(cloudStackContext, Account.Type.USER); domainAdminEnabled = setupDomainAdminProperties() != null; if (domainAdminEnabled) { - domainAdminComputeContext = CloudStackContext.class.cast(new ComputeServiceContextFactory(setupRestProperties()). - createContext(provider, ImmutableSet. of( - new Log4JLoggingModule(), new SshjSshClientModule()), setupDomainAdminProperties())); + domainAdminComputeContext = createContext(setupDomainAdminProperties(), setupModules()); domainAdminContext = domainAdminComputeContext.getDomainContext(); domainAdminClient = domainAdminContext.getApi(); domainAdminUser = verifyCurrentUserIsOfType(domainAdminContext, Account.Type.DOMAIN_ADMIN); @@ -217,16 +210,14 @@ public class BaseCloudStackClientLiveTest extends BaseVersionedServiceLiveTest { globalAdminEnabled = setupGlobalAdminProperties() != null; if (globalAdminEnabled) { - globalAdminComputeContext = CloudStackContext.class.cast(new ComputeServiceContextFactory(setupRestProperties()). - createContext(provider, ImmutableSet. of( - new Log4JLoggingModule(), new SshjSshClientModule()), setupGlobalAdminProperties())); + globalAdminComputeContext = createContext(setupGlobalAdminProperties(), setupModules()); globalAdminContext = globalAdminComputeContext.getGlobalContext(); globalAdminClient = globalAdminContext.getApi(); globalAdminUser = verifyCurrentUserIsOfType(globalAdminContext, Account.Type.ADMIN); adminClient = globalAdminContext.getApi(); } - injector = Guice.createInjector(new SshjSshClientModule(), new Log4JLoggingModule()); + injector = Guice.createInjector(setupModules()); sshFactory = injector.getInstance(SshClient.Factory.class); socketTester = new RetryablePredicate(new InetSocketAddressConnect(), 180, 1, 1, TimeUnit.SECONDS); injector.injectMembers(socketTester); @@ -251,6 +242,11 @@ public class BaseCloudStackClientLiveTest extends BaseVersionedServiceLiveTest { injector.injectMembers(reuseOrAssociate); } + @Override + protected Module getSshModule() { + return new SshjSshClientModule(); + } + protected static User verifyCurrentUserIsOfType( RestContext context, Account.Type type) { Iterable users = Iterables.concat(context.getApi().getAccountClient().listAccounts()); @@ -272,8 +268,8 @@ public class BaseCloudStackClientLiveTest extends BaseVersionedServiceLiveTest { @AfterGroups(groups = "live") protected void tearDown() { - if (context != null) - context.close(); + if (cloudStackContext != null) + cloudStackContext.close(); } } \ No newline at end of file diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/BaseCloudStackRestClientExpectTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/BaseCloudStackRestClientExpectTest.java index 706767cdb3..5686229973 100644 --- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/BaseCloudStackRestClientExpectTest.java +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/BaseCloudStackRestClientExpectTest.java @@ -24,16 +24,15 @@ import java.net.URI; import java.net.URLEncoder; import java.util.Properties; +import org.jclouds.apis.ApiMetadata; +import org.jclouds.cloudstack.CloudStackApiMetadata; import org.jclouds.cloudstack.CloudStackContext; -import org.jclouds.compute.ComputeServiceContextFactory; import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpResponse; -import org.jclouds.logging.config.NullLoggingModule; -import org.jclouds.rest.BaseRestClientExpectTest; +import org.jclouds.rest.internal.BaseRestClientExpectTest; import com.google.common.base.Function; import com.google.common.collect.ImmutableMultimap; -import com.google.common.collect.ImmutableSet; import com.google.inject.Module; /** @@ -46,12 +45,16 @@ public abstract class BaseCloudStackRestClientExpectTest extends BaseRestClie public BaseCloudStackRestClientExpectTest() { provider = "cloudstack"; } + + @Override + protected ApiMetadata createApiMetadata() { + return new CloudStackApiMetadata(); + } + @Override public S createClient(Function fn, Module module, Properties props) { - return clientFrom(CloudStackContext.class.cast(new ComputeServiceContextFactory(setupRestProperties()) - .createContext(provider, "identity", "credential", ImmutableSet. of(new ExpectModule(fn), - new NullLoggingModule(), module), props))); + return (S) clientFrom(createInjector(fn, module, props).getInstance(CloudStackContext.class)); } protected abstract S clientFrom(CloudStackContext context); diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/FirewallClientLiveTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/FirewallClientLiveTest.java index e25fbee915..089af5bb70 100644 --- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/FirewallClientLiveTest.java +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/FirewallClientLiveTest.java @@ -61,8 +61,8 @@ public class FirewallClientLiveTest extends BaseCloudStackClientLiveTest { private boolean networksDisabled; @BeforeGroups(groups = "live") - public void setupClient() { - super.setupClient(); + public void setupContext() { + super.setupContext(); prefix += "rule"; try { network = find(client.getNetworkClient().listNetworks(), Predicates.and(supportsPortForwarding(), diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalUserClientLiveTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalUserClientLiveTest.java index e42de2287e..e3b3a1cb58 100644 --- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalUserClientLiveTest.java +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalUserClientLiveTest.java @@ -33,15 +33,9 @@ import org.jclouds.cloudstack.domain.Account; import org.jclouds.cloudstack.domain.ApiKeyPair; import org.jclouds.cloudstack.domain.User; import org.jclouds.compute.ComputeServiceContext; -import org.jclouds.compute.ComputeServiceContextFactory; import org.jclouds.crypto.CryptoStreams; -import org.jclouds.logging.log4j.config.Log4JLoggingModule; -import org.jclouds.sshj.config.SshjSshClientModule; import org.testng.annotations.Test; -import com.google.common.collect.ImmutableSet; -import com.google.inject.Module; - /** * Tests behavior of {@code GlobaUserClient} */ @@ -89,9 +83,7 @@ public class GlobalUserClientLiveTest extends BaseCloudStackClientLiveTest { } private void checkAuthAsUser(ApiKeyPair keyPair) { - ComputeServiceContext context = new ComputeServiceContextFactory(setupRestProperties()). - createContext(provider, ImmutableSet.of( - new Log4JLoggingModule(), new SshjSshClientModule()), credentialsAsProperties(keyPair)); + ComputeServiceContext context = createContext(credentialsAsProperties(keyPair), setupModules()); CloudStackClient client = CloudStackClient.class.cast(context.getProviderSpecificContext().getApi()); Set accounts = client.getAccountClient().listAccounts(); diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/LoadBalancerClientLiveTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/LoadBalancerClientLiveTest.java index d190627bdd..759579c4f4 100644 --- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/LoadBalancerClientLiveTest.java +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/LoadBalancerClientLiveTest.java @@ -66,8 +66,8 @@ public class LoadBalancerClientLiveTest extends BaseCloudStackClientLiveTest { private boolean networksDisabled; @BeforeGroups(groups = "live") - public void setupClient() { - super.setupClient(); + public void setupContext() { + super.setupContext(); loadBalancerRuleActive = new RetryablePredicate(new LoadBalancerRuleActive(client), 60, 1, 1, TimeUnit.SECONDS); diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/NetworkClientLiveTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/NetworkClientLiveTest.java index 78dba8a0d9..6cc29c7112 100644 --- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/NetworkClientLiveTest.java +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/NetworkClientLiveTest.java @@ -55,8 +55,8 @@ public class NetworkClientLiveTest extends BaseCloudStackClientLiveTest { private Zone zone; @BeforeGroups(groups = "live") - public void setupClient() { - super.setupClient(); + public void setupContext() { + super.setupContext(); try { zone = find(client.getZoneClient().listZones(), ZonePredicates.supportsAdvancedNetworks()); @@ -104,7 +104,7 @@ public class NetworkClientLiveTest extends BaseCloudStackClientLiveTest { final NetworkOffering offering; try { offering = get( - context.getApi().getOfferingClient().listNetworkOfferings(specifyVLAN(true).zoneId(zone.getId())), 0); + cloudStackContext.getApi().getOfferingClient().listNetworkOfferings(specifyVLAN(true).zoneId(zone.getId())), 0); } catch (NoSuchElementException e) { Logger.getAnonymousLogger().log(Level.SEVERE, "VLAN networks not supported, skipping test"); return; diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/OfferingClientLiveTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/OfferingClientLiveTest.java index eb4ec13f05..fd187ab6c4 100644 --- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/OfferingClientLiveTest.java +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/OfferingClientLiveTest.java @@ -34,6 +34,8 @@ import org.jclouds.cloudstack.options.ListNetworkOfferingsOptions; import org.jclouds.cloudstack.options.ListServiceOfferingsOptions; import org.testng.annotations.Test; +import com.google.common.base.Predicates; +import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; /** @@ -64,7 +66,7 @@ public class OfferingClientLiveTest extends BaseCloudStackClientLiveTest { } catch (NoSuchElementException e) { // This bug is present both in 2.2.8 and 2.2.12 - assertTrue("2.2.8".equals(apiVersion) || "2.2.12".equals(apiVersion)); + assertTrue(Predicates.in(ImmutableSet.of("2.2.8", "2.2.12")).apply(cloudStackContext.getApiVersion())); } } } diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/SessionClientLiveTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/SessionClientLiveTest.java index ca7efd015d..938be58289 100644 --- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/SessionClientLiveTest.java +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/SessionClientLiveTest.java @@ -44,6 +44,7 @@ public class SessionClientLiveTest extends BaseCloudStackClientLiveTest { @Test public void testCreateContextUsingUserAndPasswordAuthentication() { + String endpoint = cloudStackContext.getEndpoint().toASCIIString(); assert globalAdminEnabled; Account testAccount = null; @@ -74,6 +75,7 @@ public class SessionClientLiveTest extends BaseCloudStackClientLiveTest { @Test(expectedExceptions = AuthorizationException.class) public void testTryToGetApiKeypairWithWrongCredentials() { + String endpoint = cloudStackContext.getEndpoint().toASCIIString(); ApiKeyPairs.loginToEndpointAsUsernameInDomainWithPasswordAndReturnApiKeyPair( URI.create(endpoint), "dummy-missing-user", "with-a-wrong-password", ""); } diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/TemplateClientLiveTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/TemplateClientLiveTest.java index ab02040466..60ce768e55 100644 --- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/TemplateClientLiveTest.java +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/TemplateClientLiveTest.java @@ -149,7 +149,7 @@ public class TemplateClientLiveTest extends BaseCloudStackClientLiveTest { String extractUrl = extract.getUrl(); assertNotNull(extractUrl); URI uri = new URI(URLDecoder.decode(extractUrl, "utf-8")); - assertTrue(context.utils().http().exists(uri), "does not exist: " + uri); + assertTrue(cloudStackContext.utils().http().exists(uri), "does not exist: " + uri); } @Test(enabled = true) diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/ZoneAsyncClientTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/ZoneAsyncClientTest.java index fc40f9e87b..bcffc9b1f6 100644 --- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/ZoneAsyncClientTest.java +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/ZoneAsyncClientTest.java @@ -58,7 +58,7 @@ public class ZoneAsyncClientTest extends BaseCloudStackAsyncClientTest DUMMY_SPEC = new RestContextSpec("cloudstack", - "http://localhost:8080/client/api", "2.2", "", "", "apiKey", "secretKey", IntegrationTestClient.class, IntegrationTestAsyncClient.class, - PropertiesBuilder.class, (Class) RestContextBuilder.class, ImmutableList. of(new MockModule(), - new NullLoggingModule(), new AbstractModule() { - @Override - protected void configure() { - bind(RequestSigner.class).to(QuerySigner.class); - } + public static final Injector INJECTOR = ContextBuilder + .newBuilder( + AnonymousProviderMetadata.forClientMappedToAsyncClientOnEndpoint(IntegrationTestClient.class, IntegrationTestAsyncClient.class, + "http://localhost:8080/client/api")) + .credentials("apiKey", "secretKey") + .apiVersion("2.2") + .modules(ImmutableList. of(new MockModule(), new NullLoggingModule())).buildInjector(); - })); @Test void testCreateStringToSign() { - QuerySigner filter = RestContextFactory.createContextBuilder(DUMMY_SPEC).buildInjector() - .getInstance(QuerySigner.class); + QuerySigner filter = INJECTOR.getInstance(QuerySigner.class); assertEquals( filter.createStringToSign(HttpRequest.builder().method("GET") @@ -72,8 +65,7 @@ public class QuerySignerTest { @Test void testFilter() { - QuerySigner filter = RestContextFactory.createContextBuilder(DUMMY_SPEC).buildInjector() - .getInstance(QuerySigner.class); + QuerySigner filter = INJECTOR.getInstance(QuerySigner.class); assertEquals( filter.filter( @@ -85,8 +77,7 @@ public class QuerySignerTest { @Test void testFilterTwice() { - QuerySigner filter = RestContextFactory.createContextBuilder(DUMMY_SPEC).buildInjector() - .getInstance(QuerySigner.class); + QuerySigner filter = INJECTOR.getInstance(QuerySigner.class); HttpRequest request = HttpRequest.builder().method("GET") .endpoint(URI.create("http://localhost:8080/client/api?command=listZones")).build(); for (int i = 0; i < 2; i++) { diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/functions/StaticNATVirtualMachineInNetworkLiveTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/functions/StaticNATVirtualMachineInNetworkLiveTest.java index 592b937de3..c0308fac3d 100644 --- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/functions/StaticNATVirtualMachineInNetworkLiveTest.java +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/functions/StaticNATVirtualMachineInNetworkLiveTest.java @@ -61,7 +61,7 @@ public class StaticNATVirtualMachineInNetworkLiveTest extends NATClientLiveTest @BeforeGroups(groups = "live") public void setupClient() { - super.setupClient(); + super.setupContext(); prefix += "nat"; try { network = find(client.getNetworkClient().listNetworks(), NetworkPredicates.supportsStaticNAT()); diff --git a/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/CloudWatchApiMetadata.java b/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/CloudWatchApiMetadata.java index 70a8190377..51fb3b648d 100644 --- a/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/CloudWatchApiMetadata.java +++ b/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/CloudWatchApiMetadata.java @@ -18,50 +18,83 @@ */ package org.jclouds.cloudwatch; +import static org.jclouds.aws.reference.AWSConstants.PROPERTY_AUTH_TAG; +import static org.jclouds.aws.reference.AWSConstants.PROPERTY_HEADER_TAG; + import java.net.URI; +import java.util.Properties; import org.jclouds.apis.ApiMetadata; import org.jclouds.apis.ApiType; -import org.jclouds.apis.BaseApiMetadata; +import org.jclouds.apis.internal.BaseApiMetadata; +import org.jclouds.rest.RestContext; +import org.jclouds.rest.internal.BaseRestApiMetadata; /** * Implementation of {@link ApiMetadata} for Amazon's CloudWatch api. * + *

note

+ *

+ * This class allows overriding of types {@code S}(client) and {@code A}(asyncClient), so that + * children can add additional methods not declared here, such as new features + * from AWS. + *

+ * + * This class is not setup to allow a different context than {@link RestContext} + * . By doing so, it reduces the type complexity. + * * @author Adrian Cole */ -public class CloudWatchApiMetadata extends BaseApiMetadata { +public class CloudWatchApiMetadata extends + BaseRestApiMetadata, CloudWatchApiMetadata> { + + @Override + public Builder toBuilder() { + return new Builder(getApi(), getAsyncApi()).fromApiMetadata(this); + } public CloudWatchApiMetadata() { - this(builder() - .id("cloudwatch") - .type(ApiType.MONITOR) - .name("Amazon CloudWatch Api") - .identityName("Access Key ID") - .credentialName("Secret Access Key") - .documentation(URI.create("http://docs.amazonwebservices.com/AmazonCloudWatch/latest/APIReference/"))); + this(new Builder(CloudWatchClient.class, CloudWatchAsyncClient.class)); } - // below are so that we can reuse builders, toString, hashCode, etc. - // we have to set concrete classes here, as our base class cannot be - // concrete due to serviceLoader - protected CloudWatchApiMetadata(Builder builder) { - super(builder); + @SuppressWarnings("unchecked") + protected CloudWatchApiMetadata(Builder builder) { + super(Builder.class.cast(builder)); } - private static class ConcreteBuilder extends Builder { + protected static Properties defaultProperties() { + Properties properties = BaseApiMetadata.Builder.defaultProperties(); + properties.setProperty(PROPERTY_AUTH_TAG, "AWS"); + properties.setProperty(PROPERTY_HEADER_TAG, "amz"); + return properties; + } + + public static class Builder extends + BaseRestApiMetadata.Builder, CloudWatchApiMetadata> { + + protected Builder(Class client, Class asyncClient) { + super(client, asyncClient); + id("cloudwatch") + .type(ApiType.MONITOR) + .name("Amazon CloudWatch Api") + .identityName("Access Key ID") + .credentialName("Secret Access Key") + .version(CloudWatchAsyncClient.VERSION) + .defaultProperties(CloudWatchApiMetadata.defaultProperties()) + .defaultEndpoint("https://monitoring.us-east-1.amazonaws.com") + .documentation(URI.create("http://docs.amazonwebservices.com/AmazonCloudWatch/latest/APIReference/")); + } @Override - public CloudWatchApiMetadata build() { - return new CloudWatchApiMetadata(this); + public CloudWatchApiMetadata build() { + return new CloudWatchApiMetadata(this); + } + + @Override + public Builder fromApiMetadata(CloudWatchApiMetadata in) { + super.fromApiMetadata(in); + return this; } } - public static ConcreteBuilder builder() { - return new ConcreteBuilder(); - } - - @Override - public ConcreteBuilder toBuilder() { - return builder().fromApiMetadata(this); - } } \ No newline at end of file diff --git a/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/CloudWatchContextBuilder.java b/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/CloudWatchContextBuilder.java index b08b3bd2a6..7d60ccef2b 100644 --- a/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/CloudWatchContextBuilder.java +++ b/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/CloudWatchContextBuilder.java @@ -19,33 +19,42 @@ package org.jclouds.cloudwatch; import java.util.List; -import java.util.Properties; import org.jclouds.cloudwatch.config.CloudWatchRestClientModule; import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule; import org.jclouds.logging.jdk.config.JDKLoggingModule; +import org.jclouds.providers.ProviderMetadata; +import org.jclouds.rest.RestContext; import org.jclouds.rest.RestContextBuilder; import com.google.inject.Injector; import com.google.inject.Module; /** - * Creates {@link MonitoringContext} or {@link Injector} instances based on the most commonly requested - * arguments. + * Creates {@link MonitoringContext} or {@link Injector} instances based on the + * most commonly requested arguments. *

- * Note that Threadsafe objects will be bound as singletons to the Injector or Context provided. + * Note that Threadsafe objects will be bound as singletons to the Injector or + * Context provided. *

*

- * If no Modules are specified, the default {@link JDKLoggingModule logging} and - * {@link JavaUrlHttpCommandExecutorServiceModule http transports} will be installed. + * If no Modules are specified, the default + * {@link JDKLoggingModule logging} and + * {@link JavaUrlHttpCommandExecutorServiceModule http transports} will be + * installed. * * @author Adrian Cole * @see MonitoringContext */ -public class CloudWatchContextBuilder extends RestContextBuilder { +public class CloudWatchContextBuilder + extends RestContextBuilder, CloudWatchApiMetadata> { - public CloudWatchContextBuilder(Properties props) { - super(CloudWatchClient.class, CloudWatchAsyncClient.class, props); + public CloudWatchContextBuilder(ProviderMetadata, CloudWatchApiMetadata> providerMetadata) { + super(providerMetadata); + } + + public CloudWatchContextBuilder(CloudWatchApiMetadata apiMetadata) { + super(apiMetadata); } @Override diff --git a/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/CloudWatchPropertiesBuilder.java b/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/CloudWatchPropertiesBuilder.java deleted file mode 100644 index b641d2c2e5..0000000000 --- a/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/CloudWatchPropertiesBuilder.java +++ /dev/null @@ -1,53 +0,0 @@ -/** - * 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.cloudwatch; - -import static org.jclouds.Constants.PROPERTY_API_VERSION; -import static org.jclouds.aws.reference.AWSConstants.PROPERTY_AUTH_TAG; -import static org.jclouds.aws.reference.AWSConstants.PROPERTY_HEADER_TAG; - -import java.util.Properties; - -import org.jclouds.PropertiesBuilder; - -/** - * Builds properties used in Cloud Watch Clients - * - * @author Adrian Cole - */ -public class CloudWatchPropertiesBuilder extends PropertiesBuilder { - - @Override - protected Properties defaultProperties() { - Properties properties = super.defaultProperties(); - properties.setProperty(PROPERTY_AUTH_TAG, "AWS"); - properties.setProperty(PROPERTY_HEADER_TAG, "amz"); - properties.setProperty(PROPERTY_API_VERSION, CloudWatchAsyncClient.VERSION); - return properties; - } - - public CloudWatchPropertiesBuilder() { - super(); - } - - public CloudWatchPropertiesBuilder(Properties properties) { - super(properties); - } - -} diff --git a/apis/cloudwatch/src/test/java/org/jclouds/cloudwatch/CloudWatchApiMetadataTest.java b/apis/cloudwatch/src/test/java/org/jclouds/cloudwatch/CloudWatchApiMetadataTest.java index e1a72cdba6..0321386289 100644 --- a/apis/cloudwatch/src/test/java/org/jclouds/cloudwatch/CloudWatchApiMetadataTest.java +++ b/apis/cloudwatch/src/test/java/org/jclouds/cloudwatch/CloudWatchApiMetadataTest.java @@ -19,15 +19,16 @@ package org.jclouds.cloudwatch; import org.jclouds.apis.ApiType; -import org.jclouds.apis.BaseApiMetadataTest; +import org.jclouds.apis.internal.BaseRestApiMetadataTest; import org.testng.annotations.Test; /** * * @author Adrian Cole */ +@SuppressWarnings("rawtypes") @Test(groups = "unit", testName = "CloudWatchApiMetadataTest") -public class CloudWatchApiMetadataTest extends BaseApiMetadataTest { +public class CloudWatchApiMetadataTest extends BaseRestApiMetadataTest { public CloudWatchApiMetadataTest() { super(new CloudWatchApiMetadata(), ApiType.MONITOR); 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 2f4b4f2ce3..193b032682 100644 --- a/apis/cloudwatch/src/test/java/org/jclouds/cloudwatch/CloudWatchAsyncClientTest.java +++ b/apis/cloudwatch/src/test/java/org/jclouds/cloudwatch/CloudWatchAsyncClientTest.java @@ -26,11 +26,11 @@ 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.apis.ApiMetadata; import org.jclouds.aws.domain.Region; import org.jclouds.aws.filters.FormSigner; import org.jclouds.cloudwatch.config.CloudWatchRestClientModule; @@ -44,9 +44,7 @@ import org.jclouds.http.functions.ParseSax; import org.jclouds.location.config.LocationModule; import org.jclouds.location.suppliers.RegionIdToURISupplier; import org.jclouds.rest.ConfiguresRestClient; -import org.jclouds.rest.RestClientTest; -import org.jclouds.rest.RestContextFactory; -import org.jclouds.rest.RestContextSpec; +import org.jclouds.rest.internal.BaseAsyncClientTest; import org.jclouds.rest.internal.RestAnnotationProcessor; import org.jclouds.util.Suppliers2; import org.testng.annotations.Test; @@ -64,7 +62,7 @@ import com.google.inject.TypeLiteral; // NOTE:without testName, this will not call @Before* and fail w/NPE during // surefire @Test(groups = "unit", testName = "CloudWatchAsyncClientTest") -public class CloudWatchAsyncClientTest extends RestClientTest { +public class CloudWatchAsyncClientTest extends BaseAsyncClientTest { public void testRegisterInstancesWithMeasure() throws SecurityException, NoSuchMethodException, IOException { Date date = new Date(10000000l); @@ -125,11 +123,10 @@ public class CloudWatchAsyncClientTest extends RestClientTest createContextSpec() { - Properties props = new Properties(); - props.setProperty("cloudwatch.endpoint", "https://monitoring.us-east-1.amazonaws.com"); - return new RestContextFactory().createContextSpec("cloudwatch", "identity", "credential", props); + public ApiMetadata createApiMetadata() { + return new CloudWatchApiMetadata(); } @Override diff --git a/apis/cloudwatch/src/test/java/org/jclouds/cloudwatch/CloudWatchClientLiveTest.java b/apis/cloudwatch/src/test/java/org/jclouds/cloudwatch/CloudWatchClientLiveTest.java index 672eaead3e..7bf1a80563 100644 --- a/apis/cloudwatch/src/test/java/org/jclouds/cloudwatch/CloudWatchClientLiveTest.java +++ b/apis/cloudwatch/src/test/java/org/jclouds/cloudwatch/CloudWatchClientLiveTest.java @@ -22,45 +22,34 @@ import static com.google.common.base.Preconditions.checkNotNull; import java.util.Calendar; import java.util.Date; -import java.util.Properties; import java.util.Set; import org.jclouds.cloudwatch.domain.Datapoint; import org.jclouds.cloudwatch.domain.Statistics; import org.jclouds.cloudwatch.domain.Unit; import org.jclouds.cloudwatch.options.GetMetricStatisticsOptions; -import org.jclouds.logging.log4j.config.Log4JLoggingModule; -import org.jclouds.rest.BaseRestClientLiveTest; import org.jclouds.rest.RestContext; -import org.jclouds.rest.RestContextFactory; -import org.testng.annotations.AfterTest; -import org.testng.annotations.BeforeGroups; +import org.jclouds.rest.internal.BaseContextLiveTest; +import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; -import com.google.common.collect.ImmutableSet; -import com.google.inject.Module; - /** * Tests behavior of {@code CloudWatchClient} * * @author Adrian Cole */ @Test(groups = "live", singleThreaded = true) -public class CloudWatchClientLiveTest extends BaseRestClientLiveTest { +public class CloudWatchClientLiveTest extends BaseContextLiveTest> { public CloudWatchClientLiveTest() { provider = "cloudwatch"; } private CloudWatchClient client; - private RestContext context; - - @BeforeGroups(groups = { "live" }) - public void setupClient() { - setupCredentials(); - Properties overrides = setupProperties(); - context = new RestContextFactory().createContext(provider, ImmutableSet. of(new Log4JLoggingModule()), - overrides); + @Override + @BeforeClass(groups = { "integration", "live" }) + public void setupContext() { + super.setupContext(); client = context.getApi(); } @@ -73,15 +62,9 @@ public class CloudWatchClientLiveTest extends BaseRestClientLiveTest { Calendar cal = Calendar.getInstance(); cal.add(Calendar.MINUTE, -60 * 24 * 3); // 3 days - Set datapoints = client.getMetricStatisticsInRegion( - region, "CPUUtilization", "AWS/EC2", cal.getTime(), new Date(), 180, Statistics.AVERAGE, - GetMetricStatisticsOptions.Builder.unit(Unit.PERCENT)); + Set datapoints = client.getMetricStatisticsInRegion(region, "CPUUtilization", "AWS/EC2", + cal.getTime(), new Date(), 180, Statistics.AVERAGE, GetMetricStatisticsOptions.Builder.unit(Unit.PERCENT)); return checkNotNull(datapoints, "Got null response for EC2 datapoints in region "); } - - @AfterTest - public void shutdown() { - context.close(); - } } diff --git a/apis/deltacloud/src/main/java/org/jclouds/deltacloud/DeltacloudApiMetadata.java b/apis/deltacloud/src/main/java/org/jclouds/deltacloud/DeltacloudApiMetadata.java index ff12e02b9f..f84a352a8f 100644 --- a/apis/deltacloud/src/main/java/org/jclouds/deltacloud/DeltacloudApiMetadata.java +++ b/apis/deltacloud/src/main/java/org/jclouds/deltacloud/DeltacloudApiMetadata.java @@ -19,50 +19,63 @@ package org.jclouds.deltacloud; import java.net.URI; +import java.util.Properties; import org.jclouds.apis.ApiMetadata; -import org.jclouds.apis.ApiType; -import org.jclouds.apis.BaseApiMetadata; +import org.jclouds.compute.ComputeServiceContext; +import org.jclouds.compute.internal.BaseComputeServiceApiMetadata; + +import com.google.common.reflect.TypeToken; /** * Implementation of {@link ApiMetadata} for Apache Deltacloud API * * @author Adrian Cole */ -public class DeltacloudApiMetadata extends BaseApiMetadata { +public class DeltacloudApiMetadata extends BaseComputeServiceApiMetadata, DeltacloudApiMetadata> { - public DeltacloudApiMetadata() { - this(builder() - .id("deltacloud") - .type(ApiType.COMPUTE) - .name("Apache Deltacloud API") - .identityName("Username") - .credentialName("Password") - .documentation(URI.create("http://deltacloud.apache.org/api.html"))); + @Override + public Builder toBuilder() { + return new Builder().fromApiMetadata(this); } - // below are so that we can reuse builders, toString, hashCode, etc. - // we have to set concrete classes here, as our base class cannot be - // concrete due to serviceLoader - protected DeltacloudApiMetadata(Builder builder) { + public DeltacloudApiMetadata() { + this(new Builder()); + } + + protected DeltacloudApiMetadata(Builder builder) { super(builder); } - private static class ConcreteBuilder extends Builder { + protected static Properties defaultProperties() { + return BaseComputeServiceApiMetadata.Builder.defaultProperties(); + } + + public static class Builder extends BaseComputeServiceApiMetadata.Builder, DeltacloudApiMetadata> { + + protected Builder() { + id("deltacloud") + .name("Apache Deltacloud API") + .identityName("Username") + .credentialName("Password") + .documentation(URI.create("http://deltacloud.apache.org/api.html")) + .version("0.3.0") + .defaultEndpoint("http://localhost:3001/api") + .javaApi(DeltacloudClient.class, DeltacloudAsyncClient.class) + .contextBuilder(TypeToken.of(DeltacloudContextBuilder.class)); + } + + @Override + public DeltacloudApiMetadata build() { + return new DeltacloudApiMetadata(this); + } + + @Override + public Builder fromApiMetadata(DeltacloudApiMetadata in) { + super.fromApiMetadata(in); + return this; + } - @Override - public DeltacloudApiMetadata build() { - return new DeltacloudApiMetadata(this); } - } - public static ConcreteBuilder builder() { - return new ConcreteBuilder(); - } - - @Override - public ConcreteBuilder toBuilder() { - return builder().fromApiMetadata(this); - } - -} \ No newline at end of file + } \ No newline at end of file diff --git a/apis/deltacloud/src/main/java/org/jclouds/deltacloud/DeltacloudContextBuilder.java b/apis/deltacloud/src/main/java/org/jclouds/deltacloud/DeltacloudContextBuilder.java index b84e82c5d2..b37769c36e 100644 --- a/apis/deltacloud/src/main/java/org/jclouds/deltacloud/DeltacloudContextBuilder.java +++ b/apis/deltacloud/src/main/java/org/jclouds/deltacloud/DeltacloudContextBuilder.java @@ -19,11 +19,12 @@ package org.jclouds.deltacloud; import java.util.List; -import java.util.Properties; +import org.jclouds.compute.ComputeServiceContext; import org.jclouds.compute.ComputeServiceContextBuilder; import org.jclouds.deltacloud.compute.config.DeltacloudComputeServiceContextModule; import org.jclouds.deltacloud.config.DeltacloudRestClientModule; +import org.jclouds.providers.ProviderMetadata; import com.google.inject.Module; @@ -31,10 +32,17 @@ import com.google.inject.Module; * * @author Adrian Cole */ -public class DeltacloudContextBuilder extends ComputeServiceContextBuilder { +public class DeltacloudContextBuilder + extends + ComputeServiceContextBuilder, DeltacloudApiMetadata> { - public DeltacloudContextBuilder(Properties props) { - super(DeltacloudClient.class, DeltacloudAsyncClient.class, props); + public DeltacloudContextBuilder( + ProviderMetadata, DeltacloudApiMetadata> providerMetadata) { + super(providerMetadata); + } + + public DeltacloudContextBuilder(DeltacloudApiMetadata apiMetadata) { + super(apiMetadata); } @Override diff --git a/apis/deltacloud/src/main/java/org/jclouds/deltacloud/DeltacloudPropertiesBuilder.java b/apis/deltacloud/src/main/java/org/jclouds/deltacloud/DeltacloudPropertiesBuilder.java deleted file mode 100644 index eeb3d1d531..0000000000 --- a/apis/deltacloud/src/main/java/org/jclouds/deltacloud/DeltacloudPropertiesBuilder.java +++ /dev/null @@ -1,46 +0,0 @@ -/** - * 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.deltacloud; - -import static org.jclouds.Constants.PROPERTY_API_VERSION; -import static org.jclouds.Constants.PROPERTY_ENDPOINT; - -import java.util.Properties; - -import org.jclouds.PropertiesBuilder; - -/** - * Builds properties used in deltacloud Clients - * - * @author Adrian Cole - */ -public class DeltacloudPropertiesBuilder extends PropertiesBuilder { - @Override - protected Properties defaultProperties() { - Properties properties = super.defaultProperties(); - properties.setProperty(PROPERTY_API_VERSION, "0.3.0"); - properties.setProperty(PROPERTY_ENDPOINT, "http://localhost:3001/api"); - return properties; - } - - public DeltacloudPropertiesBuilder(Properties properties) { - super(properties); - } - -} diff --git a/apis/deltacloud/src/test/java/org/jclouds/deltacloud/DeltacloudApiMetadataTest.java b/apis/deltacloud/src/test/java/org/jclouds/deltacloud/DeltacloudApiMetadataTest.java index 2dd950d963..da1263f079 100644 --- a/apis/deltacloud/src/test/java/org/jclouds/deltacloud/DeltacloudApiMetadataTest.java +++ b/apis/deltacloud/src/test/java/org/jclouds/deltacloud/DeltacloudApiMetadataTest.java @@ -18,8 +18,7 @@ */ package org.jclouds.deltacloud; -import org.jclouds.apis.ApiType; -import org.jclouds.apis.BaseApiMetadataTest; +import org.jclouds.compute.internal.BaseComputeServiceApiMetadataTest; import org.testng.annotations.Test; /** @@ -27,9 +26,9 @@ import org.testng.annotations.Test; * @author Adrian Cole */ @Test(groups = "unit", testName = "DeltacloudApiMetadataTest") -public class DeltacloudApiMetadataTest extends BaseApiMetadataTest { +public class DeltacloudApiMetadataTest extends BaseComputeServiceApiMetadataTest { public DeltacloudApiMetadataTest() { - super(new DeltacloudApiMetadata(), ApiType.COMPUTE); + super(new DeltacloudApiMetadata()); } } diff --git a/apis/deltacloud/src/test/java/org/jclouds/deltacloud/DeltacloudAsyncClientTest.java b/apis/deltacloud/src/test/java/org/jclouds/deltacloud/DeltacloudAsyncClientTest.java index e9611fb98e..d8f0e1899b 100644 --- a/apis/deltacloud/src/test/java/org/jclouds/deltacloud/DeltacloudAsyncClientTest.java +++ b/apis/deltacloud/src/test/java/org/jclouds/deltacloud/DeltacloudAsyncClientTest.java @@ -23,9 +23,9 @@ import static org.testng.Assert.assertEquals; import java.io.IOException; import java.lang.reflect.Method; import java.net.URI; -import java.util.Properties; import java.util.Set; +import org.jclouds.apis.ApiMetadata; import org.jclouds.deltacloud.config.DeltacloudRestClientModule; import org.jclouds.deltacloud.domain.DeltacloudCollection; import org.jclouds.deltacloud.functions.ReturnVoidOnRedirectedDelete; @@ -46,12 +46,10 @@ import org.jclouds.http.filters.BasicAuthentication; import org.jclouds.http.functions.ParseSax; import org.jclouds.http.functions.ReleasePayloadAndReturn; import org.jclouds.rest.ConfiguresRestClient; -import org.jclouds.rest.RestClientTest; -import org.jclouds.rest.RestContextFactory; -import org.jclouds.rest.RestContextSpec; import org.jclouds.rest.functions.ReturnEmptyMultimapOnNotFoundOr404; import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404; import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; +import org.jclouds.rest.internal.BaseAsyncClientTest; import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.rest.internal.RestAnnotationProcessor; import org.testng.annotations.Test; @@ -67,9 +65,10 @@ 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 = "DeltacloudAsyncClientTest") -public class DeltacloudAsyncClientTest extends RestClientTest { +public class DeltacloudAsyncClientTest extends BaseAsyncClientTest { public void testGetCollections() throws SecurityException, NoSuchMethodException, IOException { Method method = DeltacloudAsyncClient.class.getMethod("getCollections"); HttpRequest httpRequest = processor.createRequest(method); @@ -85,7 +84,7 @@ public class DeltacloudAsyncClientTest extends RestClientTest httpRequest = processor.createRequest(method, "imageId-1"); assertRequestLineEquals(httpRequest, "POST http://localhost:3001/api/instances HTTP/1.1"); @@ -250,9 +249,9 @@ public class DeltacloudAsyncClientTest extends RestClientTest httpRequest = processor.createRequest(method, "imageId-1", - CreateInstanceOptions.Builder.named("foo")); + CreateInstanceOptions.Builder.named("foo")); assertRequestLineEquals(httpRequest, "POST http://localhost:3001/api/instances HTTP/1.1"); assertNonPayloadHeadersEqual(httpRequest, "Accept: application/xml\n"); @@ -268,8 +267,8 @@ public class DeltacloudAsyncClientTest extends RestClientTest provideHardwareProfileCollection(Supplier> collectionSupplier) { + protected Supplier provideHardwareProfileCollection( + Supplier> collectionSupplier) { return Suppliers.ofInstance(URI.create("http://localhost:3001/api/profiles")); } @@ -329,15 +329,13 @@ public class DeltacloudAsyncClientTest extends RestClientTest provideInstanceStateCollection(Supplier> collectionSupplier) { + protected Supplier provideInstanceStateCollection( + Supplier> collectionSupplier) { return Suppliers.ofInstance(URI.create("http://localhost:3001/api/instance_states")); } } - @Override - public RestContextSpec createContextSpec() { - Properties props = new Properties(); - props.setProperty("deltacloud.endpoint", "http://localhost:3001/api"); - return new RestContextFactory().createContextSpec("deltacloud", "foo", "bar", props); + protected ApiMetadata createApiMetadata() { + return new DeltacloudApiMetadata(); } } diff --git a/apis/deltacloud/src/test/java/org/jclouds/deltacloud/DeltacloudClientLiveTest.java b/apis/deltacloud/src/test/java/org/jclouds/deltacloud/DeltacloudClientLiveTest.java index 0842c81890..82a4f46532 100644 --- a/apis/deltacloud/src/test/java/org/jclouds/deltacloud/DeltacloudClientLiveTest.java +++ b/apis/deltacloud/src/test/java/org/jclouds/deltacloud/DeltacloudClientLiveTest.java @@ -35,6 +35,7 @@ import org.jclouds.http.HttpRequest; import org.jclouds.net.IPSocket; import org.jclouds.ssh.SshClient; import org.jclouds.sshj.config.SshjSshClientModule; +import org.testng.annotations.AfterClass; import org.testng.annotations.Test; import com.google.common.base.Predicate; @@ -150,9 +151,9 @@ public class DeltacloudClientLiveTest extends ReadOnlyDeltacloudClientLiveTest { } @Override - protected void tearDown() { + @AfterClass(groups = { "integration", "live" }) + protected void tearDownContext() { testDestroyInstance(); - super.tearDown(); + super.tearDownContext(); } - } diff --git a/apis/deltacloud/src/test/java/org/jclouds/deltacloud/ReadOnlyDeltacloudClientLiveTest.java b/apis/deltacloud/src/test/java/org/jclouds/deltacloud/ReadOnlyDeltacloudClientLiveTest.java index 487f613b9f..3aefc77489 100644 --- a/apis/deltacloud/src/test/java/org/jclouds/deltacloud/ReadOnlyDeltacloudClientLiveTest.java +++ b/apis/deltacloud/src/test/java/org/jclouds/deltacloud/ReadOnlyDeltacloudClientLiveTest.java @@ -22,12 +22,11 @@ import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNotNull; import static org.testng.Assert.assertTrue; -import java.util.Properties; import java.util.Set; import java.util.concurrent.TimeUnit; -import org.jclouds.compute.BaseVersionedServiceLiveTest; -import org.jclouds.compute.ComputeServiceContextFactory; +import org.jclouds.compute.ComputeServiceContext; +import org.jclouds.compute.internal.BaseComputeServiceContextLiveTest; import org.jclouds.deltacloud.domain.DeltacloudCollection; import org.jclouds.deltacloud.domain.HardwareProfile; import org.jclouds.deltacloud.domain.Image; @@ -37,13 +36,11 @@ import org.jclouds.deltacloud.domain.Realm; import org.jclouds.deltacloud.domain.Transition; import org.jclouds.deltacloud.predicates.InstanceFinished; import org.jclouds.deltacloud.predicates.InstanceRunning; -import org.jclouds.logging.log4j.config.Log4JLoggingModule; import org.jclouds.net.IPSocket; import org.jclouds.predicates.InetSocketAddressConnect; import org.jclouds.predicates.RetryablePredicate; -import org.jclouds.rest.RestContext; -import org.testng.annotations.AfterGroups; -import org.testng.annotations.BeforeGroups; +import org.jclouds.sshj.config.SshjSshClientModule; +import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import com.google.common.base.Predicate; @@ -60,27 +57,24 @@ import com.google.inject.Module; * @author Adrian Cole */ @Test(groups = "live", singleThreaded = true, testName = "ReadOnlyDeltacloudClientLiveTest") -public class ReadOnlyDeltacloudClientLiveTest extends BaseVersionedServiceLiveTest { +public class ReadOnlyDeltacloudClientLiveTest + extends + BaseComputeServiceContextLiveTest> { + public ReadOnlyDeltacloudClientLiveTest() { provider = "deltacloud"; } protected DeltacloudClient client; - protected RestContext context; - protected Predicate socketTester; protected ImmutableMap> stateChanges; - - @BeforeGroups(groups = "live") - public void setupClient() { - setupCredentials(); - Properties overrides = setupProperties(); - context = new ComputeServiceContextFactory().createContext(provider, ImmutableSet. of(new Log4JLoggingModule()), - overrides).getProviderSpecificContext(); - - client = context.getApi(); + @Override + @BeforeClass(groups = { "integration", "live" }) + public void setupContext() { + super.setupContext(); + client = context.getProviderSpecificContext().getApi(); socketTester = new RetryablePredicate(new InetSocketAddressConnect(), 180, 1, TimeUnit.SECONDS); stateChanges = ImmutableMap.> of(// Instance.State.RUNNING, new RetryablePredicate(new InstanceRunning(client), 600, 1, @@ -168,10 +162,9 @@ public class ReadOnlyDeltacloudClientLiveTest extends BaseVersionedServiceLiveTe } } - @AfterGroups(groups = "live") - protected void tearDown() { - if (context != null) - context.close(); + @Override + protected Module getSshModule() { + return new SshjSshClientModule(); } } diff --git a/apis/deltacloud/src/test/java/org/jclouds/deltacloud/compute/DeltacloudComputeServiceLiveTest.java b/apis/deltacloud/src/test/java/org/jclouds/deltacloud/compute/DeltacloudComputeServiceLiveTest.java index e2c8522958..7fc4ca3ff2 100644 --- a/apis/deltacloud/src/test/java/org/jclouds/deltacloud/compute/DeltacloudComputeServiceLiveTest.java +++ b/apis/deltacloud/src/test/java/org/jclouds/deltacloud/compute/DeltacloudComputeServiceLiveTest.java @@ -22,9 +22,9 @@ import static org.testng.Assert.assertEquals; import java.io.IOException; -import org.jclouds.compute.BaseComputeServiceLiveTest; -import org.jclouds.compute.ComputeServiceContextFactory; +import org.jclouds.compute.ComputeServiceContext; import org.jclouds.compute.domain.NodeMetadata; +import org.jclouds.compute.internal.BaseComputeServiceLiveTest; import org.jclouds.deltacloud.DeltacloudAsyncClient; import org.jclouds.deltacloud.DeltacloudClient; import org.jclouds.domain.LocationScope; @@ -41,7 +41,10 @@ import com.google.inject.Module; * @author Adrian Cole */ @Test(groups = "live", enabled = true, singleThreaded = true, testName = "DeltacloudComputeServiceLiveTest") -public class DeltacloudComputeServiceLiveTest extends BaseComputeServiceLiveTest { +public class DeltacloudComputeServiceLiveTest + extends + BaseComputeServiceLiveTest> { + public DeltacloudComputeServiceLiveTest() { provider = "deltacloud"; } @@ -60,8 +63,7 @@ public class DeltacloudComputeServiceLiveTest extends BaseComputeServiceLiveTest public void testAssignability() throws Exception { @SuppressWarnings("unused") - RestContext tmContext = new ComputeServiceContextFactory() - .createContext(provider, identity, credential).getProviderSpecificContext(); + RestContext tmContext = context.getProviderSpecificContext(); } @Override diff --git a/apis/deltacloud/src/test/java/org/jclouds/deltacloud/compute/DeltacloudTemplateBuilderLiveTest.java b/apis/deltacloud/src/test/java/org/jclouds/deltacloud/compute/DeltacloudTemplateBuilderLiveTest.java index bfbc4ca6cf..b1aaea7f7c 100644 --- a/apis/deltacloud/src/test/java/org/jclouds/deltacloud/compute/DeltacloudTemplateBuilderLiveTest.java +++ b/apis/deltacloud/src/test/java/org/jclouds/deltacloud/compute/DeltacloudTemplateBuilderLiveTest.java @@ -23,10 +23,13 @@ import static org.testng.Assert.assertEquals; import java.util.Set; -import org.jclouds.compute.BaseTemplateBuilderLiveTest; +import org.jclouds.compute.ComputeServiceContext; import org.jclouds.compute.domain.OsFamily; import org.jclouds.compute.domain.OsFamilyVersion64Bit; import org.jclouds.compute.domain.Template; +import org.jclouds.compute.internal.BaseTemplateBuilderLiveTest; +import org.jclouds.deltacloud.DeltacloudAsyncClient; +import org.jclouds.deltacloud.DeltacloudClient; import org.testng.annotations.Test; import com.google.common.base.Predicate; @@ -38,7 +41,9 @@ import com.google.common.collect.ImmutableSet; * @author Adrian Cole */ @Test(groups = "live") -public class DeltacloudTemplateBuilderLiveTest extends BaseTemplateBuilderLiveTest { +public class DeltacloudTemplateBuilderLiveTest + extends + BaseTemplateBuilderLiveTest> { public DeltacloudTemplateBuilderLiveTest() { provider = "deltacloud"; diff --git a/apis/deltacloud/src/test/java/org/jclouds/deltacloud/handlers/DeltacloudRedirectionRetryHandlerTest.java b/apis/deltacloud/src/test/java/org/jclouds/deltacloud/handlers/DeltacloudRedirectionRetryHandlerTest.java index c74823b97d..1403fdf20e 100644 --- a/apis/deltacloud/src/test/java/org/jclouds/deltacloud/handlers/DeltacloudRedirectionRetryHandlerTest.java +++ b/apis/deltacloud/src/test/java/org/jclouds/deltacloud/handlers/DeltacloudRedirectionRetryHandlerTest.java @@ -25,22 +25,13 @@ import static org.easymock.EasyMock.verify; import java.net.URI; -import javax.inject.Named; -import javax.inject.Singleton; - +import org.jclouds.compute.ComputeServiceContextBuilder; import org.jclouds.http.HttpCommand; import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpResponse; -import org.jclouds.rest.BaseRestClientTest.MockModule; -import org.jclouds.rest.config.RestModule; import org.testng.annotations.Test; -import com.google.common.collect.LinkedHashMultimap; -import com.google.common.collect.Multimap; -import com.google.inject.AbstractModule; -import com.google.inject.Guice; import com.google.inject.Injector; -import com.google.inject.Provides; /** * Tests behavior of {@code DeltacloudRedirectionRetry} @@ -49,19 +40,7 @@ import com.google.inject.Provides; */ @Test(groups = "unit") public class DeltacloudRedirectionRetryHandlerTest { - Injector injector = Guice.createInjector(new MockModule(), new RestModule(), new AbstractModule() { - @SuppressWarnings("unused") - @Provides - @Singleton - @Named("CONSTANTS") - protected Multimap constants() { - return LinkedHashMultimap.create(); - } - - @Override - protected void configure() { - } - }); + Injector injector = ComputeServiceContextBuilder.forTests().buildInjector(); @Test public void test302DoesNotRetryOnDelete() { diff --git a/apis/ec2/src/main/java/org/jclouds/ec2/EC2ApiMetadata.java b/apis/ec2/src/main/java/org/jclouds/ec2/EC2ApiMetadata.java index 6e5120ab3d..80c26fc456 100644 --- a/apis/ec2/src/main/java/org/jclouds/ec2/EC2ApiMetadata.java +++ b/apis/ec2/src/main/java/org/jclouds/ec2/EC2ApiMetadata.java @@ -18,58 +18,111 @@ */ package org.jclouds.ec2; +import static org.jclouds.aws.reference.AWSConstants.PROPERTY_AUTH_TAG; +import static org.jclouds.aws.reference.AWSConstants.PROPERTY_HEADER_TAG; +import static org.jclouds.compute.config.ComputeServiceProperties.RESOURCENAME_DELIMITER; +import static org.jclouds.ec2.reference.EC2Constants.PROPERTY_EC2_AMI_OWNERS; +import static org.jclouds.ec2.reference.EC2Constants.PROPERTY_EC2_AUTO_ALLOCATE_ELASTIC_IPS; +import static org.jclouds.ec2.reference.EC2Constants.PROPERTY_EC2_TIMEOUT_SECURITYGROUP_PRESENT; + import java.net.URI; +import java.util.Properties; import org.jclouds.apis.ApiMetadata; -import org.jclouds.apis.ApiType; -import org.jclouds.apis.BaseApiMetadata; +import org.jclouds.compute.internal.BaseComputeServiceApiMetadata; +import org.jclouds.ec2.compute.EC2ComputeServiceContext; + +import com.google.common.reflect.TypeParameter; +import com.google.common.reflect.TypeToken; /** * Implementation of {@link ApiMetadata} for Amazon's EC2 api. * + *

note

+ *

+ * This class allows overriding of types {@code S}(client) and {@code A} + * (asyncClient), so that children can add additional methods not declared here, + * such as new features from AWS. + *

+ * + * As this is a popular api, we also allow overrides for type {@code C} + * (context). This allows subtypes to add in new feature groups or extensions, + * not present in the base api. For example, you could make a subtype for + * context, that exposes admin operations. + * * @author Adrian Cole */ -public class EC2ApiMetadata extends BaseApiMetadata { +public class EC2ApiMetadata, M extends EC2ApiMetadata> + extends BaseComputeServiceApiMetadata { - public EC2ApiMetadata() { - this(builder() - .id("ec2") - .type(ApiType.COMPUTE) - .name("Amazon Elastic Compute Cloud (EC2) API") - .identityName("Access Key ID") - .credentialName("Secret Access Key") - .documentation(URI.create("http://docs.amazonwebservices.com/AWSEC2/latest/APIReference"))); + @SuppressWarnings({ "unchecked", "rawtypes" }) + @Override + public Builder toBuilder() { + return (Builder) new Builder(getApi(), getAsyncApi()).fromApiMetadata(this); } - // below are so that we can reuse builders, toString, hashCode, etc. - // we have to set concrete classes here, as our base class cannot be - // concrete due to serviceLoader - protected EC2ApiMetadata(EC2ApiMetadataBuilder builder) { + @SuppressWarnings({ "unchecked", "rawtypes" }) + public EC2ApiMetadata() { + this(new Builder(EC2Client.class, EC2AsyncClient.class)); + } + + protected EC2ApiMetadata(Builder builder) { super(builder); } - public static class EC2ApiMetadataBuilder> extends Builder { + protected static Properties defaultProperties() { + Properties properties = BaseComputeServiceApiMetadata.Builder.defaultProperties(); + properties.setProperty(PROPERTY_AUTH_TAG, "AWS"); + properties.setProperty(PROPERTY_HEADER_TAG, "amz"); + properties.setProperty(PROPERTY_EC2_AMI_OWNERS, "*"); + properties.setProperty(PROPERTY_EC2_TIMEOUT_SECURITYGROUP_PRESENT, "500"); + properties.setProperty(PROPERTY_EC2_AUTO_ALLOCATE_ELASTIC_IPS, "false"); + properties.setProperty(RESOURCENAME_DELIMITER, "#"); + return properties; + } - @Override - public EC2ApiMetadata build() { - return new EC2ApiMetadata(this); + public static class Builder, M extends EC2ApiMetadata> + extends BaseComputeServiceApiMetadata.Builder { + + protected Builder(Class syncClient, Class asyncClient) { + id("ec2") + .name("Amazon Elastic Compute Cloud (EC2) API") + .identityName("Access Key ID") + .credentialName("Secret Access Key") + .defaultEndpoint("https://ec2.us-east-1.amazonaws.com") + .documentation(URI.create("http://docs.amazonwebservices.com/AWSEC2/latest/APIReference")) + .version(EC2AsyncClient.VERSION) + .defaultProperties(EC2ApiMetadata.defaultProperties()) + .javaApi(syncClient, asyncClient) + .contextBuilder(new TypeToken>(getClass()) { + private static final long serialVersionUID = 1L; + }); } - } - - private static class EC2ConcreteBuilder extends EC2ApiMetadataBuilder { - + + /** + * {@inheritDoc} + */ @Override - public EC2ApiMetadata build() { - return new EC2ApiMetadata(this); + @SuppressWarnings("rawtypes") + protected TypeToken contextToken(TypeToken clientToken, TypeToken asyncClientToken) { + return new TypeToken>() { + private static final long serialVersionUID = 1L; + }.where(new TypeParameter() { + }, clientToken).where(new TypeParameter() { + }, asyncClientToken); } + @SuppressWarnings({ "rawtypes", "unchecked" }) + @Override + public M build() { + return (M) new EC2ApiMetadata(this); + } + + @Override + public Builder fromApiMetadata(M in) { + super.fromApiMetadata(in); + return this; + } + } - private static EC2ConcreteBuilder builder() { - return new EC2ConcreteBuilder(); - } - - @Override - public EC2ApiMetadataBuilder toBuilder() { - return builder().fromApiMetadata(this); - } } \ No newline at end of file diff --git a/apis/ec2/src/main/java/org/jclouds/ec2/EC2ContextBuilder.java b/apis/ec2/src/main/java/org/jclouds/ec2/EC2ContextBuilder.java index d5be95c855..4836d97f87 100644 --- a/apis/ec2/src/main/java/org/jclouds/ec2/EC2ContextBuilder.java +++ b/apis/ec2/src/main/java/org/jclouds/ec2/EC2ContextBuilder.java @@ -19,40 +19,44 @@ package org.jclouds.ec2; import java.util.List; -import java.util.Properties; import org.jclouds.compute.ComputeServiceContextBuilder; +import org.jclouds.ec2.compute.EC2ComputeServiceContext; import org.jclouds.ec2.compute.config.EC2ComputeServiceContextModule; import org.jclouds.ec2.compute.config.EC2ResolveImagesModule; import org.jclouds.ec2.config.EC2RestClientModule; import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule; import org.jclouds.logging.jdk.config.JDKLoggingModule; +import org.jclouds.providers.ProviderMetadata; import com.google.inject.Injector; import com.google.inject.Module; /** - * Creates {@link EC2ComputeServiceContext} or {@link Injector} instances based on the most commonly - * requested arguments. + * Creates {@link EC2ComputeServiceContext} or {@link Injector} instances based + * on the most commonly requested arguments. *

- * Note that Threadsafe objects will be bound as singletons to the Injector or Context provided. + * Note that Threadsafe objects will be bound as singletons to the Injector or + * Context provided. *

*

- * If no Modules are specified, the default {@link JDKLoggingModule logging} and - * {@link JavaUrlHttpCommandExecutorServiceModule http transports} will be installed. + * If no Modules are specified, the default + * {@link JDKLoggingModule logging} and + * {@link JavaUrlHttpCommandExecutorServiceModule http transports} will be + * installed. * * @author Adrian Cole * @see EC2ComputeServiceContext */ -public class EC2ContextBuilder extends ComputeServiceContextBuilder { +public class EC2ContextBuilder, M extends EC2ApiMetadata> + extends ComputeServiceContextBuilder { - public EC2ContextBuilder(Properties props) { - super(EC2Client.class, EC2AsyncClient.class, props); + public EC2ContextBuilder(ProviderMetadata providerMetadata) { + super(providerMetadata); } - @Override - public EC2ContextBuilder withModules(Iterable modules) { - return (EC2ContextBuilder) super.withModules(modules); + public EC2ContextBuilder(M apiMetadata) { + super(apiMetadata); } @Override @@ -62,7 +66,8 @@ public class EC2ContextBuilder extends ComputeServiceContextBuilder modules) { - modules.add(EC2RestClientModule.create()); + modules.add(new EC2RestClientModule(apiMetadata.getApi(), apiMetadata.getAsyncApi(), + EC2RestClientModule.DELEGATE_MAP)); } @Override diff --git a/apis/ec2/src/main/java/org/jclouds/ec2/EC2PropertiesBuilder.java b/apis/ec2/src/main/java/org/jclouds/ec2/EC2PropertiesBuilder.java deleted file mode 100644 index f117597c96..0000000000 --- a/apis/ec2/src/main/java/org/jclouds/ec2/EC2PropertiesBuilder.java +++ /dev/null @@ -1,59 +0,0 @@ -/** - * 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.ec2; - -import static org.jclouds.Constants.PROPERTY_API_VERSION; -import static org.jclouds.aws.reference.AWSConstants.PROPERTY_AUTH_TAG; -import static org.jclouds.aws.reference.AWSConstants.PROPERTY_HEADER_TAG; -import static org.jclouds.compute.config.ComputeServiceProperties.RESOURCENAME_DELIMITER; -import static org.jclouds.ec2.reference.EC2Constants.PROPERTY_EC2_AMI_OWNERS; -import static org.jclouds.ec2.reference.EC2Constants.PROPERTY_EC2_AUTO_ALLOCATE_ELASTIC_IPS; -import static org.jclouds.ec2.reference.EC2Constants.PROPERTY_EC2_TIMEOUT_SECURITYGROUP_PRESENT; - -import java.util.Properties; - -import org.jclouds.PropertiesBuilder; - -/** - * Builds properties used in EC2 Clients - * - * @author Adrian Cole - */ -public class EC2PropertiesBuilder extends PropertiesBuilder { - @Override - protected Properties defaultProperties() { - Properties properties = super.defaultProperties(); - properties.setProperty(PROPERTY_AUTH_TAG, "AWS"); - properties.setProperty(PROPERTY_HEADER_TAG, "amz"); - properties.setProperty(PROPERTY_API_VERSION, EC2AsyncClient.VERSION); - properties.setProperty(PROPERTY_EC2_AMI_OWNERS, "*"); - properties.setProperty(PROPERTY_EC2_TIMEOUT_SECURITYGROUP_PRESENT, "500"); - properties.setProperty(PROPERTY_EC2_AUTO_ALLOCATE_ELASTIC_IPS, "false"); - properties.setProperty(RESOURCENAME_DELIMITER, "#"); - return properties; - } - - public EC2PropertiesBuilder(Properties properties) { - super(properties); - } - - public EC2PropertiesBuilder() { - super(); - } -} diff --git a/apis/ec2/src/main/java/org/jclouds/ec2/compute/EC2ComputeService.java b/apis/ec2/src/main/java/org/jclouds/ec2/compute/EC2ComputeService.java index 3ea04e1638..be5f90d46f 100644 --- a/apis/ec2/src/main/java/org/jclouds/ec2/compute/EC2ComputeService.java +++ b/apis/ec2/src/main/java/org/jclouds/ec2/compute/EC2ComputeService.java @@ -87,7 +87,7 @@ public class EC2ComputeService extends BaseComputeService { private final LoadingCache securityGroupMap; @Inject - protected EC2ComputeService(ComputeServiceContext context, Map credentialStore, + protected EC2ComputeService(@SuppressWarnings("rawtypes") ComputeServiceContext context, Map credentialStore, @Memoized Supplier> images, @Memoized Supplier> sizes, @Memoized Supplier> locations, ListNodesStrategy listNodesStrategy, GetNodeMetadataStrategy getNodeMetadataStrategy, CreateNodesInGroupThenAddToSet runNodesAndAddToSetStrategy, diff --git a/apis/cloudfiles/src/main/java/org/jclouds/cloudfiles/CloudFilesPropertiesBuilder.java b/apis/ec2/src/main/java/org/jclouds/ec2/compute/EC2ComputeServiceContext.java similarity index 63% rename from apis/cloudfiles/src/main/java/org/jclouds/cloudfiles/CloudFilesPropertiesBuilder.java rename to apis/ec2/src/main/java/org/jclouds/ec2/compute/EC2ComputeServiceContext.java index cef4e42ca2..255d4dd868 100644 --- a/apis/cloudfiles/src/main/java/org/jclouds/cloudfiles/CloudFilesPropertiesBuilder.java +++ b/apis/ec2/src/main/java/org/jclouds/ec2/compute/EC2ComputeServiceContext.java @@ -16,26 +16,21 @@ * specific language governing permissions and limitations * under the License. */ -package org.jclouds.cloudfiles; +package org.jclouds.ec2.compute; -import java.util.Properties; +import org.jclouds.compute.ComputeServiceContext; +import org.jclouds.ec2.EC2AsyncClient; +import org.jclouds.ec2.EC2Client; +import org.jclouds.ec2.compute.internal.EC2ComputeServiceContextImpl; -import org.jclouds.openstack.swift.SwiftPropertiesBuilder; +import com.google.inject.ImplementedBy; /** - * * @author Adrian Cole */ -public class CloudFilesPropertiesBuilder extends SwiftPropertiesBuilder { +@ImplementedBy(EC2ComputeServiceContextImpl.class) +public interface EC2ComputeServiceContext extends ComputeServiceContext { @Override - protected Properties defaultProperties() { - Properties properties = super.defaultProperties(); - return properties; - } - - public CloudFilesPropertiesBuilder(Properties properties) { - super(properties); - } - + EC2ComputeService getComputeService(); } diff --git a/apis/ec2/src/main/java/org/jclouds/ec2/compute/config/EC2ComputeServiceDependenciesModule.java b/apis/ec2/src/main/java/org/jclouds/ec2/compute/config/EC2ComputeServiceDependenciesModule.java index e801bbb2fa..9055515736 100644 --- a/apis/ec2/src/main/java/org/jclouds/ec2/compute/config/EC2ComputeServiceDependenciesModule.java +++ b/apis/ec2/src/main/java/org/jclouds/ec2/compute/config/EC2ComputeServiceDependenciesModule.java @@ -93,6 +93,7 @@ public class EC2ComputeServiceDependenciesModule extends AbstractModule { return instanceToNodeState; } + @SuppressWarnings("rawtypes") @Override protected void configure() { bind(TemplateBuilder.class).to(EC2TemplateBuilderImpl.class); diff --git a/apis/ec2/src/main/java/org/jclouds/ec2/compute/internal/EC2ComputeServiceContextImpl.java b/apis/ec2/src/main/java/org/jclouds/ec2/compute/internal/EC2ComputeServiceContextImpl.java new file mode 100644 index 0000000000..1d55021e64 --- /dev/null +++ b/apis/ec2/src/main/java/org/jclouds/ec2/compute/internal/EC2ComputeServiceContextImpl.java @@ -0,0 +1,52 @@ +/** + * 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.ec2.compute.internal; + +import java.util.Map; + +import javax.inject.Inject; +import javax.inject.Singleton; + +import org.jclouds.compute.Utils; +import org.jclouds.compute.internal.ComputeServiceContextImpl; +import org.jclouds.domain.Credentials; +import org.jclouds.ec2.EC2AsyncClient; +import org.jclouds.ec2.EC2Client; +import org.jclouds.ec2.compute.EC2ComputeService; +import org.jclouds.ec2.compute.EC2ComputeServiceContext; +import org.jclouds.rest.RestContext; + +/** + * @author Adrian Cole + */ +@Singleton +public class EC2ComputeServiceContextImpl extends + ComputeServiceContextImpl implements EC2ComputeServiceContext { + @Inject + public EC2ComputeServiceContextImpl(EC2ComputeService computeService, Map credentialStore, + Utils utils, @SuppressWarnings("rawtypes") RestContext providerSpecificContext) { + super(computeService, credentialStore, utils, providerSpecificContext); + } + + @Override + public EC2ComputeService getComputeService() { + return EC2ComputeService.class.cast(super.getComputeService()); + } + +} diff --git a/apis/ec2/src/main/java/org/jclouds/ec2/config/EC2RestClientModule.java b/apis/ec2/src/main/java/org/jclouds/ec2/config/EC2RestClientModule.java index 0495303dd3..e9d1862270 100644 --- a/apis/ec2/src/main/java/org/jclouds/ec2/config/EC2RestClientModule.java +++ b/apis/ec2/src/main/java/org/jclouds/ec2/config/EC2RestClientModule.java @@ -73,10 +73,6 @@ public class EC2RestClientModule .put(ElasticBlockStoreClient.class, ElasticBlockStoreAsyncClient.class)// .build(); - public static EC2RestClientModule create() { - return new EC2RestClientModule(EC2Client.class, EC2AsyncClient.class, DELEGATE_MAP); - } - public EC2RestClientModule(Class sync, Class async, Map, Class> delegateMap) { super(sync, async, delegateMap); } diff --git a/apis/ec2/src/test/java/org/jclouds/ec2/CloudApplicationArchitecturesEC2ClientLiveTest.java b/apis/ec2/src/test/java/org/jclouds/ec2/CloudApplicationArchitecturesEC2ClientLiveTest.java index f83af9a86c..8efc145d76 100644 --- a/apis/ec2/src/test/java/org/jclouds/ec2/CloudApplicationArchitecturesEC2ClientLiveTest.java +++ b/apis/ec2/src/test/java/org/jclouds/ec2/CloudApplicationArchitecturesEC2ClientLiveTest.java @@ -27,16 +27,16 @@ import static org.testng.Assert.assertNotNull; import java.io.IOException; import java.net.UnknownHostException; import java.util.Map; -import java.util.Properties; import java.util.Set; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import org.jclouds.aws.AWSResponseException; -import org.jclouds.compute.BaseVersionedServiceLiveTest; import org.jclouds.compute.domain.ExecResponse; +import org.jclouds.compute.internal.BaseComputeServiceContextLiveTest; import org.jclouds.domain.LoginCredentials; +import org.jclouds.ec2.compute.EC2ComputeServiceContext; import org.jclouds.ec2.domain.BlockDevice; import org.jclouds.ec2.domain.Image.EbsBlockDevice; import org.jclouds.ec2.domain.InstanceState; @@ -50,25 +50,21 @@ import org.jclouds.ec2.domain.Volume.InstanceInitiatedShutdownBehavior; import org.jclouds.ec2.predicates.InstanceHasIpAddress; import org.jclouds.ec2.predicates.InstanceStateRunning; import org.jclouds.http.HttpResponseException; -import org.jclouds.logging.log4j.config.Log4JLoggingModule; import org.jclouds.net.IPSocket; import org.jclouds.predicates.RetryablePredicate; import org.jclouds.predicates.SocketOpen; -import org.jclouds.rest.RestContextFactory; import org.jclouds.scriptbuilder.ScriptBuilder; import org.jclouds.scriptbuilder.domain.OsFamily; import org.jclouds.ssh.SshClient; import org.jclouds.ssh.SshException; import org.testng.annotations.AfterTest; -import org.testng.annotations.BeforeGroups; +import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; import com.google.common.collect.Maps; import com.google.inject.Injector; -import com.google.inject.Module; /** * Follows the book Cloud Application Architectures ISBN: 978-0-596-15636-7 @@ -80,7 +76,7 @@ import com.google.inject.Module; * @author Adrian Cole */ @Test(groups = "live", enabled = false, singleThreaded = true, testName = "CloudApplicationArchitecturesEC2ClientLiveTest") -public class CloudApplicationArchitecturesEC2ClientLiveTest extends BaseVersionedServiceLiveTest { +public class CloudApplicationArchitecturesEC2ClientLiveTest> extends BaseComputeServiceContextLiveTest { public CloudApplicationArchitecturesEC2ClientLiveTest() { provider = "ec2"; } @@ -97,12 +93,10 @@ public class CloudApplicationArchitecturesEC2ClientLiveTest extends BaseVersione private RetryablePredicate hasIpTester; private RetryablePredicate runningTester; - @BeforeGroups(groups = { "live" }) - public void setupClient() { - setupCredentials(); - Properties overrides = setupProperties(); - Injector injector = new RestContextFactory().createContextBuilder(provider, - ImmutableSet. of(new Log4JLoggingModule()), overrides).buildInjector(); + @BeforeClass(groups = { "integration", "live" }) + public void setupContext() { + super.setupContext(); + Injector injector = context.utils().injector(); client = injector.getInstance(EC2Client.class); sshFactory = injector.getInstance(SshClient.Factory.class); runningTester = new RetryablePredicate(new InstanceStateRunning(client), 180, 5, diff --git a/apis/ec2/src/test/java/org/jclouds/ec2/EBSBootEC2ClientLiveTest.java b/apis/ec2/src/test/java/org/jclouds/ec2/EBSBootEC2ClientLiveTest.java index 077cf7953b..c51173f3d0 100644 --- a/apis/ec2/src/test/java/org/jclouds/ec2/EBSBootEC2ClientLiveTest.java +++ b/apis/ec2/src/test/java/org/jclouds/ec2/EBSBootEC2ClientLiveTest.java @@ -27,16 +27,16 @@ import static org.testng.Assert.assertNotNull; import java.net.UnknownHostException; import java.util.Map; -import java.util.Properties; import java.util.Set; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import org.jclouds.aws.AWSResponseException; -import org.jclouds.compute.BaseVersionedServiceLiveTest; import org.jclouds.compute.domain.ExecResponse; +import org.jclouds.compute.internal.BaseComputeServiceContextLiveTest; import org.jclouds.domain.LoginCredentials; +import org.jclouds.ec2.compute.EC2ComputeServiceContext; import org.jclouds.ec2.domain.Attachment; import org.jclouds.ec2.domain.BlockDevice; import org.jclouds.ec2.domain.Image; @@ -60,28 +60,24 @@ import org.jclouds.ec2.predicates.VolumeAttached; import org.jclouds.ec2.predicates.VolumeAvailable; import org.jclouds.http.HttpResponseException; import org.jclouds.io.Payloads; -import org.jclouds.logging.log4j.config.Log4JLoggingModule; import org.jclouds.net.IPSocket; import org.jclouds.predicates.RetryablePredicate; import org.jclouds.predicates.SocketOpen; -import org.jclouds.rest.RestContextFactory; import org.jclouds.scriptbuilder.InitScript; import org.jclouds.scriptbuilder.domain.OsFamily; import org.jclouds.scriptbuilder.domain.Statements; import org.jclouds.ssh.SshClient; import org.jclouds.ssh.SshException; import org.testng.annotations.AfterTest; -import org.testng.annotations.BeforeGroups; +import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; import com.google.common.base.Predicate; import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; import com.google.common.collect.Maps; import com.google.inject.Injector; -import com.google.inject.Module; /** * Adapted from the following sources: {@link http://gist.github.com/249915}, {@link http @@ -93,7 +89,7 @@ import com.google.inject.Module; * @author Adrian Cole */ @Test(groups = "live", enabled = false, singleThreaded = true, testName = "EBSBootEC2ClientLiveTest") -public class EBSBootEC2ClientLiveTest extends BaseVersionedServiceLiveTest { +public class EBSBootEC2ClientLiveTest> extends BaseComputeServiceContextLiveTest { public EBSBootEC2ClientLiveTest() { provider = "ec2"; } @@ -127,12 +123,11 @@ public class EBSBootEC2ClientLiveTest extends BaseVersionedServiceLiveTest { private Attachment attachment; private String mkEbsBoot; - @BeforeGroups(groups = { "live" }) - public void setupClient() { - setupCredentials(); - Properties overrides = setupProperties(); - Injector injector = new RestContextFactory().createContextBuilder(provider, - ImmutableSet. of(new Log4JLoggingModule()), overrides).buildInjector(); + @Override + @BeforeClass(groups = { "integration", "live" }) + public void setupContext() { + super.setupContext(); + Injector injector = context.utils().injector(); client = injector.getInstance(EC2Client.class); sshFactory = injector.getInstance(SshClient.Factory.class); SocketOpen socketOpen = injector.getInstance(SocketOpen.class); diff --git a/apis/ec2/src/test/java/org/jclouds/ec2/EC2ApiMetadataTest.java b/apis/ec2/src/test/java/org/jclouds/ec2/EC2ApiMetadataTest.java index 14f62cdc91..74478bf7b0 100644 --- a/apis/ec2/src/test/java/org/jclouds/ec2/EC2ApiMetadataTest.java +++ b/apis/ec2/src/test/java/org/jclouds/ec2/EC2ApiMetadataTest.java @@ -18,18 +18,18 @@ */ package org.jclouds.ec2; -import org.jclouds.apis.ApiType; -import org.jclouds.apis.BaseApiMetadataTest; +import org.jclouds.compute.internal.BaseComputeServiceApiMetadataTest; import org.testng.annotations.Test; /** * * @author Adrian Cole */ +@SuppressWarnings("rawtypes") @Test(groups = "unit", testName = "EC2ApiMetadataTest") -public class EC2ApiMetadataTest extends BaseApiMetadataTest { +public class EC2ApiMetadataTest extends BaseComputeServiceApiMetadataTest { public EC2ApiMetadataTest() { - super(new EC2ApiMetadata(), ApiType.COMPUTE); + super(new EC2ApiMetadata()); } } diff --git a/apis/ec2/src/test/java/org/jclouds/ec2/compute/EC2ComputeServiceLiveTest.java b/apis/ec2/src/test/java/org/jclouds/ec2/compute/EC2ComputeServiceLiveTest.java index 233cc93a47..41d53a20fd 100644 --- a/apis/ec2/src/test/java/org/jclouds/ec2/compute/EC2ComputeServiceLiveTest.java +++ b/apis/ec2/src/test/java/org/jclouds/ec2/compute/EC2ComputeServiceLiveTest.java @@ -27,17 +27,17 @@ import java.util.NoSuchElementException; import java.util.Properties; import java.util.Set; -import org.jclouds.compute.BaseComputeServiceLiveTest; import org.jclouds.compute.ComputeServiceContext; -import org.jclouds.compute.ComputeServiceContextFactory; import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.domain.OsFamily; import org.jclouds.compute.domain.Template; +import org.jclouds.compute.internal.BaseComputeServiceLiveTest; import org.jclouds.compute.options.TemplateOptions; import org.jclouds.compute.predicates.NodePredicates; import org.jclouds.domain.Location; import org.jclouds.domain.LocationScope; import org.jclouds.domain.LoginCredentials; +import org.jclouds.ec2.EC2AsyncClient; import org.jclouds.ec2.EC2Client; import org.jclouds.ec2.compute.options.EC2TemplateOptions; import org.jclouds.ec2.domain.BlockDevice; @@ -54,7 +54,6 @@ import org.jclouds.ec2.services.ElasticBlockStoreClient; import org.jclouds.ec2.services.InstanceClient; import org.jclouds.ec2.services.KeyPairClient; import org.jclouds.ec2.services.SecurityGroupClient; -import org.jclouds.logging.log4j.config.Log4JLoggingModule; import org.jclouds.net.IPSocket; import org.jclouds.scriptbuilder.domain.Statements; import org.jclouds.sshj.config.SshjSshClientModule; @@ -63,7 +62,6 @@ import org.testng.annotations.Test; import com.google.common.base.Predicate; import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSortedSet; import com.google.common.collect.Iterables; import com.google.common.collect.Sets; @@ -74,7 +72,7 @@ import com.google.inject.Module; * @author Adrian Cole */ @Test(groups = "live", singleThreaded = true) -public class EC2ComputeServiceLiveTest extends BaseComputeServiceLiveTest { +public class EC2ComputeServiceLiveTest> extends BaseComputeServiceLiveTest { public EC2ComputeServiceLiveTest() { provider = "ec2"; @@ -177,14 +175,13 @@ public class EC2ComputeServiceLiveTest extends BaseComputeServiceLiveTest { @Test(enabled = true) //, dependsOnMethods = "testCompareSizes") public void testAutoIpAllocation() throws Exception { - ComputeServiceContext context = null; + ComputeServiceContext context = null; String group = this.group + "aip"; try { Properties overrides = setupProperties(); overrides.setProperty(EC2Constants.PROPERTY_EC2_AUTO_ALLOCATE_ELASTIC_IPS, "true"); - context = new ComputeServiceContextFactory().createContext(provider, - ImmutableSet. of(new Log4JLoggingModule()), overrides); + context = createContext(overrides, setupModules()); // create a node Set nodes = diff --git a/apis/ec2/src/test/java/org/jclouds/ec2/compute/EC2TemplateBuilderLiveTest.java b/apis/ec2/src/test/java/org/jclouds/ec2/compute/EC2TemplateBuilderLiveTest.java index 6495c88c2f..f8cae411ba 100644 --- a/apis/ec2/src/test/java/org/jclouds/ec2/compute/EC2TemplateBuilderLiveTest.java +++ b/apis/ec2/src/test/java/org/jclouds/ec2/compute/EC2TemplateBuilderLiveTest.java @@ -27,10 +27,11 @@ import java.lang.reflect.Method; import java.util.Collection; import java.util.List; -import org.jclouds.compute.BaseTemplateBuilderLiveTest; import org.jclouds.compute.ComputeServiceContext; -import org.jclouds.compute.ComputeServiceContextFactory; import org.jclouds.compute.domain.Template; +import org.jclouds.compute.internal.BaseTemplateBuilderLiveTest; +import org.jclouds.ec2.EC2AsyncClient; +import org.jclouds.ec2.EC2Client; import org.jclouds.ec2.options.DescribeAvailabilityZonesOptions; import org.jclouds.ec2.options.DescribeImagesOptions; import org.jclouds.ec2.options.DescribeRegionsOptions; @@ -47,7 +48,7 @@ import com.google.common.collect.ImmutableSet; import com.google.common.collect.Lists; import com.google.inject.Module; -public abstract class EC2TemplateBuilderLiveTest extends BaseTemplateBuilderLiveTest { +public abstract class EC2TemplateBuilderLiveTest> extends BaseTemplateBuilderLiveTest { @Test public void testTemplateBuilderCanUseImageIdWithoutFetchingAllImages() throws Exception { @@ -55,14 +56,14 @@ public abstract class EC2TemplateBuilderLiveTest extends BaseTemplateBuilderLive String defaultImageId = defaultTemplate.getImage().getId(); String defaultImageProviderId = defaultTemplate.getImage().getProviderId(); - ComputeServiceContext context = null; + ComputeServiceContext context = null; try { // Track http commands final List commandsInvoked = Lists.newArrayList(); - context = new ComputeServiceContextFactory(setupRestProperties()).createContext(provider, - ImmutableSet. of(new Log4JLoggingModule(), - TrackingJavaUrlHttpCommandExecutorService.newTrackingModule(commandsInvoked)), - setupProperties()); + context = createContext( + setupProperties(), + ImmutableSet. of(new Log4JLoggingModule(), + TrackingJavaUrlHttpCommandExecutorService.newTrackingModule(commandsInvoked))); Template template = context.getComputeService().templateBuilder().imageId(defaultImageId) .build(); diff --git a/apis/ec2/src/test/java/org/jclouds/ec2/compute/TestCanRecreateGroupLiveTest.java b/apis/ec2/src/test/java/org/jclouds/ec2/compute/TestCanRecreateGroupLiveTest.java index 1e80331689..c0dbdb145f 100644 --- a/apis/ec2/src/test/java/org/jclouds/ec2/compute/TestCanRecreateGroupLiveTest.java +++ b/apis/ec2/src/test/java/org/jclouds/ec2/compute/TestCanRecreateGroupLiveTest.java @@ -18,45 +18,26 @@ */ package org.jclouds.ec2.compute; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.util.Properties; - -import org.jclouds.compute.BaseVersionedServiceLiveTest; -import org.jclouds.compute.ComputeServiceContext; -import org.jclouds.compute.ComputeServiceContextFactory; import org.jclouds.compute.RunNodesException; import org.jclouds.compute.domain.Template; +import org.jclouds.compute.internal.BaseComputeServiceContextLiveTest; import org.jclouds.compute.predicates.NodePredicates; -import org.jclouds.logging.log4j.config.Log4JLoggingModule; -import org.jclouds.sshj.config.SshjSshClientModule; -import org.testng.annotations.BeforeGroups; +import org.jclouds.ec2.EC2AsyncClient; +import org.jclouds.ec2.EC2Client; import org.testng.annotations.Test; import com.google.common.base.Throwables; -import com.google.common.collect.ImmutableSet; -import com.google.inject.Module; /** * * @author Adrian Cole */ @Test(groups = "live", testName="TestCanRecreateGroupLiveTest") -public class TestCanRecreateGroupLiveTest extends BaseVersionedServiceLiveTest { +public class TestCanRecreateGroupLiveTest> extends BaseComputeServiceContextLiveTest { public TestCanRecreateGroupLiveTest() { provider = "ec2"; } - private ComputeServiceContext context; - - @BeforeGroups(groups = { "live" }) - public void setupClient() throws FileNotFoundException, IOException { - setupCredentials(); - Properties overrides = setupProperties(); - context = new ComputeServiceContextFactory().createContext(provider, - ImmutableSet. of(new Log4JLoggingModule(), new SshjSshClientModule()), overrides); - } - public void testCanRecreateGroup() throws Exception { String tag = PREFIX + "recreate"; diff --git a/apis/ec2/src/test/java/org/jclouds/ec2/services/AvailabilityZoneAndRegionClientLiveTest.java b/apis/ec2/src/test/java/org/jclouds/ec2/services/AvailabilityZoneAndRegionClientLiveTest.java index ef8a59dcdb..dff51b3b23 100644 --- a/apis/ec2/src/test/java/org/jclouds/ec2/services/AvailabilityZoneAndRegionClientLiveTest.java +++ b/apis/ec2/src/test/java/org/jclouds/ec2/services/AvailabilityZoneAndRegionClientLiveTest.java @@ -26,26 +26,20 @@ import static org.testng.Assert.assertNotNull; import java.net.URI; import java.util.Iterator; import java.util.Map.Entry; -import java.util.Properties; import java.util.Set; import java.util.SortedMap; import org.jclouds.aws.domain.Region; -import org.jclouds.compute.BaseVersionedServiceLiveTest; -import org.jclouds.compute.ComputeServiceContextFactory; +import org.jclouds.compute.internal.BaseComputeServiceContextLiveTest; import org.jclouds.ec2.EC2AsyncClient; import org.jclouds.ec2.EC2Client; +import org.jclouds.ec2.compute.EC2ComputeServiceContext; import org.jclouds.ec2.domain.AvailabilityZoneInfo; -import org.jclouds.logging.log4j.config.Log4JLoggingModule; -import org.jclouds.rest.RestContext; -import org.testng.annotations.AfterTest; -import org.testng.annotations.BeforeGroups; +import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; -import com.google.common.collect.ImmutableSet; import com.google.common.collect.Lists; import com.google.common.collect.Maps; -import com.google.inject.Module; /** * Tests behavior of {@code AvailabilityZoneAndRegionClient} @@ -53,21 +47,18 @@ import com.google.inject.Module; * @author Adrian Cole */ @Test(groups = "live", singleThreaded = true, testName = "AvailabilityZoneAndRegionClientLiveTest") -public class AvailabilityZoneAndRegionClientLiveTest extends BaseVersionedServiceLiveTest { +public class AvailabilityZoneAndRegionClientLiveTest> extends BaseComputeServiceContextLiveTest { public AvailabilityZoneAndRegionClientLiveTest() { provider = "ec2"; } private AvailabilityZoneAndRegionClient client; - private RestContext context; - @BeforeGroups(groups = { "live" }) - public void setupClient() { - setupCredentials(); - Properties overrides = setupProperties(); - context = new ComputeServiceContextFactory().createContext(provider, - ImmutableSet. of(new Log4JLoggingModule()), overrides).getProviderSpecificContext(); - client = context.getApi().getAvailabilityZoneAndRegionServices(); + @Override + @BeforeClass(groups = { "integration", "live" }) + public void setupContext() { + super.setupContext(); + client = context.getProviderSpecificContext().getApi().getAvailabilityZoneAndRegionServices(); } public void testDescribeAvailabilityZones() { @@ -106,8 +97,4 @@ public class AvailabilityZoneAndRegionClientLiveTest extends BaseVersionedServic assertEquals(iterator.next().getKey(), r2); } - @AfterTest - public void shutdown() { - context.close(); - } } diff --git a/apis/ec2/src/test/java/org/jclouds/ec2/services/BaseEC2AsyncClientTest.java b/apis/ec2/src/test/java/org/jclouds/ec2/services/BaseEC2AsyncClientTest.java index 3e1ae2ab85..7b141a9563 100644 --- a/apis/ec2/src/test/java/org/jclouds/ec2/services/BaseEC2AsyncClientTest.java +++ b/apis/ec2/src/test/java/org/jclouds/ec2/services/BaseEC2AsyncClientTest.java @@ -28,14 +28,14 @@ import java.util.Set; import javax.inject.Singleton; +import org.jclouds.apis.ApiMetadata; import org.jclouds.aws.domain.Region; import org.jclouds.aws.filters.FormSigner; import org.jclouds.compute.domain.Image; import org.jclouds.date.DateService; +import org.jclouds.ec2.EC2ApiMetadata; import org.jclouds.ec2.EC2AsyncClient; import org.jclouds.ec2.EC2Client; -import org.jclouds.ec2.EC2ContextBuilder; -import org.jclouds.ec2.EC2PropertiesBuilder; import org.jclouds.ec2.compute.domain.RegionAndName; import org.jclouds.ec2.config.EC2RestClientModule; import org.jclouds.http.HttpRequest; @@ -44,9 +44,7 @@ import org.jclouds.location.config.LocationModule; import org.jclouds.location.suppliers.RegionIdToURISupplier; import org.jclouds.location.suppliers.RegionIdToZoneIdsSupplier; import org.jclouds.rest.ConfiguresRestClient; -import org.jclouds.rest.RestClientTest; -import org.jclouds.rest.RestContextFactory; -import org.jclouds.rest.RestContextSpec; +import org.jclouds.rest.internal.BaseAsyncClientTest; import org.jclouds.util.Suppliers2; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; @@ -64,7 +62,7 @@ import com.google.inject.Provides; * @author Adrian Cole */ @Test(groups = "unit") -public abstract class BaseEC2AsyncClientTest extends RestClientTest { +public abstract class BaseEC2AsyncClientTest extends BaseAsyncClientTest { @RequiresHttp @ConfiguresRestClient protected static class StubEC2RestClientModule extends EC2RestClientModule { @@ -133,10 +131,6 @@ public abstract class BaseEC2AsyncClientTest extends RestClientTest { assertEquals(request.getFilters().get(0).getClass(), FormSigner.class); } - public BaseEC2AsyncClientTest() { - super(); - } - @Override @BeforeTest protected void setupFactory() throws IOException { @@ -148,17 +142,10 @@ public abstract class BaseEC2AsyncClientTest extends RestClientTest { protected Module createModule() { return new StubEC2RestClientModule(); } - - protected String provider = "ec2"; - - /** - * this is only here as "ec2" is not in rest.properties - */ - @SuppressWarnings({ "unchecked", "rawtypes" }) + + @SuppressWarnings("rawtypes") @Override - public RestContextSpec createContextSpec() { - return RestContextFactory. contextSpec(provider, "https://ec2.us-east-1.amazonaws.com", - EC2AsyncClient.VERSION, "", "", "identity", "credential", EC2Client.class, EC2AsyncClient.class, - (Class) EC2PropertiesBuilder.class, (Class) EC2ContextBuilder.class, ImmutableSet. of()); + protected ApiMetadata createApiMetadata() { + return new EC2ApiMetadata(); } } diff --git a/apis/ec2/src/test/java/org/jclouds/ec2/services/ElasticBlockStoreClientLiveTest.java b/apis/ec2/src/test/java/org/jclouds/ec2/services/ElasticBlockStoreClientLiveTest.java index a1f50b76ae..6871c9cc7c 100644 --- a/apis/ec2/src/test/java/org/jclouds/ec2/services/ElasticBlockStoreClientLiveTest.java +++ b/apis/ec2/src/test/java/org/jclouds/ec2/services/ElasticBlockStoreClientLiveTest.java @@ -22,33 +22,27 @@ import static org.jclouds.ec2.options.DescribeSnapshotsOptions.Builder.snapshotI import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNotNull; -import java.util.Properties; import java.util.Set; import java.util.SortedSet; import java.util.concurrent.TimeUnit; import org.jclouds.aws.domain.Region; -import org.jclouds.compute.BaseVersionedServiceLiveTest; -import org.jclouds.compute.ComputeServiceContextFactory; +import org.jclouds.compute.internal.BaseComputeServiceContextLiveTest; import org.jclouds.ec2.EC2AsyncClient; import org.jclouds.ec2.EC2Client; +import org.jclouds.ec2.compute.EC2ComputeServiceContext; import org.jclouds.ec2.domain.Snapshot; import org.jclouds.ec2.domain.Volume; import org.jclouds.ec2.predicates.SnapshotCompleted; import org.jclouds.ec2.predicates.VolumeAvailable; -import org.jclouds.logging.log4j.config.Log4JLoggingModule; import org.jclouds.predicates.RetryablePredicate; -import org.jclouds.rest.RestContext; -import org.testng.annotations.AfterTest; -import org.testng.annotations.BeforeGroups; +import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import com.google.common.base.Predicate; -import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; import com.google.common.collect.Lists; import com.google.common.collect.Sets; -import com.google.inject.Module; /** * Tests behavior of {@code ElasticBlockStoreClient} @@ -56,28 +50,25 @@ import com.google.inject.Module; * @author Adrian Cole */ @Test(groups = "live", singleThreaded = true, testName = "ElasticBlockStoreClientLiveTest") -public class ElasticBlockStoreClientLiveTest extends BaseVersionedServiceLiveTest { +public class ElasticBlockStoreClientLiveTest> extends BaseComputeServiceContextLiveTest { public ElasticBlockStoreClientLiveTest() { provider = "ec2"; } private ElasticBlockStoreClient client; - private RestContext context; private String volumeId; private Snapshot snapshot; - @BeforeGroups(groups = { "live" }) - public void setupClient() { - setupCredentials(); - Properties overrides = setupProperties(); - context = new ComputeServiceContextFactory().createContext(provider, - ImmutableSet. of(new Log4JLoggingModule()), overrides).getProviderSpecificContext(); - client = context.getApi().getElasticBlockStoreServices(); + @Override + @BeforeClass(groups = { "integration", "live" }) + public void setupContext() { + super.setupContext(); + client = context.getProviderSpecificContext().getApi().getElasticBlockStoreServices(); } @Test void testDescribeVolumes() { - for (String region : context.getApi().getAvailabilityZoneAndRegionServices().describeRegions().keySet()) { + for (String region : context.getProviderSpecificContext().getApi().getAvailabilityZoneAndRegionServices().describeRegions().keySet()) { SortedSet allResults = Sets.newTreeSet(client.describeVolumesInRegion(region)); assertNotNull(allResults); if (allResults.size() >= 1) { @@ -227,8 +218,4 @@ public class ElasticBlockStoreClientLiveTest extends BaseVersionedServiceLiveTes assert client.describeSnapshotsInRegion(snapshot.getRegion(), snapshotIds(snapshot.getId())).size() == 0; } - @AfterTest - public void shutdown() { - context.close(); - } } diff --git a/apis/ec2/src/test/java/org/jclouds/ec2/services/ElasticIPAddressClientLiveTest.java b/apis/ec2/src/test/java/org/jclouds/ec2/services/ElasticIPAddressClientLiveTest.java index d35074b34e..a1de5fc423 100644 --- a/apis/ec2/src/test/java/org/jclouds/ec2/services/ElasticIPAddressClientLiveTest.java +++ b/apis/ec2/src/test/java/org/jclouds/ec2/services/ElasticIPAddressClientLiveTest.java @@ -21,25 +21,19 @@ package org.jclouds.ec2.services; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNotNull; -import java.util.Properties; import java.util.SortedSet; import org.jclouds.aws.domain.Region; -import org.jclouds.compute.BaseVersionedServiceLiveTest; -import org.jclouds.compute.ComputeServiceContextFactory; +import org.jclouds.compute.internal.BaseComputeServiceContextLiveTest; import org.jclouds.ec2.EC2AsyncClient; import org.jclouds.ec2.EC2Client; +import org.jclouds.ec2.compute.EC2ComputeServiceContext; import org.jclouds.ec2.domain.PublicIpInstanceIdPair; -import org.jclouds.logging.log4j.config.Log4JLoggingModule; -import org.jclouds.rest.RestContext; -import org.testng.annotations.AfterTest; -import org.testng.annotations.BeforeGroups; +import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; -import com.google.common.collect.ImmutableSet; import com.google.common.collect.Lists; import com.google.common.collect.Sets; -import com.google.inject.Module; /** * Tests behavior of {@code ElasticIPAddressClient} @@ -47,21 +41,18 @@ import com.google.inject.Module; * @author Adrian Cole */ @Test(groups = "live", singleThreaded = true, testName = "ElasticIPAddressClientLiveTest") -public class ElasticIPAddressClientLiveTest extends BaseVersionedServiceLiveTest { +public class ElasticIPAddressClientLiveTest> extends BaseComputeServiceContextLiveTest { public ElasticIPAddressClientLiveTest() { provider = "ec2"; } private ElasticIPAddressClient client; - private RestContext context; - @BeforeGroups(groups = { "live" }) - public void setupClient() { - setupCredentials(); - Properties overrides = setupProperties(); - context = new ComputeServiceContextFactory().createContext(provider, ImmutableSet. of(new Log4JLoggingModule()), - overrides).getProviderSpecificContext(); - client = context.getApi().getElasticIPAddressServices(); + @Override + @BeforeClass(groups = { "integration", "live" }) + public void setupContext() { + super.setupContext(); + client = context.getProviderSpecificContext().getApi().getElasticIPAddressServices(); } @Test @@ -81,8 +72,4 @@ public class ElasticIPAddressClientLiveTest extends BaseVersionedServiceLiveTest } } - @AfterTest - public void shutdown() { - context.close(); - } } diff --git a/apis/ec2/src/test/java/org/jclouds/ec2/services/InstanceClientLiveTest.java b/apis/ec2/src/test/java/org/jclouds/ec2/services/InstanceClientLiveTest.java index 9a4d9f065d..9915a9d98a 100644 --- a/apis/ec2/src/test/java/org/jclouds/ec2/services/InstanceClientLiveTest.java +++ b/apis/ec2/src/test/java/org/jclouds/ec2/services/InstanceClientLiveTest.java @@ -20,25 +20,19 @@ package org.jclouds.ec2.services; import static org.testng.Assert.assertNotNull; -import java.util.Properties; import java.util.Set; import org.jclouds.aws.domain.Region; -import org.jclouds.compute.BaseVersionedServiceLiveTest; -import org.jclouds.compute.ComputeServiceContextFactory; +import org.jclouds.compute.internal.BaseComputeServiceContextLiveTest; import org.jclouds.ec2.EC2AsyncClient; import org.jclouds.ec2.EC2Client; +import org.jclouds.ec2.compute.EC2ComputeServiceContext; import org.jclouds.ec2.domain.Reservation; import org.jclouds.ec2.domain.RunningInstance; -import org.jclouds.logging.log4j.config.Log4JLoggingModule; -import org.jclouds.rest.RestContext; -import org.testng.annotations.AfterTest; -import org.testng.annotations.BeforeGroups; +import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; -import com.google.common.collect.ImmutableSet; import com.google.common.collect.Lists; -import com.google.inject.Module; /** * Tests behavior of {@code EC2Client} @@ -46,23 +40,18 @@ import com.google.inject.Module; * @author Adrian Cole */ @Test(groups = "live", singleThreaded = true, testName = "InstanceClientLiveTest") -public class InstanceClientLiveTest extends BaseVersionedServiceLiveTest { +public class InstanceClientLiveTest> extends BaseComputeServiceContextLiveTest { public InstanceClientLiveTest() { provider = "ec2"; } private InstanceClient client; - private RestContext context; - - - @BeforeGroups(groups = { "live" }) - public void setupClient() { - setupCredentials(); - Properties overrides = setupProperties(); - context = new ComputeServiceContextFactory().createContext(provider, ImmutableSet. of(new Log4JLoggingModule()), - overrides).getProviderSpecificContext(); - client = context.getApi().getInstanceServices(); + @Override + @BeforeClass(groups = { "integration", "live" }) + public void setupContext() { + super.setupContext(); + client = context.getProviderSpecificContext().getApi().getInstanceServices(); } @Test @@ -74,9 +63,4 @@ public class InstanceClientLiveTest extends BaseVersionedServiceLiveTest { assert allResults.size() >= 0 : allResults.size(); } } - - @AfterTest - public void shutdown() { - context.close(); - } } diff --git a/apis/ec2/src/test/java/org/jclouds/ec2/services/KeyPairClientLiveTest.java b/apis/ec2/src/test/java/org/jclouds/ec2/services/KeyPairClientLiveTest.java index a0d3b86ac2..c4b6c5b359 100644 --- a/apis/ec2/src/test/java/org/jclouds/ec2/services/KeyPairClientLiveTest.java +++ b/apis/ec2/src/test/java/org/jclouds/ec2/services/KeyPairClientLiveTest.java @@ -21,26 +21,20 @@ package org.jclouds.ec2.services; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNotNull; -import java.util.Properties; import java.util.Set; import java.util.SortedSet; import org.jclouds.aws.domain.Region; -import org.jclouds.compute.BaseVersionedServiceLiveTest; -import org.jclouds.compute.ComputeServiceContextFactory; +import org.jclouds.compute.internal.BaseComputeServiceContextLiveTest; import org.jclouds.ec2.EC2AsyncClient; import org.jclouds.ec2.EC2Client; +import org.jclouds.ec2.compute.EC2ComputeServiceContext; import org.jclouds.ec2.domain.KeyPair; -import org.jclouds.logging.log4j.config.Log4JLoggingModule; -import org.jclouds.rest.RestContext; -import org.testng.annotations.AfterTest; -import org.testng.annotations.BeforeGroups; +import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; -import com.google.common.collect.ImmutableSet; import com.google.common.collect.Lists; import com.google.common.collect.Sets; -import com.google.inject.Module; /** * Tests behavior of {@code KeyPairClient} @@ -48,22 +42,18 @@ import com.google.inject.Module; * @author Adrian Cole */ @Test(groups = "live", singleThreaded = true, testName = "KeyPairClientLiveTest") -public class KeyPairClientLiveTest extends BaseVersionedServiceLiveTest { +public class KeyPairClientLiveTest> extends BaseComputeServiceContextLiveTest { public KeyPairClientLiveTest() { provider = "ec2"; } private KeyPairClient client; - private RestContext context; - - - @BeforeGroups(groups = { "live" }) - public void setupClient() { - setupCredentials(); - Properties overrides = setupProperties(); - context = new ComputeServiceContextFactory().createContext(provider, - ImmutableSet. of(new Log4JLoggingModule()), overrides).getProviderSpecificContext(); - client = context.getApi().getKeyPairServices(); + + @Override + @BeforeClass(groups = { "integration", "live" }) + public void setupContext() { + super.setupContext(); + client = context.getProviderSpecificContext().getApi().getKeyPairServices(); } @Test @@ -109,8 +99,4 @@ public class KeyPairClientLiveTest extends BaseVersionedServiceLiveTest { assertEquals(listPair.getSha1OfPrivateKey(), result.getSha1OfPrivateKey()); } - @AfterTest - public void shutdown() { - context.close(); - } } diff --git a/apis/ec2/src/test/java/org/jclouds/ec2/services/SecurityGroupClientLiveTest.java b/apis/ec2/src/test/java/org/jclouds/ec2/services/SecurityGroupClientLiveTest.java index 5ff0d10bb3..3ab63ec70c 100644 --- a/apis/ec2/src/test/java/org/jclouds/ec2/services/SecurityGroupClientLiveTest.java +++ b/apis/ec2/src/test/java/org/jclouds/ec2/services/SecurityGroupClientLiveTest.java @@ -22,23 +22,20 @@ import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNotNull; import java.util.Iterator; -import java.util.Properties; import java.util.Set; import java.util.SortedSet; import org.jclouds.aws.domain.Region; -import org.jclouds.compute.BaseVersionedServiceLiveTest; -import org.jclouds.compute.ComputeServiceContextFactory; +import org.jclouds.compute.internal.BaseComputeServiceContextLiveTest; import org.jclouds.ec2.EC2AsyncClient; import org.jclouds.ec2.EC2Client; +import org.jclouds.ec2.compute.EC2ComputeServiceContext; import org.jclouds.ec2.domain.IpPermission; import org.jclouds.ec2.domain.IpProtocol; import org.jclouds.ec2.domain.SecurityGroup; import org.jclouds.ec2.domain.UserIdGroupPair; -import org.jclouds.logging.log4j.config.Log4JLoggingModule; -import org.jclouds.rest.RestContext; import org.testng.annotations.AfterTest; -import org.testng.annotations.BeforeGroups; +import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import com.google.common.base.Predicate; @@ -47,7 +44,6 @@ import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSortedSet; import com.google.common.collect.Iterables; import com.google.common.collect.Lists; -import com.google.inject.Module; /** * Tests behavior of {@code SecurityGroupClient} @@ -55,21 +51,18 @@ import com.google.inject.Module; * @author Adrian Cole */ @Test(groups = "live", singleThreaded = true, testName = "SecurityGroupClientLiveTest") -public class SecurityGroupClientLiveTest extends BaseVersionedServiceLiveTest { +public class SecurityGroupClientLiveTest> extends BaseComputeServiceContextLiveTest { public SecurityGroupClientLiveTest() { provider = "ec2"; } protected SecurityGroupClient client; - private RestContext context; - @BeforeGroups(groups = { "live" }) - public void setupClient() { - setupCredentials(); - Properties overrides = setupProperties(); - context = new ComputeServiceContextFactory().createContext(provider, - ImmutableSet. of(new Log4JLoggingModule()), overrides).getProviderSpecificContext(); - client = context.getApi().getSecurityGroupServices(); + @Override + @BeforeClass(groups = { "integration", "live" }) + public void setupContext() { + super.setupContext(); + client = context.getProviderSpecificContext().getApi().getSecurityGroupServices(); } @Test diff --git a/apis/ec2/src/test/java/org/jclouds/ec2/services/WindowsClientLiveTest.java b/apis/ec2/src/test/java/org/jclouds/ec2/services/WindowsClientLiveTest.java index 4c47ba7178..7fdee8dc5d 100644 --- a/apis/ec2/src/test/java/org/jclouds/ec2/services/WindowsClientLiveTest.java +++ b/apis/ec2/src/test/java/org/jclouds/ec2/services/WindowsClientLiveTest.java @@ -28,36 +28,28 @@ import java.util.concurrent.TimeUnit; import javax.annotation.Nullable; -import org.jclouds.compute.BaseVersionedServiceLiveTest; import org.jclouds.compute.ComputeService; -import org.jclouds.compute.ComputeServiceContext; -import org.jclouds.compute.ComputeServiceContextFactory; import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.domain.OsFamily; import org.jclouds.compute.domain.Template; +import org.jclouds.compute.internal.BaseComputeServiceContextLiveTest; import org.jclouds.compute.options.TemplateOptions; import org.jclouds.domain.LoginCredentials; import org.jclouds.ec2.EC2AsyncClient; import org.jclouds.ec2.EC2Client; -import org.jclouds.ec2.EC2ContextBuilder; -import org.jclouds.ec2.EC2PropertiesBuilder; +import org.jclouds.ec2.compute.EC2ComputeServiceContext; import org.jclouds.ec2.compute.domain.PasswordDataAndPrivateKey; import org.jclouds.ec2.compute.functions.WindowsLoginCredentialsFromEncryptedData; import org.jclouds.ec2.domain.InstanceType; import org.jclouds.ec2.domain.PasswordData; import org.jclouds.ec2.reference.EC2Constants; -import org.jclouds.encryption.bouncycastle.config.BouncyCastleCryptoModule; -import org.jclouds.logging.log4j.config.Log4JLoggingModule; import org.jclouds.predicates.RetryablePredicate; -import org.jclouds.rest.RestContext; -import org.testng.annotations.BeforeGroups; +import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import com.google.common.base.Predicate; import com.google.common.base.Strings; -import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; -import com.google.inject.Module; /** * Tests behavior of {@code WindowsClient} @@ -65,7 +57,7 @@ import com.google.inject.Module; * @author Adrian Cole */ @Test(groups = "live", singleThreaded = true, testName = "WindowsClientLiveTest") -public class WindowsClientLiveTest extends BaseVersionedServiceLiveTest { +public class WindowsClientLiveTest> extends BaseComputeServiceContextLiveTest { public WindowsClientLiveTest() { provider = "ec2"; } @@ -74,29 +66,23 @@ public class WindowsClientLiveTest extends BaseVersionedServiceLiveTest { private WindowsClient client; private static final String DEFAULT_INSTANCE = "i-TODO"; private static final String DEFAULT_BUCKET = "TODO"; - - private RestContext context; + + @Override + protected Properties setupProperties() { + Properties overrides = super.setupProperties(); + overrides.put(EC2Constants.PROPERTY_EC2_AMI_OWNERS, "206029621532"); /* Amazon Owner ID */ + return overrides; + } @Override - public Properties setupRestProperties() { - Properties rest = super.setupRestProperties(); - rest.put("ec2.contextbuilder", EC2ContextBuilder.class.getName()); - rest.put("ec2.propertiesbuilder", EC2PropertiesBuilder.class.getName()); - return rest; - } - - @BeforeGroups(groups = { "live" }) - public void setupClient() { - setupCredentials(); - Properties overrides = setupProperties(); - overrides.put(EC2Constants.PROPERTY_EC2_AMI_OWNERS, "206029621532"); /* Amazon Owner ID */ - ComputeServiceContext serviceContext = new ComputeServiceContextFactory(setupRestProperties()).createContext(provider, - ImmutableSet.of(new Log4JLoggingModule(), new BouncyCastleCryptoModule()), overrides); - computeService = serviceContext.getComputeService(); - context = serviceContext.getProviderSpecificContext(); - client = context.getApi().getWindowsServices(); + @BeforeClass(groups = { "integration", "live" }) + public void setupContext() { + super.setupContext(); + client = context.getProviderSpecificContext().getApi().getWindowsServices(); + computeService = context.getComputeService(); } + @Test(enabled = false) // TODO get instance public void testBundleInstanceInRegion() { @@ -135,7 +121,6 @@ public class WindowsClientLiveTest extends BaseVersionedServiceLiveTest { Set nodes = computeService.createNodesInGroup("test", 1, template); NodeMetadata node = Iterables.getOnlyElement(nodes); - boolean shutdown = true; try { // The Administrator password will take some time before it is ready - Amazon says sometimes 15 minutes. diff --git a/apis/elasticstack/src/main/java/org/jclouds/elasticstack/ElasticStackApiMetadata.java b/apis/elasticstack/src/main/java/org/jclouds/elasticstack/ElasticStackApiMetadata.java index bdc2d7fd0b..dd847fd26b 100644 --- a/apis/elasticstack/src/main/java/org/jclouds/elasticstack/ElasticStackApiMetadata.java +++ b/apis/elasticstack/src/main/java/org/jclouds/elasticstack/ElasticStackApiMetadata.java @@ -18,51 +18,77 @@ */ package org.jclouds.elasticstack; +import static org.jclouds.elasticstack.reference.ElasticStackConstants.PROPERTY_VNC_PASSWORD; + import java.net.URI; +import java.util.Properties; import org.jclouds.apis.ApiMetadata; -import org.jclouds.apis.ApiType; -import org.jclouds.apis.BaseApiMetadata; +import org.jclouds.compute.ComputeServiceContext; +import org.jclouds.compute.internal.BaseComputeServiceApiMetadata; + +import com.google.common.reflect.TypeToken; /** * Implementation of {@link ApiMetadata} for the ElasticStack API * * @author Adrian Cole */ -public class ElasticStackApiMetadata extends BaseApiMetadata { +public class ElasticStackApiMetadata + extends + BaseComputeServiceApiMetadata, ElasticStackApiMetadata> { - public ElasticStackApiMetadata() { - this(builder() - .id("elasticstack") - .type(ApiType.COMPUTE) - .name("ElasticStack API") - .identityName("UUID") - .credentialName("Secret API key") - .documentation(URI.create("http://www.elasticstack.com/cloud-platform/api"))); + @Override + public Builder toBuilder() { + return new Builder().fromApiMetadata(this); } - // below are so that we can reuse builders, toString, hashCode, etc. - // we have to set concrete classes here, as our base class cannot be - // concrete due to serviceLoader - protected ElasticStackApiMetadata(ConcreteBuilder builder) { + public ElasticStackApiMetadata() { + this(new Builder()); + } + + protected ElasticStackApiMetadata(Builder builder) { super(builder); } - private static class ConcreteBuilder extends Builder { + protected static Properties defaultProperties() { + Properties properties = BaseComputeServiceApiMetadata.Builder.defaultProperties(); + properties.setProperty(PROPERTY_VNC_PASSWORD, "IL9vs34d"); + // passwords are set post-boot, so auth failures are possible + // from a race condition applying the password set script + properties.setProperty("jclouds.ssh.max-retries", "5"); + properties.setProperty("jclouds.ssh.retry-auth", "true"); + return properties; + } + + public static class Builder + extends + BaseComputeServiceApiMetadata.Builder, ElasticStackApiMetadata> { + + protected Builder() { + id("elasticstack") + .name("ElasticStack API") + .identityName("UUID") + .credentialName("Secret API key") + .documentation(URI.create("http://www.elasticstack.com/cloud-platform/api")) + .version("1.0") + .defaultEndpoint("https://api.lon-p.elastichosts.com") + .defaultProperties(ElasticStackApiMetadata.defaultProperties()) + .javaApi(ElasticStackClient.class, ElasticStackAsyncClient.class) + .contextBuilder(TypeToken.of(ElasticStackContextBuilder.class)); + } @Override public ElasticStackApiMetadata build() { return new ElasticStackApiMetadata(this); } + + @Override + public Builder fromApiMetadata(ElasticStackApiMetadata in) { + super.fromApiMetadata(in); + return this; + } + } - public static ConcreteBuilder builder() { - return new ConcreteBuilder(); - } - - @Override - public ConcreteBuilder toBuilder() { - return builder().fromApiMetadata(this); - } - -} \ No newline at end of file +} diff --git a/apis/elasticstack/src/main/java/org/jclouds/elasticstack/ElasticStackContextBuilder.java b/apis/elasticstack/src/main/java/org/jclouds/elasticstack/ElasticStackContextBuilder.java index a8d1ad1b29..63b5f65cb5 100644 --- a/apis/elasticstack/src/main/java/org/jclouds/elasticstack/ElasticStackContextBuilder.java +++ b/apis/elasticstack/src/main/java/org/jclouds/elasticstack/ElasticStackContextBuilder.java @@ -19,11 +19,12 @@ package org.jclouds.elasticstack; import java.util.List; -import java.util.Properties; +import org.jclouds.compute.ComputeServiceContext; import org.jclouds.compute.ComputeServiceContextBuilder; import org.jclouds.elasticstack.compute.config.ElasticStackComputeServiceContextModule; import org.jclouds.elasticstack.config.ElasticStackRestClientModule; +import org.jclouds.providers.ProviderMetadata; import com.google.inject.Module; @@ -31,12 +32,19 @@ import com.google.inject.Module; * * @author Adrian Cole */ -public class ElasticStackContextBuilder extends - ComputeServiceContextBuilder { +public class ElasticStackContextBuilder + extends + ComputeServiceContextBuilder, ElasticStackApiMetadata> { - public ElasticStackContextBuilder(Properties props) { - super(ElasticStackClient.class, ElasticStackAsyncClient.class, props); + public ElasticStackContextBuilder( + ProviderMetadata, ElasticStackApiMetadata> providerMetadata) { + super(providerMetadata); } + + public ElasticStackContextBuilder(ElasticStackApiMetadata apiMetadata) { + super(apiMetadata); + } + @Override protected void addContextModule(List modules) { modules.add(new ElasticStackComputeServiceContextModule()); diff --git a/apis/elasticstack/src/main/java/org/jclouds/elasticstack/ElasticStackPropertiesBuilder.java b/apis/elasticstack/src/main/java/org/jclouds/elasticstack/ElasticStackPropertiesBuilder.java deleted file mode 100644 index 20395769c4..0000000000 --- a/apis/elasticstack/src/main/java/org/jclouds/elasticstack/ElasticStackPropertiesBuilder.java +++ /dev/null @@ -1,50 +0,0 @@ -/** - * 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.elasticstack; - -import static org.jclouds.Constants.PROPERTY_API_VERSION; -import static org.jclouds.elasticstack.reference.ElasticStackConstants.PROPERTY_VNC_PASSWORD; - -import java.util.Properties; - -import org.jclouds.PropertiesBuilder; - -/** - * Builds properties used in elasticstack Clients - * - * @author Adrian Cole - */ -public class ElasticStackPropertiesBuilder extends PropertiesBuilder { - @Override - protected Properties defaultProperties() { - Properties properties = super.defaultProperties(); - properties.setProperty(PROPERTY_API_VERSION, "1.0"); - properties.setProperty(PROPERTY_VNC_PASSWORD, "IL9vs34d"); - // passwords are set post-boot, so auth failures are possible - // from a race condition applying the password set script - properties.setProperty("jclouds.ssh.max-retries", "5"); - properties.setProperty("jclouds.ssh.retry-auth", "true"); - return properties; - } - - public ElasticStackPropertiesBuilder(Properties properties) { - super(properties); - } - -} diff --git a/apis/elasticstack/src/test/java/org/jclouds/elasticstack/ElasticStackApiMetadataTest.java b/apis/elasticstack/src/test/java/org/jclouds/elasticstack/ElasticStackApiMetadataTest.java index 8d80a68503..b93636dc87 100644 --- a/apis/elasticstack/src/test/java/org/jclouds/elasticstack/ElasticStackApiMetadataTest.java +++ b/apis/elasticstack/src/test/java/org/jclouds/elasticstack/ElasticStackApiMetadataTest.java @@ -18,8 +18,7 @@ */ package org.jclouds.elasticstack; -import org.jclouds.apis.ApiType; -import org.jclouds.apis.BaseApiMetadataTest; +import org.jclouds.compute.internal.BaseComputeServiceApiMetadataTest; import org.testng.annotations.Test; /** @@ -27,9 +26,9 @@ import org.testng.annotations.Test; * @author Adrian Cole */ @Test(groups = "unit", testName = "ElasticStackApiMetadataTest") -public class ElasticStackApiMetadataTest extends BaseApiMetadataTest { +public class ElasticStackApiMetadataTest extends BaseComputeServiceApiMetadataTest { public ElasticStackApiMetadataTest() { - super(new ElasticStackApiMetadata(), ApiType.COMPUTE); + super(new ElasticStackApiMetadata()); } } diff --git a/apis/elasticstack/src/test/java/org/jclouds/elasticstack/ElasticStackAsyncClientTest.java b/apis/elasticstack/src/test/java/org/jclouds/elasticstack/ElasticStackAsyncClientTest.java index eaab145d91..37dccdfe18 100644 --- a/apis/elasticstack/src/test/java/org/jclouds/elasticstack/ElasticStackAsyncClientTest.java +++ b/apis/elasticstack/src/test/java/org/jclouds/elasticstack/ElasticStackAsyncClientTest.java @@ -22,10 +22,10 @@ import static org.testng.Assert.assertEquals; import java.io.IOException; import java.lang.reflect.Method; -import java.util.Properties; import javax.ws.rs.core.MediaType; +import org.jclouds.apis.ApiMetadata; import org.jclouds.elasticstack.binders.BindServerToPlainTextStringTest; import org.jclouds.elasticstack.domain.CreateDriveRequest; import org.jclouds.elasticstack.domain.Drive; @@ -43,12 +43,10 @@ import org.jclouds.http.filters.BasicAuthentication; import org.jclouds.http.functions.ReleasePayloadAndReturn; import org.jclouds.io.Payload; import org.jclouds.io.Payloads; -import org.jclouds.rest.RestClientTest; -import org.jclouds.rest.RestContextFactory; -import org.jclouds.rest.RestContextSpec; import org.jclouds.rest.functions.MapHttp4xxCodesToExceptions; import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404; +import org.jclouds.rest.internal.BaseAsyncClientTest; import org.jclouds.rest.internal.RestAnnotationProcessor; import org.testng.annotations.Test; @@ -63,12 +61,12 @@ import com.google.inject.TypeLiteral; */ // NOTE:without testName, this will not call @Before* and fail w/NPE during surefire @Test(groups = "unit", testName = "ElasticStackAsyncClientTest") -public class ElasticStackAsyncClientTest extends RestClientTest { +public class ElasticStackAsyncClientTest extends BaseAsyncClientTest { public void testListServers() throws SecurityException, NoSuchMethodException, IOException { Method method = ElasticStackAsyncClient.class.getMethod("listServers"); HttpRequest httpRequest = processor.createRequest(method); - assertRequestLineEquals(httpRequest, "GET https://api.elasticstack.com/servers/list HTTP/1.1"); + assertRequestLineEquals(httpRequest, "GET https://api.lon-p.elastichosts.com/servers/list HTTP/1.1"); assertNonPayloadHeadersEqual(httpRequest, "Accept: text/plain\n"); assertPayloadEquals(httpRequest, null, null, false); @@ -76,10 +74,10 @@ public class ElasticStackAsyncClientTest extends RestClientTest createContextSpec() { - Properties props = new Properties(); - props.setProperty("elasticstack.endpoint", "https://api.elasticstack.com"); - return new RestContextFactory().createContextSpec("elasticstack", "foo", "bar", props); + protected ApiMetadata createApiMetadata() { + return new ElasticStackApiMetadata(); } + } diff --git a/apis/elasticstack/src/test/java/org/jclouds/elasticstack/ElasticStackClientLiveTest.java b/apis/elasticstack/src/test/java/org/jclouds/elasticstack/ElasticStackClientLiveTest.java index 43f35aee26..3a199e02b5 100644 --- a/apis/elasticstack/src/test/java/org/jclouds/elasticstack/ElasticStackClientLiveTest.java +++ b/apis/elasticstack/src/test/java/org/jclouds/elasticstack/ElasticStackClientLiveTest.java @@ -22,15 +22,13 @@ import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNotNull; import java.io.IOException; -import java.util.Properties; import java.util.Set; import java.util.concurrent.TimeUnit; import java.util.logging.Logger; -import org.jclouds.compute.BaseVersionedServiceLiveTest; import org.jclouds.compute.ComputeServiceContext; -import org.jclouds.compute.ComputeServiceContextFactory; import org.jclouds.compute.domain.ExecResponse; +import org.jclouds.compute.internal.BaseComputeServiceContextLiveTest; import org.jclouds.domain.LoginCredentials; import org.jclouds.elasticstack.domain.ClaimType; import org.jclouds.elasticstack.domain.CreateDriveRequest; @@ -46,7 +44,6 @@ import org.jclouds.elasticstack.domain.ServerStatus; import org.jclouds.elasticstack.predicates.DriveClaimed; import org.jclouds.elasticstack.util.Servers; import org.jclouds.io.Payloads; -import org.jclouds.logging.log4j.config.Log4JLoggingModule; import org.jclouds.net.IPSocket; import org.jclouds.predicates.InetSocketAddressConnect; import org.jclouds.predicates.RetryablePredicate; @@ -65,7 +62,6 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import com.google.gson.Gson; import com.google.inject.Guice; -import com.google.inject.Module; /** * Tests behavior of {@code ElasticStackClient} @@ -73,7 +69,10 @@ import com.google.inject.Module; * @author Adrian Cole */ @Test(groups = "live", singleThreaded = true, testName = "ElasticStackClientLiveTest") -public class ElasticStackClientLiveTest extends BaseVersionedServiceLiveTest { +public class ElasticStackClientLiveTest + extends + BaseComputeServiceContextLiveTest> { + public ElasticStackClientLiveTest() { provider = "elasticstack"; } @@ -82,28 +81,24 @@ public class ElasticStackClientLiveTest extends BaseVersionedServiceLiveTest { protected int maxDriveImageTime = 360; protected String vncPassword = "Il0veVNC"; protected ElasticStackClient client; - protected ComputeServiceContext computeContext; - protected RestContext context; + protected RestContext cloudStackContext; protected Predicate socketTester; protected Predicate driveNotClaimed; - - @BeforeGroups(groups = "live") - public void setupClient() { - setupCredentials(); - Properties overrides = setupProperties(); - computeContext = new ComputeServiceContextFactory().createContext(provider, - ImmutableSet. of(new Log4JLoggingModule()), overrides); - context = computeContext.getProviderSpecificContext(); + @BeforeGroups(groups = { "integration", "live" }) + @Override + public void setupContext() { + super.setupContext(); + cloudStackContext = context.getProviderSpecificContext(); - client = context.getApi(); + client = cloudStackContext.getApi(); driveNotClaimed = new RetryablePredicate(Predicates.not(new DriveClaimed(client)), maxDriveImageTime, 1, TimeUnit.SECONDS); socketTester = new RetryablePredicate(new InetSocketAddressConnect(), maxDriveImageTime, 1, TimeUnit.SECONDS); if (Strings.emptyToNull(imageId) == null) { - imageId = computeContext.getComputeService().templateBuilder().build().getImage().getId(); + imageId = context.getComputeService().templateBuilder().build().getImage().getId(); } } @@ -322,8 +317,8 @@ public class ElasticStackClientLiveTest extends BaseVersionedServiceLiveTest { } catch (Exception e) { } - if (context != null) - context.close(); + if (cloudStackContext != null) + cloudStackContext.close(); } private DriveInfo drive2; diff --git a/apis/elasticstack/src/test/java/org/jclouds/elasticstack/compute/ElasticStackComputeServiceLiveTest.java b/apis/elasticstack/src/test/java/org/jclouds/elasticstack/compute/ElasticStackComputeServiceLiveTest.java index c87539fc57..6f4e93ebae 100644 --- a/apis/elasticstack/src/test/java/org/jclouds/elasticstack/compute/ElasticStackComputeServiceLiveTest.java +++ b/apis/elasticstack/src/test/java/org/jclouds/elasticstack/compute/ElasticStackComputeServiceLiveTest.java @@ -18,9 +18,12 @@ */ package org.jclouds.elasticstack.compute; -import org.jclouds.compute.BaseComputeServiceLiveTest; +import org.jclouds.compute.ComputeServiceContext; import org.jclouds.compute.domain.ExecResponse; import org.jclouds.compute.domain.NodeMetadata; +import org.jclouds.compute.internal.BaseComputeServiceLiveTest; +import org.jclouds.elasticstack.ElasticStackAsyncClient; +import org.jclouds.elasticstack.ElasticStackClient; import org.jclouds.sshj.config.SshjSshClientModule; import org.testng.annotations.Test; @@ -31,7 +34,10 @@ import com.google.inject.Module; * @author Adrian Cole */ @Test(groups = "live") -public class ElasticStackComputeServiceLiveTest extends BaseComputeServiceLiveTest { +public class ElasticStackComputeServiceLiveTest + extends + BaseComputeServiceLiveTest> { + public ElasticStackComputeServiceLiveTest() { provider = "elasticstack"; } diff --git a/apis/eucalyptus/src/main/java/org/jclouds/eucalyptus/EucalyptusApiMetadata.java b/apis/eucalyptus/src/main/java/org/jclouds/eucalyptus/EucalyptusApiMetadata.java index c8e8877108..0297ea0b50 100644 --- a/apis/eucalyptus/src/main/java/org/jclouds/eucalyptus/EucalyptusApiMetadata.java +++ b/apis/eucalyptus/src/main/java/org/jclouds/eucalyptus/EucalyptusApiMetadata.java @@ -18,43 +18,68 @@ */ package org.jclouds.eucalyptus; +import static org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_PORT_OPEN; +import static org.jclouds.ec2.reference.EC2Constants.PROPERTY_EC2_AMI_OWNERS; +import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGIONS; + +import java.util.Properties; + import org.jclouds.apis.ApiMetadata; import org.jclouds.ec2.EC2ApiMetadata; +import org.jclouds.ec2.EC2AsyncClient; +import org.jclouds.ec2.EC2Client; +import org.jclouds.ec2.compute.EC2ComputeServiceContext; /** * Implementation of {@link ApiMetadata} for the Eucalyptus (EC2 clone) api. * * @author Adrian Cole */ -public class EucalyptusApiMetadata extends EC2ApiMetadata { +public class EucalyptusApiMetadata extends EC2ApiMetadata, EucalyptusApiMetadata> { + private static Builder builder() { + return new Builder(); + } + + @Override + public Builder toBuilder() { + return builder().fromApiMetadata(this); + } public EucalyptusApiMetadata() { - this(builder().fromApiMetadata(new EC2ApiMetadata()) - .id("eucalyptus") - .name("Eucalyptus (EC2 clone) API")); + this(builder()); } - // below are so that we can reuse builders, toString, hashCode, etc. - // we have to set concrete classes here, as our base class cannot be - // concrete due to serviceLoader - protected EucalyptusApiMetadata(ConcreteBuilder builder) { + protected EucalyptusApiMetadata(Builder builder) { super(builder); } + + protected static Properties defaultProperties() { + Properties properties = EC2ApiMetadata.defaultProperties(); + properties.setProperty(PROPERTY_REGIONS, "Eucalyptus"); + properties.setProperty(PROPERTY_EC2_AMI_OWNERS, "admin"); + properties.setProperty(TIMEOUT_PORT_OPEN, 5 * 60 * 1000 + ""); + return properties; + } - private static class ConcreteBuilder extends EC2ApiMetadataBuilder { - + public static class Builder extends EC2ApiMetadata.Builder, EucalyptusApiMetadata> { + protected Builder(){ + super(EC2Client.class, EC2AsyncClient.class); + id("eucalyptus") + .defaultEndpoint("http://173.205.188.130:8773/services/Eucalyptus") + .name("Eucalyptus (EC2 clone) API") + .defaultProperties(EucalyptusApiMetadata.defaultProperties()); + } + @Override public EucalyptusApiMetadata build() { return new EucalyptusApiMetadata(this); } + + @Override + public Builder fromApiMetadata(EucalyptusApiMetadata in) { + super.fromApiMetadata(in); + return this; + } } - private static ConcreteBuilder builder() { - return new ConcreteBuilder(); - } - - @Override - public ConcreteBuilder toBuilder() { - return builder().fromApiMetadata(this); - } } \ No newline at end of file diff --git a/apis/eucalyptus/src/main/java/org/jclouds/eucalyptus/EucalyptusPropertiesBuilder.java b/apis/eucalyptus/src/main/java/org/jclouds/eucalyptus/EucalyptusPropertiesBuilder.java deleted file mode 100644 index c995b4d940..0000000000 --- a/apis/eucalyptus/src/main/java/org/jclouds/eucalyptus/EucalyptusPropertiesBuilder.java +++ /dev/null @@ -1,50 +0,0 @@ -/** - * 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.eucalyptus; - -import static org.jclouds.Constants.PROPERTY_ENDPOINT; -import static org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_PORT_OPEN; -import static org.jclouds.ec2.reference.EC2Constants.PROPERTY_EC2_AMI_OWNERS; -import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGIONS; - -import java.util.Properties; - -import org.jclouds.ec2.EC2PropertiesBuilder; - -/** - * Builds properties used in Eucalyptus Clients - * - * @author Adrian Cole - */ -public class EucalyptusPropertiesBuilder extends EC2PropertiesBuilder { - @Override - protected Properties defaultProperties() { - Properties properties = super.defaultProperties(); - properties.setProperty(PROPERTY_ENDPOINT, "http://173.205.188.130:8773/services/Eucalyptus"); - properties.setProperty(PROPERTY_REGIONS, "Eucalyptus"); - properties.setProperty(PROPERTY_EC2_AMI_OWNERS, "admin"); - properties.setProperty(TIMEOUT_PORT_OPEN, 5 * 60 * 1000 + ""); - return properties; - } - - public EucalyptusPropertiesBuilder(Properties properties) { - super(properties); - } - -} diff --git a/apis/eucalyptus/src/test/java/org/jclouds/eucalyptus/EucalyptusApiMetadataTest.java b/apis/eucalyptus/src/test/java/org/jclouds/eucalyptus/EucalyptusApiMetadataTest.java index 7473d8a3e6..e2fcff6d83 100644 --- a/apis/eucalyptus/src/test/java/org/jclouds/eucalyptus/EucalyptusApiMetadataTest.java +++ b/apis/eucalyptus/src/test/java/org/jclouds/eucalyptus/EucalyptusApiMetadataTest.java @@ -18,8 +18,7 @@ */ package org.jclouds.eucalyptus; -import org.jclouds.apis.ApiType; -import org.jclouds.apis.BaseApiMetadataTest; +import org.jclouds.compute.internal.BaseComputeServiceApiMetadataTest; import org.testng.annotations.Test; /** @@ -27,9 +26,9 @@ import org.testng.annotations.Test; * @author Adrian Cole */ @Test(groups = "unit", testName = "EucalyptusApiMetadataTest") -public class EucalyptusApiMetadataTest extends BaseApiMetadataTest { +public class EucalyptusApiMetadataTest extends BaseComputeServiceApiMetadataTest { public EucalyptusApiMetadataTest() { - super(new EucalyptusApiMetadata(), ApiType.COMPUTE); + super(new EucalyptusApiMetadata()); } } diff --git a/apis/eucalyptus/src/test/java/org/jclouds/eucalyptus/compute/EucalyptusComputeServiceLiveTest.java b/apis/eucalyptus/src/test/java/org/jclouds/eucalyptus/compute/EucalyptusComputeServiceLiveTest.java index 49f4f34b19..13c5945786 100644 --- a/apis/eucalyptus/src/test/java/org/jclouds/eucalyptus/compute/EucalyptusComputeServiceLiveTest.java +++ b/apis/eucalyptus/src/test/java/org/jclouds/eucalyptus/compute/EucalyptusComputeServiceLiveTest.java @@ -20,6 +20,9 @@ package org.jclouds.eucalyptus.compute; import org.jclouds.compute.domain.ExecResponse; import org.jclouds.compute.domain.NodeMetadata; +import org.jclouds.ec2.EC2AsyncClient; +import org.jclouds.ec2.EC2Client; +import org.jclouds.ec2.compute.EC2ComputeServiceContext; import org.jclouds.ec2.compute.EC2ComputeServiceLiveTest; import org.jclouds.http.HttpResponseException; import org.testng.annotations.Test; @@ -29,7 +32,8 @@ import org.testng.annotations.Test; * @author Adrian Cole */ @Test(groups = "live", singleThreaded = true, testName = "EucalyptusComputeServiceLiveTest") -public class EucalyptusComputeServiceLiveTest extends EC2ComputeServiceLiveTest { +public class EucalyptusComputeServiceLiveTest extends + EC2ComputeServiceLiveTest> { public EucalyptusComputeServiceLiveTest() { provider = "eucalyptus"; diff --git a/apis/filesystem/pom.xml b/apis/filesystem/pom.xml index 84628b2cf9..ff342df44d 100644 --- a/apis/filesystem/pom.xml +++ b/apis/filesystem/pom.xml @@ -67,10 +67,6 @@ - - org.jclouds.filesystem.integration.FilesystemTestInitializer - - @@ -84,6 +80,7 @@ test + 1 **/*LiveTest.java **/Base*Test.java @@ -92,7 +89,6 @@ **/*IntegrationTest.java - ${test.initializer} ${jclouds.blobstore.httpstream.url} ${jclouds.blobstore.httpstream.md5} diff --git a/apis/filesystem/src/main/java/org/jclouds/filesystem/FilesystemApiMetadata.java b/apis/filesystem/src/main/java/org/jclouds/filesystem/FilesystemApiMetadata.java index 99d51e6402..91595c3389 100644 --- a/apis/filesystem/src/main/java/org/jclouds/filesystem/FilesystemApiMetadata.java +++ b/apis/filesystem/src/main/java/org/jclouds/filesystem/FilesystemApiMetadata.java @@ -18,50 +18,70 @@ */ package org.jclouds.filesystem; +import static org.jclouds.Constants.PROPERTY_IO_WORKER_THREADS; +import static org.jclouds.Constants.PROPERTY_USER_THREADS; + import java.net.URI; import org.jclouds.apis.ApiMetadata; -import org.jclouds.apis.ApiType; -import org.jclouds.apis.BaseApiMetadata; +import org.jclouds.blobstore.BlobStore; +import org.jclouds.blobstore.BlobStoreContext; +import org.jclouds.blobstore.internal.BaseBlobStoreApiMetadata; + +import com.google.common.collect.ImmutableMap; +import com.google.common.reflect.TypeToken; /** * Implementation of {@link ApiMetadata} for jclouds Filesystem-based BlobStore * * @author Adrian Cole */ -public class FilesystemApiMetadata extends BaseApiMetadata { +public class FilesystemApiMetadata + extends + BaseBlobStoreApiMetadata, FilesystemApiMetadata> { - public FilesystemApiMetadata() { - this(builder() - .id("filesystem") - .type(ApiType.BLOBSTORE) - .name("Filesystem-based BlobStore") - .identityName("Unused") - .documentation(URI.create("http://www.jclouds.org/documentation/userguide/blobstore-guide"))); + public static Builder builder() { + return new Builder(); } - // below are so that we can reuse builders, toString, hashCode, etc. - // we have to set concrete classes here, as our base class cannot be - // concrete due to serviceLoader - protected FilesystemApiMetadata(ConcreteBuilder builder) { + @Override + public Builder toBuilder() { + return Builder.class.cast(builder().fromApiMetadata(this)); + } + + public FilesystemApiMetadata() { + super(builder()); + } + + protected FilesystemApiMetadata(Builder builder) { super(builder); } - private static class ConcreteBuilder extends Builder { +public static class Builder extends + BaseBlobStoreApiMetadata.Builder, FilesystemApiMetadata> { + + protected Builder() { + id("filesystem") + .name("Filesystem-based BlobStore") + .identityName("Unused") + .contextBuilder(TypeToken.of(FilesystemBlobStoreContextBuilder.class)) + .javaApi(BlobStore.class, FilesystemAsyncBlobStore.class) + .identityName("Unused") + .defaultEndpoint("http://localhost/transient") + .defaultIdentity(System.getProperty("user.name")) + .defaultCredential("bar") + .version("1") + .defaultProperties( + BaseBlobStoreApiMetadata.Builder.defaultPropertiesAnd(ImmutableMap.of(PROPERTY_USER_THREADS, "0", + PROPERTY_IO_WORKER_THREADS, "0"))) + .documentation(URI.create("http://www.jclouds.org/documentation/userguide/blobstore-guide")); + } @Override public FilesystemApiMetadata build() { return new FilesystemApiMetadata(this); } - } - public static ConcreteBuilder builder() { - return new ConcreteBuilder(); - } - - @Override - public ConcreteBuilder toBuilder() { - return builder().fromApiMetadata(this); } } \ No newline at end of file diff --git a/apis/filesystem/src/main/java/org/jclouds/filesystem/FilesystemAsyncBlobStore.java b/apis/filesystem/src/main/java/org/jclouds/filesystem/FilesystemAsyncBlobStore.java index e6c3ade4db..6b9013fb76 100644 --- a/apis/filesystem/src/main/java/org/jclouds/filesystem/FilesystemAsyncBlobStore.java +++ b/apis/filesystem/src/main/java/org/jclouds/filesystem/FilesystemAsyncBlobStore.java @@ -126,7 +126,7 @@ public class FilesystemAsyncBlobStore extends BaseAsyncBlobStore { protected final FilesystemStorageStrategy storageStrategy; @Inject - protected FilesystemAsyncBlobStore(BlobStoreContext context, DateService dateService, Crypto crypto, + protected FilesystemAsyncBlobStore(@SuppressWarnings("rawtypes") BlobStoreContext context, DateService dateService, Crypto crypto, HttpGetOptionsListToGetOptions httpGetOptionsConverter, IfDirectoryReturnNameStrategy ifDirectoryReturnName, BlobUtils blobUtils, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService service, Supplier defaultLocation, @Memoized Supplier> locations, diff --git a/apis/filesystem/src/main/java/org/jclouds/filesystem/FilesystemBlobStoreContextBuilder.java b/apis/filesystem/src/main/java/org/jclouds/filesystem/FilesystemBlobStoreContextBuilder.java index 08a44ca6b9..eb5cd39033 100644 --- a/apis/filesystem/src/main/java/org/jclouds/filesystem/FilesystemBlobStoreContextBuilder.java +++ b/apis/filesystem/src/main/java/org/jclouds/filesystem/FilesystemBlobStoreContextBuilder.java @@ -19,33 +19,31 @@ package org.jclouds.filesystem; import java.util.List; -import java.util.Properties; -import org.jclouds.blobstore.AsyncBlobStore; import org.jclouds.blobstore.BlobStore; +import org.jclouds.blobstore.BlobStoreContext; import org.jclouds.blobstore.BlobStoreContextBuilder; import org.jclouds.filesystem.config.FilesystemBlobStoreContextModule; import org.jclouds.filesystem.config.FilesystemBlobStoreModule; +import org.jclouds.providers.ProviderMetadata; import com.google.inject.Module; /** - * + * * @author Alfredo "Rainbowbreeze" Morresi */ -public class FilesystemBlobStoreContextBuilder extends - BlobStoreContextBuilder { +public class FilesystemBlobStoreContextBuilder + extends + BlobStoreContextBuilder, FilesystemApiMetadata> { - /** - * This is only to have the same syntax. - * - */ - public FilesystemBlobStoreContextBuilder() { - this(new Properties()); + public FilesystemBlobStoreContextBuilder( + ProviderMetadata, FilesystemApiMetadata> providerMetadata) { + super(providerMetadata); } - public FilesystemBlobStoreContextBuilder(Properties props) { - super(BlobStore.class, AsyncBlobStore.class, props); + public FilesystemBlobStoreContextBuilder(FilesystemApiMetadata apiMetadata) { + super(apiMetadata); } @Override diff --git a/apis/filesystem/src/main/java/org/jclouds/filesystem/FilesystemBlobStorePropertiesBuilder.java b/apis/filesystem/src/main/java/org/jclouds/filesystem/FilesystemBlobStorePropertiesBuilder.java deleted file mode 100644 index 4da3e86741..0000000000 --- a/apis/filesystem/src/main/java/org/jclouds/filesystem/FilesystemBlobStorePropertiesBuilder.java +++ /dev/null @@ -1,56 +0,0 @@ -/** - * 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. - */ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ - -package org.jclouds.filesystem; - -import static org.jclouds.Constants.PROPERTY_API_VERSION; -import static org.jclouds.Constants.PROPERTY_ENDPOINT; -import static org.jclouds.Constants.PROPERTY_IDENTITY; -import static org.jclouds.Constants.PROPERTY_IO_WORKER_THREADS; -import static org.jclouds.Constants.PROPERTY_USER_THREADS; - -import java.util.Properties; - -import org.jclouds.PropertiesBuilder; - -/** - * - * @author rainbowbreeze - */ -public class FilesystemBlobStorePropertiesBuilder extends PropertiesBuilder { - @Override - protected Properties defaultProperties() { - Properties properties = super.defaultProperties(); - properties.setProperty(PROPERTY_ENDPOINT, "http://localhost/transient"); - properties.setProperty(PROPERTY_API_VERSION, "1"); - properties.setProperty(PROPERTY_IDENTITY, System.getProperty("user.name")); - properties.setProperty(PROPERTY_USER_THREADS, "0"); - properties.setProperty(PROPERTY_IO_WORKER_THREADS, "0"); - return properties; - } - - public FilesystemBlobStorePropertiesBuilder(Properties properties) { - super(properties); - } - -} diff --git a/apis/filesystem/src/main/java/org/jclouds/filesystem/config/FilesystemBlobStoreContextModule.java b/apis/filesystem/src/main/java/org/jclouds/filesystem/config/FilesystemBlobStoreContextModule.java index 1cc4267910..8223e1280b 100644 --- a/apis/filesystem/src/main/java/org/jclouds/filesystem/config/FilesystemBlobStoreContextModule.java +++ b/apis/filesystem/src/main/java/org/jclouds/filesystem/config/FilesystemBlobStoreContextModule.java @@ -49,6 +49,7 @@ import com.google.inject.TypeLiteral; */ public class FilesystemBlobStoreContextModule extends AbstractModule { + @SuppressWarnings("rawtypes") @Override protected void configure() { bind(new TypeLiteral() { diff --git a/apis/filesystem/src/main/java/org/jclouds/filesystem/config/FilesystemBlobStoreModule.java b/apis/filesystem/src/main/java/org/jclouds/filesystem/config/FilesystemBlobStoreModule.java index dee50900e4..f836d82ab0 100644 --- a/apis/filesystem/src/main/java/org/jclouds/filesystem/config/FilesystemBlobStoreModule.java +++ b/apis/filesystem/src/main/java/org/jclouds/filesystem/config/FilesystemBlobStoreModule.java @@ -24,7 +24,7 @@ import org.jclouds.filesystem.FilesystemBlobStore; import org.jclouds.rest.config.RestClientModule; /** - * + * * @author Alfredo "Rainbowbreeze" Morresi */ public class FilesystemBlobStoreModule extends RestClientModule { @@ -33,12 +33,10 @@ public class FilesystemBlobStoreModule extends RestClientModule context = null; private BlobStore blobStore = null; private Set resourcesToBeDeleted = new HashSet(); @@ -96,7 +94,7 @@ public class FilesystemAsyncBlobStoreTest { // create context for filesystem container Properties prop = new Properties(); prop.setProperty(FilesystemConstants.PROPERTY_BASEDIR, TestUtils.TARGET_BASE_DIR); - context = (BlobStoreContext) new BlobStoreContextFactory().createContext(PROVIDER, "identity", "credential", Collections.emptyList(), prop); + context = BlobStoreContextBuilder.newBuilder(PROVIDER).overrides(prop).build(); // create a container in the default location blobStore = context.getBlobStore(); @@ -133,7 +131,7 @@ public class FilesystemAsyncBlobStoreTest { // no base directory declared in properties try { Properties props = new Properties(); - new BlobStoreContextFactory().createContext(PROVIDER, props); + context = BlobStoreContextBuilder.newBuilder(PROVIDER).overrides(props).build(); fail("No error if base directory is not specified"); } catch (CreationException e) { } @@ -142,7 +140,7 @@ public class FilesystemAsyncBlobStoreTest { try { Properties props = new Properties(); props.setProperty(FilesystemConstants.PROPERTY_BASEDIR, null); - new BlobStoreContextFactory().createContext(PROVIDER, props); + context = BlobStoreContextBuilder.newBuilder(PROVIDER).overrides(props).build(); fail("No error if base directory is null in the option"); } catch (NullPointerException e) { } diff --git a/apis/filesystem/src/test/java/org/jclouds/filesystem/integration/FilesystemBlobIntegrationTest.java b/apis/filesystem/src/test/java/org/jclouds/filesystem/integration/FilesystemBlobIntegrationTestDisabled.java similarity index 55% rename from apis/filesystem/src/test/java/org/jclouds/filesystem/integration/FilesystemBlobIntegrationTest.java rename to apis/filesystem/src/test/java/org/jclouds/filesystem/integration/FilesystemBlobIntegrationTestDisabled.java index 2d49307d7e..8cde760310 100644 --- a/apis/filesystem/src/test/java/org/jclouds/filesystem/integration/FilesystemBlobIntegrationTest.java +++ b/apis/filesystem/src/test/java/org/jclouds/filesystem/integration/FilesystemBlobIntegrationTestDisabled.java @@ -18,7 +18,12 @@ */ package org.jclouds.filesystem.integration; +import java.util.Properties; + import org.jclouds.blobstore.integration.internal.BaseBlobIntegrationTest; +import org.jclouds.blobstore.integration.internal.BaseBlobStoreIntegrationTest; +import org.jclouds.filesystem.reference.FilesystemConstants; +import org.jclouds.filesystem.utils.TestUtils; import org.testng.annotations.Test; /** @@ -26,7 +31,18 @@ import org.testng.annotations.Test; * @author James Murty * @author Adrian Cole */ -@Test(groups = { "integration" }, testName = "blobstore.FilesystemBlobIntegrationTest") -public class FilesystemBlobIntegrationTest extends BaseBlobIntegrationTest { +@Test(groups = { "integration" }, singleThreaded = true, testName = "blobstore.FilesystemBlobIntegrationTest") +public class FilesystemBlobIntegrationTestDisabled extends BaseBlobIntegrationTest { + public FilesystemBlobIntegrationTestDisabled() { + provider = "filesystem"; + BaseBlobStoreIntegrationTest.SANITY_CHECK_RETURNED_BUCKET_NAME = true; + } + + @Override + protected Properties setupProperties() { + Properties props = super.setupProperties(); + props.setProperty(FilesystemConstants.PROPERTY_BASEDIR, TestUtils.TARGET_BASE_DIR); + return props; + } } \ No newline at end of file diff --git a/apis/filesystem/src/test/java/org/jclouds/filesystem/integration/FilesystemBlobMapIntegrationTest.java b/apis/filesystem/src/test/java/org/jclouds/filesystem/integration/FilesystemBlobMapIntegrationTestDisabled.java similarity index 60% rename from apis/filesystem/src/test/java/org/jclouds/filesystem/integration/FilesystemBlobMapIntegrationTest.java rename to apis/filesystem/src/test/java/org/jclouds/filesystem/integration/FilesystemBlobMapIntegrationTestDisabled.java index 17cab91141..e39b830af3 100644 --- a/apis/filesystem/src/test/java/org/jclouds/filesystem/integration/FilesystemBlobMapIntegrationTest.java +++ b/apis/filesystem/src/test/java/org/jclouds/filesystem/integration/FilesystemBlobMapIntegrationTestDisabled.java @@ -18,7 +18,12 @@ */ package org.jclouds.filesystem.integration; +import java.util.Properties; + import org.jclouds.blobstore.integration.internal.BaseBlobMapIntegrationTest; +import org.jclouds.blobstore.integration.internal.BaseBlobStoreIntegrationTest; +import org.jclouds.filesystem.reference.FilesystemConstants; +import org.jclouds.filesystem.utils.TestUtils; import org.testng.annotations.Test; /** @@ -26,6 +31,16 @@ import org.testng.annotations.Test; */ @Test(groups = { "integration", "live" }, testName = "blobstore.FilesystemBlobMapIntegrationTest") -public class FilesystemBlobMapIntegrationTest extends BaseBlobMapIntegrationTest { +public class FilesystemBlobMapIntegrationTestDisabled extends BaseBlobMapIntegrationTest { + public FilesystemBlobMapIntegrationTestDisabled() { + provider = "filesystem"; + BaseBlobStoreIntegrationTest.SANITY_CHECK_RETURNED_BUCKET_NAME = true; + } + @Override + protected Properties setupProperties() { + Properties props = super.setupProperties(); + props.setProperty(FilesystemConstants.PROPERTY_BASEDIR, TestUtils.TARGET_BASE_DIR); + return props; + } } \ No newline at end of file diff --git a/apis/filesystem/src/test/java/org/jclouds/filesystem/integration/FilesystemContainerIntegrationTest.java b/apis/filesystem/src/test/java/org/jclouds/filesystem/integration/FilesystemContainerIntegrationTestDisabled.java similarity index 78% rename from apis/filesystem/src/test/java/org/jclouds/filesystem/integration/FilesystemContainerIntegrationTest.java rename to apis/filesystem/src/test/java/org/jclouds/filesystem/integration/FilesystemContainerIntegrationTestDisabled.java index 3cec809698..4950969167 100644 --- a/apis/filesystem/src/test/java/org/jclouds/filesystem/integration/FilesystemContainerIntegrationTest.java +++ b/apis/filesystem/src/test/java/org/jclouds/filesystem/integration/FilesystemContainerIntegrationTestDisabled.java @@ -21,13 +21,18 @@ package org.jclouds.filesystem.integration; import static org.jclouds.blobstore.options.ListContainerOptions.Builder.maxResults; import static org.testng.Assert.assertEquals; +import java.util.Properties; + import javax.ws.rs.core.MediaType; import org.jclouds.blobstore.domain.Blob; import org.jclouds.blobstore.domain.BlobMetadata; import org.jclouds.blobstore.domain.PageSet; import org.jclouds.blobstore.domain.StorageMetadata; +import org.jclouds.blobstore.integration.internal.BaseBlobStoreIntegrationTest; import org.jclouds.blobstore.integration.internal.BaseContainerIntegrationTest; +import org.jclouds.filesystem.reference.FilesystemConstants; +import org.jclouds.filesystem.utils.TestUtils; import org.testng.annotations.Test; import com.google.common.collect.ImmutableMap; @@ -38,8 +43,18 @@ import com.google.common.collect.Iterables; * @author Adrian Cole */ @Test(groups = { "integration", "live" }, testName = "blobstore.FilesystemContainerIntegrationTest") -public class FilesystemContainerIntegrationTest extends BaseContainerIntegrationTest { +public class FilesystemContainerIntegrationTestDisabled extends BaseContainerIntegrationTest { + public FilesystemContainerIntegrationTestDisabled() { + provider = "filesystem"; + BaseBlobStoreIntegrationTest.SANITY_CHECK_RETURNED_BUCKET_NAME = true; + } + @Override + protected Properties setupProperties() { + Properties props = super.setupProperties(); + props.setProperty(FilesystemConstants.PROPERTY_BASEDIR, TestUtils.TARGET_BASE_DIR); + return props; + } @Test(groups = { "integration", "live" }) public void testNotWithDetails() throws InterruptedException { diff --git a/apis/filesystem/src/test/java/org/jclouds/filesystem/integration/FilesystemInputStreamMapIntegrationTest.java b/apis/filesystem/src/test/java/org/jclouds/filesystem/integration/FilesystemInputStreamMapIntegrationTestDisabled.java similarity index 60% rename from apis/filesystem/src/test/java/org/jclouds/filesystem/integration/FilesystemInputStreamMapIntegrationTest.java rename to apis/filesystem/src/test/java/org/jclouds/filesystem/integration/FilesystemInputStreamMapIntegrationTestDisabled.java index ae46ee916f..b224e36224 100644 --- a/apis/filesystem/src/test/java/org/jclouds/filesystem/integration/FilesystemInputStreamMapIntegrationTest.java +++ b/apis/filesystem/src/test/java/org/jclouds/filesystem/integration/FilesystemInputStreamMapIntegrationTestDisabled.java @@ -18,13 +18,28 @@ */ package org.jclouds.filesystem.integration; +import java.util.Properties; + +import org.jclouds.blobstore.integration.internal.BaseBlobStoreIntegrationTest; import org.jclouds.blobstore.integration.internal.BaseInputStreamMapIntegrationTest; +import org.jclouds.filesystem.reference.FilesystemConstants; +import org.jclouds.filesystem.utils.TestUtils; import org.testng.annotations.Test; /** * @author Adrian Cole */ @Test(groups = { "integration", "live" }, testName = "blobstore.FilesystemInputStreamMapIntegrationTest") -public class FilesystemInputStreamMapIntegrationTest extends BaseInputStreamMapIntegrationTest { +public class FilesystemInputStreamMapIntegrationTestDisabled extends BaseInputStreamMapIntegrationTest { + public FilesystemInputStreamMapIntegrationTestDisabled() { + provider = "filesystem"; + BaseBlobStoreIntegrationTest.SANITY_CHECK_RETURNED_BUCKET_NAME = true; + } + @Override + protected Properties setupProperties() { + Properties props = super.setupProperties(); + props.setProperty(FilesystemConstants.PROPERTY_BASEDIR, TestUtils.TARGET_BASE_DIR); + return props; + } } \ No newline at end of file diff --git a/apis/filesystem/src/test/java/org/jclouds/filesystem/integration/FilesystemServiceIntegrationTest.java b/apis/filesystem/src/test/java/org/jclouds/filesystem/integration/FilesystemServiceIntegrationTestDisabled.java similarity index 60% rename from apis/filesystem/src/test/java/org/jclouds/filesystem/integration/FilesystemServiceIntegrationTest.java rename to apis/filesystem/src/test/java/org/jclouds/filesystem/integration/FilesystemServiceIntegrationTestDisabled.java index a6877d3607..24e1f64f59 100644 --- a/apis/filesystem/src/test/java/org/jclouds/filesystem/integration/FilesystemServiceIntegrationTest.java +++ b/apis/filesystem/src/test/java/org/jclouds/filesystem/integration/FilesystemServiceIntegrationTestDisabled.java @@ -18,13 +18,28 @@ */ package org.jclouds.filesystem.integration; +import java.util.Properties; + +import org.jclouds.blobstore.integration.internal.BaseBlobStoreIntegrationTest; import org.jclouds.blobstore.integration.internal.BaseServiceIntegrationTest; +import org.jclouds.filesystem.reference.FilesystemConstants; +import org.jclouds.filesystem.utils.TestUtils; import org.testng.annotations.Test; /** * @author Adrian Cole */ @Test(groups = { "integration", "live" }, testName = "blobstore.FilesystemServiceIntegrationTest") -public class FilesystemServiceIntegrationTest extends BaseServiceIntegrationTest { +public class FilesystemServiceIntegrationTestDisabled extends BaseServiceIntegrationTest { + public FilesystemServiceIntegrationTestDisabled() { + provider = "filesystem"; + BaseBlobStoreIntegrationTest.SANITY_CHECK_RETURNED_BUCKET_NAME = true; + } + @Override + protected Properties setupProperties() { + Properties props = super.setupProperties(); + props.setProperty(FilesystemConstants.PROPERTY_BASEDIR, TestUtils.TARGET_BASE_DIR); + return props; + } } \ No newline at end of file diff --git a/apis/filesystem/src/test/java/org/jclouds/filesystem/integration/FilesystemTestInitializer.java b/apis/filesystem/src/test/java/org/jclouds/filesystem/integration/FilesystemTestInitializer.java deleted file mode 100644 index 12fbb61633..0000000000 --- a/apis/filesystem/src/test/java/org/jclouds/filesystem/integration/FilesystemTestInitializer.java +++ /dev/null @@ -1,61 +0,0 @@ -/** - * 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.filesystem.integration; - -import java.io.IOException; -import java.util.Properties; - -import org.jclouds.blobstore.BlobStoreContext; -import org.jclouds.blobstore.BlobStoreContextFactory; -import org.jclouds.blobstore.integration.TransientBlobStoreTestInitializer; -import org.jclouds.blobstore.integration.internal.BaseBlobStoreIntegrationTest; -import org.jclouds.filesystem.reference.FilesystemConstants; -import org.jclouds.filesystem.utils.TestUtils; -import org.jclouds.logging.log4j.config.Log4JLoggingModule; - -import com.google.common.collect.ImmutableSet; -import com.google.inject.Module; - -/** - * - * @author Adrian Cole - */ -public class FilesystemTestInitializer extends TransientBlobStoreTestInitializer { - - public FilesystemTestInitializer() { - provider = "filesystem"; - BaseBlobStoreIntegrationTest.SANITY_CHECK_RETURNED_BUCKET_NAME = true; - } - - @Override - protected BlobStoreContext createLiveContext(Module configurationModule, String endpoint, String apiVersion, - String buildVersion, String app, String identity, String credential) throws IOException { - return new BlobStoreContextFactory().createContext(provider, ImmutableSet.of(configurationModule, - new Log4JLoggingModule()), setupProperties(endpoint, apiVersion, buildVersion, identity, credential)); - } - - @Override - protected Properties setupProperties(String endpoint, String apiVersion, String buildVersion, String identity, - String credential) { - Properties props = super.setupProperties(endpoint, apiVersion, buildVersion, identity, credential); - props.setProperty(FilesystemConstants.PROPERTY_BASEDIR, TestUtils.TARGET_BASE_DIR); - return props; - } - -} diff --git a/apis/nova/src/main/java/org/jclouds/openstack/nova/NovaApiMetadata.java b/apis/nova/src/main/java/org/jclouds/openstack/nova/NovaApiMetadata.java index ef27f4770e..80a98df306 100644 --- a/apis/nova/src/main/java/org/jclouds/openstack/nova/NovaApiMetadata.java +++ b/apis/nova/src/main/java/org/jclouds/openstack/nova/NovaApiMetadata.java @@ -19,49 +19,69 @@ package org.jclouds.openstack.nova; import java.net.URI; +import java.util.Properties; import org.jclouds.apis.ApiMetadata; -import org.jclouds.apis.ApiType; -import org.jclouds.apis.BaseApiMetadata; +import org.jclouds.compute.ComputeServiceContext; +import org.jclouds.compute.internal.BaseComputeServiceApiMetadata; + +import com.google.common.reflect.TypeToken; /** - * Implementation of {@link ApiMetadata} for OpenStack Nova Pre-Diablo + * Implementation of {@link ApiMetadata} for Nova 1.0 API * * @author Adrian Cole */ -public class NovaApiMetadata extends BaseApiMetadata { +public class NovaApiMetadata + extends + BaseComputeServiceApiMetadata, NovaApiMetadata> { - public NovaApiMetadata() { - this(builder() - .id("nova") - .type(ApiType.COMPUTE) - .name("OpenStack Nova Pre-Diablo API") - .identityName("accessKey") - .credentialName("secretKey") - .documentation(URI.create("http://api.openstack.org/"))); + @Override + public Builder toBuilder() { + return new Builder().fromApiMetadata(this); } - // below are so that we can reuse builders, toString, hashCode, etc. - // we have to set concrete classes here, as our base class cannot be - // concrete due to serviceLoader - protected NovaApiMetadata(ConcreteBuilder builder) { + public NovaApiMetadata() { + this(new Builder()); + } + + protected NovaApiMetadata(Builder builder) { super(builder); } - private static class ConcreteBuilder extends Builder { + protected static Properties defaultProperties() { + Properties properties = BaseComputeServiceApiMetadata.Builder.defaultProperties(); + return properties; + } + + public static class Builder + extends + BaseComputeServiceApiMetadata.Builder, NovaApiMetadata> { + + protected Builder() { + id("nova") + .name("OpenStack Nova Pre-Diablo API") + .identityName("accessKey") + .credentialName("secretKey") + .documentation(URI.create("http://api.openstack.org/")) + .version("1.1") + .defaultEndpoint("http://localhost:5000") + .javaApi(NovaClient.class, NovaAsyncClient.class) + .defaultProperties(NovaApiMetadata.defaultProperties()) + .contextBuilder(TypeToken.of(NovaContextBuilder.class)); + } @Override public NovaApiMetadata build() { return new NovaApiMetadata(this); } + + @Override + public Builder fromApiMetadata(NovaApiMetadata in) { + super.fromApiMetadata(in); + return this; + } + } - public static ConcreteBuilder builder() { - return new ConcreteBuilder(); - } - - @Override - public ConcreteBuilder toBuilder() { - return builder().fromApiMetadata(this); - } } \ No newline at end of file diff --git a/apis/nova/src/main/java/org/jclouds/openstack/nova/NovaContextBuilder.java b/apis/nova/src/main/java/org/jclouds/openstack/nova/NovaContextBuilder.java index 903c983bd0..6a147dbfe6 100644 --- a/apis/nova/src/main/java/org/jclouds/openstack/nova/NovaContextBuilder.java +++ b/apis/nova/src/main/java/org/jclouds/openstack/nova/NovaContextBuilder.java @@ -19,35 +19,30 @@ package org.jclouds.openstack.nova; import java.util.List; -import java.util.Properties; +import org.jclouds.compute.ComputeServiceContext; import org.jclouds.compute.ComputeServiceContextBuilder; -import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule; -import org.jclouds.logging.jdk.config.JDKLoggingModule; import org.jclouds.openstack.nova.compute.config.NovaComputeServiceContextModule; import org.jclouds.openstack.nova.config.NovaRestClientModule; +import org.jclouds.providers.ProviderMetadata; -import com.google.inject.Injector; import com.google.inject.Module; /** - * Creates {@link NovaComputeServiceContext} or {@link Injector} instances based on the most - * commonly requested arguments. - *

- * Note that Threadsafe objects will be bound as singletons to the Injector or Context provided. - *

- *

- * If no Modules are specified, the default {@link JDKLoggingModule logging} and - * {@link JavaUrlHttpCommandExecutorServiceModule http transports} will be installed. * * @author Adrian Cole - * @see NovaComputeServiceContext */ -public class NovaContextBuilder extends - ComputeServiceContextBuilder { +public class NovaContextBuilder + extends + ComputeServiceContextBuilder, NovaApiMetadata> { - public NovaContextBuilder(Properties props) { - super(NovaClient.class, NovaAsyncClient.class, props); + public NovaContextBuilder( + ProviderMetadata, NovaApiMetadata> providerMetadata) { + super(providerMetadata); + } + + public NovaContextBuilder(NovaApiMetadata apiMetadata) { + super(apiMetadata); } @Override @@ -55,9 +50,8 @@ public class NovaContextBuilder extends modules.add(new NovaComputeServiceContextModule()); } - @Override protected void addClientModule(List modules) { modules.add(new NovaRestClientModule()); } -} +} \ No newline at end of file diff --git a/apis/nova/src/test/java/org/jclouds/openstack/nova/NovaApiMetadataTest.java b/apis/nova/src/test/java/org/jclouds/openstack/nova/NovaApiMetadataTest.java index 448a1e04b2..6ca1e8ae5a 100644 --- a/apis/nova/src/test/java/org/jclouds/openstack/nova/NovaApiMetadataTest.java +++ b/apis/nova/src/test/java/org/jclouds/openstack/nova/NovaApiMetadataTest.java @@ -18,8 +18,7 @@ */ package org.jclouds.openstack.nova; -import org.jclouds.apis.ApiType; -import org.jclouds.apis.BaseApiMetadataTest; +import org.jclouds.compute.internal.BaseComputeServiceApiMetadataTest; import org.testng.annotations.Test; /** @@ -27,9 +26,9 @@ import org.testng.annotations.Test; * @author Adrian Cole */ @Test(groups = "unit", testName = "NovaApiMetadataTest") -public class NovaApiMetadataTest extends BaseApiMetadataTest { +public class NovaApiMetadataTest extends BaseComputeServiceApiMetadataTest { public NovaApiMetadataTest() { - super(new NovaApiMetadata(), ApiType.COMPUTE); + super(new NovaApiMetadata()); } } diff --git a/apis/nova/src/test/java/org/jclouds/openstack/nova/NovaAsyncClientTest.java b/apis/nova/src/test/java/org/jclouds/openstack/nova/NovaAsyncClientTest.java index d2e6c2387f..eaef7e29af 100644 --- a/apis/nova/src/test/java/org/jclouds/openstack/nova/NovaAsyncClientTest.java +++ b/apis/nova/src/test/java/org/jclouds/openstack/nova/NovaAsyncClientTest.java @@ -18,7 +18,6 @@ */ package org.jclouds.openstack.nova; -import static org.jclouds.Constants.PROPERTY_API_VERSION; import static org.jclouds.openstack.nova.options.CreateServerOptions.Builder.withFile; import static org.jclouds.openstack.nova.options.CreateServerOptions.Builder.withMetadata; import static org.jclouds.openstack.nova.options.ListOptions.Builder.changesSince; @@ -29,7 +28,6 @@ import static org.testng.Assert.assertEquals; import java.io.IOException; import java.lang.reflect.Method; import java.util.Date; -import java.util.Properties; import javax.ws.rs.core.MediaType; @@ -46,13 +44,13 @@ import org.jclouds.openstack.nova.domain.RebootType; import org.jclouds.openstack.nova.options.CreateServerOptions; import org.jclouds.openstack.nova.options.ListOptions; import org.jclouds.openstack.nova.options.RebuildServerOptions; +import org.jclouds.providers.ProviderMetadata; +import org.jclouds.rest.AnonymousProviderMetadata; import org.jclouds.rest.ConfiguresRestClient; -import org.jclouds.rest.RestClientTest; -import org.jclouds.rest.RestContextFactory; -import org.jclouds.rest.RestContextSpec; import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404; import org.jclouds.rest.functions.ReturnFalseOnNotFoundOr404; import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; +import org.jclouds.rest.internal.BaseAsyncClientTest; import org.jclouds.rest.internal.RestAnnotationProcessor; import org.testng.annotations.Test; @@ -67,7 +65,7 @@ import com.google.inject.TypeLiteral; */ // NOTE:without testName, this will not call @Before* and fail w/NPE during surefire @Test(groups = "unit", singleThreaded = true, testName = "NovaAsyncClientTest") -public class NovaAsyncClientTest extends RestClientTest { +public class NovaAsyncClientTest extends BaseAsyncClientTest { private static final Class listOptionsVarargsClass = new ListOptions[]{}.getClass(); private static final Class createServerOptionsVarargsClass = new CreateServerOptions[]{} .getClass(); @@ -777,18 +775,10 @@ public class NovaAsyncClientTest extends RestClientTest { } - protected String provider = "nova"; - - @Override - public RestContextSpec createContextSpec() { - return new RestContextFactory(setupRestProperties()).createContextSpec(provider, "user", "password", setupProperties()); - } - - @Override - protected Properties setupProperties() { - Properties overrides = new Properties(); - overrides.setProperty(PROPERTY_API_VERSION, "api-version"); - overrides.setProperty(provider + ".endpoint", "http://endpoint"); - return overrides; + protected String provider = "nova"; + + @Override + protected ProviderMetadata createProviderMetadata() { + return AnonymousProviderMetadata.forApiWithEndpoint(new NovaApiMetadata(), "http://endpoint"); } } diff --git a/apis/nova/src/test/java/org/jclouds/openstack/nova/NovaClientLiveTest.java b/apis/nova/src/test/java/org/jclouds/openstack/nova/NovaClientLiveTest.java index 0796718958..d93ec24277 100644 --- a/apis/nova/src/test/java/org/jclouds/openstack/nova/NovaClientLiveTest.java +++ b/apis/nova/src/test/java/org/jclouds/openstack/nova/NovaClientLiveTest.java @@ -29,15 +29,14 @@ import java.io.IOException; import java.lang.reflect.UndeclaredThrowableException; import java.security.SecureRandom; import java.util.Map; -import java.util.Properties; import java.util.Set; import java.util.concurrent.TimeUnit; -import org.jclouds.compute.BaseVersionedServiceLiveTest; +import org.jclouds.compute.ComputeServiceContext; +import org.jclouds.compute.internal.BaseComputeServiceContextLiveTest; import org.jclouds.domain.LoginCredentials; import org.jclouds.http.HttpResponseException; import org.jclouds.io.Payload; -import org.jclouds.logging.log4j.config.Log4JLoggingModule; import org.jclouds.net.IPSocket; import org.jclouds.openstack.nova.domain.Flavor; import org.jclouds.openstack.nova.domain.Image; @@ -48,10 +47,8 @@ import org.jclouds.openstack.nova.domain.ServerStatus; import org.jclouds.openstack.nova.options.RebuildServerOptions; import org.jclouds.predicates.RetryablePredicate; import org.jclouds.predicates.SocketOpen; -import org.jclouds.rest.RestContextFactory; import org.jclouds.ssh.SshClient; import org.jclouds.ssh.SshException; -import org.jclouds.sshj.config.SshjSshClientModule; import org.jclouds.util.Strings2; import org.testng.annotations.AfterTest; import org.testng.annotations.BeforeGroups; @@ -59,10 +56,8 @@ import org.testng.annotations.Test; import com.google.common.base.Predicate; import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; import com.google.inject.Injector; -import com.google.inject.Module; /** * Tests behavior of {@code NovaClient} @@ -70,7 +65,10 @@ import com.google.inject.Module; * @author Adrian Cole */ @Test(groups = "live", singleThreaded = true, testName = "NovaClientLiveTest") -public class NovaClientLiveTest extends BaseVersionedServiceLiveTest { +public class NovaClientLiveTest + extends + BaseComputeServiceContextLiveTest> { + public NovaClientLiveTest() { provider = "nova"; } @@ -79,15 +77,11 @@ public class NovaClientLiveTest extends BaseVersionedServiceLiveTest { protected SshClient.Factory sshFactory; protected Predicate socketTester; - @BeforeGroups(groups = { "live" }) - public void setupClient() { - setupCredentials(); - Properties overrides = setupProperties(); - - Injector injector = new RestContextFactory().createContextBuilder(provider, - ImmutableSet. of(new Log4JLoggingModule(), new SshjSshClientModule()), overrides) - .buildInjector(); - + @BeforeGroups(groups = { "integration", "live" }) + @Override + public void setupContext() { + super.setupContext(); + Injector injector = context.utils().injector(); client = injector.getInstance(NovaClient.class); sshFactory = injector.getInstance(SshClient.Factory.class); SocketOpen socketOpen = injector.getInstance(SocketOpen.class); diff --git a/apis/nova/src/test/java/org/jclouds/openstack/nova/compute/NovaComputeServiceLiveTest.java b/apis/nova/src/test/java/org/jclouds/openstack/nova/compute/NovaComputeServiceLiveTest.java index 4d1f225a0f..eb0dc9eea2 100644 --- a/apis/nova/src/test/java/org/jclouds/openstack/nova/compute/NovaComputeServiceLiveTest.java +++ b/apis/nova/src/test/java/org/jclouds/openstack/nova/compute/NovaComputeServiceLiveTest.java @@ -22,13 +22,12 @@ import static org.testng.Assert.assertEquals; import java.io.IOException; -import org.jclouds.compute.BaseComputeServiceLiveTest; -import org.jclouds.compute.ComputeServiceContextFactory; +import org.jclouds.compute.ComputeServiceContext; import org.jclouds.compute.domain.NodeMetadata; +import org.jclouds.compute.internal.BaseComputeServiceLiveTest; import org.jclouds.domain.LocationScope; import org.jclouds.openstack.nova.NovaAsyncClient; import org.jclouds.openstack.nova.NovaClient; -import org.jclouds.rest.RestContext; import org.jclouds.sshj.config.SshjSshClientModule; import org.testng.annotations.Test; @@ -40,7 +39,9 @@ import com.google.inject.Module; * @author Adrian Cole */ @Test(groups = "live", enabled = true, singleThreaded = true, testName = "NovaComputeServiceLiveTest") -public class NovaComputeServiceLiveTest extends BaseComputeServiceLiveTest { +public class NovaComputeServiceLiveTest extends + BaseComputeServiceLiveTest> { + public NovaComputeServiceLiveTest() { provider = "nova"; } @@ -49,13 +50,7 @@ public class NovaComputeServiceLiveTest extends BaseComputeServiceLiveTest { protected Module getSshModule() { return new SshjSshClientModule(); } - - public void testAssignability() throws Exception { - @SuppressWarnings("unused") - RestContext tmContext = new ComputeServiceContextFactory() - .createContext(provider, identity, credential).getProviderSpecificContext(); - } - + @Override protected void checkNodes(Iterable nodes, String group, String task) throws IOException { super.checkNodes(nodes, group, task); diff --git a/apis/openstack-nova-ec2/src/main/java/org/jclouds/openstack/nova/ec2/NovaEC2ApiMetadata.java b/apis/openstack-nova-ec2/src/main/java/org/jclouds/openstack/nova/ec2/NovaEC2ApiMetadata.java index e8ba97cce6..240b37c49f 100644 --- a/apis/openstack-nova-ec2/src/main/java/org/jclouds/openstack/nova/ec2/NovaEC2ApiMetadata.java +++ b/apis/openstack-nova-ec2/src/main/java/org/jclouds/openstack/nova/ec2/NovaEC2ApiMetadata.java @@ -18,43 +18,84 @@ */ package org.jclouds.openstack.nova.ec2; +import static org.jclouds.Constants.PROPERTY_RELAX_HOSTNAME; +import static org.jclouds.Constants.PROPERTY_TRUST_ALL_CERTS; +import static org.jclouds.compute.config.ComputeServiceProperties.RESOURCENAME_DELIMITER; +import static org.jclouds.ec2.reference.EC2Constants.PROPERTY_EC2_AMI_OWNERS; +import static org.jclouds.ec2.reference.EC2Constants.PROPERTY_EC2_AUTO_ALLOCATE_ELASTIC_IPS; +import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGIONS; + +import java.util.Properties; + import org.jclouds.apis.ApiMetadata; import org.jclouds.ec2.EC2ApiMetadata; +import org.jclouds.ec2.EC2AsyncClient; +import org.jclouds.ec2.EC2Client; +import org.jclouds.ec2.compute.EC2ComputeServiceContext; + +import com.google.common.reflect.TypeToken; /** - * Implementation of {@link ApiMetadata} for Nova's EC2-clone API + * Implementation of {@link ApiMetadata} for the OpenStack Nova's EC2-clone API * * @author Adrian Cole */ -public class NovaEC2ApiMetadata extends EC2ApiMetadata { +public class NovaEC2ApiMetadata extends EC2ApiMetadata, NovaEC2ApiMetadata> { + private static Builder builder() { + return new Builder(); + } + + @Override + public Builder toBuilder() { + return builder().fromApiMetadata(this); + } public NovaEC2ApiMetadata() { - this(builder().fromApiMetadata(new EC2ApiMetadata()) - .id("openstack-nova-ec2") - .name("Nova's EC2-clone API")); + this(builder()); } - // below are so that we can reuse builders, toString, hashCode, etc. - // we have to set concrete classes here, as our base class cannot be - // concrete due to serviceLoader - protected NovaEC2ApiMetadata(ConcreteBuilder builder) { + protected NovaEC2ApiMetadata(Builder builder) { super(builder); } + + protected static Properties defaultProperties() { + Properties properties = EC2ApiMetadata.defaultProperties(); + properties.setProperty(PROPERTY_REGIONS, "nova"); + properties.setProperty(PROPERTY_EC2_AMI_OWNERS, "admin"); + // hash characters are banned + properties.setProperty(RESOURCENAME_DELIMITER, "-"); + // often, we are dealing with IP addresses, not hostnames + properties.setProperty(PROPERTY_RELAX_HOSTNAME, "true"); + properties.setProperty(PROPERTY_TRUST_ALL_CERTS, "true"); + properties.setProperty(PROPERTY_EC2_AUTO_ALLOCATE_ELASTIC_IPS, "true"); + // auth fail sometimes happens in EC2, as the rc.local script that injects the + // authorized key executes after ssh has started. + properties.setProperty("jclouds.ssh.max-retries", "7"); + properties.setProperty("jclouds.ssh.retry-auth", "true"); + return properties; + } - private static class ConcreteBuilder extends EC2ApiMetadataBuilder { - + public static class Builder extends EC2ApiMetadata.Builder, NovaEC2ApiMetadata> { + protected Builder(){ + super(EC2Client.class, EC2AsyncClient.class); + id("openstack-nova-ec2") + .name("OpenStack Nova's EC2-clone API") + .version("2009-04-04") + .defaultEndpoint("http://localhost:8773/services/Cloud") + .defaultProperties(NovaEC2ApiMetadata.defaultProperties()) + .contextBuilder(TypeToken.of(NovaEC2ContextBuilder.class)); + } + @Override public NovaEC2ApiMetadata build() { return new NovaEC2ApiMetadata(this); } + + @Override + public Builder fromApiMetadata(NovaEC2ApiMetadata in) { + super.fromApiMetadata(in); + return this; + } } - private static ConcreteBuilder builder() { - return new ConcreteBuilder(); - } - - @Override - public ConcreteBuilder toBuilder() { - return builder().fromApiMetadata(this); - } } \ No newline at end of file diff --git a/apis/openstack-nova-ec2/src/main/java/org/jclouds/openstack/nova/ec2/NovaEC2ContextBuilder.java b/apis/openstack-nova-ec2/src/main/java/org/jclouds/openstack/nova/ec2/NovaEC2ContextBuilder.java index 7131666d99..af5d8391de 100644 --- a/apis/openstack-nova-ec2/src/main/java/org/jclouds/openstack/nova/ec2/NovaEC2ContextBuilder.java +++ b/apis/openstack-nova-ec2/src/main/java/org/jclouds/openstack/nova/ec2/NovaEC2ContextBuilder.java @@ -19,11 +19,14 @@ package org.jclouds.openstack.nova.ec2; import java.util.List; -import java.util.Properties; +import org.jclouds.ec2.EC2AsyncClient; +import org.jclouds.ec2.EC2Client; import org.jclouds.ec2.EC2ContextBuilder; +import org.jclouds.ec2.compute.EC2ComputeServiceContext; import org.jclouds.openstack.nova.ec2.config.NovaEC2ComputeServiceContextModule; import org.jclouds.openstack.nova.ec2.config.NovaEC2RestClientModule; +import org.jclouds.providers.ProviderMetadata; import com.google.inject.Module; @@ -31,13 +34,17 @@ import com.google.inject.Module; * * @author Adrian Cole */ -public class NovaEC2ContextBuilder extends EC2ContextBuilder { +public class NovaEC2ContextBuilder extends EC2ContextBuilder, NovaEC2ApiMetadata> { - public NovaEC2ContextBuilder(Properties props) { - super(props); + public NovaEC2ContextBuilder( + ProviderMetadata, NovaEC2ApiMetadata> providerMetadata) { + super(providerMetadata); + } + + public NovaEC2ContextBuilder(NovaEC2ApiMetadata apiMetadata) { + super(apiMetadata); } - @Override protected void addClientModule(List modules) { modules.add(new NovaEC2RestClientModule()); diff --git a/apis/openstack-nova-ec2/src/main/java/org/jclouds/openstack/nova/ec2/NovaEC2PropertiesBuilder.java b/apis/openstack-nova-ec2/src/main/java/org/jclouds/openstack/nova/ec2/NovaEC2PropertiesBuilder.java deleted file mode 100644 index 41c4b59a67..0000000000 --- a/apis/openstack-nova-ec2/src/main/java/org/jclouds/openstack/nova/ec2/NovaEC2PropertiesBuilder.java +++ /dev/null @@ -1,64 +0,0 @@ -/** - * 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.openstack.nova.ec2; - -import static org.jclouds.Constants.PROPERTY_API_VERSION; -import static org.jclouds.Constants.PROPERTY_ENDPOINT; -import static org.jclouds.Constants.PROPERTY_RELAX_HOSTNAME; -import static org.jclouds.Constants.PROPERTY_TRUST_ALL_CERTS; -import static org.jclouds.compute.config.ComputeServiceProperties.RESOURCENAME_DELIMITER; -import static org.jclouds.ec2.reference.EC2Constants.PROPERTY_EC2_AMI_OWNERS; -import static org.jclouds.ec2.reference.EC2Constants.PROPERTY_EC2_AUTO_ALLOCATE_ELASTIC_IPS; -import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGIONS; - -import java.util.Properties; - -import org.jclouds.ec2.EC2PropertiesBuilder; - -/** - * Builds properties used in NovaEC2 Clients - * - * @author Adrian Cole - */ -public class NovaEC2PropertiesBuilder extends EC2PropertiesBuilder { - @Override - protected Properties defaultProperties() { - Properties properties = super.defaultProperties(); - properties.setProperty(PROPERTY_API_VERSION, "2009-04-04"); - properties.setProperty(PROPERTY_ENDPOINT, "http://localhost:8773/services/Cloud"); - properties.setProperty(PROPERTY_REGIONS, "nova"); - properties.setProperty(PROPERTY_EC2_AMI_OWNERS, "admin"); - // hash characters are banned - properties.setProperty(RESOURCENAME_DELIMITER, "-"); - // often, we are dealing with IP addresses, not hostnames - properties.setProperty(PROPERTY_RELAX_HOSTNAME, "true"); - properties.setProperty(PROPERTY_TRUST_ALL_CERTS, "true"); - properties.setProperty(PROPERTY_EC2_AUTO_ALLOCATE_ELASTIC_IPS, "true"); - // auth fail sometimes happens in EC2, as the rc.local script that injects the - // authorized key executes after ssh has started. - properties.setProperty("jclouds.ssh.max-retries", "7"); - properties.setProperty("jclouds.ssh.retry-auth", "true"); - return properties; - } - - public NovaEC2PropertiesBuilder(Properties properties) { - super(properties); - } - -} diff --git a/apis/openstack-nova-ec2/src/test/java/org/jclouds/openstack/nova/ec2/NovaEC2ApiMetadataTest.java b/apis/openstack-nova-ec2/src/test/java/org/jclouds/openstack/nova/ec2/NovaEC2ApiMetadataTest.java index 7d63c3a991..9c511cfdac 100644 --- a/apis/openstack-nova-ec2/src/test/java/org/jclouds/openstack/nova/ec2/NovaEC2ApiMetadataTest.java +++ b/apis/openstack-nova-ec2/src/test/java/org/jclouds/openstack/nova/ec2/NovaEC2ApiMetadataTest.java @@ -18,8 +18,7 @@ */ package org.jclouds.openstack.nova.ec2; -import org.jclouds.apis.ApiType; -import org.jclouds.apis.BaseApiMetadataTest; +import org.jclouds.compute.internal.BaseComputeServiceApiMetadataTest; import org.testng.annotations.Test; /** @@ -27,9 +26,9 @@ import org.testng.annotations.Test; * @author Adrian Cole */ @Test(groups = "unit", testName = "NovaEC2ApiMetadataTest") -public class NovaEC2ApiMetadataTest extends BaseApiMetadataTest { +public class NovaEC2ApiMetadataTest extends BaseComputeServiceApiMetadataTest { public NovaEC2ApiMetadataTest() { - super(new NovaEC2ApiMetadata(), ApiType.COMPUTE); + super(new NovaEC2ApiMetadata()); } } diff --git a/apis/openstack-nova-ec2/src/test/java/org/jclouds/openstack/nova/ec2/compute/NovaEC2ComputeServiceLiveTest.java b/apis/openstack-nova-ec2/src/test/java/org/jclouds/openstack/nova/ec2/compute/NovaEC2ComputeServiceLiveTest.java index 14d614e7b6..253a799832 100644 --- a/apis/openstack-nova-ec2/src/test/java/org/jclouds/openstack/nova/ec2/compute/NovaEC2ComputeServiceLiveTest.java +++ b/apis/openstack-nova-ec2/src/test/java/org/jclouds/openstack/nova/ec2/compute/NovaEC2ComputeServiceLiveTest.java @@ -20,6 +20,9 @@ package org.jclouds.openstack.nova.ec2.compute; import org.jclouds.compute.domain.ExecResponse; import org.jclouds.compute.domain.NodeMetadata; +import org.jclouds.ec2.EC2AsyncClient; +import org.jclouds.ec2.EC2Client; +import org.jclouds.ec2.compute.EC2ComputeServiceContext; import org.jclouds.ec2.compute.EC2ComputeServiceLiveTest; import org.testng.annotations.Test; @@ -28,7 +31,7 @@ import org.testng.annotations.Test; * @author Adrian Cole */ @Test(groups = "live", singleThreaded = true, testName = "NovaEC2ComputeServiceLiveTest") -public class NovaEC2ComputeServiceLiveTest extends EC2ComputeServiceLiveTest { +public class NovaEC2ComputeServiceLiveTest extends EC2ComputeServiceLiveTest> { public NovaEC2ComputeServiceLiveTest() { provider = "openstack-nova-ec2"; diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/NovaApiMetadata.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/NovaApiMetadata.java index 3df8fa8925..578d6b929d 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/NovaApiMetadata.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/NovaApiMetadata.java @@ -1,58 +1,105 @@ +/** + * 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.openstack.nova.v1_1; +import static org.jclouds.openstack.keystone.v2_0.config.KeystoneProperties.SERVICE_TYPE; +import static org.jclouds.openstack.nova.v1_1.config.NovaProperties.AUTO_ALLOCATE_FLOATING_IPS; +import static org.jclouds.openstack.nova.v1_1.config.NovaProperties.AUTO_GENERATE_KEYPAIRS; +import static org.jclouds.openstack.nova.v1_1.config.NovaProperties.TIMEOUT_SECURITYGROUP_PRESENT; + import java.net.URI; +import java.util.Properties; import org.jclouds.apis.ApiMetadata; -import org.jclouds.apis.ApiType; -import org.jclouds.apis.BaseApiMetadata; +import org.jclouds.compute.ComputeServiceContext; +import org.jclouds.compute.internal.BaseComputeServiceApiMetadata; +import org.jclouds.openstack.keystone.v2_0.config.KeystoneProperties; +import org.jclouds.openstack.services.ServiceType; + +import com.google.common.reflect.TypeToken; /** - * Implementation of {@link ApiMetadata} for OpenStack Nova Diablo+ + * Implementation of {@link ApiMetadata} for Nova 1.0 API * * @author Adrian Cole */ -public class NovaApiMetadata extends BaseApiMetadata { +public class NovaApiMetadata + extends + BaseComputeServiceApiMetadata, NovaApiMetadata> { - public NovaApiMetadata() { - this(builder() - .id("openstack-nova") - .type(ApiType.COMPUTE) - .name("OpenStack Nova Diablo+ API") - .identityName("tenantId:user") - .credentialName("password") - .documentation(URI.create("http://api.openstack.org/"))); + @Override + public Builder toBuilder() { + return new Builder().fromApiMetadata(this); } + public NovaApiMetadata() { + this(new Builder()); + } - // below are so that we can reuse builders, toString, hashCode, etc. - // we have to set concrete classes here, as our base class cannot be - // concrete due to serviceLoader - protected NovaApiMetadata(NovaApiMetadataBuilder builder) { + protected NovaApiMetadata(Builder builder) { super(builder); } - public static class NovaApiMetadataBuilder> extends Builder { + protected static Properties defaultProperties() { + Properties properties = BaseComputeServiceApiMetadata.Builder.defaultProperties(); + // auth fail can happen while cloud-init applies keypair updates + properties.setProperty("jclouds.ssh.max-retries", "7"); + properties.setProperty("jclouds.ssh.retry-auth", "true"); + + properties.setProperty(SERVICE_TYPE, ServiceType.COMPUTE); + // TODO: this doesn't actually do anything yet. + properties.setProperty(KeystoneProperties.VERSION, "2.0"); + + properties.setProperty(AUTO_ALLOCATE_FLOATING_IPS, "false"); + properties.setProperty(AUTO_GENERATE_KEYPAIRS, "false"); + properties.setProperty(TIMEOUT_SECURITYGROUP_PRESENT, "500"); + return properties; + } + + public static class Builder + extends + BaseComputeServiceApiMetadata.Builder, NovaApiMetadata> { + + protected Builder() { + id("openstack-nova") + .name("OpenStack Nova Diablo+ API") + .identityName("tenantId:user") + .credentialName("password") + .documentation(URI.create("http://api.openstack.org/")) + .version("1.1") + .defaultEndpoint("http://localhost:5000") + .javaApi(NovaClient.class, NovaAsyncClient.class) + .defaultProperties(NovaApiMetadata.defaultProperties()) + .contextBuilder(TypeToken.of(NovaContextBuilder.class)); + } @Override public NovaApiMetadata build() { return new NovaApiMetadata(this); } - } - - private static class NovaConcreteBuilder extends NovaApiMetadataBuilder { @Override - public NovaApiMetadata build() { - return new NovaApiMetadata(this); + public Builder fromApiMetadata(NovaApiMetadata in) { + super.fromApiMetadata(in); + return this; } + } - private static NovaConcreteBuilder builder() { - return new NovaConcreteBuilder(); - } - - @Override - public NovaApiMetadataBuilder toBuilder() { - return builder().fromApiMetadata(this); - } } \ No newline at end of file diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/NovaContextBuilder.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/NovaContextBuilder.java index 08eb18e0a4..06be070cb8 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/NovaContextBuilder.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/NovaContextBuilder.java @@ -19,32 +19,39 @@ package org.jclouds.openstack.nova.v1_1; import java.util.List; -import java.util.Properties; +import org.jclouds.compute.ComputeServiceContext; import org.jclouds.compute.ComputeServiceContextBuilder; import org.jclouds.openstack.nova.v1_1.compute.config.NovaComputeServiceContextModule; import org.jclouds.openstack.nova.v1_1.config.NovaRestClientModule; +import org.jclouds.providers.ProviderMetadata; import com.google.inject.Module; /** - * A context builder for getting nova clients. * * @author Adrian Cole */ -public class NovaContextBuilder extends ComputeServiceContextBuilder { +public class NovaContextBuilder + extends + ComputeServiceContextBuilder, NovaApiMetadata> { - public NovaContextBuilder(Properties props) { - super(NovaClient.class, NovaAsyncClient.class, props); + public NovaContextBuilder( + ProviderMetadata, NovaApiMetadata> providerMetadata) { + super(providerMetadata); } - @Override - protected void addClientModule(List modules) { - modules.add(new NovaRestClientModule()); + public NovaContextBuilder(NovaApiMetadata apiMetadata) { + super(apiMetadata); } @Override protected void addContextModule(List modules) { modules.add(new NovaComputeServiceContextModule()); } -} + + protected void addClientModule(List modules) { + modules.add(new NovaRestClientModule()); + } + +} \ No newline at end of file diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/NovaPropertiesBuilder.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/NovaPropertiesBuilder.java deleted file mode 100644 index 5331a87cb9..0000000000 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/NovaPropertiesBuilder.java +++ /dev/null @@ -1,63 +0,0 @@ -/** - * 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.openstack.nova.v1_1; - -import static org.jclouds.Constants.PROPERTY_API_VERSION; -import static org.jclouds.Constants.PROPERTY_ENDPOINT; -import static org.jclouds.openstack.keystone.v2_0.config.KeystoneProperties.SERVICE_TYPE; -import static org.jclouds.openstack.nova.v1_1.config.NovaProperties.AUTO_ALLOCATE_FLOATING_IPS; -import static org.jclouds.openstack.nova.v1_1.config.NovaProperties.AUTO_GENERATE_KEYPAIRS; -import static org.jclouds.openstack.nova.v1_1.config.NovaProperties.TIMEOUT_SECURITYGROUP_PRESENT; - -import java.util.Properties; - -import org.jclouds.PropertiesBuilder; -import org.jclouds.openstack.keystone.v2_0.config.KeystoneProperties; -import org.jclouds.openstack.services.ServiceType; - -/** - * Builds properties used in Nova Clients - * - * @author Adrian Cole - */ -public class NovaPropertiesBuilder extends PropertiesBuilder { - @Override - protected Properties defaultProperties() { - Properties properties = super.defaultProperties(); - properties.setProperty(PROPERTY_ENDPOINT, "http://localhost:5000"); - properties.setProperty(PROPERTY_API_VERSION, "1.1"); - // auth fail can happen while cloud-init applies keypair updates - properties.setProperty("jclouds.ssh.max-retries", "7"); - properties.setProperty("jclouds.ssh.retry-auth", "true"); - - properties.setProperty(SERVICE_TYPE, ServiceType.COMPUTE); - // TODO: this doesn't actually do anything yet. - properties.setProperty(KeystoneProperties.VERSION, "2.0"); - - properties.setProperty(AUTO_ALLOCATE_FLOATING_IPS, "false"); - properties.setProperty(AUTO_GENERATE_KEYPAIRS, "false"); - properties.setProperty(TIMEOUT_SECURITYGROUP_PRESENT, "500"); - return properties; - } - - public NovaPropertiesBuilder(Properties properties) { - super(properties); - } - -} diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/compute/NovaComputeService.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/compute/NovaComputeService.java index bd799523ce..d3f56d941c 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/compute/NovaComputeService.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/compute/NovaComputeService.java @@ -86,7 +86,7 @@ public class NovaComputeService extends BaseComputeService { protected final GroupNamingConvention.Factory namingConvention; @Inject - protected NovaComputeService(ComputeServiceContext context, Map credentialStore, + protected NovaComputeService(@SuppressWarnings("rawtypes") ComputeServiceContext context, Map credentialStore, @Memoized Supplier> images, @Memoized Supplier> sizes, @Memoized Supplier> locations, ListNodesStrategy listNodesStrategy, GetNodeMetadataStrategy getNodeMetadataStrategy, CreateNodesInGroupThenAddToSet runNodesAndAddToSetStrategy, diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/NovaApiMetadataTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/NovaApiMetadataTest.java index 2057e42892..db3c3b2d1c 100644 --- a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/NovaApiMetadataTest.java +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/NovaApiMetadataTest.java @@ -1,7 +1,6 @@ package org.jclouds.openstack.nova.v1_1; -import org.jclouds.apis.ApiType; -import org.jclouds.apis.BaseApiMetadataTest; +import org.jclouds.compute.internal.BaseComputeServiceApiMetadataTest; import org.testng.annotations.Test; /** @@ -9,9 +8,9 @@ import org.testng.annotations.Test; * @author Adrian Cole */ @Test(groups = "unit", testName = "NovaApiMetadataTest") -public class NovaApiMetadataTest extends BaseApiMetadataTest { +public class NovaApiMetadataTest extends BaseComputeServiceApiMetadataTest { public NovaApiMetadataTest() { - super(new NovaApiMetadata(), ApiType.COMPUTE); + super(new NovaApiMetadata()); } } diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/compute/NovaComputeServiceAdapterExpectTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/compute/NovaComputeServiceAdapterExpectTest.java index 5ffe5deb98..e2072a77b3 100644 --- a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/compute/NovaComputeServiceAdapterExpectTest.java +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/compute/NovaComputeServiceAdapterExpectTest.java @@ -161,6 +161,7 @@ public class NovaComputeServiceAdapterExpectTest extends BaseNovaComputeServiceC assertNotNull(server); assertEquals(server.getCredentials(), LoginCredentials.builder().privateKey("privateKey").build()); } + @Override public Injector apply(ComputeServiceContext input) { return input.utils().injector(); diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/compute/NovaComputeServiceLiveTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/compute/NovaComputeServiceLiveTest.java index f0879a0003..683fb6b301 100644 --- a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/compute/NovaComputeServiceLiveTest.java +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/compute/NovaComputeServiceLiveTest.java @@ -1,6 +1,9 @@ package org.jclouds.openstack.nova.v1_1.compute; -import org.jclouds.compute.BaseComputeServiceLiveTest; +import org.jclouds.compute.ComputeServiceContext; +import org.jclouds.compute.internal.BaseComputeServiceLiveTest; +import org.jclouds.openstack.nova.v1_1.NovaAsyncClient; +import org.jclouds.openstack.nova.v1_1.NovaClient; import org.jclouds.sshj.config.SshjSshClientModule; import org.testng.annotations.Test; @@ -11,7 +14,8 @@ import com.google.inject.Module; * @author Adrian Cole */ @Test(groups = "live", singleThreaded = true, testName = "NovaComputeServiceLiveTest") -public class NovaComputeServiceLiveTest extends BaseComputeServiceLiveTest { +public class NovaComputeServiceLiveTest extends + BaseComputeServiceLiveTest> { public NovaComputeServiceLiveTest() { provider = "openstack-nova"; diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/extensions/FloatingIPClientLiveTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/extensions/FloatingIPClientLiveTest.java index 95c3c27ce4..1db260412f 100644 --- a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/extensions/FloatingIPClientLiveTest.java +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/extensions/FloatingIPClientLiveTest.java @@ -51,8 +51,8 @@ public class FloatingIPClientLiveTest extends BaseNovaClientLiveTest { @Test public void testListFloatingIPs() throws Exception { - for (String zoneId : context.getApi().getConfiguredZones()) { - Optional clientOption = context.getApi().getFloatingIPExtensionForZone(zoneId); + for (String zoneId : novaContext.getApi().getConfiguredZones()) { + Optional clientOption = novaContext.getApi().getFloatingIPExtensionForZone(zoneId); if (!clientOption.isPresent()) continue; FloatingIPClient client = clientOption.get(); @@ -73,8 +73,8 @@ public class FloatingIPClientLiveTest extends BaseNovaClientLiveTest { @Test public void testAllocateAndDeallocateFloatingIPs() throws Exception { - for (String zoneId : context.getApi().getConfiguredZones()) { - Optional clientOption = context.getApi().getFloatingIPExtensionForZone(zoneId); + for (String zoneId : novaContext.getApi().getConfiguredZones()) { + Optional clientOption = novaContext.getApi().getFloatingIPExtensionForZone(zoneId); if (!clientOption.isPresent()) continue; FloatingIPClient client = clientOption.get(); @@ -104,12 +104,12 @@ public class FloatingIPClientLiveTest extends BaseNovaClientLiveTest { @Test public void testAddAndRemoveFloatingIp() throws Exception { - for (String zoneId : context.getApi().getConfiguredZones()) { - Optional clientOption = context.getApi().getFloatingIPExtensionForZone(zoneId); + for (String zoneId : novaContext.getApi().getConfiguredZones()) { + Optional clientOption = novaContext.getApi().getFloatingIPExtensionForZone(zoneId); if (!clientOption.isPresent()) continue; FloatingIPClient client = clientOption.get(); - ServerClient serverClient = context.getApi().getServerClientForZone(zoneId); + ServerClient serverClient = novaContext.getApi().getServerClientForZone(zoneId); Server server = serverClient.createServer("test", imageIdForZone(zoneId), flavorRefForZone(zoneId)); blockUntilServerActive(server.getId(), serverClient); FloatingIP floatingIP = client.allocate(); @@ -125,12 +125,12 @@ public class FloatingIPClientLiveTest extends BaseNovaClientLiveTest { } private String imageIdForZone(String zoneId) { - ImageClient imageClient = context.getApi().getImageClientForZone(zoneId); + ImageClient imageClient = novaContext.getApi().getImageClientForZone(zoneId); return Iterables.getLast(imageClient.listImages()).getId(); } private String flavorRefForZone(String zoneId) { - FlavorClient flavorClient = context.getApi().getFlavorClientForZone(zoneId); + FlavorClient flavorClient = novaContext.getApi().getFlavorClientForZone(zoneId); return Iterables.getLast(flavorClient.listFlavors()).getId(); } diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/extensions/KeyPairClientLiveTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/extensions/KeyPairClientLiveTest.java index 1e28e5861f..62ce2e0860 100644 --- a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/extensions/KeyPairClientLiveTest.java +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/extensions/KeyPairClientLiveTest.java @@ -36,8 +36,8 @@ import org.testng.annotations.Test; public class KeyPairClientLiveTest extends BaseNovaClientLiveTest { public void testListKeyPairs() throws Exception { - for (String zoneId : context.getApi().getConfiguredZones()) { - KeyPairClient client = context.getApi().getKeyPairExtensionForZone(zoneId).get(); + for (String zoneId : novaContext.getApi().getConfiguredZones()) { + KeyPairClient client = novaContext.getApi().getKeyPairExtensionForZone(zoneId).get(); Set> keyPairsList = client.listKeyPairs(); assertNotNull(keyPairsList); } @@ -45,8 +45,8 @@ public class KeyPairClientLiveTest extends BaseNovaClientLiveTest { public void testCreateAndDeleteKeyPair() throws Exception { final String KEYPAIR_NAME = "testkp"; - for (String zoneId : context.getApi().getConfiguredZones()) { - KeyPairClient client = context.getApi().getKeyPairExtensionForZone(zoneId).get(); + for (String zoneId : novaContext.getApi().getConfiguredZones()) { + KeyPairClient client = novaContext.getApi().getKeyPairExtensionForZone(zoneId).get(); KeyPair keyPair = null; try { keyPair = client.createKeyPair(KEYPAIR_NAME); @@ -63,8 +63,8 @@ public class KeyPairClientLiveTest extends BaseNovaClientLiveTest { final String KEYPAIR_NAME = "testkp"; final String PUBLIC_KEY = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQCrrBREFxz3002l1HuXz0+UOdJQ/mOYD5DiJwwB/TOybwIKQJPOxJWA9gBoo4k9dthTKBTaEYbzrll7iZcp59E80S6mNiAr3mUgi+x5Y8uyXeJ2Ws+h6peVyFVUu9epkwpcTd1GVfdcVWsTajwDz9+lxCDhl0RZKDFoT0scTxbj/w== nova@nv-aw2az2-api0002"; - for (String zoneId : context.getApi().getConfiguredZones()) { - KeyPairClient client = context.getApi().getKeyPairExtensionForZone(zoneId).get(); + for (String zoneId : novaContext.getApi().getConfiguredZones()) { + KeyPairClient client = novaContext.getApi().getKeyPairExtensionForZone(zoneId).get(); KeyPair keyPair = null; try { keyPair = client.createKeyPairWithPublicKey(KEYPAIR_NAME, PUBLIC_KEY); diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/extensions/SecurityGroupClientLiveTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/extensions/SecurityGroupClientLiveTest.java index 52ea12ba14..a4572b27c5 100644 --- a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/extensions/SecurityGroupClientLiveTest.java +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/extensions/SecurityGroupClientLiveTest.java @@ -42,16 +42,16 @@ public class SecurityGroupClientLiveTest extends BaseNovaClientLiveTest { public static final String SECURITY_GROUP_NAME = "testsg"; public void listSecurityGroups() throws Exception { - for (String zoneId : context.getApi().getConfiguredZones()) { - SecurityGroupClient client = context.getApi().getSecurityGroupExtensionForZone(zoneId).get(); + for (String zoneId : novaContext.getApi().getConfiguredZones()) { + SecurityGroupClient client = novaContext.getApi().getSecurityGroupExtensionForZone(zoneId).get(); Set securityGroupsList = client.listSecurityGroups(); assertNotNull(securityGroupsList); } } public void createGetAndDeleteSecurityGroup() throws Exception { - for (String zoneId : context.getApi().getConfiguredZones()) { - SecurityGroupClient client = context.getApi().getSecurityGroupExtensionForZone(zoneId).get(); + for (String zoneId : novaContext.getApi().getConfiguredZones()) { + SecurityGroupClient client = novaContext.getApi().getSecurityGroupExtensionForZone(zoneId).get(); SecurityGroup securityGroup = null; String id; try { @@ -70,8 +70,8 @@ public class SecurityGroupClientLiveTest extends BaseNovaClientLiveTest { } public void createAndDeleteSecurityGroupRule() throws Exception { - for (String zoneId : context.getApi().getConfiguredZones()) { - SecurityGroupClient client = context.getApi().getSecurityGroupExtensionForZone(zoneId).get(); + for (String zoneId : novaContext.getApi().getConfiguredZones()) { + SecurityGroupClient client = novaContext.getApi().getSecurityGroupExtensionForZone(zoneId).get(); SecurityGroup securityGroup = null; try { diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/features/ExtensionClientLiveTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/features/ExtensionClientLiveTest.java index d56e4199bd..a581894986 100644 --- a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/features/ExtensionClientLiveTest.java +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/features/ExtensionClientLiveTest.java @@ -42,8 +42,8 @@ public class ExtensionClientLiveTest extends BaseNovaClientLiveTest { */ @Test public void testListExtensions() throws Exception { - for (String zoneId : context.getApi().getConfiguredZones()) { - ExtensionClient client = context.getApi().getExtensionClientForZone(zoneId); + for (String zoneId : novaContext.getApi().getConfiguredZones()) { + ExtensionClient client = novaContext.getApi().getExtensionClientForZone(zoneId); Set response = client.listExtensions(); assert null != response; assertTrue(response.size() >= 0); diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/features/FlavorClientLiveTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/features/FlavorClientLiveTest.java index 4a913fe4a1..02974c2849 100644 --- a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/features/FlavorClientLiveTest.java +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/features/FlavorClientLiveTest.java @@ -43,8 +43,8 @@ public class FlavorClientLiveTest extends BaseNovaClientLiveTest { */ @Test public void testListFlavors() throws Exception { - for (String zoneId : context.getApi().getConfiguredZones()) { - FlavorClient client = context.getApi().getFlavorClientForZone(zoneId); + for (String zoneId : novaContext.getApi().getConfiguredZones()) { + FlavorClient client = novaContext.getApi().getFlavorClientForZone(zoneId); Set response = client.listFlavors(); assert null != response; assertTrue(response.size() >= 0); @@ -64,8 +64,8 @@ public class FlavorClientLiveTest extends BaseNovaClientLiveTest { */ @Test public void testListFlavorsInDetail() throws Exception { - for (String zoneId : context.getApi().getConfiguredZones()) { - FlavorClient client = context.getApi().getFlavorClientForZone(zoneId); + for (String zoneId : novaContext.getApi().getConfiguredZones()) { + FlavorClient client = novaContext.getApi().getFlavorClientForZone(zoneId); Set response = client.listFlavorsInDetail(); assert null != response; assertTrue(response.size() >= 0); diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/features/ImageClientLiveTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/features/ImageClientLiveTest.java index 6fce20b5d4..23744fa8d2 100644 --- a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/features/ImageClientLiveTest.java +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/features/ImageClientLiveTest.java @@ -39,8 +39,8 @@ public class ImageClientLiveTest extends BaseNovaClientLiveTest { @Test public void testListImages() throws Exception { - for (String zoneId : context.getApi().getConfiguredZones()) { - ImageClient client = context.getApi().getImageClientForZone(zoneId); + for (String zoneId : novaContext.getApi().getConfiguredZones()) { + ImageClient client = novaContext.getApi().getImageClientForZone(zoneId); Set response = client.listImages(); assertNotNull(response); assertTrue(response.size() >= 0); @@ -56,8 +56,8 @@ public class ImageClientLiveTest extends BaseNovaClientLiveTest { @Test public void testListImagesInDetail() throws Exception { - for (String zoneId : context.getApi().getConfiguredZones()) { - ImageClient client = context.getApi().getImageClientForZone(zoneId); + for (String zoneId : novaContext.getApi().getConfiguredZones()) { + ImageClient client = novaContext.getApi().getImageClientForZone(zoneId); Set response = client.listImagesInDetail(); assertNotNull(response); assertTrue(response.size() >= 0); diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/features/ServerClientLiveTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/features/ServerClientLiveTest.java index 2ddf1e7acb..470b4ba54b 100644 --- a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/features/ServerClientLiveTest.java +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/features/ServerClientLiveTest.java @@ -38,8 +38,8 @@ public class ServerClientLiveTest extends BaseNovaClientLiveTest { @Test public void testListServersInDetail() throws Exception { - for (String zoneId : context.getApi().getConfiguredZones()) { - ServerClient client = context.getApi().getServerClientForZone(zoneId); + for (String zoneId : novaContext.getApi().getConfiguredZones()) { + ServerClient client = novaContext.getApi().getServerClientForZone(zoneId); Set response = client.listServers(); assert null != response; assertTrue(response.size() >= 0); diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/internal/BaseNovaAsyncClientExpectTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/internal/BaseNovaAsyncClientExpectTest.java index 00720cdce1..7509ae04e1 100644 --- a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/internal/BaseNovaAsyncClientExpectTest.java +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/internal/BaseNovaAsyncClientExpectTest.java @@ -18,20 +18,13 @@ */ package org.jclouds.openstack.nova.v1_1.internal; -import static org.jclouds.rest.RestContextFactory.createContext; - import java.util.Properties; import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpResponse; -import org.jclouds.logging.config.NullLoggingModule; import org.jclouds.openstack.nova.v1_1.NovaAsyncClient; -import org.jclouds.openstack.nova.v1_1.NovaClient; -import org.jclouds.rest.RestContextFactory; -import org.jclouds.rest.RestContextSpec; import com.google.common.base.Function; -import com.google.common.collect.ImmutableSet; import com.google.inject.Module; /** @@ -41,9 +34,6 @@ import com.google.inject.Module; */ public class BaseNovaAsyncClientExpectTest extends BaseNovaExpectTest { public NovaAsyncClient createClient(Function fn, Module module, Properties props) { - RestContextSpec contextSpec = new RestContextFactory(setupRestProperties()) - .createContextSpec(provider, identity, credential, new Properties()); - return createContext(contextSpec, - ImmutableSet. of(new ExpectModule(fn), new NullLoggingModule(), module), props).getAsyncApi(); + return createInjector(fn, module, props).getInstance(NovaAsyncClient.class); } } diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/internal/BaseNovaClientLiveTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/internal/BaseNovaClientLiveTest.java index 8ecfd8dcdb..3e6679ed37 100644 --- a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/internal/BaseNovaClientLiveTest.java +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/internal/BaseNovaClientLiveTest.java @@ -18,46 +18,42 @@ */ package org.jclouds.openstack.nova.v1_1.internal; -import java.util.Properties; - -import org.jclouds.compute.BaseVersionedServiceLiveTest; +import org.jclouds.compute.ComputeServiceContext; +import org.jclouds.compute.internal.BaseComputeServiceContextLiveTest; import org.jclouds.openstack.nova.v1_1.NovaAsyncClient; import org.jclouds.openstack.nova.v1_1.NovaClient; import org.jclouds.rest.RestContext; -import org.jclouds.rest.RestContextFactory; -import org.jclouds.sshj.config.SshjSshClientModule; import org.testng.annotations.AfterGroups; import org.testng.annotations.BeforeGroups; import org.testng.annotations.Test; -import com.google.common.collect.ImmutableSet; -import com.google.inject.Module; - /** * Tests behavior of {@code NovaClient} * * @author Adrian Cole */ @Test(groups = "live") -public class BaseNovaClientLiveTest extends BaseVersionedServiceLiveTest { +public class BaseNovaClientLiveTest + extends + BaseComputeServiceContextLiveTest> { + public BaseNovaClientLiveTest() { provider = "openstack-nova"; } - protected RestContext context; + protected RestContext novaContext; - @BeforeGroups(groups = { "live" }) - public void setupClient() { - setupCredentials(); - Properties overrides = setupProperties(); - context = new RestContextFactory().createContext(provider, identity, credential, - ImmutableSet. of(getLoggingModule(), new SshjSshClientModule()), overrides); + @BeforeGroups(groups = { "integration", "live" }) + @Override + public void setupContext() { + super.setupContext(); + novaContext = context.getProviderSpecificContext(); } @AfterGroups(groups = "live") protected void tearDown() { - if (context != null) - context.close(); + if (novaContext != null) + novaContext.close(); } } diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/internal/BaseNovaComputeServiceContextExpectTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/internal/BaseNovaComputeServiceContextExpectTest.java index aa730d3350..59f81af989 100644 --- a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/internal/BaseNovaComputeServiceContextExpectTest.java +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/internal/BaseNovaComputeServiceContextExpectTest.java @@ -23,12 +23,12 @@ import java.net.URI; import java.util.Properties; import java.util.concurrent.ConcurrentHashMap; +import org.jclouds.apis.ApiMetadata; import org.jclouds.compute.ComputeServiceContext; -import org.jclouds.compute.ComputeServiceContextFactory; import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpResponse; import org.jclouds.io.CopyInputStreamInputSupplierMap; -import org.jclouds.logging.config.NullLoggingModule; +import org.jclouds.openstack.nova.v1_1.NovaApiMetadata; import org.jclouds.rest.config.CredentialStoreModule; import com.google.common.base.Function; @@ -84,10 +84,20 @@ public abstract class BaseNovaComputeServiceContextExpectTest extends BaseNov private ComputeServiceContext createComputeServiceContext(Function fn, Module module, Properties props) { - // the following will wipe out credential store between tests - return new ComputeServiceContextFactory(setupRestProperties()).createContext(provider, identity, credential, - ImmutableSet. of(new ExpectModule(fn), new NullLoggingModule(), new CredentialStoreModule( - new CopyInputStreamInputSupplierMap(new ConcurrentHashMap>())), - module), props); + return createInjector(fn, module, props).getInstance(ComputeServiceContext.class); + } + + @Override + protected ApiMetadata createApiMetadata() { + return new NovaApiMetadata(); + } + + // isolate tests from eachother, as default credentialStore is static + protected Module credentialStoreModule = new CredentialStoreModule(new CopyInputStreamInputSupplierMap( + new ConcurrentHashMap>())); + + @Override + protected Module createModule() { + return credentialStoreModule; } } diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/internal/BaseNovaComputeServiceExpectTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/internal/BaseNovaComputeServiceExpectTest.java index 15f68e6afa..d79e19dc45 100644 --- a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/internal/BaseNovaComputeServiceExpectTest.java +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/internal/BaseNovaComputeServiceExpectTest.java @@ -30,7 +30,7 @@ import org.jclouds.compute.ComputeServiceContext; public class BaseNovaComputeServiceExpectTest extends BaseNovaComputeServiceContextExpectTest { @Override - public ComputeService apply(ComputeServiceContext input) { + public ComputeService apply(@SuppressWarnings("rawtypes") ComputeServiceContext input) { return input.getComputeService(); } diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/internal/BaseNovaExpectTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/internal/BaseNovaExpectTest.java index 2b38d4cd7e..c311dbcbe0 100644 --- a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/internal/BaseNovaExpectTest.java +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/internal/BaseNovaExpectTest.java @@ -23,7 +23,7 @@ import java.net.URI; import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpResponse; import org.jclouds.openstack.keystone.v2_0.internal.KeystoneFixture; -import org.jclouds.rest.BaseRestClientExpectTest; +import org.jclouds.rest.internal.BaseRestClientExpectTest; import com.google.common.collect.ImmutableMultimap; diff --git a/apis/s3/pom.xml b/apis/s3/pom.xml index 4a29312792..ba491d8531 100644 --- a/apis/s3/pom.xml +++ b/apis/s3/pom.xml @@ -34,7 +34,6 @@ bundle - org.jclouds.s3.blobstore.integration.S3TestInitializer https://s3.amazonaws.com 2006-03-01 @@ -105,7 +104,6 @@ - ${test.initializer} ${jclouds.blobstore.httpstream.url} ${jclouds.blobstore.httpstream.md5} ${test.s3.endpoint} diff --git a/apis/s3/src/main/java/org/jclouds/s3/S3ApiMetadata.java b/apis/s3/src/main/java/org/jclouds/s3/S3ApiMetadata.java index d6a30143a1..45b84df2e6 100644 --- a/apis/s3/src/main/java/org/jclouds/s3/S3ApiMetadata.java +++ b/apis/s3/src/main/java/org/jclouds/s3/S3ApiMetadata.java @@ -18,58 +18,115 @@ */ package org.jclouds.s3; +import static org.jclouds.Constants.PROPERTY_API_VERSION; +import static org.jclouds.Constants.PROPERTY_RELAX_HOSTNAME; +import static org.jclouds.aws.reference.AWSConstants.PROPERTY_AUTH_TAG; +import static org.jclouds.aws.reference.AWSConstants.PROPERTY_HEADER_TAG; +import static org.jclouds.blobstore.reference.BlobStoreConstants.DIRECTORY_SUFFIX_FOLDER; +import static org.jclouds.blobstore.reference.BlobStoreConstants.PROPERTY_BLOBSTORE_DIRECTORY_SUFFIX; +import static org.jclouds.blobstore.reference.BlobStoreConstants.PROPERTY_USER_METADATA_PREFIX; +import static org.jclouds.s3.reference.S3Constants.PROPERTY_S3_SERVICE_PATH; +import static org.jclouds.s3.reference.S3Constants.PROPERTY_S3_VIRTUAL_HOST_BUCKETS; + import java.net.URI; +import java.util.Properties; import org.jclouds.apis.ApiMetadata; -import org.jclouds.apis.ApiType; -import org.jclouds.apis.BaseApiMetadata; +import org.jclouds.blobstore.internal.BaseBlobStoreApiMetadata; +import org.jclouds.s3.blobstore.S3BlobStoreContext; +import org.jclouds.s3.reference.S3Headers; + +import com.google.common.reflect.TypeParameter; +import com.google.common.reflect.TypeToken; /** * Implementation of {@link ApiMetadata} for Amazon's S3 api. * + *

note

+ *

+ * This class allows overriding of types {@code S}(client) and {@code A} + * (asyncClient), so that children can add additional methods not declared here, + * such as new features from AWS. + *

+ * + * As this is a popular api, we also allow overrides for type {@code C} + * (context). This allows subtypes to add in new feature groups or extensions, + * not present in the base api. For example, you could make a subtype for + * context, that exposes admin operations. + * * @author Adrian Cole */ -public class S3ApiMetadata extends BaseApiMetadata { +public class S3ApiMetadata, M extends S3ApiMetadata> + extends BaseBlobStoreApiMetadata { - public S3ApiMetadata() { - this(builder() - .id("s3") - .type(ApiType.BLOBSTORE) - .name("Amazon Simple Storage Service (S3) API") - .identityName("Access Key ID") - .credentialName("Secret Access Key") - .documentation(URI.create("http://docs.amazonwebservices.com/AmazonS3/latest/API"))); + @SuppressWarnings({ "unchecked", "rawtypes" }) + @Override + public Builder toBuilder() { + return (Builder) new Builder(getApi(), getAsyncApi()).fromApiMetadata(this); } - // below are so that we can reuse builders, toString, hashCode, etc. - // we have to set concrete classes here, as our base class cannot be - // concrete due to serviceLoader - protected S3ApiMetadata(S3ApiMetadataBuilder builder) { + @SuppressWarnings({ "unchecked", "rawtypes" }) + public S3ApiMetadata() { + this(new Builder(S3Client.class, S3AsyncClient.class)); + } + + protected S3ApiMetadata(Builder builder) { super(builder); } + + protected static Properties defaultProperties() { + Properties properties = BaseBlobStoreApiMetadata.Builder.defaultProperties(); + properties.setProperty(PROPERTY_API_VERSION, S3AsyncClient.VERSION); + properties.setProperty(PROPERTY_AUTH_TAG, "AWS"); + properties.setProperty(PROPERTY_HEADER_TAG, S3Headers.DEFAULT_AMAZON_HEADERTAG); + properties.setProperty(PROPERTY_S3_SERVICE_PATH, "/"); + properties.setProperty(PROPERTY_S3_VIRTUAL_HOST_BUCKETS, "true"); + properties.setProperty(PROPERTY_RELAX_HOSTNAME, "true"); + properties.setProperty(PROPERTY_BLOBSTORE_DIRECTORY_SUFFIX, DIRECTORY_SUFFIX_FOLDER); + properties.setProperty(PROPERTY_USER_METADATA_PREFIX, String.format("x-${%s}-meta-", PROPERTY_HEADER_TAG)); + return properties; + } - public static class S3ApiMetadataBuilder> extends Builder { + public static class Builder, M extends S3ApiMetadata> extends BaseBlobStoreApiMetadata.Builder { + protected Builder(Class syncClient, Class asyncClient){ + id("s3") + .name("Amazon Simple Storage Service (S3) API") + .identityName("Access Key ID") + .credentialName("Secret Access Key") + .defaultEndpoint("https://s3.amazonaws.com") + .documentation(URI.create("http://docs.amazonwebservices.com/AmazonS3/latest/API")) + .version(S3AsyncClient.VERSION) + .defaultProperties(S3ApiMetadata.defaultProperties()) + .javaApi(syncClient, asyncClient) + .contextBuilder(new TypeToken>(getClass()){ + private static final long serialVersionUID = 1L; + }); + } + + /** + * {@inheritDoc} + */ @Override - public S3ApiMetadata build() { - return new S3ApiMetadata(this); + @SuppressWarnings("rawtypes") + protected TypeToken contextToken(TypeToken clientToken, TypeToken asyncClientToken) { + return new TypeToken>() { + private static final long serialVersionUID = 1L; + }.where(new TypeParameter() { + }, clientToken).where(new TypeParameter() { + }, asyncClientToken); + } + @SuppressWarnings({ "rawtypes", "unchecked" }) + @Override + public M build() { + return (M) new S3ApiMetadata(this); + } + + @Override + public Builder fromApiMetadata(M in) { + super.fromApiMetadata(in); + return this; } } - private static class S3ConcreteBuilder extends S3ApiMetadataBuilder { - - @Override - public S3ApiMetadata build() { - return new S3ApiMetadata(this); - } - } - - private static S3ConcreteBuilder builder() { - return new S3ConcreteBuilder(); - } - - @Override - public S3ApiMetadataBuilder toBuilder() { - return builder().fromApiMetadata(this); - } } \ No newline at end of file diff --git a/apis/s3/src/main/java/org/jclouds/s3/S3ContextBuilder.java b/apis/s3/src/main/java/org/jclouds/s3/S3ContextBuilder.java index 64ccf6cec2..8c011628d1 100644 --- a/apis/s3/src/main/java/org/jclouds/s3/S3ContextBuilder.java +++ b/apis/s3/src/main/java/org/jclouds/s3/S3ContextBuilder.java @@ -19,11 +19,12 @@ package org.jclouds.s3; import java.util.List; -import java.util.Properties; import org.jclouds.blobstore.BlobStoreContextBuilder; import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule; import org.jclouds.logging.jdk.config.JDKLoggingModule; +import org.jclouds.providers.ProviderMetadata; +import org.jclouds.s3.blobstore.S3BlobStoreContext; import org.jclouds.s3.blobstore.config.S3BlobStoreContextModule; import org.jclouds.s3.config.S3RestClientModule; @@ -43,10 +44,15 @@ import com.google.inject.Module; * @author Adrian Cole, Andrew Newdigate * @see S3Context */ -public class S3ContextBuilder extends BlobStoreContextBuilder { +public class S3ContextBuilder, M extends S3ApiMetadata> + extends BlobStoreContextBuilder { - public S3ContextBuilder(Properties props) { - super(S3Client.class, S3AsyncClient.class, props); + public S3ContextBuilder(ProviderMetadata providerMetadata) { + super(providerMetadata); + } + + public S3ContextBuilder(M apiMetadata) { + super(apiMetadata); } @Override diff --git a/apis/s3/src/main/java/org/jclouds/s3/S3PropertiesBuilder.java b/apis/s3/src/main/java/org/jclouds/s3/S3PropertiesBuilder.java deleted file mode 100644 index e2158f769d..0000000000 --- a/apis/s3/src/main/java/org/jclouds/s3/S3PropertiesBuilder.java +++ /dev/null @@ -1,64 +0,0 @@ -/** - * 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.s3; - -import static org.jclouds.Constants.PROPERTY_API_VERSION; -import static org.jclouds.Constants.PROPERTY_RELAX_HOSTNAME; -import static org.jclouds.aws.reference.AWSConstants.PROPERTY_AUTH_TAG; -import static org.jclouds.aws.reference.AWSConstants.PROPERTY_HEADER_TAG; -import static org.jclouds.blobstore.reference.BlobStoreConstants.DIRECTORY_SUFFIX_FOLDER; -import static org.jclouds.blobstore.reference.BlobStoreConstants.PROPERTY_BLOBSTORE_DIRECTORY_SUFFIX; -import static org.jclouds.blobstore.reference.BlobStoreConstants.PROPERTY_USER_METADATA_PREFIX; -import static org.jclouds.s3.reference.S3Constants.PROPERTY_S3_SERVICE_PATH; -import static org.jclouds.s3.reference.S3Constants.PROPERTY_S3_VIRTUAL_HOST_BUCKETS; - -import java.util.Properties; - -import org.jclouds.PropertiesBuilder; -import org.jclouds.s3.reference.S3Headers; - -/** - * Builds properties used in S3 Connections - * - * @author Adrian Cole - */ -public class S3PropertiesBuilder extends PropertiesBuilder { - @Override - protected Properties defaultProperties() { - Properties properties = super.defaultProperties(); - properties.setProperty(PROPERTY_API_VERSION, S3AsyncClient.VERSION); - properties.setProperty(PROPERTY_AUTH_TAG, "AWS"); - properties.setProperty(PROPERTY_HEADER_TAG, S3Headers.DEFAULT_AMAZON_HEADERTAG); - properties.setProperty(PROPERTY_S3_SERVICE_PATH, "/"); - properties.setProperty(PROPERTY_S3_VIRTUAL_HOST_BUCKETS, "true"); - properties.setProperty(PROPERTY_RELAX_HOSTNAME, "true"); - properties.setProperty(PROPERTY_BLOBSTORE_DIRECTORY_SUFFIX, DIRECTORY_SUFFIX_FOLDER); - properties.setProperty(PROPERTY_USER_METADATA_PREFIX, String.format("x-${%s}-meta-", PROPERTY_HEADER_TAG)); - return properties; - } - - public S3PropertiesBuilder(Properties properties) { - super(properties); - } - - public S3PropertiesBuilder() { - super(); - } - -} diff --git a/apis/s3/src/main/java/org/jclouds/s3/blobstore/S3AsyncBlobStore.java b/apis/s3/src/main/java/org/jclouds/s3/blobstore/S3AsyncBlobStore.java index 3bded56016..0bd44b881c 100644 --- a/apis/s3/src/main/java/org/jclouds/s3/blobstore/S3AsyncBlobStore.java +++ b/apis/s3/src/main/java/org/jclouds/s3/blobstore/S3AsyncBlobStore.java @@ -93,7 +93,7 @@ public class S3AsyncBlobStore extends BaseAsyncBlobStore { private final LoadingCache bucketAcls; @Inject - protected S3AsyncBlobStore(BlobStoreContext context, BlobUtils blobUtils, + protected S3AsyncBlobStore(@SuppressWarnings("rawtypes") BlobStoreContext context, BlobUtils blobUtils, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService service, Supplier defaultLocation, @Memoized Supplier> locations, S3AsyncClient async, S3Client sync, BucketToResourceMetadata bucket2ResourceMd, ContainerToBucketListOptions container2BucketListOptions, diff --git a/apis/s3/src/main/java/org/jclouds/s3/blobstore/S3BlobStore.java b/apis/s3/src/main/java/org/jclouds/s3/blobstore/S3BlobStore.java index 3c75d3d3c2..2e2104879b 100644 --- a/apis/s3/src/main/java/org/jclouds/s3/blobstore/S3BlobStore.java +++ b/apis/s3/src/main/java/org/jclouds/s3/blobstore/S3BlobStore.java @@ -84,7 +84,7 @@ public class S3BlobStore extends BaseBlobStore { private final LoadingCache bucketAcls; @Inject - protected S3BlobStore(BlobStoreContext context, BlobUtils blobUtils, Supplier defaultLocation, + protected S3BlobStore(@SuppressWarnings("rawtypes") BlobStoreContext context, BlobUtils blobUtils, Supplier defaultLocation, @Memoized Supplier> locations, S3Client sync, BucketToResourceMetadata bucket2ResourceMd, ContainerToBucketListOptions container2BucketListOptions, BucketToResourceList bucket2ResourceList, ObjectToBlob object2Blob, diff --git a/blobstore/src/test/java/org/jclouds/blobstore/integration/TransientBlobStoreTestInitializer.java b/apis/s3/src/main/java/org/jclouds/s3/blobstore/S3BlobStoreContext.java similarity index 64% rename from blobstore/src/test/java/org/jclouds/blobstore/integration/TransientBlobStoreTestInitializer.java rename to apis/s3/src/main/java/org/jclouds/s3/blobstore/S3BlobStoreContext.java index 201287fa9b..58e8b1fec6 100644 --- a/blobstore/src/test/java/org/jclouds/blobstore/integration/TransientBlobStoreTestInitializer.java +++ b/apis/s3/src/main/java/org/jclouds/s3/blobstore/S3BlobStoreContext.java @@ -16,26 +16,24 @@ * specific language governing permissions and limitations * under the License. */ -package org.jclouds.blobstore.integration; - -import java.io.IOException; +package org.jclouds.s3.blobstore; import org.jclouds.blobstore.BlobStoreContext; -import org.jclouds.blobstore.integration.internal.BaseTestInitializer; +import org.jclouds.s3.S3AsyncClient; +import org.jclouds.s3.S3Client; +import org.jclouds.s3.blobstore.internal.S3BlobStoreContextImpl; -import com.google.inject.Module; +import com.google.inject.ImplementedBy; /** - * * @author Adrian Cole */ -public class TransientBlobStoreTestInitializer extends BaseTestInitializer { +@ImplementedBy(S3BlobStoreContextImpl.class) +public interface S3BlobStoreContext extends BlobStoreContext { @Override - protected BlobStoreContext createLiveContext(Module configurationModule, String url, String apiVersion,String buildVersion, String app, - String identity, String key) throws IOException { - return createStubContext(); - } - + S3BlobStore getBlobStore(); + @Override + S3AsyncBlobStore getAsyncBlobStore(); } diff --git a/apis/s3/src/main/java/org/jclouds/s3/blobstore/internal/S3BlobStoreContextImpl.java b/apis/s3/src/main/java/org/jclouds/s3/blobstore/internal/S3BlobStoreContextImpl.java new file mode 100644 index 0000000000..92f9066a67 --- /dev/null +++ b/apis/s3/src/main/java/org/jclouds/s3/blobstore/internal/S3BlobStoreContextImpl.java @@ -0,0 +1,61 @@ +/** + * 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.s3.blobstore.internal; + +import javax.inject.Inject; +import javax.inject.Singleton; + +import org.jclouds.blobstore.BlobMap; +import org.jclouds.blobstore.BlobRequestSigner; +import org.jclouds.blobstore.InputStreamMap; +import org.jclouds.blobstore.attr.ConsistencyModel; +import org.jclouds.blobstore.internal.BlobStoreContextImpl; +import org.jclouds.rest.RestContext; +import org.jclouds.rest.Utils; +import org.jclouds.s3.S3AsyncClient; +import org.jclouds.s3.S3Client; +import org.jclouds.s3.blobstore.S3AsyncBlobStore; +import org.jclouds.s3.blobstore.S3BlobStore; +import org.jclouds.s3.blobstore.S3BlobStoreContext; + +/** + * @author Adrian Cole + */ +@Singleton +public class S3BlobStoreContextImpl extends + BlobStoreContextImpl implements S3BlobStoreContext { + + @Inject + public S3BlobStoreContextImpl(BlobMap.Factory blobMapFactory, Utils utils, ConsistencyModel consistencyModel, + InputStreamMap.Factory inputStreamMapFactory, S3AsyncBlobStore ablobStore, S3BlobStore blobStore, + @SuppressWarnings("rawtypes") RestContext providerSpecificContext, BlobRequestSigner blobRequestSigner) { + super(blobMapFactory, utils, consistencyModel, inputStreamMapFactory, ablobStore, blobStore, providerSpecificContext, blobRequestSigner); + } + + @Override + public S3BlobStore getBlobStore() { + return S3BlobStore.class.cast(super.getBlobStore()); + } + + @Override + public S3AsyncBlobStore getAsyncBlobStore() { + return S3AsyncBlobStore.class.cast(super.getAsyncBlobStore()); + } + +} diff --git a/apis/s3/src/test/java/org/jclouds/s3/S3ApiMetadataTest.java b/apis/s3/src/test/java/org/jclouds/s3/S3ApiMetadataTest.java index b18deec218..8445d01a19 100644 --- a/apis/s3/src/test/java/org/jclouds/s3/S3ApiMetadataTest.java +++ b/apis/s3/src/test/java/org/jclouds/s3/S3ApiMetadataTest.java @@ -18,18 +18,18 @@ */ package org.jclouds.s3; -import org.jclouds.apis.ApiType; -import org.jclouds.apis.BaseApiMetadataTest; +import org.jclouds.blobstore.internal.BaseBlobStoreApiMetadataTest; import org.testng.annotations.Test; /** * * @author Adrian Cole */ +@SuppressWarnings("rawtypes") @Test(groups = "unit", testName = "S3ApiMetadataTest") -public class S3ApiMetadataTest extends BaseApiMetadataTest { +public class S3ApiMetadataTest extends BaseBlobStoreApiMetadataTest { public S3ApiMetadataTest() { - super(new S3ApiMetadata(), ApiType.BLOBSTORE); + super(new S3ApiMetadata()); } } diff --git a/apis/s3/src/test/java/org/jclouds/s3/S3ClientLiveTest.java b/apis/s3/src/test/java/org/jclouds/s3/S3ClientLiveTest.java index 0fed98817b..c5ee33c702 100644 --- a/apis/s3/src/test/java/org/jclouds/s3/S3ClientLiveTest.java +++ b/apis/s3/src/test/java/org/jclouds/s3/S3ClientLiveTest.java @@ -62,6 +62,10 @@ import com.google.common.collect.Maps; */ @Test(groups = { "integration", "live" }) public class S3ClientLiveTest extends BaseBlobStoreIntegrationTest { + public S3ClientLiveTest() { + this.provider = "s3"; + } + public S3Client getApi() { return (S3Client) context.getProviderSpecificContext().getApi(); } diff --git a/apis/s3/src/test/java/org/jclouds/s3/binders/BindAsHostPrefixIfConfiguredTest.java b/apis/s3/src/test/java/org/jclouds/s3/binders/BindAsHostPrefixIfConfiguredTest.java index 489b3bc09f..10e45102f4 100644 --- a/apis/s3/src/test/java/org/jclouds/s3/binders/BindAsHostPrefixIfConfiguredTest.java +++ b/apis/s3/src/test/java/org/jclouds/s3/binders/BindAsHostPrefixIfConfiguredTest.java @@ -45,9 +45,6 @@ import com.google.inject.TypeLiteral; @Test(groups = "unit", testName = "BindAsHostPrefixIfConfiguredTest") public class BindAsHostPrefixIfConfiguredTest extends BaseS3AsyncClientTest { - public BindAsHostPrefixIfConfiguredTest(){ - endpoint = "http://euc/services/Walrus"; - } @Override protected TypeLiteral> createTypeLiteral() { return new TypeLiteral>() { @@ -98,6 +95,7 @@ public class BindAsHostPrefixIfConfiguredTest extends BaseS3AsyncClientTest extends RestClientTest { +public abstract class BaseS3AsyncClientTest extends BaseAsyncClientTest { protected BlobToObject blobToS3Object; protected RequestAuthorizeSignature filter; @@ -67,18 +60,10 @@ public abstract class BaseS3AsyncClientTest extends Res super(); } - protected String provider = "s3"; - protected String endpoint = "https://s3.amazonaws.com"; - - /** - * this is only here as "s3" is not in rest.properties - */ - @SuppressWarnings({ "unchecked", "rawtypes" }) + @SuppressWarnings({ "rawtypes", "unchecked" }) @Override - public RestContextSpec createContextSpec() { - return RestContextFactory. contextSpec(provider, endpoint, - S3AsyncClient.VERSION, "", "", "identity", "credential", S3Client.class, S3AsyncClient.class, - (Class) S3PropertiesBuilder.class, (Class) S3ContextBuilder.class, ImmutableSet. of()); + public S3ApiMetadata createApiMetadata() { + return new S3ApiMetadata(); } } diff --git a/apis/s3/src/test/java/org/jclouds/s3/internal/BaseS3ClientExpectTest.java b/apis/s3/src/test/java/org/jclouds/s3/internal/BaseS3ClientExpectTest.java index 57318b55d6..c759c546ff 100644 --- a/apis/s3/src/test/java/org/jclouds/s3/internal/BaseS3ClientExpectTest.java +++ b/apis/s3/src/test/java/org/jclouds/s3/internal/BaseS3ClientExpectTest.java @@ -18,16 +18,13 @@ */ package org.jclouds.s3.internal; -import java.util.Properties; - import org.jclouds.date.TimeStamp; import org.jclouds.http.RequiresHttp; -import org.jclouds.rest.BaseRestClientExpectTest; import org.jclouds.rest.ConfiguresRestClient; +import org.jclouds.rest.internal.BaseRestClientExpectTest; +import org.jclouds.s3.S3ApiMetadata; import org.jclouds.s3.S3AsyncClient; import org.jclouds.s3.S3Client; -import org.jclouds.s3.S3ContextBuilder; -import org.jclouds.s3.S3PropertiesBuilder; import org.jclouds.s3.config.S3RestClientModule; import com.google.common.base.Supplier; @@ -41,19 +38,6 @@ public abstract class BaseS3ClientExpectTest extends BaseRestClientExpectTest { @@ -72,4 +56,11 @@ public abstract class BaseS3ClientExpectTest extends BaseRestClientExpectTestbundle - org.jclouds.openstack.swift.blobstore.integration.SwiftTestInitializer http://localhost:11000 1.0 @@ -105,7 +104,6 @@ - ${test.initializer} ${jclouds.blobstore.httpstream.url} ${jclouds.blobstore.httpstream.md5} ${test.swift.endpoint} diff --git a/apis/swift/src/main/java/org/jclouds/openstack/swift/SwiftApiMetadata.java b/apis/swift/src/main/java/org/jclouds/openstack/swift/SwiftApiMetadata.java index 665b84e9f6..4c26352ab1 100644 --- a/apis/swift/src/main/java/org/jclouds/openstack/swift/SwiftApiMetadata.java +++ b/apis/swift/src/main/java/org/jclouds/openstack/swift/SwiftApiMetadata.java @@ -1,49 +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.openstack.swift; +import static org.jclouds.blobstore.reference.BlobStoreConstants.PROPERTY_USER_METADATA_PREFIX; +import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGIONS; + import java.net.URI; +import java.util.Properties; import org.jclouds.apis.ApiMetadata; import org.jclouds.apis.ApiType; -import org.jclouds.apis.BaseApiMetadata; +import org.jclouds.blobstore.BlobStoreContext; +import org.jclouds.blobstore.internal.BaseBlobStoreApiMetadata; +import org.jclouds.openstack.OpenStackAuthAsyncClient; + +import com.google.common.reflect.TypeToken; /** - * Implementation of {@link ApiMetadata} for OpenStack Swift Pre-Diablo + * Implementation of {@link ApiMetadata} for Rackspace Cloud Files API * * @author Adrian Cole */ -public class SwiftApiMetadata extends BaseApiMetadata { - - public SwiftApiMetadata() { - this(builder() - .id("swift") - .type(ApiType.BLOBSTORE) - .name("OpenStack Swift Pre-Diablo API") - .identityName("tenantId:user") - .credentialName("password") - .documentation(URI.create("http://api.openstack.org/"))); +public class SwiftApiMetadata + extends + BaseBlobStoreApiMetadata, SwiftApiMetadata> { + private static Builder builder() { + return new Builder(); } - // below are so that we can reuse builders, toString, hashCode, etc. - // we have to set concrete classes here, as our base class cannot be - // concrete due to serviceLoader - protected SwiftApiMetadata(ConcreteBuilder builder) { + @Override + public Builder toBuilder() { + return builder().fromApiMetadata(this); + } + + public SwiftApiMetadata() { + this(builder()); + } + + protected SwiftApiMetadata(Builder builder) { super(builder); } - private static class ConcreteBuilder extends Builder { + protected static Properties defaultProperties() { + Properties properties = BaseBlobStoreApiMetadata.Builder.defaultProperties(); + properties.setProperty(PROPERTY_REGIONS, "DEFAULT"); + properties.setProperty(PROPERTY_USER_METADATA_PREFIX, "X-Object-Meta-"); + return properties; + } + + public static class Builder + extends + BaseBlobStoreApiMetadata.Builder, SwiftApiMetadata> { + protected Builder() { + id("swift") + .type(ApiType.BLOBSTORE) + .name("OpenStack Swift Pre-Diablo API") + .identityName("tenantId:user") + .credentialName("password") + .documentation(URI.create("http://api.openstack.org/")) + .version(OpenStackAuthAsyncClient.VERSION) + .contextBuilder(TypeToken.of(SwiftContextBuilder.class)) + .defaultProperties(SwiftApiMetadata.defaultProperties()) + .javaApi(SwiftClient.class, SwiftAsyncClient.class); + } @Override public SwiftApiMetadata build() { return new SwiftApiMetadata(this); } - } - public static ConcreteBuilder builder() { - return new ConcreteBuilder(); - } - - @Override - public ConcreteBuilder toBuilder() { - return builder().fromApiMetadata(this); + @Override + public Builder fromApiMetadata(SwiftApiMetadata in) { + super.fromApiMetadata(in); + return this; + } } } \ No newline at end of file diff --git a/apis/swift/src/main/java/org/jclouds/openstack/swift/SwiftContextBuilder.java b/apis/swift/src/main/java/org/jclouds/openstack/swift/SwiftContextBuilder.java index bdca5d130b..a64a01c24a 100644 --- a/apis/swift/src/main/java/org/jclouds/openstack/swift/SwiftContextBuilder.java +++ b/apis/swift/src/main/java/org/jclouds/openstack/swift/SwiftContextBuilder.java @@ -19,34 +19,45 @@ package org.jclouds.openstack.swift; import java.util.List; -import java.util.Properties; +import org.jclouds.blobstore.BlobStoreContext; import org.jclouds.blobstore.BlobStoreContextBuilder; import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule; import org.jclouds.logging.jdk.config.JDKLoggingModule; import org.jclouds.openstack.swift.blobstore.config.SwiftBlobStoreContextModule; import org.jclouds.openstack.swift.config.SwiftRestClientModule; +import org.jclouds.providers.ProviderMetadata; import com.google.inject.Injector; import com.google.inject.Module; /** - * Creates {@link CloudFilesBlobStoreContext} or {@link Injector} instances based on the most - * commonly requested arguments. + * Creates {@link SwiftStoreContext} or {@link Injector} instances based on + * the most commonly requested arguments. *

- * Note that Threadsafe objects will be bound as singletons to the Injector or Context provided. + * Note that Threadsafe objects will be bound as singletons to the Injector or + * Context provided. *

*

- * If no Modules are specified, the default {@link JDKLoggingModule logging} and - * {@link JavaUrlHttpCommandExecutorServiceModule http transports} will be installed. + * If no Modules are specified, the default + * {@link JDKLoggingModule logging} and + * {@link JavaUrlHttpCommandExecutorServiceModule http transports} will be + * installed. * * @author Adrian Cole, Andrew Newdigate - * @see CloudFilesBlobStoreContext + * @see SwiftStoreContext */ -public class SwiftContextBuilder extends BlobStoreContextBuilder { +public class SwiftContextBuilder + extends + BlobStoreContextBuilder, SwiftApiMetadata> { - public SwiftContextBuilder(Properties props) { - super(SwiftClient.class, SwiftAsyncClient.class, props); + public SwiftContextBuilder( + ProviderMetadata, SwiftApiMetadata> providerMetadata) { + super(providerMetadata); + } + + public SwiftContextBuilder(SwiftApiMetadata apiMetadata) { + super(apiMetadata); } @Override @@ -58,4 +69,4 @@ public class SwiftContextBuilder extends BlobStoreContextBuilder modules) { modules.add(new SwiftRestClientModule()); } -} +} \ No newline at end of file diff --git a/apis/swift/src/main/java/org/jclouds/openstack/swift/SwiftPropertiesBuilder.java b/apis/swift/src/main/java/org/jclouds/openstack/swift/SwiftPropertiesBuilder.java deleted file mode 100644 index 02c1cb981c..0000000000 --- a/apis/swift/src/main/java/org/jclouds/openstack/swift/SwiftPropertiesBuilder.java +++ /dev/null @@ -1,53 +0,0 @@ -/** - * 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.openstack.swift; - -import static org.jclouds.Constants.PROPERTY_API_VERSION; -import static org.jclouds.blobstore.reference.BlobStoreConstants.PROPERTY_USER_METADATA_PREFIX; -import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGIONS; - -import java.util.Properties; - -import org.jclouds.PropertiesBuilder; -import org.jclouds.openstack.OpenStackAuthAsyncClient; - -/** - * Builds properties used in CloudFiles Connections - * - * @author Adrian Cole - */ -public class SwiftPropertiesBuilder extends PropertiesBuilder { - @Override - protected Properties defaultProperties() { - Properties properties = super.defaultProperties(); - properties.setProperty(PROPERTY_REGIONS, "DEFAULT"); - properties.setProperty(PROPERTY_USER_METADATA_PREFIX, "X-Object-Meta-"); - properties.setProperty(PROPERTY_API_VERSION, OpenStackAuthAsyncClient.VERSION); - return properties; - } - - public SwiftPropertiesBuilder(Properties properties) { - super(properties); - } - - protected SwiftPropertiesBuilder withMetaPrefix(String prefix) { - properties.setProperty(PROPERTY_USER_METADATA_PREFIX, prefix); - return this; - } -} diff --git a/apis/swift/src/main/java/org/jclouds/openstack/swift/blobstore/SwiftAsyncBlobStore.java b/apis/swift/src/main/java/org/jclouds/openstack/swift/blobstore/SwiftAsyncBlobStore.java index b0873c9af6..ec12eec9ec 100644 --- a/apis/swift/src/main/java/org/jclouds/openstack/swift/blobstore/SwiftAsyncBlobStore.java +++ b/apis/swift/src/main/java/org/jclouds/openstack/swift/blobstore/SwiftAsyncBlobStore.java @@ -83,7 +83,7 @@ public class SwiftAsyncBlobStore extends BaseAsyncBlobStore { private final Provider fetchBlobMetadataProvider; @Inject - protected SwiftAsyncBlobStore(BlobStoreContext context, BlobUtils blobUtils, + protected SwiftAsyncBlobStore(@SuppressWarnings("rawtypes") BlobStoreContext context, BlobUtils blobUtils, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService service, Supplier defaultLocation, @Memoized Supplier> locations, CommonSwiftClient sync, CommonSwiftAsyncClient async, ContainerToResourceMetadata container2ResourceMd, diff --git a/apis/swift/src/main/java/org/jclouds/openstack/swift/blobstore/SwiftBlobStore.java b/apis/swift/src/main/java/org/jclouds/openstack/swift/blobstore/SwiftBlobStore.java index e96909ba18..9d2fab5638 100644 --- a/apis/swift/src/main/java/org/jclouds/openstack/swift/blobstore/SwiftBlobStore.java +++ b/apis/swift/src/main/java/org/jclouds/openstack/swift/blobstore/SwiftBlobStore.java @@ -73,7 +73,7 @@ public class SwiftBlobStore extends BaseBlobStore { private final Provider fetchBlobMetadataProvider; @Inject - protected SwiftBlobStore(BlobStoreContext context, BlobUtils blobUtils, Supplier defaultLocation, + protected SwiftBlobStore(@SuppressWarnings("rawtypes") BlobStoreContext context, BlobUtils blobUtils, Supplier defaultLocation, @Memoized Supplier> locations, CommonSwiftClient sync, ContainerToResourceMetadata container2ResourceMd, BlobStoreListContainerOptionsToListContainerOptions container2ContainerListOptions, diff --git a/apis/swift/src/test/java/org/jclouds/openstack/swift/CommonSwiftClientLiveTest.java b/apis/swift/src/test/java/org/jclouds/openstack/swift/CommonSwiftClientLiveTest.java index 01ce8ee90f..554a39f3ef 100644 --- a/apis/swift/src/test/java/org/jclouds/openstack/swift/CommonSwiftClientLiveTest.java +++ b/apis/swift/src/test/java/org/jclouds/openstack/swift/CommonSwiftClientLiveTest.java @@ -55,7 +55,7 @@ import com.google.common.collect.Maps; */ @Test(groups = "live") public abstract class CommonSwiftClientLiveTest extends BaseBlobStoreIntegrationTest { - + public abstract C getApi(); /** diff --git a/apis/swift/src/test/java/org/jclouds/openstack/swift/CommonSwiftClientTest.java b/apis/swift/src/test/java/org/jclouds/openstack/swift/CommonSwiftClientTest.java index 74a77d2407..4906ebd24e 100644 --- a/apis/swift/src/test/java/org/jclouds/openstack/swift/CommonSwiftClientTest.java +++ b/apis/swift/src/test/java/org/jclouds/openstack/swift/CommonSwiftClientTest.java @@ -24,14 +24,13 @@ import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGIONS; import java.util.Properties; +import org.jclouds.apis.ApiMetadata; import org.jclouds.http.HttpRequest; import org.jclouds.http.RequiresHttp; import org.jclouds.openstack.TestOpenStackAuthenticationModule; import org.jclouds.openstack.swift.config.BaseSwiftRestClientModule; import org.jclouds.rest.ConfiguresRestClient; -import org.jclouds.rest.RestClientTest; -import org.jclouds.rest.RestContextFactory; -import org.jclouds.rest.RestContextSpec; +import org.jclouds.rest.internal.BaseAsyncClientTest; import org.testng.annotations.Test; import com.google.inject.Module; @@ -43,7 +42,7 @@ import com.google.inject.Module; */ // NOTE:without testName, this will not call @Before* and fail w/NPE during surefire @Test(groups = "unit", testName = "SwiftClientTest") -public abstract class CommonSwiftClientTest extends RestClientTest { +public abstract class CommonSwiftClientTest extends BaseAsyncClientTest { @Override protected void checkFilters(HttpRequest request) { @@ -65,11 +64,10 @@ public abstract class CommonSwiftClientTest ex protected String provider = "swift"; - @Override - public RestContextSpec createContextSpec() { - return new RestContextFactory(setupRestProperties()).createContextSpec(provider, "user", "password", setupProperties()); + protected ApiMetadata createApiMetadata() { + return new SwiftApiMetadata(); } - + @Override protected Properties setupProperties() { Properties properties = new Properties(); diff --git a/apis/swift/src/test/java/org/jclouds/openstack/swift/SwiftApiMetadataTest.java b/apis/swift/src/test/java/org/jclouds/openstack/swift/SwiftApiMetadataTest.java index 299f16ea43..f9cd2b4882 100644 --- a/apis/swift/src/test/java/org/jclouds/openstack/swift/SwiftApiMetadataTest.java +++ b/apis/swift/src/test/java/org/jclouds/openstack/swift/SwiftApiMetadataTest.java @@ -1,7 +1,6 @@ package org.jclouds.openstack.swift; -import org.jclouds.apis.ApiType; -import org.jclouds.apis.BaseApiMetadataTest; +import org.jclouds.blobstore.internal.BaseBlobStoreApiMetadataTest; import org.testng.annotations.Test; /** @@ -9,9 +8,9 @@ import org.testng.annotations.Test; * @author Adrian Cole */ @Test(groups = "unit", testName = "SwiftApiMetadataTest") -public class SwiftApiMetadataTest extends BaseApiMetadataTest { +public class SwiftApiMetadataTest extends BaseBlobStoreApiMetadataTest { public SwiftApiMetadataTest() { - super(new SwiftApiMetadata(), ApiType.BLOBSTORE); + super(new SwiftApiMetadata()); } } diff --git a/apis/swift/src/test/java/org/jclouds/openstack/swift/SwiftClientLiveTest.java b/apis/swift/src/test/java/org/jclouds/openstack/swift/SwiftClientLiveTest.java index ff1f77ba64..8cc7bd1e1a 100644 --- a/apis/swift/src/test/java/org/jclouds/openstack/swift/SwiftClientLiveTest.java +++ b/apis/swift/src/test/java/org/jclouds/openstack/swift/SwiftClientLiveTest.java @@ -26,7 +26,11 @@ import org.testng.annotations.Test; */ @Test(groups = "live") public class SwiftClientLiveTest extends CommonSwiftClientLiveTest { - + + public SwiftClientLiveTest(){ + provider = "swift"; + } + @Override public SwiftClient getApi() { return (SwiftClient) context.getProviderSpecificContext().getApi(); diff --git a/apis/swift/src/test/java/org/jclouds/openstack/swift/blobstore/integration/SwiftBlobIntegrationLiveTest.java b/apis/swift/src/test/java/org/jclouds/openstack/swift/blobstore/integration/SwiftBlobIntegrationLiveTest.java index 71c4c128f2..8268a4a339 100644 --- a/apis/swift/src/test/java/org/jclouds/openstack/swift/blobstore/integration/SwiftBlobIntegrationLiveTest.java +++ b/apis/swift/src/test/java/org/jclouds/openstack/swift/blobstore/integration/SwiftBlobIntegrationLiveTest.java @@ -30,7 +30,9 @@ import org.testng.annotations.Test; */ @Test(groups = "live") public class SwiftBlobIntegrationLiveTest extends BaseBlobIntegrationTest { - + public SwiftBlobIntegrationLiveTest() { + provider = "swift"; + } @Override @Test(enabled = false) public void testGetTwoRanges() { diff --git a/apis/swift/src/test/java/org/jclouds/openstack/swift/blobstore/integration/SwiftBlobLiveTest.java b/apis/swift/src/test/java/org/jclouds/openstack/swift/blobstore/integration/SwiftBlobLiveTest.java index 89b3e02b7d..81ac376673 100644 --- a/apis/swift/src/test/java/org/jclouds/openstack/swift/blobstore/integration/SwiftBlobLiveTest.java +++ b/apis/swift/src/test/java/org/jclouds/openstack/swift/blobstore/integration/SwiftBlobLiveTest.java @@ -28,5 +28,7 @@ import org.testng.annotations.Test; */ @Test(groups = { "live" }) public class SwiftBlobLiveTest extends BaseBlobLiveTest { - + public SwiftBlobLiveTest() { + provider = "swift"; + } } diff --git a/apis/swift/src/test/java/org/jclouds/openstack/swift/blobstore/integration/SwiftBlobMapIntegrationLiveTest.java b/apis/swift/src/test/java/org/jclouds/openstack/swift/blobstore/integration/SwiftBlobMapIntegrationLiveTest.java index 7d6600d6a2..a2303a0702 100644 --- a/apis/swift/src/test/java/org/jclouds/openstack/swift/blobstore/integration/SwiftBlobMapIntegrationLiveTest.java +++ b/apis/swift/src/test/java/org/jclouds/openstack/swift/blobstore/integration/SwiftBlobMapIntegrationLiveTest.java @@ -26,5 +26,7 @@ import org.testng.annotations.Test; */ @Test(groups = "live") public class SwiftBlobMapIntegrationLiveTest extends BaseBlobMapIntegrationTest { - + public SwiftBlobMapIntegrationLiveTest() { + provider = "swift"; + } } diff --git a/apis/swift/src/test/java/org/jclouds/openstack/swift/blobstore/integration/SwiftBlobSignerLiveTest.java b/apis/swift/src/test/java/org/jclouds/openstack/swift/blobstore/integration/SwiftBlobSignerLiveTest.java index 06fb6a326f..3b116c7e15 100644 --- a/apis/swift/src/test/java/org/jclouds/openstack/swift/blobstore/integration/SwiftBlobSignerLiveTest.java +++ b/apis/swift/src/test/java/org/jclouds/openstack/swift/blobstore/integration/SwiftBlobSignerLiveTest.java @@ -27,5 +27,7 @@ import org.testng.annotations.Test; */ @Test(groups = { "live" }) public class SwiftBlobSignerLiveTest extends BaseBlobSignerLiveTest { - + public SwiftBlobSignerLiveTest() { + provider = "swift"; + } } diff --git a/apis/swift/src/test/java/org/jclouds/openstack/swift/blobstore/integration/SwiftContainerIntegrationLiveTest.java b/apis/swift/src/test/java/org/jclouds/openstack/swift/blobstore/integration/SwiftContainerIntegrationLiveTest.java index 946a12f4f8..73862bf7da 100644 --- a/apis/swift/src/test/java/org/jclouds/openstack/swift/blobstore/integration/SwiftContainerIntegrationLiveTest.java +++ b/apis/swift/src/test/java/org/jclouds/openstack/swift/blobstore/integration/SwiftContainerIntegrationLiveTest.java @@ -27,5 +27,7 @@ import org.testng.annotations.Test; */ @Test(groups = "live") public class SwiftContainerIntegrationLiveTest extends BaseContainerIntegrationTest { - + public SwiftContainerIntegrationLiveTest() { + provider = "swift"; + } } diff --git a/apis/swift/src/test/java/org/jclouds/openstack/swift/blobstore/integration/SwiftContainerLiveTest.java b/apis/swift/src/test/java/org/jclouds/openstack/swift/blobstore/integration/SwiftContainerLiveTest.java index d095628b95..7901ac4fa8 100644 --- a/apis/swift/src/test/java/org/jclouds/openstack/swift/blobstore/integration/SwiftContainerLiveTest.java +++ b/apis/swift/src/test/java/org/jclouds/openstack/swift/blobstore/integration/SwiftContainerLiveTest.java @@ -29,7 +29,9 @@ import org.testng.annotations.Test; */ @Test(groups = { "live" }) public class SwiftContainerLiveTest extends BaseContainerLiveTest { - + public SwiftContainerLiveTest() { + provider = "swift"; + } @Test(expectedExceptions=UnsupportedOperationException.class) public void testPublicAccess() throws MalformedURLException, InterruptedException, IOException { super.testPublicAccess(); diff --git a/apis/swift/src/test/java/org/jclouds/openstack/swift/blobstore/integration/SwiftInputStreamMapIntegrationLiveTest.java b/apis/swift/src/test/java/org/jclouds/openstack/swift/blobstore/integration/SwiftInputStreamMapIntegrationLiveTest.java index 90352f3599..b4c75add16 100644 --- a/apis/swift/src/test/java/org/jclouds/openstack/swift/blobstore/integration/SwiftInputStreamMapIntegrationLiveTest.java +++ b/apis/swift/src/test/java/org/jclouds/openstack/swift/blobstore/integration/SwiftInputStreamMapIntegrationLiveTest.java @@ -26,5 +26,7 @@ import org.testng.annotations.Test; */ @Test(groups = "live") public class SwiftInputStreamMapIntegrationLiveTest extends BaseInputStreamMapIntegrationTest { - + public SwiftInputStreamMapIntegrationLiveTest() { + provider = "swift"; + } } diff --git a/apis/swift/src/test/java/org/jclouds/openstack/swift/blobstore/integration/SwiftServiceIntegrationLiveTest.java b/apis/swift/src/test/java/org/jclouds/openstack/swift/blobstore/integration/SwiftServiceIntegrationLiveTest.java index ee48005503..5c559e2549 100644 --- a/apis/swift/src/test/java/org/jclouds/openstack/swift/blobstore/integration/SwiftServiceIntegrationLiveTest.java +++ b/apis/swift/src/test/java/org/jclouds/openstack/swift/blobstore/integration/SwiftServiceIntegrationLiveTest.java @@ -26,5 +26,7 @@ import org.testng.annotations.Test; */ @Test(groups = "live") public class SwiftServiceIntegrationLiveTest extends BaseServiceIntegrationTest { - + public SwiftServiceIntegrationLiveTest() { + provider = "swift"; + } } diff --git a/apis/swift/src/test/java/org/jclouds/openstack/swift/blobstore/integration/SwiftTestInitializer.java b/apis/swift/src/test/java/org/jclouds/openstack/swift/blobstore/integration/SwiftTestInitializer.java deleted file mode 100644 index 6f51336a44..0000000000 --- a/apis/swift/src/test/java/org/jclouds/openstack/swift/blobstore/integration/SwiftTestInitializer.java +++ /dev/null @@ -1,48 +0,0 @@ -/** - * 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.openstack.swift.blobstore.integration; - -import java.io.IOException; - -import org.jclouds.blobstore.BlobStoreContext; -import org.jclouds.blobstore.BlobStoreContextFactory; -import org.jclouds.blobstore.integration.TransientBlobStoreTestInitializer; -import org.jclouds.logging.log4j.config.Log4JLoggingModule; - -import com.google.common.collect.ImmutableSet; -import com.google.inject.Module; - -/** - * - * @author Adrian Cole - */ -public class SwiftTestInitializer extends TransientBlobStoreTestInitializer { - - public SwiftTestInitializer() { - provider = "swift"; - } - - @Override - protected BlobStoreContext createLiveContext(Module configurationModule, String endpoint, String apiVersion, - String buildVersion, String app, String identity, String credential) throws IOException { - return new BlobStoreContextFactory().createContext(provider, ImmutableSet.of(configurationModule, - new Log4JLoggingModule()), setupProperties(endpoint, apiVersion, buildVersion, identity, credential)); - } - -} diff --git a/apis/vcloud/src/main/java/org/jclouds/vcloud/VCloudApiMetadata.java b/apis/vcloud/src/main/java/org/jclouds/vcloud/VCloudApiMetadata.java index 8b00adb062..9238fca5ea 100644 --- a/apis/vcloud/src/main/java/org/jclouds/vcloud/VCloudApiMetadata.java +++ b/apis/vcloud/src/main/java/org/jclouds/vcloud/VCloudApiMetadata.java @@ -18,50 +18,90 @@ */ package org.jclouds.vcloud; +import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL; +import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_FENCEMODE; +import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_TIMEOUT_TASK_COMPLETED; +import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_VERSION_SCHEMA; +import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_XML_NAMESPACE; +import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_XML_SCHEMA; + import java.net.URI; +import java.util.Properties; import org.jclouds.apis.ApiMetadata; -import org.jclouds.apis.ApiType; -import org.jclouds.apis.BaseApiMetadata; +import org.jclouds.compute.ComputeServiceContext; +import org.jclouds.compute.internal.BaseComputeServiceApiMetadata; +import org.jclouds.vcloud.domain.network.FenceMode; + +import com.google.common.reflect.TypeToken; /** * Implementation of {@link ApiMetadata} for VCloud 1.0 API * * @author Adrian Cole */ -public class VCloudApiMetadata extends BaseApiMetadata { +public class VCloudApiMetadata + extends + BaseComputeServiceApiMetadata, VCloudApiMetadata> { - public VCloudApiMetadata() { - this(builder() - .id("vcloud") - .type(ApiType.COMPUTE) - .name("VCloud 1.0 API") - .identityName("User at Organization (user@org)") - .credentialName("Password") - .documentation(URI.create("http://www.vmware.com/support/pubs/vcd_pubs.html"))); + @Override + public Builder toBuilder() { + return new Builder().fromApiMetadata(this); } - // below are so that we can reuse builders, toString, hashCode, etc. - // we have to set concrete classes here, as our base class cannot be - // concrete due to serviceLoader - protected VCloudApiMetadata(ConcreteBuilder builder) { + public VCloudApiMetadata() { + this(new Builder()); + } + + protected VCloudApiMetadata(Builder builder) { super(builder); } - private static class ConcreteBuilder extends Builder { + protected static Properties defaultProperties() { + Properties properties = BaseComputeServiceApiMetadata.Builder.defaultProperties(); + properties.setProperty(PROPERTY_VCLOUD_VERSION_SCHEMA, "1"); + properties.setProperty(PROPERTY_VCLOUD_XML_NAMESPACE, + String.format("http://www.vmware.com/vcloud/v${%s}", PROPERTY_VCLOUD_VERSION_SCHEMA)); + properties.setProperty(PROPERTY_SESSION_INTERVAL, 8 * 60 + ""); + properties.setProperty(PROPERTY_VCLOUD_XML_SCHEMA, "http://vcloud.safesecureweb.com/ns/vcloud.xsd"); + properties.setProperty("jclouds.dns_name_length_min", "1"); + properties.setProperty("jclouds.dns_name_length_max", "80"); + properties.setProperty(PROPERTY_VCLOUD_DEFAULT_FENCEMODE, FenceMode.BRIDGED.toString()); + // TODO integrate this with the {@link ComputeTimeouts} instead of having + // a single timeout for + // everything. + properties.setProperty(PROPERTY_VCLOUD_TIMEOUT_TASK_COMPLETED, 1200l * 1000l + ""); + properties.setProperty(PROPERTY_SESSION_INTERVAL, 300 + ""); + return properties; + } + + public static class Builder + extends + BaseComputeServiceApiMetadata.Builder, VCloudApiMetadata> { + + protected Builder() { + id("vcloud") + .name("VCloud 1.0 API") + .identityName("User at Organization (user@org)") + .credentialName("Password") + .documentation(URI.create("http://www.vmware.com/support/pubs/vcd_pubs.html")) + .version("1.0") + .javaApi(VCloudClient.class, VCloudAsyncClient.class) + .defaultProperties(VCloudApiMetadata.defaultProperties()) + .contextBuilder(TypeToken.of(VCloudContextBuilder.class)); + } @Override public VCloudApiMetadata build() { return new VCloudApiMetadata(this); } + + @Override + public Builder fromApiMetadata(VCloudApiMetadata in) { + super.fromApiMetadata(in); + return this; + } + } - public static ConcreteBuilder builder() { - return new ConcreteBuilder(); - } - - @Override - public ConcreteBuilder toBuilder() { - return builder().fromApiMetadata(this); - } -} \ No newline at end of file +} diff --git a/apis/vcloud/src/main/java/org/jclouds/vcloud/VCloudContextBuilder.java b/apis/vcloud/src/main/java/org/jclouds/vcloud/VCloudContextBuilder.java index a14f6f3091..a69b0105c2 100644 --- a/apis/vcloud/src/main/java/org/jclouds/vcloud/VCloudContextBuilder.java +++ b/apis/vcloud/src/main/java/org/jclouds/vcloud/VCloudContextBuilder.java @@ -19,38 +19,30 @@ package org.jclouds.vcloud; import java.util.List; -import java.util.Properties; import org.jclouds.compute.ComputeServiceContext; import org.jclouds.compute.ComputeServiceContextBuilder; -import org.jclouds.compute.internal.ComputeServiceContextImpl; -import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule; -import org.jclouds.logging.jdk.config.JDKLoggingModule; +import org.jclouds.providers.ProviderMetadata; import org.jclouds.vcloud.compute.config.VCloudComputeServiceContextModule; import org.jclouds.vcloud.config.VCloudRestClientModule; -import com.google.inject.Injector; -import com.google.inject.Key; import com.google.inject.Module; -import com.google.inject.TypeLiteral; /** - * Creates {@link VCloudComputeServiceContext} or {@link Injector} instances based on the most - * commonly requested arguments. - *

- * Note that Threadsafe objects will be bound as singletons to the Injector or Context provided. - *

- *

- * If no Modules are specified, the default {@link JDKLoggingModule logging} and - * {@link JavaUrlHttpCommandExecutorServiceModule http transports} will be installed. * * @author Adrian Cole - * @see VCloudComputeServiceContext */ -public class VCloudContextBuilder extends ComputeServiceContextBuilder { +public class VCloudContextBuilder + extends + ComputeServiceContextBuilder, VCloudApiMetadata> { - public VCloudContextBuilder(Properties props) { - super(VCloudClient.class, VCloudAsyncClient.class, props); + public VCloudContextBuilder( + ProviderMetadata, VCloudApiMetadata> providerMetadata) { + super(providerMetadata); + } + + public VCloudContextBuilder(VCloudApiMetadata apiMetadata) { + super(apiMetadata); } @Override @@ -58,16 +50,8 @@ public class VCloudContextBuilder extends ComputeServiceContextBuilder modules) { modules.add(new VCloudRestClientModule()); } - @Override - public ComputeServiceContext buildComputeServiceContext() { - // need the generic type information - return (ComputeServiceContext) this.buildInjector().getInstance( - Key.get(new TypeLiteral>() { - })); - } } diff --git a/apis/vcloud/src/main/java/org/jclouds/vcloud/VCloudPropertiesBuilder.java b/apis/vcloud/src/main/java/org/jclouds/vcloud/VCloudPropertiesBuilder.java deleted file mode 100644 index d5522c343b..0000000000 --- a/apis/vcloud/src/main/java/org/jclouds/vcloud/VCloudPropertiesBuilder.java +++ /dev/null @@ -1,63 +0,0 @@ -/** - * 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.vcloud; - -import static org.jclouds.Constants.PROPERTY_API_VERSION; -import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL; -import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_FENCEMODE; -import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_TIMEOUT_TASK_COMPLETED; -import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_VERSION_SCHEMA; -import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_XML_NAMESPACE; -import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_XML_SCHEMA; - -import java.util.Properties; - -import org.jclouds.PropertiesBuilder; -import org.jclouds.vcloud.domain.network.FenceMode; - -/** - * Builds properties used in VCloud Clients - * - * @author Adrian Cole - */ -public class VCloudPropertiesBuilder extends PropertiesBuilder { - @Override - protected Properties defaultProperties() { - Properties properties = super.defaultProperties(); - properties.setProperty(PROPERTY_API_VERSION, "1.0"); - properties.setProperty(PROPERTY_VCLOUD_VERSION_SCHEMA, "1"); - properties.setProperty(PROPERTY_VCLOUD_XML_NAMESPACE, - String.format("http://www.vmware.com/vcloud/v${%s}", PROPERTY_VCLOUD_VERSION_SCHEMA)); - properties.setProperty(PROPERTY_SESSION_INTERVAL, 8 * 60 + ""); - properties.setProperty(PROPERTY_VCLOUD_XML_SCHEMA, "http://vcloud.safesecureweb.com/ns/vcloud.xsd"); - properties.setProperty("jclouds.dns_name_length_min", "1"); - properties.setProperty("jclouds.dns_name_length_max", "80"); - properties.setProperty(PROPERTY_VCLOUD_DEFAULT_FENCEMODE, FenceMode.BRIDGED.toString()); - // TODO integrate this with the {@link ComputeTimeouts} instead of having a single timeout for - // everything. - properties.setProperty(PROPERTY_VCLOUD_TIMEOUT_TASK_COMPLETED, 1200l * 1000l + ""); - properties.setProperty(PROPERTY_SESSION_INTERVAL, 300 + ""); - return properties; - } - - public VCloudPropertiesBuilder(Properties properties) { - super(properties); - } - -} diff --git a/apis/vcloud/src/test/java/org/jclouds/vcloud/VCloudApiMetadataTest.java b/apis/vcloud/src/test/java/org/jclouds/vcloud/VCloudApiMetadataTest.java index 338494962b..9bb06859b2 100644 --- a/apis/vcloud/src/test/java/org/jclouds/vcloud/VCloudApiMetadataTest.java +++ b/apis/vcloud/src/test/java/org/jclouds/vcloud/VCloudApiMetadataTest.java @@ -19,7 +19,7 @@ package org.jclouds.vcloud; import org.jclouds.apis.ApiType; -import org.jclouds.apis.BaseApiMetadataTest; +import org.jclouds.apis.internal.BaseApiMetadataTest; import org.testng.annotations.Test; /** diff --git a/apis/vcloud/src/test/java/org/jclouds/vcloud/VCloudVersionsAsyncClientTest.java b/apis/vcloud/src/test/java/org/jclouds/vcloud/VCloudVersionsAsyncClientTest.java index cc3d8c7098..6b37820b16 100644 --- a/apis/vcloud/src/test/java/org/jclouds/vcloud/VCloudVersionsAsyncClientTest.java +++ b/apis/vcloud/src/test/java/org/jclouds/vcloud/VCloudVersionsAsyncClientTest.java @@ -18,7 +18,6 @@ */ package org.jclouds.vcloud; -import static org.jclouds.rest.RestContextFactory.contextSpec; import static org.testng.Assert.assertEquals; import java.io.IOException; @@ -26,8 +25,9 @@ import java.lang.reflect.Method; import org.jclouds.http.HttpRequest; import org.jclouds.http.functions.ParseSax; -import org.jclouds.rest.RestClientTest; -import org.jclouds.rest.RestContextSpec; +import org.jclouds.providers.ProviderMetadata; +import org.jclouds.rest.AnonymousProviderMetadata; +import org.jclouds.rest.internal.BaseAsyncClientTest; import org.jclouds.rest.internal.RestAnnotationProcessor; import org.jclouds.vcloud.xml.SupportedVersionsHandler; import org.testng.annotations.Test; @@ -41,7 +41,7 @@ import com.google.inject.TypeLiteral; */ // NOTE:without testName, this will not call @Before* and fail w/NPE during surefire @Test(groups = "unit", testName = "VCloudVersionsAsyncClientTest") -public class VCloudVersionsAsyncClientTest extends RestClientTest { +public class VCloudVersionsAsyncClientTest extends BaseAsyncClientTest { public void testVersions() throws SecurityException, NoSuchMethodException, IOException { Method method = VCloudVersionsAsyncClient.class.getMethod("getSupportedVersions"); @@ -70,9 +70,8 @@ public class VCloudVersionsAsyncClientTest extends RestClientTest createContextSpec() { - return contextSpec("test", "http://localhost:8080", "1", "", "", "identity", "credential", - VCloudVersionsClient.class, VCloudVersionsAsyncClient.class); + protected ProviderMetadata createProviderMetadata() { + return AnonymousProviderMetadata.forClientMappedToAsyncClientOnEndpoint(VCloudVersionsClient.class, + VCloudVersionsAsyncClient.class, "http://localhost:8080"); } - } diff --git a/apis/vcloud/src/test/java/org/jclouds/vcloud/binders/BindCatalogItemToXmlPayloadTest.java b/apis/vcloud/src/test/java/org/jclouds/vcloud/binders/BindCatalogItemToXmlPayloadTest.java index 28d506bd0c..d59b818d32 100644 --- a/apis/vcloud/src/test/java/org/jclouds/vcloud/binders/BindCatalogItemToXmlPayloadTest.java +++ b/apis/vcloud/src/test/java/org/jclouds/vcloud/binders/BindCatalogItemToXmlPayloadTest.java @@ -26,10 +26,9 @@ import static org.easymock.EasyMock.verify; import java.io.IOException; import java.net.URI; import java.util.Map; -import java.util.Properties; import org.jclouds.rest.internal.GeneratedHttpRequest; -import org.jclouds.vcloud.VCloudPropertiesBuilder; +import org.jclouds.vcloud.VCloudApiMetadata; import org.jclouds.vcloud.options.CatalogItemOptions; import org.nnsoft.guice.rocoto.Rocoto; import org.nnsoft.guice.rocoto.configuration.ConfigurationModule; @@ -51,7 +50,7 @@ public class BindCatalogItemToXmlPayloadTest { @Override protected void bindConfigurations() { - bindProperties(new VCloudPropertiesBuilder(new Properties()).build()); + bindProperties(new VCloudApiMetadata().getDefaultProperties()); } })); diff --git a/apis/vcloud/src/test/java/org/jclouds/vcloud/binders/BindDeployVAppParamsToXmlPayloadTest.java b/apis/vcloud/src/test/java/org/jclouds/vcloud/binders/BindDeployVAppParamsToXmlPayloadTest.java index fbece0ba68..5c4dd3170c 100644 --- a/apis/vcloud/src/test/java/org/jclouds/vcloud/binders/BindDeployVAppParamsToXmlPayloadTest.java +++ b/apis/vcloud/src/test/java/org/jclouds/vcloud/binders/BindDeployVAppParamsToXmlPayloadTest.java @@ -26,10 +26,9 @@ import static org.easymock.EasyMock.verify; import java.io.IOException; import java.net.URI; import java.util.Map; -import java.util.Properties; import org.jclouds.rest.internal.GeneratedHttpRequest; -import org.jclouds.vcloud.VCloudPropertiesBuilder; +import org.jclouds.vcloud.VCloudApiMetadata; import org.nnsoft.guice.rocoto.Rocoto; import org.nnsoft.guice.rocoto.configuration.ConfigurationModule; import org.testng.annotations.Test; @@ -49,7 +48,7 @@ public class BindDeployVAppParamsToXmlPayloadTest { @Override protected void bindConfigurations() { - bindProperties(new VCloudPropertiesBuilder(new Properties()).build()); + bindProperties(new VCloudApiMetadata().getDefaultProperties()); } })); diff --git a/apis/vcloud/src/test/java/org/jclouds/vcloud/binders/BindInstantiateVAppTemplateParamsToXmlPayloadTest.java b/apis/vcloud/src/test/java/org/jclouds/vcloud/binders/BindInstantiateVAppTemplateParamsToXmlPayloadTest.java index 1b5151563e..8fbca524fd 100644 --- a/apis/vcloud/src/test/java/org/jclouds/vcloud/binders/BindInstantiateVAppTemplateParamsToXmlPayloadTest.java +++ b/apis/vcloud/src/test/java/org/jclouds/vcloud/binders/BindInstantiateVAppTemplateParamsToXmlPayloadTest.java @@ -28,14 +28,13 @@ import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAU import java.io.IOException; import java.net.URI; import java.util.Map; -import java.util.Properties; import javax.inject.Named; import javax.inject.Singleton; import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.util.Strings2; -import org.jclouds.vcloud.VCloudPropertiesBuilder; +import org.jclouds.vcloud.VCloudApiMetadata; import org.jclouds.vcloud.domain.ReferenceType; import org.jclouds.vcloud.domain.VAppTemplate; import org.jclouds.vcloud.domain.internal.ReferenceTypeImpl; @@ -90,7 +89,7 @@ public class BindInstantiateVAppTemplateParamsToXmlPayloadTest { @Override protected void bindConfigurations() { - bindProperties(new VCloudPropertiesBuilder(new Properties()).build()); + bindProperties(new VCloudApiMetadata().getDefaultProperties()); } @SuppressWarnings("unused") diff --git a/apis/vcloud/src/test/java/org/jclouds/vcloud/binders/BindNetworkConnectionSectionToXmlPayloadTest.java b/apis/vcloud/src/test/java/org/jclouds/vcloud/binders/BindNetworkConnectionSectionToXmlPayloadTest.java index 2975f56af1..a0552e1e1f 100644 --- a/apis/vcloud/src/test/java/org/jclouds/vcloud/binders/BindNetworkConnectionSectionToXmlPayloadTest.java +++ b/apis/vcloud/src/test/java/org/jclouds/vcloud/binders/BindNetworkConnectionSectionToXmlPayloadTest.java @@ -22,10 +22,9 @@ import static org.testng.Assert.assertEquals; import java.io.IOException; import java.net.URI; -import java.util.Properties; import org.jclouds.http.HttpRequest; -import org.jclouds.vcloud.VCloudPropertiesBuilder; +import org.jclouds.vcloud.VCloudApiMetadata; import org.jclouds.vcloud.domain.NetworkConnection; import org.jclouds.vcloud.domain.NetworkConnectionSection; import org.jclouds.vcloud.domain.network.IpAddressAllocationMode; @@ -48,7 +47,7 @@ public class BindNetworkConnectionSectionToXmlPayloadTest { @Override protected void bindConfigurations() { - bindProperties(new VCloudPropertiesBuilder(new Properties()).build()); + bindProperties(new VCloudApiMetadata().getDefaultProperties()); } })); diff --git a/apis/vcloud/src/test/java/org/jclouds/vcloud/binders/BindUndeployVAppParamsToXmlPayloadTest.java b/apis/vcloud/src/test/java/org/jclouds/vcloud/binders/BindUndeployVAppParamsToXmlPayloadTest.java index 123a07fc14..790ee6c8da 100644 --- a/apis/vcloud/src/test/java/org/jclouds/vcloud/binders/BindUndeployVAppParamsToXmlPayloadTest.java +++ b/apis/vcloud/src/test/java/org/jclouds/vcloud/binders/BindUndeployVAppParamsToXmlPayloadTest.java @@ -26,10 +26,9 @@ import static org.easymock.EasyMock.verify; import java.io.IOException; import java.net.URI; import java.util.Map; -import java.util.Properties; import org.jclouds.rest.internal.GeneratedHttpRequest; -import org.jclouds.vcloud.VCloudPropertiesBuilder; +import org.jclouds.vcloud.VCloudApiMetadata; import org.nnsoft.guice.rocoto.Rocoto; import org.nnsoft.guice.rocoto.configuration.ConfigurationModule; import org.testng.annotations.Test; @@ -49,7 +48,7 @@ public class BindUndeployVAppParamsToXmlPayloadTest { @Override protected void bindConfigurations() { - bindProperties(new VCloudPropertiesBuilder(new Properties()).build()); + bindProperties(new VCloudApiMetadata().getDefaultProperties()); } })); diff --git a/apis/vcloud/src/test/java/org/jclouds/vcloud/compute/BaseVCloudComputeServiceExpectTest.java b/apis/vcloud/src/test/java/org/jclouds/vcloud/compute/BaseVCloudComputeServiceExpectTest.java index 833e9ba46e..59b371f4e3 100644 --- a/apis/vcloud/src/test/java/org/jclouds/vcloud/compute/BaseVCloudComputeServiceExpectTest.java +++ b/apis/vcloud/src/test/java/org/jclouds/vcloud/compute/BaseVCloudComputeServiceExpectTest.java @@ -23,17 +23,16 @@ import java.util.Properties; import javax.ws.rs.core.MediaType; +import org.jclouds.apis.ApiMetadata; import org.jclouds.compute.ComputeService; -import org.jclouds.compute.ComputeServiceContextFactory; import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpResponse; -import org.jclouds.logging.config.NullLoggingModule; -import org.jclouds.rest.BaseRestClientExpectTest; +import org.jclouds.rest.internal.BaseRestClientExpectTest; +import org.jclouds.vcloud.VCloudApiMetadata; import org.jclouds.vcloud.VCloudMediaType; import com.google.common.base.Function; import com.google.common.collect.ImmutableMultimap; -import com.google.common.collect.ImmutableSet; import com.google.common.net.HttpHeaders; import com.google.inject.Module; @@ -57,7 +56,7 @@ public abstract class BaseVCloudComputeServiceExpectTest extends BaseRestClientE URI.create(ENDPOINT + "/v1.0/login")) .headers(ImmutableMultimap. builder() .put(HttpHeaders.ACCEPT, VCloudMediaType.ORGLIST_XML) - .put(HttpHeaders.AUTHORIZATION, "Basic dXNlckBvcmc6cGFzc3dvcmQ=").build()).build(); + .put(HttpHeaders.AUTHORIZATION, "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build()).build(); protected String sessionToken = "AtatAgvJMrwOc9pDQq4RRCRLazThpnTKJDxSVH9oB2I="; @@ -148,14 +147,18 @@ public abstract class BaseVCloudComputeServiceExpectTest extends BaseRestClientE @Override public ComputeService createClient(Function fn, Module module, Properties props) { - return new ComputeServiceContextFactory(setupRestProperties()) - .createContext(provider, "user@org", "password", ImmutableSet. of(new ExpectModule(fn), - new NullLoggingModule(), module), props).getComputeService(); + return createInjector(fn, module, props).getInstance(ComputeService.class); } + + @Override + protected ApiMetadata createApiMetadata() { + return new VCloudApiMetadata(); + } + @Override protected Properties setupProperties() { Properties props = super.setupProperties(); - props.setProperty(provider+".endpoint", ENDPOINT); + props.setProperty(provider + ".endpoint", ENDPOINT); return props; } } diff --git a/apis/vcloud/src/test/java/org/jclouds/vcloud/compute/VCloudComputeServiceLiveTest.java b/apis/vcloud/src/test/java/org/jclouds/vcloud/compute/VCloudComputeServiceLiveTest.java index aa6185c6c5..e10e9dc449 100644 --- a/apis/vcloud/src/test/java/org/jclouds/vcloud/compute/VCloudComputeServiceLiveTest.java +++ b/apis/vcloud/src/test/java/org/jclouds/vcloud/compute/VCloudComputeServiceLiveTest.java @@ -18,9 +18,12 @@ */ package org.jclouds.vcloud.compute; -import org.jclouds.compute.BaseComputeServiceLiveTest; +import org.jclouds.compute.ComputeServiceContext; import org.jclouds.compute.domain.NodeMetadata; +import org.jclouds.compute.internal.BaseComputeServiceLiveTest; import org.jclouds.sshj.config.SshjSshClientModule; +import org.jclouds.vcloud.VCloudAsyncClient; +import org.jclouds.vcloud.VCloudClient; import org.testng.annotations.Test; import com.google.common.collect.ImmutableMap; @@ -32,7 +35,9 @@ import com.google.inject.Module; * @author Adrian Cole */ @Test(groups = "live", enabled = true, singleThreaded = true) -public class VCloudComputeServiceLiveTest extends BaseComputeServiceLiveTest { +public class VCloudComputeServiceLiveTest + extends + BaseComputeServiceLiveTest> { public VCloudComputeServiceLiveTest() { provider = "vcloud"; diff --git a/apis/vcloud/src/test/java/org/jclouds/vcloud/compute/functions/VAppToNodeMetadataTest.java b/apis/vcloud/src/test/java/org/jclouds/vcloud/compute/functions/VAppToNodeMetadataTest.java index 7ce1aefb97..f3d5df5188 100644 --- a/apis/vcloud/src/test/java/org/jclouds/vcloud/compute/functions/VAppToNodeMetadataTest.java +++ b/apis/vcloud/src/test/java/org/jclouds/vcloud/compute/functions/VAppToNodeMetadataTest.java @@ -18,13 +18,11 @@ */ package org.jclouds.vcloud.compute.functions; -import static com.google.common.base.Preconditions.checkNotNull; import static org.testng.Assert.assertEquals; import java.io.InputStream; import java.util.Map; import java.util.NoSuchElementException; -import java.util.Properties; import java.util.Set; import javax.inject.Singleton; @@ -41,7 +39,7 @@ import org.jclouds.domain.LocationScope; import org.jclouds.http.functions.ParseSax; import org.jclouds.http.functions.ParseSax.Factory; import org.jclouds.http.functions.config.SaxParserModule; -import org.jclouds.vcloud.VCloudPropertiesBuilder; +import org.jclouds.vcloud.VCloudApiMetadata; import org.jclouds.vcloud.compute.config.VCloudComputeServiceDependenciesModule; import org.jclouds.vcloud.domain.ReferenceType; import org.jclouds.vcloud.domain.Status; @@ -75,8 +73,7 @@ public class VAppToNodeMetadataTest { @Override protected void configure() { - Properties props = new Properties(); - Names.bindProperties(binder(), checkNotNull(new VCloudPropertiesBuilder(props).build(), "properties")); + Names.bindProperties(binder(), new VCloudApiMetadata().getDefaultProperties()); bind(new TypeLiteral>() { }).to(new TypeLiteral() { }); diff --git a/apis/vcloud/src/test/java/org/jclouds/vcloud/features/CatalogClientLiveTest.java b/apis/vcloud/src/test/java/org/jclouds/vcloud/features/CatalogClientLiveTest.java index adc2563eb8..28e1aeed00 100644 --- a/apis/vcloud/src/test/java/org/jclouds/vcloud/features/CatalogClientLiveTest.java +++ b/apis/vcloud/src/test/java/org/jclouds/vcloud/features/CatalogClientLiveTest.java @@ -46,7 +46,7 @@ public class CatalogClientLiveTest extends BaseVCloudClientLiveTest { public void testFindCatalogIsWriteableIfNotVersion1_5() throws Exception { // when we are in vCloud 1.0.0 public catalogs don't work, so our default // catalog is private - if (!buildVersion.startsWith("1.5")) + if (!context.getProviderSpecificContext().getApiVersion().startsWith("1.5")) assertTrue(getVCloudApi().getCatalogClient().findCatalogInOrgNamed(null, null).isReadOnly()); } } \ No newline at end of file diff --git a/apis/vcloud/src/test/java/org/jclouds/vcloud/internal/BaseVCloudAsyncClientTest.java b/apis/vcloud/src/test/java/org/jclouds/vcloud/internal/BaseVCloudAsyncClientTest.java index 96b696cf30..e13e85fb12 100644 --- a/apis/vcloud/src/test/java/org/jclouds/vcloud/internal/BaseVCloudAsyncClientTest.java +++ b/apis/vcloud/src/test/java/org/jclouds/vcloud/internal/BaseVCloudAsyncClientTest.java @@ -23,7 +23,6 @@ import static org.testng.Assert.assertEquals; import java.net.URI; import java.util.Map; -import java.util.Properties; import java.util.concurrent.atomic.AtomicReference; import javax.inject.Inject; @@ -34,11 +33,12 @@ import org.jclouds.http.HttpRequest; import org.jclouds.http.RequiresHttp; import org.jclouds.ovf.Envelope; import org.jclouds.ovf.xml.EnvelopeHandlerTest; +import org.jclouds.providers.ProviderMetadata; +import org.jclouds.rest.AnonymousProviderMetadata; import org.jclouds.rest.AuthorizationException; import org.jclouds.rest.ConfiguresRestClient; -import org.jclouds.rest.RestClientTest; -import org.jclouds.rest.RestContextFactory; -import org.jclouds.rest.RestContextSpec; +import org.jclouds.rest.internal.BaseAsyncClientTest; +import org.jclouds.vcloud.VCloudApiMetadata; import org.jclouds.vcloud.VCloudMediaType; import org.jclouds.vcloud.VCloudVersionsClient; import org.jclouds.vcloud.config.VCloudRestClientModule; @@ -78,7 +78,7 @@ import com.google.inject.TypeLiteral; // NOTE:without testName, this will not call @Before* and fail w/NPE during // surefire @Test(groups = "unit", testName = "BaseVCloudAsyncClientTest") -public abstract class BaseVCloudAsyncClientTest extends RestClientTest { +public abstract class BaseVCloudAsyncClientTest extends BaseAsyncClientTest { @Override protected void checkFilters(HttpRequest request) { @@ -90,14 +90,13 @@ public abstract class BaseVCloudAsyncClientTest extends RestClientTest { protected Module createModule() { return new VCloudRestClientModuleExtension(); } - + @Override - public RestContextSpec createContextSpec() { - Properties overrides = new Properties(); - overrides.setProperty("vcloud.endpoint", "https://vcenterprise.bluelock.com/api/v1.0"); - return new RestContextFactory().createContextSpec("vcloud", "identity", "credential", overrides); + protected ProviderMetadata createProviderMetadata() { + return AnonymousProviderMetadata.forApiWithEndpoint(new VCloudApiMetadata(), + "https://vcenterprise.bluelock.com/api/v1.0"); } - + protected static final ReferenceTypeImpl ORG_REF = new ReferenceTypeImpl("org", VCloudMediaType.ORG_XML, URI.create("https://vcenterprise.bluelock.com/api/v1.0/org/1")); diff --git a/apis/vcloud/src/test/java/org/jclouds/vcloud/internal/BaseVCloudClientLiveTest.java b/apis/vcloud/src/test/java/org/jclouds/vcloud/internal/BaseVCloudClientLiveTest.java index 8b3b86b884..07edbf1379 100644 --- a/apis/vcloud/src/test/java/org/jclouds/vcloud/internal/BaseVCloudClientLiveTest.java +++ b/apis/vcloud/src/test/java/org/jclouds/vcloud/internal/BaseVCloudClientLiveTest.java @@ -18,22 +18,15 @@ */ package org.jclouds.vcloud.internal; -import java.util.Properties; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeoutException; - -import org.jclouds.compute.BaseVersionedServiceLiveTest; import org.jclouds.compute.ComputeService; -import org.jclouds.compute.ComputeServiceContextFactory; -import org.jclouds.logging.log4j.config.Log4JLoggingModule; -import org.jclouds.rest.RestContextFactory; +import org.jclouds.compute.ComputeServiceContext; +import org.jclouds.compute.internal.BaseComputeServiceContextLiveTest; import org.jclouds.sshj.config.SshjSshClientModule; +import org.jclouds.vcloud.VCloudAsyncClient; import org.jclouds.vcloud.VCloudClient; -import org.testng.annotations.AfterGroups; -import org.testng.annotations.BeforeGroups; +import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; -import com.google.common.collect.ImmutableSet; import com.google.inject.Module; /** @@ -41,38 +34,32 @@ import com.google.inject.Module; * @author Adrian Cole */ @Test(groups = "live", enabled = true, singleThreaded = true) -public abstract class BaseVCloudClientLiveTest extends BaseVersionedServiceLiveTest { +public abstract class BaseVCloudClientLiveTest + extends + BaseComputeServiceContextLiveTest> { + // username is too long for name constraints protected String prefix = "vcd"; protected ComputeService client; public BaseVCloudClientLiveTest() { - provider = "vcloud"; + provider = "vcloud"; } protected VCloudClient getVCloudApi() { - return VCloudClient.class.cast(client.getContext().getProviderSpecificContext().getApi()); + return VCloudClient.class.cast(context.getProviderSpecificContext().getApi()); } - @BeforeGroups(groups = { "live" }) - public void setupClient() { - setupCredentials(); - Properties overrides = setupProperties(); - client = new ComputeServiceContextFactory().createContext(provider, - ImmutableSet. of(new Log4JLoggingModule(), new SshjSshClientModule()), overrides).getComputeService(); - } - - protected Properties setupRestProperties() { - return RestContextFactory.getPropertiesFromResource("/rest.properties"); + @Override + @BeforeClass(groups = { "integration", "live" }) + public void setupContext() { + super.setupContext(); + client = context.getComputeService(); } + @Override protected Module getSshModule() { return new SshjSshClientModule(); } - - @AfterGroups(groups = { "live" }) - protected void cleanup() throws InterruptedException, ExecutionException, TimeoutException { - client.getContext().close(); - } } \ No newline at end of file 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 3679fc808c..e4f2cb3725 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 @@ -18,7 +18,6 @@ */ package org.jclouds.vcloud.internal; -import static org.jclouds.rest.RestContextFactory.contextSpec; import static org.testng.Assert.assertEquals; import java.io.IOException; @@ -30,8 +29,9 @@ import javax.ws.rs.core.HttpHeaders; import org.jclouds.http.HttpRequest; import org.jclouds.http.filters.BasicAuthentication; import org.jclouds.location.Provider; -import org.jclouds.rest.RestClientTest; -import org.jclouds.rest.RestContextSpec; +import org.jclouds.providers.ProviderMetadata; +import org.jclouds.rest.AnonymousProviderMetadata; +import org.jclouds.rest.internal.BaseAsyncClientTest; import org.jclouds.rest.internal.RestAnnotationProcessor; import org.jclouds.vcloud.endpoints.VCloudLogin; import org.jclouds.vcloud.functions.ParseLoginResponseFromHeaders; @@ -50,7 +50,7 @@ import com.google.inject.TypeLiteral; */ // NOTE:without testName, this will not call @Before* and fail w/NPE during surefire @Test(groups = "unit", testName = "VCloudLoginAsyncClientTest") -public class VCloudLoginAsyncClientTest extends RestClientTest { +public class VCloudLoginAsyncClientTest extends BaseAsyncClientTest { public void testLogin() throws SecurityException, NoSuchMethodException, IOException { Method method = VCloudLoginAsyncClient.class.getMethod("login"); @@ -97,10 +97,10 @@ public class VCloudLoginAsyncClientTest extends RestClientTest createContextSpec() { - return contextSpec("test", "http://localhost:8080/login", "1", "", "", "identity", "credential", - VCloudLoginClient.class, VCloudLoginAsyncClient.class); + protected ProviderMetadata createProviderMetadata() { + return AnonymousProviderMetadata.forClientMappedToAsyncClientOnEndpoint(VCloudLoginClient.class, + VCloudLoginAsyncClient.class, "http://localhost:8080/login"); } + } diff --git a/apis/walrus/pom.xml b/apis/walrus/pom.xml index 96d9236c1b..553d6bc2ce 100644 --- a/apis/walrus/pom.xml +++ b/apis/walrus/pom.xml @@ -34,7 +34,6 @@ bundle - org.jclouds.walrus.blobstore.WalrusTestInitializer http://ecc.eucalyptus.com:8773/services/Walrus 2006-03-01 @@ -101,7 +100,6 @@ - ${test.initializer} ${jclouds.blobstore.httpstream.url} ${jclouds.blobstore.httpstream.md5} ${test.walrus.endpoint} diff --git a/apis/walrus/src/main/java/org/jclouds/walrus/WalrusApiMetadata.java b/apis/walrus/src/main/java/org/jclouds/walrus/WalrusApiMetadata.java index 50ac5ace9d..d69db928ac 100644 --- a/apis/walrus/src/main/java/org/jclouds/walrus/WalrusApiMetadata.java +++ b/apis/walrus/src/main/java/org/jclouds/walrus/WalrusApiMetadata.java @@ -18,43 +18,69 @@ */ package org.jclouds.walrus; +import static org.jclouds.s3.reference.S3Constants.PROPERTY_S3_SERVICE_PATH; +import static org.jclouds.s3.reference.S3Constants.PROPERTY_S3_VIRTUAL_HOST_BUCKETS; + +import java.util.Properties; + import org.jclouds.apis.ApiMetadata; import org.jclouds.s3.S3ApiMetadata; +import org.jclouds.s3.S3AsyncClient; +import org.jclouds.s3.S3Client; +import org.jclouds.s3.blobstore.S3BlobStoreContext; + +import com.google.common.reflect.TypeToken; /** - * Implementation of {@link ApiMetadata} for the Walrus (S3 clone) api. + * Implementation of {@link ApiMetadata} for the Walrus S3 API * * @author Adrian Cole */ -public class WalrusApiMetadata extends S3ApiMetadata { +public class WalrusApiMetadata extends S3ApiMetadata, WalrusApiMetadata> { + private static Builder builder() { + return new Builder(); + } + + @Override + public Builder toBuilder() { + return builder().fromApiMetadata(this); + } public WalrusApiMetadata() { - this(builder().fromApiMetadata(new S3ApiMetadata()) - .id("walrus") - .name("Walrus (S3 clone) API")); + this(builder()); } - // below are so that we can reuse builders, toString, hashCode, etc. - // we have to set concrete classes here, as our base class cannot be - // concrete due to serviceLoader - protected WalrusApiMetadata(ConcreteBuilder builder) { + protected WalrusApiMetadata(Builder builder) { super(builder); } + + protected static Properties defaultProperties() { + Properties properties = S3ApiMetadata.defaultProperties(); + properties.setProperty(PROPERTY_S3_SERVICE_PATH, "/services/Walrus"); + properties.setProperty(PROPERTY_S3_VIRTUAL_HOST_BUCKETS, "false"); + return properties; + } - private static class ConcreteBuilder extends S3ApiMetadataBuilder { - + public static class Builder extends S3ApiMetadata.Builder, WalrusApiMetadata> { + protected Builder(){ + super(S3Client.class, S3AsyncClient.class); + id("walrus") + .name("Walrus (S3 clone) API") + .version("Walrus-1.6") + .defaultProperties(WalrusApiMetadata.defaultProperties()) + .contextBuilder(TypeToken.of(WalrusContextBuilder.class)); + } + @Override public WalrusApiMetadata build() { return new WalrusApiMetadata(this); } + + @Override + public Builder fromApiMetadata(WalrusApiMetadata in) { + super.fromApiMetadata(in); + return this; + } } - private static ConcreteBuilder builder() { - return new ConcreteBuilder(); - } - - @Override - public ConcreteBuilder toBuilder() { - return builder().fromApiMetadata(this); - } -} \ No newline at end of file +} diff --git a/apis/walrus/src/main/java/org/jclouds/walrus/WalrusContextBuilder.java b/apis/walrus/src/main/java/org/jclouds/walrus/WalrusContextBuilder.java index b7f6f33438..c6d3d1902f 100644 --- a/apis/walrus/src/main/java/org/jclouds/walrus/WalrusContextBuilder.java +++ b/apis/walrus/src/main/java/org/jclouds/walrus/WalrusContextBuilder.java @@ -19,9 +19,12 @@ package org.jclouds.walrus; import java.util.List; -import java.util.Properties; +import org.jclouds.providers.ProviderMetadata; +import org.jclouds.s3.S3AsyncClient; +import org.jclouds.s3.S3Client; import org.jclouds.s3.S3ContextBuilder; +import org.jclouds.s3.blobstore.S3BlobStoreContext; import org.jclouds.walrus.config.WalrusRestClientModule; import com.google.inject.Module; @@ -31,10 +34,19 @@ import com.google.inject.Module; * * @author Adrian Cole */ -public class WalrusContextBuilder extends S3ContextBuilder { +public class WalrusContextBuilder extends + S3ContextBuilder, WalrusApiMetadata> { + public WalrusContextBuilder() { + this(new WalrusApiMetadata()); + } - public WalrusContextBuilder(Properties props) { - super(props); + public WalrusContextBuilder( + ProviderMetadata, WalrusApiMetadata> providerMetadata) { + super(providerMetadata); + } + + public WalrusContextBuilder(WalrusApiMetadata apiMetadata) { + super(apiMetadata); } @Override diff --git a/apis/walrus/src/main/java/org/jclouds/walrus/WalrusPropertiesBuilder.java b/apis/walrus/src/main/java/org/jclouds/walrus/WalrusPropertiesBuilder.java deleted file mode 100644 index 6d61163568..0000000000 --- a/apis/walrus/src/main/java/org/jclouds/walrus/WalrusPropertiesBuilder.java +++ /dev/null @@ -1,48 +0,0 @@ -/** - * 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.walrus; - -import static org.jclouds.Constants.PROPERTY_API_VERSION; -import static org.jclouds.s3.reference.S3Constants.PROPERTY_S3_SERVICE_PATH; -import static org.jclouds.s3.reference.S3Constants.PROPERTY_S3_VIRTUAL_HOST_BUCKETS; - -import java.util.Properties; - -import org.jclouds.s3.S3PropertiesBuilder; - -/** - * Builds properties used in Walrus Clients - * - * @author Adrian Cole - */ -public class WalrusPropertiesBuilder extends S3PropertiesBuilder { - @Override - protected Properties defaultProperties() { - Properties properties = super.defaultProperties(); - properties.setProperty(PROPERTY_API_VERSION, "Walrus-1.6"); - properties.setProperty(PROPERTY_S3_SERVICE_PATH, "/services/Walrus"); - properties.setProperty(PROPERTY_S3_VIRTUAL_HOST_BUCKETS, "false"); - return properties; - } - - public WalrusPropertiesBuilder(Properties properties) { - super(properties); - } - -} diff --git a/apis/walrus/src/test/java/org/jclouds/walrus/WalrusApiMetadataTest.java b/apis/walrus/src/test/java/org/jclouds/walrus/WalrusApiMetadataTest.java index ca5dbf801d..abc4963b0a 100644 --- a/apis/walrus/src/test/java/org/jclouds/walrus/WalrusApiMetadataTest.java +++ b/apis/walrus/src/test/java/org/jclouds/walrus/WalrusApiMetadataTest.java @@ -18,8 +18,7 @@ */ package org.jclouds.walrus; -import org.jclouds.apis.ApiType; -import org.jclouds.apis.BaseApiMetadataTest; +import org.jclouds.blobstore.internal.BaseBlobStoreApiMetadataTest; import org.testng.annotations.Test; /** @@ -27,9 +26,9 @@ import org.testng.annotations.Test; * @author Adrian Cole */ @Test(groups = "unit", testName = "WalrusApiMetadataTest") -public class WalrusApiMetadataTest extends BaseApiMetadataTest { +public class WalrusApiMetadataTest extends BaseBlobStoreApiMetadataTest { public WalrusApiMetadataTest() { - super(new WalrusApiMetadata(), ApiType.BLOBSTORE); + super(new WalrusApiMetadata()); } } diff --git a/apis/walrus/src/test/java/org/jclouds/walrus/WalrusAsyncClientTestDisabled.java b/apis/walrus/src/test/java/org/jclouds/walrus/WalrusAsyncClientTestDisabled.java deleted file mode 100644 index dee43e8856..0000000000 --- a/apis/walrus/src/test/java/org/jclouds/walrus/WalrusAsyncClientTestDisabled.java +++ /dev/null @@ -1,47 +0,0 @@ -/** - * 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.walrus; - -import org.jclouds.rest.internal.RestAnnotationProcessor; -import org.jclouds.s3.S3AsyncClient; -import org.jclouds.s3.S3AsyncClientTest; -import org.testng.annotations.Test; - -import com.google.inject.TypeLiteral; - -/** - * @author Adrian Cole - */ -// NOTE:without testName, this will not call @Before* and fail w/NPE during surefire -@Test(enabled = false, groups = "unit", testName = "WalrusAsyncClientTest") -public class WalrusAsyncClientTestDisabled extends S3AsyncClientTest { - - @Override - protected TypeLiteral> createTypeLiteral() { - return new TypeLiteral>() { - }; - } - - public WalrusAsyncClientTestDisabled() { - this.provider = "walrus"; - this.url = "commondatastorage.googleapis.com"; - } - - // TODO parameterize this test so that it can pass -} diff --git a/apis/walrus/src/test/java/org/jclouds/walrus/blobstore/WalrusBlobIntegrationLiveTest.java b/apis/walrus/src/test/java/org/jclouds/walrus/blobstore/WalrusBlobIntegrationLiveTest.java index a132e97528..e6b26491e2 100644 --- a/apis/walrus/src/test/java/org/jclouds/walrus/blobstore/WalrusBlobIntegrationLiveTest.java +++ b/apis/walrus/src/test/java/org/jclouds/walrus/blobstore/WalrusBlobIntegrationLiveTest.java @@ -29,7 +29,11 @@ import org.testng.annotations.Test; */ @Test(groups = "live", testName = "WalrusBlobIntegrationLiveTest") public class WalrusBlobIntegrationLiveTest extends S3BlobIntegrationLiveTest { - + + public WalrusBlobIntegrationLiveTest() { + provider = "walrus"; + } + // no support for content encoding @Override protected void checkContentEncoding(Blob blob, String contentEncoding) { diff --git a/apis/walrus/src/test/java/org/jclouds/walrus/blobstore/WalrusBlobLiveTest.java b/apis/walrus/src/test/java/org/jclouds/walrus/blobstore/WalrusBlobLiveTest.java index 2432d2369d..509f47bf0d 100644 --- a/apis/walrus/src/test/java/org/jclouds/walrus/blobstore/WalrusBlobLiveTest.java +++ b/apis/walrus/src/test/java/org/jclouds/walrus/blobstore/WalrusBlobLiveTest.java @@ -26,5 +26,9 @@ import org.testng.annotations.Test; */ @Test(groups = "live", testName = "WalrusBlobLiveTest") public class WalrusBlobLiveTest extends S3BlobLiveTest { - + + public WalrusBlobLiveTest() { + provider = "walrus"; + } + } diff --git a/apis/walrus/src/test/java/org/jclouds/walrus/blobstore/WalrusBlobMapIntegrationLiveTest.java b/apis/walrus/src/test/java/org/jclouds/walrus/blobstore/WalrusBlobMapIntegrationLiveTest.java index 66b6816a93..c9b2fbd35d 100644 --- a/apis/walrus/src/test/java/org/jclouds/walrus/blobstore/WalrusBlobMapIntegrationLiveTest.java +++ b/apis/walrus/src/test/java/org/jclouds/walrus/blobstore/WalrusBlobMapIntegrationLiveTest.java @@ -26,5 +26,9 @@ import org.testng.annotations.Test; */ @Test(groups = "live", testName = "WalrusBlobMapIntegrationLiveTest") public class WalrusBlobMapIntegrationLiveTest extends S3BlobMapIntegrationLiveTest { - + + public WalrusBlobMapIntegrationLiveTest() { + provider = "walrus"; + } + } diff --git a/apis/walrus/src/test/java/org/jclouds/walrus/blobstore/WalrusBlobSignerLiveTest.java b/apis/walrus/src/test/java/org/jclouds/walrus/blobstore/WalrusBlobSignerLiveTest.java index 3d72a567a9..0254aef9dd 100644 --- a/apis/walrus/src/test/java/org/jclouds/walrus/blobstore/WalrusBlobSignerLiveTest.java +++ b/apis/walrus/src/test/java/org/jclouds/walrus/blobstore/WalrusBlobSignerLiveTest.java @@ -27,5 +27,9 @@ import org.testng.annotations.Test; */ @Test(groups = "live", testName = "WalrusBlobSignerLiveTest") public class WalrusBlobSignerLiveTest extends S3BlobSignerLiveTest { - + + public WalrusBlobSignerLiveTest() { + provider = "walrus"; + } + } diff --git a/apis/walrus/src/test/java/org/jclouds/walrus/blobstore/WalrusContainerIntegrationLiveTest.java b/apis/walrus/src/test/java/org/jclouds/walrus/blobstore/WalrusContainerIntegrationLiveTest.java index 7864cc5e31..145e9d30ff 100644 --- a/apis/walrus/src/test/java/org/jclouds/walrus/blobstore/WalrusContainerIntegrationLiveTest.java +++ b/apis/walrus/src/test/java/org/jclouds/walrus/blobstore/WalrusContainerIntegrationLiveTest.java @@ -26,5 +26,9 @@ import org.testng.annotations.Test; */ @Test(groups = "live", testName = "WalrusContainerIntegrationLiveTest") public class WalrusContainerIntegrationLiveTest extends S3ContainerIntegrationLiveTest { - + + public WalrusContainerIntegrationLiveTest() { + provider = "walrus"; + } + } diff --git a/apis/walrus/src/test/java/org/jclouds/walrus/blobstore/WalrusContainerLiveTest.java b/apis/walrus/src/test/java/org/jclouds/walrus/blobstore/WalrusContainerLiveTest.java index 1ae6e69527..cca820a115 100644 --- a/apis/walrus/src/test/java/org/jclouds/walrus/blobstore/WalrusContainerLiveTest.java +++ b/apis/walrus/src/test/java/org/jclouds/walrus/blobstore/WalrusContainerLiveTest.java @@ -26,5 +26,9 @@ import org.testng.annotations.Test; */ @Test(groups = "live", testName = "WalrusContainerLiveTest") public class WalrusContainerLiveTest extends S3ContainerLiveTest { - + + public WalrusContainerLiveTest() { + provider = "walrus"; + } + } diff --git a/apis/walrus/src/test/java/org/jclouds/walrus/blobstore/WalrusInputStreamMapIntegrationLiveTest.java b/apis/walrus/src/test/java/org/jclouds/walrus/blobstore/WalrusInputStreamMapIntegrationLiveTest.java index d182ed87c5..6e447ac4ad 100644 --- a/apis/walrus/src/test/java/org/jclouds/walrus/blobstore/WalrusInputStreamMapIntegrationLiveTest.java +++ b/apis/walrus/src/test/java/org/jclouds/walrus/blobstore/WalrusInputStreamMapIntegrationLiveTest.java @@ -26,5 +26,9 @@ import org.testng.annotations.Test; */ @Test(groups = "live", testName = "WalrusInputStreamMapIntegrationLiveTest") public class WalrusInputStreamMapIntegrationLiveTest extends S3InputStreamMapIntegrationLiveTest { - + + public WalrusInputStreamMapIntegrationLiveTest() { + provider = "walrus"; + } + } diff --git a/apis/walrus/src/test/java/org/jclouds/walrus/blobstore/WalrusServiceIntegrationLiveTest.java b/apis/walrus/src/test/java/org/jclouds/walrus/blobstore/WalrusServiceIntegrationLiveTest.java index c1cb853d59..b502fd6e6e 100644 --- a/apis/walrus/src/test/java/org/jclouds/walrus/blobstore/WalrusServiceIntegrationLiveTest.java +++ b/apis/walrus/src/test/java/org/jclouds/walrus/blobstore/WalrusServiceIntegrationLiveTest.java @@ -26,5 +26,9 @@ import org.testng.annotations.Test; */ @Test(groups = "live", testName = "WalrusServiceIntegrationLiveTest") public class WalrusServiceIntegrationLiveTest extends S3ServiceIntegrationLiveTest { - + + public WalrusServiceIntegrationLiveTest() { + provider = "walrus"; + } + } diff --git a/archetypes/rest-client-archetype/src/main/resources/archetype-resources/src/test/java/__providerName__AsyncClientTest.java b/archetypes/rest-client-archetype/src/main/resources/archetype-resources/src/test/java/__providerName__AsyncClientTest.java index b367b4a8f1..5097e7caa9 100644 --- a/archetypes/rest-client-archetype/src/main/resources/archetype-resources/src/test/java/__providerName__AsyncClientTest.java +++ b/archetypes/rest-client-archetype/src/main/resources/archetype-resources/src/test/java/__providerName__AsyncClientTest.java @@ -32,7 +32,7 @@ import org.jclouds.http.HttpRequest; import org.jclouds.http.filters.BasicAuthentication; import org.jclouds.http.functions.ReleasePayloadAndReturn; import org.jclouds.http.functions.ReturnStringIf2xx; -import org.jclouds.rest.RestClientTest; +import org.jclouds.rest.internal.BaseAsyncClientTest; import org.jclouds.rest.RestContextFactory.ContextSpec; import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404; import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; @@ -52,7 +52,7 @@ import com.google.inject.TypeLiteral; * @author ${author} */ @Test(groups = "unit", testName = "${lcaseProviderName}.${providerName}AsyncClientTest") -public class ${providerName}AsyncClientTest extends RestClientTest<${providerName}AsyncClient> { +public class ${providerName}AsyncClientTest extends BaseAsyncClientTest<${providerName}AsyncClient> { public void testList() throws SecurityException, NoSuchMethodException, IOException { diff --git a/blobstore/pom.xml b/blobstore/pom.xml index 7a3ebe5522..892e18495a 100644 --- a/blobstore/pom.xml +++ b/blobstore/pom.xml @@ -38,10 +38,6 @@ http://jclouds.googlecode.com/svn/trunk/blobstore - - org.jclouds.blobstore.integration.TransientBlobStoreTestInitializer - - ${project.groupId} @@ -77,7 +73,6 @@ **/*IntegrationTest.java - ${test.initializer} ${jclouds.blobstore.httpstream.url} ${jclouds.blobstore.httpstream.md5} diff --git a/blobstore/src/main/java/org/jclouds/blobstore/AsyncBlobStore.java b/blobstore/src/main/java/org/jclouds/blobstore/AsyncBlobStore.java index cf2897988b..1a7427e43d 100644 --- a/blobstore/src/main/java/org/jclouds/blobstore/AsyncBlobStore.java +++ b/blobstore/src/main/java/org/jclouds/blobstore/AsyncBlobStore.java @@ -43,7 +43,7 @@ public interface AsyncBlobStore { /** * @see BlobStore#getContext */ - BlobStoreContext getContext(); + BlobStoreContext getContext(); /** * @see BlobStore#blobBuilder diff --git a/blobstore/src/main/java/org/jclouds/blobstore/BlobStore.java b/blobstore/src/main/java/org/jclouds/blobstore/BlobStore.java index b9fa416c25..89a9b4359a 100644 --- a/blobstore/src/main/java/org/jclouds/blobstore/BlobStore.java +++ b/blobstore/src/main/java/org/jclouds/blobstore/BlobStore.java @@ -44,7 +44,7 @@ public interface BlobStore { /** * @return a reference to the context that created this BlobStore. */ - BlobStoreContext getContext(); + BlobStoreContext getContext(); /** * diff --git a/blobstore/src/main/java/org/jclouds/blobstore/BlobStoreApiMetadata.java b/blobstore/src/main/java/org/jclouds/blobstore/BlobStoreApiMetadata.java new file mode 100644 index 0000000000..77d55ce334 --- /dev/null +++ b/blobstore/src/main/java/org/jclouds/blobstore/BlobStoreApiMetadata.java @@ -0,0 +1,20 @@ +package org.jclouds.blobstore; + +import org.jclouds.apis.ApiMetadata; + +import com.google.common.annotations.Beta; + +/** + * + * @author Adrian Cole + * @since 1.5 + */ +@Beta +public interface BlobStoreApiMetadata, M extends BlobStoreApiMetadata> + extends ApiMetadata { + + public static interface Builder, M extends BlobStoreApiMetadata> + extends ApiMetadata.Builder { + } + +} \ No newline at end of file diff --git a/blobstore/src/main/java/org/jclouds/blobstore/BlobStoreContext.java b/blobstore/src/main/java/org/jclouds/blobstore/BlobStoreContext.java index 04df9d598a..81f42afbe1 100644 --- a/blobstore/src/main/java/org/jclouds/blobstore/BlobStoreContext.java +++ b/blobstore/src/main/java/org/jclouds/blobstore/BlobStoreContext.java @@ -18,10 +18,12 @@ */ package org.jclouds.blobstore; +import java.io.Closeable; + import org.jclouds.blobstore.attr.ConsistencyModel; import org.jclouds.blobstore.internal.BlobStoreContextImpl; import org.jclouds.blobstore.options.ListContainerOptions; -import org.jclouds.rest.RestContext; +import org.jclouds.rest.BackedByRestContext; import org.jclouds.rest.Utils; import com.google.inject.ImplementedBy; @@ -34,7 +36,7 @@ import com.google.inject.ImplementedBy; * */ @ImplementedBy(BlobStoreContextImpl.class) -public interface BlobStoreContext { +public interface BlobStoreContext extends Closeable, BackedByRestContext { /** * * Generates signed requests for blobs. useful in other tools such as backup utilities. @@ -105,12 +107,6 @@ public interface BlobStoreContext { */ ConsistencyModel getConsistencyModel(); - /** - * - * @return a context you can use to the access provider or vendor specific api underlying this - * context. - */ - RestContext getProviderSpecificContext(); Utils getUtils(); @@ -123,5 +119,6 @@ public interface BlobStoreContext { * closes threads and resources related to this connection. * */ + @Override void close(); } \ No newline at end of file diff --git a/blobstore/src/main/java/org/jclouds/blobstore/BlobStoreContextBuilder.java b/blobstore/src/main/java/org/jclouds/blobstore/BlobStoreContextBuilder.java index fe507350b9..e38fad5fa1 100644 --- a/blobstore/src/main/java/org/jclouds/blobstore/BlobStoreContextBuilder.java +++ b/blobstore/src/main/java/org/jclouds/blobstore/BlobStoreContextBuilder.java @@ -17,32 +17,47 @@ * under the License. */ package org.jclouds.blobstore; +import static com.google.common.base.Preconditions.checkArgument; -import java.util.Properties; +import java.util.NoSuchElementException; -import org.jclouds.rest.RestContextBuilder; - -import com.google.inject.Module; +import org.jclouds.blobstore.config.TransientBlobStore; +import org.jclouds.providers.ProviderMetadata; +import org.jclouds.rest.internal.ContextBuilder; /** * @author Adrian Cole */ -public abstract class BlobStoreContextBuilder extends RestContextBuilder { - - @Override - public BlobStoreContextBuilder withModules(Iterable modules) { - return (BlobStoreContextBuilder) super.withModules(modules); +public abstract class BlobStoreContextBuilder, M extends BlobStoreApiMetadata> + extends ContextBuilder { + + /** + * looks up a provider or api with the given id + * + * @param providerOrApi + * id of the provider or api + * @return means to build a context to that provider + * @throws NoSuchElementException + * if the id was not configured. + * @throws IllegalArgumentException + * if the api or provider isn't assignable from BlobStoreContext + */ + public static BlobStoreContextBuilder newBuilder(String providerOrApi) throws NoSuchElementException { + ContextBuilder builder = ContextBuilder.newBuilder(providerOrApi); + checkArgument(builder instanceof BlobStoreContextBuilder, + "type of providerOrApi[%s] is not BlobStoreContextBuilder: %s", providerOrApi, builder); + return BlobStoreContextBuilder.class.cast(builder); + } + + public static ContextBuilder, TransientApiMetadata> forTests() { + return ContextBuilder.newBuilder(new TransientApiMetadata()); } - public BlobStoreContextBuilder(Class syncClientType, Class asyncClientType) { - this(syncClientType, asyncClientType, new Properties()); + public BlobStoreContextBuilder(ProviderMetadata providerMetadata) { + super(providerMetadata); } - public BlobStoreContextBuilder(Class syncClientType, Class asyncClientType, Properties properties) { - super(syncClientType, asyncClientType, properties); - } - - public BlobStoreContext buildBlobStoreContext() { - return buildInjector().getInstance(BlobStoreContext.class); + public BlobStoreContextBuilder(M apiMetadata) { + super(apiMetadata); } } \ No newline at end of file diff --git a/blobstore/src/main/java/org/jclouds/blobstore/BlobStoreContextFactory.java b/blobstore/src/main/java/org/jclouds/blobstore/BlobStoreContextFactory.java index b217065484..9c32b49d99 100644 --- a/blobstore/src/main/java/org/jclouds/blobstore/BlobStoreContextFactory.java +++ b/blobstore/src/main/java/org/jclouds/blobstore/BlobStoreContextFactory.java @@ -18,124 +18,114 @@ */ package org.jclouds.blobstore; -import static org.jclouds.rest.RestContextFactory.createContextBuilder; -import static org.jclouds.util.Throwables2.propagateAuthorizationOrOriginalException; - +import java.util.NoSuchElementException; import java.util.Properties; +import org.jclouds.apis.Apis; import org.jclouds.javax.annotation.Nullable; -import org.jclouds.rest.RestContextFactory; -import org.jclouds.rest.RestContextSpec; +import org.jclouds.providers.ProviderMetadata; +import org.jclouds.providers.Providers; +import org.jclouds.rest.internal.ContextBuilder; +import com.google.common.collect.ImmutableSet; import com.google.inject.Module; /** - * Helper class to instantiate {@code BlobStoreContext} instances. * + * @see ContextBuilder + * @see BlobStoreContextBuilder * @author Adrian Cole */ +@Deprecated public class BlobStoreContextFactory { - private final RestContextFactory contextFactory; - /** - * Initializes with the default properties built-in to jclouds. This is - * typically stored in the classpath resource {@code rest.properties} - * - * @see RestContextFactory#getPropertiesFromResource + * for porting old code to {@link ContextBuilder} */ public BlobStoreContextFactory() { - this(new RestContextFactory()); } /** - * Finds definitions in the specified properties. + * for porting old code to {@link ContextBuilder} */ public BlobStoreContextFactory(Properties properties) { - this(new RestContextFactory(properties)); } /** + * @see #createContext(String, String,String, Iterable, Properties) + */ + public BlobStoreContext createContext(String providerOrApi, String identity, String credential) { + return createContext(providerOrApi, identity, credential, ImmutableSet. of(), new Properties()); + } + + /** + * @see #createContext(String, String, String, Iterable, Properties) + */ + public BlobStoreContext createContext(String providerOrApi, Properties overrides) { + return createContext(providerOrApi, null, null, ImmutableSet. of(), overrides); + } + + /** + * @see #createContext(String, String,String, Iterable, Properties) + */ + public BlobStoreContext createContext(String providerOrApi, Iterable wiring, + Properties overrides) { + return createContext(providerOrApi, null, null, wiring, overrides); + } + + /** + * @see #createContext(String, String,String, Iterable, Properties) + */ + public BlobStoreContext createContext(String providerOrApi, @Nullable String identity, + @Nullable String credential, Properties overrides) { + return createContext(providerOrApi, identity, credential, ImmutableSet. of(), overrides); + } + + /** + * @see createContext(String, String,String, Iterable, Properties) + */ + public BlobStoreContext createContext(String providerOrApi, @Nullable String identity, + @Nullable String credential, Iterable wiring) { + return createContext(providerOrApi, identity, credential, wiring, new Properties()); + } + + /** + * for porting old code to {@link ContextBuilder} * - * Uses the supplied RestContextFactory to create {@link BlobStoreContext}s + * @param providerOrApi + * @param identity + * nullable, if credentials are present in the overrides + * @param credential + * nullable, if credentials are present in the overrides + * @param wiring + * Configuration you'd like to pass to the context. Ex. + * ImmutableSet.of(new ExecutorServiceModule(myexecutor)) + * @param overrides + * properties to override defaults with. + * @return initialized context ready for use */ - public BlobStoreContextFactory(RestContextFactory restContextFactory) { - this.contextFactory = restContextFactory; - } - - public static BlobStoreContext buildContextUnwrappingExceptions(BlobStoreContextBuilder builder) { + @SuppressWarnings("unchecked") + public BlobStoreContext createContext(String providerOrApi, @Nullable String identity, + @Nullable String credential, Iterable wiring, Properties overrides) { + ContextBuilder builder = null; try { - return builder.buildBlobStoreContext(); - } catch (Exception e) { - return propagateAuthorizationOrOriginalException(e); + ProviderMetadata pm = Providers.withId(providerOrApi); + builder = BlobStoreContextBuilder.newBuilder(pm); + } catch (NoSuchElementException e) { + builder = ContextBuilder.newBuilder(Apis.withId(providerOrApi)); + } + builder.modules(Iterable.class.cast(wiring)); + builder.overrides(overrides); + if (identity != null) + builder.credentials(identity, credential); + Object context = builder.build(); + if (context instanceof BlobStoreContext) { + return BlobStoreContext.class.cast(context); + } else { + throw new IllegalArgumentException("provider " + providerOrApi + " contains an unknown context type: " + + context.getClass().getSimpleName()); } - } - - /** - * @see RestContextFactory#createContextBuilder(String, String, String) - */ - public BlobStoreContext createContext(String provider, String identity, String credential) { - BlobStoreContextBuilder builder = BlobStoreContextBuilder.class.cast(contextFactory.createContextBuilder( - provider, identity, credential)); - return buildContextUnwrappingExceptions(builder); - } - - /** - * @see RestContextFactory#createContextBuilder(String, Properties) - */ - public BlobStoreContext createContext(String provider, Properties overrides) { - BlobStoreContextBuilder builder = BlobStoreContextBuilder.class.cast(contextFactory.createContextBuilder( - provider, overrides)); - return buildContextUnwrappingExceptions(builder); - } - - /** - * @see RestContextFactory#createContextBuilder(String, Iterable) - */ - public BlobStoreContext createContext(String provider, Iterable modules, Properties overrides) { - BlobStoreContextBuilder builder = BlobStoreContextBuilder.class.cast(contextFactory.createContextBuilder( - provider, modules, overrides)); - return buildContextUnwrappingExceptions(builder); } - /** - * @see RestContextFactory#createContextBuilder(String, String,String, - * Iterable) - */ - public BlobStoreContext createContext(String provider, @Nullable String identity, @Nullable String credential, - Iterable modules) { - BlobStoreContextBuilder builder = BlobStoreContextBuilder.class.cast(contextFactory.createContextBuilder( - provider, identity, credential, modules)); - return buildContextUnwrappingExceptions(builder); - } - - /** - * @see RestContextFactory#createContextBuilder(String, String,String, - * Iterable, Properties) - */ - public BlobStoreContext createContext(String provider, @Nullable String identity, @Nullable String credential, - Iterable modules, Properties overrides) { - BlobStoreContextBuilder builder = BlobStoreContextBuilder.class.cast(contextFactory.createContextBuilder( - provider, identity, credential, modules, overrides)); - return buildContextUnwrappingExceptions(builder); - } - - /** - * @see RestContextFactory#createContextBuilder(RestContextSpec) - */ - public BlobStoreContext createContext(RestContextSpec contextSpec) { - BlobStoreContextBuilder builder = BlobStoreContextBuilder.class.cast(createContextBuilder(contextSpec)); - return buildContextUnwrappingExceptions(builder); - - } - - /** - * @see RestContextFactory#createContextBuilder(RestContextSpec, Properties) - */ - public BlobStoreContext createContext(RestContextSpec contextSpec, Properties overrides) { - BlobStoreContextBuilder builder = BlobStoreContextBuilder.class.cast(createContextBuilder(contextSpec, - overrides)); - return buildContextUnwrappingExceptions(builder); - } -} \ No newline at end of file +} diff --git a/blobstore/src/main/java/org/jclouds/blobstore/TransientApiMetadata.java b/blobstore/src/main/java/org/jclouds/blobstore/TransientApiMetadata.java index 815114d2eb..fbd1465eb7 100644 --- a/blobstore/src/main/java/org/jclouds/blobstore/TransientApiMetadata.java +++ b/blobstore/src/main/java/org/jclouds/blobstore/TransientApiMetadata.java @@ -18,50 +18,68 @@ */ package org.jclouds.blobstore; +import static org.jclouds.Constants.PROPERTY_IO_WORKER_THREADS; +import static org.jclouds.Constants.PROPERTY_USER_THREADS; + import java.net.URI; import org.jclouds.apis.ApiMetadata; -import org.jclouds.apis.ApiType; -import org.jclouds.apis.BaseApiMetadata; +import org.jclouds.apis.internal.BaseApiMetadata; +import org.jclouds.blobstore.config.TransientBlobStore; +import org.jclouds.blobstore.internal.BaseBlobStoreApiMetadata; + +import com.google.common.collect.ImmutableMap; +import com.google.common.reflect.TypeToken; /** * Implementation of {@link ApiMetadata} for jclouds in-memory (Transient) API * * @author Adrian Cole */ -public class TransientApiMetadata extends BaseApiMetadata { +public class TransientApiMetadata extends + BaseBlobStoreApiMetadata, TransientApiMetadata> { - public TransientApiMetadata() { - this(builder() - .id("transient") - .type(ApiType.BLOBSTORE) - .name("in-memory (Transient) API") - .identityName("Unused") - .documentation(URI.create("http://www.jclouds.org/documentation/userguide/blobstore-guide"))); + public static Builder builder() { + return new Builder(); } - // below are so that we can reuse builders, toString, hashCode, etc. - // we have to set concrete classes here, as our base class cannot be - // concrete due to serviceLoader - protected TransientApiMetadata(ConcreteBuilder builder) { + @Override + public Builder toBuilder() { + return Builder.class.cast(builder().fromApiMetadata(this)); + } + + public TransientApiMetadata() { + super(builder()); + } + + protected TransientApiMetadata(Builder builder) { super(builder); } - private static class ConcreteBuilder extends Builder { + public static class Builder extends + BaseBlobStoreApiMetadata.Builder, TransientApiMetadata> { + + protected Builder() { + id("transient") + .name("in-memory (Transient) API") + .javaApi(TransientBlobStore.class, AsyncBlobStore.class) + .contextBuilder(TypeToken.of(TransientBlobStoreContextBuilder.class)) + .identityName("Unused") + .defaultEndpoint("http://localhost") + .defaultIdentity(System.getProperty("user.name")) + .defaultCredential("bar") + .version("1") + .defaultProperties( + BaseBlobStoreApiMetadata.Builder.defaultPropertiesAnd(ImmutableMap.of(PROPERTY_USER_THREADS, "0", + PROPERTY_IO_WORKER_THREADS, "0"))) + .documentation(URI.create("http://www.jclouds.org/documentation/userguide/blobstore-guide")); + } @Override public TransientApiMetadata build() { return new TransientApiMetadata(this); } - } - public static ConcreteBuilder builder() { - return new ConcreteBuilder(); - } - - @Override - public ConcreteBuilder toBuilder() { - return builder().fromApiMetadata(this); } } \ No newline at end of file diff --git a/blobstore/src/main/java/org/jclouds/blobstore/TransientAsyncBlobStore.java b/blobstore/src/main/java/org/jclouds/blobstore/TransientAsyncBlobStore.java index 81ef2f5dfd..44fdce6afa 100644 --- a/blobstore/src/main/java/org/jclouds/blobstore/TransientAsyncBlobStore.java +++ b/blobstore/src/main/java/org/jclouds/blobstore/TransientAsyncBlobStore.java @@ -128,7 +128,7 @@ public class TransientAsyncBlobStore extends BaseAsyncBlobStore { protected final Factory blobFactory; @Inject - protected TransientAsyncBlobStore(BlobStoreContext context, DateService dateService, Crypto crypto, + protected TransientAsyncBlobStore(@SuppressWarnings("rawtypes") BlobStoreContext context, DateService dateService, Crypto crypto, ConcurrentMap> containerToBlobs, Provider uriBuilders, ConcurrentMap containerToLocation, HttpGetOptionsListToGetOptions httpGetOptionsConverter, diff --git a/blobstore/src/main/java/org/jclouds/blobstore/TransientBlobStoreContextBuilder.java b/blobstore/src/main/java/org/jclouds/blobstore/TransientBlobStoreContextBuilder.java index 6c14b2909f..e85910ecad 100644 --- a/blobstore/src/main/java/org/jclouds/blobstore/TransientBlobStoreContextBuilder.java +++ b/blobstore/src/main/java/org/jclouds/blobstore/TransientBlobStoreContextBuilder.java @@ -19,10 +19,11 @@ package org.jclouds.blobstore; import java.util.List; -import java.util.Properties; +import org.jclouds.blobstore.config.TransientBlobStore; import org.jclouds.blobstore.config.TransientBlobStoreContextModule; import org.jclouds.blobstore.config.TransientBlobStoreModule; +import org.jclouds.providers.ProviderMetadata; import com.google.inject.Module; @@ -30,18 +31,15 @@ import com.google.inject.Module; * @author Adrian Cole */ public class TransientBlobStoreContextBuilder extends - BlobStoreContextBuilder { + BlobStoreContextBuilder, TransientApiMetadata> { - /** - * This is only to have the same syntax. - * - */ - public TransientBlobStoreContextBuilder() { - this(new Properties()); + public TransientBlobStoreContextBuilder( + ProviderMetadata, TransientApiMetadata> providerMetadata) { + super(providerMetadata); } - - public TransientBlobStoreContextBuilder(Properties props) { - super(BlobStore.class, AsyncBlobStore.class, props); + + public TransientBlobStoreContextBuilder(TransientApiMetadata apiMetadata) { + super(apiMetadata); } @Override diff --git a/blobstore/src/main/java/org/jclouds/blobstore/TransientBlobStorePropertiesBuilder.java b/blobstore/src/main/java/org/jclouds/blobstore/TransientBlobStorePropertiesBuilder.java deleted file mode 100644 index a9de3a0d85..0000000000 --- a/blobstore/src/main/java/org/jclouds/blobstore/TransientBlobStorePropertiesBuilder.java +++ /dev/null @@ -1,52 +0,0 @@ -/** - * 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.blobstore; - -import static org.jclouds.Constants.PROPERTY_API_VERSION; -import static org.jclouds.Constants.PROPERTY_ENDPOINT; -import static org.jclouds.Constants.PROPERTY_IDENTITY; -import static org.jclouds.Constants.PROPERTY_IO_WORKER_THREADS; -import static org.jclouds.Constants.PROPERTY_USER_THREADS; - -import java.util.Properties; - -import org.jclouds.PropertiesBuilder; - -/** - * Builds properties used in transient blobstores - * - * @author Adrian Cole - */ -public class TransientBlobStorePropertiesBuilder extends PropertiesBuilder { - @Override - protected Properties defaultProperties() { - Properties properties = super.defaultProperties(); - properties.setProperty(PROPERTY_ENDPOINT, "http://localhost"); - properties.setProperty(PROPERTY_API_VERSION, "1"); - properties.setProperty(PROPERTY_IDENTITY, System.getProperty("user.name")); - properties.setProperty(PROPERTY_USER_THREADS, "0"); - properties.setProperty(PROPERTY_IO_WORKER_THREADS, "0"); - return properties; - } - - public TransientBlobStorePropertiesBuilder(Properties properties) { - super(properties); - } - -} diff --git a/blobstore/src/main/java/org/jclouds/blobstore/config/TransientBlobStore.java b/blobstore/src/main/java/org/jclouds/blobstore/config/TransientBlobStore.java index 2f50c12186..b088d5fa28 100644 --- a/blobstore/src/main/java/org/jclouds/blobstore/config/TransientBlobStore.java +++ b/blobstore/src/main/java/org/jclouds/blobstore/config/TransientBlobStore.java @@ -23,6 +23,7 @@ import java.util.concurrent.TimeUnit; import org.jclouds.blobstore.BlobStore; import org.jclouds.concurrent.Timeout; -@Timeout(duration = 2, timeUnit = TimeUnit.MINUTES) interface TransientBlobStore extends BlobStore { +@Timeout(duration = 2, timeUnit = TimeUnit.MINUTES) +public interface TransientBlobStore extends BlobStore { } \ No newline at end of file diff --git a/blobstore/src/main/java/org/jclouds/blobstore/config/TransientBlobStoreContextModule.java b/blobstore/src/main/java/org/jclouds/blobstore/config/TransientBlobStoreContextModule.java index 001db97086..2381329687 100644 --- a/blobstore/src/main/java/org/jclouds/blobstore/config/TransientBlobStoreContextModule.java +++ b/blobstore/src/main/java/org/jclouds/blobstore/config/TransientBlobStoreContextModule.java @@ -47,6 +47,7 @@ public class TransientBlobStoreContextModule extends AbstractModule { static final ConcurrentHashMap> map = new ConcurrentHashMap>(); static final ConcurrentHashMap containerToLocation = new ConcurrentHashMap(); + @SuppressWarnings("rawtypes") @Override protected void configure() { bind(new TypeLiteral() { diff --git a/blobstore/src/main/java/org/jclouds/blobstore/internal/BaseAsyncBlobStore.java b/blobstore/src/main/java/org/jclouds/blobstore/internal/BaseAsyncBlobStore.java index ef1b3f455b..f698a7b6ca 100644 --- a/blobstore/src/main/java/org/jclouds/blobstore/internal/BaseAsyncBlobStore.java +++ b/blobstore/src/main/java/org/jclouds/blobstore/internal/BaseAsyncBlobStore.java @@ -53,14 +53,14 @@ import com.google.common.util.concurrent.ListenableFuture; */ public abstract class BaseAsyncBlobStore implements AsyncBlobStore { - protected final BlobStoreContext context; + protected final BlobStoreContext context; protected final BlobUtils blobUtils; protected final ExecutorService service; protected final Supplier defaultLocation; protected final Supplier> locations; @Inject - protected BaseAsyncBlobStore(BlobStoreContext context, BlobUtils blobUtils, + protected BaseAsyncBlobStore(@SuppressWarnings("rawtypes") BlobStoreContext context, BlobUtils blobUtils, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService service, Supplier defaultLocation, @Memoized Supplier> locations) { this.context = checkNotNull(context, "context"); @@ -71,7 +71,7 @@ public abstract class BaseAsyncBlobStore implements AsyncBlobStore { } @Override - public BlobStoreContext getContext() { + public BlobStoreContext getContext() { return context; } diff --git a/blobstore/src/main/java/org/jclouds/blobstore/internal/BaseBlobStore.java b/blobstore/src/main/java/org/jclouds/blobstore/internal/BaseBlobStore.java index dc344cf454..8b2d980452 100644 --- a/blobstore/src/main/java/org/jclouds/blobstore/internal/BaseBlobStore.java +++ b/blobstore/src/main/java/org/jclouds/blobstore/internal/BaseBlobStore.java @@ -47,13 +47,13 @@ import com.google.common.base.Supplier; */ public abstract class BaseBlobStore implements BlobStore { - protected final BlobStoreContext context; + protected final BlobStoreContext context; protected final BlobUtils blobUtils; protected final Supplier defaultLocation; protected final Supplier> locations; @Inject - protected BaseBlobStore(BlobStoreContext context, BlobUtils blobUtils, Supplier defaultLocation, + protected BaseBlobStore(@SuppressWarnings("rawtypes") BlobStoreContext context, BlobUtils blobUtils, Supplier defaultLocation, @Memoized Supplier> locations) { this.context = checkNotNull(context, "context"); this.blobUtils = checkNotNull(blobUtils, "blobUtils"); @@ -62,7 +62,7 @@ public abstract class BaseBlobStore implements BlobStore { } @Override - public BlobStoreContext getContext() { + public BlobStoreContext getContext() { return context; } diff --git a/blobstore/src/main/java/org/jclouds/blobstore/internal/BaseBlobStoreApiMetadata.java b/blobstore/src/main/java/org/jclouds/blobstore/internal/BaseBlobStoreApiMetadata.java new file mode 100644 index 0000000000..d89c1f0d8e --- /dev/null +++ b/blobstore/src/main/java/org/jclouds/blobstore/internal/BaseBlobStoreApiMetadata.java @@ -0,0 +1,65 @@ +/** + * 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.blobstore.internal; + +import org.jclouds.apis.ApiType; +import org.jclouds.apis.internal.BaseApiMetadata; +import org.jclouds.blobstore.BlobStoreApiMetadata; +import org.jclouds.blobstore.BlobStoreContext; + +import com.google.common.annotations.Beta; +import com.google.common.reflect.TypeParameter; +import com.google.common.reflect.TypeToken; + +/** + * + * @author Adrian Cole + * @since 1.5 + */ +@Beta +public abstract class BaseBlobStoreApiMetadata, M extends BlobStoreApiMetadata> + extends BaseApiMetadata implements BlobStoreApiMetadata { + + public static class Builder, M extends BlobStoreApiMetadata> + extends BaseApiMetadata.Builder implements BlobStoreApiMetadata.Builder { + public Builder() { + type(ApiType.BLOBSTORE); + } + + /** + * {@inheritDoc} + */ + @Override + @SuppressWarnings("rawtypes") + protected TypeToken contextToken(TypeToken clientToken, TypeToken asyncClientToken) { + return new TypeToken>() { + private static final long serialVersionUID = 1L; + }.where(new TypeParameter() { + }, clientToken).where(new TypeParameter() { + }, asyncClientToken); + } + + } + + + protected BaseBlobStoreApiMetadata(BaseBlobStoreApiMetadata.Builder builder) { + super(builder); + } + +} \ No newline at end of file diff --git a/blobstore/src/main/java/org/jclouds/blobstore/internal/BlobStoreContextImpl.java b/blobstore/src/main/java/org/jclouds/blobstore/internal/BlobStoreContextImpl.java index 85289899db..6c8abad039 100644 --- a/blobstore/src/main/java/org/jclouds/blobstore/internal/BlobStoreContextImpl.java +++ b/blobstore/src/main/java/org/jclouds/blobstore/internal/BlobStoreContextImpl.java @@ -38,7 +38,7 @@ import org.jclouds.rest.Utils; * @author Adrian Cole */ @Singleton -public class BlobStoreContextImpl implements BlobStoreContext { +public class BlobStoreContextImpl implements BlobStoreContext { private final BlobMap.Factory blobMapFactory; private final InputStreamMap.Factory inputStreamMapFactory; private final AsyncBlobStore ablobStore; @@ -100,10 +100,9 @@ public class BlobStoreContextImpl implements BlobStoreContext { return ablobStore; } - @SuppressWarnings("unchecked") @Override public RestContext getProviderSpecificContext() { - return (RestContext) providerSpecificContext; + return providerSpecificContext; } @Override diff --git a/blobstore/src/main/java/org/jclouds/blobstore/util/BlobStoreUtils.java b/blobstore/src/main/java/org/jclouds/blobstore/util/BlobStoreUtils.java index 93866c3512..994960d254 100644 --- a/blobstore/src/main/java/org/jclouds/blobstore/util/BlobStoreUtils.java +++ b/blobstore/src/main/java/org/jclouds/blobstore/util/BlobStoreUtils.java @@ -27,7 +27,7 @@ import java.util.regex.Pattern; import org.jclouds.blobstore.AsyncBlobStore; import org.jclouds.blobstore.BlobStore; -import org.jclouds.blobstore.BlobStoreContextBuilder; +import org.jclouds.blobstore.BlobStoreContext; import org.jclouds.blobstore.ContainerNotFoundException; import org.jclouds.blobstore.KeyNotFoundException; import org.jclouds.blobstore.domain.Blob; @@ -38,11 +38,11 @@ import org.jclouds.functions.ExceptionToValueOrPropagate; import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpRequestFilter; import org.jclouds.http.HttpUtils; -import org.jclouds.rest.Providers; import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.util.Strings2; import com.google.common.collect.ImmutableMultimap; +import com.google.common.reflect.TypeToken; import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.ListenableFuture; @@ -159,7 +159,8 @@ public class BlobStoreUtils { } } + @Deprecated public static Iterable getSupportedProviders() { - return Providers.getSupportedProvidersOfType(BlobStoreContextBuilder.class); + return org.jclouds.rest.Providers.getSupportedProvidersOfType(TypeToken.of(BlobStoreContext.class)); } } \ No newline at end of file diff --git a/blobstore/src/test/java/org/jclouds/blobstore/BlobStoresTest.java b/blobstore/src/test/java/org/jclouds/blobstore/BlobStoresTest.java index 0d8c8bd571..3422312966 100644 --- a/blobstore/src/test/java/org/jclouds/blobstore/BlobStoresTest.java +++ b/blobstore/src/test/java/org/jclouds/blobstore/BlobStoresTest.java @@ -47,7 +47,7 @@ public class BlobStoresTest { public void testListAllForUnknownContainerFromTransientBlobStoreEagerly() throws Exception { ListContainerOptions containerOptions = ListContainerOptions.NONE; ListAllOptions listAllOptions = ListAllOptions.Builder.eager(true); - BlobStoreContext context = new BlobStoreContextFactory().createContext("transient", "dummyid", "dummykey"); + BlobStoreContext context = blobStoreContext(); try { BlobStore blobStore = context.getBlobStore(); BlobStores.listAll(blobStore, "wrongcontainer", containerOptions, listAllOptions); @@ -62,7 +62,7 @@ public class BlobStoresTest { @Test(expectedExceptions = { ContainerNotFoundException.class }) public void testListAllForUnknownContainerFromTransientBlobStore() throws Exception { ListContainerOptions options = ListContainerOptions.NONE; - BlobStoreContext context = new BlobStoreContextFactory().createContext("transient", "dummyid", "dummykey"); + BlobStoreContext context = blobStoreContext(); try { BlobStore blobStore = context.getBlobStore(); Iterable iterable = BlobStores.listAll(blobStore, "wrongcontainer", options); @@ -72,6 +72,10 @@ public class BlobStoresTest { } } + protected BlobStoreContext blobStoreContext() { + return BlobStoreContextBuilder.forTests().build(); + } + @Test public void testListAllFromTransientBlobStore() throws Exception { runListAllFromTransientBlobStore(false); @@ -86,7 +90,7 @@ public class BlobStoresTest { final int numTimesToIterate = 2; final int NUM_BLOBS = 31; ListContainerOptions containerOptions = ListContainerOptions.Builder.maxResults(10); - BlobStoreContext context = new BlobStoreContextFactory().createContext("transient", "dummyid", "dummykey"); + BlobStoreContext context = blobStoreContext(); BlobStore blobStore = null; try { blobStore = context.getBlobStore(); diff --git a/blobstore/src/test/java/org/jclouds/blobstore/TransientApiMetadataTest.java b/blobstore/src/test/java/org/jclouds/blobstore/TransientApiMetadataTest.java index 98fa8767fa..a10abe188e 100644 --- a/blobstore/src/test/java/org/jclouds/blobstore/TransientApiMetadataTest.java +++ b/blobstore/src/test/java/org/jclouds/blobstore/TransientApiMetadataTest.java @@ -18,8 +18,7 @@ */ package org.jclouds.blobstore; -import org.jclouds.apis.ApiType; -import org.jclouds.apis.BaseApiMetadataTest; +import org.jclouds.blobstore.internal.BaseBlobStoreApiMetadataTest; import org.testng.annotations.Test; /** @@ -27,9 +26,9 @@ import org.testng.annotations.Test; * @author Adrian Cole */ @Test(groups = "unit", testName = "TransientApiMetadataTest") -public class TransientApiMetadataTest extends BaseApiMetadataTest { +public class TransientApiMetadataTest extends BaseBlobStoreApiMetadataTest { public TransientApiMetadataTest() { - super(new TransientApiMetadata(), ApiType.BLOBSTORE); + super(new TransientApiMetadata()); } } diff --git a/blobstore/src/test/java/org/jclouds/blobstore/TransientBlobRequestSignerTest.java b/blobstore/src/test/java/org/jclouds/blobstore/TransientBlobRequestSignerTest.java index 73c5a43ebc..f3edf1a509 100644 --- a/blobstore/src/test/java/org/jclouds/blobstore/TransientBlobRequestSignerTest.java +++ b/blobstore/src/test/java/org/jclouds/blobstore/TransientBlobRequestSignerTest.java @@ -21,16 +21,14 @@ package org.jclouds.blobstore; import static org.testng.Assert.assertEquals; import java.io.IOException; -import java.util.Properties; import javax.inject.Provider; +import org.jclouds.apis.ApiMetadata; import org.jclouds.blobstore.domain.Blob; import org.jclouds.blobstore.domain.BlobBuilder; import org.jclouds.http.HttpRequest; -import org.jclouds.rest.RestClientTest; -import org.jclouds.rest.RestContextFactory; -import org.jclouds.rest.RestContextSpec; +import org.jclouds.rest.internal.BaseAsyncClientTest; import org.jclouds.rest.internal.RestAnnotationProcessor; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; @@ -44,14 +42,14 @@ import com.google.inject.TypeLiteral; */ // NOTE:without testName, this will not call @Before* and fail w/NPE during surefire @Test(groups = "unit", testName = "TransientBlobRequestSignerTest") -public class TransientBlobRequestSignerTest extends RestClientTest { +public class TransientBlobRequestSignerTest extends BaseAsyncClientTest { private BlobRequestSigner signer; private Provider blobFactory; - private final String endPoint = "http://localhost:8080"; + private final String endpoint = new TransientApiMetadata().getDefaultEndpoint().get(); private final String containerName = "container"; private final String blobName = "blob"; - private final String fullUrl = String.format("%s/%s/%s", endPoint, containerName, blobName); + private final String fullUrl = String.format("%s/%s/%s", endpoint, containerName, blobName); public void testSignGetBlob() throws ArrayIndexOutOfBoundsException, SecurityException, IllegalArgumentException, NoSuchMethodException, IOException { @@ -123,17 +121,15 @@ public class TransientBlobRequestSignerTest extends RestClientTest createContextSpec() { - Properties properties = new Properties(); - properties.setProperty("transient.endpoint", endPoint); - return new RestContextFactory().createContextSpec("transient", "identity", "credential", properties); - } - @Override protected TypeLiteral> createTypeLiteral() { return new TypeLiteral>() { }; } + @Override + public ApiMetadata createApiMetadata() { + return new TransientApiMetadata(); + } + } diff --git a/blobstore/src/test/java/org/jclouds/blobstore/binders/BindBlobToMultipartFormTest.java b/blobstore/src/test/java/org/jclouds/blobstore/binders/BindBlobToMultipartFormTest.java index f3fc0584dd..4b0be65a8d 100644 --- a/blobstore/src/test/java/org/jclouds/blobstore/binders/BindBlobToMultipartFormTest.java +++ b/blobstore/src/test/java/org/jclouds/blobstore/binders/BindBlobToMultipartFormTest.java @@ -28,10 +28,10 @@ import java.net.URI; import javax.ws.rs.HttpMethod; import javax.ws.rs.core.MediaType; +import org.jclouds.blobstore.BlobStoreContextBuilder; import org.jclouds.blobstore.domain.Blob; import org.jclouds.blobstore.domain.Blob.Factory; import org.jclouds.http.HttpRequest; -import org.jclouds.rest.RestContextFactory; import org.jclouds.util.Strings2; import org.testng.annotations.Test; @@ -47,8 +47,7 @@ public class BindBlobToMultipartFormTest { public static final Blob TEST_BLOB; static { - blobProvider = new RestContextFactory().createContextBuilder("transient", "identity", "credential") - .buildInjector().getInstance(Blob.Factory.class); + blobProvider = BlobStoreContextBuilder.forTests().buildInjector().getInstance(Blob.Factory.class); StringBuilder builder = new StringBuilder("--"); addData(BOUNDARY, "hello", builder); builder.append("--").append(BOUNDARY).append("--").append("\r\n"); diff --git a/blobstore/src/test/java/org/jclouds/blobstore/binders/BindUserMetadataToHeadersWithPrefixTest.java b/blobstore/src/test/java/org/jclouds/blobstore/binders/BindUserMetadataToHeadersWithPrefixTest.java index 515c2c972d..5f5e4c798c 100644 --- a/blobstore/src/test/java/org/jclouds/blobstore/binders/BindUserMetadataToHeadersWithPrefixTest.java +++ b/blobstore/src/test/java/org/jclouds/blobstore/binders/BindUserMetadataToHeadersWithPrefixTest.java @@ -25,9 +25,9 @@ import java.net.URI; import javax.ws.rs.HttpMethod; +import org.jclouds.blobstore.BlobStoreContextBuilder; import org.jclouds.blobstore.domain.Blob; import org.jclouds.http.HttpRequest; -import org.jclouds.rest.RestContextFactory; import org.testng.annotations.Test; import com.google.common.collect.ImmutableMap; @@ -47,8 +47,8 @@ public class BindUserMetadataToHeadersWithPrefixTest { BindUserMetadataToHeadersWithPrefix binder = new BindUserMetadataToHeadersWithPrefix( new BindMapToHeadersWithPrefix("prefix:")); - Blob blob = new RestContextFactory().createContextBuilder("transient", "identity", "credential").buildInjector() - .getInstance(Blob.Factory.class).create(null); + Blob blob = BlobStoreContextBuilder.forTests().buildInjector().getInstance(Blob.Factory.class).create(null); + blob.getMetadata().setUserMetadata(ImmutableMap.of("imageName", "foo", "serverId", "2")); assertEquals( diff --git a/blobstore/src/test/java/org/jclouds/blobstore/functions/BlobNameTest.java b/blobstore/src/test/java/org/jclouds/blobstore/functions/BlobNameTest.java index 0fa90822fb..551ff1147d 100644 --- a/blobstore/src/test/java/org/jclouds/blobstore/functions/BlobNameTest.java +++ b/blobstore/src/test/java/org/jclouds/blobstore/functions/BlobNameTest.java @@ -22,9 +22,9 @@ import static org.testng.Assert.assertEquals; import java.io.File; +import org.jclouds.blobstore.BlobStoreContextBuilder; import org.jclouds.blobstore.domain.Blob; import org.jclouds.blobstore.domain.Blob.Factory; -import org.jclouds.rest.RestContextFactory; import org.testng.annotations.Test; /** @@ -34,8 +34,8 @@ import org.testng.annotations.Test; @Test(groups = "unit") public class BlobNameTest { BlobName fn = new BlobName(); - private static final Factory BLOB_FACTORY = new RestContextFactory() - .createContextBuilder("transient", "identity", "credential").buildInjector().getInstance(Blob.Factory.class); + + private static final Factory BLOB_FACTORY = BlobStoreContextBuilder.forTests().buildInjector().getInstance(Blob.Factory.class); @Test public void testCorrect() throws SecurityException, NoSuchMethodException { diff --git a/blobstore/src/test/java/org/jclouds/blobstore/integration/TransientBlobIntegrationTest.java b/blobstore/src/test/java/org/jclouds/blobstore/integration/TransientBlobIntegrationTest.java index ba82ddb569..2fab14048d 100644 --- a/blobstore/src/test/java/org/jclouds/blobstore/integration/TransientBlobIntegrationTest.java +++ b/blobstore/src/test/java/org/jclouds/blobstore/integration/TransientBlobIntegrationTest.java @@ -28,5 +28,7 @@ import org.testng.annotations.Test; */ @Test(groups = { "integration" }) public class TransientBlobIntegrationTest extends BaseBlobIntegrationTest { - + public TransientBlobIntegrationTest() { + provider = "transient"; + } } \ No newline at end of file diff --git a/blobstore/src/test/java/org/jclouds/blobstore/integration/TransientBlobMapIntegrationTest.java b/blobstore/src/test/java/org/jclouds/blobstore/integration/TransientBlobMapIntegrationTest.java index e5ffe56df6..6823869aa4 100644 --- a/blobstore/src/test/java/org/jclouds/blobstore/integration/TransientBlobMapIntegrationTest.java +++ b/blobstore/src/test/java/org/jclouds/blobstore/integration/TransientBlobMapIntegrationTest.java @@ -27,5 +27,7 @@ import org.testng.annotations.Test; @Test(groups = { "integration", "live" }) public class TransientBlobMapIntegrationTest extends BaseBlobMapIntegrationTest { - + public TransientBlobMapIntegrationTest() { + provider = "transient"; + } } \ No newline at end of file diff --git a/blobstore/src/test/java/org/jclouds/blobstore/integration/TransientContainerIntegrationTest.java b/blobstore/src/test/java/org/jclouds/blobstore/integration/TransientContainerIntegrationTest.java index 2a6fdc0123..5ab15a7137 100644 --- a/blobstore/src/test/java/org/jclouds/blobstore/integration/TransientContainerIntegrationTest.java +++ b/blobstore/src/test/java/org/jclouds/blobstore/integration/TransientContainerIntegrationTest.java @@ -43,7 +43,10 @@ import com.google.common.collect.ImmutableMap; */ @Test(groups = { "integration", "live" }) public class TransientContainerIntegrationTest extends BaseContainerIntegrationTest { - + public TransientContainerIntegrationTest() { + provider = "transient"; + } + @Test(groups = { "integration", "live" }) public void testNotWithDetails() throws InterruptedException { diff --git a/blobstore/src/test/java/org/jclouds/blobstore/integration/TransientInputStreamMapIntegrationTest.java b/blobstore/src/test/java/org/jclouds/blobstore/integration/TransientInputStreamMapIntegrationTest.java index 44c655f921..ed298f9cc1 100644 --- a/blobstore/src/test/java/org/jclouds/blobstore/integration/TransientInputStreamMapIntegrationTest.java +++ b/blobstore/src/test/java/org/jclouds/blobstore/integration/TransientInputStreamMapIntegrationTest.java @@ -26,5 +26,7 @@ import org.testng.annotations.Test; */ @Test(groups = { "integration", "live" }) public class TransientInputStreamMapIntegrationTest extends BaseInputStreamMapIntegrationTest { - + public TransientInputStreamMapIntegrationTest() { + provider = "transient"; + } } \ No newline at end of file diff --git a/blobstore/src/test/java/org/jclouds/blobstore/integration/TransientServiceIntegrationTest.java b/blobstore/src/test/java/org/jclouds/blobstore/integration/TransientServiceIntegrationTest.java index bfb32bf0d5..5f0ea0c1ce 100644 --- a/blobstore/src/test/java/org/jclouds/blobstore/integration/TransientServiceIntegrationTest.java +++ b/blobstore/src/test/java/org/jclouds/blobstore/integration/TransientServiceIntegrationTest.java @@ -26,5 +26,7 @@ import org.testng.annotations.Test; */ @Test(groups = { "integration", "live" }) public class TransientServiceIntegrationTest extends BaseServiceIntegrationTest { - + public TransientServiceIntegrationTest() { + provider = "transient"; + } } \ No newline at end of file diff --git a/blobstore/src/test/java/org/jclouds/blobstore/integration/internal/BaseBlobIntegrationTest.java b/blobstore/src/test/java/org/jclouds/blobstore/integration/internal/BaseBlobIntegrationTest.java index 6b90d4d4fe..e9aac1bc3a 100644 --- a/blobstore/src/test/java/org/jclouds/blobstore/integration/internal/BaseBlobIntegrationTest.java +++ b/blobstore/src/test/java/org/jclouds/blobstore/integration/internal/BaseBlobIntegrationTest.java @@ -91,7 +91,7 @@ public class BaseBlobIntegrationTest extends BaseBlobStoreIntegrationTest { private byte[] oneHundredOneConstitutionsMD5; private static long oneHundredOneConstitutionsLength; - @BeforeClass(groups = { "integration", "live" }) + @BeforeClass(groups = { "integration", "live" }, dependsOnMethods = "setupContext") @Override public void setUpResourcesOnThisThread(ITestContext testContext) throws Exception { super.setUpResourcesOnThisThread(testContext); diff --git a/blobstore/src/test/java/org/jclouds/blobstore/integration/internal/BaseBlobMapIntegrationTest.java b/blobstore/src/test/java/org/jclouds/blobstore/integration/internal/BaseBlobMapIntegrationTest.java index a4780a7e87..e5667e2325 100644 --- a/blobstore/src/test/java/org/jclouds/blobstore/integration/internal/BaseBlobMapIntegrationTest.java +++ b/blobstore/src/test/java/org/jclouds/blobstore/integration/internal/BaseBlobMapIntegrationTest.java @@ -265,11 +265,13 @@ public abstract class BaseBlobMapIntegrationTest extends BaseMapIntegrationTest< return 100; } - protected BlobMap createMap(BlobStoreContext context, String bucket) { + @Override + protected BlobMap createMap(BlobStoreContext context, String bucket) { return createMap(context, bucket, maxResults(maxResultsForTestListings())); } - - protected BlobMap createMap(BlobStoreContext context, String bucket, ListContainerOptions options) { + + @Override + protected BlobMap createMap(BlobStoreContext context, String bucket, ListContainerOptions options) { return context.createBlobMap(bucket, options); } diff --git a/blobstore/src/test/java/org/jclouds/blobstore/integration/internal/BaseBlobStoreIntegrationTest.java b/blobstore/src/test/java/org/jclouds/blobstore/integration/internal/BaseBlobStoreIntegrationTest.java index 58dc9bfb55..c57d41ed55 100644 --- a/blobstore/src/test/java/org/jclouds/blobstore/integration/internal/BaseBlobStoreIntegrationTest.java +++ b/blobstore/src/test/java/org/jclouds/blobstore/integration/internal/BaseBlobStoreIntegrationTest.java @@ -18,7 +18,6 @@ */ package org.jclouds.blobstore.integration.internal; -import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Throwables.propagateIfPossible; import static org.jclouds.blobstore.util.BlobStoreUtils.getContentAsStringOrNullAndClose; import static org.testng.Assert.assertEquals; @@ -44,6 +43,7 @@ import org.jclouds.blobstore.domain.BlobMetadata; import org.jclouds.blobstore.domain.StorageMetadata; import org.jclouds.blobstore.domain.StorageType; import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule; +import org.jclouds.rest.internal.BaseContextLiveTest; import org.testng.ITestContext; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; @@ -58,7 +58,7 @@ import com.google.common.collect.Iterables; import com.google.common.collect.Sets; import com.google.inject.Module; -public class BaseBlobStoreIntegrationTest { +public class BaseBlobStoreIntegrationTest extends BaseContextLiveTest>{ protected static final String LOCAL_ENCODING = System.getProperty("file.encoding"); protected static final String XML_STRING_FORMAT = " "; protected static final String TEST_STRING = String.format(XML_STRING_FORMAT, "apple"); @@ -75,7 +75,6 @@ public class BaseBlobStoreIntegrationTest { public static long INCONSISTENCY_WINDOW = 10000; protected static volatile AtomicInteger containerIndex = new AtomicInteger(0); - protected volatile BlobStoreContext context; protected static volatile int containerCount = Integer.parseInt(System.getProperty("test.blobstore.container-count", "10")); public static final String CONTAINER_PREFIX = System.getProperty("user.name") + "-blobstore"; @@ -89,17 +88,14 @@ public class BaseBlobStoreIntegrationTest { */ @BeforeSuite public void setUpResourcesForAllThreads(ITestContext testContext) throws Exception { - // TODO: close this context - createContainersSharedByAllThreads(getCloudResources(testContext), testContext); + setupContext(); + createContainersSharedByAllThreads(context, testContext); + context.close(); + context = null; } - - @SuppressWarnings("unchecked") - private BlobStoreContext getCloudResources(ITestContext testContext) throws ClassNotFoundException, - InstantiationException, IllegalAccessException, Exception { - String initializerClass = checkNotNull(System.getProperty("test.initializer"), "test.initializer"); - Class clazz = (Class) Class.forName(initializerClass); - BaseTestInitializer initializer = clazz.newInstance(); - return initializer.init(createHttpModule(), testContext); + + protected Iterable setupModules() { + return ImmutableSet. of(getLoggingModule(), createHttpModule()); } protected ExecutorService exec; @@ -110,24 +106,24 @@ public class BaseBlobStoreIntegrationTest { * want to have a different implementation of context.getBlobStore(). For example, one class may * want non-blocking i/o and another class google appengine. */ - @BeforeClass(groups = { "integration", "live" }) + @BeforeClass(groups = { "integration", "live" }, dependsOnMethods = "setupContext") public void setUpResourcesOnThisThread(ITestContext testContext) throws Exception { - context = getCloudResources(testContext); exec = Executors.newCachedThreadPool(); } + @AfterClass(groups = { "integration", "live" }) - protected void tearDownClient() throws Exception { + @Override + protected void tearDownContext() { if (exec != null) { - exec.shutdown(); - exec.awaitTermination(60, TimeUnit.SECONDS); + exec.shutdownNow(); } context.close(); } private static volatile boolean initialized = false; - protected void createContainersSharedByAllThreads(BlobStoreContext context, ITestContext testContext) + protected void createContainersSharedByAllThreads(BlobStoreContext context, ITestContext testContext) throws Exception { while (!initialized) { synchronized (BaseBlobStoreIntegrationTest.class) { @@ -160,7 +156,7 @@ public class BaseBlobStoreIntegrationTest { } } - private static void deleteContainerOrWarnIfUnable(BlobStoreContext context, String containerName) { + private static void deleteContainerOrWarnIfUnable(BlobStoreContext context, String containerName) { try { context.getBlobStore().deleteContainer(containerName); } catch (Throwable ex) { @@ -175,7 +171,7 @@ public class BaseBlobStoreIntegrationTest { /** * Tries to delete all containers, runs up to two times */ - protected static void deleteEverything(final BlobStoreContext context) throws Exception { + protected static void deleteEverything(final BlobStoreContext context) throws Exception { try { for (int i = 0; i < 2; i++) { Iterable testContainers = Iterables.filter(context.getBlobStore().list(), @@ -204,7 +200,7 @@ public class BaseBlobStoreIntegrationTest { * Due to eventual consistency, container commands may not return correctly immediately. Hence, * we will try up to the inconsistency window to see if the assertion completes. */ - protected static void assertConsistencyAware(BlobStoreContext context, Runnable assertion) + protected static void assertConsistencyAware(BlobStoreContext context, Runnable assertion) throws InterruptedException { if (context.getConsistencyModel() == ConsistencyModel.STRICT) { assertion.run(); @@ -230,7 +226,7 @@ public class BaseBlobStoreIntegrationTest { assertConsistencyAware(context, assertion); } - protected static void createContainerAndEnsureEmpty(BlobStoreContext context, final String containerName) + protected static void createContainerAndEnsureEmpty(BlobStoreContext context, final String containerName) throws InterruptedException { context.getBlobStore().createContainerInLocation(null, containerName); if (context.getConsistencyModel() == ConsistencyModel.EVENTUAL) diff --git a/blobstore/src/test/java/org/jclouds/blobstore/integration/internal/BaseInputStreamMapIntegrationTest.java b/blobstore/src/test/java/org/jclouds/blobstore/integration/internal/BaseInputStreamMapIntegrationTest.java index 085b0d7fc9..a92952c6e0 100644 --- a/blobstore/src/test/java/org/jclouds/blobstore/integration/internal/BaseInputStreamMapIntegrationTest.java +++ b/blobstore/src/test/java/org/jclouds/blobstore/integration/internal/BaseInputStreamMapIntegrationTest.java @@ -330,11 +330,11 @@ public abstract class BaseInputStreamMapIntegrationTest extends BaseMapIntegrati return 100; } - protected InputStreamMap createMap(BlobStoreContext context, String bucket) { + protected InputStreamMap createMap(BlobStoreContext context, String bucket) { return createMap(context, bucket, maxResults(maxResultsForTestListings())); } - protected InputStreamMap createMap(BlobStoreContext context, String bucket, ListContainerOptions options) { + protected InputStreamMap createMap(BlobStoreContext context, String bucket, ListContainerOptions options) { return context.createInputStreamMap(bucket, options); } } diff --git a/blobstore/src/test/java/org/jclouds/blobstore/integration/internal/BaseMapIntegrationTest.java b/blobstore/src/test/java/org/jclouds/blobstore/integration/internal/BaseMapIntegrationTest.java index 6e59bd2a58..5d0e089ab1 100644 --- a/blobstore/src/test/java/org/jclouds/blobstore/integration/internal/BaseMapIntegrationTest.java +++ b/blobstore/src/test/java/org/jclouds/blobstore/integration/internal/BaseMapIntegrationTest.java @@ -97,9 +97,9 @@ public abstract class BaseMapIntegrationTest extends BaseBlobStoreIntegration } } - protected abstract Map createMap(BlobStoreContext context, String containerName); + protected abstract Map createMap(BlobStoreContext context, String containerName); - protected abstract Map createMap(BlobStoreContext context, String containerName, + protected abstract Map createMap(BlobStoreContext context, String containerName, ListContainerOptions options); @Test(groups = { "integration", "live" }) diff --git a/blobstore/src/test/java/org/jclouds/blobstore/integration/internal/BaseTestInitializer.java b/blobstore/src/test/java/org/jclouds/blobstore/integration/internal/BaseTestInitializer.java deleted file mode 100644 index ecfb4167c4..0000000000 --- a/blobstore/src/test/java/org/jclouds/blobstore/integration/internal/BaseTestInitializer.java +++ /dev/null @@ -1,93 +0,0 @@ -/** - * 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.blobstore.integration.internal; - -import java.io.IOException; -import java.util.Properties; - -import org.jclouds.Constants; -import org.jclouds.blobstore.BlobStoreContext; -import org.jclouds.blobstore.BlobStoreContextFactory; -import org.testng.ITestContext; - -import com.google.inject.Module; - -public abstract class BaseTestInitializer { - - protected String provider = "transient"; - - public BlobStoreContext init(Module configurationModule, ITestContext testContext) throws Exception { - String endpoint = System.getProperty("test." + provider + ".endpoint"); - String app = System.getProperty("test.app"); - String identity = System.getProperty("test." + provider + ".identity"); - String credential = System.getProperty("test." + provider + ".credential"); - String apiVersion = System.getProperty("test." + provider + ".api-version"); - String buildVersion = System.getProperty("test." + provider + ".build-version"); - if (endpoint != null) - testContext.setAttribute("test." + provider + ".endpoint", endpoint); - if (app != null) - testContext.setAttribute("test.app", app); - if (identity != null) - testContext.setAttribute("test." + provider + ".identity", identity); - if (credential != null) - testContext.setAttribute("test." + provider + ".credential", credential); - if (apiVersion != null) - testContext.setAttribute("test." + provider + ".api-version", apiVersion); - if (buildVersion != null) - testContext.setAttribute("test." + provider + ".build-version", buildVersion); - if (identity != null) { - return createLiveContext(configurationModule, endpoint, apiVersion, buildVersion, app, identity, credential); - } else { - return createStubContext(); - } - } - - - /** - * To be removed in jclouds 1.4 - */ - @Deprecated - protected Properties setupProperties(String endpoint, String apiVersion, String identity, String credential) { - return setupProperties(endpoint, apiVersion, "", identity, credential); - } - - protected Properties setupProperties(String endpoint, String apiVersion, String buildVersion, String identity, String credential) { - Properties overrides = new Properties(); - overrides.setProperty(Constants.PROPERTY_TRUST_ALL_CERTS, "true"); - overrides.setProperty(Constants.PROPERTY_RELAX_HOSTNAME, "true"); - if (identity != null) - overrides.setProperty(provider + ".identity", identity); - if (credential != null) - overrides.setProperty(provider + ".credential", credential); - if (endpoint != null) - overrides.setProperty(provider + ".endpoint", endpoint); - if (buildVersion != null) - overrides.setProperty(provider + ".build-version", buildVersion); - if (apiVersion != null) - overrides.setProperty(provider + ".api-version", apiVersion); - return overrides; - } - - protected BlobStoreContext createStubContext() throws IOException { - return new BlobStoreContextFactory().createContext("transient", "foo", "bar"); - } - - protected abstract BlobStoreContext createLiveContext(Module configurationModule, String url, String apiVersion, - String buildVersion, String app, String identity, String key) throws IOException; -} diff --git a/blobstore/src/test/java/org/jclouds/blobstore/internal/BaseBlobMapTest.java b/blobstore/src/test/java/org/jclouds/blobstore/internal/BaseBlobMapTest.java index d88a33a21e..a109ea9317 100644 --- a/blobstore/src/test/java/org/jclouds/blobstore/internal/BaseBlobMapTest.java +++ b/blobstore/src/test/java/org/jclouds/blobstore/internal/BaseBlobMapTest.java @@ -23,7 +23,7 @@ import static org.testng.Assert.assertEquals; import java.util.Map; import org.jclouds.blobstore.BlobStoreContext; -import org.jclouds.blobstore.BlobStoreContextFactory; +import org.jclouds.blobstore.BlobStoreContextBuilder; import org.jclouds.blobstore.domain.Blob; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; @@ -40,13 +40,13 @@ import com.google.inject.util.Types; @Test(groups = { "unit" }) public class BaseBlobMapTest { - BlobStoreContext context; + BlobStoreContext context; InputStreamMapImpl map; @BeforeClass void addDefaultObjectsSoThatTestsWillPass() { - context = new BlobStoreContextFactory().createContext("transient", "identity", "credential"); + context = BlobStoreContextBuilder.forTests().build(); map = (InputStreamMapImpl) context.createInputStreamMap("test"); } diff --git a/blobstore/src/test/java/org/jclouds/blobstore/internal/BaseBlobStoreApiMetadataTest.java b/blobstore/src/test/java/org/jclouds/blobstore/internal/BaseBlobStoreApiMetadataTest.java new file mode 100644 index 0000000000..32a2303059 --- /dev/null +++ b/blobstore/src/test/java/org/jclouds/blobstore/internal/BaseBlobStoreApiMetadataTest.java @@ -0,0 +1,34 @@ +package org.jclouds.blobstore.internal; + +import java.util.Set; + +import org.jclouds.apis.ApiMetadata; +import org.jclouds.apis.ApiType; +import org.jclouds.apis.Apis; +import org.jclouds.apis.internal.BaseApiMetadataTest; +import org.jclouds.blobstore.BlobStoreApiMetadata; +import org.jclouds.blobstore.BlobStoreContext; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableSet; +import com.google.common.reflect.TypeToken; + +/** + * + * @author Adrian Cole + */ +@Test(groups = "unit") +public abstract class BaseBlobStoreApiMetadataTest extends BaseApiMetadataTest { + + @SuppressWarnings("rawtypes") + public BaseBlobStoreApiMetadataTest(BlobStoreApiMetadata toTest) { + super(toTest, ApiType.BLOBSTORE); + } + + @Test + public void testContextAssignableFromBlobStoreContext() { + Set> all = ImmutableSet.copyOf(Apis.contextAssignableFrom(TypeToken.of(BlobStoreContext.class))); + assert all.contains(toTest) : String.format("%s not found in %s", toTest, all); + } + +} \ No newline at end of file diff --git a/blobstore/src/test/java/org/jclouds/blobstore/strategy/internal/BiggerThanPageSizeTest.java b/blobstore/src/test/java/org/jclouds/blobstore/strategy/internal/BiggerThanPageSizeTest.java index 0154e4c7d8..a95f01ca9c 100644 --- a/blobstore/src/test/java/org/jclouds/blobstore/strategy/internal/BiggerThanPageSizeTest.java +++ b/blobstore/src/test/java/org/jclouds/blobstore/strategy/internal/BiggerThanPageSizeTest.java @@ -23,7 +23,7 @@ import static org.testng.Assert.assertEquals; import java.io.IOException; import org.jclouds.blobstore.BlobStore; -import org.jclouds.blobstore.BlobStoreContextFactory; +import org.jclouds.blobstore.BlobStoreContextBuilder; import org.jclouds.blobstore.options.ListContainerOptions; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; @@ -38,7 +38,7 @@ public class BiggerThanPageSizeTest { @BeforeTest void setupBlobStore() { - blobstore = new BlobStoreContextFactory().createContext("transient", "foo", "bar").getBlobStore(); + blobstore = BlobStoreContextBuilder.forTests().build().getBlobStore(); } public void test() throws IOException { diff --git a/common/aws/src/test/java/org/jclouds/aws/filters/FormSignerTest.java b/common/aws/src/test/java/org/jclouds/aws/filters/FormSignerTest.java index 6cfffe4899..adeb2f8f10 100644 --- a/common/aws/src/test/java/org/jclouds/aws/filters/FormSignerTest.java +++ b/common/aws/src/test/java/org/jclouds/aws/filters/FormSignerTest.java @@ -24,23 +24,22 @@ import java.net.URI; import javax.ws.rs.core.HttpHeaders; -import org.jclouds.PropertiesBuilder; import org.jclouds.date.TimeStamp; import org.jclouds.http.HttpRequest; import org.jclouds.http.IntegrationTestAsyncClient; import org.jclouds.http.IntegrationTestClient; import org.jclouds.io.Payloads; import org.jclouds.logging.config.NullLoggingModule; +import org.jclouds.rest.AnonymousProviderMetadata; import org.jclouds.rest.RequestSigner; -import org.jclouds.rest.RestContextBuilder; -import org.jclouds.rest.RestContextFactory; -import org.jclouds.rest.RestContextSpec; -import org.jclouds.rest.BaseRestClientTest.MockModule; +import org.jclouds.rest.internal.BaseRestClientTest.MockModule; +import org.jclouds.rest.internal.ContextBuilder; import org.testng.annotations.Test; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMultimap; import com.google.inject.AbstractModule; +import com.google.inject.Injector; import com.google.inject.Module; import com.google.inject.name.Names; @@ -52,11 +51,13 @@ import com.google.inject.name.Names; // NOTE:without testName, this will not call @Before* and fail w/NPE during surefire @Test(groups = "unit", testName = "FormSignerTest") public class FormSignerTest { - @SuppressWarnings("unchecked") - public static final RestContextSpec DUMMY_SPEC = new RestContextSpec( - "provider", "endpoint", "apiVersion", "buildVersion", "", "identity", "credential", - IntegrationTestClient.class, IntegrationTestAsyncClient.class, PropertiesBuilder.class, - (Class) RestContextBuilder.class, ImmutableList. of(new MockModule(), new NullLoggingModule(), + public static final Injector INJECTOR = ContextBuilder + .newBuilder( + AnonymousProviderMetadata.forClientMappedToAsyncClientOnEndpoint(IntegrationTestClient.class, IntegrationTestAsyncClient.class, + "http://localhost")) + .credentials("identity", "credential") + .apiVersion("apiVersion") + .modules(ImmutableList. of(new MockModule(), new NullLoggingModule(), new AbstractModule() { @Override protected void configure() { @@ -65,11 +66,11 @@ public class FormSignerTest { bind(String.class).annotatedWith(TimeStamp.class).toInstance("2009-11-08T15:54:08.897Z"); } - })); + })).buildInjector(); + FormSigner filter = INJECTOR.getInstance(FormSigner.class); + @Test void testBuildCanonicalizedStringSetsVersion() { - FormSigner filter = RestContextFactory.createContextBuilder(DUMMY_SPEC).buildInjector().getInstance( - FormSigner.class); assertEquals( filter.filter( @@ -82,9 +83,6 @@ public class FormSignerTest { @Test void testBuildCanonicalizedString() { - FormSigner filter = RestContextFactory.createContextBuilder(DUMMY_SPEC).buildInjector().getInstance( - FormSigner.class); - assertEquals( filter.buildCanonicalizedString(new ImmutableMultimap.Builder().put("AWSAccessKeyId", "foo").put("Action", "DescribeImages").put("Expires", "2008-02-10T12:00:00Z").put("ImageId.1", diff --git a/common/aws/src/test/java/org/jclouds/aws/util/AWSUtilsTest.java b/common/aws/src/test/java/org/jclouds/aws/util/AWSUtilsTest.java index 220bd81f09..ed64ef6a24 100644 --- a/common/aws/src/test/java/org/jclouds/aws/util/AWSUtilsTest.java +++ b/common/aws/src/test/java/org/jclouds/aws/util/AWSUtilsTest.java @@ -32,20 +32,18 @@ import org.jclouds.http.HttpCommand; import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpResponse; import org.jclouds.io.Payloads; -import org.jclouds.rest.RestContextFactory; import org.testng.annotations.AfterTest; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; import com.google.common.collect.ImmutableMultimap; -import com.google.inject.Injector; /** * Tests parsing of S3 responses * * @author Adrian Cole */ -@Test(sequential = true, groups = { "unit" }) +@Test(singleThreaded = true, groups = { "unit" }) public class AWSUtilsTest { AWSUtils utils = null; private HttpCommand command; @@ -53,9 +51,7 @@ public class AWSUtilsTest { @BeforeTest protected void setUpInjector() throws IOException { - Injector injector = RestContextFactory.createContextBuilder(FormSignerTest.DUMMY_SPEC).buildInjector(); - - utils = injector.getInstance(AWSUtils.class); + utils = FormSignerTest.INJECTOR.getInstance(AWSUtils.class); command = createMock(HttpCommand.class); expect(command.getCurrentRequest()).andReturn(createMock(HttpRequest.class)).atLeastOnce(); diff --git a/common/azure/src/main/java/org/jclouds/azure/storage/AzureStorageContextBuilder.java b/common/azure/src/main/java/org/jclouds/azure/storage/AzureStorageContextBuilder.java index dbcf8dd38d..ef23a9a7d8 100644 --- a/common/azure/src/main/java/org/jclouds/azure/storage/AzureStorageContextBuilder.java +++ b/common/azure/src/main/java/org/jclouds/azure/storage/AzureStorageContextBuilder.java @@ -18,39 +18,47 @@ */ package org.jclouds.azure.storage; +import java.io.Closeable; import java.util.List; -import java.util.Properties; +import org.jclouds.apis.ApiMetadata; import org.jclouds.azure.storage.config.AzureStorageRestClientModule; import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule; import org.jclouds.logging.jdk.config.JDKLoggingModule; -import org.jclouds.rest.RestContextBuilder; +import org.jclouds.providers.ProviderMetadata; +import org.jclouds.rest.internal.ContextBuilder; import com.google.inject.Injector; import com.google.inject.Module; /** - * Creates {@link AzureStorageStoreContext} or {@link Injector} instances based on the most commonly - * requested arguments. + * Creates {@link AzureStorageStoreContext} or {@link Injector} instances based + * on the most commonly requested arguments. *

- * Note that Threadsafe objects will be bound as singletons to the Injector or Context provided. + * Note that Threadsafe objects will be bound as singletons to the Injector or + * Context provided. *

*

- * If no Modules are specified, the default {@link JDKLoggingModule logging} and - * {@link JavaUrlHttpCommandExecutorServiceModule http transports} will be installed. + * If no Modules are specified, the default + * {@link JDKLoggingModule logging} and + * {@link JavaUrlHttpCommandExecutorServiceModule http transports} will be + * installed. * * @author Adrian Cole, Andrew Newdigate * @see AzureStorageStoreContext */ -public class AzureStorageContextBuilder extends RestContextBuilder { +public class AzureStorageContextBuilder> extends + ContextBuilder { + public AzureStorageContextBuilder(ProviderMetadata providerMetadata) { + super(providerMetadata); + } - public AzureStorageContextBuilder(Class syncClientClass, Class asyncClientClass, - Properties properties) { - super(syncClientClass, asyncClientClass, properties); + public AzureStorageContextBuilder(M apiMetadata) { + super(apiMetadata); } @Override protected void addClientModule(List modules) { - modules.add(new AzureStorageRestClientModule(syncClientType, asyncClientType)); + modules.add(new AzureStorageRestClientModule(apiMetadata.getApi(), apiMetadata.getAsyncApi())); } } diff --git a/common/azure/src/test/java/org/jclouds/azure/storage/filters/SharedKeyLiteAuthenticationTest.java b/common/azure/src/test/java/org/jclouds/azure/storage/filters/SharedKeyLiteAuthenticationTest.java index dd68b2b4f6..5e3b0e16c6 100644 --- a/common/azure/src/test/java/org/jclouds/azure/storage/filters/SharedKeyLiteAuthenticationTest.java +++ b/common/azure/src/test/java/org/jclouds/azure/storage/filters/SharedKeyLiteAuthenticationTest.java @@ -26,21 +26,19 @@ import java.net.URI; import javax.ws.rs.HttpMethod; import javax.ws.rs.core.HttpHeaders; -import org.jclouds.PropertiesBuilder; import org.jclouds.azure.storage.config.AzureStorageRestClientModule; import org.jclouds.http.HttpRequest; import org.jclouds.http.IntegrationTestAsyncClient; import org.jclouds.http.IntegrationTestClient; import org.jclouds.logging.config.NullLoggingModule; -import org.jclouds.rest.BaseRestClientTest.MockModule; -import org.jclouds.rest.RestContextBuilder; -import org.jclouds.rest.RestContextFactory; -import org.jclouds.rest.RestContextSpec; +import org.jclouds.rest.AnonymousRestApiMetadata; +import org.jclouds.rest.internal.BaseRestClientTest.MockModule; +import org.jclouds.rest.internal.ContextBuilder; import org.testng.annotations.BeforeClass; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; -import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableSet; import com.google.inject.Injector; import com.google.inject.Module; @@ -58,18 +56,19 @@ public class SharedKeyLiteAuthenticationTest { @DataProvider(parallel = true) public Object[][] dataProvider() { return new Object[][] { - { new HttpRequest(HttpMethod.PUT, URI.create("http://" + ACCOUNT - + ".blob.core.windows.net/movies/MOV1.avi?comp=block&blockid=BlockId1&timeout=60")) }, - { new HttpRequest(HttpMethod.PUT, URI.create("http://" + ACCOUNT - + ".blob.core.windows.net/movies/MOV1.avi?comp=blocklist&timeout=120")) }, - { new HttpRequest(HttpMethod.GET, URI.create("http://" + ACCOUNT - + ".blob.core.windows.net/movies/MOV1.avi")) } }; + { new HttpRequest(HttpMethod.PUT, URI.create("http://" + ACCOUNT + + ".blob.core.windows.net/movies/MOV1.avi?comp=block&blockid=BlockId1&timeout=60")) }, + { new HttpRequest(HttpMethod.PUT, URI.create("http://" + ACCOUNT + + ".blob.core.windows.net/movies/MOV1.avi?comp=blocklist&timeout=120")) }, + { new HttpRequest(HttpMethod.GET, + URI.create("http://" + ACCOUNT + ".blob.core.windows.net/movies/MOV1.avi")) } }; } /** - * NOTE this test is dependent on how frequently the timestamp updates. At the time of writing, - * this was once per second. If this timestamp update interval is increased, it could make this - * test appear to hang for a long time. + * NOTE this test is dependent on how frequently the timestamp updates. At + * the time of writing, this was once per second. If this timestamp update + * interval is increased, it could make this test appear to hang for a long + * time. */ @Test(threadPoolSize = 3, dataProvider = "dataProvider", timeOut = 3000) void testIdempotent(HttpRequest request) { @@ -84,7 +83,7 @@ public class SharedKeyLiteAuthenticationTest { request = filter.filter(request); } System.out.printf("%s: %d iterations before the timestamp updated %n", Thread.currentThread().getName(), - iterations); + iterations); } @Test @@ -117,7 +116,7 @@ public class SharedKeyLiteAuthenticationTest { @Test void testAclQueryStringRelativeWithExtraJunk() { URI host = URI.create("http://" + ACCOUNT - + ".blob.core.windows.net/mycontainer?comp=list&marker=marker&maxresults=1&prefix=prefix"); + + ".blob.core.windows.net/mycontainer?comp=list&marker=marker&maxresults=1&prefix=prefix"); HttpRequest request = new HttpRequest(HttpMethod.GET, host); StringBuilder builder = new StringBuilder(); filter.appendUriPath(request, builder); @@ -132,16 +131,17 @@ public class SharedKeyLiteAuthenticationTest { */ @BeforeClass protected void createFilter() throws IOException { - injector = RestContextFactory.createContextBuilder(DUMMY_SPEC).buildInjector(); + injector = ContextBuilder + .newBuilder( + AnonymousRestApiMetadata + .forClientMappedToAsyncClient(IntegrationTestClient.class, IntegrationTestAsyncClient.class) + .toBuilder().build()) + .endpoint("https://${jclouds.identity}.blob.core.windows.net") + .credentials(ACCOUNT, "credential") + .modules( + ImmutableSet. of(new MockModule(), new NullLoggingModule(), + new AzureStorageRestClientModule( + IntegrationTestClient.class, IntegrationTestAsyncClient.class))).buildInjector(); filter = injector.getInstance(SharedKeyLiteAuthentication.class); } - - @SuppressWarnings("unchecked") - public static final RestContextSpec DUMMY_SPEC = new RestContextSpec( - "provider", "endpoint", "apiVersion", "buildVersion", "", "identity", "credential", IntegrationTestClient.class, - IntegrationTestAsyncClient.class, PropertiesBuilder.class, (Class) RestContextBuilder.class, ImmutableList - . of(new MockModule(), new NullLoggingModule(), - new AzureStorageRestClientModule(IntegrationTestClient.class, - IntegrationTestAsyncClient.class))); - } \ No newline at end of file diff --git a/common/openstack/src/test/java/org/jclouds/openstack/OpenStackAuthAsyncClientTest.java b/common/openstack/src/test/java/org/jclouds/openstack/OpenStackAuthAsyncClientTest.java index aa556da34a..bcfcc5017f 100644 --- a/common/openstack/src/test/java/org/jclouds/openstack/OpenStackAuthAsyncClientTest.java +++ b/common/openstack/src/test/java/org/jclouds/openstack/OpenStackAuthAsyncClientTest.java @@ -18,16 +18,17 @@ */ package org.jclouds.openstack; -import static org.jclouds.rest.RestContextFactory.contextSpec; - import java.io.IOException; import java.lang.reflect.Method; +import org.jclouds.apis.ApiMetadata; import org.jclouds.http.HttpRequest; +import org.jclouds.http.IntegrationTestAsyncClient; +import org.jclouds.http.IntegrationTestClient; import org.jclouds.openstack.functions.ParseAuthenticationResponseFromHeaders; -import org.jclouds.rest.RestClientTest; -import org.jclouds.rest.RestContextSpec; +import org.jclouds.rest.AnonymousRestApiMetadata; import org.jclouds.rest.functions.MapHttp4xxCodesToExceptions; +import org.jclouds.rest.internal.BaseAsyncClientTest; import org.jclouds.rest.internal.RestAnnotationProcessor; import org.testng.annotations.Test; @@ -40,7 +41,7 @@ import com.google.inject.TypeLiteral; */ // NOTE:without testName, this will not call @Before* and fail w/NPE during surefire @Test(groups = "unit", testName = "OpenStackAuthAsyncClientTest") -public class OpenStackAuthAsyncClientTest extends RestClientTest { +public class OpenStackAuthAsyncClientTest extends BaseAsyncClientTest { public void testAuthenticate() throws SecurityException, NoSuchMethodException, IOException { Method method = OpenStackAuthAsyncClient.class.getMethod("authenticate", String.class, String.class); @@ -71,9 +72,9 @@ public class OpenStackAuthAsyncClientTest extends RestClientTest createContextSpec() { - return contextSpec("test", "http://localhost:8080", "1.0", "", "", "identity", "credential", - OpenStackAuthClient.class, OpenStackAuthAsyncClient.class); + public ApiMetadata createApiMetadata() { + return AnonymousRestApiMetadata.forClientMappedToAsyncClient(IntegrationTestClient.class, IntegrationTestAsyncClient.class).toBuilder().defaultEndpoint( + "http://localhost:8080").version("1.0").build(); } @Override diff --git a/common/openstack/src/test/java/org/jclouds/openstack/keystone/v1_1/internal/BaseKeystoneRestClientExpectTest.java b/common/openstack/src/test/java/org/jclouds/openstack/keystone/v1_1/internal/BaseKeystoneRestClientExpectTest.java index 9ffd22aa1d..4e162a8a2a 100644 --- a/common/openstack/src/test/java/org/jclouds/openstack/keystone/v1_1/internal/BaseKeystoneRestClientExpectTest.java +++ b/common/openstack/src/test/java/org/jclouds/openstack/keystone/v1_1/internal/BaseKeystoneRestClientExpectTest.java @@ -23,7 +23,7 @@ import java.net.URI; import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpResponse; import org.jclouds.openstack.keystone.v1_1.config.AuthenticationServiceModule; -import org.jclouds.rest.BaseRestClientExpectTest; +import org.jclouds.rest.internal.BaseRestClientExpectTest; import com.google.common.collect.ImmutableMultimap; import com.google.common.net.HttpHeaders; diff --git a/common/openstack/src/test/java/org/jclouds/openstack/keystone/v2_0/internal/KeystoneFixture.java b/common/openstack/src/test/java/org/jclouds/openstack/keystone/v2_0/internal/KeystoneFixture.java index 7494229810..3da8d77a45 100644 --- a/common/openstack/src/test/java/org/jclouds/openstack/keystone/v2_0/internal/KeystoneFixture.java +++ b/common/openstack/src/test/java/org/jclouds/openstack/keystone/v2_0/internal/KeystoneFixture.java @@ -18,7 +18,7 @@ */ package org.jclouds.openstack.keystone.v2_0.internal; import static java.lang.String.format; -import static org.jclouds.rest.BaseRestClientExpectTest.payloadFromStringWithContentType; +import static org.jclouds.rest.internal.BaseRestClientExpectTest.payloadFromStringWithContentType; import java.io.IOException; import java.net.URI; diff --git a/common/trmk/src/main/java/org/jclouds/trmk/vcloud_0_8/TerremarkVCloudContextBuilder.java b/common/trmk/src/main/java/org/jclouds/trmk/vcloud_0_8/TerremarkVCloudContextBuilder.java index fd3bd951d7..2876428613 100644 --- a/common/trmk/src/main/java/org/jclouds/trmk/vcloud_0_8/TerremarkVCloudContextBuilder.java +++ b/common/trmk/src/main/java/org/jclouds/trmk/vcloud_0_8/TerremarkVCloudContextBuilder.java @@ -19,11 +19,13 @@ package org.jclouds.trmk.vcloud_0_8; import java.util.List; -import java.util.Properties; +import org.jclouds.compute.ComputeServiceApiMetadata; +import org.jclouds.compute.ComputeServiceContext; import org.jclouds.compute.ComputeServiceContextBuilder; import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule; import org.jclouds.logging.jdk.config.JDKLoggingModule; +import org.jclouds.providers.ProviderMetadata; import org.jclouds.trmk.vcloud_0_8.compute.config.TerremarkVCloudComputeServiceContextModule; import org.jclouds.trmk.vcloud_0_8.config.TerremarkVCloudRestClientModule; @@ -46,11 +48,15 @@ import com.google.inject.Module; * @author Adrian Cole * @see VCloudComputeServiceContext */ -public class TerremarkVCloudContextBuilder - extends ComputeServiceContextBuilder { +public class TerremarkVCloudContextBuilder, M extends ComputeServiceApiMetadata> + extends ComputeServiceContextBuilder { - public TerremarkVCloudContextBuilder(Class syncClientType, Class asyncClientType, Properties props) { - super(syncClientType, asyncClientType, props); + public TerremarkVCloudContextBuilder(ProviderMetadata providerMetadata) { + super(providerMetadata); + } + + public TerremarkVCloudContextBuilder(M apiMetadata) { + super(apiMetadata); } @Override @@ -60,6 +66,6 @@ public class TerremarkVCloudContextBuilder modules) { - modules.add(new TerremarkVCloudRestClientModule(syncClientType, asyncClientType)); + modules.add(new TerremarkVCloudRestClientModule(apiMetadata.getApi(), apiMetadata.getAsyncApi())); } } diff --git a/common/trmk/src/main/java/org/jclouds/trmk/vcloud_0_8/compute/TerremarkVCloudComputeService.java b/common/trmk/src/main/java/org/jclouds/trmk/vcloud_0_8/compute/TerremarkVCloudComputeService.java index 87107915e6..1185a977c2 100644 --- a/common/trmk/src/main/java/org/jclouds/trmk/vcloud_0_8/compute/TerremarkVCloudComputeService.java +++ b/common/trmk/src/main/java/org/jclouds/trmk/vcloud_0_8/compute/TerremarkVCloudComputeService.java @@ -64,6 +64,7 @@ import com.google.common.base.Supplier; public class TerremarkVCloudComputeService extends BaseComputeService { private final CleanupOrphanKeys cleanupOrphanKeys; + @SuppressWarnings("rawtypes") @Inject protected TerremarkVCloudComputeService(ComputeServiceContext context, Map credentialStore, @Memoized Supplier> images, @Memoized Supplier> sizes, diff --git a/common/trmk/src/main/java/org/jclouds/trmk/vcloud_0_8/compute/config/TerremarkVCloudComputeServiceContextModule.java b/common/trmk/src/main/java/org/jclouds/trmk/vcloud_0_8/compute/config/TerremarkVCloudComputeServiceContextModule.java index a507ac1c3c..5d13535e30 100644 --- a/common/trmk/src/main/java/org/jclouds/trmk/vcloud_0_8/compute/config/TerremarkVCloudComputeServiceContextModule.java +++ b/common/trmk/src/main/java/org/jclouds/trmk/vcloud_0_8/compute/config/TerremarkVCloudComputeServiceContextModule.java @@ -77,6 +77,7 @@ public class TerremarkVCloudComputeServiceContextModule extends BaseComputeServi return VAPPSTATUS_TO_NODESTATE; } + @SuppressWarnings("rawtypes") @Override protected void configure() { super.configure(); diff --git a/common/trmk/src/main/java/org/jclouds/trmk/vcloud_0_8/internal/TerremarkVCloudApiMetadata.java b/common/trmk/src/main/java/org/jclouds/trmk/vcloud_0_8/internal/TerremarkVCloudApiMetadata.java new file mode 100644 index 0000000000..713450b93e --- /dev/null +++ b/common/trmk/src/main/java/org/jclouds/trmk/vcloud_0_8/internal/TerremarkVCloudApiMetadata.java @@ -0,0 +1,83 @@ +package org.jclouds.trmk.vcloud_0_8.internal; + +import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL; +import static org.jclouds.trmk.vcloud_0_8.reference.TerremarkConstants.PROPERTY_TERREMARK_EXTENSION_NAME; +import static org.jclouds.trmk.vcloud_0_8.reference.TerremarkConstants.PROPERTY_TERREMARK_EXTENSION_NS; +import static org.jclouds.trmk.vcloud_0_8.reference.TerremarkConstants.PROPERTY_TERREMARK_EXTENSION_VERSION; +import static org.jclouds.trmk.vcloud_0_8.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_FENCEMODE; +import static org.jclouds.trmk.vcloud_0_8.reference.VCloudConstants.PROPERTY_VCLOUD_TIMEOUT_TASK_COMPLETED; +import static org.jclouds.trmk.vcloud_0_8.reference.VCloudConstants.PROPERTY_VCLOUD_VERSION_SCHEMA; +import static org.jclouds.trmk.vcloud_0_8.reference.VCloudConstants.PROPERTY_VCLOUD_XML_NAMESPACE; +import static org.jclouds.trmk.vcloud_0_8.reference.VCloudConstants.PROPERTY_VCLOUD_XML_SCHEMA; + +import java.util.Properties; +import java.util.concurrent.TimeUnit; + +import org.jclouds.apis.ApiMetadata; +import org.jclouds.compute.ComputeServiceContext; +import org.jclouds.compute.internal.BaseComputeServiceApiMetadata; +import org.jclouds.trmk.vcloud_0_8.TerremarkVCloudAsyncClient; +import org.jclouds.trmk.vcloud_0_8.TerremarkVCloudClient; + +/** + * Implementation of {@link ApiMetadata} for Amazon's TerremarkVCloud api. + * + *

note

+ *

+ * This class allows overriding of types {@code S}(client) and {@code A} + * (asyncClient), so that children can add additional methods not declared here, + * such as new features from AWS. + *

+ * + * As this is a popular api, we also allow overrides for type {@code C} + * (context). This allows subtypes to add in new feature groups or extensions, + * not present in the base api. For example, you could make a subtype for + * context, that exposes admin operations. + * + * @author Adrian Cole + */ +public abstract class TerremarkVCloudApiMetadata> + extends BaseComputeServiceApiMetadata, M> { + + protected TerremarkVCloudApiMetadata(Builder builder) { + super(builder); + } + + protected static Properties defaultProperties() { + Properties properties = BaseComputeServiceApiMetadata.Builder.defaultProperties(); + properties.setProperty(PROPERTY_VCLOUD_VERSION_SCHEMA, "0.8"); + properties.setProperty(PROPERTY_SESSION_INTERVAL, 8 * 60 + ""); + properties.setProperty(PROPERTY_VCLOUD_XML_SCHEMA, "http://vcloud.safesecureweb.com/ns/vcloud.xsd"); + properties.setProperty(PROPERTY_VCLOUD_DEFAULT_FENCEMODE, "allowInOut"); + properties.setProperty(PROPERTY_TERREMARK_EXTENSION_NS, String.format("urn:tmrk:${%s}-${%s}", + PROPERTY_TERREMARK_EXTENSION_NAME, PROPERTY_TERREMARK_EXTENSION_VERSION)); + properties.setProperty(PROPERTY_VCLOUD_XML_NAMESPACE, + String.format("http://www.vmware.com/vcloud/v${%s}", PROPERTY_VCLOUD_VERSION_SCHEMA)); + properties.setProperty("jclouds.dns_name_length_min", "1"); + properties.setProperty("jclouds.dns_name_length_max", "15"); + // terremark can sometimes block extremely long times + properties.setProperty(PROPERTY_VCLOUD_TIMEOUT_TASK_COMPLETED, TimeUnit.MINUTES.toMillis(20) + ""); + return properties; + } + + public static abstract class Builder> + extends BaseComputeServiceApiMetadata.Builder, M> { + + protected Builder(Class syncClient, Class asyncClient) { + id("vcloud-common") + .identityName("Email") + .credentialName("Password") + .version("0.8") + .defaultProperties(TerremarkVCloudApiMetadata.defaultProperties()) + .javaApi(syncClient, asyncClient); + } + + @Override + public Builder fromApiMetadata(M in) { + super.fromApiMetadata(in); + return this; + } + + } + +} \ No newline at end of file diff --git a/common/trmk/src/test/java/org/jclouds/trmk/vcloud_0_8/TerremarkClientLiveTest.java b/common/trmk/src/test/java/org/jclouds/trmk/vcloud_0_8/TerremarkClientLiveTest.java index 2a7c953c3f..b25256d6f3 100644 --- a/common/trmk/src/test/java/org/jclouds/trmk/vcloud_0_8/TerremarkClientLiveTest.java +++ b/common/trmk/src/test/java/org/jclouds/trmk/vcloud_0_8/TerremarkClientLiveTest.java @@ -42,19 +42,16 @@ import java.util.concurrent.TimeoutException; import org.jclouds.cim.CIMPredicates; import org.jclouds.cim.ResourceAllocationSettingData; import org.jclouds.cim.ResourceAllocationSettingData.ResourceType; -import org.jclouds.compute.BaseVersionedServiceLiveTest; -import org.jclouds.compute.ComputeServiceContextFactory; -import org.jclouds.logging.log4j.config.Log4JLoggingModule; +import org.jclouds.compute.ComputeServiceContext; +import org.jclouds.compute.internal.BaseComputeServiceContextLiveTest; import org.jclouds.net.IPSocket; import org.jclouds.predicates.RetryablePredicate; import org.jclouds.predicates.SocketOpen; import org.jclouds.rest.AuthorizationException; import org.jclouds.rest.RestContext; -import org.jclouds.rest.RestContextFactory; import org.jclouds.ssh.SshClient; import org.jclouds.ssh.SshClient.Factory; import org.jclouds.ssh.SshException; -import org.jclouds.sshj.config.SshjSshClientModule; import org.jclouds.trmk.vcloud_0_8.domain.Catalog; import org.jclouds.trmk.vcloud_0_8.domain.CatalogItem; import org.jclouds.trmk.vcloud_0_8.domain.CustomizationParameters; @@ -77,19 +74,18 @@ import org.jclouds.trmk.vcloud_0_8.options.InstantiateVAppTemplateOptions; import org.jclouds.trmk.vcloud_0_8.predicates.TaskSuccess; import org.jclouds.trmk.vcloud_0_8.reference.VCloudConstants; import org.testng.annotations.AfterGroups; -import org.testng.annotations.BeforeGroups; +import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import com.google.common.base.Function; import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; import com.google.common.collect.Lists; import com.google.inject.Injector; -import com.google.inject.Module; -@Test(groups = "live" , singleThreaded = true) -public abstract class TerremarkClientLiveTest extends BaseVersionedServiceLiveTest { +@Test(groups = "live", singleThreaded = true) +public abstract class TerremarkClientLiveTest + extends BaseComputeServiceContextLiveTest> { protected String expectedOs = "Ubuntu Linux (64-bit)"; protected String itemName = "Ubuntu JeOS 9.10 (64-bit)"; @@ -107,7 +103,7 @@ public abstract class TerremarkClientLiveTest extends BaseVersionedServiceLiveTe protected VDC vdc; protected String serverName; protected KeyPair key; - + public static final String PREFIX = System.getProperty("user.name") + "-terremark"; public TerremarkClientLiveTest() { @@ -117,7 +113,7 @@ public abstract class TerremarkClientLiveTest extends BaseVersionedServiceLiveTe name.append("d"); serverName = name.toString();// "adriantest"; } - + @Test public void testKeysList() throws Exception { for (Org org : orgs) { @@ -192,9 +188,10 @@ public abstract class TerremarkClientLiveTest extends BaseVersionedServiceLiveTe // lookup the datacenter you are deploying into vdc = connection.findVDCInOrgNamed(null, null); - + // create an options object to collect the configuration we want. - InstantiateVAppTemplateOptions instantiateOptions = createInstantiateOptions().sshKeyFingerprint(key.getFingerPrint()); + InstantiateVAppTemplateOptions instantiateOptions = createInstantiateOptions().sshKeyFingerprint( + key.getFingerPrint()); CatalogItem item = connection.findCatalogItemInOrgCatalogNamed(null, null, itemName); @@ -205,7 +202,6 @@ public abstract class TerremarkClientLiveTest extends BaseVersionedServiceLiveTe CustomizationParameters customizationOptions = connection.getCustomizationOptions(item.getCustomizationOptions() .getHref()); - if (customizationOptions.canCustomizePassword()) instantiateOptions.withPassword("robotsarefun"); @@ -275,8 +271,7 @@ public abstract class TerremarkClientLiveTest extends BaseVersionedServiceLiveTe assertNotNull(key.getPrivateKey()); assertNotNull(key.getFingerPrint()); assertEquals(key.isDefault(), false); - assertEquals(key.getFingerPrint(), connection.findKeyPairInOrg(org.getHref(), key.getName()) - .getFingerPrint()); + assertEquals(key.getFingerPrint(), connection.findKeyPairInOrg(org.getHref(), key.getName()).getFingerPrint()); } protected abstract Entry getNewInternetServiceAndIpForSSH(VApp vApp); @@ -483,13 +478,11 @@ public abstract class TerremarkClientLiveTest extends BaseVersionedServiceLiveTe } - @BeforeGroups(groups = { "live" }) - public void setupClient() { - setupCredentials(); - Properties overrides = setupProperties(); - - injector = new RestContextFactory().createContextBuilder(provider, - ImmutableSet. of(new Log4JLoggingModule(), new SshjSshClientModule()), overrides).buildInjector(); + @Override + @BeforeClass(groups = { "integration", "live" }) + public void setupContext() { + super.setupContext(); + injector = context.utils().injector(); sshFactory = injector.getInstance(SshClient.Factory.class); socketTester = new RetryablePredicate(injector.getInstance(SocketOpen.class), 300, 10, TimeUnit.SECONDS);// make @@ -499,13 +492,11 @@ public abstract class TerremarkClientLiveTest extends BaseVersionedServiceLiveTe // default internet // service timeout successTester = new RetryablePredicate(injector.getInstance(TaskSuccess.class), 650, 10, TimeUnit.SECONDS); - context = createContextWithProperties(setupProperties()); - connection = context.getApi(); + connection = context.getProviderSpecificContext().getApi(); orgs = listOrgs(); } - protected TerremarkVCloudClient connection; - protected RestContext context; + protected S connection; @Test public void testOrg() throws Exception { @@ -522,10 +513,11 @@ public abstract class TerremarkClientLiveTest extends BaseVersionedServiceLiveTe @Test public void testPropertiesCanOverrideDefaultOrg() throws Exception { for (Org org : orgs) { - RestContext newContext = null; + RestContext newContext = null; try { - newContext = createContextWithProperties(overrideDefaults(ImmutableMap.of( - VCloudConstants.PROPERTY_VCLOUD_DEFAULT_ORG, org.getName()))); + newContext = createContext( + overrideDefaults(ImmutableMap.of(VCloudConstants.PROPERTY_VCLOUD_DEFAULT_ORG, org.getName())), + setupModules()).getProviderSpecificContext(); assertEquals(newContext.getApi().findOrgNamed(null), org); } finally { newContext.close(); @@ -556,11 +548,12 @@ public abstract class TerremarkClientLiveTest extends BaseVersionedServiceLiveTe public void testPropertiesCanOverrideDefaultCatalog() throws Exception { for (Org org : orgs) { for (ReferenceType cat : org.getCatalogs().values()) { - RestContext newContext = null; + RestContext newContext = null; try { - newContext = createContextWithProperties(overrideDefaults(ImmutableMap.of( - VCloudConstants.PROPERTY_VCLOUD_DEFAULT_ORG, org.getName(), - VCloudConstants.PROPERTY_VCLOUD_DEFAULT_CATALOG, cat.getName()))); + newContext = createContext( + overrideDefaults(ImmutableMap.of(VCloudConstants.PROPERTY_VCLOUD_DEFAULT_ORG, org.getName(), + VCloudConstants.PROPERTY_VCLOUD_DEFAULT_CATALOG, cat.getName())), setupModules()) + .getProviderSpecificContext(); assertEquals(newContext.getApi().findCatalogInOrgNamed(null, null), connection.getCatalog(cat.getHref())); } finally { newContext.close(); @@ -598,12 +591,13 @@ public abstract class TerremarkClientLiveTest extends BaseVersionedServiceLiveTe for (ReferenceType vdc : org.getVDCs().values()) { VDC response = connection.getVDC(vdc.getHref()); for (ReferenceType net : response.getAvailableNetworks().values()) { - RestContext newContext = null; + RestContext newContext = null; try { - newContext = createContextWithProperties(overrideDefaults(ImmutableMap.of( - VCloudConstants.PROPERTY_VCLOUD_DEFAULT_ORG, org.getName(), - VCloudConstants.PROPERTY_VCLOUD_DEFAULT_VDC, vdc.getName(), - VCloudConstants.PROPERTY_VCLOUD_DEFAULT_NETWORK, net.getName()))); + newContext = createContext( + overrideDefaults(ImmutableMap.of(VCloudConstants.PROPERTY_VCLOUD_DEFAULT_ORG, org.getName(), + VCloudConstants.PROPERTY_VCLOUD_DEFAULT_VDC, vdc.getName(), + VCloudConstants.PROPERTY_VCLOUD_DEFAULT_NETWORK, net.getName())), setupModules()) + .getProviderSpecificContext(); assertEquals(newContext.getApi().findNetworkInOrgVDCNamed(null, null, net.getName()), connection.getNetwork(net.getHref())); } finally { @@ -676,11 +670,12 @@ public abstract class TerremarkClientLiveTest extends BaseVersionedServiceLiveTe public void testPropertiesCanOverrideDefaultVDC() throws Exception { for (Org org : orgs) { for (ReferenceType vdc : org.getVDCs().values()) { - RestContext newContext = null; + RestContext newContext = null; try { - newContext = createContextWithProperties(overrideDefaults(ImmutableMap.of( - VCloudConstants.PROPERTY_VCLOUD_DEFAULT_ORG, org.getName(), - VCloudConstants.PROPERTY_VCLOUD_DEFAULT_VDC, vdc.getName()))); + newContext = createContext( + overrideDefaults(ImmutableMap.of(VCloudConstants.PROPERTY_VCLOUD_DEFAULT_ORG, org.getName(), + VCloudConstants.PROPERTY_VCLOUD_DEFAULT_VDC, vdc.getName())), setupModules()) + .getProviderSpecificContext(); assertEquals(newContext.getApi().findVDCInOrgNamed(null, null), connection.getVDC(vdc.getHref())); } finally { newContext.close(); @@ -707,11 +702,12 @@ public abstract class TerremarkClientLiveTest extends BaseVersionedServiceLiveTe public void testPropertiesCanOverrideDefaultTasksList() throws Exception { for (Org org : orgs) { for (ReferenceType tasksList : org.getTasksLists().values()) { - RestContext newContext = null; + RestContext newContext = null; try { - newContext = createContextWithProperties(overrideDefaults(ImmutableMap.of( - VCloudConstants.PROPERTY_VCLOUD_DEFAULT_ORG, org.getName(), - VCloudConstants.PROPERTY_VCLOUD_DEFAULT_TASKSLIST, tasksList.getName()))); + newContext = createContext( + overrideDefaults(ImmutableMap.of(VCloudConstants.PROPERTY_VCLOUD_DEFAULT_ORG, org.getName(), + VCloudConstants.PROPERTY_VCLOUD_DEFAULT_TASKSLIST, tasksList.getName())), setupModules()) + .getProviderSpecificContext(); assertEquals(newContext.getApi().findTasksListInOrgNamed(null, null), connection.getTasksList(tasksList.getHref())); } finally { @@ -740,12 +736,6 @@ public abstract class TerremarkClientLiveTest extends BaseVersionedServiceLiveTe protected Iterable orgs; - public RestContext createContextWithProperties( - Properties overrides) { - return new ComputeServiceContextFactory(setupRestProperties()).createContext(provider, - ImmutableSet. of(new Log4JLoggingModule()), overrides).getProviderSpecificContext(); - } - @AfterGroups(groups = { "live" }) public void teardownClient() { context.close(); diff --git a/common/trmk/src/test/java/org/jclouds/trmk/vcloud_0_8/compute/suppliers/VAppTemplatesInOrgsLiveTest.java b/common/trmk/src/test/java/org/jclouds/trmk/vcloud_0_8/compute/suppliers/VAppTemplatesInOrgsLiveTest.java index 29374b3a84..1d16d71736 100644 --- a/common/trmk/src/test/java/org/jclouds/trmk/vcloud_0_8/compute/suppliers/VAppTemplatesInOrgsLiveTest.java +++ b/common/trmk/src/test/java/org/jclouds/trmk/vcloud_0_8/compute/suppliers/VAppTemplatesInOrgsLiveTest.java @@ -20,27 +20,20 @@ package org.jclouds.trmk.vcloud_0_8.compute.suppliers; import static org.testng.Assert.assertEquals; -import java.io.IOException; -import java.util.Properties; import java.util.Set; -import org.jclouds.compute.BaseVersionedServiceLiveTest; +import org.jclouds.compute.ComputeServiceContext; import org.jclouds.compute.domain.Image; -import org.jclouds.lifecycle.Closer; -import org.jclouds.logging.log4j.config.Log4JLoggingModule; -import org.jclouds.rest.RestContextFactory; -import org.jclouds.sshj.config.SshjSshClientModule; +import org.jclouds.compute.internal.BaseComputeServiceContextLiveTest; +import org.jclouds.trmk.vcloud_0_8.TerremarkVCloudAsyncClient; import org.jclouds.trmk.vcloud_0_8.TerremarkVCloudClient; import org.jclouds.trmk.vcloud_0_8.domain.CatalogItem; import org.jclouds.trmk.vcloud_0_8.functions.AllCatalogItemsInOrg; -import org.testng.annotations.AfterGroups; -import org.testng.annotations.BeforeGroups; +import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; -import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; import com.google.inject.Injector; -import com.google.inject.Module; /** * Tests behavior of {@code VAppTemplatesInOrgs} @@ -48,29 +41,26 @@ import com.google.inject.Module; * @author Adrian Cole */ @Test(groups = "live", singleThreaded = true, testName = "VAppTemplatesInOrgsLiveTest") -public class VAppTemplatesInOrgsLiveTest extends BaseVersionedServiceLiveTest { +public class VAppTemplatesInOrgsLiveTest +extends BaseComputeServiceContextLiveTest> { + public VAppTemplatesInOrgsLiveTest() { provider = "trmk-vcloudexpress"; } private TerremarkVCloudClient tmClient; private VAppTemplatesInOrgs parser; - private Closer closer; private AllCatalogItemsInOrg allCatalogItemsInOrg; - - @BeforeGroups(groups = { "live" }) - public void setupClient() { - setupCredentials(); - Properties overrides = setupProperties(); - - Injector injector = new RestContextFactory().createContextBuilder(provider, - ImmutableSet. of(new Log4JLoggingModule(), new SshjSshClientModule()),overrides).buildInjector(); + @Override + @BeforeClass(groups = { "integration", "live" }) + public void setupContext() { + super.setupContext(); + Injector injector = context.utils().injector(); tmClient = injector.getInstance(TerremarkVCloudClient.class); allCatalogItemsInOrg = injector.getInstance(AllCatalogItemsInOrg.class); parser = injector.getInstance(VAppTemplatesInOrgs.class); - closer = injector.getInstance(Closer.class); } @Test @@ -85,8 +75,4 @@ public class VAppTemplatesInOrgsLiveTest extends BaseVersionedServiceLiveTest { assert images.size() > 0; } - @AfterGroups(groups = { "live" }) - public void close() throws IOException { - closer.close(); - } } diff --git a/common/trmk/src/test/java/org/jclouds/trmk/vcloud_0_8/internal/BaseTerremarkClientLiveTest.java b/common/trmk/src/test/java/org/jclouds/trmk/vcloud_0_8/internal/BaseTerremarkClientLiveTest.java index b4d2a28909..f8e90f1d2c 100644 --- a/common/trmk/src/test/java/org/jclouds/trmk/vcloud_0_8/internal/BaseTerremarkClientLiveTest.java +++ b/common/trmk/src/test/java/org/jclouds/trmk/vcloud_0_8/internal/BaseTerremarkClientLiveTest.java @@ -18,28 +18,22 @@ */ package org.jclouds.trmk.vcloud_0_8.internal; -import java.util.Properties; -import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; -import org.jclouds.compute.BaseVersionedServiceLiveTest; import org.jclouds.compute.ComputeService; -import org.jclouds.compute.ComputeServiceContextFactory; -import org.jclouds.logging.log4j.config.Log4JLoggingModule; +import org.jclouds.compute.ComputeServiceContext; +import org.jclouds.compute.internal.BaseComputeServiceContextLiveTest; import org.jclouds.net.IPSocket; import org.jclouds.predicates.InetSocketAddressConnect; import org.jclouds.predicates.RetryablePredicate; -import org.jclouds.rest.RestContextFactory; import org.jclouds.ssh.SshClient.Factory; import org.jclouds.sshj.config.SshjSshClientModule; +import org.jclouds.trmk.vcloud_0_8.TerremarkVCloudAsyncClient; import org.jclouds.trmk.vcloud_0_8.TerremarkVCloudClient; -import org.testng.annotations.AfterGroups; -import org.testng.annotations.BeforeGroups; +import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; -import com.google.common.collect.ImmutableSet; -import com.google.inject.Guice; +import com.google.inject.Injector; import com.google.inject.Module; /** @@ -47,7 +41,9 @@ import com.google.inject.Module; * @author Adrian Cole */ @Test(groups = "live", enabled = true, singleThreaded = true) -public abstract class BaseTerremarkClientLiveTest extends BaseVersionedServiceLiveTest { +public abstract class BaseTerremarkClientLiveTest + extends BaseComputeServiceContextLiveTest> { + protected String prefix = System.getProperty("user.name"); protected ComputeService client; @@ -59,31 +55,21 @@ public abstract class BaseTerremarkClientLiveTest socketTester; protected Factory sshFactory; - @SuppressWarnings("unchecked") - protected T getApi() { - return (T) client.getContext().getProviderSpecificContext().getApi(); + protected S getApi() { + return context.getProviderSpecificContext().getApi(); } - @BeforeGroups(groups = { "live" }) - public void setupClient() { - setupCredentials(); - Properties overrides = setupProperties(); - client = new ComputeServiceContextFactory().createContext(provider, - ImmutableSet. of(new Log4JLoggingModule()), overrides).getComputeService(); + @Override + @BeforeClass(groups = { "integration", "live" }) + public void setupContext() { + super.setupContext(); + Injector injector = context.utils().injector(); socketTester = new RetryablePredicate(new InetSocketAddressConnect(), 300, 1, TimeUnit.SECONDS); - sshFactory = Guice.createInjector(getSshModule()).getInstance(Factory.class); + sshFactory = injector.getInstance(Factory.class); } - - protected Properties setupRestProperties() { - return RestContextFactory.getPropertiesFromResource("/rest.properties"); - } - + protected Module getSshModule() { return new SshjSshClientModule(); } - @AfterGroups(groups = { "live" }) - protected void cleanup() throws InterruptedException, ExecutionException, TimeoutException { - client.getContext().close(); - } } \ No newline at end of file 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 89a9ba2178..99e8f6862b 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 @@ -18,7 +18,6 @@ */ package org.jclouds.trmk.vcloud_0_8.internal; -import static org.jclouds.rest.RestContextFactory.contextSpec; import static org.testng.Assert.assertEquals; import java.io.IOException; @@ -30,8 +29,9 @@ import javax.ws.rs.core.HttpHeaders; import org.jclouds.http.HttpRequest; import org.jclouds.http.filters.BasicAuthentication; import org.jclouds.location.Provider; -import org.jclouds.rest.RestClientTest; -import org.jclouds.rest.RestContextSpec; +import org.jclouds.providers.ProviderMetadata; +import org.jclouds.rest.AnonymousProviderMetadata; +import org.jclouds.rest.internal.BaseAsyncClientTest; import org.jclouds.rest.internal.RestAnnotationProcessor; import org.jclouds.trmk.vcloud_0_8.endpoints.VCloudLogin; import org.jclouds.trmk.vcloud_0_8.functions.ParseLoginResponseFromHeaders; @@ -48,9 +48,10 @@ 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 = "VCloudLoginAsyncClientTest") -public class TerremarkVCloudLoginAsyncClientTest extends RestClientTest { +public class TerremarkVCloudLoginAsyncClientTest extends BaseAsyncClientTest { public void testLogin() throws SecurityException, NoSuchMethodException, IOException { Method method = TerremarkVCloudLoginAsyncClient.class.getMethod("login"); @@ -97,10 +98,10 @@ public class TerremarkVCloudLoginAsyncClientTest extends RestClientTest createContextSpec() { - return contextSpec("test", "http://localhost:8080/login", "1", "", "", "identity", "credential", - TerremarkVCloudLoginClient.class, TerremarkVCloudLoginAsyncClient.class); + protected ProviderMetadata createProviderMetadata() { + return AnonymousProviderMetadata.forClientMappedToAsyncClientOnEndpoint(TerremarkVCloudLoginClient.class, + TerremarkVCloudLoginAsyncClient.class, "http://localhost:8080/login"); } + } diff --git a/common/trmk/src/test/java/org/jclouds/trmk/vcloud_0_8/internal/TerremarkVCloudVersionsAsyncClientTest.java b/common/trmk/src/test/java/org/jclouds/trmk/vcloud_0_8/internal/TerremarkVCloudVersionsAsyncClientTest.java index 5a5e03e7d5..c1226a3945 100644 --- a/common/trmk/src/test/java/org/jclouds/trmk/vcloud_0_8/internal/TerremarkVCloudVersionsAsyncClientTest.java +++ b/common/trmk/src/test/java/org/jclouds/trmk/vcloud_0_8/internal/TerremarkVCloudVersionsAsyncClientTest.java @@ -18,7 +18,6 @@ */ package org.jclouds.trmk.vcloud_0_8.internal; -import static org.jclouds.rest.RestContextFactory.contextSpec; import static org.testng.Assert.assertEquals; import java.io.IOException; @@ -26,8 +25,9 @@ import java.lang.reflect.Method; import org.jclouds.http.HttpRequest; import org.jclouds.http.functions.ParseSax; -import org.jclouds.rest.RestClientTest; -import org.jclouds.rest.RestContextSpec; +import org.jclouds.providers.ProviderMetadata; +import org.jclouds.rest.AnonymousProviderMetadata; +import org.jclouds.rest.internal.BaseAsyncClientTest; import org.jclouds.rest.internal.RestAnnotationProcessor; import org.jclouds.trmk.vcloud_0_8.xml.SupportedVersionsHandler; import org.testng.annotations.Test; @@ -41,7 +41,7 @@ import com.google.inject.TypeLiteral; */ // NOTE:without testName, this will not call @Before* and fail w/NPE during surefire @Test(groups = "unit", testName = "VCloudVersionsAsyncClientTest") -public class TerremarkVCloudVersionsAsyncClientTest extends RestClientTest { +public class TerremarkVCloudVersionsAsyncClientTest extends BaseAsyncClientTest { public void testVersions() throws SecurityException, NoSuchMethodException, IOException { Method method = TerremarkVCloudVersionsAsyncClient.class.getMethod("getSupportedVersions"); @@ -70,9 +70,9 @@ public class TerremarkVCloudVersionsAsyncClientTest extends RestClientTest createContextSpec() { - return contextSpec("test", "http://localhost:8080", "1", "", "", "identity", "credential", - TerremarkVCloudVersionsClient.class, TerremarkVCloudVersionsAsyncClient.class); + protected ProviderMetadata createProviderMetadata() { + return AnonymousProviderMetadata.forClientMappedToAsyncClientOnEndpoint(TerremarkVCloudVersionsClient.class, + TerremarkVCloudVersionsAsyncClient.class, "http://localhost:8080"); } } diff --git a/compute/src/main/java/org/jclouds/compute/ComputeService.java b/compute/src/main/java/org/jclouds/compute/ComputeService.java index 701f8f3102..1fd310b619 100644 --- a/compute/src/main/java/org/jclouds/compute/ComputeService.java +++ b/compute/src/main/java/org/jclouds/compute/ComputeService.java @@ -54,7 +54,7 @@ public interface ComputeService { /** * @return a reference to the context that created this ComputeService. */ - ComputeServiceContext getContext(); + ComputeServiceContext getContext(); /** * Makes a new template builder for this service diff --git a/apis/walrus/src/test/java/org/jclouds/walrus/blobstore/WalrusTestInitializer.java b/compute/src/main/java/org/jclouds/compute/ComputeServiceApiMetadata.java similarity index 63% rename from apis/walrus/src/test/java/org/jclouds/walrus/blobstore/WalrusTestInitializer.java rename to compute/src/main/java/org/jclouds/compute/ComputeServiceApiMetadata.java index b9e3ca7f63..f3927be7f6 100644 --- a/apis/walrus/src/test/java/org/jclouds/walrus/blobstore/WalrusTestInitializer.java +++ b/compute/src/main/java/org/jclouds/compute/ComputeServiceApiMetadata.java @@ -16,20 +16,23 @@ * specific language governing permissions and limitations * under the License. */ -package org.jclouds.walrus.blobstore; +package org.jclouds.compute; -import org.jclouds.s3.blobstore.integration.S3TestInitializer; +import org.jclouds.apis.ApiMetadata; +import com.google.common.annotations.Beta; /** * * @author Adrian Cole + * @since 1.5 */ -public class WalrusTestInitializer extends S3TestInitializer { +@Beta +public interface ComputeServiceApiMetadata, M extends ComputeServiceApiMetadata> + extends ApiMetadata { - public WalrusTestInitializer() { - provider = "walrus"; + public static interface Builder, M extends ComputeServiceApiMetadata> + extends ApiMetadata.Builder { } - -} +} \ No newline at end of file diff --git a/compute/src/main/java/org/jclouds/compute/ComputeServiceContext.java b/compute/src/main/java/org/jclouds/compute/ComputeServiceContext.java index acfa69710f..e89f428708 100644 --- a/compute/src/main/java/org/jclouds/compute/ComputeServiceContext.java +++ b/compute/src/main/java/org/jclouds/compute/ComputeServiceContext.java @@ -18,11 +18,12 @@ */ package org.jclouds.compute; +import java.io.Closeable; import java.util.Map; import org.jclouds.compute.internal.ComputeServiceContextImpl; import org.jclouds.domain.Credentials; -import org.jclouds.rest.RestContext; +import org.jclouds.rest.BackedByRestContext; import com.google.common.annotations.Beta; import com.google.inject.ImplementedBy; @@ -35,12 +36,10 @@ import com.google.inject.ImplementedBy; * */ @ImplementedBy(ComputeServiceContextImpl.class) -public interface ComputeServiceContext { +public interface ComputeServiceContext extends Closeable, BackedByRestContext { ComputeService getComputeService(); - RestContext getProviderSpecificContext(); - /** * retrieves a list of credentials for resources created within this context, keyed on {@code id} * of the resource with a namespace prefix (ex. {@code node#}. We are testing this approach for @@ -73,5 +72,6 @@ public interface ComputeServiceContext { */ Utils utils(); + @Override void close(); } \ No newline at end of file diff --git a/compute/src/main/java/org/jclouds/compute/ComputeServiceContextBuilder.java b/compute/src/main/java/org/jclouds/compute/ComputeServiceContextBuilder.java index 2f88d3f282..5a1c302eac 100644 --- a/compute/src/main/java/org/jclouds/compute/ComputeServiceContextBuilder.java +++ b/compute/src/main/java/org/jclouds/compute/ComputeServiceContextBuilder.java @@ -18,55 +18,69 @@ */ package org.jclouds.compute; -import java.util.Properties; +import static com.google.common.base.Preconditions.checkArgument; + +import java.util.NoSuchElementException; +import java.util.concurrent.ConcurrentMap; import org.jclouds.compute.config.ResolvesImages; -import org.jclouds.compute.internal.ComputeServiceContextImpl; -import org.jclouds.rest.RestContextBuilder; +import org.jclouds.compute.stub.StubApiMetadata; +import org.jclouds.providers.ProviderMetadata; +import org.jclouds.rest.internal.ContextBuilder; import com.google.common.base.Predicate; import com.google.common.collect.Iterables; import com.google.inject.Injector; -import com.google.inject.Key; import com.google.inject.Module; -import com.google.inject.util.Types; /** * @author Adrian Cole */ -public abstract class ComputeServiceContextBuilder extends RestContextBuilder { - - public ComputeServiceContextBuilder(Class syncClientType, Class asyncClientType) { - this(syncClientType, asyncClientType, new Properties()); +public abstract class ComputeServiceContextBuilder, M extends ComputeServiceApiMetadata> extends + ContextBuilder { + + /** + * looks up a provider or api with the given id + * + * @param providerOrApi + * id of the provider or api + * @return means to build a context to that provider + * @throws NoSuchElementException + * if the id was not configured. + * @throws IllegalArgumentException + * if the api or provider isn't assignable from ComputeServiceContext + */ + public static ComputeServiceContextBuilder newBuilder(String providerOrApi) throws NoSuchElementException { + ContextBuilder builder = ContextBuilder.newBuilder(providerOrApi); + checkArgument(builder instanceof ComputeServiceContextBuilder, + "type of providerOrApi[%s] is not ComputeServiceContextBuilder: %s", providerOrApi, builder); + return ComputeServiceContextBuilder.class.cast(builder); + } + + @SuppressWarnings("rawtypes") + public static ContextBuilder, StubApiMetadata> forTests() { + return ContextBuilder.newBuilder(new StubApiMetadata()); } - public ComputeServiceContextBuilder(Class syncClientType, Class asyncClientType, - Properties properties) { - super(syncClientType, asyncClientType, properties); - + public ComputeServiceContextBuilder(ProviderMetadata providerMetadata) { + super(providerMetadata); } + public ComputeServiceContextBuilder(M apiMetadata) { + super(apiMetadata); + } + + protected void addImageResolutionModule() { + // do nothing; + // this is to be overridden when needed + } + @Override public Injector buildInjector() { addImageResolutionModuleIfNotPresent(); return super.buildInjector(); } - - /** - * {@inheritDoc} - */ - @Override - public ComputeServiceContextBuilder withModules(Iterable modules) { - return (ComputeServiceContextBuilder) super.withModules(modules); - } - - public ComputeServiceContext buildComputeServiceContext() { - // need the generic type information - return (ComputeServiceContext) buildInjector().getInstance( - Key.get(Types.newParameterizedType(ComputeServiceContextImpl.class, syncClientType, - asyncClientType))); - } - + protected void addImageResolutionModuleIfNotPresent() { if (!Iterables.any(modules, new Predicate() { public boolean apply(Module input) { @@ -78,8 +92,4 @@ public abstract class ComputeServiceContextBuilder extends RestContextBuil } } - protected void addImageResolutionModule() { - // do nothing; - // this is to be overridden when needed - } } \ No newline at end of file diff --git a/compute/src/main/java/org/jclouds/compute/ComputeServiceContextFactory.java b/compute/src/main/java/org/jclouds/compute/ComputeServiceContextFactory.java index ab54485971..0aaa4f3b06 100644 --- a/compute/src/main/java/org/jclouds/compute/ComputeServiceContextFactory.java +++ b/compute/src/main/java/org/jclouds/compute/ComputeServiceContextFactory.java @@ -18,135 +18,114 @@ */ package org.jclouds.compute; -import static org.jclouds.rest.RestContextFactory.createContextBuilder; -import static org.jclouds.util.Throwables2.propagateAuthorizationOrOriginalException; - +import java.util.NoSuchElementException; import java.util.Properties; +import org.jclouds.apis.Apis; import org.jclouds.javax.annotation.Nullable; -import org.jclouds.rest.RestContextFactory; -import org.jclouds.rest.RestContextSpec; +import org.jclouds.providers.ProviderMetadata; +import org.jclouds.providers.Providers; +import org.jclouds.rest.internal.ContextBuilder; +import com.google.common.collect.ImmutableSet; import com.google.inject.Module; /** - * Helper class to instantiate {@code ComputeServiceContext} instances. * + * @see ContextBuilder + * @see ComputeServiceContextBuilder * @author Adrian Cole */ +@Deprecated public class ComputeServiceContextFactory { - private final RestContextFactory contextFactory; - /** - * Initializes with the default properties built-in to jclouds. This is typically stored in the - * classpath resource {@code rest.properties} - * - * @see RestContextFactory#getPropertiesFromResource + * for porting old code to {@link ContextBuilder} */ public ComputeServiceContextFactory() { - this(new RestContextFactory()); } /** - * Finds definitions in the specified properties. + * for porting old code to {@link ContextBuilder} */ public ComputeServiceContextFactory(Properties properties) { - this(new RestContextFactory(properties)); } /** - * - * Uses the supplied RestContextFactory to create {@link ComputeServiceContext}s + * @see #createContext(String, String,String, Iterable, Properties) */ - public ComputeServiceContextFactory(RestContextFactory restContextFactory) { - this.contextFactory = restContextFactory; - } - - public static ComputeServiceContext buildContextUnwrappingExceptions( - ComputeServiceContextBuilder builder) { - try { - return builder.buildComputeServiceContext(); - } catch (Exception e) { - return propagateAuthorizationOrOriginalException(e); - } + public ComputeServiceContext createContext(String providerOrApi, String identity, String credential) { + return createContext(providerOrApi, identity, credential, ImmutableSet. of(), new Properties()); } /** - * @see RestContextFactory#createContextBuilder(String, String, String) + * @see #createContext(String, String, String, Iterable, Properties) */ - public ComputeServiceContext createContext(String provider, String identity, String credential) { - ComputeServiceContextBuilder builder = ComputeServiceContextBuilder.class.cast(contextFactory - .createContextBuilder(provider, identity, credential)); - return buildContextUnwrappingExceptions(builder); + public ComputeServiceContext createContext(String providerOrApi, Properties overrides) { + return createContext(providerOrApi, null, null, ImmutableSet. of(), overrides); } /** - * @see RestContextFactory#createContextBuilder(String, Properties) + * @see #createContext(String, String,String, Iterable, Properties) */ - public ComputeServiceContext createContext(String provider, Properties overrides) { - ComputeServiceContextBuilder builder = ComputeServiceContextBuilder.class.cast(contextFactory - .createContextBuilder(provider, overrides)); - return buildContextUnwrappingExceptions(builder); - } - - /** - * @see RestContextFactory#createContextBuilder(String, Iterable) - */ - public ComputeServiceContext createContext(String provider, Iterable modules, Properties overrides) { - ComputeServiceContextBuilder builder = ComputeServiceContextBuilder.class.cast(contextFactory - .createContextBuilder(provider, modules, overrides)); - return buildContextUnwrappingExceptions(builder); - - } - - /** - * @see RestContextFactory#createContextBuilder(String, String,String, Iterable) - */ - public ComputeServiceContext createContext(String provider, @Nullable String identity, @Nullable String credential, - Iterable modules) { - ComputeServiceContextBuilder builder = ComputeServiceContextBuilder.class.cast(contextFactory - .createContextBuilder(provider, identity, credential, modules)); - return buildContextUnwrappingExceptions(builder); - } - - /** - * @see RestContextFactory#createContextBuilder(String, String,String, Iterable, Properties) - */ - public ComputeServiceContext createContext(String provider, @Nullable String identity, @Nullable String credential, - Iterable modules, Properties overrides) { - ComputeServiceContextBuilder builder = ComputeServiceContextBuilder.class.cast(contextFactory - .createContextBuilder(provider, identity, credential, modules, overrides)); - return buildContextUnwrappingExceptions(builder); - } - - /** - * @see RestContextFactory#createContextBuilder(RestContextSpec) - */ - public ComputeServiceContext createContext(RestContextSpec contextSpec) { - ComputeServiceContextBuilder builder = ComputeServiceContextBuilder.class - .cast(createContextBuilder(contextSpec)); - return buildContextUnwrappingExceptions(builder); - - } - - /** - * @see RestContextFactory#createContextBuilder(RestContextSpec, Properties) - */ - public ComputeServiceContext createContext(RestContextSpec contextSpec, Properties overrides) { - ComputeServiceContextBuilder builder = ComputeServiceContextBuilder.class.cast(createContextBuilder( - contextSpec, overrides)); - return buildContextUnwrappingExceptions(builder); - } - - /** - * @see RestContextFactory#createContextBuilder(RestContextSpec, Iterable, Properties) - */ - public ComputeServiceContext createContext(RestContextSpec contextSpec, Iterable modules, + public ComputeServiceContext createContext(String providerOrApi, Iterable wiring, Properties overrides) { - ComputeServiceContextBuilder builder = ComputeServiceContextBuilder.class.cast(createContextBuilder( - contextSpec, modules, overrides)); - return buildContextUnwrappingExceptions(builder); + return createContext(providerOrApi, null, null, wiring, overrides); } -} \ No newline at end of file + /** + * @see #createContext(String, String,String, Iterable, Properties) + */ + public ComputeServiceContext createContext(String providerOrApi, @Nullable String identity, + @Nullable String credential, Properties overrides) { + return createContext(providerOrApi, identity, credential, ImmutableSet. of(), overrides); + } + + /** + * @see createContext(String, String,String, Iterable, Properties) + */ + public ComputeServiceContext createContext(String providerOrApi, @Nullable String identity, + @Nullable String credential, Iterable wiring) { + return createContext(providerOrApi, identity, credential, wiring, new Properties()); + } + + /** + * for porting old code to {@link ContextBuilder} + * + * @param providerOrApi + * @param identity + * nullable, if credentials are present in the overrides + * @param credential + * nullable, if credentials are present in the overrides + * @param wiring + * Configuration you'd like to pass to the context. Ex. + * ImmutableSet.of(new ExecutorServiceModule(myexecutor)) + * @param overrides + * properties to override defaults with. + * @return initialized context ready for use + */ + @SuppressWarnings("unchecked") + public ComputeServiceContext createContext(String providerOrApi, @Nullable String identity, + @Nullable String credential, Iterable wiring, Properties overrides) { + ContextBuilder builder = null; + try { + ProviderMetadata pm = Providers.withId(providerOrApi); + builder = ComputeServiceContextBuilder.newBuilder(pm); + } catch (NoSuchElementException e) { + builder = ContextBuilder.newBuilder(Apis.withId(providerOrApi)); + } + builder.modules(Iterable.class.cast(wiring)); + builder.overrides(overrides); + if (identity != null) + builder.credentials(identity, credential); + Object context = builder.build(); + if (context instanceof ComputeServiceContext) { + return ComputeServiceContext.class.cast(context); + } else { + throw new IllegalArgumentException("provider " + providerOrApi + " contains an unknown context type: " + + context.getClass().getSimpleName()); + } + + } + +} diff --git a/compute/src/main/java/org/jclouds/compute/StandaloneComputeServiceContextBuilder.java b/compute/src/main/java/org/jclouds/compute/StandaloneComputeServiceContextBuilder.java index 8dc8600dc9..218c2d876b 100644 --- a/compute/src/main/java/org/jclouds/compute/StandaloneComputeServiceContextBuilder.java +++ b/compute/src/main/java/org/jclouds/compute/StandaloneComputeServiceContextBuilder.java @@ -18,15 +18,11 @@ */ package org.jclouds.compute; -import static org.jclouds.Constants.PROPERTY_API_VERSION; -import static org.jclouds.Constants.PROPERTY_ENDPOINT; -import static org.jclouds.Constants.PROPERTY_IDENTITY; - import java.util.List; -import java.util.Properties; -import org.jclouds.PropertiesBuilder; +import org.jclouds.compute.ComputeServiceApiMetadata; import org.jclouds.compute.config.StandaloneComputeServiceClientModule; +import org.jclouds.providers.ProviderMetadata; import com.google.inject.Module; @@ -34,25 +30,21 @@ import com.google.inject.Module; * * @author Adrian Cole */ -public class StandaloneComputeServiceContextBuilder extends ComputeServiceContextBuilder { +public class StandaloneComputeServiceContextBuilder, M extends ComputeServiceApiMetadata> + extends ComputeServiceContextBuilder { - public StandaloneComputeServiceContextBuilder(Class driverClass, Properties props) { - super(driverClass, driverClass, props); - if (properties.size() == 0) - properties.putAll(new PropertiesBuilder().build()); - if (!properties.containsKey("jclouds.provider")) - properties.setProperty("jclouds.provider", "standalone"); - if (!properties.containsKey(PROPERTY_ENDPOINT)) - properties.setProperty(PROPERTY_ENDPOINT, "standalone"); - if (!properties.containsKey(PROPERTY_API_VERSION)) - properties.setProperty(PROPERTY_API_VERSION, "1"); - if (!properties.containsKey(PROPERTY_IDENTITY)) - properties.setProperty(PROPERTY_IDENTITY, System.getProperty("user.name")); + public StandaloneComputeServiceContextBuilder(ProviderMetadata providerMetadata) { + super(providerMetadata); } - + + public StandaloneComputeServiceContextBuilder(M apiMetadata) { + super(apiMetadata); + } + @Override protected void addClientModule(List modules) { - modules.add(new StandaloneComputeServiceClientModule(syncClientType)); + modules.add(new StandaloneComputeServiceClientModule(providerMetadata.getApiMetadata() + .getApi())); } } \ No newline at end of file diff --git a/compute/src/main/java/org/jclouds/compute/StandaloneComputeServiceContextSpec.java b/compute/src/main/java/org/jclouds/compute/StandaloneComputeServiceContextSpec.java deleted file mode 100644 index b22661071f..0000000000 --- a/compute/src/main/java/org/jclouds/compute/StandaloneComputeServiceContextSpec.java +++ /dev/null @@ -1,53 +0,0 @@ -/** - * 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.compute; - -import org.jclouds.PropertiesBuilder; -import org.jclouds.rest.RestContextSpec; - -import com.google.common.collect.ImmutableSet; -import com.google.inject.Module; - -/** - * @author Adrian Cole - */ -public class StandaloneComputeServiceContextSpec extends RestContextSpec { - public StandaloneComputeServiceContextSpec(String provider, String endpoint, String apiVersion, String buildVersion, - String iso3166Codes, String identity, String credential, Class driverClass, - Class> contextBuilderClass) { - this(provider, endpoint, apiVersion, buildVersion, iso3166Codes, identity, credential, driverClass, - contextBuilderClass, ImmutableSet. of()); - } - - public StandaloneComputeServiceContextSpec(String provider, String endpoint, String apiVersion, String buildVersion, - String iso3166Codes, String identity, String credential, Class driverClass, - Class> contextBuilderClass, Iterable modules) { - this(provider, endpoint, apiVersion, buildVersion, iso3166Codes, identity, credential, driverClass, - PropertiesBuilder.class, contextBuilderClass, modules); - } - - @SuppressWarnings( { "unchecked", "rawtypes" }) - public StandaloneComputeServiceContextSpec(String provider, String endpoint, String apiVersion, String buildVersion, - String iso3166Codes, String identity, String credential, Class driverClass, - Class propertiesBuilderClass, - Class> contextBuilderClass, Iterable modules) { - super(provider, endpoint, apiVersion, buildVersion, iso3166Codes, identity, credential, driverClass, driverClass, - (Class) propertiesBuilderClass, (Class) contextBuilderClass, modules); - } -} \ No newline at end of file diff --git a/compute/src/main/java/org/jclouds/compute/internal/BaseComputeService.java b/compute/src/main/java/org/jclouds/compute/internal/BaseComputeService.java index bd4496b219..72fd556769 100644 --- a/compute/src/main/java/org/jclouds/compute/internal/BaseComputeService.java +++ b/compute/src/main/java/org/jclouds/compute/internal/BaseComputeService.java @@ -110,7 +110,7 @@ public class BaseComputeService implements ComputeService { @Named(ComputeServiceConstants.COMPUTE_LOGGER) protected Logger logger = Logger.NULL; - protected final ComputeServiceContext context; + protected final ComputeServiceContext context; protected final Map credentialStore; private final Supplier> images; @@ -136,7 +136,7 @@ public class BaseComputeService implements ComputeService { private final ExecutorService executor; @Inject - protected BaseComputeService(ComputeServiceContext context, Map credentialStore, + protected BaseComputeService(@SuppressWarnings("rawtypes") ComputeServiceContext context, Map credentialStore, @Memoized Supplier> images, @Memoized Supplier> hardwareProfiles, @Memoized Supplier> locations, ListNodesStrategy listNodesStrategy, GetNodeMetadataStrategy getNodeMetadataStrategy, CreateNodesInGroupThenAddToSet runNodesAndAddToSetStrategy, @@ -178,7 +178,7 @@ public class BaseComputeService implements ComputeService { * {@inheritDoc} */ @Override - public ComputeServiceContext getContext() { + public ComputeServiceContext getContext() { return context; } diff --git a/compute/src/main/java/org/jclouds/compute/internal/BaseComputeServiceApiMetadata.java b/compute/src/main/java/org/jclouds/compute/internal/BaseComputeServiceApiMetadata.java new file mode 100644 index 0000000000..c5d828eac0 --- /dev/null +++ b/compute/src/main/java/org/jclouds/compute/internal/BaseComputeServiceApiMetadata.java @@ -0,0 +1,63 @@ +/** + * 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.compute.internal; + +import org.jclouds.apis.ApiType; +import org.jclouds.apis.internal.BaseApiMetadata; +import org.jclouds.compute.ComputeServiceApiMetadata; +import org.jclouds.compute.ComputeServiceContext; + +import com.google.common.annotations.Beta; +import com.google.common.reflect.TypeParameter; +import com.google.common.reflect.TypeToken; + +/** + * + * @author Adrian Cole + * @since 1.5 + */ +@Beta +public abstract class BaseComputeServiceApiMetadata, M extends ComputeServiceApiMetadata> + extends BaseApiMetadata implements ComputeServiceApiMetadata { + + public static class Builder, M extends ComputeServiceApiMetadata> + extends BaseApiMetadata.Builder implements ComputeServiceApiMetadata.Builder { + public Builder() { + type(ApiType.COMPUTE); + } + + /** + * {@inheritDoc} + */ + @Override + @SuppressWarnings("rawtypes") + protected TypeToken contextToken(TypeToken clientToken, TypeToken asyncClientToken) { + return new TypeToken>() { + private static final long serialVersionUID = 1L; + }.where(new TypeParameter() { + }, clientToken).where(new TypeParameter() { + }, asyncClientToken); + } + } + + protected BaseComputeServiceApiMetadata(BaseComputeServiceApiMetadata.Builder builder) { + super(builder); + } + +} \ No newline at end of file diff --git a/compute/src/main/java/org/jclouds/compute/internal/ComputeServiceContextImpl.java b/compute/src/main/java/org/jclouds/compute/internal/ComputeServiceContextImpl.java index 17c1a38d4d..b880525b78 100644 --- a/compute/src/main/java/org/jclouds/compute/internal/ComputeServiceContextImpl.java +++ b/compute/src/main/java/org/jclouds/compute/internal/ComputeServiceContextImpl.java @@ -35,7 +35,7 @@ import org.jclouds.rest.RestContext; * @author Adrian Cole */ @Singleton -public class ComputeServiceContextImpl implements ComputeServiceContext { +public class ComputeServiceContextImpl implements ComputeServiceContext { private final ComputeService computeService; private final RestContext providerSpecificContext; private final Utils utils; @@ -55,9 +55,8 @@ public class ComputeServiceContextImpl implements ComputeServiceContext { return computeService; } - @SuppressWarnings( { "unchecked", "hiding" }) @Override - public RestContext getProviderSpecificContext() { + public RestContext getProviderSpecificContext() { return (RestContext) providerSpecificContext; } diff --git a/compute/src/main/java/org/jclouds/compute/stub/StubApiMetadata.java b/compute/src/main/java/org/jclouds/compute/stub/StubApiMetadata.java index 30b6ffcc6c..c8c299c620 100644 --- a/compute/src/main/java/org/jclouds/compute/stub/StubApiMetadata.java +++ b/compute/src/main/java/org/jclouds/compute/stub/StubApiMetadata.java @@ -19,49 +19,60 @@ package org.jclouds.compute.stub; import java.net.URI; +import java.util.concurrent.ConcurrentMap; import org.jclouds.apis.ApiMetadata; -import org.jclouds.apis.ApiType; -import org.jclouds.apis.BaseApiMetadata; +import org.jclouds.compute.ComputeServiceContext; +import org.jclouds.compute.internal.BaseComputeServiceApiMetadata; +import org.jclouds.compute.stub.internal.StubComputeServiceContextBuilder; + +import com.google.common.reflect.TypeToken; /** * Implementation of {@link ApiMetadata} for jclouds in-memory (Stub) API * * @author Adrian Cole */ -public class StubApiMetadata extends BaseApiMetadata { - - public StubApiMetadata() { - this(builder() - .id("stub") - .type(ApiType.COMPUTE) - .name("in-memory (Stub) API") - .identityName("Unused") - .documentation(URI.create("http://www.jclouds.org/documentation/userguide/compute"))); +@SuppressWarnings("rawtypes") +public class StubApiMetadata extends BaseComputeServiceApiMetadata, StubApiMetadata> { + public static Builder builder() { + return new Builder(); } - // below are so that we can reuse builders, toString, hashCode, etc. - // we have to set concrete classes here, as our base class cannot be - // concrete due to serviceLoader - protected StubApiMetadata(ConcreteBuilder builder) { + @Override + public Builder toBuilder() { + return Builder.class.cast(builder().fromApiMetadata(this)); + } + + public StubApiMetadata() { + super(builder()); + } + + protected StubApiMetadata(Builder builder) { super(builder); } - private static class ConcreteBuilder extends Builder { + public static class Builder extends BaseComputeServiceApiMetadata.Builder, StubApiMetadata> { + + protected Builder(){ + id("stub") + .name("in-memory (Stub) API") + .identityName("Unused") + .defaultIdentity("stub") + .defaultCredential("stub") + .defaultEndpoint("stub") + .context(new TypeToken>(getClass()){ + private static final long serialVersionUID = 1L; + }) + .javaApi(ConcurrentMap.class, ConcurrentMap.class) + .documentation(URI.create("http://www.jclouds.org/documentation/userguide/compute")) + .contextBuilder(TypeToken.of(StubComputeServiceContextBuilder.class)); + } @Override public StubApiMetadata build() { return new StubApiMetadata(this); } - } - public static ConcreteBuilder builder() { - return new ConcreteBuilder(); } - - @Override - public ConcreteBuilder toBuilder() { - return builder().fromApiMetadata(this); - } - } \ No newline at end of file diff --git a/compute/src/main/java/org/jclouds/compute/stub/StubComputeServiceContextBuilder.java b/compute/src/main/java/org/jclouds/compute/stub/internal/StubComputeServiceContextBuilder.java similarity index 63% rename from compute/src/main/java/org/jclouds/compute/stub/StubComputeServiceContextBuilder.java rename to compute/src/main/java/org/jclouds/compute/stub/internal/StubComputeServiceContextBuilder.java index dcfea05ac3..843939dcb8 100644 --- a/compute/src/main/java/org/jclouds/compute/stub/StubComputeServiceContextBuilder.java +++ b/compute/src/main/java/org/jclouds/compute/stub/internal/StubComputeServiceContextBuilder.java @@ -16,14 +16,16 @@ * specific language governing permissions and limitations * under the License. */ -package org.jclouds.compute.stub; +package org.jclouds.compute.stub.internal; import java.util.List; -import java.util.Properties; import java.util.concurrent.ConcurrentMap; +import org.jclouds.compute.ComputeServiceContext; import org.jclouds.compute.StandaloneComputeServiceContextBuilder; +import org.jclouds.compute.stub.StubApiMetadata; import org.jclouds.compute.stub.config.StubComputeServiceContextModule; +import org.jclouds.providers.ProviderMetadata; import com.google.inject.Module; @@ -32,12 +34,18 @@ import com.google.inject.Module; * @author Adrian Cole */ @SuppressWarnings("rawtypes") -public class StubComputeServiceContextBuilder extends StandaloneComputeServiceContextBuilder { +public class StubComputeServiceContextBuilder extends + StandaloneComputeServiceContextBuilder, StubApiMetadata> { - public StubComputeServiceContextBuilder(Properties props) { - super(ConcurrentMap.class, props); + public StubComputeServiceContextBuilder( + ProviderMetadata, StubApiMetadata> providerMetadata) { + super(providerMetadata); } - + + public StubComputeServiceContextBuilder(StubApiMetadata apiMetadata) { + super(apiMetadata); + } + @Override protected void addContextModule(List modules) { modules.add(new StubComputeServiceContextModule()); diff --git a/compute/src/main/java/org/jclouds/compute/util/ComputeServiceUtils.java b/compute/src/main/java/org/jclouds/compute/util/ComputeServiceUtils.java index d044693424..a5f0ab0035 100644 --- a/compute/src/main/java/org/jclouds/compute/util/ComputeServiceUtils.java +++ b/compute/src/main/java/org/jclouds/compute/util/ComputeServiceUtils.java @@ -34,7 +34,7 @@ import java.util.Map.Entry; import java.util.NoSuchElementException; import java.util.regex.Pattern; -import org.jclouds.compute.ComputeServiceContextBuilder; +import org.jclouds.compute.ComputeServiceContext; import org.jclouds.compute.domain.ComputeMetadata; import org.jclouds.compute.domain.Hardware; import org.jclouds.compute.domain.NodeMetadata; @@ -44,13 +44,13 @@ import org.jclouds.compute.domain.Volume; import org.jclouds.compute.predicates.RetryIfSocketNotYetOpen; import org.jclouds.http.HttpRequest; import org.jclouds.net.IPSocket; -import org.jclouds.rest.Providers; import org.jclouds.scriptbuilder.domain.Statement; import org.jclouds.scriptbuilder.domain.Statements; import com.google.common.base.Function; import com.google.common.base.Predicate; import com.google.common.collect.Iterables; +import com.google.common.reflect.TypeToken; /** * @@ -160,8 +160,9 @@ public class ComputeServiceUtils { }); } + @Deprecated public static Iterable getSupportedProviders() { - return Providers.getSupportedProvidersOfType(ComputeServiceContextBuilder.class); + return org.jclouds.rest.Providers.getSupportedProvidersOfType(TypeToken.of(ComputeServiceContext.class)); } public static IPSocket findReachableSocketOnNode(RetryIfSocketNotYetOpen socketTester, final NodeMetadata node, diff --git a/compute/src/test/java/org/jclouds/compute/ComputeTestUtils.java b/compute/src/test/java/org/jclouds/compute/ComputeTestUtils.java index 3b73b6ba16..8fe46dd526 100644 --- a/compute/src/test/java/org/jclouds/compute/ComputeTestUtils.java +++ b/compute/src/test/java/org/jclouds/compute/ComputeTestUtils.java @@ -23,7 +23,6 @@ import static com.google.common.collect.Iterables.get; import static org.testng.Assert.assertEquals; import java.io.File; -import java.io.FileNotFoundException; import java.io.IOException; import java.lang.reflect.UndeclaredThrowableException; import java.net.URI; @@ -35,6 +34,7 @@ import org.jclouds.rest.HttpClient; import org.jclouds.util.Preconditions2; import com.google.common.base.Charsets; +import com.google.common.base.Throwables; import com.google.common.collect.ImmutableMap; import com.google.common.io.Files; @@ -45,7 +45,7 @@ import com.google.common.io.Files; */ public class ComputeTestUtils { - public static Map setupKeyPair() throws FileNotFoundException, IOException { + public static Map setupKeyPair() { String secretKeyFile; try { secretKeyFile = checkNotNull(System.getProperty("test.ssh.keyfile"), "test.ssh.keyfile"); @@ -53,16 +53,20 @@ public class ComputeTestUtils { secretKeyFile = System.getProperty("user.home") + "/.ssh/id_rsa"; } checkSecretKeyFile(secretKeyFile); - String secret = Files.toString(new File(secretKeyFile), Charsets.UTF_8); - assert secret.startsWith("-----BEGIN RSA PRIVATE KEY-----") : "invalid key:\n" + secret; - return ImmutableMap. of("private", secret, "public", Files.toString(new File(secretKeyFile - + ".pub"), Charsets.UTF_8)); + try { + String secret = Files.toString(new File(secretKeyFile), Charsets.UTF_8); + assert secret.startsWith("-----BEGIN RSA PRIVATE KEY-----") : "invalid key:\n" + secret; + return ImmutableMap. of("private", secret, "public", Files.toString(new File(secretKeyFile + + ".pub"), Charsets.UTF_8)); + } catch (IOException e) { + throw Throwables.propagate(e); + } } - public static void checkSecretKeyFile(String secretKeyFile) throws FileNotFoundException { + public static void checkSecretKeyFile(String secretKeyFile) { Preconditions2.checkNotEmpty(secretKeyFile, "System property: [test.ssh.keyfile] set to an empty string"); if (!new File(secretKeyFile).exists()) { - throw new FileNotFoundException("secretKeyFile not found at: " + secretKeyFile); + throw new IllegalStateException("secretKeyFile not found at: " + secretKeyFile); } } diff --git a/compute/src/test/java/org/jclouds/compute/StubComputeServiceIntegrationTest.java b/compute/src/test/java/org/jclouds/compute/StubComputeServiceIntegrationTest.java index cccd9f735f..8b42c1e2eb 100644 --- a/compute/src/test/java/org/jclouds/compute/StubComputeServiceIntegrationTest.java +++ b/compute/src/test/java/org/jclouds/compute/StubComputeServiceIntegrationTest.java @@ -25,7 +25,6 @@ import static org.easymock.EasyMock.replay; import static org.easymock.EasyMock.reportMatcher; import static org.testng.Assert.assertEquals; -import java.io.FileNotFoundException; import java.io.IOException; import java.io.Serializable; import java.util.Map; @@ -38,6 +37,7 @@ import java.util.concurrent.TimeoutException; import org.easymock.IArgumentMatcher; import org.jclouds.compute.domain.ExecResponse; import org.jclouds.compute.domain.NodeMetadata; +import org.jclouds.compute.internal.BaseComputeServiceLiveTest; import org.jclouds.crypto.Pems; import org.jclouds.domain.LoginCredentials; import org.jclouds.io.Payload; @@ -45,7 +45,6 @@ import org.jclouds.net.IPSocket; import org.jclouds.predicates.RetryablePredicate; import org.jclouds.predicates.SocketOpen; import org.jclouds.rest.AuthorizationException; -import org.jclouds.rest.RestContext; import org.jclouds.scriptbuilder.statements.login.AdminAccess; import org.jclouds.scriptbuilder.statements.login.AdminAccess.Configuration; import org.jclouds.ssh.SshClient; @@ -65,8 +64,10 @@ import com.google.inject.Module; * * @author Adrian Cole */ +@SuppressWarnings("rawtypes") @Test(groups = "live", testName="StubComputeServiceIntegrationTest") -public class StubComputeServiceIntegrationTest extends BaseComputeServiceLiveTest { +public class StubComputeServiceIntegrationTest extends + BaseComputeServiceLiveTest> { private static final ExecResponse EXEC_GOOD = new ExecResponse("", "", 0); private static final ExecResponse EXEC_BAD = new ExecResponse("", "", 1); @@ -377,12 +378,6 @@ public class StubComputeServiceIntegrationTest extends BaseComputeServiceLiveTes }; } - @Override - protected void setupCredentials() { - identity = "stub"; - credential = "stub"; - } - protected void assertNodeZero(Set metadataSet) { // TODO: this fails so we override it. } @@ -392,12 +387,6 @@ public class StubComputeServiceIntegrationTest extends BaseComputeServiceLiveTes return null; } - public void testAssignability() throws Exception { - @SuppressWarnings("unused") - RestContext, ConcurrentMap> stubContext = new ComputeServiceContextFactory() - .createContext(provider, identity, credential).getProviderSpecificContext(); - } - private static class PayloadEquals implements IArgumentMatcher, Serializable { private static final long serialVersionUID = 583055160049982067L; @@ -453,7 +442,7 @@ public class StubComputeServiceIntegrationTest extends BaseComputeServiceLiveTes } @Override - protected void setupKeyPairForTest() throws FileNotFoundException, IOException { + protected void setupKeyPairForTest() { keyPair = ImmutableMap. of("public", "ssh-rsa", "private", "-----BEGIN RSA PRIVATE KEY-----"); } diff --git a/compute/src/test/java/org/jclouds/compute/StubTemplateBuilderIntegrationTest.java b/compute/src/test/java/org/jclouds/compute/StubTemplateBuilderIntegrationTest.java index 957f5ee8c1..50955a05cf 100644 --- a/compute/src/test/java/org/jclouds/compute/StubTemplateBuilderIntegrationTest.java +++ b/compute/src/test/java/org/jclouds/compute/StubTemplateBuilderIntegrationTest.java @@ -19,7 +19,9 @@ package org.jclouds.compute; import java.util.Set; +import java.util.concurrent.ConcurrentMap; +import org.jclouds.compute.internal.BaseTemplateBuilderLiveTest; import org.testng.annotations.Test; import com.google.common.collect.ImmutableSet; @@ -29,19 +31,15 @@ import com.google.common.collect.ImmutableSet; * * @author Adrian Cole */ +@SuppressWarnings("rawtypes") @Test(groups = { "integration", "live" }) -public class StubTemplateBuilderIntegrationTest extends BaseTemplateBuilderLiveTest { +public class StubTemplateBuilderIntegrationTest extends + BaseTemplateBuilderLiveTest> { public StubTemplateBuilderIntegrationTest() { provider = "stub"; } - @Override - protected void setupCredentials() { - identity = "stub"; - credential = "stub"; - } - @Override protected Set getIso3166Codes() { return ImmutableSet. of(); diff --git a/compute/src/test/java/org/jclouds/compute/config/ComputeServicePropertiesTest.java b/compute/src/test/java/org/jclouds/compute/config/ComputeServicePropertiesTest.java index 10323446fc..206d6d574c 100644 --- a/compute/src/test/java/org/jclouds/compute/config/ComputeServicePropertiesTest.java +++ b/compute/src/test/java/org/jclouds/compute/config/ComputeServicePropertiesTest.java @@ -22,13 +22,10 @@ import static org.testng.Assert.assertEquals; import java.util.Properties; -import org.jclouds.compute.ComputeServiceContextFactory; +import org.jclouds.compute.ComputeServiceContextBuilder; import org.jclouds.compute.reference.ComputeServiceConstants.InitStatusProperties; import org.testng.annotations.Test; -import com.google.common.collect.ImmutableSet; -import com.google.inject.Module; - /** * * @author Adrian Cole @@ -36,7 +33,7 @@ import com.google.inject.Module; @Test(groups = "unit", testName = "ComputeServicePropertiesTest") public class ComputeServicePropertiesTest { public void testDefaultInitStatusProperties() { - InitStatusProperties props = new ComputeServiceContextFactory().createContext("stub", "", "").utils().injector() + InitStatusProperties props = ComputeServiceContextBuilder.forTests().buildInjector() .getInstance(InitStatusProperties.class); assertEquals(props.initStatusInitialPeriod, 500); assertEquals(props.initStatusMaxPeriod, 5000); @@ -47,8 +44,7 @@ public class ComputeServicePropertiesTest { overrides.setProperty(ComputeServiceProperties.INIT_STATUS_INITIAL_PERIOD, "501"); overrides.setProperty(ComputeServiceProperties.INIT_STATUS_MAX_PERIOD, "5001"); - InitStatusProperties props = new ComputeServiceContextFactory() - .createContext("stub", "", "", ImmutableSet. of(), overrides).utils().injector() + InitStatusProperties props = ComputeServiceContextBuilder.forTests().overrides(overrides).buildInjector() .getInstance(InitStatusProperties.class); assertEquals(props.initStatusInitialPeriod, 501); diff --git a/compute/src/test/java/org/jclouds/compute/internal/BaseComputeServiceApiMetadataTest.java b/compute/src/test/java/org/jclouds/compute/internal/BaseComputeServiceApiMetadataTest.java new file mode 100644 index 0000000000..acbe40a87f --- /dev/null +++ b/compute/src/test/java/org/jclouds/compute/internal/BaseComputeServiceApiMetadataTest.java @@ -0,0 +1,34 @@ +package org.jclouds.compute.internal; + +import java.util.Set; + +import org.jclouds.apis.ApiMetadata; +import org.jclouds.apis.ApiType; +import org.jclouds.apis.Apis; +import org.jclouds.apis.internal.BaseApiMetadataTest; +import org.jclouds.compute.ComputeServiceApiMetadata; +import org.jclouds.compute.ComputeServiceContext; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableSet; +import com.google.common.reflect.TypeToken; + +/** + * + * @author Adrian Cole + */ +@Test(groups = "unit") +public abstract class BaseComputeServiceApiMetadataTest extends BaseApiMetadataTest { + + @SuppressWarnings("rawtypes") + public BaseComputeServiceApiMetadataTest(ComputeServiceApiMetadata toTest) { + super(toTest, ApiType.COMPUTE); + } + + @Test + public void testContextAssignableFromComputeServiceContext() { + Set> all = ImmutableSet.copyOf(Apis.contextAssignableFrom(TypeToken.of(ComputeServiceContext.class))); + assert all.contains(toTest) : String.format("%s not found in %s", toTest, all); + } + +} \ No newline at end of file diff --git a/compute/src/test/java/org/jclouds/compute/BaseVersionedServiceLiveTest.java b/compute/src/test/java/org/jclouds/compute/internal/BaseComputeServiceContextLiveTest.java similarity index 55% rename from compute/src/test/java/org/jclouds/compute/BaseVersionedServiceLiveTest.java rename to compute/src/test/java/org/jclouds/compute/internal/BaseComputeServiceContextLiveTest.java index eca69b2d08..a9f8eb3b3d 100644 --- a/compute/src/test/java/org/jclouds/compute/BaseVersionedServiceLiveTest.java +++ b/compute/src/test/java/org/jclouds/compute/internal/BaseComputeServiceContextLiveTest.java @@ -16,52 +16,48 @@ * specific language governing permissions and limitations * under the License. */ -package org.jclouds.compute; +package org.jclouds.compute.internal; +import java.io.InputStream; import java.util.Properties; +import java.util.concurrent.ConcurrentHashMap; +import org.jclouds.compute.ComputeServiceContext; import org.jclouds.domain.LoginCredentials; import org.jclouds.domain.LoginCredentials.Builder; -import org.jclouds.logging.LoggingModules; -import org.jclouds.logging.config.LoggingModule; -import org.jclouds.rest.BaseRestClientLiveTest; -import org.testng.annotations.BeforeClass; +import org.jclouds.io.CopyInputStreamInputSupplierMap; +import org.jclouds.rest.config.CredentialStoreModule; +import org.jclouds.rest.internal.BaseContextLiveTest; import com.google.common.base.Splitter; +import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; +import com.google.common.io.InputSupplier; +import com.google.inject.Module; +import com.google.inject.util.Modules; /** - * @author Jason King + * @author Jason King, Adrian Cole */ -public abstract class BaseVersionedServiceLiveTest extends BaseRestClientLiveTest { +public abstract class BaseComputeServiceContextLiveTest> extends BaseContextLiveTest { protected String imageId; protected String loginUser; protected String authenticateSudo; protected LoginCredentials loginCredentials = LoginCredentials.builder().user("root").build(); + // isolate tests from eachother, as default credentialStore is static + protected Module credentialStoreModule = new CredentialStoreModule(new CopyInputStreamInputSupplierMap( + new ConcurrentHashMap>())); + @Override protected Properties setupProperties() { - Properties overrides= super.setupProperties(); - if (imageId != null) - overrides.setProperty(provider + ".image-id", imageId); - if (loginUser != null) - overrides.setProperty(provider + ".image.login-user", loginUser); - if (authenticateSudo != null) - overrides.setProperty(provider + ".image.authenticate-sudo", authenticateSudo); - return overrides; - } + Properties overrides = super.setupProperties(); + imageId = setIfTestSystemPropertyPresent(overrides, provider + ".image-id"); + loginUser = setIfTestSystemPropertyPresent(overrides, provider + ".image.login-user"); + authenticateSudo = setIfTestSystemPropertyPresent(overrides, provider + ".image.authenticate-sudo"); - @Override - @BeforeClass - protected void setupCredentials() { - super.setupCredentials(); - - imageId = System.getProperty("test." + provider + ".image-id"); - loginUser = System.getProperty("test." + provider + ".image.login-user"); - authenticateSudo = System.getProperty("test." + provider + ".image.authenticate-sudo"); - - if (loginUser != null){ + if (loginUser != null) { Iterable userPass = Splitter.on(':').split(loginUser); Builder loginCredentialsBuilder = LoginCredentials.builder(); loginCredentialsBuilder.user(Iterables.get(userPass, 0)); @@ -71,10 +67,15 @@ public abstract class BaseVersionedServiceLiveTest extends BaseRestClientLiveTes loginCredentialsBuilder.authenticateSudo(Boolean.valueOf(authenticateSudo)); loginCredentials = loginCredentialsBuilder.build(); } + return overrides; } - protected LoggingModule getLoggingModule() { - return LoggingModules.firstOrJDKLoggingModule(); + @Override + protected Iterable setupModules() { + return ImmutableSet. of(getLoggingModule(), credentialStoreModule, getSshModule()); + } + + protected Module getSshModule() { + return Modules.EMPTY_MODULE; } - } diff --git a/compute/src/test/java/org/jclouds/compute/BaseComputeServiceLiveTest.java b/compute/src/test/java/org/jclouds/compute/internal/BaseComputeServiceLiveTest.java similarity index 92% rename from compute/src/test/java/org/jclouds/compute/BaseComputeServiceLiveTest.java rename to compute/src/test/java/org/jclouds/compute/internal/BaseComputeServiceLiveTest.java index f65cbedbd9..fbde83d12d 100644 --- a/compute/src/test/java/org/jclouds/compute/BaseComputeServiceLiveTest.java +++ b/compute/src/test/java/org/jclouds/compute/internal/BaseComputeServiceLiveTest.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.jclouds.compute; +package org.jclouds.compute.internal; import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Predicates.and; @@ -48,7 +48,6 @@ import static org.jclouds.compute.util.ComputeServiceUtils.getCores; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNotNull; -import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.net.URI; @@ -56,12 +55,10 @@ import java.util.Collection; import java.util.Map; import java.util.Map.Entry; import java.util.NoSuchElementException; -import java.util.Properties; import java.util.Set; import java.util.SortedSet; import java.util.concurrent.Callable; import java.util.concurrent.CancellationException; -import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; @@ -69,6 +66,12 @@ import java.util.concurrent.TimeoutException; import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.jclouds.compute.ComputeService; +import org.jclouds.compute.ComputeServiceContext; +import org.jclouds.compute.ComputeTestUtils; +import org.jclouds.compute.RunNodesException; +import org.jclouds.compute.RunScriptData; +import org.jclouds.compute.RunScriptOnNodesException; import org.jclouds.compute.domain.ComputeMetadata; import org.jclouds.compute.domain.ComputeType; import org.jclouds.compute.domain.ExecResponse; @@ -84,14 +87,10 @@ import org.jclouds.domain.Credentials; import org.jclouds.domain.Location; import org.jclouds.domain.LocationScope; import org.jclouds.domain.LoginCredentials; -import org.jclouds.io.CopyInputStreamInputSupplierMap; -import org.jclouds.logging.LoggingModules; -import org.jclouds.logging.config.LoggingModule; import org.jclouds.net.IPSocket; import org.jclouds.predicates.RetryablePredicate; import org.jclouds.predicates.SocketOpen; import org.jclouds.rest.AuthorizationException; -import org.jclouds.rest.config.CredentialStoreModule; import org.jclouds.scriptbuilder.domain.SaveHttpResponseTo; import org.jclouds.scriptbuilder.domain.Statements; import org.jclouds.scriptbuilder.statements.java.InstallJDK; @@ -110,11 +109,9 @@ import com.google.common.base.Stopwatch; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; -import com.google.common.io.InputSupplier; import com.google.common.net.InetAddresses; import com.google.common.util.concurrent.ListenableFuture; import com.google.gson.annotations.SerializedName; -import com.google.inject.Guice; import com.google.inject.Module; /** @@ -122,24 +119,21 @@ import com.google.inject.Module; * @author Adrian Cole */ @Test(groups = { "integration", "live" }, singleThreaded = true) -public abstract class BaseComputeServiceLiveTest extends BaseVersionedServiceLiveTest { +public abstract class BaseComputeServiceLiveTest> extends BaseComputeServiceContextLiveTest { protected String group; protected Predicate socketTester; protected Predicate preciseSocketTester; protected SortedSet nodes; - protected ComputeServiceContext context; protected ComputeService client; protected Template template; protected Map keyPair; - // isolate tests from eachother, as default credentialStore is static - protected Module credentialStoreModule = new CredentialStoreModule( - new CopyInputStreamInputSupplierMap(new ConcurrentHashMap>())); - + @BeforeGroups(groups = { "integration", "live" }) - public void setupClient() throws InterruptedException, ExecutionException, TimeoutException, IOException { + @Override + public void setupContext() { setServiceDefaults(); if (group == null) group = checkNotNull(provider, "provider"); @@ -147,9 +141,8 @@ public abstract class BaseComputeServiceLiveTest extends BaseVersionedServiceLiv // one! if (group.indexOf('-') == -1) group = group + "-"; - setupCredentials(); setupKeyPairForTest(); - initializeContextAndClient(); + super.setupContext(); buildSocketTester(); } @@ -157,25 +150,13 @@ public abstract class BaseComputeServiceLiveTest extends BaseVersionedServiceLiv } - protected void setupKeyPairForTest() throws FileNotFoundException, IOException { + protected void setupKeyPairForTest() { keyPair = ComputeTestUtils.setupKeyPair(); } - private void initializeContextAndClient() throws IOException { - if (context != null) - context.close(); - Properties props = setupProperties(); - context = new ComputeServiceContextFactory(setupRestProperties()).createContext(provider, - ImmutableSet.of(getLoggingModule(), getSshModule()), props); - client = context.getComputeService(); - } - - protected LoggingModule getLoggingModule() { - return LoggingModules.firstOrJDKLoggingModule(); - } protected void buildSocketTester() { - SocketOpen socketOpen = Guice.createInjector(getSshModule()).getInstance(SocketOpen.class); + SocketOpen socketOpen = context.utils().injector().getInstance(SocketOpen.class); socketTester = new RetryablePredicate(socketOpen, 60, 1, TimeUnit.SECONDS); // wait a maximum of 60 seconds for port 8080 to open. long maxWait = TimeUnit.SECONDS.toMillis(60); @@ -184,19 +165,21 @@ public abstract class BaseComputeServiceLiveTest extends BaseVersionedServiceLiv preciseSocketTester = new RetryablePredicate(socketOpen, maxWait, interval, interval, TimeUnit.MILLISECONDS); } - - abstract protected Module getSshModule(); + @Override + protected void initializeContext() { + super.initializeContext(); + client = context.getComputeService(); + } // wait up to 5 seconds for an auth exception @Test(enabled = true, expectedExceptions = AuthorizationException.class) public void testCorrectAuthException() throws Exception { - ComputeServiceContext context = null; + ComputeServiceContext context = null; try { - Properties overrides = setupProperties(); - overrides.setProperty(provider + ".identity", "MOMMA"); - overrides.setProperty(provider + ".credential", "MIA"); - context = new ComputeServiceContextFactory(setupRestProperties()).createContext(provider, - ImmutableSet. of(getLoggingModule(), credentialStoreModule), overrides); + context = newBuilder() + .credentials("MOMMA", "MIA") + .modules(ImmutableSet.of(getLoggingModule(), credentialStoreModule)) + .overrides(setupProperties()).build(); context.getComputeService().listNodes(); } catch (AuthorizationException e) { throw e; @@ -295,8 +278,7 @@ public abstract class BaseComputeServiceLiveTest extends BaseVersionedServiceLiv runningInGroup(group), "echo I put a bad password", wrapInInitScript(false).runAsRoot(false).overrideLoginCredentials( - LoginCredentials.builder().user(good.identity).noPrivateKey().password("romeo") - .build())); + LoginCredentials.builder().user(good.identity).noPrivateKey().password("romeo").build())); assert responses.size() == 0 : "shouldn't pass with a bad password\n" + responses; } catch (AssertionError e) { throw e; @@ -316,12 +298,12 @@ public abstract class BaseComputeServiceLiveTest extends BaseVersionedServiceLiv assert false : node.getId() + ": " + response; } catch (TimeoutException e) { assert !future.isDone(); - response = client.runScriptOnNode(node.getId(), Statements.exec("/tmp/init-sleeper status"), wrapInInitScript(false) - .runAsRoot(false)); + response = client.runScriptOnNode(node.getId(), Statements.exec("/tmp/init-sleeper status"), + wrapInInitScript(false).runAsRoot(false)); assert !response.getOutput().trim().equals("") : node.getId() + ": " + response; future.cancel(true); - response = client.runScriptOnNode(node.getId(), Statements.exec("/tmp/init-sleeper status"), wrapInInitScript(false) - .runAsRoot(false)); + response = client.runScriptOnNode(node.getId(), Statements.exec("/tmp/init-sleeper status"), + wrapInInitScript(false).runAsRoot(false)); assert response.getOutput().trim().equals("") : node.getId() + ": " + response; try { future.get(); @@ -381,8 +363,7 @@ public abstract class BaseComputeServiceLiveTest extends BaseVersionedServiceLiv } protected static Template addRunScriptToTemplate(Template template) { - template.getOptions().runScript( - Statements.newStatementList(AdminAccess.standard(), InstallJDK.fromOpenJDK())); + template.getOptions().runScript(Statements.newStatementList(AdminAccess.standard(), InstallJDK.fromOpenJDK())); return template; } @@ -408,7 +389,7 @@ public abstract class BaseComputeServiceLiveTest extends BaseVersionedServiceLiv @Test(enabled = true, dependsOnMethods = "testCreateTwoNodesWithRunScript") public void testCreateAnotherNodeWithANewContextToEnsureSharedMemIsntRequired() throws Exception { - initializeContextAndClient(); + initializeContext(); Location existingLocation = Iterables.get(this.nodes, 0).getLocation(); boolean existingLocationIsAssignable = Iterables.any(client.listAssignableLocations(), @@ -439,15 +420,15 @@ public abstract class BaseComputeServiceLiveTest extends BaseVersionedServiceLiv @Test(enabled = true, dependsOnMethods = "testCreateAnotherNodeWithANewContextToEnsureSharedMemIsntRequired") public void testCredentialsCache() throws Exception { - initializeContextAndClient(); + initializeContext(); for (NodeMetadata node : nodes) assert (context.getCredentialStore().get("node#" + node.getId()) != null) : "credentials for " + node.getId(); } protected Map runScriptWithCreds(final String group, OperatingSystem os, LoginCredentials creds) throws RunScriptOnNodesException { - return client.runScriptOnNodesMatching(runningInGroup(group), InstallJDK.fromOpenJDK(), overrideLoginCredentials(creds) - .nameTask("runScriptWithCreds")); + return client.runScriptOnNodesMatching(runningInGroup(group), InstallJDK.fromOpenJDK(), + overrideLoginCredentials(creds).nameTask("runScriptWithCreds")); } protected void checkNodes(Iterable nodes, String group, String taskName) throws IOException { @@ -495,9 +476,9 @@ public abstract class BaseComputeServiceLiveTest extends BaseVersionedServiceLiv assert (metadata.getState() == NodeState.RUNNING) : metadata; // due to DHCP the addresses can actually change in-between runs. assertEquals(metadata.getPrivateAddresses().size(), node.getPrivateAddresses().size(), String.format( - "[%s] didn't match: [%s]", metadata.getPrivateAddresses(), node.getPrivateAddresses().size())); + "[%s] didn't match: [%s]", metadata.getPrivateAddresses(), node.getPrivateAddresses().size())); assertEquals(metadata.getPublicAddresses().size(), node.getPublicAddresses().size(), String.format( - "[%s] didn't match: [%s]", metadata.getPublicAddresses(), node.getPublicAddresses().size())); + "[%s] didn't match: [%s]", metadata.getPublicAddresses(), node.getPublicAddresses().size())); } assertNodeZero(metadataMap.values()); } @@ -620,7 +601,7 @@ public abstract class BaseComputeServiceLiveTest extends BaseVersionedServiceLiv } public ExecResponse init(NodeMetadata node, String processName, String command) { - return client.runScriptOnNode(node.getId(), "/tmp/init-" + processName + " "+command, runAsRoot(false) + return client.runScriptOnNode(node.getId(), "/tmp/init-" + processName + " " + command, runAsRoot(false) .wrapInInitScript(false)); } @@ -897,7 +878,8 @@ public abstract class BaseComputeServiceLiveTest extends BaseVersionedServiceLiv ExecResponse hello = ssh.exec("echo hello"); assertEquals(hello.getOutput().trim(), "hello"); ExecResponse exec = ssh.exec("java -version"); - assert exec.getError().indexOf("1.7") != -1 || exec.getOutput().indexOf("1.7") != -1 : exec + "\n" + assert exec.getError().indexOf("1.7") != -1 || exec.getOutput().indexOf("1.7") != -1 : exec + + "\n" + ssh.exec("cat /tmp/" + taskName + "/" + taskName + ".sh /tmp/" + taskName + "/stdout.log /tmp/" + taskName + "/stderr.log"); } finally { @@ -911,7 +893,10 @@ public abstract class BaseComputeServiceLiveTest extends BaseVersionedServiceLiv if (nodes != null) { testDestroyNodes(); } - context.close(); } + @Override + protected Module getSshModule() { + throw new IllegalStateException("ssh is required for this test!"); + } } diff --git a/compute/src/test/java/org/jclouds/compute/BaseTemplateBuilderLiveTest.java b/compute/src/test/java/org/jclouds/compute/internal/BaseTemplateBuilderLiveTest.java similarity index 86% rename from compute/src/test/java/org/jclouds/compute/BaseTemplateBuilderLiveTest.java rename to compute/src/test/java/org/jclouds/compute/internal/BaseTemplateBuilderLiveTest.java index 8577e98068..7dc9760c6c 100644 --- a/compute/src/test/java/org/jclouds/compute/BaseTemplateBuilderLiveTest.java +++ b/compute/src/test/java/org/jclouds/compute/internal/BaseTemplateBuilderLiveTest.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.jclouds.compute; +package org.jclouds.compute.internal; import static org.jclouds.compute.util.ComputeServiceUtils.getCores; import static org.testng.Assert.assertEquals; @@ -29,9 +29,8 @@ import java.util.NoSuchElementException; import java.util.Properties; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeoutException; +import org.jclouds.compute.ComputeServiceContext; import org.jclouds.compute.config.BaseComputeServiceContextModule; import org.jclouds.compute.domain.Hardware; import org.jclouds.compute.domain.OsFamily; @@ -45,11 +44,7 @@ import org.jclouds.domain.LoginCredentials; import org.jclouds.io.CopyInputStreamInputSupplierMap; import org.jclouds.json.Json; import org.jclouds.json.config.GsonModule; -import org.jclouds.logging.LoggingModules; -import org.jclouds.logging.config.LoggingModule; import org.jclouds.rest.config.CredentialStoreModule; -import org.testng.annotations.AfterTest; -import org.testng.annotations.BeforeClass; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; @@ -68,9 +63,8 @@ import com.google.inject.Module; * @author Adrian Cole */ @Test(groups = "integration,live") -public abstract class BaseTemplateBuilderLiveTest extends BaseVersionedServiceLiveTest { - - protected ComputeServiceContext context; +public abstract class BaseTemplateBuilderLiveTest> extends + BaseComputeServiceContextLiveTest { public void testCompareSizes() throws Exception { Hardware defaultSize = context.getComputeService().templateBuilder().build().getHardware(); @@ -101,17 +95,6 @@ public abstract class BaseTemplateBuilderLiveTest extends BaseVersionedServiceLi defaultTemplate.toString()); } - @BeforeClass - public void setupClient() throws InterruptedException, ExecutionException, TimeoutException, IOException { - setupCredentials(); - context = new ComputeServiceContextFactory(setupRestProperties()).createContext(provider, - ImmutableSet. of(getLoggingModule()), setupProperties()); - } - - protected LoggingModule getLoggingModule() { - return LoggingModules.firstOrJDKLoggingModule(); - } - @DataProvider(name = "osSupported") public Object[][] osSupported() { return convertToArray(Sets.filter(provideAllOperatingSystems(), @@ -176,7 +159,7 @@ public abstract class BaseTemplateBuilderLiveTest extends BaseVersionedServiceLi public void testTemplateBuilderCanUseImageId() throws Exception { Template defaultTemplate = context.getComputeService().templateBuilder().build(); context.close(); - setupClient(); + setupContext(); Template template = context.getComputeService().templateBuilder().imageId(defaultTemplate.getImage().getId()) .locationId(defaultTemplate.getLocation().getId()).build(); @@ -238,13 +221,12 @@ public abstract class BaseTemplateBuilderLiveTest extends BaseVersionedServiceLi public void testTemplateBuilderWithImageIdSpecified() throws IOException { Template defaultTemplate = context.getComputeService().templateBuilder().build(); - ComputeServiceContext context = null; + ComputeServiceContext context = null; try { Properties overrides = setupProperties(); overrides.setProperty("jclouds.image-id", defaultTemplate.getImage().getId()); - context = new ComputeServiceContextFactory().createContext(provider, - ImmutableSet. of(getLoggingModule()), overrides); + context = createContext(overrides, setupModules()); assertEquals(context.getComputeService().templateBuilder().build().toString(), defaultTemplate.toString()); } finally { @@ -257,8 +239,7 @@ public abstract class BaseTemplateBuilderLiveTest extends BaseVersionedServiceLi Properties overrides = setupProperties(); overrides.setProperty(provider + ".image-id", defaultTemplate.getImage().getId()); - context = new ComputeServiceContextFactory().createContext(provider, - ImmutableSet. of(getLoggingModule()), overrides); + context = createContext(overrides, setupModules()); assertEquals(context.getComputeService().templateBuilder().build().toString(), defaultTemplate.toString()); } finally { @@ -275,10 +256,10 @@ public abstract class BaseTemplateBuilderLiveTest extends BaseVersionedServiceLi protected void tryOverrideUsingPropertyKey(String propertyKey) { // isolate tests from eachother, as default credentialStore is static - Module credentialStoreModule = new CredentialStoreModule( - new CopyInputStreamInputSupplierMap(new ConcurrentHashMap>())); - - ComputeServiceContext context = null; + Module credentialStoreModule = new CredentialStoreModule(new CopyInputStreamInputSupplierMap( + new ConcurrentHashMap>())); + + ComputeServiceContext context = null; try { Properties overrides = setupProperties(); String login = loginUser != null ? loginUser : "foo:bar"; @@ -286,8 +267,7 @@ public abstract class BaseTemplateBuilderLiveTest extends BaseVersionedServiceLi boolean auth = authenticateSudo != null ? Boolean.valueOf(authenticateSudo) : true; overrides.setProperty(propertyKey + ".image.authenticate-sudo", auth + ""); - context = new ComputeServiceContextFactory().createContext(provider, - ImmutableSet. of(getLoggingModule(), credentialStoreModule), overrides); + context = createContext(overrides, ImmutableSet.of(credentialStoreModule)); Iterable userPass = Splitter.on(':').split(login); String user = Iterables.get(userPass, 0); @@ -295,7 +275,7 @@ public abstract class BaseTemplateBuilderLiveTest extends BaseVersionedServiceLi assertEquals(context.getComputeService().templateBuilder().build().getImage().getDefaultCredentials(), LoginCredentials.builder().user(user).password(pass).authenticateSudo(auth).build()); } finally { - if (context != null){ + if (context != null) { context.close(); } } @@ -307,9 +287,4 @@ public abstract class BaseTemplateBuilderLiveTest extends BaseVersionedServiceLi assertEquals(provider.getIso3166Codes(), getIso3166Codes()); } - @AfterTest - protected void cleanup() throws InterruptedException, ExecutionException, TimeoutException { - context.close(); - } - } \ No newline at end of file diff --git a/compute/src/test/java/org/jclouds/compute/predicates/ImagePredicatesTest.java b/compute/src/test/java/org/jclouds/compute/predicates/ImagePredicatesTest.java index cbc2e311f0..23ccd6f0af 100644 --- a/compute/src/test/java/org/jclouds/compute/predicates/ImagePredicatesTest.java +++ b/compute/src/test/java/org/jclouds/compute/predicates/ImagePredicatesTest.java @@ -19,7 +19,7 @@ package org.jclouds.compute.predicates; import org.jclouds.compute.ComputeService; -import org.jclouds.compute.ComputeServiceContextFactory; +import org.jclouds.compute.ComputeServiceContextBuilder; import org.jclouds.compute.domain.Image; import org.jclouds.compute.domain.ImageBuilder; import org.testng.annotations.Test; @@ -34,8 +34,7 @@ import com.google.common.collect.Iterables; */ @Test public class ImagePredicatesTest { - ComputeService computeService = new ComputeServiceContextFactory().createContext("stub", "foo", "bar") - .getComputeService(); + ComputeService computeService = ComputeServiceContextBuilder.forTests().build().getComputeService(); public void testImageId() { Image first = Iterables.get(computeService.listImages(), 0); diff --git a/compute/src/test/java/org/jclouds/compute/stub/StubApiMetadataTest.java b/compute/src/test/java/org/jclouds/compute/stub/StubApiMetadataTest.java index 64690551e6..ffab600fba 100644 --- a/compute/src/test/java/org/jclouds/compute/stub/StubApiMetadataTest.java +++ b/compute/src/test/java/org/jclouds/compute/stub/StubApiMetadataTest.java @@ -18,8 +18,7 @@ */ package org.jclouds.compute.stub; -import org.jclouds.apis.ApiType; -import org.jclouds.apis.BaseApiMetadataTest; +import org.jclouds.compute.internal.BaseComputeServiceApiMetadataTest; import org.testng.annotations.Test; /** @@ -27,9 +26,9 @@ import org.testng.annotations.Test; * @author Adrian Cole */ @Test(groups = "unit", testName = "StubApiMetadataTest") -public class StubApiMetadataTest extends BaseApiMetadataTest { +public class StubApiMetadataTest extends BaseComputeServiceApiMetadataTest { public StubApiMetadataTest() { - super(new StubApiMetadata(), ApiType.COMPUTE); + super(new StubApiMetadata()); } } diff --git a/core/src/main/java/org/jclouds/apis/ApiMetadata.java b/core/src/main/java/org/jclouds/apis/ApiMetadata.java index 2f00ada5f6..f81e3040a5 100644 --- a/core/src/main/java/org/jclouds/apis/ApiMetadata.java +++ b/core/src/main/java/org/jclouds/apis/ApiMetadata.java @@ -18,13 +18,17 @@ */ package org.jclouds.apis; - +import java.io.Closeable; import java.net.URI; +import java.util.Properties; import org.jclouds.javax.annotation.Nullable; +import org.jclouds.rest.internal.ContextBuilder; import com.google.common.annotations.Beta; - +import com.google.common.base.Optional; +import com.google.common.reflect.TypeToken; +import com.google.common.util.concurrent.ListenableFuture; /** * The ApiMetadata interface allows jclouds to provide a plugin framework for @@ -34,86 +38,225 @@ import com.google.common.annotations.Beta; * @since 1.5 */ @Beta -public interface ApiMetadata { +public interface ApiMetadata> { - public static interface Builder> { + public static interface Builder> { /** * @see ApiMetadata#getId() */ - B id(String id); + Builder id(String id); /** * @see ApiMetadata#getName() */ - B name(String name); + Builder name(String name); /** * @see ApiMetadata#getType() */ - B type(ApiType type); + Builder type(ApiType type); + + /** + * @see ApiMetadata#getEndpointName() + */ + Builder endpointName(String endpointName); /** * @see ApiMetadata#getIdentityName() */ - B identityName(String identityName); + Builder identityName(String identityName); /** * @see ApiMetadata#getCredentialName() */ - B credentialName(@Nullable String credentialName); + Builder credentialName(@Nullable String credentialName); + + /** + * @see ApiMetadata#getVersion() + */ + Builder version(String version); + + /** + * @see ApiMetadata#getBuildVersion() + */ + Builder buildVersion(@Nullable String buildVersion); + + /** + * @see ApiMetadata#getDefaultEndpoint() + */ + Builder defaultEndpoint(@Nullable String defaultEndpoint); + + /** + * @see ApiMetadata#getDefaultIdentity() + */ + Builder defaultIdentity(@Nullable String defaultIdentity); + + /** + * @see ApiMetadata#getDefaultCredential() + */ + Builder defaultCredential(@Nullable String defaultCredential); + + /** + * @see ApiMetadata#getDefaultProperties() + */ + Builder defaultProperties(Properties defaultProperties); + + /** + * @see ApiMetadata#getApi() + * @see ApiMetadata#getAsyncApi() + */ + Builder javaApi(Class api, Class asyncApi); /** * @see ApiMetadata#getDocumentation() */ - B documentation(URI documentation); + Builder documentation(URI documentation); - ApiMetadata build(); + M build(); - B fromApiMetadata(ApiMetadata in); + Builder fromApiMetadata(M from); + + Builder context(TypeToken context); + + Builder contextBuilder(TypeToken> contextBuilder); + } /** * @see Builder */ - Builder toBuilder(); + Builder> toBuilder(); /** * - * @return the api's unique identifier + * @return the api's unique identifier (ex. vcloud, virtualbox) */ - public String getId(); + String getId(); /** * - * @return the name (display name) of the api + * @return the name (display name) of the api (ex. EC2 Base API) */ - public String getName(); + String getName(); /** * - * @return the api's type + * @return the api's type (ex. COMPUTE or MONITOR) */ - public ApiType getType(); + ApiType getType(); + /** + * + * The {@code endpointName} helps the user supply the correct data when + * prompted. + *

+ * For example, on OpenStack APIs, this could be: {@code Keystone url}
+ * For file-based apis, this could be: {@code Path of byon.yaml} + *

+ * Default: {@code "https endpoint"} + *

+ * + * @return the name (display name) of an endpoint to this api (ex. Keystone + * url, vCloud Director URL). + */ + String getEndpointName(); + /** * * @return the name (display name) of an identity on this api (ex. user, - * email, account, apikey) + * email, account, apikey, tenantId:username) */ - public String getIdentityName(); + String getIdentityName(); /** + * Note: if the api doesn't need a credential, this will return absent. * - * @return the name (display name) of a credential on this api, or null if - * there is none (ex. password, secret, rsaKey) + * @return the name (display name) of a credential on this api, if it is + * required (ex. password, secret, rsaKey) */ - @Nullable - public String getCredentialName(); + Optional getCredentialName(); + + /** + * Explicitly identifies the version of an api. + */ + String getVersion(); + + /** + * Explicitly identifies the build that the server jclouds connects to is + * running. + * + * For example, for virtualbox, the api version may be {@code 4.1.8} while + * the build version is {@code 4.1.8r75467}. Or a vcloud endpoint may be api + * version {@code 1.0} while the build is {@code 1.5.0.0.124312} + */ + Optional getBuildVersion(); + + /** + * Explicitly identifies the most top-level endpoint to a service provider. + * This helps differentiate two providers of the same api, or a different + * environments providing the same api. + * + *

note

+ * + * The type of endpoint is {@code String} as we permit endpoints that require + * variable expansion. + * + * ex. + * + *
+    * https://${jclouds.identity}.blob.core.windows.net
+    * 
+ * + * @return the api's default endpoint, if known. + */ + Optional getDefaultEndpoint(); + + /** + * Explicitly identifies the login identity into a provider + * + * @return the login identity into a provider, if known. + */ + Optional getDefaultIdentity(); + + /** + * Explicitly sets the secret, which when combined with the identity, will + * create an authenticated subject or session + * + * @return the api's default credential, if known. + * @see #getDefaultIdentity + * @see #getCredentialName + */ + Optional getDefaultCredential(); + + /** + * Configuration Properties used when creating connections to this api + * + * @return properties used to create connections to this api + */ + Properties getDefaultProperties(); /** * * @return the url for the API documentation related to this service */ - public URI getDocumentation(); + URI getDocumentation(); + + /** + * + * @return the type of the api which blocks on all requests + */ + Class getApi(); + + /** + * + * @return the type of the api, which is the same as {@link #getApi}, except + * all methods return {@link ListenableFuture} + */ + Class
getAsyncApi(); + + TypeToken getContext(); + + // internal use + TypeToken> getContextBuilder(); } \ No newline at end of file diff --git a/core/src/main/java/org/jclouds/apis/ApiPredicates.java b/core/src/main/java/org/jclouds/apis/ApiPredicates.java index 466de17e03..45b8e5e770 100644 --- a/core/src/main/java/org/jclouds/apis/ApiPredicates.java +++ b/core/src/main/java/org/jclouds/apis/ApiPredicates.java @@ -24,6 +24,7 @@ import org.jclouds.util.Preconditions2; import com.google.common.base.Predicate; import com.google.common.base.Predicates; +import com.google.common.reflect.TypeToken; /** * Container for api filters (predicates). @@ -37,8 +38,8 @@ public class ApiPredicates { * * @return all available apis */ - public static Predicate all() { - return Predicates. alwaysTrue(); + public static Predicate> all() { + return Predicates.> alwaysTrue(); } /** @@ -49,14 +50,14 @@ public class ApiPredicates { * * @return the apis with the given id */ - public static Predicate id(final String id) { + public static Predicate> id(final String id) { Preconditions2.checkNotEmpty(id, "id must be defined"); - return new Predicate() { + return new Predicate>() { /** * {@inheritDoc} */ @Override - public boolean apply(ApiMetadata apiMetadata) { + public boolean apply(ApiMetadata apiMetadata) { return apiMetadata.getId().equals(id); } @@ -78,14 +79,14 @@ public class ApiPredicates { * * @return the apis with the given type */ - public static Predicate type(final ApiType type) { + public static Predicate> type(final ApiType type) { checkNotNull(type, "type must be defined"); - return new Predicate() { + return new Predicate>() { /** * {@inheritDoc} */ @Override - public boolean apply(ApiMetadata apiMetadata) { + public boolean apply(ApiMetadata apiMetadata) { return apiMetadata.getType().equals(type); } @@ -99,4 +100,61 @@ public class ApiPredicates { }; } + /** + * Returns all apis with the given type. + * + * @param type + * the type of the api to return + * + * @return the apis with the given type + */ + public static Predicate> apiAssignableFrom(final TypeToken type) { + checkNotNull(type, "type must be defined"); + return new Predicate>() { + /** + * {@inheritDoc} + */ + @Override + public boolean apply(ApiMetadata apiMetadata) { + return type.isAssignableFrom(apiMetadata.getApi()); + } + + /** + * {@inheritDoc} + */ + @Override + public String toString() { + return "contextAssignableFrom(" + type + ")"; + } + }; + } + + /** + * Returns all apis who's contexts are assignable from the parameter + * + * @param type + * the type of the context to search for + * + * @return the apis with contexts assignable from given type + */ + public static Predicate> contextAssignableFrom(final TypeToken contextType) { + checkNotNull(contextType, "context must be defined"); + return new Predicate>() { + /** + * {@inheritDoc} + */ + @Override + public boolean apply(ApiMetadata apiMetadata) { + return contextType.isAssignableFrom(apiMetadata.getContext().getRawType()); + } + + /** + * {@inheritDoc} + */ + @Override + public String toString() { + return "contextAssignableFrom(" + contextType + ")"; + } + }; + } } \ No newline at end of file diff --git a/core/src/main/java/org/jclouds/apis/Apis.java b/core/src/main/java/org/jclouds/apis/Apis.java index f2d6df4e83..2629f1edc8 100644 --- a/core/src/main/java/org/jclouds/apis/Apis.java +++ b/core/src/main/java/org/jclouds/apis/Apis.java @@ -24,6 +24,9 @@ import static com.google.common.collect.Iterables.find; import java.util.NoSuchElementException; import java.util.ServiceLoader; +import com.google.common.base.Function; +import com.google.common.reflect.TypeToken; + /** * The Apis class provides static methods for accessing apis. * @@ -31,14 +34,29 @@ import java.util.ServiceLoader; */ public class Apis { + public static enum IdFunction implements Function, String> { + INSTANCE; + + @Override + public String apply(ApiMetadata input) { + return input.getId(); + } + + } + + public static Function, String> idFunction() { + return IdFunction.INSTANCE; + } + /** * Returns the apis located on the classpath via * {@link java.util.ServiceLoader}. * * @return all available apis loaded from classpath via ServiceLoader */ - private static Iterable fromServiceLoader() { - return ServiceLoader.load(ApiMetadata.class); + @SuppressWarnings("unchecked") + private static Iterable> fromServiceLoader() { + return Iterable.class.cast(ServiceLoader.load(ApiMetadata.class)); } /** @@ -46,7 +64,7 @@ public class Apis { * * @return all available apis */ - public static Iterable all() { + public static Iterable> all() { return fromServiceLoader(); } @@ -61,7 +79,7 @@ public class Apis { * @throws NoSuchElementException * whenever there are no apis with the provided id */ - public static ApiMetadata withId(String id) throws NoSuchElementException { + public static ApiMetadata withId(String id) throws NoSuchElementException { return find(all(), ApiPredicates.id(id)); } @@ -71,7 +89,7 @@ public class Apis { * * @return the blobstore apis */ - public static Iterable allBlobStore() { + public static Iterable> allBlobStore() { return filter(all(), ApiPredicates.type(ApiType.BLOBSTORE)); } @@ -81,7 +99,7 @@ public class Apis { * * @return the compute service apis */ - public static Iterable allCompute() { + public static Iterable> allCompute() { return filter(all(), ApiPredicates.type(ApiType.COMPUTE)); } @@ -91,7 +109,7 @@ public class Apis { * * @return the queue service apis */ - public static Iterable allQueue() { + public static Iterable> allQueue() { return filter(all(), ApiPredicates.type(ApiType.QUEUE)); } @@ -101,7 +119,7 @@ public class Apis { * * @return the table service apis */ - public static Iterable allTable() { + public static Iterable> allTable() { return filter(all(), ApiPredicates.type(ApiType.TABLE)); } @@ -111,7 +129,7 @@ public class Apis { * * @return the load balancer service apis */ - public static Iterable allLoadBalancer() { + public static Iterable> allLoadBalancer() { return filter(all(), ApiPredicates.type(ApiType.LOADBALANCER)); } @@ -121,7 +139,7 @@ public class Apis { * * @return the load balancer service apis */ - public static Iterable allMonitor() { + public static Iterable> allMonitor() { return filter(all(), ApiPredicates.type(ApiType.MONITOR)); } @@ -133,7 +151,20 @@ public class Apis { * * @return the apis of the provided type */ - public static Iterable ofType(ApiType type) { + public static Iterable> ofType(ApiType type) { return filter(all(), ApiPredicates.type(type)); } -} + + /** + * Returns all apis who's contexts are assignable from the parameter + * + * @param type + * the type of the context to search for + * + * @return the apis with contexts assignable from given type + */ + public static Iterable> contextAssignableFrom(TypeToken type) { + return filter(all(), ApiPredicates.contextAssignableFrom(type)); + } + +} \ No newline at end of file diff --git a/core/src/main/java/org/jclouds/apis/BaseApiMetadata.java b/core/src/main/java/org/jclouds/apis/BaseApiMetadata.java deleted file mode 100644 index c60a7272ce..0000000000 --- a/core/src/main/java/org/jclouds/apis/BaseApiMetadata.java +++ /dev/null @@ -1,211 +0,0 @@ -/** - * 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.apis; - -import static com.google.common.base.Objects.equal; -import static com.google.common.base.Preconditions.checkNotNull; - -import java.net.URI; - -import org.jclouds.javax.annotation.Nullable; - -import com.google.common.base.Objects; -import com.google.common.base.Objects.ToStringHelper; - -/** - * The BaseApiMetadata class is an abstraction of {@link ApiMetadata} to be - * extended by those implementing ApiMetadata. - * - * (Note: This class must be abstract to allow {@link java.util.ServiceLoader} - * to work properly. - * - * @author Jeremy Whitlock , Adrian Cole - */ -public abstract class BaseApiMetadata implements ApiMetadata { - - public static abstract class Builder> implements ApiMetadata.Builder { - protected String id; - protected String name; - protected ApiType type; - protected String identityName; - protected String credentialName; - protected URI documentation; - - @SuppressWarnings("unchecked") - protected B self() { - return (B) this; - } - - /** - * {@inheritDoc} - */ - @Override - public B id(String id) { - this.id = checkNotNull(id, "id"); - return self(); - } - - /** - * {@inheritDoc} - */ - @Override - public B name(String name) { - this.name = checkNotNull(name, "name"); - return self(); - } - - /** - * {@inheritDoc} - */ - @Override - public B type(ApiType type) { - this.type = checkNotNull(type, "type"); - return self(); - } - - /** - * {@inheritDoc} - */ - @Override - public B identityName(String identityName) { - this.identityName = checkNotNull(identityName, "identityName"); - return self(); - } - - /** - * {@inheritDoc} - */ - @Override - public B credentialName(@Nullable String credentialName) { - this.credentialName = credentialName; - return self(); - } - - /** - * {@inheritDoc} - */ - @Override - public B documentation(URI documentation) { - this.documentation = checkNotNull(documentation, "documentation"); - return self(); - } - - public B fromApiMetadata(ApiMetadata in) { - return id(in.getId()).type(in.getType()).name(in.getName()).identityName(in.getIdentityName()) - .credentialName(in.getCredentialName()); - } - } - - protected final String id; - protected final String name; - protected final ApiType type; - protected final String identityName; - protected final String credentialName; - protected final URI documentation; - - protected BaseApiMetadata(Builder builder) { - this.id = builder.id; - this.name = builder.name; - this.type = builder.type; - this.identityName = builder.identityName; - this.credentialName = builder.credentialName; - this.documentation = builder.documentation; - } - - @Override - public boolean equals(Object o) { - if (this == o) - return true; - // subclass equivalence is ok, since we don't know the classloader - // we'll get things from - if (o == null || !(o instanceof ApiMetadata)) - return false; - ApiMetadata that = ApiMetadata.class.cast(o); - return equal(this.getId(), that.getId()) && equal(this.getName(), that.getName()) - && equal(this.getType(), that.getType()) && equal(this.getIdentityName(), that.getIdentityName()) - && equal(this.getCredentialName(), that.getCredentialName()) - && equal(this.getDocumentation(), that.getDocumentation()); - } - - @Override - public int hashCode() { - return Objects - .hashCode(getId(), getName(), getType(), getIdentityName(), getCredentialName(), getDocumentation()); - } - - @Override - public String toString() { - return string().toString(); - } - - protected ToStringHelper string() { - return Objects.toStringHelper("").add("id", getId()).add("name", getName()).add("type", getType()) - .add("identityName", getIdentityName()).add("credentialName", getCredentialName()) - .add("documentation", getDocumentation()); - } - - /** - * {@inheritDoc} - */ - @Override - public String getId() { - return id; - } - - /** - * {@inheritDoc} - */ - @Override - public String getName() { - return name; - } - - /** - * {@inheritDoc} - */ - @Override - public ApiType getType() { - return type; - } - - /** - * {@inheritDoc} - */ - @Override - public String getIdentityName() { - return identityName; - } - - /** - * {@inheritDoc} - */ - @Override - public String getCredentialName() { - return credentialName; - } - - /** - * {@inheritDoc} - */ - @Override - public URI getDocumentation() { - return documentation; - } - -} \ No newline at end of file diff --git a/core/src/main/java/org/jclouds/apis/internal/BaseApiMetadata.java b/core/src/main/java/org/jclouds/apis/internal/BaseApiMetadata.java new file mode 100644 index 0000000000..8496c32620 --- /dev/null +++ b/core/src/main/java/org/jclouds/apis/internal/BaseApiMetadata.java @@ -0,0 +1,509 @@ +/** + * 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.apis.internal; + +import static com.google.common.base.Objects.equal; +import static com.google.common.base.Preconditions.checkNotNull; +import static org.jclouds.Constants.PROPERTY_CONNECTION_TIMEOUT; +import static org.jclouds.Constants.PROPERTY_IO_WORKER_THREADS; +import static org.jclouds.Constants.PROPERTY_ISO3166_CODES; +import static org.jclouds.Constants.PROPERTY_MAX_CONNECTIONS_PER_CONTEXT; +import static org.jclouds.Constants.PROPERTY_MAX_CONNECTIONS_PER_HOST; +import static org.jclouds.Constants.PROPERTY_MAX_CONNECTION_REUSE; +import static org.jclouds.Constants.PROPERTY_MAX_SESSION_FAILURES; +import static org.jclouds.Constants.PROPERTY_PRETTY_PRINT_PAYLOADS; +import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL; +import static org.jclouds.Constants.PROPERTY_SO_TIMEOUT; +import static org.jclouds.Constants.PROPERTY_USER_THREADS; + +import java.io.Closeable; +import java.net.URI; +import java.util.Map; +import java.util.Properties; + +import org.jclouds.apis.ApiMetadata; +import org.jclouds.apis.ApiType; +import org.jclouds.rest.RestContext; +import org.jclouds.rest.internal.ContextBuilder; + +import com.google.common.base.Objects; +import com.google.common.base.Objects.ToStringHelper; +import com.google.common.base.Optional; +import com.google.common.reflect.TypeParameter; +import com.google.common.reflect.TypeToken; + +/** + * The BaseApiMetadata class is an abstraction of {@link ApiMetadata} to be + * extended by those implementing ApiMetadata. + * + * (Note: This class must be abstract to allow {@link java.util.ServiceLoader} + * to work properly. + * + * @author Jeremy Whitlock , Adrian Cole + */ +public abstract class BaseApiMetadata> implements + ApiMetadata { + + public static class Builder> implements + ApiMetadata.Builder { + protected String id; + protected String name; + protected ApiType type; + protected String endpointName = "https endpoint"; + protected String identityName; + protected Optional credentialName = Optional.absent(); + protected String version = ""; + protected Optional buildVersion = Optional.of(""); + protected Optional defaultEndpoint = Optional.absent(); + protected Optional defaultIdentity = Optional.absent(); + protected Optional defaultCredential = Optional.absent(); + protected Properties defaultProperties = defaultProperties(); + protected URI documentation; + // + protected Class api; + protected Class asyncApi; + protected TypeToken context; + protected TypeToken> contextBuilder = new TypeToken>(getClass()) { + private static final long serialVersionUID = 1L; + }; + + public static Properties defaultProperties() { + Properties props = new Properties(); + // TODO: move this to ApiMetadata + props.setProperty(PROPERTY_ISO3166_CODES, ""); + props.setProperty(PROPERTY_MAX_CONNECTIONS_PER_CONTEXT, 20 + ""); + props.setProperty(PROPERTY_MAX_CONNECTIONS_PER_HOST, 0 + ""); + props.setProperty(PROPERTY_SO_TIMEOUT, 60000 + ""); + props.setProperty(PROPERTY_CONNECTION_TIMEOUT, 60000 + ""); + props.setProperty(PROPERTY_IO_WORKER_THREADS, 20 + ""); + props.setProperty(PROPERTY_USER_THREADS, 0 + ""); + props.setProperty(PROPERTY_MAX_CONNECTION_REUSE, 75 + ""); + props.setProperty(PROPERTY_MAX_SESSION_FAILURES, 2 + ""); + props.setProperty(PROPERTY_SESSION_INTERVAL, 60 + ""); + props.setProperty(PROPERTY_PRETTY_PRINT_PAYLOADS, "true"); + return props; + } + + public static Properties defaultPropertiesAnd(Map overrides) { + Properties props = defaultProperties(); + props.putAll(overrides); + return props; + } + + /** + * {@inheritDoc} + */ + @Override + public Builder id(String id) { + this.id = checkNotNull(id, "id"); + return this; + } + + /** + * {@inheritDoc} + */ + @Override + public Builder name(String name) { + this.name = checkNotNull(name, "name"); + return this; + } + + /** + * {@inheritDoc} + */ + @Override + public Builder type(ApiType type) { + this.type = checkNotNull(type, "type"); + return this; + } + + /** + * {@inheritDoc} + */ + @Override + public Builder endpointName(String endpointName) { + this.endpointName = checkNotNull(endpointName, "endpointName"); + return this; + } + + /** + * {@inheritDoc} + */ + @Override + public Builder identityName(String identityName) { + this.identityName = checkNotNull(identityName, "identityName"); + return this; + } + + /** + * {@inheritDoc} + */ + @Override + public Builder credentialName(String credentialName) { + this.credentialName = Optional.fromNullable(credentialName); + return this; + } + + /** + * {@inheritDoc} + */ + @Override + public Builder version(String version) { + this.version = checkNotNull(version, "version"); + return this; + } + + /** + * {@inheritDoc} + */ + @Override + public Builder buildVersion(String buildVersion) { + this.buildVersion = Optional.fromNullable(buildVersion); + return this; + } + + /** + * {@inheritDoc} + */ + @Override + public Builder defaultEndpoint(String defaultEndpoint) { + this.defaultEndpoint = Optional.fromNullable(defaultEndpoint); + return this; + } + + /** + * {@inheritDoc} + */ + @Override + public Builder defaultIdentity(String defaultIdentity) { + this.defaultIdentity = Optional.fromNullable(defaultIdentity); + return this; + } + + /** + * {@inheritDoc} + */ + @Override + public Builder defaultCredential(String defaultCredential) { + this.defaultCredential = Optional.fromNullable(defaultCredential); + return this; + } + + /** + * {@inheritDoc} + */ + @Override + public Builder defaultProperties(Properties defaultProperties) { + this.defaultProperties = checkNotNull(defaultProperties, "defaultProperties"); + return this; + } + + /** + * {@inheritDoc} + */ + @SuppressWarnings("unchecked") + @Override + public Builder javaApi(Class api, Class asyncApi) { + this.api = checkNotNull(api, "api"); + this.asyncApi = checkNotNull(asyncApi, "asyncApi"); + if (context == null) + context(contextToken(TypeToken.of(checkNotNull(api, "api")), TypeToken.of(checkNotNull(asyncApi, "asyncApi")))); + return this; + } + + @SuppressWarnings("rawtypes") + protected TypeToken contextToken(TypeToken clientToken, TypeToken asyncClientToken) { + return new TypeToken>() { + private static final long serialVersionUID = 1L; + }.where(new TypeParameter() { + }, clientToken).where(new TypeParameter() { + }, asyncClientToken); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder documentation(URI documentation) { + this.documentation = checkNotNull(documentation, "documentation"); + return this; + } + + /** + * {@inheritDoc} + */ + @Override + public Builder context(TypeToken context) { + this.context = checkNotNull(context, "context"); + return this; + } + + /** + * {@inheritDoc} + */ + @Override + public Builder contextBuilder(TypeToken> contextBuilder) { + this.contextBuilder = checkNotNull(contextBuilder, "contextBuilder"); + return this; + } + + public Builder fromApiMetadata(M in) { + return id(in.getId()).type(in.getType()).name(in.getName()).endpointName(in.getEndpointName()) + .identityName(in.getIdentityName()).credentialName(in.getCredentialName().orNull()) + .version(in.getVersion()).buildVersion(in.getBuildVersion().orNull()) + .defaultEndpoint(in.getDefaultEndpoint().orNull()).defaultIdentity(in.getDefaultIdentity().orNull()) + .defaultCredential(in.getDefaultCredential().orNull()).defaultProperties(in.getDefaultProperties()) + .documentation(in.getDocumentation()).javaApi(in.getApi(), in.getAsyncApi()).context(in.getContext()) + .contextBuilder(in.getContextBuilder()); + } + + @SuppressWarnings("unchecked") + @Override + public M build() { + return (M) new BaseApiMetadata(this) { + }; + } + + } + + protected final String id; + protected final String name; + protected final ApiType type; + protected final String endpointName; + protected final String identityName; + protected final Optional credentialName; + protected final String version; + protected final Optional buildVersion; + protected final Optional defaultEndpoint; + protected final Optional defaultIdentity; + protected final Optional defaultCredential; + protected final Properties defaultProperties; + protected final URI documentation; + protected final Class api; + protected final Class asyncApi; + protected final TypeToken context; + protected final TypeToken> contextBuilder; + + @SuppressWarnings("unchecked") + protected BaseApiMetadata(Builder builder) { + this(builder.id, builder.name, builder.type, builder.endpointName, builder.identityName, builder.credentialName, + builder.version, builder.buildVersion, builder.defaultEndpoint, builder.defaultIdentity, + builder.defaultCredential, builder.defaultProperties, builder.documentation, Class.class.cast(builder.api), + Class.class.cast(builder.asyncApi), TypeToken.class.cast(builder.context), TypeToken.class + .cast(builder.contextBuilder)); + } + + + public BaseApiMetadata(String id, String name, ApiType type, String endpointName, String identityName, + Optional credentialName, String version, Optional buildVersion, + Optional defaultEndpoint, Optional defaultIdentity, Optional defaultCredential, + Properties defaultProperties, URI documentation, Class api, Class asyncApi, TypeToken context, + TypeToken> contextBuilder) { + this.id = checkNotNull(id, "id"); + this.name = checkNotNull(name, "name"); + this.type = checkNotNull(type, "type"); + this.endpointName = checkNotNull(endpointName, "endpointName"); + this.identityName = checkNotNull(identityName, "identityName"); + this.credentialName = checkNotNull(credentialName, "credentialName"); + this.version = checkNotNull(version, "version"); + this.buildVersion = checkNotNull(buildVersion, "buildVersion"); + this.defaultEndpoint = checkNotNull(defaultEndpoint, "defaultEndpoint"); + this.defaultIdentity = checkNotNull(defaultIdentity, "defaultIdentity"); + this.defaultCredential = checkNotNull(defaultCredential, "defaultCredential"); + this.defaultProperties = checkNotNull(defaultProperties, "defaultProperties"); + this.documentation = checkNotNull(documentation, "documentation"); + this.api = checkNotNull(api, "api"); + this.asyncApi = checkNotNull(asyncApi, "asyncApi"); + this.context = checkNotNull(context, "context"); + this.contextBuilder = checkNotNull(contextBuilder, "contextBuilder"); + } + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + // subclass equivalence is ok, since we don't know the classloader + // we'll get things from + if (o == null || !(o instanceof ApiMetadata)) + return false; + ApiMetadata that = ApiMetadata.class.cast(o); + return equal(this.getId(), that.getId()) && equal(this.getName(), that.getName()) + && equal(this.getType(), that.getType()); + } + + @Override + public int hashCode() { + return Objects.hashCode(getId(), getName(), getType()); + } + + @Override + public String toString() { + return string().toString(); + } + + protected ToStringHelper string() { + return Objects.toStringHelper("").add("id", getId()).add("name", getName()).add("type", getType()) + .add("endpointName", getEndpointName()).add("identityName", getIdentityName()) + .add("credentialName", getCredentialName()).add("documentation", getDocumentation()).add("api", getApi()) + .add("asyncApi", getAsyncApi()); + } + + /** + * {@inheritDoc} + */ + @Override + public String getId() { + return id; + } + + /** + * {@inheritDoc} + */ + @Override + public String getName() { + return name; + } + + /** + * {@inheritDoc} + */ + @Override + public ApiType getType() { + return type; + } + + /** + * {@inheritDoc} + */ + @Override + public String getEndpointName() { + return endpointName; + } + + /** + * {@inheritDoc} + */ + @Override + public String getIdentityName() { + return identityName; + } + + /** + * {@inheritDoc} + */ + @Override + public Optional getCredentialName() { + return credentialName; + } + + /** + * {@inheritDoc} + */ + @Override + public String getVersion() { + return version; + } + + /** + * {@inheritDoc} + */ + @Override + public Optional getBuildVersion() { + return buildVersion; + } + + /** + * {@inheritDoc} + */ + @Override + public Optional getDefaultEndpoint() { + return defaultEndpoint; + } + + /** + * {@inheritDoc} + */ + @Override + public Optional getDefaultIdentity() { + return defaultIdentity; + } + + /** + * {@inheritDoc} + */ + @Override + public Optional getDefaultCredential() { + return defaultCredential; + } + + /** + * {@inheritDoc} + */ + @Override + public Properties getDefaultProperties() { + return defaultProperties; + } + + /** + * {@inheritDoc} + */ + @Override + public URI getDocumentation() { + return documentation; + } + + /** + * {@inheritDoc} + */ + @Override + public Class getApi() { + return api; + } + + /** + * {@inheritDoc} + */ + @Override + public Class getAsyncApi() { + return asyncApi; + } + + /** + * {@inheritDoc} + */ + @Override + public TypeToken getContext() { + return context; + } + + /** + * {@inheritDoc} + */ + @Override + public TypeToken> getContextBuilder() { + return contextBuilder; + } + + @SuppressWarnings("unchecked") + @Override + public Builder toBuilder() { + return new Builder().fromApiMetadata((M) this); + } + +} \ No newline at end of file diff --git a/core/src/main/java/org/jclouds/providers/ProviderMetadata.java b/core/src/main/java/org/jclouds/providers/ProviderMetadata.java index 8542fd0c63..b4b4f25318 100644 --- a/core/src/main/java/org/jclouds/providers/ProviderMetadata.java +++ b/core/src/main/java/org/jclouds/providers/ProviderMetadata.java @@ -18,195 +18,164 @@ */ package org.jclouds.providers; +import java.io.Closeable; import java.net.URI; +import java.util.Properties; import java.util.Set; import org.jclouds.apis.ApiMetadata; import org.jclouds.javax.annotation.Nullable; +import com.google.common.base.Optional; + /** * The ProviderMetadata interface allows jclouds to provide a plugin framework * for gathering cloud provider metadata. * - * @author Jeremy Whitlock + * @author Jeremy Whitlock , Adrian Cole */ -public interface ProviderMetadata { - /** - * @see ApiMetadata#BLOBSTORE_TYPE - */ - @Deprecated - public static final String BLOBSTORE_TYPE = "blobstore"; - /** - * @see ApiMetadata#COMPUTE_TYPE - */ - @Deprecated - public static final String COMPUTE_TYPE = "compute"; - /** - * @see ApiMetadata#LOADBALANCER_TYPE - */ - @Deprecated - public static final String LOADBALANCER_TYPE = "loadbalancer"; - /** - * @see ApiMetadata#TABLE_TYPE - */ - @Deprecated - public static final String TABLE_TYPE = "table"; - /** - * @see ApiMetadata#QUEUE_TYPE - */ - @Deprecated - public static final String QUEUE_TYPE = "queue"; - /** - * @see ApiMetadata#MONITOR_TYPE - */ - @Deprecated - public static final String MONITOR_TYPE = "monitor"; - +public interface ProviderMetadata> { + /** * * @author Adrian Cole * @since 1.5 */ - public static interface Builder> { + public static interface Builder> { /** * @see ProviderMetadata#getId() */ - B id(String id); + Builder id(String id); /** * @see ProviderMetadata#getName() */ - B name(String name); + Builder name(String name); /** - * @see ProviderMetadata#getApi() + * @see ProviderMetadata#getApiMetadata() */ - B api(ApiMetadata api); + Builder apiMetadata(M api); + + /** + * @see ProviderMetadata#getEndpoint() + */ + Builder endpoint(String endpoint); + + /** + * @see ProviderMetadata#getDefaultProperties() + */ + Builder defaultProperties(Properties defaultProperties); /** * @see ProviderMetadata#getConsole() */ - B console(@Nullable URI console); + Builder console(@Nullable URI console); /** * @see ProviderMetadata#getHomepage() */ - B homepage(@Nullable URI homepage); + Builder homepage(@Nullable URI homepage); /** * @see ProviderMetadata#getLinkedServices() */ - B linkedServices(Iterable linkedServices); + Builder linkedServices(Iterable linkedServices); /** * @see ProviderMetadata#getLinkedServices() */ - B linkedServices(String... linkedServices); + Builder linkedServices(String... linkedServices); /** * @see ProviderMetadata#getLinkedServices() */ - B linkedService(String linkedService); + Builder linkedService(String linkedService); /** * @see ProviderMetadata#getIso3166Code() */ - B iso3166Codes(Iterable iso3166Codes); + Builder iso3166Codes(Iterable iso3166Codes); /** * @see ProviderMetadata#getIso3166Code() */ - B iso3166Codes(String... iso3166Codes); + Builder iso3166Codes(String... iso3166Codes); /** * @see ProviderMetadata#getIso3166Code() */ - B iso3166Code(String iso3166Code); + Builder iso3166Code(String iso3166Code); - ProviderMetadata build(); + ProviderMetadata build(); + + Builder fromProviderMetadata(ProviderMetadata in); - B fromProviderMetadata(ProviderMetadata in); } /** * @see Builder * @since 1.5 */ - Builder toBuilder(); + Builder toBuilder(); /** * - * @return the provider's unique identifier + * @return the provider's unique identifier (ex. aws-ec2, trystack-nova) */ public String getId(); /** * - * @return the name (display name) of the provider + * @return the name (display name) of the provider (ex. GoGrid) */ public String getName(); - /** - * - * @see #getApi() - * @see ApiMetadata#getType - */ - @Deprecated - public String getType(); - /** * * @return the provider's api * @since 1.5 */ - public ApiMetadata getApi(); + public M getApiMetadata(); + + /** + * @see ApiMetadata#getEndpoint + * @return the url for the provider's api + */ + public String getEndpoint(); + + /** + * Configuration Properties used when creating connections to this provider. + * For example, location information, or default networking configuration. + * + * @return properties used to create connections to this provider + * @see ApiMetadata#getDefaultProperties + */ + Properties getDefaultProperties(); /** * - * @see #getApi() - * @see ApiMetadata#getIdentityName + * @return the url for the provider's console, or absent if one doesn't exist */ - @Deprecated - public String getIdentityName(); + Optional getConsole(); /** * - * @see #getApi() - * @see ApiMetadata#getCredentialName + * @return the url for the provider's homepage, or absent if unknown */ - @Deprecated - public String getCredentialName(); + Optional getHomepage(); /** * - * @see #getApi() - * @see ApiMetadata#getDocumentation + * @return ids of all known {@link ProviderMetadata providers} which have the + * same account as this. */ - @Deprecated - public URI getApiDocumentation(); - - /** - * - * @return the url for the provider's console, or null if one doesn't exist - */ - @Nullable - public URI getConsole(); - - /** - * - * @return the url for the provider's homepage - */ - public URI getHomepage(); - - /** - * - * @return all known services linked to the same account on this provider - */ - public Set getLinkedServices(); + Set getLinkedServices(); /** + * iso 3166 codes; ex. US-CA,US * * @return all known region/location ISO 3166 codes */ - public Set getIso3166Codes(); + Set getIso3166Codes(); } \ No newline at end of file diff --git a/core/src/main/java/org/jclouds/providers/ProviderPredicates.java b/core/src/main/java/org/jclouds/providers/ProviderPredicates.java index f3b81950fd..079d9c9f28 100644 --- a/core/src/main/java/org/jclouds/providers/ProviderPredicates.java +++ b/core/src/main/java/org/jclouds/providers/ProviderPredicates.java @@ -18,13 +18,17 @@ */ package org.jclouds.providers; +import java.io.Closeable; + import org.jclouds.apis.ApiMetadata; +import org.jclouds.apis.ApiPredicates; import org.jclouds.apis.ApiType; import org.jclouds.util.Preconditions2; import com.google.common.base.Preconditions; import com.google.common.base.Predicate; import com.google.common.base.Predicates; +import com.google.common.reflect.TypeToken; /** * Container for provider filters (predicates). @@ -33,13 +37,38 @@ import com.google.common.base.Predicates; */ public class ProviderPredicates { + public static class ContextAssignableFrom> implements Predicate> { + private final TypeToken contextClass; + + public ContextAssignableFrom(TypeToken contextClass) { + Preconditions.checkNotNull(contextClass, "context must be defined"); + this.contextClass = contextClass; + } + + /** + * {@inheritDoc} + */ + @Override + public boolean apply(ProviderMetadata providerMetadata) { + return ApiPredicates.contextAssignableFrom(contextClass).apply(providerMetadata.getApiMetadata()); + } + + /** + * {@inheritDoc} + */ + @Override + public String toString() { + return "contextAssignableFrom(" + contextClass + ")"; + } + } + /** * Returns all providers available to jclouds regardless of type. * * @return all available providers */ - public static Predicate all() { - return Predicates. alwaysTrue(); + public static Predicate> all() { + return Predicates.> alwaysTrue(); } /** @@ -50,14 +79,14 @@ public class ProviderPredicates { * * @return the providers with the given id */ - public static Predicate id(final String id) { + public static Predicate> id(final String id) { Preconditions2.checkNotEmpty(id, "id must be defined"); - return new Predicate() { + return new Predicate>() { /** * {@inheritDoc} */ @Override - public boolean apply(ProviderMetadata providerMetadata) { + public boolean apply(ProviderMetadata providerMetadata) { return providerMetadata.getId().equals(id); } @@ -79,15 +108,15 @@ public class ProviderPredicates { * * @return the providers with the given type */ - public static Predicate type(final ApiType type) { + public static Predicate> type(final ApiType type) { Preconditions.checkNotNull(type, "type must be defined"); - return new Predicate() { + return new Predicate>() { /** * {@inheritDoc} */ @Override - public boolean apply(ProviderMetadata providerMetadata) { - return providerMetadata.getApi().getType().equals(type); + public boolean apply(ProviderMetadata providerMetadata) { + return providerMetadata.getApiMetadata().getType().equals(type); } /** @@ -104,7 +133,7 @@ public class ProviderPredicates { * @see #type(ApiMetadata) */ @Deprecated - public static Predicate type(final String type) { + public static Predicate> type(final String type) { return type(ApiType.fromValue(type)); } @@ -117,15 +146,15 @@ public class ProviderPredicates { * * @return the providers with the given ISO 3166 code */ - public static Predicate boundedByIso3166Code(final String iso3166Code) { + public static Predicate> boundedByIso3166Code(final String iso3166Code) { Preconditions.checkNotNull(iso3166Code, "iso3166Code must not be null"); - return new Predicate() { + return new Predicate>() { /** * {@inheritDoc} */ @Override - public boolean apply(ProviderMetadata providerMetadata) { + public boolean apply(ProviderMetadata providerMetadata) { return providerContainsIso3166Code(providerMetadata, iso3166Code); } @@ -148,15 +177,16 @@ public class ProviderPredicates { * * @return the providers that have at least one ISO 3166 code in common */ - public static Predicate intersectingIso3166Code(final ProviderMetadata refProviderMetadata) { + public static Predicate> intersectingIso3166Code( + final ProviderMetadata refProviderMetadata) { Preconditions.checkNotNull(refProviderMetadata, "refProviderMetadata must not be null"); - return new Predicate() { + return new Predicate>() { /** * {@inheritDoc} */ @Override - public boolean apply(ProviderMetadata providerMetadata) { + public boolean apply(ProviderMetadata providerMetadata) { for (String refIso3166Code : refProviderMetadata.getIso3166Codes()) { // Return only if the potential provider contains the same ISO // 3166 code and the provider and @@ -191,7 +221,7 @@ public class ProviderPredicates { * * @return the result */ - private static boolean providerContainsIso3166Code(ProviderMetadata providerMetadata, String iso3166Code) { + private static boolean providerContainsIso3166Code(ProviderMetadata providerMetadata, String iso3166Code) { for (String availCode : providerMetadata.getIso3166Codes()) { if (iso3166Code.indexOf('-') == -1) { if (availCode.startsWith(iso3166Code + "-")) { @@ -206,22 +236,23 @@ public class ProviderPredicates { } /** - * Returns all providers with an instance of the given api. + * Returns all providers with an apimetadata assignable from the given api. * * @param apiClass * the api of the provider to return * - * @return the providers with the given api + * @return the providers with an apimetadata assignable from the given api. */ - public static Predicate apiInstanceOf(final Class apiClass) { + public static > Predicate> apiMetadataAssignableFrom( + final TypeToken apiClass) { Preconditions.checkNotNull(apiClass, "api must be defined"); - return new Predicate() { + return new Predicate>() { /** * {@inheritDoc} */ @Override - public boolean apply(ProviderMetadata providerMetadata) { - return Predicates.instanceOf(apiClass).apply(providerMetadata.getApi()); + public boolean apply(ProviderMetadata providerMetadata) { + return apiClass.isAssignableFrom(providerMetadata.getApiMetadata().getClass()); } /** @@ -229,8 +260,22 @@ public class ProviderPredicates { */ @Override public String toString() { - return "apiInstanceOf(" + apiClass + ")"; + return "apiAssignableFrom(" + apiClass + ")"; } }; } + + /** + * Returns all providers with an context assignable from the given class. + * + * @param contextClass + * the context of the provider to return + * + * @return the providers with an context assignable from the given class. + */ + public static > Predicate> contextAssignableFrom( + final TypeToken contextClass) { + return new ContextAssignableFrom(contextClass); + } + } \ No newline at end of file diff --git a/core/src/main/java/org/jclouds/providers/Providers.java b/core/src/main/java/org/jclouds/providers/Providers.java index 5b883adc0c..32fb5844db 100644 --- a/core/src/main/java/org/jclouds/providers/Providers.java +++ b/core/src/main/java/org/jclouds/providers/Providers.java @@ -21,14 +21,17 @@ package org.jclouds.providers; import static com.google.common.collect.Iterables.filter; import static com.google.common.collect.Iterables.find; +import java.io.Closeable; import java.util.NoSuchElementException; import java.util.ServiceLoader; import org.jclouds.apis.ApiMetadata; import org.jclouds.apis.ApiType; +import com.google.common.base.Function; import com.google.common.base.Preconditions; import com.google.common.base.Predicates; +import com.google.common.reflect.TypeToken; /** * The Providers class provides static methods for accessing providers. @@ -37,14 +40,42 @@ import com.google.common.base.Predicates; */ public class Providers { + public static enum IdFunction implements Function, String> { + INSTANCE; + + @Override + public String apply(ProviderMetadata input) { + return input.getId(); + } + + } + + public static Function, String> idFunction() { + return IdFunction.INSTANCE; + } + + public static class ApiMetadataFunction> implements + Function, ApiMetadata> { + @Override + public ApiMetadata apply(ProviderMetadata input) { + return input.getApiMetadata(); + } + + } + + public static > Function, ApiMetadata> apiMetadataFunction() { + return new ApiMetadataFunction(); + } + /** * Returns the providers located on the classpath via * {@link java.util.ServiceLoader}. * * @return all available providers loaded from classpath via ServiceLoader */ - private static Iterable fromServiceLoader() { - return ServiceLoader.load(ProviderMetadata.class); + @SuppressWarnings("unchecked") + public static Iterable> fromServiceLoader() { + return Iterable.class.cast(ServiceLoader.load(ProviderMetadata.class)); } /** @@ -52,7 +83,7 @@ public class Providers { * * @return all available providers */ - public static Iterable all() { + public static Iterable> all() { return fromServiceLoader(); } @@ -67,7 +98,7 @@ public class Providers { * @throws NoSuchElementException * whenever there are no providers with the provided id */ - public static ProviderMetadata withId(String id) throws NoSuchElementException { + public static ProviderMetadata withId(String id) throws NoSuchElementException { return find(all(), ProviderPredicates.id(id)); } @@ -77,7 +108,7 @@ public class Providers { * * @return the blobstore providers */ - public static Iterable allBlobStore() { + public static Iterable> allBlobStore() { return filter(all(), ProviderPredicates.type(ApiType.BLOBSTORE)); } @@ -87,7 +118,7 @@ public class Providers { * * @return the compute service providers */ - public static Iterable allCompute() { + public static Iterable> allCompute() { return filter(all(), ProviderPredicates.type(ApiType.COMPUTE)); } @@ -97,7 +128,7 @@ public class Providers { * * @return the queue service providers */ - public static Iterable allQueue() { + public static Iterable> allQueue() { return filter(all(), ProviderPredicates.type(ApiType.QUEUE)); } @@ -107,7 +138,7 @@ public class Providers { * * @return the table service providers */ - public static Iterable allTable() { + public static Iterable> allTable() { return filter(all(), ProviderPredicates.type(ApiType.TABLE)); } @@ -117,7 +148,7 @@ public class Providers { * * @return the load balancer service providers */ - public static Iterable allLoadBalancer() { + public static Iterable> allLoadBalancer() { return filter(all(), ProviderPredicates.type(ApiType.LOADBALANCER)); } @@ -129,7 +160,7 @@ public class Providers { * * @return the providers of the provided type */ - public static Iterable ofType(ApiType type) { + public static Iterable> ofType(ApiType type) { return filter(all(), ProviderPredicates.type(type)); } @@ -141,19 +172,25 @@ public class Providers { * * @return the providers of the provided api */ - public static Iterable ofApi(ApiMetadata api) { + public static Iterable> apiMetadataAssignableFrom(TypeToken api) { Preconditions.checkNotNull(api, "api must be defined"); - return filter(all(), ProviderPredicates.apiInstanceOf(api.getClass())); + return filter(all(), ProviderPredicates.apiMetadataAssignableFrom(api)); } - + /** - * @see #ofType(ApiMetadata) + * Returns the providers that are of the provided context. + * + * @param context + * the context to providers to return + * + * @return the providers of the provided context */ - @Deprecated - public static Iterable ofType(String type) { - return ofType(ApiType.fromValue(type)); + public static Iterable> contextAssignableFrom(TypeToken context) { + Preconditions.checkNotNull(context, "context must be defined"); + return filter(all(), new ProviderPredicates.ContextAssignableFrom(context)); } + /** * Returns the providers that are bound to the same location as the given ISO * 3166 code regardless of type. @@ -163,7 +200,7 @@ public class Providers { * * @return the providers bound by the given ISO 3166 code */ - public static Iterable boundedByIso3166Code(String iso3166Code) { + public static Iterable> boundedByIso3166Code(String iso3166Code) { return filter(all(), ProviderPredicates.boundedByIso3166Code(iso3166Code)); } @@ -179,19 +216,11 @@ public class Providers { * @return the providers bound by the given ISO 3166 code and of the proper * type */ - public static Iterable boundedByIso3166Code(String iso3166Code, ApiType type) { + public static Iterable> boundedByIso3166Code(String iso3166Code, ApiType type) { return filter(all(), Predicates.and(ProviderPredicates.boundedByIso3166Code(iso3166Code), ProviderPredicates.type(type))); } - /** - * @see #boundedByIso3166Code(String iso3166Code, ApiType) - */ - @Deprecated - public static Iterable boundedByIso3166Code(String iso3166Code, String type) { - return boundedByIso3166Code(iso3166Code, ApiType.fromValue(type)); - } - /** * Returns the providers that have at least one common ISO 3166 code in * common regardless of type. @@ -201,7 +230,7 @@ public class Providers { * * @return the providers that share at least one common ISO 3166 code */ - public static Iterable collocatedWith(ProviderMetadata providerMetadata) { + public static Iterable> collocatedWith(ProviderMetadata providerMetadata) { return filter(all(), ProviderPredicates.intersectingIso3166Code(providerMetadata)); } @@ -217,17 +246,10 @@ public class Providers { * @return the providers that share at least one common ISO 3166 code and of * the given type */ - public static Iterable collocatedWith(ProviderMetadata providerMetadata, ApiType type) { + public static Iterable> collocatedWith(ProviderMetadata providerMetadata, + ApiType type) { return filter(all(), Predicates.and(ProviderPredicates.intersectingIso3166Code(providerMetadata), ProviderPredicates.type(type))); } - /** - * @see #collocatedWith(ProviderMetadata iso3166Code, ApiType) - */ - @Deprecated - public static Iterable collocatedWith(ProviderMetadata providerMetadata, String type) { - return collocatedWith(providerMetadata, ApiType.fromValue(type)); - } - } diff --git a/core/src/main/java/org/jclouds/providers/BaseProviderMetadata.java b/core/src/main/java/org/jclouds/providers/internal/BaseProviderMetadata.java similarity index 50% rename from core/src/main/java/org/jclouds/providers/BaseProviderMetadata.java rename to core/src/main/java/org/jclouds/providers/internal/BaseProviderMetadata.java index f9c5765c38..89376f9d23 100644 --- a/core/src/main/java/org/jclouds/providers/BaseProviderMetadata.java +++ b/core/src/main/java/org/jclouds/providers/internal/BaseProviderMetadata.java @@ -16,21 +16,25 @@ * specific language governing permissions and limitations * under the License. */ -package org.jclouds.providers; +package org.jclouds.providers.internal; import static com.google.common.base.Objects.equal; import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.collect.Iterables.addAll; import static com.google.common.collect.Sets.newLinkedHashSet; +import java.io.Closeable; import java.net.URI; +import java.util.Properties; import java.util.Set; import org.jclouds.apis.ApiMetadata; import org.jclouds.javax.annotation.Nullable; +import org.jclouds.providers.ProviderMetadata; import com.google.common.base.Objects; import com.google.common.base.Objects.ToStringHelper; +import com.google.common.base.Optional; import com.google.common.collect.ImmutableSet; /** @@ -42,27 +46,31 @@ import com.google.common.collect.ImmutableSet; * * @author Adrian Cole */ -public abstract class BaseProviderMetadata implements ProviderMetadata { +public abstract class BaseProviderMetadata> + implements ProviderMetadata { - public static abstract class Builder> implements ProviderMetadata.Builder { + @Override + public ProviderMetadata.Builder toBuilder() { + return new BaseProviderMetadata.Builder().fromProviderMetadata(this); + } + + public static class Builder> implements + ProviderMetadata.Builder { protected String id; protected String name; - protected ApiMetadata api; + protected M api; + protected String endpoint; + protected Properties defaultProperties = new Properties(); protected URI console; protected URI homepage; protected Set linkedServices = newLinkedHashSet(); protected Set iso3166Codes = newLinkedHashSet(); - @SuppressWarnings("unchecked") - protected B self() { - return (B) this; - } - /** * {@inheritDoc} */ @Override - public B id(String id) { + public Builder id(String id) { this.id = checkNotNull(id, "id"); return linkedService(id); } @@ -71,52 +79,72 @@ public abstract class BaseProviderMetadata implements ProviderMetadata { * {@inheritDoc} */ @Override - public B name(String name) { + public Builder name(String name) { this.name = checkNotNull(name, "name"); - return self(); + return this; } /** * {@inheritDoc} */ @Override - public B api(ApiMetadata api) { + public Builder apiMetadata(M api) { this.api = checkNotNull(api, "api"); - return self(); + if (this.endpoint == null) + this.endpoint = api.getDefaultEndpoint().orNull(); + return this; } /** * {@inheritDoc} */ @Override - public B console(@Nullable URI console) { + public Builder endpoint(String endpoint) { + this.endpoint = checkNotNull(endpoint, "endpoint"); + return this; + } + + /** + * {@inheritDoc} + */ + @Override + public Builder defaultProperties(Properties defaultProperties) { + this.defaultProperties = checkNotNull(defaultProperties, "defaultProperties"); + return this; + } + + /** + * {@inheritDoc} + */ + @Override + public Builder console(@Nullable URI console) { this.console = console; - return self(); + return this; } /** * {@inheritDoc} */ @Override - public B homepage(URI homepage) { + public Builder homepage(URI homepage) { this.homepage = homepage; - return self(); + return this; } /** * {@inheritDoc} */ @Override - public B linkedServices(Iterable linkedServices) { + public Builder linkedServices(Iterable linkedServices) { addAll(this.linkedServices, checkNotNull(linkedServices, "linkedServices")); - return self(); + return this; } /** * {@inheritDoc} */ @Override - public B linkedServices(String... linkedServices) { + public Builder linkedServices(String... linkedServices) { return linkedServices(ImmutableSet.copyOf(checkNotNull(linkedServices, "linkedServices"))); } @@ -124,25 +152,25 @@ public abstract class BaseProviderMetadata implements ProviderMetadata { * {@inheritDoc} */ @Override - public B linkedService(String linkedService) { + public Builder linkedService(String linkedService) { this.linkedServices.add(checkNotNull(linkedService, "linkedService")); - return self(); + return this; } /** * {@inheritDoc} */ @Override - public B iso3166Codes(Iterable iso3166Codes) { + public Builder iso3166Codes(Iterable iso3166Codes) { addAll(this.iso3166Codes, checkNotNull(iso3166Codes, "iso3166Codes")); - return self(); + return this; } /** * {@inheritDoc} */ @Override - public B iso3166Codes(String... iso3166Codes) { + public Builder iso3166Codes(String... iso3166Codes) { return iso3166Codes(ImmutableSet.copyOf(checkNotNull(iso3166Codes, "iso3166Codes"))); } @@ -150,37 +178,55 @@ public abstract class BaseProviderMetadata implements ProviderMetadata { * {@inheritDoc} */ @Override - public B iso3166Code(String iso3166Code) { + public Builder iso3166Code(String iso3166Code) { this.iso3166Codes.add(checkNotNull(iso3166Code, "iso3166Code")); - return self(); + return this; } /** * {@inheritDoc} */ @Override - public B fromProviderMetadata(ProviderMetadata in) { - return id(in.getId()).name(in.getName()).api(in.getApi()).console(in.getConsole()).homepage(in.getHomepage()) - .linkedServices(in.getLinkedServices()).iso3166Codes(in.getIso3166Codes()); + public Builder fromProviderMetadata(ProviderMetadata in) { + return id(in.getId()).name(in.getName()).apiMetadata(in.getApiMetadata()).endpoint(in.getEndpoint()) + .defaultProperties(in.getDefaultProperties()).console(in.getConsole().orNull()) + .homepage(in.getHomepage().orNull()).linkedServices(in.getLinkedServices()) + .iso3166Codes(in.getIso3166Codes()); + } + + @Override + public ProviderMetadata build() { + return new BaseProviderMetadata(this){}; } } protected final String id; protected final String name; - protected final ApiMetadata api; - protected final URI homepage; - protected final URI console; + protected final M api; + protected final String endpoint; + protected final Properties defaultProperties; + protected final Optional homepage; + protected final Optional console; protected final Set linkedServices; protected final Set iso3166Codes; - protected BaseProviderMetadata(Builder builder) { - this.id = builder.id; - this.name = builder.name; - this.api = builder.api; - this.console = builder.console; - this.homepage = builder.homepage; - this.linkedServices = ImmutableSet.copyOf(builder.linkedServices); - this.iso3166Codes = ImmutableSet.copyOf(builder.iso3166Codes); + public BaseProviderMetadata(Builder builder) { + this(builder.id, builder.name, builder.api, builder.endpoint, builder.defaultProperties, Optional + .fromNullable(builder.homepage), Optional.fromNullable(builder.console), builder.linkedServices, + builder.iso3166Codes); + } + + public BaseProviderMetadata(String id, String name, M api, String endpoint, Properties defaultProperties, + Optional homepage, Optional console, Set linkedServices, Set iso3166Codes) { + this.id = checkNotNull(id, "id"); + this.name = checkNotNull(name, "name"); + this.api = checkNotNull(api, "api"); + this.endpoint = checkNotNull(endpoint, "endpoint"); + this.console = checkNotNull(console, "console"); + this.defaultProperties = checkNotNull(defaultProperties, "defaultProperties"); + this.homepage = checkNotNull(homepage, "homepage"); + this.linkedServices = ImmutableSet.copyOf(linkedServices); + this.iso3166Codes = ImmutableSet.copyOf(iso3166Codes); } @Override @@ -191,18 +237,14 @@ public abstract class BaseProviderMetadata implements ProviderMetadata { // we'll get things from if (o == null || !(o instanceof ProviderMetadata)) return false; - ProviderMetadata that = ProviderMetadata.class.cast(o); + ProviderMetadata that = ProviderMetadata.class.cast(o); return equal(this.getId(), that.getId()) && equal(this.getName(), that.getName()) - && equal(this.getApi(), that.getApi()) && equal(this.getConsole(), that.getConsole()) - && equal(this.getHomepage(), that.getHomepage()) - && equal(this.getLinkedServices(), that.getLinkedServices()) - && equal(this.getIso3166Codes(), that.getIso3166Codes()); + && equal(this.getApiMetadata(), that.getApiMetadata()) && equal(this.getEndpoint(), that.getEndpoint()); } @Override public int hashCode() { - return Objects.hashCode(getId(), getName(), getApi(), getConsole(), getHomepage(), getLinkedServices(), - getIso3166Codes()); + return Objects.hashCode(getId(), getName(), getApiMetadata(), getEndpoint()); } @Override @@ -211,9 +253,9 @@ public abstract class BaseProviderMetadata implements ProviderMetadata { } public ToStringHelper string() { - return Objects.toStringHelper("").add("id", getId()).add("name", getName()).add("api", getApi()) - .add("console", getConsole()).add("homepage", getHomepage()).add("linkedServices", getLinkedServices()) - .add("iso3166Codes", getIso3166Codes()); + return Objects.toStringHelper("").add("id", getId()).add("name", getName()).add("api", getApiMetadata()) + .add("endpoint", getEndpoint()).add("console", getConsole()).add("homepage", getHomepage()) + .add("linkedServices", getLinkedServices()).add("iso3166Codes", getIso3166Codes()); } /** @@ -236,7 +278,7 @@ public abstract class BaseProviderMetadata implements ProviderMetadata { * {@inheritDoc} */ @Override - public ApiMetadata getApi() { + public M getApiMetadata() { return api; } @@ -244,7 +286,15 @@ public abstract class BaseProviderMetadata implements ProviderMetadata { * {@inheritDoc} */ @Override - public URI getConsole() { + public String getEndpoint() { + return endpoint; + } + + /** + * {@inheritDoc} + */ + @Override + public Optional getConsole() { return console; } @@ -252,7 +302,15 @@ public abstract class BaseProviderMetadata implements ProviderMetadata { * {@inheritDoc} */ @Override - public URI getHomepage() { + public Properties getDefaultProperties() { + return defaultProperties; + } + + /** + * {@inheritDoc} + */ + @Override + public Optional getHomepage() { return homepage; } @@ -272,35 +330,5 @@ public abstract class BaseProviderMetadata implements ProviderMetadata { return iso3166Codes; } - /** - * {@inheritDoc} - */ - @Override - public String getType() { - return getApi().getType().toString(); - } - /** - * {@inheritDoc} - */ - @Override - public String getIdentityName() { - return getApi().getIdentityName(); - } - - /** - * {@inheritDoc} - */ - @Override - public String getCredentialName() { - return getApi().getCredentialName(); - } - - /** - * {@inheritDoc} - */ - @Override - public URI getApiDocumentation() { - return getApi().getDocumentation(); - } } diff --git a/core/src/main/java/org/jclouds/rest/AnonymousProviderMetadata.java b/core/src/main/java/org/jclouds/rest/AnonymousProviderMetadata.java new file mode 100644 index 0000000000..2675f01e13 --- /dev/null +++ b/core/src/main/java/org/jclouds/rest/AnonymousProviderMetadata.java @@ -0,0 +1,79 @@ +/** + * 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.rest; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.io.Closeable; + +import org.jclouds.apis.ApiMetadata; +import org.jclouds.providers.ProviderMetadata; +import org.jclouds.providers.internal.BaseProviderMetadata; + +/** + * Useful in creating arbitrary clients. + * + * @author Adrian Cole + */ +public class AnonymousProviderMetadata> extends + BaseProviderMetadata { + + public static ProviderMetadata, AnonymousRestApiMetadata> forClientMappedToAsyncClientOnEndpoint(Class client, Class asyncClient, + String endpoint) { + return forApiWithEndpoint(AnonymousRestApiMetadata.forClientMappedToAsyncClient(client, asyncClient), endpoint); + } + + public static > ProviderMetadata forApiWithEndpoint(M md, + String endpoint) { + checkNotNull(md, "api"); + checkNotNull(endpoint, "endpoint (%s)", md.getEndpointName()); + return new AnonymousProviderMetadata(md, endpoint); + } + + @Override + public Builder toBuilder() { + return (Builder) new Builder(getApiMetadata(), getEndpoint()).fromProviderMetadata(this); + } + + public AnonymousProviderMetadata(M apiMetadata, String endpoint) { + super(new Builder(apiMetadata, endpoint)); + } + + public AnonymousProviderMetadata(Builder builder) { + super(builder); + } + + public static class Builder> extends + BaseProviderMetadata.Builder { + + public Builder(M apiMetadata, String endpoint) { + id(checkNotNull(apiMetadata, "apiMetadata").getId()) + .name(apiMetadata.getName()) + .apiMetadata(apiMetadata) + .endpoint(endpoint); + } + + @Override + public AnonymousProviderMetadata build() { + return new AnonymousProviderMetadata(this); + } + + } + +} \ No newline at end of file diff --git a/core/src/main/java/org/jclouds/rest/AnonymousRestApiMetadata.java b/core/src/main/java/org/jclouds/rest/AnonymousRestApiMetadata.java new file mode 100644 index 0000000000..1cae714604 --- /dev/null +++ b/core/src/main/java/org/jclouds/rest/AnonymousRestApiMetadata.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.rest; + +import java.net.URI; + +import org.jclouds.apis.ApiType; +import org.jclouds.rest.internal.BaseRestApiMetadata; + +import com.google.common.annotations.Beta; + +/** + * Useful in creating arbitrary clients. + * + * @author Adrian Cole + */ +@Beta +public class AnonymousRestApiMetadata extends BaseRestApiMetadata, AnonymousRestApiMetadata> { + + public static AnonymousRestApiMetadata forClientMappedToAsyncClient(Class client, Class asyncClient) { + return new AnonymousRestApiMetadata(client, asyncClient); + } + + @Override + public Builder toBuilder() { + return new Builder(getApi(), getAsyncApi()).fromApiMetadata(this); + } + + public AnonymousRestApiMetadata(Class client, Class asyncClient) { + super(new Builder(client, asyncClient)); + } + + protected AnonymousRestApiMetadata(Builder builder) { + super(builder); + } + + public static class Builder extends BaseRestApiMetadata.Builder, AnonymousRestApiMetadata> { + + public Builder(Class client, Class asyncClient) { + super(client, asyncClient); + id(client.getSimpleName()) + .type(ApiType.UNRECOGNIZED) + .name(String.format("%s->%s", client.getSimpleName(), asyncClient.getSimpleName())) + .identityName("unused") + .defaultIdentity("foo") + .version("1") + .documentation(URI.create("http://jclouds.org/documentation")); + } + + @Override + public AnonymousRestApiMetadata build() { + return new AnonymousRestApiMetadata(this); + } + + @Override + public Builder fromApiMetadata(AnonymousRestApiMetadata in) { + super.fromApiMetadata(in); + return this; + } + } + +} diff --git a/providers/cloudsigma-zrh/src/main/java/org/jclouds/cloudsigma/compute/config/CloudSigmaZurichComputeServiceContextModule.java b/core/src/main/java/org/jclouds/rest/BackedByRestContext.java similarity index 72% rename from providers/cloudsigma-zrh/src/main/java/org/jclouds/cloudsigma/compute/config/CloudSigmaZurichComputeServiceContextModule.java rename to core/src/main/java/org/jclouds/rest/BackedByRestContext.java index c9bf69c8ed..a595b334dc 100644 --- a/providers/cloudsigma-zrh/src/main/java/org/jclouds/cloudsigma/compute/config/CloudSigmaZurichComputeServiceContextModule.java +++ b/core/src/main/java/org/jclouds/rest/BackedByRestContext.java @@ -16,13 +16,22 @@ * specific language governing permissions and limitations * under the License. */ -package org.jclouds.cloudsigma.compute.config; +package org.jclouds.rest; +import com.google.common.annotations.Beta; /** + * * * @author Adrian Cole + * */ -public class CloudSigmaZurichComputeServiceContextModule extends CloudSigmaComputeServiceContextModule { - +@Beta +public interface BackedByRestContext { + /** + * + * @return a context you can use to the access provider or vendor specific + * api underlying this context. + */ + RestContext getProviderSpecificContext(); } \ No newline at end of file diff --git a/core/src/main/java/org/jclouds/rest/Providers.java b/core/src/main/java/org/jclouds/rest/Providers.java index 8ff65fff85..fe395b9374 100644 --- a/core/src/main/java/org/jclouds/rest/Providers.java +++ b/core/src/main/java/org/jclouds/rest/Providers.java @@ -18,139 +18,42 @@ */ package org.jclouds.rest; -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Predicates.notNull; -import static com.google.common.base.Throwables.propagate; -import static com.google.common.collect.Iterables.filter; -import static com.google.common.collect.Iterables.get; -import static com.google.common.collect.Iterables.transform; +import java.io.Closeable; -import java.io.IOException; -import java.lang.reflect.InvocationTargetException; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Properties; +import org.jclouds.apis.Apis; -import org.jclouds.PropertiesBuilder; -import org.jclouds.javax.annotation.Nullable; -import org.jclouds.util.ClassLoadingUtils; -import org.jclouds.util.SaxUtils; - -import com.google.common.base.Function; -import com.google.common.base.Predicate; -import com.google.common.base.Splitter; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.ImmutableSet.Builder; +import com.google.common.collect.Iterables; +import com.google.common.reflect.TypeToken; /** - * + * @see org.jclouds.providers.Providers + * @see org.jclouds.apis.Apis * @author Adrian Cole */ +@Deprecated public class Providers { /** - * Gets a set of supported providers. Idea stolen from pallets (supported-clouds). Uses - * rest.properties to populate the set. - * + * Gets a set of supported providers. Idea stolen from pallets (supported-clouds). */ public static Iterable getSupportedProviders() { - return Providers.getSupportedProvidersOfType(RestContextBuilder.class); + return getSupportedProvidersOfType(TypeToken.of(Closeable.class)); } /** - * Gets a set of supported providers. Idea stolen from pallets (supported-clouds). Uses - * rest.properties to populate the set. + * Gets a set of supported providers. Idea stolen from pallets + * (supported-clouds). * */ - public static Iterable getSupportedProvidersOfType( - @SuppressWarnings("rawtypes") Class type) { - Properties properties = new Properties(); - try { - properties.load(SaxUtils.class.getResourceAsStream("/rest.properties")); - } catch (IOException e) { - throw new RuntimeException(e); - } - return Providers.getSupportedProvidersOfTypeInProperties(type, properties); + public static Iterable getSupportedProvidersOfType(TypeToken type) { + Builder builder = ImmutableSet. builder(); + builder.addAll(Iterables.transform(Apis.contextAssignableFrom(type), Apis.idFunction())); + builder.addAll(Iterables.transform(org.jclouds.providers.Providers.contextAssignableFrom(type), + org.jclouds.providers.Providers.idFunction())); + return builder.build(); } - public static Iterable getSupportedProvidersOfTypeInProperties( - @SuppressWarnings("rawtypes") final Class type, final Properties properties) { - return filter(transform(filter(properties.entrySet(), new Predicate>() { - - @Override - public boolean apply(Entry input) { - String keyString = input.getKey().toString(); - return keyString.endsWith(".contextbuilder") || keyString.endsWith(".sync"); - } - - }), new Function, String>() { - - @Override - public String apply(Entry from) { - String keyString = from.getKey().toString(); - try { - String provider = get(Splitter.on('.').split(keyString), 0); - Class> clazz = Providers.resolveContextBuilderClass(provider, - properties); - if (clazz != null && type.isAssignableFrom(clazz)) - return provider; - } catch (ClassNotFoundException e) { - } catch (Exception e) { - propagate(e); - } - return null; - } - - }), notNull()); - } - - @SuppressWarnings("unchecked") - public static Class> resolveContextBuilderClass(String provider, - Properties properties) throws ClassNotFoundException, IllegalArgumentException, SecurityException, - InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException { - String contextBuilderClassName = properties.getProperty(provider + ".contextbuilder"); - String syncClassName = properties.getProperty(provider + ".sync"); - String asyncClassName = properties.getProperty(provider + ".async"); - if (syncClassName != null) { - checkArgument(asyncClassName != null, "please configure async class for " + syncClassName); - if(ClassLoadingUtils.loadClass(Providers.class, syncClassName) == null) { - throw new ClassNotFoundException(); - } - if(ClassLoadingUtils.loadClass(Providers.class, asyncClassName) == null) { - throw new ClassNotFoundException(); - } - return (Class>) (contextBuilderClassName != null ? ClassLoadingUtils. - loadClass(Providers.class, contextBuilderClassName) : RestContextBuilder.class); - } else { - checkArgument(contextBuilderClassName != null, "please configure contextbuilder class for " + provider); - return (Class>) ClassLoadingUtils. - loadClass(Providers.class, contextBuilderClassName); - } - } - - public static RestContextBuilder initContextBuilder( - Class> contextBuilderClass, @Nullable Class sync, @Nullable Class async, - Properties properties) throws ClassNotFoundException, IllegalArgumentException, SecurityException, - InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException { - checkArgument(properties != null, "please configure properties for " + contextBuilderClass); - try { - return (RestContextBuilder) contextBuilderClass.getConstructor(Properties.class).newInstance(properties); - } catch (NoSuchMethodException e) { - checkArgument(sync != null, "please configure sync class for " + contextBuilderClass); - checkArgument(async != null, "please configure async class for " + contextBuilderClass); - return (RestContextBuilder) contextBuilderClass.getConstructor(sync.getClass(), async.getClass(), - Properties.class).newInstance(sync, async, properties); - } - } - - @SuppressWarnings("unchecked") - public static Class resolvePropertiesBuilderClass(String providerName, Properties props) - throws ClassNotFoundException, InstantiationException, IllegalAccessException, InvocationTargetException, - NoSuchMethodException { - String propertiesBuilderClassName = props.getProperty(providerName + ".propertiesbuilder", null); - if (propertiesBuilderClassName != null) { - return (Class) ClassLoadingUtils.loadClass(Providers.class, propertiesBuilderClassName); - } else { - return PropertiesBuilder.class; - } - } } diff --git a/providers/cloudonestorage/src/test/java/org/jclouds/cloudonestorage/blobstore/integration/CloudOneStorageTestInitializer.java b/core/src/main/java/org/jclouds/rest/RestApiMetadata.java similarity index 65% rename from providers/cloudonestorage/src/test/java/org/jclouds/cloudonestorage/blobstore/integration/CloudOneStorageTestInitializer.java rename to core/src/main/java/org/jclouds/rest/RestApiMetadata.java index 3f18e16a65..84bd50d2f0 100644 --- a/providers/cloudonestorage/src/test/java/org/jclouds/cloudonestorage/blobstore/integration/CloudOneStorageTestInitializer.java +++ b/core/src/main/java/org/jclouds/rest/RestApiMetadata.java @@ -16,20 +16,23 @@ * specific language governing permissions and limitations * under the License. */ -package org.jclouds.cloudonestorage.blobstore.integration; +package org.jclouds.rest; -import org.jclouds.atmos.blobstore.integration.AtmosTestInitializer; +import org.jclouds.apis.ApiMetadata; +import com.google.common.annotations.Beta; /** * * @author Adrian Cole + * @since 1.5 */ -public class CloudOneStorageTestInitializer extends AtmosTestInitializer { +@Beta +public interface RestApiMetadata, M extends RestApiMetadata> extends + ApiMetadata { - public CloudOneStorageTestInitializer() { - provider = "cloudonestorage"; + public static interface Builder, M extends RestApiMetadata> extends + ApiMetadata.Builder { } - -} +} \ No newline at end of file diff --git a/core/src/main/java/org/jclouds/rest/RestContext.java b/core/src/main/java/org/jclouds/rest/RestContext.java index c03665d798..f564ace886 100644 --- a/core/src/main/java/org/jclouds/rest/RestContext.java +++ b/core/src/main/java/org/jclouds/rest/RestContext.java @@ -18,6 +18,7 @@ */ package org.jclouds.rest; +import java.io.Closeable; import java.net.URI; import java.util.Map; import java.util.concurrent.Future; @@ -41,7 +42,7 @@ import com.google.inject.ImplementedBy; * */ @ImplementedBy(RestContextImpl.class) -public interface RestContext extends Location { +public interface RestContext extends Location, Closeable { /** * low-level api to the cloud. Threadsafe implementations will return a singleton. @@ -96,6 +97,7 @@ public interface RestContext extends Location { /** * Closes all connections to Cloud Files. */ + @Override void close(); } \ No newline at end of file diff --git a/core/src/main/java/org/jclouds/rest/RestContextBuilder.java b/core/src/main/java/org/jclouds/rest/RestContextBuilder.java index 86f5c4f763..7d5475b244 100644 --- a/core/src/main/java/org/jclouds/rest/RestContextBuilder.java +++ b/core/src/main/java/org/jclouds/rest/RestContextBuilder.java @@ -1,277 +1,40 @@ -/** - * 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.rest; +import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.base.Predicates.instanceOf; -import static com.google.common.collect.Iterables.addAll; -import static com.google.common.collect.Iterables.any; -import static com.google.inject.Scopes.SINGLETON; -import static com.google.inject.util.Types.newParameterizedType; +import java.util.NoSuchElementException; -import java.util.ArrayList; -import java.util.List; -import java.util.Properties; - -import javax.inject.Inject; - -import org.jclouds.concurrent.MoreExecutors; -import org.jclouds.concurrent.SingleThreaded; -import org.jclouds.concurrent.config.ConfiguresExecutorService; -import org.jclouds.concurrent.config.ExecutorServiceModule; -import org.jclouds.events.config.ConfiguresEventBus; -import org.jclouds.events.config.EventBusModule; -import org.jclouds.http.RequiresHttp; -import org.jclouds.http.config.ConfiguresHttpCommandExecutorService; -import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule; -import org.jclouds.lifecycle.config.LifeCycleModule; -import org.jclouds.logging.config.LoggingModule; -import org.jclouds.logging.jdk.config.JDKLoggingModule; -import org.jclouds.rest.config.BindPropertiesToAnnotations; -import org.jclouds.rest.config.CredentialStoreModule; -import org.jclouds.rest.config.RestClientModule; -import org.jclouds.rest.config.RestModule; -import org.jclouds.rest.internal.RestContextImpl; -import org.nnsoft.guice.rocoto.Rocoto; -import org.nnsoft.guice.rocoto.configuration.ConfigurationModule; - -import com.google.common.annotations.VisibleForTesting; -import com.google.common.base.Predicate; -import com.google.common.util.concurrent.ExecutionList; -import com.google.inject.AbstractModule; -import com.google.inject.Guice; -import com.google.inject.Injector; -import com.google.inject.Key; -import com.google.inject.Module; -import com.google.inject.Stage; -import com.google.inject.TypeLiteral; +import org.jclouds.providers.ProviderMetadata; +import org.jclouds.rest.internal.ContextBuilder; /** - * Creates {@link RestContext} or {@link Injector} instances based on the most commonly requested - * arguments. - *

- * Note that Threadsafe objects will be bound as singletons to the Injector or Context provided. - *

- *

- * If no Modules are specified, the default {@link JDKLoggingModule logging} and - * {@link JavaUrlHttpCommandExecutorServiceModule http transports} will be installed. - * - * @author Adrian Cole, Andrew Newdigate - * @see RestContext + * @author Adrian Cole */ -public class RestContextBuilder { - protected Properties properties; - protected List modules = new ArrayList(3); - protected Class asyncClientType; - protected Class syncClientType; - - @Inject - public RestContextBuilder(Class syncClientClass, Class asyncClientClass, Properties properties) { - this.asyncClientType = checkNotNull(asyncClientClass, "asyncClientType"); - this.syncClientType = checkNotNull(syncClientClass, "syncClientType"); - this.properties = checkNotNull(properties, "properties"); - } - - public RestContextBuilder withModules(Iterable modules) { - addAll(this.modules, modules); - return this; - } - - public Injector buildInjector() { - modules.add(Rocoto.expandVariables(new ConfigurationModule(){ - - @Override - protected void bindConfigurations() { - Properties toBind = new Properties(); - toBind.putAll(checkNotNull(properties, "properties")); - toBind.putAll(System.getProperties()); - bindProperties(toBind); - } - - })); - addContextModule(modules); - addClientModuleIfNotPresent(modules); - addLoggingModuleIfNotPresent(modules); - addHttpModuleIfNeededAndNotPresent(modules); - ifHttpConfigureRestOtherwiseGuiceClientFactory(modules); - addExecutorServiceIfNotPresent(modules); - addEventBusIfNotPresent(modules); - addCredentialStoreIfNotPresent(modules); - modules.add(new LifeCycleModule()); - modules.add(new BindPropertiesToAnnotations()); - Injector returnVal = Guice.createInjector(Stage.PRODUCTION, modules); - returnVal.getInstance(ExecutionList.class).execute(); - return returnVal; - } - - @VisibleForTesting - protected void addLoggingModuleIfNotPresent(List modules) { - if (!any(modules, instanceOf(LoggingModule.class))) - modules.add(new JDKLoggingModule()); - } - - @VisibleForTesting - protected void addHttpModuleIfNeededAndNotPresent(List modules) { - if (defaultOrAtLeastOneModuleRequiresHttp(modules) && nothingConfiguresAnHttpService(modules)) - modules.add(new JavaUrlHttpCommandExecutorServiceModule()); - } - - private boolean nothingConfiguresAnHttpService(List modules) { - return (!any(modules, new Predicate() { - public boolean apply(Module input) { - return input.getClass().isAnnotationPresent(ConfiguresHttpCommandExecutorService.class); - } - - })); - } - - @VisibleForTesting - protected void addContextModuleIfNotPresent(List modules) { - if (!any(modules, new Predicate() { - public boolean apply(Module input) { - return input.getClass().isAnnotationPresent(ConfiguresRestContext.class); - } - - })) { - addContextModule(modules); - } - } - - @VisibleForTesting - protected void addContextModule(List modules) { - modules.add(new AbstractModule() { - - @SuppressWarnings( { "unchecked", "rawtypes" }) - @Override - protected void configure() { - bind( - (TypeLiteral) TypeLiteral.get(newParameterizedType(RestContext.class, syncClientType, - asyncClientType))).to( - TypeLiteral.get(newParameterizedType(RestContextImpl.class, syncClientType, asyncClientType))).in( - SINGLETON); - - } - - public String toString() { - return String.format("configure rest context %s->%s", syncClientType.getSimpleName(), asyncClientType - .getSimpleName()); - } - - }); - } - - @VisibleForTesting - protected void ifHttpConfigureRestOtherwiseGuiceClientFactory(List modules) { - if (defaultOrAtLeastOneModuleRequiresHttp(modules)) { - modules.add(new RestModule()); - } - } - - private boolean defaultOrAtLeastOneModuleRequiresHttp(List modules) { - return atLeastOneModuleRequiresHttp(modules) || !restClientModulePresent(modules); - } - - private boolean atLeastOneModuleRequiresHttp(List modules) { - return any(modules, new Predicate() { - public boolean apply(Module input) { - return input.getClass().isAnnotationPresent(RequiresHttp.class); - } - }); - } - - @VisibleForTesting - protected void addClientModuleIfNotPresent(List modules) { - if (!restClientModulePresent(modules)) { - addClientModule(modules); - } - } - - private boolean restClientModulePresent(List modules) { - return any(modules, new Predicate() { - public boolean apply(Module input) { - return input.getClass().isAnnotationPresent(ConfiguresRestClient.class); - } - - }); - } - - protected void addClientModule(List modules) { - modules.add(new RestClientModule(syncClientType, asyncClientType)); - } +public class RestContextBuilder, M extends RestApiMetadata> + extends ContextBuilder { - @VisibleForTesting - protected void addEventBusIfNotPresent(List modules) { - if (!any(modules, new Predicate() { - public boolean apply(Module input) { - return input.getClass().isAnnotationPresent(ConfiguresEventBus.class); - } - } - - )) { - modules.add(new EventBusModule()); - } + /** + * looks up a provider or api with the given id + * + * @param providerOrApi + * id of the provider or api + * @return means to build a context to that provider + * @throws NoSuchElementException + * if the id was not configured. + * @throws IllegalArgumentException + * if the api or provider isn't assignable from RestContext + */ + public static RestContextBuilder newBuilder(String providerOrApi) throws NoSuchElementException { + ContextBuilder builder = ContextBuilder.newBuilder(providerOrApi); + checkArgument(builder instanceof RestContextBuilder, + "type of providerOrApi[%s] is not RestContextBuilder: %s", providerOrApi, builder); + return RestContextBuilder.class.cast(builder); } - @VisibleForTesting - protected void addExecutorServiceIfNotPresent(List modules) { - if (!any(modules, new Predicate() { - public boolean apply(Module input) { - return input.getClass().isAnnotationPresent(ConfiguresExecutorService.class); - } - } - - )) { - if (any(modules, new Predicate() { - public boolean apply(Module input) { - return input.getClass().isAnnotationPresent(SingleThreaded.class); - } - })) { - modules.add(new ExecutorServiceModule(MoreExecutors.sameThreadExecutor(), MoreExecutors - .sameThreadExecutor())); - } else { - modules.add(new ExecutorServiceModule()); - } - } + public RestContextBuilder(ProviderMetadata providerMetadata) { + super(providerMetadata); } - @VisibleForTesting - protected void addCredentialStoreIfNotPresent(List modules) { - if (!any(modules, new Predicate() { - public boolean apply(Module input) { - return input.getClass().isAnnotationPresent(ConfiguresCredentialStore.class); - } - } - - )) { - modules.add(new CredentialStoreModule()); - } + public RestContextBuilder(M apiMetadata) { + super(apiMetadata); } - - @VisibleForTesting - protected Properties getProperties() { - return properties; - } - - @SuppressWarnings("unchecked") - public > T buildContext() { - Injector injector = buildInjector(); - return (T) injector - .getInstance(Key.get(newParameterizedType(RestContext.class, syncClientType, asyncClientType))); - } -} +} \ No newline at end of file diff --git a/core/src/main/java/org/jclouds/rest/RestContextFactory.java b/core/src/main/java/org/jclouds/rest/RestContextFactory.java index 4aacd74a28..fbdf38ee09 100644 --- a/core/src/main/java/org/jclouds/rest/RestContextFactory.java +++ b/core/src/main/java/org/jclouds/rest/RestContextFactory.java @@ -18,465 +18,115 @@ */ package org.jclouds.rest; -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.base.Throwables.propagate; -import static com.google.common.collect.Iterables.concat; -import static com.google.common.collect.Iterables.size; -import static com.google.common.collect.Iterables.transform; -import static java.util.Collections.EMPTY_LIST; -import static org.jclouds.util.Throwables2.propagateAuthorizationOrOriginalException; - -import java.io.File; -import java.io.IOException; +import java.util.NoSuchElementException; import java.util.Properties; -import javax.inject.Inject; - -import org.jclouds.PropertiesBuilder; +import org.jclouds.apis.Apis; import org.jclouds.javax.annotation.Nullable; -import org.jclouds.location.reference.LocationConstants; -import org.jclouds.util.ClassLoadingUtils; -import org.jclouds.util.Modules2; -import org.jclouds.util.Strings2; +import org.jclouds.providers.ProviderMetadata; +import org.jclouds.providers.Providers; +import org.jclouds.rest.internal.ContextBuilder; -import com.google.common.base.Charsets; -import com.google.common.base.Function; -import com.google.common.base.Joiner; -import com.google.common.base.Splitter; import com.google.common.collect.ImmutableSet; -import com.google.common.io.Files; import com.google.inject.Module; /** - * Helper class to instantiate {@code RestContext} instances. "blobstore.properties" - * - * At least one property is needed needed per context: - *

- * - * Optional properties are as follows - *
    - *
  • tag.contextbuilder=classname extends RestContextBuilder
  • - *
  • tag.propertiesbuilder=classname extends HttpPropertiesBuilder
  • - *
- * Ex. - * - *
- * azureblob.contextbuilder=org.jclouds.azure.storage.blob.blobstore.AzureRestContextBuilder
- * azureblob.propertiesbuilder=org.jclouds.azure.storage.blob.AzureBlobPropertiesBuilder
- * 
* + * @see ContextBuilder * @author Adrian Cole */ +@Deprecated public class RestContextFactory { - public static RestContextSpec contextSpec(String provider, String endpoint, String apiVersion, - String buildVersion, String iso3166Codes, String identity, String credential, Class sync, Class
async, - Class propertiesBuilderClass, Class> contextBuilderClass, - Iterable modules) { - return new RestContextSpec(provider, endpoint, apiVersion, buildVersion, iso3166Codes, identity, - credential, sync, async, propertiesBuilderClass, contextBuilderClass, modules); - } - - public static RestContextSpec contextSpec(String provider, String endpoint, String apiVersion,String buildVersion, - String iso3166Codes, String identity, String credential, Class sync, Class async) { - return new RestContextSpec(provider, endpoint, apiVersion, buildVersion, iso3166Codes, identity, credential, sync, async); - } - - @SuppressWarnings( { "unchecked", "rawtypes" }) - public static RestContextSpec contextSpec(String provider, String endpoint, String apiVersion, - String buildVersion, String iso3166Codes, String identity, String credential, Class sync, - Class async, Iterable modules) { - return new RestContextSpec(provider, endpoint, apiVersion, buildVersion, iso3166Codes, identity, - credential, sync, async, PropertiesBuilder.class, (Class) RestContextBuilder.class, modules); - } - - private final static Properties NO_PROPERTIES = new Properties(); - private final Properties properties; - /** - * Initializes with the default properties built-in to jclouds. This is typically stored in the - * classpath resource {@code rest.properties} - * - * @see RestContextFactory#getPropertiesFromResource + * for porting old code to {@link ContextBuilder} */ public RestContextFactory() { - this("/rest.properties"); } /** - * Initializes with the default properties built-in to jclouds. This is typically stored in the - * classpath resource {@code filename} - * - * @param filename - * name of the properties file to initialize from - * @throws IOException - * if the default properties file cannot be loaded - * @see #getPropertiesFromResource + * for porting old code to {@link ContextBuilder} */ - public RestContextFactory(String filename) { - this(getPropertiesFromResource(filename)); - } - - /** - * Loads the default properties that define the {@code RestContext} objects.

properties file - * format

- * - * Two properties are needed per context: - *
    - *
  • tag.contextbuilder=classname extends RestContextBuilder
  • - *
  • tag.propertiesbuilder=classname extends HttpPropertiesBuilder
  • - *
- * Ex. - * - *
-    * azureblob.contextbuilder=org.jclouds.azure.storage.blob.blobstore.AzureRestContextBuilder
-    * azureblob.propertiesbuilder=org.jclouds.azure.storage.blob.AzureBlobPropertiesBuilder
-    * 
- * - * @param filename - * name of file to load from in the resource path - * @return properties object with these items loaded for each tag - */ - public static Properties getPropertiesFromResource(String filename) { - Properties properties = new Properties(); - try { - properties.load(RestContextFactory.class.getResourceAsStream(filename)); - } catch (IOException e) { - propagate(e); - } - properties.putAll(System.getProperties()); - return properties; - } - - /** - * Initializes the {@code RestContext} definitions from the specified properties. - */ - @Inject public RestContextFactory(Properties properties) { - this.properties = properties; - } - - public RestContextBuilder createContextBuilder(String provider, String identity, String credential) { - return createContextBuilder(provider, identity, credential, ImmutableSet. of(), NO_PROPERTIES); } /** - * @see RestContextFactory#createContextBuilder(String, Properties, Iterable, - * Properties) + * @see #createContext(String, String,String, Iterable, Properties) */ - public RestContextBuilder createContextBuilder(String provider, Properties overrides) { - return createContextBuilder(provider, null, null, ImmutableSet. of(), overrides); + public RestContext createContext(String providerOrApi, String identity, String credential) { + return createContext(providerOrApi, identity, credential, ImmutableSet. of(), new Properties()); } /** - * @see RestContextFactory#createContextBuilder(String, Properties, Iterable, - * Properties) + * @see #createContext(String, String, String, Iterable, Properties) */ - public RestContextBuilder createContextBuilder(String provider, Iterable modules) { - return createContextBuilder(provider, null, null, modules, NO_PROPERTIES); + public RestContext createContext(String providerOrApi, Properties overrides) { + return createContext(providerOrApi, null, null, ImmutableSet. of(), overrides); } /** - * - * Identity will be found by searching {@code jclouds.identity} failing that - * {@code provider.identity} where provider corresponds to the parameter. Same pattern is used - * for credential ({@code jclouds.credential} failing that {@code provider.credential}). - * - * @param - * Type of the provider specific client - * @param
- * Type of the provide specific async client (same as above, yet all methods return - * {@code Future} results) - * @param provider - * name of the provider (ex. s3, bluelock, etc.) - * @param wiring - * defines how objects are bound to interfaces, pass in here to override this, or - * specify service implementations. - * @param overrides - * properties to pass to the context. + * @see #createContext(String, String,String, Iterable, Properties) */ - public RestContextBuilder createContextBuilder(String provider, Iterable wiring, + public RestContext createContext(String providerOrApi, Iterable wiring, Properties overrides) { - return createContextBuilder(provider, null, null, wiring, overrides); - } - - @SuppressWarnings("unchecked") - public RestContextBuilder createContextBuilder(String provider, @Nullable String identity, - @Nullable String credential, Properties properties) { - return createContextBuilder(provider, identity, credential, EMPTY_LIST, properties); - } - - public RestContextBuilder createContextBuilder(String provider, @Nullable String identity, - @Nullable String credential, Iterable wiring) { - return createContextBuilder(provider, identity, credential, wiring, NO_PROPERTIES); + return createContext(providerOrApi, null, null, wiring, overrides); } /** - * Creates a new remote context. + * @see #createContext(String, String,String, Iterable, Properties) + */ + public RestContext createContext(String providerOrApi, @Nullable String identity, + @Nullable String credential, Properties overrides) { + return createContext(providerOrApi, identity, credential, ImmutableSet. of(), overrides); + } + + /** + * @see createContext(String, String,String, Iterable, Properties) + */ + public RestContext createContext(String providerOrApi, @Nullable String identity, + @Nullable String credential, Iterable wiring) { + return createContext(providerOrApi, identity, credential, wiring, new Properties()); + } + + /** + * for porting old code to {@link ContextBuilder} * - * @param provider + * @param providerOrApi * @param identity * nullable, if credentials are present in the overrides * @param credential * nullable, if credentials are present in the overrides * @param wiring - * Configuration you'd like to pass to the context. Ex. ImmutableSet.of(new - * ExecutorServiceModule(myexecutor)) + * Configuration you'd like to pass to the context. Ex. + * ImmutableSet.of(new ExecutorServiceModule(myexecutor)) * @param overrides * properties to override defaults with. * @return initialized context ready for use */ - public RestContextBuilder createContextBuilder(String providerName, @Nullable String identity, - @Nullable String credential, Iterable wiring, Properties _overrides) { - checkNotNull(wiring, "wiring"); - RestContextSpec contextSpec = createContextSpec(providerName, identity, credential, wiring, _overrides); - return createContextBuilder(contextSpec, _overrides); - } - - public static Properties toProperties(RestContextSpec contextSpec) { - checkNotNull(contextSpec, "contextSpec"); - - Properties props = new Properties(); - - props.setProperty(contextSpec.provider + ".endpoint", contextSpec.endpoint); - props.setProperty(contextSpec.provider + ".api-version", contextSpec.apiVersion); - props.setProperty(contextSpec.provider + ".build-version", contextSpec.buildVersion); - props.setProperty(contextSpec.provider + "." + LocationConstants.ISO3166_CODES, contextSpec.iso3166Codes); - props.setProperty(contextSpec.provider + ".identity", contextSpec.identity); - if (contextSpec.credential != null) - props.setProperty(contextSpec.provider + ".credential", contextSpec.credential); - if (contextSpec.sync != null) { - props.setProperty(contextSpec.provider + ".sync", contextSpec.sync.getName()); - props.setProperty(contextSpec.provider + ".async", checkNotNull(contextSpec.async, "contextSpec.async") - .getName()); - } else { - props.setProperty(contextSpec.provider + ".contextbuilder", - checkNotNull(contextSpec.contextBuilderClass, "contextSpec.contextBuilderClass").getName()); - - props.setProperty(contextSpec.provider + ".propertiesbuilder", - checkNotNull(contextSpec.propertiesBuilderClass, "contextSpec.propertiesBuilderClass").getName()); - } - if (size(contextSpec.modules) > 0) { - props.setProperty(contextSpec.provider + ".modules", - Joiner.on(',').join(transform(contextSpec.modules, new Function() { - - @Override - public String apply(Module from) { - return from.getClass().getName(); - } - - }))); - } - return props; - } - @SuppressWarnings("unchecked") - public RestContextSpec createContextSpec(String providerName, String identity, String credential, - Properties _overrides) { - return createContextSpec(providerName, identity, credential, EMPTY_LIST, _overrides); - } - - @SuppressWarnings("unchecked") - public RestContextSpec createContextSpec(String providerName, String identity, String credential, - Iterable wiring, Properties _overrides) { - checkNotNull(providerName, "providerName"); - checkNotNull(_overrides, "overrides"); - - Properties props = new Properties(); - props.putAll(this.properties); - props.putAll(_overrides); - - String endpoint = props.getProperty(providerName + "." + LocationConstants.ENDPOINT, null); - String iso3166Codes = props.getProperty(providerName + "." + LocationConstants.ISO3166_CODES, null); - String apiVersion = props.getProperty(providerName + ".api-version", null); - String buildVersion = props.getProperty(providerName + ".build-version", null); - identity = props.getProperty(providerName + ".identity", props.getProperty("jclouds.identity", identity)); - credential = loadCredentialOrDefault(props, providerName + ".credential", - loadCredentialOrDefault(props, "jclouds.credential", credential)); - String syncClassName = props.getProperty(providerName + ".sync", null); - String asyncClassName = props.getProperty(providerName + ".async", null); - Iterable modules = concat(Modules2.modulesForProviderInProperties(providerName, props), wiring); - - Class> contextBuilderClass; - Class propertiesBuilderClass; - Class sync; - Class async; - try { - contextBuilderClass = Providers.resolveContextBuilderClass(providerName, props); - propertiesBuilderClass = Providers.resolvePropertiesBuilderClass(providerName, props); - sync = (Class) (syncClassName != null ? ClassLoadingUtils.loadClass(getClass(), syncClassName) : null); - async = (Class) (asyncClassName != null ? ClassLoadingUtils.loadClass(getClass(), asyncClassName) : null); - } catch (IllegalArgumentException e) { - throw new IllegalArgumentException( - String.format( - "The specified provider \"%s\" is either not configured or supported. Currently configured providers are:%n %s%nCheck this list, as the provider name may have changed. If you are sure that provider name is correct, check that your project has a dependency on org.jclouds.provider/%s, or on org.jclouds/jclouds-all.", - providerName, Providers.getSupportedProviders(), providerName), e); - } catch (Exception e) { - propagate(e); - assert false : "exception should have propogated " + e; - return null; - } - RestContextSpec contextSpec = new RestContextSpec(providerName, endpoint, apiVersion, buildVersion, iso3166Codes, - identity, credential, sync, async, propertiesBuilderClass, contextBuilderClass, modules); - return contextSpec; - } - - static String loadCredentialOrDefault(Properties properties, String property, String credential) { - if (properties.containsKey(property)) - return properties.getProperty(property); - else if (properties.containsKey(property + ".resource")) - try { - return Strings2.toStringAndClose(RestContextFactory.class.getResourceAsStream(properties - .getProperty(property + ".resource"))); - } catch (IOException e) { - throw new RuntimeException("error reading resource: " + properties.getProperty(property + ".resource")); - } - else if (properties.containsKey(property + ".file")) - try { - return Files.toString(new File(properties.getProperty(property + ".file")), Charsets.UTF_8); - } catch (IOException e) { - throw new RuntimeException("error reading file: " + properties.getProperty(property + ".file")); - } - else - return credential; - } - - public static RestContextBuilder createContextBuilder(RestContextSpec contextSpec) { - return createContextBuilder(contextSpec, NO_PROPERTIES); - } - - @SuppressWarnings("unchecked") - public static RestContextBuilder createContextBuilder(RestContextSpec contextSpec, - Properties overrides) { - return createContextBuilder(contextSpec, EMPTY_LIST, overrides); - } - - public static RestContextBuilder createContextBuilder(RestContextSpec contextSpec, - Iterable modules) { - return createContextBuilder(contextSpec, modules, NO_PROPERTIES); - } - - public static RestContextBuilder createContextBuilder(RestContextSpec contextSpec, - Iterable modules, Properties overrides) { - try { - PropertiesBuilder builder = contextSpec.propertiesBuilderClass.getConstructor(Properties.class).newInstance( - overrides); - - builder.provider(contextSpec.provider); - if (contextSpec.apiVersion != null) - builder.apiVersion(contextSpec.apiVersion); - if (contextSpec.buildVersion != null) - builder.buildVersion(contextSpec.buildVersion); - if (contextSpec.iso3166Codes != null) - builder.iso3166Codes(Splitter.on('.').split(contextSpec.iso3166Codes)); - if (contextSpec.identity != null) - builder.credentials(contextSpec.identity, contextSpec.credential); - if (contextSpec.endpoint != null) - builder.endpoint(contextSpec.endpoint); - - RestContextBuilder contextBuilder = Providers.initContextBuilder(contextSpec.contextBuilderClass, - contextSpec.sync, contextSpec.async, builder.build()); - - contextBuilder.withModules(concat(modules, contextSpec.modules)); - - return contextBuilder; - } catch (Exception e) { - return propagateAuthorizationOrOriginalException(e); - } - } - - /** - * @see RestContextFactory#createContextBuilder(String, String, String) - */ - public RestContext createContext(String provider, String identity, String credential) { - RestContextBuilder builder = createContextBuilder(provider, identity, credential); - return buildContextUnwrappingExceptions(builder); - } - - public static RestContext buildContextUnwrappingExceptions(RestContextBuilder builder) { - try { - return builder.buildContext(); - } catch (Exception e) { - return propagateAuthorizationOrOriginalException(e); - } - } - - /** - * @see RestContextFactory#createContextBuilder(String, Properties) - */ - public RestContext createContext(String provider, Properties overrides) { - RestContextBuilder builder = createContextBuilder(provider, overrides); - return buildContextUnwrappingExceptions(builder); - } - - /** - * @see RestContextFactory#createContextBuilder(String, Iterable) - */ - public RestContext createContext(String provider, Iterable wiring, - Properties overrides) { - RestContextBuilder builder = createContextBuilder(provider, wiring, overrides); - return buildContextUnwrappingExceptions(builder); - } - - /** - * @see RestContextFactory#createContextBuilder(String, String,String, Properties) - */ - public RestContext createContext(String provider, @Nullable String identity, - @Nullable String credential, Properties properties) { - RestContextBuilder builder = createContextBuilder(provider, identity, credential, properties); - return buildContextUnwrappingExceptions(builder); - } - - /** - * @see RestContextFactory#createContextBuilder(String, String,String, Iterable) - */ - public RestContext createContext(String provider, @Nullable String identity, - @Nullable String credential, Iterable wiring) { - RestContextBuilder builder = createContextBuilder(provider, identity, credential, wiring); - return buildContextUnwrappingExceptions(builder); - } - - /** - * @see RestContextFactory#createContextBuilder(String, String,String, Iterable, Properties) - */ - public RestContext createContext(String provider, @Nullable String identity, + public RestContext createContext(String providerOrApi, @Nullable String identity, @Nullable String credential, Iterable wiring, Properties overrides) { - RestContextBuilder builder = createContextBuilder(provider, identity, credential, wiring, overrides); - return buildContextUnwrappingExceptions(builder); + ContextBuilder builder = null; + try { + ProviderMetadata pm = Providers.withId(providerOrApi); + builder = ContextBuilder.newBuilder(pm); + } catch (NoSuchElementException e) { + builder = ContextBuilder.newBuilder(Apis.withId(providerOrApi)); + } + builder.modules(Iterable.class.cast(wiring)); + builder.overrides(overrides); + if (identity != null) + builder.credentials(identity, credential); + Object context = builder.build(); + if (context instanceof RestContext) { + return RestContext.class.cast(context); + } else if (context instanceof BackedByRestContext) { + return BackedByRestContext.class.cast(context).getProviderSpecificContext(); + } else { + throw new IllegalArgumentException("provider " + providerOrApi + " contains an unknown context type: " + + context.getClass().getSimpleName()); + } + } - /** - * @see RestContextFactory#createContextBuilder(RestContextSpec) - */ - public static RestContext createContext(RestContextSpec contextSpec) { - RestContextBuilder builder = createContextBuilder(contextSpec); - return buildContextUnwrappingExceptions(builder); - } - - /** - * @see RestContextFactory#createContextBuilder(RestContextSpec, Properties) - */ - public static RestContext createContext(RestContextSpec contextSpec, Properties overrides) { - RestContextBuilder builder = createContextBuilder(contextSpec, overrides); - return buildContextUnwrappingExceptions(builder); - } - - /** - * @see RestContextFactory#createContextBuilder(RestContextSpec, Iterable) - */ - public static RestContext createContext(RestContextSpec contextSpec, Iterable modules) { - RestContextBuilder builder = createContextBuilder(contextSpec, modules); - return buildContextUnwrappingExceptions(builder); - } - - /** - * @see RestContextFactory#createContextBuilder(RestContextSpec, Iterable, Properties) - */ - public static RestContext createContext(RestContextSpec contextSpec, Iterable modules, - Properties overrides) { - RestContextBuilder builder = createContextBuilder(contextSpec, modules, overrides); - return buildContextUnwrappingExceptions(builder); - } } diff --git a/core/src/main/java/org/jclouds/rest/RestContextSpec.java b/core/src/main/java/org/jclouds/rest/RestContextSpec.java deleted file mode 100644 index 9cbea956e0..0000000000 --- a/core/src/main/java/org/jclouds/rest/RestContextSpec.java +++ /dev/null @@ -1,99 +0,0 @@ -/** - * 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.rest; - -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; -import static java.util.Collections.EMPTY_LIST; - -import org.jclouds.PropertiesBuilder; - -import com.google.common.base.Objects; -import com.google.common.collect.ImmutableList; -import com.google.inject.Module; - -/** - * @author Adrian Cole - */ -public class RestContextSpec { - protected final String provider; - protected final String endpoint; - protected final String apiVersion; - protected final String buildVersion; - protected final String iso3166Codes; - protected final String identity; - protected final String credential; - protected final Class sync; - protected final Class async; - protected final Class propertiesBuilderClass; - protected final Class> contextBuilderClass; - protected final Iterable modules; - - public RestContextSpec(String provider, String endpoint, String apiVersion, String buildVersion, String iso3166Codes, String identity, - String credential, Class sync, Class async, Class propertiesBuilderClass, - Class> contextBuilderClass, Iterable modules) { - this.provider = checkNotNull(provider, "provider"); - this.endpoint = endpoint; - this.apiVersion = apiVersion; - this.buildVersion = buildVersion; - this.identity = identity; - this.credential = credential; - this.iso3166Codes = iso3166Codes; - this.sync = sync; - this.async = async; - checkArgument(RestContextBuilder.class.isAssignableFrom(contextBuilderClass), contextBuilderClass.getName() - + " is not a subclass of " + RestContextBuilder.class.getName()); - checkArgument(PropertiesBuilder.class.isAssignableFrom(propertiesBuilderClass), propertiesBuilderClass.getName() - + " is not a subclass of " + PropertiesBuilder.class.getName()); - this.propertiesBuilderClass = propertiesBuilderClass; - this.contextBuilderClass = contextBuilderClass; - this.modules = ImmutableList.copyOf(modules); - } - - @SuppressWarnings( { "unchecked", "rawtypes" }) - public RestContextSpec(String provider, String endpoint, String apiVersion, String buildVersion, String iso3166Codes, String identity, - String credential, Class sync, Class async) { - this(provider, endpoint, apiVersion, buildVersion, iso3166Codes, identity, credential, sync, async, PropertiesBuilder.class, - (Class) RestContextBuilder.class, EMPTY_LIST); - } - - - @Override - public int hashCode() { - return Objects.hashCode(provider, endpoint, apiVersion, buildVersion, iso3166Codes, identity, credential, sync, async, - propertiesBuilderClass, contextBuilderClass, modules); - } - - @Override - public boolean equals(Object that) { - if (that == null) - return false; - return Objects.equal(this.toString(), that.toString()); - } - - @Override - public String toString() { - return Objects.toStringHelper(this).add("provider", provider).add("endpoint", endpoint).add("apiVersion", - apiVersion).add("buildVersion", buildVersion).add("iso3166Codes", iso3166Codes) - .add("identity", identity).add("sync", sync).add("async", async).add("propertiesBuilderClass", - propertiesBuilderClass).add("contextBuilderClass", contextBuilderClass).add("modules", modules) - .toString(); - } - -} \ No newline at end of file diff --git a/core/src/main/java/org/jclouds/rest/internal/BaseRestApiMetadata.java b/core/src/main/java/org/jclouds/rest/internal/BaseRestApiMetadata.java new file mode 100644 index 0000000000..bc0e52fef1 --- /dev/null +++ b/core/src/main/java/org/jclouds/rest/internal/BaseRestApiMetadata.java @@ -0,0 +1,74 @@ +/** + * 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.rest.internal; + +import static com.google.common.base.Preconditions.checkNotNull; + +import org.jclouds.apis.internal.BaseApiMetadata; +import org.jclouds.rest.RestApiMetadata; +import org.jclouds.rest.RestContext; + +import com.google.common.annotations.Beta; + +/** + * Useful in creating rest clients. + * + * @author Adrian Cole + */ +@Beta +public class BaseRestApiMetadata, M extends RestApiMetadata> extends BaseApiMetadata + implements RestApiMetadata { + + @SuppressWarnings("unchecked") + @Override + public Builder toBuilder() { + return new Builder(getApi(), getAsyncApi()).fromApiMetadata((M) this); + } + + public BaseRestApiMetadata(Class client, Class asyncClient) { + super(new Builder(client, asyncClient)); + } + + protected BaseRestApiMetadata(Builder builder) { + super(builder); + } + + public static class Builder, M extends RestApiMetadata > extends + BaseApiMetadata.Builder implements RestApiMetadata.Builder { + + public Builder(Class client, Class asyncClient) { + checkNotNull(client, "client"); + checkNotNull(asyncClient, "asyncClient"); + javaApi(client, asyncClient); + } + + @SuppressWarnings("unchecked") + @Override + public M build() { + return (M) new BaseRestApiMetadata(this); + } + + @Override + public Builder fromApiMetadata(M in) { + super.fromApiMetadata(in); + return this; + } + } + +} diff --git a/core/src/main/java/org/jclouds/rest/internal/ContextBuilder.java b/core/src/main/java/org/jclouds/rest/internal/ContextBuilder.java new file mode 100644 index 0000000000..4224944ebe --- /dev/null +++ b/core/src/main/java/org/jclouds/rest/internal/ContextBuilder.java @@ -0,0 +1,465 @@ +/** + * 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.rest.internal; + +import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.base.Predicates.instanceOf; +import static com.google.common.collect.Iterables.addAll; +import static com.google.common.collect.Iterables.any; +import static com.google.inject.Scopes.SINGLETON; +import static com.google.inject.util.Types.newParameterizedType; +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.util.Throwables2.propagateAuthorizationOrOriginalException; + +import java.io.Closeable; +import java.lang.reflect.Constructor; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.NoSuchElementException; +import java.util.Properties; + +import org.jclouds.apis.ApiMetadata; +import org.jclouds.apis.Apis; +import org.jclouds.concurrent.MoreExecutors; +import org.jclouds.concurrent.SingleThreaded; +import org.jclouds.concurrent.config.ConfiguresExecutorService; +import org.jclouds.concurrent.config.ExecutorServiceModule; +import org.jclouds.events.config.ConfiguresEventBus; +import org.jclouds.events.config.EventBusModule; +import org.jclouds.http.RequiresHttp; +import org.jclouds.http.config.ConfiguresHttpCommandExecutorService; +import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule; +import org.jclouds.javax.annotation.Nullable; +import org.jclouds.lifecycle.config.LifeCycleModule; +import org.jclouds.logging.config.LoggingModule; +import org.jclouds.logging.jdk.config.JDKLoggingModule; +import org.jclouds.providers.ProviderMetadata; +import org.jclouds.providers.Providers; +import org.jclouds.rest.AnonymousProviderMetadata; +import org.jclouds.rest.ConfiguresCredentialStore; +import org.jclouds.rest.ConfiguresRestClient; +import org.jclouds.rest.ConfiguresRestContext; +import org.jclouds.rest.RestContext; +import org.jclouds.rest.config.BindPropertiesToAnnotations; +import org.jclouds.rest.config.CredentialStoreModule; +import org.jclouds.rest.config.RestClientModule; +import org.jclouds.rest.config.RestModule; +import org.nnsoft.guice.rocoto.Rocoto; +import org.nnsoft.guice.rocoto.configuration.ConfigurationModule; + +import com.google.common.annotations.VisibleForTesting; +import com.google.common.base.Joiner; +import com.google.common.base.Objects; +import com.google.common.base.Predicate; +import com.google.common.base.Predicates; +import com.google.common.collect.ImmutableMultimap; +import com.google.common.collect.ImmutableMultimap.Builder; +import com.google.common.collect.Iterables; +import com.google.common.collect.Lists; +import com.google.common.collect.Maps; +import com.google.common.util.concurrent.ExecutionList; +import com.google.inject.AbstractModule; +import com.google.inject.Guice; +import com.google.inject.Injector; +import com.google.inject.Key; +import com.google.inject.Module; +import com.google.inject.Stage; +import com.google.inject.TypeLiteral; + +/** + * Creates {@link RestContext} or {@link Injector} instances based on the most + * commonly requested arguments. + *

+ * Note that Threadsafe objects will be bound as singletons to the Injector or + * Context provided. + *

+ *

+ * If no Modules are specified, the default + * {@link JDKLoggingModule logging} and + * {@link JavaUrlHttpCommandExecutorServiceModule http transports} will be + * installed. + * + * @author Adrian Cole, Andrew Newdigate + * @see RestContext + */ +public class ContextBuilder> { + + /** + * looks up a provider or api with the given id + * + * @param providerOrApi + * id of the provider or api + * @return means to build a context to that provider + * @throws NoSuchElementException + * if the id was not configured. + */ + public static ContextBuilder newBuilder(String providerOrApi) throws NoSuchElementException { + try { + try { + return ContextBuilder.newBuilder(Providers.withId(providerOrApi)); + } catch (NoSuchElementException e) { + return ContextBuilder.newBuilder(Apis.withId(providerOrApi)); + } + } catch (NoSuchElementException e) { + Builder builder = ImmutableMultimap. builder(); + builder.putAll("providers", Iterables.transform(Providers.all(), Providers.idFunction())); + builder.putAll("apis", Iterables.transform(Apis.all(), Apis.idFunction())); + throw new NoSuchElementException(String.format("key [%s] not in the list of providers or apis: %s", + providerOrApi, builder.build())); + } + } + + @SuppressWarnings("unchecked") + public static > ContextBuilder newBuilder( + ApiMetadata apiMetadata) { + try { + for (Constructor ctor : apiMetadata.getContextBuilder().getRawType().getConstructors()) { + if (ctor.getParameterTypes().length == 1 + && ctor.getParameterTypes()[0].isAssignableFrom(apiMetadata.getClass())) + return (ContextBuilder) ctor.newInstance(apiMetadata); + } + throw new IllegalArgumentException(String.format("class %s has no constructor that accepts %s", apiMetadata + .getContextBuilder().getRawType().getSimpleName(), apiMetadata.getClass().getSimpleName())); + } catch (Exception e) { + return propagateAuthorizationOrOriginalException(e); + } + } + + @SuppressWarnings("unchecked") + public static > ContextBuilder newBuilder( + ProviderMetadata providerMetadata) { + try { + Class contextBuilderClass = providerMetadata.getApiMetadata().getContextBuilder().getRawType(); + return (ContextBuilder) contextBuilderClass.getConstructor(ProviderMetadata.class).newInstance( + providerMetadata); + } catch (Exception e) { + return propagateAuthorizationOrOriginalException(e); + } + } + + protected ProviderMetadata providerMetadata; + protected String endpoint; + protected String identity; + protected String credential; + protected M apiMetadata; + protected String apiVersion; + protected String buildVersion; + protected Properties overrides = new Properties();; + protected List modules = new ArrayList(3); + + @Override + public String toString() { + return Objects.toStringHelper("").add("providerMetadata", providerMetadata).add("apiMetadata", apiMetadata) + .toString(); + } + + public ContextBuilder(ProviderMetadata providerMetadata) { + this(providerMetadata, providerMetadata.getApiMetadata()); + } + + protected ContextBuilder(@Nullable ProviderMetadata providerMetadata, M apiMetadata) { + this.apiMetadata = checkNotNull(apiMetadata, "apiMetadata"); + this.providerMetadata = providerMetadata; + if (providerMetadata != null) + this.endpoint = providerMetadata.getEndpoint(); + if (apiMetadata.getDefaultIdentity().isPresent()) + identity = apiMetadata.getDefaultIdentity().get(); + if (apiMetadata.getDefaultCredential().isPresent()) + credential = apiMetadata.getDefaultCredential().get(); + this.apiVersion = apiMetadata.getVersion(); + this.buildVersion = apiMetadata.getBuildVersion().or(""); + if (endpoint == null) + endpoint = apiMetadata.getDefaultEndpoint().orNull(); + } + + public ContextBuilder(M apiMetadata) { + this(null, apiMetadata); + } + + public ContextBuilder credentials(String identity, String credential) { + this.identity = identity; + this.credential = credential; + return this; + } + + public ContextBuilder endpoint(String endpoint) { + this.endpoint = endpoint; + return this; + } + + public ContextBuilder apiVersion(String apiVersion) { + this.apiVersion = checkNotNull(apiVersion, "apiVersion"); + return this; + } + + public ContextBuilder buildVersion(String buildVersion) { + this.buildVersion = checkNotNull(buildVersion, "buildVersion"); + return this; + } + + public ContextBuilder modules(Iterable modules) { + addAll(this.modules, modules); + return this; + } + + public ContextBuilder overrides(Properties overrides) { + this.overrides.putAll(overrides); + return this; + } + + /** + * + * @throws NoSuchElementException + */ + + public static String searchPropertiesForProviderScopedProperty(Properties overrides, String prov, String key, + String defaultVal) { + try { + return Iterables.find(Lists.newArrayList(overrides.getProperty(prov + "." + key), + overrides.getProperty("jclouds." + key), defaultVal), Predicates.notNull()); + } catch (NoSuchElementException e) { + throw new NoSuchElementException("no " + key + " configured for provider: " + prov); + } + } + + public Injector buildInjector() { + checkNotNull(modules, "modules"); + checkNotNull(overrides, "overrides"); + checkNotNull(apiMetadata, "api"); + + final Properties mutable = new Properties(); + mutable.putAll(apiMetadata.getDefaultProperties()); + String providerId; + if (providerMetadata != null) { + mutable.putAll(providerMetadata.getDefaultProperties()); + mutable.setProperty(PROPERTY_PROVIDER, providerId = providerMetadata.getId()); + mutable.setProperty(PROPERTY_ISO3166_CODES, Joiner.on(',').join(providerMetadata.getIso3166Codes())); + } else { + mutable.setProperty(PROPERTY_PROVIDER, providerId = apiMetadata.getId()); + } + mutable.putAll(checkNotNull(overrides, "overrides")); + mutable.putAll(propertiesPrefixedWithJcloudsApiOrProviderId(System.getProperties(), providerId)); + + mutable.setProperty(PROPERTY_ENDPOINT, + searchPropertiesForProviderScopedProperty(mutable, providerId, "endpoint", endpoint)); + mutable.setProperty(PROPERTY_API, + searchPropertiesForProviderScopedProperty(mutable, providerId, "api", apiMetadata.getName())); + mutable.setProperty(PROPERTY_API_VERSION, + searchPropertiesForProviderScopedProperty(mutable, providerId, "api-version", apiVersion)); + mutable.setProperty(PROPERTY_BUILD_VERSION, + searchPropertiesForProviderScopedProperty(mutable, providerId, "build-version", buildVersion)); + mutable.setProperty(PROPERTY_IDENTITY, + searchPropertiesForProviderScopedProperty(mutable, providerId, "identity", identity)); + try { + mutable.setProperty(PROPERTY_CREDENTIAL, + searchPropertiesForProviderScopedProperty(mutable, providerId, "credential", credential)); + } catch (NoSuchElementException e) { + if (apiMetadata.getCredentialName().isPresent()) + throw e; + } + if (providerMetadata == null) + providerMetadata = AnonymousProviderMetadata.forApiWithEndpoint(apiMetadata, + mutable.getProperty(PROPERTY_ENDPOINT)); + modules.add(Rocoto.expandVariables(new ConfigurationModule() { + + @Override + protected void bindConfigurations() { + bindProperties(mutable); + } + + })); + addContextModule(modules); + addClientModuleIfNotPresent(modules); + addLoggingModuleIfNotPresent(modules); + addHttpModuleIfNeededAndNotPresent(modules); + ifHttpConfigureRestOtherwiseGuiceClientFactory(modules); + addExecutorServiceIfNotPresent(modules); + addCredentialStoreIfNotPresent(modules); + modules.add(new LifeCycleModule()); + modules.add(new BindPropertiesToAnnotations()); + Injector returnVal = Guice.createInjector(Stage.PRODUCTION, modules); + returnVal.getInstance(ExecutionList.class).execute(); + return returnVal; + } + + @SuppressWarnings({ "unchecked", "rawtypes" }) + Map propertiesPrefixedWithJcloudsApiOrProviderId(Properties properties, String providerId) { + return Maps.filterKeys((Map) System.getProperties(), + Predicates.containsPattern("^(jclouds|" + providerId + "|" + apiMetadata.getId() + ").*")); + } + + @VisibleForTesting + protected void addLoggingModuleIfNotPresent(List modules) { + if (!any(modules, instanceOf(LoggingModule.class))) + modules.add(new JDKLoggingModule()); + } + + @VisibleForTesting + void addHttpModuleIfNeededAndNotPresent(List modules) { + if (defaultOrAtLeastOneModuleRequiresHttp(modules) && nothingConfiguresAnHttpService(modules)) + modules.add(new JavaUrlHttpCommandExecutorServiceModule()); + } + + private boolean nothingConfiguresAnHttpService(List modules) { + return (!any(modules, new Predicate() { + public boolean apply(Module input) { + return input.getClass().isAnnotationPresent(ConfiguresHttpCommandExecutorService.class); + } + + })); + } + + @VisibleForTesting + protected void addContextModuleIfNotPresent(List modules) { + if (!any(modules, new Predicate() { + public boolean apply(Module input) { + return input.getClass().isAnnotationPresent(ConfiguresRestContext.class); + } + + })) { + addContextModule(modules); + } + } + + @VisibleForTesting + protected void addContextModule(List modules) { + modules.add(new AbstractModule() { + + @SuppressWarnings({ "unchecked", "rawtypes" }) + @Override + protected void configure() { + bind( + (TypeLiteral) TypeLiteral.get(newParameterizedType(RestContext.class, providerMetadata + .getApiMetadata().getApi(), apiMetadata.getAsyncApi()))).to( + TypeLiteral.get(newParameterizedType(RestContextImpl.class, apiMetadata.getApi(), + apiMetadata.getAsyncApi()))).in(SINGLETON); + } + + public String toString() { + return String.format("configure rest context %s->%s", apiMetadata.getApi().getSimpleName(), apiMetadata + .getAsyncApi().getSimpleName()); + } + + }); + } + + @VisibleForTesting + protected void ifHttpConfigureRestOtherwiseGuiceClientFactory(List modules) { + if (defaultOrAtLeastOneModuleRequiresHttp(modules)) { + modules.add(new RestModule()); + } + } + + private boolean defaultOrAtLeastOneModuleRequiresHttp(List modules) { + return atLeastOneModuleRequiresHttp(modules) || !restClientModulePresent(modules); + } + + private boolean atLeastOneModuleRequiresHttp(List modules) { + return any(modules, new Predicate() { + public boolean apply(Module input) { + return input.getClass().isAnnotationPresent(RequiresHttp.class); + } + }); + } + + @VisibleForTesting + protected void addClientModuleIfNotPresent(List modules) { + if (!restClientModulePresent(modules)) { + addClientModule(modules); + } + } + + private boolean restClientModulePresent(List modules) { + return any(modules, new Predicate() { + public boolean apply(Module input) { + return input.getClass().isAnnotationPresent(ConfiguresRestClient.class); + } + + }); + } + + protected void addClientModule(List modules) { + modules.add(new RestClientModule(apiMetadata.getApi(), providerMetadata.getApiMetadata().getAsyncApi())); + } + + @VisibleForTesting + protected void addEventBusIfNotPresent(List modules) { + if (!any(modules, new Predicate() { + public boolean apply(Module input) { + return input.getClass().isAnnotationPresent(ConfiguresEventBus.class); + } + } + + )) { + modules.add(new EventBusModule()); + } + } + + @VisibleForTesting + protected void addExecutorServiceIfNotPresent(List modules) { + if (!any(modules, new Predicate() { + public boolean apply(Module input) { + return input.getClass().isAnnotationPresent(ConfiguresExecutorService.class); + } + } + + )) { + if (any(modules, new Predicate() { + public boolean apply(Module input) { + return input.getClass().isAnnotationPresent(SingleThreaded.class); + } + })) { + modules.add(new ExecutorServiceModule(MoreExecutors.sameThreadExecutor(), MoreExecutors + .sameThreadExecutor())); + } else { + modules.add(new ExecutorServiceModule()); + } + } + } + + @VisibleForTesting + protected void addCredentialStoreIfNotPresent(List modules) { + if (!any(modules, new Predicate() { + public boolean apply(Module input) { + return input.getClass().isAnnotationPresent(ConfiguresCredentialStore.class); + } + } + + )) { + modules.add(new CredentialStoreModule()); + } + } + + @SuppressWarnings("unchecked") + public C build() { + return (C) buildInjector().getInstance(Key.get(TypeLiteral.get(apiMetadata.getContext().getType()))); + } + + public M getApiMetadata() { + return apiMetadata; + } +} diff --git a/core/src/main/resources/rest.properties b/core/src/main/resources/rest.properties index 81cf5fe62f..d46966ddcc 100644 --- a/core/src/main/resources/rest.properties +++ b/core/src/main/resources/rest.properties @@ -1,5 +1,3 @@ -byon.contextbuilder=org.jclouds.byon.BYONComputeServiceContextBuilder -byon.propertiesbuilder=org.jclouds.byon.BYONPropertiesBuilder azurequeue.contextbuilder=org.jclouds.azure.storage.AzureStorageContextBuilder azurequeue.sync=org.jclouds.azurequeue.AzureQueueClient @@ -37,9 +35,6 @@ aws-cloudwatch.propertiesbuilder=org.jclouds.aws.cloudwatch.AWSCloudWatchPropert aws-s3.contextbuilder=org.jclouds.aws.s3.AWSS3ContextBuilder aws-s3.propertiesbuilder=org.jclouds.aws.s3.AWSS3PropertiesBuilder -aws-ec2.contextbuilder=org.jclouds.aws.ec2.AWSEC2ContextBuilder -aws-ec2.propertiesbuilder=org.jclouds.aws.ec2.AWSEC2PropertiesBuilder - rimuhosting.contextbuilder=org.jclouds.rimuhosting.miro.RimuHostingContextBuilder rimuhosting.propertiesbuilder=org.jclouds.rimuhosting.miro.RimuHostingPropertiesBuilder @@ -155,7 +150,6 @@ virtacore-publiccloud-lax.contextbuilder=org.jclouds.virtacore.publiccloud.Virta dunkel-vcd.propertiesbuilder=org.jclouds.dunkel.vcd.DunkelVCloudDirectorPropertiesBuilder dunkel-vcd.contextbuilder=org.jclouds.dunkel.vcd.DunkelVCloudDirectorContextBuilder -stub.contextbuilder=org.jclouds.compute.stub.StubComputeServiceContextBuilder # example of where to change your endpoint # bluelock.endpoint=https://express3.bluelock.com/api @@ -234,9 +228,6 @@ hosteurope-storage.propertiesbuilder=org.jclouds.hosteurope.storage.HostEuropeSt tiscali-storage.contextbuilder=org.jclouds.scality.rs2.ScalityRS2ContextBuilder tiscali-storage.propertiesbuilder=org.jclouds.tiscali.storage.TiscaliStoragePropertiesBuilder -transient.contextbuilder=org.jclouds.blobstore.TransientBlobStoreContextBuilder -transient.propertiesbuilder=org.jclouds.blobstore.TransientBlobStorePropertiesBuilder - virtualbox.contextbuilder=org.jclouds.virtualbox.VirtualBoxContextBuilder virtualbox.propertiesbuilder=org.jclouds.virtualbox.VirtualBoxPropertiesBuilder diff --git a/core/src/test/java/org/jclouds/apis/ApisTest.java b/core/src/test/java/org/jclouds/apis/ApisTest.java index 9f945ed06c..ba6d2f5e35 100644 --- a/core/src/test/java/org/jclouds/apis/ApisTest.java +++ b/core/src/test/java/org/jclouds/apis/ApisTest.java @@ -33,14 +33,14 @@ import org.testng.annotations.Test; @Test(groups = "unit", testName = "ApisTest") public class ApisTest { - private final ApiMetadata testBlobstoreApi = new JcloudsTestBlobStoreApiMetadata(); - private final ApiMetadata testComputeApi = new JcloudsTestComputeApiMetadata(); - private final ApiMetadata testYetAnotherComputeApi = new JcloudsTestYetAnotherComputeApiMetadata(); + private final JcloudsTestBlobStoreApiMetadata testBlobstoreApi = new JcloudsTestBlobStoreApiMetadata(); + private final JcloudsTestComputeApiMetadata testComputeApi = new JcloudsTestComputeApiMetadata(); + private final JcloudsTestYetAnotherComputeApiMetadata testYetAnotherComputeApi = new JcloudsTestYetAnotherComputeApiMetadata(); @Test public void testWithId() { - ApiMetadata apiMetadata; + ApiMetadata apiMetadata; try { apiMetadata = Apis.withId("fake-id"); fail("Looking for a api with an id that doesn't exist should " + "throw an exceptoin."); @@ -55,15 +55,15 @@ public class ApisTest { @Test public void testOfType() { - Iterable apisMetadata = Apis.ofType(ApiType.BLOBSTORE); + Iterable> apisMetadata = Apis.ofType(ApiType.BLOBSTORE); - for (ApiMetadata apiMetadata : apisMetadata) { + for (ApiMetadata apiMetadata : apisMetadata) { assertEquals(testBlobstoreApi, apiMetadata); } apisMetadata = Apis.ofType(ApiType.COMPUTE); - for (ApiMetadata apiMetadata : apisMetadata) { + for (ApiMetadata apiMetadata : apisMetadata) { if (apiMetadata.getName().equals(testComputeApi.getName())) { assertEquals(testComputeApi, apiMetadata); } else { @@ -78,9 +78,9 @@ public class ApisTest { @Test public void testAll() { - Iterable apisMetadata = Apis.all(); + Iterable> apisMetadata = Apis.all(); - for (ApiMetadata apiMetadata : apisMetadata) { + for (ApiMetadata apiMetadata : apisMetadata) { if (apiMetadata.getName().equals(testBlobstoreApi.getName())) { assertEquals(testBlobstoreApi, apiMetadata); } else if (apiMetadata.getName().equals(testComputeApi.getName())) { diff --git a/core/src/test/java/org/jclouds/apis/JcloudsTestBlobStoreApiMetadata.java b/core/src/test/java/org/jclouds/apis/JcloudsTestBlobStoreApiMetadata.java index 7f1cffa226..21d2c88e4a 100644 --- a/core/src/test/java/org/jclouds/apis/JcloudsTestBlobStoreApiMetadata.java +++ b/core/src/test/java/org/jclouds/apis/JcloudsTestBlobStoreApiMetadata.java @@ -20,44 +20,56 @@ package org.jclouds.apis; import java.net.URI; +import org.jclouds.apis.internal.BaseApiMetadata; +import org.jclouds.http.IntegrationTestAsyncClient; +import org.jclouds.http.IntegrationTestClient; +import org.jclouds.rest.RestContext; + /** * Implementation of @ link org.jclouds.types.ApiMetadata} for testing. * * @author Jeremy Whitlock , Adrian Cole */ -public class JcloudsTestBlobStoreApiMetadata extends BaseApiMetadata { - - public JcloudsTestBlobStoreApiMetadata() { - this(builder() - .id("test-blobstore-api") - .type(ApiType.BLOBSTORE) - .name("Test Blobstore Api") - .identityName("user") - .credentialName("password") - .documentation(URI.create("http://jclouds.org/documentation"))); +public class JcloudsTestBlobStoreApiMetadata + extends + BaseApiMetadata, JcloudsTestBlobStoreApiMetadata> { + + public static Builder builder() { + return new Builder(); } - // below are so that we can reuse builders, toString, hashCode, etc. - // we have to set concrete classes here, as our base class cannot be - // concrete due to serviceLoader - protected JcloudsTestBlobStoreApiMetadata(ConcreteBuilder builder) { + @Override + public Builder toBuilder() { + return Builder.class.cast(builder().fromApiMetadata(this)); + } + + public JcloudsTestBlobStoreApiMetadata() { + super(builder()); + } + + protected JcloudsTestBlobStoreApiMetadata(Builder builder) { super(builder); } - private static class ConcreteBuilder extends Builder { + public static class Builder + extends + BaseApiMetadata.Builder, JcloudsTestBlobStoreApiMetadata> { + + protected Builder(){ + id("test-blobstore-api") + .type(ApiType.BLOBSTORE) + .name("Test Blobstore Api") + .javaApi(IntegrationTestClient.class, IntegrationTestAsyncClient.class) + .identityName("user") + .credentialName("password") + .documentation(URI.create("http://jclouds.org/documentation")); + } @Override public JcloudsTestBlobStoreApiMetadata build() { return new JcloudsTestBlobStoreApiMetadata(this); } + } - public static ConcreteBuilder builder() { - return new ConcreteBuilder(); - } - - @Override - public ConcreteBuilder toBuilder() { - return builder().fromApiMetadata(this); - } } \ No newline at end of file diff --git a/core/src/test/java/org/jclouds/apis/JcloudsTestComputeApiMetadata.java b/core/src/test/java/org/jclouds/apis/JcloudsTestComputeApiMetadata.java index c21f86ccab..99addc6a57 100644 --- a/core/src/test/java/org/jclouds/apis/JcloudsTestComputeApiMetadata.java +++ b/core/src/test/java/org/jclouds/apis/JcloudsTestComputeApiMetadata.java @@ -20,44 +20,54 @@ package org.jclouds.apis; import java.net.URI; +import org.jclouds.apis.internal.BaseApiMetadata; +import org.jclouds.http.IntegrationTestAsyncClient; +import org.jclouds.http.IntegrationTestClient; +import org.jclouds.rest.RestContext; + /** * Implementation of @ link org.jclouds.types.ApiMetadata} for testing. * * @author Jeremy Whitlock , Adrian Cole */ -public class JcloudsTestComputeApiMetadata extends BaseApiMetadata { - - public JcloudsTestComputeApiMetadata() { - this(builder() - .id("test-compute-api") - .type(ApiType.COMPUTE) - .name("Test Compute Api") - .identityName("user") - .credentialName("password") - .documentation(URI.create("http://jclouds.org/documentation"))); +public class JcloudsTestComputeApiMetadata extends BaseApiMetadata, JcloudsTestComputeApiMetadata>{ + + public static Builder builder() { + return new Builder(); } - // below are so that we can reuse builders, toString, hashCode, etc. - // we have to set concrete classes here, as our base class cannot be - // concrete due to serviceLoader - protected JcloudsTestComputeApiMetadata(ConcreteBuilder builder) { + @Override + public Builder toBuilder() { + return Builder.class.cast(builder().fromApiMetadata(this)); + } + + public JcloudsTestComputeApiMetadata() { + super(builder()); + } + + protected JcloudsTestComputeApiMetadata(Builder builder) { super(builder); } - private static class ConcreteBuilder extends Builder { + public static class Builder + extends + BaseApiMetadata.Builder, JcloudsTestComputeApiMetadata> { + + protected Builder(){ + id("test-compute-api") + .type(ApiType.COMPUTE) + .name("Test Compute Api") + .javaApi(IntegrationTestClient.class, IntegrationTestAsyncClient.class) + .identityName("user") + .credentialName("password") + .documentation(URI.create("http://jclouds.org/documentation")); + } @Override public JcloudsTestComputeApiMetadata build() { return new JcloudsTestComputeApiMetadata(this); } + } - public static ConcreteBuilder builder() { - return new ConcreteBuilder(); - } - - @Override - public ConcreteBuilder toBuilder() { - return builder().fromApiMetadata(this); - } } \ No newline at end of file diff --git a/core/src/test/java/org/jclouds/apis/JcloudsTestYetAnotherComputeApiMetadata.java b/core/src/test/java/org/jclouds/apis/JcloudsTestYetAnotherComputeApiMetadata.java index eb7c35e985..ad36f40fe4 100644 --- a/core/src/test/java/org/jclouds/apis/JcloudsTestYetAnotherComputeApiMetadata.java +++ b/core/src/test/java/org/jclouds/apis/JcloudsTestYetAnotherComputeApiMetadata.java @@ -20,45 +20,54 @@ package org.jclouds.apis; import java.net.URI; +import org.jclouds.apis.internal.BaseApiMetadata; +import org.jclouds.http.IntegrationTestAsyncClient; +import org.jclouds.http.IntegrationTestClient; +import org.jclouds.rest.RestContext; + /** * Implementation of @ link org.jclouds.types.ApiMetadata} for testing. * * @author Jeremy Whitlock */ -public class JcloudsTestYetAnotherComputeApiMetadata extends BaseApiMetadata { - - public JcloudsTestYetAnotherComputeApiMetadata() { - this(builder() - .id("test-yet-another-compute-api") - .type(ApiType.COMPUTE) - .name("Test Yet Another Compute Api") - .identityName("user") - .credentialName("password") - .documentation(URI.create("http://jclouds.org/documentation"))); +public class JcloudsTestYetAnotherComputeApiMetadata + extends + BaseApiMetadata, JcloudsTestYetAnotherComputeApiMetadata> { + + public static Builder builder() { + return new Builder(); } - // below are so that we can reuse builders, toString, hashCode, etc. - // we have to set concrete classes here, as our base class cannot be - // concrete due to serviceLoader - protected JcloudsTestYetAnotherComputeApiMetadata(ConcreteBuilder builder) { + @Override + public Builder toBuilder() { + return Builder.class.cast(builder().fromApiMetadata(this)); + } + + public JcloudsTestYetAnotherComputeApiMetadata() { + super(builder()); + } + + protected JcloudsTestYetAnotherComputeApiMetadata(Builder builder) { super(builder); } - private static class ConcreteBuilder extends Builder { + public static class Builder extends BaseApiMetadata.Builder, JcloudsTestYetAnotherComputeApiMetadata> { + + protected Builder(){ + id("test-yet-another-compute-api") + .type(ApiType.COMPUTE) + .name("Test Yet Another Compute Api") + .javaApi(IntegrationTestClient.class, IntegrationTestAsyncClient.class) + .identityName("user") + .credentialName("password") + .documentation(URI.create("http://jclouds.org/documentation")); + } @Override public JcloudsTestYetAnotherComputeApiMetadata build() { return new JcloudsTestYetAnotherComputeApiMetadata(this); } - } - public static ConcreteBuilder builder() { - return new ConcreteBuilder(); - } - - @Override - public ConcreteBuilder toBuilder() { - return builder().fromApiMetadata(this); } } \ No newline at end of file diff --git a/core/src/test/java/org/jclouds/apis/BaseApiMetadataTest.java b/core/src/test/java/org/jclouds/apis/internal/BaseApiMetadataTest.java similarity index 75% rename from core/src/test/java/org/jclouds/apis/BaseApiMetadataTest.java rename to core/src/test/java/org/jclouds/apis/internal/BaseApiMetadataTest.java index dc46bf8cea..95addda38b 100644 --- a/core/src/test/java/org/jclouds/apis/BaseApiMetadataTest.java +++ b/core/src/test/java/org/jclouds/apis/internal/BaseApiMetadataTest.java @@ -16,23 +16,27 @@ * specific language governing permissions and limitations * under the License. */ -package org.jclouds.apis; +package org.jclouds.apis.internal; import static org.testng.Assert.assertEquals; +import org.jclouds.apis.ApiMetadata; +import org.jclouds.apis.ApiType; +import org.jclouds.apis.Apis; import org.testng.annotations.Test; import com.google.common.collect.ImmutableSet; /** * - * @author Jeremy Whitlock + * @author Adrian Cole */ +@SuppressWarnings("rawtypes") @Test(groups = "unit") public abstract class BaseApiMetadataTest { - private final ApiMetadata toTest; - private final ApiType expectedType; + protected final ApiMetadata toTest; + protected final ApiType expectedType; public BaseApiMetadataTest(ApiMetadata toTest, ApiType expectedType) { this.toTest = toTest; @@ -41,7 +45,7 @@ public abstract class BaseApiMetadataTest { @Test public void testWithId() { - ApiMetadata apiMetadata = Apis.withId(toTest.getId()); + ApiMetadata apiMetadata = Apis.withId(toTest.getId()); assertEquals(toTest, apiMetadata); } @@ -49,13 +53,13 @@ public abstract class BaseApiMetadataTest { // it is ok to have multiple services in the same classpath (ex. ec2 vs elb) @Test public void testOfTypeContains() { - ImmutableSet ofType = ImmutableSet.copyOf(Apis.ofType(expectedType)); + ImmutableSet> ofType = ImmutableSet.copyOf(Apis.ofType(expectedType)); assert ofType.contains(toTest) : String.format("%s not found in %s", toTest, ofType); } @Test public void testAllContains() { - ImmutableSet all = ImmutableSet.copyOf(Apis.all()); + ImmutableSet> all = ImmutableSet.copyOf(Apis.all()); assert all.contains(toTest) : String.format("%s not found in %s", toTest, all); } diff --git a/compute/src/test/java/org/jclouds/compute/ComputeServiceContextFactoryTest.java b/core/src/test/java/org/jclouds/apis/internal/BaseRestApiMetadataTest.java similarity index 51% rename from compute/src/test/java/org/jclouds/compute/ComputeServiceContextFactoryTest.java rename to core/src/test/java/org/jclouds/apis/internal/BaseRestApiMetadataTest.java index af977d5d29..a6a3bec92b 100644 --- a/compute/src/test/java/org/jclouds/compute/ComputeServiceContextFactoryTest.java +++ b/core/src/test/java/org/jclouds/apis/internal/BaseRestApiMetadataTest.java @@ -16,36 +16,36 @@ * specific language governing permissions and limitations * under the License. */ -package org.jclouds.compute; +package org.jclouds.apis.internal; -import java.util.concurrent.ConcurrentMap; +import java.util.Set; -import org.jclouds.compute.domain.Hardware; -import org.jclouds.compute.domain.Image; -import org.jclouds.compute.domain.NodeMetadata; -import org.jclouds.compute.stub.StubComputeServiceContextBuilder; -import org.jclouds.domain.Location; +import org.jclouds.apis.ApiMetadata; +import org.jclouds.apis.ApiType; +import org.jclouds.apis.Apis; +import org.jclouds.rest.RestApiMetadata; +import org.jclouds.rest.RestContext; import org.testng.annotations.Test; import com.google.common.collect.ImmutableSet; -import com.google.inject.Module; +import com.google.common.reflect.TypeToken; /** * * @author Adrian Cole - * */ @Test(groups = "unit") -public class ComputeServiceContextFactoryTest { +public abstract class BaseRestApiMetadataTest extends BaseApiMetadataTest { + + @SuppressWarnings("rawtypes") + public BaseRestApiMetadataTest(RestApiMetadata toTest, ApiType type) { + super(toTest, type); + } @Test - public void testStandalone() { - @SuppressWarnings("rawtypes") - ComputeServiceContext context = new ComputeServiceContextFactory() - .createContext(new StandaloneComputeServiceContextSpec( - "stub", "stub", "1", "", "", "identity", "credential", ConcurrentMap.class, - StubComputeServiceContextBuilder.class, ImmutableSet. of())); - - context.getComputeService().listNodes(); + public void testContextAssignableFromRestContext() { + Set> all = ImmutableSet.copyOf(Apis.contextAssignableFrom(TypeToken.of(RestContext.class))); + assert all.contains(toTest) : String.format("%s not found in %s", toTest, all); } -} + +} \ No newline at end of file diff --git a/core/src/test/java/org/jclouds/http/BaseJettyTest.java b/core/src/test/java/org/jclouds/http/BaseJettyTest.java index b5b3d5ae84..8a9c196027 100644 --- a/core/src/test/java/org/jclouds/http/BaseJettyTest.java +++ b/core/src/test/java/org/jclouds/http/BaseJettyTest.java @@ -26,8 +26,6 @@ import static com.google.common.io.ByteStreams.newInputStreamSupplier; import static com.google.common.io.ByteStreams.toByteArray; import static com.google.common.io.Closeables.closeQuietly; import static javax.ws.rs.core.HttpHeaders.CONTENT_LENGTH; -import static org.jclouds.rest.RestContextFactory.contextSpec; -import static org.jclouds.rest.RestContextFactory.createContextBuilder; import java.io.ByteArrayInputStream; import java.io.IOException; @@ -55,9 +53,9 @@ import org.eclipse.jetty.util.ssl.SslContextFactory; import org.jclouds.Constants; import org.jclouds.crypto.CryptoStreams; import org.jclouds.io.InputSuppliers; +import org.jclouds.rest.AnonymousProviderMetadata; import org.jclouds.rest.RestContext; -import org.jclouds.rest.RestContextBuilder; -import org.jclouds.rest.RestContextSpec; +import org.jclouds.rest.internal.ContextBuilder; import org.jclouds.util.Strings2; import org.testng.annotations.AfterTest; import org.testng.annotations.BeforeTest; @@ -173,7 +171,7 @@ public abstract class BaseJettyTest { Properties properties = new Properties(); addConnectionProperties(properties); - context = newBuilder(testPort, properties, createConnectionModule()).buildContext(); + context = newBuilder(testPort, properties, createConnectionModule()).build(); client = context.getApi(); assert client != null; @@ -282,14 +280,16 @@ public abstract class BaseJettyTest { return temp; } - public static RestContextBuilder newBuilder(int testPort, - Properties properties, Module... connectionModules) { + public static ContextBuilder, ?> newBuilder( + int testPort, Properties properties, Module... connectionModules) { properties.setProperty(Constants.PROPERTY_TRUST_ALL_CERTS, "true"); properties.setProperty(Constants.PROPERTY_RELAX_HOSTNAME, "true"); - RestContextSpec contextSpec = contextSpec("test", - "http://localhost:" + testPort, "1", "", "", "identity", null, IntegrationTestClient.class, - IntegrationTestAsyncClient.class, ImmutableSet. copyOf(connectionModules)); - return createContextBuilder(contextSpec, properties); + return ContextBuilder + .newBuilder( + AnonymousProviderMetadata.forClientMappedToAsyncClientOnEndpoint(IntegrationTestClient.class, IntegrationTestAsyncClient.class, + "http://localhost:" + testPort)) + .modules(ImmutableSet. copyOf(connectionModules)) + .overrides(properties); } @AfterTest diff --git a/core/src/test/java/org/jclouds/http/IntegrationTestClientExpectTest.java b/core/src/test/java/org/jclouds/http/IntegrationTestClientExpectTest.java index 3e59269162..1eed674207 100644 --- a/core/src/test/java/org/jclouds/http/IntegrationTestClientExpectTest.java +++ b/core/src/test/java/org/jclouds/http/IntegrationTestClientExpectTest.java @@ -26,8 +26,9 @@ import java.util.concurrent.atomic.AtomicInteger; import javax.net.ssl.SSLException; -import org.jclouds.rest.BaseRestClientExpectTest; -import org.jclouds.rest.BaseRestClientExpectTest.RegisterContext; +import org.jclouds.providers.JcloudsTestBlobStoreProviderMetadata; +import org.jclouds.providers.ProviderMetadata; +import org.jclouds.rest.internal.BaseRestClientExpectTest; import org.testng.annotations.Test; import com.google.common.base.Function; @@ -40,7 +41,6 @@ import com.google.common.base.Function; */ @Test(groups = "unit", testName = "IntegrationTestClientExpectTest") // only needed as IntegrationTestClient is not registered in rest.properties -@RegisterContext(sync = IntegrationTestClient.class, async = IntegrationTestAsyncClient.class) public class IntegrationTestClientExpectTest extends BaseRestClientExpectTest { public void testRetryOnSSLExceptionClose() { @@ -87,4 +87,9 @@ public class IntegrationTestClientExpectTest extends BaseRestClientExpectTest createProviderMetadata() { + return new JcloudsTestBlobStoreProviderMetadata(); + } } diff --git a/core/src/test/java/org/jclouds/http/handlers/RedirectionRetryHandlerTest.java b/core/src/test/java/org/jclouds/http/handlers/RedirectionRetryHandlerTest.java index 707ef581fd..db921672db 100644 --- a/core/src/test/java/org/jclouds/http/handlers/RedirectionRetryHandlerTest.java +++ b/core/src/test/java/org/jclouds/http/handlers/RedirectionRetryHandlerTest.java @@ -32,8 +32,8 @@ import javax.ws.rs.core.HttpHeaders; import org.jclouds.http.HttpCommand; import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpResponse; -import org.jclouds.rest.BaseRestClientTest.MockModule; import org.jclouds.rest.config.RestModule; +import org.jclouds.rest.internal.BaseRestClientTest.MockModule; import org.testng.annotations.Test; import com.google.common.collect.ImmutableMultimap; diff --git a/core/src/test/java/org/jclouds/providers/JcloudsTestBlobStoreProviderMetadata.java b/core/src/test/java/org/jclouds/providers/JcloudsTestBlobStoreProviderMetadata.java index 265079b3de..c04305de97 100644 --- a/core/src/test/java/org/jclouds/providers/JcloudsTestBlobStoreProviderMetadata.java +++ b/core/src/test/java/org/jclouds/providers/JcloudsTestBlobStoreProviderMetadata.java @@ -21,6 +21,10 @@ package org.jclouds.providers; import java.net.URI; import org.jclouds.apis.JcloudsTestBlobStoreApiMetadata; +import org.jclouds.http.IntegrationTestAsyncClient; +import org.jclouds.http.IntegrationTestClient; +import org.jclouds.providers.internal.BaseProviderMetadata; +import org.jclouds.rest.RestContext; import com.google.common.collect.ImmutableSet; @@ -29,38 +33,46 @@ import com.google.common.collect.ImmutableSet; * * @author Jeremy Whitlock */ -public class JcloudsTestBlobStoreProviderMetadata extends BaseProviderMetadata { +public class JcloudsTestBlobStoreProviderMetadata + extends + BaseProviderMetadata, JcloudsTestBlobStoreApiMetadata> { - public JcloudsTestBlobStoreProviderMetadata() { - this(builder() - .api(new JcloudsTestBlobStoreApiMetadata()) - .id("test-blobstore-api") - .name("Test Blobstore Provider") - .homepage(URI.create("http://jclouds.org")) - .console(URI.create("http://jclouds.org/console")) - .iso3166Codes(ImmutableSet.of("US-VA", "US-CA", "US-FL"))); + public static Builder builder() { + return new Builder(); + } + + @Override + public Builder toBuilder() { + return Builder.class.cast(builder().fromProviderMetadata(this)); } - // below are so that we can reuse builders, toString, hashCode, etc. - // we have to set concrete classes here, as our base class cannot be - // concrete due to serviceLoader - protected JcloudsTestBlobStoreProviderMetadata(ConcreteBuilder builder) { + public JcloudsTestBlobStoreProviderMetadata() { + super(builder()); + } + + public JcloudsTestBlobStoreProviderMetadata(Builder builder) { super(builder); } - private static class ConcreteBuilder extends Builder { + public static class Builder + extends + BaseProviderMetadata.Builder, JcloudsTestBlobStoreApiMetadata> { + + protected Builder(){ + id("test-blobstore-api") + .name("Test Blobstore Provider") + .endpoint("http://mock") + .homepage(URI.create("http://jclouds.org")) + .console(URI.create("http://jclouds.org/console")) + .iso3166Codes(ImmutableSet.of("US-VA", "US-CA", "US-FL")) + .apiMetadata(new JcloudsTestBlobStoreApiMetadata()); + } @Override public JcloudsTestBlobStoreProviderMetadata build() { return new JcloudsTestBlobStoreProviderMetadata(this); } + } - public static ConcreteBuilder builder() { - return new ConcreteBuilder(); - } - - public ConcreteBuilder toBuilder() { - return builder().fromProviderMetadata(this); - } } \ No newline at end of file diff --git a/core/src/test/java/org/jclouds/providers/JcloudsTestComputeProviderMetadata.java b/core/src/test/java/org/jclouds/providers/JcloudsTestComputeProviderMetadata.java index c7abbe46ce..60fc513520 100644 --- a/core/src/test/java/org/jclouds/providers/JcloudsTestComputeProviderMetadata.java +++ b/core/src/test/java/org/jclouds/providers/JcloudsTestComputeProviderMetadata.java @@ -21,6 +21,10 @@ package org.jclouds.providers; import java.net.URI; import org.jclouds.apis.JcloudsTestComputeApiMetadata; +import org.jclouds.http.IntegrationTestAsyncClient; +import org.jclouds.http.IntegrationTestClient; +import org.jclouds.providers.internal.BaseProviderMetadata; +import org.jclouds.rest.RestContext; import com.google.common.collect.ImmutableSet; @@ -29,38 +33,46 @@ import com.google.common.collect.ImmutableSet; * * @author Jeremy Whitlock */ -public class JcloudsTestComputeProviderMetadata extends BaseProviderMetadata { - - public JcloudsTestComputeProviderMetadata() { - this(builder() - .api(new JcloudsTestComputeApiMetadata()) - .id("test-compute-api") - .name("Test Compute Provider") - .homepage(URI.create("http://jclouds.org")) - .console(URI.create("http://jclouds.org/console")) - .iso3166Codes(ImmutableSet.of("US-VA", "US-CA"))); +public class JcloudsTestComputeProviderMetadata + extends + BaseProviderMetadata, JcloudsTestComputeApiMetadata> { + + public static Builder builder() { + return new Builder(); } - // below are so that we can reuse builders, toString, hashCode, etc. - // we have to set concrete classes here, as our base class cannot be - // concrete due to serviceLoader - protected JcloudsTestComputeProviderMetadata(ConcreteBuilder builder) { + @Override + public Builder toBuilder() { + return Builder.class.cast(builder().fromProviderMetadata(this)); + } + + public JcloudsTestComputeProviderMetadata() { + super(builder()); + } + + public JcloudsTestComputeProviderMetadata(Builder builder) { super(builder); } - private static class ConcreteBuilder extends Builder { + public static class Builder + extends + BaseProviderMetadata.Builder, JcloudsTestComputeApiMetadata> { + + protected Builder(){ + id("test-compute-api") + .name("Test Compute Provider") + .endpoint("mem2") + .homepage(URI.create("http://jclouds.org")) + .console(URI.create("http://jclouds.org/console")) + .iso3166Codes(ImmutableSet.of("US-VA", "US-CA")) + .apiMetadata(new JcloudsTestComputeApiMetadata()); + } @Override public JcloudsTestComputeProviderMetadata build() { return new JcloudsTestComputeProviderMetadata(this); } + } - public static ConcreteBuilder builder() { - return new ConcreteBuilder(); - } - - public ConcreteBuilder toBuilder() { - return builder().fromProviderMetadata(this); - } } \ No newline at end of file diff --git a/core/src/test/java/org/jclouds/providers/JcloudsTestYetAnotherComputeProviderMetadata.java b/core/src/test/java/org/jclouds/providers/JcloudsTestYetAnotherComputeProviderMetadata.java index 3297b35840..388ebc9cc1 100644 --- a/core/src/test/java/org/jclouds/providers/JcloudsTestYetAnotherComputeProviderMetadata.java +++ b/core/src/test/java/org/jclouds/providers/JcloudsTestYetAnotherComputeProviderMetadata.java @@ -21,6 +21,10 @@ package org.jclouds.providers; import java.net.URI; import org.jclouds.apis.JcloudsTestComputeApiMetadata; +import org.jclouds.http.IntegrationTestAsyncClient; +import org.jclouds.http.IntegrationTestClient; +import org.jclouds.providers.internal.BaseProviderMetadata; +import org.jclouds.rest.RestContext; import com.google.common.collect.ImmutableSet; @@ -29,38 +33,46 @@ import com.google.common.collect.ImmutableSet; * * @author Jeremy Whitlock */ -public class JcloudsTestYetAnotherComputeProviderMetadata extends BaseProviderMetadata { - - public JcloudsTestYetAnotherComputeProviderMetadata() { - this(builder() - .api(new JcloudsTestComputeApiMetadata()) - .id("test-yet-another-compute-provider") - .name("Test Yet Another Compute Provider") - .homepage(URI.create("http://jclouds.org")) - .console(URI.create("http://jclouds.org/console")) - .iso3166Codes(ImmutableSet.of("JP-13"))); +public class JcloudsTestYetAnotherComputeProviderMetadata + extends + BaseProviderMetadata, JcloudsTestComputeApiMetadata> { + + public static Builder builder() { + return new Builder(); } - // below are so that we can reuse builders, toString, hashCode, etc. - // we have to set concrete classes here, as our base class cannot be - // concrete due to serviceLoader - protected JcloudsTestYetAnotherComputeProviderMetadata(ConcreteBuilder builder) { + @Override + public Builder toBuilder() { + return Builder.class.cast(builder().fromProviderMetadata(this)); + } + + public JcloudsTestYetAnotherComputeProviderMetadata() { + super(builder()); + } + + public JcloudsTestYetAnotherComputeProviderMetadata(Builder builder) { super(builder); } - private static class ConcreteBuilder extends Builder { + public static class Builder + extends + BaseProviderMetadata.Builder, JcloudsTestComputeApiMetadata> { + + protected Builder(){ + id("test-yet-another-compute-provider") + .name("Test Yet Another Compute Provider") + .endpoint("mem3") + .homepage(URI.create("http://jclouds.org")) + .console(URI.create("http://jclouds.org/console")) + .iso3166Codes(ImmutableSet.of("JP-13")) + .apiMetadata(new JcloudsTestComputeApiMetadata()); + } @Override public JcloudsTestYetAnotherComputeProviderMetadata build() { return new JcloudsTestYetAnotherComputeProviderMetadata(this); } + } - public static ConcreteBuilder builder() { - return new ConcreteBuilder(); - } - - public ConcreteBuilder toBuilder() { - return builder().fromProviderMetadata(this); - } } \ No newline at end of file diff --git a/core/src/test/java/org/jclouds/providers/ProvidersTest.java b/core/src/test/java/org/jclouds/providers/ProvidersTest.java index 0edf5d158f..5f6f841d75 100644 --- a/core/src/test/java/org/jclouds/providers/ProvidersTest.java +++ b/core/src/test/java/org/jclouds/providers/ProvidersTest.java @@ -19,6 +19,7 @@ package org.jclouds.providers; import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotEquals; import static org.testng.Assert.fail; import java.util.NoSuchElementException; @@ -36,13 +37,13 @@ import com.google.common.collect.Iterables; @Test(groups = "unit", testName = "ProvidersTest") public class ProvidersTest { - private final ProviderMetadata testBlobstoreProvider = new JcloudsTestBlobStoreProviderMetadata(); - private final ProviderMetadata testComputeProvider = new JcloudsTestComputeProviderMetadata(); - private final ProviderMetadata testYetAnotherComputeProvider = new JcloudsTestYetAnotherComputeProviderMetadata(); + private final JcloudsTestBlobStoreProviderMetadata testBlobstoreProvider = new JcloudsTestBlobStoreProviderMetadata(); + private final JcloudsTestComputeProviderMetadata testComputeProvider = new JcloudsTestComputeProviderMetadata(); + private final JcloudsTestYetAnotherComputeProviderMetadata testYetAnotherComputeProvider = new JcloudsTestYetAnotherComputeProviderMetadata(); @Test public void testWithId() { - ProviderMetadata providerMetadata; + ProviderMetadata providerMetadata; try { providerMetadata = Providers.withId("fake-id"); @@ -54,19 +55,21 @@ public class ProvidersTest { providerMetadata = Providers.withId(testBlobstoreProvider.getId()); assertEquals(testBlobstoreProvider, providerMetadata); + assertNotEquals(testBlobstoreProvider, testComputeProvider); + assertNotEquals(testBlobstoreProvider, testYetAnotherComputeProvider); } @Test public void testOfType() { - Iterable providersMetadata = Providers.ofType(ApiType.BLOBSTORE); + Iterable> providersMetadata = Providers.ofType(ApiType.BLOBSTORE); - for (ProviderMetadata providerMetadata : providersMetadata) { + for (ProviderMetadata providerMetadata : providersMetadata) { assertEquals(testBlobstoreProvider, providerMetadata); } providersMetadata = Providers.ofType(ApiType.COMPUTE); - for (ProviderMetadata providerMetadata : providersMetadata) { + for (ProviderMetadata providerMetadata : providersMetadata) { if (providerMetadata.getName().equals(testComputeProvider.getName())) { assertEquals(testComputeProvider, providerMetadata); } else { @@ -79,35 +82,11 @@ public class ProvidersTest { assertEquals(false, providersMetadata.iterator().hasNext()); } - @Test - @Deprecated - public void testOfTypeDeprecated() { - Iterable providersMetadata = Providers.ofType(ProviderMetadata.BLOBSTORE_TYPE); - - for (ProviderMetadata providerMetadata : providersMetadata) { - assertEquals(testBlobstoreProvider, providerMetadata); - } - - providersMetadata = Providers.ofType(ProviderMetadata.COMPUTE_TYPE); - - for (ProviderMetadata providerMetadata : providersMetadata) { - if (providerMetadata.getName().equals(testComputeProvider.getName())) { - assertEquals(testComputeProvider, providerMetadata); - } else { - assertEquals(testYetAnotherComputeProvider, providerMetadata); - } - } - - providersMetadata = Providers.ofType("fake-type"); - - assertEquals(false, providersMetadata.iterator().hasNext()); - } - @Test public void testAll() { - Iterable providersMetadata = Providers.all(); + Iterable> providersMetadata = Providers.all(); - for (ProviderMetadata providerMetadata : providersMetadata) { + for (ProviderMetadata providerMetadata : providersMetadata) { if (providerMetadata.getName().equals(testBlobstoreProvider.getName())) { assertEquals(testBlobstoreProvider, providerMetadata); } else if (providerMetadata.getName().equals(testComputeProvider.getName())) { @@ -142,6 +121,7 @@ public class ProvidersTest { @Test public void testCollocatedWith() { // Test filtering by collocation alone + assertEquals(Iterables.size(Providers.collocatedWith(testYetAnotherComputeProvider)), 0); assertEquals(Iterables.size(Providers.collocatedWith(testBlobstoreProvider)), 1); assertEquals(Iterables.size(Providers.collocatedWith(testComputeProvider)), 1); assertEquals(Iterables.size(Providers.collocatedWith(testYetAnotherComputeProvider)), 0); @@ -155,44 +135,4 @@ public class ProvidersTest { assertEquals(Iterables.size(Providers.collocatedWith(testYetAnotherComputeProvider, ApiType.BLOBSTORE)), 0); } - @Test - @Deprecated - public void testBoundedByIso3166CodeDeprecated() { - // Test filtering by ISO 3166 code alone - assertEquals(Iterables.size(Providers.boundedByIso3166Code("US-CA")), 2); - assertEquals(Iterables.size(Providers.boundedByIso3166Code("US-FL")), 1); - assertEquals(Iterables.size(Providers.boundedByIso3166Code("US")), 2); - assertEquals(Iterables.size(Providers.boundedByIso3166Code("JP-13")), 1); - assertEquals(Iterables.size(Providers.boundedByIso3166Code("JP")), 1); - assertEquals(Iterables.size(Providers.boundedByIso3166Code("FAKE-CODE")), 0); - - // Test filtering by ISO 3166 code and type - assertEquals(Iterables.size(Providers.boundedByIso3166Code("US-CA", ProviderMetadata.BLOBSTORE_TYPE)), 1); - assertEquals(Iterables.size(Providers.boundedByIso3166Code("US-CA", ProviderMetadata.COMPUTE_TYPE)), 1); - assertEquals(Iterables.size(Providers.boundedByIso3166Code("US-FL", ProviderMetadata.BLOBSTORE_TYPE)), 1); - assertEquals(Iterables.size(Providers.boundedByIso3166Code("US-FL", ProviderMetadata.COMPUTE_TYPE)), 0); - assertEquals(Iterables.size(Providers.boundedByIso3166Code("US", ProviderMetadata.BLOBSTORE_TYPE)), 1); - assertEquals(Iterables.size(Providers.boundedByIso3166Code("US", ProviderMetadata.COMPUTE_TYPE)), 1); - assertEquals(Iterables.size(Providers.boundedByIso3166Code("FAKE-CODE", ProviderMetadata.BLOBSTORE_TYPE)), 0); - assertEquals(Iterables.size(Providers.boundedByIso3166Code("FAKE-CODE", ProviderMetadata.COMPUTE_TYPE)), 0); - } - - @Test - @Deprecated - public void testCollocatedWithDeprecated() { - // Test filtering by collocation alone - assertEquals(Iterables.size(Providers.collocatedWith(testBlobstoreProvider)), 1); - assertEquals(Iterables.size(Providers.collocatedWith(testComputeProvider)), 1); - assertEquals(Iterables.size(Providers.collocatedWith(testYetAnotherComputeProvider)), 0); - - // Test filtering by collocation and type - assertEquals(Iterables.size(Providers.collocatedWith(testBlobstoreProvider, ProviderMetadata.BLOBSTORE_TYPE)), 0); - assertEquals(Iterables.size(Providers.collocatedWith(testBlobstoreProvider, ProviderMetadata.COMPUTE_TYPE)), 1); - assertEquals(Iterables.size(Providers.collocatedWith(testComputeProvider, ProviderMetadata.COMPUTE_TYPE)), 0); - assertEquals(Iterables.size(Providers.collocatedWith(testComputeProvider, ProviderMetadata.BLOBSTORE_TYPE)), 1); - assertEquals( - Iterables.size(Providers.collocatedWith(testYetAnotherComputeProvider, ProviderMetadata.COMPUTE_TYPE)), 0); - assertEquals( - Iterables.size(Providers.collocatedWith(testYetAnotherComputeProvider, ProviderMetadata.BLOBSTORE_TYPE)), 0); - } } diff --git a/core/src/test/java/org/jclouds/providers/BaseProviderMetadataTest.java b/core/src/test/java/org/jclouds/providers/internal/BaseProviderMetadataTest.java similarity index 80% rename from core/src/test/java/org/jclouds/providers/BaseProviderMetadataTest.java rename to core/src/test/java/org/jclouds/providers/internal/BaseProviderMetadataTest.java index 9c27af317f..23ba372edf 100644 --- a/core/src/test/java/org/jclouds/providers/BaseProviderMetadataTest.java +++ b/core/src/test/java/org/jclouds/providers/internal/BaseProviderMetadataTest.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.jclouds.providers; +package org.jclouds.providers.internal; import static com.google.common.base.Preconditions.checkNotNull; import static org.testng.Assert.assertEquals; @@ -25,16 +25,20 @@ import java.util.logging.Logger; import org.jclouds.apis.ApiMetadata; import org.jclouds.apis.ApiType; +import org.jclouds.providers.ProviderMetadata; +import org.jclouds.providers.Providers; import org.testng.annotations.Test; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; +import com.google.common.reflect.TypeToken; /** * * @author Jeremy Whitlock */ @Test(groups = "unit") +@SuppressWarnings("rawtypes") public abstract class BaseProviderMetadataTest { private final ProviderMetadata toTest; @@ -49,34 +53,35 @@ public abstract class BaseProviderMetadataTest { @Test public void testWithId() { - ProviderMetadata providerMetadata = Providers.withId(toTest.getId()); + ProviderMetadata providerMetadata = Providers.withId(toTest.getId()); assertEquals(toTest, providerMetadata); assert providerMetadata.getLinkedServices().contains(toTest.getId()); } - + @Test public void testOfApiContains() { if (expectedApi == null) Logger.getAnonymousLogger().warning("please update your test class"); - ImmutableSet ofApi = ImmutableSet.copyOf(Providers.ofApi(expectedApi)); + ImmutableSet> ofApi = ImmutableSet.copyOf(Providers.apiMetadataAssignableFrom(TypeToken.of(expectedApi.getClass()))); assert ofApi.contains(toTest) : String.format("%s not found in %s", toTest, ofApi); } // it is ok to have multiple services in the same classpath (ex. ec2 vs elb) @Test public void testOfTypeContains() { - ImmutableSet ofType = ImmutableSet.copyOf(Providers.ofType(expectedType)); + ImmutableSet> ofType = ImmutableSet.copyOf(Providers.ofType(expectedType)); assert ofType.contains(toTest) : String.format("%s not found in %s", toTest, ofType); } @Test public void testAllContains() { - ImmutableSet all = ImmutableSet.copyOf(Providers.all()); + ImmutableSet> all = ImmutableSet.copyOf(Providers.all()); assert all.contains(toTest) : String.format("%s not found in %s", toTest, all); } @Test + @Deprecated public void testInRestProperties() { Iterable providers = org.jclouds.rest.Providers.getSupportedProviders(); assert Iterables.contains(providers, toTest.getId()) : providers; diff --git a/core/src/test/java/org/jclouds/rest/BaseRestClientLiveTest.java b/core/src/test/java/org/jclouds/rest/BaseRestClientLiveTest.java deleted file mode 100644 index 4df6e584b0..0000000000 --- a/core/src/test/java/org/jclouds/rest/BaseRestClientLiveTest.java +++ /dev/null @@ -1,81 +0,0 @@ -/** - * 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.rest; - -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.base.Strings.emptyToNull; - -import java.util.Properties; - -import org.jclouds.Constants; -import org.testng.annotations.BeforeClass; - -/** - * - * @author Adrian Cole - */ -public abstract class BaseRestClientLiveTest { - protected String prefix = System.getProperty("user.name"); - - protected String provider; - protected String identity; - protected String credential; - protected String endpoint; - protected String apiVersion; - protected String buildVersion; - - protected Properties setupRestProperties() { - return RestContextFactory.getPropertiesFromResource("/rest.properties"); - } - - protected Properties setupProperties() { - - if (emptyToNull(provider) == null) - throw new NullPointerException("provider must not be null or empty:" + provider); - if (emptyToNull(identity) == null) - throw new NullPointerException("identity must not be null or empty:" + provider); - - Properties overrides = new Properties(); - overrides.setProperty(Constants.PROPERTY_TRUST_ALL_CERTS, "true"); - overrides.setProperty(Constants.PROPERTY_RELAX_HOSTNAME, "true"); - - overrides.setProperty(provider + ".identity", identity); - - if (credential != null) - overrides.setProperty(provider + ".credential", credential); - if (endpoint != null) - overrides.setProperty(provider + ".endpoint", endpoint); - if (apiVersion != null) - overrides.setProperty(provider + ".api-version", apiVersion); - if (buildVersion != null) - overrides.setProperty(provider + ".build-version", buildVersion); - - return overrides; - } - - @BeforeClass - protected void setupCredentials() { - identity = checkNotNull(System.getProperty("test." + provider + ".identity"), "test." + provider + ".identity"); - credential = System.getProperty("test." + provider + ".credential"); - endpoint = System.getProperty("test." + provider + ".endpoint"); - apiVersion = System.getProperty("test." + provider + ".api-version"); - buildVersion = System.getProperty("test." + provider + ".build-version"); - } - -} diff --git a/core/src/test/java/org/jclouds/rest/InputParamValidatorTest.java b/core/src/test/java/org/jclouds/rest/InputParamValidatorTest.java index 108f14ff45..2fc944b0ab 100644 --- a/core/src/test/java/org/jclouds/rest/InputParamValidatorTest.java +++ b/core/src/test/java/org/jclouds/rest/InputParamValidatorTest.java @@ -18,9 +18,6 @@ */ package org.jclouds.rest; -import static org.jclouds.rest.RestContextFactory.contextSpec; -import static org.jclouds.rest.RestContextFactory.createContextBuilder; - import java.lang.reflect.Method; import java.util.concurrent.TimeUnit; @@ -33,6 +30,7 @@ import org.jclouds.http.IntegrationTestClient; import org.jclouds.predicates.validators.AllLowerCaseValidator; import org.jclouds.rest.annotations.ParamValidators; import org.jclouds.rest.annotations.SkipEncoding; +import org.jclouds.rest.internal.ContextBuilder; import org.jclouds.rest.internal.RestAnnotationProcessor; import org.testng.TestException; import org.testng.annotations.BeforeClass; @@ -139,12 +137,10 @@ public class InputParamValidatorTest { @BeforeClass void setupFactory() { - - RestContextSpec contextSpec = contextSpec("test", - "http://localhost:9999", "1", "", "", "userFoo", null, IntegrationTestClient.class, - IntegrationTestAsyncClient.class); - - injector = createContextBuilder(contextSpec).buildInjector(); + injector = ContextBuilder + .newBuilder( + AnonymousProviderMetadata.forClientMappedToAsyncClientOnEndpoint(IntegrationTestClient.class, IntegrationTestAsyncClient.class, + "http://localhost:9999")).buildInjector(); } diff --git a/core/src/test/java/org/jclouds/rest/RestContextFactoryTest.java b/core/src/test/java/org/jclouds/rest/RestContextFactoryTest.java deleted file mode 100644 index 3dcfdd8ce5..0000000000 --- a/core/src/test/java/org/jclouds/rest/RestContextFactoryTest.java +++ /dev/null @@ -1,292 +0,0 @@ -/** - * 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.rest; - -import static org.jclouds.rest.RestContextFactory.contextSpec; -import static org.jclouds.rest.RestContextFactory.createContextBuilder; -import static org.testng.Assert.assertEquals; - -import java.io.File; -import java.io.IOException; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.Properties; - -import org.jclouds.PropertiesBuilder; -import org.jclouds.http.IntegrationTestAsyncClient; -import org.jclouds.http.IntegrationTestClient; -import org.jclouds.http.RequiresHttp; -import org.jclouds.rest.config.RestClientModule; -import org.testng.annotations.Test; - -import com.google.common.base.Charsets; -import com.google.common.collect.Iterables; -import com.google.common.io.Files; -import com.google.inject.AbstractModule; -import com.google.inject.Module; - -/** - * - * @author Adrian Cole - */ -@Test(groups = "unit") -public class RestContextFactoryTest { - - private static final String provider = "test"; - - public void testBuilder() { - RestContextSpec contextSpec = contextSpec(provider, - "http://localhost", "1", "", "", "dummy", null, IntegrationTestClient.class, - IntegrationTestAsyncClient.class); - - createContextBuilder(contextSpec); - } - - public void testBuilderPropertiesWithIso3166() { - RestContextSpec contextSpec = contextSpec(provider, - "http://localhost", "1", "build-foo", "US-CA", "dummy", null, IntegrationTestClient.class, - IntegrationTestAsyncClient.class); - - Properties props = RestContextFactory.toProperties(contextSpec); - assertEquals(props.getProperty("test.endpoint"), "http://localhost"); - assertEquals(props.getProperty("test.api-version"), "1"); - assertEquals(props.getProperty("test.build-version"), "build-foo"); - assertEquals(props.getProperty("test.identity"), "dummy"); - assertEquals(props.getProperty("test.iso3166-codes"), "US-CA"); - assertEquals(props.getProperty("test.credential"), null); - assertEquals(props.getProperty("test.sync"), IntegrationTestClient.class.getName()); - assertEquals(props.getProperty("test.async"), IntegrationTestAsyncClient.class.getName()); - assertEquals(props.getProperty("test.propertiesbuilder"), null); - assertEquals(props.getProperty("test.contextbuilder"), null); - assertEquals(props.getProperty("test.modules"), null); - - new RestContextFactory().createContext(provider, props); - } - - public void testBuilderPropertiesWithCredential() { - RestContextSpec contextSpec = contextSpec(provider, - "http://localhost", "1", "build-foo", "", "dummy", "credential", IntegrationTestClient.class, - IntegrationTestAsyncClient.class); - - Properties props = RestContextFactory.toProperties(contextSpec); - assertEquals(props.getProperty("test.endpoint"), "http://localhost"); - assertEquals(props.getProperty("test.api-version"), "1"); - assertEquals(props.getProperty("test.build-version"), "build-foo"); - assertEquals(props.getProperty("test.identity"), "dummy"); - assertEquals(props.getProperty("test.credential"), "credential"); - assertEquals(props.getProperty("test.sync"), IntegrationTestClient.class.getName()); - assertEquals(props.getProperty("test.async"), IntegrationTestAsyncClient.class.getName()); - assertEquals(props.getProperty("test.propertiesbuilder"), null); - assertEquals(props.getProperty("test.contextbuilder"), null); - assertEquals(props.getProperty("test.modules"), null); - - new RestContextFactory().createContext(provider, props); - } - - @SuppressWarnings("unchecked") - public void testBuilderPropertiesWithContextBuilder() { - @SuppressWarnings("rawtypes") - RestContextSpec contextSpec = contextSpec(provider, - "http://localhost", "1", "build-foo", "", "dummy", null, (Class) null, (Class) null, PropertiesBuilder.class, - (Class) IntegrationTestContextBuilder.class, Collections.EMPTY_LIST); - - Properties props = RestContextFactory.toProperties(contextSpec); - assertEquals(props.getProperty("test.endpoint"), "http://localhost"); - assertEquals(props.getProperty("test.api-version"), "1"); - assertEquals(props.getProperty("test.build-version"), "build-foo"); - assertEquals(props.getProperty("test.identity"), "dummy"); - assertEquals(props.getProperty("test.credential"), null); - assertEquals(props.getProperty("test.sync"), null); - assertEquals(props.getProperty("test.async"), null); - assertEquals(props.getProperty("test.propertiesbuilder"), PropertiesBuilder.class.getName()); - assertEquals(props.getProperty("test.contextbuilder"), IntegrationTestContextBuilder.class.getName()); - assertEquals(props.getProperty("test.modules"), null); - - new RestContextFactory().createContext(provider, props); - } - - @SuppressWarnings("unchecked") - public void testBuilderPropertiesWithModule() { - @SuppressWarnings("rawtypes") - RestContextSpec contextSpec = contextSpec(provider, - "http://localhost", "1", "build-foo", "", "dummy", null, (Class) null, (Class) null, PropertiesBuilder.class, - (Class) IntegrationTestContextBuilder.class, Collections. singleton(new A())); - - Properties props = RestContextFactory.toProperties(contextSpec); - assertEquals(props.getProperty("test.endpoint"), "http://localhost"); - assertEquals(props.getProperty("test.api-version"), "1"); - assertEquals(props.getProperty("test.build-version"), "build-foo"); - assertEquals(props.getProperty("test.identity"), "dummy"); - assertEquals(props.getProperty("test.credential"), null); - assertEquals(props.getProperty("test.sync"), null); - assertEquals(props.getProperty("test.async"), null); - assertEquals(props.getProperty("test.propertiesbuilder"), PropertiesBuilder.class.getName()); - assertEquals(props.getProperty("test.contextbuilder"), IntegrationTestContextBuilder.class.getName()); - assertEquals(props.getProperty("test.modules"), "org.jclouds.rest.RestContextFactoryTest$A"); - - new RestContextFactory().createContext(provider, props); - } - - @SuppressWarnings("unchecked") - public void testBuilderPropertiesWithModules() { - @SuppressWarnings("rawtypes") - RestContextSpec contextSpec = contextSpec(provider, - "http://localhost", "1", "build-foo", "", "dummy", null, (Class) null, (Class) null, PropertiesBuilder.class, - (Class) IntegrationTestContextBuilder.class, Arrays. asList(new A(), new B())); - - Properties props = RestContextFactory.toProperties(contextSpec); - assertEquals(props.getProperty("test.endpoint"), "http://localhost"); - assertEquals(props.getProperty("test.api-version"), "1"); - assertEquals(props.getProperty("test.build-version"), "build-foo"); - assertEquals(props.getProperty("test.identity"), "dummy"); - assertEquals(props.getProperty("test.credential"), null); - assertEquals(props.getProperty("test.sync"), null); - assertEquals(props.getProperty("test.async"), null); - assertEquals(props.getProperty("test.propertiesbuilder"), PropertiesBuilder.class.getName()); - assertEquals(props.getProperty("test.contextbuilder"), IntegrationTestContextBuilder.class.getName()); - assertEquals(props.getProperty("test.modules"), - "org.jclouds.rest.RestContextFactoryTest$A,org.jclouds.rest.RestContextFactoryTest$B"); - - new RestContextFactory().createContext(provider, props); - } - - public void testBuilderPropertiesJCloudsScope() { - Properties props = new Properties(); - props.setProperty("test.endpoint", "http://localhost"); - props.setProperty("test.api-version", "1"); - props.setProperty("test.build-version", "build-foo"); - props.setProperty("test.iso3166-codes", "US"); - props.setProperty("jclouds.identity", "foo"); - props.setProperty("jclouds.credential", "bar"); - - props.setProperty("test.propertiesbuilder", PropertiesBuilder.class.getName()); - props.setProperty("test.contextbuilder", IntegrationTestContextBuilder.class.getName()); - props.setProperty("jclouds.modules", - "org.jclouds.rest.RestContextFactoryTest$A,org.jclouds.rest.RestContextFactoryTest$B"); - - new RestContextFactory() { - - @SuppressWarnings("hiding") - @Override - public RestContextSpec createContextSpec(String providerName, String identity, String credential, - Iterable wiring, Properties _overrides) { - RestContextSpec spec = super - .createContextSpec(providerName, identity, credential, wiring, _overrides); - assertEquals(spec.iso3166Codes, "US"); - assertEquals(spec.identity, "foo"); - assertEquals(spec.credential, "bar"); - assertEquals(spec.apiVersion, "1"); - assertEquals(spec.buildVersion, "build-foo"); - assertEquals(Iterables.size(spec.modules), 2); - return spec; - } - - }.createContext(provider, props); - } - - public void testBuilderPropertiesJCloudsScopeWithProviderIdentityAndFileCredential() throws IOException { - - File file = File.createTempFile("foo", "bar"); - file.deleteOnExit(); - Files.write("bar", file, Charsets.UTF_8); - Properties props = new Properties(); - props.setProperty("test.endpoint", "http://localhost"); - props.setProperty("test.api-version", "1"); - props.setProperty("test.build-version", "build-foo"); - props.setProperty("test.iso3166-codes", "US"); - props.setProperty("test.identity", "foo"); - props.setProperty("test.credential.file", file.getAbsolutePath()); - - props.setProperty("test.propertiesbuilder", PropertiesBuilder.class.getName()); - props.setProperty("test.contextbuilder", IntegrationTestContextBuilder.class.getName()); - props.setProperty("jclouds.modules", - "org.jclouds.rest.RestContextFactoryTest$A,org.jclouds.rest.RestContextFactoryTest$B"); - - new RestContextFactory() { - - @SuppressWarnings("hiding") - @Override - public RestContextSpec createContextSpec(String providerName, String identity, String credential, - Iterable wiring, Properties _overrides) { - RestContextSpec spec = super - .createContextSpec(providerName, identity, credential, wiring, _overrides); - assertEquals(spec.iso3166Codes, "US"); - assertEquals(spec.identity, "foo"); - assertEquals(spec.credential, "bar"); - assertEquals(spec.apiVersion, "1"); - assertEquals(spec.buildVersion, "build-foo"); - assertEquals(Iterables.size(spec.modules), 2); - return spec; - } - - }.createContext(provider, props); - } - - public static class A extends AbstractModule { - - @Override - protected void configure() { - - } - - } - - public static class B extends AbstractModule { - - @Override - protected void configure() { - - } - - } - - @SuppressWarnings("unchecked") - @Test(expectedExceptions = IllegalArgumentException.class) - public void testBuilderPropertiesWithWrongConfig() { - @SuppressWarnings( { "unused", "rawtypes" }) - RestContextSpec contextSpec = contextSpec(provider, - "http://localhost", "1", "build-foo", "", "dummy", null, (Class) null, (Class) null, - (Class) IntegrationTestContextBuilder.class, (Class) PropertiesBuilder.class, Collections.EMPTY_LIST); - } - - @RequiresHttp - @ConfiguresRestClient - public static class IntegrationTestRestClientModule extends - RestClientModule { - - public IntegrationTestRestClientModule() { - super(IntegrationTestClient.class, IntegrationTestAsyncClient.class); - } - - } - - public static class IntegrationTestContextBuilder extends - RestContextBuilder { - - public IntegrationTestContextBuilder(Properties props) { - super(IntegrationTestClient.class, IntegrationTestAsyncClient.class, props); - } - - protected void addClientModule(List modules) { - modules.add(new IntegrationTestRestClientModule()); - } - - } -} diff --git a/core/src/test/java/org/jclouds/rest/RestClientTest.java b/core/src/test/java/org/jclouds/rest/internal/BaseAsyncClientTest.java similarity index 60% rename from core/src/test/java/org/jclouds/rest/RestClientTest.java rename to core/src/test/java/org/jclouds/rest/internal/BaseAsyncClientTest.java index f8124e7c81..712785970a 100644 --- a/core/src/test/java/org/jclouds/rest/RestClientTest.java +++ b/core/src/test/java/org/jclouds/rest/internal/BaseAsyncClientTest.java @@ -16,23 +16,24 @@ * specific language governing permissions and limitations * under the License. */ -package org.jclouds.rest; +package org.jclouds.rest.internal; -import static org.jclouds.rest.RestContextFactory.createContextBuilder; +import static com.google.common.base.Preconditions.checkNotNull; import java.io.IOException; import java.util.Properties; +import org.jclouds.apis.ApiMetadata; import org.jclouds.http.HttpRequest; import org.jclouds.http.functions.ParseSax; import org.jclouds.logging.config.NullLoggingModule; -import org.jclouds.rest.BaseRestClientExpectTest.RegisterContext; -import org.jclouds.rest.internal.RestAnnotationProcessor; +import org.jclouds.providers.ProviderMetadata; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import com.google.common.collect.ImmutableSet; import com.google.inject.Binder; +import com.google.inject.Injector; import com.google.inject.Key; import com.google.inject.Module; import com.google.inject.TypeLiteral; @@ -42,7 +43,7 @@ import com.google.inject.TypeLiteral; * @author Adrian Cole */ @Test(groups = "unit") -public abstract class RestClientTest extends BaseRestClientTest { +public abstract class BaseAsyncClientTest extends BaseRestClientTest { protected RestAnnotationProcessor processor; @@ -50,8 +51,6 @@ public abstract class RestClientTest extends BaseRestClientTest { protected abstract void checkFilters(HttpRequest request); - abstract public RestContextSpec createContextSpec(); - protected Module createModule() { return new Module() { @@ -65,21 +64,39 @@ public abstract class RestClientTest extends BaseRestClientTest { @BeforeClass protected void setupFactory() throws IOException { - RestContextSpec contextSpec = createContextSpec(); - - injector = createContextBuilder(contextSpec, - ImmutableSet.of(new MockModule(), new NullLoggingModule(), createModule()), setupProperties()) - .buildInjector(); + injector = createInjector(); parserFactory = injector.getInstance(ParseSax.Factory.class); processor = injector.getInstance(Key.get(createTypeLiteral())); } - + + protected String identity = "identity"; + protected String credential = "credential"; + /** - * override this when the provider or api is not located in rest.properties and you are not using - * the {@link RegisterContext} annotation on your tests. + * @see org.jclouds.providers.Providers#withId */ - protected Properties setupRestProperties() { - return RestContextFactory.getPropertiesFromResource("/rest.properties"); + protected ProviderMetadata createProviderMetadata() { + return null; + } + + /** + * @see org.jclouds.apis.Apis#withId + */ + protected ApiMetadata createApiMetadata() { + return null; + } + + protected Injector createInjector() { + ProviderMetadata pm = createProviderMetadata(); + + @SuppressWarnings("unchecked") + ContextBuilder builder = pm != null ? ContextBuilder.newBuilder(pm) : ContextBuilder + .newBuilder(ApiMetadata.class.cast(checkNotNull(createApiMetadata(), + "either createApiMetadata or createProviderMetadata must be overridden"))); + + return builder.credentials(identity, credential) + .modules(ImmutableSet.of(new MockModule(), new NullLoggingModule(), createModule())) + .overrides(setupProperties()).buildInjector(); } /** diff --git a/core/src/test/java/org/jclouds/rest/internal/BaseContextLiveTest.java b/core/src/test/java/org/jclouds/rest/internal/BaseContextLiveTest.java new file mode 100644 index 0000000000..f28aa0bd87 --- /dev/null +++ b/core/src/test/java/org/jclouds/rest/internal/BaseContextLiveTest.java @@ -0,0 +1,143 @@ +/** + * 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.rest.internal; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.io.Closeable; +import java.util.NoSuchElementException; +import java.util.Properties; +import java.util.logging.Logger; + +import org.jclouds.Constants; +import org.jclouds.apis.ApiMetadata; +import org.jclouds.apis.Apis; +import org.jclouds.logging.LoggingModules; +import org.jclouds.logging.config.LoggingModule; +import org.jclouds.providers.ProviderMetadata; +import org.jclouds.providers.Providers; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; + +import com.google.common.collect.ImmutableSet; +import com.google.common.io.Closeables; +import com.google.inject.Module; + +/** + * + * @author Adrian Cole + */ +public abstract class BaseContextLiveTest { + protected String prefix = System.getProperty("user.name"); + protected String provider; + + protected volatile C context; + + protected Properties setupProperties() { + Properties overrides = new Properties(); + overrides.setProperty(Constants.PROPERTY_TRUST_ALL_CERTS, "true"); + overrides.setProperty(Constants.PROPERTY_RELAX_HOSTNAME, "true"); + setIfTestSystemPropertyPresent(overrides, provider + ".identity"); + setIfTestSystemPropertyPresent(overrides, provider + ".credential"); + setIfTestSystemPropertyPresent(overrides, provider + ".endpoint"); + setIfTestSystemPropertyPresent(overrides, provider + ".api-version"); + setIfTestSystemPropertyPresent(overrides, provider + ".build-version"); + return overrides; + } + + protected String setIfTestSystemPropertyPresent(Properties overrides, String key) { + if (System.getProperties().containsKey("test." + key)) { + String val = System.getProperty("test." + key); + overrides.setProperty(key, val); + } + return null; + } + + @BeforeClass(groups = { "integration", "live" }) + public void setupContext() { + initializeContext(); + } + + protected void initializeContext() { + if (context != null) + Closeables.closeQuietly(context); + context = createContext(setupProperties(), setupModules()); + } + + protected Iterable setupModules() { + return ImmutableSet. of(getLoggingModule()); + } + + protected LoggingModule getLoggingModule() { + return LoggingModules.firstOrJDKLoggingModule(); + } + + /** + * @see org.jclouds.providers.Providers#withId + */ + @SuppressWarnings("unchecked") + protected ProviderMetadata createProviderMetadata() { + try { + return (ProviderMetadata) Providers.withId(provider); + } catch (NoSuchElementException e) { + return null; + } + } + + /** + * @see org.jclouds.apis.Apis#withId + */ + @SuppressWarnings("unchecked") + protected ApiMetadata createApiMetadata() { + try { + return (ApiMetadata) Apis.withId(provider); + } catch (NoSuchElementException e) { + return null; + } + } + + protected C createContext(Properties props, Iterable modules) { + return newBuilder().modules(modules).overrides(props).build(); + } + + @SuppressWarnings("unchecked") + protected ContextBuilder newBuilder() { + if (provider != null) + try { + return (ContextBuilder) ContextBuilder.newBuilder(provider); + } catch (NoSuchElementException e){ + Logger.getAnonymousLogger() + .warning("provider [" + + provider + + "] is not setup as META-INF/services/org.jclouds.apis.ApiMetadata or META-INF/services/org.jclouds.providers.ProviderMetadata"); + } + + ProviderMetadata pm = createProviderMetadata(); + + ContextBuilder builder = pm != null ? ContextBuilder.newBuilder(pm) : ContextBuilder + .newBuilder(ApiMetadata.class.cast(checkNotNull(createApiMetadata(), + "either createApiMetadata or createProviderMetadata must be overridden"))); + return builder; + } + + @AfterClass(groups = { "integration", "live" }) + protected void tearDownContext() { + Closeables.closeQuietly(context); + } +} diff --git a/core/src/test/java/org/jclouds/rest/BaseRestClientExpectTest.java b/core/src/test/java/org/jclouds/rest/internal/BaseRestClientExpectTest.java similarity index 90% rename from core/src/test/java/org/jclouds/rest/BaseRestClientExpectTest.java rename to core/src/test/java/org/jclouds/rest/internal/BaseRestClientExpectTest.java index 24583c4931..21c0f2e7c7 100644 --- a/core/src/test/java/org/jclouds/rest/BaseRestClientExpectTest.java +++ b/core/src/test/java/org/jclouds/rest/internal/BaseRestClientExpectTest.java @@ -16,24 +16,20 @@ * specific language governing permissions and limitations * under the License. */ -package org.jclouds.rest; +package org.jclouds.rest.internal; import static com.google.common.base.Preconditions.checkNotNull; -import static java.lang.annotation.ElementType.TYPE; -import static java.lang.annotation.RetentionPolicy.RUNTIME; -import static org.jclouds.rest.RestContextFactory.contextSpec; -import static org.jclouds.rest.RestContextFactory.createContext; import static org.testng.Assert.assertEquals; import java.io.IOException; -import java.lang.annotation.Retention; -import java.lang.annotation.Target; import java.util.List; import java.util.Map; +import java.util.NoSuchElementException; import java.util.Map.Entry; import java.util.Properties; import java.util.concurrent.ExecutorService; import java.util.concurrent.atomic.AtomicInteger; +import java.util.logging.Logger; import javax.inject.Inject; import javax.inject.Named; @@ -46,6 +42,7 @@ import org.custommonkey.xmlunit.DifferenceListener; import org.custommonkey.xmlunit.NodeDetail; import org.custommonkey.xmlunit.XMLUnit; import org.jclouds.Constants; +import org.jclouds.apis.ApiMetadata; import org.jclouds.concurrent.MoreExecutors; import org.jclouds.concurrent.SingleThreaded; import org.jclouds.concurrent.config.ConfiguresExecutorService; @@ -62,6 +59,7 @@ import org.jclouds.http.internal.HttpWire; import org.jclouds.io.Payload; import org.jclouds.io.Payloads; import org.jclouds.logging.config.NullLoggingModule; +import org.jclouds.providers.ProviderMetadata; import org.jclouds.util.Strings2; import org.testng.annotations.Test; import org.w3c.dom.Node; @@ -78,6 +76,7 @@ import com.google.gson.JsonElement; import com.google.gson.JsonParser; import com.google.inject.AbstractModule; import com.google.inject.Binder; +import com.google.inject.Injector; import com.google.inject.Module; import com.google.inject.TypeLiteral; import com.google.inject.name.Names; @@ -109,16 +108,6 @@ import com.google.inject.name.Names; @Test(groups = "unit") @Beta public abstract class BaseRestClientExpectTest { - /** - * only needed when the client is simple and not registered fn rest.properties - */ - @Target(TYPE) - @Retention(RUNTIME) - public static @interface RegisterContext { - Class sync(); - - Class async(); - } protected String provider = "mock"; @@ -500,38 +489,64 @@ public abstract class BaseRestClientExpectTest { } + @SuppressWarnings("unchecked") public S createClient(Function fn, Module module, Properties props) { - RestContextSpec contextSpec = makeContextSpec(); - - return createContext(contextSpec, - ImmutableSet. of(new ExpectModule(fn), new NullLoggingModule(), module), props).getApi(); + return (S) createInjector(fn, module, props).getInstance(api); } protected String identity = "identity"; protected String credential = "credential"; - - private RestContextSpec makeContextSpec() { - if (getClass().isAnnotationPresent(RegisterContext.class)) - return (RestContextSpec) contextSpec(provider, "http://mock", "1", "", "", "userfoo", null, getClass() - .getAnnotation(RegisterContext.class).sync(), - getClass().getAnnotation(RegisterContext.class).async(), ImmutableSet. of()); - else - return new RestContextFactory(setupRestProperties()).createContextSpec(provider, identity, credential, - new Properties()); - } + protected Class api; /** - * override this when the provider or api is not located in rest.properties and you are not using - * the {@link RegisterContext} annotation on your tests. + * @see org.jclouds.providers.Providers#withId */ - protected Properties setupRestProperties() { - return RestContextFactory.getPropertiesFromResource("/rest.properties"); + protected ProviderMetadata createProviderMetadata() { + return null; } + + /** + * @see org.jclouds.apis.Apis#withId + */ + protected ApiMetadata createApiMetadata() { + return null; + } + + @SuppressWarnings("unchecked") + protected Injector createInjector(Function fn, Module module, Properties props) { + ContextBuilder builder = null; + if (provider != null) + try { + builder = ContextBuilder.newBuilder(provider).credentials(identity, credential); + } catch (NoSuchElementException e){ + Logger.getAnonymousLogger() + .warning("provider [" + + provider + + "] is not setup as META-INF/services/org.jclouds.apis.ApiMetadata or META-INF/services/org.jclouds.providers.ProviderMetadata"); + } + if (builder == null){ + ProviderMetadata pm = createProviderMetadata(); + ApiMetadata am = (pm != null) ? pm.getApiMetadata() : checkNotNull(createApiMetadata(), + "either createApiMetadata or createProviderMetadata must be overridden"); + + builder = pm != null ? ContextBuilder.newBuilder(pm) : ContextBuilder + .newBuilder(ApiMetadata.class.cast(am)); + } + + this.api = builder.getApiMetadata().getApi(); + + return builder.credentials(identity, credential) + .modules(ImmutableSet.of(new ExpectModule(fn), new NullLoggingModule(), module)) + .overrides(setupProperties()).buildInjector(); + } + /** * override this to supply context-specific parameters during tests. */ protected Properties setupProperties() { - return new Properties(); + Properties props = new Properties(); + props.put(Constants.PROPERTY_MAX_RETRIES, 1); + return props; } } \ No newline at end of file diff --git a/core/src/test/java/org/jclouds/rest/BaseRestClientTest.java b/core/src/test/java/org/jclouds/rest/internal/BaseRestClientTest.java similarity index 99% rename from core/src/test/java/org/jclouds/rest/BaseRestClientTest.java rename to core/src/test/java/org/jclouds/rest/internal/BaseRestClientTest.java index b6033a6673..cdee2c240b 100644 --- a/core/src/test/java/org/jclouds/rest/BaseRestClientTest.java +++ b/core/src/test/java/org/jclouds/rest/internal/BaseRestClientTest.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.jclouds.rest; +package org.jclouds.rest.internal; import static com.google.common.base.Throwables.propagate; import static com.google.inject.util.Types.newParameterizedType; diff --git a/core/src/test/java/org/jclouds/rest/RestContextBuilderTest.java b/core/src/test/java/org/jclouds/rest/internal/ContextBuilderTest.java similarity index 74% rename from core/src/test/java/org/jclouds/rest/RestContextBuilderTest.java rename to core/src/test/java/org/jclouds/rest/internal/ContextBuilderTest.java index 113be8c1cb..a2f6145493 100644 --- a/core/src/test/java/org/jclouds/rest/RestContextBuilderTest.java +++ b/core/src/test/java/org/jclouds/rest/internal/ContextBuilderTest.java @@ -16,23 +16,26 @@ * specific language governing permissions and limitations * under the License. */ -package org.jclouds.rest; +package org.jclouds.rest.internal; import static org.testng.Assert.assertEquals; import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import java.util.Properties; import org.jclouds.concurrent.config.ExecutorServiceModule; import org.jclouds.events.config.EventBusModule; +import org.jclouds.http.IntegrationTestAsyncClient; +import org.jclouds.http.IntegrationTestClient; import org.jclouds.http.RequiresHttp; import org.jclouds.http.config.ConfiguresHttpCommandExecutorService; import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule; import org.jclouds.logging.config.LoggingModule; import org.jclouds.logging.config.NullLoggingModule; import org.jclouds.logging.jdk.config.JDKLoggingModule; +import org.jclouds.rest.AnonymousProviderMetadata; +import org.jclouds.rest.ConfiguresRestClient; import org.jclouds.rest.config.CredentialStoreModule; import org.testng.annotations.Test; @@ -41,12 +44,12 @@ import com.google.inject.Binder; import com.google.inject.Module; /** - * Tests behavior of modules configured in RestContextBuilder + * Tests behavior of modules configured in ContextBuilder * * @author Adrian Cole */ -@Test(groups = "unit") -public class RestContextBuilderTest { +@Test(groups = "unit", testName="ContextBuilderTest") +public class ContextBuilderTest { @ConfiguresHttpCommandExecutorService static class HttpModule extends AbstractModule { @@ -57,13 +60,17 @@ public class RestContextBuilderTest { } } + private ContextBuilder testContextBuilder() { + return ContextBuilder.newBuilder(AnonymousProviderMetadata.forClientMappedToAsyncClientOnEndpoint( + IntegrationTestClient.class, IntegrationTestAsyncClient.class, "http://localhost")); + } + @Test public void testAddHttpModuleIfNotPresent() { List modules = new ArrayList(); HttpModule module = new HttpModule(); modules.add(module); - new RestContextBuilder(String.class, String.class, new Properties()) - .addHttpModuleIfNeededAndNotPresent(modules); + testContextBuilder().addHttpModuleIfNeededAndNotPresent(modules); assertEquals(modules.size(), 1); assertEquals(modules.remove(0), module); } @@ -73,8 +80,7 @@ public class RestContextBuilderTest { List modules = new ArrayList(); LoggingModule module = new NullLoggingModule(); modules.add(module); - new RestContextBuilder(String.class, String.class, new Properties()) - .addLoggingModuleIfNotPresent(modules); + testContextBuilder().addLoggingModuleIfNotPresent(modules); assertEquals(modules.size(), 1); assertEquals(modules.remove(0), module); } @@ -84,8 +90,7 @@ public class RestContextBuilderTest { List modules = new ArrayList(); EventBusModule module = new EventBusModule(); modules.add(module); - new RestContextBuilder(String.class, String.class, new Properties()) - .addEventBusIfNotPresent(modules); + testContextBuilder().addEventBusIfNotPresent(modules); assertEquals(modules.size(), 1); assertEquals(modules.remove(0), module); } @@ -95,8 +100,7 @@ public class RestContextBuilderTest { List modules = new ArrayList(); ExecutorServiceModule module = new ExecutorServiceModule(); modules.add(module); - new RestContextBuilder(String.class, String.class, new Properties()) - .addExecutorServiceIfNotPresent(modules); + testContextBuilder().addExecutorServiceIfNotPresent(modules); assertEquals(modules.size(), 1); assertEquals(modules.remove(0), module); } @@ -106,8 +110,7 @@ public class RestContextBuilderTest { List modules = new ArrayList(); CredentialStoreModule module = new CredentialStoreModule(); modules.add(module); - new RestContextBuilder(String.class, String.class, new Properties()) - .addCredentialStoreIfNotPresent(modules); + testContextBuilder().addCredentialStoreIfNotPresent(modules); assertEquals(modules.size(), 1); assertEquals(modules.remove(0), module); } @@ -119,8 +122,7 @@ public class RestContextBuilderTest { modules.add(loggingModule); HttpModule httpModule = new HttpModule(); modules.add(httpModule); - RestContextBuilder builder = new RestContextBuilder(String.class, String.class, - new Properties()); + ContextBuilder builder = testContextBuilder(); builder.addHttpModuleIfNeededAndNotPresent(modules); builder.addLoggingModuleIfNotPresent(modules); assertEquals(modules.size(), 2); @@ -131,18 +133,17 @@ public class RestContextBuilderTest { @Test public void testAddBothWhenDoesntRequireHttp() { List modules = new ArrayList(); - modules.add(new ConfiguresRestClientModule()); - RestContextBuilder builder = new RestContextBuilder(String.class, String.class, - new Properties()); + modules.add(new ConfiguresClientModule()); + ContextBuilder builder = testContextBuilder(); builder.addHttpModuleIfNeededAndNotPresent(modules); builder.addLoggingModuleIfNotPresent(modules); assertEquals(modules.size(), 2); - assert modules.remove(0) instanceof ConfiguresRestClientModule; + assert modules.remove(0) instanceof ConfiguresClientModule; assert modules.remove(0) instanceof JDKLoggingModule; } @ConfiguresRestClient - static class ConfiguresRestClientModule implements Module { + static class ConfiguresClientModule implements Module { public void configure(Binder arg0) { } @@ -152,8 +153,7 @@ public class RestContextBuilderTest { @Test public void testAddBothWhenDefault() { List modules = new ArrayList(); - RestContextBuilder builder = new RestContextBuilder(String.class, String.class, - new Properties()); + ContextBuilder builder = testContextBuilder(); builder.addHttpModuleIfNeededAndNotPresent(modules); builder.addLoggingModuleIfNotPresent(modules); assertEquals(modules.size(), 2); @@ -173,8 +173,7 @@ public class RestContextBuilderTest { public void testAddBothWhenLive() { List modules = new ArrayList(); modules.add(new RequiresHttpModule()); - RestContextBuilder builder = new RestContextBuilder(String.class, String.class, - new Properties()); + ContextBuilder builder = testContextBuilder(); builder.addHttpModuleIfNeededAndNotPresent(modules); builder.addLoggingModuleIfNotPresent(modules); assertEquals(modules.size(), 3); @@ -197,9 +196,8 @@ public class RestContextBuilderTest { protected void configure() { } }; - RestContextBuilder builder = new RestContextBuilder(String.class, String.class, - new Properties()); - builder.withModules(Arrays.asList(module1, module2)); + ContextBuilder builder = testContextBuilder(); + builder.modules(Arrays.asList(module1, module2)); } } diff --git a/core/src/test/java/org/jclouds/rest/internal/RestAnnotationProcessorTest.java b/core/src/test/java/org/jclouds/rest/internal/RestAnnotationProcessorTest.java index 52745c9e10..9432d41ef4 100644 --- a/core/src/test/java/org/jclouds/rest/internal/RestAnnotationProcessorTest.java +++ b/core/src/test/java/org/jclouds/rest/internal/RestAnnotationProcessorTest.java @@ -23,8 +23,6 @@ import static com.google.common.base.Preconditions.checkNotNull; import static org.jclouds.io.Payloads.calculateMD5; import static org.jclouds.io.Payloads.newInputStreamPayload; import static org.jclouds.io.Payloads.newStringPayload; -import static org.jclouds.rest.RestContextFactory.contextSpec; -import static org.jclouds.rest.RestContextFactory.createContextBuilder; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNull; @@ -102,12 +100,11 @@ import org.jclouds.io.PayloadEnclosing; import org.jclouds.io.Payloads; import org.jclouds.javax.annotation.Nullable; import org.jclouds.logging.config.NullLoggingModule; +import org.jclouds.rest.AnonymousProviderMetadata; import org.jclouds.rest.AsyncClientFactory; import org.jclouds.rest.AuthorizationException; -import org.jclouds.rest.BaseRestClientTest; import org.jclouds.rest.ConfiguresRestClient; import org.jclouds.rest.InvocationContext; -import org.jclouds.rest.RestContextSpec; import org.jclouds.rest.annotations.BinderParam; import org.jclouds.rest.annotations.Delegate; import org.jclouds.rest.annotations.Endpoint; @@ -422,21 +419,13 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest { } private Injector injectorForCaller(HttpCommandExecutorService service, Module... modules) { - - RestContextSpec contextSpec = contextSpec( - "test", - "http://localhost:9999", - "1", - "", - "", - "userfoo", - null, - Caller.class, - AsyncCaller.class, - ImmutableSet. builder().add(new MockModule(service)).add(new NullLoggingModule()) - .add(new CallerModule()).addAll(ImmutableSet. copyOf(modules)).build()); - - return createContextBuilder(contextSpec).buildInjector(); + return ContextBuilder + .newBuilder( + AnonymousProviderMetadata.forClientMappedToAsyncClientOnEndpoint(Caller.class, AsyncCaller.class, + "http://localhost:9999")) + .modules( + ImmutableSet. builder().add(new MockModule(service)).add(new NullLoggingModule()) + .add(new CallerModule()).addAll(ImmutableSet. copyOf(modules)).build()).buildInjector(); } @@ -2543,9 +2532,11 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest { @BeforeClass void setupFactory() { - RestContextSpec contextSpec = contextSpec("test", "http://localhost:9999", "1", "", "", - "userfoo", null, Callee.class, AsyncCallee.class, - ImmutableSet. of(new MockModule(), new NullLoggingModule(), new AbstractModule() { + injector = ContextBuilder + .newBuilder( + AnonymousProviderMetadata.forClientMappedToAsyncClientOnEndpoint(Callee.class, AsyncCallee.class, + "http://localhost:9999")) + .modules(ImmutableSet. of(new MockModule(), new NullLoggingModule(), new AbstractModule() { @Override protected void configure() { @@ -2565,9 +2556,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest { throw new AuthorizationException(); } - })); - - injector = createContextBuilder(contextSpec).buildInjector(); + })).buildInjector(); parserFactory = injector.getInstance(ParseSax.Factory.class); crypto = injector.getInstance(Crypto.class); } diff --git a/core/src/test/java/org/jclouds/util/ProvidersTest.java b/core/src/test/java/org/jclouds/util/ProvidersTest.java index 07866964bf..81ee659d3f 100644 --- a/core/src/test/java/org/jclouds/util/ProvidersTest.java +++ b/core/src/test/java/org/jclouds/util/ProvidersTest.java @@ -20,7 +20,6 @@ package org.jclouds.util; import static org.testng.Assert.assertEquals; -import org.jclouds.rest.Providers; import org.testng.annotations.Test; import com.google.common.collect.ImmutableSet; @@ -34,8 +33,9 @@ public class ProvidersTest { @Test public void testSupportedProviders() { - Iterable providers = Providers.getSupportedProviders(); - assertEquals(Sets.newLinkedHashSet(providers), ImmutableSet. of()); + Iterable providers = org.jclouds.rest.Providers.getSupportedProviders(); + assertEquals(Sets.newLinkedHashSet(providers), ImmutableSet. of("test-blobstore-api", "test-compute-api", + "test-yet-another-compute-api", "test-yet-another-compute-provider")); } } diff --git a/labs/aws-elb/src/main/java/org/jclouds/aws/elb/AWSELBPropertiesBuilder.java b/labs/aws-elb/src/main/java/org/jclouds/aws/elb/AWSELBPropertiesBuilder.java deleted file mode 100644 index f22894ab4e..0000000000 --- a/labs/aws-elb/src/main/java/org/jclouds/aws/elb/AWSELBPropertiesBuilder.java +++ /dev/null @@ -1,76 +0,0 @@ -/** - * 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.aws.elb; - -import static org.jclouds.Constants.PROPERTY_API_VERSION; -import static org.jclouds.Constants.PROPERTY_ENDPOINT; -import static org.jclouds.aws.domain.Region.AP_NORTHEAST_1; -import static org.jclouds.aws.domain.Region.AP_SOUTHEAST_1; -import static org.jclouds.aws.domain.Region.EU_WEST_1; -import static org.jclouds.aws.domain.Region.SA_EAST_1; -import static org.jclouds.aws.domain.Region.US_EAST_1; -import static org.jclouds.aws.domain.Region.US_WEST_1; -import static org.jclouds.aws.domain.Region.US_WEST_2; -import static org.jclouds.aws.reference.AWSConstants.PROPERTY_AUTH_TAG; -import static org.jclouds.aws.reference.AWSConstants.PROPERTY_ZONECLIENT_ENDPOINT; -import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGION; - -import java.util.Properties; - -import org.jclouds.aws.domain.Region; -import org.jclouds.elb.ELBAsyncClient; -import org.jclouds.elb.ELBPropertiesBuilder; - -/** - * Builds properties used in ELB Clients - * - * @author Adrian Cole - */ -public class AWSELBPropertiesBuilder extends ELBPropertiesBuilder { - - @Override - protected Properties defaultProperties() { - Properties properties = super.defaultProperties(); - properties.setProperty(PROPERTY_AUTH_TAG, "AWS"); - properties.putAll(Region.regionProperties()); - properties.setProperty(PROPERTY_API_VERSION, ELBAsyncClient.VERSION); - properties.setProperty(PROPERTY_ENDPOINT, "https://elasticloadbalancing.us-east-1.amazonaws.com"); - properties.setProperty(PROPERTY_REGION + "." + US_EAST_1 + ".endpoint", - "https://elasticloadbalancing.us-east-1.amazonaws.com"); - properties.setProperty(PROPERTY_REGION + "." + US_WEST_1 + ".endpoint", - "https://elasticloadbalancing.us-west-1.amazonaws.com"); - properties.setProperty(PROPERTY_REGION + "." + US_WEST_2 + ".endpoint", - "https://elasticloadbalancing.us-west-2.amazonaws.com"); - properties.setProperty(PROPERTY_REGION + "." + SA_EAST_1 + ".endpoint", - "https://elasticloadbalancing.sa-east-1.amazonaws.com"); - properties.setProperty(PROPERTY_REGION + "." + EU_WEST_1 + ".endpoint", - "https://elasticloadbalancing.eu-west-1.amazonaws.com"); - properties.setProperty(PROPERTY_REGION + "." + AP_SOUTHEAST_1 + ".endpoint", - "https://elasticloadbalancing.ap-southeast-1.amazonaws.com"); - properties.setProperty(PROPERTY_REGION + "." + AP_NORTHEAST_1 + ".endpoint", - "https://elasticloadbalancing.ap-northeast-1.amazonaws.com"); - properties.setProperty(PROPERTY_ZONECLIENT_ENDPOINT, "https://ec2.us-east-1.amazonaws.com"); - return properties; - } - - public AWSELBPropertiesBuilder(Properties properties) { - super(properties); - } - -} diff --git a/labs/aws-elb/src/main/java/org/jclouds/aws/elb/AWSELBProviderMetadata.java b/labs/aws-elb/src/main/java/org/jclouds/aws/elb/AWSELBProviderMetadata.java index 1c33e610a5..7878225240 100644 --- a/labs/aws-elb/src/main/java/org/jclouds/aws/elb/AWSELBProviderMetadata.java +++ b/labs/aws-elb/src/main/java/org/jclouds/aws/elb/AWSELBProviderMetadata.java @@ -18,10 +18,26 @@ */ package org.jclouds.aws.elb; -import java.net.URI; +import static org.jclouds.aws.domain.Region.AP_NORTHEAST_1; +import static org.jclouds.aws.domain.Region.AP_SOUTHEAST_1; +import static org.jclouds.aws.domain.Region.EU_WEST_1; +import static org.jclouds.aws.domain.Region.SA_EAST_1; +import static org.jclouds.aws.domain.Region.US_EAST_1; +import static org.jclouds.aws.domain.Region.US_WEST_1; +import static org.jclouds.aws.domain.Region.US_WEST_2; +import static org.jclouds.aws.reference.AWSConstants.PROPERTY_ZONECLIENT_ENDPOINT; +import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGION; +import java.net.URI; +import java.util.Properties; + +import org.jclouds.aws.domain.Region; import org.jclouds.elb.ELBApiMetadata; -import org.jclouds.providers.BaseProviderMetadata; +import org.jclouds.elb.ELBAsyncClient; +import org.jclouds.elb.ELBClient; +import org.jclouds.loadbalancer.LoadBalancerServiceContext; +import org.jclouds.providers.ProviderMetadata; +import org.jclouds.providers.internal.BaseProviderMetadata; /** * Implementation of @ link org.jclouds.types.ProviderMetadata} for Amazon's Elastic Load Balancing @@ -29,40 +45,65 @@ import org.jclouds.providers.BaseProviderMetadata; * * @author Adrian Cole */ -public class AWSELBProviderMetadata extends BaseProviderMetadata { - - public AWSELBProviderMetadata() { - this(builder() - .id("aws-elb") - .name("Amazon Elastic Load Balancing") - .api(new ELBApiMetadata()) - .homepage(URI.create("http://aws.amazon.com/elasticloadbalancing")) - .console(URI.create("https://console.aws.amazon.com/ec2/home")) - .linkedServices("aws-ec2","aws-elb", "aws-elb", "aws-s3", "aws-simpledb") - .iso3166Codes("US-VA", "US-CA", "BR-SP", "US-OR", "IE", "SG", "JP-13")); +public class AWSELBProviderMetadata extends BaseProviderMetadata, ELBApiMetadata> { + + public static Builder builder() { + return new Builder(); } - // below are so that we can reuse builders, toString, hashCode, etc. - // we have to set concrete classes here, as our base class cannot be - // concrete due to serviceLoader - protected AWSELBProviderMetadata(ConcreteBuilder builder) { + @Override + public Builder toBuilder() { + return Builder.class.cast(builder().fromProviderMetadata(this)); + } + + public AWSELBProviderMetadata() { + super(builder()); + } + + public AWSELBProviderMetadata(Builder builder) { super(builder); } - private static class ConcreteBuilder extends Builder { + protected static Properties defaultProperties() { + Properties properties = new Properties(); + properties.putAll(Region.regionProperties()); + properties.setProperty(PROPERTY_REGION + "." + US_EAST_1 + ".endpoint", + "https://elasticloadbalancing.us-east-1.amazonaws.com"); + properties.setProperty(PROPERTY_REGION + "." + US_WEST_1 + ".endpoint", + "https://elasticloadbalancing.us-west-1.amazonaws.com"); + properties.setProperty(PROPERTY_REGION + "." + US_WEST_2 + ".endpoint", + "https://elasticloadbalancing.us-west-2.amazonaws.com"); + properties.setProperty(PROPERTY_REGION + "." + SA_EAST_1 + ".endpoint", + "https://elasticloadbalancing.sa-east-1.amazonaws.com"); + properties.setProperty(PROPERTY_REGION + "." + EU_WEST_1 + ".endpoint", + "https://elasticloadbalancing.eu-west-1.amazonaws.com"); + properties.setProperty(PROPERTY_REGION + "." + AP_SOUTHEAST_1 + ".endpoint", + "https://elasticloadbalancing.ap-southeast-1.amazonaws.com"); + properties.setProperty(PROPERTY_REGION + "." + AP_NORTHEAST_1 + ".endpoint", + "https://elasticloadbalancing.ap-northeast-1.amazonaws.com"); + properties.setProperty(PROPERTY_ZONECLIENT_ENDPOINT, "https://ec2.us-east-1.amazonaws.com"); + return properties; + } + + public static class Builder extends BaseProviderMetadata.Builder, ELBApiMetadata> { + + protected Builder(){ + id("aws-elb") + .name("Amazon Elastic Load Balancing") + .endpoint("https://elasticloadbalancing.us-east-1.amazonaws.com") + .homepage(URI.create("http://aws.amazon.com/elasticloadbalancing")) + .console(URI.create("https://console.aws.amazon.com/ec2/home")) + .linkedServices("aws-ec2","aws-elb", "aws-cloudwatch", "aws-s3", "aws-simpledb") + .iso3166Codes("US-VA", "US-CA", "BR-SP", "US-OR", "IE", "SG", "JP-13") + .apiMetadata(new ELBApiMetadata()) + .defaultProperties(AWSELBProviderMetadata.defaultProperties()); + } @Override - public AWSELBProviderMetadata build() { - return new AWSELBProviderMetadata(this); + public Builder fromProviderMetadata( + ProviderMetadata, ELBApiMetadata> in) { + super.fromProviderMetadata(in); + return this; } } - - public static ConcreteBuilder builder() { - return new ConcreteBuilder(); - } - - public ConcreteBuilder toBuilder() { - return builder().fromProviderMetadata(this); - } - } \ No newline at end of file diff --git a/labs/aws-elb/src/test/java/org/jclouds/aws/elb/AWSELBAsyncClientTest.java b/labs/aws-elb/src/test/java/org/jclouds/aws/elb/AWSELBAsyncClientTest.java index 283c816719..d7d92addb9 100644 --- a/labs/aws-elb/src/test/java/org/jclouds/aws/elb/AWSELBAsyncClientTest.java +++ b/labs/aws-elb/src/test/java/org/jclouds/aws/elb/AWSELBAsyncClientTest.java @@ -24,6 +24,7 @@ import java.lang.reflect.Method; import org.jclouds.aws.domain.Region; import org.jclouds.elb.ELBAsyncClient; import org.jclouds.elb.ELBAsyncClientTest; +import org.jclouds.providers.ProviderMetadata; import org.testng.annotations.Test; /** @@ -35,15 +36,16 @@ import org.testng.annotations.Test; @Test(groups = "unit", testName = "AWSELBAsyncClientTest") public class AWSELBAsyncClientTest extends ELBAsyncClientTest { - public AWSELBAsyncClientTest() { - this.provider = "aws-elb"; - } - public void testAllRegions() throws SecurityException, NoSuchMethodException, IOException { Method method = ELBAsyncClient.class.getMethod("describeLoadBalancersInRegion", String.class, String[].class); for (String region : Region.DEFAULT_REGIONS) { processor.createRequest(method, region); } } + + @Override + public ProviderMetadata createProviderMetadata() { + return new AWSELBProviderMetadata(); + } } diff --git a/labs/aws-elb/src/test/java/org/jclouds/aws/elb/AWSELBClientLiveTest.java b/labs/aws-elb/src/test/java/org/jclouds/aws/elb/AWSELBClientLiveTest.java index 25bc4e26af..29172ff5e9 100644 --- a/labs/aws-elb/src/test/java/org/jclouds/aws/elb/AWSELBClientLiveTest.java +++ b/labs/aws-elb/src/test/java/org/jclouds/aws/elb/AWSELBClientLiveTest.java @@ -19,6 +19,8 @@ package org.jclouds.aws.elb; import org.jclouds.aws.domain.Region; +import org.jclouds.elb.ELBAsyncClient; +import org.jclouds.elb.ELBClient; import org.jclouds.elb.ELBClientLiveTest; import org.testng.annotations.Test; @@ -28,7 +30,7 @@ import org.testng.annotations.Test; * @author Adrian Cole */ @Test(groups = "live", singleThreaded = true, testName = "AWSELBClientLiveTest") -public class AWSELBClientLiveTest extends ELBClientLiveTest { +public class AWSELBClientLiveTest extends ELBClientLiveTest { public AWSELBClientLiveTest() { provider = "aws-elb"; } diff --git a/labs/aws-elb/src/test/java/org/jclouds/aws/elb/AWSELBProviderTest.java b/labs/aws-elb/src/test/java/org/jclouds/aws/elb/AWSELBProviderTest.java index 7c56d557ac..13a922b5d6 100644 --- a/labs/aws-elb/src/test/java/org/jclouds/aws/elb/AWSELBProviderTest.java +++ b/labs/aws-elb/src/test/java/org/jclouds/aws/elb/AWSELBProviderTest.java @@ -19,7 +19,9 @@ package org.jclouds.aws.elb; import org.jclouds.elb.ELBApiMetadata; -import org.jclouds.providers.BaseProviderMetadataTest; +import org.jclouds.elb.ELBAsyncClient; +import org.jclouds.elb.ELBClient; +import org.jclouds.providers.internal.BaseProviderMetadataTest; import org.testng.annotations.Test; /** @@ -31,6 +33,6 @@ import org.testng.annotations.Test; public class AWSELBProviderTest extends BaseProviderMetadataTest { public AWSELBProviderTest() { - super(new AWSELBProviderMetadata(), new ELBApiMetadata()); + super(new AWSELBProviderMetadata(), new ELBApiMetadata()); } } \ No newline at end of file diff --git a/labs/aws-elb/src/test/java/org/jclouds/aws/elb/config/AWSELBLoadBalancerServiceLiveTest.java b/labs/aws-elb/src/test/java/org/jclouds/aws/elb/config/AWSELBLoadBalancerServiceLiveTest.java index e758e4b40c..690cfec465 100644 --- a/labs/aws-elb/src/test/java/org/jclouds/aws/elb/config/AWSELBLoadBalancerServiceLiveTest.java +++ b/labs/aws-elb/src/test/java/org/jclouds/aws/elb/config/AWSELBLoadBalancerServiceLiveTest.java @@ -18,6 +18,8 @@ */ package org.jclouds.aws.elb.config; +import org.jclouds.elb.ELBAsyncClient; +import org.jclouds.elb.ELBClient; import org.jclouds.elb.loadbalancer.ELBLoadBalancerServiceLiveTest; import org.testng.annotations.Test; @@ -25,8 +27,8 @@ import org.testng.annotations.Test; * * @author Adrian Cole */ -@Test(groups = "live", sequential = true, testName = "AWSELBLoadBalancerServiceLiveTest") -public class AWSELBLoadBalancerServiceLiveTest extends ELBLoadBalancerServiceLiveTest { +@Test(groups = "live", singleThreaded = true, testName = "AWSELBLoadBalancerServiceLiveTest") +public class AWSELBLoadBalancerServiceLiveTest extends ELBLoadBalancerServiceLiveTest { public AWSELBLoadBalancerServiceLiveTest() { provider = "aws-elb"; diff --git a/labs/carrenza-element-vcloud/src/main/java/org/jclouds/carrenza/vcloud/director/CarrenzaVCloudDirectorContextBuilder.java b/labs/carrenza-element-vcloud/src/main/java/org/jclouds/carrenza/vcloud/director/CarrenzaVCloudDirectorContextBuilder.java index 39a3fd86ce..59fc2c56b9 100644 --- a/labs/carrenza-element-vcloud/src/main/java/org/jclouds/carrenza/vcloud/director/CarrenzaVCloudDirectorContextBuilder.java +++ b/labs/carrenza-element-vcloud/src/main/java/org/jclouds/carrenza/vcloud/director/CarrenzaVCloudDirectorContextBuilder.java @@ -19,11 +19,14 @@ package org.jclouds.carrenza.vcloud.director; import java.util.List; -import java.util.Properties; -import org.jclouds.carrenza.vcloud.director.config.CarrenzaVCloudDirectorComputeServiceContextModule; import org.jclouds.carrenza.vcloud.director.config.CarrenzaVCloudDirectorRestClientModule; +import org.jclouds.providers.ProviderMetadata; +import org.jclouds.vcloud.director.v1_5.VCloudDirectorApiMetadata; +import org.jclouds.vcloud.director.v1_5.VCloudDirectorContext; import org.jclouds.vcloud.director.v1_5.VCloudDirectorContextBuilder; +import org.jclouds.vcloud.director.v1_5.user.VCloudDirectorAsyncClient; +import org.jclouds.vcloud.director.v1_5.user.VCloudDirectorClient; import com.google.inject.Module; @@ -34,8 +37,13 @@ import com.google.inject.Module; */ public class CarrenzaVCloudDirectorContextBuilder extends VCloudDirectorContextBuilder { - public CarrenzaVCloudDirectorContextBuilder(Properties props) { - super(props); + public CarrenzaVCloudDirectorContextBuilder( + ProviderMetadata providerMetadata) { + super(providerMetadata); + } + + public CarrenzaVCloudDirectorContextBuilder(VCloudDirectorApiMetadata apiMetadata) { + super(apiMetadata); } @Override diff --git a/labs/carrenza-element-vcloud/src/main/java/org/jclouds/carrenza/vcloud/director/CarrenzaVCloudDirectorPropertiesBuilder.java b/labs/carrenza-element-vcloud/src/main/java/org/jclouds/carrenza/vcloud/director/CarrenzaVCloudDirectorPropertiesBuilder.java deleted file mode 100644 index 80a81e275a..0000000000 --- a/labs/carrenza-element-vcloud/src/main/java/org/jclouds/carrenza/vcloud/director/CarrenzaVCloudDirectorPropertiesBuilder.java +++ /dev/null @@ -1,47 +0,0 @@ -/** - * 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.carrenza.vcloud.director; - -import static org.jclouds.Constants.PROPERTY_BUILD_VERSION; -import static org.jclouds.Constants.PROPERTY_ENDPOINT; -import static org.jclouds.Constants.PROPERTY_ISO3166_CODES; - -import java.util.Properties; - -import org.jclouds.vcloud.director.v1_5.VCloudDirectorPropertiesBuilder; - -/** - * - * @author Adrian Cole - */ -public class CarrenzaVCloudDirectorPropertiesBuilder extends VCloudDirectorPropertiesBuilder { - @Override - public Properties defaultProperties() { - Properties properties = super.defaultProperties(); - properties.setProperty(PROPERTY_ISO3166_CODES, "GB-LND"); - properties.setProperty(PROPERTY_ENDPOINT, "https://myvdc.carrenza.net/api"); - properties.setProperty(PROPERTY_BUILD_VERSION, "???"); //FIXME -// properties.setProperty(PROPERTY_VCLOUD_DEFAULT_NETWORK, "orgNet-.*-External"); FIXME: needed? - return properties; - } - - public CarrenzaVCloudDirectorPropertiesBuilder(Properties properties) { - super(properties); - } -} diff --git a/labs/carrenza-element-vcloud/src/main/java/org/jclouds/carrenza/vcloud/director/CarrenzaVCloudDirectorProviderMetadata.java b/labs/carrenza-element-vcloud/src/main/java/org/jclouds/carrenza/vcloud/director/CarrenzaVCloudDirectorProviderMetadata.java index 0d28b88cfb..3c75135bd4 100644 --- a/labs/carrenza-element-vcloud/src/main/java/org/jclouds/carrenza/vcloud/director/CarrenzaVCloudDirectorProviderMetadata.java +++ b/labs/carrenza-element-vcloud/src/main/java/org/jclouds/carrenza/vcloud/director/CarrenzaVCloudDirectorProviderMetadata.java @@ -18,49 +18,78 @@ */ package org.jclouds.carrenza.vcloud.director; -import java.net.URI; +import static org.jclouds.Constants.PROPERTY_BUILD_VERSION; -import org.jclouds.providers.BaseProviderMetadata; +import java.net.URI; +import java.util.Properties; + +import org.jclouds.providers.ProviderMetadata; +import org.jclouds.providers.internal.BaseProviderMetadata; import org.jclouds.vcloud.director.v1_5.VCloudDirectorApiMetadata; +import org.jclouds.vcloud.director.v1_5.VCloudDirectorContext; +import org.jclouds.vcloud.director.v1_5.user.VCloudDirectorAsyncClient; +import org.jclouds.vcloud.director.v1_5.user.VCloudDirectorClient; + +import com.google.common.reflect.TypeToken; /** - * Implementation of {@link org.jclouds.types.ProviderMetadata} for Carrenza vCloud Director + * Implementation of {@link org.jclouds.types.ProviderMetadata} for StratoGen VMware hosting * - * @author dankov + * @author Adrian Cole */ -public class CarrenzaVCloudDirectorProviderMetadata extends BaseProviderMetadata { +public class CarrenzaVCloudDirectorProviderMetadata + extends + BaseProviderMetadata { - public CarrenzaVCloudDirectorProviderMetadata() { - this(builder() - .id("carrenza-vcloud-director") - .name("Carrenza vCloud Director") - .api(new VCloudDirectorApiMetadata()) - .homepage(URI.create("http://carrenza.com/")) - .console(URI.create("https://myvdc.carrenza.net/cloud/org/YOUR_ORG_HERE")) - .iso3166Codes("GB-LND")); + public static Builder builder() { + return new Builder(); } - // below are so that we can reuse builders, toString, hashCode, etc. - // we have to set concrete classes here, as our base class cannot be - // concrete due to serviceLoader - protected CarrenzaVCloudDirectorProviderMetadata(ConcreteBuilder builder) { + @Override + public Builder toBuilder() { + return builder().fromProviderMetadata(this); + } + + public CarrenzaVCloudDirectorProviderMetadata() { + super(builder()); + } + + public CarrenzaVCloudDirectorProviderMetadata(Builder builder) { super(builder); } - private static class ConcreteBuilder extends Builder { + protected static Properties defaultProperties() { + Properties properties = new Properties(); + properties.setProperty(PROPERTY_BUILD_VERSION, "???"); //FIXME +// properties.setProperty(PROPERTY_VCLOUD_DEFAULT_NETWORK, "orgNet-.*-External"); FIXME: needed? + return properties; + } + + public static class Builder extends BaseProviderMetadata.Builder { + + protected Builder(){ + id("carrenza-vcloud-director") + .name("Carrenza vCloud Director") + .apiMetadata(new VCloudDirectorApiMetadata().toBuilder() + .buildVersion("1.5.0.464915") + .contextBuilder(TypeToken.of(CarrenzaVCloudDirectorContextBuilder.class)).build()) + .homepage(URI.create("http://carrenza.com/")) + .console(URI.create("https://myvdc.carrenza.net/cloud/org/YOUR_ORG_HERE")) + .iso3166Codes("GB-LND") + .endpoint("https://myvdc.carrenza.net/api") + .defaultProperties(CarrenzaVCloudDirectorProviderMetadata.defaultProperties()); + } @Override public CarrenzaVCloudDirectorProviderMetadata build() { return new CarrenzaVCloudDirectorProviderMetadata(this); } + + @Override + public Builder fromProviderMetadata( + ProviderMetadata in) { + super.fromProviderMetadata(in); + return this; + } } - - public static ConcreteBuilder builder() { - return new ConcreteBuilder(); - } - - public ConcreteBuilder toBuilder() { - return builder().fromProviderMetadata(this); - } - -} +} \ No newline at end of file diff --git a/labs/carrenza-element-vcloud/src/test/java/org/jclouds/carrenza/vcloud/director/CarrenzaVCloudDirectorNonClientOperationsLiveTest.java b/labs/carrenza-element-vcloud/src/test/java/org/jclouds/carrenza/vcloud/director/CarrenzaVCloudDirectorNonClientOperationsLiveTest.java index d9468075ba..c1054103e3 100644 --- a/labs/carrenza-element-vcloud/src/test/java/org/jclouds/carrenza/vcloud/director/CarrenzaVCloudDirectorNonClientOperationsLiveTest.java +++ b/labs/carrenza-element-vcloud/src/test/java/org/jclouds/carrenza/vcloud/director/CarrenzaVCloudDirectorNonClientOperationsLiveTest.java @@ -18,7 +18,7 @@ */ package org.jclouds.carrenza.vcloud.director; -import org.jclouds.vcloud.director.v1_5.NonClientOperationsLiveTest; +import org.jclouds.vcloud.director.v1_5.HttpClientLiveTest; import org.testng.annotations.Test; /** @@ -27,7 +27,7 @@ import org.testng.annotations.Test; * @author danikov */ @Test(groups = "live", enabled = true, singleThreaded = true, testName = "CarrenzaVCloudDirectorNonClientOperationsLiveTest") -public class CarrenzaVCloudDirectorNonClientOperationsLiveTest extends NonClientOperationsLiveTest { +public class CarrenzaVCloudDirectorNonClientOperationsLiveTest extends HttpClientLiveTest { public CarrenzaVCloudDirectorNonClientOperationsLiveTest() { provider = "carrenza-vcloud-director"; diff --git a/labs/carrenza-element-vcloud/src/test/java/org/jclouds/carrenza/vcloud/director/CarrenzaVCloudDirectorProviderTest.java b/labs/carrenza-element-vcloud/src/test/java/org/jclouds/carrenza/vcloud/director/CarrenzaVCloudDirectorProviderTest.java index d5774cb7e6..ed936665da 100644 --- a/labs/carrenza-element-vcloud/src/test/java/org/jclouds/carrenza/vcloud/director/CarrenzaVCloudDirectorProviderTest.java +++ b/labs/carrenza-element-vcloud/src/test/java/org/jclouds/carrenza/vcloud/director/CarrenzaVCloudDirectorProviderTest.java @@ -18,7 +18,7 @@ */ package org.jclouds.carrenza.vcloud.director; -import org.jclouds.providers.BaseProviderMetadataTest; +import org.jclouds.providers.internal.BaseProviderMetadataTest; import org.jclouds.vcloud.director.v1_5.VCloudDirectorApiMetadata; import org.testng.annotations.Test; diff --git a/labs/carrenza-element-vcloud/src/test/java/org/jclouds/carrenza/vcloud/director/compute/CarrenzaVCloudDirectorTemplateBuilderLiveTest.java b/labs/carrenza-element-vcloud/src/test/java/org/jclouds/carrenza/vcloud/director/compute/CarrenzaVCloudDirectorTemplateBuilderLiveTest.java index 5295f9f3ea..dea42c7a04 100644 --- a/labs/carrenza-element-vcloud/src/test/java/org/jclouds/carrenza/vcloud/director/compute/CarrenzaVCloudDirectorTemplateBuilderLiveTest.java +++ b/labs/carrenza-element-vcloud/src/test/java/org/jclouds/carrenza/vcloud/director/compute/CarrenzaVCloudDirectorTemplateBuilderLiveTest.java @@ -18,60 +18,48 @@ */ package org.jclouds.carrenza.vcloud.director.compute; -import static org.jclouds.compute.util.ComputeServiceUtils.getCores; -import static org.testng.Assert.assertEquals; - -import java.io.IOException; -import java.util.Set; - -import org.jclouds.compute.BaseTemplateBuilderLiveTest; -import org.jclouds.compute.domain.OsFamily; -import org.jclouds.compute.domain.OsFamilyVersion64Bit; -import org.jclouds.compute.domain.Template; import org.testng.annotations.Test; -import com.google.common.base.Predicate; -import com.google.common.collect.ImmutableSet; - /** * * @author danikov */ @Test(groups = "live", testName = "CarrenzaVCloudDirectorTemplateBuilderLiveTest") -public class CarrenzaVCloudDirectorTemplateBuilderLiveTest extends BaseTemplateBuilderLiveTest { - - public CarrenzaVCloudDirectorTemplateBuilderLiveTest() { - provider = "carrenza-vcloud-director"; - } - - @Override - protected Predicate defineUnsupportedOperatingSystems() { - return new Predicate() { - - @Override - public boolean apply(OsFamilyVersion64Bit input) { - switch (input.family) { - case UBUNTU: - return !input.version.equals("") || !input.is64Bit; - default: - return true; - } - } - - }; - } - - @Override - public void testDefaultTemplateBuilder() throws IOException { - Template defaultTemplate = context.getComputeService().templateBuilder().build(); - assertEquals(defaultTemplate.getImage().getOperatingSystem().getVersion(), ""); - assertEquals(defaultTemplate.getImage().getOperatingSystem().is64Bit(), true); - assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.UBUNTU); - assertEquals(getCores(defaultTemplate.getHardware()), 1.0d); - } - - @Override - protected Set getIso3166Codes() { - return ImmutableSet. of("GB-LND"); - } +public class CarrenzaVCloudDirectorTemplateBuilderLiveTest { +// BaseTemplateBuilderLiveTest { +// +// public CarrenzaVCloudDirectorTemplateBuilderLiveTest() { +// provider = "carrenza-vcloud-director"; +// } +// +// @Override +// protected Predicate defineUnsupportedOperatingSystems() { +// return new Predicate() { +// +// @Override +// public boolean apply(OsFamilyVersion64Bit input) { +// switch (input.family) { +// case UBUNTU: +// return !input.version.equals("") || !input.is64Bit; +// default: +// return true; +// } +// } +// +// }; +// } +// +// @Override +// public void testDefaultTemplateBuilder() throws IOException { +// Template defaultTemplate = context.getComputeService().templateBuilder().build(); +// assertEquals(defaultTemplate.getImage().getOperatingSystem().getVersion(), ""); +// assertEquals(defaultTemplate.getImage().getOperatingSystem().is64Bit(), true); +// assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.UBUNTU); +// assertEquals(getCores(defaultTemplate.getHardware()), 1.0d); +// } +// +// @Override +// protected Set getIso3166Codes() { +// return ImmutableSet. of("GB-LND"); +// } } diff --git a/labs/elb/src/main/java/org/jclouds/elb/ELBApiMetadata.java b/labs/elb/src/main/java/org/jclouds/elb/ELBApiMetadata.java index f0397a41a3..c0c9df2ecf 100644 --- a/labs/elb/src/main/java/org/jclouds/elb/ELBApiMetadata.java +++ b/labs/elb/src/main/java/org/jclouds/elb/ELBApiMetadata.java @@ -18,50 +18,84 @@ */ package org.jclouds.elb; +import static org.jclouds.aws.reference.AWSConstants.PROPERTY_AUTH_TAG; +import static org.jclouds.aws.reference.AWSConstants.PROPERTY_HEADER_TAG; + import java.net.URI; +import java.util.Properties; import org.jclouds.apis.ApiMetadata; -import org.jclouds.apis.ApiType; -import org.jclouds.apis.BaseApiMetadata; +import org.jclouds.apis.internal.BaseApiMetadata; +import org.jclouds.loadbalancer.LoadBalancerServiceContext; +import org.jclouds.loadbalancer.internal.BaseLoadBalancerServiceApiMetadata; + +import com.google.common.reflect.TypeToken; /** * Implementation of {@link ApiMetadata} for Amazon's Elastic Load Balancing api. + *

note

+ *

+ * This class allows overriding of types {@code S}(client) and {@code A}(asyncClient), so that + * children can add additional methods not declared here, such as new features + * from AWS. + *

+ * + * This class is not setup to allow a different context than {@link LoadBalancerServiceContext} + * . By doing so, it reduces the type complexity. * * @author Adrian Cole */ -public class ELBApiMetadata extends BaseApiMetadata { +public class ELBApiMetadata extends + BaseLoadBalancerServiceApiMetadata, ELBApiMetadata> { + + @Override + public Builder toBuilder() { + return new Builder(getApi(), getAsyncApi()).fromApiMetadata(this); + } public ELBApiMetadata() { - this(builder() - .id("elb") - .type(ApiType.LOADBALANCER) - .name("Amazon Elastic Load Balancing Api") - .identityName("Access Key ID") - .credentialName("Secret Access Key") - .documentation(URI.create("http://docs.amazonwebservices.com/ElasticLoadBalancing/latest/APIReference"))); + this(new Builder(ELBClient.class, ELBAsyncClient.class)); } - // below are so that we can reuse builders, toString, hashCode, etc. - // we have to set concrete classes here, as our base class cannot be - // concrete due to serviceLoader - protected ELBApiMetadata(ConcreteBuilder builder) { + protected ELBApiMetadata(Builder builder) { super(builder); } + + protected static Properties defaultProperties() { + Properties properties = BaseApiMetadata.Builder.defaultProperties(); + properties.setProperty(PROPERTY_AUTH_TAG, "AWS"); + properties.setProperty(PROPERTY_HEADER_TAG, "amz"); + return properties; + } + + public static class Builder extends + BaseLoadBalancerServiceApiMetadata.Builder, ELBApiMetadata> { - private static class ConcreteBuilder extends Builder { + protected Builder(Class client, Class asyncClient) { + id("elb") + .name("Amazon Elastic Load Balancing Api") + .identityName("Access Key ID") + .credentialName("Secret Access Key") + .version(ELBAsyncClient.VERSION) + .defaultProperties(ELBApiMetadata.defaultProperties()) + .defaultEndpoint("https://elasticloadbalancing.us-east-1.amazonaws.com") + .documentation(URI.create("http://docs.amazonwebservices.com/ElasticLoadBalancing/latest/APIReference")) + .javaApi(client, asyncClient) + .contextBuilder(new TypeToken>(getClass()){ + private static final long serialVersionUID = 1L; + }); + } @Override - public ELBApiMetadata build() { - return new ELBApiMetadata(this); + public ELBApiMetadata build() { + return new ELBApiMetadata(this); + } + + @Override + public Builder fromApiMetadata(ELBApiMetadata in) { + super.fromApiMetadata(in); + return this; } } - public static ConcreteBuilder builder() { - return new ConcreteBuilder(); - } - - @Override - public ConcreteBuilder toBuilder() { - return builder().fromApiMetadata(this); - } } \ No newline at end of file diff --git a/labs/elb/src/main/java/org/jclouds/elb/ELBContextBuilder.java b/labs/elb/src/main/java/org/jclouds/elb/ELBContextBuilder.java index c8b6fdf7cf..256bd88f51 100644 --- a/labs/elb/src/main/java/org/jclouds/elb/ELBContextBuilder.java +++ b/labs/elb/src/main/java/org/jclouds/elb/ELBContextBuilder.java @@ -19,13 +19,14 @@ package org.jclouds.elb; import java.util.List; -import java.util.Properties; import org.jclouds.elb.config.ELBRestClientModule; import org.jclouds.elb.loadbalancer.config.ELBLoadBalancerContextModule; import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule; +import org.jclouds.loadbalancer.LoadBalancerServiceContext; import org.jclouds.loadbalancer.LoadBalancerServiceContextBuilder; import org.jclouds.logging.jdk.config.JDKLoggingModule; +import org.jclouds.providers.ProviderMetadata; import com.google.inject.Injector; import com.google.inject.Module; @@ -43,17 +44,22 @@ import com.google.inject.Module; * @author Adrian Cole * @see ELBContext */ -public class ELBContextBuilder extends LoadBalancerServiceContextBuilder { +public class ELBContextBuilder extends + LoadBalancerServiceContextBuilder, ELBApiMetadata> { + public ELBContextBuilder(ProviderMetadata, ELBApiMetadata> providerMetadata) { + super(providerMetadata); + } + + public ELBContextBuilder(ELBApiMetadata apiMetadata) { + super(apiMetadata); + } + @Override protected void addContextModule(List modules) { modules.add(new ELBLoadBalancerContextModule()); } - public ELBContextBuilder(Properties props) { - super(ELBClient.class, ELBAsyncClient.class, props); - } - @Override protected void addClientModule(List modules) { modules.add(new ELBRestClientModule()); diff --git a/labs/elb/src/test/java/org/jclouds/elb/ELBApiMetadataTest.java b/labs/elb/src/test/java/org/jclouds/elb/ELBApiMetadataTest.java index 011d2017a1..feb103b5b5 100644 --- a/labs/elb/src/test/java/org/jclouds/elb/ELBApiMetadataTest.java +++ b/labs/elb/src/test/java/org/jclouds/elb/ELBApiMetadataTest.java @@ -18,8 +18,7 @@ */ package org.jclouds.elb; -import org.jclouds.apis.ApiType; -import org.jclouds.apis.BaseApiMetadataTest; +import org.jclouds.loadbalancer.internal.BaseLoadBalancerServiceApiMetadataTest; import org.testng.annotations.Test; /** @@ -27,9 +26,10 @@ import org.testng.annotations.Test; * @author Adrian Cole */ @Test(groups = "unit", testName = "ELBApiMetadataTest") -public class ELBApiMetadataTest extends BaseApiMetadataTest { +public class ELBApiMetadataTest extends BaseLoadBalancerServiceApiMetadataTest { + @SuppressWarnings("rawtypes") public ELBApiMetadataTest() { - super(new ELBApiMetadata(), ApiType.LOADBALANCER); + super(new ELBApiMetadata()); } } diff --git a/labs/elb/src/test/java/org/jclouds/elb/ELBAsyncClientTest.java b/labs/elb/src/test/java/org/jclouds/elb/ELBAsyncClientTest.java index bf3fe21c41..dcb425dcb2 100644 --- a/labs/elb/src/test/java/org/jclouds/elb/ELBAsyncClientTest.java +++ b/labs/elb/src/test/java/org/jclouds/elb/ELBAsyncClientTest.java @@ -22,11 +22,11 @@ import static org.testng.Assert.assertEquals; import java.io.IOException; import java.lang.reflect.Method; -import java.util.Properties; import javax.inject.Named; import org.jclouds.Constants; +import org.jclouds.apis.ApiMetadata; import org.jclouds.aws.filters.FormSigner; import org.jclouds.date.DateService; import org.jclouds.elb.config.ELBRestClientModule; @@ -38,11 +38,9 @@ import org.jclouds.http.RequiresHttp; import org.jclouds.http.functions.ParseSax; import org.jclouds.http.functions.ReleasePayloadAndReturn; import org.jclouds.rest.ConfiguresRestClient; -import org.jclouds.rest.RestClientTest; -import org.jclouds.rest.RestContextFactory; -import org.jclouds.rest.RestContextSpec; import org.jclouds.rest.functions.MapHttp4xxCodesToExceptions; import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404; +import org.jclouds.rest.internal.BaseAsyncClientTest; import org.jclouds.rest.internal.RestAnnotationProcessor; import org.testng.annotations.Test; @@ -56,7 +54,7 @@ import com.google.inject.TypeLiteral; */ // NOTE:without testName, this will not call @Before* and fail w/NPE during surefire @Test(groups = "unit", testName = "ELBAsyncClientTest") -public class ELBAsyncClientTest extends RestClientTest { +public class ELBAsyncClientTest extends BaseAsyncClientTest { public void testCreateLoadBalancerInRegion() throws SecurityException, NoSuchMethodException, IOException { Method method = ELBAsyncClient.class.getMethod("createLoadBalancerInRegion", String.class, String.class, @@ -176,14 +174,10 @@ public class ELBAsyncClientTest extends RestClientTest { protected Module createModule() { return new TestELBRestClientModule(); } - - protected String provider = "elb"; - - + @Override - public RestContextSpec createContextSpec() { - return new RestContextFactory(setupRestProperties()).createContextSpec(provider, "identity", "credential", - new Properties()); + public ApiMetadata createApiMetadata() { + return new ELBApiMetadata(); } @Override diff --git a/labs/elb/src/test/java/org/jclouds/elb/ELBClientLiveTest.java b/labs/elb/src/test/java/org/jclouds/elb/ELBClientLiveTest.java index 24b963ca62..4ac5556e31 100644 --- a/labs/elb/src/test/java/org/jclouds/elb/ELBClientLiveTest.java +++ b/labs/elb/src/test/java/org/jclouds/elb/ELBClientLiveTest.java @@ -21,45 +21,35 @@ package org.jclouds.elb; import static com.google.common.base.Preconditions.checkNotNull; import static org.testng.Assert.assertNotNull; -import java.util.Properties; import java.util.Set; import org.jclouds.elb.domain.LoadBalancer; -import org.jclouds.loadbalancer.LoadBalancerServiceContextFactory; -import org.jclouds.logging.log4j.config.Log4JLoggingModule; -import org.jclouds.rest.BaseRestClientLiveTest; -import org.jclouds.rest.RestContext; +import org.jclouds.loadbalancer.LoadBalancerServiceContext; +import org.jclouds.rest.internal.BaseContextLiveTest; import org.testng.annotations.AfterGroups; -import org.testng.annotations.BeforeGroups; +import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; -import com.google.common.collect.ImmutableSet; -import com.google.inject.Module; - /** * Tests behavior of {@code ELBClient} * * @author Lili Nader */ @Test(groups = "live", singleThreaded = true, testName = "ELBClientLiveTest") -public class ELBClientLiveTest extends BaseRestClientLiveTest { +public class ELBClientLiveTest extends BaseContextLiveTest> { public ELBClientLiveTest() { provider = "elb"; } private ELBClient client; - private RestContext context; - protected String name = "TestLoadBalancer"; - @BeforeGroups(groups = "live") - public void setupClient() { - setupCredentials(); - Properties overrides = setupProperties(); - context = new LoadBalancerServiceContextFactory().createContext(provider, - ImmutableSet. of(new Log4JLoggingModule()), overrides).getProviderSpecificContext(); - client = context.getApi(); + @Override + @BeforeClass(groups = { "integration", "live" }) + public void setupContext() { + super.setupContext(); + client = context.getProviderSpecificContext().getApi(); } @Test diff --git a/labs/elb/src/test/java/org/jclouds/elb/loadbalancer/ELBLoadBalancerServiceLiveTest.java b/labs/elb/src/test/java/org/jclouds/elb/loadbalancer/ELBLoadBalancerServiceLiveTest.java index f218ca619f..4ef29b2ae8 100644 --- a/labs/elb/src/test/java/org/jclouds/elb/loadbalancer/ELBLoadBalancerServiceLiveTest.java +++ b/labs/elb/src/test/java/org/jclouds/elb/loadbalancer/ELBLoadBalancerServiceLiveTest.java @@ -29,6 +29,7 @@ import org.jclouds.elb.ELBAsyncClient; import org.jclouds.elb.ELBClient; import org.jclouds.elb.domain.LoadBalancer; import org.jclouds.loadbalancer.BaseLoadBalancerServiceLiveTest; +import org.jclouds.loadbalancer.LoadBalancerServiceContext; import org.jclouds.rest.RestContext; import org.jclouds.sshj.config.SshjSshClientModule; import org.testng.annotations.Test; @@ -38,7 +39,7 @@ import org.testng.annotations.Test; * @author Lili Nadar */ @Test(groups = "live", singleThreaded = true, testName = "ELBLoadBalancerServiceLiveTest") -public class ELBLoadBalancerServiceLiveTest extends BaseLoadBalancerServiceLiveTest { +public class ELBLoadBalancerServiceLiveTest extends BaseLoadBalancerServiceLiveTest> { public ELBLoadBalancerServiceLiveTest() { provider = "elb"; @@ -52,7 +53,7 @@ public class ELBLoadBalancerServiceLiveTest extends BaseLoadBalancerServiceLiveT @Override protected void validateNodesInLoadBalancer() { - RestContext elbContext = context.getProviderSpecificContext(); + RestContext elbContext = context.getProviderSpecificContext(); // TODO create a LoadBalancer object and an appropriate list method so that this // does not have to be EC2 specific code ELBClient elbClient = elbContext.getApi(); diff --git a/labs/glesys/src/main/java/org/jclouds/glesys/GleSYSApiMetadata.java b/labs/glesys/src/main/java/org/jclouds/glesys/GleSYSApiMetadata.java index be731d4992..bc06dbaf60 100644 --- a/labs/glesys/src/main/java/org/jclouds/glesys/GleSYSApiMetadata.java +++ b/labs/glesys/src/main/java/org/jclouds/glesys/GleSYSApiMetadata.java @@ -19,50 +19,71 @@ package org.jclouds.glesys; import java.net.URI; +import java.util.Properties; import org.jclouds.apis.ApiMetadata; -import org.jclouds.apis.ApiType; -import org.jclouds.apis.BaseApiMetadata; +import org.jclouds.compute.ComputeServiceContext; +import org.jclouds.compute.internal.BaseComputeServiceApiMetadata; + +import com.google.common.reflect.TypeToken; /** - * Implementation of {@link ApiMetadata} for GleSYS API + * Implementation of {@link ApiMetadata} for API * * @author Adrian Cole */ -public class GleSYSApiMetadata extends BaseApiMetadata { +public class GleSYSApiMetadata + extends + BaseComputeServiceApiMetadata, GleSYSApiMetadata> { - public GleSYSApiMetadata() { - this(builder() - .id("glesys") - .type(ApiType.COMPUTE) - .name("GleSYS API") - .identityName("Username") - .credentialName("API Key") - .documentation(URI.create("https://customer.glesys.com/api.php"))); + @Override + public Builder toBuilder() { + return new Builder().fromApiMetadata(this); } - // below are so that we can reuse builders, toString, hashCode, etc. - // we have to set concrete classes here, as our base class cannot be - // concrete due to serviceLoader - protected GleSYSApiMetadata(Builder builder) { + public GleSYSApiMetadata() { + this(new Builder()); + } + + protected GleSYSApiMetadata(Builder builder) { super(builder); } - private static class ConcreteBuilder extends Builder { + protected static Properties defaultProperties() { + Properties properties = BaseComputeServiceApiMetadata.Builder.defaultProperties(); + properties.setProperty("jclouds.ssh.max-retries", "5"); + properties.setProperty("jclouds.ssh.retry-auth", "true"); + return properties; + } + + public static class Builder + extends + BaseComputeServiceApiMetadata.Builder, GleSYSApiMetadata> { + + protected Builder() { + id("glesys") + .name("GleSYS API") + .identityName("Username") + .credentialName("API Key") + .documentation(URI.create("https://customer.glesys.com/api.php")) + .version("1") + .defaultEndpoint("https://api.glesys.com") + .defaultProperties(GleSYSApiMetadata.defaultProperties()) + .javaApi(GleSYSClient.class, GleSYSAsyncClient.class) + .contextBuilder(TypeToken.of(GleSYSContextBuilder.class)); + } @Override public GleSYSApiMetadata build() { return new GleSYSApiMetadata(this); } + + @Override + public Builder fromApiMetadata(GleSYSApiMetadata in) { + super.fromApiMetadata(in); + return this; + } + } - public static ConcreteBuilder builder() { - return new ConcreteBuilder(); - } - - @Override - public ConcreteBuilder toBuilder() { - return builder().fromApiMetadata(this); - } - -} \ No newline at end of file +} diff --git a/labs/glesys/src/main/java/org/jclouds/glesys/GleSYSContextBuilder.java b/labs/glesys/src/main/java/org/jclouds/glesys/GleSYSContextBuilder.java index 1b093e8388..0f648dfe63 100644 --- a/labs/glesys/src/main/java/org/jclouds/glesys/GleSYSContextBuilder.java +++ b/labs/glesys/src/main/java/org/jclouds/glesys/GleSYSContextBuilder.java @@ -19,11 +19,12 @@ package org.jclouds.glesys; import java.util.List; -import java.util.Properties; +import org.jclouds.compute.ComputeServiceContext; import org.jclouds.compute.ComputeServiceContextBuilder; import org.jclouds.glesys.compute.config.GleSYSComputeServiceContextModule; import org.jclouds.glesys.config.GleSYSRestClientModule; +import org.jclouds.providers.ProviderMetadata; import com.google.inject.Module; @@ -31,10 +32,17 @@ import com.google.inject.Module; * * @author Adrian Cole */ -public class GleSYSContextBuilder extends ComputeServiceContextBuilder { +public class GleSYSContextBuilder + extends + ComputeServiceContextBuilder, GleSYSApiMetadata> { - public GleSYSContextBuilder(Properties props) { - super(GleSYSClient.class, GleSYSAsyncClient.class, props); + public GleSYSContextBuilder( + ProviderMetadata, GleSYSApiMetadata> providerMetadata) { + super(providerMetadata); + } + + public GleSYSContextBuilder(GleSYSApiMetadata apiMetadata) { + super(apiMetadata); } @Override @@ -42,7 +50,6 @@ public class GleSYSContextBuilder extends ComputeServiceContextBuilder modules) { modules.add(new GleSYSRestClientModule()); } diff --git a/labs/glesys/src/main/java/org/jclouds/glesys/GleSYSPropertiesBuilder.java b/labs/glesys/src/main/java/org/jclouds/glesys/GleSYSPropertiesBuilder.java deleted file mode 100644 index 31019e1973..0000000000 --- a/labs/glesys/src/main/java/org/jclouds/glesys/GleSYSPropertiesBuilder.java +++ /dev/null @@ -1,61 +0,0 @@ -/** - * 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.glesys; - -import static org.jclouds.Constants.PROPERTY_API_VERSION; -import static org.jclouds.Constants.PROPERTY_ENDPOINT; -import static org.jclouds.Constants.PROPERTY_ISO3166_CODES; -import static org.jclouds.glesys.reference.GleSYSConstants.PROPERTY_GLESYS_DEFAULT_DC; -import static org.jclouds.location.reference.LocationConstants.ISO3166_CODES; -import static org.jclouds.location.reference.LocationConstants.PROPERTY_ZONE; -import static org.jclouds.location.reference.LocationConstants.PROPERTY_ZONES; - -import java.util.Properties; - -import org.jclouds.PropertiesBuilder; - -/** - * Builds properties used in GleSYS Clients - * - * @author Adrian Cole - * @author Adam Lowe - */ -public class GleSYSPropertiesBuilder extends PropertiesBuilder { - @Override - protected Properties defaultProperties() { - Properties properties = super.defaultProperties(); - properties.setProperty(PROPERTY_ENDPOINT, "https://api.glesys.com"); - properties.setProperty(PROPERTY_API_VERSION, "1"); - properties.setProperty(PROPERTY_ZONES, "Amsterdam,Falkenberg,New York City,Stockholm"); - properties.setProperty(PROPERTY_ISO3166_CODES, "NL-NH,SE-N,US-NY,SE-AB"); - properties.setProperty(PROPERTY_ZONE + ".Amsterdam." + ISO3166_CODES, "NL-NH"); - properties.setProperty(PROPERTY_ZONE + ".Falkenberg." + ISO3166_CODES, "SE-N"); - properties.setProperty(PROPERTY_ZONE + ".New York City." + ISO3166_CODES, "US-NY"); - properties.setProperty(PROPERTY_ZONE + ".Stockholm." + ISO3166_CODES, "SE-AB"); - properties.setProperty("jclouds.ssh.max-retries", "5"); - properties.setProperty("jclouds.ssh.retry-auth", "true"); - properties.setProperty(PROPERTY_GLESYS_DEFAULT_DC, "Falkenberg"); - return properties; - } - - public GleSYSPropertiesBuilder(Properties properties) { - super(properties); - } - -} diff --git a/labs/glesys/src/main/java/org/jclouds/glesys/GleSYSProviderMetadata.java b/labs/glesys/src/main/java/org/jclouds/glesys/GleSYSProviderMetadata.java index 3d5da78f02..871fe47d79 100644 --- a/labs/glesys/src/main/java/org/jclouds/glesys/GleSYSProviderMetadata.java +++ b/labs/glesys/src/main/java/org/jclouds/glesys/GleSYSProviderMetadata.java @@ -18,48 +18,80 @@ */ package org.jclouds.glesys; -import java.net.URI; +import static org.jclouds.glesys.reference.GleSYSConstants.PROPERTY_GLESYS_DEFAULT_DC; +import static org.jclouds.location.reference.LocationConstants.ISO3166_CODES; +import static org.jclouds.location.reference.LocationConstants.PROPERTY_ZONE; +import static org.jclouds.location.reference.LocationConstants.PROPERTY_ZONES; -import org.jclouds.providers.BaseProviderMetadata; +import java.net.URI; +import java.util.Properties; + +import org.jclouds.compute.ComputeServiceContext; +import org.jclouds.providers.ProviderMetadata; +import org.jclouds.providers.internal.BaseProviderMetadata; /** * Implementation of {@link org.jclouds.types.ProviderMetadata} for GleSYS. - * * @author Adrian Cole */ -public class GleSYSProviderMetadata extends BaseProviderMetadata { +public class GleSYSProviderMetadata + extends + BaseProviderMetadata, GleSYSApiMetadata> { - public GleSYSProviderMetadata() { - this(builder() - .id("glesys") - .name("GleSYS") - .api(new GleSYSApiMetadata()) - .homepage(URI.create("http://www.glesys.com")) - .console(URI.create("https://customer.glesys.com/cloud.php")) - .iso3166Codes("NL-NH","SE-N","US-NY","SE-AB")); + public static Builder builder() { + return new Builder(); } - // below are so that we can reuse builders, toString, hashCode, etc. - // we have to set concrete classes here, as our base class cannot be - // concrete due to serviceLoader - protected GleSYSProviderMetadata(ConcreteBuilder builder) { + @Override + public Builder toBuilder() { + return builder().fromProviderMetadata(this); + } + + public GleSYSProviderMetadata() { + super(builder()); + } + + public GleSYSProviderMetadata(Builder builder) { super(builder); } - private static class ConcreteBuilder extends Builder { + protected static Properties defaultProperties() { + Properties properties = new Properties(); + properties.setProperty(PROPERTY_ZONES, "Amsterdam,Falkenberg,New York City,Stockholm"); + properties.setProperty(PROPERTY_ZONE + ".Amsterdam." + ISO3166_CODES, "NL-NH"); + properties.setProperty(PROPERTY_ZONE + ".Falkenberg." + ISO3166_CODES, "SE-N"); + properties.setProperty(PROPERTY_ZONE + ".New York City." + ISO3166_CODES, "US-NY"); + properties.setProperty(PROPERTY_ZONE + ".Stockholm." + ISO3166_CODES, "SE-AB"); + properties.setProperty(PROPERTY_GLESYS_DEFAULT_DC, "Falkenberg"); + return properties; + } + + public static class Builder + extends + BaseProviderMetadata.Builder, GleSYSApiMetadata> { + + protected Builder() { + id("glesys") + .name("GleSYS") + .apiMetadata(new GleSYSApiMetadata()) + .homepage(URI.create("http://www.glesys.com")) + .console(URI.create("https://customer.glesys.com/cloud.php")) + .iso3166Codes("NL-NH","SE-N","US-NY","SE-AB") + .endpoint("https://api.glesys.com") + .defaultProperties(GleSYSProviderMetadata.defaultProperties()); + } @Override public GleSYSProviderMetadata build() { return new GleSYSProviderMetadata(this); } - } - public static ConcreteBuilder builder() { - return new ConcreteBuilder(); - } + @Override + public Builder fromProviderMetadata( + ProviderMetadata, GleSYSApiMetadata> in) { + super.fromProviderMetadata(in); + return this; + } - public ConcreteBuilder toBuilder() { - return builder().fromProviderMetadata(this); } - -} +} \ No newline at end of file diff --git a/labs/glesys/src/test/java/org/jclouds/glesys/GleSYSProviderTest.java b/labs/glesys/src/test/java/org/jclouds/glesys/GleSYSProviderTest.java index b8a5751814..eb41a8cab0 100644 --- a/labs/glesys/src/test/java/org/jclouds/glesys/GleSYSProviderTest.java +++ b/labs/glesys/src/test/java/org/jclouds/glesys/GleSYSProviderTest.java @@ -18,7 +18,7 @@ */ package org.jclouds.glesys; -import org.jclouds.providers.BaseProviderMetadataTest; +import org.jclouds.providers.internal.BaseProviderMetadataTest; import org.testng.annotations.Test; /** diff --git a/labs/glesys/src/test/java/org/jclouds/glesys/compute/GleSYSComputeServiceLiveTest.java b/labs/glesys/src/test/java/org/jclouds/glesys/compute/GleSYSComputeServiceLiveTest.java index 70bdfb25f3..3ddec09ef4 100644 --- a/labs/glesys/src/test/java/org/jclouds/glesys/compute/GleSYSComputeServiceLiveTest.java +++ b/labs/glesys/src/test/java/org/jclouds/glesys/compute/GleSYSComputeServiceLiveTest.java @@ -18,12 +18,11 @@ */ package org.jclouds.glesys.compute; -import org.jclouds.compute.BaseComputeServiceLiveTest; -import org.jclouds.compute.ComputeServiceContextFactory; +import org.jclouds.compute.ComputeServiceContext; import org.jclouds.compute.domain.NodeMetadata; +import org.jclouds.compute.internal.BaseComputeServiceLiveTest; import org.jclouds.glesys.GleSYSAsyncClient; import org.jclouds.glesys.GleSYSClient; -import org.jclouds.rest.RestContext; import org.jclouds.sshj.config.SshjSshClientModule; import org.testng.annotations.Test; @@ -37,7 +36,10 @@ import com.google.inject.Module; * @author Adrian Cole */ @Test(groups = "live", enabled = true, singleThreaded = true) -public class GleSYSComputeServiceLiveTest extends BaseComputeServiceLiveTest { +public class GleSYSComputeServiceLiveTest + extends + BaseComputeServiceLiveTest> { + public GleSYSComputeServiceLiveTest() { provider = "glesys"; // ensure hyphens work @@ -49,12 +51,6 @@ public class GleSYSComputeServiceLiveTest extends BaseComputeServiceLiveTest { return new SshjSshClientModule(); } - public void testAssignability() throws Exception { - @SuppressWarnings("unused") - RestContext tmContext = new ComputeServiceContextFactory().createContext( - provider, identity, credential).getProviderSpecificContext(); - } - // GleSYS does not support metadata @Override protected void checkUserMetadataInNodeEquals(NodeMetadata node, ImmutableMap userMetadata) { diff --git a/labs/glesys/src/test/java/org/jclouds/glesys/compute/GleSYSExperimentExpectTest.java b/labs/glesys/src/test/java/org/jclouds/glesys/compute/GleSYSExperimentExpectTest.java index 1dc7ca53e4..34824b495f 100644 --- a/labs/glesys/src/test/java/org/jclouds/glesys/compute/GleSYSExperimentExpectTest.java +++ b/labs/glesys/src/test/java/org/jclouds/glesys/compute/GleSYSExperimentExpectTest.java @@ -33,7 +33,7 @@ public class GleSYSExperimentExpectTest extends BaseGleSYSComputeServiceExpectTe @Test public void testAndExperiment() { - ComputeServiceContext context = null; + ComputeServiceContext context = null; try { context = computeContextForKnownArgumentsAndConstantPassword(); diff --git a/labs/glesys/src/test/java/org/jclouds/glesys/compute/GleSYSExperimentLiveTest.java b/labs/glesys/src/test/java/org/jclouds/glesys/compute/GleSYSExperimentLiveTest.java index bd307e9229..357ad48039 100644 --- a/labs/glesys/src/test/java/org/jclouds/glesys/compute/GleSYSExperimentLiveTest.java +++ b/labs/glesys/src/test/java/org/jclouds/glesys/compute/GleSYSExperimentLiveTest.java @@ -20,39 +20,43 @@ package org.jclouds.glesys.compute; import static org.testng.Assert.assertEquals; -import org.jclouds.compute.BaseVersionedServiceLiveTest; import org.jclouds.compute.ComputeServiceContext; -import org.jclouds.compute.ComputeServiceContextFactory; -import org.jclouds.logging.log4j.config.Log4JLoggingModule; -import org.jclouds.sshj.config.SshjSshClientModule; +import org.jclouds.compute.ComputeServiceContextBuilder; +import org.jclouds.compute.internal.BaseComputeServiceContextLiveTest; +import org.jclouds.glesys.GleSYSAsyncClient; +import org.jclouds.glesys.GleSYSClient; +import org.jclouds.glesys.GleSYSProviderMetadata; import org.testng.annotations.Test; -import com.google.common.collect.ImmutableSet; -import com.google.inject.Module; +import com.google.common.io.Closeables; /** * * @author Adrian Cole */ @Test(groups = "live", singleThreaded = true, testName = "GleSYSExperimentLiveTest") -public class GleSYSExperimentLiveTest extends BaseVersionedServiceLiveTest { +public class GleSYSExperimentLiveTest + extends + BaseComputeServiceContextLiveTest> { + public GleSYSExperimentLiveTest() { provider = "glesys"; } @Test public void testAndExperiment() { - ComputeServiceContext context = null; + ComputeServiceContext context = null; try { - context = new ComputeServiceContextFactory().createContext(provider, identity, credential, ImmutableSet - . of(new Log4JLoggingModule(), new SshjSshClientModule())); + context = ComputeServiceContextBuilder + .newBuilder(new GleSYSProviderMetadata()) + .overrides(setupProperties()) + .modules(setupModules()).build(); assertEquals(context.getComputeService().listAssignableLocations().size(), 4); } finally { - if (context != null) - context.close(); + Closeables.closeQuietly(context); } } diff --git a/labs/glesys/src/test/java/org/jclouds/glesys/compute/GleSYSTemplateBuilderLiveTest.java b/labs/glesys/src/test/java/org/jclouds/glesys/compute/GleSYSTemplateBuilderLiveTest.java index 7e5edad7b2..55f19450e1 100644 --- a/labs/glesys/src/test/java/org/jclouds/glesys/compute/GleSYSTemplateBuilderLiveTest.java +++ b/labs/glesys/src/test/java/org/jclouds/glesys/compute/GleSYSTemplateBuilderLiveTest.java @@ -25,11 +25,14 @@ import static org.testng.Assert.assertEquals; import java.io.IOException; import java.util.Set; -import org.jclouds.compute.BaseTemplateBuilderLiveTest; +import org.jclouds.compute.ComputeServiceContext; import org.jclouds.compute.domain.OsFamily; import org.jclouds.compute.domain.OsFamilyVersion64Bit; import org.jclouds.compute.domain.Template; import org.jclouds.compute.domain.Volume; +import org.jclouds.compute.internal.BaseTemplateBuilderLiveTest; +import org.jclouds.glesys.GleSYSAsyncClient; +import org.jclouds.glesys.GleSYSClient; import org.jclouds.glesys.compute.options.GleSYSTemplateOptions; import org.testng.annotations.Test; @@ -42,7 +45,9 @@ import com.google.common.collect.ImmutableSet; * @author Adrian Cole */ @Test(groups = "live", testName = "GleSYSTemplateBuilderLiveTest") -public class GleSYSTemplateBuilderLiveTest extends BaseTemplateBuilderLiveTest { +public class GleSYSTemplateBuilderLiveTest + extends + BaseTemplateBuilderLiveTest> { public GleSYSTemplateBuilderLiveTest() { provider = "glesys"; diff --git a/labs/glesys/src/test/java/org/jclouds/glesys/compute/internal/BaseGleSYSComputeServiceExpectTest.java b/labs/glesys/src/test/java/org/jclouds/glesys/compute/internal/BaseGleSYSComputeServiceExpectTest.java index c27888934e..4e7ee5251e 100644 --- a/labs/glesys/src/test/java/org/jclouds/glesys/compute/internal/BaseGleSYSComputeServiceExpectTest.java +++ b/labs/glesys/src/test/java/org/jclouds/glesys/compute/internal/BaseGleSYSComputeServiceExpectTest.java @@ -22,19 +22,18 @@ import java.net.URI; import java.util.Map; import java.util.Properties; +import org.jclouds.apis.ApiMetadata; import org.jclouds.compute.ComputeService; import org.jclouds.compute.ComputeServiceContext; -import org.jclouds.compute.ComputeServiceContextFactory; +import org.jclouds.glesys.GleSYSApiMetadata; import org.jclouds.glesys.compute.config.GleSYSComputeServiceContextModule.PasswordProvider; import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpResponse; -import org.jclouds.logging.config.NullLoggingModule; -import org.jclouds.rest.BaseRestClientExpectTest; +import org.jclouds.rest.internal.BaseRestClientExpectTest; import com.google.common.base.Function; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMultimap; -import com.google.common.collect.ImmutableSet; import com.google.inject.AbstractModule; import com.google.inject.Injector; import com.google.inject.Module; @@ -50,10 +49,14 @@ public abstract class BaseGleSYSComputeServiceExpectTest extends BaseRestClientE provider = "glesys"; } + @Override + protected ApiMetadata createApiMetadata() { + return new GleSYSApiMetadata(); + } + @Override public ComputeService createClient(Function fn, Module module, Properties props) { - return new ComputeServiceContextFactory(setupRestProperties()).createContext(provider, identity, credential, - ImmutableSet. of(new ExpectModule(fn), new NullLoggingModule(), module), props).getComputeService(); + return createInjector(fn, module, props).getInstance(ComputeService.class); } protected PasswordProvider passwordGenerator() { @@ -73,7 +76,7 @@ public abstract class BaseGleSYSComputeServiceExpectTest extends BaseRestClientE return computeContextForKnownArgumentsAndConstantPassword(requestsResponses).utils().injector(); } - protected ComputeServiceContext computeContextForKnownArgumentsAndConstantPassword( + protected ComputeServiceContext computeContextForKnownArgumentsAndConstantPassword( Map requestsResponses) { return requestsSendResponses( ImmutableMap @@ -106,7 +109,7 @@ public abstract class BaseGleSYSComputeServiceExpectTest extends BaseRestClientE }).getContext(); } - protected ComputeServiceContext computeContextForKnownArgumentsAndConstantPassword() { + protected ComputeServiceContext computeContextForKnownArgumentsAndConstantPassword() { return computeContextForKnownArgumentsAndConstantPassword(ImmutableMap. of()); } } diff --git a/labs/glesys/src/test/java/org/jclouds/glesys/features/ArchiveClientExpectTest.java b/labs/glesys/src/test/java/org/jclouds/glesys/features/ArchiveClientExpectTest.java index 48d9799e66..cd284e7c16 100644 --- a/labs/glesys/src/test/java/org/jclouds/glesys/features/ArchiveClientExpectTest.java +++ b/labs/glesys/src/test/java/org/jclouds/glesys/features/ArchiveClientExpectTest.java @@ -33,7 +33,7 @@ import org.jclouds.glesys.domain.ArchiveDetails; import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpResponse; import org.jclouds.http.HttpResponseException; -import org.jclouds.rest.BaseRestClientExpectTest; +import org.jclouds.rest.internal.BaseRestClientExpectTest; import org.jclouds.rest.ResourceNotFoundException; import org.testng.annotations.Test; diff --git a/labs/glesys/src/test/java/org/jclouds/glesys/features/ArchiveClientLiveTest.java b/labs/glesys/src/test/java/org/jclouds/glesys/features/ArchiveClientLiveTest.java index 8f50fb54de..e71ca77225 100644 --- a/labs/glesys/src/test/java/org/jclouds/glesys/features/ArchiveClientLiveTest.java +++ b/labs/glesys/src/test/java/org/jclouds/glesys/features/ArchiveClientLiveTest.java @@ -28,7 +28,7 @@ import org.jclouds.glesys.domain.ArchiveAllowedArguments; import org.jclouds.glesys.domain.ArchiveDetails; import org.jclouds.glesys.internal.BaseGleSYSClientLiveTest; import org.jclouds.predicates.RetryablePredicate; -import org.testng.annotations.AfterGroups; +import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeGroups; import org.testng.annotations.Test; @@ -43,11 +43,11 @@ import com.google.common.base.Predicate; public class ArchiveClientLiveTest extends BaseGleSYSClientLiveTest { @BeforeGroups(groups = {"live"}) - public void setupClient() { - super.setupClient(); + public void setupContext() { + super.setupContext(); - client = context.getApi().getArchiveClient(); - archiveUser = context.getIdentity().toLowerCase() + "_jcloudstest9"; + client = gleContext.getApi().getArchiveClient(); + archiveUser = gleContext.getIdentity().toLowerCase() + "_jcloudstest9"; archiveCounter = new RetryablePredicate( new Predicate() { public boolean apply(Integer value){ @@ -56,13 +56,13 @@ public class ArchiveClientLiveTest extends BaseGleSYSClientLiveTest { }, 30, 1, TimeUnit.SECONDS); } - @AfterGroups(groups={"live"}) - public void tearDown() { + @AfterClass(groups = { "integration", "live" }) + protected void tearDownContext() { int before = client.listArchives().size(); client.deleteArchive(archiveUser); assertTrue(archiveCounter.apply(before - 1)); - super.tearDown(); + super.tearDownContext(); } private ArchiveClient client; diff --git a/labs/glesys/src/test/java/org/jclouds/glesys/features/DomainClientExpectTest.java b/labs/glesys/src/test/java/org/jclouds/glesys/features/DomainClientExpectTest.java index 60a9f448be..50de7966df 100644 --- a/labs/glesys/src/test/java/org/jclouds/glesys/features/DomainClientExpectTest.java +++ b/labs/glesys/src/test/java/org/jclouds/glesys/features/DomainClientExpectTest.java @@ -33,7 +33,7 @@ import org.jclouds.glesys.domain.DomainRecord; import org.jclouds.glesys.options.AddDomainOptions; import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpResponse; -import org.jclouds.rest.BaseRestClientExpectTest; +import org.jclouds.rest.internal.BaseRestClientExpectTest; import org.jclouds.rest.ResourceNotFoundException; import org.testng.annotations.Test; diff --git a/labs/glesys/src/test/java/org/jclouds/glesys/features/DomainClientLiveTest.java b/labs/glesys/src/test/java/org/jclouds/glesys/features/DomainClientLiveTest.java index db3e2fed79..78ec75774a 100644 --- a/labs/glesys/src/test/java/org/jclouds/glesys/features/DomainClientLiveTest.java +++ b/labs/glesys/src/test/java/org/jclouds/glesys/features/DomainClientLiveTest.java @@ -47,10 +47,10 @@ public class DomainClientLiveTest extends BaseGleSYSClientLiveTest { public final String testDomain = "glesystest.jclouds.org"; @BeforeGroups(groups = {"live"}) - public void setupClient() { - super.setupClient(); + public void setupContext() { + super.setupContext(); - client = context.getApi().getDomainClient(); + client = gleContext.getApi().getDomainClient(); domainCounter = new RetryablePredicate( new Predicate() { public boolean apply(Integer value) { @@ -73,12 +73,12 @@ public class DomainClientLiveTest extends BaseGleSYSClientLiveTest { } @AfterGroups(groups = {"live"}) - public void tearDown() { + public void tearDownContext() { int before = client.listDomains().size(); client.deleteDomain(testDomain); assertTrue(domainCounter.apply(before - 1)); - super.tearDown(); + super.tearDownContext(); } private DomainClient client; diff --git a/labs/glesys/src/test/java/org/jclouds/glesys/features/EmailClientExpectTest.java b/labs/glesys/src/test/java/org/jclouds/glesys/features/EmailClientExpectTest.java index 73ac1459bb..17b3a01f73 100644 --- a/labs/glesys/src/test/java/org/jclouds/glesys/features/EmailClientExpectTest.java +++ b/labs/glesys/src/test/java/org/jclouds/glesys/features/EmailClientExpectTest.java @@ -36,7 +36,7 @@ import org.jclouds.glesys.domain.EmailOverviewSummary; import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpResponse; import org.jclouds.rest.AuthorizationException; -import org.jclouds.rest.BaseRestClientExpectTest; +import org.jclouds.rest.internal.BaseRestClientExpectTest; import org.jclouds.rest.ResourceNotFoundException; import org.testng.annotations.Test; diff --git a/labs/glesys/src/test/java/org/jclouds/glesys/features/EmailClientLiveTest.java b/labs/glesys/src/test/java/org/jclouds/glesys/features/EmailClientLiveTest.java index a0bad98256..6db98945fb 100644 --- a/labs/glesys/src/test/java/org/jclouds/glesys/features/EmailClientLiveTest.java +++ b/labs/glesys/src/test/java/org/jclouds/glesys/features/EmailClientLiveTest.java @@ -48,9 +48,9 @@ import com.google.common.base.Predicate; public class EmailClientLiveTest extends BaseGleSYSClientLiveTest { @BeforeGroups(groups = {"live"}) - public void setupClient() { - super.setupClient(); - client = context.getApi().getEmailClient(); + public void setupContext() { + super.setupContext(); + client = gleContext.getApi().getEmailClient(); serverId = createServer("test-email-jclouds").getServerId(); @@ -67,13 +67,13 @@ public class EmailClientLiveTest extends BaseGleSYSClientLiveTest { } @AfterGroups(groups = {"live"}) - public void tearDown() { + public void tearDownContext() { client.delete("test@" + testDomain); client.delete("test1@" + testDomain); assertTrue(emailAccountCounter.apply(0)); - context.getApi().getDomainClient().deleteDomain(testDomain); - context.getApi().getServerClient().destroyServer(serverId, DestroyServerOptions.Builder.discardIp()); - super.tearDown(); + gleContext.getApi().getDomainClient().deleteDomain(testDomain); + gleContext.getApi().getServerClient().destroyServer(serverId, DestroyServerOptions.Builder.discardIp()); + super.tearDownContext(); } private EmailClient client; diff --git a/labs/glesys/src/test/java/org/jclouds/glesys/features/IpClientExpectTest.java b/labs/glesys/src/test/java/org/jclouds/glesys/features/IpClientExpectTest.java index 743afb1e7e..6acb032cab 100644 --- a/labs/glesys/src/test/java/org/jclouds/glesys/features/IpClientExpectTest.java +++ b/labs/glesys/src/test/java/org/jclouds/glesys/features/IpClientExpectTest.java @@ -33,7 +33,7 @@ import org.jclouds.glesys.domain.IpDetails; import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpResponse; import org.jclouds.http.HttpResponseException; -import org.jclouds.rest.BaseRestClientExpectTest; +import org.jclouds.rest.internal.BaseRestClientExpectTest; import org.testng.annotations.Test; import com.google.common.collect.ImmutableMultimap; diff --git a/labs/glesys/src/test/java/org/jclouds/glesys/features/IpClientLiveTest.java b/labs/glesys/src/test/java/org/jclouds/glesys/features/IpClientLiveTest.java index 60cbe675d7..0ba66e1ade 100644 --- a/labs/glesys/src/test/java/org/jclouds/glesys/features/IpClientLiveTest.java +++ b/labs/glesys/src/test/java/org/jclouds/glesys/features/IpClientLiveTest.java @@ -39,9 +39,9 @@ import org.testng.annotations.Test; public class IpClientLiveTest extends BaseGleSYSClientLiveTest { @BeforeGroups(groups = {"live"}) - public void setupClient() { - super.setupClient(); - client = context.getApi().getIpClient(); + public void setupContext() { + super.setupContext(); + client = gleContext.getApi().getIpClient(); } private IpClient client; diff --git a/labs/glesys/src/test/java/org/jclouds/glesys/features/ServerClientExpectTest.java b/labs/glesys/src/test/java/org/jclouds/glesys/features/ServerClientExpectTest.java index 32001b2894..53b2261dde 100644 --- a/labs/glesys/src/test/java/org/jclouds/glesys/features/ServerClientExpectTest.java +++ b/labs/glesys/src/test/java/org/jclouds/glesys/features/ServerClientExpectTest.java @@ -47,7 +47,7 @@ import org.jclouds.glesys.options.ServerStatusOptions; import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpResponse; import org.jclouds.rest.AuthorizationException; -import org.jclouds.rest.BaseRestClientExpectTest; +import org.jclouds.rest.internal.BaseRestClientExpectTest; import org.jclouds.rest.ResourceNotFoundException; import org.testng.annotations.Test; diff --git a/labs/glesys/src/test/java/org/jclouds/glesys/features/ServerClientLiveTest.java b/labs/glesys/src/test/java/org/jclouds/glesys/features/ServerClientLiveTest.java index 999578762f..6ff5e39fed 100644 --- a/labs/glesys/src/test/java/org/jclouds/glesys/features/ServerClientLiveTest.java +++ b/labs/glesys/src/test/java/org/jclouds/glesys/features/ServerClientLiveTest.java @@ -58,20 +58,20 @@ public class ServerClientLiveTest extends BaseGleSYSClientLiveTest { public static final String testHostName2 = "jclouds-test2"; @BeforeGroups(groups = {"live"}) - public void setupClient() { - super.setupClient(); - client = context.getApi().getServerClient(); + public void setupContext() { + super.setupContext(); + client = gleContext.getApi().getServerClient(); serverStatusChecker = createServer(testHostName1); testServerId = serverStatusChecker.getServerId(); } @AfterGroups(groups = {"live"}) - public void tearDown() { + public void tearDownContext() { client.destroyServer(testServerId, DestroyServerOptions.Builder.discardIp()); if (testServerId2 != null) { client.destroyServer(testServerId2, DestroyServerOptions.Builder.discardIp()); } - super.tearDown(); + super.tearDownContext(); } private ServerClient client; diff --git a/labs/glesys/src/test/java/org/jclouds/glesys/internal/BaseGleSYSAsyncClientTest.java b/labs/glesys/src/test/java/org/jclouds/glesys/internal/BaseGleSYSAsyncClientTest.java index 9f84fb9acf..ae89a53dcc 100644 --- a/labs/glesys/src/test/java/org/jclouds/glesys/internal/BaseGleSYSAsyncClientTest.java +++ b/labs/glesys/src/test/java/org/jclouds/glesys/internal/BaseGleSYSAsyncClientTest.java @@ -20,20 +20,16 @@ package org.jclouds.glesys.internal; import static org.testng.Assert.assertEquals; -import java.util.Properties; - -import org.jclouds.glesys.GleSYSAsyncClient; -import org.jclouds.glesys.GleSYSClient; +import org.jclouds.glesys.GleSYSProviderMetadata; import org.jclouds.http.HttpRequest; import org.jclouds.http.filters.BasicAuthentication; -import org.jclouds.rest.RestClientTest; -import org.jclouds.rest.RestContextFactory; -import org.jclouds.rest.RestContextSpec; +import org.jclouds.providers.ProviderMetadata; +import org.jclouds.rest.internal.BaseAsyncClientTest; /** * @author Adrian Cole */ -public abstract class BaseGleSYSAsyncClientTest extends RestClientTest { +public abstract class BaseGleSYSAsyncClientTest extends BaseAsyncClientTest { @Override protected void checkFilters(HttpRequest request) { @@ -42,8 +38,7 @@ public abstract class BaseGleSYSAsyncClientTest extends RestClientTest { } @Override - public RestContextSpec createContextSpec() { - Properties props = new Properties(); - return new RestContextFactory().createContextSpec("glesys", "username", "apiKey", props); + public ProviderMetadata createProviderMetadata() { + return new GleSYSProviderMetadata(); } } diff --git a/labs/glesys/src/test/java/org/jclouds/glesys/internal/BaseGleSYSClientLiveTest.java b/labs/glesys/src/test/java/org/jclouds/glesys/internal/BaseGleSYSClientLiveTest.java index 52ca98a804..753d78c6cb 100644 --- a/labs/glesys/src/test/java/org/jclouds/glesys/internal/BaseGleSYSClientLiveTest.java +++ b/labs/glesys/src/test/java/org/jclouds/glesys/internal/BaseGleSYSClientLiveTest.java @@ -26,9 +26,8 @@ import static org.testng.Assert.assertTrue; import java.util.UUID; import java.util.concurrent.TimeUnit; -import org.jclouds.compute.BaseVersionedServiceLiveTest; import org.jclouds.compute.ComputeServiceContext; -import org.jclouds.compute.ComputeServiceContextFactory; +import org.jclouds.compute.internal.BaseComputeServiceContextLiveTest; import org.jclouds.glesys.GleSYSAsyncClient; import org.jclouds.glesys.GleSYSClient; import org.jclouds.glesys.domain.Server; @@ -38,17 +37,12 @@ import org.jclouds.glesys.domain.ServerStatus; import org.jclouds.glesys.features.DomainClient; import org.jclouds.glesys.features.ServerClient; import org.jclouds.glesys.options.ServerStatusOptions; -import org.jclouds.logging.log4j.config.Log4JLoggingModule; import org.jclouds.predicates.RetryablePredicate; import org.jclouds.rest.RestContext; -import org.jclouds.sshj.config.SshjSshClientModule; -import org.testng.annotations.AfterGroups; import org.testng.annotations.BeforeGroups; import org.testng.annotations.Test; import com.google.common.base.Predicate; -import com.google.common.collect.ImmutableSet; -import com.google.inject.Module; /** * Tests behavior of {@code GleSYSClient} @@ -56,33 +50,25 @@ import com.google.inject.Module; * @author Adrian Cole, Adam Lowe */ @Test(groups = "live") -public class BaseGleSYSClientLiveTest extends BaseVersionedServiceLiveTest { - protected ComputeServiceContext computeContext; - protected RestContext context; +public class BaseGleSYSClientLiveTest + extends + BaseComputeServiceContextLiveTest> { + + protected RestContext gleContext; public BaseGleSYSClientLiveTest() { provider = "glesys"; } - @BeforeGroups(groups = { "live" }) - public void setupClient() { - setupCredentials(); - - computeContext = new ComputeServiceContextFactory(setupRestProperties()).createContext(provider, - ImmutableSet. of(new Log4JLoggingModule(), new SshjSshClientModule()), setupProperties()); - context = computeContext.getProviderSpecificContext(); - } - - @AfterGroups(groups = "live") - protected void tearDown() { - if (context != null) { - context.close(); - context = null; - } + @BeforeGroups(groups = { "integration", "live" }) + @Override + public void setupContext() { + super.setupContext(); + gleContext = context.getProviderSpecificContext(); } protected void createDomain(String domain) { - final DomainClient client = context.getApi().getDomainClient(); + final DomainClient client = gleContext.getApi().getDomainClient(); int before = client.listDomains().size(); client.addDomain(domain); RetryablePredicate result = new RetryablePredicate(new Predicate() { @@ -95,7 +81,7 @@ public class BaseGleSYSClientLiveTest extends BaseVersionedServiceLiveTest { } protected ServerStatusChecker createServer(String hostName) { - ServerClient client = context.getApi().getServerClient(); + ServerClient client = gleContext.getApi().getServerClient(); ServerDetails testServer = client.createServerWithHostnameAndRootPassword( ServerSpec.builder().datacenter("Falkenberg").platform("OpenVZ").templateName("Ubuntu 10.04 LTS 32-bit") diff --git a/labs/opsource-servers/src/main/java/org/jclouds/opsource/servers/OpSourceServersApiMetadata.java b/labs/opsource-servers/src/main/java/org/jclouds/opsource/servers/OpSourceServersApiMetadata.java new file mode 100644 index 0000000000..b94c0faac3 --- /dev/null +++ b/labs/opsource-servers/src/main/java/org/jclouds/opsource/servers/OpSourceServersApiMetadata.java @@ -0,0 +1,88 @@ +/** + * 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.opsource.servers; + +import java.net.URI; +import java.util.Properties; + +import org.jclouds.apis.ApiMetadata; +import org.jclouds.apis.ApiType; +import org.jclouds.rest.RestContext; +import org.jclouds.rest.internal.BaseRestApiMetadata; + +import com.google.common.reflect.TypeToken; + +/** + * Implementation of {@link ApiMetadata} for API + * + * @author Adrian Cole + */ +public class OpSourceServersApiMetadata + extends + BaseRestApiMetadata, OpSourceServersApiMetadata> { + + @Override + public Builder toBuilder() { + return new Builder().fromApiMetadata(this); + } + + public OpSourceServersApiMetadata() { + this(new Builder()); + } + + protected OpSourceServersApiMetadata(Builder builder) { + super(builder); + } + + protected static Properties defaultProperties() { + Properties properties = BaseRestApiMetadata.Builder.defaultProperties(); + return properties; + } + + public static class Builder + extends + BaseRestApiMetadata.Builder, OpSourceServersApiMetadata> { + + protected Builder() { + super(OpSourceServersClient.class, OpSourceServersAsyncClient.class); + id("opsource-servers") + .name("OpSourceServers API") + .identityName("Username") + .credentialName("API Key") + .documentation(URI.create("http://www.opsource.net/Services/Cloud-Hosting/Open-API")) + .version("0.9") + .defaultEndpoint("https://api.opsourcecloud.net/oec/${jclouds.api-version}") + .type(ApiType.COMPUTE) + .contextBuilder(TypeToken.of(OpSourceServersContextBuilder.class)); + } + + @Override + public OpSourceServersApiMetadata build() { + return new OpSourceServersApiMetadata(this); + } + + @Override + public Builder fromApiMetadata(OpSourceServersApiMetadata in) { + super.fromApiMetadata(in); + return this; + } + + } + +} diff --git a/labs/opsource-servers/src/main/java/org/jclouds/opsource/servers/OpSourceServersContextBuilder.java b/labs/opsource-servers/src/main/java/org/jclouds/opsource/servers/OpSourceServersContextBuilder.java index c174722015..ab7ef8b6e9 100644 --- a/labs/opsource-servers/src/main/java/org/jclouds/opsource/servers/OpSourceServersContextBuilder.java +++ b/labs/opsource-servers/src/main/java/org/jclouds/opsource/servers/OpSourceServersContextBuilder.java @@ -19,23 +19,36 @@ package org.jclouds.opsource.servers; import java.util.List; -import java.util.Properties; import org.jclouds.opsource.servers.config.OpSourceServersRestClientModule; +import org.jclouds.providers.ProviderMetadata; +import org.jclouds.rest.RestContext; import org.jclouds.rest.RestContextBuilder; import com.google.inject.Module; /** + * * @author Adrian Cole */ -public class OpSourceServersContextBuilder extends RestContextBuilder { +public class OpSourceServersContextBuilder + extends + RestContextBuilder, OpSourceServersApiMetadata> { - public OpSourceServersContextBuilder(Properties props) { - super(OpSourceServersClient.class, OpSourceServersAsyncClient.class, props); + public OpSourceServersContextBuilder( + ProviderMetadata, OpSourceServersApiMetadata> providerMetadata) { + super(providerMetadata); } - @Override + public OpSourceServersContextBuilder(OpSourceServersApiMetadata apiMetadata) { + super(apiMetadata); + } +// +// @Override +// protected void addContextModule(List modules) { +// modules.add(new OpSourceServersComputeServiceContextModule()); +// } + protected void addClientModule(List modules) { modules.add(new OpSourceServersRestClientModule()); } diff --git a/labs/opsource-servers/src/main/java/org/jclouds/opsource/servers/OpSourceServersPropertiesBuilder.java b/labs/opsource-servers/src/main/java/org/jclouds/opsource/servers/OpSourceServersPropertiesBuilder.java deleted file mode 100644 index 28cc359507..0000000000 --- a/labs/opsource-servers/src/main/java/org/jclouds/opsource/servers/OpSourceServersPropertiesBuilder.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * 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.opsource.servers; - -import static org.jclouds.Constants.PROPERTY_API_VERSION; -import static org.jclouds.Constants.PROPERTY_ENDPOINT; - -import java.util.Properties; - -import org.jclouds.PropertiesBuilder; - -/** - * Builds properties used in OpSourceServers clients - * - * @author Adrian Cole - */ -public class OpSourceServersPropertiesBuilder extends PropertiesBuilder { - - @Override - public Properties defaultProperties() { - Properties properties = super.defaultProperties(); - properties.setProperty(PROPERTY_ENDPOINT, "https://api.opsourcecloud.net/oec/${jclouds.api-version}"); - properties.setProperty(PROPERTY_API_VERSION, "0.9"); - return properties; - } - - public OpSourceServersPropertiesBuilder(Properties properties) { - super(properties); - } - -} diff --git a/labs/opsource-servers/src/main/resources/META-INF/services/org.jclouds.apis.ApiMetadata b/labs/opsource-servers/src/main/resources/META-INF/services/org.jclouds.apis.ApiMetadata new file mode 100644 index 0000000000..24f893d882 --- /dev/null +++ b/labs/opsource-servers/src/main/resources/META-INF/services/org.jclouds.apis.ApiMetadata @@ -0,0 +1 @@ +org.jclouds.opsource.servers.OpSourceServersApiMetadata \ No newline at end of file diff --git a/labs/opsource-servers/src/test/java/org/jclouds/opsource/servers/OpSourceServersClientExperimentLiveTest.java b/labs/opsource-servers/src/test/java/org/jclouds/opsource/servers/OpSourceServersClientExperimentLiveTest.java index 584a74709d..f21e36cae6 100644 --- a/labs/opsource-servers/src/test/java/org/jclouds/opsource/servers/OpSourceServersClientExperimentLiveTest.java +++ b/labs/opsource-servers/src/test/java/org/jclouds/opsource/servers/OpSourceServersClientExperimentLiveTest.java @@ -30,7 +30,7 @@ import org.testng.annotations.Test; public class OpSourceServersClientExperimentLiveTest extends BaseOpSourceServersClientLiveTest { public void testImplicitSession() { - Account account = context.getApi().getAccountClient().getMyAccount(); + Account account = restContext.getApi().getAccountClient().getMyAccount(); assert account.getOrgId() != null; } diff --git a/labs/opsource-servers/src/test/java/org/jclouds/opsource/servers/features/AccountClientLiveTest.java b/labs/opsource-servers/src/test/java/org/jclouds/opsource/servers/features/AccountClientLiveTest.java index 6028ffcec6..c2fe4e8293 100644 --- a/labs/opsource-servers/src/test/java/org/jclouds/opsource/servers/features/AccountClientLiveTest.java +++ b/labs/opsource-servers/src/test/java/org/jclouds/opsource/servers/features/AccountClientLiveTest.java @@ -32,14 +32,14 @@ import org.testng.annotations.Test; public class AccountClientLiveTest extends BaseOpSourceServersClientLiveTest { public void testGetMyAccount() { - Account account = context.getApi().getAccountClient().getMyAccount(); + Account account = restContext.getApi().getAccountClient().getMyAccount(); assert account.getOrgId() != null; } public void testGetDataCenterWithLimits() { - Account account = context.getApi().getAccountClient().getMyAccount(); + Account account = restContext.getApi().getAccountClient().getMyAccount(); assert account.getOrgId() != null; - DataCentersList dataCentersList = context.getApi().getAccountClient().getDataCentersWithLimits(account.getOrgId()); + DataCentersList dataCentersList = restContext.getApi().getAccountClient().getDataCentersWithLimits(account.getOrgId()); assert dataCentersList != null; } diff --git a/labs/opsource-servers/src/test/java/org/jclouds/opsource/servers/features/ServerClientLiveTest.java b/labs/opsource-servers/src/test/java/org/jclouds/opsource/servers/features/ServerClientLiveTest.java index 672f1700d1..e31ddab658 100644 --- a/labs/opsource-servers/src/test/java/org/jclouds/opsource/servers/features/ServerClientLiveTest.java +++ b/labs/opsource-servers/src/test/java/org/jclouds/opsource/servers/features/ServerClientLiveTest.java @@ -33,16 +33,16 @@ import org.testng.annotations.Test; public class ServerClientLiveTest extends BaseOpSourceServersClientLiveTest { public void testGetDeployedServers() { - Account account = context.getApi().getAccountClient().getMyAccount(); + Account account = restContext.getApi().getAccountClient().getMyAccount(); assert account.getOrgId() != null; - DeployedServersList deployedServersList = context.getApi().getServerClient().getDeployedServers(account.getOrgId()); + DeployedServersList deployedServersList = restContext.getApi().getServerClient().getDeployedServers(account.getOrgId()); assert deployedServersList != null; } public void testGetPendingDeployServers() { - Account account = context.getApi().getAccountClient().getMyAccount(); + Account account = restContext.getApi().getAccountClient().getMyAccount(); assert account.getOrgId() != null; - PendingDeployServersList pendingDeployServersList = context.getApi().getServerClient().getPendingDeployServers(account.getOrgId()); + PendingDeployServersList pendingDeployServersList = restContext.getApi().getServerClient().getPendingDeployServers(account.getOrgId()); assert pendingDeployServersList != null; } diff --git a/labs/opsource-servers/src/test/java/org/jclouds/opsource/servers/features/ServerImageClientLiveTest.java b/labs/opsource-servers/src/test/java/org/jclouds/opsource/servers/features/ServerImageClientLiveTest.java index d55e155438..0430698758 100644 --- a/labs/opsource-servers/src/test/java/org/jclouds/opsource/servers/features/ServerImageClientLiveTest.java +++ b/labs/opsource-servers/src/test/java/org/jclouds/opsource/servers/features/ServerImageClientLiveTest.java @@ -31,7 +31,7 @@ import org.testng.annotations.Test; public class ServerImageClientLiveTest extends BaseOpSourceServersClientLiveTest { public void testGetServerImages() { - ServerImagesList serverImagesList = context.getApi().getServerImageClient().getServerImages(); + ServerImagesList serverImagesList = restContext.getApi().getServerImageClient().getServerImages(); assert serverImagesList != null; } diff --git a/labs/opsource-servers/src/test/java/org/jclouds/opsource/servers/internal/BaseOpSourceServersClientLiveTest.java b/labs/opsource-servers/src/test/java/org/jclouds/opsource/servers/internal/BaseOpSourceServersClientLiveTest.java index 9aba439acb..3d6ee073f0 100644 --- a/labs/opsource-servers/src/test/java/org/jclouds/opsource/servers/internal/BaseOpSourceServersClientLiveTest.java +++ b/labs/opsource-servers/src/test/java/org/jclouds/opsource/servers/internal/BaseOpSourceServersClientLiveTest.java @@ -18,21 +18,14 @@ */ package org.jclouds.opsource.servers.internal; -import java.util.Properties; - -import org.jclouds.compute.BaseVersionedServiceLiveTest; -import org.jclouds.logging.log4j.config.Log4JLoggingModule; +import org.jclouds.compute.ComputeServiceContext; +import org.jclouds.compute.internal.BaseComputeServiceContextLiveTest; import org.jclouds.opsource.servers.OpSourceServersAsyncClient; import org.jclouds.opsource.servers.OpSourceServersClient; import org.jclouds.rest.RestContext; -import org.jclouds.rest.RestContextFactory; -import org.jclouds.sshj.config.SshjSshClientModule; -import org.testng.annotations.BeforeClass; +import org.testng.annotations.BeforeGroups; import org.testng.annotations.Test; -import com.google.common.collect.ImmutableSet; -import com.google.inject.Module; - /** * Tests behavior of {@link OpSourceServersClient} and acts as parent for other * client live tests. @@ -40,25 +33,21 @@ import com.google.inject.Module; * @author Adrian Cole */ @Test(groups = "live") -public abstract class BaseOpSourceServersClientLiveTest extends BaseVersionedServiceLiveTest { +public abstract class BaseOpSourceServersClientLiveTest + extends + BaseComputeServiceContextLiveTest> { protected BaseOpSourceServersClientLiveTest() { provider = "opsource-servers"; } - protected RestContext context; + protected RestContext restContext; - @BeforeClass(groups = { "live" }) + @BeforeGroups(groups = { "integration", "live" }) + @Override public void setupContext() { - setupCredentials(); - Properties overrides = setupProperties(); - - context = new RestContextFactory().createContext(provider, identity, credential, - ImmutableSet. of(new Log4JLoggingModule(), new SshjSshClientModule()), overrides); + super.setupContext(); + restContext = context.getProviderSpecificContext(); } - protected void tearDown() { - if (context != null) - context.close(); - } } diff --git a/labs/opsource-servers/src/test/java/org/jclouds/opsource/servers/internal/BaseOpSourceServersRestClientExpectTest.java b/labs/opsource-servers/src/test/java/org/jclouds/opsource/servers/internal/BaseOpSourceServersRestClientExpectTest.java index c5720cd222..217fedf1e6 100644 --- a/labs/opsource-servers/src/test/java/org/jclouds/opsource/servers/internal/BaseOpSourceServersRestClientExpectTest.java +++ b/labs/opsource-servers/src/test/java/org/jclouds/opsource/servers/internal/BaseOpSourceServersRestClientExpectTest.java @@ -18,8 +18,10 @@ */ package org.jclouds.opsource.servers.internal; +import org.jclouds.apis.ApiMetadata; +import org.jclouds.opsource.servers.OpSourceServersApiMetadata; import org.jclouds.opsource.servers.OpSourceServersClient; -import org.jclouds.rest.BaseRestClientExpectTest; +import org.jclouds.rest.internal.BaseRestClientExpectTest; /** * Base class for writing OpSourceServersClient Expect tests @@ -34,4 +36,8 @@ public class BaseOpSourceServersRestClientExpectTest extends BaseRestClientExpec credential = "password"; } + @Override + protected ApiMetadata createApiMetadata() { + return new OpSourceServersApiMetadata(); + } } diff --git a/labs/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/SavvisSymphonyVPDCApiMetadata.java b/labs/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/SavvisSymphonyVPDCApiMetadata.java deleted file mode 100644 index 718387b1af..0000000000 --- a/labs/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/SavvisSymphonyVPDCApiMetadata.java +++ /dev/null @@ -1,50 +0,0 @@ -package org.jclouds.savvis.vpdc; - -import java.net.URI; - -import org.jclouds.apis.ApiMetadata; -import org.jclouds.apis.ApiType; -import org.jclouds.apis.BaseApiMetadata; - -/** - * Implementation of {@link ApiMetadata} for the Savvis Symphony VPDC API - * - * @author Adrian Cole - */ -public class SavvisSymphonyVPDCApiMetadata extends BaseApiMetadata { - - public SavvisSymphonyVPDCApiMetadata() { - this(builder() - .id("savvis-symphonyvpdc") - .type(ApiType.COMPUTE) - .name("Savvis Symphony VPDC API") - .identityName("Username") - .credentialName("Password") - .documentation(URI.create("https://api.savvis.net/doc/spec/api/index.html"))); - } - - // below are so that we can reuse builders, toString, hashCode, etc. - // we have to set concrete classes here, as our base class cannot be - // concrete due to serviceLoader - protected SavvisSymphonyVPDCApiMetadata(Builder builder) { - super(builder); - } - - private static class ConcreteBuilder extends Builder { - - @Override - public SavvisSymphonyVPDCApiMetadata build() { - return new SavvisSymphonyVPDCApiMetadata(this); - } - } - - public static ConcreteBuilder builder() { - return new ConcreteBuilder(); - } - - @Override - public ConcreteBuilder toBuilder() { - return builder().fromApiMetadata(this); - } - -} \ No newline at end of file diff --git a/labs/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/SavvisSymphonyVPDCProviderMetadata.java b/labs/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/SavvisSymphonyVPDCProviderMetadata.java deleted file mode 100644 index 35319e9195..0000000000 --- a/labs/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/SavvisSymphonyVPDCProviderMetadata.java +++ /dev/null @@ -1,99 +0,0 @@ -/** - * 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.savvis.vpdc; - -import java.net.URI; - -import org.jclouds.providers.BaseProviderMetadata; - -/** - * Implementation of {@link org.jclouds.types.ProviderMetadata} for Savvis Symphony VPDC services. - * - * @author Kedar Dave - */ -public class SavvisSymphonyVPDCProviderMetadata extends BaseProviderMetadata { - public SavvisSymphonyVPDCProviderMetadata() { - this(builder() - .id("savvis-symphonyvpdc") - .name("Savvis Symphony VPDC") - .api(new SavvisSymphonyVPDCApiMetadata()) - .homepage(URI.create("https://api.savvis.net/doc/spec/api/index.html")) - .console(URI.create("https://www.savvisstation.com")) - /** - * {@inheritDoc} - * list of data centers from savvisstation colocation guide - * https://www.savvisstation.com/DocumentViewer?GUID=a95f0387-cbfe-43eb-b25b-4f2b0f68498f&sessionid=SavvisCCC%3ac9a8984b9655b01916be587e5204b2cf - * Once we have confirmation from Savvis as to what data centers are used for vpdc deployments, - * iso codes for those will be entered here - * - * City Code - * Lithia Springs, GA AT1 - * Waltham, MA BO1 - * Waltham, MA BO2 - * Waltham, MA B03 - * Elk Grove Village, IL CH3 - * Chicago, IL CH4 - * Sterling, VA DC2 - * Sterling, VA DC3 - * Sterling, VA DC4 Phase I - * Sterling, VA DC4 Phase II - * Fort Worth, TX DL1 - * Fort Worth, TX DL2 - * El Segundo, CA LA1 - * Jersey City, NJ NJ1 - * Weehawken, NJ NJ2 - * Piscataway, NJ NJ3 - * Piscataway, NJ 2nd floor NJ3 - * Weehawken, NJ NJ2X - * Irvine, CA OC2 - * Santa Clara, CA SC4 - * Santa Clara, CA SC5 - * Santa Clara, CA SC8 - * Santa Clara, CA SC9 - * Tukwila, WA 1st floor SE2 - * Montreal, Canada MR1 - * Toronto, Canada TR1 - * Vancouver, Canada VC1 - */ - .iso3166Codes("US", "CA")); - } - - // below are so that we can reuse builders, toString, hashCode, etc. - // we have to set concrete classes here, as our base class cannot be - // concrete due to serviceLoader - protected SavvisSymphonyVPDCProviderMetadata(ConcreteBuilder builder) { - super(builder); - } - - private static class ConcreteBuilder extends Builder { - - @Override - public SavvisSymphonyVPDCProviderMetadata build() { - return new SavvisSymphonyVPDCProviderMetadata(this); - } - } - - public static ConcreteBuilder builder() { - return new ConcreteBuilder(); - } - - public ConcreteBuilder toBuilder() { - return builder().fromProviderMetadata(this); - } -} \ No newline at end of file diff --git a/labs/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/VPDCApiMetadata.java b/labs/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/VPDCApiMetadata.java new file mode 100644 index 0000000000..cf25f6862e --- /dev/null +++ b/labs/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/VPDCApiMetadata.java @@ -0,0 +1,92 @@ +/** + * 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.savvis.vpdc; + +import static org.jclouds.savvis.vpdc.reference.VPDCConstants.PROPERTY_VPDC_TIMEOUT_TASK_COMPLETED; + +import java.net.URI; +import java.util.Properties; + +import org.jclouds.apis.ApiType; +import org.jclouds.compute.ComputeServiceContext; +import org.jclouds.compute.internal.BaseComputeServiceApiMetadata; + +import com.google.common.reflect.TypeToken; + +/** + * Implementation of {@link org.jclouds.types.ApiMetadata} for Savvis Symphony VPDC services. + * + * @author Kedar Dave + */ +public class VPDCApiMetadata + extends + BaseComputeServiceApiMetadata, VPDCApiMetadata> { + + @Override + public Builder toBuilder() { + return new Builder().fromApiMetadata(this); + } + + public VPDCApiMetadata() { + this(new Builder()); + } + + protected VPDCApiMetadata(Builder builder) { + super(builder); + } + + protected static Properties defaultProperties() { + Properties properties = BaseComputeServiceApiMetadata.Builder.defaultProperties(); + properties.setProperty(PROPERTY_VPDC_TIMEOUT_TASK_COMPLETED, 600l * 1000l + ""); + return properties; + } + + public static class Builder + extends + BaseComputeServiceApiMetadata.Builder, VPDCApiMetadata> { + + protected Builder() { + id("savvis-symphonyvpdc") + .type(ApiType.COMPUTE) + .name("Savvis Symphony VPDC API") + .identityName("Username") + .credentialName("Password") + .documentation(URI.create("https://api.savvis.net/doc/spec/api/index.html")) + .version("1.0") + .buildVersion("2.3") + .defaultEndpoint("https://api.savvis.net/vpdc") + .defaultProperties(VPDCApiMetadata.defaultProperties()) + .javaApi(VPDCClient.class, VPDCAsyncClient.class) + .contextBuilder(TypeToken.of(VPDCContextBuilder.class)); + } + + @Override + public VPDCApiMetadata build() { + return new VPDCApiMetadata(this); + } + + @Override + public Builder fromApiMetadata(VPDCApiMetadata in) { + super.fromApiMetadata(in); + return this; + } + + } + +} diff --git a/labs/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/VPDCContextBuilder.java b/labs/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/VPDCContextBuilder.java index a321f8c384..6934caea2e 100644 --- a/labs/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/VPDCContextBuilder.java +++ b/labs/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/VPDCContextBuilder.java @@ -19,9 +19,10 @@ package org.jclouds.savvis.vpdc; import java.util.List; -import java.util.Properties; +import org.jclouds.compute.ComputeServiceContext; import org.jclouds.compute.ComputeServiceContextBuilder; +import org.jclouds.providers.ProviderMetadata; import org.jclouds.savvis.vpdc.compute.config.VPDCComputeServiceContextModule; import org.jclouds.savvis.vpdc.config.VPDCRestClientModule; @@ -31,14 +32,17 @@ import com.google.inject.Module; * * @author Adrian Cole */ -public class VPDCContextBuilder extends ComputeServiceContextBuilder { +public class VPDCContextBuilder + extends + ComputeServiceContextBuilder, VPDCApiMetadata> { - public VPDCContextBuilder(Properties props) { - super(VPDCClient.class, VPDCAsyncClient.class, props); + public VPDCContextBuilder( + ProviderMetadata, VPDCApiMetadata> providerMetadata) { + super(providerMetadata); } - protected void addClientModule(List modules) { - modules.add(new VPDCRestClientModule()); + public VPDCContextBuilder(VPDCApiMetadata apiMetadata) { + super(apiMetadata); } @Override @@ -46,4 +50,8 @@ public class VPDCContextBuilder extends ComputeServiceContextBuilder modules) { + modules.add(new VPDCRestClientModule()); + } + } diff --git a/labs/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/VPDCProviderMetadata.java b/labs/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/VPDCProviderMetadata.java new file mode 100644 index 0000000000..31bbf4ccc7 --- /dev/null +++ b/labs/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/VPDCProviderMetadata.java @@ -0,0 +1,123 @@ +/** + * 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.savvis.vpdc; + +import java.net.URI; +import java.util.Properties; + +import org.jclouds.compute.ComputeServiceContext; +import org.jclouds.providers.ProviderMetadata; +import org.jclouds.providers.internal.BaseProviderMetadata; + +/** + * Implementation of {@link org.jclouds.types.ProviderMetadata} for Savvis Symphony VPDC services. + * + * @author Kedar Dave + */ +public class VPDCProviderMetadata + extends + BaseProviderMetadata, VPDCApiMetadata> { + + public static Builder builder() { + return new Builder(); + } + + @Override + public Builder toBuilder() { + return builder().fromProviderMetadata(this); + } + + public VPDCProviderMetadata() { + super(builder()); + } + + public VPDCProviderMetadata(Builder builder) { + super(builder); + } + + protected static Properties defaultProperties() { + Properties properties = new Properties(); + return properties; + } + + public static class Builder + extends + BaseProviderMetadata.Builder, VPDCApiMetadata> { + + protected Builder() { + id("savvis-symphonyvpdc") + .name("Savvis Symphony VPDC") + .apiMetadata(new VPDCApiMetadata()) + .homepage(URI.create("https://api.savvis.net/doc/spec/api/index.html")) + .console(URI.create("https://www.savvisstation.com")) + /** + * {@inheritDoc} + * list of data centers from savvisstation colocation guide + * https://www.savvisstation.com/DocumentViewer?GUID=a95f0387-cbfe-43eb-b25b-4f2b0f68498f&sessionid=SavvisCCC%3ac9a8984b9655b01916be587e5204b2cf + * Once we have confirmation from Savvis as to what data centers are used for vpdc deployments, + * iso codes for those will be entered here + * + * City Code + * Lithia Springs, GA AT1 +* Waltham, MA BO1 +* Waltham, MA BO2 +* Waltham, MA B03 +* Elk Grove Village, IL CH3 +* Chicago, IL CH4 +* Sterling, VA DC2 +* Sterling, VA DC3 +* Sterling, VA DC4 Phase I +* Sterling, VA DC4 Phase II +* Fort Worth, TX DL1 +* Fort Worth, TX DL2 +* El Segundo, CA LA1 +* Jersey City, NJ NJ1 +* Weehawken, NJ NJ2 +* Piscataway, NJ NJ3 +* Piscataway, NJ 2nd floor NJ3 +* Weehawken, NJ NJ2X +* Irvine, CA OC2 +* Santa Clara, CA SC4 +* Santa Clara, CA SC5 +* Santa Clara, CA SC8 +* Santa Clara, CA SC9 +* Tukwila, WA 1st floor SE2 +* Montreal, Canada MR1 +* Toronto, Canada TR1 +* Vancouver, Canada VC1 + */ + .iso3166Codes("US", "CA") + .endpoint("https://api.savvis.net/vpdc") + .defaultProperties(VPDCProviderMetadata.defaultProperties()); + } + + @Override + public VPDCProviderMetadata build() { + return new VPDCProviderMetadata(this); + } + + @Override + public Builder fromProviderMetadata( + ProviderMetadata, VPDCApiMetadata> in) { + super.fromProviderMetadata(in); + return this; + } + + } +} \ No newline at end of file diff --git a/labs/savvis-symphonyvpdc/src/main/resources/META-INF/services/org.jclouds.providers.ProviderMetadata b/labs/savvis-symphonyvpdc/src/main/resources/META-INF/services/org.jclouds.providers.ProviderMetadata index ab54604528..04552f7f96 100644 --- a/labs/savvis-symphonyvpdc/src/main/resources/META-INF/services/org.jclouds.providers.ProviderMetadata +++ b/labs/savvis-symphonyvpdc/src/main/resources/META-INF/services/org.jclouds.providers.ProviderMetadata @@ -1 +1 @@ -org.jclouds.savvis.vpdc.SavvisSymphonyVPDCProviderMetadata \ No newline at end of file +org.jclouds.savvis.vpdc.VPDCProviderMetadata \ No newline at end of file diff --git a/labs/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/SavvisSymphonyVPDCProviderTest.java b/labs/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/VPDCProviderTest.java similarity index 66% rename from labs/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/SavvisSymphonyVPDCProviderTest.java rename to labs/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/VPDCProviderTest.java index 9bbca2f6a3..8e4972d44b 100644 --- a/labs/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/SavvisSymphonyVPDCProviderTest.java +++ b/labs/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/VPDCProviderTest.java @@ -18,19 +18,19 @@ */ package org.jclouds.savvis.vpdc; -import org.jclouds.providers.BaseProviderMetadataTest; +import org.jclouds.providers.internal.BaseProviderMetadataTest; import org.testng.annotations.Test; /** - * The SavvisSymphonyVPDCProviderTest tests the - * org.jclouds.savvis.vpdc.SavvisSymphonyVPDCProviderMetadata class. + * The VPDCProviderTest tests the + * org.jclouds.savvis.vpdc.VPDCProviderMetadata class. * * @author Kedar Dave */ -@Test(groups = "unit", testName = "SavvisSymphonyVPDCProviderTest") -public class SavvisSymphonyVPDCProviderTest extends BaseProviderMetadataTest { +@Test(groups = "unit", testName = "VPDCProviderTest") +public class VPDCProviderTest extends BaseProviderMetadataTest { - public SavvisSymphonyVPDCProviderTest() { - super(new SavvisSymphonyVPDCProviderMetadata(), new SavvisSymphonyVPDCApiMetadata()); + public VPDCProviderTest() { + super(new VPDCProviderMetadata(), new VPDCApiMetadata()); } } \ No newline at end of file diff --git a/labs/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/compute/VPDCComputeServiceLiveTestDisabled.java b/labs/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/compute/VPDCComputeServiceLiveTestDisabled.java index d1bcf26dab..2c56d36d61 100644 --- a/labs/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/compute/VPDCComputeServiceLiveTestDisabled.java +++ b/labs/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/compute/VPDCComputeServiceLiveTestDisabled.java @@ -21,8 +21,11 @@ package org.jclouds.savvis.vpdc.compute; import java.util.Properties; import org.jclouds.Constants; -import org.jclouds.compute.BaseComputeServiceLiveTest; +import org.jclouds.compute.ComputeServiceContext; import org.jclouds.compute.domain.NodeMetadata; +import org.jclouds.compute.internal.BaseComputeServiceLiveTest; +import org.jclouds.savvis.vpdc.VPDCAsyncClient; +import org.jclouds.savvis.vpdc.VPDCClient; import org.jclouds.sshj.config.SshjSshClientModule; import org.testng.annotations.Test; @@ -38,7 +41,9 @@ import com.google.inject.Module; * */ @Test(enabled = true, groups = "live") -public class VPDCComputeServiceLiveTestDisabled extends BaseComputeServiceLiveTest { +public class VPDCComputeServiceLiveTestDisabled + extends + BaseComputeServiceLiveTest> { public VPDCComputeServiceLiveTestDisabled() { provider = "savvis-symphonyvpdc"; diff --git a/labs/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/compute/VPDCTemplateBuilderLiveTest.java b/labs/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/compute/VPDCTemplateBuilderLiveTest.java index ce763a95ea..f545316887 100644 --- a/labs/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/compute/VPDCTemplateBuilderLiveTest.java +++ b/labs/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/compute/VPDCTemplateBuilderLiveTest.java @@ -26,11 +26,14 @@ import java.io.IOException; import java.util.Properties; import java.util.Set; -import org.jclouds.compute.BaseTemplateBuilderLiveTest; +import org.jclouds.compute.ComputeServiceContext; import org.jclouds.compute.domain.OsFamily; import org.jclouds.compute.domain.OsFamilyVersion64Bit; import org.jclouds.compute.domain.Template; +import org.jclouds.compute.internal.BaseTemplateBuilderLiveTest; import org.jclouds.domain.LocationScope; +import org.jclouds.savvis.vpdc.VPDCAsyncClient; +import org.jclouds.savvis.vpdc.VPDCClient; import org.jclouds.savvis.vpdc.reference.VPDCConstants; import org.testng.annotations.Test; @@ -42,7 +45,8 @@ import com.google.common.collect.ImmutableSet; * @author Adrian Cole */ @Test(groups = "live") -public class VPDCTemplateBuilderLiveTest extends BaseTemplateBuilderLiveTest { +public class VPDCTemplateBuilderLiveTest extends + BaseTemplateBuilderLiveTest> { public VPDCTemplateBuilderLiveTest() { provider = "savvis-symphonyvpdc"; diff --git a/labs/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/features/BaseVPDCAsyncClientTest.java b/labs/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/features/BaseVPDCAsyncClientTest.java index 1e5c6c75b6..6d3674979e 100644 --- a/labs/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/features/BaseVPDCAsyncClientTest.java +++ b/labs/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/features/BaseVPDCAsyncClientTest.java @@ -29,12 +29,10 @@ import javax.inject.Named; import org.jclouds.http.HttpRequest; import org.jclouds.http.RequiresHttp; +import org.jclouds.providers.ProviderMetadata; import org.jclouds.rest.ConfiguresRestClient; -import org.jclouds.rest.RestClientTest; -import org.jclouds.rest.RestContextFactory; -import org.jclouds.rest.RestContextSpec; -import org.jclouds.savvis.vpdc.VPDCAsyncClient; -import org.jclouds.savvis.vpdc.VPDCClient; +import org.jclouds.rest.internal.BaseAsyncClientTest; +import org.jclouds.savvis.vpdc.VPDCProviderMetadata; import org.jclouds.savvis.vpdc.config.VPDCRestClientModule; import org.jclouds.savvis.vpdc.domain.Resource; import org.jclouds.savvis.vpdc.domain.ResourceImpl; @@ -52,12 +50,11 @@ import com.google.inject.Module; /** * @author Adrian Cole */ -public abstract class BaseVPDCAsyncClientTest extends RestClientTest { +public abstract class BaseVPDCAsyncClientTest extends BaseAsyncClientTest { @Override - public RestContextSpec createContextSpec() { - Properties props = new Properties(); - return new RestContextFactory().createContextSpec("savvis-symphonyvpdc", "apiKey", "secretKey", props); + public ProviderMetadata createProviderMetadata() { + return new VPDCProviderMetadata(); } @Override diff --git a/labs/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/features/BaseVPDCClientLiveTest.java b/labs/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/features/BaseVPDCClientLiveTest.java index be21aa3099..9219137347 100644 --- a/labs/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/features/BaseVPDCClientLiveTest.java +++ b/labs/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/features/BaseVPDCClientLiveTest.java @@ -23,47 +23,35 @@ import static com.google.common.base.Preconditions.checkNotNull; import java.util.Properties; import java.util.concurrent.TimeUnit; -import org.jclouds.compute.BaseVersionedServiceLiveTest; import org.jclouds.compute.ComputeServiceContext; -import org.jclouds.compute.ComputeServiceContextFactory; -import org.jclouds.logging.log4j.config.Log4JLoggingModule; +import org.jclouds.compute.internal.BaseComputeServiceContextLiveTest; import org.jclouds.predicates.RetryablePredicate; import org.jclouds.rest.RestContext; import org.jclouds.savvis.vpdc.VPDCAsyncClient; import org.jclouds.savvis.vpdc.VPDCClient; import org.jclouds.savvis.vpdc.predicates.TaskSuccess; import org.jclouds.savvis.vpdc.reference.VPDCConstants; -import org.jclouds.sshj.config.SshjSshClientModule; -import org.testng.annotations.AfterGroups; import org.testng.annotations.BeforeGroups; import org.testng.annotations.Test; -import com.google.common.collect.ImmutableSet; -import com.google.inject.Module; - /** * Tests behavior of {@code VPDCClient} * * @author Adrian Cole */ @Test(groups = "live", singleThreaded = true, testName = "BaseVPDCClientLiveTest") -public class BaseVPDCClientLiveTest extends BaseVersionedServiceLiveTest { +public class BaseVPDCClientLiveTest + extends + BaseComputeServiceContextLiveTest> { + public BaseVPDCClientLiveTest() { provider = "savvis-symphonyvpdc"; } protected RestContext restContext; - protected ComputeServiceContext context; protected String email; protected RetryablePredicate taskTester; - @Override - protected void setupCredentials() { - super.setupCredentials(); - email = checkNotNull(System.getProperty("test." + VPDCConstants.PROPERTY_VPDC_VDC_EMAIL), "test." - + VPDCConstants.PROPERTY_VPDC_VDC_EMAIL); - } - @Override protected Properties setupProperties() { Properties overrides = super.setupProperties(); @@ -71,23 +59,16 @@ public class BaseVPDCClientLiveTest extends BaseVersionedServiceLiveTest { // unlimited timeouts overrides.setProperty("jclouds.connection-timeout", "0"); overrides.setProperty("jclouds.so-timeout", "0"); + email = checkNotNull(System.getProperty("test." + VPDCConstants.PROPERTY_VPDC_VDC_EMAIL), "test." + + VPDCConstants.PROPERTY_VPDC_VDC_EMAIL); return overrides; } - @BeforeGroups(groups = { "live" }) - public void setupClient() { - setupCredentials(); - Properties overrides = setupProperties(); - context = new ComputeServiceContextFactory().createContext(provider, ImmutableSet. of( - new Log4JLoggingModule(), new SshjSshClientModule()), overrides); - restContext = context.getProviderSpecificContext(); + @BeforeGroups(groups = { "integration", "live" }) + @Override + public void setupContext() { + super.setupContext(); taskTester = new RetryablePredicate(new TaskSuccess(restContext.getApi()), 7200, 10, TimeUnit.SECONDS); } - @AfterGroups(groups = "live") - protected void tearDown() { - if (context != null) - context.close(); - } - } diff --git a/labs/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/features/BrowsingClientLiveTest.java b/labs/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/features/BrowsingClientLiveTest.java index 4a1f020126..7b1b484793 100644 --- a/labs/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/features/BrowsingClientLiveTest.java +++ b/labs/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/features/BrowsingClientLiveTest.java @@ -49,8 +49,8 @@ public class BrowsingClientLiveTest extends BaseVPDCClientLiveTest { @Override @BeforeGroups(groups = { "live" }) - public void setupClient() { - super.setupClient(); + public void setupContext() { + super.setupContext(); client = restContext.getApi().getBrowsingClient(); } diff --git a/labs/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/features/FirewallClientLiveTest.java b/labs/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/features/FirewallClientLiveTest.java index 3cf8586404..0c8fcbe7b0 100644 --- a/labs/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/features/FirewallClientLiveTest.java +++ b/labs/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/features/FirewallClientLiveTest.java @@ -21,7 +21,6 @@ package org.jclouds.savvis.vpdc.features; import org.jclouds.savvis.vpdc.domain.FirewallRule; import org.jclouds.savvis.vpdc.domain.Resource; import org.jclouds.savvis.vpdc.domain.Task; -import org.testng.annotations.AfterGroups; import org.testng.annotations.BeforeGroups; import org.testng.annotations.Test; @@ -36,8 +35,8 @@ public class FirewallClientLiveTest extends BaseVPDCClientLiveTest { @Override @BeforeGroups(groups = { "live" }) - public void setupClient() { - super.setupClient(); + public void setupContext() { + super.setupContext(); client = restContext.getApi().getFirewallClient(); } @@ -110,10 +109,4 @@ public class FirewallClientLiveTest extends BaseVPDCClientLiveTest { assert this.taskTester.apply(task.getId()); } - - @AfterGroups(groups = "live") - protected void tearDown() { - //TODO cleanup resources - super.tearDown(); - } } \ No newline at end of file diff --git a/labs/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/features/ServiceManagementClientLiveTest.java b/labs/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/features/ServiceManagementClientLiveTest.java index 7dab3a5015..3565efb42c 100644 --- a/labs/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/features/ServiceManagementClientLiveTest.java +++ b/labs/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/features/ServiceManagementClientLiveTest.java @@ -44,8 +44,8 @@ public class ServiceManagementClientLiveTest extends BaseVPDCClientLiveTest { @Override @BeforeGroups(groups = { "live" }) - public void setupClient() { - super.setupClient(); + public void setupContext() { + super.setupContext(); client = restContext.getApi().getServiceManagementClient(); } diff --git a/labs/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/features/VMClientLiveTest.java b/labs/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/features/VMClientLiveTest.java index 6ad7591f97..cb645f8346 100644 --- a/labs/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/features/VMClientLiveTest.java +++ b/labs/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/features/VMClientLiveTest.java @@ -63,8 +63,8 @@ public class VMClientLiveTest extends BaseVPDCClientLiveTest { @Override @BeforeGroups(groups = { "live" }) - public void setupClient() { - super.setupClient(); + public void setupContext() { + super.setupContext(); client = restContext.getApi().getVMClient(); socketTester = new RetryablePredicate(new InetSocketAddressConnect(), 130, 10, TimeUnit.SECONDS);// make } @@ -293,10 +293,10 @@ public class VMClientLiveTest extends BaseVPDCClientLiveTest { } @AfterGroups(groups = "live") - protected void tearDown() { + protected void tearDownContext() { if (vm != null) { assert taskTester.apply(client.removeVMFromVDC(billingSiteId, vpdcId, vm.getId()).getId()) : vm; } - super.tearDown(); + super.tearDownContext(); } } \ No newline at end of file diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorApiMetadata.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorApiMetadata.java index 62a837d3c8..b39f9298f6 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorApiMetadata.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorApiMetadata.java @@ -17,50 +17,95 @@ * under the License. */ package org.jclouds.vcloud.director.v1_5; +import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL; +import static org.jclouds.vcloud.director.v1_5.VCloudDirectorConstants.PROPERTY_VCLOUD_DIRECTOR_TIMEOUT_TASK_COMPLETED; +import static org.jclouds.vcloud.director.v1_5.VCloudDirectorConstants.PROPERTY_VCLOUD_DIRECTOR_VERSION_SCHEMA; +import static org.jclouds.vcloud.director.v1_5.VCloudDirectorConstants.PROPERTY_VCLOUD_DIRECTOR_XML_NAMESPACE; +import static org.jclouds.vcloud.director.v1_5.VCloudDirectorConstants.PROPERTY_VCLOUD_DIRECTOR_XML_SCHEMA; import java.net.URI; +import java.util.Properties; +import org.jclouds.apis.ApiMetadata; import org.jclouds.apis.ApiType; -import org.jclouds.apis.BaseApiMetadata; +import org.jclouds.compute.internal.BaseComputeServiceApiMetadata; +import org.jclouds.rest.internal.BaseRestApiMetadata; +import org.jclouds.vcloud.director.v1_5.user.VCloudDirectorAsyncClient; +import org.jclouds.vcloud.director.v1_5.user.VCloudDirectorClient; + +import com.google.common.reflect.TypeToken; /** - * Implementation of {@link ApiMetadata} for VCloud Director 1.5 API + * Implementation of {@link ApiMetadata} for VCloudDirector 1.0 API * * @author Adrian Cole */ -public class VCloudDirectorApiMetadata extends BaseApiMetadata { +public class VCloudDirectorApiMetadata + extends +// BaseComputeServiceApiMetadata { + BaseRestApiMetadata { - public VCloudDirectorApiMetadata() { - this(builder() - .id("vcloud-director") - .type(ApiType.COMPUTE) - .name("VCloud Director 1.5 API") - .identityName("User at Organization (user@org)") - .credentialName("Password") - .documentation(URI.create("http://www.vmware.com/support/pubs/vcd_pubs.html"))); + @Override + public Builder toBuilder() { + return new Builder().fromApiMetadata(this); } - // below are so that we can reuse builders, toString, hashCode, etc. - // we have to set concrete classes here, as our base class cannot be - // concrete due to serviceLoader - protected VCloudDirectorApiMetadata(ConcreteBuilder builder) { + public VCloudDirectorApiMetadata() { + this(new Builder()); + } + + public VCloudDirectorApiMetadata(Builder builder) { super(builder); } - private static class ConcreteBuilder extends Builder { + protected static Properties defaultProperties() { + Properties properties = BaseComputeServiceApiMetadata.Builder.defaultProperties(); + /** FIXME this should not be the default */ + properties.setProperty(PROPERTY_SESSION_INTERVAL, Integer.toString(30 * 60)); + + properties.setProperty(PROPERTY_VCLOUD_DIRECTOR_XML_NAMESPACE, + String.format("http://www.vmware.com/vcloud/v${%s}", PROPERTY_VCLOUD_DIRECTOR_VERSION_SCHEMA)); + properties.setProperty(PROPERTY_SESSION_INTERVAL, Integer.toString(8 * 60)); + properties.setProperty(PROPERTY_VCLOUD_DIRECTOR_XML_SCHEMA, "${jclouds.endpoint}/v1.5/schema/master.xsd"); + + // TODO integrate these with the {@link ComputeTimeouts} instead of having a single timeout for everything. + properties.setProperty(PROPERTY_SESSION_INTERVAL, Integer.toString(300)); + properties.setProperty(PROPERTY_VCLOUD_DIRECTOR_TIMEOUT_TASK_COMPLETED, Long.toString(1200l * 1000l)); + + return properties; + } + + public static class Builder + extends +// BaseComputeServiceApiMetadata.Builder { + BaseRestApiMetadata.Builder { + + protected Builder() { + super(VCloudDirectorClient.class, VCloudDirectorAsyncClient.class); + id("vcloud") + .name("VCloud Director 1.5 API") + .type(ApiType.COMPUTE) + .identityName("User at Organization (user@org)") + .credentialName("Password") + .documentation(URI.create("http://www.vmware.com/support/pubs/vcd_pubs.html")) + .version("1.5") + .defaultEndpoint("https://vcloudbeta.bluelock.com/api") + .defaultProperties(VCloudDirectorApiMetadata.defaultProperties()) + .context(TypeToken.of(VCloudDirectorContext.class)) + .contextBuilder(TypeToken.of(VCloudDirectorContextBuilder.class)); + } @Override public VCloudDirectorApiMetadata build() { return new VCloudDirectorApiMetadata(this); } + + @Override + public Builder fromApiMetadata(VCloudDirectorApiMetadata in) { + super.fromApiMetadata(in); + return this; + } + } - public static ConcreteBuilder builder() { - return new ConcreteBuilder(); - } - - @Override - public ConcreteBuilder toBuilder() { - return builder().fromApiMetadata(this); - } -} \ No newline at end of file +} diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorContextBuilder.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorContextBuilder.java index dc0bd84bdd..cde539d05f 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorContextBuilder.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorContextBuilder.java @@ -19,33 +19,43 @@ package org.jclouds.vcloud.director.v1_5; import java.util.List; -import java.util.Properties; +import org.jclouds.providers.ProviderMetadata; import org.jclouds.rest.RestContextBuilder; import org.jclouds.vcloud.director.v1_5.config.VCloudDirectorRestClientModule; -import org.jclouds.vcloud.director.v1_5.internal.VCloudDirectorContextImpl; import org.jclouds.vcloud.director.v1_5.user.VCloudDirectorAsyncClient; import org.jclouds.vcloud.director.v1_5.user.VCloudDirectorClient; import com.google.inject.Module; /** + * * @author Adrian Cole */ -public class VCloudDirectorContextBuilder extends RestContextBuilder { +public class VCloudDirectorContextBuilder + extends + // ComputeServiceContextBuilder { + RestContextBuilder { - public VCloudDirectorContextBuilder(Properties props) { - super(VCloudDirectorClient.class, VCloudDirectorAsyncClient.class, props); + public VCloudDirectorContextBuilder( + ProviderMetadata providerMetadata) { + super(providerMetadata); } - @Override + public VCloudDirectorContextBuilder(VCloudDirectorApiMetadata apiMetadata) { + super(apiMetadata); + } + + // TODO + // @Override + // protected void addContextModule(List modules) { + // modules.add(new VCloudDirectorComputeServiceContextModule()); + // } + protected void addClientModule(List modules) { modules.add(new VCloudDirectorRestClientModule()); } - - @SuppressWarnings("unchecked") - @Override - public VCloudDirectorContext buildContext() { - return buildInjector().getInstance(VCloudDirectorContextImpl.class); - } + } diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/HttpClientLiveTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/HttpClientLiveTest.java index 550c337e72..5f648123cb 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/HttpClientLiveTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/HttpClientLiveTest.java @@ -51,8 +51,7 @@ public class HttpClientLiveTest extends BaseVCloudDirectorClientLiveTest { private SessionWithToken sessionWithToken; @Override - protected void setupRequiredClients() throws Exception { - setupCredentials(); + protected void setupRequiredClients() { } @Test(description = "POST /login") diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorApiMetadataTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorApiMetadataTest.java index 5bd3bcd411..0b90278dca 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorApiMetadataTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorApiMetadataTest.java @@ -19,7 +19,7 @@ package org.jclouds.vcloud.director.v1_5; import org.jclouds.apis.ApiType; -import org.jclouds.apis.BaseApiMetadataTest; +import org.jclouds.apis.internal.BaseApiMetadataTest; import org.testng.annotations.Test; /** diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/CatalogClientLiveTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/CatalogClientLiveTest.java index 81c6df43e3..bb92d538d3 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/CatalogClientLiveTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/CatalogClientLiveTest.java @@ -79,7 +79,7 @@ public class CatalogClientLiveTest extends BaseVCloudDirectorClientLiveTest { private Reference catalogRef; @Override - protected void setupRequiredClients() throws Exception { + protected void setupRequiredClients() { // TODO why do I need a guard clause here? if (adminCatalog != null) return; catalogClient = context.getApi().getCatalogClient(); diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/internal/BaseVCloudDirectorClientLiveTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/internal/BaseVCloudDirectorClientLiveTest.java index 74f40df635..03501d9110 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/internal/BaseVCloudDirectorClientLiveTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/internal/BaseVCloudDirectorClientLiveTest.java @@ -26,7 +26,6 @@ import static org.testng.Assert.fail; import java.net.URI; import java.text.SimpleDateFormat; -import java.util.Collection; import java.util.Collections; import java.util.Date; import java.util.Properties; @@ -36,12 +35,14 @@ import java.util.Set; import javax.annotation.Resource; import javax.inject.Inject; -import org.jclouds.compute.BaseVersionedServiceLiveTest; +import org.jclouds.Constants; import org.jclouds.date.DateService; import org.jclouds.logging.Logger; import org.jclouds.predicates.RetryablePredicate; import org.jclouds.rest.RestContext; +import org.jclouds.rest.internal.BaseContextLiveTest; import org.jclouds.vcloud.director.testng.FormatApiResultsListener; +import org.jclouds.vcloud.director.v1_5.VCloudDirectorContext; import org.jclouds.vcloud.director.v1_5.VCloudDirectorException; import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType; import org.jclouds.vcloud.director.v1_5.admin.VCloudDirectorAdminAsyncClient; @@ -76,7 +77,6 @@ import org.jclouds.vcloud.director.v1_5.user.VCloudDirectorAsyncClient; import org.jclouds.vcloud.director.v1_5.user.VCloudDirectorClient; import org.testng.annotations.AfterSuite; import org.testng.annotations.BeforeClass; -import org.testng.annotations.BeforeSuite; import org.testng.annotations.Listeners; import org.testng.annotations.Test; @@ -99,7 +99,7 @@ import com.google.inject.Guice; */ @Listeners(FormatApiResultsListener.class) @Test(groups = "live") -public abstract class BaseVCloudDirectorClientLiveTest extends BaseVersionedServiceLiveTest { +public abstract class BaseVCloudDirectorClientLiveTest extends BaseContextLiveTest { @Resource protected Logger logger = Logger.CONSOLE; @@ -149,7 +149,7 @@ public abstract class BaseVCloudDirectorClientLiveTest extends BaseVersionedServ } // NOTE Implement as required to populate xxxClient fields, or NOP - protected abstract void setupRequiredClients() throws Exception; + protected abstract void setupRequiredClients(); @Inject protected void initTaskSuccess(TaskSuccess taskSuccess) { @@ -160,18 +160,23 @@ public abstract class BaseVCloudDirectorClientLiveTest extends BaseVersionedServ protected void initTaskSuccessLong(TaskSuccess taskSuccess) { retryTaskSuccessLong = new RetryablePredicate(taskSuccess, LONG_TASK_TIMEOUT_SECONDS * 1000L); } - - @BeforeSuite(alwaysRun = true) - protected void setupTestSession() { - setupCredentials(); - Properties overrides = setupProperties(); - testSession = VCloudDirectorTestSession.builder() - .identity(identity) - .credential(credential) - .provider(provider) - .overrides(overrides) - .endpoint(endpoint) - .build(); + //temporary until we marry up the test fixtures + + protected String identity; + protected String credential; + protected String endpoint; + + @Override + protected Properties setupProperties() { + Properties overrides = new Properties(); + overrides.setProperty(Constants.PROPERTY_TRUST_ALL_CERTS, "true"); + overrides.setProperty(Constants.PROPERTY_RELAX_HOSTNAME, "true"); + identity = setIfTestSystemPropertyPresent(overrides, provider + ".identity"); + credential = setIfTestSystemPropertyPresent(overrides, provider + ".credential"); + endpoint = setIfTestSystemPropertyPresent(overrides, provider + ".endpoint"); + setIfTestSystemPropertyPresent(overrides, provider + ".api-version"); + setIfTestSystemPropertyPresent(overrides, provider + ".build-version"); + return overrides; } @AfterSuite(alwaysRun = true) @@ -180,8 +185,8 @@ public abstract class BaseVCloudDirectorClientLiveTest extends BaseVersionedServ } @BeforeClass(alwaysRun = true) - protected void setupContext() throws Exception { - setupCredentials(); + @Override + public void setupContext(){ context = testSession.getUserContext(); adminContext = testSession.getAdminContext(); @@ -495,4 +500,4 @@ public abstract class BaseVCloudDirectorClientLiveTest extends BaseVersionedServ public static String name(String prefix) { return prefix + Integer.toString(random.nextInt(Integer.MAX_VALUE)); } -} \ No newline at end of file +} diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/internal/BaseVCloudDirectorExpectTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/internal/BaseVCloudDirectorExpectTest.java index d55ee72a6d..d620aacb2e 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/internal/BaseVCloudDirectorExpectTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/internal/BaseVCloudDirectorExpectTest.java @@ -25,10 +25,12 @@ import java.net.URI; import java.util.Properties; import org.jclouds.Constants; +import org.jclouds.apis.ApiMetadata; import org.jclouds.date.DateService; import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpResponse; -import org.jclouds.rest.BaseRestClientExpectTest; +import org.jclouds.rest.internal.BaseRestClientExpectTest; +import org.jclouds.vcloud.director.v1_5.VCloudDirectorApiMetadata; import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType; import org.jclouds.vcloud.director.v1_5.domain.Reference; import org.testng.annotations.BeforeGroups; @@ -250,4 +252,10 @@ public abstract class BaseVCloudDirectorExpectTest extends BaseRestClientExpe public URI toAdminUri(URI uri) { return Reference.builder().href(uri).build().toAdminReference(endpoint).getHref(); } + + @Override + protected ApiMetadata createApiMetadata() { + return new VCloudDirectorApiMetadata(); + } + } diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/internal/VCloudDirectorAdminClientExpectTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/internal/VCloudDirectorAdminClientExpectTest.java index f713b33bf2..2f582f4b73 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/internal/VCloudDirectorAdminClientExpectTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/internal/VCloudDirectorAdminClientExpectTest.java @@ -22,13 +22,10 @@ import java.util.Properties; import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpResponse; -import org.jclouds.logging.config.NullLoggingModule; -import org.jclouds.rest.RestContextFactory; import org.jclouds.vcloud.director.v1_5.VCloudDirectorContext; import org.jclouds.vcloud.director.v1_5.admin.VCloudDirectorAdminClient; import com.google.common.base.Function; -import com.google.common.collect.ImmutableSet; import com.google.inject.Module; /** @@ -50,8 +47,7 @@ public abstract class VCloudDirectorAdminClientExpectTest extends } private VCloudDirectorContext createVCloudDirectorContext(Function fn, Module module, - Properties props) { - return VCloudDirectorContext.class.cast(new RestContextFactory(setupRestProperties()).createContext(provider, - identity, credential, ImmutableSet. of(new ExpectModule(fn), new NullLoggingModule(), module), props)); + Properties props) { + return createInjector(fn, module, props).getInstance(VCloudDirectorContext.class); } } diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/login/SessionClientExpectTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/login/SessionClientExpectTest.java index d905f77b5b..0a30ccd8c3 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/login/SessionClientExpectTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/login/SessionClientExpectTest.java @@ -22,10 +22,11 @@ import static org.testng.Assert.assertEquals; import java.net.URI; +import org.jclouds.apis.ApiMetadata; import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpResponse; -import org.jclouds.rest.BaseRestClientExpectTest; -import org.jclouds.rest.BaseRestClientExpectTest.RegisterContext; +import org.jclouds.rest.AnonymousRestApiMetadata; +import org.jclouds.rest.internal.BaseRestClientExpectTest; import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType; import org.jclouds.vcloud.director.v1_5.domain.Link; import org.jclouds.vcloud.director.v1_5.domain.Session; @@ -40,9 +41,7 @@ import com.google.common.collect.ImmutableMultimap; * * @author Adrian Cole */ -@Test(groups = { "unit", "user" }, testName = "SessionClientExpectTest") -// only needed as SessionClient is not registered in rest.properties -@RegisterContext(sync = SessionClient.class, async = SessionAsyncClient.class) +@Test(groups = "unit", testName = "SessionClientExpectTest") public class SessionClientExpectTest extends BaseRestClientExpectTest { public static final String user = "adrian@jclouds.org"; public static final String org = "JClouds"; @@ -122,4 +121,10 @@ public class SessionClientExpectTest extends BaseRestClientExpectTest createApiMetadata() { + return AnonymousRestApiMetadata.forClientMappedToAsyncClient(SessionClient.class, SessionAsyncClient.class) + .toBuilder().defaultEndpoint("https://vcloudbeta.bluelock.com/api").build(); + } } diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/login/SessionClientLiveTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/login/SessionClientLiveTest.java index c4c5c7f2ee..78ab4aff81 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/login/SessionClientLiveTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/login/SessionClientLiveTest.java @@ -18,8 +18,6 @@ */ package org.jclouds.vcloud.director.v1_5.login; -import static org.jclouds.rest.RestContextFactory.contextSpec; -import static org.jclouds.rest.RestContextFactory.createContextBuilder; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNotNull; import static org.testng.Assert.assertTrue; @@ -27,20 +25,17 @@ import static org.testng.Assert.assertTrue; import java.net.URI; import java.util.Properties; -import org.jclouds.compute.BaseVersionedServiceLiveTest; -import org.jclouds.logging.log4j.config.Log4JLoggingModule; +import org.jclouds.Constants; +import org.jclouds.apis.ApiMetadata; +import org.jclouds.rest.AnonymousRestApiMetadata; import org.jclouds.rest.RestContext; -import org.jclouds.rest.RestContextSpec; +import org.jclouds.rest.internal.BaseContextLiveTest; import org.jclouds.vcloud.director.testng.FormatApiResultsListener; import org.jclouds.vcloud.director.v1_5.domain.SessionWithToken; -import org.testng.annotations.AfterGroups; import org.testng.annotations.BeforeGroups; import org.testng.annotations.Listeners; import org.testng.annotations.Test; -import com.google.common.collect.ImmutableSet; -import com.google.inject.Module; - /** * Tests behavior of {@code SessionClient}. Note this class is tested completely independently of * VCloudClient as it is a dependency of the VCloud context working. @@ -48,32 +43,42 @@ import com.google.inject.Module; * @author Adrian Cole */ @Listeners(FormatApiResultsListener.class) -@Test(groups = { "live", "user" }, testName = "SessionClientLiveTest") -public class SessionClientLiveTest extends BaseVersionedServiceLiveTest { +@Test(groups = { "live", "user", "login" }, testName = "SessionClientLiveTest") +public class SessionClientLiveTest extends BaseContextLiveTest> { public SessionClientLiveTest() { provider = "vcloud-director"; } - private RestContext context; - @BeforeGroups(groups = { "live" }) - public void setupClient() { - setupCredentials(); - Properties overrides = setupProperties(); - RestContextSpec contextSpec = contextSpec("vcloud-director", endpoint, - apiVersion, buildVersion, "", identity, credential, SessionClient.class, SessionAsyncClient.class); - - context = createContextBuilder(contextSpec, overrides).withModules( - ImmutableSet. of(new Log4JLoggingModule())).buildContext(); - + public void setupContext() { + super.setupContext(); // session client isn't typically exposed to the user, as it is implicit - client = context.utils().injector().getInstance(SessionClient.class); + client = context.getApi(); } private SessionClient client; private SessionWithToken sessionWithToken; - @Test(description = "POST /sessions") + //temporary until we marry up the test fixtures + + protected String identity; + protected String credential; + protected String endpoint; + + @Override + protected Properties setupProperties() { + Properties overrides = new Properties(); + overrides.setProperty(Constants.PROPERTY_TRUST_ALL_CERTS, "true"); + overrides.setProperty(Constants.PROPERTY_RELAX_HOSTNAME, "true"); + identity = setIfTestSystemPropertyPresent(overrides, provider + ".identity"); + credential = setIfTestSystemPropertyPresent(overrides, provider + ".credential"); + endpoint = setIfTestSystemPropertyPresent(overrides, provider + ".endpoint"); + setIfTestSystemPropertyPresent(overrides, provider + ".api-version"); + setIfTestSystemPropertyPresent(overrides, provider + ".build-version"); + return overrides; + } + + @Test(testName = "POST /sessions") public void testLogin() { String user = identity.substring(0, identity.lastIndexOf('@')); String org = identity.substring(identity.lastIndexOf('@') + 1); @@ -96,11 +101,9 @@ public class SessionClientLiveTest extends BaseVersionedServiceLiveTest { public void testLogout() { client.logoutSessionWithToken(sessionWithToken.getSession().getHref(), sessionWithToken.getToken()); } - - @AfterGroups(groups = "live") - protected void tearDown() { - if (context != null) - context.close(); + + @Override + protected ApiMetadata, ?> createApiMetadata() { + return AnonymousRestApiMetadata.forClientMappedToAsyncClient(SessionClient.class, SessionAsyncClient.class); } - } diff --git a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/VirtualBoxApiMetadata.java b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/VirtualBoxApiMetadata.java index 5c7a800a3c..dd9f02fada 100644 --- a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/VirtualBoxApiMetadata.java +++ b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/VirtualBoxApiMetadata.java @@ -18,50 +18,111 @@ */ package org.jclouds.virtualbox; +import static org.jclouds.compute.config.ComputeServiceProperties.IMAGE_AUTHENTICATE_SUDO; +import static org.jclouds.compute.config.ComputeServiceProperties.IMAGE_LOGIN_USER; +import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_DEFAULT_DIR; +import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_IMAGES_DESCRIPTOR; +import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_INSTALLATION_KEY_SEQUENCE; +import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_PRECONFIGURATION_URL; +import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_WORKINGDIR; + +import java.io.File; import java.net.URI; +import java.util.Properties; import org.jclouds.apis.ApiMetadata; import org.jclouds.apis.ApiType; -import org.jclouds.apis.BaseApiMetadata; +import org.jclouds.compute.ComputeServiceContext; +import org.jclouds.compute.internal.BaseComputeServiceApiMetadata; + +import com.google.common.base.Supplier; +import com.google.common.reflect.TypeToken; /** * Implementation of {@link ApiMetadata} for VirtualBox API * + *

note

+ * + * This class is not setup to allow a subclasses to override the type of api, + * asyncapi, or context. This is an optimization for simplicity. + * * @author Adrian Cole */ -public class VirtualBoxApiMetadata extends BaseApiMetadata { +@SuppressWarnings("rawtypes") +public class VirtualBoxApiMetadata extends BaseComputeServiceApiMetadata, VirtualBoxApiMetadata> { - public VirtualBoxApiMetadata() { - this(builder() - .id("virtualbox") - .type(ApiType.COMPUTE) - .name("VirtualBox API") - .identityName("User") - .credentialName("Password") - .documentation(URI.create("https://www.virtualbox.org/sdkref/index.html"))); + @Override + public Builder toBuilder() { + return new Builder().fromApiMetadata(this); } - // below are so that we can reuse builders, toString, hashCode, etc. - // we have to set concrete classes here, as our base class cannot be - // concrete due to serviceLoader - protected VirtualBoxApiMetadata(ConcreteBuilder builder) { + public VirtualBoxApiMetadata() { + this(new Builder()); + } + + protected VirtualBoxApiMetadata(Builder builder) { super(builder); } - private static class ConcreteBuilder extends Builder { + protected static Properties defaultProperties() { + Properties properties = BaseComputeServiceApiMetadata.Builder.defaultProperties(); + + properties.put(IMAGE_LOGIN_USER, "toor:password"); + properties.put(IMAGE_AUTHENTICATE_SUDO, "true"); + + + properties.put(VIRTUALBOX_INSTALLATION_KEY_SEQUENCE, " " + + "/install/vmlinuz noapic preseed/url=PRECONFIGURATION_URL " + + "debian-installer=en_US auto locale=en_US kbd-chooser/method=us " + "hostname=" + "HOSTNAME " + + "fb=false debconf/frontend=noninteractive " + + "keyboard-configuration/layout=USA keyboard-configuration/variant=USA console-setup/ask_detect=false " + + "initrd=/install/initrd.gz -- "); + + String workingDir = System.getProperty("test.virtualbox.workingDir", VIRTUALBOX_DEFAULT_DIR); + + properties.put(VIRTUALBOX_WORKINGDIR, workingDir); + + String yamlDescriptor = System.getProperty("test.virtualbox.image.descriptor.yaml", VIRTUALBOX_WORKINGDIR + + File.separator + "images.yaml"); + + properties.put(VIRTUALBOX_IMAGES_DESCRIPTOR, yamlDescriptor); + + properties.put(VIRTUALBOX_PRECONFIGURATION_URL, "http://10.0.2.2:23232/preseed.cfg"); + return properties; + } + + public static class Builder extends BaseComputeServiceApiMetadata.Builder, VirtualBoxApiMetadata> { + + protected Builder() { + id("virtualbox") + .type(ApiType.COMPUTE) + .name("VirtualBox API") + .identityName("User") + .credentialName("Password") + .documentation(URI.create("https://www.virtualbox.org/sdkref/index.html")) + .defaultIdentity("administrator") + .defaultCredential("12345") + .defaultEndpoint("http://localhost:18083/") + .documentation(URI.create("https://github.com/jclouds/jclouds/tree/master/apis/byon")) + // later version not in maven, yet + .version("4.1.4") + .buildVersion("4.1.8r75467") + .defaultProperties(VirtualBoxApiMetadata.defaultProperties()) + .javaApi(Supplier.class, Supplier.class) + .contextBuilder(TypeToken.of(VirtualBoxContextBuilder.class)); + } @Override public VirtualBoxApiMetadata build() { return new VirtualBoxApiMetadata(this); } + + @Override + public Builder fromApiMetadata(VirtualBoxApiMetadata in) { + super.fromApiMetadata(in); + return this; + } + } - public static ConcreteBuilder builder() { - return new ConcreteBuilder(); - } - - @Override - public ConcreteBuilder toBuilder() { - return builder().fromApiMetadata(this); - } } \ No newline at end of file diff --git a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/VirtualBoxContextBuilder.java b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/VirtualBoxContextBuilder.java index d5668ec389..4a6aec5936 100644 --- a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/VirtualBoxContextBuilder.java +++ b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/VirtualBoxContextBuilder.java @@ -21,12 +21,13 @@ package org.jclouds.virtualbox; import java.net.URI; import java.util.List; -import java.util.Properties; import org.jclouds.byon.Node; import org.jclouds.byon.config.CacheNodeStoreModule; +import org.jclouds.compute.ComputeServiceContext; import org.jclouds.compute.StandaloneComputeServiceContextBuilder; import org.jclouds.compute.domain.OsFamily; +import org.jclouds.providers.ProviderMetadata; import org.jclouds.virtualbox.config.VirtualBoxComputeServiceContextModule; import com.google.common.base.Predicate; @@ -41,10 +42,15 @@ import com.google.inject.Module; * @author Mattias Holmqvist, Andrea Turli */ @SuppressWarnings("rawtypes") -public class VirtualBoxContextBuilder extends StandaloneComputeServiceContextBuilder { +public class VirtualBoxContextBuilder extends StandaloneComputeServiceContextBuilder, VirtualBoxApiMetadata> { - public VirtualBoxContextBuilder(Properties properties) { - super(Supplier.class, new VirtualBoxPropertiesBuilder(properties).defaultProperties()); + public VirtualBoxContextBuilder( + ProviderMetadata, VirtualBoxApiMetadata> providerMetadata) { + super(providerMetadata); + } + + public VirtualBoxContextBuilder(VirtualBoxApiMetadata apiMetadata) { + super(apiMetadata); } @Override diff --git a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/VirtualBoxPropertiesBuilder.java b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/VirtualBoxPropertiesBuilder.java deleted file mode 100644 index 04218b0a5a..0000000000 --- a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/VirtualBoxPropertiesBuilder.java +++ /dev/null @@ -1,85 +0,0 @@ -/** - * 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.virtualbox; -import static org.jclouds.Constants.PROPERTY_API_VERSION; -import static org.jclouds.Constants.PROPERTY_BUILD_VERSION; -import static org.jclouds.Constants.PROPERTY_ENDPOINT; -import static org.jclouds.compute.config.ComputeServiceProperties.IMAGE_AUTHENTICATE_SUDO; -import static org.jclouds.compute.config.ComputeServiceProperties.IMAGE_LOGIN_USER; -import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_DEFAULT_DIR; -import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_IMAGES_DESCRIPTOR; -import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_INSTALLATION_KEY_SEQUENCE; -import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_PRECONFIGURATION_URL; -import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_WORKINGDIR; - -import java.io.File; -import java.util.Properties; - -import org.jclouds.PropertiesBuilder; - -/** - * Builds properties for VirtualBox integration. - * - * @author Mattias Holmqvist - */ -public class VirtualBoxPropertiesBuilder extends PropertiesBuilder { - - public VirtualBoxPropertiesBuilder() { - super(); - } - - public VirtualBoxPropertiesBuilder(Properties properties) { - super(properties); - } - - @Override - protected Properties defaultProperties() { - Properties properties = super.defaultProperties(); - properties.put(PROPERTY_ENDPOINT, "http://localhost:18083/"); - // later version not in maven, yet - properties.put(PROPERTY_API_VERSION, "4.1.4"); - - properties.put(PROPERTY_BUILD_VERSION, "4.1.8r75467"); - - properties.put(IMAGE_LOGIN_USER, "toor:password"); - properties.put(IMAGE_AUTHENTICATE_SUDO, "true"); - - - properties.put(VIRTUALBOX_INSTALLATION_KEY_SEQUENCE, " " - + "/install/vmlinuz noapic preseed/url=PRECONFIGURATION_URL " - + "debian-installer=en_US auto locale=en_US kbd-chooser/method=us " + "hostname=" + "HOSTNAME " - + "fb=false debconf/frontend=noninteractive " - + "keyboard-configuration/layout=USA keyboard-configuration/variant=USA console-setup/ask_detect=false " - + "initrd=/install/initrd.gz -- "); - - String workingDir = System.getProperty("test.virtualbox.workingDir", VIRTUALBOX_DEFAULT_DIR); - - properties.put(VIRTUALBOX_WORKINGDIR, workingDir); - - String yamlDescriptor = System.getProperty("test.virtualbox.image.descriptor.yaml", VIRTUALBOX_WORKINGDIR - + File.separator + "images.yaml"); - - properties.put(VIRTUALBOX_IMAGES_DESCRIPTOR, yamlDescriptor); - - properties.put(VIRTUALBOX_PRECONFIGURATION_URL, "http://10.0.2.2:23232/preseed.cfg"); - - return properties; - } -} diff --git a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/config/VirtualBoxComputeServiceContextModule.java b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/config/VirtualBoxComputeServiceContextModule.java index c6852e53d2..7882a130b6 100644 --- a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/config/VirtualBoxComputeServiceContextModule.java +++ b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/config/VirtualBoxComputeServiceContextModule.java @@ -34,13 +34,14 @@ import java.util.concurrent.TimeUnit; import javax.inject.Singleton; import org.eclipse.jetty.server.Server; +import org.jclouds.byon.BYONApiMetadata; import org.jclouds.byon.Node; import org.jclouds.byon.functions.NodeToNodeMetadata; import org.jclouds.byon.suppliers.SupplyFromProviderURIOrNodesProperty; import org.jclouds.compute.ComputeServiceAdapter; import org.jclouds.compute.ComputeServiceAdapter.NodeAndInitialCredentials; import org.jclouds.compute.ComputeServiceContext; -import org.jclouds.compute.ComputeServiceContextFactory; +import org.jclouds.compute.ComputeServiceContextBuilder; import org.jclouds.compute.config.ComputeServiceAdapterContextModule; import org.jclouds.compute.domain.Hardware; import org.jclouds.compute.domain.HardwareBuilder; @@ -169,11 +170,10 @@ public class VirtualBoxComputeServiceContextModule extends @Host @Singleton protected ComputeServiceContext provideHostController() { - String provider = "byon"; - String identity = ""; - String credential = ""; - return new ComputeServiceContextFactory().createContext(provider, identity, credential, - ImmutableSet. of(new SLF4JLoggingModule(), new SshjSshClientModule())); + return ComputeServiceContextBuilder.newBuilder(new BYONApiMetadata()) + .credentials("", "") + .modules(ImmutableSet. of(new SLF4JLoggingModule(), new SshjSshClientModule())) + .build(); } @Provides diff --git a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/BaseVirtualBoxClientLiveTest.java b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/BaseVirtualBoxClientLiveTest.java index fc6ecf1811..6b22c1944b 100644 --- a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/BaseVirtualBoxClientLiveTest.java +++ b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/BaseVirtualBoxClientLiveTest.java @@ -25,24 +25,20 @@ import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_INSTA import java.io.File; import java.util.Map; -import java.util.Properties; import java.util.concurrent.ExecutorService; import javax.inject.Inject; import javax.inject.Named; -import org.jclouds.compute.BaseVersionedServiceLiveTest; import org.jclouds.compute.ComputeServiceContext; -import org.jclouds.compute.ComputeServiceContextFactory; import org.jclouds.compute.domain.Image; import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.domain.Template; +import org.jclouds.compute.internal.BaseComputeServiceContextLiveTest; import org.jclouds.compute.strategy.PrioritizeCredentialsFromTemplate; import org.jclouds.concurrent.MoreExecutors; import org.jclouds.concurrent.config.ExecutorServiceModule; import org.jclouds.config.ValueOfConfigurationKeyOrNull; -import org.jclouds.logging.slf4j.config.SLF4JLoggingModule; -import org.jclouds.sshj.config.SshjSshClientModule; import org.jclouds.virtualbox.config.VirtualBoxConstants; import org.jclouds.virtualbox.domain.HardDisk; import org.jclouds.virtualbox.domain.IsoSpec; @@ -88,7 +84,8 @@ import com.google.inject.Module; * @author Adrian Cole, David Alves */ @Test(groups = "live", singleThreaded = true, testName = "BaseVirtualBoxClientLiveTest") -public class BaseVirtualBoxClientLiveTest extends BaseVersionedServiceLiveTest { +public class BaseVirtualBoxClientLiveTest extends + BaseComputeServiceContextLiveTest> { public static final String DONT_DESTROY_MASTER = "jclouds.virtualbox.keep-test-master"; @@ -96,8 +93,6 @@ public class BaseVirtualBoxClientLiveTest extends BaseVersionedServiceLiveTest { provider = "virtualbox"; } - protected ComputeServiceContext context; - @Inject protected MachineController machineController; @@ -129,30 +124,18 @@ public class BaseVirtualBoxClientLiveTest extends BaseVersionedServiceLiveTest { private final ExecutorService singleThreadExec = MoreExecutors.sameThreadExecutor(); private String masterVmName; + @Override - protected void setupCredentials() { - // default behavior is to bomb when no user is configured, but we know the - // default user of - // vbox - ensureIdentityPropertyIsSpecifiedOrTakeFromDefaults(); - super.setupCredentials(); + protected Iterable setupModules() { + return ImmutableSet. of(getLoggingModule(), credentialStoreModule, getSshModule(), new ExecutorServiceModule( + singleThreadExec, singleThreadExec)); } - - protected void ensureIdentityPropertyIsSpecifiedOrTakeFromDefaults() { - if (!System.getProperties().containsKey("test." + provider + ".identity")) - System.setProperty("test." + provider + ".identity", "administrator"); - } - - @BeforeClass(groups = "live") - public void setupClient() { - setupCredentials(); - Properties overrides = new VirtualBoxPropertiesBuilder(setupProperties()).build(); - - context = new ComputeServiceContextFactory().createContext(provider, identity, credential, ImmutableSet - . of(new SLF4JLoggingModule(), new SshjSshClientModule(), new ExecutorServiceModule( - singleThreadExec, singleThreadExec)), overrides); - + + @Override + @BeforeClass(groups = { "integration", "live" }) + public void setupContext() { + super.setupContext(); context.utils().injector().injectMembers(this); YamlImage image = getDefaultImage(); diff --git a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/PreseedCfgServerTest.java b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/PreseedCfgServerTest.java index 2dc1358f7d..1b383315db 100644 --- a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/PreseedCfgServerTest.java +++ b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/PreseedCfgServerTest.java @@ -41,7 +41,7 @@ public class PreseedCfgServerTest { @Test public void testJettyServerServesPreseedFile() throws Exception { - Properties props = new VirtualBoxPropertiesBuilder().defaultProperties(); + Properties props = VirtualBoxApiMetadata.defaultProperties(); String preconfigurationUrl = props.getProperty(VirtualBoxConstants.VIRTUALBOX_PRECONFIGURATION_URL); diff --git a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/VirtualBoxApiMetadataTest.java b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/VirtualBoxApiMetadataTest.java index 4880ed4d7b..6aec98fb30 100644 --- a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/VirtualBoxApiMetadataTest.java +++ b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/VirtualBoxApiMetadataTest.java @@ -19,7 +19,7 @@ package org.jclouds.virtualbox; import org.jclouds.apis.ApiType; -import org.jclouds.apis.BaseApiMetadataTest; +import org.jclouds.apis.internal.BaseApiMetadataTest; import org.testng.annotations.Test; /** diff --git a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/CloneAndRegisterMachineFromIMachineIfNotAlreadyExistsLiveTest.java b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/CloneAndRegisterMachineFromIMachineIfNotAlreadyExistsLiveTest.java index ed73ee4c54..8c8b1445ac 100644 --- a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/CloneAndRegisterMachineFromIMachineIfNotAlreadyExistsLiveTest.java +++ b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/CloneAndRegisterMachineFromIMachineIfNotAlreadyExistsLiveTest.java @@ -58,8 +58,8 @@ public class CloneAndRegisterMachineFromIMachineIfNotAlreadyExistsLiveTest exten @Override @BeforeClass(groups = "live") - public void setupClient() { - super.setupClient(); + public void setupContext() { + super.setupContext(); instanceName = VIRTUALBOX_IMAGE_PREFIX + CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_HYPHEN, getClass().getSimpleName()); diff --git a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/CreateAndInstallVmLiveTest.java b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/CreateAndInstallVmLiveTest.java index eb28872e36..d7c81dab49 100644 --- a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/CreateAndInstallVmLiveTest.java +++ b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/CreateAndInstallVmLiveTest.java @@ -119,8 +119,8 @@ public class CreateAndInstallVmLiveTest extends BaseVirtualBoxClientLiveTest { @Override @BeforeClass(groups = "live") - public void setupClient() { - super.setupClient(); + public void setupContext() { + super.setupContext(); instanceName = VIRTUALBOX_IMAGE_PREFIX + CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_HYPHEN, getClass().getSimpleName()); diff --git a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/CreateAndRegisterMachineFromIsoIfNotAlreadyExistsLiveTest.java b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/CreateAndRegisterMachineFromIsoIfNotAlreadyExistsLiveTest.java index de5ae9c8a3..dafab24618 100644 --- a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/CreateAndRegisterMachineFromIsoIfNotAlreadyExistsLiveTest.java +++ b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/CreateAndRegisterMachineFromIsoIfNotAlreadyExistsLiveTest.java @@ -54,8 +54,8 @@ public class CreateAndRegisterMachineFromIsoIfNotAlreadyExistsLiveTest extends B private String vmName = ""; @Override - public void setupClient() { - super.setupClient(); + public void setupContext() { + super.setupContext(); ideControllerName = "IDE Controller"; mode = CleanupMode.Full; } diff --git a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/predicates/GuestAdditionsInstallerLiveTest.java b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/predicates/GuestAdditionsInstallerLiveTest.java index da7617d484..e611e50848 100644 --- a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/predicates/GuestAdditionsInstallerLiveTest.java +++ b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/predicates/GuestAdditionsInstallerLiveTest.java @@ -70,8 +70,8 @@ public class GuestAdditionsInstallerLiveTest extends BaseVirtualBoxClientLiveTes @Override @BeforeClass(groups = "live") - public void setupClient() { - super.setupClient(); + public void setupContext() { + super.setupContext(); injector = context.utils().injector(); String instanceName = VIRTUALBOX_IMAGE_PREFIX diff --git a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/predicates/IMachinePredicatesLiveTest.java b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/predicates/IMachinePredicatesLiveTest.java index 830053e18e..a1e2815b9d 100644 --- a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/predicates/IMachinePredicatesLiveTest.java +++ b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/predicates/IMachinePredicatesLiveTest.java @@ -62,8 +62,8 @@ public class IMachinePredicatesLiveTest extends BaseVirtualBoxClientLiveTest { @Override @BeforeClass(groups = "live") - public void setupClient() { - super.setupClient(); + public void setupContext() { + super.setupContext(); instanceName = VIRTUALBOX_IMAGE_PREFIX + CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_HYPHEN, getClass().getSimpleName()); diff --git a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/util/MachineControllerLiveTest.java b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/util/MachineControllerLiveTest.java index c1da4d7121..8d90ea2028 100644 --- a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/util/MachineControllerLiveTest.java +++ b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/util/MachineControllerLiveTest.java @@ -59,8 +59,8 @@ public class MachineControllerLiveTest extends BaseVirtualBoxClientLiveTest { @Override @BeforeClass(groups = "live") - public void setupClient() { - super.setupClient(); + public void setupContext() { + super.setupContext(); instanceName = VIRTUALBOX_IMAGE_PREFIX + CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_HYPHEN, getClass().getSimpleName()); diff --git a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/util/MachineUtilsLiveTest.java b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/util/MachineUtilsLiveTest.java index 007b169ff9..d5c9725f51 100644 --- a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/util/MachineUtilsLiveTest.java +++ b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/util/MachineUtilsLiveTest.java @@ -59,8 +59,8 @@ public class MachineUtilsLiveTest extends BaseVirtualBoxClientLiveTest { @Override @BeforeClass(groups = "live") - public void setupClient() { - super.setupClient(); + public void setupContext() { + super.setupContext(); instanceName = VIRTUALBOX_IMAGE_PREFIX + CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_HYPHEN, getClass().getSimpleName()); diff --git a/loadbalancer/src/main/java/org/jclouds/loadbalancer/LoadBalancerService.java b/loadbalancer/src/main/java/org/jclouds/loadbalancer/LoadBalancerService.java index bbc6a1a9f5..611fff821f 100644 --- a/loadbalancer/src/main/java/org/jclouds/loadbalancer/LoadBalancerService.java +++ b/loadbalancer/src/main/java/org/jclouds/loadbalancer/LoadBalancerService.java @@ -49,7 +49,7 @@ public interface LoadBalancerService { /** * @return a reference to the context that created this LoadBalancerService. */ - LoadBalancerServiceContext getContext(); + LoadBalancerServiceContext getContext(); /** * @param location diff --git a/loadbalancer/src/main/java/org/jclouds/loadbalancer/LoadBalancerServiceApiMetadata.java b/loadbalancer/src/main/java/org/jclouds/loadbalancer/LoadBalancerServiceApiMetadata.java new file mode 100644 index 0000000000..32806f5163 --- /dev/null +++ b/loadbalancer/src/main/java/org/jclouds/loadbalancer/LoadBalancerServiceApiMetadata.java @@ -0,0 +1,20 @@ +package org.jclouds.loadbalancer; + +import org.jclouds.apis.ApiMetadata; + +import com.google.common.annotations.Beta; + +/** + * + * @author Adrian Cole + * @since 1.5 + */ +@Beta +public interface LoadBalancerServiceApiMetadata, M extends LoadBalancerServiceApiMetadata> + extends ApiMetadata { + + public static interface Builder, M extends LoadBalancerServiceApiMetadata> + extends ApiMetadata.Builder { + } + +} \ No newline at end of file diff --git a/loadbalancer/src/main/java/org/jclouds/loadbalancer/LoadBalancerServiceContext.java b/loadbalancer/src/main/java/org/jclouds/loadbalancer/LoadBalancerServiceContext.java index 4412d595d7..4f82ccce50 100644 --- a/loadbalancer/src/main/java/org/jclouds/loadbalancer/LoadBalancerServiceContext.java +++ b/loadbalancer/src/main/java/org/jclouds/loadbalancer/LoadBalancerServiceContext.java @@ -18,8 +18,10 @@ */ package org.jclouds.loadbalancer; +import java.io.Closeable; + import org.jclouds.loadbalancer.internal.LoadBalancerServiceContextImpl; -import org.jclouds.rest.RestContext; +import org.jclouds.rest.BackedByRestContext; import org.jclouds.rest.Utils; import com.google.inject.ImplementedBy; @@ -32,14 +34,11 @@ import com.google.inject.ImplementedBy; * */ @ImplementedBy(LoadBalancerServiceContextImpl.class) -public interface LoadBalancerServiceContext { +public interface LoadBalancerServiceContext extends Closeable, BackedByRestContext { LoadBalancerService getLoadBalancerService(); - RestContext getProviderSpecificContext(); - - Utils getUtils(); /** @@ -47,5 +46,6 @@ public interface LoadBalancerServiceContext { */ Utils utils(); + @Override void close(); } \ No newline at end of file diff --git a/loadbalancer/src/main/java/org/jclouds/loadbalancer/LoadBalancerServiceContextBuilder.java b/loadbalancer/src/main/java/org/jclouds/loadbalancer/LoadBalancerServiceContextBuilder.java index 2543f8e3f2..cd8bee81c7 100644 --- a/loadbalancer/src/main/java/org/jclouds/loadbalancer/LoadBalancerServiceContextBuilder.java +++ b/loadbalancer/src/main/java/org/jclouds/loadbalancer/LoadBalancerServiceContextBuilder.java @@ -18,33 +18,48 @@ */ package org.jclouds.loadbalancer; -import java.util.Properties; +import static com.google.common.base.Preconditions.checkArgument; -import org.jclouds.loadbalancer.internal.LoadBalancerServiceContextImpl; -import org.jclouds.rest.RestContextBuilder; +import java.util.NoSuchElementException; -import com.google.inject.Key; -import com.google.inject.util.Types; +import org.jclouds.providers.ProviderMetadata; +import org.jclouds.rest.internal.ContextBuilder; /** * @author Adrian Cole */ -public abstract class LoadBalancerServiceContextBuilder extends RestContextBuilder { - - public LoadBalancerServiceContextBuilder(Class syncClientType, Class asyncClientType) { - this(syncClientType, asyncClientType, new Properties()); +public abstract class LoadBalancerServiceContextBuilder, M extends LoadBalancerServiceApiMetadata> extends + ContextBuilder { + +// TODO: +// public static ContextBuilder forTests() { +// return ContextBuilder.newBuilder(new StubApiMetadata()); +// } + + /** + * looks up a provider or api with the given id + * + * @param providerOrApi + * id of the provider or api + * @return means to build a context to that provider + * @throws NoSuchElementException + * if the id was not configured. + * @throws IllegalArgumentException + * if the api or provider isn't assignable from LoadBalancerServiceContext + */ + public static LoadBalancerServiceContextBuilder newBuilder(String providerOrApi) throws NoSuchElementException { + ContextBuilder builder = ContextBuilder.newBuilder(providerOrApi); + checkArgument(builder instanceof LoadBalancerServiceContextBuilder, + "type of providerOrApi[%s] is not LoadBalancerServiceContextBuilder: %s", providerOrApi, builder); + return LoadBalancerServiceContextBuilder.class.cast(builder); + } + + public LoadBalancerServiceContextBuilder(ProviderMetadata providerMetadata) { + super(providerMetadata); } - public LoadBalancerServiceContextBuilder(Class syncClientType, Class asyncClientType, - Properties properties) { - super(syncClientType, asyncClientType, properties); - + public LoadBalancerServiceContextBuilder(M apiMetadata) { + super(apiMetadata); } - public LoadBalancerServiceContext buildLoadBalancerServiceContext() { - // need the generic type information - return (LoadBalancerServiceContext) buildInjector().getInstance( - Key.get(Types.newParameterizedType(LoadBalancerServiceContextImpl.class, syncClientType, - asyncClientType))); - } } \ No newline at end of file diff --git a/loadbalancer/src/main/java/org/jclouds/loadbalancer/LoadBalancerServiceContextFactory.java b/loadbalancer/src/main/java/org/jclouds/loadbalancer/LoadBalancerServiceContextFactory.java index 40ac3c05e1..d42cce256b 100644 --- a/loadbalancer/src/main/java/org/jclouds/loadbalancer/LoadBalancerServiceContextFactory.java +++ b/loadbalancer/src/main/java/org/jclouds/loadbalancer/LoadBalancerServiceContextFactory.java @@ -18,135 +18,114 @@ */ package org.jclouds.loadbalancer; -import static org.jclouds.rest.RestContextFactory.createContextBuilder; -import static org.jclouds.util.Throwables2.propagateAuthorizationOrOriginalException; - +import java.util.NoSuchElementException; import java.util.Properties; +import org.jclouds.apis.Apis; import org.jclouds.javax.annotation.Nullable; -import org.jclouds.rest.RestContextFactory; -import org.jclouds.rest.RestContextSpec; +import org.jclouds.providers.ProviderMetadata; +import org.jclouds.providers.Providers; +import org.jclouds.rest.internal.ContextBuilder; +import com.google.common.collect.ImmutableSet; import com.google.inject.Module; /** - * Helper class to instantiate {@code LoadBalancerServiceContext} instances. * + * @see ContextBuilder + * @see LoadBalancerServiceContextBuilder * @author Adrian Cole */ +@Deprecated public class LoadBalancerServiceContextFactory { - private final RestContextFactory contextFactory; - /** - * Initializes with the default properties built-in to jclouds. This is typically stored in the - * classpath resource {@code rest.properties} - * - * @see RestContextFactory#getPropertiesFromResource + * for porting old code to {@link ContextBuilder} */ public LoadBalancerServiceContextFactory() { - this(new RestContextFactory()); } /** - * Finds definitions in the specified properties. + * for porting old code to {@link ContextBuilder} */ public LoadBalancerServiceContextFactory(Properties properties) { - this(new RestContextFactory(properties)); } /** - * - * Uses the supplied RestContextFactory to create {@link LoadBalancerServiceContext}s + * @see #createContext(String, String,String, Iterable, Properties) */ - public LoadBalancerServiceContextFactory(RestContextFactory restContextFactory) { - this.contextFactory = restContextFactory; - } - - public static LoadBalancerServiceContext buildContextUnwrappingExceptions( - LoadBalancerServiceContextBuilder builder) { - try { - return builder.buildLoadBalancerServiceContext(); - } catch (Exception e) { - return propagateAuthorizationOrOriginalException(e); - } + public LoadBalancerServiceContext createContext(String providerOrApi, String identity, String credential) { + return createContext(providerOrApi, identity, credential, ImmutableSet. of(), new Properties()); } /** - * @see RestContextFactory#createContextBuilder(String, String, String) + * @see #createContext(String, String, String, Iterable, Properties) */ - public LoadBalancerServiceContext createContext(String provider, String identity, String credential) { - LoadBalancerServiceContextBuilder builder = LoadBalancerServiceContextBuilder.class.cast(contextFactory - .createContextBuilder(provider, identity, credential)); - return buildContextUnwrappingExceptions(builder); + public LoadBalancerServiceContext createContext(String providerOrApi, Properties overrides) { + return createContext(providerOrApi, null, null, ImmutableSet. of(), overrides); } /** - * @see RestContextFactory#createContextBuilder(String, Properties) + * @see #createContext(String, String,String, Iterable, Properties) */ - public LoadBalancerServiceContext createContext(String provider, Properties overrides) { - LoadBalancerServiceContextBuilder builder = LoadBalancerServiceContextBuilder.class.cast(contextFactory - .createContextBuilder(provider, overrides)); - return buildContextUnwrappingExceptions(builder); - } - - /** - * @see RestContextFactory#createContextBuilder(String, Iterable) - */ - public LoadBalancerServiceContext createContext(String provider, Iterable modules, Properties overrides) { - LoadBalancerServiceContextBuilder builder = LoadBalancerServiceContextBuilder.class.cast(contextFactory - .createContextBuilder(provider, modules, overrides)); - return buildContextUnwrappingExceptions(builder); - - } - - /** - * @see RestContextFactory#createContextBuilder(String, String,String, Iterable) - */ - public LoadBalancerServiceContext createContext(String provider, @Nullable String identity, @Nullable String credential, - Iterable modules) { - LoadBalancerServiceContextBuilder builder = LoadBalancerServiceContextBuilder.class.cast(contextFactory - .createContextBuilder(provider, identity, credential, modules)); - return buildContextUnwrappingExceptions(builder); - } - - /** - * @see RestContextFactory#createContextBuilder(String, String,String, Iterable, Properties) - */ - public LoadBalancerServiceContext createContext(String provider, @Nullable String identity, @Nullable String credential, - Iterable modules, Properties overrides) { - LoadBalancerServiceContextBuilder builder = LoadBalancerServiceContextBuilder.class.cast(contextFactory - .createContextBuilder(provider, identity, credential, modules, overrides)); - return buildContextUnwrappingExceptions(builder); - } - - /** - * @see RestContextFactory#createContextBuilder(RestContextSpec) - */ - public LoadBalancerServiceContext createContext(RestContextSpec contextSpec) { - LoadBalancerServiceContextBuilder builder = LoadBalancerServiceContextBuilder.class - .cast(createContextBuilder(contextSpec)); - return buildContextUnwrappingExceptions(builder); - - } - - /** - * @see RestContextFactory#createContextBuilder(RestContextSpec, Properties) - */ - public LoadBalancerServiceContext createContext(RestContextSpec contextSpec, Properties overrides) { - LoadBalancerServiceContextBuilder builder = LoadBalancerServiceContextBuilder.class.cast(createContextBuilder( - contextSpec, overrides)); - return buildContextUnwrappingExceptions(builder); - } - - /** - * @see RestContextFactory#createContextBuilder(RestContextSpec, Iterable, Properties) - */ - public LoadBalancerServiceContext createContext(RestContextSpec contextSpec, Iterable modules, + public LoadBalancerServiceContext createContext(String providerOrApi, Iterable wiring, Properties overrides) { - LoadBalancerServiceContextBuilder builder = LoadBalancerServiceContextBuilder.class.cast(createContextBuilder( - contextSpec, modules, overrides)); - return buildContextUnwrappingExceptions(builder); + return createContext(providerOrApi, null, null, wiring, overrides); } -} \ No newline at end of file + /** + * @see #createContext(String, String,String, Iterable, Properties) + */ + public LoadBalancerServiceContext createContext(String providerOrApi, @Nullable String identity, + @Nullable String credential, Properties overrides) { + return createContext(providerOrApi, identity, credential, ImmutableSet. of(), overrides); + } + + /** + * @see createContext(String, String,String, Iterable, Properties) + */ + public LoadBalancerServiceContext createContext(String providerOrApi, @Nullable String identity, + @Nullable String credential, Iterable wiring) { + return createContext(providerOrApi, identity, credential, wiring, new Properties()); + } + + /** + * for porting old code to {@link ContextBuilder} + * + * @param providerOrApi + * @param identity + * nullable, if credentials are present in the overrides + * @param credential + * nullable, if credentials are present in the overrides + * @param wiring + * Configuration you'd like to pass to the context. Ex. + * ImmutableSet.of(new ExecutorServiceModule(myexecutor)) + * @param overrides + * properties to override defaults with. + * @return initialized context ready for use + */ + @SuppressWarnings("unchecked") + public LoadBalancerServiceContext createContext(String providerOrApi, @Nullable String identity, + @Nullable String credential, Iterable wiring, Properties overrides) { + ContextBuilder builder = null; + try { + ProviderMetadata pm = Providers.withId(providerOrApi); + builder = LoadBalancerServiceContextBuilder.newBuilder(pm); + } catch (NoSuchElementException e) { + builder = ContextBuilder.newBuilder(Apis.withId(providerOrApi)); + } + builder.modules(Iterable.class.cast(wiring)); + builder.overrides(overrides); + if (identity != null) + builder.credentials(identity, credential); + Object context = builder.build(); + if (context instanceof LoadBalancerServiceContext) { + return LoadBalancerServiceContext.class.cast(context); + } else { + throw new IllegalArgumentException("provider " + providerOrApi + " contains an unknown context type: " + + context.getClass().getSimpleName()); + } + + } + +} diff --git a/loadbalancer/src/main/java/org/jclouds/loadbalancer/internal/BaseLoadBalancerService.java b/loadbalancer/src/main/java/org/jclouds/loadbalancer/internal/BaseLoadBalancerService.java index 1083898581..b0e32f723e 100644 --- a/loadbalancer/src/main/java/org/jclouds/loadbalancer/internal/BaseLoadBalancerService.java +++ b/loadbalancer/src/main/java/org/jclouds/loadbalancer/internal/BaseLoadBalancerService.java @@ -63,7 +63,7 @@ public class BaseLoadBalancerService implements LoadBalancerService { protected Logger logger = Logger.NULL; protected final Supplier defaultLocationSupplier; - protected final LoadBalancerServiceContext context; + protected final LoadBalancerServiceContext context; protected final LoadBalanceNodesStrategy loadBalancerStrategy; protected final GetLoadBalancerMetadataStrategy getLoadBalancerMetadataStrategy; protected final DestroyLoadBalancerStrategy destroyLoadBalancerStrategy; @@ -71,7 +71,7 @@ public class BaseLoadBalancerService implements LoadBalancerService { protected final Supplier> locations; @Inject - protected BaseLoadBalancerService(Supplier defaultLocationSupplier, LoadBalancerServiceContext context, + protected BaseLoadBalancerService(Supplier defaultLocationSupplier, @SuppressWarnings("rawtypes") LoadBalancerServiceContext context, LoadBalanceNodesStrategy loadBalancerStrategy, GetLoadBalancerMetadataStrategy getLoadBalancerMetadataStrategy, DestroyLoadBalancerStrategy destroyLoadBalancerStrategy, ListLoadBalancersStrategy listLoadBalancersStrategy, @@ -98,7 +98,7 @@ public class BaseLoadBalancerService implements LoadBalancerService { * {@inheritDoc} */ @Override - public LoadBalancerServiceContext getContext() { + public LoadBalancerServiceContext getContext() { return context; } diff --git a/loadbalancer/src/main/java/org/jclouds/loadbalancer/internal/BaseLoadBalancerServiceApiMetadata.java b/loadbalancer/src/main/java/org/jclouds/loadbalancer/internal/BaseLoadBalancerServiceApiMetadata.java new file mode 100644 index 0000000000..e4f7d3b383 --- /dev/null +++ b/loadbalancer/src/main/java/org/jclouds/loadbalancer/internal/BaseLoadBalancerServiceApiMetadata.java @@ -0,0 +1,63 @@ +/** + * 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.loadbalancer.internal; + +import org.jclouds.apis.ApiType; +import org.jclouds.apis.internal.BaseApiMetadata; +import org.jclouds.loadbalancer.LoadBalancerServiceApiMetadata; +import org.jclouds.loadbalancer.LoadBalancerServiceContext; + +import com.google.common.annotations.Beta; +import com.google.common.reflect.TypeParameter; +import com.google.common.reflect.TypeToken; + +/** + * + * @author Adrian Cole + * @since 1.5 + */ +@Beta +public abstract class BaseLoadBalancerServiceApiMetadata, M extends LoadBalancerServiceApiMetadata> + extends BaseApiMetadata implements LoadBalancerServiceApiMetadata { + + public static class Builder, M extends LoadBalancerServiceApiMetadata> + extends BaseApiMetadata.Builder implements LoadBalancerServiceApiMetadata.Builder { + public Builder() { + type(ApiType.LOADBALANCER); + } + + /** + * {@inheritDoc} + */ + @Override + @SuppressWarnings("rawtypes") + protected TypeToken contextToken(TypeToken clientToken, TypeToken asyncClientToken) { + return new TypeToken>() { + private static final long serialVersionUID = 1L; + }.where(new TypeParameter() { + }, clientToken).where(new TypeParameter() { + }, asyncClientToken); + } + } + + protected BaseLoadBalancerServiceApiMetadata(BaseLoadBalancerServiceApiMetadata.Builder builder) { + super(builder); + } + +} \ No newline at end of file diff --git a/providers/go2cloud-jhb1/src/main/java/org/jclouds/go2cloud/Go2CloudJohannesburg1ContextBuilder.java b/loadbalancer/src/main/java/org/jclouds/loadbalancer/internal/BaseLoadBalancerServiceContextBuilder.java similarity index 54% rename from providers/go2cloud-jhb1/src/main/java/org/jclouds/go2cloud/Go2CloudJohannesburg1ContextBuilder.java rename to loadbalancer/src/main/java/org/jclouds/loadbalancer/internal/BaseLoadBalancerServiceContextBuilder.java index 732f814597..a134d63a68 100644 --- a/providers/go2cloud-jhb1/src/main/java/org/jclouds/go2cloud/Go2CloudJohannesburg1ContextBuilder.java +++ b/loadbalancer/src/main/java/org/jclouds/loadbalancer/internal/BaseLoadBalancerServiceContextBuilder.java @@ -16,29 +16,24 @@ * specific language governing permissions and limitations * under the License. */ -package org.jclouds.go2cloud; +package org.jclouds.loadbalancer.internal; -import java.util.List; -import java.util.Properties; - -import org.jclouds.elasticstack.ElasticStackContextBuilder; -import org.jclouds.go2cloud.config.Go2CloudJohannesburg1ComputeServiceContextModule; - -import com.google.inject.Module; +import org.jclouds.loadbalancer.LoadBalancerServiceApiMetadata; +import org.jclouds.loadbalancer.LoadBalancerServiceContext; +import org.jclouds.providers.ProviderMetadata; +import org.jclouds.rest.internal.ContextBuilder; /** - * * @author Adrian Cole */ -public class Go2CloudJohannesburg1ContextBuilder extends ElasticStackContextBuilder { +public abstract class BaseLoadBalancerServiceContextBuilder, M extends LoadBalancerServiceApiMetadata> + extends ContextBuilder { - public Go2CloudJohannesburg1ContextBuilder(Properties props) { - super(props); + public BaseLoadBalancerServiceContextBuilder(ProviderMetadata providerMetadata) { + super(providerMetadata); } - - @Override - protected void addContextModule(List modules) { - modules.add(new Go2CloudJohannesburg1ComputeServiceContextModule()); + + public BaseLoadBalancerServiceContextBuilder(M apiMetadata) { + super(apiMetadata); } - -} +} \ No newline at end of file diff --git a/loadbalancer/src/main/java/org/jclouds/loadbalancer/internal/LoadBalancerServiceContextImpl.java b/loadbalancer/src/main/java/org/jclouds/loadbalancer/internal/LoadBalancerServiceContextImpl.java index 9aeeaa8242..4353253c15 100644 --- a/loadbalancer/src/main/java/org/jclouds/loadbalancer/internal/LoadBalancerServiceContextImpl.java +++ b/loadbalancer/src/main/java/org/jclouds/loadbalancer/internal/LoadBalancerServiceContextImpl.java @@ -32,7 +32,7 @@ import org.jclouds.rest.Utils; * @author Adrian Cole */ @Singleton -public class LoadBalancerServiceContextImpl implements LoadBalancerServiceContext { +public class LoadBalancerServiceContextImpl implements LoadBalancerServiceContext { private final LoadBalancerService loadBalancerService; private final RestContext providerSpecificContext; private final Utils utils; @@ -46,10 +46,9 @@ public class LoadBalancerServiceContextImpl implements LoadBalancerService this.loadBalancerService = checkNotNull(loadBalancerService, "loadBalancerService"); } - @SuppressWarnings({ "unchecked", "hiding" }) @Override - public RestContext getProviderSpecificContext() { - return (RestContext) providerSpecificContext; + public RestContext getProviderSpecificContext() { + return providerSpecificContext; } @Override diff --git a/loadbalancer/src/test/java/org/jclouds/loadbalancer/BaseLoadBalancerServiceLiveTest.java b/loadbalancer/src/test/java/org/jclouds/loadbalancer/BaseLoadBalancerServiceLiveTest.java index 9fa21cf636..9bbfdb8b9f 100644 --- a/loadbalancer/src/test/java/org/jclouds/loadbalancer/BaseLoadBalancerServiceLiveTest.java +++ b/loadbalancer/src/test/java/org/jclouds/loadbalancer/BaseLoadBalancerServiceLiveTest.java @@ -21,7 +21,6 @@ package org.jclouds.loadbalancer; import static com.google.common.base.Preconditions.checkNotNull; import static org.testng.Assert.assertNotNull; -import java.io.IOException; import java.util.Map; import java.util.Properties; import java.util.Set; @@ -30,24 +29,26 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import org.jclouds.Constants; -import org.jclouds.compute.BaseVersionedServiceLiveTest; import org.jclouds.compute.ComputeServiceContext; import org.jclouds.compute.ComputeServiceContextFactory; import org.jclouds.compute.RunNodesException; import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.domain.Template; import org.jclouds.compute.predicates.NodePredicates; +import org.jclouds.domain.LoginCredentials; +import org.jclouds.domain.LoginCredentials.Builder; import org.jclouds.loadbalancer.domain.LoadBalancerMetadata; -import org.jclouds.logging.log4j.config.Log4JLoggingModule; import org.jclouds.net.IPSocket; import org.jclouds.predicates.RetryablePredicate; import org.jclouds.predicates.SocketOpen; +import org.jclouds.rest.internal.BaseContextLiveTest; import org.jclouds.ssh.SshClient; import org.testng.annotations.AfterTest; import org.testng.annotations.BeforeGroups; import org.testng.annotations.Test; -import com.google.common.collect.ImmutableSet; +import com.google.common.base.Splitter; +import com.google.common.collect.Iterables; import com.google.inject.Guice; import com.google.inject.Module; @@ -56,7 +57,39 @@ import com.google.inject.Module; * @author Adrian Cole */ @Test(groups = "live", singleThreaded = true) -public abstract class BaseLoadBalancerServiceLiveTest extends BaseVersionedServiceLiveTest { +public abstract class BaseLoadBalancerServiceLiveTest> extends BaseContextLiveTest { + + protected String imageId; + protected String loginUser; + protected String authenticateSudo; + protected LoginCredentials loginCredentials = LoginCredentials.builder().user("root").build(); + + protected Properties setupComputeProperties() { + Properties overrides = new Properties(); + overrides.setProperty(Constants.PROPERTY_TRUST_ALL_CERTS, "true"); + overrides.setProperty(Constants.PROPERTY_RELAX_HOSTNAME, "true"); + computeProvider = setIfTestSystemPropertyPresent(overrides, provider + ".compute.provider"); + computeIdentity = setIfTestSystemPropertyPresent(overrides, provider + ".compute.identity"); + computeCredential = setIfTestSystemPropertyPresent(overrides, provider + ".compute.credential"); + computeEndpoint = setIfTestSystemPropertyPresent(overrides, provider + ".compute.endpoint"); + computeApiversion = setIfTestSystemPropertyPresent(overrides, provider + ".compute.api-version"); + computeBuildversion = setIfTestSystemPropertyPresent(overrides, provider + ".compute.build-version"); + imageId = setIfTestSystemPropertyPresent(overrides, provider + ".compute.image-id"); + loginUser = setIfTestSystemPropertyPresent(overrides, provider + ".compute.image.login-user"); + authenticateSudo = setIfTestSystemPropertyPresent(overrides, provider + ".compute.image.authenticate-sudo"); + + if (loginUser != null) { + Iterable userPass = Splitter.on(':').split(loginUser); + Builder loginCredentialsBuilder = LoginCredentials.builder(); + loginCredentialsBuilder.user(Iterables.get(userPass, 0)); + if (Iterables.size(userPass) == 2) + loginCredentialsBuilder.password(Iterables.get(userPass, 1)); + if (authenticateSudo != null) + loginCredentialsBuilder.authenticateSudo(Boolean.valueOf(authenticateSudo)); + loginCredentials = loginCredentialsBuilder.build(); + } + return overrides; + } protected SshClient.Factory sshFactory; protected String group; @@ -67,7 +100,7 @@ public abstract class BaseLoadBalancerServiceLiveTest extends BaseVersionedServi protected Map keyPair; protected LoadBalancerMetadata loadbalancer; - protected LoadBalancerServiceContext context; + protected LoadBalancerServiceContext context; protected String computeProvider; protected String computeIdentity; @@ -75,44 +108,19 @@ public abstract class BaseLoadBalancerServiceLiveTest extends BaseVersionedServi protected String computeEndpoint; protected String computeApiversion; protected String computeBuildversion; - protected ComputeServiceContext computeContext; - - @Override - protected void setupCredentials() { - super.setupCredentials(); - computeProvider = checkNotNull(System.getProperty("test." + provider + ".compute.provider"), "test." + provider - + ".compute.provider"); - computeIdentity = checkNotNull(System.getProperty("test." + provider + ".compute.identity"), "test." + provider - + ".compute.identity"); - computeCredential = System.getProperty("test." + provider + ".compute.credential"); - computeEndpoint = System.getProperty("test." + provider + ".compute.endpoint"); - computeApiversion = System.getProperty("test." + provider + ".compute.api-version"); - computeBuildversion = System.getProperty("test." + provider + ".compute.build-version"); - } - - protected Properties setupComputeProperties() { - Properties overrides = new Properties(); - overrides.setProperty(Constants.PROPERTY_TRUST_ALL_CERTS, "true"); - overrides.setProperty(Constants.PROPERTY_RELAX_HOSTNAME, "true"); - overrides.setProperty(computeProvider + ".identity", computeIdentity); - if (computeCredential != null) - overrides.setProperty(computeProvider + ".credential", computeCredential); - if (computeEndpoint != null) - overrides.setProperty(computeProvider + ".endpoint", computeEndpoint); - if (computeApiversion != null) - overrides.setProperty(computeProvider + ".api-version", computeApiversion); - if (computeBuildversion != null) - overrides.setProperty(computeProvider + ".build-version", computeBuildversion); - return overrides; - } + protected ComputeServiceContext computeContext; @BeforeGroups(groups = { "integration", "live" }) - public void setupClient() throws InterruptedException, ExecutionException, TimeoutException, IOException { + @Override + public void setupContext() { setServiceDefaults(); if (group == null) group = checkNotNull(provider, "provider"); - setupCredentials(); - initializeContext(); + // groups need to work with hyphens in them, so let's make sure there is + // one! + if (group.indexOf('-') == -1) + group = group + "-"; + super.setupContext(); initializeComputeContext(); buildSocketTester(); } @@ -120,19 +128,12 @@ public abstract class BaseLoadBalancerServiceLiveTest extends BaseVersionedServi public void setServiceDefaults() { } - - private void initializeContext() throws IOException { - if (context != null) - context.close(); - context = new LoadBalancerServiceContextFactory(setupRestProperties()).createContext(provider, - ImmutableSet.of(new Log4JLoggingModule()), setupProperties()); - } - - private void initializeComputeContext() throws IOException { + + protected void initializeComputeContext() { if (computeContext != null) computeContext.close(); - computeContext = new ComputeServiceContextFactory(setupRestProperties()).createContext(computeProvider, - ImmutableSet.of(new Log4JLoggingModule(), getSshModule()), setupComputeProperties()); + computeContext = new ComputeServiceContextFactory().createContext(computeProvider, setupModules(), + setupComputeProperties()); } protected void buildSocketTester() { diff --git a/loadbalancer/src/test/java/org/jclouds/loadbalancer/internal/BaseLoadBalancerServiceApiMetadataTest.java b/loadbalancer/src/test/java/org/jclouds/loadbalancer/internal/BaseLoadBalancerServiceApiMetadataTest.java new file mode 100644 index 0000000000..f55b210d32 --- /dev/null +++ b/loadbalancer/src/test/java/org/jclouds/loadbalancer/internal/BaseLoadBalancerServiceApiMetadataTest.java @@ -0,0 +1,34 @@ +package org.jclouds.loadbalancer.internal; + +import java.util.Set; + +import org.jclouds.apis.ApiMetadata; +import org.jclouds.apis.ApiType; +import org.jclouds.apis.Apis; +import org.jclouds.apis.internal.BaseApiMetadataTest; +import org.jclouds.loadbalancer.LoadBalancerServiceApiMetadata; +import org.jclouds.loadbalancer.LoadBalancerServiceContext; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableSet; +import com.google.common.reflect.TypeToken; + +/** + * + * @author Adrian Cole + */ +@Test(groups = "unit") +public abstract class BaseLoadBalancerServiceApiMetadataTest extends BaseApiMetadataTest { + + @SuppressWarnings("rawtypes") + public BaseLoadBalancerServiceApiMetadataTest(LoadBalancerServiceApiMetadata toTest) { + super(toTest, ApiType.LOADBALANCER); + } + + @Test + public void testContextAssignableFromLoadBalancerServiceContext() { + Set> all = ImmutableSet.copyOf(Apis.contextAssignableFrom(TypeToken.of(LoadBalancerServiceContext.class))); + assert all.contains(toTest) : String.format("%s not found in %s", toTest, all); + } + +} \ No newline at end of file diff --git a/providers/aws-cloudwatch/src/main/java/org/jclouds/aws/cloudwatch/AWSCloudWatchPropertiesBuilder.java b/providers/aws-cloudwatch/src/main/java/org/jclouds/aws/cloudwatch/AWSCloudWatchPropertiesBuilder.java deleted file mode 100644 index a3e988789f..0000000000 --- a/providers/aws-cloudwatch/src/main/java/org/jclouds/aws/cloudwatch/AWSCloudWatchPropertiesBuilder.java +++ /dev/null @@ -1,73 +0,0 @@ -/** - * 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.aws.cloudwatch; - -import static org.jclouds.Constants.PROPERTY_API_VERSION; -import static org.jclouds.Constants.PROPERTY_ENDPOINT; -import static org.jclouds.aws.reference.AWSConstants.PROPERTY_AUTH_TAG; -import static org.jclouds.aws.reference.AWSConstants.PROPERTY_HEADER_TAG; -import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGION; - -import java.util.Properties; - -import org.jclouds.aws.domain.Region; -import org.jclouds.cloudwatch.CloudWatchAsyncClient; -import org.jclouds.cloudwatch.CloudWatchPropertiesBuilder; - -/** - * Builds properties used in CloudWatch Clients - * - * @author Adrian Cole - */ -public class AWSCloudWatchPropertiesBuilder extends CloudWatchPropertiesBuilder { - - @Override - protected Properties defaultProperties() { - Properties properties = super.defaultProperties(); - properties.setProperty(PROPERTY_AUTH_TAG, "AWS"); - properties.setProperty(PROPERTY_HEADER_TAG, "amz"); - properties.setProperty(PROPERTY_API_VERSION, CloudWatchAsyncClient.VERSION); - properties.putAll(Region.regionProperties()); - properties.setProperty(PROPERTY_ENDPOINT, "https://monitoring.us-east-1.amazonaws.com"); - properties.setProperty(PROPERTY_REGION + "." + Region.US_EAST_1 + ".endpoint", - "https://monitoring.us-east-1.amazonaws.com"); - properties.setProperty(PROPERTY_REGION + "." + Region.US_WEST_1 + ".endpoint", - "https://monitoring.us-west-1.amazonaws.com"); - properties.setProperty(PROPERTY_REGION + "." + Region.US_WEST_2 + ".endpoint", - "https://monitoring.us-west-2.amazonaws.com"); - properties.setProperty(PROPERTY_REGION + "." + Region.SA_EAST_1 + ".endpoint", - "https://monitoring.sa-east-1.amazonaws.com"); - properties.setProperty(PROPERTY_REGION + "." + Region.EU_WEST_1 + ".endpoint", - "https://monitoring.eu-west-1.amazonaws.com"); - properties.setProperty(PROPERTY_REGION + "." + Region.AP_SOUTHEAST_1 + ".endpoint", - "https://monitoring.ap-southeast-1.amazonaws.com"); - properties.setProperty(PROPERTY_REGION + "." + Region.AP_NORTHEAST_1 + ".endpoint", - "https://monitoring.ap-northeast-1.amazonaws.com"); - return properties; - } - - public AWSCloudWatchPropertiesBuilder() { - super(); - } - - public AWSCloudWatchPropertiesBuilder(Properties properties) { - super(properties); - } - -} diff --git a/providers/aws-cloudwatch/src/main/java/org/jclouds/aws/cloudwatch/AWSCloudWatchProviderMetadata.java b/providers/aws-cloudwatch/src/main/java/org/jclouds/aws/cloudwatch/AWSCloudWatchProviderMetadata.java index 32031a90fe..56d4a634dd 100644 --- a/providers/aws-cloudwatch/src/main/java/org/jclouds/aws/cloudwatch/AWSCloudWatchProviderMetadata.java +++ b/providers/aws-cloudwatch/src/main/java/org/jclouds/aws/cloudwatch/AWSCloudWatchProviderMetadata.java @@ -18,51 +18,91 @@ */ package org.jclouds.aws.cloudwatch; -import java.net.URI; +import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGION; +import java.net.URI; +import java.util.Properties; + +import org.jclouds.aws.domain.Region; import org.jclouds.cloudwatch.CloudWatchApiMetadata; -import org.jclouds.providers.BaseProviderMetadata; +import org.jclouds.cloudwatch.CloudWatchAsyncClient; +import org.jclouds.cloudwatch.CloudWatchClient; +import org.jclouds.providers.ProviderMetadata; +import org.jclouds.providers.internal.BaseProviderMetadata; +import org.jclouds.rest.RestContext; /** * Implementation of @ link org.jclouds.types.ProviderMetadata} for Amazon's CloudWatch * provider. - * - * @author Adrian Cole - */ -public class AWSCloudWatchProviderMetadata extends BaseProviderMetadata { - - public AWSCloudWatchProviderMetadata() { - this(builder() - .id("aws-cloudwatch") - .name("Amazon CloudWatch") - .api(new CloudWatchApiMetadata()) - .homepage(URI.create("http://aws.amazon.com/cloudwatch")) - .console(URI.create("https://console.aws.amazon.com/cloudwatch/home")) - .linkedServices("aws-ec2","aws-elb", "aws-cloudwatch", "aws-s3", "aws-simpledb") - .iso3166Codes("US-VA", "US-CA", "BR-SP", "US-OR", "IE", "SG", "JP-13")); +* +* @author Adrian Cole +*/ +public class AWSCloudWatchProviderMetadata extends BaseProviderMetadata, CloudWatchApiMetadata> { + + public static Builder builder() { + return new Builder(); } - // below are so that we can reuse builders, toString, hashCode, etc. - // we have to set concrete classes here, as our base class cannot be - // concrete due to serviceLoader - protected AWSCloudWatchProviderMetadata(ConcreteBuilder builder) { + @Override + public Builder toBuilder() { + return builder().fromProviderMetadata(this); + } + + public AWSCloudWatchProviderMetadata() { + super(builder()); + } + + public AWSCloudWatchProviderMetadata(Builder builder) { super(builder); } - private static class ConcreteBuilder extends Builder { + protected static Properties defaultProperties() { + Properties properties = new Properties(); + properties.putAll(Region.regionProperties()); + properties.setProperty(PROPERTY_REGION + "." + Region.US_EAST_1 + ".endpoint", + "https://monitoring.us-east-1.amazonaws.com"); + properties.setProperty(PROPERTY_REGION + "." + Region.US_WEST_1 + ".endpoint", + "https://monitoring.us-west-1.amazonaws.com"); + properties.setProperty(PROPERTY_REGION + "." + Region.US_WEST_2 + ".endpoint", + "https://monitoring.us-west-2.amazonaws.com"); + properties.setProperty(PROPERTY_REGION + "." + Region.SA_EAST_1 + ".endpoint", + "https://monitoring.sa-east-1.amazonaws.com"); + properties.setProperty(PROPERTY_REGION + "." + Region.EU_WEST_1 + ".endpoint", + "https://monitoring.eu-west-1.amazonaws.com"); + properties.setProperty(PROPERTY_REGION + "." + Region.AP_SOUTHEAST_1 + ".endpoint", + "https://monitoring.ap-southeast-1.amazonaws.com"); + properties.setProperty(PROPERTY_REGION + "." + Region.AP_NORTHEAST_1 + ".endpoint", + "https://monitoring.ap-northeast-1.amazonaws.com"); + return properties; + } + + public static class Builder extends BaseProviderMetadata.Builder, CloudWatchApiMetadata> { + + protected Builder(){ + id("aws-cloudwatch") + .name("Amazon CloudWatch") + .endpoint("https://monitoring.us-east-1.amazonaws.com") + .homepage(URI.create("http://aws.amazon.com/cloudwatch")) + .console(URI.create("https://console.aws.amazon.com/cloudwatch/home")) + .linkedServices("aws-ec2","aws-elb", "aws-cloudwatch", "aws-s3", "aws-simpledb") + .iso3166Codes("US-VA", "US-CA", "BR-SP", "US-OR", "IE", "SG", "JP-13") + .apiMetadata( + new CloudWatchApiMetadata().toBuilder() + .version("2010-08-01").build()) + .defaultProperties(AWSCloudWatchProviderMetadata.defaultProperties()); + } @Override public AWSCloudWatchProviderMetadata build() { return new AWSCloudWatchProviderMetadata(this); } - } + + @Override + public Builder fromProviderMetadata( + ProviderMetadata, CloudWatchApiMetadata> in) { + super.fromProviderMetadata(in); + return this; + } - public static ConcreteBuilder builder() { - return new ConcreteBuilder(); } - - public ConcreteBuilder toBuilder() { - return builder().fromProviderMetadata(this); - } - -} +} \ No newline at end of file diff --git a/providers/aws-cloudwatch/src/test/java/org/jclouds/aws/cloudwatch/AWSCloudWatchProviderTest.java b/providers/aws-cloudwatch/src/test/java/org/jclouds/aws/cloudwatch/AWSCloudWatchProviderTest.java index 77882b1624..34e534042c 100644 --- a/providers/aws-cloudwatch/src/test/java/org/jclouds/aws/cloudwatch/AWSCloudWatchProviderTest.java +++ b/providers/aws-cloudwatch/src/test/java/org/jclouds/aws/cloudwatch/AWSCloudWatchProviderTest.java @@ -19,7 +19,9 @@ package org.jclouds.aws.cloudwatch; import org.jclouds.cloudwatch.CloudWatchApiMetadata; -import org.jclouds.providers.BaseProviderMetadataTest; +import org.jclouds.cloudwatch.CloudWatchAsyncClient; +import org.jclouds.cloudwatch.CloudWatchClient; +import org.jclouds.providers.internal.BaseProviderMetadataTest; import org.testng.annotations.Test; /** @@ -31,6 +33,6 @@ import org.testng.annotations.Test; public class AWSCloudWatchProviderTest extends BaseProviderMetadataTest { public AWSCloudWatchProviderTest() { - super(new AWSCloudWatchProviderMetadata(), new CloudWatchApiMetadata()); + super(new AWSCloudWatchProviderMetadata(), new CloudWatchApiMetadata()); } } diff --git a/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/AWSEC2ApiMetadata.java b/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/AWSEC2ApiMetadata.java index 04cf5b3de4..8fec86622d 100644 --- a/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/AWSEC2ApiMetadata.java +++ b/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/AWSEC2ApiMetadata.java @@ -18,43 +18,70 @@ */ package org.jclouds.aws.ec2; +import static org.jclouds.aws.ec2.reference.AWSEC2Constants.PROPERTY_EC2_GENERATE_INSTANCE_NAMES; + +import java.util.Properties; + import org.jclouds.apis.ApiMetadata; +import org.jclouds.aws.ec2.compute.AWSEC2ComputeServiceContext; import org.jclouds.ec2.EC2ApiMetadata; +import com.google.common.reflect.TypeToken; + /** * Implementation of {@link ApiMetadata} for the Amazon-specific EC2 API * * @author Adrian Cole */ -public class AWSEC2ApiMetadata extends EC2ApiMetadata { +public class AWSEC2ApiMetadata extends EC2ApiMetadata { + private static Builder builder() { + return new Builder(); + } + + @Override + public Builder toBuilder() { + return builder().fromApiMetadata(this); + } public AWSEC2ApiMetadata() { - this(builder().fromApiMetadata(new EC2ApiMetadata()) - .id("aws-ec2") - .name("Amazon-specific EC2 API")); + this(builder()); } - // below are so that we can reuse builders, toString, hashCode, etc. - // we have to set concrete classes here, as our base class cannot be - // concrete due to serviceLoader - protected AWSEC2ApiMetadata(ConcreteBuilder builder) { + protected AWSEC2ApiMetadata(Builder builder) { super(builder); } + + protected static Properties defaultProperties() { + Properties properties = EC2ApiMetadata.defaultProperties(); + // auth fail sometimes happens in EC2, as the rc.local script that injects the + // authorized key executes after ssh has started. + properties.setProperty("jclouds.ssh.max-retries", "7"); + properties.setProperty("jclouds.ssh.retry-auth", "true"); + properties.setProperty(PROPERTY_EC2_GENERATE_INSTANCE_NAMES, "true"); + return properties; + } - private static class ConcreteBuilder extends EC2ApiMetadataBuilder { - + public static class Builder extends EC2ApiMetadata.Builder { + protected Builder(){ + super(AWSEC2Client.class, AWSEC2AsyncClient.class); + id("aws-ec2") + .version(AWSEC2AsyncClient.VERSION) + .name("Amazon-specific EC2 API") + .context(TypeToken.of(AWSEC2ComputeServiceContext.class)) + .defaultProperties(AWSEC2ApiMetadata.defaultProperties()) + .contextBuilder(TypeToken.of(AWSEC2ContextBuilder.class)); + } + @Override public AWSEC2ApiMetadata build() { return new AWSEC2ApiMetadata(this); } + + @Override + public Builder fromApiMetadata(AWSEC2ApiMetadata in) { + super.fromApiMetadata(in); + return this; + } } - private static ConcreteBuilder builder() { - return new ConcreteBuilder(); - } - - @Override - public ConcreteBuilder toBuilder() { - return builder().fromApiMetadata(this); - } } \ No newline at end of file diff --git a/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/AWSEC2ContextBuilder.java b/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/AWSEC2ContextBuilder.java index 63bfd9e320..8a9c443933 100644 --- a/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/AWSEC2ContextBuilder.java +++ b/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/AWSEC2ContextBuilder.java @@ -25,9 +25,11 @@ import java.util.List; import java.util.Properties; import java.util.logging.Logger; +import org.jclouds.aws.ec2.compute.AWSEC2ComputeServiceContext; import org.jclouds.aws.ec2.compute.config.AWSEC2ComputeServiceContextModule; import org.jclouds.aws.ec2.config.AWSEC2RestClientModule; import org.jclouds.ec2.EC2ContextBuilder; +import org.jclouds.providers.ProviderMetadata; import com.google.common.annotations.VisibleForTesting; import com.google.inject.Module; @@ -36,19 +38,28 @@ import com.google.inject.Module; * * @author Adrian Cole */ -public class AWSEC2ContextBuilder extends EC2ContextBuilder { +public class AWSEC2ContextBuilder extends + EC2ContextBuilder { + public AWSEC2ContextBuilder() { + this(new AWSEC2ProviderMetadata()); + } - public AWSEC2ContextBuilder(Properties props) { - super(warnAndReplaceIfUsingOldImageKey(props)); + public AWSEC2ContextBuilder( + ProviderMetadata providerMetadata) { + super(providerMetadata); } - - @VisibleForTesting + + public AWSEC2ContextBuilder(AWSEC2ApiMetadata apiMetadata) { + super(apiMetadata); + } + @Override - public Properties getProperties(){ - return properties; + public AWSEC2ContextBuilder overrides(Properties overrides) { + super.overrides(warnAndReplaceIfUsingOldImageKey(overrides)); + return this; } - - //TODO: determine how to do conditional manipulation w/rocoto + + // TODO: determine how to do conditional manipulation w/rocoto static Properties warnAndReplaceIfUsingOldImageKey(Properties props) { if (props.containsKey(PROPERTY_EC2_AMI_OWNERS)) { StringBuilder query = new StringBuilder(); @@ -61,12 +72,12 @@ public class AWSEC2ContextBuilder extends EC2ContextBuilder { query = new StringBuilder(); props.setProperty(PROPERTY_EC2_AMI_QUERY, query.toString()); Logger.getAnonymousLogger().warning( - String.format("Property %s is deprecated, please use new syntax: %s=%s", PROPERTY_EC2_AMI_OWNERS, - PROPERTY_EC2_AMI_QUERY, query.toString())); + String.format("Property %s is deprecated, please use new syntax: %s=%s", PROPERTY_EC2_AMI_OWNERS, + PROPERTY_EC2_AMI_QUERY, query.toString())); } return props; } - + @Override protected void addClientModule(List modules) { modules.add(new AWSEC2RestClientModule()); @@ -77,4 +88,9 @@ public class AWSEC2ContextBuilder extends EC2ContextBuilder { modules.add(new AWSEC2ComputeServiceContextModule()); } + @VisibleForTesting + public Properties getOverrides() { + return overrides; + } + } diff --git a/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/AWSEC2PropertiesBuilder.java b/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/AWSEC2PropertiesBuilder.java deleted file mode 100644 index a79f049004..0000000000 --- a/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/AWSEC2PropertiesBuilder.java +++ /dev/null @@ -1,77 +0,0 @@ -/** - * 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.aws.ec2; - -import static org.jclouds.Constants.PROPERTY_API_VERSION; -import static org.jclouds.Constants.PROPERTY_ENDPOINT; -import static org.jclouds.aws.ec2.reference.AWSEC2Constants.PROPERTY_EC2_AMI_QUERY; -import static org.jclouds.aws.ec2.reference.AWSEC2Constants.PROPERTY_EC2_CC_AMI_QUERY; -import static org.jclouds.aws.ec2.reference.AWSEC2Constants.PROPERTY_EC2_CC_REGIONS; -import static org.jclouds.aws.ec2.reference.AWSEC2Constants.PROPERTY_EC2_GENERATE_INSTANCE_NAMES; -import static org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_NODE_SUSPENDED; -import static org.jclouds.ec2.reference.EC2Constants.PROPERTY_EC2_AMI_OWNERS; - -import java.util.Properties; - -import org.jclouds.aws.domain.Region; - -/** - * Builds properties used in EC2 Clients - * - * @author Adrian Cole - */ -public class AWSEC2PropertiesBuilder extends org.jclouds.ec2.EC2PropertiesBuilder { - @Override - protected Properties defaultProperties() { - Properties properties = super.defaultProperties(); - properties.setProperty(PROPERTY_API_VERSION, AWSEC2AsyncClient.VERSION); - // sometimes, like in ec2, stop takes a very long time, perhaps - // due to volume management. one example spent 2 minutes moving - // from stopping->stopped state on an ec2 micro - properties.setProperty(TIMEOUT_NODE_SUSPENDED, 120 * 1000 + ""); - // auth fail sometimes happens in EC2, as the rc.local script that injects the - // authorized key executes after ssh has started. - properties.setProperty("jclouds.ssh.max-retries", "7"); - properties.setProperty("jclouds.ssh.retry-auth", "true"); - properties.setProperty(PROPERTY_ENDPOINT, "https://ec2.us-east-1.amazonaws.com"); - properties.setProperty(PROPERTY_EC2_GENERATE_INSTANCE_NAMES, "true"); - properties.putAll(Region.regionProperties()); - properties.remove(PROPERTY_EC2_AMI_OWNERS); - // amazon, alestic, canonical, and rightscale - properties.setProperty(PROPERTY_EC2_AMI_QUERY, - "owner-id=137112412989,063491364108,099720109477,411009282317;state=available;image-type=machine"); - // amis that work with the cluster instances - properties.setProperty(PROPERTY_EC2_CC_REGIONS, Region.US_EAST_1); - properties - .setProperty( - PROPERTY_EC2_CC_AMI_QUERY, - "virtualization-type=hvm;architecture=x86_64;owner-id=137112412989,099720109477;hypervisor=xen;state=available;image-type=machine;root-device-type=ebs"); - return properties; - } - - public AWSEC2PropertiesBuilder() { - super(); - } - - public AWSEC2PropertiesBuilder(Properties properties) { - super(properties); - } - - -} diff --git a/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/AWSEC2ProviderMetadata.java b/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/AWSEC2ProviderMetadata.java index 945c4188a1..46a34a8212 100644 --- a/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/AWSEC2ProviderMetadata.java +++ b/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/AWSEC2ProviderMetadata.java @@ -18,50 +18,90 @@ */ package org.jclouds.aws.ec2; -import java.net.URI; +import static org.jclouds.aws.ec2.reference.AWSEC2Constants.PROPERTY_EC2_AMI_QUERY; +import static org.jclouds.aws.ec2.reference.AWSEC2Constants.PROPERTY_EC2_CC_AMI_QUERY; +import static org.jclouds.aws.ec2.reference.AWSEC2Constants.PROPERTY_EC2_CC_REGIONS; +import static org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_NODE_SUSPENDED; +import static org.jclouds.ec2.reference.EC2Constants.PROPERTY_EC2_AMI_OWNERS; -import org.jclouds.providers.BaseProviderMetadata; +import java.net.URI; +import java.util.Properties; + +import org.jclouds.aws.domain.Region; +import org.jclouds.aws.ec2.compute.AWSEC2ComputeServiceContext; +import org.jclouds.providers.ProviderMetadata; +import org.jclouds.providers.internal.BaseProviderMetadata; /** * Implementation of {@ link org.jclouds.types.ProviderMetadata} for Amazon's * Elastic Compute Cloud (EC2) provider. * - * @author Jeremy Whitlock + * @author Adrian Cole */ -public class AWSEC2ProviderMetadata extends BaseProviderMetadata { - - public AWSEC2ProviderMetadata() { - this(builder() - .id("aws-ec2") - .name("Amazon Elastic Compute Cloud (EC2)") - .api(new AWSEC2ApiMetadata()) - .homepage(URI.create("http://aws.amazon.com/ec2")) - .console(URI.create("https://console.aws.amazon.com/ec2/home")) - .linkedServices("aws-ec2","aws-elb", "aws-cloudwatch", "aws-s3", "aws-simpledb") - .iso3166Codes("US-VA", "US-CA", "US-OR", "BR-SP", "IE", "SG", "JP-13")); +public class AWSEC2ProviderMetadata extends BaseProviderMetadata { + + public static Builder builder() { + return new Builder(); } - // below are so that we can reuse builders, toString, hashCode, etc. - // we have to set concrete classes here, as our base class cannot be - // concrete due to serviceLoader - protected AWSEC2ProviderMetadata(ConcreteBuilder builder) { + @Override + public Builder toBuilder() { + return builder().fromProviderMetadata(this); + } + + public AWSEC2ProviderMetadata() { + super(builder()); + } + + public AWSEC2ProviderMetadata(Builder builder) { super(builder); } - private static class ConcreteBuilder extends Builder { + protected static Properties defaultProperties() { + Properties properties = new Properties(); + // sometimes, like in ec2, stop takes a very long time, perhaps + // due to volume management. one example spent 2 minutes moving + // from stopping->stopped state on an ec2 micro + properties.setProperty(TIMEOUT_NODE_SUSPENDED, 120 * 1000 + ""); + properties.putAll(Region.regionProperties()); + properties.remove(PROPERTY_EC2_AMI_OWNERS); + // amazon, alestic, canonical, and rightscale + properties.setProperty(PROPERTY_EC2_AMI_QUERY, + "owner-id=137112412989,063491364108,099720109477,411009282317;state=available;image-type=machine"); + // amis that work with the cluster instances + properties.setProperty(PROPERTY_EC2_CC_REGIONS, Region.US_EAST_1); + properties + .setProperty( + PROPERTY_EC2_CC_AMI_QUERY, + "virtualization-type=hvm;architecture=x86_64;owner-id=137112412989,099720109477;hypervisor=xen;state=available;image-type=machine;root-device-type=ebs"); + return properties; + } + + public static class Builder extends BaseProviderMetadata.Builder { + + protected Builder(){ + id("aws-ec2") + .name("Amazon Elastic Compute Cloud (EC2)") + .apiMetadata(new AWSEC2ApiMetadata()) + .endpoint("https://ec2.us-east-1.amazonaws.com") + .homepage(URI.create("http://aws.amazon.com/ec2")) + .console(URI.create("https://console.aws.amazon.com/ec2/home")) + .defaultProperties(AWSEC2ProviderMetadata.defaultProperties()) + .linkedServices("aws-ec2","aws-elb", "aws-cloudwatch", "aws-s3", "aws-simpledb") + .iso3166Codes("US-VA", "US-CA", "US-OR", "BR-SP", "IE", "SG", "JP-13"); + } @Override public AWSEC2ProviderMetadata build() { return new AWSEC2ProviderMetadata(this); } - } - public static ConcreteBuilder builder() { - return new ConcreteBuilder(); - } + @Override + public Builder fromProviderMetadata( + ProviderMetadata in) { + super.fromProviderMetadata(in); + return this; + } - public ConcreteBuilder toBuilder() { - return builder().fromProviderMetadata(this); } - } \ No newline at end of file diff --git a/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/compute/AWSEC2ComputeService.java b/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/compute/AWSEC2ComputeService.java index d54c7ed19d..758630b61c 100644 --- a/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/compute/AWSEC2ComputeService.java +++ b/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/compute/AWSEC2ComputeService.java @@ -92,7 +92,7 @@ public class AWSEC2ComputeService extends EC2ComputeService { private final boolean generateInstanceNames; @Inject - protected AWSEC2ComputeService(ComputeServiceContext context, Map credentialStore, + protected AWSEC2ComputeService(@SuppressWarnings("rawtypes") ComputeServiceContext context, Map credentialStore, @Memoized Supplier> images, @Memoized Supplier> sizes, @Memoized Supplier> locations, ListNodesStrategy listNodesStrategy, GetNodeMetadataStrategy getNodeMetadataStrategy, diff --git a/providers/cloudsigma-zrh/src/main/java/org/jclouds/cloudsigma/CloudSigmaZurichContextBuilder.java b/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/compute/AWSEC2ComputeServiceContext.java similarity index 61% rename from providers/cloudsigma-zrh/src/main/java/org/jclouds/cloudsigma/CloudSigmaZurichContextBuilder.java rename to providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/compute/AWSEC2ComputeServiceContext.java index a62728d5a2..2b1642a084 100644 --- a/providers/cloudsigma-zrh/src/main/java/org/jclouds/cloudsigma/CloudSigmaZurichContextBuilder.java +++ b/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/compute/AWSEC2ComputeServiceContext.java @@ -16,28 +16,20 @@ * specific language governing permissions and limitations * under the License. */ -package org.jclouds.cloudsigma; +package org.jclouds.aws.ec2.compute; -import java.util.List; -import java.util.Properties; +import org.jclouds.aws.ec2.AWSEC2AsyncClient; +import org.jclouds.aws.ec2.AWSEC2Client; +import org.jclouds.aws.ec2.compute.internal.AWSEC2ComputeServiceContextImpl; +import org.jclouds.ec2.compute.EC2ComputeServiceContext; -import org.jclouds.cloudsigma.compute.config.CloudSigmaZurichComputeServiceContextModule; - -import com.google.inject.Module; +import com.google.inject.ImplementedBy; /** - * * @author Adrian Cole */ -public class CloudSigmaZurichContextBuilder extends CloudSigmaContextBuilder { - - public CloudSigmaZurichContextBuilder(Properties props) { - super(props); - } - +@ImplementedBy(AWSEC2ComputeServiceContextImpl.class) +public interface AWSEC2ComputeServiceContext extends EC2ComputeServiceContext { @Override - protected void addContextModule(List modules) { - modules.add(new CloudSigmaZurichComputeServiceContextModule()); - } - -} + AWSEC2ComputeService getComputeService(); +} \ No newline at end of file diff --git a/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/compute/config/AWSEC2ComputeServiceContextModule.java b/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/compute/config/AWSEC2ComputeServiceContextModule.java index a59b027789..c46cacd2ad 100644 --- a/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/compute/config/AWSEC2ComputeServiceContextModule.java +++ b/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/compute/config/AWSEC2ComputeServiceContextModule.java @@ -28,7 +28,6 @@ import java.util.concurrent.atomic.AtomicReference; import javax.inject.Named; import javax.inject.Singleton; -import org.jclouds.aws.ec2.AWSEC2PropertiesBuilder; import org.jclouds.aws.ec2.compute.AWSEC2TemplateBuilderImpl; import org.jclouds.aws.ec2.compute.functions.AWSRunningInstanceToNodeMetadata; import org.jclouds.aws.ec2.compute.predicates.AWSEC2InstancePresent; diff --git a/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/compute/config/AWSEC2ComputeServiceDependenciesModule.java b/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/compute/config/AWSEC2ComputeServiceDependenciesModule.java index de2a4e3364..c123d18db4 100644 --- a/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/compute/config/AWSEC2ComputeServiceDependenciesModule.java +++ b/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/compute/config/AWSEC2ComputeServiceDependenciesModule.java @@ -73,6 +73,7 @@ import com.google.inject.name.Names; * @author Adrian Cole */ public class AWSEC2ComputeServiceDependenciesModule extends EC2ComputeServiceDependenciesModule { + @SuppressWarnings("rawtypes") @Override protected void configure() { bind(TemplateBuilder.class).to(EC2TemplateBuilderImpl.class); diff --git a/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/compute/internal/AWSEC2ComputeServiceContextImpl.java b/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/compute/internal/AWSEC2ComputeServiceContextImpl.java new file mode 100644 index 0000000000..4ed9c3fba1 --- /dev/null +++ b/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/compute/internal/AWSEC2ComputeServiceContextImpl.java @@ -0,0 +1,51 @@ +/** + * 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.aws.ec2.compute.internal; + +import java.util.Map; + +import javax.inject.Inject; +import javax.inject.Singleton; + +import org.jclouds.aws.ec2.AWSEC2AsyncClient; +import org.jclouds.aws.ec2.AWSEC2Client; +import org.jclouds.aws.ec2.compute.AWSEC2ComputeService; +import org.jclouds.aws.ec2.compute.AWSEC2ComputeServiceContext; +import org.jclouds.compute.Utils; +import org.jclouds.domain.Credentials; +import org.jclouds.ec2.compute.internal.EC2ComputeServiceContextImpl; +import org.jclouds.rest.RestContext; + +/** + * @author Adrian Cole + */ +@Singleton +public class AWSEC2ComputeServiceContextImpl extends EC2ComputeServiceContextImpl implements AWSEC2ComputeServiceContext { + @Inject + public AWSEC2ComputeServiceContextImpl(AWSEC2ComputeService computeService, Map credentialStore, + Utils utils, @SuppressWarnings("rawtypes") RestContext providerSpecificContext) { + super(computeService, credentialStore, utils, providerSpecificContext); + } + + @Override + public AWSEC2ComputeService getComputeService() { + return AWSEC2ComputeService.class.cast(super.getComputeService()); + } + +} diff --git a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/AWSEC2ContextBuilderTest.java b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/AWSEC2ContextBuilderTest.java index 06c18c59d1..cd2d12c99a 100644 --- a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/AWSEC2ContextBuilderTest.java +++ b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/AWSEC2ContextBuilderTest.java @@ -35,7 +35,7 @@ public class AWSEC2ContextBuilderTest { public void testConvertImageSyntax() { Properties input = new Properties(); input.setProperty(PROPERTY_EC2_AMI_OWNERS, "137112412989,063491364108,099720109477,411009282317"); - Properties props = new AWSEC2ContextBuilder(input).getProperties(); + Properties props = new AWSEC2ContextBuilder().overrides(input).getOverrides(); assertEquals(props.getProperty(PROPERTY_EC2_AMI_OWNERS), null); assertEquals(props.getProperty(PROPERTY_EC2_AMI_QUERY), "owner-id=137112412989,063491364108,099720109477,411009282317;state=available;image-type=machine"); @@ -44,7 +44,7 @@ public class AWSEC2ContextBuilderTest { public void testConvertImageSyntaxWhenStar() { Properties input = new Properties(); input.setProperty(PROPERTY_EC2_AMI_OWNERS, "*"); - Properties props = new AWSEC2ContextBuilder(input).getProperties(); + Properties props = new AWSEC2ContextBuilder().overrides(input).getOverrides(); assertEquals(props.getProperty(PROPERTY_EC2_AMI_OWNERS), null); assertEquals(props.getProperty(PROPERTY_EC2_AMI_QUERY), "state=available;image-type=machine"); } @@ -52,7 +52,7 @@ public class AWSEC2ContextBuilderTest { public void testConvertImageSyntaxWhenBlank() { Properties input = new Properties(); input.setProperty(PROPERTY_EC2_AMI_OWNERS, ""); - Properties props = new AWSEC2ContextBuilder(input).getProperties(); + Properties props = new AWSEC2ContextBuilder().overrides(input).getOverrides(); assertEquals(props.getProperty(PROPERTY_EC2_AMI_OWNERS), null); assertEquals(props.getProperty(PROPERTY_EC2_AMI_QUERY), ""); } diff --git a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/AWSEC2ProviderTest.java b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/AWSEC2ProviderTest.java index 5276ad391e..5a0c3d4bbb 100644 --- a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/AWSEC2ProviderTest.java +++ b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/AWSEC2ProviderTest.java @@ -18,7 +18,7 @@ */ package org.jclouds.aws.ec2; -import org.jclouds.providers.BaseProviderMetadataTest; +import org.jclouds.providers.internal.BaseProviderMetadataTest; import org.testng.annotations.Test; /** diff --git a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/compute/AWSEC2ComputeServiceLiveTest.java b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/compute/AWSEC2ComputeServiceLiveTest.java index 20a35d7f6a..40e15c9b77 100644 --- a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/compute/AWSEC2ComputeServiceLiveTest.java +++ b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/compute/AWSEC2ComputeServiceLiveTest.java @@ -31,6 +31,8 @@ import java.util.Date; import java.util.Set; import java.util.concurrent.TimeUnit; +import org.jclouds.aws.cloudwatch.AWSCloudWatchProviderMetadata; +import org.jclouds.aws.ec2.AWSEC2AsyncClient; import org.jclouds.aws.ec2.AWSEC2Client; import org.jclouds.aws.ec2.domain.AWSRunningInstance; import org.jclouds.aws.ec2.domain.MonitoringState; @@ -55,7 +57,7 @@ import org.jclouds.ec2.services.InstanceClient; import org.jclouds.ec2.services.KeyPairClient; import org.jclouds.logging.log4j.config.Log4JLoggingModule; import org.jclouds.rest.RestContext; -import org.jclouds.rest.RestContextFactory; +import org.jclouds.rest.internal.ContextBuilder; import org.jclouds.scriptbuilder.domain.Statements; import org.testng.annotations.Test; @@ -73,7 +75,7 @@ import com.google.inject.Module; * @author Adrian Cole */ @Test(groups = "live", singleThreaded = true, testName = "AWSEC2ComputeServiceLiveTest") -public class AWSEC2ComputeServiceLiveTest extends EC2ComputeServiceLiveTest { +public class AWSEC2ComputeServiceLiveTest extends EC2ComputeServiceLiveTest { public AWSEC2ComputeServiceLiveTest() { provider = "aws-ec2"; @@ -165,9 +167,9 @@ public class AWSEC2ComputeServiceLiveTest extends EC2ComputeServiceLiveTest { // stop the spinner future.cancel(true); - RestContext monitoringContext = new RestContextFactory() - .createContext("aws-cloudwatch", identity, credential, ImmutableSet - . of(new Log4JLoggingModule())); + RestContext monitoringContext = ContextBuilder + .newBuilder(new AWSCloudWatchProviderMetadata()) + .modules(ImmutableSet. of(new Log4JLoggingModule())).build(); try { Set datapoints = monitoringContext.getApi().getMetricStatisticsInRegion(instance.getRegion(), diff --git a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/compute/AWSEC2TemplateBuilderLiveTest.java b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/compute/AWSEC2TemplateBuilderLiveTest.java index f2e28c3776..f32ff4875e 100644 --- a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/compute/AWSEC2TemplateBuilderLiveTest.java +++ b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/compute/AWSEC2TemplateBuilderLiveTest.java @@ -28,9 +28,10 @@ import java.util.Properties; import java.util.Set; import org.jclouds.aws.domain.Region; +import org.jclouds.aws.ec2.AWSEC2AsyncClient; +import org.jclouds.aws.ec2.AWSEC2Client; import org.jclouds.aws.ec2.reference.AWSEC2Constants; import org.jclouds.compute.ComputeServiceContext; -import org.jclouds.compute.ComputeServiceContextFactory; import org.jclouds.compute.domain.OsFamily; import org.jclouds.compute.domain.OsFamilyVersion64Bit; import org.jclouds.compute.domain.Template; @@ -59,7 +60,7 @@ import com.google.inject.Module; * @author Adrian Cole */ @Test(groups = "live") -public class AWSEC2TemplateBuilderLiveTest extends EC2TemplateBuilderLiveTest { +public class AWSEC2TemplateBuilderLiveTest extends EC2TemplateBuilderLiveTest { public AWSEC2TemplateBuilderLiveTest() { provider = "aws-ec2"; @@ -96,8 +97,8 @@ public class AWSEC2TemplateBuilderLiveTest extends EC2TemplateBuilderLiveTest { public void testTemplateBuilderM1MEDIUMWithNegativeLookaroundDoesntMatchTestImages() { Template template = context.getComputeService().templateBuilder().hardwareId(InstanceType.M1_MEDIUM) - // need to select versions with double-digits so that lexicographic - // doesn't end up prefering 9.x vs 11.x + // need to select versions with double-digits so that lexicographic + // doesn't end up prefering 9.x vs 11.x .osVersionMatches("1[012].[10][04]") // negative lookahead for daily and testing, but ensure match // ubuntu-images @@ -238,15 +239,14 @@ public class AWSEC2TemplateBuilderLiveTest extends EC2TemplateBuilderLiveTest { @Test public void testTemplateBuilderWithNoOwnersParsesImageOnDemand() throws IOException { - ComputeServiceContext context = null; + ComputeServiceContext context = null; try { Properties overrides = setupProperties(); // set owners to nothing overrides.setProperty(AWSEC2Constants.PROPERTY_EC2_AMI_QUERY, ""); overrides.setProperty(AWSEC2Constants.PROPERTY_EC2_CC_AMI_QUERY, ""); - context = new ComputeServiceContextFactory().createContext(provider, - ImmutableSet. of(new Log4JLoggingModule()), overrides); + context = createContext(overrides, setupModules()); assertEquals(context.getComputeService().listImages().size(), 0); @@ -273,15 +273,14 @@ public class AWSEC2TemplateBuilderLiveTest extends EC2TemplateBuilderLiveTest { @Test public void testTemplateBuilderWithNoOwnersParsesImageOnDemandDeprecated() throws IOException { - ComputeServiceContext context = null; + ComputeServiceContext context = null; try { Properties overrides = setupProperties(); // set owners to nothing overrides.setProperty(EC2Constants.PROPERTY_EC2_AMI_OWNERS, ""); overrides.setProperty(AWSEC2Constants.PROPERTY_EC2_CC_AMI_QUERY, ""); - context = new ComputeServiceContextFactory().createContext(provider, - ImmutableSet. of(new Log4JLoggingModule()), overrides); + context = createContext(overrides, setupModules()); assertEquals(context.getComputeService().listImages().size(), 0); @@ -308,7 +307,7 @@ public class AWSEC2TemplateBuilderLiveTest extends EC2TemplateBuilderLiveTest { @Test public void testTemplateBuilderWithLessRegions() throws IOException, SecurityException, NoSuchMethodException { - ComputeServiceContext context = null; + ComputeServiceContext context = null; try { Properties overrides = setupProperties(); // set regions to only 1 @@ -318,11 +317,14 @@ public class AWSEC2TemplateBuilderLiveTest extends EC2TemplateBuilderLiveTest { overrides.setProperty(AWSEC2Constants.PROPERTY_EC2_CC_AMI_QUERY, ""); final List commandsInvoked = Lists.newArrayList(); - context = new ComputeServiceContextFactory().createContext(provider, ImmutableSet. of( - new Log4JLoggingModule(), TrackingJavaUrlHttpCommandExecutorService.newTrackingModule(commandsInvoked)), - overrides); + + context = createContext( + overrides, + ImmutableSet. of(new Log4JLoggingModule(), + TrackingJavaUrlHttpCommandExecutorService.newTrackingModule(commandsInvoked))); - assert context.getComputeService().listAssignableLocations().size() < this.context.getComputeService().listAssignableLocations().size(); + assert context.getComputeService().listAssignableLocations().size() < this.context.getComputeService() + .listAssignableLocations().size(); assertOnlyOneRegionQueriedForAvailabilityZone(commandsInvoked); @@ -346,20 +348,22 @@ public class AWSEC2TemplateBuilderLiveTest extends EC2TemplateBuilderLiveTest { } private static void assertOnlyOneRegionQueriedForAvailabilityZone(List commandsInvoked) - throws NoSuchMethodException { + throws NoSuchMethodException { assert commandsInvoked.size() == 2 : commandsInvoked; - assertEquals(getJavaMethodForRequestAtIndex(commandsInvoked, 0), AvailabilityZoneAndRegionAsyncClient.class - .getMethod("describeRegions", DescribeRegionsOptions[].class)); - assertEquals(getJavaMethodForRequestAtIndex(commandsInvoked, 1), AvailabilityZoneAndRegionAsyncClient.class - .getMethod("describeAvailabilityZonesInRegion", String.class, DescribeAvailabilityZonesOptions[].class)); + assertEquals(getJavaMethodForRequestAtIndex(commandsInvoked, 0), + AvailabilityZoneAndRegionAsyncClient.class.getMethod("describeRegions", DescribeRegionsOptions[].class)); + assertEquals(getJavaMethodForRequestAtIndex(commandsInvoked, 1), + AvailabilityZoneAndRegionAsyncClient.class.getMethod("describeAvailabilityZonesInRegion", String.class, + DescribeAvailabilityZonesOptions[].class)); } @Test public void testTemplateBuilderCanUseImageIdFromNonDefaultOwner() { - // This is the id of a public image, not owned by one of the four default owners + // This is the id of a public image, not owned by one of the four default + // owners String imageId = "us-east-1/ami-44d02f2d"; Template defaultTemplate = context.getComputeService().templateBuilder().imageId(imageId) - .imageMatches(EC2ImagePredicates.rootDeviceType(RootDeviceType.INSTANCE_STORE)).build(); + .imageMatches(EC2ImagePredicates.rootDeviceType(RootDeviceType.INSTANCE_STORE)).build(); assert (defaultTemplate.getImage().getProviderId().startsWith("ami-")) : defaultTemplate; assertEquals(defaultTemplate.getImage().getId(), imageId); } diff --git a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/services/AMIClientLiveTest.java b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/services/AMIClientLiveTest.java index 2c9ecfbf96..fd7ece9fa4 100644 --- a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/services/AMIClientLiveTest.java +++ b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/services/AMIClientLiveTest.java @@ -26,20 +26,18 @@ import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNotNull; import java.util.Iterator; -import java.util.Properties; import java.util.Set; import org.jclouds.aws.domain.Region; -import org.jclouds.compute.BaseVersionedServiceLiveTest; +import org.jclouds.aws.ec2.AWSEC2AsyncClient; +import org.jclouds.aws.ec2.AWSEC2Client; +import org.jclouds.aws.ec2.compute.AWSEC2ComputeServiceContext; import org.jclouds.compute.ComputeService; -import org.jclouds.compute.ComputeServiceContext; -import org.jclouds.compute.ComputeServiceContextFactory; import org.jclouds.compute.RunNodesException; import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.domain.Template; +import org.jclouds.compute.internal.BaseComputeServiceContextLiveTest; import org.jclouds.compute.predicates.ImagePredicates; -import org.jclouds.ec2.EC2AsyncClient; -import org.jclouds.ec2.EC2Client; import org.jclouds.ec2.domain.BlockDevice; import org.jclouds.ec2.domain.Image; import org.jclouds.ec2.domain.Image.ImageType; @@ -48,10 +46,8 @@ import org.jclouds.ec2.domain.RootDeviceType; import org.jclouds.ec2.domain.RunningInstance; import org.jclouds.ec2.domain.Snapshot; import org.jclouds.ec2.services.AMIClient; -import org.jclouds.logging.log4j.config.Log4JLoggingModule; -import org.jclouds.rest.RestContext; import org.testng.annotations.AfterTest; -import org.testng.annotations.BeforeGroups; +import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import com.google.common.base.Predicates; @@ -60,7 +56,6 @@ import com.google.common.collect.ImmutableMultimap; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; import com.google.common.collect.Sets; -import com.google.inject.Module; /** * Tests behavior of {@code AMIClient} @@ -68,7 +63,7 @@ import com.google.inject.Module; * @author Adrian Cole */ @Test(groups = "live", singleThreaded = true) -public class AMIClientLiveTest extends BaseVersionedServiceLiveTest { +public class AMIClientLiveTest extends BaseComputeServiceContextLiveTest { public AMIClientLiveTest() { provider = "aws-ec2"; // TODO: parameterize this. @@ -78,20 +73,15 @@ public class AMIClientLiveTest extends BaseVersionedServiceLiveTest { private AMIClient client; private static final String DEFAULT_MANIFEST = "adrianimages/image.manifest.xml"; private static final String DEFAULT_SNAPSHOT = "TODO"; - private RestContext context; private Set imagesToDeregister = Sets.newHashSet(); private Set snapshotsToDelete = Sets.newHashSet(); - private ComputeServiceContext jcloudsContext; - @BeforeGroups(groups = { "live" }) - public void setupClient() { - setupCredentials(); - Properties overrides = setupProperties(); - jcloudsContext = new ComputeServiceContextFactory().createContext(provider, - ImmutableSet.of(new Log4JLoggingModule()), overrides); - context = jcloudsContext.getProviderSpecificContext(); - client = context.getApi().getAMIServices(); + @Override + @BeforeClass(groups = { "integration", "live" }) + public void setupContext() { + super.setupContext(); + client = context.getProviderSpecificContext().getApi().getAMIServices(); } public void testDescribeImageNotExists() { @@ -104,7 +94,7 @@ public class AMIClientLiveTest extends BaseVersionedServiceLiveTest { } public void testDescribeImages() { - for (String region : context.getApi().getAvailabilityZoneAndRegionServices().describeRegions().keySet()) { + for (String region : context.getProviderSpecificContext().getApi().getAvailabilityZoneAndRegionServices().describeRegions().keySet()) { Set allResults = client.describeImagesInRegion(region); assertNotNull(allResults); assert allResults.size() >= 2 : allResults.size(); @@ -165,7 +155,7 @@ public class AMIClientLiveTest extends BaseVersionedServiceLiveTest { @Test public void testNewlyRegisteredImageCanBeListed() throws Exception { - ComputeService computeService = jcloudsContext.getComputeService(); + ComputeService computeService = context.getComputeService(); Snapshot snapshot = createSnapshot(computeService); // List of images before... @@ -196,10 +186,10 @@ public class AMIClientLiveTest extends BaseVersionedServiceLiveTest { Set nodes = computeService.createNodesInGroup("jcloudstest", 1, options); try { String instanceId = Iterables.getOnlyElement(nodes).getProviderId(); - Reservation reservation = Iterables.getOnlyElement(context.getApi().getInstanceServices().describeInstancesInRegion(null, instanceId)); + Reservation reservation = Iterables.getOnlyElement(context.getProviderSpecificContext().getApi().getInstanceServices().describeInstancesInRegion(null, instanceId)); RunningInstance instance = Iterables.getOnlyElement(reservation); BlockDevice device = instance.getEbsBlockDevices().get("/dev/sda1"); - Snapshot snapshot = context.getApi().getElasticBlockStoreServices().createSnapshotInRegion(null, device.getVolumeId()); + Snapshot snapshot = context.getProviderSpecificContext().getApi().getElasticBlockStoreServices().createSnapshotInRegion(null, device.getVolumeId()); snapshotsToDelete.add(snapshot.getId()); return snapshot; } finally { @@ -281,6 +271,7 @@ public class AMIClientLiveTest extends BaseVersionedServiceLiveTest { for (String imageId : imagesToDeregister) client.deregisterImageInRegion(null, imageId); for (String snapshotId : snapshotsToDelete) - context.getApi().getElasticBlockStoreServices().deleteSnapshotInRegion(null, snapshotId); + context.getProviderSpecificContext().getApi().getElasticBlockStoreServices().deleteSnapshotInRegion(null, snapshotId); } + } diff --git a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/services/AWSAMIClientLiveTest.java b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/services/AWSAMIClientLiveTest.java index 4c536fd7a0..8e2d7d25d7 100644 --- a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/services/AWSAMIClientLiveTest.java +++ b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/services/AWSAMIClientLiveTest.java @@ -25,27 +25,22 @@ import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNotNull; import java.util.Iterator; -import java.util.Properties; import java.util.Set; import org.jclouds.aws.ec2.AWSEC2AsyncClient; import org.jclouds.aws.ec2.AWSEC2Client; -import org.jclouds.compute.BaseVersionedServiceLiveTest; -import org.jclouds.compute.ComputeServiceContextFactory; +import org.jclouds.aws.ec2.compute.AWSEC2ComputeServiceContext; +import org.jclouds.compute.internal.BaseComputeServiceContextLiveTest; import org.jclouds.ec2.domain.Image; import org.jclouds.ec2.domain.Image.ImageType; import org.jclouds.ec2.domain.RootDeviceType; -import org.jclouds.logging.log4j.config.Log4JLoggingModule; -import org.jclouds.rest.RestContext; import org.testng.annotations.AfterTest; -import org.testng.annotations.BeforeGroups; +import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; import com.google.common.collect.Sets; -import com.google.inject.Module; /** * Tests behavior of {@code AWSAMIClient} @@ -53,7 +48,7 @@ import com.google.inject.Module; * @author Adrian Cole */ @Test(groups = "live", singleThreaded = true, testName = "AWSAMIClientLiveTest") -public class AWSAMIClientLiveTest extends BaseVersionedServiceLiveTest { +public class AWSAMIClientLiveTest extends BaseComputeServiceContextLiveTest { public AWSAMIClientLiveTest() { provider = "aws-ec2"; // TODO: parameterize this. @@ -63,17 +58,14 @@ public class AWSAMIClientLiveTest extends BaseVersionedServiceLiveTest { private AWSAMIClient client; private static final String DEFAULT_MANIFEST = "adrianimages/image.manifest.xml"; private static final String DEFAULT_SNAPSHOT = "TODO"; - private RestContext context; private Set imagesToDeregister = Sets.newHashSet(); - @BeforeGroups(groups = { "live" }) - public void setupClient() { - setupCredentials(); - Properties overrides = setupProperties(); - context = new ComputeServiceContextFactory().createContext(provider, - ImmutableSet. of(new Log4JLoggingModule()), overrides).getProviderSpecificContext(); - client = context.getApi().getAMIServices(); + @Override + @BeforeClass(groups = { "integration", "live" }) + public void setupContext() { + super.setupContext(); + client = context.getProviderSpecificContext().getApi().getAMIServices(); } public void testDescribeImageNotExists() { @@ -86,7 +78,7 @@ public class AWSAMIClientLiveTest extends BaseVersionedServiceLiveTest { } public void testDescribeImages() { - for (String region : context.getApi().getAvailabilityZoneAndRegionServices().describeRegions().keySet()) { + for (String region : context.getProviderSpecificContext().getApi().getAvailabilityZoneAndRegionServices().describeRegions().keySet()) { Set allResults = Sets.newLinkedHashSet(client.describeImagesInRegion(region)); assertNotNull(allResults); assert allResults.size() >= 2 : allResults.size(); diff --git a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/services/AWSInstanceClientLiveTest.java b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/services/AWSInstanceClientLiveTest.java index 5554a5b55f..068e7dec17 100644 --- a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/services/AWSInstanceClientLiveTest.java +++ b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/services/AWSInstanceClientLiveTest.java @@ -20,31 +20,24 @@ package org.jclouds.aws.ec2.services; import static org.testng.Assert.assertNotNull; -import java.util.Properties; import java.util.Set; import org.jclouds.aws.ec2.AWSEC2AsyncClient; import org.jclouds.aws.ec2.AWSEC2Client; -import org.jclouds.compute.BaseVersionedServiceLiveTest; -import org.jclouds.compute.ComputeServiceContextFactory; +import org.jclouds.aws.ec2.compute.AWSEC2ComputeServiceContext; +import org.jclouds.compute.internal.BaseComputeServiceContextLiveTest; import org.jclouds.ec2.domain.Reservation; import org.jclouds.ec2.domain.RunningInstance; -import org.jclouds.logging.log4j.config.Log4JLoggingModule; -import org.jclouds.rest.RestContext; -import org.testng.annotations.AfterTest; -import org.testng.annotations.BeforeGroups; +import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; -import com.google.common.collect.ImmutableSet; -import com.google.inject.Module; - /** * Tests behavior of {@code EC2Client} * * @author Adrian Cole */ @Test(groups = "live", singleThreaded = true) -public class AWSInstanceClientLiveTest extends BaseVersionedServiceLiveTest { +public class AWSInstanceClientLiveTest extends BaseComputeServiceContextLiveTest { public AWSInstanceClientLiveTest() { provider = "aws-ec2"; } @@ -52,29 +45,21 @@ public class AWSInstanceClientLiveTest extends BaseVersionedServiceLiveTest { public static final String PREFIX = System.getProperty("user.name") + "-ec2"; private AWSInstanceClient client; - private RestContext context; - @BeforeGroups(groups = { "live" }) - public void setupClient() { - setupCredentials(); - Properties overrides = setupProperties(); - context = new ComputeServiceContextFactory().createContext(provider, - ImmutableSet. of(new Log4JLoggingModule()), overrides).getProviderSpecificContext(); - client = context.getApi().getInstanceServices(); - + @Override + @BeforeClass(groups = { "integration", "live" }) + public void setupContext() { + super.setupContext(); + client = context.getProviderSpecificContext().getApi().getInstanceServices(); } @Test void testDescribeInstances() { - for (String region : context.getApi().getAvailabilityZoneAndRegionServices().describeRegions().keySet()) { + for (String region : context.getProviderSpecificContext().getApi().getAvailabilityZoneAndRegionServices().describeRegions().keySet()) { Set> allResults = client.describeInstancesInRegion(region); assertNotNull(allResults); assert allResults.size() >= 0 : allResults.size(); } } - @AfterTest - public void shutdown() { - context.close(); - } } diff --git a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/services/AWSKeyPairClientLiveTest.java b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/services/AWSKeyPairClientLiveTest.java index efe34ee9c9..5a915fb7aa 100644 --- a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/services/AWSKeyPairClientLiveTest.java +++ b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/services/AWSKeyPairClientLiveTest.java @@ -31,29 +31,25 @@ import static org.testng.Assert.assertNotNull; import java.io.FileNotFoundException; import java.io.IOException; import java.util.Map; -import java.util.Properties; import java.util.Set; import java.util.SortedSet; import org.jclouds.aws.domain.Region; import org.jclouds.aws.ec2.AWSEC2AsyncClient; import org.jclouds.aws.ec2.AWSEC2Client; +import org.jclouds.aws.ec2.compute.AWSEC2ComputeServiceContext; import org.jclouds.aws.ec2.compute.AWSEC2TemplateOptions; import org.jclouds.aws.ec2.domain.AWSRunningInstance; -import org.jclouds.compute.BaseVersionedServiceLiveTest; import org.jclouds.compute.ComputeServiceContext; -import org.jclouds.compute.ComputeServiceContextFactory; import org.jclouds.compute.ComputeTestUtils; import org.jclouds.compute.domain.ExecResponse; import org.jclouds.compute.domain.NodeMetadata; +import org.jclouds.compute.internal.BaseComputeServiceContextLiveTest; import org.jclouds.compute.options.TemplateOptions; import org.jclouds.domain.LoginCredentials; import org.jclouds.ec2.domain.KeyPair; import org.jclouds.logging.log4j.config.Log4JLoggingModule; -import org.jclouds.rest.RestContext; -import org.jclouds.sshj.config.SshjSshClientModule; -import org.testng.annotations.AfterTest; -import org.testng.annotations.BeforeGroups; +import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import com.google.common.collect.ImmutableSet; @@ -65,43 +61,36 @@ import com.google.inject.Module; * @author Adrian Cole */ @Test(groups = "live", singleThreaded = true) -public class AWSKeyPairClientLiveTest extends BaseVersionedServiceLiveTest { +public class AWSKeyPairClientLiveTest extends BaseComputeServiceContextLiveTest { public AWSKeyPairClientLiveTest() { provider = "aws-ec2"; } private AWSKeyPairClient client; - private RestContext context; - - private ComputeServiceContext computeContext; - - @BeforeGroups(groups = { "live" }) - public void setupClient() { - setupCredentials(); - Properties overrides = setupProperties(); - computeContext = new ComputeServiceContextFactory().createContext(provider, ImmutableSet. of( - new Log4JLoggingModule(), new SshjSshClientModule()), overrides); - context = computeContext.getProviderSpecificContext(); - client = context.getApi().getKeyPairServices(); + + @Override + @BeforeClass(groups = { "integration", "live" }) + public void setupContext() { + super.setupContext(); + client = context.getProviderSpecificContext().getApi().getKeyPairServices(); } public void testNoSsh() throws Exception { Map keyPair = ComputeTestUtils.setupKeyPair(); - AWSInstanceClient instanceClient = AWSEC2Client.class.cast(context.getApi()).getInstanceServices(); + AWSInstanceClient instanceClient = AWSEC2Client.class.cast(context.getProviderSpecificContext().getApi()).getInstanceServices(); String group = PREFIX + "unssh"; - computeContext.getComputeService().destroyNodesMatching(inGroup(group)); + context.getComputeService().destroyNodesMatching(inGroup(group)); - TemplateOptions options = computeContext.getComputeService().templateOptions(); + TemplateOptions options = context.getComputeService().templateOptions(); options.authorizePublicKey(keyPair.get("public")).as(AWSEC2TemplateOptions.class); - ComputeServiceContext noSshContext = null; + ComputeServiceContext noSshContext = null; try { - noSshContext = new ComputeServiceContextFactory().createContext(provider, ImmutableSet - .of(new Log4JLoggingModule()), setupProperties()); + noSshContext = createContext(setupProperties(), ImmutableSet. of(new Log4JLoggingModule())); Set nodes = noSshContext.getComputeService().createNodesInGroup(group, 1, options); @@ -116,7 +105,7 @@ public class AWSKeyPairClientLiveTest extends BaseVersionedServiceLiveTest { assertEquals(instance.getKeyName(), "jclouds#" + group); - Map responses = computeContext.getComputeService() + Map responses = context.getComputeService() .runScriptOnNodesMatching( runningInGroup(group), exec("echo hello"), @@ -129,7 +118,7 @@ public class AWSKeyPairClientLiveTest extends BaseVersionedServiceLiveTest { } finally { noSshContext.close(); - computeContext.getComputeService().destroyNodesMatching(inGroup(group)); + context.getComputeService().destroyNodesMatching(inGroup(group)); } } @@ -213,9 +202,5 @@ public class AWSKeyPairClientLiveTest extends BaseVersionedServiceLiveTest { protected AWSRunningInstance getInstance(AWSInstanceClient instanceClient, String id) { return getOnlyElement(getOnlyElement(instanceClient.describeInstancesInRegion(null, id))); } - - @AfterTest - public void shutdown() { - context.close(); - } + } diff --git a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/services/AWSSecurityGroupClientLiveTest.java b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/services/AWSSecurityGroupClientLiveTest.java index 7c86695f43..fc3b2a0966 100644 --- a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/services/AWSSecurityGroupClientLiveTest.java +++ b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/services/AWSSecurityGroupClientLiveTest.java @@ -23,6 +23,9 @@ import static org.testng.Assert.assertNotNull; import java.util.Set; +import org.jclouds.aws.ec2.AWSEC2AsyncClient; +import org.jclouds.aws.ec2.AWSEC2Client; +import org.jclouds.aws.ec2.compute.AWSEC2ComputeServiceContext; import org.jclouds.ec2.domain.IpPermission; import org.jclouds.ec2.domain.IpProtocol; import org.jclouds.ec2.domain.SecurityGroup; @@ -38,7 +41,7 @@ import com.google.common.collect.ImmutableMultimap; * @author Adrian Cole */ @Test(groups = "live", singleThreaded = true) -public class AWSSecurityGroupClientLiveTest extends SecurityGroupClientLiveTest { +public class AWSSecurityGroupClientLiveTest extends SecurityGroupClientLiveTest { public AWSSecurityGroupClientLiveTest() { provider = "aws-ec2"; } diff --git a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/services/BaseAWSEC2AsyncClientTest.java b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/services/BaseAWSEC2AsyncClientTest.java index 50295fe64b..3e184ba397 100644 --- a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/services/BaseAWSEC2AsyncClientTest.java +++ b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/services/BaseAWSEC2AsyncClientTest.java @@ -24,12 +24,12 @@ import static org.testng.Assert.assertEquals; import java.io.IOException; import java.net.URI; import java.util.Map; -import java.util.Properties; import java.util.Set; import javax.inject.Singleton; import org.jclouds.aws.domain.Region; +import org.jclouds.aws.ec2.AWSEC2ProviderMetadata; import org.jclouds.aws.ec2.config.AWSEC2RestClientModule; import org.jclouds.aws.filters.FormSigner; import org.jclouds.compute.domain.Image; @@ -41,9 +41,7 @@ import org.jclouds.location.config.LocationModule; import org.jclouds.location.suppliers.RegionIdToURISupplier; import org.jclouds.location.suppliers.RegionIdToZoneIdsSupplier; import org.jclouds.rest.ConfiguresRestClient; -import org.jclouds.rest.RestClientTest; -import org.jclouds.rest.RestContextFactory; -import org.jclouds.rest.RestContextSpec; +import org.jclouds.rest.internal.BaseAsyncClientTest; import org.jclouds.util.Suppliers2; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; @@ -61,7 +59,7 @@ import com.google.inject.Provides; * @author Adrian Cole */ @Test(groups = "unit") -public abstract class BaseAWSEC2AsyncClientTest extends RestClientTest { +public abstract class BaseAWSEC2AsyncClientTest extends BaseAsyncClientTest { @RequiresHttp @ConfiguresRestClient @@ -134,8 +132,8 @@ public abstract class BaseAWSEC2AsyncClientTest extends RestClientTest { protected String provider = "aws-ec2"; @Override - public RestContextSpec createContextSpec() { - return new RestContextFactory().createContextSpec(provider, "identity", "credential", new Properties()); + public AWSEC2ProviderMetadata createProviderMetadata(){ + return new AWSEC2ProviderMetadata(); } } diff --git a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/services/MonitoringClientLiveTest.java b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/services/MonitoringClientLiveTest.java index 4cd81c9fbc..a1333fa1bb 100644 --- a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/services/MonitoringClientLiveTest.java +++ b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/services/MonitoringClientLiveTest.java @@ -21,44 +21,35 @@ package org.jclouds.aws.ec2.services; import static org.testng.Assert.assertEquals; import java.util.Map; -import java.util.Properties; import org.jclouds.aws.ec2.AWSEC2AsyncClient; import org.jclouds.aws.ec2.AWSEC2Client; +import org.jclouds.aws.ec2.compute.AWSEC2ComputeServiceContext; import org.jclouds.aws.ec2.domain.MonitoringState; -import org.jclouds.compute.BaseVersionedServiceLiveTest; -import org.jclouds.compute.ComputeServiceContextFactory; -import org.jclouds.logging.log4j.config.Log4JLoggingModule; -import org.jclouds.rest.RestContext; -import org.testng.annotations.BeforeGroups; +import org.jclouds.compute.internal.BaseComputeServiceContextLiveTest; +import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; -import com.google.common.collect.ImmutableSet; -import com.google.inject.Module; - /** * Tests behavior of {@code MonitoringClient} * * @author Adrian Cole */ @Test(groups = "live", singleThreaded = true) -public class MonitoringClientLiveTest extends BaseVersionedServiceLiveTest { +public class MonitoringClientLiveTest extends BaseComputeServiceContextLiveTest { public MonitoringClientLiveTest() { provider = "aws-ec2"; } private MonitoringClient client; private static final String DEFAULT_INSTANCE = "i-TODO"; - private RestContext context; - - @BeforeGroups(groups = { "live" }) - public void setupClient() { - setupCredentials(); - Properties overrides = setupProperties(); - context = new ComputeServiceContextFactory().createContext(provider, - ImmutableSet. of(new Log4JLoggingModule()), overrides).getProviderSpecificContext(); - client = context.getApi().getMonitoringServices(); + + @Override + @BeforeClass(groups = { "integration", "live" }) + public void setupContext() { + super.setupContext(); + client = context.getProviderSpecificContext().getApi().getMonitoringServices(); } @Test(enabled = false) diff --git a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/services/PlacementGroupClientLiveTest.java b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/services/PlacementGroupClientLiveTest.java index a39c976178..0899b6ce28 100644 --- a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/services/PlacementGroupClientLiveTest.java +++ b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/services/PlacementGroupClientLiveTest.java @@ -24,41 +24,34 @@ import static com.google.common.collect.Sets.newTreeSet; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNotNull; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.util.Properties; import java.util.Set; import java.util.SortedSet; import java.util.concurrent.TimeUnit; import org.jclouds.aws.domain.Region; +import org.jclouds.aws.ec2.AWSEC2AsyncClient; import org.jclouds.aws.ec2.AWSEC2Client; +import org.jclouds.aws.ec2.compute.AWSEC2ComputeServiceContext; import org.jclouds.aws.ec2.domain.PlacementGroup; import org.jclouds.aws.ec2.domain.PlacementGroup.State; import org.jclouds.aws.ec2.predicates.PlacementGroupAvailable; import org.jclouds.aws.ec2.predicates.PlacementGroupDeleted; -import org.jclouds.compute.BaseVersionedServiceLiveTest; -import org.jclouds.compute.ComputeServiceContext; -import org.jclouds.compute.ComputeServiceContextFactory; import org.jclouds.compute.RunNodesException; import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.domain.OsFamily; import org.jclouds.compute.domain.Template; +import org.jclouds.compute.internal.BaseComputeServiceContextLiveTest; import org.jclouds.compute.predicates.NodePredicates; import org.jclouds.ec2.domain.InstanceType; -import org.jclouds.logging.log4j.config.Log4JLoggingModule; import org.jclouds.predicates.RetryablePredicate; import org.jclouds.scriptbuilder.domain.Statements; import org.jclouds.scriptbuilder.statements.java.InstallJDK; import org.jclouds.scriptbuilder.statements.login.AdminAccess; -import org.jclouds.sshj.config.SshjSshClientModule; import org.testng.annotations.AfterTest; -import org.testng.annotations.BeforeGroups; +import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import com.google.common.base.Throwables; -import com.google.common.collect.ImmutableSet; -import com.google.inject.Module; /** * Tests behavior of {@code PlacementGroupClient} @@ -66,25 +59,21 @@ import com.google.inject.Module; * @author Adrian Cole */ @Test(groups = "live", singleThreaded = true, testName = "PlacementGroupClientLiveTest") -public class PlacementGroupClientLiveTest extends BaseVersionedServiceLiveTest { +public class PlacementGroupClientLiveTest extends BaseComputeServiceContextLiveTest { public PlacementGroupClientLiveTest() { provider = "aws-ec2"; } private AWSEC2Client client; - private ComputeServiceContext context; private RetryablePredicate availableTester; private RetryablePredicate deletedTester; private PlacementGroup group; - - @BeforeGroups(groups = { "live" }) - public void setupClient() throws FileNotFoundException, IOException { - setupCredentials(); - Properties overrides = setupProperties(); - context = new ComputeServiceContextFactory().createContext(provider, - ImmutableSet. of(new Log4JLoggingModule(), new SshjSshClientModule()), overrides); - - client = AWSEC2Client.class.cast(context.getProviderSpecificContext().getApi()); + + @Override + @BeforeClass(groups = { "integration", "live" }) + public void setupContext() { + super.setupContext(); + client = context.getProviderSpecificContext().getApi(); availableTester = new RetryablePredicate(new PlacementGroupAvailable(client), 60, 1, TimeUnit.SECONDS); @@ -179,6 +168,5 @@ public class PlacementGroupClientLiveTest extends BaseVersionedServiceLiveTest { client.getPlacementGroupServices().deletePlacementGroupInRegion(group.getRegion(), group.getName()); assert deletedTester.apply(group) : group; } - context.close(); } } diff --git a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/services/SpotInstanceClientLiveTest.java b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/services/SpotInstanceClientLiveTest.java index 8908d7e48a..32c895b320 100644 --- a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/services/SpotInstanceClientLiveTest.java +++ b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/services/SpotInstanceClientLiveTest.java @@ -25,35 +25,29 @@ import static org.jclouds.aws.ec2.options.RequestSpotInstancesOptions.Builder.la import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNotNull; -import java.io.FileNotFoundException; -import java.io.IOException; import java.util.Date; -import java.util.Properties; import java.util.Set; import java.util.SortedSet; import java.util.concurrent.TimeUnit; import org.jclouds.aws.domain.Region; +import org.jclouds.aws.ec2.AWSEC2AsyncClient; import org.jclouds.aws.ec2.AWSEC2Client; +import org.jclouds.aws.ec2.compute.AWSEC2ComputeServiceContext; import org.jclouds.aws.ec2.domain.AWSRunningInstance; import org.jclouds.aws.ec2.domain.LaunchSpecification; import org.jclouds.aws.ec2.domain.Spot; import org.jclouds.aws.ec2.domain.SpotInstanceRequest; import org.jclouds.aws.ec2.predicates.SpotInstanceRequestActive; -import org.jclouds.compute.BaseVersionedServiceLiveTest; -import org.jclouds.compute.ComputeServiceContext; -import org.jclouds.compute.ComputeServiceContextFactory; +import org.jclouds.compute.internal.BaseComputeServiceContextLiveTest; import org.jclouds.ec2.domain.InstanceType; -import org.jclouds.logging.log4j.config.Log4JLoggingModule; import org.jclouds.predicates.RetryablePredicate; -import org.jclouds.sshj.config.SshjSshClientModule; import org.testng.annotations.AfterTest; -import org.testng.annotations.BeforeGroups; +import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSortedSet; -import com.google.inject.Module; /** * Tests behavior of {@code SpotInstanceClient} @@ -61,27 +55,23 @@ import com.google.inject.Module; * @author Adrian Cole */ @Test(groups = "live", singleThreaded = true) -public class SpotInstanceClientLiveTest extends BaseVersionedServiceLiveTest { +public class SpotInstanceClientLiveTest extends BaseComputeServiceContextLiveTest { public SpotInstanceClientLiveTest() { provider = "aws-ec2"; } private static final int SPOT_DELAY_SECONDS = 600; private AWSEC2Client client; - private ComputeServiceContext context; private RetryablePredicate activeTester; private Set requests; private AWSRunningInstance instance; private long start; - @BeforeGroups(groups = { "live" }) - public void setupClient() throws FileNotFoundException, IOException { - setupCredentials(); - Properties overrides = setupProperties(); - context = new ComputeServiceContextFactory().createContext(provider, ImmutableSet. of( - new Log4JLoggingModule(), new SshjSshClientModule()), overrides); - - client = AWSEC2Client.class.cast(context.getProviderSpecificContext().getApi()); + @Override + @BeforeClass(groups = { "integration", "live" }) + public void setupContext() { + super.setupContext(); + client = context.getProviderSpecificContext().getApi(); activeTester = new RetryablePredicate(new SpotInstanceRequestActive(client), SPOT_DELAY_SECONDS, 1, 1, TimeUnit.SECONDS); } @@ -181,6 +171,5 @@ public class SpotInstanceClientLiveTest extends BaseVersionedServiceLiveTest { if (instance != null) { client.getInstanceServices().terminateInstancesInRegion(instance.getRegion(), instance.getId()); } - context.close(); } } diff --git a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/services/TagClientLiveTest.java b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/services/TagClientLiveTest.java index 901b52d23f..3f554f7f34 100644 --- a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/services/TagClientLiveTest.java +++ b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/services/TagClientLiveTest.java @@ -22,31 +22,23 @@ import static com.google.common.collect.Iterables.getOnlyElement; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNotNull; -import java.util.Properties; import java.util.Set; import org.jclouds.aws.ec2.AWSEC2AsyncClient; import org.jclouds.aws.ec2.AWSEC2Client; +import org.jclouds.aws.ec2.compute.AWSEC2ComputeServiceContext; import org.jclouds.aws.ec2.domain.AWSRunningInstance; import org.jclouds.aws.ec2.domain.Tag; import org.jclouds.aws.ec2.util.TagFilters; import org.jclouds.aws.ec2.util.TagFilters.ResourceType; -import org.jclouds.compute.BaseVersionedServiceLiveTest; -import org.jclouds.compute.ComputeServiceContext; -import org.jclouds.compute.ComputeServiceContextFactory; -import org.jclouds.logging.log4j.config.Log4JLoggingModule; -import org.jclouds.rest.RestContext; -import org.jclouds.sshj.config.SshjSshClientModule; +import org.jclouds.compute.internal.BaseComputeServiceContextLiveTest; import org.testng.annotations.AfterGroups; -import org.testng.annotations.AfterTest; -import org.testng.annotations.BeforeGroups; +import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; -import com.google.inject.Module; /** * Tests live behavior of {@code TagClient} @@ -54,40 +46,34 @@ import com.google.inject.Module; * @author grkvlt@apache.org */ @Test(groups = "live", singleThreaded = true) -public class TagClientLiveTest extends BaseVersionedServiceLiveTest { +public class TagClientLiveTest extends BaseComputeServiceContextLiveTest { public TagClientLiveTest() { provider = "aws-ec2"; } private TagClient client; - private RestContext context; - protected String testGroup; - private ComputeServiceContext computeContext; - - @BeforeGroups(groups = { "live" }) - public void setupClientAndSecurityGroup() { - setupCredentials(); - Properties overrides = setupProperties(); - computeContext = new ComputeServiceContextFactory().createContext(provider, ImmutableSet. of( - new Log4JLoggingModule(), new SshjSshClientModule()), overrides); - context = computeContext.getProviderSpecificContext(); - client = context.getApi().getTagServices(); + @Override + @BeforeClass(groups = { "integration", "live" }) + public void setupContext() { + super.setupContext(); + client = context.getProviderSpecificContext().getApi().getTagServices(); + try { - testGroup = context.getApi().getSecurityGroupServices().createSecurityGroupInRegionAndReturnId(null, + testGroup = context.getProviderSpecificContext().getApi().getSecurityGroupServices().createSecurityGroupInRegionAndReturnId(null, "test-group", "test-group"); } catch (IllegalStateException e) { // already exists testGroup = Iterables.get( - context.getApi().getSecurityGroupServices().describeSecurityGroupsInRegion(null, "test-group"), 0) + context.getProviderSpecificContext().getApi().getSecurityGroupServices().describeSecurityGroupsInRegion(null, "test-group"), 0) .getId(); } } @AfterGroups(groups = { "live" }) public void deleteSecurityGroup() { - context.getApi().getSecurityGroupServices().deleteSecurityGroupInRegionById(null, testGroup); + context.getProviderSpecificContext().getApi().getSecurityGroupServices().deleteSecurityGroupInRegionById(null, testGroup); } public static final String PREFIX = System.getProperty("user.name") + "-ec2"; @@ -129,9 +115,4 @@ public class TagClientLiveTest extends BaseVersionedServiceLiveTest { protected AWSRunningInstance getInstance(AWSInstanceClient instanceClient, String id) { return getOnlyElement(getOnlyElement(instanceClient.describeInstancesInRegion(null, id))); } - - @AfterTest - public void shutdown() { - context.close(); - } } diff --git a/providers/aws-s3/src/main/java/org/jclouds/aws/s3/AWSS3ApiMetadata.java b/providers/aws-s3/src/main/java/org/jclouds/aws/s3/AWSS3ApiMetadata.java index 0b53e4bea9..708e2ef9cc 100644 --- a/providers/aws-s3/src/main/java/org/jclouds/aws/s3/AWSS3ApiMetadata.java +++ b/providers/aws-s3/src/main/java/org/jclouds/aws/s3/AWSS3ApiMetadata.java @@ -18,43 +18,62 @@ */ package org.jclouds.aws.s3; +import java.util.Properties; + import org.jclouds.apis.ApiMetadata; +import org.jclouds.aws.s3.blobstore.AWSS3BlobStoreContext; import org.jclouds.s3.S3ApiMetadata; +import com.google.common.reflect.TypeToken; + /** * Implementation of {@link ApiMetadata} for the Amazon-specific S3 API * * @author Adrian Cole */ -public class AWSS3ApiMetadata extends S3ApiMetadata { +public class AWSS3ApiMetadata extends S3ApiMetadata { + private static Builder builder() { + return new Builder(); + } + + @Override + public Builder toBuilder() { + return builder().fromApiMetadata(this); + } public AWSS3ApiMetadata() { - this(builder().fromApiMetadata(new S3ApiMetadata()) - .id("aws-s3") - .name("Amazon-specific S3 API")); + this(builder()); } - // below are so that we can reuse builders, toString, hashCode, etc. - // we have to set concrete classes here, as our base class cannot be - // concrete due to serviceLoader - protected AWSS3ApiMetadata(ConcreteBuilder builder) { + protected AWSS3ApiMetadata(Builder builder) { super(builder); } + + protected static Properties defaultProperties() { + Properties properties = S3ApiMetadata.defaultProperties(); + return properties; + } - private static class ConcreteBuilder extends S3ApiMetadataBuilder { - + public static class Builder extends S3ApiMetadata.Builder { + protected Builder(){ + super(AWSS3Client.class, AWSS3AsyncClient.class); + id("aws-s3") + .name("Amazon-specific S3 API") + .defaultProperties(AWSS3ApiMetadata.defaultProperties()) + .context(TypeToken.of(AWSS3BlobStoreContext.class)) + .contextBuilder(TypeToken.of(AWSS3ContextBuilder.class)); + } + @Override public AWSS3ApiMetadata build() { return new AWSS3ApiMetadata(this); } + + @Override + public Builder fromApiMetadata(AWSS3ApiMetadata in) { + super.fromApiMetadata(in); + return this; + } } - private static ConcreteBuilder builder() { - return new ConcreteBuilder(); - } - - @Override - public ConcreteBuilder toBuilder() { - return builder().fromApiMetadata(this); - } } \ No newline at end of file diff --git a/providers/aws-s3/src/main/java/org/jclouds/aws/s3/AWSS3ContextBuilder.java b/providers/aws-s3/src/main/java/org/jclouds/aws/s3/AWSS3ContextBuilder.java index 435933bb18..a2065d0c8c 100644 --- a/providers/aws-s3/src/main/java/org/jclouds/aws/s3/AWSS3ContextBuilder.java +++ b/providers/aws-s3/src/main/java/org/jclouds/aws/s3/AWSS3ContextBuilder.java @@ -19,10 +19,11 @@ package org.jclouds.aws.s3; import java.util.List; -import java.util.Properties; +import org.jclouds.aws.s3.blobstore.AWSS3BlobStoreContext; import org.jclouds.aws.s3.blobstore.config.AWSS3BlobStoreContextModule; import org.jclouds.aws.s3.config.AWSS3RestClientModule; +import org.jclouds.providers.ProviderMetadata; import org.jclouds.s3.S3ContextBuilder; import com.google.inject.Module; @@ -31,10 +32,19 @@ import com.google.inject.Module; * * @author Adrian Cole */ -public class AWSS3ContextBuilder extends S3ContextBuilder { +public class AWSS3ContextBuilder extends + S3ContextBuilder { + public AWSS3ContextBuilder() { + this(new AWSS3ProviderMetadata()); + } - public AWSS3ContextBuilder(Properties props) { - super(props); + public AWSS3ContextBuilder( + ProviderMetadata providerMetadata) { + super(providerMetadata); + } + + public AWSS3ContextBuilder(AWSS3ApiMetadata apiMetadata) { + super(apiMetadata); } @Override diff --git a/providers/aws-s3/src/main/java/org/jclouds/aws/s3/AWSS3PropertiesBuilder.java b/providers/aws-s3/src/main/java/org/jclouds/aws/s3/AWSS3PropertiesBuilder.java deleted file mode 100644 index 37f07d74d6..0000000000 --- a/providers/aws-s3/src/main/java/org/jclouds/aws/s3/AWSS3PropertiesBuilder.java +++ /dev/null @@ -1,67 +0,0 @@ -/** - * 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.aws.s3; - -import static org.jclouds.Constants.PROPERTY_ENDPOINT; -import static org.jclouds.aws.domain.Region.AP_NORTHEAST_1; -import static org.jclouds.aws.domain.Region.AP_SOUTHEAST_1; -import static org.jclouds.aws.domain.Region.SA_EAST_1; -import static org.jclouds.aws.domain.Region.US_STANDARD; -import static org.jclouds.aws.domain.Region.US_WEST_1; -import static org.jclouds.aws.domain.Region.US_WEST_2; -import static org.jclouds.location.reference.LocationConstants.ENDPOINT; -import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGION; - -import java.util.Properties; - -import org.jclouds.aws.domain.Region; - -/** - * Builds properties used in S3 Clients - * - * @author Adrian Cole - */ -public class AWSS3PropertiesBuilder extends org.jclouds.s3.S3PropertiesBuilder { - - @Override - protected Properties defaultProperties() { - Properties properties = super.defaultProperties(); - properties.putAll(Region.regionPropertiesS3()); - properties.setProperty(PROPERTY_ENDPOINT, "https://s3.amazonaws.com"); - properties.setProperty(PROPERTY_REGION + "." + US_STANDARD + "." + ENDPOINT, "https://s3.amazonaws.com"); - properties.setProperty(PROPERTY_REGION + "." + US_WEST_1 + "." + ENDPOINT, "https://s3-us-west-1.amazonaws.com"); - properties.setProperty(PROPERTY_REGION + "." + US_WEST_2 + "." + ENDPOINT, "https://s3-us-west-2.amazonaws.com"); - properties.setProperty(PROPERTY_REGION + "." + SA_EAST_1 + "." + ENDPOINT, "https://s3-sa-east-1.amazonaws.com"); - properties.setProperty(PROPERTY_REGION + "." + "EU" + "." + ENDPOINT, "https://s3-eu-west-1.amazonaws.com"); - properties.setProperty(PROPERTY_REGION + "." + AP_SOUTHEAST_1 + "." + ENDPOINT, - "https://s3-ap-southeast-1.amazonaws.com"); - properties.setProperty(PROPERTY_REGION + "." + AP_NORTHEAST_1 + "." + ENDPOINT, - "https://s3-ap-northeast-1.amazonaws.com"); - return properties; - } - - public AWSS3PropertiesBuilder() { - super(); - } - - public AWSS3PropertiesBuilder(Properties properties) { - super(properties); - } - -} diff --git a/providers/aws-s3/src/main/java/org/jclouds/aws/s3/AWSS3ProviderMetadata.java b/providers/aws-s3/src/main/java/org/jclouds/aws/s3/AWSS3ProviderMetadata.java index a6b758bd36..7dafc9d487 100644 --- a/providers/aws-s3/src/main/java/org/jclouds/aws/s3/AWSS3ProviderMetadata.java +++ b/providers/aws-s3/src/main/java/org/jclouds/aws/s3/AWSS3ProviderMetadata.java @@ -18,9 +18,23 @@ */ package org.jclouds.aws.s3; -import java.net.URI; +import static org.jclouds.Constants.PROPERTY_ENDPOINT; +import static org.jclouds.aws.domain.Region.AP_NORTHEAST_1; +import static org.jclouds.aws.domain.Region.AP_SOUTHEAST_1; +import static org.jclouds.aws.domain.Region.SA_EAST_1; +import static org.jclouds.aws.domain.Region.US_STANDARD; +import static org.jclouds.aws.domain.Region.US_WEST_1; +import static org.jclouds.aws.domain.Region.US_WEST_2; +import static org.jclouds.location.reference.LocationConstants.ENDPOINT; +import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGION; -import org.jclouds.providers.BaseProviderMetadata; +import java.net.URI; +import java.util.Properties; + +import org.jclouds.aws.domain.Region; +import org.jclouds.aws.s3.blobstore.AWSS3BlobStoreContext; +import org.jclouds.providers.ProviderMetadata; +import org.jclouds.providers.internal.BaseProviderMetadata; /** * Implementation of {@link org.jclouds.providers.ProviderMetadata} for Amazon's Simple Storage Service @@ -28,40 +42,64 @@ import org.jclouds.providers.BaseProviderMetadata; * * @author Adrian Cole */ -public class AWSS3ProviderMetadata extends BaseProviderMetadata { - - public AWSS3ProviderMetadata() { - this(builder() - .id("aws-s3") - .name("Amazon Simple Storage Service (S3)") - .api(new AWSS3ApiMetadata()) - .homepage(URI.create("http://aws.amazon.com/s3")) - .console(URI.create("https://console.aws.amazon.com/s3/home")) - .linkedServices("aws-ec2","aws-elb", "aws-cloudwatch", "aws-s3", "aws-simpledb") - .iso3166Codes("US", "US-CA", "US-OR", "BR-SP", "IE", "SG", "JP-13")); +public class AWSS3ProviderMetadata extends BaseProviderMetadata { + + public static Builder builder() { + return new Builder(); } - // below are so that we can reuse builders, toString, hashCode, etc. - // we have to set concrete classes here, as our base class cannot be - // concrete due to serviceLoader - protected AWSS3ProviderMetadata(ConcreteBuilder builder) { + @Override + public Builder toBuilder() { + return builder().fromProviderMetadata(this); + } + + public AWSS3ProviderMetadata() { + super(builder()); + } + + public AWSS3ProviderMetadata(Builder builder) { super(builder); } - private static class ConcreteBuilder extends Builder { + protected static Properties defaultProperties() { + Properties properties = new Properties(); + properties.putAll(Region.regionPropertiesS3()); + properties.setProperty(PROPERTY_ENDPOINT, "https://s3.amazonaws.com"); + properties.setProperty(PROPERTY_REGION + "." + US_STANDARD + "." + ENDPOINT, "https://s3.amazonaws.com"); + properties.setProperty(PROPERTY_REGION + "." + US_WEST_1 + "." + ENDPOINT, "https://s3-us-west-1.amazonaws.com"); + properties.setProperty(PROPERTY_REGION + "." + US_WEST_2 + "." + ENDPOINT, "https://s3-us-west-2.amazonaws.com"); + properties.setProperty(PROPERTY_REGION + "." + SA_EAST_1 + "." + ENDPOINT, "https://s3-sa-east-1.amazonaws.com"); + properties.setProperty(PROPERTY_REGION + "." + "EU" + "." + ENDPOINT, "https://s3-eu-west-1.amazonaws.com"); + properties.setProperty(PROPERTY_REGION + "." + AP_SOUTHEAST_1 + "." + ENDPOINT, + "https://s3-ap-southeast-1.amazonaws.com"); + properties.setProperty(PROPERTY_REGION + "." + AP_NORTHEAST_1 + "." + ENDPOINT, + "https://s3-ap-northeast-1.amazonaws.com"); + return properties; + } + + public static class Builder extends BaseProviderMetadata.Builder { + + protected Builder(){ + id("aws-s3") + .name("Amazon Simple Storage Service (S3)") + .apiMetadata(new AWSS3ApiMetadata()) + .homepage(URI.create("http://aws.amazon.com/s3")) + .console(URI.create("https://console.aws.amazon.com/s3/home")) + .linkedServices("aws-ec2","aws-elb", "aws-cloudwatch", "aws-s3", "aws-simpledb") + .iso3166Codes("US", "US-CA", "US-OR", "BR-SP", "IE", "SG", "JP-13") + .defaultProperties(AWSS3ProviderMetadata.defaultProperties()); + } @Override public AWSS3ProviderMetadata build() { return new AWSS3ProviderMetadata(this); } + + @Override + public Builder fromProviderMetadata( + ProviderMetadata in) { + super.fromProviderMetadata(in); + return this; + } } - - public static ConcreteBuilder builder() { - return new ConcreteBuilder(); - } - - public ConcreteBuilder toBuilder() { - return builder().fromProviderMetadata(this); - } - } \ No newline at end of file diff --git a/providers/aws-s3/src/main/java/org/jclouds/aws/s3/blobstore/AWSS3AsyncBlobStore.java b/providers/aws-s3/src/main/java/org/jclouds/aws/s3/blobstore/AWSS3AsyncBlobStore.java index bc5e5b15f6..7f8476d7c8 100644 --- a/providers/aws-s3/src/main/java/org/jclouds/aws/s3/blobstore/AWSS3AsyncBlobStore.java +++ b/providers/aws-s3/src/main/java/org/jclouds/aws/s3/blobstore/AWSS3AsyncBlobStore.java @@ -69,7 +69,7 @@ public class AWSS3AsyncBlobStore extends S3AsyncBlobStore { private final BlobToObject blob2Object; @Inject - public AWSS3AsyncBlobStore(BlobStoreContext context, BlobUtils blobUtils, + public AWSS3AsyncBlobStore(@SuppressWarnings("rawtypes") BlobStoreContext context, BlobUtils blobUtils, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService service, Supplier defaultLocation, @Memoized Supplier> locations, AWSS3AsyncClient async, AWSS3Client sync, BucketToResourceMetadata bucket2ResourceMd, ContainerToBucketListOptions container2BucketListOptions, diff --git a/providers/aws-s3/src/main/java/org/jclouds/aws/s3/blobstore/AWSS3BlobStore.java b/providers/aws-s3/src/main/java/org/jclouds/aws/s3/blobstore/AWSS3BlobStore.java index ba641fcc04..8fc842687d 100644 --- a/providers/aws-s3/src/main/java/org/jclouds/aws/s3/blobstore/AWSS3BlobStore.java +++ b/providers/aws-s3/src/main/java/org/jclouds/aws/s3/blobstore/AWSS3BlobStore.java @@ -65,7 +65,7 @@ public class AWSS3BlobStore extends S3BlobStore { private final BlobToObject blob2Object; @Inject - AWSS3BlobStore(BlobStoreContext context, BlobUtils blobUtils, Supplier defaultLocation, + AWSS3BlobStore(@SuppressWarnings("rawtypes") BlobStoreContext context, BlobUtils blobUtils, Supplier defaultLocation, @Memoized Supplier> locations, AWSS3Client sync, BucketToResourceMetadata bucket2ResourceMd, ContainerToBucketListOptions container2BucketListOptions, BucketToResourceList bucket2ResourceList, ObjectToBlob object2Blob, diff --git a/apis/cloudfiles/src/test/java/org/jclouds/cloudfiles/blobstore/integration/CloudFilesTestInitializer.java b/providers/aws-s3/src/main/java/org/jclouds/aws/s3/blobstore/AWSS3BlobStoreContext.java similarity index 60% rename from apis/cloudfiles/src/test/java/org/jclouds/cloudfiles/blobstore/integration/CloudFilesTestInitializer.java rename to providers/aws-s3/src/main/java/org/jclouds/aws/s3/blobstore/AWSS3BlobStoreContext.java index 2de913c0d2..a95e175ab0 100644 --- a/apis/cloudfiles/src/test/java/org/jclouds/cloudfiles/blobstore/integration/CloudFilesTestInitializer.java +++ b/providers/aws-s3/src/main/java/org/jclouds/aws/s3/blobstore/AWSS3BlobStoreContext.java @@ -16,19 +16,24 @@ * specific language governing permissions and limitations * under the License. */ -package org.jclouds.cloudfiles.blobstore.integration; +package org.jclouds.aws.s3.blobstore; -import org.jclouds.openstack.swift.blobstore.integration.SwiftTestInitializer; +import org.jclouds.aws.s3.AWSS3AsyncClient; +import org.jclouds.aws.s3.AWSS3Client; +import org.jclouds.aws.s3.blobstore.internal.AWSS3BlobStoreContextImpl; +import org.jclouds.s3.blobstore.S3BlobStoreContext; + +import com.google.inject.ImplementedBy; /** - * * @author Adrian Cole */ -public class CloudFilesTestInitializer extends SwiftTestInitializer { - - public CloudFilesTestInitializer() { - provider = "cloudfiles"; - } +@ImplementedBy(AWSS3BlobStoreContextImpl.class) +public interface AWSS3BlobStoreContext extends S3BlobStoreContext { + @Override + AWSS3BlobStore getBlobStore(); + @Override + AWSS3AsyncBlobStore getAsyncBlobStore(); } diff --git a/providers/aws-s3/src/main/java/org/jclouds/aws/s3/blobstore/internal/AWSS3BlobStoreContextImpl.java b/providers/aws-s3/src/main/java/org/jclouds/aws/s3/blobstore/internal/AWSS3BlobStoreContextImpl.java new file mode 100644 index 0000000000..640f7431d1 --- /dev/null +++ b/providers/aws-s3/src/main/java/org/jclouds/aws/s3/blobstore/internal/AWSS3BlobStoreContextImpl.java @@ -0,0 +1,62 @@ +/** + * 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.aws.s3.blobstore.internal; + +import javax.inject.Inject; +import javax.inject.Singleton; + +import org.jclouds.aws.s3.AWSS3AsyncClient; +import org.jclouds.aws.s3.AWSS3Client; +import org.jclouds.aws.s3.blobstore.AWSS3AsyncBlobStore; +import org.jclouds.aws.s3.blobstore.AWSS3BlobStore; +import org.jclouds.aws.s3.blobstore.AWSS3BlobStoreContext; +import org.jclouds.blobstore.BlobMap; +import org.jclouds.blobstore.BlobRequestSigner; +import org.jclouds.blobstore.InputStreamMap; +import org.jclouds.blobstore.attr.ConsistencyModel; +import org.jclouds.rest.RestContext; +import org.jclouds.rest.Utils; +import org.jclouds.s3.blobstore.internal.S3BlobStoreContextImpl; + +/** + * @author Adrian Cole + */ +@Singleton +public class AWSS3BlobStoreContextImpl extends S3BlobStoreContextImpl implements + AWSS3BlobStoreContext { + + @Inject + public AWSS3BlobStoreContextImpl(BlobMap.Factory blobMapFactory, Utils utils, ConsistencyModel consistencyModel, + InputStreamMap.Factory inputStreamMapFactory, AWSS3AsyncBlobStore ablobStore, AWSS3BlobStore blobStore, + @SuppressWarnings("rawtypes") RestContext providerSpecificContext, BlobRequestSigner blobRequestSigner) { + super(blobMapFactory, utils, consistencyModel, inputStreamMapFactory, ablobStore, blobStore, providerSpecificContext, + blobRequestSigner); + } + + @Override + public AWSS3BlobStore getBlobStore() { + return AWSS3BlobStore.class.cast(super.getBlobStore()); + } + + @Override + public AWSS3AsyncBlobStore getAsyncBlobStore() { + return AWSS3AsyncBlobStore.class.cast(super.getAsyncBlobStore()); + } + +} diff --git a/providers/aws-s3/src/main/java/org/jclouds/aws/s3/config/AWSS3RestClientModule.java b/providers/aws-s3/src/main/java/org/jclouds/aws/s3/config/AWSS3RestClientModule.java index a56a0f2c6f..f003e5c57d 100644 --- a/providers/aws-s3/src/main/java/org/jclouds/aws/s3/config/AWSS3RestClientModule.java +++ b/providers/aws-s3/src/main/java/org/jclouds/aws/s3/config/AWSS3RestClientModule.java @@ -90,11 +90,10 @@ public class AWSS3RestClientModule extends S3RestClientModule */ - @SuppressWarnings("unchecked") + @SuppressWarnings({ "unchecked", "rawtypes" }) @Singleton @Provides - RestContext - provideBaseContext(RestContext in) { + RestContext provideBaseContext(RestContext in) { return (RestContext) in; } 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 da375f3532..70020caa99 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 @@ -21,7 +21,6 @@ package org.jclouds.aws.s3; import java.io.IOException; import java.lang.reflect.Method; import java.util.Map; -import java.util.Properties; import java.util.concurrent.ConcurrentMap; import org.jclouds.aws.s3.config.AWSS3RestClientModule; @@ -38,8 +37,6 @@ import org.jclouds.http.functions.ReturnTrueIf2xx; import org.jclouds.io.Payload; import org.jclouds.io.Payloads; import org.jclouds.rest.ConfiguresRestClient; -import org.jclouds.rest.RestContextFactory; -import org.jclouds.rest.RestContextSpec; import org.jclouds.rest.functions.MapHttp4xxCodesToExceptions; import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404; import org.jclouds.rest.internal.RestAnnotationProcessor; @@ -66,10 +63,6 @@ import com.google.inject.TypeLiteral; @Test(groups = "unit", testName = "AWSS3AsyncClientTest") public class AWSS3AsyncClientTest extends org.jclouds.s3.S3AsyncClientTest { - public AWSS3AsyncClientTest() { - this.provider = "aws-s3"; - } - public void testGetBucketLocationEU() throws SecurityException, NoSuchMethodException, IOException { Method method = AWSS3AsyncClient.class.getMethod("getBucketLocation", String.class); HttpRequest request = processor.createRequest(method, "eubucket"); @@ -282,10 +275,9 @@ public class AWSS3AsyncClientTest extends org.jclouds.s3.S3AsyncClientTest createContextSpec() { - Properties props = new Properties(); - return new RestContextFactory().createContextSpec(provider, "identity", "credential", props); + public AWSS3ProviderMetadata createProviderMetadata() { + return new AWSS3ProviderMetadata(); } } diff --git a/providers/aws-s3/src/test/java/org/jclouds/aws/s3/AWSS3ClientExpectTest.java b/providers/aws-s3/src/test/java/org/jclouds/aws/s3/AWSS3ClientExpectTest.java index 746c3d0ac8..020ba759ff 100644 --- a/providers/aws-s3/src/test/java/org/jclouds/aws/s3/AWSS3ClientExpectTest.java +++ b/providers/aws-s3/src/test/java/org/jclouds/aws/s3/AWSS3ClientExpectTest.java @@ -24,6 +24,7 @@ import java.net.URI; import org.jclouds.aws.s3.internal.BaseAWSS3ClientExpectTest; import org.jclouds.blobstore.domain.Blob; +import org.jclouds.blobstore.domain.BlobBuilder; import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpResponse; import org.jclouds.io.payloads.StringPayload; @@ -31,7 +32,10 @@ import org.jclouds.s3.blobstore.functions.BlobToObject; import org.jclouds.s3.domain.ObjectMetadata.StorageClass; import org.testng.annotations.Test; +import com.google.common.base.Functions; +import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMultimap; +import com.google.inject.Injector; /** * @author Andrei Savu @@ -41,6 +45,11 @@ public class AWSS3ClientExpectTest extends BaseAWSS3ClientExpectTest { @Test public void testPutWithReducedRedundancy() { + Injector injector = createInjector(Functions.forMap(ImmutableMap.of()), createModule(), setupProperties()); + + Blob blob = injector.getInstance(BlobBuilder.class).name("test").payload("content").build(); + BlobToObject blobToObject = injector.getInstance(BlobToObject.class); + AWSS3Client client = requestSendsResponse( HttpRequest.builder() .method("PUT") @@ -65,14 +74,7 @@ public class AWSS3ClientExpectTest extends BaseAWSS3ClientExpectTest { .build() ); - Blob blob = blobStore.blobBuilder("test").payload("content").build(); - BlobToObject blobToObject = getInstance(BlobToObject.class); - client.putObject("test", blobToObject.apply(blob), storageClass(StorageClass.REDUCED_REDUNDANCY)); } - - public T getInstance(Class klass) { - return blobStoreContext.utils().injector().getInstance(klass); - } } diff --git a/providers/aws-s3/src/test/java/org/jclouds/aws/s3/AWSS3ClientLiveTest.java b/providers/aws-s3/src/test/java/org/jclouds/aws/s3/AWSS3ClientLiveTest.java index 6769524ae9..61ca9cb57b 100644 --- a/providers/aws-s3/src/test/java/org/jclouds/aws/s3/AWSS3ClientLiveTest.java +++ b/providers/aws-s3/src/test/java/org/jclouds/aws/s3/AWSS3ClientLiveTest.java @@ -60,8 +60,11 @@ import com.google.common.io.InputSupplier; * * @author Adrian Cole */ -@Test(groups = "live", sequential = true, testName = "AWSS3ClientLiveTest") +@Test(groups = "live", singleThreaded = true, testName = "AWSS3ClientLiveTest") public class AWSS3ClientLiveTest extends S3ClientLiveTest { + public AWSS3ClientLiveTest() { + provider = "aws-s3"; + } private InputSupplier oneHundredOneConstitutions; private byte[] oneHundredOneConstitutionsMD5; private static long oneHundredOneConstitutionsLength; diff --git a/providers/aws-s3/src/test/java/org/jclouds/aws/s3/AWSS3ProviderTest.java b/providers/aws-s3/src/test/java/org/jclouds/aws/s3/AWSS3ProviderTest.java index a4fb7bf309..e34f58f74a 100644 --- a/providers/aws-s3/src/test/java/org/jclouds/aws/s3/AWSS3ProviderTest.java +++ b/providers/aws-s3/src/test/java/org/jclouds/aws/s3/AWSS3ProviderTest.java @@ -18,7 +18,7 @@ */ package org.jclouds.aws.s3; -import org.jclouds.providers.BaseProviderMetadataTest; +import org.jclouds.providers.internal.BaseProviderMetadataTest; import org.testng.annotations.Test; /** diff --git a/providers/aws-s3/src/test/java/org/jclouds/aws/s3/blobstore/integration/AWSS3BlobIntegrationLiveTest.java b/providers/aws-s3/src/test/java/org/jclouds/aws/s3/blobstore/integration/AWSS3BlobIntegrationLiveTest.java index 5de31901a5..73b1e042fd 100644 --- a/providers/aws-s3/src/test/java/org/jclouds/aws/s3/blobstore/integration/AWSS3BlobIntegrationLiveTest.java +++ b/providers/aws-s3/src/test/java/org/jclouds/aws/s3/blobstore/integration/AWSS3BlobIntegrationLiveTest.java @@ -26,5 +26,7 @@ import org.testng.annotations.Test; */ @Test(groups = "live", testName = "AWSS3BlobIntegrationLiveTest") public class AWSS3BlobIntegrationLiveTest extends S3BlobIntegrationLiveTest { - + public AWSS3BlobIntegrationLiveTest() { + provider = "aws-s3"; + } } diff --git a/providers/aws-s3/src/test/java/org/jclouds/aws/s3/blobstore/integration/AWSS3BlobLiveTest.java b/providers/aws-s3/src/test/java/org/jclouds/aws/s3/blobstore/integration/AWSS3BlobLiveTest.java index d38a2d6744..806eba2a7b 100644 --- a/providers/aws-s3/src/test/java/org/jclouds/aws/s3/blobstore/integration/AWSS3BlobLiveTest.java +++ b/providers/aws-s3/src/test/java/org/jclouds/aws/s3/blobstore/integration/AWSS3BlobLiveTest.java @@ -26,5 +26,7 @@ import org.testng.annotations.Test; */ @Test(groups = "live", testName = "AWSS3BlobLiveTest") public class AWSS3BlobLiveTest extends S3BlobLiveTest { - + public AWSS3BlobLiveTest() { + provider = "aws-s3"; + } } diff --git a/providers/aws-s3/src/test/java/org/jclouds/aws/s3/blobstore/integration/AWSS3BlobMapIntegrationLiveTest.java b/providers/aws-s3/src/test/java/org/jclouds/aws/s3/blobstore/integration/AWSS3BlobMapIntegrationLiveTest.java index 2aa3f41440..42a9a34384 100644 --- a/providers/aws-s3/src/test/java/org/jclouds/aws/s3/blobstore/integration/AWSS3BlobMapIntegrationLiveTest.java +++ b/providers/aws-s3/src/test/java/org/jclouds/aws/s3/blobstore/integration/AWSS3BlobMapIntegrationLiveTest.java @@ -26,5 +26,7 @@ import org.testng.annotations.Test; */ @Test(groups = "live", testName = "AWSS3BlobMapIntegrationLiveTest") public class AWSS3BlobMapIntegrationLiveTest extends S3BlobMapIntegrationLiveTest { - + public AWSS3BlobMapIntegrationLiveTest() { + provider = "aws-s3"; + } } diff --git a/providers/aws-s3/src/test/java/org/jclouds/aws/s3/blobstore/integration/AWSS3BlobSignerLiveTest.java b/providers/aws-s3/src/test/java/org/jclouds/aws/s3/blobstore/integration/AWSS3BlobSignerLiveTest.java index c18e7f7046..2ef6e68634 100644 --- a/providers/aws-s3/src/test/java/org/jclouds/aws/s3/blobstore/integration/AWSS3BlobSignerLiveTest.java +++ b/providers/aws-s3/src/test/java/org/jclouds/aws/s3/blobstore/integration/AWSS3BlobSignerLiveTest.java @@ -27,5 +27,7 @@ import org.testng.annotations.Test; */ @Test(groups = "live", testName = "AWSS3BlobSignerLiveTest") public class AWSS3BlobSignerLiveTest extends S3BlobSignerLiveTest { - + public AWSS3BlobSignerLiveTest() { + provider = "aws-s3"; + } } diff --git a/providers/aws-s3/src/test/java/org/jclouds/aws/s3/blobstore/integration/AWSS3ContainerIntegrationLiveTest.java b/providers/aws-s3/src/test/java/org/jclouds/aws/s3/blobstore/integration/AWSS3ContainerIntegrationLiveTest.java index fce28d2d48..04d94b5e67 100644 --- a/providers/aws-s3/src/test/java/org/jclouds/aws/s3/blobstore/integration/AWSS3ContainerIntegrationLiveTest.java +++ b/providers/aws-s3/src/test/java/org/jclouds/aws/s3/blobstore/integration/AWSS3ContainerIntegrationLiveTest.java @@ -26,5 +26,7 @@ import org.testng.annotations.Test; */ @Test(groups = "live", testName = "AWSS3ContainerIntegrationLiveTest") public class AWSS3ContainerIntegrationLiveTest extends S3ContainerIntegrationLiveTest { - + public AWSS3ContainerIntegrationLiveTest() { + provider = "aws-s3"; + } } diff --git a/providers/aws-s3/src/test/java/org/jclouds/aws/s3/blobstore/integration/AWSS3ContainerLiveTest.java b/providers/aws-s3/src/test/java/org/jclouds/aws/s3/blobstore/integration/AWSS3ContainerLiveTest.java index 799c21721e..27b952bd65 100644 --- a/providers/aws-s3/src/test/java/org/jclouds/aws/s3/blobstore/integration/AWSS3ContainerLiveTest.java +++ b/providers/aws-s3/src/test/java/org/jclouds/aws/s3/blobstore/integration/AWSS3ContainerLiveTest.java @@ -26,5 +26,7 @@ import org.testng.annotations.Test; */ @Test(groups = "live", testName = "AWSS3ContainerLiveTest") public class AWSS3ContainerLiveTest extends S3ContainerLiveTest { - + public AWSS3ContainerLiveTest() { + provider = "aws-s3"; + } } diff --git a/providers/aws-s3/src/test/java/org/jclouds/aws/s3/blobstore/integration/AWSS3InputStreamMapIntegrationLiveTest.java b/providers/aws-s3/src/test/java/org/jclouds/aws/s3/blobstore/integration/AWSS3InputStreamMapIntegrationLiveTest.java index 9a07c4de7e..8b83a0d6a7 100644 --- a/providers/aws-s3/src/test/java/org/jclouds/aws/s3/blobstore/integration/AWSS3InputStreamMapIntegrationLiveTest.java +++ b/providers/aws-s3/src/test/java/org/jclouds/aws/s3/blobstore/integration/AWSS3InputStreamMapIntegrationLiveTest.java @@ -26,5 +26,7 @@ import org.testng.annotations.Test; */ @Test(groups = "live", testName = "AWSS3InputStreamMapIntegrationLiveTest") public class AWSS3InputStreamMapIntegrationLiveTest extends S3InputStreamMapIntegrationLiveTest { - + public AWSS3InputStreamMapIntegrationLiveTest() { + provider = "aws-s3"; + } } diff --git a/providers/aws-s3/src/test/java/org/jclouds/aws/s3/blobstore/integration/AWSS3ServiceIntegrationLiveTest.java b/providers/aws-s3/src/test/java/org/jclouds/aws/s3/blobstore/integration/AWSS3ServiceIntegrationLiveTest.java index 9736063dd3..caadb04705 100644 --- a/providers/aws-s3/src/test/java/org/jclouds/aws/s3/blobstore/integration/AWSS3ServiceIntegrationLiveTest.java +++ b/providers/aws-s3/src/test/java/org/jclouds/aws/s3/blobstore/integration/AWSS3ServiceIntegrationLiveTest.java @@ -30,6 +30,10 @@ import com.google.common.collect.ImmutableSet; */ @Test(groups = "live", testName = "AWSS3ServiceIntegrationLiveTest") public class AWSS3ServiceIntegrationLiveTest extends S3ServiceIntegrationLiveTest { + public AWSS3ServiceIntegrationLiveTest() { + provider = "aws-s3"; + } + @Override protected Set getIso3166Codes() { return ImmutableSet. of("US", "US-CA", "US-OR", "BR-SP", "IE", "SG", "JP-13"); diff --git a/providers/aws-s3/src/test/java/org/jclouds/aws/s3/blobstore/integration/AWSS3TestInitializer.java b/providers/aws-s3/src/test/java/org/jclouds/aws/s3/blobstore/integration/AWSS3TestInitializer.java deleted file mode 100644 index 5ba408bd22..0000000000 --- a/providers/aws-s3/src/test/java/org/jclouds/aws/s3/blobstore/integration/AWSS3TestInitializer.java +++ /dev/null @@ -1,52 +0,0 @@ -/** - * 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.aws.s3.blobstore.integration; - -import java.io.IOException; - -import org.jclouds.blobstore.BlobStoreContext; -import org.jclouds.blobstore.BlobStoreContextFactory; -import org.jclouds.blobstore.integration.TransientBlobStoreTestInitializer; -import org.jclouds.blobstore.integration.internal.BaseBlobStoreIntegrationTest; -import org.jclouds.enterprise.config.EnterpriseConfigurationModule; -import org.jclouds.logging.log4j.config.Log4JLoggingModule; - -import com.google.common.collect.ImmutableSet; -import com.google.inject.Module; - -/** - * - * @author Adrian Cole - */ -public class AWSS3TestInitializer extends TransientBlobStoreTestInitializer { - - public AWSS3TestInitializer() { - provider = "aws-s3"; - BaseBlobStoreIntegrationTest.SANITY_CHECK_RETURNED_BUCKET_NAME = true; - } - - @Override - protected BlobStoreContext createLiveContext(Module configurationModule, String endpoint, String apiVersion, - String buildVersion, String app, String identity, String credential) throws IOException { - return new BlobStoreContextFactory().createContext(provider, ImmutableSet.of(configurationModule, - new Log4JLoggingModule(), new EnterpriseConfigurationModule()), setupProperties(endpoint, apiVersion, - buildVersion, identity, credential)); - } - -} diff --git a/providers/aws-s3/src/test/java/org/jclouds/aws/s3/blobstore/strategy/internal/SequentialMultipartUploadStrategyTest.java b/providers/aws-s3/src/test/java/org/jclouds/aws/s3/blobstore/strategy/internal/SequentialMultipartUploadStrategyTest.java index 2ef31b4819..deeea20e38 100644 --- a/providers/aws-s3/src/test/java/org/jclouds/aws/s3/blobstore/strategy/internal/SequentialMultipartUploadStrategyTest.java +++ b/providers/aws-s3/src/test/java/org/jclouds/aws/s3/blobstore/strategy/internal/SequentialMultipartUploadStrategyTest.java @@ -54,6 +54,7 @@ import com.google.common.collect.Maps; @Test(groups = "unit") public class SequentialMultipartUploadStrategyTest { + @SuppressWarnings("unchecked") @Test public void testWithTwoParts() { AWSS3BlobStore ablobStore = createMock(AWSS3BlobStore.class); @@ -64,8 +65,8 @@ public class SequentialMultipartUploadStrategyTest { MutableBlobMetadata blobMeta = createMock(MutableBlobMetadata.class); Payload payload = createMock(Payload.class); MutableContentMetadata contentMeta = createMock(MutableContentMetadata.class); + @SuppressWarnings("rawtypes") BlobStoreContext context = createMock(BlobStoreContext.class); - @SuppressWarnings("unchecked") RestContext psc = createMock(RestContextImpl.class); AWSS3Client client = createMock(AWSS3Client.class); ObjectMetadata ometa = createMock(ObjectMetadata.class); @@ -117,6 +118,7 @@ public class SequentialMultipartUploadStrategyTest { verify(ometa); } + @SuppressWarnings("unchecked") @Test public void testWithTimeout() { AWSS3BlobStore ablobStore = createMock(AWSS3BlobStore.class); @@ -127,8 +129,8 @@ public class SequentialMultipartUploadStrategyTest { MutableBlobMetadata blobMeta = createMock(MutableBlobMetadata.class); Payload payload = createMock(Payload.class); MutableContentMetadata contentMeta = createMock(MutableContentMetadata.class); + @SuppressWarnings("rawtypes") BlobStoreContext context = createMock(BlobStoreContext.class); - @SuppressWarnings("unchecked") RestContext psc = createMock(RestContextImpl.class); AWSS3Client client = createMock(AWSS3Client.class); ObjectMetadata ometa = createMock(ObjectMetadata.class); diff --git a/providers/aws-s3/src/test/java/org/jclouds/aws/s3/internal/BaseAWSS3ClientExpectTest.java b/providers/aws-s3/src/test/java/org/jclouds/aws/s3/internal/BaseAWSS3ClientExpectTest.java index c049a12d77..671c1712b8 100644 --- a/providers/aws-s3/src/test/java/org/jclouds/aws/s3/internal/BaseAWSS3ClientExpectTest.java +++ b/providers/aws-s3/src/test/java/org/jclouds/aws/s3/internal/BaseAWSS3ClientExpectTest.java @@ -18,24 +18,16 @@ */ package org.jclouds.aws.s3.internal; -import java.util.Properties; - import org.jclouds.aws.s3.AWSS3Client; +import org.jclouds.aws.s3.AWSS3ProviderMetadata; import org.jclouds.aws.s3.config.AWSS3RestClientModule; -import org.jclouds.blobstore.BlobStore; -import org.jclouds.blobstore.BlobStoreContext; -import org.jclouds.blobstore.BlobStoreContextFactory; import org.jclouds.date.TimeStamp; -import org.jclouds.http.HttpRequest; -import org.jclouds.http.HttpResponse; import org.jclouds.http.RequiresHttp; -import org.jclouds.logging.config.NullLoggingModule; -import org.jclouds.rest.BaseRestClientExpectTest; +import org.jclouds.providers.ProviderMetadata; import org.jclouds.rest.ConfiguresRestClient; +import org.jclouds.rest.internal.BaseRestClientExpectTest; -import com.google.common.base.Function; import com.google.common.base.Supplier; -import com.google.common.collect.ImmutableSet; import com.google.inject.Module; /** @@ -46,13 +38,16 @@ import com.google.inject.Module; public class BaseAWSS3ClientExpectTest extends BaseRestClientExpectTest { protected static final String CONSTANT_DATE = "2009-11-08T15:54:08.897Z"; - - protected BlobStoreContext blobStoreContext; - protected BlobStore blobStore; + public BaseAWSS3ClientExpectTest() { provider = "aws-s3"; } + + @Override + public ProviderMetadata createProviderMetadata() { + return new AWSS3ProviderMetadata(); + } @RequiresHttp @ConfiguresRestClient @@ -68,17 +63,4 @@ public class BaseAWSS3ClientExpectTest extends BaseRestClientExpectTest fn, Module module, Properties props) { - return clientFrom(BlobStoreContext.class.cast(new BlobStoreContextFactory(setupRestProperties()) - .createContext(provider, "identity", "credential", ImmutableSet.of(new ExpectModule(fn), - new NullLoggingModule(), module), props))); - } - - protected AWSS3Client clientFrom(BlobStoreContext context) { - blobStoreContext = context; - blobStore = context.getBlobStore(); - return AWSS3Client.class.cast(context.getProviderSpecificContext().getApi()); - } - } diff --git a/providers/azureblob/pom.xml b/providers/azureblob/pom.xml index d06fd0a561..73f56cc972 100644 --- a/providers/azureblob/pom.xml +++ b/providers/azureblob/pom.xml @@ -34,7 +34,6 @@ bundle - org.jclouds.azureblob.blobstore.integration.AzureBlobTestInitializer https://${jclouds.identity}.blob.core.windows.net 2009-09-19 @@ -99,7 +98,6 @@ ${test.azureblob.build-version} ${test.azureblob.identity} ${test.azureblob.credential} - ${test.initializer} ${jclouds.blobstore.httpstream.url} ${jclouds.blobstore.httpstream.md5}
diff --git a/providers/azureblob/src/main/java/org/jclouds/azureblob/AzureBlobApiMetadata.java b/providers/azureblob/src/main/java/org/jclouds/azureblob/AzureBlobApiMetadata.java index 3c2e3bd5f2..e0d21bee2a 100644 --- a/providers/azureblob/src/main/java/org/jclouds/azureblob/AzureBlobApiMetadata.java +++ b/providers/azureblob/src/main/java/org/jclouds/azureblob/AzureBlobApiMetadata.java @@ -18,51 +18,72 @@ */ package org.jclouds.azureblob; +import static org.jclouds.blobstore.reference.BlobStoreConstants.PROPERTY_USER_METADATA_PREFIX; + import java.net.URI; +import java.util.Properties; import org.jclouds.apis.ApiMetadata; -import org.jclouds.apis.ApiType; -import org.jclouds.apis.BaseApiMetadata; +import org.jclouds.blobstore.BlobStoreContext; +import org.jclouds.blobstore.internal.BaseBlobStoreApiMetadata; + +import com.google.common.reflect.TypeToken; /** * Implementation of {@link ApiMetadata} for Microsoft Azure Blob Service API * * @author Adrian Cole */ -public class AzureBlobApiMetadata extends BaseApiMetadata { +public class AzureBlobApiMetadata + extends + BaseBlobStoreApiMetadata, AzureBlobApiMetadata> { + private static Builder builder() { + return new Builder(); + } + + @Override + public Builder toBuilder() { + return builder().fromApiMetadata(this); + } public AzureBlobApiMetadata() { - this(builder() - .id("azureblob") - .type(ApiType.BLOBSTORE) + this(builder()); + } + + protected AzureBlobApiMetadata(Builder builder) { + super(builder); + } + + protected static Properties defaultProperties() { + Properties properties = BaseBlobStoreApiMetadata.Builder.defaultProperties(); + properties.setProperty(PROPERTY_USER_METADATA_PREFIX, "x-ms-meta-"); + return properties; + } + + public static class Builder extends BaseBlobStoreApiMetadata.Builder, AzureBlobApiMetadata> { + protected Builder(){ + id("azureblob") .name("Microsoft Azure Blob Service API") .identityName("Account Name") .credentialName("Access Key") - .documentation(URI.create("http://msdn.microsoft.com/en-us/library/dd135733.aspx"))); - } - - // below are so that we can reuse builders, toString, hashCode, etc. - // we have to set concrete classes here, as our base class cannot be - // concrete due to serviceLoader - protected AzureBlobApiMetadata(Builder builder) { - super(builder); - } - - private static class ConcreteBuilder extends Builder { - + .version("2009-09-19") + .defaultEndpoint("https://${jclouds.identity}.blob.core.windows.net") + .documentation(URI.create("http://msdn.microsoft.com/en-us/library/dd135733.aspx")) + .contextBuilder(TypeToken.of(AzureBlobContextBuilder.class)) + .javaApi(AzureBlobClient.class, AzureBlobAsyncClient.class) + .defaultProperties(AzureBlobApiMetadata.defaultProperties()); + } + @Override public AzureBlobApiMetadata build() { return new AzureBlobApiMetadata(this); } + + @Override + public Builder fromApiMetadata(AzureBlobApiMetadata in) { + super.fromApiMetadata(in); + return this; + } } - public static ConcreteBuilder builder() { - return new ConcreteBuilder(); - } - - @Override - public ConcreteBuilder toBuilder() { - return builder().fromApiMetadata(this); - } - -} \ No newline at end of file +} diff --git a/providers/azureblob/src/main/java/org/jclouds/azureblob/AzureBlobContextBuilder.java b/providers/azureblob/src/main/java/org/jclouds/azureblob/AzureBlobContextBuilder.java index e36811c2be..e3492de627 100644 --- a/providers/azureblob/src/main/java/org/jclouds/azureblob/AzureBlobContextBuilder.java +++ b/providers/azureblob/src/main/java/org/jclouds/azureblob/AzureBlobContextBuilder.java @@ -19,35 +19,49 @@ package org.jclouds.azureblob; import java.util.List; -import java.util.Properties; import org.jclouds.azureblob.blobstore.config.AzureBlobStoreContextModule; import org.jclouds.azureblob.config.AzureBlobRestClientModule; +import org.jclouds.blobstore.BlobStoreContext; import org.jclouds.blobstore.BlobStoreContextBuilder; import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule; import org.jclouds.logging.jdk.config.JDKLoggingModule; +import org.jclouds.providers.ProviderMetadata; import com.google.inject.Injector; import com.google.inject.Module; /** - * Creates {@link AzureBlobStoreContext} or {@link Injector} instances based on the most commonly - * requested arguments. + * Creates {@link AzureBlobStoreContext} or {@link Injector} instances based on + * the most commonly requested arguments. *

- * Note that Threadsafe objects will be bound as singletons to the Injector or Context provided. + * Note that Threadsafe objects will be bound as singletons to the Injector or + * Context provided. *

*

- * If no Modules are specified, the default {@link JDKLoggingModule logging} and - * {@link JavaUrlHttpCommandExecutorServiceModule http transports} will be installed. + * If no Modules are specified, the default + * {@link JDKLoggingModule logging} and + * {@link JavaUrlHttpCommandExecutorServiceModule http transports} will be + * installed. * * @author Adrian Cole, Andrew Newdigate * @see AzureBlobStoreContext */ -public class AzureBlobContextBuilder extends - BlobStoreContextBuilder { +public class AzureBlobContextBuilder + extends + BlobStoreContextBuilder, AzureBlobApiMetadata> { + + public AzureBlobContextBuilder() { + this(new AzureBlobProviderMetadata()); + } - public AzureBlobContextBuilder(Properties props) { - super(AzureBlobClient.class, AzureBlobAsyncClient.class, props); + public AzureBlobContextBuilder( + ProviderMetadata, AzureBlobApiMetadata> providerMetadata) { + super(providerMetadata); + } + + public AzureBlobContextBuilder(AzureBlobApiMetadata apiMetadata) { + super(apiMetadata); } @Override diff --git a/providers/azureblob/src/main/java/org/jclouds/azureblob/AzureBlobPropertiesBuilder.java b/providers/azureblob/src/main/java/org/jclouds/azureblob/AzureBlobPropertiesBuilder.java deleted file mode 100644 index 5fae25ea68..0000000000 --- a/providers/azureblob/src/main/java/org/jclouds/azureblob/AzureBlobPropertiesBuilder.java +++ /dev/null @@ -1,50 +0,0 @@ -/** - * 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.azureblob; - -import static org.jclouds.Constants.PROPERTY_API_VERSION; -import static org.jclouds.Constants.PROPERTY_ENDPOINT; -import static org.jclouds.Constants.PROPERTY_ISO3166_CODES; -import static org.jclouds.blobstore.reference.BlobStoreConstants.PROPERTY_USER_METADATA_PREFIX; - -import java.util.Properties; - -import org.jclouds.PropertiesBuilder; - -/** - * Builds properties used in AzureBlob Connections - * - * @author Adrian Cole - */ -public class AzureBlobPropertiesBuilder extends PropertiesBuilder { - @Override - protected Properties defaultProperties() { - Properties properties = super.defaultProperties(); - properties.setProperty(PROPERTY_USER_METADATA_PREFIX, "x-ms-meta-"); - properties.setProperty(PROPERTY_API_VERSION, "2009-09-19"); - properties.setProperty(PROPERTY_ENDPOINT, "https://${jclouds.identity}.blob.core.windows.net"); - properties.setProperty(PROPERTY_ISO3166_CODES, "US-TX,US-IL,IE-D,SG,NL-NH,HK"); - return properties; - } - - public AzureBlobPropertiesBuilder(Properties properties) { - super(properties); - } - -} diff --git a/providers/azureblob/src/main/java/org/jclouds/azureblob/AzureBlobProviderMetadata.java b/providers/azureblob/src/main/java/org/jclouds/azureblob/AzureBlobProviderMetadata.java index c57e8beb53..446b44aabb 100644 --- a/providers/azureblob/src/main/java/org/jclouds/azureblob/AzureBlobProviderMetadata.java +++ b/providers/azureblob/src/main/java/org/jclouds/azureblob/AzureBlobProviderMetadata.java @@ -19,46 +19,64 @@ package org.jclouds.azureblob; import java.net.URI; +import java.util.Properties; -import org.jclouds.providers.BaseProviderMetadata; +import org.jclouds.blobstore.BlobStoreContext; +import org.jclouds.providers.ProviderMetadata; +import org.jclouds.providers.internal.BaseProviderMetadata; /** * Implementation of {@link org.jclouds.types.ProviderMetadata} for Microsoft Azure Blob Service. * * @author Adrian Cole */ -public class AzureBlobProviderMetadata extends BaseProviderMetadata { - public AzureBlobProviderMetadata() { - this(builder() - .id("azureblob") - .name("Microsoft Azure Blob Service") - .api(new AzureBlobApiMetadata()) - .homepage(URI.create("http://www.microsoft.com/windowsazure/storage/")) - .console(URI.create("https://windows.azure.com/default.aspx")) - .linkedServices("azureblob", "azurequeue", "azuretable") - .iso3166Codes("US-TX","US-IL","IE-D","SG","NL-NH","HK")); +public class AzureBlobProviderMetadata extends BaseProviderMetadata, AzureBlobApiMetadata> { + + public static Builder builder() { + return new Builder(); } - // below are so that we can reuse builders, toString, hashCode, etc. - // we have to set concrete classes here, as our base class cannot be - // concrete due to serviceLoader - protected AzureBlobProviderMetadata(ConcreteBuilder builder) { + @Override + public Builder toBuilder() { + return builder().fromProviderMetadata(this); + } + + public AzureBlobProviderMetadata() { + super(builder()); + } + + public AzureBlobProviderMetadata(Builder builder) { super(builder); } - private static class ConcreteBuilder extends Builder { + protected static Properties defaultProperties() { + Properties properties = new Properties(); + return properties; + } + public static class Builder extends BaseProviderMetadata.Builder, AzureBlobApiMetadata> { + + protected Builder(){ + id("azureblob") + .name("Microsoft Azure Blob Service") + .apiMetadata(new AzureBlobApiMetadata()) + .endpoint("https://${jclouds.identity}.blob.core.windows.net") + .homepage(URI.create("http://www.microsoft.com/windowsazure/storage/")) + .console(URI.create("https://windows.azure.com/default.aspx")) + .linkedServices("azureblob", "azurequeue", "azuretable") + .iso3166Codes("US-TX","US-IL","IE-D","SG","NL-NH","HK") + .defaultProperties(AzureBlobProviderMetadata.defaultProperties()); + } @Override public AzureBlobProviderMetadata build() { return new AzureBlobProviderMetadata(this); } - } - - public static ConcreteBuilder builder() { - return new ConcreteBuilder(); - } - - public ConcreteBuilder toBuilder() { - return builder().fromProviderMetadata(this); + + @Override + public Builder fromProviderMetadata( + ProviderMetadata, AzureBlobApiMetadata> in) { + super.fromProviderMetadata(in); + return this; + } } } \ No newline at end of file diff --git a/providers/azureblob/src/main/java/org/jclouds/azureblob/blobstore/AzureAsyncBlobStore.java b/providers/azureblob/src/main/java/org/jclouds/azureblob/blobstore/AzureAsyncBlobStore.java index dc8980bae4..10adc18057 100644 --- a/providers/azureblob/src/main/java/org/jclouds/azureblob/blobstore/AzureAsyncBlobStore.java +++ b/providers/azureblob/src/main/java/org/jclouds/azureblob/blobstore/AzureAsyncBlobStore.java @@ -80,7 +80,7 @@ public class AzureAsyncBlobStore extends BaseAsyncBlobStore { private final BlobToHttpGetOptions blob2ObjectGetOptions; @Inject - AzureAsyncBlobStore(BlobStoreContext context, BlobUtils blobUtils, + AzureAsyncBlobStore(@SuppressWarnings("rawtypes") BlobStoreContext context, BlobUtils blobUtils, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService service, Supplier defaultLocation, @Memoized Supplier> locations, AzureBlobAsyncClient async, ContainerToResourceMetadata container2ResourceMd, diff --git a/providers/azureblob/src/main/java/org/jclouds/azureblob/blobstore/AzureBlobStore.java b/providers/azureblob/src/main/java/org/jclouds/azureblob/blobstore/AzureBlobStore.java index 629f176ca7..bc51aa5b22 100644 --- a/providers/azureblob/src/main/java/org/jclouds/azureblob/blobstore/AzureBlobStore.java +++ b/providers/azureblob/src/main/java/org/jclouds/azureblob/blobstore/AzureBlobStore.java @@ -72,7 +72,7 @@ public class AzureBlobStore extends BaseBlobStore { private final BlobToHttpGetOptions blob2ObjectGetOptions; @Inject - AzureBlobStore(BlobStoreContext context, BlobUtils blobUtils, Supplier defaultLocation, + AzureBlobStore(@SuppressWarnings("rawtypes") BlobStoreContext context, BlobUtils blobUtils, Supplier defaultLocation, @Memoized Supplier> locations, AzureBlobClient sync, ContainerToResourceMetadata container2ResourceMd, ListOptionsToListBlobsOptions blobStore2AzureContainerListOptions, diff --git a/providers/azureblob/src/test/java/org/jclouds/azureblob/AzureBlobAsyncClientTest.java b/providers/azureblob/src/test/java/org/jclouds/azureblob/AzureBlobAsyncClientTest.java index b497828c03..72cf44c2b8 100644 --- a/providers/azureblob/src/test/java/org/jclouds/azureblob/AzureBlobAsyncClientTest.java +++ b/providers/azureblob/src/test/java/org/jclouds/azureblob/AzureBlobAsyncClientTest.java @@ -25,7 +25,6 @@ import static org.testng.Assert.assertEquals; import java.io.IOException; import java.lang.reflect.Method; import java.util.Map; -import java.util.Properties; import org.jclouds.azure.storage.filters.SharedKeyLiteAuthentication; import org.jclouds.azure.storage.options.ListOptions; @@ -46,10 +45,8 @@ import org.jclouds.http.functions.ReleasePayloadAndReturn; import org.jclouds.http.functions.ReturnTrueIf2xx; import org.jclouds.http.functions.ReturnTrueOn404; import org.jclouds.http.options.GetOptions; -import org.jclouds.rest.RestClientTest; -import org.jclouds.rest.RestContextFactory; -import org.jclouds.rest.RestContextSpec; import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404; +import org.jclouds.rest.internal.BaseAsyncClientTest; import org.jclouds.rest.internal.RestAnnotationProcessor; import org.testng.annotations.Test; @@ -64,7 +61,7 @@ import com.google.inject.TypeLiteral; */ // NOTE:without testName, this will not call @Before* and fail w/NPE during surefire @Test(groups = "unit", testName = "AzureBlobAsyncClientTest") -public class AzureBlobAsyncClientTest extends RestClientTest { +public class AzureBlobAsyncClientTest extends BaseAsyncClientTest { public void testListContainers() throws SecurityException, NoSuchMethodException, IOException { Method method = AzureBlobAsyncClient.class.getMethod("listContainers", ListOptions[].class); @@ -293,7 +290,7 @@ public class AzureBlobAsyncClientTest extends RestClientTest createContextSpec() { - return new RestContextFactory().createContextSpec("azureblob", "identity", "credential", new Properties()); + public AzureBlobProviderMetadata createProviderMetadata() { + return new AzureBlobProviderMetadata(); } } diff --git a/providers/azureblob/src/test/java/org/jclouds/azureblob/AzureBlobClientLiveTest.java b/providers/azureblob/src/test/java/org/jclouds/azureblob/AzureBlobClientLiveTest.java index dc84cf6044..cded63bf98 100644 --- a/providers/azureblob/src/test/java/org/jclouds/azureblob/AzureBlobClientLiveTest.java +++ b/providers/azureblob/src/test/java/org/jclouds/azureblob/AzureBlobClientLiveTest.java @@ -28,7 +28,6 @@ import java.io.ByteArrayInputStream; import java.lang.reflect.UndeclaredThrowableException; import java.net.URI; import java.security.SecureRandom; -import java.util.Properties; import java.util.Set; import org.jclouds.azure.storage.AzureStorageResponseException; @@ -40,25 +39,19 @@ import org.jclouds.azureblob.domain.ContainerProperties; import org.jclouds.azureblob.domain.ListBlobsResponse; import org.jclouds.azureblob.domain.PublicAccess; import org.jclouds.azureblob.options.ListBlobsOptions; -import org.jclouds.blobstore.BlobStoreContext; -import org.jclouds.blobstore.BlobStoreContextFactory; import org.jclouds.blobstore.ContainerNotFoundException; +import org.jclouds.blobstore.integration.internal.BaseBlobStoreIntegrationTest; import org.jclouds.crypto.CryptoStreams; import org.jclouds.http.HttpResponseException; import org.jclouds.http.options.GetOptions; import org.jclouds.io.Payloads; -import org.jclouds.logging.log4j.config.Log4JLoggingModule; -import org.jclouds.rest.BaseRestClientLiveTest; import org.jclouds.util.Strings2; import org.jclouds.util.Throwables2; -import org.testng.annotations.BeforeGroups; import org.testng.annotations.Test; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMultimap; -import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; -import com.google.inject.Module; /** * Tests behavior of {@code AzureBlobClient} @@ -66,26 +59,18 @@ import com.google.inject.Module; * @author Adrian Cole */ @Test(groups = "live", singleThreaded = true) -public class AzureBlobClientLiveTest extends BaseRestClientLiveTest { +public class AzureBlobClientLiveTest extends BaseBlobStoreIntegrationTest { public AzureBlobClientLiveTest() { provider = "azureblob"; } - protected AzureBlobClient client; - private BlobStoreContext context; - - @BeforeGroups(groups = { "live" }) - public void setupClient() { - setupCredentials(); - Properties overrides = setupProperties(); - context = new BlobStoreContextFactory().createContext(provider, ImmutableSet - . of(new Log4JLoggingModule()), overrides); - client = (AzureBlobClient) context.getProviderSpecificContext().getApi(); + public AzureBlobClient getApi() { + return (AzureBlobClient) context.getProviderSpecificContext().getApi(); } @Test public void testListContainers() throws Exception { - Set response = client.listContainers(); + Set response = getApi().listContainers(); assert null != response; long initialContainerCount = response.size(); assertTrue(initialContainerCount >= 0); @@ -101,7 +86,7 @@ public class AzureBlobClientLiveTest extends BaseRestClientLiveTest { while (!created) { privateContainer = prefix + new SecureRandom().nextInt(); try { - created = client.createContainer(privateContainer, withMetadata(ImmutableMultimap.of("foo", "bar"))); + created = getApi().createContainer(privateContainer, withMetadata(ImmutableMultimap.of("foo", "bar"))); } catch (UndeclaredThrowableException e) { HttpResponseException htpe = (HttpResponseException) e.getCause().getCause(); if (htpe.getResponse().getStatusCode() == 409) @@ -109,13 +94,13 @@ public class AzureBlobClientLiveTest extends BaseRestClientLiveTest { throw e; } } - Set response = client.listContainers(includeMetadata()); + Set response = getApi().listContainers(includeMetadata()); assert null != response; long containerCount = response.size(); assertTrue(containerCount >= 1); - ListBlobsResponse list = client.listBlobs(privateContainer); - assertEquals(list.getUrl(), URI.create(String.format("https://%s.blob.core.windows.net/%s", identity, - privateContainer))); + ListBlobsResponse list = getApi().listBlobs(privateContainer); + assertEquals(list.getUrl(), URI.create(String.format("https://%s.blob.core.windows.net/%s", context + .getProviderSpecificContext().getIdentity(), privateContainer))); // TODO .. check to see the container actually exists } @@ -125,7 +110,7 @@ public class AzureBlobClientLiveTest extends BaseRestClientLiveTest { while (!created) { publicContainer = prefix + new SecureRandom().nextInt(); try { - created = client.createContainer(publicContainer, withPublicAccess(PublicAccess.BLOB)); + created = getApi().createContainer(publicContainer, withPublicAccess(PublicAccess.BLOB)); } catch (UndeclaredThrowableException e) { HttpResponseException htpe = (HttpResponseException) e.getCause().getCause(); if (htpe.getResponse().getStatusCode() == 409) @@ -134,7 +119,8 @@ public class AzureBlobClientLiveTest extends BaseRestClientLiveTest { } } // TODO - // URL url = new URL(String.format("http://%s.blob.core.windows.net/%s", identity, + // URL url = new URL(String.format("http://%s.blob.core.windows.net/%s", + // identity, // publicContainer)); // Utils.toStringAndClose(url.openStream()); } @@ -142,11 +128,12 @@ public class AzureBlobClientLiveTest extends BaseRestClientLiveTest { @Test(timeOut = 5 * 60 * 1000) public void testCreatePublicRootContainer() throws Exception { try { - client.deleteRootContainer(); + getApi().deleteRootContainer(); } catch (ContainerNotFoundException e) { Thread.sleep(5000); } catch (AzureStorageResponseException htpe) { - if (htpe.getResponse().getStatusCode() == 409) {// TODO look for specific message + if (htpe.getResponse().getStatusCode() == 409) {// TODO look for + // specific message Thread.sleep(5000); } else { throw htpe; @@ -156,9 +143,10 @@ public class AzureBlobClientLiveTest extends BaseRestClientLiveTest { boolean created = false; while (!created) { try { - created = client.createRootContainer(); + created = getApi().createRootContainer(); } catch (AzureStorageResponseException htpe) { - if (htpe.getResponse().getStatusCode() == 409) {// TODO look for specific message + if (htpe.getResponse().getStatusCode() == 409) {// TODO look for + // specific message Thread.sleep(5000); continue; } else { @@ -166,15 +154,16 @@ public class AzureBlobClientLiveTest extends BaseRestClientLiveTest { } } } - ListBlobsResponse list = client.listBlobs(); - assertEquals(list.getUrl(), URI.create(String.format("https://%s.blob.core.windows.net/$root", identity))); + ListBlobsResponse list = getApi().listBlobs(); + assertEquals(list.getUrl(), URI.create(String.format("https://%s.blob.core.windows.net/$root", context + .getProviderSpecificContext().getIdentity()))); } @Test public void testListContainersWithOptions() throws Exception { - BoundedSet response = client.listContainers(ListOptions.Builder.prefix(privateContainer) - .maxResults(1).includeMetadata()); + BoundedSet response = getApi().listContainers( + ListOptions.Builder.prefix(privateContainer).maxResults(1).includeMetadata()); assert null != response; long initialContainerCount = response.size(); assertTrue(initialContainerCount >= 0); @@ -184,7 +173,7 @@ public class AzureBlobClientLiveTest extends BaseRestClientLiveTest { @Test(timeOut = 5 * 60 * 1000, dependsOnMethods = { "testCreatePublicRootContainer" }) public void testDeleteRootContainer() throws Exception { - client.deleteRootContainer(); + getApi().deleteRootContainer(); // TODO loop for up to 30 seconds checking if they are really gone } @@ -192,18 +181,20 @@ public class AzureBlobClientLiveTest extends BaseRestClientLiveTest { public void testListOwnedContainers() throws Exception { // Test default listing - Set response = client.listContainers(); - // assertEquals(response.size(), initialContainerCount + 2);// if the containers already + Set response = getApi().listContainers(); + // assertEquals(response.size(), initialContainerCount + 2);// if the + // containers already // exist, this will fail // Test listing with options - response = client.listContainers(ListOptions.Builder.prefix( - privateContainer.substring(0, privateContainer.length() - 1)).maxResults(1).includeMetadata()); + response = getApi().listContainers( + ListOptions.Builder.prefix(privateContainer.substring(0, privateContainer.length() - 1)).maxResults(1) + .includeMetadata()); assertEquals(response.size(), 1); assertEquals(Iterables.getOnlyElement(response).getName(), privateContainer); assertEquals(Iterables.getOnlyElement(response).getMetadata(), ImmutableMap.of("foo", "bar")); - response = client.listContainers(ListOptions.Builder.prefix(publicContainer).maxResults(1)); + response = getApi().listContainers(ListOptions.Builder.prefix(publicContainer).maxResults(1)); assertEquals(response.size(), 1); assertEquals(Iterables.getOnlyElement(response).getName(), publicContainer); @@ -211,13 +202,13 @@ public class AzureBlobClientLiveTest extends BaseRestClientLiveTest { @Test public void testDeleteOneContainer() throws Exception { - client.deleteContainer("does-not-exist"); + getApi().deleteContainer("does-not-exist"); } @Test(timeOut = 5 * 60 * 1000, dependsOnMethods = { "testListOwnedContainers", "testObjectOperations" }) public void testDeleteContainer() throws Exception { - client.deleteContainer(privateContainer); - client.deleteContainer(publicContainer); + getApi().deleteContainer(privateContainer); + getApi().deleteContainer(publicContainer); // TODO loop for up to 30 seconds checking if they are really gone } @@ -226,33 +217,37 @@ public class AzureBlobClientLiveTest extends BaseRestClientLiveTest { String data = "Here is my data"; // Test PUT with string data, ETag hash, and a piece of metadata - AzureBlob object = client.newBlob(); + AzureBlob object = getApi().newBlob(); object.getProperties().setName("object"); object.setPayload(data); Payloads.calculateMD5(object); object.getProperties().getContentMetadata().setContentType("text/plain"); object.getProperties().getMetadata().put("mykey", "metadata-value"); byte[] md5 = object.getProperties().getContentMetadata().getContentMD5(); - String newEtag = client.putBlob(privateContainer, object); - assertEquals(CryptoStreams.hex(md5), CryptoStreams.hex(object.getProperties().getContentMetadata() - .getContentMD5())); + String newEtag = getApi().putBlob(privateContainer, object); + assertEquals(CryptoStreams.hex(md5), + CryptoStreams.hex(object.getProperties().getContentMetadata().getContentMD5())); // Test HEAD of missing object - assert client.getBlobProperties(privateContainer, "non-existent-object") == null; + assert getApi().getBlobProperties(privateContainer, "non-existent-object") == null; // Test HEAD of object - BlobProperties metadata = client.getBlobProperties(privateContainer, object.getProperties().getName()); - // TODO assertEquals(metadata.getName(), object.getProperties().getName()); - // we can't check this while hacking around lack of content-md5, as GET of the first byte will - // show incorrect length 1, the returned size, as opposed to the real length. This is an ok - // tradeoff, as a container list will contain the correct size of the objects in an + BlobProperties metadata = getApi().getBlobProperties(privateContainer, object.getProperties().getName()); + // TODO assertEquals(metadata.getName(), + // object.getProperties().getName()); + // we can't check this while hacking around lack of content-md5, as GET of + // the first byte will + // show incorrect length 1, the returned size, as opposed to the real + // length. This is an ok + // tradeoff, as a container list will contain the correct size of the + // objects in an // inexpensive fashion // http://code.google.com/p/jclouds/issues/detail?id=92 // assertEquals(metadata.getSize(), data.length()); assertEquals(metadata.getContentMetadata().getContentType(), "text/plain"); // Azure doesn't return the Content-MD5 on head request.. - assertEquals(CryptoStreams.hex(md5), CryptoStreams.hex(object.getProperties().getContentMetadata() - .getContentMD5())); + assertEquals(CryptoStreams.hex(md5), + CryptoStreams.hex(object.getProperties().getContentMetadata().getContentMD5())); assertEquals(metadata.getETag(), newEtag); assertEquals(metadata.getMetadata().entrySet().size(), 1); assertEquals(metadata.getMetadata().get("mykey"), "metadata-value"); @@ -261,23 +256,25 @@ public class AzureBlobClientLiveTest extends BaseRestClientLiveTest { // Multimap userMetadata = LinkedHashMultimap.create(); // userMetadata.put("New-Metadata-1", "value-1"); // userMetadata.put("New-Metadata-2", "value-2"); - // assertTrue(client.setBlobProperties(privateContainer, object.getProperties().getName(), + // assertTrue(getApi().setBlobProperties(privateContainer, + // object.getProperties().getName(), // userMetadata)); // Test GET of missing object - assert client.getBlob(privateContainer, "non-existent-object") == null; + assert getApi().getBlob(privateContainer, "non-existent-object") == null; // Test GET of object (including updated metadata) - AzureBlob getBlob = client.getBlob(privateContainer, object.getProperties().getName()); + AzureBlob getBlob = getApi().getBlob(privateContainer, object.getProperties().getName()); assertEquals(Strings2.toStringAndClose(getBlob.getPayload().getInput()), data); // TODO assertEquals(getBlob.getName(), object.getProperties().getName()); assertEquals(getBlob.getPayload().getContentMetadata().getContentLength(), new Long(data.length())); assertEquals(getBlob.getProperties().getContentMetadata().getContentType(), "text/plain"); - assertEquals(CryptoStreams.hex(md5), CryptoStreams.hex(getBlob.getProperties().getContentMetadata() - .getContentMD5())); + assertEquals(CryptoStreams.hex(md5), + CryptoStreams.hex(getBlob.getProperties().getContentMetadata().getContentMD5())); assertEquals(newEtag, getBlob.getProperties().getETag()); // wait until we can update metadata - // assertEquals(getBlob.getProperties().getMetadata().entries().size(), 2); + // assertEquals(getBlob.getProperties().getMetadata().entries().size(), + // 2); // assertEquals( // Iterables.getLast(getBlob.getProperties().getMetadata().get("New-Metadata-1")), // "value-1"); @@ -288,38 +285,41 @@ public class AzureBlobClientLiveTest extends BaseRestClientLiveTest { assertEquals(metadata.getMetadata().get("mykey"), "metadata-value"); // test listing - ListBlobsResponse response = client.listBlobs(privateContainer, ListBlobsOptions.Builder.prefix( - object.getProperties().getName().substring(0, object.getProperties().getName().length() - 1)) - .maxResults(1).includeMetadata()); + ListBlobsResponse response = getApi().listBlobs( + privateContainer, + ListBlobsOptions.Builder + .prefix(object.getProperties().getName().substring(0, object.getProperties().getName().length() - 1)) + .maxResults(1).includeMetadata()); assertEquals(response.size(), 1); assertEquals(Iterables.getOnlyElement(response).getName(), object.getProperties().getName()); assertEquals(Iterables.getOnlyElement(response).getMetadata(), ImmutableMap.of("mykey", "metadata-value")); - // Test PUT with invalid ETag (as if object's data was corrupted in transit) + // Test PUT with invalid ETag (as if object's data was corrupted in + // transit) String correctEtag = newEtag; String incorrectEtag = "0" + correctEtag.substring(1); object.getProperties().setETag(incorrectEtag); try { - client.putBlob(privateContainer, object); + getApi().putBlob(privateContainer, object); } catch (Throwable e) { assertEquals(e.getCause().getClass(), HttpResponseException.class); assertEquals(((HttpResponseException) e.getCause()).getResponse().getStatusCode(), 422); } ByteArrayInputStream bais = new ByteArrayInputStream(data.getBytes("UTF-8")); - object = client.newBlob(); + object = getApi().newBlob(); object.getProperties().setName("chunked-object"); object.setPayload(bais); object.getPayload().getContentMetadata().setContentLength(new Long(data.getBytes().length)); - newEtag = client.putBlob(privateContainer, object); - assertEquals(CryptoStreams.hex(md5), CryptoStreams.hex(getBlob.getProperties().getContentMetadata() - .getContentMD5())); + newEtag = getApi().putBlob(privateContainer, object); + assertEquals(CryptoStreams.hex(md5), + CryptoStreams.hex(getBlob.getProperties().getContentMetadata().getContentMD5())); // Test GET with options // Non-matching ETag try { - client.getBlob(privateContainer, object.getProperties().getName(), GetOptions.Builder - .ifETagDoesntMatch(newEtag)); + getApi().getBlob(privateContainer, object.getProperties().getName(), + GetOptions.Builder.ifETagDoesntMatch(newEtag)); } catch (Exception e) { HttpResponseException httpEx = Throwables2.getFirstThrowableOfType(e, HttpResponseException.class); assert (httpEx != null) : "expected http exception, not " + e; @@ -328,8 +328,8 @@ public class AzureBlobClientLiveTest extends BaseRestClientLiveTest { // Matching ETag TODO this shouldn't fail!!! try { - getBlob = client.getBlob(privateContainer, object.getProperties().getName(), GetOptions.Builder - .ifETagMatches(newEtag)); + getBlob = getApi().getBlob(privateContainer, object.getProperties().getName(), + GetOptions.Builder.ifETagMatches(newEtag)); assertEquals(getBlob.getProperties().getETag(), newEtag); } catch (HttpResponseException e) { assertEquals(e.getResponse().getStatusCode(), 412); @@ -338,13 +338,14 @@ public class AzureBlobClientLiveTest extends BaseRestClientLiveTest { // Range // doesn't work per // http://social.msdn.microsoft.com/Forums/en-US/windowsazure/thread/479fa63f-51df-4b66-96b5-33ae362747b6 - // getBlob = client + // getBlob = getApi() // .getBlob(privateContainer, object.getProperties().getName(), // GetOptions.Builder.startAt(8)).get(120, // TimeUnit.SECONDS); - // assertEquals(Utils.toStringAndClose((InputStream) getBlob.getData()), data.substring(8)); + // assertEquals(Utils.toStringAndClose((InputStream) getBlob.getData()), + // data.substring(8)); - client.deleteBlob(privateContainer, "object"); - client.deleteBlob(privateContainer, "chunked-object"); + getApi().deleteBlob(privateContainer, "object"); + getApi().deleteBlob(privateContainer, "chunked-object"); } } diff --git a/providers/azureblob/src/test/java/org/jclouds/azureblob/AzureBlobProviderTest.java b/providers/azureblob/src/test/java/org/jclouds/azureblob/AzureBlobProviderTest.java index d37a651909..81ddbaac09 100644 --- a/providers/azureblob/src/test/java/org/jclouds/azureblob/AzureBlobProviderTest.java +++ b/providers/azureblob/src/test/java/org/jclouds/azureblob/AzureBlobProviderTest.java @@ -18,7 +18,7 @@ */ package org.jclouds.azureblob; -import org.jclouds.providers.BaseProviderMetadataTest; +import org.jclouds.providers.internal.BaseProviderMetadataTest; import org.testng.annotations.Test; /** diff --git a/providers/azureblob/src/test/java/org/jclouds/azureblob/binders/BindAzureBlobMetadataToRequestTest.java b/providers/azureblob/src/test/java/org/jclouds/azureblob/binders/BindAzureBlobMetadataToRequestTest.java index 57fce98969..a2424d3a16 100644 --- a/providers/azureblob/src/test/java/org/jclouds/azureblob/binders/BindAzureBlobMetadataToRequestTest.java +++ b/providers/azureblob/src/test/java/org/jclouds/azureblob/binders/BindAzureBlobMetadataToRequestTest.java @@ -22,18 +22,16 @@ import static org.testng.Assert.assertEquals; import java.io.File; import java.net.URI; -import java.util.Properties; import javax.ws.rs.HttpMethod; import org.jclouds.azureblob.AzureBlobAsyncClient; +import org.jclouds.azureblob.AzureBlobProviderMetadata; import org.jclouds.azureblob.domain.AzureBlob; import org.jclouds.http.HttpRequest; import org.jclouds.io.Payload; import org.jclouds.io.Payloads; -import org.jclouds.rest.RestClientTest; -import org.jclouds.rest.RestContextFactory; -import org.jclouds.rest.RestContextSpec; +import org.jclouds.rest.internal.BaseAsyncClientTest; import org.jclouds.rest.internal.RestAnnotationProcessor; import org.testng.annotations.Test; @@ -48,7 +46,7 @@ import com.google.inject.TypeLiteral; */ // NOTE:without testName, this will not call @Before* and fail w/NPE during surefire @Test(groups = "unit", testName = "BindAzureBlobMetadataToRequestTest") -public class BindAzureBlobMetadataToRequestTest extends RestClientTest { +public class BindAzureBlobMetadataToRequestTest extends BaseAsyncClientTest { @Test public void testPassWithMinimumDetailsAndPayload64MB() { @@ -147,7 +145,7 @@ public class BindAzureBlobMetadataToRequestTest extends RestClientTest createContextSpec() { - return new RestContextFactory().createContextSpec("azureblob", "identity", "credential", new Properties()); + public AzureBlobProviderMetadata createProviderMetadata() { + return new AzureBlobProviderMetadata(); } } diff --git a/providers/azureblob/src/test/java/org/jclouds/azureblob/blobstore/AzureBlobRequestSignerTest.java b/providers/azureblob/src/test/java/org/jclouds/azureblob/blobstore/AzureBlobRequestSignerTest.java index ace0f360c2..d8d54451b8 100644 --- a/providers/azureblob/src/test/java/org/jclouds/azureblob/blobstore/AzureBlobRequestSignerTest.java +++ b/providers/azureblob/src/test/java/org/jclouds/azureblob/blobstore/AzureBlobRequestSignerTest.java @@ -21,9 +21,9 @@ package org.jclouds.azureblob.blobstore; import static org.testng.Assert.assertEquals; import java.io.IOException; -import java.util.Properties; import org.jclouds.azureblob.AzureBlobAsyncClient; +import org.jclouds.azureblob.AzureBlobProviderMetadata; import org.jclouds.azureblob.config.AzureBlobRestClientModule; import org.jclouds.blobstore.BlobRequestSigner; import org.jclouds.blobstore.domain.Blob; @@ -32,9 +32,7 @@ import org.jclouds.date.TimeStamp; import org.jclouds.http.HttpRequest; import org.jclouds.http.RequiresHttp; import org.jclouds.rest.ConfiguresRestClient; -import org.jclouds.rest.RestClientTest; -import org.jclouds.rest.RestContextFactory; -import org.jclouds.rest.RestContextSpec; +import org.jclouds.rest.internal.BaseAsyncClientTest; import org.jclouds.rest.internal.RestAnnotationProcessor; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; @@ -50,7 +48,7 @@ import com.google.inject.TypeLiteral; */ // NOTE:without testName, this will not call @Before* and fail w/NPE during surefire @Test(groups = "unit", testName = "AzureBlobRequestSignerTest") -public class AzureBlobRequestSignerTest extends RestClientTest { +public class AzureBlobRequestSignerTest extends BaseAsyncClientTest { private BlobRequestSigner signer; private Factory blobFactory; @@ -138,8 +136,7 @@ public class AzureBlobRequestSignerTest extends RestClientTest createContextSpec() { - return new RestContextFactory().createContextSpec("azureblob", "identity", "credential", new Properties()); + public AzureBlobProviderMetadata createProviderMetadata() { + return new AzureBlobProviderMetadata(); } - } diff --git a/providers/azureblob/src/test/java/org/jclouds/azureblob/blobstore/config/AzureBlobStoreModuleTest.java b/providers/azureblob/src/test/java/org/jclouds/azureblob/blobstore/config/AzureBlobStoreModuleTest.java index be2cd4eb41..a4ad4e0722 100644 --- a/providers/azureblob/src/test/java/org/jclouds/azureblob/blobstore/config/AzureBlobStoreModuleTest.java +++ b/providers/azureblob/src/test/java/org/jclouds/azureblob/blobstore/config/AzureBlobStoreModuleTest.java @@ -20,18 +20,13 @@ package org.jclouds.azureblob.blobstore.config; import static org.testng.Assert.assertEquals; +import org.jclouds.azureblob.AzureBlobProviderMetadata; import org.jclouds.azureblob.blobstore.strategy.FindMD5InBlobProperties; -import org.jclouds.blobstore.BlobStoreContext; -import org.jclouds.blobstore.internal.BlobStoreContextImpl; +import org.jclouds.blobstore.BlobStoreContextBuilder; import org.jclouds.blobstore.strategy.ContainsValueInListStrategy; -import org.jclouds.logging.config.NullLoggingModule; -import org.jclouds.rest.BaseRestClientTest.MockModule; -import org.jclouds.rest.RestContextFactory; import org.testng.annotations.Test; -import com.google.common.collect.ImmutableSet; import com.google.inject.Injector; -import com.google.inject.Module; /** * @author Adrian Cole @@ -39,20 +34,14 @@ import com.google.inject.Module; @Test(groups = "unit") public class AzureBlobStoreModuleTest { - Injector createInjector() { - return new RestContextFactory().createContextBuilder("azureblob", "uid", "key", - ImmutableSet. of(new MockModule(), new NullLoggingModule())).buildInjector(); - } - @Test void testContextImpl() { - Injector injector = createInjector(); - BlobStoreContext handler = injector.getInstance(BlobStoreContext.class); - assertEquals(handler.getClass(), BlobStoreContextImpl.class); - ContainsValueInListStrategy valueList = injector - .getInstance(ContainsValueInListStrategy.class); + Injector injector = BlobStoreContextBuilder.newBuilder(new AzureBlobProviderMetadata()).credentials("foo", "bar") + .buildInjector(); + ContainsValueInListStrategy valueList = injector.getInstance(ContainsValueInListStrategy.class); assertEquals(valueList.getClass(), FindMD5InBlobProperties.class); } + } diff --git a/providers/azureblob/src/test/java/org/jclouds/azureblob/blobstore/integration/AzureBlobContainerIntegrationLiveTest.java b/providers/azureblob/src/test/java/org/jclouds/azureblob/blobstore/integration/AzureBlobContainerIntegrationLiveTest.java index 9fb7ce01cd..dc73426d51 100644 --- a/providers/azureblob/src/test/java/org/jclouds/azureblob/blobstore/integration/AzureBlobContainerIntegrationLiveTest.java +++ b/providers/azureblob/src/test/java/org/jclouds/azureblob/blobstore/integration/AzureBlobContainerIntegrationLiveTest.java @@ -27,5 +27,7 @@ import org.testng.annotations.Test; */ @Test(groups = "live") public class AzureBlobContainerIntegrationLiveTest extends BaseContainerIntegrationTest { - + public AzureBlobContainerIntegrationLiveTest() { + provider = "azureblob"; + } } diff --git a/providers/azureblob/src/test/java/org/jclouds/azureblob/blobstore/integration/AzureBlobContainerLiveTest.java b/providers/azureblob/src/test/java/org/jclouds/azureblob/blobstore/integration/AzureBlobContainerLiveTest.java index 1e000777a1..8b484bdd62 100644 --- a/providers/azureblob/src/test/java/org/jclouds/azureblob/blobstore/integration/AzureBlobContainerLiveTest.java +++ b/providers/azureblob/src/test/java/org/jclouds/azureblob/blobstore/integration/AzureBlobContainerLiveTest.java @@ -26,5 +26,7 @@ import org.testng.annotations.Test; */ @Test(groups = { "live" }) public class AzureBlobContainerLiveTest extends BaseContainerLiveTest { - + public AzureBlobContainerLiveTest() { + provider = "azureblob"; + } } diff --git a/providers/azureblob/src/test/java/org/jclouds/azureblob/blobstore/integration/AzureBlobInputStreamMapIntegrationLiveTest.java b/providers/azureblob/src/test/java/org/jclouds/azureblob/blobstore/integration/AzureBlobInputStreamMapIntegrationLiveTest.java index 46080d53ef..42dd9b61d5 100644 --- a/providers/azureblob/src/test/java/org/jclouds/azureblob/blobstore/integration/AzureBlobInputStreamMapIntegrationLiveTest.java +++ b/providers/azureblob/src/test/java/org/jclouds/azureblob/blobstore/integration/AzureBlobInputStreamMapIntegrationLiveTest.java @@ -26,5 +26,7 @@ import org.testng.annotations.Test; */ @Test(groups = "live") public class AzureBlobInputStreamMapIntegrationLiveTest extends BaseInputStreamMapIntegrationTest { - + public AzureBlobInputStreamMapIntegrationLiveTest() { + provider = "azureblob"; + } } diff --git a/providers/azureblob/src/test/java/org/jclouds/azureblob/blobstore/integration/AzureBlobIntegrationLiveTest.java b/providers/azureblob/src/test/java/org/jclouds/azureblob/blobstore/integration/AzureBlobIntegrationLiveTest.java index ce345013da..e22bebd58a 100644 --- a/providers/azureblob/src/test/java/org/jclouds/azureblob/blobstore/integration/AzureBlobIntegrationLiveTest.java +++ b/providers/azureblob/src/test/java/org/jclouds/azureblob/blobstore/integration/AzureBlobIntegrationLiveTest.java @@ -31,7 +31,9 @@ import org.testng.annotations.Test; */ @Test(groups = "live") public class AzureBlobIntegrationLiveTest extends BaseBlobIntegrationTest { - + public AzureBlobIntegrationLiveTest() { + provider = "azureblob"; + } @Override public void testGetIfMatch() throws InterruptedException { // this currently fails diff --git a/providers/azureblob/src/test/java/org/jclouds/azureblob/blobstore/integration/AzureBlobLiveTest.java b/providers/azureblob/src/test/java/org/jclouds/azureblob/blobstore/integration/AzureBlobLiveTest.java index 708385b08b..405a1f060b 100644 --- a/providers/azureblob/src/test/java/org/jclouds/azureblob/blobstore/integration/AzureBlobLiveTest.java +++ b/providers/azureblob/src/test/java/org/jclouds/azureblob/blobstore/integration/AzureBlobLiveTest.java @@ -27,5 +27,7 @@ import org.testng.annotations.Test; */ @Test(groups = { "live" }) public class AzureBlobLiveTest extends BaseBlobLiveTest { - + public AzureBlobLiveTest() { + provider = "azureblob"; + } } diff --git a/providers/azureblob/src/test/java/org/jclouds/azureblob/blobstore/integration/AzureBlobMapIntegrationLiveTest.java b/providers/azureblob/src/test/java/org/jclouds/azureblob/blobstore/integration/AzureBlobMapIntegrationLiveTest.java index b3d2829a11..27a948afbe 100644 --- a/providers/azureblob/src/test/java/org/jclouds/azureblob/blobstore/integration/AzureBlobMapIntegrationLiveTest.java +++ b/providers/azureblob/src/test/java/org/jclouds/azureblob/blobstore/integration/AzureBlobMapIntegrationLiveTest.java @@ -26,5 +26,7 @@ import org.testng.annotations.Test; */ @Test(groups = "live") public class AzureBlobMapIntegrationLiveTest extends BaseBlobMapIntegrationTest { - + public AzureBlobMapIntegrationLiveTest() { + provider = "azureblob"; + } } diff --git a/providers/azureblob/src/test/java/org/jclouds/azureblob/blobstore/integration/AzureBlobServiceIntegrationLiveTest.java b/providers/azureblob/src/test/java/org/jclouds/azureblob/blobstore/integration/AzureBlobServiceIntegrationLiveTest.java index e1cc463b93..9517b59fce 100644 --- a/providers/azureblob/src/test/java/org/jclouds/azureblob/blobstore/integration/AzureBlobServiceIntegrationLiveTest.java +++ b/providers/azureblob/src/test/java/org/jclouds/azureblob/blobstore/integration/AzureBlobServiceIntegrationLiveTest.java @@ -30,6 +30,9 @@ import com.google.common.collect.ImmutableSet; */ @Test(groups = "live") public class AzureBlobServiceIntegrationLiveTest extends BaseServiceIntegrationTest { + public AzureBlobServiceIntegrationLiveTest() { + provider = "azureblob"; + } @Override protected Set getIso3166Codes() { return ImmutableSet. of("US-TX", "US-IL", "IE-D", "SG", "NL-NH", "HK"); diff --git a/providers/azureblob/src/test/java/org/jclouds/azureblob/blobstore/integration/AzureBlobSignerLiveTest.java b/providers/azureblob/src/test/java/org/jclouds/azureblob/blobstore/integration/AzureBlobSignerLiveTest.java index 9f1358051a..04eb532b85 100644 --- a/providers/azureblob/src/test/java/org/jclouds/azureblob/blobstore/integration/AzureBlobSignerLiveTest.java +++ b/providers/azureblob/src/test/java/org/jclouds/azureblob/blobstore/integration/AzureBlobSignerLiveTest.java @@ -27,5 +27,7 @@ import org.testng.annotations.Test; */ @Test(groups = { "live" }) public class AzureBlobSignerLiveTest extends BaseBlobSignerLiveTest { - + public AzureBlobSignerLiveTest() { + provider = "azureblob"; + } } diff --git a/providers/azureblob/src/test/java/org/jclouds/azureblob/blobstore/integration/AzureBlobTestInitializer.java b/providers/azureblob/src/test/java/org/jclouds/azureblob/blobstore/integration/AzureBlobTestInitializer.java deleted file mode 100644 index 5dfcd0a1d0..0000000000 --- a/providers/azureblob/src/test/java/org/jclouds/azureblob/blobstore/integration/AzureBlobTestInitializer.java +++ /dev/null @@ -1,48 +0,0 @@ -/** - * 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.azureblob.blobstore.integration; - -import java.io.IOException; - -import org.jclouds.blobstore.BlobStoreContext; -import org.jclouds.blobstore.BlobStoreContextFactory; -import org.jclouds.blobstore.integration.TransientBlobStoreTestInitializer; -import org.jclouds.logging.log4j.config.Log4JLoggingModule; - -import com.google.common.collect.ImmutableSet; -import com.google.inject.Module; - -/** - * - * @author Adrian Cole - */ -public class AzureBlobTestInitializer extends TransientBlobStoreTestInitializer { - - public AzureBlobTestInitializer() { - provider = "azureblob"; - } - - @Override - protected BlobStoreContext createLiveContext(Module configurationModule, String endpoint, String apiVersion, - String buildVersion, String app, String identity, String credential) throws IOException { - return new BlobStoreContextFactory().createContext(provider, ImmutableSet.of(configurationModule, - new Log4JLoggingModule()), setupProperties(endpoint, apiVersion, buildVersion, identity, credential)); - } - -} diff --git a/providers/bluelock-vcloud-zone01/src/main/java/org/jclouds/bluelock/vcloud/zone01/BluelockVCloudZone01ContextBuilder.java b/providers/bluelock-vcloud-zone01/src/main/java/org/jclouds/bluelock/vcloud/zone01/BluelockVCloudZone01ContextBuilder.java index 31881dcb78..c65d72fba9 100644 --- a/providers/bluelock-vcloud-zone01/src/main/java/org/jclouds/bluelock/vcloud/zone01/BluelockVCloudZone01ContextBuilder.java +++ b/providers/bluelock-vcloud-zone01/src/main/java/org/jclouds/bluelock/vcloud/zone01/BluelockVCloudZone01ContextBuilder.java @@ -19,11 +19,15 @@ package org.jclouds.bluelock.vcloud.zone01; import java.util.List; -import java.util.Properties; import org.jclouds.bluelock.vcloud.zone01.config.BluelockVCloudZone01RestClientModule; +import org.jclouds.compute.ComputeServiceContext; import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule; import org.jclouds.logging.jdk.config.JDKLoggingModule; +import org.jclouds.providers.ProviderMetadata; +import org.jclouds.vcloud.VCloudApiMetadata; +import org.jclouds.vcloud.VCloudAsyncClient; +import org.jclouds.vcloud.VCloudClient; import org.jclouds.vcloud.VCloudContextBuilder; import org.jclouds.vcloud.compute.config.VCloudComputeServiceContextModule; @@ -31,21 +35,28 @@ import com.google.inject.Injector; import com.google.inject.Module; /** - * Creates {@link BlueLockVCloudComputeServiceContext} or {@link Injector} instances based on the - * most commonly requested arguments. + * Creates {@link BlueLockVCloudComputeServiceContext} or {@link Injector} + * instances based on the most commonly requested arguments. *

- * Note that Threadsafe objects will be bound as singletons to the Injector or Context provided. + * Note that Threadsafe objects will be bound as singletons to the Injector or + * Context provided. *

*

- * If no Modules are specified, the default {@link JDKLoggingModule logging} and - * {@link JavaUrlHttpCommandExecutorServiceModule http transports} will be installed. + * If no Modules are specified, the default + * {@link JDKLoggingModule logging} and + * {@link JavaUrlHttpCommandExecutorServiceModule http transports} will be + * installed. * * @author Adrian Cole */ public class BluelockVCloudZone01ContextBuilder extends VCloudContextBuilder { + public BluelockVCloudZone01ContextBuilder( + ProviderMetadata, VCloudApiMetadata> providerMetadata) { + super(providerMetadata); + } - public BluelockVCloudZone01ContextBuilder(Properties props) { - super(props); + public BluelockVCloudZone01ContextBuilder(VCloudApiMetadata apiMetadata) { + super(apiMetadata); } @Override diff --git a/providers/bluelock-vcloud-zone01/src/main/java/org/jclouds/bluelock/vcloud/zone01/BluelockVCloudZone01PropertiesBuilder.java b/providers/bluelock-vcloud-zone01/src/main/java/org/jclouds/bluelock/vcloud/zone01/BluelockVCloudZone01PropertiesBuilder.java deleted file mode 100644 index f7a089870f..0000000000 --- a/providers/bluelock-vcloud-zone01/src/main/java/org/jclouds/bluelock/vcloud/zone01/BluelockVCloudZone01PropertiesBuilder.java +++ /dev/null @@ -1,49 +0,0 @@ -/** - * 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.bluelock.vcloud.zone01; - -import static org.jclouds.Constants.PROPERTY_BUILD_VERSION; -import static org.jclouds.Constants.PROPERTY_ENDPOINT; -import static org.jclouds.Constants.PROPERTY_ISO3166_CODES; -import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_NETWORK; - -import java.util.Properties; - -import org.jclouds.vcloud.VCloudPropertiesBuilder; - -/** - * Builds properties used in bluelock VCloud Clients - * - * @author Adrian Cole - */ -public class BluelockVCloudZone01PropertiesBuilder extends VCloudPropertiesBuilder { - @Override - protected Properties defaultProperties() { - Properties properties = super.defaultProperties(); - properties.setProperty(PROPERTY_ISO3166_CODES, "US-IN"); - properties.setProperty(PROPERTY_ENDPOINT, "https://zone01.bluelock.com/api"); - properties.setProperty(PROPERTY_BUILD_VERSION, "1.5.0.464915"); - properties.setProperty(PROPERTY_VCLOUD_DEFAULT_NETWORK, "internet01-.*"); - return properties; - } - - public BluelockVCloudZone01PropertiesBuilder(Properties properties) { - super(properties); - } -} diff --git a/providers/bluelock-vcloud-zone01/src/main/java/org/jclouds/bluelock/vcloud/zone01/BluelockVCloudZone01ProviderMetadata.java b/providers/bluelock-vcloud-zone01/src/main/java/org/jclouds/bluelock/vcloud/zone01/BluelockVCloudZone01ProviderMetadata.java index ad88c48042..eca1705bbf 100644 --- a/providers/bluelock-vcloud-zone01/src/main/java/org/jclouds/bluelock/vcloud/zone01/BluelockVCloudZone01ProviderMetadata.java +++ b/providers/bluelock-vcloud-zone01/src/main/java/org/jclouds/bluelock/vcloud/zone01/BluelockVCloudZone01ProviderMetadata.java @@ -18,49 +18,78 @@ */ package org.jclouds.bluelock.vcloud.zone01; -import java.net.URI; +import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_NETWORK; -import org.jclouds.providers.BaseProviderMetadata; +import java.net.URI; +import java.util.Properties; + +import org.jclouds.compute.ComputeServiceContext; +import org.jclouds.providers.ProviderMetadata; +import org.jclouds.providers.internal.BaseProviderMetadata; import org.jclouds.vcloud.VCloudApiMetadata; +import org.jclouds.vcloud.VCloudAsyncClient; +import org.jclouds.vcloud.VCloudClient; + +import com.google.common.reflect.TypeToken; /** * Implementation of {@link org.jclouds.types.ProviderMetadata} for Bluelock vCloud Zone 1. * * @author Adrian Cole */ -public class BluelockVCloudZone01ProviderMetadata extends BaseProviderMetadata { +public class BluelockVCloudZone01ProviderMetadata + extends + BaseProviderMetadata, VCloudApiMetadata> { - public BluelockVCloudZone01ProviderMetadata() { - this(builder() - .id("bluelock-vcloud-zone01") - .name("Bluelock vCloud Zone 1") - .api(new VCloudApiMetadata()) - .homepage(URI.create("http://www.bluelock.com/bluelock-cloud-hosting")) - .console(URI.create("https://zone01.bluelock.com/cloud/org/YOUR_ORG_HERE")) - .iso3166Codes("US-IN")); + public static Builder builder() { + return new Builder(); } - // below are so that we can reuse builders, toString, hashCode, etc. - // we have to set concrete classes here, as our base class cannot be - // concrete due to serviceLoader - protected BluelockVCloudZone01ProviderMetadata(ConcreteBuilder builder) { + @Override + public Builder toBuilder() { + return builder().fromProviderMetadata(this); + } + + public BluelockVCloudZone01ProviderMetadata() { + super(builder()); + } + + public BluelockVCloudZone01ProviderMetadata(Builder builder) { super(builder); } - private static class ConcreteBuilder extends Builder { + protected static Properties defaultProperties() { + Properties properties = new Properties(); + properties.setProperty(PROPERTY_VCLOUD_DEFAULT_NETWORK, "internet01-.*"); + return properties; + } + + public static class Builder extends BaseProviderMetadata.Builder, VCloudApiMetadata> { + + protected Builder(){ + id("bluelock-vcloud-zone01") + .name("Bluelock vCloud Zone 1") + .apiMetadata( + new VCloudApiMetadata().toBuilder() + .buildVersion("1.5.0.464915") + .contextBuilder(TypeToken.of(BluelockVCloudZone01ContextBuilder.class)).build()) + .homepage(URI.create("http://www.bluelock.com/bluelock-cloud-hosting")) + .console(URI.create("https://zone01.bluelock.com/cloud/org/YOUR_ORG_HERE")) + .iso3166Codes("US-IN") + .endpoint("https://zone01.bluelock.com/api") + .defaultProperties(BluelockVCloudZone01ProviderMetadata.defaultProperties()); + } @Override public BluelockVCloudZone01ProviderMetadata build() { return new BluelockVCloudZone01ProviderMetadata(this); } + + @Override + public Builder fromProviderMetadata( + ProviderMetadata, VCloudApiMetadata> in) { + super.fromProviderMetadata(in); + return this; + } } - - public static ConcreteBuilder builder() { - return new ConcreteBuilder(); - } - - public ConcreteBuilder toBuilder() { - return builder().fromProviderMetadata(this); - } - -} +} \ No newline at end of file diff --git a/providers/bluelock-vcloud-zone01/src/test/java/org/jclouds/bluelock/vcloud/zone01/BluelockVCloudZone01ProviderTest.java b/providers/bluelock-vcloud-zone01/src/test/java/org/jclouds/bluelock/vcloud/zone01/BluelockVCloudZone01ProviderTest.java index 589c13500e..6ff2a9c476 100644 --- a/providers/bluelock-vcloud-zone01/src/test/java/org/jclouds/bluelock/vcloud/zone01/BluelockVCloudZone01ProviderTest.java +++ b/providers/bluelock-vcloud-zone01/src/test/java/org/jclouds/bluelock/vcloud/zone01/BluelockVCloudZone01ProviderTest.java @@ -18,7 +18,7 @@ */ package org.jclouds.bluelock.vcloud.zone01; -import org.jclouds.providers.BaseProviderMetadataTest; +import org.jclouds.providers.internal.BaseProviderMetadataTest; import org.jclouds.vcloud.VCloudApiMetadata; import org.testng.annotations.Test; diff --git a/providers/bluelock-vcloud-zone01/src/test/java/org/jclouds/bluelock/vcloud/zone01/compute/BluelockVCloudZone01TemplateBuilderLiveTest.java b/providers/bluelock-vcloud-zone01/src/test/java/org/jclouds/bluelock/vcloud/zone01/compute/BluelockVCloudZone01TemplateBuilderLiveTest.java index f53ad7a320..ce95f91059 100644 --- a/providers/bluelock-vcloud-zone01/src/test/java/org/jclouds/bluelock/vcloud/zone01/compute/BluelockVCloudZone01TemplateBuilderLiveTest.java +++ b/providers/bluelock-vcloud-zone01/src/test/java/org/jclouds/bluelock/vcloud/zone01/compute/BluelockVCloudZone01TemplateBuilderLiveTest.java @@ -24,10 +24,13 @@ import static org.testng.Assert.assertEquals; import java.io.IOException; import java.util.Set; -import org.jclouds.compute.BaseTemplateBuilderLiveTest; +import org.jclouds.compute.ComputeServiceContext; import org.jclouds.compute.domain.OsFamily; import org.jclouds.compute.domain.OsFamilyVersion64Bit; import org.jclouds.compute.domain.Template; +import org.jclouds.compute.internal.BaseTemplateBuilderLiveTest; +import org.jclouds.vcloud.VCloudAsyncClient; +import org.jclouds.vcloud.VCloudClient; import org.testng.annotations.Test; import com.google.common.base.Predicate; @@ -38,7 +41,9 @@ import com.google.common.collect.ImmutableSet; * @author Adrian Cole */ @Test(groups = "live", testName = "BluelockVCloudZone01TemplateBuilderLiveTest") -public class BluelockVCloudZone01TemplateBuilderLiveTest extends BaseTemplateBuilderLiveTest { +public class BluelockVCloudZone01TemplateBuilderLiveTest + extends + BaseTemplateBuilderLiveTest> { public BluelockVCloudZone01TemplateBuilderLiveTest() { provider = "bluelock-vcloud-zone01"; @@ -51,14 +56,14 @@ public class BluelockVCloudZone01TemplateBuilderLiveTest extends BaseTemplateBui @Override public boolean apply(OsFamilyVersion64Bit input) { switch (input.family) { - case UBUNTU: - return !input.version.equals("") || !input.is64Bit; - case RHEL: - return !input.version.equals(""); - case WINDOWS: - return !input.version.equals(""); - default: - return true; + case UBUNTU: + return !input.version.equals("") || !input.is64Bit; + case RHEL: + return !input.version.equals(""); + case WINDOWS: + return !input.version.equals(""); + default: + return true; } } diff --git a/providers/cloudfiles-uk/pom.xml b/providers/cloudfiles-uk/pom.xml index bd14deabdf..d53054cffd 100644 --- a/providers/cloudfiles-uk/pom.xml +++ b/providers/cloudfiles-uk/pom.xml @@ -34,7 +34,6 @@ bundle - org.jclouds.rackspace.cloudfiles.blobstore.integration.CloudFilesUKTestInitializer https://lon.auth.api.rackspacecloud.com 1.0 @@ -114,7 +113,6 @@ ${test.cloudfiles-uk.build-version} ${test.cloudfiles-uk.identity} ${test.cloudfiles-uk.credential} - ${test.initializer} ${jclouds.blobstore.httpstream.url} ${jclouds.blobstore.httpstream.md5} diff --git a/providers/cloudfiles-uk/src/main/java/org/jclouds/rackspace/cloudfiles/CloudFilesUKPropertiesBuilder.java b/providers/cloudfiles-uk/src/main/java/org/jclouds/rackspace/cloudfiles/CloudFilesUKPropertiesBuilder.java deleted file mode 100644 index 8ca6198225..0000000000 --- a/providers/cloudfiles-uk/src/main/java/org/jclouds/rackspace/cloudfiles/CloudFilesUKPropertiesBuilder.java +++ /dev/null @@ -1,48 +0,0 @@ -/** - * 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.rackspace.cloudfiles; - -import static org.jclouds.Constants.PROPERTY_ENDPOINT; -import static org.jclouds.Constants.PROPERTY_ISO3166_CODES; -import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGIONS; - -import java.util.Properties; - -import org.jclouds.cloudfiles.CloudFilesPropertiesBuilder; - -/** - * - * @author Adrian Cole - */ -public class CloudFilesUKPropertiesBuilder extends CloudFilesPropertiesBuilder { - - @Override - protected Properties defaultProperties() { - Properties properties = super.defaultProperties(); - properties.setProperty(PROPERTY_REGIONS, "UK"); - properties.setProperty(PROPERTY_ENDPOINT, "https://lon.auth.api.rackspacecloud.com"); - properties.setProperty(PROPERTY_ISO3166_CODES, "GB-SLG"); - return properties; - } - - public CloudFilesUKPropertiesBuilder(Properties properties) { - super(properties); - } - -} diff --git a/providers/cloudfiles-uk/src/main/java/org/jclouds/rackspace/cloudfiles/CloudFilesUKProviderMetadata.java b/providers/cloudfiles-uk/src/main/java/org/jclouds/rackspace/cloudfiles/CloudFilesUKProviderMetadata.java index f50f10a9cc..53be4911e0 100644 --- a/providers/cloudfiles-uk/src/main/java/org/jclouds/rackspace/cloudfiles/CloudFilesUKProviderMetadata.java +++ b/providers/cloudfiles-uk/src/main/java/org/jclouds/rackspace/cloudfiles/CloudFilesUKProviderMetadata.java @@ -18,50 +18,70 @@ */ package org.jclouds.rackspace.cloudfiles; -import java.net.URI; +import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGIONS; +import java.net.URI; +import java.util.Properties; + +import org.jclouds.blobstore.BlobStoreContext; import org.jclouds.cloudfiles.CloudFilesApiMetadata; -import org.jclouds.providers.BaseProviderMetadata; +import org.jclouds.cloudfiles.CloudFilesAsyncClient; +import org.jclouds.cloudfiles.CloudFilesClient; +import org.jclouds.providers.ProviderMetadata; +import org.jclouds.providers.internal.BaseProviderMetadata; /** - * Implementation of {@link org.jclouds.types.ProviderMetadata} for Rackspace Cloud Files in UK. + * Implementation of {@link org.jclouds.types.ProviderMetadata} for Rackspace Cloud Files UK. * * @author Adrian Cole */ -public class CloudFilesUKProviderMetadata extends BaseProviderMetadata { - - public CloudFilesUKProviderMetadata() { - this(builder() - .id("cloudfiles-uk") - .name("Rackspace Cloud Files UK") - .api(new CloudFilesApiMetadata()) - .homepage(URI.create("http://www.rackspace.co.uk/cloud-hosting/cloud-products/cloud-files")) - .console(URI.create("https://lon.manage.rackspacecloud.com")) - .linkedServices("cloudfiles-uk", "cloudservers-uk", "cloudloadbalancers-uk") - .iso3166Codes("GB-SLG")); +public class CloudFilesUKProviderMetadata extends BaseProviderMetadata, CloudFilesApiMetadata> { + + public static Builder builder() { + return new Builder(); } - // below are so that we can reuse builders, toString, hashCode, etc. - // we have to set concrete classes here, as our base class cannot be - // concrete due to serviceLoader - protected CloudFilesUKProviderMetadata(ConcreteBuilder builder) { + @Override + public Builder toBuilder() { + return builder().fromProviderMetadata(this); + } + + public CloudFilesUKProviderMetadata() { + super(builder()); + } + + public CloudFilesUKProviderMetadata(Builder builder) { super(builder); } - private static class ConcreteBuilder extends Builder { + protected static Properties defaultProperties() { + Properties properties = new Properties(); + properties.setProperty(PROPERTY_REGIONS, "UK"); + return properties; + } + public static class Builder extends BaseProviderMetadata.Builder, CloudFilesApiMetadata> { + + protected Builder(){ + id("cloudfiles-uk") + .name("Rackspace Cloud Files UK") + .apiMetadata(new CloudFilesApiMetadata()) + .endpoint("https://lon.auth.api.rackspacecloud.com") + .homepage(URI.create("http://www.rackspace.co.uk/cloud-hosting/cloud-products/cloud-files")) + .console(URI.create("https://lon.manage.rackspacecloud.com")) + .linkedServices("cloudfiles-uk", "cloudservers-uk", "cloudloadbalancers-uk") + .iso3166Codes("GB-SLG"); + } @Override public CloudFilesUKProviderMetadata build() { return new CloudFilesUKProviderMetadata(this); } + + @Override + public Builder fromProviderMetadata( + ProviderMetadata, CloudFilesApiMetadata> in) { + super.fromProviderMetadata(in); + return this; + } } - - public static ConcreteBuilder builder() { - return new ConcreteBuilder(); - } - - public ConcreteBuilder toBuilder() { - return builder().fromProviderMetadata(this); - } - } \ No newline at end of file diff --git a/providers/cloudfiles-uk/src/test/java/org/jclouds/rackspace/cloudfiles/CloudFilesUKClientLiveTest.java b/providers/cloudfiles-uk/src/test/java/org/jclouds/rackspace/cloudfiles/CloudFilesUKClientLiveTest.java index 0772eb26fc..703c3a3d00 100644 --- a/providers/cloudfiles-uk/src/test/java/org/jclouds/rackspace/cloudfiles/CloudFilesUKClientLiveTest.java +++ b/providers/cloudfiles-uk/src/test/java/org/jclouds/rackspace/cloudfiles/CloudFilesUKClientLiveTest.java @@ -21,7 +21,7 @@ package org.jclouds.rackspace.cloudfiles; import static org.testng.Assert.assertEquals; import org.jclouds.cloudfiles.CloudFilesClient; -import org.jclouds.openstack.swift.CommonSwiftClientLiveTest; +import org.jclouds.cloudfiles.CloudFilesClientLiveTest; import org.jclouds.openstack.swift.domain.SwiftObject; import org.testng.annotations.Test; @@ -31,7 +31,11 @@ import org.testng.annotations.Test; * @author Adrian Cole */ @Test(groups = "live", singleThreaded = true, testName = "CloudFilesUKClientLiveTest") -public class CloudFilesUKClientLiveTest extends CommonSwiftClientLiveTest { +public class CloudFilesUKClientLiveTest extends CloudFilesClientLiveTest { + public CloudFilesUKClientLiveTest() { + provider = "cloudfiles-uk"; + } + // NOTE cloudfilesuk doesn't have cdn @Override diff --git a/providers/cloudfiles-uk/src/test/java/org/jclouds/rackspace/cloudfiles/CloudFilesUKProviderTest.java b/providers/cloudfiles-uk/src/test/java/org/jclouds/rackspace/cloudfiles/CloudFilesUKProviderTest.java index b8b2b83f11..f6ceef8a78 100644 --- a/providers/cloudfiles-uk/src/test/java/org/jclouds/rackspace/cloudfiles/CloudFilesUKProviderTest.java +++ b/providers/cloudfiles-uk/src/test/java/org/jclouds/rackspace/cloudfiles/CloudFilesUKProviderTest.java @@ -19,7 +19,7 @@ package org.jclouds.rackspace.cloudfiles; import org.jclouds.cloudfiles.CloudFilesApiMetadata; -import org.jclouds.providers.BaseProviderMetadataTest; +import org.jclouds.providers.internal.BaseProviderMetadataTest; import org.testng.annotations.Test; /** diff --git a/providers/cloudfiles-uk/src/test/java/org/jclouds/rackspace/cloudfiles/blobstore/integration/CloudFilesUKBlobIntegrationLiveTest.java b/providers/cloudfiles-uk/src/test/java/org/jclouds/rackspace/cloudfiles/blobstore/integration/CloudFilesUKBlobIntegrationLiveTest.java index a8f3004331..4a71ced142 100644 --- a/providers/cloudfiles-uk/src/test/java/org/jclouds/rackspace/cloudfiles/blobstore/integration/CloudFilesUKBlobIntegrationLiveTest.java +++ b/providers/cloudfiles-uk/src/test/java/org/jclouds/rackspace/cloudfiles/blobstore/integration/CloudFilesUKBlobIntegrationLiveTest.java @@ -26,6 +26,8 @@ import org.testng.annotations.Test; */ @Test(groups = "live", testName = "CloudFilesUKBlobIntegrationLiveTest") public class CloudFilesUKBlobIntegrationLiveTest extends CloudFilesBlobIntegrationLiveTest { - + public CloudFilesUKBlobIntegrationLiveTest() { + provider = "cloudfiles-uk"; + } } diff --git a/providers/cloudfiles-uk/src/test/java/org/jclouds/rackspace/cloudfiles/blobstore/integration/CloudFilesUKBlobLiveTest.java b/providers/cloudfiles-uk/src/test/java/org/jclouds/rackspace/cloudfiles/blobstore/integration/CloudFilesUKBlobLiveTest.java index e1ea7f06f2..3fdbf7f74c 100644 --- a/providers/cloudfiles-uk/src/test/java/org/jclouds/rackspace/cloudfiles/blobstore/integration/CloudFilesUKBlobLiveTest.java +++ b/providers/cloudfiles-uk/src/test/java/org/jclouds/rackspace/cloudfiles/blobstore/integration/CloudFilesUKBlobLiveTest.java @@ -26,5 +26,8 @@ import org.testng.annotations.Test; */ @Test(groups = "live", testName = "CloudFilesUKBlobLiveTest") public class CloudFilesUKBlobLiveTest extends CloudFilesBlobLiveTest { + public CloudFilesUKBlobLiveTest() { + provider = "cloudfiles-uk"; + } } diff --git a/providers/cloudfiles-uk/src/test/java/org/jclouds/rackspace/cloudfiles/blobstore/integration/CloudFilesUKBlobMapIntegrationLiveTest.java b/providers/cloudfiles-uk/src/test/java/org/jclouds/rackspace/cloudfiles/blobstore/integration/CloudFilesUKBlobMapIntegrationLiveTest.java index 22a106e789..baddc4135e 100644 --- a/providers/cloudfiles-uk/src/test/java/org/jclouds/rackspace/cloudfiles/blobstore/integration/CloudFilesUKBlobMapIntegrationLiveTest.java +++ b/providers/cloudfiles-uk/src/test/java/org/jclouds/rackspace/cloudfiles/blobstore/integration/CloudFilesUKBlobMapIntegrationLiveTest.java @@ -26,5 +26,8 @@ import org.testng.annotations.Test; */ @Test(groups = "live", testName = "CloudFilesUKBlobMapIntegrationLiveTest") public class CloudFilesUKBlobMapIntegrationLiveTest extends CloudFilesBlobMapIntegrationLiveTest { + public CloudFilesUKBlobMapIntegrationLiveTest() { + provider = "cloudfiles-uk"; + } } diff --git a/providers/cloudfiles-uk/src/test/java/org/jclouds/rackspace/cloudfiles/blobstore/integration/CloudFilesUKBlobSignerLiveTest.java b/providers/cloudfiles-uk/src/test/java/org/jclouds/rackspace/cloudfiles/blobstore/integration/CloudFilesUKBlobSignerLiveTest.java index 0334d52a8f..c1db27fcef 100644 --- a/providers/cloudfiles-uk/src/test/java/org/jclouds/rackspace/cloudfiles/blobstore/integration/CloudFilesUKBlobSignerLiveTest.java +++ b/providers/cloudfiles-uk/src/test/java/org/jclouds/rackspace/cloudfiles/blobstore/integration/CloudFilesUKBlobSignerLiveTest.java @@ -27,5 +27,8 @@ import org.testng.annotations.Test; */ @Test(groups = "live", testName = "CloudFilesUKBlobSignerLiveTest") public class CloudFilesUKBlobSignerLiveTest extends CloudFilesBlobSignerLiveTest { + public CloudFilesUKBlobSignerLiveTest() { + provider = "cloudfiles-uk"; + } } diff --git a/providers/cloudfiles-uk/src/test/java/org/jclouds/rackspace/cloudfiles/blobstore/integration/CloudFilesUKContainerIntegrationLiveTest.java b/providers/cloudfiles-uk/src/test/java/org/jclouds/rackspace/cloudfiles/blobstore/integration/CloudFilesUKContainerIntegrationLiveTest.java index 34c40ca166..5a86298313 100644 --- a/providers/cloudfiles-uk/src/test/java/org/jclouds/rackspace/cloudfiles/blobstore/integration/CloudFilesUKContainerIntegrationLiveTest.java +++ b/providers/cloudfiles-uk/src/test/java/org/jclouds/rackspace/cloudfiles/blobstore/integration/CloudFilesUKContainerIntegrationLiveTest.java @@ -26,5 +26,8 @@ import org.testng.annotations.Test; */ @Test(groups = "live", testName = "CloudFilesUKContainerIntegrationLiveTest") public class CloudFilesUKContainerIntegrationLiveTest extends CloudFilesContainerIntegrationLiveTest { + public CloudFilesUKContainerIntegrationLiveTest() { + provider = "cloudfiles-uk"; + } } diff --git a/providers/cloudfiles-uk/src/test/java/org/jclouds/rackspace/cloudfiles/blobstore/integration/CloudFilesUKContainerLiveTest.java b/providers/cloudfiles-uk/src/test/java/org/jclouds/rackspace/cloudfiles/blobstore/integration/CloudFilesUKContainerLiveTest.java index e6be46a521..be4b310fac 100644 --- a/providers/cloudfiles-uk/src/test/java/org/jclouds/rackspace/cloudfiles/blobstore/integration/CloudFilesUKContainerLiveTest.java +++ b/providers/cloudfiles-uk/src/test/java/org/jclouds/rackspace/cloudfiles/blobstore/integration/CloudFilesUKContainerLiveTest.java @@ -26,5 +26,8 @@ import org.testng.annotations.Test; */ @Test(groups = "live", testName = "CloudFilesUKContainerLiveTest") public class CloudFilesUKContainerLiveTest extends CloudFilesContainerLiveTest { + public CloudFilesUKContainerLiveTest() { + provider = "cloudfiles-uk"; + } } diff --git a/providers/cloudfiles-uk/src/test/java/org/jclouds/rackspace/cloudfiles/blobstore/integration/CloudFilesUKInputStreamMapIntegrationLiveTest.java b/providers/cloudfiles-uk/src/test/java/org/jclouds/rackspace/cloudfiles/blobstore/integration/CloudFilesUKInputStreamMapIntegrationLiveTest.java index 2991ed8983..cd559bcbf9 100644 --- a/providers/cloudfiles-uk/src/test/java/org/jclouds/rackspace/cloudfiles/blobstore/integration/CloudFilesUKInputStreamMapIntegrationLiveTest.java +++ b/providers/cloudfiles-uk/src/test/java/org/jclouds/rackspace/cloudfiles/blobstore/integration/CloudFilesUKInputStreamMapIntegrationLiveTest.java @@ -26,5 +26,8 @@ import org.testng.annotations.Test; */ @Test(groups = "live", testName = "CloudFilesUKInputStreamMapIntegrationLiveTest") public class CloudFilesUKInputStreamMapIntegrationLiveTest extends CloudFilesInputStreamMapIntegrationLiveTest { + public CloudFilesUKInputStreamMapIntegrationLiveTest() { + provider = "cloudfiles-uk"; + } } diff --git a/providers/cloudfiles-uk/src/test/java/org/jclouds/rackspace/cloudfiles/blobstore/integration/CloudFilesUKServiceIntegrationLiveTest.java b/providers/cloudfiles-uk/src/test/java/org/jclouds/rackspace/cloudfiles/blobstore/integration/CloudFilesUKServiceIntegrationLiveTest.java index bf0f7fcab7..2d2246f71f 100644 --- a/providers/cloudfiles-uk/src/test/java/org/jclouds/rackspace/cloudfiles/blobstore/integration/CloudFilesUKServiceIntegrationLiveTest.java +++ b/providers/cloudfiles-uk/src/test/java/org/jclouds/rackspace/cloudfiles/blobstore/integration/CloudFilesUKServiceIntegrationLiveTest.java @@ -30,6 +30,10 @@ import com.google.common.collect.ImmutableSet; */ @Test(groups = "live", testName = "CloudFilesUKServiceIntegrationLiveTest") public class CloudFilesUKServiceIntegrationLiveTest extends CloudFilesServiceIntegrationLiveTest { + public CloudFilesUKServiceIntegrationLiveTest() { + provider = "cloudfiles-uk"; + } + @Override protected Set getIso3166Codes() { return ImmutableSet. of("GB-SLG"); diff --git a/providers/cloudfiles-uk/src/test/java/org/jclouds/rackspace/cloudfiles/blobstore/integration/CloudFilesUKTestInitializer.java b/providers/cloudfiles-uk/src/test/java/org/jclouds/rackspace/cloudfiles/blobstore/integration/CloudFilesUKTestInitializer.java deleted file mode 100644 index 7f0747519f..0000000000 --- a/providers/cloudfiles-uk/src/test/java/org/jclouds/rackspace/cloudfiles/blobstore/integration/CloudFilesUKTestInitializer.java +++ /dev/null @@ -1,32 +0,0 @@ -/** - * 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.rackspace.cloudfiles.blobstore.integration; - -import org.jclouds.cloudfiles.blobstore.integration.CloudFilesTestInitializer; - -/** - * - * @author Adrian Cole - */ -public class CloudFilesUKTestInitializer extends CloudFilesTestInitializer { - - public CloudFilesUKTestInitializer() { - provider = "cloudfiles-uk"; - } -} diff --git a/providers/cloudfiles-us/src/main/java/org/jclouds/rackspace/cloudfiles/CloudFilesUSPropertiesBuilder.java b/providers/cloudfiles-us/src/main/java/org/jclouds/rackspace/cloudfiles/CloudFilesUSPropertiesBuilder.java deleted file mode 100644 index fff5bc1d09..0000000000 --- a/providers/cloudfiles-us/src/main/java/org/jclouds/rackspace/cloudfiles/CloudFilesUSPropertiesBuilder.java +++ /dev/null @@ -1,48 +0,0 @@ -/** - * 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.rackspace.cloudfiles; - -import static org.jclouds.Constants.PROPERTY_ENDPOINT; -import static org.jclouds.Constants.PROPERTY_ISO3166_CODES; -import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGIONS; - -import java.util.Properties; - -import org.jclouds.cloudfiles.CloudFilesPropertiesBuilder; - -/** - * - * @author Adrian Cole - */ -public class CloudFilesUSPropertiesBuilder extends CloudFilesPropertiesBuilder { - - @Override - protected Properties defaultProperties() { - Properties properties = super.defaultProperties(); - properties.setProperty(PROPERTY_REGIONS, "US"); - properties.setProperty(PROPERTY_ENDPOINT, "https://auth.api.rackspacecloud.com"); - properties.setProperty(PROPERTY_ISO3166_CODES, "US-IL,US-TX"); - return properties; - } - - public CloudFilesUSPropertiesBuilder(Properties properties) { - super(properties); - } - -} diff --git a/providers/cloudfiles-us/src/main/java/org/jclouds/rackspace/cloudfiles/CloudFilesUSProviderMetadata.java b/providers/cloudfiles-us/src/main/java/org/jclouds/rackspace/cloudfiles/CloudFilesUSProviderMetadata.java index c30dad5cdb..2b5c581e9a 100644 --- a/providers/cloudfiles-us/src/main/java/org/jclouds/rackspace/cloudfiles/CloudFilesUSProviderMetadata.java +++ b/providers/cloudfiles-us/src/main/java/org/jclouds/rackspace/cloudfiles/CloudFilesUSProviderMetadata.java @@ -18,50 +18,71 @@ */ package org.jclouds.rackspace.cloudfiles; +import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGIONS; + import java.net.URI; +import java.util.Properties; +import org.jclouds.blobstore.BlobStoreContext; import org.jclouds.cloudfiles.CloudFilesApiMetadata; -import org.jclouds.providers.BaseProviderMetadata; - +import org.jclouds.cloudfiles.CloudFilesAsyncClient; +import org.jclouds.cloudfiles.CloudFilesClient; +import org.jclouds.providers.ProviderMetadata; +import org.jclouds.providers.internal.BaseProviderMetadata; /** - * Implementation of {@link org.jclouds.types.ProviderMetadata} for Rackspace Cloud Files in US. + * Implementation of {@link org.jclouds.types.ProviderMetadata} for Rackspace Cloud Files US. * * @author Adrian Cole */ -public class CloudFilesUSProviderMetadata extends BaseProviderMetadata { - - public CloudFilesUSProviderMetadata() { - this(builder() - .id("cloudfiles-us") - .name("Rackspace Cloud Files US") - .api(new CloudFilesApiMetadata()) - .homepage(URI.create("http://www.rackspace.com/cloud/cloud_hosting_products/files")) - .console(URI.create("https://manage.rackspacecloud.com")) - .linkedServices("cloudfiles-us", "cloudservers-us", "cloudloadbalancers-us") - .iso3166Codes("US-IL","US-TX")); +public class CloudFilesUSProviderMetadata extends BaseProviderMetadata, CloudFilesApiMetadata> { + + public static Builder builder() { + return new Builder(); } - // below are so that we can reuse builders, toString, hashCode, etc. - // we have to set concrete classes here, as our base class cannot be - // concrete due to serviceLoader - protected CloudFilesUSProviderMetadata(ConcreteBuilder builder) { + @Override + public Builder toBuilder() { + return builder().fromProviderMetadata(this); + } + + public CloudFilesUSProviderMetadata() { + super(builder()); + } + + public CloudFilesUSProviderMetadata(Builder builder) { super(builder); } - private static class ConcreteBuilder extends Builder { + protected static Properties defaultProperties() { + Properties properties = new Properties(); + properties.setProperty(PROPERTY_REGIONS, "US"); + return properties; + } + + public static class Builder extends BaseProviderMetadata.Builder, CloudFilesApiMetadata> { + + protected Builder(){ + id("cloudfiles-us") + .name("Rackspace Cloud Files US") + .apiMetadata(new CloudFilesApiMetadata()) + .endpoint("https://auth.api.rackspacecloud.com") + .homepage(URI.create("http://www.rackspace.com/cloud/cloud_hosting_products/files")) + .console(URI.create("https://manage.rackspacecloud.com")) + .linkedServices("cloudfiles-us", "cloudservers-us", "cloudloadbalancers-us") + .iso3166Codes("US-IL","US-TX"); + } @Override public CloudFilesUSProviderMetadata build() { return new CloudFilesUSProviderMetadata(this); } - } - - public static ConcreteBuilder builder() { - return new ConcreteBuilder(); - } - - public ConcreteBuilder toBuilder() { - return builder().fromProviderMetadata(this); + + @Override + public Builder fromProviderMetadata( + ProviderMetadata, CloudFilesApiMetadata> in) { + super.fromProviderMetadata(in); + return this; + } } } \ No newline at end of file diff --git a/providers/cloudfiles-us/src/test/java/org/jclouds/rackspace/cloudfiles/CloudFilesUSClientLiveTest.java b/providers/cloudfiles-us/src/test/java/org/jclouds/rackspace/cloudfiles/CloudFilesUSClientLiveTest.java index 30cff58d55..165deaf1d4 100644 --- a/providers/cloudfiles-us/src/test/java/org/jclouds/rackspace/cloudfiles/CloudFilesUSClientLiveTest.java +++ b/providers/cloudfiles-us/src/test/java/org/jclouds/rackspace/cloudfiles/CloudFilesUSClientLiveTest.java @@ -28,5 +28,7 @@ import org.testng.annotations.Test; */ @Test(groups = "live", sequential = true, testName = "CloudFilesUSClientLiveTest") public class CloudFilesUSClientLiveTest extends CloudFilesClientLiveTest { - + public CloudFilesUSClientLiveTest() { + provider = "cloudfiles-us"; + } } diff --git a/providers/cloudfiles-us/src/test/java/org/jclouds/rackspace/cloudfiles/CloudFilesUSProviderTest.java b/providers/cloudfiles-us/src/test/java/org/jclouds/rackspace/cloudfiles/CloudFilesUSProviderTest.java index 54c8da6584..3d4b976ff1 100644 --- a/providers/cloudfiles-us/src/test/java/org/jclouds/rackspace/cloudfiles/CloudFilesUSProviderTest.java +++ b/providers/cloudfiles-us/src/test/java/org/jclouds/rackspace/cloudfiles/CloudFilesUSProviderTest.java @@ -19,7 +19,7 @@ package org.jclouds.rackspace.cloudfiles; import org.jclouds.cloudfiles.CloudFilesApiMetadata; -import org.jclouds.providers.BaseProviderMetadataTest; +import org.jclouds.providers.internal.BaseProviderMetadataTest; import org.testng.annotations.Test; /** diff --git a/providers/cloudfiles-us/src/test/java/org/jclouds/rackspace/cloudfiles/blobstore/integration/CloudFilesUSBlobIntegrationLiveTest.java b/providers/cloudfiles-us/src/test/java/org/jclouds/rackspace/cloudfiles/blobstore/integration/CloudFilesUSBlobIntegrationLiveTest.java index 7f1655b522..f7c7b02c45 100644 --- a/providers/cloudfiles-us/src/test/java/org/jclouds/rackspace/cloudfiles/blobstore/integration/CloudFilesUSBlobIntegrationLiveTest.java +++ b/providers/cloudfiles-us/src/test/java/org/jclouds/rackspace/cloudfiles/blobstore/integration/CloudFilesUSBlobIntegrationLiveTest.java @@ -26,6 +26,7 @@ import org.testng.annotations.Test; */ @Test(groups = "live", testName = "CloudFilesUSBlobIntegrationLiveTest") public class CloudFilesUSBlobIntegrationLiveTest extends CloudFilesBlobIntegrationLiveTest { - - + public CloudFilesUSBlobIntegrationLiveTest() { + provider = "cloudfiles-us"; + } } diff --git a/providers/cloudfiles-us/src/test/java/org/jclouds/rackspace/cloudfiles/blobstore/integration/CloudFilesUSBlobLiveTest.java b/providers/cloudfiles-us/src/test/java/org/jclouds/rackspace/cloudfiles/blobstore/integration/CloudFilesUSBlobLiveTest.java index 8b5320ce07..1852d8feb4 100644 --- a/providers/cloudfiles-us/src/test/java/org/jclouds/rackspace/cloudfiles/blobstore/integration/CloudFilesUSBlobLiveTest.java +++ b/providers/cloudfiles-us/src/test/java/org/jclouds/rackspace/cloudfiles/blobstore/integration/CloudFilesUSBlobLiveTest.java @@ -26,5 +26,7 @@ import org.testng.annotations.Test; */ @Test(groups = "live", testName = "CloudFilesUSBlobLiveTest") public class CloudFilesUSBlobLiveTest extends CloudFilesBlobLiveTest { - + public CloudFilesUSBlobLiveTest() { + provider = "cloudfiles-us"; + } } diff --git a/providers/cloudfiles-us/src/test/java/org/jclouds/rackspace/cloudfiles/blobstore/integration/CloudFilesUSBlobMapIntegrationLiveTest.java b/providers/cloudfiles-us/src/test/java/org/jclouds/rackspace/cloudfiles/blobstore/integration/CloudFilesUSBlobMapIntegrationLiveTest.java index c5e41d195f..eecc7b0703 100644 --- a/providers/cloudfiles-us/src/test/java/org/jclouds/rackspace/cloudfiles/blobstore/integration/CloudFilesUSBlobMapIntegrationLiveTest.java +++ b/providers/cloudfiles-us/src/test/java/org/jclouds/rackspace/cloudfiles/blobstore/integration/CloudFilesUSBlobMapIntegrationLiveTest.java @@ -26,5 +26,7 @@ import org.testng.annotations.Test; */ @Test(groups = "live", testName = "CloudFilesUSBlobMapIntegrationLiveTest") public class CloudFilesUSBlobMapIntegrationLiveTest extends CloudFilesBlobMapIntegrationLiveTest { - + public CloudFilesUSBlobMapIntegrationLiveTest() { + provider = "cloudfiles-us"; + } } diff --git a/providers/cloudfiles-us/src/test/java/org/jclouds/rackspace/cloudfiles/blobstore/integration/CloudFilesUSBlobSignerLiveTest.java b/providers/cloudfiles-us/src/test/java/org/jclouds/rackspace/cloudfiles/blobstore/integration/CloudFilesUSBlobSignerLiveTest.java index 8e20eb85bb..1122d5ca58 100644 --- a/providers/cloudfiles-us/src/test/java/org/jclouds/rackspace/cloudfiles/blobstore/integration/CloudFilesUSBlobSignerLiveTest.java +++ b/providers/cloudfiles-us/src/test/java/org/jclouds/rackspace/cloudfiles/blobstore/integration/CloudFilesUSBlobSignerLiveTest.java @@ -27,5 +27,7 @@ import org.testng.annotations.Test; */ @Test(groups = "live", testName = "CloudFilesUSBlobSignerLiveTest") public class CloudFilesUSBlobSignerLiveTest extends CloudFilesBlobSignerLiveTest { - + public CloudFilesUSBlobSignerLiveTest() { + provider = "cloudfiles-us"; + } } diff --git a/providers/cloudfiles-us/src/test/java/org/jclouds/rackspace/cloudfiles/blobstore/integration/CloudFilesUSContainerIntegrationLiveTest.java b/providers/cloudfiles-us/src/test/java/org/jclouds/rackspace/cloudfiles/blobstore/integration/CloudFilesUSContainerIntegrationLiveTest.java index aab3274f63..86658faf92 100644 --- a/providers/cloudfiles-us/src/test/java/org/jclouds/rackspace/cloudfiles/blobstore/integration/CloudFilesUSContainerIntegrationLiveTest.java +++ b/providers/cloudfiles-us/src/test/java/org/jclouds/rackspace/cloudfiles/blobstore/integration/CloudFilesUSContainerIntegrationLiveTest.java @@ -26,5 +26,7 @@ import org.testng.annotations.Test; */ @Test(groups = "live", testName = "CloudFilesUSContainerIntegrationLiveTest") public class CloudFilesUSContainerIntegrationLiveTest extends CloudFilesContainerIntegrationLiveTest { - + public CloudFilesUSContainerIntegrationLiveTest() { + provider = "cloudfiles-us"; + } } diff --git a/providers/cloudfiles-us/src/test/java/org/jclouds/rackspace/cloudfiles/blobstore/integration/CloudFilesUSContainerLiveTest.java b/providers/cloudfiles-us/src/test/java/org/jclouds/rackspace/cloudfiles/blobstore/integration/CloudFilesUSContainerLiveTest.java index 16e72e0ac6..2d003cceb5 100644 --- a/providers/cloudfiles-us/src/test/java/org/jclouds/rackspace/cloudfiles/blobstore/integration/CloudFilesUSContainerLiveTest.java +++ b/providers/cloudfiles-us/src/test/java/org/jclouds/rackspace/cloudfiles/blobstore/integration/CloudFilesUSContainerLiveTest.java @@ -26,5 +26,7 @@ import org.testng.annotations.Test; */ @Test(groups = "live", testName = "CloudFilesUSContainerLiveTest") public class CloudFilesUSContainerLiveTest extends CloudFilesContainerLiveTest { - + public CloudFilesUSContainerLiveTest() { + provider = "cloudfiles-us"; + } } diff --git a/providers/cloudfiles-us/src/test/java/org/jclouds/rackspace/cloudfiles/blobstore/integration/CloudFilesUSInputStreamMapIntegrationLiveTest.java b/providers/cloudfiles-us/src/test/java/org/jclouds/rackspace/cloudfiles/blobstore/integration/CloudFilesUSInputStreamMapIntegrationLiveTest.java index c816f1eb3c..c982cb2890 100644 --- a/providers/cloudfiles-us/src/test/java/org/jclouds/rackspace/cloudfiles/blobstore/integration/CloudFilesUSInputStreamMapIntegrationLiveTest.java +++ b/providers/cloudfiles-us/src/test/java/org/jclouds/rackspace/cloudfiles/blobstore/integration/CloudFilesUSInputStreamMapIntegrationLiveTest.java @@ -26,5 +26,7 @@ import org.testng.annotations.Test; */ @Test(groups = "live", testName = "CloudFilesUSInputStreamMapIntegrationLiveTest") public class CloudFilesUSInputStreamMapIntegrationLiveTest extends CloudFilesInputStreamMapIntegrationLiveTest { - + public CloudFilesUSInputStreamMapIntegrationLiveTest() { + provider = "cloudfiles-us"; + } } diff --git a/providers/cloudfiles-us/src/test/java/org/jclouds/rackspace/cloudfiles/blobstore/integration/CloudFilesUSServiceIntegrationLiveTest.java b/providers/cloudfiles-us/src/test/java/org/jclouds/rackspace/cloudfiles/blobstore/integration/CloudFilesUSServiceIntegrationLiveTest.java index 0165ed8a51..3dfed3356f 100644 --- a/providers/cloudfiles-us/src/test/java/org/jclouds/rackspace/cloudfiles/blobstore/integration/CloudFilesUSServiceIntegrationLiveTest.java +++ b/providers/cloudfiles-us/src/test/java/org/jclouds/rackspace/cloudfiles/blobstore/integration/CloudFilesUSServiceIntegrationLiveTest.java @@ -30,6 +30,9 @@ import com.google.common.collect.ImmutableSet; */ @Test(groups = "live", testName = "CloudFilesUSServiceIntegrationLiveTest") public class CloudFilesUSServiceIntegrationLiveTest extends CloudFilesServiceIntegrationLiveTest { + public CloudFilesUSServiceIntegrationLiveTest() { + provider = "cloudfiles-us"; + } @Override protected Set getIso3166Codes() { return ImmutableSet. of("US-IL", "US-TX"); diff --git a/providers/cloudfiles-us/src/test/java/org/jclouds/rackspace/cloudfiles/blobstore/integration/CloudFilesUSTestInitializer.java b/providers/cloudfiles-us/src/test/java/org/jclouds/rackspace/cloudfiles/blobstore/integration/CloudFilesUSTestInitializer.java deleted file mode 100644 index a9d667830d..0000000000 --- a/providers/cloudfiles-us/src/test/java/org/jclouds/rackspace/cloudfiles/blobstore/integration/CloudFilesUSTestInitializer.java +++ /dev/null @@ -1,32 +0,0 @@ -/** - * 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.rackspace.cloudfiles.blobstore.integration; - -import org.jclouds.cloudfiles.blobstore.integration.CloudFilesTestInitializer; - -/** - * - * @author Adrian Cole - */ -public class CloudFilesUSTestInitializer extends CloudFilesTestInitializer { - - public CloudFilesUSTestInitializer() { - provider = "cloudfiles-us"; - } -} diff --git a/providers/cloudloadbalancers-uk/src/main/java/org/jclouds/rackspace/cloudloadbalancers/CloudLoadBalancersUKPropertiesBuilder.java b/providers/cloudloadbalancers-uk/src/main/java/org/jclouds/rackspace/cloudloadbalancers/CloudLoadBalancersUKPropertiesBuilder.java deleted file mode 100644 index f40db05837..0000000000 --- a/providers/cloudloadbalancers-uk/src/main/java/org/jclouds/rackspace/cloudloadbalancers/CloudLoadBalancersUKPropertiesBuilder.java +++ /dev/null @@ -1,62 +0,0 @@ -/** - * 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.rackspace.cloudloadbalancers; - -import static org.jclouds.Constants.PROPERTY_API_VERSION; -import static org.jclouds.Constants.PROPERTY_ENDPOINT; -import static org.jclouds.Constants.PROPERTY_ISO3166_CODES; -import static org.jclouds.cloudloadbalancers.reference.Region.LON; -import static org.jclouds.location.reference.LocationConstants.ENDPOINT; -import static org.jclouds.location.reference.LocationConstants.ISO3166_CODES; -import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGION; -import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGIONS; - -import java.util.Properties; - -import org.jclouds.cloudloadbalancers.CloudLoadBalancersPropertiesBuilder; - -import com.google.common.base.Joiner; - -/** - * Builds properties used inRackspace Cloud Load Balancers Clients - * - * @author Dan Lo Bianco - */ -public class CloudLoadBalancersUKPropertiesBuilder extends CloudLoadBalancersPropertiesBuilder { - public static final String[] REGIONS = {LON}; - - @Override - protected Properties defaultProperties() { - Properties properties = super.defaultProperties(); - properties.setProperty(PROPERTY_REGIONS, Joiner.on(',').join(REGIONS)); - properties.setProperty(PROPERTY_ENDPOINT, "https://lon.auth.api.rackspacecloud.com"); - properties.setProperty(PROPERTY_ISO3166_CODES, "GB-SLG"); - - properties.setProperty(PROPERTY_REGION + "." + LON + "." + ISO3166_CODES, "GB-SLG"); - properties.setProperty(PROPERTY_REGION + "." + LON + "." + ENDPOINT, - String.format("https://lon.loadbalancers.api.rackspacecloud.com/v${%s}", PROPERTY_API_VERSION)); - - return properties; - } - - public CloudLoadBalancersUKPropertiesBuilder(Properties properties) { - super(properties); - } - -} diff --git a/providers/cloudloadbalancers-uk/src/main/java/org/jclouds/rackspace/cloudloadbalancers/CloudLoadBalancersUKProviderMetadata.java b/providers/cloudloadbalancers-uk/src/main/java/org/jclouds/rackspace/cloudloadbalancers/CloudLoadBalancersUKProviderMetadata.java index 6069979007..f211ad45c8 100644 --- a/providers/cloudloadbalancers-uk/src/main/java/org/jclouds/rackspace/cloudloadbalancers/CloudLoadBalancersUKProviderMetadata.java +++ b/providers/cloudloadbalancers-uk/src/main/java/org/jclouds/rackspace/cloudloadbalancers/CloudLoadBalancersUKProviderMetadata.java @@ -18,49 +18,82 @@ */ package org.jclouds.rackspace.cloudloadbalancers; +import static org.jclouds.Constants.PROPERTY_API_VERSION; +import static org.jclouds.Constants.PROPERTY_ENDPOINT; +import static org.jclouds.Constants.PROPERTY_ISO3166_CODES; +import static org.jclouds.cloudloadbalancers.reference.Region.LON; +import static org.jclouds.location.reference.LocationConstants.ENDPOINT; +import static org.jclouds.location.reference.LocationConstants.ISO3166_CODES; +import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGION; +import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGIONS; + import java.net.URI; +import java.util.Properties; import org.jclouds.cloudloadbalancers.CloudLoadBalancersApiMetadata; -import org.jclouds.providers.BaseProviderMetadata; +import org.jclouds.cloudloadbalancers.CloudLoadBalancersAsyncClient; +import org.jclouds.cloudloadbalancers.CloudLoadBalancersClient; +import org.jclouds.loadbalancer.LoadBalancerServiceContext; +import org.jclouds.providers.ProviderMetadata; +import org.jclouds.providers.internal.BaseProviderMetadata; /** - * Implementation of {@link org.jclouds.types.ProviderMetadata} for Rackspace Cloud LoadBalancers in UK. + * Implementation of {@link org.jclouds.types.ProviderMetadata} for Rackspace Cloud LoadBalancers UK. * - * @author Dan Lo Bianco + * @author Adrian Cole */ -public class CloudLoadBalancersUKProviderMetadata extends BaseProviderMetadata { - - public CloudLoadBalancersUKProviderMetadata() { - this(builder() - .id("cloudloadbalancers-uk") - .name("Rackspace Cloud Load Balancers UK") - .api(new CloudLoadBalancersApiMetadata()) - .homepage(URI.create("http://www.rackspace.co.uk/cloud-hosting/cloud-products/cloud-load-balancers")) - .console(URI.create("https://lon.manage.rackspacecloud.com")) - .linkedServices("cloudloadbalancers-uk", "cloudservers-uk", "cloudfiles-uk") - .iso3166Codes("GB-SLG")); +public class CloudLoadBalancersUKProviderMetadata extends BaseProviderMetadata, CloudLoadBalancersApiMetadata> { + + public static Builder builder() { + return new Builder(); } - // below are so that we can reuse builders, toString, hashCode, etc. - // we have to set concrete classes here, as our base class cannot be - // concrete due to serviceLoader - protected CloudLoadBalancersUKProviderMetadata(ConcreteBuilder builder) { + @Override + public Builder toBuilder() { + return builder().fromProviderMetadata(this); + } + + public CloudLoadBalancersUKProviderMetadata() { + super(builder()); + } + + public CloudLoadBalancersUKProviderMetadata(Builder builder) { super(builder); } - private static class ConcreteBuilder extends Builder { + protected static Properties defaultProperties() { + Properties properties = new Properties(); + properties.setProperty(PROPERTY_REGIONS, LON); + properties.setProperty(PROPERTY_ENDPOINT, "https://lon.auth.api.rackspacecloud.com"); + properties.setProperty(PROPERTY_ISO3166_CODES, "GB-SLG"); + properties.setProperty(PROPERTY_REGION + "." + LON + "." + ISO3166_CODES, "GB-SLG"); + properties.setProperty(PROPERTY_REGION + "." + LON + "." + ENDPOINT, + String.format("https://lon.loadbalancers.api.rackspacecloud.com/v${%s}", PROPERTY_API_VERSION)); + return properties; + } + public static class Builder extends BaseProviderMetadata.Builder, CloudLoadBalancersApiMetadata> { + + protected Builder(){ + id("cloudloadbalancers-uk") + .name("Rackspace Cloud Load Balancers UK") + .apiMetadata(new CloudLoadBalancersApiMetadata()) + .homepage(URI.create("http://www.rackspace.co.uk/cloud-hosting/cloud-products/cloud-load-balancers")) + .console(URI.create("https://lon.manage.rackspacecloud.com")) + .linkedServices("cloudloadbalancers-uk", "cloudservers-uk", "cloudfiles-uk") + .iso3166Codes("GB-SLG") + .endpoint("https://lon.auth.api.rackspacecloud.com"); + } @Override public CloudLoadBalancersUKProviderMetadata build() { return new CloudLoadBalancersUKProviderMetadata(this); } - } - - public static ConcreteBuilder builder() { - return new ConcreteBuilder(); - } - - public ConcreteBuilder toBuilder() { - return builder().fromProviderMetadata(this); + + @Override + public Builder fromProviderMetadata( + ProviderMetadata, CloudLoadBalancersApiMetadata> in) { + super.fromProviderMetadata(in); + return this; + } } } \ No newline at end of file diff --git a/providers/cloudloadbalancers-uk/src/test/java/org/jclouds/rackspace/cloudloadbalancers/CloudLoadBalancersUKLoadBalancerClientLiveTest.java b/providers/cloudloadbalancers-uk/src/test/java/org/jclouds/rackspace/cloudloadbalancers/CloudLoadBalancersUKLoadBalancerClientLiveTest.java index 3ef8cfc4f6..8f2f6d2892 100644 --- a/providers/cloudloadbalancers-uk/src/test/java/org/jclouds/rackspace/cloudloadbalancers/CloudLoadBalancersUKLoadBalancerClientLiveTest.java +++ b/providers/cloudloadbalancers-uk/src/test/java/org/jclouds/rackspace/cloudloadbalancers/CloudLoadBalancersUKLoadBalancerClientLiveTest.java @@ -29,6 +29,6 @@ import org.testng.annotations.Test; public class CloudLoadBalancersUKLoadBalancerClientLiveTest extends LoadBalancerClientLiveTest { public CloudLoadBalancersUKLoadBalancerClientLiveTest() { provider = "cloudloadbalancers-uk"; - regions = CloudLoadBalancersUKPropertiesBuilder.REGIONS; + regions = new String[] { "LON" }; } } diff --git a/providers/cloudloadbalancers-uk/src/test/java/org/jclouds/rackspace/cloudloadbalancers/CloudLoadBalancersUKProviderTest.java b/providers/cloudloadbalancers-uk/src/test/java/org/jclouds/rackspace/cloudloadbalancers/CloudLoadBalancersUKProviderTest.java index ec189cfdd6..74a50dd55f 100644 --- a/providers/cloudloadbalancers-uk/src/test/java/org/jclouds/rackspace/cloudloadbalancers/CloudLoadBalancersUKProviderTest.java +++ b/providers/cloudloadbalancers-uk/src/test/java/org/jclouds/rackspace/cloudloadbalancers/CloudLoadBalancersUKProviderTest.java @@ -19,7 +19,7 @@ package org.jclouds.rackspace.cloudloadbalancers; import org.jclouds.cloudloadbalancers.CloudLoadBalancersApiMetadata; -import org.jclouds.providers.BaseProviderMetadataTest; +import org.jclouds.providers.internal.BaseProviderMetadataTest; import org.testng.annotations.Test; /** diff --git a/providers/cloudloadbalancers-us/src/main/java/org/jclouds/rackspace/cloudloadbalancers/CloudLoadBalancersUSPropertiesBuilder.java b/providers/cloudloadbalancers-us/src/main/java/org/jclouds/rackspace/cloudloadbalancers/CloudLoadBalancersUSPropertiesBuilder.java deleted file mode 100644 index 50e8e35515..0000000000 --- a/providers/cloudloadbalancers-us/src/main/java/org/jclouds/rackspace/cloudloadbalancers/CloudLoadBalancersUSPropertiesBuilder.java +++ /dev/null @@ -1,66 +0,0 @@ -/** - * 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.rackspace.cloudloadbalancers; - -import static org.jclouds.Constants.PROPERTY_API_VERSION; -import static org.jclouds.Constants.PROPERTY_ENDPOINT; -import static org.jclouds.Constants.PROPERTY_ISO3166_CODES; -import static org.jclouds.cloudloadbalancers.reference.Region.DFW; -import static org.jclouds.cloudloadbalancers.reference.Region.ORD; -import static org.jclouds.location.reference.LocationConstants.ENDPOINT; -import static org.jclouds.location.reference.LocationConstants.ISO3166_CODES; -import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGION; -import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGIONS; - -import java.util.Properties; - -import org.jclouds.cloudloadbalancers.CloudLoadBalancersPropertiesBuilder; - -import com.google.common.base.Joiner; - -/** - * Builds properties used inRackspace Cloud Load Balancers Clients - * - * @author Adrian Cole - */ -public class CloudLoadBalancersUSPropertiesBuilder extends CloudLoadBalancersPropertiesBuilder { - public static final String[] REGIONS = {ORD, DFW}; - - @Override - protected Properties defaultProperties() { - Properties properties = super.defaultProperties(); - properties.setProperty(PROPERTY_ENDPOINT, "https://auth.api.rackspacecloud.com"); - properties.setProperty(PROPERTY_REGIONS, Joiner.on(',').join(REGIONS)); - properties.setProperty(PROPERTY_ISO3166_CODES, "US-IL,US-TX"); - - properties.setProperty(PROPERTY_REGION + "." + ORD + "." + ISO3166_CODES, "US-IL"); - properties.setProperty(PROPERTY_REGION + "." + ORD + "." + ENDPOINT, String - .format("https://ord.loadbalancers.api.rackspacecloud.com/v${%s}", PROPERTY_API_VERSION)); - - properties.setProperty(PROPERTY_REGION + "." + DFW + "." + ISO3166_CODES, "US-TX"); - properties.setProperty(PROPERTY_REGION + "." + DFW + "." + ENDPOINT, String - .format("https://dfw.loadbalancers.api.rackspacecloud.com/v${%s}", PROPERTY_API_VERSION)); - return properties; - } - - public CloudLoadBalancersUSPropertiesBuilder(Properties properties) { - super(properties); - } - -} diff --git a/providers/cloudloadbalancers-us/src/main/java/org/jclouds/rackspace/cloudloadbalancers/CloudLoadBalancersUSProviderMetadata.java b/providers/cloudloadbalancers-us/src/main/java/org/jclouds/rackspace/cloudloadbalancers/CloudLoadBalancersUSProviderMetadata.java index 4249495ec9..04f2018d5e 100644 --- a/providers/cloudloadbalancers-us/src/main/java/org/jclouds/rackspace/cloudloadbalancers/CloudLoadBalancersUSProviderMetadata.java +++ b/providers/cloudloadbalancers-us/src/main/java/org/jclouds/rackspace/cloudloadbalancers/CloudLoadBalancersUSProviderMetadata.java @@ -18,49 +18,92 @@ */ package org.jclouds.rackspace.cloudloadbalancers; +import static org.jclouds.Constants.PROPERTY_API_VERSION; +import static org.jclouds.Constants.PROPERTY_ENDPOINT; +import static org.jclouds.Constants.PROPERTY_ISO3166_CODES; +import static org.jclouds.cloudloadbalancers.reference.Region.DFW; +import static org.jclouds.cloudloadbalancers.reference.Region.ORD; +import static org.jclouds.location.reference.LocationConstants.ENDPOINT; +import static org.jclouds.location.reference.LocationConstants.ISO3166_CODES; +import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGION; +import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGIONS; + import java.net.URI; +import java.util.Properties; import org.jclouds.cloudloadbalancers.CloudLoadBalancersApiMetadata; -import org.jclouds.providers.BaseProviderMetadata; +import org.jclouds.cloudloadbalancers.CloudLoadBalancersAsyncClient; +import org.jclouds.cloudloadbalancers.CloudLoadBalancersClient; +import org.jclouds.loadbalancer.LoadBalancerServiceContext; +import org.jclouds.providers.ProviderMetadata; +import org.jclouds.providers.internal.BaseProviderMetadata; + +import com.google.common.base.Joiner; /** - * Implementation of {@link org.jclouds.types.ProviderMetadata} for Rackspace Cloud LoadBalancers in US. + * Implementation of {@link org.jclouds.types.ProviderMetadata} for Rackspace Cloud LoadBalancers US. * * @author Adrian Cole */ -public class CloudLoadBalancersUSProviderMetadata extends BaseProviderMetadata { - - public CloudLoadBalancersUSProviderMetadata() { - this(builder() - .id("cloudloadbalancers-us") - .name("Rackspace Cloud Load Balancers US") - .api(new CloudLoadBalancersApiMetadata()) - .homepage(URI.create("http://www.rackspace.com/cloud/cloud_hosting_products/loadbalancers")) - .console(URI.create("https://manage.rackspacecloud.com")) - .linkedServices("cloudloadbalancers-us", "cloudservers-us", "cloudfiles-us") - .iso3166Codes("US-IL","US-TX")); +public class CloudLoadBalancersUSProviderMetadata extends BaseProviderMetadata, CloudLoadBalancersApiMetadata> { + + public static Builder builder() { + return new Builder(); } - // below are so that we can reuse builders, toString, hashCode, etc. - // we have to set concrete classes here, as our base class cannot be - // concrete due to serviceLoader - protected CloudLoadBalancersUSProviderMetadata(ConcreteBuilder builder) { + @Override + public Builder toBuilder() { + return builder().fromProviderMetadata(this); + } + + public CloudLoadBalancersUSProviderMetadata() { + super(builder()); + } + + public CloudLoadBalancersUSProviderMetadata(Builder builder) { super(builder); } + public static final String[] REGIONS = {ORD, DFW}; - private static class ConcreteBuilder extends Builder { + protected static Properties defaultProperties() { + Properties properties = new Properties(); + properties.setProperty(PROPERTY_ENDPOINT, "https://auth.api.rackspacecloud.com"); + properties.setProperty(PROPERTY_REGIONS, Joiner.on(',').join(REGIONS)); + properties.setProperty(PROPERTY_ISO3166_CODES, "US-IL,US-TX"); + + properties.setProperty(PROPERTY_REGION + "." + ORD + "." + ISO3166_CODES, "US-IL"); + properties.setProperty(PROPERTY_REGION + "." + ORD + "." + ENDPOINT, String + .format("https://ord.loadbalancers.api.rackspacecloud.com/v${%s}", PROPERTY_API_VERSION)); + + properties.setProperty(PROPERTY_REGION + "." + DFW + "." + ISO3166_CODES, "US-TX"); + properties.setProperty(PROPERTY_REGION + "." + DFW + "." + ENDPOINT, String + .format("https://dfw.loadbalancers.api.rackspacecloud.com/v${%s}", PROPERTY_API_VERSION)); + return properties; + } + + public static class Builder extends BaseProviderMetadata.Builder, CloudLoadBalancersApiMetadata> { + + protected Builder(){ + id("cloudloadbalancers-us") + .name("Rackspace Cloud Load Balancers US") + .apiMetadata(new CloudLoadBalancersApiMetadata()) + .homepage(URI.create("http://www.rackspace.com/cloud/cloud_hosting_products/loadbalancers")) + .console(URI.create("https://manage.rackspacecloud.com")) + .linkedServices("cloudloadbalancers-us", "cloudservers-us", "cloudfiles-us") + .iso3166Codes("US-IL","US-TX") + .endpoint("https://auth.api.rackspacecloud.com"); + } @Override public CloudLoadBalancersUSProviderMetadata build() { return new CloudLoadBalancersUSProviderMetadata(this); } - } - - public static ConcreteBuilder builder() { - return new ConcreteBuilder(); - } - - public ConcreteBuilder toBuilder() { - return builder().fromProviderMetadata(this); + + @Override + public Builder fromProviderMetadata( + ProviderMetadata, CloudLoadBalancersApiMetadata> in) { + super.fromProviderMetadata(in); + return this; + } } } \ No newline at end of file diff --git a/providers/cloudloadbalancers-us/src/test/java/org/jclouds/rackspace/cloudloadbalancers/CloudLoadBalancersUSLoadBalancerClientLiveTest.java b/providers/cloudloadbalancers-us/src/test/java/org/jclouds/rackspace/cloudloadbalancers/CloudLoadBalancersUSLoadBalancerClientLiveTest.java index 0d471943be..31c17ffd8a 100644 --- a/providers/cloudloadbalancers-us/src/test/java/org/jclouds/rackspace/cloudloadbalancers/CloudLoadBalancersUSLoadBalancerClientLiveTest.java +++ b/providers/cloudloadbalancers-us/src/test/java/org/jclouds/rackspace/cloudloadbalancers/CloudLoadBalancersUSLoadBalancerClientLiveTest.java @@ -29,6 +29,6 @@ import org.testng.annotations.Test; public class CloudLoadBalancersUSLoadBalancerClientLiveTest extends LoadBalancerClientLiveTest { public CloudLoadBalancersUSLoadBalancerClientLiveTest() { provider = "cloudloadbalancers-us"; - regions = CloudLoadBalancersUSPropertiesBuilder.REGIONS; + regions = CloudLoadBalancersUSProviderMetadata.REGIONS; } } diff --git a/providers/cloudloadbalancers-us/src/test/java/org/jclouds/rackspace/cloudloadbalancers/CloudLoadBalancersUSProviderTest.java b/providers/cloudloadbalancers-us/src/test/java/org/jclouds/rackspace/cloudloadbalancers/CloudLoadBalancersUSProviderTest.java index 7fdf7435f4..544d8ca23e 100644 --- a/providers/cloudloadbalancers-us/src/test/java/org/jclouds/rackspace/cloudloadbalancers/CloudLoadBalancersUSProviderTest.java +++ b/providers/cloudloadbalancers-us/src/test/java/org/jclouds/rackspace/cloudloadbalancers/CloudLoadBalancersUSProviderTest.java @@ -19,7 +19,7 @@ package org.jclouds.rackspace.cloudloadbalancers; import org.jclouds.cloudloadbalancers.CloudLoadBalancersApiMetadata; -import org.jclouds.providers.BaseProviderMetadataTest; +import org.jclouds.providers.internal.BaseProviderMetadataTest; import org.testng.annotations.Test; /** diff --git a/providers/cloudonestorage/pom.xml b/providers/cloudonestorage/pom.xml index 73ff163f5a..8390b7c257 100644 --- a/providers/cloudonestorage/pom.xml +++ b/providers/cloudonestorage/pom.xml @@ -34,7 +34,6 @@ bundle - org.jclouds.cloudonestorage.blobstore.integration.CloudOneStorageTestInitializer https://cloudonestorage.peer1.com 1.3.0 @@ -107,7 +106,6 @@ ${test.cloudonestorage.build-version} ${test.cloudonestorage.identity} ${test.cloudonestorage.credential} - ${test.initializer} ${jclouds.blobstore.httpstream.url} ${jclouds.blobstore.httpstream.md5} diff --git a/providers/cloudonestorage/src/main/java/org/jclouds/cloudonestorage/CloudOneStoragePropertiesBuilder.java b/providers/cloudonestorage/src/main/java/org/jclouds/cloudonestorage/CloudOneStoragePropertiesBuilder.java deleted file mode 100644 index 7941563395..0000000000 --- a/providers/cloudonestorage/src/main/java/org/jclouds/cloudonestorage/CloudOneStoragePropertiesBuilder.java +++ /dev/null @@ -1,53 +0,0 @@ -/** - * 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.cloudonestorage; - -import static org.jclouds.Constants.PROPERTY_API_VERSION; -import static org.jclouds.Constants.PROPERTY_ENDPOINT; -import static org.jclouds.Constants.PROPERTY_ISO3166_CODES; - -import java.util.Properties; - -import org.jclouds.PropertiesBuilder; - -/** - * Builds properties used in Atmos Clients - * - * @author Adrian Cole - */ -public class CloudOneStoragePropertiesBuilder extends PropertiesBuilder { - - @Override - protected Properties defaultProperties() { - Properties properties = super.defaultProperties(); - properties.setProperty(PROPERTY_ENDPOINT, "https://cloudonestorage.peer1.com"); - properties.setProperty(PROPERTY_ISO3166_CODES, "US-GA,US-TX"); - properties.setProperty(PROPERTY_API_VERSION, "1.3.0"); - return properties; - } - - public CloudOneStoragePropertiesBuilder() { - super(); - } - - public CloudOneStoragePropertiesBuilder(Properties properties) { - super(properties); - } - -} diff --git a/providers/cloudonestorage/src/main/java/org/jclouds/cloudonestorage/CloudOneStorageProviderMetadata.java b/providers/cloudonestorage/src/main/java/org/jclouds/cloudonestorage/CloudOneStorageProviderMetadata.java index 01c6e552ea..55e5452be9 100644 --- a/providers/cloudonestorage/src/main/java/org/jclouds/cloudonestorage/CloudOneStorageProviderMetadata.java +++ b/providers/cloudonestorage/src/main/java/org/jclouds/cloudonestorage/CloudOneStorageProviderMetadata.java @@ -19,9 +19,14 @@ package org.jclouds.cloudonestorage; import java.net.URI; +import java.util.Properties; import org.jclouds.atmos.AtmosApiMetadata; -import org.jclouds.providers.BaseProviderMetadata; +import org.jclouds.atmos.AtmosAsyncClient; +import org.jclouds.atmos.AtmosClient; +import org.jclouds.blobstore.BlobStoreContext; +import org.jclouds.providers.ProviderMetadata; +import org.jclouds.providers.internal.BaseProviderMetadata; /** * Implementation of {@ link org.jclouds.types.ProviderMetadata} for PEER1's @@ -29,38 +34,53 @@ import org.jclouds.providers.BaseProviderMetadata; * * @author Jeremy Whitlock */ -public class CloudOneStorageProviderMetadata extends BaseProviderMetadata { - - public CloudOneStorageProviderMetadata() { - this(builder() - .id("cloudonestorage") - .name("PEER1 CloudOne Storage") - .api(new AtmosApiMetadata()) - .homepage(URI.create("http://www.peer1.com/hosting/cloudone-storage.php")) - .console(URI.create("https://mypeer1.com/")) - .iso3166Codes("US-GA", "US-TX")); +public class CloudOneStorageProviderMetadata extends BaseProviderMetadata, AtmosApiMetadata> { + + public static Builder builder() { + return new Builder(); } - // below are so that we can reuse builders, toString, hashCode, etc. - // we have to set concrete classes here, as our base class cannot be - // concrete due to serviceLoader - protected CloudOneStorageProviderMetadata(ConcreteBuilder builder) { + @Override + public Builder toBuilder() { + return builder().fromProviderMetadata(this); + } + + public CloudOneStorageProviderMetadata() { + super(builder()); + } + + public CloudOneStorageProviderMetadata(Builder builder) { super(builder); } - private static class ConcreteBuilder extends Builder { + protected static Properties defaultProperties() { + Properties properties = new Properties(); + return properties; + } + + public static class Builder extends BaseProviderMetadata.Builder, AtmosApiMetadata> { + + protected Builder(){ + id("cloudonestorage") + .name("PEER1 CloudOne Storage") + .apiMetadata(new AtmosApiMetadata()) + .homepage(URI.create("http://www.peer1.com/hosting/cloudone-storage.php")) + .console(URI.create("https://mypeer1.com/")) + .iso3166Codes("US-GA", "US-TX") + .endpoint("https://cloudonestorage.peer1.com") + .defaultProperties(CloudOneStorageProviderMetadata.defaultProperties()); + } @Override public CloudOneStorageProviderMetadata build() { return new CloudOneStorageProviderMetadata(this); } + + @Override + public Builder fromProviderMetadata( + ProviderMetadata, AtmosApiMetadata> in) { + super.fromProviderMetadata(in); + return this; + } } - - public static ConcreteBuilder builder() { - return new ConcreteBuilder(); - } - - public ConcreteBuilder toBuilder() { - return builder().fromProviderMetadata(this); - } -} +} \ No newline at end of file diff --git a/providers/cloudonestorage/src/test/java/org/jclouds/cloudonestorage/CloudOneStorageProviderTest.java b/providers/cloudonestorage/src/test/java/org/jclouds/cloudonestorage/CloudOneStorageProviderTest.java index 0b1a45be58..92fa334aff 100644 --- a/providers/cloudonestorage/src/test/java/org/jclouds/cloudonestorage/CloudOneStorageProviderTest.java +++ b/providers/cloudonestorage/src/test/java/org/jclouds/cloudonestorage/CloudOneStorageProviderTest.java @@ -19,7 +19,7 @@ package org.jclouds.cloudonestorage; import org.jclouds.atmos.AtmosApiMetadata; -import org.jclouds.providers.BaseProviderMetadataTest; +import org.jclouds.providers.internal.BaseProviderMetadataTest; import org.testng.annotations.Test; /** diff --git a/providers/cloudonestorage/src/test/java/org/jclouds/cloudonestorage/blobstore/integration/CloudOneStorageBlobIntegrationLiveTest.java b/providers/cloudonestorage/src/test/java/org/jclouds/cloudonestorage/blobstore/integration/CloudOneStorageBlobIntegrationLiveTest.java index e2aa681b32..fc3fe7380d 100644 --- a/providers/cloudonestorage/src/test/java/org/jclouds/cloudonestorage/blobstore/integration/CloudOneStorageBlobIntegrationLiveTest.java +++ b/providers/cloudonestorage/src/test/java/org/jclouds/cloudonestorage/blobstore/integration/CloudOneStorageBlobIntegrationLiveTest.java @@ -26,5 +26,8 @@ import org.testng.annotations.Test; */ @Test(groups = "live", testName = "CloudOneStorageBlobIntegrationLiveTest") public class CloudOneStorageBlobIntegrationLiveTest extends AtmosIntegrationLiveTest { + public CloudOneStorageBlobIntegrationLiveTest() { + provider = "cloudonestorage"; + } } diff --git a/providers/cloudonestorage/src/test/java/org/jclouds/cloudonestorage/blobstore/integration/CloudOneStorageBlobLiveTest.java b/providers/cloudonestorage/src/test/java/org/jclouds/cloudonestorage/blobstore/integration/CloudOneStorageBlobLiveTest.java index 29402bfc2b..240730065d 100644 --- a/providers/cloudonestorage/src/test/java/org/jclouds/cloudonestorage/blobstore/integration/CloudOneStorageBlobLiveTest.java +++ b/providers/cloudonestorage/src/test/java/org/jclouds/cloudonestorage/blobstore/integration/CloudOneStorageBlobLiveTest.java @@ -26,5 +26,8 @@ import org.testng.annotations.Test; */ @Test(groups = "live", testName = "CloudOneStorageBlobLiveTest") public class CloudOneStorageBlobLiveTest extends AtmosLiveTest { + public CloudOneStorageBlobLiveTest() { + provider = "cloudonestorage"; + } } diff --git a/providers/cloudonestorage/src/test/java/org/jclouds/cloudonestorage/blobstore/integration/CloudOneStorageBlobMapIntegrationLiveTest.java b/providers/cloudonestorage/src/test/java/org/jclouds/cloudonestorage/blobstore/integration/CloudOneStorageBlobMapIntegrationLiveTest.java index 64ca7503ab..0026347e73 100644 --- a/providers/cloudonestorage/src/test/java/org/jclouds/cloudonestorage/blobstore/integration/CloudOneStorageBlobMapIntegrationLiveTest.java +++ b/providers/cloudonestorage/src/test/java/org/jclouds/cloudonestorage/blobstore/integration/CloudOneStorageBlobMapIntegrationLiveTest.java @@ -26,5 +26,8 @@ import org.testng.annotations.Test; */ @Test(groups = "live", testName = "CloudOneStorageBlobMapIntegrationLiveTest") public class CloudOneStorageBlobMapIntegrationLiveTest extends AtmosMapIntegrationLiveTest { + public CloudOneStorageBlobMapIntegrationLiveTest() { + provider = "cloudonestorage"; + } } diff --git a/providers/cloudonestorage/src/test/java/org/jclouds/cloudonestorage/blobstore/integration/CloudOneStorageBlobSignerLiveTest.java b/providers/cloudonestorage/src/test/java/org/jclouds/cloudonestorage/blobstore/integration/CloudOneStorageBlobSignerLiveTest.java index 6391cd1733..10c4ddeeff 100644 --- a/providers/cloudonestorage/src/test/java/org/jclouds/cloudonestorage/blobstore/integration/CloudOneStorageBlobSignerLiveTest.java +++ b/providers/cloudonestorage/src/test/java/org/jclouds/cloudonestorage/blobstore/integration/CloudOneStorageBlobSignerLiveTest.java @@ -27,5 +27,8 @@ import org.testng.annotations.Test; */ @Test(groups = "live", testName = "CloudOneStorageBlobSignerLiveTest") public class CloudOneStorageBlobSignerLiveTest extends AtmosBlobSignerLiveTest { + public CloudOneStorageBlobSignerLiveTest() { + provider = "cloudonestorage"; + } } diff --git a/providers/cloudonestorage/src/test/java/org/jclouds/cloudonestorage/blobstore/integration/CloudOneStorageContainerIntegrationLiveTest.java b/providers/cloudonestorage/src/test/java/org/jclouds/cloudonestorage/blobstore/integration/CloudOneStorageContainerIntegrationLiveTest.java index fb7145b820..68f69e8614 100644 --- a/providers/cloudonestorage/src/test/java/org/jclouds/cloudonestorage/blobstore/integration/CloudOneStorageContainerIntegrationLiveTest.java +++ b/providers/cloudonestorage/src/test/java/org/jclouds/cloudonestorage/blobstore/integration/CloudOneStorageContainerIntegrationLiveTest.java @@ -26,5 +26,8 @@ import org.testng.annotations.Test; */ @Test(groups = "live", testName = "CloudOneStorageContainerIntegrationLiveTest") public class CloudOneStorageContainerIntegrationLiveTest extends AtmosContainerIntegrationLiveTest { + public CloudOneStorageContainerIntegrationLiveTest() { + provider = "cloudonestorage"; + } } diff --git a/providers/cloudonestorage/src/test/java/org/jclouds/cloudonestorage/blobstore/integration/CloudOneStorageContainerLiveTest.java b/providers/cloudonestorage/src/test/java/org/jclouds/cloudonestorage/blobstore/integration/CloudOneStorageContainerLiveTest.java index bda2c12a73..440d023390 100644 --- a/providers/cloudonestorage/src/test/java/org/jclouds/cloudonestorage/blobstore/integration/CloudOneStorageContainerLiveTest.java +++ b/providers/cloudonestorage/src/test/java/org/jclouds/cloudonestorage/blobstore/integration/CloudOneStorageContainerLiveTest.java @@ -26,5 +26,8 @@ import org.testng.annotations.Test; */ @Test(groups = "live", testName = "CloudOneStorageContainerLiveTest") public class CloudOneStorageContainerLiveTest extends AtmosContainerLiveTest { + public CloudOneStorageContainerLiveTest() { + provider = "cloudonestorage"; + } } diff --git a/providers/cloudonestorage/src/test/java/org/jclouds/cloudonestorage/blobstore/integration/CloudOneStorageInputStreamMapIntegrationLiveTest.java b/providers/cloudonestorage/src/test/java/org/jclouds/cloudonestorage/blobstore/integration/CloudOneStorageInputStreamMapIntegrationLiveTest.java index da25e36a2d..37d9a9e3e5 100644 --- a/providers/cloudonestorage/src/test/java/org/jclouds/cloudonestorage/blobstore/integration/CloudOneStorageInputStreamMapIntegrationLiveTest.java +++ b/providers/cloudonestorage/src/test/java/org/jclouds/cloudonestorage/blobstore/integration/CloudOneStorageInputStreamMapIntegrationLiveTest.java @@ -26,5 +26,8 @@ import org.testng.annotations.Test; */ @Test(groups = "live", testName = "CloudOneStorageInputStreamMapIntegrationLiveTest") public class CloudOneStorageInputStreamMapIntegrationLiveTest extends AtmosInputStreamMapIntegrationLiveTest { + public CloudOneStorageInputStreamMapIntegrationLiveTest() { + provider = "cloudonestorage"; + } } diff --git a/providers/cloudonestorage/src/test/java/org/jclouds/cloudonestorage/blobstore/integration/CloudOneStorageServiceIntegrationLiveTest.java b/providers/cloudonestorage/src/test/java/org/jclouds/cloudonestorage/blobstore/integration/CloudOneStorageServiceIntegrationLiveTest.java index 6827693883..0ff05f0ad6 100644 --- a/providers/cloudonestorage/src/test/java/org/jclouds/cloudonestorage/blobstore/integration/CloudOneStorageServiceIntegrationLiveTest.java +++ b/providers/cloudonestorage/src/test/java/org/jclouds/cloudonestorage/blobstore/integration/CloudOneStorageServiceIntegrationLiveTest.java @@ -30,6 +30,10 @@ import com.google.common.collect.ImmutableSet; */ @Test(groups = "live", testName = "CloudOneStorageServiceIntegrationLiveTest") public class CloudOneStorageServiceIntegrationLiveTest extends AtmosServiceIntegrationLiveTest { + public CloudOneStorageServiceIntegrationLiveTest() { + provider = "cloudonestorage"; + } + @Override protected Set getIso3166Codes() { return ImmutableSet. of("US-GA", "US-TX"); diff --git a/providers/cloudservers-uk/src/main/java/org/jclouds/rackspace/cloudservers/CloudServersUKPropertiesBuilder.java b/providers/cloudservers-uk/src/main/java/org/jclouds/rackspace/cloudservers/CloudServersUKPropertiesBuilder.java deleted file mode 100644 index 248e503514..0000000000 --- a/providers/cloudservers-uk/src/main/java/org/jclouds/rackspace/cloudservers/CloudServersUKPropertiesBuilder.java +++ /dev/null @@ -1,46 +0,0 @@ -/** - * 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.rackspace.cloudservers; - -import static org.jclouds.Constants.PROPERTY_ENDPOINT; -import static org.jclouds.Constants.PROPERTY_ISO3166_CODES; - -import java.util.Properties; - -import org.jclouds.cloudservers.CloudServersPropertiesBuilder; - -/** - * - * @author Adrian Cole - */ -public class CloudServersUKPropertiesBuilder extends CloudServersPropertiesBuilder { - - @Override - protected Properties defaultProperties() { - Properties properties = super.defaultProperties(); - properties.setProperty(PROPERTY_ISO3166_CODES, "GB-SLG"); - properties.setProperty(PROPERTY_ENDPOINT, "https://lon.auth.api.rackspacecloud.com"); - return properties; - } - - public CloudServersUKPropertiesBuilder(Properties properties) { - super(properties); - } - -} diff --git a/providers/cloudservers-uk/src/main/java/org/jclouds/rackspace/cloudservers/CloudServersUKProviderMetadata.java b/providers/cloudservers-uk/src/main/java/org/jclouds/rackspace/cloudservers/CloudServersUKProviderMetadata.java index a2dee8abc8..0bed8a3b5d 100644 --- a/providers/cloudservers-uk/src/main/java/org/jclouds/rackspace/cloudservers/CloudServersUKProviderMetadata.java +++ b/providers/cloudservers-uk/src/main/java/org/jclouds/rackspace/cloudservers/CloudServersUKProviderMetadata.java @@ -18,50 +18,69 @@ */ package org.jclouds.rackspace.cloudservers; +import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGIONS; + import java.net.URI; +import java.util.Properties; import org.jclouds.cloudservers.CloudServersApiMetadata; -import org.jclouds.providers.BaseProviderMetadata; +import org.jclouds.cloudservers.CloudServersAsyncClient; +import org.jclouds.cloudservers.CloudServersClient; +import org.jclouds.compute.ComputeServiceContext; +import org.jclouds.providers.ProviderMetadata; +import org.jclouds.providers.internal.BaseProviderMetadata; /** - * Implementation of {@link org.jclouds.types.ProviderMetadata} for Rackspace Cloud Servers in UK. + * Implementation of {@link org.jclouds.types.ProviderMetadata} for Rackspace Cloud Servers UK. * * @author Adrian Cole */ -public class CloudServersUKProviderMetadata extends BaseProviderMetadata { - - public CloudServersUKProviderMetadata() { - this(builder() - .id("cloudservers-uk") - .name("Rackspace Cloud Servers UK") - .api(new CloudServersApiMetadata()) - .homepage(URI.create("http://www.rackspace.co.uk/cloud-hosting/cloud-products/cloud-servers")) - .console(URI.create("https://lon.manage.rackspacecloud.com")) - .linkedServices("cloudloadbalancers-uk", "cloudservers-uk", "cloudfiles-uk") - .iso3166Codes("GB-SLG")); +public class CloudServersUKProviderMetadata extends BaseProviderMetadata, CloudServersApiMetadata> { + + public static Builder builder() { + return new Builder(); } - // below are so that we can reuse builders, toString, hashCode, etc. - // we have to set concrete classes here, as our base class cannot be - // concrete due to serviceLoader - protected CloudServersUKProviderMetadata(ConcreteBuilder builder) { + @Override + public Builder toBuilder() { + return builder().fromProviderMetadata(this); + } + + public CloudServersUKProviderMetadata() { + super(builder()); + } + + public CloudServersUKProviderMetadata(Builder builder) { super(builder); } - private static class ConcreteBuilder extends Builder { + protected static Properties defaultProperties() { + Properties properties = new Properties(); + properties.setProperty(PROPERTY_REGIONS, "UK"); + return properties; + } + public static class Builder extends BaseProviderMetadata.Builder, CloudServersApiMetadata> { + + protected Builder(){ + id("cloudservers-uk") + .name("Rackspace Cloud Servers UK") + .apiMetadata(new CloudServersApiMetadata()) + .homepage(URI.create("http://www.rackspace.co.uk/cloud-hosting/cloud-products/cloud-servers")) + .console(URI.create("https://lon.manage.rackspacecloud.com")) + .linkedServices("cloudloadbalancers-uk", "cloudservers-uk", "cloudfiles-uk") + .iso3166Codes("GB-SLG"); + } @Override public CloudServersUKProviderMetadata build() { return new CloudServersUKProviderMetadata(this); } + + @Override + public Builder fromProviderMetadata( + ProviderMetadata, CloudServersApiMetadata> in) { + super.fromProviderMetadata(in); + return this; + } } - - public static ConcreteBuilder builder() { - return new ConcreteBuilder(); - } - - public ConcreteBuilder toBuilder() { - return builder().fromProviderMetadata(this); - } - } \ No newline at end of file diff --git a/providers/cloudservers-uk/src/test/java/org/jclouds/rackspace/cloudservers/CloudServersUKProviderTest.java b/providers/cloudservers-uk/src/test/java/org/jclouds/rackspace/cloudservers/CloudServersUKProviderTest.java index e0011cc6e1..3c394e4feb 100644 --- a/providers/cloudservers-uk/src/test/java/org/jclouds/rackspace/cloudservers/CloudServersUKProviderTest.java +++ b/providers/cloudservers-uk/src/test/java/org/jclouds/rackspace/cloudservers/CloudServersUKProviderTest.java @@ -36,7 +36,7 @@ package org.jclouds.rackspace.cloudservers; import org.jclouds.cloudservers.CloudServersApiMetadata; -import org.jclouds.providers.BaseProviderMetadataTest; +import org.jclouds.providers.internal.BaseProviderMetadataTest; import org.testng.annotations.Test; /** diff --git a/providers/cloudservers-uk/src/test/java/org/jclouds/rackspace/cloudservers/compute/CloudServersUKTemplateBuilderLiveTest.java b/providers/cloudservers-uk/src/test/java/org/jclouds/rackspace/cloudservers/compute/CloudServersUKTemplateBuilderLiveTest.java index 8865fc8c29..da6f4a3450 100644 --- a/providers/cloudservers-uk/src/test/java/org/jclouds/rackspace/cloudservers/compute/CloudServersUKTemplateBuilderLiveTest.java +++ b/providers/cloudservers-uk/src/test/java/org/jclouds/rackspace/cloudservers/compute/CloudServersUKTemplateBuilderLiveTest.java @@ -23,10 +23,13 @@ import static org.testng.Assert.assertEquals; import java.util.Set; -import org.jclouds.compute.BaseTemplateBuilderLiveTest; +import org.jclouds.cloudservers.CloudServersAsyncClient; +import org.jclouds.cloudservers.CloudServersClient; +import org.jclouds.compute.ComputeServiceContext; import org.jclouds.compute.domain.OsFamily; import org.jclouds.compute.domain.OsFamilyVersion64Bit; import org.jclouds.compute.domain.Template; +import org.jclouds.compute.internal.BaseTemplateBuilderLiveTest; import org.testng.annotations.Test; import com.google.common.base.Predicate; @@ -38,7 +41,9 @@ import com.google.common.collect.ImmutableSet; * @author Adrian Cole */ @Test(groups = "live") -public class CloudServersUKTemplateBuilderLiveTest extends BaseTemplateBuilderLiveTest { +public class CloudServersUKTemplateBuilderLiveTest + extends + BaseTemplateBuilderLiveTest> { public CloudServersUKTemplateBuilderLiveTest() { provider = "cloudservers-uk"; diff --git a/providers/cloudservers-us/src/main/java/org/jclouds/rackspace/cloudservers/CloudServersUSPropertiesBuilder.java b/providers/cloudservers-us/src/main/java/org/jclouds/rackspace/cloudservers/CloudServersUSPropertiesBuilder.java deleted file mode 100644 index 76c0ac294d..0000000000 --- a/providers/cloudservers-us/src/main/java/org/jclouds/rackspace/cloudservers/CloudServersUSPropertiesBuilder.java +++ /dev/null @@ -1,46 +0,0 @@ -/** - * 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.rackspace.cloudservers; - -import static org.jclouds.Constants.PROPERTY_ENDPOINT; -import static org.jclouds.Constants.PROPERTY_ISO3166_CODES; - -import java.util.Properties; - -import org.jclouds.cloudservers.CloudServersPropertiesBuilder; - -/** - * - * @author Adrian Cole - */ -public class CloudServersUSPropertiesBuilder extends CloudServersPropertiesBuilder { - - @Override - protected Properties defaultProperties() { - Properties properties = super.defaultProperties(); - properties.setProperty(PROPERTY_ISO3166_CODES, "US-IL,US-TX"); - properties.setProperty(PROPERTY_ENDPOINT, "https://auth.api.rackspacecloud.com"); - return properties; - } - - public CloudServersUSPropertiesBuilder(Properties properties) { - super(properties); - } - -} diff --git a/providers/cloudservers-us/src/main/java/org/jclouds/rackspace/cloudservers/CloudServersUSProviderMetadata.java b/providers/cloudservers-us/src/main/java/org/jclouds/rackspace/cloudservers/CloudServersUSProviderMetadata.java index 698f96f954..16f85b88ae 100644 --- a/providers/cloudservers-us/src/main/java/org/jclouds/rackspace/cloudservers/CloudServersUSProviderMetadata.java +++ b/providers/cloudservers-us/src/main/java/org/jclouds/rackspace/cloudservers/CloudServersUSProviderMetadata.java @@ -18,50 +18,70 @@ */ package org.jclouds.rackspace.cloudservers; +import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGIONS; + import java.net.URI; +import java.util.Properties; import org.jclouds.cloudservers.CloudServersApiMetadata; -import org.jclouds.providers.BaseProviderMetadata; - +import org.jclouds.cloudservers.CloudServersAsyncClient; +import org.jclouds.cloudservers.CloudServersClient; +import org.jclouds.compute.ComputeServiceContext; +import org.jclouds.providers.ProviderMetadata; +import org.jclouds.providers.internal.BaseProviderMetadata; /** - * Implementation of {@link org.jclouds.types.ProviderMetadata} for Rackspace Cloud Servers in US. + * Implementation of {@link org.jclouds.types.ProviderMetadata} for Rackspace Cloud Servers US. * * @author Adrian Cole */ -public class CloudServersUSProviderMetadata extends BaseProviderMetadata { - - public CloudServersUSProviderMetadata() { - this(builder() - .id("cloudservers-us") - .name("Rackspace Cloud Servers US") - .api(new CloudServersApiMetadata()) - .homepage(URI.create("http://www.rackspace.com/cloud/cloud_hosting_products/servers")) - .console(URI.create("https://manage.rackspacecloud.com")) - .linkedServices("cloudloadbalancers-us", "cloudservers-us", "cloudfiles-us") - .iso3166Codes("US-IL", "US-TX")); +public class CloudServersUSProviderMetadata extends BaseProviderMetadata, CloudServersApiMetadata> { + + public static Builder builder() { + return new Builder(); } - // below are so that we can reuse builders, toString, hashCode, etc. - // we have to set concrete classes here, as our base class cannot be - // concrete due to serviceLoader - protected CloudServersUSProviderMetadata(ConcreteBuilder builder) { + @Override + public Builder toBuilder() { + return builder().fromProviderMetadata(this); + } + + public CloudServersUSProviderMetadata() { + super(builder()); + } + + public CloudServersUSProviderMetadata(Builder builder) { super(builder); } - private static class ConcreteBuilder extends Builder { + protected static Properties defaultProperties() { + Properties properties = new Properties(); + properties.setProperty(PROPERTY_REGIONS, "US"); + return properties; + } + + public static class Builder extends BaseProviderMetadata.Builder, CloudServersApiMetadata> { + + protected Builder(){ + id("cloudservers-us") + .name("Rackspace Cloud Servers US") + .apiMetadata(new CloudServersApiMetadata()) + .homepage(URI.create("http://www.rackspace.com/cloud/cloud_hosting_products/servers")) + .console(URI.create("https://manage.rackspacecloud.com")) + .linkedServices("cloudloadbalancers-us", "cloudservers-us", "cloudfiles-us") + .iso3166Codes("US-IL", "US-TX"); + } @Override public CloudServersUSProviderMetadata build() { return new CloudServersUSProviderMetadata(this); } - } - - public static ConcreteBuilder builder() { - return new ConcreteBuilder(); - } - - public ConcreteBuilder toBuilder() { - return builder().fromProviderMetadata(this); + + @Override + public Builder fromProviderMetadata( + ProviderMetadata, CloudServersApiMetadata> in) { + super.fromProviderMetadata(in); + return this; + } } } \ No newline at end of file diff --git a/providers/cloudservers-us/src/test/java/org/jclouds/rackspace/cloudservers/CloudServersUSProviderTest.java b/providers/cloudservers-us/src/test/java/org/jclouds/rackspace/cloudservers/CloudServersUSProviderTest.java index 6f4ec86df6..433f0ea55f 100644 --- a/providers/cloudservers-us/src/test/java/org/jclouds/rackspace/cloudservers/CloudServersUSProviderTest.java +++ b/providers/cloudservers-us/src/test/java/org/jclouds/rackspace/cloudservers/CloudServersUSProviderTest.java @@ -36,7 +36,7 @@ package org.jclouds.rackspace.cloudservers; import org.jclouds.cloudservers.CloudServersApiMetadata; -import org.jclouds.providers.BaseProviderMetadataTest; +import org.jclouds.providers.internal.BaseProviderMetadataTest; import org.testng.annotations.Test; /** diff --git a/providers/cloudservers-us/src/test/java/org/jclouds/rackspace/cloudservers/compute/CloudServersUSTemplateBuilderLiveTest.java b/providers/cloudservers-us/src/test/java/org/jclouds/rackspace/cloudservers/compute/CloudServersUSTemplateBuilderLiveTest.java index 7d73a29c44..1dc74d846f 100644 --- a/providers/cloudservers-us/src/test/java/org/jclouds/rackspace/cloudservers/compute/CloudServersUSTemplateBuilderLiveTest.java +++ b/providers/cloudservers-us/src/test/java/org/jclouds/rackspace/cloudservers/compute/CloudServersUSTemplateBuilderLiveTest.java @@ -23,10 +23,13 @@ import static org.testng.Assert.assertEquals; import java.util.Set; -import org.jclouds.compute.BaseTemplateBuilderLiveTest; +import org.jclouds.cloudservers.CloudServersAsyncClient; +import org.jclouds.cloudservers.CloudServersClient; +import org.jclouds.compute.ComputeServiceContext; import org.jclouds.compute.domain.OsFamily; import org.jclouds.compute.domain.OsFamilyVersion64Bit; import org.jclouds.compute.domain.Template; +import org.jclouds.compute.internal.BaseTemplateBuilderLiveTest; import org.testng.annotations.Test; import com.google.common.base.Predicate; @@ -38,7 +41,9 @@ import com.google.common.collect.ImmutableSet; * @author Adrian Cole */ @Test(groups = "live") -public class CloudServersUSTemplateBuilderLiveTest extends BaseTemplateBuilderLiveTest { +public class CloudServersUSTemplateBuilderLiveTest + extends + BaseTemplateBuilderLiveTest> { public CloudServersUSTemplateBuilderLiveTest() { provider = "cloudservers-us"; diff --git a/providers/cloudsigma-lvs/src/main/java/org/jclouds/cloudsigma/CloudSigmaLasVegasPropertiesBuilder.java b/providers/cloudsigma-lvs/src/main/java/org/jclouds/cloudsigma/CloudSigmaLasVegasPropertiesBuilder.java deleted file mode 100644 index 5565b5b921..0000000000 --- a/providers/cloudsigma-lvs/src/main/java/org/jclouds/cloudsigma/CloudSigmaLasVegasPropertiesBuilder.java +++ /dev/null @@ -1,44 +0,0 @@ -/** - * 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.cloudsigma; - -import static org.jclouds.Constants.PROPERTY_ENDPOINT; -import static org.jclouds.Constants.PROPERTY_ISO3166_CODES; - -import java.util.Properties; - -/** - * Builds properties used in CloudSigma Clients - * - * @author Adrian Cole - */ -public class CloudSigmaLasVegasPropertiesBuilder extends CloudSigmaPropertiesBuilder { - @Override - protected Properties defaultProperties() { - Properties properties = super.defaultProperties(); - properties.setProperty(PROPERTY_ISO3166_CODES, "US-NV"); - properties.setProperty(PROPERTY_ENDPOINT, "https://api.lvs.cloudsigma.com"); - return properties; - } - - public CloudSigmaLasVegasPropertiesBuilder(Properties properties) { - super(properties); - } - -} diff --git a/providers/cloudsigma-lvs/src/main/java/org/jclouds/cloudsigma/CloudSigmaLasVegasProviderMetadata.java b/providers/cloudsigma-lvs/src/main/java/org/jclouds/cloudsigma/CloudSigmaLasVegasProviderMetadata.java index 12970c054d..83ada1c0b4 100644 --- a/providers/cloudsigma-lvs/src/main/java/org/jclouds/cloudsigma/CloudSigmaLasVegasProviderMetadata.java +++ b/providers/cloudsigma-lvs/src/main/java/org/jclouds/cloudsigma/CloudSigmaLasVegasProviderMetadata.java @@ -19,46 +19,70 @@ package org.jclouds.cloudsigma; import java.net.URI; +import java.util.Properties; -import org.jclouds.providers.BaseProviderMetadata; +import org.jclouds.compute.ComputeServiceContext; +import org.jclouds.providers.ProviderMetadata; +import org.jclouds.providers.internal.BaseProviderMetadata; /** * Implementation of {@link org.jclouds.types.ProviderMetadata} for CloudSigma Las Vegas. - * + + * * @author Adrian Cole */ -public class CloudSigmaLasVegasProviderMetadata extends BaseProviderMetadata { +public class CloudSigmaLasVegasProviderMetadata + extends + BaseProviderMetadata, CloudSigmaApiMetadata> { - public CloudSigmaLasVegasProviderMetadata() { - this(builder() - .id("cloudsigma-lvs") - .name("CloudSigma Las Vegas") - .api(new CloudSigmaApiMetadata()) - .homepage(URI.create("http://www.cloudsigma.com/en/our-cloud/features")) - .console(URI.create("https://gui.lvs.cloudsigma.com/")) - .iso3166Codes("US-NV")); + public static Builder builder() { + return new Builder(); } - // below are so that we can reuse builders, toString, hashCode, etc. - // we have to set concrete classes here, as our base class cannot be - // concrete due to serviceLoader - protected CloudSigmaLasVegasProviderMetadata(ConcreteBuilder builder) { + @Override + public Builder toBuilder() { + return builder().fromProviderMetadata(this); + } + + public CloudSigmaLasVegasProviderMetadata() { + super(builder()); + } + + public CloudSigmaLasVegasProviderMetadata(Builder builder) { super(builder); } - private static class ConcreteBuilder extends Builder { + protected static Properties defaultProperties() { + Properties properties = new Properties(); + return properties; + } + + public static class Builder + extends + BaseProviderMetadata.Builder, CloudSigmaApiMetadata> { + + protected Builder() { + id("cloudsigma-lvs") + .name("CloudSigma Las Vegas") + .apiMetadata(new CloudSigmaApiMetadata()) + .homepage(URI.create("http://www.cloudsigma.com/en/our-cloud/features")) + .console(URI.create("https://gui.lvs.cloudsigma.com/")) + .iso3166Codes("US-NV") + .endpoint("https://api.lvs.cloudsigma.com") + .defaultProperties(CloudSigmaLasVegasProviderMetadata.defaultProperties()); + } @Override public CloudSigmaLasVegasProviderMetadata build() { return new CloudSigmaLasVegasProviderMetadata(this); } - } - public static ConcreteBuilder builder() { - return new ConcreteBuilder(); - } + @Override + public Builder fromProviderMetadata( + ProviderMetadata, CloudSigmaApiMetadata> in) { + super.fromProviderMetadata(in); + return this; + } - public ConcreteBuilder toBuilder() { - return builder().fromProviderMetadata(this); } -} +} \ No newline at end of file diff --git a/providers/cloudsigma-lvs/src/test/java/org/jclouds/cloudsigma/CloudSigmaLasVegasProviderTest.java b/providers/cloudsigma-lvs/src/test/java/org/jclouds/cloudsigma/CloudSigmaLasVegasProviderTest.java index 0afe6d819f..5bfac827b6 100644 --- a/providers/cloudsigma-lvs/src/test/java/org/jclouds/cloudsigma/CloudSigmaLasVegasProviderTest.java +++ b/providers/cloudsigma-lvs/src/test/java/org/jclouds/cloudsigma/CloudSigmaLasVegasProviderTest.java @@ -18,7 +18,7 @@ */ package org.jclouds.cloudsigma; -import org.jclouds.providers.BaseProviderMetadataTest; +import org.jclouds.providers.internal.BaseProviderMetadataTest; import org.testng.annotations.Test; /** diff --git a/providers/cloudsigma-lvs/src/test/java/org/jclouds/cloudsigma/compute/CloudSigmaLasVegasTemplateBuilderLiveTest.java b/providers/cloudsigma-lvs/src/test/java/org/jclouds/cloudsigma/compute/CloudSigmaLasVegasTemplateBuilderLiveTest.java index d365b692bb..ada7600380 100644 --- a/providers/cloudsigma-lvs/src/test/java/org/jclouds/cloudsigma/compute/CloudSigmaLasVegasTemplateBuilderLiveTest.java +++ b/providers/cloudsigma-lvs/src/test/java/org/jclouds/cloudsigma/compute/CloudSigmaLasVegasTemplateBuilderLiveTest.java @@ -24,10 +24,13 @@ import static org.testng.Assert.assertEquals; import java.io.IOException; import java.util.Set; -import org.jclouds.compute.BaseTemplateBuilderLiveTest; +import org.jclouds.cloudsigma.CloudSigmaAsyncClient; +import org.jclouds.cloudsigma.CloudSigmaClient; +import org.jclouds.compute.ComputeServiceContext; import org.jclouds.compute.domain.OsFamily; import org.jclouds.compute.domain.OsFamilyVersion64Bit; import org.jclouds.compute.domain.Template; +import org.jclouds.compute.internal.BaseTemplateBuilderLiveTest; import org.testng.annotations.Test; import com.google.common.base.Predicate; @@ -39,7 +42,9 @@ import com.google.common.collect.ImmutableSet; * @author Adrian Cole */ @Test(groups = "live", testName = "CloudSigmaLasVegasTemplateBuilderLiveTest") -public class CloudSigmaLasVegasTemplateBuilderLiveTest extends BaseTemplateBuilderLiveTest { +public class CloudSigmaLasVegasTemplateBuilderLiveTest + extends + BaseTemplateBuilderLiveTest> { public CloudSigmaLasVegasTemplateBuilderLiveTest() { provider = "cloudsigma-lvs"; diff --git a/providers/cloudsigma-zrh/src/main/java/org/jclouds/cloudsigma/CloudSigmaZurichPropertiesBuilder.java b/providers/cloudsigma-zrh/src/main/java/org/jclouds/cloudsigma/CloudSigmaZurichPropertiesBuilder.java deleted file mode 100644 index 7900f4beaa..0000000000 --- a/providers/cloudsigma-zrh/src/main/java/org/jclouds/cloudsigma/CloudSigmaZurichPropertiesBuilder.java +++ /dev/null @@ -1,44 +0,0 @@ -/** - * 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.cloudsigma; - -import static org.jclouds.Constants.PROPERTY_ENDPOINT; -import static org.jclouds.Constants.PROPERTY_ISO3166_CODES; - -import java.util.Properties; - -/** - * Builds properties used in CloudSigma Clients - * - * @author Adrian Cole - */ -public class CloudSigmaZurichPropertiesBuilder extends CloudSigmaPropertiesBuilder { - @Override - protected Properties defaultProperties() { - Properties properties = super.defaultProperties(); - properties.setProperty(PROPERTY_ISO3166_CODES, "CH-ZH"); - properties.setProperty(PROPERTY_ENDPOINT, "https://api.zrh.cloudsigma.com"); - return properties; - } - - public CloudSigmaZurichPropertiesBuilder(Properties properties) { - super(properties); - } - -} diff --git a/providers/cloudsigma-zrh/src/main/java/org/jclouds/cloudsigma/CloudSigmaZurichProviderMetadata.java b/providers/cloudsigma-zrh/src/main/java/org/jclouds/cloudsigma/CloudSigmaZurichProviderMetadata.java index 483f22eabd..7f18af9aa2 100644 --- a/providers/cloudsigma-zrh/src/main/java/org/jclouds/cloudsigma/CloudSigmaZurichProviderMetadata.java +++ b/providers/cloudsigma-zrh/src/main/java/org/jclouds/cloudsigma/CloudSigmaZurichProviderMetadata.java @@ -19,46 +19,70 @@ package org.jclouds.cloudsigma; import java.net.URI; +import java.util.Properties; -import org.jclouds.providers.BaseProviderMetadata; +import org.jclouds.compute.ComputeServiceContext; +import org.jclouds.providers.ProviderMetadata; +import org.jclouds.providers.internal.BaseProviderMetadata; /** * Implementation of {@link org.jclouds.types.ProviderMetadata} for CloudSigma Zurich. - * + + * * @author Adrian Cole */ -public class CloudSigmaZurichProviderMetadata extends BaseProviderMetadata { +public class CloudSigmaZurichProviderMetadata + extends + BaseProviderMetadata, CloudSigmaApiMetadata> { - public CloudSigmaZurichProviderMetadata() { - this(builder() - .id("cloudsigma-zrh") - .name("CloudSigma Zurich") - .api(new CloudSigmaApiMetadata()) - .homepage(URI.create("http://www.cloudsigma.com/en/our-cloud/features")) - .console(URI.create("https://gui.zrh.cloudsigma.com/")) - .iso3166Codes("CH-ZH")); + public static Builder builder() { + return new Builder(); } - // below are so that we can reuse builders, toString, hashCode, etc. - // we have to set concrete classes here, as our base class cannot be - // concrete due to serviceLoader - protected CloudSigmaZurichProviderMetadata(ConcreteBuilder builder) { + @Override + public Builder toBuilder() { + return builder().fromProviderMetadata(this); + } + + public CloudSigmaZurichProviderMetadata() { + super(builder()); + } + + public CloudSigmaZurichProviderMetadata(Builder builder) { super(builder); } - private static class ConcreteBuilder extends Builder { + protected static Properties defaultProperties() { + Properties properties = new Properties(); + return properties; + } + + public static class Builder + extends + BaseProviderMetadata.Builder, CloudSigmaApiMetadata> { + + protected Builder() { + id("cloudsigma-zrh") + .name("CloudSigma Zurich") + .apiMetadata(new CloudSigmaApiMetadata()) + .homepage(URI.create("http://www.cloudsigma.com/en/our-cloud/features")) + .console(URI.create("https://gui.zrh.cloudsigma.com/")) + .iso3166Codes("CH-ZH") + .endpoint("https://api.zrh.cloudsigma.com") + .defaultProperties(CloudSigmaZurichProviderMetadata.defaultProperties()); + } @Override public CloudSigmaZurichProviderMetadata build() { return new CloudSigmaZurichProviderMetadata(this); } - } - public static ConcreteBuilder builder() { - return new ConcreteBuilder(); - } + @Override + public Builder fromProviderMetadata( + ProviderMetadata, CloudSigmaApiMetadata> in) { + super.fromProviderMetadata(in); + return this; + } - public ConcreteBuilder toBuilder() { - return builder().fromProviderMetadata(this); } -} +} \ No newline at end of file diff --git a/providers/cloudsigma-zrh/src/test/java/org/jclouds/cloudsigma/CloudSigmaZurichProviderTest.java b/providers/cloudsigma-zrh/src/test/java/org/jclouds/cloudsigma/CloudSigmaZurichProviderTest.java index 2e9d1d8180..6ff78f4fda 100644 --- a/providers/cloudsigma-zrh/src/test/java/org/jclouds/cloudsigma/CloudSigmaZurichProviderTest.java +++ b/providers/cloudsigma-zrh/src/test/java/org/jclouds/cloudsigma/CloudSigmaZurichProviderTest.java @@ -18,7 +18,7 @@ */ package org.jclouds.cloudsigma; -import org.jclouds.providers.BaseProviderMetadataTest; +import org.jclouds.providers.internal.BaseProviderMetadataTest; import org.testng.annotations.Test; /** diff --git a/providers/cloudsigma-zrh/src/test/java/org/jclouds/cloudsigma/compute/CloudSigmaZurichTemplateBuilderLiveTest.java b/providers/cloudsigma-zrh/src/test/java/org/jclouds/cloudsigma/compute/CloudSigmaZurichTemplateBuilderLiveTest.java index a46f237689..b85002b3b9 100644 --- a/providers/cloudsigma-zrh/src/test/java/org/jclouds/cloudsigma/compute/CloudSigmaZurichTemplateBuilderLiveTest.java +++ b/providers/cloudsigma-zrh/src/test/java/org/jclouds/cloudsigma/compute/CloudSigmaZurichTemplateBuilderLiveTest.java @@ -24,10 +24,13 @@ import static org.testng.Assert.assertEquals; import java.io.IOException; import java.util.Set; -import org.jclouds.compute.BaseTemplateBuilderLiveTest; +import org.jclouds.cloudsigma.CloudSigmaAsyncClient; +import org.jclouds.cloudsigma.CloudSigmaClient; +import org.jclouds.compute.ComputeServiceContext; import org.jclouds.compute.domain.OsFamily; import org.jclouds.compute.domain.OsFamilyVersion64Bit; import org.jclouds.compute.domain.Template; +import org.jclouds.compute.internal.BaseTemplateBuilderLiveTest; import org.testng.annotations.Test; import com.google.common.base.Predicate; @@ -39,7 +42,9 @@ import com.google.common.collect.ImmutableSet; * @author Adrian Cole */ @Test(groups = "live", singleThreaded = true, testName = "CloudSigmaZurichTemplateBuilderLiveTest") -public class CloudSigmaZurichTemplateBuilderLiveTest extends BaseTemplateBuilderLiveTest { +public class CloudSigmaZurichTemplateBuilderLiveTest + extends + BaseTemplateBuilderLiveTest> { public CloudSigmaZurichTemplateBuilderLiveTest() { provider = "cloudsigma-zrh"; diff --git a/providers/elastichosts-lax-p/src/main/java/org/jclouds/elastichosts/ElasticHostsPeer1LosAngelesPropertiesBuilder.java b/providers/elastichosts-lax-p/src/main/java/org/jclouds/elastichosts/ElasticHostsPeer1LosAngelesPropertiesBuilder.java deleted file mode 100644 index 3a34dab879..0000000000 --- a/providers/elastichosts-lax-p/src/main/java/org/jclouds/elastichosts/ElasticHostsPeer1LosAngelesPropertiesBuilder.java +++ /dev/null @@ -1,48 +0,0 @@ -/** - * 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.elastichosts; - -import static org.jclouds.Constants.PROPERTY_API_VERSION; -import static org.jclouds.Constants.PROPERTY_ENDPOINT; -import static org.jclouds.Constants.PROPERTY_ISO3166_CODES; - -import java.util.Properties; - -import org.jclouds.elasticstack.ElasticStackPropertiesBuilder; - -/** - * - * @author Adrian Cole - */ -public class ElasticHostsPeer1LosAngelesPropertiesBuilder extends ElasticStackPropertiesBuilder { - - @Override - protected Properties defaultProperties() { - Properties properties = super.defaultProperties(); - properties.setProperty(PROPERTY_ISO3166_CODES, "US-CA"); - properties.setProperty(PROPERTY_ENDPOINT, "https://api.lax-p.elastichosts.com"); - properties.setProperty(PROPERTY_API_VERSION, "2.0"); - return properties; - } - - public ElasticHostsPeer1LosAngelesPropertiesBuilder(Properties properties) { - super(properties); - } - -} diff --git a/providers/elastichosts-lax-p/src/main/java/org/jclouds/elastichosts/ElasticHostsPeer1LosAngelesProviderMetadata.java b/providers/elastichosts-lax-p/src/main/java/org/jclouds/elastichosts/ElasticHostsPeer1LosAngelesProviderMetadata.java index ec5cdd1a42..3082c24b96 100644 --- a/providers/elastichosts-lax-p/src/main/java/org/jclouds/elastichosts/ElasticHostsPeer1LosAngelesProviderMetadata.java +++ b/providers/elastichosts-lax-p/src/main/java/org/jclouds/elastichosts/ElasticHostsPeer1LosAngelesProviderMetadata.java @@ -19,47 +19,73 @@ package org.jclouds.elastichosts; import java.net.URI; +import java.util.Properties; +import org.jclouds.compute.ComputeServiceContext; import org.jclouds.elasticstack.ElasticStackApiMetadata; -import org.jclouds.providers.BaseProviderMetadata; +import org.jclouds.elasticstack.ElasticStackAsyncClient; +import org.jclouds.elasticstack.ElasticStackClient; +import org.jclouds.providers.ProviderMetadata; +import org.jclouds.providers.internal.BaseProviderMetadata; /** - * Implementation of {@link org.jclouds.types.ProviderMetadata} for ElasticHosts Los Angeles Peer 1. - * + * Implementation of {@link org.jclouds.types.ProviderMetadata} for ElasticHosts LA Peer1. + + * * @author Adrian Cole */ -public class ElasticHostsPeer1LosAngelesProviderMetadata extends BaseProviderMetadata { +public class ElasticHostsPeer1LosAngelesProviderMetadata + extends + BaseProviderMetadata, ElasticStackApiMetadata> { - public ElasticHostsPeer1LosAngelesProviderMetadata() { - this(builder() - .id("elastichosts-lax-p") - .name("ElasticHosts Los Angeles Peer 1") - .api(new ElasticStackApiMetadata()) - .homepage(URI.create("https://lax-p.elastichosts.com")) - .console(URI.create("https://lax-p.elastichosts.com/accounts")) - .iso3166Codes("US-CA")); + public static Builder builder() { + return new Builder(); } - // below are so that we can reuse builders, toString, hashCode, etc. - // we have to set concrete classes here, as our base class cannot be - // concrete due to serviceLoader - protected ElasticHostsPeer1LosAngelesProviderMetadata(ConcreteBuilder builder) { + @Override + public Builder toBuilder() { + return builder().fromProviderMetadata(this); + } + + public ElasticHostsPeer1LosAngelesProviderMetadata() { + super(builder()); + } + + public ElasticHostsPeer1LosAngelesProviderMetadata(Builder builder) { super(builder); } - private static class ConcreteBuilder extends Builder { + protected static Properties defaultProperties() { + Properties properties = new Properties(); + return properties; + } + + public static class Builder + extends + BaseProviderMetadata.Builder, ElasticStackApiMetadata> { + + protected Builder() { + id("elastichosts-lax-p") + .name("ElasticHosts Los Angeles Peer 1") + .apiMetadata(new ElasticStackApiMetadata().toBuilder().version("2.0").build()) + .homepage(URI.create("https://lax-p.elastichosts.com")) + .console(URI.create("https://lax-p.elastichosts.com/accounts")) + .iso3166Codes("US-CA") + .endpoint("https://api.lax-p.elastichosts.com") + .defaultProperties(ElasticHostsPeer1LosAngelesProviderMetadata.defaultProperties()); + } @Override public ElasticHostsPeer1LosAngelesProviderMetadata build() { return new ElasticHostsPeer1LosAngelesProviderMetadata(this); } - } - public static ConcreteBuilder builder() { - return new ConcreteBuilder(); - } + @Override + public Builder fromProviderMetadata( + ProviderMetadata, ElasticStackApiMetadata> in) { + super.fromProviderMetadata(in); + return this; + } - public ConcreteBuilder toBuilder() { - return builder().fromProviderMetadata(this); } -} +} \ No newline at end of file diff --git a/providers/elastichosts-lax-p/src/test/java/org/jclouds/elastichosts/ElasticHostsPeer1LosAngelesProviderTest.java b/providers/elastichosts-lax-p/src/test/java/org/jclouds/elastichosts/ElasticHostsPeer1LosAngelesProviderTest.java index bc8e76310a..b7da04ee1e 100644 --- a/providers/elastichosts-lax-p/src/test/java/org/jclouds/elastichosts/ElasticHostsPeer1LosAngelesProviderTest.java +++ b/providers/elastichosts-lax-p/src/test/java/org/jclouds/elastichosts/ElasticHostsPeer1LosAngelesProviderTest.java @@ -19,7 +19,7 @@ package org.jclouds.elastichosts; import org.jclouds.elasticstack.ElasticStackApiMetadata; -import org.jclouds.providers.BaseProviderMetadataTest; +import org.jclouds.providers.internal.BaseProviderMetadataTest; import org.testng.annotations.Test; /** diff --git a/providers/elastichosts-lax-p/src/test/java/org/jclouds/elastichosts/compute/ElasticHostsPeer1LosAngelesTemplateBuilderLiveTest.java b/providers/elastichosts-lax-p/src/test/java/org/jclouds/elastichosts/compute/ElasticHostsPeer1LosAngelesTemplateBuilderLiveTest.java index b147769ba1..ca8d2a2d37 100644 --- a/providers/elastichosts-lax-p/src/test/java/org/jclouds/elastichosts/compute/ElasticHostsPeer1LosAngelesTemplateBuilderLiveTest.java +++ b/providers/elastichosts-lax-p/src/test/java/org/jclouds/elastichosts/compute/ElasticHostsPeer1LosAngelesTemplateBuilderLiveTest.java @@ -23,10 +23,13 @@ import static org.testng.Assert.assertEquals; import java.util.Set; -import org.jclouds.compute.BaseTemplateBuilderLiveTest; +import org.jclouds.compute.ComputeServiceContext; import org.jclouds.compute.domain.OsFamily; import org.jclouds.compute.domain.OsFamilyVersion64Bit; import org.jclouds.compute.domain.Template; +import org.jclouds.compute.internal.BaseTemplateBuilderLiveTest; +import org.jclouds.elasticstack.ElasticStackAsyncClient; +import org.jclouds.elasticstack.ElasticStackClient; import org.testng.annotations.Test; import com.google.common.base.Predicate; @@ -38,7 +41,9 @@ import com.google.common.collect.ImmutableSet; * @author Adrian Cole */ @Test(groups = "live") -public class ElasticHostsPeer1LosAngelesTemplateBuilderLiveTest extends BaseTemplateBuilderLiveTest { +public class ElasticHostsPeer1LosAngelesTemplateBuilderLiveTest + extends + BaseTemplateBuilderLiveTest> { public ElasticHostsPeer1LosAngelesTemplateBuilderLiveTest() { provider = "elastichosts-lax-p"; diff --git a/providers/elastichosts-lon-b/src/main/java/org/jclouds/elastichosts/ElasticHostsBlueSquareLondonPropertiesBuilder.java b/providers/elastichosts-lon-b/src/main/java/org/jclouds/elastichosts/ElasticHostsBlueSquareLondonPropertiesBuilder.java deleted file mode 100644 index 2bb4317db6..0000000000 --- a/providers/elastichosts-lon-b/src/main/java/org/jclouds/elastichosts/ElasticHostsBlueSquareLondonPropertiesBuilder.java +++ /dev/null @@ -1,48 +0,0 @@ -/** - * 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.elastichosts; - -import static org.jclouds.Constants.PROPERTY_API_VERSION; -import static org.jclouds.Constants.PROPERTY_ENDPOINT; -import static org.jclouds.Constants.PROPERTY_ISO3166_CODES; - -import java.util.Properties; - -import org.jclouds.elasticstack.ElasticStackPropertiesBuilder; - -/** - * - * @author Adrian Cole - */ -public class ElasticHostsBlueSquareLondonPropertiesBuilder extends ElasticStackPropertiesBuilder { - - @Override - protected Properties defaultProperties() { - Properties properties = super.defaultProperties(); - properties.setProperty(PROPERTY_ISO3166_CODES, "GB-LND"); - properties.setProperty(PROPERTY_ENDPOINT, "https://api.lon-b.elastichosts.com"); - properties.setProperty(PROPERTY_API_VERSION, "2.0"); - return properties; - } - - public ElasticHostsBlueSquareLondonPropertiesBuilder(Properties properties) { - super(properties); - } - -} diff --git a/providers/elastichosts-lon-b/src/main/java/org/jclouds/elastichosts/ElasticHostsBlueSquareLondonProviderMetadata.java b/providers/elastichosts-lon-b/src/main/java/org/jclouds/elastichosts/ElasticHostsBlueSquareLondonProviderMetadata.java index dcf1e4a97f..337650cc65 100644 --- a/providers/elastichosts-lon-b/src/main/java/org/jclouds/elastichosts/ElasticHostsBlueSquareLondonProviderMetadata.java +++ b/providers/elastichosts-lon-b/src/main/java/org/jclouds/elastichosts/ElasticHostsBlueSquareLondonProviderMetadata.java @@ -19,48 +19,71 @@ package org.jclouds.elastichosts; import java.net.URI; +import java.util.Properties; +import org.jclouds.compute.ComputeServiceContext; import org.jclouds.elasticstack.ElasticStackApiMetadata; -import org.jclouds.providers.BaseProviderMetadata; +import org.jclouds.elasticstack.ElasticStackAsyncClient; +import org.jclouds.elasticstack.ElasticStackClient; +import org.jclouds.providers.ProviderMetadata; +import org.jclouds.providers.internal.BaseProviderMetadata; /** * Implementation of {@link org.jclouds.types.ProviderMetadata} for ElasticHosts London BlueSquare. - * * @author Adrian Cole */ -public class ElasticHostsBlueSquareLondonProviderMetadata extends BaseProviderMetadata { +public class ElasticHostsBlueSquareLondonProviderMetadata + extends + BaseProviderMetadata, ElasticStackApiMetadata> { - public ElasticHostsBlueSquareLondonProviderMetadata() { - this(builder() - .id("elastichosts-lon-b") - .name("ElasticHosts Los Angeles BlueSquare") - .api(new ElasticStackApiMetadata()) - .homepage(URI.create("https://lon-b.elastichosts.com")) - .console(URI.create("https://lon-b.elastichosts.com/accounts")) - .iso3166Codes("GB-LND")); + public static Builder builder() { + return new Builder(); } - // below are so that we can reuse builders, toString, hashCode, etc. - // we have to set concrete classes here, as our base class cannot be - // concrete due to serviceLoader - protected ElasticHostsBlueSquareLondonProviderMetadata(ConcreteBuilder builder) { + @Override + public Builder toBuilder() { + return builder().fromProviderMetadata(this); + } + + public ElasticHostsBlueSquareLondonProviderMetadata() { + super(builder()); + } + + public ElasticHostsBlueSquareLondonProviderMetadata(Builder builder) { super(builder); } - private static class ConcreteBuilder extends Builder { + protected static Properties defaultProperties() { + Properties properties = new Properties(); + return properties; + } + + public static class Builder + extends + BaseProviderMetadata.Builder, ElasticStackApiMetadata> { + + protected Builder() { + id("elastichosts-lon-b") + .name("ElasticHosts Los Angeles BlueSquare") + .apiMetadata(new ElasticStackApiMetadata().toBuilder().version("2.0").build()) + .homepage(URI.create("https://lon-b.elastichosts.com")) + .console(URI.create("https://lon-b.elastichosts.com/accounts")) + .iso3166Codes("GB-LND") + .endpoint("https://api.lon-b.elastichosts.com") + .defaultProperties(ElasticHostsBlueSquareLondonProviderMetadata.defaultProperties()); + } @Override public ElasticHostsBlueSquareLondonProviderMetadata build() { return new ElasticHostsBlueSquareLondonProviderMetadata(this); } - } - public static ConcreteBuilder builder() { - return new ConcreteBuilder(); - } + @Override + public Builder fromProviderMetadata( + ProviderMetadata, ElasticStackApiMetadata> in) { + super.fromProviderMetadata(in); + return this; + } - public ConcreteBuilder toBuilder() { - return builder().fromProviderMetadata(this); } - -} +} \ No newline at end of file diff --git a/providers/elastichosts-lon-b/src/test/java/org/jclouds/elastichosts/ElasticHostsBlueSquareLondonProviderTest.java b/providers/elastichosts-lon-b/src/test/java/org/jclouds/elastichosts/ElasticHostsBlueSquareLondonProviderTest.java index b339d08d62..f063b94e1e 100644 --- a/providers/elastichosts-lon-b/src/test/java/org/jclouds/elastichosts/ElasticHostsBlueSquareLondonProviderTest.java +++ b/providers/elastichosts-lon-b/src/test/java/org/jclouds/elastichosts/ElasticHostsBlueSquareLondonProviderTest.java @@ -19,7 +19,7 @@ package org.jclouds.elastichosts; import org.jclouds.elasticstack.ElasticStackApiMetadata; -import org.jclouds.providers.BaseProviderMetadataTest; +import org.jclouds.providers.internal.BaseProviderMetadataTest; import org.testng.annotations.Test; /** diff --git a/providers/elastichosts-lon-b/src/test/java/org/jclouds/elastichosts/compute/ElasticHostsBlueSquareLondonTemplateBuilderLiveTest.java b/providers/elastichosts-lon-b/src/test/java/org/jclouds/elastichosts/compute/ElasticHostsBlueSquareLondonTemplateBuilderLiveTest.java index d6c32b5ab8..c530f30205 100644 --- a/providers/elastichosts-lon-b/src/test/java/org/jclouds/elastichosts/compute/ElasticHostsBlueSquareLondonTemplateBuilderLiveTest.java +++ b/providers/elastichosts-lon-b/src/test/java/org/jclouds/elastichosts/compute/ElasticHostsBlueSquareLondonTemplateBuilderLiveTest.java @@ -23,10 +23,13 @@ import static org.testng.Assert.assertEquals; import java.util.Set; -import org.jclouds.compute.BaseTemplateBuilderLiveTest; +import org.jclouds.compute.ComputeServiceContext; import org.jclouds.compute.domain.OsFamily; import org.jclouds.compute.domain.OsFamilyVersion64Bit; import org.jclouds.compute.domain.Template; +import org.jclouds.compute.internal.BaseTemplateBuilderLiveTest; +import org.jclouds.elasticstack.ElasticStackAsyncClient; +import org.jclouds.elasticstack.ElasticStackClient; import org.testng.annotations.Test; import com.google.common.base.Predicate; @@ -38,7 +41,9 @@ import com.google.common.collect.ImmutableSet; * @author Adrian Cole */ @Test(groups = "live") -public class ElasticHostsBlueSquareLondonTemplateBuilderLiveTest extends BaseTemplateBuilderLiveTest { +public class ElasticHostsBlueSquareLondonTemplateBuilderLiveTest + extends + BaseTemplateBuilderLiveTest> { public ElasticHostsBlueSquareLondonTemplateBuilderLiveTest() { provider = "elastichosts-lon-b"; diff --git a/providers/elastichosts-lon-p/src/main/java/org/jclouds/elastichosts/ElasticHostsPeer1LondonPropertiesBuilder.java b/providers/elastichosts-lon-p/src/main/java/org/jclouds/elastichosts/ElasticHostsPeer1LondonPropertiesBuilder.java deleted file mode 100644 index 7bd46cd68c..0000000000 --- a/providers/elastichosts-lon-p/src/main/java/org/jclouds/elastichosts/ElasticHostsPeer1LondonPropertiesBuilder.java +++ /dev/null @@ -1,48 +0,0 @@ -/** - * 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.elastichosts; - -import static org.jclouds.Constants.PROPERTY_API_VERSION; -import static org.jclouds.Constants.PROPERTY_ENDPOINT; -import static org.jclouds.Constants.PROPERTY_ISO3166_CODES; - -import java.util.Properties; - -import org.jclouds.elasticstack.ElasticStackPropertiesBuilder; - -/** - * - * @author Adrian Cole - */ -public class ElasticHostsPeer1LondonPropertiesBuilder extends ElasticStackPropertiesBuilder { - - @Override - protected Properties defaultProperties() { - Properties properties = super.defaultProperties(); - properties.setProperty(PROPERTY_ISO3166_CODES, "GB-LND"); - properties.setProperty(PROPERTY_ENDPOINT, "https://api.lon-p.elastichosts.com"); - properties.setProperty(PROPERTY_API_VERSION, "2.0"); - return properties; - } - - public ElasticHostsPeer1LondonPropertiesBuilder(Properties properties) { - super(properties); - } - -} diff --git a/providers/elastichosts-lon-p/src/main/java/org/jclouds/elastichosts/ElasticHostsPeer1LondonProviderMetadata.java b/providers/elastichosts-lon-p/src/main/java/org/jclouds/elastichosts/ElasticHostsPeer1LondonProviderMetadata.java index c68185e919..2987ee2cab 100644 --- a/providers/elastichosts-lon-p/src/main/java/org/jclouds/elastichosts/ElasticHostsPeer1LondonProviderMetadata.java +++ b/providers/elastichosts-lon-p/src/main/java/org/jclouds/elastichosts/ElasticHostsPeer1LondonProviderMetadata.java @@ -19,48 +19,72 @@ package org.jclouds.elastichosts; import java.net.URI; +import java.util.Properties; +import org.jclouds.compute.ComputeServiceContext; import org.jclouds.elasticstack.ElasticStackApiMetadata; -import org.jclouds.providers.BaseProviderMetadata; +import org.jclouds.elasticstack.ElasticStackAsyncClient; +import org.jclouds.elasticstack.ElasticStackClient; +import org.jclouds.providers.ProviderMetadata; +import org.jclouds.providers.internal.BaseProviderMetadata; /** * Implementation of {@link org.jclouds.types.ProviderMetadata} for ElasticHosts London Peer 1. - * + * * @author Adrian Cole */ -public class ElasticHostsPeer1LondonProviderMetadata extends BaseProviderMetadata { +public class ElasticHostsPeer1LondonProviderMetadata + extends + BaseProviderMetadata, ElasticStackApiMetadata> { - public ElasticHostsPeer1LondonProviderMetadata() { - this(builder() - .id("elastichosts-lon-p") - .name("ElasticHosts Los Angeles Peer 1") - .api(new ElasticStackApiMetadata()) - .homepage(URI.create("https://lon-p.elastichosts.com")) - .console(URI.create("https://lon-p.elastichosts.com/accounts")) - .iso3166Codes("GB-LND")); + public static Builder builder() { + return new Builder(); } - // below are so that we can reuse builders, toString, hashCode, etc. - // we have to set concrete classes here, as our base class cannot be - // concrete due to serviceLoader - protected ElasticHostsPeer1LondonProviderMetadata(ConcreteBuilder builder) { + @Override + public Builder toBuilder() { + return builder().fromProviderMetadata(this); + } + + public ElasticHostsPeer1LondonProviderMetadata() { + super(builder()); + } + + public ElasticHostsPeer1LondonProviderMetadata(Builder builder) { super(builder); } - private static class ConcreteBuilder extends Builder { + protected static Properties defaultProperties() { + Properties properties = new Properties(); + return properties; + } + + public static class Builder + extends + BaseProviderMetadata.Builder, ElasticStackApiMetadata> { + + protected Builder() { + id("elastichosts-lon-p") + .name("ElasticHosts London Peer 1") + .apiMetadata(new ElasticStackApiMetadata().toBuilder().version("2.0").build()) + .homepage(URI.create("https://lon-p.elastichosts.com")) + .console(URI.create("https://lon-p.elastichosts.com/accounts")) + .iso3166Codes("GB-LND") + .endpoint("https://api.lon-p.elastichosts.com") + .defaultProperties(ElasticHostsPeer1LondonProviderMetadata.defaultProperties()); + } @Override public ElasticHostsPeer1LondonProviderMetadata build() { return new ElasticHostsPeer1LondonProviderMetadata(this); } - } - public static ConcreteBuilder builder() { - return new ConcreteBuilder(); - } + @Override + public Builder fromProviderMetadata( + ProviderMetadata, ElasticStackApiMetadata> in) { + super.fromProviderMetadata(in); + return this; + } - public ConcreteBuilder toBuilder() { - return builder().fromProviderMetadata(this); } - -} +} \ No newline at end of file diff --git a/providers/elastichosts-lon-p/src/test/java/org/jclouds/elastichosts/ElasticHostsPeer1LondonProviderTest.java b/providers/elastichosts-lon-p/src/test/java/org/jclouds/elastichosts/ElasticHostsPeer1LondonProviderTest.java index 7763951a1e..3120e1c5e4 100644 --- a/providers/elastichosts-lon-p/src/test/java/org/jclouds/elastichosts/ElasticHostsPeer1LondonProviderTest.java +++ b/providers/elastichosts-lon-p/src/test/java/org/jclouds/elastichosts/ElasticHostsPeer1LondonProviderTest.java @@ -19,7 +19,7 @@ package org.jclouds.elastichosts; import org.jclouds.elasticstack.ElasticStackApiMetadata; -import org.jclouds.providers.BaseProviderMetadataTest; +import org.jclouds.providers.internal.BaseProviderMetadataTest; import org.testng.annotations.Test; /** diff --git a/providers/elastichosts-lon-p/src/test/java/org/jclouds/elastichosts/compute/ElasticHostsPeer1LondonTemplateBuilderLiveTest.java b/providers/elastichosts-lon-p/src/test/java/org/jclouds/elastichosts/compute/ElasticHostsPeer1LondonTemplateBuilderLiveTest.java index 184cf3b590..32dbc5fcc4 100644 --- a/providers/elastichosts-lon-p/src/test/java/org/jclouds/elastichosts/compute/ElasticHostsPeer1LondonTemplateBuilderLiveTest.java +++ b/providers/elastichosts-lon-p/src/test/java/org/jclouds/elastichosts/compute/ElasticHostsPeer1LondonTemplateBuilderLiveTest.java @@ -23,10 +23,13 @@ import static org.testng.Assert.assertEquals; import java.util.Set; -import org.jclouds.compute.BaseTemplateBuilderLiveTest; +import org.jclouds.compute.ComputeServiceContext; import org.jclouds.compute.domain.OsFamily; import org.jclouds.compute.domain.OsFamilyVersion64Bit; import org.jclouds.compute.domain.Template; +import org.jclouds.compute.internal.BaseTemplateBuilderLiveTest; +import org.jclouds.elasticstack.ElasticStackAsyncClient; +import org.jclouds.elasticstack.ElasticStackClient; import org.testng.annotations.Test; import com.google.common.base.Predicate; @@ -38,7 +41,9 @@ import com.google.common.collect.ImmutableSet; * @author Adrian Cole */ @Test(groups = "live") -public class ElasticHostsPeer1LondonTemplateBuilderLiveTest extends BaseTemplateBuilderLiveTest { +public class ElasticHostsPeer1LondonTemplateBuilderLiveTest + extends + BaseTemplateBuilderLiveTest> { public ElasticHostsPeer1LondonTemplateBuilderLiveTest() { provider = "elastichosts-lon-p"; diff --git a/providers/elastichosts-sat-p/src/main/java/org/jclouds/elastichosts/ElasticHostsPeer1SanAntonioPropertiesBuilder.java b/providers/elastichosts-sat-p/src/main/java/org/jclouds/elastichosts/ElasticHostsPeer1SanAntonioPropertiesBuilder.java deleted file mode 100644 index b6e2ad94e9..0000000000 --- a/providers/elastichosts-sat-p/src/main/java/org/jclouds/elastichosts/ElasticHostsPeer1SanAntonioPropertiesBuilder.java +++ /dev/null @@ -1,48 +0,0 @@ -/** - * 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.elastichosts; - -import static org.jclouds.Constants.PROPERTY_API_VERSION; -import static org.jclouds.Constants.PROPERTY_ENDPOINT; -import static org.jclouds.Constants.PROPERTY_ISO3166_CODES; - -import java.util.Properties; - -import org.jclouds.elasticstack.ElasticStackPropertiesBuilder; - -/** - * - * @author Adrian Cole - */ -public class ElasticHostsPeer1SanAntonioPropertiesBuilder extends ElasticStackPropertiesBuilder { - - @Override - protected Properties defaultProperties() { - Properties properties = super.defaultProperties(); - properties.setProperty(PROPERTY_ISO3166_CODES, "US-TX"); - properties.setProperty(PROPERTY_ENDPOINT, "https://api.sat-p.elastichosts.com"); - properties.setProperty(PROPERTY_API_VERSION, "2.0"); - return properties; - } - - public ElasticHostsPeer1SanAntonioPropertiesBuilder(Properties properties) { - super(properties); - } - -} diff --git a/providers/elastichosts-sat-p/src/main/java/org/jclouds/elastichosts/ElasticHostsPeer1SanAntonioProviderMetadata.java b/providers/elastichosts-sat-p/src/main/java/org/jclouds/elastichosts/ElasticHostsPeer1SanAntonioProviderMetadata.java index 3643598ebf..b79332d3f0 100644 --- a/providers/elastichosts-sat-p/src/main/java/org/jclouds/elastichosts/ElasticHostsPeer1SanAntonioProviderMetadata.java +++ b/providers/elastichosts-sat-p/src/main/java/org/jclouds/elastichosts/ElasticHostsPeer1SanAntonioProviderMetadata.java @@ -1,6 +1,6 @@ /** * Licensed to jclouds, Inc. (jclouds) under one or more - * contribusat license agreements. See the NOTICE file + * 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 @@ -19,47 +19,72 @@ package org.jclouds.elastichosts; import java.net.URI; +import java.util.Properties; +import org.jclouds.compute.ComputeServiceContext; import org.jclouds.elasticstack.ElasticStackApiMetadata; -import org.jclouds.providers.BaseProviderMetadata; +import org.jclouds.elasticstack.ElasticStackAsyncClient; +import org.jclouds.elasticstack.ElasticStackClient; +import org.jclouds.providers.ProviderMetadata; +import org.jclouds.providers.internal.BaseProviderMetadata; /** * Implementation of {@link org.jclouds.types.ProviderMetadata} for ElasticHosts San Antonio Peer 1. - * + * * @author Adrian Cole */ -public class ElasticHostsPeer1SanAntonioProviderMetadata extends BaseProviderMetadata { +public class ElasticHostsPeer1SanAntonioProviderMetadata + extends + BaseProviderMetadata, ElasticStackApiMetadata> { - public ElasticHostsPeer1SanAntonioProviderMetadata() { - this(builder() - .id("elastichosts-sat-p") - .name("ElasticHosts San Antonio Peer 1") - .api(new ElasticStackApiMetadata()) - .homepage(URI.create("https://sat-p.elastichosts.com")) - .console(URI.create("https://sat-p.elastichosts.com/accounts")) - .iso3166Codes("US-TX")); + public static Builder builder() { + return new Builder(); } - // below are so that we can reuse builders, toString, hashCode, etc. - // we have to set concrete classes here, as our base class cannot be - // concrete due to serviceLoader - protected ElasticHostsPeer1SanAntonioProviderMetadata(ConcreteBuilder builder) { + @Override + public Builder toBuilder() { + return builder().fromProviderMetadata(this); + } + + public ElasticHostsPeer1SanAntonioProviderMetadata() { + super(builder()); + } + + public ElasticHostsPeer1SanAntonioProviderMetadata(Builder builder) { super(builder); } - private static class ConcreteBuilder extends Builder { + protected static Properties defaultProperties() { + Properties properties = new Properties(); + return properties; + } + + public static class Builder + extends + BaseProviderMetadata.Builder, ElasticStackApiMetadata> { + + protected Builder() { + id("elastichosts-sat-p") + .name("ElasticHosts San Antonio Peer 1") + .apiMetadata(new ElasticStackApiMetadata().toBuilder().version("2.0").build()) + .homepage(URI.create("https://sat-p.elastichosts.com")) + .console(URI.create("https://sat-p.elastichosts.com/accounts")) + .iso3166Codes("US-TX") + .endpoint("https://api.sat-p.elastichosts.com") + .defaultProperties(ElasticHostsPeer1SanAntonioProviderMetadata.defaultProperties()); + } @Override public ElasticHostsPeer1SanAntonioProviderMetadata build() { return new ElasticHostsPeer1SanAntonioProviderMetadata(this); } - } - public static ConcreteBuilder builder() { - return new ConcreteBuilder(); - } + @Override + public Builder fromProviderMetadata( + ProviderMetadata, ElasticStackApiMetadata> in) { + super.fromProviderMetadata(in); + return this; + } - public ConcreteBuilder toBuilder() { - return builder().fromProviderMetadata(this); } } \ No newline at end of file diff --git a/providers/elastichosts-sat-p/src/test/java/org/jclouds/elastichosts/ElasticHostsPeer1SanAntonioProviderTest.java b/providers/elastichosts-sat-p/src/test/java/org/jclouds/elastichosts/ElasticHostsPeer1SanAntonioProviderTest.java index 9c6cae4531..58a7ed0880 100644 --- a/providers/elastichosts-sat-p/src/test/java/org/jclouds/elastichosts/ElasticHostsPeer1SanAntonioProviderTest.java +++ b/providers/elastichosts-sat-p/src/test/java/org/jclouds/elastichosts/ElasticHostsPeer1SanAntonioProviderTest.java @@ -19,7 +19,7 @@ package org.jclouds.elastichosts; import org.jclouds.elasticstack.ElasticStackApiMetadata; -import org.jclouds.providers.BaseProviderMetadataTest; +import org.jclouds.providers.internal.BaseProviderMetadataTest; import org.testng.annotations.Test; /** diff --git a/providers/elastichosts-sat-p/src/test/java/org/jclouds/elastichosts/compute/ElasticHostsPeer1SanAntonioTemplateBuilderLiveTest.java b/providers/elastichosts-sat-p/src/test/java/org/jclouds/elastichosts/compute/ElasticHostsPeer1SanAntonioTemplateBuilderLiveTest.java index 5a0030fca4..a33e8475ce 100644 --- a/providers/elastichosts-sat-p/src/test/java/org/jclouds/elastichosts/compute/ElasticHostsPeer1SanAntonioTemplateBuilderLiveTest.java +++ b/providers/elastichosts-sat-p/src/test/java/org/jclouds/elastichosts/compute/ElasticHostsPeer1SanAntonioTemplateBuilderLiveTest.java @@ -23,10 +23,13 @@ import static org.testng.Assert.assertEquals; import java.util.Set; -import org.jclouds.compute.BaseTemplateBuilderLiveTest; +import org.jclouds.compute.ComputeServiceContext; import org.jclouds.compute.domain.OsFamily; import org.jclouds.compute.domain.OsFamilyVersion64Bit; import org.jclouds.compute.domain.Template; +import org.jclouds.compute.internal.BaseTemplateBuilderLiveTest; +import org.jclouds.elasticstack.ElasticStackAsyncClient; +import org.jclouds.elasticstack.ElasticStackClient; import org.testng.annotations.Test; import com.google.common.base.Predicate; @@ -38,7 +41,9 @@ import com.google.common.collect.ImmutableSet; * @author Adrian Cole */ @Test(groups = "live") -public class ElasticHostsPeer1SanAntonioTemplateBuilderLiveTest extends BaseTemplateBuilderLiveTest { +public class ElasticHostsPeer1SanAntonioTemplateBuilderLiveTest + extends + BaseTemplateBuilderLiveTest> { public ElasticHostsPeer1SanAntonioTemplateBuilderLiveTest() { provider = "elastichosts-sat-p"; diff --git a/providers/elastichosts-tor-p/src/main/java/org/jclouds/elastichosts/ElasticHostsPeer1TorontoPropertiesBuilder.java b/providers/elastichosts-tor-p/src/main/java/org/jclouds/elastichosts/ElasticHostsPeer1TorontoPropertiesBuilder.java deleted file mode 100644 index a9f8b0f74c..0000000000 --- a/providers/elastichosts-tor-p/src/main/java/org/jclouds/elastichosts/ElasticHostsPeer1TorontoPropertiesBuilder.java +++ /dev/null @@ -1,48 +0,0 @@ -/** - * 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.elastichosts; - -import static org.jclouds.Constants.PROPERTY_API_VERSION; -import static org.jclouds.Constants.PROPERTY_ENDPOINT; -import static org.jclouds.Constants.PROPERTY_ISO3166_CODES; - -import java.util.Properties; - -import org.jclouds.elasticstack.ElasticStackPropertiesBuilder; - -/** - * - * @author Adrian Cole - */ -public class ElasticHostsPeer1TorontoPropertiesBuilder extends ElasticStackPropertiesBuilder { - - @Override - protected Properties defaultProperties() { - Properties properties = super.defaultProperties(); - properties.setProperty(PROPERTY_ISO3166_CODES, "CA-ON"); - properties.setProperty(PROPERTY_ENDPOINT, "https://api.tor-p.elastichosts.com"); - properties.setProperty(PROPERTY_API_VERSION, "2.0"); - return properties; - } - - public ElasticHostsPeer1TorontoPropertiesBuilder(Properties properties) { - super(properties); - } - -} diff --git a/providers/elastichosts-tor-p/src/main/java/org/jclouds/elastichosts/ElasticHostsPeer1TorontoProviderMetadata.java b/providers/elastichosts-tor-p/src/main/java/org/jclouds/elastichosts/ElasticHostsPeer1TorontoProviderMetadata.java index 921c42f40d..e857445271 100644 --- a/providers/elastichosts-tor-p/src/main/java/org/jclouds/elastichosts/ElasticHostsPeer1TorontoProviderMetadata.java +++ b/providers/elastichosts-tor-p/src/main/java/org/jclouds/elastichosts/ElasticHostsPeer1TorontoProviderMetadata.java @@ -19,47 +19,72 @@ package org.jclouds.elastichosts; import java.net.URI; +import java.util.Properties; +import org.jclouds.compute.ComputeServiceContext; import org.jclouds.elasticstack.ElasticStackApiMetadata; -import org.jclouds.providers.BaseProviderMetadata; +import org.jclouds.elasticstack.ElasticStackAsyncClient; +import org.jclouds.elasticstack.ElasticStackClient; +import org.jclouds.providers.ProviderMetadata; +import org.jclouds.providers.internal.BaseProviderMetadata; /** * Implementation of {@link org.jclouds.types.ProviderMetadata} for ElasticHosts Toronto Peer 1. - * + * * @author Adrian Cole */ -public class ElasticHostsPeer1TorontoProviderMetadata extends BaseProviderMetadata { +public class ElasticHostsPeer1TorontoProviderMetadata + extends + BaseProviderMetadata, ElasticStackApiMetadata> { - public ElasticHostsPeer1TorontoProviderMetadata() { - this(builder() - .id("elastichosts-tor-p") - .name("ElasticHosts Toronto Peer 1") - .api(new ElasticStackApiMetadata()) - .homepage(URI.create("https://tor-p.elastichosts.com")) - .console(URI.create("https://tor-p.elastichosts.com/accounts")) - .iso3166Codes("CA-ON")); + public static Builder builder() { + return new Builder(); } - // below are so that we can reuse builders, toString, hashCode, etc. - // we have to set concrete classes here, as our base class cannot be - // concrete due to serviceLoader - protected ElasticHostsPeer1TorontoProviderMetadata(ConcreteBuilder builder) { + @Override + public Builder toBuilder() { + return builder().fromProviderMetadata(this); + } + + public ElasticHostsPeer1TorontoProviderMetadata() { + super(builder()); + } + + public ElasticHostsPeer1TorontoProviderMetadata(Builder builder) { super(builder); } - private static class ConcreteBuilder extends Builder { + protected static Properties defaultProperties() { + Properties properties = new Properties(); + return properties; + } + + public static class Builder + extends + BaseProviderMetadata.Builder, ElasticStackApiMetadata> { + + protected Builder() { + id("elastichosts-tor-p") + .name("ElasticHosts Toronto Peer 1") + .apiMetadata(new ElasticStackApiMetadata().toBuilder().version("2.0").build()) + .homepage(URI.create("https://tor-p.elastichosts.com")) + .console(URI.create("https://tor-p.elastichosts.com/accounts")) + .iso3166Codes("CA-ON") + .endpoint("https://api.tor-p.elastichosts.com") + .defaultProperties(ElasticHostsPeer1TorontoProviderMetadata.defaultProperties()); + } @Override public ElasticHostsPeer1TorontoProviderMetadata build() { return new ElasticHostsPeer1TorontoProviderMetadata(this); } - } - public static ConcreteBuilder builder() { - return new ConcreteBuilder(); - } + @Override + public Builder fromProviderMetadata( + ProviderMetadata, ElasticStackApiMetadata> in) { + super.fromProviderMetadata(in); + return this; + } - public ConcreteBuilder toBuilder() { - return builder().fromProviderMetadata(this); } } \ No newline at end of file diff --git a/providers/elastichosts-tor-p/src/test/java/org/jclouds/elastichosts/ElasticHostsPeer1TorontoProviderTest.java b/providers/elastichosts-tor-p/src/test/java/org/jclouds/elastichosts/ElasticHostsPeer1TorontoProviderTest.java index 9164406b60..a6ba3ec342 100644 --- a/providers/elastichosts-tor-p/src/test/java/org/jclouds/elastichosts/ElasticHostsPeer1TorontoProviderTest.java +++ b/providers/elastichosts-tor-p/src/test/java/org/jclouds/elastichosts/ElasticHostsPeer1TorontoProviderTest.java @@ -19,7 +19,7 @@ package org.jclouds.elastichosts; import org.jclouds.elasticstack.ElasticStackApiMetadata; -import org.jclouds.providers.BaseProviderMetadataTest; +import org.jclouds.providers.internal.BaseProviderMetadataTest; import org.testng.annotations.Test; /** diff --git a/providers/elastichosts-tor-p/src/test/java/org/jclouds/elastichosts/compute/ElasticHostsPeer1TorontoTemplateBuilderLiveTest.java b/providers/elastichosts-tor-p/src/test/java/org/jclouds/elastichosts/compute/ElasticHostsPeer1TorontoTemplateBuilderLiveTest.java index 103b0ec4ef..f98bb35b5d 100644 --- a/providers/elastichosts-tor-p/src/test/java/org/jclouds/elastichosts/compute/ElasticHostsPeer1TorontoTemplateBuilderLiveTest.java +++ b/providers/elastichosts-tor-p/src/test/java/org/jclouds/elastichosts/compute/ElasticHostsPeer1TorontoTemplateBuilderLiveTest.java @@ -23,10 +23,13 @@ import static org.testng.Assert.assertEquals; import java.util.Set; -import org.jclouds.compute.BaseTemplateBuilderLiveTest; +import org.jclouds.compute.ComputeServiceContext; import org.jclouds.compute.domain.OsFamily; import org.jclouds.compute.domain.OsFamilyVersion64Bit; import org.jclouds.compute.domain.Template; +import org.jclouds.compute.internal.BaseTemplateBuilderLiveTest; +import org.jclouds.elasticstack.ElasticStackAsyncClient; +import org.jclouds.elasticstack.ElasticStackClient; import org.testng.annotations.Test; import com.google.common.base.Predicate; @@ -38,7 +41,9 @@ import com.google.common.collect.ImmutableSet; * @author Adrian Cole */ @Test(groups = "live") -public class ElasticHostsPeer1TorontoTemplateBuilderLiveTest extends BaseTemplateBuilderLiveTest { +public class ElasticHostsPeer1TorontoTemplateBuilderLiveTest + extends + BaseTemplateBuilderLiveTest> { public ElasticHostsPeer1TorontoTemplateBuilderLiveTest() { provider = "elastichosts-tor-p"; diff --git a/providers/eucalyptus-partnercloud-ec2/src/main/java/org/jclouds/epc/EucalyptusPartnerCloudContextBuilder.java b/providers/eucalyptus-partnercloud-ec2/src/main/java/org/jclouds/epc/EucalyptusPartnerCloudContextBuilder.java index 8b129e06c8..97b22136f1 100644 --- a/providers/eucalyptus-partnercloud-ec2/src/main/java/org/jclouds/epc/EucalyptusPartnerCloudContextBuilder.java +++ b/providers/eucalyptus-partnercloud-ec2/src/main/java/org/jclouds/epc/EucalyptusPartnerCloudContextBuilder.java @@ -19,10 +19,14 @@ package org.jclouds.epc; import java.util.List; -import java.util.Properties; +import org.jclouds.ec2.EC2AsyncClient; +import org.jclouds.ec2.EC2Client; import org.jclouds.ec2.EC2ContextBuilder; +import org.jclouds.ec2.compute.EC2ComputeServiceContext; import org.jclouds.epc.config.EucalyptusPartnerCloudComputeServiceContextModule; +import org.jclouds.eucalyptus.EucalyptusApiMetadata; +import org.jclouds.providers.ProviderMetadata; import com.google.inject.Module; @@ -30,10 +34,14 @@ import com.google.inject.Module; * * @author Adrian Cole */ -public class EucalyptusPartnerCloudContextBuilder extends EC2ContextBuilder { +public class EucalyptusPartnerCloudContextBuilder extends EC2ContextBuilder, EucalyptusApiMetadata> { - public EucalyptusPartnerCloudContextBuilder(Properties props) { - super(props); + public EucalyptusPartnerCloudContextBuilder(ProviderMetadata, EucalyptusApiMetadata> providerMetadata) { + super(providerMetadata); + } + + public EucalyptusPartnerCloudContextBuilder(EucalyptusApiMetadata apiMetadata) { + super(apiMetadata); } @Override diff --git a/providers/eucalyptus-partnercloud-ec2/src/main/java/org/jclouds/epc/EucalyptusPartnerCloudEC2ProviderMetadata.java b/providers/eucalyptus-partnercloud-ec2/src/main/java/org/jclouds/epc/EucalyptusPartnerCloudEC2ProviderMetadata.java index ebac17f28f..1f9b118e77 100644 --- a/providers/eucalyptus-partnercloud-ec2/src/main/java/org/jclouds/epc/EucalyptusPartnerCloudEC2ProviderMetadata.java +++ b/providers/eucalyptus-partnercloud-ec2/src/main/java/org/jclouds/epc/EucalyptusPartnerCloudEC2ProviderMetadata.java @@ -18,51 +18,80 @@ */ package org.jclouds.epc; -import java.net.URI; +import static org.jclouds.location.reference.LocationConstants.ISO3166_CODES; +import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGION; +import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGIONS; +import java.net.URI; +import java.util.Properties; + +import org.jclouds.ec2.EC2AsyncClient; +import org.jclouds.ec2.EC2Client; +import org.jclouds.ec2.compute.EC2ComputeServiceContext; import org.jclouds.eucalyptus.EucalyptusApiMetadata; -import org.jclouds.providers.BaseProviderMetadata; +import org.jclouds.providers.ProviderMetadata; +import org.jclouds.providers.internal.BaseProviderMetadata; + +import com.google.common.reflect.TypeToken; /** - * Implementation of {@ link org.jclouds.types.ProviderMetadata} for Eucalpytus' - * Partner Cloud EC2 provider. + * Implementation of {@link org.jclouds.providers.ProviderMetadata} for Eucalyptus Partner Cloud EC2. * - * @author Jeremy Whitlock + * @author Adrian Cole */ -public class EucalyptusPartnerCloudEC2ProviderMetadata extends BaseProviderMetadata { - - public EucalyptusPartnerCloudEC2ProviderMetadata() { - this(builder() - .id("eucalyptus-partnercloud-ec2") - .name("Eucalyptus Partner Cloud (EC2)") - .api(new EucalyptusApiMetadata()) - .homepage(URI.create("http://www.eucalyptus.com/partners")) - .console(URI.create("https://partnercloud.eucalyptus.com:8443")) - .linkedServices("eucalyptus-partnercloud-ec2", "eucalyptus-partnercloud-s3") - .iso3166Codes("US-CA")); +public class EucalyptusPartnerCloudEC2ProviderMetadata extends BaseProviderMetadata, EucalyptusApiMetadata> { + + public static Builder builder() { + return new Builder(); } - // below are so that we can reuse builders, toString, hashCode, etc. - // we have to set concrete classes here, as our base class cannot be - // concrete due to serviceLoader - protected EucalyptusPartnerCloudEC2ProviderMetadata(ConcreteBuilder builder) { + @Override + public Builder toBuilder() { + return builder().fromProviderMetadata(this); + } + + public EucalyptusPartnerCloudEC2ProviderMetadata() { + super(builder()); + } + + public EucalyptusPartnerCloudEC2ProviderMetadata(Builder builder) { super(builder); } - private static class ConcreteBuilder extends Builder { + protected static Properties defaultProperties() { + Properties properties = new Properties(); + properties.setProperty(PROPERTY_REGIONS, "Eucalyptus"); + properties.setProperty(PROPERTY_REGION + ".Eucalyptus." + ISO3166_CODES, "US-CA"); + properties.setProperty("eucalyptus-partnercloud-ec2.virtualization-type", "kvm"); + return properties; + } + + public static class Builder extends BaseProviderMetadata.Builder, EucalyptusApiMetadata> { + + protected Builder(){ + id("eucalyptus-partnercloud-ec2") + .name("Eucalyptus Partner Cloud (EC2)") + .apiMetadata( + new EucalyptusApiMetadata().toBuilder() + .contextBuilder(TypeToken.of(EucalyptusPartnerCloudContextBuilder.class)).build()) + .homepage(URI.create("http://www.eucalyptus.com/partners")) + .console(URI.create("https://partnercloud.eucalyptus.com:8443")) + .linkedServices("eucalyptus-partnercloud-ec2", "eucalyptus-partnercloud-s3") + .iso3166Codes("US-CA") + .endpoint("http://partnercloud.eucalyptus.com:8773/services/Eucalyptus") + .defaultProperties(EucalyptusPartnerCloudEC2ProviderMetadata.defaultProperties()); + } @Override public EucalyptusPartnerCloudEC2ProviderMetadata build() { return new EucalyptusPartnerCloudEC2ProviderMetadata(this); } + + @Override + public Builder fromProviderMetadata( + ProviderMetadata, EucalyptusApiMetadata> in) { + super.fromProviderMetadata(in); + return this; + } } - - public static ConcreteBuilder builder() { - return new ConcreteBuilder(); - } - - public ConcreteBuilder toBuilder() { - return builder().fromProviderMetadata(this); - } - -} +} \ No newline at end of file diff --git a/providers/eucalyptus-partnercloud-ec2/src/main/java/org/jclouds/epc/EucalyptusPartnerCloudPropertiesBuilder.java b/providers/eucalyptus-partnercloud-ec2/src/main/java/org/jclouds/epc/EucalyptusPartnerCloudPropertiesBuilder.java deleted file mode 100644 index dfccfef7a5..0000000000 --- a/providers/eucalyptus-partnercloud-ec2/src/main/java/org/jclouds/epc/EucalyptusPartnerCloudPropertiesBuilder.java +++ /dev/null @@ -1,53 +0,0 @@ -/** - * 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.epc; - -import static org.jclouds.Constants.PROPERTY_ENDPOINT; -import static org.jclouds.Constants.PROPERTY_ISO3166_CODES; -import static org.jclouds.location.reference.LocationConstants.ISO3166_CODES; -import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGION; -import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGIONS; - -import java.util.Properties; - -import org.jclouds.eucalyptus.EucalyptusPropertiesBuilder; - -/** - * Builds properties used in EucalyptusPartnerCloudEucalyptus Clients - * - * @author Adrian Cole - */ -public class EucalyptusPartnerCloudPropertiesBuilder extends EucalyptusPropertiesBuilder { - - @Override - protected Properties defaultProperties() { - Properties properties = super.defaultProperties(); - properties.setProperty(PROPERTY_REGIONS, "Eucalyptus"); - properties.setProperty(PROPERTY_ISO3166_CODES, "US-CA"); - properties.setProperty(PROPERTY_REGION + ".Eucalyptus." + ISO3166_CODES, "US-CA"); - properties.setProperty("eucalyptus-partnercloud-ec2.virtualization-type", "kvm"); - properties.setProperty(PROPERTY_ENDPOINT, "http://partnercloud.eucalyptus.com:8773/services/Eucalyptus"); - return properties; - } - - public EucalyptusPartnerCloudPropertiesBuilder(Properties properties) { - super(properties); - } - -} diff --git a/providers/eucalyptus-partnercloud-ec2/src/test/java/org/jclouds/epc/EucalyptusPartnerCloudEC2ProviderTest.java b/providers/eucalyptus-partnercloud-ec2/src/test/java/org/jclouds/epc/EucalyptusPartnerCloudEC2ProviderTest.java index 54292a806b..a4c754a2a9 100644 --- a/providers/eucalyptus-partnercloud-ec2/src/test/java/org/jclouds/epc/EucalyptusPartnerCloudEC2ProviderTest.java +++ b/providers/eucalyptus-partnercloud-ec2/src/test/java/org/jclouds/epc/EucalyptusPartnerCloudEC2ProviderTest.java @@ -19,7 +19,7 @@ package org.jclouds.epc; import org.jclouds.eucalyptus.EucalyptusApiMetadata; -import org.jclouds.providers.BaseProviderMetadataTest; +import org.jclouds.providers.internal.BaseProviderMetadataTest; import org.testng.annotations.Test; /** diff --git a/providers/eucalyptus-partnercloud-ec2/src/test/java/org/jclouds/epc/compute/EucalyptusPartnerCloudEucalyptusTemplateBuilderLiveTest.java b/providers/eucalyptus-partnercloud-ec2/src/test/java/org/jclouds/epc/compute/EucalyptusPartnerCloudEucalyptusTemplateBuilderLiveTest.java index af0f11b69b..8dc7b80f28 100644 --- a/providers/eucalyptus-partnercloud-ec2/src/test/java/org/jclouds/epc/compute/EucalyptusPartnerCloudEucalyptusTemplateBuilderLiveTest.java +++ b/providers/eucalyptus-partnercloud-ec2/src/test/java/org/jclouds/epc/compute/EucalyptusPartnerCloudEucalyptusTemplateBuilderLiveTest.java @@ -25,11 +25,14 @@ import java.io.IOException; import java.util.Set; import org.jclouds.aws.util.AWSUtils; +import org.jclouds.compute.ComputeServiceContext; import org.jclouds.compute.domain.OsFamily; import org.jclouds.compute.domain.OsFamilyVersion64Bit; import org.jclouds.compute.domain.Template; +import org.jclouds.compute.internal.BaseTemplateBuilderLiveTest; import org.jclouds.domain.LocationScope; -import org.jclouds.ec2.compute.EC2TemplateBuilderLiveTest; +import org.jclouds.ec2.EC2AsyncClient; +import org.jclouds.ec2.EC2Client; import org.jclouds.ec2.compute.util.EC2ComputeUtils; import org.testng.annotations.Test; @@ -42,7 +45,8 @@ import com.google.common.collect.ImmutableSet; * @author Adrian Cole */ @Test(groups = "live") -public class EucalyptusPartnerCloudEucalyptusTemplateBuilderLiveTest extends EC2TemplateBuilderLiveTest { +public class EucalyptusPartnerCloudEucalyptusTemplateBuilderLiveTest extends + BaseTemplateBuilderLiveTest> { public EucalyptusPartnerCloudEucalyptusTemplateBuilderLiveTest() { provider = "eucalyptus-partnercloud-ec2"; diff --git a/providers/eucalyptus-partnercloud-s3/pom.xml b/providers/eucalyptus-partnercloud-s3/pom.xml index 0fa8f0d78c..543407cc2b 100644 --- a/providers/eucalyptus-partnercloud-s3/pom.xml +++ b/providers/eucalyptus-partnercloud-s3/pom.xml @@ -34,7 +34,6 @@ bundle - org.jclouds.epc.blobstore.EucalyptusPartnerCloudWalrusTestInitializer http://partnercloud.eucalyptus.com:8773/services/Walrus 2006-03-01 @@ -115,7 +114,6 @@ ${test.eucalyptus-partnercloud-s3.build-version} ${test.eucalyptus-partnercloud-s3.identity} ${test.eucalyptus-partnercloud-s3.credential} - ${test.initializer} ${jclouds.blobstore.httpstream.url} ${jclouds.blobstore.httpstream.md5} ${test.blobstore.container-count} diff --git a/providers/eucalyptus-partnercloud-s3/src/main/java/org/jclouds/epc/EucalyptusPartnerCloudS3ProviderMetadata.java b/providers/eucalyptus-partnercloud-s3/src/main/java/org/jclouds/epc/EucalyptusPartnerCloudS3ProviderMetadata.java index 9afe679fd5..5664afa0b5 100644 --- a/providers/eucalyptus-partnercloud-s3/src/main/java/org/jclouds/epc/EucalyptusPartnerCloudS3ProviderMetadata.java +++ b/providers/eucalyptus-partnercloud-s3/src/main/java/org/jclouds/epc/EucalyptusPartnerCloudS3ProviderMetadata.java @@ -18,51 +18,79 @@ */ package org.jclouds.epc; -import java.net.URI; +import static org.jclouds.Constants.PROPERTY_ISO3166_CODES; +import static org.jclouds.location.reference.LocationConstants.ENDPOINT; +import static org.jclouds.location.reference.LocationConstants.ISO3166_CODES; +import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGION; +import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGIONS; -import org.jclouds.providers.BaseProviderMetadata; +import java.net.URI; +import java.util.Properties; + +import org.jclouds.providers.ProviderMetadata; +import org.jclouds.providers.internal.BaseProviderMetadata; +import org.jclouds.s3.S3AsyncClient; +import org.jclouds.s3.S3Client; +import org.jclouds.s3.blobstore.S3BlobStoreContext; import org.jclouds.walrus.WalrusApiMetadata; /** - * Implementation of {@ link org.jclouds.types.ProviderMetadata} for Eucalpytus' - * Partner Cloud S3 provider. + * Implementation of {@link org.jclouds.providers.ProviderMetadata} for Eucalyptus Partner Cloud S3. * - * @author Jeremy Whitlock + * @author Adrian Cole */ -public class EucalyptusPartnerCloudS3ProviderMetadata extends BaseProviderMetadata { - - public EucalyptusPartnerCloudS3ProviderMetadata() { - this(builder() - .id("eucalyptus-partnercloud-s3") - .name("Eucalyptus Partner Cloud (S3)") - .api(new WalrusApiMetadata()) - .homepage(URI.create("http://www.eucalyptus.com/partners")) - .console(URI.create("https://partnercloud.eucalyptus.com:8443")) - .linkedServices("eucalyptus-partnercloud-s3", "eucalyptus-partnercloud-s3") - .iso3166Codes("US-CA")); +public class EucalyptusPartnerCloudS3ProviderMetadata extends BaseProviderMetadata, WalrusApiMetadata> { + + public static Builder builder() { + return new Builder(); } - // below are so that we can reuse builders, toString, hashCode, etc. - // we have to set concrete classes here, as our base class cannot be - // concrete due to serviceLoader - protected EucalyptusPartnerCloudS3ProviderMetadata(ConcreteBuilder builder) { + @Override + public Builder toBuilder() { + return builder().fromProviderMetadata(this); + } + + public EucalyptusPartnerCloudS3ProviderMetadata() { + super(builder()); + } + + public EucalyptusPartnerCloudS3ProviderMetadata(Builder builder) { super(builder); } - private static class ConcreteBuilder extends Builder { + protected static Properties defaultProperties() { + Properties properties = new Properties(); + properties.setProperty(PROPERTY_REGIONS, "Walrus"); + properties.setProperty(PROPERTY_ISO3166_CODES, "US-CA"); + properties.setProperty(PROPERTY_REGION + ".Walrus." + ISO3166_CODES, "US-CA"); + properties.setProperty(PROPERTY_REGION + "." + "Walrus" + "." + ENDPOINT, "http://partnercloud.eucalyptus.com:8773/services/Walrus"); + return properties; + } + + public static class Builder extends BaseProviderMetadata.Builder, WalrusApiMetadata> { + + protected Builder(){ + id("eucalyptus-partnercloud-s3") + .name("Eucalyptus Partner Cloud (S3)") + .apiMetadata(new WalrusApiMetadata()) + .homepage(URI.create("http://www.eucalyptus.com/partners")) + .console(URI.create("https://partnercloud.eucalyptus.com:8443")) + .linkedServices("eucalyptus-partnercloud-ec2", "eucalyptus-partnercloud-s3") + .iso3166Codes("US-CA") + .endpoint("http://partnercloud.eucalyptus.com:8773/services/Walrus") + .defaultProperties(EucalyptusPartnerCloudS3ProviderMetadata.defaultProperties()); + } @Override public EucalyptusPartnerCloudS3ProviderMetadata build() { return new EucalyptusPartnerCloudS3ProviderMetadata(this); } + + @Override + public Builder fromProviderMetadata( + ProviderMetadata, WalrusApiMetadata> in) { + super.fromProviderMetadata(in); + return this; + } } - - public static ConcreteBuilder builder() { - return new ConcreteBuilder(); - } - - public ConcreteBuilder toBuilder() { - return builder().fromProviderMetadata(this); - } - -} +} \ No newline at end of file diff --git a/providers/eucalyptus-partnercloud-s3/src/main/java/org/jclouds/epc/EucalyptusPartnerCloudWalrusPropertiesBuilder.java b/providers/eucalyptus-partnercloud-s3/src/main/java/org/jclouds/epc/EucalyptusPartnerCloudWalrusPropertiesBuilder.java deleted file mode 100644 index b89f95ba0e..0000000000 --- a/providers/eucalyptus-partnercloud-s3/src/main/java/org/jclouds/epc/EucalyptusPartnerCloudWalrusPropertiesBuilder.java +++ /dev/null @@ -1,53 +0,0 @@ -/** - * 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.epc; - -import static org.jclouds.Constants.PROPERTY_ENDPOINT; -import static org.jclouds.Constants.PROPERTY_ISO3166_CODES; -import static org.jclouds.location.reference.LocationConstants.ENDPOINT; -import static org.jclouds.location.reference.LocationConstants.ISO3166_CODES; -import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGION; -import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGIONS; - -import java.util.Properties; - -import org.jclouds.walrus.WalrusPropertiesBuilder; - -/** - * Builds properties used in EucalyptusPartnerCloudWalrus Clients - * - * @author Adrian Cole - */ -public class EucalyptusPartnerCloudWalrusPropertiesBuilder extends WalrusPropertiesBuilder { - @Override - protected Properties defaultProperties() { - Properties properties = super.defaultProperties(); - properties.setProperty(PROPERTY_REGIONS, "Walrus"); - properties.setProperty(PROPERTY_ISO3166_CODES, "US-CA"); - properties.setProperty(PROPERTY_REGION + ".Walrus." + ISO3166_CODES, "US-CA"); - properties.setProperty(PROPERTY_ENDPOINT, "http://partnercloud.eucalyptus.com:8773/services/Walrus"); - properties.setProperty(PROPERTY_REGION + "." + "Walrus" + "." + ENDPOINT, "http://partnercloud.eucalyptus.com:8773/services/Walrus"); - return properties; - } - - public EucalyptusPartnerCloudWalrusPropertiesBuilder(Properties properties) { - super(properties); - } - -} diff --git a/providers/eucalyptus-partnercloud-s3/src/test/java/org/jclouds/epc/EucalyptusPartnerCloudS3ProviderTest.java b/providers/eucalyptus-partnercloud-s3/src/test/java/org/jclouds/epc/EucalyptusPartnerCloudS3ProviderTest.java index cfdabb7d1c..9dcce9d453 100644 --- a/providers/eucalyptus-partnercloud-s3/src/test/java/org/jclouds/epc/EucalyptusPartnerCloudS3ProviderTest.java +++ b/providers/eucalyptus-partnercloud-s3/src/test/java/org/jclouds/epc/EucalyptusPartnerCloudS3ProviderTest.java @@ -18,7 +18,7 @@ */ package org.jclouds.epc; -import org.jclouds.providers.BaseProviderMetadataTest; +import org.jclouds.providers.internal.BaseProviderMetadataTest; import org.jclouds.walrus.WalrusApiMetadata; import org.testng.annotations.Test; diff --git a/providers/eucalyptus-partnercloud-s3/src/test/java/org/jclouds/epc/EucalyptusPartnerCloudWalrusAsyncClientTestDisabled.java b/providers/eucalyptus-partnercloud-s3/src/test/java/org/jclouds/epc/EucalyptusPartnerCloudWalrusAsyncClientTestDisabled.java deleted file mode 100644 index f3fb38e4d4..0000000000 --- a/providers/eucalyptus-partnercloud-s3/src/test/java/org/jclouds/epc/EucalyptusPartnerCloudWalrusAsyncClientTestDisabled.java +++ /dev/null @@ -1,36 +0,0 @@ -/** - * 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.epc; - -import org.testng.annotations.Test; - -/** - * @author Adrian Cole - */ -// NOTE:without testName, this will not call @Before* and fail w/NPE during surefire -@Test(enabled = false, groups = "unit", testName = "EucalyptusPartnerCloudWalrusAsyncClientTest") -public class EucalyptusPartnerCloudWalrusAsyncClientTestDisabled extends org.jclouds.walrus.WalrusAsyncClientTestDisabled { - - public EucalyptusPartnerCloudWalrusAsyncClientTestDisabled() { - this.provider = "eucalyptus-partnercloud-s3"; - this.url = "https://partnercloud.eucalyptus.com:8773/services/Walrus"; - } - - // TODO parameterize this test so that it can pass -} diff --git a/providers/eucalyptus-partnercloud-s3/src/test/java/org/jclouds/epc/blobstore/EucalyptusPartnerCloudWalrusBlobIntegrationLiveTest.java b/providers/eucalyptus-partnercloud-s3/src/test/java/org/jclouds/epc/blobstore/EucalyptusPartnerCloudWalrusBlobIntegrationLiveTest.java index 543858aef1..7f502e279e 100644 --- a/providers/eucalyptus-partnercloud-s3/src/test/java/org/jclouds/epc/blobstore/EucalyptusPartnerCloudWalrusBlobIntegrationLiveTest.java +++ b/providers/eucalyptus-partnercloud-s3/src/test/java/org/jclouds/epc/blobstore/EucalyptusPartnerCloudWalrusBlobIntegrationLiveTest.java @@ -27,4 +27,7 @@ import org.testng.annotations.Test; @Test(groups = "live", testName = "EucalyptusPartnerCloudWalrusBlobIntegrationLiveTest") public class EucalyptusPartnerCloudWalrusBlobIntegrationLiveTest extends WalrusBlobIntegrationLiveTest { + public EucalyptusPartnerCloudWalrusBlobIntegrationLiveTest() { + provider = "eucalyptus-partnercloud-s3"; + } } diff --git a/providers/eucalyptus-partnercloud-s3/src/test/java/org/jclouds/epc/blobstore/EucalyptusPartnerCloudWalrusBlobLiveTest.java b/providers/eucalyptus-partnercloud-s3/src/test/java/org/jclouds/epc/blobstore/EucalyptusPartnerCloudWalrusBlobLiveTest.java index 719a911d21..aa3660d613 100644 --- a/providers/eucalyptus-partnercloud-s3/src/test/java/org/jclouds/epc/blobstore/EucalyptusPartnerCloudWalrusBlobLiveTest.java +++ b/providers/eucalyptus-partnercloud-s3/src/test/java/org/jclouds/epc/blobstore/EucalyptusPartnerCloudWalrusBlobLiveTest.java @@ -24,7 +24,10 @@ import org.testng.annotations.Test; /** * @author Adrian Cole */ -@Test(groups = "live", testName = "EucalyptusPartnerCloudWalrusBlobLiveTest") +@Test(groups = "live", testName = "EucalyptusPartnerCloudWalrusBlobLiveTest") public class EucalyptusPartnerCloudWalrusBlobLiveTest extends WalrusBlobLiveTest { + public EucalyptusPartnerCloudWalrusBlobLiveTest() { + provider = "eucalyptus-partnercloud-s3"; + } } diff --git a/providers/eucalyptus-partnercloud-s3/src/test/java/org/jclouds/epc/blobstore/EucalyptusPartnerCloudWalrusBlobMapIntegrationLiveTest.java b/providers/eucalyptus-partnercloud-s3/src/test/java/org/jclouds/epc/blobstore/EucalyptusPartnerCloudWalrusBlobMapIntegrationLiveTest.java index ca4cdcc542..5ad504c3ef 100644 --- a/providers/eucalyptus-partnercloud-s3/src/test/java/org/jclouds/epc/blobstore/EucalyptusPartnerCloudWalrusBlobMapIntegrationLiveTest.java +++ b/providers/eucalyptus-partnercloud-s3/src/test/java/org/jclouds/epc/blobstore/EucalyptusPartnerCloudWalrusBlobMapIntegrationLiveTest.java @@ -24,6 +24,10 @@ import org.testng.annotations.Test; /** * @author Adrian Cole */ -@Test(groups = "live", testName = "EucalyptusPartnerCloudWalrusBlobMapIntegrationLiveTest") +@Test(groups = "live", testName = "EucalyptusPartnerCloudWalrusBlobMapIntegrationLiveTest") public class EucalyptusPartnerCloudWalrusBlobMapIntegrationLiveTest extends WalrusBlobMapIntegrationLiveTest { + + public EucalyptusPartnerCloudWalrusBlobMapIntegrationLiveTest() { + provider = "eucalyptus-partnercloud-s3"; + } } diff --git a/providers/eucalyptus-partnercloud-s3/src/test/java/org/jclouds/epc/blobstore/EucalyptusPartnerCloudWalrusBlobSignerLiveTest.java b/providers/eucalyptus-partnercloud-s3/src/test/java/org/jclouds/epc/blobstore/EucalyptusPartnerCloudWalrusBlobSignerLiveTest.java index c4a536a59f..4e239593a7 100644 --- a/providers/eucalyptus-partnercloud-s3/src/test/java/org/jclouds/epc/blobstore/EucalyptusPartnerCloudWalrusBlobSignerLiveTest.java +++ b/providers/eucalyptus-partnercloud-s3/src/test/java/org/jclouds/epc/blobstore/EucalyptusPartnerCloudWalrusBlobSignerLiveTest.java @@ -25,7 +25,10 @@ import org.testng.annotations.Test; * * @author Adrian Cole */ -@Test(groups = "live", testName = "EucalyptusPartnerCloudWalrusBlobSignerLiveTest") +@Test(groups = "live", testName = "EucalyptusPartnerCloudWalrusBlobSignerLiveTest") public class EucalyptusPartnerCloudWalrusBlobSignerLiveTest extends WalrusBlobSignerLiveTest { + public EucalyptusPartnerCloudWalrusBlobSignerLiveTest() { + provider = "eucalyptus-partnercloud-s3"; + } } diff --git a/providers/eucalyptus-partnercloud-s3/src/test/java/org/jclouds/epc/blobstore/EucalyptusPartnerCloudWalrusContainerIntegrationLiveTest.java b/providers/eucalyptus-partnercloud-s3/src/test/java/org/jclouds/epc/blobstore/EucalyptusPartnerCloudWalrusContainerIntegrationLiveTest.java index ec6ae4d24b..8e42392236 100644 --- a/providers/eucalyptus-partnercloud-s3/src/test/java/org/jclouds/epc/blobstore/EucalyptusPartnerCloudWalrusContainerIntegrationLiveTest.java +++ b/providers/eucalyptus-partnercloud-s3/src/test/java/org/jclouds/epc/blobstore/EucalyptusPartnerCloudWalrusContainerIntegrationLiveTest.java @@ -24,7 +24,10 @@ import org.testng.annotations.Test; /** * @author Adrian Cole */ -@Test(groups = "live", testName = "EucalyptusPartnerCloudWalrusContainerIntegrationLiveTest") +@Test(groups = "live", testName = "EucalyptusPartnerCloudWalrusContainerIntegrationLiveTest") public class EucalyptusPartnerCloudWalrusContainerIntegrationLiveTest extends WalrusContainerIntegrationLiveTest { + public EucalyptusPartnerCloudWalrusContainerIntegrationLiveTest() { + provider = "eucalyptus-partnercloud-s3"; + } } diff --git a/providers/eucalyptus-partnercloud-s3/src/test/java/org/jclouds/epc/blobstore/EucalyptusPartnerCloudWalrusContainerLiveTest.java b/providers/eucalyptus-partnercloud-s3/src/test/java/org/jclouds/epc/blobstore/EucalyptusPartnerCloudWalrusContainerLiveTest.java index 941b7c49a0..32e13bfc34 100644 --- a/providers/eucalyptus-partnercloud-s3/src/test/java/org/jclouds/epc/blobstore/EucalyptusPartnerCloudWalrusContainerLiveTest.java +++ b/providers/eucalyptus-partnercloud-s3/src/test/java/org/jclouds/epc/blobstore/EucalyptusPartnerCloudWalrusContainerLiveTest.java @@ -27,4 +27,7 @@ import org.testng.annotations.Test; @Test(groups = "live", testName = "EucalyptusPartnerCloudWalrusContainerLiveTest") public class EucalyptusPartnerCloudWalrusContainerLiveTest extends WalrusContainerLiveTest { + public EucalyptusPartnerCloudWalrusContainerLiveTest() { + provider = "eucalyptus-partnercloud-s3"; + } } diff --git a/providers/eucalyptus-partnercloud-s3/src/test/java/org/jclouds/epc/blobstore/EucalyptusPartnerCloudWalrusInputStreamMapIntegrationLiveTest.java b/providers/eucalyptus-partnercloud-s3/src/test/java/org/jclouds/epc/blobstore/EucalyptusPartnerCloudWalrusInputStreamMapIntegrationLiveTest.java index f81da68f87..f2b060cf28 100644 --- a/providers/eucalyptus-partnercloud-s3/src/test/java/org/jclouds/epc/blobstore/EucalyptusPartnerCloudWalrusInputStreamMapIntegrationLiveTest.java +++ b/providers/eucalyptus-partnercloud-s3/src/test/java/org/jclouds/epc/blobstore/EucalyptusPartnerCloudWalrusInputStreamMapIntegrationLiveTest.java @@ -24,7 +24,11 @@ import org.testng.annotations.Test; /** * @author Adrian Cole */ -@Test(groups = "live", testName = "EucalyptusPartnerCloudWalrusInputStreamMapIntegrationLiveTest") -public class EucalyptusPartnerCloudWalrusInputStreamMapIntegrationLiveTest extends WalrusInputStreamMapIntegrationLiveTest { +@Test(groups = "live", testName = "EucalyptusPartnerCloudWalrusInputStreamMapIntegrationLiveTest") +public class EucalyptusPartnerCloudWalrusInputStreamMapIntegrationLiveTest extends + WalrusInputStreamMapIntegrationLiveTest { + public EucalyptusPartnerCloudWalrusInputStreamMapIntegrationLiveTest() { + provider = "eucalyptus-partnercloud-s3"; + } } diff --git a/providers/eucalyptus-partnercloud-s3/src/test/java/org/jclouds/epc/blobstore/EucalyptusPartnerCloudWalrusServiceIntegrationLiveTest.java b/providers/eucalyptus-partnercloud-s3/src/test/java/org/jclouds/epc/blobstore/EucalyptusPartnerCloudWalrusServiceIntegrationLiveTest.java index e0f71a4153..37ec64a88a 100644 --- a/providers/eucalyptus-partnercloud-s3/src/test/java/org/jclouds/epc/blobstore/EucalyptusPartnerCloudWalrusServiceIntegrationLiveTest.java +++ b/providers/eucalyptus-partnercloud-s3/src/test/java/org/jclouds/epc/blobstore/EucalyptusPartnerCloudWalrusServiceIntegrationLiveTest.java @@ -30,6 +30,11 @@ import com.google.common.collect.ImmutableSet; */ @Test(groups = "live", testName = "EucalyptusPartnerCloudWalrusServiceIntegrationLiveTest") public class EucalyptusPartnerCloudWalrusServiceIntegrationLiveTest extends WalrusServiceIntegrationLiveTest { + + public EucalyptusPartnerCloudWalrusServiceIntegrationLiveTest() { + provider = "eucalyptus-partnercloud-s3"; + } + @Override protected Set getIso3166Codes() { return ImmutableSet. of("US-CA"); diff --git a/providers/eucalyptus-partnercloud-s3/src/test/java/org/jclouds/epc/blobstore/EucalyptusPartnerCloudWalrusTestInitializer.java b/providers/eucalyptus-partnercloud-s3/src/test/java/org/jclouds/epc/blobstore/EucalyptusPartnerCloudWalrusTestInitializer.java deleted file mode 100644 index caae25fb9e..0000000000 --- a/providers/eucalyptus-partnercloud-s3/src/test/java/org/jclouds/epc/blobstore/EucalyptusPartnerCloudWalrusTestInitializer.java +++ /dev/null @@ -1,35 +0,0 @@ -/** - * 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.epc.blobstore; - -import org.jclouds.walrus.blobstore.WalrusTestInitializer; - - -/** - * - * @author Adrian Cole - */ -public class EucalyptusPartnerCloudWalrusTestInitializer extends WalrusTestInitializer { - - public EucalyptusPartnerCloudWalrusTestInitializer() { - provider = "eucalyptus-partnercloud-s3"; - } - - -} diff --git a/providers/go2cloud-jhb1/src/main/java/org/jclouds/go2cloud/Go2CloudJohannesburg1PropertiesBuilder.java b/providers/go2cloud-jhb1/src/main/java/org/jclouds/go2cloud/Go2CloudJohannesburg1PropertiesBuilder.java deleted file mode 100644 index 505d431393..0000000000 --- a/providers/go2cloud-jhb1/src/main/java/org/jclouds/go2cloud/Go2CloudJohannesburg1PropertiesBuilder.java +++ /dev/null @@ -1,48 +0,0 @@ -/** - * 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.go2cloud; - -import static org.jclouds.Constants.PROPERTY_API_VERSION; -import static org.jclouds.Constants.PROPERTY_ENDPOINT; -import static org.jclouds.Constants.PROPERTY_ISO3166_CODES; - -import java.util.Properties; - -import org.jclouds.elasticstack.ElasticStackPropertiesBuilder; - -/** - * - * @author Adrian Cole - */ -public class Go2CloudJohannesburg1PropertiesBuilder extends ElasticStackPropertiesBuilder { - - @Override - protected Properties defaultProperties() { - Properties properties = super.defaultProperties(); - properties.setProperty(PROPERTY_ISO3166_CODES, "ZA-GP"); - properties.setProperty(PROPERTY_ENDPOINT, "http://api.jhb1.go2cloud.co.za"); - properties.setProperty(PROPERTY_API_VERSION, "2.0"); - return properties; - } - - public Go2CloudJohannesburg1PropertiesBuilder(Properties properties) { - super(properties); - } - -} diff --git a/providers/go2cloud-jhb1/src/main/java/org/jclouds/go2cloud/Go2CloudJohannesburg1ProviderMetadata.java b/providers/go2cloud-jhb1/src/main/java/org/jclouds/go2cloud/Go2CloudJohannesburg1ProviderMetadata.java index 90e28f6e3c..9b3afed0b6 100644 --- a/providers/go2cloud-jhb1/src/main/java/org/jclouds/go2cloud/Go2CloudJohannesburg1ProviderMetadata.java +++ b/providers/go2cloud-jhb1/src/main/java/org/jclouds/go2cloud/Go2CloudJohannesburg1ProviderMetadata.java @@ -19,49 +19,73 @@ package org.jclouds.go2cloud; import java.net.URI; +import java.util.Properties; +import org.jclouds.compute.ComputeServiceContext; import org.jclouds.elasticstack.ElasticStackApiMetadata; -import org.jclouds.providers.BaseProviderMetadata; +import org.jclouds.elasticstack.ElasticStackAsyncClient; +import org.jclouds.elasticstack.ElasticStackClient; +import org.jclouds.providers.ProviderMetadata; +import org.jclouds.providers.internal.BaseProviderMetadata; /** * Implementation of {@link org.jclouds.types.ProviderMetadata} for Go2Cloud's * Johannesburg1 provider. - * + * * @author Adrian Cole */ -public class Go2CloudJohannesburg1ProviderMetadata extends BaseProviderMetadata { +public class Go2CloudJohannesburg1ProviderMetadata + extends + BaseProviderMetadata, ElasticStackApiMetadata> { - public Go2CloudJohannesburg1ProviderMetadata() { - this(builder() - .id("go2cloud-jhb1") - .name("Go2Cloud Johannesburg1") - .api(new ElasticStackApiMetadata()) - .homepage(URI.create("https://jhb1.go2cloud.co.za")) - .console(URI.create("https://jhb1.go2cloud.co.za/accounts")) - .iso3166Codes("ZA-GP")); + public static Builder builder() { + return new Builder(); } - // below are so that we can reuse builders, toString, hashCode, etc. - // we have to set concrete classes here, as our base class cannot be - // concrete due to serviceLoader - protected Go2CloudJohannesburg1ProviderMetadata(ConcreteBuilder builder) { + @Override + public Builder toBuilder() { + return builder().fromProviderMetadata(this); + } + + public Go2CloudJohannesburg1ProviderMetadata() { + super(builder()); + } + + public Go2CloudJohannesburg1ProviderMetadata(Builder builder) { super(builder); } - private static class ConcreteBuilder extends Builder { + protected static Properties defaultProperties() { + Properties properties = new Properties(); + return properties; + } + + public static class Builder + extends + BaseProviderMetadata.Builder, ElasticStackApiMetadata> { + + protected Builder() { + id("go2cloud-jhb1") + .name("Go2Cloud Johannesburg1") + .apiMetadata(new ElasticStackApiMetadata().toBuilder().version("2.0").build()) + .homepage(URI.create("https://jhb1.go2cloud.co.za")) + .console(URI.create("https://jhb1.go2cloud.co.za/accounts")) + .iso3166Codes("ZA-GP") + .endpoint("https://api.jhb1.go2cloud.co.za") + .defaultProperties(Go2CloudJohannesburg1ProviderMetadata.defaultProperties()); + } @Override public Go2CloudJohannesburg1ProviderMetadata build() { return new Go2CloudJohannesburg1ProviderMetadata(this); } - } - public static ConcreteBuilder builder() { - return new ConcreteBuilder(); - } + @Override + public Builder fromProviderMetadata( + ProviderMetadata, ElasticStackApiMetadata> in) { + super.fromProviderMetadata(in); + return this; + } - public ConcreteBuilder toBuilder() { - return builder().fromProviderMetadata(this); } - -} +} \ No newline at end of file diff --git a/providers/go2cloud-jhb1/src/main/java/org/jclouds/go2cloud/config/Go2CloudJohannesburg1ComputeServiceContextModule.java b/providers/go2cloud-jhb1/src/main/java/org/jclouds/go2cloud/config/Go2CloudJohannesburg1ComputeServiceContextModule.java deleted file mode 100644 index c13dc45cbb..0000000000 --- a/providers/go2cloud-jhb1/src/main/java/org/jclouds/go2cloud/config/Go2CloudJohannesburg1ComputeServiceContextModule.java +++ /dev/null @@ -1,38 +0,0 @@ -/** - * 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.go2cloud.config; - -import static org.jclouds.compute.domain.OsFamily.UBUNTU; - -import org.jclouds.compute.domain.TemplateBuilder; -import org.jclouds.elasticstack.compute.config.ElasticStackComputeServiceContextModule; - -import com.google.inject.Injector; - -/** - * - * @author Adrian Cole - */ -public class Go2CloudJohannesburg1ComputeServiceContextModule extends ElasticStackComputeServiceContextModule { - - @Override - protected TemplateBuilder provideTemplate(Injector injector, TemplateBuilder template) { - return template.osFamily(UBUNTU).osVersionMatches("10.10").os64Bit(true); - } -} diff --git a/providers/go2cloud-jhb1/src/test/java/org/jclouds/go2cloud/Go2CloudJohannesburg1ProviderTest.java b/providers/go2cloud-jhb1/src/test/java/org/jclouds/go2cloud/Go2CloudJohannesburg1ProviderTest.java index 22a49cb308..cd2a00543f 100644 --- a/providers/go2cloud-jhb1/src/test/java/org/jclouds/go2cloud/Go2CloudJohannesburg1ProviderTest.java +++ b/providers/go2cloud-jhb1/src/test/java/org/jclouds/go2cloud/Go2CloudJohannesburg1ProviderTest.java @@ -19,7 +19,7 @@ package org.jclouds.go2cloud; import org.jclouds.elasticstack.ElasticStackApiMetadata; -import org.jclouds.providers.BaseProviderMetadataTest; +import org.jclouds.providers.internal.BaseProviderMetadataTest; import org.testng.annotations.Test; /** diff --git a/providers/go2cloud-jhb1/src/test/java/org/jclouds/go2cloud/compute/Go2CloudJohannesburg1TemplateBuilderLiveTest.java b/providers/go2cloud-jhb1/src/test/java/org/jclouds/go2cloud/compute/Go2CloudJohannesburg1TemplateBuilderLiveTest.java index fc46ea9edd..65175537f3 100644 --- a/providers/go2cloud-jhb1/src/test/java/org/jclouds/go2cloud/compute/Go2CloudJohannesburg1TemplateBuilderLiveTest.java +++ b/providers/go2cloud-jhb1/src/test/java/org/jclouds/go2cloud/compute/Go2CloudJohannesburg1TemplateBuilderLiveTest.java @@ -24,10 +24,13 @@ import static org.testng.Assert.assertEquals; import java.io.IOException; import java.util.Set; -import org.jclouds.compute.BaseTemplateBuilderLiveTest; +import org.jclouds.compute.ComputeServiceContext; import org.jclouds.compute.domain.OsFamily; import org.jclouds.compute.domain.OsFamilyVersion64Bit; import org.jclouds.compute.domain.Template; +import org.jclouds.compute.internal.BaseTemplateBuilderLiveTest; +import org.jclouds.elasticstack.ElasticStackAsyncClient; +import org.jclouds.elasticstack.ElasticStackClient; import org.testng.annotations.Test; import com.google.common.base.Predicate; @@ -39,7 +42,9 @@ import com.google.common.collect.ImmutableSet; * @author Adrian Cole */ @Test(groups = "live") -public class Go2CloudJohannesburg1TemplateBuilderLiveTest extends BaseTemplateBuilderLiveTest { +public class Go2CloudJohannesburg1TemplateBuilderLiveTest + extends + BaseTemplateBuilderLiveTest> { public Go2CloudJohannesburg1TemplateBuilderLiveTest() { provider = "go2cloud-jhb1"; @@ -52,14 +57,14 @@ public class Go2CloudJohannesburg1TemplateBuilderLiveTest extends BaseTemplateBu @Override public boolean apply(OsFamilyVersion64Bit input) { switch (input.family) { - case UBUNTU: - return (input.version.equals("") || input.version.equals("10.10")) && input.is64Bit; - case DEBIAN: - return (input.version.equals("") || input.version.equals("6.0")) && input.is64Bit; - case WINDOWS: - return input.version.equals("") && input.is64Bit; - default: - return false; + case UBUNTU: + return (input.version.equals("") || input.version.equals("10.10")) && input.is64Bit; + case DEBIAN: + return (input.version.equals("") || input.version.equals("6.0")) && input.is64Bit; + case WINDOWS: + return input.version.equals("") && input.is64Bit; + default: + return false; } } diff --git a/providers/gogrid/src/main/java/org/jclouds/gogrid/GoGridApiMetadata.java b/providers/gogrid/src/main/java/org/jclouds/gogrid/GoGridApiMetadata.java index e209e90e5d..7733c419de 100644 --- a/providers/gogrid/src/main/java/org/jclouds/gogrid/GoGridApiMetadata.java +++ b/providers/gogrid/src/main/java/org/jclouds/gogrid/GoGridApiMetadata.java @@ -19,50 +19,70 @@ package org.jclouds.gogrid; import java.net.URI; +import java.util.Properties; import org.jclouds.apis.ApiMetadata; -import org.jclouds.apis.ApiType; -import org.jclouds.apis.BaseApiMetadata; +import org.jclouds.compute.ComputeServiceContext; +import org.jclouds.compute.internal.BaseComputeServiceApiMetadata; + +import com.google.common.reflect.TypeToken; /** - * Implementation of {@link ApiMetadata} for the GoGrid API + * Implementation of {@link ApiMetadata} for API * * @author Adrian Cole */ -public class GoGridApiMetadata extends BaseApiMetadata { +public class GoGridApiMetadata + extends + BaseComputeServiceApiMetadata, GoGridApiMetadata> { - public GoGridApiMetadata() { - this(builder() - .id("gogrid") - .type(ApiType.COMPUTE) - .name("GoGrid API") - .identityName("API Key") - .credentialName("Shared Secret") - .documentation(URI.create("https://wiki.gogrid.com/wiki/index.php/API"))); + @Override + public Builder toBuilder() { + return new Builder().fromApiMetadata(this); } - // below are so that we can reuse builders, toString, hashCode, etc. - // we have to set concrete classes here, as our base class cannot be - // concrete due to serviceLoader - protected GoGridApiMetadata(Builder builder) { + public GoGridApiMetadata() { + this(new Builder()); + } + + protected GoGridApiMetadata(Builder builder) { super(builder); } - private static class ConcreteBuilder extends Builder { + protected static Properties defaultProperties() { + Properties properties = BaseComputeServiceApiMetadata.Builder.defaultProperties(); + properties.setProperty("jclouds.ssh.max-retries", "5"); + properties.setProperty("jclouds.ssh.retry-auth", "true"); + return properties; + } + + public static class Builder + extends + BaseComputeServiceApiMetadata.Builder, GoGridApiMetadata> { + + protected Builder() { + id("gogrid") + .name("GoGrid API") + .identityName("API Key") + .credentialName("Shared Secret") + .documentation(URI.create("https://wiki.gogrid.com/wiki/index.php/API")) + .version(GoGridAsyncClient.VERSION) + .defaultEndpoint("https://api.gogrid.com/api") + .javaApi(GoGridClient.class, GoGridAsyncClient.class) + .contextBuilder(TypeToken.of(GoGridContextBuilder.class)); + } @Override public GoGridApiMetadata build() { return new GoGridApiMetadata(this); } + + @Override + public Builder fromApiMetadata(GoGridApiMetadata in) { + super.fromApiMetadata(in); + return this; + } + } - public static ConcreteBuilder builder() { - return new ConcreteBuilder(); - } - - @Override - public ConcreteBuilder toBuilder() { - return builder().fromApiMetadata(this); - } - -} \ No newline at end of file +} diff --git a/providers/gogrid/src/main/java/org/jclouds/gogrid/GoGridContextBuilder.java b/providers/gogrid/src/main/java/org/jclouds/gogrid/GoGridContextBuilder.java index d0c16ce5e9..0318c28952 100644 --- a/providers/gogrid/src/main/java/org/jclouds/gogrid/GoGridContextBuilder.java +++ b/providers/gogrid/src/main/java/org/jclouds/gogrid/GoGridContextBuilder.java @@ -19,31 +19,30 @@ package org.jclouds.gogrid; import java.util.List; -import java.util.Properties; import org.jclouds.compute.ComputeServiceContext; import org.jclouds.compute.ComputeServiceContextBuilder; -import org.jclouds.compute.internal.ComputeServiceContextImpl; import org.jclouds.gogrid.compute.config.GoGridComputeServiceContextModule; import org.jclouds.gogrid.config.GoGridRestClientModule; +import org.jclouds.providers.ProviderMetadata; -import com.google.inject.Key; import com.google.inject.Module; -import com.google.inject.TypeLiteral; /** * * @author Adrian Cole */ -public class GoGridContextBuilder extends - ComputeServiceContextBuilder { +public class GoGridContextBuilder + extends + ComputeServiceContextBuilder, GoGridApiMetadata> { - public GoGridContextBuilder(Properties props) { - super(GoGridClient.class, GoGridAsyncClient.class, props); + public GoGridContextBuilder( + ProviderMetadata, GoGridApiMetadata> providerMetadata) { + super(providerMetadata); } - protected void addClientModule(List modules) { - modules.add(new GoGridRestClientModule()); + public GoGridContextBuilder(GoGridApiMetadata apiMetadata) { + super(apiMetadata); } @Override @@ -51,13 +50,8 @@ public class GoGridContextBuilder extends modules.add(new GoGridComputeServiceContextModule()); } - @Override - public ComputeServiceContext buildComputeServiceContext() { - return this - .buildInjector() - .getInstance( - Key - .get(new TypeLiteral>() { - })); + protected void addClientModule(List modules) { + modules.add(new GoGridRestClientModule()); } + } diff --git a/providers/gogrid/src/main/java/org/jclouds/gogrid/GoGridPropertiesBuilder.java b/providers/gogrid/src/main/java/org/jclouds/gogrid/GoGridPropertiesBuilder.java deleted file mode 100644 index 6bb3362ce6..0000000000 --- a/providers/gogrid/src/main/java/org/jclouds/gogrid/GoGridPropertiesBuilder.java +++ /dev/null @@ -1,59 +0,0 @@ -/** - * 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.gogrid; - -import static org.jclouds.Constants.PROPERTY_API_VERSION; -import static org.jclouds.Constants.PROPERTY_ENDPOINT; -import static org.jclouds.Constants.PROPERTY_ISO3166_CODES; -import static org.jclouds.gogrid.reference.GoGridConstants.PROPERTY_GOGRID_DEFAULT_DC; -import static org.jclouds.location.reference.LocationConstants.ISO3166_CODES; -import static org.jclouds.location.reference.LocationConstants.PROPERTY_ZONE; -import static org.jclouds.location.reference.LocationConstants.PROPERTY_ZONES; - -import java.util.Properties; - -import org.jclouds.PropertiesBuilder; - -/** - * Builds properties used in GoGrid Clients - * - * @author Adrian Cole - * @author Oleksiy Yarmula - * - */ -public class GoGridPropertiesBuilder extends PropertiesBuilder { - @Override - protected Properties defaultProperties() { - Properties properties = super.defaultProperties(); - properties.setProperty(PROPERTY_ZONES, "1,2,3"); - properties.setProperty(PROPERTY_ISO3166_CODES, "US-CA,US-VA,NL-NH"); - properties.setProperty(PROPERTY_ZONE + ".1." + ISO3166_CODES, "US-CA"); - properties.setProperty(PROPERTY_ZONE + ".2." + ISO3166_CODES, "US-VA"); - properties.setProperty(PROPERTY_ZONE + ".3." + ISO3166_CODES, "NL-NH"); - properties.setProperty(PROPERTY_API_VERSION, GoGridAsyncClient.VERSION); - properties.setProperty(PROPERTY_ENDPOINT, "https://api.gogrid.com/api"); - properties.setProperty(PROPERTY_GOGRID_DEFAULT_DC, "1"); - return properties; - } - - public GoGridPropertiesBuilder(Properties properties) { - super(properties); - } - -} diff --git a/providers/gogrid/src/main/java/org/jclouds/gogrid/GoGridProviderMetadata.java b/providers/gogrid/src/main/java/org/jclouds/gogrid/GoGridProviderMetadata.java index 8221241ea5..c78a719162 100644 --- a/providers/gogrid/src/main/java/org/jclouds/gogrid/GoGridProviderMetadata.java +++ b/providers/gogrid/src/main/java/org/jclouds/gogrid/GoGridProviderMetadata.java @@ -18,47 +18,81 @@ */ package org.jclouds.gogrid; -import java.net.URI; +import static org.jclouds.Constants.PROPERTY_API_VERSION; +import static org.jclouds.gogrid.reference.GoGridConstants.PROPERTY_GOGRID_DEFAULT_DC; +import static org.jclouds.location.reference.LocationConstants.ISO3166_CODES; +import static org.jclouds.location.reference.LocationConstants.PROPERTY_ZONE; +import static org.jclouds.location.reference.LocationConstants.PROPERTY_ZONES; -import org.jclouds.providers.BaseProviderMetadata; +import java.net.URI; +import java.util.Properties; + +import org.jclouds.compute.ComputeServiceContext; +import org.jclouds.providers.ProviderMetadata; +import org.jclouds.providers.internal.BaseProviderMetadata; /** * Implementation of {@link org.jclouds.types.ProviderMetadata} for GoGrid. - * * @author Adrian Cole */ -public class GoGridProviderMetadata extends BaseProviderMetadata { - public GoGridProviderMetadata() { - this(builder() - .id("gogrid") - .name("GoGrid") - .api(new GoGridApiMetadata()) - .homepage(URI.create("http://www.gogrid.com")) - .console(URI.create("https://my.gogrid.com/gogrid")) - .iso3166Codes("US-CA", "US-VA", "BR-SP")); +public class GoGridProviderMetadata + extends + BaseProviderMetadata, GoGridApiMetadata> { + + public static Builder builder() { + return new Builder(); } - // below are so that we can reuse builders, toString, hashCode, etc. - // we have to set concrete classes here, as our base class cannot be - // concrete due to serviceLoader - protected GoGridProviderMetadata(ConcreteBuilder builder) { + @Override + public Builder toBuilder() { + return builder().fromProviderMetadata(this); + } + + public GoGridProviderMetadata() { + super(builder()); + } + + public GoGridProviderMetadata(Builder builder) { super(builder); } - private static class ConcreteBuilder extends Builder { + protected static Properties defaultProperties() { + Properties properties = new Properties(); + properties.setProperty(PROPERTY_ZONES, "1,2,3"); + properties.setProperty(PROPERTY_ZONE + ".1." + ISO3166_CODES, "US-CA"); + properties.setProperty(PROPERTY_ZONE + ".2." + ISO3166_CODES, "US-VA"); + properties.setProperty(PROPERTY_ZONE + ".3." + ISO3166_CODES, "NL-NH"); + properties.setProperty(PROPERTY_API_VERSION, GoGridAsyncClient.VERSION); + properties.setProperty(PROPERTY_GOGRID_DEFAULT_DC, "1"); + return properties; + } + + public static class Builder + extends + BaseProviderMetadata.Builder, GoGridApiMetadata> { + + protected Builder() { + id("gogrid") + .name("GoGrid") + .apiMetadata(new GoGridApiMetadata()) + .homepage(URI.create("http://www.gogrid.com")) + .console(URI.create("https://my.gogrid.com/gogrid")) + .iso3166Codes("US-CA", "US-VA", "BR-SP") + .endpoint("https://api.gogrid.com/api") + .defaultProperties(GoGridProviderMetadata.defaultProperties()); + } @Override public GoGridProviderMetadata build() { return new GoGridProviderMetadata(this); } - } - public static ConcreteBuilder builder() { - return new ConcreteBuilder(); - } + @Override + public Builder fromProviderMetadata( + ProviderMetadata, GoGridApiMetadata> in) { + super.fromProviderMetadata(in); + return this; + } - public ConcreteBuilder toBuilder() { - return builder().fromProviderMetadata(this); } - } \ No newline at end of file diff --git a/providers/gogrid/src/main/java/org/jclouds/gogrid/compute/GoGridComputeService.java b/providers/gogrid/src/main/java/org/jclouds/gogrid/compute/GoGridComputeService.java index b03aadf71d..879880a23d 100644 --- a/providers/gogrid/src/main/java/org/jclouds/gogrid/compute/GoGridComputeService.java +++ b/providers/gogrid/src/main/java/org/jclouds/gogrid/compute/GoGridComputeService.java @@ -62,7 +62,7 @@ import com.google.common.base.Supplier; @Singleton public class GoGridComputeService extends BaseComputeService { @Inject - protected GoGridComputeService(ComputeServiceContext context, Map credentialStore, + protected GoGridComputeService(@SuppressWarnings("rawtypes") ComputeServiceContext context, Map credentialStore, @Memoized Supplier> images, @Memoized Supplier> hardwareProfiles, @Memoized Supplier> locations, ListNodesStrategy listNodesStrategy, GetNodeMetadataStrategy getNodeMetadataStrategy, CreateNodesInGroupThenAddToSet runNodesAndAddToSetStrategy, diff --git a/providers/gogrid/src/test/java/org/jclouds/gogrid/GoGridLiveTestDisabled.java b/providers/gogrid/src/test/java/org/jclouds/gogrid/GoGridLiveTestDisabled.java index 7c3cc171cf..31017c0ebe 100644 --- a/providers/gogrid/src/test/java/org/jclouds/gogrid/GoGridLiveTestDisabled.java +++ b/providers/gogrid/src/test/java/org/jclouds/gogrid/GoGridLiveTestDisabled.java @@ -31,12 +31,11 @@ import java.util.Date; import java.util.Iterator; import java.util.List; import java.util.Map; -import java.util.Properties; import java.util.Set; import java.util.concurrent.TimeUnit; -import org.jclouds.compute.BaseVersionedServiceLiveTest; -import org.jclouds.compute.ComputeServiceContextFactory; +import org.jclouds.compute.ComputeServiceContext; +import org.jclouds.compute.internal.BaseComputeServiceContextLiveTest; import org.jclouds.domain.Credentials; import org.jclouds.gogrid.domain.Ip; import org.jclouds.gogrid.domain.IpPortPair; @@ -54,7 +53,6 @@ import org.jclouds.gogrid.options.GetImageListOptions; import org.jclouds.gogrid.predicates.LoadBalancerLatestJobCompleted; import org.jclouds.gogrid.predicates.ServerLatestJobCompleted; import org.jclouds.javax.annotation.Nullable; -import org.jclouds.logging.log4j.config.Log4JLoggingModule; import org.jclouds.net.IPSocket; import org.jclouds.predicates.InetSocketAddressConnect; import org.jclouds.predicates.RetryablePredicate; @@ -67,9 +65,7 @@ import org.testng.annotations.BeforeGroups; import org.testng.annotations.Test; import com.google.common.base.Predicate; -import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; -import com.google.inject.Module; /** * End to end live test for GoGrid @@ -79,7 +75,10 @@ import com.google.inject.Module; * @author Oleksiy Yarmula */ @Test(enabled = false, groups = "live", singleThreaded = true, testName = "GoGridLiveTestDisabled") -public class GoGridLiveTestDisabled extends BaseVersionedServiceLiveTest { +public class GoGridLiveTestDisabled + extends + BaseComputeServiceContextLiveTest> { + public GoGridLiveTestDisabled() { provider = "gogrid"; } @@ -94,16 +93,15 @@ public class GoGridLiveTestDisabled extends BaseVersionedServiceLiveTest { private List serversToDeleteAfterTheTests = new ArrayList(); private List loadBalancersToDeleteAfterTest = new ArrayList(); - private RestContext context; + private RestContext gocontext; - @BeforeGroups(groups = { "live" }) - public void setupClient() { - setupCredentials(); - Properties overrides = setupProperties(); - context = new ComputeServiceContextFactory().createContext(provider, ImmutableSet. of(new Log4JLoggingModule()), - overrides).getProviderSpecificContext(); + @BeforeGroups(groups = { "integration", "live" }) + @Override + public void setupContext() { + super.setupContext(); + gocontext = context.getProviderSpecificContext(); - client = context.getApi(); + client = gocontext.getApi(); serverLatestJobCompleted = new RetryablePredicate(new ServerLatestJobCompleted(client.getJobServices()), 800, 20, TimeUnit.SECONDS); loadBalancerLatestJobCompleted = new RetryablePredicate(new LoadBalancerLatestJobCompleted(client @@ -352,7 +350,7 @@ public class GoGridLiveTestDisabled extends BaseVersionedServiceLiveTest { socketOpen.apply(socket); - SshClient sshClient = context.utils().injector().getInstance(SshClient.Factory.class).create(socket, instanceCredentials); + SshClient sshClient = gocontext.utils().injector().getInstance(SshClient.Factory.class).create(socket, instanceCredentials); sshClient.connect(); String output = sshClient.exec("df").getOutput(); assertTrue(output.contains("Filesystem"), diff --git a/providers/gogrid/src/test/java/org/jclouds/gogrid/GoGridProviderTest.java b/providers/gogrid/src/test/java/org/jclouds/gogrid/GoGridProviderTest.java index 2fb9140c3a..3debe01ada 100644 --- a/providers/gogrid/src/test/java/org/jclouds/gogrid/GoGridProviderTest.java +++ b/providers/gogrid/src/test/java/org/jclouds/gogrid/GoGridProviderTest.java @@ -18,7 +18,7 @@ */ package org.jclouds.gogrid; -import org.jclouds.providers.BaseProviderMetadataTest; +import org.jclouds.providers.internal.BaseProviderMetadataTest; import org.testng.annotations.Test; /** diff --git a/providers/gogrid/src/test/java/org/jclouds/gogrid/compute/GoGridComputeServiceLiveTest.java b/providers/gogrid/src/test/java/org/jclouds/gogrid/compute/GoGridComputeServiceLiveTest.java index 3c8352ac4a..c2359cb42f 100644 --- a/providers/gogrid/src/test/java/org/jclouds/gogrid/compute/GoGridComputeServiceLiveTest.java +++ b/providers/gogrid/src/test/java/org/jclouds/gogrid/compute/GoGridComputeServiceLiveTest.java @@ -25,9 +25,10 @@ import static org.testng.Assert.assertNotNull; import java.util.concurrent.TimeUnit; -import org.jclouds.compute.BaseComputeServiceLiveTest; +import org.jclouds.compute.ComputeServiceContext; import org.jclouds.compute.domain.ExecResponse; import org.jclouds.compute.domain.NodeMetadata; +import org.jclouds.compute.internal.BaseComputeServiceLiveTest; import org.jclouds.gogrid.GoGridAsyncClient; import org.jclouds.gogrid.GoGridClient; import org.jclouds.gogrid.domain.Server; @@ -47,7 +48,10 @@ import com.google.inject.Module; // NOTE:without testName, this will not call @Before* and fail w/NPE during // surefire @Test(groups = "live", singleThreaded = true, testName = "GoGridComputeServiceLiveTest") -public class GoGridComputeServiceLiveTest extends BaseComputeServiceLiveTest { +public class GoGridComputeServiceLiveTest + extends + BaseComputeServiceLiveTest> { + public GoGridComputeServiceLiveTest() { provider = "gogrid"; } @@ -70,7 +74,7 @@ public class GoGridComputeServiceLiveTest extends BaseComputeServiceLiveTest { public void testResizeRam() throws Exception { String group = this.group + "ram"; - RestContext providerContext = client.getContext().getProviderSpecificContext(); + RestContext providerContext = context.getProviderSpecificContext(); try { client.destroyNodesMatching(inGroup(group)); } catch (Exception e) { diff --git a/providers/gogrid/src/test/java/org/jclouds/gogrid/compute/GoGridTemplateBuilderLiveTest.java b/providers/gogrid/src/test/java/org/jclouds/gogrid/compute/GoGridTemplateBuilderLiveTest.java index 9d917a2174..1773206435 100644 --- a/providers/gogrid/src/test/java/org/jclouds/gogrid/compute/GoGridTemplateBuilderLiveTest.java +++ b/providers/gogrid/src/test/java/org/jclouds/gogrid/compute/GoGridTemplateBuilderLiveTest.java @@ -24,10 +24,13 @@ import static org.testng.Assert.assertEquals; import java.io.IOException; import java.util.Set; -import org.jclouds.compute.BaseTemplateBuilderLiveTest; +import org.jclouds.compute.ComputeServiceContext; import org.jclouds.compute.domain.OsFamily; import org.jclouds.compute.domain.OsFamilyVersion64Bit; import org.jclouds.compute.domain.Template; +import org.jclouds.compute.internal.BaseTemplateBuilderLiveTest; +import org.jclouds.gogrid.GoGridAsyncClient; +import org.jclouds.gogrid.GoGridClient; import org.testng.annotations.Test; import com.google.common.base.Predicate; @@ -40,7 +43,9 @@ import com.google.common.collect.ImmutableSet; */ //NOTE:without testName, this will not call @Before* and fail w/NPE during surefire @Test(groups = "live", singleThreaded = true, testName = "GoGridTemplateBuilderLiveTest") -public class GoGridTemplateBuilderLiveTest extends BaseTemplateBuilderLiveTest { +public class GoGridTemplateBuilderLiveTest + extends + BaseTemplateBuilderLiveTest> { public GoGridTemplateBuilderLiveTest() { provider = "gogrid"; diff --git a/providers/gogrid/src/test/java/org/jclouds/gogrid/services/BaseGoGridAsyncClientTest.java b/providers/gogrid/src/test/java/org/jclouds/gogrid/services/BaseGoGridAsyncClientTest.java index fb890afdbf..ef95d93eb5 100644 --- a/providers/gogrid/src/test/java/org/jclouds/gogrid/services/BaseGoGridAsyncClientTest.java +++ b/providers/gogrid/src/test/java/org/jclouds/gogrid/services/BaseGoGridAsyncClientTest.java @@ -20,17 +20,15 @@ package org.jclouds.gogrid.services; import static org.testng.Assert.assertEquals; -import java.util.Properties; - import org.jclouds.date.TimeStamp; +import org.jclouds.gogrid.GoGridProviderMetadata; import org.jclouds.gogrid.config.GoGridRestClientModule; import org.jclouds.gogrid.filters.SharedKeyLiteAuthentication; import org.jclouds.http.HttpRequest; import org.jclouds.http.RequiresHttp; +import org.jclouds.providers.ProviderMetadata; import org.jclouds.rest.ConfiguresRestClient; -import org.jclouds.rest.RestClientTest; -import org.jclouds.rest.RestContextFactory; -import org.jclouds.rest.RestContextSpec; +import org.jclouds.rest.internal.BaseAsyncClientTest; import org.testng.annotations.Test; import com.google.common.base.Supplier; @@ -41,7 +39,7 @@ import com.google.inject.Module; * @author Adrian Cole */ @Test(groups = "unit") -public abstract class BaseGoGridAsyncClientTest extends RestClientTest { +public abstract class BaseGoGridAsyncClientTest extends BaseAsyncClientTest { @Override protected void checkFilters(HttpRequest request) { assertEquals(request.getFilters().size(), 1); @@ -68,8 +66,8 @@ public abstract class BaseGoGridAsyncClientTest extends RestClientTest { } @Override - public RestContextSpec createContextSpec() { - return new RestContextFactory().createContextSpec("gogrid", "foo", "bar", new Properties()); + public ProviderMetadata createProviderMetadata() { + return new GoGridProviderMetadata(); } } \ No newline at end of file diff --git a/providers/gogrid/src/test/java/org/jclouds/gogrid/services/BaseGoGridClientLiveTest.java b/providers/gogrid/src/test/java/org/jclouds/gogrid/services/BaseGoGridClientLiveTest.java index 9ca9e9b599..e070cc5571 100644 --- a/providers/gogrid/src/test/java/org/jclouds/gogrid/services/BaseGoGridClientLiveTest.java +++ b/providers/gogrid/src/test/java/org/jclouds/gogrid/services/BaseGoGridClientLiveTest.java @@ -18,50 +18,36 @@ */ package org.jclouds.gogrid.services; -import java.util.Properties; - -import org.jclouds.compute.BaseVersionedServiceLiveTest; import org.jclouds.compute.ComputeServiceContext; -import org.jclouds.compute.ComputeServiceContextFactory; +import org.jclouds.compute.internal.BaseComputeServiceContextLiveTest; import org.jclouds.gogrid.GoGridAsyncClient; import org.jclouds.gogrid.GoGridClient; -import org.jclouds.logging.log4j.config.Log4JLoggingModule; import org.jclouds.rest.RestContext; -import org.jclouds.sshj.config.SshjSshClientModule; -import org.testng.annotations.AfterGroups; import org.testng.annotations.BeforeGroups; import org.testng.annotations.Test; -import com.google.common.collect.ImmutableSet; -import com.google.inject.Module; - /** * Tests behavior of {@code GoGridClient} * * @author Adrian Cole */ @Test(groups = "live", singleThreaded = true, testName = "BaseGoGridClientLiveTest") -public class BaseGoGridClientLiveTest extends BaseVersionedServiceLiveTest { +public class BaseGoGridClientLiveTest + extends + BaseComputeServiceContextLiveTest> { + public BaseGoGridClientLiveTest() { provider = "gogrid"; } protected RestContext restContext; - protected ComputeServiceContext context; - @BeforeGroups(groups = { "live" }) - public void setupClient() { - setupCredentials(); - Properties overrides = setupProperties(); - context = new ComputeServiceContextFactory().createContext(provider, ImmutableSet. of( - new Log4JLoggingModule(), new SshjSshClientModule()), overrides); + @BeforeGroups(groups = { "integration", "live" }) + @Override + public void setupContext() { + super.setupContext(); restContext = context.getProviderSpecificContext(); } - @AfterGroups(groups = "live") - protected void tearDown() { - if (context != null) - context.close(); - } } diff --git a/providers/gogrid/src/test/java/org/jclouds/gogrid/services/BaseGoGridRestClientExpectTest.java b/providers/gogrid/src/test/java/org/jclouds/gogrid/services/BaseGoGridRestClientExpectTest.java index 3da872721a..25fd8a968f 100644 --- a/providers/gogrid/src/test/java/org/jclouds/gogrid/services/BaseGoGridRestClientExpectTest.java +++ b/providers/gogrid/src/test/java/org/jclouds/gogrid/services/BaseGoGridRestClientExpectTest.java @@ -4,7 +4,7 @@ import org.jclouds.date.TimeStamp; import org.jclouds.gogrid.GoGridClient; import org.jclouds.gogrid.config.GoGridRestClientModule; import org.jclouds.http.RequiresHttp; -import org.jclouds.rest.BaseRestClientExpectTest; +import org.jclouds.rest.internal.BaseRestClientExpectTest; import org.jclouds.rest.ConfiguresRestClient; import com.google.common.base.Supplier; diff --git a/providers/gogrid/src/test/java/org/jclouds/gogrid/services/GridImageAsyncClientTest.java b/providers/gogrid/src/test/java/org/jclouds/gogrid/services/GridImageAsyncClientTest.java index 0999997979..a6eb0f94b4 100644 --- a/providers/gogrid/src/test/java/org/jclouds/gogrid/services/GridImageAsyncClientTest.java +++ b/providers/gogrid/src/test/java/org/jclouds/gogrid/services/GridImageAsyncClientTest.java @@ -67,7 +67,7 @@ public class GridImageAsyncClientTest extends BaseGoGridAsyncClientTest, VCloudApiMetadata> providerMetadata) { + super(providerMetadata); + } - public GreenHouseDataElementVCloudContextBuilder(Properties props) { - super(props); + public GreenHouseDataElementVCloudContextBuilder(VCloudApiMetadata apiMetadata) { + super(apiMetadata); } @Override protected void addContextModule(List modules) { - modules.add(new GreenHouseDataElementVCloudComputeServiceContextModule()); + modules.add(new VCloudComputeServiceContextModule()); } @Override diff --git a/providers/greenhousedata-element-vcloud/src/main/java/org/jclouds/greenhousedata/element/vcloud/GreenHouseDataElementVCloudPropertiesBuilder.java b/providers/greenhousedata-element-vcloud/src/main/java/org/jclouds/greenhousedata/element/vcloud/GreenHouseDataElementVCloudPropertiesBuilder.java deleted file mode 100644 index 2e832511bd..0000000000 --- a/providers/greenhousedata-element-vcloud/src/main/java/org/jclouds/greenhousedata/element/vcloud/GreenHouseDataElementVCloudPropertiesBuilder.java +++ /dev/null @@ -1,48 +0,0 @@ -/** - * 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.greenhousedata.element.vcloud; - -import static org.jclouds.Constants.PROPERTY_BUILD_VERSION; -import static org.jclouds.Constants.PROPERTY_ENDPOINT; -import static org.jclouds.Constants.PROPERTY_ISO3166_CODES; -import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_NETWORK; - -import java.util.Properties; - -import org.jclouds.vcloud.VCloudPropertiesBuilder; - -/** - * - * @author Adrian Cole - */ -public class GreenHouseDataElementVCloudPropertiesBuilder extends VCloudPropertiesBuilder { - @Override - protected Properties defaultProperties() { - Properties properties = super.defaultProperties(); - properties.setProperty(PROPERTY_ISO3166_CODES, "US-WY"); - properties.setProperty(PROPERTY_ENDPOINT, "https://mycloud.greenhousedata.com/api"); - properties.setProperty(PROPERTY_BUILD_VERSION, "1.5.0.464915"); - properties.setProperty(PROPERTY_VCLOUD_DEFAULT_NETWORK, "orgNet-.*-External"); - return properties; - } - - public GreenHouseDataElementVCloudPropertiesBuilder(Properties properties) { - super(properties); - } -} diff --git a/providers/greenhousedata-element-vcloud/src/main/java/org/jclouds/greenhousedata/element/vcloud/GreenHouseDataElementVCloudProviderMetadata.java b/providers/greenhousedata-element-vcloud/src/main/java/org/jclouds/greenhousedata/element/vcloud/GreenHouseDataElementVCloudProviderMetadata.java index a06f740ecc..0bf19f4964 100644 --- a/providers/greenhousedata-element-vcloud/src/main/java/org/jclouds/greenhousedata/element/vcloud/GreenHouseDataElementVCloudProviderMetadata.java +++ b/providers/greenhousedata-element-vcloud/src/main/java/org/jclouds/greenhousedata/element/vcloud/GreenHouseDataElementVCloudProviderMetadata.java @@ -18,49 +18,78 @@ */ package org.jclouds.greenhousedata.element.vcloud; -import java.net.URI; +import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_NETWORK; -import org.jclouds.providers.BaseProviderMetadata; +import java.net.URI; +import java.util.Properties; + +import org.jclouds.compute.ComputeServiceContext; +import org.jclouds.providers.ProviderMetadata; +import org.jclouds.providers.internal.BaseProviderMetadata; import org.jclouds.vcloud.VCloudApiMetadata; +import org.jclouds.vcloud.VCloudAsyncClient; +import org.jclouds.vcloud.VCloudClient; + +import com.google.common.reflect.TypeToken; /** * Implementation of {@link org.jclouds.types.ProviderMetadata} for Green House Data Element vCloud * * @author Adrian Cole */ -public class GreenHouseDataElementVCloudProviderMetadata extends BaseProviderMetadata { +public class GreenHouseDataElementVCloudProviderMetadata + extends + BaseProviderMetadata, VCloudApiMetadata> { - public GreenHouseDataElementVCloudProviderMetadata() { - this(builder() - .id("greenhousedata-element-vcloud") - .name("Green House Data Element vCloud") - .api(new VCloudApiMetadata()) - .homepage(URI.create("http://www.greenhousedata.com/element-cloud-hosting/vcloud-services/")) - .console(URI.create("https://mycloud.greenhousedata.com/cloud/org/YOUR_ORG_HERE")) - .iso3166Codes("US-WY")); + public static Builder builder() { + return new Builder(); } - // below are so that we can reuse builders, toString, hashCode, etc. - // we have to set concrete classes here, as our base class cannot be - // concrete due to serviceLoader - protected GreenHouseDataElementVCloudProviderMetadata(ConcreteBuilder builder) { + @Override + public Builder toBuilder() { + return builder().fromProviderMetadata(this); + } + + public GreenHouseDataElementVCloudProviderMetadata() { + super(builder()); + } + + public GreenHouseDataElementVCloudProviderMetadata(Builder builder) { super(builder); } - private static class ConcreteBuilder extends Builder { + protected static Properties defaultProperties() { + Properties properties = new Properties(); + properties.setProperty(PROPERTY_VCLOUD_DEFAULT_NETWORK, "orgNet-.*-External"); + return properties; + } + + public static class Builder extends BaseProviderMetadata.Builder, VCloudApiMetadata> { + + protected Builder(){ + id("greenhousedata-element-vcloud") + .name("Green House Data Element vCloud") + .apiMetadata( + new VCloudApiMetadata().toBuilder() + .buildVersion("1.5.0.464915") + .contextBuilder(TypeToken.of(GreenHouseDataElementVCloudContextBuilder.class)).build()) + .homepage(URI.create("http://www.greenhousedata.com/element-cloud-hosting/vcloud-services/")) + .console(URI.create("https://mycloud.greenhousedata.com/cloud/org/YOUR_ORG_HERE")) + .iso3166Codes("US-WY") + .endpoint("https://mycloud.greenhousedata.com/api") + .defaultProperties(GreenHouseDataElementVCloudProviderMetadata.defaultProperties()); + } @Override public GreenHouseDataElementVCloudProviderMetadata build() { return new GreenHouseDataElementVCloudProviderMetadata(this); } + + @Override + public Builder fromProviderMetadata( + ProviderMetadata, VCloudApiMetadata> in) { + super.fromProviderMetadata(in); + return this; + } } - - public static ConcreteBuilder builder() { - return new ConcreteBuilder(); - } - - public ConcreteBuilder toBuilder() { - return builder().fromProviderMetadata(this); - } - -} +} \ No newline at end of file diff --git a/providers/greenhousedata-element-vcloud/src/test/java/org/jclouds/greenhousedata/element/vcloud/GreenHouseDataElementVCloudProviderTest.java b/providers/greenhousedata-element-vcloud/src/test/java/org/jclouds/greenhousedata/element/vcloud/GreenHouseDataElementVCloudProviderTest.java index b72914a0dc..61b93c25f9 100644 --- a/providers/greenhousedata-element-vcloud/src/test/java/org/jclouds/greenhousedata/element/vcloud/GreenHouseDataElementVCloudProviderTest.java +++ b/providers/greenhousedata-element-vcloud/src/test/java/org/jclouds/greenhousedata/element/vcloud/GreenHouseDataElementVCloudProviderTest.java @@ -18,7 +18,7 @@ */ package org.jclouds.greenhousedata.element.vcloud; -import org.jclouds.providers.BaseProviderMetadataTest; +import org.jclouds.providers.internal.BaseProviderMetadataTest; import org.jclouds.vcloud.VCloudApiMetadata; import org.testng.annotations.Test; diff --git a/providers/greenhousedata-element-vcloud/src/test/java/org/jclouds/greenhousedata/element/vcloud/compute/GreenHouseDataElementVCloudTemplateBuilderLiveTest.java b/providers/greenhousedata-element-vcloud/src/test/java/org/jclouds/greenhousedata/element/vcloud/compute/GreenHouseDataElementVCloudTemplateBuilderLiveTest.java index ff3c504c18..efb4394359 100644 --- a/providers/greenhousedata-element-vcloud/src/test/java/org/jclouds/greenhousedata/element/vcloud/compute/GreenHouseDataElementVCloudTemplateBuilderLiveTest.java +++ b/providers/greenhousedata-element-vcloud/src/test/java/org/jclouds/greenhousedata/element/vcloud/compute/GreenHouseDataElementVCloudTemplateBuilderLiveTest.java @@ -24,10 +24,13 @@ import static org.testng.Assert.assertEquals; import java.io.IOException; import java.util.Set; -import org.jclouds.compute.BaseTemplateBuilderLiveTest; +import org.jclouds.compute.ComputeServiceContext; import org.jclouds.compute.domain.OsFamily; import org.jclouds.compute.domain.OsFamilyVersion64Bit; import org.jclouds.compute.domain.Template; +import org.jclouds.compute.internal.BaseTemplateBuilderLiveTest; +import org.jclouds.vcloud.VCloudAsyncClient; +import org.jclouds.vcloud.VCloudClient; import org.testng.annotations.Test; import com.google.common.base.Predicate; @@ -38,7 +41,9 @@ import com.google.common.collect.ImmutableSet; * @author Adrian Cole */ @Test(groups = "live", testName = "GreenHouseDataElementVCloudTemplateBuilderLiveTest") -public class GreenHouseDataElementVCloudTemplateBuilderLiveTest extends BaseTemplateBuilderLiveTest { +public class GreenHouseDataElementVCloudTemplateBuilderLiveTest + extends + BaseTemplateBuilderLiveTest> { public GreenHouseDataElementVCloudTemplateBuilderLiveTest() { provider = "greenhousedata-element-vcloud"; diff --git a/providers/hpcloud-compute/src/main/java/org/jclouds/hpcloud/compute/HPCloudComputeApiMetadata.java b/providers/hpcloud-compute/src/main/java/org/jclouds/hpcloud/compute/HPCloudComputeApiMetadata.java deleted file mode 100644 index 05596e2e9e..0000000000 --- a/providers/hpcloud-compute/src/main/java/org/jclouds/hpcloud/compute/HPCloudComputeApiMetadata.java +++ /dev/null @@ -1,60 +0,0 @@ -/** - * 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.hpcloud.compute; - -import org.jclouds.apis.ApiMetadata; -import org.jclouds.openstack.nova.v1_1.NovaApiMetadata; - -/** - * Implementation of {@link ApiMetadata} for the Amazon-specific Nova API - * - * @author Adrian Cole - */ -public class HPCloudComputeApiMetadata extends NovaApiMetadata { - - public HPCloudComputeApiMetadata() { - this(builder().fromApiMetadata(new NovaApiMetadata()) - .identityName("tenantId:accessKey") - .credentialName("secretKey")); - } - - // below are so that we can reuse builders, toString, hashCode, etc. - // we have to set concrete classes here, as our base class cannot be - // concrete due to serviceLoader - protected HPCloudComputeApiMetadata(ConcreteBuilder builder) { - super(builder); - } - - private static class ConcreteBuilder extends NovaApiMetadataBuilder { - - @Override - public HPCloudComputeApiMetadata build() { - return new HPCloudComputeApiMetadata(this); - } - } - - private static ConcreteBuilder builder() { - return new ConcreteBuilder(); - } - - @Override - public ConcreteBuilder toBuilder() { - return builder().fromApiMetadata(this); - } -} \ No newline at end of file diff --git a/providers/hpcloud-compute/src/main/java/org/jclouds/hpcloud/compute/HPCloudComputeContextBuilder.java b/providers/hpcloud-compute/src/main/java/org/jclouds/hpcloud/compute/HPCloudComputeContextBuilder.java index d0ad203eff..cdaccddb03 100644 --- a/providers/hpcloud-compute/src/main/java/org/jclouds/hpcloud/compute/HPCloudComputeContextBuilder.java +++ b/providers/hpcloud-compute/src/main/java/org/jclouds/hpcloud/compute/HPCloudComputeContextBuilder.java @@ -19,10 +19,14 @@ package org.jclouds.hpcloud.compute; import java.util.List; -import java.util.Properties; +import org.jclouds.compute.ComputeServiceContext; import org.jclouds.hpcloud.compute.config.HPCloudComputeServiceContextModule; +import org.jclouds.openstack.nova.v1_1.NovaApiMetadata; +import org.jclouds.openstack.nova.v1_1.NovaAsyncClient; +import org.jclouds.openstack.nova.v1_1.NovaClient; import org.jclouds.openstack.nova.v1_1.NovaContextBuilder; +import org.jclouds.providers.ProviderMetadata; import com.google.inject.Module; @@ -32,12 +36,18 @@ import com.google.inject.Module; */ public class HPCloudComputeContextBuilder extends NovaContextBuilder { - public HPCloudComputeContextBuilder(Properties props) { - super(props); + public HPCloudComputeContextBuilder( + ProviderMetadata, NovaApiMetadata> providerMetadata) { + super(providerMetadata); + } + + public HPCloudComputeContextBuilder(NovaApiMetadata apiMetadata) { + super(apiMetadata); } @Override protected void addContextModule(List modules) { modules.add(new HPCloudComputeServiceContextModule()); } + } diff --git a/providers/hpcloud-compute/src/main/java/org/jclouds/hpcloud/compute/HPCloudComputePropertiesBuilder.java b/providers/hpcloud-compute/src/main/java/org/jclouds/hpcloud/compute/HPCloudComputePropertiesBuilder.java deleted file mode 100644 index ca824c1744..0000000000 --- a/providers/hpcloud-compute/src/main/java/org/jclouds/hpcloud/compute/HPCloudComputePropertiesBuilder.java +++ /dev/null @@ -1,57 +0,0 @@ -/** - * 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 computee 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.hpcloud.compute; - -import static org.jclouds.Constants.PROPERTY_ENDPOINT; -import static org.jclouds.Constants.PROPERTY_ISO3166_CODES; -import static org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_NODE_TERMINATED; -import static org.jclouds.openstack.keystone.v2_0.config.KeystoneProperties.CREDENTIAL_TYPE; -import static org.jclouds.openstack.nova.v1_1.config.NovaProperties.AUTO_ALLOCATE_FLOATING_IPS; -import static org.jclouds.openstack.nova.v1_1.config.NovaProperties.AUTO_GENERATE_KEYPAIRS; - -import java.util.Properties; - -import org.jclouds.openstack.nova.v1_1.NovaPropertiesBuilder; - -/** - * - * @author Adrian Cole - */ -public class HPCloudComputePropertiesBuilder extends NovaPropertiesBuilder { - - @Override - protected Properties defaultProperties() { - Properties properties = super.defaultProperties(); - properties.setProperty(PROPERTY_ISO3166_CODES, "US-NV"); - properties.setProperty(PROPERTY_ENDPOINT, "https://region-a.geo-1.identity.hpcloudsvc.com:35357"); - - // deallocating ip addresses can take a while - properties.setProperty(TIMEOUT_NODE_TERMINATED, 60 * 1000 + ""); - - properties.setProperty(CREDENTIAL_TYPE, "apiAccessKeyCredentials"); - properties.setProperty(AUTO_ALLOCATE_FLOATING_IPS, "true"); - properties.setProperty(AUTO_GENERATE_KEYPAIRS, "true"); - return properties; - } - - public HPCloudComputePropertiesBuilder(Properties properties) { - super(properties); - } - -} diff --git a/providers/hpcloud-compute/src/main/java/org/jclouds/hpcloud/compute/HPCloudComputeProviderMetadata.java b/providers/hpcloud-compute/src/main/java/org/jclouds/hpcloud/compute/HPCloudComputeProviderMetadata.java index 5287499f88..44e48865a9 100644 --- a/providers/hpcloud-compute/src/main/java/org/jclouds/hpcloud/compute/HPCloudComputeProviderMetadata.java +++ b/providers/hpcloud-compute/src/main/java/org/jclouds/hpcloud/compute/HPCloudComputeProviderMetadata.java @@ -4,7 +4,7 @@ * 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 computee this file except in compliance + * "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 @@ -18,49 +18,86 @@ */ package org.jclouds.hpcloud.compute; +import static org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_NODE_TERMINATED; +import static org.jclouds.openstack.keystone.v2_0.config.KeystoneProperties.CREDENTIAL_TYPE; +import static org.jclouds.openstack.nova.v1_1.config.NovaProperties.AUTO_ALLOCATE_FLOATING_IPS; +import static org.jclouds.openstack.nova.v1_1.config.NovaProperties.AUTO_GENERATE_KEYPAIRS; + import java.net.URI; +import java.util.Properties; -import org.jclouds.providers.BaseProviderMetadata; +import org.jclouds.compute.ComputeServiceContext; +import org.jclouds.openstack.nova.v1_1.NovaApiMetadata; +import org.jclouds.openstack.nova.v1_1.NovaAsyncClient; +import org.jclouds.openstack.nova.v1_1.NovaClient; +import org.jclouds.providers.ProviderMetadata; +import org.jclouds.providers.internal.BaseProviderMetadata; +import com.google.common.reflect.TypeToken; /** * Implementation of {@link org.jclouds.types.ProviderMetadata} for HP Cloud Compute Services. * * @author Adrian Cole */ -public class HPCloudComputeProviderMetadata extends BaseProviderMetadata { +public class HPCloudComputeProviderMetadata + extends + BaseProviderMetadata, NovaApiMetadata> { - public HPCloudComputeProviderMetadata() { - this(builder() - .id("hpcloud-compute") - .name("HP Cloud Compute Services") - .api(new HPCloudComputeApiMetadata()) - .homepage(URI.create("http://hpcloud.com")) - .console(URI.create("https://manage.hpcloud.com/compute")) - .linkedServices("hpcloud-compute", "hpcloud-objectstorage") - .iso3166Codes("US-NV")); + public static Builder builder() { + return new Builder(); } - // below are so that we can reuse builders, toString, hashCode, etc. - // we have to set concrete classes here, as our base class cannot be - // concrete due to serviceLoader - protected HPCloudComputeProviderMetadata(ConcreteBuilder builder) { + @Override + public Builder toBuilder() { + return builder().fromProviderMetadata(this); + } + + public HPCloudComputeProviderMetadata() { + super(builder()); + } + + public HPCloudComputeProviderMetadata(Builder builder) { super(builder); } - private static class ConcreteBuilder extends Builder { + protected static Properties defaultProperties() { + Properties properties = new Properties(); + // deallocating ip addresses can take a while + properties.setProperty(TIMEOUT_NODE_TERMINATED, 60 * 1000 + ""); + + properties.setProperty(CREDENTIAL_TYPE, "apiAccessKeyCredentials"); + properties.setProperty(AUTO_ALLOCATE_FLOATING_IPS, "true"); + properties.setProperty(AUTO_GENERATE_KEYPAIRS, "true"); + return properties; + } + + public static class Builder extends BaseProviderMetadata.Builder, NovaApiMetadata> { + + protected Builder(){ + id("hpcloud-compute") + .name("HP Cloud Compute Services") + .apiMetadata(new NovaApiMetadata().toBuilder().identityName("tenantId:accessKey") + .credentialName("secretKey") + .contextBuilder(TypeToken.of(HPCloudComputeContextBuilder.class)).build()) + .homepage(URI.create("http://hpcloud.com")) + .console(URI.create("https://manage.hpcloud.com/compute")) + .linkedServices("hpcloud-compute", "hpcloud-objectstorage") + .iso3166Codes("US-NV") + .endpoint("https://region-a.geo-1.identity.hpcloudsvc.com:35357") + .defaultProperties(HPCloudComputeProviderMetadata.defaultProperties()); + } @Override public HPCloudComputeProviderMetadata build() { return new HPCloudComputeProviderMetadata(this); } + + @Override + public Builder fromProviderMetadata( + ProviderMetadata, NovaApiMetadata> in) { + super.fromProviderMetadata(in); + return this; + } } - - public static ConcreteBuilder builder() { - return new ConcreteBuilder(); - } - - public ConcreteBuilder toBuilder() { - return builder().fromProviderMetadata(this); - } -} +} \ No newline at end of file diff --git a/providers/hpcloud-compute/src/test/java/org/jclouds/hpcloud/compute/HPCloudComputeProviderTest.java b/providers/hpcloud-compute/src/test/java/org/jclouds/hpcloud/compute/HPCloudComputeProviderTest.java index 670349b9ae..f752ac991a 100644 --- a/providers/hpcloud-compute/src/test/java/org/jclouds/hpcloud/compute/HPCloudComputeProviderTest.java +++ b/providers/hpcloud-compute/src/test/java/org/jclouds/hpcloud/compute/HPCloudComputeProviderTest.java @@ -35,7 +35,8 @@ */ package org.jclouds.hpcloud.compute; -import org.jclouds.providers.BaseProviderMetadataTest; +import org.jclouds.openstack.nova.v1_1.NovaApiMetadata; +import org.jclouds.providers.internal.BaseProviderMetadataTest; import org.testng.annotations.Test; /** @@ -46,6 +47,6 @@ import org.testng.annotations.Test; public class HPCloudComputeProviderTest extends BaseProviderMetadataTest { public HPCloudComputeProviderTest() { - super(new HPCloudComputeProviderMetadata(), new HPCloudComputeApiMetadata()); + super(new HPCloudComputeProviderMetadata(), new NovaApiMetadata()); } } diff --git a/providers/hpcloud-compute/src/test/java/org/jclouds/hpcloud/compute/compute/HPCloudComputeTemplateBuilderLiveTest.java b/providers/hpcloud-compute/src/test/java/org/jclouds/hpcloud/compute/compute/HPCloudComputeTemplateBuilderLiveTest.java index 676e2808e1..29664b45f4 100644 --- a/providers/hpcloud-compute/src/test/java/org/jclouds/hpcloud/compute/compute/HPCloudComputeTemplateBuilderLiveTest.java +++ b/providers/hpcloud-compute/src/test/java/org/jclouds/hpcloud/compute/compute/HPCloudComputeTemplateBuilderLiveTest.java @@ -23,10 +23,13 @@ import static org.testng.Assert.assertEquals; import java.util.Set; -import org.jclouds.compute.BaseTemplateBuilderLiveTest; +import org.jclouds.compute.ComputeServiceContext; import org.jclouds.compute.domain.OsFamily; import org.jclouds.compute.domain.OsFamilyVersion64Bit; import org.jclouds.compute.domain.Template; +import org.jclouds.compute.internal.BaseTemplateBuilderLiveTest; +import org.jclouds.openstack.nova.v1_1.NovaAsyncClient; +import org.jclouds.openstack.nova.v1_1.NovaClient; import org.jclouds.openstack.nova.v1_1.compute.options.NovaTemplateOptions; import org.testng.annotations.Test; @@ -39,7 +42,8 @@ import com.google.common.collect.ImmutableSet; * @author Adrian Cole */ @Test(groups = "live", singleThreaded = true, testName = "HPCloudComputeTemplateBuilderLiveTest") -public class HPCloudComputeTemplateBuilderLiveTest extends BaseTemplateBuilderLiveTest { +public class HPCloudComputeTemplateBuilderLiveTest extends + BaseTemplateBuilderLiveTest> { public HPCloudComputeTemplateBuilderLiveTest() { provider = "hpcloud-compute"; diff --git a/providers/hpcloud-objectstorage/pom.xml b/providers/hpcloud-objectstorage/pom.xml index db3d4d7b55..360b992e40 100644 --- a/providers/hpcloud-objectstorage/pom.xml +++ b/providers/hpcloud-objectstorage/pom.xml @@ -34,7 +34,6 @@ bundle - org.jclouds.hpcloud.objectstorage.blobstore.integration.HPCloudObjectStorageTestInitializer https://region-a.geo-1.identity.hpcloudsvc.com:35357 1.0 @@ -127,10 +126,6 @@ test.hpcloud-objectstorage.credential ${test.hpcloud-objectstorage.credential} - - test.initializer - ${test.initializer} - jclouds.blobstore.httpstream.url ${jclouds.blobstore.httpstream.url} diff --git a/providers/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/HPCloudObjectStorageApiMetadata.java b/providers/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/HPCloudObjectStorageApiMetadata.java index 2278c43d1d..8ff3b49aad 100644 --- a/providers/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/HPCloudObjectStorageApiMetadata.java +++ b/providers/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/HPCloudObjectStorageApiMetadata.java @@ -1,49 +1,95 @@ +/** + * 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.hpcloud.objectstorage; +import static org.jclouds.openstack.keystone.v2_0.config.KeystoneProperties.CREDENTIAL_TYPE; +import static org.jclouds.openstack.keystone.v2_0.config.KeystoneProperties.SERVICE_TYPE; + import java.net.URI; +import java.util.Properties; -import org.jclouds.apis.ApiMetadata; -import org.jclouds.apis.ApiType; -import org.jclouds.apis.BaseApiMetadata; +import org.jclouds.blobstore.BlobStoreContext; +import org.jclouds.blobstore.internal.BaseBlobStoreApiMetadata; +import org.jclouds.openstack.keystone.v2_0.config.KeystoneProperties; +import org.jclouds.openstack.services.ServiceType; +import com.google.common.reflect.TypeToken; /** - * Implementation of {@link ApiMetadata} for HP Cloud Object Storage API + * Implementation of {@link org.jclouds.providers.ProviderMetadata} for HP Cloud Services Object Storage * - * @author Adrian Cole + * @author Jeremy Daggett */ -public class HPCloudObjectStorageApiMetadata extends BaseApiMetadata { +public class HPCloudObjectStorageApiMetadata + extends + BaseBlobStoreApiMetadata, HPCloudObjectStorageApiMetadata> { - public HPCloudObjectStorageApiMetadata() { - this(builder() - .id("hpcloud-objectstorage") - .type(ApiType.BLOBSTORE) - .name("HP Cloud Services Object Storage API") - .identityName("tenantId:accessKey") - .credentialName("secretKey") - .documentation(URI.create("https://build.hpcloud.com/object-storage/api"))); + private static Builder builder() { + return new Builder(); } - // below are so that we can reuse builders, toString, hashCode, etc. - // we have to set concrete classes here, as our base class cannot be - // concrete due to serviceLoader - protected HPCloudObjectStorageApiMetadata(ConcreteBuilder builder) { + @Override + public Builder toBuilder() { + return builder().fromApiMetadata(this); + } + + public HPCloudObjectStorageApiMetadata() { + this(builder()); + } + + protected HPCloudObjectStorageApiMetadata(Builder builder) { super(builder); } - private static class ConcreteBuilder extends Builder { + protected static Properties defaultProperties() { + Properties properties = BaseBlobStoreApiMetadata.Builder.defaultProperties(); + properties.setProperty(SERVICE_TYPE, ServiceType.OBJECT_STORE); + // TODO: this doesn't actually do anything yet. + properties.setProperty(KeystoneProperties.VERSION, "2.0"); + properties.setProperty(CREDENTIAL_TYPE, "apiAccessKeyCredentials"); + return properties; + } + + public static class Builder + extends + BaseBlobStoreApiMetadata.Builder, HPCloudObjectStorageApiMetadata> { + + protected Builder() { + id("hpcloud-objectstorage") + .name("HP Cloud Services Object Storage API") + .identityName("tenantId:accessKey") + .credentialName("secretKey") + .version("1.0") + .documentation(URI.create("https://build.hpcloud.com/object-storage/api")) + .javaApi(HPCloudObjectStorageClient.class, HPCloudObjectStorageAsyncClient.class) + .contextBuilder(TypeToken.of(HPCloudObjectStorageContextBuilder.class)) + .defaultProperties(HPCloudObjectStorageApiMetadata.defaultProperties()); + } @Override public HPCloudObjectStorageApiMetadata build() { return new HPCloudObjectStorageApiMetadata(this); } - } - public static ConcreteBuilder builder() { - return new ConcreteBuilder(); + @Override + public Builder fromApiMetadata(HPCloudObjectStorageApiMetadata in) { + super.fromApiMetadata(in); + return this; + } } - - @Override - public ConcreteBuilder toBuilder() { - return builder().fromApiMetadata(this); - } -} \ No newline at end of file +} diff --git a/providers/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/HPCloudObjectStorageContextBuilder.java b/providers/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/HPCloudObjectStorageContextBuilder.java index 5653544c81..f51bc37aae 100644 --- a/providers/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/HPCloudObjectStorageContextBuilder.java +++ b/providers/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/HPCloudObjectStorageContextBuilder.java @@ -19,35 +19,45 @@ package org.jclouds.hpcloud.objectstorage; import java.util.List; -import java.util.Properties; +import org.jclouds.blobstore.BlobStoreContext; import org.jclouds.blobstore.BlobStoreContextBuilder; -import org.jclouds.hpcloud.objectstorage.blobstore.HPCloudObjectStorageBlobStore; import org.jclouds.hpcloud.objectstorage.blobstore.config.HPCloudObjectStorageBlobStoreContextModule; import org.jclouds.hpcloud.objectstorage.config.HPCloudObjectStorageRestClientModule; import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule; import org.jclouds.logging.jdk.config.JDKLoggingModule; +import org.jclouds.providers.ProviderMetadata; import com.google.inject.Injector; import com.google.inject.Module; /** - * Creates {@link HPCloudObjectStorageBlobStore} or {@link Injector} instances based on the most - * commonly requested arguments. + * Creates {@link HPCloudObjectStorageStoreContext} or {@link Injector} instances based on + * the most commonly requested arguments. *

- * Note that Threadsafe objects will be bound as singletons to the Injector or Context provided. + * Note that Threadsafe objects will be bound as singletons to the Injector or + * Context provided. *

*

- * If no Modules are specified, the default {@link JDKLoggingModule logging} and - * {@link JavaUrlHttpCommandExecutorServiceModule http transports} will be installed. + * If no Modules are specified, the default + * {@link JDKLoggingModule logging} and + * {@link JavaUrlHttpCommandExecutorServiceModule http transports} will be + * installed. * * @author Adrian Cole, Andrew Newdigate - * @see HPCloudObjectStorageBlobStore + * @see HPCloudObjectStorageStoreContext */ -public class HPCloudObjectStorageContextBuilder extends BlobStoreContextBuilder { +public class HPCloudObjectStorageContextBuilder + extends + BlobStoreContextBuilder, HPCloudObjectStorageApiMetadata> { - public HPCloudObjectStorageContextBuilder(Properties props) { - super(HPCloudObjectStorageClient.class, HPCloudObjectStorageAsyncClient.class, props); + public HPCloudObjectStorageContextBuilder( + ProviderMetadata, HPCloudObjectStorageApiMetadata> providerMetadata) { + super(providerMetadata); + } + + public HPCloudObjectStorageContextBuilder(HPCloudObjectStorageApiMetadata apiMetadata) { + super(apiMetadata); } @Override @@ -59,4 +69,4 @@ public class HPCloudObjectStorageContextBuilder extends BlobStoreContextBuilder< protected void addClientModule(List modules) { modules.add(new HPCloudObjectStorageRestClientModule()); } -} +} \ No newline at end of file diff --git a/providers/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/HPCloudObjectStoragePropertiesBuilder.java b/providers/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/HPCloudObjectStoragePropertiesBuilder.java deleted file mode 100644 index 95bb9d2ecd..0000000000 --- a/providers/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/HPCloudObjectStoragePropertiesBuilder.java +++ /dev/null @@ -1,58 +0,0 @@ -/** - * 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.hpcloud.objectstorage; - -import static org.jclouds.Constants.PROPERTY_API_VERSION; -import static org.jclouds.Constants.PROPERTY_ENDPOINT; -import static org.jclouds.Constants.PROPERTY_ISO3166_CODES; -import static org.jclouds.openstack.keystone.v2_0.config.KeystoneProperties.CREDENTIAL_TYPE; -import static org.jclouds.openstack.keystone.v2_0.config.KeystoneProperties.SERVICE_TYPE; - -import java.util.Properties; - -import org.jclouds.openstack.keystone.v2_0.config.KeystoneProperties; -import org.jclouds.openstack.services.ServiceType; -import org.jclouds.openstack.swift.SwiftPropertiesBuilder; - -/** - * @author Jeremy Daggett - */ -public class HPCloudObjectStoragePropertiesBuilder extends SwiftPropertiesBuilder { - - public HPCloudObjectStoragePropertiesBuilder(Properties properties) { - super(properties); - } - - @Override - protected Properties defaultProperties() { - Properties properties = super.defaultProperties(); - properties.setProperty(PROPERTY_ISO3166_CODES, "US-NV"); - properties.setProperty(PROPERTY_ENDPOINT, "https://region-a.geo-1.identity.hpcloudsvc.com:35357"); - properties.setProperty(PROPERTY_API_VERSION, "1.0"); - - properties.setProperty(SERVICE_TYPE, ServiceType.OBJECT_STORE); - // TODO: this doesn't actually do anything yet. - properties.setProperty(KeystoneProperties.VERSION, "2.0"); - - properties.setProperty(CREDENTIAL_TYPE, "apiAccessKeyCredentials"); - - return properties; - } - -} diff --git a/providers/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/HPCloudObjectStorageProviderMetadata.java b/providers/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/HPCloudObjectStorageProviderMetadata.java index a41c592de8..65dea7c5a8 100644 --- a/providers/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/HPCloudObjectStorageProviderMetadata.java +++ b/providers/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/HPCloudObjectStorageProviderMetadata.java @@ -18,49 +18,72 @@ */ package org.jclouds.hpcloud.objectstorage; -import java.net.URI; +import static org.jclouds.Constants.PROPERTY_BUILD_VERSION; -import org.jclouds.providers.BaseProviderMetadata; +import java.net.URI; +import java.util.Properties; + +import org.jclouds.blobstore.BlobStoreContext; +import org.jclouds.providers.ProviderMetadata; +import org.jclouds.providers.internal.BaseProviderMetadata; /** - * Implementation of {@link org.jclouds.providers.ProviderMetadata} for HP Cloud Services Object Storage + * Implementation of {@link org.jclouds.types.ProviderMetadata} for StratoGen VMware hosting * - * @author Jeremy Daggett + * @author Adrian Cole */ -public class HPCloudObjectStorageProviderMetadata extends BaseProviderMetadata { +public class HPCloudObjectStorageProviderMetadata + extends + BaseProviderMetadata, HPCloudObjectStorageApiMetadata> { - public HPCloudObjectStorageProviderMetadata() { - this(builder() - .id("hpcloud-objectstorage") - .name("HP Cloud Services Object Storage") - .api(new HPCloudObjectStorageApiMetadata()) - .homepage(URI.create("http://hpcloud.com")) - .console(URI.create("https://manage.hpcloud.com/objects/us-west")) - .linkedServices("hpcloud-compute", "hpcloud-objectstorage") - .iso3166Codes("US-NV")); + public static Builder builder() { + return new Builder(); } - // below are so that we can reuse builders, toString, hashCode, etc. - // we have to set concrete classes here, as our base class cannot be - // concrete due to serviceLoader - protected HPCloudObjectStorageProviderMetadata(ConcreteBuilder builder) { + @Override + public Builder toBuilder() { + return builder().fromProviderMetadata(this); + } + + public HPCloudObjectStorageProviderMetadata() { + super(builder()); + } + + public HPCloudObjectStorageProviderMetadata(Builder builder) { super(builder); } - private static class ConcreteBuilder extends Builder { + protected static Properties defaultProperties() { + Properties properties = new Properties(); + properties.setProperty(PROPERTY_BUILD_VERSION, "???"); //FIXME +// properties.setProperty(PROPERTY_VCLOUD_DEFAULT_NETWORK, "orgNet-.*-External"); FIXME: needed? + return properties; + } + + public static class Builder extends BaseProviderMetadata.Builder, HPCloudObjectStorageApiMetadata> { + + protected Builder(){ + id("hpcloud-objectstorage") + .name("HP Cloud Services Object Storage") + .apiMetadata(new HPCloudObjectStorageApiMetadata()) + .homepage(URI.create("http://hpcloud.com")) + .console(URI.create("https://manage.hpcloud.com/objects/us-west")) + .linkedServices("hpcloud-compute", "hpcloud-objectstorage") + .iso3166Codes("US-NV") + .endpoint("https://region-a.geo-1.identity.hpcloudsvc.com:35357") + .defaultProperties(HPCloudObjectStorageProviderMetadata.defaultProperties()); + } @Override public HPCloudObjectStorageProviderMetadata build() { return new HPCloudObjectStorageProviderMetadata(this); } + + @Override + public Builder fromProviderMetadata( + ProviderMetadata, HPCloudObjectStorageApiMetadata> in) { + super.fromProviderMetadata(in); + return this; + } } - - public static ConcreteBuilder builder() { - return new ConcreteBuilder(); - } - - public ConcreteBuilder toBuilder() { - return builder().fromProviderMetadata(this); - } - } \ No newline at end of file diff --git a/providers/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/blobstore/HPCloudObjectStorageAsyncBlobStore.java b/providers/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/blobstore/HPCloudObjectStorageAsyncBlobStore.java index ed305371de..a9516d6f9c 100644 --- a/providers/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/blobstore/HPCloudObjectStorageAsyncBlobStore.java +++ b/providers/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/blobstore/HPCloudObjectStorageAsyncBlobStore.java @@ -59,7 +59,7 @@ public class HPCloudObjectStorageAsyncBlobStore extends SwiftAsyncBlobStore { private final EnableCDNAndCache enableCDNAndCache; @Inject - protected HPCloudObjectStorageAsyncBlobStore(BlobStoreContext context, BlobUtils blobUtils, + protected HPCloudObjectStorageAsyncBlobStore(@SuppressWarnings("rawtypes") BlobStoreContext context, BlobUtils blobUtils, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService service, Supplier defaultLocation, @Memoized Supplier> locations, HPCloudObjectStorageClient sync, HPCloudObjectStorageAsyncClient async, ContainerToResourceMetadata container2ResourceMd, diff --git a/providers/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/blobstore/HPCloudObjectStorageBlobStore.java b/providers/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/blobstore/HPCloudObjectStorageBlobStore.java index e05119ed8c..fc9acef141 100644 --- a/providers/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/blobstore/HPCloudObjectStorageBlobStore.java +++ b/providers/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/blobstore/HPCloudObjectStorageBlobStore.java @@ -53,7 +53,7 @@ public class HPCloudObjectStorageBlobStore extends SwiftBlobStore { private EnableCDNAndCache enableCDNAndCache; @Inject - protected HPCloudObjectStorageBlobStore(BlobStoreContext context, BlobUtils blobUtils, + protected HPCloudObjectStorageBlobStore(@SuppressWarnings("rawtypes") BlobStoreContext context, BlobUtils blobUtils, Supplier defaultLocation, @Memoized Supplier> locations, HPCloudObjectStorageClient sync, ContainerToResourceMetadata container2ResourceMd, BlobStoreListContainerOptionsToListContainerOptions container2ContainerListOptions, diff --git a/providers/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/HPCloudObjectStorageClientLiveTest.java b/providers/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/HPCloudObjectStorageClientLiveTest.java index 7deac56ea9..bda812354e 100644 --- a/providers/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/HPCloudObjectStorageClientLiveTest.java +++ b/providers/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/HPCloudObjectStorageClientLiveTest.java @@ -36,7 +36,11 @@ import org.testng.annotations.Test; */ @Test(groups = "live", testName = "HPCloudObjectStorageClientLiveTest") public class HPCloudObjectStorageClientLiveTest extends CommonSwiftClientLiveTest { - + + public HPCloudObjectStorageClientLiveTest(){ + provider = "hpcloud-objectstorage"; + } + @Override public HPCloudObjectStorageClient getApi() { return (HPCloudObjectStorageClient) context.getProviderSpecificContext().getApi(); diff --git a/providers/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/HPCloudObjectStorageProviderTest.java b/providers/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/HPCloudObjectStorageProviderTest.java index 2ec0636ca6..d6855a61f3 100644 --- a/providers/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/HPCloudObjectStorageProviderTest.java +++ b/providers/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/HPCloudObjectStorageProviderTest.java @@ -18,7 +18,7 @@ */ package org.jclouds.hpcloud.objectstorage; -import org.jclouds.providers.BaseProviderMetadataTest; +import org.jclouds.providers.internal.BaseProviderMetadataTest; import org.testng.annotations.Test; /** diff --git a/providers/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/blobstore/integration/HPCloudObjectStorageBlobIntegrationLiveTest.java b/providers/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/blobstore/integration/HPCloudObjectStorageBlobIntegrationLiveTest.java index d500d58aa0..0fc06482d6 100644 --- a/providers/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/blobstore/integration/HPCloudObjectStorageBlobIntegrationLiveTest.java +++ b/providers/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/blobstore/integration/HPCloudObjectStorageBlobIntegrationLiveTest.java @@ -27,6 +27,10 @@ import org.testng.annotations.Test; */ @Test(groups = "live") public class HPCloudObjectStorageBlobIntegrationLiveTest extends SwiftBlobIntegrationLiveTest { + public HPCloudObjectStorageBlobIntegrationLiveTest() { + provider = "hpcloud-objectstorage"; + } + @Override protected void checkContentDisposition(Blob blob, String contentDisposition) { assert blob.getPayload().getContentMetadata().getContentDisposition().startsWith(contentDisposition) : blob diff --git a/providers/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/blobstore/integration/HPCloudObjectStorageBlobLiveTest.java b/providers/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/blobstore/integration/HPCloudObjectStorageBlobLiveTest.java index d56de82499..2fd8425097 100644 --- a/providers/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/blobstore/integration/HPCloudObjectStorageBlobLiveTest.java +++ b/providers/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/blobstore/integration/HPCloudObjectStorageBlobLiveTest.java @@ -26,5 +26,8 @@ import org.testng.annotations.Test; */ @Test(groups = { "live" }) public class HPCloudObjectStorageBlobLiveTest extends SwiftBlobLiveTest { + public HPCloudObjectStorageBlobLiveTest() { + provider = "hpcloud-objectstorage"; + } } diff --git a/providers/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/blobstore/integration/HPCloudObjectStorageBlobMapIntegrationLiveTest.java b/providers/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/blobstore/integration/HPCloudObjectStorageBlobMapIntegrationLiveTest.java index 88a67ddae6..a9e36cb5cc 100644 --- a/providers/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/blobstore/integration/HPCloudObjectStorageBlobMapIntegrationLiveTest.java +++ b/providers/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/blobstore/integration/HPCloudObjectStorageBlobMapIntegrationLiveTest.java @@ -26,5 +26,8 @@ import org.testng.annotations.Test; */ @Test(groups = "live") public class HPCloudObjectStorageBlobMapIntegrationLiveTest extends SwiftBlobMapIntegrationLiveTest { + public HPCloudObjectStorageBlobMapIntegrationLiveTest() { + provider = "hpcloud-objectstorage"; + } } diff --git a/providers/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/blobstore/integration/HPCloudObjectStorageBlobSignerLiveTest.java b/providers/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/blobstore/integration/HPCloudObjectStorageBlobSignerLiveTest.java index 21b6e07f56..f78fa2436b 100644 --- a/providers/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/blobstore/integration/HPCloudObjectStorageBlobSignerLiveTest.java +++ b/providers/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/blobstore/integration/HPCloudObjectStorageBlobSignerLiveTest.java @@ -26,5 +26,8 @@ import org.testng.annotations.Test; */ @Test(groups = { "live" }) public class HPCloudObjectStorageBlobSignerLiveTest extends SwiftBlobSignerLiveTest { + public HPCloudObjectStorageBlobSignerLiveTest() { + provider = "hpcloud-objectstorage"; + } } diff --git a/providers/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/blobstore/integration/HPCloudObjectStorageContainerIntegrationLiveTest.java b/providers/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/blobstore/integration/HPCloudObjectStorageContainerIntegrationLiveTest.java index 73e717d4a3..207dc09cc2 100644 --- a/providers/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/blobstore/integration/HPCloudObjectStorageContainerIntegrationLiveTest.java +++ b/providers/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/blobstore/integration/HPCloudObjectStorageContainerIntegrationLiveTest.java @@ -26,5 +26,8 @@ import org.testng.annotations.Test; */ @Test(groups = "live") public class HPCloudObjectStorageContainerIntegrationLiveTest extends SwiftContainerIntegrationLiveTest { + public HPCloudObjectStorageContainerIntegrationLiveTest() { + provider = "hpcloud-objectstorage"; + } } diff --git a/providers/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/blobstore/integration/HPCloudObjectStorageContainerLiveTest.java b/providers/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/blobstore/integration/HPCloudObjectStorageContainerLiveTest.java index 44e70e3159..91d500d9b8 100644 --- a/providers/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/blobstore/integration/HPCloudObjectStorageContainerLiveTest.java +++ b/providers/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/blobstore/integration/HPCloudObjectStorageContainerLiveTest.java @@ -29,6 +29,9 @@ import org.testng.annotations.Test; */ @Test(groups = { "live" }) public class HPCloudObjectStorageContainerLiveTest extends BaseContainerLiveTest { + public HPCloudObjectStorageContainerLiveTest() { + provider = "hpcloud-objectstorage"; + } @Test(enabled = false) //@Test(expectedExceptions=UnsupportedOperationException.class) diff --git a/providers/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/blobstore/integration/HPCloudObjectStorageInputStreamMapIntegrationLiveTest.java b/providers/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/blobstore/integration/HPCloudObjectStorageInputStreamMapIntegrationLiveTest.java index 34907f3417..e3bd2f6061 100644 --- a/providers/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/blobstore/integration/HPCloudObjectStorageInputStreamMapIntegrationLiveTest.java +++ b/providers/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/blobstore/integration/HPCloudObjectStorageInputStreamMapIntegrationLiveTest.java @@ -26,5 +26,8 @@ import org.testng.annotations.Test; */ @Test(groups = "live") public class HPCloudObjectStorageInputStreamMapIntegrationLiveTest extends SwiftInputStreamMapIntegrationLiveTest { + public HPCloudObjectStorageInputStreamMapIntegrationLiveTest() { + provider = "hpcloud-objectstorage"; + } } diff --git a/providers/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/blobstore/integration/HPCloudObjectStorageServiceIntegrationLiveTest.java b/providers/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/blobstore/integration/HPCloudObjectStorageServiceIntegrationLiveTest.java index 5b28ee5c55..329156d7b6 100644 --- a/providers/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/blobstore/integration/HPCloudObjectStorageServiceIntegrationLiveTest.java +++ b/providers/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/blobstore/integration/HPCloudObjectStorageServiceIntegrationLiveTest.java @@ -30,6 +30,10 @@ import com.google.common.collect.ImmutableSet; */ @Test(groups = "live") public class HPCloudObjectStorageServiceIntegrationLiveTest extends SwiftServiceIntegrationLiveTest { + public HPCloudObjectStorageServiceIntegrationLiveTest() { + provider = "hpcloud-objectstorage"; + } + @Override protected Set getIso3166Codes() { return ImmutableSet. of("US-NV"); diff --git a/providers/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/blobstore/integration/HPCloudObjectStorageTestInitializer.java b/providers/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/blobstore/integration/HPCloudObjectStorageTestInitializer.java deleted file mode 100644 index 03e5cf2487..0000000000 --- a/providers/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/blobstore/integration/HPCloudObjectStorageTestInitializer.java +++ /dev/null @@ -1,32 +0,0 @@ -/** - * 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.hpcloud.objectstorage.blobstore.integration; - -import org.jclouds.openstack.swift.blobstore.integration.SwiftTestInitializer; - -/** - * @author Jeremy Daggett - */ -public class HPCloudObjectStorageTestInitializer extends SwiftTestInitializer { - - public HPCloudObjectStorageTestInitializer() { - provider = "hpcloud-objectstorage"; - } - -} diff --git a/providers/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/internal/HPCloudObjectStorageExpectTest.java b/providers/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/internal/HPCloudObjectStorageExpectTest.java index 2c7bde84d1..0e0b6fa748 100644 --- a/providers/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/internal/HPCloudObjectStorageExpectTest.java +++ b/providers/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/internal/HPCloudObjectStorageExpectTest.java @@ -8,17 +8,16 @@ import java.util.Properties; import java.util.Set; import org.jclouds.blobstore.BlobStore; -import org.jclouds.blobstore.BlobStoreContextFactory; import org.jclouds.domain.Location; +import org.jclouds.hpcloud.objectstorage.HPCloudObjectStorageProviderMetadata; import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpResponse; -import org.jclouds.logging.config.NullLoggingModule; -import org.jclouds.rest.BaseRestClientExpectTest; +import org.jclouds.providers.ProviderMetadata; +import org.jclouds.rest.internal.BaseRestClientExpectTest; import org.testng.annotations.Test; import com.google.common.base.Function; import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableSet; import com.google.inject.Module; @Test(groups = "unit", testName = "HPCloudObjectStorageExpectTest") @@ -42,12 +41,6 @@ public class HPCloudObjectStorageExpectTest extends BaseRestClientExpectTest fn, Module module, Properties props) { - return new BlobStoreContextFactory(setupRestProperties()) - .createContext(provider, identity, credential, ImmutableSet.of(new ExpectModule(fn), - new NullLoggingModule(), module), props) - .getBlobStore(); - } public void testListObjectsWhenResponseIs2xx() throws Exception { Map requestResponseMap = ImmutableMap. builder().put( @@ -60,4 +53,13 @@ public class HPCloudObjectStorageExpectTest extends BaseRestClientExpectTest fn, Module module, Properties props) { + return createInjector(fn, module, props).getInstance(BlobStore.class); + } + + @Override public ProviderMetadata createProviderMetadata(){ + return new HPCloudObjectStorageProviderMetadata(); + } } diff --git a/providers/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/internal/KeystoneFixture.java b/providers/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/internal/KeystoneFixture.java index 45a5f393f8..01153ca070 100644 --- a/providers/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/internal/KeystoneFixture.java +++ b/providers/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/internal/KeystoneFixture.java @@ -19,7 +19,7 @@ package org.jclouds.hpcloud.objectstorage.internal; import static java.lang.String.format; -import static org.jclouds.rest.BaseRestClientExpectTest.payloadFromStringWithContentType; +import static org.jclouds.rest.internal.BaseRestClientExpectTest.payloadFromStringWithContentType; import java.io.IOException; import java.net.URI; diff --git a/providers/ninefold-compute/src/main/java/org/jclouds/ninefold/compute/NinefoldComputeContextBuilder.java b/providers/ninefold-compute/src/main/java/org/jclouds/ninefold/compute/NinefoldComputeContextBuilder.java deleted file mode 100644 index 7309483ee9..0000000000 --- a/providers/ninefold-compute/src/main/java/org/jclouds/ninefold/compute/NinefoldComputeContextBuilder.java +++ /dev/null @@ -1,44 +0,0 @@ -/** - * 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.ninefold.compute; - -import java.util.List; -import java.util.Properties; - -import org.jclouds.cloudstack.CloudStackContextBuilder; -import org.jclouds.ninefold.compute.config.NinefoldComputeServiceContextModule; - -import com.google.inject.Module; - -/** - * - * @author Adrian Cole - */ -public class NinefoldComputeContextBuilder extends CloudStackContextBuilder { - - public NinefoldComputeContextBuilder(Properties props) { - super(props); - } - - @Override - protected void addContextModule(List modules) { - modules.add(new NinefoldComputeServiceContextModule()); - } - -} diff --git a/providers/ninefold-compute/src/main/java/org/jclouds/ninefold/compute/NinefoldComputePropertiesBuilder.java b/providers/ninefold-compute/src/main/java/org/jclouds/ninefold/compute/NinefoldComputePropertiesBuilder.java deleted file mode 100644 index f9ba9e888e..0000000000 --- a/providers/ninefold-compute/src/main/java/org/jclouds/ninefold/compute/NinefoldComputePropertiesBuilder.java +++ /dev/null @@ -1,51 +0,0 @@ -/** - * 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.ninefold.compute; - -import static org.jclouds.Constants.PROPERTY_API_VERSION; -import static org.jclouds.Constants.PROPERTY_ENDPOINT; -import static org.jclouds.Constants.PROPERTY_ISO3166_CODES; - -import java.util.Properties; - -import org.jclouds.cloudstack.CloudStackPropertiesBuilder; - -/** - * - * @author Adrian Cole - */ -public class NinefoldComputePropertiesBuilder extends CloudStackPropertiesBuilder { - - @Override - protected Properties defaultProperties() { - Properties properties = super.defaultProperties(); - properties.setProperty(PROPERTY_ISO3166_CODES, "AU-NSW"); - properties.setProperty(PROPERTY_ENDPOINT, "https://api.ninefold.com/compute/v1.0/"); - properties.setProperty(PROPERTY_API_VERSION, "2.2.12"); - properties.setProperty("ninefold-compute.image-id", "1215"); - properties.setProperty("ninefold-compute.image.login-user", "user:Password01"); - properties.setProperty("ninefold-compute.image.authenticate-sudo", "true"); - return properties; - } - - public NinefoldComputePropertiesBuilder(Properties properties) { - super(properties); - } - -} diff --git a/providers/ninefold-compute/src/main/java/org/jclouds/ninefold/compute/NinefoldComputeProviderMetadata.java b/providers/ninefold-compute/src/main/java/org/jclouds/ninefold/compute/NinefoldComputeProviderMetadata.java index 06b8a77b71..46da1fbdeb 100644 --- a/providers/ninefold-compute/src/main/java/org/jclouds/ninefold/compute/NinefoldComputeProviderMetadata.java +++ b/providers/ninefold-compute/src/main/java/org/jclouds/ninefold/compute/NinefoldComputeProviderMetadata.java @@ -1,66 +1,75 @@ -/** - * 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.ninefold.compute; import java.net.URI; +import java.util.Properties; import org.jclouds.cloudstack.CloudStackApiMetadata; -import org.jclouds.providers.BaseProviderMetadata; +import org.jclouds.cloudstack.CloudStackAsyncClient; +import org.jclouds.cloudstack.CloudStackClient; +import org.jclouds.cloudstack.CloudStackContext; +import org.jclouds.providers.ProviderMetadata; +import org.jclouds.providers.internal.BaseProviderMetadata; /** * Implementation of {@link org.jclouds.types.ProviderMetadata} for Ninefold - * Compute. - * + * Compute. * @author Adrian Cole */ -public class NinefoldComputeProviderMetadata extends BaseProviderMetadata { +public class NinefoldComputeProviderMetadata + extends + BaseProviderMetadata { - public NinefoldComputeProviderMetadata() { - this(builder() - .id("ninefold-compute") - .name("Ninefold Compute") - .api(new CloudStackApiMetadata()) - .homepage(URI.create("http://ninefold.com/virtual-servers/")) - .console(URI.create("https://ninefold.com/portal/portal/login")) - .iso3166Codes("AU-NSW")); + public static Builder builder() { + return new Builder(); } - // below are so that we can reuse builders, toString, hashCode, etc. - // we have to set concrete classes here, as our base class cannot be - // concrete due to serviceLoader - protected NinefoldComputeProviderMetadata(ConcreteBuilder builder) { + @Override + public Builder toBuilder() { + return builder().fromProviderMetadata(this); + } + + public NinefoldComputeProviderMetadata() { + super(builder()); + } + + public NinefoldComputeProviderMetadata(Builder builder) { super(builder); } - private static class ConcreteBuilder extends Builder { + protected static Properties defaultProperties() { + Properties properties = new Properties(); + properties.setProperty("ninefold-compute.image-id", "1215"); + properties.setProperty("ninefold-compute.image.login-user", "user:Password01"); + properties.setProperty("ninefold-compute.image.authenticate-sudo", "true"); + return properties; + } + + public static class Builder + extends + BaseProviderMetadata.Builder { + + protected Builder() { + id("ninefold-compute") + .name("Ninefold Compute") + .apiMetadata(new CloudStackApiMetadata().toBuilder().version("2.2.12").build()) + .homepage(URI.create("http://ninefold.com/virtual-servers/")) + .console(URI.create("https://ninefold.com/portal/portal/login")) + .iso3166Codes("AU-NSW") + .endpoint("https://api.ninefold.com/compute/v1.0/") + .defaultProperties(NinefoldComputeProviderMetadata.defaultProperties()); + } @Override public NinefoldComputeProviderMetadata build() { return new NinefoldComputeProviderMetadata(this); } - } - public static ConcreteBuilder builder() { - return new ConcreteBuilder(); - } + @Override + public Builder fromProviderMetadata( + ProviderMetadata in) { + super.fromProviderMetadata(in); + return this; + } - public ConcreteBuilder toBuilder() { - return builder().fromProviderMetadata(this); } -} +} \ No newline at end of file diff --git a/providers/ninefold-compute/src/main/java/org/jclouds/ninefold/compute/config/NinefoldComputeServiceContextModule.java b/providers/ninefold-compute/src/main/java/org/jclouds/ninefold/compute/config/NinefoldComputeServiceContextModule.java deleted file mode 100644 index e7551e4c30..0000000000 --- a/providers/ninefold-compute/src/main/java/org/jclouds/ninefold/compute/config/NinefoldComputeServiceContextModule.java +++ /dev/null @@ -1,29 +0,0 @@ -/** - * 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.ninefold.compute.config; - -import org.jclouds.cloudstack.compute.config.CloudStackComputeServiceContextModule; - -/** - * - * @author Adrian Cole - */ -public class NinefoldComputeServiceContextModule extends CloudStackComputeServiceContextModule { - -} diff --git a/providers/ninefold-compute/src/test/java/org/jclouds/ninefold/compute/NinefoldComputeProviderTest.java b/providers/ninefold-compute/src/test/java/org/jclouds/ninefold/compute/NinefoldComputeProviderTest.java index 0aec023a22..50fc82e0fe 100644 --- a/providers/ninefold-compute/src/test/java/org/jclouds/ninefold/compute/NinefoldComputeProviderTest.java +++ b/providers/ninefold-compute/src/test/java/org/jclouds/ninefold/compute/NinefoldComputeProviderTest.java @@ -19,7 +19,7 @@ package org.jclouds.ninefold.compute; import org.jclouds.cloudstack.CloudStackApiMetadata; -import org.jclouds.providers.BaseProviderMetadataTest; +import org.jclouds.providers.internal.BaseProviderMetadataTest; import org.testng.annotations.Test; /** diff --git a/providers/ninefold-compute/src/test/java/org/jclouds/ninefold/compute/compute/NinefoldComputeTemplateBuilderLiveTest.java b/providers/ninefold-compute/src/test/java/org/jclouds/ninefold/compute/compute/NinefoldComputeTemplateBuilderLiveTest.java index 71d3fb66d0..5368814810 100644 --- a/providers/ninefold-compute/src/test/java/org/jclouds/ninefold/compute/compute/NinefoldComputeTemplateBuilderLiveTest.java +++ b/providers/ninefold-compute/src/test/java/org/jclouds/ninefold/compute/compute/NinefoldComputeTemplateBuilderLiveTest.java @@ -24,10 +24,13 @@ import static org.testng.Assert.assertEquals; import java.io.IOException; import java.util.Set; -import org.jclouds.compute.BaseTemplateBuilderLiveTest; +import org.jclouds.cloudstack.CloudStackAsyncClient; +import org.jclouds.cloudstack.CloudStackClient; +import org.jclouds.cloudstack.CloudStackContext; import org.jclouds.compute.domain.OsFamily; import org.jclouds.compute.domain.OsFamilyVersion64Bit; import org.jclouds.compute.domain.Template; +import org.jclouds.compute.internal.BaseTemplateBuilderLiveTest; import org.testng.annotations.Test; import com.google.common.base.Predicate; @@ -39,7 +42,9 @@ import com.google.common.collect.ImmutableSet; * @author Adrian Cole */ @Test(groups = "live") -public class NinefoldComputeTemplateBuilderLiveTest extends BaseTemplateBuilderLiveTest { +public class NinefoldComputeTemplateBuilderLiveTest + extends + BaseTemplateBuilderLiveTest { public NinefoldComputeTemplateBuilderLiveTest() { provider = "ninefold-compute"; diff --git a/providers/ninefold-storage/pom.xml b/providers/ninefold-storage/pom.xml index 746355dd38..a25d2ae2b8 100644 --- a/providers/ninefold-storage/pom.xml +++ b/providers/ninefold-storage/pom.xml @@ -34,7 +34,6 @@ bundle - org.jclouds.ninefold.storage.blobstore.integration.NinefoldStorageTestInitializer http://onlinestorage.ninefold.com 1.4.0 @@ -106,7 +105,6 @@ ${test.ninefold-storage.build-version} ${test.ninefold-storage.identity} ${test.ninefold-storage.credential} - ${test.initializer} ${jclouds.blobstore.httpstream.url} ${jclouds.blobstore.httpstream.md5} diff --git a/providers/ninefold-storage/src/main/java/org/jclouds/ninefold/storage/NinefoldStoragePropertiesBuilder.java b/providers/ninefold-storage/src/main/java/org/jclouds/ninefold/storage/NinefoldStoragePropertiesBuilder.java deleted file mode 100644 index 871c043251..0000000000 --- a/providers/ninefold-storage/src/main/java/org/jclouds/ninefold/storage/NinefoldStoragePropertiesBuilder.java +++ /dev/null @@ -1,53 +0,0 @@ -/** - * 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.ninefold.storage; - -import static org.jclouds.Constants.PROPERTY_API_VERSION; -import static org.jclouds.Constants.PROPERTY_ENDPOINT; -import static org.jclouds.Constants.PROPERTY_ISO3166_CODES; - -import java.util.Properties; - -import org.jclouds.PropertiesBuilder; - -/** - * Builds properties used in Ninefold Storage - * - * @author Adrian Cole - */ -public class NinefoldStoragePropertiesBuilder extends PropertiesBuilder { - - @Override - protected Properties defaultProperties() { - Properties properties = super.defaultProperties(); - properties.setProperty(PROPERTY_ENDPOINT, "http://onlinestorage.ninefold.com"); - properties.setProperty(PROPERTY_ISO3166_CODES, "AU-NSW"); - properties.setProperty(PROPERTY_API_VERSION, "1.4.0"); - return properties; - } - - public NinefoldStoragePropertiesBuilder() { - super(); - } - - public NinefoldStoragePropertiesBuilder(Properties properties) { - super(properties); - } - -} diff --git a/providers/ninefold-storage/src/main/java/org/jclouds/ninefold/storage/NinefoldStorageProviderMetadata.java b/providers/ninefold-storage/src/main/java/org/jclouds/ninefold/storage/NinefoldStorageProviderMetadata.java index 14e40a6f8f..152c46df77 100644 --- a/providers/ninefold-storage/src/main/java/org/jclouds/ninefold/storage/NinefoldStorageProviderMetadata.java +++ b/providers/ninefold-storage/src/main/java/org/jclouds/ninefold/storage/NinefoldStorageProviderMetadata.java @@ -19,9 +19,14 @@ package org.jclouds.ninefold.storage; import java.net.URI; +import java.util.Properties; import org.jclouds.atmos.AtmosApiMetadata; -import org.jclouds.providers.BaseProviderMetadata; +import org.jclouds.atmos.AtmosAsyncClient; +import org.jclouds.atmos.AtmosClient; +import org.jclouds.blobstore.BlobStoreContext; +import org.jclouds.providers.ProviderMetadata; +import org.jclouds.providers.internal.BaseProviderMetadata; /** * Implementation of {@link org.jclouds.types.ProviderMetadata} for Ninefold's @@ -29,38 +34,53 @@ import org.jclouds.providers.BaseProviderMetadata; * * @author Jeremy Whitlock */ -public class NinefoldStorageProviderMetadata extends BaseProviderMetadata { - - public NinefoldStorageProviderMetadata() { - this(builder() - .id("ninefold-storage") - .name("Ninefold Storage") - .api(new AtmosApiMetadata()) - .homepage(URI.create("http://ninefold.com/cloud-storage/")) - .console(URI.create("https://ninefold.com/portal/")) - .iso3166Codes("AU-NSW")); +public class NinefoldStorageProviderMetadata extends BaseProviderMetadata, AtmosApiMetadata> { + + public static Builder builder() { + return new Builder(); } - // below are so that we can reuse builders, toString, hashCode, etc. - // we have to set concrete classes here, as our base class cannot be - // concrete due to serviceLoader - protected NinefoldStorageProviderMetadata(ConcreteBuilder builder) { + @Override + public Builder toBuilder() { + return builder().fromProviderMetadata(this); + } + + public NinefoldStorageProviderMetadata() { + super(builder()); + } + + public NinefoldStorageProviderMetadata(Builder builder) { super(builder); } - private static class ConcreteBuilder extends Builder { + protected static Properties defaultProperties() { + Properties properties = new Properties(); + return properties; + } + + public static class Builder extends BaseProviderMetadata.Builder, AtmosApiMetadata> { + + protected Builder(){ + id("ninefold-storage") + .name("Ninefold Storage") + .apiMetadata(new AtmosApiMetadata()) + .homepage(URI.create("http://ninefold.com/cloud-storage/")) + .console(URI.create("https://ninefold.com/portal/")) + .iso3166Codes("AU-NSW") + .endpoint("http://onlinestorage.ninefold.com") + .defaultProperties(NinefoldStorageProviderMetadata.defaultProperties()); + } @Override public NinefoldStorageProviderMetadata build() { return new NinefoldStorageProviderMetadata(this); } + + @Override + public Builder fromProviderMetadata( + ProviderMetadata, AtmosApiMetadata> in) { + super.fromProviderMetadata(in); + return this; + } } - - public static ConcreteBuilder builder() { - return new ConcreteBuilder(); - } - - public ConcreteBuilder toBuilder() { - return builder().fromProviderMetadata(this); - } -} +} \ No newline at end of file diff --git a/providers/ninefold-storage/src/test/java/org/jclouds/ninefold/storage/NinefoldStorageProviderTest.java b/providers/ninefold-storage/src/test/java/org/jclouds/ninefold/storage/NinefoldStorageProviderTest.java index 499648c11b..ccd275f809 100644 --- a/providers/ninefold-storage/src/test/java/org/jclouds/ninefold/storage/NinefoldStorageProviderTest.java +++ b/providers/ninefold-storage/src/test/java/org/jclouds/ninefold/storage/NinefoldStorageProviderTest.java @@ -19,7 +19,7 @@ package org.jclouds.ninefold.storage; import org.jclouds.atmos.AtmosApiMetadata; -import org.jclouds.providers.BaseProviderMetadataTest; +import org.jclouds.providers.internal.BaseProviderMetadataTest; import org.testng.annotations.Test; /** diff --git a/providers/ninefold-storage/src/test/java/org/jclouds/ninefold/storage/blobstore/integration/NinefoldStorageBlobIntegrationLiveTest.java b/providers/ninefold-storage/src/test/java/org/jclouds/ninefold/storage/blobstore/integration/NinefoldStorageBlobIntegrationLiveTest.java index fa45cf29f0..85459aed79 100644 --- a/providers/ninefold-storage/src/test/java/org/jclouds/ninefold/storage/blobstore/integration/NinefoldStorageBlobIntegrationLiveTest.java +++ b/providers/ninefold-storage/src/test/java/org/jclouds/ninefold/storage/blobstore/integration/NinefoldStorageBlobIntegrationLiveTest.java @@ -27,4 +27,7 @@ import org.testng.annotations.Test; @Test(groups = "live", testName = "NinefoldStorageBlobIntegrationLiveTest") public class NinefoldStorageBlobIntegrationLiveTest extends AtmosIntegrationLiveTest { + public NinefoldStorageBlobIntegrationLiveTest() { + provider = "ninefold-storage"; + } } diff --git a/providers/ninefold-storage/src/test/java/org/jclouds/ninefold/storage/blobstore/integration/NinefoldStorageBlobLiveTest.java b/providers/ninefold-storage/src/test/java/org/jclouds/ninefold/storage/blobstore/integration/NinefoldStorageBlobLiveTest.java index de886df4ad..1e726acd69 100644 --- a/providers/ninefold-storage/src/test/java/org/jclouds/ninefold/storage/blobstore/integration/NinefoldStorageBlobLiveTest.java +++ b/providers/ninefold-storage/src/test/java/org/jclouds/ninefold/storage/blobstore/integration/NinefoldStorageBlobLiveTest.java @@ -27,4 +27,7 @@ import org.testng.annotations.Test; @Test(groups = "live", testName = "NinefoldStorageBlobLiveTest") public class NinefoldStorageBlobLiveTest extends AtmosLiveTest { + public NinefoldStorageBlobLiveTest() { + provider = "ninefold-storage"; + } } diff --git a/providers/ninefold-storage/src/test/java/org/jclouds/ninefold/storage/blobstore/integration/NinefoldStorageBlobMapIntegrationLiveTest.java b/providers/ninefold-storage/src/test/java/org/jclouds/ninefold/storage/blobstore/integration/NinefoldStorageBlobMapIntegrationLiveTest.java index ab1d17221c..5028fa6261 100644 --- a/providers/ninefold-storage/src/test/java/org/jclouds/ninefold/storage/blobstore/integration/NinefoldStorageBlobMapIntegrationLiveTest.java +++ b/providers/ninefold-storage/src/test/java/org/jclouds/ninefold/storage/blobstore/integration/NinefoldStorageBlobMapIntegrationLiveTest.java @@ -27,4 +27,7 @@ import org.testng.annotations.Test; @Test(groups = "live", testName = "NinefoldStorageBlobMapIntegrationLiveTest") public class NinefoldStorageBlobMapIntegrationLiveTest extends AtmosMapIntegrationLiveTest { + public NinefoldStorageBlobMapIntegrationLiveTest() { + provider = "ninefold-storage"; + } } diff --git a/providers/ninefold-storage/src/test/java/org/jclouds/ninefold/storage/blobstore/integration/NinefoldStorageBlobSignerLiveTest.java b/providers/ninefold-storage/src/test/java/org/jclouds/ninefold/storage/blobstore/integration/NinefoldStorageBlobSignerLiveTest.java index 81051acf30..c46e66c640 100644 --- a/providers/ninefold-storage/src/test/java/org/jclouds/ninefold/storage/blobstore/integration/NinefoldStorageBlobSignerLiveTest.java +++ b/providers/ninefold-storage/src/test/java/org/jclouds/ninefold/storage/blobstore/integration/NinefoldStorageBlobSignerLiveTest.java @@ -28,4 +28,7 @@ import org.testng.annotations.Test; @Test(groups = "live", testName = "NinefoldStorageBlobSignerLiveTest") public class NinefoldStorageBlobSignerLiveTest extends AtmosBlobSignerLiveTest { + public NinefoldStorageBlobSignerLiveTest() { + provider = "ninefold-storage"; + } } diff --git a/providers/ninefold-storage/src/test/java/org/jclouds/ninefold/storage/blobstore/integration/NinefoldStorageContainerIntegrationLiveTest.java b/providers/ninefold-storage/src/test/java/org/jclouds/ninefold/storage/blobstore/integration/NinefoldStorageContainerIntegrationLiveTest.java index c9ef0fb263..50eb0c0801 100644 --- a/providers/ninefold-storage/src/test/java/org/jclouds/ninefold/storage/blobstore/integration/NinefoldStorageContainerIntegrationLiveTest.java +++ b/providers/ninefold-storage/src/test/java/org/jclouds/ninefold/storage/blobstore/integration/NinefoldStorageContainerIntegrationLiveTest.java @@ -27,4 +27,7 @@ import org.testng.annotations.Test; @Test(groups = "live", testName = "NinefoldStorageContainerIntegrationLiveTest") public class NinefoldStorageContainerIntegrationLiveTest extends AtmosContainerIntegrationLiveTest { + public NinefoldStorageContainerIntegrationLiveTest() { + provider = "ninefold-storage"; + } } diff --git a/providers/ninefold-storage/src/test/java/org/jclouds/ninefold/storage/blobstore/integration/NinefoldStorageContainerLiveTest.java b/providers/ninefold-storage/src/test/java/org/jclouds/ninefold/storage/blobstore/integration/NinefoldStorageContainerLiveTest.java index c9f9c803f5..fb3267b3e5 100644 --- a/providers/ninefold-storage/src/test/java/org/jclouds/ninefold/storage/blobstore/integration/NinefoldStorageContainerLiveTest.java +++ b/providers/ninefold-storage/src/test/java/org/jclouds/ninefold/storage/blobstore/integration/NinefoldStorageContainerLiveTest.java @@ -27,4 +27,7 @@ import org.testng.annotations.Test; @Test(groups = "live", testName = "NinefoldStorageContainerLiveTest") public class NinefoldStorageContainerLiveTest extends AtmosContainerLiveTest { + public NinefoldStorageContainerLiveTest() { + provider = "ninefold-storage"; + } } diff --git a/providers/ninefold-storage/src/test/java/org/jclouds/ninefold/storage/blobstore/integration/NinefoldStorageInputStreamMapIntegrationLiveTest.java b/providers/ninefold-storage/src/test/java/org/jclouds/ninefold/storage/blobstore/integration/NinefoldStorageInputStreamMapIntegrationLiveTest.java index 0cc55b3731..b7524ba753 100644 --- a/providers/ninefold-storage/src/test/java/org/jclouds/ninefold/storage/blobstore/integration/NinefoldStorageInputStreamMapIntegrationLiveTest.java +++ b/providers/ninefold-storage/src/test/java/org/jclouds/ninefold/storage/blobstore/integration/NinefoldStorageInputStreamMapIntegrationLiveTest.java @@ -27,4 +27,7 @@ import org.testng.annotations.Test; @Test(groups = "live", testName = "NinefoldStorageInputStreamMapIntegrationLiveTest") public class NinefoldStorageInputStreamMapIntegrationLiveTest extends AtmosInputStreamMapIntegrationLiveTest { + public NinefoldStorageInputStreamMapIntegrationLiveTest() { + provider = "ninefold-storage"; + } } diff --git a/providers/ninefold-storage/src/test/java/org/jclouds/ninefold/storage/blobstore/integration/NinefoldStorageServiceIntegrationLiveTest.java b/providers/ninefold-storage/src/test/java/org/jclouds/ninefold/storage/blobstore/integration/NinefoldStorageServiceIntegrationLiveTest.java index 206f6a85f7..2bdec426ec 100644 --- a/providers/ninefold-storage/src/test/java/org/jclouds/ninefold/storage/blobstore/integration/NinefoldStorageServiceIntegrationLiveTest.java +++ b/providers/ninefold-storage/src/test/java/org/jclouds/ninefold/storage/blobstore/integration/NinefoldStorageServiceIntegrationLiveTest.java @@ -30,6 +30,11 @@ import com.google.common.collect.ImmutableSet; */ @Test(groups = "live", testName = "NinefoldStorageServiceIntegrationLiveTest") public class NinefoldStorageServiceIntegrationLiveTest extends AtmosServiceIntegrationLiveTest { + + public NinefoldStorageServiceIntegrationLiveTest() { + provider = "ninefold-storage"; + } + @Override protected Set getIso3166Codes() { return ImmutableSet. of("AU-NSW"); diff --git a/providers/ninefold-storage/src/test/java/org/jclouds/ninefold/storage/blobstore/integration/NinefoldStorageTestInitializer.java b/providers/ninefold-storage/src/test/java/org/jclouds/ninefold/storage/blobstore/integration/NinefoldStorageTestInitializer.java deleted file mode 100644 index b9d7d37603..0000000000 --- a/providers/ninefold-storage/src/test/java/org/jclouds/ninefold/storage/blobstore/integration/NinefoldStorageTestInitializer.java +++ /dev/null @@ -1,33 +0,0 @@ -/** - * 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.ninefold.storage.blobstore.integration; - -import org.jclouds.atmos.blobstore.integration.AtmosTestInitializer; - -/** - * - * @author Adrian Cole - */ -public class NinefoldStorageTestInitializer extends AtmosTestInitializer { - - public NinefoldStorageTestInitializer() { - provider = "ninefold-storage"; - } - -} diff --git a/providers/openhosting-east1/src/main/java/org/jclouds/openhosting/OpenHostingEast1ContextBuilder.java b/providers/openhosting-east1/src/main/java/org/jclouds/openhosting/OpenHostingEast1ContextBuilder.java deleted file mode 100644 index 5a55f81ddf..0000000000 --- a/providers/openhosting-east1/src/main/java/org/jclouds/openhosting/OpenHostingEast1ContextBuilder.java +++ /dev/null @@ -1,44 +0,0 @@ -/** - * 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.openhosting; - -import java.util.List; -import java.util.Properties; - -import org.jclouds.elasticstack.ElasticStackContextBuilder; -import org.jclouds.openhosting.config.OpenHostingEast1ComputeServiceContextModule; - -import com.google.inject.Module; - -/** - * - * @author Adrian Cole - */ -public class OpenHostingEast1ContextBuilder extends ElasticStackContextBuilder { - - public OpenHostingEast1ContextBuilder(Properties props) { - super(props); - } - - @Override - protected void addContextModule(List modules) { - modules.add(new OpenHostingEast1ComputeServiceContextModule()); - } - -} diff --git a/providers/openhosting-east1/src/main/java/org/jclouds/openhosting/OpenHostingEast1PropertiesBuilder.java b/providers/openhosting-east1/src/main/java/org/jclouds/openhosting/OpenHostingEast1PropertiesBuilder.java deleted file mode 100644 index 01c05710fd..0000000000 --- a/providers/openhosting-east1/src/main/java/org/jclouds/openhosting/OpenHostingEast1PropertiesBuilder.java +++ /dev/null @@ -1,48 +0,0 @@ -/** - * 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.openhosting; - -import static org.jclouds.Constants.PROPERTY_API_VERSION; -import static org.jclouds.Constants.PROPERTY_ENDPOINT; -import static org.jclouds.Constants.PROPERTY_ISO3166_CODES; - -import java.util.Properties; - -import org.jclouds.elasticstack.ElasticStackPropertiesBuilder; - -/** - * - * @author Adrian Cole - */ -public class OpenHostingEast1PropertiesBuilder extends ElasticStackPropertiesBuilder { - - @Override - protected Properties defaultProperties() { - Properties properties = super.defaultProperties(); - properties.setProperty(PROPERTY_ISO3166_CODES, "US-FL"); - properties.setProperty(PROPERTY_ENDPOINT, "https://api.east1.openhosting.com"); - properties.setProperty(PROPERTY_API_VERSION, "2.0"); - return properties; - } - - public OpenHostingEast1PropertiesBuilder(Properties properties) { - super(properties); - } - -} diff --git a/providers/openhosting-east1/src/main/java/org/jclouds/openhosting/OpenHostingEast1ProviderMetadata.java b/providers/openhosting-east1/src/main/java/org/jclouds/openhosting/OpenHostingEast1ProviderMetadata.java index 6944d07aff..b1e33c13ca 100644 --- a/providers/openhosting-east1/src/main/java/org/jclouds/openhosting/OpenHostingEast1ProviderMetadata.java +++ b/providers/openhosting-east1/src/main/java/org/jclouds/openhosting/OpenHostingEast1ProviderMetadata.java @@ -19,48 +19,72 @@ package org.jclouds.openhosting; import java.net.URI; +import java.util.Properties; +import org.jclouds.compute.ComputeServiceContext; import org.jclouds.elasticstack.ElasticStackApiMetadata; -import org.jclouds.providers.BaseProviderMetadata; +import org.jclouds.elasticstack.ElasticStackAsyncClient; +import org.jclouds.elasticstack.ElasticStackClient; +import org.jclouds.providers.ProviderMetadata; +import org.jclouds.providers.internal.BaseProviderMetadata; /** - * Implementation of {@link org.jclouds.types.ProviderMetadata} for ElasticHosts London Peer 1. - * + * Implementation of {@link org.jclouds.types.ProviderMetadata} for OpenHosting East1. + * * @author Adrian Cole */ -public class OpenHostingEast1ProviderMetadata extends BaseProviderMetadata { +public class OpenHostingEast1ProviderMetadata + extends + BaseProviderMetadata, ElasticStackApiMetadata> { - public OpenHostingEast1ProviderMetadata() { - this(builder() - .id("openhosting-east1") - .name("OpenHosting East1") - .api(new ElasticStackApiMetadata()) - .homepage(URI.create("https://east1.openhosting.com")) - .console(URI.create("https://east1.openhosting.com/accounts")) - .iso3166Codes("US-VA")); + public static Builder builder() { + return new Builder(); } - // below are so that we can reuse builders, toString, hashCode, etc. - // we have to set concrete classes here, as our base class cannot be - // concrete due to serviceLoader - protected OpenHostingEast1ProviderMetadata(ConcreteBuilder builder) { + @Override + public Builder toBuilder() { + return builder().fromProviderMetadata(this); + } + + public OpenHostingEast1ProviderMetadata() { + super(builder()); + } + + public OpenHostingEast1ProviderMetadata(Builder builder) { super(builder); } - private static class ConcreteBuilder extends Builder { + protected static Properties defaultProperties() { + Properties properties = new Properties(); + return properties; + } + + public static class Builder + extends + BaseProviderMetadata.Builder, ElasticStackApiMetadata> { + + protected Builder() { + id("openhosting-east1") + .name("OpenHosting East1") + .apiMetadata(new ElasticStackApiMetadata()) + .homepage(URI.create("https://east1.openhosting.com")) + .console(URI.create("https://east1.openhosting.com/accounts")) + .iso3166Codes("US-VA") + .endpoint("https://api.east1.openhosting.com") + .defaultProperties(OpenHostingEast1ProviderMetadata.defaultProperties()); + } @Override public OpenHostingEast1ProviderMetadata build() { return new OpenHostingEast1ProviderMetadata(this); } - } - public static ConcreteBuilder builder() { - return new ConcreteBuilder(); - } + @Override + public Builder fromProviderMetadata( + ProviderMetadata, ElasticStackApiMetadata> in) { + super.fromProviderMetadata(in); + return this; + } - public ConcreteBuilder toBuilder() { - return builder().fromProviderMetadata(this); } - -} +} \ No newline at end of file diff --git a/providers/openhosting-east1/src/test/java/org/jclouds/openhosting/OpenHostingEast1ProviderTest.java b/providers/openhosting-east1/src/test/java/org/jclouds/openhosting/OpenHostingEast1ProviderTest.java index 7caa1d9564..a40c09c9a0 100644 --- a/providers/openhosting-east1/src/test/java/org/jclouds/openhosting/OpenHostingEast1ProviderTest.java +++ b/providers/openhosting-east1/src/test/java/org/jclouds/openhosting/OpenHostingEast1ProviderTest.java @@ -19,7 +19,7 @@ package org.jclouds.openhosting; import org.jclouds.elasticstack.ElasticStackApiMetadata; -import org.jclouds.providers.BaseProviderMetadataTest; +import org.jclouds.providers.internal.BaseProviderMetadataTest; import org.testng.annotations.Test; /** diff --git a/providers/openhosting-east1/src/test/java/org/jclouds/openhosting/compute/OpenHostingEast1TemplateBuilderLiveTest.java b/providers/openhosting-east1/src/test/java/org/jclouds/openhosting/compute/OpenHostingEast1TemplateBuilderLiveTest.java index 96e00c3b5b..50a86d8a3a 100644 --- a/providers/openhosting-east1/src/test/java/org/jclouds/openhosting/compute/OpenHostingEast1TemplateBuilderLiveTest.java +++ b/providers/openhosting-east1/src/test/java/org/jclouds/openhosting/compute/OpenHostingEast1TemplateBuilderLiveTest.java @@ -24,10 +24,13 @@ import static org.testng.Assert.assertEquals; import java.io.IOException; import java.util.Set; -import org.jclouds.compute.BaseTemplateBuilderLiveTest; +import org.jclouds.compute.ComputeServiceContext; import org.jclouds.compute.domain.OsFamily; import org.jclouds.compute.domain.OsFamilyVersion64Bit; import org.jclouds.compute.domain.Template; +import org.jclouds.compute.internal.BaseTemplateBuilderLiveTest; +import org.jclouds.elasticstack.ElasticStackAsyncClient; +import org.jclouds.elasticstack.ElasticStackClient; import org.testng.annotations.Test; import com.google.common.base.Predicate; @@ -39,7 +42,9 @@ import com.google.common.collect.ImmutableSet; * @author Adrian Cole */ @Test(groups = "live") -public class OpenHostingEast1TemplateBuilderLiveTest extends BaseTemplateBuilderLiveTest { +public class OpenHostingEast1TemplateBuilderLiveTest + extends + BaseTemplateBuilderLiveTest> { public OpenHostingEast1TemplateBuilderLiveTest() { provider = "openhosting-east1"; @@ -52,16 +57,16 @@ public class OpenHostingEast1TemplateBuilderLiveTest extends BaseTemplateBuilder @Override public boolean apply(OsFamilyVersion64Bit input) { switch (input.family) { - case WINDOWS: - return (input.version.equals("") || input.version.equals("2008 R2")) && input.is64Bit; - case UBUNTU: - return (input.version.equals("") || input.version.equals("10.04")) && input.is64Bit; - case DEBIAN: - return (input.version.equals("") || input.version.matches("[56].0")) && input.is64Bit; - case CENTOS: - return (input.version.equals("") || input.version.matches("5.[567]")) && input.is64Bit; - default: - return false; + case WINDOWS: + return (input.version.equals("") || input.version.equals("2008 R2")) && input.is64Bit; + case UBUNTU: + return (input.version.equals("") || input.version.equals("10.04")) && input.is64Bit; + case DEBIAN: + return (input.version.equals("") || input.version.matches("[56].0")) && input.is64Bit; + case CENTOS: + return (input.version.equals("") || input.version.matches("5.[567]")) && input.is64Bit; + default: + return false; } } diff --git a/providers/rimuhosting/src/main/java/org/jclouds/rimuhosting/miro/RimuHostingApiMetadata.java b/providers/rimuhosting/src/main/java/org/jclouds/rimuhosting/miro/RimuHostingApiMetadata.java index 795afc54ab..1ea439a161 100644 --- a/providers/rimuhosting/src/main/java/org/jclouds/rimuhosting/miro/RimuHostingApiMetadata.java +++ b/providers/rimuhosting/src/main/java/org/jclouds/rimuhosting/miro/RimuHostingApiMetadata.java @@ -18,50 +18,80 @@ */ package org.jclouds.rimuhosting.miro; +import static org.jclouds.Constants.PROPERTY_CONNECTION_TIMEOUT; +import static org.jclouds.Constants.PROPERTY_SO_TIMEOUT; + import java.net.URI; +import java.util.Properties; import org.jclouds.apis.ApiMetadata; import org.jclouds.apis.ApiType; -import org.jclouds.apis.BaseApiMetadata; +import org.jclouds.compute.ComputeServiceContext; +import org.jclouds.compute.config.ComputeServiceProperties; +import org.jclouds.compute.internal.BaseComputeServiceApiMetadata; +import org.jclouds.concurrent.Timeout; + +import com.google.common.reflect.TypeToken; /** * Implementation of {@link ApiMetadata} for RimuHosting API * * @author Adrian Cole */ -public class RimuHostingApiMetadata extends BaseApiMetadata { +public class RimuHostingApiMetadata + extends + BaseComputeServiceApiMetadata, RimuHostingApiMetadata> { - public RimuHostingApiMetadata() { - this(builder() - .id("rimuhosting") - .type(ApiType.COMPUTE) - .name("RimuHosting API") - .identityName("API Key") - .documentation(URI.create("http://apidocs.rimuhosting.com"))); + @Override + public Builder toBuilder() { + return new Builder().fromApiMetadata(this); } - // below are so that we can reuse builders, toString, hashCode, etc. - // we have to set concrete classes here, as our base class cannot be - // concrete due to serviceLoader - protected RimuHostingApiMetadata(Builder builder) { + public RimuHostingApiMetadata() { + this(new Builder()); + } + + protected RimuHostingApiMetadata(Builder builder) { super(builder); } - private static class ConcreteBuilder extends Builder { + protected static Properties defaultProperties() { + Properties properties = BaseComputeServiceApiMetadata.Builder.defaultProperties(); + Timeout timeout = RimuHostingClient.class.getAnnotation(Timeout.class); + long timeoutMillis = timeout.timeUnit().toMillis(timeout.duration()); + properties.setProperty(PROPERTY_SO_TIMEOUT, timeoutMillis + ""); + properties.setProperty(PROPERTY_CONNECTION_TIMEOUT, timeoutMillis + ""); + properties.setProperty(ComputeServiceProperties.TIMEOUT_NODE_TERMINATED, 60 * 1000 + ""); + return properties; + } + + public static class Builder + extends + BaseComputeServiceApiMetadata.Builder, RimuHostingApiMetadata> { + + protected Builder() { + id("rimuhosting") + .type(ApiType.COMPUTE) + .name("RimuHosting API") + .identityName("API Key") + .documentation(URI.create("http://apidocs.rimuhosting.com")) + .version("1") + .defaultEndpoint("https://api.rimuhosting.com/r") + .javaApi(RimuHostingClient.class, RimuHostingAsyncClient.class) + .contextBuilder(TypeToken.of(RimuHostingContextBuilder.class)); + } @Override public RimuHostingApiMetadata build() { return new RimuHostingApiMetadata(this); } + + @Override + public Builder fromApiMetadata(RimuHostingApiMetadata in) { + super.fromApiMetadata(in); + return this; + } + } - public static ConcreteBuilder builder() { - return new ConcreteBuilder(); - } - - @Override - public ConcreteBuilder toBuilder() { - return builder().fromApiMetadata(this); - } - -} \ No newline at end of file +} diff --git a/providers/rimuhosting/src/main/java/org/jclouds/rimuhosting/miro/RimuHostingContextBuilder.java b/providers/rimuhosting/src/main/java/org/jclouds/rimuhosting/miro/RimuHostingContextBuilder.java index 68f3f2971d..e01c11d97b 100644 --- a/providers/rimuhosting/src/main/java/org/jclouds/rimuhosting/miro/RimuHostingContextBuilder.java +++ b/providers/rimuhosting/src/main/java/org/jclouds/rimuhosting/miro/RimuHostingContextBuilder.java @@ -19,38 +19,30 @@ package org.jclouds.rimuhosting.miro; import java.util.List; -import java.util.Properties; import org.jclouds.compute.ComputeServiceContext; import org.jclouds.compute.ComputeServiceContextBuilder; -import org.jclouds.compute.internal.ComputeServiceContextImpl; -import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule; -import org.jclouds.logging.jdk.config.JDKLoggingModule; +import org.jclouds.providers.ProviderMetadata; import org.jclouds.rimuhosting.miro.compute.config.RimuHostingComputeServiceContextModule; import org.jclouds.rimuhosting.miro.config.RimuHostingRestClientModule; -import com.google.inject.Injector; -import com.google.inject.Key; import com.google.inject.Module; -import com.google.inject.TypeLiteral; /** - * Creates {@link RimuHostingComputeServiceContext} or {@link Injector} instances based on the most - * commonly requested arguments. - *

- * Note that Threadsafe objects will be bound as singletons to the Injector or Context provided. - *

- *

- * If no Modules are specified, the default {@link JDKLoggingModule logging} and - * {@link JavaUrlHttpCommandExecutorServiceModule http transports} will be installed. * * @author Adrian Cole - * @see RimuHostingComputeServiceContext */ -public class RimuHostingContextBuilder extends ComputeServiceContextBuilder { +public class RimuHostingContextBuilder + extends + ComputeServiceContextBuilder, RimuHostingApiMetadata> { - public RimuHostingContextBuilder(Properties props) { - super(RimuHostingClient.class, RimuHostingAsyncClient.class, props); + public RimuHostingContextBuilder( + ProviderMetadata, RimuHostingApiMetadata> providerMetadata) { + super(providerMetadata); + } + + public RimuHostingContextBuilder(RimuHostingApiMetadata apiMetadata) { + super(apiMetadata); } @Override @@ -58,16 +50,8 @@ public class RimuHostingContextBuilder extends ComputeServiceContextBuilder>() { - })); - } - - @Override protected void addClientModule(List modules) { modules.add(new RimuHostingRestClientModule()); } + } diff --git a/providers/rimuhosting/src/main/java/org/jclouds/rimuhosting/miro/RimuHostingPropertiesBuilder.java b/providers/rimuhosting/src/main/java/org/jclouds/rimuhosting/miro/RimuHostingPropertiesBuilder.java deleted file mode 100644 index ea3562fcfa..0000000000 --- a/providers/rimuhosting/src/main/java/org/jclouds/rimuhosting/miro/RimuHostingPropertiesBuilder.java +++ /dev/null @@ -1,66 +0,0 @@ -/** - * 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.rimuhosting.miro; - -import static org.jclouds.Constants.PROPERTY_API_VERSION; -import static org.jclouds.Constants.PROPERTY_CONNECTION_TIMEOUT; -import static org.jclouds.Constants.PROPERTY_ENDPOINT; -import static org.jclouds.Constants.PROPERTY_ISO3166_CODES; -import static org.jclouds.Constants.PROPERTY_SO_TIMEOUT; -import static org.jclouds.location.reference.LocationConstants.ISO3166_CODES; -import static org.jclouds.location.reference.LocationConstants.PROPERTY_ZONE; -import static org.jclouds.location.reference.LocationConstants.PROPERTY_ZONES; -import static org.jclouds.rimuhosting.miro.reference.RimuHostingConstants.PROPERTY_RIMUHOSTING_DEFAULT_DC; - -import java.util.Properties; - -import org.jclouds.PropertiesBuilder; -import org.jclouds.compute.reference.ComputeServiceConstants; -import org.jclouds.concurrent.Timeout; - -/** - * Builds properties used in RimuHosting Clients - * - * @author Adrian Cole - */ -public class RimuHostingPropertiesBuilder extends PropertiesBuilder { - @Override - protected Properties defaultProperties() { - Properties properties = super.defaultProperties(); - properties.setProperty(PROPERTY_ZONES, "DCAUCKLAND,DCLONDON,DCDALLAS,DCSYDNEY"); - properties.setProperty(PROPERTY_ISO3166_CODES, "NZ-AUK,US-TX,AU-NSW,GB-LND"); - properties.setProperty(PROPERTY_ZONE + ".DCAUCKLAND." + ISO3166_CODES, "NZ-AUK"); - properties.setProperty(PROPERTY_ZONE + ".DCLONDON." + ISO3166_CODES, "GB-LND"); - properties.setProperty(PROPERTY_ZONE + ".DCDALLAS." + ISO3166_CODES, "US-TX"); - properties.setProperty(PROPERTY_ZONE + ".DCSYDNEY." + ISO3166_CODES, "AU-NSW"); - properties.setProperty(PROPERTY_API_VERSION, "TODO"); - properties.setProperty(PROPERTY_ENDPOINT, "https://api.rimuhosting.com/r"); - properties.setProperty(PROPERTY_RIMUHOSTING_DEFAULT_DC, "DCDALLAS"); - Timeout timeout = RimuHostingClient.class.getAnnotation(Timeout.class); - long timeoutMillis = timeout.timeUnit().toMillis(timeout.duration()); - properties.setProperty(PROPERTY_SO_TIMEOUT, timeoutMillis + ""); - properties.setProperty(PROPERTY_CONNECTION_TIMEOUT, timeoutMillis + ""); - properties.setProperty(ComputeServiceConstants.PROPERTY_TIMEOUT_NODE_TERMINATED, 60 * 1000 + ""); - return properties; - } - - public RimuHostingPropertiesBuilder(Properties properties) { - super(properties); - } -} diff --git a/providers/rimuhosting/src/main/java/org/jclouds/rimuhosting/miro/RimuHostingProviderMetadata.java b/providers/rimuhosting/src/main/java/org/jclouds/rimuhosting/miro/RimuHostingProviderMetadata.java index b037c50830..5d32459a2f 100644 --- a/providers/rimuhosting/src/main/java/org/jclouds/rimuhosting/miro/RimuHostingProviderMetadata.java +++ b/providers/rimuhosting/src/main/java/org/jclouds/rimuhosting/miro/RimuHostingProviderMetadata.java @@ -18,47 +18,80 @@ */ package org.jclouds.rimuhosting.miro; -import java.net.URI; +import static org.jclouds.location.reference.LocationConstants.ISO3166_CODES; +import static org.jclouds.location.reference.LocationConstants.PROPERTY_ZONE; +import static org.jclouds.location.reference.LocationConstants.PROPERTY_ZONES; +import static org.jclouds.rimuhosting.miro.reference.RimuHostingConstants.PROPERTY_RIMUHOSTING_DEFAULT_DC; -import org.jclouds.providers.BaseProviderMetadata; +import java.net.URI; +import java.util.Properties; + +import org.jclouds.compute.ComputeServiceContext; +import org.jclouds.providers.ProviderMetadata; +import org.jclouds.providers.internal.BaseProviderMetadata; /** * Implementation of {@link org.jclouds.types.ProviderMetadata} for RimuHosting. - * * @author Adrian Cole */ -public class RimuHostingProviderMetadata extends BaseProviderMetadata { - public RimuHostingProviderMetadata() { - this(builder() - .id("rimuhosting") - .name("RimuHosting") - .api(new RimuHostingApiMetadata()) - .homepage(URI.create("http://www.rimuhosting.com")) - .console(URI.create("https://rimuhosting.com/cp")) - .iso3166Codes("NZ-AUK", "US-TX", "AU-NSW", "GB-LND")); +public class RimuHostingProviderMetadata + extends + BaseProviderMetadata, RimuHostingApiMetadata> { + + public static Builder builder() { + return new Builder(); } - // below are so that we can reuse builders, toString, hashCode, etc. - // we have to set concrete classes here, as our base class cannot be - // concrete due to serviceLoader - protected RimuHostingProviderMetadata(ConcreteBuilder builder) { + @Override + public Builder toBuilder() { + return builder().fromProviderMetadata(this); + } + + public RimuHostingProviderMetadata() { + super(builder()); + } + + public RimuHostingProviderMetadata(Builder builder) { super(builder); } - private static class ConcreteBuilder extends Builder { + protected static Properties defaultProperties() { + Properties properties = new Properties(); + properties.setProperty(PROPERTY_ZONES, "DCAUCKLAND,DCLONDON,DCDALLAS,DCSYDNEY"); + properties.setProperty(PROPERTY_ZONE + ".DCAUCKLAND." + ISO3166_CODES, "NZ-AUK"); + properties.setProperty(PROPERTY_ZONE + ".DCLONDON." + ISO3166_CODES, "GB-LND"); + properties.setProperty(PROPERTY_ZONE + ".DCDALLAS." + ISO3166_CODES, "US-TX"); + properties.setProperty(PROPERTY_ZONE + ".DCSYDNEY." + ISO3166_CODES, "AU-NSW"); + properties.setProperty(PROPERTY_RIMUHOSTING_DEFAULT_DC, "DCDALLAS"); + return properties; + } + + public static class Builder + extends + BaseProviderMetadata.Builder, RimuHostingApiMetadata> { + + protected Builder() { + id("rimuhosting") + .name("RimuHosting") + .apiMetadata(new RimuHostingApiMetadata()) + .homepage(URI.create("http://www.rimuhosting.com")) + .console(URI.create("https://rimuhosting.com/cp")) + .iso3166Codes("NZ-AUK", "US-TX", "AU-NSW", "GB-LND") + .endpoint("https://api.rimuhosting.com/r") + .defaultProperties(RimuHostingProviderMetadata.defaultProperties()); + } @Override public RimuHostingProviderMetadata build() { return new RimuHostingProviderMetadata(this); } - } - public static ConcreteBuilder builder() { - return new ConcreteBuilder(); - } + @Override + public Builder fromProviderMetadata( + ProviderMetadata, RimuHostingApiMetadata> in) { + super.fromProviderMetadata(in); + return this; + } - public ConcreteBuilder toBuilder() { - return builder().fromProviderMetadata(this); } - -} +} \ No newline at end of file diff --git a/providers/rimuhosting/src/test/java/org/jclouds/rimuhosting/miro/RimuHostingAsyncClientTest.java b/providers/rimuhosting/src/test/java/org/jclouds/rimuhosting/miro/RimuHostingAsyncClientTest.java index ff388b638d..8e08b5b83a 100644 --- a/providers/rimuhosting/src/test/java/org/jclouds/rimuhosting/miro/RimuHostingAsyncClientTest.java +++ b/providers/rimuhosting/src/test/java/org/jclouds/rimuhosting/miro/RimuHostingAsyncClientTest.java @@ -22,13 +22,11 @@ import static org.testng.Assert.assertEquals; import java.io.IOException; import java.lang.reflect.Method; -import java.util.Properties; import org.jclouds.http.HttpRequest; import org.jclouds.http.functions.UnwrapOnlyJsonValue; -import org.jclouds.rest.RestClientTest; -import org.jclouds.rest.RestContextFactory; -import org.jclouds.rest.RestContextSpec; +import org.jclouds.providers.ProviderMetadata; +import org.jclouds.rest.internal.BaseAsyncClientTest; import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.rest.internal.RestAnnotationProcessor; import org.jclouds.rimuhosting.miro.binder.CreateServerOptions; @@ -46,7 +44,7 @@ import com.google.inject.TypeLiteral; */ // NOTE:without testName, this will not call @Before* and fail w/NPE during surefire @Test(groups = "unit", testName = "RimuHostingAsyncClientTest") -public class RimuHostingAsyncClientTest extends RestClientTest { +public class RimuHostingAsyncClientTest extends BaseAsyncClientTest { public void testCreateServer() throws SecurityException, NoSuchMethodException, IOException { Method method = RimuHostingAsyncClient.class.getMethod("createServer", String.class, String.class, String.class, @@ -96,7 +94,7 @@ public class RimuHostingAsyncClientTest extends RestClientTest createContextSpec() { - return new RestContextFactory().createContextSpec("rimuhosting", "apikey", "null", new Properties()); + public ProviderMetadata createProviderMetadata() { + return new RimuHostingProviderMetadata(); } } diff --git a/providers/rimuhosting/src/test/java/org/jclouds/rimuhosting/miro/RimuHostingClientLiveTest.java b/providers/rimuhosting/src/test/java/org/jclouds/rimuhosting/miro/RimuHostingClientLiveTest.java index e63a41255e..22fd52dc70 100644 --- a/providers/rimuhosting/src/test/java/org/jclouds/rimuhosting/miro/RimuHostingClientLiveTest.java +++ b/providers/rimuhosting/src/test/java/org/jclouds/rimuhosting/miro/RimuHostingClientLiveTest.java @@ -22,13 +22,11 @@ import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNotNull; import static org.testng.Assert.assertTrue; -import java.util.Properties; import java.util.Set; -import org.jclouds.compute.BaseVersionedServiceLiveTest; -import org.jclouds.logging.log4j.config.Log4JLoggingModule; +import org.jclouds.compute.ComputeServiceContext; +import org.jclouds.compute.internal.BaseComputeServiceContextLiveTest; import org.jclouds.rest.RestContext; -import org.jclouds.rest.RestContextFactory; import org.jclouds.rimuhosting.miro.domain.Image; import org.jclouds.rimuhosting.miro.domain.NewServerResponse; import org.jclouds.rimuhosting.miro.domain.PricingPlan; @@ -38,31 +36,29 @@ import org.jclouds.rimuhosting.miro.domain.internal.RunningState; import org.testng.annotations.BeforeGroups; import org.testng.annotations.Test; -import com.google.common.collect.ImmutableSet; -import com.google.inject.Module; - /** * Tests behavior of {@code RimuHostingClient} * * @author Ivan Meredith */ @Test(groups = "live", singleThreaded = true, testName = "RimuHostingClientLiveTest") -public class RimuHostingClientLiveTest extends BaseVersionedServiceLiveTest { +public class RimuHostingClientLiveTest + extends + BaseComputeServiceContextLiveTest> { + public RimuHostingClientLiveTest() { provider = "rimuhosting"; } private RimuHostingClient connection; - private RestContext context; + private RestContext restContext; - @BeforeGroups(groups = { "live" }) - public void setupClient() { - setupCredentials(); - Properties overrides = setupProperties(); - - this.context = new RestContextFactory().createContext(provider, ImmutableSet - . of(new Log4JLoggingModule()), overrides); - this.connection = context.getApi(); + @BeforeGroups(groups = { "integration", "live" }) + @Override + public void setupContext() { + super.setupContext(); + restContext = context.getProviderSpecificContext(); + this.connection = restContext.getApi(); } diff --git a/providers/rimuhosting/src/test/java/org/jclouds/rimuhosting/miro/RimuHostingProviderTest.java b/providers/rimuhosting/src/test/java/org/jclouds/rimuhosting/miro/RimuHostingProviderTest.java index de1ad2dd48..2c43f53516 100644 --- a/providers/rimuhosting/src/test/java/org/jclouds/rimuhosting/miro/RimuHostingProviderTest.java +++ b/providers/rimuhosting/src/test/java/org/jclouds/rimuhosting/miro/RimuHostingProviderTest.java @@ -18,7 +18,7 @@ */ package org.jclouds.rimuhosting.miro; -import org.jclouds.providers.BaseProviderMetadataTest; +import org.jclouds.providers.internal.BaseProviderMetadataTest; import org.testng.annotations.Test; /** diff --git a/providers/rimuhosting/src/test/java/org/jclouds/rimuhosting/miro/compute/RimuHostingComputeServiceLiveTest.java b/providers/rimuhosting/src/test/java/org/jclouds/rimuhosting/miro/compute/RimuHostingComputeServiceLiveTest.java index 0c8bbb88ae..e03c5759e1 100644 --- a/providers/rimuhosting/src/test/java/org/jclouds/rimuhosting/miro/compute/RimuHostingComputeServiceLiveTest.java +++ b/providers/rimuhosting/src/test/java/org/jclouds/rimuhosting/miro/compute/RimuHostingComputeServiceLiveTest.java @@ -18,8 +18,11 @@ */ package org.jclouds.rimuhosting.miro.compute; -import org.jclouds.compute.BaseComputeServiceLiveTest; +import org.jclouds.compute.ComputeServiceContext; import org.jclouds.compute.domain.NodeMetadata; +import org.jclouds.compute.internal.BaseComputeServiceLiveTest; +import org.jclouds.rimuhosting.miro.RimuHostingAsyncClient; +import org.jclouds.rimuhosting.miro.RimuHostingClient; import org.jclouds.ssh.jsch.config.JschSshClientModule; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; @@ -30,7 +33,10 @@ import com.google.common.collect.ImmutableMap; * @author Ivan Meredith */ @Test(groups = "live", sequential = true) -public class RimuHostingComputeServiceLiveTest extends BaseComputeServiceLiveTest { +public class RimuHostingComputeServiceLiveTest + extends + BaseComputeServiceLiveTest> { + public RimuHostingComputeServiceLiveTest() { provider = "rimuhosting"; } diff --git a/providers/rimuhosting/src/test/java/org/jclouds/rimuhosting/miro/compute/RimuHostingTemplateBuilderLiveTest.java b/providers/rimuhosting/src/test/java/org/jclouds/rimuhosting/miro/compute/RimuHostingTemplateBuilderLiveTest.java index a3041fad41..b67a5acc72 100644 --- a/providers/rimuhosting/src/test/java/org/jclouds/rimuhosting/miro/compute/RimuHostingTemplateBuilderLiveTest.java +++ b/providers/rimuhosting/src/test/java/org/jclouds/rimuhosting/miro/compute/RimuHostingTemplateBuilderLiveTest.java @@ -23,10 +23,13 @@ import static org.testng.Assert.assertEquals; import java.util.Set; -import org.jclouds.compute.BaseTemplateBuilderLiveTest; +import org.jclouds.compute.ComputeServiceContext; import org.jclouds.compute.domain.OsFamily; import org.jclouds.compute.domain.OsFamilyVersion64Bit; import org.jclouds.compute.domain.Template; +import org.jclouds.compute.internal.BaseTemplateBuilderLiveTest; +import org.jclouds.rimuhosting.miro.RimuHostingAsyncClient; +import org.jclouds.rimuhosting.miro.RimuHostingClient; import org.testng.annotations.Test; import com.google.common.base.Predicate; @@ -37,7 +40,9 @@ import com.google.common.collect.ImmutableSet; * @author Adrian Cole */ @Test(groups = "live") -public class RimuHostingTemplateBuilderLiveTest extends BaseTemplateBuilderLiveTest { +public class RimuHostingTemplateBuilderLiveTest + extends + BaseTemplateBuilderLiveTest> { public RimuHostingTemplateBuilderLiveTest() { provider = "rimuhosting"; diff --git a/providers/serverlove-z1-man/src/main/java/org/jclouds/serverlove/ServerloveManchesterContextBuilder.java b/providers/serverlove-z1-man/src/main/java/org/jclouds/serverlove/ServerloveManchesterContextBuilder.java deleted file mode 100644 index e2ae42d1b0..0000000000 --- a/providers/serverlove-z1-man/src/main/java/org/jclouds/serverlove/ServerloveManchesterContextBuilder.java +++ /dev/null @@ -1,44 +0,0 @@ -/** - * 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.serverlove; - -import java.util.List; -import java.util.Properties; - -import org.jclouds.elasticstack.ElasticStackContextBuilder; -import org.jclouds.serverlove.config.ServerloveManchesterComputeServiceContextModule; - -import com.google.inject.Module; - -/** - * - * @author Adrian Cole - */ -public class ServerloveManchesterContextBuilder extends ElasticStackContextBuilder { - - public ServerloveManchesterContextBuilder(Properties props) { - super(props); - } - - @Override - protected void addContextModule(List modules) { - modules.add(new ServerloveManchesterComputeServiceContextModule()); - } - -} diff --git a/providers/serverlove-z1-man/src/main/java/org/jclouds/serverlove/ServerloveManchesterPropertiesBuilder.java b/providers/serverlove-z1-man/src/main/java/org/jclouds/serverlove/ServerloveManchesterPropertiesBuilder.java deleted file mode 100644 index a708b496ab..0000000000 --- a/providers/serverlove-z1-man/src/main/java/org/jclouds/serverlove/ServerloveManchesterPropertiesBuilder.java +++ /dev/null @@ -1,48 +0,0 @@ -/** - * 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.serverlove; - -import static org.jclouds.Constants.PROPERTY_API_VERSION; -import static org.jclouds.Constants.PROPERTY_ENDPOINT; -import static org.jclouds.Constants.PROPERTY_ISO3166_CODES; - -import java.util.Properties; - -import org.jclouds.elasticstack.ElasticStackPropertiesBuilder; - -/** - * - * @author Adrian Cole - */ -public class ServerloveManchesterPropertiesBuilder extends ElasticStackPropertiesBuilder { - - @Override - protected Properties defaultProperties() { - Properties properties = super.defaultProperties(); - properties.setProperty(PROPERTY_ISO3166_CODES, "GB-MAN"); - properties.setProperty(PROPERTY_ENDPOINT, "https://api.z1-man.serverlove.com"); - properties.setProperty(PROPERTY_API_VERSION, "1.0"); - return properties; - } - - public ServerloveManchesterPropertiesBuilder(Properties properties) { - super(properties); - } - -} diff --git a/providers/serverlove-z1-man/src/main/java/org/jclouds/serverlove/ServerloveManchesterProviderMetadata.java b/providers/serverlove-z1-man/src/main/java/org/jclouds/serverlove/ServerloveManchesterProviderMetadata.java index d1b2230206..f360e54b53 100644 --- a/providers/serverlove-z1-man/src/main/java/org/jclouds/serverlove/ServerloveManchesterProviderMetadata.java +++ b/providers/serverlove-z1-man/src/main/java/org/jclouds/serverlove/ServerloveManchesterProviderMetadata.java @@ -19,47 +19,72 @@ package org.jclouds.serverlove; import java.net.URI; +import java.util.Properties; +import org.jclouds.compute.ComputeServiceContext; import org.jclouds.elasticstack.ElasticStackApiMetadata; -import org.jclouds.providers.BaseProviderMetadata; +import org.jclouds.elasticstack.ElasticStackAsyncClient; +import org.jclouds.elasticstack.ElasticStackClient; +import org.jclouds.providers.ProviderMetadata; +import org.jclouds.providers.internal.BaseProviderMetadata; /** * Implementation of {@link org.jclouds.types.ProviderMetadata} for Serverlove Manchester. - * + * * @author Adrian Cole */ -public class ServerloveManchesterProviderMetadata extends BaseProviderMetadata { +public class ServerloveManchesterProviderMetadata + extends + BaseProviderMetadata, ElasticStackApiMetadata> { - public ServerloveManchesterProviderMetadata() { - this(builder() - .id("serverlove-z1-man") - .name("Serverlove Manchester") - .api(new ElasticStackApiMetadata()) - .homepage(URI.create("http://www.serverlove.com")) - .console(URI.create("http://www.serverlove.com/accounts")) - .iso3166Codes("GB-MAN")); + public static Builder builder() { + return new Builder(); } - // below are so that we can reuse builders, toString, hashCode, etc. - // we have to set concrete classes here, as our base class cannot be - // concrete due to serviceLoader - protected ServerloveManchesterProviderMetadata(ConcreteBuilder builder) { + @Override + public Builder toBuilder() { + return builder().fromProviderMetadata(this); + } + + public ServerloveManchesterProviderMetadata() { + super(builder()); + } + + public ServerloveManchesterProviderMetadata(Builder builder) { super(builder); } - private static class ConcreteBuilder extends Builder { + protected static Properties defaultProperties() { + Properties properties = new Properties(); + return properties; + } + + public static class Builder + extends + BaseProviderMetadata.Builder, ElasticStackApiMetadata> { + + protected Builder() { + id("serverlove-z1-man") + .name("Serverlove Manchester") + .apiMetadata(new ElasticStackApiMetadata()) + .homepage(URI.create("http://www.serverlove.com")) + .console(URI.create("http://www.serverlove.com/accounts")) + .iso3166Codes("GB-MAN") + .endpoint("https://api.z1-man.serverlove.com") + .defaultProperties(ServerloveManchesterProviderMetadata.defaultProperties()); + } @Override public ServerloveManchesterProviderMetadata build() { return new ServerloveManchesterProviderMetadata(this); } - } - public static ConcreteBuilder builder() { - return new ConcreteBuilder(); - } + @Override + public Builder fromProviderMetadata( + ProviderMetadata, ElasticStackApiMetadata> in) { + super.fromProviderMetadata(in); + return this; + } - public ConcreteBuilder toBuilder() { - return builder().fromProviderMetadata(this); } -} +} \ No newline at end of file diff --git a/providers/serverlove-z1-man/src/main/java/org/jclouds/serverlove/config/ServerloveManchesterComputeServiceContextModule.java b/providers/serverlove-z1-man/src/main/java/org/jclouds/serverlove/config/ServerloveManchesterComputeServiceContextModule.java deleted file mode 100644 index d84c5921df..0000000000 --- a/providers/serverlove-z1-man/src/main/java/org/jclouds/serverlove/config/ServerloveManchesterComputeServiceContextModule.java +++ /dev/null @@ -1,29 +0,0 @@ -/** - * 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.serverlove.config; - -import org.jclouds.elasticstack.compute.config.ElasticStackComputeServiceContextModule; - -/** - * - * @author Adrian Cole - */ -public class ServerloveManchesterComputeServiceContextModule extends ElasticStackComputeServiceContextModule { - -} diff --git a/providers/serverlove-z1-man/src/test/java/org/jclouds/serverlove/ServerloveManchesterProviderTest.java b/providers/serverlove-z1-man/src/test/java/org/jclouds/serverlove/ServerloveManchesterProviderTest.java index 9ad8d824e2..4e757bfcdc 100644 --- a/providers/serverlove-z1-man/src/test/java/org/jclouds/serverlove/ServerloveManchesterProviderTest.java +++ b/providers/serverlove-z1-man/src/test/java/org/jclouds/serverlove/ServerloveManchesterProviderTest.java @@ -19,7 +19,7 @@ package org.jclouds.serverlove; import org.jclouds.elasticstack.ElasticStackApiMetadata; -import org.jclouds.providers.BaseProviderMetadataTest; +import org.jclouds.providers.internal.BaseProviderMetadataTest; import org.testng.annotations.Test; /** diff --git a/providers/serverlove-z1-man/src/test/java/org/jclouds/serverlove/compute/ServerloveManchesterTemplateBuilderLiveTest.java b/providers/serverlove-z1-man/src/test/java/org/jclouds/serverlove/compute/ServerloveManchesterTemplateBuilderLiveTest.java index bfcf037e9e..a2bc867767 100644 --- a/providers/serverlove-z1-man/src/test/java/org/jclouds/serverlove/compute/ServerloveManchesterTemplateBuilderLiveTest.java +++ b/providers/serverlove-z1-man/src/test/java/org/jclouds/serverlove/compute/ServerloveManchesterTemplateBuilderLiveTest.java @@ -23,10 +23,13 @@ import static org.testng.Assert.assertEquals; import java.util.Set; -import org.jclouds.compute.BaseTemplateBuilderLiveTest; +import org.jclouds.compute.ComputeServiceContext; import org.jclouds.compute.domain.OsFamily; import org.jclouds.compute.domain.OsFamilyVersion64Bit; import org.jclouds.compute.domain.Template; +import org.jclouds.compute.internal.BaseTemplateBuilderLiveTest; +import org.jclouds.elasticstack.ElasticStackAsyncClient; +import org.jclouds.elasticstack.ElasticStackClient; import org.testng.annotations.Test; import com.google.common.base.Predicate; @@ -38,7 +41,9 @@ import com.google.common.collect.ImmutableSet; * @author Adrian Cole */ @Test(groups = "live") -public class ServerloveManchesterTemplateBuilderLiveTest extends BaseTemplateBuilderLiveTest { +public class ServerloveManchesterTemplateBuilderLiveTest + extends + BaseTemplateBuilderLiveTest> { public ServerloveManchesterTemplateBuilderLiveTest() { provider = "serverlove-z1-man"; @@ -51,16 +56,16 @@ public class ServerloveManchesterTemplateBuilderLiveTest extends BaseTemplateBui @Override public boolean apply(OsFamilyVersion64Bit input) { switch (input.family) { - case UBUNTU: - return (input.version.equals("") || input.version.equals("10.04")) && input.is64Bit; - case DEBIAN: - return (input.version.equals("") || input.version.equals("6.0")) && input.is64Bit; - case CENTOS: - return (input.version.equals("") || input.version.equals("5.7")) && input.is64Bit; - case WINDOWS: - return (input.version.equals("") || input.version.equals("2008 R2")) && input.is64Bit; - default: - return false; + case UBUNTU: + return (input.version.equals("") || input.version.equals("10.04")) && input.is64Bit; + case DEBIAN: + return (input.version.equals("") || input.version.equals("6.0")) && input.is64Bit; + case CENTOS: + return (input.version.equals("") || input.version.equals("5.7")) && input.is64Bit; + case WINDOWS: + return (input.version.equals("") || input.version.equals("2008 R2")) && input.is64Bit; + default: + return false; } } diff --git a/providers/skalicloud-sdg-my/src/main/java/org/jclouds/skalicloud/SkaliCloudMalaysiaContextBuilder.java b/providers/skalicloud-sdg-my/src/main/java/org/jclouds/skalicloud/SkaliCloudMalaysiaContextBuilder.java deleted file mode 100644 index d3bdb84431..0000000000 --- a/providers/skalicloud-sdg-my/src/main/java/org/jclouds/skalicloud/SkaliCloudMalaysiaContextBuilder.java +++ /dev/null @@ -1,44 +0,0 @@ -/** - * 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.skalicloud; - -import java.util.List; -import java.util.Properties; - -import org.jclouds.elasticstack.ElasticStackContextBuilder; -import org.jclouds.skalicloud.config.SkaliCloudMalaysiaComputeServiceContextModule; - -import com.google.inject.Module; - -/** - * - * @author Adrian Cole - */ -public class SkaliCloudMalaysiaContextBuilder extends ElasticStackContextBuilder { - - public SkaliCloudMalaysiaContextBuilder(Properties props) { - super(props); - } - - @Override - protected void addContextModule(List modules) { - modules.add(new SkaliCloudMalaysiaComputeServiceContextModule()); - } - -} diff --git a/providers/skalicloud-sdg-my/src/main/java/org/jclouds/skalicloud/SkaliCloudMalaysiaPropertiesBuilder.java b/providers/skalicloud-sdg-my/src/main/java/org/jclouds/skalicloud/SkaliCloudMalaysiaPropertiesBuilder.java deleted file mode 100644 index c8fcad1ff0..0000000000 --- a/providers/skalicloud-sdg-my/src/main/java/org/jclouds/skalicloud/SkaliCloudMalaysiaPropertiesBuilder.java +++ /dev/null @@ -1,48 +0,0 @@ -/** - * 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.skalicloud; - -import static org.jclouds.Constants.PROPERTY_API_VERSION; -import static org.jclouds.Constants.PROPERTY_ENDPOINT; -import static org.jclouds.Constants.PROPERTY_ISO3166_CODES; - -import java.util.Properties; - -import org.jclouds.elasticstack.ElasticStackPropertiesBuilder; - -/** - * - * @author Adrian Cole - */ -public class SkaliCloudMalaysiaPropertiesBuilder extends ElasticStackPropertiesBuilder { - - @Override - protected Properties defaultProperties() { - Properties properties = super.defaultProperties(); - properties.setProperty(PROPERTY_ISO3166_CODES, "MY-10"); - properties.setProperty(PROPERTY_ENDPOINT, "https://api.sdg-my.skalicloud.com"); - properties.setProperty(PROPERTY_API_VERSION, "1.0"); - return properties; - } - - public SkaliCloudMalaysiaPropertiesBuilder(Properties properties) { - super(properties); - } - -} diff --git a/providers/skalicloud-sdg-my/src/main/java/org/jclouds/skalicloud/SkaliCloudMalaysiaProviderMetadata.java b/providers/skalicloud-sdg-my/src/main/java/org/jclouds/skalicloud/SkaliCloudMalaysiaProviderMetadata.java index d6a80aaee3..ba9e4c69c3 100644 --- a/providers/skalicloud-sdg-my/src/main/java/org/jclouds/skalicloud/SkaliCloudMalaysiaProviderMetadata.java +++ b/providers/skalicloud-sdg-my/src/main/java/org/jclouds/skalicloud/SkaliCloudMalaysiaProviderMetadata.java @@ -19,48 +19,72 @@ package org.jclouds.skalicloud; import java.net.URI; +import java.util.Properties; +import org.jclouds.compute.ComputeServiceContext; import org.jclouds.elasticstack.ElasticStackApiMetadata; -import org.jclouds.providers.BaseProviderMetadata; +import org.jclouds.elasticstack.ElasticStackAsyncClient; +import org.jclouds.elasticstack.ElasticStackClient; +import org.jclouds.providers.ProviderMetadata; +import org.jclouds.providers.internal.BaseProviderMetadata; /** * Implementation of {@link org.jclouds.types.ProviderMetadata} for SkaliCloud Malaysia. - * + * * @author Adrian Cole */ -public class SkaliCloudMalaysiaProviderMetadata extends BaseProviderMetadata { +public class SkaliCloudMalaysiaProviderMetadata + extends + BaseProviderMetadata, ElasticStackApiMetadata> { - public SkaliCloudMalaysiaProviderMetadata() { - this(builder() - .id("skalicloud-sdg-my") - .name("SkaliCloud Malaysia") - .api(new ElasticStackApiMetadata()) - .homepage(URI.create("http://sdg-my.skalicloud.com")) - .console(URI.create("http://sdg-my.skalicloud.com/accounts")) - .iso3166Codes("MY-10")); + public static Builder builder() { + return new Builder(); } - // below are so that we can reuse builders, toString, hashCode, etc. - // we have to set concrete classes here, as our base class cannot be - // concrete due to serviceLoader - protected SkaliCloudMalaysiaProviderMetadata(ConcreteBuilder builder) { + @Override + public Builder toBuilder() { + return builder().fromProviderMetadata(this); + } + + public SkaliCloudMalaysiaProviderMetadata() { + super(builder()); + } + + public SkaliCloudMalaysiaProviderMetadata(Builder builder) { super(builder); } - private static class ConcreteBuilder extends Builder { + protected static Properties defaultProperties() { + Properties properties = new Properties(); + return properties; + } + + public static class Builder + extends + BaseProviderMetadata.Builder, ElasticStackApiMetadata> { + + protected Builder() { + id("skalicloud-sdg-my") + .name("SkaliCloud Malaysia") + .apiMetadata(new ElasticStackApiMetadata()) + .homepage(URI.create("https://sdg-my.skalicloud.com")) + .console(URI.create("https://api.sdg-my.skalicloud.com/accounts")) + .iso3166Codes("MY-10") + .endpoint("https://api.sdg-my.skalicloud.com") + .defaultProperties(SkaliCloudMalaysiaProviderMetadata.defaultProperties()); + } @Override public SkaliCloudMalaysiaProviderMetadata build() { return new SkaliCloudMalaysiaProviderMetadata(this); } - } - public static ConcreteBuilder builder() { - return new ConcreteBuilder(); - } + @Override + public Builder fromProviderMetadata( + ProviderMetadata, ElasticStackApiMetadata> in) { + super.fromProviderMetadata(in); + return this; + } - public ConcreteBuilder toBuilder() { - return builder().fromProviderMetadata(this); } - -} +} \ No newline at end of file diff --git a/providers/skalicloud-sdg-my/src/main/java/org/jclouds/skalicloud/config/SkaliCloudMalaysiaComputeServiceContextModule.java b/providers/skalicloud-sdg-my/src/main/java/org/jclouds/skalicloud/config/SkaliCloudMalaysiaComputeServiceContextModule.java deleted file mode 100644 index 0e3219d94b..0000000000 --- a/providers/skalicloud-sdg-my/src/main/java/org/jclouds/skalicloud/config/SkaliCloudMalaysiaComputeServiceContextModule.java +++ /dev/null @@ -1,29 +0,0 @@ -/** - * 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.skalicloud.config; - -import org.jclouds.elasticstack.compute.config.ElasticStackComputeServiceContextModule; - -/** - * - * @author Adrian Cole - */ -public class SkaliCloudMalaysiaComputeServiceContextModule extends ElasticStackComputeServiceContextModule { - -} \ No newline at end of file diff --git a/providers/skalicloud-sdg-my/src/test/java/org/jclouds/skalicloud/SkaliCloudMalaysiaProviderTest.java b/providers/skalicloud-sdg-my/src/test/java/org/jclouds/skalicloud/SkaliCloudMalaysiaProviderTest.java index a45034b500..6ce1d3640b 100644 --- a/providers/skalicloud-sdg-my/src/test/java/org/jclouds/skalicloud/SkaliCloudMalaysiaProviderTest.java +++ b/providers/skalicloud-sdg-my/src/test/java/org/jclouds/skalicloud/SkaliCloudMalaysiaProviderTest.java @@ -19,7 +19,7 @@ package org.jclouds.skalicloud; import org.jclouds.elasticstack.ElasticStackApiMetadata; -import org.jclouds.providers.BaseProviderMetadataTest; +import org.jclouds.providers.internal.BaseProviderMetadataTest; import org.testng.annotations.Test; /** diff --git a/providers/skalicloud-sdg-my/src/test/java/org/jclouds/skalicloud/compute/SkaliCloudMalaysiaTemplateBuilderLiveTest.java b/providers/skalicloud-sdg-my/src/test/java/org/jclouds/skalicloud/compute/SkaliCloudMalaysiaTemplateBuilderLiveTest.java index 72b92aa344..a35ea5fe04 100644 --- a/providers/skalicloud-sdg-my/src/test/java/org/jclouds/skalicloud/compute/SkaliCloudMalaysiaTemplateBuilderLiveTest.java +++ b/providers/skalicloud-sdg-my/src/test/java/org/jclouds/skalicloud/compute/SkaliCloudMalaysiaTemplateBuilderLiveTest.java @@ -24,10 +24,13 @@ import static org.testng.Assert.assertEquals; import java.io.IOException; import java.util.Set; -import org.jclouds.compute.BaseTemplateBuilderLiveTest; +import org.jclouds.compute.ComputeServiceContext; import org.jclouds.compute.domain.OsFamily; import org.jclouds.compute.domain.OsFamilyVersion64Bit; import org.jclouds.compute.domain.Template; +import org.jclouds.compute.internal.BaseTemplateBuilderLiveTest; +import org.jclouds.elasticstack.ElasticStackAsyncClient; +import org.jclouds.elasticstack.ElasticStackClient; import org.testng.annotations.Test; import com.google.common.base.Predicate; @@ -39,7 +42,9 @@ import com.google.common.collect.ImmutableSet; * @author Adrian Cole */ @Test(groups = "live") -public class SkaliCloudMalaysiaTemplateBuilderLiveTest extends BaseTemplateBuilderLiveTest { +public class SkaliCloudMalaysiaTemplateBuilderLiveTest + extends + BaseTemplateBuilderLiveTest> { public SkaliCloudMalaysiaTemplateBuilderLiveTest() { provider = "skalicloud-sdg-my"; diff --git a/providers/slicehost/src/main/java/org/jclouds/slicehost/SlicehostApiMetadata.java b/providers/slicehost/src/main/java/org/jclouds/slicehost/SlicehostApiMetadata.java index 7193e51134..8d9edb2b04 100644 --- a/providers/slicehost/src/main/java/org/jclouds/slicehost/SlicehostApiMetadata.java +++ b/providers/slicehost/src/main/java/org/jclouds/slicehost/SlicehostApiMetadata.java @@ -19,49 +19,71 @@ package org.jclouds.slicehost; import java.net.URI; +import java.util.Properties; import org.jclouds.apis.ApiMetadata; import org.jclouds.apis.ApiType; -import org.jclouds.apis.BaseApiMetadata; +import org.jclouds.compute.ComputeServiceContext; +import org.jclouds.compute.internal.BaseComputeServiceApiMetadata; + +import com.google.common.reflect.TypeToken; /** - * Implementation of {@link ApiMetadata} for Slicehost API + * Implementation of {@link ApiMetadata} for Slicehost 1.0 API * * @author Adrian Cole */ -public class SlicehostApiMetadata extends BaseApiMetadata { +public class SlicehostApiMetadata + extends + BaseComputeServiceApiMetadata, SlicehostApiMetadata> { - public SlicehostApiMetadata() { - this(builder() - .id("slicehost") - .type(ApiType.COMPUTE) - .name("Slicehost API") - .identityName("API password") - .documentation(URI.create("http://articles.slicehost.com/api"))); + @Override + public Builder toBuilder() { + return new Builder().fromApiMetadata(this); } - // below are so that we can reuse builders, toString, hashCode, etc. - // we have to set concrete classes here, as our base class cannot be - // concrete due to serviceLoader - protected SlicehostApiMetadata(Builder builder) { + public SlicehostApiMetadata() { + this(new Builder()); + } + + protected SlicehostApiMetadata(Builder builder) { super(builder); } - private static class ConcreteBuilder extends Builder { + protected static Properties defaultProperties() { + Properties properties = BaseComputeServiceApiMetadata.Builder.defaultProperties(); + properties.setProperty("jclouds.ssh.max-retries", "8"); + return properties; + } + + public static class Builder + extends + BaseComputeServiceApiMetadata.Builder, SlicehostApiMetadata> { + + protected Builder() { + id("slicehost") + .type(ApiType.COMPUTE) + .name("Slicehost API") + .identityName("API password") + .documentation(URI.create("http://articles.slicehost.com/api")) + .version("https://api.slicehost.com") + .defaultEndpoint("https://api.slicehost.com") + .javaApi(SlicehostClient.class, SlicehostAsyncClient.class) + .defaultProperties(SlicehostApiMetadata.defaultProperties()) + .contextBuilder(TypeToken.of(SlicehostContextBuilder.class)); + } @Override public SlicehostApiMetadata build() { return new SlicehostApiMetadata(this); } - } - public static ConcreteBuilder builder() { - return new ConcreteBuilder(); - } + @Override + public Builder fromApiMetadata(SlicehostApiMetadata in) { + super.fromApiMetadata(in); + return this; + } - @Override - public ConcreteBuilder toBuilder() { - return builder().fromApiMetadata(this); } } \ No newline at end of file diff --git a/providers/slicehost/src/main/java/org/jclouds/slicehost/SlicehostContextBuilder.java b/providers/slicehost/src/main/java/org/jclouds/slicehost/SlicehostContextBuilder.java index fcd4edecd2..57cdaf2a38 100644 --- a/providers/slicehost/src/main/java/org/jclouds/slicehost/SlicehostContextBuilder.java +++ b/providers/slicehost/src/main/java/org/jclouds/slicehost/SlicehostContextBuilder.java @@ -19,35 +19,30 @@ package org.jclouds.slicehost; import java.util.List; -import java.util.Properties; +import org.jclouds.compute.ComputeServiceContext; import org.jclouds.compute.ComputeServiceContextBuilder; -import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule; -import org.jclouds.logging.jdk.config.JDKLoggingModule; +import org.jclouds.providers.ProviderMetadata; import org.jclouds.slicehost.compute.config.SlicehostComputeServiceContextModule; import org.jclouds.slicehost.config.SlicehostRestClientModule; -import com.google.inject.Injector; import com.google.inject.Module; /** - * Creates {@link SlicehostComputeServiceContext} or {@link Injector} instances based on the most - * commonly requested arguments. - *

- * Note that Threadsafe objects will be bound as singletons to the Injector or Context provided. - *

- *

- * If no Modules are specified, the default {@link JDKLoggingModule logging} and - * {@link JavaUrlHttpCommandExecutorServiceModule http transports} will be installed. * * @author Adrian Cole - * @see SlicehostComputeServiceContext */ -public class SlicehostContextBuilder extends - ComputeServiceContextBuilder { +public class SlicehostContextBuilder + extends + ComputeServiceContextBuilder, SlicehostApiMetadata> { - public SlicehostContextBuilder(Properties props) { - super(SlicehostClient.class, SlicehostAsyncClient.class, props); + public SlicehostContextBuilder( + ProviderMetadata, SlicehostApiMetadata> providerMetadata) { + super(providerMetadata); + } + + public SlicehostContextBuilder(SlicehostApiMetadata apiMetadata) { + super(apiMetadata); } @Override @@ -55,9 +50,8 @@ public class SlicehostContextBuilder extends modules.add(new SlicehostComputeServiceContextModule()); } - @Override protected void addClientModule(List modules) { modules.add(new SlicehostRestClientModule()); } -} +} \ No newline at end of file diff --git a/providers/slicehost/src/main/java/org/jclouds/slicehost/SlicehostPropertiesBuilder.java b/providers/slicehost/src/main/java/org/jclouds/slicehost/SlicehostPropertiesBuilder.java deleted file mode 100644 index 9c5fa000aa..0000000000 --- a/providers/slicehost/src/main/java/org/jclouds/slicehost/SlicehostPropertiesBuilder.java +++ /dev/null @@ -1,49 +0,0 @@ -/** - * 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.slicehost; - -import static org.jclouds.Constants.PROPERTY_API_VERSION; -import static org.jclouds.Constants.PROPERTY_ENDPOINT; -import static org.jclouds.Constants.PROPERTY_ISO3166_CODES; - -import java.util.Properties; - -import org.jclouds.PropertiesBuilder; - -/** - * Builds properties used in Slicehost Connections - * - * @author Adrian Cole - */ -public class SlicehostPropertiesBuilder extends PropertiesBuilder { - @Override - protected Properties defaultProperties() { - Properties properties = super.defaultProperties(); - properties.setProperty(PROPERTY_ISO3166_CODES, "US-IL,US-TX,US-MO"); - properties.setProperty(PROPERTY_ENDPOINT, "https://api.slicehost.com"); - properties.setProperty(PROPERTY_API_VERSION, "1.4.1.1"); - properties.setProperty("jclouds.ssh.max-retries", "8"); - return properties; - } - - public SlicehostPropertiesBuilder(Properties properties) { - super(properties); - } - -} diff --git a/providers/slicehost/src/main/java/org/jclouds/slicehost/SlicehostProviderMetadata.java b/providers/slicehost/src/main/java/org/jclouds/slicehost/SlicehostProviderMetadata.java index e315e8af3f..b0aba661e7 100644 --- a/providers/slicehost/src/main/java/org/jclouds/slicehost/SlicehostProviderMetadata.java +++ b/providers/slicehost/src/main/java/org/jclouds/slicehost/SlicehostProviderMetadata.java @@ -1,63 +1,62 @@ -/** - * 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.slicehost; import java.net.URI; +import java.util.Properties; -import org.jclouds.providers.BaseProviderMetadata; +import org.jclouds.compute.ComputeServiceContext; +import org.jclouds.providers.ProviderMetadata; +import org.jclouds.providers.internal.BaseProviderMetadata; /** * Implementation of {@link org.jclouds.types.ProviderMetadata} for Slicehost * * @author Adrian Cole */ -public class SlicehostProviderMetadata extends BaseProviderMetadata { - public SlicehostProviderMetadata() { - this(builder() - .id("slicehost") - .name("Slicehost") - .api(new SlicehostApiMetadata()) - .homepage(URI.create("http://www.slicehost.com")) - .console(URI.create("https://manage.slicehost.com/")) - .iso3166Codes("US-IL", "US-TX", "US-MO")); +public class SlicehostProviderMetadata extends BaseProviderMetadata, SlicehostApiMetadata> { + + public static Builder builder() { + return new Builder(); } - // below are so that we can reuse builders, toString, hashCode, etc. - // we have to set concrete classes here, as our base class cannot be - // concrete due to serviceLoader - protected SlicehostProviderMetadata(ConcreteBuilder builder) { + @Override + public Builder toBuilder() { + return builder().fromProviderMetadata(this); + } + + public SlicehostProviderMetadata() { + super(builder()); + } + + public SlicehostProviderMetadata(Builder builder) { super(builder); } - private static class ConcreteBuilder extends Builder { + protected static Properties defaultProperties() { + Properties properties = new Properties(); + return properties; + } + + public static class Builder extends BaseProviderMetadata.Builder, SlicehostApiMetadata> { + + protected Builder(){ + id("slicehost") + .name("Slicehost") + .apiMetadata(new SlicehostApiMetadata()) + .homepage(URI.create("http://www.slicehost.com")) + .console(URI.create("https://manage.slicehost.com/")) + .iso3166Codes("US-IL", "US-TX", "US-MO"); + } @Override public SlicehostProviderMetadata build() { return new SlicehostProviderMetadata(this); } - } - - public static ConcreteBuilder builder() { - return new ConcreteBuilder(); - } - - public ConcreteBuilder toBuilder() { - return builder().fromProviderMetadata(this); + + @Override + public Builder fromProviderMetadata( + ProviderMetadata, SlicehostApiMetadata> in) { + super.fromProviderMetadata(in); + return this; + } } } \ No newline at end of file diff --git a/providers/slicehost/src/test/java/org/jclouds/slicehost/SlicehostAsyncClientTest.java b/providers/slicehost/src/test/java/org/jclouds/slicehost/SlicehostAsyncClientTest.java index f1ef8c2e55..692b324ca5 100644 --- a/providers/slicehost/src/test/java/org/jclouds/slicehost/SlicehostAsyncClientTest.java +++ b/providers/slicehost/src/test/java/org/jclouds/slicehost/SlicehostAsyncClientTest.java @@ -22,17 +22,15 @@ import static org.testng.Assert.assertEquals; import java.io.IOException; import java.lang.reflect.Method; -import java.util.Properties; import org.jclouds.http.HttpRequest; import org.jclouds.http.functions.ParseSax; import org.jclouds.http.functions.ReleasePayloadAndReturn; -import org.jclouds.rest.RestClientTest; -import org.jclouds.rest.RestContextFactory; -import org.jclouds.rest.RestContextSpec; +import org.jclouds.providers.ProviderMetadata; import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404; import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404; +import org.jclouds.rest.internal.BaseAsyncClientTest; import org.jclouds.rest.internal.RestAnnotationProcessor; import org.jclouds.slicehost.filters.SlicehostBasic; import org.jclouds.slicehost.xml.FlavorHandler; @@ -52,7 +50,7 @@ import com.google.inject.TypeLiteral; */ // NOTE:without testName, this will not call @Before* and fail w/NPE during surefire @Test(groups = "unit", testName = "SlicehostAsyncClientTest") -public class SlicehostAsyncClientTest extends RestClientTest { +public class SlicehostAsyncClientTest extends BaseAsyncClientTest { public void testCreateSlice() throws IOException, SecurityException, NoSuchMethodException { Method method = SlicehostAsyncClient.class.getMethod("createSlice", String.class, int.class, int.class); @@ -253,8 +251,8 @@ public class SlicehostAsyncClientTest extends RestClientTest createContextSpec() { - return new RestContextFactory().createContextSpec("slicehost", "apikey", null, new Properties()); + public ProviderMetadata createProviderMetadata() { + return new SlicehostProviderMetadata(); } } diff --git a/providers/slicehost/src/test/java/org/jclouds/slicehost/SlicehostClientLiveTest.java b/providers/slicehost/src/test/java/org/jclouds/slicehost/SlicehostClientLiveTest.java index b15f7fb7a8..6d0b9e3480 100644 --- a/providers/slicehost/src/test/java/org/jclouds/slicehost/SlicehostClientLiveTest.java +++ b/providers/slicehost/src/test/java/org/jclouds/slicehost/SlicehostClientLiveTest.java @@ -25,34 +25,29 @@ import static org.testng.Assert.assertTrue; import java.io.IOException; import java.lang.reflect.UndeclaredThrowableException; import java.security.SecureRandom; -import java.util.Properties; import java.util.Set; import java.util.concurrent.TimeUnit; -import org.jclouds.compute.BaseVersionedServiceLiveTest; +import org.jclouds.compute.ComputeServiceContext; +import org.jclouds.compute.internal.BaseComputeServiceContextLiveTest; import org.jclouds.domain.LoginCredentials; import org.jclouds.http.HttpResponseException; import org.jclouds.io.Payloads; -import org.jclouds.logging.log4j.config.Log4JLoggingModule; import org.jclouds.net.IPSocket; import org.jclouds.predicates.RetryablePredicate; import org.jclouds.predicates.SocketOpen; -import org.jclouds.rest.RestContextFactory; import org.jclouds.slicehost.domain.Flavor; import org.jclouds.slicehost.domain.Image; import org.jclouds.slicehost.domain.Slice; import org.jclouds.ssh.SshClient; import org.jclouds.ssh.SshException; -import org.jclouds.sshj.config.SshjSshClientModule; import org.testng.annotations.AfterTest; import org.testng.annotations.BeforeGroups; import org.testng.annotations.Test; import com.google.common.base.Predicate; -import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; import com.google.inject.Injector; -import com.google.inject.Module; /** * Tests behavior of {@code SlicehostClient} @@ -60,7 +55,10 @@ import com.google.inject.Module; * @author Adrian Cole */ @Test(groups = "live", singleThreaded = true, testName = "SlicehostClientLiveTest") -public class SlicehostClientLiveTest extends BaseVersionedServiceLiveTest { +public class SlicehostClientLiveTest + extends + BaseComputeServiceContextLiveTest> { + public SlicehostClientLiveTest() { provider = "slicehost"; } @@ -69,14 +67,12 @@ public class SlicehostClientLiveTest extends BaseVersionedServiceLiveTest { protected SshClient.Factory sshFactory; private Predicate socketTester; - @BeforeGroups(groups = { "live" }) - public void setupClient() { - setupCredentials(); - Properties overrides = setupProperties(); - - Injector injector = new RestContextFactory().createContextBuilder(provider, - ImmutableSet. of(new Log4JLoggingModule(), new SshjSshClientModule()), overrides).buildInjector(); - + @BeforeGroups(groups = { "integration", "live" }) + @Override + public void setupContext() { + super.setupContext(); + Injector injector = context.utils().injector(); + client = injector.getInstance(SlicehostClient.class); sshFactory = injector.getInstance(SshClient.Factory.class); SocketOpen socketOpen = injector.getInstance(SocketOpen.class); diff --git a/providers/slicehost/src/test/java/org/jclouds/slicehost/SlicehostProviderTest.java b/providers/slicehost/src/test/java/org/jclouds/slicehost/SlicehostProviderTest.java index 44fe33bed2..a03a98dd6e 100644 --- a/providers/slicehost/src/test/java/org/jclouds/slicehost/SlicehostProviderTest.java +++ b/providers/slicehost/src/test/java/org/jclouds/slicehost/SlicehostProviderTest.java @@ -18,7 +18,7 @@ */ package org.jclouds.slicehost; -import org.jclouds.providers.BaseProviderMetadataTest; +import org.jclouds.providers.internal.BaseProviderMetadataTest; import org.testng.annotations.Test; /** diff --git a/providers/slicehost/src/test/java/org/jclouds/slicehost/compute/SlicehostComputeServiceLiveTest.java b/providers/slicehost/src/test/java/org/jclouds/slicehost/compute/SlicehostComputeServiceLiveTest.java index e834a42e1f..79c960841c 100644 --- a/providers/slicehost/src/test/java/org/jclouds/slicehost/compute/SlicehostComputeServiceLiveTest.java +++ b/providers/slicehost/src/test/java/org/jclouds/slicehost/compute/SlicehostComputeServiceLiveTest.java @@ -18,8 +18,11 @@ */ package org.jclouds.slicehost.compute; -import org.jclouds.compute.BaseComputeServiceLiveTest; +import org.jclouds.compute.ComputeServiceContext; import org.jclouds.compute.domain.NodeMetadata; +import org.jclouds.compute.internal.BaseComputeServiceLiveTest; +import org.jclouds.slicehost.SlicehostAsyncClient; +import org.jclouds.slicehost.SlicehostClient; import org.jclouds.sshj.config.SshjSshClientModule; import org.testng.annotations.Test; @@ -32,7 +35,10 @@ import com.google.common.collect.ImmutableMap; * @author Adrian Cole */ @Test(groups = "live", enabled = true, singleThreaded = true) -public class SlicehostComputeServiceLiveTest extends BaseComputeServiceLiveTest { +public class SlicehostComputeServiceLiveTest + extends + BaseComputeServiceLiveTest> { + public SlicehostComputeServiceLiveTest() { provider = "slicehost"; } diff --git a/providers/slicehost/src/test/java/org/jclouds/slicehost/compute/SlicehostTemplateBuilderLiveTest.java b/providers/slicehost/src/test/java/org/jclouds/slicehost/compute/SlicehostTemplateBuilderLiveTest.java index 4b6c1d5dc1..ff8b08c660 100644 --- a/providers/slicehost/src/test/java/org/jclouds/slicehost/compute/SlicehostTemplateBuilderLiveTest.java +++ b/providers/slicehost/src/test/java/org/jclouds/slicehost/compute/SlicehostTemplateBuilderLiveTest.java @@ -24,10 +24,13 @@ import static org.testng.Assert.assertEquals; import java.io.IOException; import java.util.Set; -import org.jclouds.compute.BaseTemplateBuilderLiveTest; +import org.jclouds.compute.ComputeServiceContext; import org.jclouds.compute.domain.OsFamily; import org.jclouds.compute.domain.OsFamilyVersion64Bit; import org.jclouds.compute.domain.Template; +import org.jclouds.compute.internal.BaseTemplateBuilderLiveTest; +import org.jclouds.slicehost.SlicehostAsyncClient; +import org.jclouds.slicehost.SlicehostClient; import org.testng.annotations.Test; import com.google.common.base.Predicate; @@ -39,7 +42,9 @@ import com.google.common.collect.ImmutableSet; * @author Adrian Cole */ @Test(groups = "live") -public class SlicehostTemplateBuilderLiveTest extends BaseTemplateBuilderLiveTest { +public class SlicehostTemplateBuilderLiveTest + extends + BaseTemplateBuilderLiveTest> { public SlicehostTemplateBuilderLiveTest() { provider = "slicehost"; diff --git a/providers/softlayer/src/main/java/org/jclouds/softlayer/SoftLayerApiMetadata.java b/providers/softlayer/src/main/java/org/jclouds/softlayer/SoftLayerApiMetadata.java index 9650629c0e..e9347a4861 100644 --- a/providers/softlayer/src/main/java/org/jclouds/softlayer/SoftLayerApiMetadata.java +++ b/providers/softlayer/src/main/java/org/jclouds/softlayer/SoftLayerApiMetadata.java @@ -19,50 +19,73 @@ package org.jclouds.softlayer; import java.net.URI; +import java.util.Properties; import org.jclouds.apis.ApiMetadata; import org.jclouds.apis.ApiType; -import org.jclouds.apis.BaseApiMetadata; +import org.jclouds.compute.ComputeServiceContext; +import org.jclouds.compute.internal.BaseComputeServiceApiMetadata; + +import com.google.common.reflect.TypeToken; /** - * Implementation of {@link ApiMetadata} for SoftLayer API + * Implementation of {@link ApiMetadata} for API * * @author Adrian Cole */ -public class SoftLayerApiMetadata extends BaseApiMetadata { +public class SoftLayerApiMetadata + extends + BaseComputeServiceApiMetadata, SoftLayerApiMetadata> { - public SoftLayerApiMetadata() { - this(builder() - .id("softlayer") - .type(ApiType.COMPUTE) - .name("SoftLayer API") - .identityName("API Username") - .credentialName("API Key") - .documentation(URI.create("http://sldn.softlayer.com/article/REST"))); + @Override + public Builder toBuilder() { + return new Builder().fromApiMetadata(this); } - // below are so that we can reuse builders, toString, hashCode, etc. - // we have to set concrete classes here, as our base class cannot be - // concrete due to serviceLoader - protected SoftLayerApiMetadata(Builder builder) { + public SoftLayerApiMetadata() { + this(new Builder()); + } + + protected SoftLayerApiMetadata(Builder builder) { super(builder); } - private static class ConcreteBuilder extends Builder { + protected static Properties defaultProperties() { + Properties properties = BaseComputeServiceApiMetadata.Builder.defaultProperties(); + properties.setProperty("jclouds.ssh.max-retries", "5"); + properties.setProperty("jclouds.ssh.retry-auth", "true"); + return properties; + } + + public static class Builder + extends + BaseComputeServiceApiMetadata.Builder, SoftLayerApiMetadata> { + + protected Builder() { + id("softlayer") + .type(ApiType.COMPUTE) + .name("SoftLayer API") + .identityName("API Username") + .credentialName("API Key") + .documentation(URI.create("http://sldn.softlayer.com/article/REST")) + .version("3") + .defaultEndpoint("https://api.softlayer.com/rest") + .defaultProperties(SoftLayerApiMetadata.defaultProperties()) + .javaApi(SoftLayerClient.class, SoftLayerAsyncClient.class) + .contextBuilder(TypeToken.of(SoftLayerContextBuilder.class)); + } @Override public SoftLayerApiMetadata build() { return new SoftLayerApiMetadata(this); } + + @Override + public Builder fromApiMetadata(SoftLayerApiMetadata in) { + super.fromApiMetadata(in); + return this; + } + } - public static ConcreteBuilder builder() { - return new ConcreteBuilder(); - } - - @Override - public ConcreteBuilder toBuilder() { - return builder().fromApiMetadata(this); - } - -} \ No newline at end of file +} diff --git a/providers/softlayer/src/main/java/org/jclouds/softlayer/SoftLayerContextBuilder.java b/providers/softlayer/src/main/java/org/jclouds/softlayer/SoftLayerContextBuilder.java index f2b2aaa19f..86519a9cfc 100644 --- a/providers/softlayer/src/main/java/org/jclouds/softlayer/SoftLayerContextBuilder.java +++ b/providers/softlayer/src/main/java/org/jclouds/softlayer/SoftLayerContextBuilder.java @@ -19,9 +19,10 @@ package org.jclouds.softlayer; import java.util.List; -import java.util.Properties; +import org.jclouds.compute.ComputeServiceContext; import org.jclouds.compute.ComputeServiceContextBuilder; +import org.jclouds.providers.ProviderMetadata; import org.jclouds.softlayer.compute.config.SoftLayerComputeServiceContextModule; import org.jclouds.softlayer.config.SoftLayerRestClientModule; @@ -31,10 +32,17 @@ import com.google.inject.Module; * * @author Adrian Cole */ -public class SoftLayerContextBuilder extends ComputeServiceContextBuilder { +public class SoftLayerContextBuilder + extends + ComputeServiceContextBuilder, SoftLayerApiMetadata> { - public SoftLayerContextBuilder(Properties props) { - super(SoftLayerClient.class, SoftLayerAsyncClient.class, props); + public SoftLayerContextBuilder( + ProviderMetadata, SoftLayerApiMetadata> providerMetadata) { + super(providerMetadata); + } + + public SoftLayerContextBuilder(SoftLayerApiMetadata apiMetadata) { + super(apiMetadata); } @Override @@ -42,7 +50,6 @@ public class SoftLayerContextBuilder extends ComputeServiceContextBuilder modules) { modules.add(new SoftLayerRestClientModule()); } diff --git a/providers/softlayer/src/main/java/org/jclouds/softlayer/SoftLayerPropertiesBuilder.java b/providers/softlayer/src/main/java/org/jclouds/softlayer/SoftLayerPropertiesBuilder.java deleted file mode 100644 index 142ddb9df6..0000000000 --- a/providers/softlayer/src/main/java/org/jclouds/softlayer/SoftLayerPropertiesBuilder.java +++ /dev/null @@ -1,79 +0,0 @@ -/** - * 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.softlayer; - -import static org.jclouds.Constants.PROPERTY_API_VERSION; -import static org.jclouds.Constants.PROPERTY_ENDPOINT; -import static org.jclouds.Constants.PROPERTY_ISO3166_CODES; -import static org.jclouds.softlayer.reference.SoftLayerConstants.PROPERTY_SOFTLAYER_VIRTUALGUEST_CPU_REGEX; -import static org.jclouds.softlayer.reference.SoftLayerConstants.PROPERTY_SOFTLAYER_VIRTUALGUEST_DISK0_TYPE; -import static org.jclouds.softlayer.reference.SoftLayerConstants.PROPERTY_SOFTLAYER_VIRTUALGUEST_LOGIN_DETAILS_DELAY; -import static org.jclouds.softlayer.reference.SoftLayerConstants.PROPERTY_SOFTLAYER_VIRTUALGUEST_PACKAGE_NAME; -import static org.jclouds.softlayer.reference.SoftLayerConstants.PROPERTY_SOFTLAYER_VIRTUALGUEST_PORT_SPEED; -import static org.jclouds.softlayer.reference.SoftLayerConstants.PROPERTY_SOFTLAYER_VIRTUALGUEST_PRICES; - -import java.util.Properties; - -import org.jclouds.PropertiesBuilder; - -import com.google.common.base.Joiner; -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.ImmutableSet.Builder; - -/** - * Builds properties used in SoftLayer Clients - * - * @author Adrian Cole - */ -public class SoftLayerPropertiesBuilder extends PropertiesBuilder { - @Override - protected Properties defaultProperties() { - Properties properties = super.defaultProperties(); - properties.setProperty(PROPERTY_ENDPOINT, "https://api.softlayer.com/rest"); - properties.setProperty(PROPERTY_API_VERSION, "3"); - properties.setProperty(PROPERTY_SOFTLAYER_VIRTUALGUEST_LOGIN_DETAILS_DELAY, "" + 60 * 60 * 1000); - properties.setProperty(PROPERTY_SOFTLAYER_VIRTUALGUEST_PACKAGE_NAME, "Cloud Server"); - // ex: for private (ex. don't share hardware) use "Private [0-9]+ x ([.0-9]+) GHz Core[s]?" - // ex: for private and public use ".*[0-9]+ x ([.0-9]+) GHz Core[s]?" - properties.setProperty(PROPERTY_SOFTLAYER_VIRTUALGUEST_CPU_REGEX, "[0-9]+ x ([0-9.]+) GHz Core[s]?"); - // SAN or LOCAL - properties.setProperty(PROPERTY_SOFTLAYER_VIRTUALGUEST_DISK0_TYPE, "LOCAL"); - // 10, 100, 1000 - properties.setProperty(PROPERTY_SOFTLAYER_VIRTUALGUEST_PORT_SPEED, "10"); - properties.setProperty(PROPERTY_ISO3166_CODES, "SG,NL,US-CA,US-TX,US-VA,US-WA,US-TX"); - Builder prices = ImmutableSet.builder(); - prices.add("21"); // 1 IP Address - prices.add("55"); // Host Ping: categoryCode: monitoring, notification - prices.add("57"); // Email and Ticket: categoryCode: notification - prices.add("58"); // Automated Notification: categoryCode: response - prices.add("1800"); // 0 GB Bandwidth: categoryCode: bandwidth - prices.add("905"); // Reboot / Remote Console: categoryCode: remote_management - prices.add("418"); // Nessus Vulnerability Assessment & Reporting: categoryCode: - // vulnerability_scanner - prices.add("420"); // Unlimited SSL VPN Users & 1 PPTP VPN User per account: categoryCode: - // vpn_management - properties.setProperty(PROPERTY_SOFTLAYER_VIRTUALGUEST_PRICES, Joiner.on(',').join(prices.build())); - return properties; - } - - public SoftLayerPropertiesBuilder(Properties properties) { - super(properties); - } - -} diff --git a/providers/softlayer/src/main/java/org/jclouds/softlayer/SoftLayerProviderMetadata.java b/providers/softlayer/src/main/java/org/jclouds/softlayer/SoftLayerProviderMetadata.java index 00f465a085..141bd163ae 100644 --- a/providers/softlayer/src/main/java/org/jclouds/softlayer/SoftLayerProviderMetadata.java +++ b/providers/softlayer/src/main/java/org/jclouds/softlayer/SoftLayerProviderMetadata.java @@ -18,46 +18,101 @@ */ package org.jclouds.softlayer; -import java.net.URI; +import static org.jclouds.softlayer.reference.SoftLayerConstants.PROPERTY_SOFTLAYER_VIRTUALGUEST_CPU_REGEX; +import static org.jclouds.softlayer.reference.SoftLayerConstants.PROPERTY_SOFTLAYER_VIRTUALGUEST_DISK0_TYPE; +import static org.jclouds.softlayer.reference.SoftLayerConstants.PROPERTY_SOFTLAYER_VIRTUALGUEST_LOGIN_DETAILS_DELAY; +import static org.jclouds.softlayer.reference.SoftLayerConstants.PROPERTY_SOFTLAYER_VIRTUALGUEST_PACKAGE_NAME; +import static org.jclouds.softlayer.reference.SoftLayerConstants.PROPERTY_SOFTLAYER_VIRTUALGUEST_PORT_SPEED; +import static org.jclouds.softlayer.reference.SoftLayerConstants.PROPERTY_SOFTLAYER_VIRTUALGUEST_PRICES; -import org.jclouds.providers.BaseProviderMetadata; +import java.net.URI; +import java.util.Properties; + +import org.jclouds.compute.ComputeServiceContext; +import org.jclouds.providers.ProviderMetadata; +import org.jclouds.providers.internal.BaseProviderMetadata; + +import com.google.common.base.Joiner; +import com.google.common.collect.ImmutableSet; /** - * Implementation of {@ link org.jclouds.types.ProviderMetadata} for SoftLayer. - * + * Implementation of {@link org.jclouds.types.ProviderMetadata} for SoftLayer. * @author Adrian Cole */ -public class SoftLayerProviderMetadata extends BaseProviderMetadata { - public SoftLayerProviderMetadata() { - this(builder() - .id("softlayer") - .name("SoftLayer") - .api(new SoftLayerApiMetadata()) - .homepage(URI.create("http://www.softlayer.com")) - .console(URI.create("https://manage.softlayer.com")) - .iso3166Codes("SG","US-CA","US-TX","US-VA","US-WA","US-TX")); +public class SoftLayerProviderMetadata + extends + BaseProviderMetadata, SoftLayerApiMetadata> { + + public static Builder builder() { + return new Builder(); } - // below are so that we can reuse builders, toString, hashCode, etc. - // we have to set concrete classes here, as our base class cannot be - // concrete due to serviceLoader - protected SoftLayerProviderMetadata(ConcreteBuilder builder) { + @Override + public Builder toBuilder() { + return builder().fromProviderMetadata(this); + } + + public SoftLayerProviderMetadata() { + super(builder()); + } + + public SoftLayerProviderMetadata(Builder builder) { super(builder); } - private static class ConcreteBuilder extends Builder { + protected static Properties defaultProperties() { + Properties properties = new Properties(); + properties.setProperty(PROPERTY_SOFTLAYER_VIRTUALGUEST_LOGIN_DETAILS_DELAY, "" + 60 * 60 * 1000); + properties.setProperty(PROPERTY_SOFTLAYER_VIRTUALGUEST_PACKAGE_NAME, "Cloud Server"); + // ex: for private (ex. don't share hardware) use "Private [0-9]+ x ([.0-9]+) GHz Core[s]?" + // ex: for private and public use ".*[0-9]+ x ([.0-9]+) GHz Core[s]?" + properties.setProperty(PROPERTY_SOFTLAYER_VIRTUALGUEST_CPU_REGEX, "[0-9]+ x ([0-9.]+) GHz Core[s]?"); + // SAN or LOCAL + properties.setProperty(PROPERTY_SOFTLAYER_VIRTUALGUEST_DISK0_TYPE, "LOCAL"); + // 10, 100, 1000 + properties.setProperty(PROPERTY_SOFTLAYER_VIRTUALGUEST_PORT_SPEED, "10"); + ImmutableSet.Builder prices = ImmutableSet.builder(); + prices.add("21"); // 1 IP Address + prices.add("55"); // Host Ping: categoryCode: monitoring, notification + prices.add("57"); // Email and Ticket: categoryCode: notification + prices.add("58"); // Automated Notification: categoryCode: response + prices.add("1800"); // 0 GB Bandwidth: categoryCode: bandwidth + prices.add("905"); // Reboot / Remote Console: categoryCode: remote_management + prices.add("418"); // Nessus Vulnerability Assessment & Reporting: categoryCode: + // vulnerability_scanner + prices.add("420"); // Unlimited SSL VPN Users & 1 PPTP VPN User per account: categoryCode: + // vpn_management + properties.setProperty(PROPERTY_SOFTLAYER_VIRTUALGUEST_PRICES, Joiner.on(',').join(prices.build())); + + return properties; + } + + public static class Builder + extends + BaseProviderMetadata.Builder, SoftLayerApiMetadata> { + + protected Builder() { + id("softlayer") + .name("SoftLayer") + .apiMetadata(new SoftLayerApiMetadata()) + .homepage(URI.create("http://www.softlayer.com")) + .console(URI.create("https://manage.softlayer.com")) + .iso3166Codes("SG","US-CA","US-TX","US-VA","US-WA","US-TX") + .endpoint("https://api.softlayer.com/rest") + .defaultProperties(SoftLayerProviderMetadata.defaultProperties()); + } @Override public SoftLayerProviderMetadata build() { return new SoftLayerProviderMetadata(this); } - } - public static ConcreteBuilder builder() { - return new ConcreteBuilder(); - } + @Override + public Builder fromProviderMetadata( + ProviderMetadata, SoftLayerApiMetadata> in) { + super.fromProviderMetadata(in); + return this; + } - public ConcreteBuilder toBuilder() { - return builder().fromProviderMetadata(this); } } \ No newline at end of file diff --git a/providers/softlayer/src/test/java/org/jclouds/softlayer/SoftLayerProviderTest.java b/providers/softlayer/src/test/java/org/jclouds/softlayer/SoftLayerProviderTest.java index 01d71eb4ef..8ef1e7b13a 100644 --- a/providers/softlayer/src/test/java/org/jclouds/softlayer/SoftLayerProviderTest.java +++ b/providers/softlayer/src/test/java/org/jclouds/softlayer/SoftLayerProviderTest.java @@ -18,7 +18,7 @@ */ package org.jclouds.softlayer; -import org.jclouds.providers.BaseProviderMetadataTest; +import org.jclouds.providers.internal.BaseProviderMetadataTest; import org.testng.annotations.Test; /** diff --git a/providers/softlayer/src/test/java/org/jclouds/softlayer/compute/SoftLayerComputeServiceAdapterLiveTest.java b/providers/softlayer/src/test/java/org/jclouds/softlayer/compute/SoftLayerComputeServiceAdapterLiveTest.java index f663f86a2c..e784ee8a37 100644 --- a/providers/softlayer/src/test/java/org/jclouds/softlayer/compute/SoftLayerComputeServiceAdapterLiveTest.java +++ b/providers/softlayer/src/test/java/org/jclouds/softlayer/compute/SoftLayerComputeServiceAdapterLiveTest.java @@ -29,7 +29,6 @@ import org.jclouds.compute.domain.Template; import org.jclouds.compute.functions.DefaultCredentialsFromImageOrOverridingCredentials; import org.jclouds.compute.strategy.PrioritizeCredentialsFromTemplate; import org.jclouds.domain.LoginCredentials; -import org.jclouds.logging.log4j.config.Log4JLoggingModule; import org.jclouds.net.IPSocket; import org.jclouds.softlayer.compute.options.SoftLayerTemplateOptions; import org.jclouds.softlayer.compute.strategy.SoftLayerComputeServiceAdapter; @@ -43,7 +42,6 @@ import org.testng.annotations.Test; import com.google.common.collect.Iterables; import com.google.common.net.InetAddresses; -import com.google.inject.Guice; @Test(groups = "live", singleThreaded = true, testName = "SoftLayerComputeServiceAdapterLiveTest") public class SoftLayerComputeServiceAdapterLiveTest extends BaseSoftLayerClientLiveTest { @@ -52,10 +50,9 @@ public class SoftLayerComputeServiceAdapterLiveTest extends BaseSoftLayerClientL private NodeAndInitialCredentials guest; @BeforeGroups(groups = { "live" }) - public void setupClient() { - super.setupClient(); - adapter = Guice.createInjector(module, new Log4JLoggingModule()) - .getInstance(SoftLayerComputeServiceAdapter.class); + public void setupContext() { + super.setupContext(); + adapter = context.utils().injector().getInstance(SoftLayerComputeServiceAdapter.class); } @Test @@ -70,7 +67,7 @@ public class SoftLayerComputeServiceAdapterLiveTest extends BaseSoftLayerClientL public void testCreateNodeWithGroupEncodedIntoNameThenStoreCredentials() { String group = "foo"; String name = "node" + new Random().nextInt(); - Template template = computeContext.getComputeService().templateBuilder().build(); + Template template = context.getComputeService().templateBuilder().build(); // test passing custom options template.getOptions().as(SoftLayerTemplateOptions.class).domainName("me.org"); @@ -85,7 +82,7 @@ public class SoftLayerComputeServiceAdapterLiveTest extends BaseSoftLayerClientL } protected void doConnectViaSsh(VirtualGuest guest, LoginCredentials creds) { - SshClient ssh = computeContext.utils().sshFactory().create(new IPSocket(guest.getPrimaryIpAddress(), 22), creds); + SshClient ssh = context.utils().sshFactory().create(new IPSocket(guest.getPrimaryIpAddress(), 22), creds); try { ssh.connect(); ExecResponse hello = ssh.exec("echo hello"); @@ -111,9 +108,9 @@ public class SoftLayerComputeServiceAdapterLiveTest extends BaseSoftLayerClientL } @AfterGroups(groups = "live") - protected void tearDown() { + protected void tearDownContext() { if (guest != null) adapter.destroyNode(guest.getNodeId() + ""); - super.tearDown(); + super.tearDownContext(); } } diff --git a/providers/softlayer/src/test/java/org/jclouds/softlayer/compute/SoftLayerComputeServiceLiveTest.java b/providers/softlayer/src/test/java/org/jclouds/softlayer/compute/SoftLayerComputeServiceLiveTest.java index 3562fe30e6..ffd7da5e2c 100644 --- a/providers/softlayer/src/test/java/org/jclouds/softlayer/compute/SoftLayerComputeServiceLiveTest.java +++ b/providers/softlayer/src/test/java/org/jclouds/softlayer/compute/SoftLayerComputeServiceLiveTest.java @@ -18,9 +18,9 @@ */ package org.jclouds.softlayer.compute; -import org.jclouds.compute.BaseComputeServiceLiveTest; -import org.jclouds.compute.ComputeServiceContextFactory; +import org.jclouds.compute.ComputeServiceContext; import org.jclouds.compute.domain.NodeMetadata; +import org.jclouds.compute.internal.BaseComputeServiceLiveTest; import org.jclouds.rest.RestContext; import org.jclouds.softlayer.SoftLayerAsyncClient; import org.jclouds.softlayer.SoftLayerClient; @@ -37,7 +37,10 @@ import com.google.inject.Module; * @author Adrian Cole */ @Test(groups = "live", enabled = true, sequential = true) -public class SoftLayerComputeServiceLiveTest extends BaseComputeServiceLiveTest { +public class SoftLayerComputeServiceLiveTest + extends + BaseComputeServiceLiveTest> { + public SoftLayerComputeServiceLiveTest() { provider = "softlayer"; group = "soft-layer"; @@ -50,8 +53,7 @@ public class SoftLayerComputeServiceLiveTest extends BaseComputeServiceLiveTest public void testAssignability() throws Exception { @SuppressWarnings("unused") - RestContext tmContext = new ComputeServiceContextFactory() - .createContext(provider, identity, credential).getProviderSpecificContext(); + RestContext tmContext = context.getProviderSpecificContext(); } // softlayer does not support metadata diff --git a/providers/softlayer/src/test/java/org/jclouds/softlayer/compute/SoftLayerExperimentLiveTest.java b/providers/softlayer/src/test/java/org/jclouds/softlayer/compute/SoftLayerExperimentLiveTest.java index 8dbb18e283..8e90948446 100644 --- a/providers/softlayer/src/test/java/org/jclouds/softlayer/compute/SoftLayerExperimentLiveTest.java +++ b/providers/softlayer/src/test/java/org/jclouds/softlayer/compute/SoftLayerExperimentLiveTest.java @@ -20,39 +20,43 @@ package org.jclouds.softlayer.compute; import static org.testng.Assert.assertEquals; -import org.jclouds.compute.BaseVersionedServiceLiveTest; import org.jclouds.compute.ComputeServiceContext; -import org.jclouds.compute.ComputeServiceContextFactory; -import org.jclouds.logging.log4j.config.Log4JLoggingModule; -import org.jclouds.sshj.config.SshjSshClientModule; +import org.jclouds.compute.ComputeServiceContextBuilder; +import org.jclouds.compute.internal.BaseComputeServiceContextLiveTest; +import org.jclouds.softlayer.SoftLayerAsyncClient; +import org.jclouds.softlayer.SoftLayerClient; +import org.jclouds.softlayer.SoftLayerProviderMetadata; import org.testng.annotations.Test; -import com.google.common.collect.ImmutableSet; -import com.google.inject.Module; +import com.google.common.io.Closeables; /** * * @author Adrian Cole */ @Test(groups = "live", singleThreaded = true, testName = "SoftLayerExperimentLiveTest") -public class SoftLayerExperimentLiveTest extends BaseVersionedServiceLiveTest { +public class SoftLayerExperimentLiveTest + extends + BaseComputeServiceContextLiveTest> { + public SoftLayerExperimentLiveTest() { - provider = "softlayer"; + provider = "glesys"; } @Test public void testAndExperiment() { - ComputeServiceContext context = null; + ComputeServiceContext context = null; try { - context = new ComputeServiceContextFactory().createContext(provider, identity, credential, ImmutableSet - . of(new Log4JLoggingModule(), new SshjSshClientModule())); + context = ComputeServiceContextBuilder + .newBuilder(new SoftLayerProviderMetadata()) + .overrides(setupProperties()) + .modules(setupModules()).build(); assertEquals(context.getComputeService().listAssignableLocations().size(), 6); } finally { - if (context != null) - context.close(); + Closeables.closeQuietly(context); } } diff --git a/providers/softlayer/src/test/java/org/jclouds/softlayer/compute/SoftLayerTemplateBuilderLiveTest.java b/providers/softlayer/src/test/java/org/jclouds/softlayer/compute/SoftLayerTemplateBuilderLiveTest.java index 195a63a35a..79ab1ddf01 100644 --- a/providers/softlayer/src/test/java/org/jclouds/softlayer/compute/SoftLayerTemplateBuilderLiveTest.java +++ b/providers/softlayer/src/test/java/org/jclouds/softlayer/compute/SoftLayerTemplateBuilderLiveTest.java @@ -29,29 +29,30 @@ import java.io.IOException; import java.util.Properties; import java.util.Set; -import org.jclouds.compute.BaseTemplateBuilderLiveTest; import org.jclouds.compute.ComputeServiceContext; -import org.jclouds.compute.ComputeServiceContextFactory; import org.jclouds.compute.domain.OsFamily; import org.jclouds.compute.domain.OsFamilyVersion64Bit; import org.jclouds.compute.domain.Template; import org.jclouds.compute.domain.Volume; -import org.jclouds.logging.log4j.config.Log4JLoggingModule; +import org.jclouds.compute.internal.BaseTemplateBuilderLiveTest; +import org.jclouds.softlayer.SoftLayerAsyncClient; +import org.jclouds.softlayer.SoftLayerClient; import org.jclouds.softlayer.compute.options.SoftLayerTemplateOptions; import org.testng.annotations.Test; import com.google.common.base.Predicate; import com.google.common.base.Predicates; import com.google.common.collect.ImmutableSet; -import com.google.inject.Module; /** * * @author Jason King */ @Test(groups = "live") -public class SoftLayerTemplateBuilderLiveTest extends BaseTemplateBuilderLiveTest { - +public class SoftLayerTemplateBuilderLiveTest + extends + BaseTemplateBuilderLiveTest> { + public SoftLayerTemplateBuilderLiveTest() { provider = "softlayer"; } @@ -65,20 +66,20 @@ public class SoftLayerTemplateBuilderLiveTest extends BaseTemplateBuilderLiveTes public boolean apply(OsFamilyVersion64Bit input) { // For each os-type both 32- and 64-bit are supported. switch (input.family) { - case UBUNTU: - return input.version.equals("") || input.version.equals("10.04") || input.version.equals("8"); - case DEBIAN: - return input.version.equals("") || input.version.matches("[56].0"); - case FEDORA: - return input.version.equals("") || input.version.equals("13") || input.version.equals("15"); - case RHEL: - return input.version.equals("") || input.version.equals("5") || input.version.equals("6"); - case CENTOS: - return input.version.equals("") || input.version.equals("5") || input.version.equals("6.0"); - case WINDOWS: - return input.version.equals("") || input.version.equals("2003") || input.version.equals("2008"); - default: - return false; + case UBUNTU: + return input.version.equals("") || input.version.equals("10.04") || input.version.equals("8"); + case DEBIAN: + return input.version.equals("") || input.version.matches("[56].0"); + case FEDORA: + return input.version.equals("") || input.version.equals("13") || input.version.equals("15"); + case RHEL: + return input.version.equals("") || input.version.equals("5") || input.version.equals("6"); + case CENTOS: + return input.version.equals("") || input.version.equals("5") || input.version.equals("6.0"); + case WINDOWS: + return input.version.equals("") || input.version.equals("2003") || input.version.equals("2008"); + default: + return false; } } @@ -101,13 +102,12 @@ public class SoftLayerTemplateBuilderLiveTest extends BaseTemplateBuilderLiveTes @Test public void testTemplateBuilderFindsGigabitUplink() throws IOException { - ComputeServiceContext context = null; + ComputeServiceContext context = null; try { Properties overrides = setupProperties(); overrides.setProperty(PROPERTY_SOFTLAYER_VIRTUALGUEST_PORT_SPEED, "1000"); - context = new ComputeServiceContextFactory().createContext(provider, ImmutableSet - . of(new Log4JLoggingModule()), overrides); + context = createContext(overrides, setupModules()); // TODO add something to the template about port speed? context.getComputeService().templateBuilder().build(); @@ -120,13 +120,12 @@ public class SoftLayerTemplateBuilderLiveTest extends BaseTemplateBuilderLiveTes @Test public void testTemplateBuilderFindsMegabitUplink() throws IOException { - ComputeServiceContext context = null; + ComputeServiceContext context = null; try { Properties overrides = setupProperties(); overrides.setProperty(PROPERTY_SOFTLAYER_VIRTUALGUEST_PORT_SPEED, "100"); - context = new ComputeServiceContextFactory().createContext(provider, ImmutableSet - . of(new Log4JLoggingModule()), overrides); + context = createContext(overrides, setupModules()); // TODO add something to the template about port speed? context.getComputeService().templateBuilder().build(); @@ -139,13 +138,12 @@ public class SoftLayerTemplateBuilderLiveTest extends BaseTemplateBuilderLiveTes @Test public void testBiggestTemplateBuilderWhenBootIsSAN() throws IOException { - ComputeServiceContext context = null; + ComputeServiceContext context = null; try { Properties overrides = setupProperties(); overrides.setProperty(PROPERTY_SOFTLAYER_VIRTUALGUEST_DISK0_TYPE, "SAN"); - context = new ComputeServiceContextFactory().createContext(provider, ImmutableSet - . of(new Log4JLoggingModule()), overrides); + context = createContext(overrides, setupModules()); Template template = context.getComputeService().templateBuilder().biggest().build(); assertEquals(getCores(template.getHardware()), 16.0d); @@ -160,13 +158,12 @@ public class SoftLayerTemplateBuilderLiveTest extends BaseTemplateBuilderLiveTes @Test public void testDefaultTemplateBuilderWhenPrivateNetwork() throws IOException { - ComputeServiceContext context = null; + ComputeServiceContext context = null; try { Properties overrides = setupProperties(); overrides.setProperty(PROPERTY_SOFTLAYER_VIRTUALGUEST_CPU_REGEX, "Private [0-9]+ x ([.0-9]+) GHz Core[s]?"); - context = new ComputeServiceContextFactory().createContext(provider, ImmutableSet - . of(new Log4JLoggingModule()), overrides); + context = createContext(overrides, setupModules()); Template template = context.getComputeService().templateBuilder().build(); assertEquals(getCores(template.getHardware()), 1.0d); @@ -181,14 +178,13 @@ public class SoftLayerTemplateBuilderLiveTest extends BaseTemplateBuilderLiveTes @Test public void testBiggestTemplateBuilderWhenPrivateNetwork() throws IOException { - ComputeServiceContext context = null; + ComputeServiceContext context = null; try { Properties overrides = setupProperties(); overrides.setProperty(PROPERTY_SOFTLAYER_VIRTUALGUEST_CPU_REGEX, "Private [0-9]+ x ([.0-9]+) GHz Core[s]?"); - context = new ComputeServiceContextFactory().createContext(provider, ImmutableSet - . of(new Log4JLoggingModule()), overrides); - + context = createContext(overrides, setupModules()); + Template template = context.getComputeService().templateBuilder().biggest().build(); assertEquals(getCores(template.getHardware()), 8.0d); assertEquals(template.getHardware().getRam(), 16); @@ -199,6 +195,7 @@ public class SoftLayerTemplateBuilderLiveTest extends BaseTemplateBuilderLiveTes context.close(); } } + @Test public void testFastestTemplateBuilder() throws IOException { Template template = context.getComputeService().templateBuilder().fastest().build(); diff --git a/providers/softlayer/src/test/java/org/jclouds/softlayer/compute/functions/ProductItemsToHardwareTest.java b/providers/softlayer/src/test/java/org/jclouds/softlayer/compute/functions/ProductItemsToHardwareTest.java index 450ba1d802..329ce3e7a5 100644 --- a/providers/softlayer/src/test/java/org/jclouds/softlayer/compute/functions/ProductItemsToHardwareTest.java +++ b/providers/softlayer/src/test/java/org/jclouds/softlayer/compute/functions/ProductItemsToHardwareTest.java @@ -23,12 +23,11 @@ import static org.jclouds.softlayer.compute.functions.ProductItemsToHardware.har import static org.testng.AssertJUnit.assertEquals; import java.util.List; -import java.util.Properties; import org.jclouds.compute.domain.Hardware; import org.jclouds.compute.domain.Processor; import org.jclouds.compute.domain.Volume; -import org.jclouds.softlayer.SoftLayerPropertiesBuilder; +import org.jclouds.softlayer.SoftLayerProviderMetadata; import org.jclouds.softlayer.domain.ProductItem; import org.jclouds.softlayer.domain.ProductItemCategory; import org.jclouds.softlayer.domain.ProductItemPrice; @@ -59,7 +58,7 @@ public class ProductItemsToHardwareTest { toHardware = Guice.createInjector(new AbstractModule() { @Override protected void configure() { - bindProperties(binder(), new SoftLayerPropertiesBuilder(new Properties()).build()); + bindProperties(binder(), new SoftLayerProviderMetadata().getDefaultProperties()); } }).getInstance(ProductItemsToHardware.class); diff --git a/providers/softlayer/src/test/java/org/jclouds/softlayer/features/AccountClientLiveTest.java b/providers/softlayer/src/test/java/org/jclouds/softlayer/features/AccountClientLiveTest.java index 10bf050c84..fa533d87ce 100644 --- a/providers/softlayer/src/test/java/org/jclouds/softlayer/features/AccountClientLiveTest.java +++ b/providers/softlayer/src/test/java/org/jclouds/softlayer/features/AccountClientLiveTest.java @@ -34,9 +34,9 @@ import org.testng.annotations.Test; @Test(groups = "live") public class AccountClientLiveTest extends BaseSoftLayerClientLiveTest { @BeforeGroups(groups = { "live" }) - public void setupClient() { - super.setupClient(); - client = context.getApi().getAccountClient(); + public void setupContext() { + super.setupContext(); + client = socontext.getApi().getAccountClient(); } private AccountClient client; diff --git a/providers/softlayer/src/test/java/org/jclouds/softlayer/features/BaseSoftLayerAsyncClientTest.java b/providers/softlayer/src/test/java/org/jclouds/softlayer/features/BaseSoftLayerAsyncClientTest.java index 59e8ab8a8d..02d8dd7acf 100644 --- a/providers/softlayer/src/test/java/org/jclouds/softlayer/features/BaseSoftLayerAsyncClientTest.java +++ b/providers/softlayer/src/test/java/org/jclouds/softlayer/features/BaseSoftLayerAsyncClientTest.java @@ -20,20 +20,16 @@ package org.jclouds.softlayer.features; import static org.testng.Assert.assertEquals; -import java.util.Properties; - import org.jclouds.http.HttpRequest; import org.jclouds.http.filters.BasicAuthentication; -import org.jclouds.rest.RestClientTest; -import org.jclouds.rest.RestContextFactory; -import org.jclouds.rest.RestContextSpec; -import org.jclouds.softlayer.SoftLayerAsyncClient; -import org.jclouds.softlayer.SoftLayerClient; +import org.jclouds.providers.ProviderMetadata; +import org.jclouds.rest.internal.BaseAsyncClientTest; +import org.jclouds.softlayer.SoftLayerProviderMetadata; /** * @author Adrian Cole */ -public abstract class BaseSoftLayerAsyncClientTest extends RestClientTest { +public abstract class BaseSoftLayerAsyncClientTest extends BaseAsyncClientTest { @Override protected void checkFilters(HttpRequest request) { @@ -42,9 +38,8 @@ public abstract class BaseSoftLayerAsyncClientTest extends RestClientTest } @Override - public RestContextSpec createContextSpec() { - Properties props = new Properties(); - return new RestContextFactory().createContextSpec("softlayer", "apiKey", "secretKey", props); + public ProviderMetadata createProviderMetadata() { + return new SoftLayerProviderMetadata(); } } \ No newline at end of file diff --git a/providers/softlayer/src/test/java/org/jclouds/softlayer/features/BaseSoftLayerClientLiveTest.java b/providers/softlayer/src/test/java/org/jclouds/softlayer/features/BaseSoftLayerClientLiveTest.java index 9f8658c2ad..0febeb7087 100644 --- a/providers/softlayer/src/test/java/org/jclouds/softlayer/features/BaseSoftLayerClientLiveTest.java +++ b/providers/softlayer/src/test/java/org/jclouds/softlayer/features/BaseSoftLayerClientLiveTest.java @@ -18,93 +18,31 @@ */ package org.jclouds.softlayer.features; -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.inject.name.Names.bindProperties; -import static org.jclouds.softlayer.reference.SoftLayerConstants.PROPERTY_SOFTLAYER_VIRTUALGUEST_PACKAGE_NAME; -import static org.jclouds.softlayer.reference.SoftLayerConstants.PROPERTY_SOFTLAYER_VIRTUALGUEST_PRICES; - -import java.util.Properties; -import java.util.concurrent.atomic.AtomicReference; - -import javax.inject.Named; -import javax.inject.Singleton; - -import org.jclouds.collect.Memoized; import org.jclouds.compute.ComputeServiceContext; -import org.jclouds.compute.ComputeServiceContextFactory; -import org.jclouds.logging.log4j.config.Log4JLoggingModule; -import org.jclouds.rest.AuthorizationException; +import org.jclouds.compute.internal.BaseComputeServiceContextLiveTest; import org.jclouds.rest.RestContext; import org.jclouds.softlayer.SoftLayerAsyncClient; import org.jclouds.softlayer.SoftLayerClient; -import org.jclouds.softlayer.SoftLayerPropertiesBuilder; -import org.jclouds.softlayer.compute.config.SoftLayerComputeServiceContextModule; -import org.jclouds.softlayer.domain.ProductItemPrice; -import org.jclouds.softlayer.domain.ProductPackage; -import org.jclouds.sshj.config.SshjSshClientModule; -import org.testng.annotations.AfterGroups; import org.testng.annotations.BeforeGroups; import org.testng.annotations.Test; -import com.google.common.base.Supplier; -import com.google.common.collect.ImmutableSet; -import com.google.inject.AbstractModule; -import com.google.inject.Module; -import com.google.inject.Provides; - /** * Tests behavior of {@code SoftLayerClient} * * @author Adrian Cole */ @Test(groups = "live") -public class BaseSoftLayerClientLiveTest { +public class BaseSoftLayerClientLiveTest + extends + BaseComputeServiceContextLiveTest> { - protected RestContext context; - protected ComputeServiceContext computeContext; - protected Module module; + protected RestContext socontext; - @BeforeGroups(groups = { "live" }) - public void setupClient() { - String identity = checkNotNull(System.getProperty("test.softlayer.identity"), "test.softlayer.identity"); - String credential = checkNotNull(System.getProperty("test.softlayer.credential"), "test.softlayer.credential"); - - computeContext = new ComputeServiceContextFactory().createContext("softlayer", identity, credential, ImmutableSet - . of(new Log4JLoggingModule(), new SshjSshClientModule())); - context = computeContext.getProviderSpecificContext(); - module = new AbstractModule() { - - @Override - protected void configure() { - bindProperties(binder(), new SoftLayerPropertiesBuilder(new Properties()).build()); - bind(SoftLayerClient.class).toInstance(context.getApi()); - - } - - @SuppressWarnings("unused") - @Provides - @Singleton - @Memoized - public Supplier getProductPackage(AtomicReference authException, - SoftLayerClient client, - @Named(PROPERTY_SOFTLAYER_VIRTUALGUEST_PACKAGE_NAME) String virtualGuestPackageName) { - return new SoftLayerComputeServiceContextModule().getProductPackage(authException, 30, client, - virtualGuestPackageName); - } - - @SuppressWarnings("unused") - @Provides - @Singleton - public Iterable prices(@Named(PROPERTY_SOFTLAYER_VIRTUALGUEST_PRICES) String prices) { - return new SoftLayerComputeServiceContextModule().prices(prices); - } - }; - } - - @AfterGroups(groups = "live") - protected void tearDown() { - if (context != null) - context.close(); + @BeforeGroups(groups = { "integration", "live" }) + @Override + public void setupContext() { + super.setupContext(); + socontext = context.getProviderSpecificContext(); } } diff --git a/providers/softlayer/src/test/java/org/jclouds/softlayer/features/DatacenterAsyncClientTest.java b/providers/softlayer/src/test/java/org/jclouds/softlayer/features/DatacenterAsyncClientTest.java index 3a852f0b53..fd1e9fedf6 100644 --- a/providers/softlayer/src/test/java/org/jclouds/softlayer/features/DatacenterAsyncClientTest.java +++ b/providers/softlayer/src/test/java/org/jclouds/softlayer/features/DatacenterAsyncClientTest.java @@ -57,7 +57,7 @@ public class DatacenterAsyncClientTest extends BaseSoftLayerAsyncClientTest ramItems = Iterables.filter(productPackage.getItems(), Predicates.and(categoryCode("ram"), capacity(2.0f))); @@ -117,7 +116,7 @@ public class VirtualGuestClientLiveTest extends BaseSoftLayerClientLiveTest { osToProductItem.get("Ubuntu Linux 8 LTS Hardy Heron - Minimal Install (64 bit)")); Builder prices = ImmutableSet.builder(); - prices.addAll(Guice.createInjector(module).getInstance(Key.get(new TypeLiteral>() { + prices.addAll(context.utils().injector().getInstance(Key.get(new TypeLiteral>() { }))); prices.add(ramPrice); prices.add(cpuPrice); @@ -129,11 +128,11 @@ public class VirtualGuestClientLiveTest extends BaseSoftLayerClientLiveTest { ProductOrder order = ProductOrder.builder().packageId(pkgId).quantity(1).useHourlyPricing(true).prices( prices.build()).virtualGuest(guest).build(); - ProductOrderReceipt receipt = context.getApi().getVirtualGuestClient().orderVirtualGuest(order); + ProductOrderReceipt receipt = socontext.getApi().getVirtualGuestClient().orderVirtualGuest(order); ProductOrder order2 = receipt.getOrderDetails(); VirtualGuest result = Iterables.get(order2.getVirtualGuests(), 0); - ProductOrder order3 = context.getApi().getVirtualGuestClient().getOrderTemplate(result.getId()); + ProductOrder order3 = socontext.getApi().getVirtualGuestClient().getOrderTemplate(result.getId()); assertEquals(order.getPrices(), order3.getPrices()); assertNotNull(receipt); diff --git a/providers/softlayer/src/test/java/org/jclouds/softlayer/predicates/ProductItemPredicatesTest.java b/providers/softlayer/src/test/java/org/jclouds/softlayer/predicates/ProductItemPredicatesTest.java index 52a03fa214..e8e1aab43d 100644 --- a/providers/softlayer/src/test/java/org/jclouds/softlayer/predicates/ProductItemPredicatesTest.java +++ b/providers/softlayer/src/test/java/org/jclouds/softlayer/predicates/ProductItemPredicatesTest.java @@ -37,7 +37,7 @@ public class ProductItemPredicatesTest { private ProductItem emptyItem; @BeforeGroups(groups = { "unit" }) - public void setupClient() { + public void setupContext() { ramCategory = ProductItemCategory.builder().id(1).categoryCode("ram").build(); item = ProductItem.builder().id(1).description("a test item").categories(ImmutableSet.of(ramCategory)).capacity( diff --git a/providers/stratogen-vcloud-mycloud/src/main/java/org/jclouds/stratogen/vcloud/mycloud/StratoGenVCloudMyCloudContextBuilder.java b/providers/stratogen-vcloud-mycloud/src/main/java/org/jclouds/stratogen/vcloud/mycloud/StratoGenVCloudMyCloudContextBuilder.java index 3f5758010f..c4c50fb035 100644 --- a/providers/stratogen-vcloud-mycloud/src/main/java/org/jclouds/stratogen/vcloud/mycloud/StratoGenVCloudMyCloudContextBuilder.java +++ b/providers/stratogen-vcloud-mycloud/src/main/java/org/jclouds/stratogen/vcloud/mycloud/StratoGenVCloudMyCloudContextBuilder.java @@ -19,28 +19,34 @@ package org.jclouds.stratogen.vcloud.mycloud; import java.util.List; -import java.util.Properties; -import org.jclouds.stratogen.vcloud.mycloud.config.StratoGenVCloudMyCloudComputeServiceContextModule; +import org.jclouds.compute.ComputeServiceContext; +import org.jclouds.providers.ProviderMetadata; import org.jclouds.stratogen.vcloud.mycloud.config.StratoGenVCloudMyCloudRestClientModule; +import org.jclouds.vcloud.VCloudApiMetadata; +import org.jclouds.vcloud.VCloudAsyncClient; +import org.jclouds.vcloud.VCloudClient; import org.jclouds.vcloud.VCloudContextBuilder; +import org.jclouds.vcloud.compute.config.VCloudComputeServiceContextModule; import com.google.inject.Module; /** - * {@inheritDoc} - * * @author Adrian Cole */ public class StratoGenVCloudMyCloudContextBuilder extends VCloudContextBuilder { + public StratoGenVCloudMyCloudContextBuilder( + ProviderMetadata, VCloudApiMetadata> providerMetadata) { + super(providerMetadata); + } - public StratoGenVCloudMyCloudContextBuilder(Properties props) { - super(props); + public StratoGenVCloudMyCloudContextBuilder(VCloudApiMetadata apiMetadata) { + super(apiMetadata); } @Override protected void addContextModule(List modules) { - modules.add(new StratoGenVCloudMyCloudComputeServiceContextModule()); + modules.add(new VCloudComputeServiceContextModule()); } @Override diff --git a/providers/stratogen-vcloud-mycloud/src/main/java/org/jclouds/stratogen/vcloud/mycloud/StratoGenVCloudMyCloudPropertiesBuilder.java b/providers/stratogen-vcloud-mycloud/src/main/java/org/jclouds/stratogen/vcloud/mycloud/StratoGenVCloudMyCloudPropertiesBuilder.java deleted file mode 100644 index ddcd6bed32..0000000000 --- a/providers/stratogen-vcloud-mycloud/src/main/java/org/jclouds/stratogen/vcloud/mycloud/StratoGenVCloudMyCloudPropertiesBuilder.java +++ /dev/null @@ -1,49 +0,0 @@ -/** - * 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.stratogen.vcloud.mycloud; - -import static org.jclouds.Constants.PROPERTY_BUILD_VERSION; -import static org.jclouds.Constants.PROPERTY_ENDPOINT; -import static org.jclouds.Constants.PROPERTY_ISO3166_CODES; -import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_NETWORK; - -import java.util.Properties; - -import org.jclouds.vcloud.VCloudPropertiesBuilder; - -/** - * Builds properties used in stratogen VCloud Clients - * - * @author Adrian Cole - */ -public class StratoGenVCloudMyCloudPropertiesBuilder extends VCloudPropertiesBuilder { - @Override - protected Properties defaultProperties() { - Properties properties = super.defaultProperties(); - properties.setProperty(PROPERTY_ISO3166_CODES, "GB"); - properties.setProperty(PROPERTY_ENDPOINT, "https://vcd.stratogen.net/api"); - properties.setProperty(PROPERTY_BUILD_VERSION, "1.5.0.464915"); - properties.setProperty(PROPERTY_VCLOUD_DEFAULT_NETWORK, "Direct Internet"); - return properties; - } - - public StratoGenVCloudMyCloudPropertiesBuilder(Properties properties) { - super(properties); - } -} diff --git a/providers/stratogen-vcloud-mycloud/src/main/java/org/jclouds/stratogen/vcloud/mycloud/StratoGenVCloudMyCloudProviderMetadata.java b/providers/stratogen-vcloud-mycloud/src/main/java/org/jclouds/stratogen/vcloud/mycloud/StratoGenVCloudMyCloudProviderMetadata.java index 56d792b129..07a245e950 100644 --- a/providers/stratogen-vcloud-mycloud/src/main/java/org/jclouds/stratogen/vcloud/mycloud/StratoGenVCloudMyCloudProviderMetadata.java +++ b/providers/stratogen-vcloud-mycloud/src/main/java/org/jclouds/stratogen/vcloud/mycloud/StratoGenVCloudMyCloudProviderMetadata.java @@ -18,49 +18,78 @@ */ package org.jclouds.stratogen.vcloud.mycloud; -import java.net.URI; +import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_NETWORK; -import org.jclouds.providers.BaseProviderMetadata; +import java.net.URI; +import java.util.Properties; + +import org.jclouds.compute.ComputeServiceContext; +import org.jclouds.providers.ProviderMetadata; +import org.jclouds.providers.internal.BaseProviderMetadata; import org.jclouds.vcloud.VCloudApiMetadata; +import org.jclouds.vcloud.VCloudAsyncClient; +import org.jclouds.vcloud.VCloudClient; + +import com.google.common.reflect.TypeToken; /** * Implementation of {@link org.jclouds.types.ProviderMetadata} for StratoGen VMware hosting * * @author Adrian Cole */ -public class StratoGenVCloudMyCloudProviderMetadata extends BaseProviderMetadata { +public class StratoGenVCloudMyCloudProviderMetadata + extends + BaseProviderMetadata, VCloudApiMetadata> { - public StratoGenVCloudMyCloudProviderMetadata() { - this(builder() - .id("stratogen-vcloud-mycloud") - .name("StratoGen VMware hosting") - .api(new VCloudApiMetadata()) - .homepage(URI.create("http://www.stratogen.net")) - .console(URI.create("https://mycloud.stratogen.net/cloud/org/YOUR_ORG_HERE")) - .iso3166Codes("GB")); + public static Builder builder() { + return new Builder(); } - // below are so that we can reuse builders, toString, hashCode, etc. - // we have to set concrete classes here, as our base class cannot be - // concrete due to serviceLoader - protected StratoGenVCloudMyCloudProviderMetadata(ConcreteBuilder builder) { + @Override + public Builder toBuilder() { + return builder().fromProviderMetadata(this); + } + + public StratoGenVCloudMyCloudProviderMetadata() { + super(builder()); + } + + public StratoGenVCloudMyCloudProviderMetadata(Builder builder) { super(builder); } - private static class ConcreteBuilder extends Builder { + protected static Properties defaultProperties() { + Properties properties = new Properties(); + properties.setProperty(PROPERTY_VCLOUD_DEFAULT_NETWORK, "Direct Internet"); + return properties; + } + + public static class Builder extends BaseProviderMetadata.Builder, VCloudApiMetadata> { + + protected Builder(){ + id("stratogen-vcloud-mycloud") + .name("StratoGen VMware hosting") + .apiMetadata( + new VCloudApiMetadata().toBuilder() + .buildVersion("1.5.0.464915") + .contextBuilder(TypeToken.of(StratoGenVCloudMyCloudContextBuilder.class)).build()) + .homepage(URI.create("http://www.stratogen.net")) + .console(URI.create("https://mycloud.stratogen.net/cloud/org/YOUR_ORG_HERE")) + .iso3166Codes("GB") + .endpoint("https://mycloud.greenhousedata.com/api") + .defaultProperties(StratoGenVCloudMyCloudProviderMetadata.defaultProperties()); + } @Override public StratoGenVCloudMyCloudProviderMetadata build() { return new StratoGenVCloudMyCloudProviderMetadata(this); } + + @Override + public Builder fromProviderMetadata( + ProviderMetadata, VCloudApiMetadata> in) { + super.fromProviderMetadata(in); + return this; + } } - - public static ConcreteBuilder builder() { - return new ConcreteBuilder(); - } - - public ConcreteBuilder toBuilder() { - return builder().fromProviderMetadata(this); - } - -} +} \ No newline at end of file diff --git a/providers/stratogen-vcloud-mycloud/src/test/java/org/jclouds/stratogen/vcloud/mycloud/StratoGenVCloudMyCloudProviderTest.java b/providers/stratogen-vcloud-mycloud/src/test/java/org/jclouds/stratogen/vcloud/mycloud/StratoGenVCloudMyCloudProviderTest.java index 09ea912b2e..7f4f71fdf8 100644 --- a/providers/stratogen-vcloud-mycloud/src/test/java/org/jclouds/stratogen/vcloud/mycloud/StratoGenVCloudMyCloudProviderTest.java +++ b/providers/stratogen-vcloud-mycloud/src/test/java/org/jclouds/stratogen/vcloud/mycloud/StratoGenVCloudMyCloudProviderTest.java @@ -18,7 +18,7 @@ */ package org.jclouds.stratogen.vcloud.mycloud; -import org.jclouds.providers.BaseProviderMetadataTest; +import org.jclouds.providers.internal.BaseProviderMetadataTest; import org.jclouds.vcloud.VCloudApiMetadata; import org.testng.annotations.Test; diff --git a/providers/stratogen-vcloud-mycloud/src/test/java/org/jclouds/stratogen/vcloud/mycloud/compute/StratoGenVCloudMyCloudTemplateBuilderLiveTest.java b/providers/stratogen-vcloud-mycloud/src/test/java/org/jclouds/stratogen/vcloud/mycloud/compute/StratoGenVCloudMyCloudTemplateBuilderLiveTest.java index 5d03161fe5..fb4590393d 100644 --- a/providers/stratogen-vcloud-mycloud/src/test/java/org/jclouds/stratogen/vcloud/mycloud/compute/StratoGenVCloudMyCloudTemplateBuilderLiveTest.java +++ b/providers/stratogen-vcloud-mycloud/src/test/java/org/jclouds/stratogen/vcloud/mycloud/compute/StratoGenVCloudMyCloudTemplateBuilderLiveTest.java @@ -24,10 +24,13 @@ import static org.testng.Assert.assertEquals; import java.io.IOException; import java.util.Set; -import org.jclouds.compute.BaseTemplateBuilderLiveTest; +import org.jclouds.compute.ComputeServiceContext; import org.jclouds.compute.domain.OsFamily; import org.jclouds.compute.domain.OsFamilyVersion64Bit; import org.jclouds.compute.domain.Template; +import org.jclouds.compute.internal.BaseTemplateBuilderLiveTest; +import org.jclouds.vcloud.VCloudAsyncClient; +import org.jclouds.vcloud.VCloudClient; import org.testng.annotations.Test; import com.google.common.base.Predicate; @@ -39,7 +42,9 @@ import com.google.common.collect.ImmutableSet; * @author Adrian Cole */ @Test(groups = "live", testName = "StratoGenVCloudMyCloudTemplateBuilderLiveTest") -public class StratoGenVCloudMyCloudTemplateBuilderLiveTest extends BaseTemplateBuilderLiveTest { +public class StratoGenVCloudMyCloudTemplateBuilderLiveTest + extends + BaseTemplateBuilderLiveTest> { public StratoGenVCloudMyCloudTemplateBuilderLiveTest() { provider = "stratogen-vcloud-mycloud"; diff --git a/providers/synaptic-storage/pom.xml b/providers/synaptic-storage/pom.xml index 3bdfd71a8b..8eb2a76de5 100644 --- a/providers/synaptic-storage/pom.xml +++ b/providers/synaptic-storage/pom.xml @@ -34,7 +34,6 @@ bundle - org.jclouds.synaptic.storage.blobstore.integration.SynapticStorageTestInitializer https://storage.synaptic.att.com 1.3.0 @@ -106,7 +105,6 @@ ${test.synaptic-storage.build-version} ${test.synaptic-storage.identity} ${test.synaptic-storage.credential} - ${test.initializer} ${jclouds.blobstore.httpstream.url} ${jclouds.blobstore.httpstream.md5} diff --git a/providers/synaptic-storage/src/main/java/org/jclouds/synaptic/storage/SynapticStoragePropertiesBuilder.java b/providers/synaptic-storage/src/main/java/org/jclouds/synaptic/storage/SynapticStoragePropertiesBuilder.java deleted file mode 100644 index 376e5b3da8..0000000000 --- a/providers/synaptic-storage/src/main/java/org/jclouds/synaptic/storage/SynapticStoragePropertiesBuilder.java +++ /dev/null @@ -1,53 +0,0 @@ -/** - * 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.synaptic.storage; - -import static org.jclouds.Constants.PROPERTY_API_VERSION; -import static org.jclouds.Constants.PROPERTY_ENDPOINT; -import static org.jclouds.Constants.PROPERTY_ISO3166_CODES; - -import java.util.Properties; - -import org.jclouds.PropertiesBuilder; - -/** - * Builds properties used in Atmos Clients - * - * @author Adrian Cole - */ -public class SynapticStoragePropertiesBuilder extends PropertiesBuilder { - - @Override - protected Properties defaultProperties() { - Properties properties = super.defaultProperties(); - properties.setProperty(PROPERTY_ENDPOINT, "https://storage.synaptic.att.com"); - properties.setProperty(PROPERTY_ISO3166_CODES, "US-VA,US-TX"); - properties.setProperty(PROPERTY_API_VERSION, "1.3.0"); - return properties; - } - - public SynapticStoragePropertiesBuilder() { - super(); - } - - public SynapticStoragePropertiesBuilder(Properties properties) { - super(properties); - } - -} diff --git a/providers/synaptic-storage/src/main/java/org/jclouds/synaptic/storage/SynapticStorageProviderMetadata.java b/providers/synaptic-storage/src/main/java/org/jclouds/synaptic/storage/SynapticStorageProviderMetadata.java index fdd007508b..f472292fc4 100644 --- a/providers/synaptic-storage/src/main/java/org/jclouds/synaptic/storage/SynapticStorageProviderMetadata.java +++ b/providers/synaptic-storage/src/main/java/org/jclouds/synaptic/storage/SynapticStorageProviderMetadata.java @@ -1,27 +1,14 @@ -/** - * 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.synaptic.storage; import java.net.URI; +import java.util.Properties; import org.jclouds.atmos.AtmosApiMetadata; -import org.jclouds.providers.BaseProviderMetadata; +import org.jclouds.atmos.AtmosAsyncClient; +import org.jclouds.atmos.AtmosClient; +import org.jclouds.blobstore.BlobStoreContext; +import org.jclouds.providers.ProviderMetadata; +import org.jclouds.providers.internal.BaseProviderMetadata; /** * Implementation of {@link org.jclouds.types.ProviderMetadata} for AT&T's @@ -29,39 +16,53 @@ import org.jclouds.providers.BaseProviderMetadata; * * @author Jeremy Whitlock */ -public class SynapticStorageProviderMetadata extends BaseProviderMetadata { - - public SynapticStorageProviderMetadata() { - this(builder() - .id("synaptic-storage") - .name("AT&T Synaptic Storage") - .api(new AtmosApiMetadata()) - .homepage(URI.create("https://www.synaptic.att.com/")) - .console(URI.create("https://www.synaptic.att.com/clouduser/login.htm")) - .iso3166Codes("US-VA", "US-TX")); +public class SynapticStorageProviderMetadata extends BaseProviderMetadata, AtmosApiMetadata> { + + public static Builder builder() { + return new Builder(); } - // below are so that we can reuse builders, toString, hashCode, etc. - // we have to set concrete classes here, as our base class cannot be - // concrete due to serviceLoader - protected SynapticStorageProviderMetadata(ConcreteBuilder builder) { + @Override + public Builder toBuilder() { + return builder().fromProviderMetadata(this); + } + + public SynapticStorageProviderMetadata() { + super(builder()); + } + + public SynapticStorageProviderMetadata(Builder builder) { super(builder); } - private static class ConcreteBuilder extends Builder { + protected static Properties defaultProperties() { + Properties properties = new Properties(); + return properties; + } + + public static class Builder extends BaseProviderMetadata.Builder, AtmosApiMetadata> { + + protected Builder(){ + id("synaptic-storage") + .name("AT&T Synaptic Storage") + .apiMetadata(new AtmosApiMetadata()) + .homepage(URI.create("https://www.synaptic.att.com/")) + .console(URI.create("https://www.synaptic.att.com/clouduser/login.htm")) + .iso3166Codes("US-VA", "US-TX") + .endpoint("https://storage.synaptic.att.com") + .defaultProperties(SynapticStorageProviderMetadata.defaultProperties()); + } @Override public SynapticStorageProviderMetadata build() { return new SynapticStorageProviderMetadata(this); } + + @Override + public Builder fromProviderMetadata( + ProviderMetadata, AtmosApiMetadata> in) { + super.fromProviderMetadata(in); + return this; + } } - - public static ConcreteBuilder builder() { - return new ConcreteBuilder(); - } - - public ConcreteBuilder toBuilder() { - return builder().fromProviderMetadata(this); - } - } \ No newline at end of file diff --git a/providers/synaptic-storage/src/test/java/org/jclouds/synaptic/storage/SynapticStorageProviderTest.java b/providers/synaptic-storage/src/test/java/org/jclouds/synaptic/storage/SynapticStorageProviderTest.java index be9da98de9..c25618c383 100644 --- a/providers/synaptic-storage/src/test/java/org/jclouds/synaptic/storage/SynapticStorageProviderTest.java +++ b/providers/synaptic-storage/src/test/java/org/jclouds/synaptic/storage/SynapticStorageProviderTest.java @@ -19,7 +19,7 @@ package org.jclouds.synaptic.storage; import org.jclouds.atmos.AtmosApiMetadata; -import org.jclouds.providers.BaseProviderMetadataTest; +import org.jclouds.providers.internal.BaseProviderMetadataTest; import org.testng.annotations.Test; /** diff --git a/providers/synaptic-storage/src/test/java/org/jclouds/synaptic/storage/blobstore/integration/SynapticStorageBlobIntegrationLiveTest.java b/providers/synaptic-storage/src/test/java/org/jclouds/synaptic/storage/blobstore/integration/SynapticStorageBlobIntegrationLiveTest.java index 4a1963ba4c..f16204905c 100644 --- a/providers/synaptic-storage/src/test/java/org/jclouds/synaptic/storage/blobstore/integration/SynapticStorageBlobIntegrationLiveTest.java +++ b/providers/synaptic-storage/src/test/java/org/jclouds/synaptic/storage/blobstore/integration/SynapticStorageBlobIntegrationLiveTest.java @@ -27,4 +27,7 @@ import org.testng.annotations.Test; @Test(groups = "live", testName = "SynapticStorageBlobIntegrationLiveTest") public class SynapticStorageBlobIntegrationLiveTest extends AtmosIntegrationLiveTest { + public SynapticStorageBlobIntegrationLiveTest() { + provider = "synaptic-storage"; + } } diff --git a/providers/synaptic-storage/src/test/java/org/jclouds/synaptic/storage/blobstore/integration/SynapticStorageBlobLiveTest.java b/providers/synaptic-storage/src/test/java/org/jclouds/synaptic/storage/blobstore/integration/SynapticStorageBlobLiveTest.java index 715ad8124b..8a259d5d55 100644 --- a/providers/synaptic-storage/src/test/java/org/jclouds/synaptic/storage/blobstore/integration/SynapticStorageBlobLiveTest.java +++ b/providers/synaptic-storage/src/test/java/org/jclouds/synaptic/storage/blobstore/integration/SynapticStorageBlobLiveTest.java @@ -27,4 +27,7 @@ import org.testng.annotations.Test; @Test(groups = "live", testName = "SynapticStorageBlobLiveTest") public class SynapticStorageBlobLiveTest extends AtmosLiveTest { + public SynapticStorageBlobLiveTest() { + provider = "synaptic-storage"; + } } diff --git a/providers/synaptic-storage/src/test/java/org/jclouds/synaptic/storage/blobstore/integration/SynapticStorageBlobMapIntegrationLiveTest.java b/providers/synaptic-storage/src/test/java/org/jclouds/synaptic/storage/blobstore/integration/SynapticStorageBlobMapIntegrationLiveTest.java index fbd02dbe4c..c616b88cfe 100644 --- a/providers/synaptic-storage/src/test/java/org/jclouds/synaptic/storage/blobstore/integration/SynapticStorageBlobMapIntegrationLiveTest.java +++ b/providers/synaptic-storage/src/test/java/org/jclouds/synaptic/storage/blobstore/integration/SynapticStorageBlobMapIntegrationLiveTest.java @@ -27,4 +27,7 @@ import org.testng.annotations.Test; @Test(groups = "live", testName = "SynapticStorageBlobMapIntegrationLiveTest") public class SynapticStorageBlobMapIntegrationLiveTest extends AtmosMapIntegrationLiveTest { + public SynapticStorageBlobMapIntegrationLiveTest() { + provider = "synaptic-storage"; + } } diff --git a/providers/synaptic-storage/src/test/java/org/jclouds/synaptic/storage/blobstore/integration/SynapticStorageBlobSignerLiveTest.java b/providers/synaptic-storage/src/test/java/org/jclouds/synaptic/storage/blobstore/integration/SynapticStorageBlobSignerLiveTest.java index 5aeeacee60..940e67afe1 100644 --- a/providers/synaptic-storage/src/test/java/org/jclouds/synaptic/storage/blobstore/integration/SynapticStorageBlobSignerLiveTest.java +++ b/providers/synaptic-storage/src/test/java/org/jclouds/synaptic/storage/blobstore/integration/SynapticStorageBlobSignerLiveTest.java @@ -28,4 +28,7 @@ import org.testng.annotations.Test; @Test(groups = "live", testName = "SynapticStorageBlobSignerLiveTest") public class SynapticStorageBlobSignerLiveTest extends AtmosBlobSignerLiveTest { + public SynapticStorageBlobSignerLiveTest() { + provider = "synaptic-storage"; + } } diff --git a/providers/synaptic-storage/src/test/java/org/jclouds/synaptic/storage/blobstore/integration/SynapticStorageContainerIntegrationLiveTest.java b/providers/synaptic-storage/src/test/java/org/jclouds/synaptic/storage/blobstore/integration/SynapticStorageContainerIntegrationLiveTest.java index 5e0666f102..f8fbd636fa 100644 --- a/providers/synaptic-storage/src/test/java/org/jclouds/synaptic/storage/blobstore/integration/SynapticStorageContainerIntegrationLiveTest.java +++ b/providers/synaptic-storage/src/test/java/org/jclouds/synaptic/storage/blobstore/integration/SynapticStorageContainerIntegrationLiveTest.java @@ -27,4 +27,7 @@ import org.testng.annotations.Test; @Test(groups = "live", testName = "SynapticStorageContainerIntegrationLiveTest") public class SynapticStorageContainerIntegrationLiveTest extends AtmosContainerIntegrationLiveTest { + public SynapticStorageContainerIntegrationLiveTest() { + provider = "synaptic-storage"; + } } diff --git a/providers/synaptic-storage/src/test/java/org/jclouds/synaptic/storage/blobstore/integration/SynapticStorageContainerLiveTest.java b/providers/synaptic-storage/src/test/java/org/jclouds/synaptic/storage/blobstore/integration/SynapticStorageContainerLiveTest.java index a1fc00c54d..52a590f7f9 100644 --- a/providers/synaptic-storage/src/test/java/org/jclouds/synaptic/storage/blobstore/integration/SynapticStorageContainerLiveTest.java +++ b/providers/synaptic-storage/src/test/java/org/jclouds/synaptic/storage/blobstore/integration/SynapticStorageContainerLiveTest.java @@ -27,4 +27,7 @@ import org.testng.annotations.Test; @Test(groups = "live", testName = "SynapticStorageContainerLiveTest") public class SynapticStorageContainerLiveTest extends AtmosContainerLiveTest { + public SynapticStorageContainerLiveTest() { + provider = "synaptic-storage"; + } } diff --git a/providers/synaptic-storage/src/test/java/org/jclouds/synaptic/storage/blobstore/integration/SynapticStorageInputStreamMapIntegrationLiveTest.java b/providers/synaptic-storage/src/test/java/org/jclouds/synaptic/storage/blobstore/integration/SynapticStorageInputStreamMapIntegrationLiveTest.java index c9d8c7590c..272cf4a374 100644 --- a/providers/synaptic-storage/src/test/java/org/jclouds/synaptic/storage/blobstore/integration/SynapticStorageInputStreamMapIntegrationLiveTest.java +++ b/providers/synaptic-storage/src/test/java/org/jclouds/synaptic/storage/blobstore/integration/SynapticStorageInputStreamMapIntegrationLiveTest.java @@ -27,4 +27,7 @@ import org.testng.annotations.Test; @Test(groups = "live", testName = "SynapticStorageInputStreamMapIntegrationLiveTest") public class SynapticStorageInputStreamMapIntegrationLiveTest extends AtmosInputStreamMapIntegrationLiveTest { + public SynapticStorageInputStreamMapIntegrationLiveTest() { + provider = "synaptic-storage"; + } } diff --git a/providers/synaptic-storage/src/test/java/org/jclouds/synaptic/storage/blobstore/integration/SynapticStorageServiceIntegrationLiveTest.java b/providers/synaptic-storage/src/test/java/org/jclouds/synaptic/storage/blobstore/integration/SynapticStorageServiceIntegrationLiveTest.java index a0ae41b64b..179bea88ff 100644 --- a/providers/synaptic-storage/src/test/java/org/jclouds/synaptic/storage/blobstore/integration/SynapticStorageServiceIntegrationLiveTest.java +++ b/providers/synaptic-storage/src/test/java/org/jclouds/synaptic/storage/blobstore/integration/SynapticStorageServiceIntegrationLiveTest.java @@ -30,6 +30,11 @@ import com.google.common.collect.ImmutableSet; */ @Test(groups = "live", testName = "SynapticStorageServiceIntegrationLiveTest") public class SynapticStorageServiceIntegrationLiveTest extends AtmosServiceIntegrationLiveTest { + + public SynapticStorageServiceIntegrationLiveTest() { + provider = "synaptic-storage"; + } + @Override protected Set getIso3166Codes() { return ImmutableSet. of("US-VA", "US-TX"); diff --git a/providers/synaptic-storage/src/test/java/org/jclouds/synaptic/storage/blobstore/integration/SynapticStorageTestInitializer.java b/providers/synaptic-storage/src/test/java/org/jclouds/synaptic/storage/blobstore/integration/SynapticStorageTestInitializer.java deleted file mode 100644 index d8ebf06092..0000000000 --- a/providers/synaptic-storage/src/test/java/org/jclouds/synaptic/storage/blobstore/integration/SynapticStorageTestInitializer.java +++ /dev/null @@ -1,33 +0,0 @@ -/** - * 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.synaptic.storage.blobstore.integration; - -import org.jclouds.atmos.blobstore.integration.AtmosTestInitializer; - -/** - * - * @author Adrian Cole - */ -public class SynapticStorageTestInitializer extends AtmosTestInitializer { - - public SynapticStorageTestInitializer() { - provider = "synaptic-storage"; - } - -} diff --git a/providers/trmk-ecloud/src/main/java/org/jclouds/trmk/ecloud/TerremarkECloudApiMetadata.java b/providers/trmk-ecloud/src/main/java/org/jclouds/trmk/ecloud/TerremarkECloudApiMetadata.java index 77b324a1fd..dfae1bf49f 100644 --- a/providers/trmk-ecloud/src/main/java/org/jclouds/trmk/ecloud/TerremarkECloudApiMetadata.java +++ b/providers/trmk-ecloud/src/main/java/org/jclouds/trmk/ecloud/TerremarkECloudApiMetadata.java @@ -1,50 +1,69 @@ package org.jclouds.trmk.ecloud; +import static org.jclouds.trmk.vcloud_0_8.reference.TerremarkConstants.PROPERTY_TERREMARK_EXTENSION_NAME; +import static org.jclouds.trmk.vcloud_0_8.reference.TerremarkConstants.PROPERTY_TERREMARK_EXTENSION_VERSION; + import java.net.URI; +import java.util.Properties; import org.jclouds.apis.ApiMetadata; -import org.jclouds.apis.ApiType; -import org.jclouds.apis.BaseApiMetadata; +import org.jclouds.trmk.vcloud_0_8.internal.TerremarkVCloudApiMetadata; + +import com.google.common.reflect.TypeToken; /** * Implementation of {@link ApiMetadata} for Terremark eCloud v2.8 API * * @author Adrian Cole */ -public class TerremarkECloudApiMetadata extends BaseApiMetadata { +public class TerremarkECloudApiMetadata extends + TerremarkVCloudApiMetadata { - public TerremarkECloudApiMetadata() { - this(builder() - .id("trmk-ecloud") - .type(ApiType.COMPUTE) - .name("Terremark Enterprise Cloud v2.8 API") - .identityName("Email") - .credentialName("Password") - .documentation(URI.create("http://support.theenterprisecloud.com/kb/default.asp?id=533&Lang=1&SID="))); + @Override + public Builder toBuilder() { + return new Builder().fromApiMetadata(this); } - // below are so that we can reuse builders, toString, hashCode, etc. - // we have to set concrete classes here, as our base class cannot be - // concrete due to serviceLoader - protected TerremarkECloudApiMetadata(Builder builder) { + public TerremarkECloudApiMetadata() { + this(new Builder()); + } + + protected TerremarkECloudApiMetadata(Builder builder) { super(builder); } - private static class ConcreteBuilder extends Builder { + protected static Properties defaultProperties() { + Properties properties = TerremarkVCloudApiMetadata.defaultProperties(); + properties.setProperty(PROPERTY_TERREMARK_EXTENSION_NAME, "eCloudExtensions"); + properties.setProperty(PROPERTY_TERREMARK_EXTENSION_VERSION, "2.8"); + return properties; + } + + public static class Builder + extends + TerremarkVCloudApiMetadata.Builder { + + protected Builder() { + super(TerremarkECloudClient.class, TerremarkECloudAsyncClient.class); + id("trmk-ecloud") + .name("Terremark Enterprise Cloud v2.8 API") + .version("0.8b-ext2.8") + .defaultProperties(TerremarkECloudApiMetadata.defaultProperties()) + .defaultEndpoint("https://services.enterprisecloud.terremark.com/api") + .contextBuilder(TypeToken.of(TerremarkECloudContextBuilder.class)) + .documentation(URI.create("http://support.theenterprisecloud.com/kb/default.asp?id=533&Lang=1&SID=")); + } @Override public TerremarkECloudApiMetadata build() { return new TerremarkECloudApiMetadata(this); } - } - public static ConcreteBuilder builder() { - return new ConcreteBuilder(); - } - - @Override - public ConcreteBuilder toBuilder() { - return builder().fromApiMetadata(this); + @Override + public Builder fromApiMetadata(TerremarkECloudApiMetadata in) { + super.fromApiMetadata(in); + return this; + } } } \ No newline at end of file diff --git a/providers/trmk-ecloud/src/main/java/org/jclouds/trmk/ecloud/TerremarkECloudContextBuilder.java b/providers/trmk-ecloud/src/main/java/org/jclouds/trmk/ecloud/TerremarkECloudContextBuilder.java index 852e1f9b67..da4b9fe1bd 100644 --- a/providers/trmk-ecloud/src/main/java/org/jclouds/trmk/ecloud/TerremarkECloudContextBuilder.java +++ b/providers/trmk-ecloud/src/main/java/org/jclouds/trmk/ecloud/TerremarkECloudContextBuilder.java @@ -19,10 +19,11 @@ package org.jclouds.trmk.ecloud; import java.util.List; -import java.util.Properties; +import org.jclouds.compute.ComputeServiceContext; import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule; import org.jclouds.logging.jdk.config.JDKLoggingModule; +import org.jclouds.providers.ProviderMetadata; import org.jclouds.trmk.ecloud.compute.config.TerremarkECloudComputeServiceContextModule; import org.jclouds.trmk.ecloud.config.TerremarkECloudRestClientModule; import org.jclouds.trmk.vcloud_0_8.TerremarkVCloudContextBuilder; @@ -46,11 +47,20 @@ import com.google.inject.Module; * @author Adrian Cole * @see TerremarkVCloudComputeServiceContext */ -public class TerremarkECloudContextBuilder extends - TerremarkVCloudContextBuilder { +public class TerremarkECloudContextBuilder + extends + TerremarkVCloudContextBuilder, TerremarkECloudApiMetadata> { + public TerremarkECloudContextBuilder() { + this(new TerremarkECloudProviderMetadata()); + } - public TerremarkECloudContextBuilder(Properties props) { - super(TerremarkECloudClient.class, TerremarkECloudAsyncClient.class, props); + public TerremarkECloudContextBuilder( + ProviderMetadata, TerremarkECloudApiMetadata> providerMetadata) { + super(providerMetadata); + } + + public TerremarkECloudContextBuilder(TerremarkECloudApiMetadata apiMetadata) { + super(apiMetadata); } @Override diff --git a/providers/trmk-ecloud/src/main/java/org/jclouds/trmk/ecloud/TerremarkECloudPropertiesBuilder.java b/providers/trmk-ecloud/src/main/java/org/jclouds/trmk/ecloud/TerremarkECloudPropertiesBuilder.java deleted file mode 100644 index 1af1db6eaa..0000000000 --- a/providers/trmk-ecloud/src/main/java/org/jclouds/trmk/ecloud/TerremarkECloudPropertiesBuilder.java +++ /dev/null @@ -1,52 +0,0 @@ -/** - * 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.trmk.ecloud; - -import static org.jclouds.Constants.PROPERTY_API_VERSION; -import static org.jclouds.Constants.PROPERTY_ENDPOINT; -import static org.jclouds.Constants.PROPERTY_ISO3166_CODES; -import static org.jclouds.trmk.vcloud_0_8.reference.TerremarkConstants.PROPERTY_TERREMARK_EXTENSION_NAME; -import static org.jclouds.trmk.vcloud_0_8.reference.TerremarkConstants.PROPERTY_TERREMARK_EXTENSION_VERSION; - -import java.util.Properties; - -import org.jclouds.trmk.vcloud_0_8.TerremarkVCloudPropertiesBuilder; - -/** - * Builds properties used in Terremark VCloud Clients - * - * @author Adrian Cole - */ -public class TerremarkECloudPropertiesBuilder extends TerremarkVCloudPropertiesBuilder { - @Override - protected Properties defaultProperties() { - Properties properties = super.defaultProperties(); - properties.setProperty(PROPERTY_ISO3166_CODES, "US-FL,US-VA,NL-NH,BR-SP"); - properties.setProperty(PROPERTY_API_VERSION, "0.8b-ext2.8"); - properties.setProperty(PROPERTY_ENDPOINT, "https://services.enterprisecloud.terremark.com/api"); - properties.setProperty(PROPERTY_TERREMARK_EXTENSION_NAME, "eCloudExtensions"); - properties.setProperty(PROPERTY_TERREMARK_EXTENSION_VERSION, "2.8"); - return properties; - } - - public TerremarkECloudPropertiesBuilder(Properties properties) { - super(properties); - } - -} diff --git a/providers/trmk-ecloud/src/main/java/org/jclouds/trmk/ecloud/TerremarkECloudProviderMetadata.java b/providers/trmk-ecloud/src/main/java/org/jclouds/trmk/ecloud/TerremarkECloudProviderMetadata.java index 2cb542fa6d..e1c562ea88 100644 --- a/providers/trmk-ecloud/src/main/java/org/jclouds/trmk/ecloud/TerremarkECloudProviderMetadata.java +++ b/providers/trmk-ecloud/src/main/java/org/jclouds/trmk/ecloud/TerremarkECloudProviderMetadata.java @@ -19,45 +19,64 @@ package org.jclouds.trmk.ecloud; import java.net.URI; +import java.util.Properties; -import org.jclouds.providers.BaseProviderMetadata; +import org.jclouds.compute.ComputeServiceContext; +import org.jclouds.providers.ProviderMetadata; +import org.jclouds.providers.internal.BaseProviderMetadata; /** * Implementation of {@link org.jclouds.types.ProviderMetadata} for Terremark's Enterprise Cloud. * * @author Adrian Cole */ -public class TerremarkECloudProviderMetadata extends BaseProviderMetadata { - public TerremarkECloudProviderMetadata() { - this(builder() - .id("trmk-ecloud") - .name("Terremark Enterprise Cloud v2.8") - .api(new TerremarkECloudApiMetadata()) - .homepage(URI.create("http://www.terremark.com/services/cloudcomputing/theenterprisecloud.aspx")) - .console(URI.create("https://icenter.digitalops.net")) - .iso3166Codes("US-FL", "US-VA", "NL-NH", "BR-SP")); +public class TerremarkECloudProviderMetadata extends BaseProviderMetadata, TerremarkECloudApiMetadata> { + + public static Builder builder() { + return new Builder(); } - // below are so that we can reuse builders, toString, hashCode, etc. - // we have to set concrete classes here, as our base class cannot be - // concrete due to serviceLoader - protected TerremarkECloudProviderMetadata(ConcreteBuilder builder) { + @Override + public Builder toBuilder() { + return builder().fromProviderMetadata(this); + } + + public TerremarkECloudProviderMetadata() { + super(builder()); + } + + public TerremarkECloudProviderMetadata(Builder builder) { super(builder); } - private static class ConcreteBuilder extends Builder { + protected static Properties defaultProperties() { + Properties properties = new Properties(); + return properties; + } + + public static class Builder extends BaseProviderMetadata.Builder, TerremarkECloudApiMetadata> { + + protected Builder(){ + id("trmk-ecloud") + .name("Terremark Enterprise Cloud v2.8") + .apiMetadata(new TerremarkECloudApiMetadata()) + .endpoint("https://services.enterprisecloud.terremark.com/api") + .homepage(URI.create("http://www.terremark.com/services/cloudcomputing/theenterprisecloud.aspx")) + .console(URI.create("https://icenter.digitalops.net")) + .iso3166Codes("US-FL", "US-VA", "NL-NH", "BR-SP"); + } @Override public TerremarkECloudProviderMetadata build() { return new TerremarkECloudProviderMetadata(this); } - } - public static ConcreteBuilder builder() { - return new ConcreteBuilder(); - } + @Override + public Builder fromProviderMetadata( + ProviderMetadata, TerremarkECloudApiMetadata> in) { + super.fromProviderMetadata(in); + return this; + } - public ConcreteBuilder toBuilder() { - return builder().fromProviderMetadata(this); } } \ No newline at end of file diff --git a/providers/trmk-ecloud/src/test/java/org/jclouds/trmk/ecloud/BaseTerremarkECloudAsyncClientTest.java b/providers/trmk-ecloud/src/test/java/org/jclouds/trmk/ecloud/BaseTerremarkECloudAsyncClientTest.java index 4047605529..c97038565f 100644 --- a/providers/trmk-ecloud/src/test/java/org/jclouds/trmk/ecloud/BaseTerremarkECloudAsyncClientTest.java +++ b/providers/trmk-ecloud/src/test/java/org/jclouds/trmk/ecloud/BaseTerremarkECloudAsyncClientTest.java @@ -23,7 +23,6 @@ import static org.testng.Assert.assertEquals; import java.net.URI; import java.util.Map; -import java.util.Properties; import java.util.concurrent.atomic.AtomicReference; import javax.inject.Inject; @@ -32,11 +31,10 @@ import javax.inject.Singleton; import org.jclouds.http.HttpRequest; import org.jclouds.http.RequiresHttp; +import org.jclouds.providers.ProviderMetadata; import org.jclouds.rest.AuthorizationException; import org.jclouds.rest.ConfiguresRestClient; -import org.jclouds.rest.RestClientTest; -import org.jclouds.rest.RestContextFactory; -import org.jclouds.rest.RestContextSpec; +import org.jclouds.rest.internal.BaseAsyncClientTest; import org.jclouds.trmk.ecloud.config.TerremarkECloudRestClientModule; import org.jclouds.trmk.ecloud.domain.internal.ECloudOrgImpl; import org.jclouds.trmk.vcloud_0_8.domain.Org; @@ -61,7 +59,7 @@ import com.google.inject.TypeLiteral; /** * @author Adrian Cole */ -public abstract class BaseTerremarkECloudAsyncClientTest extends RestClientTest { +public abstract class BaseTerremarkECloudAsyncClientTest extends BaseAsyncClientTest { @Override protected void checkFilters(HttpRequest request) { @@ -75,8 +73,8 @@ public abstract class BaseTerremarkECloudAsyncClientTest extends RestClientTe } @Override - public RestContextSpec createContextSpec() { - return new RestContextFactory().createContextSpec("trmk-ecloud", "identity", "credential", new Properties()); + public ProviderMetadata createProviderMetadata() { + return new TerremarkECloudProviderMetadata(); } protected static final ReferenceTypeImpl ORG_REF = new ReferenceTypeImpl("org", TerremarkECloudMediaType.ORG_XML, diff --git a/providers/trmk-ecloud/src/test/java/org/jclouds/trmk/ecloud/BaseTerremarkECloudClientLiveTest.java b/providers/trmk-ecloud/src/test/java/org/jclouds/trmk/ecloud/BaseTerremarkECloudClientLiveTest.java index 726a02d1e6..57d9e41f7f 100644 --- a/providers/trmk-ecloud/src/test/java/org/jclouds/trmk/ecloud/BaseTerremarkECloudClientLiveTest.java +++ b/providers/trmk-ecloud/src/test/java/org/jclouds/trmk/ecloud/BaseTerremarkECloudClientLiveTest.java @@ -28,7 +28,7 @@ import org.testng.annotations.Test; * @author Adrian Cole */ @Test(groups = "live", enabled = true, singleThreaded = true) -public class BaseTerremarkECloudClientLiveTest extends BaseTerremarkClientLiveTest { +public class BaseTerremarkECloudClientLiveTest extends BaseTerremarkClientLiveTest { @Override protected Properties setupProperties() { Properties props = super.setupProperties(); diff --git a/providers/trmk-ecloud/src/test/java/org/jclouds/trmk/ecloud/TerremarkECloudClientLiveTest.java b/providers/trmk-ecloud/src/test/java/org/jclouds/trmk/ecloud/TerremarkECloudClientLiveTest.java index 2baf7112a5..0c57ddd652 100644 --- a/providers/trmk-ecloud/src/test/java/org/jclouds/trmk/ecloud/TerremarkECloudClientLiveTest.java +++ b/providers/trmk-ecloud/src/test/java/org/jclouds/trmk/ecloud/TerremarkECloudClientLiveTest.java @@ -39,7 +39,7 @@ import org.testng.annotations.Test; * @author Adrian Cole */ @Test(groups = "live", enabled = true, singleThreaded = true, testName = "TerremarkECloudClientLiveTest") -public class TerremarkECloudClientLiveTest extends TerremarkClientLiveTest { +public class TerremarkECloudClientLiveTest extends TerremarkClientLiveTest { public TerremarkECloudClientLiveTest() { this.provider = "trmk-ecloud"; diff --git a/providers/trmk-ecloud/src/test/java/org/jclouds/trmk/ecloud/TerremarkECloudProviderTest.java b/providers/trmk-ecloud/src/test/java/org/jclouds/trmk/ecloud/TerremarkECloudProviderTest.java index e3b13fb7e3..54e2a28b66 100644 --- a/providers/trmk-ecloud/src/test/java/org/jclouds/trmk/ecloud/TerremarkECloudProviderTest.java +++ b/providers/trmk-ecloud/src/test/java/org/jclouds/trmk/ecloud/TerremarkECloudProviderTest.java @@ -18,7 +18,7 @@ */ package org.jclouds.trmk.ecloud; -import org.jclouds.providers.BaseProviderMetadataTest; +import org.jclouds.providers.internal.BaseProviderMetadataTest; import org.testng.annotations.Test; /** diff --git a/providers/trmk-ecloud/src/test/java/org/jclouds/trmk/ecloud/compute/TerremarkECloudComputeServiceLiveTest.java b/providers/trmk-ecloud/src/test/java/org/jclouds/trmk/ecloud/compute/TerremarkECloudComputeServiceLiveTest.java index 351be4df25..8ed4c60713 100644 --- a/providers/trmk-ecloud/src/test/java/org/jclouds/trmk/ecloud/compute/TerremarkECloudComputeServiceLiveTest.java +++ b/providers/trmk-ecloud/src/test/java/org/jclouds/trmk/ecloud/compute/TerremarkECloudComputeServiceLiveTest.java @@ -22,8 +22,7 @@ import static org.testng.Assert.assertEquals; import java.util.Properties; -import org.jclouds.compute.BaseComputeServiceLiveTest; -import org.jclouds.compute.ComputeServiceContextFactory; +import org.jclouds.compute.ComputeServiceContext; import org.jclouds.compute.domain.ComputeMetadata; import org.jclouds.compute.domain.ComputeType; import org.jclouds.compute.domain.Image; @@ -31,9 +30,11 @@ import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.domain.OsFamily; import org.jclouds.compute.domain.Template; import org.jclouds.compute.domain.TemplateBuilder; +import org.jclouds.compute.internal.BaseComputeServiceLiveTest; import org.jclouds.rest.RestContext; import org.jclouds.sshj.config.SshjSshClientModule; -import org.jclouds.trmk.vcloud_0_8.TerremarkVCloudClient; +import org.jclouds.trmk.ecloud.TerremarkECloudAsyncClient; +import org.jclouds.trmk.ecloud.TerremarkECloudClient; import org.jclouds.trmk.vcloud_0_8.domain.VApp; import org.jclouds.trmk.vcloud_0_8.reference.VCloudConstants; import org.testng.annotations.Test; @@ -48,7 +49,9 @@ import com.google.inject.Module; * @author Adrian Cole */ @Test(groups = "live", enabled = true, singleThreaded = true) -public class TerremarkECloudComputeServiceLiveTest extends BaseComputeServiceLiveTest { +public class TerremarkECloudComputeServiceLiveTest + extends + BaseComputeServiceLiveTest> { @Override protected Properties setupProperties() { @@ -104,10 +107,9 @@ public class TerremarkECloudComputeServiceLiveTest extends BaseComputeServiceLiv assert node.getLocation() != null; assertEquals(node.getType(), ComputeType.NODE); NodeMetadata allData = client.getNodeMetadata(node.getId()); - RestContext tmContext = new ComputeServiceContextFactory() - .createContext(provider, identity, credential).getProviderSpecificContext(); + RestContext tmContext = context.getProviderSpecificContext(); VApp vApp = tmContext.getApi().findVAppInOrgVDCNamed(allData.getLocation().getParent().getDescription(), - allData.getLocation().getDescription(), allData.getName()); + allData.getLocation().getDescription(), allData.getName()); assertEquals(vApp.getName(), allData.getName()); } } diff --git a/providers/trmk-ecloud/src/test/java/org/jclouds/trmk/ecloud/compute/TerremarkECloudTemplateBuilderLiveTest.java b/providers/trmk-ecloud/src/test/java/org/jclouds/trmk/ecloud/compute/TerremarkECloudTemplateBuilderLiveTest.java index 0e25edcde9..2426a7d444 100644 --- a/providers/trmk-ecloud/src/test/java/org/jclouds/trmk/ecloud/compute/TerremarkECloudTemplateBuilderLiveTest.java +++ b/providers/trmk-ecloud/src/test/java/org/jclouds/trmk/ecloud/compute/TerremarkECloudTemplateBuilderLiveTest.java @@ -25,10 +25,13 @@ import java.io.IOException; import java.util.Properties; import java.util.Set; -import org.jclouds.compute.BaseTemplateBuilderLiveTest; +import org.jclouds.compute.ComputeServiceContext; import org.jclouds.compute.domain.OsFamily; import org.jclouds.compute.domain.OsFamilyVersion64Bit; import org.jclouds.compute.domain.Template; +import org.jclouds.compute.internal.BaseTemplateBuilderLiveTest; +import org.jclouds.trmk.ecloud.TerremarkECloudAsyncClient; +import org.jclouds.trmk.ecloud.TerremarkECloudClient; import org.jclouds.trmk.vcloud_0_8.reference.VCloudConstants; import org.testng.annotations.Test; @@ -40,7 +43,9 @@ import com.google.common.collect.ImmutableSet; * @author Adrian Cole */ @Test(groups = "live") -public class TerremarkECloudTemplateBuilderLiveTest extends BaseTemplateBuilderLiveTest { +public class TerremarkECloudTemplateBuilderLiveTest + extends + BaseTemplateBuilderLiveTest> { @Override protected Properties setupProperties() { Properties props = super.setupProperties(); diff --git a/providers/trmk-vcloudexpress/src/main/java/org/jclouds/trmk/vcloudexpress/TerremarkVCloudExpressApiMetadata.java b/providers/trmk-vcloudexpress/src/main/java/org/jclouds/trmk/vcloudexpress/TerremarkVCloudExpressApiMetadata.java index 8362bd989d..605a93fc10 100644 --- a/providers/trmk-vcloudexpress/src/main/java/org/jclouds/trmk/vcloudexpress/TerremarkVCloudExpressApiMetadata.java +++ b/providers/trmk-vcloudexpress/src/main/java/org/jclouds/trmk/vcloudexpress/TerremarkVCloudExpressApiMetadata.java @@ -1,50 +1,89 @@ +/** + * 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.trmk.vcloudexpress; +import static org.jclouds.trmk.vcloud_0_8.reference.TerremarkConstants.PROPERTY_TERREMARK_EXTENSION_NAME; +import static org.jclouds.trmk.vcloud_0_8.reference.TerremarkConstants.PROPERTY_TERREMARK_EXTENSION_VERSION; + import java.net.URI; +import java.util.Properties; import org.jclouds.apis.ApiMetadata; -import org.jclouds.apis.ApiType; -import org.jclouds.apis.BaseApiMetadata; +import org.jclouds.trmk.vcloud_0_8.internal.TerremarkVCloudApiMetadata; + +import com.google.common.reflect.TypeToken; /** * Implementation of {@link ApiMetadata} for the Terremark vCloud Express API * * @author Adrian Cole */ -public class TerremarkVCloudExpressApiMetadata extends BaseApiMetadata { +public class TerremarkVCloudExpressApiMetadata extends + TerremarkVCloudApiMetadata { - public TerremarkVCloudExpressApiMetadata() { - this(builder() - .id("trmk-vcloudexpress") - .type(ApiType.COMPUTE) - .name("Terremark vCloud Express API") - .identityName("Email") - .credentialName("Password") - .documentation(URI.create("https://community.vcloudexpress.terremark.com/en-us/product_docs/m/vcefiles/2342.aspx"))); + @Override + public Builder toBuilder() { + return new Builder().fromApiMetadata(this); } - // below are so that we can reuse builders, toString, hashCode, etc. - // we have to set concrete classes here, as our base class cannot be - // concrete due to serviceLoader - protected TerremarkVCloudExpressApiMetadata(Builder builder) { + public TerremarkVCloudExpressApiMetadata() { + this(new Builder()); + } + + protected TerremarkVCloudExpressApiMetadata(Builder builder) { super(builder); } - private static class ConcreteBuilder extends Builder { + protected static Properties defaultProperties() { + Properties properties = TerremarkVCloudApiMetadata.defaultProperties(); + properties.setProperty(PROPERTY_TERREMARK_EXTENSION_NAME, "vCloudExpressExtensions"); + properties.setProperty(PROPERTY_TERREMARK_EXTENSION_VERSION, "1.6"); + return properties; + } + + public static class Builder + extends + TerremarkVCloudApiMetadata.Builder { + + protected Builder() { + super(TerremarkVCloudExpressClient.class, TerremarkVCloudExpressAsyncClient.class); + id("trmk-vcloudexpress") + .name("Terremark vCloud Express API") + .identityName("Email") + .credentialName("Password") + .defaultProperties(TerremarkVCloudExpressApiMetadata.defaultProperties()) + .defaultEndpoint("https://services.vcloudexpress.terremark.com/api") + .defaultProperties(TerremarkVCloudExpressApiMetadata.defaultProperties()) + .contextBuilder(TypeToken.of(TerremarkVCloudExpressContextBuilder.class)) + .documentation(URI.create("https://community.vcloudexpress.terremark.com/en-us/product_docs/m/vcefiles/2342.aspx")); + } @Override public TerremarkVCloudExpressApiMetadata build() { return new TerremarkVCloudExpressApiMetadata(this); } - } - public static ConcreteBuilder builder() { - return new ConcreteBuilder(); - } - - @Override - public ConcreteBuilder toBuilder() { - return builder().fromApiMetadata(this); + @Override + public Builder fromApiMetadata(TerremarkVCloudExpressApiMetadata in) { + super.fromApiMetadata(in); + return this; + } } } \ No newline at end of file diff --git a/providers/trmk-vcloudexpress/src/main/java/org/jclouds/trmk/vcloudexpress/TerremarkVCloudExpressContextBuilder.java b/providers/trmk-vcloudexpress/src/main/java/org/jclouds/trmk/vcloudexpress/TerremarkVCloudExpressContextBuilder.java index 4b85951359..6a365fbbaa 100644 --- a/providers/trmk-vcloudexpress/src/main/java/org/jclouds/trmk/vcloudexpress/TerremarkVCloudExpressContextBuilder.java +++ b/providers/trmk-vcloudexpress/src/main/java/org/jclouds/trmk/vcloudexpress/TerremarkVCloudExpressContextBuilder.java @@ -19,10 +19,11 @@ package org.jclouds.trmk.vcloudexpress; import java.util.List; -import java.util.Properties; +import org.jclouds.compute.ComputeServiceContext; import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule; import org.jclouds.logging.jdk.config.JDKLoggingModule; +import org.jclouds.providers.ProviderMetadata; import org.jclouds.trmk.vcloud_0_8.TerremarkVCloudContextBuilder; import org.jclouds.trmk.vcloudexpress.compute.TerremarkVCloudExpressComputeServiceContextModule; import org.jclouds.trmk.vcloudexpress.config.TerremarkVCloudExpressRestClientModule; @@ -46,11 +47,20 @@ import com.google.inject.Module; * @author Adrian Cole * @see TerremarkVCloudComputeServiceContext */ -public class TerremarkVCloudExpressContextBuilder extends - TerremarkVCloudContextBuilder { +public class TerremarkVCloudExpressContextBuilder + extends + TerremarkVCloudContextBuilder, TerremarkVCloudExpressApiMetadata> { + public TerremarkVCloudExpressContextBuilder() { + this(new TerremarkVCloudExpressProviderMetadata()); + } - public TerremarkVCloudExpressContextBuilder(Properties props) { - super(TerremarkVCloudExpressClient.class, TerremarkVCloudExpressAsyncClient.class, props); + public TerremarkVCloudExpressContextBuilder( + ProviderMetadata, TerremarkVCloudExpressApiMetadata> providerMetadata) { + super(providerMetadata); + } + + public TerremarkVCloudExpressContextBuilder(TerremarkVCloudExpressApiMetadata apiMetadata) { + super(apiMetadata); } @Override diff --git a/providers/trmk-vcloudexpress/src/main/java/org/jclouds/trmk/vcloudexpress/TerremarkVCloudExpressProviderMetadata.java b/providers/trmk-vcloudexpress/src/main/java/org/jclouds/trmk/vcloudexpress/TerremarkVCloudExpressProviderMetadata.java index a9a58ddf22..a36e53a0d8 100644 --- a/providers/trmk-vcloudexpress/src/main/java/org/jclouds/trmk/vcloudexpress/TerremarkVCloudExpressProviderMetadata.java +++ b/providers/trmk-vcloudexpress/src/main/java/org/jclouds/trmk/vcloudexpress/TerremarkVCloudExpressProviderMetadata.java @@ -19,46 +19,65 @@ package org.jclouds.trmk.vcloudexpress; import java.net.URI; +import java.util.Properties; -import org.jclouds.providers.BaseProviderMetadata; +import org.jclouds.compute.ComputeServiceContext; +import org.jclouds.providers.ProviderMetadata; +import org.jclouds.providers.internal.BaseProviderMetadata; /** - * Implementation of {@link org.jclouds.types.ProviderMetadata} for Terremark's vCloud Express. + * Implementation of {@link org.jclouds.types.ProviderMetadata} for Terremark's Enterprise Cloud. * * @author Adrian Cole */ -public class TerremarkVCloudExpressProviderMetadata extends BaseProviderMetadata { - public TerremarkVCloudExpressProviderMetadata() { - this(builder() - .id("trmk-vcloudexpress") - .name("Terremark vCloud Express") - .api(new TerremarkVCloudExpressApiMetadata()) - .homepage(URI.create("https://vcloudexpress.terremark.com/")) - .console(URI.create("https://my.vcloudexpress.terremark.com")) - .iso3166Codes("US-FL")); +public class TerremarkVCloudExpressProviderMetadata extends BaseProviderMetadata, TerremarkVCloudExpressApiMetadata> { + + public static Builder builder() { + return new Builder(); } - // below are so that we can reuse builders, toString, hashCode, etc. - // we have to set concrete classes here, as our base class cannot be - // concrete due to serviceLoader - protected TerremarkVCloudExpressProviderMetadata(ConcreteBuilder builder) { + @Override + public Builder toBuilder() { + return builder().fromProviderMetadata(this); + } + + public TerremarkVCloudExpressProviderMetadata() { + super(builder()); + } + + public TerremarkVCloudExpressProviderMetadata(Builder builder) { super(builder); } - private static class ConcreteBuilder extends Builder { + protected static Properties defaultProperties() { + Properties properties = new Properties(); + return properties; + } + + public static class Builder extends BaseProviderMetadata.Builder, TerremarkVCloudExpressApiMetadata> { + + protected Builder(){ + id("trmk-vcloudexpress") + .name("Terremark vCloud Express") + .apiMetadata(new TerremarkVCloudExpressApiMetadata()) + .endpoint("https://services.vcloudexpress.terremark.com/api") + .homepage(URI.create("https://vcloudexpress.terremark.com/")) + .console(URI.create("https://my.vcloudexpress.terremark.com")) + .iso3166Codes("US-FL") + .defaultProperties(TerremarkVCloudExpressProviderMetadata.defaultProperties()); + } @Override public TerremarkVCloudExpressProviderMetadata build() { return new TerremarkVCloudExpressProviderMetadata(this); } - } - public static ConcreteBuilder builder() { - return new ConcreteBuilder(); - } + @Override + public Builder fromProviderMetadata( + ProviderMetadata, TerremarkVCloudExpressApiMetadata> in) { + super.fromProviderMetadata(in); + return this; + } - public ConcreteBuilder toBuilder() { - return builder().fromProviderMetadata(this); } - } \ No newline at end of file diff --git a/providers/trmk-vcloudexpress/src/test/java/org/jclouds/trmk/vcloudexpress/InternetServiceLiveTest.java b/providers/trmk-vcloudexpress/src/test/java/org/jclouds/trmk/vcloudexpress/InternetServiceLiveTest.java index 46fa7d5a97..a25f499e91 100644 --- a/providers/trmk-vcloudexpress/src/test/java/org/jclouds/trmk/vcloudexpress/InternetServiceLiveTest.java +++ b/providers/trmk-vcloudexpress/src/test/java/org/jclouds/trmk/vcloudexpress/InternetServiceLiveTest.java @@ -19,26 +19,20 @@ package org.jclouds.trmk.vcloudexpress; import java.net.URI; -import java.util.Properties; import java.util.Set; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeoutException; -import org.jclouds.compute.BaseVersionedServiceLiveTest; -import org.jclouds.compute.ComputeServiceContextFactory; -import org.jclouds.logging.log4j.config.Log4JLoggingModule; -import org.jclouds.rest.RestContext; -import org.jclouds.sshj.config.SshjSshClientModule; +import org.jclouds.compute.ComputeServiceContext; +import org.jclouds.compute.internal.BaseComputeServiceContextLiveTest; import org.jclouds.trmk.vcloud_0_8.domain.InternetService; import org.jclouds.trmk.vcloud_0_8.domain.Node; import org.jclouds.trmk.vcloud_0_8.domain.PublicIpAddress; import org.testng.annotations.AfterTest; -import org.testng.annotations.BeforeGroups; +import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; -import com.google.common.collect.ImmutableSet; import com.google.common.collect.Sets; -import com.google.inject.Module; /** * Tests behavior of {@code TerremarkVCloudClient} @@ -46,7 +40,9 @@ import com.google.inject.Module; * @author Adrian Cole */ @Test(groups = "live", singleThreaded = true, testName = "InternetServiceLiveTest") -public class InternetServiceLiveTest extends BaseVersionedServiceLiveTest { +public class InternetServiceLiveTest + extends + BaseComputeServiceContextLiveTest> { public InternetServiceLiveTest() { provider = "trmk-vcloudexpress"; } @@ -55,8 +51,6 @@ public class InternetServiceLiveTest extends BaseVersionedServiceLiveTest { private Set services = Sets.newLinkedHashSet(); - private RestContext context; - public static final String PREFIX = System.getProperty("user.name") + "-terremark"; @Test @@ -90,18 +84,12 @@ public class InternetServiceLiveTest extends BaseVersionedServiceLiveTest { void cleanup() throws InterruptedException, ExecutionException, TimeoutException { delete(services); } - - - @BeforeGroups(groups = { "live" }) - public void setupClient() { - setupCredentials(); - Properties overrides = setupProperties(); - - context = new ComputeServiceContextFactory().createContext(provider, - ImmutableSet. of(new Log4JLoggingModule(), new SshjSshClientModule()), overrides) - .getProviderSpecificContext(); - - tmClient = context.getApi(); + + @Override + @BeforeClass(groups = { "integration", "live" }) + public void setupContext() { + super.setupContext(); + tmClient = context.getProviderSpecificContext().getApi(); } diff --git a/providers/trmk-vcloudexpress/src/test/java/org/jclouds/trmk/vcloudexpress/TerremarkVCloudExpressAsyncClientTest.java b/providers/trmk-vcloudexpress/src/test/java/org/jclouds/trmk/vcloudexpress/TerremarkVCloudExpressAsyncClientTest.java index 1e38085c4c..aeccab9a00 100644 --- a/providers/trmk-vcloudexpress/src/test/java/org/jclouds/trmk/vcloudexpress/TerremarkVCloudExpressAsyncClientTest.java +++ b/providers/trmk-vcloudexpress/src/test/java/org/jclouds/trmk/vcloudexpress/TerremarkVCloudExpressAsyncClientTest.java @@ -31,7 +31,6 @@ import java.io.IOException; import java.lang.reflect.Method; import java.net.URI; import java.util.Map; -import java.util.Properties; import java.util.concurrent.atomic.AtomicReference; import javax.inject.Inject; @@ -42,15 +41,14 @@ import org.jclouds.http.HttpRequest; import org.jclouds.http.RequiresHttp; import org.jclouds.http.functions.ParseSax; import org.jclouds.http.functions.ReleasePayloadAndReturn; +import org.jclouds.providers.ProviderMetadata; import org.jclouds.rest.AuthorizationException; import org.jclouds.rest.ConfiguresRestClient; import org.jclouds.rest.ResourceNotFoundException; -import org.jclouds.rest.RestClientTest; -import org.jclouds.rest.RestContextFactory; -import org.jclouds.rest.RestContextSpec; import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404; import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404; +import org.jclouds.rest.internal.BaseAsyncClientTest; import org.jclouds.rest.internal.RestAnnotationProcessor; import org.jclouds.trmk.vcloud_0_8.domain.Org; import org.jclouds.trmk.vcloud_0_8.domain.Protocol; @@ -101,7 +99,7 @@ import com.google.inject.TypeLiteral; // NOTE:without testName, this will not call @Before* and fail w/NPE during // surefire @Test(groups = "unit", singleThreaded = true, testName = "TerremarkVCloudExpressAsyncClientTest") -public class TerremarkVCloudExpressAsyncClientTest extends RestClientTest { +public class TerremarkVCloudExpressAsyncClientTest extends BaseAsyncClientTest { public void testListOrgs() { assertEquals(injector.getInstance(TerremarkVCloudExpressAsyncClient.class).listOrgs().toString(), ImmutableMap @@ -621,11 +619,10 @@ public class TerremarkVCloudExpressAsyncClientTest extends RestClientTest createContextSpec() { - return new RestContextFactory().createContextSpec("trmk-vcloudexpress", "identity", "credential", - new Properties()); + public ProviderMetadata createProviderMetadata() { + return new TerremarkVCloudExpressProviderMetadata(); } protected static final ReferenceTypeImpl ORG_REF = new ReferenceTypeImpl("org", ORG_XML, diff --git a/providers/trmk-vcloudexpress/src/test/java/org/jclouds/trmk/vcloudexpress/TerremarkVCloudExpressClientLiveTest.java b/providers/trmk-vcloudexpress/src/test/java/org/jclouds/trmk/vcloudexpress/TerremarkVCloudExpressClientLiveTest.java index e6ef961290..fae9ba860e 100644 --- a/providers/trmk-vcloudexpress/src/test/java/org/jclouds/trmk/vcloudexpress/TerremarkVCloudExpressClientLiveTest.java +++ b/providers/trmk-vcloudexpress/src/test/java/org/jclouds/trmk/vcloudexpress/TerremarkVCloudExpressClientLiveTest.java @@ -37,7 +37,7 @@ import org.testng.annotations.Test; * @author Adrian Cole */ @Test(groups = "live", singleThreaded = true, testName = "TerremarkVCloudExpressClientLiveTest") -public class TerremarkVCloudExpressClientLiveTest extends TerremarkClientLiveTest { +public class TerremarkVCloudExpressClientLiveTest extends TerremarkClientLiveTest { @Override protected SshClient getConnectionFor(IPSocket socket) { diff --git a/providers/trmk-vcloudexpress/src/test/java/org/jclouds/trmk/vcloudexpress/TerremarkVCloudExpressProviderTest.java b/providers/trmk-vcloudexpress/src/test/java/org/jclouds/trmk/vcloudexpress/TerremarkVCloudExpressProviderTest.java index 973b272f36..d170ce54aa 100644 --- a/providers/trmk-vcloudexpress/src/test/java/org/jclouds/trmk/vcloudexpress/TerremarkVCloudExpressProviderTest.java +++ b/providers/trmk-vcloudexpress/src/test/java/org/jclouds/trmk/vcloudexpress/TerremarkVCloudExpressProviderTest.java @@ -18,7 +18,7 @@ */ package org.jclouds.trmk.vcloudexpress; -import org.jclouds.providers.BaseProviderMetadataTest; +import org.jclouds.providers.internal.BaseProviderMetadataTest; import org.testng.annotations.Test; /** diff --git a/providers/trmk-vcloudexpress/src/test/java/org/jclouds/trmk/vcloudexpress/compute/TerremarkVCloudExpressComputeServiceLiveTest.java b/providers/trmk-vcloudexpress/src/test/java/org/jclouds/trmk/vcloudexpress/compute/TerremarkVCloudExpressComputeServiceLiveTest.java index c88fabda19..3038f72cdd 100644 --- a/providers/trmk-vcloudexpress/src/test/java/org/jclouds/trmk/vcloudexpress/compute/TerremarkVCloudExpressComputeServiceLiveTest.java +++ b/providers/trmk-vcloudexpress/src/test/java/org/jclouds/trmk/vcloudexpress/compute/TerremarkVCloudExpressComputeServiceLiveTest.java @@ -20,8 +20,7 @@ package org.jclouds.trmk.vcloudexpress.compute; import static org.testng.Assert.assertEquals; -import org.jclouds.compute.BaseComputeServiceLiveTest; -import org.jclouds.compute.ComputeServiceContextFactory; +import org.jclouds.compute.ComputeServiceContext; import org.jclouds.compute.domain.ComputeMetadata; import org.jclouds.compute.domain.ComputeType; import org.jclouds.compute.domain.Image; @@ -29,11 +28,13 @@ import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.domain.OsFamily; import org.jclouds.compute.domain.Template; import org.jclouds.compute.domain.TemplateBuilder; +import org.jclouds.compute.internal.BaseComputeServiceLiveTest; import org.jclouds.domain.Credentials; import org.jclouds.rest.RestContext; import org.jclouds.sshj.config.SshjSshClientModule; -import org.jclouds.trmk.vcloud_0_8.TerremarkVCloudClient; import org.jclouds.trmk.vcloud_0_8.domain.VApp; +import org.jclouds.trmk.vcloudexpress.TerremarkVCloudExpressAsyncClient; +import org.jclouds.trmk.vcloudexpress.TerremarkVCloudExpressClient; import org.testng.annotations.Test; import com.google.common.collect.ImmutableMap; @@ -44,7 +45,10 @@ import com.google.common.collect.ImmutableMap; * @author Adrian Cole */ @Test(groups = "live", enabled = true, singleThreaded = true) -public class TerremarkVCloudExpressComputeServiceLiveTest extends BaseComputeServiceLiveTest { +public class TerremarkVCloudExpressComputeServiceLiveTest + extends + BaseComputeServiceLiveTest> { + public TerremarkVCloudExpressComputeServiceLiveTest() { provider = "trmk-vcloudexpress"; } @@ -74,7 +78,7 @@ public class TerremarkVCloudExpressComputeServiceLiveTest extends BaseComputeSer assert node.getUserMetadata().equals(ImmutableMap. of()) : String.format( "node userMetadata did not match %s %s", userMetadata, node); } - + @Override public void testListImages() throws Exception { for (Image image : client.listImages()) { @@ -95,8 +99,7 @@ public class TerremarkVCloudExpressComputeServiceLiveTest extends BaseComputeSer assertEquals(node.getType(), ComputeType.NODE); NodeMetadata allData = client.getNodeMetadata(node.getId()); System.out.println(allData.getHardware()); - RestContext tmContext = new ComputeServiceContextFactory() - .createContext(provider, identity, credential).getProviderSpecificContext(); + RestContext tmContext = context.getProviderSpecificContext(); VApp vApp = tmContext.getApi().findVAppInOrgVDCNamed(null, null, allData.getName()); assertEquals(vApp.getName(), allData.getName()); } diff --git a/providers/trmk-vcloudexpress/src/test/java/org/jclouds/trmk/vcloudexpress/compute/TerremarkVCloudExpressTemplateBuilderLiveTest.java b/providers/trmk-vcloudexpress/src/test/java/org/jclouds/trmk/vcloudexpress/compute/TerremarkVCloudExpressTemplateBuilderLiveTest.java index 45540569c5..f8a59be4f9 100644 --- a/providers/trmk-vcloudexpress/src/test/java/org/jclouds/trmk/vcloudexpress/compute/TerremarkVCloudExpressTemplateBuilderLiveTest.java +++ b/providers/trmk-vcloudexpress/src/test/java/org/jclouds/trmk/vcloudexpress/compute/TerremarkVCloudExpressTemplateBuilderLiveTest.java @@ -24,10 +24,13 @@ import static org.testng.Assert.assertEquals; import java.io.IOException; import java.util.Set; -import org.jclouds.compute.BaseTemplateBuilderLiveTest; +import org.jclouds.compute.ComputeServiceContext; import org.jclouds.compute.domain.OsFamily; import org.jclouds.compute.domain.OsFamilyVersion64Bit; import org.jclouds.compute.domain.Template; +import org.jclouds.compute.internal.BaseTemplateBuilderLiveTest; +import org.jclouds.trmk.vcloudexpress.TerremarkVCloudExpressAsyncClient; +import org.jclouds.trmk.vcloudexpress.TerremarkVCloudExpressClient; import org.testng.annotations.Test; import com.google.common.base.Predicate; @@ -39,7 +42,9 @@ import com.google.common.collect.ImmutableSet; * @author Adrian Cole */ @Test(groups = "live") -public class TerremarkVCloudExpressTemplateBuilderLiveTest extends BaseTemplateBuilderLiveTest { +public class TerremarkVCloudExpressTemplateBuilderLiveTest + extends + BaseTemplateBuilderLiveTest> { public TerremarkVCloudExpressTemplateBuilderLiveTest() { provider = "trmk-vcloudexpress"; diff --git a/providers/trystack-nova/src/main/java/org/jclouds/trystack/nova/TryStackNovaContextBuilder.java b/providers/trystack-nova/src/main/java/org/jclouds/trystack/nova/TryStackNovaContextBuilder.java index 55b8b77108..d015b534ba 100644 --- a/providers/trystack-nova/src/main/java/org/jclouds/trystack/nova/TryStackNovaContextBuilder.java +++ b/providers/trystack-nova/src/main/java/org/jclouds/trystack/nova/TryStackNovaContextBuilder.java @@ -19,9 +19,13 @@ package org.jclouds.trystack.nova; import java.util.List; -import java.util.Properties; +import org.jclouds.compute.ComputeServiceContext; +import org.jclouds.openstack.nova.v1_1.NovaApiMetadata; +import org.jclouds.openstack.nova.v1_1.NovaAsyncClient; +import org.jclouds.openstack.nova.v1_1.NovaClient; import org.jclouds.openstack.nova.v1_1.NovaContextBuilder; +import org.jclouds.providers.ProviderMetadata; import org.jclouds.trystack.nova.config.TryStackNovaServiceContextModule; import com.google.inject.Module; @@ -32,12 +36,18 @@ import com.google.inject.Module; */ public class TryStackNovaContextBuilder extends NovaContextBuilder { - public TryStackNovaContextBuilder(Properties props) { - super(props); + public TryStackNovaContextBuilder( + ProviderMetadata, NovaApiMetadata> providerMetadata) { + super(providerMetadata); + } + + public TryStackNovaContextBuilder(NovaApiMetadata apiMetadata) { + super(apiMetadata); } @Override protected void addContextModule(List modules) { modules.add(new TryStackNovaServiceContextModule()); } + } diff --git a/providers/trystack-nova/src/main/java/org/jclouds/trystack/nova/TryStackNovaPropertiesBuilder.java b/providers/trystack-nova/src/main/java/org/jclouds/trystack/nova/TryStackNovaPropertiesBuilder.java deleted file mode 100644 index f2722fbf57..0000000000 --- a/providers/trystack-nova/src/main/java/org/jclouds/trystack/nova/TryStackNovaPropertiesBuilder.java +++ /dev/null @@ -1,53 +0,0 @@ -/** - * 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 computee 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.trystack.nova; - -import static org.jclouds.Constants.PROPERTY_ENDPOINT; -import static org.jclouds.Constants.PROPERTY_ISO3166_CODES; -import static org.jclouds.Constants.PROPERTY_TRUST_ALL_CERTS; -import static org.jclouds.openstack.keystone.v2_0.config.KeystoneProperties.CREDENTIAL_TYPE; -import static org.jclouds.openstack.nova.v1_1.config.NovaProperties.AUTO_GENERATE_KEYPAIRS; - -import java.util.Properties; - -import org.jclouds.openstack.nova.v1_1.NovaPropertiesBuilder; - -/** - * - * @author Adrian Cole - */ -public class TryStackNovaPropertiesBuilder extends NovaPropertiesBuilder { - - @Override - protected Properties defaultProperties() { - Properties properties = super.defaultProperties(); - properties.setProperty(PROPERTY_ISO3166_CODES, "US-CA"); - properties.setProperty(PROPERTY_ENDPOINT, "https://nova-api.trystack.org:5443"); - properties.setProperty(PROPERTY_TRUST_ALL_CERTS, "true"); - - properties.setProperty(CREDENTIAL_TYPE, "passwordCredentials"); - properties.setProperty(AUTO_GENERATE_KEYPAIRS, "true"); - return properties; - } - - public TryStackNovaPropertiesBuilder(Properties properties) { - super(properties); - } - -} diff --git a/providers/trystack-nova/src/main/java/org/jclouds/trystack/nova/TryStackNovaProviderMetadata.java b/providers/trystack-nova/src/main/java/org/jclouds/trystack/nova/TryStackNovaProviderMetadata.java index 3c508fe33f..1a974e1dee 100644 --- a/providers/trystack-nova/src/main/java/org/jclouds/trystack/nova/TryStackNovaProviderMetadata.java +++ b/providers/trystack-nova/src/main/java/org/jclouds/trystack/nova/TryStackNovaProviderMetadata.java @@ -4,7 +4,7 @@ * 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 computee this file except in compliance + * "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 @@ -18,49 +18,81 @@ */ package org.jclouds.trystack.nova; +import static org.jclouds.Constants.PROPERTY_TRUST_ALL_CERTS; +import static org.jclouds.openstack.keystone.v2_0.config.KeystoneProperties.CREDENTIAL_TYPE; +import static org.jclouds.openstack.nova.v1_1.config.NovaProperties.AUTO_GENERATE_KEYPAIRS; + import java.net.URI; +import java.util.Properties; +import org.jclouds.compute.ComputeServiceContext; import org.jclouds.openstack.nova.v1_1.NovaApiMetadata; -import org.jclouds.providers.BaseProviderMetadata; +import org.jclouds.openstack.nova.v1_1.NovaAsyncClient; +import org.jclouds.openstack.nova.v1_1.NovaClient; +import org.jclouds.providers.ProviderMetadata; +import org.jclouds.providers.internal.BaseProviderMetadata; +import com.google.common.reflect.TypeToken; /** * Implementation of {@link org.jclouds.types.ProviderMetadata} for TryStack Nova * * @author Adrian Cole */ -public class TryStackNovaProviderMetadata extends BaseProviderMetadata { +public class TryStackNovaProviderMetadata + extends + BaseProviderMetadata, NovaApiMetadata> { - public TryStackNovaProviderMetadata() { - this(builder() - .id("trystack-nova") - .name("TryStack.org (Nova)") - .api(new NovaApiMetadata()) - .homepage(URI.create("https://trystack.org")) - .console(URI.create("https://trystack.org/dash")) - .iso3166Codes("US-CA")); + public static Builder builder() { + return new Builder(); } - // below are so that we can reuse builders, toString, hashCode, etc. - // we have to set concrete classes here, as our base class cannot be - // concrete due to serviceLoader - protected TryStackNovaProviderMetadata(ConcreteBuilder builder) { + @Override + public Builder toBuilder() { + return builder().fromProviderMetadata(this); + } + + public TryStackNovaProviderMetadata() { + super(builder()); + } + + public TryStackNovaProviderMetadata(Builder builder) { super(builder); } - private static class ConcreteBuilder extends Builder { + protected static Properties defaultProperties() { + Properties properties = new Properties(); + properties.setProperty(PROPERTY_TRUST_ALL_CERTS, "true"); + properties.setProperty(CREDENTIAL_TYPE, "passwordCredentials"); + properties.setProperty(AUTO_GENERATE_KEYPAIRS, "true"); + return properties; + } + + public static class Builder extends BaseProviderMetadata.Builder, NovaApiMetadata> { + + protected Builder(){ + id("trystack-nova") + .name("TryStack.org (Nova)") + .apiMetadata( + new NovaApiMetadata().toBuilder().contextBuilder(TypeToken.of(TryStackNovaContextBuilder.class)) + .build()) + .homepage(URI.create("https://trystack.org")) + .console(URI.create("https://trystack.org/dash")) + .iso3166Codes("US-CA") + .endpoint("https://nova-api.trystack.org:5443") + .defaultProperties(TryStackNovaProviderMetadata.defaultProperties()); + } @Override public TryStackNovaProviderMetadata build() { return new TryStackNovaProviderMetadata(this); } + + @Override + public Builder fromProviderMetadata( + ProviderMetadata, NovaApiMetadata> in) { + super.fromProviderMetadata(in); + return this; + } } - - public static ConcreteBuilder builder() { - return new ConcreteBuilder(); - } - - public ConcreteBuilder toBuilder() { - return builder().fromProviderMetadata(this); - } -} +} \ No newline at end of file diff --git a/providers/trystack-nova/src/test/java/org/jclouds/trystack/nova/TryStackNovaProviderTest.java b/providers/trystack-nova/src/test/java/org/jclouds/trystack/nova/TryStackNovaProviderTest.java index 3971fadece..cc5f3d6b33 100644 --- a/providers/trystack-nova/src/test/java/org/jclouds/trystack/nova/TryStackNovaProviderTest.java +++ b/providers/trystack-nova/src/test/java/org/jclouds/trystack/nova/TryStackNovaProviderTest.java @@ -36,7 +36,7 @@ package org.jclouds.trystack.nova; import org.jclouds.openstack.nova.v1_1.NovaApiMetadata; -import org.jclouds.providers.BaseProviderMetadataTest; +import org.jclouds.providers.internal.BaseProviderMetadataTest; import org.testng.annotations.Test; /** diff --git a/providers/trystack-nova/src/test/java/org/jclouds/trystack/nova/compute/TryStackNovaTemplateBuilderLiveTest.java b/providers/trystack-nova/src/test/java/org/jclouds/trystack/nova/compute/TryStackNovaTemplateBuilderLiveTest.java index ffbde62fa0..ed4ae1e715 100644 --- a/providers/trystack-nova/src/test/java/org/jclouds/trystack/nova/compute/TryStackNovaTemplateBuilderLiveTest.java +++ b/providers/trystack-nova/src/test/java/org/jclouds/trystack/nova/compute/TryStackNovaTemplateBuilderLiveTest.java @@ -23,10 +23,13 @@ import static org.testng.Assert.assertEquals; import java.util.Set; -import org.jclouds.compute.BaseTemplateBuilderLiveTest; +import org.jclouds.compute.ComputeServiceContext; import org.jclouds.compute.domain.OsFamily; import org.jclouds.compute.domain.OsFamilyVersion64Bit; import org.jclouds.compute.domain.Template; +import org.jclouds.compute.internal.BaseTemplateBuilderLiveTest; +import org.jclouds.openstack.nova.v1_1.NovaAsyncClient; +import org.jclouds.openstack.nova.v1_1.NovaClient; import org.jclouds.openstack.nova.v1_1.compute.options.NovaTemplateOptions; import org.testng.annotations.Test; @@ -39,7 +42,8 @@ import com.google.common.collect.ImmutableSet; * @author Adrian Cole */ @Test(groups = "live", singleThreaded = true, testName = "TryStackNovaTemplateBuilderLiveTest") -public class TryStackNovaTemplateBuilderLiveTest extends BaseTemplateBuilderLiveTest { +public class TryStackNovaTemplateBuilderLiveTest extends + BaseTemplateBuilderLiveTest> { public TryStackNovaTemplateBuilderLiveTest() { provider = "trystack-nova"; diff --git a/skeletons/standalone-compute/src/main/java/org/jclouds/servermanager/ServerManagerApiMetadata.java b/skeletons/standalone-compute/src/main/java/org/jclouds/servermanager/ServerManagerApiMetadata.java new file mode 100644 index 0000000000..b858a0fe7a --- /dev/null +++ b/skeletons/standalone-compute/src/main/java/org/jclouds/servermanager/ServerManagerApiMetadata.java @@ -0,0 +1,58 @@ +package org.jclouds.servermanager; + +import java.net.URI; + +import org.jclouds.apis.ApiMetadata; +import org.jclouds.compute.ComputeServiceContext; +import org.jclouds.compute.internal.BaseComputeServiceApiMetadata; +import org.jclouds.servermanager.compute.ServerManagerComputeServiceContextBuilder; + +import com.google.common.reflect.TypeToken; + +/** + * Implementation of {@link ApiMetadata} for an example of library integration (ServerManager) + * + * @author Adrian Cole + */ +public class ServerManagerApiMetadata extends BaseComputeServiceApiMetadata, ServerManagerApiMetadata> { + public static Builder builder() { + return new Builder(); + } + + @Override + public Builder toBuilder() { + return Builder.class.cast(builder().fromApiMetadata(this)); + } + + public ServerManagerApiMetadata() { + super(builder()); + } + + protected ServerManagerApiMetadata(Builder builder) { + super(builder); + } + + public static class Builder extends BaseComputeServiceApiMetadata.Builder, ServerManagerApiMetadata> { + + protected Builder(){ + id("servermanager") + .name("ServerManager API") + .identityName("Unused") + .defaultIdentity("foo") + .defaultCredential("bar") + .defaultEndpoint("http://demo") + .context(new TypeToken>(getClass()){ + private static final long serialVersionUID = 1L; + }) + .javaApi(ServerManager.class, ServerManager.class) + .documentation(URI.create("http://www.jclouds.org/documentation/userguide/compute")) + .contextBuilder(TypeToken.of(ServerManagerComputeServiceContextBuilder.class)); + } + + @Override + public ServerManagerApiMetadata build() { + return new ServerManagerApiMetadata(this); + } + + } +} \ No newline at end of file diff --git a/skeletons/standalone-compute/src/main/java/org/jclouds/servermanager/compute/ServerManagerComputeServiceContextBuilder.java b/skeletons/standalone-compute/src/main/java/org/jclouds/servermanager/compute/ServerManagerComputeServiceContextBuilder.java index 7449626c53..f10174a8f0 100644 --- a/skeletons/standalone-compute/src/main/java/org/jclouds/servermanager/compute/ServerManagerComputeServiceContextBuilder.java +++ b/skeletons/standalone-compute/src/main/java/org/jclouds/servermanager/compute/ServerManagerComputeServiceContextBuilder.java @@ -19,10 +19,12 @@ package org.jclouds.servermanager.compute; import java.util.List; -import java.util.Properties; +import org.jclouds.compute.ComputeServiceContext; import org.jclouds.compute.StandaloneComputeServiceContextBuilder; +import org.jclouds.providers.ProviderMetadata; import org.jclouds.servermanager.ServerManager; +import org.jclouds.servermanager.ServerManagerApiMetadata; import org.jclouds.servermanager.compute.config.ServerManagerComputeServiceContextModule; import com.google.inject.Module; @@ -31,10 +33,21 @@ import com.google.inject.Module; * * @author Adrian Cole */ -public class ServerManagerComputeServiceContextBuilder extends StandaloneComputeServiceContextBuilder { +public class ServerManagerComputeServiceContextBuilder + extends + StandaloneComputeServiceContextBuilder, ServerManagerApiMetadata> { + + public ServerManagerComputeServiceContextBuilder() { + super(new ServerManagerApiMetadata()); + } - public ServerManagerComputeServiceContextBuilder(Properties props) { - super(ServerManager.class, props); + public ServerManagerComputeServiceContextBuilder( + ProviderMetadata, ServerManagerApiMetadata> providerMetadata) { + super(providerMetadata); + } + + public ServerManagerComputeServiceContextBuilder(ServerManagerApiMetadata apiMetadata) { + super(apiMetadata); } @Override diff --git a/skeletons/standalone-compute/src/main/resources/META-INF/services/org.jclouds.apis.ApiMetadata b/skeletons/standalone-compute/src/main/resources/META-INF/services/org.jclouds.apis.ApiMetadata new file mode 100644 index 0000000000..cbad9e4179 --- /dev/null +++ b/skeletons/standalone-compute/src/main/resources/META-INF/services/org.jclouds.apis.ApiMetadata @@ -0,0 +1 @@ +org.jclouds.servermanager.ServerManagerApiMetadata \ No newline at end of file diff --git a/skeletons/standalone-compute/src/test/java/org/jclouds/servermanager/compute/ServerManagerComputeServiceContextBuilderTest.java b/skeletons/standalone-compute/src/test/java/org/jclouds/servermanager/compute/ServerManagerComputeServiceContextBuilderTest.java index 9992f1a530..ba0eeb06ff 100644 --- a/skeletons/standalone-compute/src/test/java/org/jclouds/servermanager/compute/ServerManagerComputeServiceContextBuilderTest.java +++ b/skeletons/standalone-compute/src/test/java/org/jclouds/servermanager/compute/ServerManagerComputeServiceContextBuilderTest.java @@ -23,62 +23,57 @@ import static org.testng.Assert.assertEquals; import java.util.Properties; import org.jclouds.compute.ComputeServiceContext; -import org.jclouds.compute.ComputeServiceContextFactory; -import org.jclouds.compute.StandaloneComputeServiceContextSpec; +import org.jclouds.compute.ComputeServiceContextBuilder; import org.jclouds.rest.RestContext; -import org.jclouds.servermanager.Datacenter; -import org.jclouds.servermanager.Hardware; -import org.jclouds.servermanager.Image; -import org.jclouds.servermanager.Server; import org.jclouds.servermanager.ServerManager; +import org.jclouds.servermanager.ServerManagerApiMetadata; import org.testng.annotations.Test; -import com.google.common.collect.ImmutableSet; -import com.google.inject.Module; - /** * * @author Adrian Cole * */ -@Test(groups = "unit") +@Test(groups = "unit", testName = "ServerManagerComputeServiceContextBuilderTest") public class ServerManagerComputeServiceContextBuilderTest { @Test public void testCanBuildDirectly() { - ComputeServiceContext context = new ServerManagerComputeServiceContextBuilder(new Properties()) - .buildComputeServiceContext(); + ComputeServiceContext context = new ServerManagerComputeServiceContextBuilder() + .build(); context.close(); } @Test - public void testCanBuildWithContextSpec() { - ComputeServiceContext context = new ComputeServiceContextFactory() - .createContext(new StandaloneComputeServiceContextSpec( - "servermanager", "http://host", "1", "", "", "identity", "credential", ServerManager.class, - ServerManagerComputeServiceContextBuilder.class, ImmutableSet. of())); - + public void testCanBuildWithApiMetadata() { + ComputeServiceContext context = ComputeServiceContextBuilder.newBuilder( + new ServerManagerApiMetadata()).build(); context.close(); } @Test - public void testCanBuildWithRestProperties() { - Properties restProperties = new Properties(); - restProperties.setProperty("servermanager.contextbuilder", ServerManagerComputeServiceContextBuilder.class - .getName()); - restProperties.setProperty("servermanager.endpoint", "http://host"); - restProperties.setProperty("servermanager.api-version", "1"); + public void testCanBuildById() { + ComputeServiceContext context = ComputeServiceContextBuilder.newBuilder("servermanager").build(); + context.close(); + } - ComputeServiceContext context = new ComputeServiceContextFactory(restProperties).createContext("servermanager", - "identity", "credential"); + @Test + public void testCanBuildWithOverridingProperties() { + Properties overrides = new Properties(); + overrides.setProperty("servermanager.endpoint", "http://host"); + overrides.setProperty("servermanager.api-version", "1"); + + ComputeServiceContext context = new ServerManagerComputeServiceContextBuilder() + .overrides(overrides).build(); context.close(); } @Test public void testProviderSpecificContextIsCorrectType() { - ComputeServiceContext context = new ServerManagerComputeServiceContextBuilder(new Properties()) - .buildComputeServiceContext(); + ComputeServiceContext context = new ServerManagerComputeServiceContextBuilder() + .build(); + RestContext providerContext = context.getProviderSpecificContext(); assertEquals(providerContext.getApi().getClass(), ServerManager.class); diff --git a/skeletons/standalone-compute/src/test/java/org/jclouds/servermanager/compute/ServerManagerComputeServiceLiveTest.java b/skeletons/standalone-compute/src/test/java/org/jclouds/servermanager/compute/ServerManagerComputeServiceLiveTest.java index 7844e19065..e194d09a23 100644 --- a/skeletons/standalone-compute/src/test/java/org/jclouds/servermanager/compute/ServerManagerComputeServiceLiveTest.java +++ b/skeletons/standalone-compute/src/test/java/org/jclouds/servermanager/compute/ServerManagerComputeServiceLiveTest.java @@ -21,14 +21,11 @@ package org.jclouds.servermanager.compute; import static org.jclouds.compute.util.ComputeServiceUtils.getCores; import static org.testng.Assert.assertEquals; -import java.util.Properties; - -import org.jclouds.compute.BaseComputeServiceLiveTest; -import org.jclouds.compute.ComputeServiceContextFactory; +import org.jclouds.compute.ComputeServiceContext; import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.domain.OsFamily; import org.jclouds.compute.domain.Template; -import org.jclouds.rest.RestContext; +import org.jclouds.compute.internal.BaseComputeServiceLiveTest; import org.jclouds.servermanager.ServerManager; import org.jclouds.ssh.jsch.config.JschSshClientModule; import org.testng.annotations.Test; @@ -39,21 +36,13 @@ import com.google.common.collect.ImmutableMap; * @author Adrian Cole */ @Test(groups = "live", enabled = true, singleThreaded = true) -public class ServerManagerComputeServiceLiveTest extends BaseComputeServiceLiveTest { +public class ServerManagerComputeServiceLiveTest extends + BaseComputeServiceLiveTest> { + public ServerManagerComputeServiceLiveTest() { provider = "servermanager"; } - @Override - protected Properties setupRestProperties() { - Properties restProperties = new Properties(); - restProperties.setProperty("servermanager.contextbuilder", - ServerManagerComputeServiceContextBuilder.class.getName()); - restProperties.setProperty("servermanager.endpoint", "http://host"); - restProperties.setProperty("servermanager.api-version", "1"); - return restProperties; - } - @Test public void testTemplateBuilder() { Template defaultTemplate = client.templateBuilder().build(); @@ -76,9 +65,4 @@ public class ServerManagerComputeServiceLiveTest extends BaseComputeServiceLiveT "node userMetadata did not match %s %s", userMetadata, node); } - public void testAssignability() throws Exception { - @SuppressWarnings("unused") - RestContext goGridContext = new ComputeServiceContextFactory().createContext( - provider, identity, credential).getProviderSpecificContext(); - } } diff --git a/skeletons/standalone-compute/src/test/java/org/jclouds/servermanager/compute/ServerManagerExperimentLiveTest.java b/skeletons/standalone-compute/src/test/java/org/jclouds/servermanager/compute/ServerManagerExperimentLiveTest.java index aa547e9e9f..fefa7e3879 100644 --- a/skeletons/standalone-compute/src/test/java/org/jclouds/servermanager/compute/ServerManagerExperimentLiveTest.java +++ b/skeletons/standalone-compute/src/test/java/org/jclouds/servermanager/compute/ServerManagerExperimentLiveTest.java @@ -18,38 +18,31 @@ */ package org.jclouds.servermanager.compute; -import org.jclouds.compute.BaseVersionedServiceLiveTest; import org.jclouds.compute.ComputeServiceContext; -import org.jclouds.compute.ComputeServiceContextFactory; -import org.jclouds.compute.StandaloneComputeServiceContextSpec; -import org.jclouds.servermanager.Datacenter; -import org.jclouds.servermanager.Hardware; -import org.jclouds.servermanager.Image; -import org.jclouds.servermanager.Server; +import org.jclouds.compute.ComputeServiceContextBuilder; +import org.jclouds.compute.internal.BaseComputeServiceContextLiveTest; import org.jclouds.servermanager.ServerManager; +import org.jclouds.servermanager.ServerManagerApiMetadata; import org.testng.annotations.Test; -import com.google.common.collect.ImmutableSet; -import com.google.inject.Module; - /** * * @author Adrian Cole */ @Test(groups = "live", singleThreaded = true, testName = "ServerManagerExperimentLiveTest") -public class ServerManagerExperimentLiveTest extends BaseVersionedServiceLiveTest { +public class ServerManagerExperimentLiveTest + extends + BaseComputeServiceContextLiveTest> { + public ServerManagerExperimentLiveTest() { provider = "servermanager"; } - + @Test public void testAndExperiment() { - ComputeServiceContext context = null; + ComputeServiceContext context = null; try { - context = new ComputeServiceContextFactory() - .createContext(new StandaloneComputeServiceContextSpec( - "servermanager", endpoint, apiVersion, buildVersion, "", identity, credential, ServerManager.class, - ServerManagerComputeServiceContextBuilder.class, ImmutableSet. of())); + context = ComputeServiceContextBuilder.newBuilder(new ServerManagerApiMetadata()).build(); context.getComputeService().listNodes();