You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by hu...@apache.org on 2019/05/30 04:44:28 UTC
[dubbo] branch dubbo-4200 updated (02171c3 -> 23eb7fb)
This is an automated email from the ASF dual-hosted git repository.
huxing pushed a change to branch dubbo-4200
in repository https://gitbox.apache.org/repos/asf/dubbo.git.
discard 02171c3 [Dubbo-4200] Nacos group should be not resolved from key.
omit 4b97a0b fix for #4175: ServiceConfigurationListener should override ProviderConfigurationListener (#4179)
omit 21cfe11 Create security.md (#4165)
omit 61ab320 Delete dead code (#4189)
omit 28bea9c [DUBBO-3137]: get rid of ConfigConstants, RpcConstatns, RemotingConstants (#4138)
add ae1e3bd sync pull request 4138 (#4181)
add 321afae Remove licence from dependency (#4186)
add bfc6202 performance tuning: avoid reflection on the critical path (#4190)
add d2ba946 2.7.2 release note (#4187)
new 23eb7fb [Dubbo-4200] Nacos group should be not resolved from key.
This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version. This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:
* -- * -- B -- O -- O -- O (02171c3)
\
N -- N -- N refs/heads/dubbo-4200 (23eb7fb)
You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.
Any revisions marked "omit" are not gone; other references still
refer to them. Any revisions marked "discard" are gone forever.
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
CHANGES.md | 89 ++++++++++++++++++++++
SECURITY.md | 31 --------
.../apache/dubbo/common/config/Configuration.java | 4 +
.../com/alibaba/dubbo/rpc/support/RpcUtils.java | 5 --
dubbo-dependencies-bom/pom.xml | 6 ++
.../registry/integration/RegistryProtocol.java | 2 +-
.../main/java/org/apache/dubbo/rpc/Constants.java | 4 -
.../java/org/apache/dubbo/rpc/RpcInvocation.java | 2 +-
.../dubbo/rpc/proxy/AbstractProxyInvoker.java | 6 +-
.../org/apache/dubbo/rpc/support/RpcUtils.java | 18 ++---
.../dubbo/rpc/protocol/dubbo/DubboCodec.java | 5 +-
11 files changed, 110 insertions(+), 62 deletions(-)
delete mode 100644 SECURITY.md
[dubbo] 01/01: [Dubbo-4200] Nacos group should be not resolved from
key.
Posted by hu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
huxing pushed a commit to branch dubbo-4200
in repository https://gitbox.apache.org/repos/asf/dubbo.git
commit 23eb7fb50516c62efb6e736cfed55927a22de5f2
Author: Huxing Zhang <hu...@gmail.com>
AuthorDate: Thu May 30 12:44:03 2019 +0800
[Dubbo-4200] Nacos group should be not resolved from key.
---
.../support/nacos/NacosDynamicConfiguration.java | 48 ++++++++--------------
.../nacos/NacosDynamicConfigurationTest.java | 10 +++--
.../metadata/store/nacos/NacosMetadataReport.java | 12 +++++-
.../store/nacos/NacosMetadataReportTest.java | 8 ++--
4 files changed, 40 insertions(+), 38 deletions(-)
diff --git a/dubbo-configcenter/dubbo-configcenter-nacos/src/main/java/org/apache/dubbo/configcenter/support/nacos/NacosDynamicConfiguration.java b/dubbo-configcenter/dubbo-configcenter-nacos/src/main/java/org/apache/dubbo/configcenter/support/nacos/NacosDynamicConfiguration.java
index 96bec25..9fdb8eb 100644
--- a/dubbo-configcenter/dubbo-configcenter-nacos/src/main/java/org/apache/dubbo/configcenter/support/nacos/NacosDynamicConfiguration.java
+++ b/dubbo-configcenter/dubbo-configcenter-nacos/src/main/java/org/apache/dubbo/configcenter/support/nacos/NacosDynamicConfiguration.java
@@ -57,6 +57,10 @@ import static org.apache.dubbo.common.constants.RemotingConstants.BACKUP_KEY;
public class NacosDynamicConfiguration implements DynamicConfiguration {
private final Logger logger = LoggerFactory.getLogger(getClass());
+ /**
+ * the default timeout in millis to get config from nacos
+ */
+ private static final long DEFAULT_TIMEOUT = 5000L;
/**
* The final root path would be: /$NAME_SPACE/config
@@ -93,24 +97,14 @@ public class NacosDynamicConfiguration implements DynamicConfiguration {
return configService;
}
- public void publishNacosConfig(String key, String value) {
+ public void publishNacosConfig(String key, String group, String value) {
try {
- String[] keyAndGroup = getKeyAndGroup(key);
- configService.publishConfig(keyAndGroup[0], keyAndGroup[1], value);
+ configService.publishConfig(key, group, value);
} catch (NacosException e) {
logger.error(e.getErrMsg());
}
}
- private String[] getKeyAndGroup(String key) {
- int i = key.lastIndexOf(GROUP_CHAR_SEPERATOR);
- if (i < 0) {
- return new String[]{key, null};
- } else {
- return new String[]{key.substring(0, i), key.substring(i+1)};
- }
- }
-
private Properties buildNacosProperties(URL url) {
Properties properties = new Properties();
setServerAddr(url, properties);
@@ -164,32 +158,19 @@ public class NacosDynamicConfiguration implements DynamicConfiguration {
@Override
public void addListener(String key, String group, ConfigurationListener listener) {
- String[] keyAndGroup = getKeyAndGroup(key);
- if (keyAndGroup[1] != null) {
- group = keyAndGroup[1];
- }
- String finalGroup = group;
- NacosConfigListener nacosConfigListener = watchListenerMap.computeIfAbsent(generateKey(key, group), k -> createTargetListener(key, finalGroup));
String keyInNacos = rootPath + PROPERTIES_CHAR_SEPERATOR + key;
+ NacosConfigListener nacosConfigListener = watchListenerMap.computeIfAbsent(key, k -> createTargetListener(keyInNacos, group));
nacosConfigListener.addListener(listener);
try {
configService.addListener(keyInNacos, group, nacosConfigListener);
- System.out.println("1");
} catch (NacosException e) {
logger.error(e.getMessage());
}
}
- private String generateKey(String key, String group) {
- if (StringUtils.isNotEmpty(group)) {
- key = key + GROUP_CHAR_SEPERATOR + group;
- }
- return key;
- }
-
@Override
public void removeListener(String key, String group, ConfigurationListener listener) {
- NacosConfigListener eventListener = watchListenerMap.get(generateKey(key, group));
+ NacosConfigListener eventListener = watchListenerMap.get(key);
if (eventListener != null) {
eventListener.removeListener(listener);
}
@@ -197,8 +178,14 @@ public class NacosDynamicConfiguration implements DynamicConfiguration {
@Override
public String getConfig(String key, String group, long timeout) throws IllegalStateException {
- key = generateKey(key, group);
- return (String) getInternalProperty(rootPath + PROPERTIES_CHAR_SEPERATOR + key);
+ try {
+ String keyInNacos = rootPath + PROPERTIES_CHAR_SEPERATOR + key;
+ long nacosTimeout = timeout < 0 ? DEFAULT_TIMEOUT : timeout;
+ return configService.getConfig(keyInNacos, group, nacosTimeout);
+ } catch (NacosException e) {
+ logger.error(e.getMessage());
+ }
+ return null;
}
@Override
@@ -209,8 +196,7 @@ public class NacosDynamicConfiguration implements DynamicConfiguration {
@Override
public Object getInternalProperty(String key) {
try {
- String[] keyAndGroup = getKeyAndGroup(key);
- return configService.getConfig(keyAndGroup[0], keyAndGroup[1], 5000L);
+ return configService.getConfig(key, null, 5000L);
} catch (NacosException e) {
logger.error(e.getMessage());
}
diff --git a/dubbo-configcenter/dubbo-configcenter-nacos/src/test/java/org/apache/dubbo/configcenter/support/nacos/NacosDynamicConfigurationTest.java b/dubbo-configcenter/dubbo-configcenter-nacos/src/test/java/org/apache/dubbo/configcenter/support/nacos/NacosDynamicConfigurationTest.java
index ff785b9..df65c63 100644
--- a/dubbo-configcenter/dubbo-configcenter-nacos/src/test/java/org/apache/dubbo/configcenter/support/nacos/NacosDynamicConfigurationTest.java
+++ b/dubbo-configcenter/dubbo-configcenter-nacos/src/test/java/org/apache/dubbo/configcenter/support/nacos/NacosDynamicConfigurationTest.java
@@ -47,7 +47,7 @@ public class NacosDynamicConfigurationTest {
put("dubbo-config-org.apache.dubbo.nacos.testService.configurators", "hello");
Thread.sleep(200);
- put("dubbo-config-dubbo.properties:test", "aaa=bbb");
+ put("dubbo-config-dubbo.properties", "test", "aaa=bbb");
Thread.sleep(200);
Assertions.assertEquals("hello", config.getConfig("org.apache.dubbo.nacos.testService.configurators"));
Assertions.assertEquals("aaa=bbb", config.getConfig("dubbo.properties", "test"));
@@ -89,8 +89,12 @@ public class NacosDynamicConfigurationTest {
}
private void put(String key, String value) {
+ put(key, "", value);
+ }
+
+ private void put(String key, String group, String value) {
try {
- config.publishNacosConfig(key, value);
+ config.publishNacosConfig(key, "dubbo", value);
} catch (Exception e) {
System.out.println("Error put value to nacos.");
}
@@ -121,7 +125,7 @@ public class NacosDynamicConfigurationTest {
@Override
public void process(ConfigChangeEvent event) {
System.out.println(this + ": " + event);
- Integer count = countMap.computeIfAbsent(event.getKey(), k -> new Integer(0));
+ Integer count = countMap.computeIfAbsent(event.getKey(), k -> 0);
countMap.put(event.getKey(), ++count);
value = event.getValue();
latch.countDown();
diff --git a/dubbo-metadata-report/dubbo-metadata-report-nacos/src/main/java/org/apache/dubbo/metadata/store/nacos/NacosMetadataReport.java b/dubbo-metadata-report/dubbo-metadata-report-nacos/src/main/java/org/apache/dubbo/metadata/store/nacos/NacosMetadataReport.java
index 03bdeb8..b12e4f0 100644
--- a/dubbo-metadata-report/dubbo-metadata-report-nacos/src/main/java/org/apache/dubbo/metadata/store/nacos/NacosMetadataReport.java
+++ b/dubbo-metadata-report/dubbo-metadata-report-nacos/src/main/java/org/apache/dubbo/metadata/store/nacos/NacosMetadataReport.java
@@ -37,18 +37,28 @@ import static com.alibaba.nacos.api.PropertyKeyConst.ENDPOINT;
import static com.alibaba.nacos.api.PropertyKeyConst.NAMESPACE;
import static com.alibaba.nacos.api.PropertyKeyConst.CLUSTER_NAME;
import static com.alibaba.nacos.client.naming.utils.UtilAndComs.NACOS_NAMING_LOG_NAME;
+import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY;
import static org.apache.dubbo.common.constants.RemotingConstants.BACKUP_KEY;
/**
* metadata report impl for nacos
*/
public class NacosMetadataReport extends AbstractMetadataReport {
+
private static final Logger logger = LoggerFactory.getLogger(NacosMetadataReport.class);
+
private ConfigService configService;
+ /**
+ * The group used to store metadata in Nacos
+ */
+ private String group;
+
+
public NacosMetadataReport(URL url) {
super(url);
this.configService = buildConfigService(url);
+ group = url.getParameter(GROUP_KEY, DEFAULT_ROOT);
}
public ConfigService buildConfigService(URL url) {
@@ -113,7 +123,7 @@ public class NacosMetadataReport extends AbstractMetadataReport {
private void storeMetadata(MetadataIdentifier identifier, String value) {
try {
- boolean publishResult = configService.publishConfig(identifier.getUniqueKey(MetadataIdentifier.KeyTypeEnum.UNIQUE_KEY), identifier.getGroup(), value);
+ boolean publishResult = configService.publishConfig(identifier.getUniqueKey(MetadataIdentifier.KeyTypeEnum.UNIQUE_KEY), group, value);
if (!publishResult) {
throw new RuntimeException("publish nacos metadata failed");
}
diff --git a/dubbo-metadata-report/dubbo-metadata-report-nacos/src/test/java/org/apache/dubbo/metadata/store/nacos/NacosMetadataReportTest.java b/dubbo-metadata-report/dubbo-metadata-report-nacos/src/test/java/org/apache/dubbo/metadata/store/nacos/NacosMetadataReportTest.java
index 07d6f8b..2f6b9e5 100644
--- a/dubbo-metadata-report/dubbo-metadata-report-nacos/src/test/java/org/apache/dubbo/metadata/store/nacos/NacosMetadataReportTest.java
+++ b/dubbo-metadata-report/dubbo-metadata-report-nacos/src/test/java/org/apache/dubbo/metadata/store/nacos/NacosMetadataReportTest.java
@@ -45,10 +45,12 @@ public class NacosMetadataReportTest {
private NacosMetadataReportFactory nacosMetadataReportFactory;
private ConfigService configService;
+ private static final String group = "zzz";
+
@BeforeEach
public void setUp() {
// timeout in 15 seconds.
- URL url = URL.valueOf("nacos://127.0.0.1:8848")
+ URL url = URL.valueOf("nacos://127.0.0.1:8848?group=" + group)
.addParameter(SESSION_TIMEOUT_KEY, 15000);
nacosMetadataReportFactory = new NacosMetadataReportFactory();
this.nacosMetadataReport = (NacosMetadataReport) nacosMetadataReportFactory.createMetadataReport(url);
@@ -66,7 +68,7 @@ public class NacosMetadataReportTest {
String application = "nacos-metdata-report-test";
MetadataIdentifier providerIdentifier =
storeProvider(nacosMetadataReport, TEST_SERVICE, version, group, application);
- String serverContent = configService.getConfig(providerIdentifier.getUniqueKey(MetadataIdentifier.KeyTypeEnum.UNIQUE_KEY), group, 5000L);
+ String serverContent = configService.getConfig(providerIdentifier.getUniqueKey(MetadataIdentifier.KeyTypeEnum.UNIQUE_KEY), "zzz", 5000L);
Assertions.assertNotNull(serverContent);
Gson gson = new Gson();
@@ -81,7 +83,7 @@ public class NacosMetadataReportTest {
String application = "nacos-metadata-report-consumer-test";
MetadataIdentifier consumerIdentifier = storeConsumer(nacosMetadataReport, TEST_SERVICE, version, group, application);
- String serverContent = configService.getConfig(consumerIdentifier.getUniqueKey(MetadataIdentifier.KeyTypeEnum.UNIQUE_KEY), group, 5000L);
+ String serverContent = configService.getConfig(consumerIdentifier.getUniqueKey(MetadataIdentifier.KeyTypeEnum.UNIQUE_KEY), "zzz", 5000L);
Assertions.assertNotNull(serverContent);
Assertions.assertEquals(serverContent, "{\"paramConsumerTest\":\"nacosConsumer\"}");
}