use of org.finra.herd.model.jpa.NamespaceEntity in project herd by FINRAOS.
the class EmrServiceTest method testCreateEmrClusterAmazonBadRequest.
/**
* This method tests the error cases for AmazonExceptions for Illegal Argument
*/
@Test(expected = IllegalArgumentException.class)
public void testCreateEmrClusterAmazonBadRequest() 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_BAD_REQUEST);
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.jpa.NamespaceEntity in project herd by FINRAOS.
the class EmrServiceTest method testEmrAddStepsAmazonBadRequest.
/**
* This method tests the Amazon BAD_REQUEST exception
*/
@Test(expected = IllegalArgumentException.class)
public void testEmrAddStepsAmazonBadRequest() 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 a new EMR cluster create request.
EmrShellStepAddRequest stepRequest = getNewEmrShellStepAddRequest(request.getEmrClusterName());
stepRequest.setStepName(MockAwsOperationsHelper.AMAZON_BAD_REQUEST);
emrService.addStepToCluster(stepRequest);
}
use of org.finra.herd.model.jpa.NamespaceEntity in project herd by FINRAOS.
the class EmrServiceTest method testCreateEmrClusterOverrideHadoopConfigurations.
@Test
public void testCreateEmrClusterOverrideHadoopConfigurations() 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();
EmrClusterDefinition emrClusterDefinitionOverride = new EmrClusterDefinition();
ArrayList<Serializable> hadoopConfigurations = new ArrayList<>();
hadoopConfigurations.add(new ConfigurationFiles());
hadoopConfigurations.add(new KeyValuePairConfigurations());
emrClusterDefinitionOverride.setHadoopConfigurations(hadoopConfigurations);
expectedEmrClusterDefinition.setHadoopConfigurations(emrClusterDefinitionOverride.getHadoopConfigurations());
request.setEmrClusterDefinitionOverride(emrClusterDefinitionOverride);
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.jpa.NamespaceEntity in project herd by FINRAOS.
the class EmrServiceTest method testEmrAddStepsAmazonObjectNotFound.
/**
* This method tests the error cases for AmazonExceptions for Illegal Argument
*/
@Test(expected = ObjectNotFoundException.class)
public void testEmrAddStepsAmazonObjectNotFound() 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 a new EMR cluster create request.
EmrShellStepAddRequest stepRequest = getNewEmrShellStepAddRequest(request.getEmrClusterName());
stepRequest.setStepName(MockAwsOperationsHelper.AMAZON_NOT_FOUND);
emrService.addStepToCluster(stepRequest);
}
use of org.finra.herd.model.jpa.NamespaceEntity in project herd by FINRAOS.
the class EmrServiceTest method getEmrClusterCreationLogEntities.
/**
* Returns a list of {@link EmrClusterCreationLogEntity} objects for the given cluster namespace, cluster definition name, and EMR cluster name. All the
* given parameters are case insensitive. The returned list's order is not guaranteed.
*
* @param namespace - EMR cluster namespace
* @param definitionName - EMR cluster definition name
* @param clusterName - EMR cluster name
*
* @return list of EMR cluster creation logs
*/
protected List<EmrClusterCreationLogEntity> getEmrClusterCreationLogEntities(String namespace, String definitionName, String clusterName) {
CriteriaBuilder builder = entityManager.getCriteriaBuilder();
CriteriaQuery<EmrClusterCreationLogEntity> query = builder.createQuery(EmrClusterCreationLogEntity.class);
Root<EmrClusterCreationLogEntity> emrClusterCreationLogEntity = query.from(EmrClusterCreationLogEntity.class);
Join<?, NamespaceEntity> namespaceEntity = emrClusterCreationLogEntity.join(EmrClusterCreationLogEntity_.namespace);
Predicate namespacePredicate = builder.equal(builder.upper(namespaceEntity.get(NamespaceEntity_.code)), namespace.toUpperCase());
Predicate definitionNamePredicate = builder.equal(builder.upper(emrClusterCreationLogEntity.get(EmrClusterCreationLogEntity_.emrClusterDefinitionName)), definitionName.toUpperCase());
Predicate clusterNamePredicate = builder.equal(builder.upper(emrClusterCreationLogEntity.get(EmrClusterCreationLogEntity_.emrClusterName)), clusterName.toUpperCase());
query.select(emrClusterCreationLogEntity).where(builder.and(namespacePredicate, definitionNamePredicate, clusterNamePredicate));
return entityManager.createQuery(query).getResultList();
}
Aggregations