@Override public Map<AvailabilityZone, List<ReservedInstances>> getReservedInstancesForZone( AvailabilityZone zone, AmazonEC2Client client) throws Exception { OperationStats op = new OperationStats("ec2InstanceStore", "getReservedInstancesForZone"); try { Map<AvailabilityZone, List<ReservedInstances>> ret = new HashMap<>(); DescribeReservedInstancesRequest request = new DescribeReservedInstancesRequest() .withFilters(new Filter("availability-zone", Arrays.asList(zone.getZoneName()))) .withSdkClientExecutionTimeout( 600 * 1000) //10 minutes time out for total execution including retries .withSdkRequestTimeout(300 * 1000); //5 minutes time out for a single request DescribeReservedInstancesResult result = client.describeReservedInstances(request); ret.put(zone, result.getReservedInstances()); op.succeed(); return ret; } catch (Exception e) { op.failed(); logger.error(ExceptionUtils.getRootCauseMessage(e)); throw e; } }
@Override public void onSuccess(DescribeReservedInstancesRequest request, DescribeReservedInstancesResult describeReservedInstancesResult) { List<ReservedInstances> reservedInstances = describeReservedInstancesResult .getReservedInstances(); if (CollectionUtils.isNotEmpty(reservedInstances)) { DateTime endDate = new DateTime(DateTimeZone.UTC).withDayOfMonth(1) .minusMonths(NO_OF_MONTHS) .withTimeAtStartOfDay(); for (ReservedInstances reservedInstance : reservedInstances) { if (reservedInstance.getEnd() != null && reservedInstance.getEnd().before( endDate.toDate())) { continue; } // Set the Region for RI's whose scope is region. if (reservedInstance != null && reservedInstance.getScope() != null && reservedInstance.getScope().equals(REGION)) { reservedInstance.setAvailabilityZone(this.region.getRegionName()); } this.context.reservedInstancesPlan.add(reservedInstance); } } checkAndPatchReservedInstancesPlans(); }
/** * Get Reserved instances for a given region * @param region * @return */ @Override public List<ReservedInstances> getReservedInstances(Region region) { OperationStats op = new OperationStats("ec2InstanceStore", "getReservedInstances"); try { AmazonEC2Client client = getClient(region); DescribeReservedInstancesRequest request = new DescribeReservedInstancesRequest() .withSdkClientExecutionTimeout( 600 * 1000) //10 minutes time out for total execution including retries .withSdkRequestTimeout(300 * 1000); //5 minutes time out for a single request DescribeReservedInstancesResult result = client.describeReservedInstances(request); op.succeed(); return result.getReservedInstances(); } catch (Exception e) { op.failed(); logger.error(ExceptionUtils.getRootCauseMessage(e)); throw e; } }
@Override protected void getReservedInstancesPlans(AWSReservedInstanceContext context) { AtomicInteger currentStageTaskCount = new AtomicInteger(1); DescribeReservedInstancesRequest request = new DescribeReservedInstancesRequest(); DescribeReservedInstancesResult result = new DescribeReservedInstancesResult(); result.setReservedInstances(Arrays.asList(createReservedInstance("ri1"))); new AWSReservedInstanceAsyncHandler(getHost(), currentStageTaskCount, null, context) .onSuccess(request, result); }
@Override public DescribeReservedInstancesResult describeReservedInstances(DescribeReservedInstancesRequest describeReservedInstancesRequest) throws AmazonServiceException, AmazonClientException { throw new UnsupportedOperationException("Not supported in mock"); }