use of com.querydsl.jpa.impl.JPAQuery in project kylo by Teradata.
the class JpaBatchJobExecutionProvider method getJobStatusCount.
/**
* Get count of Jobs grouped by Status
* Streaming Feeds are given a count of 1 if they are running, regardless of the number of active running flows
*/
@Override
public List<JobStatusCount> getJobStatusCount(String filter) {
QJpaBatchJobExecution jobExecution = QJpaBatchJobExecution.jpaBatchJobExecution;
QJpaBatchJobInstance jobInstance = QJpaBatchJobInstance.jpaBatchJobInstance;
QJpaOpsManagerFeed feed = QJpaOpsManagerFeed.jpaOpsManagerFeed;
BooleanBuilder whereBuilder = new BooleanBuilder();
if (StringUtils.isNotBlank(filter)) {
whereBuilder.and(GenericQueryDslFilter.buildFilter(jobExecution, filter));
}
ConstructorExpression<JpaBatchJobExecutionStatusCounts> expr = Projections.constructor(JpaBatchJobExecutionStatusCounts.class, JobStatusDslQueryExpressionBuilder.jobState().as("status"), jobExecution.jobExecutionId.count().as("count"));
JPAQuery<?> query = factory.select(expr).from(jobExecution).innerJoin(jobInstance).on(jobExecution.jobInstance.jobInstanceId.eq(jobInstance.jobInstanceId)).innerJoin(feed).on(jobInstance.feed.id.eq(feed.id)).where(whereBuilder.and(feed.isStream.eq(false)).and(FeedAclIndexQueryAugmentor.generateExistsExpression(feed.id, controller.isEntityAccessControlled()))).groupBy(jobExecution.status);
List<JobStatusCount> stats = (List<JobStatusCount>) query.fetch();
// merge in streaming feed stats
List<? extends NifiFeedStats> streamingFeedStats = feedStatisticsProvider.findFeedStats(true);
if (streamingFeedStats != null) {
if (stats == null) {
stats = new ArrayList<>();
}
Long runningCount = streamingFeedStats.stream().filter(s -> s.getRunningFeedFlows() > 0L).count();
if (runningCount > 0) {
JobStatusCount runningStatusCount = stats.stream().filter(s -> s.getStatus().equalsIgnoreCase(BatchJobExecution.RUNNING_DISPLAY_STATUS)).findFirst().orElse(null);
if (runningStatusCount != null) {
runningCount = runningStatusCount.getCount() + runningCount;
runningStatusCount.setCount(runningCount);
} else {
JpaBatchJobExecutionStatusCounts runningStreamingFeedCounts = new JpaBatchJobExecutionStatusCounts();
runningStreamingFeedCounts.setCount(runningCount);
runningStreamingFeedCounts.setStatus(BatchJobExecution.RUNNING_DISPLAY_STATUS);
stats.add(runningStreamingFeedCounts);
}
}
}
return stats;
}
use of com.querydsl.jpa.impl.JPAQuery in project kylo by Teradata.
the class JpaBatchJobExecutionProvider method getJobStatusCountByDate.
@Override
public List<JobStatusCount> getJobStatusCountByDate() {
QJpaBatchJobExecution jobExecution = QJpaBatchJobExecution.jpaBatchJobExecution;
QJpaBatchJobInstance jobInstance = QJpaBatchJobInstance.jpaBatchJobInstance;
QJpaOpsManagerFeed feed = QJpaOpsManagerFeed.jpaOpsManagerFeed;
JPAQuery query = factory.select(Projections.constructor(JpaBatchJobExecutionStatusCounts.class, JobStatusDslQueryExpressionBuilder.jobState().as("status"), jobExecution.startYear, jobExecution.startMonth, jobExecution.startDay, jobExecution.count().as("count"))).from(jobExecution).innerJoin(jobInstance).on(jobExecution.jobInstance.jobInstanceId.eq(jobInstance.jobInstanceId)).innerJoin(feed).on(jobInstance.feed.id.eq(feed.id)).where(FeedAclIndexQueryAugmentor.generateExistsExpression(feed.id, controller.isEntityAccessControlled())).groupBy(jobExecution.status, jobExecution.startYear, jobExecution.startMonth, jobExecution.startDay);
return (List<JobStatusCount>) query.fetch();
}
use of com.querydsl.jpa.impl.JPAQuery in project kylo by Teradata.
the class JpaBatchJobExecutionProvider method findAllForFeed.
private Page<? extends BatchJobExecution> findAllForFeed(String feedName, List<SearchCriteria> filters, Pageable pageable) {
QJpaBatchJobExecution jobExecution = QJpaBatchJobExecution.jpaBatchJobExecution;
QJpaOpsManagerFeed feed = QJpaOpsManagerFeed.jpaOpsManagerFeed;
QJpaOpsManagerFeed checkDataFeed = new QJpaOpsManagerFeed("checkDataFeed");
QJpaBatchJobInstance jobInstance = QJpaBatchJobInstance.jpaBatchJobInstance;
JPQLQuery checkFeedQuery = JPAExpressions.select(checkDataFeed.id).from(feed).join(feed.checkDataFeeds, checkDataFeed).where(feed.name.eq(feedName));
JPAQuery query = factory.select(jobExecution).from(jobExecution).join(jobExecution.jobInstance, jobInstance).join(jobInstance.feed, feed).where((feed.name.eq(feedName).or(feed.id.in(checkFeedQuery))).and(GenericQueryDslFilter.buildFilter(jobExecution, filters).and(augment(feed.id)))).fetchAll();
pageable = CommonFilterTranslations.resolveSortFilters(jobExecution, pageable);
return findAll(query, pageable);
}
use of com.querydsl.jpa.impl.JPAQuery in project kylo by Teradata.
the class JpaBatchJobExecutionProvider method getBatchAndStreamingJobCounts.
/**
* Get count of Jobs grouped by Status
* Streaming Feeds are given a count of 1 if they are running, regardless of the number of active running flows
*/
public List<BatchAndStreamingJobStatusCount> getBatchAndStreamingJobCounts(String filter) {
QJpaBatchJobExecution jobExecution = QJpaBatchJobExecution.jpaBatchJobExecution;
QJpaBatchJobInstance jobInstance = QJpaBatchJobInstance.jpaBatchJobInstance;
QJpaOpsManagerFeed feed = QJpaOpsManagerFeed.jpaOpsManagerFeed;
QJpaNifiFeedStats feedStats = QJpaNifiFeedStats.jpaNifiFeedStats;
BooleanBuilder whereBuilder = new BooleanBuilder();
if (StringUtils.isNotBlank(filter)) {
whereBuilder.and(GenericQueryDslFilter.buildFilter(jobExecution, filter));
}
Expression<JpaBatchAndStreamingJobStatusCounts> expr = Projections.bean(JpaBatchAndStreamingJobStatusCounts.class, JobStatusDslQueryExpressionBuilder.jobState().as("status"), feed.id.as("opsManagerFeedId"), feed.name.as("feedName"), feed.isStream.as("isStream"), feedStats.runningFeedFlows.as("runningFeedFlows"), jobExecution.jobExecutionId.count().as("count"), feedStats.lastActivityTimestamp.max().as("lastActivityTimestamp"));
JPAQuery<?> query = factory.select(expr).from(feed).innerJoin(jobInstance).on(jobInstance.feed.id.eq(feed.id)).innerJoin(jobExecution).on(jobExecution.jobInstance.jobInstanceId.eq(jobInstance.jobInstanceId)).leftJoin(feedStats).on(feed.id.uuid.eq(feedStats.feedId.uuid)).where(whereBuilder).groupBy(jobExecution.status, feed.id, feed.name, feed.isStream, feedStats.runningFeedFlows);
List<BatchAndStreamingJobStatusCount> stats = (List<BatchAndStreamingJobStatusCount>) query.fetch();
return stats.stream().map(s -> {
if (s.isStream() && (BatchJobExecution.RUNNING_DISPLAY_STATUS.equalsIgnoreCase(s.getStatus()) || BatchJobExecution.JobStatus.STARTING.name().equalsIgnoreCase(s.getStatus()) || BatchJobExecution.JobStatus.STARTED.name().equalsIgnoreCase(s.getStatus())) && s.getRunningFeedFlows() == 0L) {
((JpaBatchAndStreamingJobStatusCounts) s).setStatus(BatchJobExecution.JobStatus.STOPPED.name());
}
return s;
}).collect(Collectors.toList());
// return stats;
}
use of com.querydsl.jpa.impl.JPAQuery in project kylo by Teradata.
the class OpsFeedManagerFeedProvider method getJobStatusCountByDateFromNow.
public List<JobStatusCount> getJobStatusCountByDateFromNow(String feedName, ReadablePeriod period) {
QJpaBatchJobExecution jobExecution = QJpaBatchJobExecution.jpaBatchJobExecution;
QJpaBatchJobInstance jobInstance = QJpaBatchJobInstance.jpaBatchJobInstance;
QJpaOpsManagerFeed feed = QJpaOpsManagerFeed.jpaOpsManagerFeed;
JPAQuery query = factory.select(Projections.constructor(JpaBatchJobExecutionStatusCounts.class, JobStatusDslQueryExpressionBuilder.jobState().as("status"), Expressions.constant(feedName), jobExecution.startYear, jobExecution.startMonth, jobExecution.startDay, jobExecution.count().as("count"))).from(jobExecution).innerJoin(jobInstance).on(jobExecution.jobInstance.jobInstanceId.eq(jobInstance.jobInstanceId)).innerJoin(feed).on(jobInstance.feed.id.eq(feed.id)).where(jobExecution.startTime.goe(DateTime.now().minus(period)).and(feed.name.eq(feedName)).and(FeedAclIndexQueryAugmentor.generateExistsExpression(feed.id, accessController.isEntityAccessControlled()))).groupBy(jobExecution.status, jobExecution.startYear, jobExecution.startMonth, jobExecution.startDay);
return (List<JobStatusCount>) query.fetch();
}
Aggregations