mirror of
https://github.com/opennetworkinglab/onos.git
synced 2025-10-15 17:31:31 +02:00
Fixing ComponentConfigManager to preset values locally; not just in the distributed store.
Also added 'preset' usage to the 'cfg' command. Change-Id: I90df276e68328716784ca1f8624d4d0b8266ad24 (cherry picked from commit 8c73019d271efd7975f1f94c2aa32456dd73c170)
This commit is contained in:
parent
69e7623539
commit
4b32fcb10c
@ -41,6 +41,7 @@ public class ComponentConfigCommand extends AbstractShellCommand {
|
|||||||
|
|
||||||
static final String GET = "get";
|
static final String GET = "get";
|
||||||
static final String SET = "set";
|
static final String SET = "set";
|
||||||
|
static final String PRESET = "preset";
|
||||||
|
|
||||||
private static final String FMT = " name=%s, type=%s, value=%s, defaultValue=%s, description=%s";
|
private static final String FMT = " name=%s, type=%s, value=%s, defaultValue=%s, description=%s";
|
||||||
private static final String SHORT_FMT = " %s=%s";
|
private static final String SHORT_FMT = " %s=%s";
|
||||||
@ -51,7 +52,7 @@ public class ComponentConfigCommand extends AbstractShellCommand {
|
|||||||
|
|
||||||
|
|
||||||
@Argument(index = 0, name = "command",
|
@Argument(index = 0, name = "command",
|
||||||
description = "Command name (get|set)",
|
description = "Command name (get|set|preset)",
|
||||||
required = false, multiValued = false)
|
required = false, multiValued = false)
|
||||||
String command = null;
|
String command = null;
|
||||||
|
|
||||||
@ -85,6 +86,8 @@ public class ComponentConfigCommand extends AbstractShellCommand {
|
|||||||
service.unsetProperty(component, name);
|
service.unsetProperty(component, name);
|
||||||
} else if (command.equals(SET)) {
|
} else if (command.equals(SET)) {
|
||||||
service.setProperty(component, name, value);
|
service.setProperty(component, name, value);
|
||||||
|
} else if (command.equals(PRESET)) {
|
||||||
|
service.preSetProperty(component, name, value);
|
||||||
} else {
|
} else {
|
||||||
error("Illegal usage");
|
error("Illegal usage");
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,7 @@ import java.util.List;
|
|||||||
import java.util.SortedSet;
|
import java.util.SortedSet;
|
||||||
|
|
||||||
import static org.onosproject.cli.cfg.ComponentConfigCommand.GET;
|
import static org.onosproject.cli.cfg.ComponentConfigCommand.GET;
|
||||||
|
import static org.onosproject.cli.cfg.ComponentConfigCommand.PRESET;
|
||||||
import static org.onosproject.cli.cfg.ComponentConfigCommand.SET;
|
import static org.onosproject.cli.cfg.ComponentConfigCommand.SET;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -35,6 +36,7 @@ public class ComponentConfigCommandCompleter implements Completer {
|
|||||||
SortedSet<String> strings = delegate.getStrings();
|
SortedSet<String> strings = delegate.getStrings();
|
||||||
strings.add(GET);
|
strings.add(GET);
|
||||||
strings.add(SET);
|
strings.add(SET);
|
||||||
|
strings.add(PRESET);
|
||||||
|
|
||||||
// Now let the completer do the work for figuring out what to offer.
|
// Now let the completer do the work for figuring out what to offer.
|
||||||
return delegate.complete(buffer, cursor, candidates);
|
return delegate.complete(buffer, cursor, candidates);
|
||||||
|
@ -244,6 +244,9 @@ public class ComponentConfigManager implements ComponentConfigService {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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
|
// Locates the property in the component map and replaces it with an
|
||||||
@ -262,6 +265,21 @@ 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, null);
|
||||||
|
Dictionary<String, Object> props = config.getProperties();
|
||||||
|
if (props == null) {
|
||||||
|
props = new Hashtable<>();
|
||||||
|
}
|
||||||
|
props.put(name, value);
|
||||||
|
config.update(props);
|
||||||
|
} catch (IOException e) {
|
||||||
|
log.error("Failed to preset configuration for {}", componentName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Checks whether the value of the specified configuration property is a valid one or not.
|
// Checks whether the value of the specified configuration property is a valid one or not.
|
||||||
private void checkValidity(String componentName, String name, String newValue) {
|
private void checkValidity(String componentName, String name, String newValue) {
|
||||||
Map<String, ConfigProperty> map = properties.get(componentName);
|
Map<String, ConfigProperty> map = properties.get(componentName);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user