enhance migration rule (#6890)
This commit is contained in:
parent
585694e3cf
commit
846cc2a2b6
|
|
@ -163,7 +163,7 @@
|
|||
<mortbay_jetty_version>6.1.26</mortbay_jetty_version>
|
||||
<portlet_version>2.0</portlet_version>
|
||||
<maven_flatten_version>1.1.0</maven_flatten_version>
|
||||
<revision>3.0.0-SNAPSHOT</revision>
|
||||
<revision>3.0.0-migration-SNAPSHOT</revision>
|
||||
</properties>
|
||||
|
||||
<dependencyManagement>
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@
|
|||
<packaging>pom</packaging>
|
||||
|
||||
<properties>
|
||||
<revision>3.0.0-SNAPSHOT</revision>
|
||||
<revision>3.0.0-migration-SNAPSHOT</revision>
|
||||
<maven_flatten_version>1.1.0</maven_flatten_version>
|
||||
</properties>
|
||||
|
||||
|
|
|
|||
|
|
@ -340,13 +340,15 @@ public class MetadataInfo implements Serializable {
|
|||
}
|
||||
|
||||
private String getMethodParameter(String method, String key, Map<String, Map<String, String>> map) {
|
||||
Map<String, String> 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<String, String> keyMap = map.get(method);
|
||||
if (keyMap != null) {
|
||||
value = keyMap.get(key);
|
||||
}
|
||||
if (StringUtils.isEmpty(value)) {
|
||||
value = getParameter(key);
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@ public class MigrationRuleHandler<T> {
|
|||
|
||||
private MigrationClusterInvoker<T> migrationInvoker;
|
||||
private MigrationStep currentStep;
|
||||
private Float currentThreshold = 0f;
|
||||
private MigrationRule rule;
|
||||
private URL consumerURL;
|
||||
|
||||
|
|
@ -46,6 +47,7 @@ public class MigrationRuleHandler<T> {
|
|||
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<T> {
|
|||
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<T> {
|
|||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<InterfaceMigrationRule> interfaces;
|
||||
|
||||
private transient Map<String, InterfaceMigrationRule> 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;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue