Search in sources :

Example 1 with AggregatedFeedProcessorStatisticsHolderV3

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

the class NifiStatsJmsReceiver method saveFeedStats.

/**
 * Save the running totals for the feed
 */
private Map<String, JpaNifiFeedStats> saveFeedStats(AggregatedFeedProcessorStatisticsHolderV2 holder, List<NifiFeedProcessorStats> summaryStats) {
    Map<String, JpaNifiFeedStats> feedStatsMap = new HashMap<>();
    if (summaryStats != null) {
        Map<String, Long> feedLatestTimestamp = summaryStats.stream().collect(Collectors.toMap(NifiFeedProcessorStats::getFeedName, stats -> stats.getMinEventTime().getMillis(), Long::max));
        feedLatestTimestamp.entrySet().stream().forEach(e -> {
            String feedName = e.getKey();
            Long timestamp = e.getValue();
            JpaNifiFeedStats stats = feedStatsMap.computeIfAbsent(feedName, name -> new JpaNifiFeedStats(feedName));
            OpsManagerFeed opsManagerFeed = provenanceEventFeedUtil.getFeed(feedName);
            if (opsManagerFeed != null) {
                stats.setFeedId(new JpaNifiFeedStats.OpsManagerFeedId(opsManagerFeed.getId().toString()));
            }
            stats.setLastActivityTimestamp(timestamp);
        });
    }
    if (holder.getProcessorIdRunningFlows() != null) {
        holder.getProcessorIdRunningFlows().entrySet().stream().forEach(e -> {
            String feedProcessorId = e.getKey();
            Long runningCount = e.getValue();
            // ensure not null
            String feedName = provenanceEventFeedUtil.getFeedName(feedProcessorId);
            if (StringUtils.isNotBlank(feedName)) {
                JpaNifiFeedStats stats = feedStatsMap.computeIfAbsent(feedName, name -> new JpaNifiFeedStats(feedName));
                OpsManagerFeed opsManagerFeed = provenanceEventFeedUtil.getFeed(feedName);
                if (opsManagerFeed != null) {
                    stats.setFeedId(new JpaNifiFeedStats.OpsManagerFeedId(opsManagerFeed.getId().toString()));
                    stats.setStream(opsManagerFeed.isStream());
                }
                stats.addRunningFeedFlows(runningCount);
                if (holder instanceof AggregatedFeedProcessorStatisticsHolderV3) {
                    stats.setTime(((AggregatedFeedProcessorStatisticsHolderV3) holder).getTimestamp());
                    if (stats.getLastActivityTimestamp() == null) {
                        stats.setLastActivityTimestamp(((AggregatedFeedProcessorStatisticsHolderV3) holder).getTimestamp());
                    }
                } else {
                    stats.setTime(DateTime.now().getMillis());
                }
                if (stats.getLastActivityTimestamp() == null) {
                    log.warn("The JpaNifiFeedStats.lastActivityTimestamp for the feed {} is NULL.  The JMS Class was: {}", feedName, holder.getClass().getSimpleName());
                }
            }
        });
    }
    // group stats to save together by feed name
    if (!feedStatsMap.isEmpty()) {
        // only save those that have changed
        List<NifiFeedStats> updatedStats = feedStatsMap.entrySet().stream().map(e -> e.getValue()).collect(Collectors.toList());
        // if the running flows are 0 and its streaming we should try back to see if this feed is running or not
        updatedStats.stream().filter(s -> s.isStream()).forEach(stats -> {
            latestStatsCache.put(stats.getFeedName(), (JpaNifiFeedStats) stats);
            if (stats.getRunningFeedFlows() == 0L) {
                batchJobExecutionProvider.markStreamingFeedAsStopped(stats.getFeedName());
            } else {
                batchJobExecutionProvider.markStreamingFeedAsStarted(stats.getFeedName());
            }
        });
        nifiFeedStatisticsProvider.saveLatestFeedStats(updatedStats);
    }
    return feedStatsMap;
}
Also used : JpaNifiFeedStats(com.thinkbiganalytics.metadata.jpa.jobrepo.nifi.JpaNifiFeedStats) DateTimeZone(org.joda.time.DateTimeZone) LoadingCache(com.google.common.cache.LoadingCache) JobScheduler(com.thinkbiganalytics.scheduler.JobScheduler) ClusterServiceMessageReceiver(com.thinkbiganalytics.cluster.ClusterServiceMessageReceiver) ProvenanceEventRecordDTOHolder(com.thinkbiganalytics.nifi.provenance.model.ProvenanceEventRecordDTOHolder) LoggerFactory(org.slf4j.LoggerFactory) AggregatedFeedProcessorStatistics(com.thinkbiganalytics.nifi.provenance.model.stats.AggregatedFeedProcessorStatistics) NifiFeedProcessorStats(com.thinkbiganalytics.metadata.api.jobrepo.nifi.NifiFeedProcessorStats) StringUtils(org.apache.commons.lang3.StringUtils) Queues(com.thinkbiganalytics.jms.Queues) NifiFeedProcessorErrors(com.thinkbiganalytics.metadata.api.jobrepo.nifi.NifiFeedProcessorErrors) NifiFeedProcessorStatisticsProvider(com.thinkbiganalytics.metadata.api.jobrepo.nifi.NifiFeedProcessorStatisticsProvider) DefaultTriggerIdentifier(com.thinkbiganalytics.scheduler.model.DefaultTriggerIdentifier) Map(java.util.Map) OpsManagerFeed(com.thinkbiganalytics.metadata.api.feed.OpsManagerFeed) JmsListener(org.springframework.jms.annotation.JmsListener) MetadataAccess(com.thinkbiganalytics.metadata.api.MetadataAccess) NifiFeedStatisticsProvider(com.thinkbiganalytics.metadata.api.jobrepo.nifi.NifiFeedStatisticsProvider) BulletinDTO(org.apache.nifi.web.api.dto.BulletinDTO) AggregatedFeedProcessorStatisticsHolderV3(com.thinkbiganalytics.nifi.provenance.model.stats.AggregatedFeedProcessorStatisticsHolderV3) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) AggregatedFeedProcessorStatisticsHolderV2(com.thinkbiganalytics.nifi.provenance.model.stats.AggregatedFeedProcessorStatisticsHolderV2) ObjectAlreadyExistsException(org.quartz.ObjectAlreadyExistsException) Set(java.util.Set) ClusterMessage(com.thinkbiganalytics.cluster.ClusterMessage) Collectors(java.util.stream.Collectors) CacheLoader(com.google.common.cache.CacheLoader) BatchJobExecutionProvider(com.thinkbiganalytics.metadata.api.jobrepo.job.BatchJobExecutionProvider) List(java.util.List) AggregatedFeedProcessorStatisticsV2(com.thinkbiganalytics.nifi.provenance.model.stats.AggregatedFeedProcessorStatisticsV2) GroupedStatsV2(com.thinkbiganalytics.nifi.provenance.model.stats.GroupedStatsV2) DefaultJobIdentifier(com.thinkbiganalytics.scheduler.model.DefaultJobIdentifier) PostConstruct(javax.annotation.PostConstruct) ClusterService(com.thinkbiganalytics.cluster.ClusterService) CacheBuilder(com.google.common.cache.CacheBuilder) Queue(java.util.Queue) QuartzScheduler(com.thinkbiganalytics.scheduler.QuartzScheduler) AggregatedFeedProcessorStatisticsHolder(com.thinkbiganalytics.nifi.provenance.model.stats.AggregatedFeedProcessorStatisticsHolder) SerializationUtils(org.apache.commons.lang.SerializationUtils) HashMap(java.util.HashMap) JpaNifiFeedStats(com.thinkbiganalytics.metadata.jpa.jobrepo.nifi.JpaNifiFeedStats) ArrayList(java.util.ArrayList) Value(org.springframework.beans.factory.annotation.Value) HashSet(java.util.HashSet) Inject(javax.inject.Inject) SchedulerException(org.quartz.SchedulerException) EvictingQueue(com.google.common.collect.EvictingQueue) JmsConstants(com.thinkbiganalytics.jms.JmsConstants) ProvenanceEventRecordDTO(com.thinkbiganalytics.nifi.provenance.model.ProvenanceEventRecordDTO) JobIdentifier(com.thinkbiganalytics.scheduler.JobIdentifier) Logger(org.slf4j.Logger) DateTime(org.joda.time.DateTime) NifiFeedStats(com.thinkbiganalytics.metadata.api.jobrepo.nifi.NifiFeedStats) JpaNifiFeedProcessorStats(com.thinkbiganalytics.metadata.jpa.jobrepo.nifi.JpaNifiFeedProcessorStats) TriggerIdentifier(com.thinkbiganalytics.scheduler.TriggerIdentifier) Collections(java.util.Collections) GroupedStats(com.thinkbiganalytics.nifi.provenance.model.stats.GroupedStats) OpsManagerFeed(com.thinkbiganalytics.metadata.api.feed.OpsManagerFeed) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) JpaNifiFeedStats(com.thinkbiganalytics.metadata.jpa.jobrepo.nifi.JpaNifiFeedStats) NifiFeedStats(com.thinkbiganalytics.metadata.api.jobrepo.nifi.NifiFeedStats) AggregatedFeedProcessorStatisticsHolderV3(com.thinkbiganalytics.nifi.provenance.model.stats.AggregatedFeedProcessorStatisticsHolderV3)

