Search in sources :

Example 21 with EmrClusterDefinitionEntity

use of org.finra.herd.model.jpa.EmrClusterDefinitionEntity 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 22 with EmrClusterDefinitionEntity

use of org.finra.herd.model.jpa.EmrClusterDefinitionEntity in project herd by FINRAOS.

the class EmrClusterDefinitionServiceTest method testDeleteEmrClusterDefinitionTrimParameters.

@Test
public void testDeleteEmrClusterDefinitionTrimParameters() 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));
    // Validate that this EMR cluster definition exists.
    assertNotNull(emrClusterDefinitionDao.getEmrClusterDefinitionByAltKey(NAMESPACE, EMR_CLUSTER_DEFINITION_NAME));
    executeWithoutLogging(EmrClusterDefinitionServiceImpl.class, () -> {
        // Delete this EMR cluster definition by passing namespace and EMR cluster definition name with leading and trailing whitespace characters.
        EmrClusterDefinitionInformation deletedEmrClusterDefinition = emrClusterDefinitionService.deleteEmrClusterDefinition(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), deletedEmrClusterDefinition);
        // Ensure that this EMR cluster definition is no longer there.
        assertNull(emrClusterDefinitionDao.getEmrClusterDefinitionByAltKey(NAMESPACE, EMR_CLUSTER_DEFINITION_NAME));
    });
}
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 23 with EmrClusterDefinitionEntity

use of org.finra.herd.model.jpa.EmrClusterDefinitionEntity in project herd by FINRAOS.

the class EmrClusterDefinitionServiceTest method testDeleteEmrClusterDefinitionUpperCaseParameters.

@Test
public void testDeleteEmrClusterDefinitionUpperCaseParameters() throws Exception {
    // Create and persist the namespace entity with a lowercase name.
    NamespaceEntity namespaceEntity = namespaceDaoTestHelper.createNamespaceEntity(NAMESPACE.toLowerCase());
    // Create and persist the EMR cluster definition entity with a lowercase name.
    EmrClusterDefinitionEntity emrClusterDefinitionEntity = emrClusterDefinitionDaoTestHelper.createEmrClusterDefinitionEntity(namespaceEntity, EMR_CLUSTER_DEFINITION_NAME.toLowerCase(), getTestEmrClusterDefinitionConfigurationXml(EMR_CLUSTER_DEFINITION_XML_FILE_WITH_CLASSPATH));
    // Validate that this EMR cluster definition exists.
    assertNotNull(emrClusterDefinitionDao.getEmrClusterDefinitionByAltKey(NAMESPACE.toLowerCase(), EMR_CLUSTER_DEFINITION_NAME.toLowerCase()));
    executeWithoutLogging(EmrClusterDefinitionServiceImpl.class, () -> {
        // Delete this EMR cluster definition by passing the EMR cluster definition name key parameters in upper case.
        EmrClusterDefinitionInformation deletedEmrClusterDefinition = emrClusterDefinitionService.deleteEmrClusterDefinition(new EmrClusterDefinitionKey(NAMESPACE.toUpperCase(), EMR_CLUSTER_DEFINITION_NAME.toUpperCase()));
        // Validate the returned object.
        validateEmrClusterDefinition(emrClusterDefinitionEntity.getId(), NAMESPACE.toLowerCase(), EMR_CLUSTER_DEFINITION_NAME.toLowerCase(), getTestEmrClusterDefinitionConfiguration(EMR_CLUSTER_DEFINITION_XML_FILE_WITH_CLASSPATH), deletedEmrClusterDefinition);
        // Ensure that this EMR cluster definition is no longer there.
        assertNull(emrClusterDefinitionDao.getEmrClusterDefinitionByAltKey(NAMESPACE.toLowerCase(), EMR_CLUSTER_DEFINITION_NAME.toLowerCase()));
    });
}
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 24 with EmrClusterDefinitionEntity

use of org.finra.herd.model.jpa.EmrClusterDefinitionEntity in project herd by FINRAOS.

the class EmrServiceTest method testTerminateEmrClusterWithClusterId.

@Test
public void testTerminateEmrClusterWithClusterId() throws Exception {
    EmrService emrService = new EmrServiceImpl();
    AlternateKeyHelper mockAlternateKeyHelper = mock(AlternateKeyHelper.class);
    ReflectionTestUtils.setField(emrService, "alternateKeyHelper", mockAlternateKeyHelper);
    EmrHelper mockEmrHelper = mock(EmrHelper.class);
    ReflectionTestUtils.setField(emrService, "emrHelper", mockEmrHelper);
    EmrDao mockEmrDao = mock(EmrDao.class);
    ReflectionTestUtils.setField(emrService, "emrDao", mockEmrDao);
    NamespaceDaoHelper mockNamespaceDaoHelper = mock(NamespaceDaoHelper.class);
    ReflectionTestUtils.setField(emrService, "namespaceDaoHelper", mockNamespaceDaoHelper);
    EmrClusterDefinitionDaoHelper mockEmrClusterDefinitionDaoHelper = mock(EmrClusterDefinitionDaoHelper.class);
    ReflectionTestUtils.setField(emrService, "emrClusterDefinitionDaoHelper", mockEmrClusterDefinitionDaoHelper);
    String namespace = "namespace";
    String emrClusterDefinitionName = "emrClusterDefinitionName";
    String emrClusterName = "emrClusterName";
    boolean overrideTerminationProtection = false;
    String emrClusterId = "emrClusterId";
    EmrClusterAlternateKeyDto emrClusterAlternateKeyDto = new EmrClusterAlternateKeyDto();
    emrClusterAlternateKeyDto.setNamespace(namespace);
    emrClusterAlternateKeyDto.setEmrClusterDefinitionName(emrClusterDefinitionName);
    emrClusterAlternateKeyDto.setEmrClusterName(emrClusterName);
    AwsParamsDto awsParamsDto = new AwsParamsDto();
    when(mockEmrHelper.getAwsParamsDtoByAcccountId(any())).thenReturn(awsParamsDto);
    NamespaceEntity namespaceEntity = new NamespaceEntity();
    when(mockNamespaceDaoHelper.getNamespaceEntity(any())).thenReturn(namespaceEntity);
    EmrClusterDefinitionEntity emrClusterDefinitionEntity = new EmrClusterDefinitionEntity();
    when(mockEmrClusterDefinitionDaoHelper.getEmrClusterDefinitionEntity(any(), any())).thenReturn(emrClusterDefinitionEntity);
    String buildEmrClusterNameResult = "buildEmrClusterNameResult";
    when(mockEmrHelper.buildEmrClusterName(any(), any(), any())).thenReturn(buildEmrClusterNameResult);
    when(mockEmrHelper.getActiveEmrClusterId(any(), any(), any())).thenReturn(buildEmrClusterNameResult);
    when(mockEmrDao.getEmrClusterStatusById(any(), any())).thenReturn(buildEmrClusterNameResult);
    emrService.terminateCluster(emrClusterAlternateKeyDto, overrideTerminationProtection, emrClusterId, null);
    verify(mockAlternateKeyHelper).validateStringParameter("namespace", namespace);
    verify(mockAlternateKeyHelper).validateStringParameter("An", "EMR cluster definition name", emrClusterDefinitionName);
    verify(mockAlternateKeyHelper).validateStringParameter("An", "EMR cluster name", emrClusterName);
    verify(mockNamespaceDaoHelper).getNamespaceEntity(emrClusterAlternateKeyDto.getNamespace());
    verify(mockEmrClusterDefinitionDaoHelper).getEmrClusterDefinitionEntity(emrClusterAlternateKeyDto.getNamespace(), emrClusterAlternateKeyDto.getEmrClusterDefinitionName());
    verify(mockEmrHelper).buildEmrClusterName(namespaceEntity.getCode(), emrClusterDefinitionEntity.getName(), emrClusterAlternateKeyDto.getEmrClusterName());
    verify(mockEmrHelper).getActiveEmrClusterId(emrClusterId, buildEmrClusterNameResult, null);
    verify(mockEmrDao).terminateEmrCluster(buildEmrClusterNameResult, overrideTerminationProtection, awsParamsDto);
    verify(mockEmrDao).getEmrClusterStatusById(buildEmrClusterNameResult, awsParamsDto);
// verifyNoMoreInteractions(mockEmrHelper, mockNamespaceDaoHelper, mockEmrClusterDefinitionDaoHelper, mockEmrDao);
}
Also used : EmrClusterDefinitionDaoHelper(org.finra.herd.service.helper.EmrClusterDefinitionDaoHelper) AwsParamsDto(org.finra.herd.model.dto.AwsParamsDto) NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) EmrServiceImpl(org.finra.herd.service.impl.EmrServiceImpl) EmrHelper(org.finra.herd.dao.helper.EmrHelper) NamespaceDaoHelper(org.finra.herd.service.helper.NamespaceDaoHelper) EmrDao(org.finra.herd.dao.EmrDao) EmrClusterAlternateKeyDto(org.finra.herd.model.dto.EmrClusterAlternateKeyDto) EmrClusterDefinitionEntity(org.finra.herd.model.jpa.EmrClusterDefinitionEntity) AlternateKeyHelper(org.finra.herd.service.helper.AlternateKeyHelper) Test(org.junit.Test)

Example 25 with EmrClusterDefinitionEntity

use of org.finra.herd.model.jpa.EmrClusterDefinitionEntity in project herd by FINRAOS.

the class EmrClusterDefinitionServiceImpl method getEmrClusterDefinition.

@NamespacePermission(fields = "#emrClusterDefinitionKey?.namespace", permissions = NamespacePermissionEnum.READ)
@Override
public EmrClusterDefinitionInformation getEmrClusterDefinition(EmrClusterDefinitionKey emrClusterDefinitionKey) throws Exception {
    // Perform validate and trim of the EMR cluster definition key.
    emrClusterDefinitionHelper.validateEmrClusterDefinitionKey(emrClusterDefinitionKey);
    // Retrieve and ensure that a EMR cluster definition exists with the specified key.
    EmrClusterDefinitionEntity emrClusterDefinitionEntity = emrClusterDefinitionDaoHelper.getEmrClusterDefinitionEntity(emrClusterDefinitionKey);
    // Create and return the EMR cluster definition object from the persisted entity.
    return createEmrClusterDefinitionFromEntity(emrClusterDefinitionEntity);
}
Also used : EmrClusterDefinitionEntity(org.finra.herd.model.jpa.EmrClusterDefinitionEntity) NamespacePermission(org.finra.herd.model.annotation.NamespacePermission)

Aggregations

EmrClusterDefinitionEntity (org.finra.herd.model.jpa.EmrClusterDefinitionEntity)31 NamespaceEntity (org.finra.herd.model.jpa.NamespaceEntity)24 Test (org.junit.Test)16 EmrClusterDefinitionKey (org.finra.herd.model.api.xml.EmrClusterDefinitionKey)14 EmrClusterDefinitionInformation (org.finra.herd.model.api.xml.EmrClusterDefinitionInformation)12 AwsParamsDto (org.finra.herd.model.dto.AwsParamsDto)6 AmazonServiceException (com.amazonaws.AmazonServiceException)5 NamespacePermission (org.finra.herd.model.annotation.NamespacePermission)4 ClusterSummary (com.amazonaws.services.elasticmapreduce.model.ClusterSummary)2 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)2 Predicate (javax.persistence.criteria.Predicate)2 EmrClusterDefinition (org.finra.herd.model.api.xml.EmrClusterDefinition)2 Parameter (org.finra.herd.model.api.xml.Parameter)2 EmrClusterAlternateKeyDto (org.finra.herd.model.dto.EmrClusterAlternateKeyDto)2 Cluster (com.amazonaws.services.elasticmapreduce.model.Cluster)1 ListInstanceFleetsResult (com.amazonaws.services.elasticmapreduce.model.ListInstanceFleetsResult)1 Step (com.amazonaws.services.elasticmapreduce.model.Step)1 StepSummary (com.amazonaws.services.elasticmapreduce.model.StepSummary)1 ArrayList (java.util.ArrayList)1 Tuple (javax.persistence.Tuple)1