Merge pull request #1452 from jclouds/ultradns-tcpool-createdelete

UltraDNS tcpool create|delete
This commit is contained in:
Adrian Cole 2013-03-24 07:54:16 -07:00
commit 9555e552a0
15 changed files with 347 additions and 85 deletions

View File

@ -35,7 +35,7 @@ import org.jclouds.ultradns.ws.binders.ZoneAndResourceRecordToXML;
import org.jclouds.ultradns.ws.domain.ResourceRecord; import org.jclouds.ultradns.ws.domain.ResourceRecord;
import org.jclouds.ultradns.ws.domain.ResourceRecordMetadata; import org.jclouds.ultradns.ws.domain.ResourceRecordMetadata;
import org.jclouds.ultradns.ws.filters.SOAPWrapWithPasswordAuth; import org.jclouds.ultradns.ws.filters.SOAPWrapWithPasswordAuth;
import org.jclouds.ultradns.ws.xml.GuidHandler; import org.jclouds.ultradns.ws.xml.IDHandler;
import org.jclouds.ultradns.ws.xml.ResourceRecordListHandler; import org.jclouds.ultradns.ws.xml.ResourceRecordListHandler;
import com.google.common.collect.FluentIterable; import com.google.common.collect.FluentIterable;
@ -56,7 +56,7 @@ public interface ResourceRecordAsyncApi {
*/ */
@Named("createResourceRecord") @Named("createResourceRecord")
@POST @POST
@XMLResponseParser(GuidHandler.class) @XMLResponseParser(IDHandler.Guid.class)
@MapBinder(ZoneAndResourceRecordToXML.class) @MapBinder(ZoneAndResourceRecordToXML.class)
ListenableFuture<String> create(@PayloadParam("resourceRecord") ResourceRecord toCreate) ListenableFuture<String> create(@PayloadParam("resourceRecord") ResourceRecord toCreate)
throws ResourceAlreadyExistsException; throws ResourceAlreadyExistsException;

View File

@ -33,8 +33,7 @@ import org.jclouds.ultradns.ws.UltraDNSWSExceptions.ResourceAlreadyExistsExcepti
import org.jclouds.ultradns.ws.domain.ResourceRecord; import org.jclouds.ultradns.ws.domain.ResourceRecord;
import org.jclouds.ultradns.ws.domain.RoundRobinPool; import org.jclouds.ultradns.ws.domain.RoundRobinPool;
import org.jclouds.ultradns.ws.filters.SOAPWrapWithPasswordAuth; import org.jclouds.ultradns.ws.filters.SOAPWrapWithPasswordAuth;
import org.jclouds.ultradns.ws.xml.GuidHandler; import org.jclouds.ultradns.ws.xml.IDHandler;
import org.jclouds.ultradns.ws.xml.RRPoolIDHandler;
import org.jclouds.ultradns.ws.xml.ResourceRecordListHandler; import org.jclouds.ultradns.ws.xml.ResourceRecordListHandler;
import org.jclouds.ultradns.ws.xml.RoundRobinPoolListHandler; import org.jclouds.ultradns.ws.xml.RoundRobinPoolListHandler;
@ -75,7 +74,7 @@ public interface RoundRobinPoolAsyncApi {
*/ */
@Named("addRRLBPool") @Named("addRRLBPool")
@POST @POST
@XMLResponseParser(RRPoolIDHandler.class) @XMLResponseParser(IDHandler.RRPool.class)
@Payload("<v01:addRRLBPool><transactionID /><zoneName>{zoneName}</zoneName><hostName>{hostName}</hostName><description>{description}</description><poolRecordType>1</poolRecordType><rrGUID /></v01:addRRLBPool>") @Payload("<v01:addRRLBPool><transactionID /><zoneName>{zoneName}</zoneName><hostName>{hostName}</hostName><description>{description}</description><poolRecordType>1</poolRecordType><rrGUID /></v01:addRRLBPool>")
ListenableFuture<String> createAPoolForHostname(@PayloadParam("description") String name, ListenableFuture<String> createAPoolForHostname(@PayloadParam("description") String name,
@PayloadParam("hostName") String hostname) throws ResourceAlreadyExistsException; @PayloadParam("hostName") String hostname) throws ResourceAlreadyExistsException;
@ -85,7 +84,7 @@ public interface RoundRobinPoolAsyncApi {
*/ */
@Named("addRecordToRRPool") @Named("addRecordToRRPool")
@POST @POST
@XMLResponseParser(GuidHandler.class) @XMLResponseParser(IDHandler.Guid.class)
@Payload("<v01:addRecordToRRPool><transactionID /><roundRobinRecord lbPoolID=\"{lbPoolID}\" info1Value=\"{address}\" ZoneName=\"{zoneName}\" Type=\"1\" TTL=\"{ttl}\"/></v01:addRecordToRRPool>") @Payload("<v01:addRecordToRRPool><transactionID /><roundRobinRecord lbPoolID=\"{lbPoolID}\" info1Value=\"{address}\" ZoneName=\"{zoneName}\" Type=\"1\" TTL=\"{ttl}\"/></v01:addRecordToRRPool>")
ListenableFuture<String> addARecordWithAddressAndTTL(@PayloadParam("lbPoolID") String lbPoolID, ListenableFuture<String> addARecordWithAddressAndTTL(@PayloadParam("lbPoolID") String lbPoolID,
@PayloadParam("address") String ipv4Address, @PayloadParam("ttl") int ttl) @PayloadParam("address") String ipv4Address, @PayloadParam("ttl") int ttl)
@ -115,7 +114,7 @@ public interface RoundRobinPoolAsyncApi {
*/ */
@Named("addRRLBPool") @Named("addRRLBPool")
@POST @POST
@XMLResponseParser(RRPoolIDHandler.class) @XMLResponseParser(IDHandler.RRPool.class)
@Payload("<v01:addRRLBPool><transactionID /><zoneName>{zoneName}</zoneName><hostName>{hostName}</hostName><description>{description}</description><poolRecordType>28</poolRecordType><rrGUID /></v01:addRRLBPool>") @Payload("<v01:addRRLBPool><transactionID /><zoneName>{zoneName}</zoneName><hostName>{hostName}</hostName><description>{description}</description><poolRecordType>28</poolRecordType><rrGUID /></v01:addRRLBPool>")
ListenableFuture<String> createAAAAPoolForHostname(@PayloadParam("description") String name, ListenableFuture<String> createAAAAPoolForHostname(@PayloadParam("description") String name,
@PayloadParam("hostName") String hostname) throws ResourceAlreadyExistsException; @PayloadParam("hostName") String hostname) throws ResourceAlreadyExistsException;
@ -125,7 +124,7 @@ public interface RoundRobinPoolAsyncApi {
*/ */
@Named("addRecordToRRPool") @Named("addRecordToRRPool")
@POST @POST
@XMLResponseParser(GuidHandler.class) @XMLResponseParser(IDHandler.Guid.class)
@Payload("<v01:addRecordToRRPool><transactionID /><roundRobinRecord lbPoolID=\"{lbPoolID}\" info1Value=\"{address}\" ZoneName=\"{zoneName}\" Type=\"28\" TTL=\"{ttl}\"/></v01:addRecordToRRPool>") @Payload("<v01:addRecordToRRPool><transactionID /><roundRobinRecord lbPoolID=\"{lbPoolID}\" info1Value=\"{address}\" ZoneName=\"{zoneName}\" Type=\"28\" TTL=\"{ttl}\"/></v01:addRecordToRRPool>")
ListenableFuture<String> addAAAARecordWithAddressAndTTL(@PayloadParam("lbPoolID") String lbPoolID, ListenableFuture<String> addAAAARecordWithAddressAndTTL(@PayloadParam("lbPoolID") String lbPoolID,
@PayloadParam("address") String ipv6Address, @PayloadParam("ttl") int ttl) @PayloadParam("address") String ipv6Address, @PayloadParam("ttl") int ttl)

View File

@ -31,7 +31,7 @@ import org.jclouds.rest.annotations.VirtualHost;
import org.jclouds.rest.annotations.XMLResponseParser; import org.jclouds.rest.annotations.XMLResponseParser;
import org.jclouds.ultradns.ws.domain.Task; import org.jclouds.ultradns.ws.domain.Task;
import org.jclouds.ultradns.ws.filters.SOAPWrapWithPasswordAuth; import org.jclouds.ultradns.ws.filters.SOAPWrapWithPasswordAuth;
import org.jclouds.ultradns.ws.xml.GuidHandler; import org.jclouds.ultradns.ws.xml.IDHandler;
import org.jclouds.ultradns.ws.xml.TaskHandler; import org.jclouds.ultradns.ws.xml.TaskHandler;
import org.jclouds.ultradns.ws.xml.TaskListHandler; import org.jclouds.ultradns.ws.xml.TaskListHandler;
@ -52,7 +52,7 @@ public interface TaskAsyncApi {
*/ */
@Named("runTest") @Named("runTest")
@POST @POST
@XMLResponseParser(GuidHandler.class) @XMLResponseParser(IDHandler.Guid.class)
@Payload("<v01:runTest><value>{value}</value></v01:runTest>") @Payload("<v01:runTest><value>{value}</value></v01:runTest>")
ListenableFuture<String> runTest(@PayloadParam("value") String value); ListenableFuture<String> runTest(@PayloadParam("value") String value);

View File

@ -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.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;
@ -38,6 +40,28 @@ public interface TrafficControllerPoolApi {
*/ */
FluentIterable<TrafficControllerPool> list() throws ResourceNotFoundException; FluentIterable<TrafficControllerPool> list() throws ResourceNotFoundException;
/**
* 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;
/**
* removes a pool and all its records and probes
*
* @param id
* the {@link TrafficControllerPool#getId() id}
*/
void delete(String id);
/** /**
* Returns all records in the traffic controller pool. * Returns all records in the traffic controller pool.
* *
@ -45,4 +69,29 @@ 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;
/**
* adds a new record to the pool
*
* @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
* @return the {@link TrafficControllerPoolRecord#getId() id} of the new
* record
* @throws ResourceAlreadyExistsException
* if a record already exists with the same attrs
*/
String addRecordToPoolWithTTL(String pointsTo, String lbPoolID, int ttl) throws ResourceAlreadyExistsException;
/**
* deletes a specific pooled resource record
*
* @param poolRecordID
* {@see TrafficControllerPoolRecord#getId()}
*/
void deleteRecord(String poolRecordID);
} }

View File

@ -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,32 @@ 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);
/**
* @see TrafficControllerPoolApi#addRecordToPoolWithTTL
*/
@Named("addPoolRecord")
@POST
@XMLResponseParser(IDHandler.PoolRecord.class)
@Payload("<v01:addPoolRecord><transactionID /><poolID>{poolID}</poolID><pointsTo>{pointsTo}</pointsTo><priority /><failOverDelay /><ttl>{ttl}</ttl><weight /><mode /><threshold /></v01:addPoolRecord>")
ListenableFuture<String> addRecordToPoolWithTTL(@PayloadParam("pointsTo") String pointsTo,
@PayloadParam("poolID") String lbPoolID, @PayloadParam("ttl") int ttl) throws ResourceAlreadyExistsException;
/**
* @see TrafficControllerPoolApi#deleteRecord(String)
*/
@Named("deletePoolRecord")
@POST
@Payload("<v01:deletePoolRecord><transactionID /><poolRecordID>{poolRecordID}</poolRecordID><parentPoolId /><childPoolId /></v01:deletePoolRecord>")
@Fallback(VoidOnNotFoundOr404.class)
ListenableFuture<Void> deleteRecord(@PayloadParam("poolRecordID") String poolRecordID);
} }

View File

@ -23,33 +23,59 @@ import static org.jclouds.util.SaxUtils.currentOrNull;
import static org.jclouds.util.SaxUtils.equalsOrSuffix; import static org.jclouds.util.SaxUtils.equalsOrSuffix;
import org.jclouds.http.functions.ParseSax; import org.jclouds.http.functions.ParseSax;
import org.xml.sax.Attributes;
/** /**
* *
* @author Adrian Cole * @author Adrian Cole
*/ */
public class GuidHandler extends ParseSax.HandlerForGeneratedRequestWithResult<String> { public abstract class IDHandler extends ParseSax.HandlerForGeneratedRequestWithResult<String> {
public static class Guid extends IDHandler {
public Guid() {
super("guid");
}
}
public static class RRPool extends IDHandler {
public RRPool() {
super("RRPoolID");
}
}
public static class TCPool extends IDHandler {
public TCPool() {
super("TCPoolID");
}
}
public static class PoolRecord extends IDHandler {
public PoolRecord() {
super("poolRecordID");
}
}
private String idElement;
private StringBuilder currentText = new StringBuilder(); private StringBuilder currentText = new StringBuilder();
private String guid = null; private String id = null;
private IDHandler(String idElement) {
this.idElement = checkNotNull(idElement, "idElement");
}
@Override @Override
public String getResult() { public String getResult() {
try { try {
return checkNotNull(guid, "guid not present in the response"); return checkNotNull(id, "%s not present in the response", idElement);
} finally { } finally {
guid = null; id = null;
} }
} }
@Override
public void startElement(String url, String name, String qName, Attributes attributes) {
}
@Override @Override
public void endElement(String uri, String name, String qName) { public void endElement(String uri, String name, String qName) {
if (equalsOrSuffix(qName, "guid")) { if (equalsOrSuffix(qName, idElement)) {
guid = currentOrNull(currentText); id = currentOrNull(currentText);
} }
currentText = new StringBuilder(); currentText = new StringBuilder();
} }

View File

@ -1,61 +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.ultradns.ws.xml;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.util.SaxUtils.currentOrNull;
import static org.jclouds.util.SaxUtils.equalsOrSuffix;
import org.jclouds.http.functions.ParseSax;
import org.xml.sax.Attributes;
/**
*
* @author Adrian Cole
*/
public class RRPoolIDHandler extends ParseSax.HandlerForGeneratedRequestWithResult<String> {
private StringBuilder currentText = new StringBuilder();
private String rrPoolID = null;
@Override
public String getResult() {
try {
return checkNotNull(rrPoolID, "RRPoolId not present in the response");
} finally {
rrPoolID = null;
}
}
@Override
public void startElement(String url, String name, String qName, Attributes attributes) {
}
@Override
public void endElement(String uri, String name, String qName) {
if (equalsOrSuffix(qName, "RRPoolID")) {
rrPoolID = currentOrNull(currentText);
}
currentText = new StringBuilder();
}
@Override
public void characters(char ch[], int start, int length) {
currentText.append(ch, start, length);
}
}

View File

@ -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,46 @@ 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");
}
HttpRequest createRecord = 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.xml", "application/xml")).build();
HttpResponse createRecordResponse = HttpResponse.builder().statusCode(200)
.payload(payloadFromResourceWithContentType("/tcrecord_created.xml", "application/xml")).build();
public void testCreateRecordWhenResponseIs2xx() {
UltraDNSWSApi success = requestSendsResponse(createRecord, createRecordResponse);
assertEquals(success.getTrafficControllerPoolApiForZone("jclouds.org.").addRecordToPoolWithTTL("1.2.3.4", "04053D8E57C7931F", 300), "06063DAC54F8D3D9");
}
HttpResponse recordAlreadyCreated = HttpResponse.builder().statusCode(500)
.payload(payloadFromResourceWithContentType("/tcrecord_already_exists.xml", "application/xml")).build();
@Test(expectedExceptions = ResourceAlreadyExistsException.class, expectedExceptionsMessageRegExp = "Resource Record of type 1 with these attributes already exists in the system.")
public void testCreateWhenResponseError1802() {
UltraDNSWSApi already = requestSendsResponse(createRecord, recordAlreadyCreated);
already.getTrafficControllerPoolApiForZone("jclouds.org.").addRecordToPoolWithTTL("1.2.3.4", "04053D8E57C7931F", 300);
}
} }

View File

@ -19,31 +19,44 @@
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.DataProvider;
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 +103,128 @@ 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());
}
@DataProvider(name = "records")
public Object[][] createRecords() {
Object[][] records = new Object[2][2];
records[0][0] = "1.2.3.4";
records[0][1] = "A";
records[1][0] = "5.6.7.8";
records[1][1] = "A";
return records;
}
@Test(dependsOnMethods = "testCreatePool", dataProvider = "records")
public void addRecordsToPool(final String pointsTo, final String type) {
final String record = api(zoneName).addRecordToPoolWithTTL(pointsTo, poolId, 30);
getAnonymousLogger().info("created " + type + " record: " + record);
assertTrue(api(zoneName).listRecords(poolId).anyMatch(new Predicate<TrafficControllerPoolRecord>() {
public boolean apply(TrafficControllerPoolRecord in) {
return record.equals(in.getId()) && pointsTo.equals(in.getPointsTo()) && type.equals(in.getType());
}
}));
}
String cname1;
String cname2;
@Test(dependsOnMethods = "testCreatePool")
public void addCNAMERecordsToPool() {
cname1 = api(zoneName).addRecordToPoolWithTTL("www.foo.com.", poolId, 30);
getAnonymousLogger().info("created CNAME record: " + cname1);
assertTrue(api(zoneName).listRecords(poolId).anyMatch(new Predicate<TrafficControllerPoolRecord>() {
public boolean apply(TrafficControllerPoolRecord in) {
return cname1.equals(in.getId()) && "www.foo.com.".equals(in.getPointsTo()) && "CNAME".equals(in.getType());
}
}));
try {
api(zoneName).addRecordToPoolWithTTL("www.foo.com.", poolId, 30);
fail();
} catch (ResourceAlreadyExistsException e) {
}
cname2 = api(zoneName).addRecordToPoolWithTTL("www.bar.com.", poolId, 30);
getAnonymousLogger().info("created CNAME record: " + cname2);
assertTrue(api(zoneName).listRecords(poolId).anyMatch(new Predicate<TrafficControllerPoolRecord>() {
public boolean apply(TrafficControllerPoolRecord in) {
return cname2.equals(in.getId()) && "www.bar.com.".equals(in.getPointsTo()) && "CNAME".equals(in.getType());
}
}));
}
@Test(dependsOnMethods = "addCNAMERecordsToPool")
public void testDeleteRecord() {
api(zoneName).deleteRecord(cname1);
assertTrue(api(zoneName).listRecords(poolId).anyMatch(new Predicate<TrafficControllerPoolRecord>() {
public boolean apply(TrafficControllerPoolRecord in) {
return cname2.equals(in.getId());
}
}));
assertFalse(api(zoneName).listRecords(poolId).anyMatch(new Predicate<TrafficControllerPoolRecord>() {
public boolean apply(TrafficControllerPoolRecord in) {
return cname1.equals(in.getId());
}
}));
}
@Test(dependsOnMethods = "testDeleteRecord")
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();
}
} }

