Search in sources :

Example 1 with DataInfo

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);
    }
}
Also used : DataInfo(com.webank.wedatasphere.qualitis.metadata.response.DataInfo) GeneralResponse(com.webank.wedatasphere.qualitis.response.GeneralResponse) PageRequest(com.webank.wedatasphere.qualitis.request.PageRequest) RuleQueryRequest(com.webank.wedatasphere.qualitis.query.request.RuleQueryRequest) RuleQueryDataSource(com.webank.wedatasphere.qualitis.query.response.RuleQueryDataSource) MetaDataAcquireFailedException(com.webank.wedatasphere.qualitis.metadata.exception.MetaDataAcquireFailedException) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes)

Example 2 with DataInfo

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;
}
Also used : DataInfo(com.webank.wedatasphere.qualitis.metadata.response.DataInfo) HttpHeaders(org.springframework.http.HttpHeaders) HttpEntity(org.springframework.http.HttpEntity) ArrayList(java.util.ArrayList) ColumnInfoDetail(com.webank.wedatasphere.qualitis.metadata.response.column.ColumnInfoDetail) ClusterInfo(com.webank.wedatasphere.qualitis.entity.ClusterInfo) MetaDataAcquireFailedException(com.webank.wedatasphere.qualitis.metadata.exception.MetaDataAcquireFailedException) JSONObject(org.json.JSONObject) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map)

Example 3 with DataInfo

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;
}
Also used : DataInfo(com.webank.wedatasphere.qualitis.metadata.response.DataInfo) ExcelRuleMetric(com.webank.wedatasphere.qualitis.project.excel.ExcelRuleMetric) RuleMetric(com.webank.wedatasphere.qualitis.entity.RuleMetric) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) HiveRuleDetail(com.webank.wedatasphere.qualitis.project.response.HiveRuleDetail) ArrayList(java.util.ArrayList) Rule(com.webank.wedatasphere.qualitis.rule.entity.Rule)

Example 4 with 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;
}
Also used : DataInfo(com.webank.wedatasphere.qualitis.metadata.response.DataInfo) HiveRuleDetail(com.webank.wedatasphere.qualitis.project.response.HiveRuleDetail) ArrayList(java.util.ArrayList) Rule(com.webank.wedatasphere.qualitis.rule.entity.Rule) RuleQueryRule(com.webank.wedatasphere.qualitis.query.response.RuleQueryRule)

Example 5 with 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;
}
Also used : DataInfo(com.webank.wedatasphere.qualitis.metadata.response.DataInfo) RuleMetricValueResponse(com.webank.wedatasphere.qualitis.response.RuleMetricValueResponse) ArrayList(java.util.ArrayList) TaskResult(com.webank.wedatasphere.qualitis.entity.TaskResult) Rule(com.webank.wedatasphere.qualitis.rule.entity.Rule)

Aggregations

DataInfo (com.webank.wedatasphere.qualitis.metadata.response.DataInfo)11 ArrayList (java.util.ArrayList)10 ClusterInfo (com.webank.wedatasphere.qualitis.entity.ClusterInfo)7 MetaDataAcquireFailedException (com.webank.wedatasphere.qualitis.metadata.exception.MetaDataAcquireFailedException)7 Map (java.util.Map)6 JSONObject (org.json.JSONObject)6 HttpEntity (org.springframework.http.HttpEntity)6 HttpHeaders (org.springframework.http.HttpHeaders)6 UnExpectedRequestException (com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException)5 ColumnInfoDetail (com.webank.wedatasphere.qualitis.metadata.response.column.ColumnInfoDetail)5 List (java.util.List)5 JSONException (org.json.JSONException)4 RestClientException (org.springframework.web.client.RestClientException)4 ClusterInfoDetail (com.webank.wedatasphere.qualitis.metadata.response.cluster.ClusterInfoDetail)3 CsTableInfoDetail (com.webank.wedatasphere.qualitis.metadata.response.table.CsTableInfoDetail)3 GeneralResponse (com.webank.wedatasphere.qualitis.response.GeneralResponse)3 Rule (com.webank.wedatasphere.qualitis.rule.entity.Rule)3 LinkisConfig (com.webank.wedatasphere.qualitis.config.LinkisConfig)2 LinkisResponseKeyEnum (com.webank.wedatasphere.qualitis.constant.LinkisResponseKeyEnum)2 SpecCharEnum (com.webank.wedatasphere.qualitis.constant.SpecCharEnum)2