mirror of https://github.com/apache/jclouds.git
add ability to lookup traffic controller pool in ultradns by its dname
This commit is contained in:
parent
1979b21a85
commit
e5c78414d1
|
@ -56,6 +56,16 @@ public interface TrafficControllerPoolApi {
|
|||
*/
|
||||
String createPoolForHostname(String name, String hostname) throws ResourceAlreadyExistsException;
|
||||
|
||||
/**
|
||||
* Retrieves the name of the specified pool by dname.
|
||||
*
|
||||
* @param dname
|
||||
* {@see TrafficControllerPool#getDName()} ex. {@code jclouds.org.}
|
||||
* @return null if not found
|
||||
*/
|
||||
@Nullable
|
||||
String getNameByDName(String dname);
|
||||
|
||||
/**
|
||||
* removes a pool and all its records and probes
|
||||
*
|
||||
|
|
|
@ -35,6 +35,7 @@ import org.jclouds.ultradns.ws.domain.PoolRecordSpec;
|
|||
import org.jclouds.ultradns.ws.domain.TrafficControllerPool;
|
||||
import org.jclouds.ultradns.ws.domain.TrafficControllerPoolRecord;
|
||||
import org.jclouds.ultradns.ws.filters.SOAPWrapWithPasswordAuth;
|
||||
import org.jclouds.ultradns.ws.xml.AttributeHandler;
|
||||
import org.jclouds.ultradns.ws.xml.PoolRecordSpecHandler;
|
||||
import org.jclouds.ultradns.ws.xml.TextHandler;
|
||||
import org.jclouds.ultradns.ws.xml.TrafficControllerPoolListHandler;
|
||||
|
@ -82,6 +83,16 @@ public interface TrafficControllerPoolAsyncApi {
|
|||
ListenableFuture<FluentIterable<TrafficControllerPoolRecord>> listRecords(@PayloadParam("poolId") String poolId)
|
||||
throws ResourceNotFoundException;
|
||||
|
||||
/**
|
||||
* @see TrafficControllerPoolApi#getByDName(String)
|
||||
*/
|
||||
@Named("getPoolForPoolHostName>")
|
||||
@POST
|
||||
@Payload("<v01:getPoolForPoolHostName><hostName>{hostName}</hostName></v01:getPoolForPoolHostName>")
|
||||
@XMLResponseParser(AttributeHandler.PoolName.class)
|
||||
@Fallback(NullOnNotFoundOr404.class)
|
||||
ListenableFuture<String> getNameByDName(@PayloadParam("hostName") String dname);
|
||||
|
||||
/**
|
||||
* @see TrafficControllerPoolApi#delete(String)
|
||||
*/
|
||||
|
|
|
@ -0,0 +1,63 @@
|
|||
/**
|
||||
* 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.cleanseAttributes;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.jclouds.http.functions.ParseSax;
|
||||
import org.xml.sax.Attributes;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public abstract class AttributeHandler extends ParseSax.HandlerForGeneratedRequestWithResult<String> {
|
||||
|
||||
public static class PoolName extends AttributeHandler {
|
||||
public PoolName() {
|
||||
super("PoolName");
|
||||
}
|
||||
}
|
||||
|
||||
private String attributeName;
|
||||
private String attribute = null;
|
||||
|
||||
private AttributeHandler(String attributeName) {
|
||||
this.attributeName = checkNotNull(attributeName, "attributeName");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getResult() {
|
||||
try {
|
||||
return checkNotNull(attribute, "%s not present in the response", attributeName);
|
||||
} finally {
|
||||
attribute = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startElement(String uri, String localName, String qName, Attributes attrs) {
|
||||
Map<String, String> attributes = cleanseAttributes(attrs);
|
||||
if (attribute == null && attributes.containsKey(attributeName)) {
|
||||
attribute = attributes.get(attributeName);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -89,6 +89,27 @@ public class TrafficControllerPoolApiExpectTest extends BaseUltraDNSWSApiExpectT
|
|||
new GetTCPoolRecordsResponseTest().expected().toString());
|
||||
}
|
||||
|
||||
HttpRequest getNameByDName = HttpRequest.builder().method("POST")
|
||||
.endpoint("https://ultra-api.ultradns.com:8443/UltraDNS_WS/v01")
|
||||
.addHeader("Host", "ultra-api.ultradns.com:8443")
|
||||
.payload(payloadFromResourceWithContentType("/get_tcpool_by_dname.xml", "application/xml")).build();
|
||||
|
||||
HttpResponse getNameByDNameResponse = HttpResponse.builder().statusCode(200)
|
||||
.payload(payloadFromResourceWithContentType("/tcpool_name.xml", "application/xml")).build();
|
||||
|
||||
public void testGetNameByDNameWhenResponseIs2xx() {
|
||||
UltraDNSWSApi success = requestSendsResponse(getNameByDName, getNameByDNameResponse);
|
||||
assertEquals(success.getTrafficControllerPoolApiForZone("jclouds.org.").getNameByDName("www.foo.com."), "foo");
|
||||
}
|
||||
|
||||
HttpResponse poolDoesntExist = HttpResponse.builder().message("Server Epoolor").statusCode(500)
|
||||
.payload(payloadFromResource("/lbpool_doesnt_exist.xml")).build();
|
||||
|
||||
public void testGetNameByDNameWhenResponseNotFound() {
|
||||
UltraDNSWSApi notFound = requestSendsResponse(getNameByDName, poolDoesntExist);
|
||||
assertNull(notFound.getTrafficControllerPoolApiForZone("jclouds.org.").getNameByDName("www.foo.com."));
|
||||
}
|
||||
|
||||
HttpRequest delete = HttpRequest.builder().method("POST")
|
||||
.endpoint("https://ultra-api.ultradns.com:8443/UltraDNS_WS/v01")
|
||||
.addHeader("Host", "ultra-api.ultradns.com:8443")
|
||||
|
@ -102,9 +123,6 @@ public class TrafficControllerPoolApiExpectTest extends BaseUltraDNSWSApiExpectT
|
|||
success.getTrafficControllerPoolApiForZone("jclouds.org.").delete("04053D8E57C7931F");
|
||||
}
|
||||
|
||||
HttpResponse poolDoesntExist = HttpResponse.builder().message("Server Epoolor").statusCode(500)
|
||||
.payload(payloadFromResource("/lbpool_doesnt_exist.xml")).build();
|
||||
|
||||
public void testDeleteWhenResponseNotFound() {
|
||||
UltraDNSWSApi notFound = requestSendsResponse(delete, poolDoesntExist);
|
||||
notFound.getTrafficControllerPoolApiForZone("jclouds.org.").delete("04053D8E57C7931F");
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
/**
|
||||
* 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.parse;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
import org.jclouds.http.functions.BaseHandlerTest;
|
||||
import org.jclouds.ultradns.ws.xml.AttributeHandler;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(testName = "GetPoolForPoolHostNameResponseTest")
|
||||
public class GetPoolForPoolHostNameResponseTest extends BaseHandlerTest {
|
||||
|
||||
public void test() {
|
||||
InputStream is = getClass().getResourceAsStream("/tcpool_name.xml");
|
||||
AttributeHandler.PoolName handler = injector.getInstance(AttributeHandler.PoolName.class);
|
||||
assertEquals(factory.create(handler).parse(is), "foo");
|
||||
}
|
||||
}
|
|
@ -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:getPoolForPoolHostName><hostName>www.foo.com.</hostName></v01:getPoolForPoolHostName></soapenv:Body></soapenv:Envelope>
|
|
@ -0,0 +1,10 @@
|
|||
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
|
||||
<soap:Body>
|
||||
<ns1:getPoolForPoolHostNameResponse
|
||||
xmlns:ns1="http://webservice.api.ultra.neustar.com/v01/">
|
||||
<LBPoolData xmlns:ns2="http://schema.ultraservice.neustar.com/v01/">
|
||||
<ns2:PoolData PoolName="foo" PoolType="TC" />
|
||||
</LBPoolData>
|
||||
</ns1:getPoolForPoolHostNameResponse>
|
||||
</soap:Body>
|
||||
</soap:Envelope>
|
Loading…
Reference in New Issue