Search in sources :

Example 1 with LeafType

use of org.onosproject.yang.model.LeafType 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

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