Search in sources :

Example 1 with CustomAlarmConfigRequest

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

the class AddCustomRuleRequestBuilder method commonAlarmSetting.

public CustomAlarmConfigRequest commonAlarmSetting(Integer checkTemplateEnum, Integer compareType, double value) {
    CustomAlarmConfigRequest newAlarmConfigRequest = new CustomAlarmConfigRequest();
    newAlarmConfigRequest.setUploadAbnormalValue(getUploadAbnormalValue());
    newAlarmConfigRequest.setDeleteFailCheckResult(getDeleteFailCheckResult());
    newAlarmConfigRequest.setUploadRuleMetricValue(getUploadRuleMetricValue());
    newAlarmConfigRequest.setRuleMetricEnCode(getRuleMetricEnCode());
    newAlarmConfigRequest.setThreshold(value);
    switch(checkTemplateEnum) {
        case 1:
            newAlarmConfigRequest.setCheckTemplate(CheckTemplateEnum.MONTH_FLUCTUATION.getCode());
            break;
        case 2:
            newAlarmConfigRequest.setCheckTemplate(CheckTemplateEnum.WEEK_FLUCTUATION.getCode());
            break;
        case 3:
            newAlarmConfigRequest.setCheckTemplate(CheckTemplateEnum.DAY_FLUCTUATION.getCode());
            break;
        case 4:
            newAlarmConfigRequest.setCheckTemplate(CheckTemplateEnum.FIXED_VALUE.getCode());
            newAlarmConfigRequest.setCompareType(compareType);
            break;
        case 5:
            newAlarmConfigRequest.setCheckTemplate(CheckTemplateEnum.FULL_YEAR_RING_GROWTH.getCode());
            break;
        case 6:
            newAlarmConfigRequest.setCheckTemplate(CheckTemplateEnum.HALF_YEAR_GROWTH.getCode());
            break;
        case 7:
            newAlarmConfigRequest.setCheckTemplate(CheckTemplateEnum.SEASON_RING_GROWTH.getCode());
            break;
        case 8:
            newAlarmConfigRequest.setCheckTemplate(CheckTemplateEnum.MONTH_RING_GROWTH.getCode());
            break;
        case 9:
            newAlarmConfigRequest.setCheckTemplate(CheckTemplateEnum.WEEK_RING_GROWTH.getCode());
            break;
        case 10:
            newAlarmConfigRequest.setCheckTemplate(CheckTemplateEnum.DAY_RING_GROWTH.getCode());
            break;
        case 11:
            newAlarmConfigRequest.setCheckTemplate(CheckTemplateEnum.HOUR_RING_GROWTH.getCode());
            break;
        case 12:
            newAlarmConfigRequest.setCheckTemplate(CheckTemplateEnum.YEAR_ON_YEAR.getCode());
            break;
        default:
            addCustomRuleRequest.setAlarm(false);
            LOGGER.info("");
    }
    return newAlarmConfigRequest;
}
Also used : CustomAlarmConfigRequest(com.webank.wedatasphere.qualitis.rule.request.CustomAlarmConfigRequest)

Example 2 with CustomAlarmConfigRequest

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

the class AddCustomRuleRequestBuilder method commonAlarmSetting.

