Search in sources :

Example 41 with UnExpectedRequestException

use of com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException in project Qualitis by WeBankFinTech.

the class IndexController method getTodaySubmitApplications.

/**
 * Paging get applications information that was submitted today.
 * Including details of applications
 * @return
 */
@POST
@Path("application/today")
@Produces(MediaType.APPLICATION_JSON)
public GeneralResponse<?> getTodaySubmitApplications(@Context HttpServletRequest httpServletRequest, PageRequest pageRequest) throws UnExpectedRequestException {
    PageRequest.checkRequest(pageRequest);
    String user = HttpUtils.getUserName(httpServletRequest);
    try {
        IndexApplicationTodayResponse response = indexService.getTodaySubmitApplications(user, pageRequest);
        return new GeneralResponse<>("200", "{&QUERY_SUCCESSFULLY}", response);
    } catch (Exception e) {
        LOG.error("[Home overview]Failed to query API: application/today, internal error", e);
        return new GeneralResponse<>("500", e.getMessage(), -1);
    }
}
Also used : GeneralResponse(com.webank.wedatasphere.qualitis.response.GeneralResponse) IndexApplicationTodayResponse(com.webank.wedatasphere.qualitis.response.IndexApplicationTodayResponse) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces)

Example 42 with UnExpectedRequestException

use of com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException in project Qualitis by WeBankFinTech.

the class LinkisConfigurationController method getFullTree.

@GET
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public GeneralResponse<?> getFullTree(@QueryParam("cluster_name") String clusterName) throws UnExpectedRequestException {
    String userName = HttpUtils.getUserName(httpServletRequest);
    try {
        Map<String, Map> reponse = linkisConfiguration.getFullTree(clusterName, userName);
        LinkisConfigurationResponse linkisConfigurationResponse = new LinkisConfigurationResponse();
        linkisConfigurationResponse.setQueueName(reponse.get("full_tree_queue_name"));
        linkisConfigurationResponse.setQueue(reponse.get("full_tree"));
        return new GeneralResponse<>("200", "{&SUCCESS_TO_GET_STARTUP_PATAM}", reponse);
    } catch (UnExpectedRequestException e) {
        throw new UnExpectedRequestException(e.getMessage());
    } catch (Exception e) {
        LOGGER.error("Failed to , caused by: {}", e.getMessage(), e);
        return new GeneralResponse<>("500", "{&FAILED_TO_GET_STARTUP_PATAM}", null);
    }
}
Also used : GeneralResponse(com.webank.wedatasphere.qualitis.response.GeneralResponse) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) LinkisConfigurationResponse(com.webank.wedatasphere.qualitis.response.LinkisConfigurationResponse) Map(java.util.Map) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes) GET(javax.ws.rs.GET)

Example 43 with UnExpectedRequestException

use of com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException in project Qualitis by WeBankFinTech.

the class MetaDataClientImpl method getPartitionStatisticsInfo.

@Override
public PartitionStatisticsInfo getPartitionStatisticsInfo(String clusterName, String dbName, String tableName, String partitionPath, String userName) throws UnExpectedRequestException, MetaDataAcquireFailedException, RestClientException {
    ClusterInfo clusterInfo = checkClusterNameExists(clusterName);
    // send request to get dbs
    String url = getPath(clusterInfo.getLinkisAddress()).path(linkisConfig.getPartitionStatistics()).queryParam("database", dbName).queryParam("tableName", tableName).queryParam("partitionPath", partitionPath).toString();
    try {
        url = URLDecoder.decode(url, "UTF-8");
    } catch (UnsupportedEncodingException e) {
        LOGGER.error(e.getMessage(), e);
        throw new UnExpectedRequestException("Decode get partition statistic info exception", 500);
    }
    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 partition info by linkis. url: {}, method: {}, body: {}", url, javax.ws.rs.HttpMethod.GET, entity);
    Map<String, Object> response = null;
    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 partition info from linkis, exception: " + e.getMessage(), 500);
    }
    LOGGER.info("Finish to get partition 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 partition info from linkis, exception: " + message);
    }
    Map<String, Object> result = (Map<String, Object>) ((Map<String, Object>) response.get("data")).get("partitionStatisticInfo");
    PartitionStatisticsInfo partitionStatisticsInfo = new PartitionStatisticsInfo();
    partitionStatisticsInfo.setPartitionChildCount(Integer.parseInt(result.get("fileNum").toString()));
    partitionStatisticsInfo.setPartitionSize(result.get("partitionSize").toString());
    partitionStatisticsInfo.setPartitions((List<Map>) result.get("childrens"));
    return partitionStatisticsInfo;
}
Also used : UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) HttpHeaders(org.springframework.http.HttpHeaders) HttpEntity(org.springframework.http.HttpEntity) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ResourceAccessException(org.springframework.web.client.ResourceAccessException) ClusterInfo(com.webank.wedatasphere.qualitis.entity.ClusterInfo) MetaDataAcquireFailedException(com.webank.wedatasphere.qualitis.metadata.exception.MetaDataAcquireFailedException) JSONObject(org.json.JSONObject) PartitionStatisticsInfo(com.webank.wedatasphere.qualitis.metadata.response.table.PartitionStatisticsInfo) Map(java.util.Map)

