Updated Branches:
  refs/heads/master bd984ba50 -> 7290cc8ea

JCLOUDS-303. unhook ApiMetadata type hierarchy from ec2


Project: http://git-wip-us.apache.org/repos/asf/incubator-jclouds/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-jclouds/commit/7290cc8e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-jclouds/tree/7290cc8e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-jclouds/diff/7290cc8e

Branch: refs/heads/master
Commit: 7290cc8ea60dc7ff8d7435e93a5030dd320d4ba2
Parents: 9f12b63
Author: Andrew Bayer <[email protected]>
Authored: Fri Sep 27 15:08:47 2013 -0700
Committer: Adrian Cole <[email protected]>
Committed: Fri Sep 27 15:58:25 2013 -0700

----------------------------------------------------------------------
 .../java/org/jclouds/ec2/EC2ApiMetadata.java    | 39 +++++--------------
 .../org/jclouds/ec2/EC2ContextBuilderText.java  | 36 ++++++++++++++++++
 .../openstack/nova/ec2/NovaEC2ApiMetadata.java  | 27 +++++++------
 .../nova/ec2/NovaEC2ContextBuilderTest.java     | 40 ++++++++++++++++++++
 .../org/jclouds/aws/ec2/AWSEC2ApiMetadata.java  | 28 +++++++-------
 .../aws/ec2/AWSEC2ContextBuilderTest.java       | 11 ++++++
 6 files changed, 122 insertions(+), 59 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-jclouds/blob/7290cc8e/apis/ec2/src/main/java/org/jclouds/ec2/EC2ApiMetadata.java
----------------------------------------------------------------------
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 47fc54b..81136dd 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.
- * 
- * <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;
       }
    }

http://git-wip-us.apache.org/repos/asf/incubator-jclouds/blob/7290cc8e/apis/ec2/src/test/java/org/jclouds/ec2/EC2ContextBuilderText.java
----------------------------------------------------------------------
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 0000000..e672fd3
--- /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);
+   }
+}

http://git-wip-us.apache.org/repos/asf/incubator-jclouds/blob/7290cc8e/apis/openstack-nova-ec2/src/main/java/org/jclouds/openstack/nova/ec2/NovaEC2ApiMetadata.java
----------------------------------------------------------------------
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 d24e334..a6f1ab0 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<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);

http://git-wip-us.apache.org/repos/asf/incubator-jclouds/blob/7290cc8e/apis/openstack-nova-ec2/src/test/java/org/jclouds/openstack/nova/ec2/NovaEC2ContextBuilderTest.java
----------------------------------------------------------------------
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 0000000..4da970e
--- /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);
+   }
+}

http://git-wip-us.apache.org/repos/asf/incubator-jclouds/blob/7290cc8e/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/AWSEC2ApiMetadata.java
----------------------------------------------------------------------
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 1724331..8a915ac 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<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);

http://git-wip-us.apache.org/repos/asf/incubator-jclouds/blob/7290cc8e/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/AWSEC2ContextBuilderTest.java
----------------------------------------------------------------------
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 93c9700..42a6450 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");

Reply via email to