use of org.apache.sling.hc.api.Result in project sling by apache.
the class SlingRequestStatusHealthCheck method execute.
@Override
public Result execute() {
final FormattingResultLog resultLog = new FormattingResultLog();
ResourceResolver resolver = null;
int checked = 0;
int failed = 0;
String lastPath = null;
try {
resolver = resolverFactory.getAdministrativeResourceResolver(null);
for (String p : paths) {
lastPath = p;
final PathSpec ps = new PathSpec(p, resultLog);
final HttpServletRequest request = new InternalRequest(ps.path);
final InternalResponse response = new InternalResponse();
requestProcessor.processRequest(request, response, resolver);
final int status = response.getStatus();
if (status != ps.status) {
failed++;
resultLog.warn("[{}] returns status {}, expected {}", new Object[] { ps.path, status, ps.status });
} else {
resultLog.debug("[{}] returns status {} as expected", ps.path, status);
}
checked++;
}
} catch (Exception e) {
resultLog.warn("Exception while executing request [{}]: {}", lastPath, e);
} finally {
if (resolver != null) {
resolver.close();
}
}
if (checked == 0) {
resultLog.warn("No paths checked, empty paths list?");
} else {
resultLog.info("{} paths checked, {} failures", checked, failed);
}
return new Result(resultLog);
}
use of org.apache.sling.hc.api.Result in project sling by apache.
the class ThreadUsageHealthCheckTest method testThreadActivityOverloaded.
@Test
public void testThreadActivityOverloaded() {
long samplePeriod = 200L;
int processorsAvailable = 4;
int busyThreads = 5;
List<ThreadTimeInfo> resultListOverloaded = getFullLoadThreadInfos(samplePeriod, busyThreads);
setupExpectations(samplePeriod, processorsAvailable, resultListOverloaded);
Result result = threadsHealthCheck.execute();
assertEquals(Result.Status.WARN, result.getStatus());
}
use of org.apache.sling.hc.api.Result in project sling by apache.
the class DistributionQueueHealthCheckTest method testWithNotOkItemInTheQueue.
@Test
public void testWithNotOkItemInTheQueue() throws Exception {
DistributionQueueHealthCheck distributionQueueHealthCheck = new DistributionQueueHealthCheck();
distributionQueueHealthCheck.activate(Collections.<String, Object>emptyMap());
DistributionQueue queue = mock(DistributionQueue.class);
DistributionQueueItem item = mock(DistributionQueueItem.class);
DistributionQueueItemStatus status = mock(DistributionQueueItemStatus.class);
when(status.getAttempts()).thenReturn(10);
when(queue.getItem(any(String.class))).thenReturn(new DistributionQueueEntry(null, item, status));
when(queue.getHead()).thenReturn(new DistributionQueueEntry(null, item, status));
DistributionAgent distributionAgent = mock(DistributionAgent.class);
List<String> queues = new ArrayList<String>();
queues.add("queueName");
when(distributionAgent.getQueueNames()).thenReturn(queues);
when(distributionAgent.getQueue(anyString())).thenReturn(queue);
distributionQueueHealthCheck.bindDistributionAgent(distributionAgent);
Result result = distributionQueueHealthCheck.execute();
assertNotNull(result);
assertFalse(result.isOk());
}
use of org.apache.sling.hc.api.Result in project sling by apache.
the class DistributionQueueHealthCheck method execute.
public Result execute() {
final FormattingResultLog resultLog = new FormattingResultLog();
Map<String, Integer> failures = new HashMap<String, Integer>();
if (distributionAgents.size() > 0) {
for (DistributionAgent distributionAgent : distributionAgents) {
for (String queueName : distributionAgent.getQueueNames()) {
try {
DistributionQueue q = distributionAgent.getQueue(queueName);
DistributionQueueEntry entry = q.getHead();
if (entry != null) {
DistributionQueueItemStatus status = entry.getStatus();
if (status.getAttempts() <= numberOfRetriesAllowed) {
resultLog.debug("Queue: [{}], first item: [{}], number of retries: {}", q.getName(), entry.getId(), status.getAttempts());
} else {
// the no. of attempts is higher than the configured threshold
resultLog.warn("Queue: [{}], first item: [{}], number of retries: {}, expected number of retries <= {}", q.getName(), entry.getId(), status.getAttempts(), numberOfRetriesAllowed);
failures.put(q.getName(), status.getAttempts());
}
} else {
resultLog.debug("No items in queue [{}]", q.getName());
}
} catch (Exception e) {
resultLog.warn("Exception while inspecting distribution queue [{}]: {}", queueName, e);
}
}
}
} else {
resultLog.debug("No distribution queue providers found");
}
if (failures.size() > 0) {
// a specific log entry (using markdown) to provide a recommended user action
for (Map.Entry<String, Integer> entry : failures.entrySet()) {
resultLog.warn("Distribution queue {}'s first item in the default queue has been retried {} times (threshold: {})", entry.getKey(), entry.getValue(), numberOfRetriesAllowed);
}
}
return new Result(resultLog);
}
use of org.apache.sling.hc.api.Result in project sling by apache.
the class OsgiInstallerHealthCheck method execute.
@Override
public Result execute() {
InstallationState installationState = infoProvider.getInstallationState();
FormattingResultLog hcLog = new FormattingResultLog();
int numCheckedConfigurations = 0;
int numCheckedBundles = 0;
// go through all resource groups of the OSGi Installer
for (final ResourceGroup group : installationState.getInstalledResources()) {
String type = evaluateGroup(group, hcLog);
switch(type) {
case InstallableResource.TYPE_CONFIG:
numCheckedConfigurations++;
break;
case InstallableResource.TYPE_BUNDLE:
numCheckedBundles++;
break;
}
}
hcLog.info("Checked {} OSGi bundles and {} configurations.", numCheckedBundles, numCheckedConfigurations);
if (hcLog.getAggregateStatus().ordinal() >= Result.Status.WARN.ordinal()) {
hcLog.info("Refer to the OSGi installer's documentation page at {} for further details on how to fix those issues.", DOCUMENTATION_URL);
}
return new Result(hcLog);
}
Aggregations