Search in sources :

Example 1 with GroupedStats

use of com.thinkbiganalytics.nifi.provenance.model.stats.GroupedStats in project kylo by Teradata.

the class GroupedStatsUtil method add.

/**
 * Add 2 stats together and return a new stats object
 *
 * @param stats1 stats object
 * @param stats2 stats object
 * @return a new stats object
 */
public static GroupedStats add(GroupedStats stats1, GroupedStats stats2) {
    GroupedStats stats = new GroupedStats();
    addStats1(stats, stats1);
    addStats1(stats, stats2);
    return stats;
}
Also used : GroupedStats(com.thinkbiganalytics.nifi.provenance.model.stats.GroupedStats)

Example 2 with GroupedStats

use of com.thinkbiganalytics.nifi.provenance.model.stats.GroupedStats in project kylo by Teradata.

the class GroupedStatsUtil method groupStatsByProcessor.

/**
 * Group stats together by processor for a given feed
 *
 * @param feedName     feed name
 * @param groupedStats Map of processorIdentity to list of stats for that processor
 */
public static AggregatedFeedProcessorStatistics groupStatsByProcessor(String feedName, Map<GroupedStatsIdentity, List<GroupedStats>> groupedStats) {
    Long sendJmsTimeMillis = 3000L;
    String collectionId = UUID.randomUUID().toString();
    // Create a random id for the starting processor.
    // the starting feed processor id is not needed as we already know the feed name associated with these stats
    String startingProcessorId = UUID.randomUUID().toString();
    AggregatedFeedProcessorStatisticsV2 feedProcessorStatistics = new AggregatedFeedProcessorStatisticsV2(startingProcessorId, collectionId, sendJmsTimeMillis);
    feedProcessorStatistics.setFeedName(feedName);
    for (Map.Entry<GroupedStatsIdentity, List<GroupedStats>> stats : groupedStats.entrySet()) {
        String processorName = stats.getKey().getProcessorName();
        String processorId = stats.getKey().getProcessorId();
        Map<String, AggregatedProcessorStatistics> processorStatsMap = feedProcessorStatistics.getProcessorStats();
        if (!processorStatsMap.containsKey(processorName)) {
            processorStatsMap.put(processorName, new AggregatedProcessorStatisticsV2(processorId, processorName, collectionId));
        }
        AggregatedProcessorStatistics processorStatistics = processorStatsMap.get(processorName);
        for (GroupedStats s : stats.getValue()) {
            GroupedStatsUtil.addStats1(processorStatistics.getStats(GroupedStats.DEFAULT_SOURCE_CONNECTION_ID), s);
        }
    /*
            AggregatedProcessorStatistics
                processorStatistics =
                feedProcessorStatistics.getProcessorStats()
                    .computeIfAbsent(processorName, k -> new AggregatedProcessorStatisticsV2(processorId, k, collectionId));


            stats.getValue().stream().forEach( s ->  GroupedStatsUtil.add(processorStatistics.getStats(GroupedStats.DEFAULT_SOURCE_CONNECTION_ID), s));
            */
    }
    return feedProcessorStatistics;
}
Also used : GroupedStats(com.thinkbiganalytics.nifi.provenance.model.stats.GroupedStats) ArrayList(java.util.ArrayList) List(java.util.List) AggregatedProcessorStatistics(com.thinkbiganalytics.nifi.provenance.model.stats.AggregatedProcessorStatistics) GroupedStatsIdentity(com.thinkbiganalytics.nifi.provenance.model.stats.GroupedStatsIdentity) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Map(java.util.Map) AggregatedFeedProcessorStatisticsV2(com.thinkbiganalytics.nifi.provenance.model.stats.AggregatedFeedProcessorStatisticsV2) AggregatedProcessorStatisticsV2(com.thinkbiganalytics.nifi.provenance.model.stats.AggregatedProcessorStatisticsV2)

Example 3 with GroupedStats

use of com.thinkbiganalytics.nifi.provenance.model.stats.GroupedStats in project kylo by Teradata.

the class GroupedStatsUtil method gatherStats.

/**
 * Gather feed stats for a list of events
 */
