Search in sources :

Example 21 with RuleDataSource

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

the class OuterExecutionServiceImpl method catchAndSolve.

private void catchAndSolve(Exception e, Integer commentCode, Integer statusCode, List<Rule> rules, Application newApplication) {
    LOGGER.error(e.getMessage(), e);
    newApplication.setApplicationComment(commentCode);
    newApplication.setStatus(statusCode);
    // Record rules info and datasource info.
    StringBuffer info = new StringBuffer();
    newApplication.setFinishTime(ExecutionManagerImpl.PRINT_TIME_FORMAT.format(new Date()));
    for (Rule rule : rules) {
        info.append("Rule[").append(rule.getName()).append("; ");
        info.append("datasource: ").append(rule.getRuleDataSources().stream().filter(ruleDataSource -> StringUtils.isNotBlank(ruleDataSource.getDbName()) && StringUtils.isNotBlank(ruleDataSource.getTableName())).map(ruleDataSource -> ruleDataSource.getDbName() + "." + ruleDataSource.getTableName() + " ").collect(Collectors.joining()));
    }
    newApplication.setExceptionMessage(info.append("]\n").append(ExceptionUtils.getStackTrace(e)).toString());
    if (CollectionUtils.isNotEmpty(rules)) {
        Project currentProject = rules.iterator().next().getProject();
        newApplication.setProjectName(StringUtils.isNotBlank(currentProject.getCnName()) ? currentProject.getCnName() : currentProject.getName());
        newApplication.setRuleGroupName(rules.iterator().next().getRuleGroup().getRuleGroupName());
        newApplication.setRuleDatesource(rules.stream().map(Rule::getRuleDataSources).flatMap(ruleDataSources -> ruleDataSources.stream()).filter(ruleDataSource -> StringUtils.isNotBlank(ruleDataSource.getDbName()) && StringUtils.isNotBlank(ruleDataSource.getTableName())).map(ruleDataSource -> ruleDataSource.getDbName() + "." + ruleDataSource.getTableName() + " ").collect(Collectors.joining()));
    }
    applicationDao.saveApplication(newApplication);
    LOGGER.info("Succeed to set application status to [{}], application_id: [{}]", newApplication.getStatus(), newApplication.getId());
}
Also used : AlarmConfigStatusEnum(com.webank.wedatasphere.qualitis.constant.AlarmConfigStatusEnum) Arrays(java.util.Arrays) StringUtils(org.apache.commons.lang.StringUtils) ClusterInfoNotConfigException(com.webank.wedatasphere.qualitis.exception.ClusterInfoNotConfigException) Autowired(org.springframework.beans.factory.annotation.Autowired) GeneralResponse(com.webank.wedatasphere.qualitis.response.GeneralResponse) AlarmConfig(com.webank.wedatasphere.qualitis.rule.entity.AlarmConfig) ApplicationTaskSimpleResponse(com.webank.wedatasphere.qualitis.response.ApplicationTaskSimpleResponse) DataSourceOverSizeException(com.webank.wedatasphere.qualitis.exception.DataSourceOverSizeException) GroupExecutionRequest(com.webank.wedatasphere.qualitis.request.GroupExecutionRequest) HttpUtils(com.webank.wedatasphere.qualitis.util.HttpUtils) Map(java.util.Map) LocaleParser(com.webank.wedatasphere.qualitis.parser.LocaleParser) JobSubmitException(com.webank.wedatasphere.qualitis.exception.JobSubmitException) ConvertException(com.webank.wedatasphere.qualitis.exception.ConvertException) MonitorManager(com.webank.wedatasphere.qualitis.job.MonitorManager) ProjectUserPermissionEnum(com.webank.wedatasphere.qualitis.project.constant.ProjectUserPermissionEnum) Set(java.util.Set) RuleConstraintEnum(com.webank.wedatasphere.qualitis.metadata.constant.RuleConstraintEnum) UserProxyUser(com.webank.wedatasphere.qualitis.entity.UserProxyUser) TableStat(com.alibaba.druid.stat.TableStat) InvokeTypeEnum(com.webank.wedatasphere.qualitis.constant.InvokeTypeEnum) LeftNullDatasourceException(com.webank.wedatasphere.qualitis.exception.LeftNullDatasourceException) MetaDataClient(com.webank.wedatasphere.qualitis.metadata.client.MetaDataClient) DbType(com.alibaba.druid.DbType) GeneralExecutionRequest(com.webank.wedatasphere.qualitis.request.GeneralExecutionRequest) Project(com.webank.wedatasphere.qualitis.project.entity.Project) TaskStatusEnum(com.webank.wedatasphere.qualitis.constant.TaskStatusEnum) JobKillException(com.webank.wedatasphere.qualitis.exception.JobKillException) RuleDataSourceDao(com.webank.wedatasphere.qualitis.rule.dao.RuleDataSourceDao) Rule(com.webank.wedatasphere.qualitis.rule.entity.Rule) ProjectDao(com.webank.wedatasphere.qualitis.project.dao.ProjectDao) ApplicationTaskResponse(com.webank.wedatasphere.qualitis.response.ApplicationTaskResponse) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) HttpServletRequest(javax.servlet.http.HttpServletRequest) RuleListExecutionRequest(com.webank.wedatasphere.qualitis.request.RuleListExecutionRequest) TaskDao(com.webank.wedatasphere.qualitis.dao.TaskDao) ApplicationResultResponse(com.webank.wedatasphere.qualitis.response.ApplicationResultResponse) Service(org.springframework.stereotype.Service) TaskTypeException(com.webank.wedatasphere.qualitis.exception.TaskTypeException) TaskResult(com.webank.wedatasphere.qualitis.entity.TaskResult) ArgumentException(com.webank.wedatasphere.qualitis.exception.ArgumentException) GetTaskLogRequest(com.webank.wedatasphere.qualitis.request.GetTaskLogRequest) CsTableInfoDetail(com.webank.wedatasphere.qualitis.metadata.response.table.CsTableInfoDetail) MySqlSchemaStatVisitor(com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor) SystemConfigDao(com.webank.wedatasphere.qualitis.dao.SystemConfigDao) ExceptionUtils(org.apache.commons.lang.exception.ExceptionUtils) TaskRuleSimpleRepository(com.webank.wedatasphere.qualitis.dao.repository.TaskRuleSimpleRepository) BothNullDatasourceException(com.webank.wedatasphere.qualitis.exception.BothNullDatasourceException) IOException(java.io.IOException) TaskRuleSimple(com.webank.wedatasphere.qualitis.entity.TaskRuleSimple) DataInfo(com.webank.wedatasphere.qualitis.metadata.response.DataInfo) SystemKeyConfig(com.webank.wedatasphere.qualitis.config.SystemKeyConfig) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement) UserDao(com.webank.wedatasphere.qualitis.dao.UserDao) UnitTransfer(com.webank.wedatasphere.qualitis.rule.util.UnitTransfer) LogResult(com.webank.wedatasphere.qualitis.bean.LogResult) TaskDataSource(com.webank.wedatasphere.qualitis.entity.TaskDataSource) Date(java.util.Date) LinkisConfig(com.webank.wedatasphere.qualitis.config.LinkisConfig) LoggerFactory(org.slf4j.LoggerFactory) GetUserColumnByCsRequest(com.webank.wedatasphere.qualitis.metadata.request.GetUserColumnByCsRequest) Application(com.webank.wedatasphere.qualitis.entity.Application) TaskNotExistException(com.webank.wedatasphere.qualitis.exception.TaskNotExistException) SemanticException(org.apache.hadoop.hive.ql.parse.SemanticException) ProjectUserDao(com.webank.wedatasphere.qualitis.project.dao.ProjectUserDao) DataSourceExecutionRequest(com.webank.wedatasphere.qualitis.request.DataSourceExecutionRequest) PermissionDeniedRequestException(com.webank.wedatasphere.qualitis.exception.PermissionDeniedRequestException) ApplicationCommentEnum(com.webank.wedatasphere.qualitis.constant.ApplicationCommentEnum) EventTypeEnum(com.webank.wedatasphere.qualitis.project.constant.EventTypeEnum) RuleDataSource(com.webank.wedatasphere.qualitis.rule.entity.RuleDataSource) DateExprReplaceUtil(com.webank.wedatasphere.qualitis.util.DateExprReplaceUtil) ClusterInfoDao(com.webank.wedatasphere.qualitis.dao.ClusterInfoDao) ParseException(org.apache.hadoop.hive.ql.parse.ParseException) Task(com.webank.wedatasphere.qualitis.entity.Task) OuterExecutionService(com.webank.wedatasphere.qualitis.service.OuterExecutionService) RuleGroupDao(com.webank.wedatasphere.qualitis.rule.dao.RuleGroupDao) TaskRuleAlarmConfig(com.webank.wedatasphere.qualitis.entity.TaskRuleAlarmConfig) SystemConfigException(com.webank.wedatasphere.qualitis.exception.SystemConfigException) ProjectService(com.webank.wedatasphere.qualitis.project.service.ProjectService) RuleVariableNotSupportException(com.webank.wedatasphere.qualitis.exception.RuleVariableNotSupportException) ProjectEventService(com.webank.wedatasphere.qualitis.project.service.ProjectEventService) ExecutionManager(com.webank.wedatasphere.qualitis.submitter.ExecutionManager) PartitionStatisticsInfo(com.webank.wedatasphere.qualitis.metadata.response.table.PartitionStatisticsInfo) Context(javax.ws.rs.core.Context) UuidGenerator(com.webank.wedatasphere.qualitis.util.UuidGenerator) Collectors(java.util.stream.Collectors) RuleDataSourceMapping(com.webank.wedatasphere.qualitis.rule.entity.RuleDataSourceMapping) MetaDataAcquireFailedException(com.webank.wedatasphere.qualitis.metadata.exception.MetaDataAcquireFailedException) ApplicationProjectResponse(com.webank.wedatasphere.qualitis.response.ApplicationProjectResponse) ExecutionManagerImpl(com.webank.wedatasphere.qualitis.submitter.impl.ExecutionManagerImpl) List(java.util.List) ClusterInfo(com.webank.wedatasphere.qualitis.entity.ClusterInfo) JdbcConstants(com.alibaba.druid.util.JdbcConstants) ApplicationSubmitRequest(com.webank.wedatasphere.qualitis.request.ApplicationSubmitRequest) SystemConfig(com.webank.wedatasphere.qualitis.entity.SystemConfig) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) LogPartialException(com.webank.wedatasphere.qualitis.exception.LogPartialException) BeanUtils(org.springframework.beans.BeanUtils) RuleGroup(com.webank.wedatasphere.qualitis.rule.entity.RuleGroup) SpecCharEnum(com.webank.wedatasphere.qualitis.constant.SpecCharEnum) HashMap(java.util.HashMap) HashSet(java.util.HashSet) User(com.webank.wedatasphere.qualitis.entity.User) CollectionUtils(org.apache.commons.collections.CollectionUtils) Propagation(org.springframework.transaction.annotation.Propagation) Name(com.alibaba.druid.stat.TableStat.Name) TaskSubmitResult(com.webank.wedatasphere.qualitis.bean.TaskSubmitResult) DataQualityTaskException(com.webank.wedatasphere.qualitis.exception.DataQualityTaskException) ApplicationStatusEnum(com.webank.wedatasphere.qualitis.constant.ApplicationStatusEnum) TaskDataSourceRepository(com.webank.wedatasphere.qualitis.dao.repository.TaskDataSourceRepository) GetUserTableByCsIdRequest(com.webank.wedatasphere.qualitis.metadata.request.GetUserTableByCsIdRequest) RuleVariableNotFoundException(com.webank.wedatasphere.qualitis.exception.RuleVariableNotFoundException) DataSourceMoveException(com.webank.wedatasphere.qualitis.exception.DataSourceMoveException) SQLUtils(com.alibaba.druid.sql.SQLUtils) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) RuleMetric(com.webank.wedatasphere.qualitis.entity.RuleMetric) ResourceAccessException(org.springframework.web.client.ResourceAccessException) ColumnInfoDetail(com.webank.wedatasphere.qualitis.metadata.response.column.ColumnInfoDetail) FastDateFormat(org.apache.commons.lang3.time.FastDateFormat) TableStatisticsInfo(com.webank.wedatasphere.qualitis.metadata.response.table.TableStatisticsInfo) RuleTypeEnum(com.webank.wedatasphere.qualitis.rule.constant.RuleTypeEnum) ProjectExecutionRequest(com.webank.wedatasphere.qualitis.request.ProjectExecutionRequest) RightNullDatasourceException(com.webank.wedatasphere.qualitis.exception.RightNullDatasourceException) RuleDao(com.webank.wedatasphere.qualitis.rule.dao.RuleDao) ApplicationDao(com.webank.wedatasphere.qualitis.dao.ApplicationDao) NoPartitionException(com.webank.wedatasphere.qualitis.exception.NoPartitionException) TaskResultDao(com.webank.wedatasphere.qualitis.dao.TaskResultDao) HiveSqlParser(com.webank.wedatasphere.qualitis.parser.HiveSqlParser) Transactional(org.springframework.transaction.annotation.Transactional) Project(com.webank.wedatasphere.qualitis.project.entity.Project) Rule(com.webank.wedatasphere.qualitis.rule.entity.Rule) Date(java.util.Date)

