Search in sources :

Example 1 with BatchJobExecution

use of com.thinkbiganalytics.metadata.api.jobrepo.job.BatchJobExecution in project kylo by Teradata.

the class JpaBatchJobExecutionProvider method markStreamingFeedAsStopped.

public void markStreamingFeedAsStopped(String feed) {
    BatchJobExecution jobExecution = findLatestJobForFeed(feed);
    if (jobExecution != null && !jobExecution.getStatus().equals(BatchJobExecution.JobStatus.STOPPED)) {
        log.info("Stopping Streaming feed job {} for Feed {} ", jobExecution.getJobExecutionId(), feed);
        jobExecution.setStatus(BatchJobExecution.JobStatus.STOPPED);
        jobExecution.setExitCode(ExecutionConstants.ExitCode.COMPLETED);
        ((JpaBatchJobExecution) jobExecution).setLastUpdated(DateTimeUtil.getNowUTCTime());
        jobExecution.setEndTime(DateTimeUtil.getNowUTCTime());
        save(jobExecution);
        // update the cache
        latestStreamingJobByFeedName.put(feed, jobExecution);
    }
}
Also used : BatchJobExecution(com.thinkbiganalytics.metadata.api.jobrepo.job.BatchJobExecution)

Example 2 with BatchJobExecution

use of com.thinkbiganalytics.metadata.api.jobrepo.job.BatchJobExecution in project kylo by Teradata.

the class OpsFeedManagerFeedProvider method updateStreamingFlag.

/**
 * Sets the stream flag for the list of feeds
 *
 * @param feedNames the feed names to update
 * @param isStream  true if stream/ false if not
 */