public static AggregatedFeedProcessorStatisticsHolder gatherStats(final List<ProvenanceEventRecordDTO> events) {
    Map<String, Map<GroupedStatsIdentity, List<GroupedStats>>> feedStatsByProcessor = new ConcurrentHashMap<>();
    // events.stream().forEach(e -> {
    for (ProvenanceEventRecordDTO e : events) {
        if (!feedStatsByProcessor.containsKey(e.getFeedName())) {
            feedStatsByProcessor.put(e.getFeedName(), new ConcurrentHashMap<GroupedStatsIdentity, List<GroupedStats>>());
        }
        // feedStatsByProcessor.putIfAbsent(e.getFeedName(), );
        Map<GroupedStatsIdentity, List<GroupedStats>> feedStats = feedStatsByProcessor.get(e.getFeedName());
        GroupedStatsIdentity identity = new GroupedStatsIdentity(e.getComponentId(), e.getComponentName());
        if (!feedStats.containsKey(identity)) {
            feedStats.put(identity, new ArrayList<GroupedStats>());
        }
        // feedStats.putIfAbsent(identity, new ArrayList<>());
        List<GroupedStats> feedProcessorStats = feedStats.get(identity);
        // Add the new stats
        GroupedStats statsV2 = GroupedStatsUtil.add(new GroupedStatsV2(), e);
        feedProcessorStats.add(statsV2);
    }
    // );
    List<AggregatedFeedProcessorStatistics> statsList = new ArrayList<>();
    for (Map.Entry<String, Map<GroupedStatsIdentity, List<GroupedStats>>> feedStats : feedStatsByProcessor.entrySet()) {
        AggregatedFeedProcessorStatistics feedProcessorStatistics = GroupedStatsUtil.groupStatsByProcessor(feedStats.getKey(), feedStats.getValue());
        statsList.add(feedProcessorStatistics);
    }
    /* feedStatsByProcessor.entrySet().stream().forEach(feedStats -> {
            AggregatedFeedProcessorStatistics feedProcessorStatistics = GroupedStatsUtil.groupStatsByProcessor(feedStats.getKey(), feedStats.getValue());
            statsList.add(feedProcessorStatistics);
        });
        */
    AggregatedFeedProcessorStatisticsHolderV3 feedProcessorStatisticsHolderV3 = new AggregatedFeedProcessorStatisticsHolderV3();
    feedProcessorStatisticsHolderV3.setFeedStatistics(statsList);
    return feedProcessorStatisticsHolderV3;
}
Also used : GroupedStats(com.thinkbiganalytics.nifi.provenance.model.stats.GroupedStats) ProvenanceEventRecordDTO(com.thinkbiganalytics.nifi.provenance.model.ProvenanceEventRecordDTO) ArrayList(java.util.ArrayList) AggregatedFeedProcessorStatistics(com.thinkbiganalytics.nifi.provenance.model.stats.AggregatedFeedProcessorStatistics) GroupedStatsIdentity(com.thinkbiganalytics.nifi.provenance.model.stats.GroupedStatsIdentity) ArrayList(java.util.ArrayList) List(java.util.List) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Map(java.util.Map) GroupedStatsV2(com.thinkbiganalytics.nifi.provenance.model.stats.GroupedStatsV2) AggregatedFeedProcessorStatisticsHolderV3(com.thinkbiganalytics.nifi.provenance.model.stats.AggregatedFeedProcessorStatisticsHolderV3)

Aggregations

GroupedStats (com.thinkbiganalytics.nifi.provenance.model.stats.GroupedStats)3 GroupedStatsIdentity (com.thinkbiganalytics.nifi.provenance.model.stats.GroupedStatsIdentity)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Map (java.util.Map)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 ProvenanceEventRecordDTO (com.thinkbiganalytics.nifi.provenance.model.ProvenanceEventRecordDTO)1 AggregatedFeedProcessorStatistics (com.thinkbiganalytics.nifi.provenance.model.stats.AggregatedFeedProcessorStatistics)1 AggregatedFeedProcessorStatisticsHolderV3 (com.thinkbiganalytics.nifi.provenance.model.stats.AggregatedFeedProcessorStatisticsHolderV3)1 AggregatedFeedProcessorStatisticsV2 (com.thinkbiganalytics.nifi.provenance.model.stats.AggregatedFeedProcessorStatisticsV2)1 AggregatedProcessorStatistics (com.thinkbiganalytics.nifi.provenance.model.stats.AggregatedProcessorStatistics)1 AggregatedProcessorStatisticsV2 (com.thinkbiganalytics.nifi.provenance.model.stats.AggregatedProcessorStatisticsV2)1 GroupedStatsV2 (com.thinkbiganalytics.nifi.provenance.model.stats.GroupedStatsV2)1