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.TemplateAsyncClient;
|
||||||
import org.jclouds.cloudstack.features.VMGroupAsyncClient;
|
import org.jclouds.cloudstack.features.VMGroupAsyncClient;
|
||||||
import org.jclouds.cloudstack.features.VirtualMachineAsyncClient;
|
import org.jclouds.cloudstack.features.VirtualMachineAsyncClient;
|
||||||
|
import org.jclouds.cloudstack.features.VolumeAsyncClient;
|
||||||
import org.jclouds.cloudstack.features.ZoneAsyncClient;
|
import org.jclouds.cloudstack.features.ZoneAsyncClient;
|
||||||
import org.jclouds.rest.annotations.Delegate;
|
import org.jclouds.rest.annotations.Delegate;
|
||||||
|
|
||||||
|
@ -170,4 +171,10 @@ public interface CloudStackAsyncClient {
|
||||||
*/
|
*/
|
||||||
@Delegate
|
@Delegate
|
||||||
ISOAsyncClient getISOClient();
|
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.TemplateClient;
|
||||||
import org.jclouds.cloudstack.features.VMGroupClient;
|
import org.jclouds.cloudstack.features.VMGroupClient;
|
||||||
import org.jclouds.cloudstack.features.VirtualMachineClient;
|
import org.jclouds.cloudstack.features.VirtualMachineClient;
|
||||||
|
import org.jclouds.cloudstack.features.VolumeClient;
|
||||||
import org.jclouds.cloudstack.features.ZoneClient;
|
import org.jclouds.cloudstack.features.ZoneClient;
|
||||||
import org.jclouds.concurrent.Timeout;
|
import org.jclouds.concurrent.Timeout;
|
||||||
import org.jclouds.rest.annotations.Delegate;
|
import org.jclouds.rest.annotations.Delegate;
|
||||||
|
@ -173,4 +174,10 @@ public interface CloudStackClient {
|
||||||
*/
|
*/
|
||||||
@Delegate
|
@Delegate
|
||||||
ISOClient getISOClient();
|
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.VMGroupClient;
|
||||||
import org.jclouds.cloudstack.features.VirtualMachineAsyncClient;
|
import org.jclouds.cloudstack.features.VirtualMachineAsyncClient;
|
||||||
import org.jclouds.cloudstack.features.VirtualMachineClient;
|
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.ZoneAsyncClient;
|
||||||
import org.jclouds.cloudstack.features.ZoneClient;
|
import org.jclouds.cloudstack.features.ZoneClient;
|
||||||
import org.jclouds.cloudstack.handlers.CloudStackErrorHandler;
|
import org.jclouds.cloudstack.handlers.CloudStackErrorHandler;
|
||||||
|
@ -104,6 +106,7 @@ public class CloudStackRestClientModule extends RestClientModule<CloudStackClien
|
||||||
.put(SSHKeyPairClient.class, SSHKeyPairAsyncClient.class)//
|
.put(SSHKeyPairClient.class, SSHKeyPairAsyncClient.class)//
|
||||||
.put(VMGroupClient.class, VMGroupAsyncClient.class)//
|
.put(VMGroupClient.class, VMGroupAsyncClient.class)//
|
||||||
.put(ISOClient.class, ISOAsyncClient.class)//
|
.put(ISOClient.class, ISOAsyncClient.class)//
|
||||||
|
.put(VolumeClient.class, VolumeAsyncClient.class)//
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
public CloudStackRestClientModule() {
|
public CloudStackRestClientModule() {
|
||||||
|
|
|
@ -25,6 +25,7 @@ import javax.ws.rs.core.MediaType;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import com.google.common.util.concurrent.ListenableFuture;
|
import com.google.common.util.concurrent.ListenableFuture;
|
||||||
|
import org.jclouds.cloudstack.domain.AsyncCreateResponse;
|
||||||
import org.jclouds.cloudstack.domain.Volume;
|
import org.jclouds.cloudstack.domain.Volume;
|
||||||
import org.jclouds.cloudstack.filters.QuerySigner;
|
import org.jclouds.cloudstack.filters.QuerySigner;
|
||||||
import org.jclouds.cloudstack.options.ListVolumesOptions;
|
import org.jclouds.cloudstack.options.ListVolumesOptions;
|
||||||
|
@ -66,7 +67,7 @@ public interface VolumeAsyncClient {
|
||||||
@SelectJson("volume")
|
@SelectJson("volume")
|
||||||
@Consumes(MediaType.APPLICATION_JSON)
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||||
ListenableFuture<Volume> createVolumeFromDiskOfferingInZone(@QueryParam("name") String name,
|
ListenableFuture<AsyncCreateResponse> createVolumeFromDiskOfferingInZone(@QueryParam("name") String name,
|
||||||
@QueryParam("diskofferingid") long diskOfferingId,
|
@QueryParam("diskofferingid") long diskOfferingId,
|
||||||
@QueryParam("zoneid") long zoneId);
|
@QueryParam("zoneid") long zoneId);
|
||||||
|
|
||||||
|
@ -78,7 +79,7 @@ public interface VolumeAsyncClient {
|
||||||
@SelectJson("volume")
|
@SelectJson("volume")
|
||||||
@Consumes(MediaType.APPLICATION_JSON)
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||||
ListenableFuture<Volume> createVolumeWithSnapshot(@QueryParam("name") String name,
|
ListenableFuture<AsyncCreateResponse> createVolumeWithSnapshot(@QueryParam("name") String name,
|
||||||
@QueryParam("snapshotid") long diskOfferingId);
|
@QueryParam("snapshotid") long diskOfferingId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -21,6 +21,7 @@ package org.jclouds.cloudstack.features;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import org.jclouds.cloudstack.domain.AsyncCreateResponse;
|
||||||
import org.jclouds.cloudstack.domain.Volume;
|
import org.jclouds.cloudstack.domain.Volume;
|
||||||
import org.jclouds.cloudstack.options.ListVolumesOptions;
|
import org.jclouds.cloudstack.options.ListVolumesOptions;
|
||||||
import org.jclouds.concurrent.Timeout;
|
import org.jclouds.concurrent.Timeout;
|
||||||
|
@ -43,7 +44,7 @@ public interface VolumeClient {
|
||||||
* @param zoneId the ID of the availability zone
|
* @param zoneId the ID of the availability zone
|
||||||
* @return Volume
|
* @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
|
* 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
|
* @param snapshotId Snapshot id to be used while creating the volume
|
||||||
* @return Volume
|
* @return Volume
|
||||||
*/
|
*/
|
||||||
Volume createVolumeWithSnapshot(String name, long snapshotId);
|
AsyncCreateResponse createVolumeWithSnapshot(String name, long snapshotId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* List volumes
|
* List volumes
|
||||||
|
|
|
@ -62,6 +62,7 @@ public class CloudStackAsyncClientTest extends BaseCloudStackAsyncClientTest<Clo
|
||||||
assert syncClient.getEventClient() != null;
|
assert syncClient.getEventClient() != null;
|
||||||
assert syncClient.getLimitClient() != null;
|
assert syncClient.getLimitClient() != null;
|
||||||
assert syncClient.getISOClient() != null;
|
assert syncClient.getISOClient() != null;
|
||||||
|
assert syncClient.getVolumeClient() != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testAsync() throws SecurityException, NoSuchMethodException, InterruptedException, ExecutionException {
|
public void testAsync() throws SecurityException, NoSuchMethodException, InterruptedException, ExecutionException {
|
||||||
|
@ -85,6 +86,7 @@ public class CloudStackAsyncClientTest extends BaseCloudStackAsyncClientTest<Clo
|
||||||
assert asyncClient.getEventClient() != null;
|
assert asyncClient.getEventClient() != null;
|
||||||
assert asyncClient.getLimitClient() != null;
|
assert asyncClient.getLimitClient() != null;
|
||||||
assert asyncClient.getISOClient() != 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 {
|
public void testCreateVolumeFromDiskOffering() throws SecurityException, NoSuchMethodException, IOException {
|
||||||
Method method = VolumeAsyncClient.class.getMethod("createVolumeWithDiskOfferingInZone",
|
Method method = VolumeAsyncClient.class.getMethod("createVolumeFromDiskOfferingInZone",
|
||||||
String.class, Long.class, Long.class);
|
String.class, long.class , long.class);
|
||||||
|
|
||||||
HttpRequest httpRequest = processor.createRequest(method, prefix + "-jclouds-volume", 999L, 111L);
|
HttpRequest httpRequest = processor.createRequest(method, prefix + "-jclouds-volume", 999L, 111L);
|
||||||
|
|
||||||
assertRequestLineEquals(httpRequest,
|
assertRequestLineEquals(httpRequest,
|
||||||
|
|
|
@ -18,13 +18,15 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.cloudstack.features;
|
package org.jclouds.cloudstack.features;
|
||||||
|
|
||||||
|
import static com.google.common.collect.Iterables.find;
|
||||||
import static org.testng.AssertJUnit.assertNotNull;
|
import static org.testng.AssertJUnit.assertNotNull;
|
||||||
|
|
||||||
import java.util.Set;
|
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.Volume;
|
||||||
import org.jclouds.cloudstack.domain.Zone;
|
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -36,6 +38,9 @@ import org.testng.annotations.Test;
|
||||||
public class VolumeClientLiveTest extends BaseCloudStackClientLiveTest {
|
public class VolumeClientLiveTest extends BaseCloudStackClientLiveTest {
|
||||||
|
|
||||||
protected String prefix = System.getProperty("user.name");
|
protected String prefix = System.getProperty("user.name");
|
||||||
|
private long zoneId;
|
||||||
|
private long diskOfferingId;
|
||||||
|
private Volume volume;
|
||||||
|
|
||||||
public void testListVolumes() {
|
public void testListVolumes() {
|
||||||
final Set<Volume> volumes = client.getVolumeClient().listVolumes();
|
final Set<Volume> volumes = client.getVolumeClient().listVolumes();
|
||||||
|
@ -46,23 +51,25 @@ public class VolumeClientLiveTest extends BaseCloudStackClientLiveTest {
|
||||||
|
|
||||||
public void testCreateVolumeFromDiskofferingInZoneAndDeleteVolume() {
|
public void testCreateVolumeFromDiskofferingInZoneAndDeleteVolume() {
|
||||||
|
|
||||||
final Set<Zone> zones = client.getZoneClient().listZones();
|
zoneId = Iterables.getFirst(client.getZoneClient().listZones(), null).getId();
|
||||||
assertNotNull(zones);
|
|
||||||
final Zone zone = zones.iterator().next();
|
|
||||||
|
|
||||||
final Set<DiskOffering> diskOfferings = client.getOfferingClient().listDiskOfferings();
|
|
||||||
assertNotNull(diskOfferings);
|
|
||||||
|
|
||||||
//Pick some disk offering
|
//Pick some disk offering
|
||||||
final DiskOffering diskOffering = diskOfferings.iterator().next();
|
diskOfferingId = Iterables.getFirst(client.getOfferingClient().listDiskOfferings(), null).getId();
|
||||||
final VolumeClient volumeClient = client.getVolumeClient();
|
|
||||||
|
|
||||||
|
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.getId());
|
||||||
assertNotNull(volume.getName());
|
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