Search in sources :

Example 1 with EmrClusterAlternateKeyDto

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

the class TerminateEmrCluster method executeImpl.

@Override
public void executeImpl(DelegateExecution execution) throws Exception {
    EmrClusterAlternateKeyDto emrClusterAlternateKeyDto = getClusterAlternateKey(execution);
    boolean overrideTerminationProtectionBoolean = activitiHelper.getExpressionVariableAsBoolean(overrideTerminationProtection, execution, "overrideTerminationProtection", false, false);
    String emrClusterIdString = activitiHelper.getExpressionVariableAsString(emrClusterId, execution);
    String accountIdString = activitiHelper.getExpressionVariableAsString(accountId, execution);
    // Terminate the EMR cluster.
    EmrCluster emrCluster = emrService.terminateCluster(emrClusterAlternateKeyDto, overrideTerminationProtectionBoolean, emrClusterIdString, accountIdString);
    // Set workflow variables based on the result EMR cluster that was terminated.
    setIdStatusWorkflowVariables(execution, emrCluster);
    LOGGER.info("{} EMR cluster terminated. emrClusterId=\"{}\"", activitiHelper.getProcessIdentifyingInformation(execution), emrCluster.getId());
}
Also used : EmrCluster(org.finra.herd.model.api.xml.EmrCluster) EmrClusterAlternateKeyDto(org.finra.herd.model.dto.EmrClusterAlternateKeyDto)

Example 2 with EmrClusterAlternateKeyDto

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

the class CheckEmrCluster method executeImpl.

@Override
public void executeImpl(DelegateExecution execution) throws Exception {
    EmrClusterAlternateKeyDto emrClusterAlternateKeyDto = getClusterAlternateKey(execution);
    String emrStepIdString = activitiHelper.getExpressionVariableAsString(emrStepId, execution);
    String emrClusterIdString = activitiHelper.getExpressionVariableAsString(emrClusterId, execution);
    boolean verboseBoolean = activitiHelper.getExpressionVariableAsBoolean(verbose, execution, "verbose", false, false);
    String accountIdString = activitiHelper.getExpressionVariableAsString(accountId, execution);
    Boolean retrieveInstanceFleetsBoolean = activitiHelper.getExpressionVariableAsBoolean(retrieveInstanceFleets, execution, "retrieveInstanceFleets", false, false);
    // Gets the EMR cluster details.
    EmrCluster emrCluster = emrService.getCluster(emrClusterAlternateKeyDto, emrClusterIdString, emrStepIdString, verboseBoolean, accountIdString, retrieveInstanceFleetsBoolean);
    // Set cluster id and status workflow variables based on the result EMR cluster.
    setIdStatusWorkflowVariables(execution, emrCluster);
    setTaskWorkflowVariable(execution, VARIABLE_EMR_CLUSTER_STATUS_CHANGE_REASON_CODE, emrCluster.getStatusChangeReason().getCode());
    setTaskWorkflowVariable(execution, VARIABLE_EMR_CLUSTER_STATUS_CHANGE_REASON_MESSAGE, emrCluster.getStatusChangeReason().getMessage());
    setTaskWorkflowVariable(execution, VARIABLE_EMR_CLUSTER_CREATION_TIME, emrCluster.getStatusTimeline().getCreationTime());
    setTaskWorkflowVariable(execution, VARIABLE_EMR_CLUSTER_READY_TIME, emrCluster.getStatusTimeline().getReadyTime());
    setTaskWorkflowVariable(execution, VARIABLE_EMR_CLUSTER_END_TIME, emrCluster.getStatusTimeline().getEndTime());
    // Set the active step details in workflow variables
    if (emrCluster.getActiveStep() != null && emrCluster.getActiveStep().getId() != null) {
        setTaskWorkflowVariable(execution, "activeStep_id", emrCluster.getActiveStep().getId());
        setTaskWorkflowVariable(execution, "activeStep_stepName", emrCluster.getActiveStep().getStepName());
        setTaskWorkflowVariable(execution, "activeStep_status", emrCluster.getActiveStep().getStatus());
        if (verboseBoolean) {
            setTaskWorkflowVariable(execution, "activeStep_jarLocation", emrCluster.getActiveStep().getJarLocation());
            setTaskWorkflowVariable(execution, "activeStep_mainClass", emrCluster.getActiveStep().getMainClass());
            setTaskWorkflowVariable(execution, "activeStep_scriptArguments", herdStringHelper.buildStringWithDefaultDelimiter(emrCluster.getActiveStep().getScriptArguments()));
            setTaskWorkflowVariable(execution, "activeStep_continueOnError", emrCluster.getActiveStep().getContinueOnError());
        }
    }
    // Set the requested step details in workflow variables
    if (emrCluster.getStep() != null && emrCluster.getStep().getId() != null) {
        setTaskWorkflowVariable(execution, "step_id", emrCluster.getStep().getId());
        setTaskWorkflowVariable(execution, "step_stepName", emrCluster.getStep().getStepName());
        setTaskWorkflowVariable(execution, "step_status", emrCluster.getStep().getStatus());
        if (verboseBoolean) {
            setTaskWorkflowVariable(execution, "step_jarLocation", emrCluster.getStep().getJarLocation());
            setTaskWorkflowVariable(execution, "step_mainClass", emrCluster.getStep().getMainClass());
            setTaskWorkflowVariable(execution, "step_scriptArguments", herdStringHelper.buildStringWithDefaultDelimiter(emrCluster.getStep().getScriptArguments()));
            setTaskWorkflowVariable(execution, "step_continueOnError", emrCluster.getStep().getContinueOnError());
        }
    }
    // Set the instance fleets variable
    if (BooleanUtils.isTrue(retrieveInstanceFleetsBoolean)) {
        setTaskWorkflowVariable(execution, "instance_fleets", jsonHelper.objectToJson(emrCluster.getInstanceFleets()));
    }
}
Also used : EmrCluster(org.finra.herd.model.api.xml.EmrCluster) EmrClusterAlternateKeyDto(org.finra.herd.model.dto.EmrClusterAlternateKeyDto)

