use of org.finra.herd.model.api.xml.EmrCluster in project herd by FINRAOS.
the class EmrServiceTest method testCreateEmrClusterWrongInstanceConfigs.
/**
* This method tests some of the negative test cases
*/
@Test
public void testCreateEmrClusterWrongInstanceConfigs() 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_MINIMAL_CLASSPATH).getInputStream()));
// Create a new EMR cluster create request.
EmrClusterCreateRequest request = getNewEmrClusterCreateRequest();
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()));
// Calling again must return the same cluster id
emrService.createCluster(request);
}
use of org.finra.herd.model.api.xml.EmrCluster in project herd by FINRAOS.
the class EmrServiceTest method testCreateEmrClusterOverrideInstanceFleetsWithInstanceDefinitions.
@Test
public void testCreateEmrClusterOverrideInstanceFleetsWithInstanceDefinitions() throws Exception {
// Create the namespace entity.
NamespaceEntity namespaceEntity = namespaceDaoTestHelper.createNamespaceEntity(NAMESPACE);
// Create an EMR cluster definition that uses instance fleets instead of instance definitions.
String definitionXml = IOUtils.toString(resourceLoader.getResource(EMR_CLUSTER_DEFINITION_XML_FILE_WITH_CLASSPATH).getInputStream());
EmrClusterDefinition expectedEmrClusterDefinition = xmlHelper.unmarshallXmlToObject(EmrClusterDefinition.class, definitionXml);
InstanceDefinitions instanceDefinitions = expectedEmrClusterDefinition.getInstanceDefinitions();
expectedEmrClusterDefinition.setInstanceDefinitions(null);
expectedEmrClusterDefinition.setInstanceFleets(Arrays.asList(new EmrClusterDefinitionInstanceFleet()));
emrClusterDefinitionDaoTestHelper.createEmrClusterDefinitionEntity(namespaceEntity, EMR_CLUSTER_DEFINITION_NAME, xmlHelper.objectToXml(expectedEmrClusterDefinition));
// Update the count of master instances in the instance definitions.
instanceDefinitions.getMasterInstances().setInstanceCount(instanceDefinitions.getMasterInstances().getInstanceCount() + 1);
// Create a new EMR cluster create request that replaces instance fleets with instance definitions.
EmrClusterCreateRequest request = getNewEmrClusterCreateRequest();
EmrClusterDefinition emrClusterDefinitionOverride = new EmrClusterDefinition();
emrClusterDefinitionOverride.setInstanceDefinitions(instanceDefinitions);
emrClusterDefinitionOverride.setInstanceFleets(new ArrayList<>());
request.setEmrClusterDefinitionOverride(emrClusterDefinitionOverride);
// Update the expected EMR cluster definition.
expectedEmrClusterDefinition.setInstanceDefinitions(instanceDefinitions);
expectedEmrClusterDefinition.setInstanceFleets(new ArrayList<>());
// Create the cluster.
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());
assertTrue(emrCluster.isEmrClusterCreated());
assertNotNull(emrCluster.getEmrClusterDefinition());
assertEquals(expectedEmrClusterDefinition, emrCluster.getEmrClusterDefinition());
validateEmrClusterCreationLogUnique(emrCluster, expectedEmrClusterDefinition);
}
use of org.finra.herd.model.api.xml.EmrCluster in project herd by FINRAOS.
the class EmrServiceTest method testCreateEmrCluster.
/**
* This method tests the happy path scenario by providing all the parameters
*/
@Test
public void testCreateEmrCluster() 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);
assertEquals("scaleDownBehavior", expectedEmrClusterDefinition.getScaleDownBehavior());
emrClusterDefinitionDaoTestHelper.createEmrClusterDefinitionEntity(namespaceEntity, EMR_CLUSTER_DEFINITION_NAME, definitionXml);
// Create a new EMR cluster create request
EmrClusterCreateRequest request = getNewEmrClusterCreateRequest();
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()));
assertNull(emrCluster.getAccountId());
assertNotNull(emrCluster.getId());
assertNull(emrCluster.isDryRun());
assertNotNull(emrCluster.getEmrClusterDefinition());
assertTrue(emrCluster.isEmrClusterCreated());
assertEquals(expectedEmrClusterDefinition, emrCluster.getEmrClusterDefinition());
validateEmrClusterCreationLogUnique(emrCluster, expectedEmrClusterDefinition);
}
use of org.finra.herd.model.api.xml.EmrCluster in project herd by FINRAOS.
the class EmrServiceTest method testCreateEmrClusterWithTaskInstances.
/**
* This method tests the scenario where task instances are there
*/
@Test
public void testCreateEmrClusterWithTaskInstances() throws Exception {
// Create the namespace entity.
NamespaceEntity namespaceEntity = namespaceDaoTestHelper.createNamespaceEntity(NAMESPACE);
String configXml = IOUtils.toString(resourceLoader.getResource(EMR_CLUSTER_DEFINITION_XML_FILE_WITH_CLASSPATH).getInputStream());
EmrClusterDefinition emrClusterDefinition = xmlHelper.unmarshallXmlToObject(EmrClusterDefinition.class, configXml);
InstanceDefinition taskDef = new InstanceDefinition();
taskDef.setInstanceCount(1);
// This could be any EC2 instance type supported in EMR.
taskDef.setInstanceType(MockEc2OperationsImpl.INSTANCE_TYPE_1);
emrClusterDefinition.getInstanceDefinitions().setTaskInstances(taskDef);
configXml = xmlHelper.objectToXml(emrClusterDefinition);
emrClusterDefinitionDaoTestHelper.createEmrClusterDefinitionEntity(namespaceEntity, EMR_CLUSTER_DEFINITION_NAME, configXml);
// Create a new EMR cluster create request.
EmrClusterCreateRequest request = getNewEmrClusterCreateRequest();
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()));
}
use of org.finra.herd.model.api.xml.EmrCluster in project herd by FINRAOS.
the class EmrRestControllerTest method testTerminateEmrCluster.
@Test
public void testTerminateEmrCluster() throws Exception {
// Create an EMR cluster key.
EmrClusterAlternateKeyDto emrClusterAlternateKeyDto = new EmrClusterAlternateKeyDto(NAMESPACE, EMR_CLUSTER_DEFINITION_NAME, EMR_CLUSTER_NAME);
// Create an EMR cluster.
EmrCluster emrCluster = new EmrCluster();
emrCluster.setId(EMR_CLUSTER_ID);
// Mock the external calls.
when(emrService.terminateCluster(emrClusterAlternateKeyDto, OVERRIDE_TERMINATION_PROTECTION, EMR_CLUSTER_ID, AWS_ACCOUNT_ID)).thenReturn(emrCluster);
// Call the method under test.
EmrCluster result = emrRestController.terminateEmrCluster(NAMESPACE, EMR_CLUSTER_DEFINITION_NAME, EMR_CLUSTER_NAME, OVERRIDE_TERMINATION_PROTECTION, EMR_CLUSTER_ID, AWS_ACCOUNT_ID);
// Verify the external calls.
verify(emrService).terminateCluster(emrClusterAlternateKeyDto, OVERRIDE_TERMINATION_PROTECTION, EMR_CLUSTER_ID, AWS_ACCOUNT_ID);
verifyNoMoreInteractionsHelper();
// Validate the results.
assertEquals(emrCluster, result);
}
Aggregations