@@ -713,7 +713,7 @@ public boolean stop() {
713713
714714 @ Override
715715 @ DB
716- public String updateConfiguration (final long userId , final String name , final String category , String value , final String scope , final Long resourceId ) {
716+ public String updateConfiguration (final long userId , final String name , final String category , String value , ConfigKey . Scope scope , final Long resourceId ) {
717717 final String validationMsg = validateConfigurationValue (name , value , scope );
718718 if (validationMsg != null ) {
719719 logger .error ("Invalid value [{}] for configuration [{}] due to [{}]." , value , name , validationMsg );
@@ -724,15 +724,14 @@ public String updateConfiguration(final long userId, final String name, final St
724724 // corresponding details table,
725725 // if scope is mentioned as global or not mentioned then it is normal
726726 // global parameter updation
727- if (scope != null && !scope . isEmpty () && ! ConfigKey .Scope .Global .toString (). equalsIgnoreCase (scope )) {
727+ if (scope != null && !ConfigKey .Scope .Global .equals (scope )) {
728728 boolean valueEncrypted = shouldEncryptValue (category );
729729 if (valueEncrypted ) {
730730 value = DBEncryptionUtil .encrypt (value );
731731 }
732732
733733 ApiCommandResourceType resourceType ;
734- ConfigKey .Scope scopeVal = ConfigKey .Scope .valueOf (scope );
735- switch (scopeVal ) {
734+ switch (scope ) {
736735 case Zone :
737736 final DataCenterVO zone = _zoneDao .findById (resourceId );
738737 if (zone == null ) {
@@ -831,9 +830,9 @@ public String updateConfiguration(final long userId, final String name, final St
831830
832831 CallContext .current ().setEventResourceType (resourceType );
833832 CallContext .current ().setEventResourceId (resourceId );
834- CallContext .current ().setEventDetails (String .format (" Name: %s, New Value: %s, Scope: %s" , name , value , scope ));
833+ CallContext .current ().setEventDetails (String .format (" Name: %s, New Value: %s, Scope: %s" , name , value , scope . name () ));
835834
836- _configDepot .invalidateConfigCache (name , scopeVal , resourceId );
835+ _configDepot .invalidateConfigCache (name , scope , resourceId );
837836 return valueEncrypted ? DBEncryptionUtil .decrypt (value ) : value ;
838837 }
839838
@@ -999,40 +998,40 @@ public Configuration updateConfiguration(final UpdateCfgCmd cmd) throws InvalidP
999998 return _configDao .findByName (name );
1000999 }
10011000
1002- String scope = null ;
1001+ ConfigKey . Scope scope = null ;
10031002 Long id = null ;
10041003 int paramCountCheck = 0 ;
10051004
10061005 if (zoneId != null ) {
1007- scope = ConfigKey .Scope .Zone . toString () ;
1006+ scope = ConfigKey .Scope .Zone ;
10081007 id = zoneId ;
10091008 paramCountCheck ++;
10101009 }
10111010 if (clusterId != null ) {
1012- scope = ConfigKey .Scope .Cluster . toString () ;
1011+ scope = ConfigKey .Scope .Cluster ;
10131012 id = clusterId ;
10141013 paramCountCheck ++;
10151014 }
10161015 if (accountId != null ) {
10171016 Account account = _accountMgr .getAccount (accountId );
10181017 _accountMgr .checkAccess (caller , null , false , account );
1019- scope = ConfigKey .Scope .Account . toString () ;
1018+ scope = ConfigKey .Scope .Account ;
10201019 id = accountId ;
10211020 paramCountCheck ++;
10221021 }
10231022 if (domainId != null ) {
10241023 _accountMgr .checkAccess (caller , _domainDao .findById (domainId ));
1025- scope = ConfigKey .Scope .Domain . toString () ;
1024+ scope = ConfigKey .Scope .Domain ;
10261025 id = domainId ;
10271026 paramCountCheck ++;
10281027 }
10291028 if (storagepoolId != null ) {
1030- scope = ConfigKey .Scope .StoragePool . toString () ;
1029+ scope = ConfigKey .Scope .StoragePool ;
10311030 id = storagepoolId ;
10321031 paramCountCheck ++;
10331032 }
10341033 if (imageStoreId != null ) {
1035- scope = ConfigKey .Scope .ImageStore . toString () ;
1034+ scope = ConfigKey .Scope .ImageStore ;
10361035 id = imageStoreId ;
10371036 paramCountCheck ++;
10381037 }
@@ -1046,8 +1045,15 @@ public Configuration updateConfiguration(final UpdateCfgCmd cmd) throws InvalidP
10461045 if (value .isEmpty () || value .equals ("null" )) {
10471046 value = (id == null ) ? null : "" ;
10481047 }
1048+
1049+ String currentValueInScope = getConfigurationValueInScope (config , name , scope , id );
10491050 final String updatedValue = updateConfiguration (userId , name , category , value , scope , id );
10501051 if (value == null && updatedValue == null || updatedValue .equalsIgnoreCase (value )) {
1052+ logger .debug ("Config: {} value is updated from: {} to {} for scope: {}" , name ,
1053+ encryptEventValueIfConfigIsEncrypted (config , currentValueInScope ),
1054+ encryptEventValueIfConfigIsEncrypted (config , value ),
1055+ scope != null ? scope : ConfigKey .Scope .Global .name ());
1056+
10511057 return _configDao .findByName (name );
10521058 } else {
10531059 throw new CloudRuntimeException ("Unable to update configuration parameter " + name );
@@ -1109,7 +1115,7 @@ public Pair<Configuration, String> resetConfiguration(final ResetCfgCmd cmd) thr
11091115 configScope = config .getScopes ();
11101116 }
11111117
1112- String scope = "" ;
1118+ String scopeVal = "" ;
11131119 Map <String , Long > scopeMap = new LinkedHashMap <>();
11141120
11151121 Long id = null ;
@@ -1125,22 +1131,23 @@ public Pair<Configuration, String> resetConfiguration(final ResetCfgCmd cmd) thr
11251131 ParamCountPair paramCountPair = getParamCount (scopeMap );
11261132 id = paramCountPair .getId ();
11271133 paramCountCheck = paramCountPair .getParamCount ();
1128- scope = paramCountPair .getScope ();
1134+ scopeVal = paramCountPair .getScope ();
11291135
11301136 if (paramCountCheck > 1 ) {
11311137 throw new InvalidParameterValueException ("cannot handle multiple IDs, provide only one ID corresponding to the scope" );
11321138 }
11331139
1134- if (scope != null ) {
1135- ConfigKey .Scope scopeVal = ConfigKey .Scope .valueOf (scope );
1136- if (!scope .equals (ConfigKey .Scope .Global .toString ()) && !configScope .contains (scopeVal )) {
1140+ if (scopeVal != null ) {
1141+ ConfigKey .Scope scope = ConfigKey .Scope .valueOf (scopeVal );
1142+ if (!scopeVal .equals (ConfigKey .Scope .Global .toString ()) && !configScope .contains (scope )) {
11371143 throw new InvalidParameterValueException ("Invalid scope id provided for the parameter " + name );
11381144 }
11391145 }
11401146
11411147 String newValue = null ;
1142- ConfigKey .Scope scopeVal = ConfigKey .Scope .valueOf (scope );
1143- switch (scopeVal ) {
1148+ ConfigKey .Scope scope = ConfigKey .Scope .valueOf (scopeVal );
1149+ String currentValueInScope = getConfigurationValueInScope (config , name , scope , id );
1150+ switch (scope ) {
11441151 case Zone :
11451152 final DataCenterVO zone = _zoneDao .findById (id );
11461153 if (zone == null ) {
@@ -1225,20 +1232,36 @@ public Pair<Configuration, String> resetConfiguration(final ResetCfgCmd cmd) thr
12251232 newValue = optionalValue .isPresent () ? optionalValue .get ().toString () : defaultValue ;
12261233 }
12271234
1228- _configDepot .invalidateConfigCache (name , scopeVal , id );
1235+ logger .debug ("Config: {} value is updated from: {} to {} for scope: {}" , name ,
1236+ encryptEventValueIfConfigIsEncrypted (config , currentValueInScope ),
1237+ encryptEventValueIfConfigIsEncrypted (config , newValue ), scope );
1238+
1239+ _configDepot .invalidateConfigCache (name , scope , id );
12291240
12301241 CallContext .current ().setEventDetails (" Name: " + name + " New Value: " + (name .toLowerCase ().contains ("password" ) ? "*****" : defaultValue == null ? "" : defaultValue ));
12311242 return new Pair <Configuration , String >(_configDao .findByName (name ), newValue );
12321243 }
12331244
1245+ private String getConfigurationValueInScope (ConfigurationVO config , String name , ConfigKey .Scope scope , Long id ) {
1246+ String configValue ;
1247+ if (scope == null || ConfigKey .Scope .Global .equals (scope )) {
1248+ configValue = config .getValue ();
1249+ } else {
1250+ ConfigKey <?> configKey = _configDepot .get (name );
1251+ Object currentValue = configKey .valueInScope (scope , id );
1252+ configValue = currentValue != null ? currentValue .toString () : null ;
1253+ }
1254+ return configValue ;
1255+ }
1256+
12341257 /**
12351258 * Validates whether a value is valid for the specified configuration. This includes type and range validation.
12361259 * @param name name of the configuration.
12371260 * @param value value to validate.
12381261 * @param scope scope of the configuration.
12391262 * @return null if the value is valid; otherwise, returns an error message.
12401263 */
1241- protected String validateConfigurationValue (String name , String value , String scope ) {
1264+ protected String validateConfigurationValue (String name , String value , ConfigKey . Scope scope ) {
12421265 final ConfigurationVO cfg = _configDao .findByName (name );
12431266 if (cfg == null ) {
12441267 logger .error ("Missing configuration variable " + name + " in configuration table" );
@@ -1248,10 +1271,9 @@ protected String validateConfigurationValue(String name, String value, String sc
12481271
12491272 List <ConfigKey .Scope > configScope = cfg .getScopes ();
12501273 if (scope != null ) {
1251- ConfigKey .Scope scopeVal = ConfigKey .Scope .valueOf (scope );
1252- if (!configScope .contains (scopeVal ) &&
1274+ if (!configScope .contains (scope ) &&
12531275 !(ENABLE_ACCOUNT_SETTINGS_FOR_DOMAIN .value () && configScope .contains (ConfigKey .Scope .Account ) &&
1254- scope . equals ( ConfigKey .Scope .Domain .toString () ))) {
1276+ ConfigKey .Scope .Domain .equals ( scope ))) {
12551277 logger .error ("Invalid scope id provided for the parameter " + name );
12561278 return "Invalid scope id provided for the parameter " + name ;
12571279 }
0 commit comments