Search in sources :

Example 11 with TemplateOutputMeta

use of com.webank.wedatasphere.qualitis.rule.entity.TemplateOutputMeta 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 12 with TemplateOutputMeta

use of com.webank.wedatasphere.qualitis.rule.entity.TemplateOutputMeta 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 13 with TemplateOutputMeta

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

the class RuleTemplateServiceImpl method getRuleTemplateMeta.

@Override
public GeneralResponse<TemplateMetaResponse> getRuleTemplateMeta(Long ruleTemplateId) throws UnExpectedRequestException {
    // Find rule template by id
    Template templateInDb = ruleTemplateDao.findById(ruleTemplateId);
    if (null == templateInDb) {
        throw new UnExpectedRequestException("rule_template_id {&CAN_NOT_BE_NULL_OR_EMPTY}");
    }
    // Find input meta data by template
    List<TemplateMidTableInputMeta> templateMidTableInputMetas = templateMidTableInputMetaDao.findByRuleTemplate(templateInDb);
    List<TemplateOutputMeta> templateOutputMetas = templateOutputMetaDao.findByRuleTemplate(templateInDb);
    List<Integer> types = templateDataSourceTypeDao.findByTemplate(templateInDb).stream().map(TemplateDataSourceType::getDataSourceTypeId).collect(Collectors.toList());
    TemplateMetaResponse response = new TemplateMetaResponse(templateInDb, templateMidTableInputMetas, templateOutputMetas, types);
    LOGGER.info("Succeed to get rule_template. rule_template_id: {}", ruleTemplateId);
    return new GeneralResponse<>("200", "{&GET_RULE_TEMPLATE_META_SUCCESSFULLY}", response);
}
Also used : GeneralResponse(com.webank.wedatasphere.qualitis.response.GeneralResponse) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) TemplateMidTableInputMeta(com.webank.wedatasphere.qualitis.rule.entity.TemplateMidTableInputMeta) TemplateOutputMeta(com.webank.wedatasphere.qualitis.rule.entity.TemplateOutputMeta) Template(com.webank.wedatasphere.qualitis.rule.entity.Template) TemplateMetaResponse(com.webank.wedatasphere.qualitis.rule.response.TemplateMetaResponse)

Example 14 with TemplateOutputMeta

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

the class TemplateOutputMetaServiceImpl method getAndSaveTemplateOutputMeta.

@Override
@Transactional(rollbackFor = RuntimeException.class)
public Set<TemplateOutputMeta> getAndSaveTemplateOutputMeta(String outputName, Integer functionType, Boolean saveMidTable, Template template) {
    Set<TemplateOutputMeta> templateOutputMetas = new HashSet<>();
    TemplateOutputMeta templateOutputMeta = new TemplateOutputMeta();
    templateOutputMeta.setTemplate(template);
    templateOutputMeta.setOutputName(outputName);
    if (saveMidTable) {
        templateOutputMeta.setFieldName(FunctionTypeEnum.getByCode(functionType).getFunction());
    } else {
        templateOutputMeta.setFieldName(FunctionTypeEnum.MAX_FUNCTION.getFunction());
    }
    templateOutputMeta.setFieldType(FieldTypeEnum.NUMBER.getCode());
    TemplateOutputMeta savedTemplateOutputMeta = templateOutputMetaDao.saveTemplateOutputMeta(templateOutputMeta);
    LOGGER.info("Succeed to save template output_meta: {}", templateOutputMeta);
    templateOutputMetas.add(savedTemplateOutputMeta);
    return templateOutputMetas;
}
Also used : TemplateOutputMeta(com.webank.wedatasphere.qualitis.rule.entity.TemplateOutputMeta) HashSet(java.util.HashSet) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

TemplateOutputMeta (com.webank.wedatasphere.qualitis.rule.entity.TemplateOutputMeta)14 RuleMetric (com.webank.wedatasphere.qualitis.entity.RuleMetric)7 Template (com.webank.wedatasphere.qualitis.rule.entity.Template)7 TemplateStatisticsInputMeta (com.webank.wedatasphere.qualitis.rule.entity.TemplateStatisticsInputMeta)7 ArrayList (java.util.ArrayList)7 HashSet (java.util.HashSet)6 UnExpectedRequestException (com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException)5 TemplateMidTableInputMeta (com.webank.wedatasphere.qualitis.rule.entity.TemplateMidTableInputMeta)5 AlarmConfig (com.webank.wedatasphere.qualitis.rule.entity.AlarmConfig)4 CustomAlarmConfigRequest (com.webank.wedatasphere.qualitis.rule.request.CustomAlarmConfigRequest)4 TemplateDataSourceType (com.webank.wedatasphere.qualitis.rule.entity.TemplateDataSourceType)3 AlarmConfigRequest (com.webank.wedatasphere.qualitis.rule.request.AlarmConfigRequest)3 FileAlarmConfigRequest (com.webank.wedatasphere.qualitis.rule.request.FileAlarmConfigRequest)3 Transactional (org.springframework.transaction.annotation.Transactional)3 GeneralResponse (com.webank.wedatasphere.qualitis.response.GeneralResponse)2 Rule (com.webank.wedatasphere.qualitis.rule.entity.Rule)2 RuleDataSource (com.webank.wedatasphere.qualitis.rule.entity.RuleDataSource)2 TemplateMetaResponse (com.webank.wedatasphere.qualitis.rule.response.TemplateMetaResponse)2 RuleDataSourceMapping (com.webank.wedatasphere.qualitis.rule.entity.RuleDataSourceMapping)1 RuleVariable (com.webank.wedatasphere.qualitis.rule.entity.RuleVariable)1