public CustomAlarmConfigRequest commonAlarmSetting(Integer checkTemplateEnum, Integer compareType, String value) {
    CustomAlarmConfigRequest newAlarmConfigRequest = new CustomAlarmConfigRequest();
    newAlarmConfigRequest.setUploadAbnormalValue(getUploadAbnormalValue());
    newAlarmConfigRequest.setDeleteFailCheckResult(getDeleteFailCheckResult());
    newAlarmConfigRequest.setUploadRuleMetricValue(getUploadRuleMetricValue());
    newAlarmConfigRequest.setRuleMetricEnCode(getRuleMetricEnCode());
    newAlarmConfigRequest.setThreshold(Double.parseDouble(value));
    switch(checkTemplateEnum) {
        case 1:
            newAlarmConfigRequest.setCheckTemplate(CheckTemplateEnum.MONTH_FLUCTUATION.getCode());
            break;
        case 2:
            newAlarmConfigRequest.setCheckTemplate(CheckTemplateEnum.WEEK_FLUCTUATION.getCode());
            break;
        case 3:
            newAlarmConfigRequest.setCheckTemplate(CheckTemplateEnum.DAY_FLUCTUATION.getCode());
            break;
        case 4:
            newAlarmConfigRequest.setCheckTemplate(CheckTemplateEnum.FIXED_VALUE.getCode());
            newAlarmConfigRequest.setCompareType(compareType);
            break;
        case 5:
            newAlarmConfigRequest.setCheckTemplate(CheckTemplateEnum.FULL_YEAR_RING_GROWTH.getCode());
            break;
        case 6:
            newAlarmConfigRequest.setCheckTemplate(CheckTemplateEnum.HALF_YEAR_GROWTH.getCode());
            break;
        case 7:
            newAlarmConfigRequest.setCheckTemplate(CheckTemplateEnum.SEASON_RING_GROWTH.getCode());
            break;
        case 8:
            newAlarmConfigRequest.setCheckTemplate(CheckTemplateEnum.MONTH_RING_GROWTH.getCode());
            break;
        case 9:
            newAlarmConfigRequest.setCheckTemplate(CheckTemplateEnum.WEEK_RING_GROWTH.getCode());
            break;
        case 10:
            newAlarmConfigRequest.setCheckTemplate(CheckTemplateEnum.DAY_RING_GROWTH.getCode());
            break;
        case 11:
            newAlarmConfigRequest.setCheckTemplate(CheckTemplateEnum.HOUR_RING_GROWTH.getCode());
            break;
        case 12:
            newAlarmConfigRequest.setCheckTemplate(CheckTemplateEnum.YEAR_ON_YEAR.getCode());
            break;
        default:
            addCustomRuleRequest.setAlarm(false);
            LOGGER.info("");
    }
    return newAlarmConfigRequest;
}
Also used : CustomAlarmConfigRequest(com.webank.wedatasphere.qualitis.rule.request.CustomAlarmConfigRequest)

Example 3 with CustomAlarmConfigRequest

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

the class RuleNodeServiceImpl method constructCustomAlarmConfigRequest.

private List<CustomAlarmConfigRequest> constructCustomAlarmConfigRequest(Set<AlarmConfig> alarmConfigs, AddCustomRuleRequest addCustomRuleRequest) {
    List<CustomAlarmConfigRequest> alarmConfigRequests = new ArrayList<>(alarmConfigs.size());
    for (AlarmConfig alarmConfig : alarmConfigs) {
        CustomAlarmConfigRequest alarmConfigRequest = new CustomAlarmConfigRequest();
        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());
        alarmConfigRequest.setDeleteFailCheckResult(alarmConfig.getDeleteFailCheckResult());
        addCustomRuleRequest.setOutputName(ruleMetric.getName());
        alarmConfigRequests.add(alarmConfigRequest);
    }
    return alarmConfigRequests;
}
Also used : RuleMetric(com.webank.wedatasphere.qualitis.entity.RuleMetric) CustomAlarmConfigRequest(com.webank.wedatasphere.qualitis.rule.request.CustomAlarmConfigRequest) ArrayList(java.util.ArrayList) AlarmConfig(com.webank.wedatasphere.qualitis.rule.entity.AlarmConfig)

Example 4 with CustomAlarmConfigRequest

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

the class AddCustomRuleRequestBuilder method basicInfoWithDataSource.

