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/09/23 10:24:11 UTC
[incubator-linkis] branch dev-1.3.1 updated: errorcode code optimization (#3511)
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 9548c5709 errorcode code optimization (#3511)
9548c5709 is described below
commit 9548c57092547f8a9291dca0620f05775272ef59
Author: 成彬彬 <10...@users.noreply.github.com>
AuthorDate: Fri Sep 23 18:24:07 2022 +0800
errorcode code optimization (#3511)
---
docs/errorcode/linkis-instance-label-errorcode.md | 8 +++
.../LinkisInstanceLabelErrorCodeSummary.java | 80 ++++++++++++++++++++++
.../label/exception/InstanceErrorException.java | 4 +-
.../instance/label/restful/InstanceRestful.java | 8 ++-
.../label/service/impl/DefaultInsLabelService.java | 3 +-
5 files changed, 98 insertions(+), 5 deletions(-)
diff --git a/docs/errorcode/linkis-instance-label-errorcode.md b/docs/errorcode/linkis-instance-label-errorcode.md
new file mode 100644
index 000000000..7f38e00a1
--- /dev/null
+++ b/docs/errorcode/linkis-instance-label-errorcode.md
@@ -0,0 +1,8 @@
+## linkis-instance-label errorcode
+
+| 模块名(服务名) | 错误码 | 描述 | Exception Class|
+| -------- | -------- | ----- |-----|
+|linkis-instance-label |14100|Failed to insert service instance(插入服务实例失败)|LinkisInstanceLabelErrorCodeSummary|
+|linkis-instance-label |14100|Only admin can view all instances(只有管理员才能查看所有实例).|LinkisInstanceLabelErrorCodeSummary|
+|linkis-instance-label |14100|Only admin can modify instance label(只有管理员才能修改标签).|LinkisInstanceLabelErrorCodeSummary|
+|linkis-instance-label |14100|Failed to update label, include repeat label(更新label失败,包含重复label)|LinkisInstanceLabelErrorCodeSummary|
diff --git a/linkis-public-enhancements/linkis-instance-label/linkis-instance-label-server/src/main/java/org/apache/linkis/instance/label/errorcode/LinkisInstanceLabelErrorCodeSummary.java b/linkis-public-enhancements/linkis-instance-label/linkis-instance-label-server/src/main/java/org/apache/linkis/instance/label/errorcode/LinkisInstanceLabelErrorCodeSummary.java
new file mode 100644
index 000000000..425d539a3
--- /dev/null
+++ b/linkis-public-enhancements/linkis-instance-label/linkis-instance-label-server/src/main/java/org/apache/linkis/instance/label/errorcode/LinkisInstanceLabelErrorCodeSummary.java
@@ -0,0 +1,80 @@
+/*
+ * 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.instance.label.errorcode;
+
+public enum LinkisInstanceLabelErrorCodeSummary {
+ INSERT_SERVICE_INSTANCE(
+ 14100,
+ "Failed to insert service instance(插入服务实例失败)",
+ "Failed to insert service instance(插入服务实例失败)"),
+ ONLY_ADMIN_CAN_VIEW(
+ 14100,
+ "Only admin can view all instances(只有管理员才能查看所有实例).",
+ "Only admin can view all instances(只有管理员才能查看所有实例)."),
+ ONLY_ADMIN_CAN_MODIFY(
+ 14100,
+ "Only admin can modify instance label(只有管理员才能修改标签).",
+ "Only admin can modify instance label(只有管理员才能修改标签)."),
+ INCLUDE_REPEAT(
+ 14100,
+ "Failed to update label, include repeat label(更新label失败,包含重复label)",
+ "Failed to update label, include repeat label(更新label失败,包含重复label)"),
+ Express_All(14100, "", "");
+
+ /** (errorCode)错误码 */
+ private int errorCode;
+ /** (errorDesc)错误描述 */
+ private String errorDesc;
+ /** Possible reasons for the error(错误可能出现的原因) */
+ private String comment;
+
+ LinkisInstanceLabelErrorCodeSummary(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-public-enhancements/linkis-instance-label/linkis-instance-label-server/src/main/java/org/apache/linkis/instance/label/exception/InstanceErrorException.java b/linkis-public-enhancements/linkis-instance-label/linkis-instance-label-server/src/main/java/org/apache/linkis/instance/label/exception/InstanceErrorException.java
index b541822e0..9fe12883b 100644
--- a/linkis-public-enhancements/linkis-instance-label/linkis-instance-label-server/src/main/java/org/apache/linkis/instance/label/exception/InstanceErrorException.java
+++ b/linkis-public-enhancements/linkis-instance-label/linkis-instance-label-server/src/main/java/org/apache/linkis/instance/label/exception/InstanceErrorException.java
@@ -19,6 +19,8 @@ package org.apache.linkis.instance.label.exception;
import org.apache.linkis.common.exception.ErrorException;
+import static org.apache.linkis.instance.label.errorcode.LinkisInstanceLabelErrorCodeSummary.Express_All;
+
public class InstanceErrorException extends ErrorException {
public InstanceErrorException(int errCode, String desc) {
@@ -31,6 +33,6 @@ public class InstanceErrorException extends ErrorException {
}
public InstanceErrorException(String desc) {
- super(14100, desc);
+ super(Express_All.getErrorCode(), desc);
}
}
diff --git a/linkis-public-enhancements/linkis-instance-label/linkis-instance-label-server/src/main/java/org/apache/linkis/instance/label/restful/InstanceRestful.java b/linkis-public-enhancements/linkis-instance-label/linkis-instance-label-server/src/main/java/org/apache/linkis/instance/label/restful/InstanceRestful.java
index 4f1a7cbe1..9c7228a48 100644
--- a/linkis-public-enhancements/linkis-instance-label/linkis-instance-label-server/src/main/java/org/apache/linkis/instance/label/restful/InstanceRestful.java
+++ b/linkis-public-enhancements/linkis-instance-label/linkis-instance-label-server/src/main/java/org/apache/linkis/instance/label/restful/InstanceRestful.java
@@ -53,6 +53,8 @@ import io.swagger.annotations.ApiOperation;
import java.util.*;
+import static org.apache.linkis.instance.label.errorcode.LinkisInstanceLabelErrorCodeSummary.*;
+
@Api(tags = "instance restful")
@RestController
@RequestMapping(path = "/microservice")
@@ -72,7 +74,7 @@ public class InstanceRestful {
if (!Configuration.isAdmin(userName)) {
throw new InstanceErrorException(
String.format(
- "Only admin can view all instances(只有管理员才能查看所有实例). The user [%s] is not admin.",
+ ONLY_ADMIN_CAN_VIEW.getErrorDesc()+"The user [%s] is not admin.",
userName));
}
@@ -100,7 +102,7 @@ public class InstanceRestful {
if (!Configuration.isAdmin(userName)) {
throw new InstanceErrorException(
String.format(
- "Only admin can modify instance label(只有管理员才能修改标签). The user [%s] is not admin",
+ ONLY_ADMIN_CAN_MODIFY.getErrorDesc()+" The user [%s] is not admin",
userName));
}
String instanceName = jsonNode.get("instance").asText();
@@ -133,7 +135,7 @@ public class InstanceRestful {
}
if (labelKeySet.size() != labels.size()) {
throw new InstanceErrorException(
- "Failed to update label, include repeat label(更新label失败,包含重复label)");
+ INCLUDE_REPEAT.getErrorDesc());
}
insLabelService.refreshLabelsToInstance(labels, instance);
InstanceInfo instanceInfo = insLabelService.getInstanceInfoByServiceInstance(instance);
diff --git a/linkis-public-enhancements/linkis-instance-label/linkis-instance-label-server/src/main/java/org/apache/linkis/instance/label/service/impl/DefaultInsLabelService.java b/linkis-public-enhancements/linkis-instance-label/linkis-instance-label-server/src/main/java/org/apache/linkis/instance/label/service/impl/DefaultInsLabelService.java
index 7a0b4d831..b2bde3849 100644
--- a/linkis-public-enhancements/linkis-instance-label/linkis-instance-label-server/src/main/java/org/apache/linkis/instance/label/service/impl/DefaultInsLabelService.java
+++ b/linkis-public-enhancements/linkis-instance-label/linkis-instance-label-server/src/main/java/org/apache/linkis/instance/label/service/impl/DefaultInsLabelService.java
@@ -59,6 +59,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static org.apache.commons.lang3.math.NumberUtils.isCreatable;
+import static org.apache.linkis.instance.label.errorcode.LinkisInstanceLabelErrorCodeSummary.INSERT_SERVICE_INSTANCE;
@AdapterMode
@EnableAspectJAutoProxy(proxyTargetClass = true, exposeProxy = true)
@@ -406,7 +407,7 @@ public class DefaultInsLabelService implements InsLabelAccessService {
try {
instanceDao.insertOne(new InstanceInfo(serviceInstance));
} catch (Exception e) {
- throw new InstanceErrorException("Failed to insert service instance", e);
+ throw new InstanceErrorException(INSERT_SERVICE_INSTANCE.getErrorDesc(), e);
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@linkis.apache.org
For additional commands, e-mail: commits-help@linkis.apache.org