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

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

Introduction

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

Prototype


public String getInstanceType() 

Source Link

Document

The instance type on which the Reserved Instance can be used.

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();//from  www .j  a  v a  2s  .  co  m
    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  a v a 2 s.co 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();
            }
        }
    }
}