mirror of https://github.com/apache/jclouds.git
various cleanups to get ec2 subnet api up to latest
This commit is contained in:
parent
ece9b5b82e
commit
3dd309da2d
|
@ -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 <a
|
||||
* href="http://docs.aws.amazon.com/AmazonVPC/latest/UserGuide/VPC_Subnets.html"
|
||||
* >doc</a>
|
||||
* @see <a href="http://docs.aws.amazon.com/AmazonVPC/latest/UserGuide/VPC_Subnets.html" >doc</a>
|
||||
*
|
||||
* @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<String, String> 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<String, String> 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.<String, String> 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<String, String> 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<String, String> 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<String, String> 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<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);
|
||||
}
|
||||
|
||||
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<String, String> 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<String, String> tags = ImmutableMap.<String, String> 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<String, String> 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<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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,13 +30,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 <a
|
||||
* href="http://docs.aws.amazon.com/AmazonVPC/latest/UserGuide/VPC_Subnets.html"
|
||||
* >doc</a>
|
||||
* @see <a href="http://docs.aws.amazon.com/AmazonVPC/latest/UserGuide/VPC_Subnets.html" >doc</a>
|
||||
* @see SubnetAsyncApi
|
||||
* @author Adrian Cole
|
||||
* @author Andrew Bayer
|
||||
|
@ -61,7 +58,7 @@ public interface SubnetApi {
|
|||
* <h4>example</h4>
|
||||
*
|
||||
* <pre>
|
||||
* subnets = subnetApi.filter(new SubnetFilterBuilder().vpcId("vpc-1a2b3c4d").build());
|
||||
* subnets = subnetApi.filter(new SubnetFilterBuilder().vpcId("vpc-1a2b3c4d").build());
|
||||
* </pre>
|
||||
*
|
||||
* @param filter
|
||||
|
|
|
@ -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
|
||||
* <p/>
|
||||
*
|
||||
* @see <a
|
||||
* href="http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-DescribeSubnets.html"
|
||||
* @see <a href="http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-DescribeSubnets.html"
|
||||
* >doc</a>
|
||||
* @see SubnetApi
|
||||
* @author Adrian Cole
|
||||
|
|
|
@ -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 <a
|
||||
* href="http://docs.aws.amazon.com/AWSEC2/latest/APIReference/ApiReference-query-DescribeSubnets.html"
|
||||
* >xml</a>
|
||||
* @see <a href="http://docs.aws.amazon.com/AWSEC2/latest/APIReference/ApiReference-query-DescribeSubnets.html" >xml</a>
|
||||
*
|
||||
* @author Adrian Cole
|
||||
* @author Andrew Bayer
|
||||
*/
|
||||
public class DescribeSubnetsResponseHandler extends ParseSax.HandlerForGeneratedRequestWithResult<FluentIterable<Subnet>> {
|
||||
private final SubnetHandler subnetHandler;
|
||||
public class DescribeSubnetsResponseHandler extends
|
||||
ParseSax.HandlerForGeneratedRequestWithResult<FluentIterable<Subnet>> {
|
||||
private final SubnetHandler subnetHandler;
|
||||
|
||||
private StringBuilder currentText = new StringBuilder();
|
||||
private boolean inSubnetSet;
|
||||
private boolean inTagSet;
|
||||
private Builder<Subnet> subnets = ImmutableSet.<Subnet> builder();
|
||||
private StringBuilder currentText = new StringBuilder();
|
||||
private boolean inSubnetSet;
|
||||
private boolean inTagSet;
|
||||
private Builder<Subnet> subnets = ImmutableSet.<Subnet> builder();
|
||||
|
||||
@Inject
|
||||
public DescribeSubnetsResponseHandler(SubnetHandler subnetHandler) {
|
||||
this.subnetHandler = subnetHandler;
|
||||
}
|
||||
@Inject
|
||||
public DescribeSubnetsResponseHandler(SubnetHandler subnetHandler) {
|
||||
this.subnetHandler = subnetHandler;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public FluentIterable<Subnet> getResult() {
|
||||
return FluentIterable.from(subnets.build());
|
||||
}
|
||||
@Override
|
||||
public FluentIterable<Subnet> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 <a
|
||||
* href="http://docs.aws.amazon.com/AWSEC2/latest/APIReference/ApiReference-ItemType-SubnetType.html"
|
||||
* >xml</a>
|
||||
* @see <a href="http://docs.aws.amazon.com/AWSEC2/latest/APIReference/ApiReference-ItemType-SubnetType.html" >xml</a>
|
||||
*
|
||||
* @author Adrian Cole
|
||||
* @author Andrew Bayer
|
||||
*/
|
||||
public class SubnetHandler extends ParseSax.HandlerForGeneratedRequestWithResult<Subnet> {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<EC2Api> {
|
|||
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<EC2Api> {
|
|||
assertEquals(apiWhenDontExist.getSubnetApi().get().list().toImmutableSet(), 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 {
|
||||
|
||||
|
|
|
@ -16,32 +16,24 @@
|
|||
* 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;
|
||||
import static java.util.concurrent.TimeUnit.MILLISECONDS;
|
||||
import static java.util.logging.Logger.getAnonymousLogger;
|
||||
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.jclouds.predicates.RetryablePredicate;
|
||||
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()));
|
||||
|
|
|
@ -25,6 +25,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;
|
||||
|
@ -75,6 +81,9 @@ public class NovaEC2RestClientModule extends EC2RestClientModule<NovaEC2Client,
|
|||
.put(WindowsClient.class, WindowsAsyncClient.class)//
|
||||
.put(AvailabilityZoneAndRegionClient.class, AvailabilityZoneAndRegionAsyncClient.class)//
|
||||
.put(ElasticBlockStoreClient.class, ElasticBlockStoreAsyncClient.class)//
|
||||
.put(WindowsApi.class, WindowsAsyncApi.class)//
|
||||
.put(TagApi.class, TagAsyncApi.class)//
|
||||
.put(SubnetApi.class, SubnetAsyncApi.class)//
|
||||
.build();
|
||||
|
||||
public NovaEC2RestClientModule() {
|
||||
|
|
|
@ -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";
|
||||
}
|
||||
}
|
|
@ -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";
|
||||
}
|
||||
}
|
|
@ -46,6 +46,8 @@ import org.jclouds.ec2.EC2AsyncClient;
|
|||
import org.jclouds.ec2.EC2Client;
|
||||
import org.jclouds.ec2.config.EC2RestClientModule;
|
||||
import org.jclouds.ec2.domain.RunningInstance;
|
||||
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;
|
||||
|
@ -94,6 +96,7 @@ public class AWSEC2RestClientModule extends EC2RestClientModule<AWSEC2Client, AW
|
|||
.put(TagClient.class, TagAsyncClient.class)//
|
||||
.put(WindowsApi.class, WindowsAsyncApi.class)//
|
||||
.put(TagApi.class, TagAsyncApi.class)//
|
||||
.put(SubnetApi.class, SubnetAsyncApi.class)//
|
||||
.build();
|
||||
|
||||
public AWSEC2RestClientModule() {
|
||||
|
|
|
@ -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";
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue