in dynect, most mutations are actually scheduling

This commit is contained in:
Adrian Cole 2013-03-03 11:56:22 -08:00 committed by adriancole
parent 1ab2bea92a
commit 0a1730fb89
4 changed files with 73 additions and 43 deletions

View File

@ -18,13 +18,14 @@
*/ */
package org.jclouds.dynect.v3.features; 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.JobStillRunningException;
import org.jclouds.dynect.v3.DynECTExceptions.TargetExistsException;
import org.jclouds.dynect.v3.domain.CreatePrimaryZone; import org.jclouds.dynect.v3.domain.CreatePrimaryZone;
import org.jclouds.dynect.v3.domain.Job; import org.jclouds.dynect.v3.domain.Job;
import org.jclouds.dynect.v3.domain.Zone; import org.jclouds.dynect.v3.domain.Zone;
import org.jclouds.dynect.v3.domain.Zone.SerialStyle; import org.jclouds.dynect.v3.domain.Zone.SerialStyle;
import org.jclouds.javax.annotation.Nullable; import org.jclouds.javax.annotation.Nullable;
import org.jclouds.rest.ResourceNotFoundException;
import com.google.common.collect.FluentIterable; import com.google.common.collect.FluentIterable;
@ -35,57 +36,74 @@ import com.google.common.collect.FluentIterable;
public interface ZoneApi { public interface ZoneApi {
/** /**
* Lists all zone ids. * Lists all zone ids.
*
* @throws JobStillRunningException
* if a different job in the session is still running
*/ */
FluentIterable<String> list() throws JobStillRunningException; FluentIterable<String> 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 * @param zone
* required parameters to create the 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 * Schedules addition of a new primary zone with one hour default TTL and {@link SerialStyle#INCREMENT} into the
* {@link SerialStyle#INCREMENT} * current session. Calling {@link ZoneApi#publish(String)} will publish the zone, creating the zone.
* *
* @param fqdn * @param fqdn
* fqdn of the zone to create {@ex. jclouds.org} * fqdn of the zone to create {@ex. jclouds.org}
* @param contact * @param contact
* email address of the 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. * Retrieves information about the specified zone.
* *
* @param fqdn * @param fqdn
* fqdn of the zone to get information about. ex * fqdn of the zone to get information about. ex {@code jclouds.org}
* {@code jclouds.org}
* @return null if not found * @return null if not found
* @throws JobStillRunningException
* if a different job in the session is still running
*/ */
@Nullable @Nullable
Zone get(String fqdn) throws JobStillRunningException; Zone get(String fqdn) throws JobStillRunningException;
/** /**
* deletes the specified zone. * Deletes the zone. No need to call @link ZoneApi#publish(String)}.
* *
* @param fqdn * @param fqdn
* fqdn of the zone to delete ex {@code jclouds.org} * zone to delete
* @return null if not found * @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 @Nullable
Job delete(String fqdn) throws JobStillRunningException; Job delete(String fqdn) throws JobStillRunningException;
/** /**
* Deletes changes to the specified zone that have been created during the * Deletes changes to the specified zone that have been created during the current session but not yet published to
* current session but not yet published to the zone. * the zone.
* *
* @param fqdn * @param fqdn
* fqdn of the zone to delete changes from ex {@code jclouds.org} * 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; Job deleteChanges(String fqdn) throws JobStillRunningException;
@ -93,24 +111,31 @@ public interface ZoneApi {
* Publishes the current zone * Publishes the current zone
* *
* @param fqdn * @param fqdn
* fqdn of the zone to publish. ex * fqdn of the zone to publish. ex {@code jclouds.org}
* {@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. * freezes the specified zone.
* *
* @param fqdn * @param fqdn
* fqdn of the zone to freeze ex {@code jclouds.org} * 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; Job freeze(String fqdn) throws JobStillRunningException;
/** /**
* thaws the specified zone. * thaws the specified zone.
* *
* @param fqdn * @param fqdn
* fqdn of the zone to thaw ex {@code jclouds.org} * 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; Job thaw(String fqdn) throws JobStillRunningException;
} }

View File

@ -40,6 +40,7 @@ import org.jclouds.dynect.v3.domain.Zone;
import org.jclouds.dynect.v3.filters.AlwaysAddContentType; import org.jclouds.dynect.v3.filters.AlwaysAddContentType;
import org.jclouds.dynect.v3.filters.SessionManager; import org.jclouds.dynect.v3.filters.SessionManager;
import org.jclouds.dynect.v3.functions.ExtractZoneNames; import org.jclouds.dynect.v3.functions.ExtractZoneNames;
import org.jclouds.rest.ResourceNotFoundException;
import org.jclouds.rest.annotations.BinderParam; import org.jclouds.rest.annotations.BinderParam;
import org.jclouds.rest.annotations.Fallback; import org.jclouds.rest.annotations.Fallback;
import org.jclouds.rest.annotations.Headers; import org.jclouds.rest.annotations.Headers;
@ -86,27 +87,27 @@ public interface ZoneAsyncApi {
ListenableFuture<Zone> get(@PathParam("fqdn") String fqdn) throws JobStillRunningException; ListenableFuture<Zone> get(@PathParam("fqdn") String fqdn) throws JobStillRunningException;
/** /**
* @see ZoneApi#create * @see ZoneApi#scheduleCreate
*/ */
@Named("CreatePrimaryZone") @Named("CreatePrimaryZone")
@POST @POST
@Path("/Zone/{fqdn}") @Path("/Zone/{fqdn}")
@SelectJson("data") @Consumes(APPLICATION_JSON)
ListenableFuture<Zone> create( ListenableFuture<Job> scheduleCreate(
@PathParam("fqdn") @ParamParser(ToFQDN.class) @BinderParam(BindToJsonPayload.class) CreatePrimaryZone createZone) @PathParam("fqdn") @ParamParser(ToFQDN.class) @BinderParam(BindToJsonPayload.class) CreatePrimaryZone createZone)
throws JobStillRunningException, TargetExistsException; throws JobStillRunningException, TargetExistsException;
/** /**
* @see ZoneApi#createWithContact * @see ZoneApi#scheduleCreateWithContact
*/ */
@Named("CreatePrimaryZone") @Named("CreatePrimaryZone")
@POST @POST
@Produces(APPLICATION_JSON) @Produces(APPLICATION_JSON)
@Payload("%7B\"rname\":\"{contact}\",\"serial_style\":\"increment\",\"ttl\":3600%7D") @Payload("%7B\"rname\":\"{contact}\",\"serial_style\":\"increment\",\"ttl\":3600%7D")
@Path("/Zone/{fqdn}") @Path("/Zone/{fqdn}")
@SelectJson("data") @Consumes(APPLICATION_JSON)
ListenableFuture<Zone> createWithContact(@PathParam("fqdn") String fqdn, @PayloadParam("contact") String contact) ListenableFuture<Job> scheduleCreateWithContact(@PathParam("fqdn") String fqdn,
throws JobStillRunningException, TargetExistsException; @PayloadParam("contact") String contact) throws JobStillRunningException, TargetExistsException;
/** /**
* @see ZoneApi#delete * @see ZoneApi#delete
@ -136,7 +137,7 @@ public interface ZoneAsyncApi {
@Produces(APPLICATION_JSON) @Produces(APPLICATION_JSON)
@Payload("{\"publish\":true}") @Payload("{\"publish\":true}")
@SelectJson("data") @SelectJson("data")
ListenableFuture<Zone> publish(@PathParam("fqdn") String fqdn) throws JobStillRunningException; ListenableFuture<Zone> publish(@PathParam("fqdn") String fqdn) throws JobStillRunningException, ResourceNotFoundException;
/** /**
* @see ZoneApi#freeze * @see ZoneApi#freeze

View File

@ -26,6 +26,7 @@ import static org.testng.Assert.assertNull;
import org.jclouds.dynect.v3.DynECTApi; import org.jclouds.dynect.v3.DynECTApi;
import org.jclouds.dynect.v3.domain.CreatePrimaryZone; 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.internal.BaseDynECTApiExpectTest;
import org.jclouds.dynect.v3.parse.DeleteZoneChangesResponseTest; import org.jclouds.dynect.v3.parse.DeleteZoneChangesResponseTest;
import org.jclouds.dynect.v3.parse.DeleteZoneResponseTest; import org.jclouds.dynect.v3.parse.DeleteZoneResponseTest;
@ -54,27 +55,29 @@ public class ZoneApiExpectTest extends BaseDynECTApiExpectTest {
assertEquals(success.getZoneApi().get("jclouds.org").toString(), assertEquals(success.getZoneApi().get("jclouds.org").toString(),
new GetZoneResponseTest().expected().toString()); new GetZoneResponseTest().expected().toString());
} }
HttpRequest create = HttpRequest.builder().method("POST") HttpRequest create = HttpRequest.builder().method("POST")
.endpoint("https://api2.dynect.net/REST/Zone/jclouds.org") .endpoint("https://api2.dynect.net/REST/Zone/jclouds.org")
.addHeader("API-Version", "3.3.8") .addHeader("API-Version", "3.3.8")
.addHeader(ACCEPT, APPLICATION_JSON)
.addHeader("Auth-Token", authToken) .addHeader("Auth-Token", authToken)
.payload(stringPayload("{\"rname\":\"jimmy@jclouds.org\",\"serial_style\":\"increment\",\"ttl\":3600}")) .payload(stringPayload("{\"rname\":\"jimmy@jclouds.org\",\"serial_style\":\"increment\",\"ttl\":3600}"))
.build(); .build();
HttpResponse createResponse = HttpResponse.builder().statusCode(200)
.payload(payloadFromResourceWithContentType("/new_zone.json", APPLICATION_JSON)).build();
public void testCreateWhenResponseIs2xx() { public void testCreateWhenResponseIs2xx() {
DynECTApi success = requestsSendResponses(createSession, createSessionResponse, create, getResponse); DynECTApi success = requestsSendResponses(createSession, createSessionResponse, create, createResponse);
assertEquals(success.getZoneApi().create(CreatePrimaryZone.builder() assertEquals(success.getZoneApi().scheduleCreate(CreatePrimaryZone.builder()
.fqdn("jclouds.org") .fqdn("jclouds.org")
.contact("jimmy@jclouds.org") .contact("jimmy@jclouds.org")
.build()).toString(), .build()), Job.success(285351593l));
new GetZoneResponseTest().expected().toString());
} }
public void testCreateWithContactWhenResponseIs2xx() { public void testCreateWithContactWhenResponseIs2xx() {
DynECTApi success = requestsSendResponses(createSession, createSessionResponse, create, getResponse); DynECTApi success = requestsSendResponses(createSession, createSessionResponse, create, createResponse);
assertEquals(success.getZoneApi().createWithContact("jclouds.org", "jimmy@jclouds.org").toString(), assertEquals(success.getZoneApi().scheduleCreateWithContact("jclouds.org", "jimmy@jclouds.org"), Job.success(285351593l));
new GetZoneResponseTest().expected().toString());
} }
public void testGetWhenResponseIs404() { public void testGetWhenResponseIs404() {

View File

@ -67,14 +67,15 @@ public class ZoneApiLiveTest extends BaseDynECTApiLiveTest {
} }
String fqdn = System.getProperty("user.name").replace('.', '-') + ".zone.dynecttest.jclouds.org"; String fqdn = System.getProperty("user.name").replace('.', '-') + ".zone.dynecttest.jclouds.org";
String contact = JcloudsVersion.get() + "@jclouds.org"; String contact = JcloudsVersion.get() + ".jclouds.org";
@Test @Test
public void testCreateZone() { public void testCreateZone() {
Zone zone = api().createWithContact(fqdn, contact); Job job = api().scheduleCreateWithContact(fqdn, contact);
checkNotNull(zone, "unable to create zone %s", fqdn); checkNotNull(job, "unable to create zone %s", fqdn);
getAnonymousLogger().info("created zone: " + zone); getAnonymousLogger().info("created zone: " + job);
checkZone(zone); assertEquals(job.getStatus(), Status.SUCCESS);
assertEquals(context.getApi().getJob(job.getId()), job);
} }
@Test(dependsOnMethods = "testCreateZone") @Test(dependsOnMethods = "testCreateZone")
@ -121,7 +122,7 @@ public class ZoneApiLiveTest extends BaseDynECTApiLiveTest {
} }
@Override @Override
@AfterClass(groups = "live") @AfterClass(groups = "live", alwaysRun = true)
protected void tearDownContext() { protected void tearDownContext() {
api().delete(fqdn); api().delete(fqdn);
super.tearDownContext(); super.tearDownContext();