Search in sources :

Example 11 with RuleDataSource

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

the class RuleNodeServiceImpl method constructFileRequest.

private AddFileRuleRequest constructFileRequest(Rule rule, RuleGroup ruleGroup) {
    AddFileRuleRequest addFileRuleRequest = new AddFileRuleRequest();
    String newVersion = ruleGroup.getVersion();
    if (StringUtils.isEmpty(newVersion)) {
        String newRuleName = rule.getName() + "_copy_" + ruleGroup.getId();
        LOGGER.info("File rule start to be copied. Copied rule name: " + newRuleName);
        addFileRuleRequest.setRuleName(newRuleName);
        if (StringUtils.isNotBlank(rule.getCnName())) {
            addFileRuleRequest.setRuleCnName(rule.getCnName() + "_副本");
        }
    } else {
        String oldVersion = rule.getRuleGroup().getVersion();
        LOGGER.info("File rule start to be copied. Copied rule name: " + rule.getName() + "_" + ruleGroup.getVersion());
        if (StringUtils.isNotBlank(oldVersion) && rule.getName().endsWith(oldVersion)) {
            addFileRuleRequest.setRuleName(rule.getName().replace(oldVersion, newVersion));
            if (StringUtils.isNotBlank(rule.getCnName())) {
                addFileRuleRequest.setRuleCnName(rule.getCnName().replace(oldVersion, newVersion));
            }
        } else {
            addFileRuleRequest.setRuleName(rule.getName() + "_" + newVersion);
            if (StringUtils.isNotBlank(rule.getCnName())) {
                addFileRuleRequest.setRuleCnName(rule.getCnName() + "_" + newVersion);
            }
        }
    }
    String ruleDetail = rule.getDetail();
    addFileRuleRequest.setRuleDetail(ruleDetail);
    addFileRuleRequest.setAbortOnFailure(rule.getAbortOnFailure());
    addFileRuleRequest.setCsId(rule.getCsId());
    addFileRuleRequest.setRuleGroupId(ruleGroup.getId());
    addFileRuleRequest.setProjectId(ruleGroup.getProjectId());
    addFileRuleRequest.setAbortOnFailure(rule.getAbortOnFailure());
    for (RuleDataSource ruleDataSource : rule.getRuleDataSources()) {
        DataSourceRequest dataSourceRequest = new DataSourceRequest();
        String clusterName = ruleDataSource.getClusterName();
        String databaseName = ruleDataSource.getDbName();
        String tableName = ruleDataSource.getTableName();
        String filter = ruleDataSource.getFilter();
        dataSourceRequest.setClusterName(clusterName);
        dataSourceRequest.setDbName(databaseName);
        dataSourceRequest.setTableName(tableName);
        dataSourceRequest.setFilter(filter);
        addFileRuleRequest.setDatasource(dataSourceRequest);
        break;
    }
    List<FileAlarmConfigRequest> alarmVariable = new ArrayList<>();
    for (AlarmConfig alarmConfig : rule.getAlarmConfigs()) {
        FileAlarmConfigRequest fileAlarmConfigRequest = new FileAlarmConfigRequest();
        Double threshold = alarmConfig.getThreshold();
        Integer unit = alarmConfig.getFileOutputUnit();
        Integer alarmCompareType = alarmConfig.getCompareType();
        Integer alarmOutputName = alarmConfig.getFileOutputName();
        Integer checkTemplateName = alarmConfig.getCheckTemplate();
        fileAlarmConfigRequest.setFileOutputUnit(unit);
        fileAlarmConfigRequest.setCompareType(alarmCompareType);
        fileAlarmConfigRequest.setFileOutputName(alarmOutputName);
        fileAlarmConfigRequest.setCheckTemplate(checkTemplateName);
        fileAlarmConfigRequest.setThreshold(threshold);
        RuleMetric ruleMetric = alarmConfig.getRuleMetric();
        // Recod rule metric info (unique code).
        if (ruleMetric != null) {
            String enCode = ruleMetric.getEnCode();
            fileAlarmConfigRequest.setRuleMetricEnCode(enCode);
            fileAlarmConfigRequest.setUploadAbnormalValue(alarmConfig.getUploadAbnormalValue());
            fileAlarmConfigRequest.setUploadRuleMetricValue(alarmConfig.getUploadRuleMetricValue());
        }
        fileAlarmConfigRequest.setDeleteFailCheckResult(alarmConfig.getDeleteFailCheckResult());
        alarmVariable.add(fileAlarmConfigRequest);
    }
    addFileRuleRequest.setAlarm(true);
    addFileRuleRequest.setAlarmVariable(alarmVariable);
    return addFileRuleRequest;
}
Also used : DataSourceRequest(com.webank.wedatasphere.qualitis.rule.request.DataSourceRequest) RuleMetric(com.webank.wedatasphere.qualitis.entity.RuleMetric) RuleDataSource(com.webank.wedatasphere.qualitis.rule.entity.RuleDataSource) AddFileRuleRequest(com.webank.wedatasphere.qualitis.rule.request.AddFileRuleRequest) ArrayList(java.util.ArrayList) FileAlarmConfigRequest(com.webank.wedatasphere.qualitis.rule.request.FileAlarmConfigRequest) AlarmConfig(com.webank.wedatasphere.qualitis.rule.entity.AlarmConfig)

