Search in sources :

Example 1 with Config

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);
    }
}
Also used : Config(org.onosproject.net.config.Config) InvalidConfigException(org.onosproject.net.config.InvalidConfigException)

Example 2 with Config

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();
}
Also used : SubjectFactory(org.onosproject.net.config.SubjectFactory) NetworkConfigService(org.onosproject.net.config.NetworkConfigService) Config(org.onosproject.net.config.Config) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 3 with Config

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());
}
Also used : Config(org.onosproject.net.config.Config) Test(org.junit.Test)

Example 4 with Config

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());
}
Also used : Config(org.onosproject.net.config.Config) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Aggregations

Config (org.onosproject.net.config.Config)4 Test (org.junit.Test)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 InvalidConfigException (org.onosproject.net.config.InvalidConfigException)1 NetworkConfigService (org.onosproject.net.config.NetworkConfigService)1 SubjectFactory (org.onosproject.net.config.SubjectFactory)1