mirror of https://github.com/apache/jclouds.git
volume-client create volume test
This commit is contained in:
parent
0dad4db0a3
commit
e6090530be
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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<CloudStackClien
|
|||
.put(SSHKeyPairClient.class, SSHKeyPairAsyncClient.class)//
|
||||
.put(VMGroupClient.class, VMGroupAsyncClient.class)//
|
||||
.put(ISOClient.class, ISOAsyncClient.class)//
|
||||
.put(VolumeClient.class, VolumeAsyncClient.class)//
|
||||
.build();
|
||||
|
||||
public CloudStackRestClientModule() {
|
||||
|
|
|
@ -25,6 +25,7 @@ import javax.ws.rs.core.MediaType;
|
|||
import java.util.Set;
|
||||
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
import org.jclouds.cloudstack.domain.AsyncCreateResponse;
|
||||
import org.jclouds.cloudstack.domain.Volume;
|
||||
import org.jclouds.cloudstack.filters.QuerySigner;
|
||||
import org.jclouds.cloudstack.options.ListVolumesOptions;
|
||||
|
@ -66,9 +67,9 @@ public interface VolumeAsyncClient {
|
|||
@SelectJson("volume")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
ListenableFuture<Volume> createVolumeFromDiskOfferingInZone(@QueryParam("name") String name,
|
||||
@QueryParam("diskofferingid") long diskOfferingId,
|
||||
@QueryParam("zoneid") long zoneId);
|
||||
ListenableFuture<AsyncCreateResponse> 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<Volume> createVolumeWithSnapshot(@QueryParam("name") String name,
|
||||
@QueryParam("snapshotid") long diskOfferingId);
|
||||
ListenableFuture<AsyncCreateResponse> createVolumeWithSnapshot(@QueryParam("name") String name,
|
||||
@QueryParam("snapshotid") long diskOfferingId);
|
||||
|
||||
/**
|
||||
* @see VolumeClient#deleteVolume(long)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -62,6 +62,7 @@ public class CloudStackAsyncClientTest extends BaseCloudStackAsyncClientTest<Clo
|
|||
assert syncClient.getEventClient() != null;
|
||||
assert syncClient.getLimitClient() != null;
|
||||
assert syncClient.getISOClient() != null;
|
||||
assert syncClient.getVolumeClient() != null;
|
||||
}
|
||||
|
||||
public void testAsync() throws SecurityException, NoSuchMethodException, InterruptedException, ExecutionException {
|
||||
|
@ -85,6 +86,7 @@ public class CloudStackAsyncClientTest extends BaseCloudStackAsyncClientTest<Clo
|
|||
assert asyncClient.getEventClient() != null;
|
||||
assert asyncClient.getLimitClient() != null;
|
||||
assert asyncClient.getISOClient() != null;
|
||||
assert asyncClient.getVolumeClient() != null;
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -74,9 +74,10 @@ public class VolumeAsyncClientTest extends BaseCloudStackAsyncClientTest<VolumeA
|
|||
|
||||
}
|
||||
|
||||
public void testCreateVolumeWithDiskOffering() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = VolumeAsyncClient.class.getMethod("createVolumeWithDiskOfferingInZone",
|
||||
String.class, Long.class, Long.class);
|
||||
public void testCreateVolumeFromDiskOffering() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = VolumeAsyncClient.class.getMethod("createVolumeFromDiskOfferingInZone",
|
||||
String.class, long.class , long.class);
|
||||
|
||||
HttpRequest httpRequest = processor.createRequest(method, prefix + "-jclouds-volume", 999L, 111L);
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
|
|
|
@ -18,13 +18,15 @@
|
|||
*/
|
||||
package org.jclouds.cloudstack.features;
|
||||
|
||||
import static com.google.common.collect.Iterables.find;
|
||||
import static org.testng.AssertJUnit.assertNotNull;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import org.jclouds.cloudstack.domain.DiskOffering;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.Iterables;
|
||||
import org.jclouds.cloudstack.domain.AsyncCreateResponse;
|
||||
import org.jclouds.cloudstack.domain.Volume;
|
||||
import org.jclouds.cloudstack.domain.Zone;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
/**
|
||||
|
@ -36,6 +38,9 @@ import org.testng.annotations.Test;
|
|||
public class VolumeClientLiveTest extends BaseCloudStackClientLiveTest {
|
||||
|
||||
protected String prefix = System.getProperty("user.name");
|
||||
private long zoneId;
|
||||
private long diskOfferingId;
|
||||
private Volume volume;
|
||||
|
||||
public void testListVolumes() {
|
||||
final Set<Volume> volumes = client.getVolumeClient().listVolumes();
|
||||
|
@ -46,23 +51,25 @@ public class VolumeClientLiveTest extends BaseCloudStackClientLiveTest {
|
|||
|
||||
public void testCreateVolumeFromDiskofferingInZoneAndDeleteVolume() {
|
||||
|
||||
final Set<Zone> zones = client.getZoneClient().listZones();
|
||||
assertNotNull(zones);
|
||||
final Zone zone = zones.iterator().next();
|
||||
|
||||
final Set<DiskOffering> 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<Volume>() {
|
||||
|
||||
@Override
|
||||
public boolean apply(Volume arg0) {
|
||||
return arg0.getId() == id;
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue