From fb4248eef70b00ffcd0fc7ffce0aedc4158d5da2 Mon Sep 17 00:00:00 2001 From: adriancole Date: Mon, 11 Mar 2013 14:53:01 -0700 Subject: [PATCH 1/3] route53: replace usage of UnsignedInteger with int and corrected default ttl to 300 --- .../route53/domain/ResourceRecordSet.java | 36 ++++++++----------- .../route53/functions/SerializeRRS.java | 4 +-- .../route53/xml/HostedZoneHandler.java | 3 +- .../route53/xml/ResourceRecordSetHandler.java | 5 ++- .../ResourceRecordSetApiExpectTest.java | 2 +- .../src/test/resources/batch_rrs_request.xml | 2 +- .../src/test/resources/create_rrs_request.xml | 2 +- 7 files changed, 23 insertions(+), 31 deletions(-) diff --git a/apis/route53/src/main/java/org/jclouds/route53/domain/ResourceRecordSet.java b/apis/route53/src/main/java/org/jclouds/route53/domain/ResourceRecordSet.java index c487809f96..97f76b6bf8 100644 --- a/apis/route53/src/main/java/org/jclouds/route53/domain/ResourceRecordSet.java +++ b/apis/route53/src/main/java/org/jclouds/route53/domain/ResourceRecordSet.java @@ -20,6 +20,7 @@ package org.jclouds.route53.domain; import static com.google.common.base.Objects.equal; import static com.google.common.base.Objects.toStringHelper; +import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; import java.util.List; @@ -31,7 +32,6 @@ import com.google.common.base.Objects; import com.google.common.base.Objects.ToStringHelper; import com.google.common.base.Optional; import com.google.common.collect.ImmutableList; -import com.google.common.primitives.UnsignedInteger; /** * @@ -41,7 +41,7 @@ public class ResourceRecordSet { protected final String name; protected final String type; - protected final Optional ttl; + protected final Optional ttl; protected final List values; protected final Optional aliasTarget; @@ -98,9 +98,9 @@ public class ResourceRecordSet { public static abstract class RecordSubset extends ResourceRecordSet { public static final class Weighted extends RecordSubset { - private final UnsignedInteger weight; + private final int weight; - private Weighted(String id, String name, String type, UnsignedInteger weight, Optional ttl, List values, + private Weighted(String id, String name, String type, int weight, Optional ttl, List values, Optional aliasTarget) { super(id, name, type, ttl, values, aliasTarget); this.weight = checkNotNull(weight, "weight"); @@ -110,7 +110,7 @@ public class ResourceRecordSet { * determines what portion of traffic for the current resource record * set is routed to this subset. */ - public UnsignedInteger getWeight() { + public int getWeight() { return weight; } @@ -124,7 +124,7 @@ public class ResourceRecordSet { private final String region; - private Latency(String id, String name, String type, String region, Optional ttl, List values, + private Latency(String id, String name, String type, String region, Optional ttl, List values, Optional aliasTarget) { super(id, name, type, ttl, values, aliasTarget); this.region = checkNotNull(region, "region of %s", name); @@ -146,7 +146,7 @@ public class ResourceRecordSet { private final String id; - private RecordSubset(String id, String name, String type, Optional ttl, List values, + private RecordSubset(String id, String name, String type, Optional ttl, List values, Optional aliasTarget) { super(name, type, ttl, values, aliasTarget); this.id = checkNotNull(id, "id of %s", name); @@ -183,10 +183,11 @@ public class ResourceRecordSet { } } - private ResourceRecordSet(String name, String type, Optional ttl, List values, Optional aliasTarget) { + private ResourceRecordSet(String name, String type, Optional ttl, List values, Optional aliasTarget) { this.name = checkNotNull(name, "name"); this.type = checkNotNull(type, "type of %s", name); this.ttl = checkNotNull(ttl, "ttl for %s", name); + checkArgument(ttl.or(0) >= 0, "ttl of %s must be unsigned", name); this.values = checkNotNull(values, "values for %s", name); this.aliasTarget = checkNotNull(aliasTarget, "aliasTarget for %s", aliasTarget); } @@ -209,7 +210,7 @@ public class ResourceRecordSet { * Present in all resource record sets except aliases. The resource record * cache time to live (TTL), in seconds. */ - public Optional getTTL() { + public Optional getTTL() { return ttl; } @@ -264,11 +265,11 @@ public class ResourceRecordSet { private String id; private String name; private String type; - private Optional ttl = Optional.absent(); + private Optional ttl = Optional.absent(); private ImmutableList.Builder values = ImmutableList. builder(); private String dnsName; private String zoneId; - private UnsignedInteger weight; + private Integer weight; private String region; /** @@ -295,19 +296,12 @@ public class ResourceRecordSet { return this; } - /** - * @see ResourceRecordSet#getTTL() - */ - public Builder ttl(UnsignedInteger ttl) { - this.ttl = Optional.fromNullable(ttl); - return this; - } - /** * @see ResourceRecordSet#getTTL() */ public Builder ttl(int ttl) { - return ttl(UnsignedInteger.fromIntBits(ttl)); + this.ttl = Optional.of(ttl); + return this; } /** @@ -359,7 +353,7 @@ public class ResourceRecordSet { /** * @see RecordSubset.Weighted */ - public Builder weight(UnsignedInteger weight) { + public Builder weight(int weight) { this.weight = weight; return this; } diff --git a/apis/route53/src/main/java/org/jclouds/route53/functions/SerializeRRS.java b/apis/route53/src/main/java/org/jclouds/route53/functions/SerializeRRS.java index 654cbac420..d747457c6b 100644 --- a/apis/route53/src/main/java/org/jclouds/route53/functions/SerializeRRS.java +++ b/apis/route53/src/main/java/org/jclouds/route53/functions/SerializeRRS.java @@ -27,7 +27,6 @@ import org.jclouds.route53.domain.ResourceRecordSet.RecordSubset.Latency; import org.jclouds.route53.domain.ResourceRecordSet.RecordSubset.Weighted; import com.google.common.base.Function; -import com.google.common.primitives.UnsignedInteger; /** * @author Adrian Cole @@ -54,7 +53,8 @@ public class SerializeRRS implements Function { builder.append("").append(rrs.getAliasTarget().get().getDNSName()).append(""); builder.append(""); } else { - builder.append("").append(rrs.getTTL().or(UnsignedInteger.ZERO)).append(""); + // default ttl from the amazon console is 300 + builder.append("").append(rrs.getTTL().or(300)).append(""); builder.append(""); for (String record : rrs.getValues()) builder.append("").append("").append(record).append("") diff --git a/apis/route53/src/main/java/org/jclouds/route53/xml/HostedZoneHandler.java b/apis/route53/src/main/java/org/jclouds/route53/xml/HostedZoneHandler.java index c44987b6c2..7cfe4f95de 100644 --- a/apis/route53/src/main/java/org/jclouds/route53/xml/HostedZoneHandler.java +++ b/apis/route53/src/main/java/org/jclouds/route53/xml/HostedZoneHandler.java @@ -24,7 +24,6 @@ import org.jclouds.http.functions.ParseSax; import org.jclouds.route53.domain.HostedZone; import org.xml.sax.Attributes; -import com.google.common.primitives.UnsignedInteger; /** * @@ -59,7 +58,7 @@ public class HostedZoneHandler extends ParseSax.HandlerForGeneratedRequestWithRe } else if (qName.equals("Comment")) { builder.comment(currentOrNull(currentText)); } else if (qName.equals("ResourceRecordSetCount")) { - builder.resourceRecordSetCount(UnsignedInteger.valueOf(currentOrNull(currentText)).intValue()); + builder.resourceRecordSetCount(Integer.parseInt(currentOrNull(currentText))); } currentText = new StringBuilder(); } diff --git a/apis/route53/src/main/java/org/jclouds/route53/xml/ResourceRecordSetHandler.java b/apis/route53/src/main/java/org/jclouds/route53/xml/ResourceRecordSetHandler.java index fcc8fb7126..b36d304557 100644 --- a/apis/route53/src/main/java/org/jclouds/route53/xml/ResourceRecordSetHandler.java +++ b/apis/route53/src/main/java/org/jclouds/route53/xml/ResourceRecordSetHandler.java @@ -24,7 +24,6 @@ import org.jclouds.http.functions.ParseSax; import org.jclouds.route53.domain.ResourceRecordSet; import org.xml.sax.Attributes; -import com.google.common.primitives.UnsignedInteger; /** * @@ -55,7 +54,7 @@ public class ResourceRecordSetHandler extends ParseSax.HandlerForGeneratedReques } else if (qName.equals("Type")) { builder.type(currentOrNull(currentText)); } else if (qName.equals("TTL")) { - builder.ttl(UnsignedInteger.valueOf(currentOrNull(currentText))); + builder.ttl(Integer.parseInt(currentOrNull(currentText))); } else if (qName.equals("Value")) { builder.add(currentOrNull(currentText)); } else if (qName.equals("HostedZoneId")) { @@ -65,7 +64,7 @@ public class ResourceRecordSetHandler extends ParseSax.HandlerForGeneratedReques } else if (qName.equals("DNSName")) { builder.dnsName(currentOrNull(currentText)); } else if (qName.equals("Weight")) { - builder.weight(UnsignedInteger.valueOf(currentOrNull(currentText))); + builder.weight(Integer.parseInt(currentOrNull(currentText))); } else if (qName.equals("Region")) { builder.region(currentOrNull(currentText)); } diff --git a/apis/route53/src/test/java/org/jclouds/route53/features/ResourceRecordSetApiExpectTest.java b/apis/route53/src/test/java/org/jclouds/route53/features/ResourceRecordSetApiExpectTest.java index 7b4cf5c297..11a2a4d990 100644 --- a/apis/route53/src/test/java/org/jclouds/route53/features/ResourceRecordSetApiExpectTest.java +++ b/apis/route53/src/test/java/org/jclouds/route53/features/ResourceRecordSetApiExpectTest.java @@ -140,7 +140,7 @@ public class ResourceRecordSetApiExpectTest extends BaseRoute53ApiExpectTest { public void testDeleteWhenResponseIs2xx() { Route53Api success = requestSendsResponse(delete, jobResponse); - assertEquals(success.getResourceRecordSetApiForHostedZone("Z1PA6795UKMFR9").create(ResourceRecordSet.builder().name("jclouds.org.").type("TXT").add("my texts").build()).toString(), + assertEquals(success.getResourceRecordSetApiForHostedZone("Z1PA6795UKMFR9").create(ResourceRecordSet.builder().name("jclouds.org.").type("TXT").ttl(0).add("my texts").build()).toString(), new GetChangeResponseTest().expected().toString()); } } diff --git a/apis/route53/src/test/resources/batch_rrs_request.xml b/apis/route53/src/test/resources/batch_rrs_request.xml index c6997fdc87..dd1fc617b8 100644 --- a/apis/route53/src/test/resources/batch_rrs_request.xml +++ b/apis/route53/src/test/resources/batch_rrs_request.xml @@ -1 +1 @@ -DELETEjclouds.org.TXT0my textsCREATEjclouds.org.TXT0my better texts \ No newline at end of file +DELETEjclouds.org.TXT300my textsCREATEjclouds.org.TXT300my better texts \ No newline at end of file diff --git a/apis/route53/src/test/resources/create_rrs_request.xml b/apis/route53/src/test/resources/create_rrs_request.xml index 0003889aa0..228686b336 100644 --- a/apis/route53/src/test/resources/create_rrs_request.xml +++ b/apis/route53/src/test/resources/create_rrs_request.xml @@ -1 +1 @@ -CREATEjclouds.org.TXT0my texts \ No newline at end of file +CREATEjclouds.org.TXT300my texts \ No newline at end of file From 971a82098ee6eca558c7687a686467dd1645b225 Mon Sep 17 00:00:00 2001 From: adriancole Date: Mon, 11 Mar 2013 14:55:10 -0700 Subject: [PATCH 2/3] dynect: replace usage of UnsignedInteger with int and fixed serialized form of rdata classes --- .../dynect/v3/config/DynECTParserModule.java | 12 -- .../dynect/v3/domain/CreateRecord.java | 23 ++-- .../org/jclouds/dynect/v3/domain/Record.java | 22 ++-- .../jclouds/dynect/v3/domain/SOARecord.java | 3 +- .../dynect/v3/domain/rdata/AAAAData.java | 17 +-- .../jclouds/dynect/v3/domain/rdata/AData.java | 16 ++- .../dynect/v3/domain/rdata/CNAMEData.java | 18 +-- .../dynect/v3/domain/rdata/MXData.java | 41 +++--- .../dynect/v3/domain/rdata/NSData.java | 18 +-- .../dynect/v3/domain/rdata/PTRData.java | 18 +-- .../dynect/v3/domain/rdata/SOAData.java | 118 ++++++++---------- .../dynect/v3/domain/rdata/SRVData.java | 86 ++++++------- .../dynect/v3/domain/rdata/TXTData.java | 18 +-- .../dynect/v3/features/RecordAsyncApi.java | 2 +- 14 files changed, 192 insertions(+), 220 deletions(-) diff --git a/providers/dynect/src/main/java/org/jclouds/dynect/v3/config/DynECTParserModule.java b/providers/dynect/src/main/java/org/jclouds/dynect/v3/config/DynECTParserModule.java index 250a858c0a..9d52117038 100644 --- a/providers/dynect/src/main/java/org/jclouds/dynect/v3/config/DynECTParserModule.java +++ b/providers/dynect/src/main/java/org/jclouds/dynect/v3/config/DynECTParserModule.java @@ -26,12 +26,8 @@ import javax.inject.Singleton; import org.jclouds.dynect.v3.domain.SessionCredentials; import com.google.common.collect.ImmutableMap; -import com.google.common.primitives.UnsignedInteger; -import com.google.gson.JsonDeserializationContext; -import com.google.gson.JsonDeserializer; import com.google.gson.JsonElement; import com.google.gson.JsonObject; -import com.google.gson.JsonParseException; import com.google.gson.JsonSerializationContext; import com.google.gson.JsonSerializer; import com.google.inject.AbstractModule; @@ -51,7 +47,6 @@ public class DynECTParserModule extends AbstractModule { public Map provideCustomAdapterBindings() { return new ImmutableMap.Builder() .put(SessionCredentials.class, new SessionCredentialsTypeAdapter()) - .put(UnsignedInteger.class, new UnsignedIntegerAdapter()) .build(); } @@ -64,11 +59,4 @@ public class DynECTParserModule extends AbstractModule { return metadataObject; } } - - private static class UnsignedIntegerAdapter implements JsonDeserializer { - public UnsignedInteger deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext context) - throws JsonParseException { - return UnsignedInteger.fromIntBits(jsonElement.getAsBigInteger().intValue()); - } - } } diff --git a/providers/dynect/src/main/java/org/jclouds/dynect/v3/domain/CreateRecord.java b/providers/dynect/src/main/java/org/jclouds/dynect/v3/domain/CreateRecord.java index 4f298a5c55..58081f728d 100644 --- a/providers/dynect/src/main/java/org/jclouds/dynect/v3/domain/CreateRecord.java +++ b/providers/dynect/src/main/java/org/jclouds/dynect/v3/domain/CreateRecord.java @@ -20,12 +20,12 @@ package org.jclouds.dynect.v3.domain; import static com.google.common.base.Objects.equal; import static com.google.common.base.Objects.toStringHelper; +import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; import java.util.Map; import com.google.common.base.Objects; -import com.google.common.primitives.UnsignedInteger; /** * @author Adrian Cole @@ -34,13 +34,14 @@ public class CreateRecord> { private final String fqdn; private final String type; - private final UnsignedInteger ttl; + private final int ttl; private final D rdata; - private CreateRecord(String fqdn, String type, UnsignedInteger ttl, D rdata) { + private CreateRecord(String fqdn, String type, int ttl, D rdata) { this.fqdn = checkNotNull(fqdn, "fqdn"); this.type = checkNotNull(type, "type of %s", fqdn); - this.ttl = checkNotNull(ttl, "ttl of %s", fqdn); + checkArgument(ttl >= 0, "ttl of %s must be unsigned", fqdn); + this.ttl = ttl; this.rdata = checkNotNull(rdata, "rdata of %s", fqdn); } @@ -63,7 +64,7 @@ public class CreateRecord> { * * @see Record#getTTL() */ - public UnsignedInteger getTTL() { + public int getTTL() { return ttl; } @@ -106,7 +107,8 @@ public class CreateRecord> { public static class Builder> { protected String fqdn; protected String type; - protected UnsignedInteger ttl = UnsignedInteger.ZERO; + // default of zone is implied when ttl is set to zero + protected int ttl = 0; protected D rdata; /** @@ -128,18 +130,11 @@ public class CreateRecord> { /** * @see CreateRecord#getTTL() */ - public Builder ttl(UnsignedInteger ttl) { + public Builder ttl(int ttl) { this.ttl = ttl; return this; } - /** - * @see CreateRecord#getTTL() - */ - public Builder ttl(int ttl) { - return ttl(UnsignedInteger.fromIntBits(ttl)); - } - /** * @see CreateRecord#getRData() */ diff --git a/providers/dynect/src/main/java/org/jclouds/dynect/v3/domain/Record.java b/providers/dynect/src/main/java/org/jclouds/dynect/v3/domain/Record.java index b68b7d4d28..438ae289f2 100644 --- a/providers/dynect/src/main/java/org/jclouds/dynect/v3/domain/Record.java +++ b/providers/dynect/src/main/java/org/jclouds/dynect/v3/domain/Record.java @@ -18,6 +18,7 @@ */ package org.jclouds.dynect.v3.domain; +import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; import java.beans.ConstructorProperties; @@ -26,28 +27,28 @@ import java.util.Map; import javax.inject.Named; import com.google.common.base.Objects.ToStringHelper; -import com.google.common.primitives.UnsignedInteger; /** * @author Adrian Cole */ public class Record> extends RecordId { - private final UnsignedInteger ttl; + private final int ttl; @Named("rdata") private final D rdata; @ConstructorProperties({ "zone", "fqdn", "record_type", "record_id", "ttl", "rdata" }) - protected Record(String zone, String fqdn, String type, long id, UnsignedInteger ttl, D rdata) { + protected Record(String zone, String fqdn, String type, long id, int ttl, D rdata) { super(zone, fqdn, type, id); - this.ttl = checkNotNull(ttl, "ttl of %s", id); + checkArgument(ttl >= 0, "ttl of %s must be unsigned", fqdn); + this.ttl = ttl; this.rdata = checkNotNull(rdata, "rdata of %s", id); } /** * The current ttl of the record or zero if default for the zone */ - public UnsignedInteger getTTL() { + public int getTTL() { return ttl; } @@ -74,24 +75,17 @@ public class Record> extends RecordId { public abstract static class Builder, B extends Builder> extends RecordId.Builder { - protected UnsignedInteger ttl; + protected int ttl = -1; protected D rdata; /** * @see Record#getTTL() */ - public B ttl(UnsignedInteger ttl) { + public B ttl(int ttl) { this.ttl = ttl; return self(); } - /** - * @see Record#getTTL() - */ - public B ttl(int ttl) { - return ttl(UnsignedInteger.fromIntBits(ttl)); - } - /** * @see Record#getRData() */ diff --git a/providers/dynect/src/main/java/org/jclouds/dynect/v3/domain/SOARecord.java b/providers/dynect/src/main/java/org/jclouds/dynect/v3/domain/SOARecord.java index 9df446857d..ec8593a786 100644 --- a/providers/dynect/src/main/java/org/jclouds/dynect/v3/domain/SOARecord.java +++ b/providers/dynect/src/main/java/org/jclouds/dynect/v3/domain/SOARecord.java @@ -28,7 +28,6 @@ import org.jclouds.dynect.v3.domain.Zone.SerialStyle; import org.jclouds.dynect.v3.domain.rdata.SOAData; import com.google.common.base.Objects.ToStringHelper; -import com.google.common.primitives.UnsignedInteger; /** * Start of Authority per RFC 1035 @@ -41,7 +40,7 @@ public final class SOARecord extends Record { private final SerialStyle serialStyle; @ConstructorProperties({ "zone", "fqdn", "record_type", "record_id", "ttl", "rdata", "serial_style" }) - private SOARecord(String zone, String fqdn, String type, long id, UnsignedInteger ttl, SOAData rdata, SerialStyle serialStyle) { + private SOARecord(String zone, String fqdn, String type, long id, int ttl, SOAData rdata, SerialStyle serialStyle) { super(zone, fqdn, type, id, ttl, rdata); this.serialStyle = checkNotNull(serialStyle, "serialStyle of %s", id); } diff --git a/providers/dynect/src/main/java/org/jclouds/dynect/v3/domain/rdata/AAAAData.java b/providers/dynect/src/main/java/org/jclouds/dynect/v3/domain/rdata/AAAAData.java index 22f9a3dc6c..f297481453 100644 --- a/providers/dynect/src/main/java/org/jclouds/dynect/v3/domain/rdata/AAAAData.java +++ b/providers/dynect/src/main/java/org/jclouds/dynect/v3/domain/rdata/AAAAData.java @@ -40,22 +40,25 @@ import com.google.common.collect.ImmutableMap; * @see RFC 3596 */ public class AAAAData extends ForwardingMap { - private final ImmutableMap delegate; + private final String address; @ConstructorProperties("address") private AAAAData(String address) { - this.delegate = ImmutableMap. of("address", checkNotNull(address, "address")); - } - - protected Map delegate() { - return delegate; + this.address = checkNotNull(address, "address"); + this.delegate = ImmutableMap. of("address", address); } /** * a 128 bit IPv6 address */ public String getAddress() { - return get("address").toString(); + return address; + } + + private final transient ImmutableMap delegate; + + protected Map delegate() { + return delegate; } public static AAAAData aaaa(String address) { diff --git a/providers/dynect/src/main/java/org/jclouds/dynect/v3/domain/rdata/AData.java b/providers/dynect/src/main/java/org/jclouds/dynect/v3/domain/rdata/AData.java index 64deaa0afa..6ecd18d186 100644 --- a/providers/dynect/src/main/java/org/jclouds/dynect/v3/domain/rdata/AData.java +++ b/providers/dynect/src/main/java/org/jclouds/dynect/v3/domain/rdata/AData.java @@ -40,22 +40,26 @@ import com.google.common.collect.ImmutableMap; * @see RFC 1035 */ public class AData extends ForwardingMap { - private final ImmutableMap delegate; + + private final String address; @ConstructorProperties("address") private AData(String address) { + this.address = checkNotNull(address, "address"); this.delegate = ImmutableMap. of("address", checkNotNull(address, "address")); } - protected Map delegate() { - return delegate; - } - /** * a 32-bit internet address */ public String getAddress() { - return get("address").toString(); + return address; + } + + private final transient ImmutableMap delegate; + + protected Map delegate() { + return delegate; } public static AData a(String address) { diff --git a/providers/dynect/src/main/java/org/jclouds/dynect/v3/domain/rdata/CNAMEData.java b/providers/dynect/src/main/java/org/jclouds/dynect/v3/domain/rdata/CNAMEData.java index be8c0eda8b..33709ecc0b 100644 --- a/providers/dynect/src/main/java/org/jclouds/dynect/v3/domain/rdata/CNAMEData.java +++ b/providers/dynect/src/main/java/org/jclouds/dynect/v3/domain/rdata/CNAMEData.java @@ -40,15 +40,13 @@ import com.google.common.collect.ImmutableMap; * @see RFC 1035 */ public class CNAMEData extends ForwardingMap { - private final ImmutableMap delegate; + + private final String cname; @ConstructorProperties("cname") private CNAMEData(String cname) { - this.delegate = ImmutableMap. of("cname", checkNotNull(cname, "cname")); - } - - protected Map delegate() { - return delegate; + this.cname = checkNotNull(cname, "cname"); + this.delegate = ImmutableMap. of("cname", cname); } /** @@ -56,7 +54,13 @@ public class CNAMEData extends ForwardingMap { * The owner name is an alias. */ public String getCname() { - return get("cname").toString(); + return cname; + } + + private final transient ImmutableMap delegate; + + protected Map delegate() { + return delegate; } public static CNAMEData cname(String cname) { diff --git a/providers/dynect/src/main/java/org/jclouds/dynect/v3/domain/rdata/MXData.java b/providers/dynect/src/main/java/org/jclouds/dynect/v3/domain/rdata/MXData.java index c37f719a10..f6104a3353 100644 --- a/providers/dynect/src/main/java/org/jclouds/dynect/v3/domain/rdata/MXData.java +++ b/providers/dynect/src/main/java/org/jclouds/dynect/v3/domain/rdata/MXData.java @@ -18,6 +18,7 @@ */ package org.jclouds.dynect.v3.domain.rdata; +import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; import java.beans.ConstructorProperties; @@ -25,7 +26,6 @@ import java.util.Map; import com.google.common.collect.ForwardingMap; import com.google.common.collect.ImmutableMap; -import com.google.common.primitives.UnsignedInteger; /** * Corresponds to the binary representation of the {@code MX} (Mail Exchange) @@ -43,24 +43,24 @@ import com.google.common.primitives.UnsignedInteger; */ public class MXData extends ForwardingMap { + private final int preference; + private final String exchange; + @ConstructorProperties({ "preference", "exchange" }) - private MXData(UnsignedInteger preference, String exchange) { - this.delegate = ImmutableMap. builder().put("preference", checkNotNull(preference, "preference")) - .put("exchange", checkNotNull(exchange, "exchange")).build(); - } - - private final ImmutableMap delegate; - - protected Map delegate() { - return delegate; + private MXData(int preference, String exchange) { + checkArgument(preference >= 0, "preference of %s must be unsigned", exchange); + this.preference = preference; + this.exchange = checkNotNull(exchange, "exchange"); + this.delegate = ImmutableMap. builder().put("preference", preference).put("exchange", exchange) + .build(); } /** * specifies the preference given to this RR among others at the same owner. * Lower values are preferred. */ - public UnsignedInteger getPreference() { - return UnsignedInteger.class.cast(get("preference")); + public int getPreference() { + return preference; } /** @@ -68,7 +68,13 @@ public class MXData extends ForwardingMap { * the owner name. */ public String getExchange() { - return String.class.cast(get("exchange")); + return exchange; + } + + private final transient ImmutableMap delegate; + + protected Map delegate() { + return delegate; } public static MXData mx(int preference, String exchange) { @@ -84,20 +90,13 @@ public class MXData extends ForwardingMap { } public final static class Builder { - private UnsignedInteger preference; + private int preference = -1; private String exchange; /** * @see MXData#getPreference() */ public MXData.Builder preference(int preference) { - return preference(UnsignedInteger.fromIntBits(preference)); - } - - /** - * @see MXData#getPreference() - */ - public MXData.Builder preference(UnsignedInteger preference) { this.preference = preference; return this; } diff --git a/providers/dynect/src/main/java/org/jclouds/dynect/v3/domain/rdata/NSData.java b/providers/dynect/src/main/java/org/jclouds/dynect/v3/domain/rdata/NSData.java index f1752fec52..73e2c3415f 100644 --- a/providers/dynect/src/main/java/org/jclouds/dynect/v3/domain/rdata/NSData.java +++ b/providers/dynect/src/main/java/org/jclouds/dynect/v3/domain/rdata/NSData.java @@ -40,15 +40,13 @@ import com.google.common.collect.ImmutableMap; * @see RFC 1035 */ public class NSData extends ForwardingMap { - private final ImmutableMap delegate; + + private final String nsdname; @ConstructorProperties("nsdname") private NSData(String nsdname) { - this.delegate = ImmutableMap. of("nsdname", checkNotNull(nsdname, "nsdname")); - } - - protected Map delegate() { - return delegate; + this.nsdname = checkNotNull(nsdname, "nsdname"); + this.delegate = ImmutableMap. of("nsdname", nsdname); } /** @@ -56,7 +54,13 @@ public class NSData extends ForwardingMap { * specified class and domain. */ public String getNsdname() { - return get("nsdname").toString(); + return nsdname; + } + + private final transient ImmutableMap delegate; + + protected Map delegate() { + return delegate; } public static NSData ns(String nsdname) { diff --git a/providers/dynect/src/main/java/org/jclouds/dynect/v3/domain/rdata/PTRData.java b/providers/dynect/src/main/java/org/jclouds/dynect/v3/domain/rdata/PTRData.java index 57d2e74826..2abdd2ea27 100644 --- a/providers/dynect/src/main/java/org/jclouds/dynect/v3/domain/rdata/PTRData.java +++ b/providers/dynect/src/main/java/org/jclouds/dynect/v3/domain/rdata/PTRData.java @@ -40,22 +40,26 @@ import com.google.common.collect.ImmutableMap; * @see RFC 1035 */ public class PTRData extends ForwardingMap { - private final ImmutableMap delegate; + + private final String ptrdname; @ConstructorProperties("ptrdname") private PTRData(String ptrdname) { - this.delegate = ImmutableMap. of("ptrdname", checkNotNull(ptrdname, "ptrdname")); - } - - protected Map delegate() { - return delegate; + this.ptrdname = checkNotNull(ptrdname, "ptrdname"); + this.delegate = ImmutableMap. of("ptrdname", ptrdname); } /** * domain-name which points to some location in the domain name space. */ public String getPtrdname() { - return get("ptrdname").toString(); + return ptrdname; + } + + private final transient ImmutableMap delegate; + + protected Map delegate() { + return delegate; } public static PTRData ptr(String ptrdname) { diff --git a/providers/dynect/src/main/java/org/jclouds/dynect/v3/domain/rdata/SOAData.java b/providers/dynect/src/main/java/org/jclouds/dynect/v3/domain/rdata/SOAData.java index e24ac92154..3a5dd30722 100644 --- a/providers/dynect/src/main/java/org/jclouds/dynect/v3/domain/rdata/SOAData.java +++ b/providers/dynect/src/main/java/org/jclouds/dynect/v3/domain/rdata/SOAData.java @@ -18,6 +18,7 @@ */ package org.jclouds.dynect.v3.domain.rdata; +import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; import java.beans.ConstructorProperties; @@ -25,7 +26,6 @@ import java.util.Map; import com.google.common.collect.ForwardingMap; import com.google.common.collect.ImmutableMap; -import com.google.common.primitives.UnsignedInteger; /** * Corresponds to the binary representation of the {@code SOA} (Start of Authority) RData @@ -46,10 +46,29 @@ import com.google.common.primitives.UnsignedInteger; * @see RFC 1035 */ public class SOAData extends ForwardingMap { + private final String mname; + private final String rname; + private final int serial; + private final int refresh; + private final int retry; + private final int expire; + private final int minimum; @ConstructorProperties({ "mname", "rname", "serial", "refresh", "retry", "expire", "minimum" }) - private SOAData(String mname, String rname, UnsignedInteger serial, UnsignedInteger refresh, UnsignedInteger retry, - UnsignedInteger expire, UnsignedInteger minimum) { + private SOAData(String mname, String rname, int serial, int refresh, int retry, + int expire, int minimum) { + this.mname = checkNotNull(mname, "mname"); + this.rname = checkNotNull(rname, "rname of %s", mname); + checkArgument(serial >= 0, "serial of %s must be unsigned", mname); + this.serial = serial; + checkArgument(refresh >= 0, "refresh of %s must be unsigned", mname); + this.refresh = refresh; + checkArgument(retry >= 0, "retry of %s must be unsigned", mname); + this.retry = retry; + checkArgument(expire >= 0, "expire of %s must be unsigned", mname); + this.expire = expire; + checkArgument(minimum >= 0, "minimum of %s must be unsigned", mname); + this.minimum = minimum; this.delegate = ImmutableMap. builder() .put("mname", checkNotNull(mname, "mname")) .put("rname", checkNotNull(rname, "rname of %s", mname)) @@ -60,18 +79,12 @@ public class SOAData extends ForwardingMap { .put("minimum", checkNotNull(minimum, "minimum of %s", mname)).build(); } - private final ImmutableMap delegate; - - protected Map delegate() { - return delegate; - } - /** * domain-name of the name server that was the original or primary source of * data for this zone */ public String getMname() { - return String.class.cast(get("mname")); + return mname; } /** @@ -79,43 +92,49 @@ public class SOAData extends ForwardingMap { * zone. */ public String getRname() { - return String.class.cast(get("rname")); + return rname; } /** * version number of the original copy of the zone. */ - public UnsignedInteger getSerial() { - return UnsignedInteger.class.cast(get("serial")); + public int getSerial() { + return serial; } /** * time interval before the zone should be refreshed */ - public UnsignedInteger getRefresh() { - return UnsignedInteger.class.cast(get("refresh")); + public int getRefresh() { + return refresh; } /** * time interval that should elapse before a failed refresh should be retried */ - public UnsignedInteger getRetry() { - return UnsignedInteger.class.cast(get("retry")); + public int getRetry() { + return retry; } /** * time value that specifies the upper limit on the time interval that can * elapse before the zone is no longer authoritative. */ - public UnsignedInteger getExpire() { - return UnsignedInteger.class.cast(get("expire")); + public int getExpire() { + return expire; } /** * minimum TTL field that should be exported with any RR from this zone. */ - public UnsignedInteger getMinimum() { - return UnsignedInteger.class.cast(get("minimum")); + public int getMinimum() { + return minimum; + } + + private final transient ImmutableMap delegate; + + protected Map delegate() { + return delegate; } public static SOAData.Builder builder() { @@ -129,11 +148,11 @@ public class SOAData extends ForwardingMap { public final static class Builder { private String mname; private String rname; - private UnsignedInteger serial; - private UnsignedInteger refresh; - private UnsignedInteger retry; - private UnsignedInteger expire; - private UnsignedInteger minimum; + private int serial = -1; + private int refresh = -1; + private int retry = -1; + private int expire = -1; + private int minimum = -1; /** * @see SOAData#getMname() @@ -151,26 +170,11 @@ public class SOAData extends ForwardingMap { return this; } - /** - * @see SOAData#getSerial() - */ - public SOAData.Builder serial(UnsignedInteger serial) { - this.serial = serial; - return this; - } - /** * @see SOAData#getSerial() */ public SOAData.Builder serial(int serial) { - return serial(UnsignedInteger.fromIntBits(serial)); - } - - /** - * @see SOAData#getRefresh() - */ - public SOAData.Builder refresh(UnsignedInteger refresh) { - this.refresh = refresh; + this.serial = serial; return this; } @@ -178,14 +182,7 @@ public class SOAData extends ForwardingMap { * @see SOAData#getRefresh() */ public SOAData.Builder refresh(int refresh) { - return refresh(UnsignedInteger.fromIntBits(refresh)); - } - - /** - * @see SOAData#getRetry() - */ - public SOAData.Builder retry(UnsignedInteger retry) { - this.retry = retry; + this.refresh = refresh; return this; } @@ -193,14 +190,7 @@ public class SOAData extends ForwardingMap { * @see SOAData#getRetry() */ public SOAData.Builder retry(int retry) { - return retry(UnsignedInteger.fromIntBits(retry)); - } - - /** - * @see SOAData#getExpire() - */ - public SOAData.Builder expire(UnsignedInteger expire) { - this.expire = expire; + this.retry = retry; return this; } @@ -208,14 +198,7 @@ public class SOAData extends ForwardingMap { * @see SOAData#getExpire() */ public SOAData.Builder expire(int expire) { - return expire(UnsignedInteger.fromIntBits(expire)); - } - - /** - * @see SOAData#getMinimum() - */ - public SOAData.Builder minimum(UnsignedInteger minimum) { - this.minimum = minimum; + this.expire = expire; return this; } @@ -223,7 +206,8 @@ public class SOAData extends ForwardingMap { * @see SOAData#getMinimum() */ public SOAData.Builder minimum(int minimum) { - return minimum(UnsignedInteger.fromIntBits(minimum)); + this.minimum = minimum; + return this; } public SOAData build() { diff --git a/providers/dynect/src/main/java/org/jclouds/dynect/v3/domain/rdata/SRVData.java b/providers/dynect/src/main/java/org/jclouds/dynect/v3/domain/rdata/SRVData.java index 6fd6758b92..ee963e5b3a 100644 --- a/providers/dynect/src/main/java/org/jclouds/dynect/v3/domain/rdata/SRVData.java +++ b/providers/dynect/src/main/java/org/jclouds/dynect/v3/domain/rdata/SRVData.java @@ -18,6 +18,7 @@ */ package org.jclouds.dynect.v3.domain.rdata; +import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; import java.beans.ConstructorProperties; @@ -25,7 +26,6 @@ import java.util.Map; import com.google.common.collect.ForwardingMap; import com.google.common.collect.ImmutableMap; -import com.google.common.primitives.UnsignedInteger; /** * Corresponds to the binary representation of the {@code SRV} (Service) RData @@ -43,31 +43,36 @@ import com.google.common.primitives.UnsignedInteger; * @see RFC 2782 */ public class SRVData extends ForwardingMap { - + private final int priority; + private final int weight; + private final int port; + private final String target; + @ConstructorProperties({ "priority", "weight", "port", "target" }) - private SRVData(UnsignedInteger priority, UnsignedInteger weight, UnsignedInteger port, String target) { + private SRVData(int priority, int weight, int port, String target) { + checkArgument(checkNotNull(priority, "priority of %s", target).intValue() <= 0xFFFF, "priority must be 0-65535"); + this.priority = priority; + checkArgument(checkNotNull(weight, "weight of %s", target).intValue() <= 0xFFFF, "weight must be 0-65535"); + this.weight = weight; + checkArgument(checkNotNull(port, "port of %s", target).intValue() <= 0xFFFF, "port must be 0-65535"); + this.port = port; + this.target = checkNotNull(target, "target"); this.delegate = ImmutableMap. builder() - .put("priority", checkNotNull(priority, "priority of %s", target)) - .put("weight", checkNotNull(weight, "weight of %s", target)) - .put("port", checkNotNull(port, "port of %s", target)) - .put("target", checkNotNull(target, "target")) + .put("priority", priority) + .put("weight", weight) + .put("port", weight) + .put("target", weight) .build(); } - private final ImmutableMap delegate; - - protected Map delegate() { - return delegate; - } - /** * The priority of this target host. A client MUST attempt to contact the * target host with the lowest-numbered priority it can reach; target hosts * with the same priority SHOULD be tried in an order defined by the weight * field. */ - public UnsignedInteger getPriority() { - return UnsignedInteger.class.cast(get("priority")); + public int getPriority() { + return priority; } /** @@ -75,15 +80,15 @@ public class SRVData extends ForwardingMap { * priority. Larger weights SHOULD be given a proportionately higher * probability of being selected. */ - public UnsignedInteger getWeight() { - return UnsignedInteger.class.cast(get("weight")); + public int getWeight() { + return weight; } /** * The port on this target host of this service. */ - public UnsignedInteger getPort() { - return UnsignedInteger.class.cast(get("port")); + public int getPort() { + return port; } /** @@ -91,7 +96,13 @@ public class SRVData extends ForwardingMap { * records for this name, the name MUST NOT be an alias. */ public String getTarget() { - return String.class.cast(get("target")); + return target; + } + + private final transient ImmutableMap delegate; + + protected Map delegate() { + return delegate; } public static SRVData.Builder builder() { @@ -103,31 +114,16 @@ public class SRVData extends ForwardingMap { } public final static class Builder { - private UnsignedInteger priority; - private UnsignedInteger weight; - private UnsignedInteger port; + private int priority = -1; + private int weight = -1; + private int port = -1; private String target; - /** - * @see SRVData#getPriority() - */ - public SRVData.Builder priority(UnsignedInteger priority) { - this.priority = priority; - return this; - } - /** * @see SRVData#getPriority() */ public SRVData.Builder priority(int priority) { - return priority(UnsignedInteger.fromIntBits(priority)); - } - - /** - * @see SRVData#getWeight() - */ - public SRVData.Builder weight(UnsignedInteger weight) { - this.weight = weight; + this.priority = priority; return this; } @@ -135,14 +131,7 @@ public class SRVData extends ForwardingMap { * @see SRVData#getWeight() */ public SRVData.Builder weight(int weight) { - return weight(UnsignedInteger.fromIntBits(weight)); - } - - /** - * @see SRVData#getPort() - */ - public SRVData.Builder port(UnsignedInteger port) { - this.port = port; + this.weight = weight; return this; } @@ -150,7 +139,8 @@ public class SRVData extends ForwardingMap { * @see SRVData#getPort() */ public SRVData.Builder port(int port) { - return port(UnsignedInteger.fromIntBits(port)); + this.port = port; + return this; } /** diff --git a/providers/dynect/src/main/java/org/jclouds/dynect/v3/domain/rdata/TXTData.java b/providers/dynect/src/main/java/org/jclouds/dynect/v3/domain/rdata/TXTData.java index e20837906b..0113f41fc2 100644 --- a/providers/dynect/src/main/java/org/jclouds/dynect/v3/domain/rdata/TXTData.java +++ b/providers/dynect/src/main/java/org/jclouds/dynect/v3/domain/rdata/TXTData.java @@ -40,22 +40,26 @@ import com.google.common.collect.ImmutableMap; * @see RFC 1035 */ public class TXTData extends ForwardingMap { - private final ImmutableMap delegate; + + private final String txtdata; @ConstructorProperties("txtdata") private TXTData(String txtdata) { - this.delegate = ImmutableMap. of("txtdata", checkNotNull(txtdata, "txtdata")); - } - - protected Map delegate() { - return delegate; + this.txtdata = checkNotNull(txtdata, "txtdata"); + this.delegate = ImmutableMap. of("txtdata", txtdata); } /** * One or more character-strings. */ public String getTxtdata() { - return get("txtdata").toString(); + return txtdata; + } + + private final transient ImmutableMap delegate; + + protected Map delegate() { + return delegate; } public static TXTData txt(String txtdata) { diff --git a/providers/dynect/src/main/java/org/jclouds/dynect/v3/features/RecordAsyncApi.java b/providers/dynect/src/main/java/org/jclouds/dynect/v3/features/RecordAsyncApi.java index 57e763460c..aa26198700 100644 --- a/providers/dynect/src/main/java/org/jclouds/dynect/v3/features/RecordAsyncApi.java +++ b/providers/dynect/src/main/java/org/jclouds/dynect/v3/features/RecordAsyncApi.java @@ -128,7 +128,7 @@ public interface RecordAsyncApi { .put("fqdn", in.getFQDN()).build()); return (R) request.toBuilder() .endpoint(path) - .payload(json.toJson(ImmutableMap.of("rdata", ImmutableMap.copyOf(in.getRData()), "ttl", in.getTTL().intValue()))).build(); + .payload(json.toJson(ImmutableMap.of("rdata", in.getRData(), "ttl", in.getTTL()))).build(); } } From a95e42d1807960d08a9b2a2bea7ffdfbe3578b23 Mon Sep 17 00:00:00 2001 From: adriancole Date: Mon, 11 Mar 2013 14:56:09 -0700 Subject: [PATCH 3/3] ultradns-ws: replaced usage of UnsignedInteger with int --- .../ultradns/ws/ResourceTypeToValue.java | 23 +++++----- .../ultradns/ws/domain/ResourceRecord.java | 42 +++++++------------ .../org/jclouds/ultradns/ws/domain/Zone.java | 34 +++++++-------- .../ultradns/ws/domain/ZoneProperties.java | 22 ++++------ .../ws/features/ResourceRecordApi.java | 9 +--- .../ws/features/ResourceRecordAsyncApi.java | 12 ------ .../ws/features/RoundRobinPoolApi.java | 7 ++-- .../ws/features/RoundRobinPoolAsyncApi.java | 7 ++-- .../ws/xml/ResourceRecordMetadataHandler.java | 5 +-- .../jclouds/ultradns/ws/xml/ZoneHandler.java | 3 +- .../features/ResourceRecordApiExpectTest.java | 3 +- .../features/ResourceRecordApiLiveTest.java | 13 +++--- .../features/RoundRobinPoolApiLiveTest.java | 16 ++++--- 13 files changed, 72 insertions(+), 124 deletions(-) diff --git a/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/ResourceTypeToValue.java b/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/ResourceTypeToValue.java index f3e76d3ae1..6d9da796d2 100644 --- a/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/ResourceTypeToValue.java +++ b/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/ResourceTypeToValue.java @@ -29,7 +29,6 @@ import com.google.common.base.Function; import com.google.common.collect.BiMap; import com.google.common.collect.ForwardingMap; import com.google.common.collect.ImmutableBiMap; -import com.google.common.primitives.UnsignedInteger; /** * Most UltraDNS commands use the numerical type value of a resource record @@ -41,8 +40,8 @@ import com.google.common.primitives.UnsignedInteger; * @see org.jclouds.rest.annotations.ParamParser */ @Beta -public class ResourceTypeToValue extends ForwardingMap implements Function, - BiMap { +public class ResourceTypeToValue extends ForwardingMap implements Function, + BiMap { /** * look up the value (ex. {@code 28}) for the mnemonic name (ex. {@code AAAA} @@ -53,7 +52,7 @@ public class ResourceTypeToValue extends ForwardingMap * @throws IllegalArgumentException * if the type was not configured. */ - public static UnsignedInteger lookup(String type) throws IllegalArgumentException { + public static Integer lookup(String type) throws IllegalArgumentException { checkNotNull(type, "resource type was null"); checkArgument(lookup.containsKey(type), "%s do not include %s; types: %s", ResourceTypes.class.getSimpleName(), type, EnumSet.allOf(ResourceTypes.class)); @@ -113,22 +112,22 @@ public class ResourceTypeToValue extends ForwardingMap */ SRV(33); - private final UnsignedInteger value; + private final int value; private ResourceTypes(int value) { - this.value = UnsignedInteger.fromIntBits(value); + this.value = value; } } @Override - protected ImmutableBiMap delegate() { + protected ImmutableBiMap delegate() { return lookup; } - private static final ImmutableBiMap lookup; + private static final ImmutableBiMap lookup; static { - ImmutableBiMap.Builder builder = ImmutableBiMap.builder(); + ImmutableBiMap.Builder builder = ImmutableBiMap.builder(); for (ResourceTypes r : EnumSet.allOf(ResourceTypes.class)) { builder.put(r.name(), r.value); } @@ -140,17 +139,17 @@ public class ResourceTypeToValue extends ForwardingMap */ @Deprecated @Override - public UnsignedInteger forcePut(String key, UnsignedInteger value) { + public Integer forcePut(String key, Integer value) { return lookup.forcePut(key, value); } @Override - public Set values() { + public Set values() { return lookup.values(); } @Override - public BiMap inverse() { + public BiMap inverse() { return lookup.inverse(); } diff --git a/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/domain/ResourceRecord.java b/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/domain/ResourceRecord.java index 005d002d71..e505f1bb2d 100644 --- a/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/domain/ResourceRecord.java +++ b/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/domain/ResourceRecord.java @@ -21,6 +21,7 @@ package org.jclouds.ultradns.ws.domain; import static com.google.common.base.Functions.toStringFunction; import static com.google.common.base.Objects.equal; import static com.google.common.base.Objects.toStringHelper; +import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.collect.Iterables.transform; @@ -30,7 +31,6 @@ import org.jclouds.ultradns.ws.ResourceTypeToValue; import com.google.common.base.Objects; import com.google.common.collect.ImmutableList; -import com.google.common.primitives.UnsignedInteger; /** * @author Adrian Cole @@ -38,14 +38,16 @@ import com.google.common.primitives.UnsignedInteger; public class ResourceRecord { private final String dName; - private final UnsignedInteger type; - private final UnsignedInteger ttl; + private final int type; + private final int ttl; private final List infoValues; - private ResourceRecord(String dName, UnsignedInteger type, UnsignedInteger ttl, List infoValues) { + private ResourceRecord(String dName, int type, int ttl, List infoValues) { this.dName = checkNotNull(dName, "dName"); - this.type = checkNotNull(type, "type of %s", dName); - this.ttl = checkNotNull(ttl, "ttl of %s", dName); + checkArgument(type >= 0, "type of %s must be unsigned", dName); + this.type = type; + checkArgument(ttl >= 0, "ttl of %s must be unsigned", dName); + this.ttl = ttl; this.infoValues = checkNotNull(infoValues, "infoValues of %s", dName); } @@ -59,11 +61,11 @@ public class ResourceRecord { /** * the type value. ex {@code 1} for type {@code A} */ - public UnsignedInteger getType() { + public int getType() { return type; } - public UnsignedInteger getTTL() { + public int getTTL() { return ttl; } @@ -106,8 +108,8 @@ public class ResourceRecord { public final static class Builder { private String dName; - private UnsignedInteger type; - private UnsignedInteger ttl; + private int type = -1; + private int ttl = -1; private ImmutableList.Builder infoValues = ImmutableList. builder(); /** @@ -132,26 +134,11 @@ public class ResourceRecord { return this; } - /** - * @see ResourceRecord#getType() - */ - public Builder type(UnsignedInteger type) { - this.type = type; - return this; - } - /** * @see ResourceRecord#getType() */ public Builder type(int type) { - return type(UnsignedInteger.fromIntBits(type)); - } - - /** - * @see ResourceRecord#getTTL() - */ - public Builder ttl(UnsignedInteger ttl) { - this.ttl = ttl; + this.type = type; return this; } @@ -159,7 +146,8 @@ public class ResourceRecord { * @see ResourceRecord#getTTL() */ public Builder ttl(int ttl) { - return ttl(UnsignedInteger.fromIntBits(ttl)); + this.ttl = ttl; + return this; } /** diff --git a/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/domain/Zone.java b/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/domain/Zone.java index d44c1cfcb5..45b6e83686 100644 --- a/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/domain/Zone.java +++ b/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/domain/Zone.java @@ -18,11 +18,11 @@ */ package org.jclouds.ultradns.ws.domain; +import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; import com.google.common.base.Objects; import com.google.common.base.Optional; -import com.google.common.primitives.UnsignedInteger; /** * @@ -33,17 +33,18 @@ public final class Zone { private final String id; private final String name; private final Type type; - private final UnsignedInteger typeCode; + private final int typeCode; private final String accountId; private final String ownerId; private final DNSSECStatus dnssecStatus; private final Optional primarySrc; - private Zone(String id, String name, Type type, UnsignedInteger typeCode, String accountId, String ownerId, + private Zone(String id, String name, Type type, int typeCode, String accountId, String ownerId, DNSSECStatus dnssecStatus, Optional primarySrc) { this.id = checkNotNull(id, "id"); this.name = checkNotNull(name, "name for %s", id); - this.typeCode = checkNotNull(typeCode, "typeCode for %s", name); + checkArgument(typeCode >= 0, "typeCode of %s must be unsigned", id); + this.typeCode = typeCode; this.type = checkNotNull(type, "type for %s", name); this.accountId = checkNotNull(accountId, "accountId for %s", name); this.ownerId = checkNotNull(ownerId, "ownerId for %s", name); @@ -75,7 +76,7 @@ public final class Zone { /** * The type of the zone */ - public UnsignedInteger getTypeCode() { + public int getTypeCode() { return typeCode; } @@ -136,13 +137,13 @@ public final class Zone { PRIMARY(1), SECONDARY(2), ALIAS(3), UNRECOGNIZED(-1); - private final UnsignedInteger code; + private final int code; Type(int code) { - this.code = UnsignedInteger.fromIntBits(code); + this.code = code; } - public UnsignedInteger getCode() { + public int getCode() { return code; } @@ -152,11 +153,11 @@ public final class Zone { } public static Type fromValue(String type) { - return fromValue(UnsignedInteger.valueOf(checkNotNull(type, "type"))); + return fromValue(Integer.parseInt(checkNotNull(type, "type"))); } - public static Type fromValue(UnsignedInteger code) { - switch (code.intValue()) { + public static Type fromValue(int code) { + switch (code) { case 1: return PRIMARY; case 2: @@ -194,7 +195,7 @@ public final class Zone { private String id; private String name; private Type type; - private UnsignedInteger typeCode; + private int typeCode = -1; private String accountId; private String ownerId; private DNSSECStatus dnssecStatus; @@ -227,19 +228,12 @@ public final class Zone { /** * @see Zone#getTypeCode() */ - public Builder typeCode(UnsignedInteger typeCode) { + public Builder typeCode(int typeCode) { this.typeCode = typeCode; this.type = Type.fromValue(typeCode); return this; } - /** - * @see ZoneProperties#getTypeCode() - */ - public Builder typeCode(int typeCode) { - return typeCode(UnsignedInteger.fromIntBits(typeCode)); - } - /** * @see Zone#getAccountId() */ diff --git a/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/domain/ZoneProperties.java b/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/domain/ZoneProperties.java index a05cf0ee59..014a7f801b 100644 --- a/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/domain/ZoneProperties.java +++ b/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/domain/ZoneProperties.java @@ -18,6 +18,7 @@ */ package org.jclouds.ultradns.ws.domain; +import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; import java.util.Date; @@ -25,7 +26,6 @@ import java.util.Date; import org.jclouds.ultradns.ws.domain.Zone.Type; import com.google.common.base.Objects; -import com.google.common.primitives.UnsignedInteger; /** * @@ -35,13 +35,14 @@ public final class ZoneProperties { private final String name; private final Type type; - private final UnsignedInteger typeCode; + private final int typeCode; private final Date modified; private final int resourceRecordCount; - private ZoneProperties(String name, Type type, UnsignedInteger typeCode, Date modified, int resourceRecordCount) { + private ZoneProperties(String name, Type type, int typeCode, Date modified, int resourceRecordCount) { this.name = checkNotNull(name, "name"); - this.typeCode = checkNotNull(typeCode, "typeCode for %s", name); + checkArgument(typeCode >= 0, "typeCode of %s must be unsigned", name); + this.typeCode = typeCode; this.type = checkNotNull(type, "type for %s", name); this.modified = checkNotNull(modified, "modified for %s", name); this.resourceRecordCount = checkNotNull(resourceRecordCount, "resourceRecordCount for %s", name); @@ -64,7 +65,7 @@ public final class ZoneProperties { /** * The type of the zone */ - public UnsignedInteger getTypeCode() { + public int getTypeCode() { return typeCode; } @@ -114,7 +115,7 @@ public final class ZoneProperties { public final static class Builder { private String name; private Type type; - private UnsignedInteger typeCode; + private int typeCode = -1; private Date modified; private int resourceRecordCount; @@ -137,19 +138,12 @@ public final class ZoneProperties { /** * @see ZoneProperties#getTypeCode() */ - public Builder typeCode(UnsignedInteger typeCode) { + public Builder typeCode(int typeCode) { this.typeCode = typeCode; this.type = Type.fromValue(typeCode); return this; } - /** - * @see ZoneProperties#getTypeCode() - */ - public Builder typeCode(int typeCode) { - return typeCode(UnsignedInteger.fromIntBits(typeCode)); - } - /** * @see ZoneProperties#getModified() */ diff --git a/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/features/ResourceRecordApi.java b/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/features/ResourceRecordApi.java index fd78949bf5..e8d3072d30 100644 --- a/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/features/ResourceRecordApi.java +++ b/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/features/ResourceRecordApi.java @@ -25,7 +25,6 @@ import org.jclouds.ultradns.ws.domain.ResourceRecord; import org.jclouds.ultradns.ws.domain.ResourceRecordMetadata; import com.google.common.collect.FluentIterable; -import com.google.common.primitives.UnsignedInteger; /** * @see ResourceRecordAsyncApi @@ -88,12 +87,6 @@ public interface ResourceRecordApi { * @throws ResourceNotFoundException * if the zone doesn't exist */ - FluentIterable listByNameAndType(String hostName, UnsignedInteger rrType) - throws ResourceNotFoundException; - - /** - * @see #listByNameAndType(String, UnsignedInteger) - */ FluentIterable listByNameAndType(String hostName, int rrType) throws ResourceNotFoundException; @@ -101,7 +94,7 @@ public interface ResourceRecordApi { * @param type * the literal type defined in {@link ResourceTypeToValue}. ex * {@code AAAA} - * @see #listByNameAndType(String, UnsignedInteger) + * @see #listByNameAndType(String, int) */ FluentIterable listByNameAndType(String hostName, String type) throws ResourceNotFoundException; diff --git a/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/features/ResourceRecordAsyncApi.java b/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/features/ResourceRecordAsyncApi.java index fac2b181c9..76447e74a6 100644 --- a/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/features/ResourceRecordAsyncApi.java +++ b/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/features/ResourceRecordAsyncApi.java @@ -41,7 +41,6 @@ import org.jclouds.ultradns.ws.xml.GuidHandler; import org.jclouds.ultradns.ws.xml.ResourceRecordListHandler; import com.google.common.collect.FluentIterable; -import com.google.common.primitives.UnsignedInteger; import com.google.common.util.concurrent.ListenableFuture; /** @@ -92,17 +91,6 @@ public interface ResourceRecordAsyncApi { ListenableFuture> listByName(@PayloadParam("hostName") String hostName) throws ResourceNotFoundException; - /** - * @see ResourceRecordApi#listByNameAndType(String, UnsignedInteger) - */ - @Named("getResourceRecordsOfDNameByType") - @POST - @XMLResponseParser(ResourceRecordListHandler.class) - @Payload("{zoneName}{hostName}{rrType}") - ListenableFuture> listByNameAndType( - @PayloadParam("hostName") String hostName, @PayloadParam("rrType") UnsignedInteger rrType) - throws ResourceNotFoundException; - /** * @see ResourceRecordApi#listByNameAndType(String, int) */ diff --git a/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/features/RoundRobinPoolApi.java b/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/features/RoundRobinPoolApi.java index 7cba3e8f43..9c4eb87f18 100644 --- a/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/features/RoundRobinPoolApi.java +++ b/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/features/RoundRobinPoolApi.java @@ -25,7 +25,6 @@ import org.jclouds.ultradns.ws.domain.ResourceRecordMetadata; import org.jclouds.ultradns.ws.domain.RoundRobinPool; import com.google.common.collect.FluentIterable; -import com.google.common.primitives.UnsignedInteger; /** * @see RoundRobinPoolAsyncApi @@ -59,7 +58,7 @@ public interface RoundRobinPoolApi { * @throws ResourceAlreadyExistsException * if a record already exists with the same attrs */ - String addARecordWithAddressAndTTL(String lbPoolID, String ipv4Address, UnsignedInteger ttl) + String addARecordWithAddressAndTTL(String lbPoolID, String ipv4Address, int ttl) throws ResourceAlreadyExistsException; /** @@ -89,7 +88,7 @@ public interface RoundRobinPoolApi { * @throws ResourceAlreadyExistsException * if a record already exists with the same attrs */ - String addAAAARecordWithAddressAndTTL(String lbPoolID, String ipv6Address, UnsignedInteger ttl) + String addAAAARecordWithAddressAndTTL(String lbPoolID, String ipv6Address, int ttl) throws ResourceAlreadyExistsException; /** @@ -108,7 +107,7 @@ public interface RoundRobinPoolApi { * @throws ResourceNotFoundException * if the guid doesn't exist */ - void updateRecordWithAddressAndTTL(String lbPoolID, String guid, String address, UnsignedInteger ttl) + void updateRecordWithAddressAndTTL(String lbPoolID, String guid, String address, int ttl) throws ResourceNotFoundException; /** diff --git a/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/features/RoundRobinPoolAsyncApi.java b/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/features/RoundRobinPoolAsyncApi.java index 795392eccc..9e8c9d39c7 100644 --- a/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/features/RoundRobinPoolAsyncApi.java +++ b/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/features/RoundRobinPoolAsyncApi.java @@ -39,7 +39,6 @@ import org.jclouds.ultradns.ws.xml.ResourceRecordListHandler; import org.jclouds.ultradns.ws.xml.RoundRobinPoolListHandler; import com.google.common.collect.FluentIterable; -import com.google.common.primitives.UnsignedInteger; import com.google.common.util.concurrent.ListenableFuture; /** @@ -89,7 +88,7 @@ public interface RoundRobinPoolAsyncApi { @XMLResponseParser(GuidHandler.class) @Payload("") ListenableFuture addARecordWithAddressAndTTL(@PayloadParam("lbPoolID") String lbPoolID, - @PayloadParam("address") String ipv4Address, @PayloadParam("ttl") UnsignedInteger ttl) + @PayloadParam("address") String ipv4Address, @PayloadParam("ttl") int ttl) throws ResourceAlreadyExistsException; /** @@ -100,7 +99,7 @@ public interface RoundRobinPoolAsyncApi { @Payload("") ListenableFuture updateRecordWithAddressAndTTL(@PayloadParam("lbPoolID") String lbPoolID, @PayloadParam("guid") String guid, @PayloadParam("address") String ipv4Address, - @PayloadParam("ttl") UnsignedInteger ttl) throws ResourceNotFoundException; + @PayloadParam("ttl") int ttl) throws ResourceNotFoundException; /** * @see RoundRobinPoolApi#deleteRecord(String) @@ -129,7 +128,7 @@ public interface RoundRobinPoolAsyncApi { @XMLResponseParser(GuidHandler.class) @Payload("") ListenableFuture addAAAARecordWithAddressAndTTL(@PayloadParam("lbPoolID") String lbPoolID, - @PayloadParam("address") String ipv6Address, @PayloadParam("ttl") UnsignedInteger ttl) + @PayloadParam("address") String ipv6Address, @PayloadParam("ttl") int ttl) throws ResourceAlreadyExistsException; /** diff --git a/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/xml/ResourceRecordMetadataHandler.java b/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/xml/ResourceRecordMetadataHandler.java index 17265f2a56..9fbf48e52d 100644 --- a/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/xml/ResourceRecordMetadataHandler.java +++ b/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/xml/ResourceRecordMetadataHandler.java @@ -29,7 +29,6 @@ import org.jclouds.ultradns.ws.domain.ResourceRecord; import org.jclouds.ultradns.ws.domain.ResourceRecordMetadata; import org.xml.sax.Attributes; -import com.google.common.primitives.UnsignedInteger; import com.google.inject.Inject; /** @@ -67,9 +66,9 @@ public class ResourceRecordMetadataHandler extends rrm.zoneName(attributes.get("ZoneName")); rrm.created(dateService.iso8601DateParse(attributes.get("Created"))); rrm.modified(dateService.iso8601DateParse(attributes.get("Modified"))); - rr.type(UnsignedInteger.valueOf(attributes.get("Type"))); + rr.type(Integer.parseInt(attributes.get("Type"))); rr.name(attributes.get("DName")); - rr.ttl(UnsignedInteger.valueOf(attributes.get("TTL"))); + rr.ttl(Integer.parseInt(attributes.get("TTL"))); } else if (equalsOrSuffix(qName, "InfoValues")) { rr.rdata(attributes.values()); } diff --git a/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/xml/ZoneHandler.java b/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/xml/ZoneHandler.java index 43ee32f23b..d61c15da80 100644 --- a/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/xml/ZoneHandler.java +++ b/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/xml/ZoneHandler.java @@ -29,7 +29,6 @@ import org.jclouds.ultradns.ws.domain.Zone; import org.jclouds.ultradns.ws.domain.Zone.DNSSECStatus; import org.xml.sax.Attributes; -import com.google.common.primitives.UnsignedInteger; /** * @@ -55,7 +54,7 @@ public class ZoneHandler extends ParseSax.HandlerForGeneratedRequestWithResult 0, "Type must be positive for a ResourceRecord " + rr); + assertTrue(rr.getType() > 0, "Type must be unsigned for a ResourceRecord " + rr); checkNotNull(rr.getType(), "Type cannot be null for a ResourceRecord %s", rr); checkNotNull(rr.getTTL(), "TTL cannot be null for a ResourceRecord %s", rr); checkNotNull(rr.getRData(), "InfoValues cannot be null for a ResourceRecord %s", rr); @@ -105,19 +104,19 @@ public class ResourceRecordApiLiveTest extends BaseUltraDNSWSApiLiveTest { } } - LoadingCache recordTypeCounts = CacheBuilder.newBuilder().build( - new CacheLoader() { - public AtomicLong load(UnsignedInteger key) throws Exception { + LoadingCache recordTypeCounts = CacheBuilder.newBuilder().build( + new CacheLoader() { + public AtomicLong load(Integer key) throws Exception { return new AtomicLong(); } }); - private final static BiMap valueToType = new ResourceTypeToValue().inverse(); + private final static BiMap valueToType = new ResourceTypeToValue().inverse(); @AfterClass void logSummary() { getAnonymousLogger().info("zoneCount: " + zones); - for (Entry entry : recordTypeCounts.asMap().entrySet()) + for (Entry entry : recordTypeCounts.asMap().entrySet()) getAnonymousLogger().info( String.format("type: %s, count: %s", valueToType.get(entry.getKey()), entry.getValue())); } diff --git a/providers/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/features/RoundRobinPoolApiLiveTest.java b/providers/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/features/RoundRobinPoolApiLiveTest.java index 64f3cf7125..d6f31b4560 100644 --- a/providers/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/features/RoundRobinPoolApiLiveTest.java +++ b/providers/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/features/RoundRobinPoolApiLiveTest.java @@ -42,7 +42,6 @@ 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.primitives.UnsignedInteger; /** * @author Adrian Cole @@ -122,21 +121,21 @@ public class RoundRobinPoolApiLiveTest extends BaseUltraDNSWSApiLiveTest { @Test(dependsOnMethods = "testCreateAPool") public void addARecordToPool() { - aRecord1 = api(zoneName).addARecordWithAddressAndTTL(aPoolId, "1.2.3.4", UnsignedInteger.ONE); + aRecord1 = api(zoneName).addARecordWithAddressAndTTL(aPoolId, "1.2.3.4", 1); getAnonymousLogger().info("created A record: " + aRecord1); assertTrue(listRRs(aPoolId).anyMatch( equalTo(rrBuilder().name(hostname).type("A").ttl(1).rdata("1.2.3.4").build()))); - aRecord2 = api(zoneName).addARecordWithAddressAndTTL(aPoolId, "3.4.5.6", UnsignedInteger.ONE); + aRecord2 = api(zoneName).addARecordWithAddressAndTTL(aPoolId, "3.4.5.6", 1); assertTrue(listRRs(aPoolId).anyMatch( equalTo(rrBuilder().name(hostname).type("A").ttl(1).rdata("3.4.5.6").build()))); getAnonymousLogger().info("created A record: " + aRecord1); try { - api(zoneName).addARecordWithAddressAndTTL(aPoolId, "1.2.3.4", UnsignedInteger.ONE); + api(zoneName).addARecordWithAddressAndTTL(aPoolId, "1.2.3.4", 1); fail(); } catch (ResourceAlreadyExistsException e) { @@ -145,7 +144,7 @@ public class RoundRobinPoolApiLiveTest extends BaseUltraDNSWSApiLiveTest { @Test(dependsOnMethods = "addARecordToPool") public void testUpdateRecord() { - api(zoneName).updateRecordWithAddressAndTTL(aPoolId, aRecord1, "1.1.1.1", UnsignedInteger.ZERO); + api(zoneName).updateRecordWithAddressAndTTL(aPoolId, aRecord1, "1.1.1.1", 0); assertTrue(listRRs(aPoolId).anyMatch( equalTo(rrBuilder().name(hostname).type("A").ttl(0).rdata("1.1.1.1").build()))); } @@ -190,7 +189,7 @@ public class RoundRobinPoolApiLiveTest extends BaseUltraDNSWSApiLiveTest { @Test(dependsOnMethods = "testCreateAAAAPool") public void addAAAARecordToPool() { aaaaRecord1 = api(zoneName).addAAAARecordWithAddressAndTTL(aaaaPoolId, "2001:0DB8:85A3:0000:0000:8A2E:0370:7334", - UnsignedInteger.ONE); + 1); getAnonymousLogger().info("created AAAA record: " + aaaaRecord1); @@ -199,7 +198,7 @@ public class RoundRobinPoolApiLiveTest extends BaseUltraDNSWSApiLiveTest { .build()))); aaaaRecord2 = api(zoneName).addAAAARecordWithAddressAndTTL(aaaaPoolId, "2002:0DB8:85A3:0000:0000:8A2E:0370:7334", - UnsignedInteger.ONE); + 1); assertTrue(listRRs(aaaaPoolId).anyMatch( equalTo(rrBuilder().name(hostname).type("AAAA").ttl(1).rdata("2002:0DB8:85A3:0000:0000:8A2E:0370:7334") @@ -207,8 +206,7 @@ public class RoundRobinPoolApiLiveTest extends BaseUltraDNSWSApiLiveTest { getAnonymousLogger().info("created AAAA record: " + aaaaRecord1); try { - api(zoneName).addAAAARecordWithAddressAndTTL(aaaaPoolId, "2001:0DB8:85A3:0000:0000:8A2E:0370:7334", - UnsignedInteger.ONE); + api(zoneName).addAAAARecordWithAddressAndTTL(aaaaPoolId, "2001:0DB8:85A3:0000:0000:8A2E:0370:7334", 1); fail(); } catch (ResourceAlreadyExistsException e) {