Search in sources :

Example 1 with PerunFacility

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

the class FacilitySynchronizer method synchronizeFacilities.

public void synchronizeFacilities() {
    PerunBl perun = (PerunBl) ldapcManager.getPerunBl();
    Set<Name> presentFacilities = new HashSet<Name>();
    boolean shouldWriteExceptionLog = true;
    try {
        log.debug("Getting list of facilities");
        List<Facility> facilities = perun.getFacilitiesManagerBl().getFacilities(ldapcManager.getPerunSession());
        for (Facility facility : facilities) {
            presentFacilities.add(perunFacility.getEntryDN(String.valueOf(facility.getId())));
            try {
                log.debug("Synchronizing facility {}", facility);
                log.debug("Getting list of attributes for facility {}", facility.getId());
                List<Attribute> attrs = new ArrayList<Attribute>();
                List<String> attrNames = fillPerunAttributeNames(perunFacility.getPerunAttributeNames());
                try {
                    // log.debug("Getting attribute {} for resource {}", attrName, resource.getId());
                    attrs.addAll(perun.getAttributesManagerBl().getAttributes(ldapcManager.getPerunSession(), facility, attrNames));
                } catch (PerunRuntimeException e) {
                    log.warn("No attributes {} found for facility {}: {}", attrNames, facility.getId(), e.getMessage());
                    shouldWriteExceptionLog = false;
                    throw new InternalErrorException(e);
                }
                log.debug("Got attributes {}", attrs.toString());
                perunFacility.synchronizeFacility(facility, attrs);
            } catch (PerunRuntimeException e) {
                if (shouldWriteExceptionLog) {
                    log.error("Error synchronizing facility", e);
                }
                shouldWriteExceptionLog = false;
                throw new InternalErrorException(e);
            }
        }
        try {
            removeOldEntries(perunFacility, presentFacilities, log);
        } catch (InternalErrorException e) {
            log.error("Error removing old facility entries", e);
            shouldWriteExceptionLog = false;
            throw new InternalErrorException(e);
        }
    } catch (PerunRuntimeException e) {
        if (shouldWriteExceptionLog) {
            log.error("Error reading list of facilities", e);
        }
        throw new InternalErrorException(e);
    }
}
Also used : Attribute(cz.metacentrum.perun.core.api.Attribute) ArrayList(java.util.ArrayList) PerunBl(cz.metacentrum.perun.core.bl.PerunBl) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) Name(javax.naming.Name) PerunRuntimeException(cz.metacentrum.perun.core.api.exceptions.rt.PerunRuntimeException) Facility(cz.metacentrum.perun.core.api.Facility) PerunFacility(cz.metacentrum.perun.ldapc.model.PerunFacility) HashSet(java.util.HashSet)

Aggregations

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