use of cz.metacentrum.perun.ldapc.model.PerunResource in project perun by CESNET.
the class ResourceSynchronizer method synchronizeResources.
public void synchronizeResources() {
PerunBl perun = (PerunBl) ldapcManager.getPerunBl();
boolean shouldWriteExceptionLog = true;
try {
log.debug("Resource synchronization - getting list of VOs");
// List<Vo> vos = Rpc.VosManager.getVos(ldapcManager.getRpcCaller());
List<Vo> vos = perun.getVosManagerBl().getVos(ldapcManager.getPerunSession());
Set<Name> presentResources = new HashSet<Name>();
for (Vo vo : vos) {
try {
log.debug("Getting list of resources for VO {}", vo);
// List<Resource> resources = ldapcManager.getRpcCaller().call("resourceManager", "getResources", params).readList(Resource.class);
List<Resource> resources = perun.getResourcesManagerBl().getResources(ldapcManager.getPerunSession(), vo);
for (Resource resource : resources) {
presentResources.add(perunResource.getEntryDN(String.valueOf(vo.getId()), String.valueOf(resource.getId())));
try {
log.debug("Getting list of attributes for resource {}", resource.getId());
List<Attribute> attrs = new ArrayList<Attribute>();
/*
* replaced with single call
*
for(String attrName: fillPerunAttributeNames(perunResource.getPerunAttributeNames())) {
try {
//log.debug("Getting attribute {} for resource {}", attrName, resource.getId());
attrs.add(perun.getAttributesManager().getAttribute(ldapcManager.getPerunSession(), facility, attrName));
} catch (PerunException e) {
log.warn("No attribute {} found for resource {}: {}", attrName, resource.getId(), e.getMessage());
}
}
*/
List<String> attrNames = fillPerunAttributeNames(perunResource.getPerunAttributeNames());
try {
// log.debug("Getting attribute {} for resource {}", attrName, resource.getId());
attrs.addAll(perun.getAttributesManagerBl().getAttributes(ldapcManager.getPerunSession(), resource, attrNames));
} catch (PerunRuntimeException e) {
log.warn("No attributes {} found for resource {}: {}", attrNames, resource.getId(), e.getMessage());
shouldWriteExceptionLog = false;
throw new InternalErrorException(e);
}
log.debug("Got attributes {}", attrs.toString());
log.debug("Synchronizing resource {} with {} attrs", resource, attrs.size());
// perunResource.synchronizeEntry(resource, attrs);
log.debug("Getting list of assigned group for resource {}", resource.getId());
List<Group> assignedGroups = perun.getResourcesManagerBl().getAssignedGroups(ldapcManager.getPerunSession(), resource);
log.debug("Synchronizing {} groups for resource {}", assignedGroups.size(), resource.getId());
// perunResource.synchronizeGroups(resource, assignedGroups);
perunResource.synchronizeResource(resource, attrs, assignedGroups);
} catch (PerunRuntimeException e) {
if (shouldWriteExceptionLog) {
log.error("Error synchronizing resource", e);
}
shouldWriteExceptionLog = false;
throw new InternalErrorException(e);
}
}
} catch (PerunRuntimeException e) {
if (shouldWriteExceptionLog) {
log.error("Error synchronizing resources", e);
}
shouldWriteExceptionLog = false;
throw new InternalErrorException(e);
}
}
try {
removeOldEntries(perunResource, presentResources, log);
} catch (InternalErrorException e) {
log.error("Error removing old resource entries", e);
shouldWriteExceptionLog = false;
throw new InternalErrorException(e);
}
} catch (InternalErrorException e) {
if (shouldWriteExceptionLog) {
log.error("Error getting VO list", e);
}
throw new InternalErrorException(e);
}
}
Aggregations