From cb6e4ddd8108c4865d04c27d7fa8a4c6ab2b4f3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=98xcsnx=E2=80=99?= <‘1192709687@qq.com’> Date: Sun, 21 Jul 2024 14:35:44 +0800 Subject: [PATCH 01/61] commit --- db/upgrade/2.6.1-upgrade-2.7.0-mysql.sql | 3 + .../shenyu/admin/model/entity/SelectorDO.java | 84 +++++++++++++------ .../model/query/SelectorConditionQuery.java | 31 ++++++- .../admin/model/query/SelectorQuery.java | 33 +++++++- .../model/query/SelectorQueryCondition.java | 24 ++++++ .../service/impl/SelectorServiceImpl.java | 1 + .../resources/mappers/selector-sqlmap.xml | 20 ++++- 7 files changed, 161 insertions(+), 35 deletions(-) diff --git a/db/upgrade/2.6.1-upgrade-2.7.0-mysql.sql b/db/upgrade/2.6.1-upgrade-2.7.0-mysql.sql index 289a9fc5cceb..62c9522dae0d 100755 --- a/db/upgrade/2.6.1-upgrade-2.7.0-mysql.sql +++ b/db/upgrade/2.6.1-upgrade-2.7.0-mysql.sql @@ -165,3 +165,6 @@ INSERT INTO `shenyu`.`permission` (`id`, `object_id`, `resource_id`, `date_creat INSERT INTO `shenyu`.`permission` (`id`, `object_id`, `resource_id`, `date_created`, `date_updated`) VALUES ('1792779493541343265', '1346358560427216896', '1792749362445840484', '2024-06-25 20:00:00.000', '2024-06-25 20:00:00.000'); INSERT INTO `shenyu`.`permission` (`id`, `object_id`, `resource_id`, `date_created`, `date_updated`) VALUES ('1792779493541343266', '1346358560427216896', '1792749362445840485', '2024-06-25 20:00:00.000', '2024-06-25 20:00:00.000'); INSERT INTO `shenyu`.`permission` (`id`, `object_id`, `resource_id`, `date_created`, `date_updated`) VALUES ('1792779493541343267', '1346358560427216896', '1792749362445840486', '2024-06-25 20:00:00.000', '2024-06-25 20:00:00.000'); + + +ALTER TABLE `shenyu`.`selector` ADD COLUMN `namespace_id` varchar(50) NULL COMMENT 'namespaceId' AFTER `match_restful`; \ No newline at end of file diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/entity/SelectorDO.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/entity/SelectorDO.java index 592a85f98e61..0748d0dd0323 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/entity/SelectorDO.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/entity/SelectorDO.java @@ -82,12 +82,17 @@ public final class SelectorDO extends BaseDO { * handle. */ private String handle; - + /** * match restful. */ private Boolean matchRestful; + /** + * namespaceId. + */ + private String namespaceId; + public SelectorDO() { } @@ -100,7 +105,8 @@ public SelectorDO(final String pluginId, final Boolean loged, final Boolean continued, final String handle, - final Boolean matchRestful) { + final Boolean matchRestful, + final String namespaceId) { this.pluginId = pluginId; this.name = name; this.matchMode = matchMode; @@ -111,8 +117,10 @@ public SelectorDO(final String pluginId, this.continued = continued; this.handle = handle; this.matchRestful = matchRestful; + this.namespaceId = namespaceId; } + /** * Gets the value of pluginId. * @@ -274,7 +282,7 @@ public String getHandle() { public void setHandle(final String handle) { this.handle = handle; } - + /** * get match restful. * @@ -283,7 +291,7 @@ public void setHandle(final String handle) { public Boolean getMatchRestful() { return matchRestful; } - + /** * set match restful. * @@ -292,7 +300,25 @@ public Boolean getMatchRestful() { public void setMatchRestful(final Boolean matchRestful) { this.matchRestful = matchRestful; } - + + /** + * get namespaceId. + * + * @return namespaceId + */ + public String getNamespaceId() { + return namespaceId; + } + + /** + * set namespaceId. + * + * @param namespaceId namespaceId + */ + public void setNamespaceId(final String namespaceId) { + this.namespaceId = namespaceId; + } + /** * builder method. * @@ -303,7 +329,7 @@ public static SelectorDO.SelectorDOBuilder builder() { } @Override - public boolean equals(final Object o) { + public boolean equals(Object o) { if (this == o) { return true; } @@ -314,21 +340,15 @@ public boolean equals(final Object o) { return false; } SelectorDO that = (SelectorDO) o; - return Objects.equals(pluginId, that.pluginId) - && Objects.equals(name, that.name) - && Objects.equals(matchMode, that.matchMode) - && Objects.equals(type, that.type) - && Objects.equals(sort, that.sort) - && Objects.equals(enabled, that.enabled) - && Objects.equals(loged, that.loged) - && Objects.equals(continued, that.continued) - && Objects.equals(handle, that.handle) - && Objects.equals(matchRestful, that.matchRestful); + return Objects.equals(pluginId, that.pluginId) && Objects.equals(name, that.name) && Objects.equals(matchMode, that.matchMode) + && Objects.equals(type, that.type) && Objects.equals(sort, that.sort) && Objects.equals(enabled, that.enabled) + && Objects.equals(loged, that.loged) && Objects.equals(continued, that.continued) && Objects.equals(handle, that.handle) + && Objects.equals(matchRestful, that.matchRestful) && Objects.equals(namespaceId, that.namespaceId); } @Override public int hashCode() { - return Objects.hash(super.hashCode(), pluginId, name, matchMode, type, sort, enabled, loged, continued, handle, matchRestful); + return Objects.hash(super.hashCode(), pluginId, name, matchMode, type, sort, enabled, loged, continued, handle, matchRestful, namespaceId); } /** @@ -370,9 +390,9 @@ public static SelectorDO buildSelectorDO(final SelectorDTO selectorDTO) { /** * Trans from selector data. * - * @param selectorDO the selector do - * @param pluginName the plugin name - * @param conditionDataList the condition data list + * @param selectorDO the selector do + * @param pluginName the plugin name + * @param conditionDataList the condition data list * @param beforeConditionDataList before condition data list * @return the selector data */ @@ -395,12 +415,12 @@ public static SelectorData transFrom(final SelectorDO selectorDO, final String p .beforeConditionList(beforeConditionDataList) .build(); } - + /** * selector data transform. * - * @param selectorDO selector entity - * @param pluginName plugin name + * @param selectorDO selector entity + * @param pluginName plugin name * @param conditionDataList condition data list * @return the selector data */ @@ -433,9 +453,11 @@ public static final class SelectorDOBuilder { private Boolean continued; private String handle; - + private Boolean matchRestful; + private String namespaceId; + private SelectorDOBuilder() { } @@ -570,7 +592,7 @@ public SelectorDOBuilder handle(final String handle) { this.handle = handle; return this; } - + /** * match restful. * @@ -582,6 +604,17 @@ public SelectorDOBuilder matchRestful(final Boolean matchRestful) { return this; } + /** + * namespaceId. + * + * @param namespaceId namespaceId + * @return SelectorDOBuilder + */ + public SelectorDOBuilder namespaceId(final String namespaceId) { + this.namespaceId = namespaceId; + return this; + } + /** * build method. * @@ -602,6 +635,7 @@ public SelectorDO build() { selectorDO.setContinued(continued); selectorDO.setHandle(handle); selectorDO.setMatchRestful(matchRestful); + selectorDO.setNamespaceId(namespaceId); return selectorDO; } } diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/query/SelectorConditionQuery.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/query/SelectorConditionQuery.java index fa12f0149664..c1be0d227166 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/query/SelectorConditionQuery.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/query/SelectorConditionQuery.java @@ -32,6 +32,11 @@ public class SelectorConditionQuery implements Serializable { */ private String selectorId; + /** + * namespace id. + */ + private String namespaceId; + public SelectorConditionQuery() { } @@ -57,20 +62,38 @@ public void setSelectorId(final String selectorId) { this.selectorId = selectorId; } + /** + * Gets the value of name. + * + * @return the value of name + */ + public String getNamespaceId() { + return namespaceId; + } + + /** + * Sets the namespaceId. + * + * @param namespaceId namespaceId + */ + public void setNamespaceId(final String namespaceId) { + this.namespaceId = namespaceId; + } + @Override - public boolean equals(final Object o) { + public boolean equals(Object o) { if (this == o) { return true; } - if (!(o instanceof SelectorConditionQuery)) { + if (o == null || getClass() != o.getClass()) { return false; } SelectorConditionQuery that = (SelectorConditionQuery) o; - return Objects.equals(selectorId, that.selectorId); + return Objects.equals(selectorId, that.selectorId) && Objects.equals(namespaceId, that.namespaceId); } @Override public int hashCode() { - return Objects.hash(selectorId); + return Objects.hash(selectorId, namespaceId); } } diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/query/SelectorQuery.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/query/SelectorQuery.java index 12177eedac8c..89dd5d235d4e 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/query/SelectorQuery.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/query/SelectorQuery.java @@ -18,6 +18,7 @@ package org.apache.shenyu.admin.model.query; import java.util.List; + import org.apache.shenyu.admin.model.page.PageParameter; import java.util.Objects; @@ -49,6 +50,11 @@ public class SelectorQuery extends FilterQuery { */ private PageParameter pageParameter; + /** + * namespace id. + */ + private String namespaceId; + public SelectorQuery() { } @@ -136,23 +142,42 @@ public void setPageParameter(final PageParameter pageParameter) { this.pageParameter = pageParameter; } + /** + * Gets the value of name. + * + * @return the value of name + */ + public String getNamespaceId() { + return namespaceId; + } + + /** + * Sets the namespaceId. + * + * @param namespaceId namespaceId + */ + public void setNamespaceId(final String namespaceId) { + this.namespaceId = namespaceId; + } + @Override - public boolean equals(final Object o) { + public boolean equals(Object o) { if (this == o) { return true; } - if (!(o instanceof SelectorQuery)) { + if (o == null || getClass() != o.getClass()) { return false; } if (!super.equals(o)) { return false; } SelectorQuery that = (SelectorQuery) o; - return Objects.equals(pluginId, that.pluginId) && Objects.equals(name, that.name) && Objects.equals(pageParameter, that.pageParameter); + return Objects.equals(pluginId, that.pluginId) && Objects.equals(pluginIds, that.pluginIds) && Objects.equals(name, that.name) + && Objects.equals(pageParameter, that.pageParameter) && Objects.equals(namespaceId, that.namespaceId); } @Override public int hashCode() { - return Objects.hash(super.hashCode(), pluginId, name, pageParameter); + return Objects.hash(super.hashCode(), pluginId, pluginIds, name, pageParameter, namespaceId); } } diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/query/SelectorQueryCondition.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/query/SelectorQueryCondition.java index 5999314a2757..aa73bd87ec54 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/query/SelectorQueryCondition.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/query/SelectorQueryCondition.java @@ -43,6 +43,11 @@ public class SelectorQueryCondition extends BaseExcludedSearchCondition implemen * selector from plugin. */ private List plugin; + + /** + * namespace id. + */ + private String namespaceId; /** * user id. @@ -125,4 +130,23 @@ public List getPlugin() { public void setPlugin(final List plugin) { this.plugin = plugin; } + + /** + * Gets the value of name. + * + * @return the value of name + */ + public String getNamespaceId() { + return namespaceId; + } + + /** + * Sets the namespaceId. + * + * @param namespaceId namespaceId + */ + public void setNamespaceId(final String namespaceId) { + this.namespaceId = namespaceId; + } + } diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/SelectorServiceImpl.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/SelectorServiceImpl.java index 4483c5a807ab..604ad1310f48 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/SelectorServiceImpl.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/SelectorServiceImpl.java @@ -151,6 +151,7 @@ public void doConditionPreProcessing(final SelectorQueryCondition condition) { @Override public List searchByCondition(final SelectorQueryCondition condition) { condition.init(); + condition.setNamespaceId("111"); final List list = selectorMapper.selectByCondition(condition); for (SelectorVO selector : list) { selector.setMatchModeName(MatchModeEnum.getMatchModeByCode(selector.getMatchMode())); diff --git a/shenyu-admin/src/main/resources/mappers/selector-sqlmap.xml b/shenyu-admin/src/main/resources/mappers/selector-sqlmap.xml index 4e0f3d259215..dc547b1fb66b 100644 --- a/shenyu-admin/src/main/resources/mappers/selector-sqlmap.xml +++ b/shenyu-admin/src/main/resources/mappers/selector-sqlmap.xml @@ -32,6 +32,7 @@ + @@ -47,7 +48,8 @@ loged, continued, match_restful, - handle + handle, + namespace_id @@ -63,7 +65,8 @@ ${alis}.loged, ${alis}.continued, ${alis}.match_restful, - ${alis}.handle + ${alis}.handle, + ${alis}.namespace_id From dcfca2fe8a913875c138fbbad51857f3920043c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=98xcsnx=E2=80=99?= <‘1192709687@qq.com’> Date: Tue, 23 Jul 2024 09:00:44 +0800 Subject: [PATCH 02/61] commit --- .../shenyu/admin/model/dto/SelectorDTO.java | 74 +++++++++++++------ .../shenyu/admin/model/entity/SelectorDO.java | 1 + .../service/impl/SelectorServiceImpl.java | 5 +- .../resources/mappers/selector-sqlmap.xml | 6 ++ .../service/DataPermissionServiceTest.java | 2 +- .../e2e/testcase/grpc/GrpcPluginTest.java | 4 +- 6 files changed, 67 insertions(+), 25 deletions(-) diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/dto/SelectorDTO.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/dto/SelectorDTO.java index 4be5741c1371..fcea5273a528 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/dto/SelectorDTO.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/dto/SelectorDTO.java @@ -19,6 +19,7 @@ import org.apache.shenyu.admin.mapper.PluginMapper; import org.apache.shenyu.admin.mapper.SelectorMapper; +import org.apache.shenyu.admin.model.entity.SelectorDO; import org.apache.shenyu.admin.validation.annotation.Existed; import org.hibernate.validator.constraints.Range; @@ -112,6 +113,11 @@ public final class SelectorDTO implements Serializable { * selector rules. */ private List selectorRules; + + /** + * namespaceId. + */ + private String namespaceId; public SelectorDTO() { } @@ -128,7 +134,7 @@ public SelectorDTO(final String id, final String handle, @Valid final List selectorConditions, @NotNull final Boolean matchRestful, - @Valid final List selectorRules) { + @Valid final List selectorRules, String namespaceId) { this.id = id; this.pluginId = pluginId; this.name = name; @@ -142,6 +148,7 @@ public SelectorDTO(final String id, this.selectorConditions = selectorConditions; this.matchRestful = matchRestful; this.selectorRules = selectorRules; + this.namespaceId = namespaceId; } /** @@ -377,6 +384,24 @@ public List getSelectorRules() { public void setSelectorRules(final List selectorRules) { this.selectorRules = selectorRules; } + + /** + * get namespaceId. + * + * @return namespaceId + */ + public String getNamespaceId() { + return namespaceId; + } + + /** + * set namespaceId. + * + * @param namespaceId namespaceId + */ + public void setNamespaceId(final String namespaceId) { + this.namespaceId = namespaceId; + } /** * builder method. @@ -386,36 +411,30 @@ public void setSelectorRules(final List selectorRules) { public static SelectorDTO.SelectorDTOBuilder builder() { return new SelectorDTO.SelectorDTOBuilder(); } - + @Override - public boolean equals(final Object o) { + public boolean equals(Object o) { if (this == o) { return true; } - if (!(o instanceof SelectorDTO)) { + if (o == null || getClass() != o.getClass()) { return false; } SelectorDTO that = (SelectorDTO) o; - return Objects.equals(id, that.id) - && Objects.equals(pluginId, that.pluginId) - && Objects.equals(name, that.name) - && Objects.equals(matchMode, that.matchMode) - && Objects.equals(type, that.type) - && Objects.equals(sort, that.sort) - && Objects.equals(enabled, that.enabled) - && Objects.equals(loged, that.loged) - && Objects.equals(continued, that.continued) - && Objects.equals(handle, that.handle) - && Objects.equals(selectorConditions, that.selectorConditions) - && Objects.equals(matchRestful, that.matchRestful); + return Objects.equals(id, that.id) && Objects.equals(pluginId, that.pluginId) && Objects.equals(name, that.name) + && Objects.equals(matchMode, that.matchMode) && Objects.equals(type, that.type) && Objects.equals(sort, that.sort) + && Objects.equals(enabled, that.enabled) && Objects.equals(loged, that.loged) && Objects.equals(continued, that.continued) + && Objects.equals(handle, that.handle) && Objects.equals(selectorConditions, that.selectorConditions) + && Objects.equals(matchRestful, that.matchRestful) && Objects.equals(selectorRules, that.selectorRules) + && Objects.equals(namespaceId, that.namespaceId); } - + @Override public int hashCode() { - return Objects.hash(id, pluginId, name, matchMode, type, sort, enabled, loged, continued, handle, - selectorConditions, matchRestful); + return Objects.hash(id, pluginId, name, matchMode, type, sort, enabled, loged, continued, handle, selectorConditions, + matchRestful, selectorRules, namespaceId); } - + public static final class SelectorDTOBuilder { private String id; @@ -443,6 +462,8 @@ public static final class SelectorDTOBuilder { private Boolean matchRestful; private List selectorRules; + + private String namespaceId; private SelectorDTOBuilder() { } @@ -589,6 +610,17 @@ public SelectorDTOBuilder selectorRules(final List selectorRules) { this.selectorRules = selectorRules; return this; } + + /** + * namespaceId. + * + * @param namespaceId namespaceId + * @return SelectorDOBuilder + */ + public SelectorDTOBuilder namespaceId(final String namespaceId) { + this.namespaceId = namespaceId; + return this; + } /** * build method. @@ -597,7 +629,7 @@ public SelectorDTOBuilder selectorRules(final List selectorRules) { */ public SelectorDTO build() { return new SelectorDTO(id, pluginId, name, matchMode, type, sort, enabled, loged, continued, handle, - selectorConditions, matchRestful, selectorRules); + selectorConditions, matchRestful, selectorRules, namespaceId); } } } diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/entity/SelectorDO.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/entity/SelectorDO.java index 0748d0dd0323..492f1f6751b1 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/entity/SelectorDO.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/entity/SelectorDO.java @@ -371,6 +371,7 @@ public static SelectorDO buildSelectorDO(final SelectorDTO selectorDTO) { .pluginId(item.getPluginId()) .name(item.getName()) .matchRestful(item.getMatchRestful()) + .namespaceId(item.getNamespaceId()) .build(); if (StringUtils.isEmpty(item.getId())) { selectorDO.setId(UUIDUtils.getInstance().generateShortUuid()); diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/SelectorServiceImpl.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/SelectorServiceImpl.java index 604ad1310f48..d1f86fd2f4b0 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/SelectorServiceImpl.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/SelectorServiceImpl.java @@ -90,6 +90,8 @@ import java.util.TreeSet; import java.util.stream.Collectors; +import static org.apache.shenyu.common.constant.AdminConstants.SYS_DEFAULT_NAMESPACE_NAMESPACE_ID; + /** * Implementation of the {@link org.apache.shenyu.admin.service.SelectorService}. * Maintain {@link SelectorDO} and {@link SelectorConditionDO} related data. @@ -151,7 +153,6 @@ public void doConditionPreProcessing(final SelectorQueryCondition condition) { @Override public List searchByCondition(final SelectorQueryCondition condition) { condition.init(); - condition.setNamespaceId("111"); final List list = selectorMapper.selectByCondition(condition); for (SelectorVO selector : list) { selector.setMatchModeName(MatchModeEnum.getMatchModeByCode(selector.getMatchMode())); @@ -178,6 +179,8 @@ public String registerDefault(final MetaDataRegisterDTO dto, final String plugin if (Objects.isNull(selectorDO)) { SelectorDTO selectorDTO = SelectorUtil.buildSelectorDTO(contextPath, pluginMapper.selectByName(pluginName).getId()); selectorDTO.setHandle(selectorHandler); + // todo:[To be refactored with namespace] Temporarily hardcode + selectorDTO.setNamespaceId(SYS_DEFAULT_NAMESPACE_NAMESPACE_ID); return registerDefault(selectorDTO); } return selectorDO.getId(); diff --git a/shenyu-admin/src/main/resources/mappers/selector-sqlmap.xml b/shenyu-admin/src/main/resources/mappers/selector-sqlmap.xml index dc547b1fb66b..e6fd40c42cda 100644 --- a/shenyu-admin/src/main/resources/mappers/selector-sqlmap.xml +++ b/shenyu-admin/src/main/resources/mappers/selector-sqlmap.xml @@ -316,6 +316,9 @@ handle, + + namespace_id, + #{id, jdbcType=VARCHAR}, @@ -355,6 +358,9 @@ #{handle, jdbcType=VARCHAR}, + + #{namespace_id, jdbcType=VARCHAR}, + diff --git a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/DataPermissionServiceTest.java b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/DataPermissionServiceTest.java index e3cf415e795d..9d61630ada1a 100644 --- a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/DataPermissionServiceTest.java +++ b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/DataPermissionServiceTest.java @@ -84,7 +84,7 @@ public void setup() { dataPermissionDTO.setUserId("1001"); dataPermissionDTO.setDataId("1"); dataPermissionDTO.setIsSelected(true); - selectorDTO = new SelectorDTO("1", "1", "test", 1, 1, 1, true, false, true, "test", null, false, null); + selectorDTO = new SelectorDTO("1", "1", "test", 1, 1, 1, true, false, true, "test", null, false, null, namespaceId); } @Test diff --git a/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-grpc/src/test/java/org/apache/shenyu/e2e/testcase/grpc/GrpcPluginTest.java b/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-grpc/src/test/java/org/apache/shenyu/e2e/testcase/grpc/GrpcPluginTest.java index 580d04b2be24..ebd5fcb0b0c1 100644 --- a/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-grpc/src/test/java/org/apache/shenyu/e2e/testcase/grpc/GrpcPluginTest.java +++ b/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-grpc/src/test/java/org/apache/shenyu/e2e/testcase/grpc/GrpcPluginTest.java @@ -36,7 +36,7 @@ @ShenYuTest.Environment( serviceName = "shenyu-e2e-admin", service = @ShenYuTest.ServiceConfigure(moduleName = "shenyu-e2e", - baseUrl = "http://localhost:31095", + baseUrl = "http://localhost:9095", type = ServiceTypeEnum.SHENYU_ADMIN, parameters = { @ShenYuTest.Parameter(key = "username", value = "admin"), @@ -47,7 +47,7 @@ @ShenYuTest.Environment( serviceName = "shenyu-e2e-gateway", service = @ShenYuTest.ServiceConfigure(moduleName = "shenyu-e2e", - baseUrl = "http://localhost:31195", + baseUrl = "http://localhost:9195", type = ServiceTypeEnum.SHENYU_GATEWAY ) ) From 3538f3758b9ab76b63d6b1aa5fa78b399e083c7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=98xcsnx=E2=80=99?= <‘1192709687@qq.com’> Date: Tue, 30 Jul 2024 23:43:04 +0800 Subject: [PATCH 03/61] first draft,not verified --- .../admin/controller/SelectorController.java | 24 ++++--- .../shenyu/admin/mapper/SelectorMapper.java | 15 +++- .../shenyu/admin/model/dto/SelectorDTO.java | 3 + .../shenyu/admin/model/entity/SelectorDO.java | 1 + .../event/selector/SelectorChangedEvent.java | 7 +- .../shenyu/admin/model/vo/NamespaceVO.java | 2 +- .../shenyu/admin/model/vo/SelectorVO.java | 23 ++++++ .../shenyu/admin/service/SelectorService.java | 30 ++++---- .../admin/service/impl/ApiServiceImpl.java | 4 +- .../service/impl/DiscoveryServiceImpl.java | 4 +- .../impl/DiscoveryUpstreamServiceImpl.java | 2 +- .../service/impl/SelectorServiceImpl.java | 44 ++++++------ .../service/impl/UpstreamCheckService.java | 2 +- ...stractShenyuClientRegisterServiceImpl.java | 8 ++- ...ShenyuClientRegisterDivideServiceImpl.java | 7 +- .../ShenyuClientRegisterGrpcServiceImpl.java | 5 +- ...nyuClientRegisterWebSocketServiceImpl.java | 5 +- .../resources/mappers/selector-sqlmap.xml | 57 +++++++++++++-- .../admin/mapper/SelectorMapperTest.java | 5 +- .../admin/service/SelectorServiceTest.java | 10 +-- ...ctShenyuClientRegisterServiceImplTest.java | 4 +- .../shenyu/common/dto/SelectorData.java | 70 ++++++++++++++----- 22 files changed, 243 insertions(+), 89 deletions(-) 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 cc820e7dd2f4..c7df3cd090fd 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 @@ -18,8 +18,10 @@ package org.apache.shenyu.admin.controller; 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; import org.apache.shenyu.admin.model.dto.SelectorDTO; import org.apache.shenyu.admin.model.page.CommonPager; import org.apache.shenyu.admin.model.page.PageCondition; @@ -70,12 +72,16 @@ public SelectorController(final SelectorService selectorService) { */ @GetMapping("") public AdminResult> querySelectors(final String pluginId, final String name, - @RequestParam @NotNull final Integer currentPage, - @RequestParam @NotNull final Integer pageSize) { + @RequestParam @NotNull final Integer currentPage, + @RequestParam @NotNull final Integer pageSize, + @Existed(message = "namespaceId is not existed", + provider = NamespaceMapper.class) final String namespaceId + ) { final SelectorQueryCondition condition = new SelectorQueryCondition(); condition.setUserId(SessionUtil.visitor().getUserId()); condition.setPlugin(ListUtil.of(pluginId)); condition.setKeyword(name); + condition.setNamespaceId(namespaceId); return searchAdaptor(new PageCondition<>(currentPage, pageSize, condition)); } @@ -87,8 +93,10 @@ public AdminResult> querySelectors(final String pluginId */ @GetMapping("/{id}") public ShenyuAdminResult detailSelector(@PathVariable("id") @Valid - @Existed(provider = SelectorMapper.class, message = "selector is not existed") final String id) { - SelectorVO selectorVO = selectorService.findById(id); + @Existed(provider = SelectorMapper.class, message = "selector is not existed") final String id, + @Existed(message = "namespaceId is not existed", + provider = NamespaceMapper.class) final String namespaceId) { + SelectorVO selectorVO = selectorService.findById(id, namespaceId); return ShenyuAdminResult.success(ShenyuResultMessage.DETAIL_SUCCESS, selectorVO); } @@ -129,7 +137,7 @@ public ShenyuAdminResult updateSelector(@PathVariable("id") @Valid */ @PostMapping("/batchEnabled") public ShenyuAdminResult batchEnabled(@Valid @RequestBody final BatchCommonDTO batchCommonDTO) { - if (!selectorService.enabled(batchCommonDTO.getIds(), batchCommonDTO.getEnabled())) { + if (!selectorService.enabled(batchCommonDTO.getIds(), batchCommonDTO.getEnabled(), batchCommonDTO.getNamespaceId())) { return ShenyuAdminResult.error(ShenyuResultMessage.NOT_FOUND_EXCEPTION); } return ShenyuAdminResult.success(ShenyuResultMessage.ENABLE_SUCCESS); @@ -138,12 +146,12 @@ public ShenyuAdminResult batchEnabled(@Valid @RequestBody final BatchCommonDTO b /** * delete Selectors. * - * @param ids primary key. + * @param batchNamespaceCommonDTO batchNamespaceCommonDTO. * @return {@linkplain ShenyuAdminResult} */ @DeleteMapping("/batch") - public ShenyuAdminResult deleteSelector(@RequestBody @NotEmpty final List<@NotBlank String> ids) { - Integer deleteCount = selectorService.delete(ids); + public ShenyuAdminResult deleteSelector(@Valid @RequestBody final BatchNamespaceCommonDTO batchNamespaceCommonDTO) { + Integer deleteCount = selectorService.delete(batchNamespaceCommonDTO.getIds(), batchNamespaceCommonDTO.getNamespaceId()); return ShenyuAdminResult.success(ShenyuResultMessage.DELETE_SUCCESS, deleteCount); } diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/SelectorMapper.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/SelectorMapper.java index 871972c0792c..c11eea7ca17a 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/SelectorMapper.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/SelectorMapper.java @@ -48,9 +48,18 @@ public interface SelectorMapper extends ExistProvider { * select selector by id. * * @param id primary key. + * @param namespaceId namespaceId. * @return {@linkplain SelectorDO} */ - SelectorDO selectById(String id); + SelectorDO selectById(String id, String namespaceId); + + /** + * select selector by id. + * + * @param id primary key. + * @return {@linkplain SelectorDO} + */ + SelectorDO selectByOnlyId(String id); /** * Select selector by a list of ids. @@ -90,7 +99,7 @@ public interface SelectorMapper extends ExistProvider { * @param name the name * @return selector do list */ - List selectByName(String name); + List selectByName(String name,String namespaceId); /** * Find by name and plugin id selector do. @@ -99,7 +108,7 @@ public interface SelectorMapper extends ExistProvider { * @param pluginId the plugin id * @return the selector do */ - SelectorDO findByNameAndPluginId(@Param("name") String name, @Param("pluginId") String pluginId); + SelectorDO findByNameAndPluginId(@Param("name") String name, @Param("pluginId") String pluginId, @Param("namespaceId") String namespaceId); /** * count selector by query. diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/dto/SelectorDTO.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/dto/SelectorDTO.java index fcea5273a528..7bdfeb99ddf7 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/dto/SelectorDTO.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/dto/SelectorDTO.java @@ -17,6 +17,7 @@ package org.apache.shenyu.admin.model.dto; +import org.apache.shenyu.admin.mapper.NamespaceMapper; import org.apache.shenyu.admin.mapper.PluginMapper; import org.apache.shenyu.admin.mapper.SelectorMapper; import org.apache.shenyu.admin.model.entity.SelectorDO; @@ -117,6 +118,8 @@ public final class SelectorDTO implements Serializable { /** * namespaceId. */ + @NotBlank + @Existed(message = "namespaceId is not existed", provider = NamespaceMapper.class) private String namespaceId; public SelectorDTO() { diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/entity/SelectorDO.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/entity/SelectorDO.java index 492f1f6751b1..0a44040feb49 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/entity/SelectorDO.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/entity/SelectorDO.java @@ -414,6 +414,7 @@ public static SelectorData transFrom(final SelectorDO selectorDO, final String p .conditionList(conditionDataList) .matchRestful(selectorDO.getMatchRestful()) .beforeConditionList(beforeConditionDataList) + .namespaceId(selectorDO.getNamespaceId()) .build(); } diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/event/selector/SelectorChangedEvent.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/event/selector/SelectorChangedEvent.java index 479702a34df4..d417aa7eac94 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/event/selector/SelectorChangedEvent.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/event/selector/SelectorChangedEvent.java @@ -46,9 +46,9 @@ public SelectorChangedEvent(final SelectorDO source, final SelectorDO before, fi public String buildContext() { final SelectorDO after = (SelectorDO) getAfter(); if (Objects.isNull(getBefore())) { - return String.format("the selector [%s] is %s", after.getName(), StringUtils.lowerCase(getType().getType().toString())); + return String.format("the namespace [%s] selector [%s] is %s", after.getNamespaceId(), after.getName(), StringUtils.lowerCase(getType().getType().toString())); } - return String.format("the selector [%s] is %s : %s", after.getName(), StringUtils.lowerCase(getType().getType().toString()), contrast()); + return String.format("the namespace [%s] selector [%s] is %s : %s", after.getNamespaceId(), after.getName(), StringUtils.lowerCase(getType().getType().toString()), contrast()); } @@ -79,6 +79,9 @@ private String contrast() { if (!Objects.equals(before.getLoged(), after.getLoged())) { builder.append(String.format("loged[%s => %s] ", before.getLoged(), after.getLoged())); } + if (!Objects.equals(before.getNamespaceId(), after.getNamespaceId())) { + builder.append(String.format("namespaceId[%s => %s] ", before.getNamespaceId(), after.getNamespaceId())); + } return builder.toString(); } diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/vo/NamespaceVO.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/vo/NamespaceVO.java index 8064430c44c8..b780e25a6d4d 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/vo/NamespaceVO.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/vo/NamespaceVO.java @@ -32,7 +32,7 @@ public class NamespaceVO implements Serializable { private String id; /** - * name. + * namespaceId. */ private String namespaceId; diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/vo/SelectorVO.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/vo/SelectorVO.java index e4b8d26b76c4..be222a6a0d29 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/vo/SelectorVO.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/vo/SelectorVO.java @@ -129,6 +129,11 @@ public class SelectorVO implements Serializable { */ private List selectorRules; + /** + * namespaceId. + */ + private String namespaceId; + public SelectorVO() { } @@ -537,6 +542,24 @@ public static SelectorVO buildSelectorVO(final SelectorDO selectorDO) { return buildSelectorVO(selectorDO, null); } + /** + * 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; + } + /** * build selectorVO. * diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/SelectorService.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/SelectorService.java index 8e4e9a7f01d7..6d8f12c49cad 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/SelectorService.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/SelectorService.java @@ -108,17 +108,19 @@ default int createOrUpdate(SelectorDTO selectorDTO) { * delete selectors. * * @param ids primary key. + * @param namespaceId namespaceId. * @return rows int */ - int delete(List ids); + int delete(List ids, String namespaceId); /** * find selector by id. * * @param id primary key. + * @param namespaceId namespaceId. * @return {@linkplain SelectorVO} */ - SelectorVO findById(String id); + SelectorVO findById(String id,String namespaceId); /** * find selector by name. @@ -126,10 +128,10 @@ default int createOrUpdate(SelectorDTO selectorDTO) { * @param name the name * @return selector do * @deprecated sice 2.6.0 Deprecated. By querying under this condition, multiple data are usually obtained. - * Therefore, it is recommended to: {@linkplain SelectorService#findListByName(java.lang.String)} + * Therefore, it is recommended to: {@linkplain SelectorService#findListByName(java.lang.String,java.lang.String)} */ @Deprecated - SelectorDO findByName(String name); + SelectorDO findByName(String name, String namespaceId); /** * find selector list by name. @@ -137,16 +139,17 @@ default int createOrUpdate(SelectorDTO selectorDTO) { * @param name name * @return list */ - List findListByName(String name); + List findListByName(String name, String namespaceId); /** * Find by name and plugin id selector do. * - * @param name the name - * @param pluginName the plugin name + * @param name the name + * @param pluginName the plugin name + * @param namespaceId the namespaceId * @return the selector do */ - SelectorDO findByNameAndPluginName(String name, String pluginName); + SelectorDO findByNameAndPluginName(String name, String pluginName, String namespaceId); /** * findByNameAndPluginNameForUpdate. @@ -155,7 +158,7 @@ default int createOrUpdate(SelectorDTO selectorDTO) { * @param pluginName pluginName * @return SelectorDO */ - SelectorDO findByNameAndPluginNameForUpdate(String name, String pluginName); + SelectorDO findByNameAndPluginNameForUpdate(String name, String pluginName, String namespaceId); /** * Find selectorDO list by name and plugin name list. @@ -172,16 +175,17 @@ default int createOrUpdate(SelectorDTO selectorDTO) { * @param name the name * @return the selector data */ - SelectorData buildByName(String name); + SelectorData buildByName(String name, String namespaceId); /** * Build by name selector data. * * @param name the name * @param pluginName the plugin name + * @param namespaceId the namespaceId * @return the selector data */ - SelectorData buildByName(String name, String pluginName); + SelectorData buildByName(String name, String pluginName, String namespaceId); /** * find page of selector by query. @@ -223,6 +227,7 @@ default int createOrUpdate(SelectorDTO selectorDTO) { /** * Import the plugin selector list. + * * @param selectorList the plugin selector list * @return config import result */ @@ -233,7 +238,8 @@ default int createOrUpdate(SelectorDTO selectorDTO) { * * @param ids the ids * @param enabled the enable + * @param namespaceId namespaceId * @return the result */ - Boolean enabled(List ids, Boolean enabled); + Boolean enabled(List ids, Boolean enabled, String namespaceId); } diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/ApiServiceImpl.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/ApiServiceImpl.java index 29749faf54f4..d1a39b614a24 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/ApiServiceImpl.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/ApiServiceImpl.java @@ -63,6 +63,8 @@ import java.util.Optional; import java.util.stream.Collectors; +import static org.apache.shenyu.common.constant.AdminConstants.SYS_DEFAULT_NAMESPACE_NAMESPACE_ID; + /** * Implementation of the {@link org.apache.shenyu.admin.service.ApiService}. */ @@ -186,7 +188,7 @@ private void removeRegister(final ApiDO apiDO) { } }); if (CollectionUtils.isNotEmpty(selectorIds)) { - selectorService.delete(selectorIds); + selectorService.delete(selectorIds, SYS_DEFAULT_NAMESPACE_NAMESPACE_ID); } //clean metadata Optional.ofNullable(metaDataService.findByPath(path)) diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/DiscoveryServiceImpl.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/DiscoveryServiceImpl.java index 637fe0b0ae94..0b78c5318702 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/DiscoveryServiceImpl.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/DiscoveryServiceImpl.java @@ -63,6 +63,8 @@ import java.util.Set; import java.util.stream.Collectors; +import static org.apache.shenyu.common.constant.AdminConstants.SYS_DEFAULT_NAMESPACE_NAMESPACE_ID; + @Service public class DiscoveryServiceImpl implements DiscoveryService { @@ -125,7 +127,7 @@ public void registerDiscoveryConfig(final DiscoveryConfigRegisterDTO discoveryCo private SelectorDO findAndLockOnDB(final String selectorName, final String pluginName) { SelectorDO selectorDO = null; for (int i = 0; i < 3; i++) { - selectorDO = selectorService.findByNameAndPluginNameForUpdate(selectorName, pluginName); + selectorDO = selectorService.findByNameAndPluginNameForUpdate(selectorName, pluginName, SYS_DEFAULT_NAMESPACE_NAMESPACE_ID); if (selectorDO != null) { return selectorDO; } diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/DiscoveryUpstreamServiceImpl.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/DiscoveryUpstreamServiceImpl.java index f04e6d447af2..e5dc35325683 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/DiscoveryUpstreamServiceImpl.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/DiscoveryUpstreamServiceImpl.java @@ -151,7 +151,7 @@ public List listAll() { if (StringUtils.hasLength(discoveryRelDO.getSelectorId())) { String selectorId = discoveryRelDO.getSelectorId(); discoverySyncData.setSelectorId(selectorId); - SelectorDO selectorDO = selectorMapper.selectById(selectorId); + SelectorDO selectorDO = selectorMapper.selectByOnlyId(selectorId); discoverySyncData.setSelectorName(selectorDO.getName()); } else { String proxySelectorId = discoveryRelDO.getProxySelectorId(); diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/SelectorServiceImpl.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/SelectorServiceImpl.java index d1f86fd2f4b0..31ff51fc02dc 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/SelectorServiceImpl.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/SelectorServiceImpl.java @@ -175,12 +175,11 @@ public String registerDefault(final SelectorDTO selectorDTO) { @Override public String registerDefault(final MetaDataRegisterDTO dto, final String pluginName, final String selectorHandler) { String contextPath = ContextPathUtils.buildContextPath(dto.getContextPath(), dto.getAppName()); - SelectorDO selectorDO = findByNameAndPluginName(contextPath, pluginName); + // todo:[To be refactored with namespace] Temporarily hardcode + SelectorDO selectorDO = findByNameAndPluginName(contextPath, pluginName, SYS_DEFAULT_NAMESPACE_NAMESPACE_ID); if (Objects.isNull(selectorDO)) { SelectorDTO selectorDTO = SelectorUtil.buildSelectorDTO(contextPath, pluginMapper.selectByName(pluginName).getId()); selectorDTO.setHandle(selectorHandler); - // todo:[To be refactored with namespace] Temporarily hardcode - selectorDTO.setNamespaceId(SYS_DEFAULT_NAMESPACE_NAMESPACE_ID); return registerDefault(selectorDTO); } return selectorDO.getId(); @@ -214,7 +213,7 @@ public int create(final SelectorDTO selectorDTO) { @Override public int update(final SelectorDTO selectorDTO) { - final SelectorDO before = selectorMapper.selectById(selectorDTO.getId()); + final SelectorDO before = selectorMapper.selectById(selectorDTO.getId(), selectorDTO.getNamespaceId()); SelectorDO selectorDO = SelectorDO.buildSelectorDO(selectorDTO); final int selectorCount = selectorMapper.updateSelective(selectorDO); @@ -252,7 +251,7 @@ public int update(final SelectorDTO selectorDTO) { @Override public int updateSelective(final SelectorDO selectorDO) { - final SelectorDO before = selectorMapper.selectById(selectorDO.getId()); + final SelectorDO before = selectorMapper.selectById(selectorDO.getId(), selectorDO.getNamespaceId()); final int updateCount = selectorMapper.updateSelective(selectorDO); if (updateCount > 0) { selectorEventPublisher.onUpdated(selectorDO, before); @@ -268,7 +267,7 @@ public int updateSelective(final SelectorDO selectorDO) { */ @Override @Transactional(rollbackFor = Exception.class) - public int delete(final List ids) { + public int delete(final List ids, final String namespaceId) { final List selectors = selectorMapper.selectByIdSet(new TreeSet<>(ids)); List pluginDOS = pluginMapper.selectByIds(ListUtil.map(selectors, SelectorDO::getPluginId)); unbindDiscovery(selectors, pluginDOS); @@ -312,9 +311,9 @@ private void unbindDiscovery(final List selectors, final List conditions = ListUtil.map(selectorConditionMapper.selectByQuery(new SelectorConditionQuery(id)), SelectorConditionVO::buildSelectorConditionVO); - SelectorVO selectorVO = SelectorVO.buildSelectorVO(selectorMapper.selectById(id), conditions); + SelectorVO selectorVO = SelectorVO.buildSelectorVO(selectorMapper.selectById(id, namespaceId), conditions); DiscoveryHandlerDO discoveryHandlerDO = discoveryHandlerMapper.selectBySelectorId(id); if (Objects.nonNull(discoveryHandlerDO)) { selectorVO.setDiscoveryHandler(DiscoveryTransfer.INSTANCE.mapToVo(discoveryHandlerDO)); @@ -332,14 +331,14 @@ public SelectorVO findById(final String id) { } @Override - public SelectorDO findByName(final String name) { - List doList = selectorMapper.selectByName(name); + public SelectorDO findByName(final String name, final String namespaceId) { + List doList = selectorMapper.selectByName(name, namespaceId); return CollectionUtils.isNotEmpty(doList) ? doList.get(0) : null; } @Override - public List findListByName(final String name) { - return selectorMapper.selectByName(name); + public List findListByName(final String name, final String namespaceId) { + return selectorMapper.selectByName(name, namespaceId); } /** @@ -350,15 +349,16 @@ public List findListByName(final String name) { * @return the selector do */ @Override - public SelectorDO findByNameAndPluginName(final String name, final String pluginName) { + public SelectorDO findByNameAndPluginName(final String name, final String pluginName, final String namespaceId) { PluginDO pluginDO = pluginMapper.selectByName(pluginName); - return selectorMapper.findByNameAndPluginId(name, pluginDO.getId()); + return selectorMapper.findByNameAndPluginId(name, pluginDO.getId(), namespaceId); } @Override - public SelectorDO findByNameAndPluginNameForUpdate(final String name, final String pluginName) { + public SelectorDO findByNameAndPluginNameForUpdate(final String name, final String pluginName, final String namespaceId) { PluginDO pluginDO = pluginMapper.selectByNameForUpdate(pluginName); - return selectorMapper.findByNameAndPluginId(name, pluginDO.getId()); + // todo:[To be refactored with namespace] Temporarily hardcode + return selectorMapper.findByNameAndPluginId(name, pluginDO.getId(), namespaceId); } @Override @@ -375,8 +375,8 @@ public List findByNameAndPluginNames(final String name, final List selectorList) { @Override @Transactional(rollbackFor = Exception.class) - public Boolean enabled(final List ids, final Boolean enabled) { + public Boolean enabled(final List ids, final Boolean enabled, final String namespaceId) { ids.forEach(id -> { - SelectorDO selectorDO = selectorMapper.selectById(id); + SelectorDO selectorDO = selectorMapper.selectById(id, namespaceId); SelectorDO before = JsonUtils.jsonToObject(JsonUtils.toJson(selectorDO), SelectorDO.class); selectorDO.setEnabled(enabled); if (selectorMapper.updateEnable(id, enabled) > 0) { diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/UpstreamCheckService.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/UpstreamCheckService.java index 305f18fa026d..fa16d4192236 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/UpstreamCheckService.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/UpstreamCheckService.java @@ -382,7 +382,7 @@ private void removePendingSync(final List successList) { } private void updateSelectorHandler(final String selectorId, final List aliveList) { - SelectorDO selectorDO = selectorMapper.selectById(selectorId); + SelectorDO selectorDO = selectorMapper.selectByOnlyId(selectorId); if (Objects.isNull(selectorDO)) { return; } diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/AbstractShenyuClientRegisterServiceImpl.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/AbstractShenyuClientRegisterServiceImpl.java index fe12411a9f83..7ff232d97fa8 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/AbstractShenyuClientRegisterServiceImpl.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/AbstractShenyuClientRegisterServiceImpl.java @@ -58,6 +58,8 @@ import java.util.Objects; import java.util.stream.Collectors; +import static org.apache.shenyu.common.constant.AdminConstants.SYS_DEFAULT_NAMESPACE_NAMESPACE_ID; + /** * Abstract strategy. */ @@ -171,7 +173,8 @@ public String doRegisterURI(final String selectorName, final List buildDivideUpstreamList(final List public String offline(final String selectorName, final List uriList) { final SelectorService selectorService = getSelectorService(); String pluginName = PluginNameAdapter.rpcTypeAdapter(rpcType()); - SelectorDO selectorDO = selectorService.findByNameAndPluginName(selectorName, pluginName); + // todo:[To be refactored with namespace] Temporarily hardcode + SelectorDO selectorDO = selectorService.findByNameAndPluginName(selectorName, pluginName, SYS_DEFAULT_NAMESPACE_NAMESPACE_ID); if (Objects.isNull(selectorDO)) { return Constants.SUCCESS; } @@ -133,7 +136,7 @@ public String offline(final String selectorName, final List uriL existList.removeAll(needToRemove); final String handler = GsonUtils.getInstance().toJson(existList); selectorDO.setHandle(handler); - SelectorData selectorData = selectorService.buildByName(selectorName, PluginNameAdapter.rpcTypeAdapter(rpcType())); + SelectorData selectorData = selectorService.buildByName(selectorName, PluginNameAdapter.rpcTypeAdapter(rpcType()), SYS_DEFAULT_NAMESPACE_NAMESPACE_ID); selectorData.setHandle(handler); // update db selectorService.updateSelective(selectorDO); diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterGrpcServiceImpl.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterGrpcServiceImpl.java index 9d16aacb3a9c..8068101e2e7c 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterGrpcServiceImpl.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterGrpcServiceImpl.java @@ -46,6 +46,8 @@ import java.util.concurrent.CopyOnWriteArrayList; import java.util.stream.Collectors; +import static org.apache.shenyu.common.constant.AdminConstants.SYS_DEFAULT_NAMESPACE_NAMESPACE_ID; + /** * grpc service register. */ @@ -124,7 +126,8 @@ private List buildGrpcUpstreamList(final List uriL public String offline(final String selectorName, final List offlineList) { String pluginName = PluginNameAdapter.rpcTypeAdapter(rpcType()); SelectorService selectorService = getSelectorService(); - SelectorDO selectorDO = selectorService.findByNameAndPluginName(selectorName, pluginName); + // todo:[To be refactored with namespace] Temporarily hardcode + SelectorDO selectorDO = selectorService.findByNameAndPluginName(selectorName, pluginName, SYS_DEFAULT_NAMESPACE_NAMESPACE_ID); if (Objects.isNull(selectorDO)) { return Constants.SUCCESS; } diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterWebSocketServiceImpl.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterWebSocketServiceImpl.java index dd5df3dbb415..8a7d86b4b063 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterWebSocketServiceImpl.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterWebSocketServiceImpl.java @@ -44,6 +44,8 @@ import org.apache.shenyu.register.common.dto.URIRegisterDTO; import org.springframework.stereotype.Service; +import static org.apache.shenyu.common.constant.AdminConstants.SYS_DEFAULT_NAMESPACE_NAMESPACE_ID; + /** * spring mvc websocket service register. */ @@ -105,7 +107,8 @@ private List buildWebSocketUpstreamList(final List offlineList) { String pluginName = PluginNameAdapter.rpcTypeAdapter(rpcType()); SelectorService selectorService = getSelectorService(); - SelectorDO selectorDO = selectorService.findByNameAndPluginName(selectorName, pluginName); + // todo:[To be refactored with namespace] Temporarily hardcode + SelectorDO selectorDO = selectorService.findByNameAndPluginName(selectorName, pluginName, SYS_DEFAULT_NAMESPACE_NAMESPACE_ID); if (Objects.isNull(selectorDO)) { return Constants.SUCCESS; } diff --git a/shenyu-admin/src/main/resources/mappers/selector-sqlmap.xml b/shenyu-admin/src/main/resources/mappers/selector-sqlmap.xml index e6fd40c42cda..f8d30d94f876 100644 --- a/shenyu-admin/src/main/resources/mappers/selector-sqlmap.xml +++ b/shenyu-admin/src/main/resources/mappers/selector-sqlmap.xml @@ -74,8 +74,26 @@ FROM selector WHERE id = #{id, jdbcType=VARCHAR} + + + AND (namespace_id = #{namespaceId, jdbcType=VARCHAR} + OR + namespace_id IS NULL) + + + AND namespace_id = #{namespaceId, jdbcType=VARCHAR} + + + + + @@ -422,7 +459,17 @@ handle = #{handle, jdbcType=VARCHAR}, - WHERE id = #{id, jdbcType=VARCHAR} + WHERE id = #{id, jdbcType=VARCHAR} + + + AND (namespace_id = #{namespaceId, jdbcType=VARCHAR}) + OR + (namespace_id IS NULL) + + + AND namespace_id = #{namespaceId, jdbcType=VARCHAR} + + diff --git a/shenyu-admin/src/test/java/org/apache/shenyu/admin/mapper/SelectorMapperTest.java b/shenyu-admin/src/test/java/org/apache/shenyu/admin/mapper/SelectorMapperTest.java index 7a6f810a4008..9766d2e96cf6 100644 --- a/shenyu-admin/src/test/java/org/apache/shenyu/admin/mapper/SelectorMapperTest.java +++ b/shenyu-admin/src/test/java/org/apache/shenyu/admin/mapper/SelectorMapperTest.java @@ -35,6 +35,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.hamcrest.MatcherAssert.assertThat; +import static org.mockito.ArgumentMatchers.any; /** @@ -51,7 +52,7 @@ public void testSelectById() { int insert = selectorMapper.insert(selectorDO); assertEquals(1, insert); - SelectorDO selector = selectorMapper.selectById(selectorDO.getId()); + SelectorDO selector = selectorMapper.selectById(selectorDO.getId(),any()); assertNotNull(selector); assertEquals(selectorDO.getId(), selector.getId()); assertEquals(selectorDO.getContinued(), selector.getContinued()); @@ -114,7 +115,7 @@ public void testSelectByName() { SelectorDO selectorDO = buildSelectorDO(); int insert = selectorMapper.insert(selectorDO); assertEquals(1, insert); - List doList = selectorMapper.selectByName(selectorDO.getName()); + List doList = selectorMapper.selectByName(selectorDO.getName(), null); assertEquals(doList.size(), 1); assertNotNull(doList.get(0)); assertEquals(selectorDO.getName(), doList.get(0).getName()); diff --git a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/SelectorServiceTest.java b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/SelectorServiceTest.java index 94ec5b0abcf1..03f33967b9a1 100644 --- a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/SelectorServiceTest.java +++ b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/SelectorServiceTest.java @@ -191,14 +191,14 @@ public void testDelete() { final List ids = Collections.singletonList(correctId); given(selectorMapper.deleteByIds(ids)).willReturn(ids.size()); - assertEquals(selectorService.delete(ids), ids.size()); + assertEquals(selectorService.delete(ids, any()), ids.size()); } @Test public void testFindById() { SelectorDO selectorDO = buildSelectorDO(); - given(this.selectorMapper.selectById(eq("123"))).willReturn(selectorDO); - SelectorVO selectorVO = this.selectorService.findById("123"); + given(this.selectorMapper.selectById(eq("123"), any())).willReturn(selectorDO); + SelectorVO selectorVO = this.selectorService.findById("123", any()); assertNotNull(selectorDO); assertEquals(selectorVO.getId(), selectorDO.getId()); @@ -209,8 +209,8 @@ public void testFindById() { @Test public void testFindByName() { List selectorDO1List = Collections.singletonList(buildSelectorDO()); - given(this.selectorMapper.selectByName(eq("kuan"))).willReturn(selectorDO1List); - SelectorDO selectorDO2 = this.selectorService.findByName("kuan"); + given(this.selectorMapper.selectByName(eq("kuan"), anyString())).willReturn(selectorDO1List); + SelectorDO selectorDO2 = this.selectorService.findByName("kuan", anyString()); assertNotNull(selectorDO2); assertEquals(selectorDO1List.size(), 1); assertEquals(selectorDO1List.get(0).getId(), selectorDO2.getId()); diff --git a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/register/AbstractShenyuClientRegisterServiceImplTest.java b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/register/AbstractShenyuClientRegisterServiceImplTest.java index e9f23ca524dc..9446cb53fd1c 100644 --- a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/register/AbstractShenyuClientRegisterServiceImplTest.java +++ b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/register/AbstractShenyuClientRegisterServiceImplTest.java @@ -144,9 +144,9 @@ public void testDoRegisterURI() { assertThrows(ShenyuException.class, () -> abstractShenyuClientRegisterService.doRegisterURI("Selector_Name", Collections.singletonList(uriRegisterDTO))); SelectorDO selectorDO = mock(SelectorDO.class); - when(selectorService.findByNameAndPluginName(any(), any())).thenReturn(selectorDO); + when(selectorService.findByNameAndPluginName(any(), any() ,any())).thenReturn(selectorDO); SelectorData selectorData = new SelectorData(); - when(selectorService.buildByName(any(), any())).thenReturn(selectorData); + when(selectorService.buildByName(any(), any(), any())).thenReturn(selectorData); assertEquals(ShenyuResultMessage.SUCCESS, abstractShenyuClientRegisterService.doRegisterURI("Selector_Name", Collections.singletonList(uriRegisterDTO))); } diff --git a/shenyu-common/src/main/java/org/apache/shenyu/common/dto/SelectorData.java b/shenyu-common/src/main/java/org/apache/shenyu/common/dto/SelectorData.java index f4b7555be76f..fd9b4451af5b 100644 --- a/shenyu-common/src/main/java/org/apache/shenyu/common/dto/SelectorData.java +++ b/shenyu-common/src/main/java/org/apache/shenyu/common/dto/SelectorData.java @@ -59,14 +59,16 @@ public class SelectorData { private String handle; private List conditionList; - + private List beforeConditionList; - + /** * match restful api. */ private Boolean matchRestful; - + + private String namespaceId; + /** * no args constructor. */ @@ -93,6 +95,7 @@ private SelectorData(final Builder builder) { this.conditionList = builder.conditionList; this.matchRestful = builder.matchRestful; this.beforeConditionList = builder.beforeConditionList; + this.namespaceId = builder.namespaceId; } /** @@ -322,7 +325,7 @@ public List getConditionList() { public void setConditionList(final List conditionList) { this.conditionList = conditionList; } - + /** * get match restful. * @@ -331,7 +334,7 @@ public void setConditionList(final List conditionList) { public Boolean getMatchRestful() { return matchRestful; } - + /** * set match restful. * @@ -340,7 +343,7 @@ public Boolean getMatchRestful() { public void setMatchRestful(final Boolean matchRestful) { this.matchRestful = matchRestful; } - + /** * get before condition list. * @@ -349,7 +352,7 @@ public void setMatchRestful(final Boolean matchRestful) { public List getBeforeConditionList() { return beforeConditionList; } - + /** * set before condition list. * @@ -358,9 +361,27 @@ public List getBeforeConditionList() { public void setBeforeConditionList(final List beforeConditionList) { this.beforeConditionList = beforeConditionList; } - + + /** + * get namespaceId. + * + * @return namespaceId + */ + public String getNamespaceId() { + return namespaceId; + } + + /** + * set namespaceId. + * + * @param namespaceId namespaceId + */ + public void setNamespaceId(final String namespaceId) { + this.namespaceId = namespaceId; + } + @Override - public boolean equals(final Object o) { + public boolean equals(Object o) { if (this == o) { return true; } @@ -371,14 +392,14 @@ public boolean equals(final Object o) { return Objects.equals(id, that.id) && Objects.equals(pluginId, that.pluginId) && Objects.equals(pluginName, that.pluginName) && Objects.equals(name, that.name) && Objects.equals(matchMode, that.matchMode) && Objects.equals(type, that.type) && Objects.equals(sort, that.sort) && Objects.equals(enabled, that.enabled) && Objects.equals(logged, that.logged) - && Objects.equals(continued, that.continued) && Objects.equals(handle, that.handle) - && Objects.equals(conditionList, that.conditionList) && Objects.equals(matchRestful, that.matchRestful) - && Objects.equals(beforeConditionList, that.beforeConditionList); + && Objects.equals(continued, that.continued) && Objects.equals(handle, that.handle) && Objects.equals(conditionList, that.conditionList) + && Objects.equals(beforeConditionList, that.beforeConditionList) && Objects.equals(matchRestful, that.matchRestful) + && Objects.equals(namespaceId, that.namespaceId); } @Override public int hashCode() { - return Objects.hash(id, pluginId, pluginName, name, matchMode, type, sort, enabled, logged, continued, handle, conditionList, matchRestful, beforeConditionList); + return Objects.hash(id, pluginId, pluginName, name, matchMode, type, sort, enabled, logged, continued, handle, conditionList, beforeConditionList, matchRestful, namespaceId); } @Override @@ -415,6 +436,8 @@ public String toString() { + conditionList + ", matchRestful=" + matchRestful + + ", namespaceId=" + + namespaceId + '}'; } @@ -446,11 +469,13 @@ public static final class Builder { private String handle; private List conditionList; - + private Boolean matchRestful; - + private List beforeConditionList; + private String namespaceId; + /** * no args constructor. */ @@ -597,7 +622,7 @@ public Builder conditionList(final List conditionList) { this.conditionList = conditionList; return this; } - + /** * build match restful. * @@ -608,7 +633,7 @@ public Builder matchRestful(final Boolean matchRestful) { this.matchRestful = matchRestful; return this; } - + /** * build beforeConditionList. * @@ -619,5 +644,16 @@ public Builder beforeConditionList(final List beforeConditionList this.beforeConditionList = beforeConditionList; return this; } + + /** + * build namespaceId. + * + * @param namespaceId namespaceId + * @return this + */ + public Builder namespaceId(final String namespaceId) { + this.namespaceId = namespaceId; + return this; + } } } From 28e6b82265da6bb021bf615792666a682b3eda5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=98xcsnx=E2=80=99?= <‘1192709687@qq.com’> Date: Thu, 1 Aug 2024 22:12:40 +0800 Subject: [PATCH 04/61] simplify verified --- db/init/mysql/schema.sql | 2 ++ db/init/oracle/schema.sql | 4 +++ db/init/pg/create-table.sql | 2 ++ db/upgrade/2.6.1-upgrade-2.7.0-og.sql | 3 ++ db/upgrade/2.6.1-upgrade-2.7.0-oracle.sql | 3 ++ db/upgrade/2.6.1-upgrade-2.7.0-pg.sql | 3 ++ .../admin/controller/SelectorController.java | 16 ++++----- .../mapper/NamespacePluginRelMapper.java | 4 +-- .../shenyu/admin/mapper/SelectorMapper.java | 24 +++++++------ .../model/dto/BatchNamespaceCommonDTO.java | 4 +++ .../shenyu/admin/model/dto/SelectorDTO.java | 6 ++-- .../shenyu/admin/model/entity/PluginDO.java | 32 +++++++++++++++++ .../shenyu/admin/model/entity/SelectorDO.java | 2 +- .../event/plugin/BatchPluginDeletedEvent.java | 19 ++++++++-- .../model/query/SelectorConditionQuery.java | 2 +- .../admin/model/query/SelectorQuery.java | 2 +- .../shenyu/admin/model/vo/SelectorVO.java | 34 +++++++++--------- .../shenyu/admin/service/SelectorService.java | 35 +++++++++++-------- .../service/impl/SelectorServiceImpl.java | 9 ++--- .../service/impl/SyncDataServiceImpl.java | 2 +- .../service/impl/UpstreamCheckService.java | 5 ++- .../NamespacePluginEventPublisher.java | 19 ++++++++-- .../service/publish/PluginEventPublisher.java | 7 ++-- .../mappers/NamespacePluginRelMapper.xml | 2 +- .../resources/mappers/selector-sqlmap.xml | 34 ++++++++++++++---- .../main/resources/sql-script/h2/schema.sql | 2 ++ .../controller/SelectorControllerTest.java | 6 ++-- .../admin/mapper/SelectorMapperTest.java | 5 +-- .../plugin/BatchPluginDeletedEventTest.java | 2 +- .../service/DataPermissionServiceTest.java | 2 +- .../admin/service/PluginServiceTest.java | 2 +- .../shenyu/admin/service/RuleServiceTest.java | 6 ++-- .../admin/service/SelectorServiceTest.java | 2 +- .../admin/service/SyncDataServiceTest.java | 3 +- .../service/UpstreamCheckServiceTest.java | 3 +- ...ctShenyuClientRegisterServiceImplTest.java | 2 +- .../shenyu/common/dto/SelectorData.java | 2 +- 37 files changed, 215 insertions(+), 97 deletions(-) diff --git a/db/init/mysql/schema.sql b/db/init/mysql/schema.sql index 86e9aa0a8884..83b0645f775e 100644 --- a/db/init/mysql/schema.sql +++ b/db/init/mysql/schema.sql @@ -2369,3 +2369,5 @@ INSERT INTO `shenyu`.`permission` (`id`, `object_id`, `resource_id`, `date_creat INSERT INTO `shenyu`.`permission` (`id`, `object_id`, `resource_id`, `date_created`, `date_updated`) VALUES ('1792779493541343265', '1346358560427216896', '1792749362445840484', '2024-06-25 20:00:00.000', '2024-06-25 20:00:00.000'); INSERT INTO `shenyu`.`permission` (`id`, `object_id`, `resource_id`, `date_created`, `date_updated`) VALUES ('1792779493541343266', '1346358560427216896', '1792749362445840485', '2024-06-25 20:00:00.000', '2024-06-25 20:00:00.000'); INSERT INTO `shenyu`.`permission` (`id`, `object_id`, `resource_id`, `date_created`, `date_updated`) VALUES ('1792779493541343267', '1346358560427216896', '1792749362445840486', '2024-06-25 20:00:00.000', '2024-06-25 20:00:00.000'); + +ALTER TABLE `shenyu`.`selector` ADD COLUMN `namespace_id` varchar(50) NULL COMMENT 'namespaceId' AFTER `match_restful`; \ No newline at end of file diff --git a/db/init/oracle/schema.sql b/db/init/oracle/schema.sql index bfcca282244d..644b6ea950fb 100644 --- a/db/init/oracle/schema.sql +++ b/db/init/oracle/schema.sql @@ -2856,3 +2856,7 @@ INSERT /*+ IGNORE_ROW_ON_DUPKEY_INDEX (permission(id)) */ INTO permission (id, o INSERT /*+ IGNORE_ROW_ON_DUPKEY_INDEX (permission(id)) */ INTO permission (id, object_id, resource_id) VALUES ('1792779493541343265', '1346358560427216896', '1792749362445840484'); INSERT /*+ IGNORE_ROW_ON_DUPKEY_INDEX (permission(id)) */ INTO permission (id, object_id, resource_id) VALUES ('1792779493541343266', '1346358560427216896', '1792749362445840485'); INSERT /*+ IGNORE_ROW_ON_DUPKEY_INDEX (permission(id)) */ INTO permission (id, object_id, resource_id) VALUES ('1792779493541343267', '1346358560427216896', '1792749362445840486'); + + +ALTER TABLE selector ADD namespace_id VARCHAR2(50) NULL; +COMMENT ON COLUMN selector.namespace_id IS 'namespaceId'; \ No newline at end of file diff --git a/db/init/pg/create-table.sql b/db/init/pg/create-table.sql index 7523e6b08c21..90620ec6bb1b 100644 --- a/db/init/pg/create-table.sql +++ b/db/init/pg/create-table.sql @@ -2790,3 +2790,5 @@ INSERT INTO "public"."permission" VALUES ('1792779493541343265', '13463585604272 INSERT INTO "public"."permission" VALUES ('1792779493541343266', '1346358560427216896', '1792749362445840485', '2024-06-25 20:00:00.000', '2024-06-25 20:00:00.000'); INSERT INTO "public"."permission" VALUES ('1792779493541343267', '1346358560427216896', '1792749362445840486', '2024-06-25 20:00:00.000', '2024-06-25 20:00:00.000'); +ALTER TABLE "public"."selector" ADD COLUMN namespace_id VARCHAR(50) NULL; +COMMENT ON COLUMN "public"."selector"."namespace_id" IS 'namespaceId'; \ No newline at end of file diff --git a/db/upgrade/2.6.1-upgrade-2.7.0-og.sql b/db/upgrade/2.6.1-upgrade-2.7.0-og.sql index 97b706127430..37812c36f0a9 100644 --- a/db/upgrade/2.6.1-upgrade-2.7.0-og.sql +++ b/db/upgrade/2.6.1-upgrade-2.7.0-og.sql @@ -188,3 +188,6 @@ INSERT INTO "public"."permission" VALUES ('1792779493541343264', '13463585604272 INSERT INTO "public"."permission" VALUES ('1792779493541343265', '1346358560427216896', '1792749362445840484', '2024-06-25 20:00:00.000', '2024-06-25 20:00:00.000'); INSERT INTO "public"."permission" VALUES ('1792779493541343266', '1346358560427216896', '1792749362445840485', '2024-06-25 20:00:00.000', '2024-06-25 20:00:00.000'); INSERT INTO "public"."permission" VALUES ('1792779493541343267', '1346358560427216896', '1792749362445840486', '2024-06-25 20:00:00.000', '2024-06-25 20:00:00.000'); + +ALTER TABLE "public"."selector" ADD COLUMN namespace_id VARCHAR(50) NULL; +COMMENT ON COLUMN "public"."selector"."namespace_id" IS 'namespaceId'; \ No newline at end of file diff --git a/db/upgrade/2.6.1-upgrade-2.7.0-oracle.sql b/db/upgrade/2.6.1-upgrade-2.7.0-oracle.sql index 8b8ec0c45d65..24b58730d598 100755 --- a/db/upgrade/2.6.1-upgrade-2.7.0-oracle.sql +++ b/db/upgrade/2.6.1-upgrade-2.7.0-oracle.sql @@ -214,3 +214,6 @@ INSERT /*+ IGNORE_ROW_ON_DUPKEY_INDEX (permission(id)) */ INTO permission (id, o INSERT /*+ IGNORE_ROW_ON_DUPKEY_INDEX (permission(id)) */ INTO permission (id, object_id, resource_id) VALUES ('1792779493541343265', '1346358560427216896', '1792749362445840484'); INSERT /*+ IGNORE_ROW_ON_DUPKEY_INDEX (permission(id)) */ INTO permission (id, object_id, resource_id) VALUES ('1792779493541343266', '1346358560427216896', '1792749362445840485'); INSERT /*+ IGNORE_ROW_ON_DUPKEY_INDEX (permission(id)) */ INTO permission (id, object_id, resource_id) VALUES ('1792779493541343267', '1346358560427216896', '1792749362445840486'); + +ALTER TABLE selector ADD namespace_id VARCHAR2(50) NULL; +COMMENT ON COLUMN selector.namespace_id IS 'namespaceId'; \ No newline at end of file diff --git a/db/upgrade/2.6.1-upgrade-2.7.0-pg.sql b/db/upgrade/2.6.1-upgrade-2.7.0-pg.sql index 36bab538dcbe..55d138e48776 100755 --- a/db/upgrade/2.6.1-upgrade-2.7.0-pg.sql +++ b/db/upgrade/2.6.1-upgrade-2.7.0-pg.sql @@ -189,3 +189,6 @@ INSERT INTO "public"."permission" VALUES ('1792779493541343264', '13463585604272 INSERT INTO "public"."permission" VALUES ('1792779493541343265', '1346358560427216896', '1792749362445840484', '2024-06-25 20:00:00.000', '2024-06-25 20:00:00.000'); INSERT INTO "public"."permission" VALUES ('1792779493541343266', '1346358560427216896', '1792749362445840485', '2024-06-25 20:00:00.000', '2024-06-25 20:00:00.000'); INSERT INTO "public"."permission" VALUES ('1792779493541343267', '1346358560427216896', '1792749362445840486', '2024-06-25 20:00:00.000', '2024-06-25 20:00:00.000'); + +ALTER TABLE "public"."selector" ADD COLUMN namespace_id VARCHAR(50) NULL; +COMMENT ON COLUMN "public"."selector"."namespace_id" IS 'namespaceId'; \ No newline at end of file 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 c7df3cd090fd..46c36cd6fe76 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 @@ -44,10 +44,7 @@ import org.springframework.web.bind.annotation.RequestParam; import javax.validation.Valid; -import javax.validation.constraints.NotBlank; -import javax.validation.constraints.NotEmpty; import javax.validation.constraints.NotNull; -import java.util.List; /** * this is selector controller. @@ -68,6 +65,7 @@ public SelectorController(final SelectorService selectorService) { * @param name selector name. * @param currentPage current page. * @param pageSize page size. + * @param namespaceId namespaceId. * @return {@linkplain ShenyuAdminResult} */ @GetMapping("") @@ -89,13 +87,14 @@ public AdminResult> querySelectors(final String pluginId * detail selector. * * @param id selector id. + * @param namespaceId namespaceId. * @return {@linkplain ShenyuAdminResult} */ - @GetMapping("/{id}") + @GetMapping("/id={id}&namespaceId={namespaceId}") public ShenyuAdminResult detailSelector(@PathVariable("id") @Valid @Existed(provider = SelectorMapper.class, message = "selector is not existed") final String id, - @Existed(message = "namespaceId is not existed", - provider = NamespaceMapper.class) final String namespaceId) { + @PathVariable("namespaceId") @Valid + @Existed(provider = NamespaceMapper.class, message = "namespaceId is not existed") final String namespaceId) { SelectorVO selectorVO = selectorService.findById(id, namespaceId); return ShenyuAdminResult.success(ShenyuResultMessage.DETAIL_SUCCESS, selectorVO); } @@ -119,10 +118,9 @@ public ShenyuAdminResult createSelector(@Valid @RequestBody final SelectorDTO se * @param selectorDTO selector. * @return {@linkplain ShenyuAdminResult} */ - @PutMapping("/{id}") + @PutMapping("/id={id}") public ShenyuAdminResult updateSelector(@PathVariable("id") @Valid - @Existed(provider = SelectorMapper.class, - message = "selector is not existed") final String id, + @Existed(provider = SelectorMapper.class, message = "selector is not existed") final String id, @Valid @RequestBody final SelectorDTO selectorDTO) { selectorDTO.setId(id); Integer updateCount = selectorService.createOrUpdate(selectorDTO); 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 f5b4187015a7..7081466fe8a4 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 @@ -65,11 +65,11 @@ public interface NamespacePluginRelMapper extends ExistProvider { /** * select plugin by namespacePluginId. * - * @param id primary key. + * @param pluginId primary key. * @param namespaceId namespace id. * @return {@linkplain PluginVO} */ - NamespacePluginVO selectById(String id, String namespaceId); + NamespacePluginVO selectById(String pluginId, String namespaceId); /** * select plugin by pluginId. diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/SelectorMapper.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/SelectorMapper.java index c11eea7ca17a..171a21d21918 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/SelectorMapper.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/SelectorMapper.java @@ -47,7 +47,7 @@ public interface SelectorMapper extends ExistProvider { /** * select selector by id. * - * @param id primary key. + * @param id primary key. * @param namespaceId namespaceId. * @return {@linkplain SelectorDO} */ @@ -80,32 +80,36 @@ public interface SelectorMapper extends ExistProvider { /** * Find by plugin id list. * - * @param pluginId the plugin id + * @param pluginId the plugin id + * @param namespaceId namespaceId. * @return the list */ - List findByPluginId(String pluginId); + List findByPluginId(String pluginId, String namespaceId); /** * Find by plugin id list. * - * @param pluginIds the plugin ids + * @param pluginIds the plugin ids + * @param namespaceId namespaceId. * @return the list */ - List findByPluginIds(List pluginIds); + List findByPluginIds(@Param("list") List pluginIds, String namespaceId); /** * select select by name. * - * @param name the name + * @param name the name + * @param namespaceId namespaceId. * @return selector do list */ - List selectByName(String name,String namespaceId); + List selectByName(String name, String namespaceId); /** * Find by name and plugin id selector do. * - * @param name the name - * @param pluginId the plugin id + * @param name the name + * @param pluginId the plugin id + * @param namespaceId namespaceId. * @return the selector do */ SelectorDO findByNameAndPluginId(@Param("name") String name, @Param("pluginId") String pluginId, @Param("namespaceId") String namespaceId); @@ -208,7 +212,7 @@ public interface SelectorMapper extends ExistProvider { /** * update status. * - * @param id id + * @param id id * @param enabled enabled * @return result */ diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/dto/BatchNamespaceCommonDTO.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/dto/BatchNamespaceCommonDTO.java index 3a3b4d4a5deb..ff6c8e8e58ea 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/dto/BatchNamespaceCommonDTO.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/dto/BatchNamespaceCommonDTO.java @@ -17,6 +17,9 @@ package org.apache.shenyu.admin.model.dto; +import org.apache.shenyu.admin.mapper.NamespaceMapper; +import org.apache.shenyu.admin.validation.annotation.Existed; + import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotEmpty; import javax.validation.constraints.NotNull; @@ -37,6 +40,7 @@ public class BatchNamespaceCommonDTO implements Serializable { private Boolean enabled; @NotEmpty + @Existed(message = "namespaceId is not existed", provider = NamespaceMapper.class) private String namespaceId; /** diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/dto/SelectorDTO.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/dto/SelectorDTO.java index 7bdfeb99ddf7..59ef1bfa64a4 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/dto/SelectorDTO.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/dto/SelectorDTO.java @@ -20,7 +20,6 @@ import org.apache.shenyu.admin.mapper.NamespaceMapper; import org.apache.shenyu.admin.mapper.PluginMapper; import org.apache.shenyu.admin.mapper.SelectorMapper; -import org.apache.shenyu.admin.model.entity.SelectorDO; import org.apache.shenyu.admin.validation.annotation.Existed; import org.hibernate.validator.constraints.Range; @@ -137,7 +136,8 @@ public SelectorDTO(final String id, final String handle, @Valid final List selectorConditions, @NotNull final Boolean matchRestful, - @Valid final List selectorRules, String namespaceId) { + @Valid final List selectorRules, + @Valid final String namespaceId) { this.id = id; this.pluginId = pluginId; this.name = name; @@ -416,7 +416,7 @@ public static SelectorDTO.SelectorDTOBuilder builder() { } @Override - public boolean equals(Object o) { + public boolean equals(final Object o) { if (this == o) { return true; } 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 aba8ba41ab0d..f3275625ed0d 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 @@ -19,6 +19,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; @@ -222,6 +223,37 @@ public static PluginDO buildPluginDO(final PluginDTO pluginDTO) { }).orElse(null); } + /** + * build pluginDO. + * + * @param namespacePluginVO {@linkplain NamespacePluginVO} + * @return {@linkplain PluginDO} + */ + public static PluginDO buildPluginDO(final NamespacePluginVO namespacePluginVO) { + return Optional.ofNullable(namespacePluginVO).map(item -> { + Timestamp currentTime = new Timestamp(System.currentTimeMillis()); + PluginDO pluginDO = PluginDO.builder() + .name(item.getName()) + .config(item.getConfig()) + .enabled(item.getEnabled()) + .role(item.getRole()) + .sort(item.getSort()) + .dateUpdated(currentTime) + .build(); + + if (StringUtils.isEmpty(item.getId())) { + pluginDO.setId(UUIDUtils.getInstance().generateShortUuid()); + pluginDO.setDateCreated(currentTime); + } else { + pluginDO.setId(item.getId()); + } + if (Objects.nonNull(item.getFile())) { + pluginDO.setPluginJar(Base64.decode(item.getFile())); + } + return pluginDO; + }).orElse(null); + } + @Override public boolean equals(final Object o) { if (this == o) { diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/entity/SelectorDO.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/entity/SelectorDO.java index 0a44040feb49..f2cdc9df0018 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/entity/SelectorDO.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/entity/SelectorDO.java @@ -329,7 +329,7 @@ public static SelectorDO.SelectorDOBuilder builder() { } @Override - public boolean equals(Object o) { + public boolean equals(final Object o) { if (this == o) { return true; } diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/event/plugin/BatchPluginDeletedEvent.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/event/plugin/BatchPluginDeletedEvent.java index a1c74bdec60c..d4d43b8af37f 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/event/plugin/BatchPluginDeletedEvent.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/event/plugin/BatchPluginDeletedEvent.java @@ -33,16 +33,20 @@ public class BatchPluginDeletedEvent extends BatchPluginChangedEvent { private final List deletedPluginIds; + + private final String namespaceId; /** * Create a new {@code PluginChangedEvent}.operator is unknown. * - * @param source Current plugin state - * @param operator operator + * @param source Current plugin state + * @param operator operator + * @param namespaceId namespaceId */ - public BatchPluginDeletedEvent(final Collection source, final String operator) { + public BatchPluginDeletedEvent(final Collection source, final String operator, final String namespaceId) { super(source, null, EventTypeEnum.PLUGIN_DELETE, operator); this.deletedPluginIds = ListUtil.map(source, BaseDO::getId); + this.namespaceId = namespaceId; } @Override @@ -74,4 +78,13 @@ public List getPlugins() { public List getDeletedPluginIds() { return deletedPluginIds; } + + /** + * Gets the namespace id. + * + * @return the plugin handle list + */ + public String getNamespaceId() { + return namespaceId; + } } diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/query/SelectorConditionQuery.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/query/SelectorConditionQuery.java index c1be0d227166..c315181e3acc 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/query/SelectorConditionQuery.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/query/SelectorConditionQuery.java @@ -81,7 +81,7 @@ public void setNamespaceId(final String namespaceId) { } @Override - public boolean equals(Object o) { + public boolean equals(final Object o) { if (this == o) { return true; } diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/query/SelectorQuery.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/query/SelectorQuery.java index 89dd5d235d4e..2b44be2711dd 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/query/SelectorQuery.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/query/SelectorQuery.java @@ -161,7 +161,7 @@ public void setNamespaceId(final String namespaceId) { } @Override - public boolean equals(Object o) { + public boolean equals(final Object o) { if (this == o) { return true; } diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/vo/SelectorVO.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/vo/SelectorVO.java index be222a6a0d29..0edbb67d2e3a 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/vo/SelectorVO.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/vo/SelectorVO.java @@ -542,6 +542,24 @@ public static SelectorVO buildSelectorVO(final SelectorDO selectorDO) { return buildSelectorVO(selectorDO, null); } + /** + * build selectorVO. + * + * @param selectorDO {@linkplain SelectorDO} + * @param selectorConditions {@linkplain List} + * @return {@linkplain SelectorVO} + */ + public static SelectorVO buildSelectorVO(final SelectorDO selectorDO, + final List selectorConditions) { + return new SelectorVO(selectorDO.getId(), selectorDO.getPluginId(), selectorDO.getName(), selectorDO.getMatchMode(), + MatchModeEnum.getMatchModeByCode(selectorDO.getMatchMode()), selectorDO.getType(), + SelectorTypeEnum.getSelectorTypeByCode(selectorDO.getType()), selectorDO.getSort(), + selectorDO.getEnabled(), selectorDO.getLoged(), selectorDO.getContinued(), + selectorDO.getMatchRestful(), selectorDO.getHandle(), selectorConditions, + DateUtils.localDateTimeToString(selectorDO.getDateCreated().toLocalDateTime()), + DateUtils.localDateTimeToString(selectorDO.getDateUpdated().toLocalDateTime())); + } + /** * Gets the value of namespaceId. * @@ -560,20 +578,4 @@ public void setNamespaceId(final String namespaceId) { this.namespaceId = namespaceId; } - /** - * build selectorVO. - * - * @param selectorDO {@linkplain SelectorDO} - * @param selectorConditions {@linkplain List} - * @return {@linkplain SelectorVO} - */ - public static SelectorVO buildSelectorVO(final SelectorDO selectorDO, final List selectorConditions) { - return new SelectorVO(selectorDO.getId(), selectorDO.getPluginId(), selectorDO.getName(), selectorDO.getMatchMode(), - MatchModeEnum.getMatchModeByCode(selectorDO.getMatchMode()), selectorDO.getType(), - SelectorTypeEnum.getSelectorTypeByCode(selectorDO.getType()), selectorDO.getSort(), - selectorDO.getEnabled(), selectorDO.getLoged(), selectorDO.getContinued(), - selectorDO.getMatchRestful(), selectorDO.getHandle(), selectorConditions, - DateUtils.localDateTimeToString(selectorDO.getDateCreated().toLocalDateTime()), - DateUtils.localDateTimeToString(selectorDO.getDateUpdated().toLocalDateTime())); - } } diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/SelectorService.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/SelectorService.java index 6d8f12c49cad..f1ea40e75e04 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/SelectorService.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/SelectorService.java @@ -107,7 +107,7 @@ default int createOrUpdate(SelectorDTO selectorDTO) { /** * delete selectors. * - * @param ids primary key. + * @param ids primary key. * @param namespaceId namespaceId. * @return rows int */ @@ -116,19 +116,20 @@ default int createOrUpdate(SelectorDTO selectorDTO) { /** * find selector by id. * - * @param id primary key. + * @param id primary key. * @param namespaceId namespaceId. * @return {@linkplain SelectorVO} */ - SelectorVO findById(String id,String namespaceId); + SelectorVO findById(String id, String namespaceId); /** * find selector by name. * - * @param name the name + * @param name the name + * @param namespaceId namespaceId. + * Therefore, it is recommended to: {@linkplain SelectorService#findListByName(java.lang.String, java.lang.String)} * @return selector do * @deprecated sice 2.6.0 Deprecated. By querying under this condition, multiple data are usually obtained. - * Therefore, it is recommended to: {@linkplain SelectorService#findListByName(java.lang.String,java.lang.String)} */ @Deprecated SelectorDO findByName(String name, String namespaceId); @@ -136,7 +137,8 @@ default int createOrUpdate(SelectorDTO selectorDTO) { /** * find selector list by name. * - * @param name name + * @param name name + * @param namespaceId namespaceId. * @return list */ List findListByName(String name, String namespaceId); @@ -154,8 +156,9 @@ default int createOrUpdate(SelectorDTO selectorDTO) { /** * findByNameAndPluginNameForUpdate. * - * @param name name - * @param pluginName pluginName + * @param name name + * @param pluginName pluginName + * @param namespaceId namespaceId. * @return SelectorDO */ SelectorDO findByNameAndPluginNameForUpdate(String name, String pluginName, String namespaceId); @@ -172,7 +175,8 @@ default int createOrUpdate(SelectorDTO selectorDTO) { /** * Build by name selector data. * - * @param name the name + * @param name the name + * @param namespaceId namespaceId. * @return the selector data */ SelectorData buildByName(String name, String namespaceId); @@ -180,8 +184,8 @@ default int createOrUpdate(SelectorDTO selectorDTO) { /** * Build by name selector data. * - * @param name the name - * @param pluginName the plugin name + * @param name the name + * @param pluginName the plugin name * @param namespaceId the namespaceId * @return the selector data */ @@ -206,10 +210,11 @@ default int createOrUpdate(SelectorDTO selectorDTO) { /** * Find by plugin id list. * - * @param pluginId the plugin id + * @param pluginId the plugin id + * @param namespaceId the namespaceId * @return the list */ - List findByPluginId(String pluginId); + List findByPluginId(String pluginId, String namespaceId); /** * List all list. @@ -236,8 +241,8 @@ default int createOrUpdate(SelectorDTO selectorDTO) { /** * Enabled string. * - * @param ids the ids - * @param enabled the enable + * @param ids the ids + * @param enabled the enable * @param namespaceId namespaceId * @return the result */ diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/SelectorServiceImpl.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/SelectorServiceImpl.java index 31ff51fc02dc..027d2062aabd 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/SelectorServiceImpl.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/SelectorServiceImpl.java @@ -268,6 +268,7 @@ public int updateSelective(final SelectorDO selectorDO) { @Override @Transactional(rollbackFor = Exception.class) public int delete(final List ids, final String namespaceId) { + //todo:[Namespace] To be renovated final List selectors = selectorMapper.selectByIdSet(new TreeSet<>(ids)); List pluginDOS = pluginMapper.selectByIds(ListUtil.map(selectors, SelectorDO::getPluginId)); unbindDiscovery(selectors, pluginDOS); @@ -376,7 +377,7 @@ public List findByNameAndPluginNames(final String name, final List listByPage(final SelectorQuery selectorQuery) { } @Override - public List findByPluginId(final String pluginId) { - return this.buildSelectorDataList(selectorMapper.findByPluginId(pluginId)); + public List findByPluginId(final String pluginId, final String namespaceId) { + return this.buildSelectorDataList(selectorMapper.findByPluginId(pluginId, namespaceId)); } @Override @@ -499,7 +500,7 @@ public Boolean enabled(final List ids, final Boolean enabled, final Stri */ @EventListener(value = BatchPluginDeletedEvent.class) public void onPluginDeleted(final BatchPluginDeletedEvent event) { - deleteSelector(selectorMapper.findByPluginIds(event.getDeletedPluginIds()), event.getPlugins()); + deleteSelector(selectorMapper.findByPluginIds(event.getDeletedPluginIds(), event.getNamespaceId()), event.getPlugins()); } private void createCondition(final String selectorId, final List selectorConditions) { diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/SyncDataServiceImpl.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/SyncDataServiceImpl.java index 7f962d8b5530..f755dd451f5c 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/SyncDataServiceImpl.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/SyncDataServiceImpl.java @@ -131,7 +131,7 @@ public boolean syncPluginData(final String pluginId, final String namespaceId) { eventPublisher.publishEvent(new DataChangedEvent(ConfigGroupEnum.PLUGIN, DataEventTypeEnum.UPDATE, Collections.singletonList(PluginTransfer.INSTANCE.mapToData(namespacePluginVO)))); - List selectorDataList = selectorService.findByPluginId(pluginId); + List selectorDataList = selectorService.findByPluginId(pluginId, namespaceId); if (!CollectionUtils.isEmpty(selectorDataList)) { eventPublisher.publishEvent(new DataChangedEvent(ConfigGroupEnum.SELECTOR, DataEventTypeEnum.REFRESH, selectorDataList)); diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/UpstreamCheckService.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/UpstreamCheckService.java index fa16d4192236..ef4ade89946d 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/UpstreamCheckService.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/UpstreamCheckService.java @@ -78,6 +78,8 @@ import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; +import static org.apache.shenyu.common.constant.AdminConstants.SYS_DEFAULT_NAMESPACE_NAMESPACE_ID; + /** * This is the upstream check service. */ @@ -432,7 +434,8 @@ public void fetchUpstreamData() { } Map pluginMap = pluginDOList.stream().filter(Objects::nonNull) .collect(Collectors.toMap(PluginDO::getId, PluginDO::getName, (value1, value2) -> value1)); - final List selectorDOList = selectorMapper.findByPluginIds(new ArrayList<>(pluginMap.keySet())); + // todo:[To be refactored with namespace] Temporarily hardcode + final List selectorDOList = selectorMapper.findByPluginIds(new ArrayList<>(pluginMap.keySet()), SYS_DEFAULT_NAMESPACE_NAMESPACE_ID); long currentTimeMillis = System.currentTimeMillis(); Optional.ofNullable(selectorDOList).orElseGet(ArrayList::new).stream() .filter(Objects::nonNull) diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/publish/NamespacePluginEventPublisher.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/publish/NamespacePluginEventPublisher.java index 572fb528940c..c4748abcc504 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/publish/NamespacePluginEventPublisher.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/publish/NamespacePluginEventPublisher.java @@ -18,9 +18,11 @@ package org.apache.shenyu.admin.service.publish; import org.apache.shenyu.admin.listener.DataChangedEvent; +import org.apache.shenyu.admin.model.entity.PluginDO; import org.apache.shenyu.admin.model.enums.EventTypeEnum; import org.apache.shenyu.admin.model.event.AdminDataModelChangedEvent; import org.apache.shenyu.admin.model.event.plugin.BatchNamespacePluginChangedEvent; +import org.apache.shenyu.admin.model.event.plugin.BatchPluginDeletedEvent; import org.apache.shenyu.admin.model.event.plugin.NamespacePluginChangedEvent; import org.apache.shenyu.admin.model.event.plugin.NamespacePluginCreatedEvent; import org.apache.shenyu.admin.model.vo.NamespacePluginVO; @@ -33,6 +35,7 @@ import java.util.Collection; import java.util.Collections; +import java.util.List; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -77,9 +80,21 @@ public void onDeleted(final NamespacePluginVO namespacePluginVO) { @Override public void onDeleted(final Collection namespacePlugin) { - publish(new BatchNamespacePluginChangedEvent(namespacePlugin, null, EventTypeEnum.PLUGIN_UPDATE, SessionUtil.visitorName())); - publisher.publishEvent(new DataChangedEvent(ConfigGroupEnum.PLUGIN, DataEventTypeEnum.UPDATE, + String namespaceId = ((Collection) namespacePlugin) + .stream() + .map(NamespacePluginVO.class::cast) + .findFirst() + .map(NamespacePluginVO::getNamespaceId) + .orElse(""); + List pluginDOList = ((Collection) namespacePlugin) + .stream() + .map(NamespacePluginVO.class::cast) + .map(PluginDO::buildPluginDO) + .collect(Collectors.toList()); + publish(new BatchPluginDeletedEvent(pluginDOList, SessionUtil.visitorName(), namespaceId)); + publisher.publishEvent(new DataChangedEvent(ConfigGroupEnum.PLUGIN, DataEventTypeEnum.DELETE, namespacePlugin.stream().map(PluginTransfer.INSTANCE::mapToData).collect(Collectors.toList()))); + } /** diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/publish/PluginEventPublisher.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/publish/PluginEventPublisher.java index 35268cabf763..7ae6a709f09e 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/publish/PluginEventPublisher.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/publish/PluginEventPublisher.java @@ -21,7 +21,6 @@ import org.apache.shenyu.admin.model.enums.EventTypeEnum; import org.apache.shenyu.admin.model.event.AdminDataModelChangedEvent; import org.apache.shenyu.admin.model.event.plugin.BatchPluginChangedEvent; -import org.apache.shenyu.admin.model.event.plugin.BatchPluginDeletedEvent; import org.apache.shenyu.admin.model.event.plugin.PluginChangedEvent; import org.apache.shenyu.admin.model.event.plugin.PluginCreatedEvent; import org.apache.shenyu.admin.utils.SessionUtil; @@ -72,7 +71,7 @@ public void onUpdated(final PluginDO plugin, final PluginDO before) { public void onDeleted(final PluginDO plugin) { publish(new PluginChangedEvent(plugin, null, EventTypeEnum.PLUGIN_DELETE, SessionUtil.visitorName())); } - + /** * on plugin deleted. * @@ -80,9 +79,9 @@ public void onDeleted(final PluginDO plugin) { */ @Override public void onDeleted(final Collection plugins) { - publish(new BatchPluginDeletedEvent(plugins, SessionUtil.visitorName())); + } - + /** * on plugin batch enabled. * diff --git a/shenyu-admin/src/main/resources/mappers/NamespacePluginRelMapper.xml b/shenyu-admin/src/main/resources/mappers/NamespacePluginRelMapper.xml index 39895c5db02a..482eea0a8e0b 100644 --- a/shenyu-admin/src/main/resources/mappers/NamespacePluginRelMapper.xml +++ b/shenyu-admin/src/main/resources/mappers/NamespacePluginRelMapper.xml @@ -127,7 +127,7 @@ ( SELECT FROM plugin_ns_rel - WHERE id = #{id, jdbcType=VARCHAR} + WHERE plugin_id = #{pluginId, jdbcType=VARCHAR} and namespace_id = #{namespaceId, jdbcType=VARCHAR} ) pnr diff --git a/shenyu-admin/src/main/resources/mappers/selector-sqlmap.xml b/shenyu-admin/src/main/resources/mappers/selector-sqlmap.xml index f8d30d94f876..143ee4e6898a 100644 --- a/shenyu-admin/src/main/resources/mappers/selector-sqlmap.xml +++ b/shenyu-admin/src/main/resources/mappers/selector-sqlmap.xml @@ -129,9 +129,9 @@ AND plugin_id = #{pluginId, jdbcType=VARCHAR} - AND (namespace_id = #{namespaceId, jdbcType=VARCHAR}) + AND (namespace_id = #{namespaceId, jdbcType=VARCHAR} OR - (namespace_id IS NULL) + namespace_id IS NULL) AND namespace_id = #{namespaceId, jdbcType=VARCHAR} @@ -173,6 +173,16 @@ FROM selector WHERE plugin_id = #{pluginId, jdbcType=VARCHAR} + + + AND (namespace_id = #{namespaceId, jdbcType=VARCHAR} + OR + namespace_id IS NULL) + + + AND namespace_id = #{namespaceId, jdbcType=VARCHAR} + + @@ -482,16 +431,7 @@ WHERE id = #{id, jdbcType=VARCHAR} - - - AND (namespace_id = #{namespaceId, jdbcType=VARCHAR} - OR - namespace_id IS NULL) - - - AND namespace_id = #{namespaceId, jdbcType=VARCHAR} - - + AND namespace_id = #{namespaceId, jdbcType=VARCHAR} From afd48dba9f44a0bfeba689ee9c54fcebc61b2101 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=98xcsnx=E2=80=99?= <‘1192709687@qq.com’> Date: Sat, 3 Aug 2024 21:55:47 +0800 Subject: [PATCH 26/61] trigger ci --- .../apache/shenyu/admin/service/impl/SelectorServiceImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/SelectorServiceImpl.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/SelectorServiceImpl.java index 4c61f69e9748..73298e4869cf 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/SelectorServiceImpl.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/SelectorServiceImpl.java @@ -175,7 +175,7 @@ public String registerDefault(final SelectorDTO selectorDTO) { @Override public String registerDefault(final MetaDataRegisterDTO dto, final String pluginName, final String selectorHandler) { String contextPath = ContextPathUtils.buildContextPath(dto.getContextPath(), dto.getAppName()); - // todo:[To be refactored with namespace] Temporarily hardcode + // todo:[To be refactored with namespace] Temporarily hardcode SelectorDO selectorDO = findByNameAndPluginName(contextPath, pluginName, SYS_DEFAULT_NAMESPACE_NAMESPACE_ID); if (Objects.isNull(selectorDO)) { SelectorDTO selectorDTO = SelectorUtil.buildSelectorDTO(contextPath, pluginMapper.selectByName(pluginName).getId()); From a2d9acb31df62416e11e55e2e5c8bc4a1c1f819e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=98xcsnx=E2=80=99?= <‘1192709687@qq.com’> Date: Mon, 5 Aug 2024 20:47:05 +0800 Subject: [PATCH 27/61] fix --- .../admin/controller/SelectorController.java | 4 +- .../shenyu/admin/mapper/DiscoveryMapper.java | 2 +- .../admin/mapper/DiscoveryUpstreamMapper.java | 6 +- .../shenyu/admin/mapper/NamespaceMapper.java | 2 +- .../mapper/NamespacePluginRelMapper.java | 13 ++- .../admin/mapper/ProxySelectorMapper.java | 6 +- .../shenyu/admin/mapper/SelectorMapper.java | 12 +-- .../apache/shenyu/admin/mapper/TagMapper.java | 2 +- .../shenyu/admin/model/dto/SelectorDTO.java | 4 +- .../shenyu/admin/model/entity/SelectorDO.java | 15 +++- .../BatchNamespacePluginDeletedEvent.java | 90 +++++++++++++++++++ .../event/plugin/BatchPluginDeletedEvent.java | 16 +--- .../impl/NamespacePluginServiceImpl.java | 18 ++-- .../admin/service/impl/PluginServiceImpl.java | 13 ++- .../service/impl/ResourceServiceImpl.java | 9 +- .../service/impl/SelectorServiceImpl.java | 14 +-- .../service/impl/UpstreamCheckService.java | 2 +- .../NamespacePluginEventPublisher.java | 4 +- .../service/publish/PluginEventPublisher.java | 3 +- .../mappers/NamespacePluginRelMapper.xml | 9 +- .../resources/mappers/selector-sqlmap.xml | 6 +- .../admin/mapper/ResourceMapperTest.java | 2 +- .../admin/mapper/SelectorMapperTest.java | 4 +- ...BatchNamespacePluginDeletedEventTest.java} | 8 +- .../admin/service/PermissionServiceTest.java | 2 +- .../admin/service/PluginServiceTest.java | 8 +- .../admin/service/SelectorServiceTest.java | 4 +- .../service/UpstreamCheckServiceTest.java | 2 +- .../common/constant/AdminConstants.java | 5 ++ 29 files changed, 195 insertions(+), 90 deletions(-) create mode 100644 shenyu-admin/src/main/java/org/apache/shenyu/admin/model/event/plugin/BatchNamespacePluginDeletedEvent.java rename shenyu-admin/src/test/java/org/apache/shenyu/admin/model/event/plugin/{BatchPluginDeletedEventTest.java => BatchNamespacePluginDeletedEventTest.java} (88%) 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 c5b5899bcbb3..840cfa294dfe 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 @@ -89,7 +89,7 @@ public AdminResult> querySelectors(final String pluginId * @param namespaceId namespaceId. * @return {@linkplain ShenyuAdminResult} */ - @GetMapping("/id={id}&namespaceId={namespaceId}") + @GetMapping("{id}/{namespaceId}") public ShenyuAdminResult detailSelector(@PathVariable("id") @Valid @Existed(provider = SelectorMapper.class, message = "selector is not existed") final String id, @PathVariable("namespaceId") @Valid @@ -117,7 +117,7 @@ public ShenyuAdminResult createSelector(@Valid @RequestBody final SelectorDTO se * @param selectorDTO selector. * @return {@linkplain ShenyuAdminResult} */ - @PutMapping("/id={id}") + @PutMapping("{id}") public ShenyuAdminResult updateSelector(@PathVariable("id") @Valid @Existed(provider = SelectorMapper.class, message = "selector is not existed") final String id, @Valid @RequestBody final SelectorDTO selectorDTO) { diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/DiscoveryMapper.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/DiscoveryMapper.java index 0ea3125ece1d..21708e18b83d 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/DiscoveryMapper.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/DiscoveryMapper.java @@ -49,7 +49,7 @@ public interface DiscoveryMapper extends ExistProvider { DiscoveryDO selectById(String id); /** - * selectAll. + * selectAllByNamespaceId. * * @return discoveryDOList */ diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/DiscoveryUpstreamMapper.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/DiscoveryUpstreamMapper.java index cecf31dfdca6..019e7205c505 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/DiscoveryUpstreamMapper.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/DiscoveryUpstreamMapper.java @@ -38,7 +38,7 @@ public interface DiscoveryUpstreamMapper extends ExistProvider { Boolean existed(@Param("id") Serializable key); /** - * selectByIds. + * selectByIdsAndNamespaceId. * * @param ids id list * @return discoveryUpstreamDO list @@ -46,7 +46,7 @@ public interface DiscoveryUpstreamMapper extends ExistProvider { List selectByIds(@Param("ids") List ids); /** - * selectAll. + * selectAllByNamespaceId. * * @return discoveryUpstreamDO list */ @@ -102,7 +102,7 @@ public interface DiscoveryUpstreamMapper extends ExistProvider { int updateSelective(DiscoveryUpstreamDO discoveryUpstreamDO); /** - * deleteByIds. + * deleteByIdsAndNamespaceId. * * @param ids id list * @return rows int diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/NamespaceMapper.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/NamespaceMapper.java index 0ed1021b0204..06b16e6c9dda 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/NamespaceMapper.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/NamespaceMapper.java @@ -59,7 +59,7 @@ public interface NamespaceMapper extends ExistProvider { /** - * selectAll. + * selectAllByNamespaceId. * * @param name name. * @return namespaceDOList 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 7081466fe8a4..0c8214e65f15 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 @@ -69,16 +69,15 @@ public interface NamespacePluginRelMapper extends ExistProvider { * @param namespaceId namespace id. * @return {@linkplain PluginVO} */ - NamespacePluginVO selectById(String pluginId, String namespaceId); + NamespacePluginVO selectByPluginIdAndNamespaceId(String pluginId, String namespaceId); /** * select plugin by pluginId. * * @param pluginId primary key. - * @param namespaceId namespace id. * @return {@linkplain PluginVO} */ - NamespacePluginVO selectByPluginId(String pluginId, String namespaceId); + NamespacePluginVO selectByPluginId(String pluginId); /** * search by condition. @@ -114,7 +113,7 @@ public interface NamespacePluginRelMapper extends ExistProvider { * @param namespaceId namespace id. * @return {@linkplain NamespacePluginRelDO} */ - List selectByIds(List ids, String namespaceId); + List selectByIdsAndNamespaceId(List ids, String namespaceId); /** @@ -124,7 +123,7 @@ public interface NamespacePluginRelMapper extends ExistProvider { * @param namespaceId namespace id. * @return rows int */ - int deleteByIds(List ids, String namespaceId); + int deleteByIdsAndNamespaceId(List ids, String namespaceId); /** * select all. @@ -132,14 +131,14 @@ public interface NamespacePluginRelMapper extends ExistProvider { * @param namespaceId namespace id. * @return {@linkplain List} */ - List selectAll(String namespaceId); + List selectAllByNamespaceId(String namespaceId); /** * select all. * * @return {@linkplain List} */ - List selectAll(); + List selectAllByNamespaceId(); /** * enable data by a list of ids. diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/ProxySelectorMapper.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/ProxySelectorMapper.java index 71e30cae8226..c235dff5ad42 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/ProxySelectorMapper.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/ProxySelectorMapper.java @@ -79,7 +79,7 @@ public interface ProxySelectorMapper extends ExistProvider { ProxySelectorDO selectById(@Param("id") String id); /** - * selectByIds. + * selectByIdsAndNamespaceId. * * @param ids id list * @return proxySelectorDO list @@ -87,7 +87,7 @@ public interface ProxySelectorMapper extends ExistProvider { List selectByIds(@Param("ids") List ids); /** - * deleteByIds. + * deleteByIdsAndNamespaceId. * * @param ids id list * @return rows int @@ -113,7 +113,7 @@ public interface ProxySelectorMapper extends ExistProvider { List selectByDiscoveryId(@Param("discoveryId") String discoveryId); /** - * selectAll. + * selectAllByNamespaceId. * * @return ProxySelectorDOList */ diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/SelectorMapper.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/SelectorMapper.java index 171a21d21918..75a71860dad8 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/SelectorMapper.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/SelectorMapper.java @@ -84,16 +84,16 @@ public interface SelectorMapper extends ExistProvider { * @param namespaceId namespaceId. * @return the list */ - List findByPluginId(String pluginId, String namespaceId); + List findByPluginIdAndNamespaceId(String pluginId, String namespaceId); /** - * Find by plugin id list. + * Find by plugin id and namespace id list. * * @param pluginIds the plugin ids * @param namespaceId namespaceId. * @return the list */ - List findByPluginIds(@Param("list") List pluginIds, String namespaceId); + List findByPluginIdsAndNamespaceId(@Param("list") List pluginIds, String namespaceId); /** * select select by name. @@ -102,7 +102,7 @@ public interface SelectorMapper extends ExistProvider { * @param namespaceId namespaceId. * @return selector do list */ - List selectByName(String name, String namespaceId); + List selectByNameAndNamespaceId(String name, String namespaceId); /** * Find by name and plugin id selector do. @@ -112,7 +112,9 @@ public interface SelectorMapper extends ExistProvider { * @param namespaceId namespaceId. * @return the selector do */ - SelectorDO findByNameAndPluginId(@Param("name") String name, @Param("pluginId") String pluginId, @Param("namespaceId") String namespaceId); + SelectorDO findByNameAndPluginId(@Param("name") String name, + @Param("pluginId") String pluginId, + @Param("namespaceId") String namespaceId); /** * count selector by query. diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/TagMapper.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/TagMapper.java index b01b9b57d257..822f9cd77fcc 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/TagMapper.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/TagMapper.java @@ -119,7 +119,7 @@ public interface TagMapper extends ExistProvider { int deleteAllData(); /** - * selectByIds. + * selectByIdsAndNamespaceId. * @param list ids * @return List */ diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/dto/SelectorDTO.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/dto/SelectorDTO.java index f914ea12f61c..841582abbbd6 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/dto/SelectorDTO.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/dto/SelectorDTO.java @@ -434,8 +434,8 @@ public boolean equals(final Object o) { @Override public int hashCode() { - return Objects.hash(id, pluginId, name, matchMode, type, sort, enabled, loged, continued, handle, selectorConditions, - matchRestful, selectorRules, namespaceId); + return Objects.hash(id, pluginId, name, matchMode, type, sort, enabled, loged, continued, handle, + selectorConditions, matchRestful, namespaceId); } public static final class SelectorDTOBuilder { diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/entity/SelectorDO.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/entity/SelectorDO.java index f2cdc9df0018..ae69448f3115 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/entity/SelectorDO.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/entity/SelectorDO.java @@ -340,10 +340,17 @@ public boolean equals(final Object o) { return false; } SelectorDO that = (SelectorDO) o; - return Objects.equals(pluginId, that.pluginId) && Objects.equals(name, that.name) && Objects.equals(matchMode, that.matchMode) - && Objects.equals(type, that.type) && Objects.equals(sort, that.sort) && Objects.equals(enabled, that.enabled) - && Objects.equals(loged, that.loged) && Objects.equals(continued, that.continued) && Objects.equals(handle, that.handle) - && Objects.equals(matchRestful, that.matchRestful) && Objects.equals(namespaceId, that.namespaceId); + return Objects.equals(pluginId, that.pluginId) + && Objects.equals(name, that.name) + && Objects.equals(matchMode, that.matchMode) + && Objects.equals(type, that.type) + && Objects.equals(sort, that.sort) + && Objects.equals(enabled, that.enabled) + && Objects.equals(loged, that.loged) + && Objects.equals(continued, that.continued) + && Objects.equals(handle, that.handle) + && Objects.equals(matchRestful, that.matchRestful) + && Objects.equals(namespaceId, that.namespaceId); } @Override diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/event/plugin/BatchNamespacePluginDeletedEvent.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/event/plugin/BatchNamespacePluginDeletedEvent.java new file mode 100644 index 000000000000..87e28af14c53 --- /dev/null +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/event/plugin/BatchNamespacePluginDeletedEvent.java @@ -0,0 +1,90 @@ +/* + * 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.admin.model.event.plugin; + +import org.apache.commons.lang3.StringUtils; +import org.apache.shenyu.admin.model.entity.BaseDO; +import org.apache.shenyu.admin.model.entity.PluginDO; +import org.apache.shenyu.admin.model.enums.EventTypeEnum; +import org.apache.shenyu.common.utils.ListUtil; + +import java.util.Collection; +import java.util.List; +import java.util.stream.Collectors; + +/** + * BatchPluginDeletedEvent. + */ +public class BatchNamespacePluginDeletedEvent extends BatchPluginChangedEvent { + + private final List deletedPluginIds; + + private final String namespaceId; + + /** + * Create a new {@code PluginChangedEvent}.operator is unknown. + * + * @param source Current plugin state + * @param operator operator + * @param namespaceId namespaceId + */ + public BatchNamespacePluginDeletedEvent(final Collection source, final String operator, final String namespaceId) { + super(source, null, EventTypeEnum.PLUGIN_DELETE, operator); + this.deletedPluginIds = ListUtil.map(source, BaseDO::getId); + this.namespaceId = namespaceId; + } + + @Override + public String buildContext() { + final String plugins = ((Collection) getSource()) + .stream() + .map(s -> ((PluginDO) s).getName()) + .collect(Collectors.joining(",")); + return String.format("the plugins[%s] is %s", plugins, StringUtils.lowerCase(getType().getType().toString())); + } + + /** + * get plugins. + * + * @return plugins + */ + public List getPlugins() { + return ((Collection) getSource()) + .stream() + .map(PluginDO.class::cast) + .collect(Collectors.toList()); + } + + /** + * get deleted iss. + * + * @return list + */ + public List getDeletedPluginIds() { + return deletedPluginIds; + } + + /** + * Gets the namespace id. + * + * @return the plugin handle list + */ + public String getNamespaceId() { + return namespaceId; + } +} diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/event/plugin/BatchPluginDeletedEvent.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/event/plugin/BatchPluginDeletedEvent.java index d4d43b8af37f..0778a9d0f1c2 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/event/plugin/BatchPluginDeletedEvent.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/event/plugin/BatchPluginDeletedEvent.java @@ -31,22 +31,18 @@ * BatchPluginDeletedEvent. */ public class BatchPluginDeletedEvent extends BatchPluginChangedEvent { - + private final List deletedPluginIds; - private final String namespaceId; - /** * Create a new {@code PluginChangedEvent}.operator is unknown. * * @param source Current plugin state * @param operator operator - * @param namespaceId namespaceId */ - public BatchPluginDeletedEvent(final Collection source, final String operator, final String namespaceId) { + public BatchPluginDeletedEvent(final Collection source, final String operator) { super(source, null, EventTypeEnum.PLUGIN_DELETE, operator); this.deletedPluginIds = ListUtil.map(source, BaseDO::getId); - this.namespaceId = namespaceId; } @Override @@ -79,12 +75,4 @@ public List getDeletedPluginIds() { return deletedPluginIds; } - /** - * Gets the namespace id. - * - * @return the plugin handle list - */ - public String getNamespaceId() { - return namespaceId; - } } 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 98340657738d..b65fa25e340c 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 @@ -68,11 +68,11 @@ public NamespacePluginServiceImpl(final NamespacePluginRelMapper namespacePlugin @Override @Transactional(rollbackFor = Exception.class) public String update(final NamespacePluginDTO namespacePluginDTO) { - final NamespacePluginVO before = namespacePluginRelMapper.selectById(namespacePluginDTO.getPluginId(), + final NamespacePluginVO before = namespacePluginRelMapper.selectByPluginIdAndNamespaceId(namespacePluginDTO.getPluginId(), namespacePluginDTO.getNamespaceId()); NamespacePluginRelDO namespacePluginRelDO = NamespacePluginRelDO.buildPluginNsRelDO(namespacePluginDTO); if (namespacePluginRelMapper.updateSelective(namespacePluginRelDO) > 0) { - final NamespacePluginVO now = namespacePluginRelMapper.selectByPluginId(namespacePluginDTO.getPluginId(), namespacePluginDTO.getNamespaceId()); + final NamespacePluginVO now = namespacePluginRelMapper.selectByPluginIdAndNamespaceId(namespacePluginDTO.getPluginId(), namespacePluginDTO.getNamespaceId()); // publish update event. namespacePluginEventPublisher.onUpdated(now, before); } @@ -83,12 +83,12 @@ public String update(final NamespacePluginDTO namespacePluginDTO) { @Transactional(rollbackFor = Exception.class) public String delete(final List ids, final String namespaceId) { // select plugin id. - List namespacePluginVOS = this.namespacePluginRelMapper.selectByIds(ids, namespaceId); + List namespacePluginVOS = this.namespacePluginRelMapper.selectByIdsAndNamespaceId(ids, namespaceId); if (CollectionUtils.isEmpty(namespacePluginVOS)) { return AdminConstants.SYS_PLUGIN_ID_NOT_EXIST; } // delete plugins. - if (this.namespacePluginRelMapper.deleteByIds(ListUtil.map(namespacePluginVOS, NamespacePluginVO::getId), namespaceId) > 0) { + if (this.namespacePluginRelMapper.deleteByIdsAndNamespaceId(ListUtil.map(namespacePluginVOS, NamespacePluginVO::getId), namespaceId) > 0) { // publish deleted event. synchronously delete and link data[selector,rule,condition,resource] namespacePluginEventPublisher.onDeleted(namespacePluginVOS); } @@ -97,7 +97,7 @@ public String delete(final List ids, final String namespaceId) { @Override public NamespacePluginVO findById(final String id, final String namespaceId) { - return this.namespacePluginRelMapper.selectById(id, namespaceId); + return this.namespacePluginRelMapper.selectByPluginIdAndNamespaceId(id, namespaceId); } @Override @@ -107,12 +107,12 @@ public CommonPager listByPage(final NamespacePluginQuery name @Override public List listAll(final String namespaceId) { - return ListUtil.map(namespacePluginRelMapper.selectAll(namespaceId), PluginTransfer.INSTANCE::mapToData); + return ListUtil.map(namespacePluginRelMapper.selectAllByNamespaceId(namespaceId), PluginTransfer.INSTANCE::mapToData); } @Override public List listAll() { - return ListUtil.map(namespacePluginRelMapper.selectAll(), PluginTransfer.INSTANCE::mapToData); + return ListUtil.map(namespacePluginRelMapper.selectAllByNamespaceId(), PluginTransfer.INSTANCE::mapToData); } @Override @@ -121,7 +121,7 @@ public List listAllData(final String namespaceId) { .stream() .collect(Collectors.groupingBy(PluginHandleVO::getPluginId)); - return namespacePluginRelMapper.selectAll(namespaceId) + return namespacePluginRelMapper.selectAllByNamespaceId(namespaceId) .stream() .filter(Objects::nonNull) .peek(namespacePluginVO -> { @@ -138,7 +138,7 @@ public List listAllData(final String namespaceId) { @Override public String enabled(final List ids, final Boolean enabled, final String namespaceId) { - List namespacePluginVOList = namespacePluginRelMapper.selectByIds(ids, namespaceId); + List namespacePluginVOList = namespacePluginRelMapper.selectByIdsAndNamespaceId(ids, namespaceId); if (CollectionUtils.isEmpty(namespacePluginVOList)) { return AdminConstants.SYS_PLUGIN_ID_NOT_EXIST; } 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 ba02dba962de..678e6823304a 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 @@ -21,6 +21,7 @@ import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.apache.shenyu.admin.aspect.annotation.Pageable; +import org.apache.shenyu.admin.mapper.NamespacePluginRelMapper; import org.apache.shenyu.admin.mapper.PluginMapper; import org.apache.shenyu.admin.model.dto.PluginDTO; import org.apache.shenyu.admin.model.dto.PluginHandleDTO; @@ -79,12 +80,16 @@ public class PluginServiceImpl implements PluginService { private final PluginHandleService pluginHandleService; + private final NamespacePluginRelMapper namespacePluginRelMapper; + public PluginServiceImpl(final PluginMapper pluginMapper, final PluginEventPublisher pluginEventPublisher, - final PluginHandleService pluginHandleService) { + final PluginHandleService pluginHandleService, + final NamespacePluginRelMapper namespacePluginRelMapper) { this.pluginMapper = pluginMapper; this.pluginEventPublisher = pluginEventPublisher; this.pluginHandleService = pluginHandleService; + this.namespacePluginRelMapper = namespacePluginRelMapper; } @Override @@ -130,6 +135,12 @@ public String delete(final List ids) { if (CollectionUtils.isEmpty(plugins)) { return AdminConstants.SYS_PLUGIN_ID_NOT_EXIST; } + Optional exist = plugins.stream() + .filter(value -> !Objects.isNull(this.namespacePluginRelMapper.selectByPluginId(value.getId()))) + .findAny(); + if (exist.isPresent()) { + return AdminConstants.NAMESPACE_PLUGIN_NOT_DELETE; + } // delete plugins. if (this.pluginMapper.deleteByIds(ListUtil.map(plugins, PluginDO::getId)) > 0) { // publish deleted event. synchronously delete and link data[selector,rule,condition,resource] diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/ResourceServiceImpl.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/ResourceServiceImpl.java index 05ec859f2a32..ef5540f09917 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/ResourceServiceImpl.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/ResourceServiceImpl.java @@ -35,18 +35,17 @@ import org.apache.shenyu.admin.service.ResourceService; import org.apache.shenyu.admin.service.publish.ResourceEventPublisher; import org.apache.shenyu.admin.utils.Assert; -import org.apache.shenyu.common.utils.ListUtil; import org.apache.shenyu.admin.utils.ResourceUtil; import org.apache.shenyu.common.constant.AdminConstants; import org.apache.shenyu.common.enums.AdminResourceEnum; - -import java.util.List; -import java.util.stream.Collectors; - +import org.apache.shenyu.common.utils.ListUtil; import org.springframework.context.event.EventListener; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.List; +import java.util.stream.Collectors; + /** * Implementation of the {@link org.apache.shenyu.admin.service.ResourceService}. */ diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/SelectorServiceImpl.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/SelectorServiceImpl.java index 73298e4869cf..7a53c22701b0 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/SelectorServiceImpl.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/SelectorServiceImpl.java @@ -45,7 +45,7 @@ import org.apache.shenyu.admin.model.entity.PluginDO; import org.apache.shenyu.admin.model.entity.SelectorConditionDO; import org.apache.shenyu.admin.model.entity.SelectorDO; -import org.apache.shenyu.admin.model.event.plugin.BatchPluginDeletedEvent; +import org.apache.shenyu.admin.model.event.plugin.BatchNamespacePluginDeletedEvent; import org.apache.shenyu.admin.model.page.CommonPager; import org.apache.shenyu.admin.model.page.PageResultUtils; import org.apache.shenyu.admin.model.query.SelectorConditionQuery; @@ -334,13 +334,13 @@ public SelectorVO findById(final String id, final String namespaceId) { @Override public SelectorDO findByName(final String name, final String namespaceId) { - List doList = selectorMapper.selectByName(name, namespaceId); + List doList = selectorMapper.selectByNameAndNamespaceId(name, namespaceId); return CollectionUtils.isNotEmpty(doList) ? doList.get(0) : null; } @Override public List findListByName(final String name, final String namespaceId) { - return selectorMapper.selectByName(name, namespaceId); + return selectorMapper.selectByNameAndNamespaceId(name, namespaceId); } /** @@ -416,7 +416,7 @@ public CommonPager listByPage(final SelectorQuery selectorQuery) { @Override public List findByPluginId(final String pluginId, final String namespaceId) { - return this.buildSelectorDataList(selectorMapper.findByPluginId(pluginId, namespaceId)); + return this.buildSelectorDataList(selectorMapper.findByPluginIdAndNamespaceId(pluginId, namespaceId)); } @Override @@ -499,9 +499,9 @@ public Boolean enabled(final List ids, final Boolean enabled, final Stri * * @param event event */ - @EventListener(value = BatchPluginDeletedEvent.class) - public void onPluginDeleted(final BatchPluginDeletedEvent event) { - deleteSelector(selectorMapper.findByPluginIds(event.getDeletedPluginIds(), event.getNamespaceId()), event.getPlugins()); + @EventListener(value = BatchNamespacePluginDeletedEvent.class) + public void onPluginDeleted(final BatchNamespacePluginDeletedEvent event) { + deleteSelector(selectorMapper.findByPluginIdsAndNamespaceId(event.getDeletedPluginIds(), event.getNamespaceId()), event.getPlugins()); } private void createCondition(final String selectorId, final List selectorConditions) { diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/UpstreamCheckService.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/UpstreamCheckService.java index db70478aae51..4e4108944400 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/UpstreamCheckService.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/UpstreamCheckService.java @@ -440,7 +440,7 @@ public void fetchUpstreamData() { Map pluginMap = pluginDOList.stream().filter(Objects::nonNull) .collect(Collectors.toMap(PluginDO::getId, PluginDO::getName, (value1, value2) -> value1)); // todo:[To be refactored with namespace] Temporarily hardcode - final List selectorDOList = selectorMapper.findByPluginIds(new ArrayList<>(pluginMap.keySet()), SYS_DEFAULT_NAMESPACE_NAMESPACE_ID); + final List selectorDOList = selectorMapper.findByPluginIdsAndNamespaceId(new ArrayList<>(pluginMap.keySet()), SYS_DEFAULT_NAMESPACE_NAMESPACE_ID); long currentTimeMillis = System.currentTimeMillis(); Optional.ofNullable(selectorDOList).orElseGet(ArrayList::new).stream() .filter(Objects::nonNull) diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/publish/NamespacePluginEventPublisher.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/publish/NamespacePluginEventPublisher.java index c4748abcc504..75668350de5f 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/publish/NamespacePluginEventPublisher.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/publish/NamespacePluginEventPublisher.java @@ -22,7 +22,7 @@ import org.apache.shenyu.admin.model.enums.EventTypeEnum; import org.apache.shenyu.admin.model.event.AdminDataModelChangedEvent; import org.apache.shenyu.admin.model.event.plugin.BatchNamespacePluginChangedEvent; -import org.apache.shenyu.admin.model.event.plugin.BatchPluginDeletedEvent; +import org.apache.shenyu.admin.model.event.plugin.BatchNamespacePluginDeletedEvent; import org.apache.shenyu.admin.model.event.plugin.NamespacePluginChangedEvent; import org.apache.shenyu.admin.model.event.plugin.NamespacePluginCreatedEvent; import org.apache.shenyu.admin.model.vo.NamespacePluginVO; @@ -91,7 +91,7 @@ public void onDeleted(final Collection namespacePlugin) { .map(NamespacePluginVO.class::cast) .map(PluginDO::buildPluginDO) .collect(Collectors.toList()); - publish(new BatchPluginDeletedEvent(pluginDOList, SessionUtil.visitorName(), namespaceId)); + publish(new BatchNamespacePluginDeletedEvent(pluginDOList, SessionUtil.visitorName(), namespaceId)); publisher.publishEvent(new DataChangedEvent(ConfigGroupEnum.PLUGIN, DataEventTypeEnum.DELETE, namespacePlugin.stream().map(PluginTransfer.INSTANCE::mapToData).collect(Collectors.toList()))); diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/publish/PluginEventPublisher.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/publish/PluginEventPublisher.java index 7ae6a709f09e..a6590e5bb0e6 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/publish/PluginEventPublisher.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/publish/PluginEventPublisher.java @@ -21,6 +21,7 @@ import org.apache.shenyu.admin.model.enums.EventTypeEnum; import org.apache.shenyu.admin.model.event.AdminDataModelChangedEvent; import org.apache.shenyu.admin.model.event.plugin.BatchPluginChangedEvent; +import org.apache.shenyu.admin.model.event.plugin.BatchPluginDeletedEvent; import org.apache.shenyu.admin.model.event.plugin.PluginChangedEvent; import org.apache.shenyu.admin.model.event.plugin.PluginCreatedEvent; import org.apache.shenyu.admin.utils.SessionUtil; @@ -79,7 +80,7 @@ public void onDeleted(final PluginDO plugin) { */ @Override public void onDeleted(final Collection plugins) { - + publish(new BatchPluginDeletedEvent(plugins, SessionUtil.visitorName())); } /** diff --git a/shenyu-admin/src/main/resources/mappers/NamespacePluginRelMapper.xml b/shenyu-admin/src/main/resources/mappers/NamespacePluginRelMapper.xml index 482eea0a8e0b..035326420578 100644 --- a/shenyu-admin/src/main/resources/mappers/NamespacePluginRelMapper.xml +++ b/shenyu-admin/src/main/resources/mappers/NamespacePluginRelMapper.xml @@ -110,7 +110,7 @@ pnr.id ASC - + - + DELETE FROM plugin_ns_rel WHERE id IN @@ -257,7 +256,7 @@ and namespace_id=#{namespaceId, jdbcType=VARCHAR} - SELECT pnr.id as id, pnr.namespace_id AS namespaceId, diff --git a/shenyu-admin/src/main/resources/mappers/selector-sqlmap.xml b/shenyu-admin/src/main/resources/mappers/selector-sqlmap.xml index f2f3b9e6c793..7a78a06d287e 100644 --- a/shenyu-admin/src/main/resources/mappers/selector-sqlmap.xml +++ b/shenyu-admin/src/main/resources/mappers/selector-sqlmap.xml @@ -95,7 +95,7 @@ - SELECT FROM selector @@ -141,7 +141,7 @@ ORDER BY sort - SELECT FROM selector @@ -149,7 +149,7 @@ AND namespace_id = #{namespaceId, jdbcType=VARCHAR} - SELECT FROM selector diff --git a/shenyu-admin/src/test/java/org/apache/shenyu/admin/mapper/ResourceMapperTest.java b/shenyu-admin/src/test/java/org/apache/shenyu/admin/mapper/ResourceMapperTest.java index 26a9c4e63c84..635d29640ecf 100644 --- a/shenyu-admin/src/test/java/org/apache/shenyu/admin/mapper/ResourceMapperTest.java +++ b/shenyu-admin/src/test/java/org/apache/shenyu/admin/mapper/ResourceMapperTest.java @@ -155,7 +155,7 @@ public void testUpdateSelective() { @Test public void testSelectAll() { List resourceDOS = resourceMapper.selectAll(); - // for init schema resource insert, only assert resourceMapper.selectAll() result not null + // for init schema resource insert, only assert resourceMapper.selectAllByNamespaceId() result not null assertTrue(CollectionUtils.isNotEmpty(resourceDOS)); } diff --git a/shenyu-admin/src/test/java/org/apache/shenyu/admin/mapper/SelectorMapperTest.java b/shenyu-admin/src/test/java/org/apache/shenyu/admin/mapper/SelectorMapperTest.java index 813864cb9de3..8d59f0900eb9 100644 --- a/shenyu-admin/src/test/java/org/apache/shenyu/admin/mapper/SelectorMapperTest.java +++ b/shenyu-admin/src/test/java/org/apache/shenyu/admin/mapper/SelectorMapperTest.java @@ -101,7 +101,7 @@ public void testFindByPluginId() { int insert = selectorMapper.insert(selectorDO); assertEquals(1, insert); - List list = selectorMapper.findByPluginId(selectorDO.getPluginId(), selectorDO.getNamespaceId()); + List list = selectorMapper.findByPluginIdAndNamespaceId(selectorDO.getPluginId(), selectorDO.getNamespaceId()); assertNotNull(list); assertEquals(list.size(), 1); assertNotNull(selectorDO.getPluginId(), list.get(0).getPluginId()); @@ -115,7 +115,7 @@ public void testSelectByName() { SelectorDO selectorDO = buildSelectorDO(); int insert = selectorMapper.insert(selectorDO); assertEquals(1, insert); - List doList = selectorMapper.selectByName(selectorDO.getName(), SYS_DEFAULT_NAMESPACE_NAMESPACE_ID); + List doList = selectorMapper.selectByNameAndNamespaceId(selectorDO.getName(), SYS_DEFAULT_NAMESPACE_NAMESPACE_ID); assertEquals(doList.size(), 1); assertNotNull(doList.get(0)); assertEquals(selectorDO.getName(), doList.get(0).getName()); diff --git a/shenyu-admin/src/test/java/org/apache/shenyu/admin/model/event/plugin/BatchPluginDeletedEventTest.java b/shenyu-admin/src/test/java/org/apache/shenyu/admin/model/event/plugin/BatchNamespacePluginDeletedEventTest.java similarity index 88% rename from shenyu-admin/src/test/java/org/apache/shenyu/admin/model/event/plugin/BatchPluginDeletedEventTest.java rename to shenyu-admin/src/test/java/org/apache/shenyu/admin/model/event/plugin/BatchNamespacePluginDeletedEventTest.java index 0326f156e782..c4b097e00a81 100644 --- a/shenyu-admin/src/test/java/org/apache/shenyu/admin/model/event/plugin/BatchPluginDeletedEventTest.java +++ b/shenyu-admin/src/test/java/org/apache/shenyu/admin/model/event/plugin/BatchNamespacePluginDeletedEventTest.java @@ -26,15 +26,15 @@ import org.junit.jupiter.api.Test; /** - * test cast for {@link BatchPluginDeletedEvent}. + * test cast for {@link BatchNamespacePluginDeletedEvent}. */ -public class BatchPluginDeletedEventTest { +public class BatchNamespacePluginDeletedEventTest { private PluginDO one; private PluginDO two; - private BatchPluginDeletedEvent deletedEvent; + private BatchNamespacePluginDeletedEvent deletedEvent; @BeforeEach public void setUp() { @@ -60,7 +60,7 @@ public void setUp() { .dateCreated(now) .build(); - deletedEvent = new BatchPluginDeletedEvent(Arrays.asList(one, two), "test-operator", "namespaceId"); + deletedEvent = new BatchNamespacePluginDeletedEvent(Arrays.asList(one, two), "test-operator", "namespaceId"); } @Test diff --git a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/PermissionServiceTest.java b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/PermissionServiceTest.java index a6c2d891c793..6e6ac3f5fac3 100644 --- a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/PermissionServiceTest.java +++ b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/PermissionServiceTest.java @@ -128,7 +128,7 @@ public void setUp() throws Exception { // when(mockResourceMapper.selectById("1346776175553376256")).thenReturn(resourceDO2); // when(mockResourceMapper.selectById("1346777157943259136")).thenReturn(resourceDO3); // when(mockResourceMapper.selectById("1347053375029653504")).thenReturn(resourceDO4); -// when(mockResourceMapper.selectAll()).thenReturn(Arrays.asList(resourceDO1, resourceDO2, resourceDO3, resourceDO4)); +// when(mockResourceMapper.selectAllByNamespaceId()).thenReturn(Arrays.asList(resourceDO1, resourceDO2, resourceDO3, resourceDO4)); when(mockResourceMapper.selectByUserName("admin")).thenReturn(Arrays.asList(resourceDO2, resourceDO3, resourceDO1, resourceDO4)); when(mockResourceMapper.selectByResourceType(ResourceTypeConstants.MENU_TYPE_2)).thenReturn(Collections.singletonList(resourceDO4)); permissionServiceImplUnderTest = new PermissionServiceImpl(mockPermissionMapper, mockResourceMapper, dashboardProperties); diff --git a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/PluginServiceTest.java b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/PluginServiceTest.java index d26747687bba..c66a0409dca3 100644 --- a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/PluginServiceTest.java +++ b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/PluginServiceTest.java @@ -18,6 +18,7 @@ package org.apache.shenyu.admin.service; import org.apache.commons.lang3.StringUtils; +import org.apache.shenyu.admin.mapper.NamespacePluginRelMapper; import org.apache.shenyu.admin.mapper.PluginMapper; import org.apache.shenyu.admin.mapper.SelectorMapper; import org.apache.shenyu.admin.model.dto.BatchCommonDTO; @@ -85,9 +86,12 @@ public final class PluginServiceTest { @Mock private PluginHandleService pluginHandleService; + @Mock + private NamespacePluginRelMapper namespacePluginRelMapper; + @BeforeEach public void setUp() { - pluginService = new PluginServiceImpl(pluginMapper, modelDataEventPublisher, pluginHandleService); + pluginService = new PluginServiceImpl(pluginMapper, modelDataEventPublisher, pluginHandleService, namespacePluginRelMapper); } @Test @@ -105,7 +109,7 @@ public void testDelete() { final List selectorDOList = new ArrayList<>(); selectorDOList.add(SelectorDO.builder().id("101").build()); - when(selectorMapper.findByPluginIds(Collections.singletonList("101"), SYS_DEFAULT_NAMESPACE_NAMESPACE_ID)).thenReturn(selectorDOList); + when(selectorMapper.findByPluginIdsAndNamespaceId(Collections.singletonList("101"), SYS_DEFAULT_NAMESPACE_NAMESPACE_ID)).thenReturn(selectorDOList); assertEquals(StringUtils.EMPTY, pluginService.delete(Collections.singletonList("123"))); } diff --git a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/SelectorServiceTest.java b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/SelectorServiceTest.java index 1f4170f3d64c..696675cc074a 100644 --- a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/SelectorServiceTest.java +++ b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/SelectorServiceTest.java @@ -187,7 +187,7 @@ public void testDelete() { // mock for test for-each statement. // RuleDO mockedRuleDo = mock(RuleDO.class); -// when(ruleMapper.deleteByIds(Collections.singletonList(mockedRuleDo.getId()))).thenReturn(1); +// when(ruleMapper.deleteByIdsAndNamespaceId(Collections.singletonList(mockedRuleDo.getId()))).thenReturn(1); // when(ruleConditionMapper.deleteByRuleIds(Collections.singletonList(mockedRuleDo.getId()))).thenReturn(1); final List ids = Collections.singletonList(correctId); @@ -210,7 +210,7 @@ public void testFindById() { @Test public void testFindByName() { List selectorDO1List = Collections.singletonList(buildSelectorDO()); - given(this.selectorMapper.selectByName(eq("kuan"), eq(SYS_DEFAULT_NAMESPACE_NAMESPACE_ID))).willReturn(selectorDO1List); + given(this.selectorMapper.selectByNameAndNamespaceId(eq("kuan"), eq(SYS_DEFAULT_NAMESPACE_NAMESPACE_ID))).willReturn(selectorDO1List); SelectorDO selectorDO2 = this.selectorService.findByName("kuan", SYS_DEFAULT_NAMESPACE_NAMESPACE_ID); assertNotNull(selectorDO2); assertEquals(selectorDO1List.size(), 1); diff --git a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/UpstreamCheckServiceTest.java b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/UpstreamCheckServiceTest.java index 3400fb009adf..72049fa97577 100644 --- a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/UpstreamCheckServiceTest.java +++ b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/UpstreamCheckServiceTest.java @@ -258,7 +258,7 @@ public void testFetchUpstreamData() { .status(0) .build(); when(pluginMapper.selectByNames(anyList())).thenReturn(Lists.newArrayList(pluginDO)); - when(selectorMapper.findByPluginIds(anyList(), any())).thenReturn(Lists.newArrayList(selectorDOWithUrlError, selectorDOWithUrlReachable)); + when(selectorMapper.findByPluginIdsAndNamespaceId(anyList(), any())).thenReturn(Lists.newArrayList(selectorDOWithUrlError, selectorDOWithUrlReachable)); when(discoveryUpstreamService.findBySelectorId(anyString())).thenReturn(Lists.newArrayList(discoveryUpstreamData)); upstreamCheckService.fetchUpstreamData(); assertTrue(upstreamMap.containsKey(MOCK_SELECTOR_NAME)); diff --git a/shenyu-common/src/main/java/org/apache/shenyu/common/constant/AdminConstants.java b/shenyu-common/src/main/java/org/apache/shenyu/common/constant/AdminConstants.java index 3f672df0dba9..aea082d39047 100644 --- a/shenyu-common/src/main/java/org/apache/shenyu/common/constant/AdminConstants.java +++ b/shenyu-common/src/main/java/org/apache/shenyu/common/constant/AdminConstants.java @@ -62,6 +62,11 @@ public final class AdminConstants { */ public static final String SYS_NAMESPACE_ID_NOT_EXIST = "The namespace(s) does not exist!"; + /** + * The constant NAMESPACE_PLUGIN_NOT_DELETE. + */ + public static final String NAMESPACE_PLUGIN_NOT_DELETE = "The plugin that exists under a certain namespace cannot be deleted."; + /** * The constant SYS_DEFAULT_NAMESPACE_ID_DELETE. */ From 9020a0da0dee61899b2989d07785fcfafd418086 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=98xcsnx=E2=80=99?= <‘1192709687@qq.com’> Date: Mon, 5 Aug 2024 21:58:25 +0800 Subject: [PATCH 28/61] fix --- .../shenyu/admin/controller/SelectorControllerTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/shenyu-admin/src/test/java/org/apache/shenyu/admin/controller/SelectorControllerTest.java b/shenyu-admin/src/test/java/org/apache/shenyu/admin/controller/SelectorControllerTest.java index 181509eff01f..3ec19d85b712 100644 --- a/shenyu-admin/src/test/java/org/apache/shenyu/admin/controller/SelectorControllerTest.java +++ b/shenyu-admin/src/test/java/org/apache/shenyu/admin/controller/SelectorControllerTest.java @@ -170,7 +170,7 @@ public void updateSelector() throws Exception { when(SpringBeanUtils.getInstance().getBean(NamespaceMapper.class)).thenReturn(namespaceMapper); when(namespaceMapper.existed(SYS_DEFAULT_NAMESPACE_NAMESPACE_ID)).thenReturn(true); given(this.selectorService.createOrUpdate(selectorDTO)).willReturn(1); - this.mockMvc.perform(MockMvcRequestBuilders.put("/selector/id={id}", "123") + this.mockMvc.perform(MockMvcRequestBuilders.put("/selector/{id}", "123") .contentType(MediaType.APPLICATION_JSON) .content(GsonUtils.getInstance().toJson(selectorDTO))) .andExpect(status().isOk()) @@ -203,7 +203,7 @@ public void detailSelector() throws Exception { when(namespaceMapper.existed(SYS_DEFAULT_NAMESPACE_NAMESPACE_ID)).thenReturn(true); given(this.selectorService.findById("1", SYS_DEFAULT_NAMESPACE_NAMESPACE_ID)).willReturn(selectorVO); - this.mockMvc.perform(MockMvcRequestBuilders.get("/selector/id={id}&namespaceId={namespaceId}", "1", SYS_DEFAULT_NAMESPACE_NAMESPACE_ID)) + this.mockMvc.perform(MockMvcRequestBuilders.get("/selector/{id}/{namespaceId}", "1", SYS_DEFAULT_NAMESPACE_NAMESPACE_ID)) .andExpect(status().isOk()) .andExpect(jsonPath("$.message", is(ShenyuResultMessage.DETAIL_SUCCESS))) .andExpect(jsonPath("$.data.id", is(selectorVO.getId()))) From 9d983d324a769bb03edfeae400a4668671217f4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=98xcsnx=E2=80=99?= <‘1192709687@qq.com’> Date: Mon, 5 Aug 2024 22:21:32 +0800 Subject: [PATCH 29/61] fix --- .../shenyu/admin/model/vo/SelectorVO.java | 1 + .../service/impl/SelectorServiceImpl.java | 5 +- .../common/dto/MetaDataRegisterDTO.java | 47 +++++++++++++++++-- 3 files changed, 48 insertions(+), 5 deletions(-) diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/vo/SelectorVO.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/vo/SelectorVO.java index c2ee64adac4e..02f51d22929a 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/vo/SelectorVO.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/vo/SelectorVO.java @@ -170,6 +170,7 @@ public SelectorVO(final String id, this.selectorConditions = selectorConditions; this.dateCreated = dateCreated; this.dateUpdated = dateUpdated; + this.namespaceId = namespaceId; } /** diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/SelectorServiceImpl.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/SelectorServiceImpl.java index 7a53c22701b0..2d6bd82f4613 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/SelectorServiceImpl.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/SelectorServiceImpl.java @@ -176,11 +176,12 @@ public String registerDefault(final SelectorDTO selectorDTO) { public String registerDefault(final MetaDataRegisterDTO dto, final String pluginName, final String selectorHandler) { String contextPath = ContextPathUtils.buildContextPath(dto.getContextPath(), dto.getAppName()); // todo:[To be refactored with namespace] Temporarily hardcode - SelectorDO selectorDO = findByNameAndPluginName(contextPath, pluginName, SYS_DEFAULT_NAMESPACE_NAMESPACE_ID); + String namespaceId = StringUtils.defaultIfEmpty(dto.getNamespaceId(), SYS_DEFAULT_NAMESPACE_NAMESPACE_ID); + SelectorDO selectorDO = findByNameAndPluginName(contextPath, pluginName, namespaceId); if (Objects.isNull(selectorDO)) { SelectorDTO selectorDTO = SelectorUtil.buildSelectorDTO(contextPath, pluginMapper.selectByName(pluginName).getId()); selectorDTO.setHandle(selectorHandler); - selectorDTO.setNamespaceId(SYS_DEFAULT_NAMESPACE_NAMESPACE_ID); + selectorDTO.setNamespaceId(namespaceId); return registerDefault(selectorDTO); } return selectorDO.getId(); diff --git a/shenyu-register-center/shenyu-register-common/src/main/java/org/apache/shenyu/register/common/dto/MetaDataRegisterDTO.java b/shenyu-register-center/shenyu-register-common/src/main/java/org/apache/shenyu/register/common/dto/MetaDataRegisterDTO.java index 596b39917870..42c417fc79e5 100644 --- a/shenyu-register-center/shenyu-register-common/src/main/java/org/apache/shenyu/register/common/dto/MetaDataRegisterDTO.java +++ b/shenyu-register-center/shenyu-register-common/src/main/java/org/apache/shenyu/register/common/dto/MetaDataRegisterDTO.java @@ -63,6 +63,8 @@ public class MetaDataRegisterDTO implements DataTypeParent { private boolean addPrefixed; + private String namespaceId; + /** * Instantiates a new Meta data register dto. * @@ -82,6 +84,7 @@ public class MetaDataRegisterDTO implements DataTypeParent { * @param pluginNames the plugin names * @param registerMetaData the register meta data * @param addPrefixed the prefix forward status + * @param namespaceId the namespaceId */ public MetaDataRegisterDTO(final String appName, final String contextPath, final String path, final String pathDesc, @@ -90,7 +93,8 @@ public MetaDataRegisterDTO(final String appName, final String contextPath, final String parameterTypes, final String rpcExt, final boolean enabled, final String host, final Integer port, final List pluginNames, - final boolean registerMetaData, final boolean addPrefixed) { + final boolean registerMetaData, final boolean addPrefixed, + final String namespaceId) { this.appName = appName; this.contextPath = contextPath; this.path = path; @@ -108,6 +112,7 @@ public MetaDataRegisterDTO(final String appName, final String contextPath, this.registerMetaData = registerMetaData; this.timeMillis = System.currentTimeMillis(); this.addPrefixed = addPrefixed; + this.namespaceId = namespaceId; } /** @@ -134,6 +139,7 @@ private MetaDataRegisterDTO(final Builder builder) { registerMetaData = builder.registerMetaData; timeMillis = System.currentTimeMillis(); addPrefixed = builder.addPrefixed; + namespaceId = builder.namespaceId; } /** @@ -456,6 +462,24 @@ public void setAddPrefixed(final boolean prefixForwardEnable) { this.addPrefixed = prefixForwardEnable; } + /** + * 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; + } + @Override public boolean equals(final Object o) { if (this == o) { @@ -473,14 +497,15 @@ public boolean equals(final Object o) { && Objects.equals(enabled, that.enabled) && Objects.equals(host, that.host) && Objects.equals(port, that.port) && Objects.equals(pluginNames, that.pluginNames) && Objects.equals(registerMetaData, that.registerMetaData) - && Objects.equals(addPrefixed, that.addPrefixed); + && Objects.equals(addPrefixed, that.addPrefixed) + && Objects.equals(namespaceId, that.namespaceId); } @Override public int hashCode() { return Objects.hash(appName, contextPath, path, pathDesc, rpcType, serviceName, methodName, ruleName, parameterTypes, rpcExt, enabled, host, port, pluginNames, - registerMetaData, addPrefixed); + registerMetaData, addPrefixed, namespaceId); } @Override @@ -520,6 +545,8 @@ public String toString() { + timeMillis + ", addPrefixed=" + addPrefixed + + ", namespaceId=" + + namespaceId + '}'; } @@ -562,6 +589,8 @@ public static final class Builder { private boolean addPrefixed; + private String namespaceId; + private Builder() { } @@ -752,6 +781,18 @@ public Builder addPrefixed(final boolean addPrefixed) { return this; } + + /** + * namespaceId. + * + * @param namespaceId namespaceId + * @return SelectorDOBuilder + */ + public Builder namespaceId(final String namespaceId) { + this.namespaceId = namespaceId; + return this; + } + /** * build. * From 170e2f97d4af1b95d0db578b762cbc2b65c75bbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=98xcsnx=E2=80=99?= <‘1192709687@qq.com’> Date: Mon, 5 Aug 2024 23:34:47 +0800 Subject: [PATCH 30/61] fix --- .../shenyu/admin/mapper/ProxySelectorMapper.java | 2 +- .../apache/shenyu/admin/mapper/SelectorMapper.java | 8 ++++---- .../admin/service/impl/SelectorServiceImpl.java | 12 ++++++------ .../src/main/resources/mappers/selector-sqlmap.xml | 4 ++-- .../shenyu/admin/mapper/SelectorMapperTest.java | 2 +- .../shenyu/admin/service/PermissionServiceTest.java | 8 ++++---- .../apache/shenyu/admin/service/RuleServiceTest.java | 6 +++--- .../shenyu/admin/service/SelectorServiceTest.java | 2 +- 8 files changed, 22 insertions(+), 22 deletions(-) diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/ProxySelectorMapper.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/ProxySelectorMapper.java index c235dff5ad42..6cfbbc05cb6a 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/ProxySelectorMapper.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/ProxySelectorMapper.java @@ -71,7 +71,7 @@ public interface ProxySelectorMapper extends ExistProvider { int update(ProxySelectorDO proxySelectorDO); /** - * selectById. + * selectByIdAndNamespaceId. * * @param id id * @return ProxySelectorDO diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/SelectorMapper.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/SelectorMapper.java index 75a71860dad8..58db67a8c52b 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/SelectorMapper.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/SelectorMapper.java @@ -51,7 +51,7 @@ public interface SelectorMapper extends ExistProvider { * @param namespaceId namespaceId. * @return {@linkplain SelectorDO} */ - SelectorDO selectById(String id, String namespaceId); + SelectorDO selectByIdAndNamespaceId(String id, String namespaceId); /** * select selector by id. @@ -112,9 +112,9 @@ public interface SelectorMapper extends ExistProvider { * @param namespaceId namespaceId. * @return the selector do */ - SelectorDO findByNameAndPluginId(@Param("name") String name, - @Param("pluginId") String pluginId, - @Param("namespaceId") String namespaceId); + SelectorDO findByNameAndPluginIdAndNamespaceId(@Param("name") String name, + @Param("pluginId") String pluginId, + @Param("namespaceId") String namespaceId); /** * count selector by query. diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/SelectorServiceImpl.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/SelectorServiceImpl.java index 2d6bd82f4613..badcc064a248 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/SelectorServiceImpl.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/SelectorServiceImpl.java @@ -215,7 +215,7 @@ public int create(final SelectorDTO selectorDTO) { @Override public int update(final SelectorDTO selectorDTO) { - final SelectorDO before = selectorMapper.selectById(selectorDTO.getId(), selectorDTO.getNamespaceId()); + final SelectorDO before = selectorMapper.selectByIdAndNamespaceId(selectorDTO.getId(), selectorDTO.getNamespaceId()); SelectorDO selectorDO = SelectorDO.buildSelectorDO(selectorDTO); final int selectorCount = selectorMapper.updateSelective(selectorDO); @@ -253,7 +253,7 @@ public int update(final SelectorDTO selectorDTO) { @Override public int updateSelective(final SelectorDO selectorDO) { - final SelectorDO before = selectorMapper.selectById(selectorDO.getId(), selectorDO.getNamespaceId()); + final SelectorDO before = selectorMapper.selectByIdAndNamespaceId(selectorDO.getId(), selectorDO.getNamespaceId()); final int updateCount = selectorMapper.updateSelective(selectorDO); if (updateCount > 0) { selectorEventPublisher.onUpdated(selectorDO, before); @@ -316,7 +316,7 @@ private void unbindDiscovery(final List selectors, final List conditions = ListUtil.map(selectorConditionMapper.selectByQuery(new SelectorConditionQuery(id)), SelectorConditionVO::buildSelectorConditionVO); - SelectorVO selectorVO = SelectorVO.buildSelectorVO(selectorMapper.selectById(id, namespaceId), conditions); + SelectorVO selectorVO = SelectorVO.buildSelectorVO(selectorMapper.selectByIdAndNamespaceId(id, namespaceId), conditions); DiscoveryHandlerDO discoveryHandlerDO = discoveryHandlerMapper.selectBySelectorId(id); if (Objects.nonNull(discoveryHandlerDO)) { selectorVO.setDiscoveryHandler(DiscoveryTransfer.INSTANCE.mapToVo(discoveryHandlerDO)); @@ -354,14 +354,14 @@ public List findListByName(final String name, final String namespace @Override public SelectorDO findByNameAndPluginName(final String name, final String pluginName, final String namespaceId) { PluginDO pluginDO = pluginMapper.selectByName(pluginName); - return selectorMapper.findByNameAndPluginId(name, pluginDO.getId(), namespaceId); + return selectorMapper.findByNameAndPluginIdAndNamespaceId(name, pluginDO.getId(), namespaceId); } @Override public SelectorDO findByNameAndPluginNameForUpdate(final String name, final String pluginName, final String namespaceId) { PluginDO pluginDO = pluginMapper.selectByNameForUpdate(pluginName); // todo:[To be refactored with namespace] Temporarily hardcode - return selectorMapper.findByNameAndPluginId(name, pluginDO.getId(), namespaceId); + return selectorMapper.findByNameAndPluginIdAndNamespaceId(name, pluginDO.getId(), namespaceId); } @Override @@ -485,7 +485,7 @@ public ConfigImportResult importData(final List selectorList) { @Transactional(rollbackFor = Exception.class) public Boolean enabled(final List ids, final Boolean enabled, final String namespaceId) { ids.forEach(id -> { - SelectorDO selectorDO = selectorMapper.selectById(id, namespaceId); + SelectorDO selectorDO = selectorMapper.selectByIdAndNamespaceId(id, namespaceId); SelectorDO before = JsonUtils.jsonToObject(JsonUtils.toJson(selectorDO), SelectorDO.class); selectorDO.setEnabled(enabled); if (selectorMapper.updateEnable(id, enabled) > 0) { diff --git a/shenyu-admin/src/main/resources/mappers/selector-sqlmap.xml b/shenyu-admin/src/main/resources/mappers/selector-sqlmap.xml index 7a78a06d287e..aff050689f45 100644 --- a/shenyu-admin/src/main/resources/mappers/selector-sqlmap.xml +++ b/shenyu-admin/src/main/resources/mappers/selector-sqlmap.xml @@ -69,7 +69,7 @@ ${alis}.namespace_id - SELECT FROM selector @@ -103,7 +103,7 @@ AND namespace_id = #{namespaceId, jdbcType=VARCHAR} - SELECT FROM selector diff --git a/shenyu-admin/src/test/java/org/apache/shenyu/admin/mapper/SelectorMapperTest.java b/shenyu-admin/src/test/java/org/apache/shenyu/admin/mapper/SelectorMapperTest.java index 8d59f0900eb9..5fe351273038 100644 --- a/shenyu-admin/src/test/java/org/apache/shenyu/admin/mapper/SelectorMapperTest.java +++ b/shenyu-admin/src/test/java/org/apache/shenyu/admin/mapper/SelectorMapperTest.java @@ -52,7 +52,7 @@ public void testSelectById() { int insert = selectorMapper.insert(selectorDO); assertEquals(1, insert); - SelectorDO selector = selectorMapper.selectById(selectorDO.getId(), SYS_DEFAULT_NAMESPACE_NAMESPACE_ID); + SelectorDO selector = selectorMapper.selectByIdAndNamespaceId(selectorDO.getId(), SYS_DEFAULT_NAMESPACE_NAMESPACE_ID); assertNotNull(selector); assertEquals(selectorDO.getId(), selector.getId()); assertEquals(selectorDO.getContinued(), selector.getContinued()); diff --git a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/PermissionServiceTest.java b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/PermissionServiceTest.java index 6e6ac3f5fac3..e9e52a9157f2 100644 --- a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/PermissionServiceTest.java +++ b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/PermissionServiceTest.java @@ -124,10 +124,10 @@ public void setUp() throws Exception { when(mockDashboardUserMapper.selectByUserName("admin")).thenReturn(dashboardUserDO); when(mockUserRoleMapper.findByUserId("1")).thenReturn(Collections.singletonList(userRoleDO)); when(mockPermissionMapper.findByObjectIds(Collections.singletonList("1346358560427216896"))).thenReturn(permissionDOS); -// when(mockResourceMapper.selectById("1346775491550474240")).thenReturn(resourceDO1); -// when(mockResourceMapper.selectById("1346776175553376256")).thenReturn(resourceDO2); -// when(mockResourceMapper.selectById("1346777157943259136")).thenReturn(resourceDO3); -// when(mockResourceMapper.selectById("1347053375029653504")).thenReturn(resourceDO4); +// when(mockResourceMapper.selectByIdAndNamespaceId("1346775491550474240")).thenReturn(resourceDO1); +// when(mockResourceMapper.selectByIdAndNamespaceId("1346776175553376256")).thenReturn(resourceDO2); +// when(mockResourceMapper.selectByIdAndNamespaceId("1346777157943259136")).thenReturn(resourceDO3); +// when(mockResourceMapper.selectByIdAndNamespaceId("1347053375029653504")).thenReturn(resourceDO4); // when(mockResourceMapper.selectAllByNamespaceId()).thenReturn(Arrays.asList(resourceDO1, resourceDO2, resourceDO3, resourceDO4)); when(mockResourceMapper.selectByUserName("admin")).thenReturn(Arrays.asList(resourceDO2, resourceDO3, resourceDO1, resourceDO4)); when(mockResourceMapper.selectByResourceType(ResourceTypeConstants.MENU_TYPE_2)).thenReturn(Collections.singletonList(resourceDO4)); diff --git a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/RuleServiceTest.java b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/RuleServiceTest.java index eab3758c2433..61ee8e215059 100644 --- a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/RuleServiceTest.java +++ b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/RuleServiceTest.java @@ -202,7 +202,7 @@ public void testListAllWithSelectorNull() { } private void mockFindSelectorIsNull() { - given(this.selectorMapper.selectById("456", SYS_DEFAULT_NAMESPACE_NAMESPACE_ID)).willReturn(null); + given(this.selectorMapper.selectByIdAndNamespaceId("456", SYS_DEFAULT_NAMESPACE_NAMESPACE_ID)).willReturn(null); given(this.pluginMapper.selectById("789")).willReturn(buildPluginDO()); } @@ -213,7 +213,7 @@ public void testListAllWithPluginNull() { } private void mockFindPluginIsNull() { - given(this.selectorMapper.selectById("456", SYS_DEFAULT_NAMESPACE_NAMESPACE_ID)).willReturn(buildSelectorDO()); + given(this.selectorMapper.selectByIdAndNamespaceId("456", SYS_DEFAULT_NAMESPACE_NAMESPACE_ID)).willReturn(buildSelectorDO()); given(this.pluginMapper.selectById("789")).willReturn(null); } @@ -260,7 +260,7 @@ public void testFindBySelectorIdList() { private void publishEvent() { PluginDO pluginDO = buildPluginDO(); SelectorDO selectorDO = buildSelectorDO(); - given(this.selectorMapper.selectById("456", SYS_DEFAULT_NAMESPACE_NAMESPACE_ID)).willReturn(selectorDO); + given(this.selectorMapper.selectByIdAndNamespaceId("456", SYS_DEFAULT_NAMESPACE_NAMESPACE_ID)).willReturn(selectorDO); given(this.pluginMapper.selectById("789")).willReturn(pluginDO); given(this.selectorMapper.selectByIdSet(Sets.newHashSet("456"))).willReturn(Collections.singletonList(selectorDO)); given(this.pluginMapper.selectByIds(Lists.newArrayList("789"))).willReturn(Collections.singletonList(pluginDO)); diff --git a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/SelectorServiceTest.java b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/SelectorServiceTest.java index 696675cc074a..f324b9622fab 100644 --- a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/SelectorServiceTest.java +++ b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/SelectorServiceTest.java @@ -198,7 +198,7 @@ public void testDelete() { @Test public void testFindById() { SelectorDO selectorDO = buildSelectorDO(); - given(this.selectorMapper.selectById(eq("123"), any())).willReturn(selectorDO); + given(this.selectorMapper.selectByIdAndNamespaceId(eq("123"), any())).willReturn(selectorDO); SelectorVO selectorVO = this.selectorService.findById("123", any()); assertNotNull(selectorDO); assertEquals(selectorVO.getId(), selectorDO.getId()); From 50a999281132f6fc3a76d3f4278380a020471d9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=98xcsnx=E2=80=99?= <‘1192709687@qq.com’> Date: Mon, 5 Aug 2024 23:52:16 +0800 Subject: [PATCH 31/61] trigger ci --- .../register/AbstractShenyuClientRegisterServiceImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/AbstractShenyuClientRegisterServiceImpl.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/AbstractShenyuClientRegisterServiceImpl.java index 15c246fcb760..9e16eb8b660f 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/AbstractShenyuClientRegisterServiceImpl.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/AbstractShenyuClientRegisterServiceImpl.java @@ -185,7 +185,7 @@ public String doRegisterURI(final String selectorName, final List Date: Mon, 5 Aug 2024 23:57:31 +0800 Subject: [PATCH 32/61] trigger ci --- .../register/AbstractShenyuClientRegisterServiceImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/AbstractShenyuClientRegisterServiceImpl.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/AbstractShenyuClientRegisterServiceImpl.java index 9e16eb8b660f..15c246fcb760 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/AbstractShenyuClientRegisterServiceImpl.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/AbstractShenyuClientRegisterServiceImpl.java @@ -185,7 +185,7 @@ public String doRegisterURI(final String selectorName, final List Date: Fri, 9 Aug 2024 22:37:22 +0800 Subject: [PATCH 33/61] fix --- .../apache/shenyu/admin/controller/SelectorController.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 840cfa294dfe..343a0c403a95 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 @@ -89,7 +89,7 @@ public AdminResult> querySelectors(final String pluginId * @param namespaceId namespaceId. * @return {@linkplain ShenyuAdminResult} */ - @GetMapping("{id}/{namespaceId}") + @GetMapping("/{id}/{namespaceId}") public ShenyuAdminResult detailSelector(@PathVariable("id") @Valid @Existed(provider = SelectorMapper.class, message = "selector is not existed") final String id, @PathVariable("namespaceId") @Valid @@ -117,7 +117,7 @@ public ShenyuAdminResult createSelector(@Valid @RequestBody final SelectorDTO se * @param selectorDTO selector. * @return {@linkplain ShenyuAdminResult} */ - @PutMapping("{id}") + @PutMapping("/{id}") public ShenyuAdminResult updateSelector(@PathVariable("id") @Valid @Existed(provider = SelectorMapper.class, message = "selector is not existed") final String id, @Valid @RequestBody final SelectorDTO selectorDTO) { From 5cddb9a864bde05367aa957f4d406e7206d78a7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=98xcsnx=E2=80=99?= <‘1192709687@qq.com’> Date: Fri, 9 Aug 2024 22:52:09 +0800 Subject: [PATCH 34/61] trigger ci --- .../apache/shenyu/admin/service/impl/SelectorServiceImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/SelectorServiceImpl.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/SelectorServiceImpl.java index badcc064a248..230522fda287 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/SelectorServiceImpl.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/SelectorServiceImpl.java @@ -360,7 +360,7 @@ public SelectorDO findByNameAndPluginName(final String name, final String plugin @Override public SelectorDO findByNameAndPluginNameForUpdate(final String name, final String pluginName, final String namespaceId) { PluginDO pluginDO = pluginMapper.selectByNameForUpdate(pluginName); - // todo:[To be refactored with namespace] Temporarily hardcode + // todo:[To be refactored with namespace] Temporarily hardcode return selectorMapper.findByNameAndPluginIdAndNamespaceId(name, pluginDO.getId(), namespaceId); } From 6d3efda6be1f5b2d9b0cda85845f49be7a223b72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=98xcsnx=E2=80=99?= <‘1192709687@qq.com’> Date: Fri, 9 Aug 2024 23:24:06 +0800 Subject: [PATCH 35/61] trigger ci --- .../apache/shenyu/admin/service/impl/SelectorServiceImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/SelectorServiceImpl.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/SelectorServiceImpl.java index 230522fda287..badcc064a248 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/SelectorServiceImpl.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/SelectorServiceImpl.java @@ -360,7 +360,7 @@ public SelectorDO findByNameAndPluginName(final String name, final String plugin @Override public SelectorDO findByNameAndPluginNameForUpdate(final String name, final String pluginName, final String namespaceId) { PluginDO pluginDO = pluginMapper.selectByNameForUpdate(pluginName); - // todo:[To be refactored with namespace] Temporarily hardcode + // todo:[To be refactored with namespace] Temporarily hardcode return selectorMapper.findByNameAndPluginIdAndNamespaceId(name, pluginDO.getId(), namespaceId); } From 0c3760aaad73ae60d317dd9961b4a318fb67c31a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=98xcsnx=E2=80=99?= <‘1192709687@qq.com’> Date: Fri, 9 Aug 2024 23:42:12 +0800 Subject: [PATCH 36/61] trigger ci --- .../apache/shenyu/admin/service/impl/SelectorServiceImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/SelectorServiceImpl.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/SelectorServiceImpl.java index badcc064a248..230522fda287 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/SelectorServiceImpl.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/SelectorServiceImpl.java @@ -360,7 +360,7 @@ public SelectorDO findByNameAndPluginName(final String name, final String plugin @Override public SelectorDO findByNameAndPluginNameForUpdate(final String name, final String pluginName, final String namespaceId) { PluginDO pluginDO = pluginMapper.selectByNameForUpdate(pluginName); - // todo:[To be refactored with namespace] Temporarily hardcode + // todo:[To be refactored with namespace] Temporarily hardcode return selectorMapper.findByNameAndPluginIdAndNamespaceId(name, pluginDO.getId(), namespaceId); } From e5400b33b20b6facdddc0650b8ec78bb3efd77e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=98xcsnx=E2=80=99?= <‘1192709687@qq.com’> Date: Sun, 11 Aug 2024 02:17:43 +0800 Subject: [PATCH 37/61] fix cr --- .../admin/controller/SelectorController.java | 6 ++-- .../shenyu/admin/mapper/SelectorMapper.java | 2 +- .../shenyu/admin/model/entity/SelectorDO.java | 4 +-- .../event/plugin/BatchPluginDeletedEvent.java | 4 +-- .../shenyu/admin/service/SelectorService.java | 24 +++++++-------- .../admin/service/impl/ApiServiceImpl.java | 4 +-- .../service/impl/DiscoveryServiceImpl.java | 4 +-- .../impl/DiscoveryUpstreamServiceImpl.java | 2 +- .../service/impl/NamespaceServiceImpl.java | 2 +- .../admin/service/impl/PluginServiceImpl.java | 2 +- .../service/impl/SelectorServiceImpl.java | 30 +++++++++---------- .../service/impl/SyncDataServiceImpl.java | 6 ++-- .../service/impl/UpstreamCheckService.java | 6 ++-- .../NamespacePluginEventPublisher.java | 4 ++- ...stractShenyuClientRegisterServiceImpl.java | 6 ++-- ...ShenyuClientRegisterDivideServiceImpl.java | 6 ++-- .../ShenyuClientRegisterGrpcServiceImpl.java | 4 +-- ...nyuClientRegisterWebSocketServiceImpl.java | 4 +-- .../resources/mappers/selector-sqlmap.xml | 2 +- .../controller/SelectorControllerTest.java | 30 +++++++++---------- .../admin/mapper/SelectorMapperTest.java | 8 ++--- .../admin/service/PluginServiceTest.java | 4 +-- .../shenyu/admin/service/RuleServiceTest.java | 8 ++--- .../admin/service/SelectorServiceTest.java | 12 ++++---- .../admin/service/SyncDataServiceTest.java | 8 ++--- .../impl/LoadServiceDocEntryImplTest.java | 4 +-- ...ctShenyuClientRegisterServiceImplTest.java | 4 +-- .../common/constant/AdminConstants.java | 8 ++--- 28 files changed, 105 insertions(+), 103 deletions(-) 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 343a0c403a95..3be19be82333 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 @@ -94,7 +94,7 @@ public ShenyuAdminResult detailSelector(@PathVariable("id") @Valid @Existed(provider = SelectorMapper.class, message = "selector is not existed") final String id, @PathVariable("namespaceId") @Valid @Existed(provider = NamespaceMapper.class, message = "namespaceId is not existed") final String namespaceId) { - SelectorVO selectorVO = selectorService.findById(id, namespaceId); + SelectorVO selectorVO = selectorService.findByIdAndNamespaceId(id, namespaceId); return ShenyuAdminResult.success(ShenyuResultMessage.DETAIL_SUCCESS, selectorVO); } @@ -134,7 +134,7 @@ public ShenyuAdminResult updateSelector(@PathVariable("id") @Valid */ @PostMapping("/batchEnabled") public ShenyuAdminResult batchEnabled(@Valid @RequestBody final BatchCommonDTO batchCommonDTO) { - if (!selectorService.enabled(batchCommonDTO.getIds(), batchCommonDTO.getEnabled(), batchCommonDTO.getNamespaceId())) { + if (!selectorService.enabledByIdsAndNamespaceId(batchCommonDTO.getIds(), batchCommonDTO.getEnabled(), batchCommonDTO.getNamespaceId())) { return ShenyuAdminResult.error(ShenyuResultMessage.NOT_FOUND_EXCEPTION); } return ShenyuAdminResult.success(ShenyuResultMessage.ENABLE_SUCCESS); @@ -148,7 +148,7 @@ public ShenyuAdminResult batchEnabled(@Valid @RequestBody final BatchCommonDTO b */ @DeleteMapping("/batch") public ShenyuAdminResult deleteSelector(@Valid @RequestBody final BatchNamespaceCommonDTO batchNamespaceCommonDTO) { - Integer deleteCount = selectorService.delete(batchNamespaceCommonDTO.getIds(), batchNamespaceCommonDTO.getNamespaceId()); + Integer deleteCount = selectorService.deleteByNamespaceId(batchNamespaceCommonDTO.getIds(), batchNamespaceCommonDTO.getNamespaceId()); return ShenyuAdminResult.success(ShenyuResultMessage.DELETE_SUCCESS, deleteCount); } diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/SelectorMapper.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/SelectorMapper.java index 58db67a8c52b..21eb784c6550 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/SelectorMapper.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/SelectorMapper.java @@ -59,7 +59,7 @@ public interface SelectorMapper extends ExistProvider { * @param id primary key. * @return {@linkplain SelectorDO} */ - SelectorDO selectByOnlyId(String id); + SelectorDO selectById(String id); /** * Select selector by a list of ids. diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/entity/SelectorDO.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/entity/SelectorDO.java index ae69448f3115..c7c217184040 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/entity/SelectorDO.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/entity/SelectorDO.java @@ -428,8 +428,8 @@ public static SelectorData transFrom(final SelectorDO selectorDO, final String p /** * selector data transform. * - * @param selectorDO selector entity - * @param pluginName plugin name + * @param selectorDO selector entity + * @param pluginName plugin name * @param conditionDataList condition data list * @return the selector data */ diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/event/plugin/BatchPluginDeletedEvent.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/event/plugin/BatchPluginDeletedEvent.java index 0778a9d0f1c2..12db9d7ddaa3 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/event/plugin/BatchPluginDeletedEvent.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/event/plugin/BatchPluginDeletedEvent.java @@ -37,8 +37,8 @@ public class BatchPluginDeletedEvent extends BatchPluginChangedEvent { /** * Create a new {@code PluginChangedEvent}.operator is unknown. * - * @param source Current plugin state - * @param operator operator + * @param source Current plugin state + * @param operator operator */ public BatchPluginDeletedEvent(final Collection source, final String operator) { super(source, null, EventTypeEnum.PLUGIN_DELETE, operator); diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/SelectorService.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/SelectorService.java index f1ea40e75e04..6812d75a17b2 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/SelectorService.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/SelectorService.java @@ -111,7 +111,7 @@ default int createOrUpdate(SelectorDTO selectorDTO) { * @param namespaceId namespaceId. * @return rows int */ - int delete(List ids, String namespaceId); + int deleteByNamespaceId(List ids, String namespaceId); /** * find selector by id. @@ -120,19 +120,19 @@ default int createOrUpdate(SelectorDTO selectorDTO) { * @param namespaceId namespaceId. * @return {@linkplain SelectorVO} */ - SelectorVO findById(String id, String namespaceId); + SelectorVO findByIdAndNamespaceId(String id, String namespaceId); /** * find selector by name. * * @param name the name * @param namespaceId namespaceId. - * Therefore, it is recommended to: {@linkplain SelectorService#findListByName(java.lang.String, java.lang.String)} + * Therefore, it is recommended to: {@linkplain SelectorService#findListByNameAndNamespaceId(java.lang.String, java.lang.String)} * @return selector do * @deprecated sice 2.6.0 Deprecated. By querying under this condition, multiple data are usually obtained. */ @Deprecated - SelectorDO findByName(String name, String namespaceId); + SelectorDO findByNameAndNamespaceId(String name, String namespaceId); /** * find selector list by name. @@ -141,7 +141,7 @@ default int createOrUpdate(SelectorDTO selectorDTO) { * @param namespaceId namespaceId. * @return list */ - List findListByName(String name, String namespaceId); + List findListByNameAndNamespaceId(String name, String namespaceId); /** * Find by name and plugin id selector do. @@ -151,17 +151,17 @@ default int createOrUpdate(SelectorDTO selectorDTO) { * @param namespaceId the namespaceId * @return the selector do */ - SelectorDO findByNameAndPluginName(String name, String pluginName, String namespaceId); + SelectorDO findByNameAndPluginNameAndNamespaceId(String name, String pluginName, String namespaceId); /** - * findByNameAndPluginNameForUpdate. + * findByNameAndPluginNameAndNamespaceIdForUpdate. * * @param name name * @param pluginName pluginName * @param namespaceId namespaceId. * @return SelectorDO */ - SelectorDO findByNameAndPluginNameForUpdate(String name, String pluginName, String namespaceId); + SelectorDO findByNameAndPluginNameAndNamespaceIdForUpdate(String name, String pluginName, String namespaceId); /** * Find selectorDO list by name and plugin name list. @@ -179,7 +179,7 @@ default int createOrUpdate(SelectorDTO selectorDTO) { * @param namespaceId namespaceId. * @return the selector data */ - SelectorData buildByName(String name, String namespaceId); + SelectorData buildByNameAndNamespaceId(String name, String namespaceId); /** * Build by name selector data. @@ -189,7 +189,7 @@ default int createOrUpdate(SelectorDTO selectorDTO) { * @param namespaceId the namespaceId * @return the selector data */ - SelectorData buildByName(String name, String pluginName, String namespaceId); + SelectorData buildByNameAndPluginNameAndNamespaceId(String name, String pluginName, String namespaceId); /** * find page of selector by query. @@ -214,7 +214,7 @@ default int createOrUpdate(SelectorDTO selectorDTO) { * @param namespaceId the namespaceId * @return the list */ - List findByPluginId(String pluginId, String namespaceId); + List findByPluginIdAndNamespaceId(String pluginId, String namespaceId); /** * List all list. @@ -246,5 +246,5 @@ default int createOrUpdate(SelectorDTO selectorDTO) { * @param namespaceId namespaceId * @return the result */ - Boolean enabled(List ids, Boolean enabled, String namespaceId); + Boolean enabledByIdsAndNamespaceId(List ids, Boolean enabled, String namespaceId); } diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/ApiServiceImpl.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/ApiServiceImpl.java index d1a39b614a24..a0bc3750896f 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/ApiServiceImpl.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/ApiServiceImpl.java @@ -63,7 +63,7 @@ import java.util.Optional; import java.util.stream.Collectors; -import static org.apache.shenyu.common.constant.AdminConstants.SYS_DEFAULT_NAMESPACE_NAMESPACE_ID; +import static org.apache.shenyu.common.constant.AdminConstants.SYS_DEFAULT_NAMESPACE_ID; /** * Implementation of the {@link org.apache.shenyu.admin.service.ApiService}. @@ -188,7 +188,7 @@ private void removeRegister(final ApiDO apiDO) { } }); if (CollectionUtils.isNotEmpty(selectorIds)) { - selectorService.delete(selectorIds, SYS_DEFAULT_NAMESPACE_NAMESPACE_ID); + selectorService.delete(selectorIds, SYS_DEFAULT_NAMESPACE_ID); } //clean metadata Optional.ofNullable(metaDataService.findByPath(path)) diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/DiscoveryServiceImpl.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/DiscoveryServiceImpl.java index 0b78c5318702..68da75ad6cfd 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/DiscoveryServiceImpl.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/DiscoveryServiceImpl.java @@ -63,7 +63,7 @@ import java.util.Set; import java.util.stream.Collectors; -import static org.apache.shenyu.common.constant.AdminConstants.SYS_DEFAULT_NAMESPACE_NAMESPACE_ID; +import static org.apache.shenyu.common.constant.AdminConstants.SYS_DEFAULT_NAMESPACE_ID; @Service public class DiscoveryServiceImpl implements DiscoveryService { @@ -127,7 +127,7 @@ public void registerDiscoveryConfig(final DiscoveryConfigRegisterDTO discoveryCo private SelectorDO findAndLockOnDB(final String selectorName, final String pluginName) { SelectorDO selectorDO = null; for (int i = 0; i < 3; i++) { - selectorDO = selectorService.findByNameAndPluginNameForUpdate(selectorName, pluginName, SYS_DEFAULT_NAMESPACE_NAMESPACE_ID); + selectorDO = selectorService.findByNameAndPluginNameAndNamespaceIdForUpdate(selectorName, pluginName, SYS_DEFAULT_NAMESPACE_ID); if (selectorDO != null) { return selectorDO; } diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/DiscoveryUpstreamServiceImpl.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/DiscoveryUpstreamServiceImpl.java index 615aead8dd1d..488288c76730 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/DiscoveryUpstreamServiceImpl.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/DiscoveryUpstreamServiceImpl.java @@ -154,7 +154,7 @@ public List listAll() { if (StringUtils.hasLength(discoveryRelDO.getSelectorId())) { String selectorId = discoveryRelDO.getSelectorId(); discoverySyncData.setSelectorId(selectorId); - SelectorDO selectorDO = selectorMapper.selectByOnlyId(selectorId); + SelectorDO selectorDO = selectorMapper.selectById(selectorId); discoverySyncData.setSelectorName(selectorDO.getName()); } else { String proxySelectorId = discoveryRelDO.getProxySelectorId(); diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/NamespaceServiceImpl.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/NamespaceServiceImpl.java index 499ec9ba4bfd..1608247e9651 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/NamespaceServiceImpl.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/NamespaceServiceImpl.java @@ -80,7 +80,7 @@ public CommonPager listByPage(final NamespaceQuery namespaceQuery) @Override public String delete(final List ids) { - if (ids.contains(AdminConstants.SYS_DEFAULT_NAMESPACE_ID)) { + if (ids.contains(AdminConstants.DEFAULT_NAMESPACE_PRIMARY_KEY)) { return AdminConstants.SYS_DEFAULT_NAMESPACE_ID_DELETE; } List namespaceDOS = namespaceMapper.selectByIds(ids); 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 678e6823304a..6d294d74d25e 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 @@ -136,7 +136,7 @@ public String delete(final List ids) { return AdminConstants.SYS_PLUGIN_ID_NOT_EXIST; } Optional exist = plugins.stream() - .filter(value -> !Objects.isNull(this.namespacePluginRelMapper.selectByPluginId(value.getId()))) + .filter(value -> Objects.nonNull(this.namespacePluginRelMapper.selectByPluginId(value.getId()))) .findAny(); if (exist.isPresent()) { return AdminConstants.NAMESPACE_PLUGIN_NOT_DELETE; diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/SelectorServiceImpl.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/SelectorServiceImpl.java index 230522fda287..22269305149b 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/SelectorServiceImpl.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/SelectorServiceImpl.java @@ -90,7 +90,7 @@ import java.util.TreeSet; import java.util.stream.Collectors; -import static org.apache.shenyu.common.constant.AdminConstants.SYS_DEFAULT_NAMESPACE_NAMESPACE_ID; +import static org.apache.shenyu.common.constant.AdminConstants.SYS_DEFAULT_NAMESPACE_ID; /** * Implementation of the {@link org.apache.shenyu.admin.service.SelectorService}. @@ -176,8 +176,8 @@ public String registerDefault(final SelectorDTO selectorDTO) { public String registerDefault(final MetaDataRegisterDTO dto, final String pluginName, final String selectorHandler) { String contextPath = ContextPathUtils.buildContextPath(dto.getContextPath(), dto.getAppName()); // todo:[To be refactored with namespace] Temporarily hardcode - String namespaceId = StringUtils.defaultIfEmpty(dto.getNamespaceId(), SYS_DEFAULT_NAMESPACE_NAMESPACE_ID); - SelectorDO selectorDO = findByNameAndPluginName(contextPath, pluginName, namespaceId); + String namespaceId = StringUtils.defaultIfEmpty(dto.getNamespaceId(), SYS_DEFAULT_NAMESPACE_ID); + SelectorDO selectorDO = findByNameAndPluginNameAndNamespaceId(contextPath, pluginName, namespaceId); if (Objects.isNull(selectorDO)) { SelectorDTO selectorDTO = SelectorUtil.buildSelectorDTO(contextPath, pluginMapper.selectByName(pluginName).getId()); selectorDTO.setHandle(selectorHandler); @@ -269,7 +269,7 @@ public int updateSelective(final SelectorDO selectorDO) { */ @Override @Transactional(rollbackFor = Exception.class) - public int delete(final List ids, final String namespaceId) { + public int deleteByNamespaceId(final List ids, final String namespaceId) { //todo:[Namespace] To be renovated final List selectors = selectorMapper.selectByIdSet(new TreeSet<>(ids)); List pluginDOS = pluginMapper.selectByIds(ListUtil.map(selectors, SelectorDO::getPluginId)); @@ -314,7 +314,7 @@ private void unbindDiscovery(final List selectors, final List conditions = ListUtil.map(selectorConditionMapper.selectByQuery(new SelectorConditionQuery(id)), SelectorConditionVO::buildSelectorConditionVO); SelectorVO selectorVO = SelectorVO.buildSelectorVO(selectorMapper.selectByIdAndNamespaceId(id, namespaceId), conditions); DiscoveryHandlerDO discoveryHandlerDO = discoveryHandlerMapper.selectBySelectorId(id); @@ -334,13 +334,13 @@ public SelectorVO findById(final String id, final String namespaceId) { } @Override - public SelectorDO findByName(final String name, final String namespaceId) { + public SelectorDO findByNameAndNamespaceId(final String name, final String namespaceId) { List doList = selectorMapper.selectByNameAndNamespaceId(name, namespaceId); return CollectionUtils.isNotEmpty(doList) ? doList.get(0) : null; } @Override - public List findListByName(final String name, final String namespaceId) { + public List findListByNameAndNamespaceId(final String name, final String namespaceId) { return selectorMapper.selectByNameAndNamespaceId(name, namespaceId); } @@ -352,13 +352,13 @@ public List findListByName(final String name, final String namespace * @return the selector do */ @Override - public SelectorDO findByNameAndPluginName(final String name, final String pluginName, final String namespaceId) { + public SelectorDO findByNameAndPluginNameAndNamespaceId(final String name, final String pluginName, final String namespaceId) { PluginDO pluginDO = pluginMapper.selectByName(pluginName); return selectorMapper.findByNameAndPluginIdAndNamespaceId(name, pluginDO.getId(), namespaceId); } @Override - public SelectorDO findByNameAndPluginNameForUpdate(final String name, final String pluginName, final String namespaceId) { + public SelectorDO findByNameAndPluginNameAndNamespaceIdForUpdate(final String name, final String pluginName, final String namespaceId) { PluginDO pluginDO = pluginMapper.selectByNameForUpdate(pluginName); // todo:[To be refactored with namespace] Temporarily hardcode return selectorMapper.findByNameAndPluginIdAndNamespaceId(name, pluginDO.getId(), namespaceId); @@ -378,8 +378,8 @@ public List findByNameAndPluginNames(final String name, final List listByPage(final SelectorQuery selectorQuery) { } @Override - public List findByPluginId(final String pluginId, final String namespaceId) { + public List findByPluginIdAndNamespaceId(final String pluginId, final String namespaceId) { return this.buildSelectorDataList(selectorMapper.findByPluginIdAndNamespaceId(pluginId, namespaceId)); } @@ -483,7 +483,7 @@ public ConfigImportResult importData(final List selectorList) { @Override @Transactional(rollbackFor = Exception.class) - public Boolean enabled(final List ids, final Boolean enabled, final String namespaceId) { + public Boolean enabledByIdsAndNamespaceId(final List ids, final Boolean enabled, final String namespaceId) { ids.forEach(id -> { SelectorDO selectorDO = selectorMapper.selectByIdAndNamespaceId(id, namespaceId); SelectorDO before = JsonUtils.jsonToObject(JsonUtils.toJson(selectorDO), SelectorDO.class); diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/SyncDataServiceImpl.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/SyncDataServiceImpl.java index f755dd451f5c..a9cd1db100bb 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/SyncDataServiceImpl.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/SyncDataServiceImpl.java @@ -44,7 +44,7 @@ import java.util.List; import java.util.stream.Collectors; -import static org.apache.shenyu.common.constant.AdminConstants.SYS_DEFAULT_NAMESPACE_NAMESPACE_ID; +import static org.apache.shenyu.common.constant.AdminConstants.SYS_DEFAULT_NAMESPACE_ID; /** * Implementation of the {@link org.apache.shenyu.admin.service.SyncDataService}. @@ -111,7 +111,7 @@ public boolean syncAll(final DataEventTypeEnum type) { List pluginDataList = namespacePluginService.listAll(); //todo:[Namespace] Temporarily only synchronize plugin data for the default namespace - List pluginDataListFilter = pluginDataList.stream().filter(v -> v.getNamespaceId().equals(SYS_DEFAULT_NAMESPACE_NAMESPACE_ID)).collect(Collectors.toList()); + List pluginDataListFilter = pluginDataList.stream().filter(v -> v.getNamespaceId().equals(SYS_DEFAULT_NAMESPACE_ID)).collect(Collectors.toList()); eventPublisher.publishEvent(new DataChangedEvent(ConfigGroupEnum.PLUGIN, type, pluginDataListFilter)); List selectorDataList = selectorService.listAll(); @@ -131,7 +131,7 @@ public boolean syncPluginData(final String pluginId, final String namespaceId) { eventPublisher.publishEvent(new DataChangedEvent(ConfigGroupEnum.PLUGIN, DataEventTypeEnum.UPDATE, Collections.singletonList(PluginTransfer.INSTANCE.mapToData(namespacePluginVO)))); - List selectorDataList = selectorService.findByPluginId(pluginId, namespaceId); + List selectorDataList = selectorService.findByPluginIdAndNamespaceId(pluginId, namespaceId); if (!CollectionUtils.isEmpty(selectorDataList)) { eventPublisher.publishEvent(new DataChangedEvent(ConfigGroupEnum.SELECTOR, DataEventTypeEnum.REFRESH, selectorDataList)); diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/UpstreamCheckService.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/UpstreamCheckService.java index 4e4108944400..7884c501b0c7 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/UpstreamCheckService.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/UpstreamCheckService.java @@ -76,7 +76,7 @@ import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; -import static org.apache.shenyu.common.constant.AdminConstants.SYS_DEFAULT_NAMESPACE_NAMESPACE_ID; +import static org.apache.shenyu.common.constant.AdminConstants.SYS_DEFAULT_NAMESPACE_ID; /** * This is the upstream check service. @@ -384,7 +384,7 @@ private void removePendingSync(final List successList) { } private void updateSelectorHandler(final String selectorId, final List aliveList) { - SelectorDO selectorDO = selectorMapper.selectByOnlyId(selectorId); + SelectorDO selectorDO = selectorMapper.selectById(selectorId); if (Objects.isNull(selectorDO)) { return; } @@ -440,7 +440,7 @@ public void fetchUpstreamData() { Map pluginMap = pluginDOList.stream().filter(Objects::nonNull) .collect(Collectors.toMap(PluginDO::getId, PluginDO::getName, (value1, value2) -> value1)); // todo:[To be refactored with namespace] Temporarily hardcode - final List selectorDOList = selectorMapper.findByPluginIdsAndNamespaceId(new ArrayList<>(pluginMap.keySet()), SYS_DEFAULT_NAMESPACE_NAMESPACE_ID); + final List selectorDOList = selectorMapper.findByPluginIdsAndNamespaceId(new ArrayList<>(pluginMap.keySet()), SYS_DEFAULT_NAMESPACE_ID); long currentTimeMillis = System.currentTimeMillis(); Optional.ofNullable(selectorDOList).orElseGet(ArrayList::new).stream() .filter(Objects::nonNull) diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/publish/NamespacePluginEventPublisher.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/publish/NamespacePluginEventPublisher.java index 75668350de5f..5b48b1668b17 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/publish/NamespacePluginEventPublisher.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/publish/NamespacePluginEventPublisher.java @@ -39,6 +39,8 @@ import java.util.stream.Collectors; import java.util.stream.Stream; +import static org.apache.shenyu.common.constant.AdminConstants.SYS_DEFAULT_NAMESPACE_ID; + /** * NamespacePluginEventPublisher. */ @@ -85,7 +87,7 @@ public void onDeleted(final Collection namespacePlugin) { .map(NamespacePluginVO.class::cast) .findFirst() .map(NamespacePluginVO::getNamespaceId) - .orElse(""); + .orElse(SYS_DEFAULT_NAMESPACE_ID); List pluginDOList = ((Collection) namespacePlugin) .stream() .map(NamespacePluginVO.class::cast) diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/AbstractShenyuClientRegisterServiceImpl.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/AbstractShenyuClientRegisterServiceImpl.java index 15c246fcb760..01baa4aee2ae 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/AbstractShenyuClientRegisterServiceImpl.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/AbstractShenyuClientRegisterServiceImpl.java @@ -58,7 +58,7 @@ import java.util.Objects; import java.util.stream.Collectors; -import static org.apache.shenyu.common.constant.AdminConstants.SYS_DEFAULT_NAMESPACE_NAMESPACE_ID; +import static org.apache.shenyu.common.constant.AdminConstants.SYS_DEFAULT_NAMESPACE_ID; /** * Abstract strategy. @@ -174,7 +174,7 @@ public String doRegisterURI(final String selectorName, final List uriL final SelectorService selectorService = getSelectorService(); String pluginName = PluginNameAdapter.rpcTypeAdapter(rpcType()); // todo:[To be refactored with namespace] Temporarily hardcode - SelectorDO selectorDO = selectorService.findByNameAndPluginName(selectorName, pluginName, SYS_DEFAULT_NAMESPACE_NAMESPACE_ID); + SelectorDO selectorDO = selectorService.findByNameAndPluginNameAndNamespaceId(selectorName, pluginName, SYS_DEFAULT_NAMESPACE_ID); if (Objects.isNull(selectorDO)) { return Constants.SUCCESS; } @@ -136,7 +136,7 @@ public String offline(final String selectorName, final List uriL existList.removeAll(needToRemove); final String handler = GsonUtils.getInstance().toJson(existList); selectorDO.setHandle(handler); - SelectorData selectorData = selectorService.buildByName(selectorName, PluginNameAdapter.rpcTypeAdapter(rpcType()), SYS_DEFAULT_NAMESPACE_NAMESPACE_ID); + SelectorData selectorData = selectorService.buildByNameAndPluginNameAndNamespaceId(selectorName, PluginNameAdapter.rpcTypeAdapter(rpcType()), SYS_DEFAULT_NAMESPACE_ID); selectorData.setHandle(handler); // update db selectorService.updateSelective(selectorDO); diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterGrpcServiceImpl.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterGrpcServiceImpl.java index f0546098916b..eaf5f18513c9 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterGrpcServiceImpl.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterGrpcServiceImpl.java @@ -46,7 +46,7 @@ import java.util.concurrent.CopyOnWriteArrayList; import java.util.stream.Collectors; -import static org.apache.shenyu.common.constant.AdminConstants.SYS_DEFAULT_NAMESPACE_NAMESPACE_ID; +import static org.apache.shenyu.common.constant.AdminConstants.SYS_DEFAULT_NAMESPACE_ID; /** * grpc service register. @@ -127,7 +127,7 @@ public String offline(final String selectorName, final List offl String pluginName = PluginNameAdapter.rpcTypeAdapter(rpcType()); SelectorService selectorService = getSelectorService(); // todo:[To be refactored with namespace] Temporarily hardcode - SelectorDO selectorDO = selectorService.findByNameAndPluginName(selectorName, pluginName, SYS_DEFAULT_NAMESPACE_NAMESPACE_ID); + SelectorDO selectorDO = selectorService.findByNameAndPluginNameAndNamespaceId(selectorName, pluginName, SYS_DEFAULT_NAMESPACE_ID); if (Objects.isNull(selectorDO)) { return Constants.SUCCESS; } diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterWebSocketServiceImpl.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterWebSocketServiceImpl.java index 8a7d86b4b063..8c8ee8593d1e 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterWebSocketServiceImpl.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterWebSocketServiceImpl.java @@ -44,7 +44,7 @@ import org.apache.shenyu.register.common.dto.URIRegisterDTO; import org.springframework.stereotype.Service; -import static org.apache.shenyu.common.constant.AdminConstants.SYS_DEFAULT_NAMESPACE_NAMESPACE_ID; +import static org.apache.shenyu.common.constant.AdminConstants.SYS_DEFAULT_NAMESPACE_ID; /** * spring mvc websocket service register. @@ -108,7 +108,7 @@ public String offline(final String selectorName, final List offl String pluginName = PluginNameAdapter.rpcTypeAdapter(rpcType()); SelectorService selectorService = getSelectorService(); // todo:[To be refactored with namespace] Temporarily hardcode - SelectorDO selectorDO = selectorService.findByNameAndPluginName(selectorName, pluginName, SYS_DEFAULT_NAMESPACE_NAMESPACE_ID); + SelectorDO selectorDO = selectorService.findByNameAndPluginNameAndNamespaceId(selectorName, pluginName, SYS_DEFAULT_NAMESPACE_ID); if (Objects.isNull(selectorDO)) { return Constants.SUCCESS; } diff --git a/shenyu-admin/src/main/resources/mappers/selector-sqlmap.xml b/shenyu-admin/src/main/resources/mappers/selector-sqlmap.xml index aff050689f45..cd3c29912c25 100644 --- a/shenyu-admin/src/main/resources/mappers/selector-sqlmap.xml +++ b/shenyu-admin/src/main/resources/mappers/selector-sqlmap.xml @@ -77,7 +77,7 @@ AND namespace_id = #{namespaceId, jdbcType=VARCHAR} - SELECT FROM selector diff --git a/shenyu-admin/src/test/java/org/apache/shenyu/admin/controller/SelectorControllerTest.java b/shenyu-admin/src/test/java/org/apache/shenyu/admin/controller/SelectorControllerTest.java index 3ec19d85b712..cd785714ce48 100644 --- a/shenyu-admin/src/test/java/org/apache/shenyu/admin/controller/SelectorControllerTest.java +++ b/shenyu-admin/src/test/java/org/apache/shenyu/admin/controller/SelectorControllerTest.java @@ -54,7 +54,7 @@ import java.util.Arrays; import java.util.Collections; -import static org.apache.shenyu.common.constant.AdminConstants.SYS_DEFAULT_NAMESPACE_NAMESPACE_ID; +import static org.apache.shenyu.common.constant.AdminConstants.SYS_DEFAULT_NAMESPACE_ID; import static org.hamcrest.core.Is.is; import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.given; @@ -91,7 +91,7 @@ public final class SelectorControllerTest { MatchModeEnum.AND.getName(), SelectorTypeEnum.FULL_FLOW.getCode(), SelectorTypeEnum.FULL_FLOW.getName(), 1, true, true, true, false, "handle", Collections.emptyList(), DateUtils.localDateTimeToString(LocalDateTime.now()), DateUtils.localDateTimeToString(LocalDateTime.now()), - SYS_DEFAULT_NAMESPACE_NAMESPACE_ID); + SYS_DEFAULT_NAMESPACE_ID); private final CommonPager commonPager = new CommonPager<>(new PageParameter(), Collections.singletonList(selectorVO)); @@ -130,7 +130,7 @@ public void createSelector() throws Exception { .matchRestful(false) .pluginId("2") .sort(1) - .namespaceId(SYS_DEFAULT_NAMESPACE_NAMESPACE_ID) + .namespaceId(SYS_DEFAULT_NAMESPACE_ID) .build(); SpringBeanUtils.getInstance().setApplicationContext(mock(ConfigurableApplicationContext.class)); when(SpringBeanUtils.getInstance().getBean(SelectorMapper.class)).thenReturn(selectorMapper); @@ -138,7 +138,7 @@ public void createSelector() throws Exception { when(SpringBeanUtils.getInstance().getBean(PluginMapper.class)).thenReturn(pluginMapper); when(pluginMapper.existed(selectorDTO.getPluginId())).thenReturn(true); when(SpringBeanUtils.getInstance().getBean(NamespaceMapper.class)).thenReturn(namespaceMapper); - when(namespaceMapper.existed(SYS_DEFAULT_NAMESPACE_NAMESPACE_ID)).thenReturn(true); + when(namespaceMapper.existed(SYS_DEFAULT_NAMESPACE_ID)).thenReturn(true); given(this.selectorService.createOrUpdate(selectorDTO)).willReturn(1); this.mockMvc.perform(MockMvcRequestBuilders.post("/selector") .contentType(MediaType.APPLICATION_JSON) @@ -160,7 +160,7 @@ public void updateSelector() throws Exception { .matchRestful(false) .pluginId("2") .sort(1) - .namespaceId(SYS_DEFAULT_NAMESPACE_NAMESPACE_ID) + .namespaceId(SYS_DEFAULT_NAMESPACE_ID) .build(); SpringBeanUtils.getInstance().setApplicationContext(mock(ConfigurableApplicationContext.class)); when(SpringBeanUtils.getInstance().getBean(SelectorMapper.class)).thenReturn(selectorMapper); @@ -168,7 +168,7 @@ public void updateSelector() throws Exception { when(SpringBeanUtils.getInstance().getBean(PluginMapper.class)).thenReturn(pluginMapper); when(pluginMapper.existed(selectorDTO.getPluginId())).thenReturn(true); when(SpringBeanUtils.getInstance().getBean(NamespaceMapper.class)).thenReturn(namespaceMapper); - when(namespaceMapper.existed(SYS_DEFAULT_NAMESPACE_NAMESPACE_ID)).thenReturn(true); + when(namespaceMapper.existed(SYS_DEFAULT_NAMESPACE_ID)).thenReturn(true); given(this.selectorService.createOrUpdate(selectorDTO)).willReturn(1); this.mockMvc.perform(MockMvcRequestBuilders.put("/selector/{id}", "123") .contentType(MediaType.APPLICATION_JSON) @@ -182,10 +182,10 @@ public void updateSelector() throws Exception { public void deleteSelector() throws Exception { SpringBeanUtils.getInstance().setApplicationContext(mock(ConfigurableApplicationContext.class)); when(SpringBeanUtils.getInstance().getBean(NamespaceMapper.class)).thenReturn(namespaceMapper); - when(namespaceMapper.existed(SYS_DEFAULT_NAMESPACE_NAMESPACE_ID)).thenReturn(true); - given(this.selectorService.delete(Collections.singletonList("123"), SYS_DEFAULT_NAMESPACE_NAMESPACE_ID)).willReturn(1); + when(namespaceMapper.existed(SYS_DEFAULT_NAMESPACE_ID)).thenReturn(true); + given(this.selectorService.deleteByNamespaceId(Collections.singletonList("123"), SYS_DEFAULT_NAMESPACE_ID)).willReturn(1); final BatchNamespaceCommonDTO batchNamespaceCommonDTO = new BatchNamespaceCommonDTO(); - batchNamespaceCommonDTO.setNamespaceId(SYS_DEFAULT_NAMESPACE_NAMESPACE_ID); + batchNamespaceCommonDTO.setNamespaceId(SYS_DEFAULT_NAMESPACE_ID); batchNamespaceCommonDTO.setIds(Collections.singletonList("123")); this.mockMvc.perform(MockMvcRequestBuilders.delete("/selector/batch") .contentType(MediaType.APPLICATION_JSON) @@ -200,10 +200,10 @@ public void detailSelector() throws Exception { SpringBeanUtils.getInstance().setApplicationContext(mock(ConfigurableApplicationContext.class)); when(SpringBeanUtils.getInstance().getBean(NamespaceMapper.class)).thenReturn(namespaceMapper); - when(namespaceMapper.existed(SYS_DEFAULT_NAMESPACE_NAMESPACE_ID)).thenReturn(true); - given(this.selectorService.findById("1", SYS_DEFAULT_NAMESPACE_NAMESPACE_ID)).willReturn(selectorVO); + when(namespaceMapper.existed(SYS_DEFAULT_NAMESPACE_ID)).thenReturn(true); + given(this.selectorService.findByIdAndNamespaceId("1", SYS_DEFAULT_NAMESPACE_ID)).willReturn(selectorVO); - this.mockMvc.perform(MockMvcRequestBuilders.get("/selector/{id}/{namespaceId}", "1", SYS_DEFAULT_NAMESPACE_NAMESPACE_ID)) + this.mockMvc.perform(MockMvcRequestBuilders.get("/selector/{id}/{namespaceId}", "1", SYS_DEFAULT_NAMESPACE_ID)) .andExpect(status().isOk()) .andExpect(jsonPath("$.message", is(ShenyuResultMessage.DETAIL_SUCCESS))) .andExpect(jsonPath("$.data.id", is(selectorVO.getId()))) @@ -222,18 +222,18 @@ public void enableSelector() throws Exception { .matchRestful(false) .pluginId("2") .sort(1) - .namespaceId(SYS_DEFAULT_NAMESPACE_NAMESPACE_ID) + .namespaceId(SYS_DEFAULT_NAMESPACE_ID) .build(); SpringBeanUtils.getInstance().setApplicationContext(mock(ConfigurableApplicationContext.class)); when(SpringBeanUtils.getInstance().getBean(SelectorMapper.class)).thenReturn(selectorMapper); when(selectorMapper.existed(selectorDTO.getId())).thenReturn(true); when(SpringBeanUtils.getInstance().getBean(PluginMapper.class)).thenReturn(pluginMapper); when(pluginMapper.existed(selectorDTO.getPluginId())).thenReturn(true); - given(this.selectorService.enabled(Arrays.asList(selectorDTO.getId()), false, SYS_DEFAULT_NAMESPACE_NAMESPACE_ID)).willReturn(true); + given(this.selectorService.enabledByIdsAndNamespaceId(Arrays.asList(selectorDTO.getId()), false, SYS_DEFAULT_NAMESPACE_ID)).willReturn(true); BatchCommonDTO batchCommonDTO = new BatchCommonDTO(); batchCommonDTO.setIds(Arrays.asList(selectorDTO.getId())); batchCommonDTO.setEnabled(false); - batchCommonDTO.setNamespaceId(SYS_DEFAULT_NAMESPACE_NAMESPACE_ID); + batchCommonDTO.setNamespaceId(SYS_DEFAULT_NAMESPACE_ID); this.mockMvc.perform(MockMvcRequestBuilders.post("/selector/batchEnabled") .contentType(MediaType.APPLICATION_JSON) .content(GsonUtils.getInstance().toJson(batchCommonDTO))) diff --git a/shenyu-admin/src/test/java/org/apache/shenyu/admin/mapper/SelectorMapperTest.java b/shenyu-admin/src/test/java/org/apache/shenyu/admin/mapper/SelectorMapperTest.java index 5fe351273038..6478db06b318 100644 --- a/shenyu-admin/src/test/java/org/apache/shenyu/admin/mapper/SelectorMapperTest.java +++ b/shenyu-admin/src/test/java/org/apache/shenyu/admin/mapper/SelectorMapperTest.java @@ -31,7 +31,7 @@ import java.util.stream.Collectors; import java.util.stream.Stream; -import static org.apache.shenyu.common.constant.AdminConstants.SYS_DEFAULT_NAMESPACE_NAMESPACE_ID; +import static org.apache.shenyu.common.constant.AdminConstants.SYS_DEFAULT_NAMESPACE_ID; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.hasItems; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -52,7 +52,7 @@ public void testSelectById() { int insert = selectorMapper.insert(selectorDO); assertEquals(1, insert); - SelectorDO selector = selectorMapper.selectByIdAndNamespaceId(selectorDO.getId(), SYS_DEFAULT_NAMESPACE_NAMESPACE_ID); + SelectorDO selector = selectorMapper.selectByIdAndNamespaceId(selectorDO.getId(), SYS_DEFAULT_NAMESPACE_ID); assertNotNull(selector); assertEquals(selectorDO.getId(), selector.getId()); assertEquals(selectorDO.getContinued(), selector.getContinued()); @@ -115,7 +115,7 @@ public void testSelectByName() { SelectorDO selectorDO = buildSelectorDO(); int insert = selectorMapper.insert(selectorDO); assertEquals(1, insert); - List doList = selectorMapper.selectByNameAndNamespaceId(selectorDO.getName(), SYS_DEFAULT_NAMESPACE_NAMESPACE_ID); + List doList = selectorMapper.selectByNameAndNamespaceId(selectorDO.getName(), SYS_DEFAULT_NAMESPACE_ID); assertEquals(doList.size(), 1); assertNotNull(doList.get(0)); assertEquals(selectorDO.getName(), doList.get(0).getName()); @@ -238,7 +238,7 @@ private SelectorDO buildSelectorDO() { .matchRestful(false) .continued(Boolean.TRUE) .handle("handle") - .namespaceId(SYS_DEFAULT_NAMESPACE_NAMESPACE_ID) + .namespaceId(SYS_DEFAULT_NAMESPACE_ID) .build(); } } diff --git a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/PluginServiceTest.java b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/PluginServiceTest.java index c66a0409dca3..1006e03fa2af 100644 --- a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/PluginServiceTest.java +++ b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/PluginServiceTest.java @@ -54,7 +54,7 @@ import java.util.stream.Collectors; import java.util.stream.IntStream; -import static org.apache.shenyu.common.constant.AdminConstants.SYS_DEFAULT_NAMESPACE_NAMESPACE_ID; +import static org.apache.shenyu.common.constant.AdminConstants.SYS_DEFAULT_NAMESPACE_ID; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -109,7 +109,7 @@ public void testDelete() { final List selectorDOList = new ArrayList<>(); selectorDOList.add(SelectorDO.builder().id("101").build()); - when(selectorMapper.findByPluginIdsAndNamespaceId(Collections.singletonList("101"), SYS_DEFAULT_NAMESPACE_NAMESPACE_ID)).thenReturn(selectorDOList); + when(selectorMapper.findByPluginIdsAndNamespaceId(Collections.singletonList("101"), SYS_DEFAULT_NAMESPACE_ID)).thenReturn(selectorDOList); assertEquals(StringUtils.EMPTY, pluginService.delete(Collections.singletonList("123"))); } diff --git a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/RuleServiceTest.java b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/RuleServiceTest.java index 61ee8e215059..e8d76fe9fb50 100644 --- a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/RuleServiceTest.java +++ b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/RuleServiceTest.java @@ -64,7 +64,7 @@ import java.util.stream.Collectors; import java.util.stream.IntStream; -import static org.apache.shenyu.common.constant.AdminConstants.SYS_DEFAULT_NAMESPACE_NAMESPACE_ID; +import static org.apache.shenyu.common.constant.AdminConstants.SYS_DEFAULT_NAMESPACE_ID; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.greaterThan; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -202,7 +202,7 @@ public void testListAllWithSelectorNull() { } private void mockFindSelectorIsNull() { - given(this.selectorMapper.selectByIdAndNamespaceId("456", SYS_DEFAULT_NAMESPACE_NAMESPACE_ID)).willReturn(null); + given(this.selectorMapper.selectByIdAndNamespaceId("456", SYS_DEFAULT_NAMESPACE_ID)).willReturn(null); given(this.pluginMapper.selectById("789")).willReturn(buildPluginDO()); } @@ -213,7 +213,7 @@ public void testListAllWithPluginNull() { } private void mockFindPluginIsNull() { - given(this.selectorMapper.selectByIdAndNamespaceId("456", SYS_DEFAULT_NAMESPACE_NAMESPACE_ID)).willReturn(buildSelectorDO()); + given(this.selectorMapper.selectByIdAndNamespaceId("456", SYS_DEFAULT_NAMESPACE_ID)).willReturn(buildSelectorDO()); given(this.pluginMapper.selectById("789")).willReturn(null); } @@ -260,7 +260,7 @@ public void testFindBySelectorIdList() { private void publishEvent() { PluginDO pluginDO = buildPluginDO(); SelectorDO selectorDO = buildSelectorDO(); - given(this.selectorMapper.selectByIdAndNamespaceId("456", SYS_DEFAULT_NAMESPACE_NAMESPACE_ID)).willReturn(selectorDO); + given(this.selectorMapper.selectByIdAndNamespaceId("456", SYS_DEFAULT_NAMESPACE_ID)).willReturn(selectorDO); given(this.pluginMapper.selectById("789")).willReturn(pluginDO); given(this.selectorMapper.selectByIdSet(Sets.newHashSet("456"))).willReturn(Collections.singletonList(selectorDO)); given(this.pluginMapper.selectByIds(Lists.newArrayList("789"))).willReturn(Collections.singletonList(pluginDO)); diff --git a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/SelectorServiceTest.java b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/SelectorServiceTest.java index f324b9622fab..b22d87ac806f 100644 --- a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/SelectorServiceTest.java +++ b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/SelectorServiceTest.java @@ -72,7 +72,7 @@ import java.util.stream.Collectors; import java.util.stream.Stream; -import static org.apache.shenyu.common.constant.AdminConstants.SYS_DEFAULT_NAMESPACE_NAMESPACE_ID; +import static org.apache.shenyu.common.constant.AdminConstants.SYS_DEFAULT_NAMESPACE_ID; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.greaterThan; import static org.hamcrest.Matchers.notNullValue; @@ -192,14 +192,14 @@ public void testDelete() { final List ids = Collections.singletonList(correctId); given(selectorMapper.deleteByIds(ids)).willReturn(ids.size()); - assertEquals(selectorService.delete(ids, any()), ids.size()); + assertEquals(selectorService.deleteByNamespaceId(ids, any()), ids.size()); } @Test public void testFindById() { SelectorDO selectorDO = buildSelectorDO(); given(this.selectorMapper.selectByIdAndNamespaceId(eq("123"), any())).willReturn(selectorDO); - SelectorVO selectorVO = this.selectorService.findById("123", any()); + SelectorVO selectorVO = this.selectorService.findByIdAndNamespaceId("123", any()); assertNotNull(selectorDO); assertEquals(selectorVO.getId(), selectorDO.getId()); @@ -210,8 +210,8 @@ public void testFindById() { @Test public void testFindByName() { List selectorDO1List = Collections.singletonList(buildSelectorDO()); - given(this.selectorMapper.selectByNameAndNamespaceId(eq("kuan"), eq(SYS_DEFAULT_NAMESPACE_NAMESPACE_ID))).willReturn(selectorDO1List); - SelectorDO selectorDO2 = this.selectorService.findByName("kuan", SYS_DEFAULT_NAMESPACE_NAMESPACE_ID); + given(this.selectorMapper.selectByNameAndNamespaceId(eq("kuan"), eq(SYS_DEFAULT_NAMESPACE_ID))).willReturn(selectorDO1List); + SelectorDO selectorDO2 = this.selectorService.findByNameAndNamespaceId("kuan", SYS_DEFAULT_NAMESPACE_ID); assertNotNull(selectorDO2); assertEquals(selectorDO1List.size(), 1); assertEquals(selectorDO1List.get(0).getId(), selectorDO2.getId()); @@ -230,7 +230,7 @@ public void testListByPage() { @Test public void testFindByPluginId() { - List res = this.selectorService.findByPluginId("789", SYS_DEFAULT_NAMESPACE_NAMESPACE_ID); + List res = this.selectorService.findByPluginIdAndNamespaceId("789", SYS_DEFAULT_NAMESPACE_ID); res.forEach(selectorData -> assertEquals("789", selectorData.getPluginId())); } diff --git a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/SyncDataServiceTest.java b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/SyncDataServiceTest.java index 09803e1f07b3..dc33e858e53a 100644 --- a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/SyncDataServiceTest.java +++ b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/SyncDataServiceTest.java @@ -39,7 +39,7 @@ import java.time.LocalDateTime; import java.util.Collections; -import static org.apache.shenyu.common.constant.AdminConstants.SYS_DEFAULT_NAMESPACE_NAMESPACE_ID; +import static org.apache.shenyu.common.constant.AdminConstants.SYS_DEFAULT_NAMESPACE_ID; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.greaterThan; import static org.mockito.BDDMockito.given; @@ -108,11 +108,11 @@ public void syncAllTest() { public void syncPluginDataTest() { PluginVO pluginVO = buildPluginVO(); NamespacePluginVO namespacePluginVO = new NamespacePluginVO(); - given(this.namespacePluginService.findById(pluginVO.getId(), SYS_DEFAULT_NAMESPACE_NAMESPACE_ID)).willReturn(namespacePluginVO); + given(this.namespacePluginService.findById(pluginVO.getId(), SYS_DEFAULT_NAMESPACE_ID)).willReturn(namespacePluginVO); SelectorData selectorData = buildSelectorData(); - given(this.selectorService.findByPluginId(pluginVO.getId(), SYS_DEFAULT_NAMESPACE_NAMESPACE_ID)).willReturn(Collections.singletonList(selectorData)); + given(this.selectorService.findByPluginIdAndNamespaceId(pluginVO.getId(), SYS_DEFAULT_NAMESPACE_ID)).willReturn(Collections.singletonList(selectorData)); - assertThat(syncDataService.syncPluginData(pluginVO.getId(), SYS_DEFAULT_NAMESPACE_NAMESPACE_ID), greaterThan(false)); + assertThat(syncDataService.syncPluginData(pluginVO.getId(), SYS_DEFAULT_NAMESPACE_ID), greaterThan(false)); } diff --git a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/manager/impl/LoadServiceDocEntryImplTest.java b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/manager/impl/LoadServiceDocEntryImplTest.java index a6f821515764..bd106d353b56 100644 --- a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/manager/impl/LoadServiceDocEntryImplTest.java +++ b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/manager/impl/LoadServiceDocEntryImplTest.java @@ -48,7 +48,7 @@ import java.util.Set; import java.util.Collections; -import static org.apache.shenyu.common.constant.AdminConstants.SYS_DEFAULT_NAMESPACE_NAMESPACE_ID; +import static org.apache.shenyu.common.constant.AdminConstants.SYS_DEFAULT_NAMESPACE_ID; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.when; import static org.mockito.Mockito.verify; @@ -114,7 +114,7 @@ public void testLoadApiDocument() { new ArrayList<>(), formattedDateString, formattedDateString, - SYS_DEFAULT_NAMESPACE_NAMESPACE_ID + SYS_DEFAULT_NAMESPACE_ID ); list.add(selectorVO); commonPager.setDataList(list); diff --git a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/register/AbstractShenyuClientRegisterServiceImplTest.java b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/register/AbstractShenyuClientRegisterServiceImplTest.java index 052f0fded21c..0dea64a0a83f 100644 --- a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/register/AbstractShenyuClientRegisterServiceImplTest.java +++ b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/register/AbstractShenyuClientRegisterServiceImplTest.java @@ -144,9 +144,9 @@ public void testDoRegisterURI() { assertThrows(ShenyuException.class, () -> abstractShenyuClientRegisterService.doRegisterURI("Selector_Name", Collections.singletonList(uriRegisterDTO))); SelectorDO selectorDO = mock(SelectorDO.class); - when(selectorService.findByNameAndPluginName(any(), any(), any())).thenReturn(selectorDO); + when(selectorService.findByNameAndPluginNameAndNamespaceId(any(), any(), any())).thenReturn(selectorDO); SelectorData selectorData = new SelectorData(); - when(selectorService.buildByName(any(), any(), any())).thenReturn(selectorData); + when(selectorService.buildByNameAndPluginNameAndNamespaceId(any(), any(), any())).thenReturn(selectorData); assertEquals(ShenyuResultMessage.SUCCESS, abstractShenyuClientRegisterService.doRegisterURI("Selector_Name", Collections.singletonList(uriRegisterDTO))); } diff --git a/shenyu-common/src/main/java/org/apache/shenyu/common/constant/AdminConstants.java b/shenyu-common/src/main/java/org/apache/shenyu/common/constant/AdminConstants.java index aea082d39047..e3389226cb3d 100644 --- a/shenyu-common/src/main/java/org/apache/shenyu/common/constant/AdminConstants.java +++ b/shenyu-common/src/main/java/org/apache/shenyu/common/constant/AdminConstants.java @@ -73,14 +73,14 @@ public final class AdminConstants { public static final String SYS_DEFAULT_NAMESPACE_ID_DELETE = "The default namespace can't deleted!"; /** - * The constant SYS_DEFAULT_NAMESPACE_NAMESPACE_ID. + * The constant SYS_DEFAULT_NAMESPACE_ID. */ - public static final String SYS_DEFAULT_NAMESPACE_NAMESPACE_ID = "649330b6-c2d7-4edc-be8e-8a54df9eb385"; + public static final String SYS_DEFAULT_NAMESPACE_ID = "649330b6-c2d7-4edc-be8e-8a54df9eb385"; /** - * The constant SYS_DEFAULT_NAMESPACE_ID. + * The constant DEFAULT_NAMESPACE_PRIMARY_KEY. */ - public static final String SYS_DEFAULT_NAMESPACE_ID = "1"; + public static final String DEFAULT_NAMESPACE_PRIMARY_KEY = "1"; /** * The constant SYS_API_ID_NOT_EXIST. From c478cfaf5268b2577c418b2bbcb12667c04136bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=98xcsnx=E2=80=99?= <‘1192709687@qq.com’> Date: Sun, 11 Aug 2024 02:41:12 +0800 Subject: [PATCH 38/61] fix cr --- .../org/apache/shenyu/admin/service/impl/ApiServiceImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/ApiServiceImpl.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/ApiServiceImpl.java index a0bc3750896f..303f8eff8691 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/ApiServiceImpl.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/ApiServiceImpl.java @@ -188,7 +188,7 @@ private void removeRegister(final ApiDO apiDO) { } }); if (CollectionUtils.isNotEmpty(selectorIds)) { - selectorService.delete(selectorIds, SYS_DEFAULT_NAMESPACE_ID); + selectorService.deleteByNamespaceId(selectorIds, SYS_DEFAULT_NAMESPACE_ID); } //clean metadata Optional.ofNullable(metaDataService.findByPath(path)) From 7d2875463fa8587de3d1f855df606aadc6bd190a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=98xcsnx=E2=80=99?= <‘1192709687@qq.com’> Date: Wed, 14 Aug 2024 22:44:21 +0800 Subject: [PATCH 39/61] commit --- .../admin/controller/RuleController.java | 25 ++++++--- .../shenyu/admin/mapper/RuleMapper.java | 3 +- .../shenyu/admin/model/dto/RuleDTO.java | 52 +++++++++++++++++-- .../shenyu/admin/model/entity/RuleDO.java | 48 +++++++++++++++-- .../admin/model/query/RuleQueryCondition.java | 26 +++++++++- .../shenyu/admin/service/RuleService.java | 9 ++-- .../admin/service/impl/ApiServiceImpl.java | 3 +- .../impl/DataPermissionServiceImpl.java | 6 ++- .../admin/service/impl/RuleServiceImpl.java | 15 +++--- ...stractShenyuClientRegisterServiceImpl.java | 11 ++-- .../main/resources/mappers/rule-sqlmap.xml | 13 ++++- .../admin/controller/RuleControllerTest.java | 3 +- .../shenyu/admin/service/RuleServiceTest.java | 8 +-- 13 files changed, 183 insertions(+), 39 deletions(-) diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/controller/RuleController.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/controller/RuleController.java index 5d9a6e41b3c8..859f0780a377 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/controller/RuleController.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/controller/RuleController.java @@ -18,8 +18,10 @@ package org.apache.shenyu.admin.controller; import org.apache.shenyu.admin.aspect.annotation.RestApi; +import org.apache.shenyu.admin.mapper.NamespaceMapper; import org.apache.shenyu.admin.mapper.RuleMapper; import org.apache.shenyu.admin.model.dto.BatchCommonDTO; +import org.apache.shenyu.admin.model.dto.BatchNamespaceCommonDTO; import org.apache.shenyu.admin.model.dto.RuleDTO; import org.apache.shenyu.admin.model.page.CommonPager; import org.apache.shenyu.admin.model.page.PageCondition; @@ -66,16 +68,20 @@ public RuleController(final RuleService ruleService) { * @param name rule name. * @param currentPage current page. * @param pageSize page size. + * @param namespaceId namespaceId. * @return {@linkplain ShenyuAdminResult} */ @GetMapping("") public AdminResult> queryRules(final String selectorId, final String name, @RequestParam @NotNull final Integer currentPage, - @RequestParam @NotNull final Integer pageSize) { + @RequestParam @NotNull final Integer pageSize, + @Valid @Existed(message = "namespaceId is not existed", + provider = NamespaceMapper.class) final String namespaceId) { final RuleQueryCondition condition = new RuleQueryCondition(); condition.setUserId(SessionUtil.visitor().getUserId()); condition.setSelectors(ListUtil.of(selectorId)); condition.setKeyword(name); + condition.setNamespaceId(namespaceId); return searchAdaptor(new PageCondition<>(currentPage, pageSize, condition)); } @@ -83,13 +89,16 @@ public AdminResult> queryRules(final String selectorId, fina * detail rule. * * @param id rule id. + * @param namespaceId namespaceId. * @return {@linkplain ShenyuAdminResult} */ - @GetMapping("/{id}") + @GetMapping("/{id}/{namespaceId}") public ShenyuAdminResult detailRule(@PathVariable("id") @Valid @Existed(provider = RuleMapper.class, - message = "rule is not existed") final String id) { - RuleVO ruleVO = ruleService.findById(id); + message = "rule is not existed") final String id, + @PathVariable("namespaceId") @Valid + @Existed(provider = NamespaceMapper.class, message = "namespaceId is not existed") final String namespaceId) { + RuleVO ruleVO = ruleService.findByIdAndNamespaceId(id, namespaceId); return ShenyuAdminResult.success(ShenyuResultMessage.DETAIL_SUCCESS, ruleVO); } @@ -130,7 +139,7 @@ public ShenyuAdminResult updateRule(@PathVariable("id") @Valid */ @PostMapping("/batchEnabled") public ShenyuAdminResult batchEnabled(@Valid @RequestBody final BatchCommonDTO batchCommonDTO) { - if (!ruleService.enabled(batchCommonDTO.getIds(), batchCommonDTO.getEnabled())) { + if (!ruleService.enabled(batchCommonDTO.getIds(), batchCommonDTO.getEnabled(), batchCommonDTO.getNamespaceId())) { return ShenyuAdminResult.error(ShenyuResultMessage.NOT_FOUND_EXCEPTION); } return ShenyuAdminResult.success(ShenyuResultMessage.ENABLE_SUCCESS); @@ -139,12 +148,12 @@ public ShenyuAdminResult batchEnabled(@Valid @RequestBody final BatchCommonDTO b /** * delete rules. * - * @param ids primary key. + * @param batchNamespaceCommonDTO batchNamespaceCommonDTO. * @return {@linkplain ShenyuAdminResult} */ @DeleteMapping("/batch") - public ShenyuAdminResult deleteRules(@RequestBody @NotEmpty final List<@NotBlank String> ids) { - Integer deleteCount = ruleService.delete(ids); + public ShenyuAdminResult deleteRules(@Valid @RequestBody final BatchNamespaceCommonDTO batchNamespaceCommonDTO) { + Integer deleteCount = ruleService.delete(batchNamespaceCommonDTO.getIds(), batchNamespaceCommonDTO.getNamespaceId()); return ShenyuAdminResult.success(ShenyuResultMessage.DELETE_SUCCESS, deleteCount); } diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/RuleMapper.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/RuleMapper.java index a8490fa06574..fbce08930a9d 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/RuleMapper.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/RuleMapper.java @@ -47,9 +47,10 @@ public interface RuleMapper extends ExistProvider { * select rule by id. * * @param id primary key. + * @param namespaceId namespaceId. * @return {@linkplain RuleDO} */ - RuleDO selectById(String id); + RuleDO selectByIdAndNamespaceId(String id, String namespaceId); /** * select rule by query. diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/dto/RuleDTO.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/dto/RuleDTO.java index bdf2a540732d..66747dd4f8ac 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/dto/RuleDTO.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/dto/RuleDTO.java @@ -17,6 +17,7 @@ package org.apache.shenyu.admin.model.dto; +import org.apache.shenyu.admin.mapper.NamespaceMapper; import org.apache.shenyu.admin.mapper.RuleMapper; import org.apache.shenyu.admin.mapper.SelectorMapper; import org.apache.shenyu.admin.validation.annotation.Existed; @@ -93,6 +94,13 @@ public final class RuleDTO implements Serializable { @NotNull private Boolean matchRestful; + + /** + * namespaceId. + */ + @NotBlank + @Existed(message = "namespaceId is not existed", provider = NamespaceMapper.class) + private String namespaceId; public RuleDTO() { } @@ -106,7 +114,8 @@ public RuleDTO(final String id, @NotNull final Integer sort, final String handle, @Valid final List ruleConditions, - @NotNull final Boolean matchRestful) { + @NotNull final Boolean matchRestful, + @Valid final String namespaceId) { this.id = id; this.selectorId = selectorId; this.matchMode = matchMode; @@ -117,6 +126,7 @@ public RuleDTO(final String id, this.handle = handle; this.ruleConditions = ruleConditions; this.matchRestful = matchRestful; + this.namespaceId = namespaceId; } /** @@ -298,6 +308,24 @@ public Boolean getMatchRestful() { public void setMatchRestful(final Boolean matchRestful) { this.matchRestful = matchRestful; } + + /** + * get namespaceId. + * + * @return namespaceId + */ + public String getNamespaceId() { + return namespaceId; + } + + /** + * set namespaceId. + * + * @param namespaceId namespaceId + */ + public void setNamespaceId(final String namespaceId) { + this.namespaceId = namespaceId; + } /** * builder method. @@ -326,12 +354,14 @@ public boolean equals(final Object o) { && Objects.equals(sort, ruleDTO.sort) && Objects.equals(handle, ruleDTO.handle) && Objects.equals(ruleConditions, ruleDTO.ruleConditions) - && Objects.equals(matchRestful, ruleDTO.getMatchRestful()); + && Objects.equals(matchRestful, ruleDTO.getMatchRestful()) + && Objects.equals(namespaceId, ruleDTO.namespaceId); } @Override public int hashCode() { - return Objects.hash(id, selectorId, matchMode, name, enabled, loged, sort, handle, ruleConditions, matchRestful); + return Objects.hash(id, selectorId, matchMode, name, enabled, loged, sort, handle, ruleConditions, matchRestful, + namespaceId); } public static final class RuleDTOBuilder { @@ -355,6 +385,8 @@ public static final class RuleDTOBuilder { private List ruleConditions; private Boolean matchRestful; + + private String namespaceId; private RuleDTOBuilder() { } @@ -468,6 +500,17 @@ public RuleDTOBuilder matchRestful(final Boolean matchRestful) { this.matchRestful = matchRestful; return this; } + + /** + * namespaceId. + * + * @param namespaceId namespaceId + * @return RuleDOBuilder + */ + public RuleDTOBuilder namespaceId(final String namespaceId) { + this.namespaceId = namespaceId; + return this; + } /** * build method. @@ -475,7 +518,8 @@ public RuleDTOBuilder matchRestful(final Boolean matchRestful) { * @return build object. */ public RuleDTO build() { - return new RuleDTO(id, selectorId, matchMode, name, enabled, loged, sort, handle, ruleConditions, matchRestful); + return new RuleDTO(id, selectorId, matchMode, name, enabled, loged, sort, handle, ruleConditions, matchRestful, + namespaceId); } } } diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/entity/RuleDO.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/entity/RuleDO.java index e06bad12b5ec..4d0a102927ed 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/entity/RuleDO.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/entity/RuleDO.java @@ -76,6 +76,11 @@ public final class RuleDO extends BaseDO { */ private Boolean matchRestful; + /** + * namespaceId. + */ + private String namespaceId; + public RuleDO() { } @@ -86,7 +91,8 @@ public RuleDO(final String selectorId, final Boolean loged, final Integer sort, final String handle, - final Boolean matchRestful) { + final Boolean matchRestful, + final String namespaceId) { this.selectorId = selectorId; this.matchMode = matchMode; this.name = name; @@ -95,6 +101,7 @@ public RuleDO(final String selectorId, this.sort = sort; this.handle = handle; this.matchRestful = matchRestful; + this.namespaceId = namespaceId; } /** @@ -240,6 +247,24 @@ public Boolean getMatchRestful() { public void setMatchRestful(final Boolean matchRestful) { this.matchRestful = matchRestful; } + + /** + * get namespaceId. + * + * @return namespaceId + */ + public String getNamespaceId() { + return namespaceId; + } + + /** + * set namespaceId. + * + * @param namespaceId namespaceId + */ + public void setNamespaceId(final String namespaceId) { + this.namespaceId = namespaceId; + } /** * builder method. @@ -269,6 +294,7 @@ public static RuleDO buildRuleDO(final RuleDTO ruleDTO) { .handle(item.getHandle()) .matchRestful(item.getMatchRestful()) .dateUpdated(currentTime) + .namespaceId(item.getNamespaceId()) .build(); if (StringUtils.isEmpty(item.getId())) { ruleDO.setId(UUIDUtils.getInstance().generateShortUuid()); @@ -338,12 +364,14 @@ public boolean equals(final Object o) { && Objects.equals(loged, ruleDO.loged) && Objects.equals(sort, ruleDO.sort) && Objects.equals(handle, ruleDO.handle) - && Objects.equals(matchRestful, ruleDO.matchRestful); + && Objects.equals(matchRestful, ruleDO.matchRestful) + && Objects.equals(namespaceId, ruleDO.namespaceId); } @Override public int hashCode() { - return Objects.hash(super.hashCode(), selectorId, matchMode, name, enabled, loged, sort, handle, matchRestful); + return Objects.hash(super.hashCode(), selectorId, matchMode, name, enabled, loged, sort, handle, matchRestful, + namespaceId); } public static final class RuleDOBuilder { @@ -370,6 +398,8 @@ public static final class RuleDOBuilder { private Boolean matchRestful; + private String namespaceId; + private RuleDOBuilder() { } @@ -494,6 +524,17 @@ public RuleDOBuilder matchRestful(final Boolean matchRestful) { return this; } + /** + * namespaceId. + * + * @param namespaceId namespaceId + * @return RuleDOBuilder + */ + public RuleDOBuilder namespaceId(final String namespaceId) { + this.namespaceId = namespaceId; + return this; + } + /** * build method. * @@ -512,6 +553,7 @@ public RuleDO build() { ruleDO.setSort(sort); ruleDO.setHandle(handle); ruleDO.setMatchRestful(matchRestful); + ruleDO.setNamespaceId(namespaceId); return ruleDO; } } diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/query/RuleQueryCondition.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/query/RuleQueryCondition.java index a8bb9a8ba134..d7962359dd99 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/query/RuleQueryCondition.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/query/RuleQueryCondition.java @@ -30,7 +30,7 @@ public class RuleQueryCondition extends BaseExcludedSearchCondition implements SearchCondition, SwitchCondition { /** - * search keyword: rule name name. + * search keyword: rule name. */ private String keyword; @@ -49,6 +49,11 @@ public class RuleQueryCondition extends BaseExcludedSearchCondition implements S */ @JsonIgnore private String userId; + + /** + * namespace id. + */ + private String namespaceId; /** * Gets the value of userId. @@ -124,4 +129,23 @@ public List getSelectors() { public void setSelectors(final List selectors) { this.selectors = selectors; } + + /** + * Gets the value of name. + * + * @return the value of name + */ + public String getNamespaceId() { + return namespaceId; + } + + /** + * Sets the namespaceId. + * + * @param namespaceId namespaceId + */ + public void setNamespaceId(final String namespaceId) { + this.namespaceId = namespaceId; + } + } diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/RuleService.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/RuleService.java index c903a42d06d2..60ca7e55be42 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/RuleService.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/RuleService.java @@ -91,17 +91,19 @@ default int createOrUpdate(final RuleDTO ruleDTO) { * delete rules. * * @param ids primary key. + * @param namespaceId namespaceId. * @return rows int */ - int delete(List ids); + int delete(List ids, String namespaceId); /** * find rule by id. * * @param id primary key. + * @param namespaceId namespaceId. * @return {@linkplain RuleVO} */ - RuleVO findById(String id); + RuleVO findByIdAndNamespaceId(String id, String namespaceId); /** * find page of rule by query. @@ -170,7 +172,8 @@ default int createOrUpdate(final RuleDTO ruleDTO) { * * @param ids the ids * @param enabled the enable + * @param namespaceId namespaceId. * @return the result */ - Boolean enabled(List ids, Boolean enabled); + Boolean enabled(List ids, Boolean enabled, String namespaceId); } diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/ApiServiceImpl.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/ApiServiceImpl.java index 303f8eff8691..114df997fa82 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/ApiServiceImpl.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/ApiServiceImpl.java @@ -175,7 +175,8 @@ private void removeRegister(final ApiDO apiDO) { ruleService.delete(rules.stream() .map(RuleVO::getId) .distinct() - .collect(Collectors.toList())); + // todo:[To be refactored with namespace] Temporarily hardcode + .collect(Collectors.toList()),SYS_DEFAULT_NAMESPACE_ID); } //clean selector List selectorDOList = selectorService.findByNameAndPluginNames(apiDO.getContextPath(), PluginEnum.getUpstreamNames()); diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/DataPermissionServiceImpl.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/DataPermissionServiceImpl.java index b50b290bd24c..df6537569e7c 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/DataPermissionServiceImpl.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/DataPermissionServiceImpl.java @@ -52,6 +52,8 @@ import java.util.stream.Collectors; import java.util.stream.Stream; +import static org.apache.shenyu.common.constant.AdminConstants.SYS_DEFAULT_NAMESPACE_ID; + /** * Implementation of the {@link org.apache.shenyu.admin.service.DataPermissionService}. */ @@ -214,8 +216,8 @@ public CommonPager listRulesByPage(final RuleQuery ruleQue @Override @Transactional(rollbackFor = Exception.class) public int createRule(final DataPermissionDTO dataPermissionDTO) { - - RuleDO ruleDO = ruleMapper.selectById(dataPermissionDTO.getDataId()); + // todo:[To be refactored with namespace] Temporarily hardcode + RuleDO ruleDO = ruleMapper.selectByIdAndNamespaceId(dataPermissionDTO.getDataId(), SYS_DEFAULT_NAMESPACE_ID); if (Objects.isNull(ruleDO)) { return 0; } diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/RuleServiceImpl.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/RuleServiceImpl.java index 7e59f5e1f551..f4100290de5e 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/RuleServiceImpl.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/RuleServiceImpl.java @@ -153,7 +153,7 @@ public int create(final RuleDTO ruleDTO) { @Override public int update(final RuleDTO ruleDTO) { - final RuleDO before = ruleMapper.selectById(ruleDTO.getId()); + final RuleDO before = ruleMapper.selectByIdAndNamespaceId(ruleDTO.getId(), ruleDTO.getNamespaceId()); Assert.notNull(before, "the updated rule is not found"); RuleDO ruleDO = RuleDO.buildRuleDO(ruleDTO); final int ruleCount = ruleMapper.updateSelective(ruleDO); @@ -193,12 +193,13 @@ public int update(final RuleDTO ruleDTO) { /** * find rule by id. * - * @param id primary key.. + * @param id primary key. + * @param namespaceId namespaceId. * @return {@linkplain RuleVO} */ @Override - public RuleVO findById(final String id) { - return RuleVO.buildRuleVO(ruleMapper.selectById(id), + public RuleVO findByIdAndNamespaceId(final String id, String namespaceId) { + return RuleVO.buildRuleVO(ruleMapper.selectByIdAndNamespaceId(id, namespaceId), map(ruleConditionMapper.selectByQuery(new RuleConditionQuery(id)), RuleConditionVO::buildRuleConditionVO)); } @@ -291,9 +292,9 @@ public ConfigImportResult importData(final List ruleList) { @Override @Transactional(rollbackFor = Exception.class) - public Boolean enabled(final List ids, final Boolean enabled) { + public Boolean enabled(final List ids, final Boolean enabled, final String namespaceId) { ids.forEach(id -> { - RuleDO ruleDO = ruleMapper.selectById(id); + RuleDO ruleDO = ruleMapper.selectByIdAndNamespaceId(id, namespaceId); RuleDO before = JsonUtils.jsonToObject(JsonUtils.toJson(ruleDO), RuleDO.class); ruleDO.setEnabled(enabled); if (ruleMapper.updateEnable(id, enabled) > 0) { @@ -311,7 +312,7 @@ public Boolean enabled(final List ids, final Boolean enabled) { */ @Override @Transactional(rollbackFor = Exception.class) - public int delete(final List ids) { + public int delete(final List ids, final String namespaceId) { List rules = ruleMapper.selectByIds(ids); final int deleteCount = ruleMapper.deleteByIds(ids); if (deleteCount > 0) { diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/AbstractShenyuClientRegisterServiceImpl.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/AbstractShenyuClientRegisterServiceImpl.java index 01baa4aee2ae..08f725d7aeca 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/AbstractShenyuClientRegisterServiceImpl.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/AbstractShenyuClientRegisterServiceImpl.java @@ -53,6 +53,7 @@ import org.springframework.context.ApplicationEventPublisher; import jakarta.annotation.Resource; + import java.util.Collections; import java.util.List; import java.util.Objects; @@ -137,6 +138,8 @@ public abstract class AbstractShenyuClientRegisterServiceImpl extends FallbackSh */ @Override public String register(final MetaDataRegisterDTO dto) { + String namespaceId = StringUtils.defaultIfEmpty(dto.getNamespaceId(), SYS_DEFAULT_NAMESPACE_ID); + dto.setNamespaceId(namespaceId); //handler plugin selector String selectorHandler = selectorHandler(dto); String selectorId = selectorService.registerDefault(dto, PluginNameAdapter.rpcTypeAdapter(rpcType()), selectorHandler); @@ -283,14 +286,15 @@ protected boolean doSubmit(final String selectorId, final List - SELECT FROM rule WHERE id = #{id, jdbcType=VARCHAR} + AND namespace_id = #{namespaceId, jdbcType=VARCHAR} @@ -247,6 +251,9 @@ handle, + + namespace_id, + #{id, jdbcType=VARCHAR}, @@ -280,6 +287,9 @@ #{handle, jdbcType=VARCHAR}, + + #{namespaceId, jdbcType=VARCHAR}, + @@ -333,6 +343,7 @@ WHERE id = #{id, jdbcType=VARCHAR} + AND namespace_id = #{namespaceId, jdbcType=VARCHAR} diff --git a/shenyu-admin/src/test/java/org/apache/shenyu/admin/controller/RuleControllerTest.java b/shenyu-admin/src/test/java/org/apache/shenyu/admin/controller/RuleControllerTest.java index 4c6db890d893..8bf28686d415 100644 --- a/shenyu-admin/src/test/java/org/apache/shenyu/admin/controller/RuleControllerTest.java +++ b/shenyu-admin/src/test/java/org/apache/shenyu/admin/controller/RuleControllerTest.java @@ -54,6 +54,7 @@ import java.util.Collections; import java.util.List; +import static org.apache.shenyu.common.constant.AdminConstants.SYS_DEFAULT_NAMESPACE_ID; import static org.hamcrest.core.Is.is; import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.given; @@ -120,7 +121,7 @@ public void testQueryRules() throws Exception { @Test public void testDetailRule() throws Exception { - given(this.ruleService.findById("666")).willReturn(ruleVO); + given(this.ruleService.findByIdAndNamespaceId("666", SYS_DEFAULT_NAMESPACE_ID)).willReturn(ruleVO); this.mockMvc.perform(MockMvcRequestBuilders.get("/rule/{id}", "666")) .andExpect(status().isOk()) .andExpect(jsonPath("$.message", is(ShenyuResultMessage.DETAIL_SUCCESS))) diff --git a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/RuleServiceTest.java b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/RuleServiceTest.java index e8d76fe9fb50..a6049fe9704a 100644 --- a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/RuleServiceTest.java +++ b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/RuleServiceTest.java @@ -126,7 +126,7 @@ public void testCreateOrUpdate() { public void testDelete() { publishEvent(); RuleDO ruleDO = buildRuleDO("123"); - given(this.ruleMapper.selectById("123")).willReturn(ruleDO); + given(this.ruleMapper.selectByIdAndNamespaceId("123", SYS_DEFAULT_NAMESPACE_ID)).willReturn(ruleDO); final List ids = Collections.singletonList(ruleDO.getId()); given(this.ruleMapper.deleteByIds(ids)).willReturn(ids.size()); assertEquals(this.ruleService.delete(ids), ids.size()); @@ -135,12 +135,12 @@ public void testDelete() { @Test public void testFindById() { RuleDO ruleDO = buildRuleDO("123"); - given(this.ruleMapper.selectById("123")).willReturn(ruleDO); + given(this.ruleMapper.selectByIdAndNamespaceId("123", SYS_DEFAULT_NAMESPACE_ID)).willReturn(ruleDO); RuleConditionQuery ruleConditionQuery = buildRuleConditionQuery(); RuleConditionDO ruleCondition = buildRuleConditionDO(); given(this.ruleConditionMapper.selectByQuery(ruleConditionQuery)).willReturn(Collections.singletonList(ruleCondition)); RuleVO ruleVO = buildRuleVO(); - final RuleVO ruleVOById = this.ruleService.findById("123"); + final RuleVO ruleVOById = this.ruleService.findByIdAndNamespaceId("123", SYS_DEFAULT_NAMESPACE_ID); assertNotNull(ruleVOById); assertEquals(ruleVOById.getId(), ruleVO.getId()); } @@ -294,7 +294,7 @@ private void testCreate() { private void testUpdate() { RuleDTO ruleDTO = buildRuleDTO("123"); - given(this.ruleMapper.selectById("123")).willReturn(RuleDO.builder().id("123").build()); + given(this.ruleMapper.selectByIdAndNamespaceId("123", SYS_DEFAULT_NAMESPACE_ID)).willReturn(RuleDO.builder().id("123").build()); given(this.ruleMapper.updateSelective(any())).willReturn(1); assertThat(this.ruleService.createOrUpdate(ruleDTO), greaterThan(0)); } From b34cfa7f3cb2f69f915b0059171da789a84460ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=98xcsnx=E2=80=99?= <‘1192709687@qq.com’> Date: Thu, 15 Aug 2024 21:57:46 +0800 Subject: [PATCH 40/61] commit --- db/init/mysql/schema.sql | 4 +++- db/init/og/create-table.sql | 2 ++ db/init/pg/create-table.sql | 5 ++++- db/upgrade/2.6.1-upgrade-2.7.0-mysql.sql | 7 +++++++ db/upgrade/2.6.1-upgrade-2.7.0-og.sql | 7 ++++++- db/upgrade/2.6.1-upgrade-2.7.0-oracle.sql | 7 ++++++- db/upgrade/2.6.1-upgrade-2.7.0-pg.sql | 7 ++++++- .../shenyu/admin/controller/RuleController.java | 4 ++-- .../org/apache/shenyu/admin/mapper/RuleMapper.java | 2 +- .../apache/shenyu/admin/service/RuleService.java | 14 +++++++------- .../shenyu/admin/service/impl/ApiServiceImpl.java | 2 +- .../shenyu/admin/service/impl/RuleServiceImpl.java | 8 ++++---- .../src/main/resources/sql-script/h2/schema.sql | 4 +++- .../admin/controller/RuleControllerTest.java | 4 ++-- .../shenyu/admin/service/RuleServiceTest.java | 2 +- 15 files changed, 55 insertions(+), 24 deletions(-) diff --git a/db/init/mysql/schema.sql b/db/init/mysql/schema.sql index f7f0062218eb..e75a0621d804 100644 --- a/db/init/mysql/schema.sql +++ b/db/init/mysql/schema.sql @@ -2371,4 +2371,6 @@ INSERT INTO `shenyu`.`permission` (`id`, `object_id`, `resource_id`, `date_creat INSERT INTO `shenyu`.`permission` (`id`, `object_id`, `resource_id`, `date_created`, `date_updated`) VALUES ('1792779493541343266', '1346358560427216896', '1792749362445840485', '2024-06-25 20:00:00.000', '2024-06-25 20:00:00.000'); INSERT INTO `shenyu`.`permission` (`id`, `object_id`, `resource_id`, `date_created`, `date_updated`) VALUES ('1792779493541343267', '1346358560427216896', '1792749362445840486', '2024-06-25 20:00:00.000', '2024-06-25 20:00:00.000'); -ALTER TABLE `shenyu`.`selector` ADD COLUMN `namespace_id` varchar(50) NULL COMMENT 'namespaceId' AFTER `match_restful`; \ No newline at end of file +ALTER TABLE `shenyu`.`selector` ADD COLUMN `namespace_id` varchar(50) NULL COMMENT 'namespaceId' AFTER `match_restful`; + +ALTER TABLE `shenyu`.`rule` ADD COLUMN `namespace_id` varchar(50) NULL COMMENT 'namespaceId' AFTER `match_restful`; \ No newline at end of file diff --git a/db/init/og/create-table.sql b/db/init/og/create-table.sql index ebc4a2cbc30b..35d666805c1c 100644 --- a/db/init/og/create-table.sql +++ b/db/init/og/create-table.sql @@ -2677,3 +2677,5 @@ INSERT INTO "public"."permission" VALUES ('1792779493541343267', '13463585604272 ALTER TABLE "public"."selector" ADD COLUMN namespace_id VARCHAR(50) NULL; COMMENT ON COLUMN "public"."selector"."namespace_id" IS 'namespaceId'; +ALTER TABLE "public"."rule" ADD COLUMN namespace_id VARCHAR(50) NULL; +COMMENT ON COLUMN "public"."rule"."namespace_id" IS 'namespaceId'; \ No newline at end of file diff --git a/db/init/pg/create-table.sql b/db/init/pg/create-table.sql index dec5fcbfb536..576c39c0072a 100644 --- a/db/init/pg/create-table.sql +++ b/db/init/pg/create-table.sql @@ -2792,4 +2792,7 @@ INSERT INTO "public"."permission" VALUES ('1792779493541343266', '13463585604272 INSERT INTO "public"."permission" VALUES ('1792779493541343267', '1346358560427216896', '1792749362445840486', '2024-06-25 20:00:00.000', '2024-06-25 20:00:00.000'); ALTER TABLE "public"."selector" ADD COLUMN namespace_id VARCHAR(50) NULL; -COMMENT ON COLUMN "public"."selector"."namespace_id" IS 'namespaceId'; \ No newline at end of file +COMMENT ON COLUMN "public"."selector"."namespace_id" IS 'namespaceId'; + +ALTER TABLE "public"."rule" ADD COLUMN namespace_id VARCHAR(50) NULL; +COMMENT ON COLUMN "public"."rule"."namespace_id" IS 'namespaceId'; \ No newline at end of file diff --git a/db/upgrade/2.6.1-upgrade-2.7.0-mysql.sql b/db/upgrade/2.6.1-upgrade-2.7.0-mysql.sql index d0b2859f8aaa..a22157689d68 100755 --- a/db/upgrade/2.6.1-upgrade-2.7.0-mysql.sql +++ b/db/upgrade/2.6.1-upgrade-2.7.0-mysql.sql @@ -174,4 +174,11 @@ ALTER TABLE `shenyu`.`selector` ADD COLUMN `namespace_id` varchar(50) NULL COMME UPDATE selector SET namespace_id = '649330b6-c2d7-4edc-be8e-8a54df9eb385' +WHERE namespaceId IS NULL; + + +ALTER TABLE `shenyu`.`rule` ADD COLUMN `namespace_id` varchar(50) NULL COMMENT 'namespaceId' AFTER `match_restful`; + +UPDATE rule +SET namespace_id = '649330b6-c2d7-4edc-be8e-8a54df9eb385' WHERE namespaceId IS NULL; \ No newline at end of file diff --git a/db/upgrade/2.6.1-upgrade-2.7.0-og.sql b/db/upgrade/2.6.1-upgrade-2.7.0-og.sql index 12a3acfc1a0b..6ab950d4a0f9 100644 --- a/db/upgrade/2.6.1-upgrade-2.7.0-og.sql +++ b/db/upgrade/2.6.1-upgrade-2.7.0-og.sql @@ -196,4 +196,9 @@ COMMENT ON COLUMN "public"."dashboard_user".client_id IS 'client id'; ALTER TABLE "public"."selector" ADD COLUMN namespace_id VARCHAR(50) NULL; COMMENT ON COLUMN "public"."selector"."namespace_id" IS 'namespaceId'; -UPDATE "public"."selector" SET namespace_id = '649330b6-c2d7-4edc-be8e-8a54df9eb385' WHERE namespace_id IS NULL; \ No newline at end of file +UPDATE "public"."selector" SET namespace_id = '649330b6-c2d7-4edc-be8e-8a54df9eb385' WHERE namespace_id IS NULL; + +ALTER TABLE "public"."rule" ADD COLUMN namespace_id VARCHAR(50) NULL; +COMMENT ON COLUMN "public"."rule"."namespace_id" IS 'namespaceId'; + +UPDATE "public"."rule" SET namespace_id = '649330b6-c2d7-4edc-be8e-8a54df9eb385' WHERE namespace_id IS NULL; \ No newline at end of file diff --git a/db/upgrade/2.6.1-upgrade-2.7.0-oracle.sql b/db/upgrade/2.6.1-upgrade-2.7.0-oracle.sql index 05209e1cba4f..407fe8dbf6d1 100755 --- a/db/upgrade/2.6.1-upgrade-2.7.0-oracle.sql +++ b/db/upgrade/2.6.1-upgrade-2.7.0-oracle.sql @@ -222,4 +222,9 @@ COMMENT ON COLUMN dashboard_user.client_id IS 'client id'; ALTER TABLE selector ADD namespace_id VARCHAR2(50) NULL; COMMENT ON COLUMN selector.namespace_id IS 'namespaceId'; -UPDATE selector SET namespace_id = '649330b6-c2d7-4edc-be8e-8a54df9eb385' WHERE namespace_id IS NULL; \ No newline at end of file +UPDATE selector SET namespace_id = '649330b6-c2d7-4edc-be8e-8a54df9eb385' WHERE namespace_id IS NULL; + +ALTER TABLE rule ADD namespace_id VARCHAR2(50) NULL; +COMMENT ON COLUMN rule.namespace_id IS 'namespaceId'; + +UPDATE rule SET namespace_id = '649330b6-c2d7-4edc-be8e-8a54df9eb385' WHERE namespace_id IS NULL; \ No newline at end of file diff --git a/db/upgrade/2.6.1-upgrade-2.7.0-pg.sql b/db/upgrade/2.6.1-upgrade-2.7.0-pg.sql index dc24306f3c8c..32fd8894a653 100755 --- a/db/upgrade/2.6.1-upgrade-2.7.0-pg.sql +++ b/db/upgrade/2.6.1-upgrade-2.7.0-pg.sql @@ -197,4 +197,9 @@ COMMENT ON COLUMN "public"."dashboard_user".client_id IS 'client id'; ALTER TABLE "public"."selector" ADD COLUMN namespace_id VARCHAR(50) NULL; COMMENT ON COLUMN "public"."selector"."namespace_id" IS 'namespaceId'; -UPDATE "public"."selector" SET namespace_id = '649330b6-c2d7-4edc-be8e-8a54df9eb385' WHERE namespace_id IS NULL; \ No newline at end of file +UPDATE "public"."selector" SET namespace_id = '649330b6-c2d7-4edc-be8e-8a54df9eb385' WHERE namespace_id IS NULL; + +ALTER TABLE "public"."rule" ADD COLUMN namespace_id VARCHAR(50) NULL; +COMMENT ON COLUMN "public"."rule"."namespace_id" IS 'namespaceId'; + +UPDATE "public"."rule" SET namespace_id = '649330b6-c2d7-4edc-be8e-8a54df9eb385' WHERE namespace_id IS NULL; \ No newline at end of file diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/controller/RuleController.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/controller/RuleController.java index 859f0780a377..6b9251c8607d 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/controller/RuleController.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/controller/RuleController.java @@ -139,7 +139,7 @@ public ShenyuAdminResult updateRule(@PathVariable("id") @Valid */ @PostMapping("/batchEnabled") public ShenyuAdminResult batchEnabled(@Valid @RequestBody final BatchCommonDTO batchCommonDTO) { - if (!ruleService.enabled(batchCommonDTO.getIds(), batchCommonDTO.getEnabled(), batchCommonDTO.getNamespaceId())) { + if (!ruleService.enabledByIdsAndNamespaceId(batchCommonDTO.getIds(), batchCommonDTO.getEnabled(), batchCommonDTO.getNamespaceId())) { return ShenyuAdminResult.error(ShenyuResultMessage.NOT_FOUND_EXCEPTION); } return ShenyuAdminResult.success(ShenyuResultMessage.ENABLE_SUCCESS); @@ -153,7 +153,7 @@ public ShenyuAdminResult batchEnabled(@Valid @RequestBody final BatchCommonDTO b */ @DeleteMapping("/batch") public ShenyuAdminResult deleteRules(@Valid @RequestBody final BatchNamespaceCommonDTO batchNamespaceCommonDTO) { - Integer deleteCount = ruleService.delete(batchNamespaceCommonDTO.getIds(), batchNamespaceCommonDTO.getNamespaceId()); + Integer deleteCount = ruleService.deleteByIdsAndNamespaceId(batchNamespaceCommonDTO.getIds(), batchNamespaceCommonDTO.getNamespaceId()); return ShenyuAdminResult.success(ShenyuResultMessage.DELETE_SUCCESS, deleteCount); } diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/RuleMapper.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/RuleMapper.java index fbce08930a9d..11568c05c830 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/RuleMapper.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/RuleMapper.java @@ -44,7 +44,7 @@ public interface RuleMapper extends ExistProvider { Boolean existed(@Param("id") Serializable id); /** - * select rule by id. + * select rule by id and namespaceId. * * @param id primary key. * @param namespaceId namespaceId. diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/RuleService.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/RuleService.java index 60ca7e55be42..d4c228130166 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/RuleService.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/RuleService.java @@ -88,16 +88,16 @@ default int createOrUpdate(final RuleDTO ruleDTO) { int update(RuleDTO ruleDTO); /** - * delete rules. + * delete rules by ids and namespaceId. * * @param ids primary key. * @param namespaceId namespaceId. * @return rows int */ - int delete(List ids, String namespaceId); + int deleteByIdsAndNamespaceId(List ids, String namespaceId); /** - * find rule by id. + * find rule by id and namespaceId. * * @param id primary key. * @param namespaceId namespaceId. @@ -168,12 +168,12 @@ default int createOrUpdate(final RuleDTO ruleDTO) { ConfigImportResult importData(List ruleList); /** - * Enabled string. + * Enabled string by ids and namespaceId. * * @param ids the ids - * @param enabled the enable - * @param namespaceId namespaceId. + * @param enabled the enabled + * @param namespaceId the namespaceId. * @return the result */ - Boolean enabled(List ids, Boolean enabled, String namespaceId); + Boolean enabledByIdsAndNamespaceId(List ids, Boolean enabled, String namespaceId); } diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/ApiServiceImpl.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/ApiServiceImpl.java index 114df997fa82..e058beb553ef 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/ApiServiceImpl.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/ApiServiceImpl.java @@ -172,7 +172,7 @@ private void removeRegister(final ApiDO apiDO) { //clean rule final List rules = ruleService.searchByCondition(condition); if (CollectionUtils.isNotEmpty(rules)) { - ruleService.delete(rules.stream() + ruleService.deleteByIdsAndNamespaceId(rules.stream() .map(RuleVO::getId) .distinct() // todo:[To be refactored with namespace] Temporarily hardcode diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/RuleServiceImpl.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/RuleServiceImpl.java index f4100290de5e..cd14b20c7464 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/RuleServiceImpl.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/RuleServiceImpl.java @@ -191,7 +191,7 @@ public int update(final RuleDTO ruleDTO) { } /** - * find rule by id. + * find rule by id and namespaceId. * * @param id primary key. * @param namespaceId namespaceId. @@ -292,7 +292,7 @@ public ConfigImportResult importData(final List ruleList) { @Override @Transactional(rollbackFor = Exception.class) - public Boolean enabled(final List ids, final Boolean enabled, final String namespaceId) { + public Boolean enabledByIdsAndNamespaceId(final List ids, final Boolean enabled, final String namespaceId) { ids.forEach(id -> { RuleDO ruleDO = ruleMapper.selectByIdAndNamespaceId(id, namespaceId); RuleDO before = JsonUtils.jsonToObject(JsonUtils.toJson(ruleDO), RuleDO.class); @@ -305,14 +305,14 @@ public Boolean enabled(final List ids, final Boolean enabled, final Stri } /** - * delete rules. + * delete rules by ids and namespaceId. * * @param ids primary key. * @return rows */ @Override @Transactional(rollbackFor = Exception.class) - public int delete(final List ids, final String namespaceId) { + public int deleteByIdsAndNamespaceId(final List ids, final String namespaceId) { List rules = ruleMapper.selectByIds(ids); final int deleteCount = ruleMapper.deleteByIds(ids); if (deleteCount > 0) { diff --git a/shenyu-admin/src/main/resources/sql-script/h2/schema.sql b/shenyu-admin/src/main/resources/sql-script/h2/schema.sql index 3070489cee29..755d205cec31 100755 --- a/shenyu-admin/src/main/resources/sql-script/h2/schema.sql +++ b/shenyu-admin/src/main/resources/sql-script/h2/schema.sql @@ -1342,4 +1342,6 @@ INSERT IGNORE INTO `permission` (`id`, `object_id`, `resource_id`, `date_created INSERT IGNORE INTO `permission` (`id`, `object_id`, `resource_id`, `date_created`, `date_updated`) VALUES ('1792779493541343266', '1346358560427216896', '1792749362445840485', '2024-06-25 20:00:00.000', '2024-06-25 20:00:00.000'); INSERT IGNORE INTO `permission` (`id`, `object_id`, `resource_id`, `date_created`, `date_updated`) VALUES ('1792779493541343267', '1346358560427216896', '1792749362445840486', '2024-06-25 20:00:00.000', '2024-06-25 20:00:00.000'); -ALTER TABLE `selector` ADD COLUMN `namespace_id` varchar(50) NULL COMMENT 'namespaceId' AFTER `match_restful`; \ No newline at end of file +ALTER TABLE `selector` ADD COLUMN `namespace_id` varchar(50) NULL COMMENT 'namespaceId' AFTER `match_restful`; + +ALTER TABLE `rule` ADD COLUMN `namespace_id` varchar(50) NULL COMMENT 'namespaceId' AFTER `match_restful`; \ No newline at end of file diff --git a/shenyu-admin/src/test/java/org/apache/shenyu/admin/controller/RuleControllerTest.java b/shenyu-admin/src/test/java/org/apache/shenyu/admin/controller/RuleControllerTest.java index 8bf28686d415..e97fa0faa116 100644 --- a/shenyu-admin/src/test/java/org/apache/shenyu/admin/controller/RuleControllerTest.java +++ b/shenyu-admin/src/test/java/org/apache/shenyu/admin/controller/RuleControllerTest.java @@ -212,7 +212,7 @@ public void testUpdateRule() throws Exception { @Test public void testDeleteRules() throws Exception { - given(this.ruleService.delete(Collections.singletonList("111"))).willReturn(1); + given(this.ruleService.deleteByIdsAndNamespaceId(Collections.singletonList("111"), SYS_DEFAULT_NAMESPACE_ID)).willReturn(1); this.mockMvc.perform(MockMvcRequestBuilders.delete("/rule/batch") .contentType(MediaType.APPLICATION_JSON) .content("[\"111\"]") @@ -240,7 +240,7 @@ public void testEnableRule() throws Exception { when(ruleMapper.existed(ruleDTO.getId())).thenReturn(true); when(SpringBeanUtils.getInstance().getBean(SelectorMapper.class)).thenReturn(selectorMapper); when(selectorMapper.existed(ruleDTO.getSelectorId())).thenReturn(true); - given(this.ruleService.enabled(Arrays.asList(ruleDTO.getId()), false)).willReturn(true); + given(this.ruleService.enabledByIdsAndNamespaceId(Arrays.asList(ruleDTO.getId()), false, SYS_DEFAULT_NAMESPACE_ID)).willReturn(true); BatchCommonDTO batchCommonDTO = new BatchCommonDTO(); batchCommonDTO.setIds(Arrays.asList(ruleDTO.getId())); batchCommonDTO.setEnabled(false); diff --git a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/RuleServiceTest.java b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/RuleServiceTest.java index a6049fe9704a..711766d25a62 100644 --- a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/RuleServiceTest.java +++ b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/RuleServiceTest.java @@ -129,7 +129,7 @@ public void testDelete() { given(this.ruleMapper.selectByIdAndNamespaceId("123", SYS_DEFAULT_NAMESPACE_ID)).willReturn(ruleDO); final List ids = Collections.singletonList(ruleDO.getId()); given(this.ruleMapper.deleteByIds(ids)).willReturn(ids.size()); - assertEquals(this.ruleService.delete(ids), ids.size()); + assertEquals(this.ruleService.deleteByIdsAndNamespaceId(ids, SYS_DEFAULT_NAMESPACE_ID), ids.size()); } @Test From fc04662de738334ae8e5b701da0a8be596b16909 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=98xcsnx=E2=80=99?= <‘1192709687@qq.com’> Date: Thu, 15 Aug 2024 23:37:33 +0800 Subject: [PATCH 41/61] support e2e --- .../admin/controller/RuleController.java | 8 +--- .../admin/service/impl/ApiServiceImpl.java | 2 +- .../admin/service/impl/RuleServiceImpl.java | 2 +- .../shenyu/admin/mapper/RuleMapperTest.java | 10 +++-- .../service/DataPermissionServiceTest.java | 5 ++- .../shenyu/e2e/client/admin/AdminClient.java | 2 + .../shenyu/e2e/model/data/RuleData.java | 37 +++++++++++++++++++ .../e2e/model/data/RuleQueryCondition.java | 21 +++++++++++ 8 files changed, 73 insertions(+), 14 deletions(-) diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/controller/RuleController.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/controller/RuleController.java index 6b9251c8607d..78a9f2695fd9 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/controller/RuleController.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/controller/RuleController.java @@ -17,6 +17,8 @@ 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.RuleMapper; @@ -43,12 +45,6 @@ import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestParam; -import jakarta.validation.Valid; -import jakarta.validation.constraints.NotBlank; -import jakarta.validation.constraints.NotEmpty; -import jakarta.validation.constraints.NotNull; -import java.util.List; - /** * this is rule controller. */ diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/ApiServiceImpl.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/ApiServiceImpl.java index e058beb553ef..7041dcbd6caa 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/ApiServiceImpl.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/ApiServiceImpl.java @@ -176,7 +176,7 @@ private void removeRegister(final ApiDO apiDO) { .map(RuleVO::getId) .distinct() // todo:[To be refactored with namespace] Temporarily hardcode - .collect(Collectors.toList()),SYS_DEFAULT_NAMESPACE_ID); + .collect(Collectors.toList()), SYS_DEFAULT_NAMESPACE_ID); } //clean selector List selectorDOList = selectorService.findByNameAndPluginNames(apiDO.getContextPath(), PluginEnum.getUpstreamNames()); diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/RuleServiceImpl.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/RuleServiceImpl.java index cd14b20c7464..069a1c08a5d4 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/RuleServiceImpl.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/RuleServiceImpl.java @@ -198,7 +198,7 @@ public int update(final RuleDTO ruleDTO) { * @return {@linkplain RuleVO} */ @Override - public RuleVO findByIdAndNamespaceId(final String id, String namespaceId) { + public RuleVO findByIdAndNamespaceId(final String id, final String namespaceId) { return RuleVO.buildRuleVO(ruleMapper.selectByIdAndNamespaceId(id, namespaceId), map(ruleConditionMapper.selectByQuery(new RuleConditionQuery(id)), RuleConditionVO::buildRuleConditionVO)); } diff --git a/shenyu-admin/src/test/java/org/apache/shenyu/admin/mapper/RuleMapperTest.java b/shenyu-admin/src/test/java/org/apache/shenyu/admin/mapper/RuleMapperTest.java index 05794da16e1e..058f79d658fc 100644 --- a/shenyu-admin/src/test/java/org/apache/shenyu/admin/mapper/RuleMapperTest.java +++ b/shenyu-admin/src/test/java/org/apache/shenyu/admin/mapper/RuleMapperTest.java @@ -26,6 +26,8 @@ import java.sql.Timestamp; import java.util.List; import java.util.Random; + +import static org.apache.shenyu.common.constant.AdminConstants.SYS_DEFAULT_NAMESPACE_ID; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.MatcherAssert.assertThat; @@ -43,7 +45,7 @@ public void selectById() { int insert = ruleMapper.insert(ruleDO); assertThat(insert, equalTo(1)); - RuleDO resultRuleDO = ruleMapper.selectById(ruleDO.getId()); + RuleDO resultRuleDO = ruleMapper.selectByIdAndNamespaceId(ruleDO.getId(), SYS_DEFAULT_NAMESPACE_ID); assertThat(ruleDO, equalTo(resultRuleDO)); int delete = ruleMapper.delete(ruleDO.getId()); @@ -138,7 +140,7 @@ public void update() { int update = ruleMapper.update(ruleDO); assertThat(update, equalTo(1)); - RuleDO resultRuleDO = ruleMapper.selectById(ruleDO.getId()); + RuleDO resultRuleDO = ruleMapper.selectByIdAndNamespaceId(ruleDO.getId(), SYS_DEFAULT_NAMESPACE_ID); assertThat(ruleDO, equalTo(resultRuleDO)); int delete = ruleMapper.delete(ruleDO.getId()); @@ -155,7 +157,7 @@ public void updateSelective() { int update = ruleMapper.update(ruleDO); assertThat(update, equalTo(1)); - RuleDO resultRuleDO = ruleMapper.selectById(ruleDO.getId()); + RuleDO resultRuleDO = ruleMapper.selectByIdAndNamespaceId(ruleDO.getId(), SYS_DEFAULT_NAMESPACE_ID); assertThat(ruleDO.getHandle(), equalTo(resultRuleDO.getHandle())); int delete = ruleMapper.delete(ruleDO.getId()); @@ -171,7 +173,7 @@ public void delete() { int delete = ruleMapper.delete(ruleDO.getId()); assertThat(delete, equalTo(1)); - RuleDO resultRuleDO = ruleMapper.selectById(ruleDO.getId()); + RuleDO resultRuleDO = ruleMapper.selectByIdAndNamespaceId(ruleDO.getId(), SYS_DEFAULT_NAMESPACE_ID); assertThat(resultRuleDO, equalTo(null)); } diff --git a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/DataPermissionServiceTest.java b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/DataPermissionServiceTest.java index f35edf975158..5891d72514db 100644 --- a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/DataPermissionServiceTest.java +++ b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/DataPermissionServiceTest.java @@ -45,6 +45,7 @@ import java.util.LinkedList; import java.util.List; +import static org.apache.shenyu.common.constant.AdminConstants.SYS_DEFAULT_NAMESPACE_ID; import static org.hamcrest.Matchers.is; import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.ArgumentMatchers.any; @@ -78,7 +79,7 @@ public final class DataPermissionServiceTest { @BeforeEach public void setup() { - ruleDTO = new RuleDTO("1", "1", 1, "test", true, true, 1, "test", null, false); + ruleDTO = new RuleDTO("1", "1", 1, "test", true, true, 1, "test", null, false, SYS_DEFAULT_NAMESPACE_ID); dataPermissionDTO = new DataPermissionDTO(); dataPermissionDTO.setId("1"); dataPermissionDTO.setUserId("1001"); @@ -143,7 +144,7 @@ public void assertListRulesByPage() { @Test public void assertCreateRule() { - given(ruleMapper.selectById("1")).willReturn(RuleDO.buildRuleDO(ruleDTO)); + given(ruleMapper.selectByIdAndNamespaceId("1", SYS_DEFAULT_NAMESPACE_ID)).willReturn(RuleDO.buildRuleDO(ruleDTO)); given(dataPermissionMapper.insertSelective(any(DataPermissionDO.class))).willReturn(1); assertThat(dataPermissionService.createRule(dataPermissionDTO), is(2)); } 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 f57572379e5b..2e9a5632f910 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 @@ -277,6 +277,7 @@ public SearchedResources searchRules(final String keyword, final String RuleQueryCondition condition = RuleQueryCondition.builder() .keyword(keyword) .selectors(selectors) + .namespaceId(SYS_DEFAULT_NAMESPACE_NAMESPACE_ID) .switchStatus(true) .build(); return search("/rule/list/search", condition, SEARCHED_RULES_TYPE_REFERENCE); @@ -333,6 +334,7 @@ public SelectorDTO create(final SelectorData selector) { * @return RuleDTO */ public RuleDTO create(final RuleData rule) { + rule.setNamespaceId(SYS_DEFAULT_NAMESPACE_NAMESPACE_ID); RuleDTO dto = create("/rule", rule); Rules.INSTANCE.put(rule.getName(), dto.getId()); return dto; diff --git a/shenyu-e2e/shenyu-e2e-common/src/main/java/org/apache/shenyu/e2e/model/data/RuleData.java b/shenyu-e2e/shenyu-e2e-common/src/main/java/org/apache/shenyu/e2e/model/data/RuleData.java index 7cf3c72cd381..ca80dfb4cbb6 100644 --- a/shenyu-e2e/shenyu-e2e-common/src/main/java/org/apache/shenyu/e2e/model/data/RuleData.java +++ b/shenyu-e2e/shenyu-e2e-common/src/main/java/org/apache/shenyu/e2e/model/data/RuleData.java @@ -76,6 +76,11 @@ public final class RuleData implements ResourceData { */ private Boolean matchRestful; + /** + * namespaceId. + */ + private String namespaceId; + /** * builder constructor. * @@ -92,6 +97,7 @@ private RuleData(final RuleDataBuilder builder) { this.conditionList = builder.conditionList; this.enabled = builder.enabled; this.matchRestful = builder.matchRestful; + this.namespaceId = builder.namespaceId; } /** @@ -286,6 +292,24 @@ public Boolean getMatchRestful() { return matchRestful; } + /** + * get namespaceId. + * + * @return namespaceId + */ + public String getNamespaceId() { + return namespaceId; + } + + /** + * set namespaceId. + * + * @param namespaceId namespaceId + */ + public void setNamespaceId(final String namespaceId) { + this.namespaceId = namespaceId; + } + /** * class builder. */ @@ -314,6 +338,8 @@ public static final class RuleDataBuilder { private Boolean matchRestful; + private String namespaceId; + /** * no args constructor. */ @@ -439,5 +465,16 @@ public RuleDataBuilder matchRestful(final Boolean matchRestful) { this.matchRestful = matchRestful; return this; } + + /** + * build namespaceId. + * + * @param namespaceId namespaceId + * @return this + */ + public RuleDataBuilder namespaceId(final String namespaceId) { + this.namespaceId = namespaceId; + return this; + } } } diff --git a/shenyu-e2e/shenyu-e2e-common/src/main/java/org/apache/shenyu/e2e/model/data/RuleQueryCondition.java b/shenyu-e2e/shenyu-e2e-common/src/main/java/org/apache/shenyu/e2e/model/data/RuleQueryCondition.java index 0491296d4e12..c10a520ca6e2 100644 --- a/shenyu-e2e/shenyu-e2e-common/src/main/java/org/apache/shenyu/e2e/model/data/RuleQueryCondition.java +++ b/shenyu-e2e/shenyu-e2e-common/src/main/java/org/apache/shenyu/e2e/model/data/RuleQueryCondition.java @@ -46,6 +46,11 @@ public final class RuleQueryCondition implements QueryCondition { * status switch. */ private boolean switchStatus; + + /** + * status switch. + */ + private String namespaceId; /** * builder constructor. @@ -56,6 +61,7 @@ private RuleQueryCondition(final Builder builder) { this.keyword = builder.keyword; this.selectors = builder.selectors; this.switchStatus = builder.switchStatus; + this.namespaceId = builder.namespaceId; } /** @@ -151,6 +157,8 @@ public String toString() { + Arrays.toString(selectors) + ", switchStatus=" + switchStatus + + ", namespaceId=" + + namespaceId + '}'; } @@ -166,6 +174,8 @@ public static final class Builder { private String[] selectors; private boolean switchStatus; + + private String namespaceId; /** * no args constructor. @@ -226,5 +236,16 @@ public Builder switchStatus(final boolean switchStatus) { this.switchStatus = switchStatus; return this; } + + /** + * namespaceId. + * + * @param namespaceId namespaceId + * @return SelectorDOBuilder + */ + public Builder namespaceId(final String namespaceId) { + this.namespaceId = namespaceId; + return this; + } } } From 7650380d14704120c5f4767a38d611f703560eb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=98xcsnx=E2=80=99?= <‘1192709687@qq.com’> Date: Fri, 16 Aug 2024 19:55:57 +0800 Subject: [PATCH 42/61] commit meta_data --- db/init/mysql/schema.sql | 4 +- db/init/og/create-table.sql | 5 +- db/init/oracle/schema.sql | 8 +- db/init/pg/create-table.sql | 5 +- db/upgrade/2.6.1-upgrade-2.7.0-mysql.sql | 10 +- db/upgrade/2.6.1-upgrade-2.7.0-og.sql | 7 +- db/upgrade/2.6.1-upgrade-2.7.0-oracle.sql | 7 +- db/upgrade/2.6.1-upgrade-2.7.0-pg.sql | 7 +- .../admin/controller/MetaDataController.java | 15 +- .../shenyu/admin/model/entity/MetaDataDO.java | 47 +++- .../admin/model/query/MetaDataQuery.java | 31 ++- .../shenyu/admin/model/vo/MetaDataVO.java | 35 ++- .../resources/mappers/meta-data-sqlmap.xml | 212 +++++++++--------- .../main/resources/sql-script/h2/schema.sql | 4 +- .../controller/MetaDataControllerTest.java | 5 +- 15 files changed, 274 insertions(+), 128 deletions(-) diff --git a/db/init/mysql/schema.sql b/db/init/mysql/schema.sql index e75a0621d804..4a96c40970db 100644 --- a/db/init/mysql/schema.sql +++ b/db/init/mysql/schema.sql @@ -2373,4 +2373,6 @@ INSERT INTO `shenyu`.`permission` (`id`, `object_id`, `resource_id`, `date_creat ALTER TABLE `shenyu`.`selector` ADD COLUMN `namespace_id` varchar(50) NULL COMMENT 'namespaceId' AFTER `match_restful`; -ALTER TABLE `shenyu`.`rule` ADD COLUMN `namespace_id` varchar(50) NULL COMMENT 'namespaceId' AFTER `match_restful`; \ No newline at end of file +ALTER TABLE `shenyu`.`rule` ADD COLUMN `namespace_id` varchar(50) NULL COMMENT 'namespaceId' AFTER `match_restful`; + +ALTER TABLE `shenyu`.`meta_data` ADD COLUMN `namespace_id` varchar(50) NULL COMMENT 'namespaceId'; \ No newline at end of file diff --git a/db/init/og/create-table.sql b/db/init/og/create-table.sql index 35d666805c1c..398a487ca125 100644 --- a/db/init/og/create-table.sql +++ b/db/init/og/create-table.sql @@ -2678,4 +2678,7 @@ ALTER TABLE "public"."selector" ADD COLUMN namespace_id VARCHAR(50) NULL; COMMENT ON COLUMN "public"."selector"."namespace_id" IS 'namespaceId'; ALTER TABLE "public"."rule" ADD COLUMN namespace_id VARCHAR(50) NULL; -COMMENT ON COLUMN "public"."rule"."namespace_id" IS 'namespaceId'; \ No newline at end of file +COMMENT ON COLUMN "public"."rule"."namespace_id" IS 'namespaceId'; + +ALTER TABLE "public"."meta_data" ADD COLUMN namespace_id VARCHAR(50) NULL; +COMMENT ON COLUMN "public"."meta_data"."namespace_id" IS 'namespaceId'; \ No newline at end of file diff --git a/db/init/oracle/schema.sql b/db/init/oracle/schema.sql index 1197f14fb219..6f6b33fef05b 100644 --- a/db/init/oracle/schema.sql +++ b/db/init/oracle/schema.sql @@ -2860,4 +2860,10 @@ INSERT /*+ IGNORE_ROW_ON_DUPKEY_INDEX (permission(id)) */ INTO permission (id, o ALTER TABLE selector ADD namespace_id VARCHAR2(50) NULL; -COMMENT ON COLUMN selector.namespace_id IS 'namespaceId'; \ No newline at end of file +COMMENT ON COLUMN selector.namespace_id IS 'namespaceId'; + +ALTER TABLE rule ADD namespace_id VARCHAR2(50) NULL; +COMMENT ON COLUMN rule.namespace_id IS 'namespaceId'; + +ALTER TABLE meta_data ADD namespace_id VARCHAR2(50) NULL; +COMMENT ON COLUMN meta_data.namespace_id IS 'namespaceId'; \ No newline at end of file diff --git a/db/init/pg/create-table.sql b/db/init/pg/create-table.sql index 576c39c0072a..bae10afbc3a2 100644 --- a/db/init/pg/create-table.sql +++ b/db/init/pg/create-table.sql @@ -2795,4 +2795,7 @@ ALTER TABLE "public"."selector" ADD COLUMN namespace_id VARCHAR(50) NULL; COMMENT ON COLUMN "public"."selector"."namespace_id" IS 'namespaceId'; ALTER TABLE "public"."rule" ADD COLUMN namespace_id VARCHAR(50) NULL; -COMMENT ON COLUMN "public"."rule"."namespace_id" IS 'namespaceId'; \ No newline at end of file +COMMENT ON COLUMN "public"."rule"."namespace_id" IS 'namespaceId'; + +ALTER TABLE "public"."meta_data" ADD COLUMN namespace_id VARCHAR(50) NULL; +COMMENT ON COLUMN "public"."meta_data"."namespace_id" IS 'namespaceId'; \ No newline at end of file diff --git a/db/upgrade/2.6.1-upgrade-2.7.0-mysql.sql b/db/upgrade/2.6.1-upgrade-2.7.0-mysql.sql index a22157689d68..69ddc1e35a0c 100755 --- a/db/upgrade/2.6.1-upgrade-2.7.0-mysql.sql +++ b/db/upgrade/2.6.1-upgrade-2.7.0-mysql.sql @@ -174,11 +174,17 @@ ALTER TABLE `shenyu`.`selector` ADD COLUMN `namespace_id` varchar(50) NULL COMME UPDATE selector SET namespace_id = '649330b6-c2d7-4edc-be8e-8a54df9eb385' -WHERE namespaceId IS NULL; +WHERE namespace_id IS NULL; ALTER TABLE `shenyu`.`rule` ADD COLUMN `namespace_id` varchar(50) NULL COMMENT 'namespaceId' AFTER `match_restful`; UPDATE rule SET namespace_id = '649330b6-c2d7-4edc-be8e-8a54df9eb385' -WHERE namespaceId IS NULL; \ No newline at end of file +WHERE namespace_id IS NULL; + +ALTER TABLE `shenyu`.`meta_data` ADD COLUMN `namespace_id` varchar(50) NULL COMMENT 'namespaceId'; + +UPDATE meta_data +SET namespace_id = '649330b6-c2d7-4edc-be8e-8a54df9eb385' +WHERE namespace_id IS NULL; \ No newline at end of file diff --git a/db/upgrade/2.6.1-upgrade-2.7.0-og.sql b/db/upgrade/2.6.1-upgrade-2.7.0-og.sql index 6ab950d4a0f9..1ae2f669e541 100644 --- a/db/upgrade/2.6.1-upgrade-2.7.0-og.sql +++ b/db/upgrade/2.6.1-upgrade-2.7.0-og.sql @@ -201,4 +201,9 @@ UPDATE "public"."selector" SET namespace_id = '649330b6-c2d7-4edc-be8e-8a54df9eb ALTER TABLE "public"."rule" ADD COLUMN namespace_id VARCHAR(50) NULL; COMMENT ON COLUMN "public"."rule"."namespace_id" IS 'namespaceId'; -UPDATE "public"."rule" SET namespace_id = '649330b6-c2d7-4edc-be8e-8a54df9eb385' WHERE namespace_id IS NULL; \ No newline at end of file +UPDATE "public"."rule" SET namespace_id = '649330b6-c2d7-4edc-be8e-8a54df9eb385' WHERE namespace_id IS NULL; + +ALTER TABLE "public"."meta_data" ADD COLUMN namespace_id VARCHAR(50) NULL; +COMMENT ON COLUMN "public"."meta_data"."namespace_id" IS 'namespaceId'; + +UPDATE "public"."meta_data" SET namespace_id = '649330b6-c2d7-4edc-be8e-8a54df9eb385' WHERE namespace_id IS NULL; \ No newline at end of file diff --git a/db/upgrade/2.6.1-upgrade-2.7.0-oracle.sql b/db/upgrade/2.6.1-upgrade-2.7.0-oracle.sql index 407fe8dbf6d1..b31e9c814730 100755 --- a/db/upgrade/2.6.1-upgrade-2.7.0-oracle.sql +++ b/db/upgrade/2.6.1-upgrade-2.7.0-oracle.sql @@ -227,4 +227,9 @@ UPDATE selector SET namespace_id = '649330b6-c2d7-4edc-be8e-8a54df9eb385' WHERE ALTER TABLE rule ADD namespace_id VARCHAR2(50) NULL; COMMENT ON COLUMN rule.namespace_id IS 'namespaceId'; -UPDATE rule SET namespace_id = '649330b6-c2d7-4edc-be8e-8a54df9eb385' WHERE namespace_id IS NULL; \ No newline at end of file +UPDATE rule SET namespace_id = '649330b6-c2d7-4edc-be8e-8a54df9eb385' WHERE namespace_id IS NULL; + +ALTER TABLE meta_data ADD namespace_id VARCHAR2(50) NULL; +COMMENT ON COLUMN meta_data.namespace_id IS 'namespaceId'; + +UPDATE meta_data SET namespace_id = '649330b6-c2d7-4edc-be8e-8a54df9eb385' WHERE namespace_id IS NULL; \ No newline at end of file diff --git a/db/upgrade/2.6.1-upgrade-2.7.0-pg.sql b/db/upgrade/2.6.1-upgrade-2.7.0-pg.sql index 32fd8894a653..55d068f2b537 100755 --- a/db/upgrade/2.6.1-upgrade-2.7.0-pg.sql +++ b/db/upgrade/2.6.1-upgrade-2.7.0-pg.sql @@ -202,4 +202,9 @@ UPDATE "public"."selector" SET namespace_id = '649330b6-c2d7-4edc-be8e-8a54df9eb ALTER TABLE "public"."rule" ADD COLUMN namespace_id VARCHAR(50) NULL; COMMENT ON COLUMN "public"."rule"."namespace_id" IS 'namespaceId'; -UPDATE "public"."rule" SET namespace_id = '649330b6-c2d7-4edc-be8e-8a54df9eb385' WHERE namespace_id IS NULL; \ No newline at end of file +UPDATE "public"."rule" SET namespace_id = '649330b6-c2d7-4edc-be8e-8a54df9eb385' WHERE namespace_id IS NULL; + +ALTER TABLE "public"."meta_data" ADD COLUMN namespace_id VARCHAR(50) NULL; +COMMENT ON COLUMN "public"."meta_data"."namespace_id" IS 'namespaceId'; + +UPDATE "public"."meta_data" SET namespace_id = '649330b6-c2d7-4edc-be8e-8a54df9eb385' WHERE namespace_id IS NULL; \ No newline at end of file diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/controller/MetaDataController.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/controller/MetaDataController.java index 9ebc5b65dcb3..bd86f002a4b7 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/controller/MetaDataController.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/controller/MetaDataController.java @@ -19,6 +19,7 @@ import org.apache.commons.lang3.StringUtils; import org.apache.shenyu.admin.aspect.annotation.RestApi; +import org.apache.shenyu.admin.mapper.NamespaceMapper; import org.apache.shenyu.admin.model.dto.BatchCommonDTO; import org.apache.shenyu.admin.model.dto.MetaDataDTO; import org.apache.shenyu.admin.model.page.CommonPager; @@ -28,6 +29,7 @@ import org.apache.shenyu.admin.model.vo.MetaDataVO; import org.apache.shenyu.admin.service.MetaDataService; import org.apache.shenyu.admin.utils.ShenyuResultMessage; +import org.apache.shenyu.admin.validation.annotation.Existed; import org.apache.shiro.authz.annotation.Logical; import org.apache.shiro.authz.annotation.RequiresPermissions; import org.springframework.web.bind.annotation.DeleteMapping; @@ -67,8 +69,10 @@ public MetaDataController(final MetaDataService metaDataService) { @RequiresPermissions("system:meta:list") public ShenyuAdminResult queryList(final String path, @RequestParam @NotNull(message = "currentPage not null") final Integer currentPage, - @RequestParam @NotNull(message = "pageSize not null") final Integer pageSize) { - CommonPager commonPager = metaDataService.listByPage(new MetaDataQuery(path, new PageParameter(currentPage, pageSize))); + @RequestParam @NotNull(message = "pageSize not null") final Integer pageSize, + @Valid @Existed(message = "namespaceId is not existed", + provider = NamespaceMapper.class) final String namespaceId) { + CommonPager commonPager = metaDataService.listByPage(new MetaDataQuery(path, new PageParameter(currentPage, pageSize), namespaceId)); return ShenyuAdminResult.success(ShenyuResultMessage.QUERY_SUCCESS, commonPager); } @@ -98,11 +102,14 @@ public ShenyuAdminResult findAllGroup() { * Get detail of metadata. * * @param id the id + * @param namespaceId namespaceId. * @return the shenyu result */ - @GetMapping("/{id}") + @GetMapping("/{id}/{namespaceId}") @RequiresPermissions("system:meta:edit") - public ShenyuAdminResult detail(@PathVariable("id") final String id) { + public ShenyuAdminResult detail(@PathVariable("id") final String id, + @PathVariable("namespaceId") @Valid + @Existed(provider = NamespaceMapper.class, message = "namespaceId is not existed") final String namespaceId) { return ShenyuAdminResult.success(ShenyuResultMessage.DETAIL_SUCCESS, metaDataService.findById(id)); } diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/entity/MetaDataDO.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/entity/MetaDataDO.java index 62ae6c2a1800..2eda83833d79 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/entity/MetaDataDO.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/entity/MetaDataDO.java @@ -49,6 +49,11 @@ public final class MetaDataDO extends BaseDO implements Serializable { */ private Boolean enabled; + /** + * namespaceId. + */ + private String namespaceId; + public MetaDataDO() { } @@ -60,7 +65,8 @@ public MetaDataDO(final String appName, final String methodName, final String parameterTypes, final String rpcExt, - final Boolean enabled) { + final Boolean enabled, + final String namespaceId) { this.appName = appName; this.path = path; this.pathDesc = pathDesc; @@ -70,6 +76,7 @@ public MetaDataDO(final String appName, this.parameterTypes = parameterTypes; this.rpcExt = rpcExt; this.enabled = enabled; + this.namespaceId = namespaceId; } /** @@ -234,6 +241,24 @@ public void setEnabled(final Boolean enabled) { this.enabled = enabled; } + /** + * get namespaceId. + * + * @return namespaceId + */ + public String getNamespaceId() { + return namespaceId; + } + + /** + * set namespaceId. + * + * @param namespaceId namespaceId + */ + public void setNamespaceId(final String namespaceId) { + this.namespaceId = namespaceId; + } + /** * builder method. * @@ -263,12 +288,14 @@ public boolean equals(final Object o) { && Objects.equals(methodName, that.methodName) && Objects.equals(parameterTypes, that.parameterTypes) && Objects.equals(rpcExt, that.rpcExt) - && Objects.equals(enabled, that.enabled); + && Objects.equals(enabled, that.enabled) + && Objects.equals(namespaceId, that.namespaceId); } @Override public int hashCode() { - return Objects.hash(super.hashCode(), appName, path, pathDesc, rpcType, serviceName, methodName, parameterTypes, rpcExt, enabled); + return Objects.hash(super.hashCode(), appName, path, pathDesc, rpcType, serviceName, methodName, parameterTypes, rpcExt, enabled + , namespaceId); } public static final class MetaDataDOBuilder { @@ -297,6 +324,8 @@ public static final class MetaDataDOBuilder { private Boolean enabled; + private String namespaceId; + private MetaDataDOBuilder() { } @@ -432,6 +461,17 @@ public MetaDataDOBuilder enabled(final Boolean enabled) { return this; } + /** + * namespaceId. + * + * @param namespaceId namespaceId + * @return MetaDataDOBuilder + */ + public MetaDataDOBuilder namespaceId(final String namespaceId) { + this.namespaceId = namespaceId; + return this; + } + /** * build method. * @@ -451,6 +491,7 @@ public MetaDataDO build() { metaDataDO.setParameterTypes(parameterTypes); metaDataDO.setRpcExt(rpcExt); metaDataDO.setEnabled(enabled); + metaDataDO.setNamespaceId(namespaceId); return metaDataDO; } } diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/query/MetaDataQuery.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/query/MetaDataQuery.java index 33575562736d..e340a9f5b3d3 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/query/MetaDataQuery.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/query/MetaDataQuery.java @@ -39,12 +39,18 @@ public class MetaDataQuery implements Serializable { */ private PageParameter pageParameter; + /** + * namespace id. + */ + private String namespaceId; + public MetaDataQuery() { } - public MetaDataQuery(final String path, final PageParameter pageParameter) { + public MetaDataQuery(final String path, final PageParameter pageParameter, final String namespaceId) { this.path = path; this.pageParameter = pageParameter; + this.namespaceId = namespaceId; } /** @@ -83,6 +89,24 @@ public void setPageParameter(final PageParameter pageParameter) { this.pageParameter = pageParameter; } + /** + * Gets the value of name. + * + * @return the value of name + */ + public String getNamespaceId() { + return namespaceId; + } + + /** + * Sets the namespaceId. + * + * @param namespaceId namespaceId + */ + public void setNamespaceId(final String namespaceId) { + this.namespaceId = namespaceId; + } + @Override public boolean equals(final Object o) { if (this == o) { @@ -92,11 +116,12 @@ public boolean equals(final Object o) { return false; } MetaDataQuery that = (MetaDataQuery) o; - return Objects.equals(path, that.path) && Objects.equals(pageParameter, that.pageParameter); + return Objects.equals(path, that.path) && Objects.equals(pageParameter, that.pageParameter) + && Objects.equals(namespaceId, that.namespaceId); } @Override public int hashCode() { - return Objects.hash(path, pageParameter); + return Objects.hash(path, pageParameter, namespaceId); } } diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/vo/MetaDataVO.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/vo/MetaDataVO.java index 5bfd6b476e95..d28fe9177717 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/vo/MetaDataVO.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/vo/MetaDataVO.java @@ -60,6 +60,11 @@ public class MetaDataVO implements Serializable { private Boolean enabled; + /** + * namespaceId. + */ + private String namespaceId; + public MetaDataVO() { } @@ -74,7 +79,8 @@ public MetaDataVO(final String appName, final String id, final String dateCreated, final String dateUpdated, - final Boolean enabled) { + final Boolean enabled, + final String namespaceId) { this.appName = appName; this.path = path; this.pathDesc = pathDesc; @@ -87,6 +93,7 @@ public MetaDataVO(final String appName, this.dateCreated = dateCreated; this.dateUpdated = dateUpdated; this.enabled = enabled; + this.namespaceId = namespaceId; } /** @@ -305,6 +312,24 @@ public void setEnabled(final Boolean enabled) { this.enabled = enabled; } + /** + * 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; + } + @Override public boolean equals(final Object o) { if (this == o) { @@ -325,12 +350,13 @@ public boolean equals(final Object o) { && Objects.equals(id, that.id) && Objects.equals(dateCreated, that.dateCreated) && Objects.equals(dateUpdated, that.dateUpdated) - && Objects.equals(enabled, that.enabled); + && Objects.equals(enabled, that.enabled) + && Objects.equals(namespaceId, that.namespaceId); } @Override public int hashCode() { - return Objects.hash(appName, path, pathDesc, rpcType, serviceName, methodName, parameterTypes, rpcExt, id, dateCreated, dateUpdated, enabled); + return Objects.hash(appName, path, pathDesc, rpcType, serviceName, methodName, parameterTypes, rpcExt, id, dateCreated, dateUpdated, enabled, namespaceId); } @Override @@ -347,7 +373,8 @@ public String toString() { + ", id='" + id + '\'' + ", dateCreated='" + dateCreated + '\'' + ", dateUpdated='" + dateUpdated + '\'' - + ", enabled=" + enabled + + ", enabled=" + enabled+ '\'' + + ", namespaceId=" + namespaceId + '}'; } } diff --git a/shenyu-admin/src/main/resources/mappers/meta-data-sqlmap.xml b/shenyu-admin/src/main/resources/mappers/meta-data-sqlmap.xml index 3dc70c3fea74..7691a57221d8 100644 --- a/shenyu-admin/src/main/resources/mappers/meta-data-sqlmap.xml +++ b/shenyu-admin/src/main/resources/mappers/meta-data-sqlmap.xml @@ -34,13 +34,13 @@ - id, - date_created, - date_updated, - app_name, + id, + date_created, + date_updated, + app_name, path, path_desc, - rpc_type, + rpc_type, service_name, method_name, parameter_types, @@ -50,164 +50,172 @@ - SElECT - - FROM meta_data - - - WHERE path LIKE #{pathLike,jdbcType=VARCHAR} - + + FROM meta_data + + + + path LIKE #{pathLike,jdbcType=VARCHAR} + + + AND namespace_id = #{condition.namespaceId, jdbcType=VARCHAR} + + - SElECT COUNT(1) - FROM meta_data - - WHERE path = #{path,jdbcType=VARCHAR} - + FROM meta_data + + WHERE path = #{path,jdbcType=VARCHAR} + - INSERT INTO meta_data - (id, - date_created, - date_updated, - app_name, - path, - path_desc, - rpc_type, - service_name, - method_name, - parameter_types, - rpc_ext, - enabled) - VALUES - (#{id,jdbcType=VARCHAR}, - #{dateCreated,jdbcType=TIMESTAMP}, - #{dateUpdated,jdbcType=TIMESTAMP}, - #{appName,jdbcType=VARCHAR}, - #{path,jdbcType=VARCHAR}, - #{pathDesc,jdbcType=VARCHAR}, - #{rpcType,jdbcType=VARCHAR}, - #{serviceName,jdbcType=VARCHAR}, - #{methodName,jdbcType=VARCHAR}, - #{parameterTypes,jdbcType=VARCHAR}, - #{rpcExt,jdbcType=VARCHAR}, - #{enabled,jdbcType=TINYINT}) + INSERT INTO meta_data + (id, + date_created, + date_updated, + app_name, + path, + path_desc, + rpc_type, + service_name, + method_name, + parameter_types, + rpc_ext, + enabled) + VALUES + (#{id,jdbcType=VARCHAR}, + #{dateCreated,jdbcType=TIMESTAMP}, + #{dateUpdated,jdbcType=TIMESTAMP}, + #{appName,jdbcType=VARCHAR}, + #{path,jdbcType=VARCHAR}, + #{pathDesc,jdbcType=VARCHAR}, + #{rpcType,jdbcType=VARCHAR}, + #{serviceName,jdbcType=VARCHAR}, + #{methodName,jdbcType=VARCHAR}, + #{parameterTypes,jdbcType=VARCHAR}, + #{rpcExt,jdbcType=VARCHAR}, + #{enabled,jdbcType=TINYINT}) UPDATE meta_data - SET - app_name = #{appName,jdbcType=VARCHAR}, - path = #{path,jdbcType=VARCHAR}, - path_desc = #{pathDesc,jdbcType=VARCHAR}, - rpc_type = #{rpcType,jdbcType=VARCHAR}, - service_name = #{serviceName,jdbcType=VARCHAR}, - method_name = #{methodName,jdbcType=VARCHAR}, - parameter_types = #{parameterTypes,jdbcType=VARCHAR}, - rpc_ext= #{rpcExt,jdbcType=VARCHAR} - WHERE id = #{id,jdbcType=VARCHAR} + SET + app_name = #{appName,jdbcType=VARCHAR}, + path = #{path,jdbcType=VARCHAR}, + path_desc = #{pathDesc,jdbcType=VARCHAR}, + rpc_type = #{rpcType,jdbcType=VARCHAR}, + service_name = #{serviceName,jdbcType=VARCHAR}, + method_name = #{methodName,jdbcType=VARCHAR}, + parameter_types = #{parameterTypes,jdbcType=VARCHAR}, + rpc_ext= #{rpcExt,jdbcType=VARCHAR} + WHERE id = #{id,jdbcType=VARCHAR} UPDATE meta_data - SET enabled = #{enabled,jdbcType=TINYINT} - WHERE id = #{id,jdbcType=VARCHAR} + SET enabled = #{enabled,jdbcType=TINYINT} + WHERE id = #{id,jdbcType=VARCHAR} UPDATE meta_data - SET enabled = #{enabled,jdbcType=TINYINT} - WHERE id IN - - #{id, jdbcType=VARCHAR} - + SET enabled = #{enabled,jdbcType=TINYINT} + WHERE id IN + + #{id, jdbcType=VARCHAR} + DELETE FROM meta_data - WHERE id = #{id,jdbcType=VARCHAR} + WHERE id = #{id,jdbcType=VARCHAR} DELETE FROM meta_data - WHERE id - IN - #{id,jdbcType=VARCHAR} - + WHERE id + IN + + #{id,jdbcType=VARCHAR} + diff --git a/shenyu-admin/src/main/resources/sql-script/h2/schema.sql b/shenyu-admin/src/main/resources/sql-script/h2/schema.sql index 755d205cec31..41c0d8bf729a 100755 --- a/shenyu-admin/src/main/resources/sql-script/h2/schema.sql +++ b/shenyu-admin/src/main/resources/sql-script/h2/schema.sql @@ -1344,4 +1344,6 @@ INSERT IGNORE INTO `permission` (`id`, `object_id`, `resource_id`, `date_created ALTER TABLE `selector` ADD COLUMN `namespace_id` varchar(50) NULL COMMENT 'namespaceId' AFTER `match_restful`; -ALTER TABLE `rule` ADD COLUMN `namespace_id` varchar(50) NULL COMMENT 'namespaceId' AFTER `match_restful`; \ No newline at end of file +ALTER TABLE `rule` ADD COLUMN `namespace_id` varchar(50) NULL COMMENT 'namespaceId' AFTER `match_restful`; + +ALTER TABLE `meta_data` ADD COLUMN `namespace_id` varchar(50) NULL COMMENT 'namespaceId' AFTER `match_restful`; \ No newline at end of file diff --git a/shenyu-admin/src/test/java/org/apache/shenyu/admin/controller/MetaDataControllerTest.java b/shenyu-admin/src/test/java/org/apache/shenyu/admin/controller/MetaDataControllerTest.java index a4627e3a5789..b0750bfac8f6 100644 --- a/shenyu-admin/src/test/java/org/apache/shenyu/admin/controller/MetaDataControllerTest.java +++ b/shenyu-admin/src/test/java/org/apache/shenyu/admin/controller/MetaDataControllerTest.java @@ -53,6 +53,7 @@ import java.util.List; import java.util.Map; +import static org.apache.shenyu.common.constant.AdminConstants.SYS_DEFAULT_NAMESPACE_ID; import static org.hamcrest.core.Is.is; import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.mock; @@ -80,7 +81,7 @@ public final class MetaDataControllerTest { private final MetaDataVO metaDataVO = new MetaDataVO("appName", "appPath", "desc", "rpcType", "serviceName", "methodName", "types", "rpcExt", "1", DateUtils.localDateTimeToString(LocalDateTime.now()), DateUtils.localDateTimeToString(LocalDateTime.now()), - true); + true, SYS_DEFAULT_NAMESPACE_ID); @BeforeEach public void setUp() { @@ -97,7 +98,7 @@ public void testQueryList() throws Exception { final CommonPager commonPager = new CommonPager<>(); commonPager.setPage(pageParameter); commonPager.setDataList(metaDataVOS); - final MetaDataQuery metaDataQuery = new MetaDataQuery("path", pageParameter); + final MetaDataQuery metaDataQuery = new MetaDataQuery("path", pageParameter, SYS_DEFAULT_NAMESPACE_ID); given(this.metaDataService.listByPage(metaDataQuery)).willReturn(commonPager); this.mockMvc.perform(MockMvcRequestBuilders.get("/meta-data/queryList") .param("path", "path") From 3774e143205ed36b8014bafe72a9b6374c0edaaa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=98xcsnx=E2=80=99?= <‘1192709687@qq.com’> Date: Sat, 17 Aug 2024 22:54:03 +0800 Subject: [PATCH 43/61] commit --- .../admin/controller/MetaDataController.java | 23 ++++-------- .../shenyu/admin/mapper/MetaDataMapper.java | 13 +++---- .../shenyu/admin/model/dto/MetaDataDTO.java | 26 ++++++++++++++ .../event/metadata/MetaDataChangedEvent.java | 4 +-- .../shenyu/admin/service/MetaDataService.java | 12 +++---- .../admin/service/impl/ApiServiceImpl.java | 5 +-- .../service/impl/MetaDataServiceImpl.java | 28 +++++++-------- ...ShenyuClientRegisterDivideServiceImpl.java | 2 +- .../ShenyuClientRegisterDubboServiceImpl.java | 2 +- .../ShenyuClientRegisterGrpcServiceImpl.java | 2 +- .../ShenyuClientRegisterMotanServiceImpl.java | 2 +- .../ShenyuClientRegisterSofaServiceImpl.java | 2 +- ...uClientRegisterSpringCloudServiceImpl.java | 2 +- .../ShenyuClientRegisterTarsServiceImpl.java | 2 +- ...nyuClientRegisterWebSocketServiceImpl.java | 2 +- .../admin/transfer/MetaDataTransfer.java | 2 ++ .../resources/mappers/meta-data-sqlmap.xml | 14 ++++++-- .../admin/mapper/MetaDataMapperTest.java | 18 +++++----- .../admin/service/MetaDataServiceTest.java | 35 ++++++++++--------- ...enyuClientRegisterSofaServiceImplTest.java | 2 +- ...enyuClientRegisterTarsServiceImplTest.java | 5 +-- 21 files changed, 116 insertions(+), 87 deletions(-) diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/controller/MetaDataController.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/controller/MetaDataController.java index bd86f002a4b7..0eee7f503eb1 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/controller/MetaDataController.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/controller/MetaDataController.java @@ -21,6 +21,7 @@ import org.apache.shenyu.admin.aspect.annotation.RestApi; import org.apache.shenyu.admin.mapper.NamespaceMapper; import org.apache.shenyu.admin.model.dto.BatchCommonDTO; +import org.apache.shenyu.admin.model.dto.BatchNamespaceCommonDTO; import org.apache.shenyu.admin.model.dto.MetaDataDTO; import org.apache.shenyu.admin.model.page.CommonPager; import org.apache.shenyu.admin.model.page.PageParameter; @@ -110,7 +111,7 @@ public ShenyuAdminResult findAllGroup() { public ShenyuAdminResult detail(@PathVariable("id") final String id, @PathVariable("namespaceId") @Valid @Existed(provider = NamespaceMapper.class, message = "namespaceId is not existed") final String namespaceId) { - return ShenyuAdminResult.success(ShenyuResultMessage.DETAIL_SUCCESS, metaDataService.findById(id)); + return ShenyuAdminResult.success(ShenyuResultMessage.DETAIL_SUCCESS, metaDataService.findById(id, namespaceId)); } /** @@ -125,19 +126,6 @@ public ShenyuAdminResult createOrUpdate(@Valid @RequestBody final MetaDataDTO me return ShenyuAdminResult.success(metaDataService.createOrUpdate(metaDataDTO)); } - /** - * Batch deleted metadata. - * - * @param ids the ids - * @return the shenyu result - */ - @PostMapping("/batchDeleted") - @RequiresPermissions("system:meta:delete") - public ShenyuAdminResult batchDeleted(@RequestBody @NotEmpty final List<@NotBlank String> ids) { - Integer deleteCount = metaDataService.delete(ids); - return ShenyuAdminResult.success(ShenyuResultMessage.DELETE_SUCCESS, deleteCount); - } - /** * Batch deleted metadata. * @@ -146,8 +134,9 @@ public ShenyuAdminResult batchDeleted(@RequestBody @NotEmpty final List<@NotBlan */ @DeleteMapping("/batchDeleted") @RequiresPermissions("system:meta:delete") - public ShenyuAdminResult batchDelete(@RequestBody @NotEmpty final List<@NotBlank String> ids) { - return batchDeleted(ids); + public ShenyuAdminResult batchDeleted(@Valid @RequestBody final BatchNamespaceCommonDTO batchNamespaceCommonDTO) { + Integer deleteCount = metaDataService.delete(batchNamespaceCommonDTO.getIds(), batchNamespaceCommonDTO.getNamespaceId()); + return ShenyuAdminResult.success(ShenyuResultMessage.DELETE_SUCCESS, deleteCount); } /** @@ -159,7 +148,7 @@ public ShenyuAdminResult batchDelete(@RequestBody @NotEmpty final List<@NotBlank @PostMapping("/batchEnabled") @RequiresPermissions("system:meta:disable") public ShenyuAdminResult batchEnabled(@Valid @RequestBody final BatchCommonDTO batchCommonDTO) { - final String result = metaDataService.enabled(batchCommonDTO.getIds(), batchCommonDTO.getEnabled()); + final String result = metaDataService.enabled(batchCommonDTO.getIds(), batchCommonDTO.getEnabled(), batchCommonDTO.getNamespaceId()); if (StringUtils.isNoneBlank(result)) { return ShenyuAdminResult.error(result); } diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/MetaDataMapper.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/MetaDataMapper.java index 6320e0619f53..db90d8a6e8f0 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/MetaDataMapper.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/MetaDataMapper.java @@ -42,12 +42,13 @@ public interface MetaDataMapper extends ExistProvider { Boolean existed(@Param("id") Serializable id); /** - * Select by id meta data do. + * Select meta data do by id and namespaceId. * * @param id the id + * @param namespaceId namespaceId. * @return the meta data do */ - MetaDataDO selectById(String id); + MetaDataDO selectById(String id, String namespaceId); /** * Select a list of MetaDataDOs by idList. @@ -55,7 +56,7 @@ public interface MetaDataMapper extends ExistProvider { * @param idList a list of ids * @return a list of MetaDataDOs */ - List selectByIdList(@Param("idList") List idList); + List selectByIdList(@Param("idList") List idList, @Param("namespaceId") String namespaceId); /** * Find all list. @@ -70,7 +71,7 @@ public interface MetaDataMapper extends ExistProvider { * @param path the path * @return the meta data do */ - MetaDataDO findByPath(String path); + MetaDataDO findByPath(String path, String namespaceId); /** * Find by service name and method meta data do. @@ -79,7 +80,7 @@ public interface MetaDataMapper extends ExistProvider { * @param methodName the methodName * @return the meta data do */ - List findByServiceNameAndMethod(@Param("serviceName") String serviceName, @Param("methodName") String methodName); + List findByServiceNameAndMethod(@Param("serviceName") String serviceName, @Param("methodName") String methodName, @Param("namespaceId") String namespaceId); /** * Select by query list. @@ -151,7 +152,7 @@ public interface MetaDataMapper extends ExistProvider { * @param idList a list of ids * @return the count of deleted */ - int deleteByIdList(@Param("idList") List idList); + int deleteByIdList(@Param("idList") List idList, @Param("namespaceId") String namespaceId); /** * the path is existed. diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/dto/MetaDataDTO.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/dto/MetaDataDTO.java index 764958a641dc..a85a3fbbebe7 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/dto/MetaDataDTO.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/dto/MetaDataDTO.java @@ -18,6 +18,7 @@ package org.apache.shenyu.admin.model.dto; import org.apache.shenyu.admin.mapper.MetaDataMapper; +import org.apache.shenyu.admin.mapper.NamespaceMapper; import org.apache.shenyu.admin.validation.annotation.Existed; import jakarta.validation.constraints.NotBlank; @@ -92,6 +93,13 @@ public class MetaDataDTO implements Serializable { */ @NotNull private Boolean enabled; + + /** + * namespaceId. + */ + @NotBlank + @Existed(message = "namespaceId is not existed", provider = NamespaceMapper.class) + private String namespaceId; /** * Gets the value of id. @@ -308,6 +316,24 @@ public Boolean getEnabled() { public void setEnabled(final Boolean enabled) { this.enabled = enabled; } + + /** + * get namespaceId. + * + * @return namespaceId + */ + public String getNamespaceId() { + return namespaceId; + } + + /** + * set namespaceId. + * + * @param namespaceId namespaceId + */ + public void setNamespaceId(final String namespaceId) { + this.namespaceId = namespaceId; + } @Override public boolean equals(final Object o) { diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/event/metadata/MetaDataChangedEvent.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/event/metadata/MetaDataChangedEvent.java index 83383b5c5a76..44e303ba5156 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/event/metadata/MetaDataChangedEvent.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/event/metadata/MetaDataChangedEvent.java @@ -46,9 +46,9 @@ public MetaDataChangedEvent(final MetaDataDO source, final MetaDataDO before, fi public String buildContext() { final MetaDataDO after = (MetaDataDO) getAfter(); if (Objects.isNull(getBefore())) { - return String.format("the metadata [%s %s] is %s", after.getAppName(), after.getPath(), StringUtils.lowerCase(getType().getType().toString())); + return String.format("the namespace [%s] metadata [%s %s] is %s", after.getNamespaceId(), after.getAppName(), after.getPath(), StringUtils.lowerCase(getType().getType().toString())); } - return String.format("the metadata [%s %s] is %s : %s", after.getAppName(), after.getPath(), StringUtils.lowerCase(getType().getType().toString()), contrast()); + return String.format("the namespace [%s] metadata [%s %s] is %s : %s", after.getNamespaceId(), after.getAppName(), after.getPath(), StringUtils.lowerCase(getType().getType().toString()), contrast()); } diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/MetaDataService.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/MetaDataService.java index ffe47cbe3d06..dbfa20aae4a0 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/MetaDataService.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/MetaDataService.java @@ -57,7 +57,7 @@ public interface MetaDataService { * @param ids primary key. * @return rows int */ - int delete(List ids); + int delete(List ids, String namespaceId); /** * Find by id meta data vo. @@ -65,7 +65,7 @@ public interface MetaDataService { * @param id the id * @return the meta data vo */ - MetaDataVO findById(String id); + MetaDataVO findById(String id, String namespaceId); /** * List by page common pager. @@ -107,10 +107,10 @@ public interface MetaDataService { * Enabled string. * * @param ids the ids - * @param enabled the enable + * @param enabled the enabled * @return the string */ - String enabled(List ids, Boolean enabled); + String enabled(List ids, Boolean enabled, String namespaceId); /** * Sync data. @@ -123,7 +123,7 @@ public interface MetaDataService { * @param path the path of meta data * @return {@link MetaDataDO} */ - MetaDataDO findByPath(String path); + MetaDataDO findByPath(String path,String namespaceId); /** * find meta data by service's name and method's name. @@ -132,7 +132,7 @@ public interface MetaDataService { * @param methodName the name of method * @return {@link MetaDataDO} */ - MetaDataDO findByServiceNameAndMethodName(String serviceName, String methodName); + MetaDataDO findByServiceNameAndMethodName(String serviceName, String methodName, String namespaceId); /** * insert MetaDataDO. diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/ApiServiceImpl.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/ApiServiceImpl.java index 7041dcbd6caa..621684495849 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/ApiServiceImpl.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/ApiServiceImpl.java @@ -189,11 +189,12 @@ private void removeRegister(final ApiDO apiDO) { } }); if (CollectionUtils.isNotEmpty(selectorIds)) { + // todo:[To be refactored with namespace] Temporarily hardcode selectorService.deleteByNamespaceId(selectorIds, SYS_DEFAULT_NAMESPACE_ID); } //clean metadata - Optional.ofNullable(metaDataService.findByPath(path)) - .ifPresent(metaDataDO -> metaDataService.delete(Lists.newArrayList(metaDataDO.getId()))); + Optional.ofNullable(metaDataService.findByPath(path, SYS_DEFAULT_NAMESPACE_ID)) + .ifPresent(metaDataDO -> metaDataService.delete(Lists.newArrayList(metaDataDO.getId()), SYS_DEFAULT_NAMESPACE_ID)); } private void register(final ApiDO apiDO) { diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/MetaDataServiceImpl.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/MetaDataServiceImpl.java index 926919e21586..ad8eb8bfabae 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/MetaDataServiceImpl.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/MetaDataServiceImpl.java @@ -107,12 +107,12 @@ public String createOrUpdate(final MetaDataDTO metaDataDTO) { } @Override - public int delete(final List ids) { - List deletedMetaData = metaDataMapper.selectByIdList(ids); + public int delete(final List ids, final String namespaceId) { + List deletedMetaData = metaDataMapper.selectByIdList(ids, namespaceId); if (CollectionUtils.isEmpty(deletedMetaData)) { return 0; } - int count = metaDataMapper.deleteByIdList(ids); + int count = metaDataMapper.deleteByIdList(ids, namespaceId); if (count > 0) { publisher.onDeleted(deletedMetaData); } @@ -120,8 +120,8 @@ public int delete(final List ids) { } @Override - public String enabled(final List ids, final Boolean enabled) { - List metaDataDoList = metaDataMapper.selectByIdList(ids); + public String enabled(final List ids, final Boolean enabled, final String namespaceId) { + List metaDataDoList = metaDataMapper.selectByIdList(ids, namespaceId); if (CollectionUtils.isEmpty(metaDataDoList)) { return AdminConstants.ID_NOT_EXIST; } @@ -143,8 +143,8 @@ public void syncData() { } @Override - public MetaDataVO findById(final String id) { - return Optional.ofNullable(MetaDataTransfer.INSTANCE.mapToVO(metaDataMapper.selectById(id))).orElseGet(MetaDataVO::new); + public MetaDataVO findById(final String id, final String namespaceId) { + return Optional.ofNullable(MetaDataTransfer.INSTANCE.mapToVO(metaDataMapper.selectById(id, namespaceId))).orElseGet(MetaDataVO::new); } @Override @@ -177,13 +177,13 @@ public List listAllData() { } @Override - public MetaDataDO findByPath(final String path) { - return metaDataMapper.findByPath(path); + public MetaDataDO findByPath(final String path, final String namespaceId) { + return metaDataMapper.findByPath(path, namespaceId); } @Override - public MetaDataDO findByServiceNameAndMethodName(final String serviceName, final String methodName) { - final List metadataList = metaDataMapper.findByServiceNameAndMethod(serviceName, methodName); + public MetaDataDO findByServiceNameAndMethodName(final String serviceName, final String methodName, final String namespaceId) { + final List metadataList = metaDataMapper.findByServiceNameAndMethod(serviceName, methodName, namespaceId); return CollectionUtils.isEmpty(metadataList) ? null : metadataList.get(0); } @@ -248,15 +248,15 @@ private String create(final MetaDataDTO metaDataDTO) { private String update(final MetaDataDTO metaDataDTO) { Assert.isNull(metaDataMapper.pathExistedExclude(metaDataDTO.getPath(), Collections.singletonList(metaDataDTO.getId())), AdminConstants.DATA_PATH_IS_EXIST); MetaDataDO metaDataDO = MetaDataTransfer.INSTANCE.mapToEntity(metaDataDTO); - Optional.ofNullable(metaDataMapper.selectById(metaDataDTO.getId())) + Optional.ofNullable(metaDataMapper.selectById(metaDataDTO.getId(), metaDataDTO.getNamespaceId())) .ifPresent(e -> metaDataDTO.setEnabled(e.getEnabled())); metaDataDO.setPathDesc(Optional.ofNullable(metaDataDO.getPathDesc()).orElse("")); - final MetaDataDO before = metaDataMapper.selectById(metaDataDO.getId()); + final MetaDataDO before = metaDataMapper.selectById(metaDataDO.getId(), metaDataDTO.getNamespaceId()); if (metaDataMapper.update(metaDataDO) > 0) { publisher.onUpdated(metaDataDO, before); // update other rpc_ext for the same service final List befores = Optional.ofNullable(metaDataMapper.findByServiceNameAndMethod( - metaDataDO.getServiceName(), null)).orElseGet(LinkedList::new); + metaDataDO.getServiceName(), null, metaDataDO.getNamespaceId())).orElseGet(LinkedList::new); for (MetaDataDO b : befores) { MetaDataDO update = MetaDataTransfer.INSTANCE.copy(b); update.setRpcExt(metaDataDTO.getRpcExt()); diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterDivideServiceImpl.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterDivideServiceImpl.java index 839733851a7a..8b39480ae164 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterDivideServiceImpl.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterDivideServiceImpl.java @@ -78,7 +78,7 @@ protected String ruleHandler() { protected void registerMetadata(final MetaDataRegisterDTO dto) { if (dto.isRegisterMetaData()) { MetaDataService metaDataService = getMetaDataService(); - MetaDataDO exist = metaDataService.findByPath(dto.getPath()); + MetaDataDO exist = metaDataService.findByPath(dto.getPath(), dto.getNamespaceId()); metaDataService.saveOrUpdateMetaData(exist, dto); } } diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterDubboServiceImpl.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterDubboServiceImpl.java index 313d50c56f7f..b59a90f83d52 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterDubboServiceImpl.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterDubboServiceImpl.java @@ -64,7 +64,7 @@ protected String ruleHandler() { @Override protected void registerMetadata(final MetaDataRegisterDTO metaDataDTO) { MetaDataService metaDataService = getMetaDataService(); - MetaDataDO exist = metaDataService.findByPath(metaDataDTO.getPath()); + MetaDataDO exist = metaDataService.findByPath(metaDataDTO.getPath(), metaDataDTO.getNamespaceId()); metaDataService.saveOrUpdateMetaData(exist, metaDataDTO); } diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterGrpcServiceImpl.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterGrpcServiceImpl.java index eaf5f18513c9..612d14a4e2e1 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterGrpcServiceImpl.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterGrpcServiceImpl.java @@ -75,7 +75,7 @@ protected String ruleHandler() { @Override protected void registerMetadata(final MetaDataRegisterDTO metaDataDTO) { MetaDataService metaDataService = getMetaDataService(); - MetaDataDO exist = metaDataService.findByPath(metaDataDTO.getPath()); + MetaDataDO exist = metaDataService.findByPath(metaDataDTO.getPath(), metaDataDTO.getNamespaceId()); metaDataService.saveOrUpdateMetaData(exist, metaDataDTO); } diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterMotanServiceImpl.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterMotanServiceImpl.java index f8f7c0191fb5..b8b5fa74f228 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterMotanServiceImpl.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterMotanServiceImpl.java @@ -51,7 +51,7 @@ protected String ruleHandler() { @Override protected void registerMetadata(final MetaDataRegisterDTO metaDataDTO) { MetaDataService metaDataService = getMetaDataService(); - MetaDataDO exist = metaDataService.findByPath(metaDataDTO.getPath()); + MetaDataDO exist = metaDataService.findByPath(metaDataDTO.getPath(), metaDataDTO.getNamespaceId()); metaDataService.saveOrUpdateMetaData(exist, metaDataDTO); } diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterSofaServiceImpl.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterSofaServiceImpl.java index d53a2156350c..d685f6a17a81 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterSofaServiceImpl.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterSofaServiceImpl.java @@ -52,7 +52,7 @@ protected String ruleHandler() { @Override protected void registerMetadata(final MetaDataRegisterDTO metaDataDTO) { MetaDataService metaDataService = getMetaDataService(); - MetaDataDO exist = metaDataService.findByServiceNameAndMethodName(metaDataDTO.getServiceName(), metaDataDTO.getMethodName()); + MetaDataDO exist = metaDataService.findByServiceNameAndMethodName(metaDataDTO.getServiceName(), metaDataDTO.getMethodName(), metaDataDTO.getNamespaceId()); metaDataService.saveOrUpdateMetaData(exist, metaDataDTO); } diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterSpringCloudServiceImpl.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterSpringCloudServiceImpl.java index cb3ff9c922b7..b3ccd3a04f2a 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterSpringCloudServiceImpl.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterSpringCloudServiceImpl.java @@ -65,7 +65,7 @@ protected String ruleHandler() { @Override protected void registerMetadata(final MetaDataRegisterDTO metaDataDTO) { MetaDataService metaDataService = getMetaDataService(); - MetaDataDO metaDataDO = metaDataService.findByPath(metaDataDTO.getPath()); + MetaDataDO metaDataDO = metaDataService.findByPath(metaDataDTO.getPath(), metaDataDTO.getNamespaceId()); metaDataService.saveOrUpdateMetaData(metaDataDO, metaDataDTO); } diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterTarsServiceImpl.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterTarsServiceImpl.java index 69427a13832a..c8afe4d869e2 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterTarsServiceImpl.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterTarsServiceImpl.java @@ -63,7 +63,7 @@ protected String ruleHandler() { @Override protected void registerMetadata(final MetaDataRegisterDTO metaDataDTO) { MetaDataService metaDataService = getMetaDataService(); - MetaDataDO exist = metaDataService.findByServiceNameAndMethodName(metaDataDTO.getServiceName(), metaDataDTO.getMethodName()); + MetaDataDO exist = metaDataService.findByServiceNameAndMethodName(metaDataDTO.getServiceName(), metaDataDTO.getMethodName(), metaDataDTO.getNamespaceId()); metaDataService.saveOrUpdateMetaData(exist, metaDataDTO); } diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterWebSocketServiceImpl.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterWebSocketServiceImpl.java index 8c8ee8593d1e..c55236e95f24 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterWebSocketServiceImpl.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterWebSocketServiceImpl.java @@ -71,7 +71,7 @@ protected String ruleHandler() { protected void registerMetadata(final MetaDataRegisterDTO dto) { if (dto.isRegisterMetaData()) { MetaDataService metaDataService = getMetaDataService(); - MetaDataDO exist = metaDataService.findByPath(dto.getPath()); + MetaDataDO exist = metaDataService.findByPath(dto.getPath(), dto.getNamespaceId()); metaDataService.saveOrUpdateMetaData(exist, dto); } } diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/transfer/MetaDataTransfer.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/transfer/MetaDataTransfer.java index 305c4ec5b650..6f8dbaaaadef 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/transfer/MetaDataTransfer.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/transfer/MetaDataTransfer.java @@ -57,6 +57,7 @@ public MetaDataDO mapToEntity(final MetaDataDTO metaDataDTO) { .parameterTypes(dto.getParameterTypes()) .rpcExt(dto.getRpcExt()) .enabled(dto.getEnabled()) + .namespaceId(metaDataDTO.getNamespaceId()) .build()) .orElse(null); } @@ -79,6 +80,7 @@ public MetaDataDO mapRegisterDTOToEntity(final MetaDataRegisterDTO metaDataDTO) .parameterTypes(dto.getParameterTypes()) .rpcExt(dto.getRpcExt()) .enabled(dto.isEnabled()) + .namespaceId(dto.getNamespaceId()) .build()) .orElse(null); } diff --git a/shenyu-admin/src/main/resources/mappers/meta-data-sqlmap.xml b/shenyu-admin/src/main/resources/mappers/meta-data-sqlmap.xml index 7691a57221d8..6622530625ca 100644 --- a/shenyu-admin/src/main/resources/mappers/meta-data-sqlmap.xml +++ b/shenyu-admin/src/main/resources/mappers/meta-data-sqlmap.xml @@ -53,6 +53,7 @@ FROM meta_data WHERE id = #{id,jdbcType=VARCHAR} + AND namespace_id = #{namespaceId, jdbcType=VARCHAR} @@ -101,7 +105,7 @@ path LIKE #{pathLike,jdbcType=VARCHAR} - AND namespace_id = #{condition.namespaceId, jdbcType=VARCHAR} + AND namespace_id = #{namespaceId, jdbcType=VARCHAR} @@ -159,7 +163,8 @@ method_name, parameter_types, rpc_ext, - enabled) + enabled, + namespace_id) VALUES (#{id,jdbcType=VARCHAR}, #{dateCreated,jdbcType=TIMESTAMP}, @@ -172,7 +177,8 @@ #{methodName,jdbcType=VARCHAR}, #{parameterTypes,jdbcType=VARCHAR}, #{rpcExt,jdbcType=VARCHAR}, - #{enabled,jdbcType=TINYINT}) + #{enabled,jdbcType=TINYINT}, + #{namespaceId,jdbcType=TINYINT}) @@ -188,6 +194,7 @@ parameter_types = #{parameterTypes,jdbcType=VARCHAR}, rpc_ext= #{rpcExt,jdbcType=VARCHAR} WHERE id = #{id,jdbcType=VARCHAR} + AND namespace_id = #{namespaceId, jdbcType=VARCHAR} @@ -217,5 +224,6 @@ #{id,jdbcType=VARCHAR} + AND namespace_id = #{namespaceId, jdbcType=VARCHAR} diff --git a/shenyu-admin/src/test/java/org/apache/shenyu/admin/mapper/MetaDataMapperTest.java b/shenyu-admin/src/test/java/org/apache/shenyu/admin/mapper/MetaDataMapperTest.java index a0d6aecfa670..2a65c042cb86 100644 --- a/shenyu-admin/src/test/java/org/apache/shenyu/admin/mapper/MetaDataMapperTest.java +++ b/shenyu-admin/src/test/java/org/apache/shenyu/admin/mapper/MetaDataMapperTest.java @@ -31,6 +31,7 @@ import java.util.stream.Collectors; import java.util.stream.Stream; +import static org.apache.shenyu.common.constant.AdminConstants.SYS_DEFAULT_NAMESPACE_ID; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.comparesEqualTo; import static org.hamcrest.Matchers.hasItems; @@ -60,9 +61,8 @@ public void selectById() { MetaDataDO metaDataDO = getMetaDataDO(); int count = metaDataMapper.insert(metaDataDO); assertThat(count, comparesEqualTo(1)); - String id = metaDataDO.getId(); - MetaDataDO result = metaDataMapper.selectById(id); + MetaDataDO result = metaDataMapper.selectById(id, SYS_DEFAULT_NAMESPACE_ID); assertThat(result.getId(), comparesEqualTo(id)); } @@ -77,7 +77,7 @@ public void selectByIdSet() { assertThat(count2, comparesEqualTo(1)); List idList = Stream.of(metaDataDO.getId(), metaDataDO2.getId()).collect(Collectors.toList()); - List resultList = metaDataMapper.selectByIdList(idList); + List resultList = metaDataMapper.selectByIdList(idList, SYS_DEFAULT_NAMESPACE_ID); assertThat(resultList, hasItems(metaDataDO2, metaDataDO)); assertThat(resultList.size(), comparesEqualTo(idList.size())); } @@ -99,7 +99,7 @@ public void findByPath() { int count = metaDataMapper.insert(metaDataDO); assertThat(count, comparesEqualTo(1)); - MetaDataDO result = metaDataMapper.findByPath(metaDataDO.getPath()); + MetaDataDO result = metaDataMapper.findByPath(metaDataDO.getPath(), SYS_DEFAULT_NAMESPACE_ID); assertThat(result.getId(), comparesEqualTo(metaDataDO.getId())); } @@ -109,7 +109,7 @@ public void findByServiceNameAndMethod() { int count = metaDataMapper.insert(metaDataDO); assertThat(count, comparesEqualTo(1)); - MetaDataDO result = metaDataMapper.findByServiceNameAndMethod(metaDataDO.getServiceName(), metaDataDO.getMethodName()).get(0); + MetaDataDO result = metaDataMapper.findByServiceNameAndMethod(metaDataDO.getServiceName(), metaDataDO.getMethodName(), SYS_DEFAULT_NAMESPACE_ID).get(0); assertThat(result.getId(), comparesEqualTo(metaDataDO.getId())); } @@ -176,7 +176,7 @@ public void update() { metaDataDO.setAppName("testAppName_update"); metaDataMapper.update(metaDataDO); - MetaDataDO result = metaDataMapper.selectById(metaDataDO.getId()); + MetaDataDO result = metaDataMapper.selectById(metaDataDO.getId(), SYS_DEFAULT_NAMESPACE_ID); assertThat(result.getAppName(), comparesEqualTo("testAppName_update")); } @@ -189,7 +189,7 @@ public void updateEnable() { metaDataDO.setEnabled(true); metaDataMapper.updateEnable(metaDataDO); - MetaDataDO result = metaDataMapper.selectById(metaDataDO.getId()); + MetaDataDO result = metaDataMapper.selectById(metaDataDO.getId(), SYS_DEFAULT_NAMESPACE_ID); assertTrue(result.getEnabled()); } @@ -207,7 +207,7 @@ public void updateEnableBatch() { int ret = metaDataMapper.updateEnableBatch(idList, true); assertThat(ret, comparesEqualTo(idList.size())); - List resultList = metaDataMapper.selectByIdList(idList); + List resultList = metaDataMapper.selectByIdList(idList, SYS_DEFAULT_NAMESPACE_ID); resultList.forEach(result -> assertTrue(result.getEnabled())); } @@ -232,7 +232,7 @@ public void deleteByIdSet() { assertThat(count2, comparesEqualTo(1)); List idList = Stream.of(metaDataDO.getId(), metaDataDO2.getId()).collect(Collectors.toList()); - int result = metaDataMapper.deleteByIdList(idList); + int result = metaDataMapper.deleteByIdList(idList, SYS_DEFAULT_NAMESPACE_ID); assertThat(result, comparesEqualTo(idList.size())); } diff --git a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/MetaDataServiceTest.java b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/MetaDataServiceTest.java index d599a402c1f0..6e03845e28be 100644 --- a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/MetaDataServiceTest.java +++ b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/MetaDataServiceTest.java @@ -52,6 +52,7 @@ import java.util.List; import java.util.Map; +import static org.apache.shenyu.common.constant.AdminConstants.SYS_DEFAULT_NAMESPACE_ID; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyString; @@ -139,12 +140,12 @@ public void testDelete() { @Test public void testEnabled() { List ids = Lists.newArrayList("id1", "id2", "id3"); - String msg = metaDataService.enabled(ids, true); + String msg = metaDataService.enabled(ids, true, SYS_DEFAULT_NAMESPACE_ID); assertEquals(AdminConstants.ID_NOT_EXIST, msg); - when(metaDataMapper.selectByIdList(ids)) + when(metaDataMapper.selectByIdList(ids, SYS_DEFAULT_NAMESPACE_ID)) .thenReturn(Arrays.asList(MetaDataDO.builder().build(), MetaDataDO.builder().build())) .thenReturn(Arrays.asList(MetaDataDO.builder().build(), MetaDataDO.builder().build(), MetaDataDO.builder().build())); - msg = metaDataService.enabled(ids, false); + msg = metaDataService.enabled(ids, false, SYS_DEFAULT_NAMESPACE_ID); assertEquals(StringUtils.EMPTY, msg); } @@ -170,15 +171,15 @@ public void testSyncDate() { */ @Test public void testFindById() { - when(metaDataMapper.selectById(anyString())).thenReturn(null); - MetaDataVO dataVo = metaDataService.findById(anyString()); + when(metaDataMapper.selectById(anyString(), anyString())).thenReturn(null); + MetaDataVO dataVo = metaDataService.findById(anyString(), anyString()); Assertions.assertEquals(new MetaDataVO(), dataVo); final String appName = "appName"; MetaDataDO metaDataDO = MetaDataDO.builder().build(); metaDataDO.setAppName(appName); - when(metaDataMapper.selectById(anyString())).thenReturn(metaDataDO); - dataVo = metaDataService.findById(anyString()); + when(metaDataMapper.selectById(anyString(), anyString())).thenReturn(metaDataDO); + dataVo = metaDataService.findById(anyString(), anyString()); assertEquals(appName, dataVo.getAppName()); } @@ -267,8 +268,8 @@ public void testFindByPath() { .appName("appName1") .path("path1") .build(); - given(this.metaDataMapper.findByPath(any())).willReturn(metaDataDO1); - MetaDataDO metaDataDO = metaDataService.findByPath("path1"); + given(this.metaDataMapper.findByPath(any(), any())).willReturn(metaDataDO1); + MetaDataDO metaDataDO = metaDataService.findByPath("path1", SYS_DEFAULT_NAMESPACE_ID); assertNotNull(metaDataDO); Assertions.assertEquals(metaDataDO, metaDataDO1); } @@ -282,10 +283,10 @@ public void testFindByServiceNameAndMethodName() { .serviceName("serviceName1") .methodName("method1") .build(); - given(this.metaDataMapper.findByServiceNameAndMethod(any(), any())) + given(this.metaDataMapper.findByServiceNameAndMethod(any(), any(), any())) .willReturn(Collections.singletonList(metaDataDO1)); MetaDataDO metaDataDO = metaDataService - .findByServiceNameAndMethodName("serviceName1", "method1"); + .findByServiceNameAndMethodName("serviceName1", "method1", SYS_DEFAULT_NAMESPACE_ID); assertNotNull(metaDataDO); Assertions.assertEquals(metaDataDO, metaDataDO1); } @@ -333,7 +334,7 @@ private void testCreateOrUpdateForUpdate() { when(metaDataDTO.getId()).thenReturn("id"); when(metaDataDTO.getPath()).thenReturn("path"); when(metaDataMapper.pathExistedExclude("path", Collections.singletonList("id"))).thenReturn(null); - when(metaDataMapper.selectById("id")).thenReturn(metaDataDO); + when(metaDataMapper.selectById("id", SYS_DEFAULT_NAMESPACE_ID)).thenReturn(metaDataDO); when(metaDataMapper.update(any())).thenReturn(1); String msg = metaDataService.createOrUpdate(metaDataDTO); assertEquals(ShenyuResultMessage.UPDATE_SUCCESS, msg); @@ -349,7 +350,7 @@ private void assertEquals(final String expected, final String actual) { */ private void testDeleteForEmptyIds() { List ids = Lists.newArrayList(); - int count = metaDataService.delete(ids); + int count = metaDataService.delete(ids, SYS_DEFAULT_NAMESPACE_ID); Assertions.assertEquals(0, count, "The count of delete should be 0."); } @@ -359,11 +360,11 @@ private void testDeleteForEmptyIds() { */ private void testDeleteForNotEmptyIds() { List ids = Lists.newArrayList("id1", "id3"); - int count = metaDataService.delete(ids); + int count = metaDataService.delete(ids, SYS_DEFAULT_NAMESPACE_ID); Assertions.assertEquals(0, count, "The count of delete should be 0."); - when(metaDataMapper.selectByIdList(ids)).thenReturn(Arrays.asList(MetaDataDO.builder().build(), MetaDataDO.builder().build())); - when(metaDataMapper.deleteByIdList(ids)).thenReturn(2); - count = metaDataService.delete(ids); + when(metaDataMapper.selectByIdList(ids, SYS_DEFAULT_NAMESPACE_ID)).thenReturn(Arrays.asList(MetaDataDO.builder().build(), MetaDataDO.builder().build())); + when(metaDataMapper.deleteByIdList(ids, SYS_DEFAULT_NAMESPACE_ID)).thenReturn(2); + count = metaDataService.delete(ids, SYS_DEFAULT_NAMESPACE_ID); Assertions.assertEquals(2, count, "The count of delete should be 2."); } diff --git a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterSofaServiceImplTest.java b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterSofaServiceImplTest.java index 9cbc6e99107c..b84ce1045d47 100644 --- a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterSofaServiceImplTest.java +++ b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterSofaServiceImplTest.java @@ -74,7 +74,7 @@ public void testRuleHandler() { @Test public void testRegisterMetadata() { MetaDataDO metaDataDO = MetaDataDO.builder().build(); - when(metaDataService.findByServiceNameAndMethodName(any(), any())).thenReturn(metaDataDO); + when(metaDataService.findByServiceNameAndMethodName(any(), any(), any())).thenReturn(metaDataDO); MetaDataRegisterDTO metaDataDTO = MetaDataRegisterDTO.builder().build(); shenyuClientRegisterSofaService.registerMetadata(metaDataDTO); verify(metaDataService).saveOrUpdateMetaData(metaDataDO, metaDataDTO); diff --git a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterTarsServiceImplTest.java b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterTarsServiceImplTest.java index bed13a492b52..2c31c4b7fbde 100644 --- a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterTarsServiceImplTest.java +++ b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterTarsServiceImplTest.java @@ -39,6 +39,7 @@ import java.util.ArrayList; import java.util.List; +import static org.apache.shenyu.common.constant.AdminConstants.SYS_DEFAULT_NAMESPACE_ID; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doReturn; @@ -81,11 +82,11 @@ public void testRegisterMetadata() { MetaDataDO metaDataDO = MetaDataDO.builder().build(); String serviceName = "metaDataService"; String methodName = "registerMetadata"; - when(metaDataService.findByServiceNameAndMethodName(any(), any())).thenReturn(metaDataDO); + when(metaDataService.findByServiceNameAndMethodName(any(), any(), any())).thenReturn(metaDataDO); MetaDataRegisterDTO metaDataDTO = MetaDataRegisterDTO.builder().serviceName(serviceName) .methodName(methodName).build(); shenyuClientRegisterTarsService.registerMetadata(metaDataDTO); - verify(metaDataService).findByServiceNameAndMethodName(serviceName, methodName); + verify(metaDataService).findByServiceNameAndMethodName(serviceName, methodName, SYS_DEFAULT_NAMESPACE_ID); verify(metaDataService).saveOrUpdateMetaData(metaDataDO, metaDataDTO); } From 527b01b87e2a6905f0671ae106f874104c8cfd1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=98xcsnx=E2=80=99?= <‘1192709687@qq.com’> Date: Sun, 18 Aug 2024 01:18:01 +0800 Subject: [PATCH 44/61] commit --- .../admin/controller/MetaDataController.java | 3 ++- .../apache/shenyu/admin/mapper/MetaDataMapper.java | 14 +++++++++----- .../shenyu/admin/service/MetaDataService.java | 7 ++++++- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/controller/MetaDataController.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/controller/MetaDataController.java index 0eee7f503eb1..8d3bce9a9005 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/controller/MetaDataController.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/controller/MetaDataController.java @@ -64,6 +64,7 @@ public MetaDataController(final MetaDataService metaDataService) { * @param path the path * @param currentPage the current page * @param pageSize the page size + * @param namespaceId namespaceId. * @return the shenyu result */ @GetMapping("/queryList") @@ -129,7 +130,7 @@ public ShenyuAdminResult createOrUpdate(@Valid @RequestBody final MetaDataDTO me /** * Batch deleted metadata. * - * @param ids the ids + * @param batchNamespaceCommonDTO batchNamespaceCommonDTO. * @return the shenyu result */ @DeleteMapping("/batchDeleted") diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/MetaDataMapper.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/MetaDataMapper.java index db90d8a6e8f0..b616df90ec22 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/MetaDataMapper.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/MetaDataMapper.java @@ -45,15 +45,16 @@ public interface MetaDataMapper extends ExistProvider { * Select meta data do by id and namespaceId. * * @param id the id - * @param namespaceId namespaceId. + * @param namespaceId namespaceId * @return the meta data do */ MetaDataDO selectById(String id, String namespaceId); /** - * Select a list of MetaDataDOs by idList. + * Select a list of MetaDataDOs by idList and namespaceId. * * @param idList a list of ids + * @param namespaceId namespaceId * @return a list of MetaDataDOs */ List selectByIdList(@Param("idList") List idList, @Param("namespaceId") String namespaceId); @@ -66,18 +67,20 @@ public interface MetaDataMapper extends ExistProvider { List findAll(); /** - * Find by path meta data do. + * Find meta data do by path and namespaceId. * * @param path the path + * @param namespaceId namespaceId * @return the meta data do */ MetaDataDO findByPath(String path, String namespaceId); /** - * Find by service name and method meta data do. + * Find meta data do by service name and method and namespaceId. * * @param serviceName the service name * @param methodName the methodName + * @param namespaceId namespaceId * @return the meta data do */ List findByServiceNameAndMethod(@Param("serviceName") String serviceName, @Param("methodName") String methodName, @Param("namespaceId") String namespaceId); @@ -147,9 +150,10 @@ public interface MetaDataMapper extends ExistProvider { int delete(String id); /** - * batch delete by a list of ids. + * batch delete by a list of ids and namespaceId. * * @param idList a list of ids + * @param namespaceId namespaceId * @return the count of deleted */ int deleteByIdList(@Param("idList") List idList, @Param("namespaceId") String namespaceId); diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/MetaDataService.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/MetaDataService.java index dbfa20aae4a0..4e351e361f6b 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/MetaDataService.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/MetaDataService.java @@ -54,7 +54,8 @@ public interface MetaDataService { /** * delete application authorities. * - * @param ids primary key. + * @param ids primary key + * @param namespaceId namespaceId * @return rows int */ int delete(List ids, String namespaceId); @@ -63,6 +64,7 @@ public interface MetaDataService { * Find by id meta data vo. * * @param id the id + * @param namespaceId namespaceId * @return the meta data vo */ MetaDataVO findById(String id, String namespaceId); @@ -108,6 +110,7 @@ public interface MetaDataService { * * @param ids the ids * @param enabled the enabled + * @param namespaceId namespaceId * @return the string */ String enabled(List ids, Boolean enabled, String namespaceId); @@ -121,6 +124,7 @@ public interface MetaDataService { * find meta data by path. * * @param path the path of meta data + * @param namespaceId namespaceId * @return {@link MetaDataDO} */ MetaDataDO findByPath(String path,String namespaceId); @@ -130,6 +134,7 @@ public interface MetaDataService { * * @param serviceName the name of service * @param methodName the name of method + * @param namespaceId namespaceId * @return {@link MetaDataDO} */ MetaDataDO findByServiceNameAndMethodName(String serviceName, String methodName, String namespaceId); From 9bfd03dc33e948b8dd261855faa0170483b1b962 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=98xcsnx=E2=80=99?= <‘1192709687@qq.com’> Date: Sun, 18 Aug 2024 15:18:31 +0800 Subject: [PATCH 45/61] commit --- .../shenyu/admin/mapper/MetaDataMapper.java | 10 +++++----- .../service/impl/MetaDataServiceImpl.java | 18 +++++++++--------- .../resources/mappers/meta-data-sqlmap.xml | 10 +++++----- .../admin/mapper/MetaDataMapperTest.java | 16 ++++++++-------- .../admin/service/MetaDataServiceTest.java | 16 ++++++++-------- 5 files changed, 35 insertions(+), 35 deletions(-) diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/MetaDataMapper.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/MetaDataMapper.java index b616df90ec22..96436e03e115 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/MetaDataMapper.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/MetaDataMapper.java @@ -48,7 +48,7 @@ public interface MetaDataMapper extends ExistProvider { * @param namespaceId namespaceId * @return the meta data do */ - MetaDataDO selectById(String id, String namespaceId); + MetaDataDO selectByIdAndNamespaceId(String id, String namespaceId); /** * Select a list of MetaDataDOs by idList and namespaceId. @@ -57,7 +57,7 @@ public interface MetaDataMapper extends ExistProvider { * @param namespaceId namespaceId * @return a list of MetaDataDOs */ - List selectByIdList(@Param("idList") List idList, @Param("namespaceId") String namespaceId); + List selectByIdListAndNamespaceId(@Param("idList") List idList, @Param("namespaceId") String namespaceId); /** * Find all list. @@ -73,7 +73,7 @@ public interface MetaDataMapper extends ExistProvider { * @param namespaceId namespaceId * @return the meta data do */ - MetaDataDO findByPath(String path, String namespaceId); + MetaDataDO findByPathAndNamespaceId(String path, String namespaceId); /** * Find meta data do by service name and method and namespaceId. @@ -83,7 +83,7 @@ public interface MetaDataMapper extends ExistProvider { * @param namespaceId namespaceId * @return the meta data do */ - List findByServiceNameAndMethod(@Param("serviceName") String serviceName, @Param("methodName") String methodName, @Param("namespaceId") String namespaceId); + List findByServiceNameAndMethodAndNamespaceId(@Param("serviceName") String serviceName, @Param("methodName") String methodName, @Param("namespaceId") String namespaceId); /** * Select by query list. @@ -156,7 +156,7 @@ public interface MetaDataMapper extends ExistProvider { * @param namespaceId namespaceId * @return the count of deleted */ - int deleteByIdList(@Param("idList") List idList, @Param("namespaceId") String namespaceId); + int deleteByIdListAndNamespaceId(@Param("idList") List idList, @Param("namespaceId") String namespaceId); /** * the path is existed. diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/MetaDataServiceImpl.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/MetaDataServiceImpl.java index ad8eb8bfabae..c397ffaa8b88 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/MetaDataServiceImpl.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/MetaDataServiceImpl.java @@ -108,11 +108,11 @@ public String createOrUpdate(final MetaDataDTO metaDataDTO) { @Override public int delete(final List ids, final String namespaceId) { - List deletedMetaData = metaDataMapper.selectByIdList(ids, namespaceId); + List deletedMetaData = metaDataMapper.selectByIdListAndNamespaceId(ids, namespaceId); if (CollectionUtils.isEmpty(deletedMetaData)) { return 0; } - int count = metaDataMapper.deleteByIdList(ids, namespaceId); + int count = metaDataMapper.deleteByIdListAndNamespaceId(ids, namespaceId); if (count > 0) { publisher.onDeleted(deletedMetaData); } @@ -121,7 +121,7 @@ public int delete(final List ids, final String namespaceId) { @Override public String enabled(final List ids, final Boolean enabled, final String namespaceId) { - List metaDataDoList = metaDataMapper.selectByIdList(ids, namespaceId); + List metaDataDoList = metaDataMapper.selectByIdListAndNamespaceId(ids, namespaceId); if (CollectionUtils.isEmpty(metaDataDoList)) { return AdminConstants.ID_NOT_EXIST; } @@ -144,7 +144,7 @@ public void syncData() { @Override public MetaDataVO findById(final String id, final String namespaceId) { - return Optional.ofNullable(MetaDataTransfer.INSTANCE.mapToVO(metaDataMapper.selectById(id, namespaceId))).orElseGet(MetaDataVO::new); + return Optional.ofNullable(MetaDataTransfer.INSTANCE.mapToVO(metaDataMapper.selectByIdAndNamespaceId(id, namespaceId))).orElseGet(MetaDataVO::new); } @Override @@ -178,12 +178,12 @@ public List listAllData() { @Override public MetaDataDO findByPath(final String path, final String namespaceId) { - return metaDataMapper.findByPath(path, namespaceId); + return metaDataMapper.findByPathAndNamespaceId(path, namespaceId); } @Override public MetaDataDO findByServiceNameAndMethodName(final String serviceName, final String methodName, final String namespaceId) { - final List metadataList = metaDataMapper.findByServiceNameAndMethod(serviceName, methodName, namespaceId); + final List metadataList = metaDataMapper.findByServiceNameAndMethodAndNamespaceId(serviceName, methodName, namespaceId); return CollectionUtils.isEmpty(metadataList) ? null : metadataList.get(0); } @@ -248,14 +248,14 @@ private String create(final MetaDataDTO metaDataDTO) { private String update(final MetaDataDTO metaDataDTO) { Assert.isNull(metaDataMapper.pathExistedExclude(metaDataDTO.getPath(), Collections.singletonList(metaDataDTO.getId())), AdminConstants.DATA_PATH_IS_EXIST); MetaDataDO metaDataDO = MetaDataTransfer.INSTANCE.mapToEntity(metaDataDTO); - Optional.ofNullable(metaDataMapper.selectById(metaDataDTO.getId(), metaDataDTO.getNamespaceId())) + Optional.ofNullable(metaDataMapper.selectByIdAndNamespaceId(metaDataDTO.getId(), metaDataDTO.getNamespaceId())) .ifPresent(e -> metaDataDTO.setEnabled(e.getEnabled())); metaDataDO.setPathDesc(Optional.ofNullable(metaDataDO.getPathDesc()).orElse("")); - final MetaDataDO before = metaDataMapper.selectById(metaDataDO.getId(), metaDataDTO.getNamespaceId()); + final MetaDataDO before = metaDataMapper.selectByIdAndNamespaceId(metaDataDO.getId(), metaDataDTO.getNamespaceId()); if (metaDataMapper.update(metaDataDO) > 0) { publisher.onUpdated(metaDataDO, before); // update other rpc_ext for the same service - final List befores = Optional.ofNullable(metaDataMapper.findByServiceNameAndMethod( + final List befores = Optional.ofNullable(metaDataMapper.findByServiceNameAndMethodAndNamespaceId( metaDataDO.getServiceName(), null, metaDataDO.getNamespaceId())).orElseGet(LinkedList::new); for (MetaDataDO b : befores) { MetaDataDO update = MetaDataTransfer.INSTANCE.copy(b); diff --git a/shenyu-admin/src/main/resources/mappers/meta-data-sqlmap.xml b/shenyu-admin/src/main/resources/mappers/meta-data-sqlmap.xml index 6622530625ca..b289ae450e6a 100644 --- a/shenyu-admin/src/main/resources/mappers/meta-data-sqlmap.xml +++ b/shenyu-admin/src/main/resources/mappers/meta-data-sqlmap.xml @@ -48,7 +48,7 @@ enabled - SElECT FROM meta_data @@ -56,7 +56,7 @@ AND namespace_id = #{namespaceId, jdbcType=VARCHAR} - SElECT FROM meta_data @@ -67,7 +67,7 @@ AND namespace_id = #{namespaceId, jdbcType=VARCHAR} - SElECT FROM meta_data @@ -75,7 +75,7 @@ AND namespace_id = #{namespaceId, jdbcType=VARCHAR} - SElECT FROM meta_data @@ -217,7 +217,7 @@ WHERE id = #{id,jdbcType=VARCHAR} - + DELETE FROM meta_data WHERE id IN diff --git a/shenyu-admin/src/test/java/org/apache/shenyu/admin/mapper/MetaDataMapperTest.java b/shenyu-admin/src/test/java/org/apache/shenyu/admin/mapper/MetaDataMapperTest.java index 2a65c042cb86..36e1d460e270 100644 --- a/shenyu-admin/src/test/java/org/apache/shenyu/admin/mapper/MetaDataMapperTest.java +++ b/shenyu-admin/src/test/java/org/apache/shenyu/admin/mapper/MetaDataMapperTest.java @@ -62,7 +62,7 @@ public void selectById() { int count = metaDataMapper.insert(metaDataDO); assertThat(count, comparesEqualTo(1)); String id = metaDataDO.getId(); - MetaDataDO result = metaDataMapper.selectById(id, SYS_DEFAULT_NAMESPACE_ID); + MetaDataDO result = metaDataMapper.selectByIdAndNamespaceId(id, SYS_DEFAULT_NAMESPACE_ID); assertThat(result.getId(), comparesEqualTo(id)); } @@ -77,7 +77,7 @@ public void selectByIdSet() { assertThat(count2, comparesEqualTo(1)); List idList = Stream.of(metaDataDO.getId(), metaDataDO2.getId()).collect(Collectors.toList()); - List resultList = metaDataMapper.selectByIdList(idList, SYS_DEFAULT_NAMESPACE_ID); + List resultList = metaDataMapper.selectByIdListAndNamespaceId(idList, SYS_DEFAULT_NAMESPACE_ID); assertThat(resultList, hasItems(metaDataDO2, metaDataDO)); assertThat(resultList.size(), comparesEqualTo(idList.size())); } @@ -99,7 +99,7 @@ public void findByPath() { int count = metaDataMapper.insert(metaDataDO); assertThat(count, comparesEqualTo(1)); - MetaDataDO result = metaDataMapper.findByPath(metaDataDO.getPath(), SYS_DEFAULT_NAMESPACE_ID); + MetaDataDO result = metaDataMapper.findByPathAndNamespaceId(metaDataDO.getPath(), SYS_DEFAULT_NAMESPACE_ID); assertThat(result.getId(), comparesEqualTo(metaDataDO.getId())); } @@ -109,7 +109,7 @@ public void findByServiceNameAndMethod() { int count = metaDataMapper.insert(metaDataDO); assertThat(count, comparesEqualTo(1)); - MetaDataDO result = metaDataMapper.findByServiceNameAndMethod(metaDataDO.getServiceName(), metaDataDO.getMethodName(), SYS_DEFAULT_NAMESPACE_ID).get(0); + MetaDataDO result = metaDataMapper.findByServiceNameAndMethodAndNamespaceId(metaDataDO.getServiceName(), metaDataDO.getMethodName(), SYS_DEFAULT_NAMESPACE_ID).get(0); assertThat(result.getId(), comparesEqualTo(metaDataDO.getId())); } @@ -176,7 +176,7 @@ public void update() { metaDataDO.setAppName("testAppName_update"); metaDataMapper.update(metaDataDO); - MetaDataDO result = metaDataMapper.selectById(metaDataDO.getId(), SYS_DEFAULT_NAMESPACE_ID); + MetaDataDO result = metaDataMapper.selectByIdAndNamespaceId(metaDataDO.getId(), SYS_DEFAULT_NAMESPACE_ID); assertThat(result.getAppName(), comparesEqualTo("testAppName_update")); } @@ -189,7 +189,7 @@ public void updateEnable() { metaDataDO.setEnabled(true); metaDataMapper.updateEnable(metaDataDO); - MetaDataDO result = metaDataMapper.selectById(metaDataDO.getId(), SYS_DEFAULT_NAMESPACE_ID); + MetaDataDO result = metaDataMapper.selectByIdAndNamespaceId(metaDataDO.getId(), SYS_DEFAULT_NAMESPACE_ID); assertTrue(result.getEnabled()); } @@ -207,7 +207,7 @@ public void updateEnableBatch() { int ret = metaDataMapper.updateEnableBatch(idList, true); assertThat(ret, comparesEqualTo(idList.size())); - List resultList = metaDataMapper.selectByIdList(idList, SYS_DEFAULT_NAMESPACE_ID); + List resultList = metaDataMapper.selectByIdListAndNamespaceId(idList, SYS_DEFAULT_NAMESPACE_ID); resultList.forEach(result -> assertTrue(result.getEnabled())); } @@ -232,7 +232,7 @@ public void deleteByIdSet() { assertThat(count2, comparesEqualTo(1)); List idList = Stream.of(metaDataDO.getId(), metaDataDO2.getId()).collect(Collectors.toList()); - int result = metaDataMapper.deleteByIdList(idList, SYS_DEFAULT_NAMESPACE_ID); + int result = metaDataMapper.deleteByIdListAndNamespaceId(idList, SYS_DEFAULT_NAMESPACE_ID); assertThat(result, comparesEqualTo(idList.size())); } diff --git a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/MetaDataServiceTest.java b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/MetaDataServiceTest.java index 6e03845e28be..38a5d5ad1881 100644 --- a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/MetaDataServiceTest.java +++ b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/MetaDataServiceTest.java @@ -142,7 +142,7 @@ public void testEnabled() { List ids = Lists.newArrayList("id1", "id2", "id3"); String msg = metaDataService.enabled(ids, true, SYS_DEFAULT_NAMESPACE_ID); assertEquals(AdminConstants.ID_NOT_EXIST, msg); - when(metaDataMapper.selectByIdList(ids, SYS_DEFAULT_NAMESPACE_ID)) + when(metaDataMapper.selectByIdListAndNamespaceId(ids, SYS_DEFAULT_NAMESPACE_ID)) .thenReturn(Arrays.asList(MetaDataDO.builder().build(), MetaDataDO.builder().build())) .thenReturn(Arrays.asList(MetaDataDO.builder().build(), MetaDataDO.builder().build(), MetaDataDO.builder().build())); msg = metaDataService.enabled(ids, false, SYS_DEFAULT_NAMESPACE_ID); @@ -171,14 +171,14 @@ public void testSyncDate() { */ @Test public void testFindById() { - when(metaDataMapper.selectById(anyString(), anyString())).thenReturn(null); + when(metaDataMapper.selectByIdAndNamespaceId(anyString(), anyString())).thenReturn(null); MetaDataVO dataVo = metaDataService.findById(anyString(), anyString()); Assertions.assertEquals(new MetaDataVO(), dataVo); final String appName = "appName"; MetaDataDO metaDataDO = MetaDataDO.builder().build(); metaDataDO.setAppName(appName); - when(metaDataMapper.selectById(anyString(), anyString())).thenReturn(metaDataDO); + when(metaDataMapper.selectByIdAndNamespaceId(anyString(), anyString())).thenReturn(metaDataDO); dataVo = metaDataService.findById(anyString(), anyString()); assertEquals(appName, dataVo.getAppName()); } @@ -268,7 +268,7 @@ public void testFindByPath() { .appName("appName1") .path("path1") .build(); - given(this.metaDataMapper.findByPath(any(), any())).willReturn(metaDataDO1); + given(this.metaDataMapper.findByPathAndNamespaceId(any(), any())).willReturn(metaDataDO1); MetaDataDO metaDataDO = metaDataService.findByPath("path1", SYS_DEFAULT_NAMESPACE_ID); assertNotNull(metaDataDO); Assertions.assertEquals(metaDataDO, metaDataDO1); @@ -283,7 +283,7 @@ public void testFindByServiceNameAndMethodName() { .serviceName("serviceName1") .methodName("method1") .build(); - given(this.metaDataMapper.findByServiceNameAndMethod(any(), any(), any())) + given(this.metaDataMapper.findByServiceNameAndMethodAndNamespaceId(any(), any(), any())) .willReturn(Collections.singletonList(metaDataDO1)); MetaDataDO metaDataDO = metaDataService .findByServiceNameAndMethodName("serviceName1", "method1", SYS_DEFAULT_NAMESPACE_ID); @@ -334,7 +334,7 @@ private void testCreateOrUpdateForUpdate() { when(metaDataDTO.getId()).thenReturn("id"); when(metaDataDTO.getPath()).thenReturn("path"); when(metaDataMapper.pathExistedExclude("path", Collections.singletonList("id"))).thenReturn(null); - when(metaDataMapper.selectById("id", SYS_DEFAULT_NAMESPACE_ID)).thenReturn(metaDataDO); + when(metaDataMapper.selectByIdAndNamespaceId("id", SYS_DEFAULT_NAMESPACE_ID)).thenReturn(metaDataDO); when(metaDataMapper.update(any())).thenReturn(1); String msg = metaDataService.createOrUpdate(metaDataDTO); assertEquals(ShenyuResultMessage.UPDATE_SUCCESS, msg); @@ -362,8 +362,8 @@ private void testDeleteForNotEmptyIds() { List ids = Lists.newArrayList("id1", "id3"); int count = metaDataService.delete(ids, SYS_DEFAULT_NAMESPACE_ID); Assertions.assertEquals(0, count, "The count of delete should be 0."); - when(metaDataMapper.selectByIdList(ids, SYS_DEFAULT_NAMESPACE_ID)).thenReturn(Arrays.asList(MetaDataDO.builder().build(), MetaDataDO.builder().build())); - when(metaDataMapper.deleteByIdList(ids, SYS_DEFAULT_NAMESPACE_ID)).thenReturn(2); + when(metaDataMapper.selectByIdListAndNamespaceId(ids, SYS_DEFAULT_NAMESPACE_ID)).thenReturn(Arrays.asList(MetaDataDO.builder().build(), MetaDataDO.builder().build())); + when(metaDataMapper.deleteByIdListAndNamespaceId(ids, SYS_DEFAULT_NAMESPACE_ID)).thenReturn(2); count = metaDataService.delete(ids, SYS_DEFAULT_NAMESPACE_ID); Assertions.assertEquals(2, count, "The count of delete should be 2."); From a7f78ad0e5f60cc2d992ef21006e7130b36defb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=98xcsnx=E2=80=99?= <‘1192709687@qq.com’> Date: Sun, 18 Aug 2024 15:30:14 +0800 Subject: [PATCH 46/61] commit --- .../admin/controller/MetaDataController.java | 6 +++--- .../shenyu/admin/service/MetaDataService.java | 6 +++--- .../shenyu/admin/service/impl/ApiServiceImpl.java | 2 +- .../admin/service/impl/MetaDataServiceImpl.java | 6 +++--- .../admin/controller/MetaDataControllerTest.java | 8 ++++---- .../shenyu/admin/service/MetaDataServiceTest.java | 14 +++++++------- 6 files changed, 21 insertions(+), 21 deletions(-) diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/controller/MetaDataController.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/controller/MetaDataController.java index 8d3bce9a9005..0d26fdb02d74 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/controller/MetaDataController.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/controller/MetaDataController.java @@ -112,7 +112,7 @@ public ShenyuAdminResult findAllGroup() { public ShenyuAdminResult detail(@PathVariable("id") final String id, @PathVariable("namespaceId") @Valid @Existed(provider = NamespaceMapper.class, message = "namespaceId is not existed") final String namespaceId) { - return ShenyuAdminResult.success(ShenyuResultMessage.DETAIL_SUCCESS, metaDataService.findById(id, namespaceId)); + return ShenyuAdminResult.success(ShenyuResultMessage.DETAIL_SUCCESS, metaDataService.findByIdAndNamespaceId(id, namespaceId)); } /** @@ -136,7 +136,7 @@ public ShenyuAdminResult createOrUpdate(@Valid @RequestBody final MetaDataDTO me @DeleteMapping("/batchDeleted") @RequiresPermissions("system:meta:delete") public ShenyuAdminResult batchDeleted(@Valid @RequestBody final BatchNamespaceCommonDTO batchNamespaceCommonDTO) { - Integer deleteCount = metaDataService.delete(batchNamespaceCommonDTO.getIds(), batchNamespaceCommonDTO.getNamespaceId()); + Integer deleteCount = metaDataService.deleteByIdsAndNamespaceId(batchNamespaceCommonDTO.getIds(), batchNamespaceCommonDTO.getNamespaceId()); return ShenyuAdminResult.success(ShenyuResultMessage.DELETE_SUCCESS, deleteCount); } @@ -149,7 +149,7 @@ public ShenyuAdminResult batchDeleted(@Valid @RequestBody final BatchNamespaceCo @PostMapping("/batchEnabled") @RequiresPermissions("system:meta:disable") public ShenyuAdminResult batchEnabled(@Valid @RequestBody final BatchCommonDTO batchCommonDTO) { - final String result = metaDataService.enabled(batchCommonDTO.getIds(), batchCommonDTO.getEnabled(), batchCommonDTO.getNamespaceId()); + final String result = metaDataService.enabledByIdsAndNamespaceId(batchCommonDTO.getIds(), batchCommonDTO.getEnabled(), batchCommonDTO.getNamespaceId()); if (StringUtils.isNoneBlank(result)) { return ShenyuAdminResult.error(result); } diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/MetaDataService.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/MetaDataService.java index 4e351e361f6b..db05594567fc 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/MetaDataService.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/MetaDataService.java @@ -58,7 +58,7 @@ public interface MetaDataService { * @param namespaceId namespaceId * @return rows int */ - int delete(List ids, String namespaceId); + int deleteByIdsAndNamespaceId(List ids, String namespaceId); /** * Find by id meta data vo. @@ -67,7 +67,7 @@ public interface MetaDataService { * @param namespaceId namespaceId * @return the meta data vo */ - MetaDataVO findById(String id, String namespaceId); + MetaDataVO findByIdAndNamespaceId(String id, String namespaceId); /** * List by page common pager. @@ -113,7 +113,7 @@ public interface MetaDataService { * @param namespaceId namespaceId * @return the string */ - String enabled(List ids, Boolean enabled, String namespaceId); + String enabledByIdsAndNamespaceId(List ids, Boolean enabled, String namespaceId); /** * Sync data. diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/ApiServiceImpl.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/ApiServiceImpl.java index 621684495849..0d1cb9e95289 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/ApiServiceImpl.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/ApiServiceImpl.java @@ -194,7 +194,7 @@ private void removeRegister(final ApiDO apiDO) { } //clean metadata Optional.ofNullable(metaDataService.findByPath(path, SYS_DEFAULT_NAMESPACE_ID)) - .ifPresent(metaDataDO -> metaDataService.delete(Lists.newArrayList(metaDataDO.getId()), SYS_DEFAULT_NAMESPACE_ID)); + .ifPresent(metaDataDO -> metaDataService.deleteByIdsAndNamespaceId(Lists.newArrayList(metaDataDO.getId()), SYS_DEFAULT_NAMESPACE_ID)); } private void register(final ApiDO apiDO) { diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/MetaDataServiceImpl.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/MetaDataServiceImpl.java index c397ffaa8b88..42f45a954411 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/MetaDataServiceImpl.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/MetaDataServiceImpl.java @@ -107,7 +107,7 @@ public String createOrUpdate(final MetaDataDTO metaDataDTO) { } @Override - public int delete(final List ids, final String namespaceId) { + public int deleteByIdsAndNamespaceId(final List ids, final String namespaceId) { List deletedMetaData = metaDataMapper.selectByIdListAndNamespaceId(ids, namespaceId); if (CollectionUtils.isEmpty(deletedMetaData)) { return 0; @@ -120,7 +120,7 @@ public int delete(final List ids, final String namespaceId) { } @Override - public String enabled(final List ids, final Boolean enabled, final String namespaceId) { + public String enabledByIdsAndNamespaceId(final List ids, final Boolean enabled, final String namespaceId) { List metaDataDoList = metaDataMapper.selectByIdListAndNamespaceId(ids, namespaceId); if (CollectionUtils.isEmpty(metaDataDoList)) { return AdminConstants.ID_NOT_EXIST; @@ -143,7 +143,7 @@ public void syncData() { } @Override - public MetaDataVO findById(final String id, final String namespaceId) { + public MetaDataVO findByIdAndNamespaceId(final String id, final String namespaceId) { return Optional.ofNullable(MetaDataTransfer.INSTANCE.mapToVO(metaDataMapper.selectByIdAndNamespaceId(id, namespaceId))).orElseGet(MetaDataVO::new); } diff --git a/shenyu-admin/src/test/java/org/apache/shenyu/admin/controller/MetaDataControllerTest.java b/shenyu-admin/src/test/java/org/apache/shenyu/admin/controller/MetaDataControllerTest.java index b0750bfac8f6..86c62a4859fd 100644 --- a/shenyu-admin/src/test/java/org/apache/shenyu/admin/controller/MetaDataControllerTest.java +++ b/shenyu-admin/src/test/java/org/apache/shenyu/admin/controller/MetaDataControllerTest.java @@ -139,7 +139,7 @@ public void testFindAllGroup() throws Exception { @Test public void testEditor() throws Exception { - given(this.metaDataService.findById("1")).willReturn(metaDataVO); + given(this.metaDataService.findByIdAndNamespaceId("1", SYS_DEFAULT_NAMESPACE_ID)).willReturn(metaDataVO); this.mockMvc.perform(MockMvcRequestBuilders.get("/meta-data/{id}", "1")) .andExpect(status().isOk()) .andExpect(jsonPath("$.message", is(ShenyuResultMessage.DETAIL_SUCCESS))) @@ -200,7 +200,7 @@ public void testBatchDeleted() throws Exception { final List ids = new ArrayList<>(2); ids.add("1"); ids.add("2"); - given(this.metaDataService.delete(ids)).willReturn(2); + given(this.metaDataService.deleteByIdsAndNamespaceId(ids, SYS_DEFAULT_NAMESPACE_ID)).willReturn(2); this.mockMvc.perform(MockMvcRequestBuilders.post("/meta-data/batchDeleted") .contentType(MediaType.APPLICATION_JSON) .content(GsonUtils.getInstance().toJson(ids))) @@ -215,7 +215,7 @@ public void testBatchEnabled() throws Exception { final BatchCommonDTO batchCommonDTO = new BatchCommonDTO(); batchCommonDTO.setIds(Arrays.asList("1", "2")); batchCommonDTO.setEnabled(true); - given(this.metaDataService.enabled(batchCommonDTO.getIds(), batchCommonDTO.getEnabled())).willReturn(StringUtils.EMPTY); + given(this.metaDataService.enabledByIdsAndNamespaceId(batchCommonDTO.getIds(), batchCommonDTO.getEnabled(), SYS_DEFAULT_NAMESPACE_ID)).willReturn(StringUtils.EMPTY); this.mockMvc.perform(MockMvcRequestBuilders.post("/meta-data/batchEnabled") .contentType(MediaType.APPLICATION_JSON) .content(GsonUtils.getInstance().toJson(batchCommonDTO))) @@ -229,7 +229,7 @@ public void testBatchEnabledWithError() throws Exception { final BatchCommonDTO batchCommonDTO = new BatchCommonDTO(); batchCommonDTO.setIds(Arrays.asList("1", "2")); batchCommonDTO.setEnabled(true); - given(this.metaDataService.enabled(batchCommonDTO.getIds(), batchCommonDTO.getEnabled())).willReturn(AdminConstants.ID_NOT_EXIST); + given(this.metaDataService.enabledByIdsAndNamespaceId(batchCommonDTO.getIds(), batchCommonDTO.getEnabled(), SYS_DEFAULT_NAMESPACE_ID)).willReturn(AdminConstants.ID_NOT_EXIST); this.mockMvc.perform(MockMvcRequestBuilders.post("/meta-data/batchEnabled") .contentType(MediaType.APPLICATION_JSON) .content(GsonUtils.getInstance().toJson(batchCommonDTO))) diff --git a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/MetaDataServiceTest.java b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/MetaDataServiceTest.java index 38a5d5ad1881..3ee25cbc323e 100644 --- a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/MetaDataServiceTest.java +++ b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/MetaDataServiceTest.java @@ -140,12 +140,12 @@ public void testDelete() { @Test public void testEnabled() { List ids = Lists.newArrayList("id1", "id2", "id3"); - String msg = metaDataService.enabled(ids, true, SYS_DEFAULT_NAMESPACE_ID); + String msg = metaDataService.enabledByIdsAndNamespaceId(ids, true, SYS_DEFAULT_NAMESPACE_ID); assertEquals(AdminConstants.ID_NOT_EXIST, msg); when(metaDataMapper.selectByIdListAndNamespaceId(ids, SYS_DEFAULT_NAMESPACE_ID)) .thenReturn(Arrays.asList(MetaDataDO.builder().build(), MetaDataDO.builder().build())) .thenReturn(Arrays.asList(MetaDataDO.builder().build(), MetaDataDO.builder().build(), MetaDataDO.builder().build())); - msg = metaDataService.enabled(ids, false, SYS_DEFAULT_NAMESPACE_ID); + msg = metaDataService.enabledByIdsAndNamespaceId(ids, false, SYS_DEFAULT_NAMESPACE_ID); assertEquals(StringUtils.EMPTY, msg); } @@ -172,14 +172,14 @@ public void testSyncDate() { @Test public void testFindById() { when(metaDataMapper.selectByIdAndNamespaceId(anyString(), anyString())).thenReturn(null); - MetaDataVO dataVo = metaDataService.findById(anyString(), anyString()); + MetaDataVO dataVo = metaDataService.findByIdAndNamespaceId(anyString(), anyString()); Assertions.assertEquals(new MetaDataVO(), dataVo); final String appName = "appName"; MetaDataDO metaDataDO = MetaDataDO.builder().build(); metaDataDO.setAppName(appName); when(metaDataMapper.selectByIdAndNamespaceId(anyString(), anyString())).thenReturn(metaDataDO); - dataVo = metaDataService.findById(anyString(), anyString()); + dataVo = metaDataService.findByIdAndNamespaceId(anyString(), anyString()); assertEquals(appName, dataVo.getAppName()); } @@ -350,7 +350,7 @@ private void assertEquals(final String expected, final String actual) { */ private void testDeleteForEmptyIds() { List ids = Lists.newArrayList(); - int count = metaDataService.delete(ids, SYS_DEFAULT_NAMESPACE_ID); + int count = metaDataService.deleteByIdsAndNamespaceId(ids, SYS_DEFAULT_NAMESPACE_ID); Assertions.assertEquals(0, count, "The count of delete should be 0."); } @@ -360,11 +360,11 @@ private void testDeleteForEmptyIds() { */ private void testDeleteForNotEmptyIds() { List ids = Lists.newArrayList("id1", "id3"); - int count = metaDataService.delete(ids, SYS_DEFAULT_NAMESPACE_ID); + int count = metaDataService.deleteByIdsAndNamespaceId(ids, SYS_DEFAULT_NAMESPACE_ID); Assertions.assertEquals(0, count, "The count of delete should be 0."); when(metaDataMapper.selectByIdListAndNamespaceId(ids, SYS_DEFAULT_NAMESPACE_ID)).thenReturn(Arrays.asList(MetaDataDO.builder().build(), MetaDataDO.builder().build())); when(metaDataMapper.deleteByIdListAndNamespaceId(ids, SYS_DEFAULT_NAMESPACE_ID)).thenReturn(2); - count = metaDataService.delete(ids, SYS_DEFAULT_NAMESPACE_ID); + count = metaDataService.deleteByIdsAndNamespaceId(ids, SYS_DEFAULT_NAMESPACE_ID); Assertions.assertEquals(2, count, "The count of delete should be 2."); } From 952f5b61eb4745edf603fe77e5c9cdd1c55a8d7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=98xcsnx=E2=80=99?= <‘1192709687@qq.com’> Date: Sun, 18 Aug 2024 15:40:24 +0800 Subject: [PATCH 47/61] commit --- .../shenyu/admin/service/MetaDataService.java | 14 +++++++------- .../shenyu/admin/service/impl/ApiServiceImpl.java | 2 +- .../admin/service/impl/MetaDataServiceImpl.java | 4 ++-- .../ShenyuClientRegisterDivideServiceImpl.java | 2 +- .../ShenyuClientRegisterDubboServiceImpl.java | 2 +- .../ShenyuClientRegisterGrpcServiceImpl.java | 2 +- .../ShenyuClientRegisterMotanServiceImpl.java | 2 +- .../ShenyuClientRegisterSofaServiceImpl.java | 2 +- ...ShenyuClientRegisterSpringCloudServiceImpl.java | 2 +- .../ShenyuClientRegisterTarsServiceImpl.java | 2 +- .../ShenyuClientRegisterWebSocketServiceImpl.java | 2 +- .../shenyu/admin/service/MetaDataServiceTest.java | 4 ++-- .../ShenyuClientRegisterDivideServiceImplTest.java | 2 +- .../ShenyuClientRegisterDubboServiceImplTest.java | 2 +- .../ShenyuClientRegisterGrpcServiceImplTest.java | 4 ++-- .../ShenyuClientRegisterMotanServiceImplTest.java | 2 +- .../ShenyuClientRegisterSofaServiceImplTest.java | 2 +- ...yuClientRegisterSpringCloudServiceImplTest.java | 4 ++-- .../ShenyuClientRegisterTarsServiceImplTest.java | 4 ++-- ...enyuClientRegisterWebSocketServiceImplTest.java | 2 +- 20 files changed, 31 insertions(+), 31 deletions(-) diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/MetaDataService.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/MetaDataService.java index db05594567fc..2decf197996a 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/MetaDataService.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/MetaDataService.java @@ -52,7 +52,7 @@ public interface MetaDataService { String createOrUpdate(MetaDataDTO metaDataDTO); /** - * delete application authorities. + * delete application authorities by ids and namespaceId. * * @param ids primary key * @param namespaceId namespaceId @@ -61,7 +61,7 @@ public interface MetaDataService { int deleteByIdsAndNamespaceId(List ids, String namespaceId); /** - * Find by id meta data vo. + * Find meta data vo by id and namespaceId. * * @param id the id * @param namespaceId namespaceId @@ -106,7 +106,7 @@ public interface MetaDataService { List listAllData(); /** - * Enabled string. + * Enabled by ids and namespaceId. * * @param ids the ids * @param enabled the enabled @@ -121,23 +121,23 @@ public interface MetaDataService { void syncData(); /** - * find meta data by path. + * find meta data by path and namespaceId. * * @param path the path of meta data * @param namespaceId namespaceId * @return {@link MetaDataDO} */ - MetaDataDO findByPath(String path,String namespaceId); + MetaDataDO findByPathAndNamespaceId(String path, String namespaceId); /** - * find meta data by service's name and method's name. + * find meta data by service's name and method's name and namespaceId. * * @param serviceName the name of service * @param methodName the name of method * @param namespaceId namespaceId * @return {@link MetaDataDO} */ - MetaDataDO findByServiceNameAndMethodName(String serviceName, String methodName, String namespaceId); + MetaDataDO findByServiceNameAndMethodNameAndNamespaceId(String serviceName, String methodName, String namespaceId); /** * insert MetaDataDO. diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/ApiServiceImpl.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/ApiServiceImpl.java index 0d1cb9e95289..8b3173d05833 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/ApiServiceImpl.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/ApiServiceImpl.java @@ -193,7 +193,7 @@ private void removeRegister(final ApiDO apiDO) { selectorService.deleteByNamespaceId(selectorIds, SYS_DEFAULT_NAMESPACE_ID); } //clean metadata - Optional.ofNullable(metaDataService.findByPath(path, SYS_DEFAULT_NAMESPACE_ID)) + Optional.ofNullable(metaDataService.findByPathAndNamespaceId(path, SYS_DEFAULT_NAMESPACE_ID)) .ifPresent(metaDataDO -> metaDataService.deleteByIdsAndNamespaceId(Lists.newArrayList(metaDataDO.getId()), SYS_DEFAULT_NAMESPACE_ID)); } diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/MetaDataServiceImpl.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/MetaDataServiceImpl.java index 42f45a954411..fa9444801863 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/MetaDataServiceImpl.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/MetaDataServiceImpl.java @@ -177,12 +177,12 @@ public List listAllData() { } @Override - public MetaDataDO findByPath(final String path, final String namespaceId) { + public MetaDataDO findByPathAndNamespaceId(final String path, final String namespaceId) { return metaDataMapper.findByPathAndNamespaceId(path, namespaceId); } @Override - public MetaDataDO findByServiceNameAndMethodName(final String serviceName, final String methodName, final String namespaceId) { + public MetaDataDO findByServiceNameAndMethodNameAndNamespaceId(final String serviceName, final String methodName, final String namespaceId) { final List metadataList = metaDataMapper.findByServiceNameAndMethodAndNamespaceId(serviceName, methodName, namespaceId); return CollectionUtils.isEmpty(metadataList) ? null : metadataList.get(0); } diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterDivideServiceImpl.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterDivideServiceImpl.java index 8b39480ae164..8a37050a86c7 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterDivideServiceImpl.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterDivideServiceImpl.java @@ -78,7 +78,7 @@ protected String ruleHandler() { protected void registerMetadata(final MetaDataRegisterDTO dto) { if (dto.isRegisterMetaData()) { MetaDataService metaDataService = getMetaDataService(); - MetaDataDO exist = metaDataService.findByPath(dto.getPath(), dto.getNamespaceId()); + MetaDataDO exist = metaDataService.findByPathAndNamespaceId(dto.getPath(), dto.getNamespaceId()); metaDataService.saveOrUpdateMetaData(exist, dto); } } diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterDubboServiceImpl.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterDubboServiceImpl.java index b59a90f83d52..3ca7e0362619 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterDubboServiceImpl.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterDubboServiceImpl.java @@ -64,7 +64,7 @@ protected String ruleHandler() { @Override protected void registerMetadata(final MetaDataRegisterDTO metaDataDTO) { MetaDataService metaDataService = getMetaDataService(); - MetaDataDO exist = metaDataService.findByPath(metaDataDTO.getPath(), metaDataDTO.getNamespaceId()); + MetaDataDO exist = metaDataService.findByPathAndNamespaceId(metaDataDTO.getPath(), metaDataDTO.getNamespaceId()); metaDataService.saveOrUpdateMetaData(exist, metaDataDTO); } diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterGrpcServiceImpl.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterGrpcServiceImpl.java index 612d14a4e2e1..27672e846040 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterGrpcServiceImpl.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterGrpcServiceImpl.java @@ -75,7 +75,7 @@ protected String ruleHandler() { @Override protected void registerMetadata(final MetaDataRegisterDTO metaDataDTO) { MetaDataService metaDataService = getMetaDataService(); - MetaDataDO exist = metaDataService.findByPath(metaDataDTO.getPath(), metaDataDTO.getNamespaceId()); + MetaDataDO exist = metaDataService.findByPathAndNamespaceId(metaDataDTO.getPath(), metaDataDTO.getNamespaceId()); metaDataService.saveOrUpdateMetaData(exist, metaDataDTO); } diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterMotanServiceImpl.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterMotanServiceImpl.java index b8b5fa74f228..a1dd5a22ed5a 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterMotanServiceImpl.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterMotanServiceImpl.java @@ -51,7 +51,7 @@ protected String ruleHandler() { @Override protected void registerMetadata(final MetaDataRegisterDTO metaDataDTO) { MetaDataService metaDataService = getMetaDataService(); - MetaDataDO exist = metaDataService.findByPath(metaDataDTO.getPath(), metaDataDTO.getNamespaceId()); + MetaDataDO exist = metaDataService.findByPathAndNamespaceId(metaDataDTO.getPath(), metaDataDTO.getNamespaceId()); metaDataService.saveOrUpdateMetaData(exist, metaDataDTO); } diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterSofaServiceImpl.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterSofaServiceImpl.java index d685f6a17a81..232280679f22 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterSofaServiceImpl.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterSofaServiceImpl.java @@ -52,7 +52,7 @@ protected String ruleHandler() { @Override protected void registerMetadata(final MetaDataRegisterDTO metaDataDTO) { MetaDataService metaDataService = getMetaDataService(); - MetaDataDO exist = metaDataService.findByServiceNameAndMethodName(metaDataDTO.getServiceName(), metaDataDTO.getMethodName(), metaDataDTO.getNamespaceId()); + MetaDataDO exist = metaDataService.findByServiceNameAndMethodNameAndNamespaceId(metaDataDTO.getServiceName(), metaDataDTO.getMethodName(), metaDataDTO.getNamespaceId()); metaDataService.saveOrUpdateMetaData(exist, metaDataDTO); } diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterSpringCloudServiceImpl.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterSpringCloudServiceImpl.java index b3ccd3a04f2a..39bf2aaa2a8c 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterSpringCloudServiceImpl.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterSpringCloudServiceImpl.java @@ -65,7 +65,7 @@ protected String ruleHandler() { @Override protected void registerMetadata(final MetaDataRegisterDTO metaDataDTO) { MetaDataService metaDataService = getMetaDataService(); - MetaDataDO metaDataDO = metaDataService.findByPath(metaDataDTO.getPath(), metaDataDTO.getNamespaceId()); + MetaDataDO metaDataDO = metaDataService.findByPathAndNamespaceId(metaDataDTO.getPath(), metaDataDTO.getNamespaceId()); metaDataService.saveOrUpdateMetaData(metaDataDO, metaDataDTO); } diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterTarsServiceImpl.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterTarsServiceImpl.java index c8afe4d869e2..2f6fd65b66f3 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterTarsServiceImpl.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterTarsServiceImpl.java @@ -63,7 +63,7 @@ protected String ruleHandler() { @Override protected void registerMetadata(final MetaDataRegisterDTO metaDataDTO) { MetaDataService metaDataService = getMetaDataService(); - MetaDataDO exist = metaDataService.findByServiceNameAndMethodName(metaDataDTO.getServiceName(), metaDataDTO.getMethodName(), metaDataDTO.getNamespaceId()); + MetaDataDO exist = metaDataService.findByServiceNameAndMethodNameAndNamespaceId(metaDataDTO.getServiceName(), metaDataDTO.getMethodName(), metaDataDTO.getNamespaceId()); metaDataService.saveOrUpdateMetaData(exist, metaDataDTO); } diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterWebSocketServiceImpl.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterWebSocketServiceImpl.java index c55236e95f24..2ac96facba1b 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterWebSocketServiceImpl.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterWebSocketServiceImpl.java @@ -71,7 +71,7 @@ protected String ruleHandler() { protected void registerMetadata(final MetaDataRegisterDTO dto) { if (dto.isRegisterMetaData()) { MetaDataService metaDataService = getMetaDataService(); - MetaDataDO exist = metaDataService.findByPath(dto.getPath(), dto.getNamespaceId()); + MetaDataDO exist = metaDataService.findByPathAndNamespaceId(dto.getPath(), dto.getNamespaceId()); metaDataService.saveOrUpdateMetaData(exist, dto); } } diff --git a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/MetaDataServiceTest.java b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/MetaDataServiceTest.java index 3ee25cbc323e..52e98c83f0fc 100644 --- a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/MetaDataServiceTest.java +++ b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/MetaDataServiceTest.java @@ -269,7 +269,7 @@ public void testFindByPath() { .path("path1") .build(); given(this.metaDataMapper.findByPathAndNamespaceId(any(), any())).willReturn(metaDataDO1); - MetaDataDO metaDataDO = metaDataService.findByPath("path1", SYS_DEFAULT_NAMESPACE_ID); + MetaDataDO metaDataDO = metaDataService.findByPathAndNamespaceId("path1", SYS_DEFAULT_NAMESPACE_ID); assertNotNull(metaDataDO); Assertions.assertEquals(metaDataDO, metaDataDO1); } @@ -286,7 +286,7 @@ public void testFindByServiceNameAndMethodName() { given(this.metaDataMapper.findByServiceNameAndMethodAndNamespaceId(any(), any(), any())) .willReturn(Collections.singletonList(metaDataDO1)); MetaDataDO metaDataDO = metaDataService - .findByServiceNameAndMethodName("serviceName1", "method1", SYS_DEFAULT_NAMESPACE_ID); + .findByServiceNameAndMethodNameAndNamespaceId("serviceName1", "method1", SYS_DEFAULT_NAMESPACE_ID); assertNotNull(metaDataDO); Assertions.assertEquals(metaDataDO, metaDataDO1); } diff --git a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterDivideServiceImplTest.java b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterDivideServiceImplTest.java index 558f41351e2c..b3a318fd6e72 100644 --- a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterDivideServiceImplTest.java +++ b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterDivideServiceImplTest.java @@ -92,7 +92,7 @@ public void testRuleHandler() { @Test public void testRegisterMetadata() { MetaDataDO metaDataDO = MetaDataDO.builder().build(); - when(metaDataService.findByPath(any())).thenReturn(metaDataDO); + when(metaDataService.findByPathAndNamespaceId(any())).thenReturn(metaDataDO); MetaDataRegisterDTO metaDataDTO = MetaDataRegisterDTO.builder().registerMetaData(true).build(); shenyuClientRegisterDivideService.registerMetadata(metaDataDTO); verify(metaDataService).saveOrUpdateMetaData(metaDataDO, metaDataDTO); diff --git a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterDubboServiceImplTest.java b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterDubboServiceImplTest.java index 264031161194..e1bbddb28782 100644 --- a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterDubboServiceImplTest.java +++ b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterDubboServiceImplTest.java @@ -83,7 +83,7 @@ public void testRuleHandler() { @Test public void testRegisterMetadata() { MetaDataDO metaDataDO = MetaDataDO.builder().build(); - when(metaDataService.findByPath(any())).thenReturn(metaDataDO); + when(metaDataService.findByPathAndNamespaceId(any())).thenReturn(metaDataDO); MetaDataRegisterDTO metaDataDTO = MetaDataRegisterDTO.builder().registerMetaData(true).build(); shenyuClientRegisterDubboService.registerMetadata(metaDataDTO); verify(metaDataService).saveOrUpdateMetaData(metaDataDO, metaDataDTO); diff --git a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterGrpcServiceImplTest.java b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterGrpcServiceImplTest.java index 4de58f2f33fc..af8bf2de11b6 100644 --- a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterGrpcServiceImplTest.java +++ b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterGrpcServiceImplTest.java @@ -79,10 +79,10 @@ public void testRuleHandler() { @Test public void testRegisterMetadata() { MetaDataDO metaDataDO = MetaDataDO.builder().build(); - when(metaDataService.findByPath(any())).thenReturn(metaDataDO); + when(metaDataService.findByPathAndNamespaceId(any())).thenReturn(metaDataDO); MetaDataRegisterDTO metaDataDTO = MetaDataRegisterDTO.builder().path("/test").build(); shenyuClientRegisterGrpcService.registerMetadata(metaDataDTO); - verify(metaDataService).findByPath("/test"); + verify(metaDataService).findByPathAndNamespaceId("/test"); verify(metaDataService).saveOrUpdateMetaData(metaDataDO, metaDataDTO); } diff --git a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterMotanServiceImplTest.java b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterMotanServiceImplTest.java index a30e5fb867c8..e414df660d9f 100644 --- a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterMotanServiceImplTest.java +++ b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterMotanServiceImplTest.java @@ -73,7 +73,7 @@ public void testRuleHandler() { @Test public void testRegisterMetadata() { MetaDataDO metaDataDO = MetaDataDO.builder().build(); - when(metaDataService.findByPath(any())).thenReturn(metaDataDO); + when(metaDataService.findByPathAndNamespaceId(any())).thenReturn(metaDataDO); MetaDataRegisterDTO metaDataDTO = MetaDataRegisterDTO.builder().build(); shenyuClientRegisterMotanService.registerMetadata(metaDataDTO); verify(metaDataService).saveOrUpdateMetaData(metaDataDO, metaDataDTO); diff --git a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterSofaServiceImplTest.java b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterSofaServiceImplTest.java index b84ce1045d47..e84ba767137f 100644 --- a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterSofaServiceImplTest.java +++ b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterSofaServiceImplTest.java @@ -74,7 +74,7 @@ public void testRuleHandler() { @Test public void testRegisterMetadata() { MetaDataDO metaDataDO = MetaDataDO.builder().build(); - when(metaDataService.findByServiceNameAndMethodName(any(), any(), any())).thenReturn(metaDataDO); + when(metaDataService.findByServiceNameAndMethodNameAndNamespaceId(any(), any(), any())).thenReturn(metaDataDO); MetaDataRegisterDTO metaDataDTO = MetaDataRegisterDTO.builder().build(); shenyuClientRegisterSofaService.registerMetadata(metaDataDTO); verify(metaDataService).saveOrUpdateMetaData(metaDataDO, metaDataDTO); diff --git a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterSpringCloudServiceImplTest.java b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterSpringCloudServiceImplTest.java index 7a32bb23df08..b448dbce0584 100644 --- a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterSpringCloudServiceImplTest.java +++ b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterSpringCloudServiceImplTest.java @@ -89,10 +89,10 @@ public void testRuleHandler() { @Test public void testRegisterMetadata() { MetaDataDO metaDataDO = MetaDataDO.builder().build(); - when(metaDataService.findByPath(any())).thenReturn(metaDataDO); + when(metaDataService.findByPathAndNamespaceId(any())).thenReturn(metaDataDO); MetaDataRegisterDTO metaDataDTO = MetaDataRegisterDTO.builder().path("/contextPath/test").build(); shenyuClientRegisterSpringCloudService.registerMetadata(metaDataDTO); - verify(metaDataService).findByPath("/contextPath/test"); + verify(metaDataService).findByPathAndNamespaceId("/contextPath/test"); verify(metaDataService).saveOrUpdateMetaData(metaDataDO, metaDataDTO); } diff --git a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterTarsServiceImplTest.java b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterTarsServiceImplTest.java index 2c31c4b7fbde..8a7540e8f405 100644 --- a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterTarsServiceImplTest.java +++ b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterTarsServiceImplTest.java @@ -82,11 +82,11 @@ public void testRegisterMetadata() { MetaDataDO metaDataDO = MetaDataDO.builder().build(); String serviceName = "metaDataService"; String methodName = "registerMetadata"; - when(metaDataService.findByServiceNameAndMethodName(any(), any(), any())).thenReturn(metaDataDO); + when(metaDataService.findByServiceNameAndMethodNameAndNamespaceId(any(), any(), any())).thenReturn(metaDataDO); MetaDataRegisterDTO metaDataDTO = MetaDataRegisterDTO.builder().serviceName(serviceName) .methodName(methodName).build(); shenyuClientRegisterTarsService.registerMetadata(metaDataDTO); - verify(metaDataService).findByServiceNameAndMethodName(serviceName, methodName, SYS_DEFAULT_NAMESPACE_ID); + verify(metaDataService).findByServiceNameAndMethodNameAndNamespaceId(serviceName, methodName, SYS_DEFAULT_NAMESPACE_ID); verify(metaDataService).saveOrUpdateMetaData(metaDataDO, metaDataDTO); } diff --git a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterWebSocketServiceImplTest.java b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterWebSocketServiceImplTest.java index 21f0935ecc18..99c4d55b5a14 100644 --- a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterWebSocketServiceImplTest.java +++ b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterWebSocketServiceImplTest.java @@ -81,7 +81,7 @@ public void testRuleHandler() { @Test public void testRegisterMetadata() { MetaDataDO metaDataDO = MetaDataDO.builder().build(); - when(metaDataService.findByPath(any())).thenReturn(metaDataDO); + when(metaDataService.findByPathAndNamespaceId(any())).thenReturn(metaDataDO); MetaDataRegisterDTO metaDataDTO = MetaDataRegisterDTO.builder().registerMetaData(true).build(); shenyuClientRegisterWebSocketService.registerMetadata(metaDataDTO); verify(metaDataService).saveOrUpdateMetaData(metaDataDO, metaDataDTO); From fd8adab71b3a6b136e091b31eb7066584c2d814f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=98xcsnx=E2=80=99?= <‘1192709687@qq.com’> Date: Sun, 18 Aug 2024 16:37:45 +0800 Subject: [PATCH 48/61] commit --- .../admin/controller/MetaDataController.java | 8 ++------ .../shenyu/admin/model/entity/MetaDataDO.java | 4 ++-- .../metadata/BatchMetaDataChangedEvent.java | 18 +++++++++++++----- .../metadata/BatchMetaDataDeletedEvent.java | 11 +---------- .../event/metadata/MetaDataChangedEvent.java | 6 ++++-- .../event/rule/BatchRuleDeletedEvent.java | 10 +++++++++- .../model/event/rule/RuleChangedEvent.java | 4 ++-- .../selector/BatchSelectorDeletedEvent.java | 9 ++++++++- .../shenyu/admin/model/vo/MetaDataVO.java | 2 +- .../resources/mappers/meta-data-sqlmap.xml | 3 ++- .../src/main/resources/mappers/rule-sqlmap.xml | 3 ++- ...nyuClientRegisterDivideServiceImplTest.java | 2 +- ...enyuClientRegisterDubboServiceImplTest.java | 2 +- ...henyuClientRegisterGrpcServiceImplTest.java | 5 +++-- ...enyuClientRegisterMotanServiceImplTest.java | 2 +- ...ientRegisterSpringCloudServiceImplTest.java | 5 +++-- ...ClientRegisterWebSocketServiceImplTest.java | 6 +++--- 17 files changed, 58 insertions(+), 42 deletions(-) diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/controller/MetaDataController.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/controller/MetaDataController.java index 0d26fdb02d74..a6cbe86cfc5d 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/controller/MetaDataController.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/controller/MetaDataController.java @@ -17,6 +17,8 @@ package org.apache.shenyu.admin.controller; +import jakarta.validation.Valid; +import jakarta.validation.constraints.NotNull; import org.apache.commons.lang3.StringUtils; import org.apache.shenyu.admin.aspect.annotation.RestApi; import org.apache.shenyu.admin.mapper.NamespaceMapper; @@ -40,12 +42,6 @@ import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestParam; -import jakarta.validation.Valid; -import jakarta.validation.constraints.NotBlank; -import jakarta.validation.constraints.NotEmpty; -import jakarta.validation.constraints.NotNull; -import java.util.List; - /** * The type Meta data controller. */ diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/entity/MetaDataDO.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/entity/MetaDataDO.java index 2eda83833d79..6190b4e5c381 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/entity/MetaDataDO.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/entity/MetaDataDO.java @@ -294,8 +294,8 @@ public boolean equals(final Object o) { @Override public int hashCode() { - return Objects.hash(super.hashCode(), appName, path, pathDesc, rpcType, serviceName, methodName, parameterTypes, rpcExt, enabled - , namespaceId); + return Objects.hash(super.hashCode(), appName, path, pathDesc, rpcType, serviceName, methodName, parameterTypes, + rpcExt, enabled, namespaceId); } public static final class MetaDataDOBuilder { diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/event/metadata/BatchMetaDataChangedEvent.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/event/metadata/BatchMetaDataChangedEvent.java index e6f52bc6a637..6afd2dc594a5 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/event/metadata/BatchMetaDataChangedEvent.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/event/metadata/BatchMetaDataChangedEvent.java @@ -23,14 +23,17 @@ import org.apache.shenyu.admin.model.event.BatchChangedEvent; import java.util.Collection; +import java.util.Optional; import java.util.stream.Collectors; +import static org.apache.shenyu.common.constant.AdminConstants.SYS_DEFAULT_NAMESPACE_ID; + /** * BatchMetaDataChangedEvent. */ public class BatchMetaDataChangedEvent extends BatchChangedEvent { - - + + /** * Create a new {@code BatchMetaDataChangedEvent}.operator is unknown. * @@ -42,16 +45,21 @@ public class BatchMetaDataChangedEvent extends BatchChangedEvent { public BatchMetaDataChangedEvent(final Collection source, final Collection before, final EventTypeEnum type, final String operator) { super(source, before, type, operator); } - + @Override public String buildContext() { final String metadata = ((Collection) getSource()) .stream() .map(s -> ((MetaDataDO) s).getAppName()) .collect(Collectors.joining(",")); - return String.format("the meta data [%s] is %s", metadata, StringUtils.lowerCase(getType().getType().toString())); + final String namespaceId = ((Collection) getSource()) + .stream() + .filter(s -> StringUtils.isNotEmpty(((MetaDataDO) s).getNamespaceId())) + .map(s -> ((MetaDataDO) s).getNamespaceId()) + .findAny().orElse(SYS_DEFAULT_NAMESPACE_ID); + return String.format("the namespace [%s] meta data [%s] is %s", namespaceId, metadata, StringUtils.lowerCase(getType().getType().toString())); } - + @Override public String eventName() { return "meta data"; diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/event/metadata/BatchMetaDataDeletedEvent.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/event/metadata/BatchMetaDataDeletedEvent.java index 7cf418d4bc06..d6f3d20db403 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/event/metadata/BatchMetaDataDeletedEvent.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/event/metadata/BatchMetaDataDeletedEvent.java @@ -44,16 +44,7 @@ public BatchMetaDataDeletedEvent(final Collection source, final Stri super(source, null, EventTypeEnum.META_DATA_DELETE, operator); this.deletedIds = ListUtil.map(source, BaseDO::getId); } - - @Override - public String buildContext() { - final String metaData = ((Collection) getSource()) - .stream() - .map(s -> ((MetaDataDO) s).getAppName()) - .collect(Collectors.joining(",")); - return String.format("the meta data [%s] is %s", metaData, StringUtils.lowerCase(getType().getType().toString())); - } - + /** * get deleted iss. * diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/event/metadata/MetaDataChangedEvent.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/event/metadata/MetaDataChangedEvent.java index 44e303ba5156..0a1c01198417 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/event/metadata/MetaDataChangedEvent.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/event/metadata/MetaDataChangedEvent.java @@ -46,9 +46,11 @@ public MetaDataChangedEvent(final MetaDataDO source, final MetaDataDO before, fi public String buildContext() { final MetaDataDO after = (MetaDataDO) getAfter(); if (Objects.isNull(getBefore())) { - return String.format("the namespace [%s] metadata [%s %s] is %s", after.getNamespaceId(), after.getAppName(), after.getPath(), StringUtils.lowerCase(getType().getType().toString())); + return String.format("the namespace [%s] metadata [%s %s] is %s", after.getNamespaceId(), after.getAppName(), + after.getPath(), StringUtils.lowerCase(getType().getType().toString())); } - return String.format("the namespace [%s] metadata [%s %s] is %s : %s", after.getNamespaceId(), after.getAppName(), after.getPath(), StringUtils.lowerCase(getType().getType().toString()), contrast()); + return String.format("the namespace [%s] metadata [%s %s] is %s : %s", after.getNamespaceId(), after.getAppName(), + after.getPath(), StringUtils.lowerCase(getType().getType().toString()), contrast()); } diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/event/rule/BatchRuleDeletedEvent.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/event/rule/BatchRuleDeletedEvent.java index 7d22317fbc18..1db267c76a35 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/event/rule/BatchRuleDeletedEvent.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/event/rule/BatchRuleDeletedEvent.java @@ -21,6 +21,7 @@ import org.apache.shenyu.admin.model.entity.BaseDO; import org.apache.shenyu.admin.model.entity.PluginDO; import org.apache.shenyu.admin.model.entity.RuleDO; +import org.apache.shenyu.admin.model.entity.SelectorDO; import org.apache.shenyu.admin.model.enums.EventTypeEnum; import org.apache.shenyu.admin.model.event.BatchChangedEvent; import org.apache.shenyu.common.utils.ListUtil; @@ -29,6 +30,8 @@ import java.util.List; import java.util.stream.Collectors; +import static org.apache.shenyu.common.constant.AdminConstants.SYS_DEFAULT_NAMESPACE_ID; + /** * BatchRuleDeletedEvent. */ @@ -57,7 +60,12 @@ public String buildContext() { .stream() .map(s -> ((RuleDO) s).getName()) .collect(Collectors.joining(",")); - return String.format("the rule[%s] is %s", selector, StringUtils.lowerCase(getType().getType().toString())); + final String namespaceId = ((Collection) getSource()) + .stream() + .filter(s -> StringUtils.isNotEmpty(((RuleDO) s).getNamespaceId())) + .map(s -> ((RuleDO) s).getNamespaceId()) + .findAny().orElse(SYS_DEFAULT_NAMESPACE_ID); + return String.format("the namespace [%s] rule[%s] is %s", namespaceId, selector, StringUtils.lowerCase(getType().getType().toString())); } /** diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/event/rule/RuleChangedEvent.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/event/rule/RuleChangedEvent.java index 39c49304b569..251d25c9a3db 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/event/rule/RuleChangedEvent.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/event/rule/RuleChangedEvent.java @@ -46,9 +46,9 @@ public RuleChangedEvent(final RuleDO source, final RuleDO before, final EventTyp public String buildContext() { final RuleDO after = (RuleDO) getAfter(); if (Objects.isNull(getBefore())) { - return String.format("the rule [%s] is %s", after.getName(), StringUtils.lowerCase(getType().getType().toString())); + return String.format("the namespace [%s] rule [%s] is %s", after.getNamespaceId(), after.getName(), StringUtils.lowerCase(getType().getType().toString())); } - return String.format("the rule [%s] is %s : %s", after.getName(), StringUtils.lowerCase(getType().getType().toString()), contrast()); + return String.format("the namespace [%s] rule [%s] is %s : %s", after.getNamespaceId(), after.getName(), StringUtils.lowerCase(getType().getType().toString()), contrast()); } diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/event/selector/BatchSelectorDeletedEvent.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/event/selector/BatchSelectorDeletedEvent.java index 54bbc9d2328d..9c87c9801b9b 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/event/selector/BatchSelectorDeletedEvent.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/event/selector/BatchSelectorDeletedEvent.java @@ -31,6 +31,8 @@ import java.util.Optional; import java.util.stream.Collectors; +import static org.apache.shenyu.common.constant.AdminConstants.SYS_DEFAULT_NAMESPACE_ID; + /** * BatchPluginDeletedEvent. */ @@ -66,7 +68,12 @@ public String buildContext() { .stream() .map(s -> ((SelectorDO) s).getName()) .collect(Collectors.joining(",")); - return String.format("the selector[%s] is %s", selector, StringUtils.lowerCase(getType().getType().toString())); + final String namespaceId = ((Collection) getSource()) + .stream() + .filter(s -> StringUtils.isNotEmpty(((SelectorDO) s).getNamespaceId())) + .map(s -> ((SelectorDO) s).getNamespaceId()) + .findAny().orElse(SYS_DEFAULT_NAMESPACE_ID); + return String.format("the namespace [%s] selector[%s] is %s", namespaceId, selector, StringUtils.lowerCase(getType().getType().toString())); } /** diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/vo/MetaDataVO.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/vo/MetaDataVO.java index d28fe9177717..b9f01a337489 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/vo/MetaDataVO.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/vo/MetaDataVO.java @@ -373,7 +373,7 @@ public String toString() { + ", id='" + id + '\'' + ", dateCreated='" + dateCreated + '\'' + ", dateUpdated='" + dateUpdated + '\'' - + ", enabled=" + enabled+ '\'' + + ", enabled=" + enabled + '\'' + ", namespaceId=" + namespaceId + '}'; } diff --git a/shenyu-admin/src/main/resources/mappers/meta-data-sqlmap.xml b/shenyu-admin/src/main/resources/mappers/meta-data-sqlmap.xml index b289ae450e6a..e7b5a01a954e 100644 --- a/shenyu-admin/src/main/resources/mappers/meta-data-sqlmap.xml +++ b/shenyu-admin/src/main/resources/mappers/meta-data-sqlmap.xml @@ -45,7 +45,8 @@ method_name, parameter_types, rpc_ext, - enabled + enabled, + namespace_id diff --git a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterDivideServiceImplTest.java b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterDivideServiceImplTest.java index b3a318fd6e72..d7c205f0e146 100644 --- a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterDivideServiceImplTest.java +++ b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterDivideServiceImplTest.java @@ -92,7 +92,7 @@ public void testRuleHandler() { @Test public void testRegisterMetadata() { MetaDataDO metaDataDO = MetaDataDO.builder().build(); - when(metaDataService.findByPathAndNamespaceId(any())).thenReturn(metaDataDO); + when(metaDataService.findByPathAndNamespaceId(any(), any())).thenReturn(metaDataDO); MetaDataRegisterDTO metaDataDTO = MetaDataRegisterDTO.builder().registerMetaData(true).build(); shenyuClientRegisterDivideService.registerMetadata(metaDataDTO); verify(metaDataService).saveOrUpdateMetaData(metaDataDO, metaDataDTO); diff --git a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterDubboServiceImplTest.java b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterDubboServiceImplTest.java index e1bbddb28782..783e3cdbe80f 100644 --- a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterDubboServiceImplTest.java +++ b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterDubboServiceImplTest.java @@ -83,7 +83,7 @@ public void testRuleHandler() { @Test public void testRegisterMetadata() { MetaDataDO metaDataDO = MetaDataDO.builder().build(); - when(metaDataService.findByPathAndNamespaceId(any())).thenReturn(metaDataDO); + when(metaDataService.findByPathAndNamespaceId(any(), any())).thenReturn(metaDataDO); MetaDataRegisterDTO metaDataDTO = MetaDataRegisterDTO.builder().registerMetaData(true).build(); shenyuClientRegisterDubboService.registerMetadata(metaDataDTO); verify(metaDataService).saveOrUpdateMetaData(metaDataDO, metaDataDTO); diff --git a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterGrpcServiceImplTest.java b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterGrpcServiceImplTest.java index af8bf2de11b6..73359ebd9c01 100644 --- a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterGrpcServiceImplTest.java +++ b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterGrpcServiceImplTest.java @@ -39,6 +39,7 @@ import java.util.ArrayList; import java.util.List; +import static org.apache.shenyu.common.constant.AdminConstants.SYS_DEFAULT_NAMESPACE_ID; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doReturn; @@ -79,10 +80,10 @@ public void testRuleHandler() { @Test public void testRegisterMetadata() { MetaDataDO metaDataDO = MetaDataDO.builder().build(); - when(metaDataService.findByPathAndNamespaceId(any())).thenReturn(metaDataDO); + when(metaDataService.findByPathAndNamespaceId(any(), any())).thenReturn(metaDataDO); MetaDataRegisterDTO metaDataDTO = MetaDataRegisterDTO.builder().path("/test").build(); shenyuClientRegisterGrpcService.registerMetadata(metaDataDTO); - verify(metaDataService).findByPathAndNamespaceId("/test"); + verify(metaDataService).findByPathAndNamespaceId("/test", SYS_DEFAULT_NAMESPACE_ID); verify(metaDataService).saveOrUpdateMetaData(metaDataDO, metaDataDTO); } diff --git a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterMotanServiceImplTest.java b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterMotanServiceImplTest.java index e414df660d9f..31358fb06bb3 100644 --- a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterMotanServiceImplTest.java +++ b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterMotanServiceImplTest.java @@ -73,7 +73,7 @@ public void testRuleHandler() { @Test public void testRegisterMetadata() { MetaDataDO metaDataDO = MetaDataDO.builder().build(); - when(metaDataService.findByPathAndNamespaceId(any())).thenReturn(metaDataDO); + when(metaDataService.findByPathAndNamespaceId(any(), any())).thenReturn(metaDataDO); MetaDataRegisterDTO metaDataDTO = MetaDataRegisterDTO.builder().build(); shenyuClientRegisterMotanService.registerMetadata(metaDataDTO); verify(metaDataService).saveOrUpdateMetaData(metaDataDO, metaDataDTO); diff --git a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterSpringCloudServiceImplTest.java b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterSpringCloudServiceImplTest.java index b448dbce0584..2ec364a90683 100644 --- a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterSpringCloudServiceImplTest.java +++ b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterSpringCloudServiceImplTest.java @@ -40,6 +40,7 @@ import java.util.ArrayList; import java.util.List; +import static org.apache.shenyu.common.constant.AdminConstants.SYS_DEFAULT_NAMESPACE_ID; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doReturn; @@ -89,10 +90,10 @@ public void testRuleHandler() { @Test public void testRegisterMetadata() { MetaDataDO metaDataDO = MetaDataDO.builder().build(); - when(metaDataService.findByPathAndNamespaceId(any())).thenReturn(metaDataDO); + when(metaDataService.findByPathAndNamespaceId(any(), any())).thenReturn(metaDataDO); MetaDataRegisterDTO metaDataDTO = MetaDataRegisterDTO.builder().path("/contextPath/test").build(); shenyuClientRegisterSpringCloudService.registerMetadata(metaDataDTO); - verify(metaDataService).findByPathAndNamespaceId("/contextPath/test"); + verify(metaDataService).findByPathAndNamespaceId("/contextPath/test", SYS_DEFAULT_NAMESPACE_ID); verify(metaDataService).saveOrUpdateMetaData(metaDataDO, metaDataDTO); } diff --git a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterWebSocketServiceImplTest.java b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterWebSocketServiceImplTest.java index 99c4d55b5a14..3da5ab7cc85c 100644 --- a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterWebSocketServiceImplTest.java +++ b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterWebSocketServiceImplTest.java @@ -42,9 +42,9 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.when; -import static org.mockito.Mockito.verify; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; /** * Test cases for ShenyuClientRegisterWebSocketServiceImpl. @@ -81,7 +81,7 @@ public void testRuleHandler() { @Test public void testRegisterMetadata() { MetaDataDO metaDataDO = MetaDataDO.builder().build(); - when(metaDataService.findByPathAndNamespaceId(any())).thenReturn(metaDataDO); + when(metaDataService.findByPathAndNamespaceId(any(), any())).thenReturn(metaDataDO); MetaDataRegisterDTO metaDataDTO = MetaDataRegisterDTO.builder().registerMetaData(true).build(); shenyuClientRegisterWebSocketService.registerMetadata(metaDataDTO); verify(metaDataService).saveOrUpdateMetaData(metaDataDO, metaDataDTO); From ee63da50d1dae5806ff4b7e613d2787d139e23d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=98xcsnx=E2=80=99?= <‘1192709687@qq.com’> Date: Sun, 18 Aug 2024 16:40:48 +0800 Subject: [PATCH 49/61] fix --- .../admin/model/event/metadata/BatchMetaDataChangedEvent.java | 1 - .../admin/model/event/metadata/BatchMetaDataDeletedEvent.java | 2 -- .../shenyu/admin/model/event/rule/BatchRuleDeletedEvent.java | 1 - 3 files changed, 4 deletions(-) diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/event/metadata/BatchMetaDataChangedEvent.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/event/metadata/BatchMetaDataChangedEvent.java index 6afd2dc594a5..db6a98b29ed8 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/event/metadata/BatchMetaDataChangedEvent.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/event/metadata/BatchMetaDataChangedEvent.java @@ -23,7 +23,6 @@ import org.apache.shenyu.admin.model.event.BatchChangedEvent; import java.util.Collection; -import java.util.Optional; import java.util.stream.Collectors; import static org.apache.shenyu.common.constant.AdminConstants.SYS_DEFAULT_NAMESPACE_ID; diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/event/metadata/BatchMetaDataDeletedEvent.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/event/metadata/BatchMetaDataDeletedEvent.java index d6f3d20db403..2bc6f5a05b0a 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/event/metadata/BatchMetaDataDeletedEvent.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/event/metadata/BatchMetaDataDeletedEvent.java @@ -17,7 +17,6 @@ package org.apache.shenyu.admin.model.event.metadata; -import org.apache.commons.lang3.StringUtils; import org.apache.shenyu.admin.model.entity.BaseDO; import org.apache.shenyu.admin.model.entity.MetaDataDO; import org.apache.shenyu.admin.model.enums.EventTypeEnum; @@ -25,7 +24,6 @@ import java.util.Collection; import java.util.List; -import java.util.stream.Collectors; /** * BatchMetaDataDeletedEvent. diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/event/rule/BatchRuleDeletedEvent.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/event/rule/BatchRuleDeletedEvent.java index 1db267c76a35..0526802fc69a 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/event/rule/BatchRuleDeletedEvent.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/event/rule/BatchRuleDeletedEvent.java @@ -21,7 +21,6 @@ import org.apache.shenyu.admin.model.entity.BaseDO; import org.apache.shenyu.admin.model.entity.PluginDO; import org.apache.shenyu.admin.model.entity.RuleDO; -import org.apache.shenyu.admin.model.entity.SelectorDO; import org.apache.shenyu.admin.model.enums.EventTypeEnum; import org.apache.shenyu.admin.model.event.BatchChangedEvent; import org.apache.shenyu.common.utils.ListUtil; From afeacf61e1c334f6999e9c02f1a52df88e68d47e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=98xcsnx=E2=80=99?= <‘1192709687@qq.com’> Date: Sun, 18 Aug 2024 16:59:22 +0800 Subject: [PATCH 50/61] fix --- .../shenyu/e2e/model/data/MetaData.java | 45 ++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/shenyu-e2e/shenyu-e2e-common/src/main/java/org/apache/shenyu/e2e/model/data/MetaData.java b/shenyu-e2e/shenyu-e2e-common/src/main/java/org/apache/shenyu/e2e/model/data/MetaData.java index 537c5d6dd1a2..6ec51052e10a 100644 --- a/shenyu-e2e/shenyu-e2e-common/src/main/java/org/apache/shenyu/e2e/model/data/MetaData.java +++ b/shenyu-e2e/shenyu-e2e-common/src/main/java/org/apache/shenyu/e2e/model/data/MetaData.java @@ -76,6 +76,11 @@ public class MetaData { */ private Boolean enabled; + /** + * namespaceId. + */ + private String namespaceId; + /** * no args constructor. */ @@ -95,9 +100,10 @@ public MetaData() { * @param parameterTypes parameterTypes * @param rpcExt rpcExt * @param enabled enabled + * @param namespaceId namespaceId */ public MetaData(final String id, final String appName, final String contextPath, final String path, final String rpcType, final String serviceName, - final String methodName, final String parameterTypes, final String rpcExt, final Boolean enabled) { + final String methodName, final String parameterTypes, final String rpcExt, final Boolean enabled, final String namespaceId) { this.id = id; this.appName = appName; this.contextPath = contextPath; @@ -108,6 +114,7 @@ public MetaData(final String id, final String appName, final String contextPath, this.parameterTypes = parameterTypes; this.rpcExt = rpcExt; this.enabled = enabled; + this.namespaceId = namespaceId; } /** @@ -317,6 +324,24 @@ public void setEnabled(final Boolean enabled) { this.enabled = enabled; } + /** + * get namespaceId. + * + * @return namespaceId + */ + public String getNamespaceId() { + return namespaceId; + } + + /** + * set namespaceId. + * + * @param namespaceId namespaceId + */ + public void setNamespaceId(final String namespaceId) { + this.namespaceId = namespaceId; + } + @Override public boolean equals(final Object o) { if (this == o) { @@ -369,6 +394,8 @@ public String toString() { + '\'' + ", enabled=" + enabled + + ", namespaceId=" + + namespaceId + '}'; } @@ -437,6 +464,11 @@ public static final class Builder { */ private Boolean enabled; + /** + * namespaceId. + */ + private String namespaceId; + /** * no args constructor. */ @@ -561,5 +593,16 @@ public Builder enabled(final Boolean enabled) { this.enabled = enabled; return this; } + + /** + * build namespaceId. + * + * @param namespaceId namespaceId + * @return this + */ + public Builder namespaceId(final String namespaceId) { + this.namespaceId = namespaceId; + return this; + } } } From 848be3fc362c2904b80b079ad2da79afe4899ec0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=98xcsnx=E2=80=99?= <‘1192709687@qq.com’> Date: Mon, 19 Aug 2024 01:05:42 +0800 Subject: [PATCH 51/61] fix unit test --- .../controller/MetaDataControllerTest.java | 27 ++++++++++++++++--- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/shenyu-admin/src/test/java/org/apache/shenyu/admin/controller/MetaDataControllerTest.java b/shenyu-admin/src/test/java/org/apache/shenyu/admin/controller/MetaDataControllerTest.java index 86c62a4859fd..217e26bffcc5 100644 --- a/shenyu-admin/src/test/java/org/apache/shenyu/admin/controller/MetaDataControllerTest.java +++ b/shenyu-admin/src/test/java/org/apache/shenyu/admin/controller/MetaDataControllerTest.java @@ -20,7 +20,9 @@ import org.apache.commons.lang3.StringUtils; import org.apache.shenyu.admin.exception.ExceptionHandlers; import org.apache.shenyu.admin.mapper.MetaDataMapper; +import org.apache.shenyu.admin.mapper.NamespaceMapper; import org.apache.shenyu.admin.model.dto.BatchCommonDTO; +import org.apache.shenyu.admin.model.dto.BatchNamespaceCommonDTO; import org.apache.shenyu.admin.model.dto.MetaDataDTO; import org.apache.shenyu.admin.model.page.CommonPager; import org.apache.shenyu.admin.model.page.PageParameter; @@ -79,6 +81,9 @@ public final class MetaDataControllerTest { @Mock private MetaDataMapper metaDataMapper; + @Mock + private NamespaceMapper namespaceMapper; + private final MetaDataVO metaDataVO = new MetaDataVO("appName", "appPath", "desc", "rpcType", "serviceName", "methodName", "types", "rpcExt", "1", DateUtils.localDateTimeToString(LocalDateTime.now()), DateUtils.localDateTimeToString(LocalDateTime.now()), true, SYS_DEFAULT_NAMESPACE_ID); @@ -103,7 +108,8 @@ public void testQueryList() throws Exception { this.mockMvc.perform(MockMvcRequestBuilders.get("/meta-data/queryList") .param("path", "path") .param("currentPage", String.valueOf(pageParameter.getCurrentPage())) - .param("pageSize", String.valueOf(pageParameter.getPageSize()))) + .param("pageSize", String.valueOf(pageParameter.getPageSize())) + .param("namespaceId", SYS_DEFAULT_NAMESPACE_ID)) .andExpect(status().isOk()) .andExpect(jsonPath("$.message", is(ShenyuResultMessage.QUERY_SUCCESS))) .andExpect(jsonPath("$.data.dataList[0].appName", is(metaDataVO.getAppName()))) @@ -140,7 +146,7 @@ public void testFindAllGroup() throws Exception { @Test public void testEditor() throws Exception { given(this.metaDataService.findByIdAndNamespaceId("1", SYS_DEFAULT_NAMESPACE_ID)).willReturn(metaDataVO); - this.mockMvc.perform(MockMvcRequestBuilders.get("/meta-data/{id}", "1")) + this.mockMvc.perform(MockMvcRequestBuilders.get("/meta-data/{id}/{namespaceId}", "1", SYS_DEFAULT_NAMESPACE_ID)) .andExpect(status().isOk()) .andExpect(jsonPath("$.message", is(ShenyuResultMessage.DETAIL_SUCCESS))) .andExpect(jsonPath("$.data.appName", is(metaDataVO.getAppName()))) @@ -159,10 +165,13 @@ public void testCreateOrUpdate() throws Exception { metaDataDTO.setServiceName("serviceName"); metaDataDTO.setRuleName("ruleName"); metaDataDTO.setEnabled(false); + metaDataDTO.setNamespaceId(SYS_DEFAULT_NAMESPACE_ID); SpringBeanUtils.getInstance().setApplicationContext(mock(ConfigurableApplicationContext.class)); when(SpringBeanUtils.getInstance().getBean(MetaDataMapper.class)).thenReturn(metaDataMapper); when(metaDataMapper.existed(metaDataDTO.getId())).thenReturn(true); given(this.metaDataService.createOrUpdate(metaDataDTO)).willReturn(ShenyuResultMessage.UPDATE_SUCCESS); + when(SpringBeanUtils.getInstance().getBean(NamespaceMapper.class)).thenReturn(namespaceMapper); + when(namespaceMapper.existed(SYS_DEFAULT_NAMESPACE_ID)).thenReturn(true); this.mockMvc.perform(MockMvcRequestBuilders.post("/meta-data/createOrUpdate") .contentType(MediaType.APPLICATION_JSON) .content(GsonUtils.getInstance().toJson(metaDataDTO))) @@ -183,9 +192,12 @@ public void testCreateOrUpdateWithError() throws Exception { metaDataDTO.setServiceName("serviceName"); metaDataDTO.setRuleName("ruleName"); metaDataDTO.setEnabled(false); + metaDataDTO.setNamespaceId(SYS_DEFAULT_NAMESPACE_ID); SpringBeanUtils.getInstance().setApplicationContext(mock(ConfigurableApplicationContext.class)); when(SpringBeanUtils.getInstance().getBean(MetaDataMapper.class)).thenReturn(metaDataMapper); when(metaDataMapper.existed(metaDataDTO.getId())).thenReturn(null); + when(SpringBeanUtils.getInstance().getBean(NamespaceMapper.class)).thenReturn(namespaceMapper); + when(namespaceMapper.existed(SYS_DEFAULT_NAMESPACE_ID)).thenReturn(true); this.mockMvc.perform(MockMvcRequestBuilders.post("/meta-data/createOrUpdate") .contentType(MediaType.APPLICATION_JSON) .content(GsonUtils.getInstance().toJson(metaDataDTO))) @@ -200,10 +212,16 @@ public void testBatchDeleted() throws Exception { final List ids = new ArrayList<>(2); ids.add("1"); ids.add("2"); + SpringBeanUtils.getInstance().setApplicationContext(mock(ConfigurableApplicationContext.class)); given(this.metaDataService.deleteByIdsAndNamespaceId(ids, SYS_DEFAULT_NAMESPACE_ID)).willReturn(2); - this.mockMvc.perform(MockMvcRequestBuilders.post("/meta-data/batchDeleted") + when(SpringBeanUtils.getInstance().getBean(NamespaceMapper.class)).thenReturn(namespaceMapper); + when(namespaceMapper.existed(SYS_DEFAULT_NAMESPACE_ID)).thenReturn(true); + final BatchNamespaceCommonDTO batchNamespaceCommonDTO = new BatchNamespaceCommonDTO(); + batchNamespaceCommonDTO.setNamespaceId(SYS_DEFAULT_NAMESPACE_ID); + batchNamespaceCommonDTO.setIds(ids); + this.mockMvc.perform(MockMvcRequestBuilders.delete("/meta-data/batchDeleted") .contentType(MediaType.APPLICATION_JSON) - .content(GsonUtils.getInstance().toJson(ids))) + .content(GsonUtils.getInstance().toJson(batchNamespaceCommonDTO))) .andExpect(status().isOk()) .andExpect(jsonPath("$.message", is(ShenyuResultMessage.DELETE_SUCCESS))) .andExpect(jsonPath("$.data", is(2))) @@ -229,6 +247,7 @@ public void testBatchEnabledWithError() throws Exception { final BatchCommonDTO batchCommonDTO = new BatchCommonDTO(); batchCommonDTO.setIds(Arrays.asList("1", "2")); batchCommonDTO.setEnabled(true); + batchCommonDTO.setNamespaceId(SYS_DEFAULT_NAMESPACE_ID); given(this.metaDataService.enabledByIdsAndNamespaceId(batchCommonDTO.getIds(), batchCommonDTO.getEnabled(), SYS_DEFAULT_NAMESPACE_ID)).willReturn(AdminConstants.ID_NOT_EXIST); this.mockMvc.perform(MockMvcRequestBuilders.post("/meta-data/batchEnabled") .contentType(MediaType.APPLICATION_JSON) From ba96d5c45a587e99e5458d42f30fdeea9cd5af9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=98xcsnx=E2=80=99?= <‘1192709687@qq.com’> Date: Mon, 19 Aug 2024 12:45:44 +0800 Subject: [PATCH 52/61] fix unit test --- shenyu-admin/src/main/resources/mappers/rule-sqlmap.xml | 6 ++++-- shenyu-admin/src/main/resources/sql-script/h2/schema.sql | 2 +- .../org/apache/shenyu/admin/mapper/MetaDataMapperTest.java | 1 + .../java/org/apache/shenyu/admin/mapper/RuleMapperTest.java | 1 + 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/shenyu-admin/src/main/resources/mappers/rule-sqlmap.xml b/shenyu-admin/src/main/resources/mappers/rule-sqlmap.xml index e3f7c5bb552a..973c42c20ae9 100644 --- a/shenyu-admin/src/main/resources/mappers/rule-sqlmap.xml +++ b/shenyu-admin/src/main/resources/mappers/rule-sqlmap.xml @@ -204,7 +204,8 @@ enabled, loged, match_restful, - handle) + handle, + namespace_id) VALUES (#{id, jdbcType=VARCHAR}, #{dateCreated, jdbcType=TIMESTAMP}, #{dateUpdated, jdbcType=TIMESTAMP}, @@ -215,7 +216,8 @@ #{enabled, jdbcType=TINYINT}, #{loged, jdbcType=TINYINT}, #{matchRestful, jdbcType=TINYINT}, - #{handle, jdbcType=VARCHAR}) + #{handle, jdbcType=VARCHAR}, + #{namespaceId, jdbcType=VARCHAR}) diff --git a/shenyu-admin/src/main/resources/sql-script/h2/schema.sql b/shenyu-admin/src/main/resources/sql-script/h2/schema.sql index 41c0d8bf729a..44b32c9c2c8e 100755 --- a/shenyu-admin/src/main/resources/sql-script/h2/schema.sql +++ b/shenyu-admin/src/main/resources/sql-script/h2/schema.sql @@ -1346,4 +1346,4 @@ ALTER TABLE `selector` ADD COLUMN `namespace_id` varchar(50) NULL COMMENT 'names ALTER TABLE `rule` ADD COLUMN `namespace_id` varchar(50) NULL COMMENT 'namespaceId' AFTER `match_restful`; -ALTER TABLE `meta_data` ADD COLUMN `namespace_id` varchar(50) NULL COMMENT 'namespaceId' AFTER `match_restful`; \ No newline at end of file +ALTER TABLE `meta_data` ADD COLUMN `namespace_id` varchar(50) NULL COMMENT 'namespaceId' ; \ No newline at end of file diff --git a/shenyu-admin/src/test/java/org/apache/shenyu/admin/mapper/MetaDataMapperTest.java b/shenyu-admin/src/test/java/org/apache/shenyu/admin/mapper/MetaDataMapperTest.java index 36e1d460e270..7354f3f36144 100644 --- a/shenyu-admin/src/test/java/org/apache/shenyu/admin/mapper/MetaDataMapperTest.java +++ b/shenyu-admin/src/test/java/org/apache/shenyu/admin/mapper/MetaDataMapperTest.java @@ -251,6 +251,7 @@ private MetaDataDO getMetaDataDO() { .id(UUIDUtils.getInstance().generateShortUuid()) .dateUpdated(now) .dateCreated(now) + .namespaceId(SYS_DEFAULT_NAMESPACE_ID) .build(); } diff --git a/shenyu-admin/src/test/java/org/apache/shenyu/admin/mapper/RuleMapperTest.java b/shenyu-admin/src/test/java/org/apache/shenyu/admin/mapper/RuleMapperTest.java index 058f79d658fc..4142be797ef5 100644 --- a/shenyu-admin/src/test/java/org/apache/shenyu/admin/mapper/RuleMapperTest.java +++ b/shenyu-admin/src/test/java/org/apache/shenyu/admin/mapper/RuleMapperTest.java @@ -205,6 +205,7 @@ private RuleDO buildRuleDO() { .sort(1) .dateCreated(now) .dateUpdated(now) + .namespaceId(SYS_DEFAULT_NAMESPACE_ID) .build(); } } From 23dccc006167a3303523d462492141718ab60935 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=98xcsnx=E2=80=99?= <‘1192709687@qq.com’> Date: Mon, 19 Aug 2024 20:55:05 +0800 Subject: [PATCH 53/61] fix unit test --- .../event/metadata/MetaDataChangedEvent.java | 2 +- .../admin/controller/RuleControllerTest.java | 25 +++++++++++++++++-- .../BatchMetaDataChangedEventTest.java | 5 +++- .../metadata/MetaDataCreatedEventTest.java | 4 ++- .../metadata/MetadataUpdatedEventTest.java | 7 ++++-- .../BatchSelectorDeletedEventTest.java | 4 ++- ...enyuClientRegisterGrpcServiceImplTest.java | 2 +- ...entRegisterSpringCloudServiceImplTest.java | 2 +- ...enyuClientRegisterTarsServiceImplTest.java | 2 +- 9 files changed, 42 insertions(+), 11 deletions(-) diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/event/metadata/MetaDataChangedEvent.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/event/metadata/MetaDataChangedEvent.java index 0a1c01198417..494b72896e73 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/event/metadata/MetaDataChangedEvent.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/event/metadata/MetaDataChangedEvent.java @@ -49,7 +49,7 @@ public String buildContext() { return String.format("the namespace [%s] metadata [%s %s] is %s", after.getNamespaceId(), after.getAppName(), after.getPath(), StringUtils.lowerCase(getType().getType().toString())); } - return String.format("the namespace [%s] metadata [%s %s] is %s : %s", after.getNamespaceId(), after.getAppName(), + return String.format("the namespace [%s] metadata [%s %s] is %s : %s", after.getNamespaceId(), after.getAppName(), after.getPath(), StringUtils.lowerCase(getType().getType().toString()), contrast()); } diff --git a/shenyu-admin/src/test/java/org/apache/shenyu/admin/controller/RuleControllerTest.java b/shenyu-admin/src/test/java/org/apache/shenyu/admin/controller/RuleControllerTest.java index e97fa0faa116..d27b2b048df3 100644 --- a/shenyu-admin/src/test/java/org/apache/shenyu/admin/controller/RuleControllerTest.java +++ b/shenyu-admin/src/test/java/org/apache/shenyu/admin/controller/RuleControllerTest.java @@ -18,10 +18,12 @@ package org.apache.shenyu.admin.controller; import org.apache.shenyu.admin.exception.ExceptionHandlers; +import org.apache.shenyu.admin.mapper.NamespaceMapper; import org.apache.shenyu.admin.mapper.RuleMapper; import org.apache.shenyu.admin.mapper.SelectorMapper; import org.apache.shenyu.admin.model.custom.UserInfo; import org.apache.shenyu.admin.model.dto.BatchCommonDTO; +import org.apache.shenyu.admin.model.dto.BatchNamespaceCommonDTO; import org.apache.shenyu.admin.model.dto.RuleConditionDTO; import org.apache.shenyu.admin.model.dto.RuleDTO; import org.apache.shenyu.admin.model.page.CommonPager; @@ -84,6 +86,9 @@ public final class RuleControllerTest { @Mock private SelectorMapper selectorMapper; + @Mock + private NamespaceMapper namespaceMapper; + private final RuleConditionVO rCondition1 = new RuleConditionVO( "888", "666", "uri", "Uniform", "match", "match", "/", "/http/test/**", DateUtils.localDateTimeToString(LocalDateTime.now()), DateUtils.localDateTimeToString(LocalDateTime.now()) ); @@ -122,7 +127,7 @@ public void testQueryRules() throws Exception { @Test public void testDetailRule() throws Exception { given(this.ruleService.findByIdAndNamespaceId("666", SYS_DEFAULT_NAMESPACE_ID)).willReturn(ruleVO); - this.mockMvc.perform(MockMvcRequestBuilders.get("/rule/{id}", "666")) + this.mockMvc.perform(MockMvcRequestBuilders.get("/rule/{id}/{namespaceId}", "666", SYS_DEFAULT_NAMESPACE_ID)) .andExpect(status().isOk()) .andExpect(jsonPath("$.message", is(ShenyuResultMessage.DETAIL_SUCCESS))) .andExpect(jsonPath("$.data.id", is(ruleVO.getId()))) @@ -154,12 +159,15 @@ public void testCreateRule() throws Exception { .sort(1) .handle("{\"loadBalance\":\"random\",\"retry\":0,\"timeout\":3000}") .ruleConditions(conList) + .namespaceId(SYS_DEFAULT_NAMESPACE_ID) .build(); SpringBeanUtils.getInstance().setApplicationContext(mock(ConfigurableApplicationContext.class)); when(SpringBeanUtils.getInstance().getBean(RuleMapper.class)).thenReturn(ruleMapper); when(ruleMapper.existed(ruleDTO.getId())).thenReturn(true); when(SpringBeanUtils.getInstance().getBean(SelectorMapper.class)).thenReturn(selectorMapper); when(selectorMapper.existed(ruleDTO.getSelectorId())).thenReturn(true); + when(SpringBeanUtils.getInstance().getBean(NamespaceMapper.class)).thenReturn(namespaceMapper); + when(namespaceMapper.existed(SYS_DEFAULT_NAMESPACE_ID)).thenReturn(true); given(this.ruleService.createOrUpdate(ruleDTO)).willReturn(1); this.mockMvc.perform(MockMvcRequestBuilders.post("/rule", ruleDTO) .contentType(MediaType.APPLICATION_JSON) @@ -194,12 +202,15 @@ public void testUpdateRule() throws Exception { .sort(1) .handle("{\"loadBalance\":\"random\",\"retry\":0,\"timeout\":3000}") .ruleConditions(conList) + .namespaceId(SYS_DEFAULT_NAMESPACE_ID) .build(); SpringBeanUtils.getInstance().setApplicationContext(mock(ConfigurableApplicationContext.class)); when(SpringBeanUtils.getInstance().getBean(RuleMapper.class)).thenReturn(ruleMapper); when(ruleMapper.existed(ruleDTO.getId())).thenReturn(true); when(SpringBeanUtils.getInstance().getBean(SelectorMapper.class)).thenReturn(selectorMapper); when(selectorMapper.existed(ruleDTO.getSelectorId())).thenReturn(true); + when(SpringBeanUtils.getInstance().getBean(NamespaceMapper.class)).thenReturn(namespaceMapper); + when(namespaceMapper.existed(SYS_DEFAULT_NAMESPACE_ID)).thenReturn(true); given(this.ruleService.createOrUpdate(ruleDTO)).willReturn(1); this.mockMvc.perform(MockMvcRequestBuilders.put("/rule/{id}", "666") .contentType(MediaType.APPLICATION_JSON) @@ -212,10 +223,16 @@ public void testUpdateRule() throws Exception { @Test public void testDeleteRules() throws Exception { + final BatchNamespaceCommonDTO batchNamespaceCommonDTO = new BatchNamespaceCommonDTO(); + batchNamespaceCommonDTO.setNamespaceId(SYS_DEFAULT_NAMESPACE_ID); + batchNamespaceCommonDTO.setIds(Collections.singletonList("111")); + SpringBeanUtils.getInstance().setApplicationContext(mock(ConfigurableApplicationContext.class)); + when(SpringBeanUtils.getInstance().getBean(NamespaceMapper.class)).thenReturn(namespaceMapper); + when(namespaceMapper.existed(SYS_DEFAULT_NAMESPACE_ID)).thenReturn(true); given(this.ruleService.deleteByIdsAndNamespaceId(Collections.singletonList("111"), SYS_DEFAULT_NAMESPACE_ID)).willReturn(1); this.mockMvc.perform(MockMvcRequestBuilders.delete("/rule/batch") .contentType(MediaType.APPLICATION_JSON) - .content("[\"111\"]") + .content(GsonUtils.getGson().toJson(batchNamespaceCommonDTO)) ) .andExpect(status().isOk()) .andExpect(jsonPath("$.message", is(ShenyuResultMessage.DELETE_SUCCESS))) @@ -234,16 +251,20 @@ public void testEnableRule() throws Exception { .matchRestful(false) .sort(1) .handle("{\"loadBalance\":\"random\",\"retry\":0,\"timeout\":3000}") + .namespaceId(SYS_DEFAULT_NAMESPACE_ID) .build(); SpringBeanUtils.getInstance().setApplicationContext(mock(ConfigurableApplicationContext.class)); when(SpringBeanUtils.getInstance().getBean(RuleMapper.class)).thenReturn(ruleMapper); when(ruleMapper.existed(ruleDTO.getId())).thenReturn(true); when(SpringBeanUtils.getInstance().getBean(SelectorMapper.class)).thenReturn(selectorMapper); when(selectorMapper.existed(ruleDTO.getSelectorId())).thenReturn(true); + when(SpringBeanUtils.getInstance().getBean(NamespaceMapper.class)).thenReturn(namespaceMapper); + when(namespaceMapper.existed(SYS_DEFAULT_NAMESPACE_ID)).thenReturn(true); given(this.ruleService.enabledByIdsAndNamespaceId(Arrays.asList(ruleDTO.getId()), false, SYS_DEFAULT_NAMESPACE_ID)).willReturn(true); BatchCommonDTO batchCommonDTO = new BatchCommonDTO(); batchCommonDTO.setIds(Arrays.asList(ruleDTO.getId())); batchCommonDTO.setEnabled(false); + batchCommonDTO.setNamespaceId(SYS_DEFAULT_NAMESPACE_ID); this.mockMvc.perform(MockMvcRequestBuilders.post("/rule/batchEnabled") .contentType(MediaType.APPLICATION_JSON) .content(GsonUtils.getInstance().toJson(batchCommonDTO)) diff --git a/shenyu-admin/src/test/java/org/apache/shenyu/admin/model/event/metadata/BatchMetaDataChangedEventTest.java b/shenyu-admin/src/test/java/org/apache/shenyu/admin/model/event/metadata/BatchMetaDataChangedEventTest.java index 435b4a87ae62..7a15eebbbed4 100644 --- a/shenyu-admin/src/test/java/org/apache/shenyu/admin/model/event/metadata/BatchMetaDataChangedEventTest.java +++ b/shenyu-admin/src/test/java/org/apache/shenyu/admin/model/event/metadata/BatchMetaDataChangedEventTest.java @@ -24,6 +24,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import static org.apache.shenyu.common.constant.AdminConstants.SYS_DEFAULT_NAMESPACE_ID; import static org.junit.jupiter.api.Assertions.assertEquals; /** @@ -47,6 +48,7 @@ public void setUp() { .methodName("post") .parameterTypes("java.lang.String") .enabled(true) + .namespaceId(SYS_DEFAULT_NAMESPACE_ID) .build(); two = MetaDataDO.builder() @@ -59,6 +61,7 @@ public void setUp() { .methodName("post") .parameterTypes("java.lang.String") .enabled(true) + .namespaceId(SYS_DEFAULT_NAMESPACE_ID) .build(); } @@ -67,7 +70,7 @@ public void batchMetaDataChangedContextTest() { BatchMetaDataChangedEvent batchMetaDataChangedEvent = new BatchMetaDataChangedEvent(Arrays.asList(one, two), null, EventTypeEnum.META_DATA_UPDATE, "test-operator"); - String context = String.format("the meta data [%s] is %s", + String context = String.format("the namespace [649330b6-c2d7-4edc-be8e-8a54df9eb385] meta data [%s] is %s", "testAppNameOne,testAppNameTwo", StringUtils.lowerCase(EventTypeEnum.META_DATA_UPDATE.getType().toString())); assertEquals(context, batchMetaDataChangedEvent.buildContext()); diff --git a/shenyu-admin/src/test/java/org/apache/shenyu/admin/model/event/metadata/MetaDataCreatedEventTest.java b/shenyu-admin/src/test/java/org/apache/shenyu/admin/model/event/metadata/MetaDataCreatedEventTest.java index dc7ba7edc1df..fcf98548e183 100644 --- a/shenyu-admin/src/test/java/org/apache/shenyu/admin/model/event/metadata/MetaDataCreatedEventTest.java +++ b/shenyu-admin/src/test/java/org/apache/shenyu/admin/model/event/metadata/MetaDataCreatedEventTest.java @@ -23,6 +23,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import static org.apache.shenyu.common.constant.AdminConstants.SYS_DEFAULT_NAMESPACE_ID; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -46,6 +47,7 @@ public void setUp() { .parameterTypes("java.lang.String") .rpcExt("test") .enabled(true) + .namespaceId(SYS_DEFAULT_NAMESPACE_ID) .build(); } @@ -54,7 +56,7 @@ public void metaDataCreateContextTest() { MetaDataChangedEvent createdEvent = new MetaDataChangedEvent(createDO, null, EventTypeEnum.META_DATA_CREATE, "test-operator"); - String context = String.format("the metadata [%s %s] is %s", + String context = String.format("the namespace [%s] metadata [%s %s] is %s", createDO.getNamespaceId(), createDO.getAppName(), createDO.getPath(), StringUtils.lowerCase(EventTypeEnum.META_DATA_CREATE.getType().toString())); assertEquals(context, createdEvent.buildContext()); diff --git a/shenyu-admin/src/test/java/org/apache/shenyu/admin/model/event/metadata/MetadataUpdatedEventTest.java b/shenyu-admin/src/test/java/org/apache/shenyu/admin/model/event/metadata/MetadataUpdatedEventTest.java index e76706d84bb5..53e148cbbd1b 100644 --- a/shenyu-admin/src/test/java/org/apache/shenyu/admin/model/event/metadata/MetadataUpdatedEventTest.java +++ b/shenyu-admin/src/test/java/org/apache/shenyu/admin/model/event/metadata/MetadataUpdatedEventTest.java @@ -23,6 +23,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import static org.apache.shenyu.common.constant.AdminConstants.SYS_DEFAULT_NAMESPACE_ID; import static org.junit.jupiter.api.Assertions.assertEquals; /** @@ -46,6 +47,7 @@ public void setUp() { .parameterTypes("java.lang.String") .enabled(true) .rpcExt("rpcExtBefore") + .namespaceId(SYS_DEFAULT_NAMESPACE_ID) .build(); updateAfterDO = MetaDataDO.builder() .id("1") @@ -58,6 +60,7 @@ public void setUp() { .parameterTypes("java.lang.Integer") .enabled(false) .rpcExt("rpcExtAfter") + .namespaceId(SYS_DEFAULT_NAMESPACE_ID) .build(); } @@ -67,7 +70,7 @@ public void metaDataUpdateContextTest() { MetaDataChangedEvent updateNothingEvent = new MetaDataChangedEvent(updateBeforeDO, updateBeforeDO, EventTypeEnum.META_DATA_UPDATE, "test-operator"); - String baseContext = String.format("the metadata [%s %s] is %s : %s", + String baseContext = String.format("the namespace [%s] metadata [%s %s] is %s : %s", updateBeforeDO.getNamespaceId(), updateBeforeDO.getAppName(), updateBeforeDO.getPath(), eventTypeStr, "it no change"); assertEquals(baseContext, updateNothingEvent.buildContext()); @@ -82,7 +85,7 @@ public void metaDataUpdateContextTest() { contrast.append(String.format("rpc type[%s => %s] ", updateBeforeDO.getRpcType(), updateAfterDO.getRpcType())); contrast.append(String.format("rpc ext[%s => %s] ", updateBeforeDO.getRpcExt(), updateAfterDO.getRpcExt())); - String context = String.format("the metadata [%s %s] is %s : %s", + String context = String.format("the namespace [%s] metadata [%s %s] is %s : %s", updateAfterDO.getNamespaceId(), updateAfterDO.getAppName(), updateAfterDO.getPath(), eventTypeStr, contrast); MetaDataChangedEvent updateEvent = diff --git a/shenyu-admin/src/test/java/org/apache/shenyu/admin/model/event/selector/BatchSelectorDeletedEventTest.java b/shenyu-admin/src/test/java/org/apache/shenyu/admin/model/event/selector/BatchSelectorDeletedEventTest.java index 3aea7c3e663c..6305f746008d 100644 --- a/shenyu-admin/src/test/java/org/apache/shenyu/admin/model/event/selector/BatchSelectorDeletedEventTest.java +++ b/shenyu-admin/src/test/java/org/apache/shenyu/admin/model/event/selector/BatchSelectorDeletedEventTest.java @@ -34,6 +34,7 @@ import java.util.Collections; import java.util.List; +import static org.apache.shenyu.common.constant.AdminConstants.SYS_DEFAULT_NAMESPACE_ID; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertArrayEquals; @@ -65,7 +66,7 @@ public void init() { @Test void buildContext() { - String expectMsg = String.format("the selector[%s] is %s", selectorDO.getName(), StringUtils.lowerCase(batchSelectorDeletedEvent.getType().getType().toString())); + String expectMsg = String.format("the namespace [%s] selector[%s] is %s", selectorDO.getNamespaceId(), selectorDO.getName(), StringUtils.lowerCase(batchSelectorDeletedEvent.getType().getType().toString())); String actualMsg = batchSelectorDeletedEvent.buildContext(); @@ -110,6 +111,7 @@ private SelectorDO buildSelectorDO() { selectorDTO.setName("kuan"); selectorDTO.setType(SelectorTypeEnum.FULL_FLOW.getCode()); selectorDTO.setHandle("[{\"upstreamHost\": \"127.0.0.1\", \"protocol\": \"http://\", \"upstreamUrl\": \"anotherUrl\"}]"); + selectorDTO.setNamespaceId(SYS_DEFAULT_NAMESPACE_ID); SelectorConditionDTO selectorConditionDTO1 = new SelectorConditionDTO(); selectorConditionDTO1.setId("111"); selectorConditionDTO1.setSelectorId("456"); diff --git a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterGrpcServiceImplTest.java b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterGrpcServiceImplTest.java index 73359ebd9c01..6a5eb8aeede3 100644 --- a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterGrpcServiceImplTest.java +++ b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterGrpcServiceImplTest.java @@ -81,7 +81,7 @@ public void testRuleHandler() { public void testRegisterMetadata() { MetaDataDO metaDataDO = MetaDataDO.builder().build(); when(metaDataService.findByPathAndNamespaceId(any(), any())).thenReturn(metaDataDO); - MetaDataRegisterDTO metaDataDTO = MetaDataRegisterDTO.builder().path("/test").build(); + MetaDataRegisterDTO metaDataDTO = MetaDataRegisterDTO.builder().path("/test").namespaceId(SYS_DEFAULT_NAMESPACE_ID).build(); shenyuClientRegisterGrpcService.registerMetadata(metaDataDTO); verify(metaDataService).findByPathAndNamespaceId("/test", SYS_DEFAULT_NAMESPACE_ID); verify(metaDataService).saveOrUpdateMetaData(metaDataDO, metaDataDTO); diff --git a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterSpringCloudServiceImplTest.java b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterSpringCloudServiceImplTest.java index 2ec364a90683..b8236aeba740 100644 --- a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterSpringCloudServiceImplTest.java +++ b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterSpringCloudServiceImplTest.java @@ -91,7 +91,7 @@ public void testRuleHandler() { public void testRegisterMetadata() { MetaDataDO metaDataDO = MetaDataDO.builder().build(); when(metaDataService.findByPathAndNamespaceId(any(), any())).thenReturn(metaDataDO); - MetaDataRegisterDTO metaDataDTO = MetaDataRegisterDTO.builder().path("/contextPath/test").build(); + MetaDataRegisterDTO metaDataDTO = MetaDataRegisterDTO.builder().path("/contextPath/test").namespaceId(SYS_DEFAULT_NAMESPACE_ID).build(); shenyuClientRegisterSpringCloudService.registerMetadata(metaDataDTO); verify(metaDataService).findByPathAndNamespaceId("/contextPath/test", SYS_DEFAULT_NAMESPACE_ID); verify(metaDataService).saveOrUpdateMetaData(metaDataDO, metaDataDTO); diff --git a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterTarsServiceImplTest.java b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterTarsServiceImplTest.java index 8a7540e8f405..3c42cb050709 100644 --- a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterTarsServiceImplTest.java +++ b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterTarsServiceImplTest.java @@ -84,7 +84,7 @@ public void testRegisterMetadata() { String methodName = "registerMetadata"; when(metaDataService.findByServiceNameAndMethodNameAndNamespaceId(any(), any(), any())).thenReturn(metaDataDO); MetaDataRegisterDTO metaDataDTO = MetaDataRegisterDTO.builder().serviceName(serviceName) - .methodName(methodName).build(); + .methodName(methodName).namespaceId(SYS_DEFAULT_NAMESPACE_ID).build(); shenyuClientRegisterTarsService.registerMetadata(metaDataDTO); verify(metaDataService).findByServiceNameAndMethodNameAndNamespaceId(serviceName, methodName, SYS_DEFAULT_NAMESPACE_ID); verify(metaDataService).saveOrUpdateMetaData(metaDataDO, metaDataDTO); From 559ca6cb0c3ee73c2aadfa88e30ec1b1c82e2303 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=98xcsnx=E2=80=99?= <‘1192709687@qq.com’> Date: Mon, 19 Aug 2024 21:04:06 +0800 Subject: [PATCH 54/61] fix unit test --- .../register/ShenyuClientRegisterGrpcServiceImplTest.java | 6 +++++- .../ShenyuClientRegisterSpringCloudServiceImplTest.java | 6 +++++- .../register/ShenyuClientRegisterTarsServiceImplTest.java | 8 ++++++-- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterGrpcServiceImplTest.java b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterGrpcServiceImplTest.java index 6a5eb8aeede3..220233621a18 100644 --- a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterGrpcServiceImplTest.java +++ b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterGrpcServiceImplTest.java @@ -81,7 +81,11 @@ public void testRuleHandler() { public void testRegisterMetadata() { MetaDataDO metaDataDO = MetaDataDO.builder().build(); when(metaDataService.findByPathAndNamespaceId(any(), any())).thenReturn(metaDataDO); - MetaDataRegisterDTO metaDataDTO = MetaDataRegisterDTO.builder().path("/test").namespaceId(SYS_DEFAULT_NAMESPACE_ID).build(); + MetaDataRegisterDTO metaDataDTO = MetaDataRegisterDTO + .builder() + .path("/test") + .namespaceId(SYS_DEFAULT_NAMESPACE_ID) + .build(); shenyuClientRegisterGrpcService.registerMetadata(metaDataDTO); verify(metaDataService).findByPathAndNamespaceId("/test", SYS_DEFAULT_NAMESPACE_ID); verify(metaDataService).saveOrUpdateMetaData(metaDataDO, metaDataDTO); diff --git a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterSpringCloudServiceImplTest.java b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterSpringCloudServiceImplTest.java index b8236aeba740..0037466ffb10 100644 --- a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterSpringCloudServiceImplTest.java +++ b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterSpringCloudServiceImplTest.java @@ -91,7 +91,11 @@ public void testRuleHandler() { public void testRegisterMetadata() { MetaDataDO metaDataDO = MetaDataDO.builder().build(); when(metaDataService.findByPathAndNamespaceId(any(), any())).thenReturn(metaDataDO); - MetaDataRegisterDTO metaDataDTO = MetaDataRegisterDTO.builder().path("/contextPath/test").namespaceId(SYS_DEFAULT_NAMESPACE_ID).build(); + MetaDataRegisterDTO metaDataDTO = MetaDataRegisterDTO + .builder() + .path("/contextPath/test") + .namespaceId(SYS_DEFAULT_NAMESPACE_ID) + .build(); shenyuClientRegisterSpringCloudService.registerMetadata(metaDataDTO); verify(metaDataService).findByPathAndNamespaceId("/contextPath/test", SYS_DEFAULT_NAMESPACE_ID); verify(metaDataService).saveOrUpdateMetaData(metaDataDO, metaDataDTO); diff --git a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterTarsServiceImplTest.java b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterTarsServiceImplTest.java index 3c42cb050709..63ad63bab89e 100644 --- a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterTarsServiceImplTest.java +++ b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterTarsServiceImplTest.java @@ -83,8 +83,12 @@ public void testRegisterMetadata() { String serviceName = "metaDataService"; String methodName = "registerMetadata"; when(metaDataService.findByServiceNameAndMethodNameAndNamespaceId(any(), any(), any())).thenReturn(metaDataDO); - MetaDataRegisterDTO metaDataDTO = MetaDataRegisterDTO.builder().serviceName(serviceName) - .methodName(methodName).namespaceId(SYS_DEFAULT_NAMESPACE_ID).build(); + MetaDataRegisterDTO metaDataDTO = MetaDataRegisterDTO + .builder() + .serviceName(serviceName) + .methodName(methodName) + .namespaceId(SYS_DEFAULT_NAMESPACE_ID) + .build(); shenyuClientRegisterTarsService.registerMetadata(metaDataDTO); verify(metaDataService).findByServiceNameAndMethodNameAndNamespaceId(serviceName, methodName, SYS_DEFAULT_NAMESPACE_ID); verify(metaDataService).saveOrUpdateMetaData(metaDataDO, metaDataDTO); From f28ca27b36a07e23a0ca82517cb1e73aa74b6471 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=98xcsnx=E2=80=99?= <‘1192709687@qq.com’> Date: Mon, 19 Aug 2024 21:27:03 +0800 Subject: [PATCH 55/61] fix unit test --- .../model/event/selector/BatchSelectorDeletedEventTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/shenyu-admin/src/test/java/org/apache/shenyu/admin/model/event/selector/BatchSelectorDeletedEventTest.java b/shenyu-admin/src/test/java/org/apache/shenyu/admin/model/event/selector/BatchSelectorDeletedEventTest.java index 6305f746008d..157ea95fe665 100644 --- a/shenyu-admin/src/test/java/org/apache/shenyu/admin/model/event/selector/BatchSelectorDeletedEventTest.java +++ b/shenyu-admin/src/test/java/org/apache/shenyu/admin/model/event/selector/BatchSelectorDeletedEventTest.java @@ -66,7 +66,8 @@ public void init() { @Test void buildContext() { - String expectMsg = String.format("the namespace [%s] selector[%s] is %s", selectorDO.getNamespaceId(), selectorDO.getName(), StringUtils.lowerCase(batchSelectorDeletedEvent.getType().getType().toString())); + String expectMsg = String.format("the namespace [%s] selector[%s] is %s", selectorDO.getNamespaceId(), + selectorDO.getName(), StringUtils.lowerCase(batchSelectorDeletedEvent.getType().getType().toString())); String actualMsg = batchSelectorDeletedEvent.buildContext(); From d3fb29249dc1d1512062ec5a76fdc25ca285f20f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=98xcsnx=E2=80=99?= <‘1192709687@qq.com’> Date: Mon, 19 Aug 2024 21:51:24 +0800 Subject: [PATCH 56/61] fix unit test --- .../model/event/metadata/BatchMetaDataDeletedEventTest.java | 5 ++++- .../model/event/metadata/MetaDataChangedEventTest.java | 4 +++- .../apache/shenyu/admin/service/MetaDataServiceTest.java | 6 ++++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/shenyu-admin/src/test/java/org/apache/shenyu/admin/model/event/metadata/BatchMetaDataDeletedEventTest.java b/shenyu-admin/src/test/java/org/apache/shenyu/admin/model/event/metadata/BatchMetaDataDeletedEventTest.java index dc50b24d31da..8229671a9f16 100644 --- a/shenyu-admin/src/test/java/org/apache/shenyu/admin/model/event/metadata/BatchMetaDataDeletedEventTest.java +++ b/shenyu-admin/src/test/java/org/apache/shenyu/admin/model/event/metadata/BatchMetaDataDeletedEventTest.java @@ -24,6 +24,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import static org.apache.shenyu.common.constant.AdminConstants.SYS_DEFAULT_NAMESPACE_ID; import static org.junit.jupiter.api.Assertions.assertEquals; /** @@ -47,6 +48,7 @@ public void setUp() { .methodName("post") .parameterTypes("java.lang.String") .enabled(true) + .namespaceId(SYS_DEFAULT_NAMESPACE_ID) .build(); two = MetaDataDO.builder() @@ -59,6 +61,7 @@ public void setUp() { .methodName("post") .parameterTypes("java.lang.String") .enabled(true) + .namespaceId(SYS_DEFAULT_NAMESPACE_ID) .build(); } @@ -67,7 +70,7 @@ public void batchMetaDataDeletedContextTest() { BatchMetaDataDeletedEvent batchMetaDataChangedEvent = new BatchMetaDataDeletedEvent(Arrays.asList(one, two), "test-operator"); - String context = String.format("the meta data [%s] is %s", + String context = String.format("the namespace [649330b6-c2d7-4edc-be8e-8a54df9eb385] meta data [%s] is %s", "testAppNameOne,testAppNameTwo", StringUtils.lowerCase(EventTypeEnum.META_DATA_DELETE.getType().toString())); assertEquals(context, batchMetaDataChangedEvent.buildContext()); diff --git a/shenyu-admin/src/test/java/org/apache/shenyu/admin/model/event/metadata/MetaDataChangedEventTest.java b/shenyu-admin/src/test/java/org/apache/shenyu/admin/model/event/metadata/MetaDataChangedEventTest.java index d3da8f26dc1b..4a5b26ccc03a 100644 --- a/shenyu-admin/src/test/java/org/apache/shenyu/admin/model/event/metadata/MetaDataChangedEventTest.java +++ b/shenyu-admin/src/test/java/org/apache/shenyu/admin/model/event/metadata/MetaDataChangedEventTest.java @@ -23,6 +23,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import static org.apache.shenyu.common.constant.AdminConstants.SYS_DEFAULT_NAMESPACE_ID; import static org.junit.jupiter.api.Assertions.assertEquals; /** @@ -44,6 +45,7 @@ public void setUp() { .parameterTypes("java.lang.String") .rpcExt("test") .enabled(true) + .namespaceId(SYS_DEFAULT_NAMESPACE_ID) .build(); } @@ -52,7 +54,7 @@ public void metaDataDeleteContextTest() { MetaDataChangedEvent deleteEvent = new MetaDataChangedEvent(createDO, null, EventTypeEnum.META_DATA_DELETE, "test-operator"); - String context = String.format("the metadata [%s %s] is %s", + String context = String.format("the namespace [%s] metadata [%s %s] is %s", createDO.getNamespaceId(), createDO.getAppName(), createDO.getPath(), StringUtils.lowerCase(EventTypeEnum.META_DATA_DELETE.getType().toString())); assertEquals(context, deleteEvent.buildContext()); diff --git a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/MetaDataServiceTest.java b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/MetaDataServiceTest.java index 52e98c83f0fc..1019d02f8fe7 100644 --- a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/MetaDataServiceTest.java +++ b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/MetaDataServiceTest.java @@ -20,6 +20,7 @@ import com.google.common.collect.Lists; import org.apache.commons.lang3.StringUtils; import org.apache.shenyu.admin.mapper.MetaDataMapper; +import org.apache.shenyu.admin.mapper.NamespaceMapper; import org.apache.shenyu.admin.model.dto.MetaDataDTO; import org.apache.shenyu.admin.model.entity.MetaDataDO; import org.apache.shenyu.admin.model.page.CommonPager; @@ -92,6 +93,9 @@ public final class MetaDataServiceTest { @Mock private MetaDataQuery metaDataQuery; + @Mock + private NamespaceMapper namespaceMapper; + @BeforeAll public static void beforeClass() { loggerSpy = spy(LoggerFactory.getLogger(MetaDataServiceImpl.class)); @@ -333,9 +337,11 @@ private void testCreateOrUpdateForUpdate() { MetaDataDO metaDataDO = MetaDataDO.builder().build(); when(metaDataDTO.getId()).thenReturn("id"); when(metaDataDTO.getPath()).thenReturn("path"); + when(metaDataDTO.getNamespaceId()).thenReturn(SYS_DEFAULT_NAMESPACE_ID); when(metaDataMapper.pathExistedExclude("path", Collections.singletonList("id"))).thenReturn(null); when(metaDataMapper.selectByIdAndNamespaceId("id", SYS_DEFAULT_NAMESPACE_ID)).thenReturn(metaDataDO); when(metaDataMapper.update(any())).thenReturn(1); + String msg = metaDataService.createOrUpdate(metaDataDTO); assertEquals(ShenyuResultMessage.UPDATE_SUCCESS, msg); } From 3f2dfdef971b5e5dcb04722b8651ed6338545d0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=98xcsnx=E2=80=99?= <‘1192709687@qq.com’> Date: Mon, 19 Aug 2024 22:18:29 +0800 Subject: [PATCH 57/61] fix unit test --- .../java/org/apache/shenyu/admin/service/RuleServiceTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/RuleServiceTest.java b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/RuleServiceTest.java index 711766d25a62..ef333b108ef5 100644 --- a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/RuleServiceTest.java +++ b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/RuleServiceTest.java @@ -345,6 +345,7 @@ private RuleDTO buildRuleDTO(final String id) { .matchMode(0) .handle("{\"test1\":\"\"}") .name("456") + .namespaceId(SYS_DEFAULT_NAMESPACE_ID) .build(); if (StringUtils.isNotBlank(id)) { ruleDTO.setId(id); From 9e98a614e62cb08ed7bad8bc759aea9fe9b662de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=98xcsnx=E2=80=99?= <‘1192709687@qq.com’> Date: Tue, 20 Aug 2024 08:47:11 +0800 Subject: [PATCH 58/61] trigger ci --- .../apache/shenyu/admin/service/impl/MetaDataServiceImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/MetaDataServiceImpl.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/MetaDataServiceImpl.java index fa9444801863..00abddc14cd9 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/MetaDataServiceImpl.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/MetaDataServiceImpl.java @@ -96,7 +96,7 @@ public void saveOrUpdateMetaData(final MetaDataDO exist, final MetaDataRegisterD metaDataMapper.update(metaDataDO); eventType = DataEventTypeEnum.UPDATE; } - // publish MetaData's event + // publish MetaData's event eventPublisher.publishEvent(new DataChangedEvent(ConfigGroupEnum.META_DATA, eventType, Collections.singletonList(MetaDataTransfer.INSTANCE.mapToData(metaDataDO)))); } From 1a6717b56339026fddec2d091b30ea77fd163f2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=98xcsnx=E2=80=99?= <‘1192709687@qq.com’> Date: Wed, 21 Aug 2024 09:10:51 +0800 Subject: [PATCH 59/61] trigger ci --- .../java/org/apache/shenyu/admin/service/MetaDataService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/MetaDataService.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/MetaDataService.java index 2decf197996a..7822647c9e5e 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/MetaDataService.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/MetaDataService.java @@ -151,7 +151,7 @@ public interface MetaDataService { * Import shenyu meta data. * * @param metaDataList meta data list - * @return the config impotr result + * @return the config import result */ ConfigImportResult importData(List metaDataList); } From a7468d61a517fbec0abbd2d82af5e09cfe4ab671 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=98xcsnx=E2=80=99?= <‘1192709687@qq.com’> Date: Thu, 22 Aug 2024 00:25:01 +0800 Subject: [PATCH 60/61] merge fix --- .../register/AbstractShenyuClientRegisterServiceImpl.java | 2 +- .../service/register/ShenyuClientRegisterGrpcServiceImpl.java | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/AbstractShenyuClientRegisterServiceImpl.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/AbstractShenyuClientRegisterServiceImpl.java index b8bee2761a0f..5f69991f946c 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/AbstractShenyuClientRegisterServiceImpl.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/AbstractShenyuClientRegisterServiceImpl.java @@ -292,7 +292,7 @@ private RuleDTO buildRpcDefaultRuleDTO(final String selectorId, final MetaDataRe return buildRuleDTO(selectorId, ruleHandler, metaDataDTO.getRuleName(), metaDataDTO.getPath(), metaDataDTO.getNamespaceId()); } - private RuleDTO buildRuleDTO(final String selectorId, final String ruleHandler, final String ruleName, final String path) { + private RuleDTO buildRuleDTO(final String selectorId, final String ruleHandler, final String ruleName, final String path, final String namespaceId) { RuleDTO ruleDTO = RuleDTO.builder() .selectorId(selectorId) .name(ruleName) diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterGrpcServiceImpl.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterGrpcServiceImpl.java index f51ddede38b4..e07cb7b398b3 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterGrpcServiceImpl.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterGrpcServiceImpl.java @@ -79,11 +79,10 @@ protected String ruleHandler() { @Override protected void registerMetadata(final MetaDataRegisterDTO metaDataDTO) { MetaDataService metaDataService = getMetaDataService(); - MetaDataDO exist = metaDataService.findByPathAndNamespaceId(metaDataDTO.getPath(), metaDataDTO.getNamespaceId()); if (LOG.isDebugEnabled()) { LOG.debug("grpc register metadata:{}", GsonUtils.getInstance().toJson(metaDataDTO)); } - MetaDataDO exist = metaDataService.findByPathAndNamespaceId(metaDataDTO.getPath()); + MetaDataDO exist = metaDataService.findByPathAndNamespaceId(metaDataDTO.getPath(), metaDataDTO.getNamespaceId()); metaDataService.saveOrUpdateMetaData(exist, metaDataDTO); } From 8c4bdf7f6174a250152d184983442e4b5f554288 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=98xcsnx=E2=80=99?= <‘1192709687@qq.com’> Date: Mon, 2 Sep 2024 00:30:35 +0800 Subject: [PATCH 61/61] support ocean base --- db/init/ob/schema.sql | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/db/init/ob/schema.sql b/db/init/ob/schema.sql index f7f0062218eb..4a96c40970db 100644 --- a/db/init/ob/schema.sql +++ b/db/init/ob/schema.sql @@ -2371,4 +2371,8 @@ INSERT INTO `shenyu`.`permission` (`id`, `object_id`, `resource_id`, `date_creat INSERT INTO `shenyu`.`permission` (`id`, `object_id`, `resource_id`, `date_created`, `date_updated`) VALUES ('1792779493541343266', '1346358560427216896', '1792749362445840485', '2024-06-25 20:00:00.000', '2024-06-25 20:00:00.000'); INSERT INTO `shenyu`.`permission` (`id`, `object_id`, `resource_id`, `date_created`, `date_updated`) VALUES ('1792779493541343267', '1346358560427216896', '1792749362445840486', '2024-06-25 20:00:00.000', '2024-06-25 20:00:00.000'); -ALTER TABLE `shenyu`.`selector` ADD COLUMN `namespace_id` varchar(50) NULL COMMENT 'namespaceId' AFTER `match_restful`; \ No newline at end of file +ALTER TABLE `shenyu`.`selector` ADD COLUMN `namespace_id` varchar(50) NULL COMMENT 'namespaceId' AFTER `match_restful`; + +ALTER TABLE `shenyu`.`rule` ADD COLUMN `namespace_id` varchar(50) NULL COMMENT 'namespaceId' AFTER `match_restful`; + +ALTER TABLE `shenyu`.`meta_data` ADD COLUMN `namespace_id` varchar(50) NULL COMMENT 'namespaceId'; \ No newline at end of file