Search in sources :

Example 26 with ClusterInfo

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

the class MultiSourceRuleServiceImpl method addMultiSourceRuleReal.

private GeneralResponse<RuleResponse> addMultiSourceRuleReal(AddMultiSourceRuleRequest request, boolean check) throws UnExpectedRequestException, PermissionDeniedRequestException {
    // Check Arguments
    CommonChecker.checkObject(request, "Request");
    String csId = request.getCsId();
    boolean cs = false;
    if (StringUtils.isNotBlank(csId)) {
        cs = true;
    }
    AddMultiSourceRuleRequest.checkRequest(request, false, cs);
    String loginUser = "";
    if (request.getLoginUser() != null) {
        loginUser = request.getLoginUser();
        LOGGER.info("Recover user[{}] from is adding rule.", loginUser);
    } else {
        loginUser = HttpUtils.getUserName(httpServletRequest);
    }
    LOGGER.info("Check permission user[{}] who is adding rule.", loginUser);
    // Check existence of project
    Project projectInDb = projectService.checkProjectExistence(request.getProjectId(), loginUser);
    // Check permissions of project
    if (check) {
        List<Integer> permissions = new ArrayList<>();
        permissions.add(ProjectUserPermissionEnum.DEVELOPER.getCode());
        projectService.checkProjectPermission(projectInDb, loginUser, permissions);
    }
    // Check existence of rule name
    ruleService.checkRuleName(request.getRuleName(), projectInDb, null);
    // Check existence of cluster
    ClusterInfo clusterInfo = clusterInfoDao.findByClusterName(request.getClusterName());
    if (clusterInfo == null) {
        throw new UnExpectedRequestException("Cluster :" + request.getClusterName() + " {&DOES_NOT_EXIST}");
    }
    // Check existence of id and check if multi-table rule
    Template templateInDb = ruleTemplateService.checkRuleTemplate(request.getMultiSourceRuleTemplateId());
    if (!templateInDb.getTemplateType().equals(RuleTemplateTypeEnum.MULTI_SOURCE_TEMPLATE.getCode())) {
        throw new UnExpectedRequestException("Template id :" + request.getMultiSourceRuleTemplateId() + " {&IS_NOT_A_MULTI_SOURCE_TEMPLATE}");
    }
    RuleGroup ruleGroup;
    if (request.getRuleGroupId() != null) {
        ruleGroup = ruleGroupDao.findById(request.getRuleGroupId());
        if (ruleGroup == null) {
            throw new UnExpectedRequestException(String.format("Rule Group: %s {&CAN_NOT_BE_NULL_OR_EMPTY}", request.getRuleGroupId()));
        }
    } else {
        ruleGroup = ruleGroupDao.saveRuleGroup(new RuleGroup("Group_" + UUID.randomUUID().toString().replace("-", ""), projectInDb.getId()));
    }
    String leftUuid = UuidGenerator.generate();
    String rightUuid = UuidGenerator.generate();
    Rule savedRule = generateRule(request, projectInDb, false, null, false, cs, leftUuid, rightUuid, loginUser);
    savedRule.setRuleGroup(ruleGroup);
    savedRule.setSpecifyStaticStartupParam(request.getSpecifyStaticStartupParam());
    if (request.getSpecifyStaticStartupParam() != null && request.getSpecifyStaticStartupParam()) {
        savedRule.setStaticStartupParam(request.getStaticStartupParam());
    }
    savedRule = ruleDao.saveRule(savedRule);
    if (templateInDb.getChildTemplate() != null) {
        // Generate child rule
        AddMultiSourceRuleRequest addMultiSourceRuleRequest = generateChildRequest(request, templateInDb.getChildTemplate());
        Rule childRule = generateRule(addMultiSourceRuleRequest, null, false, null, true, cs, leftUuid, rightUuid, loginUser);
        childRule.setParentRule(savedRule);
        ruleDao.saveRule(childRule);
    }
    RuleResponse response = new RuleResponse(savedRule);
    LOGGER.info("Succeed to add multi source rule, rule_id: {}", savedRule.getId());
    return new GeneralResponse<>("200", "{&ADD_MULTI_RULE_SUCCESSFULLY}", response);
}
Also used : UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) RuleResponse(com.webank.wedatasphere.qualitis.rule.response.RuleResponse) GeneralResponse(com.webank.wedatasphere.qualitis.response.GeneralResponse) Project(com.webank.wedatasphere.qualitis.project.entity.Project) ClusterInfo(com.webank.wedatasphere.qualitis.entity.ClusterInfo)

Example 27 with ClusterInfo

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

the class RuleLimitationServiceImpl method getLimitClusters.

/**
 * Get supported cluster
 * @return
 */
@Override
public Set<String> getLimitClusters() {
    List<ClusterInfo> clusters = clusterInfoDao.findAllClusterInfo(0, Integer.MAX_VALUE);
    if (clusters == null || clusters.isEmpty()) {
        return null;
    }
    Set<String> results = new HashSet<>();
    for (ClusterInfo info : clusters) {
        results.add(info.getClusterName());
    }
    return results;
}
Also used : ClusterInfo(com.webank.wedatasphere.qualitis.entity.ClusterInfo) HashSet(java.util.HashSet)

Example 28 with ClusterInfo

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

the class MetaDataClientImpl method getDataSourceKeyDefine.

@Override
public GeneralResponse<Map> getDataSourceKeyDefine(String clusterName, String authUser, Long keyId) throws UnExpectedRequestException, MetaDataAcquireFailedException {
    // Check existence of cluster name
    ClusterInfo clusterInfo = checkClusterNameExists(clusterName);
    // send request to get dbs
    String url = getPath(clusterInfo.getLinkisAddress()).path(linkisConfig.getDatasourceKeyDefine()).path(keyId.toString()).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 key define 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 key define 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 key define", 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 29 with ClusterInfo

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

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

the class MetaDataClientImpl method getAllDataSourceTypes.

@Override
public GeneralResponse<Map> getAllDataSourceTypes(String clusterName, String authUser) throws UnExpectedRequestException, MetaDataAcquireFailedException {
    // Check existence of cluster name
    ClusterInfo clusterInfo = checkClusterNameExists(clusterName);
    // send request to get dbs
    String url = getPath(clusterInfo.getLinkisAddress()).path(linkisConfig.getDatasourceTypes()).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 types 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 types 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("type_list");
    return new GeneralResponse<>("200", "Success to get all datasource types", 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)

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