refactor PropertiesBuilder and related types into ApiMetadata and ProviderMetadata, and update all usage

This commit is contained in:
Adrian Cole 2012-04-04 22:32:48 -07:00
parent 70d179b3c7
commit 23cb01f977
831 changed files with 11752 additions and 12753 deletions

View File

@ -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);

View File

@ -34,8 +34,7 @@
<packaging>bundle</packaging>
<properties>
<test.initializer>org.jclouds.atmos.blobstore.integration.AtmosStorageTestInitializer</test.initializer>
<test.atmos.endpoint>https://accesspoint.atmos.com</test.atmos.endpoint>
<test.atmos.endpoint>https://accesspoint.atmosonline.com</test.atmos.endpoint>
<test.atmos.api-version>1.3.0</test.atmos.api-version>
<test.atmos.build-version></test.atmos.build-version>
<test.atmos.identity>FIXME</test.atmos.identity>

View File

@ -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<AtmosClient, AtmosAsyncClient, BlobStoreContext<AtmosClient, AtmosAsyncClient>, 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<ConcreteBuilder> {
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<AtmosClient, AtmosAsyncClient, BlobStoreContext<AtmosClient, AtmosAsyncClient>, 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;
}
}
}

View File

@ -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.
* <p/>
* 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.
* <p/>
* <p/>
* If no <code>Module</code>s are specified, the default {@link JDKLoggingModule logging} and
* {@link JavaUrlHttpCommandExecutorServiceModule http transports} will be installed.
* If no <code>Module</code>s 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<AtmosClient, AtmosAsyncClient> {
public class AtmosContextBuilder
extends
BlobStoreContextBuilder<AtmosClient, AtmosAsyncClient, BlobStoreContext<AtmosClient, AtmosAsyncClient>, AtmosApiMetadata> {
public AtmosContextBuilder(Properties props) {
super(AtmosClient.class, AtmosAsyncClient.class, props);
public AtmosContextBuilder(
ProviderMetadata<AtmosClient, AtmosAsyncClient, BlobStoreContext<AtmosClient, AtmosAsyncClient>, AtmosApiMetadata> providerMetadata) {
super(providerMetadata);
}
public AtmosContextBuilder(AtmosApiMetadata apiMetadata) {
super(apiMetadata);
}
@Override

View File

@ -85,7 +85,7 @@ public class AtmosAsyncBlobStore extends BaseAsyncBlobStore {
private final LoadingCache<String, Boolean> isPublic;
@Inject
AtmosAsyncBlobStore(BlobStoreContext context, BlobUtils blobUtils,
AtmosAsyncBlobStore(@SuppressWarnings("rawtypes") BlobStoreContext context, BlobUtils blobUtils,
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService service, Supplier<Location> defaultLocation,
@Memoized Supplier<Set<? extends Location>> locations, AtmosAsyncClient async, AtmosClient sync,
ObjectToBlob object2Blob, ObjectToBlobMetadata object2BlobMd, BlobToObject blob2Object,

View File

@ -73,7 +73,7 @@ public class AtmosBlobStore extends BaseBlobStore {
private final LoadingCache<String, Boolean> isPublic;
@Inject
AtmosBlobStore(BlobStoreContext context, BlobUtils blobUtils, Supplier<Location> defaultLocation,
AtmosBlobStore(@SuppressWarnings("rawtypes") BlobStoreContext context, BlobUtils blobUtils, Supplier<Location> defaultLocation,
@Memoized Supplier<Set<? extends Location>> locations, AtmosClient sync, ObjectToBlob object2Blob,
ObjectToBlobMetadata object2BlobMd, BlobToObject blob2Object,
BlobStoreListOptionsToListOptions container2ContainerListOptions,

View File

@ -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());
}
}

View File

@ -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<AtmosAsyncClient> {
public class AtmosAsyncClientTest extends BaseAsyncClientTest<AtmosAsyncClient> {
private BlobToObject blobToObject;
@ -339,10 +337,8 @@ public class AtmosAsyncClientTest extends RestClientTest<AtmosAsyncClient> {
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();
}
}

View File

@ -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<AtmosAsyncClient> {
public class AtmosBlobRequestSignerTest extends BaseAsyncClientTest<AtmosAsyncClient> {
private BlobRequestSigner signer;
private Factory blobFactory;
@ -144,8 +143,8 @@ public class AtmosBlobRequestSignerTest extends RestClientTest<AtmosAsyncClient>
}
@Override
public RestContextSpec<?, ?> createContextSpec() {
return new RestContextFactory().createContextSpec("atmos", "identity", "credential", new Properties());
public ApiMetadata<?, ?, ?, ?> createApiMetadata() {
return new AtmosApiMetadata();
}
}

View File

@ -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.<Module> of(new MockModule(), new NullLoggingModule())).buildInjector();
return BlobStoreContextBuilder
.newBuilder(new AtmosApiMetadata())
.credentials("uid", "key")
.modules(
ImmutableSet.<Module> 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);

View File

@ -27,5 +27,7 @@ import org.testng.annotations.Test;
*/
@Test(groups = { "live" })
public class AtmosBlobSignerLiveTest extends BaseBlobSignerLiveTest {
public AtmosBlobSignerLiveTest() {
provider = "atmos";
}
}

View File

@ -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

View File

@ -26,5 +26,7 @@ import org.testng.annotations.Test;
*/
@Test(groups = { "live" })
public class AtmosContainerLiveTest extends BaseContainerLiveTest {
public AtmosContainerLiveTest() {
provider = "atmos";
}
}

View File

@ -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,

View File

@ -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

View File

@ -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);

View File

@ -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 {

View File

@ -26,5 +26,7 @@ import org.testng.annotations.Test;
*/
@Test(groups = "live")
public class AtmosServiceIntegrationLiveTest extends BaseServiceIntegrationTest {
public AtmosServiceIntegrationLiveTest() {
provider = "atmos";
}
}

View File

@ -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));
}
}

View File

@ -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.<Module> of(new MockModule(), new TestAtmosRestClientModule(),
new NullLoggingModule()), new Properties()).buildInjector();
Injector injector = BlobStoreContextBuilder
.newBuilder("atmos")
.credentials(UID, KEY)
.modules(
ImmutableSet.<Module> of(new MockModule(), new TestAtmosRestClientModule(), new NullLoggingModule()))
.buildInjector();
filter = injector.getInstance(SignRequest.class);

View File

@ -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
*
* <h3>note</h3>
*
* 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<Supplier, Supplier, ComputeServiceContext<Supplier, Supplier>, 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<ConcreteBuilder> {
protected static Properties defaultProperties() {
return BaseComputeServiceApiMetadata.Builder.defaultProperties();
}
public static class Builder extends BaseComputeServiceApiMetadata.Builder<Supplier, Supplier, ComputeServiceContext<Supplier, Supplier>, 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);
}
}

