Search in sources :

Example 6 with DataInfo

use of com.webank.wedatasphere.qualitis.metadata.response.DataInfo in project Qualitis by WeBankFinTech.

the class MetaDataClientImpl method getTableByCsId.

@Override
public DataInfo<CsTableInfoDetail> getTableByCsId(GetUserTableByCsIdRequest request) throws MetaDataAcquireFailedException, UnExpectedRequestException {
    DataInfo<CsTableInfoDetail> result = new DataInfo<>();
    List<CsTableInfoDetail> csTableInfoDetailList = new ArrayList<>();
    try {
        LOGGER.info("Start to get tables with context service ID and node name by restful API. csId: {}, nodeName: {}", request.getCsId(), request.getNodeName());
        ClusterInfo clusterInfo = checkClusterNameExists(request.getClusterName());
        String authUser = request.getLoginUser();
        // send request
        String url;
        if (clusterInfo.getClusterType().endsWith(LINKIS_ONE_VERSION)) {
            url = getPath(clusterInfo.getLinkisAddress()).path(QUERY_WORKFLOW_TABLE_PATH).toString();
        } else {
            url = getPath(clusterInfo.getLinkisAddress()).path(QUERY_CS_TABLE_PATH).toString();
        }
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_JSON);
        headers.add("Token-User", authUser);
        headers.add("Token-Code", clusterInfo.getLinkisToken());
        JSONObject jsonObject = new JSONObject();
        try {
            jsonObject.put("contextID", request.getCsId());
            jsonObject.put("nodeName", request.getNodeName());
        } catch (JSONException e) {
            LOGGER.error(e.getMessage(), e);
            throw new UnExpectedRequestException("Failed to construct http body json with context ID and node name", 500);
        }
        HttpEntity<Object> entity = new HttpEntity<>(jsonObject.toString(), headers);
        LOGGER.info("Start to get table with context service ID and node name by restful API. url: {}, method: {}, body: {}", url, javax.ws.rs.HttpMethod.POST, entity);
        Map<String, Object> response = restTemplate.exchange(url, HttpMethod.POST, entity, Map.class).getBody();
        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);
        }
        LOGGER.info("Finished to get table with context service ID and node name by restful API. response: {}", response);
        Map<String, Object> data = (Map<String, Object>) response.get("data");
        List<Map<String, Object>> tables = (List<Map<String, Object>>) data.get("tables");
        if (tables == null || tables.size() == 0) {
            return result;
        }
        LOGGER.info("Successfully to get tables with context service ID and node name by restful API. csId: {}, nodeName: {}, tables: {}", request.getCsId(), request.getNodeName(), tables);
        for (Map<String, Object> table : tables) {
            CsTableInfoDetail csTableInfoDetail = new CsTableInfoDetail();
            csTableInfoDetail.setTableName(table.get("tableName").toString());
            csTableInfoDetail.setContextKey(table.get("contextKey").toString());
            csTableInfoDetailList.add(csTableInfoDetail);
        }
        result.setContent(csTableInfoDetailList);
        result.setTotalCount(tables.size());
    } catch (RestClientException e) {
        LOGGER.error(e.getMessage(), e);
        throw new MetaDataAcquireFailedException("Error! Can not get tables by context service ID and node name", 500);
    }
    return result;
}
Also used : DataInfo(com.webank.wedatasphere.qualitis.metadata.response.DataInfo) HttpHeaders(org.springframework.http.HttpHeaders) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) HttpEntity(org.springframework.http.HttpEntity) ArrayList(java.util.ArrayList) JSONException(org.json.JSONException) CsTableInfoDetail(com.webank.wedatasphere.qualitis.metadata.response.table.CsTableInfoDetail) ClusterInfo(com.webank.wedatasphere.qualitis.entity.ClusterInfo) JSONObject(org.json.JSONObject) MetaDataAcquireFailedException(com.webank.wedatasphere.qualitis.metadata.exception.MetaDataAcquireFailedException) RestClientException(org.springframework.web.client.RestClientException) JSONObject(org.json.JSONObject) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map)

Example 7 with DataInfo

use of com.webank.wedatasphere.qualitis.metadata.response.DataInfo in project Qualitis by WeBankFinTech.

the class MetaDataClientImpl method getDbByUserAndCluster.

