Search in sources :

Example 26 with BooleanBuilder

use of com.querydsl.core.BooleanBuilder 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;
}
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) BatchAndStreamingJobStatusCount(com.thinkbiganalytics.metadata.api.jobrepo.job.BatchAndStreamingJobStatusCount) BooleanBuilder(com.querydsl.core.BooleanBuilder) List(java.util.List) ArrayList(java.util.ArrayList) QJpaNifiFeedStats(com.thinkbiganalytics.metadata.jpa.jobrepo.nifi.QJpaNifiFeedStats)

Example 27 with BooleanBuilder

use of com.querydsl.core.BooleanBuilder in project kylo by Teradata.

the class GenericQueryDslFilter method buildFilter.

/**
 * build the Filter for the base QueryDSL class and the passed in filter list
 *
 * @param filters name:test, age>10
 */
public static <T> BooleanBuilder buildFilter(EntityPathBase basePath, List<SearchCriteria> filters) {
    BooleanBuilder booleanBuilder = new BooleanBuilder();
    if (filters != null && !filters.isEmpty()) {
        filters.stream().forEach(filter -> {
            Path p = buildPathFromFilterColumn(basePath, filter.getKey());
            if (p != null) {
                Object value = filter.getValue();
                Operator op = operators.get(filter.getOperation());
                if (validateOperatorPath(op, p, filter.getKey(), value)) {
                    if (Ops.LIKE_IC.equals(op) && value instanceof String && value != null && !((String) value).endsWith("%")) {
                        value = ((String) value) + "%";
                    }
                    if (value == null || (value instanceof String && ((String) value).equalsIgnoreCase(NULL_FILTER))) {
                        op = Ops.IS_NULL;
                        value = null;
                    } else if (value instanceof String && ((String) value).equalsIgnoreCase(NOT_NULL_FILTER)) {
                        op = Ops.IS_NOT_NULL;
                        value = null;
                    }
                    if (value != null) {
                        Object convertedValue = getValueForQuery(p, filter.getKey(), op, value);
                        if (convertedValue != null && convertedValue instanceof Collection) {
                            op = Ops.IN;
                        }
                        if (convertedValue != null) {
                            Expression e = null;
                            if (convertedValue instanceof Comparable) {
                                e = Expressions.asComparable((Comparable) convertedValue);
                            } else {
                                e = Expressions.constant(convertedValue);
                            }
                            // reset the operator if looking for UUID
                            if (convertedValue instanceof UUID || convertedValue instanceof Enum) {
                                op = Ops.EQ;
                            }
                            if (filter.isOrFilter()) {
                                booleanBuilder.or(Expressions.predicate(op, p, e));
                            } else {
                                booleanBuilder.and(Expressions.predicate(op, p, e));
                            }
                        }
                    } else {
                        if (filter.isOrFilter()) {
                            booleanBuilder.or(Expressions.predicate(op, p));
                        } else {
                            booleanBuilder.and(Expressions.predicate(op, p));
                        }
                    }
                }
            }
        });
    }
    return booleanBuilder;
}
Also used : Path(com.querydsl.core.types.Path) StringPath(com.querydsl.core.types.dsl.StringPath) ComparablePath(com.querydsl.core.types.dsl.ComparablePath) EnumPath(com.querydsl.core.types.dsl.EnumPath) NumberPath(com.querydsl.core.types.dsl.NumberPath) Operator(com.querydsl.core.types.Operator) EnumExpression(com.querydsl.core.types.dsl.EnumExpression) Expression(com.querydsl.core.types.Expression) BooleanBuilder(com.querydsl.core.BooleanBuilder) ImmutableCollection(com.google.common.collect.ImmutableCollection) Collection(java.util.Collection) UUID(java.util.UUID)

Example 28 with BooleanBuilder

use of com.querydsl.core.BooleanBuilder in project kylo by Teradata.

the class OpsFeedManagerFeedProvider method findFeedsWithFilter.

public List<OpsManagerFeed> findFeedsWithFilter(String filter) {
    QJpaOpsManagerFeed feed = QJpaOpsManagerFeed.jpaOpsManagerFeed;
    BooleanBuilder where = GenericQueryDslFilter.buildFilter(feed, filter);
    JPAQuery query = factory.select(feed).from(feed).where(where);
    return query.fetch();
}
Also used : BooleanBuilder(com.querydsl.core.BooleanBuilder) JPAQuery(com.querydsl.jpa.impl.JPAQuery)

Example 29 with BooleanBuilder

use of com.querydsl.core.BooleanBuilder in project kylo by Teradata.

the class JpaBatchJobExecutionTest method testFilters.

