use of org.onosproject.cfg.ConfigProperty in project onos by opennetworkinglab.
the class ComponentConfigCommand method jsonComponent.
private JsonNode jsonComponent(String component, ObjectMapper mapper) {
ObjectNode node = mapper.createObjectNode().put("componentName", component);
final ArrayNode propertiesJson = node.putArray("properties");
Set<ConfigProperty> properties = service.getProperties(component);
if (properties != null) {
properties.forEach(configProperty -> propertiesJson.add(jsonProperty(configProperty, mapper)));
}
return node;
}
use of org.onosproject.cfg.ConfigProperty in project onos by opennetworkinglab.
the class ComponentConfigManager method triggerUpdate.
private void triggerUpdate(String componentName) {
try {
Configuration cfg = cfgAdmin.getConfiguration(componentName, null);
Map<String, ConfigProperty> map = properties.get(componentName);
if (map == null) {
// Prevent NPE if the component isn't there
log.warn("Component not found for " + componentName);
return;
}
Dictionary<String, Object> props = new Hashtable<>();
map.values().stream().filter(p -> p.value() != null).forEach(p -> props.put(p.name(), p.value()));
cfg.update(props);
} catch (IOException e) {
log.warn("Unable to update configuration for " + componentName, e);
}
}
use of org.onosproject.cfg.ConfigProperty in project onos by opennetworkinglab.
the class ComponentConfigManager method reset.
// Locates the property in the component map and replaces it with an
// reset copy.
private void reset(String componentName, String name) {
Map<String, ConfigProperty> map = properties.get(componentName);
if (map != null) {
ConfigProperty prop = map.get(name);
if (prop != null) {
map.put(name, ConfigProperty.resetProperty(prop));
accumulator.add(componentName);
return;
}
log.warn("Unable to reset non-existent property {} for component {}", name, componentName);
}
}
use of org.onosproject.cfg.ConfigProperty in project onos by opennetworkinglab.
the class ConfigPropertyDefinitions method read.
/**
* Reads the specified input stream and creates from its contents a
* set of property definitions.
*
* @param stream input stream
* @return properties whose definitions are contained in the stream
* @throws java.io.IOException if unable to read the stream
*/
public static Set<ConfigProperty> read(InputStream stream) throws IOException {
ImmutableSet.Builder<ConfigProperty> builder = ImmutableSet.builder();
try (BufferedReader br = new BufferedReader(new InputStreamReader(stream))) {
String line;
while ((line = br.readLine()) != null) {
if (!line.isEmpty() && !line.startsWith(COMMENT)) {
String[] f = line.split(SEP, 4);
if (f.length < 4) {
log.warn("Cannot parse property from line: '{}'. " + "This property will be ignored", line);
continue;
}
builder.add(defineProperty(f[0], Type.valueOf(f[1]), f[2], f[3]));
}
}
}
return builder.build();
}
use of org.onosproject.cfg.ConfigProperty in project onos by opennetworkinglab.
the class ConfigPropertyDefinitionsTest method basics.
@Test
public void basics() throws IOException {
Set<ConfigProperty> original = ImmutableSet.of(defineProperty("foo", STRING, "dingo", "FOO"), defineProperty("bar", STRING, "bat", "BAR"));
ByteArrayOutputStream out = new ByteArrayOutputStream(1024);
write(out, original);
Set<ConfigProperty> read = read(new ByteArrayInputStream(out.toByteArray()));
assertEquals("incorrect defs", original, read);
}
Aggregations