.put(new Ec2OnDemandPricingKey(ec2OnDemandPricingEntity.getRegionName(), ec2OnDemandPricingEntity.getInstanceType()), ec2OnDemandPricingEntity); if (!ec2OnDemandPricing.getPricePerHour().equals(ec2OnDemandPricingEntity.getHourlyPrice())) String oldHourlyPriceAsString = ec2OnDemandPricingEntity.getHourlyPrice().toPlainString(); ec2OnDemandPricingEntity.setHourlyPrice(ec2OnDemandPricing.getPricePerHour()); ec2OnDemandPricingDao.saveAndRefresh(ec2OnDemandPricingEntity); Ec2OnDemandPricingEntity ec2OnDemandPricingEntity = new Ec2OnDemandPricingEntity(); ec2OnDemandPricingEntity.setRegionName(ec2OnDemandPricingKey.getRegionName()); ec2OnDemandPricingEntity.setInstanceType(ec2OnDemandPricingKey.getInstanceType()); ec2OnDemandPricingEntity.setHourlyPrice(ec2OnDemandPricing.getPricePerHour()); ec2OnDemandPricingDao.saveAndRefresh(ec2OnDemandPricingEntity); LOGGER.info("Deleted EC2 on-demand pricing: regionName=\"{}\" instanceType=\"{}\" hourlyPrice={}", ec2OnDemandPricingEntity.getRegionName(), ec2OnDemandPricingEntity.getInstanceType(), ec2OnDemandPricingEntity.getHourlyPrice().toPlainString());
/** * Creates and persists a new EC2 on-demand pricing entity. * * @param regionName the AWS region name * @param instanceType the EC2 instance type * @param hourlyPrice the hourly price * * @return the newly created entity */ public Ec2OnDemandPricingEntity createEc2OnDemandPricingEntity(String regionName, String instanceType, BigDecimal hourlyPrice) { Ec2OnDemandPricingEntity ec2OnDemandPricingEntity = new Ec2OnDemandPricingEntity(); ec2OnDemandPricingEntity.setRegionName(regionName); ec2OnDemandPricingEntity.setInstanceType(instanceType); ec2OnDemandPricingEntity.setHourlyPrice(hourlyPrice); return ec2OnDemandPricingDao.saveAndRefresh(ec2OnDemandPricingEntity); } }
/** * Returns a mapping of instance types to on-demand prices for the given AZ and instance types. The on-demand prices are retrieved from database * configurations. The on-demand prices are looked up by the AZ's region name. This method also validates that the given instance types are real instance * types supported by AWS. * * @param availabilityZone the availability zone of the on-demand instances * @param instanceTypes the sizes of the on-demand instances * * @return the map of instance type to on-demand price * @throws ObjectNotFoundException when any of the instance type was not found in the given region */ private Map<String, BigDecimal> getInstanceTypeOnDemandPrices(AvailabilityZone availabilityZone, Set<String> instanceTypes) { Map<String, BigDecimal> instanceTypeOnDemandPrices = new HashMap<>(); for (String instanceType : instanceTypes) { Ec2OnDemandPricingEntity onDemandPrice = ec2OnDemandPricingDao.getEc2OnDemandPricing(availabilityZone.getRegionName(), instanceType); if (onDemandPrice == null) { throw new ObjectNotFoundException( "On-demand price for region '" + availabilityZone.getRegionName() + "' and instance type '" + instanceType + "' not found."); } instanceTypeOnDemandPrices.put(instanceType, onDemandPrice.getHourlyPrice()); } return instanceTypeOnDemandPrices; }
Arrays.asList(new Ec2OnDemandPricingEntity(), new Ec2OnDemandPricingEntity(), new Ec2OnDemandPricingEntity()); ec2OnDemandPricingEntities.get(0).setRegionName(AWS_REGION_NAME); ec2OnDemandPricingEntities.get(0).setInstanceType(EC2_INSTANCE_TYPE); ec2OnDemandPricingEntities.get(0).setHourlyPrice(HOURLY_PRICE); ec2OnDemandPricingEntities.get(1).setRegionName(AWS_REGION_NAME_2); ec2OnDemandPricingEntities.get(1).setInstanceType(EC2_INSTANCE_TYPE_2); ec2OnDemandPricingEntities.get(1).setHourlyPrice(HOURLY_PRICE_2); ec2OnDemandPricingEntities.get(2).setRegionName(AWS_REGION_NAME_3); ec2OnDemandPricingEntities.get(2).setInstanceType(EC2_INSTANCE_TYPE_3); ec2OnDemandPricingEntities.get(2).setHourlyPrice(HOURLY_PRICE_3); assertEquals(HOURLY_PRICE_2, ec2OnDemandPricingEntities.get(1).getHourlyPrice()); assertEquals(HOURLY_PRICE_5, ec2OnDemandPricingEntities.get(2).getHourlyPrice());
/** * Returns a mapping of instance types to on-demand prices for the given AZ and instance types. The on-demand prices are retrieved from database * configurations. The on-demand prices are looked up by the AZ's region name. This method also validates that the given instance types are real instance * types supported by AWS. * * @param availabilityZone the availability zone of the on-demand instances * @param instanceTypes the sizes of the on-demand instances * * @return the map of instance type to on-demand price * @throws ObjectNotFoundException when any of the instance type was not found in the given region */ private Map<String, BigDecimal> getInstanceTypeOnDemandPrices(AvailabilityZone availabilityZone, Set<String> instanceTypes) { Map<String, BigDecimal> instanceTypeOnDemandPrices = new HashMap<>(); for (String instanceType : instanceTypes) { Ec2OnDemandPricingEntity onDemandPrice = ec2OnDemandPricingDao.getEc2OnDemandPricing(availabilityZone.getRegionName(), instanceType); if (onDemandPrice == null) { throw new ObjectNotFoundException( "On-demand price for region '" + availabilityZone.getRegionName() + "' and instance type '" + instanceType + "' not found."); } instanceTypeOnDemandPrices.put(instanceType, onDemandPrice.getHourlyPrice()); } return instanceTypeOnDemandPrices; }
.put(new Ec2OnDemandPricingKey(ec2OnDemandPricingEntity.getRegionName(), ec2OnDemandPricingEntity.getInstanceType()), ec2OnDemandPricingEntity); if (!ec2OnDemandPricing.getPricePerHour().equals(ec2OnDemandPricingEntity.getHourlyPrice())) String oldHourlyPriceAsString = ec2OnDemandPricingEntity.getHourlyPrice().toPlainString(); ec2OnDemandPricingEntity.setHourlyPrice(ec2OnDemandPricing.getPricePerHour()); ec2OnDemandPricingDao.saveAndRefresh(ec2OnDemandPricingEntity); Ec2OnDemandPricingEntity ec2OnDemandPricingEntity = new Ec2OnDemandPricingEntity(); ec2OnDemandPricingEntity.setRegionName(ec2OnDemandPricingKey.getRegionName()); ec2OnDemandPricingEntity.setInstanceType(ec2OnDemandPricingKey.getInstanceType()); ec2OnDemandPricingEntity.setHourlyPrice(ec2OnDemandPricing.getPricePerHour()); ec2OnDemandPricingDao.saveAndRefresh(ec2OnDemandPricingEntity); LOGGER.info("Deleted EC2 on-demand pricing: regionName=\"{}\" instanceType=\"{}\" hourlyPrice={}", ec2OnDemandPricingEntity.getRegionName(), ec2OnDemandPricingEntity.getInstanceType(), ec2OnDemandPricingEntity.getHourlyPrice().toPlainString());