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());
}
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());
}
Aggregations