Committed by
Gerrit Code Review
Fixed a bug that ComponentConfigManager#preSetProperty always fails to update a property value.
Change-Id: Id696d4920c6968c4b7592b60644b7593cec0de16
Showing
1 changed file
with
21 additions
and
3 deletions
... | @@ -245,8 +245,9 @@ public class ComponentConfigManager implements ComponentConfigService { | ... | @@ -245,8 +245,9 @@ public class ComponentConfigManager implements ComponentConfigService { |
245 | return; | 245 | return; |
246 | } | 246 | } |
247 | } | 247 | } |
248 | - log.warn("Unable to set non-existent property {} for component {}", | 248 | + |
249 | - name, componentName); | 249 | + // If definition doesn't exist in local catalog, cache the property. |
250 | + preSet(componentName, name, value); | ||
250 | } | 251 | } |
251 | 252 | ||
252 | // Locates the property in the component map and replaces it with an | 253 | // Locates the property in the component map and replaces it with an |
... | @@ -265,6 +266,24 @@ public class ComponentConfigManager implements ComponentConfigService { | ... | @@ -265,6 +266,24 @@ public class ComponentConfigManager implements ComponentConfigService { |
265 | } | 266 | } |
266 | } | 267 | } |
267 | 268 | ||
269 | + // Stores non-existent property so that loadExistingValues() can load in future. | ||
270 | + private void preSet(String componentName, String name, String value) { | ||
271 | + try { | ||
272 | + Configuration config = cfgAdmin.getConfiguration(componentName); | ||
273 | + if (config == null) { | ||
274 | + config = cfgAdmin.createFactoryConfiguration(componentName); | ||
275 | + } | ||
276 | + Dictionary<String, Object> property = config.getProperties(); | ||
277 | + if (property == null) { | ||
278 | + property = new Hashtable<>(); | ||
279 | + } | ||
280 | + property.put(name, value); | ||
281 | + config.update(property); | ||
282 | + } catch (IOException e) { | ||
283 | + log.error("Failed to preset configuration for {}", componentName); | ||
284 | + } | ||
285 | + } | ||
286 | + | ||
268 | // Loads existing property values that may have been set. | 287 | // Loads existing property values that may have been set. |
269 | private void loadExistingValues(String componentName) { | 288 | private void loadExistingValues(String componentName) { |
270 | try { | 289 | try { |
... | @@ -301,5 +320,4 @@ public class ComponentConfigManager implements ComponentConfigService { | ... | @@ -301,5 +320,4 @@ public class ComponentConfigManager implements ComponentConfigService { |
301 | log.warn("Unable to update configuration for " + componentName, e); | 320 | log.warn("Unable to update configuration for " + componentName, e); |
302 | } | 321 | } |
303 | } | 322 | } |
304 | - | ||
305 | } | 323 | } | ... | ... |
-
Please register or login to post a comment