Skip to content

Commit

Permalink
Merge pull request #592 from mderka/dns-polishing
Browse files Browse the repository at this point in the history
Renamed ManagedZoneInfo to ZoneInfo and added time units for ttl. Fixes #581 and fixes #579.
  • Loading branch information
mderka committed Jan 28, 2016
2 parents 2c87334 + 7bcff48 commit a2fdb69
Show file tree
Hide file tree
Showing 7 changed files with 133 additions and 117 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

/**
* A class representing an atomic update to a collection of {@link DnsRecord}s within a {@code
* ManagedZone}.
* Zone}.
*
* @see <a href="https://cloud.google.com/dns/api/v1/changes">Google Cloud DNS documentation</a>
*/
Expand Down Expand Up @@ -102,7 +102,7 @@ public Builder additions(List<DnsRecord> additions) {
this.additions = Lists.newLinkedList(checkNotNull(additions));
return this;
}

/**
* Sets a collection of {@link DnsRecord}s which are to be deleted from the zone upon executing
* this {@code ChangeRequest}.
Expand Down
27 changes: 17 additions & 10 deletions gcloud-java-dns/src/main/java/com/google/gcloud/dns/DnsRecord.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,21 @@
import com.google.common.base.MoreObjects;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import com.google.common.primitives.Ints;

import java.io.Serializable;
import java.util.LinkedList;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.TimeUnit;

/**
* A class that represents a Google Cloud DNS record set.
*
* <p>A {@code DnsRecord} is the unit of data that will be returned by the DNS servers upon a DNS
* request for a specific domain. The {@code DnsRecord} holds the current state of the DNS records
* that make up a managed zone. You can read the records but you cannot modify them directly.
* Rather, you edit the records in a managed zone by creating a ChangeRequest.
* that make up a zone. You can read the records but you cannot modify them directly. Rather, you
* edit the records in a zone by creating a ChangeRequest.
*
* @see <a href="https://cloud.google.com/dns/api/v1/resourceRecordSets">Google Cloud DNS
* documentation</a>
Expand All @@ -44,7 +46,7 @@ public class DnsRecord implements Serializable {
private static final long serialVersionUID = 2016011914302204L;
private final String name;
private final List<String> rrdatas;
private final Integer ttl;
private final Integer ttl; // this is in seconds
private final Type type;

/**
Expand Down Expand Up @@ -176,14 +178,19 @@ public Builder name(String name) {
}

/**
* Sets the number of seconds that this record can be cached by resolvers. This number must be
* non-negative.
* Sets the time that this record can be cached by resolvers. This number must be non-negative.
* The maximum duration must be equivalent to at most {@link Integer#MAX_VALUE} seconds.
*
* @param ttl A non-negative number of seconds
* @param duration A non-negative number of time units
* @param unit The unit of the ttl parameter
*/
public Builder ttl(int ttl) {
checkArgument(ttl >= 0, "TTL cannot be negative. The supplied value was %s.", ttl);
this.ttl = ttl;
public Builder ttl(int duration, TimeUnit unit) {
checkArgument(duration >= 0,
"Duration cannot be negative. The supplied value was %s.", duration);
checkNotNull(unit);
// we cannot have long because pb does not support it
long converted = unit.toSeconds(duration);
ttl = Ints.checkedCast(converted);
return this;
}

Expand Down Expand Up @@ -278,7 +285,7 @@ static DnsRecord fromPb(com.google.api.services.dns.model.ResourceRecordSet pb)
builder.records(pb.getRrdatas());
}
if (pb.getTtl() != null) {
builder.ttl(pb.getTtl());
builder.ttl(pb.getTtl(), TimeUnit.SECONDS);
}
return builder.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

/**
* The class provides the Google Cloud DNS information associated with this project. A project is a
* top level container for resources including {@code ManagedZone}s. Projects can be created only in
* top level container for resources including {@code Zone}s. Projects can be created only in
* the APIs console.
*
* @see <a href="https://cloud.google.com/dns/api/v1/projects">Google Cloud DNS documentation</a>
Expand All @@ -50,7 +50,7 @@ public static class Quota {
private final int resourceRecordsPerRrset;
private final int rrsetAdditionsPerChange;
private final int rrsetDeletionsPerChange;
private final int rrsetsPerManagedZone;
private final int rrsetsPerZone;
private final int totalRrdataSizePerChange;

/**
Expand All @@ -64,18 +64,18 @@ public static class Quota {
int resourceRecordsPerRrset,
int rrsetAdditionsPerChange,
int rrsetDeletionsPerChange,
int rrsetsPerManagedZone,
int rrsetsPerZone,
int totalRrdataSizePerChange) {
this.zones = zones;
this.resourceRecordsPerRrset = resourceRecordsPerRrset;
this.rrsetAdditionsPerChange = rrsetAdditionsPerChange;
this.rrsetDeletionsPerChange = rrsetDeletionsPerChange;
this.rrsetsPerManagedZone = rrsetsPerManagedZone;
this.rrsetsPerZone = rrsetsPerZone;
this.totalRrdataSizePerChange = totalRrdataSizePerChange;
}

/**
* Returns the maximum allowed number of managed zones in the project.
* Returns the maximum allowed number of zones in the project.
*/
public int zones() {
return zones;
Expand Down Expand Up @@ -104,11 +104,11 @@ public int rrsetDeletionsPerChange() {
}

/**
* Returns the maximum allowed number of {@link DnsRecord}s per {@link ManagedZoneInfo} in the
* Returns the maximum allowed number of {@link DnsRecord}s per {@link ZoneInfo} in the
* project.
*/
public int rrsetsPerManagedZone() {
return rrsetsPerManagedZone;
public int rrsetsPerZone() {
return rrsetsPerZone;
}

/**
Expand All @@ -126,7 +126,7 @@ public boolean equals(Object other) {
@Override
public int hashCode() {
return Objects.hash(zones, resourceRecordsPerRrset, rrsetAdditionsPerChange,
rrsetDeletionsPerChange, rrsetsPerManagedZone, totalRrdataSizePerChange);
rrsetDeletionsPerChange, rrsetsPerZone, totalRrdataSizePerChange);
}

com.google.api.services.dns.model.Quota toPb() {
Expand All @@ -135,7 +135,7 @@ com.google.api.services.dns.model.Quota toPb() {
pb.setResourceRecordsPerRrset(resourceRecordsPerRrset);
pb.setRrsetAdditionsPerChange(rrsetAdditionsPerChange);
pb.setRrsetDeletionsPerChange(rrsetDeletionsPerChange);
pb.setRrsetsPerManagedZone(rrsetsPerManagedZone);
pb.setRrsetsPerManagedZone(rrsetsPerZone);
pb.setTotalRrdataSizePerChange(totalRrdataSizePerChange);
return pb;
}
Expand All @@ -158,7 +158,7 @@ public String toString() {
.add("resourceRecordsPerRrset", resourceRecordsPerRrset)
.add("rrsetAdditionsPerChange", rrsetAdditionsPerChange)
.add("rrsetDeletionsPerChange", rrsetDeletionsPerChange)
.add("rrsetsPerManagedZone", rrsetsPerManagedZone)
.add("rrsetsPerZone", rrsetsPerZone)
.add("totalRrdataSizePerChange", totalRrdataSizePerChange)
.toString();
}
Expand Down
Loading

0 comments on commit a2fdb69

Please sign in to comment.