Search in sources :

Example 6 with PerunRuntimeException

use of cz.metacentrum.perun.core.api.exceptions.rt.PerunRuntimeException 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

InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)6 PerunRuntimeException (cz.metacentrum.perun.core.api.exceptions.rt.PerunRuntimeException)6 ArrayList (java.util.ArrayList)6 Attribute (cz.metacentrum.perun.core.api.Attribute)5 PerunBl (cz.metacentrum.perun.core.bl.PerunBl)5 HashSet (java.util.HashSet)5 Name (javax.naming.Name)5 Vo (cz.metacentrum.perun.core.api.Vo)4 Facility (cz.metacentrum.perun.core.api.Facility)3 Group (cz.metacentrum.perun.core.api.Group)3 Member (cz.metacentrum.perun.core.api.Member)3 Resource (cz.metacentrum.perun.core.api.Resource)2 PerunException (cz.metacentrum.perun.core.api.exceptions.PerunException)2 PerunClient (cz.metacentrum.perun.core.api.PerunClient)1 PerunRequest (cz.metacentrum.perun.core.api.PerunRequest)1 User (cz.metacentrum.perun.core.api.User)1 UserExtSource (cz.metacentrum.perun.core.api.UserExtSource)1 PrivilegeException (cz.metacentrum.perun.core.api.exceptions.PrivilegeException)1 RpcException (cz.metacentrum.perun.core.api.exceptions.RpcException)1 UserNotExistsException (cz.metacentrum.perun.core.api.exceptions.UserNotExistsException)1