Example 22 with RuleDataSource

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

the class RuleBatchServiceImpl method getMultiTemplateRule.

@Override
public List<ExcelMultiTemplateRuleByProject> getMultiTemplateRule(Iterable<Rule> rules, String localeStr) {
    List<ExcelMultiTemplateRuleByProject> lines = new ArrayList<>();
    for (Rule rule : rules) {
        if (!rule.getRuleType().equals(RuleTypeEnum.MULTI_TEMPLATE_RULE.getCode())) {
            continue;
        }
        ExcelMultiTemplateRuleByProject ruleLinePrefix = new ExcelMultiTemplateRuleByProject();
        // Rule basic info.
        String clusterName = rule.getRuleDataSources().iterator().next().getClusterName();
        basicInfoToExcel(ruleLinePrefix, rule, clusterName);
        List<RuleVariable> filterRuleVariable = rule.getRuleVariables().stream().filter(ruleVariable -> ruleVariable.getTemplateMidTableInputMeta().getInputType().equals(TemplateInputTypeEnum.CONDITION.getCode())).collect(Collectors.toList());
        if (filterRuleVariable != null && filterRuleVariable.size() != 0) {
            ruleLinePrefix.setWhereFilter(filterRuleVariable.iterator().next().getValue());
        }
        Boolean sourceAddedFlag = false;
        Boolean targetAddedFlag = false;
        lines.add(ruleLinePrefix);
        ExcelMultiTemplateRuleByProject datasourceExcelRule = new ExcelMultiTemplateRuleByProject(rule.getName());
        for (RuleDataSource ruleDataSource : rule.getRuleDataSources()) {
            String databaseName = ruleDataSource.getDbName();
            String tableName = ruleDataSource.getTableName();
            String filter = ruleDataSource.getFilter();
            Integer datasourceIndex = ruleDataSource.getDatasourceIndex();
            if (datasourceIndex == 0) {
                datasourceExcelRule.setLeftDbName(databaseName);
                datasourceExcelRule.setLeftTableName(tableName);
                datasourceExcelRule.setLeftFilter(filter);
                datasourceExcelRule.setLeftProxyUser(ruleDataSource.getProxyUser());
                if (ruleDataSource.getLinkisDataSourceId() != null) {
                    datasourceExcelRule.setLeftLinkisDataSourceType(TemplateDataSourceTypeEnum.getMessage(ruleDataSource.getDatasourceType()));
                    datasourceExcelRule.setLeftLinkisDataSourceId(String.valueOf(ruleDataSource.getLinkisDataSourceId()));
                    datasourceExcelRule.setLeftLinkisDataSourceName(ruleDataSource.getLinkisDataSourceName());
                }
                sourceAddedFlag = true;
            } else {
                datasourceExcelRule.setRightDbName(databaseName);
                datasourceExcelRule.setRightTableName(tableName);
                datasourceExcelRule.setRightFilter(filter);
                datasourceExcelRule.setRightProxyUser(ruleDataSource.getProxyUser());
                if (ruleDataSource.getLinkisDataSourceId() != null) {
                    datasourceExcelRule.setRightLlinkisDataSourceType(TemplateDataSourceTypeEnum.getMessage(ruleDataSource.getDatasourceType()));
                    datasourceExcelRule.setRightLinkisDataSourceId(String.valueOf(ruleDataSource.getLinkisDataSourceId()));
                    datasourceExcelRule.setRightLlinkisDataSourceName(ruleDataSource.getLinkisDataSourceName());
                }
                targetAddedFlag = true;
            }
            if (sourceAddedFlag && targetAddedFlag) {
                LOGGER.info("Collect excel line: {}", datasourceExcelRule);
                lines.add(datasourceExcelRule);
            }
        }
        // Get mapping and alarm info to excel.
        getMappingInfoAndAlarm(rule.getRuleDataSourceMappings(), rule.getAlarmConfigs(), lines, ruleLinePrefix, localeStr);
    }
    return lines;
}
Also used : StringUtils(org.apache.commons.lang.StringUtils) ClusterInfoNotConfigException(com.webank.wedatasphere.qualitis.exception.ClusterInfoNotConfigException) FormDataContentDisposition(org.glassfish.jersey.media.multipart.FormDataContentDisposition) Autowired(org.springframework.beans.factory.annotation.Autowired) ExcelRuleListener(com.webank.wedatasphere.qualitis.rule.excel.ExcelRuleListener) GeneralResponse(com.webank.wedatasphere.qualitis.response.GeneralResponse) AlarmConfig(com.webank.wedatasphere.qualitis.rule.entity.AlarmConfig) RuleMetricDao(com.webank.wedatasphere.qualitis.dao.RuleMetricDao) HttpUtils(com.webank.wedatasphere.qualitis.util.HttpUtils) Map(java.util.Map) LocaleParser(com.webank.wedatasphere.qualitis.parser.LocaleParser) MultiDataSourceConfigRequest(com.webank.wedatasphere.qualitis.rule.request.multi.MultiDataSourceConfigRequest) ModifyCustomRuleRequest(com.webank.wedatasphere.qualitis.rule.request.ModifyCustomRuleRequest) 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) ExcelCustomRuleByProject(com.webank.wedatasphere.qualitis.project.excel.ExcelCustomRuleByProject) ExcelReader(com.alibaba.excel.ExcelReader) ProjectUserPermissionEnum(com.webank.wedatasphere.qualitis.project.constant.ProjectUserPermissionEnum) Set(java.util.Set) DataSourceRequest(com.webank.wedatasphere.qualitis.rule.request.DataSourceRequest) FileAlarmConfigRequest(com.webank.wedatasphere.qualitis.rule.request.FileAlarmConfigRequest) TemplateArgumentRequest(com.webank.wedatasphere.qualitis.rule.request.TemplateArgumentRequest) Project(com.webank.wedatasphere.qualitis.project.entity.Project) FastDateFormat(org.apache.commons.lang.time.FastDateFormat) Rule(com.webank.wedatasphere.qualitis.rule.entity.Rule) TemplateMidTableInputMetaDao(com.webank.wedatasphere.qualitis.rule.dao.TemplateMidTableInputMetaDao) ProjectDao(com.webank.wedatasphere.qualitis.project.dao.ProjectDao) ArrayList(java.util.ArrayList) ExcelWriter(com.alibaba.excel.ExcelWriter) HttpServletRequest(javax.servlet.http.HttpServletRequest) CheckTemplateEnum(com.webank.wedatasphere.qualitis.rule.constant.CheckTemplateEnum) Service(org.springframework.stereotype.Service) RuleBatchService(com.webank.wedatasphere.qualitis.rule.service.RuleBatchService) 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) UserDao(com.webank.wedatasphere.qualitis.dao.UserDao) ModifyFileRuleRequest(com.webank.wedatasphere.qualitis.rule.request.ModifyFileRuleRequest) WriteExcelException(com.webank.wedatasphere.qualitis.rule.exception.WriteExcelException) Date(java.util.Date) LoggerFactory(org.slf4j.LoggerFactory) TaskNotExistException(com.webank.wedatasphere.qualitis.exception.TaskNotExistException) TemplateMidTableUtil(com.webank.wedatasphere.qualitis.rule.util.TemplateMidTableUtil) SemanticException(org.apache.hadoop.hive.ql.parse.SemanticException) 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) AddProjectRequest(com.webank.wedatasphere.qualitis.project.request.AddProjectRequest) ProjectService(com.webank.wedatasphere.qualitis.project.service.ProjectService) AddCustomRuleRequest(com.webank.wedatasphere.qualitis.rule.request.AddCustomRuleRequest) AlarmConfigRequest(com.webank.wedatasphere.qualitis.rule.request.AlarmConfigRequest) ProjectEventService(com.webank.wedatasphere.qualitis.project.service.ProjectEventService) ExcelMultiTemplateRuleByProject(com.webank.wedatasphere.qualitis.project.excel.ExcelMultiTemplateRuleByProject) TemplateOutputMetaDao(com.webank.wedatasphere.qualitis.rule.dao.TemplateOutputMetaDao) MappingOperationEnum(com.webank.wedatasphere.qualitis.rule.constant.MappingOperationEnum) Context(javax.ws.rs.core.Context) InputActionStepEnum(com.webank.wedatasphere.qualitis.rule.constant.InputActionStepEnum) CustomRuleService(com.webank.wedatasphere.qualitis.rule.service.CustomRuleService) Collectors(java.util.stream.Collectors) RuleDataSourceMapping(com.webank.wedatasphere.qualitis.rule.entity.RuleDataSourceMapping) MetaDataAcquireFailedException(com.webank.wedatasphere.qualitis.metadata.exception.MetaDataAcquireFailedException) ExcelTypeEnum(com.alibaba.excel.support.ExcelTypeEnum) RuleService(com.webank.wedatasphere.qualitis.rule.service.RuleService) List(java.util.List) Sheet(com.alibaba.excel.metadata.Sheet) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) ExcelTemplateRuleByProject(com.webank.wedatasphere.qualitis.project.excel.ExcelTemplateRuleByProject) BeanUtils(org.springframework.beans.BeanUtils) RuleGroup(com.webank.wedatasphere.qualitis.rule.entity.RuleGroup) SpecCharEnum(com.webank.wedatasphere.qualitis.constant.SpecCharEnum) RuleVariable(com.webank.wedatasphere.qualitis.rule.entity.RuleVariable) DownloadRuleRequest(com.webank.wedatasphere.qualitis.rule.request.DownloadRuleRequest) HashMap(java.util.HashMap) AddFileRuleRequest(com.webank.wedatasphere.qualitis.rule.request.AddFileRuleRequest) 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) OutputStream(java.io.OutputStream) 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) HttpServletResponse(javax.servlet.http.HttpServletResponse) FunctionTypeEnum(com.webank.wedatasphere.qualitis.rule.constant.FunctionTypeEnum) ModifyMultiSourceRequest(com.webank.wedatasphere.qualitis.rule.request.multi.ModifyMultiSourceRequest) FileOutputNameEnum(com.webank.wedatasphere.qualitis.rule.constant.FileOutputNameEnum) RuleTypeEnum(com.webank.wedatasphere.qualitis.rule.constant.RuleTypeEnum) URLEncoder(java.net.URLEncoder) ExcelSheetName(com.webank.wedatasphere.qualitis.project.constant.ExcelSheetName) 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) StringEscapeUtils(org.apache.commons.lang.StringEscapeUtils) InputStream(java.io.InputStream) Transactional(org.springframework.transaction.annotation.Transactional) ExcelMultiTemplateRuleByProject(com.webank.wedatasphere.qualitis.project.excel.ExcelMultiTemplateRuleByProject) RuleDataSource(com.webank.wedatasphere.qualitis.rule.entity.RuleDataSource) ArrayList(java.util.ArrayList) Rule(com.webank.wedatasphere.qualitis.rule.entity.Rule) RuleVariable(com.webank.wedatasphere.qualitis.rule.entity.RuleVariable)

