Skip to content

Commit 96e28d6

Browse files
committed
Merge pull request #784 from mderka/rename-dns-record
Renamed DnsRecord to RecordSet. Fixes #779.
2 parents 2f90e7e + 1a5aade commit 96e28d6

26 files changed

Lines changed: 477 additions & 470 deletions

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -249,13 +249,13 @@ ZoneInfo zoneInfo = ZoneInfo.of(zoneName, domainName, description);
249249
Zone zone = dns.create(zoneInfo);
250250
```
251251
252-
The second snippet shows how to create records inside a zone. The complete code can be found on [CreateOrUpdateDnsRecords.java](./gcloud-java-examples/src/main/java/com/google/gcloud/examples/dns/snippets/CreateOrUpdateDnsRecords.java).
252+
The second snippet shows how to create records inside a zone. The complete code can be found on [CreateOrUpdateRecordSets.java](./gcloud-java-examples/src/main/java/com/google/gcloud/examples/dns/snippets/CreateOrUpdateRecordSets.java).
253253
254254
```java
255255
import com.google.gcloud.dns.ChangeRequest;
256256
import com.google.gcloud.dns.Dns;
257257
import com.google.gcloud.dns.DnsOptions;
258-
import com.google.gcloud.dns.DnsRecord;
258+
import com.google.gcloud.dns.RecordSet;
259259
import com.google.gcloud.dns.Zone;
260260
261261
import java.util.Iterator;
@@ -265,17 +265,17 @@ Dns dns = DnsOptions.defaultInstance().service();
265265
String zoneName = "my-unique-zone";
266266
Zone zone = dns.getZone(zoneName);
267267
String ip = "12.13.14.15";
268-
DnsRecord toCreate = DnsRecord.builder("www.someexampledomain.com.", DnsRecord.Type.A)
268+
RecordSet toCreate = RecordSet.builder("www.someexampledomain.com.", RecordSet.Type.A)
269269
.ttl(24, TimeUnit.HOURS)
270270
.addRecord(ip)
271271
.build();
272272
ChangeRequest.Builder changeBuilder = ChangeRequest.builder().add(toCreate);
273273
274274
// Verify that the record does not exist yet.
275275
// If it does exist, we will overwrite it with our prepared record.
276-
Iterator<DnsRecord> recordIterator = zone.listDnsRecords().iterateAll();
277-
while (recordIterator.hasNext()) {
278-
DnsRecord current = recordIterator.next();
276+
Iterator<RecordSet> recordSetIterator = zone.listRecordSets().iterateAll();
277+
while (recordSetIterator.hasNext()) {
278+
RecordSet current = recordSetIterator.next();
279279
if (toCreate.name().equals(current.name()) &&
280280
toCreate.type().equals(current.type())) {
281281
changeBuilder.delete(current);

gcloud-java-dns/README.md

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -92,15 +92,15 @@ Dns dns = DnsOptions.defaultInstance().service();
9292
For other authentication options, see the [Authentication](https://github.com/GoogleCloudPlatform/gcloud-java#authentication) page.
9393

9494
#### Managing Zones
95-
DNS records in `gcloud-java-dns` are managed inside containers called "zones". `ZoneInfo` is a class
95+
Record sets in `gcloud-java-dns` are managed inside containers called "zones". `ZoneInfo` is a class
9696
which encapsulates metadata that describe a zone in Google Cloud DNS. `Zone`, a subclass of `ZoneInfo`, adds service-related
9797
functionality over `ZoneInfo`.
9898

9999
*Important: Zone names must be unique to the project. If you choose a zone name that already
100100
exists within your project, you'll get a helpful error message telling you to choose another name. In the code below,
101101
replace "my-unique-zone" with a unique zone name. See more about naming rules [here](https://cloud.google.com/dns/api/v1/managedZones#name).*
102102

103-
In this code snippet, we create a new zone to manage DNS records for domain `someexampledomain.com.`
103+
In this code snippet, we create a new zone to manage record sets for domain `someexampledomain.com.`
104104

105105
*Important: The service may require that you verify ownership of the domain for which you are creating a zone.
106106
Hence, we recommend that you do so beforehand. You can verify ownership of
@@ -128,8 +128,8 @@ Zone zone = dns.create(zoneInfo);
128128
System.out.printf("Zone was created and assigned ID %s.%n", zone.id());
129129
```
130130

131-
You now have an empty zone hosted in Google Cloud DNS which is ready to be populated with DNS
132-
records for domain name `someexampledomain.com.` Upon creating the zone, the cloud service
131+
You now have an empty zone hosted in Google Cloud DNS which is ready to be populated with
132+
record sets for domain name `someexampledomain.com.` Upon creating the zone, the cloud service
133133
assigned a set of DNS servers to host records for this zone and
134134
created the required SOA and NS records for the domain. The following snippet prints the list of servers
135135
assigned to the zone created above. First, import
@@ -152,25 +152,25 @@ You can now instruct your domain registrar to [update your domain name servers]
152152
As soon as this happens and the change propagates through cached values in DNS resolvers,
153153
all the DNS queries will be directed to and answered by the Google Cloud DNS service.
154154

155-
#### Creating DNS Records
156-
Now that we have a zone, we can add some DNS records. The DNS records held within zones are
155+
#### Creating Record Sets
156+
Now that we have a zone, we can add some record sets. The record sets held within zones are
157157
modified by "change requests". In this example, we create and apply a change request to
158-
our zone that creates a DNS record of type A and points URL www.someexampledomain.com to
158+
our zone that creates a record set of type A and points URL www.someexampledomain.com to
159159
IP address 12.13.14.15. Start by adding
160160

161161
```java
162162
import com.google.gcloud.dns.ChangeRequest;
163-
import com.google.gcloud.dns.DnsRecord;
163+
import com.google.gcloud.dns.RecordSet;
164164

165165
import java.util.concurrent.TimeUnit;
166166
```
167167

168168
and proceed with:
169169

170170
```java
171-
// Prepare a www.someexampledomain.com. type A record with ttl of 24 hours
171+
// Prepare a www.someexampledomain.com. type A record set with ttl of 24 hours
172172
String ip = "12.13.14.15";
173-
DnsRecord toCreate = DnsRecord.builder("www.someexampledomain.com.", DnsRecord.Type.A)
173+
RecordSet toCreate = RecordSet.builder("www." + zone.dnsName(), RecordSet.Type.A)
174174
.ttl(24, TimeUnit.HOURS)
175175
.addRecord(ip)
176176
.build();
@@ -182,12 +182,12 @@ ChangeRequest changeRequest = ChangeRequest.builder().add(toCreate).build();
182182
changeRequest = zone.applyChangeRequest(changeRequest);
183183
```
184184

185-
The `addRecord` method of `DnsRecord.Builder` accepts records in the form of
186-
strings. The format of the strings depends on the type of the DNS record to be added.
187-
More information on the supported DNS record types and record formats can be found [here](https://cloud.google.com/dns/what-is-cloud-dns#supported_record_types).
185+
The `addRecord` method of `RecordSet.Builder` accepts records in the form of
186+
strings. The format of the strings depends on the type of the record sets to be added.
187+
More information on the supported record set types and record formats can be found [here](https://cloud.google.com/dns/what-is-cloud-dns#supported_record_types).
188188

189-
If you already have a DNS record, Cloud DNS will return an error upon an attempt to create a duplicate of it.
190-
You can modify the code above to create a DNS record or update it if it already exists by making the
189+
If you already have a record set, Cloud DNS will return an error upon an attempt to create a duplicate of it.
190+
You can modify the code above to create a record set or update it if it already exists by making the
191191
following adjustment in your imports
192192

193193
```java
@@ -202,9 +202,9 @@ ChangeRequest.Builder changeBuilder = ChangeRequest.builder().add(toCreate);
202202

203203
// Verify the type A record does not exist yet.
204204
// If it does exist, we will overwrite it with our prepared record.
205-
Iterator<DnsRecord> recordIterator = zone.listDnsRecords().iterateAll();
206-
while (recordIterator.hasNext()) {
207-
DnsRecord current = recordIterator.next();
205+
Iterator<RecordSet> recordSetIterator = zone.listRecordSets().iterateAll();
206+
while (recordSetIterator.hasNext()) {
207+
RecordSet current = recordSetIterator.next();
208208
if (toCreate.name().equals(current.name()) && toCreate.type().equals(current.type())) {
209209
changeBuilder.delete(current);
210210
}
@@ -235,15 +235,15 @@ Change requests are applied atomically to all the assigned DNS servers at once.
235235
happens, it may still take a while for the change to be registered by the DNS cache resolvers.
236236
See more on this topic [here](https://cloud.google.com/dns/monitoring).
237237

238-
#### Listing Zones and DNS Records
239-
Suppose that you have added more zones and DNS records, and now you want to list them.
238+
#### Listing Zones and Record Sets
239+
Suppose that you have added more zones and record sets, and now you want to list them.
240240
First, import the following (unless you have done so in the previous section):
241241

242242
```java
243243
import java.util.Iterator;
244244
```
245245

246-
Then add the following code to list all your zones and DNS records.
246+
Then add the following code to list all your zones and record sets.
247247

248248
```java
249249
// List all your zones
@@ -254,11 +254,11 @@ while (zoneIterator.hasNext()) {
254254
counter++;
255255
}
256256

257-
// List the DNS records in a particular zone
258-
Iterator<DnsRecord> recordIterator = zone.listDnsRecords().iterateAll();
259-
System.out.println(String.format("DNS records inside %s:", zone.name()));
260-
while (recordIterator.hasNext()) {
261-
System.out.println(recordIterator.next());
257+
// List the record sets in a particular zone
258+
recordSetIterator = zone.listRecordSets().iterateAll();
259+
System.out.println(String.format("Record sets inside %s:", zone.name()));
260+
while (recordSetIterator.hasNext()) {
261+
System.out.println(recordSetIterator.next());
262262
}
263263
```
264264

@@ -276,15 +276,15 @@ while (changeIterator.hasNext()) {
276276
#### Deleting Zones
277277

278278
If you no longer want to host a zone in Cloud DNS, you can delete it.
279-
First, you need to empty the zone by deleting all its records except for the default SOA and NS records.
279+
First, you need to empty the zone by deleting all its records except for the default SOA and NS record sets.
280280

281281
```java
282-
// Make a change for deleting the records
283-
ChangeRequest.Builder changeBuilder = ChangeRequest.builder();
282+
// Make a change for deleting the record sets
283+
changeBuilder = ChangeRequest.builder();
284284
while (recordIterator.hasNext()) {
285-
DnsRecord current = recordIterator.next();
285+
RecordSet current = recordIterator.next();
286286
// SOA and NS records cannot be deleted
287-
if (!DnsRecord.Type.SOA.equals(current.type()) && !DnsRecord.Type.NS.equals(current.type())) {
287+
if (!RecordSet.Type.SOA.equals(current.type()) && !RecordSet.Type.NS.equals(current.type())) {
288288
changeBuilder.delete(current);
289289
}
290290
}
@@ -324,11 +324,11 @@ if (result) {
324324

325325
We composed some of the aforementioned snippets into complete executable code samples. In
326326
[CreateZones.java](../gcloud-java-examples/src/main/java/com/google/gcloud/examples/dns/snippets/CreateZone.java)
327-
we create a zone. In [CreateOrUpdateDnsRecords.java](../gcloud-java-examples/src/main/java/com/google/gcloud/examples/dns/snippets/CreateOrUpdateDnsRecords.java)
328-
we create a type A record for a zone, or update an existing type A record to a new IP address. We
327+
we create a zone. In [CreateOrUpdateRecordSets.java](../gcloud-java-examples/src/main/java/com/google/gcloud/examples/dns/snippets/CreateOrUpdateRecordSets.java)
328+
we create a type A record set for a zone, or update an existing type A record set to a new IP address. We
329329
demonstrate how to delete a zone in [DeleteZone.java](../gcloud-java-examples/src/main/java/com/google/gcloud/examples/dns/snippets/DeleteZone.java).
330-
Finally, in [ManipulateZonesAndRecords.java](../gcloud-java-examples/src/main/java/com/google/gcloud/examples/dns/snippets/ManipulateZonesAndRecords.java)
331-
we assemble all the code snippets together and create zone, create or update a DNS record, list zones, list DNS records, list changes, and
330+
Finally, in [ManipulateZonesAndRecordSets.java](../gcloud-java-examples/src/main/java/com/google/gcloud/examples/dns/snippets/ManipulateZonesAndRecordSets.java)
331+
we assemble all the code snippets together and create zone, create or update a record set, list zones, list record sets, list changes, and
332332
delete a zone. The applications assume that they are running on Compute Engine or from your own desktop. To run any of these examples on App
333333
Engine, simply move the code from the main method to your application's servlet class and change the
334334
print statements to display on your webpage.

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

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
import java.util.Objects;
3434

3535
/**
36-
* A class representing an atomic update to a collection of {@link DnsRecord}s within a {@code
36+
* A class representing an atomic update to a collection of {@link RecordSet}s within a {@code
3737
* Zone}.
3838
*
3939
* @see <a href="https://cloud.google.com/dns/api/v1/changes">Google Cloud DNS documentation</a>
@@ -48,8 +48,8 @@ public ChangeRequest apply(com.google.api.services.dns.model.Change pb) {
4848
}
4949
};
5050
private static final long serialVersionUID = -9027378042756366333L;
51-
private final List<DnsRecord> additions;
52-
private final List<DnsRecord> deletions;
51+
private final List<RecordSet> additions;
52+
private final List<RecordSet> deletions;
5353
private final String id;
5454
private final Long startTimeMillis;
5555
private final Status status;
@@ -70,8 +70,8 @@ public enum Status {
7070
*/
7171
public static class Builder {
7272

73-
private List<DnsRecord> additions = new LinkedList<>();
74-
private List<DnsRecord> deletions = new LinkedList<>();
73+
private List<RecordSet> additions = new LinkedList<>();
74+
private List<RecordSet> deletions = new LinkedList<>();
7575
private String id;
7676
private Long startTimeMillis;
7777
private Status status;
@@ -88,43 +88,43 @@ private Builder() {
8888
}
8989

9090
/**
91-
* Sets a collection of {@link DnsRecord}s which are to be added to the zone upon executing this
91+
* Sets a collection of {@link RecordSet}s which are to be added to the zone upon executing this
9292
* {@code ChangeRequest}.
9393
*/
94-
public Builder additions(List<DnsRecord> additions) {
94+
public Builder additions(List<RecordSet> additions) {
9595
this.additions = Lists.newLinkedList(checkNotNull(additions));
9696
return this;
9797
}
9898

9999
/**
100-
* Sets a collection of {@link DnsRecord}s which are to be deleted from the zone upon executing
100+
* Sets a collection of {@link RecordSet}s which are to be deleted from the zone upon executing
101101
* this {@code ChangeRequest}.
102102
*/
103-
public Builder deletions(List<DnsRecord> deletions) {
103+
public Builder deletions(List<RecordSet> deletions) {
104104
this.deletions = Lists.newLinkedList(checkNotNull(deletions));
105105
return this;
106106
}
107107

108108
/**
109-
* Adds a {@link DnsRecord} to be <strong>added</strong> to the zone upon executing this {@code
109+
* Adds a {@link RecordSet} to be <strong>added</strong> to the zone upon executing this {@code
110110
* ChangeRequest}.
111111
*/
112-
public Builder add(DnsRecord record) {
113-
this.additions.add(checkNotNull(record));
112+
public Builder add(RecordSet recordSet) {
113+
this.additions.add(checkNotNull(recordSet));
114114
return this;
115115
}
116116

117117
/**
118-
* Adds a {@link DnsRecord} to be <strong>deleted</strong> to the zone upon executing this
118+
* Adds a {@link RecordSet} to be <strong>deleted</strong> to the zone upon executing this
119119
* {@code ChangeRequest}.
120120
*/
121-
public Builder delete(DnsRecord record) {
122-
this.deletions.add(checkNotNull(record));
121+
public Builder delete(RecordSet recordSet) {
122+
this.deletions.add(checkNotNull(recordSet));
123123
return this;
124124
}
125125

126126
/**
127-
* Clears the collection of {@link DnsRecord}s which are to be added to the zone upon executing
127+
* Clears the collection of {@link RecordSet}s which are to be added to the zone upon executing
128128
* this {@code ChangeRequest}.
129129
*/
130130
public Builder clearAdditions() {
@@ -133,7 +133,7 @@ public Builder clearAdditions() {
133133
}
134134

135135
/**
136-
* Clears the collection of {@link DnsRecord}s which are to be deleted from the zone upon
136+
* Clears the collection of {@link RecordSet}s which are to be deleted from the zone upon
137137
* executing this {@code ChangeRequest}.
138138
*/
139139
public Builder clearDeletions() {
@@ -142,20 +142,20 @@ public Builder clearDeletions() {
142142
}
143143

144144
/**
145-
* Removes a single {@link DnsRecord} from the collection of records to be
145+
* Removes a single {@link RecordSet} from the collection of records to be
146146
* <strong>added</strong> to the zone upon executing this {@code ChangeRequest}.
147147
*/
148-
public Builder removeAddition(DnsRecord record) {
149-
this.additions.remove(record);
148+
public Builder removeAddition(RecordSet recordSet) {
149+
this.additions.remove(recordSet);
150150
return this;
151151
}
152152

153153
/**
154-
* Removes a single {@link DnsRecord} from the collection of records to be
154+
* Removes a single {@link RecordSet} from the collection of records to be
155155
* <strong>deleted</strong> from the zone upon executing this {@code ChangeRequest}.
156156
*/
157-
public Builder removeDeletion(DnsRecord record) {
158-
this.deletions.remove(record);
157+
public Builder removeDeletion(RecordSet recordSet) {
158+
this.deletions.remove(recordSet);
159159
return this;
160160
}
161161

@@ -215,18 +215,18 @@ public Builder toBuilder() {
215215
}
216216

217217
/**
218-
* Returns the list of {@link DnsRecord}s to be added to the zone upon submitting this {@code
218+
* Returns the list of {@link RecordSet}s to be added to the zone upon submitting this {@code
219219
* ChangeRequest}.
220220
*/
221-
public List<DnsRecord> additions() {
221+
public List<RecordSet> additions() {
222222
return additions;
223223
}
224224

225225
/**
226-
* Returns the list of {@link DnsRecord}s to be deleted from the zone upon submitting this {@code
226+
* Returns the list of {@link RecordSet}s to be deleted from the zone upon submitting this {@code
227227
* ChangeRequest}.
228228
*/
229-
public List<DnsRecord> deletions() {
229+
public List<RecordSet> deletions() {
230230
return deletions;
231231
}
232232

@@ -267,9 +267,9 @@ com.google.api.services.dns.model.Change toPb() {
267267
pb.setStatus(status().name().toLowerCase());
268268
}
269269
// set a list of additions
270-
pb.setAdditions(Lists.transform(additions(), DnsRecord.TO_PB_FUNCTION));
270+
pb.setAdditions(Lists.transform(additions(), RecordSet.TO_PB_FUNCTION));
271271
// set a list of deletions
272-
pb.setDeletions(Lists.transform(deletions(), DnsRecord.TO_PB_FUNCTION));
272+
pb.setDeletions(Lists.transform(deletions(), RecordSet.TO_PB_FUNCTION));
273273
return pb;
274274
}
275275

@@ -286,10 +286,10 @@ static ChangeRequest fromPb(com.google.api.services.dns.model.Change pb) {
286286
builder.status(ChangeRequest.Status.valueOf(pb.getStatus().toUpperCase()));
287287
}
288288
if (pb.getDeletions() != null) {
289-
builder.deletions(Lists.transform(pb.getDeletions(), DnsRecord.FROM_PB_FUNCTION));
289+
builder.deletions(Lists.transform(pb.getDeletions(), RecordSet.FROM_PB_FUNCTION));
290290
}
291291
if (pb.getAdditions() != null) {
292-
builder.additions(Lists.transform(pb.getAdditions(), DnsRecord.FROM_PB_FUNCTION));
292+
builder.additions(Lists.transform(pb.getAdditions(), RecordSet.FROM_PB_FUNCTION));
293293
}
294294
return builder.build();
295295
}

0 commit comments

Comments
 (0)