From 0a1730fb892af5712e5a5627953440ed6474b241 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Sun, 3 Mar 2013 11:56:22 -0800 Subject: [PATCH] in dynect, most mutations are actually scheduling --- .../jclouds/dynect/v3/features/ZoneApi.java | 63 +++++++++++++------ .../dynect/v3/features/ZoneAsyncApi.java | 17 ++--- .../dynect/v3/features/ZoneApiExpectTest.java | 23 ++++--- .../dynect/v3/features/ZoneApiLiveTest.java | 13 ++-- 4 files changed, 73 insertions(+), 43 deletions(-) diff --git a/labs/dynect/src/main/java/org/jclouds/dynect/v3/features/ZoneApi.java b/labs/dynect/src/main/java/org/jclouds/dynect/v3/features/ZoneApi.java index b9cf4a5867..0ebde9fdc1 100644 --- a/labs/dynect/src/main/java/org/jclouds/dynect/v3/features/ZoneApi.java +++ b/labs/dynect/src/main/java/org/jclouds/dynect/v3/features/ZoneApi.java @@ -18,13 +18,14 @@ */ package org.jclouds.dynect.v3.features; -import org.jclouds.dynect.v3.DynECTExceptions.TargetExistsException; 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.Job; import org.jclouds.dynect.v3.domain.Zone; import org.jclouds.dynect.v3.domain.Zone.SerialStyle; import org.jclouds.javax.annotation.Nullable; +import org.jclouds.rest.ResourceNotFoundException; import com.google.common.collect.FluentIterable; @@ -35,57 +36,74 @@ import com.google.common.collect.FluentIterable; public interface ZoneApi { /** * Lists all zone ids. + * + * @throws JobStillRunningException + * if a different job in the session is still running */ FluentIterable list() throws JobStillRunningException; /** - * Creates a new primary 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. - * @return unpublished zone + * @return job relating to the scheduled creation. + * @throws JobStillRunningException + * if a different job in the session is still running + * @throws TargetExistsException + * if the same fqdn exists */ - Zone create(CreatePrimaryZone zone) throws JobStillRunningException, TargetExistsException; + Job scheduleCreate(CreatePrimaryZone zone) throws JobStillRunningException, TargetExistsException; /** - * Creates a new primary zone with one hour default TTL and - * {@link SerialStyle#INCREMENT} + * 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} * @param contact * email address of the contact - * @return unpublished zone + * @return job relating to the scheduled creation. + * @throws JobStillRunningException + * if a different job in the session is still running + * @throws TargetExistsException + * if the same fqdn exists */ - Zone createWithContact(String fqdn, String contact) throws JobStillRunningException, TargetExistsException; + Job scheduleCreateWithContact(String fqdn, 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 */ @Nullable Zone get(String fqdn) throws JobStillRunningException; /** - * deletes the specified zone. + * Deletes the zone. No need to call @link ZoneApi#publish(String)}. * * @param fqdn - * fqdn of the zone to delete ex {@code jclouds.org} - * @return null if not found + * zone to delete + * @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 */ @Nullable Job delete(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; @@ -93,24 +111,31 @@ public interface ZoneApi { * Publishes the current zone * * @param fqdn - * fqdn of the zone to publish. ex - * {@code jclouds.org} + * fqdn of the zone to publish. ex {@code jclouds.org} + * @throws JobStillRunningException + * if a different job in the session is still running + * @throws ResourceNotFoundException + * if the zone doesn't exist */ - Zone publish(String fqdn) throws JobStillRunningException; + Zone publish(String fqdn) throws JobStillRunningException, ResourceNotFoundException; /** * freezes the specified zone. * * @param fqdn * fqdn of the zone to freeze ex {@code jclouds.org} + * @throws JobStillRunningException + * if a different job in the session is still running */ Job freeze(String fqdn) throws JobStillRunningException; - + /** * thaws the specified zone. * * @param fqdn * fqdn of the zone to thaw ex {@code jclouds.org} + * @throws JobStillRunningException + * if a different job in the session is still running */ Job thaw(String fqdn) throws JobStillRunningException; } \ No newline at end of file diff --git a/labs/dynect/src/main/java/org/jclouds/dynect/v3/features/ZoneAsyncApi.java b/labs/dynect/src/main/java/org/jclouds/dynect/v3/features/ZoneAsyncApi.java index 8aa23360f1..8569b814be 100644 --- a/labs/dynect/src/main/java/org/jclouds/dynect/v3/features/ZoneAsyncApi.java +++ b/labs/dynect/src/main/java/org/jclouds/dynect/v3/features/ZoneAsyncApi.java @@ -40,6 +40,7 @@ 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; @@ -86,27 +87,27 @@ public interface ZoneAsyncApi { ListenableFuture get(@PathParam("fqdn") String fqdn) throws JobStillRunningException; /** - * @see ZoneApi#create + * @see ZoneApi#scheduleCreate */ @Named("CreatePrimaryZone") @POST @Path("/Zone/{fqdn}") - @SelectJson("data") - ListenableFuture create( + @Consumes(APPLICATION_JSON) + ListenableFuture scheduleCreate( @PathParam("fqdn") @ParamParser(ToFQDN.class) @BinderParam(BindToJsonPayload.class) CreatePrimaryZone createZone) throws JobStillRunningException, TargetExistsException; /** - * @see ZoneApi#createWithContact + * @see ZoneApi#scheduleCreateWithContact */ @Named("CreatePrimaryZone") @POST @Produces(APPLICATION_JSON) @Payload("%7B\"rname\":\"{contact}\",\"serial_style\":\"increment\",\"ttl\":3600%7D") @Path("/Zone/{fqdn}") - @SelectJson("data") - ListenableFuture createWithContact(@PathParam("fqdn") String fqdn, @PayloadParam("contact") String contact) - throws JobStillRunningException, TargetExistsException; + @Consumes(APPLICATION_JSON) + ListenableFuture scheduleCreateWithContact(@PathParam("fqdn") String fqdn, + @PayloadParam("contact") String contact) throws JobStillRunningException, TargetExistsException; /** * @see ZoneApi#delete @@ -136,7 +137,7 @@ public interface ZoneAsyncApi { @Produces(APPLICATION_JSON) @Payload("{\"publish\":true}") @SelectJson("data") - ListenableFuture publish(@PathParam("fqdn") String fqdn) throws JobStillRunningException; + ListenableFuture publish(@PathParam("fqdn") String fqdn) throws JobStillRunningException, ResourceNotFoundException; /** * @see ZoneApi#freeze diff --git a/labs/dynect/src/test/java/org/jclouds/dynect/v3/features/ZoneApiExpectTest.java b/labs/dynect/src/test/java/org/jclouds/dynect/v3/features/ZoneApiExpectTest.java index c5ca17c1f4..e6cf359975 100644 --- a/labs/dynect/src/test/java/org/jclouds/dynect/v3/features/ZoneApiExpectTest.java +++ b/labs/dynect/src/test/java/org/jclouds/dynect/v3/features/ZoneApiExpectTest.java @@ -26,6 +26,7 @@ import static org.testng.Assert.assertNull; import org.jclouds.dynect.v3.DynECTApi; import org.jclouds.dynect.v3.domain.CreatePrimaryZone; +import org.jclouds.dynect.v3.domain.Job; import org.jclouds.dynect.v3.internal.BaseDynECTApiExpectTest; import org.jclouds.dynect.v3.parse.DeleteZoneChangesResponseTest; import org.jclouds.dynect.v3.parse.DeleteZoneResponseTest; @@ -54,27 +55,29 @@ public class ZoneApiExpectTest extends BaseDynECTApiExpectTest { assertEquals(success.getZoneApi().get("jclouds.org").toString(), new GetZoneResponseTest().expected().toString()); } - + HttpRequest create = HttpRequest.builder().method("POST") .endpoint("https://api2.dynect.net/REST/Zone/jclouds.org") .addHeader("API-Version", "3.3.8") + .addHeader(ACCEPT, APPLICATION_JSON) .addHeader("Auth-Token", authToken) .payload(stringPayload("{\"rname\":\"jimmy@jclouds.org\",\"serial_style\":\"increment\",\"ttl\":3600}")) .build(); + HttpResponse createResponse = HttpResponse.builder().statusCode(200) + .payload(payloadFromResourceWithContentType("/new_zone.json", APPLICATION_JSON)).build(); + public void testCreateWhenResponseIs2xx() { - DynECTApi success = requestsSendResponses(createSession, createSessionResponse, create, getResponse); - assertEquals(success.getZoneApi().create(CreatePrimaryZone.builder() - .fqdn("jclouds.org") - .contact("jimmy@jclouds.org") - .build()).toString(), - new GetZoneResponseTest().expected().toString()); + DynECTApi success = requestsSendResponses(createSession, createSessionResponse, create, createResponse); + assertEquals(success.getZoneApi().scheduleCreate(CreatePrimaryZone.builder() + .fqdn("jclouds.org") + .contact("jimmy@jclouds.org") + .build()), Job.success(285351593l)); } public void testCreateWithContactWhenResponseIs2xx() { - DynECTApi success = requestsSendResponses(createSession, createSessionResponse, create, getResponse); - assertEquals(success.getZoneApi().createWithContact("jclouds.org", "jimmy@jclouds.org").toString(), - new GetZoneResponseTest().expected().toString()); + DynECTApi success = requestsSendResponses(createSession, createSessionResponse, create, createResponse); + assertEquals(success.getZoneApi().scheduleCreateWithContact("jclouds.org", "jimmy@jclouds.org"), Job.success(285351593l)); } public void testGetWhenResponseIs404() { diff --git a/labs/dynect/src/test/java/org/jclouds/dynect/v3/features/ZoneApiLiveTest.java b/labs/dynect/src/test/java/org/jclouds/dynect/v3/features/ZoneApiLiveTest.java index 231c9f5402..afd39847ea 100644 --- a/labs/dynect/src/test/java/org/jclouds/dynect/v3/features/ZoneApiLiveTest.java +++ b/labs/dynect/src/test/java/org/jclouds/dynect/v3/features/ZoneApiLiveTest.java @@ -67,14 +67,15 @@ public class ZoneApiLiveTest extends BaseDynECTApiLiveTest { } String fqdn = System.getProperty("user.name").replace('.', '-') + ".zone.dynecttest.jclouds.org"; - String contact = JcloudsVersion.get() + "@jclouds.org"; + String contact = JcloudsVersion.get() + ".jclouds.org"; @Test public void testCreateZone() { - Zone zone = api().createWithContact(fqdn, contact); - checkNotNull(zone, "unable to create zone %s", fqdn); - getAnonymousLogger().info("created zone: " + zone); - checkZone(zone); + Job job = api().scheduleCreateWithContact(fqdn, contact); + checkNotNull(job, "unable to create zone %s", fqdn); + getAnonymousLogger().info("created zone: " + job); + assertEquals(job.getStatus(), Status.SUCCESS); + assertEquals(context.getApi().getJob(job.getId()), job); } @Test(dependsOnMethods = "testCreateZone") @@ -121,7 +122,7 @@ public class ZoneApiLiveTest extends BaseDynECTApiLiveTest { } @Override - @AfterClass(groups = "live") + @AfterClass(groups = "live", alwaysRun = true) protected void tearDownContext() { api().delete(fqdn); super.tearDownContext();