View File

@ -23,7 +23,7 @@ import static org.testng.Assert.assertEquals;
import java.io.InputStream; import java.io.InputStream;
import org.jclouds.http.functions.BaseHandlerTest; import org.jclouds.http.functions.BaseHandlerTest;
import org.jclouds.ultradns.ws.xml.GuidHandler; import org.jclouds.ultradns.ws.xml.IDHandler;
import org.testng.annotations.Test; import org.testng.annotations.Test;
/** /**
@ -35,7 +35,7 @@ public class RunTestResponseTest extends BaseHandlerTest {
public void test() { public void test() {
InputStream is = getClass().getResourceAsStream("/taskid.xml"); InputStream is = getClass().getResourceAsStream("/taskid.xml");
GuidHandler handler = injector.getInstance(GuidHandler.class); IDHandler.Guid handler = injector.getInstance(IDHandler.Guid.class);
assertEquals(factory.create(handler).parse(is), "8d7a1725-4f4a-4b70-affa-f01dcce1526e"); assertEquals(factory.create(handler).parse(is), "8d7a1725-4f4a-4b70-affa-f01dcce1526e");
} }
} }

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: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>

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 /><mode /><threshold /></v01:addPoolRecord></soapenv:Body></soapenv:Envelope>

View File

@ -0,0 +1,5 @@
<env:Body>
<v01:addTCLBPoolResponse xmlns:web="http://webservice.api.ultra.neustar.com/">
<TCPoolID>060339AA0417567A</TCPoolID>
</v01:addTCLBPoolResponse>
</env:Body>

View File

@ -0,0 +1 @@
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><soap:Fault><faultcode>soap:Server</faultcode><faultstring>Fault occurred while processing.</faultstring><detail><ns1:UltraWSException xmlns:ns1="http://webservice.api.ultra.neustar.com/v01/"><errorCode xmlns:ns2="http://schema.ultraservice.neustar.com/v01/" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xs:int">2111</errorCode><errorDescription xmlns:ns2="http://schema.ultraservice.neustar.com/v01/">Resource Record of type 1 with these attributes already exists in the system.</errorDescription></ns1:UltraWSException></detail></soap:Fault></soap:Body></soap:Envelope>

View File

@ -0,0 +1 @@
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><ns1:addPoolRecordResponse xmlns:ns1="http://webservice.api.ultra.neustar.com/v01/"><poolRecordID xmlns:ns2="http://schema.ultraservice.neustar.com/v01/">06063DAC54F8D3D9</poolRecordID></ns1:addPoolRecordResponse></soap:Body></soap:Envelope>