Skip to content

Commit

Permalink
Did more DnsRecord renames. Fixed build problem.
Browse files Browse the repository at this point in the history
  • Loading branch information
mderka committed Mar 24, 2016
1 parent bc51bd1 commit 43e7b53
Show file tree
Hide file tree
Showing 9 changed files with 100 additions and 102 deletions.
2 changes: 1 addition & 1 deletion gcloud-java-dns/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ ChangeRequest changeRequest = ChangeRequest.builder().add(toCreate).build();
changeRequest = zone.applyChangeRequest(changeRequest);
```

The `addRecord` method of `RecordSet.Builder` accepts record sets in the form of
The `addRecord` method of `RecordSet.Builder` accepts records in the form of
strings. The format of the strings depends on the type of the record sets to be added.
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).

Expand Down
10 changes: 5 additions & 5 deletions gcloud-java-dns/src/main/java/com/google/gcloud/dns/DnsImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ private static class DnsRecordPageFetcher implements PageImpl.NextPageFetcher<Re

@Override
public Page<RecordSet> nextPage() {
return listDnsRecords(zoneName, serviceOptions, requestOptions);
return listRecordSets(zoneName, serviceOptions, requestOptions);
}
}

Expand Down Expand Up @@ -179,10 +179,10 @@ public DnsRpc.ListResult<Change> call() {

@Override
public Page<RecordSet> listRecordSets(String zoneName, RecordSetListOption... options) {
return listDnsRecords(zoneName, options(), optionMap(options));
return listRecordSets(zoneName, options(), optionMap(options));
}

private static Page<RecordSet> listDnsRecords(final String zoneName,
private static Page<RecordSet> listRecordSets(final String zoneName,
final DnsOptions serviceOptions, final Map<DnsRpc.Option, ?> optionsMap) {
try {
// get a list of record sets
Expand All @@ -196,11 +196,11 @@ public DnsRpc.ListResult<ResourceRecordSet> call() {
}, serviceOptions.retryParams(), EXCEPTION_HANDLER);
String cursor = result.pageToken();
// transform that list into record sets
Iterable<RecordSet> records = result.results() == null
Iterable<RecordSet> recordSets = result.results() == null
? ImmutableList.<RecordSet>of()
: Iterables.transform(result.results(), RecordSet.FROM_PB_FUNCTION);
return new PageImpl<>(new DnsRecordPageFetcher(zoneName, serviceOptions, cursor, optionsMap),
cursor, records);
cursor, recordSets);
} catch (RetryHelperException e) {
throw DnsException.translateAndThrow(e);
}
Expand Down
22 changes: 10 additions & 12 deletions gcloud-java-dns/src/main/java/com/google/gcloud/dns/RecordSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;

import com.google.api.services.dns.model.ResourceRecordSet;
import com.google.common.base.Function;
import com.google.common.base.MoreObjects;
import com.google.common.collect.ImmutableList;
Expand All @@ -44,20 +45,18 @@
*/
public class RecordSet implements Serializable {

static final Function<com.google.api.services.dns.model.ResourceRecordSet, RecordSet>
FROM_PB_FUNCTION =
new Function<com.google.api.services.dns.model.ResourceRecordSet, RecordSet>() {
static final Function<ResourceRecordSet, RecordSet> FROM_PB_FUNCTION =
new Function<ResourceRecordSet, RecordSet>() {
@Override
public RecordSet apply(com.google.api.services.dns.model.ResourceRecordSet pb) {
public RecordSet apply(ResourceRecordSet pb) {
return RecordSet.fromPb(pb);
}
};
static final Function<RecordSet, com.google.api.services.dns.model.ResourceRecordSet>
TO_PB_FUNCTION =
new Function<RecordSet, com.google.api.services.dns.model.ResourceRecordSet>() {
static final Function<RecordSet, ResourceRecordSet> TO_PB_FUNCTION =
new Function<RecordSet, ResourceRecordSet>() {
@Override
public com.google.api.services.dns.model.ResourceRecordSet apply(RecordSet error) {
return error.toPb();
public ResourceRecordSet apply(RecordSet recordSet) {
return recordSet.toPb();
}
};
private static final long serialVersionUID = 8148009870800115261L;
Expand Down Expand Up @@ -187,7 +186,7 @@ public Builder records(List<String> records) {
}

/**
* Sets name for this record set. For example, www.example.com.
* Sets the name for this record set. For example, www.example.com.
*/
public Builder name(String name) {
this.name = checkNotNull(name);
Expand Down Expand Up @@ -283,8 +282,7 @@ public int hashCode() {

@Override
public boolean equals(Object obj) {
return obj instanceof RecordSet
&& Objects.equals(this.toPb(), ((RecordSet) obj).toPb());
return obj instanceof RecordSet && Objects.equals(this.toPb(), ((RecordSet) obj).toPb());
}

com.google.api.services.dns.model.ResourceRecordSet toPb() {
Expand Down
38 changes: 19 additions & 19 deletions gcloud-java-dns/src/test/java/com/google/gcloud/dns/DnsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,35 +30,35 @@ public class DnsTest {
private static final String DNS_NAME = "www.example.com.";

@Test
public void testDnsRecordListOption() {
public void testRecordSetListOption() {
// dns name
String dnsName = "some name";
Dns.RecordSetListOption rrsetListOption = Dns.RecordSetListOption.dnsName(dnsName);
assertEquals(dnsName, rrsetListOption.value());
assertEquals(DnsRpc.Option.NAME, rrsetListOption.rpcOption());
Dns.RecordSetListOption recordSetListOption = Dns.RecordSetListOption.dnsName(dnsName);
assertEquals(dnsName, recordSetListOption.value());
assertEquals(DnsRpc.Option.NAME, recordSetListOption.rpcOption());
// page token
rrsetListOption = Dns.RecordSetListOption.pageToken(PAGE_TOKEN);
assertEquals(PAGE_TOKEN, rrsetListOption.value());
assertEquals(DnsRpc.Option.PAGE_TOKEN, rrsetListOption.rpcOption());
recordSetListOption = Dns.RecordSetListOption.pageToken(PAGE_TOKEN);
assertEquals(PAGE_TOKEN, recordSetListOption.value());
assertEquals(DnsRpc.Option.PAGE_TOKEN, recordSetListOption.rpcOption());
// page size
rrsetListOption = Dns.RecordSetListOption.pageSize(PAGE_SIZE);
assertEquals(PAGE_SIZE, rrsetListOption.value());
assertEquals(DnsRpc.Option.PAGE_SIZE, rrsetListOption.rpcOption());
recordSetListOption = Dns.RecordSetListOption.pageSize(PAGE_SIZE);
assertEquals(PAGE_SIZE, recordSetListOption.value());
assertEquals(DnsRpc.Option.PAGE_SIZE, recordSetListOption.rpcOption());
// record type
RecordSet.Type recordType = RecordSet.Type.AAAA;
rrsetListOption = Dns.RecordSetListOption.type(recordType);
assertEquals(recordType.name(), rrsetListOption.value());
assertEquals(DnsRpc.Option.DNS_TYPE, rrsetListOption.rpcOption());
recordSetListOption = Dns.RecordSetListOption.type(recordType);
assertEquals(recordType.name(), recordSetListOption.value());
assertEquals(DnsRpc.Option.DNS_TYPE, recordSetListOption.rpcOption());
// fields
rrsetListOption = Dns.RecordSetListOption.fields(Dns.RecordSetField.NAME,
recordSetListOption = Dns.RecordSetListOption.fields(Dns.RecordSetField.NAME,
Dns.RecordSetField.TTL);
assertEquals(DnsRpc.Option.FIELDS, rrsetListOption.rpcOption());
assertTrue(rrsetListOption.value() instanceof String);
assertTrue(((String) rrsetListOption.value()).contains(
assertEquals(DnsRpc.Option.FIELDS, recordSetListOption.rpcOption());
assertTrue(recordSetListOption.value() instanceof String);
assertTrue(((String) recordSetListOption.value()).contains(
Dns.RecordSetField.NAME.selector()));
assertTrue(((String) rrsetListOption.value()).contains(
assertTrue(((String) recordSetListOption.value()).contains(
Dns.RecordSetField.TTL.selector()));
assertTrue(((String) rrsetListOption.value()).contains(
assertTrue(((String) recordSetListOption.value()).contains(
Dns.RecordSetField.NAME.selector()));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ public class RecordSetTest {

@Test
public void testDefaultDnsRecord() {
RecordSet record = builder(NAME, TYPE).build();
assertEquals(0, record.records().size());
assertEquals(TYPE, record.type());
assertEquals(NAME, record.name());
RecordSet recordSet = builder(NAME, TYPE).build();
assertEquals(0, recordSet.records().size());
assertEquals(TYPE, recordSet.type());
assertEquals(NAME, recordSet.name());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class SerializationTest extends BaseSerializationTest {
.build();
private static final Dns.ZoneListOption ZONE_LIST_OPTION =
Dns.ZoneListOption.dnsName("www.example.com.");
private static final Dns.RecordSetListOption DNS_REOCRD_LIST_OPTION =
private static final Dns.RecordSetListOption RECORD_SET_LIST_OPTION =
Dns.RecordSetListOption.fields(Dns.RecordSetField.TTL);
private static final Dns.ChangeRequestListOption CHANGE_REQUEST_LIST_OPTION =
Dns.ChangeRequestListOption.fields(Dns.ChangeRequestField.STATUS);
Expand Down Expand Up @@ -89,9 +89,9 @@ protected Serializable[] serializableObjects() {
.authCredentials(null)
.build();
return new Serializable[]{FULL_ZONE_INFO, PARTIAL_ZONE_INFO, ZONE_LIST_OPTION,
DNS_REOCRD_LIST_OPTION, CHANGE_REQUEST_LIST_OPTION, ZONE_OPTION, CHANGE_REQUEST_OPTION,
RECORD_SET_LIST_OPTION, CHANGE_REQUEST_LIST_OPTION, ZONE_OPTION, CHANGE_REQUEST_OPTION,
PROJECT_OPTION, PARTIAL_PROJECT_INFO, FULL_PROJECT_INFO, OPTIONS, FULL_ZONE, PARTIAL_ZONE,
OPTIONS, CHANGE_REQUEST_PARTIAL, DNS_RECORD_PARTIAL, DNS_RECORD_COMPLETE,
OPTIONS, CHANGE_REQUEST_PARTIAL, RECORD_SET_PARTIAL, RECORD_SET_COMPLETE,
CHANGE_REQUEST_COMPLETE, options, otherOptions};
}

Expand Down
106 changes: 53 additions & 53 deletions gcloud-java-dns/src/test/java/com/google/gcloud/dns/it/ITDnsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,13 @@ private static void clear() {
while (iterator.hasNext()) {
waitForChangeToComplete(zoneName, iterator.next().id());
}
Iterator<RecordSet> recordIterator = zone.listRecordSets().iterateAll();
Iterator<RecordSet> recordSetIterator = zone.listRecordSets().iterateAll();
List<RecordSet> toDelete = new LinkedList<>();
while (recordIterator.hasNext()) {
RecordSet record = recordIterator.next();
while (recordSetIterator.hasNext()) {
RecordSet recordSet = recordSetIterator.next();
if (!ImmutableList.of(RecordSet.Type.NS, RecordSet.Type.SOA)
.contains(record.type())) {
toDelete.add(record);
.contains(recordSet.type())) {
toDelete.add(recordSet);
}
}
if (!toDelete.isEmpty()) {
Expand Down Expand Up @@ -597,7 +597,7 @@ public void testInvalidChangeRequest() {
zone.applyChangeRequest(validChange);
try {
zone.applyChangeRequest(validChange);
fail("Created a record which already exists.");
fail("Created a record set which already exists.");
} catch (DnsException ex) {
// expected
assertFalse(ex.retryable());
Expand All @@ -608,22 +608,22 @@ public void testInvalidChangeRequest() {
ChangeRequest deletion = ChangeRequest.builder().delete(mismatch).build();
try {
zone.applyChangeRequest(deletion);
fail("Deleted a record without a complete match.");
fail("Deleted a record set without a complete match.");
} catch (DnsException ex) {
// expected
assertEquals(412, ex.code());
assertFalse(ex.retryable());
}
// delete and add SOA
Iterator<RecordSet> recordIterator = zone.listRecordSets().iterateAll();
Iterator<RecordSet> recordSetIteratorrator = zone.listRecordSets().iterateAll();
LinkedList<RecordSet> deletions = new LinkedList<>();
LinkedList<RecordSet> additions = new LinkedList<>();
while (recordIterator.hasNext()) {
RecordSet record = recordIterator.next();
if (record.type() == RecordSet.Type.SOA) {
deletions.add(record);
while (recordSetIteratorrator.hasNext()) {
RecordSet recordSet = recordSetIteratorrator.next();
if (recordSet.type() == RecordSet.Type.SOA) {
deletions.add(recordSet);
// the subdomain is necessary to get 400 instead of 412
RecordSet copy = record.toBuilder().name("x." + record.name()).build();
RecordSet copy = recordSet.toBuilder().name("x." + recordSet.name()).build();
additions.add(copy);
break;
}
Expand Down Expand Up @@ -838,88 +838,88 @@ public void testListDnsRecords() {
assertEquals(2, recordSets.size());
ImmutableList<RecordSet.Type> defaultRecords =
ImmutableList.of(RecordSet.Type.NS, RecordSet.Type.SOA);
for (RecordSet record : recordSets) {
assertTrue(defaultRecords.contains(record.type()));
for (RecordSet recordSet : recordSets) {
assertTrue(defaultRecords.contains(recordSet.type()));
}
// field options
Iterator<RecordSet> dnsRecordIterator = DNS.listRecordSets(zone.name(),
Iterator<RecordSet> recordSetIterator = DNS.listRecordSets(zone.name(),
Dns.RecordSetListOption.fields(Dns.RecordSetField.TTL)).iterateAll();
int counter = 0;
while (dnsRecordIterator.hasNext()) {
RecordSet record = dnsRecordIterator.next();
assertEquals(recordSets.get(counter).ttl(), record.ttl());
assertEquals(recordSets.get(counter).name(), record.name());
assertEquals(recordSets.get(counter).type(), record.type());
assertTrue(record.records().isEmpty());
while (recordSetIterator.hasNext()) {
RecordSet recordSet = recordSetIterator.next();
assertEquals(recordSets.get(counter).ttl(), recordSet.ttl());
assertEquals(recordSets.get(counter).name(), recordSet.name());
assertEquals(recordSets.get(counter).type(), recordSet.type());
assertTrue(recordSet.records().isEmpty());
counter++;
}
assertEquals(2, counter);
dnsRecordIterator = DNS.listRecordSets(zone.name(),
recordSetIterator = DNS.listRecordSets(zone.name(),
Dns.RecordSetListOption.fields(Dns.RecordSetField.NAME)).iterateAll();
counter = 0;
while (dnsRecordIterator.hasNext()) {
RecordSet record = dnsRecordIterator.next();
assertEquals(recordSets.get(counter).name(), record.name());
assertEquals(recordSets.get(counter).type(), record.type());
assertTrue(record.records().isEmpty());
assertNull(record.ttl());
while (recordSetIterator.hasNext()) {
RecordSet recordSet = recordSetIterator.next();
assertEquals(recordSets.get(counter).name(), recordSet.name());
assertEquals(recordSets.get(counter).type(), recordSet.type());
assertTrue(recordSet.records().isEmpty());
assertNull(recordSet.ttl());
counter++;
}
assertEquals(2, counter);
dnsRecordIterator = DNS.listRecordSets(zone.name(),
recordSetIterator = DNS.listRecordSets(zone.name(),
Dns.RecordSetListOption.fields(Dns.RecordSetField.DNS_RECORDS))
.iterateAll();
counter = 0;
while (dnsRecordIterator.hasNext()) {
RecordSet record = dnsRecordIterator.next();
assertEquals(recordSets.get(counter).records(), record.records());
assertEquals(recordSets.get(counter).name(), record.name());
assertEquals(recordSets.get(counter).type(), record.type());
assertNull(record.ttl());
while (recordSetIterator.hasNext()) {
RecordSet recordSet = recordSetIterator.next();
assertEquals(recordSets.get(counter).records(), recordSet.records());
assertEquals(recordSets.get(counter).name(), recordSet.name());
assertEquals(recordSets.get(counter).type(), recordSet.type());
assertNull(recordSet.ttl());
counter++;
}
assertEquals(2, counter);
dnsRecordIterator = DNS.listRecordSets(zone.name(),
recordSetIterator = DNS.listRecordSets(zone.name(),
Dns.RecordSetListOption.fields(Dns.RecordSetField.TYPE),
Dns.RecordSetListOption.pageSize(1)).iterateAll(); // also test paging
counter = 0;
while (dnsRecordIterator.hasNext()) {
RecordSet record = dnsRecordIterator.next();
assertEquals(recordSets.get(counter).type(), record.type());
assertEquals(recordSets.get(counter).name(), record.name());
assertTrue(record.records().isEmpty());
assertNull(record.ttl());
while (recordSetIterator.hasNext()) {
RecordSet recordSet = recordSetIterator.next();
assertEquals(recordSets.get(counter).type(), recordSet.type());
assertEquals(recordSets.get(counter).name(), recordSet.name());
assertTrue(recordSet.records().isEmpty());
assertNull(recordSet.ttl());
counter++;
}
assertEquals(2, counter);
// test page size
Page<RecordSet> dnsRecordPage = DNS.listRecordSets(zone.name(),
Page<RecordSet> recordSetPage = DNS.listRecordSets(zone.name(),
Dns.RecordSetListOption.fields(Dns.RecordSetField.TYPE),
Dns.RecordSetListOption.pageSize(1));
assertEquals(1, ImmutableList.copyOf(dnsRecordPage.values().iterator()).size());
assertEquals(1, ImmutableList.copyOf(recordSetPage.values().iterator()).size());
// test name filter
ChangeRequest change = DNS.applyChangeRequest(ZONE1.name(), CHANGE_ADD_ZONE1);
waitForChangeToComplete(ZONE1.name(), change.id());
dnsRecordIterator = DNS.listRecordSets(ZONE1.name(),
recordSetIterator = DNS.listRecordSets(ZONE1.name(),
Dns.RecordSetListOption.dnsName(A_RECORD_ZONE1.name())).iterateAll();
counter = 0;
while (dnsRecordIterator.hasNext()) {
RecordSet record = dnsRecordIterator.next();
while (recordSetIterator.hasNext()) {
RecordSet recordSet = recordSetIterator.next();
assertTrue(ImmutableList.of(A_RECORD_ZONE1.type(), AAAA_RECORD_ZONE1.type())
.contains(record.type()));
.contains(recordSet.type()));
counter++;
}
assertEquals(2, counter);
// test type filter
waitForChangeToComplete(ZONE1.name(), change.id());
dnsRecordIterator = DNS.listRecordSets(ZONE1.name(),
recordSetIterator = DNS.listRecordSets(ZONE1.name(),
Dns.RecordSetListOption.dnsName(A_RECORD_ZONE1.name()),
Dns.RecordSetListOption.type(A_RECORD_ZONE1.type()))
.iterateAll();
counter = 0;
while (dnsRecordIterator.hasNext()) {
RecordSet record = dnsRecordIterator.next();
assertEquals(A_RECORD_ZONE1, record);
while (recordSetIterator.hasNext()) {
RecordSet recordSet = recordSetIterator.next();
assertEquals(A_RECORD_ZONE1, recordSet);
counter++;
}
assertEquals(1, counter);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,12 +203,12 @@ public void run(Dns dns, String... args) {
if (args.length > 3) {
ttl = Integer.parseInt(args[3]);
}
RecordSet record = RecordSet.builder(recordName, RecordSet.Type.A)
RecordSet recordSet = RecordSet.builder(recordName, RecordSet.Type.A)
.records(ImmutableList.of(ip))
.ttl(ttl, TimeUnit.SECONDS)
.build();
ChangeRequest changeRequest = ChangeRequest.builder()
.delete(record)
.delete(recordSet)
.build();
changeRequest = dns.applyChangeRequest(zoneName, changeRequest);
System.out.printf("The request for deleting A record %s for zone %s was successfully "
Expand Down
Loading

0 comments on commit 43e7b53

Please sign in to comment.