Search in sources :

Example 6 with OpsManagerFeed

use of com.thinkbiganalytics.metadata.api.feed.OpsManagerFeed in project kylo by Teradata.

the class JpaBatchJobExecutionProvider method createJobInstance.

@Override
public BatchJobInstance createJobInstance(ProvenanceEventRecordDTO event) {
    JpaBatchJobInstance jobInstance = new JpaBatchJobInstance();
    jobInstance.setJobKey(jobKeyGenerator(event));
    jobInstance.setJobName(event.getFeedName());
    // wire this instance to the Feed
    OpsManagerFeed feed = opsManagerFeedRepository.findByName(event.getFeedName());
    jobInstance.setFeed(feed);
    BatchJobInstance batchJobInstance = this.jobInstanceRepository.save(jobInstance);
    return batchJobInstance;
}
Also used : OpsManagerFeed(com.thinkbiganalytics.metadata.api.feed.OpsManagerFeed) JpaOpsManagerFeed(com.thinkbiganalytics.metadata.jpa.feed.JpaOpsManagerFeed) QJpaOpsManagerFeed(com.thinkbiganalytics.metadata.jpa.feed.QJpaOpsManagerFeed) BatchJobInstance(com.thinkbiganalytics.metadata.api.jobrepo.job.BatchJobInstance)

Example 7 with OpsManagerFeed

use of com.thinkbiganalytics.metadata.api.feed.OpsManagerFeed in project kylo by Teradata.

the class FeedOpsUpgradeAction method upgradeTo.

/* (non-Javadoc)
     * @see com.thinkbiganalytics.metadata.upgrade.UpgradeState#upgradeFrom(com.thinkbiganalytics.metadata.api.app.KyloVersion)
     */
@Override
public void upgradeTo(KyloVersion startingVersion) {
    log.info("Upgrading from version: " + startingVersion);
    for (Category category : categoryProvider.findAll()) {
        // Ensure each category has an allowedActions (gets create if not present.)
        category.getAllowedActions();
    }
    // get all feeds defined in feed manager
    List<Feed> domainFeeds = feedProvider.findAll();
    Map<String, Feed> feedManagerFeedMap = new HashMap<>();
    if (domainFeeds != null && !domainFeeds.isEmpty()) {
        List<OpsManagerFeed.ID> opsManagerFeedIds = new ArrayList<OpsManagerFeed.ID>();
        for (Feed feedManagerFeed : domainFeeds) {
            opsManagerFeedIds.add(opsManagerFeedProvider.resolveId(feedManagerFeed.getId().toString()));
            feedManagerFeedMap.put(feedManagerFeed.getId().toString(), feedManagerFeed);
            // Ensure each feed has an allowedActions (gets create if not present.)
            feedManagerFeed.getAllowedActions();
        }
        // find those that match
        List<? extends OpsManagerFeed> opsManagerFeeds = opsManagerFeedProvider.findByFeedIds(opsManagerFeedIds);
        if (opsManagerFeeds != null) {
            for (OpsManagerFeed opsManagerFeed : opsManagerFeeds) {
                feedManagerFeedMap.remove(opsManagerFeed.getId().toString());
            }
        }
        List<OpsManagerFeed> feedsToAdd = new ArrayList<>();
        for (Feed feed : feedManagerFeedMap.values()) {
            String fullName = FeedNameUtil.fullName(feed.getCategory().getSystemName(), feed.getName());
            OpsManagerFeed.ID opsManagerFeedId = opsManagerFeedProvider.resolveId(feed.getId().toString());
            OpsManagerFeed opsManagerFeed = new JpaOpsManagerFeed(opsManagerFeedId, fullName);
            feedsToAdd.add(opsManagerFeed);
        }
        log.info("Synchronizing Feeds from Feed Manager. About to insert {} feed ids/names into Operations Manager", feedsToAdd.size());
        opsManagerFeedProvider.save(feedsToAdd);
    }
}
Also used : Category(com.thinkbiganalytics.metadata.api.category.Category) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) JpaOpsManagerFeed(com.thinkbiganalytics.metadata.jpa.feed.JpaOpsManagerFeed) JpaOpsManagerFeed(com.thinkbiganalytics.metadata.jpa.feed.JpaOpsManagerFeed) OpsManagerFeed(com.thinkbiganalytics.metadata.api.feed.OpsManagerFeed) Feed(com.thinkbiganalytics.metadata.api.feed.Feed) JpaOpsManagerFeed(com.thinkbiganalytics.metadata.jpa.feed.JpaOpsManagerFeed) OpsManagerFeed(com.thinkbiganalytics.metadata.api.feed.OpsManagerFeed)

Example 8 with OpsManagerFeed

use of com.thinkbiganalytics.metadata.api.feed.OpsManagerFeed in project kylo by Teradata.

the class DefaultJobService method failJobExecution.

