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