Search in sources :

Example 1 with HiveRuleDetail

use of com.webank.wedatasphere.qualitis.project.response.HiveRuleDetail in project Qualitis by WeBankFinTech.

the class RuleMetricServiceImpl method getRulesByRuleMetric.

@Override
public DataInfo<HiveRuleDetail> getRulesByRuleMetric(long id, int page, int size) throws UnExpectedRequestException {
    DataInfo<HiveRuleDetail> dataInfo = new DataInfo<>();
    if (id <= 0) {
        throw new UnExpectedRequestException("{&REQUEST_CAN_NOT_BE_NULL}");
    }
    // Check rule metric existence.
    RuleMetric ruleMetricInDb = ruleMetricDao.findById(id);
    if (ruleMetricInDb == null) {
        throw new UnExpectedRequestException("Rule Metric ID [" + id + "] {&DOES_NOT_EXIST}");
    }
    List<Long> ruleIds = taskResultDao.findRuleByRuleMetric(ruleMetricInDb.getId(), page, size).stream().distinct().collect(Collectors.toList());
    int total = taskResultDao.countRuleByRuleMetric(ruleMetricInDb.getId());
    List<HiveRuleDetail> result = new ArrayList<>(ruleIds.size());
    for (Long ruleId : ruleIds) {
        Rule ruleInDb = ruleDao.findById(ruleId);
        if (ruleInDb == null) {
            total--;
            continue;
        }
        List<Long> ruleMetricIds = ruleInDb.getAlarmConfigs().stream().map(AlarmConfig::getRuleMetric).filter(ruleMetric -> ruleMetric != null).map(RuleMetric::getId).collect(Collectors.toList());
        if (ruleInDb != null && ruleMetricIds.contains(id)) {
            HiveRuleDetail hiveRuleDetail = new HiveRuleDetail(ruleInDb);
            result.add(hiveRuleDetail);
        }
    }
    dataInfo.setContent(result);
    dataInfo.setTotalCount(total);
    return dataInfo;
}
Also used : DataInfo(com.webank.wedatasphere.qualitis.metadata.response.DataInfo) ExcelRuleMetric(com.webank.wedatasphere.qualitis.project.excel.ExcelRuleMetric) RuleMetric(com.webank.wedatasphere.qualitis.entity.RuleMetric) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) HiveRuleDetail(com.webank.wedatasphere.qualitis.project.response.HiveRuleDetail) ArrayList(java.util.ArrayList) Rule(com.webank.wedatasphere.qualitis.rule.entity.Rule)

Example 2 with HiveRuleDetail

use of com.webank.wedatasphere.qualitis.project.response.HiveRuleDetail in project Qualitis by WeBankFinTech.

the class RuleQueryServiceImpl method getRulesByColumn.

@Override
public DataInfo<HiveRuleDetail> getRulesByColumn(String cluster, String db, String table, String column, String userName, int page, int size) {
    LOGGER.info("Start to get rules with column. cluster: {}, db: {}, table: {}, column: {}", cluster, db, table, column);
    DataInfo<HiveRuleDetail> dataInfo = new DataInfo<>();
    List<Rule> rules = ruleDataSourceDao.findRuleByDataSource(cluster, db, table, column, userName, page, size);
    int total = ruleDataSourceDao.countRuleByDataSource(cluster, db, table, column, userName);
    if (rules == null || rules.isEmpty()) {
        return null;
    }
    List<HiveRuleDetail> result = new ArrayList<>(rules.size());
    LOGGER.info("Success to get rules with column. Rules: {}", rules);
    for (Rule rule : rules) {
        HiveRuleDetail hiveRuleDetail = new HiveRuleDetail(rule);
        hiveRuleDetail.setTemplateName(rule.getRuleTemplateName());
        result.add(hiveRuleDetail);
    }
    dataInfo.setContent(result);
    dataInfo.setTotalCount(total);
    return dataInfo;
}
Also used : DataInfo(com.webank.wedatasphere.qualitis.metadata.response.DataInfo) HiveRuleDetail(com.webank.wedatasphere.qualitis.project.response.HiveRuleDetail) ArrayList(java.util.ArrayList) Rule(com.webank.wedatasphere.qualitis.rule.entity.Rule) RuleQueryRule(com.webank.wedatasphere.qualitis.query.response.RuleQueryRule)

Aggregations

DataInfo (com.webank.wedatasphere.qualitis.metadata.response.DataInfo)2 HiveRuleDetail (com.webank.wedatasphere.qualitis.project.response.HiveRuleDetail)2 Rule (com.webank.wedatasphere.qualitis.rule.entity.Rule)2 ArrayList (java.util.ArrayList)2 RuleMetric (com.webank.wedatasphere.qualitis.entity.RuleMetric)1 UnExpectedRequestException (com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException)1 ExcelRuleMetric (com.webank.wedatasphere.qualitis.project.excel.ExcelRuleMetric)1 RuleQueryRule (com.webank.wedatasphere.qualitis.query.response.RuleQueryRule)1