Naoki Shiota
Committed by Gerrit Code Review

Fixed a bug that ComponentConfigManager#preSetProperty always fails to update a property value.

Change-Id: Id696d4920c6968c4b7592b60644b7593cec0de16
......@@ -245,8 +245,9 @@ public class ComponentConfigManager implements ComponentConfigService {
return;
}
}
log.warn("Unable to set non-existent property {} for component {}",
name, componentName);
// If definition doesn't exist in local catalog, cache the property.
preSet(componentName, name, value);
}
// Locates the property in the component map and replaces it with an
......@@ -265,6 +266,24 @@ public class ComponentConfigManager implements ComponentConfigService {
}
}
// Stores non-existent property so that loadExistingValues() can load in future.
private void preSet(String componentName, String name, String value) {
try {
Configuration config = cfgAdmin.getConfiguration(componentName);
if (config == null) {
config = cfgAdmin.createFactoryConfiguration(componentName);
}
Dictionary<String, Object> property = config.getProperties();
if (property == null) {
property = new Hashtable<>();
}
property.put(name, value);
config.update(property);
} catch (IOException e) {
log.error("Failed to preset configuration for {}", componentName);
}
}
// Loads existing property values that may have been set.
private void loadExistingValues(String componentName) {
try {
......@@ -301,5 +320,4 @@ public class ComponentConfigManager implements ComponentConfigService {
log.warn("Unable to update configuration for " + componentName, e);
}
}
}
......