Search in sources :

Example 36 with ClusterInfo

use of com.webank.wedatasphere.qualitis.entity.ClusterInfo 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 37 with ClusterInfo

use of com.webank.wedatasphere.qualitis.entity.ClusterInfo in project Qualitis by WeBankFinTech.

the class MetaDataClientImpl method getDataSourceConnectParams.

@Override
public GeneralResponse<Map> getDataSourceConnectParams(String clusterName, String authUser, Long dataSourceId, Long versionId) throws UnExpectedRequestException, MetaDataAcquireFailedException {
    // Check existence of cluster name
    ClusterInfo clusterInfo = checkClusterNameExists(clusterName);
    // send request to get dbs
    UriBuilder uriBuilder = getPath(clusterInfo.getLinkisAddress()).path(linkisConfig.getDatasourceConnectParam());
    if (versionId != null) {
        uriBuilder.path(versionId.toString());
    }
    String url = uriBuilder.toString().replace("{DATA_SOURCE_ID}", dataSourceId.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 data source connect params 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("Finish to get data source connect params 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, exception: " + message);
    }
    Map data = (Map) response.get(LinkisResponseKeyEnum.DATA.getKey());
    return new GeneralResponse<>("200", "Success to get datasource connect params", data);
}
Also used : GeneralResponse(com.webank.wedatasphere.qualitis.response.GeneralResponse) HttpHeaders(org.springframework.http.HttpHeaders) ClusterInfo(com.webank.wedatasphere.qualitis.entity.ClusterInfo) HttpEntity(org.springframework.http.HttpEntity) MetaDataAcquireFailedException(com.webank.wedatasphere.qualitis.metadata.exception.MetaDataAcquireFailedException) JSONObject(org.json.JSONObject) UriBuilder(javax.ws.rs.core.UriBuilder) Map(java.util.Map)

Example 38 with ClusterInfo

use of com.webank.wedatasphere.qualitis.entity.ClusterInfo 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)

Example 39 with ClusterInfo

use of com.webank.wedatasphere.qualitis.entity.ClusterInfo in project Qualitis by WeBankFinTech.

the class MetaDataClientImpl method getTableStatisticsInfo.

@Override
public TableStatisticsInfo getTableStatisticsInfo(String clusterName, String dbName, String tableName, String userName) throws UnExpectedRequestException, MetaDataAcquireFailedException, RestClientException {
    ClusterInfo clusterInfo = checkClusterNameExists(clusterName);
    // send request to get dbs
    String url = getPath(clusterInfo.getLinkisAddress()).path(linkisConfig.getTableStatistics()).queryParam("database", dbName).queryParam("tableName", tableName).toString();
    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_JSON);
    headers.add("Token-User", userName);
    headers.add("Token-Code", clusterInfo.getLinkisToken());
    HttpEntity<Object> entity = new HttpEntity<>(headers);
    LOGGER.info("Start to get table info by linkis. url: {}, method: {}, body: {}", url, javax.ws.rs.HttpMethod.GET, entity);
    Map<String, Object> response;
    try {
        response = restTemplate.exchange(url, HttpMethod.GET, entity, Map.class).getBody();
    } catch (ResourceAccessException e) {
        LOGGER.error(e.getMessage(), e);
        throw new MetaDataAcquireFailedException("Error! Can not get table info from linkis, exception: " + e.getMessage(), 500);
    }
    LOGGER.info("Finish to get table info 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 table info from linkis, exception: " + message);
    }
    Map<String, Object> result = (Map<String, Object>) ((Map<String, Object>) response.get("data")).get("tableStatisticInfo");
    TableStatisticsInfo tableStatisticsInfo = new TableStatisticsInfo();
    tableStatisticsInfo.setTableFileCount(Integer.parseInt(result.get("fileNum").toString()));
    tableStatisticsInfo.setTableSize(result.get("tableSize").toString());
    tableStatisticsInfo.setPartitions((List<Map>) result.get("partitions"));
    return tableStatisticsInfo;
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) ClusterInfo(com.webank.wedatasphere.qualitis.entity.ClusterInfo) HttpEntity(org.springframework.http.HttpEntity) MetaDataAcquireFailedException(com.webank.wedatasphere.qualitis.metadata.exception.MetaDataAcquireFailedException) JSONObject(org.json.JSONObject) TableStatisticsInfo(com.webank.wedatasphere.qualitis.metadata.response.table.TableStatisticsInfo) Map(java.util.Map) ResourceAccessException(org.springframework.web.client.ResourceAccessException)

