From b93d1266e81cd838a981dc3f344f5d12f82e9112 Mon Sep 17 00:00:00 2001 From: adriancole Date: Sun, 24 Mar 2013 16:20:57 -0700 Subject: [PATCH] specify weight when adding pool record support in ultradns --- .../ws/features/TrafficControllerPoolApi.java | 24 ++++++++++++++++--- .../TrafficControllerPoolAsyncApi.java | 11 +++++++++ .../TrafficControllerPoolApiExpectTest.java | 12 ++++++++++ .../TrafficControllerPoolApiLiveTest.java | 19 ++++++++++----- .../test/resources/create_tcrecord_weight.xml | 1 + 5 files changed, 58 insertions(+), 9 deletions(-) create mode 100644 providers/ultradns-ws/src/test/resources/create_tcrecord_weight.xml diff --git a/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/features/TrafficControllerPoolApi.java b/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/features/TrafficControllerPoolApi.java index 1509528eea..4ad9b5eb08 100644 --- a/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/features/TrafficControllerPoolApi.java +++ b/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/features/TrafficControllerPoolApi.java @@ -22,7 +22,6 @@ import org.jclouds.javax.annotation.Nullable; import org.jclouds.rest.ResourceNotFoundException; import org.jclouds.ultradns.ws.UltraDNSWSExceptions.ResourceAlreadyExistsException; import org.jclouds.ultradns.ws.domain.PoolRecordSpec; -import org.jclouds.ultradns.ws.domain.ResourceRecord; import org.jclouds.ultradns.ws.domain.TrafficControllerPool; import org.jclouds.ultradns.ws.domain.TrafficControllerPoolRecord; import org.jclouds.ultradns.ws.domain.UpdatePoolRecord; @@ -84,14 +83,14 @@ public interface TrafficControllerPoolApi { FluentIterable listRecords(String poolId) throws ResourceNotFoundException; /** - * adds a new record to the pool + * adds a new record to the pool with default weight. * * @param pointsTo * the ipv4 address or hostname * @param lbPoolID * the pool to add the record to. * @param ttl - * the {@link ResourceRecord#getTTL ttl} of the record + * the {@link PoolRecordSpec#getTTL ttl} of the record * @return the {@link TrafficControllerPoolRecord#getId() id} of the new * record * @throws ResourceAlreadyExistsException @@ -99,6 +98,25 @@ public interface TrafficControllerPoolApi { */ String addRecordToPoolWithTTL(String pointsTo, String lbPoolID, int ttl) throws ResourceAlreadyExistsException; + /** + * adds a new record to the pool with a specified weight. + * + * @param pointsTo + * the ipv4 address or hostname + * @param lbPoolID + * the pool to add the record to. + * @param ttl + * the {@link PoolRecordSpec#getTTL ttl} of the record + * @param weight + * the {@link PoolRecordSpec#getWeight() weight} of the record + * @return the {@link TrafficControllerPoolRecord#getId() id} of the new + * record + * @throws ResourceAlreadyExistsException + * if a record already exists with the same attrs + */ + String addRecordToPoolWithTTLAndWeight(String pointsTo, String lbPoolID, int ttl, int weight) + throws ResourceAlreadyExistsException; + /** * Retrieves information about the specified pool record * diff --git a/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/features/TrafficControllerPoolAsyncApi.java b/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/features/TrafficControllerPoolAsyncApi.java index c20cc7f72f..75e1f39c6a 100644 --- a/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/features/TrafficControllerPoolAsyncApi.java +++ b/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/features/TrafficControllerPoolAsyncApi.java @@ -115,6 +115,17 @@ public interface TrafficControllerPoolAsyncApi { ListenableFuture addRecordToPoolWithTTL(@PayloadParam("pointsTo") String pointsTo, @PayloadParam("poolID") String lbPoolID, @PayloadParam("ttl") int ttl) throws ResourceAlreadyExistsException; + /** + * @see TrafficControllerPoolApi#addRecordToPoolWithTTLAndWeight + */ + @Named("addPoolRecord") + @POST + @XMLResponseParser(TextHandler.PoolRecordID.class) + @Payload("{poolID}{pointsTo}{ttl}{weight}") + ListenableFuture addRecordToPoolWithTTLAndWeight(@PayloadParam("pointsTo") String pointsTo, + @PayloadParam("poolID") String lbPoolID, @PayloadParam("ttl") int ttl, @PayloadParam("weight") int weight) + throws ResourceAlreadyExistsException; + /** * @see TrafficControllerPoolApi#getRecordSpec(String) */ diff --git a/providers/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/features/TrafficControllerPoolApiExpectTest.java b/providers/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/features/TrafficControllerPoolApiExpectTest.java index 583a562739..82c212efd2 100644 --- a/providers/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/features/TrafficControllerPoolApiExpectTest.java +++ b/providers/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/features/TrafficControllerPoolApiExpectTest.java @@ -142,6 +142,18 @@ public class TrafficControllerPoolApiExpectTest extends BaseUltraDNSWSApiExpectT UltraDNSWSApi success = requestSendsResponse(createRecord, createRecordResponse); assertEquals(success.getTrafficControllerPoolApiForZone("jclouds.org.").addRecordToPoolWithTTL("1.2.3.4", "04053D8E57C7931F", 300), "06063DAC54F8D3D9"); } + + HttpRequest createRecordWithWeight = HttpRequest.builder().method("POST") + .endpoint("https://ultra-api.ultradns.com:8443/UltraDNS_WS/v01") + .addHeader("Host", "ultra-api.ultradns.com:8443") + .payload(payloadFromResourceWithContentType("/create_tcrecord_weight.xml", "application/xml")).build(); + + public void testCreateRecordWithWeightWhenResponseIs2xx() { + UltraDNSWSApi success = requestSendsResponse(createRecordWithWeight, createRecordResponse); + assertEquals( + success.getTrafficControllerPoolApiForZone("jclouds.org.").addRecordToPoolWithTTLAndWeight("1.2.3.4", + "04053D8E57C7931F", 300, 0), "06063DAC54F8D3D9"); + } HttpResponse recordAlreadyCreated = HttpResponse.builder().statusCode(500) .payload(payloadFromResourceWithContentType("/tcrecord_already_exists.xml", "application/xml")).build(); diff --git a/providers/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/features/TrafficControllerPoolApiLiveTest.java b/providers/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/features/TrafficControllerPoolApiLiveTest.java index c173d4c4a3..4b5a613fbe 100644 --- a/providers/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/features/TrafficControllerPoolApiLiveTest.java +++ b/providers/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/features/TrafficControllerPoolApiLiveTest.java @@ -189,25 +189,32 @@ public class TrafficControllerPoolApiLiveTest extends BaseUltraDNSWSApiLiveTest @DataProvider(name = "records") public Object[][] createRecords() { - Object[][] records = new Object[2][3]; + Object[][] records = new Object[2][4]; records[0][0] = "1.2.3.4"; records[0][1] = "A"; records[0][2] = 60; + records[0][3] = Optional.of(98); records[1][0] = "5.6.7.8"; records[1][1] = "A"; records[1][2] = 60; + records[1][3] = Optional.of(2); return records; } @Test(dependsOnMethods = "testCreatePool", dataProvider = "records") - public TrafficControllerPoolRecord addRecordToPool(final String pointsTo, final String type, final int ttl) { - String recordId = api(zoneName).addRecordToPoolWithTTL(pointsTo, poolId, ttl); + public TrafficControllerPoolRecord addRecordToPool(String pointsTo, String type, int ttl, Optional weight) { + String recordId; + if (weight.isPresent()) { + recordId = api(zoneName).addRecordToPoolWithTTLAndWeight(pointsTo, poolId, ttl, weight.get()); + } else { + recordId = api(zoneName).addRecordToPoolWithTTL(pointsTo, poolId, ttl); + } getAnonymousLogger().info("created " + type + " record: " + recordId); TrafficControllerPoolRecord record = checkPoolRecordConsistent(zoneName, getRecordById(recordId).get()); PoolRecordSpec recordSpec = checkPoolRecordSpec(api(zoneName).getRecordSpec(recordId)); assertEquals(record.getPointsTo(), pointsTo); assertEquals(record.getType(), type); - assertEquals(record.getWeight(), 2); + assertEquals(record.getWeight(), weight.or(2).intValue()); assertEquals(recordSpec.getTTL(), ttl); return record; } @@ -217,7 +224,7 @@ public class TrafficControllerPoolApiLiveTest extends BaseUltraDNSWSApiLiveTest @Test(dependsOnMethods = "testCreatePool") public void addCNAMERecordsToPool() { - cname1 = addRecordToPool("www.foo.com.", "CNAME", 30).getId(); + cname1 = addRecordToPool("www.foo.com.", "CNAME", 30, Optional. absent()).getId(); try { api(zoneName).addRecordToPoolWithTTL("www.foo.com.", poolId, 30); @@ -226,7 +233,7 @@ public class TrafficControllerPoolApiLiveTest extends BaseUltraDNSWSApiLiveTest } - cname2 = addRecordToPool("www.bar.com.", "CNAME", 30).getId(); + cname2 = addRecordToPool("www.bar.com.", "CNAME", 30, Optional. absent()).getId(); } @Test(dependsOnMethods = "addCNAMERecordsToPool") diff --git a/providers/ultradns-ws/src/test/resources/create_tcrecord_weight.xml b/providers/ultradns-ws/src/test/resources/create_tcrecord_weight.xml new file mode 100644 index 0000000000..bfca560899 --- /dev/null +++ b/providers/ultradns-ws/src/test/resources/create_tcrecord_weight.xml @@ -0,0 +1 @@ +identitycredential04053D8E57C7931F1.2.3.43000 \ No newline at end of file