View File

@ -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<Supplier> {
public class BYONComputeServiceContextBuilder extends StandaloneComputeServiceContextBuilder<Supplier, ComputeServiceContext<Supplier, Supplier>, BYONApiMetadata> {
public BYONComputeServiceContextBuilder(Properties props) {
super(Supplier.class, props);
public BYONComputeServiceContextBuilder(
ProviderMetadata<Supplier, Supplier, ComputeServiceContext<Supplier, Supplier>, BYONApiMetadata> providerMetadata) {
super(providerMetadata);
}
public BYONComputeServiceContextBuilder(BYONApiMetadata apiMetadata) {
super(apiMetadata);
}
@Override
protected void addContextModule(List<Module> modules) {
modules.add(new BYONComputeServiceContextModule());

View File

@ -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);
}
}

View File

@ -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());
}
}

View File

@ -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.<Module> of(
new SshjSshClientModule(), new Log4JLoggingModule()), contextProperties);
context = ContextBuilder.newBuilder(new BYONApiMetadata()).overrides(contextProperties)
.modules(ImmutableSet.<Module> of(new SshjSshClientModule(), new Log4JLoggingModule())).build();
}
public void testCanRunCommandAsCurrentUser() throws Exception {

View File

@ -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<Module> 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.<Module> of(),
props);
context = ContextBuilder.newBuilder(
AnonymousProviderMetadata.forApiWithEndpoint(new BYONApiMetadata(), endpoint)).build();
assertEquals(context.getProviderSpecificContext().getEndpoint(), URI.create(endpoint));

View File

@ -34,7 +34,6 @@
<packaging>bundle</packaging>
<properties>
<test.initializer>org.jclouds.cloudfiles.blobstore.integration.CloudFilesTestInitializer</test.initializer>
<test.cloudfiles.endpoint>https://auth.api.rackspacecloud.com</test.cloudfiles.endpoint>
<test.cloudfiles.api-version>1.0</test.cloudfiles.api-version>
<test.cloudfiles.build-version></test.cloudfiles.build-version>
@ -107,7 +106,6 @@
</goals>
<configuration>
<systemPropertyVariables>
<test.initializer>${test.initializer}</test.initializer>
<jclouds.blobstore.httpstream.url>${jclouds.blobstore.httpstream.url}</jclouds.blobstore.httpstream.url>
<jclouds.blobstore.httpstream.md5>${jclouds.blobstore.httpstream.md5}</jclouds.blobstore.httpstream.md5>
<test.cloudfiles.endpoint>${test.cloudfiles.endpoint}</test.cloudfiles.endpoint>

View File

@ -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<CloudFilesClient, CloudFilesAsyncClient, BlobStoreContext<CloudFilesClient, CloudFilesAsyncClient>, 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<ConcreteBuilder> {
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<CloudFilesClient, CloudFilesAsyncClient, BlobStoreContext<CloudFilesClient, CloudFilesAsyncClient>, 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);
}
}

View File

