Search in sources :

Example 1 with GetUserTableByCsIdRequest

use of com.webank.wedatasphere.qualitis.metadata.request.GetUserTableByCsIdRequest in project Qualitis by WeBankFinTech.

the class RuleQueryServiceImpl method getColumnsByTableName.

@Override
public List<ColumnInfoDetail> getColumnsByTableName(String clusterName, Long datasourceId, String dbName, String tableName, String userName) throws UnExpectedRequestException, MetaDataAcquireFailedException {
    List<ColumnInfoDetail> result = null;
    User user = userDao.findByUsername(userName);
    if (user == null) {
        throw new UnExpectedRequestException(String.format("{&FAILED_TO_FIND_USER} %s", userName));
    }
    try {
        if (StringUtils.isBlank(dbName)) {
            List<Rule> rules = ruleDataSourceDao.findRuleByDataSource(clusterName, dbName, tableName, "%", userName);
            if (rules == null || rules.isEmpty()) {
                LOGGER.info("No rules for this datasource!");
                return null;
            }
            LOGGER.info("Rules related with context service table: [{}] are: {}", tableName, rules.toArray());
            String csId = rules.get(0).getCsId();
            String nodeName = rules.get(0).getName();
            GetUserTableByCsIdRequest getUserTableByCsIdRequest = new GetUserTableByCsIdRequest();
            getUserTableByCsIdRequest.setClusterName(clusterName);
            getUserTableByCsIdRequest.setLoginUser(userName);
            getUserTableByCsIdRequest.setNodeName(nodeName);
            getUserTableByCsIdRequest.setCsId(csId);
            DataInfo<CsTableInfoDetail> csTableInfoDetails = metaDataClient.getTableByCsId(getUserTableByCsIdRequest);
            if (csTableInfoDetails.getTotalCount() == 0) {
                LOGGER.info("Cannot find context service table with existed rules!");
                return null;
            }
            for (CsTableInfoDetail csTableInfoDetail : csTableInfoDetails.getContent()) {
                if (csTableInfoDetail.getTableName().equals(tableName)) {
                    GetUserColumnByCsRequest getUserColumnByCsRequest = new GetUserColumnByCsRequest();
                    getUserColumnByCsRequest.setClusterName(clusterName);
                    getUserColumnByCsRequest.setContextKey(csTableInfoDetail.getContextKey());
                    getUserColumnByCsRequest.setCsId(csId);
                    getUserColumnByCsRequest.setLoginUser(userName);
                    result = metaDataClient.getColumnByCsId(getUserColumnByCsRequest).getContent();
                    setRuleCount(result, user.getId(), clusterName, dbName, tableName);
                    break;
                } else {
                    continue;
                }
            }
        } else {
            if (datasourceId == null) {
                result = metaDataClient.getColumnInfo(clusterName, dbName, tableName, userName);
            } else {
                result = metaDataClient.getColumnsByDataSource(clusterName, userName, datasourceId, dbName, tableName).getContent();
            }
            setRuleCount(result, user.getId(), clusterName, dbName, tableName);
        }
        LOGGER.info("Datasource table number of columns: {}", result == null ? 0 : result.size());
    } catch (MetaDataAcquireFailedException e) {
        LOGGER.error("Datasource colums info {&DOES_NOT_EXIST}. Exception: {}", e);
        throw new MetaDataAcquireFailedException("Datasource colums info {&DOES_NOT_EXIST}. Exception: " + e.getMessage());
    } catch (UnExpectedRequestException e) {
        LOGGER.error("{&QUERY_PARAM_HAS_ERROR}. Exception: {}", e);
        throw new UnExpectedRequestException("{&QUERY_PARAM_HAS_ERROR}. Exception: " + e.getMessage());
    } catch (Exception e) {
        LOGGER.error("exception: {}", e);
    }
    return result;
}
Also used : UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) User(com.webank.wedatasphere.qualitis.entity.User) ProjectUser(com.webank.wedatasphere.qualitis.project.entity.ProjectUser) ColumnInfoDetail(com.webank.wedatasphere.qualitis.metadata.response.column.ColumnInfoDetail) GetUserTableByCsIdRequest(com.webank.wedatasphere.qualitis.metadata.request.GetUserTableByCsIdRequest) PermissionDeniedRequestException(com.webank.wedatasphere.qualitis.exception.PermissionDeniedRequestException) MetaDataAcquireFailedException(com.webank.wedatasphere.qualitis.metadata.exception.MetaDataAcquireFailedException) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) CsTableInfoDetail(com.webank.wedatasphere.qualitis.metadata.response.table.CsTableInfoDetail) MetaDataAcquireFailedException(com.webank.wedatasphere.qualitis.metadata.exception.MetaDataAcquireFailedException) Rule(com.webank.wedatasphere.qualitis.rule.entity.Rule) RuleQueryRule(com.webank.wedatasphere.qualitis.query.response.RuleQueryRule) GetUserColumnByCsRequest(com.webank.wedatasphere.qualitis.metadata.request.GetUserColumnByCsRequest)

