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