Search in sources :

Example 1 with Percent

use of password.pwm.util.java.Percent in project pwm by pwm-project.

the class PasswordChangeProgressChecker method figureReplicationStatusCompletion.

private ProgressRecord figureReplicationStatusCompletion(final ProgressTracker tracker) {
    final long initDelayMs = Long.parseLong(pwmApplication.getConfig().readAppProperty(AppProperty.LDAP_PASSWORD_REPLICA_CHECK_INIT_DELAY_MS));
    final long cycleDelayMs = Long.parseLong(pwmApplication.getConfig().readAppProperty(AppProperty.LDAP_PASSWORD_REPLICA_CHECK_CYCLE_DELAY_MS));
    final TimeDuration initialReplicaDelay = new TimeDuration(initDelayMs);
    final TimeDuration cycleReplicaDelay = new TimeDuration(cycleDelayMs);
    if (passwordSyncCheckMode == PasswordSyncCheckMode.DISABLED) {
        LOGGER.trace(pwmSession, "skipping replica sync check, disabled");
        return tracker.itemCompletions.get(PROGRESS_KEY_REPLICATION);
    }
    if (tracker.itemCompletions.containsKey(PROGRESS_KEY_REPLICATION)) {
        if (tracker.itemCompletions.get(PROGRESS_KEY_REPLICATION).complete) {
            LOGGER.trace(pwmSession, "skipping replica sync check, replica sync completed previously");
            return tracker.itemCompletions.get(PROGRESS_KEY_REPLICATION);
        }
    }
    if (tracker.lastReplicaCheckTime == null) {
        if (TimeDuration.fromCurrent(tracker.beginTime).isShorterThan(initialReplicaDelay)) {
            LOGGER.trace(pwmSession, "skipping replica sync check, initDelay has not yet passed");
            return null;
        }
    } else if (TimeDuration.fromCurrent(tracker.lastReplicaCheckTime).isShorterThan(cycleReplicaDelay)) {
        LOGGER.trace(pwmSession, "skipping replica sync check, cycleDelay has not yet passed");
        return null;
    }
    tracker.lastReplicaCheckTime = Instant.now();
    LOGGER.trace(pwmSession, "beginning password replication time check for " + userIdentity.toDelimitedKey());
    try {
        final Map<String, Instant> checkResults = PasswordUtility.readIndividualReplicaLastPasswordTimes(pwmApplication, pwmSession, userIdentity);
        if (checkResults.size() <= 1) {
            LOGGER.trace("only one replica returned data, marking as complete");
            return completedReplicationRecord;
        } else {
            final HashSet<Instant> tempHashSet = new HashSet<>();
            int duplicateValues = 0;
            for (final Instant date : checkResults.values()) {
                if (tempHashSet.contains(date)) {
                    duplicateValues++;
                } else {
                    tempHashSet.add(date);
                }
            }
            final Percent pctComplete = new Percent(duplicateValues + 1, checkResults.size());
            final ProgressRecord progressRecord = makeReplicaProgressRecord(pctComplete);
            LOGGER.trace("read password replication sync status as: " + JsonUtil.serialize(progressRecord));
            return progressRecord;
        }
    } catch (PwmUnrecoverableException e) {
        LOGGER.error(pwmSession, "error during password replication status check: " + e.getMessage());
    }
    return null;
}
Also used : Percent(password.pwm.util.java.Percent) Instant(java.time.Instant) TimeDuration(password.pwm.util.java.TimeDuration) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) HashSet(java.util.HashSet)

Example 2 with Percent

use of password.pwm.util.java.Percent in project pwm by pwm-project.

the class PasswordChangeProgressChecker method figureProgress.

public PasswordChangeProgress figureProgress(final ProgressTracker tracker) {
    if (tracker == null) {
        throw new IllegalArgumentException("tracker cannot be null");
    }
    final Map<String, ProgressRecord> newItemProgress = new LinkedHashMap<>();
    newItemProgress.putAll(tracker.itemCompletions);
    if (tracker.beginTime == null || Instant.now().isAfter(maxCompletionTime(tracker))) {
        return PasswordChangeProgress.COMPLETE;
    }
    newItemProgress.putAll(figureItemProgresses(tracker));
    final Instant estimatedCompletion = figureEstimatedCompletion(tracker, newItemProgress.values());
    final long elapsedMs = TimeDuration.fromCurrent(tracker.beginTime).getTotalMilliseconds();
    final long remainingMs = TimeDuration.fromCurrent(estimatedCompletion).getTotalMilliseconds();
    final Percent percentage;
    if (Instant.now().isAfter(estimatedCompletion)) {
        percentage = Percent.ONE_HUNDRED;
    } else {
        final long totalMs = new TimeDuration(tracker.beginTime, estimatedCompletion).getTotalMilliseconds();
        percentage = new Percent(elapsedMs, totalMs + 1);
    }
    tracker.itemCompletions.putAll(newItemProgress);
    return new PasswordChangeProgress(percentage.isComplete(), percentage.asBigDecimal(2), newItemProgress.values(), new TimeDuration(elapsedMs).asLongString(locale), new TimeDuration(remainingMs).asLongString(locale));
}
Also used : Percent(password.pwm.util.java.Percent) Instant(java.time.Instant) TimeDuration(password.pwm.util.java.TimeDuration) LinkedHashMap(java.util.LinkedHashMap)