public void updateStreamingFlag(Set<String> feedNames, boolean isStream) {
    List<JpaOpsManagerFeed> feeds = (List<JpaOpsManagerFeed>) findByFeedNames(feedNames, false);
    if (feeds != null) {
        for (JpaOpsManagerFeed feed : feeds) {
            // if we move from a stream to a batch we need to stop/complete the running stream job
            if (feed.isStream() && !isStream) {
                BatchJobExecution jobExecution = batchJobExecutionProvider.findLatestJobForFeed(feed.getName());
                if (jobExecution != null && !jobExecution.isFinished()) {
                    jobExecution.setStatus(BatchJobExecution.JobStatus.STOPPED);
                    jobExecution.setExitCode(ExecutionConstants.ExitCode.COMPLETED);
                    jobExecution.setEndTime(DateTime.now());
                    jobExecution = batchJobExecutionProvider.save(jobExecution);
                    batchJobExecutionProvider.notifyStopped(jobExecution, feed, null);
                    // notify stream to batch for feed
                    batchJobExecutionProvider.notifyStreamToBatch(jobExecution, feed);
                }
            } else if (!feed.isStream() && isStream) {
                // if we move from a batch to a stream we need to complete any jobs that are running.
                batchJobExecutionProvider.findRunningJobsForFeed(feed.getName()).stream().forEach(jobExecution -> {
                    jobExecution.setExitCode(ExecutionConstants.ExitCode.STOPPED);
                    jobExecution.setEndTime(DateTime.now());
                    jobExecution.setExitMessage("Stopping and Abandoning the Job.  The job was running while the feed/template changed from a batch to a stream");
                    jobExecution.setStatus(BatchJobExecution.JobStatus.ABANDONED);
                    batchJobExecutionProvider.save(jobExecution);
                    log.info("Stopping and Abandoning the Job {} for feed {}.  The job was running while the feed/template changed from a batch to a stream", jobExecution.getJobExecutionId(), feed.getName());
                    batchJobExecutionProvider.notifyFailure(jobExecution, feed, false, null);
                    // notify batch to stream for feed
                    batchJobExecutionProvider.notifyBatchToStream(jobExecution, feed);
                });
            }
            feed.setStream(isStream);
        }
        save(feeds);
    }
}
Also used : AlertManager(com.thinkbiganalytics.alerts.spi.AlertManager) JobStatusCount(com.thinkbiganalytics.metadata.api.jobrepo.job.JobStatusCount) Spliterators(java.util.Spliterators) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) JpaBatchJobExecutionStatusCounts(com.thinkbiganalytics.metadata.jpa.jobrepo.job.JpaBatchJobExecutionStatusCounts) Projections(com.querydsl.core.types.Projections) GenericQueryDslFilter(com.thinkbiganalytics.metadata.jpa.support.GenericQueryDslFilter) Map(java.util.Map) AccessController(com.thinkbiganalytics.security.AccessController) OpsManagerFeed(com.thinkbiganalytics.metadata.api.feed.OpsManagerFeed) MetadataAccess(com.thinkbiganalytics.metadata.api.MetadataAccess) SecurityContextHolder(org.springframework.security.core.context.SecurityContextHolder) NifiFeedStatisticsProvider(com.thinkbiganalytics.metadata.api.jobrepo.nifi.NifiFeedStatisticsProvider) OpsManagerFeedProvider(com.thinkbiganalytics.metadata.api.feed.OpsManagerFeedProvider) Collection(java.util.Collection) Set(java.util.Set) MetadataEventService(com.thinkbiganalytics.metadata.api.event.MetadataEventService) Collectors(java.util.stream.Collectors) Serializable(java.io.Serializable) JPAQuery(com.querydsl.jpa.impl.JPAQuery) BatchJobExecutionProvider(com.thinkbiganalytics.metadata.api.jobrepo.job.BatchJobExecutionProvider) ReadablePeriod(org.joda.time.ReadablePeriod) List(java.util.List) ExecutionConstants(com.thinkbiganalytics.metadata.api.jobrepo.ExecutionConstants) Expressions(com.querydsl.core.types.dsl.Expressions) PostConstruct(javax.annotation.PostConstruct) BatchJobExecution(com.thinkbiganalytics.metadata.api.jobrepo.job.BatchJobExecution) Spliterator(java.util.Spliterator) AlertCriteria(com.thinkbiganalytics.alerts.api.AlertCriteria) JpaServiceLevelAgreementDescription(com.thinkbiganalytics.metadata.jpa.sla.JpaServiceLevelAgreementDescription) DateTimeUtil(com.thinkbiganalytics.DateTimeUtil) BooleanBuilder(com.querydsl.core.BooleanBuilder) QJpaBatchJobExecution(com.thinkbiganalytics.metadata.jpa.jobrepo.job.QJpaBatchJobExecution) JpaNifiFeedStats(com.thinkbiganalytics.metadata.jpa.jobrepo.nifi.JpaNifiFeedStats) Value(org.springframework.beans.factory.annotation.Value) HashSet(java.util.HashSet) Inject(javax.inject.Inject) AlertProvider(com.thinkbiganalytics.alerts.api.AlertProvider) Lists(com.google.common.collect.Lists) Alert(com.thinkbiganalytics.alerts.api.Alert) Service(org.springframework.stereotype.Service) StreamSupport(java.util.stream.StreamSupport) Named(javax.inject.Named) LatestFeedJobExecution(com.thinkbiganalytics.metadata.api.feed.LatestFeedJobExecution) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) FeedNameUtil(com.thinkbiganalytics.support.FeedNameUtil) DateTime(org.joda.time.DateTime) NifiFeedStats(com.thinkbiganalytics.metadata.api.jobrepo.nifi.NifiFeedStats) JpaServiceLevelAgreementDescriptionRepository(com.thinkbiganalytics.metadata.jpa.sla.JpaServiceLevelAgreementDescriptionRepository) AbstractCacheBackedProvider(com.thinkbiganalytics.metadata.jpa.cache.AbstractCacheBackedProvider) JPAQueryFactory(com.querydsl.jpa.impl.JPAQueryFactory) OperationalAlerts(com.thinkbiganalytics.metadata.api.alerts.OperationalAlerts) EntityAccessControlled(com.thinkbiganalytics.metadata.jpa.common.EntityAccessControlled) QJpaBatchJobInstance(com.thinkbiganalytics.metadata.jpa.jobrepo.job.QJpaBatchJobInstance) JobStatusDslQueryExpressionBuilder(com.thinkbiganalytics.metadata.jpa.support.JobStatusDslQueryExpressionBuilder) FeedHealth(com.thinkbiganalytics.metadata.api.feed.FeedHealth) FeedSummary(com.thinkbiganalytics.metadata.api.feed.FeedSummary) Collections(java.util.Collections) BatchJobExecution(com.thinkbiganalytics.metadata.api.jobrepo.job.BatchJobExecution) QJpaBatchJobExecution(com.thinkbiganalytics.metadata.jpa.jobrepo.job.QJpaBatchJobExecution) List(java.util.List)

Example 3 with BatchJobExecution

use of com.thinkbiganalytics.metadata.api.jobrepo.job.BatchJobExecution in project kylo by Teradata.

the class OpsFeedManagerFeedProvider method getLastActiveTimeStamp.

