Example usage for com.amazonaws.services.ec2.model DescribeSpotPriceHistoryRequest setAvailabilityZone

List of usage examples for com.amazonaws.services.ec2.model DescribeSpotPriceHistoryRequest setAvailabilityZone

Introduction

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

Prototype


public void setAvailabilityZone(String availabilityZone) 

Source Link

Document

Filters the results by the specified Availability Zone.

Usage

From source file:org.finra.dm.dao.impl.Ec2DaoImpl.java

License:Apache License

/**
 * This implementation uses DescribeSpotPriceHistory API which returns the latest spot price history for the specified AZ and instance types. This method
 * then filters the returned list to only contain the latest spot price for each instance type.
 *//*  w  ww .  ja v a2 s.com*/
@Override
public List<SpotPrice> getLatestSpotPrices(String availabilityZone, Collection<String> instanceTypes,
        AwsParamsDto awsParamsDto) {
    AmazonEC2Client ec2Client = getEc2Client(awsParamsDto);
    DescribeSpotPriceHistoryRequest describeSpotPriceHistoryRequest = new DescribeSpotPriceHistoryRequest();
    describeSpotPriceHistoryRequest.setAvailabilityZone(availabilityZone);
    describeSpotPriceHistoryRequest.setInstanceTypes(instanceTypes);
    DescribeSpotPriceHistoryResult describeSpotPriceHistoryResult = ec2Operations
            .describeSpotPriceHistory(ec2Client, describeSpotPriceHistoryRequest);
    List<SpotPrice> spotPrices = new ArrayList<>();
    Set<String> instanceTypesFound = new HashSet<>();
    for (SpotPrice spotPriceHistoryEntry : describeSpotPriceHistoryResult.getSpotPriceHistory()) {
        if (instanceTypesFound.add(spotPriceHistoryEntry.getInstanceType())) {
            spotPrices.add(spotPriceHistoryEntry);
        }
    }
    return spotPrices;
}

From source file:org.finra.herd.dao.impl.Ec2DaoImpl.java

License:Apache License

/**
 * This implementation uses DescribeSpotPriceHistory API which returns the latest spot price history for the specified AZ and instance types. This method
 * then filters the returned list to only contain the latest spot price for each instance type.
 *///from   w w  w.  java  2  s.c  o  m
@Override
public List<SpotPrice> getLatestSpotPrices(String availabilityZone, Collection<String> instanceTypes,
        Collection<String> productDescriptions, AwsParamsDto awsParamsDto) {
    AmazonEC2Client ec2Client = getEc2Client(awsParamsDto);
    DescribeSpotPriceHistoryRequest describeSpotPriceHistoryRequest = new DescribeSpotPriceHistoryRequest();
    describeSpotPriceHistoryRequest.setAvailabilityZone(availabilityZone);
    describeSpotPriceHistoryRequest.setInstanceTypes(instanceTypes);
    describeSpotPriceHistoryRequest.setProductDescriptions(productDescriptions);
    DescribeSpotPriceHistoryResult describeSpotPriceHistoryResult = ec2Operations
            .describeSpotPriceHistory(ec2Client, describeSpotPriceHistoryRequest);
    List<SpotPrice> spotPrices = new ArrayList<>();
    Set<String> instanceTypesFound = new HashSet<>();
    for (SpotPrice spotPriceHistoryEntry : describeSpotPriceHistoryResult.getSpotPriceHistory()) {
        if (instanceTypesFound.add(spotPriceHistoryEntry.getInstanceType())) {
            spotPrices.add(spotPriceHistoryEntry);
        }
    }
    return spotPrices;
}