api: Fix reset configuration (#6168)

This commit is contained in:
Pearl Dsilva 2022-03-29 13:24:34 +05:30 committed by GitHub
parent f4b9ab034b
commit bcd1a3274a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -914,15 +914,26 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
final Long accountId = cmd.getAccountId(); final Long accountId = cmd.getAccountId();
final Long domainId = cmd.getDomainId(); final Long domainId = cmd.getDomainId();
final Long imageStoreId = cmd.getImageStoreId(); final Long imageStoreId = cmd.getImageStoreId();
ConfigKey<?> configKey = null;
Optional optionalValue; Optional optionalValue;
final ConfigKey<?> configKey = _configDepot.get(name); String defaultValue;
if (configKey == null) { String category;
s_logger.warn("Probably the component manager where configuration variable " + name + " is defined needs to implement Configurable interface"); String configScope;
throw new InvalidParameterValueException("Config parameter with name " + name + " doesn't exist"); final ConfigurationVO config = _configDao.findByName(name);
if (config == null) {
configKey = _configDepot.get(name);
if (configKey == null) {
s_logger.warn("Probably the component manager where configuration variable " + name + " is defined needs to implement Configurable interface");
throw new InvalidParameterValueException("Config parameter with name " + name + " doesn't exist");
}
defaultValue = configKey.defaultValue();
category = configKey.category();
configScope = configKey.scope().toString();
} else {
defaultValue = config.getDefaultValue();
category = config.getCategory();
configScope = config.getScope();
} }
String defaultValue = configKey.defaultValue();
String category = configKey.category();
String configScope = configKey.scope().toString();
String scope = ""; String scope = "";
Map<String, Long> scopeMap = new LinkedHashMap<>(); Map<String, Long> scopeMap = new LinkedHashMap<>();
@ -958,7 +969,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
throw new InvalidParameterValueException("unable to find zone by id " + id); throw new InvalidParameterValueException("unable to find zone by id " + id);
} }
_dcDetailsDao.removeDetail(id, name); _dcDetailsDao.removeDetail(id, name);
optionalValue = Optional.ofNullable(configKey.valueIn(id)); optionalValue = Optional.ofNullable(configKey != null ? configKey.valueIn(id): config.getValue());
newValue = optionalValue.isPresent() ? optionalValue.get().toString() : defaultValue; newValue = optionalValue.isPresent() ? optionalValue.get().toString() : defaultValue;
break; break;
@ -968,13 +979,13 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
throw new InvalidParameterValueException("unable to find cluster by id " + id); throw new InvalidParameterValueException("unable to find cluster by id " + id);
} }
ClusterDetailsVO clusterDetailsVO = _clusterDetailsDao.findDetail(id, name); ClusterDetailsVO clusterDetailsVO = _clusterDetailsDao.findDetail(id, name);
newValue = configKey.value().toString(); newValue = configKey != null ? configKey.value().toString() : config.getValue();
if (name.equalsIgnoreCase("cpu.overprovisioning.factor") || name.equalsIgnoreCase("mem.overprovisioning.factor")) { if (name.equalsIgnoreCase("cpu.overprovisioning.factor") || name.equalsIgnoreCase("mem.overprovisioning.factor")) {
_clusterDetailsDao.persist(id, name, newValue); _clusterDetailsDao.persist(id, name, newValue);
} else if (clusterDetailsVO != null) { } else if (clusterDetailsVO != null) {
_clusterDetailsDao.remove(clusterDetailsVO.getId()); _clusterDetailsDao.remove(clusterDetailsVO.getId());
} }
optionalValue = Optional.ofNullable(configKey.valueIn(id)); optionalValue = Optional.ofNullable(configKey != null ? configKey.valueIn(id): config.getValue());
newValue = optionalValue.isPresent() ? optionalValue.get().toString() : defaultValue; newValue = optionalValue.isPresent() ? optionalValue.get().toString() : defaultValue;
break; break;
@ -984,7 +995,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
throw new InvalidParameterValueException("unable to find storage pool by id " + id); throw new InvalidParameterValueException("unable to find storage pool by id " + id);
} }
_storagePoolDetailsDao.removeDetail(id, name); _storagePoolDetailsDao.removeDetail(id, name);
optionalValue = Optional.ofNullable(configKey.valueIn(id)); optionalValue = Optional.ofNullable(configKey != null ? configKey.valueIn(id) : config.getValue());
newValue = optionalValue.isPresent() ? optionalValue.get().toString() : defaultValue; newValue = optionalValue.isPresent() ? optionalValue.get().toString() : defaultValue;
break; break;
@ -997,7 +1008,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
if (domainDetailVO != null) { if (domainDetailVO != null) {
_domainDetailsDao.remove(domainDetailVO.getId()); _domainDetailsDao.remove(domainDetailVO.getId());
} }
optionalValue = Optional.ofNullable(configKey.valueIn(id)); optionalValue = Optional.ofNullable(configKey != null ? configKey.valueIn(id) : config.getValue());
newValue = optionalValue.isPresent() ? optionalValue.get().toString() : defaultValue; newValue = optionalValue.isPresent() ? optionalValue.get().toString() : defaultValue;
break; break;
@ -1010,7 +1021,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
if (accountDetailVO != null) { if (accountDetailVO != null) {
_accountDetailsDao.remove(accountDetailVO.getId()); _accountDetailsDao.remove(accountDetailVO.getId());
} }
optionalValue = Optional.ofNullable(configKey.valueIn(id)); optionalValue = Optional.ofNullable(configKey != null ? configKey.valueIn(id) : config.getValue());
newValue = optionalValue.isPresent() ? optionalValue.get().toString() : defaultValue; newValue = optionalValue.isPresent() ? optionalValue.get().toString() : defaultValue;
break; break;
@ -1023,7 +1034,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
if (imageStoreDetailVO != null) { if (imageStoreDetailVO != null) {
_imageStoreDetailsDao.remove(imageStoreDetailVO.getId()); _imageStoreDetailsDao.remove(imageStoreDetailVO.getId());
} }
optionalValue = Optional.ofNullable(configKey.valueIn(id)); optionalValue = Optional.ofNullable(configKey != null ? configKey.valueIn(id) : config.getValue());
newValue = optionalValue.isPresent() ? optionalValue.get().toString() : defaultValue; newValue = optionalValue.isPresent() ? optionalValue.get().toString() : defaultValue;
break; break;
@ -1032,7 +1043,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
s_logger.error("Failed to reset configuration option, name: " + name + ", defaultValue:" + defaultValue); s_logger.error("Failed to reset configuration option, name: " + name + ", defaultValue:" + defaultValue);
throw new CloudRuntimeException("Failed to reset configuration value. Please contact Cloud Support."); throw new CloudRuntimeException("Failed to reset configuration value. Please contact Cloud Support.");
} }
optionalValue = Optional.ofNullable(configKey.value()); optionalValue = Optional.ofNullable(configKey != null ? configKey.value() : config.getValue());
newValue = optionalValue.isPresent() ? optionalValue.get().toString() : defaultValue; newValue = optionalValue.isPresent() ? optionalValue.get().toString() : defaultValue;
} }