Search in sources :

Example 1 with DbInfoDetail

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

the class MetaDataServiceImpl method getUserDbByCluster.

@Override
public GeneralResponse<GetAllResponse<DbInfoDetail>> getUserDbByCluster(GetUserDbByClusterRequest request) throws UnExpectedRequestException, MetaDataAcquireFailedException {
    // Check Arguments
    checkRequest(request);
    // Get login user
    String userName = HttpUtils.getUserName(httpServletRequest);
    if (StringUtils.isNotBlank(request.getProxyUser())) {
        userName = request.getProxyUser();
    }
    GetDbByUserAndClusterRequest getDbByUserAndClusterRequest = new GetDbByUserAndClusterRequest(userName, request.getStartIndex(), request.getPageSize(), request.getClusterName());
    DataInfo<DbInfoDetail> response = metaDataClient.getDbByUserAndCluster(getDbByUserAndClusterRequest);
    GetAllResponse<DbInfoDetail> result = new GetAllResponse<>();
    result.setTotal(response.getTotalCount());
    result.setData(response.getContent());
    LOGGER.info("Succeed to get database by cluster, cluster: {}", request.getClusterName());
    return new GeneralResponse<>("200", "{&GET_DB_SUCCESSFULLY}", result);
}
Also used : GeneralResponse(com.webank.wedatasphere.qualitis.response.GeneralResponse) DbInfoDetail(com.webank.wedatasphere.qualitis.metadata.response.db.DbInfoDetail) GetDbByUserAndClusterRequest(com.webank.wedatasphere.qualitis.metadata.request.GetDbByUserAndClusterRequest) GetAllResponse(com.webank.wedatasphere.qualitis.response.GetAllResponse)

Example 2 with DbInfoDetail

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

the class MetaDataController method getDbsByDataSource.

@GET
@Path("data_source/dbs")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public GeneralResponse<GetAllResponse<DbInfoDetail>> getDbsByDataSource(@QueryParam("clusterName") String clusterName, @QueryParam("proxyUser") String proxyUser, @QueryParam("dataSourceId") Long dataSourceId) {
    try {
        if (dataSourceId == null || StringUtils.isBlank(clusterName)) {
            throw new UnExpectedRequestException("Request " + "{&CAN_NOT_BE_NULL_OR_EMPTY}");
        }
        Map response = metaDataService.getDbsByDataSource(clusterName, proxyUser, dataSourceId);
        GetAllResponse allResponse = new GetAllResponse();
        List<String> dbs = (List<String>) response.get("dbs");
        List<DbInfoDetail> dbInfoDetails = new ArrayList<>(CollectionUtils.isEmpty(dbs) ? 0 : dbs.size());
        for (String db : dbs) {
            DbInfoDetail dbInfoDetail = new DbInfoDetail(db);
            dbInfoDetails.add(dbInfoDetail);
        }
        allResponse.setTotal(CollectionUtils.isEmpty(dbInfoDetails) ? 0 : dbInfoDetails.size());
        allResponse.setData(dbInfoDetails);
        return new GeneralResponse<>("200", "{&GET_DB_SUCCESSFULLY}", allResponse);
    } catch (MetaDataAcquireFailedException e) {
        LOGGER.error(e.getMessage(), e);
        return new GeneralResponse<>("500", e.getMessage(), null);
    } catch (UnExpectedRequestException e) {
        LOGGER.error(e.getMessage(), e);
        return new GeneralResponse<>("500", e.getMessage(), null);
    } catch (Exception e) {
        LOGGER.error(e.getMessage(), e);
        return new GeneralResponse<>("500", "{&FAILED_TO_GET_DATABASE_BY_CLUSTER}", null);
    }
}
Also used : UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) ArrayList(java.util.ArrayList) ResourceAccessException(org.springframework.web.client.ResourceAccessException) MetaDataAcquireFailedException(com.webank.wedatasphere.qualitis.metadata.exception.MetaDataAcquireFailedException) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) GeneralResponse(com.webank.wedatasphere.qualitis.response.GeneralResponse) DbInfoDetail(com.webank.wedatasphere.qualitis.metadata.response.db.DbInfoDetail) MetaDataAcquireFailedException(com.webank.wedatasphere.qualitis.metadata.exception.MetaDataAcquireFailedException) ArrayList(java.util.ArrayList) List(java.util.List) GetAllResponse(com.webank.wedatasphere.qualitis.response.GetAllResponse) Map(java.util.Map) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes) GET(javax.ws.rs.GET)

Example 3 with DbInfoDetail

use of com.webank.wedatasphere.qualitis.metadata.response.db.DbInfoDetail 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)

Aggregations

DbInfoDetail (com.webank.wedatasphere.qualitis.metadata.response.db.DbInfoDetail)3 GeneralResponse (com.webank.wedatasphere.qualitis.response.GeneralResponse)3 UnExpectedRequestException (com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException)2 MetaDataAcquireFailedException (com.webank.wedatasphere.qualitis.metadata.exception.MetaDataAcquireFailedException)2 GetDbByUserAndClusterRequest (com.webank.wedatasphere.qualitis.metadata.request.GetDbByUserAndClusterRequest)2 GetAllResponse (com.webank.wedatasphere.qualitis.response.GetAllResponse)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Map (java.util.Map)2 ResourceAccessException (org.springframework.web.client.ResourceAccessException)2 LinkisConfig (com.webank.wedatasphere.qualitis.config.LinkisConfig)1 LinkisResponseKeyEnum (com.webank.wedatasphere.qualitis.constant.LinkisResponseKeyEnum)1 SpecCharEnum (com.webank.wedatasphere.qualitis.constant.SpecCharEnum)1 ClusterInfoDao (com.webank.wedatasphere.qualitis.dao.ClusterInfoDao)1 ClusterInfo (com.webank.wedatasphere.qualitis.entity.ClusterInfo)1 MetaDataClient (com.webank.wedatasphere.qualitis.metadata.client.MetaDataClient)1 GetClusterByUserRequest (com.webank.wedatasphere.qualitis.metadata.request.GetClusterByUserRequest)1 GetColumnByUserAndTableRequest (com.webank.wedatasphere.qualitis.metadata.request.GetColumnByUserAndTableRequest)1 GetTableByUserAndDbRequest (com.webank.wedatasphere.qualitis.metadata.request.GetTableByUserAndDbRequest)1 GetUserColumnByCsRequest (com.webank.wedatasphere.qualitis.metadata.request.GetUserColumnByCsRequest)1