public static String nodeTypeToPurchase = "dw.hs1.xlarge";
public static Double fixedPriceLimit = 10000.00;
public static ArrayList<ReservedNodeOffering> matchingNodes = new ArrayL
ist<ReservedNodeOffering>();
public static void main(String[] args) throws IOException {
AWSCredentials credentials = new PropertiesCredentials(
ListAndPurchaseReservedNodeOffering.class
.getResourceAsStream("AwsCredentials.properties"));
client = new AmazonRedshiftClient(credentials);
try {
listReservedNodes();
findReservedNodeOffer();
purchaseReservedNodeOffer();
} catch (Exception e) {
System.err.println("Operation failed: " + e.getMessage());
}
}
private static void listReservedNodes() {
DescribeReservedNodesResult result = client.describeReservedNodes();
System.out.println("Listing nodes already purchased.");
for (ReservedNode node : result.getReservedNodes()) {
printReservedNodeDetails(node);
}
}
private static void findReservedNodeOffer()
{
DescribeReservedNodeOfferingsRequest request = new DescribeReserved
NodeOfferingsRequest();
DescribeReservedNodeOfferingsResult result = client.describeReserved
NodeOfferings(request);
Integer count = 0;
System.out.println("\nFinding nodes to purchase.");
for (ReservedNodeOffering offering : result.getReservedNodeOfferings())
{
if (offering.getNodeType().equals(nodeTypeToPurchase)){
if (offering.getFixedPrice() < fixedPriceLimit) {
matchingNodes.add(offering);
printOfferingDetails(offering);
count +=1;
}
}
}
if (count == 0) {
System.out.println("\nNo reserved node offering matches found.");
} else {
System.out.println("\nFound " + count + " matches.");
}
API Version 2012-12-01
87
Amazon Redshift Management Guide
Purchasing a Reserved Node Offering Using Java