From b3ce7c084384951643ea65a021428694aecfc299 Mon Sep 17 00:00:00 2001 From: xiaoheng1 <2018154970@qq.com> Date: Tue, 27 Jul 2021 15:58:00 +0800 Subject: [PATCH 1/2] fix migrationRule bug --- .../support/migration/MigrationRule.java | 26 ++++++++++++++++--- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/migration/MigrationRule.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/migration/MigrationRule.java index 92e34c42a0e..85da345df8f 100644 --- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/migration/MigrationRule.java +++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/migration/MigrationRule.java @@ -17,16 +17,22 @@ package org.apache.dubbo.rpc.cluster.support.migration; import org.apache.dubbo.common.config.configcenter.DynamicConfiguration; +import org.apache.dubbo.common.logger.Logger; +import org.apache.dubbo.common.logger.LoggerFactory; +import org.apache.dubbo.common.utils.PojoUtils; import org.apache.dubbo.common.utils.StringUtils; import org.apache.dubbo.rpc.model.ApplicationModel; import org.yaml.snakeyaml.Yaml; -import org.yaml.snakeyaml.constructor.Constructor; +import org.yaml.snakeyaml.constructor.SafeConstructor; +import java.util.Map; import java.util.Optional; import static org.apache.dubbo.common.constants.RegistryConstants.INIT; public class MigrationRule { + private static final Logger LOGGER = LoggerFactory.getLogger(MigrationRule.class); + private static final String DUBBO_SERVICEDISCOVERY_MIGRATION_KEY = "dubbo.application.service-discovery.migration"; public static final String DUBBO_SERVICEDISCOVERY_MIGRATION_GROUP = "MIGRATION"; public static final String RULE_KEY = ApplicationModel.getName() + ".migration"; @@ -68,9 +74,21 @@ public static MigrationRule parse(String rawRule) { } - Constructor constructor = new Constructor(MigrationRule.class); - Yaml yaml = new Yaml(constructor); - return yaml.load(rawRule); + Yaml yaml = new Yaml(new SafeConstructor()); + MigrationRule migrationRule = null; + try { + Map map = yaml.load(rawRule); + migrationRule = PojoUtils.mapToPojo(map, MigrationRule.class); + + if (null == migrationRule.getStep()) { + LOGGER.warn("Failed to parse migrationRule, step is empty, automatically switch to APPLICATION_FIRST."); + } + } catch (Exception e) { + LOGGER.error("Failed to parse migrationRule, automatically switch to APPLICATION_FIRST."); + migrationRule = getMigrationRule(null); + } + + return migrationRule; } public static MigrationRule queryRule() { From d27593a37abf9bd407262e9104656e0833194b14 Mon Sep 17 00:00:00 2001 From: xiaoheng1 <2018154970@qq.com> Date: Tue, 27 Jul 2021 16:00:02 +0800 Subject: [PATCH 2/2] Add a default policy --- .../dubbo/rpc/cluster/support/migration/MigrationRule.java | 1 + 1 file changed, 1 insertion(+) diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/migration/MigrationRule.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/migration/MigrationRule.java index 85da345df8f..95f427ff79b 100644 --- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/migration/MigrationRule.java +++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/migration/MigrationRule.java @@ -82,6 +82,7 @@ public static MigrationRule parse(String rawRule) { if (null == migrationRule.getStep()) { LOGGER.warn("Failed to parse migrationRule, step is empty, automatically switch to APPLICATION_FIRST."); + migrationRule = getMigrationRule(null); } } catch (Exception e) { LOGGER.error("Failed to parse migrationRule, automatically switch to APPLICATION_FIRST.");