Search in sources :

Example 1 with PwNotifyService

use of password.pwm.svc.pwnotify.PwNotifyService in project pwm by pwm-project.

the class AdminServlet method restreadPwNotifyLog.

@ActionHandler(action = "readPwNotifyLog")
public ProcessStatus restreadPwNotifyLog(final PwmRequest pwmRequest) throws IOException, DatabaseException, PwmUnrecoverableException {
    final PwNotifyService pwNotifyService = pwmRequest.getPwmApplication().getPwNotifyService();
    pwmRequest.outputJsonResult(RestResultBean.withData(pwNotifyService.debugLog()));
    return ProcessStatus.Halt;
}
Also used : PwNotifyService(password.pwm.svc.pwnotify.PwNotifyService)

Example 2 with PwNotifyService

use of password.pwm.svc.pwnotify.PwNotifyService in project pwm by pwm-project.

the class AdminServlet method restreadPwNotifyStatus.

@ActionHandler(action = "readPwNotifyStatus")
public ProcessStatus restreadPwNotifyStatus(final PwmRequest pwmRequest) throws IOException, DatabaseException, PwmUnrecoverableException {
    int key = 0;
    if (!pwmRequest.getConfig().readSettingAsBoolean(PwmSetting.PW_EXPY_NOTIFY_ENABLE)) {
        final DisplayElement displayElement = new DisplayElement(String.valueOf(key++), DisplayElement.Type.string, "Status", "Password Notification Feature is not enabled.  See setting: " + PwmSetting.PW_EXPY_NOTIFY_ENABLE.toMenuLocationDebug(null, pwmRequest.getLocale()));
        pwmRequest.outputJsonResult(RestResultBean.withData(new PwNotifyStatusBean(Collections.singletonList(displayElement), false)));
        return ProcessStatus.Halt;
    }
    {
        ErrorInformation errorInformation = null;
        try {
            if (!pwmRequest.getPwmApplication().getDatabaseService().getAccessor().isConnected()) {
                errorInformation = new ErrorInformation(PwmError.ERROR_DB_UNAVAILABLE, "database is not connected");
            }
        } catch (PwmUnrecoverableException e) {
            errorInformation = e.getErrorInformation();
        }
        if (errorInformation != null) {
            final DisplayElement displayElement = new DisplayElement(String.valueOf(key++), DisplayElement.Type.string, "Status", "Database must be functioning to view Password Notify status.  Current database error: " + errorInformation.toDebugStr());
            pwmRequest.outputJsonResult(RestResultBean.withData(new PwNotifyStatusBean(Collections.singletonList(displayElement), false)));
            return ProcessStatus.Halt;
        }
    }
    final List<DisplayElement> statusData = new ArrayList<>();
    final Configuration config = pwmRequest.getConfig();
    final Locale locale = pwmRequest.getLocale();
    final PwNotifyService pwNotifyService = pwmRequest.getPwmApplication().getPwNotifyService();
    final StoredJobState storedJobState = pwNotifyService.getJobState();
    final boolean canRunOnthisServer = pwNotifyService.canRunOnThisServer();
    statusData.add(new DisplayElement(String.valueOf(key++), DisplayElement.Type.string, "Currently Processing (on this server)", LocaleHelper.booleanString(pwNotifyService.isRunning(), locale, config)));
    statusData.add(new DisplayElement(String.valueOf(key++), DisplayElement.Type.string, "This Server is the Job Processor", LocaleHelper.booleanString(canRunOnthisServer, locale, config)));
    if (canRunOnthisServer) {
        statusData.add(new DisplayElement(String.valueOf(key++), DisplayElement.Type.timestamp, "Next Job Scheduled Time", LocaleHelper.instantString(pwNotifyService.getNextExecutionTime(), locale, config)));
    }
    if (storedJobState != null) {
        statusData.add(new DisplayElement(String.valueOf(key++), DisplayElement.Type.timestamp, "Last Job Start Time", LocaleHelper.instantString(storedJobState.getLastStart(), locale, config)));
        statusData.add(new DisplayElement(String.valueOf(key++), DisplayElement.Type.timestamp, "Last Job Completion Time", LocaleHelper.instantString(storedJobState.getLastCompletion(), locale, config)));
        if (storedJobState.getLastStart() != null && storedJobState.getLastCompletion() != null) {
            statusData.add(new DisplayElement(String.valueOf(key++), DisplayElement.Type.timestamp, "Last Job Duration", TimeDuration.between(storedJobState.getLastStart(), storedJobState.getLastCompletion()).asLongString(locale)));
        }
        statusData.add(new DisplayElement(String.valueOf(key++), DisplayElement.Type.string, "Last Job Server Instance", storedJobState.getServerInstance()));
        if (storedJobState.getLastError() != null) {
            statusData.add(new DisplayElement(String.valueOf(key++), DisplayElement.Type.string, "Last Job Error", storedJobState.getLastError().toDebugStr()));
        }
    }
    final boolean startButtonEnabled = !pwNotifyService.isRunning() && canRunOnthisServer;
    final PwNotifyStatusBean pwNotifyStatusBean = new PwNotifyStatusBean(statusData, startButtonEnabled);
    pwmRequest.outputJsonResult(RestResultBean.withData(pwNotifyStatusBean));
    return ProcessStatus.Halt;
}
Also used : Locale(java.util.Locale) ErrorInformation(password.pwm.error.ErrorInformation) Configuration(password.pwm.config.Configuration) ArrayList(java.util.ArrayList) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) DisplayElement(password.pwm.http.bean.DisplayElement) PwNotifyService(password.pwm.svc.pwnotify.PwNotifyService) StoredJobState(password.pwm.svc.pwnotify.StoredJobState)

Aggregations

PwNotifyService (password.pwm.svc.pwnotify.PwNotifyService)2 ArrayList (java.util.ArrayList)1 Locale (java.util.Locale)1 Configuration (password.pwm.config.Configuration)1 ErrorInformation (password.pwm.error.ErrorInformation)1 PwmUnrecoverableException (password.pwm.error.PwmUnrecoverableException)1 DisplayElement (password.pwm.http.bean.DisplayElement)1 StoredJobState (password.pwm.svc.pwnotify.StoredJobState)1