You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@linkis.apache.org by ca...@apache.org on 2022/10/16 05:38:01 UTC

[incubator-linkis] branch dev-1.3.1-errorcode updated: [linkis-gateway-core]module errorcode optimization and documentation (#3551)

This is an automated email from the ASF dual-hosted git repository.

casion pushed a commit to branch dev-1.3.1-errorcode
in repository https://gitbox.apache.org/repos/asf/incubator-linkis.git


The following commit(s) were added to refs/heads/dev-1.3.1-errorcode by this push:
     new b5e17f414 [linkis-gateway-core]module errorcode optimization and documentation (#3551)
b5e17f414 is described below

commit b5e17f414fff3fdbd76b0f5b0d3418e1c71a3b77
Author: 成彬彬 <10...@users.noreply.github.com>
AuthorDate: Sun Oct 16 13:37:56 2022 +0800

    [linkis-gateway-core]module errorcode optimization and documentation (#3551)
---
 docs/errorcode/linkis-gateway-core-errorcode.md    | 10 +++
 .../LinkisGatewayCoreErrorCodeSummary.java         | 86 ++++++++++++++++++++++
 .../exception/TooManyServiceException.scala        |  4 +-
 .../ujes/route/AbstractLabelGatewayRouter.scala    |  7 +-
 .../ujes/route/DefaultLabelGatewayRouter.scala     |  8 +-
 .../http/GatewayAuthorizationFilter.java           |  6 +-
 6 files changed, 111 insertions(+), 10 deletions(-)

diff --git a/docs/errorcode/linkis-gateway-core-errorcode.md b/docs/errorcode/linkis-gateway-core-errorcode.md
new file mode 100644
index 000000000..6c19b4ce0
--- /dev/null
+++ b/docs/errorcode/linkis-gateway-core-errorcode.md
@@ -0,0 +1,10 @@
+## linkis-gateway-core  errorcode
+
+| module name(模块名) | error code(错误码)  | describe(描述) |enumeration name(枚举)| Exception Class(类名)|
+| -------- | -------- | ----- |-----|-----|
+|linkis-gateway-core |11010|Cannot find a correct serviceId for parsedServiceId {}, service list is:{}(无法为 parsedServiceId {} 找到正确的 serviceId,服务列表为:{})|CANNOT_SERVICEID|LinkisGatewayCoreErrorCodeSummary|
+|linkis-gateway-core |11011|Cannot route to the corresponding service, URL: {} RouteLabel: {}(无法路由到相应的服务,URL:{} RouteLabel: {})|CANNOT_ROETE_SERVICE|LinkisGatewayCoreErrorCodeSummary|
+|linkis-gateway-core |11011|There are no services available in the registry URL (注册表 URL 中没有可用的服务):|NO_SERVICES_REGISTRY|LinkisGatewayCoreErrorCodeSummary|
+|linkis-gateway-core |11011|There is no route label service with the corresponding app name (没有对应app名称的路由标签服务)|NO_ROUTE_SERVICE|LinkisGatewayCoreErrorCodeSummary|
+|linkis-gateway-core |11012|Cannot find an instance in the routing chain of serviceId {} , please retry (在 serviceId {} 的路由链中找不到实例,请重试)|CANNOT_INSTANCE|LinkisGatewayCoreErrorCodeSummary|
+|linkis-gateway-core |18000|get requestBody failed!(获取 requestBody 失败!)|GET_REQUESTBODY_FAILED|LinkisGatewayCoreErrorCodeSummary|
diff --git a/linkis-spring-cloud-services/linkis-service-gateway/linkis-gateway-core/src/main/java/org/apache/linkis/gateway/errorcode/LinkisGatewayCoreErrorCodeSummary.java b/linkis-spring-cloud-services/linkis-service-gateway/linkis-gateway-core/src/main/java/org/apache/linkis/gateway/errorcode/LinkisGatewayCoreErrorCodeSummary.java
new file mode 100644
index 000000000..efaf72c83
--- /dev/null
+++ b/linkis-spring-cloud-services/linkis-service-gateway/linkis-gateway-core/src/main/java/org/apache/linkis/gateway/errorcode/LinkisGatewayCoreErrorCodeSummary.java
@@ -0,0 +1,86 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.linkis.gateway.errorcode;
+
+public enum LinkisGatewayCoreErrorCodeSummary {
+  CANNOT_SERVICEID(
+      11010,
+      "Cannot find a correct serviceId for parsedServiceId {}, service list is:{}(无法为 parsedServiceId {} 找到正确的 serviceId,服务列表为:{})",
+      "Cannot find a correct serviceId for parsedServiceId {}, service list is:{}(无法为 parsedServiceId {} 找到正确的 serviceId,服务列表为:{})"),
+  CANNOT_ROETE_SERVICE(
+      11011,
+      "Cannot route to the corresponding service, URL: {} RouteLabel: {}(无法路由到相应的服务,URL:{} RouteLabel: {})",
+      "Cannot route to the corresponding service, URL: {} RouteLabel: {}(无法路由到相应的服务,URL:{} RouteLabel: {})"),
+  NO_SERVICES_REGISTRY(
+      11011,
+      "There are no services available in the registry URL (注册表 URL 中没有可用的服务):",
+      "There are no services available in the registry URL (注册表 URL 中没有可用的服务):"),
+  NO_ROUTE_SERVICE(
+      11011,
+      "There is no route label service with the corresponding app name (没有对应app名称的路由标签服务)",
+      "There is no route label service with the corresponding app name (没有对应app名称的路由标签服务)"),
+  CANNOT_INSTANCE(
+      11012,
+      "Cannot find an instance in the routing chain of serviceId {} , please retry (在 serviceId {} 的路由链中找不到实例,请重试)",
+      "Cannot find an instance in the routing chain of serviceId {} , please retry(在 serviceId {} 的路由链中找不到实例,请重试)"),
+  GET_REQUESTBODY_FAILED(
+      18000,
+      "get requestBody failed!(获取 requestBody 失败!)",
+      "get requestBody failed!(获取 requestBody 失败!)");
+  /** (errorCode)错误码 */
+  private int errorCode;
+  /** (errorDesc)错误描述 */
+  private String errorDesc;
+  /** Possible reasons for the error(错误可能出现的原因) */
+  private String comment;
+
+  LinkisGatewayCoreErrorCodeSummary(int errorCode, String errorDesc, String comment) {
+    this.errorCode = errorCode;
+    this.errorDesc = errorDesc;
+    this.comment = comment;
+  }
+
+  public int getErrorCode() {
+    return errorCode;
+  }
+
+  public void setErrorCode(int errorCode) {
+    this.errorCode = errorCode;
+  }
+
+  public String getErrorDesc() {
+    return errorDesc;
+  }
+
+  public void setErrorDesc(String errorDesc) {
+    this.errorDesc = errorDesc;
+  }
+
+  public String getComment() {
+    return comment;
+  }
+
+  public void setComment(String comment) {
+    this.comment = comment;
+  }
+
+  @Override
+  public String toString() {
+    return "errorCode: " + this.errorCode + ", errorDesc:" + this.errorDesc;
+  }
+}
diff --git a/linkis-spring-cloud-services/linkis-service-gateway/linkis-gateway-core/src/main/scala/org/apache/linkis/gateway/exception/TooManyServiceException.scala b/linkis-spring-cloud-services/linkis-service-gateway/linkis-gateway-core/src/main/scala/org/apache/linkis/gateway/exception/TooManyServiceException.scala
index d041950ce..760332bee 100644
--- a/linkis-spring-cloud-services/linkis-service-gateway/linkis-gateway-core/src/main/scala/org/apache/linkis/gateway/exception/TooManyServiceException.scala
+++ b/linkis-spring-cloud-services/linkis-service-gateway/linkis-gateway-core/src/main/scala/org/apache/linkis/gateway/exception/TooManyServiceException.scala
@@ -18,5 +18,7 @@
 package org.apache.linkis.gateway.exception
 
 import org.apache.linkis.common.exception.ErrorException
+import org.apache.linkis.gateway.errorcode.LinkisGatewayCoreErrorCodeSummary._
 
-class TooManyServiceException(message: String) extends ErrorException(11010, message)
+class TooManyServiceException(message: String)
+    extends ErrorException(CANNOT_SERVICEID.getErrorCode, message)
diff --git a/linkis-spring-cloud-services/linkis-service-gateway/linkis-gateway-server-support/src/main/scala/org/apache/linkis/gateway/ujes/route/AbstractLabelGatewayRouter.scala b/linkis-spring-cloud-services/linkis-service-gateway/linkis-gateway-server-support/src/main/scala/org/apache/linkis/gateway/ujes/route/AbstractLabelGatewayRouter.scala
index aa5ae5fa2..5de546b72 100644
--- a/linkis-spring-cloud-services/linkis-service-gateway/linkis-gateway-server-support/src/main/scala/org/apache/linkis/gateway/ujes/route/AbstractLabelGatewayRouter.scala
+++ b/linkis-spring-cloud-services/linkis-service-gateway/linkis-gateway-server-support/src/main/scala/org/apache/linkis/gateway/ujes/route/AbstractLabelGatewayRouter.scala
@@ -20,6 +20,7 @@ package org.apache.linkis.gateway.ujes.route
 import org.apache.linkis.common.ServiceInstance
 import org.apache.linkis.common.utils.Logging
 import org.apache.linkis.gateway.config.GatewayConfiguration
+import org.apache.linkis.gateway.errorcode.LinkisGatewayCoreErrorCodeSummary._
 import org.apache.linkis.gateway.exception.GatewayErrorException
 import org.apache.linkis.gateway.http.GatewayContext
 import org.apache.linkis.gateway.route.AbstractGatewayRouter
@@ -71,7 +72,7 @@ abstract class AbstractLabelGatewayRouter extends AbstractGatewayRouter with Log
       val candidateServices = insLabelService.searchInstancesByLabels(routeLabels)
       if (null == candidateServices || candidateServices.isEmpty) {
         throw new GatewayErrorException(
-          11011,
+          CANNOT_ROETE_SERVICE.getErrorCode,
           s"Cannot route to the corresponding service, URL: ${gatewayContext.getRequest.getRequestURI} RouteLabel: ${LabelUtils.Jackson
             .toJson(routeLabels, null)}"
         )
@@ -83,8 +84,8 @@ abstract class AbstractLabelGatewayRouter extends AbstractGatewayRouter with Log
     val instance = selectInstance(gatewayContext, canSelectInstances)
     if (null == instance || StringUtils.isBlank(instance.getInstance)) {
       throw new GatewayErrorException(
-        11011,
-        s"There are no services available in the registry URL: ${gatewayContext.getRequest.getRequestURI}"
+        NO_SERVICES_REGISTRY.getErrorCode,
+        NO_SERVICES_REGISTRY.getErrorDesc + s" ${gatewayContext.getRequest.getRequestURI}"
       )
     }
     instance
diff --git a/linkis-spring-cloud-services/linkis-service-gateway/linkis-gateway-server-support/src/main/scala/org/apache/linkis/gateway/ujes/route/DefaultLabelGatewayRouter.scala b/linkis-spring-cloud-services/linkis-service-gateway/linkis-gateway-server-support/src/main/scala/org/apache/linkis/gateway/ujes/route/DefaultLabelGatewayRouter.scala
index 9c4ece7a4..dbe105284 100644
--- a/linkis-spring-cloud-services/linkis-service-gateway/linkis-gateway-server-support/src/main/scala/org/apache/linkis/gateway/ujes/route/DefaultLabelGatewayRouter.scala
+++ b/linkis-spring-cloud-services/linkis-service-gateway/linkis-gateway-server-support/src/main/scala/org/apache/linkis/gateway/ujes/route/DefaultLabelGatewayRouter.scala
@@ -18,6 +18,7 @@
 package org.apache.linkis.gateway.ujes.route
 
 import org.apache.linkis.common.ServiceInstance
+import org.apache.linkis.gateway.errorcode.LinkisGatewayCoreErrorCodeSummary._
 import org.apache.linkis.gateway.exception.GatewayErrorException
 import org.apache.linkis.gateway.http.GatewayContext
 import org.apache.linkis.gateway.ujes.route.label.RouteLabelParser
@@ -79,10 +80,7 @@ class DefaultLabelGatewayRouter(var routeLabelParsers: util.List[RouteLabelParse
   private def roulette(serviceInstances: util.List[ServiceInstance]): ServiceInstance = {
     // Fetch from registry, make sure that the instances are available and the serviceId is right
     if (serviceInstances.size() <= 0) {
-      throw new GatewayErrorException(
-        11011,
-        "There is no route label service with the corresponding app name"
-      )
+      throw new GatewayErrorException(NO_ROUTE_SERVICE.getErrorCode, NO_ROUTE_SERVICE.getErrorDesc)
     }
     val serviceId = serviceInstances.get(0).getApplicationName
     val filteredInstances = retainAllInRegistry(serviceId, serviceInstances)
@@ -90,7 +88,7 @@ class DefaultLabelGatewayRouter(var routeLabelParsers: util.List[RouteLabelParse
       filteredInstances.get(Random.nextInt(filteredInstances.size()))
     } else {
       throw new GatewayErrorException(
-        11012,
+        CANNOT_INSTANCE.getErrorCode,
         s"Cannot find an instance in the routing chain of serviceId [" +
           serviceId + "], please retry"
       )
diff --git a/linkis-spring-cloud-services/linkis-service-gateway/linkis-spring-cloud-gateway/src/main/java/org/apache/linkis/gateway/springcloud/http/GatewayAuthorizationFilter.java b/linkis-spring-cloud-services/linkis-service-gateway/linkis-spring-cloud-gateway/src/main/java/org/apache/linkis/gateway/springcloud/http/GatewayAuthorizationFilter.java
index 33827c4ea..f0f47c4f5 100644
--- a/linkis-spring-cloud-services/linkis-service-gateway/linkis-spring-cloud-gateway/src/main/java/org/apache/linkis/gateway/springcloud/http/GatewayAuthorizationFilter.java
+++ b/linkis-spring-cloud-services/linkis-service-gateway/linkis-spring-cloud-gateway/src/main/java/org/apache/linkis/gateway/springcloud/http/GatewayAuthorizationFilter.java
@@ -57,6 +57,8 @@ import org.slf4j.LoggerFactory;
 import reactor.core.publisher.Flux;
 import reactor.core.publisher.Mono;
 
+import static org.apache.linkis.gateway.errorcode.LinkisGatewayCoreErrorCodeSummary.GET_REQUESTBODY_FAILED;
+
 public class GatewayAuthorizationFilter implements GlobalFilter, Ordered {
   private static final Logger logger = LoggerFactory.getLogger(GatewayAuthorizationFilter.class);
 
@@ -83,7 +85,9 @@ public class GatewayAuthorizationFilter implements GlobalFilter, Ordered {
     try {
       requestBody = serverRequest.bodyToMono(String.class).toFuture().get();
     } catch (Exception e) {
-      GatewayWarnException exception = new GatewayWarnException(18000, "get requestBody failed!");
+      GatewayWarnException exception =
+          new GatewayWarnException(
+              GET_REQUESTBODY_FAILED.getErrorCode(), GET_REQUESTBODY_FAILED.getErrorDesc());
       exception.initCause(e);
       throw exception;
     }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@linkis.apache.org
For additional commands, e-mail: commits-help@linkis.apache.org