From c160f1e9a8afc455f95e6f1b8d1724a171721cae Mon Sep 17 00:00:00 2001 From: cvictory Date: Fri, 4 Jan 2019 14:11:58 +0800 Subject: [PATCH] fix #3123. support metadata xml configuration; support configuration format dubbo.metadata-report.address=xxx --- .../org/apache/dubbo/common/Constants.java | 2 ++ .../dubbo/config/MetadataReportConfig.java | 31 +++++++++++++++---- .../annotation/DubboConfigConfiguration.java | 3 +- .../spring/schema/DubboNamespaceHandler.java | 2 ++ .../main/resources/META-INF/compat/dubbo.xsd | 22 ++++++++++++- .../src/main/resources/META-INF/dubbo.xsd | 23 +++++++++++++- 6 files changed, 74 insertions(+), 9 deletions(-) diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/Constants.java b/dubbo-common/src/main/java/org/apache/dubbo/common/Constants.java index fa957b0c29b..0ecc5fea807 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/Constants.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/Constants.java @@ -176,6 +176,8 @@ public class Constants { public static final String REMOVE_VALUE_PREFIX = "-"; + public static final String PROPERTIES_CHAR_SEPERATOR = "-"; + public static final String HIDE_KEY_PREFIX = "."; public static final String DEFAULT_KEY_PREFIX = "default."; diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/MetadataReportConfig.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/MetadataReportConfig.java index a134eef9085..95c879555cb 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/MetadataReportConfig.java +++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/MetadataReportConfig.java @@ -16,11 +16,14 @@ */ package org.apache.dubbo.config; +import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.utils.StringUtils; import org.apache.dubbo.config.support.Parameter; import java.util.Map; +import static org.apache.dubbo.common.Constants.PROPERTIES_CHAR_SEPERATOR; + /** * RegistryConfig * @@ -29,6 +32,12 @@ public class MetadataReportConfig extends AbstractConfig { private static final long serialVersionUID = 55233L; + /** + * the value is : metadata-report + */ + private static final String PREFIX_TAG = StringUtils.camelToSplitName( + MetadataReportConfig.class.getSimpleName().substring(0, MetadataReportConfig.class.getSimpleName().length() - 6), PROPERTIES_CHAR_SEPERATOR); + // Register center address private String address; @@ -104,6 +113,7 @@ public void setParameters(Map parameters) { this.parameters = parameters; } + @Parameter(key = "retry-times") public Integer getRetryTimes() { return retryTimes; } @@ -112,6 +122,7 @@ public void setRetryTimes(Integer retryTimes) { this.retryTimes = retryTimes; } + @Parameter(key = "retry-period") public Integer getRetryPeriod() { return retryPeriod; } @@ -120,6 +131,7 @@ public void setRetryPeriod(Integer retryPeriod) { this.retryPeriod = retryPeriod; } + @Parameter(key = "cycle-report") public Boolean getCycleReport() { return cycleReport; } @@ -128,12 +140,7 @@ public void setCycleReport(Boolean cycleReport) { this.cycleReport = cycleReport; } - @Override - @Parameter(excluded = true) - public boolean isValid() { - return StringUtils.isNotEmpty(address); - } - + @Parameter(key = "sync-report") public Boolean getSyncReport() { return syncReport; } @@ -141,4 +148,16 @@ public Boolean getSyncReport() { public void setSyncReport(Boolean syncReport) { this.syncReport = syncReport; } + + + @Parameter(excluded = true) + public String getPrefix() { + return StringUtils.isNotEmpty(prefix) ? prefix : (Constants.DUBBO + "." + PREFIX_TAG); + } + + @Override + @Parameter(excluded = true) + public boolean isValid() { + return StringUtils.isNotEmpty(address); + } } diff --git a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/context/annotation/DubboConfigConfiguration.java b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/context/annotation/DubboConfigConfiguration.java index 64330702356..de60b5d2cfa 100644 --- a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/context/annotation/DubboConfigConfiguration.java +++ b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/context/annotation/DubboConfigConfiguration.java @@ -75,7 +75,8 @@ public static class Single { @EnableDubboConfigBinding(prefix = "dubbo.monitors", type = MonitorConfig.class, multiple = true), @EnableDubboConfigBinding(prefix = "dubbo.providers", type = ProviderConfig.class, multiple = true), @EnableDubboConfigBinding(prefix = "dubbo.consumers", type = ConsumerConfig.class, multiple = true), - @EnableDubboConfigBinding(prefix = "dubbo.config-centers", type = ConfigCenterBean.class, multiple = true) + @EnableDubboConfigBinding(prefix = "dubbo.config-centers", type = ConfigCenterBean.class, multiple = true), + @EnableDubboConfigBinding(prefix = "dubbo.metadata-reports", type = MetadataReportConfig.class, multiple = true) }) public static class Multiple { diff --git a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/schema/DubboNamespaceHandler.java b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/schema/DubboNamespaceHandler.java index d4ea6ed33c8..4d7b0af461e 100644 --- a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/schema/DubboNamespaceHandler.java +++ b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/schema/DubboNamespaceHandler.java @@ -19,6 +19,7 @@ import org.apache.dubbo.common.Version; import org.apache.dubbo.config.ApplicationConfig; import org.apache.dubbo.config.ConsumerConfig; +import org.apache.dubbo.config.MetadataReportConfig; import org.apache.dubbo.config.ModuleConfig; import org.apache.dubbo.config.MonitorConfig; import org.apache.dubbo.config.ProtocolConfig; @@ -47,6 +48,7 @@ public void init() { registerBeanDefinitionParser("module", new DubboBeanDefinitionParser(ModuleConfig.class, true)); registerBeanDefinitionParser("registry", new DubboBeanDefinitionParser(RegistryConfig.class, true)); registerBeanDefinitionParser("config-center", new DubboBeanDefinitionParser(ConfigCenterBean.class, true)); + registerBeanDefinitionParser("metadata-report", new DubboBeanDefinitionParser(MetadataReportConfig.class, true)); registerBeanDefinitionParser("monitor", new DubboBeanDefinitionParser(MonitorConfig.class, true)); registerBeanDefinitionParser("provider", new DubboBeanDefinitionParser(ProviderConfig.class, true)); registerBeanDefinitionParser("consumer", new DubboBeanDefinitionParser(ConsumerConfig.class, true)); 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 3d3c37132a0..98e8f66d8fa 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 @@ -606,6 +606,26 @@ + + + + + + + + + + + + + + + + + + + + @@ -1342,7 +1362,7 @@ - + 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 d0db0be8885..05ff2d59a3d 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 @@ -600,6 +600,27 @@ + + + + + + + + + + + + + + + + + + + + + @@ -1336,7 +1357,7 @@ - +