Search in sources :

Example 11 with AlarmConfigRequest

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

the class RuleBatchServiceImpl method constructAddMultiSourceRuleRequest.

private List<AddMultiSourceRuleRequest> constructAddMultiSourceRuleRequest(Map<String, List<ExcelMultiTemplateRuleByProject>> multiRulePartitionedByRuleName, Project project, String localeStr) throws UnExpectedRequestException {
    List<AddMultiSourceRuleRequest> addMultiSourceRuleRequests = new ArrayList<>();
    for (String ruleName : multiRulePartitionedByRuleName.keySet()) {
        List<ExcelMultiTemplateRuleByProject> ruleInfos = multiRulePartitionedByRuleName.get(ruleName);
        ExcelMultiTemplateRuleByProject firstCommonInfo = ruleInfos.get(0);
        AddMultiSourceRuleRequest addMultiSourceRuleRequest = new AddMultiSourceRuleRequest();
        String ruleTemplateName = firstCommonInfo.getTemplateName();
        String ruleGroupName = firstCommonInfo.getRuleGroupName();
        addMultiSourceRuleRequest.setSpecifyStaticStartupParam(firstCommonInfo.getSpecifyStaticStartupParam());
        addMultiSourceRuleRequest.setDeleteFailCheckResult(firstCommonInfo.getDeleteFailCheckResult());
        addMultiSourceRuleRequest.setStaticStartupParam(firstCommonInfo.getStaticStartupParam());
        addMultiSourceRuleRequest.setAbortOnFailure(firstCommonInfo.getAbortOnFailure());
        if (StringUtils.isBlank(ruleGroupName)) {
            throw new UnExpectedRequestException("RuleGroupName {&CAN_NOT_BE_NULL_OR_EMPTY}");
        }
        Template template = findTemplateByName(ruleTemplateName);
        if (template == null) {
            throw new UnExpectedRequestException("{&TEMPLATE_NAME}: [" + ruleTemplateName + "] {&DOES_NOT_EXIST}");
        }
        String filter = null;
        boolean alarm = false;
        String clusterName = firstCommonInfo.getClusterName();
        MultiDataSourceConfigRequest sourceConfigRequest = new MultiDataSourceConfigRequest();
        MultiDataSourceConfigRequest targetConfigRequest = new MultiDataSourceConfigRequest();
        List<MultiDataSourceJoinConfigRequest> mappings = new ArrayList<>();
        List<AlarmConfigRequest> alarmConfigRequests = new ArrayList<>();
        for (ExcelMultiTemplateRuleByProject excelMultiTemplateRule : ruleInfos) {
            if (StringUtils.isNotBlank(excelMultiTemplateRule.getWhereFilter())) {
                filter = excelMultiTemplateRule.getWhereFilter();
            }
            getAlarmConfig(alarmConfigRequests, excelMultiTemplateRule, template, localeStr);
            getMultiDataSourceRequest(sourceConfigRequest, excelMultiTemplateRule, 0);
            getMultiDataSourceRequest(targetConfigRequest, excelMultiTemplateRule, 1);
            getMultiDataSourceJoinRequest(mappings, excelMultiTemplateRule);
        }
        if (alarmConfigRequests.size() != 0) {
            alarm = true;
        }
        RuleGroup ruleGroupInDb = ruleGroupDao.findByRuleGroupNameAndProjectId(ruleGroupName, project.getId());
        if (ruleGroupInDb != null) {
            addMultiSourceRuleRequest.setRuleGroupId(ruleGroupInDb.getId());
        } else {
            RuleGroup ruleGroup = ruleGroupDao.saveRuleGroup(new RuleGroup(ruleGroupName, project.getId()));
            addMultiSourceRuleRequest.setRuleGroupId(ruleGroup.getId());
        }
        addMultiSourceRuleRequest.setRuleName(ruleName);
        addMultiSourceRuleRequest.setClusterName(clusterName);
        addMultiSourceRuleRequest.setProjectId(project.getId());
        addMultiSourceRuleRequest.setRuleDetail(firstCommonInfo.getRuleDetail());
        addMultiSourceRuleRequest.setMultiSourceRuleTemplateId(template.getId());
        addMultiSourceRuleRequest.setAlarmVariable(alarmConfigRequests);
        addMultiSourceRuleRequests.add(addMultiSourceRuleRequest);
        addMultiSourceRuleRequest.setSource(sourceConfigRequest);
        addMultiSourceRuleRequest.setTarget(targetConfigRequest);
        addMultiSourceRuleRequest.setMappings(mappings);
        addMultiSourceRuleRequest.setFilter(filter);
        addMultiSourceRuleRequest.setAlarm(alarm);
    }
    return addMultiSourceRuleRequests;
}
Also used : UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) ExcelMultiTemplateRuleByProject(com.webank.wedatasphere.qualitis.project.excel.ExcelMultiTemplateRuleByProject) ArrayList(java.util.ArrayList) RuleGroup(com.webank.wedatasphere.qualitis.rule.entity.RuleGroup) Template(com.webank.wedatasphere.qualitis.rule.entity.Template) MultiDataSourceJoinConfigRequest(com.webank.wedatasphere.qualitis.rule.request.multi.MultiDataSourceJoinConfigRequest) FileAlarmConfigRequest(com.webank.wedatasphere.qualitis.rule.request.FileAlarmConfigRequest) CustomAlarmConfigRequest(com.webank.wedatasphere.qualitis.rule.request.CustomAlarmConfigRequest) AlarmConfigRequest(com.webank.wedatasphere.qualitis.rule.request.AlarmConfigRequest) MultiDataSourceConfigRequest(com.webank.wedatasphere.qualitis.rule.request.multi.MultiDataSourceConfigRequest) AddMultiSourceRuleRequest(com.webank.wedatasphere.qualitis.rule.request.multi.AddMultiSourceRuleRequest)

