use of com.webank.wedatasphere.qualitis.metadata.request.GetUserColumnByCsRequest 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;
}
use of com.webank.wedatasphere.qualitis.metadata.request.GetUserColumnByCsRequest 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}");
}
}
}
}
use of com.webank.wedatasphere.qualitis.metadata.request.GetUserColumnByCsRequest 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;
}
Aggregations