Example 2 with AggregatedFeedProcessorStatisticsHolderV3

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

the class JmsSender method run.

public void run() {
    try {
        if (eventsToSend != null && !eventsToSend.isEmpty()) {
            ProvenanceEventRecordDTOHolder eventRecordDTOHolder = new ProvenanceEventRecordDTOHolder();
            eventRecordDTOHolder.setEvents(eventsToSend);
            getProvenanceEventActiveMqWriter().writeBatchEvents(eventRecordDTOHolder);
        }
        if (statsToSend != null && !statsToSend.isEmpty()) {
            AggregatedFeedProcessorStatisticsHolderV3 statsHolder = new AggregatedFeedProcessorStatisticsHolderV3();
            statsHolder.setProcessorIdRunningFlows(processorIdRunningFlows);
            statsHolder.setCollectionId(statsToSend.get(0).getCollectionId());
            statsHolder.setFeedStatistics(statsToSend);
            getProvenanceEventActiveMqWriter().writeStats(statsHolder);
        }
        // if there are no events to send then send off the running flows map
        if (eventsToSend == null && statsToSend == null) {
            log.info("Sending Running Flow counts statistics for feeds to JMS");
            AggregatedFeedProcessorStatisticsHolderV3 statsHolder = new AggregatedFeedProcessorStatisticsHolderV3();
            statsHolder.setProcessorIdRunningFlows(processorIdRunningFlows);
            statsHolder.setCollectionId(UUID.randomUUID().toString());
            statsHolder.setFeedStatistics(statsToSend);
            getProvenanceEventActiveMqWriter().writeStats(statsHolder);
        }
    } catch (Exception e) {
        log.error("Error writing provenance events to JMS", e);
    }
}
Also used : ProvenanceEventRecordDTOHolder(com.thinkbiganalytics.nifi.provenance.model.ProvenanceEventRecordDTOHolder) AggregatedFeedProcessorStatisticsHolderV3(com.thinkbiganalytics.nifi.provenance.model.stats.AggregatedFeedProcessorStatisticsHolderV3)

