NormalizedNodeAggregator should also report empty
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / utils / NormalizedNodeAggregator.java
index b38e4ed35b2e43d9258b5b09808f381b62e43189..4a17978f1ca6b81ff737eaa838886c82e29caa1e 100644 (file)
@@ -45,26 +45,26 @@ public final class NormalizedNodeAggregator {
     }
 
     private Optional<NormalizedNode> aggregate() throws DataValidationFailedException {
-        return combine().getRootNode();
-    }
-
-    private NormalizedNodeAggregator combine() throws DataValidationFailedException {
         final DataTreeModification mod = dataTree.takeSnapshot().newModification();
+        boolean nodePresent = false;
 
         for (final Optional<NormalizedNode> node : nodes) {
             if (node.isPresent()) {
-                mod.merge(rootIdentifier, node.get());
+                mod.merge(rootIdentifier, node.orElseThrow());
+                nodePresent = true;
             }
         }
+
+        if (!nodePresent) {
+            return Optional.empty();
+        }
+
+
         mod.ready();
         dataTree.validate(mod);
         final DataTreeCandidate candidate = dataTree.prepare(mod);
         dataTree.commit(candidate);
 
-        return this;
-    }
-
-    private Optional<NormalizedNode> getRootNode() {
         return dataTree.takeSnapshot().readNode(rootIdentifier);
     }
 }