This is an automated email from the ASF dual-hosted git repository.
liujun 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 ef8cdfc redefine MetadataReport
ef8cdfc is described below
commit ef8cdfcf49ca73d3cb31bf594526311d3eabe664
Author: ken.lj <[email protected]>
AuthorDate: Tue Jun 16 00:38:33 2020 +0800
redefine MetadataReport
---
.../src/main/java/org/apache/dubbo/common/URL.java | 11 ++-
.../dubbo/common/constants/CommonConstants.java | 6 ++
.../org/apache/dubbo/config/ServiceConfig.java | 7 +-
.../event/listener/ServiceNameMappingListener.java | 55 -------------
.../metadata/DefaultMetadataParamsFilter.java | 3 +-
.../DynamicConfigurationServiceNameMapping.java | 33 ++++----
.../org/apache/dubbo/metadata/MetadataInfo.java | 5 +-
.../dubbo/metadata/MetadataServiceNameMapping.java | 71 +++++++++++++++++
.../apache/dubbo/metadata/ServiceNameMapping.java | 33 +++++---
.../dubbo/metadata/report/MetadataReport.java | 27 +++++--
.../org.apache.dubbo.metadata.ServiceNameMapping | 3 +-
...DynamicConfigurationServiceNameMappingTest.java | 90 ----------------------
.../apache/dubbo/metadata/MetadataInfoTest.java | 2 +-
.../registry/client/DefaultServiceInstance.java | 2 +-
.../registry/client/ServiceDiscoveryRegistry.java | 27 +------
.../listener/ServiceInstancesChangedListener.java | 6 +-
.../registry/client/metadata/MetadataUtils.java | 1 -
.../store/InMemoryWritableMetadataService.java | 3 +-
18 files changed, 172 insertions(+), 213 deletions(-)
diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/URL.java
b/dubbo-common/src/main/java/org/apache/dubbo/common/URL.java
index e605643..e28cf12 100644
--- a/dubbo-common/src/main/java/org/apache/dubbo/common/URL.java
+++ b/dubbo-common/src/main/java/org/apache/dubbo/common/URL.java
@@ -793,6 +793,15 @@ class URL implements Serializable {
return URL.decode(getMethodParameter(method, key, defaultValue));
}
+ public String getMethodParameterStrict(String method, String key) {
+ Map<String, String> keyMap = methodParameters.get(method);
+ String value = null;
+ if (keyMap != null) {
+ value = keyMap.get(key);
+ }
+ return value;
+ }
+
public String getMethodParameter(String method, String key) {
Map<String, String> keyMap = methodParameters.get(method);
String value = null;
@@ -984,7 +993,7 @@ class URL implements Serializable {
}
return false;
}
- String value = getMethodParameter(method, key);
+ String value = getMethodParameterStrict(method, key);
return StringUtils.isNotEmpty(value);
}
diff --git
a/dubbo-common/src/main/java/org/apache/dubbo/common/constants/CommonConstants.java
b/dubbo-common/src/main/java/org/apache/dubbo/common/constants/CommonConstants.java
index cac52fe..c63ce71 100644
---
a/dubbo-common/src/main/java/org/apache/dubbo/common/constants/CommonConstants.java
+++
b/dubbo-common/src/main/java/org/apache/dubbo/common/constants/CommonConstants.java
@@ -183,6 +183,12 @@ public interface CommonConstants {
String METADATA_KEY = "metadata-type";
+ String MAPPING_KEY = "mapping-type";
+
+ String CONFIG_MAPPING_TYPE = "config";
+
+ String METADATA_MAPPING_TYPE = "metadata";
+
String DEFAULT_METADATA_STORAGE_TYPE = "local";
String REMOTE_METADATA_STORAGE_TYPE = "remote";
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 68dc97a..b279e67 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,6 +37,7 @@ 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.ServiceNameMapping;
import org.apache.dubbo.registry.client.metadata.MetadataUtils;
import org.apache.dubbo.rpc.Exporter;
import org.apache.dubbo.rpc.Invoker;
@@ -71,6 +72,7 @@ import static
org.apache.dubbo.common.constants.CommonConstants.ANY_VALUE;
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.MAPPING_KEY;
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;
@@ -209,7 +211,10 @@ public class ServiceConfig<T> extends ServiceConfigBase<T>
{
}
public void exported() {
-
+ List<URL> exportedURLs = this.getExportedUrls();
+ exportedURLs.forEach(url -> {
+
ServiceNameMapping.getExtension(getApplication().getParameters().get(MAPPING_KEY)).map(url);
+ });
// dispatch a ServiceConfigExportedEvent since 2.7.4
dispatch(new ServiceConfigExportedEvent(this));
}
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
deleted file mode 100644
index 4dcfde3..0000000
---
a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/event/listener/ServiceNameMappingListener.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * 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.ServiceConfig;
-import org.apache.dubbo.config.event.ServiceConfigExportedEvent;
-import org.apache.dubbo.event.EventListener;
-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;
-
-/**
- * An {@link EventListener event listener} for mapping {@link
ServiceConfig#getExportedUrls() the exported Dubbo
- * service inerface} to its service name
- *
- * @see ServiceNameMapping
- * @see ServiceConfig#getExportedUrls()
- * @since 2.7.5
- */
-public class ServiceNameMappingListener implements
EventListener<ServiceConfigExportedEvent> {
-
- private final ServiceNameMapping serviceNameMapping =
getDefaultExtension();
-
- @Override
- public void onEvent(ServiceConfigExportedEvent event) {
- 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);
- });
- }
-}
diff --git
a/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/DefaultMetadataParamsFilter.java
b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/DefaultMetadataParamsFilter.java
index 0563e43..7a11096 100644
---
a/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/DefaultMetadataParamsFilter.java
+++
b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/DefaultMetadataParamsFilter.java
@@ -25,7 +25,6 @@ import static
org.apache.dubbo.common.constants.CommonConstants.LOADBALANCE_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.PATH_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.RELEASE_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.TIMEOUT_KEY;
-import static org.apache.dubbo.common.constants.CommonConstants.TIMESTAMP_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY;
import static org.apache.dubbo.remoting.Constants.CODEC_KEY;
import static org.apache.dubbo.remoting.Constants.CONNECTIONS_KEY;
@@ -44,7 +43,7 @@ public class DefaultMetadataParamsFilter implements
MetadataParamsFilter {
return new String[]{
CODEC_KEY, EXCHANGER_KEY, SERIALIZATION_KEY, CLUSTER_KEY,
CONNECTIONS_KEY, DEPRECATED_KEY,
GROUP_KEY, LOADBALANCE_KEY, MOCK_KEY, PATH_KEY, TIMEOUT_KEY,
TOKEN_KEY, VERSION_KEY, WARMUP_KEY,
- WEIGHT_KEY, TIMESTAMP_KEY, DUBBO_VERSION_KEY, RELEASE_KEY
+ WEIGHT_KEY, DUBBO_VERSION_KEY, RELEASE_KEY
};
}
}
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..a25d07a 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,7 +28,8 @@ import java.util.Set;
import static java.lang.String.valueOf;
import static java.util.Arrays.asList;
-import static org.apache.dubbo.common.utils.StringUtils.SLASH;
+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.rpc.model.ApplicationModel.getName;
/**
@@ -42,7 +44,11 @@ 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 url) {
+ String serviceInterface = url.getServiceInterface();
+ String group = url.getParameter(GROUP_KEY);
+ String version = url.getParameter(VERSION_KEY);
+ String protocol = url.getProtocol();
if (IGNORED_SERVICE_INTERFACES.contains(serviceInterface)) {
return;
@@ -55,8 +61,9 @@ public class DynamicConfigurationServiceNameMapping
implements ServiceNameMappin
// It does matter whatever the content is, we just need a record
String key = getName();
String content = valueOf(System.currentTimeMillis());
+
execute(() -> {
- dynamicConfiguration.publishConfig(key,
buildGroup(serviceInterface, group, version, protocol), content);
+ dynamicConfiguration.publishConfig(key,
ServiceNameMapping.buildGroup(serviceInterface, group, version, protocol),
content);
if (logger.isInfoEnabled()) {
logger.info(String.format("Dubbo service[%s] mapped to
interface name[%s].",
group, serviceInterface, group));
@@ -65,28 +72,22 @@ public class DynamicConfigurationServiceNameMapping
implements ServiceNameMappin
}
@Override
- public Set<String> get(String serviceInterface, String group, String
version, String protocol) {
-
+ public Set<String> get(URL url) {
+ String serviceInterface = url.getServiceInterface();
+ String group = url.getParameter(GROUP_KEY);
+ String version = url.getParameter(VERSION_KEY);
+ String protocol = url.getProtocol();
DynamicConfiguration dynamicConfiguration =
DynamicConfiguration.getDynamicConfiguration();
Set<String> serviceNames = new LinkedHashSet<>();
execute(() -> {
- Set<String> keys =
dynamicConfiguration.getConfigKeys(buildGroup(serviceInterface, group, version,
protocol));
+ Set<String> keys = dynamicConfiguration
+
.getConfigKeys(ServiceNameMapping.buildGroup(serviceInterface, group, version,
protocol));
serviceNames.addAll(keys);
});
return Collections.unmodifiableSet(serviceNames);
}
- protected static String buildGroup(String serviceInterface, String group,
String version, String protocol) {
- // the issue : https://github.com/apache/dubbo/issues/4671
- // StringBuilder groupBuilder = new
StringBuilder(serviceInterface)
- // .append(KEY_SEPARATOR).append(defaultString(group))
- // .append(KEY_SEPARATOR).append(defaultString(version))
- //
.append(KEY_SEPARATOR).append(defaultString(protocol));
- // return groupBuilder.toString();
- return DEFAULT_MAPPING_GROUP + SLASH + serviceInterface;
- }
-
private void execute(Runnable runnable) {
try {
runnable.run();
diff --git
a/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/MetadataInfo.java
b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/MetadataInfo.java
index 01e3c09..f235655 100644
---
a/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/MetadataInfo.java
+++
b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/MetadataInfo.java
@@ -42,7 +42,8 @@ public class MetadataInfo implements Serializable {
private String revision;
private Map<String, ServiceInfo> services;
- public MetadataInfo() {
+ public MetadataInfo(String app) {
+ this.app = app;
this.services = new HashMap<>();
}
@@ -166,7 +167,7 @@ public class MetadataInfo implements Serializable {
String[] methods = url.getParameter(METHODS_KEY,
(String[]) null);
if (methods != null) {
for (String method : methods) {
- String mValue = url.getMethodParameter(method,
p);
+ String mValue =
url.getMethodParameterStrict(method, p);
if (StringUtils.isNotEmpty(mValue)) {
params.put(method + DOT_SEPARATOR + p,
mValue);
}
diff --git
a/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/MetadataServiceNameMapping.java
b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/MetadataServiceNameMapping.java
new file mode 100644
index 0000000..9c0c600
--- /dev/null
+++
b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/MetadataServiceNameMapping.java
@@ -0,0 +1,71 @@
+/*
+ * 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.metadata;
+
+import org.apache.dubbo.common.URL;
+import org.apache.dubbo.common.utils.CollectionUtils;
+import org.apache.dubbo.metadata.report.MetadataReport;
+import org.apache.dubbo.metadata.report.MetadataReportInstance;
+
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Set;
+
+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.rpc.model.ApplicationModel.getName;
+
+public class MetadataServiceNameMapping implements ServiceNameMapping {
+ private static final List<String> IGNORED_SERVICE_INTERFACES =
asList(MetadataService.class.getName());
+
+ @Override
+ public void map(URL url) {
+ String serviceInterface = url.getServiceInterface();
+ String group = url.getParameter(GROUP_KEY);
+ String version = url.getParameter(VERSION_KEY);
+ String protocol = url.getProtocol();
+
+ if (IGNORED_SERVICE_INTERFACES.contains(serviceInterface)) {
+ return;
+ }
+
+ List<MetadataReport> metadataReports =
MetadataReportInstance.getMetadataReports(true);
+ metadataReports.forEach(reporter -> {
+
reporter.registerServiceAppMapping(ServiceNameMapping.buildGroup(serviceInterface,
group, version, protocol), getName(), url);
+ });
+ }
+
+ @Override
+ public Set<String> get(URL url) {
+ String serviceInterface = url.getServiceInterface();
+ String group = url.getParameter(GROUP_KEY);
+ String version = url.getParameter(VERSION_KEY);
+ String protocol = url.getProtocol();
+
+ List<MetadataReport> metadataReports =
MetadataReportInstance.getMetadataReports(true);
+ Set<String> serviceNames = new LinkedHashSet<>();
+ for (MetadataReport reporter : metadataReports) {
+ Set<String> apps =
reporter.getServiceAppMapping(ServiceNameMapping.buildGroup(serviceInterface,
group, version, protocol), url);
+ if (CollectionUtils.isNotEmpty(apps)) {
+ serviceNames.addAll(apps);
+ break;
+ }
+ }
+ return serviceNames;
+ }
+}
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..44d55c5 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,40 +16,35 @@
*/
package org.apache.dubbo.metadata;
+import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.extension.SPI;
import java.util.Set;
+import static
org.apache.dubbo.common.constants.CommonConstants.CONFIG_MAPPING_TYPE;
import static
org.apache.dubbo.common.extension.ExtensionLoader.getExtensionLoader;
+import static org.apache.dubbo.common.utils.StringUtils.SLASH;
+import static
org.apache.dubbo.metadata.DynamicConfigurationServiceNameMapping.DEFAULT_MAPPING_GROUP;
/**
* The interface for Dubbo service name Mapping
*
* @since 2.7.5
*/
-@SPI("default")
+@SPI("config")
public interface ServiceNameMapping {
/**
* Map the specified Dubbo service interface, group, version and protocol
to current Dubbo service name
- *
- * @param serviceInterface the class name of Dubbo service interface
- * @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)
*/
- void map(String serviceInterface, String group, String version, String
protocol);
+ void map(URL url);
/**
* Get the service names from the specified Dubbo service interface,
group, version and protocol
*
- * @param serviceInterface the class name of Dubbo service interface
- * @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
*/
- Set<String> get(String serviceInterface, String group, String version,
String protocol);
+ Set<String> get(URL url);
/**
@@ -61,4 +56,18 @@ public interface ServiceNameMapping {
static ServiceNameMapping getDefaultExtension() {
return
getExtensionLoader(ServiceNameMapping.class).getDefaultExtension();
}
+
+ static ServiceNameMapping getExtension(String name) {
+ return getExtensionLoader(ServiceNameMapping.class).getExtension(name
== null ? CONFIG_MAPPING_TYPE : name);
+ }
+
+ static String buildGroup(String serviceInterface, String group, String
version, String protocol) {
+ // the issue : https://github.com/apache/dubbo/issues/4671
+ // StringBuilder groupBuilder = new
StringBuilder(serviceInterface)
+ // .append(KEY_SEPARATOR).append(defaultString(group))
+ // .append(KEY_SEPARATOR).append(defaultString(version))
+ //
.append(KEY_SEPARATOR).append(defaultString(protocol));
+ // return groupBuilder.toString();
+ return DEFAULT_MAPPING_GROUP + SLASH + serviceInterface;
+ }
}
diff --git
a/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/report/MetadataReport.java
b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/report/MetadataReport.java
index 4bc133d..256ae6e 100644
---
a/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/report/MetadataReport.java
+++
b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/report/MetadataReport.java
@@ -24,20 +24,23 @@ import
org.apache.dubbo.metadata.report.identifier.MetadataIdentifier;
import org.apache.dubbo.metadata.report.identifier.ServiceMetadataIdentifier;
import
org.apache.dubbo.metadata.report.identifier.SubscriberMetadataIdentifier;
+import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
public interface MetadataReport {
+ /**
+ * Service Definition -- START
+ **/
void storeProviderMetadata(MetadataIdentifier providerMetadataIdentifier,
ServiceDefinition serviceDefinition);
- void storeConsumerMetadata(MetadataIdentifier consumerMetadataIdentifier,
Map<String, String> serviceParameterMap);
-
- List<String> getExportedURLs(ServiceMetadataIdentifier metadataIdentifier);
-
String getServiceDefinition(MetadataIdentifier metadataIdentifier);
+ /**
+ * Application Metadata -- START
+ **/
default void publishAppMetadata(SubscriberMetadataIdentifier identifier,
MetadataInfo metadataInfo) {
}
@@ -46,8 +49,22 @@ public interface MetadataReport {
}
/**
- * deprecated
+ * Service<-->Application Mapping -- START
**/
+ default Set<String> getServiceAppMapping(String serviceKey, URL url) {
+ return Collections.emptySet();
+ }
+
+ default void registerServiceAppMapping(String serviceKey, String
application, URL url) {
+ return;
+ }
+
+ /**
+ * deprecated or need triage
+ **/
+ void storeConsumerMetadata(MetadataIdentifier consumerMetadataIdentifier,
Map<String, String> serviceParameterMap);
+
+ List<String> getExportedURLs(ServiceMetadataIdentifier metadataIdentifier);
void saveServiceMetadata(ServiceMetadataIdentifier metadataIdentifier, URL
url);
diff --git
a/dubbo-metadata/dubbo-metadata-api/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.metadata.ServiceNameMapping
b/dubbo-metadata/dubbo-metadata-api/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.metadata.ServiceNameMapping
index 3975068..d43b342 100644
---
a/dubbo-metadata/dubbo-metadata-api/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.metadata.ServiceNameMapping
+++
b/dubbo-metadata/dubbo-metadata-api/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.metadata.ServiceNameMapping
@@ -1 +1,2 @@
-default=org.apache.dubbo.metadata.DynamicConfigurationServiceNameMapping
\ No newline at end of file
+config=org.apache.dubbo.metadata.DynamicConfigurationServiceNameMapping
+metadata=org.apache.dubbo.metadata.MetadataServiceNameMapping
\ No newline at end of file
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
deleted file mode 100644
index 0e677df..0000000
---
a/dubbo-metadata/dubbo-metadata-api/src/test/java/org/apache/dubbo/metadata/DynamicConfigurationServiceNameMappingTest.java
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * 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.metadata;
-
-import org.apache.dubbo.common.config.configcenter.DynamicConfiguration;
-import org.apache.dubbo.common.config.configcenter.DynamicConfigurationFactory;
-import org.apache.dubbo.config.ApplicationConfig;
-import org.apache.dubbo.rpc.model.ApplicationModel;
-
-import org.junit.jupiter.api.BeforeAll;
-import org.junit.jupiter.api.Test;
-
-import java.util.Set;
-import java.util.TreeSet;
-
-import static java.util.Arrays.asList;
-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;
-
-/**
- * {@link DynamicConfigurationServiceNameMapping} Test
- *
- * @since 2.7.5
- */
-public class DynamicConfigurationServiceNameMappingTest {
-
-
- private final ServiceNameMapping serviceNameMapping =
getDefaultExtension();
-
- @BeforeAll
- public static void setUp() throws Exception {
-
- DynamicConfiguration configuration =
getExtensionLoader(DynamicConfigurationFactory.class)
- .getExtension("file")
- .getDynamicConfiguration(null);
-
-
ApplicationModel.getEnvironment().setDynamicConfiguration(configuration);
- }
-
- @Test
- public void testBuildGroup() {
- assertEquals("mapping/test", buildGroup("test", null, null, null));
- assertEquals("mapping/test", buildGroup("test", "default", null,
null));
- assertEquals("mapping/test", buildGroup("test", "default", "1.0.0",
null));
- assertEquals("mapping/test", buildGroup("test", "default", "1.0.0",
"dubbo"));
- }
-
- @Test
- public void testMapAndGet() {
-
- String serviceName = "test";
- String serviceName2 = "test2";
-
- ApplicationModel.getConfigManager().setApplication(new
ApplicationConfig(serviceName));
-
- String serviceInterface = "org.apache.dubbo.service.UserService";
- String group = null;
- String version = null;
- String protocol = null;
-
- serviceNameMapping.map(serviceInterface, group, version, protocol);
-
- ApplicationModel.getConfigManager().removeConfig(new
ApplicationConfig(serviceName));
- ApplicationModel.getConfigManager().setApplication(new
ApplicationConfig(serviceName2));
-
- serviceNameMapping.map(serviceInterface, group, version, protocol);
-
- Set<String> serviceNames = serviceNameMapping.get(serviceInterface,
group, version, protocol);
-
- assertEquals(new TreeSet(asList(serviceName, serviceName2)),
serviceNames);
-
- ApplicationModel.getConfigManager().removeConfig(new
ApplicationConfig(serviceName2));
- }
-}
diff --git
a/dubbo-metadata/dubbo-metadata-api/src/test/java/org/apache/dubbo/metadata/MetadataInfoTest.java
b/dubbo-metadata/dubbo-metadata-api/src/test/java/org/apache/dubbo/metadata/MetadataInfoTest.java
index 1d2f42e..be8c3fe 100644
---
a/dubbo-metadata/dubbo-metadata-api/src/test/java/org/apache/dubbo/metadata/MetadataInfoTest.java
+++
b/dubbo-metadata/dubbo-metadata-api/src/test/java/org/apache/dubbo/metadata/MetadataInfoTest.java
@@ -23,7 +23,7 @@ import org.junit.jupiter.api.Test;
public class MetadataInfoTest {
@Test
public void revisionTest() {
- MetadataInfo metadataInfo = new MetadataInfo();
+ MetadataInfo metadataInfo = new MetadataInfo("demo");
metadataInfo.setApp("demo");
URL url =
URL.valueOf("dubbo://10.230.11.211:20880/org.apache.dubbo.metadata.DemoService?timeout=1000&testKey=aaa");
diff --git
a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/DefaultServiceInstance.java
b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/DefaultServiceInstance.java
index 6c88e8c..3d80c22 100644
---
a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/DefaultServiceInstance.java
+++
b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/DefaultServiceInstance.java
@@ -46,7 +46,7 @@ public class DefaultServiceInstance implements
ServiceInstance {
private Map<String, String> metadata = new HashMap<>();
- private MetadataInfo serviceMetadata;
+ private transient MetadataInfo serviceMetadata;
public DefaultServiceInstance() {
}
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 48ceffd..92db129 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
@@ -23,7 +23,6 @@ import org.apache.dubbo.common.logger.Logger;
import org.apache.dubbo.common.logger.LoggerFactory;
import org.apache.dubbo.common.utils.CollectionUtils;
import org.apache.dubbo.common.utils.StringUtils;
-import org.apache.dubbo.metadata.MetadataService;
import org.apache.dubbo.metadata.ServiceNameMapping;
import org.apache.dubbo.metadata.WritableMetadataService;
import org.apache.dubbo.registry.NotifyListener;
@@ -33,7 +32,6 @@ import
org.apache.dubbo.registry.client.metadata.SubscribedURLsSynthesizer;
import org.apache.dubbo.registry.support.FailbackRegistry;
import java.util.ArrayList;
-import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
@@ -49,9 +47,9 @@ import static java.util.Collections.emptySet;
import static java.util.Collections.unmodifiableSet;
import static java.util.stream.Collectors.toSet;
import static java.util.stream.Stream.of;
-import static org.apache.dubbo.common.constants.CommonConstants.DUBBO_PROTOCOL;
import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.INTERFACE_KEY;
+import static org.apache.dubbo.common.constants.CommonConstants.MAPPING_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.PROTOCOL_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.PROVIDER_SIDE;
import static org.apache.dubbo.common.constants.CommonConstants.SIDE_KEY;
@@ -79,20 +77,6 @@ import static
org.apache.dubbo.registry.client.ServiceDiscoveryFactory.getExtens
* protocol associates with a kind of {@link ServiceDiscovery}'s
implementation if present, or the
* {@link FileSystemServiceDiscovery} will be the default one. Obviously, it's
also allowed to extend
* {@link ServiceDiscovery} using {@link SPI the Dubbo SPI}.
- * <p>
- * In the {@link #subscribe(URL, NotifyListener) subscription phase}, the
{@link ServiceDiscovery} instance will be used
- * to discovery the {@link ServiceInstance service instances} via the {@link
ServiceDiscovery#getInstances(String)}.
- * However, the argument of this method requires the service name that the
subscribed {@link URL} can't find, thus,
- * {@link ServiceNameMapping} will help to figure out one or more services
that exported correlative Dubbo services. If
- * the service names can be found, the exported {@link URL URLs} will be get
from the remote {@link MetadataService}
- * being deployed on all {@link ServiceInstance instances} of services. The
whole process runs under the
- * {@link #subscribeURLs(URL, NotifyListener, String, Collection)} method.
It's very expensive to invoke
- * {@link MetadataService} for each {@link ServiceInstance service instance},
thus {@link ServiceDiscoveryRegistry}
- * introduces a cache to optimize the calculation with "revisions". If the
revisions of N
- * {@link ServiceInstance service instances} are same, {@link MetadataService}
is invoked just only once, and then it
- * does return the exported {@link URL URLs} as a template by which others are
- * {@link #cloneExportedURLs(URL, Collection) cloned}.
- * <p>
* In contrast, current {@link ServiceInstance service instance} will not be
registered to the registry whether any
* Dubbo service is exported or not.
* <p>
@@ -130,7 +114,7 @@ public class ServiceDiscoveryRegistry extends
FailbackRegistry {
super(registryURL);
this.serviceDiscovery = createServiceDiscovery(registryURL);
this.subscribedServices =
parseServices(registryURL.getParameter(SUBSCRIBED_SERVICE_NAMES_KEY));
- this.serviceNameMapping = ServiceNameMapping.getDefaultExtension();
+ this.serviceNameMapping =
ServiceNameMapping.getExtension(registryURL.getParameter(MAPPING_KEY));
this.writableMetadataService =
WritableMetadataService.getDefaultExtension();
}
@@ -303,6 +287,7 @@ public class ServiceDiscoveryRegistry extends
FailbackRegistry {
listener.notifyServiceInstances();
}
});
+ serviceListener.setUrl(url);
listener.addServiceListener(serviceListener);
registerServiceInstancesChangedListener(url, serviceListener);
}
@@ -392,11 +377,7 @@ public class ServiceDiscoveryRegistry extends
FailbackRegistry {
* @return
*/
protected Set<String> findMappedServices(URL subscribedURL) {
- String serviceInterface = subscribedURL.getServiceInterface();
- String group = subscribedURL.getParameter(GROUP_KEY);
- String version = subscribedURL.getParameter(VERSION_KEY);
- String protocol = subscribedURL.getParameter(PROTOCOL_KEY,
DUBBO_PROTOCOL);
- return serviceNameMapping.get(serviceInterface, group, version,
protocol);
+ return serviceNameMapping.get(subscribedURL);
}
/**
diff --git
a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/event/listener/ServiceInstancesChangedListener.java
b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/event/listener/ServiceInstancesChangedListener.java
index 5f40b2a..3bd4042 100644
---
a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/event/listener/ServiceInstancesChangedListener.java
+++
b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/event/listener/ServiceInstancesChangedListener.java
@@ -53,7 +53,7 @@ public abstract class ServiceInstancesChangedListener
implements ConditionalEven
private final String serviceName;
private final ServiceDiscovery serviceDiscovery;
- private final URL url;
+ private URL url;
private List<ServiceInstance> instances;
@@ -165,6 +165,10 @@ public abstract class ServiceInstancesChangedListener
implements ConditionalEven
return serviceName;
}
+ public void setUrl(URL url) {
+ this.url = url;
+ }
+
public URL getUrl() {
return url;
}
diff --git
a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/MetadataUtils.java
b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/MetadataUtils.java
index 9cbe577..2685a4a 100644
---
a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/MetadataUtils.java
+++
b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/MetadataUtils.java
@@ -37,7 +37,6 @@ import static
org.apache.dubbo.registry.client.metadata.ServiceInstanceMetadataU
public class MetadataUtils {
- private static final Object LOCK = new Object();
private static final Object REMOTE_LOCK = new Object();
public static ConcurrentMap<String, MetadataService>
metadataServiceProxies = new ConcurrentHashMap<>();
diff --git
a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/store/InMemoryWritableMetadataService.java
b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/store/InMemoryWritableMetadataService.java
index b9e7877..588c7ae 100644
---
a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/store/InMemoryWritableMetadataService.java
+++
b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/store/InMemoryWritableMetadataService.java
@@ -26,6 +26,7 @@ import org.apache.dubbo.metadata.MetadataService;
import org.apache.dubbo.metadata.WritableMetadataService;
import org.apache.dubbo.metadata.definition.ServiceDefinitionBuilder;
import org.apache.dubbo.metadata.definition.model.ServiceDefinition;
+import org.apache.dubbo.rpc.model.ApplicationModel;
import org.apache.dubbo.rpc.support.ProtocolUtils;
import com.google.gson.Gson;
@@ -85,7 +86,7 @@ public class InMemoryWritableMetadataService implements
WritableMetadataService
ConcurrentNavigableMap<String, String> serviceDefinitions = new
ConcurrentSkipListMap<>();
public InMemoryWritableMetadataService() {
- this.metadataInfo = new MetadataInfo();
+ this.metadataInfo = new MetadataInfo(ApplicationModel.getName());
}
@Override