@Override
public DataInfo<DbInfoDetail> getDbByUserAndCluster(GetDbByUserAndClusterRequest request) throws UnExpectedRequestException, MetaDataAcquireFailedException {
    // Check existence of cluster name
    ClusterInfo clusterInfo = checkClusterNameExists(request.getClusterName());
    String authUser = request.getLoginUser();
    // send request to get dbs
    String url = getPath(clusterInfo.getLinkisAddress()).path(linkisConfig.getDbPath()).toString();
    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 db by user and cluster by linkis. 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("Start to get db by user and cluster by linkis. 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, message: " + message);
    }
    List<String> allDbs = ((List<Map<String, String>>) ((Map<String, Object>) response.get("data")).get("dbs")).stream().map(o -> o.get("dbName")).collect(Collectors.toList());
    DataInfo<DbInfoDetail> dataInfo = new DataInfo<>(allDbs.size());
    if (CollectionUtils.isEmpty(allDbs)) {
        return dataInfo;
    }
    List<DbInfoDetail> details = new ArrayList<>();
    for (String data : allDbs) {
        DbInfoDetail detail = new DbInfoDetail(data);
        details.add(detail);
    }
    dataInfo.setContent(details);
    return dataInfo;
}
Also used : ClusterInfoDetail(com.webank.wedatasphere.qualitis.metadata.response.cluster.ClusterInfoDetail) StringUtils(org.apache.commons.lang.StringUtils) GetTableByUserAndDbRequest(com.webank.wedatasphere.qualitis.metadata.request.GetTableByUserAndDbRequest) URLDecoder(java.net.URLDecoder) SpecCharEnum(com.webank.wedatasphere.qualitis.constant.SpecCharEnum) LinkisConfig(com.webank.wedatasphere.qualitis.config.LinkisConfig) LoggerFactory(org.slf4j.LoggerFactory) GetUserColumnByCsRequest(com.webank.wedatasphere.qualitis.metadata.request.GetUserColumnByCsRequest) Autowired(org.springframework.beans.factory.annotation.Autowired) ArrayList(java.util.ArrayList) GeneralResponse(com.webank.wedatasphere.qualitis.response.GeneralResponse) ClusterInfoDao(com.webank.wedatasphere.qualitis.dao.ClusterInfoDao) JSONException(org.json.JSONException) JSONObject(org.json.JSONObject) CollectionUtils(org.apache.commons.collections.CollectionUtils) Map(java.util.Map) GetUserTableByCsIdRequest(com.webank.wedatasphere.qualitis.metadata.request.GetUserTableByCsIdRequest) GetClusterByUserRequest(com.webank.wedatasphere.qualitis.metadata.request.GetClusterByUserRequest) UriBuilder(javax.ws.rs.core.UriBuilder) RestTemplate(org.springframework.web.client.RestTemplate) CsTableInfoDetail(com.webank.wedatasphere.qualitis.metadata.response.table.CsTableInfoDetail) RestClientException(org.springframework.web.client.RestClientException) PartitionStatisticsInfo(com.webank.wedatasphere.qualitis.metadata.response.table.PartitionStatisticsInfo) Logger(org.slf4j.Logger) HttpHeaders(org.springframework.http.HttpHeaders) MediaType(org.springframework.http.MediaType) HttpMethod(org.springframework.http.HttpMethod) TableInfoDetail(com.webank.wedatasphere.qualitis.metadata.response.table.TableInfoDetail) ResourceAccessException(org.springframework.web.client.ResourceAccessException) GetColumnByUserAndTableRequest(com.webank.wedatasphere.qualitis.metadata.request.GetColumnByUserAndTableRequest) ColumnInfoDetail(com.webank.wedatasphere.qualitis.metadata.response.column.ColumnInfoDetail) Collectors(java.util.stream.Collectors) LinkisResponseKeyEnum(com.webank.wedatasphere.qualitis.constant.LinkisResponseKeyEnum) DbInfoDetail(com.webank.wedatasphere.qualitis.metadata.response.db.DbInfoDetail) TableStatisticsInfo(com.webank.wedatasphere.qualitis.metadata.response.table.TableStatisticsInfo) MetaDataAcquireFailedException(com.webank.wedatasphere.qualitis.metadata.exception.MetaDataAcquireFailedException) GetDbByUserAndClusterRequest(com.webank.wedatasphere.qualitis.metadata.request.GetDbByUserAndClusterRequest) DataInfo(com.webank.wedatasphere.qualitis.metadata.response.DataInfo) List(java.util.List) HttpEntity(org.springframework.http.HttpEntity) Component(org.springframework.stereotype.Component) ClusterInfo(com.webank.wedatasphere.qualitis.entity.ClusterInfo) MetaDataClient(com.webank.wedatasphere.qualitis.metadata.client.MetaDataClient) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) DataInfo(com.webank.wedatasphere.qualitis.metadata.response.DataInfo) HttpHeaders(org.springframework.http.HttpHeaders) HttpEntity(org.springframework.http.HttpEntity) ArrayList(java.util.ArrayList) ClusterInfo(com.webank.wedatasphere.qualitis.entity.ClusterInfo) DbInfoDetail(com.webank.wedatasphere.qualitis.metadata.response.db.DbInfoDetail) 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 8 with DataInfo