@ -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.
* <p/>
* 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.
* <p/>
* <p/>
* If no <code>Module</code>s are specified, the default {@link JDKLoggingModule logging} and
* {@link JavaUrlHttpCommandExecutorServiceModule http transports} will be installed.
* If no <code>Module</code>s 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<CloudFilesClient, CloudFilesAsyncClient> {
public class CloudFilesContextBuilder
extends
BlobStoreContextBuilder<CloudFilesClient, CloudFilesAsyncClient, BlobStoreContext<CloudFilesClient, CloudFilesAsyncClient>, CloudFilesApiMetadata> {
public CloudFilesContextBuilder(Properties props) {
super(CloudFilesClient.class, CloudFilesAsyncClient.class, props);
public CloudFilesContextBuilder(
ProviderMetadata<CloudFilesClient, CloudFilesAsyncClient, BlobStoreContext<CloudFilesClient, CloudFilesAsyncClient>, CloudFilesApiMetadata> providerMetadata) {
super(providerMetadata);
}
public CloudFilesContextBuilder(CloudFilesApiMetadata apiMetadata) {
super(apiMetadata);
}
@Override

View File

@ -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<Location> defaultLocation,
@Memoized Supplier<Set<? extends Location>> locations, CloudFilesClient sync, CloudFilesAsyncClient async,
ContainerToResourceMetadata container2ResourceMd,

View File

@ -53,7 +53,7 @@ public class CloudFilesBlobStore extends SwiftBlobStore {
private EnableCDNAndCache enableCDNAndCache;
@Inject
protected CloudFilesBlobStore(BlobStoreContext context, BlobUtils blobUtils, Supplier<Location> defaultLocation,
protected CloudFilesBlobStore(@SuppressWarnings("rawtypes") BlobStoreContext context, BlobUtils blobUtils, Supplier<Location> defaultLocation,
@Memoized Supplier<Set<? extends Location>> locations, CommonSwiftClient sync,
ContainerToResourceMetadata container2ResourceMd,
BlobStoreListContainerOptionsToListContainerOptions container2ContainerListOptions,

View File

@ -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());
}
}

View File

@ -41,6 +41,10 @@ import com.google.common.collect.Iterables;
@Test(groups = "live")
public class CloudFilesClientLiveTest extends CommonSwiftClientLiveTest<CloudFilesClient> {
public CloudFilesClientLiveTest(){
provider = "cloudfiles";
}
@Override
public CloudFilesClient getApi() {
return (CloudFilesClient) context.getProviderSpecificContext().getApi();

View File

@ -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

View File

@ -27,5 +27,7 @@ import org.testng.annotations.Test;
*/
@Test(groups = { "live" })
public class CloudFilesBlobLiveTest extends SwiftBlobLiveTest {
public CloudFilesBlobLiveTest(){
provider = "cloudfiles";
}
}

View File

@ -26,5 +26,7 @@ import org.testng.annotations.Test;
*/
@Test(groups = "live")
public class CloudFilesBlobMapIntegrationLiveTest extends SwiftBlobMapIntegrationLiveTest {
public CloudFilesBlobMapIntegrationLiveTest(){
provider = "cloudfiles";
}
}

View File

@ -27,5 +27,7 @@ import org.testng.annotations.Test;
*/
@Test(groups = { "live" })
public class CloudFilesBlobSignerLiveTest extends SwiftBlobSignerLiveTest {
public CloudFilesBlobSignerLiveTest(){
provider = "cloudfiles";
}
}

View File

@ -26,5 +26,7 @@ import org.testng.annotations.Test;
*/
@Test(groups = "live")
public class CloudFilesContainerIntegrationLiveTest extends SwiftContainerIntegrationLiveTest {
public CloudFilesContainerIntegrationLiveTest(){
provider = "cloudfiles";
}
}

View File

@ -26,5 +26,7 @@ import org.testng.annotations.Test;
*/
@Test(groups = { "live" })
public class CloudFilesContainerLiveTest extends BaseContainerLiveTest {
public CloudFilesContainerLiveTest(){
provider = "cloudfiles";
}
}

View File

@ -26,5 +26,7 @@ import org.testng.annotations.Test;
*/
@Test(groups = "live")
public class CloudFilesInputStreamMapIntegrationLiveTest extends SwiftInputStreamMapIntegrationLiveTest {
public CloudFilesInputStreamMapIntegrationLiveTest(){
provider = "cloudfiles";
}
}

View File

@ -26,5 +26,7 @@ import org.testng.annotations.Test;
*/
@Test(groups = "live")
public class CloudFilesServiceIntegrationLiveTest extends SwiftServiceIntegrationLiveTest {
public CloudFilesServiceIntegrationLiveTest(){
provider = "cloudfiles";
}
}

View File

@ -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<CloudLoadBalancersClient, CloudLoadBalancersAsyncClient, LoadBalancerServiceContext<CloudLoadBalancersClient, CloudLoadBalancersAsyncClient>, 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<ConcreteBuilder> {
protected static Properties defaultProperties() {
Properties properties = BaseLoadBalancerServiceApiMetadata.Builder.defaultProperties();
return properties;
}
public static class Builder
extends
BaseLoadBalancerServiceApiMetadata.Builder<CloudLoadBalancersClient, CloudLoadBalancersAsyncClient, LoadBalancerServiceContext<CloudLoadBalancersClient, CloudLoadBalancersAsyncClient>, 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);
}
}

View File

@ -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<CloudLoadBalancersClient, CloudLoadBalancersAsyncClient> {
public class CloudLoadBalancersContextBuilder
extends
LoadBalancerServiceContextBuilder<CloudLoadBalancersClient, CloudLoadBalancersAsyncClient, LoadBalancerServiceContext<CloudLoadBalancersClient, CloudLoadBalancersAsyncClient>, CloudLoadBalancersApiMetadata> {
public CloudLoadBalancersContextBuilder(Properties props) {
super(CloudLoadBalancersClient.class, CloudLoadBalancersAsyncClient.class, props);
public CloudLoadBalancersContextBuilder(
ProviderMetadata<CloudLoadBalancersClient, CloudLoadBalancersAsyncClient, LoadBalancerServiceContext<CloudLoadBalancersClient, CloudLoadBalancersAsyncClient>, CloudLoadBalancersApiMetadata> providerMetadata) {
super(providerMetadata);
}
public CloudLoadBalancersContextBuilder(CloudLoadBalancersApiMetadata apiMetadata) {
super(apiMetadata);
}
@Override
@ -47,4 +54,4 @@ public class CloudLoadBalancersContextBuilder extends
modules.add(new CloudLoadBalancersRestClientModule());
}
}
}

View File

@ -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);
}
}

View File

@ -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());
}
}

View File

@ -46,8 +46,8 @@ public class LoadBalancerClientLiveTest extends BaseCloudLoadBalancersClientLive
private Set<LoadBalancer> 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());
}

View File

