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);
}
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());
}
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());
}
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;
}
Aggregations