use of org.apache.sling.hc.api.execution.HealthCheckExecutionResult in project acs-aem-commons by Adobe-Consulting-Services.
the class HealthCheckStatusEmailer method run.
@Override
public final void run() {
log.trace("Executing ACS Commons Health Check E-mailer scheduled service");
final List<HealthCheckExecutionResult> success = new ArrayList<>();
final List<HealthCheckExecutionResult> failure = new ArrayList<>();
final long start = System.currentTimeMillis();
final HealthCheckExecutionOptions options = new HealthCheckExecutionOptions();
options.setForceInstantExecution(true);
options.setCombineTagsWithOr(healthCheckTagsOptionsOr);
if (healthCheckTimeoutOverride > 0) {
options.setOverrideGlobalTimeout(healthCheckTimeoutOverride);
}
final List<HealthCheckExecutionResult> results = healthCheckExecutor.execute(options, healthCheckTags);
log.debug("Obtained [ {} ] results for Health Check tags [ {} ]", results.size(), StringUtils.join(healthCheckTags, ", "));
for (HealthCheckExecutionResult result : results) {
if (result.getHealthCheckResult().isOk()) {
success.add(result);
} else {
failure.add(result);
}
}
final long timeTaken = System.currentTimeMillis() - start;
log.info("Executed ACS Commons Health Check E-mailer scheduled service in [ {} ms ]", timeTaken);
if (!sendEmailOnlyOnFailure || failure.size() > 0) {
if (nextEmailTime == null || Calendar.getInstance().after(nextEmailTime)) {
sendEmail(success, failure, timeTaken);
synchronized (LOCK) {
nextEmailTime = Calendar.getInstance();
nextEmailTime.add(Calendar.MINUTE, throttleInMins);
}
} else {
log.info("Did not send e-mail as it did not meet the e-mail throttle configured time of a [ {} ] minute quiet period. Next valid time to e-mail is [ {} ]", throttleInMins, nextEmailTime.getTime());
}
} else {
log.debug("Declining to send e-mail notification of 100% successful Health Check execution due to configuration.");
}
}
use of org.apache.sling.hc.api.execution.HealthCheckExecutionResult in project sling by apache.
the class HealthCheckWebconsolePlugin method doGet.
@Override
protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException {
if (getStaticResource(req, resp)) {
return;
}
final String tags = getParam(req, PARAM_TAGS, null);
final boolean debug = Boolean.valueOf(getParam(req, PARAM_DEBUG, "false"));
final boolean quiet = Boolean.valueOf(getParam(req, PARAM_QUIET, "false"));
final boolean combineTagsWithOr = Boolean.valueOf(getParam(req, PARAM_COMBINE_TAGS_WITH_OR, "false"));
final boolean forceInstantExecution = Boolean.valueOf(getParam(req, PARAM_FORCE_INSTANT_EXECUTION, "false"));
final String overrideGlobalTimeoutStr = getParam(req, PARAM_OVERRIDE_GLOBAL_TIMEOUT, "");
final PrintWriter pw = resp.getWriter();
doForm(pw, tags, debug, quiet, combineTagsWithOr, forceInstantExecution, overrideGlobalTimeoutStr);
// Execute health checks only if tags are specified (even if empty)
if (tags != null) {
HealthCheckExecutionOptions options = new HealthCheckExecutionOptions();
options.setCombineTagsWithOr(combineTagsWithOr);
options.setForceInstantExecution(forceInstantExecution);
try {
options.setOverrideGlobalTimeout(Integer.valueOf(overrideGlobalTimeoutStr));
} catch (NumberFormatException nfe) {
// override not set in UI
}
Collection<HealthCheckExecutionResult> results = healthCheckExecutor.execute(options, tags.split(","));
pw.println("<table class='content healthcheck' cellpadding='0' cellspacing='0' width='100%'>");
int total = 0;
int failed = 0;
for (final HealthCheckExecutionResult exR : results) {
final Result r = exR.getHealthCheckResult();
total++;
if (!r.isOk()) {
failed++;
}
if (!quiet || !r.isOk()) {
renderResult(pw, exR, debug);
}
}
final WebConsoleHelper c = new WebConsoleHelper(resp.getWriter());
c.titleHtml("Summary", total + " HealthCheck executed, " + failed + " failures");
pw.println("</table>");
pw.println("<a href='configMgr/org.apache.sling.hc.core.impl.executor.HealthCheckExecutorImpl'>Configure executor</a><br/><br/>");
}
}
use of org.apache.sling.hc.api.execution.HealthCheckExecutionResult in project sling by apache.
the class HealthCheckWebconsolePlugin method renderResult.
private void renderResult(final PrintWriter pw, final HealthCheckExecutionResult exResult, final boolean debug) throws IOException {
final Result result = exResult.getHealthCheckResult();
final WebConsoleHelper c = new WebConsoleHelper(pw);
final StringBuilder status = new StringBuilder();
status.append("Tags: ").append(exResult.getHealthCheckMetadata().getTags());
status.append(" Finished: ").append(new SimpleDateFormat("yyyy-MM-dd mm:ss").format(exResult.getFinishedAt()) + " after " + msHumanReadable(exResult.getElapsedTimeInMs()));
c.titleHtml(exResult.getHealthCheckMetadata().getTitle(), null);
c.tr();
c.tdContent();
c.writer().print(ResponseUtil.escapeXml(status.toString()));
c.writer().print("<br/>Result: <span class='resultOk");
c.writer().print(result.isOk());
c.writer().print("'>");
c.writer().print(result.getStatus().toString());
c.writer().print("</span>");
c.closeTd();
c.closeTr();
c.tr();
c.tdContent();
for (final ResultLog.Entry e : result) {
if (!debug && e.getStatus().equals(Result.Status.DEBUG)) {
continue;
}
c.writer().print("<div class='log");
c.writer().print(e.getStatus().toString());
c.writer().print("'>");
c.writer().print(e.getStatus().toString());
c.writer().print(' ');
c.writer().print(ResponseUtil.escapeXml(e.getMessage()));
if (e.getException() != null) {
c.writer().print(" ");
c.writer().print(ResponseUtil.escapeXml(e.getException().toString()));
}
c.writer().println("</div>");
}
c.closeTd();
}
use of org.apache.sling.hc.api.execution.HealthCheckExecutionResult in project sling by apache.
the class HealthCheckExecutorImpl method execute.
/**
* Execute a set of health checks
*/
private List<HealthCheckExecutionResult> execute(final ServiceReference[] healthCheckReferences, HealthCheckExecutionOptions options) {
final StopWatch stopWatch = new StopWatch();
stopWatch.start();
final List<HealthCheckExecutionResult> results = new ArrayList<HealthCheckExecutionResult>();
final List<HealthCheckMetadata> healthCheckDescriptors = getHealthCheckMetadata(healthCheckReferences);
createResultsForDescriptors(healthCheckDescriptors, results, options);
stopWatch.stop();
if (logger.isDebugEnabled()) {
logger.debug("Time consumed for all checks: {}", msHumanReadable(stopWatch.getTime()));
}
// sort result
Collections.sort(results, new Comparator<HealthCheckExecutionResult>() {
@Override
public int compare(final HealthCheckExecutionResult arg0, final HealthCheckExecutionResult arg1) {
return ((ExecutionResult) arg0).compareTo((ExecutionResult) arg1);
}
});
return results;
}
use of org.apache.sling.hc.api.execution.HealthCheckExecutionResult in project sling by apache.
the class HealthCheckExecutorImpl method createResultsForDescriptor.
private HealthCheckExecutionResult createResultsForDescriptor(final HealthCheckMetadata metadata) {
// create result for a single descriptor
// reuse cached results where possible
HealthCheckExecutionResult result;
result = healthCheckResultCache.getValidCacheResult(metadata, resultCacheTtlInMs);
if (result == null) {
final HealthCheckFuture future;
synchronized (this.stillRunningFutures) {
future = createOrReuseFuture(metadata);
}
// wait for futures at most until timeout (but will return earlier if all futures are finished)
waitForFuturesRespectingTimeout(Collections.singletonList(future), null);
result = collectResultFromFuture(future);
}
return result;
}
Aggregations