Search in sources :

Example 1 with SubjectFactory

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

the class NetworkConfigCommand method doExecute.

@Override
protected void doExecute() {
    service = get(NetworkConfigService.class);
    JsonNode root = mapper.createObjectNode();
    if (isNullOrEmpty(subjectClassKey)) {
        if (remove) {
            service.removeConfig();
        }
        addAll((ObjectNode) root);
    } else {
        SubjectFactory subjectFactory = nullIsIllegal(service.getSubjectFactory(subjectClassKey), subjectClassKey + E_CLASSKEY_NOT_REGISTERED);
        if (isNullOrEmpty(subjectKey)) {
            addSubjectClass((ObjectNode) root, subjectFactory);
        } else {
            Object s = subjectFactory.createSubject(subjectKey);
            if (isNullOrEmpty(configKey)) {
                if (remove) {
                    service.removeConfig(s);
                }
                addSubject((ObjectNode) root, s);
            } else {
                if (remove) {
                    service.removeConfig(subjectClassKey, s, configKey);
                }
                root = getSubjectConfig(getConfig(s, subjectClassKey, configKey));
            }
        }
    }
    try {
        print("%s", mapper.writerWithDefaultPrettyPrinter().writeValueAsString(root));
    } catch (JsonProcessingException e) {
        throw new IllegalStateException("Error writing JSON to string", e);
    }
}
Also used : SubjectFactory(org.onosproject.net.config.SubjectFactory) NetworkConfigService(org.onosproject.net.config.NetworkConfigService) JsonNode(com.fasterxml.jackson.databind.JsonNode) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 2 with SubjectFactory

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

the class NetworkConfigCommand method addAll.

@SuppressWarnings("unchecked")
private void addAll(ObjectNode root) {
    service.getSubjectClasses().forEach(sc -> {
        SubjectFactory sf = service.getSubjectFactory(sc);
        addSubjectClass(newObject(root, sf.subjectClassKey()), sf);
    });
}
Also used : SubjectFactory(org.onosproject.net.config.SubjectFactory)

Example 3 with SubjectFactory

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

the class SubjectKeyCompleter method choices.

@Override
protected List<String> choices() {
    NetworkConfigRegistry service = AbstractShellCommand.get(NetworkConfigRegistry.class);
    String subjectClassKey = commandLine.getArguments()[commandLine.getCursorArgumentIndex() - 1];
    SubjectFactory subjectFactory = service.getSubjectFactory(subjectClassKey);
    if (subjectFactory == null) {
        return Collections.emptyList();
    }
    // get all registered subject objects.
    Set<Object> subjects = service.getSubjects(subjectFactory.subjectClass());
    return subjects.stream().map(subjectFactory::subjectKey).collect(Collectors.toList());
}
Also used : SubjectFactory(org.onosproject.net.config.SubjectFactory) NetworkConfigRegistry(org.onosproject.net.config.NetworkConfigRegistry)

Example 4 with SubjectFactory

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

the class NetworkConfigManager method registerConfigFactory.

@Override
@SuppressWarnings("unchecked")
public void registerConfigFactory(ConfigFactory configFactory) {
    checkNotNull(configFactory, NULL_FACTORY_MSG);
    if (factoryCounters.containsKey(key(configFactory))) {
        factoryCounters.replace(key(configFactory), (factoryCounters.get(key(configFactory)) + 1));
    } else {
        factories.put(key(configFactory), configFactory);
        factoryCounters.put(key(configFactory), 1);
        configClasses.put(identifier(configFactory), configFactory.configClass());
        SubjectFactory subjectFactory = configFactory.subjectFactory();
        subjectClasses.putIfAbsent(subjectFactory.subjectClassKey(), subjectFactory);
        subjectClassKeys.putIfAbsent(subjectFactory.subjectClass(), subjectFactory);
        store.addConfigFactory(configFactory);
    }
}
Also used : SubjectFactory(org.onosproject.net.config.SubjectFactory)

Example 5 with SubjectFactory

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

the class NetworkConfigWebResource method download.

/**
 * Gets entire network configuration base.
 *
 * @return 200 OK with network configuration JSON
 */
@GET
@Produces(MediaType.APPLICATION_JSON)
@SuppressWarnings("unchecked")
public Response download() {
    NetworkConfigService service = get(NetworkConfigService.class);
    ObjectNode root = mapper().createObjectNode();
    service.getSubjectClasses().forEach(sc -> {
        SubjectFactory subjectFactory = service.getSubjectFactory(sc);
        produceJson(service, newObject(root, subjectFactory.subjectClassKey()), subjectFactory, sc);
    });
    return ok(root).build();
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) SubjectFactory(org.onosproject.net.config.SubjectFactory) NetworkConfigService(org.onosproject.net.config.NetworkConfigService) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

SubjectFactory (org.onosproject.net.config.SubjectFactory)8 NetworkConfigService (org.onosproject.net.config.NetworkConfigService)5 Path (javax.ws.rs.Path)3 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 GET (javax.ws.rs.GET)2 Produces (javax.ws.rs.Produces)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 Consumes (javax.ws.rs.Consumes)1 DELETE (javax.ws.rs.DELETE)1 POST (javax.ws.rs.POST)1 Config (org.onosproject.net.config.Config)1 NetworkConfigRegistry (org.onosproject.net.config.NetworkConfigRegistry)1