Search in sources :

Example 1 with LeafNode

use of org.onosproject.yang.model.LeafNode in project onos by opennetworkinglab.

the class DistributedDynamicConfigStore method traverseInner.

// FIXME this is more like addInnteNode
/**
 * @param path pointing to {@code node}
 * @param node node
 */
private void traverseInner(String path, InnerNode node) {
    log.trace("traverseInner({}, {})", path, node);
    addKey(path, node.type());
    Map<NodeKey, DataNode> entries = node.childNodes();
    if (entries.size() == 0) {
        return;
    }
    // FIXME ignoring results
    entries.forEach((k, v) -> {
        String tempPath;
        tempPath = ResourceIdParser.appendNodeKey(path, v.key());
        if (v.type() == DataNode.Type.SINGLE_INSTANCE_LEAF_VALUE_NODE) {
            addLeaf(tempPath, (LeafNode) v);
        } else if (v.type() == DataNode.Type.MULTI_INSTANCE_LEAF_VALUE_NODE) {
            tempPath = ResourceIdParser.appendLeafList(tempPath, (LeafListKey) v.key());
            addLeaf(tempPath, (LeafNode) v);
        } else if (v.type() == DataNode.Type.SINGLE_INSTANCE_NODE) {
            traverseInner(tempPath, (InnerNode) v);
        } else if (v.type() == DataNode.Type.MULTI_INSTANCE_NODE) {
            tempPath = ResourceIdParser.appendKeyList(tempPath, (ListKey) v.key());
            traverseInner(tempPath, (InnerNode) v);
        } else {
            throw new FailedException("Invalid node type");
        }
    });
}
Also used : DataNode(org.onosproject.yang.model.DataNode) FailedException(org.onosproject.config.FailedException) LeafNode(org.onosproject.yang.model.LeafNode) NodeKey(org.onosproject.yang.model.NodeKey) InnerNode(org.onosproject.yang.model.InnerNode)

Example 2 with LeafNode

use of org.onosproject.yang.model.LeafNode in project onos by opennetworkinglab.

the class DistributedDynamicConfigStore method readInner.

private void readInner(DataNode.Builder superBldr, String spath) {
    CompletableFuture<Map<String, Versioned<DataNode.Type>>> ret = keystore.getChildren(DocumentPath.from(spath));
    Map<String, Versioned<DataNode.Type>> entries = null;
    entries = complete(ret);
    log.trace(" keystore.getChildren({})", spath);
    log.trace("  entries keys:{}", entries.keySet());
    if (!entries.isEmpty()) {
        entries.forEach((k, v) -> {
            String[] names = k.split(ResourceIdParser.NM_CHK);
            String name = names[0];
            String nmSpc = ResourceIdParser.getNamespace(names[1]);
            String keyVal = ResourceIdParser.getKeyVal(names[1]);
            DataNode.Type type = v.value();
            String tempPath = ResourceIdParser.appendNodeKey(spath, name, nmSpc);
            if (type == DataNode.Type.SINGLE_INSTANCE_LEAF_VALUE_NODE) {
                LeafNode lfnode = readLeaf(tempPath);
                // FIXME there should be builder for copying
                superBldr.createChildBuilder(name, nmSpc, lfnode.value(), lfnode.valueNamespace()).type(type).leafType(lfnode.leafType()).exitNode();
            } else if (type == DataNode.Type.MULTI_INSTANCE_LEAF_VALUE_NODE) {
                String mlpath = ResourceIdParser.appendLeafList(tempPath, keyVal);
                LeafNode lfnode = readLeaf(mlpath);
                // FIXME there should be builder for copying
                superBldr.createChildBuilder(name, nmSpc, lfnode.value(), lfnode.valueNamespace()).type(type).leafType(lfnode.leafType()).addLeafListValue(lfnode.value()).exitNode();
            // TODO this alone should be sufficient and take the nm, nmspc too
            } else if (type == DataNode.Type.SINGLE_INSTANCE_NODE) {
                DataNode.Builder tempBldr = superBldr.createChildBuilder(name, nmSpc).type(type);
                readInner(tempBldr, tempPath);
            } else if (type == DataNode.Type.MULTI_INSTANCE_NODE) {
                DataNode.Builder tempBldr = superBldr.createChildBuilder(name, nmSpc).type(type);
                tempPath = ResourceIdParser.appendMultiInstKey(tempPath, k);
                String[] keys = k.split(ResourceIdParser.KEY_CHK);
                for (int i = 1; i < keys.length; i++) {
                    // String curKey = ResourceIdParser.appendKeyLeaf(tempPath, keys[i]);
                    // LeafNode lfnd = readLeaf(curKey);
                    String[] keydata = keys[i].split(ResourceIdParser.NM_CHK);
                    tempBldr.addKeyLeaf(keydata[0], keydata[1], keydata[2]);
                }
                readInner(tempBldr, tempPath);
            } else {
                throw new FailedException("Invalid node type");
            }
        });
    }
    superBldr.exitNode();
}
Also used : Versioned(org.onosproject.store.service.Versioned) LeafType(org.onosproject.yang.model.LeafType) DataNode(org.onosproject.yang.model.DataNode) FailedException(org.onosproject.config.FailedException) LeafNode(org.onosproject.yang.model.LeafNode) ConsistentMap(org.onosproject.store.service.ConsistentMap) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

FailedException (org.onosproject.config.FailedException)2 DataNode (org.onosproject.yang.model.DataNode)2 LeafNode (org.onosproject.yang.model.LeafNode)2 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 ConsistentMap (org.onosproject.store.service.ConsistentMap)1 Versioned (org.onosproject.store.service.Versioned)1 InnerNode (org.onosproject.yang.model.InnerNode)1 LeafType (org.onosproject.yang.model.LeafType)1 NodeKey (org.onosproject.yang.model.NodeKey)1