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);
}
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);
}
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;
}
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());
}
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));
}
Aggregations