use of org.apache.sling.hc.api.execution.HealthCheckExecutionResult in project sling by apache.
the class ResultJsonSerializer method serialize.
public String serialize(final Result overallResult, final List<HealthCheckExecutionResult> executionResults, final String jsonpCallback, boolean includeDebug) {
LOG.debug("Sending json response... ");
JsonObjectBuilder result = Json.createObjectBuilder();
try {
result.add("overallResult", overallResult.getStatus().toString());
JsonArrayBuilder resultsJsonArr = Json.createArrayBuilder();
for (HealthCheckExecutionResult healthCheckResult : executionResults) {
resultsJsonArr.add(getJsonForSimpleResult(healthCheckResult, includeDebug));
}
result.add("results", resultsJsonArr);
} catch (JsonException e) {
LOG.info("Could not serialize health check result: " + e, e);
}
StringWriter writer = new StringWriter();
Json.createGenerator(writer).write(result.build()).close();
String resultStr = writer.toString();
if (StringUtils.isNotBlank(jsonpCallback)) {
resultStr = jsonpCallback + "(" + resultStr + ");";
}
return resultStr;
}
use of org.apache.sling.hc.api.execution.HealthCheckExecutionResult in project sling by apache.
the class HealthCheckExecutorImplTest method testCollectResultsFromFuturesCriticalTimeout.
@Test
public void testCollectResultsFromFuturesCriticalTimeout() throws Exception {
List<HealthCheckFuture> futures = new LinkedList<HealthCheckFuture>();
futures.add(future);
Set<HealthCheckExecutionResult> results = new TreeSet<HealthCheckExecutionResult>();
when(future.isDone()).thenReturn(false);
// use an old date now (simulating a future that has run for an hour)
when(future.getCreatedTime()).thenReturn(new Date(new Date().getTime() - 1000 * 60 * 60));
healthCheckExecutorImpl.collectResultsFromFutures(futures, results);
assertEquals(1, results.size());
HealthCheckExecutionResult result = results.iterator().next();
verify(future, times(0)).get();
assertEquals(Result.Status.CRITICAL, result.getHealthCheckResult().getStatus());
assertEquals(1, getLogEntryCount(result));
}
use of org.apache.sling.hc.api.execution.HealthCheckExecutionResult in project sling by apache.
the class HealthCheckExecutorImplTest method testCollectResultsFromFuturesTimeout.
@Test
public void testCollectResultsFromFuturesTimeout() throws Exception {
// add an earlier result with status ok (that will be shown as part of the log)
addResultToCache(Status.OK);
List<HealthCheckFuture> futures = new LinkedList<HealthCheckFuture>();
futures.add(future);
Set<HealthCheckExecutionResult> results = new TreeSet<HealthCheckExecutionResult>();
when(future.isDone()).thenReturn(false);
// simulating a future that was created 5sec ago
when(future.getCreatedTime()).thenReturn(new Date(new Date().getTime() - 1000 * 5));
healthCheckExecutorImpl.collectResultsFromFutures(futures, results);
verify(future, times(0)).get();
assertEquals(1, results.size());
HealthCheckExecutionResult result = results.iterator().next();
assertEquals(Result.Status.WARN, result.getHealthCheckResult().getStatus());
// 3 because previous result exists and is part of log
assertEquals(3, getLogEntryCount(result));
}
use of org.apache.sling.hc.api.execution.HealthCheckExecutionResult in project sling by apache.
the class HealthCheckExecutorImplTest method testCollectResultsFromFuturesWarnTimeoutWithPreviousCritical.
@Test
public void testCollectResultsFromFuturesWarnTimeoutWithPreviousCritical() throws Exception {
// an earlier result with critical
addResultToCache(Status.CRITICAL);
List<HealthCheckFuture> futures = new LinkedList<HealthCheckFuture>();
futures.add(future);
Set<HealthCheckExecutionResult> results = new TreeSet<HealthCheckExecutionResult>();
when(future.isDone()).thenReturn(false);
// simulating a future that was created 5sec ago
when(future.getCreatedTime()).thenReturn(new Date(new Date().getTime() - 1000 * 5));
healthCheckExecutorImpl.collectResultsFromFutures(futures, results);
assertEquals(1, results.size());
HealthCheckExecutionResult result = results.iterator().next();
verify(future, times(0)).get();
// expect CRITICAL because previous result (before timeout) was CRITICAL (and not only WARN)
assertEquals(Result.Status.CRITICAL, result.getHealthCheckResult().getStatus());
assertEquals(3, getLogEntryCount(result));
}
use of org.apache.sling.hc.api.execution.HealthCheckExecutionResult in project acs-aem-commons by Adobe-Consulting-Services.
the class HealthCheckStatusEmailer method resultToPlainText.
/**
* Gererates the plain-text email sections for sets of Health Check Execution Results.
*
* @param title The section title
* @param results the Health Check Execution Results to render as plain text
* @return the String for this section to be embedded in the e-mail
*/
protected String resultToPlainText(final String title, final List<HealthCheckExecutionResult> results) {
final StringBuilder sb = new StringBuilder();
sb.append(title);
sb.append(System.lineSeparator());
if (results.size() == 0) {
sb.append("No " + StringUtils.lowerCase(title) + " could be found!");
sb.append(System.lineSeparator());
} else {
sb.append(StringUtils.repeat("-", NUM_DASHES));
sb.append(System.lineSeparator());
for (final HealthCheckExecutionResult result : results) {
sb.append(StringUtils.rightPad("[ " + result.getHealthCheckResult().getStatus().name() + " ]", HEALTH_CHECK_STATUS_PADDING));
sb.append(" ");
sb.append(result.getHealthCheckMetadata().getTitle());
sb.append(System.lineSeparator());
}
}
return sb.toString();
}
Aggregations