use of com.amazonaws.services.elasticmapreduce.model.ClusterSummary 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.ClusterSummary in project herd by FINRAOS.
the class EmrDaoTest method addEmrMasterSecurityGroupsThrowWhenNoInstancesFound.
@Test
public void addEmrMasterSecurityGroupsThrowWhenNoInstancesFound() throws Exception {
String clusterName = "clusterName";
List<String> securityGroups = Arrays.asList("securityGroup");
AwsParamsDto awsParams = new AwsParamsDto();
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);
when(mockEmrOperations.listClusterInstancesRequest(any(), any())).thenReturn(new ListInstancesResult());
try {
emrDao.addEmrMasterSecurityGroups(clusterName, securityGroups, awsParams);
fail();
} catch (Exception e) {
assertEquals(IllegalArgumentException.class, e.getClass());
assertEquals("No master instances found for the cluster \"" + clusterName + "\".", e.getMessage());
}
}
use of com.amazonaws.services.elasticmapreduce.model.ClusterSummary in project herd by FINRAOS.
the class EmrDaoTest method addEmrStepCallsAddJobFlowSteps.
@Test
public void addEmrStepCallsAddJobFlowSteps() throws Exception {
String clusterName = "clusterName";
StepConfig emrStepConfig = new StepConfig();
String clusterId = "clusterId";
String stepId = "stepId";
/*
* Mock the EmrOperations.listEmrClusters() call to return a known result.
*/
ListClustersResult listClustersResult = new ListClustersResult();
ClusterSummary clusterSummary = new ClusterSummary();
clusterSummary.setId(clusterId);
clusterSummary.setName(clusterName);
listClustersResult.setClusters(Arrays.asList(clusterSummary));
when(mockEmrOperations.listEmrClusters(any(), any())).thenReturn(listClustersResult);
/*
* Mock EmrOperations.addJobFlowStepsRequest() and assert parameters passed in.
*/
when(mockEmrOperations.addJobFlowStepsRequest(any(), any())).thenAnswer(new Answer<List<String>>() {
@Override
public List<String> answer(InvocationOnMock invocation) throws Throwable {
AddJobFlowStepsRequest addJobFlowStepsRequest = invocation.getArgument(1);
assertEquals(clusterId, addJobFlowStepsRequest.getJobFlowId());
List<StepConfig> steps = addJobFlowStepsRequest.getSteps();
assertEquals(1, steps.size());
assertEquals(emrStepConfig, steps.get(0));
// return a single step with the given stepId
return Arrays.asList(stepId);
}
});
assertEquals(stepId, emrDao.addEmrStep(clusterId, emrStepConfig, new AwsParamsDto()));
}
use of com.amazonaws.services.elasticmapreduce.model.ClusterSummary 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.ClusterSummary in project herd by FINRAOS.
the class EmrDaoTest method terminateEmrCluster.
@Test
public void terminateEmrCluster() throws Exception {
String clusterName = "clusterName";
boolean overrideTerminationProtection = false;
String clusterId = "clusterId";
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);
emrDao.terminateEmrCluster(clusterId, overrideTerminationProtection, new AwsParamsDto());
// Assert that terminateEmrCluster was called with these parameters ONCE
verify(mockEmrOperations).terminateEmrCluster(any(), eq(clusterId), eq(overrideTerminationProtection));
}
Aggregations