Search in sources :

Example 1 with RuleDataSourceMapping

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

the class RuleNodeServiceImpl method updateImportedChildRule.

public void updateImportedChildRule(Rule parentRule, RuleNodeRequest ruleNodeRequest) throws IOException, UnExpectedRequestException {
    if (parentRule.getChildRule() == null) {
        return;
    }
    LOGGER.info("Start to update imported child rule.");
    ObjectMapper objectMapper = new ObjectMapper();
    Rule childRule = parentRule.getChildRule();
    Rule childRuleObject = objectMapper.readValue(ruleNodeRequest.getChildRuleObject(), Rule.class);
    Template childTemplateObject = objectMapper.readValue(ruleNodeRequest.getChildTemplateObject(), Template.class);
    Set<RuleDataSource> childRuleDataSources = objectMapper.readValue(ruleNodeRequest.getChildRuleDataSourcesObject(), new TypeReference<Set<RuleDataSource>>() {
    });
    Set<RuleDataSourceMapping> childRuleDataSourceMappings = objectMapper.readValue(ruleNodeRequest.getChildRuleDataSourceMappingsObject(), new TypeReference<Set<RuleDataSourceMapping>>() {
    });
    Set<AlarmConfig> childAlarmConfigs = objectMapper.readValue(ruleNodeRequest.getChildAlarmConfigsObject(), new TypeReference<Set<AlarmConfig>>() {
    });
    Set<RuleVariable> childRuleVariables = objectMapper.readValue(ruleNodeRequest.getChildRuleVariablesObject(), new TypeReference<Set<RuleVariable>>() {
    });
    childRule.setAlarm(childRuleObject.getAlarm());
    childRule.setAbortOnFailure(childRuleObject.getAbortOnFailure());
    childRule.setFromContent(childRuleObject.getFromContent());
    childRule.setWhereContent(childRuleObject.getWhereContent());
    childRule.setRuleType(childRuleObject.getRuleType());
    childRule.setRuleTemplateName(childTemplateObject.getName());
    childRule.setOutputName(childRuleObject.getOutputName());
    childRule.setFunctionType(childRuleObject.getFunctionType());
    childRule.setFunctionContent(childRuleObject.getFunctionContent());
    Template childTemplateInDb = ruleTemplateService.checkRuleTemplate(childTemplateObject.getId());
    if (childTemplateInDb == null) {
        throw new UnExpectedRequestException("Child template [id = " + childTemplateObject.getId() + "] does not exist.");
    }
    alarmConfigService.deleteByRule(childRule);
    LOGGER.info("Succeed to delete all alarm_config of child rule. rule_id: {}", childRule.getId());
    ruleVariableService.deleteByRule(childRule);
    LOGGER.info("Succeed to delete all rule_variable of child rule. rule_id: {}", childRule.getId());
    ruleDataSourceService.deleteByRule(childRule);
    LOGGER.info("Succeed to delete all rule_dataSources of child rule. rule_id: {}", childRule.getId());
    ruleDataSourceMappingService.deleteByRule(childRule);
    LOGGER.info("Succeed to delete all rule_dataSource_mapping. rule_id: {}", childRule.getId());
    Rule updateRule = ruleDao.saveRule(childRule);
    List<RuleDataSource> ruleDataSourceList = new ArrayList<>();
    for (RuleDataSource ruleDataSource : childRuleDataSources) {
        ruleDataSource.setProjectId(parentRule.getProject().getId());
        ruleDataSource.setRule(updateRule);
        ruleDataSourceList.add(ruleDataSource);
    }
    List<AlarmConfig> alarmConfigList = new ArrayList<>();
    for (AlarmConfig alarmConfig : childAlarmConfigs) {
        alarmConfig.setRule(updateRule);
        alarmConfigList.add(alarmConfig);
    }
    List<RuleVariable> ruleVariablesList = new ArrayList<>();
    for (RuleVariable ruleVariable : childRuleVariables) {
        ruleVariable.setRule(updateRule);
        ruleVariablesList.add(ruleVariable);
    }
    updateRule.setAlarmConfigs(new HashSet<>(alarmConfigDao.saveAllAlarmConfig(alarmConfigList)));
    updateRule.setRuleVariables(new HashSet<>(ruleVariableDao.saveAllRuleVariable(ruleVariablesList)));
    updateRule.setRuleDataSources(new HashSet<>(ruleDataSourceDao.saveAllRuleDataSource(ruleDataSourceList)));
    for (RuleDataSourceMapping ruleDataSourceMapping : childRuleDataSourceMappings) {
        ruleDataSourceMapping.setRule(updateRule);
        ruleDataSourceMappingDao.saveRuleDataSourceMapping(ruleDataSourceMapping);
    }
    updateRule.setParentRule(parentRule);
    parentRule.setChildRule(updateRule);
}
Also used : RuleDataSourceMapping(com.webank.wedatasphere.qualitis.rule.entity.RuleDataSourceMapping) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) RuleDataSource(com.webank.wedatasphere.qualitis.rule.entity.RuleDataSource) Set(java.util.Set) HashSet(java.util.HashSet) ArrayList(java.util.ArrayList) Template(com.webank.wedatasphere.qualitis.rule.entity.Template) Rule(com.webank.wedatasphere.qualitis.rule.entity.Rule) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) AlarmConfig(com.webank.wedatasphere.qualitis.rule.entity.AlarmConfig) RuleVariable(com.webank.wedatasphere.qualitis.rule.entity.RuleVariable)

