From 7e270c5ddb29f16e72c0b979cf7a416cc17b226b Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Sun, 24 Feb 2013 14:40:31 -0800 Subject: [PATCH] various cleanups to get ec2 subnet api up to latest --- .../java/org/jclouds/ec2/domain/Subnet.java | 417 +++++++++--------- .../org/jclouds/ec2/features/SubnetApi.java | 12 +- .../jclouds/ec2/features/SubnetAsyncApi.java | 5 +- .../xml/DescribeSubnetsResponseHandler.java | 117 ++--- .../org/jclouds/ec2/xml/SubnetHandler.java | 137 +++--- .../ec2/features/SubnetApiExpectTest.java | 57 +-- .../ec2/features/SubnetApiLiveTest.java | 12 +- .../ec2/config/NovaEC2RestClientModule.java | 9 + .../ec2/features/NovaSubnetApiLiveTest.java | 33 ++ .../features/CloudStackSubnetApiLiveTest.java | 33 ++ .../ec2/config/AWSEC2RestClientModule.java | 3 + .../ec2/features/AWSSubnetApiLiveTest.java | 33 ++ 12 files changed, 445 insertions(+), 423 deletions(-) create mode 100644 apis/openstack-nova-ec2/src/test/java/org/jclouds/openstack/nova/ec2/features/NovaSubnetApiLiveTest.java create mode 100644 labs/cloudstack-ec2/src/test/java/org/jclouds/cloudstack/ec2/features/CloudStackSubnetApiLiveTest.java create mode 100644 providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/features/AWSSubnetApiLiveTest.java diff --git a/apis/ec2/src/main/java/org/jclouds/ec2/domain/Subnet.java b/apis/ec2/src/main/java/org/jclouds/ec2/domain/Subnet.java index 13f2137b89..5fd5510c9c 100644 --- a/apis/ec2/src/main/java/org/jclouds/ec2/domain/Subnet.java +++ b/apis/ec2/src/main/java/org/jclouds/ec2/domain/Subnet.java @@ -24,249 +24,232 @@ import java.util.Map; import com.google.common.base.Objects; import com.google.common.base.Objects.ToStringHelper; -import com.google.common.base.Optional; -import com.google.common.base.Strings; import com.google.common.collect.ImmutableMap; -import com.google.common.collect.Maps; /** * Amazon EC2 VPCs contain one or more subnets. * - * @see doc + * @see doc * * @author Adrian Cole * @author Andrew Bayer */ -public class Subnet { +public final class Subnet { - public static enum State { - /** - * The subnet is available for use. - */ - AVAILABLE, - /** - * The subnet is not yet available for use. - */ - PENDING, UNRECOGNIZED; - public String value() { - return name().toLowerCase(); - } - - public static State fromValue(String v) { - try { - return valueOf(v.toUpperCase()); - } catch (IllegalArgumentException e) { - return UNRECOGNIZED; - } - } - } - - private final String subnetId; - private final State subnetState; - private final String vpcId; - private final String cidrBlock; - private final int availableIpAddressCount; - private final String availabilityZone; - private final Map tags; + public static enum State { + /** + * The subnet is available for use. + */ + AVAILABLE, + /** + * The subnet is not yet available for use. + */ + PENDING, UNRECOGNIZED; + public String value() { + return name().toLowerCase(); + } - public Subnet(String subnetId, State subnetState, String vpcId, String cidrBlock, - int availableIpAddressCount, String availabilityZone, Map tags) { - this.subnetId = checkNotNull(subnetId, "subnetId"); - this.subnetState = checkNotNull(subnetState, "subnetState for %s", subnetId); - this.vpcId = checkNotNull(vpcId, "vpcId for %s", subnetId); - this.cidrBlock = checkNotNull(cidrBlock, "cidrBlock for %s", subnetId); - this.availableIpAddressCount = availableIpAddressCount; - this.availabilityZone = checkNotNull(availabilityZone, "availabilityZone for %s", subnetId); - this.tags = ImmutableMap. copyOf(checkNotNull(tags, "tags for %s", subnetId)); - - } + public static State fromValue(String v) { + try { + return valueOf(v.toUpperCase()); + } catch (IllegalArgumentException e) { + return UNRECOGNIZED; + } + } + } - /** - * The subnet ID, ex. subnet-c5473ba8 - */ - public String getSubnetId() { - return subnetId; - } - - /** - * The subnet state - either available or pending. - */ - public State getSubnetState() { - return subnetState; - } - - /** - * The vpc ID this subnet belongs to. - */ - public String getVpcId() { - return vpcId; - } + private final String subnetId; + private final State subnetState; + private final String vpcId; + private final String cidrBlock; + private final int availableIpAddressCount; + private final String availabilityZone; + private final Map tags; - /** - * The CIDR block for this subnet. - */ - public String getCidrBlock() { - return cidrBlock; - } + private Subnet(String subnetId, State subnetState, String vpcId, String cidrBlock, int availableIpAddressCount, + String availabilityZone, ImmutableMap tags) { + this.subnetId = checkNotNull(subnetId, "subnetId"); + this.subnetState = checkNotNull(subnetState, "subnetState for %s", subnetId); + this.vpcId = checkNotNull(vpcId, "vpcId for %s", subnetId); + this.cidrBlock = checkNotNull(cidrBlock, "cidrBlock for %s", subnetId); + this.availableIpAddressCount = availableIpAddressCount; + this.availabilityZone = checkNotNull(availabilityZone, "availabilityZone for %s", subnetId); + this.tags = checkNotNull(tags, "tags for %s", subnetId); + } - /** - * The number of available IPs in this subnet. - */ - public int getAvailableIpAddressCount() { - return availableIpAddressCount; - } + /** + * The subnet ID, ex. subnet-c5473ba8 + */ + public String getSubnetId() { + return subnetId; + } - /** - * The availability zone this subnet is in. - */ - public String getAvailabilityZone() { - return availabilityZone; - } + /** + * The subnet state - either available or pending. + */ + public State getSubnetState() { + return subnetState; + } - /** - * Tags that are attached to this subnet. - */ - public Map getTags() { - return tags; - } + /** + * The vpc ID this subnet belongs to. + */ + public String getVpcId() { + return vpcId; + } - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return Objects.hashCode(subnetId, vpcId, availabilityZone); - } + /** + * The CIDR block for this subnet. + */ + public String getCidrBlock() { + return cidrBlock; + } - /** - * {@inheritDoc} - */ - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - Subnet other = (Subnet) obj; - return Objects.equal(this.subnetId, other.subnetId) - && Objects.equal(this.vpcId, other.vpcId) - && Objects.equal(this.availabilityZone, other.availabilityZone); - } - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return string().toString(); - } + /** + * The number of available IPs in this subnet. + */ + public int getAvailableIpAddressCount() { + return availableIpAddressCount; + } - private final ToStringHelper string() { - return Objects.toStringHelper(this).omitNullValues().add("subnetId", subnetId) - .add("subnetState", subnetState).add("vpcId", vpcId) - .add("cidrBlock", cidrBlock).add("availableIpAddressCount", availableIpAddressCount) + /** + * The availability zone this subnet is in. + */ + public String getAvailabilityZone() { + return availabilityZone; + } + + /** + * Tags that are attached to this subnet. + */ + public Map getTags() { + return tags; + } + + @Override + public int hashCode() { + return Objects.hashCode(subnetId, vpcId, availabilityZone); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null || getClass() != obj.getClass()) + return false; + Subnet that = Subnet.class.cast(obj); + return Objects.equal(this.subnetId, that.subnetId) && Objects.equal(this.vpcId, that.vpcId) + && Objects.equal(this.availabilityZone, that.availabilityZone); + } + + @Override + public String toString() { + return string().toString(); + } + + private final ToStringHelper string() { + return Objects.toStringHelper(this).omitNullValues().add("subnetId", subnetId).add("subnetState", subnetState) + .add("vpcId", vpcId).add("cidrBlock", cidrBlock).add("availableIpAddressCount", availableIpAddressCount) .add("availabilityZone", availabilityZone).add("tags", tags); - } - - public static Builder builder() { - return new Builder(); - } - - public Builder toBuilder() { - return builder().fromSubnet(this); - } + } - public static class Builder { - private String subnetId; - private State subnetState; - private String vpcId; - private String cidrBlock; - private int availableIpAddressCount; - private String availabilityZone; - private Map tags = Maps.newLinkedHashMap(); + public static Builder builder() { + return new Builder(); + } - /** - * @see Subnet#getSubnetId() - */ - public Builder subnetId(String subnetId) { - this.subnetId = subnetId; - return this; - } + public Builder toBuilder() { + return builder().from(this); + } - /** - * @see Subnet#getState() - */ - public Builder subnetState(State subnetState) { - this.subnetState = subnetState; - return this; - } + public final static class Builder { + private String subnetId; + private State subnetState; + private String vpcId; + private String cidrBlock; + private int availableIpAddressCount; + private String availabilityZone; + private ImmutableMap.Builder tags = ImmutableMap. builder(); - /** - * @see Subnet#getVpcId() - */ - public Builder vpcId(String vpcId) { - this.vpcId = vpcId; - return this; - } + /** + * @see Subnet#getSubnetId() + */ + public Builder subnetId(String subnetId) { + this.subnetId = subnetId; + return this; + } - /** - * @see Subnet#getCidrBlock() - */ - public Builder cidrBlock(String cidrBlock) { - this.cidrBlock = cidrBlock; - return this; - } - - /** - * @see Subnet#getAvailableIpAddressCount() - */ - public Builder availableIpAddressCount(int availableIpAddressCount) { - this.availableIpAddressCount = availableIpAddressCount; - return this; - } - - /** - * @see Subnet#getAvailabilityZone() - */ - public Builder availabilityZone(String availabilityZone) { - this.availabilityZone = availabilityZone; - return this; - } + /** + * @see Subnet#getState() + */ + public Builder subnetState(State subnetState) { + this.subnetState = subnetState; + return this; + } - /** - * @see Subnet#getTags() - */ - public Builder tags(Map tags) { - this.tags = ImmutableMap.copyOf(checkNotNull(tags, "tags")); - return this; - } + /** + * @see Subnet#getVpcId() + */ + public Builder vpcId(String vpcId) { + this.vpcId = vpcId; + return this; + } - /** - * @see Subnet#getTags() - */ - public Builder tag(String key, String value) { - if (key != null) - this.tags.put(key, Strings.nullToEmpty(value)); - return this; - } - - public Subnet build() { - return new Subnet(subnetId, subnetState, vpcId, cidrBlock, availableIpAddressCount, - availabilityZone, tags); - } + /** + * @see Subnet#getCidrBlock() + */ + public Builder cidrBlock(String cidrBlock) { + this.cidrBlock = cidrBlock; + return this; + } - public Builder fromSubnet(Subnet in) { - return this.subnetId(in.getSubnetId()) - .subnetState(in.getSubnetState()) - .vpcId(in.getVpcId()) - .cidrBlock(in.getCidrBlock()) - .availableIpAddressCount(in.getAvailableIpAddressCount()) - .availabilityZone(in.getAvailabilityZone()) - .tags(in.getTags()); - } - } + /** + * @see Subnet#getAvailableIpAddressCount() + */ + public Builder availableIpAddressCount(int availableIpAddressCount) { + this.availableIpAddressCount = availableIpAddressCount; + return this; + } + + /** + * @see Subnet#getAvailabilityZone() + */ + public Builder availabilityZone(String availabilityZone) { + this.availabilityZone = availabilityZone; + return this; + } + + /** + * @see Subnet#getTags() + */ + public Builder tags(Map tags) { + this.tags.putAll(checkNotNull(tags, "tags")); + return this; + } + + /** + * @see Subnet#getTags() + */ + public Builder tag(String key) { + return tag(key, ""); + } + + /** + * @see Subnet#getTags() + */ + public Builder tag(String key, String value) { + this.tags.put(checkNotNull(key, "key"), checkNotNull(value, "value")); + return this; + } + + public Subnet build() { + return new Subnet(subnetId, subnetState, vpcId, cidrBlock, availableIpAddressCount, availabilityZone, + tags.build()); + } + + public Builder from(Subnet in) { + return this.subnetId(in.getSubnetId()).subnetState(in.getSubnetState()).vpcId(in.getVpcId()) + .cidrBlock(in.getCidrBlock()).availableIpAddressCount(in.getAvailableIpAddressCount()) + .availabilityZone(in.getAvailabilityZone()).tags(in.getTags()); + } + } } diff --git a/apis/ec2/src/main/java/org/jclouds/ec2/features/SubnetApi.java b/apis/ec2/src/main/java/org/jclouds/ec2/features/SubnetApi.java index c0e2a5c281..4322393e3c 100644 --- a/apis/ec2/src/main/java/org/jclouds/ec2/features/SubnetApi.java +++ b/apis/ec2/src/main/java/org/jclouds/ec2/features/SubnetApi.java @@ -18,7 +18,6 @@ */ package org.jclouds.ec2.features; -import java.util.Map; import org.jclouds.ec2.domain.Subnet; import org.jclouds.ec2.util.SubnetFilterBuilder; import org.jclouds.rest.annotations.SinceApiVersion; @@ -27,13 +26,10 @@ import com.google.common.collect.FluentIterable; import com.google.common.collect.Multimap; /** - * To help you manage your Amazon EC2 instances, images, and other Amazon EC2 - * resources, you can assign your own metadata to each resource in the form of - * tags. + * To help you manage your Amazon EC2 instances, images, and other Amazon EC2 resources, you can assign your own + * metadata to each resource in the form of tags. * - * @see doc + * @see doc * @see SubnetAsyncApi * @author Adrian Cole * @author Andrew Bayer @@ -57,7 +53,7 @@ public interface SubnetApi { *

example

* *
-    * subnets = subnetApi.filter(new SubnetFilterBuilder().vpcId("vpc-1a2b3c4d").build());
+    * subnets = subnetApi.filter(new SubnetFilterBuilder().vpcId("vpc-1a2b3c4d").build());
     * 
* * @param filter diff --git a/apis/ec2/src/main/java/org/jclouds/ec2/features/SubnetAsyncApi.java b/apis/ec2/src/main/java/org/jclouds/ec2/features/SubnetAsyncApi.java index e252dbcb92..0e4557e17d 100644 --- a/apis/ec2/src/main/java/org/jclouds/ec2/features/SubnetAsyncApi.java +++ b/apis/ec2/src/main/java/org/jclouds/ec2/features/SubnetAsyncApi.java @@ -20,8 +20,6 @@ package org.jclouds.ec2.features; import static org.jclouds.aws.reference.FormParameters.ACTION; -import java.util.Map; - import javax.inject.Named; import javax.ws.rs.POST; import javax.ws.rs.Path; @@ -47,8 +45,7 @@ import com.google.common.util.concurrent.ListenableFuture; * Provides access to Amazon EC2 via the Query API *

* - * @see doc * @see SubnetApi * @author Adrian Cole diff --git a/apis/ec2/src/main/java/org/jclouds/ec2/xml/DescribeSubnetsResponseHandler.java b/apis/ec2/src/main/java/org/jclouds/ec2/xml/DescribeSubnetsResponseHandler.java index fca2b95729..fc6b1eaf21 100644 --- a/apis/ec2/src/main/java/org/jclouds/ec2/xml/DescribeSubnetsResponseHandler.java +++ b/apis/ec2/src/main/java/org/jclouds/ec2/xml/DescribeSubnetsResponseHandler.java @@ -18,95 +18,76 @@ */ package org.jclouds.ec2.xml; -import static org.jclouds.util.SaxUtils.currentOrNull; import static org.jclouds.util.SaxUtils.equalsOrSuffix; -import java.util.Set; - import org.jclouds.ec2.domain.Subnet; import org.jclouds.http.functions.ParseSax; import org.xml.sax.Attributes; -import org.xml.sax.SAXException; import com.google.common.collect.FluentIterable; import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet.Builder; -import com.google.common.collect.Sets; import com.google.inject.Inject; /** - * @see xml + * @see xml * * @author Adrian Cole * @author Andrew Bayer */ -public class DescribeSubnetsResponseHandler extends ParseSax.HandlerForGeneratedRequestWithResult> { - private final SubnetHandler subnetHandler; +public class DescribeSubnetsResponseHandler extends + ParseSax.HandlerForGeneratedRequestWithResult> { + private final SubnetHandler subnetHandler; - private StringBuilder currentText = new StringBuilder(); - private boolean inSubnetSet; - private boolean inTagSet; - private Builder subnets = ImmutableSet. builder(); + private StringBuilder currentText = new StringBuilder(); + private boolean inSubnetSet; + private boolean inTagSet; + private Builder subnets = ImmutableSet. builder(); - @Inject - public DescribeSubnetsResponseHandler(SubnetHandler subnetHandler) { - this.subnetHandler = subnetHandler; - } + @Inject + public DescribeSubnetsResponseHandler(SubnetHandler subnetHandler) { + this.subnetHandler = subnetHandler; + } - /** - * {@inheritDoc} - */ - @Override - public FluentIterable getResult() { - return FluentIterable.from(subnets.build()); - } + @Override + public FluentIterable getResult() { + return FluentIterable.from(subnets.build()); + } - /** - * {@inheritDoc} - */ - @Override - public void startElement(String url, String name, String qName, Attributes attributes) throws SAXException { - if (equalsOrSuffix(qName, "subnetSet")) { - inSubnetSet = true; - } else if (inSubnetSet) { - if (equalsOrSuffix(qName, "tagSet")) { - inTagSet = true; - } - subnetHandler.startElement(url, name, qName, attributes); - } - } + @Override + public void startElement(String url, String name, String qName, Attributes attributes) { + if (equalsOrSuffix(qName, "subnetSet")) { + inSubnetSet = true; + } else if (inSubnetSet) { + if (equalsOrSuffix(qName, "tagSet")) { + inTagSet = true; + } + subnetHandler.startElement(url, name, qName, attributes); + } + } - /** - * {@inheritDoc} - */ - @Override - public void endElement(String uri, String name, String qName) throws SAXException { - if (equalsOrSuffix(qName, "subnetSet")) { - inSubnetSet = false; - } else if (equalsOrSuffix(qName, "tagSet")) { - inTagSet = false; - subnetHandler.endElement(uri, name, qName); - } else if (equalsOrSuffix(qName, "item") && !inTagSet) { - subnets.add(subnetHandler.getResult()); - } else if (inSubnetSet) { - subnetHandler.endElement(uri, name, qName); - } + @Override + public void endElement(String uri, String name, String qName) { + if (equalsOrSuffix(qName, "subnetSet")) { + inSubnetSet = false; + } else if (equalsOrSuffix(qName, "tagSet")) { + inTagSet = false; + subnetHandler.endElement(uri, name, qName); + } else if (equalsOrSuffix(qName, "item") && !inTagSet) { + subnets.add(subnetHandler.getResult()); + } else if (inSubnetSet) { + subnetHandler.endElement(uri, name, qName); + } - currentText = new StringBuilder(); - } - - /** - * {@inheritDoc} - */ - @Override - public void characters(char ch[], int start, int length) { - if (inSubnetSet) { - subnetHandler.characters(ch, start, length); - } else { - currentText.append(ch, start, length); - } - } + currentText = new StringBuilder(); + } + @Override + public void characters(char ch[], int start, int length) { + if (inSubnetSet) { + subnetHandler.characters(ch, start, length); + } else { + currentText.append(ch, start, length); + } + } } diff --git a/apis/ec2/src/main/java/org/jclouds/ec2/xml/SubnetHandler.java b/apis/ec2/src/main/java/org/jclouds/ec2/xml/SubnetHandler.java index 13f6235e0c..344e15b3ba 100644 --- a/apis/ec2/src/main/java/org/jclouds/ec2/xml/SubnetHandler.java +++ b/apis/ec2/src/main/java/org/jclouds/ec2/xml/SubnetHandler.java @@ -24,99 +24,74 @@ import static org.jclouds.util.SaxUtils.equalsOrSuffix; import javax.inject.Inject; import org.jclouds.ec2.domain.Subnet; -import org.jclouds.ec2.domain.Subnet.State; import org.jclouds.http.functions.ParseSax; - import org.xml.sax.Attributes; -import com.google.common.base.Supplier; - /** - * @see xml + * @see xml * * @author Adrian Cole * @author Andrew Bayer */ public class SubnetHandler extends ParseSax.HandlerForGeneratedRequestWithResult { - private StringBuilder currentText = new StringBuilder(); - private Subnet.Builder builder = newBuilder(); - private final TagSetHandler tagSetHandler; - private boolean inTagSet; + private StringBuilder currentText = new StringBuilder(); + private Subnet.Builder builder = Subnet.builder(); + private final TagSetHandler tagSetHandler; + private boolean inTagSet; - @Inject - public SubnetHandler(TagSetHandler tagSetHandler) { - this.tagSetHandler = tagSetHandler; - } + @Inject + public SubnetHandler(TagSetHandler tagSetHandler) { + this.tagSetHandler = tagSetHandler; + } - /** - * {@inheritDoc} - */ - @Override - public Subnet getResult() { - try { - return builder.build(); - } finally { - builder = Subnet.builder(); - } - } + @Override + public Subnet getResult() { + try { + return builder.build(); + } finally { + builder = Subnet.builder(); + } + } - /** - * {@inheritDoc} - */ - @Override - public void startElement(String uri, String name, String qName, Attributes attrs) { - if (equalsOrSuffix(qName, "tagSet")) { - inTagSet = true; - } - if (inTagSet) { - tagSetHandler.startElement(uri, name, qName, attrs); - } - } - - /** - * {@inheritDoc} - */ - @Override - public void endElement(String uri, String name, String qName) { - if (equalsOrSuffix(qName, "tagSet")) { - inTagSet = false; - builder.tags(tagSetHandler.getResult()); - } else if (inTagSet) { - tagSetHandler.endElement(uri, name, qName); - } else if (equalsOrSuffix(qName, "subnetId")) { - builder.subnetId(currentOrNull(currentText)); - } else if (equalsOrSuffix(qName, "state")) { - builder.subnetState(Subnet.State.fromValue(currentOrNull(currentText))); - } else if (equalsOrSuffix(qName, "vpcId")) { - builder.vpcId(currentOrNull(currentText)); - } else if (equalsOrSuffix(qName, "cidrBlock")) { - builder.cidrBlock(currentOrNull(currentText)); - } else if (equalsOrSuffix(qName, "availableIpAddressCount")) { - builder.availableIpAddressCount(Integer.parseInt(currentOrNull(currentText))); - } else if (equalsOrSuffix(qName, "availabilityZone")) { - builder.availabilityZone(currentOrNull(currentText)); - } - currentText = new StringBuilder(); - } + @Override + public void startElement(String uri, String name, String qName, Attributes attrs) { + if (equalsOrSuffix(qName, "tagSet")) { + inTagSet = true; + } + if (inTagSet) { + tagSetHandler.startElement(uri, name, qName, attrs); + } + } + @Override + public void endElement(String uri, String name, String qName) { + if (equalsOrSuffix(qName, "tagSet")) { + inTagSet = false; + builder.tags(tagSetHandler.getResult()); + } else if (inTagSet) { + tagSetHandler.endElement(uri, name, qName); + } else if (equalsOrSuffix(qName, "subnetId")) { + builder.subnetId(currentOrNull(currentText)); + } else if (equalsOrSuffix(qName, "state")) { + builder.subnetState(Subnet.State.fromValue(currentOrNull(currentText))); + } else if (equalsOrSuffix(qName, "vpcId")) { + builder.vpcId(currentOrNull(currentText)); + } else if (equalsOrSuffix(qName, "cidrBlock")) { + builder.cidrBlock(currentOrNull(currentText)); + } else if (equalsOrSuffix(qName, "availableIpAddressCount")) { + builder.availableIpAddressCount(Integer.parseInt(currentOrNull(currentText))); + } else if (equalsOrSuffix(qName, "availabilityZone")) { + builder.availabilityZone(currentOrNull(currentText)); + } + currentText = new StringBuilder(); + } - - /** - * {@inheritDoc} - */ - @Override - public void characters(char ch[], int start, int length) { - if (inTagSet) { - tagSetHandler.characters(ch, start, length); - } else { - currentText.append(ch, start, length); - } - } - - - private Subnet.Builder newBuilder() { - return Subnet.builder(); - } + @Override + public void characters(char ch[], int start, int length) { + if (inTagSet) { + tagSetHandler.characters(ch, start, length); + } else { + currentText.append(ch, start, length); + } + } } diff --git a/apis/ec2/src/test/java/org/jclouds/ec2/features/SubnetApiExpectTest.java b/apis/ec2/src/test/java/org/jclouds/ec2/features/SubnetApiExpectTest.java index 6516b1bac3..a81d2fa915 100644 --- a/apis/ec2/src/test/java/org/jclouds/ec2/features/SubnetApiExpectTest.java +++ b/apis/ec2/src/test/java/org/jclouds/ec2/features/SubnetApiExpectTest.java @@ -27,11 +27,9 @@ import org.jclouds.ec2.internal.BaseEC2ApiExpectTest; import org.jclouds.ec2.parse.DescribeSubnetsResponseTest; import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpResponse; -import org.jclouds.rest.ResourceNotFoundException; import org.jclouds.rest.annotations.SinceApiVersion; import org.testng.annotations.Test; -import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMultimap; import com.google.common.collect.ImmutableSet; @@ -51,21 +49,17 @@ public class SubnetApiExpectTest extends BaseEC2ApiExpectTest { return props; } - HttpRequest list = HttpRequest.builder() - .method("POST") - .endpoint("https://ec2.us-east-1.amazonaws.com/") - .addHeader("Host", "ec2.us-east-1.amazonaws.com") - .payload( - payloadFromStringWithContentType( - "Action=DescribeSubnets" + - "&Signature=Uuafp9lnYQmMUcf/JE1epPTQVCSMPqfns%2BwlZssUsi4%3D" + - "&SignatureMethod=HmacSHA256" + - "&SignatureVersion=2" + - "&Timestamp=2012-04-16T15%3A54%3A08.897Z" + - "&Version=2011-01-01" + - "&AWSAccessKeyId=identity", - "application/x-www-form-urlencoded")) - .build(); + HttpRequest list = HttpRequest.builder().method("POST") + .endpoint("https://ec2.us-east-1.amazonaws.com/") + .addHeader("Host", "ec2.us-east-1.amazonaws.com") + .addFormParam("Action", "DescribeSubnets") + .addFormParam("Signature", "Uuafp9lnYQmMUcf/JE1epPTQVCSMPqfns%2BwlZssUsi4%3D") + .addFormParam("SignatureMethod", "HmacSHA256") + .addFormParam("SignatureVersion", "2") + .addFormParam("Timestamp", "2012-04-16T15%3A54%3A08.897Z") + .addFormParam("Version", "2011-01-01") + .addFormParam("AWSAccessKeyId", "identity") + .build(); public void testListWhenResponseIs2xx() throws Exception { @@ -88,23 +82,18 @@ public class SubnetApiExpectTest extends BaseEC2ApiExpectTest { assertEquals(apiWhenDontExist.getSubnetApi().get().list().toSet(), ImmutableSet.of()); } - HttpRequest filter = - HttpRequest.builder() - .method("POST") - .endpoint("https://ec2.us-east-1.amazonaws.com/") - .addHeader("Host", "ec2.us-east-1.amazonaws.com") - .payload(payloadFromStringWithContentType( - "Action=DescribeSubnets" + - "&Filter.1.Name=subnet-id" + - "&Filter.1.Value.1=subnet-9d4a7b6c" + - "&Signature=%2Bp34YACfLk9km1H3eALnDmrkst9FhJttojVSf7VztLk%3D" + - "&SignatureMethod=HmacSHA256" + - "&SignatureVersion=2" + - "&Timestamp=2012-04-16T15%3A54%3A08.897Z" + - "&Version=2011-01-01" + - "&AWSAccessKeyId=identity", - "application/x-www-form-urlencoded")) - .build(); + HttpRequest filter = HttpRequest.builder().method("POST") + .endpoint("https://ec2.us-east-1.amazonaws.com/") + .addHeader("Host", "ec2.us-east-1.amazonaws.com") + .addFormParam("Action", "DescribeSubnets") + .addFormParam("Filter.1.Name", "subnet-id") + .addFormParam("Filter.1.Value.1", "subnet-9d4a7b6c") + .addFormParam("Signature", "%2Bp34YACfLk9km1H3eALnDmrkst9FhJttojVSf7VztLk%3D") + .addFormParam("SignatureMethod", "HmacSHA256") + .addFormParam("SignatureVersion", "2") + .addFormParam("Timestamp", "2012-04-16T15%3A54%3A08.897Z") + .addFormParam("Version", "2011-01-01") + .addFormParam("AWSAccessKeyId", "identity").build(); public void testFilterWhenResponseIs2xx() throws Exception { diff --git a/apis/ec2/src/test/java/org/jclouds/ec2/features/SubnetApiLiveTest.java b/apis/ec2/src/test/java/org/jclouds/ec2/features/SubnetApiLiveTest.java index d4800a61f0..216a009972 100644 --- a/apis/ec2/src/test/java/org/jclouds/ec2/features/SubnetApiLiveTest.java +++ b/apis/ec2/src/test/java/org/jclouds/ec2/features/SubnetApiLiveTest.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.jclouds.ec2.features.internal; +package org.jclouds.ec2.features; import static com.google.common.base.Preconditions.checkNotNull; import static java.lang.String.format; @@ -24,24 +24,16 @@ import static java.util.concurrent.TimeUnit.MILLISECONDS; import static java.util.logging.Logger.getAnonymousLogger; import static org.jclouds.util.Predicates2.retry; import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertFalse; import static org.testng.Assert.assertTrue; -import java.util.logging.Logger; - import org.jclouds.ec2.domain.Subnet; -import org.jclouds.ec2.features.SubnetApi; import org.jclouds.ec2.internal.BaseEC2ApiLiveTest; import org.jclouds.ec2.util.SubnetFilterBuilder; import org.testng.SkipException; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import com.google.common.base.Optional; import com.google.common.base.Predicate; -import com.google.common.collect.FluentIterable; -import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; /** @@ -52,8 +44,6 @@ import com.google.common.collect.ImmutableSet; */ @Test(groups = "live") public class SubnetApiLiveTest extends BaseEC2ApiLiveTest { - private Subnet subnet; - private void checkSubnet(Subnet subnet) { getAnonymousLogger().info(format("subnet %s vpc: %s", subnet.getSubnetId(), subnet.getVpcId())); diff --git a/apis/openstack-nova-ec2/src/main/java/org/jclouds/openstack/nova/ec2/config/NovaEC2RestClientModule.java b/apis/openstack-nova-ec2/src/main/java/org/jclouds/openstack/nova/ec2/config/NovaEC2RestClientModule.java index 66ac14b333..3ce75efd82 100644 --- a/apis/openstack-nova-ec2/src/main/java/org/jclouds/openstack/nova/ec2/config/NovaEC2RestClientModule.java +++ b/apis/openstack-nova-ec2/src/main/java/org/jclouds/openstack/nova/ec2/config/NovaEC2RestClientModule.java @@ -27,6 +27,12 @@ import javax.inject.Singleton; import org.jclouds.ec2.EC2AsyncClient; import org.jclouds.ec2.EC2Client; import org.jclouds.ec2.config.EC2RestClientModule; +import org.jclouds.ec2.features.SubnetApi; +import org.jclouds.ec2.features.SubnetAsyncApi; +import org.jclouds.ec2.features.TagApi; +import org.jclouds.ec2.features.TagAsyncApi; +import org.jclouds.ec2.features.WindowsApi; +import org.jclouds.ec2.features.WindowsAsyncApi; import org.jclouds.ec2.services.AMIAsyncClient; import org.jclouds.ec2.services.AMIClient; import org.jclouds.ec2.services.AvailabilityZoneAndRegionAsyncClient; @@ -76,6 +82,9 @@ public class NovaEC2RestClientModule extends EC2RestClientModule