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;
}
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));
}
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);
}
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) + ")";
}
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;
}
Aggregations