Search in sources :

Example 1 with GroupAlreadyAssignedException

use of cz.metacentrum.perun.core.api.exceptions.GroupAlreadyAssignedException in project perun by CESNET.

the class ResourcesManagerBlImpl method assignGroupsToResource.

@Override
public void assignGroupsToResource(PerunSession perunSession, Iterable<Group> groups, Resource resource, boolean async, boolean assignInactive, boolean autoAssignSubgroups) throws WrongAttributeValueException, WrongReferenceAttributeValueException, GroupResourceMismatchException {
    for (Group g : groups) {
        getPerunBl().getAttributesManagerBl().checkGroupIsFromTheSameVoLikeResource(perunSession, g, resource);
        // assign source group
        try {
            getResourcesManagerImpl().assignGroupToResource(perunSession, g, resource, autoAssignSubgroups);
            setAssignedGroupStatusAndActivate(perunSession, resource, async, assignInactive, g);
        } catch (GroupAlreadyAssignedException e) {
        // silently skip
        }
        if (autoAssignSubgroups) {
            GroupsManagerBl groupsManager = getPerunBl().getGroupsManagerBl();
            List<Group> subgroups;
            // If it is 'members' group, use all groups from corresponding VO (except for members, they've been assigned already)
            if (g.getName().equals(VosManager.MEMBERS_GROUP)) {
                subgroups = groupsManager.getAllGroups(perunSession, groupsManager.getVo(perunSession, g));
                subgroups.removeIf((group -> group.getName().equals(VosManager.MEMBERS_GROUP)));
            } else {
                subgroups = groupsManager.getAllSubGroups(perunSession, g);
            }
            for (Group subgroup : subgroups) {
                try {
                    assignAutomaticGroupToResource(perunSession, g, subgroup, resource);
                } catch (GroupAlreadyAssignedException e) {
                // silently skip
                }
            }
        }
    }
}
Also used : InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) Arrays(java.util.Arrays) ResourceTag(cz.metacentrum.perun.core.api.ResourceTag) Vo(cz.metacentrum.perun.core.api.Vo) ServiceNotAssignedException(cz.metacentrum.perun.core.api.exceptions.ServiceNotAssignedException) LoggerFactory(org.slf4j.LoggerFactory) GroupResourceAssignment(cz.metacentrum.perun.core.api.GroupResourceAssignment) ServicesPackage(cz.metacentrum.perun.core.api.ServicesPackage) BanSetForResource(cz.metacentrum.perun.audit.events.ResourceManagerEvents.BanSetForResource) UserNotAdminException(cz.metacentrum.perun.core.api.exceptions.UserNotAdminException) GroupAlreadyRemovedFromResourceException(cz.metacentrum.perun.core.api.exceptions.GroupAlreadyRemovedFromResourceException) Role(cz.metacentrum.perun.core.api.Role) AssignedResource(cz.metacentrum.perun.core.api.AssignedResource) ResourceTagAlreadyAssignedException(cz.metacentrum.perun.core.api.exceptions.ResourceTagAlreadyAssignedException) Attribute(cz.metacentrum.perun.core.api.Attribute) Facility(cz.metacentrum.perun.core.api.Facility) GroupResourceStatus(cz.metacentrum.perun.core.api.GroupResourceStatus) ResourceAlreadyRemovedException(cz.metacentrum.perun.core.api.exceptions.ResourceAlreadyRemovedException) AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException) FacilityNotExistsException(cz.metacentrum.perun.core.api.exceptions.FacilityNotExistsException) RoleCannotBeManagedException(cz.metacentrum.perun.core.api.exceptions.RoleCannotBeManagedException) Collectors(java.util.stream.Collectors) User(cz.metacentrum.perun.core.api.User) Objects(java.util.Objects) VosManager(cz.metacentrum.perun.core.api.VosManager) BanUpdatedForResource(cz.metacentrum.perun.audit.events.ResourceManagerEvents.BanUpdatedForResource) GroupResourceMismatchException(cz.metacentrum.perun.core.api.exceptions.GroupResourceMismatchException) List(java.util.List) BanRemovedForResource(cz.metacentrum.perun.audit.events.ResourceManagerEvents.BanRemovedForResource) Optional(java.util.Optional) AssignedGroup(cz.metacentrum.perun.core.api.AssignedGroup) ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) RichMember(cz.metacentrum.perun.core.api.RichMember) WrongAttributeAssignmentException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException) Service(cz.metacentrum.perun.core.api.Service) MemberResourceMismatchException(cz.metacentrum.perun.core.api.exceptions.MemberResourceMismatchException) PerunBl(cz.metacentrum.perun.core.bl.PerunBl) Resource(cz.metacentrum.perun.core.api.Resource) ResourceDeleted(cz.metacentrum.perun.audit.events.ResourceManagerEvents.ResourceDeleted) Async(org.springframework.scheduling.annotation.Async) PerunSession(cz.metacentrum.perun.core.api.PerunSession) GroupNotAdminException(cz.metacentrum.perun.core.api.exceptions.GroupNotAdminException) ObjectUtils.isEmpty(org.apache.commons.lang3.ObjectUtils.isEmpty) AssignedMember(cz.metacentrum.perun.core.api.AssignedMember) AttributesManagerBl(cz.metacentrum.perun.core.bl.AttributesManagerBl) GroupResourceStatusException(cz.metacentrum.perun.core.api.exceptions.GroupResourceStatusException) ServiceRemovedFromResource(cz.metacentrum.perun.audit.events.ResourceManagerEvents.ServiceRemovedFromResource) GroupsManagerBl(cz.metacentrum.perun.core.bl.GroupsManagerBl) GroupAssignedToResource(cz.metacentrum.perun.audit.events.ResourceManagerEvents.GroupAssignedToResource) Group(cz.metacentrum.perun.core.api.Group) ArrayList(java.util.ArrayList) ResourcesManagerBl(cz.metacentrum.perun.core.bl.ResourcesManagerBl) ResourceCreated(cz.metacentrum.perun.audit.events.ResourceManagerEvents.ResourceCreated) ServiceAssignedToResource(cz.metacentrum.perun.audit.events.ResourceManagerEvents.ServiceAssignedToResource) ResourceTagNotAssignedException(cz.metacentrum.perun.core.api.exceptions.ResourceTagNotAssignedException) GroupAlreadyAssignedException(cz.metacentrum.perun.core.api.exceptions.GroupAlreadyAssignedException) ResourceUpdated(cz.metacentrum.perun.audit.events.ResourceManagerEvents.ResourceUpdated) AlreadyAdminException(cz.metacentrum.perun.core.api.exceptions.AlreadyAdminException) GroupRemovedFromResource(cz.metacentrum.perun.audit.events.ResourceManagerEvents.GroupRemovedFromResource) ResourceSelfServiceAddedForGroup(cz.metacentrum.perun.audit.events.ResourceManagerEvents.ResourceSelfServiceAddedForGroup) BanOnResource(cz.metacentrum.perun.core.api.BanOnResource) AttributeValueException(cz.metacentrum.perun.core.api.exceptions.AttributeValueException) RichResource(cz.metacentrum.perun.core.api.RichResource) RichUser(cz.metacentrum.perun.core.api.RichUser) ServiceAlreadyAssignedException(cz.metacentrum.perun.core.api.exceptions.ServiceAlreadyAssignedException) Member(cz.metacentrum.perun.core.api.Member) Logger(org.slf4j.Logger) WrongReferenceAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException) ResourceNotExistsException(cz.metacentrum.perun.core.api.exceptions.ResourceNotExistsException) AttributesManager(cz.metacentrum.perun.core.api.AttributesManager) WrongAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException) ResourceSelfServiceRemovedForGroup(cz.metacentrum.perun.audit.events.ResourceManagerEvents.ResourceSelfServiceRemovedForGroup) BanNotExistsException(cz.metacentrum.perun.core.api.exceptions.BanNotExistsException) VoNotExistsException(cz.metacentrum.perun.core.api.exceptions.VoNotExistsException) ResourceSelfServiceRemovedForUser(cz.metacentrum.perun.audit.events.ResourceManagerEvents.ResourceSelfServiceRemovedForUser) EnrichedResource(cz.metacentrum.perun.core.api.EnrichedResource) UserNotExistsException(cz.metacentrum.perun.core.api.exceptions.UserNotExistsException) BanAlreadyExistsException(cz.metacentrum.perun.core.api.exceptions.BanAlreadyExistsException) ResourceExistsException(cz.metacentrum.perun.core.api.exceptions.ResourceExistsException) ResourcesManagerImplApi(cz.metacentrum.perun.core.implApi.ResourcesManagerImplApi) Collections(java.util.Collections) Status(cz.metacentrum.perun.core.api.Status) ResourceTagNotExistsException(cz.metacentrum.perun.core.api.exceptions.ResourceTagNotExistsException) GroupNotDefinedOnResourceException(cz.metacentrum.perun.core.api.exceptions.GroupNotDefinedOnResourceException) AssignedGroup(cz.metacentrum.perun.core.api.AssignedGroup) Group(cz.metacentrum.perun.core.api.Group) ResourceSelfServiceAddedForGroup(cz.metacentrum.perun.audit.events.ResourceManagerEvents.ResourceSelfServiceAddedForGroup) ResourceSelfServiceRemovedForGroup(cz.metacentrum.perun.audit.events.ResourceManagerEvents.ResourceSelfServiceRemovedForGroup) GroupsManagerBl(cz.metacentrum.perun.core.bl.GroupsManagerBl) GroupAlreadyAssignedException(cz.metacentrum.perun.core.api.exceptions.GroupAlreadyAssignedException)

