Search in sources :

Example 26 with EmrClusterDefinitionKey

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

the class EmrClusterDefinitionServiceTest method createEmrClusterDefinitionCreateRequest.

/**
 * Creates a new EMR cluster definition create request.
 *
 * @param namespace the namespace
 * @param emrClusterDefinitionName the EMR cluster definition name
 * @param emrClusterDefinitionConfiguration the EMR cluster definition configuration
 *
 * @return the newly created EMR cluster definition create request
 */
private EmrClusterDefinitionCreateRequest createEmrClusterDefinitionCreateRequest(String namespace, String emrClusterDefinitionName, EmrClusterDefinition emrClusterDefinitionConfiguration) {
    // Create a new ENR cluster definition create request.
    EmrClusterDefinitionCreateRequest request = new EmrClusterDefinitionCreateRequest();
    // Fill in the parameters.
    request.setEmrClusterDefinitionKey(new EmrClusterDefinitionKey(namespace, emrClusterDefinitionName));
    request.setEmrClusterDefinition(emrClusterDefinitionConfiguration);
    return request;
}
Also used : EmrClusterDefinitionKey(org.finra.herd.model.api.xml.EmrClusterDefinitionKey) EmrClusterDefinitionCreateRequest(org.finra.herd.model.api.xml.EmrClusterDefinitionCreateRequest)

Example 27 with EmrClusterDefinitionKey

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

the class EmrClusterDefinitionServiceTest method testGetEmrClusterDefinitionTrimParameters.

@Test
public void testGetEmrClusterDefinitionTrimParameters() throws Exception {
    // Create and persist the namespace entity.
    NamespaceEntity namespaceEntity = namespaceDaoTestHelper.createNamespaceEntity(NAMESPACE);
    // Create and persist the EMR cluster definition entity.
    EmrClusterDefinitionEntity emrClusterDefinitionEntity = emrClusterDefinitionDaoTestHelper.createEmrClusterDefinitionEntity(namespaceEntity, EMR_CLUSTER_DEFINITION_NAME, getTestEmrClusterDefinitionConfigurationXml(EMR_CLUSTER_DEFINITION_XML_FILE_WITH_CLASSPATH));
    // Get an EMR cluster definition by passing namespace and EMR cluster definition name with leading and trailing whitespace characters.
    EmrClusterDefinitionInformation resultEmrClusterDefinition = emrClusterDefinitionService.getEmrClusterDefinition(new EmrClusterDefinitionKey(addWhitespace(NAMESPACE), addWhitespace(EMR_CLUSTER_DEFINITION_NAME)));
    // Validate the returned object.
    validateEmrClusterDefinition(emrClusterDefinitionEntity.getId(), NAMESPACE, EMR_CLUSTER_DEFINITION_NAME, getTestEmrClusterDefinitionConfiguration(EMR_CLUSTER_DEFINITION_XML_FILE_WITH_CLASSPATH), resultEmrClusterDefinition);
}
Also used : NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) EmrClusterDefinitionKey(org.finra.herd.model.api.xml.EmrClusterDefinitionKey) EmrClusterDefinitionInformation(org.finra.herd.model.api.xml.EmrClusterDefinitionInformation) EmrClusterDefinitionEntity(org.finra.herd.model.jpa.EmrClusterDefinitionEntity) Test(org.junit.Test)

Example 28 with EmrClusterDefinitionKey

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

the class EmrClusterDefinitionServiceTest method testUpdateEmrClusterDefinitionLowerCaseParameters.