Example 2 with RuleDataSourceMapping

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

the class RuleNodeServiceImpl method importRule.

@Override
@Transactional(rollbackFor = { RuntimeException.class, UnExpectedRequestException.class }, propagation = Propagation.REQUIRED)
public void importRule(RuleNodeRequest ruleNodeRequest, Project projectInDb, RuleGroup ruleGroup, ObjectMapper objectMapper) throws UnExpectedRequestException, IOException {
    // Rule, Template, RuleGroup.
    Rule rule = objectMapper.readValue(ruleNodeRequest.getRuleObject(), Rule.class);
    Template template = objectMapper.readValue(ruleNodeRequest.getTemplateObject(), Template.class);
    // RuleDataSource.
    Set<RuleDataSource> ruleDataSources = objectMapper.readValue(ruleNodeRequest.getRuleDataSourcesObject(), new TypeReference<Set<RuleDataSource>>() {
    });
    Set<RuleDataSourceMapping> ruleDataSourceMappings = objectMapper.readValue(ruleNodeRequest.getRuleDataSourceMappingsObject(), new TypeReference<Set<RuleDataSourceMapping>>() {
    });
    // Rule check meta info.
    Set<AlarmConfig> alarmConfigs = objectMapper.readValue(ruleNodeRequest.getAlarmConfigsObject(), new TypeReference<Set<AlarmConfig>>() {
    });
    Set<RuleVariable> ruleVariables = objectMapper.readValue(ruleNodeRequest.getRuleVariablesObject(), new TypeReference<Set<RuleVariable>>() {
    });
    LOGGER.info("Import basic information: {}", new StringBuilder().append("\n").append(rule.getName()).append("\n").append(template.getName()).append("\n").toString());
    LOGGER.info(objectMapper.writeValueAsString(ruleNodeRequest));
    Rule ruleInDb = ruleDao.findByProjectAndRuleName(projectInDb, rule.getName());
    try {
        importRuleReal(ruleNodeRequest, ruleInDb, rule, projectInDb, template, ruleGroup, alarmConfigs, ruleVariables, ruleDataSources, ruleDataSourceMappings);
    } catch (NullPointerException e) {
        LOGGER.error("Rule object attributes must not be null.", e);
    }
}
Also used : RuleDataSourceMapping(com.webank.wedatasphere.qualitis.rule.entity.RuleDataSourceMapping) RuleDataSource(com.webank.wedatasphere.qualitis.rule.entity.RuleDataSource) Set(java.util.Set) HashSet(java.util.HashSet) Template(com.webank.wedatasphere.qualitis.rule.entity.Template) Rule(com.webank.wedatasphere.qualitis.rule.entity.Rule) AlarmConfig(com.webank.wedatasphere.qualitis.rule.entity.AlarmConfig) RuleVariable(com.webank.wedatasphere.qualitis.rule.entity.RuleVariable) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with RuleDataSourceMapping

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

the class RuleNodeServiceImpl method constructMultiRequest.

