Search in sources :

Example 1 with ConfigFactory

use of org.onosproject.net.config.ConfigFactory in project onos by opennetworkinglab.

the class DistributedNetworkConfigStore method applyConfig.

@Override
public <S, C extends Config<S>> C applyConfig(S subject, Class<C> configClass, JsonNode json) {
    // Create the configuration and validate it.
    C config = createConfig(subject, configClass, json);
    try {
        checkArgument(config.isValid(), INVALID_CONFIG_JSON);
    } catch (RuntimeException e) {
        ConfigFactory<S, C> configFactory = getConfigFactory(configClass);
        String subjectKey = configFactory.subjectFactory().subjectClassKey();
        String subjectString = configFactory.subjectFactory().subjectKey(config.subject());
        String configKey = config.key();
        throw new InvalidConfigException(subjectKey, subjectString, configKey, e);
    }
    // Insert the validated configuration and get it back.
    Versioned<JsonNode> versioned = configs.putAndGet(key(subject, configClass), json);
    // was supplanted by someone else already.
    return versioned.value() == json ? config : createConfig(subject, configClass, versioned.value());
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) InvalidConfigException(org.onosproject.net.config.InvalidConfigException) ConfigFactory(org.onosproject.net.config.ConfigFactory)

Example 2 with ConfigFactory

use of org.onosproject.net.config.ConfigFactory in project onos by opennetworkinglab.

the class NetworkConfigManagerTest method testRegistry.

@Test
public void testRegistry() {
    assertThat(registry.getConfigFactories(), hasSize(0));
    assertThat(registry.getConfigFactories(String.class), hasSize(0));
    assertThat(registry.getConfigFactory(BasicConfig1.class), nullValue());
    registry.registerConfigFactory(config1Factory);
    registry.registerConfigFactory(config2Factory);
    assertThat(registry.getConfigFactories(), hasSize(2));
    assertThat(registry.getConfigFactories(String.class), hasSize(2));
    ConfigFactory queried = registry.getConfigFactory(BasicConfig1.class);
    assertThat(queried, is(config1Factory));
    registry.unregisterConfigFactory(queried);
    // Factory associations are not removed according to code documentation
    assertThat(registry.getConfigFactories(), hasSize(1));
    assertThat(registry.getConfigFactories(String.class), hasSize(1));
    assertThat(registry.getConfigFactory(BasicConfig1.class), nullValue());
}
Also used : ConfigFactory(org.onosproject.net.config.ConfigFactory) Test(org.junit.Test)

Aggregations

ConfigFactory (org.onosproject.net.config.ConfigFactory)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 Test (org.junit.Test)1 InvalidConfigException (org.onosproject.net.config.InvalidConfigException)1