Merge pull request #1352 from jclouds/ec2-subnet-cleanup

various cleanups to get ec2 subnet api up to latest
This commit is contained in:
Adrian Cole 2013-02-24 15:18:25 -08:00
commit 0d43da7339
12 changed files with 445 additions and 423 deletions

View File

@ -24,249 +24,232 @@ import java.util.Map;
import com.google.common.base.Objects; import com.google.common.base.Objects;
import com.google.common.base.Objects.ToStringHelper; 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.ImmutableMap;
import com.google.common.collect.Maps;
/** /**
* Amazon EC2 VPCs contain one or more subnets. * Amazon EC2 VPCs contain one or more subnets.
* *
* @see <a * @see <a href="http://docs.aws.amazon.com/AmazonVPC/latest/UserGuide/VPC_Subnets.html" >doc</a>
* href="http://docs.aws.amazon.com/AmazonVPC/latest/UserGuide/VPC_Subnets.html"
* >doc</a>
* *
* @author Adrian Cole * @author Adrian Cole
* @author Andrew Bayer * @author Andrew Bayer
*/ */
public class Subnet { public final class Subnet {
public static enum State { public static enum State {
/** /**
* The subnet is available for use. * The subnet is available for use.
*/ */
AVAILABLE, AVAILABLE,
/** /**
* The subnet is not yet available for use. * The subnet is not yet available for use.
*/ */
PENDING, UNRECOGNIZED; PENDING, UNRECOGNIZED;
public String value() { public String value() {
return name().toLowerCase(); 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<String, String> tags;
public Subnet(String subnetId, State subnetState, String vpcId, String cidrBlock, public static State fromValue(String v) {
int availableIpAddressCount, String availabilityZone, Map<String, String> tags) { try {
this.subnetId = checkNotNull(subnetId, "subnetId"); return valueOf(v.toUpperCase());
this.subnetState = checkNotNull(subnetState, "subnetState for %s", subnetId); } catch (IllegalArgumentException e) {
this.vpcId = checkNotNull(vpcId, "vpcId for %s", subnetId); return UNRECOGNIZED;
this.cidrBlock = checkNotNull(cidrBlock, "cidrBlock for %s", subnetId); }
this.availableIpAddressCount = availableIpAddressCount; }
this.availabilityZone = checkNotNull(availabilityZone, "availabilityZone for %s", subnetId); }
this.tags = ImmutableMap.<String, String> copyOf(checkNotNull(tags, "tags for %s", subnetId));
}
/** private final String subnetId;
* The subnet ID, ex. subnet-c5473ba8 private final State subnetState;
*/ private final String vpcId;
public String getSubnetId() { private final String cidrBlock;
return subnetId; private final int availableIpAddressCount;
} private final String availabilityZone;
private final Map<String, String> tags;
/**
* 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 Subnet(String subnetId, State subnetState, String vpcId, String cidrBlock, int availableIpAddressCount,
* The CIDR block for this subnet. String availabilityZone, ImmutableMap<String, String> tags) {
*/ this.subnetId = checkNotNull(subnetId, "subnetId");
public String getCidrBlock() { this.subnetState = checkNotNull(subnetState, "subnetState for %s", subnetId);
return cidrBlock; 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. * The subnet ID, ex. subnet-c5473ba8
*/ */
public int getAvailableIpAddressCount() { public String getSubnetId() {
return availableIpAddressCount; return subnetId;
} }
/** /**
* The availability zone this subnet is in. * The subnet state - either available or pending.
*/ */
public String getAvailabilityZone() { public State getSubnetState() {
return availabilityZone; return subnetState;
} }
/** /**
* Tags that are attached to this subnet. * The vpc ID this subnet belongs to.
*/ */
public Map<String, String> getTags() { public String getVpcId() {
return tags; return vpcId;
} }
/** /**
* {@inheritDoc} * The CIDR block for this subnet.
*/ */
@Override public String getCidrBlock() {
public int hashCode() { return cidrBlock;
return Objects.hashCode(subnetId, vpcId, availabilityZone); }
}
/** /**
* {@inheritDoc} * The number of available IPs in this subnet.
*/ */
@Override public int getAvailableIpAddressCount() {
public boolean equals(Object obj) { return availableIpAddressCount;
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();
}
private final ToStringHelper string() { /**
return Objects.toStringHelper(this).omitNullValues().add("subnetId", subnetId) * The availability zone this subnet is in.
.add("subnetState", subnetState).add("vpcId", vpcId) */
.add("cidrBlock", cidrBlock).add("availableIpAddressCount", availableIpAddressCount) public String getAvailabilityZone() {
return availabilityZone;
}
/**
* Tags that are attached to this subnet.
*/
public Map<String, String> 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); .add("availabilityZone", availabilityZone).add("tags", tags);
} }
public static Builder builder() {
return new Builder();
}
public Builder toBuilder() {
return builder().fromSubnet(this);
}
public static class Builder { public static Builder builder() {
private String subnetId; return new Builder();
private State subnetState; }
private String vpcId;
private String cidrBlock;
private int availableIpAddressCount;
private String availabilityZone;
private Map<String, String> tags = Maps.newLinkedHashMap();
/** public Builder toBuilder() {
* @see Subnet#getSubnetId() return builder().from(this);
*/ }
public Builder subnetId(String subnetId) {
this.subnetId = subnetId;
return this;
}
/** public final static class Builder {
* @see Subnet#getState() private String subnetId;
*/ private State subnetState;
public Builder subnetState(State subnetState) { private String vpcId;
this.subnetState = subnetState; private String cidrBlock;
return this; private int availableIpAddressCount;
} private String availabilityZone;
private ImmutableMap.Builder<String, String> tags = ImmutableMap.<String, String> builder();
/** /**
* @see Subnet#getVpcId() * @see Subnet#getSubnetId()
*/ */
public Builder vpcId(String vpcId) { public Builder subnetId(String subnetId) {
this.vpcId = vpcId; this.subnetId = subnetId;
return this; return this;
} }
/** /**
* @see Subnet#getCidrBlock() * @see Subnet#getState()
*/ */
public Builder cidrBlock(String cidrBlock) { public Builder subnetState(State subnetState) {
this.cidrBlock = cidrBlock; this.subnetState = subnetState;
return this; 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#getTags() * @see Subnet#getVpcId()
*/ */
public Builder tags(Map<String, String> tags) { public Builder vpcId(String vpcId) {
this.tags = ImmutableMap.copyOf(checkNotNull(tags, "tags")); this.vpcId = vpcId;
return this; return this;
} }
/** /**
* @see Subnet#getTags() * @see Subnet#getCidrBlock()
*/ */
public Builder tag(String key, String value) { public Builder cidrBlock(String cidrBlock) {
if (key != null) this.cidrBlock = cidrBlock;
this.tags.put(key, Strings.nullToEmpty(value)); return this;
return this; }
}
public Subnet build() {
return new Subnet(subnetId, subnetState, vpcId, cidrBlock, availableIpAddressCount,
availabilityZone, tags);
}
public Builder fromSubnet(Subnet in) { /**
return this.subnetId(in.getSubnetId()) * @see Subnet#getAvailableIpAddressCount()
.subnetState(in.getSubnetState()) */
.vpcId(in.getVpcId()) public Builder availableIpAddressCount(int availableIpAddressCount) {
.cidrBlock(in.getCidrBlock()) this.availableIpAddressCount = availableIpAddressCount;
.availableIpAddressCount(in.getAvailableIpAddressCount()) return this;
.availabilityZone(in.getAvailabilityZone()) }
.tags(in.getTags());
} /**
} * @see Subnet#getAvailabilityZone()
*/
public Builder availabilityZone(String availabilityZone) {
this.availabilityZone = availabilityZone;
return this;
}
/**
* @see Subnet#getTags()
*/
public Builder tags(Map<String, String> 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());
}
}
} }

View File

@ -18,7 +18,6 @@
*/ */
package org.jclouds.ec2.features; package org.jclouds.ec2.features;
import java.util.Map;
import org.jclouds.ec2.domain.Subnet; import org.jclouds.ec2.domain.Subnet;
import org.jclouds.ec2.util.SubnetFilterBuilder; import org.jclouds.ec2.util.SubnetFilterBuilder;
import org.jclouds.rest.annotations.SinceApiVersion; import org.jclouds.rest.annotations.SinceApiVersion;
@ -27,13 +26,10 @@ import com.google.common.collect.FluentIterable;
import com.google.common.collect.Multimap; import com.google.common.collect.Multimap;
/** /**
* To help you manage your Amazon EC2 instances, images, and other Amazon EC2 * To help you manage your Amazon EC2 instances, images, and other Amazon EC2 resources, you can assign your own
* resources, you can assign your own metadata to each resource in the form of * metadata to each resource in the form of tags.
* tags.
* *
* @see <a * @see <a href="http://docs.aws.amazon.com/AmazonVPC/latest/UserGuide/VPC_Subnets.html" >doc</a>
* href="http://docs.aws.amazon.com/AmazonVPC/latest/UserGuide/VPC_Subnets.html"
* >doc</a>
* @see SubnetAsyncApi * @see SubnetAsyncApi
* @author Adrian Cole * @author Adrian Cole
* @author Andrew Bayer * @author Andrew Bayer
@ -57,7 +53,7 @@ public interface SubnetApi {
* <h4>example</h4> * <h4>example</h4>
* *
* <pre> * <pre>
* subnets = subnetApi.filter(new SubnetFilterBuilder().vpcId("vpc-1a2b3c4d").build()); * subnets = subnetApi.filter(new SubnetFilterBuilder().vpcId(&quot;vpc-1a2b3c4d&quot;).build());
* </pre> * </pre>
* *
* @param filter * @param filter

View File

@ -20,8 +20,6 @@ package org.jclouds.ec2.features;
import static org.jclouds.aws.reference.FormParameters.ACTION; import static org.jclouds.aws.reference.FormParameters.ACTION;
import java.util.Map;
import javax.inject.Named; import javax.inject.Named;
import javax.ws.rs.POST; import javax.ws.rs.POST;
import javax.ws.rs.Path; 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 * Provides access to Amazon EC2 via the Query API
* <p/> * <p/>
* *
* @see <a * @see <a href="http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-DescribeSubnets.html"
* href="http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-DescribeSubnets.html"
* >doc</a> * >doc</a>
* @see SubnetApi * @see SubnetApi
* @author Adrian Cole * @author Adrian Cole

View File

@ -18,95 +18,76 @@
*/ */
package org.jclouds.ec2.xml; package org.jclouds.ec2.xml;
import static org.jclouds.util.SaxUtils.currentOrNull;
import static org.jclouds.util.SaxUtils.equalsOrSuffix; import static org.jclouds.util.SaxUtils.equalsOrSuffix;
import java.util.Set;
import org.jclouds.ec2.domain.Subnet; import org.jclouds.ec2.domain.Subnet;
import org.jclouds.http.functions.ParseSax; import org.jclouds.http.functions.ParseSax;
import org.xml.sax.Attributes; import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import com.google.common.collect.FluentIterable; import com.google.common.collect.FluentIterable;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSet.Builder; import com.google.common.collect.ImmutableSet.Builder;
import com.google.common.collect.Sets;
import com.google.inject.Inject; import com.google.inject.Inject;
/** /**
* @see <a * @see <a href="http://docs.aws.amazon.com/AWSEC2/latest/APIReference/ApiReference-query-DescribeSubnets.html" >xml</a>
* href="http://docs.aws.amazon.com/AWSEC2/latest/APIReference/ApiReference-query-DescribeSubnets.html"
* >xml</a>
* *
* @author Adrian Cole * @author Adrian Cole
* @author Andrew Bayer * @author Andrew Bayer
*/ */
public class DescribeSubnetsResponseHandler extends ParseSax.HandlerForGeneratedRequestWithResult<FluentIterable<Subnet>> { public class DescribeSubnetsResponseHandler extends
private final SubnetHandler subnetHandler; ParseSax.HandlerForGeneratedRequestWithResult<FluentIterable<Subnet>> {
private final SubnetHandler subnetHandler;
private StringBuilder currentText = new StringBuilder(); private StringBuilder currentText = new StringBuilder();
private boolean inSubnetSet; private boolean inSubnetSet;
private boolean inTagSet; private boolean inTagSet;
private Builder<Subnet> subnets = ImmutableSet.<Subnet> builder(); private Builder<Subnet> subnets = ImmutableSet.<Subnet> builder();
@Inject @Inject
public DescribeSubnetsResponseHandler(SubnetHandler subnetHandler) { public DescribeSubnetsResponseHandler(SubnetHandler subnetHandler) {
this.subnetHandler = subnetHandler; this.subnetHandler = subnetHandler;
} }
/** @Override
* {@inheritDoc} public FluentIterable<Subnet> getResult() {
*/ return FluentIterable.from(subnets.build());
@Override }
public FluentIterable<Subnet> getResult() {
return FluentIterable.from(subnets.build());
}
/** @Override
* {@inheritDoc} public void startElement(String url, String name, String qName, Attributes attributes) {
*/ if (equalsOrSuffix(qName, "subnetSet")) {
@Override inSubnetSet = true;
public void startElement(String url, String name, String qName, Attributes attributes) throws SAXException { } else if (inSubnetSet) {
if (equalsOrSuffix(qName, "subnetSet")) { if (equalsOrSuffix(qName, "tagSet")) {
inSubnetSet = true; inTagSet = true;
} else if (inSubnetSet) { }
if (equalsOrSuffix(qName, "tagSet")) { subnetHandler.startElement(url, name, qName, attributes);
inTagSet = true; }
} }
subnetHandler.startElement(url, name, qName, attributes);
}
}
/** @Override
* {@inheritDoc} public void endElement(String uri, String name, String qName) {
*/ if (equalsOrSuffix(qName, "subnetSet")) {
@Override inSubnetSet = false;
public void endElement(String uri, String name, String qName) throws SAXException { } else if (equalsOrSuffix(qName, "tagSet")) {
if (equalsOrSuffix(qName, "subnetSet")) { inTagSet = false;
inSubnetSet = false; subnetHandler.endElement(uri, name, qName);
} else if (equalsOrSuffix(qName, "tagSet")) { } else if (equalsOrSuffix(qName, "item") && !inTagSet) {
inTagSet = false; subnets.add(subnetHandler.getResult());
subnetHandler.endElement(uri, name, qName); } else if (inSubnetSet) {
} else if (equalsOrSuffix(qName, "item") && !inTagSet) { subnetHandler.endElement(uri, name, qName);
subnets.add(subnetHandler.getResult()); }
} else if (inSubnetSet) {
subnetHandler.endElement(uri, name, qName);
}
currentText = new StringBuilder(); 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);
}
}
@Override
public void characters(char ch[], int start, int length) {
if (inSubnetSet) {
subnetHandler.characters(ch, start, length);
} else {
currentText.append(ch, start, length);
}
}
} }

