Package org.apache.sling.hc.util

Examples of org.apache.sling.hc.util.FormattingResultLog


                new Object[] { properties.get(HealthCheck.NAME), mbeanName, attributeName, constraint });
    }

    @Override
    public Result execute() {
        final FormattingResultLog resultLog = new FormattingResultLog();
        resultLog.debug("Checking {} / {} with constraint {}", mbeanName, attributeName, constraint);
        try {
            final MBeanServer jmxServer = ManagementFactory.getPlatformMBeanServer();
            final ObjectName objectName = new ObjectName(mbeanName);
            if(jmxServer.queryNames(objectName, null).size() == 0) {
                resultLog.warn("MBean not found: {}", objectName);
            } else {
                final Object value = jmxServer.getAttribute(objectName, attributeName);
                resultLog.debug("{} {} returns {}", mbeanName, attributeName, value);
                new SimpleConstraintChecker().check(value, constraint, resultLog);
            }
        } catch(final Exception e) {
            log.warn("JMX attribute {}/{} check failed: {}", new Object []{ mbeanName, attributeName, e});
            resultLog.healthCheckError("JMX attribute check failed: {}", e);
        }
        return new Result(resultLog);
    }
View Full Code Here


                languageExtension, expression});
    }

    @Override
    public Result execute() {
        final FormattingResultLog resultLog = new FormattingResultLog();
        resultLog.debug("Checking expression [{}], language extension=[{}]",  expression, languageExtension);
        try {
            final ScriptEngine engine = scriptEngineManager.getEngineByExtension(languageExtension);
            if (engine == null) {
                resultLog.healthCheckError("No ScriptEngine available for extension {}", languageExtension);
            } else {
                // Set Bindings, with our ResultLog as a binding first, so that other bindings can use it
                final Bindings b = engine.createBindings();
                b.put(FormattingResultLog.class.getName(), resultLog);
                synchronized (bindingsValuesProviders) {
                    for(BindingsValuesProvider bvp : bindingsValuesProviders) {
                        log.debug("Adding Bindings provided by {}", bvp);
                        bvp.addBindings(b);
                    }
                }
                log.debug("All Bindings added: {}", b.keySet());

                final Object value = engine.eval(expression, b);
                if(value!=null && "true".equals(value.toString().toLowerCase())) {
                    resultLog.debug("Expression [{}] evaluates to true as expected", expression);
                } else {
                    resultLog.warn("Expression [{}] does not evaluate to true as expected, value=[{}]", expression, value);
                }
            }
        } catch (final Exception e) {
            resultLog.healthCheckError(
                    "Exception while evaluating expression [{}] with language extension [{}]: {}",
                    expression, languageExtension, e);
        }
        return new Result(resultLog);
    }
View Full Code Here

        }
        log.debug("Unregistering replication queue provider {} ", replicationQueueProvider);
    }

    public Result execute() {
        final FormattingResultLog resultLog = new FormattingResultLog();
        Map<String, Integer> failures = new HashMap<String, Integer>();
        if (replicationQueueProviders.size() > 0) {

            for (ReplicationQueueProvider replicationQueueProvider : replicationQueueProviders) {
                for (ReplicationQueue q : replicationQueueProvider.getAllQueues())
                    try {
                        ReplicationQueueItem item = q.getHead();
                        if (item != null) {
                            ReplicationQueueItemState status = q.getStatus(item);
                            if (status.getAttempts() <= numberOfRetriesAllowed) {
                                resultLog.debug("Queue: [{}], first item: [{}], number of retries: {}", q.getName(), item.getId(), status.getAttempts());
                            } else {
                                // the no. of attempts is higher than the configured threshold
                                resultLog.warn("Queue: [{}], first item: [{}], number of retries: {}, expected number of retries <= {}",
                                        q.getName(), item.getId(), status.getAttempts(), numberOfRetriesAllowed);
                                failures.put(q.getName(), status.getAttempts());
                            }
                        } else {
                            resultLog.debug("No items in queue [{}]", q.getName());
                        }

                    } catch (Exception e) {
                        resultLog.warn("Exception while inspecting replication queue [{}]: {}", q.getName(), e);
                    }
            }
        } else {
            resultLog.debug("No replication queue providers found");
        }

        if (failures.size() > 0) {
            // a specific log entry (using markdown) to provide a recommended user action
            for (Map.Entry<String, Integer> entry : failures.entrySet()) {
                resultLog.warn("Replication queue {}'s first item in the default queue has been retried {} times (threshold: {})",
                        entry.getKey(), entry.getValue(), numberOfRetriesAllowed);
            }
        }

        return new Result(resultLog);
View Full Code Here

        this.paths = PropertiesUtil.toStringArray(properties.get(PROP_PATHS), new String[0]);
    }

    @Override
    public Result execute() {
        final FormattingResultLog resultLog = new FormattingResultLog();
        int templatesWithoutIcons = 0;

        ResourceResolver resolver = null;
        try {
            resolver = rrFactory.getAdministrativeResourceResolver(null);
            PageManager pageManager = resolver.adaptTo(PageManager.class);

            Collection<Template> templates = pageManager.getTemplates(null);
            for (Template template : templates) {
                String path = template.getPath();
                if (StringUtils.startsWithAny(path, paths)) {
                    String thumbnailPath = template.getThumbnailPath();

                    if (thumbnailPath == null) {
                        templatesWithoutIcons++;
                        resultLog.warn("Template {} doesn't have a thumbnail.", path);
                    }
                }
            }

            if (templatesWithoutIcons > 0) {
                resultLog.info("[You have templates without thumbnails.]");
            } else {
                resultLog.debug("All templates have thumbnails.");
            }
        } catch (Exception e) {
            log.error("Unable to list templates", e);
        } finally {
            if (resolver != null) {
View Full Code Here

                new String[] { FOUNDATION_PAGE_TYPE, CLOUD_SERVICE_CONFIG_PAGE_TYPE });
    }

    @Override
    public Result execute() {
        final FormattingResultLog resultLog = new FormattingResultLog();
        int componentsWithoutIcons = 0;

        ResourceResolver resolver = null;
        try {
            resolver = rrFactory.getAdministrativeResourceResolver(null);
            ComponentManager compManager = resolver.adaptTo(ComponentManager.class);

            Collection<Component> components = compManager.getComponents();
            for (Component component : components) {
                String path = component.getPath();
                if (StringUtils.startsWithAny(path, paths)) {
                    String iconPath = component.getIconPath();

                    if (isDroppable(component) && !isPageType(component) && iconPath == null) {
                        componentsWithoutIcons++;
                        resultLog.warn("Component {} is editable, but doesn't have an icon.", path);
                    }
                }
            }

            if (componentsWithoutIcons > 0) {
                resultLog.info("[You have component without icons.]");
            } else {
                resultLog.debug("All components have icons.");
            }
        } catch (Exception e) {
            log.error("Unable to list components", e);
        } finally {
            if (resolver != null) {
View Full Code Here

TOP

Related Classes of org.apache.sling.hc.util.FormattingResultLog

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.