Search in sources :

Example 1 with HealthCheck

use of org.apache.sling.hc.api.HealthCheck in project sling by apache.

the class SlingHealthCheckProcessor method processHealthCheck.

/** Processes the given healthcheck annotation.
     * 
     * @param cad the annotation
     * @param classDescription the class description */
private void processHealthCheck(final ClassAnnotation cad, final ClassDescription classDescription) {
    final boolean generateComponent = cad.getBooleanValue("generateComponent", true);
    final boolean metatype = cad.getBooleanValue("metatype", true);
    final boolean immediate = cad.getBooleanValue("immediate", false);
    // generate ComponentDescription if required
    if (generateComponent) {
        String nameOfAnnotatedClass = classDescription.getDescribedClass().getName();
        final ComponentDescription cd = new ComponentDescription(cad);
        cd.setName(cad.getStringValue("componentName", nameOfAnnotatedClass));
        cd.setConfigurationPolicy(ComponentConfigurationPolicy.valueOf(cad.getEnumValue("configurationPolicy", ComponentConfigurationPolicy.OPTIONAL.name())));
        cd.setSetMetatypeFactoryPid(cad.getBooleanValue("configurationFactory", false));
        String nameFromAnnotation = (String) cad.getValue("name");
        String defaultLabel = "Sling Health Check: " + (nameFromAnnotation != null ? nameFromAnnotation : nameOfAnnotatedClass);
        cd.setLabel(cad.getStringValue("label", defaultLabel));
        cd.setDescription(cad.getStringValue("description", "Health Check Configuration"));
        cd.setCreateMetatype(metatype);
        cd.setImmediate(immediate);
        classDescription.add(cd);
    }
    // generate ServiceDescription if required
    final boolean generateService = cad.getBooleanValue("generateService", true);
    if (generateService) {
        final ServiceDescription sd = new ServiceDescription(cad);
        sd.addInterface(HealthCheck.class.getName());
        classDescription.add(sd);
    }
    // generate HC PropertyDescriptions
    generatePropertyDescriptor(cad, classDescription, metatype, "name", HealthCheck.NAME, PropertyType.String, "Name", "Name of the Health Check", false);
    generatePropertyDescriptor(cad, classDescription, metatype, "tags", HealthCheck.TAGS, PropertyType.String, "Tags", "List of tags", true);
    generatePropertyDescriptor(cad, classDescription, metatype, "mbeanName", HealthCheck.MBEAN_NAME, PropertyType.String, "MBean", "MBean name (leave empty for not using JMX)", false);
    generatePropertyDescriptor(cad, classDescription, metatype, "asyncCronExpression", HealthCheck.ASYNC_CRON_EXPRESSION, PropertyType.String, "Cron expression", "Cron expression for asynchronous execution (leave empty for synchronous execution)", false);
    generatePropertyDescriptor(cad, classDescription, metatype, "resultCacheTtlInMs", "hc.resultCacheTtlInMs", /* use constant once API is released */
    PropertyType.Long, "Result Cache TTL", "TTL for results. The value -1 (default) uses the global configuration in health check executor. Redeployment of a HC always invalidates its cached result.", false);
}
Also used : ComponentDescription(org.apache.felix.scrplugin.description.ComponentDescription) ServiceDescription(org.apache.felix.scrplugin.description.ServiceDescription) HealthCheck(org.apache.sling.hc.api.HealthCheck)

Example 2 with HealthCheck

use of org.apache.sling.hc.api.HealthCheck in project sling by apache.

the class JmxAdjustableStatusForTesting method registerDynamicTestingHealthCheck.

