From 998bfea33ed6be8861c33da0449ef68375c6899c Mon Sep 17 00:00:00 2001 From: Everett Toews Date: Tue, 23 Apr 2013 23:53:05 -0500 Subject: [PATCH] The Rackspace Cloud DNS APIs moved over from labs. --- all/pom.xml | 15 + apis/pom.xml | 1 + apis/rackspace-clouddns/pom.xml | 154 +++ .../rackspace/clouddns/v1/CloudDNSApi.java | 106 ++ .../clouddns/v1/CloudDNSApiMetadata.java | 95 ++ .../clouddns/v1/CloudDNSExceptions.java | 47 + .../v1/binders/CreateReverseDNSToJSON.java | 79 ++ .../v1/binders/FormatAndContentsToJSON.java | 56 + .../v1/binders/UpdateDomainsToJSON.java | 74 ++ .../v1/binders/UpdateRecordsToJSON.java | 98 ++ .../v1/binders/UpdateReverseDNSToJSON.java | 83 ++ .../clouddns/v1/config/CloudDNS.java | 38 + .../v1/config/CloudDNSHttpApiModule.java | 46 + .../clouddns/v1/domain/CreateDomain.java | 206 ++++ .../clouddns/v1/domain/CreateSubdomain.java | 153 +++ .../rackspace/clouddns/v1/domain/Domain.java | 162 +++ .../clouddns/v1/domain/DomainChange.java | 188 +++ .../rackspace/clouddns/v1/domain/Job.java | 129 +++ .../rackspace/clouddns/v1/domain/Record.java | 221 ++++ .../clouddns/v1/domain/RecordDetail.java | 186 +++ .../clouddns/v1/domain/Subdomain.java | 98 ++ .../clouddns/v1/domain/UpdateDomain.java | 125 ++ .../clouddns/v1/features/DomainApi.java | 298 +++++ .../clouddns/v1/features/LimitApi.java | 63 + .../clouddns/v1/features/RecordApi.java | 230 ++++ .../clouddns/v1/features/ReverseDNSApi.java | 155 +++ .../v1/functions/DomainFunctions.java | 51 + .../v1/functions/DomainsToPagedIterable.java | 73 ++ .../clouddns/v1/functions/ParseDomain.java | 139 +++ .../clouddns/v1/functions/ParseDomains.java | 61 + .../clouddns/v1/functions/ParseJob.java | 135 +++ .../v1/functions/ParseOnlyRecord.java | 60 + .../clouddns/v1/functions/ParseRecord.java | 95 ++ .../clouddns/v1/functions/ParseRecords.java | 71 ++ .../v1/functions/ParseSubdomains.java | 68 ++ .../v1/functions/RecordFunctions.java | 64 ++ .../v1/functions/RecordsToPagedIterable.java | 74 ++ .../functions/SubdomainsToPagedIterable.java | 75 ++ .../clouddns/v1/predicates/JobPredicates.java | 109 ++ .../services/org.jclouds.apis.ApiMetadata | 1 + .../v1/features/CloudDNSApiExpectTest.java | 50 + .../v1/features/DomainApiExpectTest.java | 311 +++++ .../v1/features/DomainApiLiveTest.java | 407 +++++++ .../v1/features/LimitApiExpectTest.java | 84 ++ .../v1/features/LimitApiLiveTest.java | 50 + .../v1/features/RecordApiExpectTest.java | 328 ++++++ .../v1/features/RecordApiLiveTest.java | 293 +++++ .../v1/features/ReverseDNSApiExpectTest.java | 221 ++++ .../v1/features/ReverseDNSApiLiveTest.java | 227 ++++ .../internal/BaseCloudDNSApiExpectTest.java | 58 + .../v1/internal/BaseCloudDNSApiLiveTest.java | 42 + .../resources/domain-create-response.json | 111 ++ .../src/test/resources/domain-create.json | 1 + .../src/test/resources/domain-delete.json | 7 + .../src/test/resources/domain-export.json | 13 + .../src/test/resources/domain-get.json | 41 + .../resources/domain-import-response.json | 42 + .../src/test/resources/domain-import.json | 1 + .../test/resources/domain-list-changes.json | 1010 +++++++++++++++++ .../resources/domain-list-with-filter.json | 13 + .../src/test/resources/domain-list.json | 41 + .../test/resources/domain-update-email.json | 1 + .../resources/domain-update-response.json | 8 + .../src/test/resources/domain-update-ttl.json | 1 + .../src/test/resources/domain-update.json | 1 + .../src/test/resources/job.json | 7 + .../src/test/resources/limit-list.json | 57 + .../src/test/resources/limit-types-list.json | 7 + .../src/test/resources/logback.xml | 38 + .../resources/record-create-response.json | 32 + .../src/test/resources/record-create.json | 1 + .../src/test/resources/record-delete.json | 7 + .../src/test/resources/record-get.json | 9 + .../resources/record-list-with-filter.json | 13 + .../src/test/resources/record-list.json | 42 + .../resources/record-ptr-create-response.json | 31 + .../src/test/resources/record-ptr-create.json | 1 + .../src/test/resources/record-ptr-delete.json | 7 + .../src/test/resources/record-ptr-get.json | 9 + .../src/test/resources/record-ptr-list.json | 23 + .../resources/record-ptr-update-response.json | 8 + .../src/test/resources/record-ptr-update.json | 1 + .../resources/record-update-response.json | 8 + .../src/test/resources/record-update.json | 1 + .../src/test/resources/records-delete.json | 7 + .../test/resources/records-ptr-delete.json | 7 + .../resources/records-update-response.json | 8 + .../src/test/resources/records-update.json | 1 + providers/pom.xml | 2 + providers/rackspace-clouddns-uk/pom.xml | 148 +++ .../uk/CloudDNSUKProviderMetadata.java | 85 ++ .../org.jclouds.providers.ProviderMetadata | 1 + .../features/CloudDNSUKDomainApiLiveTest.java | 33 + .../features/CloudDNSUKLimitApiLiveTest.java | 33 + .../uk/features/CloudDNSUKProviderTest.java | 36 + .../features/CloudDNSUKRecordApiLiveTest.java | 33 + providers/rackspace-clouddns-us/pom.xml | 167 +++ .../us/CloudDNSUSProviderMetadata.java | 85 ++ .../org.jclouds.providers.ProviderMetadata | 1 + .../features/CloudDNSUSDomainApiLiveTest.java | 33 + .../features/CloudDNSUSLimitApiLiveTest.java | 33 + .../us/features/CloudDNSUSProviderTest.java | 36 + .../features/CloudDNSUSRecordApiLiveTest.java | 33 + .../CloudDNSUSReverseDNSApiLiveTest.java | 33 + 104 files changed, 8661 insertions(+) create mode 100644 apis/rackspace-clouddns/pom.xml create mode 100644 apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/CloudDNSApi.java create mode 100644 apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/CloudDNSApiMetadata.java create mode 100644 apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/CloudDNSExceptions.java create mode 100644 apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/binders/CreateReverseDNSToJSON.java create mode 100644 apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/binders/FormatAndContentsToJSON.java create mode 100644 apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/binders/UpdateDomainsToJSON.java create mode 100644 apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/binders/UpdateRecordsToJSON.java create mode 100644 apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/binders/UpdateReverseDNSToJSON.java create mode 100644 apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/config/CloudDNS.java create mode 100644 apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/config/CloudDNSHttpApiModule.java create mode 100644 apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/domain/CreateDomain.java create mode 100644 apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/domain/CreateSubdomain.java create mode 100644 apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/domain/Domain.java create mode 100644 apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/domain/DomainChange.java create mode 100644 apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/domain/Job.java create mode 100644 apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/domain/Record.java create mode 100644 apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/domain/RecordDetail.java create mode 100644 apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/domain/Subdomain.java create mode 100644 apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/domain/UpdateDomain.java create mode 100644 apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/features/DomainApi.java create mode 100644 apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/features/LimitApi.java create mode 100644 apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/features/RecordApi.java create mode 100644 apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/features/ReverseDNSApi.java create mode 100644 apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/functions/DomainFunctions.java create mode 100644 apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/functions/DomainsToPagedIterable.java create mode 100644 apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/functions/ParseDomain.java create mode 100644 apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/functions/ParseDomains.java create mode 100644 apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/functions/ParseJob.java create mode 100644 apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/functions/ParseOnlyRecord.java create mode 100644 apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/functions/ParseRecord.java create mode 100644 apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/functions/ParseRecords.java create mode 100644 apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/functions/ParseSubdomains.java create mode 100644 apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/functions/RecordFunctions.java create mode 100644 apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/functions/RecordsToPagedIterable.java create mode 100644 apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/functions/SubdomainsToPagedIterable.java create mode 100644 apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/predicates/JobPredicates.java create mode 100644 apis/rackspace-clouddns/src/main/resources/META-INF/services/org.jclouds.apis.ApiMetadata create mode 100644 apis/rackspace-clouddns/src/test/java/org/jclouds/rackspace/clouddns/v1/features/CloudDNSApiExpectTest.java create mode 100644 apis/rackspace-clouddns/src/test/java/org/jclouds/rackspace/clouddns/v1/features/DomainApiExpectTest.java create mode 100644 apis/rackspace-clouddns/src/test/java/org/jclouds/rackspace/clouddns/v1/features/DomainApiLiveTest.java create mode 100644 apis/rackspace-clouddns/src/test/java/org/jclouds/rackspace/clouddns/v1/features/LimitApiExpectTest.java create mode 100644 apis/rackspace-clouddns/src/test/java/org/jclouds/rackspace/clouddns/v1/features/LimitApiLiveTest.java create mode 100644 apis/rackspace-clouddns/src/test/java/org/jclouds/rackspace/clouddns/v1/features/RecordApiExpectTest.java create mode 100644 apis/rackspace-clouddns/src/test/java/org/jclouds/rackspace/clouddns/v1/features/RecordApiLiveTest.java create mode 100644 apis/rackspace-clouddns/src/test/java/org/jclouds/rackspace/clouddns/v1/features/ReverseDNSApiExpectTest.java create mode 100644 apis/rackspace-clouddns/src/test/java/org/jclouds/rackspace/clouddns/v1/features/ReverseDNSApiLiveTest.java create mode 100644 apis/rackspace-clouddns/src/test/java/org/jclouds/rackspace/clouddns/v1/internal/BaseCloudDNSApiExpectTest.java create mode 100644 apis/rackspace-clouddns/src/test/java/org/jclouds/rackspace/clouddns/v1/internal/BaseCloudDNSApiLiveTest.java create mode 100644 apis/rackspace-clouddns/src/test/resources/domain-create-response.json create mode 100644 apis/rackspace-clouddns/src/test/resources/domain-create.json create mode 100644 apis/rackspace-clouddns/src/test/resources/domain-delete.json create mode 100644 apis/rackspace-clouddns/src/test/resources/domain-export.json create mode 100644 apis/rackspace-clouddns/src/test/resources/domain-get.json create mode 100644 apis/rackspace-clouddns/src/test/resources/domain-import-response.json create mode 100644 apis/rackspace-clouddns/src/test/resources/domain-import.json create mode 100644 apis/rackspace-clouddns/src/test/resources/domain-list-changes.json create mode 100644 apis/rackspace-clouddns/src/test/resources/domain-list-with-filter.json create mode 100644 apis/rackspace-clouddns/src/test/resources/domain-list.json create mode 100644 apis/rackspace-clouddns/src/test/resources/domain-update-email.json create mode 100644 apis/rackspace-clouddns/src/test/resources/domain-update-response.json create mode 100644 apis/rackspace-clouddns/src/test/resources/domain-update-ttl.json create mode 100644 apis/rackspace-clouddns/src/test/resources/domain-update.json create mode 100644 apis/rackspace-clouddns/src/test/resources/job.json create mode 100644 apis/rackspace-clouddns/src/test/resources/limit-list.json create mode 100644 apis/rackspace-clouddns/src/test/resources/limit-types-list.json create mode 100644 apis/rackspace-clouddns/src/test/resources/logback.xml create mode 100644 apis/rackspace-clouddns/src/test/resources/record-create-response.json create mode 100644 apis/rackspace-clouddns/src/test/resources/record-create.json create mode 100644 apis/rackspace-clouddns/src/test/resources/record-delete.json create mode 100644 apis/rackspace-clouddns/src/test/resources/record-get.json create mode 100644 apis/rackspace-clouddns/src/test/resources/record-list-with-filter.json create mode 100644 apis/rackspace-clouddns/src/test/resources/record-list.json create mode 100644 apis/rackspace-clouddns/src/test/resources/record-ptr-create-response.json create mode 100644 apis/rackspace-clouddns/src/test/resources/record-ptr-create.json create mode 100644 apis/rackspace-clouddns/src/test/resources/record-ptr-delete.json create mode 100644 apis/rackspace-clouddns/src/test/resources/record-ptr-get.json create mode 100644 apis/rackspace-clouddns/src/test/resources/record-ptr-list.json create mode 100644 apis/rackspace-clouddns/src/test/resources/record-ptr-update-response.json create mode 100644 apis/rackspace-clouddns/src/test/resources/record-ptr-update.json create mode 100644 apis/rackspace-clouddns/src/test/resources/record-update-response.json create mode 100644 apis/rackspace-clouddns/src/test/resources/record-update.json create mode 100644 apis/rackspace-clouddns/src/test/resources/records-delete.json create mode 100644 apis/rackspace-clouddns/src/test/resources/records-ptr-delete.json create mode 100644 apis/rackspace-clouddns/src/test/resources/records-update-response.json create mode 100644 apis/rackspace-clouddns/src/test/resources/records-update.json create mode 100644 providers/rackspace-clouddns-uk/pom.xml create mode 100644 providers/rackspace-clouddns-uk/src/main/java/org/jclouds/rackspace/clouddns/uk/CloudDNSUKProviderMetadata.java create mode 100644 providers/rackspace-clouddns-uk/src/main/resources/META-INF/services/org.jclouds.providers.ProviderMetadata create mode 100644 providers/rackspace-clouddns-uk/src/test/java/org/jclouds/rackspace/clouddns/uk/features/CloudDNSUKDomainApiLiveTest.java create mode 100644 providers/rackspace-clouddns-uk/src/test/java/org/jclouds/rackspace/clouddns/uk/features/CloudDNSUKLimitApiLiveTest.java create mode 100644 providers/rackspace-clouddns-uk/src/test/java/org/jclouds/rackspace/clouddns/uk/features/CloudDNSUKProviderTest.java create mode 100644 providers/rackspace-clouddns-uk/src/test/java/org/jclouds/rackspace/clouddns/uk/features/CloudDNSUKRecordApiLiveTest.java create mode 100644 providers/rackspace-clouddns-us/pom.xml create mode 100644 providers/rackspace-clouddns-us/src/main/java/org/jclouds/rackspace/clouddns/us/CloudDNSUSProviderMetadata.java create mode 100644 providers/rackspace-clouddns-us/src/main/resources/META-INF/services/org.jclouds.providers.ProviderMetadata create mode 100644 providers/rackspace-clouddns-us/src/test/java/org/jclouds/rackspace/clouddns/us/features/CloudDNSUSDomainApiLiveTest.java create mode 100644 providers/rackspace-clouddns-us/src/test/java/org/jclouds/rackspace/clouddns/us/features/CloudDNSUSLimitApiLiveTest.java create mode 100644 providers/rackspace-clouddns-us/src/test/java/org/jclouds/rackspace/clouddns/us/features/CloudDNSUSProviderTest.java create mode 100644 providers/rackspace-clouddns-us/src/test/java/org/jclouds/rackspace/clouddns/us/features/CloudDNSUSRecordApiLiveTest.java create mode 100644 providers/rackspace-clouddns-us/src/test/java/org/jclouds/rackspace/clouddns/us/features/CloudDNSUSReverseDNSApiLiveTest.java diff --git a/all/pom.xml b/all/pom.xml index aafc2fc6b0..8e0a758983 100644 --- a/all/pom.xml +++ b/all/pom.xml @@ -40,6 +40,11 @@ openstack-cinder ${project.version} + + org.jclouds.api + rackspace-clouddns + ${project.version} + org.jclouds.provider aws-cloudwatch @@ -55,6 +60,16 @@ rackspace-cloudblockstorage-uk ${project.version} + + org.jclouds.provider + rackspace-clouddns-us + ${project.version} + + + org.jclouds.provider + rackspace-clouddns-uk + ${project.version} + org.jclouds.provider aws-sqs diff --git a/apis/pom.xml b/apis/pom.xml index 4075e262b5..e4e9b7554c 100644 --- a/apis/pom.xml +++ b/apis/pom.xml @@ -52,6 +52,7 @@ cloudservers rackspace-cloudidentity rackspace-cloudloadbalancers + rackspace-clouddns sts route53 diff --git a/apis/rackspace-clouddns/pom.xml b/apis/rackspace-clouddns/pom.xml new file mode 100644 index 0000000000..60442915af --- /dev/null +++ b/apis/rackspace-clouddns/pom.xml @@ -0,0 +1,154 @@ + + + + 4.0.0 + + org.jclouds + jclouds-project + 1.7.0-SNAPSHOT + ../../project/pom.xml + + org.jclouds.api + rackspace-clouddns + jclouds rackspace clouddns api + jclouds components for Rackspace Cloud DNS + bundle + + + https://identity.api.rackspacecloud.com/v2.0/ + 1.0 + + ${test.rackspace-us.identity} + ${test.rackspace-us.credential} + + org.jclouds.rackspace.clouddns.v1*;version="${project.version}" + + org.jclouds.rest.internal;version="${project.version}", + org.jclouds*;version="${project.version}", + * + + + + + + org.jclouds + jclouds-core + ${project.version} + + + org.jclouds.api + openstack-keystone + ${project.version} + + + org.jclouds.api + rackspace-cloudidentity + ${project.version} + + + org.jclouds + jclouds-core + ${project.version} + test-jar + test + + + org.jclouds + jclouds-compute + ${project.version} + test-jar + test + + + org.jclouds.api + openstack-keystone + ${project.version} + test-jar + test + + + org.jclouds.api + openstack-nova + ${project.version} + test + + + org.jclouds.api + rackspace-cloudidentity + ${project.version} + test-jar + test + + + org.jclouds.provider + rackspace-cloudservers-us + ${project.version} + test + + + org.jclouds.driver + jclouds-slf4j + ${project.version} + test + + + ch.qos.logback + logback-classic + test + + + + + + live + + + + org.apache.maven.plugins + maven-surefire-plugin + + + integration + integration-test + + test + + + + 1 + + ${test.rackspace-clouddns.endpoint} + ${test.rackspace-clouddns.api-version} + ${test.rackspace-clouddns.build-version} + ${test.rackspace-clouddns.identity} + ${test.rackspace-clouddns.credential} + + + + + + + + + + + diff --git a/apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/CloudDNSApi.java b/apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/CloudDNSApi.java new file mode 100644 index 0000000000..a9148a8431 --- /dev/null +++ b/apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/CloudDNSApi.java @@ -0,0 +1,106 @@ +/** + * 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.rackspace.clouddns.v1; + +import static javax.ws.rs.core.MediaType.APPLICATION_JSON; + +import java.io.Closeable; + +import javax.inject.Named; +import javax.ws.rs.Consumes; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; + +import org.jclouds.Fallbacks.NullOnNotFoundOr404; +import org.jclouds.javax.annotation.Nullable; +import org.jclouds.openstack.keystone.v2_0.filters.AuthenticateRequest; +import org.jclouds.rackspace.clouddns.v1.config.CloudDNS; +import org.jclouds.rackspace.clouddns.v1.domain.Job; +import org.jclouds.rackspace.clouddns.v1.features.DomainApi; +import org.jclouds.rackspace.clouddns.v1.features.LimitApi; +import org.jclouds.rackspace.clouddns.v1.features.RecordApi; +import org.jclouds.rackspace.clouddns.v1.features.ReverseDNSApi; +import org.jclouds.rackspace.clouddns.v1.functions.ParseJob; +import org.jclouds.rackspace.clouddns.v1.predicates.JobPredicates; +import org.jclouds.rest.annotations.Delegate; +import org.jclouds.rest.annotations.Endpoint; +import org.jclouds.rest.annotations.Fallback; +import org.jclouds.rest.annotations.PayloadParam; +import org.jclouds.rest.annotations.QueryParams; +import org.jclouds.rest.annotations.RequestFilters; +import org.jclouds.rest.annotations.ResponseParser; + +/** + * Provides access to the Rackspace Cloud DNS API. + *

