Search in sources :

Example 1 with ClusterSummary

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

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

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

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

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

ClusterSummary (com.amazonaws.services.elasticmapreduce.model.ClusterSummary)15 AwsParamsDto (org.finra.herd.model.dto.AwsParamsDto)11 Test (org.junit.Test)10 ListClustersResult (com.amazonaws.services.elasticmapreduce.model.ListClustersResult)9 ListClustersRequest (com.amazonaws.services.elasticmapreduce.model.ListClustersRequest)3 ArrayList (java.util.ArrayList)3 AbstractDaoTest (org.finra.herd.dao.AbstractDaoTest)3 AmazonServiceException (com.amazonaws.AmazonServiceException)2 Cluster (com.amazonaws.services.elasticmapreduce.model.Cluster)2 ListInstancesResult (com.amazonaws.services.elasticmapreduce.model.ListInstancesResult)2 EmrClusterDefinition (org.finra.herd.model.api.xml.EmrClusterDefinition)2 EmrClusterDefinitionEntity (org.finra.herd.model.jpa.EmrClusterDefinitionEntity)2 NamespaceEntity (org.finra.herd.model.jpa.NamespaceEntity)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 AmazonElasticMapReduceClient (com.amazonaws.services.elasticmapreduce.AmazonElasticMapReduceClient)1 AddJobFlowStepsRequest (com.amazonaws.services.elasticmapreduce.model.AddJobFlowStepsRequest)1 ClusterStateChangeReason (com.amazonaws.services.elasticmapreduce.model.ClusterStateChangeReason)1 ClusterStatus (com.amazonaws.services.elasticmapreduce.model.ClusterStatus)1 ClusterTimeline (com.amazonaws.services.elasticmapreduce.model.ClusterTimeline)1 Instance (com.amazonaws.services.elasticmapreduce.model.Instance)1