@Override
public DateTime getLastActiveTimeStamp(String feedName) {
    DateTime lastFeedTime = null;
    OpsManagerFeed feed = this.findByName(feedName);
    if (feed != null && feed.isStream()) {
        NifiFeedStats feedStats = metadataAccess.read(() -> nifiFeedStatisticsProvider.findLatestStatsForFeed(feedName));
        if (feedStats != null && feedStats.getLastActivityTimestamp() != null) {
            lastFeedTime = new DateTime(feedStats.getLastActivityTimestamp());
        } else {
            log.warn("feedStats.getLastActivityTimestamp is null for streaming feed {} ", feedName);
        }
    } else {
        BatchJobExecution jobExecution = metadataAccess.read(() -> batchJobExecutionProvider.findLatestCompletedJobForFeed(feedName));
        if (jobExecution != null) {
            lastFeedTime = jobExecution.getEndTime();
        }
    }
    return lastFeedTime;
}
Also used : OpsManagerFeed(com.thinkbiganalytics.metadata.api.feed.OpsManagerFeed) BatchJobExecution(com.thinkbiganalytics.metadata.api.jobrepo.job.BatchJobExecution) QJpaBatchJobExecution(com.thinkbiganalytics.metadata.jpa.jobrepo.job.QJpaBatchJobExecution) JpaNifiFeedStats(com.thinkbiganalytics.metadata.jpa.jobrepo.nifi.JpaNifiFeedStats) NifiFeedStats(com.thinkbiganalytics.metadata.api.jobrepo.nifi.NifiFeedStats) DateTime(org.joda.time.DateTime)

Example 4 with BatchJobExecution

use of com.thinkbiganalytics.metadata.api.jobrepo.job.BatchJobExecution in project kylo by Teradata.

the class FeedFailureService method findLatestJob.

/**
 * Find the latest Job, first looking for any failures between the last time this service ran, and now.
 *
 * @param feedName feed to check
 */
public LastFeedJob findLatestJob(String feedName) {
    LastFeedJob lastFeedJob = metadataAccess.read(() -> {
        LastFeedJob lastAssessedJob = lastAssessedFeedMap.getOrDefault(feedName, newEmptyFeedJob(DateTime.now()));
        LOG.debug("Feed failure service check.  LastAssessJob from map is {}", lastAssessedJob);
        DateTime lastAssessedTime = lastAssessedJob.getDateTime();
        if (isEmptyJob(lastAssessedJob)) {
            // attempt to get jobs since the app started
            lastAssessedTime = servicesApplicationStartupListener.getStartTime();
            lastAssessedJob.setDateTime(lastAssessedTime);
        }
        OpsManagerFeed feed = feedProvider.findByName(feedName);
        if (feed == null) {
            LOG.error("Feed Failure Service check Error!!!  Unable to find feed for:  {}", feedName);
            return newEmptyFeedJob(DateTime.now());
        }
        if (feed.isStream()) {
            List<NifiFeedProcessorStats> latestStats = nifiFeedProcessorStatisticsProvider.findLatestFinishedStatsSince(feedName, lastAssessedTime);
            LOG.debug("Streaming Feed failure check for {}.  Found {} stats", feedName, latestStats.size());
            Optional<NifiFeedProcessorStats> total = latestStats.stream().reduce((a, b) -> {
                a.setFailedCount(a.getFailedCount() + b.getFailedCount());
                if (b.getMinEventTime().isAfter(a.getMinEventTime())) {
                    a.setMinEventTime(b.getMinEventTime());
                }
                return a;
            });
            LastFeedJob lastJob = null;
            if (total.isPresent()) {
                NifiFeedProcessorStats stats = total.get();
                boolean success = stats.getFailedCount() == 0;
                lastJob = new LastFeedJob(feedName, stats.getMinEventTime(), success);
            } else {
                lastJob = new LastFeedJob(feedName, lastAssessedTime, true);
            }
            LOG.debug("{} stats for feed. Streaming Feed failure returning {}", total.isPresent() ? "Found" : "Did not find any", lastJob);
            return lastJob;
        } else {
            List<? extends BatchJobExecution> latestJobs = batchJobExecutionProvider.findLatestFinishedJobForFeedSince(feedName, lastAssessedTime);
            LOG.debug("Batch Feed failure check for {}.  Found {} jobs", feedName, latestJobs != null ? latestJobs.size() : 0);
            BatchJobExecution latestJob = latestJobs.stream().sorted(Comparator.comparing(BatchJobExecution::getEndTime).reversed()).filter(job -> FAILED.equals(job.getStatus())).findFirst().orElse(null);
            if (latestJob == null) {
                // find the last job if there are no failures
                latestJob = latestJobs.stream().sorted(Comparator.comparing(BatchJobExecution::getEndTime).reversed()).findFirst().orElse(null);
                // if the set doesnt have anything attempt to get the latest job
                if (latestJob == null) {
                    latestJob = batchJobExecutionProvider.findLatestFinishedJobForFeed(feedName);
                }
            }
            LastFeedJob lastJob = latestJob != null ? new LastFeedJob(feedName, latestJob.getEndTime(), !FAILED.equals(latestJob.getStatus()), latestJob.getJobExecutionId()) : newEmptyFeedJob(lastAssessedTime);
            LOG.debug("Batch Feed failure check returning {} for feed {}", lastJob, feedName);
            return lastJob;
        }
    }, MetadataAccess.SERVICE);
    lastAssessedFeedMap.put(feedName, lastFeedJob);
    return lastFeedJob;
}
Also used : OpsManagerFeed(com.thinkbiganalytics.metadata.api.feed.OpsManagerFeed) BatchJobExecution(com.thinkbiganalytics.metadata.api.jobrepo.job.BatchJobExecution) NifiFeedProcessorStats(com.thinkbiganalytics.metadata.api.jobrepo.nifi.NifiFeedProcessorStats) DateTime(org.joda.time.DateTime)

