From 2830c0bca9d5512b05d5192d29e2bb01eeb0eabd Mon Sep 17 00:00:00 2001 From: adriancole Date: Thu, 7 Mar 2013 14:08:01 -0800 Subject: [PATCH] added Round Robin Pool features to UltraDNS --- .../jclouds/ultradns/ws/UltraDNSWSApi.java | 6 +- .../ultradns/ws/UltraDNSWSAsyncApi.java | 6 +- .../ws/config/UltraDNSWSRestClientModule.java | 6 +- .../ultradns/ws/domain/PoolRecord.java | 168 ------------ .../{LBPool.java => RoundRobinPool.java} | 79 ++---- .../ultradns/ws/features/LBPoolApi.java | 66 ----- .../ultradns/ws/features/LBPoolAsyncApi.java | 88 ------ .../ws/features/ResourceRecordApi.java | 2 +- .../ws/features/RoundRobinPoolApi.java | 146 ++++++++++ .../ws/features/RoundRobinPoolAsyncApi.java | 143 ++++++++++ .../ws/handlers/UltraDNSWSErrorHandler.java | 2 + .../ultradns/ws/xml/PoolRecordHandler.java | 59 ----- ...dListHandler.java => RRPoolIDHandler.java} | 41 ++- ...andler.java => RoundRobinPoolHandler.java} | 18 +- ...er.java => RoundRobinPoolListHandler.java} | 12 +- .../ws/features/LBPoolApiLiveTest.java | 103 -------- .../features/ResourceRecordApiLiveTest.java | 14 +- ....java => RoundRobinPoolApiExpectTest.java} | 66 +++-- .../features/RoundRobinPoolApiLiveTest.java | 250 ++++++++++++++++++ .../handlers/UltraDNSWSErrorHandlerTest.java | 45 ++++ ...tLoadBalancingPoolsByZoneResponseTest.java | 37 +-- .../ws/parse/GetPoolRecordsResponseTest.java | 65 ----- .../{list_lbpools.xml => create_rrpool_a.xml} | 2 +- .../src/test/resources/create_rrpool_aaaa.xml | 1 + .../test/resources/lbpool_already_exists.xml | 1 + .../test/resources/lbpool_doesnt_exist.xml | 2 +- ...t_lbpools_by_type.xml => list_rrpools.xml} | 2 +- ...ist_poolrecords.xml => list_rrrecords.xml} | 2 +- .../src/test/resources/poolrecords.xml | 18 -- .../src/test/resources/rrpool_created.xml | 5 + .../resources/{lbpools.xml => rrpools.xml} | 6 - 31 files changed, 724 insertions(+), 737 deletions(-) delete mode 100644 labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/domain/PoolRecord.java rename labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/domain/{LBPool.java => RoundRobinPool.java} (58%) delete mode 100644 labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/features/LBPoolApi.java delete mode 100644 labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/features/LBPoolAsyncApi.java create mode 100644 labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/features/RoundRobinPoolApi.java create mode 100644 labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/features/RoundRobinPoolAsyncApi.java delete mode 100644 labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/xml/PoolRecordHandler.java rename labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/xml/{PoolRecordListHandler.java => RRPoolIDHandler.java} (57%) rename labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/xml/{LBPoolHandler.java => RoundRobinPoolHandler.java} (72%) rename labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/xml/{LBPoolListHandler.java => RoundRobinPoolListHandler.java} (79%) delete mode 100644 labs/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/features/LBPoolApiLiveTest.java rename labs/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/features/{LBPoolApiExpectTest.java => RoundRobinPoolApiExpectTest.java} (55%) create mode 100644 labs/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/features/RoundRobinPoolApiLiveTest.java delete mode 100644 labs/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/parse/GetPoolRecordsResponseTest.java rename labs/ultradns-ws/src/test/resources/{list_lbpools.xml => create_rrpool_a.xml} (65%) create mode 100644 labs/ultradns-ws/src/test/resources/create_rrpool_aaaa.xml create mode 100644 labs/ultradns-ws/src/test/resources/lbpool_already_exists.xml rename labs/ultradns-ws/src/test/resources/{list_lbpools_by_type.xml => list_rrpools.xml} (91%) rename labs/ultradns-ws/src/test/resources/{list_poolrecords.xml => list_rrrecords.xml} (76%) delete mode 100644 labs/ultradns-ws/src/test/resources/poolrecords.xml create mode 100644 labs/ultradns-ws/src/test/resources/rrpool_created.xml rename labs/ultradns-ws/src/test/resources/{lbpools.xml => rrpools.xml} (77%) diff --git a/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/UltraDNSWSApi.java b/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/UltraDNSWSApi.java index a7009d7b9e..24713babca 100644 --- a/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/UltraDNSWSApi.java +++ b/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/UltraDNSWSApi.java @@ -21,7 +21,7 @@ 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.LBPoolApi; +import org.jclouds.ultradns.ws.features.RoundRobinPoolApi; import org.jclouds.ultradns.ws.features.ResourceRecordApi; import org.jclouds.ultradns.ws.features.TaskApi; import org.jclouds.ultradns.ws.features.ZoneApi; @@ -56,13 +56,13 @@ public interface UltraDNSWSApi { ResourceRecordApi getResourceRecordApiForZone(@PayloadParam("zoneName") String zoneName); /** - * Provides synchronous access to Load Balancing Pool features. + * Provides synchronous access to Round Robin Pool features. * * @param zoneName * zoneName including a trailing dot */ @Delegate - LBPoolApi getLBPoolApiForZone(@PayloadParam("zoneName") String zoneName); + RoundRobinPoolApi getRoundRobinPoolApiForZone(@PayloadParam("zoneName") String zoneName); /** * Provides synchronous access to Task features. diff --git a/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/UltraDNSWSAsyncApi.java b/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/UltraDNSWSAsyncApi.java index 5977a2544e..4cc800fe81 100644 --- a/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/UltraDNSWSAsyncApi.java +++ b/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/UltraDNSWSAsyncApi.java @@ -28,7 +28,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.features.LBPoolAsyncApi; +import org.jclouds.ultradns.ws.features.RoundRobinPoolAsyncApi; import org.jclouds.ultradns.ws.features.ResourceRecordAsyncApi; import org.jclouds.ultradns.ws.features.TaskAsyncApi; import org.jclouds.ultradns.ws.features.ZoneAsyncApi; @@ -74,13 +74,13 @@ public interface UltraDNSWSAsyncApi { ResourceRecordAsyncApi getResourceRecordApiForZone(@PayloadParam("zoneName") String zoneName); /** - * Provides asynchronous access to Load Balancing Pool features. + * Provides asynchronous access to Round Robin Pool features. * * @param zoneName * zoneName including a trailing dot */ @Delegate - LBPoolAsyncApi getLBPoolApiForZone(@PayloadParam("zoneName") String zoneName); + RoundRobinPoolAsyncApi getRoundRobinPoolApiForZone(@PayloadParam("zoneName") String zoneName); /** * Provides asynchronous access to Task features. diff --git a/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/config/UltraDNSWSRestClientModule.java b/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/config/UltraDNSWSRestClientModule.java index 56dea55dbc..a3072b34e7 100644 --- a/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/config/UltraDNSWSRestClientModule.java +++ b/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/config/UltraDNSWSRestClientModule.java @@ -29,8 +29,8 @@ 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.LBPoolApi; -import org.jclouds.ultradns.ws.features.LBPoolAsyncApi; +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.TaskApi; @@ -52,7 +52,7 @@ public class UltraDNSWSRestClientModule extends RestClientModule, Class> DELEGATE_MAP = ImmutableMap., Class> builder() .put(ZoneApi.class, ZoneAsyncApi.class) .put(ResourceRecordApi.class, ResourceRecordAsyncApi.class) - .put(LBPoolApi.class, LBPoolAsyncApi.class) + .put(RoundRobinPoolApi.class, RoundRobinPoolAsyncApi.class) .put(TaskApi.class, TaskAsyncApi.class).build(); public UltraDNSWSRestClientModule() { diff --git a/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/domain/PoolRecord.java b/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/domain/PoolRecord.java deleted file mode 100644 index fe2a6058de..0000000000 --- a/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/domain/PoolRecord.java +++ /dev/null @@ -1,168 +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.domain; - -import static com.google.common.base.Preconditions.checkNotNull; - -import com.google.common.base.Objects; - -/** - * - * @author Adrian Cole - */ -public final class PoolRecord { - - private final String poolId; - private final String id; - private final String description; - private final String type; - private final String pointsTo; - - private PoolRecord(String poolId, String id, String description, String type, String pointsTo) { - this.poolId = checkNotNull(poolId, "poolId"); - this.id = checkNotNull(id, "id"); - this.description = checkNotNull(description, "description for %s", id); - this.type = checkNotNull(type, "type for %s", description); - this.pointsTo = checkNotNull(pointsTo, "pointsTo for %s", description); - } - - /** - * The ID of the pool. - */ - public String getPoolId() { - return poolId; - } - - /** - * The ID of the record. - */ - public String getId() { - return id; - } - - /** - * The description of the record. ex. {@code SiteBacker pool via API} - */ - public String getDescription() { - return description; - } - - /** - * The type of the record ex. ex. {@code A} - */ - public String getType() { - return type; - } - - /** - * What the record points to ex. {@code 172.16.8.1} - */ - public String getPointsTo() { - return pointsTo; - } - - @Override - public int hashCode() { - return Objects.hashCode(poolId, id, description, type, pointsTo); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - PoolRecord that = PoolRecord.class.cast(obj); - return Objects.equal(this.poolId, that.poolId) && Objects.equal(this.id, that.id) - && Objects.equal(this.description, that.description) && Objects.equal(this.type, that.type) - && Objects.equal(this.pointsTo, that.pointsTo); - } - - @Override - public String toString() { - return Objects.toStringHelper(this).omitNullValues().add("poolId", poolId).add("id", id).add("description", description) - .add("type", type).add("pointsTo", pointsTo).toString(); - } - - public static Builder builder() { - return new Builder(); - } - - public Builder toBuilder() { - return builder().from(this); - } - - public final static class Builder { - private String poolId; - private String id; - private String description; - private String type; - private String pointsTo; - - /** - * @see PoolRecord#getPoolId() - */ - public Builder poolId(String poolId) { - this.poolId = poolId; - return this; - } - - /** - * @see PoolRecord#getId() - */ - public Builder id(String id) { - this.id = id; - return this; - } - - /** - * @see PoolRecord#getDescription() - */ - public Builder description(String description) { - this.description = description; - return this; - } - - /** - * @see PoolRecord#getType() - */ - public Builder type(String type) { - this.type = type; - return this; - } - - /** - * @see PoolRecord#getPointsTo() - */ - public Builder pointsTo(String pointsTo) { - this.pointsTo = pointsTo; - return this; - } - - public PoolRecord build() { - return new PoolRecord(poolId, id, description, type, pointsTo); - } - - public Builder from(PoolRecord in) { - return this.poolId(in.poolId).id(in.id).description(in.description).type(in.type).pointsTo(in.pointsTo); - } - } -} diff --git a/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/domain/LBPool.java b/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/domain/RoundRobinPool.java similarity index 58% rename from labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/domain/LBPool.java rename to labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/domain/RoundRobinPool.java index 65aca2ac7d..1c79d6090b 100644 --- a/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/domain/LBPool.java +++ b/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/domain/RoundRobinPool.java @@ -21,26 +21,23 @@ package org.jclouds.ultradns.ws.domain; import static com.google.common.base.Preconditions.checkNotNull; import com.google.common.base.Objects; -import com.google.common.base.Optional; /** * * @author Adrian Cole */ -public final class LBPool { +public final class RoundRobinPool { private final String zoneId; private final String id; private final String name; - private final Type type; - private final Optional responseMethod; + private final String dname; - private LBPool(String zoneId, String id, String name, Type type, Optional responseMethod) { + private RoundRobinPool(String zoneId, String id, String name, String dname) { this.zoneId = checkNotNull(zoneId, "zoneId"); this.id = checkNotNull(id, "id"); this.name = checkNotNull(name, "name for %s", id); - this.type = checkNotNull(type, "type for %s", name); - this.responseMethod = checkNotNull(responseMethod, "responseMethod for %s", name); + this.dname = checkNotNull(dname, "dname for %s", id); } /** @@ -58,29 +55,22 @@ public final class LBPool { } /** - * The name of the pool. ex. {@code jclouds.org.} + * The name of the pool. ex. {@code My Pool} */ public String getName() { return name; } /** - * The type of the pool + * The dname of the pool. ex. {@code jclouds.org.} */ - public Type getType() { - return type; - } - - /** - * The response method - */ - public Optional getResponseMethod() { - return responseMethod; + public String getDName() { + return dname; } @Override public int hashCode() { - return Objects.hashCode(zoneId, id, name, type, responseMethod); + return Objects.hashCode(zoneId, id, name, dname); } @Override @@ -91,29 +81,15 @@ public final class LBPool { return false; if (getClass() != obj.getClass()) return false; - LBPool that = LBPool.class.cast(obj); + RoundRobinPool that = RoundRobinPool.class.cast(obj); return Objects.equal(this.zoneId, that.zoneId) && Objects.equal(this.id, that.id) - && Objects.equal(this.name, that.name) && Objects.equal(this.type, that.type) - && Objects.equal(this.responseMethod, that.responseMethod); + && Objects.equal(this.name, that.name) && Objects.equal(this.dname, that.dname); } @Override public String toString() { return Objects.toStringHelper(this).omitNullValues().add("zoneId", zoneId).add("id", id).add("name", name) - .add("type", type).add("responseMethod", responseMethod.orNull()).toString(); - } - - public static enum Type { - - RD, RR, SB, TC, UNRECOGNIZED; - - public static Type fromValue(String type) { - try { - return valueOf(checkNotNull(type, "type")); - } catch (IllegalArgumentException e) { - return UNRECOGNIZED; - } - } + .add("dname", dname).toString(); } public static Builder builder() { @@ -128,11 +104,10 @@ public final class LBPool { private String zoneId; private String id; private String name; - private Type type; - private Optional responseMethod = Optional.absent(); + private String dname; /** - * @see LBPool#getZoneId() + * @see RoundRobinPool#getZoneId() */ public Builder zoneId(String zoneId) { this.zoneId = zoneId; @@ -140,7 +115,7 @@ public final class LBPool { } /** - * @see LBPool#getId() + * @see RoundRobinPool#getId() */ public Builder id(String id) { this.id = id; @@ -148,7 +123,7 @@ public final class LBPool { } /** - * @see LBPool#getName() + * @see RoundRobinPool#getName() */ public Builder name(String name) { this.name = name; @@ -156,27 +131,19 @@ public final class LBPool { } /** - * @see LBPool#getType() + * @see RoundRobinPool#getDName() */ - public Builder type(Type type) { - this.type = type; + public Builder dname(String dname) { + this.dname = dname; return this; } - /** - * @see LBPool#getResponseMethod() - */ - public Builder responseMethod(Type responseMethod) { - this.responseMethod = Optional.fromNullable(responseMethod); - return this; + public RoundRobinPool build() { + return new RoundRobinPool(zoneId, id, name, dname); } - public LBPool build() { - return new LBPool(zoneId, id, name, type, responseMethod); - } - - public Builder from(LBPool in) { - return this.zoneId(in.zoneId).id(in.id).name(in.name).type(in.type).responseMethod(in.responseMethod.orNull()); + public Builder from(RoundRobinPool in) { + return this.zoneId(in.zoneId).id(in.id).name(in.name).dname(in.dname); } } } diff --git a/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/features/LBPoolApi.java b/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/features/LBPoolApi.java deleted file mode 100644 index 50c0072e87..0000000000 --- a/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/features/LBPoolApi.java +++ /dev/null @@ -1,66 +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.features; - -import org.jclouds.rest.ResourceNotFoundException; -import org.jclouds.ultradns.ws.domain.LBPool; -import org.jclouds.ultradns.ws.domain.LBPool.Type; -import org.jclouds.ultradns.ws.domain.PoolRecord; - -import com.google.common.collect.FluentIterable; - -/** - * @see LBPoolAsyncApi - * @author Adrian Cole - */ -public interface LBPoolApi { - - /** - * Returns all pools in the zone. - * - * @throws ResourceNotFoundException - * if the zone doesn't exist - */ - FluentIterable list() throws ResourceNotFoundException; - - /** - * Returns all records in the pool. - * - * @throws ResourceNotFoundException - * if the pool doesn't exist - */ - FluentIterable listRecords(String poolId) throws ResourceNotFoundException; - - /** - * Returns all pools with the specified {@link LBPool#getType()} - * - * @param type - * the {@link LBPool#getType() type} - * @throws ResourceNotFoundException - * if the zone doesn't exist - */ - FluentIterable listByType(Type type) throws ResourceNotFoundException; - - /** - * removes a pool and all its records and probes - * - * @param id the {@link LBPool#getId() id} - */ - void delete(String id); -} diff --git a/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/features/LBPoolAsyncApi.java b/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/features/LBPoolAsyncApi.java deleted file mode 100644 index cbc5d43c39..0000000000 --- a/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/features/LBPoolAsyncApi.java +++ /dev/null @@ -1,88 +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.features; - -import javax.inject.Named; -import javax.ws.rs.POST; - -import org.jclouds.Fallbacks.VoidOnNotFoundOr404; -import org.jclouds.rest.ResourceNotFoundException; -import org.jclouds.rest.annotations.Fallback; -import org.jclouds.rest.annotations.Payload; -import org.jclouds.rest.annotations.PayloadParam; -import org.jclouds.rest.annotations.RequestFilters; -import org.jclouds.rest.annotations.VirtualHost; -import org.jclouds.rest.annotations.XMLResponseParser; -import org.jclouds.ultradns.ws.domain.LBPool; -import org.jclouds.ultradns.ws.domain.LBPool.Type; -import org.jclouds.ultradns.ws.domain.PoolRecord; -import org.jclouds.ultradns.ws.filters.SOAPWrapWithPasswordAuth; -import org.jclouds.ultradns.ws.xml.LBPoolListHandler; -import org.jclouds.ultradns.ws.xml.PoolRecordListHandler; - -import com.google.common.collect.FluentIterable; -import com.google.common.util.concurrent.ListenableFuture; - -/** - * @see LBPoolApi - * @see - * @see - * @author Adrian Cole - */ -@RequestFilters(SOAPWrapWithPasswordAuth.class) -@VirtualHost -public interface LBPoolAsyncApi { - - /** - * @see LBPoolApi#list() - */ - @Named("getLoadBalancingPoolsByZone") - @POST - @XMLResponseParser(LBPoolListHandler.class) - @Payload("{zoneName}all") - ListenableFuture> list() throws ResourceNotFoundException; - - /** - * @see LBPoolApi#listRecords(String) - */ - @Named("getPoolRecords") - @POST - @XMLResponseParser(PoolRecordListHandler.class) - @Payload("{poolId}") - ListenableFuture> listRecords(@PayloadParam("poolId") String poolId) throws ResourceNotFoundException; - - /** - * @see LBPoolApi#listByType(String) - */ - @Named("getLoadBalancingPoolsByZone") - @POST - @XMLResponseParser(LBPoolListHandler.class) - @Payload("{zoneName}{type}") - ListenableFuture> listByType(@PayloadParam("type") Type type) - throws ResourceNotFoundException; - - /** - * @see LBPoolApi#delete(String) - */ - @Named("deleteLBPool") - @POST - @Payload("{lbPoolID}Yes") - @Fallback(VoidOnNotFoundOr404.class) - ListenableFuture delete(@PayloadParam("lbPoolID") String id); -} diff --git a/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/features/ResourceRecordApi.java b/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/features/ResourceRecordApi.java index 14de0435be..fd78949bf5 100644 --- a/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/features/ResourceRecordApi.java +++ b/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/features/ResourceRecordApi.java @@ -107,7 +107,7 @@ public interface ResourceRecordApi { throws ResourceNotFoundException; /** - * deletes a specific resource record/ + * deletes a specific resource record * * @param guid * the global unique identifier for the resource record {@see diff --git a/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/features/RoundRobinPoolApi.java b/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/features/RoundRobinPoolApi.java new file mode 100644 index 0000000000..7cba3e8f43 --- /dev/null +++ b/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/features/RoundRobinPoolApi.java @@ -0,0 +1,146 @@ +/** + * 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 org.jclouds.rest.ResourceNotFoundException; +import org.jclouds.ultradns.ws.UltraDNSWSExceptions.ResourceAlreadyExistsException; +import org.jclouds.ultradns.ws.domain.ResourceRecord; +import org.jclouds.ultradns.ws.domain.ResourceRecordMetadata; +import org.jclouds.ultradns.ws.domain.RoundRobinPool; + +import com.google.common.collect.FluentIterable; +import com.google.common.primitives.UnsignedInteger; + +/** + * @see RoundRobinPoolAsyncApi + * @author Adrian Cole + */ +public interface RoundRobinPoolApi { + /** + * creates a round robin pool for {@code A} (ipv4) records + * + * @param name + * {@link RoundRobinPool#getName() name} of the RR pool + * @param hostname + * {@link RoundRobinPool#getDName() dname} of the RR 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 createAPoolForHostname(String name, String hostname) throws ResourceAlreadyExistsException; + + /** + * adds a new {@code A} record to the pool + * + * @param lbPoolID + * the pool to add the record to. + * @param ipv4Address + * the ipv4 address + * @param ttl + * the {@link ResourceRecord#getTTL ttl} of the record + * @return the {@code guid} of the new record + * @throws ResourceAlreadyExistsException + * if a record already exists with the same attrs + */ + String addARecordWithAddressAndTTL(String lbPoolID, String ipv4Address, UnsignedInteger ttl) + throws ResourceAlreadyExistsException; + + /** + * creates a round robin pool for {@code AAAA} (ipv6) records + * + * @param name + * {@link RoundRobinPool#getName() name} of the RR pool + * @param hostname + * {@link RoundRobinPool#getDName() hostname} {ex. + * www.jclouds.org.} + * @return the {@code guid} of the new record + * @throws ResourceAlreadyExistsException + * if a pool already exists with the same attrs + */ + String createAAAAPoolForHostname(String name, String hostname) throws ResourceAlreadyExistsException; + + /** + * adds a new {@code AAAA} record to the pool + * + * @param lbPoolID + * the pool to add the record to. + * @param ipv6Address + * the ipv6 address + * @param ttl + * the {@link ResourceRecord#getTTL ttl} of the record + * @return the {@code guid} of the new record + * @throws ResourceAlreadyExistsException + * if a record already exists with the same attrs + */ + String addAAAARecordWithAddressAndTTL(String lbPoolID, String ipv6Address, UnsignedInteger ttl) + throws ResourceAlreadyExistsException; + + /** + * updates an existing A or AAAA record in the pool. + * + * @param lbPoolID + * the pool to add the record to. + * @param guid + * the global unique identifier for the resource record {@see + * ResourceRecordMetadata#getGuid()} + * @param address + * the ipv4 or ipv6 address + * @param ttl + * the {@link ResourceRecord#getTTL ttl} of the record + * + * @throws ResourceNotFoundException + * if the guid doesn't exist + */ + void updateRecordWithAddressAndTTL(String lbPoolID, String guid, String address, UnsignedInteger ttl) + throws ResourceNotFoundException; + + /** + * Returns all round robin pools in the zone. + * + * @throws ResourceNotFoundException + * if the zone doesn't exist + */ + FluentIterable list() throws ResourceNotFoundException; + + /** + * Returns all records in the round robin pool. + * + * @throws ResourceNotFoundException + * if the pool doesn't exist + */ + FluentIterable listRecords(String poolId) throws ResourceNotFoundException; + + /** + * deletes a specific pooled resource record + * + * @param guid + * the global unique identifier for the resource record {@see + * ResourceRecordMetadata#getGuid()} + */ + void deleteRecord(String guid); + + /** + * removes a pool and all its records and probes + * + * @param id + * the {@link RoundRobinPool#getId() id} + */ + void delete(String id); +} diff --git a/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/features/RoundRobinPoolAsyncApi.java b/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/features/RoundRobinPoolAsyncApi.java new file mode 100644 index 0000000000..795392eccc --- /dev/null +++ b/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/features/RoundRobinPoolAsyncApi.java @@ -0,0 +1,143 @@ +/** + * 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.Fallbacks.VoidOnNotFoundOr404; +import org.jclouds.rest.ResourceNotFoundException; +import org.jclouds.rest.annotations.Fallback; +import org.jclouds.rest.annotations.Payload; +import org.jclouds.rest.annotations.PayloadParam; +import org.jclouds.rest.annotations.RequestFilters; +import org.jclouds.rest.annotations.VirtualHost; +import org.jclouds.rest.annotations.XMLResponseParser; +import org.jclouds.ultradns.ws.UltraDNSWSExceptions.ResourceAlreadyExistsException; +import org.jclouds.ultradns.ws.domain.ResourceRecord; +import org.jclouds.ultradns.ws.domain.RoundRobinPool; +import org.jclouds.ultradns.ws.filters.SOAPWrapWithPasswordAuth; +import org.jclouds.ultradns.ws.xml.GuidHandler; +import org.jclouds.ultradns.ws.xml.RRPoolIDHandler; +import org.jclouds.ultradns.ws.xml.ResourceRecordListHandler; +import org.jclouds.ultradns.ws.xml.RoundRobinPoolListHandler; + +import com.google.common.collect.FluentIterable; +import com.google.common.primitives.UnsignedInteger; +import com.google.common.util.concurrent.ListenableFuture; + +/** + * @see RoundRobinPoolApi + * @see + * @see + * @author Adrian Cole + */ +@RequestFilters(SOAPWrapWithPasswordAuth.class) +@VirtualHost +public interface RoundRobinPoolAsyncApi { + + /** + * @see RoundRobinPoolApi#list() + */ + @Named("getLoadBalancingPoolsByZone") + @POST + @XMLResponseParser(RoundRobinPoolListHandler.class) + @Payload("{zoneName}RR") + ListenableFuture> list() throws ResourceNotFoundException; + + /** + * @see RoundRobinPoolApi#listRecords(String) + */ + @Named("getRRPoolRecords") + @POST + @XMLResponseParser(ResourceRecordListHandler.class) + @Payload("{poolId}") + ListenableFuture> listRecords(@PayloadParam("poolId") String poolId) + throws ResourceNotFoundException; + + /** + * @see RoundRobinPoolApi#createAPoolForHostname + */ + @Named("addRRLBPool") + @POST + @XMLResponseParser(RRPoolIDHandler.class) + @Payload("{zoneName}{hostName}{description}1") + ListenableFuture createAPoolForHostname(@PayloadParam("description") String name, + @PayloadParam("hostName") String hostname) throws ResourceAlreadyExistsException; + + /** + * @see RoundRobinPoolApi#addARecordWithAddressAndTTL + */ + @Named("addRecordToRRPool") + @POST + @XMLResponseParser(GuidHandler.class) + @Payload("") + ListenableFuture addARecordWithAddressAndTTL(@PayloadParam("lbPoolID") String lbPoolID, + @PayloadParam("address") String ipv4Address, @PayloadParam("ttl") UnsignedInteger ttl) + throws ResourceAlreadyExistsException; + + /** + * @see RoundRobinPoolApi#updateRecordWithAddressAndTTL + */ + @Named("updateRecordOfRRPool") + @POST + @Payload("") + ListenableFuture updateRecordWithAddressAndTTL(@PayloadParam("lbPoolID") String lbPoolID, + @PayloadParam("guid") String guid, @PayloadParam("address") String ipv4Address, + @PayloadParam("ttl") UnsignedInteger ttl) throws ResourceNotFoundException; + + /** + * @see RoundRobinPoolApi#deleteRecord(String) + */ + @Named("deleteRecordOfRRPool") + @POST + @Payload("{guid}") + @Fallback(VoidOnNotFoundOr404.class) + ListenableFuture deleteRecord(@PayloadParam("guid") String guid); + + /** + * @see RoundRobinPoolApi#createAAAAPoolForHostname + */ + @Named("addRRLBPool") + @POST + @XMLResponseParser(RRPoolIDHandler.class) + @Payload("{zoneName}{hostName}{description}28") + ListenableFuture createAAAAPoolForHostname(@PayloadParam("description") String name, + @PayloadParam("hostName") String hostname) throws ResourceAlreadyExistsException; + + /** + * @see RoundRobinPoolApi#addAAAARecordWithAddressAndTTL + */ + @Named("addRecordToRRPool") + @POST + @XMLResponseParser(GuidHandler.class) + @Payload("") + ListenableFuture addAAAARecordWithAddressAndTTL(@PayloadParam("lbPoolID") String lbPoolID, + @PayloadParam("address") String ipv6Address, @PayloadParam("ttl") UnsignedInteger ttl) + throws ResourceAlreadyExistsException; + + /** + * @see RoundRobinPoolApi#delete(String) + */ + @Named("deleteLBPool") + @POST + @Payload("{lbPoolID}Yes") + @Fallback(VoidOnNotFoundOr404.class) + ListenableFuture delete(@PayloadParam("lbPoolID") String id); +} diff --git a/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/handlers/UltraDNSWSErrorHandler.java b/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/handlers/UltraDNSWSErrorHandler.java index 3e3cd7c675..b336591946 100644 --- a/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/handlers/UltraDNSWSErrorHandler.java +++ b/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/handlers/UltraDNSWSErrorHandler.java @@ -80,9 +80,11 @@ public class UltraDNSWSErrorHandler implements HttpErrorHandler { case 1801: case 2103: case 2401: + case 2911: return new ResourceNotFoundException(exception.getError().getDescription(), exception); case 1802: case 2111: + case 2912: return new ResourceAlreadyExistsException(exception.getError().getDescription(), exception); } return exception; diff --git a/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/xml/PoolRecordHandler.java b/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/xml/PoolRecordHandler.java deleted file mode 100644 index 4ee4576581..0000000000 --- a/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/xml/PoolRecordHandler.java +++ /dev/null @@ -1,59 +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 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.PoolRecord; -import org.xml.sax.Attributes; - -/** - * - * @author Adrian Cole - */ -public class PoolRecordHandler extends ParseSax.HandlerForGeneratedRequestWithResult { - - private PoolRecord poolRecord; - - @Override - public PoolRecord getResult() { - try { - return poolRecord; - } finally { - poolRecord = null; - } - } - - @Override - public void startElement(String uri, String localName, String qName, Attributes attrs) { - Map attributes = cleanseAttributes(attrs); - if (equalsOrSuffix(qName, "PoolRecordData")) { - poolRecord = PoolRecord.builder() - .poolId(attributes.get("poolId")) - .id(attributes.get("poolRecordID")) - .description(attributes.get("description")) - .type(attributes.get("recordType")) - .pointsTo(attributes.get("pointsTo")).build(); - } - } -} diff --git a/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/xml/PoolRecordListHandler.java b/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/xml/RRPoolIDHandler.java similarity index 57% rename from labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/xml/PoolRecordListHandler.java rename to labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/xml/RRPoolIDHandler.java index 61c5d1397d..909e591e42 100644 --- a/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/xml/PoolRecordListHandler.java +++ b/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/xml/RRPoolIDHandler.java @@ -18,48 +18,43 @@ */ package org.jclouds.ultradns.ws.xml; +import static org.jclouds.util.SaxUtils.currentOrNull; import static org.jclouds.util.SaxUtils.equalsOrSuffix; import org.jclouds.http.functions.ParseSax; -import org.jclouds.ultradns.ws.domain.PoolRecord; 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 PoolRecordListHandler extends ParseSax.HandlerForGeneratedRequestWithResult> { - - private final PoolRecordHandler zoneHandler; - - private Builder zones = ImmutableSet. builder(); - - @Inject - public PoolRecordListHandler(PoolRecordHandler zoneHandler) { - this.zoneHandler = zoneHandler; - } +public class RRPoolIDHandler extends ParseSax.HandlerForGeneratedRequestWithResult { + private StringBuilder currentText = new StringBuilder(); + private String rrPoolID = null; @Override - public FluentIterable getResult() { - return FluentIterable.from(zones.build()); + public String getResult() { + try { + return rrPoolID; + } finally { + rrPoolID = null; + } } @Override public void startElement(String url, String name, String qName, Attributes attributes) { - if (equalsOrSuffix(qName, "PoolRecordData")) { - zoneHandler.startElement(url, name, qName, attributes); - } } @Override public void endElement(String uri, String name, String qName) { - if (equalsOrSuffix(qName, "PoolRecordData")) { - zones.add(zoneHandler.getResult()); + 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); } } diff --git a/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/xml/LBPoolHandler.java b/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/xml/RoundRobinPoolHandler.java similarity index 72% rename from labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/xml/LBPoolHandler.java rename to labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/xml/RoundRobinPoolHandler.java index d5c8544227..779997af60 100644 --- a/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/xml/LBPoolHandler.java +++ b/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/xml/RoundRobinPoolHandler.java @@ -24,25 +24,24 @@ import static org.jclouds.util.SaxUtils.equalsOrSuffix; import java.util.Map; import org.jclouds.http.functions.ParseSax; -import org.jclouds.ultradns.ws.domain.LBPool; -import org.jclouds.ultradns.ws.domain.LBPool.Builder; -import org.jclouds.ultradns.ws.domain.LBPool.Type; +import org.jclouds.ultradns.ws.domain.RoundRobinPool; +import org.jclouds.ultradns.ws.domain.RoundRobinPool.Builder; import org.xml.sax.Attributes; /** * * @author Adrian Cole */ -public class LBPoolHandler extends ParseSax.HandlerForGeneratedRequestWithResult { +public class RoundRobinPoolHandler extends ParseSax.HandlerForGeneratedRequestWithResult { - private Builder pool = LBPool.builder(); + private Builder pool = RoundRobinPool.builder(); @Override - public LBPool getResult() { + public RoundRobinPool getResult() { try { return pool.build(); } finally { - pool = LBPool.builder(); + pool = RoundRobinPool.builder(); } } @@ -52,10 +51,7 @@ public class LBPoolHandler extends ParseSax.HandlerForGeneratedRequestWithResult if (equalsOrSuffix(qName, "LBPoolData")) { pool.zoneId(attributes.get("zoneid")); } else if (equalsOrSuffix(qName, "PoolData")) { - Type responseMethod = attributes.containsKey("ResponseMethod") ? Type.fromValue(attributes - .get("ResponseMethod")) : null; - pool.id(attributes.get("PoolId")).name(attributes.get("PoolName")) - .type(Type.fromValue(attributes.get("PoolType"))).responseMethod(responseMethod); + pool.id(attributes.get("PoolId")).name(attributes.get("PoolName")).dname(attributes.get("PoolDName")); } } } diff --git a/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/xml/LBPoolListHandler.java b/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/xml/RoundRobinPoolListHandler.java similarity index 79% rename from labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/xml/LBPoolListHandler.java rename to labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/xml/RoundRobinPoolListHandler.java index 540cb8e09f..d49149aace 100644 --- a/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/xml/LBPoolListHandler.java +++ b/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/xml/RoundRobinPoolListHandler.java @@ -21,7 +21,7 @@ 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.LBPool; +import org.jclouds.ultradns.ws.domain.RoundRobinPool; import org.xml.sax.Attributes; import com.google.common.collect.FluentIterable; @@ -33,19 +33,19 @@ import com.google.inject.Inject; * * @author Adrian Cole */ -public class LBPoolListHandler extends ParseSax.HandlerForGeneratedRequestWithResult> { +public class RoundRobinPoolListHandler extends ParseSax.HandlerForGeneratedRequestWithResult> { - private final LBPoolHandler poolHandler; + private final RoundRobinPoolHandler poolHandler; - private Builder pools = ImmutableSet. builder(); + private Builder pools = ImmutableSet. builder(); @Inject - public LBPoolListHandler(LBPoolHandler poolHandler) { + public RoundRobinPoolListHandler(RoundRobinPoolHandler poolHandler) { this.poolHandler = poolHandler; } @Override - public FluentIterable getResult() { + public FluentIterable getResult() { return FluentIterable.from(pools.build()); } diff --git a/labs/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/features/LBPoolApiLiveTest.java b/labs/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/features/LBPoolApiLiveTest.java deleted file mode 100644 index 1ff44081dc..0000000000 --- a/labs/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/features/LBPoolApiLiveTest.java +++ /dev/null @@ -1,103 +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.features; - -import static com.google.common.base.Preconditions.checkNotNull; -import static org.testng.Assert.assertTrue; - -import org.jclouds.rest.ResourceNotFoundException; -import org.jclouds.ultradns.ws.domain.Account; -import org.jclouds.ultradns.ws.domain.LBPool; -import org.jclouds.ultradns.ws.domain.LBPool.Type; -import org.jclouds.ultradns.ws.domain.PoolRecord; -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 = "LBPoolApiLiveTest") -public class LBPoolApiLiveTest extends BaseUltraDNSWSApiLiveTest { - - private Account account; - - @Override - @BeforeClass(groups = { "integration", "live" }) - public void setupContext() { - super.setupContext(); - account = context.getApi().getCurrentAccount(); - } - - private void checkLBPool(LBPool pool) { - checkNotNull(pool.getZoneId(), "ZoneId cannot be null for a LBPool %s", pool); - checkNotNull(pool.getId(), "Id cannot be null for a LBPool %s", pool); - checkNotNull(pool.getName(), "Name cannot be null for a LBPool %s", pool); - checkNotNull(pool.getType(), "Type cannot be null for a LBPool %s", pool); - checkNotNull(pool.getResponseMethod(), "ResponseMethod cannot be null for a LBPool %s", pool); - } - - private void checkPoolRecord(PoolRecord record) { - checkNotNull(record.getPoolId(), "PoolId cannot be null for a PoolRecord %s", record); - checkNotNull(record.getId(), "Id cannot be null for a PoolRecord %s", record); - checkNotNull(record.getDescription(), "Description cannot be null for a PoolRecord %s", record); - checkNotNull(record.getPointsTo(), "PointsTo cannot be null for a PoolRecord %s", record); - checkNotNull(record.getType(), "Type cannot be null for a PoolRecord %s", record); - } - - @Test - public void testListLBPools() { - for (Zone zone : context.getApi().getZoneApi().listByAccount(account.getId())) { - for (LBPool pool : api(zone.getName()).list()) { - checkLBPool(pool); - } - } - } - - @Test - public void testListLBPoolsByType() { - for (Zone zone : context.getApi().getZoneApi().listByAccount(account.getId())) { - for (LBPool pool : api(zone.getName()).list()) { - assertTrue(api(zone.getName()).listByType(pool.getType()).contains(pool)); - break; - } - } - } - - @Test - public void testListLBPoolRecords() { - for (Zone zone : context.getApi().getZoneApi().listByAccount(account.getId())) { - for (LBPool pool : api(zone.getName()).listByType(Type.RR)) { - for (PoolRecord record : api(zone.getName()).listRecords(pool.getId())) { - checkPoolRecord(record); - } - } - } - } - - @Test(expectedExceptions = ResourceNotFoundException.class, expectedExceptionsMessageRegExp = "Zone does not exist in the system.") - public void testListLBPoolsWhenZoneIdNotFound() { - api("AAAAAAAAAAAAAAAA").list(); - } - - private LBPoolApi api(String zoneName) { - return context.getApi().getLBPoolApiForZone(zoneName); - } -} diff --git a/labs/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/features/ResourceRecordApiLiveTest.java b/labs/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/features/ResourceRecordApiLiveTest.java index 73f48733f4..9c72955636 100644 --- a/labs/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/features/ResourceRecordApiLiveTest.java +++ b/labs/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/features/ResourceRecordApiLiveTest.java @@ -74,7 +74,7 @@ public class ResourceRecordApiLiveTest extends BaseUltraDNSWSApiLiveTest { super.tearDownContext(); } - private void checkResourceRecord(ResourceRecord rr) { + static void checkResourceRecord(ResourceRecord rr) { checkNotNull(rr.getName(), "DName cannot be null for a ResourceRecord %s", rr); checkNotNull(rr.getType(), "Type cannot be null for a ResourceRecord %s", rr); assertTrue(rr.getType().intValue() > 0, "Type must be positive for a ResourceRecord " + rr); @@ -83,7 +83,7 @@ public class ResourceRecordApiLiveTest extends BaseUltraDNSWSApiLiveTest { checkNotNull(rr.getRData(), "InfoValues cannot be null for a ResourceRecord %s", rr); } - private void checkResourceRecordMetadata(ResourceRecordMetadata rr) { + static void checkResourceRecordMetadata(ResourceRecordMetadata rr) { checkNotNull(rr.getZoneId(), "ZoneId cannot be null for a ResourceRecordMetadata %s", rr); checkNotNull(rr.getGuid(), "Guid cannot be null for a ResourceRecordMetadata %s", rr); checkNotNull(rr.getZoneName(), "ZoneName cannot be null for a ResourceRecordMetadata %s", rr); @@ -152,7 +152,7 @@ public class ResourceRecordApiLiveTest extends BaseUltraDNSWSApiLiveTest { } catch (ResourceAlreadyExistsException e) { } - assertTrue(listRRs(mx).anyMatch(equalTo(mx))); + assertTrue(listRRs().anyMatch(equalTo(mx))); } @Test(dependsOnMethods = "testCreateRecord") @@ -172,23 +172,23 @@ public class ResourceRecordApiLiveTest extends BaseUltraDNSWSApiLiveTest { public void testUpdateRecord() { mx = mx.toBuilder().ttl(3600).build(); api(zoneName).update(guid, mx); - assertTrue(listRRs(mx).anyMatch(equalTo(mx))); + assertTrue(listRRs().anyMatch(equalTo(mx))); } @Test(dependsOnMethods = "testUpdateRecord") public void testDeleteRecord() { api(zoneName).delete(guid); - assertFalse(listRRs(mx).anyMatch(equalTo(mx))); + assertFalse(listRRs().anyMatch(equalTo(mx))); } - private Function toRecord = new Function() { + static Function toRecord = new Function() { public ResourceRecord apply(ResourceRecordMetadata in) { checkResourceRecordMetadata(in); return in.getRecord(); } }; - private FluentIterable listRRs(ResourceRecord mx) { + private FluentIterable listRRs() { return api(zoneName).list().transform(toRecord); } diff --git a/labs/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/features/LBPoolApiExpectTest.java b/labs/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/features/RoundRobinPoolApiExpectTest.java similarity index 55% rename from labs/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/features/LBPoolApiExpectTest.java rename to labs/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/features/RoundRobinPoolApiExpectTest.java index b771f577d0..8015f66bf2 100644 --- a/labs/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/features/LBPoolApiExpectTest.java +++ b/labs/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/features/RoundRobinPoolApiExpectTest.java @@ -23,61 +23,79 @@ 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.domain.LBPool.Type; +import org.jclouds.ultradns.ws.UltraDNSWSExceptions.ResourceAlreadyExistsException; import org.jclouds.ultradns.ws.internal.BaseUltraDNSWSApiExpectTest; import org.jclouds.ultradns.ws.parse.GetLoadBalancingPoolsByZoneResponseTest; -import org.jclouds.ultradns.ws.parse.GetPoolRecordsResponseTest; +import org.jclouds.ultradns.ws.parse.GetResourceRecordsOfResourceRecordResponseTest; import org.testng.annotations.Test; /** * @author Adrian Cole */ -@Test(groups = "unit", testName = "LBPoolApiExpectTest") -public class LBPoolApiExpectTest extends BaseUltraDNSWSApiExpectTest { +@Test(groups = "unit", testName = "RoundRobinPoolApiExpectTest") +public class RoundRobinPoolApiExpectTest extends BaseUltraDNSWSApiExpectTest { + HttpRequest createA = HttpRequest.builder().method("POST") + .endpoint("https://ultra-api.ultradns.com:8443/UltraDNS_WS/v01") + .addHeader("Host", "ultra-api.ultradns.com:8443") + .payload(payloadFromResourceWithContentType("/create_rrpool_a.xml", "application/xml")).build(); + + HttpRequest createAAAA = HttpRequest.builder().method("POST") + .endpoint("https://ultra-api.ultradns.com:8443/UltraDNS_WS/v01") + .addHeader("Host", "ultra-api.ultradns.com:8443") + .payload(payloadFromResourceWithContentType("/create_rrpool_aaaa.xml", "application/xml")).build(); + + HttpResponse createResponse = HttpResponse.builder().statusCode(200) + .payload(payloadFromResourceWithContentType("/rrpool_created.xml", "application/xml")).build(); + + public void testCreateAWhenResponseIs2xx() { + UltraDNSWSApi success = requestSendsResponse(createA, createResponse); + assertEquals(success.getRoundRobinPoolApiForZone("jclouds.org.").createAPoolForHostname("www.jclouds.org.", "foo"), "060339AA04175655"); + } + + public void testCreateAAAAWhenResponseIs2xx() { + UltraDNSWSApi success = requestSendsResponse(createAAAA, createResponse); + assertEquals(success.getRoundRobinPoolApiForZone("jclouds.org.").createAAAAPoolForHostname("www.jclouds.org.", "foo"), "060339AA04175655"); + } + + 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(createA, alreadyCreated); + already.getRoundRobinPoolApiForZone("jclouds.org.").createAPoolForHostname("www.jclouds.org.", "foo"); + } 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_lbpools.xml", "application/xml")).build(); + .payload(payloadFromResourceWithContentType("/list_rrpools.xml", "application/xml")).build(); HttpResponse listResponse = HttpResponse.builder().statusCode(200) - .payload(payloadFromResourceWithContentType("/lbpools.xml", "application/xml")).build(); + .payload(payloadFromResourceWithContentType("/rrpools.xml", "application/xml")).build(); public void testListWhenResponseIs2xx() { UltraDNSWSApi success = requestSendsResponse(list, listResponse); assertEquals( - success.getLBPoolApiForZone("jclouds.org.").list().toString(), - new GetLoadBalancingPoolsByZoneResponseTest().expected().toString()); - } - - HttpRequest listByType = HttpRequest.builder().method("POST") - .endpoint("https://ultra-api.ultradns.com:8443/UltraDNS_WS/v01") - .addHeader("Host", "ultra-api.ultradns.com:8443") - .payload(payloadFromResourceWithContentType("/list_lbpools_by_type.xml", "application/xml")).build(); - - public void testListByTypeWhenResponseIs2xx() { - UltraDNSWSApi success = requestSendsResponse(listByType, listResponse); - - assertEquals( - success.getLBPoolApiForZone("jclouds.org.").listByType(Type.RD).toString(), + success.getRoundRobinPoolApiForZone("jclouds.org.").list().toString(), new GetLoadBalancingPoolsByZoneResponseTest().expected().toString()); } HttpRequest listRecords = HttpRequest.builder().method("POST") .endpoint("https://ultra-api.ultradns.com:8443/UltraDNS_WS/v01") .addHeader("Host", "ultra-api.ultradns.com:8443") - .payload(payloadFromResourceWithContentType("/list_poolrecords.xml", "application/xml")).build(); + .payload(payloadFromResourceWithContentType("/list_rrrecords.xml", "application/xml")).build(); HttpResponse listRecordsResponse = HttpResponse.builder().statusCode(200) - .payload(payloadFromResourceWithContentType("/poolrecords.xml", "application/xml")).build(); + .payload(payloadFromResourceWithContentType("/records.xml", "application/xml")).build(); public void testListRecordsWhenResponseIs2xx() { UltraDNSWSApi success = requestSendsResponse(listRecords, listRecordsResponse); assertEquals( - success.getLBPoolApiForZone("jclouds.org.").listRecords("04053D8E57C7931F").toString(), - new GetPoolRecordsResponseTest().expected().toString()); + success.getRoundRobinPoolApiForZone("jclouds.org.").listRecords("04053D8E57C7931F").toString(), + new GetResourceRecordsOfResourceRecordResponseTest().expected().toString()); } HttpRequest delete = HttpRequest.builder().method("POST") diff --git a/labs/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/features/RoundRobinPoolApiLiveTest.java b/labs/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/features/RoundRobinPoolApiLiveTest.java new file mode 100644 index 0000000000..64f3cf7125 --- /dev/null +++ b/labs/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/features/RoundRobinPoolApiLiveTest.java @@ -0,0 +1,250 @@ +/** + * 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 com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.base.Predicates.equalTo; +import static java.util.logging.Logger.getAnonymousLogger; +import static org.jclouds.ultradns.ws.domain.ResourceRecord.rrBuilder; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertFalse; +import static org.testng.Assert.assertTrue; +import static org.testng.Assert.fail; + +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.ResourceRecord; +import org.jclouds.ultradns.ws.domain.ResourceRecordMetadata; +import org.jclouds.ultradns.ws.domain.RoundRobinPool; +import org.jclouds.ultradns.ws.domain.Zone; +import org.jclouds.ultradns.ws.internal.BaseUltraDNSWSApiLiveTest; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import com.google.common.base.Optional; +import com.google.common.base.Predicate; +import com.google.common.collect.FluentIterable; +import com.google.common.primitives.UnsignedInteger; + +/** + * @author Adrian Cole + */ +@Test(groups = "live", singleThreaded = true, testName = "RoundRobinPoolApiLiveTest") +public class RoundRobinPoolApiLiveTest extends BaseUltraDNSWSApiLiveTest { + + private String zoneName = System.getProperty("user.name").replace('.', '-') + ".rrpool.ultradnstest.jclouds.org."; + private Account account; + + @Override + @BeforeClass(groups = { "integration", "live" }) + public void setupContext() { + super.setupContext(); + context.getApi().getZoneApi().delete(zoneName); + account = context.getApi().getCurrentAccount(); + context.getApi().getZoneApi().createInAccount(zoneName, account.getId()); + } + + private void checkLBPool(RoundRobinPool pool) { + checkNotNull(pool.getZoneId(), "ZoneId cannot be null for a RoundRobinPool %s", pool); + checkNotNull(pool.getId(), "Id cannot be null for a RoundRobinPool %s", pool); + checkNotNull(pool.getName(), "Name cannot be null for a RoundRobinPool %s", pool); + } + + @Test + public void testListRRPools() { + for (Zone zone : context.getApi().getZoneApi().listByAccount(account.getId())) { + for (RoundRobinPool pool : api(zone.getName()).list()) { + checkLBPool(pool); + } + } + } + + @Test + public void testListRRPoolRecords() { + for (Zone zone : context.getApi().getZoneApi().listByAccount(account.getId())) { + for (RoundRobinPool pool : api(zone.getName()).list()) { + for (ResourceRecordMetadata record : api(zone.getName()).listRecords(pool.getId())) { + ResourceRecordApiLiveTest.checkResourceRecordMetadata(record); + } + } + } + } + + @Test(expectedExceptions = ResourceNotFoundException.class, expectedExceptionsMessageRegExp = "Zone does not exist in the system.") + public void testListRRPoolsWhenZoneIdNotFound() { + api("AAAAAAAAAAAAAAAA").list(); + } + + @Test + public void testDeleteWhenNotFound() { + api(zoneName).delete("06063D9C54C5AE09"); + } + + String hostname = "www.rrpool." + zoneName; + String aPoolId; + + @Test + public void testCreateAPool() { + aPoolId = api(zoneName).createAPoolForHostname("A pool", hostname); + getAnonymousLogger().info("created A rr pool: " + aPoolId); + try { + api(zoneName).createAPoolForHostname("A pool", hostname); + fail(); + } catch (ResourceAlreadyExistsException e) { + + } + Optional aPool = getPoolById(aPoolId); + assertTrue(aPool.isPresent()); + assertEquals(aPool.get().getName(), "A pool"); + assertEquals(aPool.get().getDName(), hostname); + } + + String aRecord1; + String aRecord2; + + @Test(dependsOnMethods = "testCreateAPool") + public void addARecordToPool() { + aRecord1 = api(zoneName).addARecordWithAddressAndTTL(aPoolId, "1.2.3.4", UnsignedInteger.ONE); + + getAnonymousLogger().info("created A record: " + aRecord1); + + assertTrue(listRRs(aPoolId).anyMatch( + equalTo(rrBuilder().name(hostname).type("A").ttl(1).rdata("1.2.3.4").build()))); + + aRecord2 = api(zoneName).addARecordWithAddressAndTTL(aPoolId, "3.4.5.6", UnsignedInteger.ONE); + + assertTrue(listRRs(aPoolId).anyMatch( + equalTo(rrBuilder().name(hostname).type("A").ttl(1).rdata("3.4.5.6").build()))); + + getAnonymousLogger().info("created A record: " + aRecord1); + try { + api(zoneName).addARecordWithAddressAndTTL(aPoolId, "1.2.3.4", UnsignedInteger.ONE); + fail(); + } catch (ResourceAlreadyExistsException e) { + + } + } + + @Test(dependsOnMethods = "addARecordToPool") + public void testUpdateRecord() { + api(zoneName).updateRecordWithAddressAndTTL(aPoolId, aRecord1, "1.1.1.1", UnsignedInteger.ZERO); + assertTrue(listRRs(aPoolId).anyMatch( + equalTo(rrBuilder().name(hostname).type("A").ttl(0).rdata("1.1.1.1").build()))); + } + + @Test(dependsOnMethods = "testUpdateRecord") + public void testDeleteRecord() { + api(zoneName).deleteRecord(aRecord2); + assertTrue(listRRs(aPoolId).anyMatch( + equalTo(rrBuilder().name(hostname).type("A").ttl(0).rdata("1.1.1.1").build()))); + + assertFalse(listRRs(aPoolId).anyMatch( + equalTo(rrBuilder().name(hostname).type("A").ttl(1).rdata("3.4.5.6").build()))); + } + + @Test(dependsOnMethods = "testDeleteRecord") + public void testDeleteAPool() { + api(zoneName).delete(aPoolId); + assertFalse(getPoolById(aPoolId).isPresent()); + } + + private String aaaaPoolId; + + @Test + public void testCreateAAAAPool() { + aaaaPoolId = api(zoneName).createAAAAPoolForHostname("AAAA pool", hostname); + getAnonymousLogger().info("created AAAA rr pool: " + aaaaPoolId); + try { + api(zoneName).createAAAAPoolForHostname("AAAA pool", hostname); + fail(); + } catch (ResourceAlreadyExistsException e) { + + } + Optional aPool = getPoolById(aaaaPoolId); + assertTrue(aPool.isPresent()); + assertEquals(aPool.get().getName(), "AAAA pool"); + assertEquals(aPool.get().getDName(), hostname); + } + + String aaaaRecord1; + String aaaaRecord2; + + @Test(dependsOnMethods = "testCreateAAAAPool") + public void addAAAARecordToPool() { + aaaaRecord1 = api(zoneName).addAAAARecordWithAddressAndTTL(aaaaPoolId, "2001:0DB8:85A3:0000:0000:8A2E:0370:7334", + UnsignedInteger.ONE); + + getAnonymousLogger().info("created AAAA record: " + aaaaRecord1); + + assertTrue(listRRs(aaaaPoolId).anyMatch( + equalTo(rrBuilder().name(hostname).type("AAAA").ttl(1).rdata("2001:0DB8:85A3:0000:0000:8A2E:0370:7334") + .build()))); + + aaaaRecord2 = api(zoneName).addAAAARecordWithAddressAndTTL(aaaaPoolId, "2002:0DB8:85A3:0000:0000:8A2E:0370:7334", + UnsignedInteger.ONE); + + assertTrue(listRRs(aaaaPoolId).anyMatch( + equalTo(rrBuilder().name(hostname).type("AAAA").ttl(1).rdata("2002:0DB8:85A3:0000:0000:8A2E:0370:7334") + .build()))); + + getAnonymousLogger().info("created AAAA record: " + aaaaRecord1); + try { + api(zoneName).addAAAARecordWithAddressAndTTL(aaaaPoolId, "2001:0DB8:85A3:0000:0000:8A2E:0370:7334", + UnsignedInteger.ONE); + fail(); + } catch (ResourceAlreadyExistsException e) { + + } + } + + @Test(dependsOnMethods = "addAAAARecordToPool") + public void testDeleteAAAAPool() { + api(zoneName).delete(aaaaPoolId); + assertFalse(getPoolById(aaaaPoolId).isPresent()); + } + + protected Optional getPoolById(final String poolId) { + return api(zoneName).list().firstMatch(new Predicate() { + public boolean apply(RoundRobinPool in) { + return in.getId().equals(poolId); + } + }); + } + + private FluentIterable listRRs(String poolId) { + return api(zoneName).listRecords(poolId).transform(ResourceRecordApiLiveTest.toRecord); + } + + private RoundRobinPoolApi api(String zoneName) { + return context.getApi().getRoundRobinPoolApiForZone(zoneName); + } + + @Override + @AfterClass(groups = { "integration", "live" }) + protected void tearDownContext() { + if (aPoolId != null) + api(zoneName).delete(aPoolId); + if (aaaaPoolId != null) + api(zoneName).delete(aaaaPoolId); + context.getApi().getZoneApi().delete(zoneName); + super.tearDownContext(); + } +} diff --git a/labs/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/handlers/UltraDNSWSErrorHandlerTest.java b/labs/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/handlers/UltraDNSWSErrorHandlerTest.java index 95ef12c03d..8423a1842a 100644 --- a/labs/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/handlers/UltraDNSWSErrorHandlerTest.java +++ b/labs/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/handlers/UltraDNSWSErrorHandlerTest.java @@ -176,6 +176,51 @@ public class UltraDNSWSErrorHandlerTest { assertEquals(exception.getError().getCode(), 2111); } + @Test + public void testCode2911SetsResourceNotFoundException() throws IOException { + HttpRequest request = HttpRequest.builder().method("POST") + .endpoint("https://ultra-api.ultradns.com:8443/UltraDNS_WS/v01") + .addHeader("Host", "ultra-api.ultradns.com:8443").payload(payloadFromResource("/delete_lbpool.xml")).build(); + HttpCommand command = new HttpCommand(request); + HttpResponse response = HttpResponse.builder().message("Server Error").statusCode(500) + .payload(payloadFromResource("/lbpool_doesnt_exist.xml")).build(); + + function.handleError(command, response); + + assertEquals(command.getException().getClass(), ResourceNotFoundException.class); + assertEquals(command.getException().getMessage(), "Pool does not exist in the system"); + + UltraDNSWSResponseException exception = UltraDNSWSResponseException.class.cast(command.getException().getCause()); + + assertEquals(exception.getMessage(), "Error 2911: Pool does not exist in the system"); + assertEquals(exception.getError().getDescription(), "Pool does not exist in the system"); + assertEquals(exception.getError().getCode(), 2911); + } + + @Test + public void testCode2912SetsResourceAlreadyExistsException() throws IOException { + HttpRequest request = HttpRequest.builder().method("POST") + .endpoint("https://ultra-api.ultradns.com:8443/UltraDNS_WS/v01") + .addHeader("Host", "ultra-api.ultradns.com:8443").payload(payloadFromResource("/create_rrpool_a.xml")).build(); + HttpCommand command = new HttpCommand(request); + HttpResponse response = HttpResponse.builder().message("Server Error").statusCode(500) + .payload(payloadFromResource("/lbpool_already_exists.xml")).build(); + + function.handleError(command, response); + + assertEquals(command.getException().getClass(), ResourceAlreadyExistsException.class); + assertEquals(command.getException().getMessage(), + "Pool already created for this host name : www.rrpool.adrianc.rrpool.ultradnstest.jclouds.org."); + + UltraDNSWSResponseException exception = UltraDNSWSResponseException.class.cast(command.getException().getCause()); + + assertEquals(exception.getMessage(), + "Error 2912: Pool already created for this host name : www.rrpool.adrianc.rrpool.ultradnstest.jclouds.org."); + assertEquals(exception.getError().getDescription(), + "Pool already created for this host name : www.rrpool.adrianc.rrpool.ultradnstest.jclouds.org."); + assertEquals(exception.getError().getCode(), 2912); + } + private Payload payloadFromResource(String resource) { try { return payloadFromStringWithContentType(toStringAndClose(getClass().getResourceAsStream(resource)), diff --git a/labs/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/parse/GetLoadBalancingPoolsByZoneResponseTest.java b/labs/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/parse/GetLoadBalancingPoolsByZoneResponseTest.java index f7e46e9299..177068df27 100644 --- a/labs/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/parse/GetLoadBalancingPoolsByZoneResponseTest.java +++ b/labs/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/parse/GetLoadBalancingPoolsByZoneResponseTest.java @@ -23,9 +23,8 @@ import static org.testng.Assert.assertEquals; import java.io.InputStream; import org.jclouds.http.functions.BaseHandlerTest; -import org.jclouds.ultradns.ws.domain.LBPool; -import org.jclouds.ultradns.ws.domain.LBPool.Type; -import org.jclouds.ultradns.ws.xml.LBPoolListHandler; +import org.jclouds.ultradns.ws.domain.RoundRobinPool; +import org.jclouds.ultradns.ws.xml.RoundRobinPoolListHandler; import org.testng.annotations.Test; import com.google.common.collect.FluentIterable; @@ -38,40 +37,32 @@ import com.google.common.collect.ImmutableList; public class GetLoadBalancingPoolsByZoneResponseTest extends BaseHandlerTest { public void test() { - InputStream is = getClass().getResourceAsStream("/lbpools.xml"); + InputStream is = getClass().getResourceAsStream("/rrpools.xml"); - FluentIterable expected = expected(); + FluentIterable expected = expected(); - LBPoolListHandler handler = injector.getInstance(LBPoolListHandler.class); - FluentIterable result = factory.create(handler).parse(is); + RoundRobinPoolListHandler handler = injector.getInstance(RoundRobinPoolListHandler.class); + FluentIterable result = factory.create(handler).parse(is); assertEquals(result.toSet().toString(), expected.toSet().toString()); } - public FluentIterable expected() { - return FluentIterable.from(ImmutableList. builder() - .add(LBPool.builder() - .zoneId("0000000000000001") - .id("000000000000001") - .name("us-west-1c.app.jclouds.org.") - .type(Type.TC).build()) - .add(LBPool.builder() + public FluentIterable expected() { + return FluentIterable.from(ImmutableList. builder() + .add(RoundRobinPool.builder() .zoneId("0000000000000001") .id("000000000000002") .name("app-uswest1.jclouds.org.") - .type(Type.RD) - .responseMethod(Type.RR).build()) - .add(LBPool.builder() + .dname("app-uswest1.jclouds.org.").build()) + .add(RoundRobinPool.builder() .zoneId("0000000000000001") .id("000000000000003") .name("app-uswest2.jclouds.org.") - .type(Type.RD) - .responseMethod(Type.RR).build()) - .add(LBPool.builder() + .dname("app-uswest2.jclouds.org.").build()) + .add(RoundRobinPool.builder() .zoneId("0000000000000001") .id("000000000000004") .name("app-euwest.jclouds.org.") - .type(Type.RD) - .responseMethod(Type.RR).build()).build()); + .dname("app-euwest.jclouds.org.").build()).build()); } } \ No newline at end of file diff --git a/labs/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/parse/GetPoolRecordsResponseTest.java b/labs/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/parse/GetPoolRecordsResponseTest.java deleted file mode 100644 index 26ab403f84..0000000000 --- a/labs/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/parse/GetPoolRecordsResponseTest.java +++ /dev/null @@ -1,65 +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.parse; - -import static org.testng.Assert.assertEquals; - -import java.io.InputStream; - -import org.jclouds.http.functions.BaseHandlerTest; -import org.jclouds.ultradns.ws.domain.PoolRecord; -import org.jclouds.ultradns.ws.xml.PoolRecordListHandler; -import org.testng.annotations.Test; - -import com.google.common.collect.FluentIterable; -import com.google.common.collect.ImmutableSet; - -/** - * @author Adrian Cole - */ -@Test(testName = "GetPoolRecordsResponseTest") -public class GetPoolRecordsResponseTest extends BaseHandlerTest { - - public void test() { - InputStream is = getClass().getResourceAsStream("/poolrecords.xml"); - - FluentIterable expected = expected(); - - PoolRecordListHandler handler = injector.getInstance(PoolRecordListHandler.class); - FluentIterable result = factory.create(handler).parse(is); - - assertEquals(result.toSet().toString(), expected.toSet().toString()); - } - - public FluentIterable expected() { - return FluentIterable.from(ImmutableSet. builder() - .add(PoolRecord.builder() - .poolId("0603399D0413BC46") - .id("0603399D0413BC47") - .description("SiteBacker pool via API") - .type("A") - .pointsTo("172.16.8.1").build()) - .add(PoolRecord.builder() - .poolId("0603399D0413BC46") - .id("060339A30416430C") - .description("SiteBacker pool via API") - .type("A") - .pointsTo("172.16.8.2").build()).build()); - } -} diff --git a/labs/ultradns-ws/src/test/resources/list_lbpools.xml b/labs/ultradns-ws/src/test/resources/create_rrpool_a.xml similarity index 65% rename from labs/ultradns-ws/src/test/resources/list_lbpools.xml rename to labs/ultradns-ws/src/test/resources/create_rrpool_a.xml index 869d54af9c..7fc5be2c10 100644 --- a/labs/ultradns-ws/src/test/resources/list_lbpools.xml +++ b/labs/ultradns-ws/src/test/resources/create_rrpool_a.xml @@ -1 +1 @@ -identitycredentialjclouds.org.all \ No newline at end of file +identitycredentialjclouds.org.foowww.jclouds.org.1 \ No newline at end of file diff --git a/labs/ultradns-ws/src/test/resources/create_rrpool_aaaa.xml b/labs/ultradns-ws/src/test/resources/create_rrpool_aaaa.xml new file mode 100644 index 0000000000..55936e01aa --- /dev/null +++ b/labs/ultradns-ws/src/test/resources/create_rrpool_aaaa.xml @@ -0,0 +1 @@ +identitycredentialjclouds.org.foowww.jclouds.org.28 \ No newline at end of file diff --git a/labs/ultradns-ws/src/test/resources/lbpool_already_exists.xml b/labs/ultradns-ws/src/test/resources/lbpool_already_exists.xml new file mode 100644 index 0000000000..833e09cacd --- /dev/null +++ b/labs/ultradns-ws/src/test/resources/lbpool_already_exists.xml @@ -0,0 +1 @@ +soap:ServerFault occurred while processing.2912Pool already created for this host name : www.rrpool.adrianc.rrpool.ultradnstest.jclouds.org. \ No newline at end of file diff --git a/labs/ultradns-ws/src/test/resources/lbpool_doesnt_exist.xml b/labs/ultradns-ws/src/test/resources/lbpool_doesnt_exist.xml index 6550a2a982..bdb46e1f70 100644 --- a/labs/ultradns-ws/src/test/resources/lbpool_doesnt_exist.xml +++ b/labs/ultradns-ws/src/test/resources/lbpool_doesnt_exist.xml @@ -1 +1 @@ -soap:ServerFault occurred while processing.2103No Resource Record with GUID found in the system AAAAAAAAAAAAAAAA \ No newline at end of file +soap:ServerFault occurred while processing.2911Pool does not exist in the system \ No newline at end of file diff --git a/labs/ultradns-ws/src/test/resources/list_lbpools_by_type.xml b/labs/ultradns-ws/src/test/resources/list_rrpools.xml similarity index 91% rename from labs/ultradns-ws/src/test/resources/list_lbpools_by_type.xml rename to labs/ultradns-ws/src/test/resources/list_rrpools.xml index b2d3423aec..c288dbb59d 100644 --- a/labs/ultradns-ws/src/test/resources/list_lbpools_by_type.xml +++ b/labs/ultradns-ws/src/test/resources/list_rrpools.xml @@ -1 +1 @@ -identitycredentialjclouds.org.RD \ No newline at end of file +identitycredentialjclouds.org.RR \ No newline at end of file diff --git a/labs/ultradns-ws/src/test/resources/list_poolrecords.xml b/labs/ultradns-ws/src/test/resources/list_rrrecords.xml similarity index 76% rename from labs/ultradns-ws/src/test/resources/list_poolrecords.xml rename to labs/ultradns-ws/src/test/resources/list_rrrecords.xml index 6b09704e1c..81b93733b9 100644 --- a/labs/ultradns-ws/src/test/resources/list_poolrecords.xml +++ b/labs/ultradns-ws/src/test/resources/list_rrrecords.xml @@ -1 +1 @@ -identitycredential04053D8E57C7931F \ No newline at end of file +identitycredential04053D8E57C7931F \ No newline at end of file diff --git a/labs/ultradns-ws/src/test/resources/poolrecords.xml b/labs/ultradns-ws/src/test/resources/poolrecords.xml deleted file mode 100644 index 86783736dc..0000000000 --- a/labs/ultradns-ws/src/test/resources/poolrecords.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - diff --git a/labs/ultradns-ws/src/test/resources/rrpool_created.xml b/labs/ultradns-ws/src/test/resources/rrpool_created.xml new file mode 100644 index 0000000000..5573f99457 --- /dev/null +++ b/labs/ultradns-ws/src/test/resources/rrpool_created.xml @@ -0,0 +1,5 @@ + + + 060339AA04175655 + + \ No newline at end of file diff --git a/labs/ultradns-ws/src/test/resources/lbpools.xml b/labs/ultradns-ws/src/test/resources/rrpools.xml similarity index 77% rename from labs/ultradns-ws/src/test/resources/lbpools.xml rename to labs/ultradns-ws/src/test/resources/rrpools.xml index 8c6e42bf27..4d0986734d 100644 --- a/labs/ultradns-ws/src/test/resources/lbpools.xml +++ b/labs/ultradns-ws/src/test/resources/rrpools.xml @@ -3,12 +3,6 @@ - - -