use of com.webank.wedatasphere.qualitis.metadata.response.DataInfo in project Qualitis by WeBankFinTech.

the class MetaDataClientImpl method getTableByUserAndDb.

@Override
public DataInfo<TableInfoDetail> getTableByUserAndDb(GetTableByUserAndDbRequest request) throws UnExpectedRequestException, MetaDataAcquireFailedException {
    ClusterInfo clusterInfo = checkClusterNameExists(request.getClusterName());
    String authUser = request.getLoginUser();
    // send request to get dbs
    String url = getPath(clusterInfo.getLinkisAddress()).path(linkisConfig.getTablePath()).queryParam("database", request.getDbName()).toString();
    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 table by user and cluster and db by linkis. 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("Finished to get table by user and cluster and db by linkis. 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);
    }
    List<String> allTables = ((List<Map<String, String>>) ((Map<String, Object>) response.get("data")).get("tables")).stream().map(o -> o.get("tableName")).collect(Collectors.toList());
    DataInfo<TableInfoDetail> dataInfo = new DataInfo<>(allTables.size());
    if (CollectionUtils.isEmpty(allTables)) {
        return dataInfo;
    }
    List<TableInfoDetail> details = new ArrayList<>();
    for (String data : allTables) {
        TableInfoDetail detail = new TableInfoDetail(data);
        details.add(detail);
    }
    dataInfo.setContent(details);
    return dataInfo;
}
Also used : ClusterInfoDetail(com.webank.wedatasphere.qualitis.metadata.response.cluster.ClusterInfoDetail) StringUtils(org.apache.commons.lang.StringUtils) GetTableByUserAndDbRequest(com.webank.wedatasphere.qualitis.metadata.request.GetTableByUserAndDbRequest) URLDecoder(java.net.URLDecoder) SpecCharEnum(com.webank.wedatasphere.qualitis.constant.SpecCharEnum) LinkisConfig(com.webank.wedatasphere.qualitis.config.LinkisConfig) LoggerFactory(org.slf4j.LoggerFactory) GetUserColumnByCsRequest(com.webank.wedatasphere.qualitis.metadata.request.GetUserColumnByCsRequest) Autowired(org.springframework.beans.factory.annotation.Autowired) ArrayList(java.util.ArrayList) GeneralResponse(com.webank.wedatasphere.qualitis.response.GeneralResponse) ClusterInfoDao(com.webank.wedatasphere.qualitis.dao.ClusterInfoDao) JSONException(org.json.JSONException) JSONObject(org.json.JSONObject) CollectionUtils(org.apache.commons.collections.CollectionUtils) Map(java.util.Map) GetUserTableByCsIdRequest(com.webank.wedatasphere.qualitis.metadata.request.GetUserTableByCsIdRequest) GetClusterByUserRequest(com.webank.wedatasphere.qualitis.metadata.request.GetClusterByUserRequest) UriBuilder(javax.ws.rs.core.UriBuilder) RestTemplate(org.springframework.web.client.RestTemplate) CsTableInfoDetail(com.webank.wedatasphere.qualitis.metadata.response.table.CsTableInfoDetail) RestClientException(org.springframework.web.client.RestClientException) PartitionStatisticsInfo(com.webank.wedatasphere.qualitis.metadata.response.table.PartitionStatisticsInfo) Logger(org.slf4j.Logger) HttpHeaders(org.springframework.http.HttpHeaders) MediaType(org.springframework.http.MediaType) HttpMethod(org.springframework.http.HttpMethod) TableInfoDetail(com.webank.wedatasphere.qualitis.metadata.response.table.TableInfoDetail) ResourceAccessException(org.springframework.web.client.ResourceAccessException) GetColumnByUserAndTableRequest(com.webank.wedatasphere.qualitis.metadata.request.GetColumnByUserAndTableRequest) ColumnInfoDetail(com.webank.wedatasphere.qualitis.metadata.response.column.ColumnInfoDetail) Collectors(java.util.stream.Collectors) LinkisResponseKeyEnum(com.webank.wedatasphere.qualitis.constant.LinkisResponseKeyEnum) DbInfoDetail(com.webank.wedatasphere.qualitis.metadata.response.db.DbInfoDetail) TableStatisticsInfo(com.webank.wedatasphere.qualitis.metadata.response.table.TableStatisticsInfo) MetaDataAcquireFailedException(com.webank.wedatasphere.qualitis.metadata.exception.MetaDataAcquireFailedException) GetDbByUserAndClusterRequest(com.webank.wedatasphere.qualitis.metadata.request.GetDbByUserAndClusterRequest) DataInfo(com.webank.wedatasphere.qualitis.metadata.response.DataInfo) List(java.util.List) HttpEntity(org.springframework.http.HttpEntity) Component(org.springframework.stereotype.Component) ClusterInfo(com.webank.wedatasphere.qualitis.entity.ClusterInfo) MetaDataClient(com.webank.wedatasphere.qualitis.metadata.client.MetaDataClient) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) DataInfo(com.webank.wedatasphere.qualitis.metadata.response.DataInfo) HttpHeaders(org.springframework.http.HttpHeaders) HttpEntity(org.springframework.http.HttpEntity) ArrayList(java.util.ArrayList) 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) CsTableInfoDetail(com.webank.wedatasphere.qualitis.metadata.response.table.CsTableInfoDetail) TableInfoDetail(com.webank.wedatasphere.qualitis.metadata.response.table.TableInfoDetail)

