Search in sources :

Example 1 with PerunGroup

use of cz.metacentrum.perun.ldapc.model.PerunGroup in project perun by CESNET.

the class GroupSynchronizer method synchronizeGroups.

public void synchronizeGroups() {
    PerunBl perun = (PerunBl) ldapcManager.getPerunBl();
    boolean shouldWriteExceptionLog = true;
    try {
        log.debug("Group synchronization - getting list of VOs");
        List<Vo> vos = perun.getVosManagerBl().getVos(ldapcManager.getPerunSession());
        Set<Name> presentGroups = new HashSet<Name>();
        for (Vo vo : vos) {
            try {
                log.debug("Getting list of groups for VO {}", vo);
                List<Group> groups = perun.getGroupsManagerBl().getAllGroups(ldapcManager.getPerunSession(), vo);
                for (Group group : groups) {
                    presentGroups.add(perunGroup.getEntryDN(String.valueOf(vo.getId()), String.valueOf(group.getId())));
                    log.debug("Synchronizing group {}", group);
                    log.debug("Getting list of attributes for group {}", group.getId());
                    List<Attribute> attrs = new ArrayList<Attribute>();
                    List<String> attrNames = fillPerunAttributeNames(perunGroup.getPerunAttributeNames());
                    try {
                        attrs.addAll(perun.getAttributesManagerBl().getAttributes(ldapcManager.getPerunSession(), group, attrNames));
                    } catch (PerunRuntimeException e) {
                        log.warn("Couldn't get attributes {} for group {}: {}", attrNames, group.getId(), e.getMessage());
                        shouldWriteExceptionLog = false;
                        throw new InternalErrorException(e);
                    }
                    log.debug("Got attributes {}", attrNames.toString());
                    try {
                        log.debug("Getting list of members for group {}", group.getId());
                        // List<Member> members = ldapcManager.getRpcCaller().call("groupsManager",  "getGroupMembers", params).readList(Member.class);
                        List<Member> members = perun.getGroupsManagerBl().getActiveGroupMembers(ldapcManager.getPerunSession(), group, Status.VALID);
                        log.debug("Synchronizing {} members of group {}", members.size(), group.getId());
                        // perunGroup.synchronizeMembers(group, members);
                        log.debug("Getting list of resources assigned to group {}", group.getId());
                        // List<Resource> resources = Rpc.ResourcesManager.getAssignedResources(ldapcManager.getRpcCaller(), group);
                        List<Resource> resources = perun.getResourcesManagerBl().getAssignedResources(ldapcManager.getPerunSession(), group);
                        log.debug("Synchronizing {} resources assigned to group {}", resources.size(), group.getId());
                        // perunGroup.synchronizeResources(group, resources);
                        GroupsManagerBl groupsManager = perun.getGroupsManagerBl();
                        List<Group> admin_groups = groupsManager.getGroupsWhereGroupIsAdmin(ldapcManager.getPerunSession(), group);
                        List<Vo> admin_vos = groupsManager.getVosWhereGroupIsAdmin(ldapcManager.getPerunSession(), group);
                        List<Facility> admin_facilities = groupsManager.getFacilitiesWhereGroupIsAdmin(ldapcManager.getPerunSession(), group);
                        log.debug("Synchronizing group {} as admin of {} groups, {} VOs and {} facilities", group.getId(), admin_groups.size(), admin_vos.size(), admin_facilities.size());
                        perunGroup.synchronizeGroup(group, attrs, members, resources, admin_groups, admin_vos, admin_facilities);
                    } catch (PerunRuntimeException e) {
                        log.error("Error synchronizing group", e);
                        shouldWriteExceptionLog = false;
                        throw new InternalErrorException(e);
                    }
                }
            } catch (PerunRuntimeException e) {
                if (shouldWriteExceptionLog) {
                    log.error("Error synchronizing groups", e);
                }
                shouldWriteExceptionLog = false;
                throw new InternalErrorException(e);
            }
        }
        try {
            removeOldEntries(perunGroup, presentGroups, log);
        } catch (InternalErrorException e) {
            log.error("Error removing old group entries", e);
            shouldWriteExceptionLog = false;
            throw new InternalErrorException(e);
        }
    } catch (InternalErrorException e) {
        if (shouldWriteExceptionLog) {
            log.error("Error reading list of VOs", e);
        }
        throw new InternalErrorException(e);
    }
}
Also used : Group(cz.metacentrum.perun.core.api.Group) PerunGroup(cz.metacentrum.perun.ldapc.model.PerunGroup) GroupsManagerBl(cz.metacentrum.perun.core.bl.GroupsManagerBl) Attribute(cz.metacentrum.perun.core.api.Attribute) ArrayList(java.util.ArrayList) Resource(cz.metacentrum.perun.core.api.Resource) PerunBl(cz.metacentrum.perun.core.bl.PerunBl) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) Name(javax.naming.Name) Vo(cz.metacentrum.perun.core.api.Vo) PerunRuntimeException(cz.metacentrum.perun.core.api.exceptions.rt.PerunRuntimeException) Facility(cz.metacentrum.perun.core.api.Facility) Member(cz.metacentrum.perun.core.api.Member) HashSet(java.util.HashSet)

Aggregations

Attribute (cz.metacentrum.perun.core.api.Attribute)1 Facility (cz.metacentrum.perun.core.api.Facility)1 Group (cz.metacentrum.perun.core.api.Group)1 Member (cz.metacentrum.perun.core.api.Member)1 Resource (cz.metacentrum.perun.core.api.Resource)1 Vo (cz.metacentrum.perun.core.api.Vo)1 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)1 PerunRuntimeException (cz.metacentrum.perun.core.api.exceptions.rt.PerunRuntimeException)1 GroupsManagerBl (cz.metacentrum.perun.core.bl.GroupsManagerBl)1 PerunBl (cz.metacentrum.perun.core.bl.PerunBl)1 PerunGroup (cz.metacentrum.perun.ldapc.model.PerunGroup)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Name (javax.naming.Name)1