Search in sources :

Example 1 with EmrShellStep

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

the class EmrShellStepHelper method buildResponseFromRequest.

@Override
public Object buildResponseFromRequest(Object stepRequest) {
    EmrShellStepAddRequest emrShellStepAddRequest = (EmrShellStepAddRequest) stepRequest;
    EmrShellStep step = new EmrShellStep();
    step.setNamespace(emrShellStepAddRequest.getNamespace());
    step.setEmrClusterDefinitionName(emrShellStepAddRequest.getEmrClusterDefinitionName());
    step.setEmrClusterName(emrShellStepAddRequest.getEmrClusterName());
    step.setStepName(emrShellStepAddRequest.getStepName().trim());
    step.setScriptLocation(emrShellStepAddRequest.getScriptLocation().trim().replaceAll(getS3ManagedReplaceString(), emrHelper.getS3StagingLocation()));
    // Add the script arguments
    if (!CollectionUtils.isEmpty(emrShellStepAddRequest.getScriptArguments())) {
        List<String> scriptArguments = new ArrayList<>();
        step.setScriptArguments(scriptArguments);
        for (String argument : emrShellStepAddRequest.getScriptArguments()) {
            scriptArguments.add(argument.trim());
        }
    }
    step.setContinueOnError(emrShellStepAddRequest.isContinueOnError());
    return step;
}
Also used : EmrShellStepAddRequest(org.finra.herd.model.api.xml.EmrShellStepAddRequest) EmrShellStep(org.finra.herd.model.api.xml.EmrShellStep) ArrayList(java.util.ArrayList)

Example 2 with EmrShellStep

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

the class EmrRestControllerTest method testAddShellStepToEmrCluster.

@Test
public void testAddShellStepToEmrCluster() throws Exception {
    // Create an add step request.
    EmrShellStepAddRequest emrShellStepAddRequest = new EmrShellStepAddRequest(NAMESPACE, EMR_CLUSTER_DEFINITION_NAME, EMR_CLUSTER_NAME, EMR_STEP_NAME, EMR_STEP_SCRIPT_LOCATION, Arrays.asList(ATTRIBUTE_NAME_1_MIXED_CASE), CONTINUE_ON_ERROR, EMR_CLUSTER_ID, AWS_ACCOUNT_ID);
    // Create an add step response.
    EmrShellStep emrShellStep = new EmrShellStep(EMR_STEP_ID, NAMESPACE, EMR_CLUSTER_DEFINITION_NAME, EMR_CLUSTER_NAME, EMR_STEP_NAME, EMR_STEP_SCRIPT_LOCATION, Arrays.asList(ATTRIBUTE_NAME_1_MIXED_CASE), CONTINUE_ON_ERROR, EMR_CLUSTER_ID);
    // Mock the external calls.
    when(emrService.addStepToCluster(emrShellStepAddRequest)).thenReturn(emrShellStep);
    // Call the method under test.
    EmrShellStep result = emrRestController.addShellStepToEmrCluster(emrShellStepAddRequest);
    // Verify the external calls.
    verify(emrService).addStepToCluster(emrShellStepAddRequest);
    verifyNoMoreInteractionsHelper();
    // Validate the results.
    assertEquals(emrShellStep, result);
}
Also used : EmrShellStepAddRequest(org.finra.herd.model.api.xml.EmrShellStepAddRequest) EmrShellStep(org.finra.herd.model.api.xml.EmrShellStep) Test(org.junit.Test)

Example 3 with EmrShellStep

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

the class EmrServiceTest method testEmrAddSteps.

/**
 * This method tests the happy path scenario by providing all the parameters
 */
