Search in sources :

Example 31 with RuleMetric

use of com.webank.wedatasphere.qualitis.entity.RuleMetric in project Qualitis by WeBankFinTech.

the class RuleNodeServiceImpl method constructAlarmConfigRequest.

private List<AlarmConfigRequest> constructAlarmConfigRequest(Set<AlarmConfig> alarmConfigs) {
    List<AlarmConfigRequest> alarmConfigRequests = new ArrayList<>(alarmConfigs.size());
    for (AlarmConfig alarmConfig : alarmConfigs) {
        AlarmConfigRequest alarmConfigRequest = new AlarmConfigRequest();
        alarmConfigRequest.setOutputMetaId(alarmConfig.getTemplateOutputMeta().getId());
        alarmConfigRequest.setCheckTemplate(alarmConfig.getCheckTemplate());
        alarmConfigRequest.setCompareType(alarmConfig.getCompareType());
        alarmConfigRequest.setThreshold(alarmConfig.getThreshold());
        RuleMetric ruleMetric = alarmConfig.getRuleMetric();
        alarmConfigRequest.setRuleMetricEnCode(ruleMetric != null ? ruleMetric.getEnCode() : "");
        alarmConfigRequest.setUploadAbnormalValue(alarmConfig.getUploadAbnormalValue());
        alarmConfigRequest.setUploadRuleMetricValue(alarmConfig.getUploadRuleMetricValue());
        alarmConfigRequests.add(alarmConfigRequest);
    }
    return alarmConfigRequests;
}
Also used : RuleMetric(com.webank.wedatasphere.qualitis.entity.RuleMetric) FileAlarmConfigRequest(com.webank.wedatasphere.qualitis.rule.request.FileAlarmConfigRequest) CustomAlarmConfigRequest(com.webank.wedatasphere.qualitis.rule.request.CustomAlarmConfigRequest) AlarmConfigRequest(com.webank.wedatasphere.qualitis.rule.request.AlarmConfigRequest) ArrayList(java.util.ArrayList) AlarmConfig(com.webank.wedatasphere.qualitis.rule.entity.AlarmConfig)

Example 32 with RuleMetric

use of com.webank.wedatasphere.qualitis.entity.RuleMetric in project Qualitis by WeBankFinTech.

the class RuleNodeServiceImpl method updateImportedRule.

