From 7e0c4cfb00405b1e07f6c3895b8684afe062be56 Mon Sep 17 00:00:00 2001 From: adriancole Date: Tue, 9 Apr 2013 22:35:05 -0700 Subject: [PATCH] removed async api from dynect --- .../java/org/jclouds/dynect/v3/DynECTApi.java | 27 +- .../jclouds/dynect/v3/DynECTApiMetadata.java | 21 +- .../org/jclouds/dynect/v3/DynECTAsyncApi.java | 86 ------ .../dynect/v3/binders/CreateRecordBinder.java | 55 ++++ .../dynect/v3/binders/RecordIdBinder.java | 45 +++ ...ntModule.java => DynECTHttpApiModule.java} | 44 +-- .../jclouds/dynect/v3/features/RecordApi.java | 184 +++++++++-- .../dynect/v3/features/RecordAsyncApi.java | 291 ------------------ .../dynect/v3/features/SessionApi.java | 33 +- .../dynect/v3/features/SessionAsyncApi.java | 76 ----- .../jclouds/dynect/v3/features/ZoneApi.java | 117 +++++-- .../dynect/v3/features/ZoneAsyncApi.java | 163 ---------- .../v3/internal/BaseDynECTExpectTest.java | 10 +- 13 files changed, 438 insertions(+), 714 deletions(-) delete mode 100644 providers/dynect/src/main/java/org/jclouds/dynect/v3/DynECTAsyncApi.java create mode 100644 providers/dynect/src/main/java/org/jclouds/dynect/v3/binders/CreateRecordBinder.java create mode 100644 providers/dynect/src/main/java/org/jclouds/dynect/v3/binders/RecordIdBinder.java rename providers/dynect/src/main/java/org/jclouds/dynect/v3/config/{DynECTRestClientModule.java => DynECTHttpApiModule.java} (76%) delete mode 100644 providers/dynect/src/main/java/org/jclouds/dynect/v3/features/RecordAsyncApi.java delete mode 100644 providers/dynect/src/main/java/org/jclouds/dynect/v3/features/SessionAsyncApi.java delete mode 100644 providers/dynect/src/main/java/org/jclouds/dynect/v3/features/ZoneAsyncApi.java diff --git a/providers/dynect/src/main/java/org/jclouds/dynect/v3/DynECTApi.java b/providers/dynect/src/main/java/org/jclouds/dynect/v3/DynECTApi.java index fcf67780fb..19119f4f38 100644 --- a/providers/dynect/src/main/java/org/jclouds/dynect/v3/DynECTApi.java +++ b/providers/dynect/src/main/java/org/jclouds/dynect/v3/DynECTApi.java @@ -18,24 +18,34 @@ */ package org.jclouds.dynect.v3; +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.dynect.v3.domain.Job; import org.jclouds.dynect.v3.features.RecordApi; import org.jclouds.dynect.v3.features.SessionApi; import org.jclouds.dynect.v3.features.ZoneApi; +import org.jclouds.dynect.v3.filters.AlwaysAddContentType; +import org.jclouds.dynect.v3.filters.SessionManager; import org.jclouds.javax.annotation.Nullable; import org.jclouds.rest.annotations.Delegate; +import org.jclouds.rest.annotations.Fallback; +import org.jclouds.rest.annotations.Headers; +import org.jclouds.rest.annotations.RequestFilters; /** * Provides access to DynECT Managed DNS through the API2 api *

* - * @see DynECTAsyncApi - * @see + * @see * @author Adrian Cole */ public interface DynECTApi extends Closeable { @@ -46,8 +56,15 @@ public interface DynECTApi extends Closeable { * The ID of the job * @return null, if not found */ + @Named("GetJob") + @GET + @Path("/Job/{jobId}") + @RequestFilters({ AlwaysAddContentType.class, SessionManager.class }) + @Headers(keys = "API-Version", values = "{jclouds.api-version}") + @Fallback(NullOnNotFoundOr404.class) + @Consumes(APPLICATION_JSON) @Nullable - Job getJob(long jobId); + Job getJob(@PathParam("jobId") long jobId); /** * Provides synchronous access to Session features. @@ -60,7 +77,7 @@ public interface DynECTApi extends Closeable { */ @Delegate ZoneApi getZoneApi(); - + /** * Provides synchronous access to Record features */ diff --git a/providers/dynect/src/main/java/org/jclouds/dynect/v3/DynECTApiMetadata.java b/providers/dynect/src/main/java/org/jclouds/dynect/v3/DynECTApiMetadata.java index 89be1afb5b..614d7faa4b 100644 --- a/providers/dynect/src/main/java/org/jclouds/dynect/v3/DynECTApiMetadata.java +++ b/providers/dynect/src/main/java/org/jclouds/dynect/v3/DynECTApiMetadata.java @@ -23,8 +23,8 @@ import java.util.Properties; import org.jclouds.apis.ApiMetadata; import org.jclouds.dynect.v3.config.DynECTParserModule; -import org.jclouds.dynect.v3.config.DynECTRestClientModule; -import org.jclouds.rest.internal.BaseRestApiMetadata; +import org.jclouds.dynect.v3.config.DynECTHttpApiModule; +import org.jclouds.rest.internal.BaseHttpApiMetadata; import com.google.common.collect.ImmutableSet; import com.google.inject.Module; @@ -34,10 +34,8 @@ import com.google.inject.Module; * * @author Adrian Cole */ -public class DynECTApiMetadata extends BaseRestApiMetadata { +public class DynECTApiMetadata extends BaseHttpApiMetadata { - public static final String ANONYMOUS_IDENTITY = "ANONYMOUS"; - @Override public Builder toBuilder() { return new Builder().fromApiMetadata(this); @@ -52,27 +50,24 @@ public class DynECTApiMetadata extends BaseRestApiMetadata { } public static Properties defaultProperties() { - Properties properties = BaseRestApiMetadata.defaultProperties(); + Properties properties = BaseHttpApiMetadata.defaultProperties(); return properties; } - public static class Builder extends BaseRestApiMetadata.Builder { + public static class Builder extends BaseHttpApiMetadata.Builder { protected Builder() { - super(DynECTApi.class, DynECTAsyncApi.class); id("dynect") .name("DynECT API2") - .identityName("Username (or " + ANONYMOUS_IDENTITY + " if anonymous)") - .defaultIdentity(ANONYMOUS_IDENTITY) - .credentialName("Password") - .defaultCredential(ANONYMOUS_IDENTITY) + .identityName("${customer}:${userName}") + .credentialName("${password}") .documentation(URI.create("https://manage.dynect.net/help/docs/api2/rest/")) .version("3.3.8") .defaultEndpoint("https://api2.dynect.net/REST") .defaultProperties(DynECTApiMetadata.defaultProperties()) .defaultModules(ImmutableSet.>builder() .add(DynECTParserModule.class) - .add(DynECTRestClientModule.class).build()); + .add(DynECTHttpApiModule.class).build()); } @Override diff --git a/providers/dynect/src/main/java/org/jclouds/dynect/v3/DynECTAsyncApi.java b/providers/dynect/src/main/java/org/jclouds/dynect/v3/DynECTAsyncApi.java deleted file mode 100644 index 14f86b234f..0000000000 --- a/providers/dynect/src/main/java/org/jclouds/dynect/v3/DynECTAsyncApi.java +++ /dev/null @@ -1,86 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.jclouds.dynect.v3; - -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.dynect.v3.domain.Job; -import org.jclouds.dynect.v3.features.RecordAsyncApi; -import org.jclouds.dynect.v3.features.SessionAsyncApi; -import org.jclouds.dynect.v3.features.ZoneAsyncApi; -import org.jclouds.dynect.v3.filters.AlwaysAddContentType; -import org.jclouds.dynect.v3.filters.SessionManager; -import org.jclouds.rest.annotations.Delegate; -import org.jclouds.rest.annotations.Fallback; -import org.jclouds.rest.annotations.Headers; -import org.jclouds.rest.annotations.RequestFilters; - -import com.google.common.util.concurrent.ListenableFuture; - -/** - * Provides access to DynECT Managed DNS through the API2 api - *

- * - * @see DynECTApi - * @see - * @author Adrian Cole - * @deprecated please use {@code org.jclouds.ContextBuilder#buildApi(DynECTApi.class)} as - * {@link DynECTAsyncApi} interface will be removed in jclouds 1.7. - */ - -public interface DynECTAsyncApi extends Closeable { - /** - * @see DynECTApi#getJob - */ - @Named("GetJob") - @GET - @Path("/Job/{jobId}") - @RequestFilters({ AlwaysAddContentType.class, SessionManager.class }) - @Headers(keys = "API-Version", values = "{jclouds.api-version}") - @Fallback(NullOnNotFoundOr404.class) - @Consumes(APPLICATION_JSON) - ListenableFuture getJob(@PathParam("jobId") long jobId); - - /** - * Provides asynchronous access to Session features. - */ - @Delegate - SessionAsyncApi getSessionApi(); - - /** - * Provides asynchronous access to Zone features. - */ - @Delegate - ZoneAsyncApi getZoneApi(); - - /** - * Provides asynchronous access to Record features - */ - @Delegate - RecordAsyncApi getRecordApiForZone(@PathParam("zone") String zone); -} diff --git a/providers/dynect/src/main/java/org/jclouds/dynect/v3/binders/CreateRecordBinder.java b/providers/dynect/src/main/java/org/jclouds/dynect/v3/binders/CreateRecordBinder.java new file mode 100644 index 0000000000..6efd16b65d --- /dev/null +++ b/providers/dynect/src/main/java/org/jclouds/dynect/v3/binders/CreateRecordBinder.java @@ -0,0 +1,55 @@ +/** + * 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.dynect.v3.binders; + +import static com.google.common.base.Preconditions.checkNotNull; +import static org.jclouds.http.Uris.uriBuilder; + +import java.net.URI; + +import javax.inject.Inject; + +import org.jclouds.dynect.v3.domain.CreateRecord; +import org.jclouds.http.HttpRequest; +import org.jclouds.json.Json; +import org.jclouds.rest.Binder; + +import com.google.common.collect.ImmutableMap; + +public class CreateRecordBinder implements Binder { + private final Json json; + + @Inject + CreateRecordBinder(Json json){ + this.json = checkNotNull(json, "json"); + } + + @SuppressWarnings("unchecked") + @Override + public R bindToRequest(R request, Object arg) { + CreateRecord in = CreateRecord.class.cast(checkNotNull(arg, "record to create")); + URI path = uriBuilder(request.getEndpoint()) + .build(ImmutableMap. builder() + .put("type", in.getType()) + .put("fqdn", in.getFQDN()).build()); + return (R) request.toBuilder() + .endpoint(path) + .payload(json.toJson(ImmutableMap.of("rdata", in.getRData(), "ttl", in.getTTL()))).build(); + } +} diff --git a/providers/dynect/src/main/java/org/jclouds/dynect/v3/binders/RecordIdBinder.java b/providers/dynect/src/main/java/org/jclouds/dynect/v3/binders/RecordIdBinder.java new file mode 100644 index 0000000000..e2ed0fe70c --- /dev/null +++ b/providers/dynect/src/main/java/org/jclouds/dynect/v3/binders/RecordIdBinder.java @@ -0,0 +1,45 @@ +/** + * 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.dynect.v3.binders; + +import static com.google.common.base.Preconditions.checkNotNull; +import static org.jclouds.http.Uris.uriBuilder; + +import java.net.URI; + +import org.jclouds.dynect.v3.domain.RecordId; +import org.jclouds.http.HttpRequest; +import org.jclouds.rest.Binder; + +import com.google.common.collect.ImmutableMap; + +public class RecordIdBinder implements Binder { + @SuppressWarnings("unchecked") + @Override + public R bindToRequest(R request, Object recordId) { + RecordId valueToAppend = RecordId.class.cast(checkNotNull(recordId, "recordId")); + URI path = uriBuilder(request.getEndpoint()).appendPath("/{type}Record/{zone}/{fqdn}/{id}").build( + ImmutableMap. builder() + .put("type", valueToAppend.getType()) + .put("zone", valueToAppend.getZone()) + .put("fqdn", valueToAppend.getFQDN()) + .put("id", valueToAppend.getId()).build()); + return (R) request.toBuilder().endpoint(path).build(); + } +} \ No newline at end of file diff --git a/providers/dynect/src/main/java/org/jclouds/dynect/v3/config/DynECTRestClientModule.java b/providers/dynect/src/main/java/org/jclouds/dynect/v3/config/DynECTHttpApiModule.java similarity index 76% rename from providers/dynect/src/main/java/org/jclouds/dynect/v3/config/DynECTRestClientModule.java rename to providers/dynect/src/main/java/org/jclouds/dynect/v3/config/DynECTHttpApiModule.java index a56b23dcbc..a20c5ef97c 100644 --- a/providers/dynect/src/main/java/org/jclouds/dynect/v3/config/DynECTRestClientModule.java +++ b/providers/dynect/src/main/java/org/jclouds/dynect/v3/config/DynECTHttpApiModule.java @@ -19,13 +19,12 @@ package org.jclouds.dynect.v3.config; import static org.jclouds.http.HttpUtils.closeClientButKeepContentStream; -import static org.jclouds.rest.config.BinderUtils.bindMappedHttpApi; +import static org.jclouds.rest.config.BinderUtils.bindHttpApi; import java.io.IOException; import java.net.HttpURLConnection; import java.net.Proxy; import java.net.URI; -import java.util.Map; import javax.inject.Inject; import javax.inject.Named; @@ -36,13 +35,7 @@ import javax.net.ssl.SSLContext; import org.jclouds.Constants; import org.jclouds.concurrent.SingleThreaded; import org.jclouds.dynect.v3.DynECTApi; -import org.jclouds.dynect.v3.DynECTAsyncApi; -import org.jclouds.dynect.v3.features.RecordApi; -import org.jclouds.dynect.v3.features.RecordAsyncApi; import org.jclouds.dynect.v3.features.SessionApi; -import org.jclouds.dynect.v3.features.SessionAsyncApi; -import org.jclouds.dynect.v3.features.ZoneApi; -import org.jclouds.dynect.v3.features.ZoneAsyncApi; import org.jclouds.dynect.v3.filters.SessionManager; import org.jclouds.dynect.v3.handlers.DynECTErrorHandler; import org.jclouds.dynect.v3.handlers.GetJobRedirectionRetryHandler; @@ -60,12 +53,11 @@ import org.jclouds.http.handlers.RedirectionRetryHandler; import org.jclouds.http.internal.HttpWire; import org.jclouds.http.internal.JavaUrlHttpCommandExecutorService; import org.jclouds.io.ContentMetadataCodec; -import org.jclouds.rest.ConfiguresRestClient; -import org.jclouds.rest.config.RestClientModule; +import org.jclouds.rest.ConfiguresHttpApi; +import org.jclouds.rest.config.HttpApiModule; import com.google.common.base.Function; import com.google.common.base.Supplier; -import com.google.common.collect.ImmutableMap; import com.google.common.util.concurrent.ListeningExecutorService; /** @@ -73,18 +65,12 @@ import com.google.common.util.concurrent.ListeningExecutorService; * * @author Adrian Cole */ -@ConfiguresRestClient +@ConfiguresHttpApi // only one job at a time or error "This session already has a job running" @SingleThreaded -public class DynECTRestClientModule extends RestClientModule { +public class DynECTHttpApiModule extends HttpApiModule { - public static final Map, Class> DELEGATE_MAP = ImmutableMap., Class> builder() - .put(SessionApi.class, SessionAsyncApi.class) - .put(ZoneApi.class, ZoneAsyncApi.class) - .put(RecordApi.class, RecordAsyncApi.class).build(); - - public DynECTRestClientModule() { - super(DELEGATE_MAP); + public DynECTHttpApiModule() { } @Override @@ -105,16 +91,15 @@ public class DynECTRestClientModule extends RestClientModule list() throws JobStillRunningException; /** - * Retrieves a list of resource record ids for all records of the fqdn in the given zone + * Retrieves a list of resource record ids for all records of the fqdn in the + * given zone * * @throws JobStillRunningException * if a different job in the session is still running */ - FluentIterable listByFQDN(String fqdn) throws JobStillRunningException; + @Named("GetRecord") + @GET + @Path("/AllRecord/{zone}/{fqdn}") + @ResponseParser(ToRecordIds.class) + @Fallback(EmptyFluentIterableOnNotFoundOr404.class) + FluentIterable listByFQDN(@PathParam("fqdn") String fqdn) throws JobStillRunningException; /** - * Retrieves a list of resource record ids for all records of the fqdn and type in the given zone + * Retrieves a list of resource record ids for all records of the fqdn and + * type in the given zone * * @throws JobStillRunningException * if a different job in the session is still running */ - FluentIterable listByFQDNAndType(String fqdn, String type) throws JobStillRunningException; + @Named("GetRecord") + @GET + @Path("/{type}Record/{zone}/{fqdn}") + @ResponseParser(ToRecordIds.class) + @Fallback(EmptyFluentIterableOnNotFoundOr404.class) + FluentIterable listByFQDNAndType(@PathParam("fqdn") String fqdn, @PathParam("type") String type) + throws JobStillRunningException; /** - * Schedules addition of a new record into the current session. Calling {@link ZoneApi#publish(String)} will publish - * the zone, creating the record. + * Schedules addition of a new record into the current session. Calling + * {@link ZoneApi#publish(String)} will publish the zone, creating the + * record. * * @param newRecord * record to create @@ -79,20 +123,31 @@ public interface RecordApi { * @throws JobStillRunningException * if a different job in the session is still running */ - Job scheduleCreate(CreateRecord newRecord) throws JobStillRunningException; + @Named("CreateRecord") + @POST + @Path("/{type}Record/{zone}/{fqdn}") + @Consumes(APPLICATION_JSON) + @Produces(APPLICATION_JSON) + Job scheduleCreate(@BinderParam(CreateRecordBinder.class) CreateRecord newRecord) throws JobStillRunningException; /** - * Schedules deletion of a record into the current session. Calling {@link ZoneApi#publish(String)} will publish the - * changes, deleting the record. + * Schedules deletion of a record into the current session. Calling + * {@link ZoneApi#publish(String)} will publish the changes, deleting the + * record. * * @param recordId * record to delete - * @return job relating to the scheduled deletion or null, if the record never existed. + * @return job relating to the scheduled deletion or null, if the record + * never existed. * @throws JobStillRunningException * if a different job in the session is still running */ @Nullable - Job scheduleDelete(RecordId recordId) throws JobStillRunningException; + @Named("DeleteRecord") + @DELETE + @Fallback(NullOnNotFoundOr404.class) + @Consumes(APPLICATION_JSON) + Job scheduleDelete(@BinderParam(RecordIdBinder.class) RecordId recordId) throws JobStillRunningException; /** * retrieves a resource record without regard to type @@ -101,7 +156,13 @@ public interface RecordApi { * @throws JobStillRunningException * if a different job in the session is still running */ - Record> get(RecordId recordId) throws JobStillRunningException; + @Named("GetRecord") + @GET + @SelectJson("data") + @Fallback(NullOnNotFoundOr404.class) + @Nullable + Record> get(@BinderParam(RecordIdBinder.class) RecordId recordId) + throws JobStillRunningException; /** * Gets the {@link AAAARecord} or null if not present. @@ -114,7 +175,14 @@ public interface RecordApi { * @throws JobStillRunningException * if a different job in the session is still running */ - Record getAAAA(String fqdn, long recordId) throws JobStillRunningException; + @Named("GetAAAARecord") + @GET + @Path("/AAAARecord/{zone}/{fqdn}/{id}") + @SelectJson("data") + @Fallback(NullOnNotFoundOr404.class) + @Nullable + Record getAAAA(@PathParam("fqdn") String fqdn, @PathParam("id") long recordId) + throws JobStillRunningException; /** * Gets the {@link ARecord} or null if not present. @@ -127,7 +195,13 @@ public interface RecordApi { * @throws JobStillRunningException * if a different job in the session is still running */ - Record getA(String fqdn, long recordId) throws JobStillRunningException; + @Named("GetARecord") + @GET + @Path("/ARecord/{zone}/{fqdn}/{id}") + @SelectJson("data") + @Fallback(NullOnNotFoundOr404.class) + @Nullable + Record getA(@PathParam("fqdn") String fqdn, @PathParam("id") long recordId) throws JobStillRunningException; /** * Gets the {@link CNAMERecord} or null if not present. @@ -140,7 +214,14 @@ public interface RecordApi { * @throws JobStillRunningException * if a different job in the session is still running */ - Record getCNAME(String fqdn, long recordId) throws JobStillRunningException; + @Named("GetCNAMERecord") + @GET + @Path("/CNAMERecord/{zone}/{fqdn}/{id}") + @SelectJson("data") + @Fallback(NullOnNotFoundOr404.class) + @Nullable + Record getCNAME(@PathParam("fqdn") String fqdn, @PathParam("id") long recordId) + throws JobStillRunningException; /** * Gets the {@link MXRecord} or null if not present. @@ -153,7 +234,13 @@ public interface RecordApi { * @throws JobStillRunningException * if a different job in the session is still running */ - Record getMX(String fqdn, long recordId) throws JobStillRunningException; + @Named("GetMXRecord") + @GET + @Path("/MXRecord/{zone}/{fqdn}/{id}") + @SelectJson("data") + @Fallback(NullOnNotFoundOr404.class) + @Nullable + Record getMX(@PathParam("fqdn") String fqdn, @PathParam("id") long recordId) throws JobStillRunningException; /** * Gets the {@link NSRecord} or null if not present. @@ -166,7 +253,13 @@ public interface RecordApi { * @throws JobStillRunningException * if a different job in the session is still running */ - Record getNS(String fqdn, long recordId) throws JobStillRunningException; + @Named("GetNSRecord") + @GET + @Path("/NSRecord/{zone}/{fqdn}/{id}") + @SelectJson("data") + @Fallback(NullOnNotFoundOr404.class) + @Nullable + Record getNS(@PathParam("fqdn") String fqdn, @PathParam("id") long recordId) throws JobStillRunningException; /** * Gets the {@link PTRRecord} or null if not present. @@ -179,7 +272,14 @@ public interface RecordApi { * @throws JobStillRunningException * if a different job in the session is still running */ - Record getPTR(String fqdn, long recordId) throws JobStillRunningException; + @Named("GetPTRRecord") + @GET + @Path("/PTRRecord/{zone}/{fqdn}/{id}") + @SelectJson("data") + @Fallback(NullOnNotFoundOr404.class) + @Nullable + Record getPTR(@PathParam("fqdn") String fqdn, @PathParam("id") long recordId) + throws JobStillRunningException; /** * Gets the {@link SOARecord} or null if not present. @@ -192,7 +292,13 @@ public interface RecordApi { * @throws JobStillRunningException * if a different job in the session is still running */ - SOARecord getSOA(String fqdn, long recordId) throws JobStillRunningException; + @Named("GetSOARecord") + @GET + @Path("/SOARecord/{zone}/{fqdn}/{id}") + @SelectJson("data") + @Fallback(NullOnNotFoundOr404.class) + @Nullable + SOARecord getSOA(@PathParam("fqdn") String fqdn, @PathParam("id") long recordId) throws JobStillRunningException; /** * Gets the {@link SPFRecord} or null if not present. @@ -205,7 +311,14 @@ public interface RecordApi { * @throws JobStillRunningException * if a different job in the session is still running */ - Record getSPF(String fqdn, long recordId) throws JobStillRunningException; + @Named("GetSPFRecord") + @GET + @Path("/SPFRecord/{zone}/{fqdn}/{id}") + @SelectJson("data") + @Fallback(NullOnNotFoundOr404.class) + @Nullable + Record getSPF(@PathParam("fqdn") String fqdn, @PathParam("id") long recordId) + throws JobStillRunningException; /** * Gets the {@link SRVRecord} or null if not present. @@ -218,7 +331,14 @@ public interface RecordApi { * @throws JobStillRunningException * if a different job in the session is still running */ - Record getSRV(String fqdn, long recordId) throws JobStillRunningException; + @Named("GetSRVRecord") + @GET + @Path("/SRVRecord/{zone}/{fqdn}/{id}") + @SelectJson("data") + @Fallback(NullOnNotFoundOr404.class) + @Nullable + Record getSRV(@PathParam("fqdn") String fqdn, @PathParam("id") long recordId) + throws JobStillRunningException; /** * Gets the {@link SSHFPRecord} or null if not present. @@ -231,7 +351,14 @@ public interface RecordApi { * @throws JobStillRunningException * if a different job in the session is still running */ - Record getSSHFP(String fqdn, long recordId) throws JobStillRunningException; + @Named("GetSSHFPRecord") + @GET + @Path("/SSHFPRecord/{zone}/{fqdn}/{id}") + @SelectJson("data") + @Fallback(NullOnNotFoundOr404.class) + @Nullable + Record getSSHFP(@PathParam("fqdn") String fqdn, @PathParam("id") long recordId) + throws JobStillRunningException; /** * Gets the {@link TXTRecord} or null if not present. @@ -244,5 +371,12 @@ public interface RecordApi { * @throws JobStillRunningException * if a different job in the session is still running */ - Record getTXT(String fqdn, long recordId) throws JobStillRunningException; + @Named("GetTXTRecord") + @GET + @Path("/TXTRecord/{zone}/{fqdn}/{id}") + @SelectJson("data") + @Fallback(NullOnNotFoundOr404.class) + @Nullable + Record getTXT(@PathParam("fqdn") String fqdn, @PathParam("id") long recordId) + throws JobStillRunningException; } \ No newline at end of file diff --git a/providers/dynect/src/main/java/org/jclouds/dynect/v3/features/RecordAsyncApi.java b/providers/dynect/src/main/java/org/jclouds/dynect/v3/features/RecordAsyncApi.java deleted file mode 100644 index b6badf12cc..0000000000 --- a/providers/dynect/src/main/java/org/jclouds/dynect/v3/features/RecordAsyncApi.java +++ /dev/null @@ -1,291 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds licenses this file - * to you under the Apache License, 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.dynect.v3.features; - -import static com.google.common.base.Preconditions.checkNotNull; -import static javax.ws.rs.core.MediaType.APPLICATION_JSON; -import static org.jclouds.http.Uris.uriBuilder; - -import java.net.URI; -import java.util.Map; - -import javax.inject.Inject; -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.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; - -import org.jclouds.Fallbacks.EmptyFluentIterableOnNotFoundOr404; -import org.jclouds.Fallbacks.NullOnNotFoundOr404; -import org.jclouds.dynect.v3.DynECTExceptions.JobStillRunningException; -import org.jclouds.dynect.v3.domain.CreateRecord; -import org.jclouds.dynect.v3.domain.Job; -import org.jclouds.dynect.v3.domain.Record; -import org.jclouds.dynect.v3.domain.RecordId; -import org.jclouds.dynect.v3.domain.SOARecord; -import org.jclouds.dynect.v3.domain.rdata.AAAAData; -import org.jclouds.dynect.v3.domain.rdata.AData; -import org.jclouds.dynect.v3.domain.rdata.CNAMEData; -import org.jclouds.dynect.v3.domain.rdata.MXData; -import org.jclouds.dynect.v3.domain.rdata.NSData; -import org.jclouds.dynect.v3.domain.rdata.PTRData; -import org.jclouds.dynect.v3.domain.rdata.SPFData; -import org.jclouds.dynect.v3.domain.rdata.SRVData; -import org.jclouds.dynect.v3.domain.rdata.SSHFPData; -import org.jclouds.dynect.v3.domain.rdata.TXTData; -import org.jclouds.dynect.v3.filters.AlwaysAddContentType; -import org.jclouds.dynect.v3.filters.SessionManager; -import org.jclouds.dynect.v3.functions.ToRecordIds; -import org.jclouds.http.HttpRequest; -import org.jclouds.json.Json; -import org.jclouds.rest.Binder; -import org.jclouds.rest.annotations.BinderParam; -import org.jclouds.rest.annotations.Fallback; -import org.jclouds.rest.annotations.Headers; -import org.jclouds.rest.annotations.RequestFilters; -import org.jclouds.rest.annotations.ResponseParser; -import org.jclouds.rest.annotations.SelectJson; - -import com.google.common.collect.FluentIterable; -import com.google.common.collect.ImmutableMap; -import com.google.common.util.concurrent.ListenableFuture; - -/** - * - * @see RecordApi - * @see doc - * @author Adrian Cole - */ -@Headers(keys = "API-Version", values = "{jclouds.api-version}") -@RequestFilters({ AlwaysAddContentType.class, SessionManager.class }) -public interface RecordAsyncApi { - - /** - * @see RecordApi#list - */ - @Named("GetAllRecord") - @GET - @Path("/AllRecord/{zone}") - @ResponseParser(ToRecordIds.class) - ListenableFuture> list() throws JobStillRunningException; - - /** - * @see RecordApi#listByFQDN - */ - @Named("GetRecord") - @GET - @Path("/AllRecord/{zone}/{fqdn}") - @ResponseParser(ToRecordIds.class) - @Fallback(EmptyFluentIterableOnNotFoundOr404.class) - ListenableFuture> listByFQDN(@PathParam("fqdn") String fqdn) - throws JobStillRunningException; - - /** - * @see RecordApi#listByFQDNAndType - */ - @Named("GetRecord") - @GET - @Path("/{type}Record/{zone}/{fqdn}") - @ResponseParser(ToRecordIds.class) - @Fallback(EmptyFluentIterableOnNotFoundOr404.class) - ListenableFuture> listByFQDNAndType(@PathParam("fqdn") String fqdn, - @PathParam("type") String type) throws JobStillRunningException; - - /** - * @see RecordApi#scheduleCreate - */ - @Named("CreateRecord") - @POST - @Path("/{type}Record/{zone}/{fqdn}") - @Consumes(APPLICATION_JSON) - @Produces(APPLICATION_JSON) - ListenableFuture scheduleCreate(@BinderParam(CreateRecordBinder.class) CreateRecord newRecord) - throws JobStillRunningException; - - static class CreateRecordBinder implements Binder { - private final Json json; - - @Inject - CreateRecordBinder(Json json){ - this.json = checkNotNull(json, "json"); - } - - @SuppressWarnings("unchecked") - @Override - public R bindToRequest(R request, Object arg) { - CreateRecord in = CreateRecord.class.cast(checkNotNull(arg, "record to create")); - URI path = uriBuilder(request.getEndpoint()) - .build(ImmutableMap. builder() - .put("type", in.getType()) - .put("fqdn", in.getFQDN()).build()); - return (R) request.toBuilder() - .endpoint(path) - .payload(json.toJson(ImmutableMap.of("rdata", in.getRData(), "ttl", in.getTTL()))).build(); - } - } - - /** - * @see RecordApi#scheduleDelete - */ - @Named("DeleteRecord") - @DELETE - @Fallback(NullOnNotFoundOr404.class) - @Consumes(APPLICATION_JSON) - ListenableFuture scheduleDelete(@BinderParam(RecordIdBinder.class) RecordId recordId) throws JobStillRunningException; - - /** - * @see RecordApi#get - */ - @Named("GetRecord") - @GET - @SelectJson("data") - @Fallback(NullOnNotFoundOr404.class) - ListenableFuture>> get(@BinderParam(RecordIdBinder.class) RecordId recordId) throws JobStillRunningException; - - static class RecordIdBinder implements Binder { - @SuppressWarnings("unchecked") - @Override - public R bindToRequest(R request, Object recordId) { - RecordId valueToAppend = RecordId.class.cast(checkNotNull(recordId, "recordId")); - URI path = uriBuilder(request.getEndpoint()) - .appendPath("/{type}Record/{zone}/{fqdn}/{id}") - .build(ImmutableMap. builder() - .put("type", valueToAppend.getType()) - .put("zone", valueToAppend.getZone()) - .put("fqdn", valueToAppend.getFQDN()) - .put("id", valueToAppend.getId()).build()); - return (R) request.toBuilder().endpoint(path).build(); - } - } - - /** - * @see RecordApi#getAAAA - */ - @Named("GetAAAARecord") - @GET - @Path("/AAAARecord/{zone}/{fqdn}/{id}") - @SelectJson("data") - @Fallback(NullOnNotFoundOr404.class) - ListenableFuture> getAAAA(@PathParam("fqdn") String fqdn, @PathParam("id") long recordId) throws JobStillRunningException; - - /** - * @see RecordApi#getA - */ - @Named("GetARecord") - @GET - @Path("/ARecord/{zone}/{fqdn}/{id}") - @SelectJson("data") - @Fallback(NullOnNotFoundOr404.class) - ListenableFuture> getA(@PathParam("fqdn") String fqdn, @PathParam("id") long recordId) throws JobStillRunningException; - - /** - * @see RecordApi#getCNAME - */ - @Named("GetCNAMERecord") - @GET - @Path("/CNAMERecord/{zone}/{fqdn}/{id}") - @SelectJson("data") - @Fallback(NullOnNotFoundOr404.class) - ListenableFuture> getCNAME(@PathParam("fqdn") String fqdn, @PathParam("id") long recordId) throws JobStillRunningException; - - /** - * @see RecordApi#getMX - */ - @Named("GetMXRecord") - @GET - @Path("/MXRecord/{zone}/{fqdn}/{id}") - @SelectJson("data") - @Fallback(NullOnNotFoundOr404.class) - ListenableFuture> getMX(@PathParam("fqdn") String fqdn, @PathParam("id") long recordId) throws JobStillRunningException; - - /** - * @see RecordApi#getNS - */ - @Named("GetNSRecord") - @GET - @Path("/NSRecord/{zone}/{fqdn}/{id}") - @SelectJson("data") - @Fallback(NullOnNotFoundOr404.class) - ListenableFuture> getNS(@PathParam("fqdn") String fqdn, @PathParam("id") long recordId) throws JobStillRunningException; - - /** - * @see RecordApi#getPTR - */ - @Named("GetPTRRecord") - @GET - @Path("/PTRRecord/{zone}/{fqdn}/{id}") - @SelectJson("data") - @Fallback(NullOnNotFoundOr404.class) - ListenableFuture> getPTR(@PathParam("fqdn") String fqdn, @PathParam("id") long recordId) throws JobStillRunningException; - - /** - * @see RecordApi#getSOA - */ - @Named("GetSOARecord") - @GET - @Path("/SOARecord/{zone}/{fqdn}/{id}") - @SelectJson("data") - @Fallback(NullOnNotFoundOr404.class) - ListenableFuture getSOA(@PathParam("fqdn") String fqdn, @PathParam("id") long recordId) throws JobStillRunningException; - - /** - * @see RecordApi#getSPF - */ - @Named("GetSPFRecord") - @GET - @Path("/SPFRecord/{zone}/{fqdn}/{id}") - @SelectJson("data") - @Fallback(NullOnNotFoundOr404.class) - ListenableFuture> getSPF(@PathParam("fqdn") String fqdn, @PathParam("id") long recordId) throws JobStillRunningException; - - /** - * @see RecordApi#getSRV - */ - @Named("GetSRVRecord") - @GET - @Path("/SRVRecord/{zone}/{fqdn}/{id}") - @SelectJson("data") - @Fallback(NullOnNotFoundOr404.class) - ListenableFuture> getSRV(@PathParam("fqdn") String fqdn, @PathParam("id") long recordId) throws JobStillRunningException; - - /** - * @see RecordApi#getSSHFP - */ - @Named("GetSSHFPRecord") - @GET - @Path("/SSHFPRecord/{zone}/{fqdn}/{id}") - @SelectJson("data") - @Fallback(NullOnNotFoundOr404.class) - ListenableFuture> getSSHFP(@PathParam("fqdn") String fqdn, @PathParam("id") long recordId) throws JobStillRunningException; - - /** - * @see RecordApi#getTXT - */ - @Named("GetTXTRecord") - @GET - @Path("/TXTRecord/{zone}/{fqdn}/{id}") - @SelectJson("data") - @Fallback(NullOnNotFoundOr404.class) - ListenableFuture> getTXT(@PathParam("fqdn") String fqdn, @PathParam("id") long recordId) throws JobStillRunningException; -} diff --git a/providers/dynect/src/main/java/org/jclouds/dynect/v3/features/SessionApi.java b/providers/dynect/src/main/java/org/jclouds/dynect/v3/features/SessionApi.java index fc6fcf2816..ce0505b2df 100644 --- a/providers/dynect/src/main/java/org/jclouds/dynect/v3/features/SessionApi.java +++ b/providers/dynect/src/main/java/org/jclouds/dynect/v3/features/SessionApi.java @@ -18,21 +18,46 @@ */ package org.jclouds.dynect.v3.features; +import javax.inject.Named; +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.HeaderParam; +import javax.ws.rs.POST; +import javax.ws.rs.Path; + +import org.jclouds.dynect.v3.DynECTFallbacks.FalseOn400; import org.jclouds.dynect.v3.domain.Session; import org.jclouds.dynect.v3.domain.SessionCredentials; +import org.jclouds.dynect.v3.filters.AlwaysAddContentType; +import org.jclouds.rest.annotations.BinderParam; +import org.jclouds.rest.annotations.Fallback; +import org.jclouds.rest.annotations.Headers; +import org.jclouds.rest.annotations.RequestFilters; +import org.jclouds.rest.annotations.SelectJson; +import org.jclouds.rest.binders.BindToJsonPayload; /** - * @see SessionAsyncApi * @see * @author Adrian Cole */ +@Headers(keys = "API-Version", values = "{jclouds.api-version}") +@Path("/Session") +@RequestFilters(AlwaysAddContentType.class) public interface SessionApi { - Session login(SessionCredentials credentials); + @Named("POST:Session") + @POST + @SelectJson("data") + Session login(@BinderParam(BindToJsonPayload.class) SessionCredentials credentials); - boolean isValid(String token); + @Named("GET:Session") + @GET + @Fallback(FalseOn400.class) + boolean isValid(@HeaderParam("Auth-Token") String token); - void logout(String token); + @Named("DELETE:Session") + @DELETE + void logout(@HeaderParam("Auth-Token") String token); } \ No newline at end of file diff --git a/providers/dynect/src/main/java/org/jclouds/dynect/v3/features/SessionAsyncApi.java b/providers/dynect/src/main/java/org/jclouds/dynect/v3/features/SessionAsyncApi.java deleted file mode 100644 index 5eabd50f95..0000000000 --- a/providers/dynect/src/main/java/org/jclouds/dynect/v3/features/SessionAsyncApi.java +++ /dev/null @@ -1,76 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.jclouds.dynect.v3.features; - -import javax.inject.Named; -import javax.ws.rs.DELETE; -import javax.ws.rs.GET; -import javax.ws.rs.HeaderParam; -import javax.ws.rs.POST; -import javax.ws.rs.Path; - -import org.jclouds.dynect.v3.DynECTFallbacks.FalseOn400; -import org.jclouds.dynect.v3.domain.Session; -import org.jclouds.dynect.v3.domain.SessionCredentials; -import org.jclouds.dynect.v3.filters.AlwaysAddContentType; -import org.jclouds.rest.annotations.BinderParam; -import org.jclouds.rest.annotations.Fallback; -import org.jclouds.rest.annotations.Headers; -import org.jclouds.rest.annotations.RequestFilters; -import org.jclouds.rest.annotations.SelectJson; -import org.jclouds.rest.binders.BindToJsonPayload; - -import com.google.common.util.concurrent.ListenableFuture; - -/** - * Provides access to DynECT Managed DNS through the API2 api - *

- * - * @see SessionApi - * @see - * @author Adrian Cole - */ -@Headers(keys = "API-Version", values = "{jclouds.api-version}") -@Path("/Session") -@RequestFilters(AlwaysAddContentType.class) -public interface SessionAsyncApi { - - /** - * @see SessionApi#create - */ - @Named("POST:Session") - @POST - @SelectJson("data") - ListenableFuture login(@BinderParam(BindToJsonPayload.class) SessionCredentials credentials); - - /** - * @see SessionApi#isValid - */ - @Named("GET:Session") - @GET - @Fallback(FalseOn400.class) - ListenableFuture isValid(@HeaderParam("Auth-Token") String token); - - /** - * @see SessionApi#logout - */ - @Named("DELETE:Session") - @DELETE - ListenableFuture logout(@HeaderParam("Auth-Token") String token); -} diff --git a/providers/dynect/src/main/java/org/jclouds/dynect/v3/features/ZoneApi.java b/providers/dynect/src/main/java/org/jclouds/dynect/v3/features/ZoneApi.java index 0ebde9fdc1..e90d1d4cef 100644 --- a/providers/dynect/src/main/java/org/jclouds/dynect/v3/features/ZoneApi.java +++ b/providers/dynect/src/main/java/org/jclouds/dynect/v3/features/ZoneApi.java @@ -18,21 +18,49 @@ */ package org.jclouds.dynect.v3.features; +import static javax.ws.rs.core.MediaType.APPLICATION_JSON; + +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 org.jclouds.Fallbacks.NullOnNotFoundOr404; import org.jclouds.dynect.v3.DynECTExceptions.JobStillRunningException; import org.jclouds.dynect.v3.DynECTExceptions.TargetExistsException; import org.jclouds.dynect.v3.domain.CreatePrimaryZone; +import org.jclouds.dynect.v3.domain.CreatePrimaryZone.ToFQDN; import org.jclouds.dynect.v3.domain.Job; import org.jclouds.dynect.v3.domain.Zone; import org.jclouds.dynect.v3.domain.Zone.SerialStyle; +import org.jclouds.dynect.v3.filters.AlwaysAddContentType; +import org.jclouds.dynect.v3.filters.SessionManager; +import org.jclouds.dynect.v3.functions.ExtractZoneNames; import org.jclouds.javax.annotation.Nullable; import org.jclouds.rest.ResourceNotFoundException; +import org.jclouds.rest.annotations.BinderParam; +import org.jclouds.rest.annotations.Fallback; +import org.jclouds.rest.annotations.Headers; +import org.jclouds.rest.annotations.ParamParser; +import org.jclouds.rest.annotations.Payload; +import org.jclouds.rest.annotations.PayloadParam; +import org.jclouds.rest.annotations.RequestFilters; +import org.jclouds.rest.annotations.SelectJson; +import org.jclouds.rest.annotations.Transform; +import org.jclouds.rest.binders.BindToJsonPayload; import com.google.common.collect.FluentIterable; /** - * @see ZoneAsyncApi * @author Adrian Cole */ +@Headers(keys = "API-Version", values = "{jclouds.api-version}") +@RequestFilters({ AlwaysAddContentType.class, SessionManager.class }) public interface ZoneApi { /** * Lists all zone ids. @@ -40,11 +68,16 @@ public interface ZoneApi { * @throws JobStillRunningException * if a different job in the session is still running */ + @Named("ListZones") + @GET + @Path("/Zone") + @SelectJson("data") + @Transform(ExtractZoneNames.class) FluentIterable list() throws JobStillRunningException; /** - * Schedules addition of a new primary zone into the current session. Calling {@link ZoneApi#publish(String)} will - * publish the zone, creating the zone. + * Schedules addition of a new primary zone into the current session. Calling + * {@link ZoneApi#publish(String)} will publish the zone, creating the zone. * * @param zone * required parameters to create the zone. @@ -54,11 +87,18 @@ public interface ZoneApi { * @throws TargetExistsException * if the same fqdn exists */ - Job scheduleCreate(CreatePrimaryZone zone) throws JobStillRunningException, TargetExistsException; + @Named("CreatePrimaryZone") + @POST + @Path("/Zone/{fqdn}") + @Consumes(APPLICATION_JSON) + Job scheduleCreate( + @PathParam("fqdn") @ParamParser(ToFQDN.class) @BinderParam(BindToJsonPayload.class) CreatePrimaryZone createZone) + throws JobStillRunningException, TargetExistsException; /** - * Schedules addition of a new primary zone with one hour default TTL and {@link SerialStyle#INCREMENT} into the - * current session. Calling {@link ZoneApi#publish(String)} will publish the zone, creating the zone. + * Schedules addition of a new primary zone with one hour default TTL and + * {@link SerialStyle#INCREMENT} into the current session. Calling + * {@link ZoneApi#publish(String)} will publish the zone, creating the zone. * * @param fqdn * fqdn of the zone to create {@ex. jclouds.org} @@ -70,42 +110,65 @@ public interface ZoneApi { * @throws TargetExistsException * if the same fqdn exists */ - Job scheduleCreateWithContact(String fqdn, String contact) throws JobStillRunningException, TargetExistsException; + @Named("CreatePrimaryZone") + @POST + @Produces(APPLICATION_JSON) + @Payload("%7B\"rname\":\"{contact}\",\"serial_style\":\"increment\",\"ttl\":3600%7D") + @Path("/Zone/{fqdn}") + @Consumes(APPLICATION_JSON) + Job scheduleCreateWithContact(@PathParam("fqdn") String fqdn, @PayloadParam("contact") String contact) + throws JobStillRunningException, TargetExistsException; /** * Retrieves information about the specified zone. * * @param fqdn - * fqdn of the zone to get information about. ex {@code jclouds.org} + * fqdn of the zone to get information about. ex + * {@code jclouds.org} * @return null if not found * @throws JobStillRunningException * if a different job in the session is still running */ + @Named("GetZone") + @GET + @Path("/Zone/{fqdn}") + @SelectJson("data") + @Fallback(NullOnNotFoundOr404.class) @Nullable - Zone get(String fqdn) throws JobStillRunningException; + Zone get(@PathParam("fqdn") String fqdn) throws JobStillRunningException; /** - * Deletes the zone. No need to call @link ZoneApi#publish(String)}. + * Deletes the zone. No need to call @link ZoneApi#publish(String)}. * * @param fqdn * zone to delete - * @return job relating to the scheduled deletion or null, if the zone never existed. + * @return job relating to the scheduled deletion or null, if the zone never + * existed. * @throws JobStillRunningException * if a different job in the session is still running */ + @Named("DeleteZone") + @DELETE + @Path("/Zone/{fqdn}") + @Fallback(NullOnNotFoundOr404.class) + @Consumes(APPLICATION_JSON) @Nullable - Job delete(String fqdn) throws JobStillRunningException; + Job delete(@PathParam("fqdn") String fqdn) throws JobStillRunningException; /** - * Deletes changes to the specified zone that have been created during the current session but not yet published to - * the zone. + * Deletes changes to the specified zone that have been created during the + * current session but not yet published to the zone. * * @param fqdn * fqdn of the zone to delete changes from ex {@code jclouds.org} * @throws JobStillRunningException * if a different job in the session is still running */ - Job deleteChanges(String fqdn) throws JobStillRunningException; + @Named("DeleteZoneChanges") + @DELETE + @Path("/ZoneChanges/{fqdn}") + @Consumes(APPLICATION_JSON) + Job deleteChanges(@PathParam("fqdn") String fqdn) throws JobStillRunningException; /** * Publishes the current zone @@ -117,7 +180,13 @@ public interface ZoneApi { * @throws ResourceNotFoundException * if the zone doesn't exist */ - Zone publish(String fqdn) throws JobStillRunningException, ResourceNotFoundException; + @Named("PublishZone") + @PUT + @Path("/Zone/{fqdn}") + @Produces(APPLICATION_JSON) + @Payload("{\"publish\":true}") + @SelectJson("data") + Zone publish(@PathParam("fqdn") String fqdn) throws JobStillRunningException, ResourceNotFoundException; /** * freezes the specified zone. @@ -127,7 +196,13 @@ public interface ZoneApi { * @throws JobStillRunningException * if a different job in the session is still running */ - Job freeze(String fqdn) throws JobStillRunningException; + @Named("FreezeZone") + @PUT + @Path("/Zone/{fqdn}") + @Produces(APPLICATION_JSON) + @Payload("{\"freeze\":true}") + @Consumes(APPLICATION_JSON) + Job freeze(@PathParam("fqdn") String fqdn) throws JobStillRunningException; /** * thaws the specified zone. @@ -137,5 +212,11 @@ public interface ZoneApi { * @throws JobStillRunningException * if a different job in the session is still running */ - Job thaw(String fqdn) throws JobStillRunningException; + @Named("ThawZone") + @PUT + @Path("/Zone/{fqdn}") + @Produces(APPLICATION_JSON) + @Payload("{\"thaw\":true}") + @Consumes(APPLICATION_JSON) + Job thaw(@PathParam("fqdn") String fqdn) throws JobStillRunningException; } \ No newline at end of file diff --git a/providers/dynect/src/main/java/org/jclouds/dynect/v3/features/ZoneAsyncApi.java b/providers/dynect/src/main/java/org/jclouds/dynect/v3/features/ZoneAsyncApi.java deleted file mode 100644 index 8569b814be..0000000000 --- a/providers/dynect/src/main/java/org/jclouds/dynect/v3/features/ZoneAsyncApi.java +++ /dev/null @@ -1,163 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds licenses this file - * to you under the Apache License, 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.dynect.v3.features; - -import static javax.ws.rs.core.MediaType.APPLICATION_JSON; - -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 org.jclouds.Fallbacks.NullOnNotFoundOr404; -import org.jclouds.dynect.v3.DynECTExceptions.JobStillRunningException; -import org.jclouds.dynect.v3.DynECTExceptions.TargetExistsException; -import org.jclouds.dynect.v3.domain.CreatePrimaryZone; -import org.jclouds.dynect.v3.domain.CreatePrimaryZone.ToFQDN; -import org.jclouds.dynect.v3.domain.Job; -import org.jclouds.dynect.v3.domain.Zone; -import org.jclouds.dynect.v3.filters.AlwaysAddContentType; -import org.jclouds.dynect.v3.filters.SessionManager; -import org.jclouds.dynect.v3.functions.ExtractZoneNames; -import org.jclouds.rest.ResourceNotFoundException; -import org.jclouds.rest.annotations.BinderParam; -import org.jclouds.rest.annotations.Fallback; -import org.jclouds.rest.annotations.Headers; -import org.jclouds.rest.annotations.ParamParser; -import org.jclouds.rest.annotations.Payload; -import org.jclouds.rest.annotations.PayloadParam; -import org.jclouds.rest.annotations.RequestFilters; -import org.jclouds.rest.annotations.SelectJson; -import org.jclouds.rest.annotations.Transform; -import org.jclouds.rest.binders.BindToJsonPayload; - -import com.google.common.collect.FluentIterable; -import com.google.common.util.concurrent.ListenableFuture; - -/** - * - * @see ZoneApi - * @see doc - * @author Adrian Cole - */ -@Headers(keys = "API-Version", values = "{jclouds.api-version}") -@RequestFilters({ AlwaysAddContentType.class, SessionManager.class }) -public interface ZoneAsyncApi { - - /** - * @see ZoneApi#list - */ - @Named("ListZones") - @GET - @Path("/Zone") - @SelectJson("data") - @Transform(ExtractZoneNames.class) - ListenableFuture> list() throws JobStillRunningException; - - /** - * @see ZoneApi#get - */ - @Named("GetZone") - @GET - @Path("/Zone/{fqdn}") - @SelectJson("data") - @Fallback(NullOnNotFoundOr404.class) - ListenableFuture get(@PathParam("fqdn") String fqdn) throws JobStillRunningException; - - /** - * @see ZoneApi#scheduleCreate - */ - @Named("CreatePrimaryZone") - @POST - @Path("/Zone/{fqdn}") - @Consumes(APPLICATION_JSON) - ListenableFuture scheduleCreate( - @PathParam("fqdn") @ParamParser(ToFQDN.class) @BinderParam(BindToJsonPayload.class) CreatePrimaryZone createZone) - throws JobStillRunningException, TargetExistsException; - - /** - * @see ZoneApi#scheduleCreateWithContact - */ - @Named("CreatePrimaryZone") - @POST - @Produces(APPLICATION_JSON) - @Payload("%7B\"rname\":\"{contact}\",\"serial_style\":\"increment\",\"ttl\":3600%7D") - @Path("/Zone/{fqdn}") - @Consumes(APPLICATION_JSON) - ListenableFuture scheduleCreateWithContact(@PathParam("fqdn") String fqdn, - @PayloadParam("contact") String contact) throws JobStillRunningException, TargetExistsException; - - /** - * @see ZoneApi#delete - */ - @Named("DeleteZone") - @DELETE - @Path("/Zone/{fqdn}") - @Fallback(NullOnNotFoundOr404.class) - @Consumes(APPLICATION_JSON) - ListenableFuture delete(@PathParam("fqdn") String fqdn) throws JobStillRunningException; - - /** - * @see ZoneApi#deleteChanges - */ - @Named("DeleteZoneChanges") - @DELETE - @Path("/ZoneChanges/{fqdn}") - @Consumes(APPLICATION_JSON) - ListenableFuture deleteChanges(@PathParam("fqdn") String fqdn) throws JobStillRunningException; - - /** - * @see ZoneApi#publish - */ - @Named("PublishZone") - @PUT - @Path("/Zone/{fqdn}") - @Produces(APPLICATION_JSON) - @Payload("{\"publish\":true}") - @SelectJson("data") - ListenableFuture publish(@PathParam("fqdn") String fqdn) throws JobStillRunningException, ResourceNotFoundException; - - /** - * @see ZoneApi#freeze - */ - @Named("FreezeZone") - @PUT - @Path("/Zone/{fqdn}") - @Produces(APPLICATION_JSON) - @Payload("{\"freeze\":true}") - @Consumes(APPLICATION_JSON) - ListenableFuture freeze(@PathParam("fqdn") String fqdn) throws JobStillRunningException; - - /** - * @see ZoneApi#thaw - */ - @Named("ThawZone") - @PUT - @Path("/Zone/{fqdn}") - @Produces(APPLICATION_JSON) - @Payload("{\"thaw\":true}") - @Consumes(APPLICATION_JSON) - ListenableFuture thaw(@PathParam("fqdn") String fqdn) throws JobStillRunningException; -} diff --git a/providers/dynect/src/test/java/org/jclouds/dynect/v3/internal/BaseDynECTExpectTest.java b/providers/dynect/src/test/java/org/jclouds/dynect/v3/internal/BaseDynECTExpectTest.java index 89ed0a5770..d502bfbb60 100644 --- a/providers/dynect/src/test/java/org/jclouds/dynect/v3/internal/BaseDynECTExpectTest.java +++ b/providers/dynect/src/test/java/org/jclouds/dynect/v3/internal/BaseDynECTExpectTest.java @@ -20,13 +20,13 @@ package org.jclouds.dynect.v3.internal; import static javax.ws.rs.core.MediaType.APPLICATION_JSON; -import org.jclouds.dynect.v3.config.DynECTRestClientModule; +import org.jclouds.dynect.v3.config.DynECTHttpApiModule; import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpResponse; import org.jclouds.http.config.SSLModule; import org.jclouds.io.Payload; import org.jclouds.io.Payloads; -import org.jclouds.rest.ConfiguresRestClient; +import org.jclouds.rest.ConfiguresHttpApi; import org.jclouds.rest.internal.BaseRestApiExpectTest; import com.google.inject.Module; @@ -45,11 +45,11 @@ public class BaseDynECTExpectTest extends BaseRestApiExpectTest { @Override protected Module createModule() { - return new TestDynECTRestClientModule(); + return new TestDynECTHttpApiModule(); } - @ConfiguresRestClient - private static final class TestDynECTRestClientModule extends DynECTRestClientModule { + @ConfiguresHttpApi + private static final class TestDynECTHttpApiModule extends DynECTHttpApiModule { @Override protected void configure() { install(new SSLModule());