@Test
public void testEmrAddSteps() 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();
    emrService.createCluster(request);
    // Create the Add step request.
    EmrShellStepAddRequest stepRequest = getNewEmrShellStepAddRequest(request.getEmrClusterName());
    EmrShellStep emrShellStep = (EmrShellStep) emrService.addStepToCluster(stepRequest);
    // Validate the returned object against the input.
    assertNotNull(emrShellStep);
    assertTrue(emrShellStep.getNamespace().equals(request.getNamespace()));
    assertTrue(emrShellStep.getEmrClusterDefinitionName().equals(request.getEmrClusterDefinitionName()));
    assertTrue(emrShellStep.getEmrClusterName().equals(request.getEmrClusterName()));
}
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) EmrShellStep(org.finra.herd.model.api.xml.EmrShellStep) Test(org.junit.Test)

Example 4 with EmrShellStep

use of org.finra.herd.model.api.xml.EmrShellStep 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 5 with EmrShellStep

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

the class EmrShellStepHelper method getEmrStepConfig.

@Override
public StepConfig getEmrStepConfig(Object step) {
    EmrShellStep emrShellStep = (EmrShellStep) step;
    // Hadoop Jar provided by Amazon for running Shell Scripts
    String hadoopJarForShellScript = configurationHelper.getProperty(ConfigurationValue.EMR_SHELL_SCRIPT_JAR);
    // Default ActionOnFailure is to cancel the execution and wait
    ActionOnFailure actionOnFailure = ActionOnFailure.CANCEL_AND_WAIT;
    if (emrShellStep.isContinueOnError() != null && emrShellStep.isContinueOnError()) {
        // Override based on user input
        actionOnFailure = ActionOnFailure.CONTINUE;
    }
    // Add the script location
    List<String> argsList = new ArrayList<>();
    argsList.add(emrShellStep.getScriptLocation().trim());
    // Add the script arguments
    if (!CollectionUtils.isEmpty(emrShellStep.getScriptArguments())) {
        for (String argument : emrShellStep.getScriptArguments()) {
            argsList.add(argument.trim());
        }
    }
    // Return the StepConfig object
    HadoopJarStepConfig jarConfig = new HadoopJarStepConfig(hadoopJarForShellScript).withArgs(argsList);
    return new StepConfig().withName(emrShellStep.getStepName().trim()).withActionOnFailure(actionOnFailure).withHadoopJarStep(jarConfig);
}
Also used : HadoopJarStepConfig(com.amazonaws.services.elasticmapreduce.model.HadoopJarStepConfig) ActionOnFailure(com.amazonaws.services.elasticmapreduce.model.ActionOnFailure) EmrShellStep(org.finra.herd.model.api.xml.EmrShellStep) ArrayList(java.util.ArrayList) StepConfig(com.amazonaws.services.elasticmapreduce.model.StepConfig) HadoopJarStepConfig(com.amazonaws.services.elasticmapreduce.model.HadoopJarStepConfig)

Aggregations

EmrShellStep (org.finra.herd.model.api.xml.EmrShellStep)6 EmrShellStepAddRequest (org.finra.herd.model.api.xml.EmrShellStepAddRequest)4 Test (org.junit.Test)4 ArrayList (java.util.ArrayList)3 EmrClusterCreateRequest (org.finra.herd.model.api.xml.EmrClusterCreateRequest)3 NamespaceEntity (org.finra.herd.model.jpa.NamespaceEntity)3 EmrCluster (org.finra.herd.model.api.xml.EmrCluster)2 ActionOnFailure (com.amazonaws.services.elasticmapreduce.model.ActionOnFailure)1 HadoopJarStepConfig (com.amazonaws.services.elasticmapreduce.model.HadoopJarStepConfig)1 StepConfig (com.amazonaws.services.elasticmapreduce.model.StepConfig)1 EmrHadoopJarStep (org.finra.herd.model.api.xml.EmrHadoopJarStep)1 EmrHiveStep (org.finra.herd.model.api.xml.EmrHiveStep)1 EmrPigStep (org.finra.herd.model.api.xml.EmrPigStep)1 EmrClusterAlternateKeyDto (org.finra.herd.model.dto.EmrClusterAlternateKeyDto)1 AbstractServiceTest (org.finra.herd.service.AbstractServiceTest)1