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:38:46 UTC
[incubator-linkis] branch dev-1.3.1 updated: [linkis-configuration]errorcode code optimization (#3522)
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 a5fc2a5ac [linkis-configuration]errorcode code optimization (#3522)
a5fc2a5ac is described below
commit a5fc2a5acbba2cc42d629360dd2a1d688dec74e6
Author: 成彬彬 <10...@users.noreply.github.com>
AuthorDate: Fri Sep 23 18:38:41 2022 +0800
[linkis-configuration]errorcode code optimization (#3522)
---
docs/errorcode/linkis-configuration -errorcode.md | 22 ++++
.../LinkisConfigurationErrorCodeSummary.java | 120 +++++++++++++++++++++
.../exception/ConfigurationException.java | 6 +-
.../restful/api/ConfigurationRestfulApi.java | 20 ++--
.../service/impl/ConfigKeyServiceImpl.java | 18 ++--
.../configuration/util/LabelParameterParser.scala | 3 +-
.../configuration/validate/FloatValidator.scala | 3 +-
.../validate/NumericalValidator.scala | 3 +-
8 files changed, 174 insertions(+), 21 deletions(-)
diff --git a/docs/errorcode/linkis-configuration -errorcode.md b/docs/errorcode/linkis-configuration -errorcode.md
new file mode 100644
index 000000000..a829eea64
--- /dev/null
+++ b/docs/errorcode/linkis-configuration -errorcode.md
@@ -0,0 +1,22 @@
+## linkis-configuration errorcode
+
+| 模块名(服务名) | 错误码 | 描述 | Exception Class|
+| -------- | -------- | ----- |-----|
+|linkis-configuration |14100|Failed to build label(建立标签失败)|LinkisConfigurationErrorCodeSummary|
+|linkis-configuration |14100|Failed to build label ,label is null(建立标签失败,标签为空)|LinkisConfigurationErrorCodeSummary|
+|linkis-configuration |14100|config key not exists:(配置键不存在:)|LinkisConfigurationErrorCodeSummary|
+|linkis-configuration |14100|label not exists:(标签不存在:)|LinkisConfigurationErrorCodeSummary|
+|linkis-configuration |14100|key or value cannot be null(键或值不能为空)|LinkisConfigurationErrorCodeSummary|
+|linkis-configuration |14100|params cannot be empty!(参数不能为空!)|LinkisConfigurationErrorCodeSummary|
+|linkis-configuration |14100|token is error(令牌是错误的)|LinkisConfigurationErrorCodeSummary|
+|linkis-configuration |14100|categoryName is null, cannot be added(categoryName 为空,无法添加)|LinkisConfigurationErrorCodeSummary|
+|linkis-configuration |14100|categoryName cannot be included '-'(类别名称不能包含 '-')|LinkisConfigurationErrorCodeSummary|
+|linkis-configuration |14100|creator is null, cannot be added(创建者为空,无法添加)|LinkisConfigurationErrorCodeSummary|
+|linkis-configuration |14100|engine type is null, cannot be added(引擎类型为空,无法添加)|LinkisConfigurationErrorCodeSummary|
+|linkis-configuration |14100|The saved engine type parameter is incorrect, please send it in a fixed format, such as spark-2.4.3(保存的引擎类型参数有误,请按照固定格式传送,例如spark-2.4.3)|LinkisConfigurationErrorCodeSummary|
+|linkis-configuration |14100|Incomplete request parameters, please reconfirm(请求参数不完整,请重新确认)|LinkisConfigurationErrorCodeSummary|
+|linkis-configuration |14100|only admin can modify category(只有管理员才能修改目录)|LinkisConfigurationErrorCodeSummary|
+|linkis-configuration |14100| The label parameter is empty(标签参数为空)|LinkisConfigurationErrorCodeSummary|
+|linkis-configuration |14100|error validator range!(错误验证器范围!)|LinkisConfigurationErrorCodeSummary|
+|linkis-configuration |14100|this type of label is not supported:{}(不支持这种类型的标签:{})|LinkisConfigurationErrorCodeSummary|
+
diff --git a/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/errorcode/LinkisConfigurationErrorCodeSummary.java b/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/errorcode/LinkisConfigurationErrorCodeSummary.java
new file mode 100644
index 000000000..cff85d6e5
--- /dev/null
+++ b/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/errorcode/LinkisConfigurationErrorCodeSummary.java
@@ -0,0 +1,120 @@
+/*
+ * 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.configuration.errorcode;
+
+import org.apache.linkis.common.errorcode.ErrorCodeUtils;
+
+public enum LinkisConfigurationErrorCodeSummary {
+ BUILD_LABEL_ID(14100, "", ""),
+ FAILED_TO_BUILD_LABEL(14100, "Failed to build label(建立标签失败)", "Failed to build label(建立标签失败)"),
+ BUILD_LABEL_IS_NULL(
+ 14100,
+ "Failed to build label ,label is null(建立标签失败,标签为空)",
+ "Failed to build label ,label is null(建立标签失败,标签为空)"),
+ CONFIGKEY_CANNOT_BE_NULL(
+ 14100,
+ "configKey cannot be null(configKey 不能为空)",
+ "configKey cannot be null(configKey 不能为空)"),
+ CONFIG_KEY_NOT_EXISTS(
+ 14100, "config key not exists:(配置键不存在:)", "config key not exists:(配置键不存在:)"),
+ LABEL_NOT_EXISTS(14100, "label not exists:(标签不存在:)", "label not exists:(标签不存在:)"),
+ KEY_OR_VALUE_CANNOT(
+ 14100, "key or value cannot be null(键或值不能为空)", " key or value cannot be null(键或值不能为空)"),
+ PARAMS_CANNOT_BE_EMPTY(
+ 14100, "params cannot be empty!(参数不能为空!)", "params cannot be empty!(参数不能为空!)"),
+ TOKEN_IS_ERROR(14100, "token is error(令牌是错误的)", "token is error(令牌是错误的)"),
+ IS_NULL_CANNOT_BE_ADDED(
+ 14100,
+ "categoryName is null, cannot be added(categoryName 为空,无法添加)",
+ "categoryName is null, cannot be added(categoryName 为空,无法添加)"),
+ CANNOT_BE_INCLUDED(
+ 14100,
+ "categoryName cannot be included '-'(类别名称不能包含 '-')",
+ "categoryName cannot be included '-'(类别名称不能包含 '-')"),
+ CREATOR_IS_NULL_CANNOT_BE_ADDED(
+ 14100,
+ "creator is null, cannot be added(创建者为空,无法添加)",
+ "creator is null, cannot be added(创建者为空,无法添加)"),
+ ENGINE_TYPE_IS_NULL(
+ 14100,
+ "engine type is null, cannot be added(引擎类型为空,无法添加)",
+ "engine type is null, cannot be added(引擎类型为空,无法添加)"),
+ INCORRECT_FIXED_SUCH(
+ 14100,
+ "The saved engine type parameter is incorrect, please send it in a fixed format, such as spark-2.4.3(保存的引擎类型参数有误,请按照固定格式传送,例如spark-2.4.3)",
+ "The saved engine type parameter is incorrect, please send it in a fixed format, such as spark-2.4.3(保存的引擎类型参数有误,请按照固定格式传送,例如spark-2.4.3)"),
+ INCOMPLETE_RECONFIRM(
+ 14100,
+ "Incomplete request parameters, please reconfirm(请求参数不完整,请重新确认)",
+ "Incomplete request parameters, please reconfirm(请求参数不完整,请重新确认)"),
+ ONLY_ADMIN_CAN_MODIFY(
+ 14100,
+ "only admin can modify category(只有管理员才能修改目录)",
+ "only admin can modify category(只有管理员才能修改目录)"),
+ THE_LABEL_PARAMETER_IS_EMPTY(
+ 14100, " The label parameter is empty(标签参数为空)", " The label parameter is empty(标签参数为空)"),
+ ERROR_VALIDATOR_RANGE(
+ 14100, "error validator range!(错误验证器范围!)", "error validator range!(错误验证器范围!)"),
+ TYPE_OF_LABEL_NOT_SUPPORTED(
+ 14100,
+ "this type of label is not supported:{}(不支持这种类型的标签:{})",
+ "this type of label is not supported:{}(不支持这种类型的标签:{})");
+
+ /** 错误码 */
+ private int errorCode;
+ /** 错误描述 */
+ private String errorDesc;
+ /** 错误可能出现的原因 */
+ private String comment;
+
+ LinkisConfigurationErrorCodeSummary(int errorCode, String errorDesc, String comment) {
+ ErrorCodeUtils.validateErrorCode(errorCode, 20000, 24999);
+ 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-configuration/src/main/java/org/apache/linkis/configuration/exception/ConfigurationException.java b/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/exception/ConfigurationException.java
index f91165c52..9f27f1253 100644
--- a/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/exception/ConfigurationException.java
+++ b/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/exception/ConfigurationException.java
@@ -19,16 +19,18 @@ package org.apache.linkis.configuration.exception;
import org.apache.linkis.common.exception.ErrorException;
+import static org.apache.linkis.configuration.errorcode.LinkisConfigurationErrorCodeSummary.BUILD_LABEL_ID;
+
public class ConfigurationException extends ErrorException {
public static final int CONFIGURATION_ERROR_CODE = 14100;
public ConfigurationException(String message) {
- super(14100, message);
+ super(BUILD_LABEL_ID.getErrorCode(), message);
}
public ConfigurationException(String message, Throwable throwable) {
- super(14100, message);
+ super(BUILD_LABEL_ID.getErrorCode(), message);
initCause(throwable);
}
}
diff --git a/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/restful/api/ConfigurationRestfulApi.java b/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/restful/api/ConfigurationRestfulApi.java
index d56a159c3..c2106a8ac 100644
--- a/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/restful/api/ConfigurationRestfulApi.java
+++ b/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/restful/api/ConfigurationRestfulApi.java
@@ -55,6 +55,8 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Map;
+import static org.apache.linkis.configuration.errorcode.LinkisConfigurationErrorCodeSummary.*;
+
@Api(tags = "parameter configuration")
@RestController
@RequestMapping(path = "/configuration")
@@ -90,11 +92,11 @@ public class ConfigurationRestfulApi {
if (StringUtils.isBlank(engineType)
|| StringUtils.isBlank(version)
|| StringUtils.isBlank(token)) {
- throw new ConfigurationException("params cannot be empty!");
+ throw new ConfigurationException(PARAMS_CANNOT_BE_EMPTY.getErrorDesc());
}
// todo 检验token
if (!token.equals(ConfigurationConfiguration.COPYKEYTOKEN)) {
- throw new ConfigurationException("token is error");
+ throw new ConfigurationException(TOKEN_IS_ERROR.getErrorDesc());
}
ConfigKey configKey = BDPJettyServerHelper.gson().fromJson(keyJson, ConfigKey.class);
configurationService.addKeyForEngine(engineType, version, configKey);
@@ -150,10 +152,10 @@ public class ConfigurationRestfulApi {
String categoryName = jsonNode.get("categoryName").asText();
String description = jsonNode.get("description").asText();
if (StringUtils.isEmpty(categoryName) || categoryName.equals(NULL)) {
- throw new ConfigurationException("categoryName is null, cannot be added");
+ throw new ConfigurationException(IS_NULL_CANNOT_BE_ADDED.getErrorDesc());
}
if (StringUtils.isEmpty(categoryName) || categoryName.contains("-")) {
- throw new ConfigurationException("categoryName cannot be included '-'");
+ throw new ConfigurationException(CANNOT_BE_INCLUDED.getErrorDesc());
}
categoryService.createFirstCategory(categoryName, description);
return Message.ok();
@@ -192,10 +194,10 @@ public class ConfigurationRestfulApi {
String version = jsonNode.get("version").asText();
String description = jsonNode.get("description").asText();
if (categoryId <= 0) {
- throw new ConfigurationException("creator is null, cannot be added");
+ throw new ConfigurationException(CREATOR_IS_NULL_CANNOT_BE_ADDED.getErrorDesc());
}
if (StringUtils.isEmpty(engineType) || engineType.toLowerCase().equals(NULL)) {
- throw new ConfigurationException("engine type is null, cannot be added");
+ throw new ConfigurationException(ENGINE_TYPE_IS_NULL.getErrorDesc());
}
if (StringUtils.isEmpty(version) || version.toLowerCase().equals(NULL)) {
version = LabelUtils.COMMON_VALUE;
@@ -242,7 +244,7 @@ public class ConfigurationRestfulApi {
String[] tmpString = engineType.split("-");
if (tmpString.length != 2) {
throw new ConfigurationException(
- "The saved engine type parameter is incorrect, please send it in a fixed format, such as spark-2.4.3(保存的引擎类型参数有误,请按照固定格式传送,例如spark-2.4.3)");
+ INCORRECT_FIXED_SUCH.getErrorDesc());
}
engine = tmpString[0];
version = tmpString[1];
@@ -277,7 +279,7 @@ public class ConfigurationRestfulApi {
description = jsonNode.get("description").asText();
categoryId = jsonNode.get("categoryId").asInt();
} catch (Exception e) {
- throw new ConfigurationException("请求参数不完整,请重新确认");
+ throw new ConfigurationException(INCOMPLETE_RECONFIRM.getErrorDesc());
}
if (description != null) {
categoryService.updateCategory(categoryId, description);
@@ -313,7 +315,7 @@ public class ConfigurationRestfulApi {
private void checkAdmin(String userName) throws ConfigurationException {
if (!Configuration.isAdmin(userName)) {
- throw new ConfigurationException("only admin can modify category(只有管理员才能修改目录)");
+ throw new ConfigurationException(ONLY_ADMIN_CAN_MODIFY.getErrorDesc());
}
}
diff --git a/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/service/impl/ConfigKeyServiceImpl.java b/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/service/impl/ConfigKeyServiceImpl.java
index bd59f4818..6e54e742b 100644
--- a/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/service/impl/ConfigKeyServiceImpl.java
+++ b/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/service/impl/ConfigKeyServiceImpl.java
@@ -45,6 +45,8 @@ import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import static org.apache.linkis.configuration.errorcode.LinkisConfigurationErrorCodeSummary.*;
+
@Service
public class ConfigKeyServiceImpl implements ConfigKeyService {
@@ -62,13 +64,14 @@ public class ConfigKeyServiceImpl implements ConfigKeyService {
if (StringUtils.isBlank(configKeyValue.getConfigValue())
|| StringUtils.isBlank(configKeyValue.getKey())) {
- throw new ConfigurationException("key or value cannot be null");
+ throw new ConfigurationException(KEY_OR_VALUE_CANNOT.getErrorDesc());
}
LabelParameterParser.labelCheck(labelList);
List<ConfigKey> configKeys = configMapper.seleteKeyByKeyName(configKeyValue.getKey());
if (null == configKeys || configKeys.isEmpty()) {
- throw new ConfigurationException("config key not exists: " + configKeyValue.getKey());
+ throw new ConfigurationException(
+ CONFIG_KEY_NOT_EXISTS.getErrorDesc() + configKeyValue.getKey());
}
ConfigKey configKey = configKeys.get(0);
EngineTypeLabel engineTypeLabel = LabelUtil.getEngineTypeLabel(labelList);
@@ -117,10 +120,10 @@ public class ConfigKeyServiceImpl implements ConfigKeyService {
try {
combinedLabel = (CombinedLabel) combinedLabelBuilder.build("", labelList);
} catch (LabelErrorException e) {
- throw new ConfigurationException("Failed to build label", e);
+ throw new ConfigurationException(FAILED_TO_BUILD_LABEL.getErrorDesc(), e);
}
if (null == combinedLabel) {
- throw new ConfigurationException("Failed to build label ,label is null");
+ throw new ConfigurationException(BUILD_LABEL_IS_NULL.getErrorDesc());
}
return combinedLabel;
}
@@ -129,20 +132,21 @@ public class ConfigKeyServiceImpl implements ConfigKeyService {
public List<ConfigValue> getConfigValue(String key, List<Label<?>> labelList)
throws ConfigurationException {
if (StringUtils.isBlank(key)) {
- throw new ConfigurationException("configKey cannot be null");
+ throw new ConfigurationException(CONFIGKEY_CANNOT_BE_NULL.getErrorDesc());
}
LabelParameterParser.labelCheck(labelList);
List<ConfigKey> configKeys = configMapper.seleteKeyByKeyName(key);
if (null == configKeys || configKeys.isEmpty()) {
- throw new ConfigurationException("config key not exists: " + key);
+ throw new ConfigurationException(CONFIG_KEY_NOT_EXISTS.getErrorDesc() + key);
}
CombinedLabel combinedLabel = getCombinedLabel(labelList);
ConfigLabel configLabel =
labelMapper.getLabelByKeyValue(combinedLabel.getLabelKey(), combinedLabel.getStringValue());
if (null == configLabel || configLabel.getId() < 0) {
- throw new ConfigurationException("label not exists: " + combinedLabel.getStringValue());
+ throw new ConfigurationException(
+ LABEL_NOT_EXISTS.getErrorDesc() + combinedLabel.getStringValue());
}
List<ConfigValue> configValues = new ArrayList<>();
for (ConfigKey configKey : configKeys) {
diff --git a/linkis-public-enhancements/linkis-configuration/src/main/scala/org/apache/linkis/configuration/util/LabelParameterParser.scala b/linkis-public-enhancements/linkis-configuration/src/main/scala/org/apache/linkis/configuration/util/LabelParameterParser.scala
index 2fb9ef50d..d257579da 100644
--- a/linkis-public-enhancements/linkis-configuration/src/main/scala/org/apache/linkis/configuration/util/LabelParameterParser.scala
+++ b/linkis-public-enhancements/linkis-configuration/src/main/scala/org/apache/linkis/configuration/util/LabelParameterParser.scala
@@ -18,6 +18,7 @@
package org.apache.linkis.configuration.util
import org.apache.linkis.common.conf.CommonVars
+import org.apache.linkis.configuration.errorcode.LinkisConfigurationErrorCodeSummary.THE_LABEL_PARAMETER_IS_EMPTY
import org.apache.linkis.configuration.exception.ConfigurationException
import org.apache.linkis.governance.common.conf.GovernanceCommonConf
import org.apache.linkis.manager.label.builder.factory.LabelBuilderFactoryContext
@@ -89,7 +90,7 @@ object LabelParameterParser {
}
true
} else {
- throw new ConfigurationException("The label parameter is empty")
+ throw new ConfigurationException(THE_LABEL_PARAMETER_IS_EMPTY.getErrorDesc())
}
}
diff --git a/linkis-public-enhancements/linkis-configuration/src/main/scala/org/apache/linkis/configuration/validate/FloatValidator.scala b/linkis-public-enhancements/linkis-configuration/src/main/scala/org/apache/linkis/configuration/validate/FloatValidator.scala
index 15ee09eab..a256073cc 100644
--- a/linkis-public-enhancements/linkis-configuration/src/main/scala/org/apache/linkis/configuration/validate/FloatValidator.scala
+++ b/linkis-public-enhancements/linkis-configuration/src/main/scala/org/apache/linkis/configuration/validate/FloatValidator.scala
@@ -18,6 +18,7 @@
package org.apache.linkis.configuration.validate
import org.apache.linkis.common.utils.Logging
+import org.apache.linkis.configuration.errorcode.LinkisConfigurationErrorCodeSummary.ERROR_VALIDATOR_RANGE
import org.apache.linkis.configuration.exception.ConfigurationException
import com.google.gson.GsonBuilder
@@ -28,7 +29,7 @@ class FloatValidator extends Validator with Logging {
try {
val rangArray = new GsonBuilder().create().fromJson(range, classOf[Array[Double]])
if (rangArray.size != 2) {
- throw new ConfigurationException("error validator range!")
+ throw new ConfigurationException(ERROR_VALIDATOR_RANGE.getErrorDesc)
}
value.toDouble >= rangArray.sorted.apply(0) && value.toDouble <= rangArray.sorted.apply(1)
} catch {
diff --git a/linkis-public-enhancements/linkis-configuration/src/main/scala/org/apache/linkis/configuration/validate/NumericalValidator.scala b/linkis-public-enhancements/linkis-configuration/src/main/scala/org/apache/linkis/configuration/validate/NumericalValidator.scala
index 87aa62f09..696b6442a 100644
--- a/linkis-public-enhancements/linkis-configuration/src/main/scala/org/apache/linkis/configuration/validate/NumericalValidator.scala
+++ b/linkis-public-enhancements/linkis-configuration/src/main/scala/org/apache/linkis/configuration/validate/NumericalValidator.scala
@@ -18,6 +18,7 @@
package org.apache.linkis.configuration.validate
import org.apache.linkis.common.utils.{Logging, Utils}
+import org.apache.linkis.configuration.errorcode.LinkisConfigurationErrorCodeSummary.ERROR_VALIDATOR_RANGE
import org.apache.linkis.configuration.exception.ConfigurationException
import com.google.gson.GsonBuilder
@@ -29,7 +30,7 @@ class NumericalValidator extends Validator with Logging {
val rangArray = new GsonBuilder().create().fromJson(range, classOf[Array[Int]])
val valueInt = Integer.parseInt(value)
if (rangArray.size != 2) {
- throw new ConfigurationException("error validator range!")
+ throw new ConfigurationException(ERROR_VALIDATOR_RANGE.getErrorDesc)
}
valueInt >= rangArray.sorted.apply(0) && valueInt <= rangArray.sorted.apply(1)
} {
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@linkis.apache.org
For additional commands, e-mail: commits-help@linkis.apache.org