diff --git a/labs/cloudstack-ec2/src/main/java/org/jclouds/cloudstack/ec2/CloudStackEC2ApiMetadata.java b/labs/cloudstack-ec2/src/main/java/org/jclouds/cloudstack/ec2/CloudStackEC2ApiMetadata.java index f2f18c0c7e..da17e6c0e7 100644 --- a/labs/cloudstack-ec2/src/main/java/org/jclouds/cloudstack/ec2/CloudStackEC2ApiMetadata.java +++ b/labs/cloudstack-ec2/src/main/java/org/jclouds/cloudstack/ec2/CloudStackEC2ApiMetadata.java @@ -22,19 +22,29 @@ import java.net.URI; import java.util.Properties; import org.jclouds.apis.ApiMetadata; +import org.jclouds.cloudstack.ec2.config.CloudStackEC2RestClientModule; import org.jclouds.ec2.EC2ApiMetadata; -import org.jclouds.ec2.EC2AsyncClient; -import org.jclouds.ec2.EC2Client; +import org.jclouds.ec2.compute.config.EC2ComputeServiceContextModule; +import org.jclouds.ec2.compute.config.EC2ResolveImagesModule; +import org.jclouds.rest.RestContext; +import com.google.common.collect.ImmutableSet; +import com.google.common.reflect.TypeToken; +import com.google.inject.Module; /** - * Implementation of {@link ApiMetadata} for the CloudStackEC2 (EC2 clone) api. + * Implementation of {@link ApiMetadata} for the CloudStack's EC2-clone API * * @author Adrian Cole */ public class CloudStackEC2ApiMetadata extends EC2ApiMetadata { + /** The serialVersionUID */ - private static final long serialVersionUID = 3060225665040763827L; + private static final long serialVersionUID = -8539835226183747429L; + + public static final TypeToken> CONTEXT_TOKEN = new TypeToken>() { + private static final long serialVersionUID = -6449920293625658712L; + }; private static Builder builder() { return new Builder(); @@ -52,23 +62,29 @@ public class CloudStackEC2ApiMetadata extends EC2ApiMetadata { protected CloudStackEC2ApiMetadata(Builder builder) { super(builder); } - + public static Properties defaultProperties() { Properties properties = EC2ApiMetadata.defaultProperties(); + // any property overrides here return properties; } public static class Builder extends EC2ApiMetadata.Builder { - protected Builder() { - super(EC2Client.class, EC2AsyncClient.class); + protected Builder(){ + super(CloudStackEC2Client.class, CloudStackEC2AsyncClient.class); id("cloudstack-ec2") - .name("CloudStackEC2 (EC2 clone) API") + .name("CloudBridge (EC2 clone) API") .version("2010-11-15") .defaultEndpoint("http://localhost:8090/bridge/rest/AmazonEC2") .documentation(URI.create("http://docs.cloudstack.org/CloudBridge_Documentation")) - .defaultProperties(CloudStackEC2ApiMetadata.defaultProperties()); + .defaultProperties(CloudStackEC2ApiMetadata.defaultProperties()) + .context(CONTEXT_TOKEN) + .defaultModules(ImmutableSet.>builder() + .add(CloudStackEC2RestClientModule.class) + .add(EC2ResolveImagesModule.class) + .add(EC2ComputeServiceContextModule.class).build()); } - + @Override public CloudStackEC2ApiMetadata build() { return new CloudStackEC2ApiMetadata(this); diff --git a/labs/cloudstack-ec2/src/main/java/org/jclouds/cloudstack/ec2/CloudStackEC2AsyncClient.java b/labs/cloudstack-ec2/src/main/java/org/jclouds/cloudstack/ec2/CloudStackEC2AsyncClient.java new file mode 100644 index 0000000000..43dabfeb96 --- /dev/null +++ b/labs/cloudstack-ec2/src/main/java/org/jclouds/cloudstack/ec2/CloudStackEC2AsyncClient.java @@ -0,0 +1,37 @@ +/** + * 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.ec2; + +import org.jclouds.cloudstack.ec2.services.CloudStackAMIAsyncClient; +import org.jclouds.ec2.EC2AsyncClient; +import org.jclouds.rest.annotations.Delegate; + +/** + * Provides asynchronous access to EC2 services. + * + * @author Adrian Cole + */ +public interface CloudStackEC2AsyncClient extends EC2AsyncClient { + /** + * {@inheritDoc} + */ + @Delegate + @Override + CloudStackAMIAsyncClient getAMIServices(); +} diff --git a/labs/cloudstack-ec2/src/main/java/org/jclouds/cloudstack/ec2/CloudStackEC2Client.java b/labs/cloudstack-ec2/src/main/java/org/jclouds/cloudstack/ec2/CloudStackEC2Client.java new file mode 100644 index 0000000000..9f9fc16873 --- /dev/null +++ b/labs/cloudstack-ec2/src/main/java/org/jclouds/cloudstack/ec2/CloudStackEC2Client.java @@ -0,0 +1,42 @@ +/** + * 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.ec2; + +import java.util.concurrent.TimeUnit; + +import org.jclouds.cloudstack.ec2.services.CloudStackAMIClient; +import org.jclouds.concurrent.Timeout; +import org.jclouds.ec2.EC2Client; +import org.jclouds.rest.annotations.Delegate; + +/** + * Provides synchronous access to EC2 services. + * + * @author Adrian Cole + */ +@Timeout(duration = 180, timeUnit = TimeUnit.SECONDS) +public interface CloudStackEC2Client extends EC2Client { + + /** + * {@inheritDoc} + */ + @Delegate + @Override + CloudStackAMIClient getAMIServices(); +} diff --git a/labs/cloudstack-ec2/src/main/java/org/jclouds/cloudstack/ec2/config/CloudStackEC2RestClientModule.java b/labs/cloudstack-ec2/src/main/java/org/jclouds/cloudstack/ec2/config/CloudStackEC2RestClientModule.java new file mode 100644 index 0000000000..6458057bcc --- /dev/null +++ b/labs/cloudstack-ec2/src/main/java/org/jclouds/cloudstack/ec2/config/CloudStackEC2RestClientModule.java @@ -0,0 +1,95 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.cloudstack.ec2.config; + +import java.util.Map; + +import javax.inject.Singleton; + +import org.jclouds.cloudstack.ec2.CloudStackEC2AsyncClient; +import org.jclouds.cloudstack.ec2.CloudStackEC2Client; +import org.jclouds.cloudstack.ec2.services.CloudStackAMIAsyncClient; +import org.jclouds.cloudstack.ec2.services.CloudStackAMIClient; +import org.jclouds.ec2.EC2AsyncClient; +import org.jclouds.ec2.EC2Client; +import org.jclouds.ec2.config.EC2RestClientModule; +import org.jclouds.ec2.features.WindowsApi; +import org.jclouds.ec2.features.WindowsAsyncApi; +import org.jclouds.ec2.services.AvailabilityZoneAndRegionAsyncClient; +import org.jclouds.ec2.services.AvailabilityZoneAndRegionClient; +import org.jclouds.ec2.services.ElasticBlockStoreAsyncClient; +import org.jclouds.ec2.services.ElasticBlockStoreClient; +import org.jclouds.ec2.services.ElasticIPAddressAsyncClient; +import org.jclouds.ec2.services.ElasticIPAddressClient; +import org.jclouds.ec2.services.InstanceAsyncClient; +import org.jclouds.ec2.services.InstanceClient; +import org.jclouds.ec2.services.KeyPairAsyncClient; +import org.jclouds.ec2.services.KeyPairClient; +import org.jclouds.ec2.services.SecurityGroupAsyncClient; +import org.jclouds.ec2.services.SecurityGroupClient; +import org.jclouds.ec2.services.WindowsAsyncClient; +import org.jclouds.ec2.services.WindowsClient; +import org.jclouds.rest.ConfiguresRestClient; + +import com.google.common.collect.ImmutableMap; +import com.google.common.reflect.TypeToken; +import com.google.inject.Provides; + +/** + * + * @author Adrian Cole + */ +@ConfiguresRestClient +public class CloudStackEC2RestClientModule extends EC2RestClientModule { + public static final Map, Class> DELEGATE_MAP = ImmutableMap., Class> builder()// + .put(CloudStackAMIClient.class, CloudStackAMIAsyncClient.class)// + .put(ElasticIPAddressClient.class, ElasticIPAddressAsyncClient.class)// + .put(InstanceClient.class, InstanceAsyncClient.class)// + .put(KeyPairClient.class, KeyPairAsyncClient.class)// + .put(SecurityGroupClient.class, SecurityGroupAsyncClient.class)// + .put(WindowsClient.class, WindowsAsyncClient.class)// + .put(AvailabilityZoneAndRegionClient.class, AvailabilityZoneAndRegionAsyncClient.class)// + .put(ElasticBlockStoreClient.class, ElasticBlockStoreAsyncClient.class)// + .put(WindowsApi.class, WindowsAsyncApi.class)// + .build(); + + public CloudStackEC2RestClientModule() { + super(TypeToken.of(CloudStackEC2Client.class), TypeToken.of(CloudStackEC2AsyncClient.class), DELEGATE_MAP); + } + + @Override + protected void configure() { + super.configure(); + // override parsers, etc. here + // ex. + // bind(DescribeImagesResponseHandler.class).to(CloudStackDescribeImagesResponseHandler.class); + } + + @Singleton + @Provides + EC2Client provide(CloudStackEC2Client in) { + return in; + } + + @Singleton + @Provides + EC2AsyncClient provide(CloudStackEC2AsyncClient in) { + return in; + } +} diff --git a/labs/cloudstack-ec2/src/main/java/org/jclouds/cloudstack/ec2/services/CloudStackAMIAsyncClient.java b/labs/cloudstack-ec2/src/main/java/org/jclouds/cloudstack/ec2/services/CloudStackAMIAsyncClient.java new file mode 100644 index 0000000000..1701f0e1f9 --- /dev/null +++ b/labs/cloudstack-ec2/src/main/java/org/jclouds/cloudstack/ec2/services/CloudStackAMIAsyncClient.java @@ -0,0 +1,33 @@ +/** + * 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.ec2.services; + +import org.jclouds.aws.filters.FormSigner; +import org.jclouds.ec2.services.AMIAsyncClient; +import org.jclouds.rest.annotations.RequestFilters; +import org.jclouds.rest.annotations.VirtualHost; + +/** + * @author Adrian Cole + */ +@RequestFilters(FormSigner.class) +@VirtualHost +public interface CloudStackAMIAsyncClient extends AMIAsyncClient { + +} diff --git a/labs/cloudstack-ec2/src/main/java/org/jclouds/cloudstack/ec2/services/CloudStackAMIClient.java b/labs/cloudstack-ec2/src/main/java/org/jclouds/cloudstack/ec2/services/CloudStackAMIClient.java new file mode 100644 index 0000000000..64457b23b9 --- /dev/null +++ b/labs/cloudstack-ec2/src/main/java/org/jclouds/cloudstack/ec2/services/CloudStackAMIClient.java @@ -0,0 +1,43 @@ +/** + * 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.ec2.services; + +import java.util.concurrent.TimeUnit; + +import org.jclouds.concurrent.Timeout; +import org.jclouds.ec2.options.CreateImageOptions; +import org.jclouds.ec2.services.AMIClient; +import org.jclouds.javax.annotation.Nullable; + +/** + * + * @author Adrian Cole + */ +@Timeout(duration = 90, timeUnit = TimeUnit.SECONDS) +public interface CloudStackAMIClient extends AMIClient { + + /** + * {@inheritDoc} + */ + @Override + //overriding to set a new default timeout as this is a blocking call + @Timeout(duration = 15, timeUnit = TimeUnit.MINUTES) + String createImageInRegion(@Nullable String region, String name, String instanceId, CreateImageOptions... options); + +} diff --git a/labs/cloudstack-ec2/src/test/java/org/jclouds/cloudstack/ec2/internal/BaseCloudStackEC2RestClientExpectTest.java b/labs/cloudstack-ec2/src/test/java/org/jclouds/cloudstack/ec2/internal/BaseCloudStackEC2RestClientExpectTest.java new file mode 100644 index 0000000000..2c7b8795a6 --- /dev/null +++ b/labs/cloudstack-ec2/src/test/java/org/jclouds/cloudstack/ec2/internal/BaseCloudStackEC2RestClientExpectTest.java @@ -0,0 +1,54 @@ +/** + * 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.ec2.internal; + +import org.jclouds.cloudstack.ec2.CloudStackEC2Client; +import org.jclouds.cloudstack.ec2.config.CloudStackEC2RestClientModule; +import org.jclouds.date.DateService; +import org.jclouds.rest.ConfiguresRestClient; +import org.jclouds.rest.internal.BaseRestClientExpectTest; + +import com.google.inject.Module; +import com.google.inject.Provides; + +/** + * + * @author Adrian Cole + */ +public abstract class BaseCloudStackEC2RestClientExpectTest extends BaseRestClientExpectTest { + protected static final String CONSTANT_DATE = "2012-04-16T15:54:08.897Z"; + + public BaseCloudStackEC2RestClientExpectTest() { + provider = "cloudstack-ec2"; + } + + @ConfiguresRestClient + private static final class TestCloudStackEC2RestClientModule extends CloudStackEC2RestClientModule { + @Override + @Provides + protected String provideTimeStamp(DateService dateService) { + return CONSTANT_DATE; + } + } + + @Override + protected Module createModule() { + return new TestCloudStackEC2RestClientModule(); + } +} diff --git a/labs/cloudstack-ec2/src/test/java/org/jclouds/cloudstack/ec2/services/CloudStackEC2InstanceClientLiveTest.java b/labs/cloudstack-ec2/src/test/java/org/jclouds/cloudstack/ec2/services/CloudStackEC2InstanceClientLiveTest.java index c11f846efc..9671981f1f 100644 --- a/labs/cloudstack-ec2/src/test/java/org/jclouds/cloudstack/ec2/services/CloudStackEC2InstanceClientLiveTest.java +++ b/labs/cloudstack-ec2/src/test/java/org/jclouds/cloudstack/ec2/services/CloudStackEC2InstanceClientLiveTest.java @@ -25,7 +25,7 @@ import org.testng.annotations.Test; * * @author Adrian Cole */ -@Test(groups = "live", singleThreaded = true, testName = "CloudStackEC2InstanceClientLiveTest") +@Test(groups = "live", singleThreaded = true, testName = "CloudStackInstanceClientLiveTest") public class CloudStackEC2InstanceClientLiveTest extends InstanceClientLiveTest { public CloudStackEC2InstanceClientLiveTest() { provider = "cloudstack-ec2";