mirror of
https://github.com/apache/jclouds.git
synced 2025-02-16 06:56:45 +00:00
JCLOUDS-303. unhook ApiMetadata type hierarchy from ec2
This commit is contained in:
parent
9f12b6309d
commit
7290cc8ea6
@ -35,39 +35,20 @@ import org.jclouds.ec2.config.EC2HttpApiModule;
|
||||
import org.jclouds.rest.internal.BaseHttpApiMetadata;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.reflect.TypeToken;
|
||||
import com.google.inject.Module;
|
||||
|
||||
/**
|
||||
* Implementation of {@link ApiMetadata} for Amazon's EC2 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 EC2ApiMetadata extends BaseHttpApiMetadata<EC2Api> {
|
||||
|
||||
public final class EC2ApiMetadata extends BaseHttpApiMetadata<EC2Api> {
|
||||
|
||||
@Override
|
||||
public Builder<?> toBuilder() {
|
||||
return new ConcreteBuilder().fromApiMetadata(this);
|
||||
public Builder toBuilder() {
|
||||
return new Builder().fromApiMetadata(this);
|
||||
}
|
||||
|
||||
public EC2ApiMetadata() {
|
||||
this(new ConcreteBuilder());
|
||||
super(new Builder());
|
||||
}
|
||||
|
||||
protected EC2ApiMetadata(Builder<?> builder) {
|
||||
protected EC2ApiMetadata(Builder builder) {
|
||||
super(builder);
|
||||
}
|
||||
|
||||
@ -83,8 +64,8 @@ public class EC2ApiMetadata extends BaseHttpApiMetadata<EC2Api> {
|
||||
return properties;
|
||||
}
|
||||
|
||||
public abstract static class Builder<T extends Builder<T>> extends BaseHttpApiMetadata.Builder<EC2Api, T> {
|
||||
protected Builder() {
|
||||
public final static class Builder extends BaseHttpApiMetadata.Builder<EC2Api, Builder> {
|
||||
public Builder() {
|
||||
id("ec2")
|
||||
.name("Amazon Elastic Compute Cloud (EC2) API")
|
||||
.identityName("Access Key ID")
|
||||
@ -101,11 +82,9 @@ public class EC2ApiMetadata extends BaseHttpApiMetadata<EC2Api> {
|
||||
public ApiMetadata build() {
|
||||
return new EC2ApiMetadata(this);
|
||||
}
|
||||
}
|
||||
|
||||
private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
|
||||
|
||||
@Override
|
||||
protected ConcreteBuilder self() {
|
||||
protected Builder self() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jclouds.ec2;
|
||||
|
||||
import static org.jclouds.reflect.Reflection2.typeToken;
|
||||
|
||||
import org.jclouds.ContextBuilder;
|
||||
import org.jclouds.View;
|
||||
import org.jclouds.compute.ComputeServiceContext;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
/**
|
||||
* @author Andrew Bayer
|
||||
*/
|
||||
@Test(groups = "unit", testName = "EC2ContextBuilderTest")
|
||||
public class EC2ContextBuilderText {
|
||||
public void testAssignability() {
|
||||
View view = ContextBuilder.newBuilder(new EC2ApiMetadata()).credentials("foo", "bar")
|
||||
.buildView(typeToken(ComputeServiceContext.class));
|
||||
view.unwrapApi(EC2Api.class);
|
||||
}
|
||||
}
|
@ -23,25 +23,21 @@ import static org.jclouds.ec2.reference.EC2Constants.PROPERTY_EC2_AMI_OWNERS;
|
||||
import static org.jclouds.ec2.reference.EC2Constants.PROPERTY_EC2_AUTO_ALLOCATE_ELASTIC_IPS;
|
||||
import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGIONS;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.jclouds.apis.ApiMetadata;
|
||||
import org.jclouds.ec2.EC2ApiMetadata;
|
||||
import org.jclouds.ec2.compute.EC2ComputeServiceContext;
|
||||
import org.jclouds.ec2.compute.config.EC2ResolveImagesModule;
|
||||
import org.jclouds.openstack.nova.ec2.config.HyphenToNullIso8601Module;
|
||||
import org.jclouds.openstack.nova.ec2.config.NovaEC2ComputeServiceContextModule;
|
||||
import org.jclouds.openstack.nova.ec2.config.NovaEC2HttpApiModule;
|
||||
import org.jclouds.rest.internal.BaseHttpApiMetadata;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.reflect.TypeToken;
|
||||
import com.google.inject.Module;
|
||||
|
||||
/**
|
||||
* Implementation of {@link ApiMetadata} for the OpenStack Nova's EC2-clone API
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class NovaEC2ApiMetadata extends EC2ApiMetadata {
|
||||
public final class NovaEC2ApiMetadata extends BaseHttpApiMetadata<NovaEC2Api> {
|
||||
|
||||
@Override
|
||||
public Builder toBuilder() {
|
||||
@ -49,13 +45,13 @@ public class NovaEC2ApiMetadata extends EC2ApiMetadata {
|
||||
}
|
||||
|
||||
public NovaEC2ApiMetadata() {
|
||||
this(new Builder());
|
||||
super(new Builder());
|
||||
}
|
||||
|
||||
protected NovaEC2ApiMetadata(Builder builder) {
|
||||
super(builder);
|
||||
}
|
||||
|
||||
|
||||
public static Properties defaultProperties() {
|
||||
Properties properties = EC2ApiMetadata.defaultProperties();
|
||||
properties.setProperty(PROPERTY_REGIONS, "nova");
|
||||
@ -73,21 +69,24 @@ public class NovaEC2ApiMetadata extends EC2ApiMetadata {
|
||||
return properties;
|
||||
}
|
||||
|
||||
public static class Builder extends EC2ApiMetadata.Builder<Builder> {
|
||||
@SuppressWarnings("deprecation")
|
||||
protected Builder(){
|
||||
public final static class Builder extends BaseHttpApiMetadata.Builder<NovaEC2Api, Builder> {
|
||||
public Builder() {
|
||||
id("openstack-nova-ec2")
|
||||
.name("OpenStack Nova's EC2-clone API")
|
||||
.version("2009-04-04")
|
||||
.identityName("Access Key ID")
|
||||
.credentialName("Secret Access Key")
|
||||
.defaultEndpoint("http://localhost:8773/services/Cloud")
|
||||
.documentation(URI.create("http://docs.amazonwebservices.com/AWSEC2/latest/APIReference"))
|
||||
.defaultProperties(NovaEC2ApiMetadata.defaultProperties())
|
||||
.view(EC2ComputeServiceContext.class)
|
||||
.defaultModules(ImmutableSet.<Class<? extends Module>>builder()
|
||||
.add(NovaEC2HttpApiModule.class)
|
||||
.add(EC2ResolveImagesModule.class)
|
||||
.add(NovaEC2ComputeServiceContextModule.class)
|
||||
.add(HyphenToNullIso8601Module.class).build());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public NovaEC2ApiMetadata build() {
|
||||
return new NovaEC2ApiMetadata(this);
|
||||
|
@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jclouds.openstack.nova.ec2;
|
||||
|
||||
import static org.jclouds.reflect.Reflection2.typeToken;
|
||||
|
||||
import org.jclouds.ContextBuilder;
|
||||
import org.jclouds.View;
|
||||
import org.jclouds.compute.ComputeServiceContext;
|
||||
import org.jclouds.ec2.EC2Api;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Andrew Bayer
|
||||
*/
|
||||
@Test(groups = "unit", testName = "NovaEC2ContextBuilderTest")
|
||||
public class NovaEC2ContextBuilderTest {
|
||||
|
||||
public void testAssignability() {
|
||||
View view = ContextBuilder.newBuilder(new NovaEC2ApiMetadata()).credentials("foo", "bar")
|
||||
.buildView(typeToken(ComputeServiceContext.class));
|
||||
view.unwrapApi(EC2Api.class);
|
||||
view.unwrapApi(NovaEC2Api.class);
|
||||
}
|
||||
}
|
@ -18,25 +18,20 @@ package org.jclouds.aws.ec2;
|
||||
|
||||
import static org.jclouds.ec2.reference.EC2Constants.PROPERTY_EC2_AMI_OWNERS;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.jclouds.apis.ApiMetadata;
|
||||
import org.jclouds.aws.ec2.compute.AWSEC2ComputeServiceContext;
|
||||
import org.jclouds.aws.ec2.compute.config.AWSEC2ComputeServiceContextModule;
|
||||
import org.jclouds.aws.ec2.config.AWSEC2HttpApiModule;
|
||||
import org.jclouds.ec2.EC2ApiMetadata;
|
||||
import org.jclouds.ec2.compute.config.EC2ResolveImagesModule;
|
||||
import org.jclouds.rest.internal.BaseHttpApiMetadata;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.reflect.TypeToken;
|
||||
import com.google.inject.Module;
|
||||
|
||||
/**
|
||||
* Implementation of {@link ApiMetadata} for the Amazon-specific EC2 API
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class AWSEC2ApiMetadata extends EC2ApiMetadata {
|
||||
public final class AWSEC2ApiMetadata extends BaseHttpApiMetadata<AWSEC2Api> {
|
||||
|
||||
@Override
|
||||
public Builder toBuilder() {
|
||||
@ -44,13 +39,13 @@ public class AWSEC2ApiMetadata extends EC2ApiMetadata {
|
||||
}
|
||||
|
||||
public AWSEC2ApiMetadata() {
|
||||
this(new Builder());
|
||||
super(new Builder());
|
||||
}
|
||||
|
||||
protected AWSEC2ApiMetadata(Builder builder) {
|
||||
super(builder);
|
||||
}
|
||||
|
||||
|
||||
public static Properties defaultProperties() {
|
||||
Properties properties = EC2ApiMetadata.defaultProperties();
|
||||
properties.remove(PROPERTY_EC2_AMI_OWNERS);
|
||||
@ -61,17 +56,20 @@ public class AWSEC2ApiMetadata extends EC2ApiMetadata {
|
||||
return properties;
|
||||
}
|
||||
|
||||
public static class Builder extends EC2ApiMetadata.Builder<Builder> {
|
||||
@SuppressWarnings("deprecation")
|
||||
protected Builder(){
|
||||
public final static class Builder extends BaseHttpApiMetadata.Builder<AWSEC2Api, Builder> {
|
||||
public Builder() {
|
||||
id("aws-ec2")
|
||||
.version("2012-06-01")
|
||||
.name("Amazon-specific EC2 API")
|
||||
.view(AWSEC2ComputeServiceContext.class)
|
||||
.identityName("Access Key ID")
|
||||
.credentialName("Secret Access Key")
|
||||
.defaultEndpoint("https://ec2.us-east-1.amazonaws.com")
|
||||
.documentation(URI.create("http://docs.amazonwebservices.com/AWSEC2/latest/APIReference"))
|
||||
.defaultProperties(AWSEC2ApiMetadata.defaultProperties())
|
||||
.view(AWSEC2ComputeServiceContext.class)
|
||||
.defaultModules(ImmutableSet.<Class<? extends Module>>of(AWSEC2HttpApiModule.class, EC2ResolveImagesModule.class, AWSEC2ComputeServiceContextModule.class));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public AWSEC2ApiMetadata build() {
|
||||
return new AWSEC2ApiMetadata(this);
|
||||
|
@ -18,13 +18,17 @@ package org.jclouds.aws.ec2;
|
||||
|
||||
import static org.jclouds.aws.ec2.reference.AWSEC2Constants.PROPERTY_EC2_AMI_QUERY;
|
||||
import static org.jclouds.ec2.reference.EC2Constants.PROPERTY_EC2_AMI_OWNERS;
|
||||
import static org.jclouds.reflect.Reflection2.typeToken;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.jclouds.ContextBuilder;
|
||||
import org.jclouds.View;
|
||||
import org.jclouds.aws.ec2.compute.config.ImageQuery;
|
||||
import org.jclouds.compute.ComputeServiceContext;
|
||||
import org.jclouds.ec2.EC2Api;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.inject.Key;
|
||||
@ -41,6 +45,13 @@ public class AWSEC2ContextBuilderTest {
|
||||
}, ImageQuery.class));
|
||||
}
|
||||
|
||||
public void testAssignability() {
|
||||
View view = ContextBuilder.newBuilder(new AWSEC2ProviderMetadata()).credentials("foo", "bar")
|
||||
.buildView(typeToken(ComputeServiceContext.class));
|
||||
view.unwrapApi(EC2Api.class);
|
||||
view.unwrapApi(AWSEC2Api.class);
|
||||
}
|
||||
|
||||
public void testConvertImageSyntax() {
|
||||
Properties input = new Properties();
|
||||
input.setProperty(PROPERTY_EC2_AMI_OWNERS, "137112412989,063491364108,099720109477,411009282317");
|
||||
|
Loading…
x
Reference in New Issue
Block a user