Example 2 with GetUserTableByCsIdRequest

use of com.webank.wedatasphere.qualitis.metadata.request.GetUserTableByCsIdRequest in project Qualitis by WeBankFinTech.

the class OuterExecutionServiceImpl method checkDatasourceInContextService.

private void checkDatasourceInContextService(RuleDataSource ruleDataSource, Map<String, String> mappingCol, String clusterName, String userName, String nodeName, String csId) throws UnExpectedRequestException, MetaDataAcquireFailedException {
    GetUserTableByCsIdRequest getUserTableByCsIdRequest = new GetUserTableByCsIdRequest();
    getUserTableByCsIdRequest.setClusterName(StringUtils.isNotBlank(clusterName) ? clusterName : ruleDataSource.getClusterName());
    getUserTableByCsIdRequest.setLoginUser(userName);
    getUserTableByCsIdRequest.setCsId(csId);
    if (StringUtils.isBlank(nodeName)) {
        getUserTableByCsIdRequest.setNodeName(RuleConstraintEnum.DEFAULT_NODENAME.getValue());
    } else {
        getUserTableByCsIdRequest.setNodeName(nodeName);
    }
    DataInfo<CsTableInfoDetail> csTableInfoDetails = metaDataClient.getTableByCsId(getUserTableByCsIdRequest);
    if (csTableInfoDetails.getTotalCount() == 0) {
        LOGGER.info("Cannot find context service table with existed rules!");
        throw new UnExpectedRequestException("Table[" + ruleDataSource.getTableName() + "] {&RULE_DATASOURCE_BE_MOVED}");
    }
    for (CsTableInfoDetail csTableInfoDetail : csTableInfoDetails.getContent()) {
        if (csTableInfoDetail.getTableName().equals(ruleDataSource.getTableName())) {
            GetUserColumnByCsRequest getUserColumnByCsRequest = new GetUserColumnByCsRequest();
            getUserColumnByCsRequest.setClusterName(StringUtils.isNotBlank(clusterName) ? clusterName : ruleDataSource.getClusterName());
            getUserColumnByCsRequest.setContextKey(csTableInfoDetail.getContextKey());
            getUserColumnByCsRequest.setLoginUser(userName);
            getUserColumnByCsRequest.setCsId(csId);
            List<ColumnInfoDetail> cols = metaDataClient.getColumnByCsId(getUserColumnByCsRequest).getContent();
            if (ruleDataSource.getRule().getRuleType().equals(RuleTypeEnum.CUSTOM_RULE.getCode())) {
                continue;
            }
            if (!metaDataClient.fieldExist(ruleDataSource.getColName(), cols, mappingCol)) {
                throw new UnExpectedRequestException("Table[" + ruleDataSource.getTableName() + ":" + ruleDataSource.getColName() + "] {&RULE_DATASOURCE_BE_MOVED}");
            }
        }
    }
}
Also used : CsTableInfoDetail(com.webank.wedatasphere.qualitis.metadata.response.table.CsTableInfoDetail) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) GetUserColumnByCsRequest(com.webank.wedatasphere.qualitis.metadata.request.GetUserColumnByCsRequest) ColumnInfoDetail(com.webank.wedatasphere.qualitis.metadata.response.column.ColumnInfoDetail) GetUserTableByCsIdRequest(com.webank.wedatasphere.qualitis.metadata.request.GetUserTableByCsIdRequest)

Example 3 with GetUserTableByCsIdRequest

use of com.webank.wedatasphere.qualitis.metadata.request.GetUserTableByCsIdRequest in project Qualitis by WeBankFinTech.

the class RuleDataSourceServiceImpl method saveCustomColumn.

