Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert to primarily addressing CloudDNS and Designate zones by ID #349

Merged
merged 2 commits into from
Mar 22, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import denominator.DNSApiManager;
import denominator.ResourceRecordSetApi;
import denominator.ZoneApi;
import denominator.clouddns.RackspaceAdapters.DomainIdListAdapter;
import denominator.clouddns.RackspaceAdapters.DomainListAdapter;
import denominator.clouddns.RackspaceAdapters.JobIdAndStatusAdapter;
import denominator.clouddns.RackspaceAdapters.RecordListAdapter;
Expand Down Expand Up @@ -142,7 +141,6 @@ Feign feign(Logger logger, Logger.Level logLevel) {
new KeystoneAccessAdapter("rax:dns"),
new JobIdAndStatusAdapter(),
new DomainListAdapter(),
new DomainIdListAdapter(),
new RecordListAdapter()))
)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,8 @@ static final class Factory implements denominator.ResourceRecordSetApi.Factory {
}

@Override
public ResourceRecordSetApi create(String name) {
ListWithNext<Integer> matching = api.domainIdsByName(name);
checkArgument(!matching.isEmpty(), "zone %s does not exist", name);
return new CloudDNSResourceRecordSetApi(api, matching.get(0));
public ResourceRecordSetApi create(String id) {
return new CloudDNSResourceRecordSetApi(api, Integer.parseInt(id));
}
}
}
29 changes: 4 additions & 25 deletions clouddns/src/main/java/denominator/clouddns/RackspaceAdapters.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,30 +58,6 @@ public Job read(JsonReader reader) throws IOException {
}
}

static class DomainIdListAdapter extends ListWithNextAdapter<Integer> {

@Override
protected String jsonKey() {
return "domains";
}

protected Integer build(JsonReader reader) throws IOException {
Integer id = null;
while (reader.hasNext()) {
if (reader.nextName().equals("id")) {
id = reader.nextInt();
} else {
reader.skipValue();
}
}
return id;
}
}

