Search in sources :

Example 6 with FailedException

use of org.onosproject.config.FailedException in project onos by opennetworkinglab.

the class DistributedDynamicConfigStore method deleteNodeRecursive.

@Override
public CompletableFuture<Boolean> deleteNodeRecursive(ResourceId path) {
    String spath = ResourceIdParser.parseResId(path);
    if (spath == null) {
        throw new FailedException("Invalid RsourceId, cannot delete Node");
    }
    if (spath.compareTo(ResourceIdParser.ROOT) == 0) {
        throw new FailedException("Cannot delete Root");
    }
    DocumentPath dpath = DocumentPath.from(spath);
    DataNode.Type type = null;
    CompletableFuture<Versioned<DataNode.Type>> ret = keystore.get(dpath);
    type = completeVersioned(ret);
    if (type == null) {
        throw new FailedException("Cannot delete, Requested node or some of the parents" + "are not present in the requested path");
    }
    DataNode retVal = null;
    if (type == DataNode.Type.SINGLE_INSTANCE_LEAF_VALUE_NODE) {
        removeLeaf(spath);
    } else if (type == DataNode.Type.MULTI_INSTANCE_LEAF_VALUE_NODE) {
        removeLeaf(spath);
    } else if (type == DataNode.Type.SINGLE_INSTANCE_NODE) {
        deleteInner(spath);
    } else if (type == DataNode.Type.MULTI_INSTANCE_NODE) {
        deleteInner(spath);
    } else {
        throw new FailedException("Invalid node type");
    }
    return CompletableFuture.completedFuture(true);
}
Also used : Versioned(org.onosproject.store.service.Versioned) FailedException(org.onosproject.config.FailedException) DataNode(org.onosproject.yang.model.DataNode) DocumentPath(org.onosproject.store.service.DocumentPath)

Example 7 with FailedException

use of org.onosproject.config.FailedException in project onos by opennetworkinglab.

the class DistributedDynamicConfigStore method readNode.

@Override
public CompletableFuture<DataNode> readNode(ResourceId path, Filter filter) {
    CompletableFuture<DataNode> eventFuture = CompletableFuture.completedFuture(null);
    String spath = ResourceIdParser.parseResId(path);
    DocumentPath dpath = DocumentPath.from(spath);
    DataNode.Type type = null;
    CompletableFuture<Versioned<DataNode.Type>> ret = keystore.get(dpath);
    type = completeVersioned(ret);
    if (type == null) {
        throw new FailedException("Requested node or some of the parents " + "are not present in the requested path: " + spath);
    }
    DataNode retVal = null;
    if (type == DataNode.Type.SINGLE_INSTANCE_LEAF_VALUE_NODE) {
        retVal = readLeaf(spath);
    } else if (type == DataNode.Type.MULTI_INSTANCE_LEAF_VALUE_NODE) {
        retVal = readLeaf(spath);
    } else if (type == DataNode.Type.SINGLE_INSTANCE_NODE) {
        NodeKey key = ResourceIdParser.getInstanceKey(path);
        if (key == null) {
            throw new FailedException("Key type did not match node type");
        }
        DataNode.Builder superBldr = InnerNode.builder(key.schemaId().name(), key.schemaId().namespace()).type(type);
        readInner(superBldr, spath);
        retVal = superBldr.build();
    } else if (type == DataNode.Type.MULTI_INSTANCE_NODE) {
        NodeKey key = ResourceIdParser.getMultiInstanceKey(path);
        if (key == null) {
            throw new FailedException("Key type did not match node type");
        }
        DataNode.Builder superBldr = InnerNode.builder(key.schemaId().name(), key.schemaId().namespace()).type(type);
        for (KeyLeaf keyLeaf : ((ListKey) key).keyLeafs()) {
            // String tempPath = ResourceIdParser.appendKeyLeaf(spath, keyLeaf);
            // LeafNode lfnd = readLeaf(tempPath);
            superBldr.addKeyLeaf(keyLeaf.leafSchema().name(), keyLeaf.leafSchema().namespace(), String.valueOf(keyLeaf.leafValue()));
        }
        readInner(superBldr, spath);
        retVal = superBldr.build();
    } else {
        throw new FailedException("Invalid node type");
    }
    if (retVal != null) {
        eventFuture = CompletableFuture.completedFuture(retVal);
    } else {
        log.info("STORE: Failed to READ node");
    }
    return eventFuture;
}
Also used : Versioned(org.onosproject.store.service.Versioned) DataNode(org.onosproject.yang.model.DataNode) FailedException(org.onosproject.config.FailedException) KeyLeaf(org.onosproject.yang.model.KeyLeaf) DocumentPath(org.onosproject.store.service.DocumentPath) NodeKey(org.onosproject.yang.model.NodeKey)

Example 8 with FailedException

use of org.onosproject.config.FailedException 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 9 with FailedException

use of org.onosproject.config.FailedException 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)

Example 10 with FailedException

use of org.onosproject.config.FailedException in project onos by opennetworkinglab.

the class DynamicConfigManager method invokeRpc.

@Override
public CompletableFuture<RpcOutput> invokeRpc(RpcInput input) {
    checkNotNull(input);
    checkNotNull(input.id());
    RpcContext context = contextProvider.getRpcContext(input.id());
    String srvcIntf = context.serviceIntf().getName();
    RpcService handler = handlerRegistry.get(srvcIntf);
    if (handler == null) {
        throw new FailedException("No registered handler found, cannot invoke");
    }
    return CompletableFuture.supplyAsync(new RpcExecutor(handler, getSvcId(handler, srvcIntf), context.rpcName(), RpcMessageId.generate(), input));
}
Also used : RpcContext(org.onosproject.yang.model.RpcContext) RpcExecutor(org.onosproject.config.RpcExecutor) FailedException(org.onosproject.config.FailedException) RpcService(org.onosproject.yang.model.RpcService)

Aggregations

FailedException (org.onosproject.config.FailedException)10 DataNode (org.onosproject.yang.model.DataNode)8 Versioned (org.onosproject.store.service.Versioned)4 RestconfException (org.onosproject.restconf.api.RestconfException)3 RestconfUtils.convertJsonToDataNode (org.onosproject.restconf.utils.RestconfUtils.convertJsonToDataNode)3 LinkedHashMap (java.util.LinkedHashMap)2 Map (java.util.Map)2 ConsistentMap (org.onosproject.store.service.ConsistentMap)2 DocumentPath (org.onosproject.store.service.DocumentPath)2 DefaultResourceData (org.onosproject.yang.model.DefaultResourceData)2 LeafNode (org.onosproject.yang.model.LeafNode)2 LeafType (org.onosproject.yang.model.LeafType)2 NodeKey (org.onosproject.yang.model.NodeKey)2 ResourceData (org.onosproject.yang.model.ResourceData)2 ResourceId (org.onosproject.yang.model.ResourceId)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 Filter (org.onosproject.config.Filter)1 RpcExecutor (org.onosproject.config.RpcExecutor)1 InnerNode (org.onosproject.yang.model.InnerNode)1 KeyLeaf (org.onosproject.yang.model.KeyLeaf)1