This is an automated email from the ASF dual-hosted git repository. xxyu pushed a commit to branch kylin5 in repository https://gitbox.apache.org/repos/asf/kylin.git
commit 3a876267f0264334bfbb7f075695345017a8e503 Author: huangsheng <huangshen...@163.com> AuthorDate: Thu May 18 14:59:37 2023 +0800 [DIRTY] model names that exceed 127 characters --- .../java/org/apache/kylin/common/constant/Constant.java | 2 ++ .../kylin/common/exception/code/ErrorCodeServer.java | 1 + .../main/resources/kylin_error_msg_conf_cn.properties | 1 + .../main/resources/kylin_error_msg_conf_en.properties | 1 + .../resources/kylin_error_suggestion_conf_cn.properties | 1 + .../resources/kylin_error_suggestion_conf_en.properties | 1 + .../src/main/resources/kylin_errorcode_conf.properties | 1 + .../kylin/rest/controller/NMetaStoreController.java | 7 +++++++ .../apache/kylin/rest/controller/NModelController.java | 5 +++++ .../kylin/rest/controller/NModelControllerTest.java | 16 ++++++++++++++++ .../java/org/apache/kylin/rest/service/ModelService.java | 11 +++++++++++ .../org/apache/kylin/rest/service/ModelServiceTest.java | 10 ++++++++++ 12 files changed, 57 insertions(+) diff --git a/src/core-common/src/main/java/org/apache/kylin/common/constant/Constant.java b/src/core-common/src/main/java/org/apache/kylin/common/constant/Constant.java index 8c87f83c15..dbaa1262a2 100644 --- a/src/core-common/src/main/java/org/apache/kylin/common/constant/Constant.java +++ b/src/core-common/src/main/java/org/apache/kylin/common/constant/Constant.java @@ -27,4 +27,6 @@ public class Constant { public static final long MINUTE = 60 * SECOND; public static final int AUDIT_MAX_BUFFER_SIZE = 10 * 1024 * 1024; + + public static final int MODEL_ALIAS_LEN_LIMIT = 127; } diff --git a/src/core-common/src/main/java/org/apache/kylin/common/exception/code/ErrorCodeServer.java b/src/core-common/src/main/java/org/apache/kylin/common/exception/code/ErrorCodeServer.java index 9f62f94734..26f558be38 100644 --- a/src/core-common/src/main/java/org/apache/kylin/common/exception/code/ErrorCodeServer.java +++ b/src/core-common/src/main/java/org/apache/kylin/common/exception/code/ErrorCodeServer.java @@ -36,6 +36,7 @@ public enum ErrorCodeServer implements ErrorCodeProducer { MODEL_TDS_EXPORT_COLUMN_AND_MEASURE_NAME_CONFLICT("KE-010002302"), MODEL_SUM_LC_INVALID_DATA_TYPE("KE-010002303"), MODEL_SUM_LC_INVALID_TIMESTAMP_TYPE("KE-010002304"), + MODEL_NAME_TOO_LONG("KE-010002305"), // 100252XX Cube CUBE_NOT_EXIST("KE-010025201"), diff --git a/src/core-common/src/main/resources/kylin_error_msg_conf_cn.properties b/src/core-common/src/main/resources/kylin_error_msg_conf_cn.properties index 4af7f8862c..ffb3f55714 100644 --- a/src/core-common/src/main/resources/kylin_error_msg_conf_cn.properties +++ b/src/core-common/src/main/resources/kylin_error_msg_conf_cn.properties @@ -36,6 +36,7 @@ KE-010002301=维度的列名 %s 与度量名 %s 重复,无法导出 TDS。请 KE-010002302=模型中的列名 %s 与度量名 %s 重复,无法导出 TDS。请去除重名后再重试。 KE-010002303=SUM_LC度量的返回类型 '%s' 不合法。返回类型必须是这其中的一个:%s。 KE-010002304=SUM_LC度量的时间类型 '%s' 不合法。 +KE-010002305=模型名称最长 127 字符,请修改后重试。 ## 100252XX Cube KE-010025201=无法找到相关 Cube。 diff --git a/src/core-common/src/main/resources/kylin_error_msg_conf_en.properties b/src/core-common/src/main/resources/kylin_error_msg_conf_en.properties index c4a10ecbf1..b2bcbac2bd 100644 --- a/src/core-common/src/main/resources/kylin_error_msg_conf_en.properties +++ b/src/core-common/src/main/resources/kylin_error_msg_conf_en.properties @@ -36,6 +36,7 @@ KE-010002301=There are duplicated names among dimension column %s and measure na KE-010002302=There are duplicated names among model column %s and measure name %s. Cannot export a valid TDS file. Please correct the duplicated names and try again. KE-010002303=SUM_LC Measure's return type '%s' is illegal. It must be one of %s. KE-010002304=SUM_LC Measure's time column type '%s' is illegal. +KE-010002305=The maximum length of the model name is 127 characters, please modify and try again. ## 100252XX Cube KE-010025201=Can't find the cube. diff --git a/src/core-common/src/main/resources/kylin_error_suggestion_conf_cn.properties b/src/core-common/src/main/resources/kylin_error_suggestion_conf_cn.properties index 758fd6b11a..946726bdbd 100644 --- a/src/core-common/src/main/resources/kylin_error_suggestion_conf_cn.properties +++ b/src/core-common/src/main/resources/kylin_error_suggestion_conf_cn.properties @@ -34,6 +34,7 @@ KE-010002207= KE-010002208= KE-010002303= KE-010002304= +KE-010002305= ## 100252XX Cube KE-010025201= diff --git a/src/core-common/src/main/resources/kylin_error_suggestion_conf_en.properties b/src/core-common/src/main/resources/kylin_error_suggestion_conf_en.properties index 0b45ebf647..b34c268e50 100644 --- a/src/core-common/src/main/resources/kylin_error_suggestion_conf_en.properties +++ b/src/core-common/src/main/resources/kylin_error_suggestion_conf_en.properties @@ -34,6 +34,7 @@ KE-010002207= KE-010002208= KE-010002303= KE-010002304= +KE-010002305= ## 100252XX Cube KE-010025201= diff --git a/src/core-common/src/main/resources/kylin_errorcode_conf.properties b/src/core-common/src/main/resources/kylin_errorcode_conf.properties index 21699ac510..b274ff6399 100644 --- a/src/core-common/src/main/resources/kylin_errorcode_conf.properties +++ b/src/core-common/src/main/resources/kylin_errorcode_conf.properties @@ -37,6 +37,7 @@ KE-010002301 KE-010002302 KE-010002303 KE-010002304 +KE-010002305 ## 100252XX Cube KE-010025201 diff --git a/src/metadata-server/src/main/java/org/apache/kylin/rest/controller/NMetaStoreController.java b/src/metadata-server/src/main/java/org/apache/kylin/rest/controller/NMetaStoreController.java index a8958219fa..660c70aa36 100644 --- a/src/metadata-server/src/main/java/org/apache/kylin/rest/controller/NMetaStoreController.java +++ b/src/metadata-server/src/main/java/org/apache/kylin/rest/controller/NMetaStoreController.java @@ -22,6 +22,7 @@ import static org.apache.kylin.common.constant.HttpConstant.HTTP_VND_APACHE_KYLI import static org.apache.kylin.common.exception.ServerErrorCode.EMPTY_MODEL_ID; import static org.apache.kylin.common.exception.ServerErrorCode.FILE_FORMAT_ERROR; import static org.apache.kylin.common.exception.ServerErrorCode.FILE_NOT_EXIST; +import static org.apache.kylin.common.exception.code.ErrorCodeServer.MODEL_NAME_TOO_LONG; import static org.apache.kylin.rest.request.ModelImportRequest.ImportType.NEW; import static org.apache.kylin.rest.request.ModelImportRequest.ImportType.OVERWRITE; import static org.springframework.http.MediaType.MULTIPART_FORM_DATA_VALUE; @@ -39,6 +40,7 @@ import javax.servlet.http.HttpServletResponse; import javax.xml.bind.DatatypeConverter; import org.apache.commons.collections.CollectionUtils; +import org.apache.kylin.common.constant.Constant; import org.apache.kylin.common.exception.KylinException; import org.apache.kylin.common.persistence.transaction.UnitOfWork; import org.apache.kylin.common.util.ZipFileUtils; @@ -142,6 +144,11 @@ public class NMetaStoreController extends NBasicController { if (request.getModels().stream().noneMatch(modelImport -> IMPORT_TYPE.contains(modelImport.getImportType()))) { throw new KylinException(EMPTY_MODEL_ID, "At least one model should be selected to import!"); } + if (request.getModels().stream().filter(modelImport -> modelImport.getImportType().equals(NEW)) + .anyMatch(modelImport -> modelImport.getTargetName().length() > Constant.MODEL_ALIAS_LEN_LIMIT)) { + throw new KylinException(MODEL_NAME_TOO_LONG); + } + metaStoreService.importModelMetadata(project, metadataFile, request); return new EnvelopeResponse<>(KylinException.CODE_SUCCESS, "", ""); } diff --git a/src/metadata-server/src/main/java/org/apache/kylin/rest/controller/NModelController.java b/src/metadata-server/src/main/java/org/apache/kylin/rest/controller/NModelController.java index 70ecf24943..ac99e38d29 100644 --- a/src/metadata-server/src/main/java/org/apache/kylin/rest/controller/NModelController.java +++ b/src/metadata-server/src/main/java/org/apache/kylin/rest/controller/NModelController.java @@ -23,6 +23,7 @@ import static org.apache.kylin.common.constant.HttpConstant.HTTP_VND_APACHE_KYLI import static org.apache.kylin.common.exception.ServerErrorCode.FAILED_CREATE_MODEL; import static org.apache.kylin.common.exception.ServerErrorCode.FAILED_UPDATE_MODEL; import static org.apache.kylin.common.exception.code.ErrorCodeServer.MODEL_NAME_INVALID; +import static org.apache.kylin.common.exception.code.ErrorCodeServer.MODEL_NAME_TOO_LONG; import java.io.IOException; import java.text.SimpleDateFormat; @@ -36,6 +37,7 @@ import javax.servlet.http.HttpServletResponse; import org.apache.commons.lang.exception.ExceptionUtils; import org.apache.commons.lang3.StringUtils; +import org.apache.kylin.common.constant.Constant; import org.apache.kylin.common.exception.KylinException; import org.apache.kylin.metadata.model.NDataModel; import org.apache.kylin.metadata.model.PartitionDesc; @@ -492,6 +494,9 @@ public class NModelController extends NBasicController { if (!StringUtils.containsOnly(newAlias, AbstractModelService.VALID_NAME_FOR_MODEL)) { throw new KylinException(MODEL_NAME_INVALID, newAlias); } + if (newAlias.length() > Constant.MODEL_ALIAS_LEN_LIMIT) { + throw new KylinException(MODEL_NAME_TOO_LONG); + } fusionModelService.renameDataModel(modelRenameRequest.getProject(), modelId, newAlias, description); return new EnvelopeResponse<>(KylinException.CODE_SUCCESS, "", ""); diff --git a/src/metadata-server/src/test/java/org/apache/kylin/rest/controller/NModelControllerTest.java b/src/metadata-server/src/test/java/org/apache/kylin/rest/controller/NModelControllerTest.java index 64edf9a64f..79ba76abd7 100644 --- a/src/metadata-server/src/test/java/org/apache/kylin/rest/controller/NModelControllerTest.java +++ b/src/metadata-server/src/test/java/org/apache/kylin/rest/controller/NModelControllerTest.java @@ -299,6 +299,22 @@ public class NModelControllerTest extends NLocalFileMetadataTestCase { Mockito.any(ModelUpdateRequest.class)); } + + @Test + public void testRenameModelWithVeryLongNewName() throws Exception { + ModelUpdateRequest modelUpdateRequest = mockModelUpdateRequest(); + modelUpdateRequest.setNewModelName("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"); + Mockito.doNothing().when(modelService).renameDataModel("default", "89af4ee2-2cdb-4b07-b39e-4c29856309aa", + "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz", ""); + mockMvc.perform(MockMvcRequestBuilders.put("/api/models/{model}/name", "89af4ee2-2cdb-4b07-b39e-4c29856309aa") + .contentType(MediaType.APPLICATION_JSON).content(JsonUtil.writeValueAsString(modelUpdateRequest)) + .accept(MediaType.parseMediaType(HTTP_VND_APACHE_KYLIN_JSON))) + .andExpect(MockMvcResultMatchers.status().isInternalServerError()); + Mockito.verify(nModelController).updateModelName(eq("89af4ee2-2cdb-4b07-b39e-4c29856309aa"), + Mockito.any(ModelUpdateRequest.class)); + } + + @Test public void testUpdateModelStatus() throws Exception { ModelUpdateRequest modelUpdateRequest = mockModelUpdateRequest(); diff --git a/src/modeling-service/src/main/java/org/apache/kylin/rest/service/ModelService.java b/src/modeling-service/src/main/java/org/apache/kylin/rest/service/ModelService.java index c0fbe9c02f..9f46c116be 100644 --- a/src/modeling-service/src/main/java/org/apache/kylin/rest/service/ModelService.java +++ b/src/modeling-service/src/main/java/org/apache/kylin/rest/service/ModelService.java @@ -55,6 +55,7 @@ import static org.apache.kylin.common.exception.code.ErrorCodeServer.DATETIME_FO import static org.apache.kylin.common.exception.code.ErrorCodeServer.MODEL_ID_NOT_EXIST; import static org.apache.kylin.common.exception.code.ErrorCodeServer.MODEL_NAME_DUPLICATE; import static org.apache.kylin.common.exception.code.ErrorCodeServer.MODEL_NAME_NOT_EXIST; +import static org.apache.kylin.common.exception.code.ErrorCodeServer.MODEL_NAME_TOO_LONG; import static org.apache.kylin.common.exception.code.ErrorCodeServer.PARAMETER_INVALID_SUPPORT_LIST; import static org.apache.kylin.common.exception.code.ErrorCodeServer.PROJECT_NOT_EXIST; import static org.apache.kylin.common.exception.code.ErrorCodeServer.SEGMENT_LOCKED; @@ -108,6 +109,7 @@ import org.apache.commons.lang3.StringUtils; import org.apache.kylin.common.KapConfig; import org.apache.kylin.common.KylinConfig; import org.apache.kylin.common.QueryContext; +import org.apache.kylin.common.constant.Constant; import org.apache.kylin.common.event.ModelAddEvent; import org.apache.kylin.common.event.ModelDropEvent; import org.apache.kylin.common.exception.JobErrorCode; @@ -1340,6 +1342,12 @@ public class ModelService extends AbstractModelService implements TableModelSupp return relatedModel; } + private void checkAliasIsExceededLimit(String newAlias) { + if (newAlias.length() > Constant.MODEL_ALIAS_LEN_LIMIT) { + throw new KylinException(MODEL_NAME_TOO_LONG); + } + } + private void checkAliasExist(String modelId, String newAlias, String project) { if (!checkModelAliasUniqueness(modelId, newAlias, project)) { throw new KylinException(MODEL_NAME_DUPLICATE, newAlias); @@ -1426,6 +1434,7 @@ public class ModelService extends AbstractModelService implements TableModelSupp public void cloneModel(String modelId, String newModelName, String project) { aclEvaluate.checkProjectWritePermission(project); checkAliasExist("", newModelName, project); + checkAliasIsExceededLimit(newModelName); EnhancedUnitOfWork.doInTransactionWithCheckAndRetry(() -> { NDataModelManager dataModelManager = getManager(NDataModelManager.class, project); NDataModel dataModelDesc = getModelById(modelId, project); @@ -1473,6 +1482,7 @@ public class ModelService extends AbstractModelService implements TableModelSupp nDataModel.setDescription(description); } else { checkAliasExist(modelId, newAlias, project); + checkAliasIsExceededLimit(newAlias); nDataModel.setAlias(newAlias); if (StringUtils.isNotBlank(description)) { nDataModel.setDescription(description); @@ -2016,6 +2026,7 @@ public class ModelService extends AbstractModelService implements TableModelSupp private NDataModel doCheckBeforeModelSave(String project, ModelRequest modelRequest) { checkAliasExist(modelRequest.getUuid(), modelRequest.getAlias(), project); + checkAliasIsExceededLimit(modelRequest.getAlias()); modelRequest.setOwner(AclPermissionUtil.getCurrentUsername()); modelRequest.setLastModified(modelRequest.getCreateTime()); checkModelRequest(modelRequest); diff --git a/src/modeling-service/src/test/java/org/apache/kylin/rest/service/ModelServiceTest.java b/src/modeling-service/src/test/java/org/apache/kylin/rest/service/ModelServiceTest.java index 0f6eaba520..9b039b040a 100644 --- a/src/modeling-service/src/test/java/org/apache/kylin/rest/service/ModelServiceTest.java +++ b/src/modeling-service/src/test/java/org/apache/kylin/rest/service/ModelServiceTest.java @@ -32,6 +32,7 @@ import static org.apache.kylin.common.exception.code.ErrorCodeServer.MODEL_ID_NO import static org.apache.kylin.common.exception.code.ErrorCodeServer.MODEL_NAME_DUPLICATE; import static org.apache.kylin.common.exception.code.ErrorCodeServer.MODEL_NAME_EMPTY; import static org.apache.kylin.common.exception.code.ErrorCodeServer.MODEL_NAME_INVALID; +import static org.apache.kylin.common.exception.code.ErrorCodeServer.MODEL_NAME_TOO_LONG; import static org.apache.kylin.common.exception.code.ErrorCodeServer.MODEL_NOT_EXIST; import static org.apache.kylin.common.exception.code.ErrorCodeServer.PARAMETER_INVALID_SUPPORT_LIST; import static org.apache.kylin.common.exception.code.ErrorCodeServer.SEGMENT_LOCKED; @@ -1299,6 +1300,15 @@ public class ModelServiceTest extends SourceTestCase { modelService.cloneModel("89af4ee2-2cdb-4b07-b39e-4c29856309aa", nmodel_basic_inner, "default"); } + @Test + public void testCloneModelNameTooLongException() { + thrown.expect(KylinException.class); + String longModelName = "Long_Long_Long_Long_Long_Long_Long_Long_Long_Long_Long_Long_Long" + + "_Long_Long_Long_Long_Long_Long_Long_Long_Long_Long_Long_Long_Long_Long_Long_Long"; + thrown.expectMessage(MODEL_NAME_TOO_LONG.getMsg()); + modelService.cloneModel("89af4ee2-2cdb-4b07-b39e-4c29856309aa", longModelName, "default"); + } + @Test public void testCloneModelExceptionName() { thrown.expectInTransaction(KylinException.class);