Example 9 with DataInfo

use of com.webank.wedatasphere.qualitis.metadata.response.DataInfo in project Qualitis by WeBankFinTech.

the class MetaDataClientImpl method getColumnByUserAndTable.

@Override
public DataInfo<ColumnInfoDetail> getColumnByUserAndTable(GetColumnByUserAndTableRequest request) throws UnExpectedRequestException, MetaDataAcquireFailedException {
    ClusterInfo clusterInfo = checkClusterNameExists(request.getClusterName());
    String authUser = request.getLoginUser();
    // send request to get dbs
    String url = getPath(clusterInfo.getLinkisAddress()).path(linkisConfig.getColumnPath()).queryParam("database", request.getDbName()).queryParam("table", request.getTableName()).toString();
    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 column by user and cluster and db and table by linkis. 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("Finished to get table by user and cluster and and table by linkis. 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);
    }
    List<Map<String, String>> allTables = ((List<Map<String, String>>) ((Map<String, Object>) response.get("data")).get("columns"));
    DataInfo<ColumnInfoDetail> dataInfo = new DataInfo<>(allTables.size());
    if (CollectionUtils.isEmpty(allTables)) {
        return dataInfo;
    }
    List<ColumnInfoDetail> details = new ArrayList<>();
    for (Map<String, String> table : allTables) {
        ColumnInfoDetail detail = new ColumnInfoDetail(table.get("columnName"), table.get("columnType"));
        details.add(detail);
    }
    dataInfo.setContent(details);
    return dataInfo;
}
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) Map(java.util.Map)

Example 10 with DataInfo

use of com.webank.wedatasphere.qualitis.metadata.response.DataInfo in project Qualitis by WeBankFinTech.

the class MetaDataClientImpl method getClusterByUser.

@Override
public DataInfo<ClusterInfoDetail> getClusterByUser(GetClusterByUserRequest request) {
    Long total = clusterInfoDao.countAll();
    List<ClusterInfo> allCluster = clusterInfoDao.findAllClusterInfo(request.getStartIndex(), request.getPageSize());
    DataInfo<ClusterInfoDetail> dataInfo = new DataInfo<>(total.intValue());
    if (CollectionUtils.isEmpty(allCluster)) {
        return dataInfo;
    }
    List<ClusterInfoDetail> details = new ArrayList<>();
    for (ClusterInfo clusterInfo : allCluster) {
        ClusterInfoDetail detail = new ClusterInfoDetail(clusterInfo.getClusterName());
        details.add(detail);
    }
    dataInfo.setContent(details);
    return dataInfo;
}
Also used : DataInfo(com.webank.wedatasphere.qualitis.metadata.response.DataInfo) ClusterInfoDetail(com.webank.wedatasphere.qualitis.metadata.response.cluster.ClusterInfoDetail) ClusterInfo(com.webank.wedatasphere.qualitis.entity.ClusterInfo) ArrayList(java.util.ArrayList)

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