Search in sources :

Example 1 with EmrHadoopJarStepAddRequest

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

the class AddEmrHadoopJarStep method executeImpl.

@Override
public void executeImpl(DelegateExecution execution) throws Exception {
    // Create the request.
    EmrHadoopJarStepAddRequest request = new EmrHadoopJarStepAddRequest();
    populateCommonParams(request, execution);
    request.setJarLocation(getJarLocation(execution));
    request.setMainClass(getMainClass(execution));
    request.setScriptArguments(getScriptArguments(execution));
    addEmrStepAndSetWorkflowVariables(request, execution);
}
Also used : EmrHadoopJarStepAddRequest(org.finra.herd.model.api.xml.EmrHadoopJarStepAddRequest)

Example 2 with EmrHadoopJarStepAddRequest

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

the class EmrServiceWithAccountIdTest method testEmrAddStepsAllTypes.

/**
 * This method tests the happy path scenario by testing all the step types.
 */
@Test
public void testEmrAddStepsAllTypes() throws Exception {
    // Create the namespace entity.
    NamespaceEntity namespaceEntity = namespaceDaoTestHelper.createNamespaceEntity(NAMESPACE);
    // Create a trusting AWS account.
    trustingAccountDaoTestHelper.createTrustingAccountEntity(AWS_ACCOUNT_ID, AWS_ROLE_ARN);
    emrClusterDefinitionDaoTestHelper.createEmrClusterDefinitionEntity(namespaceEntity, EMR_CLUSTER_DEFINITION_NAME, IOUtils.toString(resourceLoader.getResource(EMR_CLUSTER_DEFINITION_XML_FILE_WITH_CLASSPATH).getInputStream()));
    EmrClusterCreateRequest request = getNewEmrClusterCreateRequestWithAccountId();
    emrService.createCluster(request);
    List<Object> emrSteps = new ArrayList<>();
    List<String> shellScriptArgs = new ArrayList<>();
    shellScriptArgs.add("Hello");
    shellScriptArgs.add("herd");
    shellScriptArgs.add("How Are You");
    EmrShellStepAddRequest shellStepRequest = new EmrShellStepAddRequest();
    shellStepRequest.setScriptLocation("s3://test-bucket-managed/app-a/test/test_script.sh");
    shellStepRequest.setStepName("Test Shell Script");
    shellStepRequest.setScriptArguments(shellScriptArgs);
    emrSteps.add(shellStepRequest);
    EmrHiveStepAddRequest hiveStepRequest = new EmrHiveStepAddRequest();
    List<String> scriptArgs1 = new ArrayList<>();
    scriptArgs1.add("arg2=sampleArg");
    scriptArgs1.add("arg1=tables");
    hiveStepRequest.setStepName("Test Hive");
    hiveStepRequest.setScriptLocation("s3://test-bucket-managed/app-a/test/test_hive.hql");
    hiveStepRequest.setScriptArguments(scriptArgs1);
    emrSteps.add(hiveStepRequest);
    EmrPigStepAddRequest pigStepRequest = new EmrPigStepAddRequest();
    pigStepRequest.setStepName("Test Pig");
    pigStepRequest.setScriptArguments(shellScriptArgs);
    pigStepRequest.setScriptLocation("s3://test-bucket-managed/app-a/test/test_pig.pig");
    emrSteps.add(pigStepRequest);
    shellStepRequest = new EmrShellStepAddRequest();
    shellStepRequest.setScriptLocation("s3://test-bucket-managed/app-a/bootstrap/install_oozie.sh");
    shellStepRequest.setStepName("Install Oozie");
    List<String> shellScriptArgsOozie = new ArrayList<>();
    shellScriptArgsOozie.add("s3://test-bucket-managed/app-a/bootstrap/oozie-4.0.1-distro.tar");
    shellStepRequest.setScriptArguments(shellScriptArgsOozie);
    emrSteps.add(shellStepRequest);
    EmrHadoopJarStepAddRequest hadoopJarStepRequest = new EmrHadoopJarStepAddRequest();
    List<String> scriptArgs2 = new ArrayList<>();
    scriptArgs2.add("oozie_run");
    scriptArgs2.add("wordcountOutput");
    hadoopJarStepRequest.setStepName("Hadoop Jar");
    hadoopJarStepRequest.setJarLocation("s3://test-bucket-managed/app-a/test/hadoop-mapreduce-examples-2.4.0.jar");
    hadoopJarStepRequest.setMainClass("wordcount");
    hadoopJarStepRequest.setScriptArguments(scriptArgs2);
    emrSteps.add(hadoopJarStepRequest);
    EmrStepHelper stepHelper;
    for (Object emrStepAddRequest : emrSteps) {
        stepHelper = emrStepHelperFactory.getStepHelper(emrStepAddRequest.getClass().getName());
        stepHelper.setRequestNamespace(emrStepAddRequest, NAMESPACE);
        stepHelper.setRequestEmrClusterDefinitionName(emrStepAddRequest, EMR_CLUSTER_DEFINITION_NAME);
        stepHelper.setRequestEmrClusterName(emrStepAddRequest, request.getEmrClusterName());
        stepHelper.setRequestAccountId(emrStepAddRequest, AWS_ACCOUNT_ID);
        Object emrStep = emrService.addStepToCluster(emrStepAddRequest);
        assertNotNull(emrStep);
        assertNotNull(stepHelper.getStepId(emrStep));
        Method getNameMethod = emrStep.getClass().getMethod("getStepName");
        String emrStepName = (String) getNameMethod.invoke(emrStep);
        assertEquals(stepHelper.getRequestStepName(emrStepAddRequest), emrStepName);
        Method isContinueOnErrorMethod = emrStep.getClass().getMethod("isContinueOnError");
        Object emrStepIsContinueOnError = isContinueOnErrorMethod.invoke(emrStep);
        assertEquals(stepHelper.isRequestContinueOnError(emrStepAddRequest), emrStepIsContinueOnError);
    }
}
Also used : NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) EmrPigStepAddRequest(org.finra.herd.model.api.xml.EmrPigStepAddRequest) EmrClusterCreateRequest(org.finra.herd.model.api.xml.EmrClusterCreateRequest) EmrShellStepAddRequest(org.finra.herd.model.api.xml.EmrShellStepAddRequest) ArrayList(java.util.ArrayList) EmrStepHelper(org.finra.herd.service.helper.EmrStepHelper) Method(java.lang.reflect.Method) EmrHadoopJarStepAddRequest(org.finra.herd.model.api.xml.EmrHadoopJarStepAddRequest) EmrHiveStepAddRequest(org.finra.herd.model.api.xml.EmrHiveStepAddRequest) Test(org.junit.Test)