Example 23 with RuleDataSource

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

the class RuleBatchServiceImpl method getTemplateRule.

@Override
public List<ExcelTemplateRuleByProject> getTemplateRule(Iterable<Rule> rules, String localeStr) {
    List<ExcelTemplateRuleByProject> lines = new ArrayList<>();
    for (Rule rule : rules) {
        if (!rule.getRuleType().equals(RuleTypeEnum.SINGLE_TEMPLATE_RULE.getCode())) {
            continue;
        }
        // Rule basic info.
        ExcelTemplateRuleByProject ruleLinePrefix = new ExcelTemplateRuleByProject();
        basicInfoToExcel(ruleLinePrefix, rule);
        lines.add(ruleLinePrefix);
        for (RuleDataSource ruleDataSource : rule.getRuleDataSources()) {
            String clusterName = ruleDataSource.getClusterName();
            String databaseName = ruleDataSource.getDbName();
            String tableName = ruleDataSource.getTableName();
            String columnName = ruleDataSource.getColName();
            String filter = ruleDataSource.getFilter();
            ExcelTemplateRuleByProject tmp = new ExcelTemplateRuleByProject(rule.getName());
            tmp.setBlackColName(ruleDataSource.getBlackColName());
            tmp.setProxyUser(ruleDataSource.getProxyUser());
            tmp.setFilter(filter);
            tmp.setCluster(clusterName);
            tmp.setDbName(databaseName);
            tmp.setTableName(tableName);
            tmp.setColumnNames(columnName);
            if (ruleDataSource.getLinkisDataSourceId() != null) {
                tmp.setLinkisDataSourceName(ruleDataSource.getLinkisDataSourceName());
                tmp.setLinkisDataSourceId(String.valueOf(ruleDataSource.getLinkisDataSourceId()));
                tmp.setLinkisDataSourceType(TemplateDataSourceTypeEnum.getMessage(ruleDataSource.getDatasourceType()));
            }
            LOGGER.info("Collect excel line: {}", tmp);
            lines.add(tmp);
        }
        for (TemplateMidTableInputMeta templateMidTableInputMeta : rule.getTemplate().getTemplateMidTableInputMetas()) {
            if (TemplateMidTableUtil.shouldResponse(templateMidTableInputMeta)) {
                for (RuleVariable ruleVariable : rule.getRuleVariables()) {
                    if (ruleVariable.getTemplateMidTableInputMeta().equals(templateMidTableInputMeta)) {
                        ExcelTemplateRuleByProject tmp = new ExcelTemplateRuleByProject(rule.getName());
                        String key = templateMidTableInputMeta.getName();
                        String value = StringEscapeUtils.unescapeJava(ruleVariable.getValue());
                        if (templateMidTableInputMeta.getInputType().equals(TemplateInputTypeEnum.REGEXP.getCode())) {
                            if (templateMidTableInputMeta.getRegexpType() != null) {
                                value = ruleVariable.getOriginValue();
                            }
                        }
                        tmp.setArgumentKey(key);
                        tmp.setArgumentValue(value);
                        LOGGER.info("Collect excel line: {}", tmp);
                        lines.add(tmp);
                    }
                }
            }
        }
        alarmConfigsToExcel(rule, lines, localeStr);
    }
    return lines;
}
Also used : RuleDataSource(com.webank.wedatasphere.qualitis.rule.entity.RuleDataSource) ArrayList(java.util.ArrayList) Rule(com.webank.wedatasphere.qualitis.rule.entity.Rule) TemplateMidTableInputMeta(com.webank.wedatasphere.qualitis.rule.entity.TemplateMidTableInputMeta) ExcelTemplateRuleByProject(com.webank.wedatasphere.qualitis.project.excel.ExcelTemplateRuleByProject) RuleVariable(com.webank.wedatasphere.qualitis.rule.entity.RuleVariable)

