Skip to content

Commit

Permalink
fix migrationRule bug (#8358)
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoheng1 authored Jul 27, 2021
1 parent ffabb89 commit bfa4b3b
Showing 1 changed file with 23 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -68,9 +74,22 @@ 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<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() {
Expand Down

0 comments on commit bfa4b3b

Please sign in to comment.