ONOS-6185
[ONOS-YANG-DEMO1]Delete operation is not deleting from store
Change-Id: Id053bedb73cfb8914a5b46811ac934ed0d540cad
diff --git a/apps/config/src/main/java/org/onosproject/config/impl/DistributedDynamicConfigStore.java b/apps/config/src/main/java/org/onosproject/config/impl/DistributedDynamicConfigStore.java
index e4fcb0e..dcc84fa 100644
--- a/apps/config/src/main/java/org/onosproject/config/impl/DistributedDynamicConfigStore.java
+++ b/apps/config/src/main/java/org/onosproject/config/impl/DistributedDynamicConfigStore.java
@@ -269,9 +269,9 @@
DocumentPath.from(spath));
Map<String, Versioned<DataNode.Type>> entries = null;
entries = complete(ret);
- if ((entries == null) || (entries.size() == 0)) {
+ /*if ((entries == null) || (entries.size() == 0)) {
throw new FailedException("Inner node cannot have empty children map");
- }
+ }*/
entries.forEach((k, v) -> {
String[] names = k.split(ResourceIdParser.NM_CHK);
String name = names[0];
@@ -338,6 +338,43 @@
throw new FailedException("Not yet implemented");
}
+ 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.size() == 0)) {
+ throw new FailedException("Inner node cannot have empty children map");
+ }*/
+ 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");
+ }
+ });
+ keystore.removeNode(DocumentPath.from(spath));
+ }
+
+ private void removeLeaf(String path) {
+ keystore.removeNode(DocumentPath.from(path));
+ objectStore.remove(path);
+ }
+
@Override
public CompletableFuture<Boolean> deleteNodeRecursive(ResourceId path) {
List<NodeKey> nodeKeyList = path.nodeKeys();
@@ -346,19 +383,33 @@
nodeKeyList.remove(0);
}
String spath = ResourceIdParser.parseResId(path);
+ if (spath == null) {
+ throw new FailedException("Invalid RsourceId, cannot create 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>> vtype = keystore.removeNode(dpath);
- type = completeVersioned(vtype);
+ CompletableFuture<Versioned<DataNode.Type>> ret = keystore.get(dpath);
+ type = completeVersioned(ret);
if (type == null) {
- throw new FailedException("Node delete failed");
+ throw new FailedException("Cannot delete, Requested node or some of the parents" +
+ "are not present in the requested path");
}
- Versioned<LeafNode> res = objectStore.remove(spath);
- if (res == null) {
- return CompletableFuture.completedFuture(false);
+ 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 {
- return CompletableFuture.completedFuture(true);
+ throw new FailedException("Invalid node type");
}
+ return CompletableFuture.completedFuture(true);
}
public class InternalDocTreeListener implements DocumentTreeListener<DataNode.Type> {
diff --git a/apps/netconf/client/src/main/java/org/onosproject/netconf/client/impl/NetconfActiveComponent.java b/apps/netconf/client/src/main/java/org/onosproject/netconf/client/impl/NetconfActiveComponent.java
index ae6b453..b1b2f33 100644
--- a/apps/netconf/client/src/main/java/org/onosproject/netconf/client/impl/NetconfActiveComponent.java
+++ b/apps/netconf/client/src/main/java/org/onosproject/netconf/client/impl/NetconfActiveComponent.java
@@ -269,22 +269,23 @@
//checkIfRelevant already filters only the relevant events
event = e;
checkNotNull(event, "process:Event cannot be null");
- Filter filt = new Filter();
- DataNode node = cfgService.readNode(event.subject(), filt);
- DeviceId deviceId = getDeviceId(node);
- if (!isMaster(deviceId)) {
- log.info("NetConfListener: not master, ignoring config for {}", event.type());
- return;
- }
- initiateConnection(deviceId);
switch (event.type()) {
case NODE_ADDED:
case NODE_UPDATED:
case NODE_REPLACED:
+ Filter filt = new Filter();
+ DataNode node = cfgService.readNode(event.subject(), filt);
+ DeviceId deviceId = getDeviceId(node);
+ if (!isMaster(deviceId)) {
+ log.info("NetConfListener: not master, ignoring config for {}", event.type());
+ return;
+ }
+ initiateConnection(deviceId);
configUpdate(node, deviceId, event.subject());
break;
case NODE_DELETED:
- configDelete(node, deviceId, event.subject());
+ log.info("NetConfListener: RXD DELETE EVT for {}", event.type());
+ //configDelete(null, null, event.subject());
break;
case UNKNOWN_OPRN:
default: