From fb68147c25480d8ae75c1ea8de4edfd24ef79e6f Mon Sep 17 00:00:00 2001 From: hstdream <33045461+hstdream@users.noreply.github.com> Date: Wed, 18 May 2022 01:36:40 +0800 Subject: [PATCH] [Fix-10080]When the created tenant name is too long, an error message will be prompted (#10081) * [Fix-10080]When the created tenant name is too long, an error message will be prompted * [Fix-10080]When the created tenant name is too long, an error message will be prompted * [Fix-10080]When the created tenant name is too long, an error message will be prompted Co-authored-by: houshitao (cherry picked from commit 67cf7b280087d4424bf0c2a698c9c12ab874bd2e) --- .../java/org/apache/dolphinscheduler/api/enums/Status.java | 3 ++- .../api/service/impl/TenantServiceImpl.java | 7 +++++++ .../java/org/apache/dolphinscheduler/common/Constants.java | 5 +++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/enums/Status.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/enums/Status.java index 3d88b1b79c..0dd6cbf36d 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/enums/Status.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/enums/Status.java @@ -350,7 +350,8 @@ public enum Status { UPDATE_ENVIRONMENT_WORKER_GROUP_RELATION_ERROR(1200013,"You can't modify the worker group, because the worker group [{0}] and this environment [{1}] already be used in the task [{2}]", "您不能修改工作组选项,因为该工作组 [{0}] 和 该环境 [{1}] 已经被用在任务 [{2}] 中"), NOT_ALLOW_TO_DISABLE_OWN_ACCOUNT(130020, "Not allow to disable your own account", "不能停用自己的账号"), - VERIFY_PARAMETER_NAME_FAILED(1300009, "The file name verify failed", "文件命名校验失败"); + VERIFY_PARAMETER_NAME_FAILED(1300009, "The file name verify failed", "文件命名校验失败"), + TENANT_FULL_NAME_TOO_LONG_ERROR(1300016, "tenant's fullname is too long error", "租户名过长"); private final int code; diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TenantServiceImpl.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TenantServiceImpl.java index 0601725797..86845ad8d9 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TenantServiceImpl.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TenantServiceImpl.java @@ -17,6 +17,8 @@ package org.apache.dolphinscheduler.api.service.impl; +import static org.apache.dolphinscheduler.common.Constants.TENANT_FULL_NAME_MAX_LENGTH; + import org.apache.dolphinscheduler.api.enums.Status; import org.apache.dolphinscheduler.api.service.TenantService; import org.apache.dolphinscheduler.api.utils.PageInfo; @@ -90,6 +92,11 @@ public class TenantServiceImpl extends BaseServiceImpl implements TenantService return result; } + if(StringUtils.length(tenantCode) > TENANT_FULL_NAME_MAX_LENGTH){ + putMsg(result, Status.TENANT_FULL_NAME_TOO_LONG_ERROR); + return result; + } + if (!RegexUtils.isValidLinuxUserName(tenantCode)) { putMsg(result, Status.CHECK_OS_TENANT_CODE_ERROR); return result; diff --git a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/Constants.java b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/Constants.java index eb2f46b796..1f6558a0db 100644 --- a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/Constants.java +++ b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/Constants.java @@ -1092,4 +1092,9 @@ public final class Constants { public static final int DRY_RUN_FLAG_YES = 1; public static final String CACHE_KEY_VALUE_ALL = "'all'"; + + /** + * tenant + */ + public static final int TENANT_FULL_NAME_MAX_LENGTH = 30; }