Search in sources :

Example 71 with EmrClusterDefinition

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

the class EmrClusterDefinitionServiceTest method testUpdateEmrClusterDefinitionMissingMandatoryNodeTags.

@Test
public void testUpdateEmrClusterDefinitionMissingMandatoryNodeTags() throws Exception {
    // Set a list of test mandatory AWS tags that are present in EMR_CLUSTER_DEFINITION_XML_FILE_WITH_CLASSPATH XML file.
    List<String> testMandatoryAwsTagNames = Arrays.asList(ATTRIBUTE_NAME_1_MIXED_CASE, ATTRIBUTE_NAME_2_MIXED_CASE, ATTRIBUTE_NAME_3_MIXED_CASE);
    // Override configuration to add max partition values.
    Map<String, Object> overrideMap = new HashMap<>();
    overrideMap.put(ConfigurationValue.MANDATORY_AWS_TAGS.getKey(), StringUtils.join(testMandatoryAwsTagNames, "|"));
    modifyPropertySourceInEnvironment(overrideMap);
    try {
        // Test each of the AWS mandatory node tags.
        for (String mandatoryAwsTagName : testMandatoryAwsTagNames) {
            EmrClusterDefinition emrClusterDefinitionConfiguration = getTestEmrClusterDefinitionConfiguration(EMR_CLUSTER_DEFINITION_XML_FILE_WITH_CLASSPATH);
            // Change EMR cluster definition configuration to have a new list of the test node tags that does not have the relative AWS mandatory node tag.
            emrClusterDefinitionConfiguration.setNodeTags(getTestNodeTags(testMandatoryAwsTagNames, mandatoryAwsTagName));
            try {
                emrClusterDefinitionService.updateEmrClusterDefinition(new EmrClusterDefinitionKey(NAMESPACE, EMR_CLUSTER_DEFINITION_NAME), createEmrClusterDefinitionUpdateRequest(emrClusterDefinitionConfiguration));
                fail(String.format("Should throw an IllegalArgumentException when \"%s\" required AWS node tag is not specified.", mandatoryAwsTagName));
            } catch (IllegalArgumentException e) {
                assertEquals(String.format("Mandatory AWS tag not specified: \"%s\"", mandatoryAwsTagName), e.getMessage());
            }
        }
    } finally {
        // Restore the property sources so we don't affect other tests.
        restorePropertySourceInEnvironment();
    }
}
Also used : EmrClusterDefinition(org.finra.herd.model.api.xml.EmrClusterDefinition) HashMap(java.util.HashMap) EmrClusterDefinitionKey(org.finra.herd.model.api.xml.EmrClusterDefinitionKey) Test(org.junit.Test)

Example 72 with EmrClusterDefinition

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

the class EmrClusterDefinitionServiceTest method testUpdateEmrClusterDefinitionMaxInstancesExceeded.

@Test
public void testUpdateEmrClusterDefinitionMaxInstancesExceeded() throws Exception {
    final Integer TEST_MAX_EMR_INSTANCES_COUNT = 10;
    // Override configuration.
    Map<String, Object> overrideMap = new HashMap<>();
    overrideMap.put(ConfigurationValue.MAX_EMR_INSTANCES_COUNT.getKey(), TEST_MAX_EMR_INSTANCES_COUNT.toString());
    modifyPropertySourceInEnvironment(overrideMap);
    // Try to perform an update by specifying too many instances (TEST_MAX_EMR_INSTANCES_COUNT + 1).
    EmrClusterDefinition emrClusterDefinitionConfiguration = getTestEmrClusterDefinitionConfiguration(EMR_CLUSTER_DEFINITION_XML_FILE_WITH_CLASSPATH);
    emrClusterDefinitionConfiguration.getInstanceDefinitions().getMasterInstances().setInstanceCount(TEST_MAX_EMR_INSTANCES_COUNT);
    emrClusterDefinitionConfiguration.getInstanceDefinitions().getCoreInstances().setInstanceCount(1);
    try {
        emrClusterDefinitionService.updateEmrClusterDefinition(new EmrClusterDefinitionKey(NAMESPACE, EMR_CLUSTER_DEFINITION_NAME), createEmrClusterDefinitionUpdateRequest(emrClusterDefinitionConfiguration));
        fail("Should throw an IllegalArgumentException when total number of instances exceeds maximum allowed.");
    } catch (IllegalArgumentException e) {
        assertEquals(String.format("Total number of instances requested can not exceed : %d", TEST_MAX_EMR_INSTANCES_COUNT), e.getMessage());
    } finally {
        // Restore the property sources so we don't affect other tests.
        restorePropertySourceInEnvironment();
    }
}
Also used : EmrClusterDefinition(org.finra.herd.model.api.xml.EmrClusterDefinition) HashMap(java.util.HashMap) EmrClusterDefinitionKey(org.finra.herd.model.api.xml.EmrClusterDefinitionKey) Test(org.junit.Test)

