Search in sources :

Example 1 with MemberResourceMismatchException

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

the class ResourcesManagerBlImpl method assignServices.

@Override
public void assignServices(PerunSession sess, Resource resource, List<Service> services) throws ServiceAlreadyAssignedException, WrongAttributeValueException, WrongReferenceAttributeValueException {
    for (Service service : services) {
        getResourcesManagerImpl().assignService(sess, resource, service);
        getPerunBl().getAuditer().log(sess, new ServiceAssignedToResource(service, resource));
    }
    boolean requiresAttributes = services.stream().anyMatch(s -> !getPerunBl().getAttributesManagerBl().getRequiredAttributesDefinition(sess, s).isEmpty());
    if (!requiresAttributes) {
        // there are new no attributes to check or add
        return;
    }
    try {
        fillAndSetRequiredAttributesForGroups(sess, services, resource);
        checkSemanticsOfFacilityAndResourceRequiredAttributes(sess, resource);
        updateAllRequiredAttributesForAllowedMembers(sess, resource, services);
    } catch (WrongAttributeAssignmentException | GroupResourceMismatchException | MemberResourceMismatchException | AttributeNotExistsException e) {
        throw new ConsistencyErrorException(e);
    }
}
Also used : ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) MemberResourceMismatchException(cz.metacentrum.perun.core.api.exceptions.MemberResourceMismatchException) ServiceAssignedToResource(cz.metacentrum.perun.audit.events.ResourceManagerEvents.ServiceAssignedToResource) WrongAttributeAssignmentException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException) AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException) Service(cz.metacentrum.perun.core.api.Service) GroupResourceMismatchException(cz.metacentrum.perun.core.api.exceptions.GroupResourceMismatchException)

Example 2 with MemberResourceMismatchException

use of cz.metacentrum.perun.core.api.exceptions.MemberResourceMismatchException 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)

Example 3 with MemberResourceMismatchException

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

the class GroupsManagerBlImpl method setRequiredAttributes.

/**
 * Set required attributes when adding new direct or indirect members.
 * @param sess perun session
 * @param member member
 * @param group group
 * @throws InternalErrorException
 * @throws WrongAttributeValueException
 * @throws WrongReferenceAttributeValueException
 */
private void setRequiredAttributes(PerunSession sess, Member member, Group group) throws WrongAttributeValueException, WrongReferenceAttributeValueException {
    // setting required attributes
    User user = getPerunBl().getUsersManagerBl().getUserByMember(sess, member);
    List<Resource> resources = getPerunBl().getResourcesManagerBl().getAssignedResources(sess, group);
    for (Resource resource : resources) {
        Facility facility = getPerunBl().getResourcesManagerBl().getFacility(sess, resource);
        // check members attributes
        try {
            getPerunBl().getAttributesManagerBl().setRequiredAttributes(sess, facility, resource, user, member);
        } catch (WrongAttributeAssignmentException | AttributeNotExistsException | MemberResourceMismatchException ex) {
            throw new ConsistencyErrorException(ex);
        }
    }
}
Also used : ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) User(cz.metacentrum.perun.core.api.User) RichUser(cz.metacentrum.perun.core.api.RichUser) MemberResourceMismatchException(cz.metacentrum.perun.core.api.exceptions.MemberResourceMismatchException) WrongAttributeAssignmentException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException) AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException) AssignedResource(cz.metacentrum.perun.core.api.AssignedResource) Resource(cz.metacentrum.perun.core.api.Resource) Facility(cz.metacentrum.perun.core.api.Facility)

Example 4 with MemberResourceMismatchException

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

the class AttributesManagerBlImpl method checkMemberIsFromTheSameVoLikeResource.

/**
 * Check if member is assigned on resource. If not, throw MemberResourceMismatchException Exception
 */
private void checkMemberIsFromTheSameVoLikeResource(PerunSession sess, Member member, Resource resource) throws MemberResourceMismatchException {
    Utils.notNull(sess, "sess");
    Utils.notNull(member, "member");
    Utils.notNull(resource, "resource");
    if (member.getVoId() != resource.getVoId())
        throw new MemberResourceMismatchException("Member is not from the same vo like Resource: " + member + " " + resource);
}
Also used : MemberResourceMismatchException(cz.metacentrum.perun.core.api.exceptions.MemberResourceMismatchException)

