Search in sources :

Example 6 with ListClustersResult

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

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

the class MockEmrOperationsImpl method listEmrClusters.

@Override
public ListClustersResult listEmrClusters(AmazonElasticMapReduceClient emrClient, ListClustersRequest listClustersRequest) {
    List<ClusterSummary> clusterSummaryList = new ArrayList<>();
    for (MockEmrJobFlow cluster : emrClusters.values()) {
        if (!listClustersRequest.getClusterStates().isEmpty() && listClustersRequest.getClusterStates().contains(cluster.getStatus())) {
            ClusterSummary clusterSummary = new ClusterSummary();
            clusterSummary.withId(cluster.getJobFlowId()).withName(cluster.getJobFlowName()).withStatus(new ClusterStatus().withState(cluster.getStatus()).withStateChangeReason(new ClusterStateChangeReason().withCode(cluster.getStatusChangeReason().getCode()).withMessage(cluster.getStatusChangeReason().getMessage())).withTimeline(new ClusterTimeline().withCreationDateTime(cluster.getStatusTimeline().getCreationTime() != null ? cluster.getStatusTimeline().getCreationTime().toGregorianCalendar().getTime() : null).withEndDateTime(cluster.getStatusTimeline().getEndTime() != null ? cluster.getStatusTimeline().getEndTime().toGregorianCalendar().getTime() : null).withReadyDateTime(cluster.getStatusTimeline().getReadyTime() != null ? cluster.getStatusTimeline().getReadyTime().toGregorianCalendar().getTime() : null)));
            clusterSummaryList.add(clusterSummary);
        }
    }
    if (StringUtils.isBlank(listClustersRequest.getMarker())) {
        return new ListClustersResult().withClusters(clusterSummaryList).withMarker(MOCK_EMR_MAKER);
    } else {
        return new ListClustersResult().withClusters(clusterSummaryList);
    }
}
Also used : ClusterStateChangeReason(com.amazonaws.services.elasticmapreduce.model.ClusterStateChangeReason) ClusterSummary(com.amazonaws.services.elasticmapreduce.model.ClusterSummary) ArrayList(java.util.ArrayList) ListClustersResult(com.amazonaws.services.elasticmapreduce.model.ListClustersResult) ClusterStatus(com.amazonaws.services.elasticmapreduce.model.ClusterStatus) ClusterTimeline(com.amazonaws.services.elasticmapreduce.model.ClusterTimeline)

Example 8 with ListClustersResult

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

the class EmrDaoTest method addEmrMasterSecurityGroupsCallsEc2AddSecurityGroup.

@Test
public void addEmrMasterSecurityGroupsCallsEc2AddSecurityGroup() throws Exception {
    String clusterName = "clusterName";
    List<String> securityGroups = Arrays.asList("securityGroup");
    AwsParamsDto awsParams = new AwsParamsDto();
    String ec2InstanceId = "ec2InstanceId";
    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);
    ListInstancesResult listInstancesResult = new ListInstancesResult();
    listInstancesResult.setInstances(new ArrayList<>());
    Instance instance = new Instance();
    instance.setEc2InstanceId(ec2InstanceId);
    listInstancesResult.getInstances().add(instance);
    when(mockEmrOperations.listClusterInstancesRequest(any(), any())).thenReturn(listInstancesResult);
    emrDao.addEmrMasterSecurityGroups(clusterName, securityGroups, awsParams);
    verify(mockEc2Dao).addSecurityGroupsToEc2Instance(eq(ec2InstanceId), eq(securityGroups), any());
    verifyNoMoreInteractions(mockEc2Dao);
}
Also used : AwsParamsDto(org.finra.herd.model.dto.AwsParamsDto) ListInstancesResult(com.amazonaws.services.elasticmapreduce.model.ListInstancesResult) Instance(com.amazonaws.services.elasticmapreduce.model.Instance) ClusterSummary(com.amazonaws.services.elasticmapreduce.model.ClusterSummary) ListClustersResult(com.amazonaws.services.elasticmapreduce.model.ListClustersResult) Test(org.junit.Test)

Example 9 with ListClustersResult

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

the class EmrDaoTest method getActiveEmrClusterByNameAssertReturnNullWhenClusterNameIsBlank.

@Test
public void getActiveEmrClusterByNameAssertReturnNullWhenClusterNameIsBlank() throws Exception {
    String clusterName = "";
    when(mockEmrOperations.listEmrClusters(any(), any())).thenReturn(new ListClustersResult());
    assertNull(emrDao.getActiveEmrClusterByName(clusterName, new AwsParamsDto()));
}
Also used : AwsParamsDto(org.finra.herd.model.dto.AwsParamsDto) ListClustersResult(com.amazonaws.services.elasticmapreduce.model.ListClustersResult) Test(org.junit.Test)

Example 10 with ListClustersResult

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

the class EmrDaoTest method getActiveEmrClusterByNameAssertOnlyReturnClusterWithMatchingName.

@Test
public void getActiveEmrClusterByNameAssertOnlyReturnClusterWithMatchingName() throws Exception {
    String clusterName = "clusterName";
    String expectedClusterId = "clusterId3";
    ListClustersResult listClustersResult = new ListClustersResult();
    listClustersResult.setClusters(new ArrayList<>());
    {
        ClusterSummary clusterSummary = new ClusterSummary();
        clusterSummary.setId("clusterId1");
        clusterSummary.setName("not_matching");
        listClustersResult.getClusters().add(clusterSummary);
    }
    {
        ClusterSummary clusterSummary = new ClusterSummary();
        clusterSummary.setId("clusterId2");
        clusterSummary.setName("");
        listClustersResult.getClusters().add(clusterSummary);
    }
    {
        ClusterSummary clusterSummary = new ClusterSummary();
        clusterSummary.setId(expectedClusterId);
        clusterSummary.setName(clusterName);
        listClustersResult.getClusters().add(clusterSummary);
    }
    when(mockEmrOperations.listEmrClusters(any(), any())).thenReturn(listClustersResult);
    ClusterSummary result = emrDao.getActiveEmrClusterByName(clusterName, new AwsParamsDto());
    assertNotNull(result);
    assertEquals(expectedClusterId, result.getId());
}
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