Example 3 with EmrClusterAlternateKeyDto

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

the class EmrRestControllerTest method testGetEmrCluster.

@Test
public void testGetEmrCluster() throws Exception {
    // Create an EMR cluster key.
    EmrClusterAlternateKeyDto emrClusterAlternateKeyDto = new EmrClusterAlternateKeyDto(NAMESPACE, EMR_CLUSTER_DEFINITION_NAME, EMR_CLUSTER_NAME);
    // Create an EMR cluster.
    EmrCluster emrCluster = new EmrCluster();
    emrCluster.setId(EMR_CLUSTER_ID);
    // Mock the external calls.
    when(emrService.getCluster(emrClusterAlternateKeyDto, EMR_CLUSTER_ID, EMR_STEP_ID, EMR_CLUSTER_VERBOSE_FLAG, AWS_ACCOUNT_ID, RETRIEVE_INSTANCE_FLEETS)).thenReturn(emrCluster);
    // Call the method under test.
    EmrCluster result = emrRestController.getEmrCluster(NAMESPACE, EMR_CLUSTER_DEFINITION_NAME, EMR_CLUSTER_NAME, EMR_CLUSTER_ID, EMR_STEP_ID, EMR_CLUSTER_VERBOSE_FLAG, AWS_ACCOUNT_ID, RETRIEVE_INSTANCE_FLEETS);
    // Verify the external calls.
    verify(emrService).getCluster(emrClusterAlternateKeyDto, EMR_CLUSTER_ID, EMR_STEP_ID, EMR_CLUSTER_VERBOSE_FLAG, AWS_ACCOUNT_ID, RETRIEVE_INSTANCE_FLEETS);
    verifyNoMoreInteractionsHelper();
    // Validate the results.
    assertEquals(emrCluster, result);
}
Also used : EmrCluster(org.finra.herd.model.api.xml.EmrCluster) EmrClusterAlternateKeyDto(org.finra.herd.model.dto.EmrClusterAlternateKeyDto) Test(org.junit.Test)

Example 4 with EmrClusterAlternateKeyDto

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

the class EmrServiceTest method testTerminateEmrCluster.

/**
 * This method tests the happy path scenario by providing all the parameters
 */
@Test
public void testTerminateEmrCluster() 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);
    EmrClusterAlternateKeyDto emrClusterAlternateKeyDto = EmrClusterAlternateKeyDto.builder().withNamespace(NAMESPACE).withEmrClusterDefinitionName(EMR_CLUSTER_DEFINITION_NAME).withEmrClusterName(request.getEmrClusterName()).build();
    EmrCluster emrClusterTerminated = emrService.terminateCluster(emrClusterAlternateKeyDto, true, null, null);
    // Validate the returned object against the input.
    assertNotNull(emrCluster);
    assertNotNull(emrClusterTerminated);
    assertTrue(emrCluster.getNamespace().equals(emrClusterTerminated.getNamespace()));
    assertTrue(emrCluster.getEmrClusterDefinitionName().equals(emrClusterTerminated.getEmrClusterDefinitionName()));
    assertTrue(emrCluster.getEmrClusterName().equals(emrClusterTerminated.getEmrClusterName()));
}
Also used : NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) 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 5 with EmrClusterAlternateKeyDto

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

the class EmrServiceTest method testGetEmrClusterByIdDoesNotExist.

/**
 * This method tests the scenario when cluster specified does not exists.
 */
@Test(expected = IllegalArgumentException.class)
public void testGetEmrClusterByIdDoesNotExist() 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("cluster_does_not_exist").build();
    emrService.getCluster(emrClusterAlternateKeyDto, "cluster_does_not_exist", null, true, null, false);
    fail("Should throw an IllegalArgumentException.");
}
Also used : NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) EmrClusterAlternateKeyDto(org.finra.herd.model.dto.EmrClusterAlternateKeyDto) 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