Example 12 with AlarmConfigRequest

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

the class RuleBatchServiceImpl method constructAddRuleRequest.

private List<AddRuleRequest> constructAddRuleRequest(Map<String, List<ExcelTemplateRuleByProject>> partitionedByRuleName, Project project, String localeStr) throws UnExpectedRequestException {
    List<AddRuleRequest> addRuleRequests = new ArrayList<>();
    for (String ruleName : partitionedByRuleName.keySet()) {
        List<ExcelTemplateRuleByProject> ruleInfos = partitionedByRuleName.get(ruleName);
        ExcelTemplateRuleByProject firstCommonInfo = ruleInfos.get(0);
        AddRuleRequest addRuleRequest = new AddRuleRequest();
        String ruleDetail = firstCommonInfo.getRuleDetail();
        String ruleCnName = firstCommonInfo.getRuleCnName();
        String ruleGroupName = firstCommonInfo.getRuleGroupName();
        String ruleTemplateName = firstCommonInfo.getTemplateName();
        addRuleRequest.setRuleCnName(ruleCnName);
        addRuleRequest.setAbortOnFailure(firstCommonInfo.getAbortOnFailure());
        addRuleRequest.setStaticStartupParam(firstCommonInfo.getStaticStartupParam());
        addRuleRequest.setDeleteFailCheckResult(firstCommonInfo.getDeleteFailCheckResult());
        addRuleRequest.setSpecifyStaticStartupParam(firstCommonInfo.getSpecifyStaticStartupParam());
        if (StringUtils.isBlank(ruleGroupName)) {
            throw new UnExpectedRequestException("RuleGroupName {&CAN_NOT_BE_NULL_OR_EMPTY}");
        }
        Template template = findTemplateByName(ruleTemplateName);
        if (template == null) {
            throw new UnExpectedRequestException("{&TEMPLATE_NAME}: [" + ruleTemplateName + "] {&DOES_NOT_EXIST}");
        }
        boolean alarm = false;
        Long projectId = project.getId();
        List<DataSourceRequest> dataSourceRequests = new ArrayList<>();
        List<AlarmConfigRequest> alarmConfigRequests = new ArrayList<>();
        List<TemplateArgumentRequest> templateArgumentRequests = new ArrayList<>();
        for (ExcelTemplateRuleByProject excelTemplateRuleByProject : ruleInfos) {
            getDataSourceRequest(dataSourceRequests, excelTemplateRuleByProject);
            getTemplateArgument(templateArgumentRequests, excelTemplateRuleByProject, template);
            getAlarmConfig(alarmConfigRequests, excelTemplateRuleByProject, template, localeStr);
        }
        RuleGroup ruleGroupInDb = ruleGroupDao.findByRuleGroupNameAndProjectId(ruleGroupName, projectId);
        if (ruleGroupInDb != null) {
            addRuleRequest.setRuleGroupId(ruleGroupInDb.getId());
        } else {
            RuleGroup ruleGroup = ruleGroupDao.saveRuleGroup(new RuleGroup(ruleGroupName, project.getId()));
            addRuleRequest.setRuleGroupId(ruleGroup.getId());
        }
        // Construct addRuleRequest
        addRuleRequest.setRuleName(ruleName);
        addRuleRequest.setRuleDetail(ruleDetail);
        addRuleRequest.setRuleTemplateId(template.getId());
        if (!alarmConfigRequests.isEmpty()) {
            alarm = true;
        }
        addRuleRequest.setAlarmVariable(alarmConfigRequests);
        addRuleRequest.setDatasource(dataSourceRequests);
        addRuleRequest.setProjectId(projectId);
        addRuleRequest.setAlarm(alarm);
        addRuleRequest.setTemplateArgumentRequests(templateArgumentRequests);
        addRuleRequests.add(addRuleRequest);
    }
    return addRuleRequests;
}
Also used : AddRuleRequest(com.webank.wedatasphere.qualitis.rule.request.AddRuleRequest) DataSourceRequest(com.webank.wedatasphere.qualitis.rule.request.DataSourceRequest) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) ArrayList(java.util.ArrayList) RuleGroup(com.webank.wedatasphere.qualitis.rule.entity.RuleGroup) Template(com.webank.wedatasphere.qualitis.rule.entity.Template) TemplateArgumentRequest(com.webank.wedatasphere.qualitis.rule.request.TemplateArgumentRequest) FileAlarmConfigRequest(com.webank.wedatasphere.qualitis.rule.request.FileAlarmConfigRequest) CustomAlarmConfigRequest(com.webank.wedatasphere.qualitis.rule.request.CustomAlarmConfigRequest) AlarmConfigRequest(com.webank.wedatasphere.qualitis.rule.request.AlarmConfigRequest) ExcelTemplateRuleByProject(com.webank.wedatasphere.qualitis.project.excel.ExcelTemplateRuleByProject)

