mirror of https://github.com/apache/jclouds.git
added ability to read the regions available in ultradns
This commit is contained in:
parent
001c2cc91b
commit
d32c449efb
|
@ -22,6 +22,7 @@ import java.io.Closeable;
|
|||
|
||||
import javax.inject.Named;
|
||||
import javax.ws.rs.POST;
|
||||
import java.util.Map;
|
||||
|
||||
import org.jclouds.rest.annotations.Delegate;
|
||||
import org.jclouds.rest.annotations.Payload;
|
||||
|
@ -30,6 +31,7 @@ import org.jclouds.rest.annotations.RequestFilters;
|
|||
import org.jclouds.rest.annotations.VirtualHost;
|
||||
import org.jclouds.rest.annotations.XMLResponseParser;
|
||||
import org.jclouds.ultradns.ws.domain.Account;
|
||||
import org.jclouds.ultradns.ws.domain.Region;
|
||||
import org.jclouds.ultradns.ws.features.ResourceRecordApi;
|
||||
import org.jclouds.ultradns.ws.features.RoundRobinPoolApi;
|
||||
import org.jclouds.ultradns.ws.features.TaskApi;
|
||||
|
@ -58,13 +60,22 @@ public interface UltraDNSWSApi extends Closeable {
|
|||
Account getCurrentAccount();
|
||||
|
||||
/**
|
||||
* Provides synchronous access to Zone features.
|
||||
* Lists the directional regions available in the account.
|
||||
*/
|
||||
@Named("getAvailableRegions")
|
||||
@POST
|
||||
@XMLResponseParser(RegionListHandler.class)
|
||||
@Payload("<v01:getAvailableRegions/>")
|
||||
Map<Integer, Region> getRegionsById();
|
||||
|
||||
/**
|
||||
* Provides access to Zone features.
|
||||
*/
|
||||
@Delegate
|
||||
ZoneApi getZoneApi();
|
||||
|
||||
/**
|
||||
* Provides synchronous access to Resource Record features.
|
||||
* Provides access to Resource Record features.
|
||||
*
|
||||
* @param zoneName
|
||||
* zoneName including a trailing dot
|
||||
|
@ -73,7 +84,7 @@ public interface UltraDNSWSApi extends Closeable {
|
|||
ResourceRecordApi getResourceRecordApiForZone(@PayloadParam("zoneName") String zoneName);
|
||||
|
||||
/**
|
||||
* Provides synchronous access to Round Robin Pool features.
|
||||
* Provides access to Round Robin Pool features.
|
||||
*
|
||||
* @param zoneName
|
||||
* zoneName including a trailing dot
|
||||
|
@ -82,7 +93,7 @@ public interface UltraDNSWSApi extends Closeable {
|
|||
RoundRobinPoolApi getRoundRobinPoolApiForZone(@PayloadParam("zoneName") String zoneName);
|
||||
|
||||
/**
|
||||
* Provides synchronous access to Traffic Controller Pool features.
|
||||
* Provides access to Traffic Controller Pool features.
|
||||
*
|
||||
* @param zoneName
|
||||
* zoneName including a trailing dot
|
||||
|
@ -91,7 +102,7 @@ public interface UltraDNSWSApi extends Closeable {
|
|||
TrafficControllerPoolApi getTrafficControllerPoolApiForZone(@PayloadParam("zoneName") String zoneName);
|
||||
|
||||
/**
|
||||
* Provides synchronous access to Task features.
|
||||
* Provides access to Task features.
|
||||
*/
|
||||
@Delegate
|
||||
TaskApi getTaskApi();
|
||||
|
|
|
@ -0,0 +1,127 @@
|
|||
/**
|
||||
* 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.domain;
|
||||
|
||||
import static com.google.common.base.Objects.equal;
|
||||
import static com.google.common.base.Objects.toStringHelper;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.collect.ForwardingSet;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
/**
|
||||
* A region is a set of territory names.
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class Region extends ForwardingSet<String> {
|
||||
|
||||
private final String name;
|
||||
private final Set<String> territoryNames;
|
||||
|
||||
private Region(String name, Set<String> territoryNames) {
|
||||
this.name = checkNotNull(name, "name");
|
||||
this.territoryNames = checkNotNull(territoryNames, "territoryNames of %s", name);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public Set<String> getTerritoryNames() {
|
||||
return territoryNames;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Set<String> delegate() {
|
||||
return territoryNames;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(name, territoryNames);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null || getClass() != obj.getClass())
|
||||
return false;
|
||||
Region that = Region.class.cast(obj);
|
||||
return equal(this.name, that.name) && equal(this.territoryNames, that.territoryNames);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return toStringHelper("").add("name", name).add("territoryNames", territoryNames).toString();
|
||||
}
|
||||
|
||||
public static Builder builder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
public Builder toBuilder() {
|
||||
return builder().from(this);
|
||||
}
|
||||
|
||||
public final static class Builder {
|
||||
private String name;
|
||||
private ImmutableSet.Builder<String> territoryNames = ImmutableSet.<String> builder();
|
||||
|
||||
/**
|
||||
* @see Region#getName()
|
||||
*/
|
||||
public Builder name(String name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* adds to current territoryNames
|
||||
*
|
||||
* @see Region#getTerritoryNames()
|
||||
*/
|
||||
public Builder addTerritoryName(String territoryName) {
|
||||
this.territoryNames.add(territoryName);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* replaces current territoryNames
|
||||
*
|
||||
* @see Region#getTerritoryNames()
|
||||
*/
|
||||
public Builder territoryNames(Iterable<String> territoryNames) {
|
||||
this.territoryNames = ImmutableSet.<String> builder().addAll(territoryNames);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Region build() {
|
||||
return new Region(name, territoryNames.build());
|
||||
}
|
||||
|
||||
public Builder from(Region in) {
|
||||
return name(in.getName()).territoryNames(in.getTerritoryNames());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,59 @@
|
|||
/**
|
||||
* 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 org.jclouds.util.SaxUtils.cleanseAttributes;
|
||||
import static org.jclouds.util.SaxUtils.equalsOrSuffix;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.jclouds.http.functions.ParseSax;
|
||||
import org.jclouds.ultradns.ws.domain.Region;
|
||||
import org.xml.sax.Attributes;
|
||||
|
||||
import com.google.common.base.Splitter;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableMap.Builder;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class RegionListHandler extends ParseSax.HandlerForGeneratedRequestWithResult<Map<Integer, Region>> {
|
||||
|
||||
private final Builder<Integer, Region> regions = ImmutableMap.<Integer, Region> builder();
|
||||
|
||||
@Override
|
||||
public Map<Integer, Region> getResult() {
|
||||
return regions.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startElement(String url, String name, String qName, Attributes attrs) {
|
||||
if (equalsOrSuffix(qName, "Region")) {
|
||||
Map<String, String> attributes = cleanseAttributes(attrs);
|
||||
int id = Integer.parseInt(attributes.get("RegionID"));
|
||||
Iterable<String> territories = Splitter.on(';').split(attributes.get("TerritoryName"));
|
||||
Region region = Region.builder()
|
||||
.name(attributes.get("RegionName"))
|
||||
.territoryNames(territories).build();
|
||||
regions.put(id, region);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -26,6 +26,7 @@ import org.jclouds.http.HttpRequest;
|
|||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.ultradns.ws.internal.BaseUltraDNSWSApiExpectTest;
|
||||
import org.jclouds.ultradns.ws.parse.GetAccountsListOfUserResponseTest;
|
||||
import org.jclouds.ultradns.ws.parse.GetAvailableRegionsResponseTest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
/**
|
||||
|
@ -50,4 +51,21 @@ public class UltraDNSWSApiExpectTest extends BaseUltraDNSWSApiExpectTest {
|
|||
success.getCurrentAccount().toString(),
|
||||
new GetAccountsListOfUserResponseTest().expected().toString());
|
||||
}
|
||||
|
||||
HttpRequest getRegionsById = HttpRequest.builder().method("POST")
|
||||
.endpoint("https://ultra-api.ultradns.com:8443/UltraDNS_WS/v01")
|
||||
.addHeader("Host", "ultra-api.ultradns.com:8443")
|
||||
.payload(payloadFromResourceWithContentType("/list_regions.xml", "application/xml")).build();
|
||||
|
||||
HttpResponse getRegionsByIdResponse = HttpResponse.builder().statusCode(200)
|
||||
.payload(payloadFromResourceWithContentType("/regions.xml", "application/xml")).build();
|
||||
|
||||
public void testGetRegionsByIdWhenResponseIs2xx() {
|
||||
|
||||
UltraDNSWSApi success = requestSendsResponse(getRegionsById, getRegionsByIdResponse);
|
||||
|
||||
assertEquals(
|
||||
success.getRegionsById().toString(),
|
||||
new GetAvailableRegionsResponseTest().expected().toString());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,9 +18,14 @@
|
|||
*/
|
||||
package org.jclouds.ultradns.ws;
|
||||
|
||||
import static org.testng.Assert.assertFalse;
|
||||
import static org.testng.Assert.assertNotNull;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.jclouds.ultradns.ws.domain.Account;
|
||||
import org.jclouds.ultradns.ws.domain.Region;
|
||||
import org.jclouds.ultradns.ws.internal.BaseUltraDNSWSApiLiveTest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
|
@ -40,4 +45,18 @@ public class UltraDNSWSApiLiveTest extends BaseUltraDNSWSApiLiveTest {
|
|||
assertNotNull(account.getId(), "Id cannot be null for " + account);
|
||||
assertNotNull(account.getName(), "Name cannot be null for " + account);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testListRegions() {
|
||||
for (Entry<Integer, Region> region : api.getRegionsById().entrySet()) {
|
||||
checkRegion(region);
|
||||
}
|
||||
}
|
||||
|
||||
private void checkRegion(Entry<Integer, Region> region) {
|
||||
assertTrue(region.getKey() > 0, "Id cannot be negative " + region);
|
||||
assertNotNull(region.getValue().getName(), "Name cannot be null " + region);
|
||||
assertNotNull(region.getValue().getTerritoryNames(), "TerritoryNames cannot be null " + region);
|
||||
assertFalse(region.getValue().getTerritoryNames().isEmpty(), "TerritoryNames cannot be empty " + region);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,65 @@
|
|||
/**
|
||||
* 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 java.util.Map;
|
||||
|
||||
import org.jclouds.http.functions.BaseHandlerTest;
|
||||
import org.jclouds.ultradns.ws.domain.Region;
|
||||
import org.jclouds.ultradns.ws.xml.RegionListHandler;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(testName = "GetAvailableRegionsResponseTest")
|
||||
public class GetAvailableRegionsResponseTest extends BaseHandlerTest {
|
||||
|
||||
public void test() {
|
||||
InputStream is = getClass().getResourceAsStream("/regions.xml");
|
||||
|
||||
Map<Integer, Region> expected = expected();
|
||||
|
||||
RegionListHandler handler = injector.getInstance(RegionListHandler.class);
|
||||
Map<Integer, Region> result = factory.create(handler).parse(is);
|
||||
|
||||
assertEquals(result.toString(), expected.toString());
|
||||
}
|
||||
|
||||
public Map<Integer, Region> expected() {
|
||||
return ImmutableMap.<Integer, Region> builder()
|
||||
.put(14, Region.builder()
|
||||
.name("Anonymous Proxy (A1)")
|
||||
.addTerritoryName("Anonymous Proxy").build())
|
||||
.put(3, Region.builder()
|
||||
.name("Antarctica")
|
||||
.territoryNames(ImmutableSet.<String> builder()
|
||||
.add("Antarctica")
|
||||
.add("Bouvet Island")
|
||||
.add("French Southern Territories").build())
|
||||
.build())
|
||||
.build();
|
||||
}
|
||||
}
|
|
@ -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:getAvailableRegions/></soapenv:Body></soapenv:Envelope>
|
|
@ -0,0 +1,14 @@
|
|||
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
|
||||
<soap:Body>
|
||||
<ns1:getAvailableRegionsResponse
|
||||
xmlns:ns1="http://webservice.api.ultra.neustar.com/v01/">
|
||||
<DirectionalDNSAvailableRegionList
|
||||
xmlns:ns2="http://schema.ultraservice.neustar.com/v01/">
|
||||
<ns2:Region TerritoryName="Anonymous Proxy" RegionName="Anonymous Proxy (A1)"
|
||||
RegionID="14" />
|
||||
<ns2:Region TerritoryName="Antarctica;Bouvet Island;French Southern Territories"
|
||||
RegionName="Antarctica" RegionID="3" />
|
||||
</DirectionalDNSAvailableRegionList>
|
||||
</ns1:getAvailableRegionsResponse>
|
||||
</soap:Body>
|
||||
</soap:Envelope>
|
Loading…
Reference in New Issue