@ -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<T> extends RestClientTest<T> {
public abstract class BaseCloudLoadBalancersAsyncClientTest<T> extends BaseAsyncClientTest<T> {
protected String provider;
@ -131,15 +126,9 @@ public abstract class BaseCloudLoadBalancersAsyncClientTest<T> extends RestClien
return overrides;
}
/**
* this is only here as "cloudloadbalancers" is not in rest.properties
*/
@SuppressWarnings( { "unchecked", "rawtypes" })
@Override
public RestContextSpec<?, ?> createContextSpec() {
return RestContextFactory.<LoadBalancerClient, LoadBalancerAsyncClient> contextSpec(provider, "https://auth",
"1.0", "", "", "identity", "credential", LoadBalancerClient.class, LoadBalancerAsyncClient.class,
(Class) CloudLoadBalancersPropertiesBuilder.class, (Class) CloudLoadBalancersContextBuilder.class,
ImmutableSet.<Module> of());
protected ApiMetadata<?, ?, ?, ?> createApiMetadata() {
return new CloudLoadBalancersApiMetadata();
}
}

View File

@ -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<LoadBalancerServiceContext<CloudLoadBalancersClient, CloudLoadBalancersAsyncClient>> {
public BaseCloudLoadBalancersClientLiveTest() {
provider = "cloudloadbalancers";
}
protected CloudLoadBalancersClient client;
protected RestContext<CloudLoadBalancersClient, CloudLoadBalancersAsyncClient> context;
protected RestContext<CloudLoadBalancersClient, CloudLoadBalancersAsyncClient> lbContext;
protected String[] regions = {};
protected Predicate<IPSocket> socketTester;
protected RetryablePredicate<LoadBalancer> 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.<Module> of(new Log4JLoggingModule()),
overrides).getProviderSpecificContext();
client = context.getApi();
client = lbContext.getApi();
injector = Guice.createInjector(new Log4JLoggingModule());
loadBalancerActive = new RetryablePredicate<LoadBalancer>(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();
}
}

View File

@ -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<CloudServersClient, CloudServersAsyncClient, ComputeServiceContext<CloudServersClient, CloudServersAsyncClient>, 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<ConcreteBuilder> {
protected static Properties defaultProperties() {
Properties properties = BaseComputeServiceApiMetadata.Builder.defaultProperties();
return properties;
}
public static class Builder
extends
BaseComputeServiceApiMetadata.Builder<CloudServersClient, CloudServersAsyncClient, ComputeServiceContext<CloudServersClient, CloudServersAsyncClient>, 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);
}
}

View File

@ -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.
* <p/>
* Note that Threadsafe objects will be bound as singletons to the Injector or Context provided.
* <p/>
* <p/>
* If no <code>Module</code>s 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<CloudServersClient, CloudServersAsyncClient> {
public class CloudServersContextBuilder
extends
ComputeServiceContextBuilder<CloudServersClient, CloudServersAsyncClient, ComputeServiceContext<CloudServersClient, CloudServersAsyncClient>, CloudServersApiMetadata> {
public CloudServersContextBuilder(Properties props) {
super(CloudServersClient.class, CloudServersAsyncClient.class, props);
public CloudServersContextBuilder(
ProviderMetadata<CloudServersClient, CloudServersAsyncClient, ComputeServiceContext<CloudServersClient, CloudServersAsyncClient>, 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<Module> modules) {
modules.add(new CloudServersRestClientModule());
}
}
}

View File

@ -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);
}
}

View File

@ -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());
}
}

View File