View File

@ -24,99 +24,74 @@ import static org.jclouds.util.SaxUtils.equalsOrSuffix;
import javax.inject.Inject; import javax.inject.Inject;
import org.jclouds.ec2.domain.Subnet; import org.jclouds.ec2.domain.Subnet;
import org.jclouds.ec2.domain.Subnet.State;
import org.jclouds.http.functions.ParseSax; import org.jclouds.http.functions.ParseSax;
import org.xml.sax.Attributes; import org.xml.sax.Attributes;
import com.google.common.base.Supplier;
/** /**
* @see <a * @see <a href="http://docs.aws.amazon.com/AWSEC2/latest/APIReference/ApiReference-ItemType-SubnetType.html" >xml</a>
* href="http://docs.aws.amazon.com/AWSEC2/latest/APIReference/ApiReference-ItemType-SubnetType.html"
* >xml</a>
* *
* @author Adrian Cole * @author Adrian Cole
* @author Andrew Bayer * @author Andrew Bayer
*/ */
public class SubnetHandler extends ParseSax.HandlerForGeneratedRequestWithResult<Subnet> { public class SubnetHandler extends ParseSax.HandlerForGeneratedRequestWithResult<Subnet> {
private StringBuilder currentText = new StringBuilder(); private StringBuilder currentText = new StringBuilder();
private Subnet.Builder builder = newBuilder(); private Subnet.Builder builder = Subnet.builder();
private final TagSetHandler tagSetHandler; private final TagSetHandler tagSetHandler;
private boolean inTagSet; private boolean inTagSet;
@Inject @Inject
public SubnetHandler(TagSetHandler tagSetHandler) { public SubnetHandler(TagSetHandler tagSetHandler) {
this.tagSetHandler = tagSetHandler; this.tagSetHandler = tagSetHandler;
} }
/** @Override
* {@inheritDoc} public Subnet getResult() {
*/ try {
@Override return builder.build();
public Subnet getResult() { } finally {
try { builder = Subnet.builder();
return builder.build(); }
} finally { }
builder = Subnet.builder();
}
}
/** @Override
* {@inheritDoc} public void startElement(String uri, String name, String qName, Attributes attrs) {
*/ if (equalsOrSuffix(qName, "tagSet")) {
@Override inTagSet = true;
public void startElement(String uri, String name, String qName, Attributes attrs) { }
if (equalsOrSuffix(qName, "tagSet")) { if (inTagSet) {
inTagSet = true; tagSetHandler.startElement(uri, name, qName, attrs);
} }
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 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 characters(char ch[], int start, int length) {
* {@inheritDoc} if (inTagSet) {
*/ tagSetHandler.characters(ch, start, length);
@Override } else {
public void characters(char ch[], int start, int length) { currentText.append(ch, start, length);
if (inTagSet) { }
tagSetHandler.characters(ch, start, length); }
} else {
currentText.append(ch, start, length);
}
}
private Subnet.Builder newBuilder() {
return Subnet.builder();
}
} }

