use of org.finra.herd.model.annotation.NamespacePermission in project herd by FINRAOS.
the class EmrClusterDefinitionServiceImpl method getEmrClusterDefinition.
@NamespacePermission(fields = "#emrClusterDefinitionKey?.namespace", permissions = NamespacePermissionEnum.READ)
@Override
public EmrClusterDefinitionInformation getEmrClusterDefinition(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 exists with the specified key.
EmrClusterDefinitionEntity emrClusterDefinitionEntity = emrClusterDefinitionDaoHelper.getEmrClusterDefinitionEntity(emrClusterDefinitionKey);
// Create and return the EMR cluster definition object from the persisted entity.
return createEmrClusterDefinitionFromEntity(emrClusterDefinitionEntity);
}
use of org.finra.herd.model.annotation.NamespacePermission in project herd by FINRAOS.
the class EmrClusterDefinitionServiceImpl method createEmrClusterDefinition.
@NamespacePermission(fields = "#request?.emrClusterDefinitionKey?.namespace", permissions = NamespacePermissionEnum.WRITE)
@Override
public EmrClusterDefinitionInformation createEmrClusterDefinition(EmrClusterDefinitionCreateRequest request) throws Exception {
// Perform validate and trim of the EMR cluster definition key.
emrClusterDefinitionHelper.validateEmrClusterDefinitionKey(request.getEmrClusterDefinitionKey());
// Validate the EMR cluster definition configuration.
emrClusterDefinitionHelper.validateEmrClusterDefinitionConfiguration(request.getEmrClusterDefinition());
// Get the namespace and ensure it exists.
NamespaceEntity namespaceEntity = namespaceDaoHelper.getNamespaceEntity(request.getEmrClusterDefinitionKey().getNamespace());
namespaceIamRoleAuthorizationHelper.checkPermissions(namespaceEntity, request.getEmrClusterDefinition().getServiceIamRole(), request.getEmrClusterDefinition().getEc2NodeIamProfileName());
// Ensure a EMR cluster definition with the specified name doesn't already exist.
EmrClusterDefinitionEntity emrClusterDefinitionEntity = emrClusterDefinitionDao.getEmrClusterDefinitionByAltKey(request.getEmrClusterDefinitionKey());
if (emrClusterDefinitionEntity != null) {
throw new AlreadyExistsException(String.format("Unable to create EMR cluster definition with name \"%s\" for namespace \"%s\" because it already exists.", request.getEmrClusterDefinitionKey().getEmrClusterDefinitionName(), request.getEmrClusterDefinitionKey().getNamespace()));
}
// Create a EMR cluster definition entity from the request information.
emrClusterDefinitionEntity = createEmrClusterDefinitionEntity(namespaceEntity, request);
// Persist the new entity.
emrClusterDefinitionEntity = emrClusterDefinitionDao.saveAndRefresh(emrClusterDefinitionEntity);
// Create and return the EMR cluster definition object from the persisted entity.
return createEmrClusterDefinitionFromEntity(emrClusterDefinitionEntity);
}
use of org.finra.herd.model.annotation.NamespacePermission in project herd by FINRAOS.
the class EmrClusterDefinitionServiceImpl method updateEmrClusterDefinition.
@NamespacePermission(fields = "#emrClusterDefinitionKey?.namespace", permissions = NamespacePermissionEnum.WRITE)
@Override
public EmrClusterDefinitionInformation updateEmrClusterDefinition(EmrClusterDefinitionKey emrClusterDefinitionKey, EmrClusterDefinitionUpdateRequest request) throws Exception {
// Perform validate and trim of the EMR cluster definition key.
emrClusterDefinitionHelper.validateEmrClusterDefinitionKey(emrClusterDefinitionKey);
// Validate the EMR cluster definition configuration.
emrClusterDefinitionHelper.validateEmrClusterDefinitionConfiguration(request.getEmrClusterDefinition());
// Retrieve and ensure that a EMR cluster definition already exists with the specified name.
EmrClusterDefinitionEntity emrClusterDefinitionEntity = emrClusterDefinitionDaoHelper.getEmrClusterDefinitionEntity(emrClusterDefinitionKey);
namespaceIamRoleAuthorizationHelper.checkPermissions(emrClusterDefinitionEntity.getNamespace(), request.getEmrClusterDefinition().getServiceIamRole(), request.getEmrClusterDefinition().getEc2NodeIamProfileName());
// Log the existing EMR cluster definition before the update.
LOGGER.info("Logging EMR cluster definition before the update. emrClusterDefinition={}", xmlHelper.objectToXml(createEmrClusterDefinitionFromEntity(emrClusterDefinitionEntity), true));
// Convert EMR cluster configuration to the XML representation.
String emrClusterConfiguration = xmlHelper.objectToXml(request.getEmrClusterDefinition());
// Update the EMR cluster definition entity.
emrClusterDefinitionEntity.setConfiguration(emrClusterConfiguration);
// Persist and refresh the entity.
emrClusterDefinitionEntity = emrClusterDefinitionDao.saveAndRefresh(emrClusterDefinitionEntity);
// Create and return the EMR cluster definition object from the persisted entity.
return createEmrClusterDefinitionFromEntity(emrClusterDefinitionEntity);
}
use of org.finra.herd.model.annotation.NamespacePermission in project herd by FINRAOS.
the class AllowedAttributeValueServiceImpl method deleteAllowedAttributeValues.
/**
* Deletes specified allowed attribute values from an existing attribute value list which is identified by name.
*
* @param request the information needed to delete the allowed attribute values
*
* @return the allowed attribute values that got deleted
*/
@NamespacePermission(fields = "#request.attributeValueListKey.namespace", permissions = NamespacePermissionEnum.WRITE)
@Override
public AllowedAttributeValuesInformation deleteAllowedAttributeValues(AllowedAttributeValuesDeleteRequest request) {
// Perform request validation and trim request parameters.
validateAllowedAttributeValuesDeleteRequest(request);
// Retrieve and ensure that a attribute value list exists with the specified name.
AttributeValueListEntity attributeValueListEntity = attributeValueListDaoHelper.getAttributeValueListEntity(request.getAttributeValueListKey());
// Load all existing allowed attribute value entities into a map for quick access.
Map<String, AllowedAttributeValueEntity> allowedAttributeValueEntityMap = getAllowedAttributeValueEntityMap(attributeValueListEntity.getAllowedAttributeValues());
// Build a list of all allowed attribute value entities to be deleted.
Collection<AllowedAttributeValueEntity> deletedAllowedAttributeValueEntities = new ArrayList<>();
for (String allowedAttributeValue : request.getAllowedAttributeValues()) {
// Find the relative allowed attribute entity.
AllowedAttributeValueEntity allowedAttributeValueEntity = allowedAttributeValueEntityMap.get(allowedAttributeValue);
if (allowedAttributeValueEntity != null) {
deletedAllowedAttributeValueEntities.add(allowedAttributeValueEntity);
} else {
throw new ObjectNotFoundException(String.format("Allowed attribute value \"%s\" doesn't exist in \"%s\" attribute value list.", allowedAttributeValue, attributeValueListEntity.getName()));
}
}
// Perform the actual deletion.
for (AllowedAttributeValueEntity allowedAttributeValueEntity : deletedAllowedAttributeValueEntities) {
attributeValueListEntity.getAllowedAttributeValues().remove(allowedAttributeValueEntity);
}
allowedAttributeValueDao.saveAndRefresh(attributeValueListEntity);
return createAllowedAttributeValuesInformationFromEntities(attributeValueListEntity, deletedAllowedAttributeValueEntities);
}
use of org.finra.herd.model.annotation.NamespacePermission in project herd by FINRAOS.
the class AllowedAttributeValueServiceImpl method createAllowedAttributeValues.
/**
* Creates a list of allowed attribute values for an existing attribute value list key.
*
* @param request the information needed to create the allowed attribute values
*
* @return the newly created allowed attribute values
*/
@NamespacePermission(fields = "#request.attributeValueListKey.namespace", permissions = NamespacePermissionEnum.WRITE)
@Override
public AllowedAttributeValuesInformation createAllowedAttributeValues(AllowedAttributeValuesCreateRequest request) {
// Perform request validation and trim request parameters.
validateAllowedAttributeValuesCreateRequest(request);
// Retrieve and ensure that a attribute value list exists with the specified name.
AttributeValueListEntity attributeValueListEntity = attributeValueListDaoHelper.getAttributeValueListEntity(request.getAttributeValueListKey());
// Load all existing allowed attribute value entities into a map for quick access.
Map<String, AllowedAttributeValueEntity> allowedAttributeValueEntityMap = getAllowedAttributeValueEntityMap(attributeValueListEntity.getAllowedAttributeValues());
// Fail if any of the allowed attribute values to be created already exist.
for (String allowedAttributeValue : request.getAllowedAttributeValues()) {
if (allowedAttributeValueEntityMap.containsKey(allowedAttributeValue)) {
throw new AlreadyExistsException(String.format("Allowed attribute value \"%s\" already exists in \"%s\" attribute value list.", allowedAttributeValue, attributeValueListEntity.getName()));
}
}
// Create and persist the allowed attribute value entities.
Collection<AllowedAttributeValueEntity> createdAllowedAttributeValueEntities = new ArrayList<>();
for (String allowedAttributeValue : request.getAllowedAttributeValues()) {
AllowedAttributeValueEntity allowedAttributeValueEntity = new AllowedAttributeValueEntity();
createdAllowedAttributeValueEntities.add(allowedAttributeValueEntity);
allowedAttributeValueEntity.setAttributeValueList(attributeValueListEntity);
allowedAttributeValueEntity.setAllowedAttributeValue(allowedAttributeValue);
allowedAttributeValueDao.saveAndRefresh(allowedAttributeValueEntity);
}
allowedAttributeValueDao.saveAndRefresh(attributeValueListEntity);
return createAllowedAttributeValuesInformationFromEntities(attributeValueListEntity, createdAllowedAttributeValueEntities);
}
Aggregations