com.amazonaws.services.elasticmapreduce.model.ListClustersRequest Java Examples
The following examples show how to use
com.amazonaws.services.elasticmapreduce.model.ListClustersRequest.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EmrClusterTableProvider.java From aws-athena-query-federation with Apache License 2.0 | 6 votes |
/** * Calls ListClusters and DescribeCluster on the AWS EMR Client returning all clusters that match the supplied * predicate and attempting to push down certain predicates (namely queries for specific cluster) to EC2. * * @See TableProvider */ @Override public void readWithConstraint(BlockSpiller spiller, ReadRecordsRequest recordsRequest, QueryStatusChecker queryStatusChecker) { boolean done = false; ListClustersRequest request = new ListClustersRequest(); while (!done) { ListClustersResult response = emr.listClusters(request); for (ClusterSummary next : response.getClusters()) { Cluster cluster = null; if (!next.getStatus().getState().toLowerCase().contains("terminated")) { DescribeClusterResult clusterResponse = emr.describeCluster(new DescribeClusterRequest().withClusterId(next.getId())); cluster = clusterResponse.getCluster(); } clusterToRow(next, cluster, spiller); } request.setMarker(response.getMarker()); if (response.getMarker() == null || !queryStatusChecker.isQueryRunning()) { done = true; } } }
Example #2
Source File: CloudFormationClient.java From herd-mdl with Apache License 2.0 | 6 votes |
public List<ClusterSummary> getStackClustersSummary(AmazonElasticMapReduce amazonElasticMapReduce, List<String> stackClusterIds, CFTStackInfo cftStackInfo) { List<ClusterSummary> stackClustersSummary = new ArrayList<>(); ListClustersRequest listClustersRequest = new ListClustersRequest(); //Only get clusters that got created after we setup our stack listClustersRequest.setCreatedAfter(cftStackInfo.creationTime()); ListClustersResult listClustersResult = amazonElasticMapReduce .listClusters(listClustersRequest); while (true) { for (ClusterSummary cluster : listClustersResult.getClusters()) { if (stackClusterIds.contains(cluster.getId())) { stackClustersSummary.add(cluster); } } if (listClustersResult.getMarker() != null) { listClustersRequest.setMarker(listClustersResult.getMarker()); listClustersResult = amazonElasticMapReduce.listClusters(listClustersRequest); } else { break; } } return stackClustersSummary; }
Example #3
Source File: LambdaContainer.java From aws-big-data-blog with Apache License 2.0 | 6 votes |
protected List<String> getActiveTaggedClusters() throws Exception{ AmazonElasticMapReduceClient emrClient = new AmazonElasticMapReduceClient(); List<String> waitingClusters = new ArrayList<String>(); ListClustersResult clusterResult = emrClient.listClusters(new ListClustersRequest().withClusterStates(ClusterState.WAITING)); DescribeClusterRequest specifcTagDescribe = new DescribeClusterRequest(); specifcTagDescribe.putCustomQueryParameter("Cluster.Tags",null); for( ClusterSummary cluster : clusterResult.getClusters()){ System.out.println("list cluster id "+cluster.getId()); List<Tag> tagList = emrClient.describeCluster(specifcTagDescribe.withClusterId(cluster.getId())).getCluster().getTags(); for(Tag tag:tagList){ if(tag.getKey().equals(props.getProperty("edba.cluster.tag.key"))){ waitingClusters.add(cluster.getId()); } } } return waitingClusters; }
Example #4
Source File: InventoryUtil.java From pacbot with Apache License 2.0 | 5 votes |
/** * Fetch EMR info. * * @param temporaryCredentials the temporary credentials * @param skipRegions the skip regions * @param accountId the accountId * @param accountName the account name * @return the map */ public static Map<String,List<Cluster>> fetchEMRInfo(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName){ Map<String,List<Cluster>> clusterList = new LinkedHashMap<>(); String expPrefix = InventoryConstants.ERROR_PREFIX_CODE+accountId + "\",\"Message\": \"Exception in fetching info for resource in specific region\" ,\"type\": \"EMR\" , \"region\":\"" ; for(Region region : RegionUtils.getRegions()){ try{ if(!skipRegions.contains(region.getName())){ AmazonElasticMapReduce emrClient = AmazonElasticMapReduceClientBuilder.standard(). withCredentials(new AWSStaticCredentialsProvider(temporaryCredentials)).withRegion(region.getName()).build(); List<ClusterSummary> clusters = new ArrayList<>(); String marker = null; ListClustersResult clusterResult ; do{ clusterResult = emrClient.listClusters(new ListClustersRequest().withMarker(marker)); clusters.addAll(clusterResult.getClusters()); marker = clusterResult.getMarker(); }while(marker!=null); List<Cluster> clustersList = new ArrayList<>(); clusters.forEach(cluster -> { DescribeClusterResult descClstrRslt = emrClient.describeCluster(new DescribeClusterRequest().withClusterId(cluster.getId())); clustersList.add(descClstrRslt.getCluster()); }); if( !clustersList.isEmpty() ){ log.debug(InventoryConstants.ACCOUNT + accountId +" Type : EMR "+region.getName() + " >> "+clustersList.size()); clusterList.put(accountId+delimiter+accountName+delimiter+region.getName(),clustersList); } } }catch(Exception e){ if(region.isServiceSupported(AmazonElasticMapReduce.ENDPOINT_PREFIX)){ log.warn(expPrefix+ region.getName()+InventoryConstants.ERROR_CAUSE +e.getMessage()+"\"}"); ErrorManageUtil.uploadError(accountId,region.getName(),"emr",e.getMessage()); } } } return clusterList; }
Example #5
Source File: MockEmrOperationsImpl.java From herd with Apache License 2.0 | 5 votes |
@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); } }
Example #6
Source File: EmrClusterJob.java From datacollector with Apache License 2.0 | 5 votes |
@Override public String getActiveCluster(String clusterName) { ListClustersRequest listClustersRequest = new ListClustersRequest().withClusterStates(CLUSTER_ACTIVE_STATES); ListClustersResult result = getEmrClient(emrClusterConfig).listClusters(listClustersRequest); LOG.info("Got clusters " + result.getClusters()); Optional<ClusterSummary> clusterSummary = result.getClusters().stream().filter(cs -> cs.getName().equals( clusterName)).findAny(); if (clusterSummary.isPresent()) { return clusterSummary.get().getId(); } return null; }
Example #7
Source File: TestEmrClusterJob.java From datacollector with Apache License 2.0 | 5 votes |
@Test public void testGetActiveCluster() { Properties properties = new Properties(); EmrClusterJob emrClusterJob = new EmrClusterJob(); EmrClusterJob.Client client = Mockito.spy(emrClusterJob.getClient(properties)); AmazonElasticMapReduce emr = Mockito.mock(AmazonElasticMapReduce.class); Mockito.doReturn(emr).when(client).getEmrClient(Mockito.any(EmrClusterConfig.class)); Mockito.doReturn(Mockito.mock(ListClustersResult.class)).when(emr).listClusters(Mockito.any(ListClustersRequest .class)); client.getActiveCluster("foo"); Mockito.verify(emr, Mockito.times(1)).listClusters(Mockito.any(ListClustersRequest.class)); Mockito.verify(client, Mockito.times(1)).getEmrClient(Mockito.any(EmrClusterConfig.class)); }
Example #8
Source File: EmrOperationsImpl.java From herd with Apache License 2.0 | 4 votes |
/** * List the EMR Clusters in the account */ @Override public ListClustersResult listEmrClusters(AmazonElasticMapReduceClient emrClient, ListClustersRequest listClustersRequest) { return emrClient.listClusters(listClustersRequest); }
Example #9
Source File: EmrDaoTest.java From herd with Apache License 2.0 | 4 votes |
@Test public void getActiveEmrClusterByNameAssertUsesListMarker() { String clusterName = "clusterName"; String expectedClusterId = "clusterId"; when(mockEmrOperations.listEmrClusters(any(), any())).then(new Answer<ListClustersResult>() { @Override public ListClustersResult answer(InvocationOnMock invocation) { 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"); } /* * When a marker is given, this is expected to be the subsequent call. */ else { // 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.getActiveEmrClusterByNameAndAccountId(clusterName, null, getAwsParamsDto()); assertNotNull(result); assertEquals(expectedClusterId, result.getId()); }
Example #10
Source File: EmrDaoImplTest.java From herd with Apache License 2.0 | 4 votes |
@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, AWS_REGION_NAME_US_EAST_1); // 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).withId(EMR_CLUSTER_ID)).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).withId(EMR_CLUSTER_ID); // 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.getActiveEmrClusterByNameAndAccountId(EMR_CLUSTER_NAME, null, 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); }
Example #11
Source File: EmrDaoImplTest.java From herd with Apache License 2.0 | 4 votes |
private void testGetActiveEmrClusterByNameWithTimestamps(EmrClusterCacheTimestamps emrClusterCacheTimestamps, Date createdAfter) { // 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, AWS_REGION_NAME_US_EAST_1); // Create a mock AmazonElasticMapReduceClient. AmazonElasticMapReduceClient amazonElasticMapReduceClient = mock(AmazonElasticMapReduceClient.class); // Create a list cluster request. ListClustersRequest listClustersRequest = new ListClustersRequest().withClusterStates(EMR_VALID_STATE).withCreatedAfter(createdAfter); // Create a list cluster result with a non-matching cluster and a marker. ListClustersResult listClusterResultWithMarker = new ListClustersResult().withClusters(new ClusterSummary().withName(INVALID_VALUE).withId(EMR_CLUSTER_ID)).withMarker(MARKER); // Create a list cluster request with marker. ListClustersRequest listClustersRequestWithMarker = new ListClustersRequest().withClusterStates(EMR_VALID_STATE).withMarker(MARKER).withCreatedAfter(createdAfter); // Create a cluster summary. ClusterSummary clusterSummary = new ClusterSummary().withName(EMR_CLUSTER_NAME).withId(EMR_CLUSTER_ID); // Create a list cluster result with the matching cluster. ListClustersResult listClusterResult = new ListClustersResult().withClusters(clusterSummary); // Mock the external calls. when(emrClusterCacheTimestampsMap.get(EMR_CLUSTER_CACHE_MAP_DEFAULT_AWS_ACCOUNT_ID_KEY)).thenReturn(emrClusterCacheTimestamps); 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.getActiveEmrClusterByNameAndAccountId(EMR_CLUSTER_NAME, null, 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); }
Example #12
Source File: EmrDaoImplTest.java From herd with Apache License 2.0 | 4 votes |
private void getActiveEmrClusterByNameAndAccountIdClusterNameIsInCache(Cluster cluster, String accountId) { // 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, AWS_REGION_NAME_US_EAST_1); // Create a mock AmazonElasticMapReduceClient. AmazonElasticMapReduceClient amazonElasticMapReduceClient = mock(AmazonElasticMapReduceClient.class); // Create a cluster summary. ClusterSummary clusterSummary = new ClusterSummary().withName(EMR_CLUSTER_NAME).withId(EMR_CLUSTER_ID).withStatus(cluster == null ? null : cluster.getStatus()); // Create a list cluster result with the matching cluster. ListClustersResult listClusterResult = new ListClustersResult().withClusters(clusterSummary); // Create a describe cluster result. DescribeClusterResult describeClusterResult = new DescribeClusterResult().withCluster(cluster); // Create a describe cluster request. DescribeClusterRequest describeClusterRequest = new DescribeClusterRequest().withClusterId(EMR_CLUSTER_ID); // Build the EMR cluster cache key EmrClusterCacheKey emrClusterCacheKey = new EmrClusterCacheKey(EMR_CLUSTER_NAME.toUpperCase(), accountId); // Build the EMR cluster cache Map<EmrClusterCacheKey, String> emrClusterCache = new ConcurrentHashMap<>(); emrClusterCache.put(emrClusterCacheKey, EMR_CLUSTER_ID); // Mock the external calls. if (accountId == null) { when(emrClusterCacheMap.get(EMR_CLUSTER_CACHE_MAP_DEFAULT_AWS_ACCOUNT_ID_KEY)).thenReturn(emrClusterCache); } else { when(emrClusterCacheMap.get(accountId)).thenReturn(emrClusterCache); } when(emrOperations.describeClusterRequest(eq(amazonElasticMapReduceClient), any(DescribeClusterRequest.class))).thenReturn(describeClusterResult); when(configurationHelper.getProperty(ConfigurationValue.EMR_VALID_STATES)).thenReturn(ConfigurationValue.EMR_VALID_STATES.getDefaultValue().toString()); when(configurationHelper.getProperty(ConfigurationValue.FIELD_DATA_DELIMITER)) .thenReturn((String) ConfigurationValue.FIELD_DATA_DELIMITER.getDefaultValue()); when(awsClientFactory.getEmrClient(awsParamsDto)).thenReturn(amazonElasticMapReduceClient); when(emrOperations.listEmrClusters(any(AmazonElasticMapReduceClient.class), any(ListClustersRequest.class))).thenReturn(listClusterResult); // Call the method under test. ClusterSummary result = emrDaoImpl.getActiveEmrClusterByNameAndAccountId(EMR_CLUSTER_NAME, accountId, awsParamsDto); // Verify the external calls. verify(emrOperations).describeClusterRequest(eq(amazonElasticMapReduceClient), eq(describeClusterRequest)); if (cluster == null) { verify(configurationHelper).getProperty(ConfigurationValue.FIELD_DATA_DELIMITER); verify(configurationHelper).getProperty(ConfigurationValue.EMR_VALID_STATES); verify(awsClientFactory, times(2)).getEmrClient(awsParamsDto); verify(emrOperations).listEmrClusters(eq(amazonElasticMapReduceClient), any(ListClustersRequest.class)); } else if (cluster.getStatus().getState().equals(EMR_INVALID_STATE)) { verify(configurationHelper, times(2)).getProperty(ConfigurationValue.FIELD_DATA_DELIMITER); verify(configurationHelper, times(2)).getProperty(ConfigurationValue.EMR_VALID_STATES); verify(awsClientFactory, times(2)).getEmrClient(awsParamsDto); verify(emrOperations).listEmrClusters(eq(amazonElasticMapReduceClient), any(ListClustersRequest.class)); } else { verify(configurationHelper).getProperty(ConfigurationValue.FIELD_DATA_DELIMITER); verify(configurationHelper).getProperty(ConfigurationValue.EMR_VALID_STATES); verify(awsClientFactory).getEmrClient(awsParamsDto); } verifyNoMoreInteractionsHelper(); // Validate the results. assertEquals(clusterSummary, result); }
Example #13
Source File: EmrOperations.java From herd with Apache License 2.0 | votes |
public ListClustersResult listEmrClusters(AmazonElasticMapReduceClient emrClient, ListClustersRequest listClustersRequest);