diff --git a/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/UltraDNSWSApi.java b/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/UltraDNSWSApi.java index 24713babca..1ca04b6a42 100644 --- a/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/UltraDNSWSApi.java +++ b/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/UltraDNSWSApi.java @@ -21,9 +21,10 @@ package org.jclouds.ultradns.ws; import org.jclouds.rest.annotations.Delegate; import org.jclouds.rest.annotations.PayloadParam; import org.jclouds.ultradns.ws.domain.Account; -import org.jclouds.ultradns.ws.features.RoundRobinPoolApi; import org.jclouds.ultradns.ws.features.ResourceRecordApi; +import org.jclouds.ultradns.ws.features.RoundRobinPoolApi; import org.jclouds.ultradns.ws.features.TaskApi; +import org.jclouds.ultradns.ws.features.TrafficControllerPoolApi; import org.jclouds.ultradns.ws.features.ZoneApi; /** @@ -64,6 +65,15 @@ public interface UltraDNSWSApi { @Delegate RoundRobinPoolApi getRoundRobinPoolApiForZone(@PayloadParam("zoneName") String zoneName); + /** + * Provides synchronous access to Traffic Controller Pool features. + * + * @param zoneName + * zoneName including a trailing dot + */ + @Delegate + TrafficControllerPoolApi getTrafficControllerPoolApiForZone(@PayloadParam("zoneName") String zoneName); + /** * Provides synchronous access to Task features. */ diff --git a/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/UltraDNSWSAsyncApi.java b/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/UltraDNSWSAsyncApi.java index 4cc800fe81..0dea677ef8 100644 --- a/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/UltraDNSWSAsyncApi.java +++ b/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/UltraDNSWSAsyncApi.java @@ -28,9 +28,10 @@ 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.features.RoundRobinPoolAsyncApi; import org.jclouds.ultradns.ws.features.ResourceRecordAsyncApi; +import org.jclouds.ultradns.ws.features.RoundRobinPoolAsyncApi; import org.jclouds.ultradns.ws.features.TaskAsyncApi; +import org.jclouds.ultradns.ws.features.TrafficControllerPoolAsyncApi; import org.jclouds.ultradns.ws.features.ZoneAsyncApi; import org.jclouds.ultradns.ws.filters.SOAPWrapWithPasswordAuth; import org.jclouds.ultradns.ws.xml.AccountHandler; @@ -82,6 +83,15 @@ public interface UltraDNSWSAsyncApi { @Delegate RoundRobinPoolAsyncApi getRoundRobinPoolApiForZone(@PayloadParam("zoneName") String zoneName); + /** + * Provides asynchronous access to Traffic Controller Pool features. + * + * @param zoneName + * zoneName including a trailing dot + */ + @Delegate + TrafficControllerPoolAsyncApi getTrafficControllerPoolApiForZone(@PayloadParam("zoneName") String zoneName); + /** * Provides asynchronous access to Task features. */ diff --git a/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/config/UltraDNSWSRestClientModule.java b/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/config/UltraDNSWSRestClientModule.java index a3072b34e7..a5aa13b662 100644 --- a/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/config/UltraDNSWSRestClientModule.java +++ b/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/config/UltraDNSWSRestClientModule.java @@ -29,12 +29,14 @@ import org.jclouds.rest.ConfiguresRestClient; import org.jclouds.rest.config.RestClientModule; import org.jclouds.ultradns.ws.UltraDNSWSApi; import org.jclouds.ultradns.ws.UltraDNSWSAsyncApi; -import org.jclouds.ultradns.ws.features.RoundRobinPoolApi; -import org.jclouds.ultradns.ws.features.RoundRobinPoolAsyncApi; import org.jclouds.ultradns.ws.features.ResourceRecordApi; import org.jclouds.ultradns.ws.features.ResourceRecordAsyncApi; +import org.jclouds.ultradns.ws.features.RoundRobinPoolApi; +import org.jclouds.ultradns.ws.features.RoundRobinPoolAsyncApi; import org.jclouds.ultradns.ws.features.TaskApi; import org.jclouds.ultradns.ws.features.TaskAsyncApi; +import org.jclouds.ultradns.ws.features.TrafficControllerPoolApi; +import org.jclouds.ultradns.ws.features.TrafficControllerPoolAsyncApi; import org.jclouds.ultradns.ws.features.ZoneApi; import org.jclouds.ultradns.ws.features.ZoneAsyncApi; import org.jclouds.ultradns.ws.handlers.UltraDNSWSErrorHandler; @@ -53,6 +55,7 @@ public class UltraDNSWSRestClientModule extends RestClientModule list() throws ResourceNotFoundException; +} diff --git a/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/features/TrafficControllerPoolAsyncApi.java b/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/features/TrafficControllerPoolAsyncApi.java new file mode 100644 index 0000000000..7c1a8c5620 --- /dev/null +++ b/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/features/TrafficControllerPoolAsyncApi.java @@ -0,0 +1,54 @@ +/** + * 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.features; + +import javax.inject.Named; +import javax.ws.rs.POST; + +import org.jclouds.rest.ResourceNotFoundException; +import org.jclouds.rest.annotations.Payload; +import org.jclouds.rest.annotations.RequestFilters; +import org.jclouds.rest.annotations.VirtualHost; +import org.jclouds.rest.annotations.XMLResponseParser; +import org.jclouds.ultradns.ws.domain.TrafficControllerPool; +import org.jclouds.ultradns.ws.filters.SOAPWrapWithPasswordAuth; +import org.jclouds.ultradns.ws.xml.TrafficControllerPoolListHandler; + +import com.google.common.collect.FluentIterable; +import com.google.common.util.concurrent.ListenableFuture; + +/** + * @see TrafficControllerPoolApi + * @see + * @see + * @author Adrian Cole + */ +@RequestFilters(SOAPWrapWithPasswordAuth.class) +@VirtualHost +public interface TrafficControllerPoolAsyncApi { + + /** + * @see TrafficControllerPoolApi#list() + */ + @Named("getLoadBalancingPoolsByZone") + @POST + @XMLResponseParser(TrafficControllerPoolListHandler.class) + @Payload("{zoneName}TC") + ListenableFuture> list() throws ResourceNotFoundException; +} diff --git a/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/xml/TrafficControllerPoolHandler.java b/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/xml/TrafficControllerPoolHandler.java new file mode 100644 index 0000000000..afff20ff55 --- /dev/null +++ b/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/xml/TrafficControllerPoolHandler.java @@ -0,0 +1,61 @@ +/** + * 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.TrafficControllerPool; +import org.jclouds.ultradns.ws.domain.TrafficControllerPool.Builder; +import org.xml.sax.Attributes; + +/** + * + * @author Adrian Cole + */ +public class TrafficControllerPoolHandler extends ParseSax.HandlerForGeneratedRequestWithResult { + + private Builder pool = TrafficControllerPool.builder(); + + @Override + public TrafficControllerPool getResult() { + try { + return pool.build(); + } finally { + pool = TrafficControllerPool.builder(); + } + } + + @Override + public void startElement(String uri, String localName, String qName, Attributes attrs) { + Map attributes = cleanseAttributes(attrs); + if (equalsOrSuffix(qName, "LBPoolData")) { + pool.zoneId(attributes.get("zoneid")); + } else if (equalsOrSuffix(qName, "PoolData")) { + pool.id(attributes.get("PoolId")).name(attributes.get("PoolName")).dname(attributes.get("PoolDName")); + pool.statusCode(Integer.parseInt(attributes.get("PoolStatus"))); + pool.failOverEnabled("Enabled".equalsIgnoreCase(attributes.get("FailOver"))); + pool.probingEnabled("Enabled".equalsIgnoreCase(attributes.get("Probing"))); + // MaxActiveServers is always 0 for TC + } + } +} diff --git a/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/xml/TrafficControllerPoolListHandler.java b/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/xml/TrafficControllerPoolListHandler.java new file mode 100644 index 0000000000..49f3655c0f --- /dev/null +++ b/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/xml/TrafficControllerPoolListHandler.java @@ -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.xml; + +import static org.jclouds.util.SaxUtils.equalsOrSuffix; + +import org.jclouds.http.functions.ParseSax; +import org.jclouds.ultradns.ws.domain.TrafficControllerPool; +import org.xml.sax.Attributes; + +import com.google.common.collect.FluentIterable; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.ImmutableSet.Builder; +import com.google.inject.Inject; + +/** + * + * @author Adrian Cole + */ +public class TrafficControllerPoolListHandler extends ParseSax.HandlerForGeneratedRequestWithResult> { + + private final TrafficControllerPoolHandler poolHandler; + + private final Builder pools = ImmutableSet. builder(); + + @Inject + public TrafficControllerPoolListHandler(TrafficControllerPoolHandler poolHandler) { + this.poolHandler = poolHandler; + } + + @Override + public FluentIterable getResult() { + return FluentIterable.from(pools.build()); + } + + @Override + public void startElement(String url, String name, String qName, Attributes attributes) { + if (equalsOrSuffix(qName, "LBPoolData") || equalsOrSuffix(qName, "PoolData")) { + poolHandler.startElement(url, name, qName, attributes); + } + } + + @Override + public void endElement(String uri, String name, String qName) { + if (equalsOrSuffix(qName, "LBPoolData")) { + pools.add(poolHandler.getResult()); + } + } +} diff --git a/providers/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/features/TrafficControllerPoolApiExpectTest.java b/providers/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/features/TrafficControllerPoolApiExpectTest.java new file mode 100644 index 0000000000..e903aa5ca2 --- /dev/null +++ b/providers/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/features/TrafficControllerPoolApiExpectTest.java @@ -0,0 +1,50 @@ +/** + * 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.features; + +import static org.testng.Assert.assertEquals; + +import org.jclouds.http.HttpRequest; +import org.jclouds.http.HttpResponse; +import org.jclouds.ultradns.ws.UltraDNSWSApi; +import org.jclouds.ultradns.ws.internal.BaseUltraDNSWSApiExpectTest; +import org.jclouds.ultradns.ws.parse.GetTCLoadBalancingPoolsByZoneResponseTest; +import org.testng.annotations.Test; + +/** + * @author Adrian Cole + */ +@Test(groups = "unit", testName = "TrafficControllerPoolApiExpectTest") +public class TrafficControllerPoolApiExpectTest extends BaseUltraDNSWSApiExpectTest { + + HttpRequest list = HttpRequest.builder().method("POST") + .endpoint("https://ultra-api.ultradns.com:8443/UltraDNS_WS/v01") + .addHeader("Host", "ultra-api.ultradns.com:8443") + .payload(payloadFromResourceWithContentType("/list_tcpools.xml", "application/xml")).build(); + + HttpResponse listResponse = HttpResponse.builder().statusCode(200) + .payload(payloadFromResourceWithContentType("/tcpools.xml", "application/xml")).build(); + + public void testListWhenResponseIs2xx() { + UltraDNSWSApi success = requestSendsResponse(list, listResponse); + + assertEquals(success.getTrafficControllerPoolApiForZone("jclouds.org.").list().toString(), + new GetTCLoadBalancingPoolsByZoneResponseTest().expected().toString()); + } +} diff --git a/providers/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/features/TrafficControllerPoolApiLiveTest.java b/providers/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/features/TrafficControllerPoolApiLiveTest.java new file mode 100644 index 0000000000..fd3358f89d --- /dev/null +++ b/providers/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/features/TrafficControllerPoolApiLiveTest.java @@ -0,0 +1,70 @@ +/** + * 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 WATCANTIES 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.features; + +import static com.google.common.base.Preconditions.checkNotNull; + +import org.jclouds.rest.ResourceNotFoundException; +import org.jclouds.ultradns.ws.domain.Account; +import org.jclouds.ultradns.ws.domain.TrafficControllerPool; +import org.jclouds.ultradns.ws.domain.Zone; +import org.jclouds.ultradns.ws.internal.BaseUltraDNSWSApiLiveTest; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * @author Adrian Cole + */ +@Test(groups = "live", singleThreaded = true, testName = "TrafficControllerPoolApiLiveTest") +public class TrafficControllerPoolApiLiveTest extends BaseUltraDNSWSApiLiveTest { + + private Account account; + + @Override + @BeforeClass(groups = { "integration", "live" }) + public void setupContext() { + super.setupContext(); + account = context.getApi().getCurrentAccount(); + } + + private void checkTCPool(TrafficControllerPool pool) { + checkNotNull(pool.getZoneId(), "ZoneId cannot be null for a TrafficControllerPool %s", pool); + checkNotNull(pool.getId(), "Id cannot be null for a TrafficControllerPool %s", pool); + checkNotNull(pool.getName(), "Name cannot be null for a TrafficControllerPool %s", pool); + checkNotNull(pool.getDName(), "DName cannot be null for a TrafficControllerPool %s", pool); + } + + @Test + public void testListTCPools() { + for (Zone zone : context.getApi().getZoneApi().listByAccount(account.getId())) { + for (TrafficControllerPool pool : api(zone.getName()).list()) { + checkTCPool(pool); + } + } + } + + @Test(expectedExceptions = ResourceNotFoundException.class, expectedExceptionsMessageRegExp = "Zone does not exist in the system.") + public void testListTCPoolsWhenZoneIdNotFound() { + api("AAAAAAAAAAAAAAAA").list(); + } + + private TrafficControllerPoolApi api(String zoneName) { + return context.getApi().getTrafficControllerPoolApiForZone(zoneName); + } +} diff --git a/providers/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/parse/GetTCLoadBalancingPoolsByZoneResponseTest.java b/providers/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/parse/GetTCLoadBalancingPoolsByZoneResponseTest.java new file mode 100644 index 0000000000..c808c76b66 --- /dev/null +++ b/providers/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/parse/GetTCLoadBalancingPoolsByZoneResponseTest.java @@ -0,0 +1,61 @@ +/** + * 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 WATCANTIES 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.domain.TrafficControllerPool; +import org.jclouds.ultradns.ws.xml.TrafficControllerPoolListHandler; +import org.testng.annotations.Test; + +import com.google.common.collect.FluentIterable; +import com.google.common.collect.ImmutableList; + +/** + * @author Adrian Cole + */ +@Test(testName = "GetTCLoadBalancingPoolsByZoneResponseTest") +public class GetTCLoadBalancingPoolsByZoneResponseTest extends BaseHandlerTest { + + public void test() { + InputStream is = getClass().getResourceAsStream("/tcpools.xml"); + + FluentIterable expected = expected(); + + TrafficControllerPoolListHandler handler = injector.getInstance(TrafficControllerPoolListHandler.class); + FluentIterable result = factory.create(handler).parse(is); + + assertEquals(result.toSet().toString(), expected.toSet().toString()); + } + + public FluentIterable expected() { + return FluentIterable.from(ImmutableList. builder() + .add(TrafficControllerPool.builder() + .zoneId("0000000000000001") + .id("000000000000002") + .name("us-west-1c.discovery.jclouds.org.") + .dname("us-west-1c.discovery.jclouds.org.") + .statusCode(1) + .failOverEnabled(true) + .probingEnabled(true).build()).build()); + } +} \ No newline at end of file diff --git a/providers/ultradns-ws/src/test/resources/list_tcpools.xml b/providers/ultradns-ws/src/test/resources/list_tcpools.xml new file mode 100644 index 0000000000..541aeedc4c --- /dev/null +++ b/providers/ultradns-ws/src/test/resources/list_tcpools.xml @@ -0,0 +1 @@ +identitycredentialjclouds.org.TC \ No newline at end of file diff --git a/providers/ultradns-ws/src/test/resources/tcpools.xml b/providers/ultradns-ws/src/test/resources/tcpools.xml new file mode 100644 index 0000000000..69199637e4 --- /dev/null +++ b/providers/ultradns-ws/src/test/resources/tcpools.xml @@ -0,0 +1,15 @@ + + + + + + + + + + +