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 db6a98b29ed8..630ced8843aa 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 @@ -25,7 +25,7 @@ import java.util.Collection; import java.util.stream.Collectors; -import static org.apache.shenyu.common.constant.AdminConstants.SYS_DEFAULT_NAMESPACE_ID; +import static org.apache.shenyu.common.constant.Constants.SYS_DEFAULT_NAMESPACE_ID; /** * BatchMetaDataChangedEvent. 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 0526802fc69a..10975d0f7130 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 @@ -29,7 +29,7 @@ import java.util.List; import java.util.stream.Collectors; -import static org.apache.shenyu.common.constant.AdminConstants.SYS_DEFAULT_NAMESPACE_ID; +import static org.apache.shenyu.common.constant.Constants.SYS_DEFAULT_NAMESPACE_ID; /** * BatchRuleDeletedEvent. 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 9c87c9801b9b..7112b1d252bc 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,7 +31,7 @@ import java.util.Optional; import java.util.stream.Collectors; -import static org.apache.shenyu.common.constant.AdminConstants.SYS_DEFAULT_NAMESPACE_ID; +import static org.apache.shenyu.common.constant.Constants.SYS_DEFAULT_NAMESPACE_ID; /** * BatchPluginDeletedEvent. 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 8b3173d05833..187d8da10202 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_ID; +import static org.apache.shenyu.common.constant.Constants.SYS_DEFAULT_NAMESPACE_ID; /** * Implementation of the {@link org.apache.shenyu.admin.service.ApiService}. 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 df6537569e7c..61910be24766 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,7 +52,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.apache.shenyu.common.constant.Constants.SYS_DEFAULT_NAMESPACE_ID; /** * Implementation of the {@link org.apache.shenyu.admin.service.DataPermissionService}. 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 68da75ad6cfd..1c9635a83270 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_ID; +import static org.apache.shenyu.common.constant.Constants.SYS_DEFAULT_NAMESPACE_ID; @Service public class DiscoveryServiceImpl implements DiscoveryService { 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 1608247e9651..7adc399f4bde 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 @@ -34,6 +34,7 @@ import org.apache.shenyu.admin.transfer.NamespaceTransfer; import org.apache.shenyu.admin.utils.ShenyuResultMessage; import org.apache.shenyu.common.constant.AdminConstants; +import org.apache.shenyu.common.constant.Constants; import org.apache.shenyu.common.dto.PluginData; import org.apache.shenyu.common.utils.NamespaceIDUtils; import org.apache.shenyu.common.utils.UUIDUtils; @@ -80,7 +81,7 @@ public CommonPager listByPage(final NamespaceQuery namespaceQuery) @Override public String delete(final List ids) { - if (ids.contains(AdminConstants.DEFAULT_NAMESPACE_PRIMARY_KEY)) { + if (ids.contains(Constants.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/SelectorServiceImpl.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/SelectorServiceImpl.java index 8d8deec59873..9e6091e7bffa 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_ID; +import static org.apache.shenyu.common.constant.Constants.SYS_DEFAULT_NAMESPACE_ID; /** * Implementation of the {@link org.apache.shenyu.admin.service.SelectorService}. 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 caa251470d45..7089fbad2340 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_ID; +import static org.apache.shenyu.common.constant.Constants.SYS_DEFAULT_NAMESPACE_ID; /** * Implementation of the {@link org.apache.shenyu.admin.service.SyncDataService}. 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 7884c501b0c7..ac7c66bdb2f5 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_ID; +import static org.apache.shenyu.common.constant.Constants.SYS_DEFAULT_NAMESPACE_ID; /** * This is the upstream check service. 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 5b48b1668b17..c2a9d3574e7c 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,7 +39,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.apache.shenyu.common.constant.Constants.SYS_DEFAULT_NAMESPACE_ID; /** * NamespacePluginEventPublisher. 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 5f69991f946c..977003f9da69 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 @@ -57,7 +57,7 @@ import java.util.Objects; import java.util.stream.Collectors; -import static org.apache.shenyu.common.constant.AdminConstants.SYS_DEFAULT_NAMESPACE_ID; +import static org.apache.shenyu.common.constant.Constants.SYS_DEFAULT_NAMESPACE_ID; /** * Abstract strategy. 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 8a37050a86c7..a3ce16bc64ed 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 @@ -48,7 +48,7 @@ import java.util.concurrent.CopyOnWriteArrayList; import java.util.stream.Collectors; -import static org.apache.shenyu.common.constant.AdminConstants.SYS_DEFAULT_NAMESPACE_ID; +import static org.apache.shenyu.common.constant.Constants.SYS_DEFAULT_NAMESPACE_ID; /** * spring mvc http service register. 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 e07cb7b398b3..7bff6fb6bec1 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 @@ -48,7 +48,7 @@ import java.util.concurrent.CopyOnWriteArrayList; import java.util.stream.Collectors; -import static org.apache.shenyu.common.constant.AdminConstants.SYS_DEFAULT_NAMESPACE_ID; +import static org.apache.shenyu.common.constant.Constants.SYS_DEFAULT_NAMESPACE_ID; /** * grpc service register. 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 2ac96facba1b..57e8cc5c4277 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_ID; +import static org.apache.shenyu.common.constant.Constants.SYS_DEFAULT_NAMESPACE_ID; /** * spring mvc websocket service register. 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 217e26bffcc5..3fd232827945 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 @@ -55,7 +55,7 @@ import java.util.List; import java.util.Map; -import static org.apache.shenyu.common.constant.AdminConstants.SYS_DEFAULT_NAMESPACE_ID; +import static org.apache.shenyu.common.constant.Constants.SYS_DEFAULT_NAMESPACE_ID; import static org.hamcrest.core.Is.is; import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.mock; 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 d27b2b048df3..d55bc61b7623 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 @@ -56,7 +56,7 @@ import java.util.Collections; import java.util.List; -import static org.apache.shenyu.common.constant.AdminConstants.SYS_DEFAULT_NAMESPACE_ID; +import static org.apache.shenyu.common.constant.Constants.SYS_DEFAULT_NAMESPACE_ID; import static org.hamcrest.core.Is.is; import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.given; 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 cd785714ce48..df978633a45d 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_ID; +import static org.apache.shenyu.common.constant.Constants.SYS_DEFAULT_NAMESPACE_ID; import static org.hamcrest.core.Is.is; import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.given; 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 7354f3f36144..5cce28d4e48f 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,7 +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.apache.shenyu.common.constant.Constants.SYS_DEFAULT_NAMESPACE_ID; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.comparesEqualTo; import static org.hamcrest.Matchers.hasItems; 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 4142be797ef5..d03d0f158cc3 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 @@ -27,7 +27,7 @@ import java.util.List; import java.util.Random; -import static org.apache.shenyu.common.constant.AdminConstants.SYS_DEFAULT_NAMESPACE_ID; +import static org.apache.shenyu.common.constant.Constants.SYS_DEFAULT_NAMESPACE_ID; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.MatcherAssert.assertThat; 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 6478db06b318..59ce1936db7b 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,13 +31,12 @@ 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.apache.shenyu.common.constant.Constants.SYS_DEFAULT_NAMESPACE_ID; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.hasItems; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; - /** * Test Cases for SelectorMapper. */ 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 7a15eebbbed4..2f7cdfcaafec 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,7 +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.apache.shenyu.common.constant.Constants.SYS_DEFAULT_NAMESPACE_ID; import static org.junit.jupiter.api.Assertions.assertEquals; /** 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 8229671a9f16..dc33d99a5566 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,7 +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.apache.shenyu.common.constant.Constants.SYS_DEFAULT_NAMESPACE_ID; import static org.junit.jupiter.api.Assertions.assertEquals; /** 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 4a5b26ccc03a..6ae6bbadff02 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,7 +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.apache.shenyu.common.constant.Constants.SYS_DEFAULT_NAMESPACE_ID; import static org.junit.jupiter.api.Assertions.assertEquals; /** 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 fcf98548e183..9beab81668b4 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,7 +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.apache.shenyu.common.constant.Constants.SYS_DEFAULT_NAMESPACE_ID; import static org.junit.jupiter.api.Assertions.assertEquals; 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 53e148cbbd1b..7f4a7fa1e0c6 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,7 +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.apache.shenyu.common.constant.Constants.SYS_DEFAULT_NAMESPACE_ID; import static org.junit.jupiter.api.Assertions.assertEquals; /** 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 157ea95fe665..ad9de2f6551a 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,7 +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.apache.shenyu.common.constant.Constants.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; 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 5891d72514db..adb225a437b8 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,7 +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.apache.shenyu.common.constant.Constants.SYS_DEFAULT_NAMESPACE_ID; import static org.hamcrest.Matchers.is; import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.ArgumentMatchers.any; 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 1019d02f8fe7..954dbb3b684c 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 @@ -53,7 +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.apache.shenyu.common.constant.Constants.SYS_DEFAULT_NAMESPACE_ID; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyString; 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 1006e03fa2af..a1b9ec1081ca 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_ID; +import static org.apache.shenyu.common.constant.Constants.SYS_DEFAULT_NAMESPACE_ID; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; import static org.junit.jupiter.api.Assertions.assertEquals; 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 ef333b108ef5..aaeb9f618374 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_ID; +import static org.apache.shenyu.common.constant.Constants.SYS_DEFAULT_NAMESPACE_ID; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.greaterThan; import static org.junit.jupiter.api.Assertions.assertEquals; 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 b22d87ac806f..0714ba581b8e 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_ID; +import static org.apache.shenyu.common.constant.Constants.SYS_DEFAULT_NAMESPACE_ID; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.greaterThan; import static org.hamcrest.Matchers.notNullValue; 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 bbe42e14a14b..e3383a0c5427 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_ID; +import static org.apache.shenyu.common.constant.Constants.SYS_DEFAULT_NAMESPACE_ID; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.greaterThan; import static org.mockito.BDDMockito.given; 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 bd106d353b56..a88bfd83fca5 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_ID; +import static org.apache.shenyu.common.constant.Constants.SYS_DEFAULT_NAMESPACE_ID; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.when; import static org.mockito.Mockito.verify; 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 220233621a18..eb5ac6e0b40f 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,7 +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.apache.shenyu.common.constant.Constants.SYS_DEFAULT_NAMESPACE_ID; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doReturn; 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 0037466ffb10..5d55a199087e 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,7 +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.apache.shenyu.common.constant.Constants.SYS_DEFAULT_NAMESPACE_ID; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doReturn; 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 63ad63bab89e..8047e54b8ef3 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,7 +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.apache.shenyu.common.constant.Constants.SYS_DEFAULT_NAMESPACE_ID; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doReturn; diff --git a/shenyu-client/shenyu-client-core/src/main/java/org/apache/shenyu/client/core/client/AbstractContextRefreshedEventListener.java b/shenyu-client/shenyu-client-core/src/main/java/org/apache/shenyu/client/core/client/AbstractContextRefreshedEventListener.java index 133761c2a41a..7e48b58e7766 100644 --- a/shenyu-client/shenyu-client-core/src/main/java/org/apache/shenyu/client/core/client/AbstractContextRefreshedEventListener.java +++ b/shenyu-client/shenyu-client-core/src/main/java/org/apache/shenyu/client/core/client/AbstractContextRefreshedEventListener.java @@ -28,6 +28,7 @@ import org.apache.shenyu.client.core.disruptor.ShenyuClientRegisterEventPublisher; import org.apache.shenyu.client.core.exception.ShenyuClientIllegalArgumentException; import org.apache.shenyu.client.core.utils.OpenApiUtils; +import org.apache.shenyu.common.constant.Constants; import org.apache.shenyu.common.enums.ApiHttpMethodEnum; import org.apache.shenyu.common.enums.ApiSourceEnum; import org.apache.shenyu.common.enums.ApiStateEnum; @@ -36,7 +37,8 @@ import org.apache.shenyu.common.utils.IpUtils; import org.apache.shenyu.common.utils.UriUtils; import org.apache.shenyu.register.client.api.ShenyuClientRegisterRepository; -import org.apache.shenyu.register.common.config.PropertiesConfig; +import org.apache.shenyu.register.common.config.ShenyuClientConfig; +import org.apache.shenyu.register.common.config.ShenyuClientConfig.ClientPropertiesConfig; import org.apache.shenyu.register.common.dto.ApiDocRegisterDTO; import org.apache.shenyu.register.common.dto.MetaDataRegisterDTO; import org.apache.shenyu.register.common.dto.URIRegisterDTO; @@ -102,6 +104,11 @@ public abstract class AbstractContextRefreshedEventListener namespace; /** * Instantiates a new context refreshed event listener. @@ -109,9 +116,19 @@ public abstract class AbstractContextRefreshedEventListener namespaceIds = this.getNamespace(); + namespaceIds.forEach(namespaceId -> { + publisher.publishEvent(buildURIRegisterDTO(context, beans, namespaceId)); + }); } beans.forEach(this::handle); Map apiModules = context.getBeansWithAnnotation(ApiModule.class); @@ -255,7 +275,10 @@ private String buildDocumentJson(final List tags, final String path, fin @SuppressWarnings("all") protected abstract URIRegisterDTO buildURIRegisterDTO(ApplicationContext context, - Map beans); + Map beans, + String namespaceId); + + protected abstract String getClientName(); protected void handle(final String beanName, final T bean) { Class clazz = getCorrectedClass(bean); @@ -287,7 +310,12 @@ protected void handleClass(final Class clazz, final T bean, @NonNull final A beanShenyuClient, final String superPath) { - publisher.publishEvent(buildMetaDataDTO(bean, beanShenyuClient, pathJoin(contextPath, superPath), clazz, null)); + List namespaceIds = this.getNamespace(); + for (String namespaceId : namespaceIds) { + final MetaDataRegisterDTO metaData = buildMetaDataDTO(bean, beanShenyuClient, + pathJoin(contextPath, superPath), clazz, null, namespaceId); + publisher.publishEvent(metaData); + } } protected void handleMethod(final T bean, @@ -297,10 +325,13 @@ protected void handleMethod(final T bean, final String superPath) { A methodShenyuClient = AnnotatedElementUtils.findMergedAnnotation(method, getAnnotationType()); if (Objects.nonNull(methodShenyuClient)) { - final MetaDataRegisterDTO metaData = buildMetaDataDTO(bean, methodShenyuClient, - buildApiPath(method, superPath, methodShenyuClient), clazz, method); - publisher.publishEvent(metaData); - metaDataMap.put(method, metaData); + List namespaceIds = this.getNamespace(); + for (String namespaceId : namespaceIds) { + final MetaDataRegisterDTO metaData = buildMetaDataDTO(bean, methodShenyuClient, + buildApiPath(method, superPath, methodShenyuClient), clazz, method, namespaceId); + publisher.publishEvent(metaData); + metaDataMap.put(method, metaData); + } } } @@ -320,12 +351,17 @@ protected String pathJoin(@NonNull final String... path) { } return result.toString(); } + + protected List getNamespace() { + return namespace; + } protected abstract MetaDataRegisterDTO buildMetaDataDTO(T bean, @NonNull A shenyuClient, String path, Class clazz, - Method method); + Method method, + String namespaceId); /** * Get the event publisher. diff --git a/shenyu-client/shenyu-client-dubbo/shenyu-client-apache-dubbo/src/main/java/org/apache/shenyu/client/apache/dubbo/ApacheDubboServiceBeanListener.java b/shenyu-client/shenyu-client-dubbo/shenyu-client-apache-dubbo/src/main/java/org/apache/shenyu/client/apache/dubbo/ApacheDubboServiceBeanListener.java index 796a0a926265..17a884972bb1 100644 --- a/shenyu-client/shenyu-client-dubbo/shenyu-client-apache-dubbo/src/main/java/org/apache/shenyu/client/apache/dubbo/ApacheDubboServiceBeanListener.java +++ b/shenyu-client/shenyu-client-dubbo/shenyu-client-apache-dubbo/src/main/java/org/apache/shenyu/client/apache/dubbo/ApacheDubboServiceBeanListener.java @@ -30,7 +30,7 @@ import org.apache.shenyu.common.exception.ShenyuException; import org.apache.shenyu.common.utils.GsonUtils; import org.apache.shenyu.register.client.api.ShenyuClientRegisterRepository; -import org.apache.shenyu.register.common.config.PropertiesConfig; +import org.apache.shenyu.register.common.config.ShenyuClientConfig; import org.apache.shenyu.register.common.dto.MetaDataRegisterDTO; import org.apache.shenyu.register.common.dto.URIRegisterDTO; import org.apache.shenyu.register.common.enums.EventType; @@ -45,6 +45,7 @@ import java.lang.annotation.Annotation; import java.lang.reflect.Method; import java.util.Arrays; +import java.util.List; import java.util.Map; import java.util.Objects; import java.util.Optional; @@ -64,7 +65,7 @@ public class ApacheDubboServiceBeanListener extends AbstractContextRefreshedEven * @param clientConfig the shenyu dubbo client config * @param shenyuClientRegisterRepository the shenyuClientRegisterRepository */ - public ApacheDubboServiceBeanListener(final PropertiesConfig clientConfig, + public ApacheDubboServiceBeanListener(final ShenyuClientConfig clientConfig, final ShenyuClientRegisterRepository shenyuClientRegisterRepository) { super(clientConfig, shenyuClientRegisterRepository); } @@ -108,7 +109,8 @@ protected Class getCorrectedClass(final ServiceBean bean) { @Override protected URIRegisterDTO buildURIRegisterDTO(final ApplicationContext context, - final Map beans) { + final Map beans, + final String namespaceId) { return beans.entrySet().stream().findFirst().map(entry -> { final ServiceBean bean = entry.getValue(); return URIRegisterDTO.builder() @@ -118,10 +120,16 @@ protected URIRegisterDTO buildURIRegisterDTO(final ApplicationContext context, .eventType(EventType.REGISTER) .host(super.getHost()) .port(Integer.valueOf(getPort())) + .namespaceId(namespaceId) .build(); }).orElse(null); } + @Override + protected String getClientName() { + return RpcTypeEnum.DUBBO.getName(); + } + private String buildAppName(final ServiceBean serviceBean) { String appName = this.getAppName(); return StringUtils.isBlank(appName) ? serviceBean.getApplication().getName() : appName; @@ -146,12 +154,15 @@ protected void handleClass(final Class clazz, final ServiceBean bean, @NonNull final ShenyuDubboClient beanShenyuClient, final String superPath) { + List namespaceIds = super.getNamespace(); Method[] methods = ReflectionUtils.getDeclaredMethods(clazz); - for (Method method : methods) { - final MetaDataRegisterDTO metaData = buildMetaDataDTO(bean, beanShenyuClient, - buildApiPath(method, superPath, null), clazz, method); - getPublisher().publishEvent(metaData); - getMetaDataMap().put(method, metaData); + for (String namespaceId : namespaceIds) { + for (Method method : methods) { + final MetaDataRegisterDTO metaData = buildMetaDataDTO(bean, beanShenyuClient, + buildApiPath(method, superPath, null), clazz, method, namespaceId); + getPublisher().publishEvent(metaData); + getMetaDataMap().put(method, metaData); + } } } @@ -169,7 +180,8 @@ protected MetaDataRegisterDTO buildMetaDataDTO(final ServiceBean bean, @NonNull final ShenyuDubboClient shenyuClient, final String path, final Class clazz, - final Method method) { + final Method method, + final String namespaceId) { String appName = buildAppName(bean); String desc = shenyuClient.desc(); String serviceName = bean.getInterface(); @@ -192,6 +204,7 @@ protected MetaDataRegisterDTO buildMetaDataDTO(final ServiceBean bean, .rpcExt(buildRpcExt(bean)) .rpcType(RpcTypeEnum.DUBBO.getName()) .enabled(shenyuClient.enabled()) + .namespaceId(namespaceId) .build(); } diff --git a/shenyu-client/shenyu-client-grpc/src/main/java/org/apache/shenyu/client/grpc/GrpcClientEventListener.java b/shenyu-client/shenyu-client-grpc/src/main/java/org/apache/shenyu/client/grpc/GrpcClientEventListener.java index 62cad628c507..11a8b1645199 100644 --- a/shenyu-client/shenyu-client-grpc/src/main/java/org/apache/shenyu/client/grpc/GrpcClientEventListener.java +++ b/shenyu-client/shenyu-client-grpc/src/main/java/org/apache/shenyu/client/grpc/GrpcClientEventListener.java @@ -32,7 +32,7 @@ import org.apache.shenyu.common.enums.RpcTypeEnum; import org.apache.shenyu.common.utils.GsonUtils; import org.apache.shenyu.register.client.api.ShenyuClientRegisterRepository; -import org.apache.shenyu.register.common.config.PropertiesConfig; +import org.apache.shenyu.register.common.config.ShenyuClientConfig; import org.apache.shenyu.register.common.dto.MetaDataRegisterDTO; import org.apache.shenyu.register.common.dto.URIRegisterDTO; import org.apache.shenyu.register.common.enums.EventType; @@ -66,7 +66,7 @@ public class GrpcClientEventListener extends AbstractContextRefreshedEventListen * @param clientConfig the shenyu grpc client config * @param shenyuClientRegisterRepository the shenyuClientRegisterRepository */ - public GrpcClientEventListener(final PropertiesConfig clientConfig, final ShenyuClientRegisterRepository shenyuClientRegisterRepository) { + public GrpcClientEventListener(final ShenyuClientConfig clientConfig, final ShenyuClientRegisterRepository shenyuClientRegisterRepository) { super(clientConfig, shenyuClientRegisterRepository); if (StringUtils.isAnyBlank(getContextPath(), getIpAndPort(), getPort())) { throw new ShenyuClientIllegalArgumentException("grpc client must config the contextPath, ipAndPort"); @@ -99,7 +99,7 @@ protected Map getBeans(final ApplicationContext context } @Override - protected URIRegisterDTO buildURIRegisterDTO(final ApplicationContext context, final Map beans) { + protected URIRegisterDTO buildURIRegisterDTO(final ApplicationContext context, final Map beans, final String namespaceId) { return URIRegisterDTO.builder() .contextPath(getContextPath()) .appName(getIpAndPort()) @@ -107,9 +107,15 @@ protected URIRegisterDTO buildURIRegisterDTO(final ApplicationContext context, f .eventType(EventType.REGISTER) .host(super.getHost()) .port(Integer.parseInt(getPort())) + .namespaceId(namespaceId) .build(); } + @Override + protected String getClientName() { + return RpcTypeEnum.GRPC.getName(); + } + @Override protected String buildApiSuperPath(final Class clazz, final ShenyuGrpcClient beanShenyuClient) { if (Objects.nonNull(beanShenyuClient) && !StringUtils.isBlank(beanShenyuClient.path())) { @@ -135,18 +141,23 @@ protected String buildApiPath(final Method method, @Override protected void handleClass(final Class clazz, final BindableService bean, @NonNull final ShenyuGrpcClient beanShenyuClient, final String superPath) { Method[] methods = ReflectionUtils.getDeclaredMethods(clazz); - for (Method method : methods) { - if (Modifier.isPublic(method.getModifiers())) { - final MetaDataRegisterDTO metaData = buildMetaDataDTO(bean, beanShenyuClient, - buildApiPath(method, superPath, null), clazz, method); - getPublisher().publishEvent(metaData); - getMetaDataMap().put(method, metaData); + List namespaceIds = super.getNamespace(); + for (String namespaceId : namespaceIds) { + for (Method method : methods) { + if (Modifier.isPublic(method.getModifiers())) { + final MetaDataRegisterDTO metaData = buildMetaDataDTO(bean, beanShenyuClient, + buildApiPath(method, superPath, null), clazz, method, namespaceId); + getPublisher().publishEvent(metaData); + getMetaDataMap().put(method, metaData); + } } } } @Override - protected MetaDataRegisterDTO buildMetaDataDTO(final BindableService bean, @NonNull final ShenyuGrpcClient shenyuClient, final String path, final Class clazz, final Method method) { + protected MetaDataRegisterDTO buildMetaDataDTO(final BindableService bean, @NonNull final ShenyuGrpcClient shenyuClient, + final String path, final Class clazz, + final Method method, final String namespaceId) { String desc = shenyuClient.desc(); String configRuleName = shenyuClient.ruleName(); String ruleName = StringUtils.defaultIfBlank(configRuleName, path); @@ -170,6 +181,7 @@ protected MetaDataRegisterDTO buildMetaDataDTO(final BindableService bean, @NonN .rpcType(RpcTypeEnum.GRPC.getName()) .rpcExt(buildRpcExt(shenyuClient, methodType)) .enabled(shenyuClient.enabled()) + .namespaceId(namespaceId) .build(); } diff --git a/shenyu-client/shenyu-client-http/shenyu-client-springcloud/src/main/java/org/apache/shenyu/client/springcloud/init/SpringCloudClientEventListener.java b/shenyu-client/shenyu-client-http/shenyu-client-springcloud/src/main/java/org/apache/shenyu/client/springcloud/init/SpringCloudClientEventListener.java index ee01b2ddff9c..a6c5599fbd26 100644 --- a/shenyu-client/shenyu-client-http/shenyu-client-springcloud/src/main/java/org/apache/shenyu/client/springcloud/init/SpringCloudClientEventListener.java +++ b/shenyu-client/shenyu-client-http/shenyu-client-springcloud/src/main/java/org/apache/shenyu/client/springcloud/init/SpringCloudClientEventListener.java @@ -30,7 +30,7 @@ import org.apache.shenyu.common.exception.ShenyuException; import org.apache.shenyu.common.utils.PathUtils; import org.apache.shenyu.register.client.api.ShenyuClientRegisterRepository; -import org.apache.shenyu.register.common.config.PropertiesConfig; +import org.apache.shenyu.register.common.config.ShenyuClientConfig; import org.apache.shenyu.register.common.dto.MetaDataRegisterDTO; import org.apache.shenyu.register.common.dto.URIRegisterDTO; import org.apache.shenyu.register.common.enums.EventType; @@ -87,11 +87,11 @@ public class SpringCloudClientEventListener extends AbstractContextRefreshedEven * @param shenyuClientRegisterRepository the shenyuClientRegisterRepository * @param env the env */ - public SpringCloudClientEventListener(final PropertiesConfig clientConfig, + public SpringCloudClientEventListener(final ShenyuClientConfig clientConfig, final ShenyuClientRegisterRepository shenyuClientRegisterRepository, final Environment env) { super(clientConfig, shenyuClientRegisterRepository); - Properties props = clientConfig.getProps(); + Properties props = clientConfig.getClient().get(getClientName()).getProps(); this.env = env; if (StringUtils.isBlank(getAppName())) { String errorMsg = "spring cloud param must config the appName"; @@ -125,23 +125,27 @@ protected Sextet getBeans(final ApplicationContext context) { // Filter out is not controller out if (Boolean.TRUE.equals(isFull)) { - getPublisher().publishEvent(MetaDataRegisterDTO.builder() - .contextPath(getContextPath()) - .appName(getAppName()) - .path(UriComponentsBuilder.fromUriString(PathUtils.decoratorPathWithSlash(getContextPath()) + EVERY_PATH).build().encode().toUriString()) - .rpcType(RpcTypeEnum.SPRING_CLOUD.getName()) - .enabled(true) - .ruleName(getContextPath()) - .build()); LOG.info("init spring cloud client success with isFull mode"); - publisher.publishEvent(buildURIRegisterDTO(context, Collections.emptyMap())); + List namespaceIds = super.getNamespace(); + namespaceIds.forEach(namespaceId -> { + getPublisher().publishEvent(MetaDataRegisterDTO.builder() + .contextPath(getContextPath()) + .appName(getAppName()) + .path(UriComponentsBuilder.fromUriString(PathUtils.decoratorPathWithSlash(getContextPath()) + EVERY_PATH).build().encode().toUriString()) + .rpcType(RpcTypeEnum.SPRING_CLOUD.getName()) + .enabled(true) + .ruleName(getContextPath()) + .namespaceId(namespaceId) + .build()); + publisher.publishEvent(buildURIRegisterDTO(context, Collections.emptyMap(), namespaceId)); + }); return Collections.emptyMap(); } return context.getBeansWithAnnotation(Controller.class); } @Override - protected URIRegisterDTO buildURIRegisterDTO(final ApplicationContext context, final Map beans) { + protected URIRegisterDTO buildURIRegisterDTO(final ApplicationContext context, final Map beans, final String namespaceId) { try { return URIRegisterDTO.builder() .contextPath(getContextPath()) @@ -150,12 +154,18 @@ protected URIRegisterDTO buildURIRegisterDTO(final ApplicationContext context, f .port(Integer.valueOf(getPort())) .rpcType(RpcTypeEnum.SPRING_CLOUD.getName()) .eventType(EventType.REGISTER) + .namespaceId(namespaceId) .build(); } catch (ShenyuException e) { throw new ShenyuException(e.getMessage() + "please config ${shenyu.client.http.props.port} in xml/yml !"); } } - + + @Override + protected String getClientName() { + return RpcTypeEnum.SPRING_CLOUD.getName(); + } + @Override protected void handleMethod(final Object bean, final Class clazz, @Nullable final ShenyuSpringCloudClient beanShenyuClient, final Method method, @@ -166,10 +176,13 @@ protected void handleMethod(final Object bean, final Class clazz, // the result of ReflectionUtils#getUniqueDeclaredMethods contains methods such as hashCode, wait, toSting // add Objects.nonNull(requestMapping) to make sure not register wrong method if (Objects.nonNull(methodShenyuClient) && Objects.nonNull(requestMapping)) { - final MetaDataRegisterDTO metaData = buildMetaDataDTO(bean, methodShenyuClient, - buildApiPath(method, superPath, methodShenyuClient), clazz, method); - getPublisher().publishEvent(metaData); - getMetaDataMap().put(method, metaData); + List namespaceIds = super.getNamespace(); + for (String namespaceId : namespaceIds) { + final MetaDataRegisterDTO metaData = buildMetaDataDTO(bean, methodShenyuClient, + buildApiPath(method, superPath, methodShenyuClient), clazz, method, namespaceId); + getPublisher().publishEvent(metaData); + getMetaDataMap().put(method, metaData); + } } } @@ -235,7 +248,7 @@ protected Class getAnnotationType() { @Override protected MetaDataRegisterDTO buildMetaDataDTO(final Object bean, final @NonNull ShenyuSpringCloudClient shenyuClient, - final String path, final Class clazz, final Method method) { + final String path, final Class clazz, final Method method, final String namespaceId) { return MetaDataRegisterDTO.builder() .contextPath(StringUtils.defaultIfBlank(getContextPath(), this.servletContextPath)) .addPrefixed(addPrefixed) @@ -252,6 +265,7 @@ protected MetaDataRegisterDTO buildMetaDataDTO(final Object bean, .rpcType(RpcTypeEnum.SPRING_CLOUD.getName()) .enabled(shenyuClient.enabled()) .ruleName(StringUtils.defaultIfBlank(shenyuClient.ruleName(), path)) + .namespaceId(namespaceId) .build(); } diff --git a/shenyu-client/shenyu-client-http/shenyu-client-springcloud/src/test/java/org/apache/shenyu/client/springcloud/init/SpringCloudClientEventListenerTest.java b/shenyu-client/shenyu-client-http/shenyu-client-springcloud/src/test/java/org/apache/shenyu/client/springcloud/init/SpringCloudClientEventListenerTest.java index 176c3402e69e..0afa0f40a3ed 100644 --- a/shenyu-client/shenyu-client-http/shenyu-client-springcloud/src/test/java/org/apache/shenyu/client/springcloud/init/SpringCloudClientEventListenerTest.java +++ b/shenyu-client/shenyu-client-http/shenyu-client-springcloud/src/test/java/org/apache/shenyu/client/springcloud/init/SpringCloudClientEventListenerTest.java @@ -20,8 +20,10 @@ import org.apache.shenyu.client.core.exception.ShenyuClientIllegalArgumentException; import org.apache.shenyu.client.core.register.ShenyuClientRegisterRepositoryFactory; import org.apache.shenyu.client.springcloud.annotation.ShenyuSpringCloudClient; +import org.apache.shenyu.common.enums.RpcTypeEnum; import org.apache.shenyu.register.client.http.utils.RegisterUtils; -import org.apache.shenyu.register.common.config.PropertiesConfig; +import org.apache.shenyu.register.common.config.ShenyuClientConfig; +import org.apache.shenyu.register.common.config.ShenyuClientConfig.ClientPropertiesConfig; import org.apache.shenyu.register.common.config.ShenyuRegisterCenterConfig; import org.junit.Assert; import org.junit.jupiter.api.BeforeEach; @@ -124,17 +126,22 @@ private SpringCloudClientEventListener buildSpringCloudClientEventListener(final properties.setProperty("port", "8081"); properties.setProperty("username", "admin"); properties.setProperty("password", "123456"); - PropertiesConfig config = new PropertiesConfig(); + ClientPropertiesConfig config = new ClientPropertiesConfig(); config.setProps(properties); ShenyuRegisterCenterConfig mockRegisterCenter = new ShenyuRegisterCenterConfig(); mockRegisterCenter.setServerLists("http://127.0.0.1:8080"); mockRegisterCenter.setRegisterType("http"); mockRegisterCenter.setProps(properties); + ShenyuClientConfig clientConfig = new ShenyuClientConfig(); + Map client = new LinkedHashMap<>(); + client.put(RpcTypeEnum.SPRING_CLOUD.getName(), config); + clientConfig.setClient(client); // hit error when(env.getProperty("spring.application.name")).thenReturn(""); - Assert.assertThrows(ShenyuClientIllegalArgumentException.class, () -> new SpringCloudClientEventListener(config, ShenyuClientRegisterRepositoryFactory.newInstance(mockRegisterCenter), env)); + Assert.assertThrows(ShenyuClientIllegalArgumentException.class, + () -> new SpringCloudClientEventListener(clientConfig, ShenyuClientRegisterRepositoryFactory.newInstance(mockRegisterCenter), env)); when(env.getProperty("spring.application.name")).thenReturn("spring-cloud-test"); - return new SpringCloudClientEventListener(config, ShenyuClientRegisterRepositoryFactory.newInstance(mockRegisterCenter), env); + return new SpringCloudClientEventListener(clientConfig, ShenyuClientRegisterRepositoryFactory.newInstance(mockRegisterCenter), env); } @RestController diff --git a/shenyu-client/shenyu-client-http/shenyu-client-springmvc/src/main/java/org/apache/shenyu/client/springmvc/init/SpringMvcClientEventListener.java b/shenyu-client/shenyu-client-http/shenyu-client-springmvc/src/main/java/org/apache/shenyu/client/springmvc/init/SpringMvcClientEventListener.java index ab14c638130d..568bb91ab64e 100644 --- a/shenyu-client/shenyu-client-http/shenyu-client-springmvc/src/main/java/org/apache/shenyu/client/springmvc/init/SpringMvcClientEventListener.java +++ b/shenyu-client/shenyu-client-http/shenyu-client-springmvc/src/main/java/org/apache/shenyu/client/springmvc/init/SpringMvcClientEventListener.java @@ -29,7 +29,7 @@ import org.apache.shenyu.common.exception.ShenyuException; import org.apache.shenyu.common.utils.PathUtils; import org.apache.shenyu.register.client.api.ShenyuClientRegisterRepository; -import org.apache.shenyu.register.common.config.PropertiesConfig; +import org.apache.shenyu.register.common.config.ShenyuClientConfig; import org.apache.shenyu.register.common.dto.ApiDocRegisterDTO; import org.apache.shenyu.register.common.dto.MetaDataRegisterDTO; import org.apache.shenyu.register.common.dto.URIRegisterDTO; @@ -87,12 +87,12 @@ public class SpringMvcClientEventListener extends AbstractContextRefreshedEventL * @param shenyuClientRegisterRepository the shenyuClientRegisterRepository * @param env the env */ - public SpringMvcClientEventListener(final PropertiesConfig clientConfig, + public SpringMvcClientEventListener(final ShenyuClientConfig clientConfig, final ShenyuClientRegisterRepository shenyuClientRegisterRepository, final Environment env) { super(clientConfig, shenyuClientRegisterRepository); this.env = env; - Properties props = clientConfig.getProps(); + Properties props = clientConfig.getClient().get(getClientName()).getProps(); this.isFull = Boolean.parseBoolean(props.getProperty(ShenyuClientConstants.IS_FULL, Boolean.FALSE.toString())); this.protocol = props.getProperty(ShenyuClientConstants.PROTOCOL, ShenyuClientConstants.HTTP); this.addPrefixed = Boolean.parseBoolean(props.getProperty(ShenyuClientConstants.ADD_PREFIXED, @@ -121,17 +121,22 @@ protected Sextet getBeans(final ApplicationContext context) { // Filter out if (Boolean.TRUE.equals(isFull)) { - getPublisher().publishEvent(MetaDataRegisterDTO.builder() - .contextPath(getContextPath()) - .addPrefixed(addPrefixed) - .appName(getAppName()) - .path(UriComponentsBuilder.fromUriString(PathUtils.decoratorPathWithSlash(getContextPath()) + EVERY_PATH).build().encode().toUriString()) - .rpcType(RpcTypeEnum.HTTP.getName()) - .enabled(true) - .ruleName(getContextPath()) - .build()); LOG.info("init spring mvc client success with isFull mode"); - publisher.publishEvent(buildURIRegisterDTO(context, Collections.emptyMap())); + List namespaceIds = super.getNamespace(); + namespaceIds.forEach(namespaceId -> { + getPublisher().publishEvent(MetaDataRegisterDTO.builder() + .contextPath(getContextPath()) + .addPrefixed(addPrefixed) + .appName(getAppName()) + .path(UriComponentsBuilder.fromUriString(PathUtils.decoratorPathWithSlash(getContextPath()) + EVERY_PATH).build().encode().toUriString()) + .rpcType(RpcTypeEnum.HTTP.getName()) + .enabled(true) + .ruleName(getContextPath()) + .namespaceId(namespaceId) + .build()); + + publisher.publishEvent(buildURIRegisterDTO(context, Collections.emptyMap(), namespaceId)); + }); return Collections.emptyMap(); } return context.getBeansWithAnnotation(Controller.class); @@ -139,7 +144,8 @@ protected Map getBeans(final ApplicationContext context) { @Override protected URIRegisterDTO buildURIRegisterDTO(final ApplicationContext context, - final Map beans) { + final Map beans, + final String namespaceId) { try { return URIRegisterDTO.builder() .contextPath(getContextPath()) @@ -149,12 +155,18 @@ protected URIRegisterDTO buildURIRegisterDTO(final ApplicationContext context, .port(Integer.valueOf(getPort())) .rpcType(RpcTypeEnum.HTTP.getName()) .eventType(EventType.REGISTER) + .namespaceId(namespaceId) .build(); } catch (ShenyuException e) { throw new ShenyuException(e.getMessage() + "please config ${shenyu.client.http.props.port} in xml/yml !"); } } - + + @Override + protected String getClientName() { + return RpcTypeEnum.HTTP.getName(); + } + @Override protected String buildApiSuperPath(final Class clazz, @Nullable final ShenyuSpringMvcClient beanShenyuClient) { final String servletPath = StringUtils.defaultString(this.env.getProperty("spring.mvc.servlet.path"), ""); @@ -186,10 +198,13 @@ protected void handleMethod(final Object bean, final Class clazz, // the result of ReflectionUtils#getUniqueDeclaredMethods contains method such as hashCode, wait, toSting // add Objects.nonNull(requestMapping) to make sure not register wrong method if (Objects.nonNull(methodShenyuClient) && Objects.nonNull(requestMapping)) { - final MetaDataRegisterDTO metaData = buildMetaDataDTO(bean, methodShenyuClient, - buildApiPath(method, superPath, methodShenyuClient), clazz, method); - getPublisher().publishEvent(metaData); - getMetaDataMap().put(method, metaData); + List namespaceIds = super.getNamespace(); + for (String namespaceId : namespaceIds) { + final MetaDataRegisterDTO metaData = buildMetaDataDTO(bean, methodShenyuClient, + buildApiPath(method, superPath, methodShenyuClient), clazz, method, namespaceId); + getPublisher().publishEvent(metaData); + getMetaDataMap().put(method, metaData); + } } } @@ -240,7 +255,8 @@ private String getPathByAnnotation(@Nullable final Annotation annotation) { protected MetaDataRegisterDTO buildMetaDataDTO(final Object bean, @NonNull final ShenyuSpringMvcClient shenyuClient, final String path, final Class clazz, - final Method method) { + final Method method, + final String namespaceId) { return MetaDataRegisterDTO.builder() .contextPath(getContextPath()) .addPrefixed(addPrefixed) @@ -258,6 +274,7 @@ protected MetaDataRegisterDTO buildMetaDataDTO(final Object bean, .enabled(shenyuClient.enabled()) .ruleName(StringUtils.defaultIfBlank(shenyuClient.ruleName(), path)) .registerMetaData(shenyuClient.registerMetaData()) + .namespaceId(namespaceId) .build(); } diff --git a/shenyu-client/shenyu-client-http/shenyu-client-springmvc/src/test/java/org/apache/shenyu/client/springmvc/init/SpringMvcClientEventListenerTest.java b/shenyu-client/shenyu-client-http/shenyu-client-springmvc/src/test/java/org/apache/shenyu/client/springmvc/init/SpringMvcClientEventListenerTest.java index 182a65f2ebb5..a9e4ba8c49e2 100644 --- a/shenyu-client/shenyu-client-http/shenyu-client-springmvc/src/test/java/org/apache/shenyu/client/springmvc/init/SpringMvcClientEventListenerTest.java +++ b/shenyu-client/shenyu-client-http/shenyu-client-springmvc/src/test/java/org/apache/shenyu/client/springmvc/init/SpringMvcClientEventListenerTest.java @@ -25,7 +25,8 @@ import org.apache.shenyu.client.core.utils.PortUtils; import org.apache.shenyu.register.client.api.ShenyuClientRegisterRepository; import org.apache.shenyu.register.client.http.utils.RegisterUtils; -import org.apache.shenyu.register.common.config.PropertiesConfig; +import org.apache.shenyu.register.common.config.ShenyuClientConfig; +import org.apache.shenyu.register.common.config.ShenyuClientConfig.ClientPropertiesConfig; import org.apache.shenyu.register.common.config.ShenyuRegisterCenterConfig; import org.junit.Assert; import org.junit.jupiter.api.Assertions; @@ -45,6 +46,7 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import java.util.HashMap; import java.util.LinkedHashMap; import java.util.Map; import java.util.Optional; @@ -93,11 +95,8 @@ private void init() { results.put("springMvcClientTestBean4", springMvcClientTestBean4); when(applicationContext.getBeansWithAnnotation(any())).thenReturn(results); contextRefreshedEvent = new ContextRefreshedEvent(applicationContext); - Properties properties = mock(Properties.class); - - PropertiesConfig clientConfig = mock(PropertiesConfig.class); - when(clientConfig.getProps()).thenReturn(properties); - Assert.assertThrows(ShenyuClientIllegalArgumentException.class, () -> new SpringMvcClientEventListener(clientConfig, mock(ShenyuClientRegisterRepository.class), env)); + ShenyuClientConfig shenyuClientConfig = mock(ShenyuClientConfig.class); + Assert.assertThrows(ShenyuClientIllegalArgumentException.class, () -> new SpringMvcClientEventListener(shenyuClientConfig, mock(ShenyuClientRegisterRepository.class), env)); } @Test @@ -143,13 +142,17 @@ private SpringMvcClientEventListener buildSpringMvcClientEventListener(final boo properties.setProperty("username", "admin"); properties.setProperty("password", "123456"); properties.setProperty(ShenyuClientConstants.DISCOVERY_LOCAL_MODE_KEY, Boolean.TRUE.toString()); - PropertiesConfig config = new PropertiesConfig(); + ShenyuClientConfig.ClientPropertiesConfig config = new ShenyuClientConfig.ClientPropertiesConfig(); config.setProps(properties); ShenyuRegisterCenterConfig mockRegisterCenter = new ShenyuRegisterCenterConfig(); mockRegisterCenter.setServerLists("http://127.0.0.1:9095"); mockRegisterCenter.setRegisterType("http"); mockRegisterCenter.setProps(properties); - return new SpringMvcClientEventListener(config, ShenyuClientRegisterRepositoryFactory.newInstance(mockRegisterCenter), env); + ShenyuClientConfig shenyuClientConfig = new ShenyuClientConfig(); + Map client = new HashMap<>(); + client.put("http", config); + shenyuClientConfig.setClient(client); + return new SpringMvcClientEventListener(shenyuClientConfig, ShenyuClientRegisterRepositoryFactory.newInstance(mockRegisterCenter), env); } @Test diff --git a/shenyu-client/shenyu-client-motan/src/main/java/org/apache/shenyu/client/motan/MotanServiceEventListener.java b/shenyu-client/shenyu-client-motan/src/main/java/org/apache/shenyu/client/motan/MotanServiceEventListener.java index d42f2d0cd1e5..7c23e85d976e 100644 --- a/shenyu-client/shenyu-client-motan/src/main/java/org/apache/shenyu/client/motan/MotanServiceEventListener.java +++ b/shenyu-client/shenyu-client-motan/src/main/java/org/apache/shenyu/client/motan/MotanServiceEventListener.java @@ -31,7 +31,7 @@ import org.apache.shenyu.common.enums.RpcTypeEnum; import org.apache.shenyu.common.utils.GsonUtils; import org.apache.shenyu.register.client.api.ShenyuClientRegisterRepository; -import org.apache.shenyu.register.common.config.PropertiesConfig; +import org.apache.shenyu.register.common.config.ShenyuClientConfig; import org.apache.shenyu.register.common.dto.MetaDataRegisterDTO; import org.apache.shenyu.register.common.dto.URIRegisterDTO; import org.apache.shenyu.register.common.enums.EventType; @@ -67,7 +67,7 @@ public class MotanServiceEventListener extends AbstractContextRefreshedEventList private String group; - public MotanServiceEventListener(final PropertiesConfig clientConfig, + public MotanServiceEventListener(final ShenyuClientConfig clientConfig, final ShenyuClientRegisterRepository shenyuClientRegisterRepository) { super(clientConfig, shenyuClientRegisterRepository); } @@ -94,7 +94,9 @@ protected Map getBeans(final ApplicationContext context) { } @Override - protected URIRegisterDTO buildURIRegisterDTO(final ApplicationContext context, final Map beans) { + protected URIRegisterDTO buildURIRegisterDTO(final ApplicationContext context, + final Map beans, + final String namespaceId) { return URIRegisterDTO.builder() .contextPath(this.getContextPath()) .appName(this.getAppName()) @@ -102,9 +104,15 @@ protected URIRegisterDTO buildURIRegisterDTO(final ApplicationContext context, f .eventType(EventType.REGISTER) .host(this.getHost()) .port(Integer.parseInt(this.getPort())) + .namespaceId(namespaceId) .build(); } - + + @Override + protected String getClientName() { + return RpcTypeEnum.MOTAN.getName(); + } + @Override protected String buildApiSuperPath(final Class clazz, final ShenyuMotanClient shenyuMotanClient) { if (Objects.nonNull(shenyuMotanClient) && !StringUtils.isBlank(shenyuMotanClient.path())) { @@ -123,7 +131,8 @@ protected MetaDataRegisterDTO buildMetaDataDTO(final Object bean, final ShenyuMotanClient shenyuMotanClient, final String path, final Class clazz, - final Method method) { + final Method method, + final String namespaceId) { Integer timeout = Optional.ofNullable(((BasicServiceConfigBean) applicationContext.getBean(BASE_SERVICE_CONFIG)).getRequestTimeout()).orElse(1000); MotanService service = AnnotatedElementUtils.findMergedAnnotation(clazz, MotanService.class); String desc = shenyuMotanClient.desc(); @@ -159,6 +168,7 @@ protected MetaDataRegisterDTO buildMetaDataDTO(final Object bean, .rpcType(RpcTypeEnum.MOTAN.getName()) .rpcExt(buildRpcExt(method, timeout, protocol)) .enabled(shenyuMotanClient.enabled()) + .namespaceId(namespaceId) .build(); } @@ -174,11 +184,14 @@ protected String buildApiPath(final Method method, @Override protected void handleClass(final Class clazz, final Object bean, final ShenyuMotanClient beanShenyuClient, final String superPath) { Method[] methods = ReflectionUtils.getDeclaredMethods(clazz); - for (Method method : methods) { - final MetaDataRegisterDTO metaData = buildMetaDataDTO(bean, beanShenyuClient, - buildApiPath(method, superPath, null), clazz, method); - publisher.publishEvent(metaData); - getMetaDataMap().put(method, metaData); + List namespaceIds = super.getNamespace(); + for (String namespaceId : namespaceIds) { + for (Method method : methods) { + final MetaDataRegisterDTO metaData = buildMetaDataDTO(bean, beanShenyuClient, + buildApiPath(method, superPath, null), clazz, method, namespaceId); + publisher.publishEvent(metaData); + getMetaDataMap().put(method, metaData); + } } } diff --git a/shenyu-client/shenyu-client-sofa/src/main/java/org/apache/shenyu/client/sofa/SofaServiceEventListener.java b/shenyu-client/shenyu-client-sofa/src/main/java/org/apache/shenyu/client/sofa/SofaServiceEventListener.java index 35e4208a618a..167c580da687 100644 --- a/shenyu-client/shenyu-client-sofa/src/main/java/org/apache/shenyu/client/sofa/SofaServiceEventListener.java +++ b/shenyu-client/shenyu-client-sofa/src/main/java/org/apache/shenyu/client/sofa/SofaServiceEventListener.java @@ -28,7 +28,7 @@ import org.apache.shenyu.common.enums.RpcTypeEnum; import org.apache.shenyu.common.utils.GsonUtils; import org.apache.shenyu.register.client.api.ShenyuClientRegisterRepository; -import org.apache.shenyu.register.common.config.PropertiesConfig; +import org.apache.shenyu.register.common.config.ShenyuClientConfig; import org.apache.shenyu.register.common.dto.MetaDataRegisterDTO; import org.apache.shenyu.register.common.dto.URIRegisterDTO; import org.apache.shenyu.register.common.enums.EventType; @@ -47,6 +47,7 @@ import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; import java.util.Arrays; +import java.util.List; import java.util.Map; import java.util.Objects; import java.util.stream.Collectors; @@ -58,7 +59,7 @@ public class SofaServiceEventListener extends AbstractContextRefreshedEventListe private static final Logger LOG = LoggerFactory.getLogger(SofaServiceEventListener.class); - public SofaServiceEventListener(final PropertiesConfig clientConfig, final ShenyuClientRegisterRepository shenyuClientRegisterRepository) { + public SofaServiceEventListener(final ShenyuClientConfig clientConfig, final ShenyuClientRegisterRepository shenyuClientRegisterRepository) { super(clientConfig, shenyuClientRegisterRepository); } @@ -69,7 +70,8 @@ protected Map getBeans(final ApplicationContext cont @Override protected URIRegisterDTO buildURIRegisterDTO(final ApplicationContext context, - final Map beans) { + final Map beans, + final String namespaceId) { return URIRegisterDTO.builder() .contextPath(this.getContextPath()) .appName(this.getAppName()) @@ -77,9 +79,15 @@ protected URIRegisterDTO buildURIRegisterDTO(final ApplicationContext context, .eventType(EventType.REGISTER) .host(super.getHost()) .port(Integer.parseInt(getPort())) + .namespaceId(namespaceId) .build(); } - + + @Override + protected String getClientName() { + return RpcTypeEnum.SOFA.getName(); + } + @Override protected String buildApiSuperPath(final Class clazz, final ShenyuSofaClient beanShenyuClient) { @@ -108,7 +116,8 @@ protected MetaDataRegisterDTO buildMetaDataDTO(final ServiceFactoryBean serviceB @NonNull final ShenyuSofaClient shenyuSofaClient, final String superPath, final Class clazz, - final Method method) { + final Method method, + final String namespaceId) { String appName = this.getAppName(); String contextPath = this.getContextPath(); String path = pathJoin(contextPath, superPath, shenyuSofaClient.path()); @@ -143,6 +152,7 @@ protected MetaDataRegisterDTO buildMetaDataDTO(final ServiceFactoryBean serviceB .rpcType(RpcTypeEnum.SOFA.getName()) .rpcExt(buildRpcExt(shenyuSofaClient)) .enabled(shenyuSofaClient.enabled()) + .namespaceId(namespaceId) .build(); } @@ -184,18 +194,23 @@ private void handler(final ServiceFactoryBean serviceBean) { } final ShenyuSofaClient beanSofaClient = AnnotatedElementUtils.findMergedAnnotation(clazz, ShenyuSofaClient.class); final String superPath = buildApiSuperPath(clazz, beanSofaClient); + List namespaceIds = super.getNamespace(); if (superPath.contains("*") && Objects.nonNull(beanSofaClient)) { Method[] declaredMethods = ReflectionUtils.getDeclaredMethods(clazz); - for (Method declaredMethod : declaredMethods) { - getPublisher().publishEvent(buildMetaDataDTO(serviceBean, beanSofaClient, superPath, clazz, declaredMethod)); + for (String namespaceId : namespaceIds) { + for (Method declaredMethod : declaredMethods) { + getPublisher().publishEvent(buildMetaDataDTO(serviceBean, beanSofaClient, superPath, clazz, declaredMethod, namespaceId)); + } } return; } Method[] methods = ReflectionUtils.getUniqueDeclaredMethods(clazz); - for (Method method : methods) { - ShenyuSofaClient methodSofaClient = AnnotatedElementUtils.findMergedAnnotation(method, ShenyuSofaClient.class); - if (Objects.nonNull(methodSofaClient)) { - getPublisher().publishEvent(buildMetaDataDTO(serviceBean, methodSofaClient, superPath, clazz, method)); + for (String namespaceId : namespaceIds) { + for (Method method : methods) { + ShenyuSofaClient methodSofaClient = AnnotatedElementUtils.findMergedAnnotation(method, ShenyuSofaClient.class); + if (Objects.nonNull(methodSofaClient)) { + getPublisher().publishEvent(buildMetaDataDTO(serviceBean, methodSofaClient, superPath, clazz, method, namespaceId)); + } } } } diff --git a/shenyu-client/shenyu-client-sofa/src/test/java/org/apache/shenyu/client/sofa/SofaServiceEventListenerTest.java b/shenyu-client/shenyu-client-sofa/src/test/java/org/apache/shenyu/client/sofa/SofaServiceEventListenerTest.java index 6a03afbcbafb..a38615c987d7 100644 --- a/shenyu-client/shenyu-client-sofa/src/test/java/org/apache/shenyu/client/sofa/SofaServiceEventListenerTest.java +++ b/shenyu-client/shenyu-client-sofa/src/test/java/org/apache/shenyu/client/sofa/SofaServiceEventListenerTest.java @@ -20,8 +20,10 @@ import com.alipay.sofa.runtime.spring.factory.ServiceFactoryBean; import org.apache.shenyu.client.core.register.ShenyuClientRegisterRepositoryFactory; import org.apache.shenyu.client.sofa.common.annotation.ShenyuSofaClient; +import org.apache.shenyu.common.constant.Constants; import org.apache.shenyu.common.enums.RpcTypeEnum; -import org.apache.shenyu.register.common.config.PropertiesConfig; +import org.apache.shenyu.register.common.config.ShenyuClientConfig; +import org.apache.shenyu.register.common.config.ShenyuClientConfig.ClientPropertiesConfig; import org.apache.shenyu.register.common.config.ShenyuRegisterCenterConfig; import org.apache.shenyu.register.common.dto.MetaDataRegisterDTO; import org.apache.shenyu.register.common.dto.URIRegisterDTO; @@ -119,9 +121,10 @@ public void testBuildURIRegisterDTO() { .eventType(EventType.REGISTER) .host(HOST) .port(Integer.parseInt(PORT)) + .namespaceId(Constants.SYS_DEFAULT_NAMESPACE_ID) .build(); Map beans = new HashMap<>(); - URIRegisterDTO realURIRegisterDTO = sofaServiceEventListener.buildURIRegisterDTO(applicationContext, beans); + URIRegisterDTO realURIRegisterDTO = sofaServiceEventListener.buildURIRegisterDTO(applicationContext, beans, Constants.SYS_DEFAULT_NAMESPACE_ID); assertEquals(expectedURIRegisterDTO, realURIRegisterDTO); } @@ -184,7 +187,7 @@ public void testBuildApiPathSuperPathNotContainsStar() { public void testBuildMetaDataDTO() throws NoSuchMethodException { Method method = SofaServiceEventListener .class - .getDeclaredMethod(METHOD_NAME, ApplicationContext.class, Map.class); + .getDeclaredMethod(METHOD_NAME, ApplicationContext.class, Map.class, String.class); given(shenyuSofaClient.path()).willReturn(PATH); given(shenyuSofaClient.desc()).willReturn(DESC); given(shenyuSofaClient.ruleName()).willReturn(CONFIG_RULE_NAME); @@ -197,7 +200,7 @@ public void testBuildMetaDataDTO() throws NoSuchMethodException { doReturn(Comparable.class).when(serviceFactoryBean).getInterfaceClass(); String expectedParameterTypes = "org.springframework.context.ApplicationContext,java.util.Map#java.lang.String#" - + "com.alipay.sofa.runtime.spring.factory.ServiceFactoryBean"; + + "com.alipay.sofa.runtime.spring.factory.ServiceFactoryBean,java.lang.String"; String expectedPath = "/sofa/findByIdsAndName/path"; String expectedRpcExt = "{\"loadbalance\":\"loadBalance\",\"retries\":0,\"timeout\":0}"; @@ -207,7 +210,7 @@ public void testBuildMetaDataDTO() throws NoSuchMethodException { shenyuSofaClient, SUPER_PATH_NOT_CONTAINS_STAR, SofaServiceEventListener.class, - method); + method, Constants.SYS_DEFAULT_NAMESPACE_ID); MetaDataRegisterDTO expectedMetaDataRegisterDTO = MetaDataRegisterDTO .builder() .appName(APP_NAME) @@ -223,6 +226,7 @@ public void testBuildMetaDataDTO() throws NoSuchMethodException { .rpcType(RpcTypeEnum.SOFA.getName()) .rpcExt(expectedRpcExt) .enabled(ENABLED) + .namespaceId(Constants.SYS_DEFAULT_NAMESPACE_ID) .build(); assertEquals(expectedMetaDataRegisterDTO, realMetaDataRegisterDTO); @@ -236,15 +240,20 @@ private SofaServiceEventListener buildSofaServiceEventListener() { properties.setProperty("username", USERNAME); properties.setProperty("password", PASSWORD); properties.setProperty("appName", APP_NAME); - PropertiesConfig config = new PropertiesConfig(); + ClientPropertiesConfig config = new ClientPropertiesConfig(); config.setProps(properties); + + ShenyuClientConfig clientConfig = new ShenyuClientConfig(); + Map client = new HashMap<>(); + client.put(RpcTypeEnum.SOFA.getName(), config); + clientConfig.setClient(client); ShenyuRegisterCenterConfig mockRegisterCenter = new ShenyuRegisterCenterConfig(); mockRegisterCenter.setServerLists("http://localhost:58080"); mockRegisterCenter.setRegisterType("http"); mockRegisterCenter.setProps(properties); - return new SofaServiceEventListener(config, ShenyuClientRegisterRepositoryFactory.newInstance(mockRegisterCenter)); + return new SofaServiceEventListener(clientConfig, ShenyuClientRegisterRepositoryFactory.newInstance(mockRegisterCenter)); } } diff --git a/shenyu-client/shenyu-client-tars/src/main/java/org/apache/shenyu/client/tars/TarsServiceBeanEventListener.java b/shenyu-client/shenyu-client-tars/src/main/java/org/apache/shenyu/client/tars/TarsServiceBeanEventListener.java index fe7501f0468a..59891e1a79e4 100644 --- a/shenyu-client/shenyu-client-tars/src/main/java/org/apache/shenyu/client/tars/TarsServiceBeanEventListener.java +++ b/shenyu-client/shenyu-client-tars/src/main/java/org/apache/shenyu/client/tars/TarsServiceBeanEventListener.java @@ -30,7 +30,7 @@ import org.apache.shenyu.common.enums.RpcTypeEnum; import org.apache.shenyu.common.utils.GsonUtils; import org.apache.shenyu.register.client.api.ShenyuClientRegisterRepository; -import org.apache.shenyu.register.common.config.PropertiesConfig; +import org.apache.shenyu.register.common.config.ShenyuClientConfig; import org.apache.shenyu.register.common.dto.MetaDataRegisterDTO; import org.apache.shenyu.register.common.dto.URIRegisterDTO; import org.apache.shenyu.register.common.enums.EventType; @@ -67,9 +67,9 @@ public class TarsServiceBeanEventListener extends AbstractContextRefreshedEventL private final String ipAndPort; - public TarsServiceBeanEventListener(final PropertiesConfig clientConfig, final ShenyuClientRegisterRepository shenyuClientRegisterRepository) { + public TarsServiceBeanEventListener(final ShenyuClientConfig clientConfig, final ShenyuClientRegisterRepository shenyuClientRegisterRepository) { super(clientConfig, shenyuClientRegisterRepository); - Properties props = clientConfig.getProps(); + Properties props = clientConfig.getClient().get(getClientName()).getProps(); String contextPath = props.getProperty(ShenyuClientConstants.CONTEXT_PATH); String port = props.getProperty(ShenyuClientConstants.PORT); if (StringUtils.isAnyBlank(contextPath, this.getHost(), port)) { @@ -101,7 +101,8 @@ protected Map getBeans(final ApplicationContext context) { @Override protected URIRegisterDTO buildURIRegisterDTO(final ApplicationContext context, - final Map beans) { + final Map beans, + final String namespaceId) { return URIRegisterDTO.builder() .contextPath(this.contextPath) .appName(this.ipAndPort) @@ -109,9 +110,15 @@ protected URIRegisterDTO buildURIRegisterDTO(final ApplicationContext context, .eventType(EventType.REGISTER) .host(this.getHost()) .port(Integer.parseInt(this.getPort())) + .namespaceId(namespaceId) .build(); } - + + @Override + protected String getClientName() { + return RpcTypeEnum.TARS.getName(); + } + @Override protected String buildApiSuperPath(final Class clazz, @Nullable final ShenyuTarsClient shenyuTarsClient) { if (Objects.nonNull(shenyuTarsClient) && !StringUtils.isBlank(shenyuTarsClient.path())) { @@ -133,18 +140,23 @@ public void handle(final String beanName, final Object bean) { } final ShenyuTarsClient beanTarsClient = AnnotatedElementUtils.findMergedAnnotation(clazz, ShenyuTarsClient.class); final String superPath = buildApiSuperPath(clazz, beanTarsClient); + List namespaceIds = super.getNamespace(); if (superPath.contains("*") && Objects.nonNull(beanTarsClient)) { Method[] declaredMethods = ReflectionUtils.getDeclaredMethods(clazz); - for (Method declaredMethod : declaredMethods) { - publisher.publishEvent(buildMetaDataDTO(bean, beanTarsClient, buildApiPath(declaredMethod, superPath, beanTarsClient), clazz, declaredMethod)); + for (String namespaceId : namespaceIds) { + for (Method declaredMethod : declaredMethods) { + publisher.publishEvent(buildMetaDataDTO(bean, beanTarsClient, buildApiPath(declaredMethod, superPath, beanTarsClient), clazz, declaredMethod, namespaceId)); + } } return; } Method[] methods = ReflectionUtils.getUniqueDeclaredMethods(clazz); - for (Method method : methods) { - ShenyuTarsClient shenyuTarsClient = AnnotatedElementUtils.findMergedAnnotation(method, ShenyuTarsClient.class); - if (Objects.nonNull(shenyuTarsClient)) { - publisher.publishEvent(buildMetaDataDTO(bean, shenyuTarsClient, buildApiPath(method, superPath, shenyuTarsClient), clazz, method)); + for (String namespaceId : namespaceIds) { + for (Method method : methods) { + ShenyuTarsClient shenyuTarsClient = AnnotatedElementUtils.findMergedAnnotation(method, ShenyuTarsClient.class); + if (Objects.nonNull(shenyuTarsClient)) { + publisher.publishEvent(buildMetaDataDTO(bean, shenyuTarsClient, buildApiPath(method, superPath, shenyuTarsClient), clazz, method, namespaceId)); + } } } } @@ -153,7 +165,7 @@ public void handle(final String beanName, final Object bean) { public MetaDataRegisterDTO buildMetaDataDTO(final Object bean, @NonNull final ShenyuTarsClient shenyuTarsClient, final String path, final Class clazz, - final Method method) { + final Method method, final String namespaceId) { String serviceName = clazz.getAnnotation(ShenyuTarsService.class).serviceName(); String ipAndPort = this.ipAndPort; String desc = shenyuTarsClient.desc(); @@ -177,6 +189,7 @@ public MetaDataRegisterDTO buildMetaDataDTO(final Object bean, .rpcType(RpcTypeEnum.TARS.getName()) .rpcExt(buildRpcExtJson(method)) .enabled(shenyuTarsClient.enabled()) + .namespaceId(namespaceId) .build(); } diff --git a/shenyu-client/shenyu-client-tars/src/test/java/org/apache/shenyu/client/tars/TarsServiceBeanPostProcessorTest.java b/shenyu-client/shenyu-client-tars/src/test/java/org/apache/shenyu/client/tars/TarsServiceBeanPostProcessorTest.java index 65217573f47c..26bacfafa9ea 100644 --- a/shenyu-client/shenyu-client-tars/src/test/java/org/apache/shenyu/client/tars/TarsServiceBeanPostProcessorTest.java +++ b/shenyu-client/shenyu-client-tars/src/test/java/org/apache/shenyu/client/tars/TarsServiceBeanPostProcessorTest.java @@ -21,9 +21,11 @@ import org.apache.shenyu.client.core.register.ShenyuClientRegisterRepositoryFactory; import org.apache.shenyu.client.tars.common.annotation.ShenyuTarsClient; import org.apache.shenyu.client.tars.common.annotation.ShenyuTarsService; +import org.apache.shenyu.common.enums.RpcTypeEnum; import org.apache.shenyu.register.client.api.ShenyuClientRegisterRepository; import org.apache.shenyu.register.client.http.utils.RegisterUtils; -import org.apache.shenyu.register.common.config.PropertiesConfig; +import org.apache.shenyu.register.common.config.ShenyuClientConfig; +import org.apache.shenyu.register.common.config.ShenyuClientConfig.ClientPropertiesConfig; import org.apache.shenyu.register.common.config.ShenyuRegisterCenterConfig; import org.junit.Assert; import org.junit.jupiter.api.BeforeEach; @@ -76,11 +78,9 @@ public void init() { results.put("tarsDemoService3", tarsDemoService3); when(applicationContext.getBeansWithAnnotation(any())).thenReturn(results); contextRefreshedEvent = new ContextRefreshedEvent(applicationContext); - - Properties properties = mock(Properties.class); - PropertiesConfig clientConfig = mock(PropertiesConfig.class); - when(clientConfig.getProps()).thenReturn(properties); - Assert.assertThrows(ShenyuClientIllegalArgumentException.class, () -> new TarsServiceBeanEventListener(clientConfig, mock(ShenyuClientRegisterRepository.class))); + + ShenyuClientConfig shenyuClientConfig = mock(ShenyuClientConfig.class); + Assert.assertThrows(ShenyuClientIllegalArgumentException.class, () -> new TarsServiceBeanEventListener(shenyuClientConfig, mock(ShenyuClientRegisterRepository.class))); } @Test @@ -108,15 +108,20 @@ private TarsServiceBeanEventListener buildTarsServiceBeanEventListener(final boo properties.setProperty("host", "localhost"); properties.setProperty("username", "admin"); properties.setProperty("password", "123456"); - PropertiesConfig config = new PropertiesConfig(); - config.setProps(properties); ShenyuRegisterCenterConfig mockRegisterCenter = new ShenyuRegisterCenterConfig(); mockRegisterCenter.setServerLists("http://localhost:58080"); mockRegisterCenter.setRegisterType("http"); mockRegisterCenter.setProps(properties); - - return new TarsServiceBeanEventListener(config, ShenyuClientRegisterRepositoryFactory.newInstance(mockRegisterCenter)); + + ShenyuClientConfig clientConfig = new ShenyuClientConfig(); + ClientPropertiesConfig clientPropertiesConfig = new ClientPropertiesConfig(); + clientPropertiesConfig.setProps(properties); + Map client = new LinkedHashMap<>(); + client.put(RpcTypeEnum.TARS.getName(), clientPropertiesConfig); + clientConfig.setClient(client); + + return new TarsServiceBeanEventListener(clientConfig, ShenyuClientRegisterRepositoryFactory.newInstance(mockRegisterCenter)); } @ShenyuTarsService(serviceName = "testObj") diff --git a/shenyu-client/shenyu-client-websocket/shenyu-client-spring-websocket/src/main/java/org/apache/shenyu/client/spring/websocket/init/SpringWebSocketClientEventListener.java b/shenyu-client/shenyu-client-websocket/shenyu-client-spring-websocket/src/main/java/org/apache/shenyu/client/spring/websocket/init/SpringWebSocketClientEventListener.java index eacf8749dbd3..338ad8d9a72f 100644 --- a/shenyu-client/shenyu-client-websocket/shenyu-client-spring-websocket/src/main/java/org/apache/shenyu/client/spring/websocket/init/SpringWebSocketClientEventListener.java +++ b/shenyu-client/shenyu-client-websocket/shenyu-client-spring-websocket/src/main/java/org/apache/shenyu/client/spring/websocket/init/SpringWebSocketClientEventListener.java @@ -30,7 +30,7 @@ import org.apache.shenyu.common.exception.ShenyuException; import org.apache.shenyu.common.utils.PathUtils; import org.apache.shenyu.register.client.api.ShenyuClientRegisterRepository; -import org.apache.shenyu.register.common.config.PropertiesConfig; +import org.apache.shenyu.register.common.config.ShenyuClientConfig; import org.apache.shenyu.register.common.dto.MetaDataRegisterDTO; import org.apache.shenyu.register.common.dto.URIRegisterDTO; import org.apache.shenyu.register.common.enums.EventType; @@ -78,10 +78,10 @@ public class SpringWebSocketClientEventListener extends AbstractContextRefreshed * @param clientConfig the client config * @param shenyuClientRegisterRepository the shenyu client register repository */ - public SpringWebSocketClientEventListener(final PropertiesConfig clientConfig, + public SpringWebSocketClientEventListener(final ShenyuClientConfig clientConfig, final ShenyuClientRegisterRepository shenyuClientRegisterRepository) { super(clientConfig, shenyuClientRegisterRepository); - Properties props = clientConfig.getProps(); + Properties props = clientConfig.getClient().get(getClientName()).getProps(); this.isFull = Boolean.parseBoolean(props.getProperty(ShenyuClientConstants.IS_FULL, Boolean.FALSE.toString())); this.protocol = props.getProperty(ShenyuClientConstants.PROTOCOL, ShenyuClientConstants.WS); mappingAnnotation.add(ShenyuSpringWebSocketClient.class); @@ -106,7 +106,8 @@ protected Map getBeans(final ApplicationContext context) { // Filter out is not controller out if (Boolean.TRUE.equals(isFull)) { LOG.info("init spring websocket client success with isFull mode"); - publisher.publishEvent(buildURIRegisterDTO(context, Collections.emptyMap())); + List namespaceIds = super.getNamespace(); + namespaceIds.forEach(namespaceId -> publisher.publishEvent(buildURIRegisterDTO(context, Collections.emptyMap(), namespaceId))); return Collections.emptyMap(); } Map endpointBeans = context.getBeansWithAnnotation(ShenyuServerEndpoint.class); @@ -115,7 +116,9 @@ protected Map getBeans(final ApplicationContext context) { } @Override - protected URIRegisterDTO buildURIRegisterDTO(final ApplicationContext context, final Map beans) { + protected URIRegisterDTO buildURIRegisterDTO(final ApplicationContext context, + final Map beans, + final String namespaceId) { try { return URIRegisterDTO.builder() .contextPath(getContextPath()) @@ -125,12 +128,18 @@ protected URIRegisterDTO buildURIRegisterDTO(final ApplicationContext context, f .port(Integer.valueOf(getPort())) .rpcType(RpcTypeEnum.WEB_SOCKET.getName()) .eventType(EventType.REGISTER) + .namespaceId(namespaceId) .build(); } catch (ShenyuException e) { throw new ShenyuException(e.getMessage() + "please config ${shenyu.client.http.props.port} in xml/yml !"); } } - + + @Override + protected String getClientName() { + return RpcTypeEnum.WEB_SOCKET.getName(); + } + @Override protected void handle(final String beanName, final Object bean) { Class clazz = getCorrectedClass(bean); @@ -161,11 +170,14 @@ protected void handleClass(final Class clazz, @NonNull final ShenyuSpringWebSocketClient beanShenyuClient, final String superPath) { Method[] methods = ReflectionUtils.getDeclaredMethods(clazz); - for (Method method : methods) { - final MetaDataRegisterDTO metaData = buildMetaDataDTO(bean, beanShenyuClient, - pathJoin(getContextPath(), superPath), clazz, method); - getPublisher().publishEvent(metaData); - getMetaDataMap().put(method, metaData); + List namespaceIds = super.getNamespace(); + for (String namespaceId : namespaceIds) { + for (Method method : methods) { + final MetaDataRegisterDTO metaData = buildMetaDataDTO(bean, beanShenyuClient, + pathJoin(getContextPath(), superPath), clazz, method, namespaceId); + getPublisher().publishEvent(metaData); + getMetaDataMap().put(method, metaData); + } } } @@ -178,10 +190,13 @@ protected void handleMethod(final Object bean, ShenyuSpringWebSocketClient methodShenyuClient = AnnotatedElementUtils.findMergedAnnotation(method, getAnnotationType()); methodShenyuClient = Objects.isNull(methodShenyuClient) ? beanShenyuClient : methodShenyuClient; if (Objects.nonNull(methodShenyuClient)) { - final MetaDataRegisterDTO metaData = buildMetaDataDTO(bean, methodShenyuClient, - buildApiPath(method, superPath, methodShenyuClient), clazz, method); - getPublisher().publishEvent(metaData); - getMetaDataMap().put(method, metaData); + List namespaceIds = super.getNamespace(); + for (String namespaceId : namespaceIds) { + final MetaDataRegisterDTO metaData = buildMetaDataDTO(bean, methodShenyuClient, + buildApiPath(method, superPath, methodShenyuClient), clazz, method, namespaceId); + getPublisher().publishEvent(metaData); + getMetaDataMap().put(method, metaData); + } } } @@ -203,7 +218,9 @@ protected String buildApiPath(final Method method, final String superPath, final } @Override - protected MetaDataRegisterDTO buildMetaDataDTO(final Object bean, @NonNull final ShenyuSpringWebSocketClient webSocketClient, final String path, final Class clazz, final Method method) { + protected MetaDataRegisterDTO buildMetaDataDTO(final Object bean, @NonNull final ShenyuSpringWebSocketClient webSocketClient, + final String path, final Class clazz, + final Method method, final String namespaceId) { return MetaDataRegisterDTO.builder() .contextPath(getContextPath()) .appName(getAppName()) @@ -211,6 +228,7 @@ protected MetaDataRegisterDTO buildMetaDataDTO(final Object bean, @NonNull final .rpcType(RpcTypeEnum.WEB_SOCKET.getName()) .enabled(true) .ruleName(StringUtils.defaultIfBlank(webSocketClient.ruleName(), getContextPath())) + .namespaceId(namespaceId) .build(); } diff --git a/shenyu-client/shenyu-client-websocket/shenyu-client-spring-websocket/src/test/java/org/apache/shenyu/client/spring/websocket/init/SpringWebSocketClientEventListenerTest.java b/shenyu-client/shenyu-client-websocket/shenyu-client-spring-websocket/src/test/java/org/apache/shenyu/client/spring/websocket/init/SpringWebSocketClientEventListenerTest.java index 347fa2fe324b..52058efd23dc 100644 --- a/shenyu-client/shenyu-client-websocket/shenyu-client-spring-websocket/src/test/java/org/apache/shenyu/client/spring/websocket/init/SpringWebSocketClientEventListenerTest.java +++ b/shenyu-client/shenyu-client-websocket/shenyu-client-spring-websocket/src/test/java/org/apache/shenyu/client/spring/websocket/init/SpringWebSocketClientEventListenerTest.java @@ -20,8 +20,12 @@ import org.apache.shenyu.client.core.constant.ShenyuClientConstants; import org.apache.shenyu.client.core.disruptor.ShenyuClientRegisterEventPublisher; import org.apache.shenyu.client.spring.websocket.annotation.ShenyuSpringWebSocketClient; +import org.apache.shenyu.common.constant.Constants; +import org.apache.shenyu.common.enums.RpcTypeEnum; import org.apache.shenyu.register.client.api.ShenyuClientRegisterRepository; import org.apache.shenyu.register.common.config.PropertiesConfig; +import org.apache.shenyu.register.common.config.ShenyuClientConfig; +import org.apache.shenyu.register.common.config.ShenyuClientConfig.ClientPropertiesConfig; import org.apache.shenyu.register.common.dto.MetaDataRegisterDTO; import org.apache.shenyu.register.common.dto.URIRegisterDTO; import org.junit.jupiter.api.BeforeEach; @@ -36,6 +40,7 @@ import java.lang.annotation.Annotation; import java.lang.reflect.Method; import java.util.Collections; +import java.util.HashMap; import java.util.Map; import java.util.Properties; @@ -86,8 +91,14 @@ public void setUp() { when(properties.getProperty(ShenyuClientConstants.PORT)).thenReturn("8080"); when(properties.getProperty(ShenyuClientConstants.HOST)).thenReturn("127.0.0.1"); when(properties.getProperty(ShenyuClientConstants.IP_PORT)).thenReturn("127.0.0.1:8080"); - when(propertiesConfig.getProps()).thenReturn(properties); - eventListener = new SpringWebSocketClientEventListener(propertiesConfig, registerRepository); + + ShenyuClientConfig clientConfig = mock(ShenyuClientConfig.class); + Map client = new HashMap<>(); + ClientPropertiesConfig clientPropertiesConfig = new ClientPropertiesConfig(); + clientPropertiesConfig.setProps(properties); + client.put(RpcTypeEnum.WEB_SOCKET.getName(), clientPropertiesConfig); + when(clientConfig.getClient()).thenReturn(client); + eventListener = new SpringWebSocketClientEventListener(clientConfig, registerRepository); } @Test @@ -106,7 +117,7 @@ public void testGetBeans() { @Test public void testBuildURIRegisterDTO() { - URIRegisterDTO uriRegisterDTO = eventListener.buildURIRegisterDTO(applicationContext, Collections.emptyMap()); + URIRegisterDTO uriRegisterDTO = eventListener.buildURIRegisterDTO(applicationContext, Collections.emptyMap(), Constants.SYS_DEFAULT_NAMESPACE_ID); assertNotNull(uriRegisterDTO); assertEquals("/contextPath", uriRegisterDTO.getContextPath()); assertEquals("appName", uriRegisterDTO.getAppName()); @@ -156,7 +167,7 @@ public void testBuildApiPath() throws NoSuchMethodException { @Test public void testBuildMetaDataDTO() throws NoSuchMethodException { Method method = mockClass.getClass().getMethod("mockMethod"); - MetaDataRegisterDTO metaDataRegisterDTO = eventListener.buildMetaDataDTO(mockClass, annotation, SUPER_PATH, MockClass.class, method); + MetaDataRegisterDTO metaDataRegisterDTO = eventListener.buildMetaDataDTO(mockClass, annotation, SUPER_PATH, MockClass.class, method, Constants.SYS_DEFAULT_NAMESPACE_ID); assertNotNull(metaDataRegisterDTO); } 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 0fa874d68325..c4bef84dc350 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 @@ -72,16 +72,6 @@ public final class AdminConstants { */ public static final String SYS_DEFAULT_NAMESPACE_ID_DELETE = "The default namespace can't deleted!"; - /** - * The constant SYS_DEFAULT_NAMESPACE_ID. - */ - public static final String SYS_DEFAULT_NAMESPACE_ID = "649330b6-c2d7-4edc-be8e-8a54df9eb385"; - - /** - * The constant DEFAULT_NAMESPACE_PRIMARY_KEY. - */ - public static final String DEFAULT_NAMESPACE_PRIMARY_KEY = "1"; - /** * The constant SYS_API_ID_NOT_EXIST. */ diff --git a/shenyu-common/src/main/java/org/apache/shenyu/common/constant/Constants.java b/shenyu-common/src/main/java/org/apache/shenyu/common/constant/Constants.java index 7d440f89a46c..d97270fc4385 100644 --- a/shenyu-common/src/main/java/org/apache/shenyu/common/constant/Constants.java +++ b/shenyu-common/src/main/java/org/apache/shenyu/common/constant/Constants.java @@ -22,6 +22,11 @@ */ public interface Constants { + /** + * The constant string separator. + */ + String SEPARATOR_CHARS = ";"; + /** * The constant SUCCESS. */ @@ -829,7 +834,17 @@ public interface Constants { * Hystrix plugin metrics. */ String METRICS_HYSTRIX = "metricsHystrix"; - + + /** + * The constant SYS_DEFAULT_NAMESPACE_ID. + */ + String SYS_DEFAULT_NAMESPACE_ID = "649330b6-c2d7-4edc-be8e-8a54df9eb385"; + + /** + * The constant DEFAULT_NAMESPACE_PRIMARY_KEY. + */ + String DEFAULT_NAMESPACE_PRIMARY_KEY = "1"; + /** * String q. */ diff --git a/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-storage/k8s/script/healthcheck.sh b/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-storage/k8s/script/healthcheck.sh index 7dbb32189efc..53fdb1e6dfc2 100644 --- a/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-storage/k8s/script/healthcheck.sh +++ b/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-storage/k8s/script/healthcheck.sh @@ -29,7 +29,7 @@ do break fi - sleep 2 + sleep 5 done done diff --git a/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-storage/src/test/java/org/apache/shenyu/e2e/testcase/divide/DividePluginCases.java b/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-storage/src/test/java/org/apache/shenyu/e2e/testcase/divide/DividePluginCases.java index 2c597bb9516e..05bd7b62594d 100644 --- a/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-storage/src/test/java/org/apache/shenyu/e2e/testcase/divide/DividePluginCases.java +++ b/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-storage/src/test/java/org/apache/shenyu/e2e/testcase/divide/DividePluginCases.java @@ -75,6 +75,7 @@ private ShenYuScenarioSpec testDivideWithUriEquals() { newRuleBuilder("rule") .handle(newDivideRuleHandle()) .conditionList(newConditions(ParamType.URI, Operator.EQUAL, ANYTHING)) + .namespaceId(SYS_DEFAULT_NAMESPACE_NAMESPACE_ID) .build() ) .checker(notExists(ANYTHING)) @@ -112,6 +113,7 @@ public ShenYuScenarioSpec testDivideWithUriPathPattern() { newRuleBuilder("rule") .handle(newDivideRuleHandle()) .conditionList(newConditions(ParamType.URI, Operator.PATH_PATTERN, "/anything/xx/**")) + .namespaceId(SYS_DEFAULT_NAMESPACE_NAMESPACE_ID) .build() ) .checker(notExists(ANYTHING + "/xx/yyy")) @@ -152,6 +154,7 @@ public ShenYuScenarioSpec testDivideWithUriStartWith() { newRuleBuilder("rule") .handle(newDivideRuleHandle()) .conditionList(newConditions(ParamType.URI, Operator.STARTS_WITH, ANYTHING + "/xx")) + .namespaceId(SYS_DEFAULT_NAMESPACE_NAMESPACE_ID) .build() ) .checker(notExists(ANYTHING + "/xx")) @@ -238,6 +241,7 @@ public ShenYuScenarioSpec testDivideWithMethodGet() { newCondition(ParamType.METHOD, Operator.EQUAL, "GET"), newCondition(ParamType.URI, Operator.EQUAL, ANYTHING) )) + .namespaceId(SYS_DEFAULT_NAMESPACE_NAMESPACE_ID) .build() ) .checker(notExists(Method.GET, ANYTHING)) @@ -284,6 +288,7 @@ public ShenYuScenarioSpec testDivideWithMethodPost() { newCondition(ParamType.METHOD, Operator.EQUAL, "POST"), newCondition(ParamType.URI, Operator.EQUAL, ANYTHING) )) + .namespaceId(SYS_DEFAULT_NAMESPACE_NAMESPACE_ID) .build() ) .checker(notExists(Method.POST, ANYTHING)) @@ -330,6 +335,7 @@ public ShenYuScenarioSpec testDivideWithMethodPut() { newCondition(ParamType.METHOD, Operator.EQUAL, "PUT"), newCondition(ParamType.URI, Operator.EQUAL, ANYTHING) )) + .namespaceId(SYS_DEFAULT_NAMESPACE_NAMESPACE_ID) .build() ) .checker(notExists(Method.PUT, ANYTHING)) @@ -376,6 +382,7 @@ public ShenYuScenarioSpec testDivideWithMethodDelete() { newCondition(ParamType.METHOD, Operator.EQUAL, "DELETE"), newCondition(ParamType.URI, Operator.EQUAL, ANYTHING) )) + .namespaceId(SYS_DEFAULT_NAMESPACE_NAMESPACE_ID) .build() ) .checker(notExists(Method.DELETE, ANYTHING)) diff --git a/shenyu-examples/shenyu-examples-http/src/main/resources/application.yml b/shenyu-examples/shenyu-examples-http/src/main/resources/application.yml index 1ebaab46d289..e1bd53dc1f05 100644 --- a/shenyu-examples/shenyu-examples-http/src/main/resources/application.yml +++ b/shenyu-examples/shenyu-examples-http/src/main/resources/application.yml @@ -20,6 +20,7 @@ server: max-http-form-post-size: 100MB shenyu: + namespace: 649330b6-c2d7-4edc-be8e-8a54df9eb385 register: registerType: http serverLists: http://localhost:9095 diff --git a/shenyu-register-center/shenyu-register-common/src/main/java/org/apache/shenyu/register/common/config/ShenyuClientConfig.java b/shenyu-register-center/shenyu-register-common/src/main/java/org/apache/shenyu/register/common/config/ShenyuClientConfig.java index 2bf61e1da956..0214f13bafb6 100644 --- a/shenyu-register-center/shenyu-register-common/src/main/java/org/apache/shenyu/register/common/config/ShenyuClientConfig.java +++ b/shenyu-register-center/shenyu-register-common/src/main/java/org/apache/shenyu/register/common/config/ShenyuClientConfig.java @@ -39,6 +39,8 @@ public ClientPropertiesConfig get(final Object key) { } }; + private String namespace; + /** * Gets client. * @@ -56,6 +58,24 @@ public Map getClient() { public void setClient(final Map client) { this.client = client; } + + /** + * getNamespace. + * + * @return String + */ + public String getNamespace() { + return namespace; + } + + /** + * setNamespace. + * + * @param namespace namespace identifier + */ + public void setNamespace(final String namespace) { + this.namespace = namespace; + } /** * this client properties config. 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 42c417fc79e5..2c4cbcab2205 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 @@ -781,7 +781,6 @@ public Builder addPrefixed(final boolean addPrefixed) { return this; } - /** * namespaceId. * diff --git a/shenyu-register-center/shenyu-register-common/src/main/java/org/apache/shenyu/register/common/dto/URIRegisterDTO.java b/shenyu-register-center/shenyu-register-common/src/main/java/org/apache/shenyu/register/common/dto/URIRegisterDTO.java index a0193191f29e..955ec910bcf8 100644 --- a/shenyu-register-center/shenyu-register-common/src/main/java/org/apache/shenyu/register/common/dto/URIRegisterDTO.java +++ b/shenyu-register-center/shenyu-register-common/src/main/java/org/apache/shenyu/register/common/dto/URIRegisterDTO.java @@ -41,7 +41,8 @@ public class URIRegisterDTO implements DataTypeParent { private Integer port; private EventType eventType; - + + private String namespaceId; /** * Instantiates a new Uri register dto. @@ -56,7 +57,7 @@ public class URIRegisterDTO implements DataTypeParent { */ public URIRegisterDTO(final String protocol, final String appName, final String contextPath, final String rpcType, final String host, final Integer port, - final EventType eventType, final Integer prefixForwardEnable) { + final EventType eventType, final String namespaceId) { this.protocol = protocol; this.appName = appName; this.contextPath = contextPath; @@ -64,6 +65,7 @@ public URIRegisterDTO(final String protocol, final String appName, final String this.host = host; this.port = port; this.eventType = eventType; + this.namespaceId = namespaceId; } /** @@ -80,6 +82,7 @@ private URIRegisterDTO(final Builder builder) { host = builder.host; port = builder.port; eventType = builder.eventType; + namespaceId = builder.namespaceId; } /** @@ -233,6 +236,24 @@ public EventType getEventType() { return eventType; } + /** + * getNamespaceId. + * + * @return String namespace + */ + public String getNamespaceId() { + return namespaceId; + } + + /** + * setNamespaceId. + * + * @param namespaceId namespace id + */ + public void setNamespaceId(final String namespaceId) { + this.namespaceId = namespaceId; + } + /** * setEventType. * @@ -259,7 +280,8 @@ public boolean equals(final Object o) { && Objects.equals(getRpcType(), that.getRpcType()) && Objects.equals(getHost(), that.getHost()) && Objects.equals(getPort(), that.getPort()) - && getEventType() == that.getEventType(); + && getEventType() == that.getEventType() + && Objects.equals(getNamespaceId(), that.getNamespaceId()); } @Override @@ -289,6 +311,8 @@ public String toString() { + port + ", eventType=" + eventType + + ", namespaceId=" + + namespaceId + '}'; } @@ -310,6 +334,8 @@ public static final class Builder { private Integer port; private EventType eventType; + + private String namespaceId; private Builder() { } @@ -390,6 +416,17 @@ public Builder eventType(final EventType eventType) { this.eventType = eventType; return this; } + + /** + * namespace. + * + * @param namespaceId namespace id + * @return Builder builder + */ + public Builder namespaceId(final String namespaceId) { + this.namespaceId = namespaceId; + return this; + } /** * build. diff --git a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-client/shenyu-spring-boot-starter-client-apache-dubbo/src/main/java/org/apache/shenyu/springboot/starter/client/apache/dubbo/ShenyuApacheDubboClientConfiguration.java b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-client/shenyu-spring-boot-starter-client-apache-dubbo/src/main/java/org/apache/shenyu/springboot/starter/client/apache/dubbo/ShenyuApacheDubboClientConfiguration.java index 2e6d9c17eb2a..a8ac2bc6a70a 100644 --- a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-client/shenyu-spring-boot-starter-client-apache-dubbo/src/main/java/org/apache/shenyu/springboot/starter/client/apache/dubbo/ShenyuApacheDubboClientConfiguration.java +++ b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-client/shenyu-spring-boot-starter-client-apache-dubbo/src/main/java/org/apache/shenyu/springboot/starter/client/apache/dubbo/ShenyuApacheDubboClientConfiguration.java @@ -18,7 +18,6 @@ package org.apache.shenyu.springboot.starter.client.apache.dubbo; import org.apache.shenyu.client.apache.dubbo.ApacheDubboServiceBeanListener; -import org.apache.shenyu.common.enums.RpcTypeEnum; import org.apache.shenyu.common.utils.VersionUtils; import org.apache.shenyu.register.client.api.ShenyuClientRegisterRepository; import org.apache.shenyu.register.common.config.ShenyuClientConfig; @@ -50,6 +49,6 @@ public class ShenyuApacheDubboClientConfiguration { @Bean public ApacheDubboServiceBeanListener apacheDubboServiceBeanListener(final ShenyuClientConfig clientConfig, final ShenyuClientRegisterRepository shenyuClientRegisterRepository) { - return new ApacheDubboServiceBeanListener(clientConfig.getClient().get(RpcTypeEnum.DUBBO.getName()), shenyuClientRegisterRepository); + return new ApacheDubboServiceBeanListener(clientConfig, shenyuClientRegisterRepository); } } diff --git a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-client/shenyu-spring-boot-starter-client-grpc/src/main/java/org/apache/springboot/starter/client/grpc/ShenyuGrpcClientConfiguration.java b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-client/shenyu-spring-boot-starter-client-grpc/src/main/java/org/apache/springboot/starter/client/grpc/ShenyuGrpcClientConfiguration.java index d84c1ce3b3a8..53f76fd40f91 100644 --- a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-client/shenyu-spring-boot-starter-client-grpc/src/main/java/org/apache/springboot/starter/client/grpc/ShenyuGrpcClientConfiguration.java +++ b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-client/shenyu-spring-boot-starter-client-grpc/src/main/java/org/apache/springboot/starter/client/grpc/ShenyuGrpcClientConfiguration.java @@ -67,7 +67,7 @@ public GrpcClientEventListener grpcClientEventListener(final ShenyuClientConfig if (props != null) { props.setProperty(ShenyuClientConstants.DISCOVERY_LOCAL_MODE_KEY, Boolean.valueOf(ShenyuClientConstants.DISCOVERY_LOCAL_MODE.equals(discoveryMode)).toString()); } - return new GrpcClientEventListener(clientConfig.getClient().get(RpcTypeEnum.GRPC.getName()), shenyuClientRegisterRepository); + return new GrpcClientEventListener(clientConfig, shenyuClientRegisterRepository); } /** diff --git a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-client/shenyu-spring-boot-starter-client-motan/src/main/java/org/apache/shenyu/springboot/starter/client/motan/ShenyuMotanClientConfiguration.java b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-client/shenyu-spring-boot-starter-client-motan/src/main/java/org/apache/shenyu/springboot/starter/client/motan/ShenyuMotanClientConfiguration.java index 62bc0accd668..14ca4979d044 100644 --- a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-client/shenyu-spring-boot-starter-client-motan/src/main/java/org/apache/shenyu/springboot/starter/client/motan/ShenyuMotanClientConfiguration.java +++ b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-client/shenyu-spring-boot-starter-client-motan/src/main/java/org/apache/shenyu/springboot/starter/client/motan/ShenyuMotanClientConfiguration.java @@ -24,7 +24,6 @@ import com.weibo.api.motan.config.springsupport.RegistryConfigBean; import com.weibo.api.motan.util.MotanSwitcherUtil; import org.apache.shenyu.client.motan.MotanServiceEventListener; -import org.apache.shenyu.common.enums.RpcTypeEnum; import org.apache.shenyu.common.utils.VersionUtils; import org.apache.shenyu.register.client.api.ShenyuClientRegisterRepository; import org.apache.shenyu.register.common.config.ShenyuClientConfig; @@ -61,7 +60,7 @@ public class ShenyuMotanClientConfiguration implements ApplicationListener