@@ -713,7 +713,7 @@ public boolean stop() {
713
713
714
714
@ Override
715
715
@ 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 ) {
717
717
final String validationMsg = validateConfigurationValue (name , value , scope );
718
718
if (validationMsg != null ) {
719
719
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
724
724
// corresponding details table,
725
725
// if scope is mentioned as global or not mentioned then it is normal
726
726
// global parameter updation
727
- if (scope != null && !scope . isEmpty () && ! ConfigKey .Scope .Global .toString (). equalsIgnoreCase (scope )) {
727
+ if (scope != null && !ConfigKey .Scope .Global .equals (scope )) {
728
728
boolean valueEncrypted = shouldEncryptValue (category );
729
729
if (valueEncrypted ) {
730
730
value = DBEncryptionUtil .encrypt (value );
731
731
}
732
732
733
733
ApiCommandResourceType resourceType ;
734
- ConfigKey .Scope scopeVal = ConfigKey .Scope .valueOf (scope );
735
- switch (scopeVal ) {
734
+ switch (scope ) {
736
735
case Zone :
737
736
final DataCenterVO zone = _zoneDao .findById (resourceId );
738
737
if (zone == null ) {
@@ -831,9 +830,9 @@ public String updateConfiguration(final long userId, final String name, final St
831
830
832
831
CallContext .current ().setEventResourceType (resourceType );
833
832
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 () ));
835
834
836
- _configDepot .invalidateConfigCache (name , scopeVal , resourceId );
835
+ _configDepot .invalidateConfigCache (name , scope , resourceId );
837
836
return valueEncrypted ? DBEncryptionUtil .decrypt (value ) : value ;
838
837
}
839
838
@@ -999,40 +998,40 @@ public Configuration updateConfiguration(final UpdateCfgCmd cmd) throws InvalidP
999
998
return _configDao .findByName (name );
1000
999
}
1001
1000
1002
- String scope = null ;
1001
+ ConfigKey . Scope scope = null ;
1003
1002
Long id = null ;
1004
1003
int paramCountCheck = 0 ;
1005
1004
1006
1005
if (zoneId != null ) {
1007
- scope = ConfigKey .Scope .Zone . toString () ;
1006
+ scope = ConfigKey .Scope .Zone ;
1008
1007
id = zoneId ;
1009
1008
paramCountCheck ++;
1010
1009
}
1011
1010
if (clusterId != null ) {
1012
- scope = ConfigKey .Scope .Cluster . toString () ;
1011
+ scope = ConfigKey .Scope .Cluster ;
1013
1012
id = clusterId ;
1014
1013
paramCountCheck ++;
1015
1014
}
1016
1015
if (accountId != null ) {
1017
1016
Account account = _accountMgr .getAccount (accountId );
1018
1017
_accountMgr .checkAccess (caller , null , false , account );
1019
- scope = ConfigKey .Scope .Account . toString () ;
1018
+ scope = ConfigKey .Scope .Account ;
1020
1019
id = accountId ;
1021
1020
paramCountCheck ++;
1022
1021
}
1023
1022
if (domainId != null ) {
1024
1023
_accountMgr .checkAccess (caller , _domainDao .findById (domainId ));
1025
- scope = ConfigKey .Scope .Domain . toString () ;
1024
+ scope = ConfigKey .Scope .Domain ;
1026
1025
id = domainId ;
1027
1026
paramCountCheck ++;
1028
1027
}
1029
1028
if (storagepoolId != null ) {
1030
- scope = ConfigKey .Scope .StoragePool . toString () ;
1029
+ scope = ConfigKey .Scope .StoragePool ;
1031
1030
id = storagepoolId ;
1032
1031
paramCountCheck ++;
1033
1032
}
1034
1033
if (imageStoreId != null ) {
1035
- scope = ConfigKey .Scope .ImageStore . toString () ;
1034
+ scope = ConfigKey .Scope .ImageStore ;
1036
1035
id = imageStoreId ;
1037
1036
paramCountCheck ++;
1038
1037
}
@@ -1046,8 +1045,15 @@ public Configuration updateConfiguration(final UpdateCfgCmd cmd) throws InvalidP
1046
1045
if (value .isEmpty () || value .equals ("null" )) {
1047
1046
value = (id == null ) ? null : "" ;
1048
1047
}
1048
+
1049
+ String currentValueInScope = getConfigurationValueInScope (config , name , scope , id );
1049
1050
final String updatedValue = updateConfiguration (userId , name , category , value , scope , id );
1050
1051
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
+
1051
1057
return _configDao .findByName (name );
1052
1058
} else {
1053
1059
throw new CloudRuntimeException ("Unable to update configuration parameter " + name );
@@ -1109,7 +1115,7 @@ public Pair<Configuration, String> resetConfiguration(final ResetCfgCmd cmd) thr
1109
1115
configScope = config .getScopes ();
1110
1116
}
1111
1117
1112
- String scope = "" ;
1118
+ String scopeVal = "" ;
1113
1119
Map <String , Long > scopeMap = new LinkedHashMap <>();
1114
1120
1115
1121
Long id = null ;
@@ -1125,22 +1131,23 @@ public Pair<Configuration, String> resetConfiguration(final ResetCfgCmd cmd) thr
1125
1131
ParamCountPair paramCountPair = getParamCount (scopeMap );
1126
1132
id = paramCountPair .getId ();
1127
1133
paramCountCheck = paramCountPair .getParamCount ();
1128
- scope = paramCountPair .getScope ();
1134
+ scopeVal = paramCountPair .getScope ();
1129
1135
1130
1136
if (paramCountCheck > 1 ) {
1131
1137
throw new InvalidParameterValueException ("cannot handle multiple IDs, provide only one ID corresponding to the scope" );
1132
1138
}
1133
1139
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 )) {
1137
1143
throw new InvalidParameterValueException ("Invalid scope id provided for the parameter " + name );
1138
1144
}
1139
1145
}
1140
1146
1141
1147
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 ) {
1144
1151
case Zone :
1145
1152
final DataCenterVO zone = _zoneDao .findById (id );
1146
1153
if (zone == null ) {
@@ -1225,20 +1232,36 @@ public Pair<Configuration, String> resetConfiguration(final ResetCfgCmd cmd) thr
1225
1232
newValue = optionalValue .isPresent () ? optionalValue .get ().toString () : defaultValue ;
1226
1233
}
1227
1234
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 );
1229
1240
1230
1241
CallContext .current ().setEventDetails (" Name: " + name + " New Value: " + (name .toLowerCase ().contains ("password" ) ? "*****" : defaultValue == null ? "" : defaultValue ));
1231
1242
return new Pair <Configuration , String >(_configDao .findByName (name ), newValue );
1232
1243
}
1233
1244
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
+
1234
1257
/**
1235
1258
* Validates whether a value is valid for the specified configuration. This includes type and range validation.
1236
1259
* @param name name of the configuration.
1237
1260
* @param value value to validate.
1238
1261
* @param scope scope of the configuration.
1239
1262
* @return null if the value is valid; otherwise, returns an error message.
1240
1263
*/
1241
- protected String validateConfigurationValue (String name , String value , String scope ) {
1264
+ protected String validateConfigurationValue (String name , String value , ConfigKey . Scope scope ) {
1242
1265
final ConfigurationVO cfg = _configDao .findByName (name );
1243
1266
if (cfg == null ) {
1244
1267
logger .error ("Missing configuration variable " + name + " in configuration table" );
@@ -1248,10 +1271,9 @@ protected String validateConfigurationValue(String name, String value, String sc
1248
1271
1249
1272
List <ConfigKey .Scope > configScope = cfg .getScopes ();
1250
1273
if (scope != null ) {
1251
- ConfigKey .Scope scopeVal = ConfigKey .Scope .valueOf (scope );
1252
- if (!configScope .contains (scopeVal ) &&
1274
+ if (!configScope .contains (scope ) &&
1253
1275
!(ENABLE_ACCOUNT_SETTINGS_FOR_DOMAIN .value () && configScope .contains (ConfigKey .Scope .Account ) &&
1254
- scope . equals ( ConfigKey .Scope .Domain .toString () ))) {
1276
+ ConfigKey .Scope .Domain .equals ( scope ))) {
1255
1277
logger .error ("Invalid scope id provided for the parameter " + name );
1256
1278
return "Invalid scope id provided for the parameter " + name ;
1257
1279
}
0 commit comments