use of org.apache.sling.hc.util.SimpleConstraintChecker in project sling by apache.
the class JmxAttributeHealthCheck method execute.
@Override
public Result execute() {
final FormattingResultLog resultLog = new FormattingResultLog();
resultLog.debug("Checking {} / {} with constraint {}", mbeanName, attributeName, constraint);
try {
final MBeanServer jmxServer = ManagementFactory.getPlatformMBeanServer();
final ObjectName objectName = new ObjectName(mbeanName);
if (jmxServer.queryNames(objectName, null).size() == 0) {
resultLog.warn("MBean not found: {}", objectName);
} else {
final Object value = jmxServer.getAttribute(objectName, attributeName);
resultLog.debug("{} {} returns {}", mbeanName, attributeName, value);
new SimpleConstraintChecker().check(value, constraint, resultLog);
}
} catch (final Exception e) {
log.warn("JMX attribute {}/{} check failed: {}", new Object[] { mbeanName, attributeName, e });
resultLog.healthCheckError("JMX attribute check failed: {}", e);
}
return new Result(resultLog);
}
use of org.apache.sling.hc.util.SimpleConstraintChecker in project sling by apache.
the class HealthCheckMBeanTest method assertJmxValue.
private void assertJmxValue(String mbeanName, String attributeName, String constraint, boolean expected) throws Exception {
final MBeanServer jmxServer = ManagementFactory.getPlatformMBeanServer();
final ObjectName objectName = new ObjectName(mbeanName);
if (jmxServer.queryNames(objectName, null).size() == 0) {
fail("MBean not found: " + objectName);
}
final Object value = jmxServer.getAttribute(objectName, attributeName);
final ResultLog resultLog = new ResultLog();
new SimpleConstraintChecker().check(value, constraint, resultLog);
assertEquals("Expecting result " + expected + "(" + resultLog + ")", expected, resultLog.getAggregateStatus().equals(Result.Status.OK));
}
Aggregations