This is an automated email from the ASF dual-hosted git repository.
mercyblitz pushed a commit to branch 2.7.8-dev
in repository https://gitbox.apache.org/repos/asf/dubbo.git
The following commit(s) were added to refs/heads/2.7.8-dev by this push:
new e65f81f 2.7.8 service introspection (#6337)
e65f81f is described below
commit e65f81f26da226fd352daff4feac38a82b873e09
Author: Mercy Ma <[email protected]>
AuthorDate: Wed Jun 17 11:02:48 2020 +0800
2.7.8 service introspection (#6337)
* Polish apache/dubbo#6296 : Adding the new methods into MetadataReport to
manipulate the exported URLs for service introspection
* Polish apache/dubbo#6296 : Adding the new methods into MetadataReport to
manipulate the exported URLs for service introspection
* Polish apache/dubbo#6171 : [Feature] Introducing the composite
implementation of MetadataService
* Revert "fix wrong check of InvokerListener when export a service (fix
issue_6269) (#6271)"
This reverts commit 91989cae508f8482f31ac335879da4a5975661c8.
* Revert "fix wrong check of InvokerListener when export a service (fix
issue_6269) (#6271)"
This reverts commit 91989cae508f8482f31ac335879da4a5975661c8.
* Revert the MetadataReport
* Polish apache/dubbo#6305 : [Refactor] ServiceConfig and ReferenceConfig
publish the ServiceDefinition based on the Dubbo Event
* Polish apache/dubbo#6198 : [Issue] Fixing
NacosDynamicConfiguration#publishConfig bug
* Polish apache/dubbo#6310 : Refactoring MetadataReport's methods
* Polish apache/dubbo#6198 : [Issue] Fixing
NacosDynamicConfiguration#publishConfig bug
* Polish apache/dubbo#6198 : [Issue] Fixing
NacosDynamicConfiguration#publishConfig bug
* Polish apache/dubbo#6315 : [Refactor] Refactoring the implementation of
MetadataReport based on The Config-Center infrastructure
Deprecated List :
- NacosMetadataReport
- ZookeeperMetadataReport
* Polish apache/dubbo#6315 : Refactoring by TreePathDynamicConfiguration
* Polish apache/dubbo#6315 : Refactoring ConsulDynamicConfiguration by
TreePathDynamicConfiguration
* Polish apache/dubbo#6315 : Reset the config base path to be "metadata"
for ConfigCenterBasedMetadataReportFactory
* Polish apache/dubbo#6315 : Bugfix
* Polish apache/dubbo#6315 : Bugfix
* Polish apache/dubbo#6315 : Correct words
* Polish apache/dubbo#6333 : [Refactor] Using mandatory implementation of
Service Instance registration instead of the event
* Polish apache/dubbo#6336 : [Refactor]
org.apache.dubbo.metadata.ServiceNameMapping
---
.../dubbo/config/bootstrap/DubboBootstrap.java | 29 ++++++++++++++++++++
.../event/listener/ServiceNameMappingListener.java | 8 +-----
.../DynamicConfigurationServiceNameMapping.java | 18 +++++++++++--
.../apache/dubbo/metadata/ServiceNameMapping.java | 31 +++++++++++++++++++---
...DynamicConfigurationServiceNameMappingTest.java | 25 ++++++++++++++---
.../CustomizableServiceInstanceListener.java | 2 ++
.../metadata/ServiceInstanceMetadataUtils.java | 4 +--
.../internal/org.apache.dubbo.event.EventListener | 5 +++-
8 files changed, 104 insertions(+), 18 deletions(-)
diff --git
a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/bootstrap/DubboBootstrap.java
b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/bootstrap/DubboBootstrap.java
index 16d331c..863e834 100644
---
a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/bootstrap/DubboBootstrap.java
+++
b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/bootstrap/DubboBootstrap.java
@@ -66,6 +66,7 @@ import
org.apache.dubbo.registry.client.DefaultServiceInstance;
import org.apache.dubbo.registry.client.ServiceDiscovery;
import org.apache.dubbo.registry.client.ServiceDiscoveryRegistry;
import org.apache.dubbo.registry.client.ServiceInstance;
+import org.apache.dubbo.registry.client.ServiceInstanceCustomizer;
import org.apache.dubbo.registry.support.AbstractRegistryFactory;
import org.apache.dubbo.rpc.model.ApplicationModel;
@@ -1085,9 +1086,37 @@ public class DubboBootstrap extends GenericEventListener
{
ServiceInstance serviceInstance = createServiceInstance(serviceName,
host, port);
+ preRegisterServiceInstance(serviceInstance);
+
getServiceDiscoveries().forEach(serviceDiscovery ->
serviceDiscovery.register(serviceInstance));
}
+ /**
+ * Pre-register {@link ServiceInstance the service instance}
+ *
+ * @param serviceInstance {@link ServiceInstance the service instance}
+ * @since 2.7.8
+ */
+ private void preRegisterServiceInstance(ServiceInstance serviceInstance) {
+ customizeServiceInstance(serviceInstance);
+ }
+
+ /**
+ * Customize {@link ServiceInstance the service instance}
+ *
+ * @param serviceInstance {@link ServiceInstance the service instance}
+ * @since 2.7.8
+ */
+ private void customizeServiceInstance(ServiceInstance serviceInstance) {
+ ExtensionLoader<ServiceInstanceCustomizer> loader =
+
ExtensionLoader.getExtensionLoader(ServiceInstanceCustomizer.class);
+ // FIXME, sort customizer before apply
+ loader.getSupportedExtensionInstances().forEach(customizer -> {
+ // customizes
+ customizer.customize(serviceInstance);
+ });
+ }
+
private URL selectMetadataServiceExportedURL() {
URL selectedURL = null;
diff --git
a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/event/listener/ServiceNameMappingListener.java
b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/event/listener/ServiceNameMappingListener.java
index 4dcfde3..8607b51 100644
---
a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/event/listener/ServiceNameMappingListener.java
+++
b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/event/listener/ServiceNameMappingListener.java
@@ -24,8 +24,6 @@ import org.apache.dubbo.metadata.ServiceNameMapping;
import java.util.List;
-import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY;
-import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY;
import static org.apache.dubbo.metadata.ServiceNameMapping.getDefaultExtension;
/**
@@ -45,11 +43,7 @@ public class ServiceNameMappingListener implements
EventListener<ServiceConfigEx
ServiceConfig serviceConfig = event.getServiceConfig();
List<URL> exportedURLs = serviceConfig.getExportedUrls();
exportedURLs.forEach(url -> {
- String serviceInterface = url.getServiceInterface();
- String group = url.getParameter(GROUP_KEY);
- String version = url.getParameter(VERSION_KEY);
- String protocol = url.getProtocol();
- serviceNameMapping.map(serviceInterface, group, version, protocol);
+ serviceNameMapping.map(url);
});
}
}
diff --git
a/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/DynamicConfigurationServiceNameMapping.java
b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/DynamicConfigurationServiceNameMapping.java
index b03148a..fda59aa 100644
---
a/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/DynamicConfigurationServiceNameMapping.java
+++
b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/DynamicConfigurationServiceNameMapping.java
@@ -16,6 +16,7 @@
*/
package org.apache.dubbo.metadata;
+import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.config.configcenter.DynamicConfiguration;
import org.apache.dubbo.common.logger.Logger;
import org.apache.dubbo.common.logger.LoggerFactory;
@@ -27,6 +28,8 @@ import java.util.Set;
import static java.lang.String.valueOf;
import static java.util.Arrays.asList;
+import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY;
+import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY;
import static org.apache.dubbo.common.utils.CollectionUtils.isNotEmpty;
import static org.apache.dubbo.common.utils.StringUtils.SLASH;
import static org.apache.dubbo.rpc.model.ApplicationModel.getName;
@@ -43,12 +46,18 @@ public class DynamicConfigurationServiceNameMapping
implements ServiceNameMappin
private final Logger logger = LoggerFactory.getLogger(getClass());
@Override
- public void map(String serviceInterface, String group, String version,
String protocol) {
+ public void map(URL exportedURL) {
+
+ String serviceInterface = exportedURL.getServiceInterface();
if (IGNORED_SERVICE_INTERFACES.contains(serviceInterface)) {
return;
}
+ String group = exportedURL.getParameter(GROUP_KEY);
+ String version = exportedURL.getParameter(VERSION_KEY);
+ String protocol = exportedURL.getProtocol();
+
DynamicConfiguration dynamicConfiguration =
DynamicConfiguration.getDynamicConfiguration();
// the Dubbo Service Key as group
@@ -66,10 +75,15 @@ public class DynamicConfigurationServiceNameMapping
implements ServiceNameMappin
}
@Override
- public Set<String> get(String serviceInterface, String group, String
version, String protocol) {
+ public Set<String> get(URL subscribedURL) {
DynamicConfiguration dynamicConfiguration =
DynamicConfiguration.getDynamicConfiguration();
+ String serviceInterface = subscribedURL.getServiceInterface();
+ String group = subscribedURL.getParameter(GROUP_KEY);
+ String version = subscribedURL.getParameter(VERSION_KEY);
+ String protocol = subscribedURL.getProtocol();
+
Set<String> serviceNames = new LinkedHashSet<>();
execute(() -> {
Set<String> keys =
dynamicConfiguration.getConfigKeys(buildGroup(serviceInterface, group, version,
protocol));
diff --git
a/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/ServiceNameMapping.java
b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/ServiceNameMapping.java
index 74113f2..8a8c10d 100644
---
a/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/ServiceNameMapping.java
+++
b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/ServiceNameMapping.java
@@ -16,6 +16,7 @@
*/
package org.apache.dubbo.metadata;
+import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.extension.SPI;
import java.util.Set;
@@ -37,8 +38,20 @@ public interface ServiceNameMapping {
* @param group the group of Dubbo service interface (optional)
* @param version the version of Dubbo service interface version
(optional)
* @param protocol the protocol of Dubbo service interface
exported (optional)
+ * @deprecated 2.7.8 This method will be removed since 3.0
*/
- void map(String serviceInterface, String group, String version, String
protocol);
+ @Deprecated
+ default void map(String serviceInterface, String group, String version,
String protocol) {
+ throw new UnsupportedOperationException("This method has been
deprecated and should not be invoked!");
+ }
+
+ /**
+ * Map the specified Dubbo service {@link URL} to current Dubbo service
name
+ *
+ * @param exportedURL the {@link URL} that the Dubbo Provider exported
+ * @since 2.7.8
+ */
+ void map(URL exportedURL);
/**
* Get the service names from the specified Dubbo service interface,
group, version and protocol
@@ -47,10 +60,22 @@ public interface ServiceNameMapping {
* @param group the group of Dubbo service interface (optional)
* @param version the version of Dubbo service interface version
(optional)
* @param protocol the protocol of Dubbo service interface
exported (optional)
- * @return
+ * @return non-null {@link Set}
+ * @deprecated 2.7.8 This method will be removed since 3.0
*/
- Set<String> get(String serviceInterface, String group, String version,
String protocol);
+ @Deprecated
+ default Set<String> get(String serviceInterface, String group, String
version, String protocol) {
+ throw new UnsupportedOperationException("This method has been
deprecated and should not be invoked!");
+ }
+ /**
+ * Get the service names from the subscribed Dubbo service {@link URL}
+ *
+ * @param subscribedURL the {@link URL} that the Dubbo consumer subscribed
+ * @return non-null {@link Set}
+ * @since 2.7.8
+ */
+ Set<String> get(URL subscribedURL);
/**
* Get the default extension of {@link ServiceNameMapping}
diff --git
a/dubbo-metadata/dubbo-metadata-api/src/test/java/org/apache/dubbo/metadata/DynamicConfigurationServiceNameMappingTest.java
b/dubbo-metadata/dubbo-metadata-api/src/test/java/org/apache/dubbo/metadata/DynamicConfigurationServiceNameMappingTest.java
index 0e677df..d4d25ee 100644
---
a/dubbo-metadata/dubbo-metadata-api/src/test/java/org/apache/dubbo/metadata/DynamicConfigurationServiceNameMappingTest.java
+++
b/dubbo-metadata/dubbo-metadata-api/src/test/java/org/apache/dubbo/metadata/DynamicConfigurationServiceNameMappingTest.java
@@ -16,6 +16,7 @@
*/
package org.apache.dubbo.metadata;
+import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.config.configcenter.DynamicConfiguration;
import org.apache.dubbo.common.config.configcenter.DynamicConfigurationFactory;
import org.apache.dubbo.config.ApplicationConfig;
@@ -28,10 +29,13 @@ import java.util.Set;
import java.util.TreeSet;
import static java.util.Arrays.asList;
+import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY;
+import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY;
import static
org.apache.dubbo.common.extension.ExtensionLoader.getExtensionLoader;
import static
org.apache.dubbo.metadata.DynamicConfigurationServiceNameMapping.buildGroup;
import static org.apache.dubbo.metadata.ServiceNameMapping.getDefaultExtension;
import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
/**
* {@link DynamicConfigurationServiceNameMapping} Test
@@ -62,6 +66,17 @@ public class DynamicConfigurationServiceNameMappingTest {
}
@Test
+ public void testAndGetOnFailed() {
+ assertThrows(UnsupportedOperationException.class, () -> {
+ serviceNameMapping.map(null, null, null, null);
+ });
+
+ assertThrows(UnsupportedOperationException.class, () -> {
+ serviceNameMapping.get(null, null, null, null);
+ });
+ }
+
+ @Test
public void testMapAndGet() {
String serviceName = "test";
@@ -74,14 +89,18 @@ public class DynamicConfigurationServiceNameMappingTest {
String version = null;
String protocol = null;
- serviceNameMapping.map(serviceInterface, group, version, protocol);
+ URL url =
URL.valueOf("dubbo://127.0.0.1:20880").setServiceInterface(serviceInterface)
+ .addParameter(GROUP_KEY, group)
+ .addParameter(VERSION_KEY, version);
+
+ serviceNameMapping.map(url);
ApplicationModel.getConfigManager().removeConfig(new
ApplicationConfig(serviceName));
ApplicationModel.getConfigManager().setApplication(new
ApplicationConfig(serviceName2));
- serviceNameMapping.map(serviceInterface, group, version, protocol);
+ serviceNameMapping.map(url);
- Set<String> serviceNames = serviceNameMapping.get(serviceInterface,
group, version, protocol);
+ Set<String> serviceNames = serviceNameMapping.get(url);
assertEquals(new TreeSet(asList(serviceName, serviceName2)),
serviceNames);
diff --git
a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/event/listener/CustomizableServiceInstanceListener.java
b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/event/listener/CustomizableServiceInstanceListener.java
index d2ee50f..f739ca8 100644
---
a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/event/listener/CustomizableServiceInstanceListener.java
+++
b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/event/listener/CustomizableServiceInstanceListener.java
@@ -26,7 +26,9 @@ import
org.apache.dubbo.registry.client.event.ServiceInstancePreRegisteredEvent;
* Customize the {@link ServiceInstance} before registering to Registry.
*
* @since 2.7.5
+ * @deprecated 2.7.8 Current class will be removed since 3.0.0
*/
+@Deprecated
public class CustomizableServiceInstanceListener implements
EventListener<ServiceInstancePreRegisteredEvent> {
@Override
diff --git
a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/ServiceInstanceMetadataUtils.java
b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/ServiceInstanceMetadataUtils.java
index b66ae79..14c7988 100644
---
a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/ServiceInstanceMetadataUtils.java
+++
b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/ServiceInstanceMetadataUtils.java
@@ -207,10 +207,10 @@ public class ServiceInstanceMetadataUtils {
|| metadata.containsKey(METADATA_SERVICE_URLS_PROPERTY_NAME);
}
- public static void setEndpoints(ServiceInstance serviceInstance,
Map<String, Integer> protocolPortss) {
+ public static void setEndpoints(ServiceInstance serviceInstance,
Map<String, Integer> protocolPorts) {
Map<String, String> metadata = serviceInstance.getMetadata();
List<Endpoint> endpoints = new ArrayList<>();
- protocolPortss.forEach((k, v) -> {
+ protocolPorts.forEach((k, v) -> {
Endpoint endpoint = new Endpoint(v, k);
endpoints.add(endpoint);
});
diff --git
a/dubbo-registry/dubbo-registry-api/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.event.EventListener
b/dubbo-registry/dubbo-registry-api/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.event.EventListener
index 2ac7539..bbd6b81 100644
---
a/dubbo-registry/dubbo-registry-api/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.event.EventListener
+++
b/dubbo-registry/dubbo-registry-api/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.event.EventListener
@@ -1,4 +1,7 @@
-service-instance=org.apache.dubbo.registry.client.event.listener.CustomizableServiceInstanceListener
+# "service-instance" has been deprecated since 2.7.8
+#
service-instance=org.apache.dubbo.registry.client.event.listener.CustomizableServiceInstanceListener
+
registry-logging=org.apache.dubbo.registry.client.event.listener.LoggingEventListener
+
# "publishing-remote-metadata" in introduced since 2.7.8
publishing-remote-metadata=org.apache.dubbo.registry.client.event.listener.PublishingRemoteMetadataListener
\ No newline at end of file