private AddMultiSourceRuleRequest constructMultiRequest(Rule rule, RuleGroup ruleGroup) {
    AddMultiSourceRuleRequest addMultiSourceRuleRequest = new AddMultiSourceRuleRequest();
    String newVersion = ruleGroup.getVersion();
    if (StringUtils.isEmpty(newVersion)) {
        String newRuleName = rule.getName() + "_copy_" + ruleGroup.getId();
        LOGGER.info("Multi rule start to be copied. Copied rule name: " + newRuleName);
        addMultiSourceRuleRequest.setRuleName(newRuleName);
        if (StringUtils.isNotBlank(rule.getCnName())) {
            addMultiSourceRuleRequest.setRuleCnName(rule.getCnName() + "_副本");
        }
    } else {
        String oldVersion = rule.getRuleGroup().getVersion();
        LOGGER.info("Multi rule start to be copied. Copied rule name: " + rule.getName() + "_" + ruleGroup.getVersion());
        if (StringUtils.isNotBlank(oldVersion) && rule.getName().endsWith(oldVersion)) {
            addMultiSourceRuleRequest.setRuleName(rule.getName().replace(oldVersion, newVersion));
            if (StringUtils.isNotBlank(rule.getCnName())) {
                addMultiSourceRuleRequest.setRuleCnName(rule.getCnName().replace(oldVersion, newVersion));
            }
        } else {
            addMultiSourceRuleRequest.setRuleName(rule.getName() + "_" + newVersion);
            if (StringUtils.isNotBlank(rule.getCnName())) {
                addMultiSourceRuleRequest.setRuleCnName(rule.getCnName() + "_" + newVersion);
            }
        }
    }
    String ruleDetail = rule.getDetail();
    String clusterName = rule.getRuleDataSources().iterator().next().getClusterName();
    addMultiSourceRuleRequest.setAbortOnFailure(rule.getAbortOnFailure());
    addMultiSourceRuleRequest.setClusterName(clusterName);
    addMultiSourceRuleRequest.setRuleDetail(ruleDetail);
    addMultiSourceRuleRequest.setCsId(rule.getCsId());
    addMultiSourceRuleRequest.setSpecifyStaticStartupParam(rule.getSpecifyStaticStartupParam());
    addMultiSourceRuleRequest.setDeleteFailCheckResult(rule.getDeleteFailCheckResult());
    addMultiSourceRuleRequest.setMultiSourceRuleTemplateId(rule.getTemplate().getId());
    addMultiSourceRuleRequest.setStaticStartupParam(rule.getStaticStartupParam());
    addMultiSourceRuleRequest.setProjectId(ruleGroup.getProjectId());
    addMultiSourceRuleRequest.setRuleGroupId(ruleGroup.getId());
    List<RuleVariable> filterRuleVariable = rule.getRuleVariables().stream().filter(ruleVariable -> ruleVariable.getTemplateMidTableInputMeta().getInputType().equals(TemplateInputTypeEnum.CONDITION.getCode())).collect(Collectors.toList());
    if (filterRuleVariable != null && filterRuleVariable.size() != 0) {
        addMultiSourceRuleRequest.setFilter(filterRuleVariable.iterator().next().getValue());
    }
    // Data source request
    for (RuleDataSource ruleDataSource : rule.getRuleDataSources()) {
        String databaseName = ruleDataSource.getDbName();
        String tableName = ruleDataSource.getTableName();
        String filter = ruleDataSource.getFilter();
        Integer datasourceIndex = ruleDataSource.getDatasourceIndex();
        MultiDataSourceConfigRequest dataSourceConfigRequest = new MultiDataSourceConfigRequest();
        dataSourceConfigRequest.setDbName(databaseName);
        dataSourceConfigRequest.setTableName(tableName);
        dataSourceConfigRequest.setFilter(filter);
        dataSourceConfigRequest.setProxyUser(ruleDataSource.getProxyUser());
        if (ruleDataSource.getLinkisDataSourceId() != null) {
            dataSourceConfigRequest.setLinkisDataSourceType(TemplateDataSourceTypeEnum.getMessage(ruleDataSource.getDatasourceType()));
            dataSourceConfigRequest.setLinkisDataSourceName(ruleDataSource.getLinkisDataSourceName());
            dataSourceConfigRequest.setLinkisDataSourceId(ruleDataSource.getLinkisDataSourceId());
        }
        if (datasourceIndex == 0) {
            addMultiSourceRuleRequest.setSource(dataSourceConfigRequest);
        } else {
            addMultiSourceRuleRequest.setTarget(dataSourceConfigRequest);
        }
    }
    // Mapping
    List<MultiDataSourceJoinConfigRequest> mappings = new ArrayList<>();
    for (RuleDataSourceMapping mapping : rule.getRuleDataSourceMappings()) {
        MultiDataSourceJoinConfigRequest multiDataSourceJoinConfigRequest = new MultiDataSourceJoinConfigRequest();
        multiDataSourceJoinConfigRequest.setOperation(mapping.getOperation());
        multiDataSourceJoinConfigRequest.setLeftStatement(mapping.getLeftStatement());
        multiDataSourceJoinConfigRequest.setRightStatement(mapping.getRightStatement());
        List<MultiDataSourceJoinColumnRequest> left = getMultiDataSourceJoinColumnRequest(mapping.getLeftColumnNames(), mapping.getLeftColumnTypes());
        List<MultiDataSourceJoinColumnRequest> right = getMultiDataSourceJoinColumnRequest(mapping.getRightColumnNames(), mapping.getLeftColumnTypes());
        multiDataSourceJoinConfigRequest.setLeft(left);
        multiDataSourceJoinConfigRequest.setRight(right);
        mappings.add(multiDataSourceJoinConfigRequest);
    }
    addMultiSourceRuleRequest.setMappings(mappings);
    List<AlarmConfigRequest> alarmConfigRequests = constructAlarmConfigRequest(rule.getAlarmConfigs());
    addMultiSourceRuleRequest.setAlarm(true);
    addMultiSourceRuleRequest.setAlarmVariable(alarmConfigRequests);
    return addMultiSourceRuleRequest;
}
Also used : RuleDataSourceMappingDao(com.webank.wedatasphere.qualitis.rule.dao.RuleDataSourceMappingDao) Arrays(java.util.Arrays) StringUtils(org.apache.commons.lang.StringUtils) TemplateOutputMetaService(com.webank.wedatasphere.qualitis.rule.service.TemplateOutputMetaService) Autowired(org.springframework.beans.factory.annotation.Autowired) JsonProcessingException(org.codehaus.jackson.JsonProcessingException) GeneralResponse(com.webank.wedatasphere.qualitis.response.GeneralResponse) AlarmConfig(com.webank.wedatasphere.qualitis.rule.entity.AlarmConfig) RuleMetricDao(com.webank.wedatasphere.qualitis.dao.RuleMetricDao) DeleteRuleRequest(com.webank.wedatasphere.qualitis.rule.request.DeleteRuleRequest) OuterWorkflowService(com.webank.wedatasphere.qualitis.project.service.OuterWorkflowService) MultiDataSourceConfigRequest(com.webank.wedatasphere.qualitis.rule.request.multi.MultiDataSourceConfigRequest) RuleNodeRequests(com.webank.wedatasphere.qualitis.rule.request.RuleNodeRequests) FileOutputUnitEnum(com.webank.wedatasphere.qualitis.rule.constant.FileOutputUnitEnum) TemplateMidTableInputMeta(com.webank.wedatasphere.qualitis.rule.entity.TemplateMidTableInputMeta) AddMultiSourceRuleRequest(com.webank.wedatasphere.qualitis.rule.request.multi.AddMultiSourceRuleRequest) Set(java.util.Set) TemplateDataSourceType(com.webank.wedatasphere.qualitis.rule.entity.TemplateDataSourceType) DataSourceRequest(com.webank.wedatasphere.qualitis.rule.request.DataSourceRequest) TemplateMidTableInputMetaService(com.webank.wedatasphere.qualitis.rule.service.TemplateMidTableInputMetaService) TypeReference(org.codehaus.jackson.type.TypeReference) RuleDataSourceMappingService(com.webank.wedatasphere.qualitis.rule.service.RuleDataSourceMappingService) RuleNodeRequest(com.webank.wedatasphere.qualitis.rule.request.RuleNodeRequest) TemplateStatisticsInputMeta(com.webank.wedatasphere.qualitis.rule.entity.TemplateStatisticsInputMeta) FileAlarmConfigRequest(com.webank.wedatasphere.qualitis.rule.request.FileAlarmConfigRequest) TemplateArgumentRequest(com.webank.wedatasphere.qualitis.rule.request.TemplateArgumentRequest) Project(com.webank.wedatasphere.qualitis.project.entity.Project) RuleDataSourceDao(com.webank.wedatasphere.qualitis.rule.dao.RuleDataSourceDao) Rule(com.webank.wedatasphere.qualitis.rule.entity.Rule) ProjectDao(com.webank.wedatasphere.qualitis.project.dao.ProjectDao) ArrayList(java.util.ArrayList) TemplateDataSourceTypeDao(com.webank.wedatasphere.qualitis.rule.dao.TemplateDataSourceTypeDao) CheckTemplateEnum(com.webank.wedatasphere.qualitis.rule.constant.CheckTemplateEnum) Service(org.springframework.stereotype.Service) TemplateStatisticsInputMetaService(com.webank.wedatasphere.qualitis.rule.service.TemplateStatisticsInputMetaService) RuleTemplateService(com.webank.wedatasphere.qualitis.rule.service.RuleTemplateService) RuleVariableService(com.webank.wedatasphere.qualitis.rule.service.RuleVariableService) RoleService(com.webank.wedatasphere.qualitis.service.RoleService) DataSourceColumnRequest(com.webank.wedatasphere.qualitis.rule.request.DataSourceColumnRequest) CustomAlarmConfigRequest(com.webank.wedatasphere.qualitis.rule.request.CustomAlarmConfigRequest) IOException(java.io.IOException) FileRuleService(com.webank.wedatasphere.qualitis.rule.service.FileRuleService) TemplateInputTypeEnum(com.webank.wedatasphere.qualitis.rule.constant.TemplateInputTypeEnum) MultiSourceRuleService(com.webank.wedatasphere.qualitis.rule.service.MultiSourceRuleService) TemplateDataSourceTypeEnum(com.webank.wedatasphere.qualitis.rule.constant.TemplateDataSourceTypeEnum) RuleMetricDepartmentUserDao(com.webank.wedatasphere.qualitis.dao.RuleMetricDepartmentUserDao) UserDao(com.webank.wedatasphere.qualitis.dao.UserDao) RuleNodeService(com.webank.wedatasphere.qualitis.rule.service.RuleNodeService) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) LocalConfig(com.webank.wedatasphere.qualitis.LocalConfig) LoggerFactory(org.slf4j.LoggerFactory) TemplateMidTableUtil(com.webank.wedatasphere.qualitis.rule.util.TemplateMidTableUtil) SemanticException(org.apache.hadoop.hive.ql.parse.SemanticException) JsonNode(org.codehaus.jackson.JsonNode) PermissionDeniedRequestException(com.webank.wedatasphere.qualitis.exception.PermissionDeniedRequestException) RuleDataSource(com.webank.wedatasphere.qualitis.rule.entity.RuleDataSource) ParseException(org.apache.hadoop.hive.ql.parse.ParseException) RuleGroupDao(com.webank.wedatasphere.qualitis.rule.dao.RuleGroupDao) ProjectService(com.webank.wedatasphere.qualitis.project.service.ProjectService) AddCustomRuleRequest(com.webank.wedatasphere.qualitis.rule.request.AddCustomRuleRequest) AlarmConfigRequest(com.webank.wedatasphere.qualitis.rule.request.AlarmConfigRequest) ExcelMultiTemplateRuleByProject(com.webank.wedatasphere.qualitis.project.excel.ExcelMultiTemplateRuleByProject) TemplateOutputMetaDao(com.webank.wedatasphere.qualitis.rule.dao.TemplateOutputMetaDao) MappingOperationEnum(com.webank.wedatasphere.qualitis.rule.constant.MappingOperationEnum) InputActionStepEnum(com.webank.wedatasphere.qualitis.rule.constant.InputActionStepEnum) CustomRuleService(com.webank.wedatasphere.qualitis.rule.service.CustomRuleService) UuidGenerator(com.webank.wedatasphere.qualitis.util.UuidGenerator) CopyRuleRequest(com.webank.wedatasphere.qualitis.rule.request.CopyRuleRequest) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) RuleDataSourceMapping(com.webank.wedatasphere.qualitis.rule.entity.RuleDataSourceMapping) MetaDataAcquireFailedException(com.webank.wedatasphere.qualitis.metadata.exception.MetaDataAcquireFailedException) RuleService(com.webank.wedatasphere.qualitis.rule.service.RuleService) List(java.util.List) RoleNotFoundException(javax.management.relation.RoleNotFoundException) AlarmConfigDao(com.webank.wedatasphere.qualitis.rule.dao.AlarmConfigDao) CommonChecker(com.webank.wedatasphere.qualitis.project.request.CommonChecker) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) RuleNodeResponses(com.webank.wedatasphere.qualitis.rule.response.RuleNodeResponses) RuleNodeResponse(com.webank.wedatasphere.qualitis.rule.response.RuleNodeResponse) AlarmConfigService(com.webank.wedatasphere.qualitis.rule.service.AlarmConfigService) RuleGroup(com.webank.wedatasphere.qualitis.rule.entity.RuleGroup) SpecCharEnum(com.webank.wedatasphere.qualitis.constant.SpecCharEnum) RuleVariableDao(com.webank.wedatasphere.qualitis.rule.dao.RuleVariableDao) RuleVariable(com.webank.wedatasphere.qualitis.rule.entity.RuleVariable) RuleDataSourceService(com.webank.wedatasphere.qualitis.rule.service.RuleDataSourceService) UserRoleDao(com.webank.wedatasphere.qualitis.dao.UserRoleDao) AddFileRuleRequest(com.webank.wedatasphere.qualitis.rule.request.AddFileRuleRequest) HashSet(java.util.HashSet) User(com.webank.wedatasphere.qualitis.entity.User) CollectionUtils(org.apache.commons.collections.CollectionUtils) Propagation(org.springframework.transaction.annotation.Propagation) RuleTemplateDao(com.webank.wedatasphere.qualitis.rule.dao.RuleTemplateDao) TemplateOutputMeta(com.webank.wedatasphere.qualitis.rule.entity.TemplateOutputMeta) CompareTypeEnum(com.webank.wedatasphere.qualitis.rule.constant.CompareTypeEnum) MultiDataSourceJoinColumnRequest(com.webank.wedatasphere.qualitis.rule.request.multi.MultiDataSourceJoinColumnRequest) AddRuleRequest(com.webank.wedatasphere.qualitis.rule.request.AddRuleRequest) Logger(org.slf4j.Logger) ExcelTemplateFileRuleByProject(com.webank.wedatasphere.qualitis.project.excel.ExcelTemplateFileRuleByProject) Iterator(java.util.Iterator) RuleMetric(com.webank.wedatasphere.qualitis.entity.RuleMetric) Template(com.webank.wedatasphere.qualitis.rule.entity.Template) ProjectTypeEnum(com.webank.wedatasphere.qualitis.project.constant.ProjectTypeEnum) RuleResponse(com.webank.wedatasphere.qualitis.rule.response.RuleResponse) FunctionTypeEnum(com.webank.wedatasphere.qualitis.rule.constant.FunctionTypeEnum) UserService(com.webank.wedatasphere.qualitis.service.UserService) FileOutputNameEnum(com.webank.wedatasphere.qualitis.rule.constant.FileOutputNameEnum) RuleTypeEnum(com.webank.wedatasphere.qualitis.rule.constant.RuleTypeEnum) RuleDao(com.webank.wedatasphere.qualitis.rule.dao.RuleDao) MultiDataSourceJoinConfigRequest(com.webank.wedatasphere.qualitis.rule.request.multi.MultiDataSourceJoinConfigRequest) ModifyRuleRequest(com.webank.wedatasphere.qualitis.rule.request.ModifyRuleRequest) Comparator(java.util.Comparator) StringEscapeUtils(org.apache.commons.lang.StringEscapeUtils) Transactional(org.springframework.transaction.annotation.Transactional) RuleDataSourceMapping(com.webank.wedatasphere.qualitis.rule.entity.RuleDataSourceMapping) RuleDataSource(com.webank.wedatasphere.qualitis.rule.entity.RuleDataSource) MultiDataSourceJoinColumnRequest(com.webank.wedatasphere.qualitis.rule.request.multi.MultiDataSourceJoinColumnRequest) ArrayList(java.util.ArrayList) 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) RuleVariable(com.webank.wedatasphere.qualitis.rule.entity.RuleVariable)