Example 44 with UnExpectedRequestException

use of com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException in project Qualitis by WeBankFinTech.

the class DateExprReplaceUtil method replaceFilter.

public static String replaceFilter(Date date, String filter) throws UnExpectedRequestException {
    Matcher matcher = CUSTOM_PLACEHOLODER_PATTERN.matcher(filter);
    while (matcher.find()) {
        String replaceStr = matcher.group();
        boolean legalSystemParams = replaceStr.contains("run_date") || replaceStr.contains("run_date_std");
        if (!legalSystemParams) {
            throw new UnExpectedRequestException("Custom placeholoder must be system variables.");
        }
        String currentParam = replaceStr.substring(2, replaceStr.length() - 1);
        String dateStr = "";
        Calendar calendar = Calendar.getInstance();
        if (currentParam.contains(SpecCharEnum.MINUS.getValue())) {
            String[] keys = currentParam.split(SpecCharEnum.MINUS.getValue());
            int forwayDay = Integer.parseInt(keys[1]);
            calendar.setTime(date);
            calendar.add(Calendar.DATE, 0 - forwayDay - 1);
            dateStr = new SimpleDateFormat(RUN_DATE_FORMAT.get(keys[0])).format(calendar.getTime());
        } else {
            calendar.setTime(date);
            calendar.add(Calendar.DATE, -1);
            dateStr = new SimpleDateFormat(RUN_DATE_FORMAT.get(currentParam)).format(calendar.getTime());
        }
        filter = filter.replace(replaceStr, dateStr);
    }
    return filter;
}
Also used : UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) Matcher(java.util.regex.Matcher) Calendar(java.util.Calendar) SimpleDateFormat(java.text.SimpleDateFormat)

Example 45 with UnExpectedRequestException

use of com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException in project Qualitis by WeBankFinTech.

the class MetaDataServiceImpl method constructRequest.

