Merge pull request #1446 from jclouds/route53-weighted

fix bug in route53 weighted rrsets
This commit is contained in:
Adrian Cole 2013-03-22 09:27:39 -07:00
commit c76c599f77
5 changed files with 99 additions and 57 deletions

View File

@ -103,7 +103,7 @@ public class ResourceRecordSet {
private Weighted(String id, String name, String type, int weight, Optional<Integer> ttl, List<String> values, private Weighted(String id, String name, String type, int weight, Optional<Integer> ttl, List<String> values,
Optional<AliasTarget> aliasTarget) { Optional<AliasTarget> aliasTarget) {
super(id, name, type, ttl, values, aliasTarget); super(id, name, type, ttl, values, aliasTarget);
this.weight = checkNotNull(weight, "weight"); this.weight = weight;
} }
/** /**

View File

@ -20,7 +20,6 @@ package org.jclouds.route53.functions;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import org.jclouds.rest.annotations.ParamParser;
import org.jclouds.route53.domain.ResourceRecordSet; import org.jclouds.route53.domain.ResourceRecordSet;
import org.jclouds.route53.domain.ResourceRecordSet.RecordSubset; import org.jclouds.route53.domain.ResourceRecordSet.RecordSubset;
import org.jclouds.route53.domain.ResourceRecordSet.RecordSubset.Latency; import org.jclouds.route53.domain.ResourceRecordSet.RecordSubset.Latency;
@ -30,7 +29,6 @@ import com.google.common.base.Function;
/** /**
* @author Adrian Cole * @author Adrian Cole
* @see ParamParser
*/ */
public class SerializeRRS implements Function<Object, String> { public class SerializeRRS implements Function<Object, String> {
@Override @Override
@ -41,7 +39,7 @@ public class SerializeRRS implements Function<Object, String> {
builder.append("<Type>").append(rrs.getType()).append("</Type>"); builder.append("<Type>").append(rrs.getType()).append("</Type>");
if (rrs instanceof RecordSubset) { if (rrs instanceof RecordSubset) {
String id = RecordSubset.class.cast(rrs).getId(); String id = RecordSubset.class.cast(rrs).getId();
builder.append("<ResourceRecordSubset>").append(id).append("</ResourceRecordSubset>"); builder.append("<SetIdentifier>").append(id).append("</SetIdentifier>");
} }
if (rrs instanceof Weighted) if (rrs instanceof Weighted)
builder.append("<Weight>").append(Weighted.class.cast(rrs).getWeight()).append("</Weight>"); builder.append("<Weight>").append(Weighted.class.cast(rrs).getWeight()).append("</Weight>");

View File

@ -135,33 +135,59 @@ public class ResourceRecordSetApiLiveTest extends BaseRoute53ApiLiveTest {
@Test @Test
public void testCreateAndDeleteBulkRecords() { public void testCreateAndDeleteBulkRecords() {
String name = System.getProperty("user.name").replace('.', '-') + ".bulk.route53test.jclouds.org."; String name = System.getProperty("user.name").replace('.', '-') + ".bulk.route53test.jclouds.org.";
try {
String zoneId = recreateZone(name);
ImmutableList<ResourceRecordSet> records = ImmutableList.<ResourceRecordSet> builder()
.add(ResourceRecordSet.builder().name("dom1." + name).type("TXT").add("\"somehow\" \" somewhere\"")
.build())
.add(ResourceRecordSet.builder().name("dom2." + name).type("TXT").add("\"goodies\"").build()).build();
createAndDeleteRecordsInZone(records, zoneId);
} finally {
clearAndDeleteHostedZonesNamed(name);
}
}
@Test
public void testCreateAndDeleteWeightedRecords() {
String name = System.getProperty("user.name").replace('.', '-') + ".weight.route53test.jclouds.org.";
try {
String zoneId = recreateZone(name);
ImmutableList<ResourceRecordSet> records = ImmutableList.<ResourceRecordSet> builder()
.add(Weighted.builder().id("dom1").weight(1).name("dom." + name).type("CNAME").add("dom1." + name)
.build())
.add(Weighted.builder().id("dom2").weight(1).name("dom." + name).type("CNAME").add("dom2." + name)
.build()).build();
createAndDeleteRecordsInZone(records, zoneId);
} finally {
clearAndDeleteHostedZonesNamed(name);
}
}
private String recreateZone(String name) {
clearAndDeleteHostedZonesNamed(name); clearAndDeleteHostedZonesNamed(name);
ImmutableList<ResourceRecordSet> records = ImmutableList.<ResourceRecordSet> builder()
.add(ResourceRecordSet.builder().name("dom1." + name).type("TXT").add("\"somehow\" \" somewhere\"").build())
.add(ResourceRecordSet.builder().name("dom2." + name).type("TXT").add("\"goodies\"").build()).build();
String nonce = name + " @ " + new Date(); String nonce = name + " @ " + new Date();
String comment = name + " for " + JcloudsVersion.get(); String comment = name + " for " + JcloudsVersion.get();
NewHostedZone newHostedZone = context.getApi().getHostedZoneApi() NewHostedZone newHostedZone = context.getApi().getHostedZoneApi()
.createWithReferenceAndComment(name, nonce, comment); .createWithReferenceAndComment(name, nonce, comment);
String zoneId = newHostedZone.getZone().getId();
getAnonymousLogger().info("created zone: " + newHostedZone); getAnonymousLogger().info("created zone: " + newHostedZone);
try { assertTrue(inSync.apply(newHostedZone.getChange()), "zone didn't sync " + newHostedZone);
assertTrue(inSync.apply(newHostedZone.getChange()), "zone didn't sync " + newHostedZone); return newHostedZone.getZone().getId();
sync(api(zoneId).apply(createAll(records))); }
checkAllRRs(zoneId); private void createAndDeleteRecordsInZone(ImmutableList<ResourceRecordSet> records, String zoneId) {
sync(api(zoneId).apply(createAll(records)));
sync(api(zoneId).apply(deleteAll(records))); checkAllRRs(zoneId);
PagedIterable<ResourceRecordSet> refreshed = refresh(zoneId); sync(api(zoneId).apply(deleteAll(records)));
assertTrue(refreshed.concat().filter(not(requiredRRTypes)).isEmpty(), "zone still has optional records: "
+ refreshed);
} finally { PagedIterable<ResourceRecordSet> refreshed = refresh(zoneId);
clearAndDeleteHostedZonesNamed(name); assertTrue(refreshed.concat().filter(not(requiredRRTypes)).isEmpty(), "zone still has optional records: "
} + refreshed);
} }
private void clearAndDeleteHostedZonesNamed(String name) { private void clearAndDeleteHostedZonesNamed(String name) {

View File

@ -1,36 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.route53.filters;
import org.testng.annotations.Test;
/**
* Tests behavior of {@code RestAuthentication}
*
* @author Adrian Cole
*/
// NOTE:without testName, this will not call @Before* and fail w/NPE during surefire
@Test(groups = "unit", testName = "RestAuthenticationTest")
public class RestAuthenticationTest {
@Test
void test() {
}
}

View File

@ -0,0 +1,54 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.route53.functions;
import static org.testng.Assert.assertEquals;
import org.jclouds.route53.domain.ResourceRecordSet;
import org.jclouds.route53.domain.ResourceRecordSet.RecordSubset.Weighted;
import org.testng.annotations.Test;
/**
* @author Adrian Cole
*/
@Test(groups = "unit")
public class SerializeRRSTest {
@Test
void roundRobinRRSetToXML() {
assertEquals(
new SerializeRRS().apply(ResourceRecordSet.builder()
.name("dom1.foo.com.")
.type("A")
.add("1.2.3.4")
.add("5.6.7.8").build()),
"<ResourceRecordSet><Name>dom1.foo.com.</Name><Type>A</Type><TTL>300</TTL><ResourceRecords><ResourceRecord><Value>1.2.3.4</Value></ResourceRecord><ResourceRecord><Value>5.6.7.8</Value></ResourceRecord></ResourceRecords></ResourceRecordSet>");
}
@Test
void roundWeightedRRSetToXML() {
assertEquals(new SerializeRRS().apply(Weighted.builder()
.id("dom1")
.weight(1)
.name("dom.foo.com.")
.type("CNAME")
.add("dom1.foo.com.").build()),
"<ResourceRecordSet><Name>dom.foo.com.</Name><Type>CNAME</Type><SetIdentifier>dom1</SetIdentifier><Weight>1</Weight><TTL>300</TTL><ResourceRecords><ResourceRecord><Value>dom1.foo.com.</Value></ResourceRecord></ResourceRecords></ResourceRecordSet>");
}
}