Example 4 with RuleDataSourceMapping

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

the class RuleNodeServiceImpl method saveRuleInfo.

public void saveRuleInfo(Rule savedRule, Template template, Project projectInDb, Set<AlarmConfig> alarmConfigs, Set<RuleVariable> ruleVariables, Set<RuleDataSource> ruleDataSources, Set<RuleDataSourceMapping> ruleDataSourceMappings) {
    LOGGER.info("Start to save rule Info.");
    List<AlarmConfig> alarmConfigList = new ArrayList<>();
    for (AlarmConfig alarmConfig : alarmConfigs) {
        alarmConfig.setRule(savedRule);
        ruleMetricSycn(alarmConfig);
        alarmConfig.setTemplateOutputMeta(savedRule.getTemplate().getTemplateOutputMetas().iterator().next());
        alarmConfigList.add(alarmConfig);
    }
    List<RuleVariable> ruleVariablesList = new ArrayList<>();
    TemplateStatisticsInputMeta templateStatisticsInputMeta = savedRule.getTemplate().getStatisticAction().iterator().next();
    for (RuleVariable ruleVariable : ruleVariables) {
        ruleVariable.setRule(savedRule);
        ruleVariable.setTemplateStatisticsInputMeta(templateStatisticsInputMeta);
        ruleVariablesList.add(ruleVariable);
    }
    if (template.getId().intValue() != savedRule.getTemplate().getId().intValue()) {
        ruleVariablesList.sort(Comparator.comparing(RuleVariable::getId));
        List<TemplateMidTableInputMeta> templateMidTableInputMetaList = new ArrayList<>();
        if (savedRule.getTemplate().getTemplateMidTableInputMetas() != null) {
            templateMidTableInputMetaList.addAll(savedRule.getTemplate().getTemplateMidTableInputMetas());
            templateMidTableInputMetaList.sort(Comparator.comparing(TemplateMidTableInputMeta::getId));
            Iterator iterator = templateMidTableInputMetaList.iterator();
            for (RuleVariable ruleVariable : ruleVariablesList) {
                ruleVariable.setTemplateMidTableInputMeta((TemplateMidTableInputMeta) iterator.next());
            }
        }
    }
    List<RuleDataSource> ruleDataSourceList = new ArrayList<>();
    for (RuleDataSource ruleDataSource : ruleDataSources) {
        ruleDataSource.setProjectId(projectInDb.getId());
        ruleDataSource.setRule(savedRule);
        ruleDataSourceList.add(ruleDataSource);
    }
    if (RuleTypeEnum.CUSTOM_RULE.getCode().equals(savedRule.getRuleType())) {
        List<AlarmConfig> customAlarmConfigs = new ArrayList<>();
        for (AlarmConfig alarmConfig : alarmConfigList) {
            TemplateOutputMeta templateOutputMetaInDb = savedRule.getTemplate().getTemplateOutputMetas().iterator().next();
            AlarmConfig customAlarmConfig = new AlarmConfig();
            customAlarmConfig.setRule(savedRule);
            customAlarmConfig.setRuleMetric(alarmConfig.getRuleMetric());
            customAlarmConfig.setThreshold(alarmConfig.getThreshold());
            customAlarmConfig.setTemplateOutputMeta(templateOutputMetaInDb);
            customAlarmConfig.setCheckTemplate(alarmConfig.getCheckTemplate());
            Integer checkTemplateCode = alarmConfig.getCheckTemplate();
            if (alarmConfig.getCheckTemplate().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())) {
                customAlarmConfig.setCompareType(alarmConfig.getCompareType());
            }
            customAlarmConfigs.add(customAlarmConfig);
        }
        savedRule.setAlarmConfigs(new HashSet<>(alarmConfigDao.saveAllAlarmConfig(customAlarmConfigs)));
        savedRule.setRuleDataSources(new HashSet<>(ruleDataSourceDao.saveAllRuleDataSource(ruleDataSourceList)));
    } else {
        savedRule.setAlarmConfigs(new HashSet<>(alarmConfigDao.saveAllAlarmConfig(alarmConfigList)));
        savedRule.setRuleVariables(new HashSet<>(ruleVariableDao.saveAllRuleVariable(ruleVariablesList)));
        savedRule.setRuleDataSources(new HashSet<>(ruleDataSourceDao.saveAllRuleDataSource(ruleDataSourceList)));
        for (RuleDataSourceMapping ruleDataSourceMapping : ruleDataSourceMappings) {
            ruleDataSourceMapping.setRule(savedRule);
            ruleDataSourceMappingDao.saveRuleDataSourceMapping(ruleDataSourceMapping);
        }
    }
}
Also used : RuleDataSourceMapping(com.webank.wedatasphere.qualitis.rule.entity.RuleDataSourceMapping) RuleDataSource(com.webank.wedatasphere.qualitis.rule.entity.RuleDataSource) ArrayList(java.util.ArrayList) TemplateMidTableInputMeta(com.webank.wedatasphere.qualitis.rule.entity.TemplateMidTableInputMeta) TemplateOutputMeta(com.webank.wedatasphere.qualitis.rule.entity.TemplateOutputMeta) TemplateStatisticsInputMeta(com.webank.wedatasphere.qualitis.rule.entity.TemplateStatisticsInputMeta) Iterator(java.util.Iterator) AlarmConfig(com.webank.wedatasphere.qualitis.rule.entity.AlarmConfig) RuleVariable(com.webank.wedatasphere.qualitis.rule.entity.RuleVariable)