public void updateImportedRule(Rule rule, Rule ruleInDb, RuleGroup ruleGroup, RuleNodeRequest ruleNodeRequest, Template template, Set<AlarmConfig> alarmConfigs, Set<RuleVariable> ruleVariables, Set<RuleDataSource> ruleDataSources, Set<RuleDataSourceMapping> ruleDataSourceMappings) throws UnExpectedRequestException, IOException {
    ruleInDb.setRuleGroup(ruleGroup);
    ruleInDb.setAlarm(rule.getAlarm());
    ruleInDb.setAbortOnFailure(rule.getAbortOnFailure());
    ruleInDb.setFromContent(rule.getFromContent());
    ruleInDb.setWhereContent(rule.getWhereContent());
    ruleInDb.setRuleType(rule.getRuleType());
    ruleInDb.setRuleTemplateName(template.getName());
    ruleInDb.setOutputName(rule.getOutputName());
    ruleInDb.setFunctionType(rule.getFunctionType());
    ruleInDb.setFunctionContent(rule.getFunctionContent());
    ruleInDb.setDeleteFailCheckResult(rule.getDeleteFailCheckResult());
    if (RuleTypeEnum.CUSTOM_RULE.getCode().equals(rule.getRuleType())) {
        ruleTemplateService.deleteCustomTemplate(ruleInDb.getTemplate());
        Template savedTemplate = ruleTemplateDao.saveTemplate(template);
        Set<TemplateStatisticsInputMeta> templateStatisticsInputMetas = new HashSet<>();
        Set<TemplateOutputMeta> templateOutputMetaSet = new HashSet<>();
        if (rule.getOutputName() != null && rule.getFunctionType() != null && rule.getFunctionContent() != null) {
            templateStatisticsInputMetas = templateStatisticsInputMetaService.getAndSaveTemplateStatisticsInputMeta(rule.getOutputName(), rule.getFunctionType(), rule.getFunctionContent(), savedTemplate.getSaveMidTable(), savedTemplate);
            templateOutputMetaSet = templateOutputMetaService.getAndSaveTemplateOutputMeta(rule.getOutputName(), rule.getFunctionType(), savedTemplate.getSaveMidTable(), savedTemplate);
        } else {
            List<RuleMetric> ruleMetrics = alarmConfigs.stream().map(AlarmConfig::getRuleMetric).collect(Collectors.toList());
            for (RuleMetric ruleMetric : ruleMetrics) {
                templateStatisticsInputMetas.addAll(templateStatisticsInputMetaService.getAndSaveTemplateStatisticsInputMeta(ruleMetric.getName(), FunctionTypeEnum.MAX_FUNCTION.getCode(), ruleMetric.getName(), savedTemplate.getSaveMidTable(), savedTemplate));
                templateOutputMetaSet.addAll(templateOutputMetaService.getAndSaveTemplateOutputMeta(ruleMetric.getName(), FunctionTypeEnum.MAX_FUNCTION.getCode(), savedTemplate.getSaveMidTable(), savedTemplate));
            }
        }
        savedTemplate.setStatisticAction(templateStatisticsInputMetas);
        savedTemplate.setTemplateOutputMetas(templateOutputMetaSet);
        ruleInDb.setTemplate(savedTemplate);
    } else {
        synchroRuleTemplate(ruleNodeRequest, ruleInDb, template, ruleDataSources);
    }
    alarmConfigService.deleteByRule(ruleInDb);
    LOGGER.info("Succeed to delete all alarm_config. rule_id: {}", ruleInDb.getId());
    Integer ruleType = ruleInDb.getRuleType();
    if (RuleTypeEnum.SINGLE_TEMPLATE_RULE.getCode().equals(ruleType) || RuleTypeEnum.MULTI_TEMPLATE_RULE.getCode().equals(ruleType)) {
        ruleVariableService.deleteByRule(ruleInDb);
        LOGGER.info("Succeed to delete all rule_variable. rule_id: {}", ruleInDb.getId());
        if (RuleTypeEnum.MULTI_TEMPLATE_RULE.getCode().equals(ruleType)) {
            ruleDataSourceMappingService.deleteByRule(ruleInDb);
            LOGGER.info("Succeed to delete all rule_dataSource_mapping. rule_id: {}", ruleInDb.getId());
        }
    }
    ruleDataSourceService.deleteByRule(ruleInDb);
    LOGGER.info("Succeed to delete all rule_dataSources. rule_id: {}", ruleInDb.getId());
    Rule updateRule = ruleDao.saveRule(ruleInDb);
    saveRuleInfo(updateRule, template, updateRule.getProject(), alarmConfigs, ruleVariables, ruleDataSources, ruleDataSourceMappings);
    updateImportedChildRule(updateRule, ruleNodeRequest);
}
Also used : RuleMetric(com.webank.wedatasphere.qualitis.entity.RuleMetric) Rule(com.webank.wedatasphere.qualitis.rule.entity.Rule) TemplateOutputMeta(com.webank.wedatasphere.qualitis.rule.entity.TemplateOutputMeta) Template(com.webank.wedatasphere.qualitis.rule.entity.Template) TemplateStatisticsInputMeta(com.webank.wedatasphere.qualitis.rule.entity.TemplateStatisticsInputMeta) HashSet(java.util.HashSet)

Example 33 with RuleMetric

use of com.webank.wedatasphere.qualitis.entity.RuleMetric in project Qualitis by WeBankFinTech.

the class AlarmConfigServiceImpl method checkAndSaveCustomAlarmVariable.

