@@ -727,7 +727,7 @@ public boolean stop() {
727
727
728
728
@ Override
729
729
@ DB
730
- public String updateConfiguration (final long userId , final String name , final String category , String value , final String scope , final Long resourceId ) {
730
+ public String updateConfiguration (final long userId , final String name , final String category , String value , ConfigKey . Scope scope , final Long resourceId ) {
731
731
final String validationMsg = validateConfigurationValue (name , value , scope );
732
732
if (validationMsg != null ) {
733
733
logger .error ("Invalid value [{}] for configuration [{}] due to [{}]." , value , name , validationMsg );
@@ -738,15 +738,14 @@ public String updateConfiguration(final long userId, final String name, final St
738
738
// corresponding details table,
739
739
// if scope is mentioned as global or not mentioned then it is normal
740
740
// global parameter updation
741
- if (scope != null && !scope . isEmpty () && ! ConfigKey .Scope .Global .toString (). equalsIgnoreCase (scope )) {
741
+ if (scope != null && !ConfigKey .Scope .Global .equals (scope )) {
742
742
boolean valueEncrypted = shouldEncryptValue (category );
743
743
if (valueEncrypted ) {
744
744
value = DBEncryptionUtil .encrypt (value );
745
745
}
746
746
747
747
ApiCommandResourceType resourceType ;
748
- ConfigKey .Scope scopeVal = ConfigKey .Scope .valueOf (scope );
749
- switch (scopeVal ) {
748
+ switch (scope ) {
750
749
case Zone :
751
750
final DataCenterVO zone = _zoneDao .findById (resourceId );
752
751
if (zone == null ) {
@@ -845,9 +844,9 @@ public String updateConfiguration(final long userId, final String name, final St
845
844
846
845
CallContext .current ().setEventResourceType (resourceType );
847
846
CallContext .current ().setEventResourceId (resourceId );
848
- CallContext .current ().setEventDetails (String .format (" Name: %s, New Value: %s, Scope: %s" , name , value , scope ));
847
+ CallContext .current ().setEventDetails (String .format (" Name: %s, New Value: %s, Scope: %s" , name , value , scope . name () ));
849
848
850
- _configDepot .invalidateConfigCache (name , scopeVal , resourceId );
849
+ _configDepot .invalidateConfigCache (name , scope , resourceId );
851
850
return valueEncrypted ? DBEncryptionUtil .decrypt (value ) : value ;
852
851
}
853
852
@@ -1013,40 +1012,40 @@ public Configuration updateConfiguration(final UpdateCfgCmd cmd) throws InvalidP
1013
1012
return _configDao .findByName (name );
1014
1013
}
1015
1014
1016
- String scope = null ;
1015
+ ConfigKey . Scope scope = null ;
1017
1016
Long id = null ;
1018
1017
int paramCountCheck = 0 ;
1019
1018
1020
1019
if (zoneId != null ) {
1021
- scope = ConfigKey .Scope .Zone . toString () ;
1020
+ scope = ConfigKey .Scope .Zone ;
1022
1021
id = zoneId ;
1023
1022
paramCountCheck ++;
1024
1023
}
1025
1024
if (clusterId != null ) {
1026
- scope = ConfigKey .Scope .Cluster . toString () ;
1025
+ scope = ConfigKey .Scope .Cluster ;
1027
1026
id = clusterId ;
1028
1027
paramCountCheck ++;
1029
1028
}
1030
1029
if (accountId != null ) {
1031
1030
Account account = _accountMgr .getAccount (accountId );
1032
1031
_accountMgr .checkAccess (caller , null , false , account );
1033
- scope = ConfigKey .Scope .Account . toString () ;
1032
+ scope = ConfigKey .Scope .Account ;
1034
1033
id = accountId ;
1035
1034
paramCountCheck ++;
1036
1035
}
1037
1036
if (domainId != null ) {
1038
1037
_accountMgr .checkAccess (caller , _domainDao .findById (domainId ));
1039
- scope = ConfigKey .Scope .Domain . toString () ;
1038
+ scope = ConfigKey .Scope .Domain ;
1040
1039
id = domainId ;
1041
1040
paramCountCheck ++;
1042
1041
}
1043
1042
if (storagepoolId != null ) {
1044
- scope = ConfigKey .Scope .StoragePool . toString () ;
1043
+ scope = ConfigKey .Scope .StoragePool ;
1045
1044
id = storagepoolId ;
1046
1045
paramCountCheck ++;
1047
1046
}
1048
1047
if (imageStoreId != null ) {
1049
- scope = ConfigKey .Scope .ImageStore . toString () ;
1048
+ scope = ConfigKey .Scope .ImageStore ;
1050
1049
id = imageStoreId ;
1051
1050
paramCountCheck ++;
1052
1051
}
@@ -1060,8 +1059,15 @@ public Configuration updateConfiguration(final UpdateCfgCmd cmd) throws InvalidP
1060
1059
if (value .isEmpty () || value .equals ("null" )) {
1061
1060
value = (id == null ) ? null : "" ;
1062
1061
}
1062
+
1063
+ String currentValueInScope = getConfigurationValueInScope (config , name , scope , id );
1063
1064
final String updatedValue = updateConfiguration (userId , name , category , value , scope , id );
1064
1065
if (value == null && updatedValue == null || updatedValue .equalsIgnoreCase (value )) {
1066
+ logger .debug ("Config: {} value is updated from: {} to {} for scope: {}" , name ,
1067
+ encryptEventValueIfConfigIsEncrypted (config , currentValueInScope ),
1068
+ encryptEventValueIfConfigIsEncrypted (config , value ),
1069
+ scope != null ? scope : ConfigKey .Scope .Global .name ());
1070
+
1065
1071
return _configDao .findByName (name );
1066
1072
} else {
1067
1073
throw new CloudRuntimeException ("Unable to update configuration parameter " + name );
@@ -1123,7 +1129,7 @@ public Pair<Configuration, String> resetConfiguration(final ResetCfgCmd cmd) thr
1123
1129
configScope = config .getScopes ();
1124
1130
}
1125
1131
1126
- String scope = "" ;
1132
+ String scopeVal = "" ;
1127
1133
Map <String , Long > scopeMap = new LinkedHashMap <>();
1128
1134
1129
1135
Long id = null ;
@@ -1139,22 +1145,23 @@ public Pair<Configuration, String> resetConfiguration(final ResetCfgCmd cmd) thr
1139
1145
ParamCountPair paramCountPair = getParamCount (scopeMap );
1140
1146
id = paramCountPair .getId ();
1141
1147
paramCountCheck = paramCountPair .getParamCount ();
1142
- scope = paramCountPair .getScope ();
1148
+ scopeVal = paramCountPair .getScope ();
1143
1149
1144
1150
if (paramCountCheck > 1 ) {
1145
1151
throw new InvalidParameterValueException ("cannot handle multiple IDs, provide only one ID corresponding to the scope" );
1146
1152
}
1147
1153
1148
- if (scope != null ) {
1149
- ConfigKey .Scope scopeVal = ConfigKey .Scope .valueOf (scope );
1150
- if (!scope .equals (ConfigKey .Scope .Global .toString ()) && !configScope .contains (scopeVal )) {
1154
+ if (scopeVal != null ) {
1155
+ ConfigKey .Scope scope = ConfigKey .Scope .valueOf (scopeVal );
1156
+ if (!scopeVal .equals (ConfigKey .Scope .Global .toString ()) && !configScope .contains (scope )) {
1151
1157
throw new InvalidParameterValueException ("Invalid scope id provided for the parameter " + name );
1152
1158
}
1153
1159
}
1154
1160
1155
1161
String newValue = null ;
1156
- ConfigKey .Scope scopeVal = ConfigKey .Scope .valueOf (scope );
1157
- switch (scopeVal ) {
1162
+ ConfigKey .Scope scope = ConfigKey .Scope .valueOf (scopeVal );
1163
+ String currentValueInScope = getConfigurationValueInScope (config , name , scope , id );
1164
+ switch (scope ) {
1158
1165
case Zone :
1159
1166
final DataCenterVO zone = _zoneDao .findById (id );
1160
1167
if (zone == null ) {
@@ -1239,20 +1246,36 @@ public Pair<Configuration, String> resetConfiguration(final ResetCfgCmd cmd) thr
1239
1246
newValue = optionalValue .isPresent () ? optionalValue .get ().toString () : defaultValue ;
1240
1247
}
1241
1248
1242
- _configDepot .invalidateConfigCache (name , scopeVal , id );
1249
+ logger .debug ("Config: {} value is updated from: {} to {} for scope: {}" , name ,
1250
+ encryptEventValueIfConfigIsEncrypted (config , currentValueInScope ),
1251
+ encryptEventValueIfConfigIsEncrypted (config , newValue ), scope );
1252
+
1253
+ _configDepot .invalidateConfigCache (name , scope , id );
1243
1254
1244
1255
CallContext .current ().setEventDetails (" Name: " + name + " New Value: " + (name .toLowerCase ().contains ("password" ) ? "*****" : defaultValue == null ? "" : defaultValue ));
1245
1256
return new Pair <Configuration , String >(_configDao .findByName (name ), newValue );
1246
1257
}
1247
1258
1259
+ private String getConfigurationValueInScope (ConfigurationVO config , String name , ConfigKey .Scope scope , Long id ) {
1260
+ String configValue ;
1261
+ if (scope == null || ConfigKey .Scope .Global .equals (scope )) {
1262
+ configValue = config .getValue ();
1263
+ } else {
1264
+ ConfigKey <?> configKey = _configDepot .get (name );
1265
+ Object currentValue = configKey .valueInScope (scope , id );
1266
+ configValue = currentValue != null ? currentValue .toString () : null ;
1267
+ }
1268
+ return configValue ;
1269
+ }
1270
+
1248
1271
/**
1249
1272
* Validates whether a value is valid for the specified configuration. This includes type and range validation.
1250
1273
* @param name name of the configuration.
1251
1274
* @param value value to validate.
1252
1275
* @param scope scope of the configuration.
1253
1276
* @return null if the value is valid; otherwise, returns an error message.
1254
1277
*/
1255
- protected String validateConfigurationValue (String name , String value , String scope ) {
1278
+ protected String validateConfigurationValue (String name , String value , ConfigKey . Scope scope ) {
1256
1279
final ConfigurationVO cfg = _configDao .findByName (name );
1257
1280
if (cfg == null ) {
1258
1281
logger .error ("Missing configuration variable " + name + " in configuration table" );
@@ -1262,10 +1285,9 @@ protected String validateConfigurationValue(String name, String value, String sc
1262
1285
1263
1286
List <ConfigKey .Scope > configScope = cfg .getScopes ();
1264
1287
if (scope != null ) {
1265
- ConfigKey .Scope scopeVal = ConfigKey .Scope .valueOf (scope );
1266
- if (!configScope .contains (scopeVal ) &&
1288
+ if (!configScope .contains (scope ) &&
1267
1289
!(ENABLE_ACCOUNT_SETTINGS_FOR_DOMAIN .value () && configScope .contains (ConfigKey .Scope .Account ) &&
1268
- scope . equals ( ConfigKey .Scope .Domain .toString () ))) {
1290
+ ConfigKey .Scope .Domain .equals ( scope ))) {
1269
1291
logger .error ("Invalid scope id provided for the parameter " + name );
1270
1292
return "Invalid scope id provided for the parameter " + name ;
1271
1293
}
0 commit comments