Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix migrationRule bug #8358

Merged
merged 2 commits into from Jul 27, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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