/** * Selects the EMR cluster pricing with the lowest core instance price. We will select one pricing randomly if there are multiple pricings that meet the * lowest core price criteria. * <p> * Returns null if the given list is empty * * @param emrClusterPrices the list of pricing to select from * * @return the pricing with the lowest core price */ EmrClusterPriceDto getEmrClusterPriceWithLowestCoreInstancePrice(final List<EmrClusterPriceDto> emrClusterPrices) { final List<EmrClusterPriceDto> lowestCoreInstancePriceEmrClusters = getEmrClusterPricesWithinLowestCoreInstancePriceThreshold(emrClusterPrices, configurationHelper.getNonNegativeBigDecimalRequiredProperty(ConfigurationValue.EMR_CLUSTER_LOWEST_CORE_INSTANCE_PRICE_PERCENTAGE)); if (!lowestCoreInstancePriceEmrClusters.isEmpty()) { // Pick one randomly from the lowest core instance price list final EmrClusterPriceDto selectedEmrClusterPriceDto = lowestCoreInstancePriceEmrClusters.get(new Random().nextInt(lowestCoreInstancePriceEmrClusters.size())); // Log the selected pricing as well as the pricing list LOGGER.info("selectedEmrCluster={} from lowestCoreInstancePriceEmrClusters={}", jsonHelper.objectToJson(selectedEmrClusterPriceDto), jsonHelper.objectToJson(lowestCoreInstancePriceEmrClusters)); return selectedEmrClusterPriceDto; } else { return null; } }
/** * Selects the EMR cluster pricing with the lowest core instance price. We will select one pricing randomly if there are multiple pricings that meet the * lowest core price criteria. * <p> * Returns null if the given list is empty * * @param emrClusterPrices the list of pricing to select from * * @return the pricing with the lowest core price */ EmrClusterPriceDto getEmrClusterPriceWithLowestCoreInstancePrice(final List<EmrClusterPriceDto> emrClusterPrices) { final List<EmrClusterPriceDto> lowestCoreInstancePriceEmrClusters = getEmrClusterPricesWithinLowestCoreInstancePriceThreshold(emrClusterPrices, configurationHelper.getNonNegativeBigDecimalRequiredProperty(ConfigurationValue.EMR_CLUSTER_LOWEST_CORE_INSTANCE_PRICE_PERCENTAGE)); if (!lowestCoreInstancePriceEmrClusters.isEmpty()) { // Pick one randomly from the lowest core instance price list final EmrClusterPriceDto selectedEmrClusterPriceDto = lowestCoreInstancePriceEmrClusters.get(new Random().nextInt(lowestCoreInstancePriceEmrClusters.size())); // Log the selected pricing as well as the pricing list LOGGER.info("selectedEmrCluster={} from lowestCoreInstancePriceEmrClusters={}", jsonHelper.objectToJson(selectedEmrClusterPriceDto), jsonHelper.objectToJson(lowestCoreInstancePriceEmrClusters)); return selectedEmrClusterPriceDto; } else { return null; } }
@Test public void testGetEmrClusterPricesWithinLowestCoreInstancePriceThresholdSinglePricing() throws Exception { List<EmrClusterPriceDto> pricingList = Arrays.asList(createSimpleEmrClusterPrice(AVAILABILITY_ZONE_1, BigDecimal.ONE)); List<EmrClusterPriceDto> lowestCoreInstancePriceClusters = emrPricingHelper.getEmrClusterPricesWithinLowestCoreInstancePriceThreshold(pricingList, TEN_PERCENT); assertEquals(1, lowestCoreInstancePriceClusters.size()); assertEquals(AVAILABILITY_ZONE_1, lowestCoreInstancePriceClusters.get(0).getAvailabilityZone()); }
/** * Tests when one cluster does not have core instance. In this case this cluster will be picked since the price for the cluster is now zero (the lowest) * * @throws Exception */ @Test public void testGetEmrClusterPricesWithinLowestCoreInstancePriceEmptyCoreInstanceMultiplePricings() throws Exception { List<EmrClusterPriceDto> pricingList = Arrays.asList(createSimpleEmrClusterPrice(AVAILABILITY_ZONE_1, BigDecimal.ONE), createSimpleEmrClusterPrice(AVAILABILITY_ZONE_4, null)); List<EmrClusterPriceDto> lowestCoreInstancePriceClusters = emrPricingHelper.getEmrClusterPricesWithinLowestCoreInstancePriceThreshold(pricingList, TEN_PERCENT); assertEquals(1, lowestCoreInstancePriceClusters.size()); for (EmrClusterPriceDto emrClusterPriceDto : lowestCoreInstancePriceClusters) { assertTrue(Arrays.asList(AVAILABILITY_ZONE_4).contains(emrClusterPriceDto.getAvailabilityZone())); } }
@Test public void testGetEmrClusterPricesWithinLowestCoreInstancePriceThresholdMultiplePricing() throws Exception { List<EmrClusterPriceDto> pricingList = Arrays .asList(createSimpleEmrClusterPrice(AVAILABILITY_ZONE_1, BigDecimal.ONE), createSimpleEmrClusterPrice(AVAILABILITY_ZONE_2, BigDecimal.TEN), createSimpleEmrClusterPrice(AVAILABILITY_ZONE_3, ONE_POINT_ONE), createSimpleEmrClusterPrice(AVAILABILITY_ZONE_4, ONE_POINT_ONE_ONE)); List<EmrClusterPriceDto> lowestCoreInstancePriceClusters = emrPricingHelper.getEmrClusterPricesWithinLowestCoreInstancePriceThreshold(pricingList, TEN_PERCENT); assertEquals(2, lowestCoreInstancePriceClusters.size()); for (EmrClusterPriceDto emrClusterPriceDto : lowestCoreInstancePriceClusters) { assertTrue(Arrays.asList(AVAILABILITY_ZONE_1, AVAILABILITY_ZONE_3).contains(emrClusterPriceDto.getAvailabilityZone())); } }
/** * Tests when the threshold is set to zero. * * @throws Exception */ @Test public void testGetEmrClusterPricesWithinLowestCoreInstancePriceZeroThresholdMultiplePricings() throws Exception { List<EmrClusterPriceDto> pricingList = Arrays .asList(createSimpleEmrClusterPrice(AVAILABILITY_ZONE_1, BigDecimal.ONE), createSimpleEmrClusterPrice(AVAILABILITY_ZONE_2, BigDecimal.TEN), createSimpleEmrClusterPrice(AVAILABILITY_ZONE_3, BigDecimal.ONE.add(FIVE_UNIT)), createSimpleEmrClusterPrice(AVAILABILITY_ZONE_4, BigDecimal.ONE)); List<EmrClusterPriceDto> lowestCoreInstancePriceClusters = emrPricingHelper.getEmrClusterPricesWithinLowestCoreInstancePriceThreshold(pricingList, BigDecimal.ZERO); assertEquals(2, lowestCoreInstancePriceClusters.size()); for (EmrClusterPriceDto emrClusterPriceDto : lowestCoreInstancePriceClusters) { assertTrue(Arrays.asList(AVAILABILITY_ZONE_1, AVAILABILITY_ZONE_4).contains(emrClusterPriceDto.getAvailabilityZone())); } }