@Override
public List<AlarmConfig> checkAndSaveCustomAlarmVariable(List<CustomAlarmConfigRequest> requests, Rule rule) throws UnExpectedRequestException {
    List<AlarmConfig> alarmConfigs = new ArrayList<>();
    List<RuleMetric> ruleMetrics = new ArrayList<>();
    for (CustomAlarmConfigRequest request : requests) {
        AlarmConfig newAlarmConfig = new AlarmConfig();
        RuleMetric ruleMetric = ruleMetricDao.findByEnCode(request.getRuleMetricEnCode());
        newAlarmConfig.setRuleMetric(ruleMetric);
        ruleMetrics.add(ruleMetric);
        // Check existence of templateOutputMeta
        TemplateOutputMeta templateOutputMetaInDb = rule.getTemplate().getTemplateOutputMetas().stream().filter(f -> f.getOutputName().equals(ruleMetric.getName())).iterator().next();
        // Generate alarmConfig and save
        newAlarmConfig.setRule(rule);
        newAlarmConfig.setTemplateOutputMeta(templateOutputMetaInDb);
        newAlarmConfig.setCheckTemplate(request.getCheckTemplate());
        newAlarmConfig.setThreshold(request.getThreshold());
        Integer checkTemplateCode = request.getCheckTemplate();
        if (checkTemplateCode.equals(CheckTemplateEnum.FIXED_VALUE.getCode()) || checkTemplateCode.equals(CheckTemplateEnum.FULL_YEAR_RING_GROWTH.getCode()) || checkTemplateCode.equals(CheckTemplateEnum.HALF_YEAR_GROWTH.getCode()) || checkTemplateCode.equals(CheckTemplateEnum.SEASON_RING_GROWTH.getCode()) || checkTemplateCode.equals(CheckTemplateEnum.MONTH_RING_GROWTH.getCode()) || checkTemplateCode.equals(CheckTemplateEnum.WEEK_RING_GROWTH.getCode()) || checkTemplateCode.equals(CheckTemplateEnum.DAY_RING_GROWTH.getCode()) || checkTemplateCode.equals(CheckTemplateEnum.HOUR_RING_GROWTH.getCode()) || checkTemplateCode.equals(CheckTemplateEnum.YEAR_ON_YEAR.getCode())) {
            newAlarmConfig.setCompareType(request.getCompareType());
        }
        newAlarmConfig.setUploadAbnormalValue(request.getUploadAbnormalValue());
        newAlarmConfig.setUploadRuleMetricValue(request.getUploadRuleMetricValue());
        newAlarmConfig.setDeleteFailCheckResult(request.getDeleteFailCheckResult());
        alarmConfigs.add(newAlarmConfig);
    }
    Set<String> deptNames = ruleMetrics.stream().map(RuleMetric::getDepartmentName).collect(Collectors.toSet());
    if (deptNames.size() > 1) {
        throw new UnExpectedRequestException("{&NOT_SAME_DEPT_SYS_METRIC}");
    }
    return alarmConfigDao.saveAllAlarmConfig(alarmConfigs);
}
Also used : RuleMetric(com.webank.wedatasphere.qualitis.entity.RuleMetric) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) ArrayList(java.util.ArrayList) CustomAlarmConfigRequest(com.webank.wedatasphere.qualitis.rule.request.CustomAlarmConfigRequest) TemplateOutputMeta(com.webank.wedatasphere.qualitis.rule.entity.TemplateOutputMeta) AlarmConfig(com.webank.wedatasphere.qualitis.rule.entity.AlarmConfig)

Example 34 with RuleMetric

use of com.webank.wedatasphere.qualitis.entity.RuleMetric in project Qualitis by WeBankFinTech.

the class AlarmConfigServiceImpl method checkAndSaveAlarmVariable.

