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 e9175a6 add more configuration items for control of remote metadata
registration. (#9767)
e9175a6 is described below
commit e9175a6c748ca50ef06d1a6108fabad32e402a32
Author: ken.lj <[email protected]>
AuthorDate: Fri Mar 11 15:11:10 2022 +0800
add more configuration items for control of remote metadata registration.
(#9767)
---
.../dubbo/common/constants/CommonConstants.java | 4 ++++
.../apache/dubbo/config/MetadataReportConfig.java | 23 ++++++++++++++++++++++
.../org/apache/dubbo/config/ReferenceConfig.java | 7 -------
.../org/apache/dubbo/config/ServiceConfig.java | 7 -------
.../src/main/resources/META-INF/compat/dubbo.xsd | 12 +++++++++++
.../src/main/resources/META-INF/dubbo.xsd | 12 +++++++++++
.../src/main/resources/spring/dubbo-provider.xml | 2 +-
.../dubbo/metadata/report/MetadataReport.java | 5 +++++
.../report/support/AbstractMetadataReport.java | 18 +++++++++++++++++
.../metadata/report/support/NopMetadataReport.java | 10 ++++++++++
.../support/AbstractMetadataReportFactoryTest.java | 10 ++++++++++
.../registry/client/AbstractServiceDiscovery.java | 10 ++++++++--
.../registry/client/metadata/MetadataUtils.java | 8 ++++++++
13 files changed, 111 insertions(+), 17 deletions(-)
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 40f6401..bdeffe0 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
@@ -217,6 +217,10 @@ public interface CommonConstants {
String METADATA_KEY = "metadata-type";
+ String REPORT_METADATA_KEY = "report-metadata";
+
+ String REPORT_DEFINITION_KEY = "report-definition";
+
String DEFAULT_METADATA_STORAGE_TYPE = "local";
String REMOTE_METADATA_STORAGE_TYPE = "remote";
diff --git
a/dubbo-common/src/main/java/org/apache/dubbo/config/MetadataReportConfig.java
b/dubbo-common/src/main/java/org/apache/dubbo/config/MetadataReportConfig.java
index f82af33..dbb58b6 100644
---
a/dubbo-common/src/main/java/org/apache/dubbo/config/MetadataReportConfig.java
+++
b/dubbo-common/src/main/java/org/apache/dubbo/config/MetadataReportConfig.java
@@ -27,6 +27,8 @@ import java.util.HashMap;
import java.util.Map;
import static
org.apache.dubbo.common.constants.CommonConstants.CYCLE_REPORT_KEY;
+import static
org.apache.dubbo.common.constants.CommonConstants.REPORT_DEFINITION_KEY;
+import static
org.apache.dubbo.common.constants.CommonConstants.REPORT_METADATA_KEY;
import static
org.apache.dubbo.common.constants.CommonConstants.RETRY_PERIOD_KEY;
import static
org.apache.dubbo.common.constants.CommonConstants.RETRY_TIMES_KEY;
import static
org.apache.dubbo.common.constants.CommonConstants.SYNC_REPORT_KEY;
@@ -115,6 +117,9 @@ public class MetadataReportConfig extends AbstractConfig {
*/
private Boolean check;
+ private Boolean reportMetadata;
+
+ private Boolean reportDefinition;
public MetadataReportConfig() {
}
@@ -319,4 +324,22 @@ public class MetadataReportConfig extends AbstractConfig {
public void setCheck(Boolean check) {
this.check = check;
}
+
+ @Parameter(key = REPORT_METADATA_KEY)
+ public Boolean getReportMetadata() {
+ return reportMetadata;
+ }
+
+ public void setReportMetadata(Boolean reportMetadata) {
+ this.reportMetadata = reportMetadata;
+ }
+
+ @Parameter(key = REPORT_DEFINITION_KEY)
+ public Boolean getReportDefinition() {
+ return reportDefinition;
+ }
+
+ public void setReportDefinition(Boolean reportDefinition) {
+ this.reportDefinition = reportDefinition;
+ }
}
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 539e6d6..2a44d0b 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
@@ -66,11 +66,9 @@ 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.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;
@@ -347,11 +345,6 @@ public class ReferenceConfig<T> extends
ReferenceConfigBase<T> {
AbstractConfig.appendParameters(map, this);
appendMetricsCompatible(map);
- MetadataReportConfig metadataReportConfig = getMetadataReportConfig();
- if (metadataReportConfig != null && metadataReportConfig.isValid()) {
- map.putIfAbsent(METADATA_KEY, REMOTE_METADATA_STORAGE_TYPE);
- }
-
String hostToRegistry =
ConfigUtils.getSystemProperty(DUBBO_IP_TO_REGISTRY);
if (StringUtils.isEmpty(hostToRegistry)) {
hostToRegistry = NetUtils.getLocalHost();
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 6f161d3..2e1f02b 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
@@ -62,12 +62,10 @@ 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.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.SERVICE_NAME_MAPPING_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.SIDE_KEY;
@@ -416,11 +414,6 @@ public class ServiceConfig<T> extends ServiceConfigBase<T>
{
AbstractConfig.appendParameters(map, this);
appendMetricsCompatible(map);
- MetadataReportConfig metadataReportConfig = getMetadataReportConfig();
- if (metadataReportConfig != null && metadataReportConfig.isValid()) {
- map.putIfAbsent(METADATA_KEY, REMOTE_METADATA_STORAGE_TYPE);
- }
-
// append params with method configs,
if (CollectionUtils.isNotEmpty(getMethods())) {
getMethods().forEach(method -> appendParametersWithMethod(method,
map));
diff --git
a/dubbo-config/dubbo-config-spring/src/main/resources/META-INF/compat/dubbo.xsd
b/dubbo-config/dubbo-config-spring/src/main/resources/META-INF/compat/dubbo.xsd
index 6b0b20b..b22bd91 100644
---
a/dubbo-config/dubbo-config-spring/src/main/resources/META-INF/compat/dubbo.xsd
+++
b/dubbo-config/dubbo-config-spring/src/main/resources/META-INF/compat/dubbo.xsd
@@ -724,6 +724,18 @@
<xsd:documentation><![CDATA[ registry config id.
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
+ <xsd:attribute name="report-metadata" type="xsd:boolean"
use="optional">
+ <xsd:annotation>
+ <xsd:documentation>
+ <![CDATA[ Whether to report metadata to remote center,
default is false. ]]></xsd:documentation>
+ </xsd:annotation>
+ </xsd:attribute>
+ <xsd:attribute name="report-definition" type="xsd:boolean"
use="optional">
+ <xsd:annotation>
+ <xsd:documentation>
+ <![CDATA[ Whether to report service definition to remote
center, default is true. ]]></xsd:documentation>
+ </xsd:annotation>
+ </xsd:attribute>
</xsd:complexType>
<xsd:complexType name="configCenterType">
diff --git
a/dubbo-config/dubbo-config-spring/src/main/resources/META-INF/dubbo.xsd
b/dubbo-config/dubbo-config-spring/src/main/resources/META-INF/dubbo.xsd
index c6f8205..9a9a6a7 100644
--- a/dubbo-config/dubbo-config-spring/src/main/resources/META-INF/dubbo.xsd
+++ b/dubbo-config/dubbo-config-spring/src/main/resources/META-INF/dubbo.xsd
@@ -780,6 +780,18 @@
<![CDATA[ The policy to apply when connecting to metadata
center fails. ]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
+ <xsd:attribute name="report-metadata" type="xsd:boolean"
use="optional">
+ <xsd:annotation>
+ <xsd:documentation>
+ <![CDATA[ Whether to report metadata to remote center,
default is false. ]]></xsd:documentation>
+ </xsd:annotation>
+ </xsd:attribute>
+ <xsd:attribute name="report-definition" type="xsd:boolean"
use="optional">
+ <xsd:annotation>
+ <xsd:documentation>
+ <![CDATA[ Whether to report service definition to remote
center, default is true. ]]></xsd:documentation>
+ </xsd:annotation>
+ </xsd:attribute>
</xsd:complexType>
<xsd:complexType name="configCenterType">
diff --git
a/dubbo-demo/dubbo-demo-xml/dubbo-demo-xml-provider/src/main/resources/spring/dubbo-provider.xml
b/dubbo-demo/dubbo-demo-xml/dubbo-demo-xml-provider/src/main/resources/spring/dubbo-provider.xml
index 60f1d93..ad402bc 100644
---
a/dubbo-demo/dubbo-demo-xml/dubbo-demo-xml-provider/src/main/resources/spring/dubbo-provider.xml
+++
b/dubbo-demo/dubbo-demo-xml/dubbo-demo-xml-provider/src/main/resources/spring/dubbo-provider.xml
@@ -21,7 +21,7 @@
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
http://dubbo.apache.org/schema/dubbo
http://dubbo.apache.org/schema/dubbo/dubbo.xsd">
- <dubbo:application name="demo-provider" metadata-type="remote">
+ <dubbo:application name="demo-provider" >
</dubbo:application>
<dubbo:config-center address="zookeeper://127.0.0.1:2181"/>
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 9cb009b..b871dc7 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
@@ -95,4 +95,9 @@ public interface MetadataReport {
default Set<String> getServiceAppMapping(String serviceKey, URL url) {
return Collections.emptySet();
}
+
+ boolean shouldReportDefinition();
+
+ boolean shouldReportMetadata();
+
}
diff --git
a/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/report/support/AbstractMetadataReport.java
b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/report/support/AbstractMetadataReport.java
index 71901c5..aa9f4c7 100644
---
a/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/report/support/AbstractMetadataReport.java
+++
b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/report/support/AbstractMetadataReport.java
@@ -65,6 +65,8 @@ import static
org.apache.dubbo.common.constants.CommonConstants.CONSUMER_SIDE;
import static
org.apache.dubbo.common.constants.CommonConstants.CYCLE_REPORT_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.FILE_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.PROVIDER_SIDE;
+import static
org.apache.dubbo.common.constants.CommonConstants.REPORT_DEFINITION_KEY;
+import static
org.apache.dubbo.common.constants.CommonConstants.REPORT_METADATA_KEY;
import static
org.apache.dubbo.common.constants.CommonConstants.RETRY_PERIOD_KEY;
import static
org.apache.dubbo.common.constants.CommonConstants.RETRY_TIMES_KEY;
import static
org.apache.dubbo.common.constants.CommonConstants.SYNC_REPORT_KEY;
@@ -100,6 +102,9 @@ public abstract class AbstractMetadataReport implements
MetadataReport {
public MetadataReportRetry metadataReportRetry;
private ScheduledExecutorService reportTimerScheduler;
+ private final boolean reportMetadata;
+ private final boolean reportDefinition;
+
public AbstractMetadataReport(URL reportServerURL) {
setUrl(reportServerURL);
// Start file save timer
@@ -130,6 +135,9 @@ public abstract class AbstractMetadataReport implements
MetadataReport {
reportTimerScheduler =
Executors.newSingleThreadScheduledExecutor(new
NamedThreadFactory("DubboMetadataReportTimer", true));
reportTimerScheduler.scheduleAtFixedRate(this::publishAll,
calculateStartTime(), ONE_DAY_IN_MILLISECONDS, TimeUnit.MILLISECONDS);
}
+
+ this.reportMetadata =
reportServerURL.getParameter(REPORT_METADATA_KEY, false);
+ this.reportDefinition =
reportServerURL.getParameter(REPORT_DEFINITION_KEY, true);
}
public URL getUrl() {
@@ -364,6 +372,16 @@ public abstract class AbstractMetadataReport implements
MetadataReport {
return doHandleMetadataCollection(failedReports);
}
+ @Override
+ public boolean shouldReportDefinition() {
+ return reportDefinition;
+ }
+
+ @Override
+ public boolean shouldReportMetadata() {
+ return reportMetadata;
+ }
+
private boolean doHandleMetadataCollection(Map<MetadataIdentifier, Object>
metadataMap) {
if (metadataMap.isEmpty()) {
return true;
diff --git
a/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/report/support/NopMetadataReport.java
b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/report/support/NopMetadataReport.java
index f63be93..e42ae27 100644
---
a/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/report/support/NopMetadataReport.java
+++
b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/report/support/NopMetadataReport.java
@@ -75,4 +75,14 @@ public class NopMetadataReport implements MetadataReport {
public List<String> getSubscribedURLs(SubscriberMetadataIdentifier
subscriberMetadataIdentifier) {
return null;
}
+
+ @Override
+ public boolean shouldReportDefinition() {
+ return true;
+ }
+
+ @Override
+ public boolean shouldReportMetadata() {
+ return false;
+ }
}
diff --git
a/dubbo-metadata/dubbo-metadata-api/src/test/java/org/apache/dubbo/metadata/report/support/AbstractMetadataReportFactoryTest.java
b/dubbo-metadata/dubbo-metadata-api/src/test/java/org/apache/dubbo/metadata/report/support/AbstractMetadataReportFactoryTest.java
index eb68abf..5ec5f2b 100644
---
a/dubbo-metadata/dubbo-metadata-api/src/test/java/org/apache/dubbo/metadata/report/support/AbstractMetadataReportFactoryTest.java
+++
b/dubbo-metadata/dubbo-metadata-api/src/test/java/org/apache/dubbo/metadata/report/support/AbstractMetadataReportFactoryTest.java
@@ -85,6 +85,16 @@ public class AbstractMetadataReportFactoryTest {
}
@Override
+ public boolean shouldReportDefinition() {
+ return true;
+ }
+
+ @Override
+ public boolean shouldReportMetadata() {
+ return false;
+ }
+
+ @Override
public String getServiceDefinition(MetadataIdentifier
consumerMetadataIdentifier) {
return null;
}
diff --git
a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/AbstractServiceDiscovery.java
b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/AbstractServiceDiscovery.java
index 6221b2d..5ce2e64 100644
---
a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/AbstractServiceDiscovery.java
+++
b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/AbstractServiceDiscovery.java
@@ -35,6 +35,8 @@ import org.apache.dubbo.rpc.model.ApplicationModel;
import java.util.List;
import java.util.Set;
+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.common.constants.RegistryConstants.REGISTRY_CLUSTER_KEY;
import static org.apache.dubbo.metadata.RevisionResolver.EMPTY_REVISION;
import static
org.apache.dubbo.registry.client.metadata.ServiceInstanceMetadataUtils.EXPORTED_SERVICES_REVISION_PROPERTY_NAME;
@@ -271,14 +273,18 @@ public abstract class AbstractServiceDiscovery implements
ServiceDiscovery {
protected void reportMetadata(MetadataInfo metadataInfo) {
if (metadataReport != null) {
SubscriberMetadataIdentifier identifier = new
SubscriberMetadataIdentifier(serviceName, metadataInfo.getRevision());
- metadataReport.publishAppMetadata(identifier, metadataInfo);
+ if ((DEFAULT_METADATA_STORAGE_TYPE.equals(metadataType) &&
metadataReport.shouldReportMetadata()) ||
REMOTE_METADATA_STORAGE_TYPE.equals(metadataType)) {
+ metadataReport.publishAppMetadata(identifier, metadataInfo);
+ }
}
}
protected void unReportMetadata(MetadataInfo metadataInfo) {
if (metadataReport != null) {
SubscriberMetadataIdentifier identifier = new
SubscriberMetadataIdentifier(serviceName, metadataInfo.getRevision());
- metadataReport.unPublishAppMetadata(identifier, metadataInfo);
+ if ((DEFAULT_METADATA_STORAGE_TYPE.equals(metadataType) &&
metadataReport.shouldReportMetadata()) ||
REMOTE_METADATA_STORAGE_TYPE.equals(metadataType)) {
+ metadataReport.unPublishAppMetadata(identifier, metadataInfo);
+ }
}
}
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 dc144d2..faee636 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
@@ -68,6 +68,10 @@ public class MetadataUtils {
serviceDefinition.setParameters(url.getParameters());
for (Map.Entry<String, MetadataReport> entry :
getMetadataReports(applicationModel).entrySet()) {
MetadataReport metadataReport = entry.getValue();
+ if (!metadataReport.shouldReportDefinition()) {
+ logger.info("Report of service definition is
disabled for " + entry.getKey());
+ continue;
+ }
metadataReport.storeProviderMetadata(
new MetadataIdentifier(
url.getServiceInterface(),
@@ -81,6 +85,10 @@ public class MetadataUtils {
} else {
for (Map.Entry<String, MetadataReport> entry :
getMetadataReports(applicationModel).entrySet()) {
MetadataReport metadataReport = entry.getValue();
+ if (!metadataReport.shouldReportDefinition()) {
+ logger.info("Report of service definition is disabled
for " + entry.getKey());
+ continue;
+ }
metadataReport.storeConsumerMetadata(
new MetadataIdentifier(
url.getServiceInterface(),