Search in sources :

Example 16 with BatchJobExecution

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

the class JpaBatchJobExecutionProvider method markStreamingFeedAsStarted.

public void markStreamingFeedAsStarted(String feed) {
    BatchJobExecution jobExecution = findLatestJobForFeed(feed);
    // ensure its Running
    if (jobExecution != null && !jobExecution.getStatus().equals(BatchJobExecution.JobStatus.STARTED)) {
        log.info("Starting Streaming feed job {} for Feed {} ", jobExecution.getJobExecutionId(), feed);
        jobExecution.setStatus(BatchJobExecution.JobStatus.STARTED);
        jobExecution.setExitCode(ExecutionConstants.ExitCode.EXECUTING);
        ((JpaBatchJobExecution) jobExecution).setLastUpdated(DateTimeUtil.getNowUTCTime());
        jobExecution.setStartTime(DateTimeUtil.getNowUTCTime());
        save(jobExecution);
        latestStreamingJobByFeedName.put(feed, jobExecution);
    }
}
Also used : BatchJobExecution(com.thinkbiganalytics.metadata.api.jobrepo.job.BatchJobExecution)

Example 17 with BatchJobExecution

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

the class JpaBatchJobExecutionProvider method findAll.

/**
 * Find all BatchJobExecution objects with the provided filter. the filter needs to match
 *
 * @return a paged result set of all the job executions matching the incoming filter
 */