Example 73 with EmrClusterDefinition

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

the class EmrClusterDefinitionServiceTest method testCreateEmrClusterDefinitionMissingMandatoryNodeTags.

@Test
public void testCreateEmrClusterDefinitionMissingMandatoryNodeTags() throws Exception {
    // Set a list of test mandatory AWS tags that are present in EMR_CLUSTER_DEFINITION_XML_FILE_WITH_CLASSPATH XML file.
    List<String> testMandatoryAwsTagNames = Arrays.asList(ATTRIBUTE_NAME_1_MIXED_CASE, ATTRIBUTE_NAME_2_MIXED_CASE, ATTRIBUTE_NAME_3_MIXED_CASE);
    // Override configuration to add max partition values.
    Map<String, Object> overrideMap = new HashMap<>();
    overrideMap.put(ConfigurationValue.MANDATORY_AWS_TAGS.getKey(), StringUtils.join(testMandatoryAwsTagNames, "|"));
    modifyPropertySourceInEnvironment(overrideMap);
    try {
        // Test each of the AWS mandatory node tags.
        for (String mandatoryAwsTagName : testMandatoryAwsTagNames) {
            EmrClusterDefinition emrClusterDefinitionConfiguration = getTestEmrClusterDefinitionConfiguration(EMR_CLUSTER_DEFINITION_XML_FILE_WITH_CLASSPATH);
            // Change EMR cluster definition configuration to have a new list of the test node tags that does not have the relative AWS mandatory node tag.
            emrClusterDefinitionConfiguration.setNodeTags(getTestNodeTags(testMandatoryAwsTagNames, mandatoryAwsTagName));
            try {
                emrClusterDefinitionService.createEmrClusterDefinition(createEmrClusterDefinitionCreateRequest(NAMESPACE, EMR_CLUSTER_DEFINITION_NAME, emrClusterDefinitionConfiguration));
                fail(String.format("Should throw an IllegalArgumentException when \"%s\" required AWS node tag is not specified.", mandatoryAwsTagName));
            } catch (IllegalArgumentException e) {
                assertEquals(String.format("Mandatory AWS tag not specified: \"%s\"", mandatoryAwsTagName), e.getMessage());
            }
        }
    } finally {
        // Restore the property sources so we don't affect other tests.
        restorePropertySourceInEnvironment();
    }
}
Also used : EmrClusterDefinition(org.finra.herd.model.api.xml.EmrClusterDefinition) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 74 with EmrClusterDefinition

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

the class EmrServiceTest method testGetEmrClusterById.

/**
 * This method tests the happy path scenario by providing all the parameters
 */
