Search in sources :

Example 21 with AwsParamsDto

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

the class EmrDaoTest method getEmrClusterByIdAssertReturnNullWhenDescribeClusterResponseClusterIsNull.

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

Example 22 with AwsParamsDto

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

the class EmrDaoTest method getClusterStepAssertCallsDescribeStepAndReturnsStep.

@Test
public void getClusterStepAssertCallsDescribeStepAndReturnsStep() throws Exception {
    String clusterId = "clusterId";
    String stepId = "stepId";
    Step expectedStep = new Step();
    when(mockEmrOperations.describeStepRequest(any(), any())).then(new Answer<DescribeStepResult>() {

        @Override
        public DescribeStepResult answer(InvocationOnMock invocation) throws Throwable {
            DescribeStepRequest describeStepRequest = invocation.getArgument(1);
            assertEquals(clusterId, describeStepRequest.getClusterId());
            assertEquals(stepId, describeStepRequest.getStepId());
            DescribeStepResult describeStepResult = new DescribeStepResult();
            describeStepResult.setStep(expectedStep);
            return describeStepResult;
        }
    });
    assertEquals(expectedStep, emrDao.getClusterStep(clusterId, stepId, new AwsParamsDto()));
}
Also used : AwsParamsDto(org.finra.herd.model.dto.AwsParamsDto) DescribeStepResult(com.amazonaws.services.elasticmapreduce.model.DescribeStepResult) DescribeStepRequest(com.amazonaws.services.elasticmapreduce.model.DescribeStepRequest) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Step(com.amazonaws.services.elasticmapreduce.model.Step) HadoopJarStep(org.finra.herd.model.api.xml.HadoopJarStep) Test(org.junit.Test)

Example 23 with AwsParamsDto

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

the class EmrDaoTest method getActiveEmrClusterByNameAssertUsesListMarker.

@Test
public void getActiveEmrClusterByNameAssertUsesListMarker() throws Exception {
    String clusterName = "clusterName";
    String expectedClusterId = "clusterId";
    when(mockEmrOperations.listEmrClusters(any(), any())).then(new Answer<ListClustersResult>() {

        @Override
        public ListClustersResult answer(InvocationOnMock invocation) throws Throwable {
            ListClustersRequest listClustersRequest = invocation.getArgument(1);
            String marker = listClustersRequest.getMarker();
            ListClustersResult listClustersResult = new ListClustersResult();
            listClustersResult.setClusters(new ArrayList<>());
            /*
                 * When no marker is given, this is the request for the first page.
                 * Return a known marker. The expectation is that the next call to this method should have a request with this expected marker.
                 */
            if (marker == null) {
                listClustersResult.setMarker("pagination_marker");
            } else /*
                 * When a marker is given, this is expected to be the subsequent call.
                 */
            {
                // Assert that the correct marker is passed in
                assertEquals("pagination_marker", marker);
                ClusterSummary clusterSummary = new ClusterSummary();
                clusterSummary.setId(expectedClusterId);
                clusterSummary.setName(clusterName);
                listClustersResult.getClusters().add(clusterSummary);
            }
            return listClustersResult;
        }
    });
    ClusterSummary result = emrDao.getActiveEmrClusterByName(clusterName, new AwsParamsDto());
    assertNotNull(result);
    assertEquals(expectedClusterId, result.getId());
}
Also used : AwsParamsDto(org.finra.herd.model.dto.AwsParamsDto) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ClusterSummary(com.amazonaws.services.elasticmapreduce.model.ClusterSummary) ArrayList(java.util.ArrayList) ListClustersRequest(com.amazonaws.services.elasticmapreduce.model.ListClustersRequest) ListClustersResult(com.amazonaws.services.elasticmapreduce.model.ListClustersResult) Test(org.junit.Test)

Example 24 with AwsParamsDto

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

the class EmrDaoTest method terminateEmrCluster.

@Test
public void terminateEmrCluster() throws Exception {
    String clusterName = "clusterName";
    boolean overrideTerminationProtection = false;
    String clusterId = "clusterId";
    ListClustersResult listClustersResult = new ListClustersResult();
    listClustersResult.setClusters(new ArrayList<>());
    ClusterSummary clusterSummary = new ClusterSummary();
    clusterSummary.setId(clusterId);
    clusterSummary.setName(clusterName);
    listClustersResult.getClusters().add(clusterSummary);
    when(mockEmrOperations.listEmrClusters(any(), any())).thenReturn(listClustersResult);
    emrDao.terminateEmrCluster(clusterId, overrideTerminationProtection, new AwsParamsDto());
    // Assert that terminateEmrCluster was called with these parameters ONCE
    verify(mockEmrOperations).terminateEmrCluster(any(), eq(clusterId), eq(overrideTerminationProtection));
}
Also used : AwsParamsDto(org.finra.herd.model.dto.AwsParamsDto) ClusterSummary(com.amazonaws.services.elasticmapreduce.model.ClusterSummary) ListClustersResult(com.amazonaws.services.elasticmapreduce.model.ListClustersResult) Test(org.junit.Test)

Example 25 with AwsParamsDto

use of org.finra.herd.model.dto.AwsParamsDto 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)

Aggregations

AwsParamsDto (org.finra.herd.model.dto.AwsParamsDto)67 Test (org.junit.Test)52 InvocationOnMock (org.mockito.invocation.InvocationOnMock)13 ClusterSummary (com.amazonaws.services.elasticmapreduce.model.ClusterSummary)11 ClientConfiguration (com.amazonaws.ClientConfiguration)9 ArrayList (java.util.ArrayList)9 ListClustersResult (com.amazonaws.services.elasticmapreduce.model.ListClustersResult)8 AbstractDaoTest (org.finra.herd.dao.AbstractDaoTest)8 EmrClusterDefinition (org.finra.herd.model.api.xml.EmrClusterDefinition)7 AmazonElasticMapReduceClient (com.amazonaws.services.elasticmapreduce.AmazonElasticMapReduceClient)6 AmazonServiceException (com.amazonaws.AmazonServiceException)5 RunJobFlowRequest (com.amazonaws.services.elasticmapreduce.model.RunJobFlowRequest)5 NodeTag (org.finra.herd.model.api.xml.NodeTag)5 EmrClusterDefinitionEntity (org.finra.herd.model.jpa.EmrClusterDefinitionEntity)5 NamespaceEntity (org.finra.herd.model.jpa.NamespaceEntity)5 Cluster (com.amazonaws.services.elasticmapreduce.model.Cluster)4 DescribeClusterResult (com.amazonaws.services.elasticmapreduce.model.DescribeClusterResult)4 ListInstancesResult (com.amazonaws.services.elasticmapreduce.model.ListInstancesResult)4 List (java.util.List)4 InstanceDefinitions (org.finra.herd.model.api.xml.InstanceDefinitions)4