Skip to content
Permalink
Browse files
Fix 3.0 config (#318)
* fix provider props

* improve config

* add nacos docker-compose

* remove external config props

* improve protocol config

* fix dubbo-samples-context tests

* improve dubbo build scripts in workflows

* fix compile error

* compatible with 3.0 dev branch

* fix dubbo-samples-metadata-report-configcenter configs compatibility
  • Loading branch information
kylixs committed May 24, 2021
1 parent 03ce574 commit e05f77601c5376263319361635394b7ce664e903
Showing 17 changed files with 112 additions and 57 deletions.
@@ -28,7 +28,6 @@ env:
spring-boot.version:2.4.1;
'
DUBBO_REF: 'master'
DUBBO_SPRING_BOOT_REF: '2.7.x'

jobs:
build-samples:
@@ -65,20 +64,16 @@ jobs:
with:
repository: 'apache/dubbo'
ref: ${{env.DUBBO_REF}}
path: dubbo
- name: Get commit id and dubbo version
id: git-checker
run: |
# Calculate Dubbo Version
REVISION=`awk '/<revision>[^<]+<\/revision>/{gsub(/<revision>|<\/revision>/,"",$1);print $1;exit;}' dubbo/pom.xml`
REVISION=`awk '/<revision>[^<]+<\/revision>/{gsub(/<revision>|<\/revision>/,"",$1);print $1;exit;}' pom.xml`
echo "::set-output name=version::$REVISION"
echo "dubbo version: $REVISION"
#
#concat dubbo/dubbo-spring-boot commit id
cd dubbo
dubbo_commit_id=`git log --format="%H" -n 1`
cd ..
commit_id=$dubbo_commit_id
# commit id
commit_id=`git log --format="%H" -n 1`
echo "::set-output name=commit_id::$commit_id"
echo "commit_id: $commit_id"
- name: Dubbo cache
@@ -103,7 +98,6 @@ jobs:
- name: Build dubbo
if: steps.dubbocache.outputs.cache-hit != 'true'
run: |
cd dubbo
./mvnw --batch-mode --no-transfer-progress clean install -Dmaven.test.skip=true -Dmaven.test.skip.exec=true
prepare_test:
@@ -28,7 +28,6 @@ env:
spring-boot.version:2.4.1;
'
DUBBO_REF: '3.0'
DUBBO_SPRING_BOOT_REF: '3.0.x'

jobs:
build-samples:
@@ -65,20 +64,16 @@ jobs:
with:
repository: 'apache/dubbo'
ref: ${{env.DUBBO_REF}}
path: dubbo
- name: Get commit id and dubbo version
id: git-checker
run: |
# Calculate Dubbo Version
REVISION=`awk '/<revision>[^<]+<\/revision>/{gsub(/<revision>|<\/revision>/,"",$1);print $1;exit;}' dubbo/pom.xml`
REVISION=`awk '/<revision>[^<]+<\/revision>/{gsub(/<revision>|<\/revision>/,"",$1);print $1;exit;}' pom.xml`
echo "::set-output name=version::$REVISION"
echo "dubbo version: $REVISION"
#
#concat dubbo/dubbo-spring-boot commit id
cd dubbo
dubbo_commit_id=`git log --format="%H" -n 1`
cd ..
commit_id=$dubbo_commit_id
# commit id
commit_id=`git log --format="%H" -n 1`
echo "::set-output name=commit_id::$commit_id"
echo "commit_id: $commit_id"
- name: Dubbo cache
@@ -103,7 +98,6 @@ jobs:
- name: Build dubbo
if: steps.dubbocache.outputs.cache-hit != 'true'
run: |
cd dubbo
./mvnw --batch-mode --no-transfer-progress clean install -Dmaven.test.skip=true -Dmaven.test.skip.exec=true
prepare_test:
@@ -29,7 +29,6 @@ env:
spring-boot.version: 2.0.9.RELEASE, 2.1.18.RELEASE, 2.2.12.RELEASE, 2.3.7.RELEASE, 2.4.1
'
DUBBO_REF: 'master'
DUBBO_SPRING_BOOT_REF: '2.7.x'

jobs:
build-samples:
@@ -68,20 +67,16 @@ jobs:
with:
repository: 'apache/dubbo'
ref: ${{env.DUBBO_REF}}
path: dubbo
- name: Get commit id and dubbo version
id: git-checker
run: |
# Calculate Dubbo Version
REVISION=`awk '/<revision>[^<]+<\/revision>/{gsub(/<revision>|<\/revision>/,"",$1);print $1;exit;}' dubbo/pom.xml`
REVISION=`awk '/<revision>[^<]+<\/revision>/{gsub(/<revision>|<\/revision>/,"",$1);print $1;exit;}' pom.xml`
echo "::set-output name=version::$REVISION"
echo "dubbo version: $REVISION"
#
#concat dubbo/dubbo-spring-boot commit id
cd dubbo
dubbo_commit_id=`git log --format="%H" -n 1`
cd ..
commit_id=$dubbo_commit_id
# commit id
commit_id=`git log --format="%H" -n 1`
echo "::set-output name=commit_id::$commit_id"
echo "commit_id: $commit_id"
- name: Dubbo cache
@@ -106,7 +101,6 @@ jobs:
- name: Build dubbo
if: steps.dubbocache.outputs.cache-hit != 'true'
run: |
cd dubbo
./mvnw --batch-mode --no-transfer-progress clean install -Dmaven.test.skip=true -Dmaven.test.skip.exec=true
prepare_test:
@@ -28,7 +28,6 @@ env:
spring-boot.version: 2.0.9.RELEASE, 2.1.18.RELEASE, 2.2.12.RELEASE, 2.3.7.RELEASE, 2.4.1
'
DUBBO_REF: '3.0'
DUBBO_SPRING_BOOT_REF: '3.0.x'

jobs:
build-samples:
@@ -67,20 +66,16 @@ jobs:
with:
repository: 'apache/dubbo'
ref: ${{env.DUBBO_REF}}
path: dubbo
- name: Get commit id and dubbo version
id: git-checker
run: |
# Calculate Dubbo Version
REVISION=`awk '/<revision>[^<]+<\/revision>/{gsub(/<revision>|<\/revision>/,"",$1);print $1;exit;}' dubbo/pom.xml`
REVISION=`awk '/<revision>[^<]+<\/revision>/{gsub(/<revision>|<\/revision>/,"",$1);print $1;exit;}' pom.xml`
echo "::set-output name=version::$REVISION"
echo "dubbo version: $REVISION"
#
#concat dubbo/dubbo-spring-boot commit id
cd dubbo
dubbo_commit_id=`git log --format="%H" -n 1`
cd ..
commit_id=$dubbo_commit_id
# commit id
commit_id=`git log --format="%H" -n 1`
echo "::set-output name=commit_id::$commit_id"
echo "commit_id: $commit_id"
- name: Dubbo cache
@@ -105,7 +100,6 @@ jobs:
- name: Build dubbo
if: steps.dubbocache.outputs.cache-hit != 'true'
run: |
cd dubbo
./mvnw --batch-mode --no-transfer-progress clean install -Dmaven.test.skip=true -Dmaven.test.skip.exec=true
prepare_test:
@@ -29,7 +29,7 @@

<dubbo:registry address="zookeeper://${zookeeper.address:127.0.0.1}:2181"/>

<dubbo:protocol port="20880"/>
<dubbo:protocol name="dubbo" port="20880"/>

<bean id="asyncService" class="org.apache.dubbo.samples.async.impl.AsyncServiceImpl"/>

@@ -28,7 +28,7 @@
<!-- optional provider's application name, used for tracing dependency relationship -->
<dubbo:application name="chain-backend-app"/>
<dubbo:registry address="zookeeper://${zookeeper.address:127.0.0.1}:2181"/>
<dubbo:protocol port="20880"/>
<dubbo:protocol name="dubbo" port="20880"/>

<dubbo:config-center address="zookeeper://${zookeeper.address:127.0.0.1}:2181"/>

@@ -29,7 +29,7 @@
<!-- optional provider's application name, used for tracing dependency relationship -->
<dubbo:application name="chain-middle-app"/>
<dubbo:registry address="zookeeper://${zookeeper.address:127.0.0.1}:2181"/>
<dubbo:protocol port="20881"/>
<dubbo:protocol name="dubbo" port="20881"/>

<dubbo:config-center address="zookeeper://${zookeeper.address:127.0.0.1}:2181"/>

@@ -27,7 +27,7 @@
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath*:/spring/dubbo-context-consumer.xml", "classpath*:/spring/dubbo-context-provider.xml"})
@ContextConfiguration(locations = {"classpath*:/spring/dubbo-context-consumer.xml"})
public class ContextServiceIT {

@Autowired
@@ -28,7 +28,7 @@
<dubbo:application name="governance-appoverride-provider"/>

<dubbo:registry address="zookeeper://${zookeeper.address:127.0.0.1}:2181"/>
<dubbo:protocol port="${dubbo.port:20880}"/>
<dubbo:protocol name="dubbo" port="${dubbo.port:20880}"/>

<bean id="demoService" class="org.apache.dubbo.samples.governance.impl.DemoServiceImpl"/>
<dubbo:service interface="org.apache.dubbo.samples.governance.api.DemoService" ref="demoService"/>
@@ -29,7 +29,7 @@

<dubbo:registry address="zookeeper://${zookeeper.address:127.0.0.1}:2181"/>

<dubbo:protocol port="${dubbo.port:-1}"/>
<dubbo:protocol name="dubbo" port="${dubbo.port:-1}"/>

<dubbo:config-center highest-priority="false" address="zookeeper://${zookeeper.address:127.0.0.1}:2181"/>

@@ -20,6 +20,7 @@
package org.apache.dubbo.samples.metadatareport.configcenter;


import org.apache.dubbo.common.Version;
import org.apache.dubbo.common.constants.CommonConstants;
import org.apache.dubbo.config.ProviderConfig;
import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
@@ -32,19 +33,25 @@

import java.util.concurrent.CountDownLatch;

import static org.apache.dubbo.samples.metadatareport.configcenter.ZKTools.VERSION300;

public class MetadataConfigcenterProvider {

public static void main(String[] args) throws Exception {
new EmbeddedZooKeeper(2181, false).start();
ZKTools.generateDubboProperties();

AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ProviderConfiguration.class);
context.start();
try {
ZKTools.generateDubboProperties();
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ProviderConfiguration.class);
context.start();

printServiceData();
printServiceData();

System.out.println("dubbo service started");
new CountDownLatch(1).await();
System.out.println("dubbo service started");
new CountDownLatch(1).await();
} finally {
ZKTools.removeDubboProperties();
}
}

@Configuration
@@ -54,7 +61,14 @@ static public class ProviderConfiguration {
@Bean
public ProviderConfig providerConfig() {
ProviderConfig providerConfig = new ProviderConfig();
providerConfig.setId("id"); //FIXME, spring bean id 'providerConfig' should not be used as dubbo id.
// compatible with dubbo 2.7.x
if (Version.getIntVersion(Version.getVersion()) < VERSION300) {
// avoid using spring bean id 'providerConfig' as dubbo config id.
providerConfig.setId("my-provider");
} else {
//TODO remove the following line after merging dubbo 3.0 config refactor pr
providerConfig.setId("my-provider");
}
providerConfig.setTimeout(1000);
return providerConfig;
}
@@ -16,6 +16,7 @@
*/
package org.apache.dubbo.samples.metadatareport.configcenter;

import org.apache.dubbo.common.Version;
import org.apache.dubbo.common.utils.StringUtils;
import org.apache.dubbo.metadata.report.identifier.KeyTypeEnum;
import org.apache.dubbo.metadata.report.identifier.MetadataIdentifier;
@@ -27,15 +28,21 @@
import static org.apache.dubbo.common.constants.CommonConstants.PATH_SEPARATOR;

public class ZKTools {
public static final String GLOBAL_DUBBO_PROPERTIES_PATH = "/dubbo/config/dubbo/dubbo.properties";
public static final String CONSUMER_DUBBO_PROPERTIES_PATH = "/dubbo/config/metadatareport-configcenter-consumer/dubbo.properties";
public static final String PROVIDER_DUBBO_PROPERTIES_PATH = "/dubbo/config/metadatareport-configcenter-provider/dubbo.properties";
private static String zookeeperHost = System.getProperty("zookeeper.address", "127.0.0.1");
private static CuratorFramework client;

public static final int VERSION300 = Version.getIntVersion("3.0.0");

static {
initClient();
}

public static void main(String[] args) throws Exception {
generateDubboProperties();
removeDubboProperties();
}

public static void generateDubboProperties() {
@@ -56,13 +63,22 @@ public static void generateDubboPropertiesForGlobal() {
"#global config for consumer\n" +
"dubbo.consumer.timeout=6000\n" +
"#global config for provider\n" +
"dubbo.protocol.port=20831\n" +
"dubbo.provider.id.timeout=5000";
"dubbo.protocol.port=20831\n";

if (Version.getIntVersion(Version.getVersion()) >= VERSION300) {
// dubbo 3.x
str += "dubbo.provider.timeout=5000\n";
// TODO compatible with 3.0 preview and dev branch, remove the following line after merging dubbo 3.0 config refactor pr
str += "dubbo.provider.my-provider.timeout=5000";
} else {
// compatible with dubbo 2.7.x
str += "dubbo.provider.my-provider.timeout=5000";
}

System.out.println(str);

try {
String path = "/dubbo/config/dubbo/dubbo.properties";
String path = GLOBAL_DUBBO_PROPERTIES_PATH;
if (client.checkExists().forPath(path) == null) {
client.create().creatingParentsIfNeeded().forPath(path);
}
@@ -78,7 +94,7 @@ public static void generateDubboPropertiesForConsumer() {
System.out.println(str);

try {
String path = "/dubbo/config/metadatareport-configcenter-consumer/dubbo.properties";
String path = CONSUMER_DUBBO_PROPERTIES_PATH;
if (client.checkExists().forPath(path) == null) {
client.create().creatingParentsIfNeeded().forPath(path);
}
@@ -95,7 +111,7 @@ public static void generateDubboPropertiesForProvider() {
System.out.println(str);

try {
String path = "/dubbo/config/metadatareport-configcenter-provider/dubbo.properties";
String path = PROVIDER_DUBBO_PROPERTIES_PATH;
if (client.checkExists().forPath(path) == null) {
client.create().creatingParentsIfNeeded().forPath(path);
}
@@ -141,12 +157,20 @@ private static String toRootDir(String root) {
return root + PATH_SEPARATOR;
}

private static void removeGlobalConfig() {
public static void removeDubboProperties() {
try {
client.delete().forPath("/dubbo/config/dubbo/dubbo.properties");
client.delete().forPath(GLOBAL_DUBBO_PROPERTIES_PATH);
client.delete().forPath(PROVIDER_DUBBO_PROPERTIES_PATH);
client.delete().forPath(CONSUMER_DUBBO_PROPERTIES_PATH);
client.delete().forPath(getParent(PROVIDER_DUBBO_PROPERTIES_PATH));
client.delete().forPath(getParent(CONSUMER_DUBBO_PROPERTIES_PATH));
} catch (Exception e) {
e.printStackTrace();
}
}

private static String getParent(String path) {
return path.substring(0, PROVIDER_DUBBO_PROPERTIES_PATH.lastIndexOf('/'));
}

}
@@ -24,6 +24,7 @@

import com.google.gson.Gson;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
@@ -36,6 +37,12 @@
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:/spring/metadata-consumer.xml"})
public class MetadataIT {

@BeforeClass
public static void beforeClass() {
//new EmbeddedZooKeeper(2181, false).start();
}

@Autowired
private DemoService demoService;

0 comments on commit e05f776

Please sign in to comment.