use of com.amazonaws.services.elasticmapreduce.model.Cluster in project herd by FINRAOS.
the class EmrHelperTest method testGetActiveEmrClusterIdAssertErrorWhenClusterIdSpecifiedAndNameMismatch.
@Test
public void testGetActiveEmrClusterIdAssertErrorWhenClusterIdSpecifiedAndNameMismatch() {
EmrDao originalEmrDao = emrHelper.getEmrDao();
EmrDao mockEmrDao = mock(EmrDao.class);
emrHelper.setEmrDao(mockEmrDao);
try {
String emrClusterId = "emrClusterId";
String emrClusterName = "emrClusterName";
String expectedEmrClusterId = "expectedEmrClusterId";
String actualEmrClusterName = "actualEmrClusterName";
when(mockEmrDao.getEmrClusterById(any(), any())).thenReturn(new Cluster().withId(expectedEmrClusterId).withName(actualEmrClusterName).withStatus(new ClusterStatus().withState(ClusterState.RUNNING)));
try {
emrHelper.getActiveEmrClusterId(emrClusterId, emrClusterName, null);
fail();
} catch (IllegalArgumentException e) {
assertEquals(String.format("The cluster with ID \"%s\" does not match the expected name \"%s\". The actual name is \"%s\".", expectedEmrClusterId, emrClusterName, actualEmrClusterName), e.getMessage());
}
verify(mockEmrDao).getEmrClusterById(eq(emrClusterId.trim()), any());
verifyNoMoreInteractions(mockEmrDao);
} finally {
emrHelper.setEmrDao(originalEmrDao);
}
}
use of com.amazonaws.services.elasticmapreduce.model.Cluster in project herd by FINRAOS.
the class EmrHelperTest method testGetActiveEmrClusterIdAssertParametersTrimmed.
@Test
public void testGetActiveEmrClusterIdAssertParametersTrimmed() {
EmrDao originalEmrDao = emrHelper.getEmrDao();
EmrDao mockEmrDao = mock(EmrDao.class);
emrHelper.setEmrDao(mockEmrDao);
try {
String emrClusterId = "emrClusterId";
String emrClusterName = "emrClusterName";
String expectedEmrClusterId = "expectedEmrClusterId";
when(mockEmrDao.getEmrClusterById(any(), any())).thenReturn(new Cluster().withId(expectedEmrClusterId).withName(emrClusterName).withStatus(new ClusterStatus().withState(ClusterState.RUNNING)));
assertEquals(expectedEmrClusterId, emrHelper.getActiveEmrClusterId(StringUtils.wrap(emrClusterId, BLANK_TEXT), StringUtils.wrap(emrClusterName, BLANK_TEXT), null));
verify(mockEmrDao).getEmrClusterById(eq(emrClusterId.trim()), any());
verifyNoMoreInteractions(mockEmrDao);
} finally {
emrHelper.setEmrDao(originalEmrDao);
}
}
use of com.amazonaws.services.elasticmapreduce.model.Cluster in project herd by FINRAOS.
the class EmrHelperTest method testGetActiveEmrClusterIdAssertErrorWhenClusterIdSpecifiedAndClusterStateNotActive.
@Test
public void testGetActiveEmrClusterIdAssertErrorWhenClusterIdSpecifiedAndClusterStateNotActive() {
EmrDao originalEmrDao = emrHelper.getEmrDao();
EmrDao mockEmrDao = mock(EmrDao.class);
emrHelper.setEmrDao(mockEmrDao);
try {
String emrClusterId = "emrClusterId";
String emrClusterName = "emrClusterName";
String expectedEmrClusterId = "expectedEmrClusterId";
ClusterState actualClusterState = ClusterState.TERMINATED;
when(mockEmrDao.getEmrClusterById(any(), any())).thenReturn(new Cluster().withId(expectedEmrClusterId).withName(emrClusterName).withStatus(new ClusterStatus().withState(actualClusterState)));
try {
emrHelper.getActiveEmrClusterId(emrClusterId, emrClusterName, null);
fail();
} catch (IllegalArgumentException e) {
assertEquals(String.format("The cluster with ID \"%s\" is not active. The cluster state must be in one of [STARTING, BOOTSTRAPPING, RUNNING, " + "WAITING]. Current state is \"%s\"", emrClusterId, actualClusterState), e.getMessage());
}
verify(mockEmrDao).getEmrClusterById(eq(emrClusterId), any());
verifyNoMoreInteractions(mockEmrDao);
} finally {
emrHelper.setEmrDao(originalEmrDao);
}
}
use of com.amazonaws.services.elasticmapreduce.model.Cluster in project herd by FINRAOS.
the class EmrDaoTest method getEmrClusterStatusByIdAssertReturnClusterState.
@Test
public void getEmrClusterStatusByIdAssertReturnClusterState() throws Exception {
String clusterId = "clusterId";
ClusterState expectedState = ClusterState.BOOTSTRAPPING;
when(mockEmrOperations.describeClusterRequest(any(), any())).then(new Answer<DescribeClusterResult>() {
@Override
public DescribeClusterResult answer(InvocationOnMock invocation) throws Throwable {
DescribeClusterRequest describeClusterRequest = invocation.getArgument(1);
assertEquals(clusterId, describeClusterRequest.getClusterId());
DescribeClusterResult describeClusterResult = new DescribeClusterResult();
Cluster cluster = new Cluster();
ClusterStatus status = new ClusterStatus();
status.setState(expectedState);
cluster.setStatus(status);
describeClusterResult.setCluster(cluster);
return describeClusterResult;
}
});
assertEquals(expectedState.toString(), emrDao.getEmrClusterStatusById(clusterId, new AwsParamsDto()));
}
use of com.amazonaws.services.elasticmapreduce.model.Cluster in project herd by FINRAOS.
the class EmrHelper method getActiveEmrClusterId.
/**
* Gets the ID of an active EMR cluster which matches the given criteria. If both cluster ID and cluster name is specified, the name of the actual cluster
* with the given ID must match the specified name. For cases where the cluster is not found (does not exists or not active), the method fails. All
* parameters are case-insensitive and whitespace trimmed. Blank parameters are equal to null.
*
* @param emrClusterId EMR cluster ID
* @param emrClusterName EMR cluster name
* @param accountId the account Id that EMR cluster is running under
*
* @return The cluster ID
*/
public String getActiveEmrClusterId(String emrClusterId, String emrClusterName, String accountId) {
boolean emrClusterIdSpecified = StringUtils.isNotBlank(emrClusterId);
boolean emrClusterNameSpecified = StringUtils.isNotBlank(emrClusterName);
Assert.isTrue(emrClusterIdSpecified || emrClusterNameSpecified, "One of EMR cluster ID or EMR cluster name must be specified.");
AwsParamsDto awsParamsDto = getAwsParamsDtoByAcccountId(accountId);
// Get cluster by ID first
if (emrClusterIdSpecified) {
String emrClusterIdTrimmed = emrClusterId.trim();
// Assert cluster exists
Cluster cluster = emrDao.getEmrClusterById(emrClusterIdTrimmed, awsParamsDto);
Assert.notNull(cluster, String.format("The cluster with ID \"%s\" does not exist.", emrClusterIdTrimmed));
// Assert the cluster's state is active
String emrClusterState = cluster.getStatus().getState();
Assert.isTrue(isActiveEmrState(emrClusterState), String.format("The cluster with ID \"%s\" is not active. The cluster state must be in one of %s. Current state is \"%s\"", emrClusterIdTrimmed, Arrays.toString(getActiveEmrClusterStates()), emrClusterState));
// Assert cluster name equals if cluster name was specified
if (emrClusterNameSpecified) {
String emrClusterNameTrimmed = emrClusterName.trim();
Assert.isTrue(cluster.getName().equalsIgnoreCase(emrClusterNameTrimmed), String.format("The cluster with ID \"%s\" does not match the expected name \"%s\". The actual name is \"%s\".", cluster.getId(), emrClusterNameTrimmed, cluster.getName()));
}
return cluster.getId();
} else {
String emrClusterNameTrimmed = emrClusterName.trim();
ClusterSummary clusterSummary = emrDao.getActiveEmrClusterByName(emrClusterNameTrimmed, awsParamsDto);
Assert.notNull(clusterSummary, String.format("The cluster with name \"%s\" does not exist.", emrClusterNameTrimmed));
return clusterSummary.getId();
}
}
Aggregations