Example 5 with BatchJobExecution

use of com.thinkbiganalytics.metadata.api.jobrepo.job.BatchJobExecution in project kylo by Teradata.

the class DefaultJobService method restartJobExecution.

@Override
public Long restartJobExecution(ReplayJobExecution replayJobExecution) throws JobExecutionException {
    SavepointReplayJobExecution savepointReplayJobExecution = ((SavepointReplayJobExecution) replayJobExecution);
    return metadataAccess.commit(() -> {
        BatchJobExecution jobExecution = this.jobExecutionProvider.findByJobExecutionId(savepointReplayJobExecution.getJobExecutionId(), false);
        if (jobExecution != null) {
            ((JpaBatchJobExecution) jobExecution).markAsRunning();
            // trigger the jms message
            SavepointReplayEvent event = new SavepointReplayEvent();
            event.setJobExecutionId(savepointReplayJobExecution.getJobExecutionId());
            event.setFlowfileId(savepointReplayJobExecution.getFlowFileId());
            event.setAction(SavepointReplayEvent.Action.RETRY);
            savepointReplayJmsEventService.triggerSavepoint(event);
            return jobExecution.getJobExecutionId();
        }
        return null;
    });
}
Also used : JpaBatchJobExecution(com.thinkbiganalytics.metadata.jpa.jobrepo.job.JpaBatchJobExecution) BatchJobExecution(com.thinkbiganalytics.metadata.api.jobrepo.job.BatchJobExecution) SavepointReplayJobExecution(com.thinkbiganalytics.jobrepo.model.SavepointReplayJobExecution) SavepointReplayEvent(com.thinkbiganalytics.nifi.savepoint.model.SavepointReplayEvent) JpaBatchJobExecution(com.thinkbiganalytics.metadata.jpa.jobrepo.job.JpaBatchJobExecution)

Aggregations

BatchJobExecution (com.thinkbiganalytics.metadata.api.jobrepo.job.BatchJobExecution)23 OpsManagerFeed (com.thinkbiganalytics.metadata.api.feed.OpsManagerFeed)8 DateTime (org.joda.time.DateTime)7 ArrayList (java.util.ArrayList)5 MetadataAccess (com.thinkbiganalytics.metadata.api.MetadataAccess)3 MetadataEventService (com.thinkbiganalytics.metadata.api.event.MetadataEventService)3 BatchJobExecutionProvider (com.thinkbiganalytics.metadata.api.jobrepo.job.BatchJobExecutionProvider)3 JpaBatchJobExecution (com.thinkbiganalytics.metadata.jpa.jobrepo.job.JpaBatchJobExecution)3 BooleanBuilder (com.querydsl.core.BooleanBuilder)2 Projections (com.querydsl.core.types.Projections)2 JPAQuery (com.querydsl.jpa.impl.JPAQuery)2 JPAQueryFactory (com.querydsl.jpa.impl.JPAQueryFactory)2 DateTimeUtil (com.thinkbiganalytics.DateTimeUtil)2 Alert (com.thinkbiganalytics.alerts.api.Alert)2 AlertProvider (com.thinkbiganalytics.alerts.api.AlertProvider)2 AlertManager (com.thinkbiganalytics.alerts.spi.AlertManager)2 ClusterService (com.thinkbiganalytics.cluster.ClusterService)2 SavepointReplayJobExecution (com.thinkbiganalytics.jobrepo.model.SavepointReplayJobExecution)2 Feed (com.thinkbiganalytics.metadata.api.feed.Feed)2 OpsManagerFeedProvider (com.thinkbiganalytics.metadata.api.feed.OpsManagerFeedProvider)2