Skip to content

Commit

Permalink
Update Dns examples, snippets and READMEs to use renamed getters/sett…
Browse files Browse the repository at this point in the history
…ers/builders
  • Loading branch information
mziccard committed Oct 17, 2016
1 parent 5fdde09 commit 8c7b19f
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 69 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -359,19 +359,19 @@ Dns dns = DnsOptions.defaultInstance().service();
String zoneName = "my-unique-zone";
Zone zone = dns.getZone(zoneName);
String ip = "12.13.14.15";
RecordSet toCreate = RecordSet.builder("www.someexampledomain.com.", RecordSet.Type.A)
.ttl(24, TimeUnit.HOURS)
RecordSet toCreate = RecordSet.newBuilder("www.someexampledomain.com.", RecordSet.Type.A)
.setTtl(24, TimeUnit.HOURS)
.addRecord(ip)
.build();
ChangeRequestInfo.Builder changeBuilder = ChangeRequestInfo.builder().add(toCreate);
ChangeRequestInfo.Builder changeBuilder = ChangeRequestInfo.newBuilder().add(toCreate);
// Verify that the record does not exist yet.
// If it does exist, we will overwrite it with our prepared record.
Iterator<RecordSet> recordSetIterator = zone.listRecordSets().iterateAll();
while (recordSetIterator.hasNext()) {
RecordSet current = recordSetIterator.next();
if (toCreate.name().equals(current.name()) &&
toCreate.type().equals(current.type())) {
if (toCreate.name().equals(current.getName()) &&
toCreate.type().equals(current.getType())) {
changeBuilder.delete(current);
}
}
Expand Down
5 changes: 3 additions & 2 deletions TESTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,11 @@ You can test against an in-memory local DNS by following these steps:
The `delay` parameter determines if change requests should be processed synchronously
(value `0`) or in a separate thread with a minimum of delay of `delay` milliseconds.
2. In your program, create the DNS service by using the helper's `options()` method. For example:
2. In your program, create the DNS service by using the helper's `getOptions()` method.
For example:

```java
Dns dns = LocalDnsHelper.options().service();
Dns dns = LocalDnsHelper.getOptions().service();
```

3. Run your tests.
Expand Down
26 changes: 14 additions & 12 deletions google-cloud-dns/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ ZoneInfo zoneInfo = ZoneInfo.of(zoneName, domainName, description);

// Create zone in Google Cloud DNS
Zone zone = dns.create(zoneInfo);
System.out.printf("Zone was created and assigned ID %s.%n", zone.generatedId());
System.out.printf("Zone was created and assigned ID %s.%n", zone.getGeneratedId());
```

You now have an empty zone hosted in Google Cloud DNS which is ready to be populated with
Expand All @@ -142,7 +142,7 @@ and then add

```java
// Print assigned name servers
List<String> nameServers = zone.nameServers();
List<String> nameServers = zone.getNameServers();
for(String nameServer : nameServers) {
System.out.println(nameServer);
}
Expand Down Expand Up @@ -170,13 +170,13 @@ and proceed with:
```java
// Prepare a www.someexampledomain.com. type A record set with ttl of 24 hours
String ip = "12.13.14.15";
RecordSet toCreate = RecordSet.builder("www." + zone.dnsName(), RecordSet.Type.A)
.ttl(24, TimeUnit.HOURS)
RecordSet toCreate = RecordSet.newBuilder("www." + zone.dnsName(), RecordSet.Type.A)
.setTtl(24, TimeUnit.HOURS)
.addRecord(ip)
.build();

// Make a change
ChangeRequestInfo changeRequest = ChangeRequestInfo.builder().add(toCreate).build();
ChangeRequestInfo changeRequest = ChangeRequestInfo.newBuilder().add(toCreate).build();

// Build and apply the change request to our zone
changeRequest = zone.applyChangeRequest(changeRequest);
Expand Down Expand Up @@ -205,7 +205,8 @@ ChangeRequestInfo.Builder changeBuilder = ChangeRequestInfo.builder().add(toCrea
Iterator<RecordSet> recordSetIterator = zone.listRecordSets().iterateAll();
while (recordSetIterator.hasNext()) {
RecordSet current = recordSetIterator.next();
if (toCreate.name().equals(current.name()) && toCreate.type().equals(current.type())) {
if (toCreate.getName().equals(current.getName())
&& toCreate.getType().equals(current.getType())) {
changeBuilder.delete(current);
}
}
Expand Down Expand Up @@ -255,7 +256,7 @@ while (zoneIterator.hasNext()) {

// List the record sets in a particular zone
recordSetIterator = zone.listRecordSets().iterateAll();
System.out.println(String.format("Record sets inside %s:", zone.name()));
System.out.println(String.format("Record sets inside %s:", zone.getName()));
while (recordSetIterator.hasNext()) {
System.out.println(recordSetIterator.next());
}
Expand All @@ -274,7 +275,7 @@ and then:

// List the change requests applied to a particular zone
Iterator<ChangeRequest> changeIterator = zone.listChangeRequests().iterateAll();
System.out.println(String.format("The history of changes in %s:", zone.name()));
System.out.println(String.format("The history of changes in %s:", zone.getName()));
while (changeIterator.hasNext()) {
System.out.println(changeIterator.next());
}
Expand All @@ -287,18 +288,19 @@ First, you need to empty the zone by deleting all its records except for the def

```java
// Make a change for deleting the record sets
changeBuilder = ChangeRequestInfo.builder();
changeBuilder = ChangeRequestInfo.newBuilder();
while (recordIterator.hasNext()) {
RecordSet current = recordIterator.next();
// SOA and NS records cannot be deleted
if (!RecordSet.Type.SOA.equals(current.type()) && !RecordSet.Type.NS.equals(current.type())) {
if (!RecordSet.Type.SOA.equals(current.getType())
&& !RecordSet.Type.NS.equals(current.getType())) {
changeBuilder.delete(current);
}
}

// Build and apply the change request to our zone if it contains records to delete
ChangeRequestInfo changeRequest = changeBuilder.build();
if (!changeRequest.deletions().isEmpty()) {
if (!changeRequest.getDeletions().isEmpty()) {
ChangeRequest pendingRequest = dns.applyChangeRequest(zoneName, changeRequest);

// Wait for the change request to complete
Expand All @@ -325,7 +327,7 @@ if (result) {
#### Complete Source Code

We composed some of the aforementioned snippets into complete executable code samples. In
[CreateZones.java](../google-cloud-examples/src/main/java/com/google/cloud/examples/dns/snippets/CreateZone.java)
[CreateZone.java](../google-cloud-examples/src/main/java/com/google/cloud/examples/dns/snippets/CreateZone.java)
we create a zone. In [CreateOrUpdateRecordSets.java](../google-cloud-examples/src/main/java/com/google/cloud/examples/dns/snippets/CreateOrUpdateRecordSets.java)
we create a type A record set for a zone, or update an existing type A record set to a new IP address. We
demonstrate how to delete a zone in [DeleteZone.java](../google-cloud-examples/src/main/java/com/google/cloud/examples/dns/snippets/DeleteZone.java).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public void run(Dns dns, String... args) {
ZoneInfo zoneInfo = ZoneInfo.of(zoneName, dnsName, description);
Zone zone = dns.create(zoneInfo);
System.out.printf("Successfully created zone with name %s which was assigned ID %s.%n",
zone.name(), zone.generatedId());
zone.getName(), zone.getGeneratedId());
}

@Override
Expand Down Expand Up @@ -201,16 +201,17 @@ public void run(Dns dns, String... args) {
if (args.length > 3) {
ttl = Integer.parseInt(args[3]);
}
RecordSet recordSet = RecordSet.builder(recordName, RecordSet.Type.A)
.records(ImmutableList.of(ip))
.ttl(ttl, TimeUnit.SECONDS)
RecordSet recordSet = RecordSet.newBuilder(recordName, RecordSet.Type.A)
.setRecords(ImmutableList.of(ip))
.setTtl(ttl, TimeUnit.SECONDS)
.build();
ChangeRequestInfo changeRequest = ChangeRequest.builder()
ChangeRequestInfo changeRequest = ChangeRequest.newBuilder()
.delete(recordSet)
.build();
changeRequest = dns.applyChangeRequest(zoneName, changeRequest);
System.out.printf("The request for deleting A record %s for zone %s was successfully "
+ "submitted and assigned ID %s.%n", recordName, zoneName, changeRequest.generatedId());
+ "submitted and assigned ID %s.%n", recordName, zoneName,
changeRequest.getGeneratedId());
System.out.print("Waiting for deletion to happen...");
waitForChangeToFinish(dns, zoneName, changeRequest);
System.out.printf("%nThe deletion has been completed.%n");
Expand Down Expand Up @@ -248,14 +249,15 @@ public void run(Dns dns, String... args) {
if (args.length > 3) {
ttl = Integer.parseInt(args[3]);
}
RecordSet recordSet = RecordSet.builder(recordName, RecordSet.Type.A)
.records(ImmutableList.of(ip))
.ttl(ttl, TimeUnit.SECONDS)
RecordSet recordSet = RecordSet.newBuilder(recordName, RecordSet.Type.A)
.setRecords(ImmutableList.of(ip))
.setTtl(ttl, TimeUnit.SECONDS)
.build();
ChangeRequestInfo changeRequest = ChangeRequest.builder().add(recordSet).build();
ChangeRequestInfo changeRequest = ChangeRequest.newBuilder().add(recordSet).build();
changeRequest = dns.applyChangeRequest(zoneName, changeRequest);
System.out.printf("The request for adding A record %s for zone %s was successfully "
+ "submitted and assigned ID %s.%n", recordName, zoneName, changeRequest.generatedId());
+ "submitted and assigned ID %s.%n", recordName, zoneName,
changeRequest.getGeneratedId());
System.out.print("Waiting for addition to happen...");
waitForChangeToFinish(dns, zoneName, changeRequest);
System.out.printf("The addition has been completed.%n");
Expand Down Expand Up @@ -291,8 +293,8 @@ public void run(Dns dns, String... args) {
System.out.printf("Record sets for zone %s:%n", zoneName);
while (iterator.hasNext()) {
RecordSet recordSet = iterator.next();
System.out.printf("%nRecord name: %s%nTTL: %s%nRecords: %s%n", recordSet.name(),
recordSet.ttl(), Joiner.on(", ").join(recordSet.records()));
System.out.printf("%nRecord name: %s%nTTL: %s%nRecords: %s%n", recordSet.getName(),
recordSet.getTtl(), Joiner.on(", ").join(recordSet.getRecords()));
}
} else {
System.out.printf("Zone %s has no record sets records.%n", zoneName);
Expand Down Expand Up @@ -331,11 +333,11 @@ public void run(Dns dns, String... args) {
System.out.printf("Change requests for zone %s:%n", zoneName);
while (iterator.hasNext()) {
ChangeRequest change = iterator.next();
System.out.printf("%nID: %s%n", change.generatedId());
System.out.printf("%nID: %s%n", change.getGeneratedId());
System.out.printf("Status: %s%n", change.status());
System.out.printf("Started: %s%n", FORMATTER.print(change.startTimeMillis()));
System.out.printf("Deletions: %s%n", Joiner.on(", ").join(change.deletions()));
System.out.printf("Additions: %s%n", Joiner.on(", ").join(change.additions()));
System.out.printf("Started: %s%n", FORMATTER.print(change.getStartTimeMillis()));
System.out.printf("Deletions: %s%n", Joiner.on(", ").join(change.getDeletions()));
System.out.printf("Additions: %s%n", Joiner.on(", ").join(change.getAdditions()));
}
} else {
System.out.printf("Zone %s has no change requests.%n", zoneName);
Expand Down Expand Up @@ -401,16 +403,16 @@ private static class GetProjectAction implements DnsAction {
@Override
public void run(Dns dns, String... args) {
ProjectInfo project = dns.getProject();
ProjectInfo.Quota quota = project.quota();
ProjectInfo.Quota quota = project.getQuota();
System.out.printf("Project id: %s%nQuota:%n", dns.options().projectId());
System.out.printf("\tZones: %d%n", quota.zones());
System.out.printf("\tRecord sets per zone: %d%n", quota.rrsetsPerZone());
System.out.printf("\tZones: %d%n", quota.getZones());
System.out.printf("\tRecord sets per zone: %d%n", quota.getRrsetsPerZone());
System.out.printf("\tRecord sets per DNS record: %d%n",
quota.resourceRecordsPerRrset());
System.out.printf("\tAdditions per change: %d%n", quota.rrsetAdditionsPerChange());
System.out.printf("\tDeletions per change: %d%n", quota.rrsetDeletionsPerChange());
quota.getResourceRecordsPerRrset());
System.out.printf("\tAdditions per change: %d%n", quota.getRrsetAdditionsPerChange());
System.out.printf("\tDeletions per change: %d%n", quota.getRrsetDeletionsPerChange());
System.out.printf("\tTotal data size per change: %d%n",
quota.totalRrdataSizePerChange());
quota.getTotalRrdataSizePerChange());
}

@Override
Expand All @@ -435,11 +437,11 @@ public boolean check(String... args) {
}

private static void printZone(Zone zone) {
System.out.printf("%nName: %s%n", zone.name());
System.out.printf("ID: %s%n", zone.generatedId());
System.out.printf("Description: %s%n", zone.description());
System.out.printf("Created: %s%n", FORMATTER.print(zone.creationTimeMillis()));
System.out.printf("Name servers: %s%n", Joiner.on(", ").join(zone.nameServers()));
System.out.printf("%nName: %s%n", zone.getName());
System.out.printf("ID: %s%n", zone.getGeneratedId());
System.out.printf("Description: %s%n", zone.getDescription());
System.out.printf("Created: %s%n", FORMATTER.print(zone.getCreationTimeMillis()));
System.out.printf("Name servers: %s%n", Joiner.on(", ").join(zone.getNameServers()));
}

private static ChangeRequestInfo waitForChangeToFinish(Dns dns, String zoneName,
Expand All @@ -452,7 +454,7 @@ private static ChangeRequestInfo waitForChangeToFinish(Dns dns, String zoneName,
} catch (InterruptedException e) {
System.err.println("Thread was interrupted while waiting.");
}
current = dns.getChangeRequest(zoneName, current.generatedId());
current = dns.getChangeRequest(zoneName, current.getGeneratedId());
}
return current;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,21 @@ public static void main(String... args) {

// Prepare a <i>www.<zone-domain>.</i> type A record set with ttl of 24 hours
String ip = "12.13.14.15";
RecordSet toCreate = RecordSet.builder("www." + zone.dnsName(), RecordSet.Type.A)
.ttl(24, TimeUnit.HOURS)
RecordSet toCreate = RecordSet.newBuilder("www." + zone.getDnsName(), RecordSet.Type.A)
.setTtl(24, TimeUnit.HOURS)
.addRecord(ip)
.build();

// Make a change
ChangeRequestInfo.Builder changeBuilder = ChangeRequestInfo.builder().add(toCreate);
ChangeRequestInfo.Builder changeBuilder = ChangeRequestInfo.newBuilder().add(toCreate);

// Verify a www.<zone-domain>. type A record does not exist yet.
// If it does exist, we will overwrite it with our prepared record.
Iterator<RecordSet> recordSetIterator = zone.listRecordSets().iterateAll();
while (recordSetIterator.hasNext()) {
RecordSet current = recordSetIterator.next();
if (toCreate.name().equals(current.name()) && toCreate.type().equals(current.type())) {
if (toCreate.getName().equals(current.getName())
&& toCreate.getType().equals(current.getType())) {
changeBuilder.delete(current);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,6 @@ public static void main(String... args) {

// Create zone in Google Cloud DNS
Zone zone = dns.create(zoneInfo);
System.out.printf("Zone was created and assigned ID %s.%n", zone.generatedId());
System.out.printf("Zone was created and assigned ID %s.%n", zone.getGeneratedId());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,19 @@ public static void main(String... args) {
Iterator<RecordSet> recordIterator = dns.listRecordSets(zoneName).iterateAll();

// Make a change for deleting the records
ChangeRequestInfo.Builder changeBuilder = ChangeRequestInfo.builder();
ChangeRequestInfo.Builder changeBuilder = ChangeRequestInfo.newBuilder();
while (recordIterator.hasNext()) {
RecordSet current = recordIterator.next();
// SOA and NS records cannot be deleted
if (!RecordSet.Type.SOA.equals(current.type()) && !RecordSet.Type.NS.equals(current.type())) {
if (!RecordSet.Type.SOA.equals(current.getType())
&& !RecordSet.Type.NS.equals(current.getType())) {
changeBuilder.delete(current);
}
}

// Build and apply the change request to our zone if it contains records to delete
ChangeRequestInfo changeRequest = changeBuilder.build();
if (!changeRequest.deletions().isEmpty()) {
if (!changeRequest.getDeletions().isEmpty()) {
ChangeRequest pendingRequest = dns.applyChangeRequest(zoneName, changeRequest);

// Wait for the change request to complete
Expand Down
Loading

0 comments on commit 8c7b19f

Please sign in to comment.