Merge pull request #1423 from jclouds/route53-list-name

add support for list recordsets by name in route53
This commit is contained in:
Adrian Cole 2013-03-13 18:21:44 -07:00
commit 2e1cc3c281
3 changed files with 28 additions and 11 deletions

View File

@ -37,7 +37,8 @@ public class BindNextRecord implements Binder {
NextRecord from = NextRecord.class.cast(payload);
Builder<?> builder = request.toBuilder();
builder.addQueryParam("name", from.getName());
builder.addQueryParam("type", from.getType().toString());
if (from.getType().isPresent())
builder.addQueryParam("type", from.getType().get());
if (from.getIdentifier().isPresent())
builder.addQueryParam("identifier", from.getIdentifier().get());
return (R) builder.build();

View File

@ -88,6 +88,10 @@ public class ResourceRecordSetIterable extends IterableWithMarker<ResourceRecord
* If the results were truncated, this holds the position of the next item.
*/
public static class NextRecord {
public static NextRecord name(String name) {
return new NextRecord(name, null, null);
}
public static NextRecord nameAndType(String name, String type) {
return new NextRecord(name, type, null);
}
@ -97,12 +101,12 @@ public class ResourceRecordSetIterable extends IterableWithMarker<ResourceRecord
}
private final String name;
private final String type;
private final Optional<String> type;
private final Optional<String> identifier;
private NextRecord(String name, String type, String identifier) {
this.name = checkNotNull(name, "name");
this.type = checkNotNull(type, "type for %s", name);
this.type = Optional.fromNullable(type);
this.identifier = Optional.fromNullable(identifier);
}
@ -116,7 +120,7 @@ public class ResourceRecordSetIterable extends IterableWithMarker<ResourceRecord
/**
* the type of the next record in the list.
*/
public String getType() {
public Optional<String> getType() {
return type;
}
@ -139,13 +143,12 @@ public class ResourceRecordSetIterable extends IterableWithMarker<ResourceRecord
if (obj == null || getClass() != obj.getClass())
return false;
NextRecord that = NextRecord.class.cast(obj);
return equal(this.name, that.name) && equal(this.type, that.type)
&& equal(this.identifier, that.identifier);
return equal(this.name, that.name) && equal(this.type, that.type) && equal(this.identifier, that.identifier);
}
@Override
public String toString() {
return toStringHelper("").omitNullValues().add("name", name).add("type", type)
return toStringHelper("").omitNullValues().add("name", name).add("type", type.orNull())
.add("identifier", identifier.orNull()).toString();
}
}

View File

@ -108,15 +108,28 @@ public class ResourceRecordSetApiExpectTest extends BaseRoute53ApiExpectTest {
Route53Api fail = requestSendsResponse(list, notFound);
assertEquals(fail.getResourceRecordSetApiForHostedZone("Z1PA6795UKMFR9").list().get(0).toSet(), ImmutableSet.of());
}
HttpRequest listAt = HttpRequest.builder().method("GET")
.endpoint("https://route53.amazonaws.com/2012-02-29/hostedzone/Z1PA6795UKMFR9/rrset?name=testdoc2.example.com")
.addHeader("Host", "route53.amazonaws.com")
.addHeader("Date", "Mon, 21 Jan 02013 19:29:03 -0800")
.addHeader("X-Amzn-Authorization", authForDate).build();
public void testListAtWhenResponseIs2xx() {
Route53Api apiWhenAtExist = requestSendsResponse(listAt, listResponse);
NextRecord next = NextRecord.name("testdoc2.example.com");
assertEquals(apiWhenAtExist.getResourceRecordSetApiForHostedZone("Z1PA6795UKMFR9").listAt(next).toString(),
new ListResourceRecordSetsResponseTest().expected().toString());
}
HttpRequest listAtNameAndType = HttpRequest.builder().method("GET")
.endpoint("https://route53.amazonaws.com/2012-02-29/hostedzone/Z1PA6795UKMFR9/rrset?name=testdoc2.example.com&type=NS")
.addHeader("Host", "route53.amazonaws.com")
.addHeader("Date", "Mon, 21 Jan 02013 19:29:03 -0800")
.addHeader("X-Amzn-Authorization", authForDate).build();
public void testListAtWhenResponseIs2xx() {
Route53Api apiWhenAtExist = requestSendsResponse(listAt, listResponse);
public void testListAtNameAndTypeWhenResponseIs2xx() {
Route53Api apiWhenAtExist = requestSendsResponse(listAtNameAndType, listResponse);
NextRecord next = NextRecord.nameAndType("testdoc2.example.com", "NS");
assertEquals(apiWhenAtExist.getResourceRecordSetApiForHostedZone("Z1PA6795UKMFR9").listAt(next).toString(),
new ListResourceRecordSetsResponseTest().expected().toString());
@ -126,7 +139,7 @@ public class ResourceRecordSetApiExpectTest extends BaseRoute53ApiExpectTest {
HttpResponse noMore = HttpResponse.builder().statusCode(200)
.payload(payloadFromStringWithContentType("<ListResourceRecordSetsResponse />", "text/xml")).build();
Route53Api success = requestsSendResponses(list, listResponse, listAt, noMore);
Route53Api success = requestsSendResponses(list, listResponse, listAtNameAndType, noMore);
assertEquals(success.getResourceRecordSetApiForHostedZone("Z1PA6795UKMFR9").list().concat().toSet(), new ListResourceRecordSetsResponseTest().expected()
.toSet());
}