Example 3 with AggregatedFeedProcessorStatisticsHolderV3

use of com.thinkbiganalytics.nifi.provenance.model.stats.AggregatedFeedProcessorStatisticsHolderV3 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

AggregatedFeedProcessorStatisticsHolderV3 (com.thinkbiganalytics.nifi.provenance.model.stats.AggregatedFeedProcessorStatisticsHolderV3)3 ProvenanceEventRecordDTO (com.thinkbiganalytics.nifi.provenance.model.ProvenanceEventRecordDTO)2 ProvenanceEventRecordDTOHolder (com.thinkbiganalytics.nifi.provenance.model.ProvenanceEventRecordDTOHolder)2 AggregatedFeedProcessorStatistics (com.thinkbiganalytics.nifi.provenance.model.stats.AggregatedFeedProcessorStatistics)2 GroupedStats (com.thinkbiganalytics.nifi.provenance.model.stats.GroupedStats)2 GroupedStatsV2 (com.thinkbiganalytics.nifi.provenance.model.stats.GroupedStatsV2)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Map (java.util.Map)2 CacheBuilder (com.google.common.cache.CacheBuilder)1 CacheLoader (com.google.common.cache.CacheLoader)1 LoadingCache (com.google.common.cache.LoadingCache)1 EvictingQueue (com.google.common.collect.EvictingQueue)1 ClusterMessage (com.thinkbiganalytics.cluster.ClusterMessage)1 ClusterService (com.thinkbiganalytics.cluster.ClusterService)1 ClusterServiceMessageReceiver (com.thinkbiganalytics.cluster.ClusterServiceMessageReceiver)1 JmsConstants (com.thinkbiganalytics.jms.JmsConstants)1 Queues (com.thinkbiganalytics.jms.Queues)1 MetadataAccess (com.thinkbiganalytics.metadata.api.MetadataAccess)1 OpsManagerFeed (com.thinkbiganalytics.metadata.api.feed.OpsManagerFeed)1