Search in sources :

Example 6 with InstanceDefinition

use of org.finra.herd.model.api.xml.InstanceDefinition in project herd by FINRAOS.

the class EmrPricingHelperTest method testBestPriceAlgorithmicMaxSearchPriceTooLow.

/**
 * Tests algorithmic case when the max search price is lower than both spot and on-demand price. The update method should throw an error indicating that no
 * subnets satisfied the given criteria.
 * <p/>
 * Test case reference ClusterSpotPriceAlgorithm 3
 */
@Test
public void testBestPriceAlgorithmicMaxSearchPriceTooLow() {
    String subnetId = SUBNET_1;
    MasterInstanceDefinition masterInstanceDefinition = new MasterInstanceDefinition();
    masterInstanceDefinition.setInstanceCount(1);
    masterInstanceDefinition.setInstanceType(INSTANCE_TYPE_1);
    masterInstanceDefinition.setInstanceMaxSearchPrice(SPOT_PRICE_LOW_LESS_ONE);
    InstanceDefinition coreInstanceDefinition = new InstanceDefinition();
    coreInstanceDefinition.setInstanceCount(1);
    coreInstanceDefinition.setInstanceType(INSTANCE_TYPE_1);
    coreInstanceDefinition.setInstanceMaxSearchPrice(SPOT_PRICE_LOW_LESS_ONE);
    InstanceDefinition taskInstanceDefinition = new InstanceDefinition();
    taskInstanceDefinition.setInstanceCount(1);
    taskInstanceDefinition.setInstanceType(INSTANCE_TYPE_1);
    taskInstanceDefinition.setInstanceMaxSearchPrice(SPOT_PRICE_LOW_LESS_ONE);
    // Try with both master, core, and task failing criteria
    try {
        updateEmrClusterDefinitionWithBestPrice(subnetId, masterInstanceDefinition, coreInstanceDefinition, taskInstanceDefinition);
        fail("Expected ObjectNotFoundException, but no exception was thrown");
    } catch (Exception e) {
        assertEquals("thrown exception", ObjectNotFoundException.class, e.getClass());
    }
    // Now try with only core and task failing criteria
    masterInstanceDefinition.setInstanceMaxSearchPrice(ON_DEMAND);
    try {
        updateEmrClusterDefinitionWithBestPrice(subnetId, masterInstanceDefinition, coreInstanceDefinition, taskInstanceDefinition);
        fail("Expected ObjectNotFoundException, but no exception was thrown");
    } catch (Exception e) {
        assertEquals("thrown exception", ObjectNotFoundException.class, e.getClass());
    }
    // Try with only task failing criteria
    coreInstanceDefinition.setInstanceMaxSearchPrice(ON_DEMAND);
    try {
        updateEmrClusterDefinitionWithBestPrice(subnetId, masterInstanceDefinition, coreInstanceDefinition, taskInstanceDefinition);
        fail("Expected ObjectNotFoundException, but no exception was thrown");
    } catch (Exception e) {
        assertEquals("thrown exception", ObjectNotFoundException.class, e.getClass());
    }
}
Also used : InstanceDefinition(org.finra.herd.model.api.xml.InstanceDefinition) MasterInstanceDefinition(org.finra.herd.model.api.xml.MasterInstanceDefinition) ObjectNotFoundException(org.finra.herd.model.ObjectNotFoundException) MasterInstanceDefinition(org.finra.herd.model.api.xml.MasterInstanceDefinition) ObjectNotFoundException(org.finra.herd.model.ObjectNotFoundException) AmazonServiceException(com.amazonaws.AmazonServiceException) Test(org.junit.Test) AbstractDaoTest(org.finra.herd.dao.AbstractDaoTest)

Example 7 with InstanceDefinition

use of org.finra.herd.model.api.xml.InstanceDefinition in project herd by FINRAOS.

the class EmrPricingHelperTest method testBestPriceMultipleRegions.

/**
 * Tests case where subnet spans multiple regions, and one of the region has a cheaper price. The on-demand prices are identified by region, therefore this
 * test case tests that the correct on-demand price is selected.
 * <p/>
 * Test case reference ClusterSpotPriceAlgorithm 14
 */
