Search in sources :

Example 6 with ClusterInfo

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

the class OuterExecutionServiceImpl method getTaskLog.

@Override
public GeneralResponse<?> getTaskLog(GetTaskLogRequest request) throws UnExpectedRequestException, PermissionDeniedRequestException {
    // Check Arguments
    GetTaskLogRequest.checkRequest(request);
    Task task = taskDao.findByRemoteTaskIdAndClusterName(request.getTaskId(), request.getClusterId());
    if (task == null) {
        throw new UnExpectedRequestException("Task_id {&DOES_NOT_EXIST}");
    }
    ClusterInfo clusterInfo = clusterInfoDao.findByClusterName(request.getClusterId());
    if (clusterInfo == null) {
        throw new UnExpectedRequestException("cluster : [" + request.getClusterId() + "] {&DOES_NOT_EXIST}");
    }
    String executeUser = task.getApplication().getExecuteUser();
    // Check if user has permissions proxying execution user
    checkPermissionCreateUserProxyExecuteUser(request.getCreateUser(), executeUser);
    // Check if user has permissions to view this task
    if (!request.getCreateUser().equals(task.getApplication().getCreateUser())) {
        throw new UnExpectedRequestException(String.format("User: %s {&HAS_NO_PERMISSION_TO_ACCESS} task: %s", request.getCreateUser(), request.getTaskId()), 403);
    }
    LogResult logResult;
    try {
        logResult = monitorManager.getTaskPartialLog(request.getTaskId(), 0, executeUser, clusterInfo.getLinkisAddress(), clusterInfo.getClusterName());
    } catch (LogPartialException | ClusterInfoNotConfigException e) {
        throw new UnExpectedRequestException(e.getMessage());
    }
    LOGGER.info("Succeed to get log of the task. task_id: {}, cluster_id: {}", request.getTaskId(), request.getClusterId());
    return new GeneralResponse<>("200", "{&SUCCEED_TO_GET_TASK_LOG}", logResult.getLog());
}
Also used : GeneralResponse(com.webank.wedatasphere.qualitis.response.GeneralResponse) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) Task(com.webank.wedatasphere.qualitis.entity.Task) ClusterInfo(com.webank.wedatasphere.qualitis.entity.ClusterInfo) LogResult(com.webank.wedatasphere.qualitis.bean.LogResult) LogPartialException(com.webank.wedatasphere.qualitis.exception.LogPartialException) ClusterInfoNotConfigException(com.webank.wedatasphere.qualitis.exception.ClusterInfoNotConfigException)

Example 7 with ClusterInfo

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

the class ClusterInfoServiceImpl method addClusterInfo.

@Override
@Transactional(rollbackFor = { RuntimeException.class, UnExpectedRequestException.class })
public GeneralResponse<ClusterInfo> addClusterInfo(AddClusterInfoRequest request) throws UnExpectedRequestException {
    // 检查参数
    checkRequest(request);
    // 查看clusterName是否已存在
    String clusterName = request.getClusterName();
    String clusterType = request.getClusterType();
    String linkisAddress = request.getLinkisAddress();
    String linkisToken = request.getLinkisToken();
    ClusterInfo clusterInfoInDb = clusterInfoDao.findByClusterName(clusterName);
    if (clusterInfoInDb != null) {
        throw new UnExpectedRequestException("cluster name {&ALREADY_EXIST}");
    }
    // 创建新ClusterInfo并保存
    ClusterInfo newClusterInfo = new ClusterInfo();
    newClusterInfo.setClusterName(clusterName);
    newClusterInfo.setClusterType(clusterType);
    newClusterInfo.setLinkisAddress(linkisAddress);
    newClusterInfo.setLinkisToken(linkisToken);
    ClusterInfo savedClusterInfo = clusterInfoDao.saveClusterInfo(newClusterInfo);
    LOGGER.info("Succeed to add cluster_info, response: {}", savedClusterInfo);
    return new GeneralResponse<>("200", "{&ADD_CLUSTER_INFO_SUCCESSFULLY}", savedClusterInfo);
}
Also used : GeneralResponse(com.webank.wedatasphere.qualitis.response.GeneralResponse) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) ClusterInfo(com.webank.wedatasphere.qualitis.entity.ClusterInfo) Transactional(org.springframework.transaction.annotation.Transactional)

Example 8 with ClusterInfo

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

the class MetaDataClientImpl method getColumnInfo.

@Override
public List<ColumnInfoDetail> getColumnInfo(String clusterName, String dbName, String tableName, String userName) throws MetaDataAcquireFailedException, UnExpectedRequestException {
    ClusterInfo clusterInfo = checkClusterNameExists(clusterName);
    // send request to get table comment.
    String url = getPath(clusterInfo.getLinkisAddress()).path(linkisConfig.getColumnInfo()).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 column info 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 column info by user and cluster and db 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, Object>> tableFieldInfo = (List<Map<String, Object>>) ((Map<String, Object>) response.get("data")).get("tableFieldsInfo");
    List<ColumnInfoDetail> result = new ArrayList<>();
    for (Map<String, Object> map : tableFieldInfo) {
        ColumnInfoDetail columnInfoDetail = new ColumnInfoDetail();
        columnInfoDetail.setFieldName(map.get("name").toString());
        columnInfoDetail.setDataType(map.get("type").toString());
        if (map.get("length") != null && !"".equals(map.get("length").toString())) {
            columnInfoDetail.setColumnLen(Integer.parseInt(map.get("length").toString()));
        }
        columnInfoDetail.setColumnAlias(map.get("alias") == null ? "" : map.get("alias").toString());
        columnInfoDetail.setColumnComment(map.get("comment") == null ? "" : map.get("comment").toString());
        columnInfoDetail.setPrimary((Boolean) map.get("primary"));
        columnInfoDetail.setPartitionField((Boolean) map.get("partitionField"));
        result.add(columnInfoDetail);
    }
    return result;
}
Also used : 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 9 with ClusterInfo

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

the class MetaDataClientImpl method getDataSourceVersions.

@Override
public GeneralResponse<Map> getDataSourceVersions(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.getDatasourceVersions()).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 versions 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 versions 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("versions");
    return new GeneralResponse<>("200", "Success to get datasource version", 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) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map)

Example 10 with ClusterInfo

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

the class MetaDataClientImpl method getTablesByDataSource.

@Override
public Map getTablesByDataSource(String clusterName, String authUser, Long dataSourceId, String dbName) throws UnExpectedRequestException, MetaDataAcquireFailedException {
    // Check existence of cluster name
    ClusterInfo clusterInfo = checkClusterNameExists(clusterName);
    // send request to get dbs
    String url = getPath(clusterInfo.getLinkisAddress()).path(linkisConfig.getDatasourceTable()).queryParam("system", "Qualitis").toString().replace("{DATA_SOURCE_ID}", dataSourceId.toString()).replace("{DATA_SOURCE_DB}", dbName);
    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 tables 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 tables 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> tables = (List<Map>) data.get("tables");
    if (CollectionUtils.isEmpty(tables)) {
        LOGGER.info("No tables 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)

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