Search in sources :

Example 11 with NamespaceEntity

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

the class NamespaceServiceImpl method createNamespace.

@Override
public Namespace createNamespace(NamespaceCreateRequest request) {
    // Perform the validation.
    validateNamespaceCreateRequest(request);
    // Get the namespace key.
    NamespaceKey namespaceKey = new NamespaceKey(request.getNamespaceCode());
    // Ensure a namespace with the specified namespace key doesn't already exist.
    NamespaceEntity namespaceEntity = namespaceDao.getNamespaceByKey(namespaceKey);
    if (namespaceEntity != null) {
        throw new AlreadyExistsException(String.format("Unable to create namespace \"%s\" because it already exists.", namespaceKey.getNamespaceCode()));
    }
    // Create a namespace entity from the request information.
    namespaceEntity = createNamespaceEntity(request);
    // Persist the new entity.
    namespaceEntity = namespaceDao.saveAndRefresh(namespaceEntity);
    // Create and return the namespace object from the persisted entity.
    return createNamespaceFromEntity(namespaceEntity);
}
Also used : NamespaceKey(org.finra.herd.model.api.xml.NamespaceKey) NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) AlreadyExistsException(org.finra.herd.model.AlreadyExistsException)

Example 12 with NamespaceEntity

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

the class NamespaceServiceImpl method deleteNamespace.

@Override
public Namespace deleteNamespace(NamespaceKey namespaceKey) {
    // Perform validation and trim.
    namespaceHelper.validateNamespaceKey(namespaceKey);
    // Retrieve and ensure that a namespace already exists with the specified key.
    NamespaceEntity namespaceEntity = namespaceDaoHelper.getNamespaceEntity(namespaceKey.getNamespaceCode());
    // Delete the namespace.
    namespaceDao.delete(namespaceEntity);
    // Create and return the namespace object from the deleted entity.
    return createNamespaceFromEntity(namespaceEntity);
}
Also used : NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity)

Example 13 with NamespaceEntity

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

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

the class JobServiceImpl method createAndStartJob.

@NamespacePermission(fields = "#request?.namespace", permissions = NamespacePermissionEnum.EXECUTE)
@Override
public Job createAndStartJob(JobCreateRequest request) throws Exception {
    // Perform the validation.
    validateJobCreateRequest(request);
    // Get the namespace and ensure it exists.
    NamespaceEntity namespaceEntity = namespaceDaoHelper.getNamespaceEntity(request.getNamespace());
    // Get the job definition and ensure it exists.
    JobDefinitionEntity jobDefinitionEntity = jobDefinitionDao.getJobDefinitionByAltKey(request.getNamespace(), request.getJobName());
    if (jobDefinitionEntity == null) {
        throw new ObjectNotFoundException("Job definition with name \"" + request.getJobName() + "\" doesn't exist for namespace \"" + request.getNamespace() + "\".");
    }
    // Build the parameters map
    Map<String, Object> mergedParameters = getParameters(jobDefinitionEntity, request);
    // Create a process instance holder to check for a handle to the process instance once it is created.
    String processDefinitionId = jobDefinitionEntity.getActivitiId();
    ProcessDefinition processDefinition = activitiService.getProcessDefinitionById(processDefinitionId);
    Assert.notNull(processDefinition, "No process definition found for Id: " + processDefinitionId);
    Assert.isTrue(!processDefinition.isSuspended(), "Cannot start process instance for process definition Id: " + processDefinitionId + " because it is suspended.");
    ProcessInstance processInstance = activitiService.startProcessInstanceByProcessDefinitionId(processDefinitionId, mergedParameters);
    // If we get here, we have a newly created process instance. Log to know it was created successfully.
    LOGGER.info("Created process instance with Id: " + processInstance.getProcessInstanceId() + " for process definition Id: " + processDefinitionId + " with merged parameters: " + mergedParameters);
    // Create and return the job object.
    return createJobFromRequest(namespaceEntity.getCode(), jobDefinitionEntity.getName(), mergedParameters, processInstance.getProcessInstanceId());
}
Also used : JobDefinitionEntity(org.finra.herd.model.jpa.JobDefinitionEntity) NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) ObjectNotFoundException(org.finra.herd.model.ObjectNotFoundException) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) NamespacePermission(org.finra.herd.model.annotation.NamespacePermission)

