use of org.onosproject.config.FailedException in project onos by opennetworkinglab.
the class DistributedDynamicConfigStore method deleteInner.
private void deleteInner(String spath) {
CompletableFuture<Map<String, Versioned<DataNode.Type>>> ret = keystore.getChildren(DocumentPath.from(spath));
Map<String, Versioned<DataNode.Type>> entries = null;
entries = complete(ret);
if ((entries != null) && (!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) {
removeLeaf(tempPath);
} else if (type == DataNode.Type.MULTI_INSTANCE_LEAF_VALUE_NODE) {
String mlpath = ResourceIdParser.appendLeafList(tempPath, keyVal);
removeLeaf(mlpath);
} else if (type == DataNode.Type.SINGLE_INSTANCE_NODE) {
deleteInner(tempPath);
} else if (type == DataNode.Type.MULTI_INSTANCE_NODE) {
tempPath = ResourceIdParser.appendMultiInstKey(tempPath, k);
deleteInner(tempPath);
} else {
throw new FailedException("Invalid node type");
}
});
}
log.trace(" keystore.removeNode({})", spath);
keystore.removeNode(DocumentPath.from(spath));
}
use of org.onosproject.config.FailedException in project onos by opennetworkinglab.
the class RestconfManager method runGetOperationOnDataResource.
@Override
public ObjectNode runGetOperationOnDataResource(URI uri) throws RestconfException {
DataResourceLocator rl = DataResourceLocator.newInstance(uri);
// TODO: define Filter (if there is any requirement).
Filter filter = Filter.builder().build();
DataNode dataNode;
try {
if (!dynamicConfigService.nodeExist(rl.ridForDynConfig())) {
return null;
}
dataNode = dynamicConfigService.readNode(rl.ridForDynConfig(), filter);
} catch (FailedException e) {
log.error("ERROR: DynamicConfigService: ", e);
throw new RestconfException("ERROR: DynamicConfigService", e, RestconfError.ErrorTag.OPERATION_FAILED, INTERNAL_SERVER_ERROR, Optional.of(uri.getPath()));
}
ObjectNode rootNode = convertDataNodeToJson(rl.ridForYangRuntime(), dataNode);
return rootNode;
}
use of org.onosproject.config.FailedException in project onos by opennetworkinglab.
the class RestconfManager method runPutOperationOnDataResource.
@Override
public void runPutOperationOnDataResource(URI uri, ObjectNode rootNode) throws RestconfException {
DataResourceLocator rl = DataResourceLocator.newInstance(uri);
ResourceData receivedData = convertJsonToDataNode(rmLastPathSegment(rl.uriForYangRuntime()), rootNode);
List<DataNode> dataNodeList = receivedData.dataNodes();
if (dataNodeList == null || dataNodeList.isEmpty()) {
log.warn("There is no one Data Node can be proceed.");
return;
}
if (dataNodeList.size() > 1) {
log.warn("There are more than one Data Node can be proceed: {}", dataNodeList.size());
}
DataNode dataNode = dataNodeList.get(0);
try {
/*
* If the data node already exists, then replace it.
* Otherwise, create it.
*/
if (dynamicConfigService.nodeExist(rl.ridForDynConfig())) {
dynamicConfigService.replaceNode(parentOf(rl.ridForDynConfig()), dataNode);
} else {
dynamicConfigService.createNode(parentOf(rl.ridForDynConfig()), dataNode);
}
} catch (FailedException e) {
log.error("ERROR: DynamicConfigService: ", e);
throw new RestconfException("ERROR: DynamicConfigService", e, RestconfError.ErrorTag.OPERATION_FAILED, INTERNAL_SERVER_ERROR, Optional.of(uri.getPath()));
}
}
use of org.onosproject.config.FailedException in project onos by opennetworkinglab.
the class RestconfManager method runPatchOperationOnDataResource.
@Override
public void runPatchOperationOnDataResource(URI uri, ObjectNode rootNode) throws RestconfException {
DataResourceLocator rl = DataResourceLocator.newInstance(uri);
ResourceData receivedData = convertJsonToDataNode(rmLastPathSegment(rl.uriForYangRuntime()), rootNode);
ResourceId rid = receivedData.resourceId();
List<DataNode> dataNodeList = receivedData.dataNodes();
if (dataNodeList == null || dataNodeList.isEmpty()) {
log.warn("There is no one Data Node can be proceed.");
return;
}
if (dataNodeList.size() > 1) {
log.warn("There are more than one Data Node can be proceed: {}", dataNodeList.size());
}
DataNode dataNode = dataNodeList.get(0);
if (rid == null) {
rid = ResourceId.builder().addBranchPointSchema("/", null).build();
dataNode = removeTopNode(dataNode);
}
try {
dynamicConfigService.updateNode(parentOf(rl.ridForDynConfig()), dataNode);
} catch (FailedException e) {
log.error("ERROR: DynamicConfigService: ", e);
throw new RestconfException("ERROR: DynamicConfigService", e, RestconfError.ErrorTag.OPERATION_FAILED, INTERNAL_SERVER_ERROR, Optional.of(uri.getPath()));
}
}
use of org.onosproject.config.FailedException in project onos by opennetworkinglab.
the class DistributedDynamicConfigStore method addNode.
@Override
public CompletableFuture<Boolean> addNode(ResourceId parent, DataNode node) {
String spath = ResourceIdParser.parseResId(parent);
log.trace(" addNode({}, {})", parent, node);
log.trace(" spath={}", spath);
if (spath == null) {
throw new FailedException("Invalid ResourceId, cannot create Node");
}
if (spath.equals(ResourceIdParser.ROOT)) {
// If not present, adding static ROOT node after immutable documentTree root.
if (complete(keystore.get(DocumentPath.from(spath))) == null) {
addLeaf(spath, LeafNode.builder(DeviceResourceIds.ROOT_NAME, DCS_NAMESPACE).type(DataNode.Type.SINGLE_INSTANCE_NODE).build());
}
ResourceId abs = ResourceIds.resourceId(parent, node);
parseNode(ResourceIdParser.parseResId(abs), node);
return CompletableFuture.completedFuture(true);
} else if (complete(keystore.get(DocumentPath.from(spath))) == null) {
throw new FailedException("Node or parent does not exist for " + spath);
}
ResourceId abs = ResourceIds.resourceId(parent, node);
// spath = ResourceIdParser.appendNodeKey(spath, node.key());
parseNode(ResourceIdParser.parseResId(abs), node);
return CompletableFuture.completedFuture(true);
}
Aggregations