mirror of https://github.com/apache/jclouds.git
Merge branch 'master' of https://github.com/grkvlt/jclouds into grkvlt-master
Conflicts: apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/VolumeClientLiveTest.java
This commit is contained in:
commit
bf6c0f4984
|
@ -8,6 +8,7 @@ bin/
|
|||
.project
|
||||
.idea/
|
||||
*.iml
|
||||
*.eml
|
||||
*.ipr
|
||||
*.iws
|
||||
TAGS
|
||||
|
|
|
@ -29,12 +29,9 @@ import org.jclouds.cloudstack.domain.AsyncCreateResponse;
|
|||
import org.jclouds.cloudstack.domain.Volume;
|
||||
import org.jclouds.cloudstack.filters.QuerySigner;
|
||||
import org.jclouds.cloudstack.options.ListVolumesOptions;
|
||||
import org.jclouds.rest.annotations.ExceptionParser;
|
||||
import org.jclouds.rest.annotations.QueryParams;
|
||||
import org.jclouds.rest.annotations.RequestFilters;
|
||||
import org.jclouds.rest.annotations.SelectJson;
|
||||
import org.jclouds.rest.annotations.Unwrap;
|
||||
import org.jclouds.rest.annotations.*;
|
||||
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
|
||||
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
|
||||
import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404;
|
||||
|
||||
/**
|
||||
|
@ -58,6 +55,17 @@ public interface VolumeAsyncClient {
|
|||
@ExceptionParser(ReturnEmptySetOnNotFoundOr404.class)
|
||||
ListenableFuture<Set<Volume>> listVolumes(ListVolumesOptions... options);
|
||||
|
||||
/**
|
||||
* @see VolumeClient#getVolume(long)
|
||||
*/
|
||||
@GET
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@QueryParams(keys = "command", values = "listVolumes")
|
||||
@SelectJson("volume")
|
||||
@OnlyElement
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
ListenableFuture<Volume> getVolume(@QueryParam("id") long id);
|
||||
|
||||
|
||||
/**
|
||||
* @see VolumeClient#createVolumeFromDiskOfferingInZone(String, long, long)
|
||||
|
|
|
@ -59,10 +59,18 @@ public interface VolumeClient {
|
|||
/**
|
||||
* List volumes
|
||||
*
|
||||
* @return volume list or null if not found
|
||||
* @return volume list, empty if not found
|
||||
*/
|
||||
Set<Volume> listVolumes(ListVolumesOptions... options);
|
||||
|
||||
/**
|
||||
* Get volume by id
|
||||
*
|
||||
* @param id the volume id to retrieve
|
||||
* @return volume or null if not found
|
||||
*/
|
||||
Volume getVolume(long id);
|
||||
|
||||
/**
|
||||
* Deletes a attached disk volume
|
||||
*
|
||||
|
|
|
@ -25,6 +25,7 @@ import com.google.inject.TypeLiteral;
|
|||
import org.jclouds.cloudstack.options.ListVolumesOptions;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
|
||||
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
|
||||
import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404;
|
||||
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
||||
import org.testng.annotations.Test;
|
||||
|
@ -55,6 +56,22 @@ public class VolumeAsyncClientTest extends BaseCloudStackAsyncClientTest<VolumeA
|
|||
|
||||
}
|
||||
|
||||
public void testGetVolume() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = VolumeAsyncClient.class.getMethod("getVolume", long.class);
|
||||
HttpRequest httpRequest = processor.createRequest(method, 111L);
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET http://localhost:8080/client/api?response=json&command=listVolumes&id=111 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
|
||||
|
||||
checkFilters(httpRequest);
|
||||
|
||||
}
|
||||
|
||||
public void testCreateVolumeWithSnapshot() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = VolumeAsyncClient.class.getMethod("createVolumeFromSnapshotInZone", String.class, long.class,
|
||||
long.class);
|
||||
|
@ -119,10 +136,10 @@ public class VolumeAsyncClientTest extends BaseCloudStackAsyncClientTest<VolumeA
|
|||
|
||||
public void testDeleteVolume() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = VolumeAsyncClient.class.getMethod("deleteVolume", long.class);
|
||||
HttpRequest httpRequest = processor.createRequest(method, "jclouds-volume");
|
||||
HttpRequest httpRequest = processor.createRequest(method, 111L);
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET http://localhost:8080/client/api?response=json&command=deleteVolume&id=jclouds-volume HTTP/1.1");
|
||||
"GET http://localhost:8080/client/api?response=json&command=deleteVolume&id=111 HTTP/1.1");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
|
|
|
@ -18,103 +18,160 @@
|
|||
*/
|
||||
package org.jclouds.cloudstack.features;
|
||||
|
||||
import static com.google.common.collect.Iterables.find;
|
||||
import static org.testng.AssertJUnit.assertNotNull;
|
||||
import static org.testng.AssertJUnit.assertNotSame;
|
||||
import static com.google.common.collect.Iterables.*;
|
||||
import static org.testng.AssertJUnit.*;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import org.jclouds.cloudstack.domain.AsyncCreateResponse;
|
||||
import org.jclouds.cloudstack.domain.Snapshot;
|
||||
import org.jclouds.cloudstack.domain.Volume;
|
||||
import org.jclouds.cloudstack.domain.Zone;
|
||||
import org.jclouds.cloudstack.options.ListVolumesOptions;
|
||||
import org.testng.annotations.BeforeMethod;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code SSHKeyPairClient}
|
||||
* Tests behavior of {@code VolumeClient}
|
||||
*
|
||||
* @author Vijay Kiran
|
||||
*/
|
||||
@Test(groups = "live", singleThreaded = true, testName = "VolumeClientLiveTest")
|
||||
public class VolumeClientLiveTest extends BaseCloudStackClientLiveTest {
|
||||
|
||||
protected String prefix = System.getProperty("user.name");
|
||||
|
||||
private long zoneId;
|
||||
private long diskOfferingId;
|
||||
private long snapshotId;
|
||||
private Volume volume;
|
||||
|
||||
@BeforeMethod(groups = "live")
|
||||
public void setZoneId() {
|
||||
Set<Zone> zones = client.getZoneClient().listZones();
|
||||
assertNotNull(zones);
|
||||
assertFalse(zones.isEmpty());
|
||||
zoneId = Iterables.get(zones, 0).getId();
|
||||
}
|
||||
|
||||
public void testListVolumes() {
|
||||
final Set<Volume> volumes = client.getVolumeClient().listVolumes();
|
||||
Set<Volume> volumes = client.getVolumeClient().listVolumes();
|
||||
assertNotNull(volumes);
|
||||
assertFalse(volumes.isEmpty());
|
||||
|
||||
for (Volume volume : volumes) {
|
||||
checkVolume(volume);
|
||||
}
|
||||
}
|
||||
|
||||
public void testListVolumesById() {
|
||||
Iterable<Long> volumeIds = Iterables.transform(client.getVolumeClient().listVolumes(), new Function<Volume, Long>() {
|
||||
public Long apply(Volume input) {
|
||||
return input.getId();
|
||||
}
|
||||
});
|
||||
assertNotNull(volumeIds);
|
||||
assertFalse(Iterables.isEmpty(volumeIds));
|
||||
|
||||
for (Long id : volumeIds) {
|
||||
Set<Volume> found = client.getVolumeClient().listVolumes(ListVolumesOptions.Builder.id(id));
|
||||
assertNotNull(found);
|
||||
assertEquals(1, found.size());
|
||||
Volume volume = Iterables.getOnlyElement(found);
|
||||
assertEquals(id.longValue(), volume.getId());
|
||||
checkVolume(volume);
|
||||
}
|
||||
}
|
||||
|
||||
public void testListVolumesNonexistantId() {
|
||||
Set<Volume> found = client.getVolumeClient().listVolumes(ListVolumesOptions.Builder.id(-1));
|
||||
assertNotNull(found);
|
||||
assertTrue(found.isEmpty());
|
||||
}
|
||||
|
||||
public void testGetVolumeById() {
|
||||
Iterable<Long> volumeIds = Iterables.transform(client.getVolumeClient().listVolumes(), new Function<Volume, Long>() {
|
||||
public Long apply(Volume input) {
|
||||
return input.getId();
|
||||
}
|
||||
});
|
||||
assertNotNull(volumeIds);
|
||||
assertFalse(Iterables.isEmpty(volumeIds));
|
||||
|
||||
for (Long id : volumeIds) {
|
||||
Volume found = client.getVolumeClient().getVolume(id);
|
||||
assertNotNull(found);
|
||||
assertEquals(id.longValue(), found.getId());
|
||||
checkVolume(found);
|
||||
}
|
||||
}
|
||||
|
||||
public void testGetVolumeNonexistantId() {
|
||||
Volume found = client.getVolumeClient().getVolume(-1);
|
||||
assertNull(found);
|
||||
}
|
||||
|
||||
public void testCreateVolumeFromDiskofferingInZoneAndDeleteVolume() {
|
||||
// Pick some disk offering
|
||||
long diskOfferingId = Iterables.get(client.getOfferingClient().listDiskOfferings(), 0).getId();
|
||||
|
||||
zoneId = Iterables.getFirst(client.getZoneClient().listZones(), null).getId();
|
||||
//Pick some disk offering
|
||||
diskOfferingId = Iterables.getFirst(client.getOfferingClient().listDiskOfferings(), null).getId();
|
||||
|
||||
|
||||
Volume volume = null;
|
||||
while (volume == null) {
|
||||
try {
|
||||
AsyncCreateResponse job = client.getVolumeClient().createVolumeFromDiskOfferingInZone(prefix + "-jclouds-volume",
|
||||
diskOfferingId, zoneId);
|
||||
assert jobComplete.apply(job.getJobId());
|
||||
assertTrue(jobComplete.apply(job.getJobId()));
|
||||
volume = findVolumeWithId(job.getId());
|
||||
} catch (IllegalStateException e) {
|
||||
//TODO volume creation failed - retry?
|
||||
// TODO volume creation failed - retry?
|
||||
}
|
||||
}
|
||||
|
||||
checkVolume(volume);
|
||||
//Delete the volume
|
||||
|
||||
// Delete the volume
|
||||
client.getVolumeClient().deleteVolume(volume.getId());
|
||||
}
|
||||
|
||||
public void testCreateVolumeFromDiskofferingInZoneAndAttachVolumeToVirtualMachineAndDetachAndDelete() {
|
||||
// Pick some disk offering
|
||||
long diskOfferingId = Iterables.get(client.getOfferingClient().listDiskOfferings(), 0).getId();
|
||||
|
||||
zoneId = Iterables.getFirst(client.getZoneClient().listZones(), null).getId();
|
||||
//Pick some disk offering
|
||||
diskOfferingId = Iterables.getFirst(client.getOfferingClient().listDiskOfferings(), null).getId();
|
||||
|
||||
|
||||
Volume volume = null;
|
||||
while (volume == null) {
|
||||
try {
|
||||
AsyncCreateResponse job = client.getVolumeClient().createVolumeFromDiskOfferingInZone(prefix + "-jclouds-volume",
|
||||
diskOfferingId, zoneId);
|
||||
assert jobComplete.apply(job.getJobId());
|
||||
assertTrue(jobComplete.apply(job.getJobId()));
|
||||
volume = findVolumeWithId(job.getId());
|
||||
} catch (IllegalStateException e) {
|
||||
//TODO volume creation failed - retry?
|
||||
// TODO volume creation failed - retry?
|
||||
}
|
||||
}
|
||||
|
||||
checkVolume(volume);
|
||||
long virtualMachineId = Iterables.getFirst(client.getVirtualMachineClient().listVirtualMachines(), null).getId();
|
||||
//Attach Volume
|
||||
long virtualMachineId = Iterables.get(client.getVirtualMachineClient().listVirtualMachines(), 0).getId();
|
||||
|
||||
// Attach Volume
|
||||
Volume attachedVolume = null;
|
||||
while (attachedVolume == null) {
|
||||
try {
|
||||
AsyncCreateResponse job = client.getVolumeClient().attachVolume(volume.getId(), virtualMachineId);
|
||||
assert jobComplete.apply(job.getJobId());
|
||||
assertTrue(jobComplete.apply(job.getJobId()));
|
||||
attachedVolume = findVolumeWithId(volume.getId());
|
||||
assert attachedVolume.getVirtualMachineId() == virtualMachineId;
|
||||
assert attachedVolume.getAttached() != null;
|
||||
assertEquals(virtualMachineId, attachedVolume.getVirtualMachineId());
|
||||
assertNotNull(attachedVolume.getAttached());
|
||||
} catch (IllegalStateException e) {
|
||||
//TODO volume creation failed - retry?
|
||||
// TODO volume creation failed - retry?
|
||||
}
|
||||
}
|
||||
|
||||
//Detach Volume
|
||||
// Detach Volume
|
||||
Volume detachedVolume = null;
|
||||
while (detachedVolume == null) {
|
||||
try {
|
||||
AsyncCreateResponse job = client.getVolumeClient().detachVolume(volume.getId());
|
||||
assert jobComplete.apply(job.getJobId());
|
||||
assertTrue(jobComplete.apply(job.getJobId()));
|
||||
detachedVolume = findVolumeWithId(volume.getId());
|
||||
checkVolume(detachedVolume);
|
||||
} catch (IllegalStateException e) {
|
||||
|
@ -122,34 +179,33 @@ public class VolumeClientLiveTest extends BaseCloudStackClientLiveTest {
|
|||
}
|
||||
}
|
||||
|
||||
//Cleanup
|
||||
// Cleanup
|
||||
client.getVolumeClient().deleteVolume(volume.getId());
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
TODO Uncomment this test after SnapshotClient has test coverage.
|
||||
// TODO Uncomment this test after SnapshotClient has test coverage.
|
||||
public void testCreateVolumeFromSnapshotInZoneAndDeleteVolume() {
|
||||
|
||||
zoneId = Iterables.getFirst(client.getZoneClient().listZones(), null).getId();
|
||||
final Set<Snapshot> snapshots = client.getSnapshotClient().listSnapshots();
|
||||
Set<Snapshot> snapshots = client.getSnapshotClient().listSnapshots();
|
||||
assertNotNull(snapshots);
|
||||
assertNotSame(0, snapshots.size() );
|
||||
snapshotId = Iterables.getFirst(snapshots, null).getId();
|
||||
assertFalse(snapshots.isEmpty());
|
||||
long snapshotId = Iterables.get(snapshots, 0).getId();
|
||||
|
||||
Volume volume = null;
|
||||
while (volume == null) {
|
||||
try {
|
||||
AsyncCreateResponse job = client.getVolumeClient().createVolumeFromSnapshotInZone(prefix + "-jclouds-volume",
|
||||
snapshotId, zoneId);
|
||||
assert jobComplete.apply(job.getJobId());
|
||||
assertTrue(jobComplete.apply(job.getJobId()));
|
||||
volume = findVolumeWithId(job.getId());
|
||||
} catch (IllegalStateException e) {
|
||||
//TODO volume creation failed - retry?
|
||||
// TODO volume creation failed - retry?
|
||||
}
|
||||
}
|
||||
|
||||
checkVolume(volume);
|
||||
//Delete the volume
|
||||
|
||||
// Delete the volume
|
||||
client.getVolumeClient().deleteVolume(volume.getId());
|
||||
}
|
||||
*/
|
||||
|
@ -162,13 +218,10 @@ public class VolumeClientLiveTest extends BaseCloudStackClientLiveTest {
|
|||
|
||||
private Volume findVolumeWithId(final long id) {
|
||||
return find(client.getVolumeClient().listVolumes(), new Predicate<Volume>() {
|
||||
|
||||
@Override
|
||||
public boolean apply(Volume arg0) {
|
||||
return arg0.getId() == id;
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue