Search in sources :

Example 11 with EmrClusterAlternateKeyDto

use of org.finra.herd.model.dto.EmrClusterAlternateKeyDto 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 12 with EmrClusterAlternateKeyDto

use of org.finra.herd.model.dto.EmrClusterAlternateKeyDto in project herd by FINRAOS.

the class EmrServiceTest method testGetEmrClusterByIdWithStepId.

/**
 * This method tests the scenario with providing step Id.
 */
@Test
public void testGetEmrClusterByIdWithStepId() throws Exception {
    // Create the namespace entity.
    NamespaceEntity namespaceEntity = namespaceDaoTestHelper.createNamespaceEntity(NAMESPACE);
    emrClusterDefinitionDaoTestHelper.createEmrClusterDefinitionEntity(namespaceEntity, EMR_CLUSTER_DEFINITION_NAME, IOUtils.toString(resourceLoader.getResource(EMR_CLUSTER_DEFINITION_XML_FILE_WITH_CLASSPATH).getInputStream()));
    // Create a new EMR cluster create request
    EmrClusterCreateRequest request = getNewEmrClusterCreateRequest();
    EmrCluster emrCluster = emrService.createCluster(request);
    // Add a running step
    // Create the Add step request.
    EmrShellStepAddRequest stepRequest = getNewEmrShellStepAddRequest(request.getEmrClusterName());
    stepRequest.setStepName(MockEmrOperationsImpl.MOCK_STEP_RUNNING_NAME);
    EmrShellStep emrShellStep = (EmrShellStep) emrService.addStepToCluster(stepRequest);
    String stepId = emrShellStep.getId();
    EmrClusterAlternateKeyDto emrClusterAlternateKeyDto = EmrClusterAlternateKeyDto.builder().withNamespace(NAMESPACE).withEmrClusterDefinitionName(EMR_CLUSTER_DEFINITION_NAME).withEmrClusterName(request.getEmrClusterName()).build();
    EmrCluster emrClusterGet = emrService.getCluster(emrClusterAlternateKeyDto, emrCluster.getId(), stepId, 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()));
    assertTrue(stepId.equals(emrClusterGet.getActiveStep().getId()));
    assertTrue(stepId.equals(emrClusterGet.getStep().getId()));
    // Test the non verbose flow
    emrClusterGet = emrService.getCluster(emrClusterAlternateKeyDto, emrCluster.getId(), stepId, false, 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()));
    assertTrue(stepId.equals(emrClusterGet.getActiveStep().getId()));
    assertTrue(stepId.equals(emrClusterGet.getStep().getId()));
}
Also used : NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) EmrClusterCreateRequest(org.finra.herd.model.api.xml.EmrClusterCreateRequest) EmrShellStepAddRequest(org.finra.herd.model.api.xml.EmrShellStepAddRequest) EmrCluster(org.finra.herd.model.api.xml.EmrCluster) EmrShellStep(org.finra.herd.model.api.xml.EmrShellStep) EmrClusterAlternateKeyDto(org.finra.herd.model.dto.EmrClusterAlternateKeyDto) Test(org.junit.Test)

Example 13 with EmrClusterAlternateKeyDto

use of org.finra.herd.model.dto.EmrClusterAlternateKeyDto in project herd by FINRAOS.

the class EmrServiceTest method testTerminateEmrClusterAmazonException.

/**
 * This method tests the scenario where AmazonServiceException is thrown
 */
@Test(expected = AmazonServiceException.class)
public void testTerminateEmrClusterAmazonException() throws Exception {
    // Create the namespace entity.
    NamespaceEntity namespaceEntity = namespaceDaoTestHelper.createNamespaceEntity(NAMESPACE);
    emrClusterDefinitionDaoTestHelper.createEmrClusterDefinitionEntity(namespaceEntity, EMR_CLUSTER_DEFINITION_NAME, IOUtils.toString(resourceLoader.getResource(EMR_CLUSTER_DEFINITION_XML_FILE_WITH_CLASSPATH).getInputStream()));
    EmrClusterCreateRequest request = getNewEmrClusterCreateRequest();
    request.setEmrClusterName(MockAwsOperationsHelper.AMAZON_SERVICE_EXCEPTION);
    emrService.createCluster(request);
    EmrClusterAlternateKeyDto emrClusterAlternateKeyDto = EmrClusterAlternateKeyDto.builder().withNamespace(NAMESPACE).withEmrClusterDefinitionName(EMR_CLUSTER_DEFINITION_NAME).withEmrClusterName(request.getEmrClusterName()).build();
    emrService.terminateCluster(emrClusterAlternateKeyDto, true, null, null);
}
Also used : NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) EmrClusterCreateRequest(org.finra.herd.model.api.xml.EmrClusterCreateRequest) EmrClusterAlternateKeyDto(org.finra.herd.model.dto.EmrClusterAlternateKeyDto) Test(org.junit.Test)

