diff --git a/dubbo-dependencies-bom/pom.xml b/dubbo-dependencies-bom/pom.xml
index 9c40c96914..0d9bea9e57 100644
--- a/dubbo-dependencies-bom/pom.xml
+++ b/dubbo-dependencies-bom/pom.xml
@@ -163,7 +163,7 @@
6.1.26
2.0
1.1.0
- 3.0.0-SNAPSHOT
+ 3.0.0-migration-SNAPSHOT
diff --git a/dubbo-dependencies/dubbo-dependencies-zookeeper/pom.xml b/dubbo-dependencies/dubbo-dependencies-zookeeper/pom.xml
index 1ff9f7f6ca..283e93b291 100644
--- a/dubbo-dependencies/dubbo-dependencies-zookeeper/pom.xml
+++ b/dubbo-dependencies/dubbo-dependencies-zookeeper/pom.xml
@@ -32,7 +32,7 @@
pom
- 3.0.0-SNAPSHOT
+ 3.0.0-migration-SNAPSHOT
1.1.0
diff --git a/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/MetadataInfo.java b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/MetadataInfo.java
index 4a9ea6ff61..e354784439 100644
--- a/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/MetadataInfo.java
+++ b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/MetadataInfo.java
@@ -340,13 +340,15 @@ public class MetadataInfo implements Serializable {
}
private String getMethodParameter(String method, String key, Map> map) {
- Map keyMap = map.get(method);
String value = null;
- if (keyMap != null) {
- value = keyMap.get(key);
- }
- if (StringUtils.isEmpty(value)) {
- value = getParameter(key);
+ if (map != null) {
+ Map keyMap = map.get(method);
+ if (keyMap != null) {
+ value = keyMap.get(key);
+ }
+ if (StringUtils.isEmpty(value)) {
+ value = getParameter(key);
+ }
}
return value;
}
diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/migration/DefaultMigrationAddressComparator.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/migration/DefaultMigrationAddressComparator.java
index a3f7c02c06..c7642afec8 100644
--- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/migration/DefaultMigrationAddressComparator.java
+++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/migration/DefaultMigrationAddressComparator.java
@@ -50,7 +50,11 @@ public class DefaultMigrationAddressComparator implements MigrationAddressCompar
int newAddressSize = CollectionUtils.isNotEmpty(invokers1) ? invokers1.size() : 0;
int oldAddressSize = CollectionUtils.isNotEmpty(invokers2) ? invokers2.size() : 0;
- String rawThreshold = rule.getThreshold(invoker.getUrl().getServiceKey());
+ String rawThreshold = null;
+ Float configedThreshold = rule == null ? null : rule.getThreshold(invoker.getUrl().getServiceKey());
+ if (configedThreshold != null) {
+ rawThreshold = String.valueOf(configedThreshold);
+ }
rawThreshold = StringUtils.isNotEmpty(rawThreshold) ? rawThreshold : ConfigurationUtils.getDynamicProperty(MIGRATION_THRESHOLD, DEFAULT_THRESHOLD_STRING);
float threshold;
try {
diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/migration/MigrationRuleHandler.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/migration/MigrationRuleHandler.java
index e2d3054c3d..7d4eae353d 100644
--- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/migration/MigrationRuleHandler.java
+++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/migration/MigrationRuleHandler.java
@@ -34,6 +34,7 @@ public class MigrationRuleHandler {
private MigrationClusterInvoker migrationInvoker;
private MigrationStep currentStep;
+ private Float currentThreshold = 0f;
private MigrationRule rule;
private URL consumerURL;
@@ -46,6 +47,7 @@ public class MigrationRuleHandler {
MigrationStep step = (migrationInvoker instanceof ServiceDiscoveryMigrationInvoker)
? MigrationStep.FORCE_APPLICATION
: MigrationStep.INTERFACE_FIRST;
+ Float threshold = 0f;
if (StringUtils.isEmpty(rawRule)) {
logger.error("Find empty migration rule, will ignore.");
return;
@@ -56,13 +58,14 @@ public class MigrationRuleHandler {
rule = MigrationRule.parse(rawRule);
setMigrationRule(rule);
step = rule.getStep(consumerURL.getServiceKey());
+ threshold = rule.getThreshold(consumerURL.getServiceKey());
} catch (Exception e) {
logger.error("Parse migration rule error, will use default step " + step, e);
}
}
- if (currentStep == null || currentStep != step) {
- setCurrentStep(step);
+ if ((currentStep == null || currentStep != step) || (!currentThreshold.equals(threshold))) {
+ setCurrentStepAndThreshold(step, threshold);
switch (step) {
case APPLICATION_FIRST:
migrationInvoker.migrateToServiceDiscoveryInvoker(false);
@@ -77,11 +80,13 @@ public class MigrationRuleHandler {
}
}
- public void setCurrentStep(MigrationStep currentStep) {
+ public void setCurrentStepAndThreshold(MigrationStep currentStep, Float currentThreshold) {
this.currentStep = currentStep;
+ this.currentThreshold = currentThreshold;
}
public void setMigrationRule(MigrationRule rule) {
this.migrationInvoker.setMigrationStep(currentStep);
+ this.migrationInvoker.setMigrationRule(rule);
}
}
diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/migration/model/InterfaceMigrationRule.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/migration/model/InterfaceMigrationRule.java
index 658248b878..99ec43f386 100644
--- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/migration/model/InterfaceMigrationRule.java
+++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/migration/model/InterfaceMigrationRule.java
@@ -19,7 +19,7 @@ package org.apache.dubbo.registry.client.migration.model;
public class InterfaceMigrationRule {
private String serviceKey;
private MigrationStep step;
- private String threshold;
+ private Float threshold;
public String getServiceKey() {
return serviceKey;
@@ -37,11 +37,11 @@ public class InterfaceMigrationRule {
this.step = step;
}
- public String getThreshold() {
+ public Float getThreshold() {
return threshold;
}
- public void setThreshold(String threshold) {
+ public void setThreshold(Float threshold) {
this.threshold = threshold;
}
}
diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/migration/model/MigrationRule.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/migration/model/MigrationRule.java
index a0aecf950b..13dffc31b4 100644
--- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/migration/model/MigrationRule.java
+++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/migration/model/MigrationRule.java
@@ -40,7 +40,7 @@ import java.util.Map;
public class MigrationRule {
private String key;
private MigrationStep step;
- private String threshold;
+ private Float threshold;
private List interfaces;
private transient Map interfaceRules;
@@ -54,14 +54,19 @@ public class MigrationRule {
}
public MigrationStep getStep(String serviceKey) {
- InterfaceMigrationRule rule = interfaceRules.get(serviceKey);
- if (rule != null) {
- return rule.getStep() == null ? step : rule.getStep();
+ if (interfaceRules != null) {
+ InterfaceMigrationRule rule = interfaceRules.get(serviceKey);
+ if (rule != null) {
+ return rule.getStep() == null ? step : rule.getStep();
+ }
}
return step;
}
public InterfaceMigrationRule getInterfaceRule(String serviceKey) {
+ if (interfaceRules == null) {
+ return null;
+ }
return interfaceRules.get(serviceKey);
}
@@ -69,19 +74,21 @@ public class MigrationRule {
return step;
}
- public String getThreshold(String serviceKey) {
- InterfaceMigrationRule rule = interfaceRules.get(serviceKey);
- if (rule != null) {
- return rule.getThreshold() == null ? threshold : rule.getThreshold();
+ public Float getThreshold(String serviceKey) {
+ if (interfaceRules != null) {
+ InterfaceMigrationRule rule = interfaceRules.get(serviceKey);
+ if (rule != null) {
+ return rule.getThreshold() == null ? threshold : rule.getThreshold();
+ }
}
return threshold;
}
- public String getThreshold() {
+ public Float getThreshold() {
return threshold;
}
- public void setThreshold(String threshold) {
+ public void setThreshold(Float threshold) {
this.threshold = threshold;
}
diff --git a/pom.xml b/pom.xml
index e2c22aa076..b2f4814f5c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -126,7 +126,7 @@
true
true
- 3.0.0-SNAPSHOT
+ 3.0.0-migration-SNAPSHOT