Search in sources :

Example 11 with ListClustersResult

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

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