You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@linkis.apache.org by pe...@apache.org on 2022/10/11 06:40:34 UTC
[incubator-linkis] branch dev-1.3.1 updated: [ISSUE-3361][linkis-rpc]module errorcode optimization and documentation (#3493)
This is an automated email from the ASF dual-hosted git repository.
peacewong pushed a commit to branch dev-1.3.1
in repository https://gitbox.apache.org/repos/asf/incubator-linkis.git
The following commit(s) were added to refs/heads/dev-1.3.1 by this push:
new 79f4e092c [ISSUE-3361][linkis-rpc]module errorcode optimization and documentation (#3493)
79f4e092c is described below
commit 79f4e092cb740a6074743c9cd29f14d0ae288866
Author: 成彬彬 <10...@users.noreply.github.com>
AuthorDate: Tue Oct 11 14:40:30 2022 +0800
[ISSUE-3361][linkis-rpc]module errorcode optimization and documentation (#3493)
* errorcode code optimization
---
docs/errorcode/linkis-rpc-errorcode.md | 23 ++++++
.../rpc/errorcode/LinkisRpcErrorCodeSummary.java | 84 ++++++++++++++++++++++
.../linkis/rpc/message/method/MessageExecutor.java | 4 +-
.../org/apache/linkis/rpc/AsynRPCMessageBus.scala | 4 +-
.../org/apache/linkis/rpc/RPCReceiveRestful.scala | 3 +-
.../linkis/rpc/interceptor/RPCServerLoader.scala | 3 +-
.../apache/linkis/rpc/transform/RPCConsumer.scala | 6 +-
.../apache/linkis/rpc/transform/RPCProduct.scala | 9 ++-
8 files changed, 127 insertions(+), 9 deletions(-)
diff --git a/docs/errorcode/linkis-rpc-errorcode.md b/docs/errorcode/linkis-rpc-errorcode.md
new file mode 100644
index 000000000..b9f98e664
--- /dev/null
+++ b/docs/errorcode/linkis-rpc-errorcode.md
@@ -0,0 +1,23 @@
+## linkis-rpc errorcode
+
+
+| 模块名(服务名) | 错误码 | 描述 | class|
+| -------- | -------- | ----- |-----|
+|linkis-rpc|10021|Failed to get user parameters! Reason: RPC request(获取用户参数失败!原因:RPC请求) #applicationName Service failed!(服务失败!)|RPCErrorConstants|
+|linkis-rpc|10054|Asyn RPC Consumer Thread has stopped!(Asyn RPC Consumer 线程已停止!)|RPCErrorConstants|
+|linkis-rpc|10000|The service does not exist for the available Receiver.(服务不存在可用的Receiver.) |EngineConnManager|
+|linkis-rpc|15555| Asyn RPC Consumer Queue is full, please retry after some times.(Asyn RPC Consumer Queue 已满,请稍后重试。)|DWCRPCRetryException|
+|linkis-rpc|10002|The timeout period is not set!(超时时间未设置!)|LinkisRpcErrorCodeSummary|
+|linkis-rpc|10003|The corresponding anti-sequence class $objectClass was not found:(找不到对应的反序列类:)|LinkisRpcErrorCodeSummary|
+|linkis-rpc|10004|The corresponding anti-sequence class failed to initialize:(对应的反序列类初始化失败:)|LinkisRpcErrorCodeSummary|
+|linkis-rpc|10001|The transmitted bean is Null.(传输的bean为Null.|LinkisRpcErrorCodeSummary|
+|linkis-rpc|10051|The instance ## of application ## is not exists.(应用程序## 的实例## 不存在。)|LinkisRpcErrorCodeSummary|
+|linkis-rpc|10000|method call failed:(方法调用失败:)|LinkisRpcErrorCodeSummary|
+
+
+
+
+
+
+
+
diff --git a/linkis-commons/linkis-rpc/src/main/java/org/apache/linkis/rpc/errorcode/LinkisRpcErrorCodeSummary.java b/linkis-commons/linkis-rpc/src/main/java/org/apache/linkis/rpc/errorcode/LinkisRpcErrorCodeSummary.java
new file mode 100644
index 000000000..2268c164d
--- /dev/null
+++ b/linkis-commons/linkis-rpc/src/main/java/org/apache/linkis/rpc/errorcode/LinkisRpcErrorCodeSummary.java
@@ -0,0 +1,84 @@
+/*
+ * 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.rpc.errorcode;
+
+public enum LinkisRpcErrorCodeSummary {
+ TIMEOUT_PERIOD(
+ 10002,
+ "The timeout period is not set!(超时时间未设置!)",
+ "The timeout period is not set!(超时时间未设置!)"),
+ CORRESPONDING_NOT_FOUND(
+ 10003,
+ "The corresponding anti-sequence class $objectClass was not found:(找不到对应的反序列类:)",
+ "The corresponding anti-sequence class was not found.(找不到对应的反序列类 :)"),
+ CORRESPONDING_TO_INITIALIZE(
+ 10004,
+ "The corresponding anti-sequence class failed to initialize:(对应的反序列类初始化失败:)",
+ "The corresponding anti-sequence class failed to initialize.(对应的反序列类 初始化失败:)"),
+ TRANSMITTED_BEAN_IS_NULL(
+ 10001,
+ "The transmitted bean is Null.(传输的bean为Null.",
+ "The transmitted bean is Null.(传输的bean为Null."),
+ APPLICATION_IS_NOT_EXISTS(
+ 10051,
+ "The instance ## of application ### is not exists.(应用程序### 的实例## 不存在。)",
+ "The instance ## of application ### is not exists.(应用程序### 的实例## 不存在。)"),
+ METHON_CALL_FAILED(10000, "method call failed:(方法调用失败:)", "method call failed:(方法调用失败:)");
+
+ /** 错误码 */
+ private int errorCode;
+ /** 错误描述 */
+ private String errorDesc;
+ /** 错误可能出现的原因 */
+ private String comment;
+
+ LinkisRpcErrorCodeSummary(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-commons/linkis-rpc/src/main/java/org/apache/linkis/rpc/message/method/MessageExecutor.java b/linkis-commons/linkis-rpc/src/main/java/org/apache/linkis/rpc/message/method/MessageExecutor.java
index 3790735dc..d1d18b506 100644
--- a/linkis-commons/linkis-rpc/src/main/java/org/apache/linkis/rpc/message/method/MessageExecutor.java
+++ b/linkis-commons/linkis-rpc/src/main/java/org/apache/linkis/rpc/message/method/MessageExecutor.java
@@ -32,6 +32,8 @@ import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import static org.apache.linkis.rpc.errorcode.LinkisRpcErrorCodeSummary.METHON_CALL_FAILED;
+
public class MessageExecutor {
private static final Logger logger = LoggerFactory.getLogger(MessageExecutor.class);
@@ -92,7 +94,7 @@ public class MessageExecutor {
? "method call failed: "
+ ((InvocationTargetException) t).getTargetException().getMessage()
: "method call failed.";
- throw new MessageWarnException(10000, errorMsg, t);
+ throw new MessageWarnException(METHON_CALL_FAILED.getErrorCode(), errorMsg, t);
}
}
return result;
diff --git a/linkis-commons/linkis-rpc/src/main/scala/org/apache/linkis/rpc/AsynRPCMessageBus.scala b/linkis-commons/linkis-rpc/src/main/scala/org/apache/linkis/rpc/AsynRPCMessageBus.scala
index 9313ad4b1..398e78153 100644
--- a/linkis-commons/linkis-rpc/src/main/scala/org/apache/linkis/rpc/AsynRPCMessageBus.scala
+++ b/linkis-commons/linkis-rpc/src/main/scala/org/apache/linkis/rpc/AsynRPCMessageBus.scala
@@ -42,12 +42,12 @@ class AsynRPCMessageBus(capacity: Int, busName: String)(
override protected val dropEvent: DropEvent = new DropEvent {
override def onDropEvent(event: RPCMessageEvent): Unit = throw new DWCRPCRetryException(
- "Asyn RPC Consumer Queue is full, please retry after some times."
+ "Asyn RPC Consumer Queue is full, please retry after some times.(Asyn RPC Consumer Queue 已满,请稍后重试。)"
)
override def onBusStopped(event: RPCMessageEvent): Unit = throw new RPCInitFailedException(
RPCErrorConstants.RPC_INIT_ERROR,
- "Asyn RPC Consumer Thread has stopped!"
+ "Asyn RPC Consumer Thread has stopped!(Asyn RPC Consumer 线程已停止!)"
)
}
diff --git a/linkis-commons/linkis-rpc/src/main/scala/org/apache/linkis/rpc/RPCReceiveRestful.scala b/linkis-commons/linkis-rpc/src/main/scala/org/apache/linkis/rpc/RPCReceiveRestful.scala
index 4bc97e8d7..6e5046330 100644
--- a/linkis-commons/linkis-rpc/src/main/scala/org/apache/linkis/rpc/RPCReceiveRestful.scala
+++ b/linkis-commons/linkis-rpc/src/main/scala/org/apache/linkis/rpc/RPCReceiveRestful.scala
@@ -24,6 +24,7 @@ import org.apache.linkis.rpc.conf.RPCConfiguration.{
BDP_RPC_RECEIVER_ASYN_CONSUMER_THREAD_MAX,
BDP_RPC_RECEIVER_ASYN_QUEUE_CAPACITY
}
+import org.apache.linkis.rpc.errorcode.LinkisRpcErrorCodeSummary.TIMEOUT_PERIOD
import org.apache.linkis.rpc.exception.DWCURIException
import org.apache.linkis.rpc.transform.{RPCConsumer, RPCProduct}
import org.apache.linkis.server.{catchIt, Message}
@@ -178,7 +179,7 @@ private[rpc] class RPCReceiveRestful extends RPCReceiveRemote with Logging {
override def receiveAndReplyInMills(@RequestBody message: Message): Message = catchIt {
val duration = message.getData.get("duration")
if (duration == null || StringUtils.isEmpty(duration.toString)) {
- throw new DWCURIException(10002, "The timeout period is not set!(超时时间未设置!)")
+ throw new DWCURIException(TIMEOUT_PERIOD.getErrorCode, TIMEOUT_PERIOD.getErrorDesc)
}
val timeout = Duration(duration.toString.toLong, TimeUnit.MILLISECONDS)
receiveAndReplyWithMessage(message, _.receiveAndReply(_, timeout, _))
diff --git a/linkis-commons/linkis-rpc/src/main/scala/org/apache/linkis/rpc/interceptor/RPCServerLoader.scala b/linkis-commons/linkis-rpc/src/main/scala/org/apache/linkis/rpc/interceptor/RPCServerLoader.scala
index 0c70393cb..2a34fb345 100644
--- a/linkis-commons/linkis-rpc/src/main/scala/org/apache/linkis/rpc/interceptor/RPCServerLoader.scala
+++ b/linkis-commons/linkis-rpc/src/main/scala/org/apache/linkis/rpc/interceptor/RPCServerLoader.scala
@@ -19,6 +19,7 @@ package org.apache.linkis.rpc.interceptor
import org.apache.linkis.common.ServiceInstance
import org.apache.linkis.common.utils.{Logging, Utils}
+import org.apache.linkis.rpc.errorcode.LinkisRpcErrorCodeSummary.APPLICATION_IS_NOT_EXISTS
import org.apache.linkis.rpc.exception.NoInstanceExistsException
import org.apache.linkis.rpc.sender.SpringCloudFeignConfigurationCache
@@ -61,7 +62,7 @@ abstract class AbstractRPCServerLoader extends RPCServerLoader with Logging {
serviceInstance: ServiceInstance
): Unit = {
val instanceNotExists = new NoInstanceExistsException(
- 10051,
+ APPLICATION_IS_NOT_EXISTS.getErrorCode,
"The instance " +
serviceInstance.getInstance + " of application " + serviceInstance.getApplicationName + " is not exists."
)
diff --git a/linkis-commons/linkis-rpc/src/main/scala/org/apache/linkis/rpc/transform/RPCConsumer.scala b/linkis-commons/linkis-rpc/src/main/scala/org/apache/linkis/rpc/transform/RPCConsumer.scala
index 3191da79a..06ec1441b 100644
--- a/linkis-commons/linkis-rpc/src/main/scala/org/apache/linkis/rpc/transform/RPCConsumer.scala
+++ b/linkis-commons/linkis-rpc/src/main/scala/org/apache/linkis/rpc/transform/RPCConsumer.scala
@@ -19,6 +19,8 @@ package org.apache.linkis.rpc.transform
import org.apache.linkis.common.exception.ExceptionManager
import org.apache.linkis.common.utils.Utils
+import org.apache.linkis.rpc.errorcode.LinkisRpcErrorCodeSummary.CORRESPONDING_NOT_FOUND
+import org.apache.linkis.rpc.errorcode.LinkisRpcErrorCodeSummary.CORRESPONDING_TO_INITIALIZE
import org.apache.linkis.rpc.exception.DWCURIException
import org.apache.linkis.rpc.serializer.ProtostuffSerializeUtil
import org.apache.linkis.server.{EXCEPTION_MSG, JMap, Message}
@@ -50,12 +52,12 @@ private[linkis] object RPCConsumer {
val clazz = Utils.tryThrow(Class.forName(objectClass)) {
case _: ClassNotFoundException =>
new DWCURIException(
- 10003,
+ CORRESPONDING_NOT_FOUND.getErrorCode,
s"The corresponding anti-sequence class $objectClass was not found.(找不到对应的反序列类$objectClass.)"
)
case t: ExceptionInInitializerError =>
val exception = new DWCURIException(
- 10004,
+ CORRESPONDING_TO_INITIALIZE.getErrorCode,
s"The corresponding anti-sequence class ${objectClass} failed to initialize.(对应的反序列类${objectClass}初始化失败.)"
)
exception.initCause(t)
diff --git a/linkis-commons/linkis-rpc/src/main/scala/org/apache/linkis/rpc/transform/RPCProduct.scala b/linkis-commons/linkis-rpc/src/main/scala/org/apache/linkis/rpc/transform/RPCProduct.scala
index e244758a4..238e41dfd 100644
--- a/linkis-commons/linkis-rpc/src/main/scala/org/apache/linkis/rpc/transform/RPCProduct.scala
+++ b/linkis-commons/linkis-rpc/src/main/scala/org/apache/linkis/rpc/transform/RPCProduct.scala
@@ -20,6 +20,7 @@ package org.apache.linkis.rpc.transform
import org.apache.linkis.DataWorkCloudApplication
import org.apache.linkis.common.utils.Logging
import org.apache.linkis.protocol.message.RequestProtocol
+import org.apache.linkis.rpc.errorcode.LinkisRpcErrorCodeSummary.TRANSMITTED_BEAN_IS_NULL
import org.apache.linkis.rpc.errorcode.RPCErrorConstants
import org.apache.linkis.rpc.exception.DWCURIException
import org.apache.linkis.rpc.serializer.ProtostuffSerializeUtil
@@ -67,8 +68,12 @@ private[linkis] object RPCProduct extends Logging {
}
override def toMessage(t: Any): Message = {
- if (t == null)
- throw new DWCURIException(10001, "The transmitted bean is Null.(传输的bean为Null.)")
+ if (t == null) {
+ throw new DWCURIException(
+ TRANSMITTED_BEAN_IS_NULL.getErrorCode,
+ TRANSMITTED_BEAN_IS_NULL.getErrorDesc
+ )
+ }
val message = Message.ok("RPC Message.")
if (isRequestProtocol(t)) {
message.data(IS_REQUEST_PROTOCOL_CLASS, "true")
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@linkis.apache.org
For additional commands, e-mail: commits-help@linkis.apache.org