use of cz.metacentrum.perun.audit.events.ResourceManagerEvents.GroupRemovedFromResource in project perun by CESNET.
the class ResourcesManagerBlImpl method removeGroupFromResource.
/**
* Remove group from a resource. Remove subgroups automatic assignments.
* After removing, check attributes and fix them if it is needed.
*
* @param sess
* @param group
* @param resource
* @param sourceGroupId id of a source group if an automatic assignment should be deleted, null otherwise
* @throws GroupNotDefinedOnResourceException when there is no such group-resource assignment
* @throws GroupAlreadyRemovedFromResourceException when the assignment was already removed
*/
private void removeGroupFromResource(PerunSession sess, Group group, Resource resource, Integer sourceGroupId) throws GroupNotDefinedOnResourceException, GroupAlreadyRemovedFromResourceException {
Vo groupVo = getPerunBl().getGroupsManagerBl().getVo(sess, group);
// Check if the group and resource belongs to the same VO
if (!groupVo.equals(this.getVo(sess, resource))) {
throw new InternalErrorException("Group " + group + " and resource " + resource + " belongs to the different VOs");
}
// Check if the group-resource assignment is defined
Optional<AssignedGroup> assignmentToRemove = getResourcesManagerImpl().getGroupAssignments(sess, resource).stream().filter(assignedGroup -> assignedGroup.getEnrichedGroup().getGroup().equals(group) && Objects.equals(assignedGroup.getSourceGroupId(), sourceGroupId)).findFirst();
if (assignmentToRemove.isEmpty()) {
// Group is not defined on the resource
throw new GroupNotDefinedOnResourceException(group.getName());
}
// Remove group
if (sourceGroupId != null) {
getResourcesManagerImpl().removeAutomaticGroupFromResource(sess, group, resource, sourceGroupId);
} else {
getResourcesManagerImpl().removeGroupFromResource(sess, group, resource);
// Remove automatically assigned subgroups
List<AssignedGroup> subgroupsAssignments = getResourcesManagerImpl().getGroupAssignments(sess, resource).stream().filter(assignedGroup -> Objects.equals(assignedGroup.getSourceGroupId(), group.getId())).collect(Collectors.toList());
for (AssignedGroup assignedSubgroup : subgroupsAssignments) {
try {
removeAutomaticGroupFromResource(sess, assignedSubgroup.getEnrichedGroup().getGroup(), resource, group.getId());
} catch (GroupAlreadyRemovedFromResourceException e) {
// skip silently
}
}
}
// If it was the last ACTIVE assignment, we can delete group-resource attributes and audit the removal
if (!isGroupAssigned(sess, resource, group)) {
getPerunBl().getAuditer().log(sess, new GroupRemovedFromResource(group, resource));
// Remove group-resource attributes
try {
getPerunBl().getAttributesManagerBl().removeAllAttributes(sess, resource, group);
} catch (WrongAttributeValueException | WrongReferenceAttributeValueException e) {
throw new InternalErrorException(e);
} catch (GroupResourceMismatchException ex) {
throw new ConsistencyErrorException(ex);
}
}
// FIXME - here we should call checkSemantics() and on error re-fill/set user-facility attributes
// for the group members of removed group, which are still allowed on the facility, since we removed
// one relation and attribute constraints might have changed (eg. for shell / default gid/group).
// We don't do this for performance reasons.
}
use of cz.metacentrum.perun.audit.events.ResourceManagerEvents.GroupRemovedFromResource in project perun by CESNET.
the class ResourcesManagerBlImpl method deactivateGroupResourceAssignment.
@Override
public void deactivateGroupResourceAssignment(PerunSession sess, Group group, Resource resource) throws GroupNotDefinedOnResourceException, GroupResourceStatusException {
GroupResourceStatus status = getResourcesManagerImpl().getGroupResourceStatus(sess, group, resource);
if (status == GroupResourceStatus.PROCESSING) {
throw new GroupResourceStatusException("Cannot deactivate an assignment in PROCESSING state.");
}
getResourcesManagerImpl().setGroupResourceStatus(sess, group, resource, GroupResourceStatus.INACTIVE);
getPerunBl().getAuditer().log(sess, new GroupRemovedFromResource(group, resource));
// reset assignment failure cause
getResourcesManagerImpl().setFailedGroupResourceAssignmentCause(sess, group, resource, null);
}
Aggregations