/* synchronized as potentially multiple users can run JMX operations */
private synchronized void registerDynamicTestingHealthCheck(Result.Status status, String[] tags) {
    unregisterDynamicTestingHealthCheck();
    HealthCheck healthCheck = new DynamicTestingHealthCheck(status);
    Dictionary<String, Object> props = new Hashtable<String, Object>();
    props.put(HealthCheck.NAME, "JMX-adjustable Testing Check");
    props.put(HealthCheck.TAGS, tags);
    healthCheckRegistration = bundleContext.registerService(HealthCheck.class.getName(), healthCheck, props);
}
Also used : Hashtable(java.util.Hashtable) HealthCheck(org.apache.sling.hc.api.HealthCheck)

Example 3 with HealthCheck

use of org.apache.sling.hc.api.HealthCheck in project sling by apache.

the class ExtendedHealthCheckExecutorIT method registerHC.

private void registerHC(final String... tags) {
    final HealthCheck hc = new HealthCheck() {

        @Override
        public Result execute() {
            return new Result(testResult, "Returning " + testResult + " for " + tags[0]);
        }
    };
    final Dictionary<String, Object> props = new Hashtable<String, Object>();
    props.put(HealthCheck.NAME, "name_" + tags[0]);
    props.put(HealthCheck.TAGS, tags);
    regs.add(bundleContext.registerService(HealthCheck.class.getName(), hc, props));
}
Also used : Hashtable(java.util.Hashtable) HealthCheck(org.apache.sling.hc.api.HealthCheck) Result(org.apache.sling.hc.api.Result) HealthCheckExecutionResult(org.apache.sling.hc.api.execution.HealthCheckExecutionResult)

Example 4 with HealthCheck

use of org.apache.sling.hc.api.HealthCheck in project sling by apache.

the class HealthCheckExecutorSelectionIT method registerHC.

private void registerHC(final String... tags) {
    final HealthCheck hc = new HealthCheck() {

        @Override
        public Result execute() {
            return new Result(Result.Status.OK, "All good for " + tags[0]);
        }
    };
    final Dictionary<String, Object> props = new Hashtable<String, Object>();
    props.put(HealthCheck.NAME, "name_" + tags[0]);
    props.put(HealthCheck.TAGS, tags);
    regs.add(bundleContext.registerService(HealthCheck.class.getName(), hc, props));
}
Also used : Hashtable(java.util.Hashtable) HealthCheck(org.apache.sling.hc.api.HealthCheck) Result(org.apache.sling.hc.api.Result)

Example 5 with HealthCheck

use of org.apache.sling.hc.api.HealthCheck in project sling by apache.

the class JmxAdjustableStatusForTestingIT method registerHC.

private void registerHC(final String... tags) {
    final HealthCheck hc = new HealthCheck() {

        @Override
        public Result execute() {
            return new Result(Result.Status.OK, "All good for " + tags[0]);
        }
    };
    final Dictionary<String, Object> props = new Hashtable<String, Object>();
    props.put(HealthCheck.NAME, "name_" + tags[0]);
    props.put(HealthCheck.TAGS, tags);
    regs.add(bundleContext.registerService(HealthCheck.class.getName(), hc, props));
}
Also used : Hashtable(java.util.Hashtable) HealthCheck(org.apache.sling.hc.api.HealthCheck) Result(org.apache.sling.hc.api.Result) HealthCheckExecutionResult(org.apache.sling.hc.api.execution.HealthCheckExecutionResult)

Aggregations

HealthCheck (org.apache.sling.hc.api.HealthCheck)8 Hashtable (java.util.Hashtable)5 Result (org.apache.sling.hc.api.Result)5 ArrayList (java.util.ArrayList)2 HealthCheckExecutionResult (org.apache.sling.hc.api.execution.HealthCheckExecutionResult)2 ServiceReference (org.osgi.framework.ServiceReference)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 ComponentDescription (org.apache.felix.scrplugin.description.ComponentDescription)1 ServiceDescription (org.apache.felix.scrplugin.description.ServiceDescription)1 FormattingResultLog (org.apache.sling.hc.util.FormattingResultLog)1 Test (org.junit.Test)1 ServiceRegistration (org.osgi.framework.ServiceRegistration)1