Example 2 with GroupAlreadyAssignedException

use of cz.metacentrum.perun.core.api.exceptions.GroupAlreadyAssignedException in project perun by CESNET.

the class ResourceAssignmentChecker method assignSubgroupsToResource.

/**
 * Filter subgroups of source group (with autoassign) which are not assigned and assign them.
 * Runs in transaction.
 * @param resource
 * @param automaticallyAssignedSubgroups
 * @param sourceGroup
 */
public void assignSubgroupsToResource(Resource resource, List<AssignedGroup> automaticallyAssignedSubgroups, AssignedGroup sourceGroup) {
    List<Group> sourceGroupSubgroups = perunBl.getGroupsManagerBl().getAllSubGroups(sess, sourceGroup.getEnrichedGroup().getGroup());
    sourceGroupSubgroups = sourceGroupSubgroups.stream().filter(sourceSubgroup -> automaticallyAssignedSubgroups.stream().noneMatch(assignedSubgroup -> assignedSubgroup.getSourceGroupId() == sourceGroup.getEnrichedGroup().getGroup().getId() && assignedSubgroup.getEnrichedGroup().getGroup().equals(sourceSubgroup))).collect(Collectors.toList());
    for (Group subgroup : sourceGroupSubgroups) {
        try {
            perunBl.getResourcesManagerBl().assignAutomaticGroupToResource(sess, sourceGroup.getEnrichedGroup().getGroup(), subgroup, resource);
        } catch (GroupResourceMismatchException e) {
            log.error("Cannot activate group (id = " + subgroup.getId() + ") assignment on resource " + resource, e);
        } catch (GroupAlreadyAssignedException | WrongReferenceAttributeValueException | WrongAttributeValueException e) {
        // silently skip
        }
    }
}
Also used : Resource(cz.metacentrum.perun.core.api.Resource) PerunSession(cz.metacentrum.perun.core.api.PerunSession) Logger(org.slf4j.Logger) GroupNotExistsException(cz.metacentrum.perun.core.api.exceptions.GroupNotExistsException) WrongReferenceAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException) LoggerFactory(org.slf4j.LoggerFactory) Scheduled(org.springframework.scheduling.annotation.Scheduled) WrongAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException) Collectors(java.util.stream.Collectors) Group(cz.metacentrum.perun.core.api.Group) GroupResourceMismatchException(cz.metacentrum.perun.core.api.exceptions.GroupResourceMismatchException) List(java.util.List) ExtSourcesManager(cz.metacentrum.perun.core.api.ExtSourcesManager) PerunClient(cz.metacentrum.perun.core.api.PerunClient) GroupAlreadyAssignedException(cz.metacentrum.perun.core.api.exceptions.GroupAlreadyAssignedException) GroupAlreadyRemovedFromResourceException(cz.metacentrum.perun.core.api.exceptions.GroupAlreadyRemovedFromResourceException) AssignedGroup(cz.metacentrum.perun.core.api.AssignedGroup) PerunPrincipal(cz.metacentrum.perun.core.api.PerunPrincipal) PerunBl(cz.metacentrum.perun.core.bl.PerunBl) GroupNotDefinedOnResourceException(cz.metacentrum.perun.core.api.exceptions.GroupNotDefinedOnResourceException) Group(cz.metacentrum.perun.core.api.Group) AssignedGroup(cz.metacentrum.perun.core.api.AssignedGroup) GroupAlreadyAssignedException(cz.metacentrum.perun.core.api.exceptions.GroupAlreadyAssignedException) WrongReferenceAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException) GroupResourceMismatchException(cz.metacentrum.perun.core.api.exceptions.GroupResourceMismatchException) WrongAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)

Example 3 with GroupAlreadyAssignedException

use of cz.metacentrum.perun.core.api.exceptions.GroupAlreadyAssignedException in project perun by CESNET.

the class GroupsManagerBlImpl method autoassignMovedTree.

/**
 * Checks, if moved group and subgroups should be automatically assigned to any group
 * @param sess
 * @param destinationGroup
 * @param movingGroup
 * @throws WrongReferenceAttributeValueException
 * @throws WrongAttributeValueException
 */
private void autoassignMovedTree(PerunSession sess, Group destinationGroup, Group movingGroup) throws WrongReferenceAttributeValueException, WrongAttributeValueException {
    List<AssignedResource> resourcesToAutoassign = perunBl.getResourcesManagerBl().getResourceAssignments(sess, destinationGroup, List.of()).stream().filter(AssignedResource::isAutoAssignSubgroups).collect(toList());
    for (AssignedResource resourceToAutoassign : resourcesToAutoassign) {
        Group sourceGroup;
        try {
            sourceGroup = resourceToAutoassign.getSourceGroupId() == null ? destinationGroup : this.getGroupById(sess, resourceToAutoassign.getSourceGroupId());
        } catch (GroupNotExistsException e) {
            throw new ConsistencyErrorException(e);
        }
        List<Group> groupsToAutoAssign = perunBl.getGroupsManagerBl().getAllSubGroups(sess, movingGroup);
        groupsToAutoAssign.add(movingGroup);
        for (Group groupToAutoassign : groupsToAutoAssign) {
            try {
                perunBl.getResourcesManagerBl().assignAutomaticGroupToResource(sess, sourceGroup, groupToAutoassign, resourceToAutoassign.getEnrichedResource().getResource());
            } catch (GroupAlreadyAssignedException e) {
            // skip
            } catch (GroupResourceMismatchException e) {
                log.error("Could not autoassign group " + groupToAutoassign + " to resource " + resourceToAutoassign, e);
            }
        }
    }
}
Also used : EnrichedGroup(cz.metacentrum.perun.core.api.EnrichedGroup) IndirectMemberRemovedFromGroup(cz.metacentrum.perun.audit.events.GroupManagerEvents.IndirectMemberRemovedFromGroup) CandidateGroup(cz.metacentrum.perun.core.api.CandidateGroup) RichGroup(cz.metacentrum.perun.core.api.RichGroup) MemberExpiredInGroup(cz.metacentrum.perun.audit.events.GroupManagerEvents.MemberExpiredInGroup) MemberValidatedInGroup(cz.metacentrum.perun.audit.events.GroupManagerEvents.MemberValidatedInGroup) DirectMemberRemovedFromGroup(cz.metacentrum.perun.audit.events.GroupManagerEvents.DirectMemberRemovedFromGroup) Group(cz.metacentrum.perun.core.api.Group) DirectMemberAddedToGroup(cz.metacentrum.perun.audit.events.GroupManagerEvents.DirectMemberAddedToGroup) IndirectMemberAddedToGroup(cz.metacentrum.perun.audit.events.GroupManagerEvents.IndirectMemberAddedToGroup) ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) GroupNotExistsException(cz.metacentrum.perun.core.api.exceptions.GroupNotExistsException) ParentGroupNotExistsException(cz.metacentrum.perun.core.api.exceptions.ParentGroupNotExistsException) GroupAlreadyAssignedException(cz.metacentrum.perun.core.api.exceptions.GroupAlreadyAssignedException) GroupResourceMismatchException(cz.metacentrum.perun.core.api.exceptions.GroupResourceMismatchException) AssignedResource(cz.metacentrum.perun.core.api.AssignedResource)

