Search in sources :

Example 6 with InstanceDefinitions

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

the class EmrClusterDefinitionHelperTest method createValidEmrClusterDefinition.

/**
 * Creates a EMR cluster definition which does not cause validateEmrClusterDefinitionConfiguration() to throw an exception.
 * <p/>
 * - One subnet is specified - Master, core, and task instances are specified - Instance count, and instance type are specified for each instance
 * definition. - One node tag is specified
 *
 * @return A new instance of {@link EmrClusterDefinition}
 */
private EmrClusterDefinition createValidEmrClusterDefinition() {
    EmrClusterDefinition emrClusterDefinition = new EmrClusterDefinition();
    emrClusterDefinition.setSubnetId(MockEc2OperationsImpl.SUBNET_1);
    InstanceDefinitions instanceDefinitions = new InstanceDefinitions();
    MasterInstanceDefinition masterInstanceDefinition = new MasterInstanceDefinition();
    masterInstanceDefinition.setInstanceCount(1);
    masterInstanceDefinition.setInstanceType(MockEc2OperationsImpl.INSTANCE_TYPE_1);
    instanceDefinitions.setMasterInstances(masterInstanceDefinition);
    InstanceDefinition coreInstanceDefinition = new InstanceDefinition();
    coreInstanceDefinition.setInstanceCount(1);
    coreInstanceDefinition.setInstanceType(MockEc2OperationsImpl.INSTANCE_TYPE_1);
    instanceDefinitions.setCoreInstances(coreInstanceDefinition);
    InstanceDefinition taskInstanceDefinition = new InstanceDefinition();
    taskInstanceDefinition.setInstanceCount(1);
    taskInstanceDefinition.setInstanceType(MockEc2OperationsImpl.INSTANCE_TYPE_1);
    instanceDefinitions.setTaskInstances(taskInstanceDefinition);
    emrClusterDefinition.setInstanceDefinitions(instanceDefinitions);
    List<NodeTag> nodeTags = new ArrayList<>();
    {
        nodeTags.add(new NodeTag("test_nodeTagName", "test_nodeTagValue"));
    }
    emrClusterDefinition.setNodeTags(nodeTags);
    return emrClusterDefinition;
}
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) NodeTag(org.finra.herd.model.api.xml.NodeTag) ArrayList(java.util.ArrayList) MasterInstanceDefinition(org.finra.herd.model.api.xml.MasterInstanceDefinition) InstanceDefinitions(org.finra.herd.model.api.xml.InstanceDefinitions)

Example 7 with InstanceDefinitions

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

the class EmrDaoImplTest method testGetInstanceGroupConfigs.

@Test
public void testGetInstanceGroupConfigs() {
    // Create objects required for testing.
    final Integer instanceCount = 0;
    final InstanceDefinitions instanceDefinitions = new InstanceDefinitions(new MasterInstanceDefinition(), new InstanceDefinition(), new InstanceDefinition());
    // Mock the external calls.
    when(emrHelper.isInstanceDefinitionsEmpty(instanceDefinitions)).thenReturn(false);
    // Call the method under test.
    List<InstanceGroupConfig> result = emrDaoImpl.getInstanceGroupConfigs(instanceDefinitions);
    // Verify the external calls.
    verify(emrHelper).isInstanceDefinitionsEmpty(instanceDefinitions);
    verifyNoMoreInteractionsHelper();
    // Validate the results.
    assertEquals(3, CollectionUtils.size(result));
    assertTrue(result.contains(new InstanceGroupConfig(InstanceRoleType.MASTER, null, instanceCount)));
    assertTrue(result.contains(new InstanceGroupConfig(InstanceRoleType.CORE, null, instanceCount)));
    assertTrue(result.contains(new InstanceGroupConfig(InstanceRoleType.TASK, null, instanceCount)));
}
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) InstanceGroupConfig(com.amazonaws.services.elasticmapreduce.model.InstanceGroupConfig) Test(org.junit.Test) AbstractDaoTest(org.finra.herd.dao.AbstractDaoTest)

Example 8 with InstanceDefinitions

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

the class EmrPricingHelperTest method updateEmrClusterDefinitionWithBestPrice.

/**
 * Creates a new EMR cluster definition using the specified parameters, updates it with best price algorithm, and returns the definition.
 *
 * @param subnetId Subnet ID. Optional.
 * @param masterInstanceDefinition The master instance definition
 * @param coreInstanceDefinition The core instance definition
 * @param taskInstanceDefinition The task instance definition. Optional.
 *
 * @return Updated EMR cluster definition.
 */
private EmrClusterDefinition updateEmrClusterDefinitionWithBestPrice(String subnetId, MasterInstanceDefinition masterInstanceDefinition, InstanceDefinition coreInstanceDefinition, InstanceDefinition taskInstanceDefinition) {
    EmrClusterDefinition emrClusterDefinition = new EmrClusterDefinition();
    emrClusterDefinition.setSubnetId(subnetId);
    InstanceDefinitions instanceDefinitions = new InstanceDefinitions();
    instanceDefinitions.setMasterInstances(masterInstanceDefinition);
    instanceDefinitions.setCoreInstances(coreInstanceDefinition);
    instanceDefinitions.setTaskInstances(taskInstanceDefinition);
    emrClusterDefinition.setInstanceDefinitions(instanceDefinitions);
    emrPricingHelper.updateEmrClusterDefinitionWithBestPrice(new EmrClusterAlternateKeyDto(), emrClusterDefinition, new AwsParamsDto());
    return emrClusterDefinition;
}
Also used : AwsParamsDto(org.finra.herd.model.dto.AwsParamsDto) EmrClusterDefinition(org.finra.herd.model.api.xml.EmrClusterDefinition) EmrClusterAlternateKeyDto(org.finra.herd.model.dto.EmrClusterAlternateKeyDto) InstanceDefinitions(org.finra.herd.model.api.xml.InstanceDefinitions)

