mirror of https://github.com/apache/jclouds.git
Merge pull request #1412 from jclouds/ultradns-remove_recordmap
removed problematic record type mapping code
This commit is contained in:
commit
10827445f7
|
@ -1,160 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.jclouds.ultradns.ws;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.util.EnumSet;
|
||||
import java.util.Set;
|
||||
|
||||
import com.google.common.annotations.Beta;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.BiMap;
|
||||
import com.google.common.collect.ForwardingMap;
|
||||
import com.google.common.collect.ImmutableBiMap;
|
||||
|
||||
/**
|
||||
* Most UltraDNS commands use the numerical type value of a resource record
|
||||
* rather than their names. This class helps convert the numerical values to
|
||||
* what people more commonly use. Note that this does not complain a complete
|
||||
* mapping and may need updates over time.
|
||||
*
|
||||
* @author Adrian Cole
|
||||
* @see org.jclouds.rest.annotations.ParamParser
|
||||
*/
|
||||
@Beta
|
||||
public class ResourceTypeToValue extends ForwardingMap<String, Integer> implements Function<Object, String>,
|
||||
BiMap<String, Integer> {
|
||||
|
||||
/**
|
||||
* look up the value (ex. {@code 28}) for the mnemonic name (ex. {@code AAAA}
|
||||
* ).
|
||||
*
|
||||
* @param type
|
||||
* type to look up. ex {@code AAAA}
|
||||
* @throws IllegalArgumentException
|
||||
* if the type was not configured.
|
||||
*/
|
||||
public static Integer lookup(String type) throws IllegalArgumentException {
|
||||
checkNotNull(type, "resource type was null");
|
||||
checkArgument(lookup.containsKey(type), "%s do not include %s; types: %s", ResourceTypes.class.getSimpleName(),
|
||||
type, EnumSet.allOf(ResourceTypes.class));
|
||||
return lookup.get(type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Taken from <a href=
|
||||
* "http://www.iana.org/assignments/dns-parameters/dns-parameters.xml#dns-parameters-3"
|
||||
* >iana types</a>.
|
||||
*
|
||||
*/
|
||||
// enum only to look and format prettier than fluent bimap builder calls
|
||||
private static enum ResourceTypes {
|
||||
/**
|
||||
* a host address
|
||||
*/
|
||||
A(1),
|
||||
|
||||
/**
|
||||
* an authoritative name server
|
||||
*/
|
||||
NS(2),
|
||||
|
||||
/**
|
||||
* the canonical name for an alias
|
||||
*/
|
||||
CNAME(5),
|
||||
|
||||
/**
|
||||
* marks the start of a zone of authority
|
||||
*/
|
||||
SOA(6),
|
||||
|
||||
/**
|
||||
* a domain name pointer
|
||||
*/
|
||||
PTR(12),
|
||||
|
||||
/**
|
||||
* mail exchange
|
||||
*/
|
||||
MX(15),
|
||||
|
||||
/**
|
||||
* text strings
|
||||
*/
|
||||
TXT(16),
|
||||
|
||||
/**
|
||||
* IP6 Address
|
||||
*/
|
||||
AAAA(28),
|
||||
|
||||
/**
|
||||
* Server Selection
|
||||
*/
|
||||
SRV(33);
|
||||
|
||||
private final int value;
|
||||
|
||||
private ResourceTypes(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ImmutableBiMap<String, Integer> delegate() {
|
||||
return lookup;
|
||||
}
|
||||
|
||||
private static final ImmutableBiMap<String, Integer> lookup;
|
||||
|
||||
static {
|
||||
ImmutableBiMap.Builder<String, Integer> builder = ImmutableBiMap.builder();
|
||||
for (ResourceTypes r : EnumSet.allOf(ResourceTypes.class)) {
|
||||
builder.put(r.name(), r.value);
|
||||
}
|
||||
lookup = builder.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ImmutableBiMap#forcePut(Object, Object)
|
||||
*/
|
||||
@Deprecated
|
||||
@Override
|
||||
public Integer forcePut(String key, Integer value) {
|
||||
return lookup.forcePut(key, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Integer> values() {
|
||||
return lookup.values();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BiMap<Integer, String> inverse() {
|
||||
return lookup.inverse();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String apply(Object input) {
|
||||
return lookup(checkNotNull(input, "resource type was null").toString()).toString();
|
||||
}
|
||||
}
|
|
@ -27,8 +27,6 @@ import static com.google.common.collect.Iterables.transform;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import org.jclouds.ultradns.ws.ResourceTypeToValue;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
|
@ -120,20 +118,6 @@ public class ResourceRecord {
|
|||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* use this for common type values available in
|
||||
* {@link ResourceTypeToValue}, such as {@code MX} or {@code PTR}
|
||||
*
|
||||
* @see ResourceRecord#getType()
|
||||
* @throws IllegalArgumentException
|
||||
* if the type value is not present in
|
||||
* {@link ResourceTypeToValue},
|
||||
*/
|
||||
public Builder type(String type) throws IllegalArgumentException {
|
||||
this.type = ResourceTypeToValue.lookup(type);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ResourceRecord#getType()
|
||||
*/
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
package org.jclouds.ultradns.ws.features;
|
||||
|
||||
import org.jclouds.rest.ResourceNotFoundException;
|
||||
import org.jclouds.ultradns.ws.ResourceTypeToValue;
|
||||
import org.jclouds.ultradns.ws.UltraDNSWSExceptions.ResourceAlreadyExistsException;
|
||||
import org.jclouds.ultradns.ws.domain.ResourceRecord;
|
||||
import org.jclouds.ultradns.ws.domain.ResourceRecordMetadata;
|
||||
|
@ -90,15 +89,6 @@ public interface ResourceRecordApi {
|
|||
FluentIterable<ResourceRecordMetadata> listByNameAndType(String hostName, int rrType)
|
||||
throws ResourceNotFoundException;
|
||||
|
||||
/**
|
||||
* @param type
|
||||
* the literal type defined in {@link ResourceTypeToValue}. ex
|
||||
* {@code AAAA}
|
||||
* @see #listByNameAndType(String, int)
|
||||
*/
|
||||
FluentIterable<ResourceRecordMetadata> listByNameAndType(String hostName, String type)
|
||||
throws ResourceNotFoundException;
|
||||
|
||||
/**
|
||||
* deletes a specific resource record
|
||||
*
|
||||
|
|
|
@ -25,13 +25,11 @@ import org.jclouds.Fallbacks.VoidOnNotFoundOr404;
|
|||
import org.jclouds.rest.ResourceNotFoundException;
|
||||
import org.jclouds.rest.annotations.Fallback;
|
||||
import org.jclouds.rest.annotations.MapBinder;
|
||||
import org.jclouds.rest.annotations.ParamParser;
|
||||
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.ResourceTypeToValue;
|
||||
import org.jclouds.ultradns.ws.UltraDNSWSExceptions.ResourceAlreadyExistsException;
|
||||
import org.jclouds.ultradns.ws.binders.ZoneAndResourceRecordToXML;
|
||||
import org.jclouds.ultradns.ws.domain.ResourceRecord;
|
||||
|
@ -102,18 +100,6 @@ public interface ResourceRecordAsyncApi {
|
|||
@PayloadParam("hostName") String hostName, @PayloadParam("rrType") int rrType)
|
||||
throws ResourceNotFoundException;
|
||||
|
||||
/**
|
||||
* @see ResourceRecordApi#listByNameAndType(String, String)
|
||||
*/
|
||||
@Named("getResourceRecordsOfDNameByType")
|
||||
@POST
|
||||
@XMLResponseParser(ResourceRecordListHandler.class)
|
||||
@Payload("<v01:getResourceRecordsOfDNameByType><zoneName>{zoneName}</zoneName><hostName>{hostName}</hostName><rrType>{rrType}</rrType></v01:getResourceRecordsOfDNameByType>")
|
||||
ListenableFuture<FluentIterable<ResourceRecordMetadata>> listByNameAndType(
|
||||
@PayloadParam("hostName") String hostName,
|
||||
@PayloadParam("rrType") @ParamParser(ResourceTypeToValue.class) String rrType)
|
||||
throws ResourceNotFoundException;
|
||||
|
||||
/**
|
||||
* @see ResourceRecordApi#delete(String)
|
||||
*/
|
||||
|
|
|
@ -1,46 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.jclouds.ultradns.ws;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = "unit", testName = "ResourceTypeToValueTest")
|
||||
public class ResourceTypeToValueTest {
|
||||
|
||||
@Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "ResourceTypes do not include RRRR; types: \\[A, NS, CNAME, SOA, PTR, MX, TXT, AAAA, SRV\\]")
|
||||
public void testNiceExceptionOnNotFound() {
|
||||
new ResourceTypeToValue().apply("RRRR");
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = NullPointerException.class, expectedExceptionsMessageRegExp = "resource type was null")
|
||||
public void testNiceExceptionOnNull() {
|
||||
new ResourceTypeToValue().apply(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNormalCase() {
|
||||
assertEquals(new ResourceTypeToValue().apply("AAAA"), "28");
|
||||
}
|
||||
}
|
|
@ -45,7 +45,7 @@ public class ResourceRecordApiExpectTest extends BaseUltraDNSWSApiExpectTest {
|
|||
HttpResponse createResponse = HttpResponse.builder().statusCode(200)
|
||||
.payload(payloadFromResourceWithContentType("/rr_created.xml", "application/xml")).build();
|
||||
|
||||
ResourceRecord record = rrBuilder().name("mail.jclouds.org.").type("MX").ttl(1800).rdata(10)
|
||||
ResourceRecord record = rrBuilder().name("mail.jclouds.org.").type(15).ttl(1800).rdata(10)
|
||||
.rdata("maileast.jclouds.org.").build();
|
||||
|
||||
public void testCreateWhenResponseIs2xx() {
|
||||
|
@ -128,9 +128,6 @@ public class ResourceRecordApiExpectTest extends BaseUltraDNSWSApiExpectTest {
|
|||
success.getResourceRecordApiForZone("jclouds.org.")
|
||||
.listByNameAndType("www.jclouds.org.", 1).toString(),
|
||||
new GetResourceRecordsOfResourceRecordResponseTest().expected().toString());
|
||||
|
||||
assertEquals(success.getResourceRecordApiForZone("jclouds.org.").listByNameAndType("www.jclouds.org.", "A")
|
||||
.toString(), new GetResourceRecordsOfResourceRecordResponseTest().expected().toString());
|
||||
}
|
||||
|
||||
HttpRequest delete = HttpRequest.builder().method("POST")
|
||||
|
|
|
@ -30,7 +30,6 @@ import java.util.Map.Entry;
|
|||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
import org.jclouds.rest.ResourceNotFoundException;
|
||||
import org.jclouds.ultradns.ws.ResourceTypeToValue;
|
||||
import org.jclouds.ultradns.ws.UltraDNSWSExceptions.ResourceAlreadyExistsException;
|
||||
import org.jclouds.ultradns.ws.domain.Account;
|
||||
import org.jclouds.ultradns.ws.domain.ResourceRecord;
|
||||
|
@ -45,7 +44,6 @@ import com.google.common.base.Function;
|
|||
import com.google.common.cache.CacheBuilder;
|
||||
import com.google.common.cache.CacheLoader;
|
||||
import com.google.common.cache.LoadingCache;
|
||||
import com.google.common.collect.BiMap;
|
||||
import com.google.common.collect.FluentIterable;
|
||||
|
||||
/**
|
||||
|
@ -111,14 +109,12 @@ public class ResourceRecordApiLiveTest extends BaseUltraDNSWSApiLiveTest {
|
|||
}
|
||||
});
|
||||
|
||||
private final static BiMap<Integer, String> valueToType = new ResourceTypeToValue().inverse();
|
||||
|
||||
@AfterClass
|
||||
void logSummary() {
|
||||
getAnonymousLogger().info("zoneCount: " + zones);
|
||||
for (Entry<Integer, AtomicLong> entry : recordTypeCounts.asMap().entrySet())
|
||||
getAnonymousLogger().info(
|
||||
String.format("type: %s, count: %s", valueToType.get(entry.getKey()), entry.getValue()));
|
||||
String.format("type: %s, count: %s", entry.getKey(), entry.getValue()));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = ResourceNotFoundException.class, expectedExceptionsMessageRegExp = "Zone does not exist in the system.")
|
||||
|
@ -129,7 +125,7 @@ public class ResourceRecordApiLiveTest extends BaseUltraDNSWSApiLiveTest {
|
|||
@Test(expectedExceptions = ResourceNotFoundException.class, expectedExceptionsMessageRegExp = "No Resource Record with GUID found in the system")
|
||||
public void testUpdateWhenNotFound() {
|
||||
api(zoneName).update("AAAAAAAAAAAAAAAA",
|
||||
rrBuilder().name("mail." + zoneName).type("MX").ttl(1800).rdata(10).rdata("maileast.jclouds.org.").build());
|
||||
rrBuilder().name("mail." + zoneName).type(15).ttl(1800).rdata(10).rdata("maileast.jclouds.org.").build());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -138,7 +134,7 @@ public class ResourceRecordApiLiveTest extends BaseUltraDNSWSApiLiveTest {
|
|||
}
|
||||
|
||||
String guid;
|
||||
ResourceRecord mx = rrBuilder().name("mail." + zoneName).type("MX").ttl(1800).rdata(10)
|
||||
ResourceRecord mx = rrBuilder().name("mail." + zoneName).type(15).ttl(1800).rdata(10)
|
||||
.rdata("maileast.jclouds.org.").build();
|
||||
|
||||
@Test
|
||||
|
|
|
@ -126,12 +126,12 @@ public class RoundRobinPoolApiLiveTest extends BaseUltraDNSWSApiLiveTest {
|
|||
getAnonymousLogger().info("created A record: " + aRecord1);
|
||||
|
||||
assertTrue(listRRs(aPoolId).anyMatch(
|
||||
equalTo(rrBuilder().name(hostname).type("A").ttl(1).rdata("1.2.3.4").build())));
|
||||
equalTo(rrBuilder().name(hostname).type(1).ttl(1).rdata("1.2.3.4").build())));
|
||||
|
||||
aRecord2 = api(zoneName).addARecordWithAddressAndTTL(aPoolId, "3.4.5.6", 1);
|
||||
|
||||
assertTrue(listRRs(aPoolId).anyMatch(
|
||||
equalTo(rrBuilder().name(hostname).type("A").ttl(1).rdata("3.4.5.6").build())));
|
||||
equalTo(rrBuilder().name(hostname).type(1).ttl(1).rdata("3.4.5.6").build())));
|
||||
|
||||
getAnonymousLogger().info("created A record: " + aRecord1);
|
||||
try {
|
||||
|
@ -146,17 +146,17 @@ public class RoundRobinPoolApiLiveTest extends BaseUltraDNSWSApiLiveTest {
|
|||
public void testUpdateRecord() {
|
||||
api(zoneName).updateRecordWithAddressAndTTL(aPoolId, aRecord1, "1.1.1.1", 0);
|
||||
assertTrue(listRRs(aPoolId).anyMatch(
|
||||
equalTo(rrBuilder().name(hostname).type("A").ttl(0).rdata("1.1.1.1").build())));
|
||||
equalTo(rrBuilder().name(hostname).type(1).ttl(0).rdata("1.1.1.1").build())));
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "testUpdateRecord")
|
||||
public void testDeleteRecord() {
|
||||
api(zoneName).deleteRecord(aRecord2);
|
||||
assertTrue(listRRs(aPoolId).anyMatch(
|
||||
equalTo(rrBuilder().name(hostname).type("A").ttl(0).rdata("1.1.1.1").build())));
|
||||
equalTo(rrBuilder().name(hostname).type(1).ttl(0).rdata("1.1.1.1").build())));
|
||||
|
||||
assertFalse(listRRs(aPoolId).anyMatch(
|
||||
equalTo(rrBuilder().name(hostname).type("A").ttl(1).rdata("3.4.5.6").build())));
|
||||
equalTo(rrBuilder().name(hostname).type(1).ttl(1).rdata("3.4.5.6").build())));
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "testDeleteRecord")
|
||||
|
@ -194,14 +194,14 @@ public class RoundRobinPoolApiLiveTest extends BaseUltraDNSWSApiLiveTest {
|
|||
getAnonymousLogger().info("created AAAA record: " + aaaaRecord1);
|
||||
|
||||
assertTrue(listRRs(aaaaPoolId).anyMatch(
|
||||
equalTo(rrBuilder().name(hostname).type("AAAA").ttl(1).rdata("2001:0DB8:85A3:0000:0000:8A2E:0370:7334")
|
||||
equalTo(rrBuilder().name(hostname).type(28).ttl(1).rdata("2001:0DB8:85A3:0000:0000:8A2E:0370:7334")
|
||||
.build())));
|
||||
|
||||
aaaaRecord2 = api(zoneName).addAAAARecordWithAddressAndTTL(aaaaPoolId, "2002:0DB8:85A3:0000:0000:8A2E:0370:7334",
|
||||
1);
|
||||
|
||||
assertTrue(listRRs(aaaaPoolId).anyMatch(
|
||||
equalTo(rrBuilder().name(hostname).type("AAAA").ttl(1).rdata("2002:0DB8:85A3:0000:0000:8A2E:0370:7334")
|
||||
equalTo(rrBuilder().name(hostname).type(28).ttl(1).rdata("2002:0DB8:85A3:0000:0000:8A2E:0370:7334")
|
||||
.build())));
|
||||
|
||||
getAnonymousLogger().info("created AAAA record: " + aaaaRecord1);
|
||||
|
|
Loading…
Reference in New Issue