Search in sources :

Example 1 with HealthCheckFilter

use of org.apache.sling.hc.util.HealthCheckFilter in project sling by apache.

the class HealthCheckExecutorImpl method execute.

@Override
public List<HealthCheckExecutionResult> execute(HealthCheckSelector selector, HealthCheckExecutionOptions options) {
    logger.debug("Starting executing checks for filter selector {} and execution options {}", selector, options);
    final HealthCheckFilter filter = new HealthCheckFilter(this.bundleContext);
    try {
        final ServiceReference[] healthCheckReferences = filter.getHealthCheckServiceReferences(selector, options.isCombineTagsWithOr());
        return this.execute(healthCheckReferences, options);
    } finally {
        filter.dispose();
    }
}
Also used : HealthCheckFilter(org.apache.sling.hc.util.HealthCheckFilter) ServiceReference(org.osgi.framework.ServiceReference)

Example 2 with HealthCheckFilter

use of org.apache.sling.hc.util.HealthCheckFilter in project sling by apache.

the class CompositeHealthCheck method activate.

@Activate
protected void activate(final ComponentContext ctx) {
    bundleContext = ctx.getBundleContext();
    componentContext = ctx;
    healthCheckFilter = new HealthCheckFilter(bundleContext);
    filterTags = PropertiesUtil.toStringArray(ctx.getProperties().get(PROP_FILTER_TAGS), new String[] {});
    log.debug("Activated, will select HealthCheck having tags {}", Arrays.asList(filterTags));
}
Also used : HealthCheckFilter(org.apache.sling.hc.util.HealthCheckFilter) Activate(org.apache.felix.scr.annotations.Activate)

Example 3 with HealthCheckFilter

use of org.apache.sling.hc.util.HealthCheckFilter in project sling by apache.

the class CompositeHealthCheckTest method testSimpleRecursion.

@Test
public void testSimpleRecursion() {
    // composite check referencing itself
    final String[] filterTags = new String[] { "check1" };
    final DummyHcServiceReference hcRef = new DummyHcServiceReference("Check 1", new String[] { "check1" }, filterTags);
    // test check is hcRef
    doReturn(hcRef).when(componentContext).getServiceReference();
    compositeHealthCheck.setFilterTags(filterTags);
    compositeHealthCheck.setHealthCheckFilter(new HealthCheckFilter(null) {

        @Override
        public ServiceReference[] getHealthCheckServiceReferences(HealthCheckSelector selector) {
            String[] tags = selector.tags();
            ServiceReference[] result = new ServiceReference[] {};
            if (tags.length > 0) {
                if (tags[0].equals(filterTags[0])) {
                    result = new ServiceReference[] { hcRef };
                }
            }
            return result;
        }
    });
    Result result = compositeHealthCheck.execute();
    verify(healthCheckExecutor, never()).execute(any(HealthCheckSelector.class));
    assertEquals(Result.Status.HEALTH_CHECK_ERROR, result.getStatus());
}
Also used : HealthCheckSelector(org.apache.sling.hc.api.execution.HealthCheckSelector) HealthCheckFilter(org.apache.sling.hc.util.HealthCheckFilter) ServiceReference(org.osgi.framework.ServiceReference) ExecutionResult(org.apache.sling.hc.core.impl.executor.ExecutionResult) Result(org.apache.sling.hc.api.Result) HealthCheckExecutionResult(org.apache.sling.hc.api.execution.HealthCheckExecutionResult) Test(org.junit.Test)

Example 4 with HealthCheckFilter

use of org.apache.sling.hc.util.HealthCheckFilter in project sling by apache.

the class HealthCheckFilterIT method setup.

@Before
public void setup() {
    testServices.add(builder().withTags("foo").withName("test1").build());
    testServices.add(builder().withTags("bar").withName("test2").build());
    testServices.add(builder().withTags("foo", "bar").withName("test3").build());
    testServices.add(builder().withTags("other", "thing").withName("test4").build());
    testServices.add(builder().withName("test5").build());
    filter = new HealthCheckFilter(bundleContext);
}
Also used : HealthCheckFilter(org.apache.sling.hc.util.HealthCheckFilter) Before(org.junit.Before)

Example 5 with HealthCheckFilter

use of org.apache.sling.hc.util.HealthCheckFilter in project sling by apache.

the class AsyncHealthCheckExecutor method activate.

@Activate
protected final void activate(final ComponentContext componentContext) {
    this.bundleContext = componentContext.getBundleContext();
    this.bundleContext.addServiceListener(this);
    int count = 0;
    HealthCheckFilter healthCheckFilter = new HealthCheckFilter(bundleContext);
    final ServiceReference[] healthCheckReferences = healthCheckFilter.getHealthCheckServiceReferences(HealthCheckSelector.empty());
    for (ServiceReference serviceReference : healthCheckReferences) {
        HealthCheckMetadata healthCheckMetadata = new HealthCheckMetadata(serviceReference);
        if (isAsync(healthCheckMetadata)) {
            if (scheduleHealthCheck(healthCheckMetadata)) {
                count++;
            }
        }
    }
    LOG.debug("Scheduled {} jobs for asynchronous health checks", count);
}
Also used : HealthCheckMetadata(org.apache.sling.hc.util.HealthCheckMetadata) HealthCheckFilter(org.apache.sling.hc.util.HealthCheckFilter) ServiceReference(org.osgi.framework.ServiceReference) Activate(org.apache.felix.scr.annotations.Activate)

Aggregations

HealthCheckFilter (org.apache.sling.hc.util.HealthCheckFilter)7 ServiceReference (org.osgi.framework.ServiceReference)5 HealthCheckExecutionResult (org.apache.sling.hc.api.execution.HealthCheckExecutionResult)3 Test (org.junit.Test)3 Activate (org.apache.felix.scr.annotations.Activate)2 Result (org.apache.sling.hc.api.Result)2 HealthCheckSelector (org.apache.sling.hc.api.execution.HealthCheckSelector)2 ExecutionResult (org.apache.sling.hc.core.impl.executor.ExecutionResult)2 Method (java.lang.reflect.Method)1 HealthCheckMetadata (org.apache.sling.hc.util.HealthCheckMetadata)1 Before (org.junit.Before)1