Search in sources :

Example 11 with MetricEntry

use of org.xdi.model.metric.ldap.MetricEntry in project oxCore by GluuFederation.

the class MetricService method findMetricEntry.

public Map<MetricType, List<? extends MetricEntry>> findMetricEntry(ApplicationType applicationType, String applianceInum, List<MetricType> metricTypes, Date startDate, Date endDate, String... returnAttributes) {
    prepareBranch(null, applicationType);
    Map<MetricType, List<? extends MetricEntry>> result = new HashMap<MetricType, List<? extends MetricEntry>>();
    if ((metricTypes == null) || (metricTypes.size() == 0)) {
        return result;
    }
    // Prepare list of DNs
    Set<String> metricDns = getBaseDnForPeriod(applicationType, applianceInum, startDate, endDate);
    if (metricDns.size() == 0) {
        return result;
    }
    for (MetricType metricType : metricTypes) {
        List<MetricEntry> metricTypeResult = new LinkedList<MetricEntry>();
        for (String metricDn : metricDns) {
            List<Filter> metricTypeFilters = new ArrayList<Filter>();
            Filter applicationTypeFilter = Filter.createEqualityFilter("oxApplicationType", applicationType.getValue());
            Filter eventTypeTypeFilter = Filter.createEqualityFilter("oxMetricType", metricType.getValue());
            Filter startDateFilter = Filter.createGreaterOrEqualFilter("oxStartDate", ldapEntryManager.encodeGeneralizedTime((startDate)));
            Filter endDateFilter = Filter.createLessOrEqualFilter("oxEndDate", ldapEntryManager.encodeGeneralizedTime(endDate));
            metricTypeFilters.add(applicationTypeFilter);
            metricTypeFilters.add(eventTypeTypeFilter);
            metricTypeFilters.add(startDateFilter);
            metricTypeFilters.add(endDateFilter);
            Filter filter = Filter.createANDFilter(metricTypeFilters);
            List<? extends MetricEntry> metricTypeMonthResult = (List<? extends MetricEntry>) ldapEntryManager.findEntries(metricDn, metricType.getMetricEntryType(), filter, returnAttributes);
            metricTypeResult.addAll(metricTypeMonthResult);
        }
        // Sort entries to avoid calculation errors
        ldapEntryManager.sortListByProperties(MetricEntry.class, metricTypeResult, false, "creationDate");
        result.put(metricType, metricTypeResult);
    }
    return result;
}
Also used : HashMap(java.util.HashMap) MetricType(org.xdi.model.metric.MetricType) ArrayList(java.util.ArrayList) MetricEntry(org.xdi.model.metric.ldap.MetricEntry) LinkedList(java.util.LinkedList) Filter(org.gluu.search.filter.Filter) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List)

Aggregations

MetricEntry (org.xdi.model.metric.ldap.MetricEntry)11 ArrayList (java.util.ArrayList)8 CounterMetricEntry (org.xdi.model.metric.counter.CounterMetricEntry)6 List (java.util.List)5 MetricType (org.xdi.model.metric.MetricType)5 Date (java.util.Date)4 TimerMetricEntry (org.xdi.model.metric.timer.TimerMetricEntry)4 HashSet (java.util.HashSet)3 LinkedList (java.util.LinkedList)3 Calendar (java.util.Calendar)2 Filter (org.gluu.search.filter.Filter)2 Counter (com.codahale.metrics.Counter)1 Snapshot (com.codahale.metrics.Snapshot)1 Timer (com.codahale.metrics.Timer)1 Filter (com.unboundid.ldap.sdk.Filter)1 HashMap (java.util.HashMap)1 AuthenticationChartDto (org.gluu.oxtrust.model.AuthenticationChartDto)1 DefaultBatchOperation (org.gluu.persist.model.DefaultBatchOperation)1 SimpleBranch (org.gluu.persist.model.base.SimpleBranch)1 BatchOperation (org.gluu.site.ldap.persistence.BatchOperation)1