Skip to content

Commit 3cf81e2

Browse files
committed
---
yaml --- r: 4439 b: refs/heads/logging-alpha c: 01662be h: refs/heads/master i: 4437: 558c718 4435: 028083d 4431: 4fa2386
1 parent 5ad82af commit 3cf81e2

5 files changed

Lines changed: 60 additions & 28 deletions

File tree

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ refs/heads/compute-alpha: 969cba2627f1d53d352cc4a5ffe0879dacf65e6c
1212
refs/heads/dns-alpha: 2f90e7e338349287ace33375896907af0f032ca1
1313
refs/heads/dns-alpha-batch: 17442b07867021b85d0452f5f3eda29a3413288f
1414
refs/heads/gcs-nio: 283aeaf15efdcf3621eb6859f05e55ad7764375d
15-
refs/heads/logging-alpha: 1fc0e3275e352706734dc935c6d4bab77976fb1c
15+
refs/heads/logging-alpha: 01662be5e9f6bf11496d84b909676f97ca0401b9
1616
refs/tags/v0.1.0: a615317f7424ed58621b1f65d5c4d8cbbe8a6ed8
1717
refs/tags/v0.1.1: 7a7f6985fe465e9dd6a075af55493f42b4933be0
1818
refs/tags/v0.1.2: 3eb3fe866ba22487686048f45d927b8c8638ea3f

branches/logging-alpha/gcloud-java-dns/pom.xml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?xml version="1.0"?>
2-
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
35
<modelVersion>4.0.0</modelVersion>
46
<groupId>com.google.gcloud</groupId>
57
<artifactId>gcloud-java-dns</artifactId>
@@ -28,10 +30,10 @@
2830
<version>v1-rev7-1.21.0</version>
2931
<scope>compile</scope>
3032
<exclusions>
31-
<exclusion>
32-
<groupId>com.google.guava</groupId>
33-
<artifactId>guava-jdk5</artifactId>
34-
</exclusion>
33+
<exclusion>
34+
<groupId>com.google.guava</groupId>
35+
<artifactId>guava-jdk5</artifactId>
36+
</exclusion>
3537
<exclusion>
3638
<groupId>com.google.api-client</groupId>
3739
<artifactId>google-api-client</artifactId>

branches/logging-alpha/gcloud-java-dns/src/main/java/com/google/gcloud/dns/DnsRecord.java

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,17 @@
2424
import com.google.common.collect.Lists;
2525

2626
import java.io.Serializable;
27-
2827
import java.util.LinkedList;
2928
import java.util.List;
3029
import java.util.Objects;
3130

