Skip to content

Commit b38f39d

Browse files
committed
---
yaml --- r: 3047 b: refs/heads/master c: f652277 h: refs/heads/master i: 3045: bf0a582 3043: b7884bd 3039: 57e4ffc
1 parent f3e9a28 commit b38f39d

4 files changed

Lines changed: 166 additions & 116 deletions

File tree

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: fe4e137fce65882465ca0e092761e080f366fece
2+
refs/heads/master: f652277e166b7d3cb3f248e0dafd92ea063c0caf
33
refs/heads/travis: e21ee7b88a5edc3f3d8c71f90c3fc32abf7e8dd6
44
refs/heads/gh-pages: 4e0561bb4504bf647db669a14417b2b2c87ba45d
55
refs/heads/pubsub-alpha: 1a0e970f265af871e02274085b9662b3fe29058b

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

Lines changed: 102 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -15,110 +15,110 @@
1515
*/
1616
package com.google.gcloud.dns;
1717

18+
import static com.google.common.base.Preconditions.checkArgument;
1819
import static com.google.common.base.Preconditions.checkNotNull;
1920

2021
import com.google.common.collect.ImmutableList;
2122

23+
import java.io.Serializable;
24+
2225
import java.util.LinkedList;
2326
import java.util.List;
27+
import java.util.Objects;
2428

