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/18 02:26:44 UTC
[incubator-linkis] branch dev-1.3.1-errorcode updated: [WIP][linkis-udf-common]module errorcode optimization and documentation (#3605)
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 2078b80a4 [WIP][linkis-udf-common]module errorcode optimization and documentation (#3605)
2078b80a4 is described below
commit 2078b80a4d3cb766b22c6be47e06fc34f9c7734f
Author: 成彬彬 <10...@users.noreply.github.com>
AuthorDate: Tue Oct 18 10:26:40 2022 +0800
[WIP][linkis-udf-common]module errorcode optimization and documentation (#3605)
---
docs/errorcode/linkis-udf-common-errorcode.md | 42 +++++
.../udf/errorcode/UdfCommonErrorCodeSummary.java | 206 +++++++++++++++++++++
.../apache/linkis/udf/excepiton/UDFException.java | 14 +-
.../linkis/udf/excepiton/UDFExceptionTest.java | 2 +-
.../org/apache/linkis/udf/api/UDFRestfulApi.java | 45 +++--
.../linkis/udf/service/impl/UDFServiceImpl.java | 66 +++----
.../udf/service/impl/UDFTreeServiceImpl.java | 19 +-
7 files changed, 318 insertions(+), 76 deletions(-)
diff --git a/docs/errorcode/linkis-udf-common-errorcode.md b/docs/errorcode/linkis-udf-common-errorcode.md
new file mode 100644
index 000000000..dbba54d5f
--- /dev/null
+++ b/docs/errorcode/linkis-udf-common-errorcode.md
@@ -0,0 +1,42 @@
+## linkis-udf-common errorcode
+
+| module name(模块名) | error code(错误码) | describe(描述) |enumeration name(枚举)| Exception Class(类名)|
+| -------- | -------- | ----- |-----|-----|
+|linkis-udf-common |202011|UserName is empty(用户名为空)|USER_NAME_EMPTY|UdfCommonErrorCodeSummary|
+|linkis-udf-common |202011|UdfId is empty(udfId为空)|UDFID_EMPTY|UdfCommonErrorCodeSummary|
+|linkis-udf-common |202011|Only manager can share udf(只有manager可以共享 udf)|ONLY_MANAGER_SHARE|UdfCommonErrorCodeSummary|
+|linkis-udf-common |202011|Only manager can publish udf(只有manager可以发布 udf)|ONLY_MANAGER_PUBLISH|UdfCommonErrorCodeSummary|
+|linkis-udf-common |202011|Can't find udf by this id(通过这个 id 找不到 udf)|NOT_FIND_UDF|UdfCommonErrorCodeSummary|
+|linkis-udf-common |202011|UserList cat not be null(userList cat 不为空)|USERLIST_NOT_NULL|UdfCommonErrorCodeSummary|
+|linkis-udf-common |202011|The handover user can't be null(切换用户不能为空)|HANDOVER_NOT_NULL|UdfCommonErrorCodeSummary|
+|linkis-udf-common |202011|Admin users cannot hand over UDFs to regular users.(管理员用户不能移交UDF给普通用户!)|ADMIN_NOT_HANDOVER_UDF|UdfCommonErrorCodeSummary|
+|linkis-udf-common |202011|CreateUser must be consistent with the operation user(创建用户必须和操作用户一致)|MUST_OPERATION_USER|UdfCommonErrorCodeSummary|
+|linkis-udf-common |202011|The name of udf is the same name. Please rename it and rebuild it.(udf的名字重名,请改名后重建)|UDF_SAME_NAME|UdfCommonErrorCodeSummary|
+|linkis-udf-common |202011|Category name cannot be empty!(分类名不能为空!)|CATEGORY_NOT_EMPTY|UdfCommonErrorCodeSummary|
+|linkis-udf-common |202011|File read exception(文件读取异常):|FILE_READ_EXCEPTION|UdfCommonErrorCodeSummary|
+|linkis-udf-common |202011|Upload to bml failed, file path is(上传到bml失败,文件路径为):|UPLOAD_BML_FAILED|UdfCommonErrorCodeSummary|
+|linkis-udf-common |202011|Upload to bml failed, msg(上传到bml异常!msg):|UPLOAD_BML_FAILED_MSG|UdfCommonErrorCodeSummary|
+|linkis-udf-common |202011|A jar with the same name already exists in the user's udf!(用户的udf已存在同名jar!)|JAR_SAME_NAME|UdfCommonErrorCodeSummary|
+|linkis-udf-common |202011|id Can not be empty(不能为空)|ID_NOT_EMPTY|UdfCommonErrorCodeSummary|
+|linkis-udf-common |202011|This user does not have a personal function directory!(该用户没有个人函数目录!)|NOT_FUNCTION_DIRECTORY|UdfCommonErrorCodeSummary|
+|linkis-udf-common |202011|Current user must be consistent with the modified user(当前用户必须和修改用户一致)|CURRENT_MUST_MODIFIED|UdfCommonErrorCodeSummary|
+|linkis-udf-common |202011|Current user must be consistent with the user created(当前用户必须和创建用户一致)|CURRENT_MUST_MODIFIED_CREATED|UdfCommonErrorCodeSummary|
+|linkis-udf-common |202011|UDF type modification is not allowed(不允许修改 UDF 类型)|UDF_MODIFICATION_NOT_ALLOWED|UdfCommonErrorCodeSummary|
+|linkis-udf-common |202011|The name of udf is not allowed modified.(udf的名字禁止修改!)|NOT_ALLOWED_MODIFIED|UdfCommonErrorCodeSummary|
+|linkis-udf-common |202011|Can't found latestVersion for the udf(找不到 udf 的最新版本)|NOT_FOUND_VERSION|UdfCommonErrorCodeSummary|
+|linkis-udf-common |202011|The handoverUser has same name udf.(被移交用户包含重名udf)|HANDOVER_SAME_NAME_UDF|UdfCommonErrorCodeSummary|
+|linkis-udf-common |202011|The publish operation is not supported for non-shared udfs!(非共享udf不支持发布操作!)|OPERATION_NOT_SUPPORTED|UdfCommonErrorCodeSummary|
+|linkis-udf-common |202011|Bml rollback version abnormal(bml回滚版本异常)|ROLLBACK_VERSION_ABNORMAL|UdfCommonErrorCodeSummary|
+|linkis-udf-common |202011|The udf of jar type content does not support downloading and viewing(jar类型内容的udf不支持下载查看)|JAR_NOT_DOWNLOADING|UdfCommonErrorCodeSummary|
+|linkis-udf-common |202011|There is a Jar package function with the same name(存在同名的Jar包函数): |SAME_NAME_FUNCTION|UdfCommonErrorCodeSummary|
+|linkis-udf-common |202011|Do not support sharing to yourself!(不支持分享给自己!) |NOT_SHARING_YOURSELF|UdfCommonErrorCodeSummary|
+|linkis-udf-common |202011|Duplicate file name(文件名重复)|DUPLICATE_FILE_NAME|UdfCommonErrorCodeSummary|
+|linkis-udf-common |202011|Failed to copy resource to anotherUser(无法将资源复制到另一个用户):|FAILED_COPY_RESOURCE|UdfCommonErrorCodeSummary|
+|linkis-udf-common |202011|Shared users cannot contain empty usernames(共享用户不能包含空用户名)|SHARED_USERS_NOT_EMPTY|UdfCommonErrorCodeSummary|
+|linkis-udf-common |202011|Username can only contain alphanumeric underscores(用户名只能包含字母数字下划线)|CONTAIN_NUMERIC_SCORES|UdfCommonErrorCodeSummary|
+|linkis-udf-common |202011|User contains the same name udf!(用户包含同名udf!)|CONTAINS_SAME_NAME|UdfCommonErrorCodeSummary|
+|linkis-udf-common |202011|Shared udf name Already exists, please edit the name and re-share(分享的udf的名字已存在,请修改名字后重新进行分享)|ALREADY_EXISTS_SHARE|UdfCommonErrorCodeSummary|
+|linkis-udf-common |202011|Only the udf loaded by the shared user can be set to expire(只有被共享用户加载的udf可以设置过期)|SHARED_USER_EXPIRE|UdfCommonErrorCodeSummary|
+|linkis-udf-common |202011|User There are two root directory directories,user(用户存在两个根目录目录,用户):|DIRECTORY_DIRECTORIES|UdfCommonErrorCodeSummary|
+|linkis-udf-common |202011|User the parent directory is not yours,user(用户父目录不是你的,用户):|DIRECTORY_PARENT|UdfCommonErrorCodeSummary|
+
diff --git a/linkis-public-enhancements/linkis-udf/linkis-udf-common/src/main/java/org/apache/linkis/udf/errorcode/UdfCommonErrorCodeSummary.java b/linkis-public-enhancements/linkis-udf/linkis-udf-common/src/main/java/org/apache/linkis/udf/errorcode/UdfCommonErrorCodeSummary.java
new file mode 100644
index 000000000..cb3bdc575
--- /dev/null
+++ b/linkis-public-enhancements/linkis-udf/linkis-udf-common/src/main/java/org/apache/linkis/udf/errorcode/UdfCommonErrorCodeSummary.java
@@ -0,0 +1,206 @@
+/*
+ * 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.udf.errorcode;
+
+public enum UdfCommonErrorCodeSummary {
+ UDF_EXCEPTION_ID(202011, "", ""),
+ USER_NAME_EMPTY(202011, "UserName is Empty(用户名为空)", "UserName is Empty(用户名为空)"),
+ UDFID_EMPTY(202011, "UdfId is empty(udfId为空)", "UdfId is empty(udfId为空)"),
+ ONLY_MANAGER_SHARE(
+ 202011,
+ "Only manager can share udf(只有manager可以共享 udf)",
+ "Only manager can share udf(只有manager可以共享 udf)"),
+ ONLY_MANAGER_PUBLISH(
+ 202011,
+ "Only manager can publish udf(只有manager可以发布 udf)",
+ "Only manager can publish udf(只有manager可以发布 udf)"),
+ NOT_FIND_UDF(
+ 202011,
+ "Can't find udf by this id(通过这个 id 找不到 udf)",
+ "Can't find udf by this id(通过这个 id 找不到 udf)"),
+
+ USERLIST_NOT_NULL(
+ 202011,
+ "UserList cat not be null(userList cat 不为空)",
+ "UserList cat not be null(userList cat 不为空)"),
+ HANDOVER_NOT_NULL(
+ 202011,
+ "The handover user can't be null(切换用户不能为空)",
+ "The handover user can't be null(切换用户不能为空)"),
+ ADMIN_NOT_HANDOVER_UDF(
+ 202011,
+ "Admin users cannot hand over UDFs to regular users.(管理员用户不能移交UDF给普通用户!)",
+ "Admin users cannot hand over UDFs to regular users.(管理员用户不能移交UDF给普通用户!)"),
+ MUST_OPERATION_USER(
+ 202011,
+ "CreateUser must be consistent with the operation user(创建用户必须和操作用户一致)",
+ "CreateUser must be consistent with the operation user(创建用户必须和操作用户一致)"),
+ UDF_SAME_NAME(
+ 202011,
+ "The name of udf is the same name. Please rename it and rebuild it.(udf的名字重名,请改名后重建)",
+ "The name of udf is the same name. Please rename it and rebuild it.(udf的名字重名,请改名后重建)"),
+ CATEGORY_NOT_EMPTY(
+ 202011,
+ "Category name cannot be empty!(分类名不能为空!)",
+ "Category name cannot be empty!(分类名不能为空!)"),
+ FILE_READ_EXCEPTION(202011, "File read exception(文件读取异常):", "File read exception(文件读取异常):"),
+ UPLOAD_BML_FAILED(
+ 202011,
+ "Upload to bml failed, file path is(上传到bml失败,文件路径为):",
+ "Upload to bml failed, file path is(上传到bml失败,文件路径为):"),
+ UPLOAD_BML_FAILED_MSG(
+ 202011,
+ "Upload to bml failed, msg(上传到bml异常!msg):",
+ "Upload to bml failed, msg(上传到bml异常!msg):"),
+ JAR_SAME_NAME(
+ 202011,
+ "A jar with the same name already exists in the user's udf!(用户的udf已存在同名jar!)",
+ "A jar with the same name already exists in the user's udf!(用户的udf已存在同名jar!)"),
+ ID_NOT_EMPTY(202011, "id Can not be empty(不能为空)", "id Can not be empty(不能为空)"),
+ NOT_FUNCTION_DIRECTORY(
+ 202011,
+ "This user does not have a personal function directory!(该用户没有个人函数目录!)",
+ "This user does not have a personal function directory!(该用户没有个人函数目录!)"),
+ OLD_UDF_FOUND(
+ 202011,
+ "No old UDF found by this ID(此 ID 未找到旧 UDF)",
+ "No old UDF found by this ID(此 ID 未找到旧 UDF)"),
+ CURRENT_MUST_MODIFIED(
+ 202011,
+ "Current user must be consistent with the modified user(当前用户必须和修改用户一致)",
+ "Current user must be consistent with the modified user(当前用户必须和修改用户一致)"),
+ CURRENT_MUST_MODIFIED_CREATED(
+ 202011,
+ "Current user must be consistent with the user created(当前用户必须和创建用户一致)",
+ "Current user must be consistent with the user created(当前用户必须和创建用户一致)"),
+ UDF_MODIFICATION_NOT_ALLOWED(
+ 202011,
+ "UDF type modification is not allowed(不允许修改 UDF 类型)",
+ "UDF type modification is not allowed(不允许修改 UDF 类型)"),
+ NOT_ALLOWED_MODIFIED(
+ 202011,
+ "The name of udf is not allowed modified.(udf的名字禁止修改!)",
+ "The name of udf is not allowed modified.(udf的名字禁止修改!)"),
+ NOT_FOUND_VERSION(
+ 202011,
+ "Can't found latestVersion for the udf(找不到 udf 的最新版本)",
+ "Can't found latestVersion for the udf(找不到 udf 的最新版本)"),
+ HANDOVER_SAME_NAME_UDF(
+ 202011,
+ "The handoverUser has same name udf.(被移交用户包含重名udf)",
+ "The handoverUser has same name udf.(被移交用户包含重名udf)"),
+ OPERATION_NOT_SUPPORTED(
+ 202011,
+ "The publish operation is not supported for non-shared udfs!(非共享udf不支持发布操作!)",
+ "The publish operation is not supported for non-shared udfs!(非共享udf不支持发布操作!)"),
+ ROLLBACK_VERSION_ABNORMAL(
+ 202011,
+ "Bml rollback version abnormal(bml回滚版本异常)",
+ "Bml rollback version abnormal(bml回滚版本异常)"),
+ JAR_NOT_DOWNLOADING(
+ 202011,
+ "The udf of jar type content does not support downloading and viewing(jar类型内容的udf不支持下载查看)",
+ "The udf of jar type content does not support downloading and viewing(jar类型内容的udf不支持下载查看)"),
+ CANNOT_DELETED(
+ 202011,
+ "The shared udf is loaded by the user and cannot be deleted(该共享udf被用户加载,不能删除)",
+ "The shared udf is loaded by the user and cannot be deleted(该共享udf被用户加载,不能删除)"),
+ SAME_NAME_FUNCTION(
+ 202011,
+ "There is a Jar package function with the same name(存在同名的Jar包函数): ",
+ "There is a Jar package function with the same name(存在同名的Jar包函数): "),
+ NOT_SHARING_YOURSELF(
+ 202011,
+ "Do not support sharing to yourself!(不支持分享给自己!) ",
+ "Do not support sharing to yourself!(不支持分享给自己!)"),
+ DUPLICATE_FILE_NAME(202011, "Duplicate file name(文件名重复)", "Duplicate file name(文件名重复)"),
+ FAILED_COPY_RESOURCE(
+ 202011,
+ "Failed to copy resource to anotherUser(无法将资源复制到另一个用户):",
+ "Failed to copy resource to anotherUser(无法将资源复制到另一个用户):"),
+ SHARED_USERS_NOT_EMPTY(
+ 202011,
+ "Shared users cannot contain empty usernames(共享用户不能包含空用户名)",
+ "Shared users cannot contain empty usernames(共享用户不能包含空用户名)"),
+ CONTAIN_NUMERIC_SCORES(
+ 202011,
+ "Username can only contain alphanumeric underscores(用户名只能包含字母数字下划线)",
+ "Username can only contain alphanumeric underscores(用户名只能包含字母数字下划线)"),
+ CONTAINS_SAME_NAME(
+ 202011,
+ "User contains the same name udf!(用户包含同名udf!)",
+ "User contains the same name udf!(用户包含同名udf!)"),
+ ALREADY_EXISTS_SHARE(
+ 202011,
+ "Shared udf name Already exists, please edit the name and re-share(分享的udf的名字已存在,请修改名字后重新进行分享)",
+ "Shared udf name Already exists, please edit the name and re-share(分享的udf的名字已存在,请修改名字后重新进行分享)"),
+ SHARED_USER_EXPIRE(
+ 202011,
+ "Only the udf loaded by the shared user can be set to expire(只有被共享用户加载的udf可以设置过期)",
+ "Only the udf loaded by the shared user can be set to expire(只有被共享用户加载的udf可以设置过期)"),
+ DIRECTORY_DIRECTORIES(
+ 202011,
+ "User There are two root directory directories,user(用户存在两个根目录目录,用户):",
+ "User There are two root directory directories,user(用户存在两个根目录目录,用户):"),
+ DIRECTORY_PARENT(
+ 202011,
+ "User the parent directory is not yours,user(用户父目录不是你的,用户):",
+ "User the parent directory is not yours,user(用户父目录不是你的,用户):");
+
+ /** (errorCode)错误码 */
+ private int errorCode;
+ /** (errorDesc)错误描述 */
+ private String errorDesc;
+ /** Possible reasons for the error(错误可能出现的原因) */
+ private String comment;
+
+ UdfCommonErrorCodeSummary(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-udf/linkis-udf-common/src/main/java/org/apache/linkis/udf/excepiton/UDFException.java b/linkis-public-enhancements/linkis-udf/linkis-udf-common/src/main/java/org/apache/linkis/udf/excepiton/UDFException.java
index dcbcb909e..46dd819fa 100644
--- a/linkis-public-enhancements/linkis-udf/linkis-udf-common/src/main/java/org/apache/linkis/udf/excepiton/UDFException.java
+++ b/linkis-public-enhancements/linkis-udf/linkis-udf-common/src/main/java/org/apache/linkis/udf/excepiton/UDFException.java
@@ -17,13 +17,17 @@
package org.apache.linkis.udf.excepiton;
-public class UDFException extends Exception {
+import org.apache.linkis.common.exception.ErrorException;
- public UDFException() {
- super();
+import static org.apache.linkis.udf.errorcode.UdfCommonErrorCodeSummary.UDF_EXCEPTION_ID;
+
+public class UDFException extends ErrorException {
+
+ public UDFException(String desc) {
+ super(UDF_EXCEPTION_ID.getErrorCode(), desc);
}
- public UDFException(String message) {
- super(message);
+ public UDFException(int errCode, String desc) {
+ super(errCode, desc);
}
}
diff --git a/linkis-public-enhancements/linkis-udf/linkis-udf-common/src/test/java/org/apache/linkis/udf/excepiton/UDFExceptionTest.java b/linkis-public-enhancements/linkis-udf/linkis-udf-common/src/test/java/org/apache/linkis/udf/excepiton/UDFExceptionTest.java
index 58d03594e..298418e05 100644
--- a/linkis-public-enhancements/linkis-udf/linkis-udf-common/src/test/java/org/apache/linkis/udf/excepiton/UDFExceptionTest.java
+++ b/linkis-public-enhancements/linkis-udf/linkis-udf-common/src/test/java/org/apache/linkis/udf/excepiton/UDFExceptionTest.java
@@ -28,6 +28,6 @@ public class UDFExceptionTest {
public void udfExceptionTest() {
String errorMsg = "udf is not exist";
UDFException udfException = new UDFException(errorMsg);
- Assertions.assertEquals(errorMsg, udfException.getMessage());
+ Assertions.assertEquals(errorMsg, udfException.getDesc());
}
}
diff --git a/linkis-public-enhancements/linkis-udf/linkis-udf-service/src/main/java/org/apache/linkis/udf/api/UDFRestfulApi.java b/linkis-public-enhancements/linkis-udf/linkis-udf-service/src/main/java/org/apache/linkis/udf/api/UDFRestfulApi.java
index e63b6424e..ed24eb08e 100644
--- a/linkis-public-enhancements/linkis-udf/linkis-udf-service/src/main/java/org/apache/linkis/udf/api/UDFRestfulApi.java
+++ b/linkis-public-enhancements/linkis-udf/linkis-udf-service/src/main/java/org/apache/linkis/udf/api/UDFRestfulApi.java
@@ -58,6 +58,7 @@ import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import static org.apache.linkis.udf.errorcode.UdfCommonErrorCodeSummary.*;
import static org.apache.linkis.udf.utils.ConstantVar.*;
@Api(tags = "UDF management")
@@ -421,7 +422,7 @@ public class UDFRestfulApi {
try {
String userName = ModuleUserUtils.getOperationUser(req);
if (StringUtils.isEmpty(userName)) {
- throw new UDFException("UserName is Empty!");
+ throw new UDFException(USER_NAME_EMPTY.getErrorDesc());
}
Boolean boo = udfService.isUDFManager(userName);
message = Message.ok();
@@ -446,11 +447,11 @@ public class UDFRestfulApi {
try {
Long udfId = json.get("udfId").longValue();
if (StringUtils.isEmpty(udfId)) {
- throw new UDFException("udfId is Empty!");
+ throw new UDFException(UDFID_EMPTY.getErrorDesc());
}
String userName = ModuleUserUtils.getOperationUser(req, "set expire udf " + udfId);
if (StringUtils.isEmpty(userName)) {
- throw new UDFException("UserName is Empty!");
+ throw new UDFException(USER_NAME_EMPTY.getErrorDesc());
}
verifyOperationUser(userName, udfId);
@@ -489,14 +490,14 @@ public class UDFRestfulApi {
try {
String userName = ModuleUserUtils.getOperationUser(req);
if (StringUtils.isEmpty(userName)) {
- throw new UDFException("UserName is Empty!");
+ throw new UDFException(USER_NAME_EMPTY.getErrorDesc());
}
if (!udfService.isUDFManager(userName)) {
- throw new UDFException("Only manager can share udf!");
+ throw new UDFException(ONLY_MANAGER_SHARE.getErrorDesc());
}
List<String> userList = mapper.treeToValue(json.get("sharedUsers"), List.class);
if (userList == null) {
- throw new UDFException("userList cat not be null!");
+ throw new UDFException(USERLIST_NOT_NULL.getErrorDesc());
}
Set<String> sharedUserSet = new HashSet<>(userList);
UDFInfo udfInfo = mapper.treeToValue(json.get("udfInfo"), UDFInfo.class);
@@ -543,7 +544,7 @@ public class UDFRestfulApi {
try {
String userName = ModuleUserUtils.getOperationUser(req);
if (StringUtils.isEmpty(userName)) {
- throw new UDFException("UserName is Empty!");
+ throw new UDFException(USER_NAME_EMPTY.getErrorDesc());
}
long udfId = json.get("udfId").longValue();
List<String> shareUsers = udfService.getAllSharedUsersByUdfId(userName, udfId);
@@ -586,19 +587,18 @@ public class UDFRestfulApi {
long udfId = json.get("udfId").longValue();
String handoverUser = json.get("handoverUser").textValue();
if (StringUtils.isEmpty(handoverUser)) {
- throw new UDFException("The handover user can't be null!");
+ throw new UDFException(HANDOVER_NOT_NULL.getErrorDesc());
}
String userName =
ModuleUserUtils.getOperationUser(
req, String.join(",", "hand over udf", "" + udfId, handoverUser));
if (StringUtils.isEmpty(userName)) {
- throw new UDFException("username is empty!");
+ throw new UDFException(USER_NAME_EMPTY.getErrorDesc());
}
UDFInfo udfInfo = verifyOperationUser(userName, udfId);
if (udfService.isUDFManager(udfInfo.getCreateUser())
&& !udfService.isUDFManager(handoverUser)) {
- throw new UDFException(
- "Admin users cannot hand over UDFs to regular users.(管理员用户不能移交UDF给普通用户!)");
+ throw new UDFException(ADMIN_NOT_HANDOVER_UDF.getErrorDesc());
}
udfService.handoverUdf(udfId, handoverUser);
message = Message.ok();
@@ -619,11 +619,10 @@ public class UDFRestfulApi {
private UDFInfo verifyOperationUser(String userName, long udfId) throws UDFException {
UDFInfo udfInfo = udfService.getUDFById(udfId, userName);
if (udfInfo == null) {
- throw new UDFException("can't find udf by this id!");
+ throw new UDFException(NOT_FIND_UDF.getErrorDesc());
}
if (!udfInfo.getCreateUser().equals(userName)) {
- throw new UDFException(
- "createUser must be consistent with the operation user(创建用户必须和操作用户一致)");
+ throw new UDFException(MUST_OPERATION_USER.getErrorDesc());
}
return udfInfo;
}
@@ -640,10 +639,10 @@ public class UDFRestfulApi {
try {
String userName = ModuleUserUtils.getOperationUser(req);
if (StringUtils.isEmpty(userName)) {
- throw new UDFException("username is empty!");
+ throw new UDFException(USER_NAME_EMPTY.getErrorDesc());
}
if (!udfService.isUDFManager(userName)) {
- throw new UDFException("only manager can publish udf!");
+ throw new UDFException(ONLY_MANAGER_PUBLISH.getErrorDesc());
}
long udfId = json.get("udfId").longValue();
String version = json.get("version").textValue();
@@ -679,7 +678,7 @@ public class UDFRestfulApi {
try {
String userName = ModuleUserUtils.getOperationUser(req);
if (StringUtils.isEmpty(userName)) {
- throw new UDFException("username is empty!");
+ throw new UDFException(USER_NAME_EMPTY.getErrorDesc());
}
long udfId = json.get("udfId").longValue();
String version = json.get("version").textValue();
@@ -703,7 +702,7 @@ public class UDFRestfulApi {
try {
String userName = ModuleUserUtils.getOperationUser(req);
if (StringUtils.isEmpty(userName)) {
- throw new UDFException("username is empty!");
+ throw new UDFException(USER_NAME_EMPTY.getErrorDesc());
}
List<UDFVersionVo> versionList = udfService.getUdfVersionList(udfId);
message = Message.ok();
@@ -752,7 +751,7 @@ public class UDFRestfulApi {
try {
String userName = ModuleUserUtils.getOperationUser(req);
if (StringUtils.isEmpty(userName)) {
- throw new UDFException("username is empty!");
+ throw new UDFException(USER_NAME_EMPTY.getErrorDesc());
}
String udfName = jsonNode.get("udfName") == null ? null : jsonNode.get("udfName").textValue();
String udfType = jsonNode.get("udfType").textValue();
@@ -801,7 +800,7 @@ public class UDFRestfulApi {
String version = json.get("version").textValue();
String userName = ModuleUserUtils.getOperationUser(req, "downloadUdf " + udfId);
if (StringUtils.isEmpty(userName)) {
- throw new UDFException("username is empty!");
+ throw new UDFException(USER_NAME_EMPTY.getErrorDesc());
}
String content = udfService.downLoadUDF(udfId, version, userName);
message = Message.ok();
@@ -843,7 +842,7 @@ public class UDFRestfulApi {
String version = json.get("version").textValue();
String userName = ModuleUserUtils.getOperationUser(req, "downloadUdf " + udfId);
if (StringUtils.isEmpty(userName)) {
- throw new UDFException("username is empty!");
+ throw new UDFException(USER_NAME_EMPTY.getErrorDesc());
}
DownloadVo downloadVo = udfService.downloadToLocal(udfId, version, userName);
is = downloadVo.getInputStream();
@@ -889,7 +888,7 @@ public class UDFRestfulApi {
try {
String userName = ModuleUserUtils.getOperationUser(req, "allUdfUsers ");
if (StringUtils.isEmpty(userName)) {
- throw new UDFException("username is empty!");
+ throw new UDFException(USER_NAME_EMPTY.getErrorDesc());
}
List<String> udfUsers = udfService.allUdfUsers();
message = Message.ok();
@@ -913,7 +912,7 @@ public class UDFRestfulApi {
try {
String userName = ModuleUserUtils.getOperationUser(req, "userDirectory ");
if (StringUtils.isEmpty(userName)) {
- throw new UDFException("username is empty!");
+ throw new UDFException(USER_NAME_EMPTY.getErrorDesc());
}
List<String> userDirectory = udfService.getUserDirectory(userName, category);
message = Message.ok();
diff --git a/linkis-public-enhancements/linkis-udf/linkis-udf-service/src/main/java/org/apache/linkis/udf/service/impl/UDFServiceImpl.java b/linkis-public-enhancements/linkis-udf/linkis-udf-service/src/main/java/org/apache/linkis/udf/service/impl/UDFServiceImpl.java
index 25cb38c6a..9d0f2c30a 100644
--- a/linkis-public-enhancements/linkis-udf/linkis-udf-service/src/main/java/org/apache/linkis/udf/service/impl/UDFServiceImpl.java
+++ b/linkis-public-enhancements/linkis-udf/linkis-udf-service/src/main/java/org/apache/linkis/udf/service/impl/UDFServiceImpl.java
@@ -63,6 +63,7 @@ import com.google.common.collect.Lists;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import static org.apache.linkis.udf.errorcode.UdfCommonErrorCodeSummary.*;
import static org.apache.linkis.udf.utils.ConstantVar.*;
@Service
@@ -118,11 +119,10 @@ public class UDFServiceImpl implements UDFService {
try {
commonLockService.lock(commonLock, LOCK_TIMEOUT);
if (validateDuplicateUDFName(udfVo.getUdfName(), userName)) {
- throw new UDFException(
- "The name of udf is the same name. Please rename it and rebuild it.(udf的名字重名,请改名后重建)");
+ throw new UDFException(UDF_SAME_NAME.getErrorDesc());
}
if (StringUtils.isEmpty(udfVo.getDirectory())) {
- throw new UDFException("分类名不能为空!");
+ throw new UDFException(CATEGORY_NOT_EMPTY.getErrorDesc());
}
// 支持hdfs path
FsPath fsPath = new FsPath(udfVo.getPath());
@@ -145,7 +145,7 @@ public class UDFServiceImpl implements UDFService {
response = uploadToBml(userName, fsPath.getPath(), is2);
logger.info("bml resourceId:" + response.resourceId());
} catch (IOException e) {
- throw new UDFException("文件读取异常:" + e.getMessage());
+ throw new UDFException(FILE_READ_EXCEPTION.getErrorDesc() + e.getMessage());
} finally {
IOUtils.closeQuietly(is2);
IOUtils.closeQuietly(is);
@@ -154,7 +154,7 @@ public class UDFServiceImpl implements UDFService {
}
}
if (!response.isSuccess()) {
- throw new UDFException("上传到bml失败,文件路径为:" + udfVo.getPath());
+ throw new UDFException(UPLOAD_BML_FAILED.getErrorDesc() + udfVo.getPath());
}
// 判断分类不存在则创建
String category =
@@ -223,7 +223,7 @@ public class UDFServiceImpl implements UDFService {
private void validateJarFileName(String jarPath, String userName) throws UDFException {
int cnt = udfVersionDao.getSameJarCount(userName, jarPath);
if (cnt > 0) {
- throw new UDFException("用户的udf已存在同名jar!");
+ throw new UDFException(JAR_SAME_NAME.getErrorDesc());
}
}
@@ -283,21 +283,20 @@ public class UDFServiceImpl implements UDFService {
public void updateUDF(UDFUpdateVo udfUpdateVo, String userName) throws Exception {
logger.info(userName + "start to update udfInfo, udfName:" + udfUpdateVo.getUdfName());
if (udfUpdateVo.getId() == null) {
- throw new UDFException("id Can not be empty(不能为空)");
+ throw new UDFException(ID_NOT_EMPTY.getErrorDesc());
}
UDFInfo oldUdfInfo = udfDao.getUDFById(udfUpdateVo.getId());
if (oldUdfInfo == null) {
- throw new UDFException("No old UDF found by this ID.");
+ throw new UDFException(OLD_UDF_FOUND.getErrorDesc());
}
if (!userName.equals(oldUdfInfo.getCreateUser())) {
- throw new UDFException(
- "Current user must be consistent with the modified user(当前用户必须和修改用户一致)");
+ throw new UDFException(CURRENT_MUST_MODIFIED.getErrorDesc());
}
if (!oldUdfInfo.getUdfType().equals(udfUpdateVo.getUdfType())) {
- throw new UDFException("UDF type modification is not allowed.");
+ throw new UDFException(UDF_MODIFICATION_NOT_ALLOWED.getErrorDesc());
}
if (!udfUpdateVo.getUdfName().equals(oldUdfInfo.getUdfName())) {
- throw new UDFException("The name of udf is not allowed modified.(udf的名字禁止修改!)");
+ throw new UDFException(NOT_ALLOWED_MODIFIED.getErrorDesc());
}
// 不考虑jar共享
if (udfUpdateVo.getUdfType() == UDF_JAR && StringUtils.isNotBlank(udfUpdateVo.getPath())) {
@@ -307,7 +306,7 @@ public class UDFServiceImpl implements UDFService {
udfUpdateVo.getPath().substring(udfUpdateVo.getPath().lastIndexOf("/") + 1),
udfUpdateVo.getId());
if (cnt > 0) {
- throw new UDFException("用户的udf已存在同名jar");
+ throw new UDFException(JAR_SAME_NAME.getErrorDesc());
}
}
oldUdfInfo.setUpdateTime(new Date());
@@ -320,7 +319,7 @@ public class UDFServiceImpl implements UDFService {
commonLockService.lock(persistenceLock, LOCK_TIMEOUT);
UDFVersion latestVersion = udfVersionDao.selectLatestByUdfId(udfUpdateVo.getId());
if (null == latestVersion) {
- throw new UDFException("can't found latestVersion for the udf");
+ throw new UDFException(NOT_FOUND_VERSION.getErrorDesc());
}
// 支持hdfs path
FsPath fsPath = new FsPath(udfUpdateVo.getPath());
@@ -344,9 +343,9 @@ public class UDFServiceImpl implements UDFService {
is2 = fileSystem.read(fsPath);
response = uploadToBml(userName, fsPath.getPath(), is2, latestVersion.getBmlResourceId());
} catch (IOException e) {
- throw new UDFException("文件读取异常:" + e.getMessage());
+ throw new UDFException(FILE_READ_EXCEPTION.getErrorDesc() + e.getMessage());
} catch (Exception e) {
- throw new UDFException("上传到bml异常!msg:" + e.getMessage());
+ throw new UDFException(UPLOAD_BML_FAILED_MSG.getErrorDesc() + e.getMessage());
} finally {
IOUtils.closeQuietly(is);
IOUtils.closeQuietly(is2);
@@ -355,7 +354,7 @@ public class UDFServiceImpl implements UDFService {
}
}
if (!response.isSuccess()) {
- throw new UDFException("上传到bml失败,文件路径为:" + udfUpdateVo.getPath());
+ throw new UDFException(UPLOAD_BML_FAILED.getErrorDesc() + udfUpdateVo.getPath());
}
UDFVersion newVersion = new UDFVersion();
newVersion.setUdfId(udfUpdateVo.getId());
@@ -406,7 +405,7 @@ public class UDFServiceImpl implements UDFService {
}
});
if (selfTree == null || selfTree.size() == 0) {
- throw new UDFException("该用户没有个人函数目录!");
+ throw new UDFException(NOT_FUNCTION_DIRECTORY.getErrorDesc());
}
List<UDFTree> selfTreeChildren =
udfTreeDao.getTreesByParentId(
@@ -447,7 +446,7 @@ public class UDFServiceImpl implements UDFService {
udfDao.getShareSameNameCountExcludeUser(
udfInfo.getUdfName(), handoverUser, udfInfo.getCreateUser());
if (count > 0 || sharedCount > 0) {
- throw new UDFException("The handoverUser has same name udf.(被移交用户包含重名udf)");
+ throw new UDFException(HANDOVER_SAME_NAME_UDF.getErrorDesc());
}
// 只考虑校验最新版本的jar是否同名,否则需要校验移交udf的所有版本的jar
if (udfInfo.getUdfType() == UDF_JAR && StringUtils.isNotBlank(latestVersion.getPath())) {
@@ -501,7 +500,7 @@ public class UDFServiceImpl implements UDFService {
bmlClient.copyResourceToAnotherUser(
latestVersion.getBmlResourceId(), handoverUser, oldUser);
if (!response.isSuccess()) {
- throw new UDFException("failed to copy resource to anotherUser:" + handoverUser);
+ throw new UDFException(FAILED_COPY_RESOURCE.getErrorDesc() + handoverUser);
}
udfVersionDao.updateResourceIdByUdfId(udfId, response.resourceId(), oldUser, handoverUser);
@@ -513,7 +512,7 @@ public class UDFServiceImpl implements UDFService {
logger.info("begin to publish udf, udfId: " + udfId);
UDFInfo udfInfo = udfDao.getUDFById(udfId);
if (!Boolean.TRUE.equals(udfInfo.getShared())) {
- throw new UDFException("非共享udf不支持发布操作!");
+ throw new UDFException(OPERATION_NOT_SUPPORTED.getErrorDesc());
}
udfVersionDao.updatePublishStatus(udfId, version, true);
logger.info("end to publish udf, udfId: " + udfId);
@@ -551,7 +550,7 @@ public class UDFServiceImpl implements UDFService {
bmlClient.rollbackVersion(
udfVersion.getBmlResourceId(), udfVersion.getBmlResourceVersion(), userName);
if (!response.isSuccess()) {
- throw new UDFException("bml rollback version 异常!");
+ throw new UDFException(ROLLBACK_VERSION_ABNORMAL.getErrorDesc());
}
UDFVersion newVersion =
new UDFVersion(
@@ -622,7 +621,7 @@ public class UDFServiceImpl implements UDFService {
logger.info("user " + user + " begin to downLoad udf, udfId: " + udfId);
UDFInfo udfInfo = udfDao.getUDFById(udfId);
if (udfInfo.getUdfType() == UDF_JAR) {
- throw new UDFException("jar类型的udf不支持下载查看内容");
+ throw new UDFException(JAR_NOT_DOWNLOADING.getErrorDesc());
}
UDFVersion udfVersion = udfVersionDao.selectByUdfIdAndVersion(udfId, version);
BmlDownloadResponse downloadResponse =
@@ -713,7 +712,7 @@ public class UDFServiceImpl implements UDFService {
if (Boolean.TRUE.equals(udfInfo.getShared())) {
long loadCount = udfDao.getUserLoadCountByUdfId(udfId, userName);
if (loadCount > 0) {
- throw new UDFException("该共享udf被用户加载,不能删除");
+ throw new UDFException(CANNOT_DELETED.getErrorDesc());
} else {
udfDao.deleteAllSharedUser(udfId);
}
@@ -755,9 +754,7 @@ public class UDFServiceImpl implements UDFService {
/*long sysCount = udfDao.getSameSysCount(udfInfo.getUdfName());*/
long loadCount = udfDao.getSameLoadCount(userName, udfInfo.getUdfName());
if (loadCount > 0) {
- throw new UDFException(
- "There is a Jar package function with the same name(存在同名的Jar包函数): "
- + udfInfo.getUdfName());
+ throw new UDFException(SAME_NAME_FUNCTION.getErrorDesc() + udfInfo.getUdfName());
}
// 校验jar包名字
// String path = udfInfo.getPath();
@@ -947,20 +944,20 @@ public class UDFServiceImpl implements UDFService {
public void checkSharedUsers(Set<String> sharedUsers, String userName, String udfName)
throws UDFException {
if (sharedUsers.contains(userName)) {
- throw new UDFException("Do not support sharing to yourself!(不支持分享给自己!)");
+ throw new UDFException(NOT_SHARING_YOURSELF.getErrorDesc());
}
// 校验共享用户是否包含同名udf
for (String shareduser : sharedUsers) {
if (StringUtils.isEmpty(shareduser)) {
- throw new UDFException("共享用户不能包含空用户名!");
+ throw new UDFException(SHARED_USERS_NOT_EMPTY.getErrorDesc());
}
if (!pattern.matcher(shareduser).matches()) {
- throw new UDFException("用户名只能包含字母数字下划线!");
+ throw new UDFException(CONTAIN_NUMERIC_SCORES.getErrorDesc());
}
long count = udfDao.getSameNameCountByUser(udfName, shareduser);
long sharedCount = udfDao.getShareSameNameCountExcludeUser(udfName, shareduser, userName);
if (count > 0 || sharedCount > 0) {
- throw new UDFException("用户:" + shareduser + "包含同名udf!");
+ throw new UDFException(CONTAINS_SAME_NAME.getErrorDesc() + shareduser);
}
}
// List<String> notExistUsers = Lists.newArrayList();
@@ -983,10 +980,7 @@ public class UDFServiceImpl implements UDFService {
udfDao.getShareSameNameCountByUser(
sharedUDFInfo.getUdfName(), sharedUDFInfo.getCreateUser());
if (count > 0) {
- throw new UDFException(
- "Shared udf name(分享的udf的名字)("
- + sharedUDFInfo.getUdfName()
- + ")Already exists, please edit the name and re-share(已存在,请修改名字后重新进行分享)");
+ throw new UDFException(ALREADY_EXISTS_SHARE.getErrorDesc());
}
udfDao.addUDF(sharedUDFInfo);
return sharedUDFInfo;
@@ -1015,7 +1009,7 @@ public class UDFServiceImpl implements UDFService {
return;
}
}
- throw new UDFException("只有被共享用户加载的udf可以设置过期");
+ throw new UDFException(SHARED_USER_EXPIRE.getErrorDesc());
}
@Override
diff --git a/linkis-public-enhancements/linkis-udf/linkis-udf-service/src/main/java/org/apache/linkis/udf/service/impl/UDFTreeServiceImpl.java b/linkis-public-enhancements/linkis-udf/linkis-udf-service/src/main/java/org/apache/linkis/udf/service/impl/UDFTreeServiceImpl.java
index 706c58cb4..37e2ffd93 100644
--- a/linkis-public-enhancements/linkis-udf/linkis-udf-service/src/main/java/org/apache/linkis/udf/service/impl/UDFTreeServiceImpl.java
+++ b/linkis-public-enhancements/linkis-udf/linkis-udf-service/src/main/java/org/apache/linkis/udf/service/impl/UDFTreeServiceImpl.java
@@ -37,6 +37,7 @@ import com.google.common.collect.Iterables;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import static org.apache.linkis.udf.errorcode.UdfCommonErrorCodeSummary.*;
import static org.apache.linkis.udf.utils.ConstantVar.*;
@Service
@@ -113,8 +114,7 @@ public class UDFTreeServiceImpl implements UDFTreeService {
return udfTree;
}
if (first.size() > 1) {
- throw new UDFException(
- "user(用户)" + userName + "There are two root directory directories(存在两个根目录目录)");
+ throw new UDFException(DIRECTORY_DIRECTORIES.getErrorDesc() + userName);
}
return first.get(0);
}
@@ -125,23 +125,21 @@ public class UDFTreeServiceImpl implements UDFTreeService {
try {
UDFTree parentTree = udfTreeDao.getTreeById(udfTree.getParent());
if (parentTree != null && !parentTree.getUserName().equals(userName)) {
- throw new UDFException(
- "user(用户) " + userName + ", the parent directory is not yours(父目录不是你的)");
+ throw new UDFException(DIRECTORY_PARENT.getErrorDesc() + userName);
}
logger.info(userName + " to add directory");
udfTreeDao.addTree(udfTree);
} catch (Throwable e) {
if (e instanceof DuplicateKeyException) {
- throw new UDFException("Duplicate file name(文件名重复)");
+ throw new UDFException(DUPLICATE_FILE_NAME.getErrorDesc());
} else {
throw new UDFException(e.getMessage());
}
}
} else {
- throw new UDFException(
- "Current user must be consistent with the user created(当前用户必须和创建用户一致)");
+ throw new UDFException(CURRENT_MUST_MODIFIED_CREATED.getErrorDesc());
}
return udfTree;
}
@@ -150,21 +148,20 @@ public class UDFTreeServiceImpl implements UDFTreeService {
public UDFTree updateTree(UDFTree udfTree, String userName) throws UDFException {
if (userName.equals(udfTree.getUserName())) {
if (udfTree.getId() == null) {
- throw new UDFException("id Can not be empty(不能为空)");
+ throw new UDFException(ID_NOT_EMPTY.getErrorDesc());
}
try {
logger.info(userName + " to update directory");
udfTreeDao.updateTree(udfTree);
} catch (Throwable e) {
if (e instanceof DuplicateKeyException) {
- throw new UDFException("Duplicate file name(文件名重复)");
+ throw new UDFException(DUPLICATE_FILE_NAME.getErrorDesc());
} else {
throw new UDFException(e.getMessage());
}
}
} else {
- throw new UDFException(
- "Current user must be consistent with the modified user(当前用户必须和修改用户一致)");
+ throw new UDFException(CURRENT_MUST_MODIFIED.getErrorDesc());
}
return udfTree;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@linkis.apache.org
For additional commands, e-mail: commits-help@linkis.apache.org