Search in sources :

Example 1 with ListClustersResult

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

the class EmrDaoImplTest method testGetActiveEmrClusterByName.

@Test
public void testGetActiveEmrClusterByName() {
    // Create an AWS parameters DTO.
    AwsParamsDto awsParamsDto = new AwsParamsDto(AWS_ASSUMED_ROLE_ACCESS_KEY, AWS_ASSUMED_ROLE_SECRET_KEY, AWS_ASSUMED_ROLE_SESSION_TOKEN, HTTP_PROXY_HOST, HTTP_PROXY_PORT);
    // Create a mock AmazonElasticMapReduceClient.
    AmazonElasticMapReduceClient amazonElasticMapReduceClient = mock(AmazonElasticMapReduceClient.class);
    // Create a list cluster request.
    ListClustersRequest listClustersRequest = new ListClustersRequest().withClusterStates(EMR_VALID_STATE);
    // Create a list cluster result with a non-matching cluster and a marker.
    ListClustersResult listClusterResultWithMarker = new ListClustersResult().withClusters(new ClusterSummary().withName(INVALID_VALUE)).withMarker(MARKER);
    // Create a list cluster request with marker.
    ListClustersRequest listClustersRequestWithMarker = new ListClustersRequest().withClusterStates(EMR_VALID_STATE).withMarker(MARKER);
    // Create a cluster summary.
    ClusterSummary clusterSummary = new ClusterSummary().withName(EMR_CLUSTER_NAME);
    // Create a list cluster result with the matching cluster.
    ListClustersResult listClusterResult = new ListClustersResult().withClusters(clusterSummary);
    // Mock the external calls.
    when(configurationHelper.getProperty(ConfigurationValue.EMR_VALID_STATES)).thenReturn(EMR_VALID_STATE);
    when(configurationHelper.getProperty(ConfigurationValue.FIELD_DATA_DELIMITER)).thenReturn((String) ConfigurationValue.FIELD_DATA_DELIMITER.getDefaultValue());
    when(awsClientFactory.getEmrClient(awsParamsDto)).thenReturn(amazonElasticMapReduceClient);
    when(emrOperations.listEmrClusters(amazonElasticMapReduceClient, listClustersRequest)).thenReturn(listClusterResultWithMarker);
    when(emrOperations.listEmrClusters(amazonElasticMapReduceClient, listClustersRequestWithMarker)).thenReturn(listClusterResult);
    // Call the method under test.
    ClusterSummary result = emrDaoImpl.getActiveEmrClusterByName(EMR_CLUSTER_NAME, awsParamsDto);
    // Verify the external calls.
    verify(configurationHelper).getProperty(ConfigurationValue.EMR_VALID_STATES);
    verify(configurationHelper).getProperty(ConfigurationValue.FIELD_DATA_DELIMITER);
    verify(awsClientFactory, times(2)).getEmrClient(awsParamsDto);
    verify(emrOperations, times(2)).listEmrClusters(eq(amazonElasticMapReduceClient), any(ListClustersRequest.class));
    verifyNoMoreInteractionsHelper();
    // Validate the results.
    assertEquals(clusterSummary, result);
}
Also used : AwsParamsDto(org.finra.herd.model.dto.AwsParamsDto) ClusterSummary(com.amazonaws.services.elasticmapreduce.model.ClusterSummary) AmazonElasticMapReduceClient(com.amazonaws.services.elasticmapreduce.AmazonElasticMapReduceClient) ListClustersRequest(com.amazonaws.services.elasticmapreduce.model.ListClustersRequest) ListClustersResult(com.amazonaws.services.elasticmapreduce.model.ListClustersResult) Test(org.junit.Test) AbstractDaoTest(org.finra.herd.dao.AbstractDaoTest)

Example 2 with ListClustersResult

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

the class EmrDaoTest method addEmrMasterSecurityGroupsThrowWhenNoInstancesFound.

@Test
public void addEmrMasterSecurityGroupsThrowWhenNoInstancesFound() throws Exception {
    String clusterName = "clusterName";
    List<String> securityGroups = Arrays.asList("securityGroup");
    AwsParamsDto awsParams = new AwsParamsDto();
    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);
    when(mockEmrOperations.listClusterInstancesRequest(any(), any())).thenReturn(new ListInstancesResult());
    try {
        emrDao.addEmrMasterSecurityGroups(clusterName, securityGroups, awsParams);
        fail();
    } catch (Exception e) {
        assertEquals(IllegalArgumentException.class, e.getClass());
        assertEquals("No master instances found for the cluster \"" + clusterName + "\".", e.getMessage());
    }
}
Also used : AwsParamsDto(org.finra.herd.model.dto.AwsParamsDto) ListInstancesResult(com.amazonaws.services.elasticmapreduce.model.ListInstancesResult) ClusterSummary(com.amazonaws.services.elasticmapreduce.model.ClusterSummary) ListClustersResult(com.amazonaws.services.elasticmapreduce.model.ListClustersResult) Test(org.junit.Test)

