Search in sources :

Example 1 with DiscoveryLiteDescriptor

use of org.apache.sling.discovery.commons.providers.spi.base.DiscoveryLiteDescriptor in project sling by apache.

the class TopologyWebConsolePlugin method updateDiscoveryLiteHistory.

/**
     * if there's any change add a discoveryLite descriptor entry to the history, truncating if necessary
     */
private synchronized void updateDiscoveryLiteHistory() {
    ResourceResolver resourceResolver = null;
    try {
        resourceResolver = getResourceResolver();
        DiscoveryLiteDescriptor descriptor = DiscoveryLiteDescriptor.getDescriptorFrom(resourceResolver);
        if (lastDiscoveryLiteDescriptor != null && descriptor.getDescriptorStr().equals(lastDiscoveryLiteDescriptor.getDescriptorStr())) {
            // de-duplication - then there's nothing to update
            return;
        }
        final String logEntry = getCurrentDateFormatted() + ": " + descriptor.getDescriptorStr();
        lastDiscoveryLiteDescriptor = descriptor;
        discoveryLiteHistory.add(logEntry);
        while (discoveryLiteHistory.size() > 12) {
            discoveryLiteHistory.remove(0);
        }
    } catch (Exception e) {
        logger.error("addDiscoveryLiteHistoryEntry: Exception: " + e, e);
    } finally {
        if (resourceResolver != null) {
            resourceResolver.close();
        }
    }
}
Also used : ResourceResolver(org.apache.sling.api.resource.ResourceResolver) DiscoveryLiteDescriptor(org.apache.sling.discovery.commons.providers.spi.base.DiscoveryLiteDescriptor) ServletException(javax.servlet.ServletException) LoginException(org.apache.sling.api.resource.LoginException) IOException(java.io.IOException)

Example 2 with DiscoveryLiteDescriptor

use of org.apache.sling.discovery.commons.providers.spi.base.DiscoveryLiteDescriptor in project sling by apache.

the class OakClusterViewService method getLocalClusterView.

@Override
public LocalClusterView getLocalClusterView() throws UndefinedClusterViewException {
    logger.trace("getLocalClusterView: start");
    ResourceResolver resourceResolver = null;
    try {
        resourceResolver = getResourceResolver();
        DiscoveryLiteDescriptor descriptor = DiscoveryLiteDescriptor.getDescriptorFrom(resourceResolver);
        if (lastSeqNum != descriptor.getSeqNum()) {
            logger.info("getLocalClusterView: sequence number change detected - clearing idmap cache");
            idMapService.clearCache();
            lastSeqNum = descriptor.getSeqNum();
        }
        return asClusterView(descriptor, resourceResolver);
    } catch (UndefinedClusterViewException e) {
        logger.info("getLocalClusterView: undefined clusterView: " + e.getReason() + " - " + e.getMessage());
        throw e;
    } catch (Exception e) {
        if (e.getMessage() != null && e.getMessage().contains("No Descriptor value available")) {
            logger.warn("getLocalClusterView: repository exception: " + e);
        } else {
            logger.error("getLocalClusterView: repository exception: " + e, e);
        }
        throw new UndefinedClusterViewException(Reason.REPOSITORY_EXCEPTION, "Exception while processing descriptor: " + e);
    } finally {
        logger.trace("getLocalClusterView: end");
        if (resourceResolver != null) {
            resourceResolver.close();
        }
    }
}
Also used : ResourceResolver(org.apache.sling.api.resource.ResourceResolver) DiscoveryLiteDescriptor(org.apache.sling.discovery.commons.providers.spi.base.DiscoveryLiteDescriptor) UndefinedClusterViewException(org.apache.sling.discovery.base.commons.UndefinedClusterViewException) PersistenceException(org.apache.sling.api.resource.PersistenceException) LoginException(org.apache.sling.api.resource.LoginException) UndefinedClusterViewException(org.apache.sling.discovery.base.commons.UndefinedClusterViewException)

Aggregations

LoginException (org.apache.sling.api.resource.LoginException)2 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)2 DiscoveryLiteDescriptor (org.apache.sling.discovery.commons.providers.spi.base.DiscoveryLiteDescriptor)2 IOException (java.io.IOException)1 ServletException (javax.servlet.ServletException)1 PersistenceException (org.apache.sling.api.resource.PersistenceException)1 UndefinedClusterViewException (org.apache.sling.discovery.base.commons.UndefinedClusterViewException)1