Search in sources :

Example 11 with InstanceDefinition

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

the class EmrPricingHelperTest method testBestPriceExplicitSpotAndSpotPriceNotAvailable.

/**
 * Tests algorithmic case when spot is explicitly requested and spot price is not available. The update method should throw an error indicating that no
 * subnets satisfied the given criteria.
 */
@Test
public void testBestPriceExplicitSpotAndSpotPriceNotAvailable() {
    String subnetId = SUBNET_1;
    // For master instance definition, use instance type that does not have spot price available.
    MasterInstanceDefinition masterInstanceDefinition = new MasterInstanceDefinition();
    masterInstanceDefinition.setInstanceCount(1);
    masterInstanceDefinition.setInstanceType(INSTANCE_TYPE_4);
    masterInstanceDefinition.setInstanceSpotPrice(ON_DEMAND);
    InstanceDefinition coreInstanceDefinition = null;
    InstanceDefinition taskInstanceDefinition = null;
    // Try with master failing criteria
    try {
        updateEmrClusterDefinitionWithBestPrice(subnetId, masterInstanceDefinition, coreInstanceDefinition, taskInstanceDefinition);
        fail();
    } catch (ObjectNotFoundException e) {
        // Set expected EMR VPC price state.
        EmrVpcPricingState expectedEmrVpcPricingState = new EmrVpcPricingState();
        expectedEmrVpcPricingState.setSubnetAvailableIpAddressCounts(new HashMap<String, Integer>() {

            {
                put(SUBNET_1, 10);
            }
        });
        expectedEmrVpcPricingState.setSpotPricesPerAvailabilityZone(new HashMap<String, Map<String, BigDecimal>>() {

            {
                put(AVAILABILITY_ZONE_1, new HashMap<>());
            }
        });
        expectedEmrVpcPricingState.setOnDemandPricesPerAvailabilityZone(new HashMap<String, Map<String, BigDecimal>>() {

            {
                put(AVAILABILITY_ZONE_1, new HashMap<String, BigDecimal>() {

                    {
                        put(INSTANCE_TYPE_4, ON_DEMAND);
                    }
                });
            }
        });
        assertEquals(String.format("There were no subnets which satisfied your best price search criteria. If you explicitly opted to use spot EC2 instances, please confirm " + "that your instance types support spot pricing. Otherwise, try setting the max price or the on-demand threshold to a higher value.%n%s", emrVpcPricingStateFormatter.format(expectedEmrVpcPricingState)), e.getMessage());
    }
}
Also used : InstanceDefinition(org.finra.herd.model.api.xml.InstanceDefinition) MasterInstanceDefinition(org.finra.herd.model.api.xml.MasterInstanceDefinition) EmrVpcPricingState(org.finra.herd.model.dto.EmrVpcPricingState) HashMap(java.util.HashMap) ObjectNotFoundException(org.finra.herd.model.ObjectNotFoundException) MasterInstanceDefinition(org.finra.herd.model.api.xml.MasterInstanceDefinition) BigDecimal(java.math.BigDecimal) Test(org.junit.Test) AbstractDaoTest(org.finra.herd.dao.AbstractDaoTest)

Example 12 with InstanceDefinition

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

the class EmrPricingHelperTest method testBestPriceSubnetError.

/**
 * Tests case where the subnet retrieval throws an unexpected amazon error.
 */
@Test
public void testBestPriceSubnetError() throws Exception {
    String subnetId = "throw.SomeError";
    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 AmazonServiceException, but no exception was thrown");
    } catch (Exception e) {
        assertEquals("thrown exception", AmazonServiceException.class, e.getClass());
    }
}
Also used : InstanceDefinition(org.finra.herd.model.api.xml.InstanceDefinition) MasterInstanceDefinition(org.finra.herd.model.api.xml.MasterInstanceDefinition) AmazonServiceException(com.amazonaws.AmazonServiceException) 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 13 with InstanceDefinition

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

the class EmrHelperTest method testIsInstanceDefinitionsEmpty.

@Test
public void testIsInstanceDefinitionsEmpty() {
    assertTrue(emrHelper.isInstanceDefinitionsEmpty(null));
    assertTrue(emrHelper.isInstanceDefinitionsEmpty(new InstanceDefinitions(null, null, null)));
    assertFalse(emrHelper.isInstanceDefinitionsEmpty(new InstanceDefinitions(new MasterInstanceDefinition(), null, null)));
    assertFalse(emrHelper.isInstanceDefinitionsEmpty(new InstanceDefinitions(null, new InstanceDefinition(), null)));
    assertFalse(emrHelper.isInstanceDefinitionsEmpty(new InstanceDefinitions(null, null, new InstanceDefinition())));
}
Also used : MasterInstanceDefinition(org.finra.herd.model.api.xml.MasterInstanceDefinition) InstanceDefinition(org.finra.herd.model.api.xml.InstanceDefinition) MasterInstanceDefinition(org.finra.herd.model.api.xml.MasterInstanceDefinition) InstanceDefinitions(org.finra.herd.model.api.xml.InstanceDefinitions) Test(org.junit.Test) AbstractDaoTest(org.finra.herd.dao.AbstractDaoTest)

