mirror of https://github.com/apache/jclouds.git
create and delete traffic controller pools in ultradns
This commit is contained in:
parent
e3f51bd030
commit
a329feee7c
|
@ -19,6 +19,8 @@
|
||||||
package org.jclouds.ultradns.ws.features;
|
package org.jclouds.ultradns.ws.features;
|
||||||
|
|
||||||
import org.jclouds.rest.ResourceNotFoundException;
|
import org.jclouds.rest.ResourceNotFoundException;
|
||||||
|
import org.jclouds.ultradns.ws.UltraDNSWSExceptions.ResourceAlreadyExistsException;
|
||||||
|
import org.jclouds.ultradns.ws.domain.RoundRobinPool;
|
||||||
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;
|
||||||
|
|
||||||
|
@ -29,6 +31,19 @@ import com.google.common.collect.FluentIterable;
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
public interface TrafficControllerPoolApi {
|
public interface TrafficControllerPoolApi {
|
||||||
|
/**
|
||||||
|
* creates a traffic controller pool.
|
||||||
|
*
|
||||||
|
* @param name
|
||||||
|
* {@link TrafficControllerPool#getName() name} of the TC pool
|
||||||
|
* @param hostname
|
||||||
|
* {@link TrafficControllerPool#getDName() dname} of the TC pool
|
||||||
|
* {ex. www.jclouds.org.}
|
||||||
|
* @return the {@code guid} of the new record
|
||||||
|
* @throws ResourceAlreadyExistsException
|
||||||
|
* if a pool already exists with the same attrs
|
||||||
|
*/
|
||||||
|
String createPoolForHostname(String name, String hostname) throws ResourceAlreadyExistsException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns all traffic controller pools in the zone.
|
* Returns all traffic controller pools in the zone.
|
||||||
|
@ -45,4 +60,12 @@ public interface TrafficControllerPoolApi {
|
||||||
* if the pool doesn't exist
|
* if the pool doesn't exist
|
||||||
*/
|
*/
|
||||||
FluentIterable<TrafficControllerPoolRecord> listRecords(String poolId) throws ResourceNotFoundException;
|
FluentIterable<TrafficControllerPoolRecord> listRecords(String poolId) throws ResourceNotFoundException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* removes a pool and all its records and probes
|
||||||
|
*
|
||||||
|
* @param id
|
||||||
|
* the {@link RoundRobinPool#getId() id}
|
||||||
|
*/
|
||||||
|
void delete(String id);
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,15 +21,19 @@ package org.jclouds.ultradns.ws.features;
|
||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
import javax.ws.rs.POST;
|
import javax.ws.rs.POST;
|
||||||
|
|
||||||
|
import org.jclouds.Fallbacks.VoidOnNotFoundOr404;
|
||||||
import org.jclouds.rest.ResourceNotFoundException;
|
import org.jclouds.rest.ResourceNotFoundException;
|
||||||
|
import org.jclouds.rest.annotations.Fallback;
|
||||||
import org.jclouds.rest.annotations.Payload;
|
import org.jclouds.rest.annotations.Payload;
|
||||||
import org.jclouds.rest.annotations.PayloadParam;
|
import org.jclouds.rest.annotations.PayloadParam;
|
||||||
import org.jclouds.rest.annotations.RequestFilters;
|
import org.jclouds.rest.annotations.RequestFilters;
|
||||||
import org.jclouds.rest.annotations.VirtualHost;
|
import org.jclouds.rest.annotations.VirtualHost;
|
||||||
import org.jclouds.rest.annotations.XMLResponseParser;
|
import org.jclouds.rest.annotations.XMLResponseParser;
|
||||||
|
import org.jclouds.ultradns.ws.UltraDNSWSExceptions.ResourceAlreadyExistsException;
|
||||||
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.filters.SOAPWrapWithPasswordAuth;
|
import org.jclouds.ultradns.ws.filters.SOAPWrapWithPasswordAuth;
|
||||||
|
import org.jclouds.ultradns.ws.xml.IDHandler;
|
||||||
import org.jclouds.ultradns.ws.xml.TrafficControllerPoolListHandler;
|
import org.jclouds.ultradns.ws.xml.TrafficControllerPoolListHandler;
|
||||||
import org.jclouds.ultradns.ws.xml.TrafficControllerPoolRecordListHandler;
|
import org.jclouds.ultradns.ws.xml.TrafficControllerPoolRecordListHandler;
|
||||||
|
|
||||||
|
@ -46,6 +50,16 @@ import com.google.common.util.concurrent.ListenableFuture;
|
||||||
@VirtualHost
|
@VirtualHost
|
||||||
public interface TrafficControllerPoolAsyncApi {
|
public interface TrafficControllerPoolAsyncApi {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see RoundRobinPoolApi#createPoolForHostname
|
||||||
|
*/
|
||||||
|
@Named("addTCLBPool")
|
||||||
|
@POST
|
||||||
|
@XMLResponseParser(IDHandler.TCPool.class)
|
||||||
|
@Payload("<v01:addTCLBPool><transactionID /><zoneName>{zoneName}</zoneName><hostName>{hostName}</hostName><description>{description}</description><poolRecordType>1</poolRecordType><failOver>Enabled</failOver><probing>Enabled</probing><maxActive>0</maxActive><rrGUID /></v01:addTCLBPool>")
|
||||||
|
ListenableFuture<String> createPoolForHostname(@PayloadParam("description") String name,
|
||||||
|
@PayloadParam("hostName") String hostname) throws ResourceAlreadyExistsException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see TrafficControllerPoolApi#list()
|
* @see TrafficControllerPoolApi#list()
|
||||||
*/
|
*/
|
||||||
|
@ -54,7 +68,7 @@ public interface TrafficControllerPoolAsyncApi {
|
||||||
@XMLResponseParser(TrafficControllerPoolListHandler.class)
|
@XMLResponseParser(TrafficControllerPoolListHandler.class)
|
||||||
@Payload("<v01:getLoadBalancingPoolsByZone><zoneName>{zoneName}</zoneName><lbPoolType>TC</lbPoolType></v01:getLoadBalancingPoolsByZone>")
|
@Payload("<v01:getLoadBalancingPoolsByZone><zoneName>{zoneName}</zoneName><lbPoolType>TC</lbPoolType></v01:getLoadBalancingPoolsByZone>")
|
||||||
ListenableFuture<FluentIterable<TrafficControllerPool>> list() throws ResourceNotFoundException;
|
ListenableFuture<FluentIterable<TrafficControllerPool>> list() throws ResourceNotFoundException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see TrafficControllerPoolApi#listRecords(String)
|
* @see TrafficControllerPoolApi#listRecords(String)
|
||||||
*/
|
*/
|
||||||
|
@ -65,4 +79,12 @@ public interface TrafficControllerPoolAsyncApi {
|
||||||
ListenableFuture<FluentIterable<TrafficControllerPoolRecord>> listRecords(@PayloadParam("poolId") String poolId)
|
ListenableFuture<FluentIterable<TrafficControllerPoolRecord>> listRecords(@PayloadParam("poolId") String poolId)
|
||||||
throws ResourceNotFoundException;
|
throws ResourceNotFoundException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see TrafficControllerPoolApi#delete(String)
|
||||||
|
*/
|
||||||
|
@Named("deleteLBPool")
|
||||||
|
@POST
|
||||||
|
@Payload("<v01:deleteLBPool><transactionID /><lbPoolID>{lbPoolID}</lbPoolID><DeleteAll>Yes</DeleteAll><retainRecordId /></v01:deleteLBPool>")
|
||||||
|
@Fallback(VoidOnNotFoundOr404.class)
|
||||||
|
ListenableFuture<Void> delete(@PayloadParam("lbPoolID") String id);
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,7 @@ import static org.testng.Assert.assertEquals;
|
||||||
import org.jclouds.http.HttpRequest;
|
import org.jclouds.http.HttpRequest;
|
||||||
import org.jclouds.http.HttpResponse;
|
import org.jclouds.http.HttpResponse;
|
||||||
import org.jclouds.ultradns.ws.UltraDNSWSApi;
|
import org.jclouds.ultradns.ws.UltraDNSWSApi;
|
||||||
|
import org.jclouds.ultradns.ws.UltraDNSWSExceptions.ResourceAlreadyExistsException;
|
||||||
import org.jclouds.ultradns.ws.internal.BaseUltraDNSWSApiExpectTest;
|
import org.jclouds.ultradns.ws.internal.BaseUltraDNSWSApiExpectTest;
|
||||||
import org.jclouds.ultradns.ws.parse.GetTCLoadBalancingPoolsByZoneResponseTest;
|
import org.jclouds.ultradns.ws.parse.GetTCLoadBalancingPoolsByZoneResponseTest;
|
||||||
import org.jclouds.ultradns.ws.parse.GetTCPoolRecordsResponseTest;
|
import org.jclouds.ultradns.ws.parse.GetTCPoolRecordsResponseTest;
|
||||||
|
@ -33,6 +34,27 @@ import org.testng.annotations.Test;
|
||||||
*/
|
*/
|
||||||
@Test(groups = "unit", testName = "TrafficControllerPoolApiExpectTest")
|
@Test(groups = "unit", testName = "TrafficControllerPoolApiExpectTest")
|
||||||
public class TrafficControllerPoolApiExpectTest extends BaseUltraDNSWSApiExpectTest {
|
public class TrafficControllerPoolApiExpectTest extends BaseUltraDNSWSApiExpectTest {
|
||||||
|
HttpRequest create = HttpRequest.builder().method("POST")
|
||||||
|
.endpoint("https://ultra-api.ultradns.com:8443/UltraDNS_WS/v01")
|
||||||
|
.addHeader("Host", "ultra-api.ultradns.com:8443")
|
||||||
|
.payload(payloadFromResourceWithContentType("/create_tcpool.xml", "application/xml")).build();
|
||||||
|
|
||||||
|
HttpResponse createResponse = HttpResponse.builder().statusCode(200)
|
||||||
|
.payload(payloadFromResourceWithContentType("/tcpool_created.xml", "application/xml")).build();
|
||||||
|
|
||||||
|
public void testCreateWhenResponseIs2xx() {
|
||||||
|
UltraDNSWSApi success = requestSendsResponse(create, createResponse);
|
||||||
|
assertEquals(success.getTrafficControllerPoolApiForZone("jclouds.org.").createPoolForHostname("www.jclouds.org.", "foo"), "060339AA0417567A");
|
||||||
|
}
|
||||||
|
|
||||||
|
HttpResponse alreadyCreated = HttpResponse.builder().statusCode(500)
|
||||||
|
.payload(payloadFromResourceWithContentType("/lbpool_already_exists.xml", "application/xml")).build();
|
||||||
|
|
||||||
|
@Test(expectedExceptions = ResourceAlreadyExistsException.class, expectedExceptionsMessageRegExp = "Pool already created for this host name : www.rrpool.adrianc.rrpool.ultradnstest.jclouds.org.")
|
||||||
|
public void testCreateWhenResponseError2912() {
|
||||||
|
UltraDNSWSApi already = requestSendsResponse(create, alreadyCreated);
|
||||||
|
already.getTrafficControllerPoolApiForZone("jclouds.org.").createPoolForHostname("www.jclouds.org.", "foo");
|
||||||
|
}
|
||||||
|
|
||||||
HttpRequest list = HttpRequest.builder().method("POST")
|
HttpRequest list = HttpRequest.builder().method("POST")
|
||||||
.endpoint("https://ultra-api.ultradns.com:8443/UltraDNS_WS/v01")
|
.endpoint("https://ultra-api.ultradns.com:8443/UltraDNS_WS/v01")
|
||||||
|
@ -65,4 +87,24 @@ public class TrafficControllerPoolApiExpectTest extends BaseUltraDNSWSApiExpectT
|
||||||
new GetTCPoolRecordsResponseTest().expected().toString());
|
new GetTCPoolRecordsResponseTest().expected().toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
HttpRequest delete = HttpRequest.builder().method("POST")
|
||||||
|
.endpoint("https://ultra-api.ultradns.com:8443/UltraDNS_WS/v01")
|
||||||
|
.addHeader("Host", "ultra-api.ultradns.com:8443")
|
||||||
|
.payload(payloadFromResourceWithContentType("/delete_lbpool.xml", "application/xml")).build();
|
||||||
|
|
||||||
|
HttpResponse deleteResponse = HttpResponse.builder().statusCode(404)
|
||||||
|
.payload(payloadFromResourceWithContentType("/lbpool_deleted.xml", "application/xml")).build();
|
||||||
|
|
||||||
|
public void testDeleteWhenResponseIs2xx() {
|
||||||
|
UltraDNSWSApi success = requestSendsResponse(delete, deleteResponse);
|
||||||
|
success.getTrafficControllerPoolApiForZone("jclouds.org.").delete("04053D8E57C7931F");
|
||||||
|
}
|
||||||
|
|
||||||
|
HttpResponse poolDoesntExist = HttpResponse.builder().message("Server Epoolor").statusCode(500)
|
||||||
|
.payload(payloadFromResource("/lbpool_doesnt_exist.xml")).build();
|
||||||
|
|
||||||
|
public void testDeleteWhenResponseRRNotFound() {
|
||||||
|
UltraDNSWSApi notFound = requestSendsResponse(delete, poolDoesntExist);
|
||||||
|
notFound.getTrafficControllerPoolApiForZone("jclouds.org.").delete("04053D8E57C7931F");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,31 +19,43 @@
|
||||||
package org.jclouds.ultradns.ws.features;
|
package org.jclouds.ultradns.ws.features;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
import static java.util.logging.Logger.getAnonymousLogger;
|
||||||
|
import static org.testng.Assert.assertEquals;
|
||||||
|
import static org.testng.Assert.assertFalse;
|
||||||
import static org.testng.Assert.assertTrue;
|
import static org.testng.Assert.assertTrue;
|
||||||
|
import static org.testng.Assert.fail;
|
||||||
|
|
||||||
import org.jclouds.rest.ResourceNotFoundException;
|
import org.jclouds.rest.ResourceNotFoundException;
|
||||||
|
import org.jclouds.ultradns.ws.UltraDNSWSExceptions.ResourceAlreadyExistsException;
|
||||||
import org.jclouds.ultradns.ws.domain.Account;
|
import org.jclouds.ultradns.ws.domain.Account;
|
||||||
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.TrafficControllerPoolRecord.Status;
|
import org.jclouds.ultradns.ws.domain.TrafficControllerPoolRecord.Status;
|
||||||
import org.jclouds.ultradns.ws.domain.Zone;
|
import org.jclouds.ultradns.ws.domain.Zone;
|
||||||
import org.jclouds.ultradns.ws.internal.BaseUltraDNSWSApiLiveTest;
|
import org.jclouds.ultradns.ws.internal.BaseUltraDNSWSApiLiveTest;
|
||||||
|
import org.testng.annotations.AfterClass;
|
||||||
import org.testng.annotations.BeforeClass;
|
import org.testng.annotations.BeforeClass;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
import com.google.common.base.Optional;
|
||||||
|
import com.google.common.base.Predicate;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
@Test(groups = "live", singleThreaded = true, testName = "TrafficControllerPoolApiLiveTest")
|
@Test(groups = "live", singleThreaded = true, testName = "TrafficControllerPoolApiLiveTest")
|
||||||
public class TrafficControllerPoolApiLiveTest extends BaseUltraDNSWSApiLiveTest {
|
public class TrafficControllerPoolApiLiveTest extends BaseUltraDNSWSApiLiveTest {
|
||||||
|
|
||||||
|
private String zoneName = System.getProperty("user.name").replace('.', '-') + ".tcpool.ultradnstest.jclouds.org.";
|
||||||
private Account account;
|
private Account account;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@BeforeClass(groups = { "integration", "live" })
|
@BeforeClass(groups = { "integration", "live" })
|
||||||
public void setupContext() {
|
public void setupContext() {
|
||||||
super.setupContext();
|
super.setupContext();
|
||||||
|
context.getApi().getZoneApi().delete(zoneName);
|
||||||
account = context.getApi().getCurrentAccount();
|
account = context.getApi().getCurrentAccount();
|
||||||
|
context.getApi().getZoneApi().createInAccount(zoneName, account.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkTCPool(TrafficControllerPool pool) {
|
private void checkTCPool(TrafficControllerPool pool) {
|
||||||
|
@ -90,7 +102,55 @@ public class TrafficControllerPoolApiLiveTest extends BaseUltraDNSWSApiLiveTest
|
||||||
api("AAAAAAAAAAAAAAAA").list();
|
api("AAAAAAAAAAAAAAAA").list();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDeleteWhenNotFound() {
|
||||||
|
api(zoneName).delete("06063D9C54C5AE09");
|
||||||
|
}
|
||||||
|
|
||||||
|
String hostname = "www.tcpool." + zoneName;
|
||||||
|
String poolId;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCreatePool() {
|
||||||
|
poolId = api(zoneName).createPoolForHostname("pool", hostname);
|
||||||
|
getAnonymousLogger().info("created tc pool: " + poolId);
|
||||||
|
try {
|
||||||
|
api(zoneName).createPoolForHostname("pool", hostname);
|
||||||
|
fail();
|
||||||
|
} catch (ResourceAlreadyExistsException e) {
|
||||||
|
|
||||||
|
}
|
||||||
|
Optional<TrafficControllerPool> pool = getPoolById(poolId);
|
||||||
|
assertTrue(pool.isPresent());
|
||||||
|
assertEquals(pool.get().getName(), "pool");
|
||||||
|
assertEquals(pool.get().getDName(), hostname);
|
||||||
|
checkTCPool(pool.get());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(dependsOnMethods = "testCreatePool")
|
||||||
|
public void testDeletePool() {
|
||||||
|
api(zoneName).delete(poolId);
|
||||||
|
assertFalse(getPoolById(poolId).isPresent());
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Optional<TrafficControllerPool> getPoolById(final String poolId) {
|
||||||
|
return api(zoneName).list().firstMatch(new Predicate<TrafficControllerPool>() {
|
||||||
|
public boolean apply(TrafficControllerPool in) {
|
||||||
|
return in.getId().equals(poolId);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
private TrafficControllerPoolApi api(String zoneName) {
|
private TrafficControllerPoolApi api(String zoneName) {
|
||||||
return context.getApi().getTrafficControllerPoolApiForZone(zoneName);
|
return context.getApi().getTrafficControllerPoolApiForZone(zoneName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@AfterClass(groups = { "integration", "live" })
|
||||||
|
protected void tearDownContext() {
|
||||||
|
if (poolId != null)
|
||||||
|
api(zoneName).delete(poolId);
|
||||||
|
context.getApi().getZoneApi().delete(zoneName);
|
||||||
|
super.tearDownContext();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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:addTCLBPool><transactionID /><zoneName>jclouds.org.</zoneName><hostName>foo</hostName><description>www.jclouds.org.</description><poolRecordType>1</poolRecordType><failOver>Enabled</failOver><probing>Enabled</probing><maxActive>0</maxActive><rrGUID /></v01:addTCLBPool></soapenv:Body></soapenv:Envelope>
|
|
@ -0,0 +1,5 @@
|
||||||
|
<env:Body>
|
||||||
|
<v01:addTCLBPoolResponse xmlns:web="http://webservice.api.ultra.neustar.com/">
|
||||||
|
<TCPoolID>060339AA0417567A</TCPoolID>
|
||||||
|
</v01:addTCLBPoolResponse>
|
||||||
|
</env:Body>
|
Loading…
Reference in New Issue