@Override
public Page<? extends BatchJobExecution> findAll(String filter, Pageable pageable) {
    QJpaBatchJobExecution jobExecution = QJpaBatchJobExecution.jpaBatchJobExecution;
    // if the filter contains a filter on the feed then delegate to the findAllForFeed method to include any check data jobs
    List<SearchCriteria> searchCriterias = GenericQueryDslFilter.parseFilterString(filter);
    SearchCriteria feedFilter = searchCriterias.stream().map(searchCriteria -> searchCriteria.withKey(CommonFilterTranslations.resolvedFilter(jobExecution, searchCriteria.getKey()))).filter(sc -> sc.getKey().equalsIgnoreCase(CommonFilterTranslations.jobExecutionFeedNameFilterKey)).findFirst().orElse(null);
    if (feedFilter != null && feedFilter.getPreviousSearchCriteria() != null && !feedFilter.isValueCollection()) {
        // remove the feed filter from the list and filter by this feed
        searchCriterias.remove(feedFilter.getPreviousSearchCriteria());
        String feedValue = feedFilter.getValue().toString();
        // remove any quotes around the feedValue
        feedValue = feedValue.replaceAll("^\"|\"$", "");
        return findAllForFeed(feedValue, searchCriterias, pageable);
    } else {
        pageable = CommonFilterTranslations.resolveSortFilters(jobExecution, pageable);
        QJpaBatchJobInstance jobInstancePath = new QJpaBatchJobInstance("jobInstance");
        QJpaOpsManagerFeed feedPath = new QJpaOpsManagerFeed("feed");
        return findAllWithFetch(jobExecution, GenericQueryDslFilter.buildFilter(jobExecution, filter).and(augment(feedPath.id)), pageable, QueryDslFetchJoin.innerJoin(jobExecution.nifiEventJobExecution), QueryDslFetchJoin.innerJoin(jobExecution.jobInstance, jobInstancePath), QueryDslFetchJoin.innerJoin(jobInstancePath.feed, feedPath));
    }
}
Also used : AlertManager(com.thinkbiganalytics.alerts.spi.AlertManager) JobStatusCount(com.thinkbiganalytics.metadata.api.jobrepo.job.JobStatusCount) BatchRelatedFlowFile(com.thinkbiganalytics.metadata.api.jobrepo.job.BatchRelatedFlowFile) ClusterServiceMessageReceiver(com.thinkbiganalytics.cluster.ClusterServiceMessageReceiver) JpaNifiEventJobExecution(com.thinkbiganalytics.metadata.jpa.jobrepo.nifi.JpaNifiEventJobExecution) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) Projections(com.querydsl.core.types.Projections) FeedAclIndexQueryAugmentor(com.thinkbiganalytics.metadata.jpa.feed.FeedAclIndexQueryAugmentor) StringUtils(org.apache.commons.lang3.StringUtils) GenericQueryDslFilter(com.thinkbiganalytics.metadata.jpa.support.GenericQueryDslFilter) SecurityRole(com.thinkbiganalytics.security.role.SecurityRole) BatchAndStreamingJobStatusCount(com.thinkbiganalytics.metadata.api.jobrepo.job.BatchAndStreamingJobStatusCount) Map(java.util.Map) AccessController(com.thinkbiganalytics.security.AccessController) OpsManagerFeed(com.thinkbiganalytics.metadata.api.feed.OpsManagerFeed) Pageable(org.springframework.data.domain.Pageable) BigInteger(java.math.BigInteger) MetadataAccess(com.thinkbiganalytics.metadata.api.MetadataAccess) SecurityContextHolder(org.springframework.security.core.context.SecurityContextHolder) NifiFeedStatisticsProvider(com.thinkbiganalytics.metadata.api.jobrepo.nifi.NifiFeedStatisticsProvider) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) ClusterMessage(com.thinkbiganalytics.cluster.ClusterMessage) Page(org.springframework.data.domain.Page) Expression(com.querydsl.core.types.Expression) MetadataEventService(com.thinkbiganalytics.metadata.api.event.MetadataEventService) Collectors(java.util.stream.Collectors) JPAExpressions(com.querydsl.jpa.JPAExpressions) JpaOpsManagerFeed(com.thinkbiganalytics.metadata.jpa.feed.JpaOpsManagerFeed) 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) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) PostConstruct(javax.annotation.PostConstruct) ClusterService(com.thinkbiganalytics.cluster.ClusterService) BatchJobExecution(com.thinkbiganalytics.metadata.api.jobrepo.job.BatchJobExecution) CommonFilterTranslations(com.thinkbiganalytics.metadata.jpa.support.CommonFilterTranslations) Predicate(com.querydsl.core.types.Predicate) SearchCriteria(com.thinkbiganalytics.metadata.api.SearchCriteria) Authentication(org.springframework.security.core.Authentication) UnsupportedEncodingException(java.io.UnsupportedEncodingException) FeedOperationBatchStatusChange(com.thinkbiganalytics.metadata.api.event.feed.FeedOperationBatchStatusChange) BatchStepExecutionProvider(com.thinkbiganalytics.metadata.api.jobrepo.step.BatchStepExecutionProvider) Stopwatch(com.google.common.base.Stopwatch) MessageDigest(java.security.MessageDigest) DateTimeUtil(com.thinkbiganalytics.DateTimeUtil) BooleanBuilder(com.querydsl.core.BooleanBuilder) QOpsManagerFeedId(com.thinkbiganalytics.metadata.jpa.feed.QOpsManagerFeedId) BooleanUtils(org.apache.commons.lang3.BooleanUtils) HashMap(java.util.HashMap) JPQLQuery(com.querydsl.jpa.JPQLQuery) DefaultAlertChangeEventContent(com.thinkbiganalytics.alerts.spi.DefaultAlertChangeEventContent) QueryDslFetchJoin(com.thinkbiganalytics.metadata.jpa.support.QueryDslFetchJoin) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Inject(javax.inject.Inject) AlertProvider(com.thinkbiganalytics.alerts.api.AlertProvider) RoleSetExposingSecurityExpressionRoot(com.thinkbiganalytics.metadata.config.RoleSetExposingSecurityExpressionRoot) NifiRelatedRootFlowFilesRepository(com.thinkbiganalytics.metadata.jpa.jobrepo.nifi.NifiRelatedRootFlowFilesRepository) Alert(com.thinkbiganalytics.alerts.api.Alert) CheckDataStepConstants(com.thinkbiganalytics.jobrepo.common.constants.CheckDataStepConstants) Service(org.springframework.stereotype.Service) QueryDslPagingSupport(com.thinkbiganalytics.metadata.jpa.support.QueryDslPagingSupport) Named(javax.inject.Named) ProvenanceEventRecordDTO(com.thinkbiganalytics.nifi.provenance.model.ProvenanceEventRecordDTO) FeedOperation(com.thinkbiganalytics.metadata.api.op.FeedOperation) Logger(org.slf4j.Logger) BatchJobInstance(com.thinkbiganalytics.metadata.api.jobrepo.job.BatchJobInstance) FeedNameUtil(com.thinkbiganalytics.support.FeedNameUtil) OptimisticLockException(javax.persistence.OptimisticLockException) ConstructorExpression(com.querydsl.core.types.ConstructorExpression) DateTime(org.joda.time.DateTime) NifiFeedStats(com.thinkbiganalytics.metadata.api.jobrepo.nifi.NifiFeedStats) JPAQueryFactory(com.querydsl.jpa.impl.JPAQueryFactory) OperationalAlerts(com.thinkbiganalytics.metadata.api.alerts.OperationalAlerts) QJpaNifiFeedStats(com.thinkbiganalytics.metadata.jpa.jobrepo.nifi.QJpaNifiFeedStats) TimeUnit(java.util.concurrent.TimeUnit) JobStatusDslQueryExpressionBuilder(com.thinkbiganalytics.metadata.jpa.support.JobStatusDslQueryExpressionBuilder) QJpaOpsManagerFeed(com.thinkbiganalytics.metadata.jpa.feed.QJpaOpsManagerFeed) FeedConstants(com.thinkbiganalytics.jobrepo.common.constants.FeedConstants) Collections(java.util.Collections) OpsManagerFeedRepository(com.thinkbiganalytics.metadata.jpa.feed.OpsManagerFeedRepository) QJpaOpsManagerFeed(com.thinkbiganalytics.metadata.jpa.feed.QJpaOpsManagerFeed) SearchCriteria(com.thinkbiganalytics.metadata.api.SearchCriteria)