Example 5 with RuleDataSourceMapping

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

the class OuterExecutionServiceImpl method getMappingCols.

private void getMappingCols(Rule currentRule, List<Map<String, String>> mappingCols) {
    Map<String, String> leftCols = new LinkedHashMap<>();
    Map<String, String> rightCols = new LinkedHashMap<>();
    for (RuleDataSourceMapping ruleDataSourceMapping : currentRule.getRuleDataSourceMappings()) {
        if (StringUtils.isBlank(ruleDataSourceMapping.getLeftColumnNames()) || StringUtils.isBlank(ruleDataSourceMapping.getLeftColumnTypes()) || StringUtils.isBlank(ruleDataSourceMapping.getRightColumnNames()) || StringUtils.isBlank(ruleDataSourceMapping.getRightColumnTypes())) {
            break;
        }
        String[] leftJoinCols = ruleDataSourceMapping.getLeftColumnNames().split(",");
        String[] leftJoinTypes = ruleDataSourceMapping.getLeftColumnTypes().split("\\|");
        for (int i = 0; i < leftJoinCols.length; i++) {
            leftCols.put(leftJoinCols[i].split("\\.")[1], leftJoinTypes[i]);
        }
        String[] rightJoinCols = ruleDataSourceMapping.getRightColumnNames().split(",");
        String[] rightJoinTypes = ruleDataSourceMapping.getRightColumnTypes().split("\\|");
        for (int i = 0; i < rightJoinCols.length; i++) {
            rightCols.put(rightJoinCols[i].split("\\.")[1], rightJoinTypes[i]);
        }
    }
    mappingCols.add(leftCols);
    mappingCols.add(rightCols);
}
Also used : RuleDataSourceMapping(com.webank.wedatasphere.qualitis.rule.entity.RuleDataSourceMapping) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

