use of org.onosproject.yang.model.DataNode in project onos by opennetworkinglab.
the class RestconfManager method executeRpc.
private RestconfRpcOutput executeRpc(URI uri, ObjectNode input, String clientIpAddress) {
ResourceData rpcInputNode = convertJsonToDataNode(uri, input);
ResourceId resourceId = rpcInputNode.resourceId();
List<DataNode> inputDataNodeList = rpcInputNode.dataNodes();
DataNode inputDataNode = inputDataNodeList.get(0);
RpcInput rpcInput = new RpcInput(resourceId, inputDataNode);
RestconfRpcOutput restconfOutput = null;
try {
CompletableFuture<RpcOutput> rpcFuture = dynamicConfigService.invokeRpc(rpcInput);
RpcOutput rpcOutput = rpcFuture.get();
restconfOutput = RestconfUtils.convertRpcOutput(resourceId, rpcOutput);
} catch (InterruptedException e) {
log.error("ERROR: computeResultQ.take() has been interrupted.");
log.debug("executeRpc Exception:", e);
RestconfError error = RestconfError.builder(RestconfError.ErrorType.RPC, RestconfError.ErrorTag.OPERATION_FAILED).errorMessage("RPC execution has been interrupted").errorPath(uri.getPath()).build();
restconfOutput = new RestconfRpcOutput(INTERNAL_SERVER_ERROR, RestconfError.wrapErrorAsJson(Arrays.asList(error)));
restconfOutput.reason("RPC execution has been interrupted");
} catch (Exception e) {
log.error("ERROR: executeRpc: {}", e.getMessage());
log.debug("executeRpc Exception:", e);
RestconfError error = RestconfError.builder(RestconfError.ErrorType.RPC, RestconfError.ErrorTag.OPERATION_FAILED).errorMessage(e.getMessage()).errorPath(uri.getPath()).build();
restconfOutput = new RestconfRpcOutput(INTERNAL_SERVER_ERROR, RestconfError.wrapErrorAsJson(Arrays.asList(error)));
restconfOutput.reason(e.getMessage());
}
return restconfOutput;
}
use of org.onosproject.yang.model.DataNode 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);
}
use of org.onosproject.yang.model.DataNode 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;
}
use of org.onosproject.yang.model.DataNode 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");
}
});
}
Aggregations