added ability to read directional groups in ultradns

This commit is contained in:
adriancole 2013-04-07 22:05:26 -07:00
parent ec439c65b7
commit 4130db4f43
34 changed files with 1438 additions and 42 deletions

View File

@ -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.
*

View File

@ -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 = "<v01:getDirectionalDNSRecordsForGroup><groupName>{groupName}</groupName><hostName>{recordName}</hostName><zoneName>{zoneName}</zoneName><poolRecordType>{recordType}</poolRecordType></v01:getDirectionalDNSRecordsForGroup>";
@SuppressWarnings("unchecked")
@Override
public <R extends HttpRequest> R bindToRequest(R request, Object in) {
DirectionalGroupCoordinates group = DirectionalGroupCoordinates.class.cast(in);
ImmutableMap<String, Object> variables = ImmutableMap.<String, Object> 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();
}
}

View File

@ -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);
}
}
}

View File

@ -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<String> description;
private DirectionalGroup(String id, String name, Optional<String> 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<String> 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<String> 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);
}
}
}

View File

@ -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);
}
}
}

View File

@ -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<Region> {
private final String name;
private final Set<Region> regions;
private DirectionalGroupNameAndRegions(String name, Set<Region> regions) {
this.name = checkNotNull(name, "name");
this.regions = checkNotNull(regions, "regions of %s", name);
}
public String getName() {
return name;
}
public Set<Region> getRegions() {
return regions;
}
@Override
protected Set<Region> 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<Region> regions = ImmutableSet.<Region> 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<Region> regions) {
this.regions = ImmutableSet.<Region> 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());
}
}
}

View File

@ -62,14 +62,23 @@ public class DirectionalRecordDetail {
return id;
}
/**
* group containing all regions that you have not specifically configured in {@link #getGeolocationGroup()}
*/
public Optional<DirectionalGroup> getGroup() {
return group;
}
/**
* group containing territories.
*/
public Optional<DirectionalGroup> getGeolocationGroup() {
return geolocationGroup;
}
/**
* group containing IPV4 or IPV6 ranges.
*/
public Optional<DirectionalGroup> getSourceIpGroup() {
return sourceIpGroup;
}

View File

@ -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 <a href="https://ultra-api.ultradns.com:8443/UltraDNS_WS/v01?wsdl" />
* @see <a href="https://www.ultradns.net/api/NUS_API_XML_SOAP.pdf" />
* @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("<v01:getDirectionalDNSGroupDetails><GroupId>{GroupId}</GroupId></v01:getDirectionalDNSGroupDetails>")
@Nullable
DirectionalGroupNameAndRegions get(@PayloadParam("GroupId") String groupId);
/**
* Returns all account-level groups.
*
*/
@Named("getAccountLevelDirectionalGroupsOfZone")
@POST
@XMLResponseParser(AccountLevelGroupsHandler.class)
@Payload("<v01:getAccountLevelDirectionalGroups><accountId>{accountId}</accountId><GroupType /></v01:getAccountLevelDirectionalGroups>")
FluentIterable<AccountLevelGroup> 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("<v01:getDirectionalDNSRecordsForAcctLvlGroup><groupId>{groupId}</groupId></v01:getDirectionalDNSRecordsForAcctLvlGroup>")
FluentIterable<DirectionalRecordDetail> 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("<v01:getAvailableGroups><poolName>{hostName}</poolName><poolRecordType>{rrType}</poolRecordType><accountID>{accountId}</accountID><groupType /></v01:getAvailableGroups>")
FluentIterable<String> 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<DirectionalRecordDetail> listRecordsByGroupCoordinates(
@BinderParam(DirectionalGroupCoordinatesToXML.class) DirectionalGroupCoordinates group)
throws ResourceNotFoundException;
}

View File

@ -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:

View File

@ -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<FluentIterable<AccountLevelGroup>> {
private final Builder<AccountLevelGroup> groups = ImmutableSet.<AccountLevelGroup> builder();
@Override
public FluentIterable<AccountLevelGroup> getResult() {
return FluentIterable.from(groups.build());
}
@Override
public void startElement(String url, String name, String qName, Attributes attrs) {
if (equalsOrSuffix(qName, "AccountLevelGroups")) {
Map<String, String> 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());
}
}
}

View File

@ -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<DirectionalGroupNameAndRegions> {
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<String> territories = Splitter.on(';').split(attrs.getValue("TerritoryName"));
Region region = Region.builder()
.name(attrs.getValue("RegionName"))
.territoryNames(territories).build();
group.addRegion(region);
}
}
}

View File

@ -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"));

View File

@ -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<FluentIterable<String>> {
private StringBuilder currentText = new StringBuilder();
private Builder<String> items = ImmutableSet.<String> builder();
@Override
public FluentIterable<String> 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);
}
}

View File

@ -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)

View File

@ -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());
}
}

View File

@ -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<DirectionalGroupCoordinates> 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());
}
}