RuleDataSourceMapping (com.webank.wedatasphere.qualitis.rule.entity.RuleDataSourceMapping)9 AlarmConfig (com.webank.wedatasphere.qualitis.rule.entity.AlarmConfig)7 RuleDataSource (com.webank.wedatasphere.qualitis.rule.entity.RuleDataSource)6 RuleVariable (com.webank.wedatasphere.qualitis.rule.entity.RuleVariable)6 ArrayList (java.util.ArrayList)6 Rule (com.webank.wedatasphere.qualitis.rule.entity.Rule)5 Template (com.webank.wedatasphere.qualitis.rule.entity.Template)5 HashSet (java.util.HashSet)5 Set (java.util.Set)5 RuleMetric (com.webank.wedatasphere.qualitis.entity.RuleMetric)3 UnExpectedRequestException (com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException)3 TemplateMidTableInputMeta (com.webank.wedatasphere.qualitis.rule.entity.TemplateMidTableInputMeta)3 TemplateStatisticsInputMeta (com.webank.wedatasphere.qualitis.rule.entity.TemplateStatisticsInputMeta)3 SpecCharEnum (com.webank.wedatasphere.qualitis.constant.SpecCharEnum)2 ExcelMultiTemplateRuleByProject (com.webank.wedatasphere.qualitis.project.excel.ExcelMultiTemplateRuleByProject)2 TemplateOutputMeta (com.webank.wedatasphere.qualitis.rule.entity.TemplateOutputMeta)2 Iterator (java.util.Iterator)2 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)2 Transactional (org.springframework.transaction.annotation.Transactional)2 LocalConfig (com.webank.wedatasphere.qualitis.LocalConfig)1