Example 12 with RuleDataSource

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

the class RuleNodeServiceImpl method updateImportedFileRule.

private void updateImportedFileRule(Rule rule, Rule ruleInDb, RuleGroup ruleGroup, Set<AlarmConfig> alarmConfigs, Set<RuleDataSource> ruleDataSources) {
    ruleInDb.setRuleGroup(ruleGroup);
    ruleInDb.setAlarm(rule.getAlarm());
    ruleInDb.setAbortOnFailure(rule.getAbortOnFailure());
    alarmConfigService.deleteByRule(ruleInDb);
    LOGGER.info("Succeed to delete all alarm_config. rule_id: {}", ruleInDb.getId());
    ruleDataSourceService.deleteByRule(ruleInDb);
    LOGGER.info("Succeed to delete all rule_dataSources. rule_id: {}", ruleInDb.getId());
    Rule updateRule = ruleDao.saveRule(ruleInDb);
    // Save file alarmconfig
    List<AlarmConfig> alarmConfigList = new ArrayList<>();
    for (AlarmConfig alarmConfig : alarmConfigs) {
        alarmConfig.setRule(updateRule);
        alarmConfigList.add(alarmConfig);
    }
    // Save file datasource
    List<RuleDataSource> ruleDataSourceList = new ArrayList<>();
    for (RuleDataSource ruleDataSource : ruleDataSources) {
        ruleDataSource.setProjectId(updateRule.getId());
        ruleDataSource.setRule(updateRule);
        ruleDataSourceList.add(ruleDataSource);
    }
    updateRule.setAlarmConfigs(new HashSet<>(alarmConfigDao.saveAllAlarmConfig(alarmConfigList)));
    updateRule.setRuleDataSources(new HashSet<>(ruleDataSourceDao.saveAllRuleDataSource(ruleDataSourceList)));
}
Also used : RuleDataSource(com.webank.wedatasphere.qualitis.rule.entity.RuleDataSource) ArrayList(java.util.ArrayList) Rule(com.webank.wedatasphere.qualitis.rule.entity.Rule) AlarmConfig(com.webank.wedatasphere.qualitis.rule.entity.AlarmConfig)

Example 13 with RuleDataSource

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

the class OuterExecutionServiceImpl method customReSaveDateSource.