@ -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<CloudServersAsyncClient> {
public class CloudServersAsyncClientTest extends BaseAsyncClientTest<CloudServersAsyncClient> {
private static final Class<? extends ListOptions[]> listOptionsVarargsClass = new ListOptions[] {}.getClass();
private static final Class<? extends CreateServerOptions[]> createServerOptionsVarargsClass = new CreateServerOptions[] {}
.getClass();
@ -910,8 +909,8 @@ public class CloudServersAsyncClientTest extends RestClientTest<CloudServersAsyn
protected String provider = "cloudservers";
@Override
public RestContextSpec<?, ?> createContextSpec() {
return new RestContextFactory(setupRestProperties()).createContextSpec(provider, "user", "password", setupProperties());
protected ApiMetadata<?, ?, ?, ?> createApiMetadata() {
return new CloudServersApiMetadata();
}
@Override

View File

@ -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<CloudServersClient, CloudServersAsyncClient, ComputeServiceContext<CloudServersClient, CloudServersAsyncClient>> {
public CloudServersClientLiveTest() {
provider = "cloudservers";
}
@ -86,15 +84,11 @@ public class CloudServersClientLiveTest extends BaseVersionedServiceLiveTest {
protected SshClient.Factory sshFactory;
protected Predicate<IPSocket> socketTester;
@BeforeGroups(groups = { "live" })
public void setupClient() {
setupCredentials();
Properties overrides = setupProperties();
Injector injector = new RestContextFactory().createContextBuilder(provider,
ImmutableSet.<Module> 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);

View File

@ -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<CloudServersClient, CloudServersAsyncClient, ComputeServiceContext<CloudServersClient, CloudServersAsyncClient>> {
public CloudServersComputeServiceLiveTest() {
provider = "cloudservers";
}
@ -51,12 +53,6 @@ public class CloudServersComputeServiceLiveTest extends BaseComputeServiceLiveTe
return new SshjSshClientModule();
}
public void testAssignability() throws Exception {
@SuppressWarnings("unused")
RestContext<CloudServersClient, CloudServersAsyncClient> tmContext = new ComputeServiceContextFactory()
.createContext(provider, identity, credential).getProviderSpecificContext();
}
@Override
protected void checkNodes(Iterable<? extends NodeMetadata> nodes, String group, String task) throws IOException {
super.checkNodes(nodes, group, task);

View File

@ -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;
}

View File

@ -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<CloudSigmaClient, CloudSigmaAsyncClient, ComputeServiceContext<CloudSigmaClient, CloudSigmaAsyncClient>, 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<ConcreteBuilder> {
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<CloudSigmaClient, CloudSigmaAsyncClient, ComputeServiceContext<CloudSigmaClient, CloudSigmaAsyncClient>, 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);
}
}

View File

@ -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<CloudSigmaClient, CloudSigmaAsyncClient> {
public class CloudSigmaContextBuilder
extends
ComputeServiceContextBuilder<CloudSigmaClient, CloudSigmaAsyncClient, ComputeServiceContext<CloudSigmaClient, CloudSigmaAsyncClient>, CloudSigmaApiMetadata> {
public CloudSigmaContextBuilder(Properties props) {
super(CloudSigmaClient.class, CloudSigmaAsyncClient.class, props);
public CloudSigmaContextBuilder(
ProviderMetadata<CloudSigmaClient, CloudSigmaAsyncClient, ComputeServiceContext<CloudSigmaClient, CloudSigmaAsyncClient>, CloudSigmaApiMetadata> providerMetadata) {
super(providerMetadata);
}
public CloudSigmaContextBuilder(CloudSigmaApiMetadata apiMetadata) {
super(apiMetadata);
}
@Override

View File

@ -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);
}
}

View File

@ -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());
}
}

View File

@ -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<CloudSigmaAsyncClient> {
public class CloudSigmaAsyncClientTest extends BaseAsyncClientTest<CloudSigmaAsyncClient> {
public void testGetProfileInfo() throws SecurityException, NoSuchMethodException, IOException {
Method method = CloudSigmaAsyncClient.class.getMethod("getProfileInfo");
@ -243,7 +241,7 @@ public class CloudSigmaAsyncClientTest extends RestClientTest<CloudSigmaAsyncCli
assertRequestLineEquals(httpRequest, "GET https://api.cloudsigma.com/servers/list HTTP/1.1");
// for example, using basic authentication, we should get "only one"
// header
assertNonPayloadHeadersEqual(httpRequest, "Accept: text/plain\nAuthorization: Basic Zm9vOmJhcg==\n");
assertNonPayloadHeadersEqual(httpRequest, "Accept: text/plain\nAuthorization: Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==\n");
assertPayloadEquals(httpRequest, null, null, false);
// TODO: insert expected response class, which probably extends ParseJson
@ -413,7 +411,7 @@ public class CloudSigmaAsyncClientTest extends RestClientTest<CloudSigmaAsyncCli
assertRequestLineEquals(httpRequest, "GET https://api.cloudsigma.com/drives/list HTTP/1.1");
// for example, using basic authentication, we should get "only one"
// header
assertNonPayloadHeadersEqual(httpRequest, "Accept: text/plain\nAuthorization: Basic Zm9vOmJhcg==\n");
assertNonPayloadHeadersEqual(httpRequest, "Accept: text/plain\nAuthorization: Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==\n");
assertPayloadEquals(httpRequest, null, null, false);
// TODO: insert expected response class, which probably extends ParseJson
@ -456,7 +454,7 @@ public class CloudSigmaAsyncClientTest extends RestClientTest<CloudSigmaAsyncCli
assertRequestLineEquals(httpRequest, "GET https://api.cloudsigma.com/resources/vlan/list HTTP/1.1");
// for example, using basic authentication, we should get "only one"
// header
assertNonPayloadHeadersEqual(httpRequest, "Accept: text/plain\nAuthorization: Basic Zm9vOmJhcg==\n");
assertNonPayloadHeadersEqual(httpRequest, "Accept: text/plain\nAuthorization: Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==\n");
assertPayloadEquals(httpRequest, null, null, false);
// TODO: insert expected response class, which probably extends ParseJson
@ -562,7 +560,7 @@ public class CloudSigmaAsyncClientTest extends RestClientTest<CloudSigmaAsyncCli
assertRequestLineEquals(httpRequest, "GET https://api.cloudsigma.com/resources/ip/list HTTP/1.1");
// for example, using basic authentication, we should get "only one"
// header
assertNonPayloadHeadersEqual(httpRequest, "Accept: text/plain\nAuthorization: Basic Zm9vOmJhcg==\n");
assertNonPayloadHeadersEqual(httpRequest, "Accept: text/plain\nAuthorization: Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==\n");
assertPayloadEquals(httpRequest, null, null, false);
// TODO: insert expected response class, which probably extends ParseJson
@ -650,9 +648,8 @@ public class CloudSigmaAsyncClientTest extends RestClientTest<CloudSigmaAsyncCli
}
@Override
public RestContextSpec<CloudSigmaClient, CloudSigmaAsyncClient> 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();
}
}

View File

@ -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<CloudSigmaClient, CloudSigmaAsyncClient, ComputeServiceContext<CloudSigmaClient, CloudSigmaAsyncClient>> {
public CloudSigmaClientLiveTest() {
provider = "cloudsigma";
}
protected long driveSize = 8 * 1024 * 1024 * 1024l;
protected int maxDriveImageTime = 300;
protected String vncPassword = "Il0veVNC";
protected CloudSigmaClient client;
protected RestContext<CloudSigmaClient, CloudSigmaAsyncClient> context;
protected RestContext<CloudSigmaClient, CloudSigmaAsyncClient> cloudSigmaContext;
protected Predicate<IPSocket> socketTester;
protected Predicate<DriveInfo> 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.<Module> of(new Log4JLoggingModule()), overrides);
context = computeContext.getProviderSpecificContext();
client = context.getApi();
client = cloudSigmaContext.getApi();
driveNotClaimed = new RetryablePredicate<DriveInfo>(Predicates.not(new DriveClaimed(client)), maxDriveImageTime,
1, TimeUnit.SECONDS);
socketTester = new RetryablePredicate<IPSocket>(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"));

View File

@ -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<CloudSigmaClient, CloudSigmaAsyncClient, ComputeServiceContext<CloudSigmaClient, CloudSigmaAsyncClient>> {
public CloudSigmaComputeServiceLiveTest() {
provider = "cloudsigma";
}

View File

@ -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.
*
* <h3>note</h3>
* <p/>
* 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.
* <p/>
*
* 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<CloudStackClient, CloudStackAsyncClient, CloudStackContext, CloudStackApiMetadata>
{
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<ConcreteBuilder> {
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<CloudStackClient, CloudStackAsyncClient, CloudStackContext, CloudStackApiMetadata> {
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);
}
}

View File

@ -31,9 +31,8 @@ import com.google.inject.ImplementedBy;
*
*/
@ImplementedBy(CloudStackContextImpl.class)
public interface CloudStackContext extends ComputeServiceContext {
public interface CloudStackContext extends ComputeServiceContext<CloudStackClient, CloudStackAsyncClient> {
@SuppressWarnings("unchecked")
@Override
RestContext<CloudStackClient, CloudStackAsyncClient> getProviderSpecificContext();

View File

@ -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<CloudStackClient, CloudStackAsyncClient> {
public class CloudStackContextBuilder extends
ComputeServiceContextBuilder<CloudStackClient, CloudStackAsyncClient, CloudStackContext, CloudStackApiMetadata> {
public CloudStackContextBuilder(Properties props) {
super(CloudStackClient.class, CloudStackAsyncClient.class, props);
public CloudStackContextBuilder(
ProviderMetadata<CloudStackClient, CloudStackAsyncClient, CloudStackContext, CloudStackApiMetadata> providerMetadata) {
super(providerMetadata);
}
@Override
protected void addContextModule(List<Module> modules) {
modules.add(new CloudStackComputeServiceContextModule());
public CloudStackContextBuilder(CloudStackApiMetadata apiMetadata) {
super(apiMetadata);
}
@Override
@ -49,7 +51,13 @@ public class CloudStackContextBuilder extends ComputeServiceContextBuilder<Cloud
}
@Override
public CloudStackContext buildComputeServiceContext() {
return buildInjector().getInstance(CloudStackContextImpl.class);
protected void addContextModule(List<Module> modules) {
modules.add(new CloudStackComputeServiceContextModule());
}
@VisibleForTesting
public Properties getOverrides() {
return overrides;
}
}

View File

@ -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);
}
}

View File

@ -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.

View File

@ -57,7 +57,6 @@ public class CloudStackContextImpl extends ComputeServiceContextImpl<CloudStackC
this.globalContext = globalContext;
}
@SuppressWarnings("unchecked")
@Override
public RestContext<CloudStackClient,CloudStackAsyncClient> getProviderSpecificContext() {
return providerSpecificContext;

View File

@ -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.<Module>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<Account> 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;
}
}

View File

@ -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());
}
}

