You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by li...@apache.org on 2021/07/27 10:25:07 UTC

[dubbo] branch master updated: fix migrationRule bug (#8358)

This is an automated email from the ASF dual-hosted git repository.

liujun pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/dubbo.git


The following commit(s) were added to refs/heads/master by this push:
     new bfa4b3b  fix migrationRule bug (#8358)
bfa4b3b is described below

commit bfa4b3bb6660d404c0715f54f8743dda45b46909
Author: xiaoheng1 <20...@qq.com>
AuthorDate: Tue Jul 27 18:24:54 2021 +0800

    fix migrationRule bug (#8358)
---
 .../cluster/support/migration/MigrationRule.java   | 27 ++++++++++++++++++----
 1 file changed, 23 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 92e34c4..95f427f 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,22 @@ public class MigrationRule {
 
         }
 
-        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<String, Object> 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.");
+                migrationRule = getMigrationRule(null);
+            }
+        } catch (Exception e) {
+            LOGGER.error("Failed to parse migrationRule, automatically switch to APPLICATION_FIRST.");
+            migrationRule = getMigrationRule(null);
+        }
+
+        return migrationRule;
     }
 
     public static MigrationRule queryRule() {