Example 13 with AlarmConfigRequest

use of com.webank.wedatasphere.qualitis.rule.request.AlarmConfigRequest 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 14 with AlarmConfigRequest

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

Aggregations

AlarmConfigRequest (com.webank.wedatasphere.qualitis.rule.request.AlarmConfigRequest)14 CustomAlarmConfigRequest (com.webank.wedatasphere.qualitis.rule.request.CustomAlarmConfigRequest)7 FileAlarmConfigRequest (com.webank.wedatasphere.qualitis.rule.request.FileAlarmConfigRequest)7 UnExpectedRequestException (com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException)6 ArrayList (java.util.ArrayList)6 RuleMetric (com.webank.wedatasphere.qualitis.entity.RuleMetric)5 TemplateOutputMeta (com.webank.wedatasphere.qualitis.rule.entity.TemplateOutputMeta)4 AddMultiSourceRuleRequest (com.webank.wedatasphere.qualitis.rule.request.multi.AddMultiSourceRuleRequest)3 MultiDataSourceConfigRequest (com.webank.wedatasphere.qualitis.rule.request.multi.MultiDataSourceConfigRequest)3 MultiDataSourceJoinConfigRequest (com.webank.wedatasphere.qualitis.rule.request.multi.MultiDataSourceJoinConfigRequest)3 ExcelMultiTemplateRuleByProject (com.webank.wedatasphere.qualitis.project.excel.ExcelMultiTemplateRuleByProject)2 AlarmConfig (com.webank.wedatasphere.qualitis.rule.entity.AlarmConfig)2 RuleGroup (com.webank.wedatasphere.qualitis.rule.entity.RuleGroup)2 Template (com.webank.wedatasphere.qualitis.rule.entity.Template)2 MultiDataSourceJoinColumnRequest (com.webank.wedatasphere.qualitis.rule.request.multi.MultiDataSourceJoinColumnRequest)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 LocalConfig (com.webank.wedatasphere.qualitis.LocalConfig)1 SpecCharEnum (com.webank.wedatasphere.qualitis.constant.SpecCharEnum)1 RuleMetricDao (com.webank.wedatasphere.qualitis.dao.RuleMetricDao)1 RuleMetricDepartmentUserDao (com.webank.wedatasphere.qualitis.dao.RuleMetricDepartmentUserDao)1