use of org.apache.sling.hc.api.Result in project acs-aem-commons by Adobe-Consulting-Services.
the class SMTPMailServiceHealthCheck method execute.
@Override
@SuppressWarnings("squid:S1141")
public Result execute() {
final FormattingResultLog resultLog = new FormattingResultLog();
if (messageGatewayService == null) {
resultLog.critical("MessageGatewayService OSGi service could not be found.");
resultLog.info("Verify the Default Mail Service is active: http://<host>:<port>/system/console/components/com.day.cq.mailer.impl.CqMailingService");
} else {
final MessageGateway<SimpleEmail> messageGateway = messageGatewayService.getGateway(SimpleEmail.class);
if (messageGateway == null) {
resultLog.critical("The AEM Default Mail Service is INACTIVE, thus e-mails cannot be sent.");
resultLog.info("Verify the Default Mail Service is active and configured: http://<host>:<port>/system/console/components/com.day.cq.mailer.DefaultMailService");
log.warn("Could not retrieve a SimpleEmail Message Gateway");
} else {
try {
List<InternetAddress> emailAddresses = new ArrayList<InternetAddress>();
emailAddresses.add(new InternetAddress(this.toEmail));
MailTemplate mailTemplate = new MailTemplate(IOUtils.toInputStream(MAIL_TEMPLATE), CharEncoding.UTF_8);
SimpleEmail email = mailTemplate.getEmail(StrLookup.mapLookup(Collections.emptyMap()), SimpleEmail.class);
email.setSubject("AEM E-mail Service Health Check");
email.setTo(emailAddresses);
email.setSocketConnectionTimeout(TIMEOUT);
email.setSocketTimeout(TIMEOUT);
try {
messageGateway.send(email);
resultLog.info("The E-mail Service appears to be working properly. Verify the health check e-mail was sent to [ {} ]", this.toEmail);
} catch (Exception e) {
resultLog.critical("Failed sending e-mail. Unable to send a test toEmail via the configured E-mail server: " + e.getMessage(), e);
log.warn("Failed to send E-mail for E-mail Service health check", e);
}
logMailServiceConfig(resultLog, email);
} catch (Exception e) {
resultLog.healthCheckError("Sling Health check could not formulate a test toEmail: " + e.getMessage(), e);
log.error("Unable to execute E-mail health check", e);
}
}
}
return new Result(resultLog);
}
use of org.apache.sling.hc.api.Result in project sling by apache.
the class SynchronizedClocksHealthCheck method execute.
@Override
public Result execute() {
final FormattingResultLog resultLog = new FormattingResultLog();
resultLog.debug("Checking cluster internal clocks");
try {
final MBeanServer jmxServer = ManagementFactory.getPlatformMBeanServer();
ObjectName n = new ObjectName(DOCUMENT_NODE_STORE_MBEAN);
Set<ObjectName> names = jmxServer.queryNames(n, null);
if (names.size() == 0) {
resultLog.info("Intra-cluster test n/a (No DocumentNodeStore MBean found)");
} else {
ObjectName firstName = names.iterator().next();
final Object value = jmxServer.invoke(firstName, TIME_DIFF_METHOD_NAME, new Object[0], new String[0]);
logger.debug("{} returns {}", new Object[] { firstName, TIME_DIFF_METHOD_NAME, value });
resultLog.debug("{} returns {}", firstName, TIME_DIFF_METHOD_NAME, value);
if (value != null && (value instanceof Long)) {
Long diffMillis = (Long) value;
if (Math.abs(diffMillis) >= INTRA_CLUSTER_HIGH_WATER_MARK) {
logger.warn("execute: clocks in local cluster out of sync by {}ms " + "which is equal or higher than the high-water mark of {}ms.", diffMillis, INTRA_CLUSTER_HIGH_WATER_MARK);
resultLog.critical("Clocks heavily out of sync in local cluster: " + "time difference of this VM with DocumentStore server: " + "{}ms is equal or larger than high-water mark of {}ms", diffMillis, INTRA_CLUSTER_HIGH_WATER_MARK);
} else if (Math.abs(diffMillis) >= INTRA_CLUSTER_LOW_WATER_MARK) {
logger.warn("execute: clocks in local cluster out of sync by {}ms" + "ms which is equal or higher than the low-water mark of {}ms.", diffMillis, INTRA_CLUSTER_LOW_WATER_MARK);
resultLog.warn("Clocks noticeably out of sync in local cluster: " + "time difference of this VM with DocumentStore server: " + "{}ms is equal or larger than low-water mark of {}ms", diffMillis, INTRA_CLUSTER_LOW_WATER_MARK);
} else {
logger.debug("execute: clocks in local cluster in sync. diff is {}ms" + "ms which is within low-water mark of {}ms.", diffMillis, INTRA_CLUSTER_LOW_WATER_MARK);
resultLog.info("Clocks in sync in local cluster: time difference of this VM with DocumentStore server: " + "{}ms is within low-water mark of {}ms", diffMillis, INTRA_CLUSTER_LOW_WATER_MARK);
}
}
}
} catch (final Exception e) {
logger.warn("execute: {}, JMX method {} invocation failed: {}", new Object[] { DOCUMENT_NODE_STORE_MBEAN, TIME_DIFF_METHOD_NAME, e });
resultLog.healthCheckError("{}, JMX method {} invocation failed: {}", DOCUMENT_NODE_STORE_MBEAN, TIME_DIFF_METHOD_NAME, e);
}
final String slingId = settingsService == null ? "n/a" : settingsService.getSlingId();
if (announcementRegistry == null) {
logger.warn("execute: no announcementRegistry ({}) set", announcementRegistry);
resultLog.warn("Cannot determine topology clocks since no announcementRegistry ({}) set", announcementRegistry);
} else {
final Collection<Announcement> localAnnouncements = announcementRegistry.listLocalAnnouncements();
if (localAnnouncements.isEmpty()) {
logger.info("execute: no topology connectors connected to local instance.");
resultLog.info("No topology connectors connected to local instance.");
}
for (Announcement ann : localAnnouncements) {
final String peerSlingId = ann.getOwnerId();
final long originallyCreatedAt = ann.getOriginallyCreatedAt();
final long receivedAt = ann.getReceivedAt();
long diffMillis = Math.abs(originallyCreatedAt - receivedAt);
if (Math.abs(diffMillis) >= INTER_CLUSTER_HIGH_WATER_MARK) {
logger.warn("execute: clocks between local instance (slingId: {}) and remote instance (slingId: {}) out of sync by {}ms" + "ms which is equal or higher than the high-water mark of {}ms.", new Object[] { slingId, peerSlingId, diffMillis, INTER_CLUSTER_HIGH_WATER_MARK });
resultLog.critical("Clocks heavily out of sync between local instance (slingId: {}) and remote instance (slingId: {}): " + "by {}ms which is equal or larger than high-water mark of {}ms", new Object[] { slingId, peerSlingId, diffMillis, INTER_CLUSTER_HIGH_WATER_MARK });
} else if (Math.abs(diffMillis) >= INTER_CLUSTER_LOW_WATER_MARK) {
logger.warn("execute: clocks out of sync between local instance (slingId: {}) and remote instance (slingId: {}) by {}ms " + "ms which is equal or higher than the low-water mark of {}ms.", new Object[] { slingId, peerSlingId, diffMillis, INTER_CLUSTER_HIGH_WATER_MARK });
resultLog.warn("Clocks noticeably out of sync between local instance (slingId: {}) and remote instance (slingId: {}): " + "by {}ms which is equal or larger than low-water mark of {}ms", new Object[] { slingId, peerSlingId, diffMillis, INTER_CLUSTER_HIGH_WATER_MARK });
} else {
logger.debug("execute: clocks in sync between local instance (slingId: {}) and remote instance (slingId: {}). " + "diff is {}ms which is within low-water mark of {}ms.", new Object[] { slingId, peerSlingId, diffMillis, INTER_CLUSTER_HIGH_WATER_MARK });
resultLog.info("Clocks in sync between local instance (slingId: {}) and remote instance (slingId: {}): " + "diff is {}ms which is within low-water mark of {}ms", new Object[] { slingId, peerSlingId, diffMillis, INTER_CLUSTER_HIGH_WATER_MARK });
}
}
}
return new Result(resultLog);
}
use of org.apache.sling.hc.api.Result in project sling by apache.
the class ThreadUsageHealthCheckTest method testThreadActivityWithinThreshold.
@Test
public void testThreadActivityWithinThreshold() {
long samplePeriod = 200L;
int processorsAvailable = 4;
int busyThreads = 3;
List<ThreadTimeInfo> resultListOverloaded = getFullLoadThreadInfos(samplePeriod, busyThreads);
setupExpectations(samplePeriod, processorsAvailable, resultListOverloaded);
Result result = threadsHealthCheck.execute();
assertEquals(Result.Status.OK, result.getStatus());
}
use of org.apache.sling.hc.api.Result 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.Result 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();
}
Aggregations