private List<DataSourceColumnRequest> saveCustomColumn(String clusterName, String db, String table, String loginUser, String csId, String nodeName, String funcContent, boolean fps, boolean cs) throws UnExpectedRequestException, MetaDataAcquireFailedException {
    List<DataSourceColumnRequest> dataSourceColumnRequests = new ArrayList<>();
    List<ColumnInfoDetail> cols = new ArrayList<>();
    if (cs) {
        GetUserTableByCsIdRequest getUserTableByCsIdRequest = new GetUserTableByCsIdRequest();
        getUserTableByCsIdRequest.setClusterName(clusterName);
        getUserTableByCsIdRequest.setLoginUser(loginUser);
        getUserTableByCsIdRequest.setCsId(csId);
        getUserTableByCsIdRequest.setNodeName(nodeName);
        DataInfo<CsTableInfoDetail> csTableInfoDetails = metaDataClient.getTableByCsId(getUserTableByCsIdRequest);
        if (csTableInfoDetails.getTotalCount() == 0 && !fps) {
            LOGGER.info("Cannot find context service table with existed rules!");
            throw new UnExpectedRequestException("Table in sql {&DOES_NOT_EXIST}");
        }
        for (CsTableInfoDetail csTableInfoDetail : csTableInfoDetails.getContent()) {
            if (csTableInfoDetail.getTableName().equals(table)) {
                GetUserColumnByCsRequest getUserColumnByCsRequest = new GetUserColumnByCsRequest();
                getUserColumnByCsRequest.setClusterName(clusterName);
                getUserColumnByCsRequest.setContextKey(csTableInfoDetail.getContextKey());
                getUserColumnByCsRequest.setCsId(csId);
                getUserColumnByCsRequest.setLoginUser(loginUser);
                cols = metaDataClient.getColumnByCsId(getUserColumnByCsRequest).getContent();
                if (CollectionUtils.isEmpty(cols) && !fps) {
                    throw new UnExpectedRequestException("Table in sql {&DOES_NOT_EXIST}");
                }
            }
        }
    } else {
        cols = metaDataClient.getColumnInfo(clusterName, db, table, loginUser);
        if (CollectionUtils.isEmpty(cols) && !fps) {
            throw new UnExpectedRequestException("Table in sql {&DOES_NOT_EXIST}");
        }
    }
    // Save column info in use.
    for (ColumnInfoDetail detail : cols) {
        if (funcContent != null && funcContent.contains(detail.getFieldName())) {
            dataSourceColumnRequests.add(new DataSourceColumnRequest(detail.getFieldName(), detail.getDataType()));
        }
    }
    return dataSourceColumnRequests;
}
Also used : DataSourceColumnRequest(com.webank.wedatasphere.qualitis.rule.request.DataSourceColumnRequest) CsTableInfoDetail(com.webank.wedatasphere.qualitis.metadata.response.table.CsTableInfoDetail) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) ArrayList(java.util.ArrayList) ColumnInfoDetail(com.webank.wedatasphere.qualitis.metadata.response.column.ColumnInfoDetail) GetUserColumnByCsRequest(com.webank.wedatasphere.qualitis.metadata.request.GetUserColumnByCsRequest) GetUserTableByCsIdRequest(com.webank.wedatasphere.qualitis.metadata.request.GetUserTableByCsIdRequest)

Aggregations

UnExpectedRequestException (com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException)3 GetUserColumnByCsRequest (com.webank.wedatasphere.qualitis.metadata.request.GetUserColumnByCsRequest)3 GetUserTableByCsIdRequest (com.webank.wedatasphere.qualitis.metadata.request.GetUserTableByCsIdRequest)3 ColumnInfoDetail (com.webank.wedatasphere.qualitis.metadata.response.column.ColumnInfoDetail)3 CsTableInfoDetail (com.webank.wedatasphere.qualitis.metadata.response.table.CsTableInfoDetail)3 User (com.webank.wedatasphere.qualitis.entity.User)1 PermissionDeniedRequestException (com.webank.wedatasphere.qualitis.exception.PermissionDeniedRequestException)1 MetaDataAcquireFailedException (com.webank.wedatasphere.qualitis.metadata.exception.MetaDataAcquireFailedException)1 ProjectUser (com.webank.wedatasphere.qualitis.project.entity.ProjectUser)1 RuleQueryRule (com.webank.wedatasphere.qualitis.query.response.RuleQueryRule)1 Rule (com.webank.wedatasphere.qualitis.rule.entity.Rule)1 DataSourceColumnRequest (com.webank.wedatasphere.qualitis.rule.request.DataSourceColumnRequest)1 ArrayList (java.util.ArrayList)1