mirror of https://github.com/apache/jclouds.git
specify weight when adding pool record support in ultradns
This commit is contained in:
parent
2a4198d217
commit
b93d1266e8
|
@ -22,7 +22,6 @@ import org.jclouds.javax.annotation.Nullable;
|
||||||
import org.jclouds.rest.ResourceNotFoundException;
|
import org.jclouds.rest.ResourceNotFoundException;
|
||||||
import org.jclouds.ultradns.ws.UltraDNSWSExceptions.ResourceAlreadyExistsException;
|
import org.jclouds.ultradns.ws.UltraDNSWSExceptions.ResourceAlreadyExistsException;
|
||||||
import org.jclouds.ultradns.ws.domain.PoolRecordSpec;
|
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.TrafficControllerPool;
|
||||||
import org.jclouds.ultradns.ws.domain.TrafficControllerPoolRecord;
|
import org.jclouds.ultradns.ws.domain.TrafficControllerPoolRecord;
|
||||||
import org.jclouds.ultradns.ws.domain.UpdatePoolRecord;
|
import org.jclouds.ultradns.ws.domain.UpdatePoolRecord;
|
||||||
|
@ -84,14 +83,14 @@ public interface TrafficControllerPoolApi {
|
||||||
FluentIterable<TrafficControllerPoolRecord> listRecords(String poolId) throws ResourceNotFoundException;
|
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
|
* @param pointsTo
|
||||||
* the ipv4 address or hostname
|
* the ipv4 address or hostname
|
||||||
* @param lbPoolID
|
* @param lbPoolID
|
||||||
* the pool to add the record to.
|
* the pool to add the record to.
|
||||||
* @param ttl
|
* @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
|
* @return the {@link TrafficControllerPoolRecord#getId() id} of the new
|
||||||
* record
|
* record
|
||||||
* @throws ResourceAlreadyExistsException
|
* @throws ResourceAlreadyExistsException
|
||||||
|
@ -99,6 +98,25 @@ public interface TrafficControllerPoolApi {
|
||||||
*/
|
*/
|
||||||
String addRecordToPoolWithTTL(String pointsTo, String lbPoolID, int ttl) throws ResourceAlreadyExistsException;
|
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
|
* Retrieves information about the specified pool record
|
||||||
*
|
*
|
||||||
|
|
|
@ -115,6 +115,17 @@ public interface TrafficControllerPoolAsyncApi {
|
||||||
ListenableFuture<String> addRecordToPoolWithTTL(@PayloadParam("pointsTo") String pointsTo,
|
ListenableFuture<String> addRecordToPoolWithTTL(@PayloadParam("pointsTo") String pointsTo,
|
||||||
@PayloadParam("poolID") String lbPoolID, @PayloadParam("ttl") int ttl) throws ResourceAlreadyExistsException;
|
@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)
|
* @see TrafficControllerPoolApi#getRecordSpec(String)
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -143,6 +143,18 @@ public class TrafficControllerPoolApiExpectTest extends BaseUltraDNSWSApiExpectT
|
||||||
assertEquals(success.getTrafficControllerPoolApiForZone("jclouds.org.").addRecordToPoolWithTTL("1.2.3.4", "04053D8E57C7931F", 300), "06063DAC54F8D3D9");
|
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)
|
HttpResponse recordAlreadyCreated = HttpResponse.builder().statusCode(500)
|
||||||
.payload(payloadFromResourceWithContentType("/tcrecord_already_exists.xml", "application/xml")).build();
|
.payload(payloadFromResourceWithContentType("/tcrecord_already_exists.xml", "application/xml")).build();
|
||||||
|
|
||||||
|
|
|
@ -189,25 +189,32 @@ public class TrafficControllerPoolApiLiveTest extends BaseUltraDNSWSApiLiveTest
|
||||||
|
|
||||||
@DataProvider(name = "records")
|
@DataProvider(name = "records")
|
||||||
public Object[][] createRecords() {
|
public Object[][] createRecords() {
|
||||||
Object[][] records = new Object[2][3];
|
Object[][] records = new Object[2][4];
|
||||||
records[0][0] = "1.2.3.4";
|
records[0][0] = "1.2.3.4";
|
||||||
records[0][1] = "A";
|
records[0][1] = "A";
|
||||||
records[0][2] = 60;
|
records[0][2] = 60;
|
||||||
|
records[0][3] = Optional.of(98);
|
||||||
records[1][0] = "5.6.7.8";
|
records[1][0] = "5.6.7.8";
|
||||||
records[1][1] = "A";
|
records[1][1] = "A";
|
||||||
records[1][2] = 60;
|
records[1][2] = 60;
|
||||||
|
records[1][3] = Optional.of(2);
|
||||||
return records;
|
return records;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(dependsOnMethods = "testCreatePool", dataProvider = "records")
|
@Test(dependsOnMethods = "testCreatePool", dataProvider = "records")
|
||||||
public TrafficControllerPoolRecord addRecordToPool(final String pointsTo, final String type, final int ttl) {
|
public TrafficControllerPoolRecord addRecordToPool(String pointsTo, String type, int ttl, Optional<Integer> weight) {
|
||||||
String recordId = api(zoneName).addRecordToPoolWithTTL(pointsTo, poolId, ttl);
|
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);
|
getAnonymousLogger().info("created " + type + " record: " + recordId);
|
||||||
TrafficControllerPoolRecord record = checkPoolRecordConsistent(zoneName, getRecordById(recordId).get());
|
TrafficControllerPoolRecord record = checkPoolRecordConsistent(zoneName, getRecordById(recordId).get());
|
||||||
PoolRecordSpec recordSpec = checkPoolRecordSpec(api(zoneName).getRecordSpec(recordId));
|
PoolRecordSpec recordSpec = checkPoolRecordSpec(api(zoneName).getRecordSpec(recordId));
|
||||||
assertEquals(record.getPointsTo(), pointsTo);
|
assertEquals(record.getPointsTo(), pointsTo);
|
||||||
assertEquals(record.getType(), type);
|
assertEquals(record.getType(), type);
|
||||||
assertEquals(record.getWeight(), 2);
|
assertEquals(record.getWeight(), weight.or(2).intValue());
|
||||||
assertEquals(recordSpec.getTTL(), ttl);
|
assertEquals(recordSpec.getTTL(), ttl);
|
||||||
return record;
|
return record;
|
||||||
}
|
}
|
||||||
|
@ -217,7 +224,7 @@ public class TrafficControllerPoolApiLiveTest extends BaseUltraDNSWSApiLiveTest
|
||||||
|
|
||||||
@Test(dependsOnMethods = "testCreatePool")
|
@Test(dependsOnMethods = "testCreatePool")
|
||||||
public void addCNAMERecordsToPool() {
|
public void addCNAMERecordsToPool() {
|
||||||
cname1 = addRecordToPool("www.foo.com.", "CNAME", 30).getId();
|
cname1 = addRecordToPool("www.foo.com.", "CNAME", 30, Optional.<Integer> absent()).getId();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
api(zoneName).addRecordToPoolWithTTL("www.foo.com.", poolId, 30);
|
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")
|
@Test(dependsOnMethods = "addCNAMERecordsToPool")
|
||||||
|
|
|
@ -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>
|
Loading…
Reference in New Issue