@Override
@Transactional(rollbackFor = { RuntimeException.class, UnExpectedRequestException.class })
public List<AlarmConfig> checkAndSaveAlarmVariable(List<AlarmConfigRequest> requests, Rule rule) throws UnExpectedRequestException {
    List<AlarmConfig> alarmConfigs = new ArrayList<>();
    for (AlarmConfigRequest request : requests) {
        // Check Arguments
        AlarmConfigRequest.checkRequest(request);
        // Check existence of templateOutputMeta
        TemplateOutputMeta templateOutputMetaInDb = templateOutputMetaService.checkTemplateOutputMetaId(request.getOutputMetaId());
        // return if is multi-table template
        if (isChildOrParentOutput(rule.getTemplate(), templateOutputMetaInDb)) {
            continue;
        }
        // Check template output meta
        checkTemplateContain(rule.getTemplate(), templateOutputMetaInDb);
        // Generate alarmConfig and save
        AlarmConfig newAlarmConfig = new AlarmConfig();
        newAlarmConfig.setRule(rule);
        newAlarmConfig.setTemplateOutputMeta(templateOutputMetaInDb);
        newAlarmConfig.setCheckTemplate(request.getCheckTemplate());
        newAlarmConfig.setThreshold(request.getThreshold());
        Integer checkTemplateCode = request.getCheckTemplate();
        if (checkTemplateCode.equals(CheckTemplateEnum.FIXED_VALUE.getCode()) || checkTemplateCode.equals(CheckTemplateEnum.FULL_YEAR_RING_GROWTH.getCode()) || checkTemplateCode.equals(CheckTemplateEnum.HALF_YEAR_GROWTH.getCode()) || checkTemplateCode.equals(CheckTemplateEnum.SEASON_RING_GROWTH.getCode()) || checkTemplateCode.equals(CheckTemplateEnum.MONTH_RING_GROWTH.getCode()) || checkTemplateCode.equals(CheckTemplateEnum.WEEK_RING_GROWTH.getCode()) || checkTemplateCode.equals(CheckTemplateEnum.DAY_RING_GROWTH.getCode()) || checkTemplateCode.equals(CheckTemplateEnum.HOUR_RING_GROWTH.getCode()) || checkTemplateCode.equals(CheckTemplateEnum.YEAR_ON_YEAR.getCode())) {
            newAlarmConfig.setCompareType(request.getCompareType());
        }
        if (StringUtils.isNotBlank(request.getRuleMetricEnCode())) {
            RuleMetric ruleMetric = ruleMetricDao.findByEnCode(request.getRuleMetricEnCode());
            newAlarmConfig.setRuleMetric(ruleMetric);
            newAlarmConfig.setUploadAbnormalValue(request.getUploadAbnormalValue());
            newAlarmConfig.setUploadRuleMetricValue(request.getUploadRuleMetricValue());
        }
        alarmConfigs.add(newAlarmConfig);
    }
    return alarmConfigDao.saveAllAlarmConfig(alarmConfigs);
}
Also used : RuleMetric(com.webank.wedatasphere.qualitis.entity.RuleMetric) FileAlarmConfigRequest(com.webank.wedatasphere.qualitis.rule.request.FileAlarmConfigRequest) CustomAlarmConfigRequest(com.webank.wedatasphere.qualitis.rule.request.CustomAlarmConfigRequest) AlarmConfigRequest(com.webank.wedatasphere.qualitis.rule.request.AlarmConfigRequest) ArrayList(java.util.ArrayList) TemplateOutputMeta(com.webank.wedatasphere.qualitis.rule.entity.TemplateOutputMeta) AlarmConfig(com.webank.wedatasphere.qualitis.rule.entity.AlarmConfig) Transactional(org.springframework.transaction.annotation.Transactional)

Example 35 with RuleMetric

use of com.webank.wedatasphere.qualitis.entity.RuleMetric in project Qualitis by WeBankFinTech.

the class AlarmConfigServiceImpl method checkAndSaveFileAlarmVariable.