@Override
public AddRequestBuilder basicInfoWithDataSource(String cluster, String sql, String alertInfo, boolean abortOnFailure, String execParams) throws UnExpectedRequestException, MetaDataAcquireFailedException {
    // Use automatic generate rule name and project.
    automaticProjectRuleSetting();
    // Alert info.
    alertSetting(alertInfo);
    addCustomRuleRequest.setSqlCheckArea(sql);
    addCustomRuleRequest.setSaveMidTable(false);
    String dataSourceId = "";
    Matcher matcherId = DATA_SOURCE_ID.matcher(cluster.toUpperCase());
    String dataSourceName = "";
    Matcher matcherName = DATA_SOURCE_NAME.matcher(cluster.toUpperCase());
    while (matcherId.find()) {
        String group = matcherId.group();
        dataSourceId = group.replace(".(", "").replace(")", "").split("=")[1];
        int startIndex = cluster.toUpperCase().indexOf(group);
        String replaceStr = cluster.substring(startIndex, startIndex + group.length());
        cluster = cluster.replace(replaceStr, "");
    }
    if (StringUtils.isBlank(dataSourceId)) {
        while (matcherName.find()) {
            String group = matcherName.group();
            int startIndex = cluster.toUpperCase().indexOf(group);
            String replaceStr = cluster.substring(startIndex, startIndex + group.length());
            dataSourceName = replaceStr.replace(".(", "").replace(")", "").split("=")[1];
            cluster = cluster.replace(replaceStr, "");
        }
    }
    addCustomRuleRequest.setClusterName(cluster);
    if (StringUtils.isNotBlank(dataSourceId)) {
        LOGGER.info("Find data source connect. Data source ID: " + dataSourceId);
        addCustomRuleRequest.setLinkisDataSourceId(Long.parseLong(dataSourceId));
        GeneralResponse<Map> response = metaDataClient.getDataSourceInfoDetail(cluster, userName, addCustomRuleRequest.getLinkisDataSourceId(), null);
        Map dataSourceInfo = ((Map) response.getData().get("info"));
        String dataSourceInfoName = (String) dataSourceInfo.get("dataSourceName");
        String dataSourceInfoType = (String) ((Map) dataSourceInfo.get("dataSourceType")).get("name");
        addCustomRuleRequest.setLinkisDataSourceName(dataSourceInfoName);
        addCustomRuleRequest.setLinkisDataSourceType(dataSourceInfoType);
    } else if (StringUtils.isNotBlank(dataSourceName)) {
        LOGGER.info("Find data source connect. Data source name: " + dataSourceName);
        GeneralResponse<Map> response = metaDataClient.getDataSourceInfoDetailByName(cluster, userName, dataSourceName);
        Map dataSourceInfo = ((Map) response.getData().get("info"));
        String dataSourceInfoName = (String) dataSourceInfo.get("dataSourceName");
        String dataSourceInfoType = (String) ((Map) dataSourceInfo.get("dataSourceType")).get("name");
        Integer currentDataSourceId = (Integer) dataSourceInfo.get("id");
        addCustomRuleRequest.setLinkisDataSourceId(currentDataSourceId.longValue());
        addCustomRuleRequest.setLinkisDataSourceName(dataSourceInfoName);
        addCustomRuleRequest.setLinkisDataSourceType(dataSourceInfoType);
    }
    taskSetting(abortOnFailure, execParams);
    // Init alarm properties.
    List<CustomAlarmConfigRequest> alarmVariable = new ArrayList<>();
    addCustomRuleRequest.setAlarm(true);
    addCustomRuleRequest.setAlarmVariable(alarmVariable);
    return this;
}
Also used : GeneralResponse(com.webank.wedatasphere.qualitis.response.GeneralResponse) Matcher(java.util.regex.Matcher) CustomAlarmConfigRequest(com.webank.wedatasphere.qualitis.rule.request.CustomAlarmConfigRequest) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) Map(java.util.Map)

Example 5 with CustomAlarmConfigRequest

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

the class RuleBatchServiceImpl method constructAddCustomRuleRequest.

