Search in sources :

Example 1 with PerunResource

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);
    }
}
Also used : Group(cz.metacentrum.perun.core.api.Group) Attribute(cz.metacentrum.perun.core.api.Attribute) Resource(cz.metacentrum.perun.core.api.Resource) PerunResource(cz.metacentrum.perun.ldapc.model.PerunResource) ArrayList(java.util.ArrayList) 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) HashSet(java.util.HashSet)

Aggregations

Attribute (cz.metacentrum.perun.core.api.Attribute)1 Group (cz.metacentrum.perun.core.api.Group)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 PerunBl (cz.metacentrum.perun.core.bl.PerunBl)1 PerunResource (cz.metacentrum.perun.ldapc.model.PerunResource)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Name (javax.naming.Name)1