mirror of https://github.com/apache/jclouds.git
changed single instance spot syntax to only return a single value
This commit is contained in:
parent
25db134edc
commit
77d91f6e1a
|
@ -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<? extends Set<SpotInstanceRequest>> 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<? extends Set<SpotInstanceRequest>> requestSpotInstancesInRegion(
|
||||
@XMLResponseParser(SpotInstanceHandler.class)
|
||||
ListenableFuture<SpotInstanceRequest> 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<? extends Set<SpotInstanceRequest>> requestSpotInstancesInRegion(
|
||||
@EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region,
|
||||
@FormParam("SpotPrice") float spotPrice, @FormParam("InstanceCount") int instanceCount,
|
||||
|
|
|
@ -62,6 +62,24 @@ public interface SpotInstanceClient {
|
|||
*/
|
||||
Set<SpotInstanceRequest> 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 <a href=
|
||||
* "http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-RequestSpotInstances.html"
|
||||
* />
|
||||
* @return TODO
|
||||
* @return set of spot instance requests
|
||||
*/
|
||||
Set<SpotInstanceRequest> requestSpotInstancesInRegion(@Nullable String region, float spotPrice, String imageId, String instanceType);
|
||||
|
||||
Set<SpotInstanceRequest> requestSpotInstancesInRegion(@Nullable String region, float spotPrice, int instanceCount,
|
||||
LaunchSpecification launchSpec, RequestSpotInstancesOptions... options);
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ import org.xml.sax.Attributes;
|
|||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class SpotInstanceRequestHandler extends ParseSax.HandlerForGeneratedRequestWithResult<SpotInstanceRequest> {
|
||||
public class SpotInstanceHandler extends ParseSax.HandlerForGeneratedRequestWithResult<SpotInstanceRequest> {
|
||||
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;
|
|
@ -36,14 +36,14 @@ import com.google.common.collect.ImmutableSet.Builder;
|
|||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class SpotInstanceRequestsResponseHandler extends ParseSax.HandlerWithResult<Set<SpotInstanceRequest>> {
|
||||
public class SpotInstancesHandler extends ParseSax.HandlerWithResult<Set<SpotInstanceRequest>> {
|
||||
|
||||
private final Builder<SpotInstanceRequest> spotRequests = ImmutableSet.<SpotInstanceRequest> builder();
|
||||
private final SpotInstanceRequestHandler spotRequestHandler;
|
||||
private final SpotInstanceHandler spotRequestHandler;
|
||||
private int itemDepth;
|
||||
|
||||
@Inject
|
||||
public SpotInstanceRequestsResponseHandler(SpotInstanceRequestHandler spotRequestHandler) {
|
||||
public SpotInstancesHandler(SpotInstanceHandler spotRequestHandler) {
|
||||
this.spotRequestHandler = spotRequestHandler;
|
||||
}
|
||||
|
|
@ -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<SpotInstanceAsyncClient> {
|
||||
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<SpotI
|
|||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, SpotInstanceRequestsResponseHandler.class);
|
||||
assertSaxResponseParserClassEquals(method, SpotInstanceHandler.class);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
|
||||
checkFilters(request);
|
||||
|
@ -81,7 +82,7 @@ public class SpotInstanceAsyncClientTest extends BaseAWSEC2AsyncClientTest<SpotI
|
|||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, SpotInstanceRequestsResponseHandler.class);
|
||||
assertSaxResponseParserClassEquals(method, SpotInstancesHandler.class);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
|
||||
checkFilters(request);
|
||||
|
@ -115,7 +116,7 @@ public class SpotInstanceAsyncClientTest extends BaseAWSEC2AsyncClientTest<SpotI
|
|||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, SpotInstanceRequestsResponseHandler.class);
|
||||
assertSaxResponseParserClassEquals(method, SpotInstancesHandler.class);
|
||||
assertExceptionParserClassEquals(method, ReturnEmptySetOnNotFoundOr404.class);
|
||||
|
||||
checkFilters(request);
|
||||
|
@ -134,7 +135,7 @@ public class SpotInstanceAsyncClientTest extends BaseAWSEC2AsyncClientTest<SpotI
|
|||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, SpotInstanceRequestsResponseHandler.class);
|
||||
assertSaxResponseParserClassEquals(method, SpotInstancesHandler.class);
|
||||
assertExceptionParserClassEquals(method, ReturnEmptySetOnNotFoundOr404.class);
|
||||
|
||||
checkFilters(request);
|
||||
|
|
|
@ -158,11 +158,12 @@ public class SpotInstanceClientLiveTest {
|
|||
if (launchGroup.equals(request.getLaunchGroup()))
|
||||
client.getSpotInstanceServices().cancelSpotInstanceRequestsInRegion("us-west-1", request.getId());
|
||||
start = System.currentTimeMillis();
|
||||
|
||||
requests = client.getSpotInstanceServices().requestSpotInstancesInRegion(
|
||||
"us-west-1",
|
||||
0.03f,
|
||||
1,
|
||||
LaunchSpecification.builder().instanceType(InstanceType.T1_MICRO).imageId("ami-595a0a1c").build(),
|
||||
LaunchSpecification.builder().imageId("ami-595a0a1c").instanceType(InstanceType.T1_MICRO).build(),
|
||||
launchGroup(launchGroup).availabilityZoneGroup(launchGroup).validFrom(new Date())
|
||||
.validUntil(new Date(System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(SPOT_DELAY_SECONDS))));
|
||||
assertNotNull(requests);
|
||||
|
|
|
@ -43,13 +43,13 @@ import com.google.inject.AbstractModule;
|
|||
import com.google.inject.Guice;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code SpotInstanceRequestHandler}
|
||||
* Tests behavior of {@code SpotInstanceHandler}
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
// NOTE:without testName, this will not call @Before* and fail w/NPE during surefire
|
||||
@Test(groups = "unit", testName = "SpotInstanceRequestHandlerTest")
|
||||
public class SpotInstanceRequestHandlerTest extends BaseEC2HandlerTest {
|
||||
@Test(groups = "unit", testName = "SpotInstanceHandlerTest")
|
||||
public class SpotInstanceHandlerTest extends BaseEC2HandlerTest {
|
||||
|
||||
private DateService dateService;
|
||||
|
||||
|
@ -87,7 +87,7 @@ public class SpotInstanceRequestHandlerTest extends BaseEC2HandlerTest {
|
|||
.mapEphemeralDeviceToDevice("/dev/sda3", "vre1").monitoringEnabled(false).build())
|
||||
.createTime(new SimpleDateFormatDateService().iso8601DateParse("2011-03-08T03:30:36.000Z"))
|
||||
.productDescription("Linux/UNIX").build();
|
||||
SpotInstanceRequestHandler handler = injector.getInstance(SpotInstanceRequestHandler.class);
|
||||
SpotInstanceHandler handler = injector.getInstance(SpotInstanceHandler.class);
|
||||
addDefaultRegionToHandler(handler);
|
||||
SpotInstanceRequest result = factory.create(handler).parse(is);
|
||||
assertEquals(result, expected);
|
|
@ -42,13 +42,13 @@ import com.google.inject.AbstractModule;
|
|||
import com.google.inject.Guice;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code SpotInstancesRequestsResponseHandler}
|
||||
* Tests behavior of {@code SpotInstancesHandler}
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
// NOTE:without testName, this will not call @Before* and fail w/NPE during surefire
|
||||
@Test(groups = "unit", testName = "SpotInstancesRequestsResponseHandlerTest")
|
||||
public class SpotInstancesRequestsResponseHandlerTest extends BaseEC2HandlerTest {
|
||||
@Test(groups = "unit", testName = "SpotInstancesHandlerTest")
|
||||
public class SpotInstancesHandlerTest extends BaseEC2HandlerTest {
|
||||
|
||||
private DateService dateService;
|
||||
|
||||
|
@ -70,8 +70,8 @@ public class SpotInstancesRequestsResponseHandlerTest extends BaseEC2HandlerTest
|
|||
public void testDescribe() {
|
||||
|
||||
InputStream is = getClass().getResourceAsStream("/describe_spot_instance_requests.xml");
|
||||
SpotInstanceRequestsResponseHandler handler = injector
|
||||
.getInstance(SpotInstanceRequestsResponseHandler.class);
|
||||
SpotInstancesHandler handler = injector
|
||||
.getInstance(SpotInstancesHandler.class);
|
||||
addDefaultRegionToHandler(handler);
|
||||
Set<SpotInstanceRequest> 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<SpotInstanceRequest> result = factory.create(handler).parse(is);
|
||||
assertEquals(result.size(), 3);
|
Loading…
Reference in New Issue