specify weight when adding pool record support in ultradns

This commit is contained in:
adriancole 2013-03-24 16:20:57 -07:00
parent d9572151ae
commit d7221dc9fc
5 changed files with 58 additions and 9 deletions

View File

@ -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<TrafficControllerPoolRecord> 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
*

View File

@ -115,6 +115,17 @@ public interface TrafficControllerPoolAsyncApi {
ListenableFuture<String> 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("<v01:addPoolRecord><transactionID /><poolID>{poolID}</poolID><pointsTo>{pointsTo}</pointsTo><priority /><failOverDelay /><ttl>{ttl}</ttl><weight>{weight}</weight><mode /><threshold /></v01:addPoolRecord>")
ListenableFuture<String> addRecordToPoolWithTTLAndWeight(@PayloadParam("pointsTo") String pointsTo,
@PayloadParam("poolID") String lbPoolID, @PayloadParam("ttl") int ttl, @PayloadParam("weight") int weight)
throws ResourceAlreadyExistsException;
/**
* @see TrafficControllerPoolApi#getRecordSpec(String)
*/

View File

@ -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();

View File

@ -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<Integer> 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.<Integer> 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.<Integer> absent()).getId();
}
@Test(dependsOnMethods = "addCNAMERecordsToPool")

View File

@ -0,0 +1 @@
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v01="http://webservice.api.ultra.neustar.com/v01/"><soapenv:Header><wsse:Security soapenv:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"><wsse:UsernameToken><wsse:Username>identity</wsse:Username><wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">credential</wsse:Password></wsse:UsernameToken></wsse:Security></soapenv:Header><soapenv:Body><v01:addPoolRecord><transactionID /><poolID>04053D8E57C7931F</poolID><pointsTo>1.2.3.4</pointsTo><priority /><failOverDelay /><ttl>300</ttl><weight>0</weight><mode /><threshold /></v01:addPoolRecord></soapenv:Body></soapenv:Envelope>