@Test
public void testBestPriceMultipleRegions() {
    String subnetId = SUBNET_1 + "," + SUBNET_5;
    MasterInstanceDefinition masterInstanceDefinition = new MasterInstanceDefinition();
    masterInstanceDefinition.setInstanceCount(1);
    masterInstanceDefinition.setInstanceType(INSTANCE_TYPE_1);
    InstanceDefinition coreInstanceDefinition = new InstanceDefinition();
    coreInstanceDefinition.setInstanceCount(1);
    coreInstanceDefinition.setInstanceType(INSTANCE_TYPE_1);
    InstanceDefinition taskInstanceDefinition = null;
    EmrClusterDefinition emrClusterDefinition = updateEmrClusterDefinitionWithBestPrice(subnetId, masterInstanceDefinition, coreInstanceDefinition, taskInstanceDefinition);
    assertBestPriceCriteriaRemoved(emrClusterDefinition);
    assertNull("master instance was not on-demand", emrClusterDefinition.getInstanceDefinitions().getMasterInstances().getInstanceSpotPrice());
    assertNull("core instance was not on-demand", emrClusterDefinition.getInstanceDefinitions().getMasterInstances().getInstanceSpotPrice());
    assertEquals("selected subnet", SUBNET_5, emrClusterDefinition.getSubnetId());
}
Also used : InstanceDefinition(org.finra.herd.model.api.xml.InstanceDefinition) MasterInstanceDefinition(org.finra.herd.model.api.xml.MasterInstanceDefinition) EmrClusterDefinition(org.finra.herd.model.api.xml.EmrClusterDefinition) MasterInstanceDefinition(org.finra.herd.model.api.xml.MasterInstanceDefinition) Test(org.junit.Test) AbstractDaoTest(org.finra.herd.dao.AbstractDaoTest)

Example 8 with InstanceDefinition

use of org.finra.herd.model.api.xml.InstanceDefinition in project herd by FINRAOS.

the class EmrPricingHelperTest method testBestPriceAlgorithmicSearchBelowOnDemandThresholdBelowOnDemand.

/**
 * Tests case where max search price < on-demand, threshold < on-demand. The algorithm should select spot price because max search price is below
 * on-demand.
 * <p/>
 * Test case reference ClusterSpotPriceAlgorithm 8
 */
@Test
public void testBestPriceAlgorithmicSearchBelowOnDemandThresholdBelowOnDemand() {
    String subnetId = SUBNET_1;
    MasterInstanceDefinition masterInstanceDefinition = new MasterInstanceDefinition();
    masterInstanceDefinition.setInstanceCount(1);
    masterInstanceDefinition.setInstanceType(INSTANCE_TYPE_1);
    masterInstanceDefinition.setInstanceMaxSearchPrice(ON_DEMAND_LESS_ONE);
    masterInstanceDefinition.setInstanceOnDemandThreshold(ON_DEMAND_LESS_ONE.subtract(SPOT_PRICE_LOW));
    InstanceDefinition coreInstanceDefinition = new InstanceDefinition();
    coreInstanceDefinition.setInstanceCount(1);
    coreInstanceDefinition.setInstanceType(INSTANCE_TYPE_1);
    coreInstanceDefinition.setInstanceMaxSearchPrice(ON_DEMAND_LESS_ONE);
    coreInstanceDefinition.setInstanceOnDemandThreshold(ON_DEMAND_LESS_ONE.subtract(SPOT_PRICE_LOW));
    InstanceDefinition taskInstanceDefinition = null;
    EmrClusterDefinition emrClusterDefinition = updateEmrClusterDefinitionWithBestPrice(subnetId, masterInstanceDefinition, coreInstanceDefinition, taskInstanceDefinition);
    assertBestPriceCriteriaRemoved(emrClusterDefinition);
    assertEquals("master instance bid price", ON_DEMAND_LESS_ONE, emrClusterDefinition.getInstanceDefinitions().getMasterInstances().getInstanceSpotPrice());
    assertEquals("core instance bid price", ON_DEMAND_LESS_ONE, emrClusterDefinition.getInstanceDefinitions().getCoreInstances().getInstanceSpotPrice());
}
Also used : InstanceDefinition(org.finra.herd.model.api.xml.InstanceDefinition) MasterInstanceDefinition(org.finra.herd.model.api.xml.MasterInstanceDefinition) EmrClusterDefinition(org.finra.herd.model.api.xml.EmrClusterDefinition) MasterInstanceDefinition(org.finra.herd.model.api.xml.MasterInstanceDefinition) Test(org.junit.Test) AbstractDaoTest(org.finra.herd.dao.AbstractDaoTest)

Example 9 with InstanceDefinition

use of org.finra.herd.model.api.xml.InstanceDefinition in project herd by FINRAOS.

the class EmrPricingHelperTest method testBestPriceSubnetNotFound.

/**
 * Tests case where at least one user specified subnet does not exist. This is a user error.
 */
@Test
public void testBestPriceSubnetNotFound() {
    String subnetId = "I_DO_NOT_EXIST," + SUBNET_1;
    MasterInstanceDefinition masterInstanceDefinition = new MasterInstanceDefinition();
    masterInstanceDefinition.setInstanceCount(1);
    masterInstanceDefinition.setInstanceType(INSTANCE_TYPE_1);
    InstanceDefinition coreInstanceDefinition = new InstanceDefinition();
    coreInstanceDefinition.setInstanceCount(1);
    coreInstanceDefinition.setInstanceType(INSTANCE_TYPE_1);
    InstanceDefinition taskInstanceDefinition = null;
    try {
        updateEmrClusterDefinitionWithBestPrice(subnetId, masterInstanceDefinition, coreInstanceDefinition, taskInstanceDefinition);
        fail("expected ObjectNotFoundException, but no exception was thrown");
    } catch (Exception e) {
        assertEquals("thrown exception", ObjectNotFoundException.class, e.getClass());
    }
}
Also used : InstanceDefinition(org.finra.herd.model.api.xml.InstanceDefinition) MasterInstanceDefinition(org.finra.herd.model.api.xml.MasterInstanceDefinition) ObjectNotFoundException(org.finra.herd.model.ObjectNotFoundException) MasterInstanceDefinition(org.finra.herd.model.api.xml.MasterInstanceDefinition) ObjectNotFoundException(org.finra.herd.model.ObjectNotFoundException) AmazonServiceException(com.amazonaws.AmazonServiceException) Test(org.junit.Test) AbstractDaoTest(org.finra.herd.dao.AbstractDaoTest)