Example 14 with EmrClusterAlternateKeyDto

use of org.finra.herd.model.dto.EmrClusterAlternateKeyDto in project herd by FINRAOS.

the class EmrServiceTest method testGetEmrClusterByIdAmazonException.

/**
 * This method tests the scenario with AmazonServiceException.
 */
@Test(expected = AmazonServiceException.class)
public void testGetEmrClusterByIdAmazonException() throws Exception {
    // Create the namespace entity.
    NamespaceEntity namespaceEntity = namespaceDaoTestHelper.createNamespaceEntity(NAMESPACE);
    emrClusterDefinitionDaoTestHelper.createEmrClusterDefinitionEntity(namespaceEntity, EMR_CLUSTER_DEFINITION_NAME, IOUtils.toString(resourceLoader.getResource(EMR_CLUSTER_DEFINITION_XML_FILE_WITH_CLASSPATH).getInputStream()));
    EmrClusterAlternateKeyDto emrClusterAlternateKeyDto = EmrClusterAlternateKeyDto.builder().withNamespace(NAMESPACE).withEmrClusterDefinitionName(EMR_CLUSTER_DEFINITION_NAME).withEmrClusterName("test").build();
    emrService.getCluster(emrClusterAlternateKeyDto, MockAwsOperationsHelper.AMAZON_SERVICE_EXCEPTION, null, true, null, false);
    fail("Should throw an AmazonServiceException.");
}
Also used : NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) EmrClusterAlternateKeyDto(org.finra.herd.model.dto.EmrClusterAlternateKeyDto) Test(org.junit.Test)

Example 15 with EmrClusterAlternateKeyDto

use of org.finra.herd.model.dto.EmrClusterAlternateKeyDto 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)

Aggregations

EmrClusterAlternateKeyDto (org.finra.herd.model.dto.EmrClusterAlternateKeyDto)21 Test (org.junit.Test)16 NamespaceEntity (org.finra.herd.model.jpa.NamespaceEntity)14 EmrCluster (org.finra.herd.model.api.xml.EmrCluster)12 EmrClusterCreateRequest (org.finra.herd.model.api.xml.EmrClusterCreateRequest)10 EmrClusterDefinition (org.finra.herd.model.api.xml.EmrClusterDefinition)5 AwsParamsDto (org.finra.herd.model.dto.AwsParamsDto)3 EmrShellStepAddRequest (org.finra.herd.model.api.xml.EmrShellStepAddRequest)2 EmrClusterDefinitionEntity (org.finra.herd.model.jpa.EmrClusterDefinitionEntity)2 AmazonServiceException (com.amazonaws.AmazonServiceException)1 ClusterSummary (com.amazonaws.services.elasticmapreduce.model.ClusterSummary)1 EmrDao (org.finra.herd.dao.EmrDao)1 EmrHelper (org.finra.herd.dao.helper.EmrHelper)1 ObjectNotFoundException (org.finra.herd.model.ObjectNotFoundException)1 EmrMasterSecurityGroupAddRequest (org.finra.herd.model.api.xml.EmrMasterSecurityGroupAddRequest)1 EmrShellStep (org.finra.herd.model.api.xml.EmrShellStep)1 InstanceDefinitions (org.finra.herd.model.api.xml.InstanceDefinitions)1 EmrClusterCreationLogEntity (org.finra.herd.model.jpa.EmrClusterCreationLogEntity)1 AlternateKeyHelper (org.finra.herd.service.helper.AlternateKeyHelper)1 EmrClusterDefinitionDaoHelper (org.finra.herd.service.helper.EmrClusterDefinitionDaoHelper)1