Search in sources :

Example 1 with EmrClusterDefinitionKey

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;
}
Also used : EmrClusterDefinition(org.finra.herd.model.api.xml.EmrClusterDefinition) EmrClusterDefinitionKey(org.finra.herd.model.api.xml.EmrClusterDefinitionKey) EmrClusterDefinitionInformation(org.finra.herd.model.api.xml.EmrClusterDefinitionInformation)

Example 2 with EmrClusterDefinitionKey

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());
}
Also used : EmrClusterDefinitionKey(org.finra.herd.model.api.xml.EmrClusterDefinitionKey) EmrClusterDefinitionEntity(org.finra.herd.model.jpa.EmrClusterDefinitionEntity) Test(org.junit.Test)

Example 3 with EmrClusterDefinitionKey

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());
}
Also used : EmrClusterDefinitionKey(org.finra.herd.model.api.xml.EmrClusterDefinitionKey) Test(org.junit.Test)

Example 4 with EmrClusterDefinitionKey

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;
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) ArrayList(java.util.ArrayList) Predicate(javax.persistence.criteria.Predicate) EmrClusterDefinitionKey(org.finra.herd.model.api.xml.EmrClusterDefinitionKey) Tuple(javax.persistence.Tuple) EmrClusterDefinitionEntity(org.finra.herd.model.jpa.EmrClusterDefinitionEntity)

Example 5 with EmrClusterDefinitionKey

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);
}
Also used : EmrClusterDefinition(org.finra.herd.model.api.xml.EmrClusterDefinition) EmrClusterDefinitionKey(org.finra.herd.model.api.xml.EmrClusterDefinitionKey) EmrClusterDefinitionCreateRequest(org.finra.herd.model.api.xml.EmrClusterDefinitionCreateRequest) EmrClusterDefinitionInformation(org.finra.herd.model.api.xml.EmrClusterDefinitionInformation) Test(org.junit.Test)

Aggregations

EmrClusterDefinitionKey (org.finra.herd.model.api.xml.EmrClusterDefinitionKey)35 Test (org.junit.Test)32 EmrClusterDefinitionInformation (org.finra.herd.model.api.xml.EmrClusterDefinitionInformation)17 EmrClusterDefinitionEntity (org.finra.herd.model.jpa.EmrClusterDefinitionEntity)14 NamespaceEntity (org.finra.herd.model.jpa.NamespaceEntity)13 EmrClusterDefinition (org.finra.herd.model.api.xml.EmrClusterDefinition)9 EmrClusterDefinitionKeys (org.finra.herd.model.api.xml.EmrClusterDefinitionKeys)5 ObjectNotFoundException (org.finra.herd.model.ObjectNotFoundException)3 HashMap (java.util.HashMap)2 EmrClusterDefinitionCreateRequest (org.finra.herd.model.api.xml.EmrClusterDefinitionCreateRequest)2 EmrClusterDefinitionUpdateRequest (org.finra.herd.model.api.xml.EmrClusterDefinitionUpdateRequest)2 NodeTag (org.finra.herd.model.api.xml.NodeTag)2 ArrayList (java.util.ArrayList)1 Tuple (javax.persistence.Tuple)1 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)1 Predicate (javax.persistence.criteria.Predicate)1