Skip to content

Commit a2fdb69

Browse files
committed
Merge pull request #592 from mderka/dns-polishing
Renamed ManagedZoneInfo to ZoneInfo and added time units for ttl. Fixes #581 and fixes #579.
2 parents 2c87334 + 7bcff48 commit a2fdb69

File tree

7 files changed

+133
-117
lines changed

7 files changed

+133
-117
lines changed

gcloud-java-dns/src/main/java/com/google/gcloud/dns/ChangeRequest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434

3535
/**
3636
* A class representing an atomic update to a collection of {@link DnsRecord}s within a {@code
37-
* ManagedZone}.
37+
* Zone}.
3838
*
3939
* @see <a href="https://cloud.google.com/dns/api/v1/changes">Google Cloud DNS documentation</a>
4040
*/
@@ -102,7 +102,7 @@ public Builder additions(List<DnsRecord> additions) {
102102
this.additions = Lists.newLinkedList(checkNotNull(additions));
103103
return this;
104104
}
105-
105+
106106
/**
107107
* Sets a collection of {@link DnsRecord}s which are to be deleted from the zone upon executing
108108
* this {@code ChangeRequest}.

gcloud-java-dns/src/main/java/com/google/gcloud/dns/DnsRecord.java

+17-10
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,21 @@
2222
import com.google.common.base.MoreObjects;
2323
import com.google.common.collect.ImmutableList;
2424
import com.google.common.collect.Lists;
25+
import com.google.common.primitives.Ints;
2526

2627
import java.io.Serializable;
2728
import java.util.LinkedList;
2829
import java.util.List;
2930
import java.util.Objects;
31+
import java.util.concurrent.TimeUnit;
3032

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

5052
/**
@@ -176,14 +178,19 @@ public Builder name(String name) {
176178
}
177179

178180
/**
179-
* Sets the number of seconds that this record can be cached by resolvers. This number must be
180-
* non-negative.
181+
* Sets the time that this record can be cached by resolvers. This number must be non-negative.
182+
* The maximum duration must be equivalent to at most {@link Integer#MAX_VALUE} seconds.
181183
*
182-
* @param ttl A non-negative number of seconds
184+
* @param duration A non-negative number of time units
185+
* @param unit The unit of the ttl parameter
183186
*/
184-
public Builder ttl(int ttl) {
185-
checkArgument(ttl >= 0, "TTL cannot be negative. The supplied value was %s.", ttl);
186-
this.ttl = ttl;
187+
public Builder ttl(int duration, TimeUnit unit) {
188+
checkArgument(duration >= 0,
189+
"Duration cannot be negative. The supplied value was %s.", duration);
190+
checkNotNull(unit);
191+
// we cannot have long because pb does not support it
192+
long converted = unit.toSeconds(duration);
193+
ttl = Ints.checkedCast(converted);
187194
return this;
188195
}
189196

@@ -278,7 +285,7 @@ static DnsRecord fromPb(com.google.api.services.dns.model.ResourceRecordSet pb)
278285
builder.records(pb.getRrdatas());
279286
}
280287
if (pb.getTtl() != null) {
281-
builder.ttl(pb.getTtl());
288+
builder.ttl(pb.getTtl(), TimeUnit.SECONDS);
282289
}
283290
return builder.build();
284291
}

gcloud-java-dns/src/main/java/com/google/gcloud/dns/ProjectInfo.java

+11-11
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

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

5656
/**
@@ -64,18 +64,18 @@ public static class Quota {
6464
int resourceRecordsPerRrset,
6565
int rrsetAdditionsPerChange,
6666
int rrsetDeletionsPerChange,
67-
int rrsetsPerManagedZone,
67+
int rrsetsPerZone,
6868
int totalRrdataSizePerChange) {
6969
this.zones = zones;
7070
this.resourceRecordsPerRrset = resourceRecordsPerRrset;
7171
this.rrsetAdditionsPerChange = rrsetAdditionsPerChange;
7272
this.rrsetDeletionsPerChange = rrsetDeletionsPerChange;
73-
this.rrsetsPerManagedZone = rrsetsPerManagedZone;
73+
this.rrsetsPerZone = rrsetsPerZone;
7474
this.totalRrdataSizePerChange = totalRrdataSizePerChange;
7575
}
7676

7777
/**
78-
* Returns the maximum allowed number of managed zones in the project.
78+
* Returns the maximum allowed number of zones in the project.
7979
*/
8080
public int zones() {
8181
return zones;
@@ -104,11 +104,11 @@ public int rrsetDeletionsPerChange() {
104104
}
105105

106106
/**
107-
* Returns the maximum allowed number of {@link DnsRecord}s per {@link ManagedZoneInfo} in the
107+
* Returns the maximum allowed number of {@link DnsRecord}s per {@link ZoneInfo} in the
108108
* project.
109109
*/
110-
public int rrsetsPerManagedZone() {
111-
return rrsetsPerManagedZone;
110+
public int rrsetsPerZone() {
111+
return rrsetsPerZone;
112112
}
113113

114114
/**
@@ -126,7 +126,7 @@ public boolean equals(Object other) {
126126
@Override
127127
public int hashCode() {
128128
return Objects.hash(zones, resourceRecordsPerRrset, rrsetAdditionsPerChange,
129-
rrsetDeletionsPerChange, rrsetsPerManagedZone, totalRrdataSizePerChange);
129+
rrsetDeletionsPerChange, rrsetsPerZone, totalRrdataSizePerChange);
130130
}
131131

132132
com.google.api.services.dns.model.Quota toPb() {
@@ -135,7 +135,7 @@ com.google.api.services.dns.model.Quota toPb() {
135135
pb.setResourceRecordsPerRrset(resourceRecordsPerRrset);
136136
pb.setRrsetAdditionsPerChange(rrsetAdditionsPerChange);
137137
pb.setRrsetDeletionsPerChange(rrsetDeletionsPerChange);
138-
pb.setRrsetsPerManagedZone(rrsetsPerManagedZone);
138+
pb.setRrsetsPerManagedZone(rrsetsPerZone);
139139
pb.setTotalRrdataSizePerChange(totalRrdataSizePerChange);
140140
return pb;
141141
}
@@ -158,7 +158,7 @@ public String toString() {
158158
.add("resourceRecordsPerRrset", resourceRecordsPerRrset)
159159
.add("rrsetAdditionsPerChange", rrsetAdditionsPerChange)
160160
.add("rrsetDeletionsPerChange", rrsetDeletionsPerChange)
161-
.add("rrsetsPerManagedZone", rrsetsPerManagedZone)
161+
.add("rrsetsPerZone", rrsetsPerZone)
162162
.add("totalRrdataSizePerChange", totalRrdataSizePerChange)
163163
.toString();
164164
}

0 commit comments

Comments
 (0)