Example 24 with RuleDataSource

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

the class RuleDataSourceServiceImpl method checkAndSaveRuleDataSource.

@Override
@Transactional(rollbackFor = { RuntimeException.class, UnExpectedRequestException.class })
public List<RuleDataSource> checkAndSaveRuleDataSource(List<DataSourceRequest> requests, Rule rule, boolean cs, String loginUser) throws UnExpectedRequestException {
    List<RuleDataSource> ruleDataSources = new ArrayList<>();
    for (DataSourceRequest request : requests) {
        RuleDataSource newRuleDataSource = new RuleDataSource();
        // Check Arguments
        DataSourceRequest.checkRequest(request, cs, false);
        if (StringUtils.isNotBlank(request.getLinkisDataSourceType())) {
            newRuleDataSource.setDatasourceType(TemplateDataSourceTypeEnum.getCode(request.getLinkisDataSourceType()));
            newRuleDataSource.setLinkisDataSourceVersionId(request.getLinkisDataSourceVersionId());
            newRuleDataSource.setLinkisDataSourceName(request.getLinkisDataSourceName());
            newRuleDataSource.setLinkisDataSourceId(request.getLinkisDataSourceId());
        }
        newRuleDataSource.setClusterName(request.getClusterName());
        newRuleDataSource.setTableName(request.getTableName());
        newRuleDataSource.setDbName(request.getDbName());
        newRuleDataSource.setFilter(request.getFilter());
        // Saved as: field1: type1, field2: type2
        newRuleDataSource.setBlackColName(request.getBlackList());
        newRuleDataSource.setProxyUser(request.getProxyUser());
        String joinCols = joinColNames(request.getColNames());
        newRuleDataSource.setColName(joinCols);
        newRuleDataSource.setRule(rule);
        if (rule.getTemplate().getTemplateType().equals(RuleTemplateTypeEnum.MULTI_SOURCE_TEMPLATE.getCode())) {
            newRuleDataSource.setDatasourceIndex(request.getDatasourceIndex());
        }
        newRuleDataSource.setProjectId(rule.getProject().getId());
        ruleDataSources.add(newRuleDataSource);
        LOGGER.info("Succeed to save rule_datasource. rule_datasource: {}", newRuleDataSource);
    }
    LOGGER.info("Succeed to save all rule_datasource.");
    return ruleDatasourceDao.saveAllRuleDataSource(ruleDataSources);
}
Also used : DataSourceRequest(com.webank.wedatasphere.qualitis.rule.request.DataSourceRequest) RuleDataSource(com.webank.wedatasphere.qualitis.rule.entity.RuleDataSource) ArrayList(java.util.ArrayList) Transactional(org.springframework.transaction.annotation.Transactional)

