This is an automated email from the ASF dual-hosted git repository. hefengen pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/shenyu.git
The following commit(s) were added to refs/heads/master by this push: new 195356c1c8 [tye:bugfix]fix namespace bugs (#5823) 195356c1c8 is described below commit 195356c1c8c218ed87f01918292c8f7a57160d49 Author: aias00 <liuhon...@apache.org> AuthorDate: Thu Dec 5 19:43:01 2024 +0800 [tye:bugfix]fix namespace bugs (#5823) * [type:bugfix] fix namespace bugs * [type:bugfix] fix namespace bugs * [type:bugfix] fix namespace bugs * [type:bugfix] fix http example InaccessibleObjectException * [type:bugfix] fix namespace bugs * [type:bugfix] fix namespace bugs * [type:bugfix] fix namespace bugs, debug * [type:bugfix] fix namespace bugs, debug * [type:bugfix] fix namespace bugs * [type:bugfix] fix namespace bugs * [type:bugfix] fix namespace bugs * [type:bugfix] fix namespace bugs, debug * [type:bugfix] fix namespace bugs, debug * [type:bugfix] fix namespace bugs, debug * [type:bugfix] fix namespace bugs * [type:bugfix] fix namespace bugs, debug * [type:bugfix] fix namespace bugs, debug * [type:bugfix] fix namespace bugs, debug * [type:bugfix] fix namespace bugs * [type:bugfix] fix namespace bugs * [type:bugfix] fix namespace bugs * [type:bugfix] fix namespace bugs * Revert "[type:bugfix] fix namespace bugs" This reverts commit f17369a99a596551d5da88e2f0dc75d641b77920. * Revert "Revert "[type:bugfix] fix namespace bugs"" This reverts commit a412cbc9234f2356452e1409f87bac477e54f479. * [type:bugfix] fix namespace bugs * [type:bugfix] fix namespace bugs * [type:bugfix] fix namespace bugs * [type:bugfix] fix namespace bugs * [type:bugfix] fix namespace bugs * [type:bugfix] fix namespace bugs * [type:fix] namespace selector copy * [type:bugfix] fix namespace bugs * [type:bugfix] fix namespace bugs * [type:bugfix] fix namespace bugs * Revert "[type:bugfix] fix namespace bugs" This reverts commit a6daa49447c0d4ee71c15bb883f6830833534cab. * [type:bugfix] fix namespace bugs * [type:bugfix] fix namespace bugs * [type:bugfix] fix namespace bugs * [type:bugfix] fix namespace bugs * [type:bugfix] fix namespace bugs * [type:bugfix] fix namespace bugs --------- Co-authored-by: zhengpeng <847850...@qq.com> Co-authored-by: xiaoyu <xia...@apache.org> --- .../controller/NamespacePluginController.java | 14 ++++++- .../shenyu/admin/controller/PluginController.java | 12 ------ .../admin/controller/SelectorController.java | 8 ++-- .../admin/mapper/NamespacePluginRelMapper.java | 22 +++++++++-- .../apache/shenyu/admin/model/entity/PluginDO.java | 2 +- .../admin/service/NamespacePluginService.java | 2 + .../apache/shenyu/admin/service/PluginService.java | 8 ---- .../service/impl/NamespacePluginServiceImpl.java | 12 +++++- .../admin/service/impl/PluginServiceImpl.java | 11 ------ .../mappers/namespace-plugin-rel-sqlmap.xml | 41 +++++++++++++++++++ .../shenyu/e2e/client/admin/AdminClient.java | 8 +++- .../shenyu/e2e/model/data/NamespaceSyncData.java | 46 ++++++++++++++++++++++ shenyu-examples/shenyu-examples-http/Dockerfile | 2 +- 13 files changed, 144 insertions(+), 44 deletions(-) diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/controller/NamespacePluginController.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/controller/NamespacePluginController.java index a99952141d..1d8a06827b 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/controller/NamespacePluginController.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/controller/NamespacePluginController.java @@ -139,7 +139,7 @@ public class NamespacePluginController implements PagedController<NamespacePlugi * @param pluginId pluginId. * @return {@linkplain ShenyuAdminResult} */ - @PutMapping("/{namespaceId}/{pluginId}") + @PostMapping("/{namespaceId}/{pluginId}") @RequiresPermissions("system:plugin:edit") public ShenyuAdminResult generateNamespacePlugin(@Existed(message = "namespace is not exist", provider = NamespaceMapper.class) @PathVariable("namespaceId") final String namespaceId, @@ -237,6 +237,18 @@ public class NamespacePluginController implements PagedController<NamespacePlugi public ShenyuAdminResult activePluginSnapshot(final String namespaceId) { return ShenyuAdminResult.success(namespacePluginService.activePluginSnapshot(namespaceId)); } + + /** + * query plugins by namespace. + * + * @param namespace namespace. + * @return {@linkplain ShenyuAdminResult} + */ + @GetMapping("/listByNamespace") + public ShenyuAdminResult queryPluginsByNamespace(final String namespace) { + List<PluginData> pluginDataList = namespacePluginService.listByNamespace(namespace); + return ShenyuAdminResult.success(ShenyuResultMessage.QUERY_SUCCESS, pluginDataList); + } @Override public PageService<NamespacePluginQueryCondition, NamespacePluginVO> pageService() { diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/controller/PluginController.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/controller/PluginController.java index 0331eba53c..fa02803166 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/controller/PluginController.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/controller/PluginController.java @@ -88,18 +88,6 @@ public class PluginController implements PagedController<PluginQueryCondition, P return ShenyuAdminResult.success(ShenyuResultMessage.QUERY_SUCCESS, pluginDataList); } - /** - * query plugins by namespace. - * - * @param namespace namespace. - * @return {@linkplain ShenyuAdminResult} - */ - @GetMapping("/listByNamespace") - public ShenyuAdminResult queryPluginsByNamespace(final String namespace) { - List<PluginData> pluginDataList = pluginService.listByNamespace(namespace); - return ShenyuAdminResult.success(ShenyuResultMessage.QUERY_SUCCESS, pluginDataList); - } - /** * detail plugin. * diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/controller/SelectorController.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/controller/SelectorController.java index c2952ac0da..69d7d72c0a 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/controller/SelectorController.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/controller/SelectorController.java @@ -20,7 +20,6 @@ package org.apache.shenyu.admin.controller; import jakarta.validation.Valid; import jakarta.validation.constraints.NotNull; import org.apache.shenyu.admin.aspect.annotation.RestApi; -import org.apache.shenyu.admin.mapper.NamespaceMapper; import org.apache.shenyu.admin.mapper.SelectorMapper; import org.apache.shenyu.admin.model.dto.BatchCommonDTO; import org.apache.shenyu.admin.model.dto.BatchNamespaceCommonDTO; @@ -71,14 +70,15 @@ public class SelectorController implements PagedController<SelectorQueryConditio public AdminResult<CommonPager<SelectorVO>> querySelectors(final String pluginId, final String name, @RequestParam @NotNull final Integer currentPage, @RequestParam @NotNull final Integer pageSize, - @Valid @Existed(message = "namespaceId is not existed", - provider = NamespaceMapper.class) final String namespaceId + @RequestParam(value = "namespaceId", required = false) final String namespaceId ) { final SelectorQueryCondition condition = new SelectorQueryCondition(); condition.setUserId(SessionUtil.visitor().getUserId()); condition.setPlugin(ListUtil.of(pluginId)); condition.setKeyword(name); - condition.setNamespaceId(namespaceId); + if (namespaceId != null) { + condition.setNamespaceId(namespaceId); + } return searchAdaptor(new PageCondition<>(currentPage, pageSize, condition)); } diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/NamespacePluginRelMapper.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/NamespacePluginRelMapper.java index 69f69b0717..ca5603d4a1 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/NamespacePluginRelMapper.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/NamespacePluginRelMapper.java @@ -103,8 +103,7 @@ public interface NamespacePluginRelMapper extends ExistProvider { * @return existed */ Boolean nameExistedExclude(@Param("name") Serializable name, @Param("exclude") List<String> exclude, @Param("namespaceId") String namespaceId); - - + /** * update selective plugin. * @@ -112,15 +111,32 @@ public interface NamespacePluginRelMapper extends ExistProvider { * @return rows int */ int updateSelective(NamespacePluginRelDO namespacePluginRelDO); + + /** + * update plugin by namespaceId and pluginId. + * + * @param namespacePluginRelDO {@linkplain NamespacePluginRelDO} + * @return rows int + */ + int updateByNamespaceIdAndPluginId(NamespacePluginRelDO namespacePluginRelDO); /** - * select plugin by ids and namespaceId. + * select plugin by ids. * * @param ids primary keys. * @return {@linkplain NamespacePluginRelDO} */ List<NamespacePluginVO> selectByIds(List<String> ids); + /** + * select plugin by namespaceId and pluginIds. + * + * @param namespaceId namespaceId. + * @param pluginIds pluginIds. + * @return {@linkplain NamespacePluginRelDO} + */ + List<NamespacePluginVO> selectByNamespaceIdAndPluginIds(String namespaceId, List<String> pluginIds); + /** * delete plugin by ids and namespaceId. diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/entity/PluginDO.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/entity/PluginDO.java index f3275625ed..4963829db6 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/entity/PluginDO.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/entity/PluginDO.java @@ -21,7 +21,7 @@ import org.apache.commons.lang3.StringUtils; import org.apache.shenyu.admin.model.dto.PluginDTO; import org.apache.shenyu.admin.model.vo.NamespacePluginVO; import org.apache.shenyu.common.utils.UUIDUtils; -import org.opengauss.util.Base64; +import org.apache.shiro.codec.Base64; import java.sql.Timestamp; import java.util.Arrays; diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/NamespacePluginService.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/NamespacePluginService.java index 99c4ec50c4..b3de7bf277 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/NamespacePluginService.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/NamespacePluginService.java @@ -152,4 +152,6 @@ public interface NamespacePluginService extends PageService<NamespacePluginQuery * @return config import result */ ConfigImportResult importData(List<PluginDTO> pluginList); + + List<PluginData> listByNamespace(String namespace); } diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/PluginService.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/PluginService.java index 4ee3cc9f5f..73cf6f6fb5 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/PluginService.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/PluginService.java @@ -79,14 +79,6 @@ public interface PluginService extends PageService<PluginQueryCondition, PluginV * @return the list */ List<PluginData> listAll(); - - /** - * List by namespace list. - * - * @param namespace the namespace - * @return the list - */ - List<PluginData> listByNamespace(String namespace); /** * List all vo list. diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/NamespacePluginServiceImpl.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/NamespacePluginServiceImpl.java index 007d5e5868..95903af87f 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/NamespacePluginServiceImpl.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/NamespacePluginServiceImpl.java @@ -123,7 +123,7 @@ public class NamespacePluginServiceImpl implements NamespacePluginService { @Override @Transactional(rollbackFor = Exception.class) public String delete(final List<String> ids) { - // select plugin id. + // select namespace plugin by ns plugin rel Ids. List<NamespacePluginVO> namespacePluginVOS = this.namespacePluginRelMapper.selectByIds(ids); if (CollectionUtils.isEmpty(namespacePluginVOS)) { return AdminConstants.SYS_PLUGIN_ID_NOT_EXIST; @@ -246,4 +246,14 @@ public class NamespacePluginServiceImpl implements NamespacePluginService { public ConfigImportResult importData(final List<PluginDTO> pluginList) { return null; } + + @Override + public List<PluginData> listByNamespace(final String namespace) { + List<NamespacePluginVO> namespacePluginList = namespacePluginRelMapper.selectAllByNamespaceId(namespace); + if (CollectionUtils.isEmpty(namespacePluginList)) { + return Lists.newArrayList(); + } + List<String> pluginIds = namespacePluginList.stream().map(NamespacePluginVO::getPluginId).distinct().collect(Collectors.toList()); + return ListUtil.map(pluginMapper.selectByIds(pluginIds), PluginTransfer.INSTANCE::mapToData); + } } diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/PluginServiceImpl.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/PluginServiceImpl.java index 51acd2fc7f..03ef57e5fb 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/PluginServiceImpl.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/PluginServiceImpl.java @@ -35,7 +35,6 @@ import org.apache.shenyu.admin.model.page.PageResultUtils; import org.apache.shenyu.admin.model.query.PluginQuery; import org.apache.shenyu.admin.model.query.PluginQueryCondition; import org.apache.shenyu.admin.model.result.ConfigImportResult; -import org.apache.shenyu.admin.model.vo.NamespacePluginVO; import org.apache.shenyu.admin.model.vo.PluginHandleVO; import org.apache.shenyu.admin.model.vo.PluginSnapshotVO; import org.apache.shenyu.admin.model.vo.PluginVO; @@ -211,16 +210,6 @@ public class PluginServiceImpl implements PluginService { return ListUtil.map(pluginMapper.selectAll(), PluginTransfer.INSTANCE::mapToData); } - @Override - public List<PluginData> listByNamespace(final String namespace) { - List<NamespacePluginVO> namespacePluginList = namespacePluginRelMapper.selectAllByNamespaceId(namespace); - if (CollectionUtils.isEmpty(namespacePluginList)) { - return Lists.newArrayList(); - } - List<String> pluginIds = namespacePluginList.stream().map(NamespacePluginVO::getPluginId).distinct().collect(Collectors.toList()); - return ListUtil.map(pluginMapper.selectByIds(pluginIds), PluginTransfer.INSTANCE::mapToData); - } - @Override public List<PluginVO> listAllData() { // plugin handle diff --git a/shenyu-admin/src/main/resources/mappers/namespace-plugin-rel-sqlmap.xml b/shenyu-admin/src/main/resources/mappers/namespace-plugin-rel-sqlmap.xml index 9aee928ec3..b0a7354da2 100644 --- a/shenyu-admin/src/main/resources/mappers/namespace-plugin-rel-sqlmap.xml +++ b/shenyu-admin/src/main/resources/mappers/namespace-plugin-rel-sqlmap.xml @@ -224,6 +224,26 @@ WHERE id = #{id, jdbcType=VARCHAR} </update> + <update id="updateByNamespaceIdAndPluginId" parameterType="org.apache.shenyu.admin.model.entity.NamespacePluginRelDO"> + UPDATE namespace_plugin_rel + <set> + <if test="dateUpdated != null"> + date_updated = #{dateUpdated, jdbcType=TIMESTAMP}, + </if> + <if test="config != null"> + config = #{config, jdbcType=VARCHAR}, + </if> + <if test="sort != null"> + sort = #{sort, jdbcType=INTEGER}, + </if> + <if test="enabled != null"> + enabled = #{enabled, jdbcType=TINYINT}, + </if> + </set> + WHERE namespace_id = #{namespaceId, jdbcType=VARCHAR} + AND plugin_id = #{pluginId, jdbcType=VARCHAR} + </update> + <select id="selectByIds" parameterType="java.util.List" resultType="org.apache.shenyu.admin.model.vo.NamespacePluginVO"> SELECT npr.id AS id, @@ -243,6 +263,27 @@ </foreach> </select> + <select id="selectByNamespaceIdAndPluginIds" parameterType="java.util.List" resultType="org.apache.shenyu.admin.model.vo.NamespacePluginVO"> + SELECT + npr.id AS id, + npr.namespace_id AS namespaceId, + npr.plugin_id AS pluginId, + npr.config AS config, + npr.sort AS sort, + npr.enabled AS enabled, + npr.date_created AS dateCreated, + npr.date_updated AS dateUpdated, + p.role AS role, + p.NAME AS NAME + FROM namespace_plugin_rel npr LEFT JOIN plugin p ON npr.plugin_id = p.id + WHERE + npr.namespace_id = #{namespaceId, jdbcType=VARCHAR} + AND npr.plugin_id IN + <foreach item="pluginId" collection="pluginIds" open="(" separator="," close=")"> + #{pluginId, jdbcType=VARCHAR} + </foreach> + </select> + <delete id="deleteByIds" parameterType="java.util.List"> DELETE FROM namespace_plugin_rel WHERE id IN diff --git a/shenyu-e2e/shenyu-e2e-client/src/main/java/org/apache/shenyu/e2e/client/admin/AdminClient.java b/shenyu-e2e/shenyu-e2e-client/src/main/java/org/apache/shenyu/e2e/client/admin/AdminClient.java index 1056c119ba..6bac1d572b 100644 --- a/shenyu-e2e/shenyu-e2e-client/src/main/java/org/apache/shenyu/e2e/client/admin/AdminClient.java +++ b/shenyu-e2e/shenyu-e2e-client/src/main/java/org/apache/shenyu/e2e/client/admin/AdminClient.java @@ -32,6 +32,7 @@ import org.apache.shenyu.e2e.common.NameUtils; import org.apache.shenyu.e2e.model.Plugin; import org.apache.shenyu.e2e.model.ShenYuResult; import org.apache.shenyu.e2e.model.data.BindingData; +import org.apache.shenyu.e2e.model.data.NamespaceSyncData; import org.apache.shenyu.e2e.model.data.QueryCondition; import org.apache.shenyu.e2e.model.data.ResourceData; import org.apache.shenyu.e2e.model.data.RuleData; @@ -543,8 +544,11 @@ public class AdminClient extends BaseClient { * sync all plugin. */ public void syncPluginAll() { - HttpEntity<SearchCondition> entity = new HttpEntity<>(basicAuth); - template.postForEntity(baseURL + "/plugin-template/syncPluginAll", entity, ShenYuResult.class); + NamespaceSyncData namespaceSyncData = new NamespaceSyncData(); + namespaceSyncData.setNamespaceId(SYS_DEFAULT_NAMESPACE_NAMESPACE_ID); + basicAuth.add("Content-Type", MediaType.APPLICATION_JSON_VALUE); + HttpEntity<NamespaceSyncData> entity = new HttpEntity<>(namespaceSyncData, basicAuth); + template.postForEntity(baseURL + "/namespace-plugin/syncPluginAll", entity, ShenYuResult.class); log.warn("admin syncPluginAll"); } diff --git a/shenyu-e2e/shenyu-e2e-common/src/main/java/org/apache/shenyu/e2e/model/data/NamespaceSyncData.java b/shenyu-e2e/shenyu-e2e-common/src/main/java/org/apache/shenyu/e2e/model/data/NamespaceSyncData.java new file mode 100644 index 0000000000..30c4084fc3 --- /dev/null +++ b/shenyu-e2e/shenyu-e2e-common/src/main/java/org/apache/shenyu/e2e/model/data/NamespaceSyncData.java @@ -0,0 +1,46 @@ +/* + * 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.shenyu.e2e.model.data; + +import java.io.Serializable; + +public class NamespaceSyncData implements Serializable { + /** + * namespaceId. + */ + private String namespaceId; + + /** + * Gets the value of namespaceId. + * + * @return the value of namespaceId + */ + public String getNamespaceId() { + return namespaceId; + } + + /** + * Sets the namespaceId. + * + * @param namespaceId namespaceId + */ + public void setNamespaceId(final String namespaceId) { + this.namespaceId = namespaceId; + } + +} diff --git a/shenyu-examples/shenyu-examples-http/Dockerfile b/shenyu-examples/shenyu-examples-http/Dockerfile index d6b53f4fb1..c7ac7d3bc2 100644 --- a/shenyu-examples/shenyu-examples-http/Dockerfile +++ b/shenyu-examples/shenyu-examples-http/Dockerfile @@ -26,4 +26,4 @@ ADD target/${APP_NAME}.jar ${LOCAL_PATH} WORKDIR ${LOCAL_PATH} EXPOSE 8189 -CMD java -jar ${APP_NAME}.jar +CMD java --add-opens java.base/java.lang=ALL-UNNAMED -jar ${APP_NAME}.jar