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 2a0d015  2.7.8 service introspection update (#6308)
2a0d015 is described below

commit 2a0d015ac220a1e869c8aaf44aebdcef624e193f
Author: Mercy Ma <mercybl...@gmail.com>
AuthorDate: Thu Jun 11 17:16:00 2020 +0800

    2.7.8 service introspection update (#6308)
    
    * 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
---
 .../org/apache/dubbo/config/ReferenceConfig.java   | 21 +-----
 .../org/apache/dubbo/config/ServiceConfig.java     | 16 -----
 .../PublishingServiceDefinitionListener.java       | 74 ++++++++++++++++++++++
 .../dubbo/config/utils/ConfigValidationUtils.java  |  5 +-
 .../internal/org.apache.dubbo.event.EventListener  |  4 +-
 .../DynamicConfigurationServiceNameMapping.java    |  5 +-
 6 files changed, 85 insertions(+), 40 deletions(-)

diff --git 
a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ReferenceConfig.java
 
b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ReferenceConfig.java
index 138a68e..f03d49f 100644
--- 
a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ReferenceConfig.java
+++ 
b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ReferenceConfig.java
@@ -34,7 +34,6 @@ import 
org.apache.dubbo.config.event.ReferenceConfigInitializedEvent;
 import org.apache.dubbo.config.utils.ConfigValidationUtils;
 import org.apache.dubbo.event.Event;
 import org.apache.dubbo.event.EventDispatcher;
-import org.apache.dubbo.metadata.WritableMetadataService;
 import org.apache.dubbo.rpc.Invoker;
 import org.apache.dubbo.rpc.Protocol;
 import org.apache.dubbo.rpc.ProxyFactory;
@@ -62,20 +61,16 @@ import static 
org.apache.dubbo.common.constants.CommonConstants.ANY_VALUE;
 import static org.apache.dubbo.common.constants.CommonConstants.CLUSTER_KEY;
 import static 
org.apache.dubbo.common.constants.CommonConstants.COMMA_SEPARATOR;
 import static org.apache.dubbo.common.constants.CommonConstants.CONSUMER_SIDE;
-import static 
org.apache.dubbo.common.constants.CommonConstants.DEFAULT_METADATA_STORAGE_TYPE;
 import static org.apache.dubbo.common.constants.CommonConstants.INTERFACE_KEY;
 import static 
org.apache.dubbo.common.constants.CommonConstants.LOCALHOST_VALUE;
-import static org.apache.dubbo.common.constants.CommonConstants.METADATA_KEY;
 import static org.apache.dubbo.common.constants.CommonConstants.METHODS_KEY;
 import static org.apache.dubbo.common.constants.CommonConstants.MONITOR_KEY;
 import static 
org.apache.dubbo.common.constants.CommonConstants.PROXY_CLASS_REF;
-import static 
org.apache.dubbo.common.constants.CommonConstants.REMOTE_METADATA_STORAGE_TYPE;
 import static org.apache.dubbo.common.constants.CommonConstants.REVISION_KEY;
 import static 
org.apache.dubbo.common.constants.CommonConstants.SEMICOLON_SPLIT_PATTERN;
 import static org.apache.dubbo.common.constants.CommonConstants.SIDE_KEY;
 import static org.apache.dubbo.common.utils.NetUtils.isInvalidLocalHost;
 import static org.apache.dubbo.config.Constants.DUBBO_IP_TO_REGISTRY;
-import static org.apache.dubbo.registry.Constants.CONSUMER_PROTOCOL;
 import static org.apache.dubbo.registry.Constants.REGISTER_IP_KEY;
 import static org.apache.dubbo.rpc.Constants.LOCAL_PROTOCOL;
 import static org.apache.dubbo.rpc.cluster.Constants.REFER_KEY;
@@ -221,10 +216,6 @@ public class ReferenceConfig<T> extends 
ReferenceConfigBase<T> {
         // appendParameters(map, consumer, Constants.DEFAULT_KEY);
         AbstractConfig.appendParameters(map, consumer);
         AbstractConfig.appendParameters(map, this);
-        MetadataReportConfig metadataReportConfig = getMetadataReportConfig();
-        if (metadataReportConfig != null && metadataReportConfig.isValid()) {
-            map.putIfAbsent(METADATA_KEY, REMOTE_METADATA_STORAGE_TYPE);
-        }
         Map<String, AsyncMethodInfo> attributes = null;
         if (CollectionUtils.isNotEmpty(getMethods())) {
             attributes = new HashMap<>();
@@ -352,16 +343,6 @@ public class ReferenceConfig<T> extends 
ReferenceConfigBase<T> {
         if (logger.isInfoEnabled()) {
             logger.info("Refer dubbo service " + interfaceClass.getName() + " 
from url " + invoker.getUrl());
         }
-        /**
-         * @since 2.7.0
-         * ServiceData Store
-         */
-        String metadata = map.get(METADATA_KEY);
-        WritableMetadataService metadataService = 
WritableMetadataService.getExtension(metadata == null ? 
DEFAULT_METADATA_STORAGE_TYPE : metadata);
-        if (metadataService != null) {
-            URL consumerURL = new URL(CONSUMER_PROTOCOL, 
map.remove(REGISTER_IP_KEY), 0, map.get(INTERFACE_KEY), map);
-            metadataService.publishServiceDefinition(consumerURL);
-        }
         // create service proxy
         return (T) PROXY_FACTORY.getProxy(invoker, 
ProtocolUtils.isGeneric(generic));
     }
@@ -466,7 +447,7 @@ public class ReferenceConfig<T> extends 
ReferenceConfigBase<T> {
     }
 
     private void postProcessConfig() {
-        List<ConfigPostProcessor> configPostProcessors 
=ExtensionLoader.getExtensionLoader(ConfigPostProcessor.class)
+        List<ConfigPostProcessor> configPostProcessors = 
ExtensionLoader.getExtensionLoader(ConfigPostProcessor.class)
                 .getActivateExtension(URL.valueOf("configPostProcessor://"), 
(String[]) null);
         configPostProcessors.forEach(component -> 
component.postProcessReferConfig(this));
     }
diff --git 
a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ServiceConfig.java
 
b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ServiceConfig.java
index 3ad4545..c2d4a85 100644
--- 
a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ServiceConfig.java
+++ 
b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ServiceConfig.java
@@ -37,7 +37,6 @@ import org.apache.dubbo.config.support.Parameter;
 import org.apache.dubbo.config.utils.ConfigValidationUtils;
 import org.apache.dubbo.event.Event;
 import org.apache.dubbo.event.EventDispatcher;
-import org.apache.dubbo.metadata.WritableMetadataService;
 import org.apache.dubbo.rpc.Exporter;
 import org.apache.dubbo.rpc.Invoker;
 import org.apache.dubbo.rpc.Protocol;
@@ -68,16 +67,13 @@ import java.util.concurrent.TimeUnit;
 
 import static org.apache.dubbo.common.constants.CommonConstants.ANYHOST_KEY;
 import static org.apache.dubbo.common.constants.CommonConstants.ANY_VALUE;
-import static 
org.apache.dubbo.common.constants.CommonConstants.DEFAULT_METADATA_STORAGE_TYPE;
 import static org.apache.dubbo.common.constants.CommonConstants.DUBBO;
 import static 
org.apache.dubbo.common.constants.CommonConstants.DUBBO_IP_TO_BIND;
 import static 
org.apache.dubbo.common.constants.CommonConstants.LOCALHOST_VALUE;
-import static org.apache.dubbo.common.constants.CommonConstants.METADATA_KEY;
 import static org.apache.dubbo.common.constants.CommonConstants.METHODS_KEY;
 import static org.apache.dubbo.common.constants.CommonConstants.MONITOR_KEY;
 import static org.apache.dubbo.common.constants.CommonConstants.PROVIDER_SIDE;
 import static org.apache.dubbo.common.constants.CommonConstants.REGISTER_KEY;
-import static 
org.apache.dubbo.common.constants.CommonConstants.REMOTE_METADATA_STORAGE_TYPE;
 import static org.apache.dubbo.common.constants.CommonConstants.REVISION_KEY;
 import static org.apache.dubbo.common.constants.CommonConstants.SIDE_KEY;
 import static org.apache.dubbo.common.constants.RegistryConstants.DYNAMIC_KEY;
@@ -344,10 +340,6 @@ public class ServiceConfig<T> extends ServiceConfigBase<T> 
{
         AbstractConfig.appendParameters(map, provider);
         AbstractConfig.appendParameters(map, protocolConfig);
         AbstractConfig.appendParameters(map, this);
-        MetadataReportConfig metadataReportConfig = getMetadataReportConfig();
-        if (metadataReportConfig != null && metadataReportConfig.isValid()) {
-            map.putIfAbsent(METADATA_KEY, REMOTE_METADATA_STORAGE_TYPE);
-        }
         if (CollectionUtils.isNotEmpty(getMethods())) {
             for (MethodConfig method : getMethods()) {
                 AbstractConfig.appendParameters(map, method, method.getName());
@@ -502,14 +494,6 @@ public class ServiceConfig<T> extends ServiceConfigBase<T> 
{
                     Exporter<?> exporter = PROTOCOL.export(wrapperInvoker);
                     exporters.add(exporter);
                 }
-                /**
-                 * @since 2.7.0
-                 * ServiceData Store
-                 */
-                WritableMetadataService metadataService = 
WritableMetadataService.getExtension(url.getParameter(METADATA_KEY, 
DEFAULT_METADATA_STORAGE_TYPE));
-                if (metadataService != null) {
-                    metadataService.publishServiceDefinition(url);
-                }
             }
         }
         this.urls.add(url);
diff --git 
a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/event/listener/PublishingServiceDefinitionListener.java
 
b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/event/listener/PublishingServiceDefinitionListener.java
new file mode 100644
index 0000000..9731034
--- /dev/null
+++ 
b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/event/listener/PublishingServiceDefinitionListener.java
@@ -0,0 +1,74 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.dubbo.config.event.listener;
+
+import org.apache.dubbo.common.URL;
+import org.apache.dubbo.config.AbstractInterfaceConfig;
+import org.apache.dubbo.config.ApplicationConfig;
+import org.apache.dubbo.config.MetadataReportConfig;
+import org.apache.dubbo.config.event.ReferenceConfigInitializedEvent;
+import org.apache.dubbo.config.event.ServiceConfigExportedEvent;
+import org.apache.dubbo.event.EventListener;
+import org.apache.dubbo.event.GenericEventListener;
+import org.apache.dubbo.metadata.WritableMetadataService;
+
+import static 
org.apache.dubbo.common.constants.CommonConstants.DEFAULT_METADATA_STORAGE_TYPE;
+import static 
org.apache.dubbo.common.constants.CommonConstants.REMOTE_METADATA_STORAGE_TYPE;
+import static org.apache.dubbo.metadata.WritableMetadataService.getExtension;
+
+/**
+ * An {@link EventListener} {@link 
WritableMetadataService#publishServiceDefinition(URL) publishs the service 
definition}
+ * when {@link ServiceConfigExportedEvent the event of the exported Dubbo 
service} and
+ * {@link ReferenceConfigInitializedEvent the event of the referenced Dubbo 
service} is raised.
+ *
+ * @see GenericEventListener
+ * @see ServiceConfigExportedEvent
+ * @see ReferenceConfigInitializedEvent
+ * @since 2.7.8
+ */
+public class PublishingServiceDefinitionListener extends GenericEventListener {
+
+    public void onEvent(ReferenceConfigInitializedEvent event) {
+        handleEvent(event.getReferenceConfig());
+    }
+
+    public void onEvent(ServiceConfigExportedEvent event) {
+        handleEvent(event.getServiceConfig());
+    }
+
+    private void handleEvent(AbstractInterfaceConfig config) {
+        String metadataType = getMetadataType(config);
+        for (URL exportedURL : config.getExportedUrls()) {
+            WritableMetadataService metadataService = 
getExtension(metadataType);
+            if (metadataService != null) {
+                metadataService.publishServiceDefinition(exportedURL);
+            }
+        }
+    }
+
+    private String getMetadataType(AbstractInterfaceConfig config) {
+        ApplicationConfig applicationConfig = config.getApplication();
+        String metadataType = applicationConfig.getMetadataType();
+        if (REMOTE_METADATA_STORAGE_TYPE.equals(metadataType)) {
+            MetadataReportConfig metadataReportConfig = 
config.getMetadataReportConfig();
+            if (metadataReportConfig == null || 
!metadataReportConfig.isValid()) {
+                metadataType = DEFAULT_METADATA_STORAGE_TYPE;
+            }
+        }
+        return metadataType;
+    }
+}
diff --git 
a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/utils/ConfigValidationUtils.java
 
b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/utils/ConfigValidationUtils.java
index f9b0e35..ba8b9a7 100644
--- 
a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/utils/ConfigValidationUtils.java
+++ 
b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/utils/ConfigValidationUtils.java
@@ -297,6 +297,7 @@ public class ConfigValidationUtils {
         checkExtension(ProxyFactory.class, PROXY_KEY, config.getProxy());
         checkExtension(Cluster.class, CLUSTER_KEY, config.getCluster());
         checkMultiExtension(Filter.class, FILE_KEY, config.getFilter());
+        checkMultiExtension(InvokerListener.class, LISTENER_KEY, 
config.getListener());
         checkNameHasSymbol(LAYER_KEY, config.getLayer());
 
         List<MethodConfig> methods = config.getMethods();
@@ -311,7 +312,7 @@ public class ConfigValidationUtils {
         checkName(TOKEN_KEY, config.getToken());
         checkPathName(PATH_KEY, config.getPath());
 
-        checkMultiExtension(ExporterListener.class, LISTENER_KEY, 
config.getListener());
+        checkMultiExtension(ExporterListener.class, "listener", 
config.getListener());
 
         validateAbstractInterfaceConfig(config);
 
@@ -336,7 +337,7 @@ public class ConfigValidationUtils {
     }
 
     public static void validateReferenceConfig(ReferenceConfig config) {
-        checkMultiExtension(InvokerListener.class, LISTENER_KEY, 
config.getListener());
+        checkMultiExtension(InvokerListener.class, "listener", 
config.getListener());
         checkKey(VERSION_KEY, config.getVersion());
         checkKey(GROUP_KEY, config.getGroup());
         checkName(CLIENT_KEY, config.getClient());
diff --git 
a/dubbo-config/dubbo-config-api/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.event.EventListener
 
b/dubbo-config/dubbo-config-api/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.event.EventListener
index db73041..b1946c0 100644
--- 
a/dubbo-config/dubbo-config-api/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.event.EventListener
+++ 
b/dubbo-config/dubbo-config-api/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.event.EventListener
@@ -1,2 +1,4 @@
 
service-mapping=org.apache.dubbo.config.event.listener.ServiceNameMappingListener
-config-logging=org.apache.dubbo.config.event.listener.LoggingEventListener
\ No newline at end of file
+config-logging=org.apache.dubbo.config.event.listener.LoggingEventListener
+# since 2.7.8
+publishing-service-definition=org.apache.dubbo.config.event.listener.PublishingServiceDefinitionListener
\ No newline at end of file
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 d84eba0..b03148a 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
@@ -27,6 +27,7 @@ import java.util.Set;
 
 import static java.lang.String.valueOf;
 import static java.util.Arrays.asList;
+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;
 
@@ -72,7 +73,9 @@ public class DynamicConfigurationServiceNameMapping 
implements ServiceNameMappin
         Set<String> serviceNames = new LinkedHashSet<>();
         execute(() -> {
             Set<String> keys = 
dynamicConfiguration.getConfigKeys(buildGroup(serviceInterface, group, version, 
protocol));
-            serviceNames.addAll(keys);
+            if (isNotEmpty(keys)) {
+                serviceNames.addAll(keys);
+            }
         });
         return Collections.unmodifiableSet(serviceNames);
     }

Reply via email to