Example 3 with EmrHadoopJarStepAddRequest

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

the class EmrRestControllerTest method testAddHadoopJarStepToEmrCluster.

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

Example 4 with EmrHadoopJarStepAddRequest

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

the class EmrServiceTest method testEmrAddStepsHadoopNoMainClass.

/**
 * This method tests the happy path scenario by testing all the step types
 */
@Test
public void testEmrAddStepsHadoopNoMainClass() 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);
    // TODO: Why are we adding EMR steps to a list, but not doing anything with them once they're added?
    List<Serializable> emrSteps = new ArrayList<>();
    EmrHadoopJarStepAddRequest hadoopJarStepRequest = new EmrHadoopJarStepAddRequest();
    hadoopJarStepRequest.setNamespace(request.getNamespace());
    hadoopJarStepRequest.setEmrClusterDefinitionName(request.getEmrClusterDefinitionName());
    hadoopJarStepRequest.setEmrClusterName(request.getEmrClusterName());
    hadoopJarStepRequest.setStepName("Hadoop Jar");
    hadoopJarStepRequest.setJarLocation("s3://test-bucket-managed/app-a/test/hadoop-mapreduce-examples-2.4.0.jar");
    emrSteps.add(hadoopJarStepRequest);
    EmrHadoopJarStep emrHadoopJarStep = (EmrHadoopJarStep) emrService.addStepToCluster(hadoopJarStepRequest);
    assertNotNull(emrHadoopJarStep);
    assertNotNull(emrHadoopJarStep.getId());
}
Also used : EmrHadoopJarStep(org.finra.herd.model.api.xml.EmrHadoopJarStep) NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) Serializable(java.io.Serializable) EmrHadoopJarStepAddRequest(org.finra.herd.model.api.xml.EmrHadoopJarStepAddRequest) EmrClusterCreateRequest(org.finra.herd.model.api.xml.EmrClusterCreateRequest) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 5 with EmrHadoopJarStepAddRequest

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

the class EmrServiceTest method testEmrAddStepsAllTypes.

/**
 * This method tests the happy path scenario by testing all the step types
 */