Example 3 with Percent

use of password.pwm.util.java.Percent in project pwm by pwm-project.

the class ResourceServletService method cacheHitRatio.

public Percent cacheHitRatio() {
    final BigDecimal numerator = BigDecimal.valueOf(getCacheHitRatio().getAverage());
    final BigDecimal denominator = BigDecimal.ONE;
    return new Percent(numerator, denominator);
}
Also used : Percent(password.pwm.util.java.Percent) BigDecimal(java.math.BigDecimal)

Example 4 with Percent

use of password.pwm.util.java.Percent in project pwm by pwm-project.

the class LocalDbAuditVault method sizeToDebugString.

@Override
public String sizeToDebugString() {
    final long storedEvents = this.size();
    final long maxEvents = settings.getMaxRecordCount();
    final Percent percent = new Percent(storedEvents, maxEvents);
    return storedEvents + " / " + maxEvents + " (" + percent.pretty(2) + ")";
}
Also used : Percent(password.pwm.util.java.Percent)

Example 5 with Percent

use of password.pwm.util.java.Percent in project pwm by pwm-project.

the class LocaleHelper method getConfigLocaleStats.

public static ConfigLocaleStats getConfigLocaleStats() throws PwmUnrecoverableException, PwmOperationalException {
    final ConfigLocaleStats configLocaleStats = new ConfigLocaleStats();
    {
        final StoredValue storedValue = PwmSetting.CHALLENGE_RANDOM_CHALLENGES.getDefaultValue(PwmSettingTemplateSet.getDefault());
        final Map<String, List<ChallengeItemConfiguration>> value = ((ChallengeValue) storedValue).toNativeObject();
        for (final String localeStr : value.keySet()) {
            final Locale loopLocale = LocaleHelper.parseLocaleString(localeStr);
            configLocaleStats.getDefaultChallenges().add(loopLocale);
        }
    }
    for (final Locale locale : LocaleInfoGenerator.knownLocales()) {
        configLocaleStats.descriptionPresentLocalizations.put(locale, 0);
        configLocaleStats.descriptionMissingLocalizations.put(locale, 0);
    }
    for (final PwmSetting pwmSetting : PwmSetting.values()) {
        final String defaultValue = pwmSetting.getDescription(PwmConstants.DEFAULT_LOCALE);
        configLocaleStats.descriptionPresentLocalizations.put(PwmConstants.DEFAULT_LOCALE, configLocaleStats.descriptionPresentLocalizations.get(PwmConstants.DEFAULT_LOCALE) + 1);
        for (final Locale locale : LocaleInfoGenerator.knownLocales()) {
            if (!PwmConstants.DEFAULT_LOCALE.equals(locale)) {
                final String localeValue = pwmSetting.getDescription(locale);
                if (defaultValue.equals(localeValue)) {
                    configLocaleStats.descriptionMissingLocalizations.put(PwmConstants.DEFAULT_LOCALE, configLocaleStats.descriptionMissingLocalizations.get(locale) + 1);
                } else {
                    configLocaleStats.descriptionPresentLocalizations.put(PwmConstants.DEFAULT_LOCALE, configLocaleStats.descriptionPresentLocalizations.get(locale) + 1);
                }
            }
        }
    }
    for (final Locale locale : LocaleInfoGenerator.knownLocales()) {
        final int totalCount = PwmSetting.values().length;
        final int presentCount = configLocaleStats.getDescriptionPresentLocalizations().get(locale);
        final Percent percent = new Percent(presentCount, totalCount);
        configLocaleStats.getDescriptionPercentLocalizations().put(locale, percent.pretty());
    }
    return configLocaleStats;
}
Also used : Locale(java.util.Locale) PwmSetting(password.pwm.config.PwmSetting) Percent(password.pwm.util.java.Percent) ChallengeItemConfiguration(password.pwm.config.value.data.ChallengeItemConfiguration) StoredValue(password.pwm.config.StoredValue) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) TreeMap(java.util.TreeMap)

Aggregations

Percent (password.pwm.util.java.Percent)7 Instant (java.time.Instant)3 LinkedHashMap (java.util.LinkedHashMap)3 TimeDuration (password.pwm.util.java.TimeDuration)3 BigDecimal (java.math.BigDecimal)2 HashSet (java.util.HashSet)1 Locale (java.util.Locale)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 PwmSetting (password.pwm.config.PwmSetting)1 StoredValue (password.pwm.config.StoredValue)1 NewUserProfile (password.pwm.config.profile.NewUserProfile)1 ChallengeItemConfiguration (password.pwm.config.value.data.ChallengeItemConfiguration)1 PwmUnrecoverableException (password.pwm.error.PwmUnrecoverableException)1 NewUserBean (password.pwm.http.bean.NewUserBean)1 RestResultBean (password.pwm.ws.server.RestResultBean)1