Example 25 with RuleDataSource

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

the class RuleDataSourceServiceImpl method updateRuleDataSourceCount.

@Override
public void updateRuleDataSourceCount(Rule ruleInDb, Integer varyAmount) {
    Set<RuleDataSource> ruleDataSources = ruleInDb.getRuleDataSources();
    if (ruleDataSources == null || ruleDataSources.isEmpty()) {
        LOGGER.error("Rule does not have ruledatasource.");
        return;
    }
    for (RuleDataSource ruleDataSource : ruleDataSources) {
        StringBuffer datasourceName = new StringBuffer();
        if (StringUtils.isEmpty(ruleDataSource.getTableName()) || StringUtils.isEmpty(ruleDataSource.getColName())) {
            continue;
        }
        if (StringUtils.isNotBlank(ruleDataSource.getColName())) {
            String[] cols = ruleDataSource.getColName().split(SpecCharEnum.VERTICAL_BAR.getValue());
            for (String col : cols) {
                datasourceName.append(ruleDataSource.getClusterName()).append("-").append(ruleDataSource.getDbName()).append("-").append(ruleDataSource.getTableName()).append("-").append(col);
                Long userId = userDao.findByUsername(ruleInDb.getCreateUser()).getId();
                RuleDataSourceCount ruleDataSourceCount = ruleDataSourceCountRepository.findByDatasourceNameAndUserId(datasourceName.toString(), userId);
                if (ruleDataSourceCount == null) {
                    if (varyAmount > 0) {
                        ruleDataSourceCount = new RuleDataSourceCount(datasourceName.toString(), userId);
                        ruleDataSourceCountRepository.save(ruleDataSourceCount);
                    } else {
                        LOGGER.error("Rule datasource ddes not have related rules.");
                    }
                } else {
                    ruleDataSourceCount.setDatasourceCount(ruleDataSourceCount.getDatasourceCount() + varyAmount);
                    ruleDataSourceCountRepository.save(ruleDataSourceCount);
                    LOGGER.info("Rule [{}] count of datasource is: {}", ruleInDb.getName(), ruleDataSourceCount.getDatasourceCount());
                }
                datasourceName.delete(0, datasourceName.length());
            }
        }
    }
}
Also used : RuleDataSource(com.webank.wedatasphere.qualitis.rule.entity.RuleDataSource) RuleDataSourceCount(com.webank.wedatasphere.qualitis.rule.entity.RuleDataSourceCount)