private AddMultiSourceRuleRequest constructRequest(MulDbRequest request, FilterRequest filterRequest, String currentSourceTable, String currentTargetTable, int index, int total, String loginUser) throws UnExpectedRequestException, MetaDataAcquireFailedException, IOException {
    LOGGER.info("Start to construct add multi source rule request.");
    // rule basic info.
    AddMultiSourceRuleRequest addMultiSourceRuleRequest = new AddMultiSourceRuleRequest();
    basicInfo(addMultiSourceRuleRequest, request, index, total);
    MultiDataSourceConfigRequest sourceConfigRequest = new MultiDataSourceConfigRequest();
    sourceConfigRequest.setLinkisDataSourceName(request.getSourceLinkisDataSourceName());
    sourceConfigRequest.setLinkisDataSourceType(request.getSourceLinkisDataSourceType());
    sourceConfigRequest.setLinkisDataSourceId(request.getSourceLinkisDataSourceId());
    sourceConfigRequest.setProxyUser(request.getProxyUser());
    sourceConfigRequest.setDbName(request.getSourceDb());
    sourceConfigRequest.setContextService(false);
    MultiDataSourceConfigRequest targetConfigRequest = new MultiDataSourceConfigRequest();
    targetConfigRequest.setLinkisDataSourceName(request.getTargetLinkisDataSourceName());
    targetConfigRequest.setLinkisDataSourceType(request.getTargetLinkisDataSourceType());
    targetConfigRequest.setLinkisDataSourceId(request.getTargetLinkisDataSourceId());
    targetConfigRequest.setProxyUser(request.getProxyUser());
    targetConfigRequest.setDbName(request.getTargetDb());
    targetConfigRequest.setContextService(false);
    if (filterRequest == null) {
        // source table and target table
        sourceConfigRequest.setTableName(currentSourceTable);
        sourceConfigRequest.setFilter("true");
        targetConfigRequest.setTableName(currentTargetTable);
        targetConfigRequest.setFilter("true");
        addMultiSourceRuleRequest.setMultiSourceRuleTemplateId(20L);
        List<AlarmConfigRequest> alarmConfigRequests = new ArrayList<>();
        alarmConfigRequests.add(new AlarmConfigRequest(645L, CheckTemplateEnum.FIXED_VALUE.getCode(), CompareTypeEnum.EQUAL.getCode(), 0.0));
        addMultiSourceRuleRequest.setAlarmVariable(alarmConfigRequests);
    } else {
        sourceConfigRequest.setTableName(filterRequest.getSourceTable());
        if (StringUtils.isNotBlank(filterRequest.getSourceFilter())) {
            sourceConfigRequest.setFilter("! (" + filterRequest.getSourceFilter() + ")");
        } else {
            sourceConfigRequest.setFilter("true");
        }
        targetConfigRequest.setTableName(filterRequest.getTargetTable());
        if (StringUtils.isNotBlank(filterRequest.getTargetFilter())) {
            targetConfigRequest.setFilter("! (" + filterRequest.getTargetFilter() + ")");
        } else {
            targetConfigRequest.setFilter("true");
        }
        addMultiSourceRuleRequest.setMultiSourceRuleTemplateId(17L);
        List<AlarmConfigRequest> alarmConfigRequests = new ArrayList<>();
        alarmConfigRequests.add(new AlarmConfigRequest(33L, CheckTemplateEnum.FIXED_VALUE.getCode(), CompareTypeEnum.EQUAL.getCode(), 0.0));
        addMultiSourceRuleRequest.setAlarmVariable(alarmConfigRequests);
    }
    addMultiSourceRuleRequest.setSource(sourceConfigRequest);
    addMultiSourceRuleRequest.setTarget(targetConfigRequest);
    // All fields mappings
    LOGGER.info("Start to get all fields with source database's table and target database's table.");
    List<ColumnInfoDetail> sourceFields;
    List<ColumnInfoDetail> targetFields;
    if (request.getSourceLinkisDataSourceId() == null) {
        GetUserColumnByTableIdRequest getUserColumnSourceRequest = new GetUserColumnByTableIdRequest(0, Integer.MAX_VALUE, request.getClusterName(), request.getSourceDb(), filterRequest == null ? currentSourceTable : filterRequest.getSourceTable());
        getUserColumnSourceRequest.setProxyUser(request.getProxyUser());
        getUserColumnSourceRequest.setLoginUser(loginUser);
        sourceFields = getUserColumnByTableId(getUserColumnSourceRequest).getData().getData();
    } else {
        sourceFields = getColumnsByDataSource(request.getClusterName(), request.getProxyUser(), request.getSourceLinkisDataSourceId(), request.getSourceDb(), currentSourceTable).getData().getData();
    }
    if (request.getTargetLinkisDataSourceId() == null) {
        GetUserColumnByTableIdRequest getUserColumnTargetRequest = new GetUserColumnByTableIdRequest(0, Integer.MAX_VALUE, request.getClusterName(), request.getTargetDb(), filterRequest == null ? currentTargetTable : filterRequest.getTargetTable());
        getUserColumnTargetRequest.setProxyUser(request.getProxyUser());
        getUserColumnTargetRequest.setLoginUser(loginUser);
        targetFields = getUserColumnByTableId(getUserColumnTargetRequest).getData().getData();
    } else {
        targetFields = getColumnsByDataSource(request.getClusterName(), request.getProxyUser(), request.getTargetLinkisDataSourceId(), request.getTargetDb(), currentTargetTable).getData().getData();
    }
    if (CollectionUtils.isEmpty(sourceFields) || CollectionUtils.isEmpty(targetFields)) {
        throw new UnExpectedRequestException("There is table which has none field");
    }
    LOGGER.info("Success to get all fields with source database's table and target database's table.");
    // Sorted columns.
    Collections.sort(sourceFields, new Comparator<ColumnInfoDetail>() {

        @Override
        public int compare(ColumnInfoDetail front, ColumnInfoDetail back) {
            return front.getFieldName().compareTo(back.getFieldName());
        }
    });
    Collections.sort(targetFields, new Comparator<ColumnInfoDetail>() {

        @Override
        public int compare(ColumnInfoDetail front, ColumnInfoDetail back) {
            return front.getFieldName().compareTo(back.getFieldName());
        }
    });
    String sourceFieldStr = sourceFields.stream().map(ColumnInfoDetail::getFieldName).collect(Collectors.joining(SpecCharEnum.COMMA.getValue()));
    String sourceFieldTypeStr = sourceFields.stream().map(ColumnInfoDetail::getDataType).collect(Collectors.joining(SpecCharEnum.COMMA.getValue()));
    String targetFieldStr = targetFields.stream().map(ColumnInfoDetail::getFieldName).collect(Collectors.joining(SpecCharEnum.COMMA.getValue()));
    String targetFieldTypeStr = targetFields.stream().map(ColumnInfoDetail::getDataType).collect(Collectors.joining(SpecCharEnum.COMMA.getValue()));
    if (sourceFields.size() == 0 || targetFields.size() == 0 || sourceFields.size() != targetFields.size() || !sourceFieldStr.equals(targetFieldStr) || !sourceFieldTypeStr.equals(targetFieldTypeStr)) {
        throw new UnExpectedRequestException("Create multi-db rules failed, because the fields' name of table is different.");
    }
    List<MultiDataSourceJoinConfigRequest> mappings = new ArrayList<>(sourceFields.size());
    for (int j = 0; j < sourceFields.size() && j < targetFields.size(); j++) {
        ColumnInfoDetail currentSourceField = sourceFields.get(j);
        ColumnInfoDetail currentTargetField = targetFields.get(j);
        if (filterRequest != null && CollectionUtils.isNotEmpty(filterRequest.getFilterColumnList()) && filterRequest.getFilterColumnList().contains(currentSourceField.getFieldName())) {
            continue;
        }
        if (currentSourceField.getFieldName().equals(currentTargetField.getFieldName()) && currentSourceField.getDataType().equals(currentTargetField.getDataType())) {
            // TODO: continue
            MultiDataSourceJoinConfigRequest multiDataSourceJoinConfigRequest = new MultiDataSourceJoinConfigRequest();
            MultiDataSourceJoinColumnRequest leftJoinColumnRequest = new MultiDataSourceJoinColumnRequest("tmp1.".concat(currentSourceField.getFieldName()), currentSourceField.getDataType());
            MultiDataSourceJoinColumnRequest rightJoinColumnRequest = new MultiDataSourceJoinColumnRequest("tmp2.".concat(currentTargetField.getFieldName()), currentTargetField.getDataType());
            multiDataSourceJoinConfigRequest.setOperation(MappingOperationEnum.EQUAL.getCode());
            multiDataSourceJoinConfigRequest.setLeft(Arrays.asList(leftJoinColumnRequest));
            multiDataSourceJoinConfigRequest.setRight(Arrays.asList(rightJoinColumnRequest));
            multiDataSourceJoinConfigRequest.setLeftStatement("tmp1.".concat(currentSourceField.getFieldName()));
            multiDataSourceJoinConfigRequest.setRightStatement("tmp2.".concat(currentTargetField.getFieldName()));
            mappings.add(multiDataSourceJoinConfigRequest);
        } else {
            throw new UnExpectedRequestException("Create multi-db rules failed, because the fields' name of tables is different");
        }
    }
    addMultiSourceRuleRequest.setMappings(mappings);
    addMultiSourceRuleRequest.setLoginUser(loginUser);
    LOGGER.info("Success to construct add multi source rule request. Request[{}]", new ObjectMapper().writeValueAsString(addMultiSourceRuleRequest));
    return addMultiSourceRuleRequest;
}
Also used : UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) MultiDataSourceJoinColumnRequest(com.webank.wedatasphere.qualitis.rule.request.multi.MultiDataSourceJoinColumnRequest) ArrayList(java.util.ArrayList) ColumnInfoDetail(com.webank.wedatasphere.qualitis.metadata.response.column.ColumnInfoDetail) MultiDataSourceJoinConfigRequest(com.webank.wedatasphere.qualitis.rule.request.multi.MultiDataSourceJoinConfigRequest) AlarmConfigRequest(com.webank.wedatasphere.qualitis.rule.request.AlarmConfigRequest) MultiDataSourceConfigRequest(com.webank.wedatasphere.qualitis.rule.request.multi.MultiDataSourceConfigRequest) GetUserColumnByTableIdRequest(com.webank.wedatasphere.qualitis.request.GetUserColumnByTableIdRequest) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) AddMultiSourceRuleRequest(com.webank.wedatasphere.qualitis.rule.request.multi.AddMultiSourceRuleRequest)