private void customReSaveDateSource(Rule currentRule, Map<String, String> execParams, String clusterName, Date date) throws UnExpectedRequestException, SemanticException, ParseException {
    String midTableAction = currentRule.getTemplate().getMidTableAction();
    if (StringUtils.isNotBlank(currentRule.getWhereContent())) {
        midTableAction = midTableAction.replace("${filter}", currentRule.getWhereContent());
    }
    // Replace placeholder with key and value for sql parse check.
    for (String key : execParams.keySet()) {
        midTableAction = midTableAction.replace("${" + key + "}", execParams.get(key));
    }
    midTableAction = DateExprReplaceUtil.replaceRunDate(date, midTableAction);
    // Save datasource in first execution(Only possible data sources related to fps).
    boolean firstExecution = CollectionUtils.isEmpty(currentRule.getRuleDataSources().stream().filter(ruleDataSource -> !ORIGINAL_INDEX.equals(ruleDataSource.getDatasourceIndex())).collect(Collectors.toSet()));
    if (!firstExecution) {
        return;
    }
    RuleDataSource originalRuleDataSource = currentRule.getRuleDataSources().stream().filter(ruleDataSource -> ORIGINAL_INDEX.equals(ruleDataSource.getDatasourceIndex())).iterator().next();
    if (StringUtils.isEmpty(clusterName)) {
        clusterName = originalRuleDataSource.getClusterName();
    }
    Map<String, List<String>> dbAndTables = new HashMap<>(2);
    // 0.16.0 for mysql oracle, hive parse, use druid.
    LOGGER.info("Parse sql: " + midTableAction);
    List<RuleMetric> ruleMetrics = currentRule.getAlarmConfigs().stream().map(AlarmConfig::getRuleMetric).distinct().collect(Collectors.toList());
    Set<String> ruleMetricNames = ruleMetrics.stream().map(RuleMetric::getName).collect(Collectors.toSet());
    for (String ruleMetricName : ruleMetricNames) {
        String cleanRuleMetricName = ruleMetricName.replace("-", "_");
        midTableAction = midTableAction.replace(ruleMetricName, cleanRuleMetricName);
    }
    LOGGER.info("Parse sql after replace rule metric names: " + midTableAction);
    if (originalRuleDataSource.getLinkisDataSourceId() != null) {
        DbType dbType = JdbcConstants.MYSQL;
        MySqlSchemaStatVisitor visitor = new MySqlSchemaStatVisitor();
        List<SQLStatement> stmtList = SQLUtils.parseStatements(midTableAction, dbType);
        for (int i = 0; i < stmtList.size(); i++) {
            SQLStatement stmt = stmtList.get(i);
            stmt.accept(visitor);
            Map<Name, TableStat> tableStatMap = visitor.getTables();
            dbAndTables = toDbAndTables(dbAndTables, tableStatMap);
        }
    } else {
        HiveSqlParser hiveSqlParser = new HiveSqlParser();
        dbAndTables = hiveSqlParser.checkSelectSqlAndGetDbAndTable(midTableAction);
    }
    LOGGER.info("Db and tables: " + dbAndTables.toString());
    for (String db : dbAndTables.keySet()) {
        List<RuleDataSource> ruleDataSources = new ArrayList<>();
        for (String table : dbAndTables.get(db)) {
            RuleDataSource ruleDataSource = new RuleDataSource();
            ruleDataSource.setClusterName(clusterName);
            ruleDataSource.setProjectId(currentRule.getProject().getId());
            ruleDataSource.setDbName(db.toLowerCase());
            ruleDataSource.setRule(currentRule);
            ruleDataSource.setTableName(table);
            ruleDataSource.setProxyUser(originalRuleDataSource.getProxyUser());
            ruleDataSource.setLinkisDataSourceId(originalRuleDataSource.getLinkisDataSourceId());
            ruleDataSource.setLinkisDataSourceName(originalRuleDataSource.getLinkisDataSourceName());
            ruleDataSource.setLinkisDataSourceVersionId(originalRuleDataSource.getLinkisDataSourceVersionId());
            ruleDataSources.add(ruleDataSource);
        }
        Set<RuleDataSource> ruleDataSourcesExist = currentRule.getRuleDataSources();
        ruleDataSourcesExist.addAll(ruleDataSourceDao.saveAllRuleDataSource(ruleDataSources).stream().collect(Collectors.toSet()));
        currentRule.setRuleDataSources(ruleDataSourcesExist);
        ruleDao.saveRule(currentRule);
    }
}
Also used : RuleMetric(com.webank.wedatasphere.qualitis.entity.RuleMetric) RuleDataSource(com.webank.wedatasphere.qualitis.rule.entity.RuleDataSource) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) TableStat(com.alibaba.druid.stat.TableStat) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement) DbType(com.alibaba.druid.DbType) Name(com.alibaba.druid.stat.TableStat.Name) MySqlSchemaStatVisitor(com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor) ArrayList(java.util.ArrayList) List(java.util.List) HiveSqlParser(com.webank.wedatasphere.qualitis.parser.HiveSqlParser) AlarmConfig(com.webank.wedatasphere.qualitis.rule.entity.AlarmConfig) TaskRuleAlarmConfig(com.webank.wedatasphere.qualitis.entity.TaskRuleAlarmConfig)