@Test
public void testUpdateEmrClusterDefinitionLowerCaseParameters() throws Exception {
    // Create and persist the namespace entity with an uppercase name.
    NamespaceEntity namespaceEntity = namespaceDaoTestHelper.createNamespaceEntity(NAMESPACE.toUpperCase());
    // Create and persist the EMR cluster definition entity with an uppercase name using minimal test XML configuration.
    EmrClusterDefinitionEntity emrClusterDefinitionEntity = emrClusterDefinitionDaoTestHelper.createEmrClusterDefinitionEntity(namespaceEntity, EMR_CLUSTER_DEFINITION_NAME.toUpperCase(), getTestEmrClusterDefinitionConfigurationXml(EMR_CLUSTER_DEFINITION_XML_FILE_MINIMAL_CLASSPATH));
    executeWithoutLogging(EmrClusterDefinitionServiceImpl.class, () -> {
        // Update an EMR cluster definition with the normal test XML configuration by passing the EMR cluster definition name key parameters in lower case.
        EmrClusterDefinitionInformation updatedEmrClusterDefinition = emrClusterDefinitionService.updateEmrClusterDefinition(new EmrClusterDefinitionKey(NAMESPACE.toLowerCase(), EMR_CLUSTER_DEFINITION_NAME.toLowerCase()), createEmrClusterDefinitionUpdateRequest(getTestEmrClusterDefinitionConfiguration(EMR_CLUSTER_DEFINITION_XML_FILE_WITH_CLASSPATH)));
        // Validate the returned object.
        validateEmrClusterDefinition(emrClusterDefinitionEntity.getId(), NAMESPACE.toUpperCase(), EMR_CLUSTER_DEFINITION_NAME.toUpperCase(), getTestEmrClusterDefinitionConfiguration(EMR_CLUSTER_DEFINITION_XML_FILE_WITH_CLASSPATH), updatedEmrClusterDefinition);
    });
}
Also used : NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) EmrClusterDefinitionKey(org.finra.herd.model.api.xml.EmrClusterDefinitionKey) EmrClusterDefinitionInformation(org.finra.herd.model.api.xml.EmrClusterDefinitionInformation) EmrClusterDefinitionEntity(org.finra.herd.model.jpa.EmrClusterDefinitionEntity) Test(org.junit.Test)

Example 29 with EmrClusterDefinitionKey

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

the class EmrClusterDefinitionServiceTest method testDeleteEmrClusterDefinitionMissingRequiredParameters.

@Test
public void testDeleteEmrClusterDefinitionMissingRequiredParameters() throws Exception {
    // Try to perform a delete without specifying a namespace.
    try {
        emrClusterDefinitionService.deleteEmrClusterDefinition(new EmrClusterDefinitionKey(BLANK_TEXT, EMR_CLUSTER_DEFINITION_NAME));
        fail("Should throw an IllegalArgumentException when namespace is not specified.");
    } catch (IllegalArgumentException e) {
        assertEquals("A namespace must be specified.", e.getMessage());
    }
    // Try to perform a delete without specifying an EMR cluster definition name.
    try {
        emrClusterDefinitionService.deleteEmrClusterDefinition(new EmrClusterDefinitionKey(NAMESPACE, BLANK_TEXT));
        fail("Should throw an IllegalArgumentException when EMR cluster definition name is not specified.");
    } catch (IllegalArgumentException e) {
        assertEquals("An EMR cluster definition name must be specified.", e.getMessage());
    }
}
Also used : EmrClusterDefinitionKey(org.finra.herd.model.api.xml.EmrClusterDefinitionKey) Test(org.junit.Test)

Example 30 with EmrClusterDefinitionKey

use of org.finra.herd.model.api.xml.EmrClusterDefinitionKey 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)

Aggregations

EmrClusterDefinitionKey (org.finra.herd.model.api.xml.EmrClusterDefinitionKey)35 Test (org.junit.Test)32 EmrClusterDefinitionInformation (org.finra.herd.model.api.xml.EmrClusterDefinitionInformation)17 EmrClusterDefinitionEntity (org.finra.herd.model.jpa.EmrClusterDefinitionEntity)14 NamespaceEntity (org.finra.herd.model.jpa.NamespaceEntity)13 EmrClusterDefinition (org.finra.herd.model.api.xml.EmrClusterDefinition)9 EmrClusterDefinitionKeys (org.finra.herd.model.api.xml.EmrClusterDefinitionKeys)5 ObjectNotFoundException (org.finra.herd.model.ObjectNotFoundException)3 HashMap (java.util.HashMap)2 EmrClusterDefinitionCreateRequest (org.finra.herd.model.api.xml.EmrClusterDefinitionCreateRequest)2 EmrClusterDefinitionUpdateRequest (org.finra.herd.model.api.xml.EmrClusterDefinitionUpdateRequest)2 NodeTag (org.finra.herd.model.api.xml.NodeTag)2 ArrayList (java.util.ArrayList)1 Tuple (javax.persistence.Tuple)1 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)1 Predicate (javax.persistence.criteria.Predicate)1