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);
}
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);
}
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));
}
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));
}
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));
}
Aggregations