From 5cab8dcd961e73653ba34b34e5c77cf425f034d0 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Mon, 25 Feb 2013 17:04:32 -0800 Subject: [PATCH] unhooked version dependency from ec2 async tests --- ...BlockDeviceMappingToIndexedFormParams.java | 20 +-- ...kDeviceMappingToIndexedFormParamsTest.java | 7 +- .../ec2/services/InstanceAsyncClientTest.java | 25 +-- .../jclouds/aws/ec2/AWSEC2AsyncClient.java | 2 +- .../ec2/services/AWSAMIAsyncClientTest.java | 147 ++++-------------- .../services/AWSInstanceAsyncClientTest.java | 82 +++------- .../services/AWSKeyPairAsyncClientTest.java | 10 +- .../AWSSecurityGroupAsyncClientTest.java | 10 +- .../PlacementGroupAsyncClientTest.java | 10 +- .../services/SpotInstanceAsyncClientTest.java | 120 +------------- 10 files changed, 94 insertions(+), 339 deletions(-) diff --git a/apis/ec2/src/main/java/org/jclouds/ec2/binders/BindBlockDeviceMappingToIndexedFormParams.java b/apis/ec2/src/main/java/org/jclouds/ec2/binders/BindBlockDeviceMappingToIndexedFormParams.java index cde7812ebd..4a55bffbd4 100644 --- a/apis/ec2/src/main/java/org/jclouds/ec2/binders/BindBlockDeviceMappingToIndexedFormParams.java +++ b/apis/ec2/src/main/java/org/jclouds/ec2/binders/BindBlockDeviceMappingToIndexedFormParams.java @@ -21,6 +21,8 @@ package org.jclouds.ec2.binders; import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; import static java.lang.String.format; +import static org.jclouds.http.utils.Queries.queryParser; +import static org.jclouds.io.Payloads.newUrlEncodedFormPayload; import java.util.Map; import java.util.Map.Entry; @@ -29,9 +31,8 @@ import org.jclouds.ec2.domain.BlockDevice; import org.jclouds.http.HttpRequest; import org.jclouds.rest.Binder; -import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableMultimap; import com.google.common.collect.Multimap; -import com.google.common.collect.Multimaps; /** * @author Oleksiy Yarmula @@ -40,28 +41,29 @@ import com.google.common.collect.Multimaps; public class BindBlockDeviceMappingToIndexedFormParams implements Binder { private static final String deviceNamePattern = "BlockDeviceMapping.%d.DeviceName"; - private static final String volumeIdPattern = "BlockDeviceMapping.%d.Ebs.VolumeId"; private static final String deleteOnTerminationPattern = "BlockDeviceMapping.%d.Ebs.DeleteOnTermination"; + private static final String volumeIdPattern = "BlockDeviceMapping.%d.Ebs.VolumeId"; @SuppressWarnings("unchecked") @Override public R bindToRequest(R request, Object input) { checkArgument(checkNotNull(input, "input") instanceof Map, "this binder is only valid for Map"); Map blockDeviceMapping = (Map) input; - - ImmutableMap.Builder builder = ImmutableMap.builder(); + Multimap original = queryParser().apply(request.getPayload().getRawContent().toString()); + ImmutableMultimap.Builder builder = ImmutableMultimap.builder(); + builder.putAll("Action", "ModifyInstanceAttribute"); int amazonOneBasedIndex = 1; // according to docs, counters must start with 1 for (Entry ebsBlockDeviceName : blockDeviceMapping.entrySet()) { // not null by contract - builder.put(format(volumeIdPattern, amazonOneBasedIndex), ebsBlockDeviceName.getValue().getVolumeId()); builder.put(format(deviceNamePattern, amazonOneBasedIndex), ebsBlockDeviceName.getKey()); builder.put(format(deleteOnTerminationPattern, amazonOneBasedIndex), String.valueOf(ebsBlockDeviceName.getValue().isDeleteOnTermination())); - + builder.put(format(volumeIdPattern, amazonOneBasedIndex), ebsBlockDeviceName.getValue().getVolumeId()); amazonOneBasedIndex++; } - Multimap forms = Multimaps.forMap(builder.build()); - return forms.size() == 0 ? request : (R) request.toBuilder().replaceFormParams(forms).build(); + builder.putAll("InstanceId", original.get("InstanceId")); + request.setPayload(newUrlEncodedFormPayload(builder.build())); + return request; } } diff --git a/apis/ec2/src/test/java/org/jclouds/ec2/binders/BindBlockDeviceMappingToIndexedFormParamsTest.java b/apis/ec2/src/test/java/org/jclouds/ec2/binders/BindBlockDeviceMappingToIndexedFormParamsTest.java index 12ccf98a5e..356b6ed9f4 100644 --- a/apis/ec2/src/test/java/org/jclouds/ec2/binders/BindBlockDeviceMappingToIndexedFormParamsTest.java +++ b/apis/ec2/src/test/java/org/jclouds/ec2/binders/BindBlockDeviceMappingToIndexedFormParamsTest.java @@ -44,17 +44,18 @@ public class BindBlockDeviceMappingToIndexedFormParamsTest { BindBlockDeviceMappingToIndexedFormParams binder = injector .getInstance(BindBlockDeviceMappingToIndexedFormParams.class); - public void testMapping() { + public void testMappingOrdersLexicographically() { Map mapping = Maps.newLinkedHashMap(); mapping.put("apple", new BlockDevice("appleId", true)); Date date = new Date(999999l); mapping.put("cranberry", new BlockDevice("cranberry", Status.ATTACHED, date, false)); - HttpRequest request = HttpRequest.builder().method("POST").endpoint("http://localhost").build(); + HttpRequest request = HttpRequest.builder().method("POST").endpoint("http://localhost") + .addFormParam("InstanceId", "i-foo").build(); request = binder.bindToRequest(request, mapping); assertEquals( request.getPayload().getRawContent(), - "BlockDeviceMapping.1.Ebs.VolumeId=appleId&BlockDeviceMapping.1.DeviceName=apple&BlockDeviceMapping.1.Ebs.DeleteOnTermination=true&BlockDeviceMapping.2.Ebs.VolumeId=cranberry&BlockDeviceMapping.2.DeviceName=cranberry&BlockDeviceMapping.2.Ebs.DeleteOnTermination=false"); + "Action=ModifyInstanceAttribute&BlockDeviceMapping.1.DeviceName=apple&BlockDeviceMapping.1.Ebs.DeleteOnTermination=true&BlockDeviceMapping.1.Ebs.VolumeId=appleId&BlockDeviceMapping.2.DeviceName=cranberry&BlockDeviceMapping.2.Ebs.DeleteOnTermination=false&BlockDeviceMapping.2.Ebs.VolumeId=cranberry&InstanceId=i-foo"); } @Test(expectedExceptions = IllegalArgumentException.class) diff --git a/apis/ec2/src/test/java/org/jclouds/ec2/services/InstanceAsyncClientTest.java b/apis/ec2/src/test/java/org/jclouds/ec2/services/InstanceAsyncClientTest.java index c674ff25c7..acd7f9d871 100644 --- a/apis/ec2/src/test/java/org/jclouds/ec2/services/InstanceAsyncClientTest.java +++ b/apis/ec2/src/test/java/org/jclouds/ec2/services/InstanceAsyncClientTest.java @@ -548,6 +548,15 @@ public class InstanceAsyncClientTest extends BaseEC2AsyncClientTest { - HttpRequest requestSpotInstances = HttpRequest.builder().method("POST") - .endpoint("https://ec2.us-east-1.amazonaws.com/") - .addHeader("Host", "ec2.us-east-1.amazonaws.com") - .addFormParam("Action", "RequestSpotInstances") - .addFormParam("LaunchSpecification.ImageId", "m1.small") - .addFormParam("LaunchSpecification.InstanceType", "ami-voo") - .addFormParam("Signature", "5PZRT8xXMugx1ku/NxQpaGWqYLLbKwJksBbeldGLO2s=") - .addFormParam("SignatureMethod", "HmacSHA256") - .addFormParam("SignatureVersion", "2") - .addFormParam("SpotPrice", "0.01") - .addFormParam("Timestamp", "2009-11-08T15%3A54%3A08.897Z") - .addFormParam("Version", "2011-05-15") - .addFormParam("AWSAccessKeyId", "identity").build(); - - public void testRequestSpotInstance() throws SecurityException, NoSuchMethodException, IOException { - Method method = SpotInstanceAsyncClient.class.getMethod("requestSpotInstanceInRegion", String.class, - float.class, String.class, String.class); - HttpRequest request = processor.createRequest(method, null, 0.01f, "m1.small", "ami-voo"); - - request = request.getFilters().get(0).filter(request); - - assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); - assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n"); - assertPayloadEquals(request, requestSpotInstances.getPayload().getRawContent().toString(), - "application/x-www-form-urlencoded", false); - - assertResponseParserClassEquals(method, request, ParseSax.class); - assertSaxResponseParserClassEquals(method, SpotInstanceHandler.class); - assertExceptionParserClassEquals(method, null); - - checkFilters(request); - } - - HttpRequest requestSpotInstancesOptions = HttpRequest.builder().method("POST") - .endpoint("https://ec2.us-east-1.amazonaws.com/") - .addHeader("Host", "ec2.us-east-1.amazonaws.com") - .addFormParam("Action", "RequestSpotInstances") - .addFormParam("AvailabilityZoneGroup", "availabilityZoneGroup") - .addFormParam("InstanceCount", "3") - .addFormParam("LaunchGroup", "launchGroup") - .addFormParam("LaunchSpecification.ImageId", "ami-voo") - .addFormParam("LaunchSpecification.InstanceType", "m1.small") - .addFormParam("LaunchSpecification.KernelId", "kernelId") - .addFormParam("LaunchSpecification.Placement.AvailabilityZone", "eu-west-1a") - .addFormParam("LaunchSpecification.SecurityGroup.1", "group1") - .addFormParam("Signature", "94pCsdmfYVMbMzofCeTvfvpQozIY6iDu0LewXvHl1ao=") - .addFormParam("SignatureMethod", "HmacSHA256") - .addFormParam("SignatureVersion", "2") - .addFormParam("SpotPrice", "0.01") - .addFormParam("Timestamp", "2009-11-08T15%3A54%3A08.897Z") - .addFormParam("ValidFrom", "1970-05-23T21%3A21%3A18Z") - .addFormParam("ValidUntil", "2009-02-13T23%3A31%3A31Z") - .addFormParam("Version", "2011-05-15") - .addFormParam("AWSAccessKeyId", "identity").build(); - - public void testRequestSpotInstancesOptions() throws SecurityException, NoSuchMethodException, IOException { - Method method = SpotInstanceAsyncClient.class.getMethod("requestSpotInstancesInRegion", String.class, - float.class, int.class, LaunchSpecification.class, RequestSpotInstancesOptions[].class); - HttpRequest request = processor.createRequest(method, "eu-west-1", 0.01, 3, - LaunchSpecification.builder().instanceType("m1.small").imageId("ami-voo").availabilityZone("eu-west-1a") - .kernelId("kernelId").securityGroupName("group1").build(), new RequestSpotInstancesOptions().validFrom(from) - .validUntil(to).availabilityZoneGroup("availabilityZoneGroup").launchGroup("launchGroup")); - - request = request.getFilters().get(0).filter(request); - - assertRequestLineEquals(request, "POST https://ec2.eu-west-1.amazonaws.com/ HTTP/1.1"); - assertNonPayloadHeadersEqual(request, "Host: ec2.eu-west-1.amazonaws.com\n"); - assertPayloadEquals(request, requestSpotInstancesOptions.getPayload().getRawContent().toString(), - "application/x-www-form-urlencoded", false); - - assertResponseParserClassEquals(method, request, ParseSax.class); - assertSaxResponseParserClassEquals(method, SpotInstancesHandler.class); - assertExceptionParserClassEquals(method, null); - - checkFilters(request); - } - public void testCancelSpotInstanceRequests() throws SecurityException, NoSuchMethodException, IOException { Method method = SpotInstanceAsyncClient.class.getMethod("cancelSpotInstanceRequestsInRegion", String.class, String[].class); @@ -141,42 +61,6 @@ public class SpotInstanceAsyncClientTest extends BaseAWSEC2AsyncClientTest