Search in sources :

Example 1 with GroupAssignedToResource

use of cz.metacentrum.perun.audit.events.ResourceManagerEvents.GroupAssignedToResource in project perun by CESNET.

the class ResourcesManagerBlImpl method processGroupResourceActivation.

/**
 * Sets assignment status of given group and resource to ACTIVE. Check if attributes for each member
 * from group are valid. Fill members' attributes with missing values.
 *
 * @param sess session
 * @param group group
 * @param resource resource
 * @throws WrongAttributeValueException when an attribute value has wrong/illegal syntax
 * @throws WrongReferenceAttributeValueException when an attribute value has wrong/illegal semantics
 * @throws GroupResourceMismatchException when the given group and resource are not from the same VO
 * @throws GroupNotDefinedOnResourceException when there is no such group-resource assignment
 */
private void processGroupResourceActivation(PerunSession sess, Group group, Resource resource) throws GroupResourceMismatchException, WrongReferenceAttributeValueException, WrongAttributeValueException, GroupNotDefinedOnResourceException {
    getPerunBl().getAttributesManagerBl().checkGroupIsFromTheSameVoLikeResource(sess, group, resource);
    // set status as ACTIVE first because methods checkAttributesSemantics and fillAttribute need active state to work correctly
    getResourcesManagerImpl().setGroupResourceStatus(sess, group, resource, GroupResourceStatus.ACTIVE);
    // reset assignment failure cause
    getResourcesManagerImpl().setFailedGroupResourceAssignmentCause(sess, group, resource, null);
    // if there are no services, the members are empty and there is nothing more to process
    if (getAssignedServices(sess, resource).isEmpty()) {
        getPerunBl().getAuditer().log(sess, new GroupAssignedToResource(group, resource));
        return;
    }
    // get/fill/set all required group and group-resource attributes
    try {
        List<Attribute> attributes = getPerunBl().getAttributesManagerBl().getResourceRequiredAttributes(sess, resource, resource, group, true);
        attributes = getPerunBl().getAttributesManagerBl().fillAttributes(sess, resource, group, attributes, true);
        getPerunBl().getAttributesManagerBl().setAttributes(sess, resource, group, attributes, true);
    } catch (WrongAttributeAssignmentException | GroupResourceMismatchException ex) {
        throw new ConsistencyErrorException(ex);
    }
    List<Member> members = getPerunBl().getGroupsManagerBl().getGroupMembersExceptInvalidAndDisabled(sess, group);
    // get all "allowed" group members and get/fill/set required attributes for them
    Facility facility = getPerunBl().getResourcesManagerBl().getFacility(sess, resource);
    for (Member member : members) {
        User user = getPerunBl().getUsersManagerBl().getUserByMember(sess, member);
        try {
            getPerunBl().getAttributesManagerBl().setRequiredAttributes(sess, facility, resource, user, member, true);
        } catch (WrongAttributeAssignmentException | MemberResourceMismatchException | AttributeNotExistsException ex) {
            throw new ConsistencyErrorException(ex);
        }
    }
    getPerunBl().getAuditer().log(sess, new GroupAssignedToResource(group, resource));
// TODO: set and check member-group attributes
}
Also used : ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) User(cz.metacentrum.perun.core.api.User) RichUser(cz.metacentrum.perun.core.api.RichUser) ResourceSelfServiceRemovedForUser(cz.metacentrum.perun.audit.events.ResourceManagerEvents.ResourceSelfServiceRemovedForUser) Attribute(cz.metacentrum.perun.core.api.Attribute) WrongAttributeAssignmentException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException) AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException) GroupResourceMismatchException(cz.metacentrum.perun.core.api.exceptions.GroupResourceMismatchException) MemberResourceMismatchException(cz.metacentrum.perun.core.api.exceptions.MemberResourceMismatchException) GroupAssignedToResource(cz.metacentrum.perun.audit.events.ResourceManagerEvents.GroupAssignedToResource) Facility(cz.metacentrum.perun.core.api.Facility) RichMember(cz.metacentrum.perun.core.api.RichMember) AssignedMember(cz.metacentrum.perun.core.api.AssignedMember) Member(cz.metacentrum.perun.core.api.Member)

Aggregations

GroupAssignedToResource (cz.metacentrum.perun.audit.events.ResourceManagerEvents.GroupAssignedToResource)1 ResourceSelfServiceRemovedForUser (cz.metacentrum.perun.audit.events.ResourceManagerEvents.ResourceSelfServiceRemovedForUser)1 AssignedMember (cz.metacentrum.perun.core.api.AssignedMember)1 Attribute (cz.metacentrum.perun.core.api.Attribute)1 Facility (cz.metacentrum.perun.core.api.Facility)1 Member (cz.metacentrum.perun.core.api.Member)1 RichMember (cz.metacentrum.perun.core.api.RichMember)1 RichUser (cz.metacentrum.perun.core.api.RichUser)1 User (cz.metacentrum.perun.core.api.User)1 AttributeNotExistsException (cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException)1 ConsistencyErrorException (cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException)1 GroupResourceMismatchException (cz.metacentrum.perun.core.api.exceptions.GroupResourceMismatchException)1 MemberResourceMismatchException (cz.metacentrum.perun.core.api.exceptions.MemberResourceMismatchException)1 WrongAttributeAssignmentException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException)1