Search in sources :

Example 1 with EmrClusterPriceDto

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()));
    }
}
Also used : EmrClusterPriceDto(org.finra.herd.model.dto.EmrClusterPriceDto) Test(org.junit.Test) AbstractDaoTest(org.finra.herd.dao.AbstractDaoTest)

Example 2 with EmrClusterPriceDto

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()));
    }
}
Also used : EmrClusterPriceDto(org.finra.herd.model.dto.EmrClusterPriceDto) Test(org.junit.Test) AbstractDaoTest(org.finra.herd.dao.AbstractDaoTest)

Example 3 with EmrClusterPriceDto

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;
}
Also used : Ec2PriceDto(org.finra.herd.model.dto.Ec2PriceDto) EmrClusterPriceDto(org.finra.herd.model.dto.EmrClusterPriceDto)

Example 4 with 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;
    }
}
Also used : Random(java.util.Random) EmrClusterPriceDto(org.finra.herd.model.dto.EmrClusterPriceDto)

Example 5 with EmrClusterPriceDto

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;
}
Also used : EmrClusterPriceDto(org.finra.herd.model.dto.EmrClusterPriceDto) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) TreeMap(java.util.TreeMap) HashMap(java.util.HashMap) Map(java.util.Map) TreeMap(java.util.TreeMap) BigDecimal(java.math.BigDecimal)

Aggregations

EmrClusterPriceDto (org.finra.herd.model.dto.EmrClusterPriceDto)8 AbstractDaoTest (org.finra.herd.dao.AbstractDaoTest)3 Test (org.junit.Test)3 BigDecimal (java.math.BigDecimal)2 ArrayList (java.util.ArrayList)2 Ec2PriceDto (org.finra.herd.model.dto.Ec2PriceDto)2 AvailabilityZone (com.amazonaws.services.ec2.model.AvailabilityZone)1 Subnet (com.amazonaws.services.ec2.model.Subnet)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Random (java.util.Random)1 TreeMap (java.util.TreeMap)1 ObjectNotFoundException (org.finra.herd.model.ObjectNotFoundException)1 InstanceDefinition (org.finra.herd.model.api.xml.InstanceDefinition)1 MasterInstanceDefinition (org.finra.herd.model.api.xml.MasterInstanceDefinition)1 EmrVpcPricingState (org.finra.herd.model.dto.EmrVpcPricingState)1