From 59d430b3f864e4ee1f9ed6510d8e1c1d00a53ad9 Mon Sep 17 00:00:00 2001 From: peacewong Date: Tue, 24 Oct 2023 20:48:06 +0800 Subject: [PATCH] [Feature]New configuration management function added to the management console #4842 [Feature]New user configuration function added to the management console #4841 --- .../configuration/dao/ConfigMapper.java | 4 +- .../configuration/dao/UserTenantMapper.java | 40 --- .../linkis/configuration/entity/TenantVo.java | 143 --------- .../linkis/configuration/entity/UserIpVo.java | 143 --------- .../LinkisConfigurationErrorCodeSummary.java | 69 ----- .../exception/ConfigurationException.java | 8 +- .../restful/api/ConfigurationRestfulApi.java | 240 +++++++++------ .../api/TenantConfigrationRestfulApi.java | 270 ----------------- .../api/UserIpConfigrationRestfulApi.java | 230 --------------- .../service/TenantConfigService.java | 39 --- .../service/UserIpConfigService.java | 39 --- .../service/impl/ConfigKeyServiceImpl.java | 24 +- .../service/impl/TenantConfigServiceImpl.java | 188 ------------ .../service/impl/TenantServiceImpl.java | 54 ---- .../service/impl/UserIpConfigServiceImpl.java | 154 ---------- .../service/impl/UserIpServiceImpl.java | 53 ---- .../util/ConfigurationConfiguration.java | 6 - .../linkis/configuration/util/HttpsUtil.java | 114 ------- .../configuration/util/LabelEntityParser.java | 6 +- .../resources/mapper/common/LabelMapper.xml | 23 +- .../mapper/mysql/AcrossClusterRuleMapper.xml | 130 ++++++++ .../mysql/ConfigKeyLimitForUserMapper.xml | 145 +++++++++ .../resources/mapper/mysql/ConfigMapper.xml | 243 ++++++++++++++- .../mapper/mysql/TemplateConfigKeyMapper.xml | 161 ++++++++++ .../postgresql/AcrossClusterRuleMapper.xml | 130 ++++++++ .../ConfigKeyLimitForUserMapper.xml | 145 +++++++++ .../mapper/postgresql/ConfigMapper.xml | 278 ++++++++++++++++-- .../postgresql/TemplateConfigKeyMapper.xml | 161 ++++++++++ .../configuration/conf/Configuration.scala | 5 - .../configuration/constant/Constants.scala | 49 --- .../service/CategoryService.scala | 25 +- .../service/ConfigurationService.scala | 41 +-- .../util/LabelParameterParser.scala | 13 +- .../validate/FloatValidator.scala | 3 +- .../validate/NumericalValidator.scala | 3 +- .../configuration/dao/ConfigMapperTest.java | 26 +- .../configuration/dao/LabelMapperTest.java | 32 +- .../configuration/dao/UserIpMapperTest.java | 91 ------ .../dao/UserTenantMapperTest.java | 84 ------ .../exception/ConfigurationExceptionTest.java | 17 -- 40 files changed, 1575 insertions(+), 2054 deletions(-) delete mode 100644 linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/dao/UserTenantMapper.java delete mode 100644 linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/entity/TenantVo.java delete mode 100644 linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/entity/UserIpVo.java delete mode 100644 linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/errorcode/LinkisConfigurationErrorCodeSummary.java delete mode 100644 linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/restful/api/TenantConfigrationRestfulApi.java delete mode 100644 linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/restful/api/UserIpConfigrationRestfulApi.java delete mode 100644 linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/service/TenantConfigService.java delete mode 100644 linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/service/UserIpConfigService.java delete mode 100644 linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/service/impl/TenantConfigServiceImpl.java delete mode 100644 linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/service/impl/TenantServiceImpl.java delete mode 100644 linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/service/impl/UserIpConfigServiceImpl.java delete mode 100644 linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/service/impl/UserIpServiceImpl.java delete mode 100644 linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/util/HttpsUtil.java create mode 100644 linkis-public-enhancements/linkis-configuration/src/main/resources/mapper/mysql/AcrossClusterRuleMapper.xml create mode 100644 linkis-public-enhancements/linkis-configuration/src/main/resources/mapper/mysql/ConfigKeyLimitForUserMapper.xml create mode 100644 linkis-public-enhancements/linkis-configuration/src/main/resources/mapper/mysql/TemplateConfigKeyMapper.xml create mode 100644 linkis-public-enhancements/linkis-configuration/src/main/resources/mapper/postgresql/AcrossClusterRuleMapper.xml create mode 100644 linkis-public-enhancements/linkis-configuration/src/main/resources/mapper/postgresql/ConfigKeyLimitForUserMapper.xml create mode 100644 linkis-public-enhancements/linkis-configuration/src/main/resources/mapper/postgresql/TemplateConfigKeyMapper.xml delete mode 100644 linkis-public-enhancements/linkis-configuration/src/main/scala/org/apache/linkis/configuration/constant/Constants.scala delete mode 100644 linkis-public-enhancements/linkis-configuration/src/test/java/org/apache/linkis/configuration/dao/UserIpMapperTest.java delete mode 100644 linkis-public-enhancements/linkis-configuration/src/test/java/org/apache/linkis/configuration/dao/UserTenantMapperTest.java diff --git a/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/dao/ConfigMapper.java b/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/dao/ConfigMapper.java index 6b6b15a65c..54e694ee4e 100644 --- a/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/dao/ConfigMapper.java +++ b/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/dao/ConfigMapper.java @@ -55,7 +55,7 @@ List getConfigByEngineUserCreator( ConfigKey selectKeyByKeyID(@Param("id") Long keyID); - List selectKeyByKeyName(@Param("keyName") String keyName); + List seleteKeyByKeyName(@Param("keyName") String keyName); List listKeyByStringValue(@Param("stringValue") String stringValue); @@ -72,6 +72,4 @@ List getConfigByEngineUserCreator( void updateCategory(CategoryLabel categoryLabel); void insertKey(ConfigKey key); - - List getConfigEnKeyValueByLabelId(@Param("labelId") Integer labelId); } diff --git a/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/dao/UserTenantMapper.java b/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/dao/UserTenantMapper.java deleted file mode 100644 index c141738ced..0000000000 --- a/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/dao/UserTenantMapper.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * 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.dao; - -import org.apache.linkis.configuration.entity.TenantVo; - -import org.apache.ibatis.annotations.Param; - -import java.util.List; - -public interface UserTenantMapper { - - List queryTenantList( - @Param("user") String user, - @Param("creator") String creator, - @Param("tenant_value") String tenant); - - void deleteTenant(@Param("id") Integer id); - - void updateTenant(TenantVo tenantVo); - - void createTenant(TenantVo tenantVo); - - TenantVo queryTenant(@Param("user") String user, @Param("creator") String creator); -} diff --git a/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/entity/TenantVo.java b/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/entity/TenantVo.java deleted file mode 100644 index c2399ff9b6..0000000000 --- a/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/entity/TenantVo.java +++ /dev/null @@ -1,143 +0,0 @@ -/* - * 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.entity; - -import java.util.Date; - -import io.swagger.annotations.ApiModel; -import io.swagger.annotations.ApiModelProperty; - -@ApiModel -public class TenantVo { - - @ApiModelProperty("id") - private String id; - - @ApiModelProperty("user") - private String user; - - @ApiModelProperty("creator") - private String creator; - - @ApiModelProperty("tenantValue") - private String tenantValue; - - @ApiModelProperty("createTime") - private Date createTime; - - @ApiModelProperty("updateTime") - private Date updateTime; - - @ApiModelProperty("desc") - private String desc; - - @ApiModelProperty("bussinessUser") - private String bussinessUser; - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getUser() { - return user; - } - - public void setUser(String user) { - this.user = user; - } - - public String getCreator() { - return creator; - } - - public void setCreator(String creator) { - this.creator = creator; - } - - public String getTenantValue() { - return tenantValue; - } - - public void setTenantValue(String tenantValue) { - this.tenantValue = tenantValue; - } - - public Date getCreateTime() { - return createTime; - } - - public void setCreateTime(Date createTime) { - this.createTime = createTime; - } - - public Date getUpdateTime() { - return updateTime; - } - - public void setUpdateTime(Date updateTime) { - this.updateTime = updateTime; - } - - public String getDesc() { - return desc; - } - - public void setDesc(String desc) { - this.desc = desc; - } - - public String getBussinessUser() { - return bussinessUser; - } - - public void setBussinessUser(String bussinessUser) { - this.bussinessUser = bussinessUser; - } - - @Override - public String toString() { - return "TenantVo{" - + "id='" - + id - + '\'' - + ", user='" - + user - + '\'' - + ", creator='" - + creator - + '\'' - + ", tenantValue='" - + tenantValue - + '\'' - + ", createTime=" - + createTime - + ", updateTime=" - + updateTime - + ", desc='" - + desc - + '\'' - + ", bussinessUser='" - + bussinessUser - + '\'' - + '}'; - } -} diff --git a/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/entity/UserIpVo.java b/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/entity/UserIpVo.java deleted file mode 100644 index 05ec8046fd..0000000000 --- a/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/entity/UserIpVo.java +++ /dev/null @@ -1,143 +0,0 @@ -/* - * 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.entity; - -import java.util.Date; - -import io.swagger.annotations.ApiModel; -import io.swagger.annotations.ApiModelProperty; - -@ApiModel -public class UserIpVo { - - @ApiModelProperty("id") - private String id; - - @ApiModelProperty("user") - private String user; - - @ApiModelProperty("creator") - private String creator; - - @ApiModelProperty("ipList") - private String ipList; - - @ApiModelProperty("createTime") - private Date createTime; - - @ApiModelProperty("updateTime") - private Date updateTime; - - @ApiModelProperty("desc") - private String desc; - - @ApiModelProperty("bussinessUser") - private String bussinessUser; - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getUser() { - return user; - } - - public void setUser(String user) { - this.user = user; - } - - public String getCreator() { - return creator; - } - - public void setCreator(String creator) { - this.creator = creator; - } - - public String getDesc() { - return desc; - } - - public void setDesc(String desc) { - this.desc = desc; - } - - public String getBussinessUser() { - return bussinessUser; - } - - public void setBussinessUser(String bussinessUser) { - this.bussinessUser = bussinessUser; - } - - public Date getCreateTime() { - return createTime; - } - - public void setCreateTime(Date createTime) { - this.createTime = createTime; - } - - public Date getUpdateTime() { - return updateTime; - } - - public void setUpdateTime(Date updateTime) { - this.updateTime = updateTime; - } - - public String getIpList() { - return ipList; - } - - public void setIpList(String ips) { - this.ipList = ips; - } - - @Override - public String toString() { - return "UserIpVo{" - + "id='" - + id - + '\'' - + ", user='" - + user - + '\'' - + ", creator='" - + creator - + '\'' - + ", ipList='" - + ipList - + '\'' - + ", createTime=" - + createTime - + ", updateTime=" - + updateTime - + ", desc='" - + desc - + '\'' - + ", bussinessUser='" - + bussinessUser - + '\'' - + '}'; - } -} 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 deleted file mode 100644 index f02e0398f5..0000000000 --- a/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/errorcode/LinkisConfigurationErrorCodeSummary.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * 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; -import org.apache.linkis.common.errorcode.LinkisErrorCode; - -public enum LinkisConfigurationErrorCodeSummary implements LinkisErrorCode { - BUILD_LABEL_ID(14100, ""), - CONFIGURATION_NOT_TYPE(14100, "Configuration does not support engine type:{0}(配置暂不支持{0}引擎类型)"), - CORRESPONDING_ENGINE_TYPE( - 14100, "The corresponding engine type is not matched:{0}(没有匹配到对应的引擎类型:{0})"), - FAILED_TO_BUILD_LABEL(14100, "Failed to build label(建立标签失败)"), - BUILD_LABEL_IS_NULL(14100, "Failed to build label ,label is null(建立标签失败,标签为空)"), - CONFIGKEY_CANNOT_BE_NULL(14100, "ConfigKey cannot be null(configKey 不能为空)"), - CONFIG_KEY_NOT_EXISTS(14100, "Config key not exists:{0}(配置键不存在:{0})"), - LABEL_NOT_EXISTS(14100, "Label not exists:{0}(标签不存在{0})"), - KEY_OR_VALUE_CANNOT(14100, "Key or value cannot be null(键或值不能为空)"), - PARAMS_CANNOT_BE_EMPTY(14100, "Params cannot be empty!(参数不能为空!)"), - TOKEN_IS_ERROR(14100, "Token is error(令牌是错误的)"), - IS_NULL_CANNOT_BE_ADDED(14100, "CategoryName is null, cannot be added(categoryName 为空,无法添加)"), - CANNOT_BE_INCLUDED(14100, "CategoryName cannot be included '-'(类别名称不能包含 '-')"), - CREATOR_IS_NULL_CANNOT_BE_ADDED(14100, "Creator is null, cannot be added(创建者为空,无法添加)"), - ENGINE_TYPE_IS_NULL(14100, "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-3.2.1(保存的引擎类型参数有误,请按照固定格式传送,例如spark-3.2.1)"), - INCOMPLETE_RECONFIRM(14100, "Incomplete request parameters, please reconfirm(请求参数不完整,请重新确认)"), - ONLY_ADMIN_CAN_MODIFY(14100, "Only admin can modify category(只有管理员才能修改目录)"), - THE_LABEL_PARAMETER_IS_EMPTY(14100, " The label parameter is empty(标签参数为空)"), - ERROR_VALIDATOR_RANGE(14100, "Error validator range!(错误验证器范围!)"), - TYPE_OF_LABEL_NOT_SUPPORTED(14100, "This type of label is not supported:{0}(不支持这种类型的标签:{0})"); - - /** 错误码 */ - private final int errorCode; - /** 错误描述 */ - private final String errorDesc; - /** 错误可能出现的原因 */ - LinkisConfigurationErrorCodeSummary(int errorCode, String errorDesc) { - ErrorCodeUtils.validateErrorCode(errorCode, 10000, 24999); - this.errorCode = errorCode; - this.errorDesc = errorDesc; - } - - @Override - public int getErrorCode() { - return errorCode; - } - - @Override - public String getErrorDesc() { - return 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 d90bc6f455..37fa203eec 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,16 @@ 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(BUILD_LABEL_ID.getErrorCode(), message); + super(14100, message); } public ConfigurationException(String message, Throwable throwable) { - super(BUILD_LABEL_ID.getErrorCode(), message); + super(14100, 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 283960d5df..f407fcb614 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 @@ -17,7 +17,7 @@ package org.apache.linkis.configuration.restful.api; -import org.apache.linkis.configuration.conf.Configuration; +import org.apache.linkis.common.conf.Configuration; import org.apache.linkis.configuration.entity.*; import org.apache.linkis.configuration.exception.ConfigurationException; import org.apache.linkis.configuration.service.CategoryService; @@ -41,7 +41,6 @@ import javax.servlet.http.HttpServletRequest; import java.io.IOException; -import java.text.MessageFormat; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -56,8 +55,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import static org.apache.linkis.configuration.errorcode.LinkisConfigurationErrorCodeSummary.*; - @Api(tags = "parameter configuration") @RestController @RequestMapping(path = "/configuration") @@ -77,7 +74,11 @@ public class ConfigurationRestfulApi { @ApiOperation(value = "addKeyForEngine", notes = "add key for engine", response = Message.class) @ApiImplicitParams({ - @ApiImplicitParam(name = "engineType", dataType = "String"), + @ApiImplicitParam( + name = "engineType", + required = false, + dataType = "String", + value = "engine type"), @ApiImplicitParam(name = "version", required = false, dataType = "String", value = "version"), @ApiImplicitParam(name = "token, required = false", dataType = "String", value = "token"), @ApiImplicitParam(name = "keyJson", required = false, dataType = "String", value = "key json") @@ -93,15 +94,11 @@ public Message addKeyForEngine( if (StringUtils.isBlank(engineType) || StringUtils.isBlank(version) || StringUtils.isBlank(token)) { - throw new ConfigurationException(PARAMS_CANNOT_BE_EMPTY.getErrorDesc()); + throw new ConfigurationException("params cannot be empty!"); } - ModuleUserUtils.getOperationUser( - req, - MessageFormat.format( - "addKeyForEngine,engineType:{0},version:{1},token:{2}", engineType, version, token)); // todo 检验token if (!token.equals(ConfigurationConfiguration.COPYKEYTOKEN)) { - throw new ConfigurationException(TOKEN_IS_ERROR.getErrorDesc()); + throw new ConfigurationException("token is error"); } ConfigKey configKey = BDPJettyServerHelper.gson().fromJson(keyJson, ConfigKey.class); configurationService.addKeyForEngine(engineType, version, configKey); @@ -114,9 +111,13 @@ public Message addKeyForEngine( notes = "get full trees by app name", response = Message.class) @ApiImplicitParams({ - @ApiImplicitParam(name = "engineType", dataType = "String"), - @ApiImplicitParam(name = "version", dataType = "String", value = "version"), - @ApiImplicitParam(name = "creator", dataType = "String", value = "creator") + @ApiImplicitParam( + name = "engineType", + required = false, + dataType = "String", + value = "engine type"), + @ApiImplicitParam(name = "version", required = false, dataType = "String", value = "version"), + @ApiImplicitParam(name = "creator", required = false, dataType = "String", value = "creator") }) @RequestMapping(path = "/getFullTreesByAppName", method = RequestMethod.GET) public Message getFullTreesByAppName( @@ -125,33 +126,24 @@ public Message getFullTreesByAppName( @RequestParam(value = "version", required = false) String version, @RequestParam(value = "creator", required = false) String creator) throws ConfigurationException { - if (creator != null - && (creator.equals(Configuration.GLOBAL_CONF_CHN_NAME()) - || creator.equals(Configuration.GLOBAL_CONF_CHN_OLDNAME()) - || creator.equals(Configuration.GLOBAL_CONF_CHN_EN_NAME()))) { + String username = ModuleUserUtils.getOperationUser(req, "getFullTreesByAppName"); + if (creator != null && (creator.equals("通用设置") || creator.equals("全局设置"))) { engineType = "*"; version = "*"; creator = "*"; } - String username = - ModuleUserUtils.getOperationUser( - req, - MessageFormat.format( - "ConfigurationException,engineType:{0},version:{1}", engineType, version)); List labelList = LabelEntityParser.generateUserCreatorEngineTypeLabelList( username, creator, engineType, version); ArrayList configTrees = - configurationService.getFullTreeByLabelList( - labelList, true, req.getHeader("Content-Language")); + configurationService.getFullTreeByLabelList(labelList, true); return Message.ok().data("fullTree", configTrees); } @ApiOperation(value = "getCategory", notes = "get category", response = Message.class) @RequestMapping(path = "/getCategory", method = RequestMethod.GET) public Message getCategory(HttpServletRequest req) { - List categoryLabelList = - categoryService.getAllCategory(req.getHeader("Content-Language")); + List categoryLabelList = categoryService.getAllCategory(); return Message.ok().data("Category", categoryLabelList); } @@ -160,8 +152,18 @@ public Message getCategory(HttpServletRequest req) { notes = "create first category", response = Message.class) @ApiImplicitParams({ - @ApiImplicitParam(name = "categoryName", required = true, dataType = "String"), - @ApiImplicitParam(name = "description", required = true, dataType = "String"), + @ApiImplicitParam( + name = "categoryName", + required = true, + dataType = "String", + value = "category name", + example = "name"), + @ApiImplicitParam( + name = "description", + required = true, + dataType = "STring", + value = "description", + example = "description"), }) @ApiOperationSupport(ignoreParameters = {"jsonNode"}) @RequestMapping(path = "/createFirstCategory", method = RequestMethod.POST) @@ -172,10 +174,10 @@ public Message createFirstCategory(HttpServletRequest request, @RequestBody Json String categoryName = jsonNode.get("categoryName").asText(); String description = jsonNode.get("description").asText(); if (StringUtils.isEmpty(categoryName) || categoryName.equals(NULL)) { - throw new ConfigurationException(IS_NULL_CANNOT_BE_ADDED.getErrorDesc()); + throw new ConfigurationException("categoryName is null, cannot be added"); } if (StringUtils.isEmpty(categoryName) || categoryName.contains("-")) { - throw new ConfigurationException(CANNOT_BE_INCLUDED.getErrorDesc()); + throw new ConfigurationException("categoryName cannot be included '-'"); } categoryService.createFirstCategory(categoryName, description); return Message.ok(); @@ -183,7 +185,12 @@ public Message createFirstCategory(HttpServletRequest request, @RequestBody Json @ApiOperation(value = "deleteCategory", notes = "delete category", response = Message.class) @ApiImplicitParams({ - @ApiImplicitParam(name = "categoryId", required = true, dataType = "String", example = "54") + @ApiImplicitParam( + name = "categoryId", + required = true, + dataType = "String", + value = "category id", + example = "54") }) @ApiOperationSupport(ignoreParameters = "jsonNode") @RequestMapping(path = "/deleteCategory", method = RequestMethod.POST) @@ -201,10 +208,29 @@ public Message deleteCategory(HttpServletRequest request, @RequestBody JsonNode notes = "create second category", response = Message.class) @ApiImplicitParams({ - @ApiImplicitParam(name = "categoryId", required = true, dataType = "String", example = "39"), - @ApiImplicitParam(name = "engineType", required = true, dataType = "String", example = "hive"), - @ApiImplicitParam(name = "version", required = true, dataType = "String", example = "1.2.0"), - @ApiImplicitParam(name = "description", required = true, dataType = "String"), + @ApiImplicitParam( + name = "categoryId", + required = true, + dataType = "String", + value = "category id", + example = "39"), + @ApiImplicitParam( + name = "engineType", + required = true, + dataType = "String", + value = "engine type", + example = "hive"), + @ApiImplicitParam( + name = "version", + required = true, + dataType = "String", + value = "Version", + example = "1.2.0"), + @ApiImplicitParam( + name = "description", + required = true, + dataType = "String", + value = "description"), }) @ApiOperationSupport(ignoreParameters = {"jsonNode"}) @RequestMapping(path = "/createSecondCategory", method = RequestMethod.POST) @@ -217,10 +243,10 @@ public Message createSecondCategory(HttpServletRequest request, @RequestBody Jso String version = jsonNode.get("version").asText(); String description = jsonNode.get("description").asText(); if (categoryId <= 0) { - throw new ConfigurationException(CREATOR_IS_NULL_CANNOT_BE_ADDED.getErrorDesc()); + throw new ConfigurationException("creator is null, cannot be added"); } if (StringUtils.isEmpty(engineType) || engineType.toLowerCase().equals(NULL)) { - throw new ConfigurationException(ENGINE_TYPE_IS_NULL.getErrorDesc()); + throw new ConfigurationException("engine type is null, cannot be added"); } if (StringUtils.isEmpty(version) || version.toLowerCase().equals(NULL)) { version = LabelUtils.COMMON_VALUE; @@ -231,11 +257,25 @@ public Message createSecondCategory(HttpServletRequest request, @RequestBody Jso @ApiOperation(value = "saveFullTree", notes = "save full tree", response = Message.class) @ApiImplicitParams({ - @ApiImplicitParam(name = "creator", required = true, dataType = "String", example = "xwzTest"), - @ApiImplicitParam(name = "engineType", required = true, dataType = "String", example = "hive"), + @ApiImplicitParam( + name = "creator", + required = true, + dataType = "String", + value = "creator", + example = "xwzTest"), + @ApiImplicitParam( + name = "engineType", + required = true, + dataType = "String", + value = "engine type", + example = "python-ss"), @ApiImplicitParam(name = "fullTree", required = true, dataType = "List", value = "full tree"), @ApiImplicitParam(name = "name", required = true, dataType = "String", value = "name"), - @ApiImplicitParam(name = "description", required = true, dataType = "String"), + @ApiImplicitParam( + name = "description", + required = true, + dataType = "String", + value = "description"), @ApiImplicitParam(name = "settings", required = true, dataType = "List", value = "settings") }) @ApiOperationSupport(ignoreParameters = {"json"}) @@ -245,10 +285,7 @@ public Message saveFullTree(HttpServletRequest req, @RequestBody JsonNode json) List fullTrees = mapper.treeToValue(json.get("fullTree"), List.class); String creator = JsonNodeUtil.getStringValue(json.get("creator")); String engineType = JsonNodeUtil.getStringValue(json.get("engineType")); - if (creator != null - && (creator.equals(Configuration.GLOBAL_CONF_CHN_NAME()) - || creator.equals(Configuration.GLOBAL_CONF_CHN_OLDNAME()) - || creator.equals(Configuration.GLOBAL_CONF_CHN_EN_NAME()))) { + if (creator != null && (creator.equals("通用设置") || creator.equals("全局设置"))) { creator = "*"; } String username = ModuleUserUtils.getOperationUser(req, "saveFullTree"); @@ -269,45 +306,16 @@ public Message saveFullTree(HttpServletRequest req, @RequestBody JsonNode json) if (engineType != null) { String[] tmpString = engineType.split("-"); if (tmpString.length != 2) { - throw new ConfigurationException(INCORRECT_FIXED_SUCH.getErrorDesc()); + 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)"); } engine = tmpString[0]; version = tmpString[1]; } configurationService.updateUserValue(createList, updateList); - // TODO: Add a refresh cache interface later - if (StringUtils.isNotBlank(creator) && creator.equals("*")) { - List allCategory = categoryService.getAllCategory(null); - List categoryLabelVos = - allCategory.stream() - .filter(s -> s.getCategoryName().equals(Configuration.REMOVE_APPLICATION_CACHE())) - .map(CategoryLabelVo::getChildCategory) - .findFirst() - .get(); - categoryLabelVos.stream() - .map(CategoryLabelVo::getCategoryName) - .filter(StringUtils::isNotBlank) - .forEach( - info -> { - String[] tmpString = info.split("-"); - if (tmpString.length == 2) { - String engineName = tmpString[0]; - String engineVersion = tmpString[1]; - logger.info( - "Config remove engine cache:engineName:{},engineVersion:{}", - engineName, - engineVersion); - configurationService.clearAMCacheConf( - username, - Configuration.REMOVE_APPLICATION_CACHE(), - engineName, - engineVersion); - } - }); - } else { - configurationService.clearAMCacheConf(username, creator, engine, version); - } - return Message.ok(); + configurationService.clearAMCacheConf(username, creator, engine, version); + Message message = Message.ok(); + return message; } @ApiOperation( @@ -325,8 +333,16 @@ public Message listAllEngineType(HttpServletRequest request) { notes = "update category info", response = Message.class) @ApiImplicitParams({ - @ApiImplicitParam(name = "description", required = true, dataType = "String"), - @ApiImplicitParam(name = "categoryId", required = true, dataType = "String") + @ApiImplicitParam( + name = "description", + required = true, + dataType = "String", + value = "description"), + @ApiImplicitParam( + name = "categoryId", + required = true, + dataType = "String", + value = "category id") }) @ApiOperationSupport(ignoreParameters = {"jsonNode"}) @RequestMapping(path = "/updateCategoryInfo", method = RequestMethod.POST) @@ -340,7 +356,7 @@ public Message updateCategoryInfo(HttpServletRequest request, @RequestBody JsonN description = jsonNode.get("description").asText(); categoryId = jsonNode.get("categoryId").asInt(); } catch (Exception e) { - throw new ConfigurationException(INCOMPLETE_RECONFIRM.getErrorDesc()); + throw new ConfigurationException("请求参数不完整,请重新确认"); } if (description != null) { categoryService.updateCategory(categoryId, description); @@ -350,9 +366,17 @@ public Message updateCategoryInfo(HttpServletRequest request, @RequestBody JsonN @ApiOperation(value = "rpcTest", notes = "rpc test", response = Message.class) @ApiImplicitParams({ - @ApiImplicitParam(name = "creator", dataType = "String", value = "creator"), - @ApiImplicitParam(name = "engineType", dataType = "String"), - @ApiImplicitParam(name = "username", dataType = "String"), + @ApiImplicitParam(name = "creator", required = false, dataType = "String", value = "creator"), + @ApiImplicitParam( + name = "engineType", + required = false, + dataType = "String", + value = "engine type"), + @ApiImplicitParam( + name = "username", + required = false, + dataType = "String", + value = "user name"), @ApiImplicitParam(name = "version", required = false, dataType = "String", value = "version") }) @RequestMapping(path = "/rpcTest", method = RequestMethod.GET) @@ -375,16 +399,24 @@ public Message rpcTest( } private void checkAdmin(String userName) throws ConfigurationException { - if (!org.apache.linkis.common.conf.Configuration.isAdmin(userName)) { - throw new ConfigurationException(ONLY_ADMIN_CAN_MODIFY.getErrorDesc()); + if (!Configuration.isAdmin(userName)) { + throw new ConfigurationException("only admin can modify category(只有管理员才能修改目录)"); } } @ApiOperation(value = "getKeyValue", notes = "get key value", response = Message.class) @ApiImplicitParams({ @ApiImplicitParam(name = "creator", required = false, dataType = "String", value = "creator"), - @ApiImplicitParam(name = "engineType", dataType = "String"), - @ApiImplicitParam(name = "configKey", dataType = "String"), + @ApiImplicitParam( + name = "engineType", + required = false, + dataType = "String", + value = "engine type"), + @ApiImplicitParam( + name = "configKey", + required = false, + dataType = "String", + value = "config key"), @ApiImplicitParam(name = "version", required = false, dataType = "String", value = "version") }) @RequestMapping(path = "/keyvalue", method = RequestMethod.GET) @@ -414,11 +446,23 @@ public Message getKeyValue( @ApiOperation(value = "saveKeyValue", notes = "save key value", response = Message.class) @ApiImplicitParams({ - @ApiImplicitParam(name = "engineType", required = true, dataType = "String"), + @ApiImplicitParam( + name = "engineType", + required = true, + dataType = "String", + value = "engine type"), @ApiImplicitParam(name = "version", required = true, dataType = "String", value = "version"), @ApiImplicitParam(name = "creator", required = true, dataType = "String", value = "creator"), - @ApiImplicitParam(name = "configKey", required = true, dataType = "String"), - @ApiImplicitParam(name = "configValue", required = true, dataType = "String") + @ApiImplicitParam( + name = "configKey", + required = true, + dataType = "String", + value = "config key"), + @ApiImplicitParam( + name = "configValue", + required = true, + dataType = "String", + value = "config value") }) @ApiOperationSupport(ignoreParameters = {"json"}) @RequestMapping(path = "/keyvalue", method = RequestMethod.POST) @@ -451,10 +495,18 @@ public Message saveKeyValue(HttpServletRequest req, @RequestBody Map resultMap = - tenantConfigService.queryTenantList(user, creator, tenantValue, pageNow, pageSize); - return Message.ok() - .data("tenantList", resultMap.get("tenantList")) - .data(JobRequestConstants.TOTAL_PAGE(), resultMap.get(JobRequestConstants.TOTAL_PAGE())); - } - - @ApiImplicitParams({ - @ApiImplicitParam( - paramType = "query", - dataType = "HttpServletRequest", - name = "req", - value = ""), - @ApiImplicitParam(paramType = "query", dataType = "string", name = "user", value = "user"), - @ApiImplicitParam( - paramType = "query", - dataType = "string", - name = "creator", - value = "creator"), - @ApiImplicitParam( - paramType = "query", - dataType = "string", - name = "tenantValue", - value = "tenantValue") - }) - @ApiOperation( - value = "check-user-creator", - notes = "check user creator", - httpMethod = "GET", - response = Message.class) - @RequestMapping(path = "/check-user-creator", method = RequestMethod.GET) - public Message checkUserCreator( - HttpServletRequest req, - @RequestParam(value = "user", required = false) String user, - @RequestParam(value = "creator", required = false) String creator) { - Boolean result = false; - try { - // Parameter verification - if (StringUtils.isBlank(creator)) { - throw new ConfigurationException("Application Name can't be empty "); - } - if (StringUtils.isBlank(user)) { - throw new ConfigurationException("User Name can't be empty "); - } - String userName = ModuleUserUtils.getOperationUser(req, "checkUserCreator"); - if (!Configuration.isAdmin(userName)) { - return Message.error("Failed to check-user-creator,msg: only administrators can configure"); - } - result = tenantConfigService.isExist(user, creator); - } catch (ConfigurationException e) { - return Message.error("Failed to check-user-creator,msg:" + e.getMessage()); - } - return Message.ok().data("exist", result); - } - - private void parameterVerification(TenantVo tenantVo) throws ConfigurationException { - // Parameter verification - if (StringUtils.isBlank(tenantVo.getCreator())) { - throw new ConfigurationException("Application name can't be empty "); - } - if (StringUtils.isBlank(tenantVo.getUser())) { - throw new ConfigurationException("User name can't be empty "); - } - if (StringUtils.isBlank(tenantVo.getBussinessUser())) { - throw new ConfigurationException("Creat user can't be empty "); - } - if (StringUtils.isBlank(tenantVo.getDesc())) { - throw new ConfigurationException("Description can't be empty "); - } - if (StringUtils.isBlank(tenantVo.getTenantValue())) { - throw new ConfigurationException("Tenant tag can't be empty "); - } - if (tenantVo.getCreator().equals("*") && tenantVo.getUser().equals("*")) { - throw new ConfigurationException("User && Creator cannot be both *"); - } - } -} diff --git a/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/restful/api/UserIpConfigrationRestfulApi.java b/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/restful/api/UserIpConfigrationRestfulApi.java deleted file mode 100644 index 78e7003d49..0000000000 --- a/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/restful/api/UserIpConfigrationRestfulApi.java +++ /dev/null @@ -1,230 +0,0 @@ -/* - * 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.restful.api; - -import org.apache.linkis.common.conf.Configuration; -import org.apache.linkis.configuration.entity.UserIpVo; -import org.apache.linkis.configuration.exception.ConfigurationException; -import org.apache.linkis.configuration.service.UserIpConfigService; -import org.apache.linkis.governance.common.constant.job.JobRequestConstants; -import org.apache.linkis.server.Message; -import org.apache.linkis.server.utils.ModuleUserUtils; - -import org.apache.commons.lang.StringUtils; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.dao.DuplicateKeyException; -import org.springframework.web.bind.annotation.*; - -import javax.servlet.http.HttpServletRequest; - -import java.util.Map; - -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiImplicitParam; -import io.swagger.annotations.ApiImplicitParams; -import io.swagger.annotations.ApiOperation; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -@Api -@RestController -@RequestMapping(path = "/configuration/user-ip-mapping") -public class UserIpConfigrationRestfulApi { - - private static final Logger logger = LoggerFactory.getLogger(UserIpConfigrationRestfulApi.class); - - @Autowired private UserIpConfigService userIpConfigService; - - @ApiImplicitParams({ - @ApiImplicitParam( - paramType = "query", - dataType = "HttpServletRequest", - name = "req", - value = ""), - @ApiImplicitParam( - paramType = "body", - dataType = "UserIpVo", - name = "userIpVo", - value = "userIpVo") - }) - @ApiOperation(value = "create-user-ip", notes = "create user ip", httpMethod = "POST") - @RequestMapping(path = "/create-user-ip", method = RequestMethod.POST) - public Message createUserIp(HttpServletRequest req, @RequestBody UserIpVo userIpVo) { - try { - String userName = ModuleUserUtils.getOperationUser(req, "execute createUserIP"); - if (!Configuration.isAdmin(userName)) { - return Message.error("Failed to create-user-ip,msg: only administrators can configure"); - } - if (userIpConfigService.userExists(userIpVo.getUser(), userIpVo.getCreator())) { - throw new ConfigurationException("User-creator is existed"); - } - parameterVerification(userIpVo); - userIpConfigService.createUserIP(userIpVo); - } catch (DuplicateKeyException e) { - return Message.error("Failed to create-user-ip,msg:create user-creator is existed"); - } catch (ConfigurationException e) { - return Message.error("Failed to create-user-ip,msg:" + e.getMessage()); - } - return Message.ok(); - } - - @ApiImplicitParams({ - @ApiImplicitParam( - paramType = "query", - dataType = "HttpServletRequest", - name = "req", - value = ""), - @ApiImplicitParam( - paramType = "body", - dataType = "UserIpVo", - name = "UserIpVo", - value = "UserIpVo") - }) - @ApiOperation(value = "update-user-ip", notes = "update user ip", httpMethod = "POST") - @RequestMapping(path = "/update-user-ip", method = RequestMethod.POST) - public Message updateUserIp(HttpServletRequest req, @RequestBody UserIpVo userIpVo) { - try { - String userName = ModuleUserUtils.getOperationUser(req, "execute updateUserIP"); - if (!Configuration.isAdmin(userName)) { - return Message.error("Failed to update-user-ip,msg: only administrators can configure "); - } - // if (!userIpConfigService.checkUserCteator(userIpVo.getUser(), userIpVo.getCreator())) - // { - // throw new ConfigurationException("User-creator is not existed"); - // } - parameterVerification(userIpVo); - userIpConfigService.updateUserIP(userIpVo); - } catch (ConfigurationException e) { - return Message.error("Failed to update-user-ip,msg:" + e.getMessage()); - } - return Message.ok(); - } - - @ApiImplicitParams({ - @ApiImplicitParam( - paramType = "query", - dataType = "HttpServletRequest", - name = "req", - value = ""), - @ApiImplicitParam(paramType = "query", dataType = "int", name = "id", value = "id") - }) - @ApiOperation(value = "delete-user-ip", notes = "delete user ip", httpMethod = "GET") - @RequestMapping(path = "/delete-user-ip", method = RequestMethod.GET) - public Message deleteUserIp(HttpServletRequest req, @RequestParam(value = "id") Integer id) { - try { - String userName = ModuleUserUtils.getOperationUser(req, "execute deleteUserIp,id: " + id); - if (!Configuration.isAdmin(userName)) { - return Message.error("Failed to delete-user-ip,msg: only administrators can configure"); - } - userIpConfigService.deleteUserIP(id); - } catch (ConfigurationException e) { - return Message.error("Failed to check-user-creator,msg:" + e.getMessage()); - } - return Message.ok(); - } - - @ApiImplicitParams({ - @ApiImplicitParam( - paramType = "query", - dataType = "HttpServletRequest", - name = "req", - value = ""), - @ApiImplicitParam(paramType = "query", dataType = "string", name = "user", value = "user"), - @ApiImplicitParam(paramType = "query", dataType = "string", name = "creator", value = "creator") - }) - @ApiOperation(value = "query-user-ip-list", notes = "query user ip list", httpMethod = "GET") - @RequestMapping(path = "/query-user-ip-list", method = RequestMethod.GET) - public Message queryUserIpList( - HttpServletRequest req, - @RequestParam(value = "user", required = false) String user, - @RequestParam(value = "creator", required = false) String creator, - @RequestParam(value = "pageNow") Integer pageNow, - @RequestParam(value = "pageSize") Integer pageSize) { - String userName = ModuleUserUtils.getOperationUser(req, "queryUserIPList"); - if (!Configuration.isAdmin(userName)) { - return Message.error("Failed to query-user-ip-list,msg: only administrators can configure"); - } - if (StringUtils.isBlank(user)) user = null; - if (StringUtils.isBlank(creator)) creator = null; - if (null == pageNow) pageNow = 1; - if (null == pageSize) pageSize = 20; - Map resultMap = - userIpConfigService.queryUserIPList(user, creator, pageNow, pageSize); - return Message.ok() - .data("userIpList", resultMap.get("userIpList")) - .data(JobRequestConstants.TOTAL_PAGE(), resultMap.get(JobRequestConstants.TOTAL_PAGE())); - } - - @ApiImplicitParams({ - @ApiImplicitParam( - paramType = "query", - dataType = "HttpServletRequest", - name = "req", - value = ""), - @ApiImplicitParam(paramType = "query", dataType = "string", name = "user", value = "user"), - @ApiImplicitParam(paramType = "query", dataType = "string", name = "creator", value = "creator") - }) - @ApiOperation(value = "check-user-creator", notes = " check user creator", httpMethod = "GET") - @RequestMapping(path = "/check-user-creator", method = RequestMethod.GET) - public Message checkUserCreator( - HttpServletRequest req, - @RequestParam(value = "user") String user, - @RequestParam(value = "creator") String creator) { - boolean result = false; - try { - String userName = ModuleUserUtils.getOperationUser(req, "checkUserCreator"); - if (!Configuration.isAdmin(userName)) { - return Message.error("Failed to check-user-creator,msg: only administrators can configure"); - } - // Parameter verification - if (StringUtils.isBlank(creator)) { - throw new ConfigurationException("Application Name couldn't be empty "); - } - if (StringUtils.isBlank(user)) { - throw new ConfigurationException("User Name couldn't be empty "); - } - if (creator.equals("*")) { - throw new ConfigurationException("Application Name couldn't be '*' "); - } - result = userIpConfigService.userExists(user, creator); - } catch (ConfigurationException e) { - return Message.error("Failed to check-user-creator,msg:" + e.getMessage()); - } - return Message.ok().data("exist", result); - } - - private void parameterVerification(UserIpVo userIpVo) throws ConfigurationException { - // Parameter verification - if (StringUtils.isBlank(userIpVo.getCreator())) { - throw new ConfigurationException("Application Name couldn't be empty "); - } - if (StringUtils.isBlank(userIpVo.getUser())) { - throw new ConfigurationException("User Name couldn't be empty "); - } - if (StringUtils.isBlank(userIpVo.getBussinessUser())) { - throw new ConfigurationException("Creat User couldn't be empty "); - } - if (StringUtils.isBlank(userIpVo.getIpList())) { - throw new ConfigurationException("Ip List couldn't be empty "); - } - if (StringUtils.isBlank(userIpVo.getDesc())) { - throw new ConfigurationException("Description couldn't be empty "); - } - } -} diff --git a/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/service/TenantConfigService.java b/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/service/TenantConfigService.java deleted file mode 100644 index 87b14a9c5e..0000000000 --- a/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/service/TenantConfigService.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * 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.service; - -import org.apache.linkis.configuration.entity.TenantVo; -import org.apache.linkis.configuration.exception.ConfigurationException; - -import java.util.Map; - -public interface TenantConfigService { - - Map queryTenantList( - String user, String creator, String tenantValue, Integer pageNow, Integer pageSize); - - void deleteTenant(Integer id) throws ConfigurationException; - - void updateTenant(TenantVo tenantVo) throws ConfigurationException; - - void createTenant(TenantVo tenantVo) throws ConfigurationException; - - Boolean isExist(String user, String creator) throws ConfigurationException; - - TenantVo queryTenant(String user, String creator); -} diff --git a/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/service/UserIpConfigService.java b/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/service/UserIpConfigService.java deleted file mode 100644 index 6d292d6813..0000000000 --- a/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/service/UserIpConfigService.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * 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.service; - -import org.apache.linkis.configuration.entity.UserIpVo; -import org.apache.linkis.configuration.exception.ConfigurationException; - -import java.util.Map; - -public interface UserIpConfigService { - - void createUserIP(UserIpVo userIpVo) throws ConfigurationException; - - void updateUserIP(UserIpVo userIpVo) throws ConfigurationException; - - void deleteUserIP(Integer id) throws ConfigurationException; - - Map queryUserIPList( - String user, String creator, Integer pageNow, Integer pageSize); - - boolean userExists(String user, String creator); - - UserIpVo queryUserIP(String user, String creator); -} 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 6811b5e7e2..0b28ae3267 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 @@ -39,15 +39,12 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import java.text.MessageFormat; import java.util.ArrayList; 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 { @@ -65,14 +62,13 @@ public ConfigValue saveConfigValue(ConfigKeyValue configKeyValue, List> if (StringUtils.isBlank(configKeyValue.getConfigValue()) || StringUtils.isBlank(configKeyValue.getKey())) { - throw new ConfigurationException(KEY_OR_VALUE_CANNOT.getErrorDesc()); + throw new ConfigurationException("key or value cannot be null"); } LabelParameterParser.labelCheck(labelList); - List configKeys = configMapper.selectKeyByKeyName(configKeyValue.getKey()); + List configKeys = configMapper.seleteKeyByKeyName(configKeyValue.getKey()); if (null == configKeys || configKeys.isEmpty()) { - throw new ConfigurationException( - MessageFormat.format(CONFIG_KEY_NOT_EXISTS.getErrorDesc(), configKeyValue.getKey())); + throw new ConfigurationException("config key not exists: " + configKeyValue.getKey()); } ConfigKey configKey = configKeys.get(0); EngineTypeLabel engineTypeLabel = LabelUtil.getEngineTypeLabel(labelList); @@ -121,10 +117,10 @@ private CombinedLabel getCombinedLabel(List> labelList) throws Configur try { combinedLabel = (CombinedLabel) combinedLabelBuilder.build("", labelList); } catch (LabelErrorException e) { - throw new ConfigurationException(FAILED_TO_BUILD_LABEL.getErrorDesc(), e); + throw new ConfigurationException("Failed to build label", e); } if (null == combinedLabel) { - throw new ConfigurationException(BUILD_LABEL_IS_NULL.getErrorDesc()); + throw new ConfigurationException("Failed to build label ,label is null"); } return combinedLabel; } @@ -133,22 +129,20 @@ private CombinedLabel getCombinedLabel(List> labelList) throws Configur public List getConfigValue(String key, List> labelList) throws ConfigurationException { if (StringUtils.isBlank(key)) { - throw new ConfigurationException(CONFIGKEY_CANNOT_BE_NULL.getErrorDesc()); + throw new ConfigurationException("configKey cannot be null"); } LabelParameterParser.labelCheck(labelList); - List configKeys = configMapper.selectKeyByKeyName(key); + List configKeys = configMapper.seleteKeyByKeyName(key); if (null == configKeys || configKeys.isEmpty()) { - throw new ConfigurationException( - MessageFormat.format(CONFIG_KEY_NOT_EXISTS.getErrorDesc(), key)); + throw new ConfigurationException("config key not exists: " + key); } CombinedLabel combinedLabel = getCombinedLabel(labelList); ConfigLabel configLabel = labelMapper.getLabelByKeyValue(combinedLabel.getLabelKey(), combinedLabel.getStringValue()); if (null == configLabel || configLabel.getId() < 0) { - throw new ConfigurationException( - MessageFormat.format(LABEL_NOT_EXISTS.getErrorDesc(), combinedLabel.getStringValue())); + throw new ConfigurationException("label not exists: " + combinedLabel.getStringValue()); } List configValues = new ArrayList<>(); for (ConfigKey configKey : configKeys) { diff --git a/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/service/impl/TenantConfigServiceImpl.java b/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/service/impl/TenantConfigServiceImpl.java deleted file mode 100644 index bf9755a307..0000000000 --- a/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/service/impl/TenantConfigServiceImpl.java +++ /dev/null @@ -1,188 +0,0 @@ -/* - * 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.service.impl; - -import org.apache.linkis.configuration.dao.UserTenantMapper; -import org.apache.linkis.configuration.entity.TenantVo; -import org.apache.linkis.configuration.exception.ConfigurationException; -import org.apache.linkis.configuration.service.TenantConfigService; -import org.apache.linkis.configuration.util.HttpsUtil; -import org.apache.linkis.governance.common.constant.job.JobRequestConstants; - -import org.apache.commons.collections.MapUtils; -import org.apache.commons.lang.StringUtils; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - -import java.io.IOException; -import java.util.*; -import java.util.concurrent.atomic.AtomicReference; - -import com.github.pagehelper.PageHelper; -import com.github.pagehelper.PageInfo; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -@Service -public class TenantConfigServiceImpl implements TenantConfigService { - - private static final Logger logger = LoggerFactory.getLogger(TenantConfigServiceImpl.class); - - @Autowired private UserTenantMapper userTenantMapper; - - /** - * * Querying the tenant configuration table - * - * @param user - * @param creator - * @param tenantValue - * @param pageNow - * @param pageSize - * @return List - */ - @Override - public Map queryTenantList( - String user, String creator, String tenantValue, Integer pageNow, Integer pageSize) { - Map result = new HashMap<>(2); - List tenantVos = null; - if (Objects.isNull(pageNow)) { - pageNow = 1; - } - if (Objects.isNull(pageSize)) { - pageSize = 20; - } - PageHelper.startPage(pageNow, pageSize); - try { - tenantVos = userTenantMapper.queryTenantList(user, creator, tenantValue); - } finally { - PageHelper.clearPage(); - } - PageInfo pageInfo = new PageInfo<>(tenantVos); - result.put("tenantList", tenantVos); - result.put(JobRequestConstants.TOTAL_PAGE(), pageInfo.getTotal()); - return result; - } - - /** - * Delete tenant By ID - * - * @param id - */ - @Override - public void deleteTenant(Integer id) throws ConfigurationException { - logger.info("deleteUserIP : id:{}", id); - if (StringUtils.isBlank(id.toString())) { - throw new ConfigurationException("id can't be empty "); - } - userTenantMapper.deleteTenant(id); - } - - /** - * Update tenant - * - * @param tenantVo - */ - @Override - public void updateTenant(TenantVo tenantVo) throws ConfigurationException { - if (StringUtils.isBlank(tenantVo.getId())) { - throw new ConfigurationException("id can't be empty "); - } - dataProcessing(tenantVo); - TenantVo tenantVoLowerCase = toLowerCase(tenantVo); - logger.info("updateTenant : {}", tenantVoLowerCase); - userTenantMapper.updateTenant(tenantVoLowerCase); - } - - /** - * Insert tenant - * - * @param tenantVo - */ - @Override - public void createTenant(TenantVo tenantVo) throws ConfigurationException { - dataProcessing(tenantVo); - TenantVo tenantVoLowerCase = toLowerCase(tenantVo); - tenantVoLowerCase.setCreateTime(new Date()); - logger.info("createTenant : {}", tenantVoLowerCase); - userTenantMapper.createTenant(tenantVo); - } - - private void dataProcessing(TenantVo tenantVo) throws ConfigurationException { - if (!tenantVo.getCreator().equals("*")) { - AtomicReference tenantResult = new AtomicReference<>(false); - // Obtain the tenant information of the ECM list - Map ecmListResult = null; - try { - ecmListResult = HttpsUtil.sendHttp(null, null); - logger.info("Request ecm list response {}:", ecmListResult); - } catch (IOException e) { - logger.warn("failed to get ecmResource data"); - } - Map>> data = MapUtils.getMap(ecmListResult, "data"); - List> emNodeVoList = data.get("EMs"); - // Compare ECM list tenant labels for task - emNodeVoList.forEach( - ecmInfo -> { - List> labels = (List>) ecmInfo.get("labels"); - labels.stream() - .filter(labelmap -> labelmap.containsKey("tenant")) - .forEach( - map -> { - String tenant = map.get("tenant").toString().toLowerCase(); - if (tenant.equals(tenantVo.getTenantValue().toLowerCase())) { - tenantResult.set(true); - } - }); - }); - // Compare the value of ecm tenant - if (!tenantResult.get()) - throw new ConfigurationException("The ECM with the corresponding label was not found"); - // The beginning of tenantValue needs to contain creator - String creator = tenantVo.getCreator().toLowerCase(); - String[] tenantArray = tenantVo.getTenantValue().toLowerCase().split("_"); - if (tenantArray.length > 1 && !creator.equals(tenantArray[0])) { - throw new ConfigurationException("tenantValue should contain creator first"); - } - } - } - - @Override - public Boolean isExist(String user, String creator) { - boolean result = true; - Map resultMap = - queryTenantList(user.toLowerCase(), creator.toLowerCase(), null, 1, 20); - Object tenantList = resultMap.getOrDefault(JobRequestConstants.TOTAL_PAGE(), 0); - int total = Integer.parseInt(tenantList.toString()); - if (total == 0) result = false; - return result; - } - - @Override - public TenantVo queryTenant(String user, String creator) { - return userTenantMapper.queryTenant(user, creator); - } - - public TenantVo toLowerCase(TenantVo tenantVo) { - tenantVo.setTenantValue(tenantVo.getTenantValue().toLowerCase()); - tenantVo.setCreator(tenantVo.getCreator().toLowerCase()); - tenantVo.setUser(tenantVo.getUser().toLowerCase()); - tenantVo.setUpdateTime(new Date()); - return tenantVo; - } -} diff --git a/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/service/impl/TenantServiceImpl.java b/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/service/impl/TenantServiceImpl.java deleted file mode 100644 index 25d272c121..0000000000 --- a/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/service/impl/TenantServiceImpl.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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.service.impl; - -import org.apache.linkis.configuration.entity.TenantVo; -import org.apache.linkis.configuration.service.TenantConfigService; -import org.apache.linkis.configuration.service.TenantService; -import org.apache.linkis.governance.common.protocol.conf.TenantRequest; -import org.apache.linkis.governance.common.protocol.conf.TenantResponse; -import org.apache.linkis.rpc.Sender; -import org.apache.linkis.rpc.message.annotation.Receiver; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -@Service -public class TenantServiceImpl implements TenantService { - - private static final Logger logger = LoggerFactory.getLogger(TenantService.class); - - @Autowired private TenantConfigService tenantConfigService; - - @Receiver - @Override - public TenantResponse getTenantData(TenantRequest request, Sender sender) { - TenantVo tenantVo = tenantConfigService.queryTenant(request.user(), request.creator()); - if (null == tenantVo) { - logger.warn( - "TenantCache user {} creator {} data loading failed", request.user(), request.creator()); - return new TenantResponse(request.user(), request.creator(), ""); - } else { - return new TenantResponse( - tenantVo.getUser(), tenantVo.getCreator(), tenantVo.getTenantValue()); - } - } -} diff --git a/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/service/impl/UserIpConfigServiceImpl.java b/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/service/impl/UserIpConfigServiceImpl.java deleted file mode 100644 index 9c96121156..0000000000 --- a/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/service/impl/UserIpConfigServiceImpl.java +++ /dev/null @@ -1,154 +0,0 @@ -/* - * 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.service.impl; - -import org.apache.linkis.configuration.dao.UserIpMapper; -import org.apache.linkis.configuration.entity.UserIpVo; -import org.apache.linkis.configuration.exception.ConfigurationException; -import org.apache.linkis.configuration.service.UserIpConfigService; -import org.apache.linkis.configuration.util.CommonUtils; -import org.apache.linkis.governance.common.constant.job.JobRequestConstants; - -import org.apache.commons.lang.StringUtils; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -import java.util.*; - -import com.github.pagehelper.PageHelper; -import com.github.pagehelper.PageInfo; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -@Service -public class UserIpConfigServiceImpl implements UserIpConfigService { - - private static final Logger logger = LoggerFactory.getLogger(UserIpConfigServiceImpl.class); - - @Autowired private UserIpMapper userIpMapper; - - /** - * * createUserIP - * - * @param userIpVo - * @return - */ - @Override - public void createUserIP(UserIpVo userIpVo) throws ConfigurationException { - dataProcessing(userIpVo); - UserIpVo userIpVoLowerCase = toLowerCase(userIpVo); - userIpVoLowerCase.setCreateTime(new Date()); - userIpVoLowerCase.setUpdateTime(new Date()); - userIpMapper.createUserIP(userIpVoLowerCase); - } - - /** - * updateUserIP - * - * @param userIpVo - */ - @Override - public void updateUserIP(UserIpVo userIpVo) throws ConfigurationException { - if (StringUtils.isBlank(userIpVo.getId())) { - throw new ConfigurationException("id couldn't be empty "); - } - dataProcessing(userIpVo); - UserIpVo userIpVoLowerCase = toLowerCase(userIpVo); - userIpVoLowerCase.setUpdateTime(new Date()); - logger.info("updateUserIP : {}", userIpVoLowerCase); - userIpMapper.updateUserIP(userIpVoLowerCase); - } - - /** - * deleteUserIP - * - * @param id - */ - @Override - @Transactional(rollbackFor = Throwable.class) - public void deleteUserIP(Integer id) throws ConfigurationException { - logger.info("deleteUserIP : id:{}", id); - if (StringUtils.isBlank(id.toString())) { - throw new ConfigurationException("id couldn't be empty "); - } - userIpMapper.deleteUserIP(id); - } - - /** - * Query IP Collection - * - * @return List - * @param user - * @param creator - * @param pageNow - * @param pageSize - */ - @Override - public Map queryUserIPList( - String user, String creator, Integer pageNow, Integer pageSize) { - Map result = new HashMap<>(2); - List userIpVos = null; - PageHelper.startPage(pageNow, pageSize); - try { - userIpVos = userIpMapper.queryUserIPList(user, creator); - } finally { - PageHelper.clearPage(); - } - PageInfo pageInfo = new PageInfo<>(userIpVos); - result.put("userIpList", userIpVos); - result.put(JobRequestConstants.TOTAL_PAGE(), pageInfo.getTotal()); - return result; - } - - private void dataProcessing(UserIpVo userIpVo) throws ConfigurationException { - // Ip rule verification - String ipList = userIpVo.getIpList(); - if (!ipList.equals("*")) { - String[] split = ipList.split(","); - StringJoiner joiner = new StringJoiner(","); - Arrays.stream(split) - .distinct() - .filter(ipStr -> !CommonUtils.ipCheck(ipStr)) - .forEach(joiner::add); - if (StringUtils.isNotBlank(joiner.toString())) { - throw new ConfigurationException(joiner + ",Illegal IP address "); - } - } - } - - @Override - public boolean userExists(String user, String creator) { - Map resultMap = - queryUserIPList(user.toLowerCase(), creator.toLowerCase(), 1, 20); - Object userIpList = resultMap.getOrDefault(JobRequestConstants.TOTAL_PAGE(), 0); - return Integer.parseInt(String.valueOf(userIpList)) > 0; - } - - @Override - public UserIpVo queryUserIP(String user, String creator) { - return userIpMapper.queryUserIP(user, creator); - } - - private UserIpVo toLowerCase(UserIpVo userIpVo) { - userIpVo.setCreator(userIpVo.getCreator().toLowerCase()); - userIpVo.setUser(userIpVo.getUser().toLowerCase()); - return userIpVo; - } -} diff --git a/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/service/impl/UserIpServiceImpl.java b/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/service/impl/UserIpServiceImpl.java deleted file mode 100644 index 40128cc5be..0000000000 --- a/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/service/impl/UserIpServiceImpl.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * 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.service.impl; - -import org.apache.linkis.configuration.entity.UserIpVo; -import org.apache.linkis.configuration.service.UserIpConfigService; -import org.apache.linkis.configuration.service.UserIpService; -import org.apache.linkis.governance.common.protocol.conf.UserIpRequest; -import org.apache.linkis.governance.common.protocol.conf.UserIpResponse; -import org.apache.linkis.rpc.Sender; -import org.apache.linkis.rpc.message.annotation.Receiver; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -@Service -public class UserIpServiceImpl implements UserIpService { - - private static final Logger logger = LoggerFactory.getLogger(UserIpService.class); - - @Autowired private UserIpConfigService userIpConfigService; - - @Receiver - @Override - public UserIpResponse getUserIpData(UserIpRequest request, Sender sender) { - UserIpVo userIpVo = userIpConfigService.queryUserIP(request.user(), request.creator()); - if (null == userIpVo) { - logger.warn( - "UserIpCache user {} creator {} data loading failed", request.user(), request.creator()); - return new UserIpResponse(request.user(), request.creator(), ""); - } else { - return new UserIpResponse(userIpVo.getUser(), userIpVo.getCreator(), userIpVo.getIpList()); - } - } -} diff --git a/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/util/ConfigurationConfiguration.java b/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/util/ConfigurationConfiguration.java index b69f20cdb5..515d8320d4 100644 --- a/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/util/ConfigurationConfiguration.java +++ b/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/util/ConfigurationConfiguration.java @@ -30,12 +30,6 @@ public class ConfigurationConfiguration { public static final String COPYKEYTOKEN = CommonVars$.MODULE$.apply("wds.linkis.configuration.copykey.token", "e8724-e").getValue(); - public static final String IPCHECK = - CommonVars$.MODULE$ - .apply( - "linkis.configuration.ipcheck.pattern", - "^(\\d|[1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5])(\\.(\\d|[1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5])){3}$") - .getValue(); static { PERMIT_LABEL_TYPE.add(new UserCreatorLabel()); diff --git a/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/util/HttpsUtil.java b/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/util/HttpsUtil.java deleted file mode 100644 index 57fd7035da..0000000000 --- a/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/util/HttpsUtil.java +++ /dev/null @@ -1,114 +0,0 @@ -/* - * 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.util; - -import org.apache.linkis.common.conf.Configuration; -import org.apache.linkis.configuration.constant.Constants; -import org.apache.linkis.httpclient.dws.authentication.TokenAuthenticationStrategy; -import org.apache.linkis.httpclient.dws.config.DWSClientConfig; -import org.apache.linkis.httpclient.dws.config.DWSClientConfigBuilder; -import org.apache.linkis.ujes.client.UJESClientImpl; -import org.apache.linkis.ujes.client.request.EmsListAction; -import org.apache.linkis.ujes.client.response.EmsListResult; - -import org.apache.commons.collections.MapUtils; -import org.apache.commons.lang3.StringUtils; - -import java.io.IOException; -import java.util.HashMap; -import java.util.Map; -import java.util.concurrent.TimeUnit; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class HttpsUtil { - - private static final Logger logger = LoggerFactory.getLogger(HttpsUtil.class); - - public static DWSClientConfig dwsClientConfig = createClientConfig(null, null); - - public static UJESClientImpl client = new UJESClientImpl(dwsClientConfig); - - public static Map sendHttp(String url, Map properties) - throws IOException { - if (null == dwsClientConfig) { - dwsClientConfig = createClientConfig(url, properties); - } - if (null == client) { - client = new UJESClientImpl(dwsClientConfig); - } - EmsListAction build = EmsListAction.newBuilder().setUser("hadoop").build(); - EmsListResult result = client.listECM(build); - return result.getResultMap(); - } - - private static DWSClientConfig createClientConfig(String url, Map properties) { - String realUrl = ""; - if (StringUtils.isBlank(url)) { - realUrl = Configuration.getGateWayURL(); - } else { - realUrl = url; - } - Map parms = new HashMap<>(); - if (MapUtils.isNotEmpty(properties)) { - parms = properties; - } - int maxConnection = - (int) - parms.getOrDefault( - Constants.CONNECTION_MAX_SIZE_SHORT_NAME(), - Constants.CONNECTION_MAX_SIZE().getValue()); - int connectTimeout = - (int) - parms.getOrDefault( - Constants.CONNECTION_TIMEOUT_SHORT_NAME(), - Constants.CONNECTION_TIMEOUT().getValue()); - int readTimeout = - (int) - parms.getOrDefault( - Constants.CONNECTION_READ_TIMEOUT_SHORT_NAME(), - Constants.CONNECTION_READ_TIMEOUT().getValue()); - String tokenKey = - (String) - parms.getOrDefault( - Constants.AUTH_TOKEN_KEY_SHORT_NAME(), Constants.AUTH_TOKEN_KEY().getValue()); - String tokenValue = - (String) - parms.getOrDefault( - Constants.AUTH_TOKEN_VALUE_SHORT_NAME(), Constants.AUTH_TOKEN_VALUE().getValue()); - - DWSClientConfig clientConfig = - ((DWSClientConfigBuilder) - (DWSClientConfigBuilder.newBuilder() - .addServerUrl(realUrl) - .connectionTimeout(connectTimeout) - .discoveryEnabled(false) - .discoveryFrequency(1, TimeUnit.MINUTES) - .loadbalancerEnabled(false) - .maxConnectionSize(maxConnection) - .retryEnabled(false) - .readTimeout(readTimeout) - .setAuthenticationStrategy(new TokenAuthenticationStrategy()) - .setAuthTokenKey(tokenKey) - .setAuthTokenValue(tokenValue))) - .setDWSVersion("v1") - .build(); - return clientConfig; - } -} diff --git a/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/util/LabelEntityParser.java b/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/util/LabelEntityParser.java index cfd180e0fa..a808dcb0b4 100644 --- a/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/util/LabelEntityParser.java +++ b/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/util/LabelEntityParser.java @@ -62,7 +62,7 @@ public static ArrayList