From: Robert Varga Date: Thu, 7 Apr 2022 20:23:33 +0000 (+0200) Subject: NormalizedNodeAggregator should also report empty X-Git-Tag: v5.0.2~3 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=commitdiff_plain;h=1d5ca4009be6c61d7b61989799037ad8f1ab7a75 NormalizedNodeAggregator should also report empty DataTree root is always present as of now, which means that even if we pretend there is no result, the result of aggregation is non-empty. Fix NormalizedNodeAggregator to check whether there was any operation applied before running actual transaction. JIRA: CONTROLLER-2038 Change-Id: Ie7e4625ad2377483d0623d96234bcc77fbba033d Signed-off-by: Robert Varga --- diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/utils/NormalizedNodeAggregator.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/utils/NormalizedNodeAggregator.java index b38e4ed35b..4a17978f1c 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/utils/NormalizedNodeAggregator.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/utils/NormalizedNodeAggregator.java @@ -45,26 +45,26 @@ public final class NormalizedNodeAggregator { } private Optional aggregate() throws DataValidationFailedException { - return combine().getRootNode(); - } - - private NormalizedNodeAggregator combine() throws DataValidationFailedException { final DataTreeModification mod = dataTree.takeSnapshot().newModification(); + boolean nodePresent = false; for (final Optional 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 getRootNode() { return dataTree.takeSnapshot().readNode(rootIdentifier); } }