2529
/**
2630
* A class that represents Google Cloud DNS record set.
2731
*
28-
* <p>
29-
* A unit of data that will be returned by the DNS servers.
32+
* <p> A unit of data that will be returned by the DNS servers.
3033
*
31-
* @see <a href="https://cloud.google.com/dns/api/v1/resourceRecordSets">Google
32-
* Cloud DNS documentation</a>
34+
* @see <a href="https://cloud.google.com/dns/api/v1/resourceRecordSets">Google Cloud DNS
35+
* documentation</a>
3336
*/
34-
public class DnsRecord {
37+
public class DnsRecord implements Serializable {
3538

36-
private String name;
37-
private List<String> rrdatas = new LinkedList<>();
38-
private Integer ttl = 86400; // the default ttl of 24 hours
39-
private DnsRecordType type;
40-
private String parentName;
41-
private Long parentId;
39+
private static final long serialVersionUID = 2016011914302204L;
40+
private final String name;
41+
private final List<String> rrdatas;
42+
private final Integer ttl;
43+
private final DnsRecordType type;
44+
private final String zoneName;
45+
private final Long zoneId;
4246

4347
/**
4448
* A private constructor. Obtain an instance using {@link DnsRecord#Builder}.
4549
*/
4650
private DnsRecord() {
51+
this.name = null;
52+
this.rrdatas = null;
53+
this.ttl = null;
54+
this.type = null;
55+
this.zoneName = null;
56+
this.zoneId = null;
4757
}
4858

4959
DnsRecord(Builder builder) {
5060
this.name = builder.name;
5161
this.rrdatas = ImmutableList.copyOf(builder.rrdatas);
5262
this.ttl = builder.ttl;
5363
this.type = builder.type;
54-
this.parentName = builder.parentName;
55-
this.parentId = builder.parentId;
64+
this.zoneName = builder.zoneName;
65+
this.zoneId = builder.zoneId;
5666
}
5767

5868
/**
5969
* Enum for the DNS record types supported by Cloud DNS.
6070
*
61-
* <p>
62-
* Google Cloud DNS currently supports records of type A, AAAA, CNAME, MX
63-
* NAPTR, NS, PTR, SOA, SPF, SRV, TXT.
71+
* <p> Google Cloud DNS currently supports records of type A, AAAA, CNAME, MX NAPTR, NS, PTR, SOA,
72+
* SPF, SRV, TXT.
6473
*
65-
* @see
66-
* <a href="https://cloud.google.com/dns/what-is-cloud-dns#supported_record_types">Cloud
67-
* DNS supported record types</a>
74+
* @see <a href="https://cloud.google.com/dns/what-is-cloud-dns#supported_record_types">Cloud DNS
75+
* supported record types</a>
6876
*/
6977
public enum DnsRecordType {
70-
A("A"),
71-
AAAA("AAAA"),
72-
CNAME("CNAME"),
73-
MX("MX"),
74-
NAPTR("NAPTR"),
75-
NS("NS"),
76-
PTR("PTR"),
77-
SOA("SOA"),
78-
SPF("SPF"),
79-
SRV("SRV"),
80-
TXT("TXT");
81-
82-
private final String type;
83-
84-
private DnsRecordType(String type) {
85-
this.type = type;
86-
}
78+
A,
79+
AAAA,
80+
CNAME,
81+
MX,
82+
NAPTR,
83+
NS,
84+
PTR,
85+
SOA,
86+
SPF,
87+
SRV,
88+
TXT;
8789
}
8890

8991
public static class Builder {
9092

9193
private List<String> rrdatas = new LinkedList<>();
9294
private String name;
93-
private Integer ttl = 86400; // default ttl of 24 hours
95+
private Integer ttl;
9496
private DnsRecordType type;
95-
private String parentName;
96-
private Long parentId;
97+
private String zoneName;
98+
private Long zoneId;
9799

98100
private Builder() {
99101
}
100102

101103
/**
102-
* Creates a builder and pre-populates attributes with the values from the
103-
* provided DnsRecord instance.
104+
* Creates a builder and pre-populates attributes with the values from the provided DnsRecord
105+
* instance.
104106
*/
105107
public Builder(DnsRecord record) {
106108
this.name = record.name;
107109
this.ttl = record.ttl;
108110
this.type = record.type;
109-
this.parentId = record.parentId;
110-
this.parentName = record.parentName;
111+
this.zoneId = record.zoneId;
112+
this.zoneName = record.zoneName;
111113
this.rrdatas.addAll(record.rrdatas);
112114
}
113115

114116
/**
115-
* Adds a record to the record set.
117+
* Adds a record to the record set. The records should be as defined in RFC 1035 (section 5) and
118+
* RFC 1034 (section 3.6.1). Examples of records are available in Google DNS documentation.
116119
*
117-
* <p>
118-
* The records should be as defined in RFC 1035 (section 5) and RFC 1034
119-
* (section 3.6.1). Examples of records are available in
120-
* <a href="https://cloud.google.com/dns/what-is-cloud-dns#supported_record_types">Cloud
121-
* DNS documentation</a>.
120+
* @see <a href="https://cloud.google.com/dns/what-is-cloud-dns#supported_record_types">Google
121+
* DNS documentation </a>.
122122
*/
123123
public Builder add(String record) {
124124
this.rrdatas.add(checkNotNull(record));
@@ -134,25 +134,19 @@ public Builder name(String name) {
134134
}
135135

136136
/**
137-
* Sets the number of seconds that this record can be cached by resolvers.
138-
* This number must be non-negative.
137+
* Sets the number of seconds that this record can be cached by resolvers. This number must be
138+
* non-negative.
139139
*
140140
* @param ttl A non-negative number of seconds
141141
*/
142142
public Builder ttl(int ttl) {
143-
// change only if
144-
if (ttl < 0) {
145-
throw new IllegalArgumentException(
146-
"TTL cannot be negative. The supplied value was " + ttl + "."
147-
);
148-
}
143+
checkArgument(ttl >= 0, "TTL cannot be negative. The supplied value was " + ttl + ".");
149144
this.ttl = ttl;
150145
return this;
151146
}
152147

153148
/**
154-
* The identifier of a supported record type, for example, A, AAAA, MX, TXT,
155-
* and so on.
149+
* The identifier of a supported record type, for example, A, AAAA, MX, TXT, and so on.
156150
*/
157151
public Builder type(DnsRecordType type) {
158152
this.type = checkNotNull(type);
@@ -171,8 +165,8 @@ public DnsRecord build() {
171165
*/
172166
public Builder managedZone(ManagedZoneInfo parent) {
173167
checkNotNull(parent);
174-
this.parentId = parent.id();
175-
this.parentName = parent.name();
168+
this.zoneId = parent.id();
169+
this.zoneName = parent.name();
176170
return this;
177171
}
178172
}
@@ -192,9 +186,7 @@ public static Builder builder() {
192186
}
193187

194188
/**
195-
* Get user assigned name of this DNS record.
196-
*
197-
* TODO: is this field mandatory?
189+
* Get the mandatory user assigned name of this DNS record.
198190
*/
199191
public String name() {
200192
return name;
@@ -204,16 +196,12 @@ public String name() {
204196
* Returns a list of DNS record stored in this record set.
205197
*/
206198
public List<String> rrdatas() {
207-
return rrdatas;
199+
return ImmutableList.copyOf(rrdatas);
208200
}
209201

210202
/**
211-
* Returns the number of seconds that this ResourceRecordSet can be cached by
212-
* resolvers.
213-
*
214-
* <p>
215-
* This number is provided by the user. If this values is not set, we use
216-
* default of 86400.
203+
* Returns the number of seconds that this ResourceRecordSet can be cached by resolvers. This
204+
* number is provided by the user.
217205
*/
218206
public Integer ttl() {
219207
return ttl;
@@ -227,28 +215,56 @@ public DnsRecordType type() {
227215
}
228216

229217
/**
230-
* Returns name of the managed zone that this record belongs to.
231-
*
232-
* <p>
233-
* The name of the managed zone is provided by the user when the managed zone
234-
* is created. It is unique within a project. If this DNS record is not
235-
* associated with a managed zone, this returns null.
218+
* Returns name of the managed zone that this record belongs to. The name of the managed zone is
219+
* provided by the user when the managed zone is created. It is unique within a project. If this
220+
* DNS record is not associated with a managed zone, this returns null.
236221
*/
237-
public String parentName() {
238-
return parentName;
222+
public String zoneName() {
223+
return zoneName;
239224
}
240225

241226
/**
242227
* Returns name of the managed zone that this record belongs to.
243228
*
244-
* <p>
245-
* The id of the managed zone is determined by the server when the managed
246-
* zone is created. It is a read only value. If this DNS record is not
247-
* associated with a managed zone, or if the id of the managed zone was not
248-
* loaded from the cloud service, this returns null.
229+
* <p> The id of the managed zone is determined by the server when the managed zone is created. It
230+
* is a read only value. If this DNS record is not associated with a managed zone, or if the id of
231+
* the managed zone was not loaded from the cloud service, this returns null.
249232
*/
250-
public Long parentId() {
251-
return parentId;
233+
public Long zoneId() {
234+
return zoneId;
235+
}
236+
237+
@Override
238+
public int hashCode() {
239+
return Objects.hash(name, rrdatas, ttl, type, zoneName, zoneId);
240+
}
241+
242+
@Override
243+
public boolean equals(Object obj) {
244+
if (obj instanceof DnsRecord) {
245+
DnsRecord other = (DnsRecord) obj;
246+
return zoneId == other.zoneId()
247+
&& zoneName == other.zoneName
248+
&& this.toRRSet().equals(other.toRRSet());
249+
}
250+
return false;
251+
}
252+
253+
com.google.api.services.dns.model.ResourceRecordSet toRRSet() {
254+
com.google.api.services.dns.model.ResourceRecordSet rrset =
255+
new com.google.api.services.dns.model.ResourceRecordSet();
256+
rrset.setName(name);
257+
rrset.setRrdatas(this.rrdatas());
258+
rrset.setTtl(ttl);
259+
rrset.setType(type == null ? null : type.name());
260+
return rrset;
261+
}
262+
263+
@Override
264+
public String toString() {
265+
return "DnsRecord{" + "name=" + name + ", rrdatas=" + rrdatas
266+
+ ", ttl=" + ttl + ", type=" + type + ", zoneName="
267+
+ zoneName + ", zoneId=" + zoneId + '}';
252268
}
253269

254270
}

trunk/gcloud-java-dns/src/main/java/com/google/gcloud/dns/ManagedZoneInfo.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
package com.google.gcloud.dns;
1717

1818
/**
19-
* TODO: Implement.
20-
* TODO: Add documentation.
19+
* todo(mderka): Implement.
20+
* todo(mderka): Add documentation.
2121
*/
2222
public class ManagedZoneInfo {
2323

@@ -26,19 +26,19 @@ public class ManagedZoneInfo {
2626

2727
public String name() {
2828
throw new UnsupportedOperationException("Not implemented yet.");
29-
// TODO: Implement
29+
// todo(mderka): Implement
3030
}
3131

3232
public Long id() {
3333
return id;
34-
// TODO: Implement
34+
// todo(mderka): Implement
3535
}
3636

3737
private ManagedZoneInfo() {
3838
name = null;
3939
id = null;
4040
throw new UnsupportedOperationException("Not implemented yet");
41-
// TODO: Implement
41+
// todo(mderka): Implement
4242
}
4343

4444
}

0 commit comments

Comments
 (0)