@Test
public void testEmrAddStepsAllTypes() 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);
    List<Object> emrSteps = new ArrayList<>();
    List<String> shellScriptArgs = new ArrayList<>();
    shellScriptArgs.add("Hello");
    shellScriptArgs.add("herd");
    shellScriptArgs.add("How Are You");
    EmrShellStepAddRequest shellStepRequest = new EmrShellStepAddRequest();
    shellStepRequest.setScriptLocation("s3://test-bucket-managed/app-a/test/test_script.sh");
    shellStepRequest.setStepName("Test Shell Script");
    shellStepRequest.setScriptArguments(shellScriptArgs);
    emrSteps.add(shellStepRequest);
    EmrHiveStepAddRequest hiveStepRequest = new EmrHiveStepAddRequest();
    List<String> scriptArgs1 = new ArrayList<>();
    scriptArgs1.add("arg2=sampleArg");
    scriptArgs1.add("arg1=tables");
    hiveStepRequest.setStepName("Test Hive");
    hiveStepRequest.setScriptLocation("s3://test-bucket-managed/app-a/test/test_hive.hql");
    hiveStepRequest.setScriptArguments(scriptArgs1);
    emrSteps.add(hiveStepRequest);
    EmrPigStepAddRequest pigStepRequest = new EmrPigStepAddRequest();
    pigStepRequest.setStepName("Test Pig");
    pigStepRequest.setScriptArguments(shellScriptArgs);
    pigStepRequest.setScriptLocation("s3://test-bucket-managed/app-a/test/test_pig.pig");
    emrSteps.add(pigStepRequest);
    shellStepRequest = new EmrShellStepAddRequest();
    shellStepRequest.setScriptLocation("s3://test-bucket-managed/app-a/bootstrap/install_oozie.sh");
    shellStepRequest.setStepName("Install Oozie");
    List<String> shellScriptArgsOozie = new ArrayList<>();
    shellScriptArgsOozie.add("s3://test-bucket-managed/app-a/bootstrap/oozie-4.0.1-distro.tar");
    shellStepRequest.setScriptArguments(shellScriptArgsOozie);
    emrSteps.add(shellStepRequest);
    EmrHadoopJarStepAddRequest hadoopJarStepRequest = new EmrHadoopJarStepAddRequest();
    List<String> scriptArgs2 = new ArrayList<>();
    scriptArgs2.add("oozie_run");
    scriptArgs2.add("wordcountOutput");
    hadoopJarStepRequest.setStepName("Hadoop Jar");
    hadoopJarStepRequest.setJarLocation("s3://test-bucket-managed/app-a/test/hadoop-mapreduce-examples-2.4.0.jar");
    hadoopJarStepRequest.setMainClass("wordcount");
    hadoopJarStepRequest.setScriptArguments(scriptArgs2);
    emrSteps.add(hadoopJarStepRequest);
    EmrStepHelper stepHelper;
    for (Object emrStepAddRequest : emrSteps) {
        stepHelper = emrStepHelperFactory.getStepHelper(emrStepAddRequest.getClass().getName());
        stepHelper.setRequestNamespace(emrStepAddRequest, NAMESPACE);
        stepHelper.setRequestEmrClusterDefinitionName(emrStepAddRequest, EMR_CLUSTER_DEFINITION_NAME);
        stepHelper.setRequestEmrClusterName(emrStepAddRequest, request.getEmrClusterName());
        Object emrStep = emrService.addStepToCluster(emrStepAddRequest);
        assertNotNull(emrStep);
        assertNotNull(stepHelper.getStepId(emrStep));
        Method getNameMethod = emrStep.getClass().getMethod("getStepName");
        String emrStepName = (String) getNameMethod.invoke(emrStep);
        assertEquals(stepHelper.getRequestStepName(emrStepAddRequest), emrStepName);
        Method isContinueOnErrorMethod = emrStep.getClass().getMethod("isContinueOnError");
        Object emrStepIsContinueOnError = isContinueOnErrorMethod.invoke(emrStep);
        assertEquals(stepHelper.isRequestContinueOnError(emrStepAddRequest), emrStepIsContinueOnError);
    }
}
Also used : NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) EmrPigStepAddRequest(org.finra.herd.model.api.xml.EmrPigStepAddRequest) EmrClusterCreateRequest(org.finra.herd.model.api.xml.EmrClusterCreateRequest) EmrShellStepAddRequest(org.finra.herd.model.api.xml.EmrShellStepAddRequest) ArrayList(java.util.ArrayList) EmrStepHelper(org.finra.herd.service.helper.EmrStepHelper) Method(java.lang.reflect.Method) EmrHadoopJarStepAddRequest(org.finra.herd.model.api.xml.EmrHadoopJarStepAddRequest) EmrHiveStepAddRequest(org.finra.herd.model.api.xml.EmrHiveStepAddRequest) Test(org.junit.Test)

Aggregations

EmrHadoopJarStepAddRequest (org.finra.herd.model.api.xml.EmrHadoopJarStepAddRequest)7 ArrayList (java.util.ArrayList)4 Test (org.junit.Test)4 EmrClusterCreateRequest (org.finra.herd.model.api.xml.EmrClusterCreateRequest)3 EmrHadoopJarStep (org.finra.herd.model.api.xml.EmrHadoopJarStep)3 NamespaceEntity (org.finra.herd.model.jpa.NamespaceEntity)3 Method (java.lang.reflect.Method)2 EmrHiveStepAddRequest (org.finra.herd.model.api.xml.EmrHiveStepAddRequest)2 EmrPigStepAddRequest (org.finra.herd.model.api.xml.EmrPigStepAddRequest)2 EmrShellStepAddRequest (org.finra.herd.model.api.xml.EmrShellStepAddRequest)2 EmrStepHelper (org.finra.herd.service.helper.EmrStepHelper)2 Serializable (java.io.Serializable)1