diff --git a/dubbo-all/pom.xml b/dubbo-all/pom.xml
index f1ed0943300..a5e674a1edd 100644
--- a/dubbo-all/pom.xml
+++ b/dubbo-all/pom.xml
@@ -450,6 +450,13 @@
compile
true
+
+ org.apache.dubbo
+ dubbo-metadata-report-etcd
+ ${project.version}
+ compile
+ true
+
diff --git a/dubbo-bom/pom.xml b/dubbo-bom/pom.xml
index 148b49aebdc..2a6ef723e0d 100644
--- a/dubbo-bom/pom.xml
+++ b/dubbo-bom/pom.xml
@@ -357,6 +357,11 @@
dubbo-metadata-report-consul
${project.version}
+
+ org.apache.dubbo
+ dubbo-metadata-report-etcd
+ ${project.version}
+
org.apache.dubbo
dubbo-configcenter-api
diff --git a/dubbo-configcenter/dubbo-configcenter-etcd/src/test/java/org/apache/dubbo/configcenter/support/etcd/EtcdDynamicConfigurationTest.java b/dubbo-configcenter/dubbo-configcenter-etcd/src/test/java/org/apache/dubbo/configcenter/support/etcd/EtcdDynamicConfigurationTest.java
index 4e305eaf01e..0f07cab99d9 100644
--- a/dubbo-configcenter/dubbo-configcenter-etcd/src/test/java/org/apache/dubbo/configcenter/support/etcd/EtcdDynamicConfigurationTest.java
+++ b/dubbo-configcenter/dubbo-configcenter-etcd/src/test/java/org/apache/dubbo/configcenter/support/etcd/EtcdDynamicConfigurationTest.java
@@ -120,7 +120,6 @@ public String getValue() {
private void put(String key, String value) {
try {
-
client.getKVClient().put(ByteSequence.from(key, UTF_8), ByteSequence.from(value, UTF_8)).get();
} catch (Exception e) {
System.out.println("Error put value to etcd.");
diff --git a/dubbo-distribution/pom.xml b/dubbo-distribution/pom.xml
index e92363db722..76e73a3df67 100644
--- a/dubbo-distribution/pom.xml
+++ b/dubbo-distribution/pom.xml
@@ -185,6 +185,56 @@
dubbo-registry-sofa
${project.version}
+
+ org.apache.dubbo
+ dubbo-configcenter-api
+ ${project.version}
+
+
+ org.apache.dubbo
+ dubbo-configcenter-zookeeper
+ ${project.version}
+
+
+ org.apache.dubbo
+ dubbo-configcenter-apollo
+ ${project.version}
+
+
+ org.apache.dubbo
+ dubbo-configcenter-consul
+ ${project.version}
+
+
+ org.apache.dubbo
+ dubbo-configcenter-etcd
+ ${project.version}
+
+
+ org.apache.dubbo
+ dubbo-metadata-report-api
+ ${project.version}
+
+
+ org.apache.dubbo
+ dubbo-metadata-report-zookeeper
+ ${project.version}
+
+
+ org.apache.dubbo
+ dubbo-metadata-report-redis
+ ${project.version}
+
+
+ org.apache.dubbo
+ dubbo-metadata-report-consul
+ ${project.version}
+
+
+ org.apache.dubbo
+ dubbo-metadata-report-etcd
+ ${project.version}
+
org.apache.dubbo
dubbo-monitor-api
diff --git a/dubbo-metadata-report/dubbo-metadata-report-api/src/main/java/org/apache/dubbo/metadata/identifier/MetadataIdentifier.java b/dubbo-metadata-report/dubbo-metadata-report-api/src/main/java/org/apache/dubbo/metadata/identifier/MetadataIdentifier.java
index fca21bfbc99..457b3b6092b 100644
--- a/dubbo-metadata-report/dubbo-metadata-report-api/src/main/java/org/apache/dubbo/metadata/identifier/MetadataIdentifier.java
+++ b/dubbo-metadata-report/dubbo-metadata-report-api/src/main/java/org/apache/dubbo/metadata/identifier/MetadataIdentifier.java
@@ -23,8 +23,10 @@
* 2018/10/25
*/
public class MetadataIdentifier {
+
public static final String SEPARATOR = ":";
final static String DEFAULT_PATH_TAG = "metadata";
+ final static String META_DATA_STORE_TAG = ".metaData";
private String serviceInterface;
private String version;
@@ -53,9 +55,9 @@ public MetadataIdentifier(URL url) {
public String getUniqueKey(KeyTypeEnum keyType) {
if (keyType == KeyTypeEnum.PATH) {
- return getFilePathKey();
+ return getFilePathKey() + Constants.PATH_SEPARATOR + DEFAULT_PATH_TAG;
}
- return getIdentifierKey();
+ return getIdentifierKey() + META_DATA_STORE_TAG;
}
public String getIdentifierKey() {
diff --git a/dubbo-metadata-report/dubbo-metadata-report-api/src/main/java/org/apache/dubbo/metadata/store/MetadataReport.java b/dubbo-metadata-report/dubbo-metadata-report-api/src/main/java/org/apache/dubbo/metadata/store/MetadataReport.java
index 922f97cbeb3..1afcc83438b 100644
--- a/dubbo-metadata-report/dubbo-metadata-report-api/src/main/java/org/apache/dubbo/metadata/store/MetadataReport.java
+++ b/dubbo-metadata-report/dubbo-metadata-report-api/src/main/java/org/apache/dubbo/metadata/store/MetadataReport.java
@@ -26,9 +26,6 @@
*/
public interface MetadataReport {
- public static final String META_DATA_STORE_TAG = ".metaData";
-
-
void storeProviderMetadata(MetadataIdentifier providerMetadataIdentifier, FullServiceDefinition serviceDefinition);
void storeConsumerMetadata(MetadataIdentifier consumerMetadataIdentifier, Map serviceParameterMap);
diff --git a/dubbo-metadata-report/dubbo-metadata-report-api/src/main/java/org/apache/dubbo/metadata/support/AbstractMetadataReport.java b/dubbo-metadata-report/dubbo-metadata-report-api/src/main/java/org/apache/dubbo/metadata/support/AbstractMetadataReport.java
index 95b44f44927..16daa2eeb50 100644
--- a/dubbo-metadata-report/dubbo-metadata-report-api/src/main/java/org/apache/dubbo/metadata/support/AbstractMetadataReport.java
+++ b/dubbo-metadata-report/dubbo-metadata-report-api/src/main/java/org/apache/dubbo/metadata/support/AbstractMetadataReport.java
@@ -56,6 +56,7 @@
*/
public abstract class AbstractMetadataReport implements MetadataReport {
+ protected final static String DEFAULT_ROOT = "dubbo";
private static final int ONE_DAY_IN_MIll = 60 * 24 * 60 * 1000;
private static final int FOUR_HOURS_IN_MIll = 60 * 4 * 60 * 1000;
@@ -216,12 +217,7 @@ public void storeProviderMetadata(MetadataIdentifier providerMetadataIdentifier,
if (syncReport) {
storeProviderMetadataTask(providerMetadataIdentifier, serviceDefinition);
} else {
- reportCacheExecutor.execute(new Runnable() {
- @Override
- public void run() {
- storeProviderMetadataTask(providerMetadataIdentifier, serviceDefinition);
- }
- });
+ reportCacheExecutor.execute(() -> storeProviderMetadataTask(providerMetadataIdentifier, serviceDefinition));
}
}
@@ -249,12 +245,7 @@ public void storeConsumerMetadata(MetadataIdentifier consumerMetadataIdentifier,
if (syncReport) {
storeConsumerMetadataTask(consumerMetadataIdentifier, serviceParameterMap);
} else {
- reportCacheExecutor.execute(new Runnable() {
- @Override
- public void run() {
- storeConsumerMetadataTask(consumerMetadataIdentifier, serviceParameterMap);
- }
- });
+ reportCacheExecutor.execute(() -> storeConsumerMetadataTask(consumerMetadataIdentifier, serviceParameterMap));
}
}
diff --git a/dubbo-metadata-report/dubbo-metadata-report-api/src/test/java/org/apache/dubbo/metadata/identifier/MetadataIdentifierTest.java b/dubbo-metadata-report/dubbo-metadata-report-api/src/test/java/org/apache/dubbo/metadata/identifier/MetadataIdentifierTest.java
index 40fab45c4c8..ca415b46457 100644
--- a/dubbo-metadata-report/dubbo-metadata-report-api/src/test/java/org/apache/dubbo/metadata/identifier/MetadataIdentifierTest.java
+++ b/dubbo-metadata-report/dubbo-metadata-report-api/src/test/java/org/apache/dubbo/metadata/identifier/MetadataIdentifierTest.java
@@ -21,6 +21,8 @@
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
+import static org.apache.dubbo.metadata.identifier.MetadataIdentifier.META_DATA_STORE_TAG;
+
/**
* 2019/1/7
*/
@@ -34,10 +36,16 @@ public void testGetUniqueKey() {
String application = "vic.zk.md";
MetadataIdentifier providerMetadataIdentifier = new MetadataIdentifier(interfaceName, version, group, Constants.PROVIDER_SIDE, application);
System.out.println(providerMetadataIdentifier.getUniqueKey(MetadataIdentifier.KeyTypeEnum.PATH));
- Assertions.assertEquals(providerMetadataIdentifier.getUniqueKey(MetadataIdentifier.KeyTypeEnum.PATH), "metadata" + Constants.PATH_SEPARATOR + interfaceName + Constants.PATH_SEPARATOR + (version == null ? "" : (version + Constants.PATH_SEPARATOR))
- + (group == null ? "" : (group + Constants.PATH_SEPARATOR)) + Constants.PROVIDER_SIDE + Constants.PATH_SEPARATOR + application);
+ Assertions.assertEquals(providerMetadataIdentifier.getUniqueKey(MetadataIdentifier.KeyTypeEnum.PATH),
+ "metadata" + Constants.PATH_SEPARATOR + interfaceName + Constants.PATH_SEPARATOR +
+ (version == null ? "" : (version + Constants.PATH_SEPARATOR))
+ + (group == null ? "" : (group + Constants.PATH_SEPARATOR)) + Constants.PROVIDER_SIDE
+ + Constants.PATH_SEPARATOR + application + Constants.PATH_SEPARATOR + "metadata");
System.out.println(providerMetadataIdentifier.getUniqueKey(MetadataIdentifier.KeyTypeEnum.UNIQUE_KEY));
Assertions.assertEquals(providerMetadataIdentifier.getUniqueKey(MetadataIdentifier.KeyTypeEnum.UNIQUE_KEY),
- interfaceName + MetadataIdentifier.SEPARATOR + (version == null ? "" : version + MetadataIdentifier.SEPARATOR) + (group == null ? "" : group + MetadataIdentifier.SEPARATOR) + Constants.PROVIDER_SIDE + MetadataIdentifier.SEPARATOR + application);
+ interfaceName + MetadataIdentifier.SEPARATOR +
+ (version == null ? "" : version + MetadataIdentifier.SEPARATOR)
+ + (group == null ? "" : group + MetadataIdentifier.SEPARATOR)
+ + Constants.PROVIDER_SIDE + MetadataIdentifier.SEPARATOR + application + META_DATA_STORE_TAG);
}
}
diff --git a/dubbo-metadata-report/dubbo-metadata-report-api/src/test/java/org/apache/dubbo/metadata/store/test/JTestMetadataReport4Test.java b/dubbo-metadata-report/dubbo-metadata-report-api/src/test/java/org/apache/dubbo/metadata/store/test/JTestMetadataReport4Test.java
index 76778cee339..f5c129692e1 100644
--- a/dubbo-metadata-report/dubbo-metadata-report-api/src/test/java/org/apache/dubbo/metadata/store/test/JTestMetadataReport4Test.java
+++ b/dubbo-metadata-report/dubbo-metadata-report-api/src/test/java/org/apache/dubbo/metadata/store/test/JTestMetadataReport4Test.java
@@ -54,7 +54,7 @@ protected void doStoreProviderMetadata(MetadataIdentifier providerMetadataIdenti
@Override
protected void doStoreConsumerMetadata(MetadataIdentifier consumerMetadataIdentifier, String serviceParameterString) {
- store.put(consumerMetadataIdentifier.getIdentifierKey(), serviceParameterString);
+ store.put(consumerMetadataIdentifier.getUniqueKey(MetadataIdentifier.KeyTypeEnum.UNIQUE_KEY), serviceParameterString);
}
public static String getProviderKey(URL url) {
diff --git a/dubbo-metadata-report/dubbo-metadata-report-consul/src/main/java/org/apache/dubbo/metadata/store/consul/ConsulMetadataReport.java b/dubbo-metadata-report/dubbo-metadata-report-consul/src/main/java/org/apache/dubbo/metadata/store/consul/ConsulMetadataReport.java
index 7bc6e7ee644..42a2f600f63 100644
--- a/dubbo-metadata-report/dubbo-metadata-report-consul/src/main/java/org/apache/dubbo/metadata/store/consul/ConsulMetadataReport.java
+++ b/dubbo-metadata-report/dubbo-metadata-report-consul/src/main/java/org/apache/dubbo/metadata/store/consul/ConsulMetadataReport.java
@@ -55,7 +55,7 @@ protected void doStoreConsumerMetadata(MetadataIdentifier consumerMetadataIdenti
private void storeMetadata(MetadataIdentifier identifier, String v) {
try {
- client.setKVValue(identifier.getIdentifierKey() + META_DATA_STORE_TAG, v);
+ client.setKVValue(identifier.getUniqueKey(MetadataIdentifier.KeyTypeEnum.UNIQUE_KEY), v);
} catch (Throwable t) {
logger.error("Failed to put " + identifier + " to consul " + v + ", cause: " + t.getMessage(), t);
throw new RpcException("Failed to put " + identifier + " to consul " + v + ", cause: " + t.getMessage(), t);
diff --git a/dubbo-metadata-report/dubbo-metadata-report-etcd/pom.xml b/dubbo-metadata-report/dubbo-metadata-report-etcd/pom.xml
new file mode 100644
index 00000000000..6ab0c1e6d93
--- /dev/null
+++ b/dubbo-metadata-report/dubbo-metadata-report-etcd/pom.xml
@@ -0,0 +1,53 @@
+
+
+
+
+
+ dubbo-metadata-report
+ org.apache.dubbo
+ 2.7.2-SNAPSHOT
+
+ 4.0.0
+
+ dubbo-metadata-report-etcd
+
+
+
+ org.apache.dubbo
+ dubbo-metadata-report-api
+ ${project.parent.version}
+
+
+ org.apache.dubbo
+ dubbo-remoting-etcd3
+ ${project.parent.version}
+
+
+ io.etcd
+ jetcd-launcher
+ test
+
+
+ org.testcontainers
+ testcontainers
+ test
+
+
+
\ No newline at end of file
diff --git a/dubbo-metadata-report/dubbo-metadata-report-etcd/src/main/java/org/apache/dubbo/metadata/store/etcd/EtcdMetadataReport.java b/dubbo-metadata-report/dubbo-metadata-report-etcd/src/main/java/org/apache/dubbo/metadata/store/etcd/EtcdMetadataReport.java
new file mode 100644
index 00000000000..0a472f55a78
--- /dev/null
+++ b/dubbo-metadata-report/dubbo-metadata-report-etcd/src/main/java/org/apache/dubbo/metadata/store/etcd/EtcdMetadataReport.java
@@ -0,0 +1,98 @@
+/*
+ * 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.
+ */
+
+/*
+ * 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.store.etcd;
+
+import org.apache.dubbo.common.Constants;
+import org.apache.dubbo.common.URL;
+import org.apache.dubbo.common.logger.Logger;
+import org.apache.dubbo.common.logger.LoggerFactory;
+import org.apache.dubbo.metadata.identifier.MetadataIdentifier;
+import org.apache.dubbo.metadata.support.AbstractMetadataReport;
+import org.apache.dubbo.remoting.etcd.jetcd.JEtcdClient;
+
+/**
+ * Report Metadata to Etcd
+ */
+public class EtcdMetadataReport extends AbstractMetadataReport {
+
+ private final static Logger logger = LoggerFactory.getLogger(EtcdMetadataReport.class);
+
+ private final String root;
+
+ /**
+ * The etcd client
+ */
+ private final JEtcdClient etcdClient;
+
+ public EtcdMetadataReport(URL url) {
+ super(url);
+ if (url.isAnyHost()) {
+ throw new IllegalStateException("registry address == null");
+ }
+ String group = url.getParameter(Constants.GROUP_KEY, DEFAULT_ROOT);
+ if (!group.startsWith(Constants.PATH_SEPARATOR)) {
+ group = Constants.PATH_SEPARATOR + group;
+ }
+ this.root = group;
+ etcdClient = new JEtcdClient(url);
+ }
+
+ @Override
+ protected void doStoreProviderMetadata(MetadataIdentifier providerMetadataIdentifier, String serviceDefinitions) {
+ storeMetadata(providerMetadataIdentifier, serviceDefinitions);
+ }
+
+ @Override
+ protected void doStoreConsumerMetadata(MetadataIdentifier consumerMetadataIdentifier, String value) {
+ storeMetadata(consumerMetadataIdentifier, value);
+ }
+
+ private void storeMetadata(MetadataIdentifier identifier, String v) {
+ String key = getNodeKey(identifier);
+ if (!etcdClient.put(key, v)) {
+ logger.error("Failed to put " + identifier + " to etcd, value: " + v);
+ }
+ }
+
+ String getNodeKey(MetadataIdentifier identifier) {
+ return toRootDir() + identifier.getUniqueKey(MetadataIdentifier.KeyTypeEnum.PATH);
+ }
+
+ String toRootDir() {
+ if (root.equals(Constants.PATH_SEPARATOR)) {
+ return root;
+ }
+ return root + Constants.PATH_SEPARATOR;
+ }
+}
diff --git a/dubbo-metadata-report/dubbo-metadata-report-etcd/src/main/java/org/apache/dubbo/metadata/store/etcd/EtcdMetadataReportFactory.java b/dubbo-metadata-report/dubbo-metadata-report-etcd/src/main/java/org/apache/dubbo/metadata/store/etcd/EtcdMetadataReportFactory.java
new file mode 100644
index 00000000000..f0572b64482
--- /dev/null
+++ b/dubbo-metadata-report/dubbo-metadata-report-etcd/src/main/java/org/apache/dubbo/metadata/store/etcd/EtcdMetadataReportFactory.java
@@ -0,0 +1,50 @@
+/*
+ * 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.
+ */
+
+/*
+ * 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.store.etcd;
+
+import org.apache.dubbo.common.URL;
+import org.apache.dubbo.metadata.store.MetadataReport;
+import org.apache.dubbo.metadata.support.AbstractMetadataReportFactory;
+
+/**
+ * MetadataReportFactory to create an Etcd based {@link MetadataReport}.
+ */
+public class EtcdMetadataReportFactory extends AbstractMetadataReportFactory {
+
+ @Override
+ public MetadataReport createMetadataReport(URL url) {
+ return new EtcdMetadataReport(url);
+ }
+
+}
diff --git a/dubbo-metadata-report/dubbo-metadata-report-etcd/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.metadata.store.MetadataReportFactory b/dubbo-metadata-report/dubbo-metadata-report-etcd/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.metadata.store.MetadataReportFactory
new file mode 100644
index 00000000000..9a3c98c82a5
--- /dev/null
+++ b/dubbo-metadata-report/dubbo-metadata-report-etcd/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.metadata.store.MetadataReportFactory
@@ -0,0 +1 @@
+etcd=org.apache.dubbo.metadata.store.etcd.EtcdMetadataReportFactory
diff --git a/dubbo-metadata-report/dubbo-metadata-report-etcd/src/test/java/org/apache/dubbo/metadata/store/etcd/EtcdMetadata4TstService.java b/dubbo-metadata-report/dubbo-metadata-report-etcd/src/test/java/org/apache/dubbo/metadata/store/etcd/EtcdMetadata4TstService.java
new file mode 100644
index 00000000000..1de21ce5652
--- /dev/null
+++ b/dubbo-metadata-report/dubbo-metadata-report-etcd/src/test/java/org/apache/dubbo/metadata/store/etcd/EtcdMetadata4TstService.java
@@ -0,0 +1,28 @@
+/*
+ * 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.store.etcd;
+
+/**
+ * Test interface for Etcd metadata report
+ */
+public interface EtcdMetadata4TstService {
+
+ int getCounter();
+
+ void printResult(String var);
+}
diff --git a/dubbo-metadata-report/dubbo-metadata-report-etcd/src/test/java/org/apache/dubbo/metadata/store/etcd/EtcdMetadataReportTest.java b/dubbo-metadata-report/dubbo-metadata-report-etcd/src/test/java/org/apache/dubbo/metadata/store/etcd/EtcdMetadataReportTest.java
new file mode 100644
index 00000000000..e6f6b02c522
--- /dev/null
+++ b/dubbo-metadata-report/dubbo-metadata-report-etcd/src/test/java/org/apache/dubbo/metadata/store/etcd/EtcdMetadataReportTest.java
@@ -0,0 +1,132 @@
+/*
+ * 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.store.etcd;
+
+import com.google.gson.Gson;
+import io.etcd.jetcd.ByteSequence;
+import io.etcd.jetcd.Client;
+import io.etcd.jetcd.kv.GetResponse;
+import io.etcd.jetcd.launcher.EtcdCluster;
+import io.etcd.jetcd.launcher.EtcdClusterFactory;
+import org.apache.dubbo.common.Constants;
+import org.apache.dubbo.common.URL;
+import org.apache.dubbo.common.utils.NetUtils;
+import org.apache.dubbo.metadata.definition.ServiceDefinitionBuilder;
+import org.apache.dubbo.metadata.definition.model.FullServiceDefinition;
+import org.apache.dubbo.metadata.identifier.MetadataIdentifier;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import java.net.URI;
+import java.nio.charset.StandardCharsets;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.CompletableFuture;
+
+/**
+ * Unit test for etcd metadata report
+ */
+public class EtcdMetadataReportTest {
+
+ private static final String TEST_SERVICE = "org.apache.dubbo.metadata.store.etcd.EtcdMetadata4TstService";
+
+ private EtcdCluster etcdCluster = EtcdClusterFactory.buildCluster(getClass().getSimpleName(), 1, false, false);
+ private Client etcdClientForTest;
+ private EtcdMetadataReport etcdMetadataReport;
+ private URL registryUrl;
+ private EtcdMetadataReportFactory etcdMetadataReportFactory;
+
+ @BeforeEach
+ public void setUp() {
+ etcdCluster.start();
+ etcdClientForTest = Client.builder().endpoints(etcdCluster.getClientEndpoints()).build();
+ List clientEndPoints = etcdCluster.getClientEndpoints();
+ this.registryUrl = URL.valueOf("etcd://" + clientEndPoints.get(0).getHost() + ":" + clientEndPoints.get(0).getPort());
+ etcdMetadataReportFactory = new EtcdMetadataReportFactory();
+ this.etcdMetadataReport = (EtcdMetadataReport) etcdMetadataReportFactory.createMetadataReport(registryUrl);
+ }
+
+ @AfterEach
+ public void tearDown() throws Exception {
+ etcdCluster.close();
+ }
+
+ @Test
+ public void testStoreProvider() throws Exception {
+ String version = "1.0.0";
+ String group = null;
+ String application = "etcd-metdata-report-test";
+ MetadataIdentifier providerIdentifier =
+ storeProvider(etcdMetadataReport, TEST_SERVICE, version, group, application);
+
+ CompletableFuture response = etcdClientForTest.getKVClient().get(ByteSequence.from(
+ etcdMetadataReport.getNodeKey(providerIdentifier), StandardCharsets.UTF_8));
+ String fileContent = response.get().getKvs().get(0).getValue().toString(StandardCharsets.UTF_8);
+ Assertions.assertNotNull(fileContent);
+
+ Gson gson = new Gson();
+ FullServiceDefinition fullServiceDefinition = gson.fromJson(fileContent, FullServiceDefinition.class);
+ Assertions.assertEquals(fullServiceDefinition.getParameters().get("paramTest"), "etcdTest");
+ }
+
+ @Test
+ public void testStoreConsumer() throws Exception {
+ String version = "1.0.0";
+ String group = null;
+ String application = "etc-metadata-report-consumer-test";
+ MetadataIdentifier consumerIdentifier = storeConsumer(etcdMetadataReport, TEST_SERVICE, version, group, application);
+
+ CompletableFuture response = etcdClientForTest.getKVClient().get(ByteSequence.from(
+ etcdMetadataReport.getNodeKey(consumerIdentifier), StandardCharsets.UTF_8));
+ String fileContent = response.get().getKvs().get(0).getValue().toString(StandardCharsets.UTF_8);
+ Assertions.assertNotNull(fileContent);
+ Assertions.assertEquals(fileContent, "{\"paramConsumerTest\":\"etcdConsumer\"}");
+ }
+
+ private MetadataIdentifier storeProvider(EtcdMetadataReport etcdMetadataReport, String interfaceName, String version,
+ String group, String application)
+ throws ClassNotFoundException, InterruptedException {
+ URL url = URL.valueOf("xxx://" + NetUtils.getLocalAddress().getHostName() + ":4444/" + interfaceName +
+ "?paramTest=etcdTest&version=" + version + "&application="
+ + application + (group == null ? "" : "&group=" + group));
+
+ MetadataIdentifier providerMetadataIdentifier =
+ new MetadataIdentifier(interfaceName, version, group, Constants.PROVIDER_SIDE, application);
+ Class interfaceClass = Class.forName(interfaceName);
+ FullServiceDefinition fullServiceDefinition =
+ ServiceDefinitionBuilder.buildFullDefinition(interfaceClass, url.getParameters());
+
+ etcdMetadataReport.storeProviderMetadata(providerMetadataIdentifier, fullServiceDefinition);
+ Thread.sleep(1000);
+ return providerMetadataIdentifier;
+ }
+
+ private MetadataIdentifier storeConsumer(EtcdMetadataReport etcdMetadataReport, String interfaceName,
+ String version, String group, String application) throws InterruptedException {
+
+ MetadataIdentifier consumerIdentifier = new MetadataIdentifier(interfaceName, version, group, Constants.CONSUMER_SIDE, application);
+ Map tmp = new HashMap<>();
+ tmp.put("paramConsumerTest", "etcdConsumer");
+ etcdMetadataReport.storeConsumerMetadata(consumerIdentifier, tmp);
+ Thread.sleep(1000);
+ return consumerIdentifier;
+ }
+}
diff --git a/dubbo-metadata-report/dubbo-metadata-report-redis/src/main/java/org/apache/dubbo/metadata/store/redis/RedisMetadataReport.java b/dubbo-metadata-report/dubbo-metadata-report-redis/src/main/java/org/apache/dubbo/metadata/store/redis/RedisMetadataReport.java
index 42d88802e5b..b00295c3bdf 100644
--- a/dubbo-metadata-report/dubbo-metadata-report-redis/src/main/java/org/apache/dubbo/metadata/store/redis/RedisMetadataReport.java
+++ b/dubbo-metadata-report/dubbo-metadata-report-redis/src/main/java/org/apache/dubbo/metadata/store/redis/RedisMetadataReport.java
@@ -54,7 +54,7 @@ protected void doStoreConsumerMetadata(MetadataIdentifier consumerMetadataIdenti
private void storeMetadata(MetadataIdentifier metadataIdentifier, String v) {
try (Jedis jedis = pool.getResource()) {
- jedis.set(metadataIdentifier.getIdentifierKey() + META_DATA_STORE_TAG, v);
+ jedis.set(metadataIdentifier.getUniqueKey(MetadataIdentifier.KeyTypeEnum.UNIQUE_KEY), v);
} catch (Throwable e) {
logger.error("Failed to put " + metadataIdentifier + " to redis " + v + ", cause: " + e.getMessage(), e);
throw new RpcException("Failed to put " + metadataIdentifier + " to redis " + v + ", cause: " + e.getMessage(), e);
diff --git a/dubbo-metadata-report/dubbo-metadata-report-redis/src/test/java/org/apache/dubbo/metadata/store/redis/RedisMetadataReportTest.java b/dubbo-metadata-report/dubbo-metadata-report-redis/src/test/java/org/apache/dubbo/metadata/store/redis/RedisMetadataReportTest.java
index 4984bde5b19..5a6d4f5fcf1 100644
--- a/dubbo-metadata-report/dubbo-metadata-report-redis/src/test/java/org/apache/dubbo/metadata/store/redis/RedisMetadataReportTest.java
+++ b/dubbo-metadata-report/dubbo-metadata-report-redis/src/test/java/org/apache/dubbo/metadata/store/redis/RedisMetadataReportTest.java
@@ -39,7 +39,6 @@
import java.util.Map;
import static org.apache.dubbo.common.Constants.SYNC_REPORT_KEY;
-import static org.apache.dubbo.metadata.store.MetadataReport.META_DATA_STORE_TAG;
/**
* 2018/10/9
@@ -93,7 +92,7 @@ private void testStoreProvider(RedisMetadataReport redisMetadataReport, String v
Jedis jedis = null;
try {
jedis = redisMetadataReport.pool.getResource();
- String keyTmp = providerMetadataIdentifier.getUniqueKey(MetadataIdentifier.KeyTypeEnum.UNIQUE_KEY) + META_DATA_STORE_TAG;
+ String keyTmp = providerMetadataIdentifier.getUniqueKey(MetadataIdentifier.KeyTypeEnum.UNIQUE_KEY);
String value = jedis.get(keyTmp);
if (value == null) {
Thread.sleep(moreTime);
@@ -109,7 +108,7 @@ private void testStoreProvider(RedisMetadataReport redisMetadataReport, String v
throw new RpcException("Failed to put to redis . cause: " + e.getMessage(), e);
} finally {
if (jedis != null) {
- jedis.del(providerMetadataIdentifier.getUniqueKey(MetadataIdentifier.KeyTypeEnum.UNIQUE_KEY) + META_DATA_STORE_TAG);
+ jedis.del(providerMetadataIdentifier.getUniqueKey(MetadataIdentifier.KeyTypeEnum.UNIQUE_KEY));
}
redisMetadataReport.pool.close();
}
@@ -133,7 +132,7 @@ private void testStoreConsumer(RedisMetadataReport redisMetadataReport, String v
Jedis jedis = null;
try {
jedis = redisMetadataReport.pool.getResource();
- String keyTmp = consumerMetadataIdentifier.getUniqueKey(MetadataIdentifier.KeyTypeEnum.UNIQUE_KEY) + META_DATA_STORE_TAG;
+ String keyTmp = consumerMetadataIdentifier.getUniqueKey(MetadataIdentifier.KeyTypeEnum.UNIQUE_KEY);
String value = jedis.get(keyTmp);
if (value == null) {
Thread.sleep(moreTime);
@@ -144,7 +143,7 @@ private void testStoreConsumer(RedisMetadataReport redisMetadataReport, String v
throw new RpcException("Failed to put to redis . cause: " + e.getMessage(), e);
} finally {
if (jedis != null) {
- jedis.del(consumerMetadataIdentifier.getUniqueKey(MetadataIdentifier.KeyTypeEnum.UNIQUE_KEY) + META_DATA_STORE_TAG);
+ jedis.del(consumerMetadataIdentifier.getUniqueKey(MetadataIdentifier.KeyTypeEnum.UNIQUE_KEY));
}
redisMetadataReport.pool.close();
}
diff --git a/dubbo-metadata-report/dubbo-metadata-report-zookeeper/src/main/java/org/apache/dubbo/metadata/store/zookeeper/ZookeeperMetadataReport.java b/dubbo-metadata-report/dubbo-metadata-report-zookeeper/src/main/java/org/apache/dubbo/metadata/store/zookeeper/ZookeeperMetadataReport.java
index 8194e1ae446..de26faf7c2a 100644
--- a/dubbo-metadata-report/dubbo-metadata-report-zookeeper/src/main/java/org/apache/dubbo/metadata/store/zookeeper/ZookeeperMetadataReport.java
+++ b/dubbo-metadata-report/dubbo-metadata-report-zookeeper/src/main/java/org/apache/dubbo/metadata/store/zookeeper/ZookeeperMetadataReport.java
@@ -20,14 +20,11 @@
import org.apache.dubbo.common.URL;
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.metadata.identifier.MetadataIdentifier;
import org.apache.dubbo.metadata.support.AbstractMetadataReport;
import org.apache.dubbo.remoting.zookeeper.ZookeeperClient;
import org.apache.dubbo.remoting.zookeeper.ZookeeperTransporter;
-import java.util.List;
-
/**
* ZookeeperMetadataReport
*/
@@ -35,9 +32,6 @@ public class ZookeeperMetadataReport extends AbstractMetadataReport {
private final static Logger logger = LoggerFactory.getLogger(ZookeeperMetadataReport.class);
- private final static String DEFAULT_ROOT = "dubbo";
- private final static String METADATA_NODE_NAME = "service.data";
-
private final String root;
final ZookeeperClient zkClient;
@@ -55,16 +49,6 @@ public ZookeeperMetadataReport(URL url, ZookeeperTransporter zookeeperTransporte
zkClient = zookeeperTransporter.connect(url);
}
- void deletePath(String category) {
- List urlStrs = zkClient.getChildren(category);
- if (CollectionUtils.isEmpty(urlStrs)) {
- return;
- }
- for (String urlStr : urlStrs) {
- zkClient.delete(category + Constants.PATH_SEPARATOR + urlStr);
- }
- }
-
String toRootDir() {
if (root.equals(Constants.PATH_SEPARATOR)) {
return root;
@@ -87,7 +71,7 @@ private void storeMetadata(MetadataIdentifier metadataIdentifier, String v) {
}
String getNodePath(MetadataIdentifier metadataIdentifier) {
- return toRootDir() + metadataIdentifier.getUniqueKey(MetadataIdentifier.KeyTypeEnum.PATH) + Constants.PATH_SEPARATOR + METADATA_NODE_NAME;
+ return toRootDir() + metadataIdentifier.getUniqueKey(MetadataIdentifier.KeyTypeEnum.PATH);
}
diff --git a/dubbo-metadata-report/dubbo-metadata-report-zookeeper/src/test/java/org/apache/dubbo/metadata/store/zookeeper/ZookeeperMetadataReportTest.java b/dubbo-metadata-report/dubbo-metadata-report-zookeeper/src/test/java/org/apache/dubbo/metadata/store/zookeeper/ZookeeperMetadataReportTest.java
index c9ed9cfa9bb..da1e87b8945 100644
--- a/dubbo-metadata-report/dubbo-metadata-report-zookeeper/src/test/java/org/apache/dubbo/metadata/store/zookeeper/ZookeeperMetadataReportTest.java
+++ b/dubbo-metadata-report/dubbo-metadata-report-zookeeper/src/test/java/org/apache/dubbo/metadata/store/zookeeper/ZookeeperMetadataReportTest.java
@@ -29,7 +29,6 @@
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import java.util.HashMap;
@@ -62,7 +61,7 @@ public void tearDown() throws Exception {
private void deletePath(MetadataIdentifier metadataIdentifier, ZookeeperMetadataReport zookeeperMetadataReport) {
String category = zookeeperMetadataReport.toRootDir() + metadataIdentifier.getUniqueKey(MetadataIdentifier.KeyTypeEnum.PATH);
- zookeeperMetadataReport.deletePath(category);
+ zookeeperMetadataReport.zkClient.delete(category);
}
@Test
diff --git a/dubbo-metadata-report/pom.xml b/dubbo-metadata-report/pom.xml
index 6d47af47374..3cb254afb96 100644
--- a/dubbo-metadata-report/pom.xml
+++ b/dubbo-metadata-report/pom.xml
@@ -30,6 +30,7 @@
dubbo-metadata-report-redis
dubbo-metadata-definition
dubbo-metadata-report-consul
+ dubbo-metadata-report-etcd