use of org.finra.herd.model.api.xml.EmrClusterDefinition 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.api.xml.EmrClusterDefinition in project herd by FINRAOS.
the class EmrServiceWithAccountIdTest method testCreateEmrClusterWithAccountId.
@Test
public void testCreateEmrClusterWithAccountId() 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 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 and add an account id to the EMR cluster definition override.
EmrClusterCreateRequest request = getNewEmrClusterCreateRequestWithAccountId();
EmrClusterDefinition emrClusterDefinitionOverride = new EmrClusterDefinition();
request.setEmrClusterDefinitionOverride(emrClusterDefinitionOverride);
emrClusterDefinitionOverride.setAccountId(AWS_ACCOUNT_ID);
// Create an EMR cluster.
EmrCluster emrCluster = emrService.createCluster(request);
// Update the expected EMR cluster definition with the account id.
expectedEmrClusterDefinition.setAccountId(AWS_ACCOUNT_ID);
// 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()));
assertEquals(AWS_ACCOUNT_ID, 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.EmrClusterDefinition in project herd by FINRAOS.
the class EmrHelperTest method testGetActiveEmrClusterByName.
@Test
public void testGetActiveEmrClusterByName() throws Exception {
// Get the EMR cluster definition object
String configXml = IOUtils.toString(resourceLoader.getResource(EMR_CLUSTER_DEFINITION_XML_FILE_WITH_CLASSPATH).getInputStream());
EmrClusterDefinition emrClusterDefinition = xmlHelper.unmarshallXmlToObject(EmrClusterDefinition.class, configXml);
// check cluster summary before creation
ClusterSummary clusterSummary = emrDao.getActiveEmrClusterByName(MockEmrOperationsImpl.MOCK_CLUSTER_NAME, emrHelper.getAwsParamsDto());
assertNull(clusterSummary);
// Create the cluster
String clusterId = emrDao.createEmrCluster(MockEmrOperationsImpl.MOCK_CLUSTER_NAME, emrClusterDefinition, emrHelper.getAwsParamsDto());
// check cluster summary after creation
clusterSummary = emrDao.getActiveEmrClusterByName(MockEmrOperationsImpl.MOCK_CLUSTER_NAME, emrHelper.getAwsParamsDto());
assertNotNull(clusterSummary);
assertEquals(clusterId, clusterSummary.getId());
}
use of org.finra.herd.model.api.xml.EmrClusterDefinition in project herd by FINRAOS.
the class EmrClusterDefinitionHelperTest method testValidateEmrClusterDefinitionConfigurationMasterMaxSearchPriceNegative.
/**
* Tests case where validation is run against the definition generated by createValidEmrClusterDefinition() The master instance max search price is
* negative. The definition is not valid. All prices must be positive.
*/
@Test
public void testValidateEmrClusterDefinitionConfigurationMasterMaxSearchPriceNegative() {
EmrClusterDefinition emrClusterDefinition = createValidEmrClusterDefinition();
emrClusterDefinition.getInstanceDefinitions().getMasterInstances().setInstanceMaxSearchPrice(BigDecimal.ONE.negate());
try {
emrClusterDefinitionHelper.validateEmrClusterDefinitionConfiguration(emrClusterDefinition);
fail("expected IllegalArgumentException, but no exception was thrown");
} catch (Exception e) {
assertEquals("thrown exception", IllegalArgumentException.class, e.getClass());
}
}
use of org.finra.herd.model.api.xml.EmrClusterDefinition in project herd by FINRAOS.
the class EmrClusterDefinitionHelperTest method testValidateEmrClusterDefinitionConfigurationCoreInstanceSpecifiedInstanceCountNegative.
@Test
public void testValidateEmrClusterDefinitionConfigurationCoreInstanceSpecifiedInstanceCountNegative() {
EmrClusterDefinition emrClusterDefinition = createValidEmrClusterDefinition();
emrClusterDefinition.getInstanceDefinitions().getCoreInstances().setInstanceCount(-1);
try {
emrClusterDefinitionHelper.validateEmrClusterDefinitionConfiguration(emrClusterDefinition);
fail();
} catch (IllegalArgumentException e) {
assertEquals("At least 0 core instance must be specified.", e.getMessage());
}
}
Aggregations