Example 5 with MemberResourceMismatchException

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

the class MembersManagerBlImpl method moveMembersAttributes.

/**
 * Moves member related attributes from source member to target member.
 *
 * @param sess
 * @param vo VO where sourceUser and targetUser are members
 * @param sourceMember member to move attributes from
 * @param targetMember member to move attributes to
 * @param groups groups for which move member-group attributes
 */
private void moveMembersAttributes(PerunSession sess, Vo vo, Member sourceMember, Member targetMember, List<Group> groups) {
    try {
        // set member attributes
        List<Attribute> memberAttributes = getPerunBl().getAttributesManagerBl().getAttributes(sess, sourceMember);
        for (Attribute attribute : memberAttributes) {
            if (!getPerunBl().getAttributesManagerBl().isVirtAttribute(sess, attribute) && !getPerunBl().getAttributesManagerBl().isCoreAttribute(sess, attribute))
                getPerunBl().getAttributesManagerBl().setAttribute(sess, targetMember, attribute);
        }
        // set member-group attributes
        for (Group group : groups) {
            List<Attribute> groupMemberAttributes = getPerunBl().getAttributesManagerBl().getAttributes(sess, sourceMember, group);
            for (Attribute attribute : groupMemberAttributes) {
                if (!getPerunBl().getAttributesManagerBl().isVirtAttribute(sess, attribute)) {
                    getPerunBl().getAttributesManagerBl().setAttribute(sess, targetMember, group, attribute);
                }
            }
        }
        // set member-resource attributes
        List<Resource> resources = getPerunBl().getResourcesManagerBl().getResources(sess, vo);
        for (Resource resource : resources) {
            List<Attribute> memberResourceAttributes = getPerunBl().getAttributesManagerBl().getAttributes(sess, sourceMember, resource);
            for (Attribute attribute : memberResourceAttributes) {
                if (!getPerunBl().getAttributesManagerBl().isVirtAttribute(sess, attribute)) {
                    getPerunBl().getAttributesManagerBl().setAttribute(sess, targetMember, resource, attribute);
                }
            }
        }
    } catch (WrongAttributeValueException | WrongAttributeAssignmentException | WrongReferenceAttributeValueException | MemberGroupMismatchException | MemberResourceMismatchException e) {
        throw new InternalErrorException(e);
    }
}
Also used : Group(cz.metacentrum.perun.core.api.Group) MemberGroupMismatchException(cz.metacentrum.perun.core.api.exceptions.MemberGroupMismatchException) MemberResourceMismatchException(cz.metacentrum.perun.core.api.exceptions.MemberResourceMismatchException) Attribute(cz.metacentrum.perun.core.api.Attribute) WrongAttributeAssignmentException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException) WrongReferenceAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException) Resource(cz.metacentrum.perun.core.api.Resource) BanOnResource(cz.metacentrum.perun.core.api.BanOnResource) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) WrongAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)

Aggregations

MemberResourceMismatchException (cz.metacentrum.perun.core.api.exceptions.MemberResourceMismatchException)17 ConsistencyErrorException (cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException)13 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)11 WrongAttributeAssignmentException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException)10 Attribute (cz.metacentrum.perun.core.api.Attribute)8 Member (cz.metacentrum.perun.core.api.Member)8 AttributeNotExistsException (cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException)8 WrongAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)8 Resource (cz.metacentrum.perun.core.api.Resource)7 ArrayList (java.util.ArrayList)6 Vo (cz.metacentrum.perun.core.api.Vo)5 Facility (cz.metacentrum.perun.core.api.Facility)4 ServiceAttributes (cz.metacentrum.perun.core.api.ServiceAttributes)4 User (cz.metacentrum.perun.core.api.User)4 WrongReferenceAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException)4 BanOnResource (cz.metacentrum.perun.core.api.BanOnResource)3 Group (cz.metacentrum.perun.core.api.Group)3 Pair (cz.metacentrum.perun.core.api.Pair)3 HashMap (java.util.HashMap)3 LinkedHashMap (java.util.LinkedHashMap)3