Example 40 with ClusterInfo

use of com.webank.wedatasphere.qualitis.entity.ClusterInfo in project Qualitis by WeBankFinTech.

the class MetaDataClientImpl method getColumnByCsId.

@Override
public DataInfo<ColumnInfoDetail> getColumnByCsId(GetUserColumnByCsRequest request) throws MetaDataAcquireFailedException, UnExpectedRequestException {
    DataInfo<ColumnInfoDetail> result = new DataInfo<>();
    List<ColumnInfoDetail> list = new ArrayList<>();
    try {
        LOGGER.info("Start to get columns with context service ID and table's context key. csId: {}, contextKey: {}", request.getCsId(), request.getContextKey());
        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_COLUMN_PATH).toString();
        } else {
            url = getPath(clusterInfo.getLinkisAddress()).path(QUERY_CS_COLUMN_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("contextKey", request.getContextKey());
        } catch (JSONException e) {
            LOGGER.error("Failed to construct http body json, exception is : {}", e);
        }
        HttpEntity<Object> entity = new HttpEntity<>(jsonObject.toString(), headers);
        LOGGER.info("Start to get column with context service ID and table's context key 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 column with context service ID and table's context key by restful API. response: {}", response);
        Map<String, Object> data = (Map<String, Object>) response.get("data");
        List<Map<String, Object>> columns = (List<Map<String, Object>>) data.get("columns");
        if (columns == null || columns.size() == 0) {
            return result;
        }
        LOGGER.info("Successfully to get columns with context service ID and table's context key by restful API. csId: {}, contextKey: {}", request.getCsId(), request.getContextKey());
        for (Map<String, Object> column : columns) {
            ColumnInfoDetail columnInfoDetail = new ColumnInfoDetail();
            columnInfoDetail.setFieldName(column.get("columnName").toString());
            columnInfoDetail.setDataType(column.get("columnType").toString());
            columnInfoDetail.setColumnComment(column.get("columnComment") == null ? "" : column.get("columnComment").toString());
            columnInfoDetail.setPartitionField((Boolean) column.get("partitioned"));
            list.add(columnInfoDetail);
        }
        result.setTotalCount(columns.size());
        result.setContent(list);
    } catch (RestClientException e) {
        LOGGER.error(e.getMessage(), e);
        throw new MetaDataAcquireFailedException("Error! Can not get column by context service ID", 500);
    }
    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) JSONException(org.json.JSONException) ColumnInfoDetail(com.webank.wedatasphere.qualitis.metadata.response.column.ColumnInfoDetail) 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)

Aggregations

ClusterInfo (com.webank.wedatasphere.qualitis.entity.ClusterInfo)41 Map (java.util.Map)31 HttpEntity (org.springframework.http.HttpEntity)28 HttpHeaders (org.springframework.http.HttpHeaders)28 MetaDataAcquireFailedException (com.webank.wedatasphere.qualitis.metadata.exception.MetaDataAcquireFailedException)27 JSONObject (org.json.JSONObject)26 GeneralResponse (com.webank.wedatasphere.qualitis.response.GeneralResponse)25 ArrayList (java.util.ArrayList)18 UnExpectedRequestException (com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException)17 List (java.util.List)14 ColumnInfoDetail (com.webank.wedatasphere.qualitis.metadata.response.column.ColumnInfoDetail)7 UriBuilder (javax.ws.rs.core.UriBuilder)7 DataInfo (com.webank.wedatasphere.qualitis.metadata.response.DataInfo)6 Task (com.webank.wedatasphere.qualitis.entity.Task)5 PartitionStatisticsInfo (com.webank.wedatasphere.qualitis.metadata.response.table.PartitionStatisticsInfo)5 LinkisConfig (com.webank.wedatasphere.qualitis.config.LinkisConfig)4 ClusterInfoDao (com.webank.wedatasphere.qualitis.dao.ClusterInfoDao)4 TableStatisticsInfo (com.webank.wedatasphere.qualitis.metadata.response.table.TableStatisticsInfo)4 JSONException (org.json.JSONException)4 RestClientException (org.springframework.web.client.RestClientException)4