View File

@ -27,11 +27,9 @@ import org.jclouds.ec2.internal.BaseEC2ApiExpectTest;
import org.jclouds.ec2.parse.DescribeSubnetsResponseTest; import org.jclouds.ec2.parse.DescribeSubnetsResponseTest;
import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse; import org.jclouds.http.HttpResponse;
import org.jclouds.rest.ResourceNotFoundException;
import org.jclouds.rest.annotations.SinceApiVersion; import org.jclouds.rest.annotations.SinceApiVersion;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableMultimap; import com.google.common.collect.ImmutableMultimap;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
@ -51,21 +49,17 @@ public class SubnetApiExpectTest extends BaseEC2ApiExpectTest<EC2Api> {
return props; return props;
} }
HttpRequest list = HttpRequest.builder() HttpRequest list = HttpRequest.builder().method("POST")
.method("POST") .endpoint("https://ec2.us-east-1.amazonaws.com/")
.endpoint("https://ec2.us-east-1.amazonaws.com/") .addHeader("Host", "ec2.us-east-1.amazonaws.com")
.addHeader("Host", "ec2.us-east-1.amazonaws.com") .addFormParam("Action", "DescribeSubnets")
.payload( .addFormParam("Signature", "Uuafp9lnYQmMUcf/JE1epPTQVCSMPqfns%2BwlZssUsi4%3D")
payloadFromStringWithContentType( .addFormParam("SignatureMethod", "HmacSHA256")
"Action=DescribeSubnets" + .addFormParam("SignatureVersion", "2")
"&Signature=Uuafp9lnYQmMUcf/JE1epPTQVCSMPqfns%2BwlZssUsi4%3D" + .addFormParam("Timestamp", "2012-04-16T15%3A54%3A08.897Z")
"&SignatureMethod=HmacSHA256" + .addFormParam("Version", "2011-01-01")
"&SignatureVersion=2" + .addFormParam("AWSAccessKeyId", "identity")
"&Timestamp=2012-04-16T15%3A54%3A08.897Z" + .build();
"&Version=2011-01-01" +
"&AWSAccessKeyId=identity",
"application/x-www-form-urlencoded"))
.build();
public void testListWhenResponseIs2xx() throws Exception { public void testListWhenResponseIs2xx() throws Exception {
@ -88,23 +82,18 @@ public class SubnetApiExpectTest extends BaseEC2ApiExpectTest<EC2Api> {
assertEquals(apiWhenDontExist.getSubnetApi().get().list().toSet(), ImmutableSet.of()); assertEquals(apiWhenDontExist.getSubnetApi().get().list().toSet(), ImmutableSet.of());
} }
HttpRequest filter = HttpRequest filter = HttpRequest.builder().method("POST")
HttpRequest.builder() .endpoint("https://ec2.us-east-1.amazonaws.com/")
.method("POST") .addHeader("Host", "ec2.us-east-1.amazonaws.com")
.endpoint("https://ec2.us-east-1.amazonaws.com/") .addFormParam("Action", "DescribeSubnets")
.addHeader("Host", "ec2.us-east-1.amazonaws.com") .addFormParam("Filter.1.Name", "subnet-id")
.payload(payloadFromStringWithContentType( .addFormParam("Filter.1.Value.1", "subnet-9d4a7b6c")
"Action=DescribeSubnets" + .addFormParam("Signature", "%2Bp34YACfLk9km1H3eALnDmrkst9FhJttojVSf7VztLk%3D")
"&Filter.1.Name=subnet-id" + .addFormParam("SignatureMethod", "HmacSHA256")
"&Filter.1.Value.1=subnet-9d4a7b6c" + .addFormParam("SignatureVersion", "2")
"&Signature=%2Bp34YACfLk9km1H3eALnDmrkst9FhJttojVSf7VztLk%3D" + .addFormParam("Timestamp", "2012-04-16T15%3A54%3A08.897Z")
"&SignatureMethod=HmacSHA256" + .addFormParam("Version", "2011-01-01")
"&SignatureVersion=2" + .addFormParam("AWSAccessKeyId", "identity").build();
"&Timestamp=2012-04-16T15%3A54%3A08.897Z" +
"&Version=2011-01-01" +
"&AWSAccessKeyId=identity",
"application/x-www-form-urlencoded"))
.build();
public void testFilterWhenResponseIs2xx() throws Exception { public void testFilterWhenResponseIs2xx() throws Exception {

View File

@ -16,7 +16,7 @@
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*/ */
package org.jclouds.ec2.features.internal; package org.jclouds.ec2.features;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import static java.lang.String.format; 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 java.util.logging.Logger.getAnonymousLogger;
import static org.jclouds.util.Predicates2.retry; import static org.jclouds.util.Predicates2.retry;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertTrue; import static org.testng.Assert.assertTrue;
import java.util.logging.Logger;
import org.jclouds.ec2.domain.Subnet; import org.jclouds.ec2.domain.Subnet;
import org.jclouds.ec2.features.SubnetApi;
import org.jclouds.ec2.internal.BaseEC2ApiLiveTest; import org.jclouds.ec2.internal.BaseEC2ApiLiveTest;
import org.jclouds.ec2.util.SubnetFilterBuilder; import org.jclouds.ec2.util.SubnetFilterBuilder;
import org.testng.SkipException; import org.testng.SkipException;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.base.Optional; import com.google.common.base.Optional;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
/** /**
@ -52,8 +44,6 @@ import com.google.common.collect.ImmutableSet;
*/ */
@Test(groups = "live") @Test(groups = "live")
public class SubnetApiLiveTest extends BaseEC2ApiLiveTest { public class SubnetApiLiveTest extends BaseEC2ApiLiveTest {
private Subnet subnet;
private void checkSubnet(Subnet subnet) { private void checkSubnet(Subnet subnet) {
getAnonymousLogger().info(format("subnet %s vpc: %s", subnet.getSubnetId(), subnet.getVpcId())); getAnonymousLogger().info(format("subnet %s vpc: %s", subnet.getSubnetId(), subnet.getVpcId()));

View File

@ -27,6 +27,12 @@ import javax.inject.Singleton;
import org.jclouds.ec2.EC2AsyncClient; import org.jclouds.ec2.EC2AsyncClient;
import org.jclouds.ec2.EC2Client; import org.jclouds.ec2.EC2Client;
import org.jclouds.ec2.config.EC2RestClientModule; 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.AMIAsyncClient;
import org.jclouds.ec2.services.AMIClient; import org.jclouds.ec2.services.AMIClient;
import org.jclouds.ec2.services.AvailabilityZoneAndRegionAsyncClient; import org.jclouds.ec2.services.AvailabilityZoneAndRegionAsyncClient;
@ -76,6 +82,9 @@ public class NovaEC2RestClientModule extends EC2RestClientModule<NovaEC2Client,
.put(WindowsClient.class, WindowsAsyncClient.class)// .put(WindowsClient.class, WindowsAsyncClient.class)//
.put(AvailabilityZoneAndRegionClient.class, AvailabilityZoneAndRegionAsyncClient.class)// .put(AvailabilityZoneAndRegionClient.class, AvailabilityZoneAndRegionAsyncClient.class)//
.put(ElasticBlockStoreClient.class, ElasticBlockStoreAsyncClient.class)// .put(ElasticBlockStoreClient.class, ElasticBlockStoreAsyncClient.class)//
.put(WindowsApi.class, WindowsAsyncApi.class)//
.put(TagApi.class, TagAsyncApi.class)//
.put(SubnetApi.class, SubnetAsyncApi.class)//
.build(); .build();
public NovaEC2RestClientModule() { public NovaEC2RestClientModule() {

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.openstack.nova.ec2.features;
import org.jclouds.ec2.features.SubnetApiLiveTest;
import org.testng.annotations.Test;
/**
*
* @author Adrian Cole
*/
@Test(groups = "live", testName = "NovaSubnetApiLiveTest")
public class NovaSubnetApiLiveTest extends SubnetApiLiveTest {
public NovaSubnetApiLiveTest() {
provider = "cloudstack-ec2";
}
}

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.features;
import org.jclouds.ec2.features.SubnetApiLiveTest;
import org.testng.annotations.Test;
/**
*
* @author Adrian Cole
*/
@Test(groups = "live", testName = "CloudStackSubnetApiLiveTest")
public class CloudStackSubnetApiLiveTest extends SubnetApiLiveTest {
public CloudStackSubnetApiLiveTest() {
provider = "cloudstack-ec2";
}
}

View File

@ -46,6 +46,8 @@ import org.jclouds.aws.ec2.services.SpotInstanceClient;
import org.jclouds.ec2.EC2AsyncClient; import org.jclouds.ec2.EC2AsyncClient;
import org.jclouds.ec2.EC2Client; import org.jclouds.ec2.EC2Client;
import org.jclouds.ec2.config.EC2RestClientModule; 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.TagApi;
import org.jclouds.ec2.features.TagAsyncApi; import org.jclouds.ec2.features.TagAsyncApi;
import org.jclouds.ec2.features.WindowsApi; import org.jclouds.ec2.features.WindowsApi;
@ -94,6 +96,7 @@ public class AWSEC2RestClientModule extends EC2RestClientModule<AWSEC2Client, AW
.put(SpotInstanceClient.class, SpotInstanceAsyncClient.class)// .put(SpotInstanceClient.class, SpotInstanceAsyncClient.class)//
.put(WindowsApi.class, WindowsAsyncApi.class)// .put(WindowsApi.class, WindowsAsyncApi.class)//
.put(TagApi.class, TagAsyncApi.class)// .put(TagApi.class, TagAsyncApi.class)//
.put(SubnetApi.class, SubnetAsyncApi.class)//
.build(); .build();
public AWSEC2RestClientModule() { public AWSEC2RestClientModule() {

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.aws.ec2.features;
import org.jclouds.ec2.features.SubnetApiLiveTest;
import org.testng.annotations.Test;
/**
*
* @author Adrian Cole
*/
@Test(groups = "live", testName = "AWSSubnetApiLiveTest")
public class AWSSubnetApiLiveTest extends SubnetApiLiveTest {
public AWSSubnetApiLiveTest() {
provider = "aws-ec2";
}
}