Example 18 with BatchJobExecution

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

the class FeedFailureMetricAssessorTest method testExistingBatchFailure.

/**
 * Tests when no new jobs have been run since the last time, but the last job execution was failed
 */
@Test
public void testExistingBatchFailure() throws ParseException {
    DateTime lastAssessedTime = DateTime.now();
    String feedName = "feed";
    List<NifiFeedProcessorStats> streamingStats = new ArrayList<>();
    boolean isStream = false;
    this.metric.setFeedName(feedName);
    when(feedProvider.findByName(feedName)).thenReturn(newOpsManagerFeed(feedName, isStream));
    DateTime startingEvent = DateTime.now().minusMinutes(5);
    List<? extends BatchJobExecution> batchJobs = new ArrayList<>();
    BatchJobExecution jobExecution = newBatchJob(feedName, startingEvent, true);
    Mockito.when(this.jobExecutionProvider.findLatestFinishedJobForFeedSince(Mockito.anyString(), Mockito.any(DateTime.class))).thenAnswer(x -> batchJobs);
    Mockito.when(this.jobExecutionProvider.findLatestFinishedJobForFeed(Mockito.anyString())).thenAnswer(x -> jobExecution);
    this.assessor.assess(metric, this.builder);
    verify(this.builder).result(AssessmentResult.FAILURE);
}
Also used : BatchJobExecution(com.thinkbiganalytics.metadata.api.jobrepo.job.BatchJobExecution) ArrayList(java.util.ArrayList) NifiFeedProcessorStats(com.thinkbiganalytics.metadata.api.jobrepo.nifi.NifiFeedProcessorStats) DateTime(org.joda.time.DateTime) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 19 with BatchJobExecution

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

the class FeedOnTimeArrivalMetricAssessorTest method createFeedJobExecution.

private BatchJobExecution createFeedJobExecution(DateTime endTime) {
    BatchJobExecution feed = mock(BatchJobExecution.class);
    when(feed.getEndTime()).thenReturn(endTime);
    return feed;
}
Also used : BatchJobExecution(com.thinkbiganalytics.metadata.api.jobrepo.job.BatchJobExecution)

Example 20 with BatchJobExecution

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

the class ProvenanceEventReceiver method notifyJobFinished.

/**
 * Notify that the Job is complete either as a successful job or failed Job
 * if its a streaming event notifications will go out every xx seconds default 5
 * if its a batch it will always notify
 *
 * @param event a provenance event
 */
private void notifyJobFinished(BatchJobExecution jobExecution, ProvenanceEventRecordDTO event) {
    if (isNotifyJobFinished(event)) {
        // register the event as being triggered
        String mapKey = triggeredEventsKey(event);
        completedJobEvents.put(mapKey, mapKey);
        lastFeedFinishedNotificationCache.put(event.getFeedName(), DateTime.now());
        metadataAccess.commit(() -> {
            BatchJobExecution batchJobExecution = jobExecution;
            if ((!event.isStream() && batchJobExecution.isFailed()) || (event.isStream() && event.isFailure())) {
                // requery for failure events as we need to access the map of data for alert generation
                batchJobExecution = batchJobExecutionProvider.findByJobExecutionId(jobExecution.getJobExecutionId(), false);
                failedJob(batchJobExecution, event);
            } else {
                successfulJob(batchJobExecution, event);
            }
        }, MetadataAccess.SERVICE);
    } else {
        log.debug("skipping job finished notification for feed: {}, isStream:{}, isFailure:{} ", event.getFeedName(), event.isStream(), event.isFailure());
    }
}
Also used : BatchJobExecution(com.thinkbiganalytics.metadata.api.jobrepo.job.BatchJobExecution)

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