use of org.finra.herd.model.api.xml.EmrClusterCreateRequest in project herd by FINRAOS.
the class EmrServiceTest method testCreateEmrClusterOverrideExistingCoreInstanceTo0InstanceCountAssertSuccess.
@Test
public void testCreateEmrClusterOverrideExistingCoreInstanceTo0InstanceCountAssertSuccess() 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 emrClusterDefinition = xmlHelper.unmarshallXmlToObject(EmrClusterDefinition.class, definitionXml);
emrClusterDefinition.getInstanceDefinitions().getCoreInstances().setInstanceCount(1);
emrClusterDefinitionDaoTestHelper.createEmrClusterDefinitionEntity(namespaceEntity, EMR_CLUSTER_DEFINITION_NAME, xmlHelper.objectToXml(emrClusterDefinition));
// Create a new EMR cluster create request
EmrClusterCreateRequest request = getNewEmrClusterCreateRequest();
EmrClusterDefinition emrClusterDefinitionOverride = new EmrClusterDefinition();
emrClusterDefinitionOverride.setInstanceDefinitions(emrClusterDefinition.getInstanceDefinitions());
emrClusterDefinitionOverride.getInstanceDefinitions().getCoreInstances().setInstanceCount(0);
request.setEmrClusterDefinitionOverride(emrClusterDefinitionOverride);
EmrCluster emrClusterCreateResponse = emrService.createCluster(request);
assertNull(emrClusterCreateResponse.getEmrClusterDefinition().getInstanceDefinitions().getCoreInstances());
}
use of org.finra.herd.model.api.xml.EmrClusterCreateRequest in project herd by FINRAOS.
the class EmrServiceTest method testCreateEmrClusterSecurityConfiguration.
/**
* This method tests security configuration.
*/
@Test
public void testCreateEmrClusterSecurityConfiguration() 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);
// Set the security configuration along with the EMR release label.
// This is needed since security configuration is not supported prior to EMR version 4.8.0.
emrClusterDefinition.setSecurityConfiguration("securityConfiguration");
emrClusterDefinition.setReleaseLabel("4.8.0");
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);
}
use of org.finra.herd.model.api.xml.EmrClusterCreateRequest in project herd by FINRAOS.
the class EmrServiceTest method testCreateEmrClusterAmazonObjectNotFound.
/**
* This method tests the error cases for AmazonExceptions for Illegal Argument
*/
@Test(expected = ObjectNotFoundException.class)
public void testCreateEmrClusterAmazonObjectNotFound() 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_NOT_FOUND);
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);
}
use of org.finra.herd.model.api.xml.EmrClusterCreateRequest in project herd by FINRAOS.
the class EmrServiceTest method testCreateEmrClusterMandatoryTagsNull.
/**
* This method tests the scenario where task instances are there
*/
@Test
public void testCreateEmrClusterMandatoryTagsNull() 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();
// Remove property source so that we can test mandatory tags config being null
Map<String, Object> overrideMap = new HashMap<>();
overrideMap.put(ConfigurationValue.MANDATORY_AWS_TAGS.getKey(), null);
modifyPropertySourceInEnvironment(overrideMap);
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()));
restorePropertySourceInEnvironment();
}
use of org.finra.herd.model.api.xml.EmrClusterCreateRequest in project herd by FINRAOS.
the class EmrServiceTest method testEmrServiceMethodsNewTx.
/**
* This method is to get the coverage for the emr service method that starts the new transaction.
*/
@Test
public void testEmrServiceMethodsNewTx() throws Exception {
EmrClusterCreateRequest request = getNewEmrClusterCreateRequest();
try {
emrServiceImpl.createCluster(request);
fail("Should throw a ObjectNotFoundException.");
} catch (ObjectNotFoundException e) {
assertEquals("Namespace \"" + NAMESPACE + "\" doesn't exist.", e.getMessage());
}
try {
EmrShellStepAddRequest stepRequest = getNewEmrShellStepAddRequest(request.getEmrClusterName());
emrServiceImpl.addStepToCluster(stepRequest);
fail("Should throw a ObjectNotFoundException.");
} catch (ObjectNotFoundException e) {
assertEquals("Namespace \"" + NAMESPACE + "\" doesn't exist.", e.getMessage());
}
try {
EmrMasterSecurityGroupAddRequest emrMasterSecurityGroupAddRequest = getNewEmrAddSecurityGroupMasterRequest(request.getEmrClusterName());
emrServiceImpl.addSecurityGroupsToClusterMaster(emrMasterSecurityGroupAddRequest);
fail("Should throw a ObjectNotFoundException.");
} catch (ObjectNotFoundException e) {
assertEquals("Namespace \"" + NAMESPACE + "\" doesn't exist.", e.getMessage());
}
try {
EmrClusterAlternateKeyDto emrClusterAlternateKeyDto = EmrClusterAlternateKeyDto.builder().withNamespace(NAMESPACE).withEmrClusterDefinitionName(EMR_CLUSTER_DEFINITION_NAME).withEmrClusterName("test_cluster").build();
emrServiceImpl.getCluster(emrClusterAlternateKeyDto, null, null, false, null, false);
fail("Should throw a ObjectNotFoundException.");
} catch (ObjectNotFoundException e) {
assertEquals("Namespace \"" + NAMESPACE + "\" doesn't exist.", e.getMessage());
}
try {
EmrClusterAlternateKeyDto emrClusterAlternateKeyDto = EmrClusterAlternateKeyDto.builder().withNamespace(NAMESPACE).withEmrClusterDefinitionName(EMR_CLUSTER_DEFINITION_NAME).withEmrClusterName("test_cluster").build();
emrServiceImpl.terminateCluster(emrClusterAlternateKeyDto, false, null, null);
fail("Should throw a ObjectNotFoundException.");
} catch (ObjectNotFoundException e) {
assertEquals("Namespace \"" + NAMESPACE + "\" doesn't exist.", e.getMessage());
}
}
Aggregations