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