View File

@ -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<String, Credentials> 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<Supplier<User>>() {
}).annotatedWith(Memoized.class).to(GetCurrentUser.class).in(Scopes.SINGLETON);
bind(new TypeLiteral<Supplier<Map<Long, Network>>>() {
}).annotatedWith(Memoized.class).to(NetworksForCurrentUser.class).in(Scopes.SINGLETON);
bind(new TypeLiteral<Map<String, Credentials>>() {
}).toInstance(credentialStore);
bind(CloudStackClient.class).toInstance(context.getApi());
bind(CloudStackClient.class).toInstance(cloudStackContext.getApi());
bind(new TypeLiteral<Map<NetworkType, ? extends OptionsConverter>>() {}).
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()

View File

@ -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<CloudStackClient, CloudStackAsyncClient, CloudStackContext> {
public CloudStackComputeServiceLiveTest() {
provider = "cloudstack";
}
@ -50,9 +50,7 @@ public class CloudStackComputeServiceLiveTest extends BaseComputeServiceLiveTest
public void testAssignability() throws Exception {
@SuppressWarnings("unused")
RestContext<CloudStackClient, CloudStackAsyncClient> tmContext = new ComputeServiceContextFactory(
setupRestProperties()).createContext(provider, identity, credential, ImmutableSet.<Module> of(),
setupProperties()).getProviderSpecificContext();
RestContext<CloudStackClient, CloudStackAsyncClient> tmContext = context.getProviderSpecificContext();
}
// cloudstack does not support metadata

View File

@ -90,9 +90,9 @@ public class CloudStackExperimentLiveTest extends BaseCloudStackClientLiveTest {
Network network = null;
Set<? extends NodeMetadata> 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());
}
}

View File

@ -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<T> extends RestClientTest<T> {
public abstract class BaseCloudStackAsyncClientTest<T> extends BaseAsyncClientTest<T> {
@RequiresHttp
@ConfiguresRestClient
@ -58,10 +55,9 @@ public abstract class BaseCloudStackAsyncClientTest<T> extends RestClientTest<T>
}
@Override
public RestContextSpec<CloudStackClient, CloudStackAsyncClient> 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");
}
}

View File

@ -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<CloudStackClient, CloudStackAsyncClient, CloudStackContext> {
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<CloudStackClient, CloudStackAsyncClient> context;
protected RestContext<CloudStackClient, CloudStackAsyncClient> 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.<Module> 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.<Module> 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.<Module> 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<IPSocket>(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<? extends CloudStackClient, ? extends CloudStackAsyncClient> context, Account.Type type) {
Iterable<User> 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();
}
}

View File

@ -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<S> extends BaseRestClie
public BaseCloudStackRestClientExpectTest() {
provider = "cloudstack";
}
@Override
protected ApiMetadata<?, ?, ?, ?> createApiMetadata() {
return new CloudStackApiMetadata();
}
@Override
public S createClient(Function<HttpRequest, HttpResponse> fn, Module module, Properties props) {
return clientFrom(CloudStackContext.class.cast(new ComputeServiceContextFactory(setupRestProperties())
.createContext(provider, "identity", "credential", ImmutableSet.<Module> of(new ExpectModule(fn),
new NullLoggingModule(), module), props)));
return (S) clientFrom(createInjector(fn, module, props).getInstance(CloudStackContext.class));
}
protected abstract S clientFrom(CloudStackContext context);

View File

@ -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(),

View File

