Search in sources :

Example 16 with ClusterInfo

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

the class MetaDataClientImpl method modifyDataSource.

@Override
public GeneralResponse<Map> modifyDataSource(String clusterName, String authUser, Long dataSourceId, String jsonRequest) throws UnExpectedRequestException, MetaDataAcquireFailedException {
    // Check existence of cluster name
    ClusterInfo clusterInfo = checkClusterNameExists(clusterName);
    // send request to get dbs
    String url = getPath(clusterInfo.getLinkisAddress()).path(linkisConfig.getDatasourceModify()).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<>(jsonRequest, headers);
    LOGGER.info("Start to modify data source by user and cluster by linkis. url: {}, method: {}, body: {}", url, javax.ws.rs.HttpMethod.PUT, entity);
    Map<String, Object> response = restTemplate.exchange(url, HttpMethod.PUT, entity, Map.class).getBody();
    LOGGER.info("Finish to modify data source 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 modify datasource", 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) Map(java.util.Map)

Example 17 with ClusterInfo

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

the class MetaDataClientImpl method getDbsByDataSource.

@Override
public Map getDbsByDataSource(String clusterName, String authUser, Long dataSourceId) throws UnExpectedRequestException, MetaDataAcquireFailedException {
    // Check existence of cluster name
    ClusterInfo clusterInfo = checkClusterNameExists(clusterName);
    // send request to get dbs
    String url = getPath(clusterInfo.getLinkisAddress()).path(linkisConfig.getDatasourceDb()).queryParam("system", "Qualitis").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 dbs 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 dbs 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());
    List<Map> dbs = (List<Map>) data.get("dbs");
    if (CollectionUtils.isEmpty(dbs)) {
        LOGGER.info("No dbs with data source to be choosed.");
    }
    return data;
}
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) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map)

Example 18 with ClusterInfo

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

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

the class MetaDataClientImpl method createDataSource.

@Override
public GeneralResponse<Map> createDataSource(String clusterName, String authUser, String jsonRequest) throws UnExpectedRequestException, MetaDataAcquireFailedException {
    // Check existence of cluster name
    ClusterInfo clusterInfo = checkClusterNameExists(clusterName);
    // send request to get dbs
    String url = getPath(clusterInfo.getLinkisAddress()).path(linkisConfig.getDatasourceCreate()).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<>(jsonRequest, headers);
    LOGGER.info("Start to create data source by user and cluster by linkis. url: {}, method: {}, body: {}", url, javax.ws.rs.HttpMethod.POST, entity);
    Map<String, Object> response = restTemplate.exchange(url, HttpMethod.POST, entity, Map.class).getBody();
    LOGGER.info("Finish to create data source 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 create datasource", 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) Map(java.util.Map)

Example 20 with ClusterInfo

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

the class MetaDataClientImpl method getDataSourceInfoPage.

@Override
public GeneralResponse<Map> getDataSourceInfoPage(String clusterName, String authUser, int page, int size, String searchName, Long typeId) throws UnExpectedRequestException, MetaDataAcquireFailedException, UnsupportedEncodingException {
    // Check existence of cluster name
    ClusterInfo clusterInfo = checkClusterNameExists(clusterName);
    // send request to get dbs
    UriBuilder uriBuilder = getPath(clusterInfo.getLinkisAddress()).path(linkisConfig.getDatasourceInfo()).queryParam("currentPage", page).queryParam("pageSize", size);
    if (StringUtils.isNotBlank(searchName)) {
        uriBuilder.queryParam("name", searchName);
    }
    if (typeId != null) {
        uriBuilder.queryParam("typeId", typeId);
    }
    String url = uriBuilder.toString();
    url = URLDecoder.decode(url, "UTF-8");
    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 info 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 info 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());
    List<Map> types = (List<Map>) data.get("query_list");
    return new GeneralResponse<>("200", "Success to get datasource info", data);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) HttpEntity(org.springframework.http.HttpEntity) GeneralResponse(com.webank.wedatasphere.qualitis.response.GeneralResponse) 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) UriBuilder(javax.ws.rs.core.UriBuilder) 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