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 b4c27c1bed..c302348f49 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 @@ -32,6 +32,7 @@ import org.jclouds.rest.annotations.VirtualHost; import org.jclouds.rest.annotations.XMLResponseParser; import org.jclouds.ultradns.ws.domain.Account; import org.jclouds.ultradns.ws.domain.Region; +import org.jclouds.ultradns.ws.features.DirectionalGroupApi; import org.jclouds.ultradns.ws.features.DirectionalPoolApi; import org.jclouds.ultradns.ws.features.ResourceRecordApi; import org.jclouds.ultradns.ws.features.RoundRobinPoolApi; @@ -103,6 +104,15 @@ public interface UltraDNSWSApi extends Closeable { @Delegate TrafficControllerPoolApi getTrafficControllerPoolApiForZone(@PayloadParam("zoneName") String zoneName); + /** + * Provides access to Account-Level Directional Group features. + * + * @param accountId + * id of the account where the groups live. + */ + @Delegate + DirectionalGroupApi getDirectionalGroupApiForAccount(@PayloadParam("accountId") String accountId); + /** * Provides access to Directional Pool features. * diff --git a/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/binders/DirectionalGroupCoordinatesToXML.java b/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/binders/DirectionalGroupCoordinatesToXML.java new file mode 100644 index 0000000000..729fee5aa4 --- /dev/null +++ b/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/binders/DirectionalGroupCoordinatesToXML.java @@ -0,0 +1,46 @@ +/** + * 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.binders; + +import org.jclouds.http.HttpRequest; +import org.jclouds.http.UriTemplates; +import org.jclouds.rest.Binder; +import org.jclouds.ultradns.ws.domain.DirectionalGroupCoordinates; + +import com.google.common.collect.ImmutableMap; + +/** + * + * @author Adrian Cole + */ +public class DirectionalGroupCoordinatesToXML implements Binder { + private static final String TEMPLATE = "{groupName}{recordName}{zoneName}{recordType}"; + + @SuppressWarnings("unchecked") + @Override + public R bindToRequest(R request, Object in) { + DirectionalGroupCoordinates group = DirectionalGroupCoordinates.class.cast(in); + ImmutableMap variables = ImmutableMap. builder() + .put("zoneName", group.getZoneName()) + .put("recordName", group.getRecordName()) + .put("recordType", group.getRecordType()) + .put("groupName", group.getGroupName()).build(); + return (R) request.toBuilder().payload(UriTemplates.expand(TEMPLATE, variables)).build(); + } +} \ No newline at end of file diff --git a/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/domain/AccountLevelGroup.java b/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/domain/AccountLevelGroup.java new file mode 100644 index 0000000000..8776c6d2bf --- /dev/null +++ b/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/domain/AccountLevelGroup.java @@ -0,0 +1,141 @@ +/** + * 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.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; + +import org.jclouds.ultradns.ws.domain.DirectionalPool.Type; + +import com.google.common.base.Objects; + +/** + * + * @author Adrian Cole + */ +public final class AccountLevelGroup { + + private final String id; + private final String name; + private final Type type; + private final int recordCount; + + private AccountLevelGroup(String id, String name, Type type, int recordCount) { + this.id = checkNotNull(id, "id"); + this.name = checkNotNull(name, "name of %s", id); + this.type = checkNotNull(type, "type of %s", id); + this.recordCount = recordCount; + checkArgument(recordCount >= 0, "recordCount of %s must be >= 0", id); + } + + public String getId() { + return id; + } + + public String getName() { + return name; + } + + public Type getType() { + return type; + } + + public int getRecordCount() { + return recordCount; + } + + @Override + public int hashCode() { + return Objects.hashCode(id, name, type); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + AccountLevelGroup that = AccountLevelGroup.class.cast(obj); + return Objects.equal(this.id, that.id) && Objects.equal(this.name, that.name) + && Objects.equal(this.type, that.type); + } + + @Override + public String toString() { + return Objects.toStringHelper(this).omitNullValues().add("id", id).add("name", name).add("type", type) + .add("recordCount", recordCount).toString(); + } + + public static Builder builder() { + return new Builder(); + } + + public Builder toBuilder() { + return builder().from(this); + } + + public final static class Builder { + private String id; + private String name; + private Type type; + private int recordCount = -1; + + /** + * @see AccountLevelGroup#getId() + */ + public Builder id(String id) { + this.id = id; + return this; + } + + /** + * @see AccountLevelGroup#getName() + */ + public Builder name(String name) { + this.name = name; + return this; + } + + /** + * @see AccountLevelGroup#getType() + */ + public Builder type(Type type) { + this.type = type; + return this; + } + + /** + * @see AccountLevelGroup#getRecordCount() + */ + public Builder recordCount(int recordCount) { + this.recordCount = recordCount; + return this; + } + + public AccountLevelGroup build() { + return new AccountLevelGroup(id, name, type, recordCount); + } + + public Builder from(AccountLevelGroup in) { + return this.id(in.id).name(in.name).type(in.type).recordCount(in.recordCount); + } + } +} diff --git a/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/domain/DirectionalGroup.java b/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/domain/DirectionalGroup.java index 72c51f6d01..97a67490e0 100644 --- a/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/domain/DirectionalGroup.java +++ b/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/domain/DirectionalGroup.java @@ -23,7 +23,6 @@ import static com.google.common.base.Objects.toStringHelper; import static com.google.common.base.Preconditions.checkNotNull; import com.google.common.base.Objects; -import com.google.common.base.Optional; /** * @author Adrian Cole @@ -31,12 +30,10 @@ import com.google.common.base.Optional; public class DirectionalGroup { private final String id; private final String name; - private final Optional description; - private DirectionalGroup(String id, String name, Optional description) { + private DirectionalGroup(String id, String name) { this.id = checkNotNull(id, "id"); this.name = checkNotNull(name, "name"); - this.description = checkNotNull(description, "description"); } public String getId() { @@ -47,13 +44,9 @@ public class DirectionalGroup { return name; } - public Optional getDescription() { - return description; - } - @Override public int hashCode() { - return Objects.hashCode(id, name, description); + return Objects.hashCode(id, name); } @Override @@ -63,13 +56,12 @@ public class DirectionalGroup { if (obj == null || getClass() != obj.getClass()) return false; DirectionalGroup that = DirectionalGroup.class.cast(obj); - return equal(this.id, that.id) && equal(this.name, that.name) && equal(this.description, that.description); + return equal(this.id, that.id) && equal(this.name, that.name); } @Override public String toString() { - return toStringHelper("").omitNullValues().add("id", id).add("name", name) - .add("description", description.orNull()).toString(); + return toStringHelper("").omitNullValues().add("id", id).add("name", name).toString(); } public static Builder builder() { @@ -83,7 +75,6 @@ public class DirectionalGroup { public final static class Builder { private String id; private String name; - private Optional description = Optional.absent(); /** * @see DirectionalGroup#getId() @@ -101,20 +92,12 @@ public class DirectionalGroup { return this; } - /** - * @see DirectionalGroup#getDescription() - */ - public Builder description(String description) { - this.description = Optional.fromNullable(description); - return this; - } - public DirectionalGroup build() { - return new DirectionalGroup(id, name, description); + return new DirectionalGroup(id, name); } public Builder from(DirectionalGroup in) { - return id(in.id).name(in.name).description(in.description.orNull()); + return id(in.id).name(in.name); } } } diff --git a/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/domain/DirectionalGroupCoordinates.java b/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/domain/DirectionalGroupCoordinates.java new file mode 100644 index 0000000000..65bf4cf17d --- /dev/null +++ b/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/domain/DirectionalGroupCoordinates.java @@ -0,0 +1,156 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.ultradns.ws.domain; + +import static com.google.common.base.Objects.equal; +import static com.google.common.base.Objects.toStringHelper; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; + +import com.google.common.base.Objects; + +/** + * @author Adrian Cole + */ +public class DirectionalGroupCoordinates { + + private final String zoneName; + private final String recordName; + private final int recordType; + private final String groupName; + + private DirectionalGroupCoordinates(String zoneName, String recordName, int recordType, String groupName) { + this.zoneName = checkNotNull(zoneName, "zoneName"); + this.recordName = checkNotNull(recordName, "recordName"); + checkArgument(recordType >= 0, "recordType of %s must be >= 0", recordName); + this.recordType = recordType; + this.groupName = checkNotNull(groupName, "groupName"); + } + + /** + * the {@link DirectionalRecordDetail#getZoneName() name} of the zone. + */ + public String getZoneName() { + return zoneName; + } + + /** + * the {@link DirectionalRecordDetail#getName() dname} of the record. + */ + public String getRecordName() { + return recordName; + } + + /** + * the {@link DirectionalRecord#getType() recordType} of the record. + * + * @see DirectionalRecordDetail#getRecord() + */ + public int getRecordType() { + return recordType; + } + + /** + * the {@link DirectionalGroup#getName() name} of the directional group. + * + * @see DirectionalRecordDetail#getGroup() + * @see DirectionalRecordDetail#getGeolocationGroup() + * @see DirectionalRecordDetail#getSourceIpGroup() + */ + public String getGroupName() { + return groupName; + } + + @Override + public int hashCode() { + return Objects.hashCode(zoneName, recordName, recordType, groupName); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null || getClass() != obj.getClass()) + return false; + DirectionalGroupCoordinates that = DirectionalGroupCoordinates.class.cast(obj); + return equal(this.zoneName, that.zoneName) && equal(this.recordName, that.recordName) + && equal(this.recordType, that.recordType) && equal(this.groupName, that.groupName); + } + + @Override + public String toString() { + return toStringHelper("").add("zoneName", zoneName).add("recordName", recordName).add("recordType", recordType) + .add("groupName", groupName).toString(); + } + + public static Builder builder() { + return new Builder(); + } + + public Builder toBuilder() { + return builder().from(this); + } + + public final static class Builder { + private String zoneName; + private String recordName; + private int recordType = -1; + private String groupName; + + /** + * @see DirectionalGroupCoordinates#getZoneName() + */ + public Builder zoneName(String zoneName) { + this.zoneName = zoneName; + return this; + } + + /** + * @see DirectionalGroupCoordinates#getRecordName() + */ + public Builder recordName(String recordName) { + this.recordName = recordName; + return this; + } + + /** + * @see DirectionalGroupCoordinates#getRecordType() + */ + public Builder recordType(int recordType) { + this.recordType = recordType; + return this; + } + + /** + * @see DirectionalGroupCoordinates#getGroupName() + */ + public Builder groupName(String groupName) { + this.groupName = groupName; + return this; + } + + public DirectionalGroupCoordinates build() { + return new DirectionalGroupCoordinates(zoneName, recordName, recordType, groupName); + } + + public Builder from(DirectionalGroupCoordinates in) { + return zoneName(in.zoneName).recordName(in.zoneName).recordType(in.recordType).groupName(in.groupName); + } + } +} diff --git a/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/domain/DirectionalGroupNameAndRegions.java b/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/domain/DirectionalGroupNameAndRegions.java new file mode 100644 index 0000000000..1b0f960cf7 --- /dev/null +++ b/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/domain/DirectionalGroupNameAndRegions.java @@ -0,0 +1,127 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.ultradns.ws.domain; + +import static com.google.common.base.Objects.equal; +import static com.google.common.base.Objects.toStringHelper; +import static com.google.common.base.Preconditions.checkNotNull; + +import java.util.Set; + +import com.google.common.base.Objects; +import com.google.common.collect.ForwardingSet; +import com.google.common.collect.ImmutableSet; + +/** + * A region is a set of territory names. + * + * @author Adrian Cole + */ +public class DirectionalGroupNameAndRegions extends ForwardingSet { + + private final String name; + private final Set regions; + + private DirectionalGroupNameAndRegions(String name, Set regions) { + this.name = checkNotNull(name, "name"); + this.regions = checkNotNull(regions, "regions of %s", name); + } + + public String getName() { + return name; + } + + public Set getRegions() { + return regions; + } + + @Override + protected Set delegate() { + return regions; + } + + @Override + public int hashCode() { + return Objects.hashCode(name, regions); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null || getClass() != obj.getClass()) + return false; + DirectionalGroupNameAndRegions that = DirectionalGroupNameAndRegions.class.cast(obj); + return equal(this.name, that.name) && equal(this.regions, that.regions); + } + + @Override + public String toString() { + return toStringHelper("").add("name", name).add("regions", regions).toString(); + } + + public static Builder builder() { + return new Builder(); + } + + public Builder toBuilder() { + return builder().from(this); + } + + public final static class Builder { + private String name; + private ImmutableSet.Builder regions = ImmutableSet. builder(); + + /** + * @see DirectionalGroupNameAndRegions#getName() + */ + public Builder name(String name) { + this.name = name; + return this; + } + + /** + * adds to current regions + * + * @see DirectionalGroupNameAndRegions#getRegions() + */ + public Builder addRegion(Region region) { + this.regions.add(region); + return this; + } + + /** + * replaces current regions + * + * @see DirectionalGroupNameAndRegions#getRegions() + */ + public Builder regions(Iterable regions) { + this.regions = ImmutableSet. builder().addAll(regions); + return this; + } + + public DirectionalGroupNameAndRegions build() { + return new DirectionalGroupNameAndRegions(name, regions.build()); + } + + public Builder from(DirectionalGroupNameAndRegions in) { + return name(in.getName()).regions(in.getRegions()); + } + } +} diff --git a/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/domain/DirectionalRecordDetail.java b/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/domain/DirectionalRecordDetail.java index aae0031084..098688c45e 100644 --- a/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/domain/DirectionalRecordDetail.java +++ b/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/domain/DirectionalRecordDetail.java @@ -62,14 +62,23 @@ public class DirectionalRecordDetail { return id; } + /** + * group containing all regions that you have not specifically configured in {@link #getGeolocationGroup()} + */ public Optional getGroup() { return group; } + /** + * group containing territories. + */ public Optional getGeolocationGroup() { return geolocationGroup; } + /** + * group containing IPV4 or IPV6 ranges. + */ public Optional getSourceIpGroup() { return sourceIpGroup; } diff --git a/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/features/DirectionalGroupApi.java b/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/features/DirectionalGroupApi.java new file mode 100644 index 0000000000..70e1436a94 --- /dev/null +++ b/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/features/DirectionalGroupApi.java @@ -0,0 +1,135 @@ +/** + * 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.EmptyFluentIterableOnNotFoundOr404; +import org.jclouds.Fallbacks.NullOnNotFoundOr404; +import org.jclouds.javax.annotation.Nullable; +import org.jclouds.rest.ResourceNotFoundException; +import org.jclouds.rest.annotations.BinderParam; +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.binders.DirectionalGroupCoordinatesToXML; +import org.jclouds.ultradns.ws.domain.AccountLevelGroup; +import org.jclouds.ultradns.ws.domain.DirectionalGroup; +import org.jclouds.ultradns.ws.domain.DirectionalGroupCoordinates; +import org.jclouds.ultradns.ws.domain.DirectionalGroupNameAndRegions; +import org.jclouds.ultradns.ws.domain.DirectionalRecordDetail; +import org.jclouds.ultradns.ws.filters.SOAPWrapWithPasswordAuth; +import org.jclouds.ultradns.ws.xml.AccountLevelGroupsHandler; +import org.jclouds.ultradns.ws.xml.DirectionalGroupNameAndRegionsHandler; +import org.jclouds.ultradns.ws.xml.DirectionalRecordDetailListHandler; +import org.jclouds.ultradns.ws.xml.ItemListHandler; + +import com.google.common.collect.FluentIterable; + +/** + * @see + * @see + * @author Adrian Cole + */ +@RequestFilters(SOAPWrapWithPasswordAuth.class) +@VirtualHost +public interface DirectionalGroupApi { + + /** + * returns the regions and name of the specified directional group or null, + * if not found. + * + * @param groupId + * the {@link DirectionalGroup#getId() id} of the group + */ + @Named("getDirectionalDNSGroupDetails") + @POST + @XMLResponseParser(DirectionalGroupNameAndRegionsHandler.class) + @Fallback(NullOnNotFoundOr404.class) + @Payload("{GroupId}") + @Nullable + DirectionalGroupNameAndRegions get(@PayloadParam("GroupId") String groupId); + + /** + * Returns all account-level groups. + * + */ + @Named("getAccountLevelDirectionalGroupsOfZone") + @POST + @XMLResponseParser(AccountLevelGroupsHandler.class) + @Payload("{accountId}") + FluentIterable listAccountLevelGroups(); + + /** + * Returns all the directional pool records in the account-level group. + * + * @param groupId + * the id of the account-level group containing the records. + * @throws ResourceNotFoundException + * if the group doesn't exist + */ + @Named("getDirectionalDNSRecordsForAcctLvlGroup") + @POST + @XMLResponseParser(DirectionalRecordDetailListHandler.class) + @Payload("{groupId}") + FluentIterable listRecordsByAccountLevelGroup( + @PayloadParam("groupId") String groupId) throws ResourceNotFoundException; + + /** + * Returns directional group names visible to the account for the fully + * qualified {@link hostName} and {@link rrType} + * + * @param accountId + * the account where the groups exist + * @param hostName + * fully qualified hostname including the trailing dot. + * @param rrType + * type value, with special casing: for {@code A} or {@code CNAME} + * of ipv4 hosts, this is {@code 1}; for {@code AAAA} or + * {@code CNAME} of ipv4 hosts, this is {@code 28} + * @return empty if there are not groups for the specified host and type + */ + @Named("getAvailableGroups") + @POST + @XMLResponseParser(ItemListHandler.class) + @Fallback(EmptyFluentIterableOnNotFoundOr404.class) + @Payload("{hostName}{rrType}{accountId}") + FluentIterable listGroupNamesByRecordNameAndType( + @PayloadParam("hostName") String hostName, @PayloadParam("rrType") int rrType); + + /** + * Returns all the directional pool records in the pool-level group. + * + * @param group + * the zone, record name, record type, and group name + * @throws ResourceNotFoundException + * if the group doesn't exist + */ + @Named("getDirectionalDNSRecordsForGroup") + @POST + @XMLResponseParser(DirectionalRecordDetailListHandler.class) + @Fallback(EmptyFluentIterableOnNotFoundOr404.class) + FluentIterable listRecordsByGroupCoordinates( + @BinderParam(DirectionalGroupCoordinatesToXML.class) DirectionalGroupCoordinates group) + throws ResourceNotFoundException; +} diff --git a/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/handlers/UltraDNSWSErrorHandler.java b/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/handlers/UltraDNSWSErrorHandler.java index 3a598084c8..e541901c2c 100644 --- a/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/handlers/UltraDNSWSErrorHandler.java +++ b/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/handlers/UltraDNSWSErrorHandler.java @@ -95,6 +95,10 @@ public class UltraDNSWSErrorHandler implements HttpErrorHandler { * Resource record exists with the same name and type. */ static final int RESOURCE_RECORD_ALREADY_EXISTS = 2111; + /** + * No Pool or Multiple pools of same type exists for the PoolName + */ + static final int DIRECTIONAL_POOL_NOT_FOUND = 2142; /** * Account not found in the system. */ @@ -111,6 +115,10 @@ public class UltraDNSWSErrorHandler implements HttpErrorHandler { * Pool Record does not exist. */ static final int POOL_RECORD_NOT_FOUND = 3101; + /** + * Group does not exist. + */ + static final int GROUP_NOT_FOUND = 4003; } private Exception refineException(UltraDNSWSResponseException exception) { @@ -125,7 +133,9 @@ public class UltraDNSWSErrorHandler implements HttpErrorHandler { case RESOURCE_RECORD_NOT_FOUND: case ACCOUNT_NOT_FOUND: case POOL_NOT_FOUND: + case DIRECTIONAL_POOL_NOT_FOUND: case POOL_RECORD_NOT_FOUND: + case GROUP_NOT_FOUND: return new ResourceNotFoundException(message, exception); case ZONE_ALREADY_EXISTS: case RESOURCE_RECORD_ALREADY_EXISTS: diff --git a/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/xml/AccountLevelGroupsHandler.java b/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/xml/AccountLevelGroupsHandler.java new file mode 100644 index 0000000000..4a6985c90a --- /dev/null +++ b/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/xml/AccountLevelGroupsHandler.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.AccountLevelGroup; +import org.jclouds.ultradns.ws.domain.DirectionalPool.Type; +import org.xml.sax.Attributes; + +import com.google.common.collect.FluentIterable; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.ImmutableSet.Builder; + +/** + * + * @author Adrian Cole + */ +public class AccountLevelGroupsHandler extends + ParseSax.HandlerForGeneratedRequestWithResult> { + + private final Builder groups = ImmutableSet. builder(); + + @Override + public FluentIterable getResult() { + return FluentIterable.from(groups.build()); + } + + @Override + public void startElement(String url, String name, String qName, Attributes attrs) { + if (equalsOrSuffix(qName, "AccountLevelGroups")) { + Map attributes = cleanseAttributes(attrs); + groups.add(AccountLevelGroup.builder() + .id(attributes.get("GroupId")) + .name(attributes.get("GroupName")) + .type(Type.valueOf(attributes.get("GroupType"))) + .recordCount(Integer.parseInt(attributes.get("RecordsCount"))) + .build()); + } + } +} diff --git a/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/xml/DirectionalGroupNameAndRegionsHandler.java b/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/xml/DirectionalGroupNameAndRegionsHandler.java new file mode 100644 index 0000000000..800a9bd16f --- /dev/null +++ b/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/xml/DirectionalGroupNameAndRegionsHandler.java @@ -0,0 +1,56 @@ +/** + * 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.DirectionalGroupNameAndRegions; +import org.jclouds.ultradns.ws.domain.DirectionalGroupNameAndRegions.Builder; +import org.jclouds.ultradns.ws.domain.Region; +import org.xml.sax.Attributes; + +import com.google.common.base.Splitter; + +/** + * + * @author Adrian Cole + */ +public class DirectionalGroupNameAndRegionsHandler extends ParseSax.HandlerForGeneratedRequestWithResult { + + private final Builder group = DirectionalGroupNameAndRegions.builder(); + + @Override + public DirectionalGroupNameAndRegions getResult() { + return group.build(); + } + + @Override + public void startElement(String url, String name, String qName, Attributes attrs) { + if (equalsOrSuffix(qName, "DirectionalDNSGroupDetail")) { + group.name(attrs.getValue("GroupName")); + } else if (equalsOrSuffix(qName, "RegionForNewGroups")) { + Iterable territories = Splitter.on(';').split(attrs.getValue("TerritoryName")); + Region region = Region.builder() + .name(attrs.getValue("RegionName")) + .territoryNames(territories).build(); + group.addRegion(region); + } + } +} diff --git a/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/xml/DirectionalRecordDetailHandler.java b/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/xml/DirectionalRecordDetailHandler.java index d6dd91d894..7c967aaa2f 100644 --- a/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/xml/DirectionalRecordDetailHandler.java +++ b/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/xml/DirectionalRecordDetailHandler.java @@ -66,20 +66,17 @@ public class DirectionalRecordDetailHandler extends if (attributes.containsKey("GroupId")) { drd.group(DirectionalGroup.builder() .id(attributes.get("GroupId")) - .name(attributes.get("GroupName")) - .description(attributes.get("GroupDescription")).build()); + .name(attributes.get("GroupName")).build()); } if (attributes.containsKey("GeolocationGroupId")) { drd.geolocationGroup(DirectionalGroup.builder() .id(attributes.get("GeolocationGroupId")) - .name(attributes.get("GeolocationGroupName")) - .description(attributes.get("GeolocationGroupDescription")).build()); + .name(attributes.get("GeolocationGroupName")).build()); } if (attributes.containsKey("SourceIPGroupId")) { drd.sourceIpGroup(DirectionalGroup.builder() .id(attributes.get("SourceIPGroupId")) - .name(attributes.get("SourceIPGroupName")) - .description(attributes.get("SourceIPGroupDescription")).build()); + .name(attributes.get("SourceIPGroupName")).build()); } if (attributes.containsKey("recordType")) { dr.type(attributes.get("recordType")); diff --git a/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/xml/ItemListHandler.java b/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/xml/ItemListHandler.java new file mode 100644 index 0000000000..4b0b99d1fc --- /dev/null +++ b/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/xml/ItemListHandler.java @@ -0,0 +1,57 @@ +/** + * 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.currentOrNull; +import static org.jclouds.util.SaxUtils.equalsOrSuffix; + +import org.jclouds.http.functions.ParseSax; + +import com.google.common.collect.FluentIterable; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.ImmutableSet.Builder; + +/** + * + * @author Adrian Cole + */ +public class ItemListHandler extends ParseSax.HandlerForGeneratedRequestWithResult> { + + private StringBuilder currentText = new StringBuilder(); + + private Builder items = ImmutableSet. builder(); + + @Override + public FluentIterable getResult() { + return FluentIterable.from(items.build()); + } + + @Override + public void endElement(String uri, String name, String qName) { + if (equalsOrSuffix(qName, "item")) { + items.add(currentOrNull(currentText)); + } + currentText = new StringBuilder(); + } + + @Override + public void characters(char ch[], int start, int length) { + currentText.append(ch, start, length); + } +} diff --git a/providers/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/UltraDNSWSApiExpectTest.java b/providers/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/UltraDNSWSApiExpectTest.java index c216a7209d..5ad9827308 100644 --- a/providers/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/UltraDNSWSApiExpectTest.java +++ b/providers/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/UltraDNSWSApiExpectTest.java @@ -52,9 +52,9 @@ public class UltraDNSWSApiExpectTest extends BaseUltraDNSWSApiExpectTest { new GetAccountsListOfUserResponseTest().expected().toString()); } - HttpRequest getRegionsById = HttpRequest.builder().method("POST") + HttpRequest getRegionsById = HttpRequest.builder().method(POST) .endpoint("https://ultra-api.ultradns.com:8443/UltraDNS_WS/v01") - .addHeader("Host", "ultra-api.ultradns.com:8443") + .addHeader(HOST, "ultra-api.ultradns.com:8443") .payload(payloadFromResourceWithContentType("/list_regions.xml", "application/xml")).build(); HttpResponse getRegionsByIdResponse = HttpResponse.builder().statusCode(200) diff --git a/providers/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/features/DirectionalGroupApiExpectTest.java b/providers/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/features/DirectionalGroupApiExpectTest.java new file mode 100644 index 0000000000..c65bb42dcf --- /dev/null +++ b/providers/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/features/DirectionalGroupApiExpectTest.java @@ -0,0 +1,128 @@ +/** + * 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.net.HttpHeaders.HOST; +import static javax.ws.rs.HttpMethod.POST; +import static javax.ws.rs.core.Response.Status.OK; +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.DirectionalGroupCoordinates; +import org.jclouds.ultradns.ws.internal.BaseUltraDNSWSApiExpectTest; +import org.jclouds.ultradns.ws.parse.GetAccountLevelDirectionalGroupsResponseTest; +import org.jclouds.ultradns.ws.parse.GetAvailableGroupsResponseTest; +import org.jclouds.ultradns.ws.parse.GetDirectionalDNSGroupDetailsResponseTest; +import org.jclouds.ultradns.ws.parse.GetDirectionalDNSRecordsForHostResponseTest; +import org.testng.annotations.Test; + +/** + * @author Adrian Cole + */ +@Test(groups = "unit", testName = "DirectionalGroupApiExpectTest") +public class DirectionalGroupApiExpectTest extends BaseUltraDNSWSApiExpectTest { + + HttpRequest listGroupNamesByRecordNameAndType = HttpRequest.builder().method(POST) + .endpoint("https://ultra-api.ultradns.com:8443/UltraDNS_WS/v01") + .addHeader(HOST, "ultra-api.ultradns.com:8443") + .payload(payloadFromResourceWithContentType("/list_directionalgroup_names.xml", "application/xml")).build(); + + HttpResponse listGroupNamesByRecordNameAndTypeResponse = HttpResponse.builder().statusCode(OK.getStatusCode()) + + .payload(payloadFromResourceWithContentType("/directionalgroup_names.xml", "application/xml")).build(); + + public void testListGroupNamesByRecordNameAndTypeWhenResponseIs2xx() { + UltraDNSWSApi success = requestSendsResponse(listGroupNamesByRecordNameAndType, listGroupNamesByRecordNameAndTypeResponse); + + assertEquals(success.getDirectionalGroupApiForAccount("accountid").listGroupNamesByRecordNameAndType("www.jclouds.org.", 1).toString(), + new GetAvailableGroupsResponseTest().expected().toString()); + } + + HttpRequest listRecordsByGroupCoordinates = HttpRequest.builder().method(POST) + .endpoint("https://ultra-api.ultradns.com:8443/UltraDNS_WS/v01") + .addHeader(HOST, "ultra-api.ultradns.com:8443") + .payload(payloadFromResourceWithContentType("/list_directionalgroup_records.xml", "application/xml")).build(); + + HttpResponse listRecordsByGroupCoordinatesResponse = HttpResponse.builder().statusCode(OK.getStatusCode()) + + .payload(payloadFromResourceWithContentType("/directionalrecords.xml", "application/xml")).build(); + + public void testListRecordsByGroupCoordinatesWhenResponseIs2xx() { + UltraDNSWSApi success = requestSendsResponse(listRecordsByGroupCoordinates, listRecordsByGroupCoordinatesResponse); + + DirectionalGroupCoordinates group = DirectionalGroupCoordinates.builder() + .zoneName("jclouds.org.") + .recordName("www.jclouds.org.") + .recordType(1) + .groupName("EU-www.jclouds.org.").build(); + assertEquals( + success.getDirectionalGroupApiForAccount("accountid").listRecordsByGroupCoordinates(group).toString(), + new GetDirectionalDNSRecordsForHostResponseTest().expected().toString()); + } + + HttpRequest get = HttpRequest.builder().method(POST) + .endpoint("https://ultra-api.ultradns.com:8443/UltraDNS_WS/v01") + .addHeader(HOST, "ultra-api.ultradns.com:8443") + .payload(payloadFromResourceWithContentType("/get_directionalgroup.xml", "application/xml")).build(); + + HttpResponse getResponse = HttpResponse.builder().statusCode(OK.getStatusCode()) + + .payload(payloadFromResourceWithContentType("/directionalgroup.xml", "application/xml")).build(); + + public void testGetWhenResponseIs2xx() { + UltraDNSWSApi success = requestSendsResponse(get, getResponse); + + assertEquals(success.getDirectionalGroupApiForAccount("accountid").get("0000000000A").toString(), + new GetDirectionalDNSGroupDetailsResponseTest().expected().toString()); + } + + HttpRequest listAccountLevelGroups = HttpRequest.builder().method(POST) + .endpoint("https://ultra-api.ultradns.com:8443/UltraDNS_WS/v01") + .addHeader(HOST, "ultra-api.ultradns.com:8443") + .payload(payloadFromResourceWithContentType("/list_accountlevelgroups.xml", "application/xml")).build(); + + HttpResponse listAccountLevelGroupsResponse = HttpResponse.builder().statusCode(OK.getStatusCode()) + + .payload(payloadFromResourceWithContentType("/accountlevelgroups.xml", "application/xml")).build(); + + public void testListAccountLevelGroupsWhenResponseIs2xx() { + UltraDNSWSApi success = requestSendsResponse(listAccountLevelGroups, listAccountLevelGroupsResponse); + + assertEquals(success.getDirectionalGroupApiForAccount("accountid").listAccountLevelGroups().toString(), + new GetAccountLevelDirectionalGroupsResponseTest().expected().toString()); + } + + HttpRequest listRecordsByAccountLevelGroup = HttpRequest.builder().method(POST) + .endpoint("https://ultra-api.ultradns.com:8443/UltraDNS_WS/v01") + .addHeader(HOST, "ultra-api.ultradns.com:8443") + .payload(payloadFromResourceWithContentType("/list_accountlevelgroup_records.xml", "application/xml")).build(); + + HttpResponse listRecordsByAccountLevelGroupResponse = HttpResponse.builder().statusCode(OK.getStatusCode()) + + .payload(payloadFromResourceWithContentType("/directionalrecords.xml", "application/xml")).build(); + + public void testListRecordsByAccountLevelGroupWhenResponseIs2xx() { + UltraDNSWSApi success = requestSendsResponse(listRecordsByAccountLevelGroup, listRecordsByAccountLevelGroupResponse); + + assertEquals( + success.getDirectionalGroupApiForAccount("accountid").listRecordsByAccountLevelGroup("000000000000000A").toString(), + new GetDirectionalDNSRecordsForHostResponseTest().expected().toString()); + } +} diff --git a/providers/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/features/DirectionalGroupApiLiveTest.java b/providers/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/features/DirectionalGroupApiLiveTest.java new file mode 100644 index 0000000000..0f67e65b87 --- /dev/null +++ b/providers/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/features/DirectionalGroupApiLiveTest.java @@ -0,0 +1,126 @@ +/** + * 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 org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertTrue; + +import java.util.EnumSet; +import java.util.Set; + +import org.jclouds.rest.ResourceNotFoundException; +import org.jclouds.ultradns.ws.domain.Account; +import org.jclouds.ultradns.ws.domain.AccountLevelGroup; +import org.jclouds.ultradns.ws.domain.DirectionalGroupCoordinates; +import org.jclouds.ultradns.ws.domain.DirectionalGroupNameAndRegions; +import org.jclouds.ultradns.ws.domain.DirectionalPool; +import org.jclouds.ultradns.ws.domain.DirectionalRecordDetail; +import org.jclouds.ultradns.ws.domain.DirectionalRecordType; +import org.jclouds.ultradns.ws.domain.Zone; +import org.jclouds.ultradns.ws.internal.BaseUltraDNSWSApiLiveTest; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import com.google.common.collect.Sets; + +/** + * @author Adrian Cole + */ +@Test(groups = "live", singleThreaded = true, testName = "DirectionalGroupApiLiveTest") +public class DirectionalGroupApiLiveTest extends BaseUltraDNSWSApiLiveTest { + + private Account account; + + @Override + @BeforeClass(groups = { "integration", "live" }) + public void setup() { + super.setup(); + account = api.getCurrentAccount(); + } + + @Test + public void testListAccountLevelGroups() { + for (AccountLevelGroup group : api().listAccountLevelGroups()) { + checkGroup(group); + } + } + + private void checkGroup(AccountLevelGroup group) { + assertNotNull(group.getId(), "Id cannot be null " + group); + assertNotNull(group.getName(), "Name cannot be null " + group); + assertNotNull(group.getType(), "Type cannot be null " + group); + assertTrue(group.getRecordCount() >= 0, "RecordCount must be positive " + group); + } + + @Test + public void testListRecordsByAccountLevelGroup() { + for (AccountLevelGroup group : api().listAccountLevelGroups()) { + for (DirectionalRecordDetail rr : api().listRecordsByAccountLevelGroup(group.getId())) { + DirectionalPoolApiLiveTest.checkDirectionalRecordDetail(rr); + } + } + } + + @Test + public void testGetDirectionalGroup() { + for (AccountLevelGroup group : api().listAccountLevelGroups()) { + DirectionalGroupNameAndRegions withRegions = api().get(group.getId()); + assertEquals(withRegions.getName(), group.getName()); + assertTrue(withRegions.size() > 0); + } + } + + Set allGroups = Sets.newLinkedHashSet(); + + @Test + public void testListGroupNamesByRecordNameAndType() { + for (Zone zone : api.getZoneApi().listByAccount(account.getId())) { + for (DirectionalPool pool : api.getDirectionalPoolApiForZone(zone.getName()).list()) { + for (DirectionalRecordType type : EnumSet.allOf(DirectionalRecordType.class)) { + for (String groupName : api().listGroupNamesByRecordNameAndType(pool.getName(), type.getCode())) { + allGroups.add(DirectionalGroupCoordinates.builder() + .zoneName(zone.getName()) + .recordName(pool.getName()) + .recordType(type.getCode()) + .groupName(groupName).build()); + } + } + } + } + } + + @Test(dependsOnMethods = "testListGroupNamesByRecordNameAndType") + public void testListRecordsByGroupCoordinates() { + for (DirectionalGroupCoordinates group : allGroups) { + for (DirectionalRecordDetail rr : api().listRecordsByGroupCoordinates(group)) { + DirectionalPoolApiLiveTest.checkDirectionalRecordDetail(rr); + } + } + } + + @Test(expectedExceptions = ResourceNotFoundException.class, expectedExceptionsMessageRegExp = "Group does not exist.") + public void testListRecordsByAccountLevelGroupWhenGroupIdNotFound() { + api().listRecordsByAccountLevelGroup("AAAAAAAAAAAAAAAA"); + } + + private DirectionalGroupApi api() { + return api.getDirectionalGroupApiForAccount(account.getId()); + } +} diff --git a/providers/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/features/DirectionalPoolApiExpectTest.java b/providers/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/features/DirectionalPoolApiExpectTest.java index 63c027a3d9..72a9814cde 100644 --- a/providers/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/features/DirectionalPoolApiExpectTest.java +++ b/providers/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/features/DirectionalPoolApiExpectTest.java @@ -17,7 +17,9 @@ * under the License. */ package org.jclouds.ultradns.ws.features; - +import static com.google.common.net.HttpHeaders.HOST; +import static javax.ws.rs.HttpMethod.POST; +import static javax.ws.rs.core.Response.Status.OK; import static org.testng.Assert.assertEquals; import org.jclouds.http.HttpRequest; @@ -34,12 +36,13 @@ import org.testng.annotations.Test; @Test(groups = "unit", testName = "DirectionalPoolApiExpectTest") public class DirectionalPoolApiExpectTest extends BaseUltraDNSWSApiExpectTest { - HttpRequest list = HttpRequest.builder().method("POST") + HttpRequest list = HttpRequest.builder().method(POST) .endpoint("https://ultra-api.ultradns.com:8443/UltraDNS_WS/v01") - .addHeader("Host", "ultra-api.ultradns.com:8443") + .addHeader(HOST, "ultra-api.ultradns.com:8443") .payload(payloadFromResourceWithContentType("/list_directionalpools.xml", "application/xml")).build(); - HttpResponse listResponse = HttpResponse.builder().statusCode(200) + HttpResponse listResponse = HttpResponse.builder().statusCode(OK.getStatusCode()) + .payload(payloadFromResourceWithContentType("/directionalpools.xml", "application/xml")).build(); public void testListWhenResponseIs2xx() { @@ -49,12 +52,13 @@ public class DirectionalPoolApiExpectTest extends BaseUltraDNSWSApiExpectTest { new GetDirectionalPoolsByZoneResponseTest().expected().toString()); } - HttpRequest listRecords = HttpRequest.builder().method("POST") + HttpRequest listRecords = HttpRequest.builder().method(POST) .endpoint("https://ultra-api.ultradns.com:8443/UltraDNS_WS/v01") - .addHeader("Host", "ultra-api.ultradns.com:8443") + .addHeader(HOST, "ultra-api.ultradns.com:8443") .payload(payloadFromResourceWithContentType("/list_directionalrecords.xml", "application/xml")).build(); - HttpResponse listRecordsResponse = HttpResponse.builder().statusCode(200) + HttpResponse listRecordsResponse = HttpResponse.builder().statusCode(OK.getStatusCode()) + .payload(payloadFromResourceWithContentType("/directionalrecords.xml", "application/xml")).build(); public void testListRecordsWhenResponseIs2xx() { diff --git a/providers/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/features/DirectionalPoolApiLiveTest.java b/providers/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/features/DirectionalPoolApiLiveTest.java index 2076b018a5..b7929c03f8 100644 --- a/providers/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/features/DirectionalPoolApiLiveTest.java +++ b/providers/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/features/DirectionalPoolApiLiveTest.java @@ -93,7 +93,6 @@ public class DirectionalPoolApiLiveTest extends BaseUltraDNSWSApiLiveTest { allDirectionalGroups.add(group); assertNotNull(group.getId(), "Id cannot be null " + group); assertNotNull(group.getName(), "Name cannot be null " + group); - assertNotNull(group.getDescription(), "Description cannot be null " + group); } assertEquals(rr.getZoneName(), zone.getName()); assertEquals(rr.getName(), pool.getName()); @@ -104,8 +103,7 @@ public class DirectionalPoolApiLiveTest extends BaseUltraDNSWSApiLiveTest { assertNull(rr.getSourceIpGroup().orNull(), "SourceIpGroup must be absent " + rr); break; case SOURCEIP: - assertNotNull(rr.getSourceIpGroup().or(rr.getGroup()).orNull(), - "SourceIpGroup or Group must be present " + rr); + assertNotNull(rr.getSourceIpGroup().orNull(), "SourceIpGroup must be present " + rr); assertNull(rr.getGeolocationGroup().orNull(), "GeolocationGroup must be absent " + rr); break; case MIXED: diff --git a/providers/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/handlers/UltraDNSWSErrorHandlerTest.java b/providers/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/handlers/UltraDNSWSErrorHandlerTest.java index 876588c934..bc71fee0da 100644 --- a/providers/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/handlers/UltraDNSWSErrorHandlerTest.java +++ b/providers/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/handlers/UltraDNSWSErrorHandlerTest.java @@ -240,6 +240,30 @@ public class UltraDNSWSErrorHandlerTest { assertEquals(exception.getError().getCode(), 2911); } + @Test + public void testCode2142SetsResourceNotFoundException() 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(INTERNAL_SERVER_ERROR.getReasonPhrase()) + .statusCode(INTERNAL_SERVER_ERROR.getStatusCode()) + .payload(payloadFromResource("/directionalpool_doesnt_exist.xml")).build(); + + function.handleError(command, response); + + assertEquals(command.getException().getClass(), ResourceNotFoundException.class); + assertEquals(command.getException().getMessage(), "No Pool or Multiple pools of same type exists for the PoolName : foo.jclouds.org."); + + UltraDNSWSResponseException exception = UltraDNSWSResponseException.class.cast(command.getException().getCause()); + + assertEquals(exception.getMessage(), "Error 2142: No Pool or Multiple pools of same type exists for the PoolName : foo.jclouds.org."); + assertEquals(exception.getError().getDescription().get(), "No Pool or Multiple pools of same type exists for the PoolName : foo.jclouds.org."); + assertEquals(exception.getError().getCode(), 2142); + } + @Test public void testCode2912SetsResourceAlreadyExistsException() throws IOException { HttpRequest request = HttpRequest.builder().method(POST) @@ -291,6 +315,30 @@ public class UltraDNSWSErrorHandlerTest { assertEquals(exception.getError().getCode(), 3101); } + @Test + public void testCode4003SetsResourceNotFoundException() 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_tcrecord.xml")).build(); + HttpCommand command = new HttpCommand(request); + HttpResponse response = HttpResponse.builder() + .message(INTERNAL_SERVER_ERROR.getReasonPhrase()) + .statusCode(INTERNAL_SERVER_ERROR.getStatusCode()) + .payload(payloadFromResource("/directionalgroup_doesnt_exist.xml")).build(); + + function.handleError(command, response); + + assertEquals(command.getException().getClass(), ResourceNotFoundException.class); + assertEquals(command.getException().getMessage(), "Group does not exist."); + + UltraDNSWSResponseException exception = UltraDNSWSResponseException.class.cast(command.getException().getCause()); + + assertEquals(exception.getMessage(), "Error 4003: Group does not exist."); + assertEquals(exception.getError().getDescription().get(), "Group does not exist."); + assertEquals(exception.getError().getCode(), 4003); + } + private Payload payloadFromResource(String resource) { try { return payloadFromStringWithContentType(toStringAndClose(getClass().getResourceAsStream(resource)), diff --git a/providers/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/parse/GetAccountLevelDirectionalGroupsResponseTest.java b/providers/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/parse/GetAccountLevelDirectionalGroupsResponseTest.java new file mode 100644 index 0000000000..4a3fede587 --- /dev/null +++ b/providers/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/parse/GetAccountLevelDirectionalGroupsResponseTest.java @@ -0,0 +1,69 @@ +/** + * 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 WADirectionalANTIES 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.AccountLevelGroup; +import org.jclouds.ultradns.ws.domain.DirectionalPool.Type; +import org.jclouds.ultradns.ws.xml.AccountLevelGroupsHandler; +import org.testng.annotations.Test; + +import com.google.common.collect.FluentIterable; +import com.google.common.collect.ImmutableList; + +/** + * @author Adrian Cole + */ +@Test(testName = "GetAccountLevelDirectionalGroupsResponseTest") +public class GetAccountLevelDirectionalGroupsResponseTest extends BaseHandlerTest { + + public void test() { + InputStream is = getClass().getResourceAsStream("/accountlevelgroups.xml"); + + FluentIterable expected = expected(); + + AccountLevelGroupsHandler handler = injector.getInstance(AccountLevelGroupsHandler.class); + FluentIterable result = factory.create(handler).parse(is); + + assertEquals(result.toSet().toString(), expected.toSet().toString()); + } + + public FluentIterable expected() { + return FluentIterable.from(ImmutableList. builder() + .add(AccountLevelGroup.builder() + .id("000000000000000A") + .name("ASIA") + .type(Type.GEOLOCATION) + .recordCount(0).build()) + .add(AccountLevelGroup.builder() + .id("000000000000000B") + .name("EU") + .type(Type.GEOLOCATION) + .recordCount(3).build()) + .add(AccountLevelGroup.builder() + .id("000000000000000C") + .name("LATAM") + .type(Type.GEOLOCATION) + .recordCount(1).build()).build()); + } +} \ No newline at end of file diff --git a/providers/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/parse/GetAvailableGroupsResponseTest.java b/providers/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/parse/GetAvailableGroupsResponseTest.java new file mode 100644 index 0000000000..79df598fcd --- /dev/null +++ b/providers/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/parse/GetAvailableGroupsResponseTest.java @@ -0,0 +1,52 @@ +/** + * 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 WADirectionalANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.ultradns.ws.parse; + +import static org.testng.Assert.assertEquals; + +import java.io.InputStream; + +import org.jclouds.http.functions.BaseHandlerTest; +import org.jclouds.ultradns.ws.xml.ItemListHandler; +import org.testng.annotations.Test; + +import com.google.common.collect.FluentIterable; +import com.google.common.collect.ImmutableSet; + +/** + * @author Adrian Cole + */ +@Test(testName = "GetAvailableGroupsResponseTest") +public class GetAvailableGroupsResponseTest extends BaseHandlerTest { + + public void test() { + InputStream is = getClass().getResourceAsStream("/directionalgroup_names.xml"); + + FluentIterable expected = expected(); + + ItemListHandler handler = injector.getInstance(ItemListHandler.class); + FluentIterable result = factory.create(handler).parse(is); + + assertEquals(result.toSet().toString(), expected.toSet().toString()); + } + + public FluentIterable expected() { + return FluentIterable.from(ImmutableSet.of("EU-foo.jclouds.org.", "non-foo.jclouds.org.")); + } +} \ No newline at end of file diff --git a/providers/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/parse/GetDirectionalDNSGroupDetailsResponseTest.java b/providers/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/parse/GetDirectionalDNSGroupDetailsResponseTest.java new file mode 100644 index 0000000000..85ff3bfc63 --- /dev/null +++ b/providers/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/parse/GetDirectionalDNSGroupDetailsResponseTest.java @@ -0,0 +1,63 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WADirectionalANTIES 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.DirectionalGroupNameAndRegions; +import org.jclouds.ultradns.ws.domain.Region; +import org.jclouds.ultradns.ws.xml.DirectionalGroupNameAndRegionsHandler; +import org.testng.annotations.Test; + +/** + * @author Adrian Cole + */ +@Test(testName = "GetDirectionalDNSGroupDetailsResponseTest") +public class GetDirectionalDNSGroupDetailsResponseTest extends BaseHandlerTest { + + public void test() { + InputStream is = getClass().getResourceAsStream("/directionalgroup.xml"); + + DirectionalGroupNameAndRegions expected = expected(); + + DirectionalGroupNameAndRegionsHandler handler = injector.getInstance(DirectionalGroupNameAndRegionsHandler.class); + DirectionalGroupNameAndRegions result = factory.create(handler).parse(is); + + assertEquals(result.toString(), expected.toString()); + } + + public DirectionalGroupNameAndRegions expected() { + return DirectionalGroupNameAndRegions.builder() + .name("NON-EU") + .addRegion(Region.builder() + .name("Anonymous Proxy (A1)") + .addTerritoryName("Anonymous Proxy").build()) + .addRegion(Region.builder() + .name("Mexico") + .addTerritoryName("Mexico").build()) + .addRegion(Region.builder() + .name("Antarctica") + .addTerritoryName("Bouvet Island") + .addTerritoryName("French Southern Territories") + .addTerritoryName("Antarctica").build()).build(); + } +} \ No newline at end of file diff --git a/providers/ultradns-ws/src/test/resources/accountlevelgroup_records.xml b/providers/ultradns-ws/src/test/resources/accountlevelgroup_records.xml new file mode 100644 index 0000000000..bcd3b3c70b --- /dev/null +++ b/providers/ultradns-ws/src/test/resources/accountlevelgroup_records.xml @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/providers/ultradns-ws/src/test/resources/accountlevelgroups.xml b/providers/ultradns-ws/src/test/resources/accountlevelgroups.xml new file mode 100644 index 0000000000..0bd948f16f --- /dev/null +++ b/providers/ultradns-ws/src/test/resources/accountlevelgroups.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/providers/ultradns-ws/src/test/resources/directionalgroup.xml b/providers/ultradns-ws/src/test/resources/directionalgroup.xml new file mode 100644 index 0000000000..e0dcf52f59 --- /dev/null +++ b/providers/ultradns-ws/src/test/resources/directionalgroup.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/providers/ultradns-ws/src/test/resources/directionalgroup_doesnt_exist.xml b/providers/ultradns-ws/src/test/resources/directionalgroup_doesnt_exist.xml new file mode 100644 index 0000000000..1052273ba7 --- /dev/null +++ b/providers/ultradns-ws/src/test/resources/directionalgroup_doesnt_exist.xml @@ -0,0 +1,16 @@ + + + + soap:Server + Fault occurred while processing. + + + 4003 + Group does not exist. + + + + + \ No newline at end of file diff --git a/providers/ultradns-ws/src/test/resources/directionalgroup_names.xml b/providers/ultradns-ws/src/test/resources/directionalgroup_names.xml new file mode 100644 index 0000000000..a936a75f7d --- /dev/null +++ b/providers/ultradns-ws/src/test/resources/directionalgroup_names.xml @@ -0,0 +1,13 @@ + + + + + + EU-foo.jclouds.org. + non-foo.jclouds.org. + + + + \ No newline at end of file diff --git a/providers/ultradns-ws/src/test/resources/directionalpools.xml b/providers/ultradns-ws/src/test/resources/directionalpools.xml index 1dc04a86d1..05206c54a7 100644 --- a/providers/ultradns-ws/src/test/resources/directionalpools.xml +++ b/providers/ultradns-ws/src/test/resources/directionalpools.xml @@ -11,4 +11,4 @@ - \ No newline at end of file + diff --git a/providers/ultradns-ws/src/test/resources/get_directionalgroup.xml b/providers/ultradns-ws/src/test/resources/get_directionalgroup.xml new file mode 100644 index 0000000000..d391d6a656 --- /dev/null +++ b/providers/ultradns-ws/src/test/resources/get_directionalgroup.xml @@ -0,0 +1 @@ +identitycredential0000000000A \ No newline at end of file diff --git a/providers/ultradns-ws/src/test/resources/group_doesnt_exist.xml b/providers/ultradns-ws/src/test/resources/group_doesnt_exist.xml new file mode 100644 index 0000000000..1052273ba7 --- /dev/null +++ b/providers/ultradns-ws/src/test/resources/group_doesnt_exist.xml @@ -0,0 +1,16 @@ + + + + soap:Server + Fault occurred while processing. + + + 4003 + Group does not exist. + + + + + \ No newline at end of file diff --git a/providers/ultradns-ws/src/test/resources/list_accountlevelgroup_records.xml b/providers/ultradns-ws/src/test/resources/list_accountlevelgroup_records.xml new file mode 100644 index 0000000000..51f715955a --- /dev/null +++ b/providers/ultradns-ws/src/test/resources/list_accountlevelgroup_records.xml @@ -0,0 +1 @@ +identitycredential000000000000000A \ No newline at end of file diff --git a/providers/ultradns-ws/src/test/resources/list_accountlevelgroups.xml b/providers/ultradns-ws/src/test/resources/list_accountlevelgroups.xml new file mode 100644 index 0000000000..a4ea9e2e3a --- /dev/null +++ b/providers/ultradns-ws/src/test/resources/list_accountlevelgroups.xml @@ -0,0 +1 @@ +identitycredentialaccountid \ No newline at end of file diff --git a/providers/ultradns-ws/src/test/resources/list_directionalgroup_names.xml b/providers/ultradns-ws/src/test/resources/list_directionalgroup_names.xml new file mode 100644 index 0000000000..2e601216ea --- /dev/null +++ b/providers/ultradns-ws/src/test/resources/list_directionalgroup_names.xml @@ -0,0 +1 @@ +identitycredentialwww.jclouds.org.1accountid \ No newline at end of file diff --git a/providers/ultradns-ws/src/test/resources/list_directionalgroup_records.xml b/providers/ultradns-ws/src/test/resources/list_directionalgroup_records.xml new file mode 100644 index 0000000000..25625c178c --- /dev/null +++ b/providers/ultradns-ws/src/test/resources/list_directionalgroup_records.xml @@ -0,0 +1 @@ +identitycredentialEU-www.jclouds.org.www.jclouds.org.jclouds.org.1 \ No newline at end of file