@ -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.<Module>of(
new Log4JLoggingModule(), new SshjSshClientModule()), credentialsAsProperties(keyPair));
ComputeServiceContext<?, ?> context = createContext(credentialsAsProperties(keyPair), setupModules());
CloudStackClient client = CloudStackClient.class.cast(context.getProviderSpecificContext().getApi());
Set<Account> accounts = client.getAccountClient().listAccounts();

View File

@ -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<LoadBalancerRule>(new LoadBalancerRuleActive(client), 60, 1, 1,
TimeUnit.SECONDS);

View File

@ -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;

View File

@ -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()));
}
}
}

View File

@ -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", "");
}

View File

@ -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)

View File

@ -58,7 +58,7 @@ public class ZoneAsyncClientTest extends BaseCloudStackAsyncClientTest<ZoneAsync
assertRequestLineEquals(
httpRequest,
"GET http://localhost:8080/client/api?response=json&command=listZones&apiKey=apiKey&signature=hNz838u4Z1ofz9vRaqYo9GDv1Io%3D HTTP/1.1");
"GET http://localhost:8080/client/api?response=json&command=listZones&apiKey=identity&signature=wLSqVlxuiLXZcHi9IoSAwXNRGFs%3D HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
assertPayloadEquals(httpRequest, null, null, false);

View File

