use of org.onosproject.net.config.Config in project onos by opennetworkinglab.
the class DistributedNetworkConfigStore method validateConfig.
@SuppressWarnings("unchecked")
private void validateConfig(ConfigKey key, ConfigFactory configFactory, JsonNode json) {
Object subject;
if (key.subject instanceof String) {
subject = configFactory.subjectFactory().createSubject((String) key.subject);
} else {
subject = key.subject;
}
Config config = createConfig(subject, configFactory.configClass(), json);
try {
checkArgument(config.isValid(), INVALID_CONFIG_JSON);
configs.putAndGet(key(subject, configFactory.configClass()), json);
} catch (Exception e) {
log.warn("Failed to validate pending {} configuration for {}: {}", key.configKey, key.subject, json);
}
}
use of org.onosproject.net.config.Config in project onos by opennetworkinglab.
the class NetworkConfigWebResource method download.
/**
* Gets specific network configuration for a subjectKey.
*
* @param subjectClassKey subjectKey class key
* @param subjectKey subjectKey key
* @param configKey configuration class key
* @return 200 OK with network configuration JSON
*/
@GET
@Path("{subjectClassKey}/{subjectKey}/{configKey}")
@Produces(MediaType.APPLICATION_JSON)
@SuppressWarnings("unchecked")
public Response download(@PathParam("subjectClassKey") String subjectClassKey, @PathParam("subjectKey") String subjectKey, @PathParam("configKey") String configKey) {
NetworkConfigService service = get(NetworkConfigService.class);
SubjectFactory subjectFactory = nullIsNotFound(service.getSubjectFactory(subjectClassKey), subjectClassNotFoundErrorString(subjectClassKey));
Object subject = nullIsNotFound(subjectFactory.createSubject(subjectKey), subjectNotFoundErrorString(subjectClassKey, subjectKey));
Class configClass = nullIsNotFound(service.getConfigClass(subjectClassKey, configKey), configKeyNotFoundErrorString(subjectClassKey, subjectKey, configKey));
Config config = nullIsNotFound((Config) service.getConfig(subject, configClass), configKeyNotFoundErrorString(subjectClassKey, subjectKey, configKey));
return ok(config.node()).build();
}
use of org.onosproject.net.config.Config in project onos by opennetworkinglab.
the class NetworkConfigManagerTest method testAddConfig.
/**
* Tests creation, query and removal of a factory.
*/
@Test
public void testAddConfig() {
assertThat(configService.getSubjectFactory(String.class), nullValue());
assertThat(configService.getSubjectFactory("key"), nullValue());
registry.registerConfigFactory(config1Factory);
registry.registerConfigFactory(config2Factory);
configService.addConfig("configKey", BasicConfig1.class);
Config newConfig = configService.getConfig("configKey", BasicConfig1.class);
assertThat(newConfig, notNullValue());
assertThat(configService.getSubjectFactory(String.class), notNullValue());
assertThat(configService.getSubjectFactory("key1"), notNullValue());
Set<Class> classes = configService.getSubjectClasses();
assertThat(classes, hasSize(1));
Set<String> subjectsForClass = configService.getSubjects(String.class);
assertThat(subjectsForClass, hasSize(1));
Set<String> subjectsForConfig = configService.getSubjects(String.class, BasicConfig1.class);
assertThat(subjectsForConfig, hasSize(1));
Class queriedConfigClass = configService.getConfigClass("key1", "config1");
assertThat(queriedConfigClass == BasicConfig1.class, is(true));
Set<? extends Config> configs = configService.getConfigs("configKey");
assertThat(configs.size(), is(1));
configs.forEach(c -> assertThat(c, instanceOf(BasicConfig1.class)));
configService.removeConfig("configKey", BasicConfig1.class);
Config newConfigAfterRemove = configService.getConfig("configKey", BasicConfig1.class);
assertThat(newConfigAfterRemove, nullValue());
}
use of org.onosproject.net.config.Config in project onos by opennetworkinglab.
the class NetworkConfigManagerTest method testApplyConfig.
/**
* Tests creation, query and removal of a factory.
*/
@Test
public void testApplyConfig() {
assertThat(configService.getSubjectFactory(String.class), nullValue());
assertThat(configService.getSubjectFactory("key"), nullValue());
registry.registerConfigFactory(config1Factory);
registry.registerConfigFactory(config2Factory);
configService.applyConfig("configKey", BasicConfig1.class, new ObjectMapper().createObjectNode());
Config newConfig = configService.getConfig("configKey", BasicConfig1.class);
assertThat(newConfig, notNullValue());
assertThat(configService.getSubjectFactory(String.class), notNullValue());
assertThat(configService.getSubjectFactory("key1"), notNullValue());
}
Aggregations