View File

@ -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() {

View File

@ -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:

View File

@ -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)),

View File

@ -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<AccountLevelGroup> expected = expected();
AccountLevelGroupsHandler handler = injector.getInstance(AccountLevelGroupsHandler.class);
FluentIterable<AccountLevelGroup> result = factory.create(handler).parse(is);
assertEquals(result.toSet().toString(), expected.toSet().toString());
}
public FluentIterable<AccountLevelGroup> expected() {
return FluentIterable.from(ImmutableList.<AccountLevelGroup> 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());
}
}

View File

@ -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<String> expected = expected();
ItemListHandler handler = injector.getInstance(ItemListHandler.class);
FluentIterable<String> result = factory.create(handler).parse(is);
assertEquals(result.toSet().toString(), expected.toSet().toString());
}
public FluentIterable<String> expected() {
return FluentIterable.from(ImmutableSet.of("EU-foo.jclouds.org.", "non-foo.jclouds.org."));
}
}

View File

@ -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();
}
}

View File

@ -0,0 +1,37 @@
<?xml version="1.0"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<ns1:getDirectionalDNSRecordsForAcctLvlGroupResponse
xmlns:ns1="http://webservice.api.ultra.neustar.com/v01/">
<DirectionalDNSRecordDetailList
xmlns:ns2="http://schema.ultraservice.neustar.com/v01/">
<ns2:DirectionalDNSRecordDetail
DirPoolRecordId="06023D94130C8F89" ZoneName="netflix.com."
DName="ccs-int-eu.netflix.com.">
<ns2:DirectionalDNSRecord recordType="CNAME"
TTL="3600" noResponseRecord="false">
<ns2:InfoValues
Info1Value="ccs-int-frontend-1181536117.eu-west-1.elb.amazonaws.com." />
</ns2:DirectionalDNSRecord>
</ns2:DirectionalDNSRecordDetail>
<ns2:DirectionalDNSRecordDetail
DirPoolRecordId="06023D94130C8F61" ZoneName="netflix.com." DName="ccs-int.netflix.com.">
<ns2:DirectionalDNSRecord recordType="CNAME"
TTL="3600" noResponseRecord="false">
<ns2:InfoValues
Info1Value="ccs-int-frontend-1181536117.eu-west-1.elb.amazonaws.com." />
</ns2:DirectionalDNSRecord>
</ns2:DirectionalDNSRecordDetail>
<ns2:DirectionalDNSRecordDetail
DirPoolRecordId="06023D161000DE02" ZoneName="netflix.com."
DName="nrdpv6.nccp.netflix.com.">
<ns2:DirectionalDNSRecord recordType="CNAME"
TTL="3600" noResponseRecord="false">
<ns2:InfoValues
Info1Value="dualstack.nccp-wildcard-nccp-netflix-com-1840524669.eu-west-1.elb.amazonaws.com." />
</ns2:DirectionalDNSRecord>
</ns2:DirectionalDNSRecordDetail>
</DirectionalDNSRecordDetailList>
</ns1:getDirectionalDNSRecordsForAcctLvlGroupResponse>
</soap:Body>
</soap:Envelope>

View File

@ -0,0 +1,15 @@
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<ns1:getAccountLevelDirectionalGroupsResponse
xmlns:ns1="http://webservice.api.ultra.neustar.com/v01/">
<GroupsList xmlns:ns2="http://schema.ultraservice.neustar.com/v01/">
<ns2:AccountLevelGroups GroupId="000000000000000A"
GroupName="ASIA" RecordsCount="0" GroupType="GEOLOCATION" />
<ns2:AccountLevelGroups GroupId="000000000000000B"
GroupName="EU" RecordsCount="3" GroupType="GEOLOCATION" />
<ns2:AccountLevelGroups GroupId="000000000000000C"
GroupName="LATAM" RecordsCount="1" GroupType="GEOLOCATION" />
</GroupsList>
</ns1:getAccountLevelDirectionalGroupsResponse>
</soap:Body>
</soap:Envelope>

View File

@ -0,0 +1,18 @@
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<ns1:getDirectionalDNSGroupDetailsResponse
xmlns:ns1="http://webservice.api.ultra.neustar.com/v01/">
<DirectionalDNSGroupDetail
xmlns:ns2="http://schema.ultraservice.neustar.com/v01/" GroupName="NON-EU">
<ns2:DirectionalDNSRegion>
<ns2:RegionForNewGroups RegionName="Anonymous Proxy (A1)"
TerritoryName="Anonymous Proxy" />
<ns2:RegionForNewGroups RegionName="Mexico"
TerritoryName="Mexico" />
<ns2:RegionForNewGroups RegionName="Antarctica"
TerritoryName="Bouvet Island;French Southern Territories;Antarctica" />
</ns2:DirectionalDNSRegion>
</DirectionalDNSGroupDetail>
</ns1:getDirectionalDNSGroupDetailsResponse>
</soap:Body>
</soap:Envelope>

