Merge pull request #971 from jclouds/override-timeout-cloudstack-ec2

added configuration necessary to override timeout default for ami create
This commit is contained in:
Adrian Cole 2012-11-08 15:19:51 -08:00
commit 3aa47bb499
8 changed files with 331 additions and 11 deletions

View File

@ -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<RestContext<CloudStackEC2Client, CloudStackEC2AsyncClient>> CONTEXT_TOKEN = new TypeToken<RestContext<CloudStackEC2Client, CloudStackEC2AsyncClient>>() {
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.<Class<? extends Module>>builder()
.add(CloudStackEC2RestClientModule.class)
.add(EC2ResolveImagesModule.class)
.add(EC2ComputeServiceContextModule.class).build());
}
@Override
public CloudStackEC2ApiMetadata build() {
return new CloudStackEC2ApiMetadata(this);

View File

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

View File

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

View File

@ -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<CloudStackEC2Client, CloudStackEC2AsyncClient> {
public static final Map<Class<?>, Class<?>> DELEGATE_MAP = ImmutableMap.<Class<?>, 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;
}
}

View File

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

View File

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

View File

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

View File

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