Search in sources :

Example 6 with CustomAlarmConfigRequest

use of com.webank.wedatasphere.qualitis.rule.request.CustomAlarmConfigRequest in project Qualitis by WeBankFinTech.

the class RuleBatchServiceImpl method getCustomAlarmConfig.

private void getCustomAlarmConfig(List<CustomAlarmConfigRequest> customAlarmConfigRequests, ExcelCustomRuleByProject excelCustomRule, String localeStr) throws UnExpectedRequestException {
    String templateOutputName = excelCustomRule.getAlarmCheckName();
    if (!StringUtils.isBlank(templateOutputName)) {
        String checkTemplateName = excelCustomRule.getCheckTemplateName();
        String compareTypeName = excelCustomRule.getCompareType();
        String threshold = excelCustomRule.getThreshold();
        CustomAlarmConfigRequest customAlarmConfigRequest = new CustomAlarmConfigRequest();
        customAlarmConfigRequest.setCheckTemplate(CheckTemplateEnum.getCheckTemplateCode(checkTemplateName, localeStr));
        customAlarmConfigRequest.setCompareType(CompareTypeEnum.getCompareTypeCode(compareTypeName));
        customAlarmConfigRequest.setThreshold(Double.valueOf(threshold));
        // Rule Metric.
        String ruleMetricEnCode = excelCustomRule.getRuleMetricEnCode();
        if (StringUtils.isNotBlank(ruleMetricEnCode)) {
            // xx_xx_xx_encode, index is 3.
            RuleMetric ruleMetricInDb = ruleMetricDao.findByEnCode(ruleMetricEnCode);
            if (ruleMetricInDb == null) {
                throw new UnExpectedRequestException("Rule metric[Code=" + ruleMetricEnCode + "] " + "{&DOES_NOT_EXIST}");
            }
            String code = ruleMetricInDb.getEnCode();
            customAlarmConfigRequest.setRuleMetricEnCode(code);
        }
        customAlarmConfigRequest.setUploadRuleMetricValue(excelCustomRule.getUploadRuleMetricValue());
        customAlarmConfigRequest.setUploadAbnormalValue(excelCustomRule.getUploadAbnormalValue());
        customAlarmConfigRequests.add(customAlarmConfigRequest);
    }
}
Also used : RuleMetric(com.webank.wedatasphere.qualitis.entity.RuleMetric) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) CustomAlarmConfigRequest(com.webank.wedatasphere.qualitis.rule.request.CustomAlarmConfigRequest)

Example 7 with CustomAlarmConfigRequest

use of com.webank.wedatasphere.qualitis.rule.request.CustomAlarmConfigRequest 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)

Aggregations

CustomAlarmConfigRequest (com.webank.wedatasphere.qualitis.rule.request.CustomAlarmConfigRequest)7 ArrayList (java.util.ArrayList)4 RuleMetric (com.webank.wedatasphere.qualitis.entity.RuleMetric)3 UnExpectedRequestException (com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException)3 AlarmConfig (com.webank.wedatasphere.qualitis.rule.entity.AlarmConfig)2 ExcelCustomRuleByProject (com.webank.wedatasphere.qualitis.project.excel.ExcelCustomRuleByProject)1 GeneralResponse (com.webank.wedatasphere.qualitis.response.GeneralResponse)1 RuleGroup (com.webank.wedatasphere.qualitis.rule.entity.RuleGroup)1 TemplateOutputMeta (com.webank.wedatasphere.qualitis.rule.entity.TemplateOutputMeta)1 AddCustomRuleRequest (com.webank.wedatasphere.qualitis.rule.request.AddCustomRuleRequest)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Matcher (java.util.regex.Matcher)1