use of org.finra.herd.model.dto.EmrClusterAlternateKeyDto in project herd by FINRAOS.
the class EmrServiceTest method testGetEmrClusterByIdDoesNotExistForNamespace.
/**
* This method tests the scenario when cluster specified does not exists.
*/
@Test(expected = IllegalArgumentException.class)
public void testGetEmrClusterByIdDoesNotExistForNamespace() throws Exception {
// Create the namespace entity.
NamespaceEntity namespaceEntity = namespaceDaoTestHelper.createNamespaceEntity(NAMESPACE);
emrClusterDefinitionDaoTestHelper.createEmrClusterDefinitionEntity(namespaceEntity, EMR_CLUSTER_DEFINITION_NAME, IOUtils.toString(resourceLoader.getResource(EMR_CLUSTER_DEFINITION_XML_FILE_WITH_CLASSPATH).getInputStream()));
// Create a new EMR cluster create request
EmrClusterCreateRequest request = getNewEmrClusterCreateRequest();
EmrCluster emrCluster = emrService.createCluster(request);
// EmrClusterAlternateKeyDto emrClusterAlternateKeyDto = EmrClusterAlternateKeyDto.builder().namespace(NAMESPACE)
// .emrClusterDefinitionName(EMR_CLUSTER_DEFINITION_NAME).withEmrClusterName(request.getEmrClusterName()).build();
// Create the second namespace entity.
NamespaceEntity namespaceEntity_2 = namespaceDaoTestHelper.createNamespaceEntity(NAMESPACE_2);
emrClusterDefinitionDaoTestHelper.createEmrClusterDefinitionEntity(namespaceEntity_2, EMR_CLUSTER_DEFINITION_NAME, IOUtils.toString(resourceLoader.getResource(EMR_CLUSTER_DEFINITION_XML_FILE_WITH_CLASSPATH).getInputStream()));
EmrClusterAlternateKeyDto emrClusterAlternateKeyDto_2 = EmrClusterAlternateKeyDto.builder().withNamespace(NAMESPACE_2).withEmrClusterDefinitionName(EMR_CLUSTER_DEFINITION_NAME).withEmrClusterName(request.getEmrClusterName()).build();
emrService.getCluster(emrClusterAlternateKeyDto_2, emrCluster.getId(), null, true, null, false);
fail("Should throw an IllegalArgumentException.");
}
use of org.finra.herd.model.dto.EmrClusterAlternateKeyDto in project herd by FINRAOS.
the class EmrServiceTest method testTerminateEmrClusterNoCluster.
/**
* This method tests the scenario when no active cluster exists.
*/
@Test(expected = IllegalArgumentException.class)
public void testTerminateEmrClusterNoCluster() throws Exception {
// Create the namespace entity.
NamespaceEntity namespaceEntity = namespaceDaoTestHelper.createNamespaceEntity(NAMESPACE);
emrClusterDefinitionDaoTestHelper.createEmrClusterDefinitionEntity(namespaceEntity, EMR_CLUSTER_DEFINITION_NAME, IOUtils.toString(resourceLoader.getResource(EMR_CLUSTER_DEFINITION_XML_FILE_WITH_CLASSPATH).getInputStream()));
EmrClusterAlternateKeyDto emrClusterAlternateKeyDto = EmrClusterAlternateKeyDto.builder().withNamespace(NAMESPACE).withEmrClusterDefinitionName(EMR_CLUSTER_DEFINITION_NAME).withEmrClusterName("cluster_not_found").build();
emrService.terminateCluster(emrClusterAlternateKeyDto, true, null, null);
}
use of org.finra.herd.model.dto.EmrClusterAlternateKeyDto in project herd by FINRAOS.
the class EmrServiceWithAccountIdTest method testGetEmrClusterById.
@Test
public void testGetEmrClusterById() throws Exception {
// Create the namespace entity.
NamespaceEntity namespaceEntity = namespaceDaoTestHelper.createNamespaceEntity(NAMESPACE);
// Create a trusting AWS account.
trustingAccountDaoTestHelper.createTrustingAccountEntity(AWS_ACCOUNT_ID, AWS_ROLE_ARN);
String configXml = IOUtils.toString(resourceLoader.getResource(EMR_CLUSTER_DEFINITION_XML_FILE_MINIMAL_CLASSPATH).getInputStream());
EmrClusterDefinition emrClusterDefinition = xmlHelper.unmarshallXmlToObject(EmrClusterDefinition.class, configXml);
emrClusterDefinition.setAmiVersion(MockAwsOperationsHelper.AMAZON_CLUSTER_STATUS_WAITING);
configXml = xmlHelper.objectToXml(emrClusterDefinition);
emrClusterDefinitionDaoTestHelper.createEmrClusterDefinitionEntity(namespaceEntity, EMR_CLUSTER_DEFINITION_NAME, configXml);
// Create a new EMR cluster create request
EmrClusterCreateRequest request = getNewEmrClusterCreateRequestWithAccountId();
EmrCluster emrCluster = emrService.createCluster(request);
EmrClusterAlternateKeyDto emrClusterAlternateKeyDto = EmrClusterAlternateKeyDto.builder().withNamespace(NAMESPACE).withEmrClusterDefinitionName(EMR_CLUSTER_DEFINITION_NAME).withEmrClusterName(request.getEmrClusterName()).build();
EmrCluster emrClusterGet = emrService.getCluster(emrClusterAlternateKeyDto, emrCluster.getId(), null, true, AWS_ACCOUNT_ID, false);
// Validate the returned object against the input.
assertNotNull(emrCluster);
assertNotNull(emrClusterGet);
assertTrue(emrCluster.getId().equals(emrClusterGet.getId()));
assertTrue(emrCluster.getNamespace().equals(emrClusterGet.getNamespace()));
assertTrue(emrCluster.getEmrClusterDefinitionName().equals(emrClusterGet.getEmrClusterDefinitionName()));
assertTrue(emrCluster.getEmrClusterName().equals(emrClusterGet.getEmrClusterName()));
assertEquals(emrCluster.getEmrClusterDefinition().getAccountId(), AWS_ACCOUNT_ID);
assertEquals(AWS_ACCOUNT_ID, emrCluster.getAccountId());
// Terminate the cluster and validate.
emrService.terminateCluster(emrClusterAlternateKeyDto, true, null, AWS_ACCOUNT_ID);
emrClusterGet = emrService.getCluster(emrClusterAlternateKeyDto, emrCluster.getId(), null, true, AWS_ACCOUNT_ID, false);
// Validate the returned object against the input.
assertNotNull(emrCluster);
assertNotNull(emrClusterGet);
assertTrue(emrCluster.getId().equals(emrClusterGet.getId()));
assertTrue(emrCluster.getNamespace().equals(emrClusterGet.getNamespace()));
assertTrue(emrCluster.getEmrClusterDefinitionName().equals(emrClusterGet.getEmrClusterDefinitionName()));
assertTrue(emrCluster.getEmrClusterName().equals(emrClusterGet.getEmrClusterName()));
assertEquals(emrCluster.getEmrClusterDefinition().getAccountId(), AWS_ACCOUNT_ID);
}
use of org.finra.herd.model.dto.EmrClusterAlternateKeyDto in project herd by FINRAOS.
the class EmrServiceWithAccountIdTest method testTerminateEmrCluster.
/**
* This method tests the happy path scenario by providing all the parameters.
*/
@Test
public void testTerminateEmrCluster() throws Exception {
// Create the namespace entity.
NamespaceEntity namespaceEntity = namespaceDaoTestHelper.createNamespaceEntity(NAMESPACE);
emrClusterDefinitionDaoTestHelper.createEmrClusterDefinitionEntity(namespaceEntity, EMR_CLUSTER_DEFINITION_NAME, IOUtils.toString(resourceLoader.getResource(EMR_CLUSTER_DEFINITION_XML_FILE_WITH_CLASSPATH).getInputStream()));
// Create a trusting AWS account.
trustingAccountDaoTestHelper.createTrustingAccountEntity(AWS_ACCOUNT_ID, AWS_ROLE_ARN);
// Create a new EMR cluster create request
EmrClusterCreateRequest request = getNewEmrClusterCreateRequestWithAccountId();
EmrCluster emrCluster = emrService.createCluster(request);
EmrClusterAlternateKeyDto emrClusterAlternateKeyDto = EmrClusterAlternateKeyDto.builder().withNamespace(NAMESPACE).withEmrClusterDefinitionName(EMR_CLUSTER_DEFINITION_NAME).withEmrClusterName(request.getEmrClusterName()).build();
EmrCluster emrClusterTerminated = emrService.terminateCluster(emrClusterAlternateKeyDto, true, null, null);
// Validate the returned object against the input.
assertNotNull(emrCluster);
assertNotNull(emrClusterTerminated);
assertTrue(emrCluster.getNamespace().equals(emrClusterTerminated.getNamespace()));
assertTrue(emrCluster.getEmrClusterDefinitionName().equals(emrClusterTerminated.getEmrClusterDefinitionName()));
assertTrue(emrCluster.getEmrClusterName().equals(emrClusterTerminated.getEmrClusterName()));
assertEquals(AWS_ACCOUNT_ID, emrCluster.getAccountId());
}
use of org.finra.herd.model.dto.EmrClusterAlternateKeyDto in project herd by FINRAOS.
the class BaseEmrCluster method getClusterAlternateKey.
/**
* Builds the cluster alternate key and returns.
*
* @param execution the DelegateExecution
*
* @return the cluster alternate key.
*/
protected EmrClusterAlternateKeyDto getClusterAlternateKey(DelegateExecution execution) {
// Create the alternate key.
EmrClusterAlternateKeyDto emrClusterAlternateKeyDto = new EmrClusterAlternateKeyDto();
emrClusterAlternateKeyDto.setNamespace(activitiHelper.getExpressionVariableAsString(namespace, execution));
emrClusterAlternateKeyDto.setEmrClusterDefinitionName(activitiHelper.getExpressionVariableAsString(emrClusterDefinitionName, execution));
emrClusterAlternateKeyDto.setEmrClusterName(activitiHelper.getExpressionVariableAsString(emrClusterName, execution));
return emrClusterAlternateKeyDto;
}
Aggregations