Search in sources :

Example 6 with EmrShellStepAddRequest

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

use of org.finra.herd.model.api.xml.EmrShellStepAddRequest 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)

Example 8 with EmrShellStepAddRequest

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

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

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

the class EmrServiceTest method testEmrAddStepsInvalidCluster.

/**
 * This method tests the happy path scenario by providing all the parameters
 */
@Test(expected = IllegalArgumentException.class)
public void testEmrAddStepsInvalidCluster() 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 a new EMR cluster create request.
    EmrShellStepAddRequest stepRequest = getNewEmrShellStepAddRequest(request.getEmrClusterName());
    stepRequest.setEmrClusterName("InvalidName");
    emrService.addStepToCluster(stepRequest);
}
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) Test(org.junit.Test)

Aggregations

EmrShellStepAddRequest (org.finra.herd.model.api.xml.EmrShellStepAddRequest)14 Test (org.junit.Test)10 EmrClusterCreateRequest (org.finra.herd.model.api.xml.EmrClusterCreateRequest)9 NamespaceEntity (org.finra.herd.model.jpa.NamespaceEntity)8 ArrayList (java.util.ArrayList)4 EmrShellStep (org.finra.herd.model.api.xml.EmrShellStep)4 Method (java.lang.reflect.Method)2 EmrHadoopJarStepAddRequest (org.finra.herd.model.api.xml.EmrHadoopJarStepAddRequest)2 EmrHiveStepAddRequest (org.finra.herd.model.api.xml.EmrHiveStepAddRequest)2 EmrPigStepAddRequest (org.finra.herd.model.api.xml.EmrPigStepAddRequest)2 EmrClusterAlternateKeyDto (org.finra.herd.model.dto.EmrClusterAlternateKeyDto)2 EmrStepHelper (org.finra.herd.service.helper.EmrStepHelper)2 ObjectNotFoundException (org.finra.herd.model.ObjectNotFoundException)1 EmrCluster (org.finra.herd.model.api.xml.EmrCluster)1 EmrMasterSecurityGroupAddRequest (org.finra.herd.model.api.xml.EmrMasterSecurityGroupAddRequest)1