Example 14 with InstanceDefinition

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

the class EmrDaoTest method createEmrClusterAssertInstallOozieDisabled.

@Test
public void createEmrClusterAssertInstallOozieDisabled() throws Exception {
    /*
         * Use only minimum required options
         */
    String clusterName = "clusterName";
    EmrClusterDefinition emrClusterDefinition = new EmrClusterDefinition();
    InstanceDefinitions instanceDefinitions = new InstanceDefinitions();
    instanceDefinitions.setMasterInstances(new MasterInstanceDefinition(10, "masterInstanceType", NO_EMR_CLUSTER_DEFINITION_EBS_CONFIGURATION, NO_INSTANCE_SPOT_PRICE, NO_INSTANCE_MAX_SEARCH_PRICE, NO_INSTANCE_ON_DEMAND_THRESHOLD));
    instanceDefinitions.setCoreInstances(new InstanceDefinition(20, "coreInstanceType", NO_EMR_CLUSTER_DEFINITION_EBS_CONFIGURATION, NO_INSTANCE_SPOT_PRICE, NO_INSTANCE_MAX_SEARCH_PRICE, NO_INSTANCE_ON_DEMAND_THRESHOLD));
    emrClusterDefinition.setInstanceDefinitions(instanceDefinitions);
    emrClusterDefinition.setNodeTags(Arrays.asList(new NodeTag("tagName", "tagValue")));
    emrClusterDefinition.setInstallOozie(false);
    String clusterId = "clusterId";
    when(mockEmrOperations.runEmrJobFlow(any(), any())).then(new Answer<String>() {

        @Override
        public String answer(InvocationOnMock invocation) throws Throwable {
            RunJobFlowRequest runJobFlowRequest = invocation.getArgument(1);
            // The oozie step should be skipped.
            assertEquals(0, runJobFlowRequest.getSteps().size());
            return clusterId;
        }
    });
    assertEquals(clusterId, emrDao.createEmrCluster(clusterName, emrClusterDefinition, new AwsParamsDto()));
}
Also used : MasterInstanceDefinition(org.finra.herd.model.api.xml.MasterInstanceDefinition) InstanceDefinition(org.finra.herd.model.api.xml.InstanceDefinition) AwsParamsDto(org.finra.herd.model.dto.AwsParamsDto) EmrClusterDefinition(org.finra.herd.model.api.xml.EmrClusterDefinition) RunJobFlowRequest(com.amazonaws.services.elasticmapreduce.model.RunJobFlowRequest) InvocationOnMock(org.mockito.invocation.InvocationOnMock) NodeTag(org.finra.herd.model.api.xml.NodeTag) MasterInstanceDefinition(org.finra.herd.model.api.xml.MasterInstanceDefinition) InstanceDefinitions(org.finra.herd.model.api.xml.InstanceDefinitions) Test(org.junit.Test)

Example 15 with InstanceDefinition

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

the class EmrPricingHelper method getTotalInstanceCount.

/**
 * Returns the total number of requested instances. Returns the sum of master, core, and task instance counts. Task instance is optional.
 *
 * @param emrClusterDefinition the EMR cluster definition containing the instance definitions
 *
 * @return the total instance count
 */
private int getTotalInstanceCount(EmrClusterDefinition emrClusterDefinition) {
    InstanceDefinition masterInstanceDefinition = getMasterInstanceDefinition(emrClusterDefinition);
    InstanceDefinition coreInstanceDefinition = getCoreInstanceDefinition(emrClusterDefinition);
    InstanceDefinition taskInstanceDefinition = getTaskInstanceDefinition(emrClusterDefinition);
    // Get total count of instances this definition will attempt to create
    int totalInstanceCount = masterInstanceDefinition.getInstanceCount();
    if (coreInstanceDefinition != null) {
        totalInstanceCount += coreInstanceDefinition.getInstanceCount();
    }
    if (taskInstanceDefinition != null) {
        totalInstanceCount += taskInstanceDefinition.getInstanceCount();
    }
    return totalInstanceCount;
}
Also used : InstanceDefinition(org.finra.herd.model.api.xml.InstanceDefinition) MasterInstanceDefinition(org.finra.herd.model.api.xml.MasterInstanceDefinition)

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