Example 3 with ListClustersResult

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

the class EmrDaoTest method addEmrStepCallsAddJobFlowSteps.

@Test
public void addEmrStepCallsAddJobFlowSteps() throws Exception {
    String clusterName = "clusterName";
    StepConfig emrStepConfig = new StepConfig();
    String clusterId = "clusterId";
    String stepId = "stepId";
    /*
         * Mock the EmrOperations.listEmrClusters() call to return a known result.
         */
    ListClustersResult listClustersResult = new ListClustersResult();
    ClusterSummary clusterSummary = new ClusterSummary();
    clusterSummary.setId(clusterId);
    clusterSummary.setName(clusterName);
    listClustersResult.setClusters(Arrays.asList(clusterSummary));
    when(mockEmrOperations.listEmrClusters(any(), any())).thenReturn(listClustersResult);
    /*
         * Mock EmrOperations.addJobFlowStepsRequest() and assert parameters passed in.
         */
    when(mockEmrOperations.addJobFlowStepsRequest(any(), any())).thenAnswer(new Answer<List<String>>() {

        @Override
        public List<String> answer(InvocationOnMock invocation) throws Throwable {
            AddJobFlowStepsRequest addJobFlowStepsRequest = invocation.getArgument(1);
            assertEquals(clusterId, addJobFlowStepsRequest.getJobFlowId());
            List<StepConfig> steps = addJobFlowStepsRequest.getSteps();
            assertEquals(1, steps.size());
            assertEquals(emrStepConfig, steps.get(0));
            // return a single step with the given stepId
            return Arrays.asList(stepId);
        }
    });
    assertEquals(stepId, emrDao.addEmrStep(clusterId, emrStepConfig, new AwsParamsDto()));
}
Also used : AwsParamsDto(org.finra.herd.model.dto.AwsParamsDto) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ClusterSummary(com.amazonaws.services.elasticmapreduce.model.ClusterSummary) StepConfig(com.amazonaws.services.elasticmapreduce.model.StepConfig) List(java.util.List) ArrayList(java.util.ArrayList) ListClustersResult(com.amazonaws.services.elasticmapreduce.model.ListClustersResult) AddJobFlowStepsRequest(com.amazonaws.services.elasticmapreduce.model.AddJobFlowStepsRequest) Test(org.junit.Test)

Example 4 with ListClustersResult

use of com.amazonaws.services.elasticmapreduce.model.ListClustersResult 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 5 with ListClustersResult

use of com.amazonaws.services.elasticmapreduce.model.ListClustersResult 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)

Aggregations

ListClustersResult (com.amazonaws.services.elasticmapreduce.model.ListClustersResult)11 ClusterSummary (com.amazonaws.services.elasticmapreduce.model.ClusterSummary)9 Test (org.junit.Test)9 AwsParamsDto (org.finra.herd.model.dto.AwsParamsDto)8 ListClustersRequest (com.amazonaws.services.elasticmapreduce.model.ListClustersRequest)4 ArrayList (java.util.ArrayList)3 ListInstancesResult (com.amazonaws.services.elasticmapreduce.model.ListInstancesResult)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 DescribeAutoScalingGroupsRequest (com.amazonaws.services.autoscaling.model.DescribeAutoScalingGroupsRequest)1 DescribeAutoScalingGroupsResult (com.amazonaws.services.autoscaling.model.DescribeAutoScalingGroupsResult)1 ListMetricsRequest (com.amazonaws.services.cloudwatch.model.ListMetricsRequest)1 ListMetricsResult (com.amazonaws.services.cloudwatch.model.ListMetricsResult)1 PutMetricDataRequest (com.amazonaws.services.cloudwatch.model.PutMetricDataRequest)1 PutMetricDataResult (com.amazonaws.services.cloudwatch.model.PutMetricDataResult)1 AttributeValue (com.amazonaws.services.dynamodbv2.model.AttributeValue)1 ScanRequest (com.amazonaws.services.dynamodbv2.model.ScanRequest)1 ScanResult (com.amazonaws.services.dynamodbv2.model.ScanResult)1 DescribeInstancesRequest (com.amazonaws.services.ec2.model.DescribeInstancesRequest)1 DescribeInstancesResult (com.amazonaws.services.ec2.model.DescribeInstancesResult)1 DescribeLoadBalancersRequest (com.amazonaws.services.elasticloadbalancing.model.DescribeLoadBalancersRequest)1