Search in sources :

Example 1 with ListStepsResult

use of com.amazonaws.services.elasticmapreduce.model.ListStepsResult in project herd by FINRAOS.

the class EmrDaoTest method getClusterActiveStepAssertReturnNullWhenStepListIsEmpty.

@Test
public void getClusterActiveStepAssertReturnNullWhenStepListIsEmpty() throws Exception {
    String clusterId = "clusterId";
    when(mockEmrOperations.listStepsRequest(any(), any())).thenReturn(new ListStepsResult());
    assertNull(emrDao.getClusterActiveStep(clusterId, new AwsParamsDto()));
}
Also used : ListStepsResult(com.amazonaws.services.elasticmapreduce.model.ListStepsResult) AwsParamsDto(org.finra.herd.model.dto.AwsParamsDto) Test(org.junit.Test)

Example 2 with ListStepsResult

use of com.amazonaws.services.elasticmapreduce.model.ListStepsResult in project herd by FINRAOS.

the class EmrDaoTest method getClusterActiveStepAssertReturnFirstWhenStepListSizeGt1.

@Test
public void getClusterActiveStepAssertReturnFirstWhenStepListSizeGt1() throws Exception {
    String clusterId = "clusterId";
    StepSummary expectedStepSummary = new StepSummary();
    expectedStepSummary.setId("expected");
    ListStepsResult listStepsResult = new ListStepsResult();
    listStepsResult.setSteps(Arrays.asList(expectedStepSummary, new StepSummary()));
    when(mockEmrOperations.listStepsRequest(any(), any())).thenReturn(listStepsResult);
    assertEquals(expectedStepSummary, emrDao.getClusterActiveStep(clusterId, new AwsParamsDto()));
}
Also used : ListStepsResult(com.amazonaws.services.elasticmapreduce.model.ListStepsResult) AwsParamsDto(org.finra.herd.model.dto.AwsParamsDto) StepSummary(com.amazonaws.services.elasticmapreduce.model.StepSummary) Test(org.junit.Test)

Example 3 with ListStepsResult

use of com.amazonaws.services.elasticmapreduce.model.ListStepsResult in project herd by FINRAOS.

the class EmrServiceTest method testCreateEmrClusterStartupSteps.

/**
 * This method tests the cluster creation with the startup hadoop jar steps being added.
 */
@Test
public void testCreateEmrClusterStartupSteps() throws Exception {
    // Create the namespace entity.
    NamespaceEntity namespaceEntity = namespaceDaoTestHelper.createNamespaceEntity(NAMESPACE);
    String definitionXml = IOUtils.toString(resourceLoader.getResource(EMR_CLUSTER_DEFINITION_XML_FILE_WITH_CLASSPATH).getInputStream());
    EmrClusterDefinition expectedEmrClusterDefinition = xmlHelper.unmarshallXmlToObject(EmrClusterDefinition.class, definitionXml);
    emrClusterDefinitionDaoTestHelper.createEmrClusterDefinitionEntity(namespaceEntity, EMR_CLUSTER_DEFINITION_NAME, definitionXml);
    // Create a new EMR cluster create request
    EmrClusterCreateRequest request = getNewEmrClusterCreateRequest();
    EmrCluster emrCluster = emrService.createCluster(request);
    // Validate the returned object against the input.
    assertNotNull(emrCluster);
    assertTrue(emrCluster.getNamespace().equals(request.getNamespace()));
    assertTrue(emrCluster.getEmrClusterDefinitionName().equals(request.getEmrClusterDefinitionName()));
    assertTrue(emrCluster.getEmrClusterName().equals(request.getEmrClusterName()));
    assertNotNull(emrCluster.getId());
    assertNull(emrCluster.isDryRun());
    assertNotNull(emrCluster.getEmrClusterDefinition());
    assertTrue(emrCluster.isEmrClusterCreated());
    assertEquals(expectedEmrClusterDefinition, emrCluster.getEmrClusterDefinition());
    validateEmrClusterCreationLogUnique(emrCluster, expectedEmrClusterDefinition);
    ListStepsRequest listStepsRequest = (new ListStepsRequest()).withClusterId(emrCluster.getId());
    ListStepsResult listStepsResult = emrOperations.listStepsRequest(null, listStepsRequest);
    List<StepSummary> addedSteps = listStepsResult.getSteps();
    // Validate that the step was added.
    for (HadoopJarStep hadoopJarStep : expectedEmrClusterDefinition.getHadoopJarSteps()) {
        boolean stepFound = false;
        for (StepSummary stepSummary : addedSteps) {
            if (stepSummary.getName().equals(hadoopJarStep.getStepName())) {
                // Step found
                stepFound = true;
                break;
            }
        }
        assertTrue(stepFound);
    }
}
Also used : ListStepsResult(com.amazonaws.services.elasticmapreduce.model.ListStepsResult) NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) EmrClusterDefinition(org.finra.herd.model.api.xml.EmrClusterDefinition) EmrClusterCreateRequest(org.finra.herd.model.api.xml.EmrClusterCreateRequest) StepSummary(com.amazonaws.services.elasticmapreduce.model.StepSummary) EmrCluster(org.finra.herd.model.api.xml.EmrCluster) ListStepsRequest(com.amazonaws.services.elasticmapreduce.model.ListStepsRequest) HadoopJarStep(org.finra.herd.model.api.xml.HadoopJarStep) EmrHadoopJarStep(org.finra.herd.model.api.xml.EmrHadoopJarStep) Test(org.junit.Test)

