Example usage for com.amazonaws.services.ec2.model DescribeReservedInstancesOfferingsResult getNextToken

List of usage examples for com.amazonaws.services.ec2.model DescribeReservedInstancesOfferingsResult getNextToken

Introduction

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

Prototype


public String getNextToken() 

Source Link

Document

The token to use to retrieve the next page of results.

Usage

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

License:Open Source License

private void addReservedOfferings(ArrayNode array, String availabilityZone, String productDescription,
        String offeringType, String instanceType) {
    DescribeReservedInstancesOfferingsRequest req = new DescribeReservedInstancesOfferingsRequest()
            .withIncludeMarketplace(false).withInstanceTenancy(Tenancy.Default); // Not Tenancy.Dedicated
    if (availabilityZone != null)
        req.setAvailabilityZone(availabilityZone);
    if (productDescription != null)
        req.setProductDescription(productDescription);
    if (offeringType != null)
        req.setOfferingType(offeringType);
    if (instanceType != null)
        req.setInstanceType(parseInstanceType(instanceType));

    String nextToken = null;/*from ww  w .  ja v a 2s . co m*/
    do {
        DescribeReservedInstancesOfferingsResult res = ec2.describeReservedInstancesOfferings(req);
        for (ReservedInstancesOffering o : res.getReservedInstancesOfferings()) {
            Offering offering = new Offering(o);
            try {
                array.add(offering.toJsonNode());
            } catch (JsonProcessingException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        nextToken = res.getNextToken();
        req.withNextToken(nextToken);
    } while (nextToken != null);
}

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 2s .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();
            }
        }
    }
}