use of org.finra.herd.model.api.xml.EmrClusterDefinitionKey in project herd by FINRAOS.
the class EmrClusterDefinitionServiceImpl method createEmrClusterDefinitionFromEntity.
/**
* Creates the EMR cluster definition information from the persisted entity.
*
* @param emrClusterDefinitionEntity the EMR cluster definition entity
*
* @return the EMR cluster definition information
*/
private EmrClusterDefinitionInformation createEmrClusterDefinitionFromEntity(EmrClusterDefinitionEntity emrClusterDefinitionEntity) throws Exception {
// Unmarshal EMR cluster definition XML into JAXB object.
EmrClusterDefinition emrClusterDefinition = xmlHelper.unmarshallXmlToObject(EmrClusterDefinition.class, emrClusterDefinitionEntity.getConfiguration());
// Create a new instance of EMR cluster definition information.
EmrClusterDefinitionInformation emrClusterDefinitionInformation = new EmrClusterDefinitionInformation();
emrClusterDefinitionInformation.setId(emrClusterDefinitionEntity.getId());
emrClusterDefinitionInformation.setEmrClusterDefinitionKey(new EmrClusterDefinitionKey(emrClusterDefinitionEntity.getNamespace().getCode(), emrClusterDefinitionEntity.getName()));
emrClusterDefinitionInformation.setEmrClusterDefinition(emrClusterDefinition);
return emrClusterDefinitionInformation;
}
use of org.finra.herd.model.api.xml.EmrClusterDefinitionKey in project herd by FINRAOS.
the class EmrClusterDefinitionDaoTest method testGetEmrClusterDefinitionByAltKey.
/**
* Tests the happy path scenario by providing all the parameters.
*/
@Test
public void testGetEmrClusterDefinitionByAltKey() throws IOException {
// Create and persist an EMR cluster definition entity.
emrClusterDefinitionDaoTestHelper.createEmrClusterDefinitionEntity(namespaceDaoTestHelper.createNamespaceEntity(NAMESPACE), EMR_CLUSTER_DEFINITION_NAME, IOUtils.toString(resourceLoader.getResource(EMR_CLUSTER_DEFINITION_XML_FILE_WITH_CLASSPATH).getInputStream()));
// Call the API to query the newly added entity by providing the app and EMT cluster definition details
EmrClusterDefinitionEntity emrClusterDefinitionEntityResult = emrClusterDefinitionDao.getEmrClusterDefinitionByAltKey(new EmrClusterDefinitionKey(NAMESPACE, EMR_CLUSTER_DEFINITION_NAME));
// Fail if there is any problem in the result
assertNotNull(emrClusterDefinitionEntityResult);
assertEquals(NAMESPACE, emrClusterDefinitionEntityResult.getNamespace().getCode());
assertEquals(EMR_CLUSTER_DEFINITION_NAME, emrClusterDefinitionEntityResult.getName());
}
use of org.finra.herd.model.api.xml.EmrClusterDefinitionKey in project herd by FINRAOS.
the class EmrClusterDefinitionDaoTest method testGetEmrClusterDefinitionsByNamespace.
@Test
public void testGetEmrClusterDefinitionsByNamespace() throws IOException {
// Create and persist an EMR cluster definition entity.
emrClusterDefinitionDaoTestHelper.createEmrClusterDefinitionEntity(namespaceDaoTestHelper.createNamespaceEntity(NAMESPACE), EMR_CLUSTER_DEFINITION_NAME, IOUtils.toString(resourceLoader.getResource(EMR_CLUSTER_DEFINITION_XML_FILE_WITH_CLASSPATH).getInputStream()));
// Create an EMR cluster definition key.
EmrClusterDefinitionKey emrClusterDefinitionKey = new EmrClusterDefinitionKey(NAMESPACE, EMR_CLUSTER_DEFINITION_NAME);
// Retrieve a list of EMR cluster definition keys.
assertEquals(Arrays.asList(emrClusterDefinitionKey), emrClusterDefinitionDao.getEmrClusterDefinitionsByNamespace(NAMESPACE));
// Get business object data attribute by passing namespace parameter value in uppercase.
assertEquals(Arrays.asList(emrClusterDefinitionKey), emrClusterDefinitionDao.getEmrClusterDefinitionsByNamespace(NAMESPACE.toUpperCase()));
// Get business object data attribute by passing namespace parameter value in lowercase.
assertEquals(Arrays.asList(emrClusterDefinitionKey), emrClusterDefinitionDao.getEmrClusterDefinitionsByNamespace(NAMESPACE.toLowerCase()));
// Try an invalid value for the namespace input parameter.
assertTrue(emrClusterDefinitionDao.getEmrClusterDefinitionsByNamespace("I_DO_NO_EXIST").isEmpty());
}
use of org.finra.herd.model.api.xml.EmrClusterDefinitionKey in project herd by FINRAOS.
the class EmrClusterDefinitionDaoImpl method getEmrClusterDefinitionsByNamespace.
@Override
public List<EmrClusterDefinitionKey> getEmrClusterDefinitionsByNamespace(String namespace) {
// Create the criteria builder and a tuple style criteria query.
CriteriaBuilder builder = entityManager.getCriteriaBuilder();
CriteriaQuery<Tuple> criteria = builder.createTupleQuery();
// The criteria root is the EMR cluster definition.
Root<EmrClusterDefinitionEntity> emrClusterDefinitionEntityRoot = criteria.from(EmrClusterDefinitionEntity.class);
// Join to the other tables we can filter on.
Join<EmrClusterDefinitionEntity, NamespaceEntity> namespaceEntityJoin = emrClusterDefinitionEntityRoot.join(EmrClusterDefinitionEntity_.namespace);
// Get the columns.
Path<String> namespaceCodeColumn = namespaceEntityJoin.get(NamespaceEntity_.code);
Path<String> emrClusterDefinitionNameColumn = emrClusterDefinitionEntityRoot.get(EmrClusterDefinitionEntity_.name);
// Create the standard restrictions (i.e. the standard where clauses).
Predicate queryRestriction = builder.equal(builder.upper(namespaceEntityJoin.get(NamespaceEntity_.code)), namespace.toUpperCase());
// Add the select clause.
criteria.multiselect(namespaceCodeColumn, emrClusterDefinitionNameColumn);
// Add the where clause.
criteria.where(queryRestriction);
// Add the order by clause.
criteria.orderBy(builder.asc(emrClusterDefinitionNameColumn));
// Run the query to get a list of tuples back.
List<Tuple> tuples = entityManager.createQuery(criteria).getResultList();
// Populate the "keys" objects from the returned tuples (i.e. 1 tuple for each row).
List<EmrClusterDefinitionKey> emrClusterDefinitionKeys = new ArrayList<>();
for (Tuple tuple : tuples) {
EmrClusterDefinitionKey emrClusterDefinitionKey = new EmrClusterDefinitionKey();
emrClusterDefinitionKeys.add(emrClusterDefinitionKey);
emrClusterDefinitionKey.setNamespace(tuple.get(namespaceCodeColumn));
emrClusterDefinitionKey.setEmrClusterDefinitionName(tuple.get(emrClusterDefinitionNameColumn));
}
return emrClusterDefinitionKeys;
}
use of org.finra.herd.model.api.xml.EmrClusterDefinitionKey in project herd by FINRAOS.
the class EmrClusterDefinitionRestControllerTest method testCreateEmrClusterDefinition.
@Test
public void testCreateEmrClusterDefinition() throws Exception {
// Create an EMR cluster definition key.
EmrClusterDefinitionKey emrClusterDefinitionKey = new EmrClusterDefinitionKey(NAMESPACE, EMR_CLUSTER_DEFINITION_NAME);
// Create an EMR cluster definition.
EmrClusterDefinition emrClusterDefinition = new EmrClusterDefinition();
// Create an EMR cluster definition create request.
EmrClusterDefinitionCreateRequest emrClusterDefinitionCreateRequest = new EmrClusterDefinitionCreateRequest(emrClusterDefinitionKey, emrClusterDefinition);
// Create an object that holds EMR cluster definition information.
EmrClusterDefinitionInformation emrClusterDefinitionInformation = new EmrClusterDefinitionInformation(ID, emrClusterDefinitionKey, emrClusterDefinition);
// Mock the external calls.
when(emrClusterDefinitionService.createEmrClusterDefinition(emrClusterDefinitionCreateRequest)).thenReturn(emrClusterDefinitionInformation);
// Call the method under test.
EmrClusterDefinitionInformation result = emrClusterDefinitionRestController.createEmrClusterDefinition(emrClusterDefinitionCreateRequest);
// Verify the external calls.
verify(emrClusterDefinitionService).createEmrClusterDefinition(emrClusterDefinitionCreateRequest);
verifyNoMoreInteractionsHelper();
// Validate the results.
assertEquals(emrClusterDefinitionInformation, result);
}
Aggregations