Example 10 with InstanceDefinition

use of org.finra.herd.model.api.xml.InstanceDefinition in project herd by FINRAOS.

the class EmrPricingHelperTest method testBestPriceAlgorithmicOnDemandOverMaxAndSpotGreaterThanOnDemand.

/**
 * Tests 2 cases: Master spot is less than on-demand, max search price is less than on-demand, threshold is greater than on-demand. - Master should pick
 * spot because even though on-demand is within the threshold, it is above the max Core spot > on-demand, max search price = spot - Core should pick
 * on-demand since on-demand is cheaper
 * <p/>
 * Test case reference ClusterSpotPriceAlgorithm 4, 5
 */
@Test
public void testBestPriceAlgorithmicOnDemandOverMaxAndSpotGreaterThanOnDemand() {
    String subnetId = SUBNET_1;
    MasterInstanceDefinition masterInstanceDefinition = new MasterInstanceDefinition();
    masterInstanceDefinition.setInstanceCount(1);
    masterInstanceDefinition.setInstanceType(INSTANCE_TYPE_1);
    masterInstanceDefinition.setInstanceMaxSearchPrice(ON_DEMAND_LESS_ONE);
    masterInstanceDefinition.setInstanceOnDemandThreshold(SPOT_PRICE_LOW_PLUS_ONE);
    InstanceDefinition coreInstanceDefinition = new InstanceDefinition();
    coreInstanceDefinition.setInstanceCount(1);
    coreInstanceDefinition.setInstanceType(INSTANCE_TYPE_3);
    coreInstanceDefinition.setInstanceMaxSearchPrice(ON_DEMAND);
    InstanceDefinition taskInstanceDefinition = null;
    EmrClusterDefinition emrClusterDefinition = updateEmrClusterDefinitionWithBestPrice(subnetId, masterInstanceDefinition, coreInstanceDefinition, taskInstanceDefinition);
    assertBestPriceCriteriaRemoved(emrClusterDefinition);
    assertEquals("master instance bid price", ON_DEMAND_LESS_ONE, emrClusterDefinition.getInstanceDefinitions().getMasterInstances().getInstanceSpotPrice());
    assertNull("core instance was not on-demand", emrClusterDefinition.getInstanceDefinitions().getCoreInstances().getInstanceSpotPrice());
}
Also used : InstanceDefinition(org.finra.herd.model.api.xml.InstanceDefinition) MasterInstanceDefinition(org.finra.herd.model.api.xml.MasterInstanceDefinition) EmrClusterDefinition(org.finra.herd.model.api.xml.EmrClusterDefinition) MasterInstanceDefinition(org.finra.herd.model.api.xml.MasterInstanceDefinition) Test(org.junit.Test) AbstractDaoTest(org.finra.herd.dao.AbstractDaoTest)

Aggregations

InstanceDefinition (org.finra.herd.model.api.xml.InstanceDefinition)39 MasterInstanceDefinition (org.finra.herd.model.api.xml.MasterInstanceDefinition)36 Test (org.junit.Test)34 AbstractDaoTest (org.finra.herd.dao.AbstractDaoTest)27 EmrClusterDefinition (org.finra.herd.model.api.xml.EmrClusterDefinition)24 ObjectNotFoundException (org.finra.herd.model.ObjectNotFoundException)8 InstanceDefinitions (org.finra.herd.model.api.xml.InstanceDefinitions)7 AmazonServiceException (com.amazonaws.AmazonServiceException)5 NodeTag (org.finra.herd.model.api.xml.NodeTag)5 RunJobFlowRequest (com.amazonaws.services.elasticmapreduce.model.RunJobFlowRequest)4 AwsParamsDto (org.finra.herd.model.dto.AwsParamsDto)4 InvocationOnMock (org.mockito.invocation.InvocationOnMock)4 InstanceGroupConfig (com.amazonaws.services.elasticmapreduce.model.InstanceGroupConfig)3 BigDecimal (java.math.BigDecimal)3 ArrayList (java.util.ArrayList)3 EmrVpcPricingState (org.finra.herd.model.dto.EmrVpcPricingState)3 HashMap (java.util.HashMap)2 EmrClusterDefinitionCreateRequest (org.finra.herd.model.api.xml.EmrClusterDefinitionCreateRequest)2 ClientConfiguration (com.amazonaws.ClientConfiguration)1 AvailabilityZone (com.amazonaws.services.ec2.model.AvailabilityZone)1