From 77d91f6e1ac79ad18eb2c7b0725c81382e4dfb45 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Tue, 8 Mar 2011 00:32:44 -0800 Subject: [PATCH] changed single instance spot syntax to only return a single value --- .../ec2/services/SpotInstanceAsyncClient.java | 16 +++++----- .../aws/ec2/services/SpotInstanceClient.java | 32 +++++++++++++++---- ...tHandler.java => SpotInstanceHandler.java} | 4 +-- ...Handler.java => SpotInstancesHandler.java} | 6 ++-- .../services/SpotInstanceAsyncClientTest.java | 15 +++++---- .../services/SpotInstanceClientLiveTest.java | 3 +- ...Test.java => SpotInstanceHandlerTest.java} | 8 ++--- ...est.java => SpotInstancesHandlerTest.java} | 14 ++++---- 8 files changed, 59 insertions(+), 39 deletions(-) rename providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/xml/{SpotInstanceRequestHandler.java => SpotInstanceHandler.java} (95%) rename providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/xml/{SpotInstanceRequestsResponseHandler.java => SpotInstancesHandler.java} (90%) rename providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/xml/{SpotInstanceRequestHandlerTest.java => SpotInstanceHandlerTest.java} (92%) rename providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/xml/{SpotInstancesRequestsResponseHandlerTest.java => SpotInstancesHandlerTest.java} (86%) diff --git a/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/services/SpotInstanceAsyncClient.java b/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/services/SpotInstanceAsyncClient.java index b4a58e0037..3d918adc12 100644 --- a/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/services/SpotInstanceAsyncClient.java +++ b/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/services/SpotInstanceAsyncClient.java @@ -37,8 +37,9 @@ import org.jclouds.aws.ec2.domain.Spot; import org.jclouds.aws.ec2.domain.SpotInstanceRequest; import org.jclouds.aws.ec2.options.DescribeSpotPriceHistoryOptions; import org.jclouds.aws.ec2.options.RequestSpotInstancesOptions; -import org.jclouds.aws.ec2.xml.SpotInstanceRequestsResponseHandler; import org.jclouds.aws.ec2.xml.DescribeSpotPriceHistoryResponseHandler; +import org.jclouds.aws.ec2.xml.SpotInstanceHandler; +import org.jclouds.aws.ec2.xml.SpotInstancesHandler; import org.jclouds.aws.filters.FormSigner; import org.jclouds.location.functions.RegionToEndpointOrProviderIfNull; import org.jclouds.rest.annotations.BinderParam; @@ -71,31 +72,30 @@ public interface SpotInstanceAsyncClient { @Path("/") @FormParams(keys = ACTION, values = "DescribeSpotInstanceRequests") @ExceptionParser(ReturnEmptySetOnNotFoundOr404.class) - @XMLResponseParser(SpotInstanceRequestsResponseHandler.class) + @XMLResponseParser(SpotInstancesHandler.class) ListenableFuture> describeSpotInstanceRequestsInRegion( @EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region, @BinderParam(BindSpotInstanceRequestIdsToIndexedFormParams.class) String... requestIds); /** - * @see SpotInstanceClient#requestSpotInstancesInRegion(String,float,String,String) + * @see SpotInstanceClient#requestSpotInstanceInRegion */ @POST @Path("/") @FormParams(keys = ACTION, values = "RequestSpotInstances") - @XMLResponseParser(SpotInstanceRequestsResponseHandler.class) - ListenableFuture> requestSpotInstancesInRegion( + @XMLResponseParser(SpotInstanceHandler.class) + ListenableFuture requestSpotInstanceInRegion( @EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region, @FormParam("SpotPrice") float spotPrice, @FormParam("LaunchSpecification.ImageId") String imageId, @FormParam("LaunchSpecification.InstanceType") String instanceType); /** - * @see SpotInstanceClient#requestSpotInstancesInRegion(String,float,int, - * LaunchSpecification,RequestSpotInstancesOptions[]) + * @see SpotInstanceClient#requestSpotInstancesInRegion */ @POST @Path("/") @FormParams(keys = ACTION, values = "RequestSpotInstances") - @XMLResponseParser(SpotInstanceRequestsResponseHandler.class) + @XMLResponseParser(SpotInstancesHandler.class) ListenableFuture> requestSpotInstancesInRegion( @EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region, @FormParam("SpotPrice") float spotPrice, @FormParam("InstanceCount") int instanceCount, diff --git a/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/services/SpotInstanceClient.java b/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/services/SpotInstanceClient.java index c5f6010048..2771d4153b 100644 --- a/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/services/SpotInstanceClient.java +++ b/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/services/SpotInstanceClient.java @@ -62,6 +62,24 @@ public interface SpotInstanceClient { */ Set describeSpotInstanceRequestsInRegion(@Nullable String region, String... requestIds); + /** + * request a single spot instance + * + * @param region + * Region where the spot instance service is running + * @param spotPrice + * Specifies the maximum hourly price for any Spot Instance launched to fulfill the + * request. + * @param imageId + * The AMI ID. + * @param instanceType + * The instance type (ex. m1.small) + * @return spot instance request + * @see #requestSpotInstancesInRegion + */ + SpotInstanceRequest requestSpotInstanceInRegion(@Nullable String region, float spotPrice, String imageId, + String instanceType); + /** * Creates a Spot Instance request. Spot Instances are instances that Amazon EC2 starts on your * behalf when the maximum price that you specify exceeds the current Spot Price. Amazon EC2 @@ -74,10 +92,12 @@ public interface SpotInstanceClient { * @param spotPrice * Specifies the maximum hourly price for any Spot Instance launched to fulfill the * request. - * @param imageId - * The AMI ID. - * @param instanceType - * The instance type (ex. m1.small) + * @param instanceCount + * number of instances to request + * @param launchSpec + * includes at least The AMI ID and instance type (ex. m1.small) + * @param options + * options including expiration time or grouping * * @see #describeSpotInstanceRequestsInRegion * @see #cancelSpotInstanceRequestsInRegion @@ -85,10 +105,8 @@ public interface SpotInstanceClient { * @see - * @return TODO + * @return set of spot instance requests */ - Set requestSpotInstancesInRegion(@Nullable String region, float spotPrice, String imageId, String instanceType); - Set requestSpotInstancesInRegion(@Nullable String region, float spotPrice, int instanceCount, LaunchSpecification launchSpec, RequestSpotInstancesOptions... options); diff --git a/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/xml/SpotInstanceRequestHandler.java b/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/xml/SpotInstanceHandler.java similarity index 95% rename from providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/xml/SpotInstanceRequestHandler.java rename to providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/xml/SpotInstanceHandler.java index 41743fdfea..c4bde57afe 100644 --- a/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/xml/SpotInstanceRequestHandler.java +++ b/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/xml/SpotInstanceHandler.java @@ -33,7 +33,7 @@ import org.xml.sax.Attributes; * * @author Adrian Cole */ -public class SpotInstanceRequestHandler extends ParseSax.HandlerForGeneratedRequestWithResult { +public class SpotInstanceHandler extends ParseSax.HandlerForGeneratedRequestWithResult { private StringBuilder currentText = new StringBuilder(); protected final DateService dateService; @@ -43,7 +43,7 @@ public class SpotInstanceRequestHandler extends ParseSax.HandlerForGeneratedRequ protected final LaunchSpecificationHandler launchSpecificationHandler; @Inject - public SpotInstanceRequestHandler(DateService dateService, @Region String defaultRegion, + public SpotInstanceHandler(DateService dateService, @Region String defaultRegion, LaunchSpecificationHandler launchSpecificationHandler, SpotInstanceRequest.Builder builder) { this.dateService = dateService; this.defaultRegion = defaultRegion; diff --git a/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/xml/SpotInstanceRequestsResponseHandler.java b/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/xml/SpotInstancesHandler.java similarity index 90% rename from providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/xml/SpotInstanceRequestsResponseHandler.java rename to providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/xml/SpotInstancesHandler.java index 251f71e62b..d5022fe8b4 100644 --- a/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/xml/SpotInstanceRequestsResponseHandler.java +++ b/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/xml/SpotInstancesHandler.java @@ -36,14 +36,14 @@ import com.google.common.collect.ImmutableSet.Builder; /** * @author Adrian Cole */ -public class SpotInstanceRequestsResponseHandler extends ParseSax.HandlerWithResult> { +public class SpotInstancesHandler extends ParseSax.HandlerWithResult> { private final Builder spotRequests = ImmutableSet. builder(); - private final SpotInstanceRequestHandler spotRequestHandler; + private final SpotInstanceHandler spotRequestHandler; private int itemDepth; @Inject - public SpotInstanceRequestsResponseHandler(SpotInstanceRequestHandler spotRequestHandler) { + public SpotInstancesHandler(SpotInstanceHandler spotRequestHandler) { this.spotRequestHandler = spotRequestHandler; } diff --git a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/services/SpotInstanceAsyncClientTest.java b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/services/SpotInstanceAsyncClientTest.java index 70433dea6a..6e1dde535d 100644 --- a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/services/SpotInstanceAsyncClientTest.java +++ b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/services/SpotInstanceAsyncClientTest.java @@ -27,7 +27,8 @@ import org.jclouds.aws.ec2.domain.LaunchSpecification; import org.jclouds.aws.ec2.options.DescribeSpotPriceHistoryOptions; import org.jclouds.aws.ec2.options.RequestSpotInstancesOptions; import org.jclouds.aws.ec2.xml.DescribeSpotPriceHistoryResponseHandler; -import org.jclouds.aws.ec2.xml.SpotInstanceRequestsResponseHandler; +import org.jclouds.aws.ec2.xml.SpotInstanceHandler; +import org.jclouds.aws.ec2.xml.SpotInstancesHandler; import org.jclouds.http.HttpRequest; import org.jclouds.http.functions.ParseSax; import org.jclouds.http.functions.ReleasePayloadAndReturn; @@ -46,8 +47,8 @@ import com.google.inject.TypeLiteral; // NOTE:without testName, this will not call @Before* and fail w/NPE during surefire @Test(groups = "unit", testName = "SpotInstanceAsyncClientTest") public class SpotInstanceAsyncClientTest extends BaseAWSEC2AsyncClientTest { - public void testRequestSpotInstances() throws SecurityException, NoSuchMethodException, IOException { - Method method = SpotInstanceAsyncClient.class.getMethod("requestSpotInstancesInRegion", String.class, + 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"); @@ -59,7 +60,7 @@ public class SpotInstanceAsyncClientTest extends BaseAWSEC2AsyncClientTest result = factory.create(handler).parse(is); assertEquals(result.size(), 18); @@ -79,8 +79,8 @@ public class SpotInstancesRequestsResponseHandlerTest extends BaseEC2HandlerTest public void testRequest() { InputStream is = getClass().getResourceAsStream("/request_spot_instances.xml"); - SpotInstanceRequestsResponseHandler handler = injector - .getInstance(SpotInstanceRequestsResponseHandler.class); + SpotInstancesHandler handler = injector + .getInstance(SpotInstancesHandler.class); addDefaultRegionToHandler(handler); Set result = factory.create(handler).parse(is); assertEquals(result.size(), 3);