Search in sources :

Example 1 with ConfigProperty

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;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ConfigProperty(org.onosproject.cfg.ConfigProperty) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Example 2 with ConfigProperty

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);
    }
}
Also used : ComponentConfigEvent(org.onosproject.cfg.ComponentConfigEvent) ComponentConfigStore(org.onosproject.cfg.ComponentConfigStore) AppGuard.checkPermission(org.onosproject.security.AppGuard.checkPermission) HashSet(java.util.HashSet) Component(org.osgi.service.component.annotations.Component) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) Configuration(org.osgi.service.cm.Configuration) SharedExecutors(org.onlab.util.SharedExecutors) CONFIG_READ(org.onosproject.security.AppPermission.Type.CONFIG_READ) Map(java.util.Map) Activate(org.osgi.service.component.annotations.Activate) Hashtable(java.util.Hashtable) ComponentConfigService(org.onosproject.cfg.ComponentConfigService) ImmutableSet(com.google.common.collect.ImmutableSet) Logger(org.slf4j.Logger) Deactivate(org.osgi.service.component.annotations.Deactivate) AbstractAccumulator(org.onlab.util.AbstractAccumulator) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) Set(java.util.Set) IOException(java.io.IOException) Maps(com.google.common.collect.Maps) ComponentConfigStoreDelegate(org.onosproject.cfg.ComponentConfigStoreDelegate) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) Objects(java.util.Objects) List(java.util.List) Accumulator(org.onlab.util.Accumulator) ConfigProperty(org.onosproject.cfg.ConfigProperty) CONFIG_WRITE(org.onosproject.security.AppPermission.Type.CONFIG_WRITE) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) ConfigurationAdmin(org.osgi.service.cm.ConfigurationAdmin) Reference(org.osgi.service.component.annotations.Reference) Dictionary(java.util.Dictionary) InputStream(java.io.InputStream) Configuration(org.osgi.service.cm.Configuration) Hashtable(java.util.Hashtable) ConfigProperty(org.onosproject.cfg.ConfigProperty) IOException(java.io.IOException)

Example 3 with ConfigProperty

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);
    }
}
Also used : ConfigProperty(org.onosproject.cfg.ConfigProperty)

Example 4 with ConfigProperty

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();
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) InputStreamReader(java.io.InputStreamReader) ConfigProperty(org.onosproject.cfg.ConfigProperty) BufferedReader(java.io.BufferedReader)

Example 5 with ConfigProperty

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);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ConfigProperty(org.onosproject.cfg.ConfigProperty) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Aggregations

ConfigProperty (org.onosproject.cfg.ConfigProperty)12 ComponentConfigService (org.onosproject.cfg.ComponentConfigService)4 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)3 IOException (java.io.IOException)3 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)2 ImmutableSet (com.google.common.collect.ImmutableSet)2 InputStream (java.io.InputStream)2 Set (java.util.Set)2 Configuration (org.osgi.service.cm.Configuration)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)1 Strings.isNullOrEmpty (com.google.common.base.Strings.isNullOrEmpty)1 Maps (com.google.common.collect.Maps)1 BufferedReader (java.io.BufferedReader)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 InputStreamReader (java.io.InputStreamReader)1 Dictionary (java.util.Dictionary)1