Search in sources :

Example 1 with PwmService

use of password.pwm.svc.PwmService in project pwm by pwm-project.

the class HealthMonitor method doHealthChecks.

private void doHealthChecks() {
    if (status != STATUS.OPEN) {
        return;
    }
    final TimeDuration timeSinceLastUpdate = TimeDuration.fromCurrent(lastHealthCheckTime);
    if (timeSinceLastUpdate.isShorterThan(settings.getMinimumCheckInterval().getTotalMilliseconds(), TimeUnit.MILLISECONDS)) {
        return;
    }
    final Instant startTime = Instant.now();
    LOGGER.trace("beginning background health check process");
    final List<HealthRecord> tempResults = new ArrayList<>();
    for (final HealthChecker loopChecker : HEALTH_CHECKERS) {
        try {
            final List<HealthRecord> loopResults = loopChecker.doHealthCheck(pwmApplication);
            if (loopResults != null) {
                tempResults.addAll(loopResults);
            }
        } catch (Exception e) {
            if (status == STATUS.OPEN) {
                LOGGER.warn("unexpected error during healthCheck: " + e.getMessage(), e);
            }
        }
    }
    for (final PwmService service : pwmApplication.getPwmServices()) {
        try {
            final List<HealthRecord> loopResults = service.healthCheck();
            if (loopResults != null) {
                tempResults.addAll(loopResults);
            }
        } catch (Exception e) {
            if (status == STATUS.OPEN) {
                LOGGER.warn("unexpected error during healthCheck: " + e.getMessage(), e);
            }
        }
    }
    healthRecords.clear();
    healthRecords.addAll(tempResults);
    lastHealthCheckTime = Instant.now();
    LOGGER.trace("health check process completed (" + TimeDuration.fromCurrent(startTime).asCompactString() + ")");
}
Also used : PwmService(password.pwm.svc.PwmService) Instant(java.time.Instant) ArrayList(java.util.ArrayList) TimeDuration(password.pwm.util.java.TimeDuration) PwmException(password.pwm.error.PwmException)

Example 2 with PwmService

use of password.pwm.svc.PwmService in project pwm by pwm-project.

the class AppDashboardData method getServiceData.

private static List<ServiceData> getServiceData(final PwmApplication pwmApplication) {
    final Map<String, ServiceData> returnData = new TreeMap<>();
    for (final PwmService pwmService : pwmApplication.getPwmServices()) {
        final PwmService.ServiceInfo serviceInfo = pwmService.serviceInfo();
        final Collection<DataStorageMethod> storageMethods = serviceInfo == null ? Collections.emptyList() : serviceInfo.getUsedStorageMethods() == null ? Collections.emptyList() : serviceInfo.getUsedStorageMethods();
        final Map<String, String> debugData = serviceInfo == null ? Collections.emptyMap() : serviceInfo.getDebugProperties() == null ? Collections.emptyMap() : serviceInfo.getDebugProperties();
        returnData.put(pwmService.getClass().getSimpleName(), new ServiceData(pwmService.getClass().getSimpleName(), pwmService.status(), storageMethods, pwmService.healthCheck(), debugData));
    }
    return Collections.unmodifiableList(new ArrayList<>(returnData.values()));
}
Also used : PwmService(password.pwm.svc.PwmService) DataStorageMethod(password.pwm.config.option.DataStorageMethod) TreeMap(java.util.TreeMap)

Aggregations

PwmService (password.pwm.svc.PwmService)2 Instant (java.time.Instant)1 ArrayList (java.util.ArrayList)1 TreeMap (java.util.TreeMap)1 DataStorageMethod (password.pwm.config.option.DataStorageMethod)1 PwmException (password.pwm.error.PwmException)1 TimeDuration (password.pwm.util.java.TimeDuration)1