Example 14 with RuleDataSource

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

the class MetaDataServiceImpl method addMultiDbRules.

@Override
@Transactional(rollbackFor = { Exception.class, UnExpectedRequestException.class })
public String addMultiDbRules(MulDbRequest request) throws UnExpectedRequestException, MetaDataAcquireFailedException {
    MulDbRequest.checkRequst(request);
    String loginUser = HttpUtils.getUserName(httpServletRequest);
    LOGGER.info("Start to get all tables with source database and target database.");
    List<String> sourceTableName = new ArrayList<>();
    List<String> targetTableName = new ArrayList<>();
    if (request.getSourceLinkisDataSourceId() == null) {
        GetUserTableByDbIdRequest sourceRequest = new GetUserTableByDbIdRequest(0, Integer.MAX_VALUE, request.getClusterName(), request.getSourceDb());
        sourceRequest.setProxyUser(request.getProxyUser());
        GeneralResponse<GetAllResponse<TableInfoDetail>> sourceTableInfos = getUserTableByDbId(sourceRequest);
        if (sourceTableInfos.getData().getTotal() <= 0) {
            throw new UnExpectedRequestException("Source database has no tables.");
        }
        sourceTableName.addAll(sourceTableInfos.getData().getData().stream().map(TableInfoDetail::getTableName).collect(Collectors.toList()));
    } else {
        Map response = getTablesByDataSource(request.getClusterName(), request.getProxyUser(), request.getSourceLinkisDataSourceId(), request.getSourceDb());
        List<String> tables = (List<String>) response.get("tables");
        for (String table : tables) {
            sourceTableName.add(table);
        }
    }
    if (request.getTargetLinkisDataSourceId() == null) {
        GetUserTableByDbIdRequest targetRequest = new GetUserTableByDbIdRequest(0, Integer.MAX_VALUE, request.getClusterName(), request.getTargetDb());
        targetRequest.setProxyUser(request.getProxyUser());
        GeneralResponse<GetAllResponse<TableInfoDetail>> targetTableInfos = getUserTableByDbId(targetRequest);
        if (targetTableInfos.getData().getTotal() <= 0) {
            throw new UnExpectedRequestException("Target database has no tables.");
        }
        targetTableName.addAll(targetTableInfos.getData().getData().stream().map(TableInfoDetail::getTableName).collect(Collectors.toList()));
    } else {
        Map response = getTablesByDataSource(request.getClusterName(), request.getProxyUser(), request.getTargetLinkisDataSourceId(), request.getTargetDb());
        List<String> tables = (List<String>) response.get("tables");
        for (String table : tables) {
            targetTableName.add(table);
        }
    }
    // Collect the table with the same name that exists in the source database and the target database.
    sourceTableName.retainAll(targetTableName);
    Set<String> ruleFailedTable = new HashSet<>();
    Long projectId = request.getProjectId();
    List<String> ruleTables = new ArrayList<>(ruleDataSourceDao.findByProjectId(projectId).stream().map(RuleDataSource::getTableName).distinct().collect(Collectors.toList()));
    // Filter tables for which rules have been created.
    sourceTableName = sourceTableName.stream().filter(tableName -> !ruleTables.contains(tableName)).collect(Collectors.toList());
    // Rule name index starts with the last created rule.
    int ruleIndex = ruleDao.findByProject(projectDao.findById(projectId)).size();
    // Filter tables with black list.
    sourceTableName = filterTablesWithBlackList(request.getBlackList(), sourceTableName);
    // White list.
    List<String> whiteList = request.getWhiteList();
    // Filter special table to compare with accuracy template.
    List<FilterRequest> filterRequests = request.getFilterRequests();
    List<FilterRequest> sameTableFilterRequests = filterRequests.stream().filter(filterRequest -> filterRequest.getSourceTable().equals(filterRequest.getTargetTable())).collect(Collectors.toList());
    List<String> filterSameTableName = sameTableFilterRequests.stream().map(FilterRequest::getSourceTable).collect(Collectors.toList());
    sourceTableName.removeAll(filterSameTableName);
    filterRequests.removeAll(sameTableFilterRequests);
    List<String> filterDiffTableName = filterRequests.stream().map(filterRequest -> filterRequest.getSourceTable() + SpecCharEnum.COLON.getValue() + filterRequest.getTargetTable()).collect(Collectors.toList());
    whiteList.removeAll(filterDiffTableName);
    filterRequests.addAll(sameTableFilterRequests);
    // Check flag: create rules in a loop, and only do permission verification for the first time.
    boolean check = true;
    int sourceTableSize = sourceTableName.size();
    int filterRequestsSize = filterRequests.size();
    int total = ruleIndex + sourceTableSize + whiteList.size() + filterRequestsSize;
    int i = ruleIndex;
    for (; i < ruleIndex + sourceTableSize; i++) {
        String currentSameTable = sourceTableName.get(i - ruleIndex);
        try {
            AddMultiSourceRuleRequest addMultiSourceRuleRequest = constructRequest(request, null, currentSameTable, currentSameTable, i, total, loginUser);
            LOGGER.info("Start to add {}th multi source rule.", i);
            if (i > 0) {
                check = false;
            }
            multiSourceRuleService.addMultiSourceRule(addMultiSourceRuleRequest, check);
        } catch (Exception e) {
            LOGGER.error("One of rule failed to add, rule index:[{}], table name: [{}], exception:{}", i, currentSameTable, e.getMessage());
            ruleFailedTable.add(currentSameTable);
        }
        LOGGER.info("Finish to add {}th multi source rule.", i);
    }
    // With white list.
    withWhiteListAndFilterRequest(i, ruleIndex, sourceTableSize, total, whiteList, filterRequests, request, loginUser, check);
    // Record the table that failed to create a rule.
    saveRuleFailedTableInLabel(ruleFailedTable, projectId);
    // projectEventService.record(projectId, loginUser, "create multi-source rule with dbs", "Success: " + (total - ruleFailedTable.size()) + "; Failed: " + ruleFailedTable.size(), EventTypeEnum.MODIFY_PROJECT.getCode());
    return request.getSourceDb() + " vs " + request.getSourceDb() + ": " + "{&CONTINUE_CREATE_RULES}";
}
Also used : GetUserTableByDbIdRequest(com.webank.wedatasphere.qualitis.request.GetUserTableByDbIdRequest) Arrays(java.util.Arrays) StringUtils(org.apache.commons.lang.StringUtils) LoggerFactory(org.slf4j.LoggerFactory) GetUserColumnByCsRequest(com.webank.wedatasphere.qualitis.metadata.request.GetUserColumnByCsRequest) Autowired(org.springframework.beans.factory.annotation.Autowired) RuleDataSource(com.webank.wedatasphere.qualitis.rule.entity.RuleDataSource) GeneralResponse(com.webank.wedatasphere.qualitis.response.GeneralResponse) ClusterInfoDao(com.webank.wedatasphere.qualitis.dao.ClusterInfoDao) HttpUtils(com.webank.wedatasphere.qualitis.util.HttpUtils) Map(java.util.Map) MultiDataSourceConfigRequest(com.webank.wedatasphere.qualitis.rule.request.multi.MultiDataSourceConfigRequest) GetClusterByUserRequest(com.webank.wedatasphere.qualitis.metadata.request.GetClusterByUserRequest) ProjectService(com.webank.wedatasphere.qualitis.project.service.ProjectService) GetAllResponse(com.webank.wedatasphere.qualitis.response.GetAllResponse) AlarmConfigRequest(com.webank.wedatasphere.qualitis.rule.request.AlarmConfigRequest) ProjectEventService(com.webank.wedatasphere.qualitis.project.service.ProjectEventService) GetUserDbByClusterRequest(com.webank.wedatasphere.qualitis.request.GetUserDbByClusterRequest) GetAllClusterResponse(com.webank.wedatasphere.qualitis.response.GetAllClusterResponse) DataSourceModifyRequest(com.webank.wedatasphere.qualitis.request.DataSourceModifyRequest) AddMultiSourceRuleRequest(com.webank.wedatasphere.qualitis.rule.request.multi.AddMultiSourceRuleRequest) MappingOperationEnum(com.webank.wedatasphere.qualitis.rule.constant.MappingOperationEnum) Context(javax.ws.rs.core.Context) TableInfoDetail(com.webank.wedatasphere.qualitis.metadata.response.table.TableInfoDetail) Set(java.util.Set) Collectors(java.util.stream.Collectors) MetaDataAcquireFailedException(com.webank.wedatasphere.qualitis.metadata.exception.MetaDataAcquireFailedException) GetDbByUserAndClusterRequest(com.webank.wedatasphere.qualitis.metadata.request.GetDbByUserAndClusterRequest) List(java.util.List) ClusterInfo(com.webank.wedatasphere.qualitis.entity.ClusterInfo) MetaDataClient(com.webank.wedatasphere.qualitis.metadata.client.MetaDataClient) Pattern(java.util.regex.Pattern) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) DataSourceConnectRequest(com.webank.wedatasphere.qualitis.request.DataSourceConnectRequest) GetUserClusterRequest(com.webank.wedatasphere.qualitis.request.GetUserClusterRequest) UnsupportedEncodingException(java.io.UnsupportedEncodingException) BlackListFilterTypeEnum(com.webank.wedatasphere.qualitis.constant.BlackListFilterTypeEnum) ClusterInfoDetail(com.webank.wedatasphere.qualitis.metadata.response.cluster.ClusterInfoDetail) GetTableByUserAndDbRequest(com.webank.wedatasphere.qualitis.metadata.request.GetTableByUserAndDbRequest) Project(com.webank.wedatasphere.qualitis.project.entity.Project) RuleLimitationService(com.webank.wedatasphere.qualitis.rule.service.RuleLimitationService) SpecCharEnum(com.webank.wedatasphere.qualitis.constant.SpecCharEnum) MulDbRequest(com.webank.wedatasphere.qualitis.request.MulDbRequest) RuleDataSourceDao(com.webank.wedatasphere.qualitis.rule.dao.RuleDataSourceDao) ProjectDao(com.webank.wedatasphere.qualitis.project.dao.ProjectDao) DataSourceParamModifyRequest(com.webank.wedatasphere.qualitis.request.DataSourceParamModifyRequest) FilterRequest(com.webank.wedatasphere.qualitis.request.FilterRequest) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) HttpServletRequest(javax.servlet.http.HttpServletRequest) CheckTemplateEnum(com.webank.wedatasphere.qualitis.rule.constant.CheckTemplateEnum) CollectionUtils(org.apache.commons.collections.CollectionUtils) Service(org.springframework.stereotype.Service) GetUserTableByCsIdRequest(com.webank.wedatasphere.qualitis.metadata.request.GetUserTableByCsIdRequest) CompareTypeEnum(com.webank.wedatasphere.qualitis.rule.constant.CompareTypeEnum) MetaDataService(com.webank.wedatasphere.qualitis.service.MetaDataService) MultiDataSourceJoinColumnRequest(com.webank.wedatasphere.qualitis.rule.request.multi.MultiDataSourceJoinColumnRequest) CsTableInfoDetail(com.webank.wedatasphere.qualitis.metadata.response.table.CsTableInfoDetail) Logger(org.slf4j.Logger) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IOException(java.io.IOException) GetColumnByUserAndTableRequest(com.webank.wedatasphere.qualitis.metadata.request.GetColumnByUserAndTableRequest) GetUserColumnByTableIdRequest(com.webank.wedatasphere.qualitis.request.GetUserColumnByTableIdRequest) ColumnInfoDetail(com.webank.wedatasphere.qualitis.metadata.response.column.ColumnInfoDetail) DbInfoDetail(com.webank.wedatasphere.qualitis.metadata.response.db.DbInfoDetail) DataInfo(com.webank.wedatasphere.qualitis.metadata.response.DataInfo) MultiSourceRuleService(com.webank.wedatasphere.qualitis.rule.service.MultiSourceRuleService) RuleDao(com.webank.wedatasphere.qualitis.rule.dao.RuleDao) MultiDataSourceJoinConfigRequest(com.webank.wedatasphere.qualitis.rule.request.multi.MultiDataSourceJoinConfigRequest) GetUserTableByDbIdRequest(com.webank.wedatasphere.qualitis.request.GetUserTableByDbIdRequest) Comparator(java.util.Comparator) Collections(java.util.Collections) Transactional(org.springframework.transaction.annotation.Transactional) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) ArrayList(java.util.ArrayList) MetaDataAcquireFailedException(com.webank.wedatasphere.qualitis.metadata.exception.MetaDataAcquireFailedException) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IOException(java.io.IOException) FilterRequest(com.webank.wedatasphere.qualitis.request.FilterRequest) List(java.util.List) ArrayList(java.util.ArrayList) GetAllResponse(com.webank.wedatasphere.qualitis.response.GetAllResponse) TableInfoDetail(com.webank.wedatasphere.qualitis.metadata.response.table.TableInfoDetail) CsTableInfoDetail(com.webank.wedatasphere.qualitis.metadata.response.table.CsTableInfoDetail) Map(java.util.Map) HashSet(java.util.HashSet) AddMultiSourceRuleRequest(com.webank.wedatasphere.qualitis.rule.request.multi.AddMultiSourceRuleRequest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 15 with RuleDataSource

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

the class PredicateTest method test.

@Test
@Transactional
public void test() {
    String user = "v_wblwyan_test1";
    /*
     * ProjectUserDao测试
     */
    DataSourceQo param = new DataSourceQo();
    param.setUser(user);
    param.setUserType(new Integer[] { ProjectUserPermissionEnum.CREATOR.getCode() });
    List<ProjectUser> projectUsers = dao.findByUsernameAndPermissionsIn(param);
    assertTrue(projectUsers.isEmpty());
    param.setUserType(new Integer[] { ProjectUserPermissionEnum.CREATOR.getCode() });
    projectUsers = dao.findByUsernameAndPermissionsIn(param);
    assertTrue(projectUsers.isEmpty());
    param.setUserType(null);
    projectUsers = dao.findByUsernameAndPermissionsIn(param);
    assertTrue(projectUsers.isEmpty());
    param.setUserType(new Integer[] {});
    projectUsers = dao.findByUsernameAndPermissionsIn(param);
    assertTrue(projectUsers.isEmpty());
    /*
     *TaskDataSourceDao 测试
     */
    List<TaskDataSource> taskDataSources = taskDataSourceDao.findByUserAndDataSource(user, null, null, null, 0, 5);
    assertTrue(taskDataSources.isEmpty());
    taskDataSources = taskDataSourceDao.findByUserAndDataSource(user, "clusterName_test", null, null, 0, 5);
    assertTrue(taskDataSources.isEmpty());
    taskDataSources = taskDataSourceDao.findByUserAndDataSource(user, "clusterName_test", "databaseName_test", null, 0, 5);
    assertTrue(taskDataSources.isEmpty());
    taskDataSources = taskDataSourceDao.findByUserAndDataSource(user, "clusterName_test", "databaseName_test", "tableName_test", 0, 5);
    assertTrue(taskDataSources.isEmpty());
    long count = taskDataSourceDao.countByUserAndDataSource(user, "clusterName_test", "databaseName_test", null);
    assertEquals(0, count);
    /*
     *RuleDataSourceDao 测试
     */
    List<RuleDataSource> ruleDataSources = ruleDataSourceDao.findByProjectUser((long) Integer.MAX_VALUE, null, null, null);
    assertTrue(ruleDataSources.isEmpty());
    ruleDataSources = ruleDataSourceDao.findByProjectUser((long) Integer.MAX_VALUE, "clusterName_test", null, null);
    assertTrue(ruleDataSources.isEmpty());
    ruleDataSources = ruleDataSourceDao.findByProjectUser((long) Integer.MAX_VALUE, "clusterName_test", "databaseName_test", null);
    assertTrue(ruleDataSources.isEmpty());
    ruleDataSources = ruleDataSourceDao.findByProjectUser((long) Integer.MAX_VALUE, "clusterName_test", "databaseName_test", "tableName_test");
    assertTrue(ruleDataSources.isEmpty());
}
Also used : ProjectUser(com.webank.wedatasphere.qualitis.project.entity.ProjectUser) RuleDataSource(com.webank.wedatasphere.qualitis.rule.entity.RuleDataSource) TaskDataSource(com.webank.wedatasphere.qualitis.entity.TaskDataSource) DataSourceQo(com.webank.wedatasphere.qualitis.query.queryqo.DataSourceQo) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

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