You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by li...@apache.org on 2019/09/11 06:39:32 UTC
[dubbo] branch master updated: Fix generic impl does not support
metadata report. (#4660)
This is an automated email from the ASF dual-hosted git repository.
liujun pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/dubbo.git
The following commit(s) were added to refs/heads/master by this push:
new 7d564e7 Fix generic impl does not support metadata report. (#4660)
7d564e7 is described below
commit 7d564e75fe776681e9e3c0a6f6bd1c4ad1ea51af
Author: cvictory <sh...@gmail.com>
AuthorDate: Wed Sep 11 14:39:22 2019 +0800
Fix generic impl does not support metadata report. (#4660)
Fixes #4641
---
.../org/apache/dubbo/common/utils/UrlUtils.java | 1 -
.../integration/MetadataReportService.java | 15 ++++++++++++++
.../integration/MetadataReportServiceTest.java | 24 ++++++++++++++++++++++
3 files changed, 39 insertions(+), 1 deletion(-)
diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/utils/UrlUtils.java b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/UrlUtils.java
index 73c03f0..56e73cb 100644
--- a/dubbo-common/src/main/java/org/apache/dubbo/common/utils/UrlUtils.java
+++ b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/UrlUtils.java
@@ -484,7 +484,6 @@ public class UrlUtils {
PROVIDERS_CATEGORY.equals(url.getParameter(CATEGORY_KEY, PROVIDERS_CATEGORY));
}
-
/**
* Check if the given value matches the given pattern. The pattern supports wildcard "*".
*
diff --git a/dubbo-metadata-report/dubbo-metadata-report-api/src/main/java/org/apache/dubbo/metadata/integration/MetadataReportService.java b/dubbo-metadata-report/dubbo-metadata-report-api/src/main/java/org/apache/dubbo/metadata/integration/MetadataReportService.java
index 5ceb5c5..f42bfd9 100644
--- a/dubbo-metadata-report/dubbo-metadata-report-api/src/main/java/org/apache/dubbo/metadata/integration/MetadataReportService.java
+++ b/dubbo-metadata-report/dubbo-metadata-report-api/src/main/java/org/apache/dubbo/metadata/integration/MetadataReportService.java
@@ -29,6 +29,7 @@ import org.apache.dubbo.metadata.store.MetadataReport;
import org.apache.dubbo.metadata.store.MetadataReportFactory;
import org.apache.dubbo.remoting.Constants;
import org.apache.dubbo.rpc.RpcException;
+import org.apache.dubbo.rpc.support.ProtocolUtils;
import java.util.function.Supplier;
@@ -87,6 +88,9 @@ public class MetadataReportService {
}
public void publishProvider(URL providerUrl) throws RpcException {
+ if (!needStore(providerUrl)) {
+ return;
+ }
//first add into the list
// remove the individul param
providerUrl = providerUrl.removeParameters(PID_KEY, TIMESTAMP_KEY, Constants.BIND_IP_KEY, Constants.BIND_PORT_KEY, TIMESTAMP_KEY);
@@ -110,10 +114,21 @@ public class MetadataReportService {
}
public void publishConsumer(URL consumerURL) throws RpcException {
+ if (!needStore(consumerURL)) {
+ return;
+ }
consumerURL = consumerURL.removeParameters(PID_KEY, TIMESTAMP_KEY, Constants.BIND_IP_KEY, Constants.BIND_PORT_KEY, TIMESTAMP_KEY);
metadataReport.storeConsumerMetadata(new MetadataIdentifier(consumerURL.getServiceInterface(),
consumerURL.getParameter(VERSION_KEY), consumerURL.getParameter(GROUP_KEY), CONSUMER_SIDE,
consumerURL.getParameter(APPLICATION_KEY)), consumerURL.getParameters());
}
+ private boolean needStore(URL url) {
+ if (!ProtocolUtils.isGeneric(url.getParameter(org.apache.dubbo.rpc.Constants.GENERIC_KEY))) {
+ logger.debug("The metadata is ignored for this service is generic. The service is: " + url.getParameter(INTERFACE_KEY, ""));
+ return true;
+ }
+ return false;
+ }
+
}
diff --git a/dubbo-metadata-report/dubbo-metadata-report-api/src/test/java/org/apache/dubbo/metadata/integration/MetadataReportServiceTest.java b/dubbo-metadata-report/dubbo-metadata-report-api/src/test/java/org/apache/dubbo/metadata/integration/MetadataReportServiceTest.java
index d6ec491..032c073 100644
--- a/dubbo-metadata-report/dubbo-metadata-report-api/src/test/java/org/apache/dubbo/metadata/integration/MetadataReportServiceTest.java
+++ b/dubbo-metadata-report/dubbo-metadata-report-api/src/test/java/org/apache/dubbo/metadata/integration/MetadataReportServiceTest.java
@@ -121,6 +121,30 @@ public class MetadataReportServiceTest {
}
+ @Test
+ public void testIgnorePublishProvider() throws InterruptedException {
+ URL publishUrl = URL.valueOf("dubbo://" + NetUtils.getLocalAddress().getHostName() + ":4444/org.apache.dubbo.TestService?version=1.0.3&application=vicpubp&generic=true&interface=org.apache.dubbo.metadata.integration.XXXX&side=provider");
+ metadataReportService1.publishProvider(publishUrl);
+ Thread.sleep(300);
+
+ JTestMetadataReport4Test jTestMetadataReport4Test = (JTestMetadataReport4Test) metadataReportService1.metadataReport;
+
+ String value = jTestMetadataReport4Test.store.get(JTestMetadataReport4Test.getProviderKey(publishUrl));
+ Assertions.assertNull(value);
+ }
+
+ @Test
+ public void testIgnorePublishConsumer() throws InterruptedException {
+ URL publishUrl = URL.valueOf("dubbo://" + NetUtils.getLocalAddress().getHostName() + ":4444/org.apache.dubbo.XXXService?version=1.0.x&application=vicpubconsumer&generic=true&side=consumer");
+ metadataReportService1.publishConsumer(publishUrl);
+ Thread.sleep(300);
+
+ JTestMetadataReport4Test jTestMetadataReport4Test = (JTestMetadataReport4Test) metadataReportService1.metadataReport;
+
+ String value = jTestMetadataReport4Test.store.get(JTestMetadataReport4Test.getConsumerKey(publishUrl));
+ Assertions.assertNull(value);
+ }
+
private FullServiceDefinition toServiceDefinition(String urlQuery) {
Gson gson = new Gson();
return gson.fromJson(urlQuery, FullServiceDefinition.class);