use of org.finra.herd.model.api.xml.EmrClusterCreateRequest in project herd by FINRAOS.
the class EmrServiceTest 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 new EMR cluster create request
EmrClusterCreateRequest request = getNewEmrClusterCreateRequest();
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()));
}
use of org.finra.herd.model.api.xml.EmrClusterCreateRequest in project herd by FINRAOS.
the class EmrServiceTest method testCreateEmrClusterDuplicate.
@Test
public void testCreateEmrClusterDuplicate() throws Exception {
// Create the namespace entity.
NamespaceEntity namespaceEntity = namespaceDaoTestHelper.createNamespaceEntity(NAMESPACE);
String definitionXml = IOUtils.toString(resourceLoader.getResource(EMR_CLUSTER_DEFINITION_XML_FILE_WITH_CLASSPATH).getInputStream());
EmrClusterDefinition expectedEmrClusterDefinition = xmlHelper.unmarshallXmlToObject(EmrClusterDefinition.class, definitionXml);
emrClusterDefinitionDaoTestHelper.createEmrClusterDefinitionEntity(namespaceEntity, EMR_CLUSTER_DEFINITION_NAME, definitionXml);
// Create a new EMR cluster create request
EmrClusterCreateRequest request = getNewEmrClusterCreateRequest();
emrService.createCluster(request);
EmrCluster emrCluster = emrService.createCluster(request);
// Validate the returned object against the input.
assertNotNull(emrCluster);
assertTrue(emrCluster.getNamespace().equals(request.getNamespace()));
assertTrue(emrCluster.getEmrClusterDefinitionName().equals(request.getEmrClusterDefinitionName()));
assertTrue(emrCluster.getEmrClusterName().equals(request.getEmrClusterName()));
assertNotNull(emrCluster.getId());
assertNull(emrCluster.isDryRun());
assertFalse(emrCluster.isEmrClusterCreated());
assertNull(emrCluster.getEmrClusterDefinition());
// should throw if not unique
validateEmrClusterCreationLogUnique(emrCluster, expectedEmrClusterDefinition);
}
use of org.finra.herd.model.api.xml.EmrClusterCreateRequest in project herd by FINRAOS.
the class EmrServiceTest method testAddSecurityGroupAmazonException.
/**
* This method tests the scenario where AmazonServiceException is thrown
*/
@Test(expected = AmazonServiceException.class)
public void testAddSecurityGroupAmazonException() 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()));
EmrClusterCreateRequest request = getNewEmrClusterCreateRequest();
emrService.createCluster(request);
// Create the Add security group.
EmrMasterSecurityGroupAddRequest emrMasterSecurityGroupAddRequest = getNewEmrAddSecurityGroupMasterRequest(request.getEmrClusterName());
emrMasterSecurityGroupAddRequest.getSecurityGroupIds().clear();
emrMasterSecurityGroupAddRequest.getSecurityGroupIds().add(MockAwsOperationsHelper.AMAZON_SERVICE_EXCEPTION);
emrService.addSecurityGroupsToClusterMaster(emrMasterSecurityGroupAddRequest);
}
use of org.finra.herd.model.api.xml.EmrClusterCreateRequest in project herd by FINRAOS.
the class EmrServiceTest method testCreateEmrClusterInvalidParameters.
@Test
public void testCreateEmrClusterInvalidParameters() throws Exception {
// Try to perform a create when namespace contains a forward slash character.
try {
EmrClusterCreateRequest request = getNewEmrClusterCreateRequest();
request.setNamespace(addSlash(request.getNamespace()));
emrService.createCluster(request);
fail("Should throw an IllegalArgumentException when namespace contains a forward slash character.");
} catch (IllegalArgumentException e) {
assertEquals("Namespace can not contain a forward slash character.", e.getMessage());
}
// Try to perform a create when EMR cluster definition name contains a forward slash character.
try {
EmrClusterCreateRequest request = getNewEmrClusterCreateRequest();
request.setEmrClusterDefinitionName(addSlash(request.getEmrClusterDefinitionName()));
emrService.createCluster(request);
fail("Should throw an IllegalArgumentException when EMR cluster definition name contains a forward slash character.");
} catch (IllegalArgumentException e) {
assertEquals("EMR cluster definition name can not contain a forward slash character.", e.getMessage());
}
// Try to perform a create when EMR cluster name contains a forward slash character.
try {
EmrClusterCreateRequest request = getNewEmrClusterCreateRequest();
request.setEmrClusterName(addSlash(request.getEmrClusterName()));
emrService.createCluster(request);
fail("Should throw an IllegalArgumentException when EMR cluster name contains a forward slash character.");
} catch (IllegalArgumentException e) {
assertEquals("EMR cluster name can not contain a forward slash character.", e.getMessage());
}
}
use of org.finra.herd.model.api.xml.EmrClusterCreateRequest in project herd by FINRAOS.
the class EmrServiceTest method testCreateEmrClusterAmazonOtherException.
/**
* This method tests the error cases for AmazonExceptions for AmazonServiceException
*/
@Test(expected = AmazonServiceException.class)
public void testCreateEmrClusterAmazonOtherException() throws Exception {
// Create the namespace entity.
NamespaceEntity namespaceEntity = namespaceDaoTestHelper.createNamespaceEntity(NAMESPACE);
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_SERVICE_EXCEPTION);
configXml = xmlHelper.objectToXml(emrClusterDefinition);
emrClusterDefinitionDaoTestHelper.createEmrClusterDefinitionEntity(namespaceEntity, EMR_CLUSTER_DEFINITION_NAME, configXml);
// Create a new EMR cluster create request.
EmrClusterCreateRequest request = getNewEmrClusterCreateRequest();
emrService.createCluster(request);
}
Aggregations