use of org.finra.herd.model.dto.EmrClusterPriceDto in project herd by FINRAOS.
the class EmrPricingHelperTest method testGetEmrClusterPricesWithinLowestCoreInstancePriceEmptyCoreInstanceMultiplePricings.
/**
* 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()));
}
}
use of org.finra.herd.model.dto.EmrClusterPriceDto in project herd by FINRAOS.
the class EmrPricingHelperTest method testGetEmrClusterPricesWithinLowestCoreInstancePriceThresholdMultiplePricing.
@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()));
}
}
use of org.finra.herd.model.dto.EmrClusterPriceDto in project herd by FINRAOS.
the class EmrPricingHelperTest method createSimpleEmrClusterPrice.
private EmrClusterPriceDto createSimpleEmrClusterPrice(final String availabilityZone, final BigDecimal instancePrice) {
EmrClusterPriceDto emrClusterPriceDto = new EmrClusterPriceDto();
emrClusterPriceDto.setAvailabilityZone(availabilityZone);
if (instancePrice != null) {
Ec2PriceDto corePrice = new Ec2PriceDto();
corePrice.setInstanceCount(1);
corePrice.setInstancePrice(instancePrice);
emrClusterPriceDto.setCorePrice(corePrice);
}
return emrClusterPriceDto;
}
use of org.finra.herd.model.dto.EmrClusterPriceDto in project herd by FINRAOS.
the class EmrPricingHelper method getEmrClusterPriceWithLowestCoreInstancePrice.
/**
* 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;
}
}
use of org.finra.herd.model.dto.EmrClusterPriceDto in project herd by FINRAOS.
the class EmrPricingHelper method getEmrClusterPricesWithinLowestCoreInstancePriceThreshold.
/**
* Finds all the clusters that are within the range of lowest core instance price.
* <p>
* For example, if the core prices are 0.30, 0.32, 0.34, 0.36, and the threshold value is 0.1(10%), then the lowest core price range should be [0.30, 0.33].
* The upper bound is derived by calculating 0.30*(1 + 0.1) = 0.33
*
* @param emrClusterPrices the list of clusters to select from
* @param lowestCoreInstancePriceThresholdPercentage the threshold value that defines the range of lowest core instance price
*
* @return the list of clusters that fall in lowest core instance price range
*/
List<EmrClusterPriceDto> getEmrClusterPricesWithinLowestCoreInstancePriceThreshold(final List<EmrClusterPriceDto> emrClusterPrices, final BigDecimal lowestCoreInstancePriceThresholdPercentage) {
// Builds a tree map that has the core instance price as the key, and the list of pricing with the same core instance price as the value. The tree map
// is automatically sorted, so it is easy to find the lowest core instance price range.
TreeMap<BigDecimal, List<EmrClusterPriceDto>> emrClusterPriceMapKeyedByCoreInstancePrice = new TreeMap<>();
for (final EmrClusterPriceDto emrClusterPriceDto : emrClusterPrices) {
final BigDecimal coreInstancePrice = getEmrClusterCoreInstancePrice(emrClusterPriceDto);
if (emrClusterPriceMapKeyedByCoreInstancePrice.containsKey(coreInstancePrice)) {
emrClusterPriceMapKeyedByCoreInstancePrice.get(coreInstancePrice).add(emrClusterPriceDto);
} else {
List<EmrClusterPriceDto> emrClusterPriceList = new ArrayList<>();
emrClusterPriceList.add(emrClusterPriceDto);
emrClusterPriceMapKeyedByCoreInstancePrice.put(coreInstancePrice, emrClusterPriceList);
}
}
// Log all the information in the tree map
LOGGER.info("All available EMR clusters keyed by core instance price: availableEmrClusters={}", jsonHelper.objectToJson(emrClusterPriceMapKeyedByCoreInstancePrice));
// Finds the list of pricing in the range of the lowest core instance price
List<EmrClusterPriceDto> lowestCoreInstancePriceEmrClusters = new ArrayList<>();
if (!emrClusterPriceMapKeyedByCoreInstancePrice.isEmpty()) {
// calculate the lowest core instance price range
final BigDecimal lowestCoreInstancePriceLowerBound = emrClusterPriceMapKeyedByCoreInstancePrice.firstEntry().getKey();
final BigDecimal lowestCoreInstancePriceUpperBound = lowestCoreInstancePriceLowerBound.multiply(BigDecimal.ONE.add(lowestCoreInstancePriceThresholdPercentage));
LOGGER.info("emrClusterLowestCoreInstancePriceRange={}", jsonHelper.objectToJson(Arrays.asList(lowestCoreInstancePriceLowerBound, lowestCoreInstancePriceUpperBound)));
for (final Map.Entry<BigDecimal, List<EmrClusterPriceDto>> entry : emrClusterPriceMapKeyedByCoreInstancePrice.entrySet()) {
final BigDecimal coreInstancePrice = entry.getKey();
// There is no need to check the lower bound here, since the tree map is sorted, and lower bound is the lowest core price in the tree map.
if (coreInstancePrice.compareTo(lowestCoreInstancePriceUpperBound) <= 0) {
lowestCoreInstancePriceEmrClusters.addAll(entry.getValue());
} else {
// since the tree map is sorted in ascending order, we do not need to check the rest of entries in the map
break;
}
}
}
return lowestCoreInstancePriceEmrClusters;
}
Aggregations