Example 4 with GroupAlreadyAssignedException

use of cz.metacentrum.perun.core.api.exceptions.GroupAlreadyAssignedException in project perun by CESNET.

the class GroupsManagerBlImpl method createGroup.

@Override
public Group createGroup(PerunSession sess, Group parentGroup, Group group) throws GroupExistsException, GroupRelationNotAllowed, GroupRelationAlreadyExists {
    Vo vo = this.getVo(sess, parentGroup);
    group = getGroupsManagerImpl().createGroup(sess, vo, parentGroup, group);
    try {
        parentGroup = createGroupUnion(sess, parentGroup, group, true);
    // We catch those exceptions, but they should never be thrown, so we just log them.
    } catch (WrongAttributeValueException | WrongReferenceAttributeValueException e) {
        log.error("Exception thrown in createGroup method, while it shouldn't be thrown. Cause:{}", e);
    } catch (GroupNotExistsException e) {
        throw new ConsistencyErrorException("Database consistency error while creating group: {}", e);
    }
    getPerunBl().getAuditer().log(sess, new GroupCreatedAsSubgroup(group, vo, parentGroup));
    // check if new subgroup should be automatically assigned to resources
    List<AssignedResource> assignedResources = getPerunBl().getResourcesManagerBl().getResourceAssignments(sess, parentGroup, null).stream().filter(AssignedResource::isAutoAssignSubgroups).collect(toList());
    for (AssignedResource assignedResource : assignedResources) {
        try {
            Group sourceGroup = assignedResource.getSourceGroupId() == null ? parentGroup : getPerunBl().getGroupsManagerBl().getGroupById(sess, assignedResource.getSourceGroupId());
            getPerunBl().getResourcesManagerBl().assignAutomaticGroupToResource(sess, sourceGroup, group, assignedResource.getEnrichedResource().getResource());
        } catch (GroupResourceMismatchException | GroupNotExistsException | WrongReferenceAttributeValueException | WrongAttributeValueException e) {
        // silently skip, assignment will have to be repeated after failure cause is solved
        } catch (GroupAlreadyAssignedException e) {
        // skip, periodic checker might have assigned it already
        }
    }
    return group;
}
Also used : GroupCreatedAsSubgroup(cz.metacentrum.perun.audit.events.GroupManagerEvents.GroupCreatedAsSubgroup) EnrichedGroup(cz.metacentrum.perun.core.api.EnrichedGroup) IndirectMemberRemovedFromGroup(cz.metacentrum.perun.audit.events.GroupManagerEvents.IndirectMemberRemovedFromGroup) CandidateGroup(cz.metacentrum.perun.core.api.CandidateGroup) RichGroup(cz.metacentrum.perun.core.api.RichGroup) MemberExpiredInGroup(cz.metacentrum.perun.audit.events.GroupManagerEvents.MemberExpiredInGroup) MemberValidatedInGroup(cz.metacentrum.perun.audit.events.GroupManagerEvents.MemberValidatedInGroup) DirectMemberRemovedFromGroup(cz.metacentrum.perun.audit.events.GroupManagerEvents.DirectMemberRemovedFromGroup) Group(cz.metacentrum.perun.core.api.Group) DirectMemberAddedToGroup(cz.metacentrum.perun.audit.events.GroupManagerEvents.DirectMemberAddedToGroup) IndirectMemberAddedToGroup(cz.metacentrum.perun.audit.events.GroupManagerEvents.IndirectMemberAddedToGroup) ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) GroupNotExistsException(cz.metacentrum.perun.core.api.exceptions.GroupNotExistsException) ParentGroupNotExistsException(cz.metacentrum.perun.core.api.exceptions.ParentGroupNotExistsException) GroupAlreadyAssignedException(cz.metacentrum.perun.core.api.exceptions.GroupAlreadyAssignedException) GroupResourceMismatchException(cz.metacentrum.perun.core.api.exceptions.GroupResourceMismatchException) AssignedResource(cz.metacentrum.perun.core.api.AssignedResource) WrongReferenceAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException) Vo(cz.metacentrum.perun.core.api.Vo) GroupCreatedInVo(cz.metacentrum.perun.audit.events.GroupManagerEvents.GroupCreatedInVo) WrongAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)

