You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by al...@apache.org on 2021/10/28 06:00:13 UTC
[dubbo] branch 3.0 updated: Disable SD Registry URL Override & Fix
Accept for Registry (#9152)
This is an automated email from the ASF dual-hosted git repository.
albumenj pushed a commit to branch 3.0
in repository https://gitbox.apache.org/repos/asf/dubbo.git
The following commit(s) were added to refs/heads/3.0 by this push:
new 0afc12f Disable SD Registry URL Override & Fix Accept for Registry (#9152)
0afc12f is described below
commit 0afc12f409067224a530c397dbf1221de42f2e45
Author: Albumen Kevin <jh...@gmail.com>
AuthorDate: Thu Oct 28 13:59:46 2021 +0800
Disable SD Registry URL Override & Fix Accept for Registry (#9152)
* Disable SD Registry URL Override & Fix Accept for Registry
* fix
* fix ut
---
...ryCenterServiceDiscoveryRegistryIntegrationTest.java | 3 ++-
.../apache/dubbo/registry/ListenerRegistryWrapper.java | 5 +++++
.../main/java/org/apache/dubbo/registry/Registry.java | 4 ++++
.../dubbo/registry/client/ServiceDiscoveryRegistry.java | 5 +++++
.../dubbo/registry/integration/RegistryProtocol.java | 10 +++++++---
.../apache/dubbo/registry/support/AbstractRegistry.java | 17 +++++++++++++++--
6 files changed, 38 insertions(+), 6 deletions(-)
diff --git a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/multiple/servicediscoveryregistry/MultipleRegistryCenterServiceDiscoveryRegistryIntegrationTest.java b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/multiple/servicediscoveryregistry/MultipleRegistryCenterServiceDiscoveryRegistryIntegrationTest.java
index fed2bae..2be4305 100644
--- a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/multiple/servicediscoveryregistry/MultipleRegistryCenterServiceDiscoveryRegistryIntegrationTest.java
+++ b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/multiple/servicediscoveryregistry/MultipleRegistryCenterServiceDiscoveryRegistryIntegrationTest.java
@@ -29,6 +29,7 @@ import org.apache.dubbo.registry.RegistryServiceListener;
import org.apache.dubbo.registry.client.metadata.store.InMemoryWritableMetadataService;
import org.apache.dubbo.registrycenter.RegistryCenter;
import org.apache.dubbo.registrycenter.ZookeeperMultipleRegistryCenter;
+
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
@@ -177,7 +178,7 @@ public class MultipleRegistryCenterServiceDiscoveryRegistryIntegrationTest imple
// check if it's registered
Assertions.assertTrue(serviceDiscoveryRegistryInfoWrapper.isRegistered());
// check if it's subscribed
- Assertions.assertTrue(serviceDiscoveryRegistryInfoWrapper.isSubscribed());
+ Assertions.assertFalse(serviceDiscoveryRegistryInfoWrapper.isSubscribed());
InMemoryWritableMetadataService inMemoryWritableMetadataService = serviceDiscoveryRegistryInfoWrapper.getInMemoryWritableMetadataService();
// check if the count of exported urls is right or not
Assertions.assertEquals(inMemoryWritableMetadataService.getExportedURLs().size(), 1);
diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/ListenerRegistryWrapper.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/ListenerRegistryWrapper.java
index 7e0aea1..fc686a4 100644
--- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/ListenerRegistryWrapper.java
+++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/ListenerRegistryWrapper.java
@@ -153,6 +153,11 @@ public class ListenerRegistryWrapper implements Registry {
}
@Override
+ public boolean isServiceDiscovery() {
+ return registry.isServiceDiscovery();
+ }
+
+ @Override
public List<URL> lookup(URL url) {
return registry.lookup(url);
}
diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/Registry.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/Registry.java
index 957e5e1..2eaef41 100644
--- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/Registry.java
+++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/Registry.java
@@ -33,6 +33,10 @@ public interface Registry extends Node, RegistryService {
return getUrl().getParameter(REGISTRY_DELAY_NOTIFICATION_KEY, DEFAULT_DELAY_NOTIFICATION_TIME);
}
+ default boolean isServiceDiscovery() {
+ return false;
+ }
+
default void reExportRegister(URL url) {
register(url);
}
diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/ServiceDiscoveryRegistry.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/ServiceDiscoveryRegistry.java
index 0152647..043f583 100644
--- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/ServiceDiscoveryRegistry.java
+++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/ServiceDiscoveryRegistry.java
@@ -282,6 +282,11 @@ public class ServiceDiscoveryRegistry extends FailbackRegistry {
execute(serviceDiscovery::destroy);
}
+ @Override
+ public boolean isServiceDiscovery() {
+ return true;
+ }
+
protected void subscribeURLs(URL url, NotifyListener listener, Set<String> serviceNames) {
serviceNames = new TreeSet<>(serviceNames);
String serviceNamesKey = toStringKeys(serviceNames);
diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryProtocol.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryProtocol.java
index e9ed322..2df9270 100644
--- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryProtocol.java
+++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryProtocol.java
@@ -253,8 +253,10 @@ public class RegistryProtocol implements Protocol, ScopeModelAware {
exporter.setRegisterUrl(registeredProviderUrl);
exporter.setSubscribeUrl(overrideSubscribeUrl);
- // Deprecated! Subscribe to override rules in 2.6.x or before.
- registry.subscribe(overrideSubscribeUrl, overrideSubscribeListener);
+ if (!registry.isServiceDiscovery()) {
+ // Deprecated! Subscribe to override rules in 2.6.x or before.
+ registry.subscribe(overrideSubscribeUrl, overrideSubscribeListener);
+ }
notifyExport(exporter);
//Ensure that a new exporter instance is returned every time export
@@ -892,7 +894,9 @@ public class RegistryProtocol implements Protocol, ScopeModelAware {
Map<URL, NotifyListener> overrideListeners = getProviderConfigurationListener(subscribeUrl).getOverrideListeners();
NotifyListener listener = overrideListeners.remove(registerUrl);
if (listener != null) {
- registry.unsubscribe(subscribeUrl, listener);
+ if (!registry.isServiceDiscovery()) {
+ registry.unsubscribe(subscribeUrl, listener);
+ }
ApplicationModel applicationModel = getApplicationModel(registerUrl.getScopeModel());
if (applicationModel.getModelEnvironment().getConfiguration().convert(Boolean.class, ENABLE_CONFIGURATION_LISTEN, true)) {
for (ModuleModel moduleModel : applicationModel.getPubModuleModels()) {
diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/AbstractRegistry.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/AbstractRegistry.java
index 72f73dd..4c71d83 100644
--- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/AbstractRegistry.java
+++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/AbstractRegistry.java
@@ -51,6 +51,7 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.AtomicReference;
+import java.util.stream.Collectors;
import static org.apache.dubbo.common.constants.CommonConstants.ANY_VALUE;
import static org.apache.dubbo.common.constants.CommonConstants.COMMA_SPLIT_PATTERN;
@@ -521,8 +522,20 @@ public abstract class AbstractRegistry implements Registry {
}
String[] accepts = COMMA_SPLIT_PATTERN.split(pattern);
- return Arrays.stream(accepts).anyMatch(p -> p.equalsIgnoreCase(urlToRegistry.getProtocol())) &&
- Arrays.stream(accepts).noneMatch(p -> p.equalsIgnoreCase("-" + urlToRegistry.getProtocol()));
+
+ Set<String> allow = Arrays.stream(accepts).filter(p -> !p.startsWith("-")).collect(Collectors.toSet());
+ Set<String> disAllow = Arrays.stream(accepts).filter(p -> p.startsWith("-")).map(p -> p.substring(1)).collect(Collectors.toSet());
+
+ if (CollectionUtils.isNotEmpty(allow)) {
+ // allow first
+ return allow.contains(urlToRegistry.getProtocol());
+ } else if (CollectionUtils.isNotEmpty(disAllow)) {
+ // contains disAllow, deny
+ return !disAllow.contains(urlToRegistry.getProtocol());
+ } else {
+ // default allow
+ return true;
+ }
}
@Override