Search in sources :

Example 6 with AddMultiSourceRuleRequest

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

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

the class RuleBatchServiceImpl method addMultiTemplateRule.

private void addMultiTemplateRule(Map<String, List<ExcelMultiTemplateRuleByProject>> multiRulePartitionedByRuleName, Project project, String userName, boolean aomp) throws UnExpectedRequestException, ClusterInfoNotConfigException, TaskNotExistException, PermissionDeniedRequestException {
    Map<String, List<ExcelMultiTemplateRuleByProject>> modifyRulePartitionedByRuleName = new HashMap<>(1);
    Map<String, List<ExcelMultiTemplateRuleByProject>> addRulePartitionedByRuleName = new HashMap<>(1);
    String localeStr = httpServletRequest.getHeader("Content-Language");
    for (Iterator<String> iterator = multiRulePartitionedByRuleName.keySet().iterator(); iterator.hasNext(); ) {
        String currentRuleName = iterator.next();
        Rule currentRule = ruleDao.findByProjectAndRuleName(project, currentRuleName);
        if (currentRule != null) {
            modifyRulePartitionedByRuleName.put(currentRuleName, multiRulePartitionedByRuleName.get(currentRuleName));
            List<AddMultiSourceRuleRequest> addRuleRequestList = constructAddMultiSourceRuleRequest(modifyRulePartitionedByRuleName, project, localeStr);
            ModifyMultiSourceRequest modifyRuleRequest = new ModifyMultiSourceRequest();
            modifyRuleRequest.setRuleId(currentRule.getId());
            AddMultiSourceRuleRequest addRuleRequest = addRuleRequestList.iterator().next();
            BeanUtils.copyProperties(addRuleRequest, modifyRuleRequest);
            LOGGER.info("Start to modify multi rule. request: {}", modifyRuleRequest);
            if (aomp) {
                multiSourceRuleService.modifyRuleDetailForOuter(modifyRuleRequest, userName);
            } else {
                multiSourceRuleService.modifyMultiSourceRule(modifyRuleRequest);
            }
            LOGGER.info("Success to modify multi rule.");
            modifyRulePartitionedByRuleName.clear();
        } else {
            addRulePartitionedByRuleName.put(currentRuleName, multiRulePartitionedByRuleName.get(currentRuleName));
            List<AddMultiSourceRuleRequest> addRuleRequestList = constructAddMultiSourceRuleRequest(addRulePartitionedByRuleName, project, localeStr);
            AddMultiSourceRuleRequest currentAddMultiSourceRuleRequest = addRuleRequestList.iterator().next();
            LOGGER.info("Start to add multi rule. request: {}", currentAddMultiSourceRuleRequest);
            if (aomp) {
                currentAddMultiSourceRuleRequest.setLoginUser(userName);
                multiSourceRuleService.addRuleForOuter(currentAddMultiSourceRuleRequest, true);
            } else {
                multiSourceRuleService.addMultiSourceRuleForUpload(currentAddMultiSourceRuleRequest, true);
            }
            LOGGER.info("Success to add multi rule.");
            addRulePartitionedByRuleName.clear();
        }
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List) Rule(com.webank.wedatasphere.qualitis.rule.entity.Rule) ModifyMultiSourceRequest(com.webank.wedatasphere.qualitis.rule.request.multi.ModifyMultiSourceRequest) AddMultiSourceRuleRequest(com.webank.wedatasphere.qualitis.rule.request.multi.AddMultiSourceRuleRequest)

Aggregations

AddMultiSourceRuleRequest (com.webank.wedatasphere.qualitis.rule.request.multi.AddMultiSourceRuleRequest)7 UnExpectedRequestException (com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException)6 ArrayList (java.util.ArrayList)5 AlarmConfigRequest (com.webank.wedatasphere.qualitis.rule.request.AlarmConfigRequest)4 MultiDataSourceConfigRequest (com.webank.wedatasphere.qualitis.rule.request.multi.MultiDataSourceConfigRequest)4 MultiDataSourceJoinConfigRequest (com.webank.wedatasphere.qualitis.rule.request.multi.MultiDataSourceJoinConfigRequest)4 MetaDataAcquireFailedException (com.webank.wedatasphere.qualitis.metadata.exception.MetaDataAcquireFailedException)3 GeneralResponse (com.webank.wedatasphere.qualitis.response.GeneralResponse)3 Rule (com.webank.wedatasphere.qualitis.rule.entity.Rule)3 RuleGroup (com.webank.wedatasphere.qualitis.rule.entity.RuleGroup)3 MultiDataSourceJoinColumnRequest (com.webank.wedatasphere.qualitis.rule.request.multi.MultiDataSourceJoinColumnRequest)3 IOException (java.io.IOException)3 List (java.util.List)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 SpecCharEnum (com.webank.wedatasphere.qualitis.constant.SpecCharEnum)2 ColumnInfoDetail (com.webank.wedatasphere.qualitis.metadata.response.column.ColumnInfoDetail)2 ProjectDao (com.webank.wedatasphere.qualitis.project.dao.ProjectDao)2 Project (com.webank.wedatasphere.qualitis.project.entity.Project)2 ProjectService (com.webank.wedatasphere.qualitis.project.service.ProjectService)2