@WithMockJaasUser(username = "dladmin", password = "secret", authorities = { "admin" })
@Test
public void testFilters() {
    operationalMetadataAccess.read(() -> {
        QJpaBatchJobExecution jobExecution = QJpaBatchJobExecution.jpaBatchJobExecution;
        BooleanBuilder builder = GenericQueryDslFilter.buildFilter(jobExecution, "status==\"COMPLETED,FAILED\"");
        int i = 0;
        return null;
    });
}
Also used : BooleanBuilder(com.querydsl.core.BooleanBuilder) QJpaBatchJobExecution(com.thinkbiganalytics.metadata.jpa.jobrepo.job.QJpaBatchJobExecution) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) WithMockJaasUser(com.thinkbiganalytics.test.security.WithMockJaasUser)

Example 30 with BooleanBuilder

use of com.querydsl.core.BooleanBuilder in project kylo by Teradata.

the class KyloEntityAwareAlertCriteria method createSummaryQuery.

public JPAQuery<AlertSummary> createSummaryQuery() {
    QJpaAlert alert = QJpaAlert.jpaAlert;
    QJpaOpsManagerFeed feed = QJpaOpsManagerFeed.jpaOpsManagerFeed;
    QJpaOpsManagerFeed slaFeed = new QJpaOpsManagerFeed("slaFeed");
    QJpaServiceLevelAgreementDescription sla = QJpaServiceLevelAgreementDescription.jpaServiceLevelAgreementDescription;
    JPAQuery query = queryFactory.select(Projections.bean(KyloEntityAwareAlertSummary.class, alert.typeString.as("type"), alert.subtype.as("subtype"), alert.level.as("level"), feed.id.as("feedId"), feed.name.as("feedName"), sla.slaId.as("slaId"), sla.name.as("slaName"), alert.count().as("count"), alert.createdTimeMillis.max().as("lastAlertTimestamp"))).from(alert).leftJoin(feed).on(feed.id.uuid.eq(alert.entityId.value).and(alert.entityType.eq(Expressions.stringPath("'FEED'")))).leftJoin(sla).on(sla.slaId.uuid.eq(alert.entityId.value).and(alert.entityType.eq(Expressions.stringPath("'SLA'")))).leftJoin(sla.feeds, slaFeed).groupBy(alert.typeString, alert.subtype, feed.id, feed.name, sla.slaId, sla.name, alert.level);
    List<Predicate> preds = filter(alert);
    boolean entityAccessControlled = !isAsServiceAccount() && controller.isEntityAccessControlled();
    preds.add(feed.isNull().or(feed.isNotNull().and(FeedAclIndexQueryAugmentor.generateExistsExpression(feed.id, entityAccessControlled))));
    preds.add(slaFeed.isNull().or(slaFeed.isNotNull().and(FeedAclIndexQueryAugmentor.generateExistsExpression(slaFeed.id, entityAccessControlled))));
    BooleanBuilder orFilter = orFilter(alert, feed, sla);
    addEntityFilter(alert, preds);
    return (JPAQuery<AlertSummary>) super.addWhere(query, preds, orFilter);
}
Also used : QJpaOpsManagerFeed(com.thinkbiganalytics.metadata.jpa.feed.QJpaOpsManagerFeed) QJpaAlert(com.thinkbiganalytics.metadata.jpa.alerts.QJpaAlert) BooleanBuilder(com.querydsl.core.BooleanBuilder) QJpaServiceLevelAgreementDescription(com.thinkbiganalytics.metadata.jpa.sla.QJpaServiceLevelAgreementDescription) JPAQuery(com.querydsl.jpa.impl.JPAQuery) Predicate(com.querydsl.core.types.Predicate)

Aggregations

BooleanBuilder (com.querydsl.core.BooleanBuilder)41 Predicate (com.querydsl.core.types.Predicate)12 ArrayList (java.util.ArrayList)10 JPAQuery (com.querydsl.jpa.impl.JPAQuery)8 QJpaAlert (com.thinkbiganalytics.metadata.jpa.alerts.QJpaAlert)8 Sort (org.springframework.data.domain.Sort)8 List (java.util.List)7 QJpaOpsManagerFeed (com.thinkbiganalytics.metadata.jpa.feed.QJpaOpsManagerFeed)6 Map (java.util.Map)6 Pageable (org.springframework.data.domain.Pageable)6 Alert (com.thinkbiganalytics.alerts.api.Alert)5 Test (org.junit.Test)5 JpaAlert (com.thinkbiganalytics.metadata.jpa.alerts.JpaAlert)4 HashMap (java.util.HashMap)4 Collectors (java.util.stream.Collectors)4 EntityNotFoundException (javax.persistence.EntityNotFoundException)4 Autowired (org.springframework.beans.factory.annotation.Autowired)4 Service (org.springframework.stereotype.Service)4 Expression (com.querydsl.core.types.Expression)3 Projections (com.querydsl.core.types.Projections)3