View File

@ -0,0 +1,16 @@
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<soap:Fault>
<faultcode>soap:Server</faultcode>
<faultstring>Fault occurred while processing.</faultstring>
<detail>
<ns1:UltraWSException xmlns:ns1="http://webservice.api.ultra.neustar.com/v01/">
<errorCode xmlns:ns2="http://schema.ultraservice.neustar.com/v01/"
xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:type="xs:int">4003</errorCode>
<errorDescription xmlns:ns2="http://schema.ultraservice.neustar.com/v01/">Group does not exist.</errorDescription>
</ns1:UltraWSException>
</detail>
</soap:Fault>
</soap:Body>
</soap:Envelope>

View File

@ -0,0 +1,13 @@
<?xml version="1.0"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<ns1:getAvailableGroupsResponse
xmlns:ns1="http://webservice.api.ultra.neustar.com/v01/">
<DirectionalDNSAvailableGroups
xmlns:ns2="http://schema.ultraservice.neustar.com/v01/">
<item>EU-foo.jclouds.org.</item>
<item>non-foo.jclouds.org.</item>
</DirectionalDNSAvailableGroups>
</ns1:getAvailableGroupsResponse>
</soap:Body>
</soap:Envelope>

View File

@ -0,0 +1 @@
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v01="http://webservice.api.ultra.neustar.com/v01/"><soapenv:Header><wsse:Security soapenv:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"><wsse:UsernameToken><wsse:Username>identity</wsse:Username><wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">credential</wsse:Password></wsse:UsernameToken></wsse:Security></soapenv:Header><soapenv:Body><v01:getDirectionalDNSGroupDetails><GroupId>0000000000A</GroupId></v01:getDirectionalDNSGroupDetails></soapenv:Body></soapenv:Envelope>

View File

@ -0,0 +1,16 @@
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<soap:Fault>
<faultcode>soap:Server</faultcode>
<faultstring>Fault occurred while processing.</faultstring>
<detail>
<ns1:UltraWSException xmlns:ns1="http://webservice.api.ultra.neustar.com/v01/">
<errorCode xmlns:ns2="http://schema.ultraservice.neustar.com/v01/"
xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:type="xs:int">4003</errorCode>
<errorDescription xmlns:ns2="http://schema.ultraservice.neustar.com/v01/">Group does not exist.</errorDescription>
</ns1:UltraWSException>
</detail>
</soap:Fault>
</soap:Body>
</soap:Envelope>

View File

@ -0,0 +1 @@
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v01="http://webservice.api.ultra.neustar.com/v01/"><soapenv:Header><wsse:Security soapenv:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"><wsse:UsernameToken><wsse:Username>identity</wsse:Username><wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">credential</wsse:Password></wsse:UsernameToken></wsse:Security></soapenv:Header><soapenv:Body><v01:getDirectionalDNSRecordsForAcctLvlGroup><groupId>000000000000000A</groupId></v01:getDirectionalDNSRecordsForAcctLvlGroup></soapenv:Body></soapenv:Envelope>

View File

@ -0,0 +1 @@
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v01="http://webservice.api.ultra.neustar.com/v01/"><soapenv:Header><wsse:Security soapenv:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"><wsse:UsernameToken><wsse:Username>identity</wsse:Username><wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">credential</wsse:Password></wsse:UsernameToken></wsse:Security></soapenv:Header><soapenv:Body><v01:getAccountLevelDirectionalGroups><accountId>accountid</accountId><GroupType /></v01:getAccountLevelDirectionalGroups></soapenv:Body></soapenv:Envelope>

View File

@ -0,0 +1 @@
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v01="http://webservice.api.ultra.neustar.com/v01/"><soapenv:Header><wsse:Security soapenv:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"><wsse:UsernameToken><wsse:Username>identity</wsse:Username><wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">credential</wsse:Password></wsse:UsernameToken></wsse:Security></soapenv:Header><soapenv:Body><v01:getAvailableGroups><poolName>www.jclouds.org.</poolName><poolRecordType>1</poolRecordType><accountID>accountid</accountID><groupType /></v01:getAvailableGroups></soapenv:Body></soapenv:Envelope>

View File

@ -0,0 +1 @@
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v01="http://webservice.api.ultra.neustar.com/v01/"><soapenv:Header><wsse:Security soapenv:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"><wsse:UsernameToken><wsse:Username>identity</wsse:Username><wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">credential</wsse:Password></wsse:UsernameToken></wsse:Security></soapenv:Header><soapenv:Body><v01:getDirectionalDNSRecordsForGroup><groupName>EU-www.jclouds.org.</groupName><hostName>www.jclouds.org.</hostName><zoneName>jclouds.org.</zoneName><poolRecordType>1</poolRecordType></v01:getDirectionalDNSRecordsForGroup></soapenv:Body></soapenv:Envelope>