Search in sources :

Example 1 with StatEntry

use of org.gluu.oxauth.model.stat.StatEntry in project oxAuth by GluuFederation.

the class StatService method setupCurrentEntry.

private void setupCurrentEntry(Date now) {
    final String month = PERIOD_DATE_FORMAT.format(now);
    // jansId=<id>,ou=yyyyMM,ou=stat,o=gluu
    String dn = String.format("jansId=%s,%s", nodeId, monthlyDn);
    if (currentEntry != null && month.equals(currentEntry.getStat().getMonth())) {
        return;
    }
    try {
        StatEntry entryFromPersistence = entryManager.find(StatEntry.class, dn);
        if (entryFromPersistence != null && month.equals(entryFromPersistence.getStat().getMonth())) {
            hll = HLL.fromBytes(Base64.getDecoder().decode(entryFromPersistence.getUserHllData()));
            tokenCounters = new ConcurrentHashMap<>(entryFromPersistence.getStat().getTokenCountPerGrantType());
            currentEntry = entryFromPersistence;
            log.trace("Stat entry loaded.");
            return;
        }
    } catch (EntryPersistenceException e) {
        log.trace("Stat entry is not found in persistence.");
    }
    if (currentEntry == null) {
        log.trace("Creating stat entry ...");
        hll = newHll();
        tokenCounters = new ConcurrentHashMap<>();
        currentEntry = new StatEntry();
        currentEntry.setId(nodeId);
        currentEntry.setDn(dn);
        currentEntry.setUserHllData(Base64.getEncoder().encodeToString(hll.toBytes()));
        currentEntry.getStat().setMonth(PERIOD_DATE_FORMAT.format(new Date()));
        entryManager.persist(currentEntry);
        log.trace("Created stat entry. nodeId:" + nodeId);
    }
}
Also used : StatEntry(org.gluu.oxauth.model.stat.StatEntry) EntryPersistenceException(org.gluu.persist.exception.EntryPersistenceException) Date(java.util.Date)

Example 2 with StatEntry

use of org.gluu.oxauth.model.stat.StatEntry in project oxAuth by GluuFederation.

the class StatWS method unionTokenMapIntoResponseItem.

private void unionTokenMapIntoResponseItem(List<StatEntry> entries, StatResponseItem responseItem) {
    for (StatEntry entry : entries) {
        for (Map.Entry<String, Map<String, Long>> en : entry.getStat().getTokenCountPerGrantType().entrySet()) {
            if (en.getValue() == null) {
                continue;
            }
            final Map<String, Long> tokenMap = responseItem.getTokenCountPerGrantType().get(en.getKey());
            if (tokenMap == null) {
                responseItem.getTokenCountPerGrantType().put(en.getKey(), en.getValue());
                continue;
            }
            for (Map.Entry<String, Long> tokenEntry : en.getValue().entrySet()) {
                final Long counter = tokenMap.get(tokenEntry.getKey());
                if (counter == null) {
                    tokenMap.put(tokenEntry.getKey(), tokenEntry.getValue());
                    continue;
                }
                tokenMap.put(tokenEntry.getKey(), counter + tokenEntry.getValue());
            }
        }
    }
}
Also used : StatEntry(org.gluu.oxauth.model.stat.StatEntry) Map(java.util.Map)

Aggregations

StatEntry (org.gluu.oxauth.model.stat.StatEntry)2 Date (java.util.Date)1 Map (java.util.Map)1 EntryPersistenceException (org.gluu.persist.exception.EntryPersistenceException)1