Search in sources :

Example 1 with HealthCheckExecutionOptions

use of org.apache.sling.hc.api.execution.HealthCheckExecutionOptions in project sling by apache.

the class HealthCheckExecutorServletTest method testDoGetNameAndTagInPath.

@Test
public void testDoGetNameAndTagInPath() throws ServletException, IOException {
    final String testTag = "testTag";
    final String testName = "test name";
    doReturn(testTag + "," + testName).when(request).getPathInfo();
    doReturn("false").when(request).getParameter(HealthCheckExecutorServlet.PARAM_COMBINE_TAGS_WITH_OR.name);
    final List<HealthCheckExecutionResult> executionResults = getExecutionResults(Result.Status.CRITICAL);
    doReturn(executionResults).when(healthCheckExecutor).execute(selector(new String[] { testTag }, new String[] { testName }), eq(new HealthCheckExecutionOptions()));
    healthCheckExecutorServlet.doGet(request, response);
    verify(request, never()).getParameter(HealthCheckExecutorServlet.PARAM_TAGS.name);
    verify(request, never()).getParameter(HealthCheckExecutorServlet.PARAM_NAMES.name);
    verifyZeroInteractions(jsonSerializer);
    verifyZeroInteractions(txtSerializer);
    verifyZeroInteractions(verboseTxtSerializer);
    verify(htmlSerializer).serialize(resultEquals(new Result(Result.Status.CRITICAL, "Overall Status CRITICAL")), eq(executionResults), contains("Supported URL parameters"), eq(false));
}
Also used : HealthCheckExecutionOptions(org.apache.sling.hc.api.execution.HealthCheckExecutionOptions) Matchers.anyString(org.mockito.Matchers.anyString) HealthCheckExecutionResult(org.apache.sling.hc.api.execution.HealthCheckExecutionResult) 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 2 with HealthCheckExecutionOptions

use of org.apache.sling.hc.api.execution.HealthCheckExecutionOptions in project sling by apache.

the class HealthCheckExecutorServletTest method testDoGetJson.

@Test
public void testDoGetJson() throws ServletException, IOException {
    final String testTag = "testTag";
    doReturn("true").when(request).getParameter(HealthCheckExecutorServlet.PARAM_COMBINE_TAGS_WITH_OR.name);
    int timeout = 5000;
    doReturn(timeout + "").when(request).getParameter(HealthCheckExecutorServlet.PARAM_OVERRIDE_GLOBAL_TIMEOUT.name);
    doReturn("/" + testTag + ".json").when(request).getPathInfo();
    final List<HealthCheckExecutionResult> executionResults = getExecutionResults(Result.Status.WARN);
    HealthCheckExecutionOptions options = new HealthCheckExecutionOptions();
    options.setCombineTagsWithOr(true);
    options.setOverrideGlobalTimeout(timeout);
    doReturn(executionResults).when(healthCheckExecutor).execute(selector(new String[] { testTag }, new String[0]), eq(options));
    healthCheckExecutorServlet.doGet(request, response);
    verifyZeroInteractions(htmlSerializer);
    verifyZeroInteractions(txtSerializer);
    verifyZeroInteractions(verboseTxtSerializer);
    verify(jsonSerializer).serialize(resultEquals(new Result(Result.Status.WARN, "Overall Status WARN")), eq(executionResults), anyString(), eq(false));
}
Also used : HealthCheckExecutionOptions(org.apache.sling.hc.api.execution.HealthCheckExecutionOptions) Matchers.anyString(org.mockito.Matchers.anyString) HealthCheckExecutionResult(org.apache.sling.hc.api.execution.HealthCheckExecutionResult) 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 3 with HealthCheckExecutionOptions

use of org.apache.sling.hc.api.execution.HealthCheckExecutionOptions 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.");
    }
}
Also used : ArrayList(java.util.ArrayList) HealthCheckExecutionOptions(org.apache.sling.hc.api.execution.HealthCheckExecutionOptions) HealthCheckExecutionResult(org.apache.sling.hc.api.execution.HealthCheckExecutionResult)

Example 4 with HealthCheckExecutionOptions

use of org.apache.sling.hc.api.execution.HealthCheckExecutionOptions 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/>");
    }
}
Also used : HealthCheckExecutionOptions(org.apache.sling.hc.api.execution.HealthCheckExecutionOptions) HealthCheckExecutionResult(org.apache.sling.hc.api.execution.HealthCheckExecutionResult) PrintWriter(java.io.PrintWriter) Result(org.apache.sling.hc.api.Result) HealthCheckExecutionResult(org.apache.sling.hc.api.execution.HealthCheckExecutionResult)

Example 5 with HealthCheckExecutionOptions

use of org.apache.sling.hc.api.execution.HealthCheckExecutionOptions in project sling by apache.

the class HealthCheckExecutorSelectionIT method setup.

@Before
public void setup() {
    options = new HealthCheckExecutionOptions();
    U.expectHealthChecks(0, executor, idA);
    U.expectHealthChecks(0, executor, idB);
    registerHC(idA);
    registerHC(idB);
    registerHC(idB);
    registerHC(idA, idB);
}
Also used : HealthCheckExecutionOptions(org.apache.sling.hc.api.execution.HealthCheckExecutionOptions) Before(org.junit.Before)

Aggregations

HealthCheckExecutionOptions (org.apache.sling.hc.api.execution.HealthCheckExecutionOptions)9 HealthCheckExecutionResult (org.apache.sling.hc.api.execution.HealthCheckExecutionResult)8 Result (org.apache.sling.hc.api.Result)7 Test (org.junit.Test)5 ExecutionResult (org.apache.sling.hc.core.impl.executor.ExecutionResult)4 Matchers.anyString (org.mockito.Matchers.anyString)4 ArrayList (java.util.ArrayList)2 HealthCheckSelector (org.apache.sling.hc.api.execution.HealthCheckSelector)2 PrintWriter (java.io.PrintWriter)1 Date (java.util.Date)1 List (java.util.List)1 ObjectName (javax.management.ObjectName)1 Status (org.apache.sling.hc.api.Result.Status)1 ExtendedHealthCheckExecutor (org.apache.sling.hc.core.impl.executor.ExtendedHealthCheckExecutor)1 HealthCheckMetadata (org.apache.sling.hc.util.HealthCheckMetadata)1 Before (org.junit.Before)1 Bundle (org.osgi.framework.Bundle)1 ServiceReference (org.osgi.framework.ServiceReference)1