use of com.webank.wedatasphere.qualitis.metadata.response.DataInfo in project Qualitis by WeBankFinTech.
the class RuleQueryController method query.
@POST
@Path("query")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public GeneralResponse<?> query(RuleQueryRequest param, @Context HttpServletRequest request) {
if (param == null) {
param = new RuleQueryRequest();
}
// Get login user
param.setUser(HttpUtils.getUserName(request));
try {
PageRequest pageRequest = new PageRequest();
pageRequest.setPage(param.getPage());
pageRequest.setSize(param.getSize());
PageRequest.checkRequest(pageRequest);
DataInfo<RuleQueryDataSource> results = new DataInfo<>();
List<RuleQueryDataSource> ruleQueryDataSources = ruleQueryService.filter(pageRequest, param.getUser(), param.getCluster(), param.getDb(), param.getTable(), false);
results.setContent(ruleQueryDataSources);
List<RuleQueryDataSource> allRuleDataSource = ruleQueryService.filter(null, param.getUser(), param.getCluster(), param.getDb(), param.getTable(), true);
results.setTotalCount(allRuleDataSource == null ? 0 : allRuleDataSource.size());
LOG.info("[My DataSource] Query successfully. The number of results:{}", allRuleDataSource == null ? 0 : allRuleDataSource.size());
return new GeneralResponse<>("200", "{&QUERY_SUCCESSFULLY}", results);
} catch (Exception e) {
LOG.error("[My DataSource] Query failed, internal error.", e);
return new GeneralResponse<>("500", e.getMessage(), null);
}
}
use of com.webank.wedatasphere.qualitis.metadata.response.DataInfo in project Qualitis by WeBankFinTech.
the class MetaDataClientImpl method getColumnsByDataSource.
@Override
public DataInfo<ColumnInfoDetail> getColumnsByDataSource(String clusterName, String authUser, Long dataSourceId, String dbName, String tableName) throws UnExpectedRequestException, MetaDataAcquireFailedException {
// Check existence of cluster name
ClusterInfo clusterInfo = checkClusterNameExists(clusterName);
// send request to get dbs
String url = getPath(clusterInfo.getLinkisAddress()).path(linkisConfig.getDatasourceColumn()).queryParam("system", "Qualitis").toString().replace("{DATA_SOURCE_ID}", dataSourceId.toString()).replace("{DATA_SOURCE_DB}", dbName).replace("{DATA_SOURCE_TABLE}", tableName);
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.add("Token-User", authUser);
headers.add("Token-Code", clusterInfo.getLinkisToken());
HttpEntity<Object> entity = new HttpEntity<>(headers);
LOGGER.info("Start to get columns by data source. url: {}, method: {}, body: {}", url, javax.ws.rs.HttpMethod.GET, entity);
Map<String, Object> response = restTemplate.exchange(url, HttpMethod.GET, entity, Map.class).getBody();
LOGGER.info("Finish to get columns by data source. response: {}", response);
if (!checkResponse(response)) {
String message = (String) response.get("message");
LOGGER.error("Error! Can not get meta data from linkis, message: " + message);
throw new MetaDataAcquireFailedException("Error! Can not get meta data from linkis, exception: " + message);
}
Map data = (Map) response.get(LinkisResponseKeyEnum.DATA.getKey());
DataInfo<ColumnInfoDetail> result = new DataInfo<>();
List<Map> tables = (List<Map>) data.get("columns");
if (CollectionUtils.isEmpty(tables)) {
LOGGER.info("No columns with data source to be choosed.");
} else {
List<ColumnInfoDetail> columnInfoDetailList = new ArrayList<>(tables.size());
for (Map map : tables) {
ColumnInfoDetail columnInfoDetail = new ColumnInfoDetail();
columnInfoDetail.setFieldName((String) map.get("name"));
columnInfoDetail.setDataType((String) map.get("type"));
columnInfoDetailList.add(columnInfoDetail);
}
result.setTotalCount(columnInfoDetailList.size());
result.setContent(columnInfoDetailList);
}
return result;
}
use of com.webank.wedatasphere.qualitis.metadata.response.DataInfo in project Qualitis by WeBankFinTech.
the class RuleMetricServiceImpl method getRulesByRuleMetric.
@Override
public DataInfo<HiveRuleDetail> getRulesByRuleMetric(long id, int page, int size) throws UnExpectedRequestException {
DataInfo<HiveRuleDetail> dataInfo = new DataInfo<>();
if (id <= 0) {
throw new UnExpectedRequestException("{&REQUEST_CAN_NOT_BE_NULL}");
}
// Check rule metric existence.
RuleMetric ruleMetricInDb = ruleMetricDao.findById(id);
if (ruleMetricInDb == null) {
throw new UnExpectedRequestException("Rule Metric ID [" + id + "] {&DOES_NOT_EXIST}");
}
List<Long> ruleIds = taskResultDao.findRuleByRuleMetric(ruleMetricInDb.getId(), page, size).stream().distinct().collect(Collectors.toList());
int total = taskResultDao.countRuleByRuleMetric(ruleMetricInDb.getId());
List<HiveRuleDetail> result = new ArrayList<>(ruleIds.size());
for (Long ruleId : ruleIds) {
Rule ruleInDb = ruleDao.findById(ruleId);
if (ruleInDb == null) {
total--;
continue;
}
List<Long> ruleMetricIds = ruleInDb.getAlarmConfigs().stream().map(AlarmConfig::getRuleMetric).filter(ruleMetric -> ruleMetric != null).map(RuleMetric::getId).collect(Collectors.toList());
if (ruleInDb != null && ruleMetricIds.contains(id)) {
HiveRuleDetail hiveRuleDetail = new HiveRuleDetail(ruleInDb);
result.add(hiveRuleDetail);
}
}
dataInfo.setContent(result);
dataInfo.setTotalCount(total);
return dataInfo;
}
use of com.webank.wedatasphere.qualitis.metadata.response.DataInfo in project Qualitis by WeBankFinTech.
the class RuleQueryServiceImpl method getRulesByColumn.
@Override
public DataInfo<HiveRuleDetail> getRulesByColumn(String cluster, String db, String table, String column, String userName, int page, int size) {
LOGGER.info("Start to get rules with column. cluster: {}, db: {}, table: {}, column: {}", cluster, db, table, column);
DataInfo<HiveRuleDetail> dataInfo = new DataInfo<>();
List<Rule> rules = ruleDataSourceDao.findRuleByDataSource(cluster, db, table, column, userName, page, size);
int total = ruleDataSourceDao.countRuleByDataSource(cluster, db, table, column, userName);
if (rules == null || rules.isEmpty()) {
return null;
}
List<HiveRuleDetail> result = new ArrayList<>(rules.size());
LOGGER.info("Success to get rules with column. Rules: {}", rules);
for (Rule rule : rules) {
HiveRuleDetail hiveRuleDetail = new HiveRuleDetail(rule);
hiveRuleDetail.setTemplateName(rule.getRuleTemplateName());
result.add(hiveRuleDetail);
}
dataInfo.setContent(result);
dataInfo.setTotalCount(total);
return dataInfo;
}
use of com.webank.wedatasphere.qualitis.metadata.response.DataInfo in project Qualitis by WeBankFinTech.
the class RuleMetricServiceImpl method getResultsByRuleMetric.
@Override
public DataInfo<RuleMetricValueResponse> getResultsByRuleMetric(long ruleMetricId, int page, int size) throws UnExpectedRequestException {
DataInfo<RuleMetricValueResponse> dataInfo = new DataInfo<>();
int total = taskResultDao.countValuesByRuleMetric(ruleMetricId);
List<TaskResult> values = taskResultDao.findValuesByRuleMetric(ruleMetricId, page, size);
List<RuleMetricValueResponse> responses = new ArrayList<>(values.size());
for (TaskResult taskResult : values) {
if (taskResult == null) {
continue;
}
RuleMetricValueResponse ruleMetricValueResponse = new RuleMetricValueResponse();
ruleMetricValueResponse.setGenerateTime(taskResult.getCreateTime());
Rule currentRule = ruleDao.findById(taskResult.getRuleId());
ruleMetricValueResponse.setRelatedRuleName(currentRule == null ? "Deleted" : currentRule.getName());
ruleMetricValueResponse.setRuleMetricValue(StringUtils.isBlank(taskResult.getValue()) ? "0" : taskResult.getValue());
responses.add(ruleMetricValueResponse);
}
dataInfo.setContent(responses);
dataInfo.setTotalCount(total);
return dataInfo;
}
Aggregations