Example 9 with InstanceDefinitions

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

the class EmrDaoTest method createEmrClusterAssertEncryptionDisabled.

@Test
public void createEmrClusterAssertEncryptionDisabled() 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.setEncryptionEnabled(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);
            // No bootstrap action should be added
            assertEquals(0, runJobFlowRequest.getBootstrapActions().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 10 with InstanceDefinitions

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

the class EmrDaoTest method createEmrClusterAssertCallRunEmrJobFlowRequiredParamsOnly.

@Test
public void createEmrClusterAssertCallRunEmrJobFlowRequiredParamsOnly() throws Exception {
    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")));
    String clusterId = "clusterId";
    when(mockEmrOperations.runEmrJobFlow(any(), any())).then(new Answer<String>() {

        @Override
        public String answer(InvocationOnMock invocation) throws Throwable {
            /*
                 * Assert that the given EMR cluster definition produced the correct RunJobFlowRequest
                 */
            RunJobFlowRequest runJobFlowRequest = invocation.getArgument(1);
            JobFlowInstancesConfig jobFlowInstancesConfig = runJobFlowRequest.getInstances();
            List<InstanceGroupConfig> instanceGroupConfigs = jobFlowInstancesConfig.getInstanceGroups();
            assertEquals(2, instanceGroupConfigs.size());
            {
                InstanceGroupConfig instanceGroupConfig = instanceGroupConfigs.get(0);
                assertEquals(10, instanceGroupConfig.getInstanceCount().intValue());
                assertEquals("masterInstanceType", instanceGroupConfig.getInstanceType());
            }
            {
                InstanceGroupConfig instanceGroupConfig = instanceGroupConfigs.get(1);
                assertEquals(20, instanceGroupConfig.getInstanceCount().intValue());
                assertEquals("coreInstanceType", instanceGroupConfig.getInstanceType());
            }
            assertEquals(herdStringHelper.getRequiredConfigurationValue(ConfigurationValue.EMR_DEFAULT_EC2_NODE_IAM_PROFILE_NAME), runJobFlowRequest.getJobFlowRole());
            assertEquals(herdStringHelper.getRequiredConfigurationValue(ConfigurationValue.EMR_DEFAULT_SERVICE_IAM_ROLE_NAME), runJobFlowRequest.getServiceRole());
            List<StepConfig> stepConfigs = runJobFlowRequest.getSteps();
            assertEquals(0, stepConfigs.size());
            List<Tag> tags = runJobFlowRequest.getTags();
            assertEquals(1, tags.size());
            {
                Tag tag = tags.get(0);
                assertEquals("tagName", tag.getKey());
                assertEquals("tagValue", tag.getValue());
            }
            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) RunJobFlowRequest(com.amazonaws.services.elasticmapreduce.model.RunJobFlowRequest) JobFlowInstancesConfig(com.amazonaws.services.elasticmapreduce.model.JobFlowInstancesConfig) MasterInstanceDefinition(org.finra.herd.model.api.xml.MasterInstanceDefinition) InstanceDefinitions(org.finra.herd.model.api.xml.InstanceDefinitions) EmrClusterDefinition(org.finra.herd.model.api.xml.EmrClusterDefinition) InvocationOnMock(org.mockito.invocation.InvocationOnMock) NodeTag(org.finra.herd.model.api.xml.NodeTag) List(java.util.List) ArrayList(java.util.ArrayList) Tag(com.amazonaws.services.elasticmapreduce.model.Tag) NodeTag(org.finra.herd.model.api.xml.NodeTag) InstanceGroupConfig(com.amazonaws.services.elasticmapreduce.model.InstanceGroupConfig) Test(org.junit.Test)

Aggregations

InstanceDefinitions (org.finra.herd.model.api.xml.InstanceDefinitions)12 Test (org.junit.Test)10 EmrClusterDefinition (org.finra.herd.model.api.xml.EmrClusterDefinition)8 MasterInstanceDefinition (org.finra.herd.model.api.xml.MasterInstanceDefinition)8 InstanceDefinition (org.finra.herd.model.api.xml.InstanceDefinition)7 InstanceGroupConfig (com.amazonaws.services.elasticmapreduce.model.InstanceGroupConfig)5 NodeTag (org.finra.herd.model.api.xml.NodeTag)5 AwsParamsDto (org.finra.herd.model.dto.AwsParamsDto)5 RunJobFlowRequest (com.amazonaws.services.elasticmapreduce.model.RunJobFlowRequest)4 AbstractDaoTest (org.finra.herd.dao.AbstractDaoTest)4 InvocationOnMock (org.mockito.invocation.InvocationOnMock)4 ArrayList (java.util.ArrayList)2 EmrCluster (org.finra.herd.model.api.xml.EmrCluster)2 EmrClusterCreateRequest (org.finra.herd.model.api.xml.EmrClusterCreateRequest)2 EmrClusterDefinitionInstanceFleet (org.finra.herd.model.api.xml.EmrClusterDefinitionInstanceFleet)2 NamespaceEntity (org.finra.herd.model.jpa.NamespaceEntity)2 ClientConfiguration (com.amazonaws.ClientConfiguration)1 Application (com.amazonaws.services.elasticmapreduce.model.Application)1 BootstrapActionConfig (com.amazonaws.services.elasticmapreduce.model.BootstrapActionConfig)1 Configuration (com.amazonaws.services.elasticmapreduce.model.Configuration)1