Search in sources :

Example 16 with OpsManagerFeed

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

the class FeedsRestController method getFeedHealthForFeed.

@GET
@Path("/health/{feedName}")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation("Gets the detailed health status of the specified feed.")
@ApiResponses({ @ApiResponse(code = 200, message = "Returns the health.", response = FeedStatus.class), @ApiResponse(code = 404, message = "The feed does not exist.", response = RestResponseStatus.class) })
public FeedStatus getFeedHealthForFeed(@Context HttpServletRequest request, @PathParam("feedName") String feedName) {
    this.accessController.checkPermission(AccessController.SERVICES, OperationsAccessControl.ACCESS_OPS);
    return metadataAccess.read(() -> {
        final FeedHealth feedHealth = getFeedHealthCounts(request, feedName);
        if (feedHealth != null) {
            return FeedModelTransform.feedStatus(Lists.newArrayList(feedHealth));
        }
        final OpsManagerFeed feed = opsFeedManagerFeedProvider.findByName(feedName);
        if (feed != null) {
            return FeedModelTransform.feedStatus(feed);
        } else {
            throw new NotFoundException();
        }
    });
}
Also used : OpsManagerFeed(com.thinkbiganalytics.metadata.api.feed.OpsManagerFeed) NotFoundException(javax.ws.rs.NotFoundException) FeedHealth(com.thinkbiganalytics.jobrepo.query.model.FeedHealth) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 17 with OpsManagerFeed

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

the class JobModelTransform method executedJob.

public static ExecutedJob executedJob(BatchJobExecution jobExecution) {
    DefaultExecutedJob job = (DefaultExecutedJob) executedJobSimple(jobExecution);
    Map<String, String> jobExecutionContext = jobExecution.getJobExecutionContextAsMap();
    if (jobExecutionContext != null) {
        job.setExecutionContext(new HashMap<>(jobExecutionContext));
    }
    OpsManagerFeed feed = jobExecution.getJobInstance().getFeed();
    if (feed != null) {
        job.setJobType(feed.getFeedType().name());
    }
    Map<String, String> jobParams = jobExecution.getJobParametersAsMap();
    if (jobParams != null) {
        job.setJobParameters(new HashMap<>(jobParams));
    }
    job.setExecutedSteps(executedSteps(jobExecution.getStepExecutions()));
    return job;
}
Also used : OpsManagerFeed(com.thinkbiganalytics.metadata.api.feed.OpsManagerFeed) DefaultExecutedJob(com.thinkbiganalytics.jobrepo.query.model.DefaultExecutedJob)

Example 18 with OpsManagerFeed

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

the class OpsFeedManagerFeedProvider method save.

@Override
public OpsManagerFeed save(OpsManagerFeed.ID feedId, String systemName, boolean isStream, Long timeBetweenBatchJobs) {
    OpsManagerFeed feed = repository.findByIdWithoutAcl(feedId);
    if (feed == null) {
        if (ensureUniqueFeedName) {
            ensureAndRemoveDuplicateFeedsWithTheSameName(systemName, feedId);
        }
        feed = new JpaOpsManagerFeed();
        ((JpaOpsManagerFeed) feed).setName(systemName);
        ((JpaOpsManagerFeed) feed).setId((OpsManagerFeedId) feedId);
        ((JpaOpsManagerFeed) feed).setStream(isStream);
        ((JpaOpsManagerFeed) feed).setTimeBetweenBatchJobs(timeBetweenBatchJobs);
        NifiFeedStats stats = feedStatisticsProvider.findLatestStatsForFeedWithoutAccessControl(systemName);
        if (stats == null) {
            JpaNifiFeedStats newStats = new JpaNifiFeedStats(systemName, new JpaNifiFeedStats.OpsManagerFeedId(feedId.toString()));
            newStats.setRunningFeedFlows(0L);
            feedStatisticsProvider.saveLatestFeedStats(Lists.newArrayList(newStats));
        }
    } else {
        ((JpaOpsManagerFeed) feed).setStream(isStream);
        ((JpaOpsManagerFeed) feed).setTimeBetweenBatchJobs(timeBetweenBatchJobs);
    }
    feed = save(feed);
    return feed;
}
Also used : JpaNifiFeedStats(com.thinkbiganalytics.metadata.jpa.jobrepo.nifi.JpaNifiFeedStats) OpsManagerFeed(com.thinkbiganalytics.metadata.api.feed.OpsManagerFeed) JpaNifiFeedStats(com.thinkbiganalytics.metadata.jpa.jobrepo.nifi.JpaNifiFeedStats) NifiFeedStats(com.thinkbiganalytics.metadata.api.jobrepo.nifi.NifiFeedStats)

Example 19 with OpsManagerFeed

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

the class JpaBatchJobExecutionProvider method abandonJob.

@Override
public BatchJobExecution abandonJob(Long executionId) {
    BatchJobExecution execution = findByJobExecutionId(executionId, false);
    if (execution != null && !execution.getStatus().equals(BatchJobExecution.JobStatus.ABANDONED)) {
        if (execution.getStartTime() == null) {
            execution.setStartTime(DateTimeUtil.getNowUTCTime());
        }
        execution.setStatus(BatchJobExecution.JobStatus.ABANDONED);
        if (execution.getEndTime() == null) {
            execution.setEndTime(DateTimeUtil.getNowUTCTime());
        }
        String abandonMessage = "Job manually abandoned @ " + DateTimeUtil.getNowFormattedWithTimeZone();
        String msg = execution.getExitMessage() != null ? execution.getExitMessage() + "\n" : "";
        msg += abandonMessage;
        execution.setExitMessage(msg);
        // also stop any running steps??
        // find the feed associated with the job
        OpsManagerFeed feed = execution.getJobInstance().getFeed();
        save(execution);
        jobExecutionChangedNotifier.notifyAbandoned(execution, feed, null);
        // clear the associated alert
        String alertId = execution.getJobExecutionContextAsMap().get(BatchJobExecutionProvider.KYLO_ALERT_ID_PROPERTY);
        if (StringUtils.isNotBlank(alertId)) {
            provider.respondTo(provider.resolve(alertId), (alert1, response) -> response.handle(abandonMessage));
        }
    }
    return execution;
}
Also used : BatchJobExecution(com.thinkbiganalytics.metadata.api.jobrepo.job.BatchJobExecution) OpsManagerFeed(com.thinkbiganalytics.metadata.api.feed.OpsManagerFeed) JpaOpsManagerFeed(com.thinkbiganalytics.metadata.jpa.feed.JpaOpsManagerFeed) QJpaOpsManagerFeed(com.thinkbiganalytics.metadata.jpa.feed.QJpaOpsManagerFeed)

