diff --git a/apis/ec2/src/main/java/org/jclouds/ec2/EC2ApiMetadata.java b/apis/ec2/src/main/java/org/jclouds/ec2/EC2ApiMetadata.java
index 47fc54ba18..81136dd707 100644
--- a/apis/ec2/src/main/java/org/jclouds/ec2/EC2ApiMetadata.java
+++ b/apis/ec2/src/main/java/org/jclouds/ec2/EC2ApiMetadata.java
@@ -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.
- *
- *
note
- *
- * This class allows overriding of types {@code S}(client) and {@code A}
- * (asyncClient), so that children can add additional methods not declared here,
- * such as new features from AWS.
- *
- *
- * As this is a popular api, we also allow overrides for type {@code C}
- * (context). This allows subtypes to add in new feature groups or extensions,
- * not present in the base api. For example, you could make a subtype for
- * context, that exposes admin operations.
- *
- * @author Adrian Cole
- */
-public class EC2ApiMetadata extends BaseHttpApiMetadata {
-
+public final class EC2ApiMetadata extends BaseHttpApiMetadata {
@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 {
return properties;
}
- public abstract static class Builder> extends BaseHttpApiMetadata.Builder {
- protected Builder() {
+ public final static class Builder extends BaseHttpApiMetadata.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 {
public ApiMetadata build() {
return new EC2ApiMetadata(this);
}
- }
-
- private static class ConcreteBuilder extends Builder {
+
@Override
- protected ConcreteBuilder self() {
+ protected Builder self() {
return this;
}
}
diff --git a/apis/ec2/src/test/java/org/jclouds/ec2/EC2ContextBuilderText.java b/apis/ec2/src/test/java/org/jclouds/ec2/EC2ContextBuilderText.java
new file mode 100644
index 0000000000..e672fd3b43
--- /dev/null
+++ b/apis/ec2/src/test/java/org/jclouds/ec2/EC2ContextBuilderText.java
@@ -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);
+ }
+}
diff --git a/apis/openstack-nova-ec2/src/main/java/org/jclouds/openstack/nova/ec2/NovaEC2ApiMetadata.java b/apis/openstack-nova-ec2/src/main/java/org/jclouds/openstack/nova/ec2/NovaEC2ApiMetadata.java
index d24e334a66..a6f1ab0c44 100644
--- a/apis/openstack-nova-ec2/src/main/java/org/jclouds/openstack/nova/ec2/NovaEC2ApiMetadata.java
+++ b/apis/openstack-nova-ec2/src/main/java/org/jclouds/openstack/nova/ec2/NovaEC2ApiMetadata.java
@@ -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 {
@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 {
- @SuppressWarnings("deprecation")
- protected Builder(){
+ public final static class Builder extends BaseHttpApiMetadata.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.>builder()
.add(NovaEC2HttpApiModule.class)
.add(EC2ResolveImagesModule.class)
.add(NovaEC2ComputeServiceContextModule.class)
.add(HyphenToNullIso8601Module.class).build());
}
-
+
@Override
public NovaEC2ApiMetadata build() {
return new NovaEC2ApiMetadata(this);
diff --git a/apis/openstack-nova-ec2/src/test/java/org/jclouds/openstack/nova/ec2/NovaEC2ContextBuilderTest.java b/apis/openstack-nova-ec2/src/test/java/org/jclouds/openstack/nova/ec2/NovaEC2ContextBuilderTest.java
new file mode 100644
index 0000000000..4da970ed21
--- /dev/null
+++ b/apis/openstack-nova-ec2/src/test/java/org/jclouds/openstack/nova/ec2/NovaEC2ContextBuilderTest.java
@@ -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);
+ }
+}
diff --git a/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/AWSEC2ApiMetadata.java b/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/AWSEC2ApiMetadata.java
index 1724331ec9..8a915acc57 100644
--- a/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/AWSEC2ApiMetadata.java
+++ b/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/AWSEC2ApiMetadata.java
@@ -18,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 {
@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 {
- @SuppressWarnings("deprecation")
- protected Builder(){
+ public final static class Builder extends BaseHttpApiMetadata.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.>of(AWSEC2HttpApiModule.class, EC2ResolveImagesModule.class, AWSEC2ComputeServiceContextModule.class));
}
-
+
@Override
public AWSEC2ApiMetadata build() {
return new AWSEC2ApiMetadata(this);
diff --git a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/AWSEC2ContextBuilderTest.java b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/AWSEC2ContextBuilderTest.java
index 93c9700f40..42a64507c1 100644
--- a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/AWSEC2ContextBuilderTest.java
+++ b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/AWSEC2ContextBuilderTest.java
@@ -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");