@Override
public void failJobExecution(Long executionId) {
    metadataAccess.commit(() -> {
        BatchJobExecution execution = this.jobExecutionProvider.findByJobExecutionId(executionId, false);
        if (execution != null && !execution.isFailed()) {
            Set<BatchStepExecution> steps = execution.getStepExecutions();
            if (steps != null) {
                for (BatchStepExecution step : steps) {
                    if (!step.isFinished()) {
                        step.setStatus(BatchStepExecution.StepStatus.FAILED);
                        step.setExitCode(ExecutionConstants.ExitCode.FAILED);
                        String msg = step.getExitMessage() != null ? step.getExitMessage() + "\n" : "";
                        msg += "Step manually failed @ " + DateTimeUtil.getNowFormattedWithTimeZone();
                        step.setExitMessage(msg);
                        execution.setExitMessage(msg);
                    }
                }
            }
            if (execution.getStartTime() == null) {
                execution.setStartTime(DateTimeUtil.getNowUTCTime());
            }
            execution.setStatus(BatchJobExecution.JobStatus.FAILED);
            if (execution.getEndTime() == null) {
                execution.setEndTime(DateTimeUtil.getNowUTCTime());
            }
            String msg = execution.getExitMessage() != null ? execution.getExitMessage() + "\n" : "";
            msg += "Job manually failed @ " + DateTimeUtil.getNowFormattedWithTimeZone();
            execution.setExitMessage(msg);
            OpsManagerFeed feed = execution.getJobInstance().getFeed();
            this.jobExecutionProvider.save(execution);
            this.jobExecutionProvider.notifyFailure(execution, feed, false, "Job manually failed @ " + DateTimeUtil.getNowFormattedWithTimeZone());
        }
        return execution;
    });
}
Also used : JpaBatchJobExecution(com.thinkbiganalytics.metadata.jpa.jobrepo.job.JpaBatchJobExecution) BatchJobExecution(com.thinkbiganalytics.metadata.api.jobrepo.job.BatchJobExecution) OpsManagerFeed(com.thinkbiganalytics.metadata.api.feed.OpsManagerFeed) BatchStepExecution(com.thinkbiganalytics.metadata.api.jobrepo.step.BatchStepExecution)

Example 9 with OpsManagerFeed

use of com.thinkbiganalytics.metadata.api.feed.OpsManagerFeed in project kylo by Teradata.

the class NifiStatsJmsReceiver method ensureStreamingJobExecutionRecord.

private void ensureStreamingJobExecutionRecord(NifiFeedProcessorStats stats) {
    if (stats.getJobsStarted() > 0 || stats.getJobsFinished() > 0) {
        OpsManagerFeed feed = provenanceEventFeedUtil.getFeed(stats.getFeedName());
        if (feed.isStream()) {
            ProvenanceEventRecordDTO event = new ProvenanceEventRecordDTO();
            event.setEventId(stats.getMaxEventId());
            event.setEventTime(stats.getMinEventTime().getMillis());
            event.setEventDuration(stats.getDuration());
            event.setFlowFileUuid(stats.getLatestFlowFileId());
            event.setJobFlowFileId(stats.getLatestFlowFileId());
            event.setComponentId(stats.getProcessorId());
            event.setComponentName(stats.getProcessorName());
            event.setIsFailure(stats.getFailedCount() > 0L);
            event.setStream(feed.isStream());
            event.setIsStartOfJob(stats.getJobsStarted() > 0L);
            event.setIsFinalJobEvent(stats.getJobsFinished() > 0L);
            event.setFeedProcessGroupId(stats.getFeedProcessGroupId());
            event.setFeedName(stats.getFeedName());
            ProvenanceEventRecordDTOHolder holder = new ProvenanceEventRecordDTOHolder();
            List<ProvenanceEventRecordDTO> events = new ArrayList<>();
            events.add(event);
            holder.setEvents(events);
            log.info("Ensuring Streaming Feed Event: {} has a respective JobExecution record ", event);
            provenanceEventReceiver.receiveEvents(holder);
        }
    }
}
Also used : OpsManagerFeed(com.thinkbiganalytics.metadata.api.feed.OpsManagerFeed) ProvenanceEventRecordDTO(com.thinkbiganalytics.nifi.provenance.model.ProvenanceEventRecordDTO) ProvenanceEventRecordDTOHolder(com.thinkbiganalytics.nifi.provenance.model.ProvenanceEventRecordDTOHolder) ArrayList(java.util.ArrayList)

Example 10 with OpsManagerFeed

use of com.thinkbiganalytics.metadata.api.feed.OpsManagerFeed 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)

Aggregations

OpsManagerFeed (com.thinkbiganalytics.metadata.api.feed.OpsManagerFeed)23 BatchJobExecution (com.thinkbiganalytics.metadata.api.jobrepo.job.BatchJobExecution)6 ArrayList (java.util.ArrayList)6 JpaOpsManagerFeed (com.thinkbiganalytics.metadata.jpa.feed.JpaOpsManagerFeed)4 HashMap (java.util.HashMap)4 Feed (com.thinkbiganalytics.metadata.api.feed.Feed)3 NifiFeedStats (com.thinkbiganalytics.metadata.api.jobrepo.nifi.NifiFeedStats)3 QJpaOpsManagerFeed (com.thinkbiganalytics.metadata.jpa.feed.QJpaOpsManagerFeed)3 JpaNifiFeedStats (com.thinkbiganalytics.metadata.jpa.jobrepo.nifi.JpaNifiFeedStats)3 DateTime (org.joda.time.DateTime)3 CacheBuilder (com.google.common.cache.CacheBuilder)2 CacheLoader (com.google.common.cache.CacheLoader)2 LoadingCache (com.google.common.cache.LoadingCache)2 FeedHealth (com.thinkbiganalytics.jobrepo.query.model.FeedHealth)2 MetadataAccess (com.thinkbiganalytics.metadata.api.MetadataAccess)2 NifiFeedProcessorStats (com.thinkbiganalytics.metadata.api.jobrepo.nifi.NifiFeedProcessorStats)2 ProvenanceEventRecordDTO (com.thinkbiganalytics.nifi.provenance.model.ProvenanceEventRecordDTO)2 ProvenanceEventRecordDTOHolder (com.thinkbiganalytics.nifi.provenance.model.ProvenanceEventRecordDTOHolder)2 Stopwatch (com.google.common.base.Stopwatch)1 EvictingQueue (com.google.common.collect.EvictingQueue)1