Example 4 with ListStepsResult

use of com.amazonaws.services.elasticmapreduce.model.ListStepsResult in project herd by FINRAOS.

the class MockEmrOperationsImpl method listStepsRequest.

@Override
public ListStepsResult listStepsRequest(AmazonElasticMapReduceClient emrClient, ListStepsRequest listStepsRequest) {
    MockEmrJobFlow cluster = getClusterById(listStepsRequest.getClusterId());
    if (cluster == null) {
        throw new AmazonServiceException("No cluster found with jobFlowId: " + listStepsRequest.getClusterId());
    }
    List<StepSummary> steps = new ArrayList<>();
    // Add steps that are in these states
    for (MockEmrJobFlow step : cluster.getSteps()) {
        if ((listStepsRequest.getStepStates() == null || listStepsRequest.getStepStates().isEmpty()) || listStepsRequest.getStepStates().contains(step.getStatus())) {
            StepSummary stepSummary = new StepSummary().withId(step.getJobFlowId()).withName(step.getJobFlowName()).withStatus(new StepStatus().withState(step.getStatus())).withConfig(new HadoopStepConfig().withJar(step.getJarLocation()));
            steps.add(stepSummary);
        }
    }
    return new ListStepsResult().withSteps(steps);
}
Also used : ListStepsResult(com.amazonaws.services.elasticmapreduce.model.ListStepsResult) StepSummary(com.amazonaws.services.elasticmapreduce.model.StepSummary) AmazonServiceException(com.amazonaws.AmazonServiceException) ArrayList(java.util.ArrayList) StepStatus(com.amazonaws.services.elasticmapreduce.model.StepStatus) HadoopStepConfig(com.amazonaws.services.elasticmapreduce.model.HadoopStepConfig)

Example 5 with ListStepsResult

use of com.amazonaws.services.elasticmapreduce.model.ListStepsResult in project herd by FINRAOS.

the class EmrDaoTest method getClusterActiveStepAssertCallListStepsAndReturnStepSummary.

@Test
public void getClusterActiveStepAssertCallListStepsAndReturnStepSummary() throws Exception {
    String clusterId = "clusterId";
    StepSummary expectedStepSummary = new StepSummary();
    when(mockEmrOperations.listStepsRequest(any(), any())).then(new Answer<ListStepsResult>() {

        @Override
        public ListStepsResult answer(InvocationOnMock invocation) throws Throwable {
            ListStepsRequest listStepsRequest = invocation.getArgument(1);
            assertEquals(clusterId, listStepsRequest.getClusterId());
            assertEquals(1, listStepsRequest.getStepStates().size());
            assertEquals(StepState.RUNNING.toString(), listStepsRequest.getStepStates().get(0));
            ListStepsResult listStepsResult = new ListStepsResult();
            listStepsResult.setSteps(new ArrayList<>());
            listStepsResult.getSteps().add(expectedStepSummary);
            return listStepsResult;
        }
    });
    assertEquals(expectedStepSummary, emrDao.getClusterActiveStep(clusterId, new AwsParamsDto()));
}
Also used : ListStepsResult(com.amazonaws.services.elasticmapreduce.model.ListStepsResult) AwsParamsDto(org.finra.herd.model.dto.AwsParamsDto) StepSummary(com.amazonaws.services.elasticmapreduce.model.StepSummary) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ArrayList(java.util.ArrayList) ListStepsRequest(com.amazonaws.services.elasticmapreduce.model.ListStepsRequest) Test(org.junit.Test)

Aggregations

ListStepsResult (com.amazonaws.services.elasticmapreduce.model.ListStepsResult)5 StepSummary (com.amazonaws.services.elasticmapreduce.model.StepSummary)4 Test (org.junit.Test)4 AwsParamsDto (org.finra.herd.model.dto.AwsParamsDto)3 ListStepsRequest (com.amazonaws.services.elasticmapreduce.model.ListStepsRequest)2 ArrayList (java.util.ArrayList)2 AmazonServiceException (com.amazonaws.AmazonServiceException)1 HadoopStepConfig (com.amazonaws.services.elasticmapreduce.model.HadoopStepConfig)1 StepStatus (com.amazonaws.services.elasticmapreduce.model.StepStatus)1 EmrCluster (org.finra.herd.model.api.xml.EmrCluster)1 EmrClusterCreateRequest (org.finra.herd.model.api.xml.EmrClusterCreateRequest)1 EmrClusterDefinition (org.finra.herd.model.api.xml.EmrClusterDefinition)1 EmrHadoopJarStep (org.finra.herd.model.api.xml.EmrHadoopJarStep)1 HadoopJarStep (org.finra.herd.model.api.xml.HadoopJarStep)1 NamespaceEntity (org.finra.herd.model.jpa.NamespaceEntity)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1