@Test
public void testGetEmrClusterById() throws Exception {
    // Create the namespace entity.
    NamespaceEntity namespaceEntity = namespaceDaoTestHelper.createNamespaceEntity(NAMESPACE);
    String configXml = IOUtils.toString(resourceLoader.getResource(EMR_CLUSTER_DEFINITION_XML_FILE_MINIMAL_CLASSPATH).getInputStream());
    EmrClusterDefinition emrClusterDefinition = xmlHelper.unmarshallXmlToObject(EmrClusterDefinition.class, configXml);
    emrClusterDefinition.setAmiVersion(MockAwsOperationsHelper.AMAZON_CLUSTER_STATUS_WAITING);
    configXml = xmlHelper.objectToXml(emrClusterDefinition);
    emrClusterDefinitionDaoTestHelper.createEmrClusterDefinitionEntity(namespaceEntity, EMR_CLUSTER_DEFINITION_NAME, configXml);
    // Create a new EMR cluster create request
    EmrClusterCreateRequest request = getNewEmrClusterCreateRequest();
    EmrCluster emrCluster = emrService.createCluster(request);
    EmrClusterAlternateKeyDto emrClusterAlternateKeyDto = EmrClusterAlternateKeyDto.builder().withNamespace(NAMESPACE).withEmrClusterDefinitionName(EMR_CLUSTER_DEFINITION_NAME).withEmrClusterName(request.getEmrClusterName()).build();
    EmrCluster emrClusterGet = emrService.getCluster(emrClusterAlternateKeyDto, emrCluster.getId(), null, true, null, false);
    // Validate the returned object against the input.
    assertNotNull(emrCluster);
    assertNotNull(emrClusterGet);
    assertTrue(emrCluster.getId().equals(emrClusterGet.getId()));
    assertTrue(emrCluster.getNamespace().equals(emrClusterGet.getNamespace()));
    assertTrue(emrCluster.getEmrClusterDefinitionName().equals(emrClusterGet.getEmrClusterDefinitionName()));
    assertTrue(emrCluster.getEmrClusterName().equals(emrClusterGet.getEmrClusterName()));
    // Terminate the cluster and validate.
    emrService.terminateCluster(emrClusterAlternateKeyDto, true, null, null);
    emrClusterGet = emrService.getCluster(emrClusterAlternateKeyDto, emrCluster.getId(), null, true, null, false);
    // Validate the returned object against the input.
    assertNotNull(emrCluster);
    assertNotNull(emrClusterGet);
    assertTrue(emrCluster.getId().equals(emrClusterGet.getId()));
    assertTrue(emrCluster.getNamespace().equals(emrClusterGet.getNamespace()));
    assertTrue(emrCluster.getEmrClusterDefinitionName().equals(emrClusterGet.getEmrClusterDefinitionName()));
    assertTrue(emrCluster.getEmrClusterName().equals(emrClusterGet.getEmrClusterName()));
}
Also used : NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) EmrClusterDefinition(org.finra.herd.model.api.xml.EmrClusterDefinition) EmrClusterCreateRequest(org.finra.herd.model.api.xml.EmrClusterCreateRequest) EmrCluster(org.finra.herd.model.api.xml.EmrCluster) EmrClusterAlternateKeyDto(org.finra.herd.model.dto.EmrClusterAlternateKeyDto) Test(org.junit.Test)

Example 75 with EmrClusterDefinition

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

the class EmrServiceTest method testCreateEmrClusterMultipleBootstrap.

/**
 * This method tests the multiple bootstrap scripts.
 */