Example 20 with OpsManagerFeed

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

the class FeedHealthSummaryCache method fetchFeedSummary.

private List<? extends FeedSummary> fetchFeedSummary() {
    return metadataAccess.read(() -> {
        Stopwatch stopwatch = Stopwatch.createStarted();
        List<? extends FeedSummary> list = opsManagerFeedProvider.findFeedSummary();
        Map<String, FeedSummary> latestFeeds = new HashMap<>();
        // NOTE it could also populate the last job execution time since the above query gets a union of the running jobs along with the latest finished jobs by feed
        list.stream().sorted(byRunningStatus.thenComparing(byStartTime)).forEach(f -> {
            String feedId = f.getFeedId().toString();
            if (!latestFeeds.containsKey(feedId)) {
                latestFeeds.put(feedId, f);
            }
        });
        // add in initial feeds
        List<? extends OpsManagerFeed> allFeeds = opsManagerFeedProvider.findAllWithoutAcl();
        allFeeds.stream().filter(f -> !latestFeeds.containsKey(f.getId().toString())).forEach(f -> {
            JpaFeedSummary s = new JpaFeedSummary();
            s.setStream(f.isStream());
            s.setFeedId(UUID.fromString(f.getId().toString()));
            s.setFeedName(f.getName());
            s.setFeedType(f.getFeedType());
            s.setRunningCount(0L);
            s.setAbandonedCount(0L);
            s.setFailedCount(0L);
            s.setAllCount(0L);
            s.setCompletedCount(0L);
            s.setRunStatus(FeedSummary.RunStatus.INITIAL);
            s.setStatus(BatchJobExecution.JobStatus.UNKNOWN);
            latestFeeds.put(s.getFeedId().toString(), s);
        });
        stopwatch.stop();
        log.debug("Time to fetchAndDedupe FeedSummary: {} ", stopwatch.elapsed(TimeUnit.MILLISECONDS));
        return new ArrayList<>(latestFeeds.values());
    }, MetadataAccess.SERVICE);
}
Also used : LoadingCache(com.google.common.cache.LoadingCache) SearchResultImpl(com.thinkbiganalytics.rest.model.search.SearchResultImpl) Stopwatch(com.google.common.base.Stopwatch) LoggerFactory(org.slf4j.LoggerFactory) DateTimeUtil(com.thinkbiganalytics.DateTimeUtil) HashMap(java.util.HashMap) FeedAclCache(com.thinkbiganalytics.metadata.jpa.feed.security.FeedAclCache) StringUtils(org.apache.commons.lang3.StringUtils) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) RoleSetExposingSecurityExpressionRoot(com.thinkbiganalytics.metadata.config.RoleSetExposingSecurityExpressionRoot) Map(java.util.Map) FeedHealth(com.thinkbiganalytics.jobrepo.query.model.FeedHealth) OpsManagerFeed(com.thinkbiganalytics.metadata.api.feed.OpsManagerFeed) AtomicLongMap(com.google.common.util.concurrent.AtomicLongMap) MetadataAccess(com.thinkbiganalytics.metadata.api.MetadataAccess) OpsManagerFeedProvider(com.thinkbiganalytics.metadata.api.feed.OpsManagerFeedProvider) Logger(org.slf4j.Logger) NullSafeComparator(org.springframework.util.comparator.NullSafeComparator) FeedStatus(com.thinkbiganalytics.jobrepo.query.model.FeedStatus) Predicate(java.util.function.Predicate) TimeUtil(com.thinkbiganalytics.metadata.cache.util.TimeUtil) UUID(java.util.UUID) MetadataEventService(com.thinkbiganalytics.metadata.api.event.MetadataEventService) SearchResult(com.thinkbiganalytics.rest.model.search.SearchResult) Collectors(java.util.stream.Collectors) JpaFeedSummary(com.thinkbiganalytics.metadata.jpa.feed.JpaFeedSummary) CacheLoader(com.google.common.cache.CacheLoader) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) FeedModelTransform(com.thinkbiganalytics.jobrepo.query.model.transform.FeedModelTransform) CacheBuilder(com.google.common.cache.CacheBuilder) BatchJobExecution(com.thinkbiganalytics.metadata.api.jobrepo.job.BatchJobExecution) Comparator(java.util.Comparator) FeedSummary(com.thinkbiganalytics.metadata.api.feed.FeedSummary) HashMap(java.util.HashMap) Stopwatch(com.google.common.base.Stopwatch) JpaFeedSummary(com.thinkbiganalytics.metadata.jpa.feed.JpaFeedSummary) ArrayList(java.util.ArrayList) JpaFeedSummary(com.thinkbiganalytics.metadata.jpa.feed.JpaFeedSummary) FeedSummary(com.thinkbiganalytics.metadata.api.feed.FeedSummary)

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