Example usage for com.amazonaws.services.ec2.model SpotPrice getSpotPrice

List of usage examples for com.amazonaws.services.ec2.model SpotPrice getSpotPrice

Introduction

In this page you can find the example usage for com.amazonaws.services.ec2.model SpotPrice getSpotPrice.

Prototype


public String getSpotPrice() 

Source Link

Document

The maximum price per hour that you are willing to pay for a Spot Instance.

Usage

From source file:org.excalibur.service.aws.ec2.EC2.java

License:Open Source License

public List<SpotPriceHistory> getSpotPriceHistory(SpotPriceHistoryRequest request) {
    List<SpotPriceHistory> history = new ArrayList<SpotPriceHistory>();

    DescribeSpotPriceHistoryRequest spotPriceRequest = new DescribeSpotPriceHistoryRequest()
            .withEndTime(request.getUntil()).withStartTime(request.getFrom())
            .withAvailabilityZone(request.getRegion() != null ? request.getRegion().getName() : null)
            .withMaxResults(request.getMaxResult()).withProductDescriptions(request.getImageTypes());

    List<InstanceType> types = request.getInstanceTypes();
    String[] instanceTypes = new String[types.size()];

    for (int i = 0; i < instanceTypes.length; i++) {
        instanceTypes[i] = types.get(i).getName();
    }/* ww  w  .  java  2s .c o m*/

    spotPriceRequest.withInstanceTypes(instanceTypes);

    DescribeSpotPriceHistoryResult describeSpotPriceHistory = ec2_.describeSpotPriceHistory(spotPriceRequest);

    for (SpotPrice spot : describeSpotPriceHistory.getSpotPriceHistory()) {
        history.add(new SpotPriceHistory().withInstanceType(new InstanceType().setName(spot.getInstanceType()))
                .withPrice(spot.getSpotPrice()).withImageTypeDescription(spot.getProductDescription())
                .withRegion(new Region(spot.getAvailabilityZone())).withTime(spot.getTimestamp()));
    }

    return history;
}

From source file:org.finra.dm.dao.helper.EmrPricingHelper.java

License:Apache License

/**
 * Returns a mapping of instance types to spot prices for the given AZ and instance types. The spot prices are retrieved from EC2 API.
 * <p/>/*  w  w w .ja v  a 2s .c o  m*/
 * This method also validates that the given instance types are real instance types supported by AWS.
 *
 * @param availabilityZone The AZ of the spot instances.
 * @param instanceTypes The size of the spot instances.
 *
 * @return A mapping of instance type to spot prices.
 * @throws ObjectNotFoundException when any of the instance type does not exist in AWS
 */
private Map<String, BigDecimal> getInstanceTypeSpotPrices(AvailabilityZone availabilityZone,
        Set<String> instanceTypes) {
    List<SpotPrice> spotPrices = ec2Dao.getLatestSpotPrices(availabilityZone.getZoneName(), instanceTypes,
            getAwsParamsDto());

    Map<String, BigDecimal> instanceTypeSpotPrices = new HashMap<>();
    for (SpotPrice spotPrice : spotPrices) {
        instanceTypeSpotPrices.put(spotPrice.getInstanceType(), new BigDecimal(spotPrice.getSpotPrice()));
    }

    // Ensure that all of the specified instance types were found.
    // If not found, it probably means user tried to lookup non-existent types.
    Set<String> difference = new HashSet<>(instanceTypes);
    difference.removeAll(instanceTypeSpotPrices.keySet());

    if (!difference.isEmpty()) {
        throw new ObjectNotFoundException(
                "Spot prices for instance types " + difference + " not found in AZ " + availabilityZone + ".");
    }

    return instanceTypeSpotPrices;
}

From source file:org.finra.herd.dao.helper.EmrPricingHelper.java

License:Apache License

/**
 * Returns a mapping of instance types to spot prices for the given AZ and instance types. The spot prices are retrieved from EC2 API.
 * <p/>/*ww w  .  j  av  a2 s.c  o m*/
 * This method also validates that the given instance types are real instance types supported by AWS.
 *
 * @param availabilityZone the AZ of the spot instances
 * @param instanceTypes the size of the spot instances
 * @param awsParamsDto the AWS related parameters for access/secret keys and proxy details
 *
 * @return the mapping of instance type to spot prices
 * @throws ObjectNotFoundException when any of the instance type does not exist in AWS
 */
private Map<String, BigDecimal> getInstanceTypeSpotPrices(AvailabilityZone availabilityZone,
        Set<String> instanceTypes, AwsParamsDto awsParamsDto) {
    List<String> productDescriptions = herdStringHelper
            .getDelimitedConfigurationValue(ConfigurationValue.EMR_SPOT_PRICE_HISTORY_PRODUCT_DESCRIPTIONS);
    List<SpotPrice> spotPrices = ec2Dao.getLatestSpotPrices(availabilityZone.getZoneName(), instanceTypes,
            productDescriptions, awsParamsDto);

    Map<String, BigDecimal> instanceTypeSpotPrices = new HashMap<>();
    for (SpotPrice spotPrice : spotPrices) {
        instanceTypeSpotPrices.put(spotPrice.getInstanceType(), new BigDecimal(spotPrice.getSpotPrice()));
    }

    return instanceTypeSpotPrices;
}