Aggregations

Group (cz.metacentrum.perun.core.api.Group)4 GroupAlreadyAssignedException (cz.metacentrum.perun.core.api.exceptions.GroupAlreadyAssignedException)4 GroupResourceMismatchException (cz.metacentrum.perun.core.api.exceptions.GroupResourceMismatchException)4 AssignedResource (cz.metacentrum.perun.core.api.AssignedResource)3 ConsistencyErrorException (cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException)3 GroupNotExistsException (cz.metacentrum.perun.core.api.exceptions.GroupNotExistsException)3 WrongAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)3 WrongReferenceAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException)3 DirectMemberAddedToGroup (cz.metacentrum.perun.audit.events.GroupManagerEvents.DirectMemberAddedToGroup)2 DirectMemberRemovedFromGroup (cz.metacentrum.perun.audit.events.GroupManagerEvents.DirectMemberRemovedFromGroup)2 IndirectMemberAddedToGroup (cz.metacentrum.perun.audit.events.GroupManagerEvents.IndirectMemberAddedToGroup)2 IndirectMemberRemovedFromGroup (cz.metacentrum.perun.audit.events.GroupManagerEvents.IndirectMemberRemovedFromGroup)2 MemberExpiredInGroup (cz.metacentrum.perun.audit.events.GroupManagerEvents.MemberExpiredInGroup)2 MemberValidatedInGroup (cz.metacentrum.perun.audit.events.GroupManagerEvents.MemberValidatedInGroup)2 AssignedGroup (cz.metacentrum.perun.core.api.AssignedGroup)2 PerunSession (cz.metacentrum.perun.core.api.PerunSession)2 Resource (cz.metacentrum.perun.core.api.Resource)2 GroupAlreadyRemovedFromResourceException (cz.metacentrum.perun.core.api.exceptions.GroupAlreadyRemovedFromResourceException)2 GroupNotDefinedOnResourceException (cz.metacentrum.perun.core.api.exceptions.GroupNotDefinedOnResourceException)2 PerunBl (cz.metacentrum.perun.core.bl.PerunBl)2