Search in sources :

Example 1 with ListClustersRequest

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

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

use of com.amazonaws.services.elasticmapreduce.model.ListClustersRequest in project iep by Netflix.

the class PaginationTest method emr.

@Test
public void emr() throws Exception {
    SortedSet<String> pages = newPageSet(5);
    final Iterator<String> reqIt = pages.iterator();
    final Iterator<String> resIt = pages.iterator();
    Function<ListClustersRequest, ListClustersResult> f = r -> {
        if (r.getMarker() != null) {
            Assert.assertEquals(reqIt.next(), r.getMarker());
        }
        return new ListClustersResult().withMarker(resIt.hasNext() ? resIt.next() : null);
    };
    Publisher<ListClustersResult> publisher = Pagination.createPublisher(new ListClustersRequest(), f);
    Iterable<String> iter = Flowable.fromPublisher(publisher).filter(r -> r.getMarker() != null).map(ListClustersResult::getMarker).blockingIterable();
    SortedSet<String> results = new TreeSet<>();
    for (String s : iter) {
        results.add(s);
    }
    Assert.assertEquals(pages, results);
    Assert.assertFalse(reqIt.hasNext());
}
Also used : ListHostedZonesResult(com.amazonaws.services.route53.model.ListHostedZonesResult) ListMetricsRequest(com.amazonaws.services.cloudwatch.model.ListMetricsRequest) SortedSet(java.util.SortedSet) ScanResult(com.amazonaws.services.dynamodbv2.model.ScanResult) RunWith(org.junit.runner.RunWith) HashMap(java.util.HashMap) ListMetricsResult(com.amazonaws.services.cloudwatch.model.ListMetricsResult) DescribeLoadBalancersRequest(com.amazonaws.services.elasticloadbalancing.model.DescribeLoadBalancersRequest) Function(java.util.function.Function) TreeSet(java.util.TreeSet) PutMetricDataRequest(com.amazonaws.services.cloudwatch.model.PutMetricDataRequest) DescribeTargetGroupsRequest(com.amazonaws.services.elasticloadbalancingv2.model.DescribeTargetGroupsRequest) Flowable(io.reactivex.Flowable) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AttributeValue(com.amazonaws.services.dynamodbv2.model.AttributeValue) DescribeInstancesRequest(com.amazonaws.services.ec2.model.DescribeInstancesRequest) Map(java.util.Map) DescribeAutoScalingGroupsResult(com.amazonaws.services.autoscaling.model.DescribeAutoScalingGroupsResult) ListClustersResult(com.amazonaws.services.elasticmapreduce.model.ListClustersResult) DescribeTargetGroupsResult(com.amazonaws.services.elasticloadbalancingv2.model.DescribeTargetGroupsResult) Iterator(java.util.Iterator) ScanRequest(com.amazonaws.services.dynamodbv2.model.ScanRequest) Publisher(org.reactivestreams.Publisher) DescribeInstancesResult(com.amazonaws.services.ec2.model.DescribeInstancesResult) Test(org.junit.Test) JUnit4(org.junit.runners.JUnit4) DescribeAutoScalingGroupsRequest(com.amazonaws.services.autoscaling.model.DescribeAutoScalingGroupsRequest) ListResourceRecordSetsResult(com.amazonaws.services.route53.model.ListResourceRecordSetsResult) ListHostedZonesRequest(com.amazonaws.services.route53.model.ListHostedZonesRequest) ListClustersRequest(com.amazonaws.services.elasticmapreduce.model.ListClustersRequest) DescribeLoadBalancersResult(com.amazonaws.services.elasticloadbalancing.model.DescribeLoadBalancersResult) PutMetricDataResult(com.amazonaws.services.cloudwatch.model.PutMetricDataResult) Assert(org.junit.Assert) ListResourceRecordSetsRequest(com.amazonaws.services.route53.model.ListResourceRecordSetsRequest) TreeSet(java.util.TreeSet) ListClustersRequest(com.amazonaws.services.elasticmapreduce.model.ListClustersRequest) ListClustersResult(com.amazonaws.services.elasticmapreduce.model.ListClustersResult) Test(org.junit.Test)

Example 4 with ListClustersRequest

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

the class EmrDaoImpl method getActiveEmrClusterByName.

@Override
public ClusterSummary getActiveEmrClusterByName(String clusterName, AwsParamsDto awsParams) {
    if (StringUtils.isNotBlank(clusterName)) {
        /**
         * Call AWSOperations for ListClusters API. Need to list all the active clusters that are in
         * BOOTSTRAPPING/RUNNING/STARTING/WAITING states
         */
        ListClustersRequest listClustersRequest = new ListClustersRequest().withClusterStates(getActiveEmrClusterStates());
        /**
         * ListClusterRequest returns only 50 clusters at a time. However, this returns a marker
         * that can be used for subsequent calls to listClusters to get all the clusters
         */
        String markerForListClusters = listClustersRequest.getMarker();
        // Loop through all the available clusters and look for the given cluster id
        do {
            /**
             * Call AWSOperations for ListClusters API.
             * Need to include the Marker returned by the previous iteration
             */
            ListClustersResult clusterResult = emrOperations.listEmrClusters(getEmrClient(awsParams), listClustersRequest.withMarker(markerForListClusters));
            // Loop through all the active clusters returned by AWS
            for (ClusterSummary clusterInstance : clusterResult.getClusters()) {
                // If the cluster name matches, then return the status
                if (StringUtils.isNotBlank(clusterInstance.getName()) && clusterInstance.getName().equalsIgnoreCase(clusterName)) {
                    return clusterInstance;
                }
            }
            markerForListClusters = clusterResult.getMarker();
        } while (markerForListClusters != null);
    }
    return null;
}
Also used : ClusterSummary(com.amazonaws.services.elasticmapreduce.model.ClusterSummary) ListClustersRequest(com.amazonaws.services.elasticmapreduce.model.ListClustersRequest) ListClustersResult(com.amazonaws.services.elasticmapreduce.model.ListClustersResult)

Aggregations

ListClustersRequest (com.amazonaws.services.elasticmapreduce.model.ListClustersRequest)4 ListClustersResult (com.amazonaws.services.elasticmapreduce.model.ListClustersResult)4 ClusterSummary (com.amazonaws.services.elasticmapreduce.model.ClusterSummary)3 Test (org.junit.Test)3 AwsParamsDto (org.finra.herd.model.dto.AwsParamsDto)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 DescribeLoadBalancersResult (com.amazonaws.services.elasticloadbalancing.model.DescribeLoadBalancersResult)1 DescribeTargetGroupsRequest (com.amazonaws.services.elasticloadbalancingv2.model.DescribeTargetGroupsRequest)1 DescribeTargetGroupsResult (com.amazonaws.services.elasticloadbalancingv2.model.DescribeTargetGroupsResult)1