@Override
@Transactional(rollbackFor = { RuntimeException.class, UnExpectedRequestException.class })
public List<AlarmConfig> checkAndSaveFileAlarmVariable(List<FileAlarmConfigRequest> requests, Rule rule) {
    List<AlarmConfig> alarmConfigs = new ArrayList<>();
    for (FileAlarmConfigRequest request : requests) {
        // Generate alarmConfig and save
        AlarmConfig newAlarmConfig = new AlarmConfig();
        newAlarmConfig.setFileOutputName(request.getFileOutputName());
        newAlarmConfig.setFileOutputUnit(request.getFileOutputUnit());
        newAlarmConfig.setRule(rule);
        newAlarmConfig.setCheckTemplate(request.getCheckTemplate());
        newAlarmConfig.setThreshold(request.getThreshold());
        Integer checkTemplateCode = request.getCheckTemplate();
        if (checkTemplateCode.equals(CheckTemplateEnum.FIXED_VALUE.getCode()) || checkTemplateCode.equals(CheckTemplateEnum.FULL_YEAR_RING_GROWTH.getCode()) || checkTemplateCode.equals(CheckTemplateEnum.HALF_YEAR_GROWTH.getCode()) || checkTemplateCode.equals(CheckTemplateEnum.SEASON_RING_GROWTH.getCode()) || checkTemplateCode.equals(CheckTemplateEnum.MONTH_RING_GROWTH.getCode()) || checkTemplateCode.equals(CheckTemplateEnum.WEEK_RING_GROWTH.getCode()) || checkTemplateCode.equals(CheckTemplateEnum.DAY_RING_GROWTH.getCode()) || checkTemplateCode.equals(CheckTemplateEnum.HOUR_RING_GROWTH.getCode()) || checkTemplateCode.equals(CheckTemplateEnum.YEAR_ON_YEAR.getCode())) {
            newAlarmConfig.setCompareType(request.getCompareType());
        }
        if (StringUtils.isNotBlank(request.getRuleMetricEnCode())) {
            RuleMetric ruleMetric = ruleMetricDao.findByEnCode(request.getRuleMetricEnCode());
            newAlarmConfig.setRuleMetric(ruleMetric);
        }
        newAlarmConfig.setUploadAbnormalValue(request.getUploadAbnormalValue());
        newAlarmConfig.setUploadRuleMetricValue(request.getUploadRuleMetricValue());
        newAlarmConfig.setDeleteFailCheckResult(request.getDeleteFailCheckResult());
        alarmConfigs.add(newAlarmConfig);
    }
    return alarmConfigDao.saveAllAlarmConfig(alarmConfigs);
}
Also used : RuleMetric(com.webank.wedatasphere.qualitis.entity.RuleMetric) ArrayList(java.util.ArrayList) FileAlarmConfigRequest(com.webank.wedatasphere.qualitis.rule.request.FileAlarmConfigRequest) AlarmConfig(com.webank.wedatasphere.qualitis.rule.entity.AlarmConfig) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

RuleMetric (com.webank.wedatasphere.qualitis.entity.RuleMetric)36 ArrayList (java.util.ArrayList)23 UnExpectedRequestException (com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException)19 AlarmConfig (com.webank.wedatasphere.qualitis.rule.entity.AlarmConfig)15 RuleMetricDepartmentUser (com.webank.wedatasphere.qualitis.entity.RuleMetricDepartmentUser)10 User (com.webank.wedatasphere.qualitis.entity.User)10 Department (com.webank.wedatasphere.qualitis.entity.Department)9 UserRole (com.webank.wedatasphere.qualitis.entity.UserRole)9 List (java.util.List)9 ExcelRuleMetric (com.webank.wedatasphere.qualitis.project.excel.ExcelRuleMetric)8 GeneralResponse (com.webank.wedatasphere.qualitis.response.GeneralResponse)8 Rule (com.webank.wedatasphere.qualitis.rule.entity.Rule)7 TemplateOutputMeta (com.webank.wedatasphere.qualitis.rule.entity.TemplateOutputMeta)7 CustomAlarmConfigRequest (com.webank.wedatasphere.qualitis.rule.request.CustomAlarmConfigRequest)7 FileAlarmConfigRequest (com.webank.wedatasphere.qualitis.rule.request.FileAlarmConfigRequest)7 PermissionDeniedRequestException (com.webank.wedatasphere.qualitis.exception.PermissionDeniedRequestException)6 RuleMetricResponse (com.webank.wedatasphere.qualitis.response.RuleMetricResponse)6 RuleDataSource (com.webank.wedatasphere.qualitis.rule.entity.RuleDataSource)5 Date (java.util.Date)5 Template (com.webank.wedatasphere.qualitis.rule.entity.Template)4