Example 15 with NamespaceEntity

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

the class NamespaceIamRoleAuthorizationServiceImpl method deleteNamespaceIamRoleAuthorization.

@NamespacePermission(fields = "#namespace", permissions = NamespacePermissionEnum.GRANT)
@Override
public NamespaceIamRoleAuthorization deleteNamespaceIamRoleAuthorization(String namespace) {
    Assert.hasText(namespace, "Namespace must be specified");
    NamespaceEntity namespaceEntity = namespaceDaoHelper.getNamespaceEntity(namespace.trim());
    List<NamespaceIamRoleAuthorizationEntity> namespaceIamRoleAuthorizationEntities = getNamespaeIamRoleAuthorizationEntities(namespaceEntity);
    NamespaceIamRoleAuthorization result = new NamespaceIamRoleAuthorization(namespaceEntity.getCode(), new ArrayList<>());
    for (NamespaceIamRoleAuthorizationEntity namespaceIamRoleAuthorizationEntity : namespaceIamRoleAuthorizationEntities) {
        namespaceIamRoleAuthorizationDao.delete(namespaceIamRoleAuthorizationEntity);
        result.getIamRoles().add(new IamRole(namespaceIamRoleAuthorizationEntity.getIamRoleName(), namespaceIamRoleAuthorizationEntity.getDescription()));
    }
    return result;
}
Also used : NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) NamespaceIamRoleAuthorization(org.finra.herd.model.api.xml.NamespaceIamRoleAuthorization) IamRole(org.finra.herd.model.api.xml.IamRole) NamespaceIamRoleAuthorizationEntity(org.finra.herd.model.jpa.NamespaceIamRoleAuthorizationEntity) NamespacePermission(org.finra.herd.model.annotation.NamespacePermission)

Aggregations

NamespaceEntity (org.finra.herd.model.jpa.NamespaceEntity)225 Test (org.junit.Test)139 ArrayList (java.util.ArrayList)63 EmrClusterCreateRequest (org.finra.herd.model.api.xml.EmrClusterCreateRequest)59 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)43 EmrClusterDefinition (org.finra.herd.model.api.xml.EmrClusterDefinition)40 Predicate (javax.persistence.criteria.Predicate)39 BusinessObjectDefinitionEntity (org.finra.herd.model.jpa.BusinessObjectDefinitionEntity)38 EmrCluster (org.finra.herd.model.api.xml.EmrCluster)32 FileTypeEntity (org.finra.herd.model.jpa.FileTypeEntity)25 EmrClusterDefinitionEntity (org.finra.herd.model.jpa.EmrClusterDefinitionEntity)24 NamespaceIamRoleAuthorizationEntity (org.finra.herd.model.jpa.NamespaceIamRoleAuthorizationEntity)24 JobDefinitionEntity (org.finra.herd.model.jpa.JobDefinitionEntity)18 AlreadyExistsException (org.finra.herd.model.AlreadyExistsException)16 BusinessObjectDefinitionKey (org.finra.herd.model.api.xml.BusinessObjectDefinitionKey)14 EmrClusterDefinitionKey (org.finra.herd.model.api.xml.EmrClusterDefinitionKey)13 AttributeValueListEntity (org.finra.herd.model.jpa.AttributeValueListEntity)13 BusinessObjectFormatEntity (org.finra.herd.model.jpa.BusinessObjectFormatEntity)13 StorageEntity (org.finra.herd.model.jpa.StorageEntity)13 EmrClusterDefinitionInformation (org.finra.herd.model.api.xml.EmrClusterDefinitionInformation)12