3231
/**
33-
* A class that represents Google Cloud DNS record set.
32+
* A class that represents a Google Cloud DNS record set.
3433
*
35-
* <p>A DnsRecord is the unit of data that will be returned by the DNS servers upon a DNS request
36-
* for a specific domain. The DnsRecord holds the current state of the DNS records that make up a
37-
* managed zone. You can read the records but you do not modify them directly. Rather, you edit
38-
* the records in a managed zone by creating a {@link ChangeRequest}.
34+
* <p>A {@code DnsRecord} is the unit of data that will be returned by the DNS servers upon a DNS
35+
* 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 do not modify them directly.
37+
* Rather, you edit the records in a managed zone by creating a ChangeRequest.
3938
*
4039
* @see <a href="https://cloud.google.com/dns/api/v1/resourceRecordSets">Google Cloud DNS
4140
* documentation</a>
@@ -117,8 +116,8 @@ private Builder() {
117116
}
118117

119118
/**
120-
* Creates a builder and pre-populates attributes with the values from the provided DnsRecord
121-
* instance.
119+
* Creates a builder and pre-populates attributes with the values from the provided {@code
120+
* DnsRecord} instance.
122121
*/
123122
private Builder(DnsRecord record) {
124123
this.name = record.name;
@@ -142,15 +141,15 @@ public Builder addRecord(String record) {
142141
/**
143142
* Removes a record from the set. An exact match is required.
144143
*/
145-
public Builder removerRecord(String record) {
144+
public Builder removeRecord(String record) {
146145
this.rrdatas.remove(checkNotNull(record));
147146
return this;
148147
}
149148

150149
/**
151150
* Removes a record on the given index from the set.
152151
*/
153-
public Builder removerRecord(int index) {
152+
public Builder removeRecord(int index) {
154153
checkArgument(index >= 0 && index < this.rrdatas.size(), "The index is out of bounds. An " +
155154
"integer between 0 and " + (this.rrdatas.size() - 1) + " is required. The provided " +
156155
"value was " + index + ".");
@@ -225,10 +224,10 @@ public Builder toBuilder() {
225224
}
226225

227226
/**
228-
* Creates an empty builder.
227+
* Creates a builder for {@code DnsRecord} with mandatorily set name and type of the record.
229228
*/
230-
public static Builder builder() {
231-
return new Builder();
229+
public static Builder builder(String name, DnsRecordType type) {
230+
return new Builder().name(name).type(type);
232231
}
233232

234233
/**
@@ -279,6 +278,17 @@ com.google.api.services.dns.model.ResourceRecordSet toPb() {
279278
return pb;
280279
}
281280

281+
static DnsRecord fromPb(com.google.api.services.dns.model.ResourceRecordSet pb) {
282+
Builder b = builder(pb.getName(), DnsRecordType.valueOf(pb.getType()));
283+
if (pb.getRrdatas() != null) {
284+
b.records(pb.getRrdatas());
285+
}
286+
if (pb.getTtl() != null) {
287+
b.ttl(pb.getTtl());
288+
}
289+
return b.build();
290+
}
291+
282292
@Override
283293
public String toString() {
284294
return MoreObjects.toStringHelper(this)
@@ -288,5 +298,4 @@ public String toString() {
288298
.add("type", type())
289299
.toString();
290300
}
291-
292301
}

branches/logging-alpha/gcloud-java-dns/src/test/java/com/google/gcloud/dns/DnsRecordTest.java

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,13 @@ public class DnsRecordTest {
2727
private static final String NAME = "example.com.";
2828
private static final Integer TTL = 3600;
2929
private static final DnsRecord.DnsRecordType TYPE = DnsRecord.DnsRecordType.AAAA;
30-
private static final DnsRecord record = DnsRecord.builder()
31-
.name(NAME)
30+
private static final DnsRecord record = DnsRecord.builder(NAME, TYPE)
3231
.ttl(TTL)
33-
.type(TYPE)
3432
.build();
3533

3634
@Test
3735
public void testDefaultDnsRecord() {
38-
DnsRecord record = DnsRecord.builder().build();
36+
DnsRecord record = DnsRecord.builder(NAME, TYPE).build();
3937
assertEquals(0, record.records().size());
4038
}
4139

@@ -59,13 +57,13 @@ public void testBuilder() {
5957
@Test
6058
public void testValidTtl() {
6159
try {
62-
DnsRecord.builder().ttl(-1);
60+
DnsRecord.builder(NAME, TYPE).ttl(-1);
6361
fail("A negative value is not acceptable for ttl.");
6462
} catch (IllegalArgumentException e) {
6563
// expected
6664
}
67-
DnsRecord.builder().ttl(0);
68-
DnsRecord.builder().ttl(Integer.MAX_VALUE);
65+
DnsRecord.builder(NAME, TYPE).ttl(0);
66+
DnsRecord.builder(NAME, TYPE).ttl(Integer.MAX_VALUE);
6967
}
7068

7169
@Test
@@ -89,4 +87,26 @@ public void testSameHashCodeOnEquals() {
8987
DnsRecord clone = record.toBuilder().build();
9088
assertEquals(clone.hashCode(), hash);
9189
}
92-
}
90+
91+
@Test
92+
public void testToAndFromPb() {
93+
assertEquals(record, DnsRecord.fromPb(record.toPb()));
94+
DnsRecord partial = DnsRecord.builder(NAME, TYPE).build();
95+
assertEquals(partial, DnsRecord.fromPb(partial.toPb()));
96+
partial = DnsRecord.builder(NAME, TYPE).addRecord("test").build();
97+
assertEquals(partial, DnsRecord.fromPb(partial.toPb()));
98+
partial = DnsRecord.builder(NAME, TYPE).ttl(15).build();
99+
assertEquals(partial, DnsRecord.fromPb(partial.toPb()));
100+
}
101+
102+
@Test
103+
public void testToBuilder() {
104+
assertEquals(record, record.toBuilder().build());
105+
DnsRecord partial = DnsRecord.builder(NAME, TYPE).build();
106+
assertEquals(partial, partial.toBuilder().build());
107+
partial = DnsRecord.builder(NAME, TYPE).addRecord("test").build();
108+
assertEquals(partial, partial.toBuilder().build());
109+
partial = DnsRecord.builder(NAME, TYPE).ttl(15).build();
110+
assertEquals(partial, partial.toBuilder().build());
111+
}
112+
}

branches/logging-alpha/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
<module>gcloud-java-bigquery</module>
7171
<module>gcloud-java-core</module>
7272
<module>gcloud-java-datastore</module>
73+
<module>gcloud-java-dns</module>
7374
<module>gcloud-java-examples</module>
7475
<module>gcloud-java-resourcemanager</module>
7576
<module>gcloud-java-storage</module>

0 commit comments

Comments
 (0)