Aggregations

UnExpectedRequestException (com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException)150 GeneralResponse (com.webank.wedatasphere.qualitis.response.GeneralResponse)97 ArrayList (java.util.ArrayList)56 Transactional (org.springframework.transaction.annotation.Transactional)54 Project (com.webank.wedatasphere.qualitis.project.entity.Project)33 User (com.webank.wedatasphere.qualitis.entity.User)32 Rule (com.webank.wedatasphere.qualitis.rule.entity.Rule)32 RuleMetric (com.webank.wedatasphere.qualitis.entity.RuleMetric)25 Map (java.util.Map)24 ClusterInfo (com.webank.wedatasphere.qualitis.entity.ClusterInfo)22 List (java.util.List)22 PermissionDeniedRequestException (com.webank.wedatasphere.qualitis.exception.PermissionDeniedRequestException)19 IOException (java.io.IOException)19 MetaDataAcquireFailedException (com.webank.wedatasphere.qualitis.metadata.exception.MetaDataAcquireFailedException)17 Date (java.util.Date)17 HashMap (java.util.HashMap)17 RuleDataSource (com.webank.wedatasphere.qualitis.rule.entity.RuleDataSource)15 RuleGroup (com.webank.wedatasphere.qualitis.rule.entity.RuleGroup)15 Collectors (java.util.stream.Collectors)15 Template (com.webank.wedatasphere.qualitis.rule.entity.Template)14