/**
* Note that we do not expose the ID back to the user as ID isn't semantic when the API doesn't
* support multiple zones
*/
static class DomainListAdapter extends ListWithNextAdapter<Zone> {

@Override
Expand All @@ -93,8 +69,11 @@ protected Zone build(JsonReader reader) throws IOException {
String name = null;
String id = null;
while (reader.hasNext()) {
if (reader.nextName().equals("name")) {
String nextName = reader.nextName();
if (nextName.equals("name")) {
name = reader.nextString();
} else if (nextName.equals("id")) {
id = reader.nextString();
} else {
reader.skipValue();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ static interface CloudDNS {
* aren't permitted in the create api.
*/
@RequestLine("GET /domains?name={name}")
ListWithNext<Integer> domainIdsByName(@Param("name") String name);
ListWithNext<Zone> domainsByName(@Param("name") String name);

@RequestLine("GET")
ListWithNext<Zone> domains(URI href);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import denominator.model.rdata.AData;

import static denominator.assertj.ModelAssertions.assertThat;
import static denominator.clouddns.RackspaceApisTest.domainsResponse;
import static denominator.clouddns.RackspaceApisTest.domainId;
import static junit.framework.Assert.assertFalse;
import static org.junit.Assert.assertNull;

Expand Down Expand Up @@ -40,10 +40,9 @@ public class CloudDNSResourceRecordSetApiMockTest {
@Test
public void listWhenPresent() throws Exception {
server.enqueueAuthResponse();
server.enqueue(new MockResponse().setBody(domainsResponse));
server.enqueue(new MockResponse().setBody(records));

ResourceRecordSetApi api = server.connect().api().basicRecordSetsInZone("denominator.io");
ResourceRecordSetApi api = server.connect().api().basicRecordSetsInZone(domainId + "");
Iterator<ResourceRecordSet<?>> records = api.iterator();

while (records.hasNext()) {
Expand All @@ -53,9 +52,6 @@ public void listWhenPresent() throws Exception {
}

server.assertAuthRequest();
server.assertRequest()
.hasMethod("GET")
.hasPath("/v1.0/123123/domains?name=denominator.io");
server.assertRequest()
.hasMethod("GET")
.hasPath("/v1.0/123123/domains/1234/records");
Expand All @@ -64,18 +60,14 @@ public void listWhenPresent() throws Exception {
@Test
public void listWhenAbsent() throws Exception {
server.enqueueAuthResponse();
server.enqueue(new MockResponse().setBody(domainsResponse));
server.enqueue(new MockResponse().setResponseCode(404).setBody(
"{\"message\":\"Not Found\",\"code\":404,\"details\":\"\"}"));

ResourceRecordSetApi api = server.connect().api().basicRecordSetsInZone("denominator.io");
ResourceRecordSetApi api = server.connect().api().basicRecordSetsInZone(domainId + "");

assertFalse(api.iterator().hasNext());

server.assertAuthRequest();
server.assertRequest()
.hasMethod("GET")
.hasPath("/v1.0/123123/domains?name=denominator.io");
server.assertRequest()
.hasMethod("GET")
.hasPath("/v1.0/123123/domains/1234/records");
Expand All @@ -84,11 +76,10 @@ public void listWhenAbsent() throws Exception {
@Test
public void listPagesWhenPresent() throws Exception {
server.enqueueAuthResponse();
server.enqueue(new MockResponse().setBody(domainsResponse));
server.enqueue(new MockResponse().setBody(recordsPage1.replace("URL", server.url())));
server.enqueue(new MockResponse().setBody(recordsPage2.replace("URL", server.url())));

ResourceRecordSetApi api = server.connect().api().basicRecordSetsInZone("denominator.io");
ResourceRecordSetApi api = server.connect().api().basicRecordSetsInZone(domainId + "");
Iterator<ResourceRecordSet<?>> records = api.iterator();

while (records.hasNext()) {
Expand All @@ -98,9 +89,6 @@ public void listPagesWhenPresent() throws Exception {
}

server.assertAuthRequest();
server.assertRequest()
.hasMethod("GET")
.hasPath("/v1.0/123123/domains?name=denominator.io");
server.assertRequest()
.hasMethod("GET")
.hasPath("/v1.0/123123/domains/1234/records");
Expand All @@ -112,10 +100,9 @@ public void listPagesWhenPresent() throws Exception {
@Test
public void iterateByNameWhenPresent() throws Exception {
server.enqueueAuthResponse();
server.enqueue(new MockResponse().setBody(domainsResponse));
server.enqueue(new MockResponse().setBody(recordsByName));

ResourceRecordSetApi api = server.connect().api().basicRecordSetsInZone("denominator.io");
ResourceRecordSetApi api = server.connect().api().basicRecordSetsInZone(domainId + "");
Iterator<ResourceRecordSet<?>> records = api.iterateByName("www.denominator.io");

while (records.hasNext()) {
Expand All @@ -125,9 +112,6 @@ public void iterateByNameWhenPresent() throws Exception {
}

server.assertAuthRequest();
server.assertRequest()
.hasMethod("GET")
.hasPath("/v1.0/123123/domains?name=denominator.io");
server.assertRequest()
.hasMethod("GET")
.hasPath("/v1.0/123123/domains/1234/records");
Expand All @@ -136,17 +120,13 @@ public void iterateByNameWhenPresent() throws Exception {
@Test
public void iterateByNameWhenAbsent() throws Exception {
server.enqueueAuthResponse();
server.enqueue(new MockResponse().setBody(domainsResponse));
server.enqueue(new MockResponse().setResponseCode(404).setBody(
"{\"message\":\"Not Found\",\"code\":404,\"details\":\"\"}"));

ResourceRecordSetApi api = server.connect().api().basicRecordSetsInZone("denominator.io");
ResourceRecordSetApi api = server.connect().api().basicRecordSetsInZone(domainId + "");
assertFalse(api.iterateByName("www.denominator.io").hasNext());

server.assertAuthRequest();
server.assertRequest()
.hasMethod("GET")
.hasPath("/v1.0/123123/domains?name=denominator.io");
server.assertRequest()
.hasMethod("GET")
.hasPath("/v1.0/123123/domains/1234/records");
Expand All @@ -155,10 +135,9 @@ public void iterateByNameWhenAbsent() throws Exception {
@Test
public void getByNameAndTypeWhenPresent() throws Exception {
server.enqueueAuthResponse();
server.enqueue(new MockResponse().setBody(domainsResponse));
server.enqueue(new MockResponse().setBody(recordsByNameAndType));

ResourceRecordSetApi api = server.connect().api().basicRecordSetsInZone("denominator.io");
ResourceRecordSetApi api = server.connect().api().basicRecordSetsInZone(domainId + "");

assertThat(api.getByNameAndType("www.denominator.io", "A"))
.hasName("www.denominator.io")
Expand All @@ -167,9 +146,6 @@ public void getByNameAndTypeWhenPresent() throws Exception {
.containsExactlyRecords(AData.create("1.2.3.4"), AData.create("5.6.7.8"));

server.assertAuthRequest();
server.assertRequest()
.hasMethod("GET")
.hasPath("/v1.0/123123/domains?name=denominator.io");
server.assertRequest()
.hasMethod("GET")
.hasPath("/v1.0/123123/domains/1234/records?name=www.denominator.io&type=A");
Expand All @@ -178,17 +154,13 @@ public void getByNameAndTypeWhenPresent() throws Exception {
@Test
public void getByNameAndTypeWhenAbsent() throws Exception {
server.enqueueAuthResponse();
server.enqueue(new MockResponse().setBody(domainsResponse));
server.enqueue(new MockResponse().setResponseCode(404).setBody(
"{\"message\":\"Not Found\",\"code\":404,\"details\":\"\"}"));

ResourceRecordSetApi api = server.connect().api().basicRecordSetsInZone("denominator.io");
ResourceRecordSetApi api = server.connect().api().basicRecordSetsInZone(domainId + "");
assertNull(api.getByNameAndType("www.denominator.io", "A"));

server.assertAuthRequest();
server.assertRequest()
.hasMethod("GET")
.hasPath("/v1.0/123123/domains?name=denominator.io");
server.assertRequest()
.hasMethod("GET")
.hasPath("/v1.0/123123/domains/1234/records?name=www.denominator.io&type=A");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import denominator.model.Zone;

import static denominator.assertj.ModelAssertions.assertThat;
import static denominator.clouddns.RackspaceApisTest.domainId;
import static denominator.clouddns.RackspaceApisTest.domainsResponse;
import static org.junit.Assert.assertFalse;

Expand All @@ -28,7 +29,8 @@ public void iteratorWhenPresent() throws Exception {
Iterator<Zone> domains = api.iterator();

assertThat(domains.next())
.hasName("denominator.io");
.hasName("denominator.io")
.hasId(String.valueOf(domainId));

server.assertAuthRequest();
server.assertRequest().hasPath("/v1.0/123123/domains");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import denominator.clouddns.RackspaceApis.CloudIdentity;
import denominator.clouddns.RackspaceApis.Job;
import denominator.clouddns.RackspaceApis.TokenIdAndPublicURL;
import denominator.model.Zone;
import feign.Feign;

import static denominator.assertj.ModelAssertions.assertThat;
Expand Down Expand Up @@ -74,12 +75,12 @@ public void domainsPresent() throws Exception {
}

@Test
public void domainIdsByNamePresent() throws Exception {
public void domainsByNamePresent() throws Exception {
server.enqueueAuthResponse();
server.enqueue(new MockResponse().setBody(domainsResponse));

assertThat(mockApi().domainIdsByName("denominator.io"))
.containsOnly(1234);
assertThat(mockApi().domainsByName("denominator.io"))
.containsOnly(Zone.create("denominator.io", "1234"));

server.assertAuthRequest();
server.assertRequest()
Expand Down
3 changes: 0 additions & 3 deletions designate/src/main/java/denominator/designate/Designate.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ public interface Designate {
@RequestLine("GET /domains")
List<Zone> domains();

@RequestLine("GET /domains")
Map<String, String> domainIdsByName();

@RequestLine("GET /domains/{domainId}/records")
List<Record> records(@Param("domainId") String domainId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@
import java.io.IOException;
import java.util.Collections;
import java.util.Comparator;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import denominator.designate.Designate.Record;
import denominator.model.Zone;
Expand Down Expand Up @@ -80,48 +78,6 @@ public Record read(JsonReader reader) throws IOException {
}
}

static class DomainNameToIdAdapter extends TypeAdapter<Map<String, String>> {

@Override
public Map<String, String> read(JsonReader reader) throws IOException {
Map<String, String> result = new LinkedHashMap<String, String>();
reader.beginObject();
while (reader.hasNext()) {
String nextName = reader.nextName();
if ("domains".equals(nextName)) {
reader.beginArray();
while (reader.hasNext()) {
reader.beginObject();
String name = null;
String id = null;
while (reader.hasNext()) {
nextName = reader.nextName();
if (nextName.equals("name")) {
name = reader.nextString();
} else if (nextName.equals("id")) {
id = reader.nextString();
} else {
reader.skipValue();
}
}
result.put(name, id);
reader.endObject();
}
reader.endArray();
} else {
reader.skipValue();
}
}
reader.endObject();
return result;
}

@Override
public void write(JsonWriter out, Map<String, String> value) throws IOException {
throw new UnsupportedOperationException();
}
}

static class DomainListAdapter extends ListAdapter<Zone> {

@Override
Expand All @@ -131,14 +87,18 @@ protected String jsonKey() {

protected Zone build(JsonReader reader) throws IOException {
String name = null;
String id = null;
while (reader.hasNext()) {
if (reader.nextName().equals("name")) {
String key = reader.nextName();
if (key.equals("name")) {
name = reader.nextString();
} else if (key.equals("id")) {
id = reader.nextString();
} else {
reader.skipValue();
}
}
return Zone.create(name);
return Zone.create(name, id);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import denominator.config.OnlyBasicResourceRecordSets;
import denominator.config.WeightedUnsupported;
import denominator.designate.DesignateAdapters.DomainListAdapter;
import denominator.designate.DesignateAdapters.DomainNameToIdAdapter;
import denominator.designate.DesignateAdapters.RecordAdapter;
import denominator.designate.DesignateAdapters.RecordListAdapter;
import feign.Feign;
Expand Down Expand Up @@ -140,7 +139,6 @@ Feign feign(Logger logger, Logger.Level logLevel) {
new KeystoneV2AccessAdapter(),
recordAdapter,
new DomainListAdapter(),
new DomainNameToIdAdapter(),
new RecordListAdapter()))
)
.build();
Expand Down
Loading