Search in sources :

Example 1 with EmrClusterDefinitionEntity

use of org.finra.herd.model.jpa.EmrClusterDefinitionEntity in project herd by FINRAOS.

the class EmrServiceImpl method terminateClusterImpl.

/**
 * Terminates the EMR Cluster.
 *
 * @param emrClusterAlternateKeyDto the EMR cluster alternate key
 * @param overrideTerminationProtection parameter for whether to override termination protection
 * @param emrClusterId The EMR cluster ID
 * @param accountId The account Id
 *
 * @return the terminated EMR cluster object
 * @throws Exception if there were any errors while terminating the cluster
 */
protected EmrCluster terminateClusterImpl(EmrClusterAlternateKeyDto emrClusterAlternateKeyDto, boolean overrideTerminationProtection, String emrClusterId, String accountId) throws Exception {
    AwsParamsDto awsParamsDto = emrHelper.getAwsParamsDtoByAcccountId(accountId);
    // Perform the request validation.
    validateEmrClusterKey(emrClusterAlternateKeyDto);
    // Get the namespace and ensure it exists.
    NamespaceEntity namespaceEntity = namespaceDaoHelper.getNamespaceEntity(emrClusterAlternateKeyDto.getNamespace());
    // Get the EMR cluster definition and ensure it exists.
    EmrClusterDefinitionEntity emrClusterDefinitionEntity = emrClusterDefinitionDaoHelper.getEmrClusterDefinitionEntity(emrClusterAlternateKeyDto.getNamespace(), emrClusterAlternateKeyDto.getEmrClusterDefinitionName());
    String clusterId = null;
    String clusterName = emrHelper.buildEmrClusterName(namespaceEntity.getCode(), emrClusterDefinitionEntity.getName(), emrClusterAlternateKeyDto.getEmrClusterName());
    try {
        clusterId = emrHelper.getActiveEmrClusterId(emrClusterId, clusterName, accountId);
        emrDao.terminateEmrCluster(clusterId, overrideTerminationProtection, awsParamsDto);
    } catch (AmazonServiceException ex) {
        handleAmazonException(ex, "An Amazon exception occurred while terminating EMR cluster with name \"" + clusterName + "\".");
    }
    return createEmrClusterFromRequest(clusterId, namespaceEntity.getCode(), emrClusterDefinitionEntity.getName(), emrClusterAlternateKeyDto.getEmrClusterName(), accountId, emrDao.getEmrClusterStatusById(clusterId, awsParamsDto), null, null, null);
}
Also used : AwsParamsDto(org.finra.herd.model.dto.AwsParamsDto) NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) AmazonServiceException(com.amazonaws.AmazonServiceException) EmrClusterDefinitionEntity(org.finra.herd.model.jpa.EmrClusterDefinitionEntity)

Example 2 with EmrClusterDefinitionEntity

use of org.finra.herd.model.jpa.EmrClusterDefinitionEntity in project herd by FINRAOS.

the class EmrClusterDefinitionServiceImpl method deleteEmrClusterDefinition.

@NamespacePermission(fields = "#emrClusterDefinitionKey?.namespace", permissions = NamespacePermissionEnum.WRITE)
@Override
public EmrClusterDefinitionInformation deleteEmrClusterDefinition(EmrClusterDefinitionKey emrClusterDefinitionKey) throws Exception {
    // Perform validate and trim of the EMR cluster definition key.
    emrClusterDefinitionHelper.validateEmrClusterDefinitionKey(emrClusterDefinitionKey);
    // Retrieve and ensure that a EMR cluster definition already exists with the specified key.
    EmrClusterDefinitionEntity emrClusterDefinitionEntity = emrClusterDefinitionDaoHelper.getEmrClusterDefinitionEntity(emrClusterDefinitionKey);
    // Log the existing EMR cluster definition.
    LOGGER.info("Logging EMR cluster definition being deleted. emrClusterDefinition={}", xmlHelper.objectToXml(createEmrClusterDefinitionFromEntity(emrClusterDefinitionEntity), true));
    // Delete the EMR cluster definition.
    emrClusterDefinitionDao.delete(emrClusterDefinitionEntity);
    // Create and return the EMR cluster definition object from the deleted entity.
    return createEmrClusterDefinitionFromEntity(emrClusterDefinitionEntity);
}
Also used : EmrClusterDefinitionEntity(org.finra.herd.model.jpa.EmrClusterDefinitionEntity) NamespacePermission(org.finra.herd.model.annotation.NamespacePermission)

Example 3 with EmrClusterDefinitionEntity

use of org.finra.herd.model.jpa.EmrClusterDefinitionEntity in project herd by FINRAOS.

the class EmrClusterDefinitionServiceImpl method createEmrClusterDefinitionEntity.

