From e6090530be0ca8ab585da30ab122557a90f4787c Mon Sep 17 00:00:00 2001 From: vijaykiran Date: Mon, 14 Nov 2011 21:57:01 +0100 Subject: [PATCH] volume-client create volume test --- .../cloudstack/CloudStackAsyncClient.java | 7 +++ .../jclouds/cloudstack/CloudStackClient.java | 7 +++ .../config/CloudStackRestClientModule.java | 3 ++ .../features/VolumeAsyncClient.java | 11 ++-- .../cloudstack/features/VolumeClient.java | 5 +- .../cloudstack/CloudStackAsyncClientTest.java | 2 + .../features/VolumeAsyncClientTest.java | 7 +-- .../features/VolumeClientLiveTest.java | 54 +++++++++++++------ 8 files changed, 69 insertions(+), 27 deletions(-) diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/CloudStackAsyncClient.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/CloudStackAsyncClient.java index 1fb1723adb..6f5d80d0e0 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/CloudStackAsyncClient.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/CloudStackAsyncClient.java @@ -37,6 +37,7 @@ import org.jclouds.cloudstack.features.SecurityGroupAsyncClient; import org.jclouds.cloudstack.features.TemplateAsyncClient; import org.jclouds.cloudstack.features.VMGroupAsyncClient; import org.jclouds.cloudstack.features.VirtualMachineAsyncClient; +import org.jclouds.cloudstack.features.VolumeAsyncClient; import org.jclouds.cloudstack.features.ZoneAsyncClient; import org.jclouds.rest.annotations.Delegate; @@ -170,4 +171,10 @@ public interface CloudStackAsyncClient { */ @Delegate ISOAsyncClient getISOClient(); + + /** + * Provides asynchronous access to Volumes + */ + @Delegate + VolumeAsyncClient getVolumeClient(); } diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/CloudStackClient.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/CloudStackClient.java index 8ba40e5d8a..760f36cff8 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/CloudStackClient.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/CloudStackClient.java @@ -39,6 +39,7 @@ import org.jclouds.cloudstack.features.SecurityGroupClient; import org.jclouds.cloudstack.features.TemplateClient; import org.jclouds.cloudstack.features.VMGroupClient; import org.jclouds.cloudstack.features.VirtualMachineClient; +import org.jclouds.cloudstack.features.VolumeClient; import org.jclouds.cloudstack.features.ZoneClient; import org.jclouds.concurrent.Timeout; import org.jclouds.rest.annotations.Delegate; @@ -173,4 +174,10 @@ public interface CloudStackClient { */ @Delegate ISOClient getISOClient(); + + /** + * Provides synchronous access to Volumes + */ + @Delegate + VolumeClient getVolumeClient(); } diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/config/CloudStackRestClientModule.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/config/CloudStackRestClientModule.java index df677b311b..8e45950aca 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/config/CloudStackRestClientModule.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/config/CloudStackRestClientModule.java @@ -61,6 +61,8 @@ import org.jclouds.cloudstack.features.VMGroupAsyncClient; import org.jclouds.cloudstack.features.VMGroupClient; import org.jclouds.cloudstack.features.VirtualMachineAsyncClient; import org.jclouds.cloudstack.features.VirtualMachineClient; +import org.jclouds.cloudstack.features.VolumeAsyncClient; +import org.jclouds.cloudstack.features.VolumeClient; import org.jclouds.cloudstack.features.ZoneAsyncClient; import org.jclouds.cloudstack.features.ZoneClient; import org.jclouds.cloudstack.handlers.CloudStackErrorHandler; @@ -104,6 +106,7 @@ public class CloudStackRestClientModule extends RestClientModule createVolumeFromDiskOfferingInZone(@QueryParam("name") String name, - @QueryParam("diskofferingid") long diskOfferingId, - @QueryParam("zoneid") long zoneId); + ListenableFuture createVolumeFromDiskOfferingInZone(@QueryParam("name") String name, + @QueryParam("diskofferingid") long diskOfferingId, + @QueryParam("zoneid") long zoneId); /** * @see VolumeClient#createVolumeWithSnapshot(String, long) @@ -78,8 +79,8 @@ public interface VolumeAsyncClient { @SelectJson("volume") @Consumes(MediaType.APPLICATION_JSON) @ExceptionParser(ReturnNullOnNotFoundOr404.class) - ListenableFuture createVolumeWithSnapshot(@QueryParam("name") String name, - @QueryParam("snapshotid") long diskOfferingId); + ListenableFuture createVolumeWithSnapshot(@QueryParam("name") String name, + @QueryParam("snapshotid") long diskOfferingId); /** * @see VolumeClient#deleteVolume(long) diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/VolumeClient.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/VolumeClient.java index e34208f3d6..960751afd4 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/VolumeClient.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/VolumeClient.java @@ -21,6 +21,7 @@ package org.jclouds.cloudstack.features; import java.util.Set; import java.util.concurrent.TimeUnit; +import org.jclouds.cloudstack.domain.AsyncCreateResponse; import org.jclouds.cloudstack.domain.Volume; import org.jclouds.cloudstack.options.ListVolumesOptions; import org.jclouds.concurrent.Timeout; @@ -43,7 +44,7 @@ public interface VolumeClient { * @param zoneId the ID of the availability zone * @return Volume */ - Volume createVolumeFromDiskOfferingInZone(String name, long diskOfferingId, long zoneId); + AsyncCreateResponse createVolumeFromDiskOfferingInZone(String name, long diskOfferingId, long zoneId); /** * Create a volume with given name and snapshotId @@ -52,7 +53,7 @@ public interface VolumeClient { * @param snapshotId Snapshot id to be used while creating the volume * @return Volume */ - Volume createVolumeWithSnapshot(String name, long snapshotId); + AsyncCreateResponse createVolumeWithSnapshot(String name, long snapshotId); /** * List volumes diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/CloudStackAsyncClientTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/CloudStackAsyncClientTest.java index e7db88988c..7042300de1 100644 --- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/CloudStackAsyncClientTest.java +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/CloudStackAsyncClientTest.java @@ -62,6 +62,7 @@ public class CloudStackAsyncClientTest extends BaseCloudStackAsyncClientTest volumes = client.getVolumeClient().listVolumes(); @@ -46,23 +51,25 @@ public class VolumeClientLiveTest extends BaseCloudStackClientLiveTest { public void testCreateVolumeFromDiskofferingInZoneAndDeleteVolume() { - final Set zones = client.getZoneClient().listZones(); - assertNotNull(zones); - final Zone zone = zones.iterator().next(); - - final Set diskOfferings = client.getOfferingClient().listDiskOfferings(); - assertNotNull(diskOfferings); - + zoneId = Iterables.getFirst(client.getZoneClient().listZones(), null).getId(); //Pick some disk offering - final DiskOffering diskOffering = diskOfferings.iterator().next(); - final VolumeClient volumeClient = client.getVolumeClient(); + diskOfferingId = Iterables.getFirst(client.getOfferingClient().listDiskOfferings(), null).getId(); + + + while (volume == null) { + try { + AsyncCreateResponse job = client.getVolumeClient().createVolumeFromDiskOfferingInZone(prefix + "-jclouds-volume", + diskOfferingId, zoneId); + assert jobComplete.apply(job.getJobId()); + volume = findVolumeWithId(job.getId()); + } catch (IllegalStateException e) { + //TODO Retry ? + e.printStackTrace(); + } + } + + checkVolume(volume); - final Volume volumeWithDiskOffering = - volumeClient.createVolumeFromDiskOfferingInZone(prefix + "-jclouds-volume", - diskOffering.getId(), - zone.getId()); - checkVolume(volumeWithDiskOffering); - volumeClient.deleteVolume(volumeWithDiskOffering.getId()); } @@ -70,4 +77,17 @@ public class VolumeClientLiveTest extends BaseCloudStackClientLiveTest { assertNotNull(volume.getId()); assertNotNull(volume.getName()); } + + private Volume findVolumeWithId(final long id) { + System.out.println(id); + return find(client.getVolumeClient().listVolumes(), new Predicate() { + + @Override + public boolean apply(Volume arg0) { + return arg0.getId() == id; + } + + }); + } + }