ravening commented on a change in pull request #4230:
URL: https://github.com/apache/cloudstack/pull/4230#discussion_r712073453
##########
File path:
server/src/main/java/com/cloud/configuration/ConfigurationManagerImpl.java
##########
@@ -851,6 +861,161 @@ public Configuration updateConfiguration(final
UpdateCfgCmd cmd) throws InvalidP
}
}
+ @Override
+ @ActionEvent(eventType = EventTypes.EVENT_CONFIGURATION_VALUE_EDIT,
eventDescription = "resetting configuration")
+ public Pair<Configuration, String> resetConfiguration(final ResetCfgCmd
cmd) throws InvalidParameterValueException {
+ final Long userId = CallContext.current().getCallingUserId();
+ final String name = cmd.getCfgName();
+ final Long zoneId = cmd.getZoneId();
+ final Long clusterId = cmd.getClusterId();
+ final Long storagepoolId = cmd.getStoragepoolId();
+ final Long accountId = cmd.getAccountId();
+ final Long domainId = cmd.getDomainId();
+ final Long imageStoreId = cmd.getImageStoreId();
+ Optional optionalValue;
+ final ConfigKey<?> 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");
+ }
+ String defaultValue = configKey.defaultValue();
+ String category = configKey.category();
+ String configScope = configKey.scope().toString();
+
+ String scope = ConfigKey.Scope.Global.toString();
+
+ Long id = null;
+ int paramCountCheck = 0;
+
+ if (zoneId != null) {
+ scope = ConfigKey.Scope.Zone.toString();
+ id = zoneId;
+ paramCountCheck++;
+ }
+ if (clusterId != null) {
+ scope = ConfigKey.Scope.Cluster.toString();
+ id = clusterId;
+ paramCountCheck++;
+ }
+ if (domainId != null) {
+ scope = ConfigKey.Scope.Domain.toString();
+ id = domainId;
+ paramCountCheck++;
+ }
+ if (accountId != null) {
+ scope = ConfigKey.Scope.Account.toString();
+ id = accountId;
+ paramCountCheck++;
+ }
+ if (storagepoolId != null) {
+ scope = ConfigKey.Scope.StoragePool.toString();
+ id = storagepoolId;
+ paramCountCheck++;
+ }
+ if (imageStoreId != null) {
+ scope = ConfigKey.Scope.ImageStore.toString();
+ id = imageStoreId;
+ paramCountCheck++;
+ }
+
+ if (paramCountCheck > 1) {
+ throw new InvalidParameterValueException("cannot handle multiple
IDs, provide only one ID corresponding to the scope");
+ }
+
+ if (scope != null && !scope.equals(ConfigKey.Scope.Global.toString())
&& !configScope.contains(scope)) {
+ throw new InvalidParameterValueException("Invalid scope id
provided for the parameter " + name);
+ }
+
+ String newValue = null;
+ switch (ConfigKey.Scope.valueOf(scope)) {
+ case Zone:
+ final DataCenterVO zone = _zoneDao.findById(id);
+ if (zone == null) {
+ throw new InvalidParameterValueException("unable to find
zone by id " + id);
+ }
+ _dcDetailsDao.removeDetail(id, name);
+ optionalValue = Optional.ofNullable(configKey.valueIn(id));
+ newValue = optionalValue.isPresent() ?
optionalValue.get().toString() : defaultValue;
+ break;
+
+ case Cluster:
+ final ClusterVO cluster = _clusterDao.findById(id);
+ if (cluster == null) {
+ throw new InvalidParameterValueException("unable to find
cluster by id " + id);
+ }
+ ClusterDetailsVO clusterDetailsVO =
_clusterDetailsDao.findDetail(id, name);
+ newValue = configKey.value().toString();
+ if (name.equalsIgnoreCase("cpu.overprovisioning.factor") ||
name.equalsIgnoreCase("mem.overprovisioning.factor")) {
+ _clusterDetailsDao.persist(id, name, newValue);
+ } else if (clusterDetailsVO != null) {
+ _clusterDetailsDao.remove(clusterDetailsVO.getId());
+ }
+ optionalValue = Optional.ofNullable(configKey.valueIn(id));
+ newValue = optionalValue.isPresent() ?
optionalValue.get().toString() : defaultValue;
+ break;
+
+ case StoragePool:
+ final StoragePoolVO pool = _storagePoolDao.findById(id);
+ if (pool == null) {
+ throw new InvalidParameterValueException("unable to find
storage pool by id " + id);
+ }
+ _storagePoolDetailsDao.removeDetail(id, name);
+ optionalValue = Optional.ofNullable(configKey.valueIn(id));
+ newValue = optionalValue.isPresent() ?
optionalValue.get().toString() : defaultValue;
+ break;
+
+ case Domain:
+ final DomainVO domain = _domainDao.findById(id);
+ if (domain == null) {
+ throw new InvalidParameterValueException("unable to find
domain by id " + id);
+ }
+ DomainDetailVO domainDetailVO =
_domainDetailsDao.findDetail(id, name);
+ if (domainDetailVO != null) {
+ _domainDetailsDao.remove(domainDetailVO.getId());
+ }
+ optionalValue =
Optional.ofNullable(configKey.valueInDomain(id));
Review comment:
@weizhouapache yes because, few part of the code are present in another
pr
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]