/**
 * Creates a new EMR cluster definition entity from the request information.
 *
 * @param namespaceEntity the namespace entity
 * @param request the EMR cluster definition create request
 *
 * @return the newly created EMR cluster definition entity
 */
private EmrClusterDefinitionEntity createEmrClusterDefinitionEntity(NamespaceEntity namespaceEntity, EmrClusterDefinitionCreateRequest request) throws Exception {
    // Convert EMR cluster configuration to the XML representation.
    String emrClusterConfiguration = xmlHelper.objectToXml(request.getEmrClusterDefinition());
    // Create a new entity.
    EmrClusterDefinitionEntity emrClusterDefinitionEntity = new EmrClusterDefinitionEntity();
    emrClusterDefinitionEntity.setNamespace(namespaceEntity);
    emrClusterDefinitionEntity.setName(request.getEmrClusterDefinitionKey().getEmrClusterDefinitionName());
    emrClusterDefinitionEntity.setConfiguration(emrClusterConfiguration);
    return emrClusterDefinitionEntity;
}
Also used : EmrClusterDefinitionEntity(org.finra.herd.model.jpa.EmrClusterDefinitionEntity)

Example 4 with EmrClusterDefinitionEntity

use of org.finra.herd.model.jpa.EmrClusterDefinitionEntity 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 5 with EmrClusterDefinitionEntity

use of org.finra.herd.model.jpa.EmrClusterDefinitionEntity in project herd by FINRAOS.

the class EmrClusterDefinitionDaoImpl method getEmrClusterDefinitionByAltKey.

@Override
public EmrClusterDefinitionEntity getEmrClusterDefinitionByAltKey(String namespaceCd, String definitionName) {
    // Create the criteria builder and the criteria.
    CriteriaBuilder builder = entityManager.getCriteriaBuilder();
    CriteriaQuery<EmrClusterDefinitionEntity> criteria = builder.createQuery(EmrClusterDefinitionEntity.class);
    // The criteria root is the EMR cluster definition.
    Root<EmrClusterDefinitionEntity> emrClusterDefinition = criteria.from(EmrClusterDefinitionEntity.class);
    // Join to the other tables we can filter on.
    Join<EmrClusterDefinitionEntity, NamespaceEntity> namespace = emrClusterDefinition.join(EmrClusterDefinitionEntity_.namespace);
    // Create the standard restrictions (i.e. the standard where clauses).
    Predicate namespaceRestriction = builder.equal(builder.upper(namespace.get(NamespaceEntity_.code)), namespaceCd.toUpperCase());
    Predicate definitionNameRestriction = builder.equal(builder.upper(emrClusterDefinition.get(EmrClusterDefinitionEntity_.name)), definitionName.toUpperCase());
    criteria.select(emrClusterDefinition).where(builder.and(namespaceRestriction, definitionNameRestriction));
    return executeSingleResultQuery(criteria, String.format("Found more than one EMR cluster definition with parameters {namespace=\"%s\", clusterDefinitionName=\"%s\"}.", namespace, definitionName));
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) EmrClusterDefinitionEntity(org.finra.herd.model.jpa.EmrClusterDefinitionEntity) Predicate(javax.persistence.criteria.Predicate)

Aggregations

EmrClusterDefinitionEntity (org.finra.herd.model.jpa.EmrClusterDefinitionEntity)31 NamespaceEntity (org.finra.herd.model.jpa.NamespaceEntity)24 Test (org.junit.Test)16 EmrClusterDefinitionKey (org.finra.herd.model.api.xml.EmrClusterDefinitionKey)14 EmrClusterDefinitionInformation (org.finra.herd.model.api.xml.EmrClusterDefinitionInformation)12 AwsParamsDto (org.finra.herd.model.dto.AwsParamsDto)6 AmazonServiceException (com.amazonaws.AmazonServiceException)5 NamespacePermission (org.finra.herd.model.annotation.NamespacePermission)4 ClusterSummary (com.amazonaws.services.elasticmapreduce.model.ClusterSummary)2 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)2 Predicate (javax.persistence.criteria.Predicate)2 EmrClusterDefinition (org.finra.herd.model.api.xml.EmrClusterDefinition)2 Parameter (org.finra.herd.model.api.xml.Parameter)2 EmrClusterAlternateKeyDto (org.finra.herd.model.dto.EmrClusterAlternateKeyDto)2 Cluster (com.amazonaws.services.elasticmapreduce.model.Cluster)1 ListInstanceFleetsResult (com.amazonaws.services.elasticmapreduce.model.ListInstanceFleetsResult)1 Step (com.amazonaws.services.elasticmapreduce.model.Step)1 StepSummary (com.amazonaws.services.elasticmapreduce.model.StepSummary)1 ArrayList (java.util.ArrayList)1 Tuple (javax.persistence.Tuple)1