Added an overloaded version of 'createVolumeFromSnapshotInAvailabilityZone' to support specific size for a volume

This commit is contained in:
Alex Yarmula 2010-02-16 10:37:18 -08:00
parent bb80d90755
commit 3e8381e3f3
4 changed files with 84 additions and 1 deletions

View File

@ -81,6 +81,17 @@ public interface ElasticBlockStoreAsyncClient {
@EndpointParam(parser = AvailabilityZoneToEndpoint.class) @FormParam("AvailabilityZone") AvailabilityZone availabilityZone,
@FormParam("SnapshotId") String snapshotId);
/**
* @see ElasticBlockStoreClient#createVolumeFromSnapshotInAvailabilityZone
*/
@POST
@Path("/")
@FormParams(keys = ACTION, values = "CreateVolume")
@XMLResponseParser(CreateVolumeResponseHandler.class)
ListenableFuture<Volume> createVolumeFromSnapshotInAvailabilityZone(
@EndpointParam(parser = AvailabilityZoneToEndpoint.class) @FormParam("AvailabilityZone") AvailabilityZone availabilityZone,
@FormParam("Size") int size, @FormParam("SnapshotId") String snapshotId);
/**
* @see ElasticBlockStoreClient#createVolumeInAvailabilityZone
*/
@ -183,7 +194,7 @@ public interface ElasticBlockStoreAsyncClient {
@FormParam("SnapshotId") String snapshotId);
/**
* @see ElasticBlockStoreClient#removeCreateVolumePermissionsToSnapshotInRegion
* @see ElasticBlockStoreClient#removeCreateVolumePermissionsFromSnapshotInRegion
*/
@POST
@Path("/")

View File

@ -66,6 +66,36 @@ public interface ElasticBlockStoreClient {
Volume createVolumeFromSnapshotInAvailabilityZone(AvailabilityZone availabilityZone,
String snapshotId);
/**
* Creates a new Amazon EBS volume to which any Amazon EC2 instance can attach within the same
* Availability Zone. This is overloaded {@link #createVolumeFromSnapshotInAvailabilityZone},
* which creates a volume with a specific size.
* For more information about Amazon EBS, go to the Amazon Elastic Compute
* Cloud Developer Guide or Amazon Elastic Compute Cloud User Guide.
*
* @param availabilityZone
* An Amazon EBS volume must be located within the same Availability Zone as the
* instance to which it attaches.
* @param size
* Size of volume to be created
* @param snapshotId
* The snapshot from which to create the new volume.
*
* @see #createVolumeFromSnapshotInAvailabilityZone
* @see #describeVolumesInRegion
* @see #deleteVolumeInRegion
* @see #attachVolumeInRegion
* @see #detachVolumeInRegion
* @see AvailabilityZoneAndRegionClient#describeAvailabilityZonesInRegion
*
*
* @see <a href=
* "http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-CreateVolume.html"
* />
*/
Volume createVolumeFromSnapshotInAvailabilityZone(AvailabilityZone availabilityZone,
int size, String snapshotId);
/**
* Creates a new Amazon EBS volume to which any Amazon EC2 instance can attach within the same
* Availability Zone. For more information about Amazon EBS, go to the Amazon Elastic Compute

View File

@ -110,6 +110,27 @@ public class ElasticBlockStoreAsyncClientTest extends RestClientTest<ElasticBloc
checkFilters(httpMethod);
}
public void testCreateVolumeFromSnapShotWithSize() throws SecurityException, NoSuchMethodException,
IOException {
Method method = ElasticBlockStoreAsyncClient.class.getMethod(
"createVolumeFromSnapshotInAvailabilityZone", AvailabilityZone.class,
int.class, String.class);
GeneratedHttpRequest<ElasticBlockStoreAsyncClient> httpMethod = processor.createRequest(
method, AvailabilityZone.US_EAST_1A, 15, "snapshotId");
assertRequestLineEquals(httpMethod, "POST https://ec2.amazonaws.com/ HTTP/1.1");
assertHeadersEqual(httpMethod,
"Content-Length: 96\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.amazonaws.com\n");
assertPayloadEquals(httpMethod,
"Version=2009-11-30&Action=CreateVolume&AvailabilityZone=us-east-1a&SnapshotId=snapshotId&Size=15");
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
assertSaxResponseParserClassEquals(method, CreateVolumeResponseHandler.class);
assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod);
}
public void testDeleteVolume() throws SecurityException, NoSuchMethodException, IOException {
Method method = ElasticBlockStoreAsyncClient.class.getMethod("deleteVolumeInRegion",
Region.class, String.class);

View File

@ -138,6 +138,27 @@ public class ElasticBlockStoreClientLiveTest {
client.deleteVolumeInRegion(snapshot.getRegion(), volume.getId());
}
@Test(dependsOnMethods = "testCreateSnapshotInRegion")
void testCreateVolumeFromSnapshotInAvailabilityZoneWithSize() {
Volume volume = client.createVolumeFromSnapshotInAvailabilityZone(
AvailabilityZone.US_EAST_1B, 2, snapshot.getId());
assertNotNull(volume);
Predicate<Volume> availabile = new RetryablePredicate<Volume>(new VolumeAvailable(client),
600, 10, TimeUnit.SECONDS);
assert availabile.apply(volume);
Volume result = Iterables.getOnlyElement(client.describeVolumesInRegion(snapshot.getRegion(),
volume.getId()));
assertEquals(volume.getId(), result.getId());
assertEquals(volume.getSnapshotId(), snapshot.getId());
assertEquals(volume.getAvailabilityZone(), AvailabilityZone.US_EAST_1B);
assertEquals(volume.getSize(), 2);
assertEquals(result.getStatus(), Volume.Status.AVAILABLE);
client.deleteVolumeInRegion(snapshot.getRegion(), volume.getId());
}
@Test
void testAttachVolumeInRegion() {
// TODO: need an instance