@Test
public void testCreateEmrClusterMultipleBootstrap() throws Exception {
    // Create the namespace entity.
    NamespaceEntity namespaceEntity = namespaceDaoTestHelper.createNamespaceEntity(NAMESPACE);
    String configXml = IOUtils.toString(resourceLoader.getResource(EMR_CLUSTER_DEFINITION_XML_FILE_WITH_CLASSPATH).getInputStream());
    EmrClusterDefinition emrClusterDefinition = xmlHelper.unmarshallXmlToObject(EmrClusterDefinition.class, configXml);
    ScriptDefinition allScript = emrClusterDefinition.getCustomBootstrapActionAll().get(0);
    ScriptDefinition secondAllScript = new ScriptDefinition();
    secondAllScript.setScriptName(allScript.getScriptName() + "_second");
    secondAllScript.setScriptLocation(allScript.getScriptLocation());
    secondAllScript.setScriptArguments(allScript.getScriptArguments());
    emrClusterDefinition.getCustomBootstrapActionAll().add(secondAllScript);
    ScriptDefinition masterScript = emrClusterDefinition.getCustomBootstrapActionMaster().get(0);
    ScriptDefinition secondMasterScript = new ScriptDefinition();
    secondMasterScript.setScriptName(masterScript.getScriptName() + "_second");
    secondMasterScript.setScriptLocation(masterScript.getScriptLocation());
    secondMasterScript.setScriptArguments(masterScript.getScriptArguments());
    emrClusterDefinition.getCustomBootstrapActionMaster().add(secondMasterScript);
    emrClusterDefinitionDaoTestHelper.createEmrClusterDefinitionEntity(namespaceEntity, EMR_CLUSTER_DEFINITION_NAME, xmlHelper.objectToXml(emrClusterDefinition));
    // Create a new EMR cluster create request
    EmrClusterCreateRequest request = getNewEmrClusterCreateRequest();
    EmrCluster emrCluster = emrService.createCluster(request);
    // Validate the returned object against the input.
    assertNotNull(emrCluster);
    assertTrue(emrCluster.getNamespace().equals(request.getNamespace()));
    assertTrue(emrCluster.getEmrClusterDefinitionName().equals(request.getEmrClusterDefinitionName()));
    assertTrue(emrCluster.getEmrClusterName().equals(request.getEmrClusterName()));
}
Also used : NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) EmrClusterDefinition(org.finra.herd.model.api.xml.EmrClusterDefinition) ScriptDefinition(org.finra.herd.model.api.xml.ScriptDefinition) EmrClusterCreateRequest(org.finra.herd.model.api.xml.EmrClusterCreateRequest) EmrCluster(org.finra.herd.model.api.xml.EmrCluster) Test(org.junit.Test)

Aggregations

EmrClusterDefinition (org.finra.herd.model.api.xml.EmrClusterDefinition)101 Test (org.junit.Test)94 NamespaceEntity (org.finra.herd.model.jpa.NamespaceEntity)40 EmrClusterCreateRequest (org.finra.herd.model.api.xml.EmrClusterCreateRequest)39 EmrCluster (org.finra.herd.model.api.xml.EmrCluster)25 InstanceDefinition (org.finra.herd.model.api.xml.InstanceDefinition)24 MasterInstanceDefinition (org.finra.herd.model.api.xml.MasterInstanceDefinition)23 AbstractServiceTest (org.finra.herd.service.AbstractServiceTest)20 AbstractDaoTest (org.finra.herd.dao.AbstractDaoTest)18 NodeTag (org.finra.herd.model.api.xml.NodeTag)12 EmrClusterDefinitionKey (org.finra.herd.model.api.xml.EmrClusterDefinitionKey)9 InstanceDefinitions (org.finra.herd.model.api.xml.InstanceDefinitions)8 AwsParamsDto (org.finra.herd.model.dto.AwsParamsDto)7 ArrayList (java.util.ArrayList)6 RunJobFlowRequest (com.amazonaws.services.elasticmapreduce.model.RunJobFlowRequest)5 HashMap (java.util.HashMap)5 EmrClusterDefinitionInformation (org.finra.herd.model.api.xml.EmrClusterDefinitionInformation)5 EmrClusterAlternateKeyDto (org.finra.herd.model.dto.EmrClusterAlternateKeyDto)5 InvocationOnMock (org.mockito.invocation.InvocationOnMock)5 EmrClusterDefinitionInstanceFleet (org.finra.herd.model.api.xml.EmrClusterDefinitionInstanceFleet)4