diff --git a/src/backend/commons/cmdb-sdk/src/main/java/com/tencent/bk/job/common/cc/sdk/BizCmdbClient.java b/src/backend/commons/cmdb-sdk/src/main/java/com/tencent/bk/job/common/cc/sdk/BizCmdbClient.java index ee9f24ace6..5397b45e73 100644 --- a/src/backend/commons/cmdb-sdk/src/main/java/com/tencent/bk/job/common/cc/sdk/BizCmdbClient.java +++ b/src/backend/commons/cmdb-sdk/src/main/java/com/tencent/bk/job/common/cc/sdk/BizCmdbClient.java @@ -28,6 +28,7 @@ import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheLoader; import com.google.common.cache.LoadingCache; +import com.google.common.util.concurrent.UncheckedExecutionException; import com.tencent.bk.job.common.cc.config.CmdbConfig; import com.tencent.bk.job.common.cc.exception.CmdbException; import com.tencent.bk.job.common.cc.model.AppRoleDTO; @@ -85,7 +86,6 @@ import com.tencent.bk.job.common.esb.model.EsbResp; import com.tencent.bk.job.common.esb.sdk.AbstractEsbSdkClient; import com.tencent.bk.job.common.exception.CmdbClientException; -import com.tencent.bk.job.common.exception.InternalException; import com.tencent.bk.job.common.gse.service.QueryAgentStatusClient; import com.tencent.bk.job.common.metrics.CommonMetricNames; import com.tencent.bk.job.common.model.dto.ApplicationDTO; @@ -264,10 +264,10 @@ public InstanceTopologyDTO getBizInstCompleteTopology(long bizId) { return completeTopologyDTO; } - public InstanceTopologyDTO getCachedBizInstCompleteTopology(long bizId) { + public InstanceTopologyDTO getCachedBizInstCompleteTopology(long bizId){ try { return bizInstCompleteTopologyCache.get(bizId); - } catch (Throwable e) { + } catch (ExecutionException | UncheckedExecutionException e) { throw new CmdbClientException(e, ErrorCode.CMDB_API_DATA_ERROR, null); } } diff --git a/src/backend/commons/common-web/src/main/java/com/tencent/bk/job/common/web/exception/handler/EsbExceptionControllerAdvice.java b/src/backend/commons/common-web/src/main/java/com/tencent/bk/job/common/web/exception/handler/EsbExceptionControllerAdvice.java index ebc1c468aa..0b9b0631b3 100644 --- a/src/backend/commons/common-web/src/main/java/com/tencent/bk/job/common/web/exception/handler/EsbExceptionControllerAdvice.java +++ b/src/backend/commons/common-web/src/main/java/com/tencent/bk/job/common/web/exception/handler/EsbExceptionControllerAdvice.java @@ -29,7 +29,6 @@ import com.tencent.bk.job.common.constant.ErrorCode; import com.tencent.bk.job.common.esb.model.EsbResp; import com.tencent.bk.job.common.exception.AlreadyExistsException; -import com.tencent.bk.job.common.exception.CmdbClientException; import com.tencent.bk.job.common.exception.FailedPreconditionException; import com.tencent.bk.job.common.exception.InternalException; import com.tencent.bk.job.common.exception.InvalidParamException; @@ -193,15 +192,6 @@ ResponseEntity handleResourceExhaustedException(HttpServletRequest request, R return new ResponseEntity<>(EsbResp.buildCommonFailResp(ex), HttpStatus.OK); } - @ExceptionHandler(CmdbClientException.class) - @ResponseBody - @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) - ResponseEntity handleInternalException(HttpServletRequest request, CmdbClientException ex) { - String errorMsg = "Handle CmdbException, uri: " + request.getRequestURI(); - log.error(errorMsg, ex); - return new ResponseEntity<>(EsbResp.buildCommonFailResp(ex.getErrorCode()), HttpStatus.OK); - } - @Override @SuppressWarnings("all") protected ResponseEntity handleHttpRequestMethodNotSupported(HttpRequestMethodNotSupportedException ex, diff --git a/src/backend/commons/common-web/src/main/java/com/tencent/bk/job/common/web/exception/handler/ServiceExceptionControllerAdvice.java b/src/backend/commons/common-web/src/main/java/com/tencent/bk/job/common/web/exception/handler/ServiceExceptionControllerAdvice.java index 6a0d277967..3ce6ce58c1 100644 --- a/src/backend/commons/common-web/src/main/java/com/tencent/bk/job/common/web/exception/handler/ServiceExceptionControllerAdvice.java +++ b/src/backend/commons/common-web/src/main/java/com/tencent/bk/job/common/web/exception/handler/ServiceExceptionControllerAdvice.java @@ -27,7 +27,6 @@ import com.tencent.bk.job.common.annotation.InternalAPI; import com.tencent.bk.job.common.constant.ErrorCode; import com.tencent.bk.job.common.exception.AlreadyExistsException; -import com.tencent.bk.job.common.exception.CmdbClientException; import com.tencent.bk.job.common.exception.FailedPreconditionException; import com.tencent.bk.job.common.exception.InternalException; import com.tencent.bk.job.common.exception.InvalidParamException; @@ -174,13 +173,4 @@ ResponseEntity handleResourceExhaustedException(HttpServletRequest request, R return new ResponseEntity<>(InternalResponse.buildCommonFailResp(ex), HttpStatus.TOO_MANY_REQUESTS); } - @ExceptionHandler(CmdbClientException.class) - @ResponseBody - @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) - InternalResponse handleCmdbException(HttpServletRequest request, CmdbClientException ex) { - String errorMsg = "Handle CmdbException, uri: " + request.getRequestURI(); - log.error(errorMsg, ex); - return InternalResponse.buildCommonFailResp(ex); - } - } diff --git a/src/backend/commons/common-web/src/main/java/com/tencent/bk/job/common/web/exception/handler/WebExceptionControllerAdvice.java b/src/backend/commons/common-web/src/main/java/com/tencent/bk/job/common/web/exception/handler/WebExceptionControllerAdvice.java index e875b33c21..b4579ef63e 100644 --- a/src/backend/commons/common-web/src/main/java/com/tencent/bk/job/common/web/exception/handler/WebExceptionControllerAdvice.java +++ b/src/backend/commons/common-web/src/main/java/com/tencent/bk/job/common/web/exception/handler/WebExceptionControllerAdvice.java @@ -27,7 +27,6 @@ import com.tencent.bk.job.common.annotation.WebAPI; import com.tencent.bk.job.common.constant.ErrorCode; import com.tencent.bk.job.common.exception.AlreadyExistsException; -import com.tencent.bk.job.common.exception.CmdbClientException; import com.tencent.bk.job.common.exception.FailedPreconditionException; import com.tencent.bk.job.common.exception.InternalException; import com.tencent.bk.job.common.exception.InvalidParamException; @@ -184,13 +183,4 @@ ResponseEntity handleResourceExhaustedException(HttpServletRequest request, R return new ResponseEntity<>(Response.buildCommonFailResp(ex), HttpStatus.TOO_MANY_REQUESTS); } - @ExceptionHandler(CmdbClientException.class) - @ResponseBody - @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) - Response handleCmdbException(HttpServletRequest request, CmdbClientException ex) { - String errorMsg = "Handle CmdbException, uri: " + request.getRequestURI(); - log.error(errorMsg, ex); - return Response.buildCommonFailResp(ex); - } - } diff --git a/src/backend/commons/esb-sdk/src/main/java/com/tencent/bk/job/common/esb/sdk/AbstractEsbSdkClient.java b/src/backend/commons/esb-sdk/src/main/java/com/tencent/bk/job/common/esb/sdk/AbstractEsbSdkClient.java index 90674c6e78..d364f5e3a9 100644 --- a/src/backend/commons/esb-sdk/src/main/java/com/tencent/bk/job/common/esb/sdk/AbstractEsbSdkClient.java +++ b/src/backend/commons/esb-sdk/src/main/java/com/tencent/bk/job/common/esb/sdk/AbstractEsbSdkClient.java @@ -28,7 +28,7 @@ import com.tencent.bk.job.common.constant.ErrorCode; import com.tencent.bk.job.common.esb.model.EsbReq; import com.tencent.bk.job.common.esb.model.EsbResp; -import com.tencent.bk.job.common.exception.CmdbClientException; +import com.tencent.bk.job.common.exception.InternalException; import com.tencent.bk.job.common.util.http.ExtHttpHelper; import com.tencent.bk.job.common.util.http.HttpHelperFactory; import com.tencent.bk.job.common.util.json.JsonMapper; @@ -248,7 +248,7 @@ public EsbResp getEsbRespByReq(String method, String uri, EsbReq reqBody, if (StringUtils.isBlank(respStr)) { String errorMsg = method + " " + uri + ", error: " + "Response is blank"; log.error(errorMsg); - throw new CmdbClientException(errorMsg, ErrorCode.API_ERROR); + throw new InternalException(errorMsg, ErrorCode.API_ERROR); } else { log.debug("success|method={}|uri={}|reqStr={}|respStr={}", method, uri, reqStr, respStr); } @@ -256,7 +256,7 @@ public EsbResp getEsbRespByReq(String method, String uri, EsbReq reqBody, if (esbResp == null) { String errorMsg = method + " " + uri + ", error: " + "Response is blank after parse"; log.error(errorMsg); - throw new CmdbClientException(errorMsg, ErrorCode.API_ERROR); + throw new InternalException(errorMsg, ErrorCode.API_ERROR); } else if (!esbResp.getResult()) { log.warn( "fail:esbResp code!=0|esbResp.requestId={}|esbResp.code={}|esbResp" + @@ -284,7 +284,7 @@ public EsbResp getEsbRespByReq(String method, String uri, EsbReq reqBody, + "|reqStr=" + reqStr + "|respStr=" + respStr; log.error(errorMsg, e); - throw new CmdbClientException("Fail to request esb api", e, ErrorCode.API_ERROR); + throw new InternalException("Fail to request esb api", e, ErrorCode.API_ERROR); } } }