Aggregations

RuleDataSource (com.webank.wedatasphere.qualitis.rule.entity.RuleDataSource)37 ArrayList (java.util.ArrayList)29 Rule (com.webank.wedatasphere.qualitis.rule.entity.Rule)21 AlarmConfig (com.webank.wedatasphere.qualitis.rule.entity.AlarmConfig)18 UnExpectedRequestException (com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException)14 Template (com.webank.wedatasphere.qualitis.rule.entity.Template)11 HashSet (java.util.HashSet)11 List (java.util.List)10 Set (java.util.Set)10 Transactional (org.springframework.transaction.annotation.Transactional)10 RuleMetric (com.webank.wedatasphere.qualitis.entity.RuleMetric)9 Project (com.webank.wedatasphere.qualitis.project.entity.Project)9 GeneralResponse (com.webank.wedatasphere.qualitis.response.GeneralResponse)9 RuleDataSourceMapping (com.webank.wedatasphere.qualitis.rule.entity.RuleDataSourceMapping)9 Date (java.util.Date)9 HashMap (java.util.HashMap)9 RuleVariable (com.webank.wedatasphere.qualitis.rule.entity.RuleVariable)8 Map (java.util.Map)8 SpecCharEnum (com.webank.wedatasphere.qualitis.constant.SpecCharEnum)6 MetaDataAcquireFailedException (com.webank.wedatasphere.qualitis.metadata.exception.MetaDataAcquireFailedException)6