private List<AddCustomRuleRequest> constructAddCustomRuleRequest(Map<String, List<ExcelCustomRuleByProject>> customRulePartitionedByRuleName, Project project, String localeStr) throws UnExpectedRequestException {
    List<AddCustomRuleRequest> addCustomRuleRequests = new ArrayList<>();
    for (String ruleName : customRulePartitionedByRuleName.keySet()) {
        List<ExcelCustomRuleByProject> ruleInfos = customRulePartitionedByRuleName.get(ruleName);
        AddCustomRuleRequest addCustomRuleRequest = new AddCustomRuleRequest();
        ExcelCustomRuleByProject firstCommonInfo = ruleInfos.get(0);
        boolean alarm = false;
        Long projectId = project.getId();
        addCustomRuleRequest.setSpecifyStaticStartupParam(firstCommonInfo.getSpecifyStaticStartupParam());
        addCustomRuleRequest.setDeleteFailCheckResult(firstCommonInfo.getDeleteFailCheckResult());
        addCustomRuleRequest.setStaticStartupParam(firstCommonInfo.getStaticStartupParam());
        addCustomRuleRequest.setAbortOnFailure(firstCommonInfo.getAbortOnFailure());
        addCustomRuleRequest.setProxyUser(firstCommonInfo.getProxyUser());
        String ruleGroupName = firstCommonInfo.getRuleGroupName();
        String clusterName = firstCommonInfo.getClusterName();
        String outputName = firstCommonInfo.getOutputName();
        String fromContent = null;
        String whereContent = null;
        Integer functionType = null;
        String functionContent = null;
        Boolean saveMidTable = firstCommonInfo.getSaveMidTable();
        if (firstCommonInfo.getLinkisDataSourceId() != null) {
            addCustomRuleRequest.setLinkisDataSourceId(Long.parseLong(firstCommonInfo.getLinkisDataSourceId()));
            addCustomRuleRequest.setLinkisDataSourceName(firstCommonInfo.getLinkisDataSourceName());
            addCustomRuleRequest.setLinkisDataSourceType(firstCommonInfo.getLinkisDataSourceType());
        }
        if (StringUtils.isNotBlank(firstCommonInfo.getFunctionName()) && StringUtils.isNotBlank(firstCommonInfo.getFunctionContent()) && StringUtils.isNotBlank(firstCommonInfo.getFromContent()) && StringUtils.isNotBlank(firstCommonInfo.getWhereContent())) {
            functionType = FunctionTypeEnum.getFunctionTypeByName(firstCommonInfo.getFunctionName());
            functionContent = firstCommonInfo.getFunctionContent();
            whereContent = firstCommonInfo.getWhereContent();
            fromContent = firstCommonInfo.getFromContent();
        } else {
            addCustomRuleRequest.setSqlCheckArea(firstCommonInfo.getSqlCheckArea());
        }
        List<CustomAlarmConfigRequest> alarmConfigRequests = new ArrayList<>();
        for (ExcelCustomRuleByProject excelCustomRule : ruleInfos) {
            getCustomAlarmConfig(alarmConfigRequests, excelCustomRule, localeStr);
        }
        if (StringUtils.isBlank(ruleGroupName)) {
            throw new UnExpectedRequestException("RuleGroupName {&CAN_NOT_BE_NULL_OR_EMPTY}");
        }
        RuleGroup ruleGroupInDb = ruleGroupDao.findByRuleGroupNameAndProjectId(ruleGroupName, projectId);
        if (ruleGroupInDb != null) {
            addCustomRuleRequest.setRuleGroupId(ruleGroupInDb.getId());
        } else {
            RuleGroup ruleGroup = ruleGroupDao.saveRuleGroup(new RuleGroup(ruleGroupName, project.getId()));
            addCustomRuleRequest.setRuleGroupId(ruleGroup.getId());
        }
        addCustomRuleRequest.setRuleName(ruleName);
        addCustomRuleRequest.setRuleCnName(firstCommonInfo.getRuleCnName());
        addCustomRuleRequest.setRuleDetail(firstCommonInfo.getRuleDetail());
        if (!alarmConfigRequests.isEmpty()) {
            alarm = true;
        }
        addCustomRuleRequest.setAlarm(alarm);
        addCustomRuleRequest.setProjectId(projectId);
        addCustomRuleRequest.setOutputName(outputName);
        addCustomRuleRequest.setFunctionType(functionType);
        addCustomRuleRequest.setSaveMidTable(saveMidTable);
        addCustomRuleRequest.setFunctionContent(functionContent);
        addCustomRuleRequest.setAlarmVariable(alarmConfigRequests);
        addCustomRuleRequest.setWhereContent(whereContent);
        addCustomRuleRequest.setFromContent(fromContent);
        addCustomRuleRequest.setClusterName(clusterName);
        addCustomRuleRequests.add(addCustomRuleRequest);
    }
    return addCustomRuleRequests;
}
Also used : UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) ExcelCustomRuleByProject(com.webank.wedatasphere.qualitis.project.excel.ExcelCustomRuleByProject) ArrayList(java.util.ArrayList) RuleGroup(com.webank.wedatasphere.qualitis.rule.entity.RuleGroup) AddCustomRuleRequest(com.webank.wedatasphere.qualitis.rule.request.AddCustomRuleRequest) CustomAlarmConfigRequest(com.webank.wedatasphere.qualitis.rule.request.CustomAlarmConfigRequest)

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