Example usage for com.amazonaws.services.ec2.model ReservedInstancesOffering getProductDescription

List of usage examples for com.amazonaws.services.ec2.model ReservedInstancesOffering getProductDescription

Introduction

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

Prototype


public String getProductDescription() 

Source Link

Document

The Reserved Instance product platform description.

Usage

From source file:com.kenlin.awsec2offering.Offering.java

License:Open Source License

public Offering(ReservedInstancesOffering offering) {
    availabilityZone = offering.getAvailabilityZone();
    offeringType = offering.getOfferingType();
    instanceType = offering.getInstanceType();
    productDescription = offering.getProductDescription();
    currencyCode = offering.getCurrencyCode();
    duration = offering.getDuration();/*  www.  java2s  . c om*/
    fixedPrice = offering.getFixedPrice();
    try {
        hourlyPrice = offering.getRecurringCharges().get(0).getAmount();
    } catch (IndexOutOfBoundsException e) {
        hourlyPrice = offering.getUsagePrice().doubleValue(); // e.g., c1.medium
    }
    /* totalMonthlyCost functionality has been offloaded to the client-side         
          totalMonthlyCost   = calculateTotalCost(duration, fixedPrice, hourlyPrice);
    */
}

From source file:com.netflix.ice.basic.BasicReservationService.java

License:Apache License

private void pollAPI() throws Exception {
    long currentTime = new DateMidnight().getMillis();

    DescribeReservedInstancesOfferingsRequest req = new DescribeReservedInstancesOfferingsRequest().withFilters(
            new com.amazonaws.services.ec2.model.Filter().withName("marketplace").withValues("false"));
    String token = null;/*from  w ww .j  av a  2  s. c o  m*/
    boolean hasNewPrice = false;
    AmazonEC2Client ec2Client = new AmazonEC2Client(AwsUtils.awsCredentialsProvider, AwsUtils.clientConfig);

    for (Region region : Region.getAllRegions()) {
        ec2Client.setEndpoint("ec2." + region.name + ".amazonaws.com");
        do {
            if (!StringUtils.isEmpty(token))
                req.setNextToken(token);
            DescribeReservedInstancesOfferingsResult offers = ec2Client.describeReservedInstancesOfferings(req);
            token = offers.getNextToken();

            for (ReservedInstancesOffering offer : offers.getReservedInstancesOfferings()) {
                if (offer.getProductDescription().indexOf("Amazon VPC") >= 0)
                    continue;
                ReservationUtilization utilization = ReservationUtilization.get(offer.getOfferingType());
                Ec2InstanceReservationPrice.ReservationPeriod term = offer.getDuration() / 24 / 3600 > 366
                        ? Ec2InstanceReservationPrice.ReservationPeriod.threeyear
                        : Ec2InstanceReservationPrice.ReservationPeriod.oneyear;
                if (term != this.term)
                    continue;

                double hourly = offer.getUsagePrice();
                if (hourly <= 0) {
                    for (RecurringCharge recurringCharge : offer.getRecurringCharges()) {
                        if (recurringCharge.getFrequency().equals("Hourly")) {
                            hourly = recurringCharge.getAmount();
                            break;
                        }
                    }
                }
                UsageType usageType = getUsageType(offer.getInstanceType(), offer.getProductDescription());
                hasNewPrice = setPrice(utilization, currentTime,
                        Zone.getZone(offer.getAvailabilityZone()).region, usageType, offer.getFixedPrice(),
                        hourly) || hasNewPrice;

                logger.info("Setting RI price for " + Zone.getZone(offer.getAvailabilityZone()).region + " "
                        + utilization + " " + usageType + " " + offer.getFixedPrice() + " " + hourly);
            }
        } while (!StringUtils.isEmpty(token));
    }

    ec2Client.shutdown();
    if (hasNewPrice) {
        for (ReservationUtilization utilization : files.keySet()) {
            File file = files.get(utilization);
            DataOutputStream out = new DataOutputStream(new FileOutputStream(file));
            try {
                Serializer.serialize(out, this.ec2InstanceReservationPrices.get(utilization));
                AwsUtils.upload(config.workS3BucketName, config.workS3BucketPrefix, file);
            } finally {
                out.close();
            }
        }
    }
}