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