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 <robert.varga@pantheon.tech>
}
private Optional<NormalizedNode> aggregate() throws DataValidationFailedException {
}
private Optional<NormalizedNode> aggregate() throws DataValidationFailedException {
- return combine().getRootNode();
- }
-
- private NormalizedNodeAggregator combine() throws DataValidationFailedException {
final DataTreeModification mod = dataTree.takeSnapshot().newModification();
final DataTreeModification mod = dataTree.takeSnapshot().newModification();
+ boolean nodePresent = false;
for (final Optional<NormalizedNode> node : nodes) {
if (node.isPresent()) {
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);
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);
}
}
return dataTree.takeSnapshot().readNode(rootIdentifier);
}
}