Fix NPE in CB Config Resolution

This commit is contained in:
Atri Sharma 2020-08-27 20:52:12 +05:30
parent 6a7da3cd50
commit b381595f55
1 changed files with 14 additions and 8 deletions

View File

@ -137,7 +137,8 @@ public class CircuitBreakerManager implements PluginInfoInitialized {
*/
@SuppressWarnings({"rawtypes"})
public static CircuitBreakerManager build(PluginInfo pluginInfo) {
CircuitBreakerManager circuitBreakerManager = new CircuitBreakerManager(Boolean.parseBoolean(pluginInfo.attributes.get("enabled")));
boolean enabled = pluginInfo == null ? false : Boolean.parseBoolean(pluginInfo.attributes.getOrDefault("enabled", "false"));
CircuitBreakerManager circuitBreakerManager = new CircuitBreakerManager(enabled);
circuitBreakerManager.init(pluginInfo);
@ -147,19 +148,24 @@ public class CircuitBreakerManager implements PluginInfoInitialized {
@VisibleForTesting
@SuppressWarnings({"rawtypes"})
public static CircuitBreaker.CircuitBreakerConfig buildCBConfig(PluginInfo pluginInfo) {
boolean enabled = Boolean.parseBoolean(pluginInfo.attributes.get("enabled"));
boolean enabled = false;
boolean cpuCBEnabled = false;
boolean memCBEnabled = false;
int memCBThreshold = 100;
int cpuCBThreshold = 100;
NamedList args = pluginInfo.initArgs;
if (args != null) {
cpuCBEnabled = args.getBooleanArg("cpuEnabled");
memCBEnabled = args.getBooleanArg("memEnabled");
memCBThreshold = Integer.parseInt((String) args.get("memThreshold"));
cpuCBThreshold = Integer.parseInt((String) args.get("cpuThreshold"));
if (pluginInfo != null) {
NamedList args = pluginInfo.initArgs;
enabled = Boolean.parseBoolean(pluginInfo.attributes.getOrDefault("enabled", "false"));
if (args != null) {
cpuCBEnabled = Boolean.parseBoolean(args._getStr("cpuEnabled", "false"));
memCBEnabled = Boolean.parseBoolean(args._getStr("memEnabled", "false"));
memCBThreshold = Integer.parseInt(args._getStr("memThreshold", "100"));
cpuCBThreshold = Integer.parseInt(args._getStr("cpuThreshold", "100"));
}
}
return new CircuitBreaker.CircuitBreakerConfig(enabled, memCBEnabled, memCBThreshold, cpuCBEnabled, cpuCBThreshold);