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