@ -22,20 +22,17 @@ import static org.testng.Assert.assertEquals;
import java.net.URI;
import org.jclouds.PropertiesBuilder;
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.RequestSigner;
import org.jclouds.rest.RestContextBuilder;
import org.jclouds.rest.RestContextFactory;
import org.jclouds.rest.RestContextSpec;
import org.jclouds.rest.AnonymousProviderMetadata;
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.inject.AbstractModule;
import com.google.inject.Injector;
import com.google.inject.Module;
/**
@ -47,22 +44,18 @@ import com.google.inject.Module;
// surefire
@Test(groups = "unit", testName = "QuerySignerTest")
public class QuerySignerTest {
@SuppressWarnings({ "unchecked", "rawtypes" })
public static final RestContextSpec<IntegrationTestClient, IntegrationTestAsyncClient> DUMMY_SPEC = new RestContextSpec<IntegrationTestClient, IntegrationTestAsyncClient>("cloudstack",
"http://localhost:8080/client/api", "2.2", "", "", "apiKey", "secretKey", IntegrationTestClient.class, IntegrationTestAsyncClient.class,
PropertiesBuilder.class, (Class) RestContextBuilder.class, ImmutableList.<Module> 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.<Module> 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++) {

View File

@ -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());

View File

@ -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.
*
* <h3>note</h3>
* <p/>
* 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.
* <p/>
*
* 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<S extends CloudWatchClient, A extends CloudWatchAsyncClient> extends
BaseRestApiMetadata<S, A, RestContext<S, A>, CloudWatchApiMetadata<S, A>> {
@Override
public Builder<S, A> toBuilder() {
return new Builder<S, A>(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, CloudWatchAsyncClient>(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<ConcreteBuilder> {
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<S extends CloudWatchClient, A extends CloudWatchAsyncClient> extends
BaseRestApiMetadata.Builder<S, A, RestContext<S, A>, CloudWatchApiMetadata<S, A>> {
protected Builder(Class<S> client, Class<A> 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<S, A> build() {
return new CloudWatchApiMetadata<S, A>(this);
}
@Override
public Builder<S, A> fromApiMetadata(CloudWatchApiMetadata<S, A> in) {
super.fromApiMetadata(in);
return this;
}
}
public static ConcreteBuilder builder() {
return new ConcreteBuilder();
}
@Override
public ConcreteBuilder toBuilder() {
return builder().fromApiMetadata(this);
}
}

View File

@ -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.
* <p/>
* 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.
* <p/>
* <p/>
* If no <code>Module</code>s are specified, the default {@link JDKLoggingModule logging} and
* {@link JavaUrlHttpCommandExecutorServiceModule http transports} will be installed.
* If no <code>Module</code>s 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<CloudWatchClient, CloudWatchAsyncClient> {
public class CloudWatchContextBuilder<S extends CloudWatchClient, A extends CloudWatchAsyncClient>
extends RestContextBuilder<S, A, RestContext<S, A>, CloudWatchApiMetadata<S, A>> {
public CloudWatchContextBuilder(Properties props) {
super(CloudWatchClient.class, CloudWatchAsyncClient.class, props);
public CloudWatchContextBuilder(ProviderMetadata<S, A, RestContext<S, A>, CloudWatchApiMetadata<S, A>> providerMetadata) {
super(providerMetadata);
}
public CloudWatchContextBuilder(CloudWatchApiMetadata<S, A> apiMetadata) {
super(apiMetadata);
}
@Override

View File

@ -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);
}
}

View File

@ -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);

View File

@ -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<CloudWatchAsyncClient> {
public class CloudWatchAsyncClientTest extends BaseAsyncClientTest<CloudWatchAsyncClient> {
public void testRegisterInstancesWithMeasure() throws SecurityException, NoSuchMethodException, IOException {
Date date = new Date(10000000l);
@ -125,11 +123,10 @@ public class CloudWatchAsyncClientTest extends RestClientTest<CloudWatchAsyncCli
return new TestMonitoringRestClientModule();
}
@SuppressWarnings("rawtypes")
@Override
public RestContextSpec<?, ?> 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

View File

@ -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<RestContext<CloudWatchClient, CloudWatchAsyncClient>> {
public CloudWatchClientLiveTest() {
provider = "cloudwatch";
}
private CloudWatchClient client;
private RestContext<CloudWatchClient, CloudWatchAsyncClient> context;
@BeforeGroups(groups = { "live" })
public void setupClient() {
setupCredentials();
Properties overrides = setupProperties();
context = new RestContextFactory().createContext(provider, ImmutableSet.<Module> 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<Datapoint> datapoints = client.getMetricStatisticsInRegion(
region, "CPUUtilization", "AWS/EC2", cal.getTime(), new Date(), 180, Statistics.AVERAGE,
GetMetricStatisticsOptions.Builder.unit(Unit.PERCENT));
Set<Datapoint> 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();
}
}

View File

@ -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<DeltacloudClient, DeltacloudAsyncClient, ComputeServiceContext<DeltacloudClient, DeltacloudAsyncClient>, 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<ConcreteBuilder> {
protected static Properties defaultProperties() {
return BaseComputeServiceApiMetadata.Builder.defaultProperties();
}
public static class Builder extends BaseComputeServiceApiMetadata.Builder<DeltacloudClient, DeltacloudAsyncClient, ComputeServiceContext<DeltacloudClient, DeltacloudAsyncClient>, 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);
}
}
}

View File

@ -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<DeltacloudClient, DeltacloudAsyncClient> {
public class DeltacloudContextBuilder
extends
ComputeServiceContextBuilder<DeltacloudClient, DeltacloudAsyncClient, ComputeServiceContext<DeltacloudClient, DeltacloudAsyncClient>, DeltacloudApiMetadata> {
public DeltacloudContextBuilder(Properties props) {
super(DeltacloudClient.class, DeltacloudAsyncClient.class, props);
public DeltacloudContextBuilder(
ProviderMetadata<DeltacloudClient, DeltacloudAsyncClient, ComputeServiceContext<DeltacloudClient, DeltacloudAsyncClient>, DeltacloudApiMetadata> providerMetadata) {
super(providerMetadata);
}
public DeltacloudContextBuilder(DeltacloudApiMetadata apiMetadata) {
super(apiMetadata);
}
@Override

View File

@ -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);
}
}

View File

@ -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());
}
}

View File

@ -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<DeltacloudAsyncClient> {
public class DeltacloudAsyncClientTest extends BaseAsyncClientTest<DeltacloudAsyncClient> {
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<DeltacloudAsyncCli
assertRequestLineEquals(httpRequest, "GET http://localhost:3001/api HTTP/1.1");
// for example, using basic authentication, we should get "only one"
// header
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/xml\nAuthorization: Basic Zm9vOmJhcg==\n");
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/xml\nAuthorization: Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==\n");
assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, ParseSax.class);
@ -233,7 +232,7 @@ public class DeltacloudAsyncClientTest extends RestClientTest<DeltacloudAsyncCli
public void testCreateInstance() throws SecurityException, NoSuchMethodException, IOException {
Method method = DeltacloudAsyncClient.class.getMethod("createInstance", String.class,
CreateInstanceOptions[].class);
CreateInstanceOptions[].class);
GeneratedHttpRequest<DeltacloudAsyncClient> 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<DeltacloudAsyncCli
public void testCreateInstanceWithOptions() throws SecurityException, NoSuchMethodException, IOException {
Method method = DeltacloudAsyncClient.class.getMethod("createInstance", String.class,
CreateInstanceOptions[].class);
CreateInstanceOptions[].class);
GeneratedHttpRequest<DeltacloudAsyncClient> 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<DeltacloudAsyncCli
public void testPerformAction() throws IOException, SecurityException, NoSuchMethodException {
Method method = DeltacloudAsyncClient.class.getMethod("performAction", HttpRequest.class);
HttpRequest request = processor.createRequest(method, HttpRequest.builder().method("POST").endpoint(
URI.create("https://delta/instance1/reboot")).build());
HttpRequest request = processor.createRequest(method,
HttpRequest.builder().method("POST").endpoint(URI.create("https://delta/instance1/reboot")).build());
assertRequestLineEquals(request, "POST https://delta/instance1/reboot HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/xml\n");
@ -314,7 +313,8 @@ public class DeltacloudAsyncClientTest extends RestClientTest<DeltacloudAsyncCli
}
@Override
protected Supplier<URI> provideHardwareProfileCollection(Supplier<Set<? extends DeltacloudCollection>> collectionSupplier) {
protected Supplier<URI> provideHardwareProfileCollection(
Supplier<Set<? extends DeltacloudCollection>> collectionSupplier) {
return Suppliers.ofInstance(URI.create("http://localhost:3001/api/profiles"));
}
@ -329,15 +329,13 @@ public class DeltacloudAsyncClientTest extends RestClientTest<DeltacloudAsyncCli
}
@Override
protected Supplier<URI> provideInstanceStateCollection(Supplier<Set<? extends DeltacloudCollection>> collectionSupplier) {
protected Supplier<URI> provideInstanceStateCollection(
Supplier<Set<? extends DeltacloudCollection>> collectionSupplier) {
return Suppliers.ofInstance(URI.create("http://localhost:3001/api/instance_states"));
}
}
@Override
public RestContextSpec<DeltacloudClient, DeltacloudAsyncClient> 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();
}
}

View File

@ -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();
}
}

View File

@ -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<DeltacloudClient, DeltacloudAsyncClient, ComputeServiceContext<DeltacloudClient, DeltacloudAsyncClient>> {
public ReadOnlyDeltacloudClientLiveTest() {
provider = "deltacloud";
}
protected DeltacloudClient client;
protected RestContext<DeltacloudClient, DeltacloudAsyncClient> context;
protected Predicate<IPSocket> socketTester;
protected ImmutableMap<State, Predicate<Instance>> stateChanges;
@BeforeGroups(groups = "live")
public void setupClient() {
setupCredentials();
Properties overrides = setupProperties();
context = new ComputeServiceContextFactory().createContext(provider, ImmutableSet.<Module> 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<IPSocket>(new InetSocketAddressConnect(), 180, 1, TimeUnit.SECONDS);
stateChanges = ImmutableMap.<Instance.State, Predicate<Instance>> of(//
Instance.State.RUNNING, new RetryablePredicate<Instance>(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();
}
}

Some files were not shown because too many files have changed in this diff Show More