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