+ * See Cloud DNS Developer Guide + * + * @author Everett Toews + */ +public interface CloudDNSApi extends Closeable { + + /** + * Returns the current status of a job. + *

+ * Operations that create, update, or delete resources may take some time to process. Therefore they return + * a Job containing information, which allows the status and response information of the job to be + * retrieved at a later point in time. + *

+ * You likely won't need to use this method directly. Use {@link JobPredicates#awaitComplete(CloudDNSApi, Job)}. + * + * @return null, if not found. + */ + @Named("job:get") + @Endpoint(CloudDNS.class) + @RequestFilters(AuthenticateRequest.class) + @GET + @Consumes(APPLICATION_JSON) + @ResponseParser(ParseJob.class) + @Fallback(NullOnNotFoundOr404.class) + @QueryParams(keys = "showDetails", values = "true") + @Path("/status/{jobId}") + @Nullable + Job getJob(@PathParam("jobId") String jobId); + + /** + * Provides access to Limit features. + */ + @Delegate + LimitApi getLimitApi(); + + /** + * Provides access to Domain features. + */ + @Delegate + DomainApi getDomainApi(); + + /** + * Provides access to Record features. + */ + @Delegate + @Path("/domains/{domainId}") + RecordApi getRecordApiForDomain(@PathParam("domainId") int domainId); + + /** + * Provides access to Reverse DNS features. + */ + @Delegate + ReverseDNSApi getReverseDNSApiForService(@PayloadParam("serviceName") @PathParam("serviceName") String serviceName); +} diff --git a/apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/CloudDNSApiMetadata.java b/apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/CloudDNSApiMetadata.java new file mode 100644 index 0000000000..fd9acad76b --- /dev/null +++ b/apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/CloudDNSApiMetadata.java @@ -0,0 +1,95 @@ +/** + * 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.rackspace.clouddns.v1; + +import static org.jclouds.openstack.keystone.v2_0.config.KeystoneProperties.CREDENTIAL_TYPE; +import static org.jclouds.openstack.keystone.v2_0.config.KeystoneProperties.SERVICE_TYPE; +import static org.jclouds.rackspace.cloudidentity.v2_0.ServiceType.DNS; +import static org.jclouds.rackspace.cloudidentity.v2_0.config.CloudIdentityCredentialTypes.API_KEY_CREDENTIALS; + +import java.net.URI; +import java.util.Properties; + +import org.jclouds.apis.ApiMetadata; +import org.jclouds.openstack.keystone.v2_0.config.KeystoneAuthenticationModule.ProviderModule; +import org.jclouds.rackspace.clouddns.v1.config.CloudDNSHttpApiModule; +import org.jclouds.rackspace.cloudidentity.v2_0.config.CloudIdentityAuthenticationApiModule; +import org.jclouds.rackspace.cloudidentity.v2_0.config.CloudIdentityAuthenticationModule; +import org.jclouds.rest.internal.BaseHttpApiMetadata; + +import com.google.common.collect.ImmutableSet; +import com.google.inject.Module; + +/** + * Implementation of {@link ApiMetadata} for Rackspace Cloud DNS 1.0 API + * + * @author Everett Toews + */ +public class CloudDNSApiMetadata extends BaseHttpApiMetadata { + + @Override + public Builder toBuilder() { + return new Builder().fromApiMetadata(this); + } + + public CloudDNSApiMetadata() { + this(new Builder()); + } + + protected CloudDNSApiMetadata(Builder builder) { + super(builder); + } + + public static Properties defaultProperties() { + Properties properties = BaseHttpApiMetadata.defaultProperties(); + properties.setProperty(SERVICE_TYPE, DNS); + properties.setProperty(CREDENTIAL_TYPE, API_KEY_CREDENTIALS); + return properties; + } + + public static class Builder extends BaseHttpApiMetadata.Builder { + + protected Builder() { + id("rackspace-clouddns") + .name("Rackspace Cloud DNS API") + .identityName("Username") + .credentialName("API Key") + .documentation(URI.create("http://docs.rackspace.com/cdns/api/v1.0/cdns-devguide/content/index.html")) + .version("1.0") + .defaultEndpoint("https://identity.api.rackspacecloud.com/v2.0/") + .defaultProperties(CloudDNSApiMetadata.defaultProperties()) + .defaultModules(ImmutableSet.> builder() + .add(CloudIdentityAuthenticationApiModule.class) + .add(CloudIdentityAuthenticationModule.class) + .add(ProviderModule.class) + .add(CloudDNSHttpApiModule.class) + .build()); + } + + @Override + public CloudDNSApiMetadata build() { + return new CloudDNSApiMetadata(this); + } + + @Override + protected Builder self() { + return this; + } + } +} diff --git a/apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/CloudDNSExceptions.java b/apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/CloudDNSExceptions.java new file mode 100644 index 0000000000..20be0af97c --- /dev/null +++ b/apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/CloudDNSExceptions.java @@ -0,0 +1,47 @@ +/** + * 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.rackspace.clouddns.v1; + +import static com.google.common.base.Preconditions.checkNotNull; + +import org.jclouds.rackspace.clouddns.v1.domain.Job; + +/** + * Exceptions likely to be encountered when using {@link CloudDNSApi} + * + * @author Everett Toews + */ +public interface CloudDNSExceptions { + /** + * A Job errored out. + */ + public static class JobErrorException extends RuntimeException { + private static final long serialVersionUID = 1L; + private final Job.Error jobError; + + public JobErrorException(Job.Error jobError) { + super(jobError.toString()); + this.jobError = checkNotNull(jobError, "jobError"); + } + + public Job.Error getJobError() { + return jobError; + } + } +} diff --git a/apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/binders/CreateReverseDNSToJSON.java b/apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/binders/CreateReverseDNSToJSON.java new file mode 100644 index 0000000000..6d45d088a9 --- /dev/null +++ b/apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/binders/CreateReverseDNSToJSON.java @@ -0,0 +1,79 @@ +/** + * 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.rackspace.clouddns.v1.binders; + +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; + +import java.net.URI; +import java.util.Map; + +import javax.inject.Inject; +import javax.ws.rs.core.MediaType; + +import org.jclouds.http.HttpRequest; +import org.jclouds.json.Json; +import org.jclouds.rackspace.clouddns.v1.domain.Record; +import org.jclouds.rest.MapBinder; + +import com.google.common.collect.ImmutableMap; + +/** + * @author Everett Toews + */ +public class CreateReverseDNSToJSON implements MapBinder { + private final Json jsonBinder; + + @Inject + public CreateReverseDNSToJSON(Json jsonBinder) { + this.jsonBinder = checkNotNull(jsonBinder, "jsonBinder"); + } + + @SuppressWarnings("unchecked") + @Override + public R bindToRequest(R request, Map postParams) { + checkArgument(checkNotNull(postParams.get("href"), "href") instanceof URI, "href is only valid for a URI!"); + checkArgument(checkNotNull(postParams.get("records"), "records") instanceof Iterable, + "records is only valid for an Iterable!"); + checkNotNull(postParams.get("serviceName"), "serviceName"); + + Iterable records = Iterable.class.cast(postParams.get("records")); + URI deviceURI = URI.class.cast(postParams.get("href")); + String serviceName = postParams.get("serviceName").toString(); + + String json = toJSON(records, deviceURI, serviceName); + request.setPayload(json); + request.getPayload().getContentMetadata().setContentType(MediaType.APPLICATION_JSON); + + return (R) request.toBuilder().payload(json).build(); + } + + private String toJSON(Iterable records, URI deviceURI, String serviceName) { + return jsonBinder.toJson(ImmutableMap. of( + "recordsList", ImmutableMap.of("records", records), + "link", ImmutableMap. of( + "href", deviceURI, + "rel", serviceName))); + } + + @Override + public R bindToRequest(R request, Object input) { + throw new UnsupportedOperationException("use map form"); + } +} diff --git a/apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/binders/FormatAndContentsToJSON.java b/apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/binders/FormatAndContentsToJSON.java new file mode 100644 index 0000000000..473b007235 --- /dev/null +++ b/apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/binders/FormatAndContentsToJSON.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.rackspace.clouddns.v1.binders; + +import static java.lang.String.format; + +import java.util.List; +import java.util.Map; + +import org.jclouds.http.HttpRequest; +import org.jclouds.rest.MapBinder; + +import com.google.common.base.Joiner; + +/** + * @author Everett Toews + */ +public class FormatAndContentsToJSON implements MapBinder { + private static final String template = "{\"domains\":[{\"contentType\":\"%s\",\"contents\":\"%s\"}]}"; + + @SuppressWarnings("unchecked") + @Override + public R bindToRequest(R request, Map postParams) { + String format = postParams.get("format").toString(); + List contents = List.class.cast(postParams.get("contents")); + + return (R) request.toBuilder().payload(toJSON(format, contents)).build(); + } + + private String toJSON(String format, List contents) { + String contentsAsOneString = Joiner.on("\\n").join(contents); + + return format(template, format, contentsAsOneString); + } + + @Override + public R bindToRequest(R request, Object input) { + throw new UnsupportedOperationException("use map form"); + } +} diff --git a/apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/binders/UpdateDomainsToJSON.java b/apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/binders/UpdateDomainsToJSON.java new file mode 100644 index 0000000000..fb6d0e42f2 --- /dev/null +++ b/apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/binders/UpdateDomainsToJSON.java @@ -0,0 +1,74 @@ +/** + * 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.rackspace.clouddns.v1.binders; + +import static java.lang.String.format; + +import java.util.List; +import java.util.Map; + +import org.jclouds.http.HttpRequest; +import org.jclouds.rest.MapBinder; + +import com.google.common.base.Joiner; +import com.google.common.collect.Lists; + +/** + * @author Everett Toews + */ +public class UpdateDomainsToJSON implements MapBinder { + private static final String template = "{\"domains\":[%s]}"; + + @SuppressWarnings("unchecked") + @Override + public R bindToRequest(R request, Map postParams) { + Iterable ids = Iterable.class.cast(postParams.get("ids")); + String key, value, updateTemplate; + + if (postParams.get("emailAddress") != null) { + updateTemplate = "{\"id\":%s,\"%s\":\"%s\"}"; + key = "emailAddress"; + } else if (postParams.get("ttl") != null) { + updateTemplate = "{\"id\":%s,\"%s\":%s}"; + key = "ttl"; + } else { + throw new IllegalStateException("emailAddress or ttl not found in " + postParams); + } + + value = postParams.get(key).toString(); + return (R) request.toBuilder().payload(toJSON(ids, updateTemplate, key, value)).build(); + } + + private String toJSON(Iterable ids, String updateTemplate, String key, String value) { + List json = Lists.newArrayList(); + + for (Integer id: ids) { + json.add(format(updateTemplate, id, key, value)); + } + + String contentsAsOneString = Joiner.on(",").join(json); + + return format(template, contentsAsOneString); + } + + @Override + public R bindToRequest(R request, Object input) { + throw new UnsupportedOperationException("use map form"); + } +} diff --git a/apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/binders/UpdateRecordsToJSON.java b/apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/binders/UpdateRecordsToJSON.java new file mode 100644 index 0000000000..4fcd9d00cc --- /dev/null +++ b/apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/binders/UpdateRecordsToJSON.java @@ -0,0 +1,98 @@ +/** + * 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.rackspace.clouddns.v1.binders; + +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; + +import java.util.List; +import java.util.Map; + +import javax.inject.Inject; +import javax.inject.Singleton; +import javax.ws.rs.core.MediaType; + +import org.jclouds.http.HttpRequest; +import org.jclouds.json.Json; +import org.jclouds.rackspace.clouddns.v1.domain.Record; +import org.jclouds.rest.Binder; + +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.Lists; + +/** + * Binds the Records to the request as a JSON payload. + * + * @author Everett Toews + */ +@Singleton +public class UpdateRecordsToJSON implements Binder { + + private final Json jsonBinder; + + @Inject + public UpdateRecordsToJSON(Json jsonBinder) { + this.jsonBinder = checkNotNull(jsonBinder, "jsonBinder"); + } + + @SuppressWarnings("unchecked") + @Override + public R bindToRequest(R request, Object input) { + checkArgument(checkNotNull(input, "input") instanceof Map, "This binder is only valid for Map"); + checkNotNull(request, "request"); + + Map idsToRecords = (Map) input; + List updateRecords = toUpdateRecordList(idsToRecords); + + String json = jsonBinder.toJson(ImmutableMap.of("records", updateRecords)); + request.setPayload(json); + request.getPayload().getContentMetadata().setContentType(MediaType.APPLICATION_JSON); + + return request; + } + + static List toUpdateRecordList(Map idsToRecords) { + List updateRecords = Lists.newArrayList(); + + for (String recordId: idsToRecords.keySet()) { + Record record = idsToRecords.get(recordId); + + UpdateRecord updateRecord = new UpdateRecord(); + updateRecord.id = recordId; + updateRecord.name = record.getName(); + updateRecord.ttl = record.getTTL().isPresent() ? record.getTTL().get() : null; + updateRecord.data = record.getData(); + updateRecord.priority = record.getPriority(); + updateRecord.comment = record.getComment(); + + updateRecords.add(updateRecord); + } + + return updateRecords; + } + + static final class UpdateRecord { + public String id; + public String name; + public Integer ttl; + public String data; + public Integer priority; + public String comment; + } +} diff --git a/apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/binders/UpdateReverseDNSToJSON.java b/apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/binders/UpdateReverseDNSToJSON.java new file mode 100644 index 0000000000..3546e7521f --- /dev/null +++ b/apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/binders/UpdateReverseDNSToJSON.java @@ -0,0 +1,83 @@ +/** + * 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.rackspace.clouddns.v1.binders; + +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; + +import java.net.URI; +import java.util.List; +import java.util.Map; + +import javax.inject.Inject; +import javax.ws.rs.core.MediaType; + +import org.jclouds.http.HttpRequest; +import org.jclouds.json.Json; +import org.jclouds.rackspace.clouddns.v1.binders.UpdateRecordsToJSON.UpdateRecord; +import org.jclouds.rackspace.clouddns.v1.domain.Record; +import org.jclouds.rest.MapBinder; + +import com.google.common.collect.ImmutableMap; + +/** + * @author Everett Toews + */ +public class UpdateReverseDNSToJSON implements MapBinder { + private final Json jsonBinder; + + @Inject + public UpdateReverseDNSToJSON(Json jsonBinder) { + this.jsonBinder = checkNotNull(jsonBinder, "jsonBinder"); + } + + @SuppressWarnings("unchecked") + @Override + public R bindToRequest(R request, Map postParams) { + checkArgument(checkNotNull(postParams.get("href"), "href") instanceof URI, + "href is only valid for a URI!"); + checkArgument(checkNotNull(postParams.get("idsToRecords"), "idsToRecords") instanceof Map, + "records is only valid for a Map!"); + checkNotNull(postParams.get("serviceName"), "serviceName"); + + Map idsToRecords = Map.class.cast(postParams.get("idsToRecords")); + List updateRecords = UpdateRecordsToJSON.toUpdateRecordList(idsToRecords); + URI deviceURI = URI.class.cast(postParams.get("href")); + String serviceName = postParams.get("serviceName").toString(); + + String json = toJSON(updateRecords, deviceURI, serviceName); + request.setPayload(json); + request.getPayload().getContentMetadata().setContentType(MediaType.APPLICATION_JSON); + + return (R) request.toBuilder().payload(json).build(); + } + + private String toJSON(Iterable records, URI deviceURI, String serviceName) { + return jsonBinder.toJson(ImmutableMap. of( + "recordsList", ImmutableMap.of("records", records), + "link", ImmutableMap. of( + "href", deviceURI, + "rel", serviceName))); + } + + @Override + public R bindToRequest(R request, Object input) { + throw new UnsupportedOperationException("use map form"); + } +} diff --git a/apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/config/CloudDNS.java b/apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/config/CloudDNS.java new file mode 100644 index 0000000000..764e0c9aa6 --- /dev/null +++ b/apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/config/CloudDNS.java @@ -0,0 +1,38 @@ +/** + * 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.rackspace.clouddns.v1.config; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; + +/** + * Represents a component related to Rackspace Cloud DNS. + * + * @author Everett Toews + */ +@Retention(value = RetentionPolicy.RUNTIME) +@Target(value = { ElementType.TYPE, ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD }) +@Qualifier +public @interface CloudDNS { + +} diff --git a/apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/config/CloudDNSHttpApiModule.java b/apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/config/CloudDNSHttpApiModule.java new file mode 100644 index 0000000000..ccfa36f45a --- /dev/null +++ b/apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/config/CloudDNSHttpApiModule.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.rackspace.clouddns.v1.config; + +import java.net.URI; + +import org.jclouds.json.config.GsonModule.DateAdapter; +import org.jclouds.json.config.GsonModule.Iso8601DateAdapter; +import org.jclouds.rackspace.clouddns.v1.CloudDNSApi; +import org.jclouds.rest.ConfiguresHttpApi; +import org.jclouds.rest.config.HttpApiModule; + +import com.google.common.base.Supplier; +import com.google.inject.TypeLiteral; + +/** + * Configures Rackspace Cloud DNS. + * + * @author Everett Toews + */ +@ConfiguresHttpApi +public class CloudDNSHttpApiModule extends HttpApiModule { + + @Override + protected void configure() { + bind(new TypeLiteral>() {}).annotatedWith(CloudDNS.class).to(new TypeLiteral>() {}); + bind(DateAdapter.class).to(Iso8601DateAdapter.class); + super.configure(); + } +} diff --git a/apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/domain/CreateDomain.java b/apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/domain/CreateDomain.java new file mode 100644 index 0000000000..8f8a0ae5a7 --- /dev/null +++ b/apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/domain/CreateDomain.java @@ -0,0 +1,206 @@ +/** + * 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, String 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.rackspace.clouddns.v1.domain; + +import static com.google.common.base.Preconditions.checkNotNull; + +import com.google.common.base.Objects; +import com.google.common.base.Objects.ToStringHelper; +import com.google.common.base.Optional; +import com.google.common.collect.ImmutableMap; + +/** + * Create a Domain or Subdomain. + * + * @author Everett Toews + */ +public class CreateDomain { + private final String name; + private final String emailAddress; + private final Optional ttl; + private final Optional comment; + // subdomains is an ImmutableMap for serialization + private final ImmutableMap> subdomains; + // recordList is an ImmutableMap for serialization + private final ImmutableMap> recordsList; + + private CreateDomain(String name, String email, Optional ttl, Optional comment, + ImmutableMap> subdomains, + ImmutableMap> recordsList) { + this.name = checkNotNull(name, "name required"); + this.emailAddress = checkNotNull(email, "email required"); + this.ttl = ttl; + this.comment = comment; + this.subdomains = subdomains != null ? subdomains : ImmutableMap.> of(); + this.recordsList = recordsList != null ? recordsList : ImmutableMap.> of(); + } + + /** + * @see Builder#name(String) + */ + public String getName() { + return name; + } + + /** + * @see Builder#email(String) + */ + public String getEmail() { + return emailAddress; + } + + /** + * @see Builder#ttl(Integer) + */ + public Optional getTTL() { + return ttl; + } + + /** + * @see Builder#comment(String) + */ + public Optional getComment() { + return comment; + } + + /** + * @see Builder#subdomains(Iterable) + */ + public Iterable getSubdomains() { + return subdomains.get("domains"); + } + + /** + * @see Builder#records(Iterable) + */ + public Iterable getRecords() { + return recordsList.get("records"); + } + + @Override + public int hashCode() { + return Objects.hashCode(name); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null || getClass() != obj.getClass()) + return false; + CreateDomain that = CreateDomain.class.cast(obj); + + return Objects.equal(this.name, that.name); + } + + protected ToStringHelper string() { + return Objects.toStringHelper(this).omitNullValues().add("name", name).add("email", emailAddress) + .add("ttl", ttl.orNull()).add("comment", comment.orNull()).add("subdomains", subdomains) + .add("records", recordsList); + } + + @Override + public String toString() { + return string().toString(); + } + + public static class Builder { + private String name; + private String emailAddress; + private Optional ttl = Optional.absent(); + private Optional comment = Optional.absent(); + private ImmutableMap> subdomains; + private ImmutableMap> records; + + /** + * The name for the domain or subdomain. Must be a fully qualified domain name (FQDN) that doesn't end in a '.'. + */ + public Builder name(String name) { + this.name = name; + return this; + } + + /** + * Email address to use for contacting the domain administrator. Used as the email-addr (rname) in the SOA record. + */ + public Builder email(String email) { + this.emailAddress = email; + return this; + } + + /** + * The duration in seconds that the record may be cached by clients. If specified, must be greater than 300. The + * default value, if not specified, is 3600. + */ + public Builder ttl(Integer ttl) { + this.ttl = Optional.fromNullable(ttl); + return this; + } + + /** + * If included, its length must be less than or equal to 160 characters. + */ + public Builder comment(String comment) { + this.comment = Optional.fromNullable(comment); + return this; + } + + /** + * Create Subdomains of this Domain. + */ + public Builder subdomains(Iterable subdomains) { + if (subdomains != null) { + this.subdomains = ImmutableMap.of("domains", subdomains); + } + + return this; + } + + /** + * Create Records for this Domain. + *

+ * See + * Supported Record Types + */ + public Builder records(Iterable records) { + if (records != null) { + this.records = ImmutableMap.of("records", records); + } + + return this; + } + + public CreateDomain build() { + return new CreateDomain(name, emailAddress, ttl, comment, subdomains, records); + } + + public Builder from(CreateDomain in) { + return this.name(in.getName()).email(in.getEmail()).ttl(in.getTTL().orNull()) + .comment(in.getComment().orNull()).subdomains(in.getSubdomains()).records(in.getRecords()); + } + } + + public static Builder builder() { + return new Builder(); + } + + public Builder toBuilder() { + return new Builder().from(this); + } +} diff --git a/apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/domain/CreateSubdomain.java b/apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/domain/CreateSubdomain.java new file mode 100644 index 0000000000..da94cb5176 --- /dev/null +++ b/apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/domain/CreateSubdomain.java @@ -0,0 +1,153 @@ +/** + * 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, String 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.rackspace.clouddns.v1.domain; + +import static com.google.common.base.Preconditions.checkNotNull; + +import com.google.common.base.Objects; +import com.google.common.base.Objects.ToStringHelper; +import com.google.common.base.Optional; + +/** + * @author Everett Toews + */ +public class CreateSubdomain { + private final String name; + private final String emailAddress; + private final Optional ttl; + private final Optional comment; + + private CreateSubdomain(String name, String email, Optional ttl, Optional comment) { + this.name = checkNotNull(name, "name required"); + this.emailAddress = checkNotNull(email, "email required"); + this.ttl = ttl; + this.comment = comment; + } + + /** + * @see Builder#name(String) + */ + public String getName() { + return name; + } + + /** + * @see Builder#email(String) + */ + public String getEmail() { + return emailAddress; + } + + /** + * @see Builder#ttl(Integer) + */ + public Optional getTTL() { + return ttl; + } + + /** + * @see Builder#comment(String) + */ + public Optional getComment() { + return comment; + } + + @Override + public int hashCode() { + return Objects.hashCode(name); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null || getClass() != obj.getClass()) + return false; + CreateSubdomain that = CreateSubdomain.class.cast(obj); + + return Objects.equal(this.name, that.name); + } + + protected ToStringHelper string() { + return Objects.toStringHelper(this).omitNullValues().add("name", name).add("email", emailAddress) + .add("ttl", ttl.orNull()).add("comment", comment.orNull()); + } + + @Override + public String toString() { + return string().toString(); + } + + public static class Builder { + private String name; + private String emailAddress; + private Optional ttl = Optional.absent(); + private Optional comment = Optional.absent(); + + /** + * The name for the subdomain. Must be a fully qualified domain name (FQDN) that doesn't end in a '.'. + */ + public Builder name(String name) { + this.name = name; + return this; + } + + /** + * Email address to use for contacting the domain administrator. Used as the email-addr (rname) in the SOA record. + */ + public Builder email(String email) { + this.emailAddress = email; + return this; + } + + /** + * The duration in seconds that the record may be cached. If specified, must be greater than 300. The default + * value, if not specified, is 3600. + */ + public Builder ttl(Integer ttl) { + this.ttl = Optional.fromNullable(ttl); + return this; + } + + /** + * If included, its length must be less than or equal to 160 characters. + */ + public Builder comment(String comment) { + this.comment = Optional.fromNullable(comment); + return this; + } + + public CreateSubdomain build() { + return new CreateSubdomain(name, emailAddress, ttl, comment); + } + + public Builder from(CreateSubdomain in) { + return this.name(in.getName()).email(in.getEmail()).ttl(in.getTTL().orNull()) + .comment(in.getComment().orNull()); + } + } + + public static Builder builder() { + return new Builder(); + } + + public Builder toBuilder() { + return new Builder().from(this); + } +} diff --git a/apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/domain/Domain.java b/apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/domain/Domain.java new file mode 100644 index 0000000000..9ed8c6d162 --- /dev/null +++ b/apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/domain/Domain.java @@ -0,0 +1,162 @@ +/** + * 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.rackspace.clouddns.v1.domain; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.beans.ConstructorProperties; +import java.util.Date; +import java.util.Set; + +import org.jclouds.javax.annotation.Nullable; + +import com.google.common.base.Objects; +import com.google.common.base.Objects.ToStringHelper; +import com.google.common.base.Optional; +import com.google.common.collect.ImmutableSet; + +/** + * A domain is an entity/container of all DNS-related information containing one or more records. Within Rackspace DNS, + * the account which creates the domain is the domain owner. + * + * @author Everett Toews + */ +public class Domain { + private final int id; + private final String name; + private final String email; + private final Optional comment; + private final Date created; + private final Date updated; + private final int accountId; + private final int ttl; + private final Set nameservers; + private final Set subdomains; + private final Set records; + + @ConstructorProperties({ "id", "name", "emailAddress", "comment", "created", "updated", "accountId", "ttl", + "nameservers", "subdomains", "recordsList" }) + protected Domain(int id, String name, String email, @Nullable String comment, Date created, Date updated, + int accountId, int ttl, @Nullable Set nameservers, @Nullable Set nameToSubdomain, + @Nullable Set records) { + this.id = id; + this.name = name; + this.email = email; + this.comment = Optional.fromNullable(comment); + this.created = created; + this.updated = updated; + this.accountId = accountId; + this.ttl = ttl; + this.nameservers = nameservers != null ? nameservers : ImmutableSet. of(); + this.subdomains = nameToSubdomain != null ? nameToSubdomain : ImmutableSet. of(); + this.records = records != null ? records : ImmutableSet. of(); + } + + public int getId() { + return id; + } + + public String getName() { + return name; + } + + public String getEmail() { + return email; + } + + public Optional getComment() { + return comment; + } + + public Date getCreated() { + return created; + } + + public Date getUpdated() { + return updated; + } + + public int getAccountId() { + return accountId; + } + + public int getTTL() { + return ttl; + } + + public Set getNameservers() { + return nameservers; + } + + public Set getSubdomains() { + return subdomains; + } + + public Set getRecords() { + return records; + } + + @Override + public int hashCode() { + return Objects.hashCode(id); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null || getClass() != obj.getClass()) + return false; + Domain that = Domain.class.cast(obj); + + return Objects.equal(this.id, that.id); + } + + protected ToStringHelper string() { + return Objects.toStringHelper(this).omitNullValues().add("id", id).add("name", name).add("email", email) + .add("comment", comment.orNull()).add("created", created).add("updated", updated) + .add("accountId", accountId).add("ttl", ttl).add("nameservers", nameservers) + .add("subdomains", subdomains).add("records", records); + } + + @Override + public String toString() { + return string().toString(); + } + + protected Domain from(Domain in) { + return new Domain(in.getId(), in.getName(), in.getEmail(), in.getComment().orNull(), in.getCreated(), + in.getUpdated(), in.getAccountId(), in.getTTL(), in.getNameservers(), in.getSubdomains(), in.getRecords()); + } + + public enum Format { + BIND_9, + + UNRECOGNIZED; + + public static Format fromValue(String format) { + try { + return valueOf(checkNotNull(format, "format").toUpperCase()); + } + catch (IllegalArgumentException e) { + return UNRECOGNIZED; + } + } + } +} diff --git a/apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/domain/DomainChange.java b/apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/domain/DomainChange.java new file mode 100644 index 0000000000..6e134cac3e --- /dev/null +++ b/apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/domain/DomainChange.java @@ -0,0 +1,188 @@ +/** + * 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, String 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.rackspace.clouddns.v1.domain; + +import static com.google.common.base.Objects.equal; + +import java.beans.ConstructorProperties; +import java.util.Date; +import java.util.List; + +import com.google.common.base.Objects; + +public class DomainChange { + private final Date from; + private final Date to; + private final List changes; + + @ConstructorProperties({ "from", "to", "changes" }) + private DomainChange(Date from, Date to, List changes) { + this.from = from; + this.to = to; + this.changes = changes; + } + + public Date getFrom() { + return from; + } + + public Date getTo() { + return to; + } + + public List getChanges() { + return changes; + } + + @Override + public int hashCode() { + return Objects.hashCode(from, to, changes); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null || getClass() != obj.getClass()) + return false; + DomainChange that = DomainChange.class.cast(obj); + return equal(this.from, that.from) && equal(this.to, that.to) && equal(this.changes, that.changes); + } + + @Override + public String toString() { + return Objects.toStringHelper(this).omitNullValues().add("from", from).add("to", to).add("changes", changes) + .toString(); + } + + public static class Change { + private final String domain; + private final String action; + private final String targetType; + private final int accountId; + private final int targetId; + private final List changeDetails; + + @ConstructorProperties({ "domain", "action", "targetType", "accountId", "targetId", "changeDetails" }) + protected Change(String domain, String action, String targetType, int accountId, int targetId, + List changeDetails) { + this.domain = domain; + this.action = action; + this.targetType = targetType; + this.accountId = accountId; + this.targetId = targetId; + this.changeDetails = changeDetails; + } + + public String getDomain() { + return domain; + } + + public String getAction() { + return action; + } + + public String getTargetType() { + return targetType; + } + + public int getAccountId() { + return accountId; + } + + public int getTargetId() { + return targetId; + } + + public List getChangeDetails() { + return changeDetails; + } + + @Override + public int hashCode() { + return Objects.hashCode(domain, action, targetType, accountId, targetId, changeDetails); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null || getClass() != obj.getClass()) + return false; + Change that = Change.class.cast(obj); + return equal(this.domain, that.domain) && equal(this.action, that.action) + && equal(this.targetType, that.targetType) && equal(this.accountId, that.accountId) + && equal(this.targetId, that.targetId) && equal(this.changeDetails, that.changeDetails); + } + + @Override + public String toString() { + return Objects.toStringHelper(this).omitNullValues().add("domain", domain).add("action", action) + .add("targetType", targetType).add("accountId", accountId).add("targetId", targetId) + .add("changeDetails", changeDetails).toString(); + } + } + + public static class ChangeDetail { + private final String field; + private final String originalValue; + private final String newValue; + + @ConstructorProperties({ "field", "originalValue", "newValue" }) + protected ChangeDetail(String field, String originalValue, String newValue) { + this.field = field; + this.originalValue = originalValue; + this.newValue = newValue; + } + + public String getField() { + return field; + } + + public String getOriginalValue() { + return originalValue; + } + + public String getNewValue() { + return newValue; + } + + @Override + public int hashCode() { + return Objects.hashCode(field, originalValue, newValue); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null || getClass() != obj.getClass()) + return false; + ChangeDetail that = ChangeDetail.class.cast(obj); + return equal(this.field, that.field) && equal(this.originalValue, that.originalValue) + && equal(this.newValue, that.newValue); + } + + @Override + public String toString() { + return Objects.toStringHelper(this).omitNullValues().add("field", field).add("originalValue", originalValue) + .add("newValue", newValue).toString(); + } + } +} diff --git a/apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/domain/Job.java b/apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/domain/Job.java new file mode 100644 index 0000000000..fc8d79ff32 --- /dev/null +++ b/apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/domain/Job.java @@ -0,0 +1,129 @@ +package org.jclouds.rackspace.clouddns.v1.domain; + +import static com.google.common.base.Objects.toStringHelper; +import static com.google.common.base.Preconditions.checkNotNull; + +import java.beans.ConstructorProperties; + +import org.jclouds.rackspace.clouddns.v1.CloudDNSApi; + +import com.google.common.base.Optional; + +/** + * @see CloudDNSApi#getJob(String) + * @author Everett Toews + */ +public class Job { + private final String id; + private final Status status; + private final Optional error; + private final Optional resource; + + private Job(String id, Status status, Optional error, Optional resource) { + this.id = id; + this.status = status; + this.error = error; + this.resource = resource; + } + + public String getId() { + return id; + } + + public Status getStatus() { + return status; + } + + public Optional getError() { + return error; + } + + public Optional getResource() { + return resource; + } + + public enum Status { + /** + * INITIALIZED is the status that immediately precedes RUNNING and is the first possible state of a job. + * It indicates acceptance of the job. + */ + INITIALIZED, + + RUNNING, COMPLETED, ERROR, UNRECOGNIZED; + + public static Status fromValue(String status) { + try { + return valueOf(checkNotNull(status, "status").toUpperCase()); + } + catch (IllegalArgumentException e) { + return UNRECOGNIZED; + } + } + } + + public static Builder builder() { + return new Builder(); + } + + public static class Builder { + private String id; + private Status status; + private Optional error = Optional.absent(); + private Optional resource = Optional.absent(); + + public Builder id(String id) { + this.id = id; + return this; + } + + public Builder status(Status status) { + this.status = status; + return this; + } + + public Builder error(Error error) { + this.error = Optional.fromNullable(error); + return this; + } + + public Builder resource(T resource) { + this.resource = Optional.fromNullable(resource); + return this; + } + + public Job build() { + return new Job(id, status, error, resource); + } + } + + public static final class Error { + + private final int code; + private final String message; + private final String details; + + @ConstructorProperties({ "code", "message", "details" }) + protected Error(int code, String message, String details) { + this.code = code; + this.message = message; + this.details = details; + } + + public int getCode() { + return code; + } + + public String getMessage() { + return message; + } + + public String getDetails() { + return details; + } + + @Override + public String toString() { + return toStringHelper(this).add("code", code).add("message", message).add("details", details).toString(); + } + } +} diff --git a/apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/domain/Record.java b/apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/domain/Record.java new file mode 100644 index 0000000000..a7c9f94207 --- /dev/null +++ b/apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/domain/Record.java @@ -0,0 +1,221 @@ +/** + * 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.rackspace.clouddns.v1.domain; + +import static com.google.common.base.Objects.equal; +import static com.google.common.base.Objects.toStringHelper; + +import org.jclouds.javax.annotation.Nullable; + +import com.google.common.base.Objects; +import com.google.common.base.Objects.ToStringHelper; +import com.google.common.base.Optional; + +/** + * @author Everett Toews + */ +public class Record { + private final String name; + private final String type; + private final Optional ttl; + private final String data; + private final Integer priority; + private final String comment; + + private Record(@Nullable String name, @Nullable String type, Optional ttl, @Nullable String data, + @Nullable Integer priority, @Nullable String comment) { + this.name = name; + this.type = type; + this.ttl = ttl; + this.data = data; + this.priority = priority; + this.comment = comment; + } + + /** + * @see Record.Builder#name(String) + */ + public String getName() { + return name; + } + + /** + * @see Record.Builder#type(String) + */ + public String getType() { + return type; + } + + /** + * @see Record.Builder#ttl(Integer) + */ + public Optional getTTL() { + return ttl; + } + + /** + * @see Record.Builder#data(String) + */ + public String getData() { + return data; + } + + /** + * @see Record.Builder#priority(Integer) + */ + @Nullable + public Integer getPriority() { + return priority; + } + + /** + * @see Record.Builder#comment(String) + */ + @Nullable + public String getComment() { + return comment; + } + + @Override + public int hashCode() { + return Objects.hashCode(name, type, ttl, data, priority, comment); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null || getClass() != obj.getClass()) + return false; + Record that = Record.class.cast(obj); + + return equal(this.name, that.name) && equal(this.type, that.type) && equal(this.ttl, that.ttl) + && equal(this.data, that.data) && equal(this.priority, that.priority) && equal(this.comment, that.comment); + } + + protected ToStringHelper string() { + return toStringHelper(this).omitNullValues().add("name", name).add("type", type).add("ttl", ttl) + .add("data", data).add("priority", priority).add("comment", comment); + } + + @Override + public String toString() { + return string().toString(); + } + + public final static class Builder { + private String name; + private String type; + private Optional ttl = Optional.absent(); + private String data; + private Integer priority; + private String comment; + + /** + * The name for the domain or subdomain. Must be a fully qualified domain name (FQDN) that doesn't end in a '.'. + *

+ * Users can add one or more wildcard records to any domain or sub-domain on their account. For information on the + * intent and use of wildcard records, see the DNS literature including RFC 1034, section 4.3.3, and RFC 4595. + *

+ * Wildcards are supported for A, AAAA, CNAME, MX, SRV and TXT record types. + *

+ * A valid wildcard DNS record is specified by using an asterisk ("*") as the leftmost part of a record name, for + * example *.example.com. An asterisk in any other part of a record name is invalid. Only the asterisk ("*") is + * accepted as a wildcard character. + *

+ * For SRV records, this specifies the entire service name, which is made up of the service, protocol, and domain + * name to which the record belongs. The service and protocol fields of the service name can be modified but not + * the domain name field. + */ + public Builder name(String name) { + this.name = name; + return this; + } + + /** + * The record type to add. + *

+ * See + * Supported Record Types + */ + public Builder type(String type) { + this.type = type; + return this; + } + + /** + * The duration in seconds that the record may be cached by clients. If specified, must be greater than 300. The + * default value, if not specified, is 3600. + */ + public Builder ttl(int ttl) { + this.ttl = Optional.fromNullable(ttl); + return this; + } + + /** + * @see Builder#ttl(int) + */ + public Builder ttl(Optional ttl) { + this.ttl = ttl; + return this; + } + + /** + * The data field for PTR, A, and AAAA records must be a valid IPv4 or IPv6 IP address. + */ + public Builder data(String data) { + this.data = data; + return this; + } + + /** + * Required for MX and SRV records, but forbidden for other record types. If specified, must be an integer from 0 + * to 65535. + */ + public Builder priority(Integer priority) { + this.priority = priority; + return this; + } + + /** + * If included, its length must be less than or equal to 160 characters. + */ + public Builder comment(String comment) { + this.comment = comment; + return this; + } + + public Record build() { + return new Record(name, type, ttl, data, priority, comment); + } + + public Builder from(Record in) { + return name(in.getName()).type(in.getType()).ttl(in.getTTL()).data(in.getData()).priority(in.getPriority()) + .comment(in.getComment()); + } + } + + public static Builder builder() { + return new Builder(); + } + + public Builder toBuilder() { + return builder().from(this); + } +} diff --git a/apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/domain/RecordDetail.java b/apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/domain/RecordDetail.java new file mode 100644 index 0000000000..d7f35b1f67 --- /dev/null +++ b/apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/domain/RecordDetail.java @@ -0,0 +1,186 @@ +/** + * 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.rackspace.clouddns.v1.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.Date; + +import com.google.common.base.Objects; +import com.google.common.base.Objects.ToStringHelper; + +/** + * @author Everett Toews + */ +public class RecordDetail { + private final String id; + private final Date created; + private final Date updated; + private final Record record; + + private RecordDetail(String id, Date created, Date updated, Record record) { + this.id = checkNotNull(id, "id required"); + this.created = checkNotNull(created, "created required"); + this.updated = checkNotNull(updated, "updated required"); + this.record = checkNotNull(record, "record required"); + } + + public String getId() { + return id; + } + + /** + * When this record was created. + */ + public Date getCreated() { + return created; + } + + /** + * When this record was updated. + */ + public Date getUpdated() { + return updated; + } + + /** + * The Record. + */ + public Record getRecord() { + return record; + } + + /** + * @see Record.Builder#name(String) + */ + public String getName() { + return record.getName(); + } + + /** + * @see Record.Builder#type(String) + */ + public String getType() { + return record.getType(); + } + + /** + * @see Record.Builder#ttl(Integer) + */ + public int getTTL() { + return record.getTTL().get(); + } + + /** + * @see Record.Builder#data(String) + */ + public String getData() { + return record.getData(); + } + + /** + * @see Record.Builder#priority(Integer) + */ + public Integer getPriority() { + return record.getPriority(); + } + + /** + * @see Record.Builder#comment(String) + */ + public String getComment() { + return record.getComment(); + } + + @Override + public int hashCode() { + return Objects.hashCode(id); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null || getClass() != obj.getClass()) + return false; + RecordDetail that = RecordDetail.class.cast(obj); + + return equal(this.id, that.id); + } + + protected ToStringHelper string() { + return toStringHelper(this).omitNullValues().add("id", id).add("created", created).add("updated", updated) + .add("record", record); + } + + @Override + public String toString() { + return string().toString(); + } + + public final static class Builder { + private String id; + private Date created; + private Date updated; + private Record record; + + public Builder id(String id) { + this.id = id; + return this; + } + + public Builder created(Date created) { + this.created = created; + return this; + } + + public Builder updated(Date updated) { + this.updated = updated; + return this; + } + + public Builder record(Record record) { + this.record = record; + return this; + } + + public Builder record(Record.Builder recordBuilder) { + this.record = recordBuilder.build(); + return this; + } + + public RecordDetail build() { + return new RecordDetail(id, created, updated, record); + } + + public Builder from(RecordDetail in) { + return this.id(in.getId()).created(in.getCreated()).updated(in.getUpdated()).record(in.getRecord()); + } + } + + public static Builder builder() { + return new Builder(); + } + + public Builder toBuilder() { + return builder().from(this); + } +} diff --git a/apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/domain/Subdomain.java b/apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/domain/Subdomain.java new file mode 100644 index 0000000000..097c859e9f --- /dev/null +++ b/apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/domain/Subdomain.java @@ -0,0 +1,98 @@ +/** + * 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, String 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.rackspace.clouddns.v1.domain; + +import java.beans.ConstructorProperties; +import java.util.Date; + +import org.jclouds.javax.annotation.Nullable; + +import com.google.common.base.Objects; +import com.google.common.base.Optional; + +/** + * Subdomains are domains within a parent domain. Subdomains allow you to delegate domains. Subdomains can themselves + * have subdomains, so third-level, fourth-level, fifth-level, and deeper levels of nesting are possible. + * + * @author Everett Toews + */ +public class Subdomain { + private final int id; + private final String name; + private final String emailAddress; + private final Optional comment; + private final Date created; + private final Date updated; + + @ConstructorProperties({ "id", "name", "emailAddress", "comment", "created", "updated" }) + private Subdomain(int id, String name, String email, @Nullable String comment, Date created, Date updated) { + this.id = id; + this.name = name; + this.emailAddress = email; + this.comment = Optional.fromNullable(comment); + this.created = created; + this.updated = updated; + } + + public int getId() { + return id; + } + + public String getName() { + return name; + } + + public String getEmail() { + return emailAddress; + } + + public Optional getComment() { + return comment; + } + + public Date getCreated() { + return created; + } + + public Date getUpdated() { + return updated; + } + + @Override + public int hashCode() { + return Objects.hashCode(id); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null || getClass() != obj.getClass()) + return false; + Subdomain that = Subdomain.class.cast(obj); + + return Objects.equal(this.id, that.id); + } + + @Override + public String toString() { + return Objects.toStringHelper(this).omitNullValues().add("id", id).add("name", name).add("email", emailAddress) + .add("comment", comment.orNull()).add("created", created).add("updated", updated).toString(); + } +} diff --git a/apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/domain/UpdateDomain.java b/apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/domain/UpdateDomain.java new file mode 100644 index 0000000000..ebd0b50048 --- /dev/null +++ b/apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/domain/UpdateDomain.java @@ -0,0 +1,125 @@ +/** + * 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, String 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.rackspace.clouddns.v1.domain; + +import com.google.common.base.Objects; +import com.google.common.base.Objects.ToStringHelper; +import com.google.common.base.Optional; + +/** + * Update a Domain or Subdomain. + * + * @author Everett Toews + */ +public class UpdateDomain { + private final Optional emailAddress; + private final Optional ttl; + private final Optional comment; + + private UpdateDomain(Optional email, Optional ttl, Optional comment) { + this.emailAddress = email; + this.ttl = ttl; + this.comment = comment; + } + + public Optional getEmail() { + return emailAddress; + } + + public Optional getTTL() { + return ttl; + } + + public Optional getComment() { + return comment; + } + + @Override + public int hashCode() { + return Objects.hashCode(emailAddress, ttl, comment); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null || getClass() != obj.getClass()) + return false; + UpdateDomain that = UpdateDomain.class.cast(obj); + + return Objects.equal(this.emailAddress, that.emailAddress) && Objects.equal(this.ttl, that.ttl) + && Objects.equal(this.comment, that.comment); + } + + protected ToStringHelper string() { + return Objects.toStringHelper(this).omitNullValues().add("email", emailAddress.orNull()).add("ttl", ttl.orNull()) + .add("comment", comment.orNull()); + } + + @Override + public String toString() { + return string().toString(); + } + + public static class Builder { + private Optional emailAddress = Optional.absent(); + private Optional ttl = Optional.absent(); + private Optional comment = Optional.absent(); + + /** + * Email address to use for contacting the domain administrator. + */ + public Builder email(String email) { + this.emailAddress = Optional.fromNullable(email); + return this; + } + + /** + * If specified, must be greater than 300. + */ + public Builder ttl(Integer ttl) { + this.ttl = Optional.fromNullable(ttl); + return this; + } + + /** + * If included, its length must be less than or equal to 160 characters. + */ + public Builder comment(String comment) { + this.comment = Optional.fromNullable(comment); + return this; + } + + public UpdateDomain build() { + return new UpdateDomain(emailAddress, ttl, comment); + } + + public Builder from(UpdateDomain in) { + return this.email(in.getEmail().orNull()).ttl(in.getTTL().orNull()).comment(in.getComment().orNull()); + } + } + + public static Builder builder() { + return new Builder(); + } + + public Builder toBuilder() { + return new Builder().from(this); + } +} diff --git a/apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/features/DomainApi.java b/apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/features/DomainApi.java new file mode 100644 index 0000000000..494c313116 --- /dev/null +++ b/apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/features/DomainApi.java @@ -0,0 +1,298 @@ +/** + * 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, String 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.rackspace.clouddns.v1.features; + +import java.util.Date; +import java.util.List; +import java.util.Set; + +import javax.inject.Named; +import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.MediaType; + +import org.jclouds.Fallbacks.EmptyPagedIterableOnNotFoundOr404; +import org.jclouds.Fallbacks.NullOnNotFoundOr404; +import org.jclouds.Fallbacks.VoidOnNotFoundOr404; +import org.jclouds.collect.PagedIterable; +import org.jclouds.javax.annotation.Nullable; +import org.jclouds.openstack.keystone.v2_0.filters.AuthenticateRequest; +import org.jclouds.rackspace.clouddns.v1.CloudDNSApi; +import org.jclouds.rackspace.clouddns.v1.binders.FormatAndContentsToJSON; +import org.jclouds.rackspace.clouddns.v1.binders.UpdateDomainsToJSON; +import org.jclouds.rackspace.clouddns.v1.config.CloudDNS; +import org.jclouds.rackspace.clouddns.v1.domain.CreateDomain; +import org.jclouds.rackspace.clouddns.v1.domain.Domain; +import org.jclouds.rackspace.clouddns.v1.domain.DomainChange; +import org.jclouds.rackspace.clouddns.v1.domain.Job; +import org.jclouds.rackspace.clouddns.v1.domain.Subdomain; +import org.jclouds.rackspace.clouddns.v1.domain.UpdateDomain; +import org.jclouds.rackspace.clouddns.v1.functions.DomainsToPagedIterable; +import org.jclouds.rackspace.clouddns.v1.functions.ParseDomain; +import org.jclouds.rackspace.clouddns.v1.functions.ParseDomains; +import org.jclouds.rackspace.clouddns.v1.functions.ParseJob; +import org.jclouds.rackspace.clouddns.v1.functions.ParseSubdomains; +import org.jclouds.rackspace.clouddns.v1.functions.SubdomainsToPagedIterable; +import org.jclouds.rackspace.clouddns.v1.predicates.JobPredicates; +import org.jclouds.rackspace.cloudidentity.v2_0.CloudIdentityFallbacks.EmptyPaginatedCollectionOnNotFoundOr404; +import org.jclouds.rackspace.cloudidentity.v2_0.domain.PaginatedCollection; +import org.jclouds.rackspace.cloudidentity.v2_0.functions.DateParser; +import org.jclouds.rackspace.cloudidentity.v2_0.options.PaginationOptions; +import org.jclouds.rest.annotations.BinderParam; +import org.jclouds.rest.annotations.Endpoint; +import org.jclouds.rest.annotations.Fallback; +import org.jclouds.rest.annotations.MapBinder; +import org.jclouds.rest.annotations.ParamParser; +import org.jclouds.rest.annotations.PayloadParam; +import org.jclouds.rest.annotations.QueryParams; +import org.jclouds.rest.annotations.RequestFilters; +import org.jclouds.rest.annotations.ResponseParser; +import org.jclouds.rest.annotations.Transform; +import org.jclouds.rest.annotations.WrapWith; +import org.jclouds.rest.binders.BindToJsonPayload; + +/** + * @author Everett Toews + */ +@Endpoint(CloudDNS.class) +@RequestFilters(AuthenticateRequest.class) +public interface DomainApi { + /** + * Provisions one or more new DNS domains based on the configuration defined in CreateDomain. If the domain + * creation cannot be fulfilled due to insufficient or invalid data, Job with an ERROR status will + * be returned with information regarding the nature of the failure in the body of the Job. Failures in the + * validation process are non-recoverable and require the caller to correct the cause of the failure. + * This is an atomic operation: if there is a failure in creation of even a single record, the entire process + * will fail. + *

+ * When a domain is created, and no Time To Live (TTL) is specified, the SOA minTTL (3600 seconds) is used as the + * default. When a record is added without a specified TTL, it will receive the domain TTL by default. When the + * domain and/or record TTL is supplied by the user, either via a create or update call, the TTL values must be 300 + * seconds or more. + *

+ * To wait for this call to complete use {@link JobPredicates#awaitComplete(CloudDNSApi, Job)}. + */ + @Named("domain:create") + @POST + @Consumes(MediaType.APPLICATION_JSON) + @ResponseParser(ParseJob.class) + @Path("/domains") + Job> create(@WrapWith("domains") Iterable createDomains); + + /** + * The resulting list is flat, and does not break the domains down hierarchically by subdomain. All representative + * domains are included in the list, even if a domain is conceptually a subdomain of another domain in the list. + * Records are not included. + */ + @Named("domain:list") + @GET + @Consumes(MediaType.APPLICATION_JSON) + @ResponseParser(ParseDomains.class) + @Transform(DomainsToPagedIterable.class) + @Path("/domains") + @Fallback(EmptyPagedIterableOnNotFoundOr404.class) + PagedIterable list(); + + /** + * Filtering the search to limit the results returned can be performed by using the nameFilter parameter. For + * example, "hoola.com" matches hoola.com and similar names such as main.hoola.com and sub.hoola.com. + *

+ * Filter criteria may consist of: + *
    + *
  • Any letter (A-Za-z)
  • + *
  • Numbers (0-9)
  • + *
  • Hyphen ("-")
  • + *
  • 1 to 63 characters
  • + *
+ * Filter criteria should not include any of the following characters: ' + , | ! " £ $ % & / ( ) = ? ^ * ç ° § ; : _ + * > ] [ @ à, é, ò + */ + @Named("domain:list") + @GET + @Consumes(MediaType.APPLICATION_JSON) + @ResponseParser(ParseDomains.class) + @Transform(DomainsToPagedIterable.class) + @Path("/domains") + @Fallback(EmptyPagedIterableOnNotFoundOr404.class) + PagedIterable listWithFilterByNamesMatching(@QueryParam("name") String nameFilter); + + /** + * The resulting list is flat, and does not break the domains down hierarchically by subdomain. + */ + @Named("domain:list") + @GET + @ResponseParser(ParseDomains.class) + @Consumes(MediaType.APPLICATION_JSON) + @Fallback(EmptyPaginatedCollectionOnNotFoundOr404.class) + @Path("/domains") + PaginatedCollection list(PaginationOptions options); + + /** + * List the subdomains of a domain. + */ + @Named("domain:list") + @GET + @Consumes(MediaType.APPLICATION_JSON) + @ResponseParser(ParseSubdomains.class) + @Transform(SubdomainsToPagedIterable.class) + @Path("/domains/{domainId}/subdomains") + @Fallback(EmptyPagedIterableOnNotFoundOr404.class) + @Nullable + PagedIterable listSubdomains(@PathParam("domainId") int domainId); + + /** + * List the subdomains of a domain and manually control pagination. + */ + @Named("domain:list") + @GET + @ResponseParser(ParseSubdomains.class) + @Consumes(MediaType.APPLICATION_JSON) + @Fallback(EmptyPaginatedCollectionOnNotFoundOr404.class) + @Path("/domains/{domainId}/subdomains") + PaginatedCollection listSubdomains(@PathParam("domainId") int domainId, + PaginationOptions options); + + /** + * Shows all changes to the specified domain since the specified date/time. + */ + @Named("domain:list") + @GET + @Consumes(MediaType.APPLICATION_JSON) + @Path("/domains/{id}/changes") + @Fallback(NullOnNotFoundOr404.class) + @Nullable + DomainChange listChanges(@PathParam("id") int id, + @ParamParser(DateParser.class) @QueryParam("changes") Date since); + + /** + * Get all information for a Domain, including records and subdomains. + */ + @Named("domain:get") + @GET + @Consumes(MediaType.APPLICATION_JSON) + @Path("/domains/{id}") + @QueryParams(keys = { "showRecords", "showSubdomains" }, values = { "true", "true" }) + @ResponseParser(ParseDomain.class) + @Fallback(NullOnNotFoundOr404.class) + @Nullable + Domain get(@PathParam("id") int id); + + /** + * This call modifies the domain attributes only. Records cannot be added, modified, or removed. + *

+ * To wait for this call to complete use {@link JobPredicates#awaitComplete(CloudDNSApi, Job)}. + * + * @see RecordApi + */ + @Named("domain:update") + @PUT + @Produces(MediaType.APPLICATION_JSON) + @Consumes(MediaType.APPLICATION_JSON) + @ResponseParser(ParseJob.class) + @Path("/domains/{id}") + Job update(@PathParam("id") int id, @BinderParam(BindToJsonPayload.class) UpdateDomain updateDomain); + + /** + * This call modifies the domain's TTL only. + *

+ * To wait for this call to complete use {@link JobPredicates#awaitComplete(CloudDNSApi, Job)}. + */ + @Named("domain:update") + @PUT + @Produces(MediaType.APPLICATION_JSON) + @Consumes(MediaType.APPLICATION_JSON) + @ResponseParser(ParseJob.class) + @Path("/domains") + @MapBinder(UpdateDomainsToJSON.class) + Job updateTTL(@PayloadParam("ids") Iterable ids, @PayloadParam("ttl") int ttl); + + /** + * This call modifies the domain's email only. + *

+ * To wait for this call to complete use {@link JobPredicates#awaitComplete(CloudDNSApi, Job)}. + */ + @Named("domain:update") + @PUT + @Produces(MediaType.APPLICATION_JSON) + @Consumes(MediaType.APPLICATION_JSON) + @ResponseParser(ParseJob.class) + @Path("/domains") + @MapBinder(UpdateDomainsToJSON.class) + Job updateEmail(@PayloadParam("ids") Iterable ids, @PayloadParam("emailAddress") String email); + + /** + * This call removes one or more specified domains from the account; when a domain is deleted, its immediate resource + * records are also deleted from the account. By default, if a deleted domain had subdomains, each subdomain becomes + * a root domain and is not deleted; this can be overridden by the optional deleteSubdomains parameter. Utilizing the + * optional deleteSubdomains parameter on domains without subdomains does not result in a failure. When a domain is + * deleted, any and all domain data is immediately purged and is not recoverable via the API. + *

+ * To wait for this call to complete use {@link JobPredicates#awaitComplete(CloudDNSApi, Job)}. + */ + @Named("domain:delete") + @DELETE + @Fallback(VoidOnNotFoundOr404.class) + @ResponseParser(ParseJob.class) + @Path("/domains") + @Consumes("*/*") + Job delete(@QueryParam("id") Iterable ids, + @QueryParam("deleteSubdomains") boolean deleteSubdomains); + + /** + * This call provides the BIND (Berkeley Internet Name Domain) 9 formatted contents of the requested domain. This + * call is for a single domain only, and as such, does not traverse up or down the domain hierarchy for details (that + * is, no subdomain information is provided). + *

+ * To wait for this call to complete use {@link JobPredicates#awaitComplete(CloudDNSApi, Job)}. + */ + @Named("domain:export") + @GET + @Consumes(MediaType.APPLICATION_JSON) + @ResponseParser(ParseJob.class) + @Path("/domains/{id}/export") + // format is ignored because the Cloud DNS API doesn't use it but other formats (e.g. BIND 10) may be supported in + // the future and we don't want this interface to change + Job> exportFormat(@PathParam("id") int id, Domain.Format format); + + /** + * This call provisions a new DNS domain under the account specified by the BIND 9 formatted file configuration + * contents. If the corresponding request cannot be fulfilled due to insufficient or invalid data, an exception will + * be thrown with information regarding the nature of the failure in the body of the response. Failures in the + * validation process are non-recoverable and require the caller to correct the cause of the failure and call again. + *

+ * To wait for this call to complete use {@link JobPredicates#awaitComplete(CloudDNSApi, Job)}. + */ + @Named("domain:import") + @POST + @Produces(MediaType.APPLICATION_JSON) + @Consumes(MediaType.APPLICATION_JSON) + @ResponseParser(ParseJob.class) + @MapBinder(FormatAndContentsToJSON.class) + @Path("/domains/import") + Job importFormat( + @PayloadParam("contents") List contents, + @PayloadParam("format") Domain.Format format); +} diff --git a/apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/features/LimitApi.java b/apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/features/LimitApi.java new file mode 100644 index 0000000000..e911f9ff23 --- /dev/null +++ b/apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/features/LimitApi.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, String 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.rackspace.clouddns.v1.features; + +import javax.inject.Named; +import javax.ws.rs.Consumes; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.core.MediaType; + +import org.jclouds.openstack.keystone.v2_0.filters.AuthenticateRequest; +import org.jclouds.openstack.v2_0.domain.Limits; +import org.jclouds.rackspace.clouddns.v1.config.CloudDNS; +import org.jclouds.rest.annotations.Endpoint; +import org.jclouds.rest.annotations.RequestFilters; +import org.jclouds.rest.annotations.SelectJson; + +/** + * All accounts, by default, have a preconfigured set of thresholds (or limits) to manage capacity and prevent abuse + * of the system. The system recognizes two kinds of limits: rate limits and absolute limits. Rate limits are + * thresholds that are reset after a certain amount of time passes. Absolute limits are fixed. + * + * @author Everett Toews + */ +@Endpoint(CloudDNS.class) +@RequestFilters(AuthenticateRequest.class) +public interface LimitApi { + /** + * Provides a list of all applicable limits. + */ + @Named("limits:list") + @GET + @Consumes(MediaType.APPLICATION_JSON) + @SelectJson("limits") + @Path("/limits") + Limits list(); + + /** + * All applicable limit types. + */ + @Named("limits:list") + @GET + @Consumes(MediaType.APPLICATION_JSON) + @SelectJson("limitTypes") + @Path("/limits/types") + Iterable listTypes(); +} diff --git a/apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/features/RecordApi.java b/apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/features/RecordApi.java new file mode 100644 index 0000000000..b7b848747d --- /dev/null +++ b/apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/features/RecordApi.java @@ -0,0 +1,230 @@ +/** + * 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.rackspace.clouddns.v1.features; + +import java.util.Map; +import java.util.Set; + +import javax.inject.Named; +import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.MediaType; + +import org.jclouds.Fallbacks.EmptyPagedIterableOnNotFoundOr404; +import org.jclouds.Fallbacks.NullOnNotFoundOr404; +import org.jclouds.Fallbacks.VoidOnNotFoundOr404; +import org.jclouds.collect.PagedIterable; +import org.jclouds.javax.annotation.Nullable; +import org.jclouds.openstack.keystone.v2_0.filters.AuthenticateRequest; +import org.jclouds.rackspace.clouddns.v1.CloudDNSApi; +import org.jclouds.rackspace.clouddns.v1.binders.UpdateRecordsToJSON; +import org.jclouds.rackspace.clouddns.v1.config.CloudDNS; +import org.jclouds.rackspace.clouddns.v1.domain.Job; +import org.jclouds.rackspace.clouddns.v1.domain.Record; +import org.jclouds.rackspace.clouddns.v1.domain.RecordDetail; +import org.jclouds.rackspace.clouddns.v1.functions.ParseJob; +import org.jclouds.rackspace.clouddns.v1.functions.ParseOnlyRecord; +import org.jclouds.rackspace.clouddns.v1.functions.ParseRecord; +import org.jclouds.rackspace.clouddns.v1.functions.ParseRecords; +import org.jclouds.rackspace.clouddns.v1.functions.RecordsToPagedIterable; +import org.jclouds.rackspace.clouddns.v1.predicates.JobPredicates; +import org.jclouds.rackspace.cloudidentity.v2_0.CloudIdentityFallbacks.EmptyPaginatedCollectionOnNotFoundOr404; +import org.jclouds.rackspace.cloudidentity.v2_0.domain.PaginatedCollection; +import org.jclouds.rackspace.cloudidentity.v2_0.options.PaginationOptions; +import org.jclouds.rest.annotations.BinderParam; +import org.jclouds.rest.annotations.Endpoint; +import org.jclouds.rest.annotations.Fallback; +import org.jclouds.rest.annotations.RequestFilters; +import org.jclouds.rest.annotations.ResponseParser; +import org.jclouds.rest.annotations.Transform; +import org.jclouds.rest.annotations.WrapWith; +import org.jclouds.rest.binders.BindToJsonPayload; + +/** + * @author Everett Toews + */ +@Endpoint(CloudDNS.class) +@RequestFilters(AuthenticateRequest.class) +public interface RecordApi { + + /** + * Create Records for a Domain or Subdomain. + *

+ * See + * Supported Record Types + *

+ * To wait for this call to complete use {@link JobPredicates#awaitComplete(CloudDNSApi, Job)}. + */ + @Named("record:create") + @POST + @Consumes(MediaType.APPLICATION_JSON) + @ResponseParser(ParseJob.class) + @Path("/records") + Job> create(@WrapWith("records") Iterable createRecords); + + /** + * This call lists all records configured for the specified domain. + */ + @Named("record:list") + @GET + @Consumes(MediaType.APPLICATION_JSON) + @ResponseParser(ParseRecords.class) + @Transform(RecordsToPagedIterable.class) + @Path("/records") + @Fallback(EmptyPagedIterableOnNotFoundOr404.class) + PagedIterable list(); + + /** + * RecordDetails filtered by type. + */ + @Named("record:list") + @GET + @Consumes(MediaType.APPLICATION_JSON) + @ResponseParser(ParseRecords.class) + @Transform(RecordsToPagedIterable.class) + @Path("/records") + @Fallback(EmptyPagedIterableOnNotFoundOr404.class) + PagedIterable listByType( + @QueryParam("type") String typeFilter); + + /** + * RecordDetails filtered by type and data. + */ + @Named("record:list") + @GET + @Consumes(MediaType.APPLICATION_JSON) + @ResponseParser(ParseRecords.class) + @Transform(RecordsToPagedIterable.class) + @Path("/records") + @Fallback(EmptyPagedIterableOnNotFoundOr404.class) + PagedIterable listByTypeAndData( + @QueryParam("type") String typeFilter, + @QueryParam("data") String dataFilter); + + /** + * RecordDetails filtered by name and type. + */ + @Named("record:list") + @GET + @Consumes(MediaType.APPLICATION_JSON) + @ResponseParser(ParseRecords.class) + @Transform(RecordsToPagedIterable.class) + @Path("/records") + @Fallback(EmptyPagedIterableOnNotFoundOr404.class) + PagedIterable listByNameAndType( + @QueryParam("name") String nameFilter, + @QueryParam("type") String typeFilter); + + /** + * Use PaginationOptions to manually control the list of RecordDetail pages returned. + */ + @Named("record:list") + @GET + @ResponseParser(ParseRecords.class) + @Consumes(MediaType.APPLICATION_JSON) + @Fallback(EmptyPaginatedCollectionOnNotFoundOr404.class) + @Path("/records") + PaginatedCollection list(PaginationOptions options); + + /** + * RecordDetails filtered by name and type and data. + */ + @Named("record:get") + @GET + @Consumes(MediaType.APPLICATION_JSON) + @ResponseParser(ParseOnlyRecord.class) + @Path("/records") + @Fallback(NullOnNotFoundOr404.class) + @Nullable + RecordDetail getByNameAndTypeAndData( + @QueryParam("name") String nameFilter, + @QueryParam("type") String typeFilter, + @QueryParam("data") String dataFilter); + + /** + * Get the details for the specified record in the specified domain. + */ + @Named("record:get") + @GET + @ResponseParser(ParseRecord.class) + @Consumes(MediaType.APPLICATION_JSON) + @Path("/records/{recordId}") + @Fallback(NullOnNotFoundOr404.class) + @Nullable + RecordDetail get(@PathParam("recordId") String recordId); + + /** + * Update the configuration of the specified record in the specified domain. + *

+ * To wait for this call to complete use {@link JobPredicates#awaitComplete(CloudDNSApi, Job)}. + */ + @Named("record:update") + @PUT + @Consumes(MediaType.APPLICATION_JSON) + @ResponseParser(ParseJob.class) + @Path("/records/{recordId}") + Job update( + @PathParam("recordId") String recordId, + @BinderParam(BindToJsonPayload.class) Record record); + + /** + * Update the configuration of the specified records in the specified domain. + *

+ * To wait for this call to complete use {@link JobPredicates#awaitComplete(CloudDNSApi, Job)}. + */ + @Named("record:update") + @PUT + @Consumes(MediaType.APPLICATION_JSON) + @ResponseParser(ParseJob.class) + @Path("/records") + Job update( + @BinderParam(UpdateRecordsToJSON.class) Map idsToRecords); + + /** + * Delete the specified record in the specified domain. + *

+ * To wait for this call to complete use {@link JobPredicates#awaitComplete(CloudDNSApi, Job)}. + */ + @Named("record:delete") + @DELETE + @Fallback(VoidOnNotFoundOr404.class) + @ResponseParser(ParseJob.class) + @Path("/records/{recordId}") + @Consumes("*/*") + Job delete(@PathParam("recordId") String recordId); + + /** + * Delete the specified records in the specified domain. + *

+ * To wait for this call to complete use {@link JobPredicates#awaitComplete(CloudDNSApi, Job)}. + */ + @Named("record:delete") + @DELETE + @Fallback(VoidOnNotFoundOr404.class) + @ResponseParser(ParseJob.class) + @Path("/records") + @Consumes("*/*") + Job delete(@QueryParam("id") Iterable recordId); +} diff --git a/apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/features/ReverseDNSApi.java b/apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/features/ReverseDNSApi.java new file mode 100644 index 0000000000..fad68416d9 --- /dev/null +++ b/apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/features/ReverseDNSApi.java @@ -0,0 +1,155 @@ +/** + * 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, String 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.rackspace.clouddns.v1.features; + +import java.net.URI; +import java.util.Map; +import java.util.Set; + +import javax.inject.Named; +import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.MediaType; + +import org.jclouds.Fallbacks.EmptyPagedIterableOnNotFoundOr404; +import org.jclouds.Fallbacks.NullOnNotFoundOr404; +import org.jclouds.Fallbacks.VoidOnNotFoundOr404; +import org.jclouds.collect.PagedIterable; +import org.jclouds.openstack.keystone.v2_0.filters.AuthenticateRequest; +import org.jclouds.rackspace.clouddns.v1.CloudDNSApi; +import org.jclouds.rackspace.clouddns.v1.binders.CreateReverseDNSToJSON; +import org.jclouds.rackspace.clouddns.v1.binders.UpdateReverseDNSToJSON; +import org.jclouds.rackspace.clouddns.v1.config.CloudDNS; +import org.jclouds.rackspace.clouddns.v1.domain.Job; +import org.jclouds.rackspace.clouddns.v1.domain.Record; +import org.jclouds.rackspace.clouddns.v1.domain.RecordDetail; +import org.jclouds.rackspace.clouddns.v1.functions.ParseJob; +import org.jclouds.rackspace.clouddns.v1.functions.ParseRecord; +import org.jclouds.rackspace.clouddns.v1.functions.ParseRecords; +import org.jclouds.rackspace.clouddns.v1.functions.RecordsToPagedIterable; +import org.jclouds.rackspace.clouddns.v1.predicates.JobPredicates; +import org.jclouds.rest.annotations.Endpoint; +import org.jclouds.rest.annotations.Fallback; +import org.jclouds.rest.annotations.MapBinder; +import org.jclouds.rest.annotations.PayloadParam; +import org.jclouds.rest.annotations.RequestFilters; +import org.jclouds.rest.annotations.ResponseParser; +import org.jclouds.rest.annotations.Transform; + +/** + * Cloud DNS supports the management of reverse DNS (PTR) records for Rackspace Cloud devices such as Cloud Load + * Balancers and Cloud Servers (both first generation and next generation). In order to manage the PTR records for + * Rackspace Cloud devices, the service as well as the device resource URI must be specified along with record details. + * + * @author Everett Toews + */ +@Endpoint(CloudDNS.class) +@RequestFilters(AuthenticateRequest.class) +public interface ReverseDNSApi { + /** + * List all of the Reverse DNS (PTR) records for a device. + */ + @Named("rdns:list") + @GET + @Consumes(MediaType.APPLICATION_JSON) + @ResponseParser(ParseRecords.class) + @Transform(RecordsToPagedIterable.class) + @Fallback(EmptyPagedIterableOnNotFoundOr404.class) + @Path("/rdns/{serviceName}") + PagedIterable list( + @QueryParam("href") URI deviceURI); + + /** + * List all of the Reverse DNS (PTR) records for a device. + */ + @Named("rdns:list") + @GET + @Consumes(MediaType.APPLICATION_JSON) + @ResponseParser(ParseRecord.class) + @Fallback(NullOnNotFoundOr404.class) + @Path("/rdns/{serviceName}/{recordId}") + RecordDetail get( + @QueryParam("href") URI deviceURI, + @PathParam("recordId") String recordId); + + /** + * Create Reverse DNS (PTR) records for a device. + *

+ * To wait for this call to complete use {@link JobPredicates#awaitComplete(CloudDNSApi, Job)}. + */ + @Named("rdns:create") + @POST + @Produces(MediaType.APPLICATION_JSON) + @Consumes(MediaType.APPLICATION_JSON) + @ResponseParser(ParseJob.class) + @MapBinder(CreateReverseDNSToJSON.class) + @Path("/rdns") + Job> create( + @PayloadParam("href") URI deviceURI, + @PayloadParam("records") Iterable records); + + /** + * Update Reverse DNS (PTR) records for a device. + *

+ * To wait for this call to complete use {@link JobPredicates#awaitComplete(CloudDNSApi, Job)}. + */ + @Named("rdns:update") + @PUT + @Produces(MediaType.APPLICATION_JSON) + @Consumes(MediaType.APPLICATION_JSON) + @ResponseParser(ParseJob.class) + @MapBinder(UpdateReverseDNSToJSON.class) + @Path("/rdns") + Job update( + @PayloadParam("href") URI deviceURI, + @PayloadParam("idsToRecords") Map idsToRecords); + + /** + * Delete the Reverse DNS (PTR) record with the specified IP address for a device. + *

+ * To wait for this call to complete use {@link JobPredicates#awaitComplete(CloudDNSApi, Job)}. + */ + @Named("rdns:delete") + @DELETE + @Fallback(VoidOnNotFoundOr404.class) + @ResponseParser(ParseJob.class) + @Path("/rdns/{serviceName}") + @Consumes("*/*") + Job delete(@QueryParam("href") URI deviceURI, @QueryParam("ip") String ipAddress); + + /** + * Delete all Reverse DNS (PTR) records for a device. + *

+ * To wait for this call to complete use {@link JobPredicates#awaitComplete(CloudDNSApi, Job)}. + */ + @Named("rdns:delete") + @DELETE + @Fallback(VoidOnNotFoundOr404.class) + @ResponseParser(ParseJob.class) + @Path("/rdns/{serviceName}") + @Consumes("*/*") + Job deleteAll(@QueryParam("href") URI deviceURI); +} diff --git a/apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/functions/DomainFunctions.java b/apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/functions/DomainFunctions.java new file mode 100644 index 0000000000..2bd6ec0f99 --- /dev/null +++ b/apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/functions/DomainFunctions.java @@ -0,0 +1,51 @@ +/** + * 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.rackspace.clouddns.v1.functions; + +import java.util.Map; +import java.util.Set; + +import org.jclouds.rackspace.clouddns.v1.domain.Domain; + +import com.google.common.base.Function; +import com.google.common.collect.Maps; + +/** + * Functions for working with Domains. + * + * @author Everett Toews + */ +public class DomainFunctions { + + /** + * Take a Set of Domains and return a Map of domain name to the Domain. + */ + public static Map toDomainMap(Set domains) { + return Maps.uniqueIndex(domains, DomainFunctions.GET_DOMAIN_NAME); + } + + /** + * Take a Domain and return its name. + */ + public static final Function GET_DOMAIN_NAME = new Function() { + public String apply(Domain domain) { + return domain.getName(); + } + }; +} diff --git a/apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/functions/DomainsToPagedIterable.java b/apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/functions/DomainsToPagedIterable.java new file mode 100644 index 0000000000..95c2af3af0 --- /dev/null +++ b/apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/functions/DomainsToPagedIterable.java @@ -0,0 +1,73 @@ +/** + * 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.rackspace.clouddns.v1.functions; + +import static com.google.common.base.Preconditions.checkNotNull; + +import javax.inject.Inject; + +import org.jclouds.collect.IterableWithMarker; +import org.jclouds.collect.internal.Arg0ToPagedIterable; +import org.jclouds.rackspace.clouddns.v1.CloudDNSApi; +import org.jclouds.rackspace.clouddns.v1.domain.Domain; +import org.jclouds.rackspace.clouddns.v1.features.DomainApi; +import org.jclouds.rackspace.cloudidentity.v2_0.domain.PaginatedCollection; +import org.jclouds.rackspace.cloudidentity.v2_0.options.PaginationOptions; + +import com.google.common.annotations.Beta; +import com.google.common.base.Function; +import com.google.common.base.Optional; + +/** + * @author Everett Toews + */ +@Beta +public class DomainsToPagedIterable extends Arg0ToPagedIterable { + + private final DomainApi api; + + @Inject + protected DomainsToPagedIterable(CloudDNSApi api) { + this.api = checkNotNull(api, "api").getDomainApi(); + } + + @Override + protected Function> markerToNextForArg0(Optional arg0) { + return new ListDomainsAtMarker(api); + } + + private static class ListDomainsAtMarker implements Function> { + private final DomainApi api; + + @Inject + protected ListDomainsAtMarker(DomainApi api) { + this.api = checkNotNull(api, "api"); + } + + public PaginatedCollection apply(Object input) { + PaginationOptions paginationOptions = (PaginationOptions) input; + + return api.list(paginationOptions); + } + + public String toString() { + return "ListDomainsAtMarker"; + } + } +} diff --git a/apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/functions/ParseDomain.java b/apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/functions/ParseDomain.java new file mode 100644 index 0000000000..4ae2663afd --- /dev/null +++ b/apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/functions/ParseDomain.java @@ -0,0 +1,139 @@ +/** + * 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.rackspace.clouddns.v1.functions; + +import static com.google.common.base.Preconditions.checkNotNull; +import static org.jclouds.rackspace.clouddns.v1.functions.ParseRecord.toRecordDetails; + +import java.beans.ConstructorProperties; +import java.util.Date; +import java.util.Map; +import java.util.Set; + +import javax.inject.Inject; +import javax.inject.Named; + +import org.jclouds.http.HttpResponse; +import org.jclouds.http.functions.ParseJson; +import org.jclouds.rackspace.clouddns.v1.domain.Domain; +import org.jclouds.rackspace.clouddns.v1.domain.RecordDetail; +import org.jclouds.rackspace.clouddns.v1.domain.Subdomain; +import org.jclouds.rackspace.clouddns.v1.functions.ParseRecord.RawRecord; + +import com.google.common.base.Function; +import com.google.common.collect.FluentIterable; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.ImmutableSet.Builder; + +/** + * @author Everett Toews + */ +public class ParseDomain implements Function { + + private final ParseJson json; + + @Inject + ParseDomain(ParseJson json) { + this.json = checkNotNull(json, "json"); + } + + @Override + public Domain apply(HttpResponse response) { + RawDomain rawDomain = json.apply(response); + + if (rawDomain == null) + return null; + + return rawDomain.getDomain(); + } + + /** + * This class is here only to deal with the domain JSON format in Cloud DNS. + */ + static class RawDomain extends Domain { + @ConstructorProperties({ "id", "name", "emailAddress", "comment", "created", "updated", "accountId", "ttl", + "nameservers", "subdomains", "recordsList" }) + protected RawDomain(int id, String name, String emailAddress, String comment, Date created, Date updated, + int accountId, int ttl, Iterable> nameservers, + SubdomainsWithTotalEntries subdomainsWTE, RecordsWithTotalEntries recordsWTE) { + super(id, name, emailAddress, comment, created, updated, accountId, ttl, transform(nameservers), + transform(subdomainsWTE), transform(recordsWTE)); + } + + public Domain getDomain() { + return from(this); + } + + private static Set transform(Iterable> nameserversNasty) { + Builder nameservers = ImmutableSet.builder(); + + for (Map nameToNameserver: nameserversNasty) { + nameservers.add(nameToNameserver.get("name")); + } + + return nameservers.build(); + } + + private static Set transform(SubdomainsWithTotalEntries subdomainsWTE) { + if (subdomainsWTE == null) { + return null; + } + else { + return ImmutableSet. copyOf(subdomainsWTE.subdomains); + } + } + + private static Set transform(RecordsWithTotalEntries recordsWTE) { + if (recordsWTE == null) { + return null; + } + else { + Set recordDetails = FluentIterable.from(recordsWTE.records).transform(toRecordDetails).toSet(); + return recordDetails; + } + } + + /** + * This class is here only to deal with the domain JSON format in Cloud DNS. + */ + private static class SubdomainsWithTotalEntries { + // ignore "totalEntries" in the JSON as it can just be derived form the size of subdomains + @Named("domains") + private Iterable subdomains; + + @ConstructorProperties({ "domains" }) + protected SubdomainsWithTotalEntries(Iterable subdomains) { + this.subdomains = subdomains; + } + } + + /** + * This class is here only to deal with the domain JSON format in Cloud DNS. + */ + private static class RecordsWithTotalEntries { + // ignore "totalEntries" in the JSON as it can just be derived form the size of records + private Set records; + + @ConstructorProperties({ "records" }) + protected RecordsWithTotalEntries(Set records) { + this.records = records; + } + } + } +} diff --git a/apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/functions/ParseDomains.java b/apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/functions/ParseDomains.java new file mode 100644 index 0000000000..772c5510ac --- /dev/null +++ b/apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/functions/ParseDomains.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.rackspace.clouddns.v1.functions; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.beans.ConstructorProperties; + +import javax.inject.Inject; + +import org.jclouds.http.HttpResponse; +import org.jclouds.http.functions.ParseJson; +import org.jclouds.openstack.v2_0.domain.Link; +import org.jclouds.rackspace.clouddns.v1.domain.Domain; +import org.jclouds.rackspace.cloudidentity.v2_0.domain.PaginatedCollection; + +import com.google.common.base.Function; + +/** + * @author Everett Toews + */ +public class ParseDomains implements Function> { + + private final ParseJson json; + + @Inject + ParseDomains(ParseJson json) { + this.json = checkNotNull(json, "json"); + } + + @Override + public PaginatedCollection apply(HttpResponse response) { + Domains domains = json.apply(response); + + return domains; + } + + private static class Domains extends PaginatedCollection { + + @ConstructorProperties({ "domains", "links", "totalEntries" }) + protected Domains(Iterable domains, Iterable links, int totalEntries) { + super(domains, links, totalEntries); + } + } +} diff --git a/apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/functions/ParseJob.java b/apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/functions/ParseJob.java new file mode 100644 index 0000000000..e893760021 --- /dev/null +++ b/apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/functions/ParseJob.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.rackspace.clouddns.v1.functions; + +import static com.google.common.base.Preconditions.checkNotNull; +import static org.jclouds.rackspace.clouddns.v1.functions.ParseRecord.toRecordDetails; + +import java.lang.reflect.Type; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import javax.inject.Inject; + +import org.jclouds.domain.JsonBall; +import org.jclouds.http.HttpResponse; +import org.jclouds.http.functions.ParseJson; +import org.jclouds.json.Json; +import org.jclouds.rackspace.clouddns.v1.domain.Domain; +import org.jclouds.rackspace.clouddns.v1.domain.Job; +import org.jclouds.rackspace.clouddns.v1.domain.RecordDetail; +import org.jclouds.rackspace.clouddns.v1.functions.ParseDomain.RawDomain; +import org.jclouds.rackspace.clouddns.v1.functions.ParseRecord.RawRecord; + +import com.google.common.base.Function; +import com.google.common.base.Splitter; +import com.google.common.collect.FluentIterable; +import com.google.common.collect.Iterables; +import com.google.common.collect.Iterators; +import com.google.common.collect.Lists; +import com.google.inject.TypeLiteral; + +/** + * @author Everett Toews + */ +public class ParseJob implements Function> { + + private final ParseJson parseJson; + private final Json json; + private boolean isCreateSingleRecord; + + @Inject + ParseJob(Json json, ParseJson parseJson) { + this.json = checkNotNull(json, "json"); + this.parseJson = checkNotNull(parseJson, "parseJson"); + } + + @Override + public Job apply(HttpResponse response) { + RawJob rawJob = parseJson.apply(response); + + if (rawJob == null) + return null; + + return toJob(rawJob); + } + + public Job toJob(RawJob in) { + return Job.builder().id(in.jobId).status(in.status).error(in.error) + .resource(parseResponse(in.requestUrl, in.response)).build(); + } + + protected Object parseResponse(String requestUrl, JsonBall response) { + if (response == null) { + return null; + } + else if (requestUrl.contains("import")) { + Type type = new TypeLiteral>>() { }.getType(); + Map> domainMap = json.fromJson(response.toString(), type); + Domain domain = Iterators.getOnlyElement(domainMap.get("domains").iterator()).getDomain(); + + return domain; + } + else if (requestUrl.contains("export")) { + Type type = new TypeLiteral>() { }.getType(); + Map exportMap = json.fromJson(response.toString(), type); + String contents = exportMap.get("contents"); + List contentsAsList = Lists.newArrayList(Splitter.on("\n").omitEmptyStrings().split(contents)); + + return contentsAsList; + } + else if (response.toString().contains("domains")) { + Type type = new TypeLiteral>>() { }.getType(); + Map> domainMap = json.fromJson(response.toString(), type); + Set domains = FluentIterable.from(domainMap.get("domains")).transform(toDomain).toSet(); + + return domains; + } + else if (response.toString().contains("records")) { + Type type = new TypeLiteral>>() { }.getType(); + Map> recordMap = json.fromJson(response.toString(), type); + Set records = FluentIterable.from(recordMap.get("records")).transform(toRecordDetails).toSet(); + + if (isCreateSingleRecord) { + return Iterables.getOnlyElement(records); + } else { + return records; + } + } + else { + throw new IllegalStateException("Job parsing problem. Did not recognize any type in job response.\n" + + response.toString()); + } + } + + private static class RawJob { + private String jobId; + private Job.Status status; + private Job.Error error; + private String requestUrl; + private JsonBall response; + } + + private static final Function toDomain = new Function() { + public Domain apply(RawDomain domain) { + return domain.getDomain(); + } + }; +} diff --git a/apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/functions/ParseOnlyRecord.java b/apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/functions/ParseOnlyRecord.java new file mode 100644 index 0000000000..626b88278b --- /dev/null +++ b/apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/functions/ParseOnlyRecord.java @@ -0,0 +1,60 @@ +/** + * 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.rackspace.clouddns.v1.functions; + +import static com.google.common.base.Preconditions.checkNotNull; +import static org.jclouds.rackspace.clouddns.v1.functions.ParseRecord.toRecordDetails; + +import java.util.List; +import java.util.Map; + +import javax.inject.Inject; + +import org.jclouds.http.HttpResponse; +import org.jclouds.http.functions.ParseJson; +import org.jclouds.rackspace.clouddns.v1.domain.RecordDetail; +import org.jclouds.rackspace.clouddns.v1.functions.ParseRecord.RawRecord; + +import com.google.common.base.Function; +import com.google.common.collect.Iterables; + +/** + * @author Everett Toews + */ +public class ParseOnlyRecord implements Function { + + private final ParseJson>> json; + + @Inject + ParseOnlyRecord(ParseJson>> json) { + this.json = checkNotNull(json, "json"); + } + + @Override + public RecordDetail apply(HttpResponse response) { + Map> records = json.apply(response); + + if (records == null) + return null; + + RawRecord rawRecord = Iterables.getOnlyElement(records.get("records")); + + return toRecordDetails.apply(rawRecord); + } +} diff --git a/apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/functions/ParseRecord.java b/apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/functions/ParseRecord.java new file mode 100644 index 0000000000..18d43a8a99 --- /dev/null +++ b/apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/functions/ParseRecord.java @@ -0,0 +1,95 @@ +/** + * 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.rackspace.clouddns.v1.functions; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.beans.ConstructorProperties; +import java.util.Date; + +import javax.inject.Inject; + +import org.jclouds.http.HttpResponse; +import org.jclouds.http.functions.ParseJson; +import org.jclouds.rackspace.clouddns.v1.domain.Record; +import org.jclouds.rackspace.clouddns.v1.domain.RecordDetail; + +import com.google.common.base.Function; + +/** + * @author Everett Toews + */ +public class ParseRecord implements Function { + + private final ParseJson json; + + @Inject + ParseRecord(ParseJson json) { + this.json = checkNotNull(json, "json"); + } + + @Override + public RecordDetail apply(HttpResponse response) { + RawRecord rawRecord = json.apply(response); + + if (rawRecord == null) + return null; + + return toRecordDetails.apply(rawRecord); + } + + static class RawRecord { + public String id; + public String name; + public String type; + public int ttl; + public String data; + public Integer priority; + public String comment; + public Date created; + public Date updated; + + @ConstructorProperties({ "id", "name", "type", "ttl", "data", "priority", "comment", "created", "updated" }) + protected RawRecord(String id, String name, String type, int ttl, String data, Integer priority, String comment, + Date created, Date updated) { + super(); + this.id = id; + this.name = name; + this.type = type; + this.ttl = ttl; + this.data = data; + this.priority = priority; + this.comment = comment; + this.created = created; + this.updated = updated; + } + } + + static final Function toRecordDetails = new Function() { + @Override + public RecordDetail apply(RawRecord rawRecord) { + Record record = Record.builder().name(rawRecord.name).type(rawRecord.type).ttl(rawRecord.ttl) + .data(rawRecord.data).priority(rawRecord.priority).comment(rawRecord.comment).build(); + RecordDetail recordDetails = RecordDetail.builder().id(rawRecord.id).created(rawRecord.created) + .updated(rawRecord.updated).record(record).build(); + + return recordDetails; + } + }; +} diff --git a/apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/functions/ParseRecords.java b/apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/functions/ParseRecords.java new file mode 100644 index 0000000000..2c889ec660 --- /dev/null +++ b/apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/functions/ParseRecords.java @@ -0,0 +1,71 @@ +/** + * 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.rackspace.clouddns.v1.functions; + +import static com.google.common.base.Preconditions.checkNotNull; +import static org.jclouds.rackspace.clouddns.v1.functions.ParseRecord.toRecordDetails; + +import java.beans.ConstructorProperties; + +import javax.inject.Inject; + +import org.jclouds.http.HttpResponse; +import org.jclouds.http.functions.ParseJson; +import org.jclouds.openstack.v2_0.domain.Link; +import org.jclouds.rackspace.clouddns.v1.domain.RecordDetail; +import org.jclouds.rackspace.clouddns.v1.functions.ParseRecord.RawRecord; +import org.jclouds.rackspace.cloudidentity.v2_0.domain.PaginatedCollection; + +import com.google.common.base.Function; + +/** + * @author Everett Toews + */ +public class ParseRecords implements Function> { + + private final ParseJson json; + + @Inject + ParseRecords(ParseJson json) { + this.json = checkNotNull(json, "json"); + } + + @Override + public PaginatedCollection apply(HttpResponse response) { + RawRecords rawRecords = json.apply(response); + Iterable records = rawRecords.transform(toRecordDetails); + + return new Records(records, rawRecords.getLinks(), rawRecords.getTotalEntries()); + } + + private static class RawRecords extends PaginatedCollection { + + @ConstructorProperties({ "records", "links", "totalEntries" }) + protected RawRecords(Iterable records, Iterable links, int totalEntries) { + super(records, links, totalEntries); + } + } + + private static class Records extends PaginatedCollection { + + protected Records(Iterable records, Iterable links, int totalEntries) { + super(records, links, totalEntries); + } + } +} diff --git a/apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/functions/ParseSubdomains.java b/apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/functions/ParseSubdomains.java new file mode 100644 index 0000000000..b0438eba4c --- /dev/null +++ b/apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/functions/ParseSubdomains.java @@ -0,0 +1,68 @@ +/** + * 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.rackspace.clouddns.v1.functions; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.beans.ConstructorProperties; + +import javax.inject.Inject; + +import org.jclouds.http.HttpRequest; +import org.jclouds.http.HttpResponse; +import org.jclouds.http.functions.ParseJson; +import org.jclouds.openstack.v2_0.domain.Link; +import org.jclouds.rackspace.clouddns.v1.domain.Subdomain; +import org.jclouds.rackspace.cloudidentity.v2_0.domain.PaginatedCollection; +import org.jclouds.rest.InvocationContext; + +import com.google.common.base.Function; + +/** + * @author Everett Toews + */ +public class ParseSubdomains implements Function>, InvocationContext { + + private final ParseJson json; + + @Inject + ParseSubdomains(ParseJson json) { + this.json = checkNotNull(json, "json"); + } + + @Override + public PaginatedCollection apply(HttpResponse response) { + Subdomains subdomains = json.apply(response); + + return subdomains; + } + + @Override + public ParseSubdomains setContext(HttpRequest request) { + return this; + } + + static class Subdomains extends PaginatedCollection { + + @ConstructorProperties({ "domains", "links", "totalEntries" }) + protected Subdomains(Iterable domains, Iterable links, int totalEntries) { + super(domains, links, totalEntries); + } + } +} diff --git a/apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/functions/RecordFunctions.java b/apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/functions/RecordFunctions.java new file mode 100644 index 0000000000..cbf345fffb --- /dev/null +++ b/apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/functions/RecordFunctions.java @@ -0,0 +1,64 @@ +/** + * 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.rackspace.clouddns.v1.functions; + +import java.util.Map; +import java.util.Set; + +import org.jclouds.rackspace.clouddns.v1.domain.Record; +import org.jclouds.rackspace.clouddns.v1.domain.RecordDetail; + +import com.google.common.base.Function; +import com.google.common.collect.Maps; + +/** + * Functions for working with Records. + * + * @author Everett Toews + */ +public class RecordFunctions { + + private RecordFunctions() { + } + + /** + * Take a Set of RecordDetails and return a Map of record id to the Record. + */ + public static Map toRecordMap(Set recordDetails) { + Map idsToRecordDetails = Maps.uniqueIndex(recordDetails, RecordFunctions.GET_RECORD_ID); + return Maps.transformValues(idsToRecordDetails, RecordFunctions.GET_RECORD); + } + + /** + * Take a RecordDetail and return its id. + */ + public static final Function GET_RECORD_ID = new Function() { + public String apply(RecordDetail recordDetail) { + return recordDetail.getId(); + } + }; + /** + * Take a RecordDetail and return its Record. + */ + public static final Function GET_RECORD = new Function() { + public Record apply(RecordDetail recordDetail) { + return recordDetail.getRecord(); + } + }; +} diff --git a/apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/functions/RecordsToPagedIterable.java b/apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/functions/RecordsToPagedIterable.java new file mode 100644 index 0000000000..4127b80a92 --- /dev/null +++ b/apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/functions/RecordsToPagedIterable.java @@ -0,0 +1,74 @@ +/** + * 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.rackspace.clouddns.v1.functions; + +import static com.google.common.base.Preconditions.checkNotNull; + +import javax.inject.Inject; + +import org.jclouds.collect.IterableWithMarker; +import org.jclouds.collect.internal.Arg0ToPagedIterable; +import org.jclouds.rackspace.clouddns.v1.CloudDNSApi; +import org.jclouds.rackspace.clouddns.v1.domain.RecordDetail; +import org.jclouds.rackspace.clouddns.v1.features.RecordApi; +import org.jclouds.rackspace.cloudidentity.v2_0.domain.PaginatedCollection; +import org.jclouds.rackspace.cloudidentity.v2_0.options.PaginationOptions; + +import com.google.common.annotations.Beta; +import com.google.common.base.Function; +import com.google.common.base.Optional; + +/** + * @author Everett Toews + */ +@Beta +public class RecordsToPagedIterable extends Arg0ToPagedIterable { + + private final CloudDNSApi api; + + @Inject + protected RecordsToPagedIterable(CloudDNSApi api) { + this.api = checkNotNull(api, "api"); + } + + @Override + protected Function> markerToNextForArg0(Optional arg0) { + int domainId = Integer.class.cast(arg0.get()); + return new ListRecordsAtMarker(api.getRecordApiForDomain(domainId)); + } + + private static class ListRecordsAtMarker implements Function> { + private final RecordApi api; + + @Inject + protected ListRecordsAtMarker(RecordApi api) { + this.api = checkNotNull(api, "api"); + } + + public PaginatedCollection apply(Object input) { + PaginationOptions paginationOptions = (PaginationOptions) input; + + return api.list(paginationOptions); + } + + public String toString() { + return "ListRecordsAtMarker"; + } + } +} diff --git a/apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/functions/SubdomainsToPagedIterable.java b/apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/functions/SubdomainsToPagedIterable.java new file mode 100644 index 0000000000..49fa5e402c --- /dev/null +++ b/apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/functions/SubdomainsToPagedIterable.java @@ -0,0 +1,75 @@ +/** + * 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.rackspace.clouddns.v1.functions; + +import static com.google.common.base.Preconditions.checkNotNull; + +import javax.inject.Inject; + +import org.jclouds.collect.IterableWithMarker; +import org.jclouds.collect.internal.Arg0ToPagedIterable; +import org.jclouds.rackspace.clouddns.v1.CloudDNSApi; +import org.jclouds.rackspace.clouddns.v1.domain.Subdomain; +import org.jclouds.rackspace.clouddns.v1.features.DomainApi; +import org.jclouds.rackspace.cloudidentity.v2_0.domain.PaginatedCollection; +import org.jclouds.rackspace.cloudidentity.v2_0.options.PaginationOptions; + +import com.google.common.annotations.Beta; +import com.google.common.base.Function; +import com.google.common.base.Optional; + +/** + * @author Everett Toews + */ +@Beta +public class SubdomainsToPagedIterable extends Arg0ToPagedIterable { + + private final DomainApi api; + + @Inject + protected SubdomainsToPagedIterable(CloudDNSApi api) { + this.api = checkNotNull(api, "api").getDomainApi(); + } + + @Override + protected Function> markerToNextForArg0(Optional domainId) { + return new ListSubdomainsUnderDomainIdAtMarker(api, Integer.valueOf(domainId.get().toString())); + } + + private static class ListSubdomainsUnderDomainIdAtMarker implements Function> { + private final DomainApi api; + private final int domainId; + + @Inject + protected ListSubdomainsUnderDomainIdAtMarker(DomainApi api, int domainId) { + this.api = checkNotNull(api, "api"); + this.domainId = domainId; + } + + public PaginatedCollection apply(Object input) { + PaginationOptions paginationOptions = (PaginationOptions) input; + + return api.listSubdomains(domainId, paginationOptions); + } + + public String toString() { + return "ListSubdomainsUnderDomainIdAtMarker(" + domainId + ")"; + } + } +} diff --git a/apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/predicates/JobPredicates.java b/apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/predicates/JobPredicates.java new file mode 100644 index 0000000000..01da4d0c62 --- /dev/null +++ b/apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/predicates/JobPredicates.java @@ -0,0 +1,109 @@ +/** + * 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.rackspace.clouddns.v1.predicates; + +import static com.google.common.base.Preconditions.checkNotNull; +import static java.util.concurrent.TimeUnit.SECONDS; +import static org.jclouds.util.Predicates2.retry; + +import java.util.concurrent.TimeoutException; +import java.util.concurrent.atomic.AtomicReference; + +import org.jclouds.rackspace.clouddns.v1.CloudDNSApi; +import org.jclouds.rackspace.clouddns.v1.CloudDNSExceptions; +import org.jclouds.rackspace.clouddns.v1.domain.Job; + +import com.google.common.base.Predicate; +import com.google.common.util.concurrent.Atomics; + +/** + * Useful Predicates for dealing with Jobs. + * + * @author Everett Toews + */ +public class JobPredicates { + + private JobPredicates() { + } + + /** + * Tests to see if a Job has completed. + * + *
+    * {@code
+    * CreateDomain createDomain1 = CreateDomain.builder()
+    *    .name("jclouds-example.org")
+    *    .email("jclouds@jclouds-example.org")
+    *    .ttl(600001)
+    *    .comment("Hello Domain 1")
+    *    .build();
+    *
+    * Iterable createDomains = ImmutableList.of(createDomain1);      
+    * Set domains = awaitComplete(api, api.getDomainApi().create(createDomains));
+    * }
+    * 
+ */ + public static T awaitComplete(CloudDNSApi api, Job job) + throws TimeoutException { + AtomicReference> jobRef = Atomics.newReference(job); + + if (!retry(jobCompleted(api), 600, 2, 2, SECONDS).apply(jobRef)) { + throw new TimeoutException("Timeout on: " + jobRef.get()); + } + + return jobRef.get().getResource().orNull(); + } + + @SuppressWarnings({ "rawtypes", "unchecked" }) + private static Predicate>> jobCompleted(CloudDNSApi cloudDNSApi) { + return new JobStatusPredicate(cloudDNSApi, Job.Status.COMPLETED); + } + + private static class JobStatusPredicate implements Predicate>> { + private CloudDNSApi cloudDNSApi; + private Job.Status status; + + private JobStatusPredicate(CloudDNSApi cloudDNSApi, Job.Status status) { + this.cloudDNSApi = checkNotNull(cloudDNSApi, "domainApi must be defined"); + this.status = checkNotNull(status, "status must be defined"); + } + + /** + * @return boolean Return true when the Job reaches status, false otherwise. + */ + @Override + public boolean apply(AtomicReference> jobRef) { + checkNotNull(jobRef, "job must be defined"); + + if (status.equals(jobRef.get().getStatus())) { + return true; + } + else { + jobRef.set(cloudDNSApi.getJob(jobRef.get().getId())); + checkNotNull(jobRef.get(), "Job %s not found.", jobRef.get().getId()); + + if (jobRef.get().getError().isPresent()) { + throw new CloudDNSExceptions.JobErrorException(jobRef.get().getError().get()); + } + + return status.equals(jobRef.get().getStatus()); + } + } + } +} diff --git a/apis/rackspace-clouddns/src/main/resources/META-INF/services/org.jclouds.apis.ApiMetadata b/apis/rackspace-clouddns/src/main/resources/META-INF/services/org.jclouds.apis.ApiMetadata new file mode 100644 index 0000000000..eae6b81b84 --- /dev/null +++ b/apis/rackspace-clouddns/src/main/resources/META-INF/services/org.jclouds.apis.ApiMetadata @@ -0,0 +1 @@ +org.jclouds.rackspace.clouddns.v1.CloudDNSApiMetadata \ No newline at end of file diff --git a/apis/rackspace-clouddns/src/test/java/org/jclouds/rackspace/clouddns/v1/features/CloudDNSApiExpectTest.java b/apis/rackspace-clouddns/src/test/java/org/jclouds/rackspace/clouddns/v1/features/CloudDNSApiExpectTest.java new file mode 100644 index 0000000000..2f0a0db1e0 --- /dev/null +++ b/apis/rackspace-clouddns/src/test/java/org/jclouds/rackspace/clouddns/v1/features/CloudDNSApiExpectTest.java @@ -0,0 +1,50 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.rackspace.clouddns.v1.features; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertFalse; + +import java.net.URI; + +import org.jclouds.http.HttpResponse; +import org.jclouds.rackspace.clouddns.v1.CloudDNSApi; +import org.jclouds.rackspace.clouddns.v1.domain.Domain; +import org.jclouds.rackspace.clouddns.v1.domain.Job; +import org.jclouds.rackspace.clouddns.v1.internal.BaseCloudDNSApiExpectTest; +import org.testng.annotations.Test; + +/** + * @author Everett Toews + */ +@Test(groups = "unit") +public class CloudDNSApiExpectTest extends BaseCloudDNSApiExpectTest { + public void testGetJobDomainExport() { + URI endpoint = URI.create("https://dns.api.rackspacecloud.com/v1.0/123123/status/bfbd6ec8-5d4c-49f8-97b5-aa5bfd3e95a4?showDetails=true"); + CloudDNSApi api = requestsSendResponses( + rackspaceAuthWithUsernameAndApiKey, + responseWithAccess, + authenticatedGET().endpoint(endpoint).build(), + HttpResponse.builder().statusCode(200).payload(payloadFromResource("/job.json")).build()); + + Job job = api.getJob("bfbd6ec8-5d4c-49f8-97b5-aa5bfd3e95a4"); + assertEquals(job.getStatus(), Job.Status.RUNNING); + assertFalse(job.getResource().isPresent()); + } +} diff --git a/apis/rackspace-clouddns/src/test/java/org/jclouds/rackspace/clouddns/v1/features/DomainApiExpectTest.java b/apis/rackspace-clouddns/src/test/java/org/jclouds/rackspace/clouddns/v1/features/DomainApiExpectTest.java new file mode 100644 index 0000000000..50111f3991 --- /dev/null +++ b/apis/rackspace-clouddns/src/test/java/org/jclouds/rackspace/clouddns/v1/features/DomainApiExpectTest.java @@ -0,0 +1,311 @@ +/** + * 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.rackspace.clouddns.v1.features; + +import static javax.ws.rs.HttpMethod.POST; +import static javax.ws.rs.HttpMethod.PUT; +import static javax.ws.rs.core.Response.Status.OK; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertTrue; + +import java.net.URI; +import java.util.Calendar; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.SimpleTimeZone; + +import javax.ws.rs.core.MediaType; + +import org.jclouds.http.HttpResponse; +import org.jclouds.rackspace.clouddns.v1.CloudDNSApi; +import org.jclouds.rackspace.clouddns.v1.domain.CreateDomain; +import org.jclouds.rackspace.clouddns.v1.domain.CreateSubdomain; +import org.jclouds.rackspace.clouddns.v1.domain.Domain; +import org.jclouds.rackspace.clouddns.v1.domain.DomainChange; +import org.jclouds.rackspace.clouddns.v1.domain.Job; +import org.jclouds.rackspace.clouddns.v1.domain.Record; +import org.jclouds.rackspace.clouddns.v1.domain.UpdateDomain; +import org.jclouds.rackspace.clouddns.v1.functions.DomainFunctions; +import org.jclouds.rackspace.clouddns.v1.internal.BaseCloudDNSApiExpectTest; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableList; + +/** + * @author Everett Toews + */ +@Test(groups = "unit") +public class DomainApiExpectTest extends BaseCloudDNSApiExpectTest { + private static final String JCLOUDS_EXAMPLE = "jclouds-example.com"; + + public void testCreateDomain() { + URI endpoint = URI.create("https://dns.api.rackspacecloud.com/v1.0/123123/domains"); + DomainApi api = requestsSendResponses( + rackspaceAuthWithUsernameAndApiKey, + responseWithAccess, + authenticatedGET() + .method(POST) + .payload(payloadFromResource("/domain-create.json")) + .endpoint(endpoint) + .build(), + HttpResponse.builder().statusCode(OK.getStatusCode()).payload(payloadFromResource("/domain-create-response.json")).build()) + .getDomainApi(); + + Record createMXRecord = Record.builder() + .type("MX") + .name(JCLOUDS_EXAMPLE) + .data("mail." + JCLOUDS_EXAMPLE) + .priority(11235) + .build(); + + Record createARecord = Record.builder() + .type("A") + .name(JCLOUDS_EXAMPLE) + .data("10.0.0.1") + .build(); + + List createRecords = ImmutableList.of(createMXRecord, createARecord); + + CreateSubdomain createSubdomain1 = CreateSubdomain.builder() + .name("dev." + JCLOUDS_EXAMPLE) + .email("jclouds@" + JCLOUDS_EXAMPLE) + .comment("Hello dev subdomain") + .build(); + + CreateSubdomain createSubdomain2 = CreateSubdomain.builder() + .name("test." + JCLOUDS_EXAMPLE) + .email("jclouds@" + JCLOUDS_EXAMPLE) + .comment("Hello test subdomain") + .build(); + + List createSubdomains = ImmutableList.of(createSubdomain1, createSubdomain2); + + CreateDomain createDomain1 = CreateDomain.builder() + .name(JCLOUDS_EXAMPLE) + .email("jclouds@" + JCLOUDS_EXAMPLE) + .ttl(600000) + .comment("Hello Domain") + .subdomains(createSubdomains) + .records(createRecords) + .build(); + + CreateDomain createDomain2 = CreateDomain.builder() + .name("x" + JCLOUDS_EXAMPLE) + .email("jclouds@" + JCLOUDS_EXAMPLE) + .ttl(600000) + .comment("Hello Domain") + .build(); + + Iterable createDomains = ImmutableList.of(createDomain1, createDomain2); + Job> job = api.create(createDomains); + + assertEquals(job.getStatus(), Job.Status.COMPLETED); + assertTrue(job.getResource().isPresent()); + + Map domains = DomainFunctions.toDomainMap(job.getResource().get()); + + assertEquals(domains.get(JCLOUDS_EXAMPLE).getId(), 3650906); + assertEquals(domains.get(JCLOUDS_EXAMPLE).getEmail(), "jclouds@jclouds-example.com"); + assertEquals(domains.get(JCLOUDS_EXAMPLE).getSubdomains().size(), 2); + assertEquals(domains.get(JCLOUDS_EXAMPLE).getRecords().size(), 2); + assertEquals(domains.get("x" + JCLOUDS_EXAMPLE).getId(), 3650909); + } + + public void testListDomains() { + URI endpoint = URI.create("https://dns.api.rackspacecloud.com/v1.0/123123/domains"); + DomainApi api = requestsSendResponses( + rackspaceAuthWithUsernameAndApiKey, + responseWithAccess, + authenticatedGET().endpoint(endpoint).build(), + HttpResponse.builder().statusCode(OK.getStatusCode()).payload(payloadFromResource("/domain-list.json")).build()) + .getDomainApi(); + + ImmutableList domains = api.list().concat().toList(); + assertEquals(domains.size(), 4); + + for (Domain domain: domains) { + assertTrue(domain.getName().contains(JCLOUDS_EXAMPLE)); + } + } + + public void testListWithFilterByNamesMatching() { + URI endpoint = URI.create("https://dns.api.rackspacecloud.com/v1.0/123123/domains?name=test.jclouds-example.com"); + DomainApi api = requestsSendResponses( + rackspaceAuthWithUsernameAndApiKey, + responseWithAccess, + authenticatedGET().endpoint(endpoint).build(), + HttpResponse.builder().statusCode(OK.getStatusCode()).payload(payloadFromResource("/domain-list-with-filter.json")).build()) + .getDomainApi(); + + ImmutableList domains = api.listWithFilterByNamesMatching("test." + JCLOUDS_EXAMPLE).concat().toList(); + assertEquals(domains.size(), 1); + assertEquals(domains.get(0).getId(), 3650908); + assertEquals(domains.get(0).getName(), "test." + JCLOUDS_EXAMPLE); + } + + public void testListDomainChanges() { + URI endpoint = URI.create("https://dns.api.rackspacecloud.com/v1.0/123123/domains/3650908/changes?changes=2013-03-22T03%3A39%3A31Z"); + DomainApi api = requestsSendResponses( + rackspaceAuthWithUsernameAndApiKey, + responseWithAccess, + authenticatedGET().endpoint(endpoint).build(), + HttpResponse.builder().statusCode(OK.getStatusCode()).payload(payloadFromResource("/domain-list-changes.json")).build()) + .getDomainApi(); + + Calendar cal = Calendar.getInstance(new SimpleTimeZone(0, "GMT")); + cal.set(2013, 2, 22, 3, 39, 31); + DomainChange domainChange = api.listChanges(3650908, cal.getTime()); + + assertEquals(domainChange.getChanges().size(), 25); + } + + public void testGetDomain() { + URI endpoint = URI.create("https://dns.api.rackspacecloud.com/v1.0/123123/domains/3650908?showRecords=true&showSubdomains=true"); + DomainApi api = requestsSendResponses( + rackspaceAuthWithUsernameAndApiKey, + responseWithAccess, + authenticatedGET().endpoint(endpoint).build(), + HttpResponse.builder().statusCode(OK.getStatusCode()).payload(payloadFromResource("/domain-get.json")).build()) + .getDomainApi(); + + Domain domain = api.get(3650908); + assertEquals(domain.getName(), "test." + JCLOUDS_EXAMPLE); + assertEquals(domain.getRecords().size(), 2); + assertEquals(domain.getComment().get(), "Hello test subdomain"); + assertEquals(domain.getTTL(), 3600); + } + + @SuppressWarnings("rawtypes") + public void testUpdateDomain() { + URI endpoint = URI.create("https://dns.api.rackspacecloud.com/v1.0/123123/domains/3650908"); + DomainApi api = requestsSendResponses( + rackspaceAuthWithUsernameAndApiKey, + responseWithAccess, + authenticatedGET() + .method(PUT) + .payload(payloadFromResourceWithContentType("/domain-update.json", MediaType.APPLICATION_JSON)) + .endpoint(endpoint) + .build(), + HttpResponse.builder().statusCode(OK.getStatusCode()).payload(payloadFromResource("/domain-update-response.json")).build()) + .getDomainApi(); + + UpdateDomain updateDomain = UpdateDomain.builder() + .email("everett@" + JCLOUDS_EXAMPLE) + .ttl(600001) + .comment("Hello Domain Update") + .build(); + + Job job = api.update(3650908, updateDomain); + + assertEquals(job.getStatus(), Job.Status.COMPLETED); + } + + @SuppressWarnings("rawtypes") + public void testUpdateDomainsTTL() { + URI endpoint = URI.create("https://dns.api.rackspacecloud.com/v1.0/123123/domains"); + DomainApi api = requestsSendResponses( + rackspaceAuthWithUsernameAndApiKey, + responseWithAccess, + authenticatedGET() + .method(PUT) + .payload(payloadFromResource("/domain-update-ttl.json")) + .endpoint(endpoint) + .build(), + HttpResponse.builder().statusCode(OK.getStatusCode()).payload(payloadFromResource("/domain-update-response.json")).build()) + .getDomainApi(); + + List ids = ImmutableList.of(3650906, 3650908); + Job job = api.updateTTL(ids, 1234567); + + assertEquals(job.getStatus(), Job.Status.COMPLETED); + } + + @SuppressWarnings("rawtypes") + public void testUpdateDomainsEmail() { + URI endpoint = URI.create("https://dns.api.rackspacecloud.com/v1.0/123123/domains"); + DomainApi api = requestsSendResponses( + rackspaceAuthWithUsernameAndApiKey, + responseWithAccess, + authenticatedGET() + .method(PUT) + .payload(payloadFromResource("/domain-update-email.json")) + .endpoint(endpoint) + .build(), + HttpResponse.builder().statusCode(OK.getStatusCode()).payload(payloadFromResource("/domain-update-response.json")).build()) + .getDomainApi(); + + List ids = ImmutableList.of(3650906, 3650908); + Job job = api.updateEmail(ids, "everett@" + JCLOUDS_EXAMPLE); + + assertEquals(job.getStatus(), Job.Status.COMPLETED); + } + + @SuppressWarnings("rawtypes") + public void testDeleteDomains() { + URI endpoint = URI.create("https://dns.api.rackspacecloud.com/v1.0/123123/domains?id=3650907&id=3650906&id=3650908&id=3650909&deleteSubdomains=true"); + DomainApi api = requestsSendResponses( + rackspaceAuthWithUsernameAndApiKey, + responseWithAccess, + authenticatedGET().method("DELETE").replaceHeader("Accept", MediaType.WILDCARD).endpoint(endpoint).build(), + HttpResponse.builder().statusCode(OK.getStatusCode()).payload(payloadFromResource("/domain-delete.json")).build()) + .getDomainApi(); + + List domainIds = ImmutableList. of(3650907, 3650906, 3650908, 3650909); + Job job = api.delete(domainIds, true); + + assertEquals(job.getStatus(), Job.Status.COMPLETED); + } + + public void testExportDomain() { + URI endpoint = URI.create("https://dns.api.rackspacecloud.com/v1.0/123123/domains/3651323/export"); + DomainApi api = requestsSendResponses( + rackspaceAuthWithUsernameAndApiKey, + responseWithAccess, + authenticatedGET().endpoint(endpoint).build(), + HttpResponse.builder().statusCode(OK.getStatusCode()).payload(payloadFromResource("/domain-export.json")).build()) + .getDomainApi(); + + Job> job = api.exportFormat(3651323, Domain.Format.BIND_9); + assertEquals(job.getStatus(), Job.Status.COMPLETED); + assertEquals(job.getResource().get().size(), 5); + } + + public void testImportDomain() { + URI endpoint = URI.create("https://dns.api.rackspacecloud.com/v1.0/123123/domains/import"); + DomainApi api = requestsSendResponses( + rackspaceAuthWithUsernameAndApiKey, + responseWithAccess, + authenticatedGET() + .method(POST) + .payload(payloadFromResource("/domain-import.json")) + .endpoint(endpoint) + .build(), + HttpResponse.builder().statusCode(OK.getStatusCode()).payload(payloadFromResource("/domain-import-response.json")).build()) + .getDomainApi(); + + List contents = ImmutableList. of( + "jclouds-example.com. 3600 IN SOA ns.rackspace.com. jclouds.jclouds-example.com. 1363882703 3600 3600 3600 3600", + "jclouds-example.com. 600 IN A 50.56.174.152"); + + Job job = api.importFormat(contents, Domain.Format.BIND_9); + assertEquals(job.getStatus(), Job.Status.COMPLETED); + assertEquals(job.getResource().get().getName(), JCLOUDS_EXAMPLE); + } +} diff --git a/apis/rackspace-clouddns/src/test/java/org/jclouds/rackspace/clouddns/v1/features/DomainApiLiveTest.java b/apis/rackspace-clouddns/src/test/java/org/jclouds/rackspace/clouddns/v1/features/DomainApiLiveTest.java new file mode 100644 index 0000000000..f7807d5fb7 --- /dev/null +++ b/apis/rackspace-clouddns/src/test/java/org/jclouds/rackspace/clouddns/v1/features/DomainApiLiveTest.java @@ -0,0 +1,407 @@ +/** + * 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.rackspace.clouddns.v1.features; + +import static org.jclouds.rackspace.clouddns.v1.predicates.JobPredicates.awaitComplete; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertNull; +import static org.testng.Assert.assertTrue; + +import java.util.Date; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.TimeoutException; + +import org.jclouds.rackspace.clouddns.v1.domain.CreateDomain; +import org.jclouds.rackspace.clouddns.v1.domain.CreateSubdomain; +import org.jclouds.rackspace.clouddns.v1.domain.Domain; +import org.jclouds.rackspace.clouddns.v1.domain.Record; +import org.jclouds.rackspace.clouddns.v1.domain.RecordDetail; +import org.jclouds.rackspace.clouddns.v1.domain.Subdomain; +import org.jclouds.rackspace.clouddns.v1.domain.UpdateDomain; +import org.jclouds.rackspace.clouddns.v1.functions.DomainFunctions; +import org.jclouds.rackspace.clouddns.v1.internal.BaseCloudDNSApiLiveTest; +import org.testng.annotations.AfterClass; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableList; +import com.google.common.collect.Lists; +import com.google.common.collect.Maps; + +/** + * @author Everett Toews + */ +@Test(groups = "live", singleThreaded = true, testName = "DomainApiLiveTest") +public class DomainApiLiveTest extends BaseCloudDNSApiLiveTest { + + // just in case the username has a '.' we replace it to avoid creating subdomains + private static final String JCLOUDS_EXAMPLE = System.getProperty("user.name").replace('.', '-') + "-domaintest-jclouds.org"; + + private Map testDomains; + + @Test + public void testCreateDomainsWithSubdomainsAndRecords() throws Exception { + Record createMXRecord = Record.builder() + .type("MX") + .name(JCLOUDS_EXAMPLE) + .data("mail." + JCLOUDS_EXAMPLE) + .priority(11235) + .comment("MX Record") + .ttl(60000) + .build(); + + Record createARecord = Record.builder() + .type("A") + .name(JCLOUDS_EXAMPLE) + .data("10.0.0.1") + .comment("A Record") + .ttl(60000) + .build(); + + List createRecords = ImmutableList.of(createMXRecord, createARecord); + + CreateSubdomain createSubdomain1 = CreateSubdomain.builder() + .name("dev." + JCLOUDS_EXAMPLE) + .email("jclouds@" + JCLOUDS_EXAMPLE) + .comment("Hello dev subdomain") + .build(); + + CreateSubdomain createSubdomain2 = CreateSubdomain.builder() + .name("test." + JCLOUDS_EXAMPLE) + .email("jclouds@" + JCLOUDS_EXAMPLE) + .comment("Hello test subdomain") + .build(); + + List createSubdomains = ImmutableList.of(createSubdomain1, createSubdomain2); + + CreateDomain createDomain1 = CreateDomain.builder() + .name(JCLOUDS_EXAMPLE) + .email("jclouds1@" + JCLOUDS_EXAMPLE) + .ttl(600001) + .comment("Hello Domain 1") + .subdomains(createSubdomains) + .records(createRecords) + .build(); + + CreateDomain createDomain2 = CreateDomain.builder() + .name("alt-" + JCLOUDS_EXAMPLE) + .email("jclouds2@" + JCLOUDS_EXAMPLE) + .ttl(600002) + .comment("Hello Domain 2") + .build(); + + Iterable createDomains = ImmutableList.of(createDomain1, createDomain2); + testDomains = DomainFunctions.toDomainMap(awaitComplete(api, api.getDomainApi().create(createDomains))); + + assertEquals(testDomains.size(), 2); + + Domain jclouds = testDomains.get(JCLOUDS_EXAMPLE); + Domain altjclouds = testDomains.get("alt-" + JCLOUDS_EXAMPLE); + + Thread.sleep(1000); + Date now = new Date(); + + assertTrue(jclouds.getId() > 0); + assertTrue(jclouds.getAccountId() > 0); + assertEquals(jclouds.getName(), JCLOUDS_EXAMPLE); + assertEquals(jclouds.getEmail(), "jclouds1@" + JCLOUDS_EXAMPLE); + assertEquals(jclouds.getComment().get(), "Hello Domain 1"); + assertEquals(jclouds.getTTL(), 600001); + assertTrue(jclouds.getCreated().before(now)); + assertTrue(jclouds.getUpdated().before(now)); + + assertEquals(jclouds.getSubdomains().size(), 2); + + Subdomain devjclouds = null; + Subdomain testjclouds = null; + + for (Subdomain subdomain: jclouds.getSubdomains()) { + if (subdomain.getName().equals("dev." + JCLOUDS_EXAMPLE)) { + devjclouds = subdomain; + } else if (subdomain.getName().equals("test." + JCLOUDS_EXAMPLE)) { + testjclouds = subdomain; + } + } + + assertTrue(devjclouds.getId() > 0); + assertEquals(devjclouds.getName(), "dev." + JCLOUDS_EXAMPLE); + assertEquals(devjclouds.getEmail(), "jclouds@" + JCLOUDS_EXAMPLE); + assertEquals(devjclouds.getComment().get(), "Hello dev subdomain"); + assertTrue(devjclouds.getCreated().before(now)); + assertTrue(devjclouds.getUpdated().before(now)); + + assertTrue(testjclouds.getId() > 0); + assertEquals(testjclouds.getName(), "test." + JCLOUDS_EXAMPLE); + assertEquals(testjclouds.getEmail(), "jclouds@" + JCLOUDS_EXAMPLE); + assertEquals(testjclouds.getComment().get(), "Hello test subdomain"); + assertTrue(testjclouds.getCreated().before(now)); + assertTrue(testjclouds.getUpdated().before(now)); + + assertEquals(jclouds.getRecords().size(), 2); + + RecordDetail mxRecord = null; + RecordDetail aRecord = null; + + for (RecordDetail record: jclouds.getRecords()) { + if (record.getType().equals("MX")) { + mxRecord = record; + } else if (record.getType().equals("A")) { + aRecord = record; + } + } + + assertNotNull(mxRecord.getId()); + assertEquals(mxRecord.getType(), "MX"); + assertEquals(mxRecord.getName(), JCLOUDS_EXAMPLE); + assertEquals(mxRecord.getPriority().intValue(), 11235); + assertEquals(mxRecord.getComment(), "MX Record"); + assertEquals(mxRecord.getTTL(), 60000); + assertTrue(mxRecord.getCreated().before(now)); + assertTrue(mxRecord.getUpdated().before(now)); + + assertNotNull(aRecord.getId()); + assertEquals(aRecord.getType(), "A"); + assertEquals(aRecord.getName(), JCLOUDS_EXAMPLE); + assertNull(aRecord.getPriority()); + assertEquals(aRecord.getComment(), "A Record"); + assertEquals(aRecord.getTTL(), 60000); + assertTrue(aRecord.getCreated().before(now)); + assertTrue(aRecord.getUpdated().before(now)); + + assertTrue(altjclouds.getId() > 0); + assertTrue(altjclouds.getAccountId() > 0); + assertEquals(altjclouds.getName(), "alt-" + JCLOUDS_EXAMPLE); + assertEquals(altjclouds.getEmail(), "jclouds2@" + JCLOUDS_EXAMPLE); + assertEquals(altjclouds.getComment().get(), "Hello Domain 2"); + assertEquals(altjclouds.getTTL(), 600002); + assertTrue(altjclouds.getCreated().before(now)); + assertTrue(altjclouds.getUpdated().before(now)); + } + + @Test(dependsOnMethods = "testCreateDomainsWithSubdomainsAndRecords") + public void testCreateSimpleDomain() throws Exception { + CreateDomain createDomain = CreateDomain.builder() + .name("simple-" + JCLOUDS_EXAMPLE) + .email("simple-jclouds@" + JCLOUDS_EXAMPLE) + .build(); + + Iterable createDomains = ImmutableList.of(createDomain); + Domain domain = awaitComplete(api, api.getDomainApi().create(createDomains)).iterator().next(); + + assertEquals(domain.getName(), "simple-" + JCLOUDS_EXAMPLE); + assertEquals(domain.getEmail(), "simple-jclouds@" + JCLOUDS_EXAMPLE); + + testDomains = Maps.newHashMap(testDomains); + testDomains.put(domain.getName(), domain); + } + + @Test(dependsOnMethods = "testCreateSimpleDomain") + public void testListDomains() throws Exception { + Set domains = api.getDomainApi().list().concat().toSet(); + assertEquals(domains.size(), 5); + } + + @Test(dependsOnMethods = "testListDomains") + public void testListDomainsWithFilter() throws Exception { + Set domains = api.getDomainApi().listWithFilterByNamesMatching("alt-" + JCLOUDS_EXAMPLE).concat().toSet(); + assertEquals(domains.size(), 1); + } + + @Test(dependsOnMethods = "testListDomainsWithFilter") + public void testListSubdomains() throws Exception { + Domain domain = testDomains.get(JCLOUDS_EXAMPLE); + Set subdomains = api.getDomainApi().listSubdomains(domain.getId()).concat().toSet(); + assertEquals(subdomains.size(), 2); + } + + @Test(dependsOnMethods = "testListSubdomains") + public void testGetDomain() throws Exception { + Domain domain = testDomains.get(JCLOUDS_EXAMPLE); + Domain jclouds = api.getDomainApi().get(domain.getId()); + + Thread.sleep(1000); + Date now = new Date(); + + assertTrue(jclouds.getId() > 0); + assertTrue(jclouds.getAccountId() > 0); + assertEquals(jclouds.getName(), JCLOUDS_EXAMPLE); + assertEquals(jclouds.getEmail(), "jclouds1@" + JCLOUDS_EXAMPLE); + assertEquals(jclouds.getComment().get(), "Hello Domain 1"); + assertEquals(jclouds.getTTL(), 600001); + assertTrue(jclouds.getCreated().before(now)); + assertTrue(jclouds.getUpdated().before(now)); + + assertEquals(jclouds.getSubdomains().size(), 2); + + Subdomain devjclouds = null; + Subdomain testjclouds = null; + + for (Subdomain subdomain: jclouds.getSubdomains()) { + if (subdomain.getName().equals("dev." + JCLOUDS_EXAMPLE)) { + devjclouds = subdomain; + } else if (subdomain.getName().equals("test." + JCLOUDS_EXAMPLE)) { + testjclouds = subdomain; + } + } + + assertTrue(devjclouds.getId() > 0); + assertEquals(devjclouds.getName(), "dev." + JCLOUDS_EXAMPLE); + assertEquals(devjclouds.getEmail(), "jclouds@" + JCLOUDS_EXAMPLE); + assertEquals(devjclouds.getComment().get(), "Hello dev subdomain"); + assertTrue(devjclouds.getCreated().before(now)); + assertTrue(devjclouds.getUpdated().before(now)); + + assertTrue(testjclouds.getId() > 0); + assertEquals(testjclouds.getName(), "test." + JCLOUDS_EXAMPLE); + assertEquals(testjclouds.getEmail(), "jclouds@" + JCLOUDS_EXAMPLE); + assertEquals(testjclouds.getComment().get(), "Hello test subdomain"); + assertTrue(testjclouds.getCreated().before(now)); + assertTrue(testjclouds.getUpdated().before(now)); + + assertEquals(jclouds.getRecords().size(), 4); // 2 created above + 2 nameserver (NS) records + + RecordDetail mxRecord = null; + RecordDetail aRecord = null; + RecordDetail nsRecord = null; + + for (RecordDetail record: jclouds.getRecords()) { + if (record.getType().equals("MX")) { + mxRecord = record; + } else if (record.getType().equals("A")) { + aRecord = record; + } else if (record.getType().equals("NS")) { + nsRecord = record; // don't care which one we get + } + } + + assertNotNull(mxRecord.getId()); + assertEquals(mxRecord.getType(), "MX"); + assertEquals(mxRecord.getName(), JCLOUDS_EXAMPLE); + assertEquals(mxRecord.getPriority().intValue(), 11235); + assertEquals(mxRecord.getComment(), "MX Record"); + assertEquals(mxRecord.getTTL(), 60000); + assertTrue(mxRecord.getCreated().before(now)); + assertTrue(mxRecord.getUpdated().before(now)); + + assertNotNull(aRecord.getId()); + assertEquals(aRecord.getType(), "A"); + assertEquals(aRecord.getName(), JCLOUDS_EXAMPLE); + assertNull(aRecord.getPriority()); + assertEquals(aRecord.getComment(), "A Record"); + assertEquals(aRecord.getTTL(), 60000); + assertTrue(aRecord.getCreated().before(now)); + assertTrue(aRecord.getUpdated().before(now)); + + assertNotNull(nsRecord.getId()); + assertEquals(nsRecord.getType(), "NS"); + assertEquals(nsRecord.getName(), JCLOUDS_EXAMPLE); + assertEquals(nsRecord.getTTL(), 600001); + assertTrue(nsRecord.getCreated().before(now)); + assertTrue(nsRecord.getUpdated().before(now)); + } + + @Test(dependsOnMethods = "testGetDomain") + public void testUpdateDomain() throws Exception { + UpdateDomain updateDomain = UpdateDomain.builder() + .email("jclouds3@" + JCLOUDS_EXAMPLE) + .ttl(600003) + .comment("Hello Domain Update 3") + .build(); + + awaitComplete(api, api.getDomainApi().update(testDomains.get(JCLOUDS_EXAMPLE).getId(), updateDomain)); + Domain jclouds = api.getDomainApi().get(testDomains.get(JCLOUDS_EXAMPLE).getId()); + + assertEquals(jclouds.getEmail(), "jclouds3@" + JCLOUDS_EXAMPLE); + assertEquals(jclouds.getComment().get(), "Hello Domain Update 3"); + assertEquals(jclouds.getTTL(), 600003); + } + + @Test(dependsOnMethods = "testUpdateDomain") + public void testUpdateDomainsTTL() throws Exception { + List ids = ImmutableList.of( + testDomains.get(JCLOUDS_EXAMPLE).getId(), testDomains.get("alt-" + JCLOUDS_EXAMPLE).getId()); + awaitComplete(api, api.getDomainApi().updateTTL(ids, 1234567)); + + Domain jclouds = api.getDomainApi().get(testDomains.get(JCLOUDS_EXAMPLE).getId()); + Domain altjclouds = api.getDomainApi().get(testDomains.get("alt-" + JCLOUDS_EXAMPLE).getId()); + + assertEquals(jclouds.getTTL(), 1234567); + assertEquals(altjclouds.getTTL(), 1234567); + } + + @Test(dependsOnMethods = "testUpdateDomainsTTL") + public void testUpdateDomainsEmail() throws Exception { + List ids = ImmutableList.of( + testDomains.get(JCLOUDS_EXAMPLE).getId(), testDomains.get("alt-" + JCLOUDS_EXAMPLE).getId()); + awaitComplete(api, api.getDomainApi().updateEmail(ids, "jclouds-up@" + JCLOUDS_EXAMPLE)); + + Domain jclouds = api.getDomainApi().get(testDomains.get(JCLOUDS_EXAMPLE).getId()); + Domain altjclouds = api.getDomainApi().get(testDomains.get("alt-" + JCLOUDS_EXAMPLE).getId()); + + assertEquals(jclouds.getEmail(), "jclouds-up@" + JCLOUDS_EXAMPLE); + assertEquals(altjclouds.getEmail(), "jclouds-up@" + JCLOUDS_EXAMPLE); + } + + @Test(dependsOnMethods = "testUpdateDomainsEmail") + public void testExportDomain() throws Exception { + Domain domain = testDomains.get(JCLOUDS_EXAMPLE); + List domainExport = awaitComplete(api, api.getDomainApi().exportFormat(domain.getId(), Domain.Format.BIND_9)); + + assertTrue(domainExport.get(0).contains(JCLOUDS_EXAMPLE)); + } + + @Test(dependsOnMethods = "testExportDomain") + public void testImportDomain() throws Exception { + List contents = ImmutableList. of( + "imp-" + JCLOUDS_EXAMPLE + ". 3600 IN SOA ns.rackspace.com. jclouds.imp-" + JCLOUDS_EXAMPLE + ". 1363882703 3600 3600 3600 3600", + "imp-" + JCLOUDS_EXAMPLE + ". 600 IN A 50.56.174.152"); + + Domain domain = awaitComplete(api, api.getDomainApi().importFormat(contents, Domain.Format.BIND_9)); + RecordDetail record = domain.getRecords().iterator().next(); + + assertEquals(domain.getName(), "imp-" + JCLOUDS_EXAMPLE); + assertEquals(domain.getEmail(), "jclouds@imp-" + JCLOUDS_EXAMPLE); + assertEquals(record.getType(), "A"); + assertEquals(record.getData(), "50.56.174.152"); + assertEquals(record.getTTL(), 600); + + testDomains = Maps.newHashMap(testDomains); + testDomains.put(domain.getName(), domain); + } + + @Override + @AfterClass(groups = { "integration", "live" }) + protected void tearDown() { + List domainIds = Lists.newArrayList(); + + for (Domain domain: testDomains.values()) { + domainIds.add(domain.getId()); + } + + try { + awaitComplete(api, api.getDomainApi().delete(domainIds, true)); + } + catch (TimeoutException e) { + e.printStackTrace(); + } + super.tearDown(); + } +} diff --git a/apis/rackspace-clouddns/src/test/java/org/jclouds/rackspace/clouddns/v1/features/LimitApiExpectTest.java b/apis/rackspace-clouddns/src/test/java/org/jclouds/rackspace/clouddns/v1/features/LimitApiExpectTest.java new file mode 100644 index 0000000000..9c6beb184f --- /dev/null +++ b/apis/rackspace-clouddns/src/test/java/org/jclouds/rackspace/clouddns/v1/features/LimitApiExpectTest.java @@ -0,0 +1,84 @@ +/** + * 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.rackspace.clouddns.v1.features; + +import static javax.ws.rs.core.Response.Status.OK; +import static org.testng.Assert.assertEquals; + +import java.net.URI; + +import org.jclouds.http.HttpResponse; +import org.jclouds.openstack.v2_0.domain.Limits; +import org.jclouds.openstack.v2_0.domain.RateLimit; +import org.jclouds.rackspace.clouddns.v1.CloudDNSApi; +import org.jclouds.rackspace.clouddns.v1.internal.BaseCloudDNSApiExpectTest; +import org.testng.annotations.Test; + +import com.google.common.base.Predicate; +import com.google.common.collect.Iterables; + +/** + * @author Everett Toews + */ +@Test(groups = "unit") +public class LimitApiExpectTest extends BaseCloudDNSApiExpectTest { + public void testListLimits() { + URI endpoint = URI.create("https://dns.api.rackspacecloud.com/v1.0/123123/limits"); + LimitApi api = requestsSendResponses( + rackspaceAuthWithUsernameAndApiKey, + responseWithAccess, + authenticatedGET().endpoint(endpoint).build(), + HttpResponse.builder().statusCode(OK.getStatusCode()).payload(payloadFromResource("/limit-list.json")).build() + ).getLimitApi(); + + Limits limits = api.list(); + assertEquals(limits.getAbsoluteLimits().get("records per domain"), Integer.valueOf(500)); + assertEquals(limits.getAbsoluteLimits().get("domains"), Integer.valueOf(500)); + assertEquals(Iterables.size(limits.getRateLimits()), 2); + + RateLimit statusRateLimit = Iterables.tryFind(limits.getRateLimits(), isStatusRateLimit()).orNull(); + assertEquals(statusRateLimit.getRegex(), ".*/v\\d+\\.\\d+/(\\d+/status).*"); + assertEquals(Iterables.get(statusRateLimit.getLimits(), 0).getVerb(), "GET"); + assertEquals(Iterables.get(statusRateLimit.getLimits(), 0).getValue(), 5); + assertEquals(Iterables.get(statusRateLimit.getLimits(), 0).getRemaining().get(), Integer.valueOf(5)); + assertEquals(Iterables.get(statusRateLimit.getLimits(), 0).getUnit(), "SECOND"); + } + + public void testListLimitTypes() { + URI endpoint = URI.create("https://dns.api.rackspacecloud.com/v1.0/123123/limits/types"); + LimitApi api = requestsSendResponses( + rackspaceAuthWithUsernameAndApiKey, + responseWithAccess, + authenticatedGET().endpoint(endpoint).build(), + HttpResponse.builder().statusCode(OK.getStatusCode()).payload(payloadFromResource("/limit-types-list.json")).build() + ).getLimitApi(); + + Iterable limitTypes = api.listTypes(); + assertEquals(Iterables.size(limitTypes), 3); + } + + private static Predicate isStatusRateLimit() { + return new Predicate() { + @Override + public boolean apply(RateLimit rateLimit) { + return rateLimit.getUri().contains("status"); + } + }; + } +} diff --git a/apis/rackspace-clouddns/src/test/java/org/jclouds/rackspace/clouddns/v1/features/LimitApiLiveTest.java b/apis/rackspace-clouddns/src/test/java/org/jclouds/rackspace/clouddns/v1/features/LimitApiLiveTest.java new file mode 100644 index 0000000000..f1d107af09 --- /dev/null +++ b/apis/rackspace-clouddns/src/test/java/org/jclouds/rackspace/clouddns/v1/features/LimitApiLiveTest.java @@ -0,0 +1,50 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.rackspace.clouddns.v1.features; + +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertTrue; + +import org.jclouds.openstack.v2_0.domain.Limits; +import org.jclouds.rackspace.clouddns.v1.internal.BaseCloudDNSApiLiveTest; +import org.testng.annotations.Test; + +import com.google.common.collect.Iterables; + +/** + * @author Everett Toews + */ +@Test(groups = "live", singleThreaded = true, testName = "LimitApiLiveTest") +public class LimitApiLiveTest extends BaseCloudDNSApiLiveTest { + @Test + public void testList() throws Exception { + Limits limits = api.getLimitApi().list(); + assertNotNull(limits.getAbsoluteLimits()); + assertNotNull(limits.getRateLimits()); + assertTrue(limits.getAbsoluteLimits().size() > 1); + assertTrue(Iterables.size(limits.getRateLimits()) > 1); + } + + @Test + public void testListTypes() throws Exception { + Iterable limitTypes = api.getLimitApi().listTypes(); + assertNotNull(limitTypes); + assertTrue(Iterables.size(limitTypes) > 1); + } +} diff --git a/apis/rackspace-clouddns/src/test/java/org/jclouds/rackspace/clouddns/v1/features/RecordApiExpectTest.java b/apis/rackspace-clouddns/src/test/java/org/jclouds/rackspace/clouddns/v1/features/RecordApiExpectTest.java new file mode 100644 index 0000000000..1bc64a61b9 --- /dev/null +++ b/apis/rackspace-clouddns/src/test/java/org/jclouds/rackspace/clouddns/v1/features/RecordApiExpectTest.java @@ -0,0 +1,328 @@ +/** + * 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.rackspace.clouddns.v1.features; + +import static javax.ws.rs.HttpMethod.POST; +import static javax.ws.rs.HttpMethod.PUT; +import static javax.ws.rs.core.Response.Status.OK; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertNull; +import static org.testng.Assert.assertTrue; + +import java.net.URI; +import java.util.Date; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import javax.ws.rs.core.MediaType; + +import org.jclouds.http.HttpResponse; +import org.jclouds.rackspace.clouddns.v1.CloudDNSApi; +import org.jclouds.rackspace.clouddns.v1.domain.Job; +import org.jclouds.rackspace.clouddns.v1.domain.Record; +import org.jclouds.rackspace.clouddns.v1.domain.RecordDetail; +import org.jclouds.rackspace.clouddns.v1.internal.BaseCloudDNSApiExpectTest; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; + +/** + * @author Everett Toews + */ +@Test(groups = "unit") +public class RecordApiExpectTest extends BaseCloudDNSApiExpectTest { + private static final String JCLOUDS_EXAMPLE = "jclouds-example.com"; + + public void testAddRecord() { + URI endpoint = URI.create("https://dns.api.rackspacecloud.com/v1.0/123123/domains/3650908/records"); + RecordApi api = requestsSendResponses( + rackspaceAuthWithUsernameAndApiKey, + responseWithAccess, + authenticatedGET() + .method(POST) + .payload(payloadFromResource("/record-create.json")) + .endpoint(endpoint) + .build(), + HttpResponse.builder().statusCode(OK.getStatusCode()).payload(payloadFromResource("/record-create-response.json")).build()) + .getRecordApiForDomain(3650908); + + Record createMXRecord = Record.builder() + .type("MX") + .name(JCLOUDS_EXAMPLE) + .data("mail." + JCLOUDS_EXAMPLE) + .comment("MX Record") + .priority(11235) + .build(); + + Record createARecord = Record.builder() + .type("A") + .name(JCLOUDS_EXAMPLE) + .data("10.0.0.1") + .build(); + + List createRecords = ImmutableList.of(createMXRecord, createARecord); + Job> job = api.create(createRecords); + + assertEquals(job.getStatus(), Job.Status.COMPLETED); + assertTrue(job.getResource().isPresent()); + + Set records = job.getResource().get(); + Date now = new Date(); + RecordDetail mxRecord = null; + RecordDetail aRecord = null; + + for (RecordDetail record: records) { + if (record.getType().equals("MX")) { + mxRecord = record; + } else if (record.getType().equals("A")) { + aRecord = record; + } + } + + assertNotNull(mxRecord.getId()); + assertEquals(mxRecord.getType(), "MX"); + assertEquals(mxRecord.getName(), JCLOUDS_EXAMPLE); + assertEquals(mxRecord.getPriority().intValue(), 11235); + assertEquals(mxRecord.getComment(), "MX Record"); + assertEquals(mxRecord.getTTL(), 60000); + assertTrue(mxRecord.getCreated().before(now)); + assertTrue(mxRecord.getUpdated().before(now)); + + assertNotNull(aRecord.getId()); + assertEquals(aRecord.getType(), "A"); + assertEquals(aRecord.getName(), JCLOUDS_EXAMPLE); + assertNull(aRecord.getPriority()); + assertEquals(aRecord.getTTL(), 60000); + assertTrue(aRecord.getCreated().before(now)); + assertTrue(aRecord.getUpdated().before(now)); + } + + public void testListRecords() { + URI endpoint = URI.create("https://dns.api.rackspacecloud.com/v1.0/123123/domains/3650908/records"); + RecordApi api = requestsSendResponses( + rackspaceAuthWithUsernameAndApiKey, + responseWithAccess, + authenticatedGET().endpoint(endpoint).build(), + HttpResponse.builder().statusCode(OK.getStatusCode()).payload(payloadFromResource("/record-list.json")).build()) + .getRecordApiForDomain(3650908); + + ImmutableList records = api.list().concat().toList(); + assertEquals(records.size(), 4); // 2 created above + 2 nameserver (NS) records + + for (RecordDetail record: records) { + assertTrue(record.getName().contains(JCLOUDS_EXAMPLE)); + } + } + + public void testListByType() { + URI endpoint = URI.create("https://dns.api.rackspacecloud.com/v1.0/123123/domains/3650908/records?type=A"); + RecordApi api = requestsSendResponses( + rackspaceAuthWithUsernameAndApiKey, + responseWithAccess, + authenticatedGET().endpoint(endpoint).build(), + HttpResponse.builder().statusCode(OK.getStatusCode()).payload(payloadFromResource("/record-list-with-filter.json")).build()) + .getRecordApiForDomain(3650908); + + ImmutableList records = api.listByType("A").concat().toList(); + Date now = new Date(); + + assertEquals(records.size(), 1); + assertEquals(records.get(0).getId(), "A-9846146"); + assertEquals(records.get(0).getName(), JCLOUDS_EXAMPLE); + assertEquals(records.get(0).getType(), "A"); + assertEquals(records.get(0).getData(), "10.0.1.0"); + assertEquals(records.get(0).getTTL(), 60000); + assertTrue(records.get(0).getCreated().before(now)); + assertTrue(records.get(0).getUpdated().before(now)); + } + + public void testListByTypeAndData() { + URI endpoint = URI.create("https://dns.api.rackspacecloud.com/v1.0/123123/domains/3650908/records?type=A&data=10.0.1.0"); + RecordApi api = requestsSendResponses( + rackspaceAuthWithUsernameAndApiKey, + responseWithAccess, + authenticatedGET().endpoint(endpoint).build(), + HttpResponse.builder().statusCode(OK.getStatusCode()).payload(payloadFromResource("/record-list-with-filter.json")).build()) + .getRecordApiForDomain(3650908); + + ImmutableList records = api.listByTypeAndData("A", "10.0.1.0").concat().toList(); + Date now = new Date(); + + assertEquals(records.size(), 1); + assertEquals(records.get(0).getId(), "A-9846146"); + assertEquals(records.get(0).getName(), JCLOUDS_EXAMPLE); + assertEquals(records.get(0).getType(), "A"); + assertEquals(records.get(0).getData(), "10.0.1.0"); + assertEquals(records.get(0).getTTL(), 60000); + assertTrue(records.get(0).getCreated().before(now)); + assertTrue(records.get(0).getUpdated().before(now)); + } + + public void testListByNameAndType() { + URI endpoint = URI.create("https://dns.api.rackspacecloud.com/v1.0/123123/domains/3650908/records?name=jclouds-example.com&type=A"); + RecordApi api = requestsSendResponses( + rackspaceAuthWithUsernameAndApiKey, + responseWithAccess, + authenticatedGET().endpoint(endpoint).build(), + HttpResponse.builder().statusCode(OK.getStatusCode()).payload(payloadFromResource("/record-list-with-filter.json")).build()) + .getRecordApiForDomain(3650908); + + ImmutableList records = api.listByNameAndType(JCLOUDS_EXAMPLE, "A").concat().toList(); + Date now = new Date(); + + assertEquals(records.size(), 1); + assertEquals(records.get(0).getId(), "A-9846146"); + assertEquals(records.get(0).getName(), JCLOUDS_EXAMPLE); + assertEquals(records.get(0).getType(), "A"); + assertEquals(records.get(0).getData(), "10.0.1.0"); + assertEquals(records.get(0).getTTL(), 60000); + assertTrue(records.get(0).getCreated().before(now)); + assertTrue(records.get(0).getUpdated().before(now)); + } + + public void testGetByNameAndTypeAndData() { + URI endpoint = URI.create("https://dns.api.rackspacecloud.com/v1.0/123123/domains/3650908/records?name=jclouds-example.com&type=A&data=10.0.1.0"); + RecordApi api = requestsSendResponses( + rackspaceAuthWithUsernameAndApiKey, + responseWithAccess, + authenticatedGET().endpoint(endpoint).build(), + HttpResponse.builder().statusCode(OK.getStatusCode()).payload(payloadFromResource("/record-list-with-filter.json")).build()) + .getRecordApiForDomain(3650908); + + RecordDetail record = api.getByNameAndTypeAndData(JCLOUDS_EXAMPLE, "A", "10.0.1.0"); + Date now = new Date(); + + assertEquals(record.getId(), "A-9846146"); + assertEquals(record.getName(), JCLOUDS_EXAMPLE); + assertEquals(record.getType(), "A"); + assertEquals(record.getData(), "10.0.1.0"); + assertEquals(record.getTTL(), 60000); + assertTrue(record.getCreated().before(now)); + assertTrue(record.getUpdated().before(now)); + } + + public void testGetRecord() { + URI endpoint = URI.create("https://dns.api.rackspacecloud.com/v1.0/123123/domains/3650908/records/A-9846146"); + RecordApi api = requestsSendResponses( + rackspaceAuthWithUsernameAndApiKey, + responseWithAccess, + authenticatedGET().endpoint(endpoint).build(), + HttpResponse.builder().statusCode(OK.getStatusCode()).payload(payloadFromResource("/record-get.json")).build()) + .getRecordApiForDomain(3650908); + + RecordDetail record = api.get("A-9846146"); + Date now = new Date(); + + assertEquals(record.getId(), "A-9846146"); + assertEquals(record.getName(), JCLOUDS_EXAMPLE); + assertEquals(record.getType(), "A"); + assertEquals(record.getData(), "10.0.1.0"); + assertEquals(record.getTTL(), 60000); + assertTrue(record.getCreated().before(now)); + assertTrue(record.getUpdated().before(now)); + } + + public void testUpdateRecord() { + URI endpoint = URI.create("https://dns.api.rackspacecloud.com/v1.0/123123/domains/3650908/records/SRV-21858"); + RecordApi api = requestsSendResponses( + rackspaceAuthWithUsernameAndApiKey, + responseWithAccess, + authenticatedGET() + .method(PUT) + .payload(payloadFromResourceWithContentType("/record-update.json", MediaType.APPLICATION_JSON)) + .endpoint(endpoint) + .build(), + HttpResponse.builder().statusCode(OK.getStatusCode()).payload(payloadFromResource("/record-update-response.json")).build()) + .getRecordApiForDomain(3650908); + + Record record = Record.builder() + .name("_sip._udp." + JCLOUDS_EXAMPLE) + .ttl(86401) + .data("1 3444 sip." + JCLOUDS_EXAMPLE) // weight port target + .priority(12358) + .comment("Updated Protocol to UDP") + .build(); + + Job job = api.update("SRV-21858", record); + + assertEquals(job.getStatus(), Job.Status.COMPLETED); + } + + public void testUpdateRecords() { + URI endpoint = URI.create("https://dns.api.rackspacecloud.com/v1.0/123123/domains/3650908/records"); + RecordApi api = requestsSendResponses( + rackspaceAuthWithUsernameAndApiKey, + responseWithAccess, + authenticatedGET() + .method(PUT) + .payload(payloadFromResourceWithContentType("/records-update.json", MediaType.APPLICATION_JSON)) + .endpoint(endpoint) + .build(), + HttpResponse.builder().statusCode(OK.getStatusCode()).payload(payloadFromResource("/records-update-response.json")).build()) + .getRecordApiForDomain(3650908); + + Record updateARecord = Record.builder() + .comment("Multi-record Update") + .build(); + + Record updateMXRecord = Record.builder() + .comment("Multi-record Update") + .build(); + + Map updateRecords = ImmutableMap. of( + "A-9846146", updateARecord, + "MX-9846146", updateMXRecord); + + Job job = api.update(updateRecords); + + assertEquals(job.getStatus(), Job.Status.COMPLETED); + } + + public void testDeleteRecord() { + URI endpoint = URI.create("https://dns.api.rackspacecloud.com/v1.0/123123/domains/3650908/records/A-9846146"); + RecordApi api = requestsSendResponses( + rackspaceAuthWithUsernameAndApiKey, + responseWithAccess, + authenticatedGET().method("DELETE").replaceHeader("Accept", MediaType.WILDCARD).endpoint(endpoint).build(), + HttpResponse.builder().statusCode(OK.getStatusCode()).payload(payloadFromResource("/record-delete.json")).build()) + .getRecordApiForDomain(3650908); + + Job job = api.delete("A-9846146"); + + assertEquals(job.getStatus(), Job.Status.COMPLETED); + } + + public void testDeleteRecords() { + URI endpoint = URI.create("https://dns.api.rackspacecloud.com/v1.0/123123/domains/3650908/records?id=A-9846146&id=MX-9846146"); + RecordApi api = requestsSendResponses( + rackspaceAuthWithUsernameAndApiKey, + responseWithAccess, + authenticatedGET().method("DELETE").replaceHeader("Accept", MediaType.WILDCARD).endpoint(endpoint).build(), + HttpResponse.builder().statusCode(OK.getStatusCode()).payload(payloadFromResource("/records-delete.json")).build()) + .getRecordApiForDomain(3650908); + + List recordIds = ImmutableList. of("A-9846146", "MX-9846146"); + Job job = api.delete(recordIds); + + assertEquals(job.getStatus(), Job.Status.COMPLETED); + } +} diff --git a/apis/rackspace-clouddns/src/test/java/org/jclouds/rackspace/clouddns/v1/features/RecordApiLiveTest.java b/apis/rackspace-clouddns/src/test/java/org/jclouds/rackspace/clouddns/v1/features/RecordApiLiveTest.java new file mode 100644 index 0000000000..5fa0b1e6ea --- /dev/null +++ b/apis/rackspace-clouddns/src/test/java/org/jclouds/rackspace/clouddns/v1/features/RecordApiLiveTest.java @@ -0,0 +1,293 @@ +/** + * 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.rackspace.clouddns.v1.features; + +import static org.jclouds.rackspace.clouddns.v1.predicates.JobPredicates.awaitComplete; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertNull; +import static org.testng.Assert.assertTrue; + +import java.util.Date; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.TimeoutException; + +import org.jclouds.rackspace.clouddns.v1.domain.CreateDomain; +import org.jclouds.rackspace.clouddns.v1.domain.Domain; +import org.jclouds.rackspace.clouddns.v1.domain.Record; +import org.jclouds.rackspace.clouddns.v1.domain.RecordDetail; +import org.jclouds.rackspace.clouddns.v1.functions.RecordFunctions; +import org.jclouds.rackspace.clouddns.v1.internal.BaseCloudDNSApiLiveTest; +import org.testng.annotations.AfterClass; +import org.testng.annotations.Test; + +import com.google.common.base.Function; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.Maps; + +/** + * @author Everett Toews + */ +@Test(groups = "live", singleThreaded = true, testName = "RecordApiLiveTest") +public class RecordApiLiveTest extends BaseCloudDNSApiLiveTest { + + // just in case the username has a '.' we replace it to avoid creating subdomains + private static final String JCLOUDS_EXAMPLE = System.getProperty("user.name").replace('.', '-') + "-recordtest-jclouds.org"; + + private int domainId; + private String aRecordId; + private String srvRecordId; + private String mxRecordId; + + @Test + public void testCreateDomain() throws Exception { + CreateDomain createDomain = CreateDomain.builder() + .name(JCLOUDS_EXAMPLE) + .email("jclouds@" + JCLOUDS_EXAMPLE) + .ttl(60000) + .build(); + + Iterable createDomains = ImmutableList.of(createDomain); + Domain domain = awaitComplete(api, api.getDomainApi().create(createDomains)).iterator().next(); + + assertEquals(domain.getName(), JCLOUDS_EXAMPLE); + assertEquals(domain.getEmail(), "jclouds@" + JCLOUDS_EXAMPLE); + assertTrue(domain.getRecords().isEmpty()); + + domainId = domain.getId(); + } + + @Test(dependsOnMethods = "testCreateDomain") + public void testCreateRecords() throws Exception { + Record createMXRecord = Record.builder() + .type("MX") + .name(JCLOUDS_EXAMPLE) + .data("mail." + JCLOUDS_EXAMPLE) + .comment("MX Record") + .priority(11235) + .build(); + + Record createARecord = Record.builder() + .type("A") + .name(JCLOUDS_EXAMPLE) + .data("10.0.0.1") + .build(); + + Record createSRVRecord = Record.builder() + .type("SRV") + .name("_sip._tcp." + JCLOUDS_EXAMPLE) + .ttl(86400) + .data("1 3443 sip." + JCLOUDS_EXAMPLE) // weight port target + .priority(11235) + .comment("Updated Protocol to UDP") + .build(); + + List createRecords = ImmutableList.of(createMXRecord, createARecord, createSRVRecord); + Set records = awaitComplete(api, api.getRecordApiForDomain(domainId).create(createRecords)); + + Thread.sleep(1000); + Date now = new Date(); + + RecordDetail mxRecord = null; + RecordDetail aRecord = null; + RecordDetail srvRecord = null; + + for (RecordDetail record: records) { + if (record.getType().equals("MX")) { + mxRecord = record; + } else if (record.getType().equals("A")) { + aRecord = record; + } else if (record.getType().equals("SRV")) { + srvRecord = record; + } + } + + assertNotNull(mxRecord.getId()); + assertEquals(mxRecord.getType(), "MX"); + assertEquals(mxRecord.getName(), JCLOUDS_EXAMPLE); + assertEquals(mxRecord.getPriority().intValue(), 11235); + assertEquals(mxRecord.getComment(), "MX Record"); + assertEquals(mxRecord.getTTL(), 60000); + assertTrue(mxRecord.getCreated().before(now)); + assertTrue(mxRecord.getUpdated().before(now)); + + assertNotNull(aRecord.getId()); + assertEquals(aRecord.getType(), "A"); + assertEquals(aRecord.getName(), JCLOUDS_EXAMPLE); + assertEquals(aRecord.getData(), "10.0.0.1"); + assertNull(aRecord.getPriority()); + assertEquals(aRecord.getTTL(), 60000); + assertTrue(aRecord.getCreated().before(now)); + assertTrue(aRecord.getUpdated().before(now)); + + assertNotNull(srvRecord.getId()); + assertEquals(srvRecord.getType(), "SRV"); + assertEquals(srvRecord.getName(), "_sip._tcp." + JCLOUDS_EXAMPLE); + assertEquals(srvRecord.getData(), "1 3443 sip." + JCLOUDS_EXAMPLE); + assertEquals(srvRecord.getPriority().intValue(), 11235); + assertEquals(srvRecord.getTTL(), 86400); + assertTrue(srvRecord.getCreated().before(now)); + assertTrue(srvRecord.getUpdated().before(now)); + } + + @Test(dependsOnMethods = "testCreateRecords") + public void testListRecords() throws Exception { + Set records = api.getRecordApiForDomain(domainId).list().concat().toSet(); + assertEquals(records.size(), 5); // 3 created above + 2 nameserver (NS) records + } + + @Test(dependsOnMethods = "testListRecords") + public void testListRecordsByCriteriaMethods() throws Exception { + List records = api.getRecordApiForDomain(domainId).listByType("SRV").concat().toList(); + assertEquals(records.size(), 1); + + srvRecordId = records.get(0).getId(); + + records = api.getRecordApiForDomain(domainId).listByTypeAndData("A", "10.0.0.1").concat().toList(); + assertEquals(records.size(), 1); + + aRecordId = records.get(0).getId(); + + records = api.getRecordApiForDomain(domainId).listByNameAndType(JCLOUDS_EXAMPLE, "MX").concat().toList(); + assertEquals(records.size(), 1); + + mxRecordId = records.get(0).getId(); + } + + @Test(dependsOnMethods = "testListRecordsByCriteriaMethods") + public void testGetRecordByNameAndTypeAndData() throws Exception { + RecordDetail record = api.getRecordApiForDomain(domainId).getByNameAndTypeAndData(JCLOUDS_EXAMPLE, "A", "10.0.0.1"); + Date now = new Date(); + + assertNotNull(record.getId()); + assertEquals(record.getName(), JCLOUDS_EXAMPLE); + assertEquals(record.getType(), "A"); + assertEquals(record.getData(), "10.0.0.1"); + assertEquals(record.getTTL(), 60000); + assertTrue(record.getCreated().before(now)); + assertTrue(record.getUpdated().before(now)); + } + + @Test(dependsOnMethods = "testGetRecordByNameAndTypeAndData") + public void testGetRecord() throws Exception { + RecordDetail record = api.getRecordApiForDomain(domainId).get(aRecordId); + Date now = new Date(); + + assertNotNull(record.getId()); + assertEquals(record.getName(), JCLOUDS_EXAMPLE); + assertEquals(record.getType(), "A"); + assertEquals(record.getData(), "10.0.0.1"); + assertEquals(record.getTTL(), 60000); + assertTrue(record.getCreated().before(now)); + assertTrue(record.getUpdated().before(now)); + } + + @Test(dependsOnMethods = "testGetRecord") + public void testUpdateRecord() throws Exception { + Record record = Record.builder() + .name("_sip._udp." + JCLOUDS_EXAMPLE) + .ttl(86401) + .data("1 3444 sip." + JCLOUDS_EXAMPLE) // weight port target + .priority(12358) + .comment("Updated Protocol to UDP") + .build(); + + awaitComplete(api, api.getRecordApiForDomain(domainId).update(srvRecordId, record)); + + RecordDetail srvRecord = api.getRecordApiForDomain(domainId).get(srvRecordId); + Date now = new Date(); + + assertNotNull(srvRecord.getId()); + assertEquals(srvRecord.getType(), "SRV"); + assertEquals(srvRecord.getName(), "_sip._udp." + JCLOUDS_EXAMPLE); + assertEquals(srvRecord.getData(), "1 3444 sip." + JCLOUDS_EXAMPLE); + assertEquals(srvRecord.getPriority().intValue(), 12358); + assertEquals(srvRecord.getTTL(), 86401); + assertEquals(srvRecord.getComment(), "Updated Protocol to UDP"); + assertTrue(srvRecord.getCreated().before(now)); + assertTrue(srvRecord.getUpdated().before(now)); + } + + @Test(dependsOnMethods = "testUpdateRecord") + public void testUpdateRecords() throws Exception { + Set recordDetails = api.getRecordApiForDomain(domainId).list().concat().toSet(); + Map idsToRecords = RecordFunctions.toRecordMap(recordDetails); + Map updateRecords = Maps.transformValues(idsToRecords, updateTTLAndComment(35813, "New TTL")); + + awaitComplete(api, api.getRecordApiForDomain(domainId).update(updateRecords)); + + RecordDetail record = api.getRecordApiForDomain(domainId).get(aRecordId); + Date now = new Date(); + + assertNotNull(record.getId()); + assertEquals(record.getName(), JCLOUDS_EXAMPLE); + assertEquals(record.getType(), "A"); + assertEquals(record.getData(), "10.0.0.1"); + assertEquals(record.getTTL(), 35813); + assertEquals(record.getComment(), "New TTL"); + assertTrue(record.getCreated().before(now)); + assertTrue(record.getUpdated().before(now)); + + recordDetails = api.getRecordApiForDomain(domainId).list().concat().toSet(); + + for (RecordDetail recordDetail: recordDetails) { + assertEquals(recordDetail.getTTL(), 35813); + assertEquals(recordDetail.getComment(), "New TTL"); + } + } + + private Function updateTTLAndComment(final int ttl, final String comment) { + return new Function() { + public Record apply(Record record) { + return record.toBuilder().ttl(ttl).comment(comment).build(); + } + }; + } + + @Test(dependsOnMethods = "testUpdateRecords") + public void testDeleteRecord() throws Exception { + awaitComplete(api, api.getRecordApiForDomain(domainId).delete(aRecordId)); + + assertNull(api.getRecordApiForDomain(domainId).get(aRecordId)); + } + + @Test(dependsOnMethods = "testDeleteRecord") + public void testDeleteRecords() throws Exception { + List recordIds = ImmutableList. of(srvRecordId, mxRecordId); + + awaitComplete(api, api.getRecordApiForDomain(domainId).delete(recordIds)); + + assertNull(api.getRecordApiForDomain(domainId).get(srvRecordId)); + assertNull(api.getRecordApiForDomain(domainId).get(mxRecordId)); + } + + @Override + @AfterClass(groups = { "integration", "live" }) + protected void tearDown() { + try { + awaitComplete(api, api.getDomainApi().delete(ImmutableList. of(domainId), true)); + } + catch (TimeoutException e) { + e.printStackTrace(); + } + super.tearDown(); + } +} diff --git a/apis/rackspace-clouddns/src/test/java/org/jclouds/rackspace/clouddns/v1/features/ReverseDNSApiExpectTest.java b/apis/rackspace-clouddns/src/test/java/org/jclouds/rackspace/clouddns/v1/features/ReverseDNSApiExpectTest.java new file mode 100644 index 0000000000..1e5a4aeb1c --- /dev/null +++ b/apis/rackspace-clouddns/src/test/java/org/jclouds/rackspace/clouddns/v1/features/ReverseDNSApiExpectTest.java @@ -0,0 +1,221 @@ +/** + * 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.rackspace.clouddns.v1.features; + +import static javax.ws.rs.HttpMethod.DELETE; +import static javax.ws.rs.HttpMethod.POST; +import static javax.ws.rs.HttpMethod.PUT; +import static javax.ws.rs.core.Response.Status.OK; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertNull; +import static org.testng.Assert.assertTrue; + +import java.net.URI; +import java.util.Date; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import javax.ws.rs.core.HttpHeaders; +import javax.ws.rs.core.MediaType; + +import org.jclouds.http.HttpResponse; +import org.jclouds.rackspace.clouddns.v1.CloudDNSApi; +import org.jclouds.rackspace.clouddns.v1.domain.Job; +import org.jclouds.rackspace.clouddns.v1.domain.Record; +import org.jclouds.rackspace.clouddns.v1.domain.RecordDetail; +import org.jclouds.rackspace.clouddns.v1.internal.BaseCloudDNSApiExpectTest; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; + +/** + * @author Everett Toews + */ +@Test(groups = "unit") +public class ReverseDNSApiExpectTest extends BaseCloudDNSApiExpectTest { + public static final String CLOUD_SERVERS_OPEN_STACK = "cloudServersOpenStack"; + private static final String JCLOUDS_EXAMPLE = "jclouds-example.com"; + private static final URI SERVER_URI = URI.create("https://dfw.servers.api.rackspacecloud.com/v2/123123/servers/f5fb9334-b4f0-49d0-a2cc-57a5772dc7d1"); + + public void testCreateReverseDNSRecord() { + URI endpoint = URI.create("https://dns.api.rackspacecloud.com/v1.0/123123/rdns"); + ReverseDNSApi api = requestsSendResponses( + rackspaceAuthWithUsernameAndApiKey, + responseWithAccess, + authenticatedGET() + .method(POST) + .payload(payloadFromResource("/record-ptr-create.json")) + .endpoint(endpoint) + .build(), + HttpResponse.builder().statusCode(OK.getStatusCode()).payload(payloadFromResource("/record-ptr-create-response.json")).build()) + .getReverseDNSApiForService(CLOUD_SERVERS_OPEN_STACK); + + Record createPTRRecordIPv4 = Record.builder() + .type("PTR") + .name(JCLOUDS_EXAMPLE) + .data("166.78.146.80") + .ttl(11235) + .build(); + + Record createPTRRecordIPv6 = Record.builder() + .type("PTR") + .name(JCLOUDS_EXAMPLE) + .data("2001:4800:7812:0514:9a32:3c2a:ff04:aed2") + .comment("Hello IPv6") + .build(); + + List createRecords = ImmutableList.of(createPTRRecordIPv4, createPTRRecordIPv6); + Job> job = api.create(SERVER_URI, createRecords); + + assertEquals(job.getStatus(), Job.Status.COMPLETED); + assertTrue(job.getResource().isPresent()); + + Set records = job.getResource().get(); + Date now = new Date(); + RecordDetail ptrRecordIPv4 = null; + RecordDetail ptrRecordIPv6 = null; + + for (RecordDetail record: records) { + if (record.getData().startsWith("166")) { + ptrRecordIPv4 = record; + } else if (record.getData().startsWith("2001")) { + ptrRecordIPv6 = record; + } + } + + assertNotNull(ptrRecordIPv4.getId()); + assertEquals(ptrRecordIPv4.getType(), "PTR"); + assertEquals(ptrRecordIPv4.getName(), JCLOUDS_EXAMPLE); + assertEquals(ptrRecordIPv4.getData(), "166.78.146.80"); + assertEquals(ptrRecordIPv4.getTTL(), 11235); + assertNull(ptrRecordIPv4.getPriority()); + assertNull(ptrRecordIPv4.getComment()); + assertTrue(ptrRecordIPv4.getCreated().before(now)); + assertTrue(ptrRecordIPv4.getUpdated().before(now)); + + assertNotNull(ptrRecordIPv6.getId()); + assertEquals(ptrRecordIPv6.getType(), "PTR"); + assertEquals(ptrRecordIPv6.getName(), JCLOUDS_EXAMPLE); + assertEquals(ptrRecordIPv6.getData(), "2001:4800:7812:514:9a32:3c2a:ff04:aed2"); // leading 0 in 0514 removed + assertTrue(ptrRecordIPv6.getTTL() > 0); + assertNull(ptrRecordIPv6.getPriority()); + assertEquals(ptrRecordIPv6.getComment(), "Hello IPv6"); + assertTrue(ptrRecordIPv6.getCreated().before(now)); + assertTrue(ptrRecordIPv6.getUpdated().before(now)); + } + + public void testListReverseDNSRecords() { + URI endpoint = URI.create("https://dns.api.rackspacecloud.com/v1.0/123123/rdns/cloudServersOpenStack?href=https%3A//dfw.servers.api.rackspacecloud.com/v2/123123/servers/f5fb9334-b4f0-49d0-a2cc-57a5772dc7d1"); + ReverseDNSApi api = requestsSendResponses( + rackspaceAuthWithUsernameAndApiKey, + responseWithAccess, + authenticatedGET().endpoint(endpoint).build(), + HttpResponse.builder().statusCode(OK.getStatusCode()).payload(payloadFromResource("/record-ptr-list.json")).build()) + .getReverseDNSApiForService(CLOUD_SERVERS_OPEN_STACK); + + ImmutableList records = api.list(SERVER_URI).concat().toList(); + assertEquals(records.size(), 2); + + for (RecordDetail record: records) { + assertTrue(record.getType().contains("PTR")); + assertTrue(record.getName().contains(JCLOUDS_EXAMPLE)); + } + } + + public void testGetReverseDNSRecord() { + URI endpoint = URI.create("https://dns.api.rackspacecloud.com/v1.0/123123/rdns/cloudServersOpenStack/PTR-557437?href=https%3A//dfw.servers.api.rackspacecloud.com/v2/123123/servers/f5fb9334-b4f0-49d0-a2cc-57a5772dc7d1"); + ReverseDNSApi api = requestsSendResponses( + rackspaceAuthWithUsernameAndApiKey, + responseWithAccess, + authenticatedGET().endpoint(endpoint).build(), + HttpResponse.builder().statusCode(OK.getStatusCode()).payload(payloadFromResource("/record-ptr-get.json")).build()) + .getReverseDNSApiForService(CLOUD_SERVERS_OPEN_STACK); + + RecordDetail record = api.get(SERVER_URI, "PTR-557437"); + Date now = new Date(); + + assertEquals(record.getId(), "PTR-557437"); + assertEquals(record.getType(), "PTR"); + assertEquals(record.getName(), JCLOUDS_EXAMPLE); + assertEquals(record.getData(), "166.78.146.80"); + assertEquals(record.getTTL(), 11235); + assertNull(record.getPriority()); + assertNull(record.getComment()); + assertTrue(record.getCreated().before(now)); + assertTrue(record.getUpdated().before(now)); + } + + public void testUpdateReverseDNSRecord() { + URI endpoint = URI.create("https://dns.api.rackspacecloud.com/v1.0/123123/rdns"); + ReverseDNSApi api = requestsSendResponses( + rackspaceAuthWithUsernameAndApiKey, + responseWithAccess, + authenticatedGET() + .method(PUT) + .payload(payloadFromResourceWithContentType("/record-ptr-update.json", MediaType.APPLICATION_JSON)) + .endpoint(endpoint) + .build(), + HttpResponse.builder().statusCode(OK.getStatusCode()).payload(payloadFromResource("/record-ptr-update-response.json")).build()) + .getReverseDNSApiForService(CLOUD_SERVERS_OPEN_STACK); + + Record updatePTRRecordIPv4 = Record.builder() + .type("PTR") + .name(JCLOUDS_EXAMPLE) + .data("166.78.146.80") + .ttl(12358) + .build(); + + Map idsToRecords = ImmutableMap. of("PTR-557437", updatePTRRecordIPv4); + + Job job = api.update(SERVER_URI, idsToRecords); + + assertEquals(job.getStatus(), Job.Status.COMPLETED); + } + + public void testDeleteReverseDNSRecord() { + URI endpoint = URI.create("https://dns.api.rackspacecloud.com/v1.0/123123/rdns/cloudServersOpenStack?href=https%3A//dfw.servers.api.rackspacecloud.com/v2/123123/servers/f5fb9334-b4f0-49d0-a2cc-57a5772dc7d1&ip=166.78.146.80"); + ReverseDNSApi api = requestsSendResponses( + rackspaceAuthWithUsernameAndApiKey, + responseWithAccess, + authenticatedGET().method(DELETE).replaceHeader(HttpHeaders.ACCEPT, MediaType.WILDCARD).endpoint(endpoint).build(), + HttpResponse.builder().statusCode(OK.getStatusCode()).payload(payloadFromResource("/record-ptr-delete.json")).build()) + .getReverseDNSApiForService(CLOUD_SERVERS_OPEN_STACK); + + Job job = api.delete(SERVER_URI, "166.78.146.80"); + + assertEquals(job.getStatus(), Job.Status.COMPLETED); + } + + public void testDeleteReverseDNSRecords() { + URI endpoint = URI.create("https://dns.api.rackspacecloud.com/v1.0/123123/rdns/cloudServersOpenStack?href=https%3A//dfw.servers.api.rackspacecloud.com/v2/123123/servers/f5fb9334-b4f0-49d0-a2cc-57a5772dc7d1"); + ReverseDNSApi api = requestsSendResponses( + rackspaceAuthWithUsernameAndApiKey, + responseWithAccess, + authenticatedGET().method(DELETE).replaceHeader("Accept", MediaType.WILDCARD).endpoint(endpoint).build(), + HttpResponse.builder().statusCode(OK.getStatusCode()).payload(payloadFromResource("/records-ptr-delete.json")).build()) + .getReverseDNSApiForService(CLOUD_SERVERS_OPEN_STACK); + + Job job = api.deleteAll(SERVER_URI); + + assertEquals(job.getStatus(), Job.Status.COMPLETED); + } +} diff --git a/apis/rackspace-clouddns/src/test/java/org/jclouds/rackspace/clouddns/v1/features/ReverseDNSApiLiveTest.java b/apis/rackspace-clouddns/src/test/java/org/jclouds/rackspace/clouddns/v1/features/ReverseDNSApiLiveTest.java new file mode 100644 index 0000000000..c8291743f1 --- /dev/null +++ b/apis/rackspace-clouddns/src/test/java/org/jclouds/rackspace/clouddns/v1/features/ReverseDNSApiLiveTest.java @@ -0,0 +1,227 @@ +/** + * 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.rackspace.clouddns.v1.features; + +import static org.jclouds.rackspace.clouddns.v1.features.ReverseDNSApiExpectTest.CLOUD_SERVERS_OPEN_STACK; +import static org.jclouds.rackspace.clouddns.v1.predicates.JobPredicates.awaitComplete; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertNull; +import static org.testng.Assert.assertTrue; + +import java.net.URI; +import java.util.Date; +import java.util.List; +import java.util.Map; +import java.util.Properties; +import java.util.Set; +import java.util.concurrent.TimeoutException; + +import org.jclouds.ContextBuilder; +import org.jclouds.compute.ComputeService; +import org.jclouds.compute.ComputeServiceContext; +import org.jclouds.compute.config.ComputeServiceProperties; +import org.jclouds.compute.domain.NodeMetadata; +import org.jclouds.compute.domain.Template; +import org.jclouds.openstack.nova.v2_0.NovaApi; +import org.jclouds.openstack.nova.v2_0.NovaAsyncApi; +import org.jclouds.openstack.nova.v2_0.domain.Server; +import org.jclouds.openstack.nova.v2_0.features.ServerApi; +import org.jclouds.rackspace.clouddns.v1.domain.CreateDomain; +import org.jclouds.rackspace.clouddns.v1.domain.Domain; +import org.jclouds.rackspace.clouddns.v1.domain.Record; +import org.jclouds.rackspace.clouddns.v1.domain.RecordDetail; +import org.jclouds.rackspace.clouddns.v1.internal.BaseCloudDNSApiLiveTest; +import org.jclouds.rest.RestContext; +import org.testng.annotations.AfterClass; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; + +/** + * @author Everett Toews + */ +@Test(groups = "live", singleThreaded = true, testName = "ReverseDNSApiLiveTest") +public class ReverseDNSApiLiveTest extends BaseCloudDNSApiLiveTest { + + // just in case the username has a '.' we replace it to avoid creating subdomains + private static final String JCLOUDS_EXAMPLE = System.getProperty("user.name").replace('.', '-') + + "-recordtest-jclouds.org"; + + private ComputeService computeService; + private RestContext nova; + private String serverId; + private URI serverURI; + private String serverIPv4; + private String serverIPv6; + + private int domainId; + private String ptrRecordIPv4Id; + private String ptrRecordIPv6Id; + + @Test + public void testCreateServer() throws Exception { + Properties overrides = new Properties(); + overrides.setProperty(ComputeServiceProperties.POLL_INITIAL_PERIOD, "10000"); + overrides.setProperty(ComputeServiceProperties.POLL_MAX_PERIOD, "10000"); + + ComputeServiceContext context = ContextBuilder.newBuilder("rackspace-cloudservers-us") + .credentials(identity, credential) + .overrides(overrides) + .buildView(ComputeServiceContext.class); + computeService = context.getComputeService(); + nova = context.unwrap(); + + Template template = computeService.templateBuilder().smallest().build(); + NodeMetadata nodeMetadata = computeService.createNodesInGroup("jclouds-reverse-dns-test", 1, template).iterator().next(); + serverId = nodeMetadata.getId(); + serverURI = nodeMetadata.getUri(); + + ServerApi serverApi = nova.getApi().getServerApiForZone(nodeMetadata.getLocation().getParent().getId()); + Server server = serverApi.get(nodeMetadata.getProviderId()); + serverIPv4 = server.getAccessIPv4(); + serverIPv6 = server.getAccessIPv6(); + + System.out.println("serverURI = " + serverURI); + System.out.println("serverIPv4 = " + serverIPv4); + System.out.println("serverIPv6 = " + serverIPv6); + } + + @Test(dependsOnMethods = "testCreateServer") + public void testCreateDomain() throws Exception { + CreateDomain createDomain = CreateDomain.builder().name(JCLOUDS_EXAMPLE).email("jclouds@" + JCLOUDS_EXAMPLE) + .ttl(60000).build(); + + Iterable createDomains = ImmutableList.of(createDomain); + Domain domain = awaitComplete(api, api.getDomainApi().create(createDomains)).iterator().next(); + + assertEquals(domain.getName(), JCLOUDS_EXAMPLE); + assertEquals(domain.getEmail(), "jclouds@" + JCLOUDS_EXAMPLE); + assertTrue(domain.getRecords().isEmpty()); + + domainId = domain.getId(); + } + + @Test(dependsOnMethods = "testCreateDomain") + public void testCreateReverseDNSRecords() throws Exception { + Record createPTRRecordIPv4 = Record.builder().type("PTR").name(JCLOUDS_EXAMPLE).data(serverIPv4).ttl(11235) + .build(); + + Record createPTRRecordIPv6 = Record.builder().type("PTR").name(JCLOUDS_EXAMPLE).data(serverIPv6) + .comment("Hello IPv6").build(); + + List createRecords = ImmutableList.of(createPTRRecordIPv4, createPTRRecordIPv6); + Set records = awaitComplete(api, + api.getReverseDNSApiForService(CLOUD_SERVERS_OPEN_STACK).create(serverURI, createRecords)); + + Date now = new Date(); + RecordDetail ptrRecordIPv4 = null; + RecordDetail ptrRecordIPv6 = null; + + for (RecordDetail record: records) { + if (record.getData().equals(serverIPv4)) { + ptrRecordIPv4 = record; + ptrRecordIPv4Id = record.getId(); + } + else { + ptrRecordIPv6 = record; + ptrRecordIPv6Id = record.getId(); + } + } + + assertNotNull(ptrRecordIPv4.getId()); + assertEquals(ptrRecordIPv4.getType(), "PTR"); + assertEquals(ptrRecordIPv4.getName(), JCLOUDS_EXAMPLE); + assertEquals(ptrRecordIPv4.getData(), serverIPv4); + assertEquals(ptrRecordIPv4.getTTL(), 11235); + assertNull(ptrRecordIPv4.getPriority()); + assertNull(ptrRecordIPv4.getComment()); + assertTrue(ptrRecordIPv4.getCreated().before(now)); + assertTrue(ptrRecordIPv4.getUpdated().before(now)); + + assertNotNull(ptrRecordIPv6.getId()); + assertEquals(ptrRecordIPv6.getType(), "PTR"); + assertEquals(ptrRecordIPv6.getName(), JCLOUDS_EXAMPLE); + // can't test equals for data as CDNS will remove leading 0s from IPv6 Addrs + assertNotNull(ptrRecordIPv6.getData()); + assertTrue(ptrRecordIPv6.getTTL() > 0); + assertNull(ptrRecordIPv6.getPriority()); + assertEquals(ptrRecordIPv6.getComment(), "Hello IPv6"); + assertTrue(ptrRecordIPv6.getCreated().before(now)); + assertTrue(ptrRecordIPv6.getUpdated().before(now)); + } + + @Test(dependsOnMethods = "testCreateReverseDNSRecords") + public void testListReverseDNSRecords() throws Exception { + Set records = api.getReverseDNSApiForService(CLOUD_SERVERS_OPEN_STACK).list(serverURI).concat() + .toSet(); + assertEquals(records.size(), 2); + } + + @Test(dependsOnMethods = "testListReverseDNSRecords") + public void testUpdateAndGetReverseDNSRecords() throws Exception { + Record updatePTRRecordIPv4 = Record.builder().type("PTR").name(JCLOUDS_EXAMPLE).data(serverIPv4).ttl(12358) + .build(); + + Map idsToRecords = ImmutableMap. of(ptrRecordIPv4Id, updatePTRRecordIPv4); + + awaitComplete(api, api.getReverseDNSApiForService(CLOUD_SERVERS_OPEN_STACK).update(serverURI, idsToRecords)); + + RecordDetail record = api.getReverseDNSApiForService(CLOUD_SERVERS_OPEN_STACK).get(serverURI, ptrRecordIPv4Id); + Date now = new Date(); + + assertNotNull(record.getId()); + assertEquals(record.getType(), "PTR"); + assertEquals(record.getName(), JCLOUDS_EXAMPLE); + assertEquals(record.getData(), serverIPv4); + assertEquals(record.getTTL(), 12358); + assertNull(record.getPriority()); + assertNull(record.getComment()); + assertTrue(record.getCreated().before(now)); + assertTrue(record.getUpdated().before(now)); + } + + @Test(dependsOnMethods = "testUpdateAndGetReverseDNSRecords") + public void testDeleteReverseDNSRecord() throws Exception { + awaitComplete(api, api.getReverseDNSApiForService(CLOUD_SERVERS_OPEN_STACK).delete(serverURI, serverIPv4)); + + assertNull(api.getReverseDNSApiForService(CLOUD_SERVERS_OPEN_STACK).get(serverURI, ptrRecordIPv4Id)); + } + + @Test(dependsOnMethods = "testUpdateAndGetReverseDNSRecords") + public void testDeleteReverseDNSRecords() throws Exception { + awaitComplete(api, api.getReverseDNSApiForService(CLOUD_SERVERS_OPEN_STACK).deleteAll(serverURI)); + + assertNull(api.getReverseDNSApiForService(CLOUD_SERVERS_OPEN_STACK).get(serverURI, ptrRecordIPv6Id)); + } + + @Override + @AfterClass(groups = { "integration", "live" }) + protected void tearDown() { + try { + computeService.destroyNode(serverId); + awaitComplete(api, api.getDomainApi().delete(ImmutableList. of(domainId), true)); + } + catch (TimeoutException e) { + e.printStackTrace(); + } + super.tearDown(); + } +} diff --git a/apis/rackspace-clouddns/src/test/java/org/jclouds/rackspace/clouddns/v1/internal/BaseCloudDNSApiExpectTest.java b/apis/rackspace-clouddns/src/test/java/org/jclouds/rackspace/clouddns/v1/internal/BaseCloudDNSApiExpectTest.java new file mode 100644 index 0000000000..6d02a4706c --- /dev/null +++ b/apis/rackspace-clouddns/src/test/java/org/jclouds/rackspace/clouddns/v1/internal/BaseCloudDNSApiExpectTest.java @@ -0,0 +1,58 @@ +/** + * 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.rackspace.clouddns.v1.internal; + +import javax.ws.rs.core.MediaType; + +import org.jclouds.http.HttpRequest; +import org.jclouds.http.HttpResponse; +import org.jclouds.rackspace.cloudidentity.v2_0.internal.RackspaceFixture; +import org.jclouds.rest.internal.BaseRestApiExpectTest; + +/** + * @author Everett Toews + */ +public class BaseCloudDNSApiExpectTest extends BaseRestApiExpectTest { + protected HttpRequest rackspaceAuthWithUsernameAndApiKey; + + protected String authToken; + protected HttpResponse responseWithAccess; + + public BaseCloudDNSApiExpectTest() { + provider = "rackspace-clouddns"; + + rackspaceAuthWithUsernameAndApiKey = RackspaceFixture.INSTANCE + .initialAuthWithUsernameAndApiKey(identity, credential); + + authToken = RackspaceFixture.INSTANCE.getAuthToken(); + responseWithAccess = RackspaceFixture.INSTANCE.responseWithAccess(); + } + + @Override + protected HttpRequestComparisonType compareHttpRequestAsType(HttpRequest input) { + return HttpRequestComparisonType.JSON; + } + + protected HttpRequest.Builder authenticatedGET() { + return HttpRequest.builder() + .method("GET") + .addHeader("Accept", MediaType.APPLICATION_JSON) + .addHeader("X-Auth-Token", authToken); + } +} diff --git a/apis/rackspace-clouddns/src/test/java/org/jclouds/rackspace/clouddns/v1/internal/BaseCloudDNSApiLiveTest.java b/apis/rackspace-clouddns/src/test/java/org/jclouds/rackspace/clouddns/v1/internal/BaseCloudDNSApiLiveTest.java new file mode 100644 index 0000000000..62c972f0b6 --- /dev/null +++ b/apis/rackspace-clouddns/src/test/java/org/jclouds/rackspace/clouddns/v1/internal/BaseCloudDNSApiLiveTest.java @@ -0,0 +1,42 @@ +/** + * 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.rackspace.clouddns.v1.internal; + +import java.util.Properties; + +import org.jclouds.apis.BaseApiLiveTest; +import org.jclouds.openstack.keystone.v2_0.config.KeystoneProperties; +import org.jclouds.rackspace.clouddns.v1.CloudDNSApi; + +/** + * @author Everett Toews + */ +public class BaseCloudDNSApiLiveTest extends BaseApiLiveTest { + + public BaseCloudDNSApiLiveTest() { + provider = "rackspace-clouddns"; + } + + @Override + protected Properties setupProperties() { + Properties props = super.setupProperties(); + setIfTestSystemPropertyPresent(props, KeystoneProperties.CREDENTIAL_TYPE); + return props; + } +} diff --git a/apis/rackspace-clouddns/src/test/resources/domain-create-response.json b/apis/rackspace-clouddns/src/test/resources/domain-create-response.json new file mode 100644 index 0000000000..b5cd1c7bf3 --- /dev/null +++ b/apis/rackspace-clouddns/src/test/resources/domain-create-response.json @@ -0,0 +1,111 @@ +{ + "request": "{\"domains\":[{\"name\":\"jclouds-example.com\",\"emailAddress\":\"jclouds@jclouds-example.com\",\"ttl\":600000,\"comment\":\"Hello Domain\",\"subdomains\":{\"domains\":[{\"name\":\"dev.jclouds-example.com\",\"emailAddress\":\"jclouds@jclouds-example.com\",\"comment\":\"Hello dev subdomain\"},{\"name\":\"test.jclouds-example.com\",\"emailAddress\":\"jclouds@jclouds-example.com\",\"comment\":\"Hello test subdomain\"}]},\"recordsList\":{\"records\":[{\"name\":\"jclouds-example.com\",\"type\":\"MX\",\"data\":\"mail.jclouds-example.com\",\"priority\":11235},{\"name\":\"jclouds-example.com\",\"type\":\"A\",\"data\":\"10.0.0.1\"}]}},{\"name\":\"xjclouds-example.com\",\"emailAddress\":\"jclouds@jclouds-example.com\",\"ttl\":600000,\"comment\":\"Hello Domain\"}]}", + "response": { + "domains": [ + { + "name": "jclouds-example.com", + "id": 3650906, + "comment": "Hello Domain", + "accountId": 123123, + "ttl": 600000, + "subdomains": { + "domains": [ + { + "name": "dev.jclouds-example.com", + "id": 3650907, + "comment": "Hello dev subdomain", + "accountId": 123123, + "ttl": 3600, + "emailAddress": "jclouds@jclouds-example.com", + "nameservers": [ + { + "name": "dns1.stabletransit.com" + }, + { + "name": "dns2.stabletransit.com" + } + ], + "updated": "2013-03-22T03:04:15.000+0000", + "created": "2013-03-22T03:04:15.000+0000" + }, + { + "name": "test.jclouds-example.com", + "id": 3650908, + "comment": "Hello test subdomain", + "accountId": 123123, + "ttl": 3600, + "emailAddress": "jclouds@jclouds-example.com", + "nameservers": [ + { + "name": "dns1.stabletransit.com" + }, + { + "name": "dns2.stabletransit.com" + } + ], + "updated": "2013-03-22T03:04:15.000+0000", + "created": "2013-03-22T03:04:15.000+0000" + } + ] + }, + "recordsList": { + "records": [ + { + "name": "jclouds-example.com", + "id": "MX-4328817", + "priority": 11235, + "type": "MX", + "data": "mail.jclouds-example.com", + "ttl": 600000, + "updated": "2013-03-22T03:04:13.000+0000", + "created": "2013-03-22T03:04:13.000+0000" + }, + { + "name": "jclouds-example.com", + "id": "A-9785208", + "type": "A", + "data": "10.0.0.1", + "ttl": 600000, + "updated": "2013-03-22T03:04:14.000+0000", + "created": "2013-03-22T03:04:14.000+0000" + } + ] + }, + "emailAddress": "jclouds@jclouds-example.com", + "nameservers": [ + { + "name": "dns1.stabletransit.com" + }, + { + "name": "dns2.stabletransit.com" + } + ], + "updated": "2013-03-22T03:04:12.000+0000", + "created": "2013-03-22T03:04:12.000+0000" + }, + { + "name": "xjclouds-example.com", + "id": 3650909, + "comment": "Hello Domain", + "accountId": 123123, + "ttl": 600000, + "emailAddress": "jclouds@jclouds-example.com", + "nameservers": [ + { + "name": "dns1.stabletransit.com" + }, + { + "name": "dns2.stabletransit.com" + } + ], + "updated": "2013-03-22T03:04:16.000+0000", + "created": "2013-03-22T03:04:16.000+0000" + } + ] + }, + "status": "COMPLETED", + "verb": "POST", + "jobId": "3f4be747-70b0-40e6-96fe-e445c3e12805", + "callbackUrl": "https://dns.api.rackspacecloud.com/v1.0/123123/status/3f4be747-70b0-40e6-96fe-e445c3e12805", + "requestUrl": "https://dns.api.rackspacecloud.com/v1.0/123123/domains" +} diff --git a/apis/rackspace-clouddns/src/test/resources/domain-create.json b/apis/rackspace-clouddns/src/test/resources/domain-create.json new file mode 100644 index 0000000000..b40a8288e4 --- /dev/null +++ b/apis/rackspace-clouddns/src/test/resources/domain-create.json @@ -0,0 +1 @@ +{"domains":[{"name":"jclouds-example.com","emailAddress":"jclouds@jclouds-example.com","ttl":600000,"comment":"Hello Domain","subdomains":{"domains":[{"name":"dev.jclouds-example.com","emailAddress":"jclouds@jclouds-example.com","comment":"Hello dev subdomain"},{"name":"test.jclouds-example.com","emailAddress":"jclouds@jclouds-example.com","comment":"Hello test subdomain"}]},"recordsList":{"records":[{"name":"jclouds-example.com","type":"MX","data":"mail.jclouds-example.com","priority":11235},{"name":"jclouds-example.com","type":"A","data":"10.0.0.1"}]}},{"name":"xjclouds-example.com","emailAddress":"jclouds@jclouds-example.com","ttl":600000,"comment":"Hello Domain","subdomains":{},"recordsList":{}}]} \ No newline at end of file diff --git a/apis/rackspace-clouddns/src/test/resources/domain-delete.json b/apis/rackspace-clouddns/src/test/resources/domain-delete.json new file mode 100644 index 0000000000..01f5cf69e8 --- /dev/null +++ b/apis/rackspace-clouddns/src/test/resources/domain-delete.json @@ -0,0 +1,7 @@ +{ + "status": "COMPLETED", + "verb": "DELETE", + "jobId": "769cffe7-407c-4146-bab5-3a6c4da3e374", + "callbackUrl": "https://dns.api.rackspacecloud.com/v1.0/123123/status/769cffe7-407c-4146-bab5-3a6c4da3e374", + "requestUrl": "https://dns.api.rackspacecloud.com/v1.0/123123/domainsid=3650909&deleteSubdomains=true" +} diff --git a/apis/rackspace-clouddns/src/test/resources/domain-export.json b/apis/rackspace-clouddns/src/test/resources/domain-export.json new file mode 100644 index 0000000000..fa86ba7a30 --- /dev/null +++ b/apis/rackspace-clouddns/src/test/resources/domain-export.json @@ -0,0 +1,13 @@ +{ + "response": { + "id": 3651323, + "contentType": "BIND_9", + "contents": "jclouds-example.com.\t600000\tIN\tSOA\tns.rackspace.com. jclouds.jclouds-example.com. 1363960242 21600 3600 1814400 500\njclouds-example.com.\t600000\tIN\tA\t10.0.0.1\njclouds-example.com.\t600000\tIN\tNS\tdns1.stabletransit.com.\njclouds-example.com.\t600000\tIN\tNS\tdns2.stabletransit.com.\njclouds-example.com.\t600000\tIN\tMX\t11235 mail.jclouds-example.com.\n", + "accountId": 123123 + }, + "status": "COMPLETED", + "verb": "GET", + "jobId": "526d518b-f1b1-4e25-9e19-9643cb030a1e", + "callbackUrl": "https://dns.api.rackspacecloud.com/v1.0/123123/status/526d518b-f1b1-4e25-9e19-9643cb030a1e", + "requestUrl": "https://dns.api.rackspacecloud.com/v1.0/123123/domains/3651323/export" +} diff --git a/apis/rackspace-clouddns/src/test/resources/domain-get.json b/apis/rackspace-clouddns/src/test/resources/domain-get.json new file mode 100644 index 0000000000..489627ee93 --- /dev/null +++ b/apis/rackspace-clouddns/src/test/resources/domain-get.json @@ -0,0 +1,41 @@ +{ + "name": "test.jclouds-example.com", + "id": 3650908, + "comment": "Hello test subdomain", + "accountId": 123123, + "ttl": 3600, + "recordsList": { + "records": [ + { + "name": "test.jclouds-example.com", + "id": "NS-8646158", + "type": "NS", + "data": "dns1.stabletransit.com", + "ttl": 3600, + "updated": "2013-03-22T03:04:15.000+0000", + "created": "2013-03-22T03:04:15.000+0000" + }, + { + "name": "test.jclouds-example.com", + "id": "NS-8646159", + "type": "NS", + "data": "dns2.stabletransit.com", + "ttl": 3600, + "updated": "2013-03-22T03:04:16.000+0000", + "created": "2013-03-22T03:04:16.000+0000" + } + ], + "totalEntries": 2 + }, + "emailAddress": "jclouds@jclouds-example.com", + "nameservers": [ + { + "name": "dns1.stabletransit.com" + }, + { + "name": "dns2.stabletransit.com" + } + ], + "updated": "2013-03-22T03:04:16.000+0000", + "created": "2013-03-22T03:04:15.000+0000" +} diff --git a/apis/rackspace-clouddns/src/test/resources/domain-import-response.json b/apis/rackspace-clouddns/src/test/resources/domain-import-response.json new file mode 100644 index 0000000000..096ee45221 --- /dev/null +++ b/apis/rackspace-clouddns/src/test/resources/domain-import-response.json @@ -0,0 +1,42 @@ +{ + "request": "{\"domains\":[{\"contentType\":\"BIND_9\",\"contents\":\"jclouds-example.com. 3600 IN SOA ns.rackspace.com. jclouds.jclouds-example.com. 1363882703 3600 3600 3600 3600\\njclouds-example.com. 600 IN A 50.56.174.152\"}]}", + "response": { + "domains": [ + { + "name": "jclouds-example.com", + "id": 3653942, + "accountId": 123123, + "ttl": 3600, + "recordsList": { + "records": [ + { + "name": "jclouds-example.com", + "id": "A-9795196", + "type": "A", + "data": "50.56.174.152", + "ttl": 600, + "updated": "2013-03-25T15:15:09.000+0000", + "created": "2013-03-25T15:15:09.000+0000" + } + ] + }, + "emailAddress": "jclouds@jclouds-example.com", + "nameservers": [ + { + "name": "dns1.stabletransit.com" + }, + { + "name": "dns2.stabletransit.com" + } + ], + "updated": "2013-03-25T15:15:08.000+0000", + "created": "2013-03-25T15:15:08.000+0000" + } + ] + }, + "status": "COMPLETED", + "verb": "POST", + "jobId": "7729a749-7a16-41ee-a081-00ed71dce4bb", + "callbackUrl": "https://dns.api.rackspacecloud.com/v1.0/123123/status/7729a749-7a16-41ee-a081-00ed71dce4bb", + "requestUrl": "https://dns.api.rackspacecloud.com/v1.0/123123/domains/import" +} diff --git a/apis/rackspace-clouddns/src/test/resources/domain-import.json b/apis/rackspace-clouddns/src/test/resources/domain-import.json new file mode 100644 index 0000000000..b98a8c40e4 --- /dev/null +++ b/apis/rackspace-clouddns/src/test/resources/domain-import.json @@ -0,0 +1 @@ +{"domains":[{"contentType":"BIND_9","contents":"jclouds-example.com. 3600 IN SOA ns.rackspace.com. jclouds.jclouds-example.com. 1363882703 3600 3600 3600 3600\njclouds-example.com. 600 IN A 50.56.174.152"}]} \ No newline at end of file diff --git a/apis/rackspace-clouddns/src/test/resources/domain-list-changes.json b/apis/rackspace-clouddns/src/test/resources/domain-list-changes.json new file mode 100644 index 0000000000..9b6eff690b --- /dev/null +++ b/apis/rackspace-clouddns/src/test/resources/domain-list-changes.json @@ -0,0 +1,1010 @@ +{ + "changes": [ + { + "domain": "test.jclouds-example.com", + "action": "update", + "targetType": "Domain", + "accountId": 123123, + "changeDetails": [ + { + "field": "serial_number", + "newValue": "1363921456", + "originalValue": "1363921455" + }, + { + "field": "updated_at", + "newValue": "Fri Mar 22 03:04:16 UTC 2013", + "originalValue": "Fri Mar 22 03:04:15 UTC 2013" + } + ], + "targetId": 3650908 + }, + { + "domain": "test.jclouds-example.com", + "action": "create", + "targetType": "NS Record", + "changeDetails": [ + { + "field": "created_at", + "newValue": "Fri Mar 22 03:04:16 UTC 2013", + "originalValue": "" + }, + { + "field": "fqdn", + "newValue": "test.jclouds-example.com", + "originalValue": "" + }, + { + "field": "ttl", + "newValue": "3600", + "originalValue": "" + }, + { + "field": "updated_at", + "newValue": "Fri Mar 22 03:04:16 UTC 2013", + "originalValue": "" + }, + { + "field": "destination", + "newValue": "dns2.stabletransit.com", + "originalValue": "" + }, + { + "field": "id", + "newValue": "8646159", + "originalValue": "" + }, + { + "field": "zone_id", + "newValue": "3650908", + "originalValue": "" + } + ], + "targetId": 8646159 + }, + { + "domain": "test.jclouds-example.com", + "action": "update", + "targetType": "Domain", + "accountId": 123123, + "targetId": 3650908 + }, + { + "domain": "test.jclouds-example.com", + "action": "create", + "targetType": "NS Record", + "changeDetails": [ + { + "field": "created_at", + "newValue": "Fri Mar 22 03:04:15 UTC 2013", + "originalValue": "" + }, + { + "field": "fqdn", + "newValue": "test.jclouds-example.com", + "originalValue": "" + }, + { + "field": "ttl", + "newValue": "3600", + "originalValue": "" + }, + { + "field": "updated_at", + "newValue": "Fri Mar 22 03:04:15 UTC 2013", + "originalValue": "" + }, + { + "field": "destination", + "newValue": "dns1.stabletransit.com", + "originalValue": "" + }, + { + "field": "id", + "newValue": "8646158", + "originalValue": "" + }, + { + "field": "zone_id", + "newValue": "3650908", + "originalValue": "" + } + ], + "targetId": 8646158 + }, + { + "domain": "test.jclouds-example.com", + "action": "create", + "targetType": "Domain", + "accountId": 123123, + "changeDetails": [ + { + "field": "serial_number", + "newValue": "1363921455", + "originalValue": "" + }, + { + "field": "comment", + "newValue": "Hello test subdomain", + "originalValue": "" + }, + { + "field": "label", + "newValue": "test.jclouds-example.com", + "originalValue": "" + }, + { + "field": "auth_name_server", + "newValue": "ns.rackspace.com", + "originalValue": "" + }, + { + "field": "created_at", + "newValue": "Fri Mar 22 03:04:15 UTC 2013", + "originalValue": "" + }, + { + "field": "owner_number", + "newValue": "DCO579619", + "originalValue": "" + }, + { + "field": "ttl", + "newValue": "3600", + "originalValue": "" + }, + { + "field": "responsible_email", + "newValue": "jclouds@jclouds-example.com", + "originalValue": "" + }, + { + "field": "updated_at", + "newValue": "Fri Mar 22 03:04:15 UTC 2013", + "originalValue": "" + }, + { + "field": "id", + "newValue": "3650908", + "originalValue": "" + }, + { + "field": "reverse_label", + "newValue": "moc.elpmaxe-sduolcj.tset", + "originalValue": "" + }, + { + "field": "refresh", + "newValue": "3600", + "originalValue": "" + }, + { + "field": "type", + "newValue": "DefaultZone", + "originalValue": "" + }, + { + "field": "minimum_ttl", + "newValue": "3600", + "originalValue": "" + }, + { + "field": "expiry", + "newValue": "3600", + "originalValue": "" + }, + { + "field": "update_retry", + "newValue": "300", + "originalValue": "" + } + ], + "targetId": 3650908 + }, + { + "domain": "test.jclouds-example.com", + "action": "destroy", + "targetType": "Domain", + "accountId": 123123, + "changeDetails": [ + { + "field": "auth_name_server", + "newValue": "", + "originalValue": "ns.rackspace.com" + }, + { + "field": "comment", + "newValue": "", + "originalValue": "Hello test subdomain" + }, + { + "field": "label", + "newValue": "", + "originalValue": "test.jclouds-example.com" + }, + { + "field": "serial_number", + "newValue": "", + "originalValue": "1363920596" + }, + { + "field": "created_at", + "newValue": "", + "originalValue": "Fri Mar 22 02:49:55 UTC 2013" + }, + { + "field": "owner_number", + "newValue": "", + "originalValue": "DCO579619" + }, + { + "field": "responsible_email", + "newValue": "", + "originalValue": "jclouds@jclouds-example.com" + }, + { + "field": "ttl", + "newValue": "", + "originalValue": "3600" + }, + { + "field": "allow_indefinite_ttl_change", + "newValue": "", + "originalValue": "false" + }, + { + "field": "updated_at", + "newValue": "", + "originalValue": "Fri Mar 22 02:49:56 UTC 2013" + }, + { + "field": "id", + "newValue": "", + "originalValue": "3650900" + }, + { + "field": "refresh", + "newValue": "", + "originalValue": "3600" + }, + { + "field": "reverse_label", + "newValue": "", + "originalValue": "moc.elpmaxe-sduolcj.tset" + }, + { + "field": "type", + "newValue": "", + "originalValue": "DefaultZone" + }, + { + "field": "minimum_ttl", + "newValue": "", + "originalValue": "3600" + }, + { + "field": "expiry", + "newValue": "", + "originalValue": "3600" + }, + { + "field": "update_retry", + "newValue": "", + "originalValue": "300" + } + ], + "targetId": 3650900 + }, + { + "domain": "test.jclouds-example.com", + "action": "update", + "targetType": "Domain", + "accountId": 123123, + "targetId": 3650900 + }, + { + "domain": "test.jclouds-example.com", + "action": "destroy", + "targetType": "NS Record", + "changeDetails": [ + { + "field": "created_at", + "newValue": "", + "originalValue": "Fri Mar 22 02:49:56 UTC 2013" + }, + { + "field": "fqdn", + "newValue": "", + "originalValue": "test.jclouds-example.com" + }, + { + "field": "ttl", + "newValue": "", + "originalValue": "3600" + }, + { + "field": "destination", + "newValue": "", + "originalValue": "dns2.stabletransit.com" + }, + { + "field": "updated_at", + "newValue": "", + "originalValue": "Fri Mar 22 02:49:56 UTC 2013" + }, + { + "field": "id", + "newValue": "", + "originalValue": "8646143" + }, + { + "field": "zone_id", + "newValue": "", + "originalValue": "3650900" + } + ], + "targetId": 8646143 + }, + { + "domain": "test.jclouds-example.com", + "action": "update", + "targetType": "Domain", + "accountId": 123123, + "changeDetails": [ + { + "field": "serial_number", + "newValue": "1363921396", + "originalValue": "1363920596" + }, + { + "field": "updated_at", + "newValue": "Fri Mar 22 03:03:16 UTC 2013", + "originalValue": "Fri Mar 22 02:49:56 UTC 2013" + } + ], + "targetId": 3650900 + }, + { + "domain": "test.jclouds-example.com", + "action": "destroy", + "targetType": "NS Record", + "changeDetails": [ + { + "field": "created_at", + "newValue": "", + "originalValue": "Fri Mar 22 02:49:56 UTC 2013" + }, + { + "field": "fqdn", + "newValue": "", + "originalValue": "test.jclouds-example.com" + }, + { + "field": "ttl", + "newValue": "", + "originalValue": "3600" + }, + { + "field": "destination", + "newValue": "", + "originalValue": "dns1.stabletransit.com" + }, + { + "field": "updated_at", + "newValue": "", + "originalValue": "Fri Mar 22 02:49:56 UTC 2013" + }, + { + "field": "id", + "newValue": "", + "originalValue": "8646141" + }, + { + "field": "zone_id", + "newValue": "", + "originalValue": "3650900" + } + ], + "targetId": 8646141 + }, + { + "domain": "test.jclouds-example.com", + "action": "update", + "targetType": "Domain", + "accountId": 123123, + "targetId": 3650900 + }, + { + "domain": "test.jclouds-example.com", + "action": "create", + "targetType": "NS Record", + "changeDetails": [ + { + "field": "created_at", + "newValue": "Fri Mar 22 02:49:56 UTC 2013", + "originalValue": "" + }, + { + "field": "fqdn", + "newValue": "test.jclouds-example.com", + "originalValue": "" + }, + { + "field": "ttl", + "newValue": "3600", + "originalValue": "" + }, + { + "field": "updated_at", + "newValue": "Fri Mar 22 02:49:56 UTC 2013", + "originalValue": "" + }, + { + "field": "destination", + "newValue": "dns2.stabletransit.com", + "originalValue": "" + }, + { + "field": "id", + "newValue": "8646143", + "originalValue": "" + }, + { + "field": "zone_id", + "newValue": "3650900", + "originalValue": "" + } + ], + "targetId": 8646143 + }, + { + "domain": "test.jclouds-example.com", + "action": "update", + "targetType": "Domain", + "accountId": 123123, + "changeDetails": [ + { + "field": "serial_number", + "newValue": "1363920596", + "originalValue": "1363920595" + }, + { + "field": "updated_at", + "newValue": "Fri Mar 22 02:49:56 UTC 2013", + "originalValue": "Fri Mar 22 02:49:55 UTC 2013" + } + ], + "targetId": 3650900 + }, + { + "domain": "test.jclouds-example.com", + "action": "create", + "targetType": "NS Record", + "changeDetails": [ + { + "field": "created_at", + "newValue": "Fri Mar 22 02:49:56 UTC 2013", + "originalValue": "" + }, + { + "field": "fqdn", + "newValue": "test.jclouds-example.com", + "originalValue": "" + }, + { + "field": "ttl", + "newValue": "3600", + "originalValue": "" + }, + { + "field": "updated_at", + "newValue": "Fri Mar 22 02:49:56 UTC 2013", + "originalValue": "" + }, + { + "field": "destination", + "newValue": "dns1.stabletransit.com", + "originalValue": "" + }, + { + "field": "id", + "newValue": "8646141", + "originalValue": "" + }, + { + "field": "zone_id", + "newValue": "3650900", + "originalValue": "" + } + ], + "targetId": 8646141 + }, + { + "domain": "test.jclouds-example.com", + "action": "create", + "targetType": "Domain", + "accountId": 123123, + "changeDetails": [ + { + "field": "serial_number", + "newValue": "1363920595", + "originalValue": "" + }, + { + "field": "comment", + "newValue": "Hello test subdomain", + "originalValue": "" + }, + { + "field": "label", + "newValue": "test.jclouds-example.com", + "originalValue": "" + }, + { + "field": "auth_name_server", + "newValue": "ns.rackspace.com", + "originalValue": "" + }, + { + "field": "created_at", + "newValue": "Fri Mar 22 02:49:55 UTC 2013", + "originalValue": "" + }, + { + "field": "owner_number", + "newValue": "DCO579619", + "originalValue": "" + }, + { + "field": "ttl", + "newValue": "3600", + "originalValue": "" + }, + { + "field": "responsible_email", + "newValue": "jclouds@jclouds-example.com", + "originalValue": "" + }, + { + "field": "updated_at", + "newValue": "Fri Mar 22 02:49:55 UTC 2013", + "originalValue": "" + }, + { + "field": "id", + "newValue": "3650900", + "originalValue": "" + }, + { + "field": "reverse_label", + "newValue": "moc.elpmaxe-sduolcj.tset", + "originalValue": "" + }, + { + "field": "refresh", + "newValue": "3600", + "originalValue": "" + }, + { + "field": "type", + "newValue": "DefaultZone", + "originalValue": "" + }, + { + "field": "minimum_ttl", + "newValue": "3600", + "originalValue": "" + }, + { + "field": "expiry", + "newValue": "3600", + "originalValue": "" + }, + { + "field": "update_retry", + "newValue": "300", + "originalValue": "" + } + ], + "targetId": 3650900 + }, + { + "domain": "test.jclouds-example.com", + "action": "destroy", + "targetType": "Domain", + "accountId": 123123, + "changeDetails": [ + { + "field": "auth_name_server", + "newValue": "", + "originalValue": "ns.rackspace.com" + }, + { + "field": "comment", + "newValue": "", + "originalValue": "Hello test subdomain" + }, + { + "field": "label", + "newValue": "", + "originalValue": "test.jclouds-example.com" + }, + { + "field": "serial_number", + "newValue": "", + "originalValue": "1363919226" + }, + { + "field": "created_at", + "newValue": "", + "originalValue": "Fri Mar 22 02:27:06 UTC 2013" + }, + { + "field": "owner_number", + "newValue": "", + "originalValue": "DCO579619" + }, + { + "field": "responsible_email", + "newValue": "", + "originalValue": "jclouds@jclouds-example.com" + }, + { + "field": "ttl", + "newValue": "", + "originalValue": "3600" + }, + { + "field": "allow_indefinite_ttl_change", + "newValue": "", + "originalValue": "false" + }, + { + "field": "updated_at", + "newValue": "", + "originalValue": "Fri Mar 22 02:27:06 UTC 2013" + }, + { + "field": "id", + "newValue": "", + "originalValue": "3650882" + }, + { + "field": "refresh", + "newValue": "", + "originalValue": "3600" + }, + { + "field": "reverse_label", + "newValue": "", + "originalValue": "moc.elpmaxe-sduolcj.tset" + }, + { + "field": "type", + "newValue": "", + "originalValue": "DefaultZone" + }, + { + "field": "minimum_ttl", + "newValue": "", + "originalValue": "3600" + }, + { + "field": "expiry", + "newValue": "", + "originalValue": "3600" + }, + { + "field": "update_retry", + "newValue": "", + "originalValue": "300" + } + ], + "targetId": 3650882 + }, + { + "domain": "test.jclouds-example.com", + "action": "update", + "targetType": "Domain", + "accountId": 123123, + "targetId": 3650882 + }, + { + "domain": "test.jclouds-example.com", + "action": "destroy", + "targetType": "NS Record", + "changeDetails": [ + { + "field": "created_at", + "newValue": "", + "originalValue": "Fri Mar 22 02:27:06 UTC 2013" + }, + { + "field": "fqdn", + "newValue": "", + "originalValue": "test.jclouds-example.com" + }, + { + "field": "ttl", + "newValue": "", + "originalValue": "3600" + }, + { + "field": "destination", + "newValue": "", + "originalValue": "dns2.stabletransit.com" + }, + { + "field": "updated_at", + "newValue": "", + "originalValue": "Fri Mar 22 02:27:06 UTC 2013" + }, + { + "field": "id", + "newValue": "", + "originalValue": "8646106" + }, + { + "field": "zone_id", + "newValue": "", + "originalValue": "3650882" + } + ], + "targetId": 8646106 + }, + { + "domain": "test.jclouds-example.com", + "action": "update", + "targetType": "Domain", + "accountId": 123123, + "changeDetails": [ + { + "field": "serial_number", + "newValue": "1363920514", + "originalValue": "1363919226" + }, + { + "field": "updated_at", + "newValue": "Fri Mar 22 02:48:34 UTC 2013", + "originalValue": "Fri Mar 22 02:27:06 UTC 2013" + } + ], + "targetId": 3650882 + }, + { + "domain": "test.jclouds-example.com", + "action": "destroy", + "targetType": "NS Record", + "changeDetails": [ + { + "field": "created_at", + "newValue": "", + "originalValue": "Fri Mar 22 02:27:06 UTC 2013" + }, + { + "field": "fqdn", + "newValue": "", + "originalValue": "test.jclouds-example.com" + }, + { + "field": "ttl", + "newValue": "", + "originalValue": "3600" + }, + { + "field": "destination", + "newValue": "", + "originalValue": "dns1.stabletransit.com" + }, + { + "field": "updated_at", + "newValue": "", + "originalValue": "Fri Mar 22 02:27:06 UTC 2013" + }, + { + "field": "id", + "newValue": "", + "originalValue": "8646105" + }, + { + "field": "zone_id", + "newValue": "", + "originalValue": "3650882" + } + ], + "targetId": 8646105 + }, + { + "domain": "test.jclouds-example.com", + "action": "update", + "targetType": "Domain", + "accountId": 123123, + "targetId": 3650882 + }, + { + "domain": "test.jclouds-example.com", + "action": "create", + "targetType": "NS Record", + "changeDetails": [ + { + "field": "created_at", + "newValue": "Fri Mar 22 02:27:06 UTC 2013", + "originalValue": "" + }, + { + "field": "fqdn", + "newValue": "test.jclouds-example.com", + "originalValue": "" + }, + { + "field": "ttl", + "newValue": "3600", + "originalValue": "" + }, + { + "field": "updated_at", + "newValue": "Fri Mar 22 02:27:06 UTC 2013", + "originalValue": "" + }, + { + "field": "destination", + "newValue": "dns2.stabletransit.com", + "originalValue": "" + }, + { + "field": "id", + "newValue": "8646106", + "originalValue": "" + }, + { + "field": "zone_id", + "newValue": "3650882", + "originalValue": "" + } + ], + "targetId": 8646106 + }, + { + "domain": "test.jclouds-example.com", + "action": "update", + "targetType": "Domain", + "accountId": 123123, + "targetId": 3650882 + }, + { + "domain": "test.jclouds-example.com", + "action": "create", + "targetType": "NS Record", + "changeDetails": [ + { + "field": "created_at", + "newValue": "Fri Mar 22 02:27:06 UTC 2013", + "originalValue": "" + }, + { + "field": "fqdn", + "newValue": "test.jclouds-example.com", + "originalValue": "" + }, + { + "field": "ttl", + "newValue": "3600", + "originalValue": "" + }, + { + "field": "updated_at", + "newValue": "Fri Mar 22 02:27:06 UTC 2013", + "originalValue": "" + }, + { + "field": "destination", + "newValue": "dns1.stabletransit.com", + "originalValue": "" + }, + { + "field": "id", + "newValue": "8646105", + "originalValue": "" + }, + { + "field": "zone_id", + "newValue": "3650882", + "originalValue": "" + } + ], + "targetId": 8646105 + }, + { + "domain": "test.jclouds-example.com", + "action": "create", + "targetType": "Domain", + "accountId": 123123, + "changeDetails": [ + { + "field": "serial_number", + "newValue": "1363919226", + "originalValue": "" + }, + { + "field": "comment", + "newValue": "Hello test subdomain", + "originalValue": "" + }, + { + "field": "label", + "newValue": "test.jclouds-example.com", + "originalValue": "" + }, + { + "field": "auth_name_server", + "newValue": "ns.rackspace.com", + "originalValue": "" + }, + { + "field": "created_at", + "newValue": "Fri Mar 22 02:27:06 UTC 2013", + "originalValue": "" + }, + { + "field": "owner_number", + "newValue": "DCO579619", + "originalValue": "" + }, + { + "field": "ttl", + "newValue": "3600", + "originalValue": "" + }, + { + "field": "responsible_email", + "newValue": "jclouds@jclouds-example.com", + "originalValue": "" + }, + { + "field": "updated_at", + "newValue": "Fri Mar 22 02:27:06 UTC 2013", + "originalValue": "" + }, + { + "field": "id", + "newValue": "3650882", + "originalValue": "" + }, + { + "field": "reverse_label", + "newValue": "moc.elpmaxe-sduolcj.tset", + "originalValue": "" + }, + { + "field": "refresh", + "newValue": "3600", + "originalValue": "" + }, + { + "field": "type", + "newValue": "DefaultZone", + "originalValue": "" + }, + { + "field": "minimum_ttl", + "newValue": "3600", + "originalValue": "" + }, + { + "field": "expiry", + "newValue": "3600", + "originalValue": "" + }, + { + "field": "update_retry", + "newValue": "300", + "originalValue": "" + } + ], + "targetId": 3650882 + } + ], + "from": "2013-03-22T00:00:00.000+0000", + "to": "2013-03-22T03:22:47.000+0000", + "totalEntries": 25 +} diff --git a/apis/rackspace-clouddns/src/test/resources/domain-list-with-filter.json b/apis/rackspace-clouddns/src/test/resources/domain-list-with-filter.json new file mode 100644 index 0000000000..36a9690039 --- /dev/null +++ b/apis/rackspace-clouddns/src/test/resources/domain-list-with-filter.json @@ -0,0 +1,13 @@ +{ + "domains": [ + { + "name": "test.jclouds-example.com", + "id": 3650908, + "comment": "Hello test subdomain", + "emailAddress": "jclouds@jclouds-example.com", + "updated": "2013-03-22T03:04:16.000+0000", + "created": "2013-03-22T03:04:15.000+0000" + } + ], + "totalEntries": 1 +} \ No newline at end of file diff --git a/apis/rackspace-clouddns/src/test/resources/domain-list.json b/apis/rackspace-clouddns/src/test/resources/domain-list.json new file mode 100644 index 0000000000..304bc888ef --- /dev/null +++ b/apis/rackspace-clouddns/src/test/resources/domain-list.json @@ -0,0 +1,41 @@ +{ + "domains": [ + { + "name": "dev.jclouds-example.com", + "id": 3650907, + "comment": "Hello dev subdomain", + "accountId": 123123, + "emailAddress": "jclouds@jclouds-example.com", + "updated": "2013-03-22T03:04:15.000+0000", + "created": "2013-03-22T03:04:15.000+0000" + }, + { + "name": "jclouds-example.com", + "id": 3650906, + "comment": "Hello Domain", + "accountId": 123123, + "emailAddress": "jclouds@jclouds-example.com", + "updated": "2013-03-22T03:04:14.000+0000", + "created": "2013-03-22T03:04:12.000+0000" + }, + { + "name": "test.jclouds-example.com", + "id": 3650908, + "comment": "Hello test subdomain", + "accountId": 123123, + "emailAddress": "jclouds@jclouds-example.com", + "updated": "2013-03-22T03:04:16.000+0000", + "created": "2013-03-22T03:04:15.000+0000" + }, + { + "name": "xjclouds-example.com", + "id": 3650909, + "comment": "Hello Domain", + "accountId": 123123, + "emailAddress": "jclouds@jclouds-example.com", + "updated": "2013-03-22T03:04:16.000+0000", + "created": "2013-03-22T03:04:16.000+0000" + } + ], + "totalEntries": 4 +} diff --git a/apis/rackspace-clouddns/src/test/resources/domain-update-email.json b/apis/rackspace-clouddns/src/test/resources/domain-update-email.json new file mode 100644 index 0000000000..d568260265 --- /dev/null +++ b/apis/rackspace-clouddns/src/test/resources/domain-update-email.json @@ -0,0 +1 @@ +{"domains":[{"id":3650906,"emailAddress":"everett@jclouds-example.com"},{"id":3650908,"emailAddress":"everett@jclouds-example.com"}]} \ No newline at end of file diff --git a/apis/rackspace-clouddns/src/test/resources/domain-update-response.json b/apis/rackspace-clouddns/src/test/resources/domain-update-response.json new file mode 100644 index 0000000000..b959cfabf2 --- /dev/null +++ b/apis/rackspace-clouddns/src/test/resources/domain-update-response.json @@ -0,0 +1,8 @@ +{ + "request": "{\"domains\":[{\"id\":3650906,\"emailAddress\":\"everett@jclouds-example.com\",\"ttl\":600001,\"comment\":\"Hello Domain Update\"},{\"id\":3650908,\"emailAddress\":\"everett@jclouds-example.com\",\"ttl\":600002,\"comment\":\"Hello Domain Update\"}]}", + "status": "COMPLETED", + "verb": "PUT", + "jobId": "b7fca312-abb5-4e23-91b4-8a21599f0403", + "callbackUrl": "https://dns.api.rackspacecloud.com/v1.0/123123/status/b7fca312-abb5-4e23-91b4-8a21599f0403", + "requestUrl": "https://dns.api.rackspacecloud.com/v1.0/123123/domains" +} diff --git a/apis/rackspace-clouddns/src/test/resources/domain-update-ttl.json b/apis/rackspace-clouddns/src/test/resources/domain-update-ttl.json new file mode 100644 index 0000000000..8f659fdaa7 --- /dev/null +++ b/apis/rackspace-clouddns/src/test/resources/domain-update-ttl.json @@ -0,0 +1 @@ +{"domains":[{"id":3650906,"ttl":1234567},{"id":3650908,"ttl":1234567}]} \ No newline at end of file diff --git a/apis/rackspace-clouddns/src/test/resources/domain-update.json b/apis/rackspace-clouddns/src/test/resources/domain-update.json new file mode 100644 index 0000000000..1367597acf --- /dev/null +++ b/apis/rackspace-clouddns/src/test/resources/domain-update.json @@ -0,0 +1 @@ +{"ttl":600001,"emailAddress":"everett@jclouds-example.com","comment":"Hello Domain Update"} \ No newline at end of file diff --git a/apis/rackspace-clouddns/src/test/resources/job.json b/apis/rackspace-clouddns/src/test/resources/job.json new file mode 100644 index 0000000000..03119aaa94 --- /dev/null +++ b/apis/rackspace-clouddns/src/test/resources/job.json @@ -0,0 +1,7 @@ +{ + "status": "RUNNING", + "verb": "GET", + "jobId": "bfbd6ec8-5d4c-49f8-97b5-aa5bfd3e95a4", + "callbackUrl": "https://dns.api.rackspacecloud.com/v1.0/123123/status/bfbd6ec8-5d4c-49f8-97b5-aa5bfd3e95a4", + "requestUrl": "https://dns.api.rackspacecloud.com/v1.0/123123/domains/3650883/export" +} diff --git a/apis/rackspace-clouddns/src/test/resources/limit-list.json b/apis/rackspace-clouddns/src/test/resources/limit-list.json new file mode 100644 index 0000000000..27896a3d49 --- /dev/null +++ b/apis/rackspace-clouddns/src/test/resources/limit-list.json @@ -0,0 +1,57 @@ +{ + "limits": { + "absolute": { + "records per domain": 500, + "domains": 500 + }, + "rate": [ + { + "limit": [ + { + "verb": "GET", + "value": 5, + "remaining": 5, + "unit": "SECOND", + "next-available": "2013-03-06T20:11:14.000Z" + } + ], + "uri": "*/status/*", + "regex": ".*/v\\d+\\.\\d+/(\\d+/status).*" + }, + { + "limit": [ + { + "verb": "GET", + "value": 100, + "remaining": 100, + "unit": "MINUTE", + "next-available": "2013-03-06T20:11:14.000Z" + }, + { + "verb": "POST", + "value": 25, + "remaining": 25, + "unit": "MINUTE", + "next-available": "2013-03-06T20:11:14.000Z" + }, + { + "verb": "PUT", + "value": 50, + "remaining": 50, + "unit": "MINUTE", + "next-available": "2013-03-06T20:11:14.000Z" + }, + { + "verb": "DELETE", + "value": 50, + "remaining": 50, + "unit": "MINUTE", + "next-available": "2013-03-06T20:11:14.000Z" + } + ], + "uri": "*/domains*", + "regex": ".*/v\\d+\\.\\d+/(\\d+/domains).*" + } + ] + } +} \ No newline at end of file diff --git a/apis/rackspace-clouddns/src/test/resources/limit-types-list.json b/apis/rackspace-clouddns/src/test/resources/limit-types-list.json new file mode 100644 index 0000000000..8952e2c628 --- /dev/null +++ b/apis/rackspace-clouddns/src/test/resources/limit-types-list.json @@ -0,0 +1,7 @@ +{ + "limitTypes": [ + "RATE_LIMIT", + "DOMAIN_LIMIT", + "DOMAIN_RECORD_LIMIT" + ] +} \ No newline at end of file diff --git a/apis/rackspace-clouddns/src/test/resources/logback.xml b/apis/rackspace-clouddns/src/test/resources/logback.xml new file mode 100644 index 0000000000..9679b2e03a --- /dev/null +++ b/apis/rackspace-clouddns/src/test/resources/logback.xml @@ -0,0 +1,38 @@ + + + + target/test-data/jclouds.log + + + %d %-5p [%c] [%thread] %m%n + + + + + target/test-data/jclouds-wire.log + + + %d %-5p [%c] [%thread] %m%n + + + + + + + + + + + + + + + + + + + + + + + diff --git a/apis/rackspace-clouddns/src/test/resources/record-create-response.json b/apis/rackspace-clouddns/src/test/resources/record-create-response.json new file mode 100644 index 0000000000..4bbb2bee6d --- /dev/null +++ b/apis/rackspace-clouddns/src/test/resources/record-create-response.json @@ -0,0 +1,32 @@ +{ + "request": "{\"records\":[{\"name\":\"jclouds-example.com\",\"type\":\"MX\",\"data\":\"mail.jclouds-example.com\",\"comment\":\"MX Record\",\"priority\":11235},{\"name\":\"jclouds-example.com\",\"type\":\"A\",\"data\":\"10.0.0.1\"}]}", + "response": { + "records": [ + { + "name": "jclouds-example.com", + "id": "MX-4350353", + "priority": 11235, + "type": "MX", + "comment":"MX Record", + "data": "mail.jclouds-example.com", + "ttl": 60000, + "updated": "2013-04-05T19:53:18.000+0000", + "created": "2013-04-05T19:53:18.000+0000" + }, + { + "name": "jclouds-example.com", + "id": "A-9844102", + "type": "A", + "data": "10.0.0.1", + "ttl": 60000, + "updated": "2013-04-05T19:53:19.000+0000", + "created": "2013-04-05T19:53:19.000+0000" + } + ] + }, + "status": "COMPLETED", + "verb": "POST", + "jobId": "290bdc5b-f6fa-4c67-83d7-3b29d2abb8e0", + "callbackUrl": "https://dns.api.rackspacecloud.com/v1.0/123123/status/290bdc5b-f6fa-4c67-83d7-3b29d2abb8e0", + "requestUrl": "https://dns.api.rackspacecloud.com/v1.0/123123/domains/3668461/records" +} diff --git a/apis/rackspace-clouddns/src/test/resources/record-create.json b/apis/rackspace-clouddns/src/test/resources/record-create.json new file mode 100644 index 0000000000..3d03c8d1af --- /dev/null +++ b/apis/rackspace-clouddns/src/test/resources/record-create.json @@ -0,0 +1 @@ +{"records":[{"name":"jclouds-example.com","type":"MX","data":"mail.jclouds-example.com","comment":"MX Record","priority":11235},{"name":"jclouds-example.com","type":"A","data":"10.0.0.1"}]} diff --git a/apis/rackspace-clouddns/src/test/resources/record-delete.json b/apis/rackspace-clouddns/src/test/resources/record-delete.json new file mode 100644 index 0000000000..7b33183754 --- /dev/null +++ b/apis/rackspace-clouddns/src/test/resources/record-delete.json @@ -0,0 +1,7 @@ +{ + "status": "COMPLETED", + "verb": "DELETE", + "jobId": "2a5b0f28-05a1-4003-9cec-470c7602cc02", + "callbackUrl": "https://dns.api.rackspacecloud.com/v1.0/717071/status/2a5b0f28-05a1-4003-9cec-470c7602cc02", + "requestUrl": "https://dns.api.rackspacecloud.com/v1.0/717071/domains/3670431/records/A-9849792" +} diff --git a/apis/rackspace-clouddns/src/test/resources/record-get.json b/apis/rackspace-clouddns/src/test/resources/record-get.json new file mode 100644 index 0000000000..4bb72b01c2 --- /dev/null +++ b/apis/rackspace-clouddns/src/test/resources/record-get.json @@ -0,0 +1,9 @@ +{ + "name": "jclouds-example.com", + "id": "A-9846146", + "type": "A", + "data": "10.0.1.0", + "ttl": 60000, + "updated": "2013-04-06T15:20:29.000+0000", + "created": "2013-04-06T15:20:29.000+0000" +} diff --git a/apis/rackspace-clouddns/src/test/resources/record-list-with-filter.json b/apis/rackspace-clouddns/src/test/resources/record-list-with-filter.json new file mode 100644 index 0000000000..c5cffc81ca --- /dev/null +++ b/apis/rackspace-clouddns/src/test/resources/record-list-with-filter.json @@ -0,0 +1,13 @@ +{ + "records": [ + { + "name": "jclouds-example.com", + "id": "A-9846146", + "type": "A", + "data": "10.0.1.0", + "ttl": 60000, + "updated": "2013-04-06T15:20:29.000+0000", + "created": "2013-04-06T15:20:29.000+0000" + } + ] +} diff --git a/apis/rackspace-clouddns/src/test/resources/record-list.json b/apis/rackspace-clouddns/src/test/resources/record-list.json new file mode 100644 index 0000000000..060e1904c6 --- /dev/null +++ b/apis/rackspace-clouddns/src/test/resources/record-list.json @@ -0,0 +1,42 @@ +{ + "records": [ + { + "name": "jclouds-example.com", + "id": "A-9846146", + "type": "A", + "data": "10.0.1.0", + "ttl": 60000, + "updated": "2013-04-06T15:20:29.000+0000", + "created": "2013-04-06T15:20:29.000+0000" + }, + { + "name": "jclouds-example.com", + "id": "NS-8684719", + "type": "NS", + "data": "dns1.stabletransit.com", + "ttl": 60000, + "updated": "2013-04-06T15:19:20.000+0000", + "created": "2013-04-06T15:19:20.000+0000" + }, + { + "name": "jclouds-example.com", + "id": "NS-8684720", + "type": "NS", + "data": "dns2.stabletransit.com", + "ttl": 60000, + "updated": "2013-04-06T15:19:20.000+0000", + "created": "2013-04-06T15:19:20.000+0000" + }, + { + "name": "jclouds-example.com", + "id": "MX-4351045", + "priority": 11235, + "type": "MX", + "data": "mail.jclouds-example.com.com", + "ttl": 60000, + "updated": "2013-04-06T15:20:28.000+0000", + "created": "2013-04-06T15:20:28.000+0000" + } + ], + "totalEntries": 4 +} diff --git a/apis/rackspace-clouddns/src/test/resources/record-ptr-create-response.json b/apis/rackspace-clouddns/src/test/resources/record-ptr-create-response.json new file mode 100644 index 0000000000..b532177270 --- /dev/null +++ b/apis/rackspace-clouddns/src/test/resources/record-ptr-create-response.json @@ -0,0 +1,31 @@ +{ + "request": "{\"recordsList\":{\"records\":[{\"name\":\"jclouds-example.com\",\"type\":\"PTR\",\"ttl\":11235,\"data\":\"166.78.146.80\"},{\"name\":\"jclouds-example.com\",\"type\":\"PTR\",\"data\":\"2001:4800:7812:0514:9a32:3c2a:ff04:aed2\",\"comment\":\"Hello IPv6\"}]},\"link\":{\"href\":\"https://dfw.servers.api.rackspacecloud.com/v2/123123/servers/f5fb9334-b4f0-49d0-a2cc-57a5772dc7d1\",\"rel\":\"cloudServersOpenStack\"}}", + "response": { + "records": [ + { + "name": "jclouds-example.com", + "id": "PTR-557432", + "type": "PTR", + "data": "166.78.146.80", + "ttl": 11235, + "updated": "2013-04-11T15:20:23.000+0000", + "created": "2013-04-11T15:20:23.000+0000" + }, + { + "name": "jclouds-example.com", + "id": "PTR-557433", + "type": "PTR", + "data": "2001:4800:7812:514:9a32:3c2a:ff04:aed2", + "ttl": 3600, + "comment": "Hello IPv6", + "updated": "2013-04-11T15:20:25.000+0000", + "created": "2013-04-11T15:20:25.000+0000" + } + ] + }, + "status": "COMPLETED", + "verb": "POST", + "jobId": "0e9aefac-476f-40ba-9626-66dd54c0a5c9", + "callbackUrl": "https://dns.api.rackspacecloud.com/v1.0/123123/status/0e9aefac-476f-40ba-9626-66dd54c0a5c9", + "requestUrl": "https://dns.api.rackspacecloud.com/v1.0/123123/rdns" +} diff --git a/apis/rackspace-clouddns/src/test/resources/record-ptr-create.json b/apis/rackspace-clouddns/src/test/resources/record-ptr-create.json new file mode 100644 index 0000000000..6d233e40fa --- /dev/null +++ b/apis/rackspace-clouddns/src/test/resources/record-ptr-create.json @@ -0,0 +1 @@ +{"recordsList":{"records":[{"name":"jclouds-example.com","type":"PTR","ttl":11235,"data":"166.78.146.80"},{"name":"jclouds-example.com","type":"PTR","data":"2001:4800:7812:0514:9a32:3c2a:ff04:aed2","comment":"Hello IPv6"}]},"link":{"href":"https://dfw.servers.api.rackspacecloud.com/v2/123123/servers/f5fb9334-b4f0-49d0-a2cc-57a5772dc7d1","rel":"cloudServersOpenStack"}} diff --git a/apis/rackspace-clouddns/src/test/resources/record-ptr-delete.json b/apis/rackspace-clouddns/src/test/resources/record-ptr-delete.json new file mode 100644 index 0000000000..6db87e3b2e --- /dev/null +++ b/apis/rackspace-clouddns/src/test/resources/record-ptr-delete.json @@ -0,0 +1,7 @@ +{ + "status": "COMPLETED", + "verb": "DELETE", + "jobId": "4988d69c-37b5-406c-b82b-58ed099d68cd", + "callbackUrl": "https://dns.api.rackspacecloud.com/v1.0/123123/status/4988d69c-37b5-406c-b82b-58ed099d68cd", + "requestUrl": "https://dns.api.rackspacecloud.com/v1.0/123123/rdns/cloudServersOpenStackhref=https://dfw.servers.api.rackspacecloud.com/v2/123123/servers/f5fb9334-b4f0-49d0-a2cc-57a5772dc7d1&ip=166.78.146.80" +} diff --git a/apis/rackspace-clouddns/src/test/resources/record-ptr-get.json b/apis/rackspace-clouddns/src/test/resources/record-ptr-get.json new file mode 100644 index 0000000000..5a9278f528 --- /dev/null +++ b/apis/rackspace-clouddns/src/test/resources/record-ptr-get.json @@ -0,0 +1,9 @@ +{ + "name": "jclouds-example.com", + "id": "PTR-557437", + "type": "PTR", + "data": "166.78.146.80", + "ttl": 11235, + "updated": "2013-04-11T15:35:34.000+0000", + "created": "2013-04-11T15:35:34.000+0000" +} diff --git a/apis/rackspace-clouddns/src/test/resources/record-ptr-list.json b/apis/rackspace-clouddns/src/test/resources/record-ptr-list.json new file mode 100644 index 0000000000..22f85663ce --- /dev/null +++ b/apis/rackspace-clouddns/src/test/resources/record-ptr-list.json @@ -0,0 +1,23 @@ +{ + "records": [ + { + "name": "jclouds-example.com", + "id": "PTR-557437", + "type": "PTR", + "data": "166.78.146.80", + "ttl": 11235, + "updated": "2013-04-11T15:35:34.000+0000", + "created": "2013-04-11T15:35:34.000+0000" + }, + { + "name": "jclouds-example.com", + "id": "PTR-557438", + "type": "PTR", + "comment": "Hello IPv6", + "data": "2001:4800:7812:514:9a32:3c2a:ff04:aed2", + "ttl": 3600, + "updated": "2013-04-11T15:35:37.000+0000", + "created": "2013-04-11T15:35:37.000+0000" + } + ] +} diff --git a/apis/rackspace-clouddns/src/test/resources/record-ptr-update-response.json b/apis/rackspace-clouddns/src/test/resources/record-ptr-update-response.json new file mode 100644 index 0000000000..8cac77a247 --- /dev/null +++ b/apis/rackspace-clouddns/src/test/resources/record-ptr-update-response.json @@ -0,0 +1,8 @@ +{ + "request": "{\"recordsList\":{\"records\":[{\"id\":\"PTR-557437\",\"name\":\"jclouds-example.com\",\"ttl\":12358,\"data\":\"166.78.146.80\"}]},\"link\":{\"href\":\"https://dfw.servers.api.rackspacecloud.com/v2/123123/servers/f5fb9334-b4f0-49d0-a2cc-57a5772dc7d1\",\"rel\":\"cloudServersOpenStack\"}}", + "status": "COMPLETED", + "verb": "PUT", + "jobId": "8e9970a4-365e-4fd9-a243-71c0abcdf18f", + "callbackUrl": "https://dns.api.rackspacecloud.com/v1.0/123123/status/8e9970a4-365e-4fd9-a243-71c0abcdf18f", + "requestUrl": "https://dns.api.rackspacecloud.com/v1.0/123123/rdns" +} diff --git a/apis/rackspace-clouddns/src/test/resources/record-ptr-update.json b/apis/rackspace-clouddns/src/test/resources/record-ptr-update.json new file mode 100644 index 0000000000..0f72f2badc --- /dev/null +++ b/apis/rackspace-clouddns/src/test/resources/record-ptr-update.json @@ -0,0 +1 @@ +{"recordsList":{"records":[{"id":"PTR-557437","name":"jclouds-example.com","ttl":12358,"data":"166.78.146.80"}]},"link":{"href":"https://dfw.servers.api.rackspacecloud.com/v2/123123/servers/f5fb9334-b4f0-49d0-a2cc-57a5772dc7d1","rel":"cloudServersOpenStack"}} diff --git a/apis/rackspace-clouddns/src/test/resources/record-update-response.json b/apis/rackspace-clouddns/src/test/resources/record-update-response.json new file mode 100644 index 0000000000..376651d4a7 --- /dev/null +++ b/apis/rackspace-clouddns/src/test/resources/record-update-response.json @@ -0,0 +1,8 @@ +{ + "request": "{\"name\":\"_sip._udp.jclouds-example.com\",\"ttl\":86401,\"data\":\"1 3444 sip.jclouds-example.com\",\"priority\":12358,\"comment\":\"Updated Protocol to UDP\"}", + "status": "COMPLETED", + "verb": "PUT", + "jobId": "90659522-915d-4b69-a806-0bc464f01cde", + "callbackUrl": "https://dns.api.rackspacecloud.com/v1.0/717071/status/90659522-915d-4b69-a806-0bc464f01cde", + "requestUrl": "https://dns.api.rackspacecloud.com/v1.0/717071/domains/3669444/records/SRV-21839" +} diff --git a/apis/rackspace-clouddns/src/test/resources/record-update.json b/apis/rackspace-clouddns/src/test/resources/record-update.json new file mode 100644 index 0000000000..30f474bd45 --- /dev/null +++ b/apis/rackspace-clouddns/src/test/resources/record-update.json @@ -0,0 +1 @@ +{"name":"_sip._udp.jclouds-example.com","ttl":86401,"data":"1 3444 sip.jclouds-example.com","priority":12358,"comment":"Updated Protocol to UDP"} diff --git a/apis/rackspace-clouddns/src/test/resources/records-delete.json b/apis/rackspace-clouddns/src/test/resources/records-delete.json new file mode 100644 index 0000000000..ca0a742f66 --- /dev/null +++ b/apis/rackspace-clouddns/src/test/resources/records-delete.json @@ -0,0 +1,7 @@ +{ + "status": "COMPLETED", + "verb": "DELETE", + "jobId": "2ad9876f-74f8-4c1c-af9c-1641a72cab75", + "callbackUrl": "https://dns.api.rackspacecloud.com/v1.0/717071/status/2ad9876f-74f8-4c1c-af9c-1641a72cab75", + "requestUrl": "https://dns.api.rackspacecloud.com/v1.0/717071/domains/3670431/records?id=A-9846146&id=MX-9846146" +} diff --git a/apis/rackspace-clouddns/src/test/resources/records-ptr-delete.json b/apis/rackspace-clouddns/src/test/resources/records-ptr-delete.json new file mode 100644 index 0000000000..e603db7578 --- /dev/null +++ b/apis/rackspace-clouddns/src/test/resources/records-ptr-delete.json @@ -0,0 +1,7 @@ +{ + "status": "COMPLETED", + "verb": "DELETE", + "jobId": "ddeea5c4-cbec-4bc3-b37f-eb4f8c0771cc", + "callbackUrl": "https://dns.api.rackspacecloud.com/v1.0/123123/status/ddeea5c4-cbec-4bc3-b37f-eb4f8c0771cc", + "requestUrl": "https://dns.api.rackspacecloud.com/v1.0/123123/rdns/cloudServersOpenStackhref=https://dfw.servers.api.rackspacecloud.com/v2/123123/servers/f5fb9334-b4f0-49d0-a2cc-57a5772dc7d1" +} diff --git a/apis/rackspace-clouddns/src/test/resources/records-update-response.json b/apis/rackspace-clouddns/src/test/resources/records-update-response.json new file mode 100644 index 0000000000..340e856f81 --- /dev/null +++ b/apis/rackspace-clouddns/src/test/resources/records-update-response.json @@ -0,0 +1,8 @@ +{ + "request": "{\"records\":[{\"id\":\"A-9849792\",\"comment\":\"Multi-record Update\"},{\"id\":\"NS-8687533\",\"comment\":\"Multi-record Update\"},{\"id\":\"NS-8687534\",\"comment\":\"Multi-record Update\"},{\"id\":\"MX-4352374\",\"comment\":\"Multi-record Update\"}]}", + "status": "COMPLETED", + "verb": "PUT", + "jobId": "839768a9-102b-49cc-8227-b9de7485296a", + "callbackUrl": "https://dns.api.rackspacecloud.com/v1.0/717071/status/839768a9-102b-49cc-8227-b9de7485296a", + "requestUrl": "https://dns.api.rackspacecloud.com/v1.0/717071/domains/3670431/records" +} diff --git a/apis/rackspace-clouddns/src/test/resources/records-update.json b/apis/rackspace-clouddns/src/test/resources/records-update.json new file mode 100644 index 0000000000..df39825714 --- /dev/null +++ b/apis/rackspace-clouddns/src/test/resources/records-update.json @@ -0,0 +1 @@ +{"records":[{"id":"A-9846146","comment":"Multi-record Update"},{"id":"MX-9846146","comment":"Multi-record Update"}]} diff --git a/providers/pom.xml b/providers/pom.xml index 8b7757c78b..c1d43042b4 100644 --- a/providers/pom.xml +++ b/providers/pom.xml @@ -66,6 +66,8 @@ cloudservers-uk cloudfiles-us cloudfiles-uk + rackspace-clouddns-us + rackspace-clouddns-uk rackspace-cloudloadbalancers-us rackspace-cloudloadbalancers-uk rackspace-cloudservers-us diff --git a/providers/rackspace-clouddns-uk/pom.xml b/providers/rackspace-clouddns-uk/pom.xml new file mode 100644 index 0000000000..28cdb7382e --- /dev/null +++ b/providers/rackspace-clouddns-uk/pom.xml @@ -0,0 +1,148 @@ + + + + 4.0.0 + + org.jclouds + jclouds-project + 1.7.0-SNAPSHOT + ../../project/pom.xml + + org.jclouds.provider + rackspace-clouddns-uk + jclouds Rackspace Next Generation Cloud DNS UK provider + Rackspace Next Generation Cloud DNS UK + bundle + + + https://lon.identity.api.rackspacecloud.com/v2.0/ + 1.0 + + ${test.rackspace-uk.identity} + ${test.rackspace-uk.credential} + + org.jclouds.rackspace.clouddns.us*;version="${project.version}" + + org.jclouds.compute.internal;version="${project.version}", + org.jclouds.rest.internal;version="${project.version}", + org.jclouds*;version="${project.version}", + * + + + + + + org.jclouds + jclouds-core + ${project.version} + + + org.jclouds.api + openstack-keystone + ${project.version} + + + org.jclouds.api + rackspace-clouddns + ${project.version} + + + org.jclouds.api + rackspace-cloudidentity + ${project.version} + + + org.jclouds + jclouds-core + ${project.version} + test-jar + test + + + org.jclouds.api + openstack-keystone + ${project.version} + test-jar + test + + + org.jclouds.api + rackspace-clouddns + ${project.version} + test-jar + test + + + org.jclouds.api + rackspace-cloudidentity + ${project.version} + test-jar + test + + + org.jclouds.driver + jclouds-slf4j + ${project.version} + test + + + ch.qos.logback + logback-classic + test + + + + + + live + + + + org.apache.maven.plugins + maven-surefire-plugin + + + integration + integration-test + + test + + + 1 + + ${test.rackspace-clouddns-uk.endpoint} + ${test.rackspace-clouddns-uk.api-version} + ${test.rackspace-clouddns-uk.build-version} + ${test.rackspace-clouddns-uk.identity} + ${test.rackspace-clouddns-uk.credential} + ${test.rackspace-clouddns-uk.template} + + + + + + + + + + + diff --git a/providers/rackspace-clouddns-uk/src/main/java/org/jclouds/rackspace/clouddns/uk/CloudDNSUKProviderMetadata.java b/providers/rackspace-clouddns-uk/src/main/java/org/jclouds/rackspace/clouddns/uk/CloudDNSUKProviderMetadata.java new file mode 100644 index 0000000000..c8deaadf4e --- /dev/null +++ b/providers/rackspace-clouddns-uk/src/main/java/org/jclouds/rackspace/clouddns/uk/CloudDNSUKProviderMetadata.java @@ -0,0 +1,85 @@ +/** + * 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.rackspace.clouddns.uk; + +import java.net.URI; +import java.util.Properties; + +import org.jclouds.providers.ProviderMetadata; +import org.jclouds.providers.internal.BaseProviderMetadata; +import org.jclouds.rackspace.clouddns.v1.CloudDNSApiMetadata; + +/** + * Implementation of {@link org.jclouds.types.ProviderMetadata} for Rackspace DNS UK. + * + * @author Everett Toews + */ +public class CloudDNSUKProviderMetadata extends BaseProviderMetadata { + + public static Builder builder() { + return new Builder(); + } + + @Override + public Builder toBuilder() { + return builder().fromProviderMetadata(this); + } + + public CloudDNSUKProviderMetadata() { + super(builder()); + } + + public CloudDNSUKProviderMetadata(Builder builder) { + super(builder); + } + + public static Properties defaultProperties() { + Properties properties = new Properties(); + return properties; + } + + public static class Builder extends BaseProviderMetadata.Builder { + + protected Builder(){ + id("rackspace-clouddns-uk") + .name("Rackspace Cloud DNS UK") + .apiMetadata(new CloudDNSApiMetadata().toBuilder() + .defaultEndpoint("https://lon.identity.api.rackspacecloud.com/v2.0/") + .build()) + .homepage(URI.create("http://www.rackspace.com/cloud/public/dns/")) + .console(URI.create("https://mycloud.rackspace.com")) + .linkedServices("rackspace-cloudidentity", "rackspace-cloudservers-uk", "cloudfiles-uk", "rackspace-cloudblockstorage-uk", "rackspace-cloudloadbalancers-uk") + .iso3166Codes("GB-SLG") + .endpoint("https://lon.identity.api.rackspacecloud.com/v2.0/") + .defaultProperties(CloudDNSApiMetadata.defaultProperties()); + } + + @Override + public CloudDNSUKProviderMetadata build() { + return new CloudDNSUKProviderMetadata(this); + } + + @Override + public Builder fromProviderMetadata( + ProviderMetadata in) { + super.fromProviderMetadata(in); + return this; + } + } +} diff --git a/providers/rackspace-clouddns-uk/src/main/resources/META-INF/services/org.jclouds.providers.ProviderMetadata b/providers/rackspace-clouddns-uk/src/main/resources/META-INF/services/org.jclouds.providers.ProviderMetadata new file mode 100644 index 0000000000..dbb2966301 --- /dev/null +++ b/providers/rackspace-clouddns-uk/src/main/resources/META-INF/services/org.jclouds.providers.ProviderMetadata @@ -0,0 +1 @@ +org.jclouds.rackspace.clouddns.uk.CloudDNSUKProviderMetadata diff --git a/providers/rackspace-clouddns-uk/src/test/java/org/jclouds/rackspace/clouddns/uk/features/CloudDNSUKDomainApiLiveTest.java b/providers/rackspace-clouddns-uk/src/test/java/org/jclouds/rackspace/clouddns/uk/features/CloudDNSUKDomainApiLiveTest.java new file mode 100644 index 0000000000..f0ae202525 --- /dev/null +++ b/providers/rackspace-clouddns-uk/src/test/java/org/jclouds/rackspace/clouddns/uk/features/CloudDNSUKDomainApiLiveTest.java @@ -0,0 +1,33 @@ +/** + * 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.rackspace.clouddns.uk.features; + +import org.jclouds.rackspace.clouddns.v1.features.DomainApiLiveTest; +import org.testng.annotations.Test; + +/** + * + * @author Everett Toews + */ +@Test(groups = "live", singleThreaded = true, testName = "CloudDNSUKDomainApiLiveTest") +public class CloudDNSUKDomainApiLiveTest extends DomainApiLiveTest { + public CloudDNSUKDomainApiLiveTest() { + provider = "rackspace-clouddns-uk"; + } +} diff --git a/providers/rackspace-clouddns-uk/src/test/java/org/jclouds/rackspace/clouddns/uk/features/CloudDNSUKLimitApiLiveTest.java b/providers/rackspace-clouddns-uk/src/test/java/org/jclouds/rackspace/clouddns/uk/features/CloudDNSUKLimitApiLiveTest.java new file mode 100644 index 0000000000..4fbd9a3ef7 --- /dev/null +++ b/providers/rackspace-clouddns-uk/src/test/java/org/jclouds/rackspace/clouddns/uk/features/CloudDNSUKLimitApiLiveTest.java @@ -0,0 +1,33 @@ +/** + * 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.rackspace.clouddns.uk.features; + +import org.jclouds.rackspace.clouddns.v1.features.LimitApiLiveTest; +import org.testng.annotations.Test; + +/** + * + * @author Everett Toews + */ +@Test(groups = "live", singleThreaded = true, testName = "CloudDNSUKLimitApiLiveTest") +public class CloudDNSUKLimitApiLiveTest extends LimitApiLiveTest { + public CloudDNSUKLimitApiLiveTest() { + provider = "rackspace-clouddns-uk"; + } +} diff --git a/providers/rackspace-clouddns-uk/src/test/java/org/jclouds/rackspace/clouddns/uk/features/CloudDNSUKProviderTest.java b/providers/rackspace-clouddns-uk/src/test/java/org/jclouds/rackspace/clouddns/uk/features/CloudDNSUKProviderTest.java new file mode 100644 index 0000000000..07ef9606c2 --- /dev/null +++ b/providers/rackspace-clouddns-uk/src/test/java/org/jclouds/rackspace/clouddns/uk/features/CloudDNSUKProviderTest.java @@ -0,0 +1,36 @@ +/** + * 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.rackspace.clouddns.uk.features; + +import org.jclouds.providers.internal.BaseProviderMetadataTest; +import org.jclouds.rackspace.clouddns.uk.CloudDNSUKProviderMetadata; +import org.jclouds.rackspace.clouddns.v1.CloudDNSApiMetadata; +import org.testng.annotations.Test; + +/** + * + * @author Everett Toews + */ +@Test(groups = "unit", testName = "CloudDNSUKProviderTest") +public class CloudDNSUKProviderTest extends BaseProviderMetadataTest { + + public CloudDNSUKProviderTest() { + super(new CloudDNSUKProviderMetadata(), new CloudDNSApiMetadata()); + } +} diff --git a/providers/rackspace-clouddns-uk/src/test/java/org/jclouds/rackspace/clouddns/uk/features/CloudDNSUKRecordApiLiveTest.java b/providers/rackspace-clouddns-uk/src/test/java/org/jclouds/rackspace/clouddns/uk/features/CloudDNSUKRecordApiLiveTest.java new file mode 100644 index 0000000000..17f91162fb --- /dev/null +++ b/providers/rackspace-clouddns-uk/src/test/java/org/jclouds/rackspace/clouddns/uk/features/CloudDNSUKRecordApiLiveTest.java @@ -0,0 +1,33 @@ +/** + * 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.rackspace.clouddns.uk.features; + +import org.jclouds.rackspace.clouddns.v1.features.RecordApiLiveTest; +import org.testng.annotations.Test; + +/** + * + * @author Everett Toews + */ +@Test(groups = "live", singleThreaded = true, testName = "CloudDNSUKRecordApiLiveTest") +public class CloudDNSUKRecordApiLiveTest extends RecordApiLiveTest { + public CloudDNSUKRecordApiLiveTest() { + provider = "rackspace-clouddns-uk"; + } +} diff --git a/providers/rackspace-clouddns-us/pom.xml b/providers/rackspace-clouddns-us/pom.xml new file mode 100644 index 0000000000..5addeb4c82 --- /dev/null +++ b/providers/rackspace-clouddns-us/pom.xml @@ -0,0 +1,167 @@ + + + + 4.0.0 + + org.jclouds + jclouds-project + 1.7.0-SNAPSHOT + ../../project/pom.xml + + org.jclouds.provider + rackspace-clouddns-us + jclouds Rackspace Next Generation Cloud DNS US provider + Rackspace Next Generation Cloud DNS US + bundle + + + https://identity.api.rackspacecloud.com/v2.0/ + 1.0 + + ${test.rackspace-us.identity} + ${test.rackspace-us.credential} + + org.jclouds.rackspace.clouddns.us*;version="${project.version}" + + org.jclouds.compute.internal;version="${project.version}", + org.jclouds.rest.internal;version="${project.version}", + org.jclouds*;version="${project.version}", + * + + + + + + org.jclouds + jclouds-core + ${project.version} + + + org.jclouds.api + openstack-keystone + ${project.version} + + + org.jclouds.api + rackspace-clouddns + ${project.version} + + + org.jclouds.api + rackspace-cloudidentity + ${project.version} + + + org.jclouds + jclouds-core + ${project.version} + test-jar + test + + + org.jclouds + jclouds-compute + ${project.version} + test-jar + test + + + org.jclouds.api + openstack-keystone + ${project.version} + test-jar + test + + + org.jclouds.api + openstack-nova + ${project.version} + test + + + org.jclouds.api + rackspace-clouddns + ${project.version} + test-jar + test + + + org.jclouds.api + rackspace-cloudidentity + ${project.version} + test-jar + test + + + org.jclouds.provider + rackspace-cloudservers-us + ${project.version} + test + + + org.jclouds.driver + jclouds-slf4j + ${project.version} + test + + + ch.qos.logback + logback-classic + test + + + + + + live + + + + org.apache.maven.plugins + maven-surefire-plugin + + + integration + integration-test + + test + + + 1 + + ${test.rackspace-clouddns-us.endpoint} + ${test.rackspace-clouddns-us.api-version} + ${test.rackspace-clouddns-us.build-version} + ${test.rackspace-clouddns-us.identity} + ${test.rackspace-clouddns-us.credential} + ${test.rackspace-clouddns-us.template} + + + + + + + + + + + diff --git a/providers/rackspace-clouddns-us/src/main/java/org/jclouds/rackspace/clouddns/us/CloudDNSUSProviderMetadata.java b/providers/rackspace-clouddns-us/src/main/java/org/jclouds/rackspace/clouddns/us/CloudDNSUSProviderMetadata.java new file mode 100644 index 0000000000..846517aa60 --- /dev/null +++ b/providers/rackspace-clouddns-us/src/main/java/org/jclouds/rackspace/clouddns/us/CloudDNSUSProviderMetadata.java @@ -0,0 +1,85 @@ +/** + * 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.rackspace.clouddns.us; + +import java.net.URI; +import java.util.Properties; + +import org.jclouds.providers.ProviderMetadata; +import org.jclouds.providers.internal.BaseProviderMetadata; +import org.jclouds.rackspace.clouddns.v1.CloudDNSApiMetadata; + +/** + * Implementation of {@link org.jclouds.types.ProviderMetadata} for Rackspace DNS US. + * + * @author Everett Toews + */ +public class CloudDNSUSProviderMetadata extends BaseProviderMetadata { + + public static Builder builder() { + return new Builder(); + } + + @Override + public Builder toBuilder() { + return builder().fromProviderMetadata(this); + } + + public CloudDNSUSProviderMetadata() { + super(builder()); + } + + public CloudDNSUSProviderMetadata(Builder builder) { + super(builder); + } + + public static Properties defaultProperties() { + Properties properties = new Properties(); + return properties; + } + + public static class Builder extends BaseProviderMetadata.Builder { + + protected Builder(){ + id("rackspace-clouddns-us") + .name("Rackspace Cloud DNS US") + .apiMetadata(new CloudDNSApiMetadata().toBuilder() + .defaultEndpoint("https://identity.api.rackspacecloud.com/v2.0/") + .build()) + .homepage(URI.create("http://www.rackspace.com/cloud/public/dns/")) + .console(URI.create("https://mycloud.rackspace.com")) + .linkedServices("rackspace-cloudidentity", "rackspace-cloudservers-us", "cloudfiles-us", "rackspace-cloudblockstorage-us", "rackspace-cloudloadbalancers-us") + .iso3166Codes("US-TX") + .endpoint("https://identity.api.rackspacecloud.com/v2.0/") + .defaultProperties(CloudDNSApiMetadata.defaultProperties()); + } + + @Override + public CloudDNSUSProviderMetadata build() { + return new CloudDNSUSProviderMetadata(this); + } + + @Override + public Builder fromProviderMetadata( + ProviderMetadata in) { + super.fromProviderMetadata(in); + return this; + } + } +} diff --git a/providers/rackspace-clouddns-us/src/main/resources/META-INF/services/org.jclouds.providers.ProviderMetadata b/providers/rackspace-clouddns-us/src/main/resources/META-INF/services/org.jclouds.providers.ProviderMetadata new file mode 100644 index 0000000000..b2db3e2a92 --- /dev/null +++ b/providers/rackspace-clouddns-us/src/main/resources/META-INF/services/org.jclouds.providers.ProviderMetadata @@ -0,0 +1 @@ +org.jclouds.rackspace.clouddns.us.CloudDNSUSProviderMetadata diff --git a/providers/rackspace-clouddns-us/src/test/java/org/jclouds/rackspace/clouddns/us/features/CloudDNSUSDomainApiLiveTest.java b/providers/rackspace-clouddns-us/src/test/java/org/jclouds/rackspace/clouddns/us/features/CloudDNSUSDomainApiLiveTest.java new file mode 100644 index 0000000000..6b0bd88cbb --- /dev/null +++ b/providers/rackspace-clouddns-us/src/test/java/org/jclouds/rackspace/clouddns/us/features/CloudDNSUSDomainApiLiveTest.java @@ -0,0 +1,33 @@ +/** + * 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.rackspace.clouddns.us.features; + +import org.jclouds.rackspace.clouddns.v1.features.DomainApiLiveTest; +import org.testng.annotations.Test; + +/** + * + * @author Everett Toews + */ +@Test(groups = "live", singleThreaded = true, testName = "CloudDNSUSDomainApiLiveTest") +public class CloudDNSUSDomainApiLiveTest extends DomainApiLiveTest { + public CloudDNSUSDomainApiLiveTest() { + provider = "rackspace-clouddns-us"; + } +} diff --git a/providers/rackspace-clouddns-us/src/test/java/org/jclouds/rackspace/clouddns/us/features/CloudDNSUSLimitApiLiveTest.java b/providers/rackspace-clouddns-us/src/test/java/org/jclouds/rackspace/clouddns/us/features/CloudDNSUSLimitApiLiveTest.java new file mode 100644 index 0000000000..f4433bcd18 --- /dev/null +++ b/providers/rackspace-clouddns-us/src/test/java/org/jclouds/rackspace/clouddns/us/features/CloudDNSUSLimitApiLiveTest.java @@ -0,0 +1,33 @@ +/** + * 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.rackspace.clouddns.us.features; + +import org.jclouds.rackspace.clouddns.v1.features.LimitApiLiveTest; +import org.testng.annotations.Test; + +/** + * + * @author Everett Toews + */ +@Test(groups = "live", singleThreaded = true, testName = "CloudDNSUSLimitApiLiveTest") +public class CloudDNSUSLimitApiLiveTest extends LimitApiLiveTest { + public CloudDNSUSLimitApiLiveTest() { + provider = "rackspace-clouddns-us"; + } +} diff --git a/providers/rackspace-clouddns-us/src/test/java/org/jclouds/rackspace/clouddns/us/features/CloudDNSUSProviderTest.java b/providers/rackspace-clouddns-us/src/test/java/org/jclouds/rackspace/clouddns/us/features/CloudDNSUSProviderTest.java new file mode 100644 index 0000000000..f5faabc29e --- /dev/null +++ b/providers/rackspace-clouddns-us/src/test/java/org/jclouds/rackspace/clouddns/us/features/CloudDNSUSProviderTest.java @@ -0,0 +1,36 @@ +/** + * 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.rackspace.clouddns.us.features; + +import org.jclouds.providers.internal.BaseProviderMetadataTest; +import org.jclouds.rackspace.clouddns.us.CloudDNSUSProviderMetadata; +import org.jclouds.rackspace.clouddns.v1.CloudDNSApiMetadata; +import org.testng.annotations.Test; + +/** + * + * @author Everett Toews + */ +@Test(groups = "unit", testName = "CloudDNSUSProviderTest") +public class CloudDNSUSProviderTest extends BaseProviderMetadataTest { + + public CloudDNSUSProviderTest() { + super(new CloudDNSUSProviderMetadata(), new CloudDNSApiMetadata()); + } +} diff --git a/providers/rackspace-clouddns-us/src/test/java/org/jclouds/rackspace/clouddns/us/features/CloudDNSUSRecordApiLiveTest.java b/providers/rackspace-clouddns-us/src/test/java/org/jclouds/rackspace/clouddns/us/features/CloudDNSUSRecordApiLiveTest.java new file mode 100644 index 0000000000..0bea0574da --- /dev/null +++ b/providers/rackspace-clouddns-us/src/test/java/org/jclouds/rackspace/clouddns/us/features/CloudDNSUSRecordApiLiveTest.java @@ -0,0 +1,33 @@ +/** + * 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.rackspace.clouddns.us.features; + +import org.jclouds.rackspace.clouddns.v1.features.RecordApiLiveTest; +import org.testng.annotations.Test; + +/** + * + * @author Everett Toews + */ +@Test(groups = "live", singleThreaded = true, testName = "CloudDNSUSRecordApiLiveTest") +public class CloudDNSUSRecordApiLiveTest extends RecordApiLiveTest { + public CloudDNSUSRecordApiLiveTest() { + provider = "rackspace-clouddns-us"; + } +} diff --git a/providers/rackspace-clouddns-us/src/test/java/org/jclouds/rackspace/clouddns/us/features/CloudDNSUSReverseDNSApiLiveTest.java b/providers/rackspace-clouddns-us/src/test/java/org/jclouds/rackspace/clouddns/us/features/CloudDNSUSReverseDNSApiLiveTest.java new file mode 100644 index 0000000000..ce5f71ce89 --- /dev/null +++ b/providers/rackspace-clouddns-us/src/test/java/org/jclouds/rackspace/clouddns/us/features/CloudDNSUSReverseDNSApiLiveTest.java @@ -0,0 +1,33 @@ +/** + * 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.rackspace.clouddns.us.features; + +import org.jclouds.rackspace.clouddns.v1.features.ReverseDNSApiLiveTest; +import org.testng.annotations.Test; + +/** + * + * @author Everett Toews + */ +@Test(groups = "live", singleThreaded = true, testName = "CloudDNSUSReverseDNSApiLiveTest") +public class CloudDNSUSReverseDNSApiLiveTest extends ReverseDNSApiLiveTest { + public CloudDNSUSReverseDNSApiLiveTest() { + provider = "rackspace-clouddns-us"; + } +}