Search in sources :

Example 11 with DataTreeCandidateNode

use of org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidateNode in project yangtools by opendaylight.

the class LeafRefValidation method validateNode.

private void validateNode(final DataTreeCandidateNode node, final LeafRefContext referencedByCtx, final LeafRefContext referencingCtx, final YangInstanceIdentifier current) {
    if (node.getModificationType() == ModificationType.WRITE && node.getDataAfter().isPresent()) {
        validateNodeData(node.getDataAfter().get(), referencedByCtx, referencingCtx, node.getModificationType(), current);
        return;
    }
    if (node.getModificationType() == ModificationType.DELETE && referencedByCtx != null) {
        validateNodeData(node.getDataBefore().get(), referencedByCtx, null, node.getModificationType(), current);
        return;
    }
    for (final DataTreeCandidateNode childNode : node.getChildNodes()) {
        if (childNode.getModificationType() != ModificationType.UNMODIFIED) {
            final LeafRefContext childReferencedByCtx = getReferencedByCtxChild(referencedByCtx, childNode);
            final LeafRefContext childReferencingCtx = getReferencingCtxChild(referencingCtx, childNode);
            if (childReferencedByCtx != null || childReferencingCtx != null) {
                validateNode(childNode, childReferencedByCtx, childReferencingCtx, current.node(childNode.getIdentifier()));
            }
        }
    }
}
Also used : DataTreeCandidateNode(org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidateNode)

Example 12 with DataTreeCandidateNode

use of org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidateNode in project yangtools by opendaylight.

the class DataTreeCandidatesTest method testEmptyMergesOnExisting.

@Test
public void testEmptyMergesOnExisting() throws DataValidationFailedException {
    // Make sure 'non-presence' is present
    DataTreeModification modification = dataTree.takeSnapshot().newModification();
    modification.write(TestModel.NAME_PATH, ImmutableNodes.leafNode(TestModel.NAME_QNAME, "foo"));
    modification.ready();
    dataTree.validate(modification);
    dataTree.commit(dataTree.prepare(modification));
    // Issue an empty merge on it and a child choice
    modification = dataTree.takeSnapshot().newModification();
    modification.merge(TestModel.NON_PRESENCE_PATH, ImmutableNodes.containerNode(TestModel.NON_PRESENCE_QNAME));
    modification.merge(TestModel.DEEP_CHOICE_PATH, ImmutableNodes.choiceNode(TestModel.DEEP_CHOICE_QNAME));
    modification.ready();
    dataTree.validate(modification);
    // The entire transaction needs to fizzle to a no-op
    final DataTreeCandidate candidate = dataTree.prepare(modification);
    assertEquals(YangInstanceIdentifier.empty(), candidate.getRootPath());
    final DataTreeCandidateNode node = candidate.getRootNode();
    assertEquals(ModificationType.UNMODIFIED, node.getModificationType());
    // 'non-presence' and 'test'
    assertUnmodified(2, node.getChildNodes());
}
Also used : DataTreeModification(org.opendaylight.yangtools.yang.data.tree.api.DataTreeModification) DataTreeCandidate(org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidate) DataTreeCandidateNode(org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidateNode) Test(org.junit.Test)

Example 13 with DataTreeCandidateNode

use of org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidateNode in project yangtools by opendaylight.

the class DataTreeCandidatesTest method testEmptyWriteOnContainer.

@Test
public void testEmptyWriteOnContainer() throws DataValidationFailedException {
    DataTreeModification modification = dataTree.takeSnapshot().newModification();
    modification.write(TestModel.NON_PRESENCE_PATH, ImmutableNodes.containerNode(TestModel.NON_PRESENCE_QNAME));
    modification.ready();
    dataTree.validate(modification);
    // The entire transaction needs to fizzle to a no-op
    DataTreeCandidate candidate = dataTree.prepare(modification);
    DataTreeCandidateNode node = candidate.getRootNode();
    assertEquals(ModificationType.UNMODIFIED, node.getModificationType());
    // 'test'
    assertUnmodified(1, node.getChildNodes());
}
Also used : DataTreeModification(org.opendaylight.yangtools.yang.data.tree.api.DataTreeModification) DataTreeCandidate(org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidate) DataTreeCandidateNode(org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidateNode) Test(org.junit.Test)

Example 14 with DataTreeCandidateNode

use of org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidateNode in project yangtools by opendaylight.

the class DataTreeCandidatesTest method testEmptyMergesOnDeleted.

@Test
public void testEmptyMergesOnDeleted() throws DataValidationFailedException {
    DataTreeModification modification = dataTree.takeSnapshot().newModification();
    modification.delete(TestModel.NON_PRESENCE_PATH);
    modification.merge(TestModel.DEEP_CHOICE_PATH, ImmutableNodes.choiceNode(TestModel.DEEP_CHOICE_QNAME));
    modification.ready();
    dataTree.validate(modification);
    final DataTreeCandidate candidate = dataTree.prepare(modification);
    assertEquals(YangInstanceIdentifier.empty(), candidate.getRootPath());
    final DataTreeCandidateNode node = candidate.getRootNode();
    assertEquals(ModificationType.UNMODIFIED, node.getModificationType());
    // 'test'
    assertUnmodified(1, node.getChildNodes());
}
Also used : DataTreeModification(org.opendaylight.yangtools.yang.data.tree.api.DataTreeModification) DataTreeCandidate(org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidate) DataTreeCandidateNode(org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidateNode) Test(org.junit.Test)

Example 15 with DataTreeCandidateNode

use of org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidateNode in project yangtools by opendaylight.

the class DataTreeCandidates method cleanUpTree.

// Compare data before and after in order to find modified nodes without actual changes
private static DataTreeCandidateNode cleanUpTree(final TerminalDataTreeCandidateNode finalNode, final TerminalDataTreeCandidateNode node) {
    PathArgument identifier = node.getIdentifier();
    ModificationType nodeModification = node.getModificationType();
    Collection<DataTreeCandidateNode> childNodes = node.getChildNodes();
    for (DataTreeCandidateNode childNode : childNodes) {
        cleanUpTree(finalNode, (TerminalDataTreeCandidateNode) childNode);
    }
    Optional<NormalizedNode> dataBefore = finalNode.getDataBefore(identifier);
    switch(nodeModification) {
        case UNMODIFIED:
            finalNode.deleteNode(identifier);
            return finalNode;
        case WRITE:
            return finalNode;
        case DELETE:
            if (dataBefore.isEmpty()) {
                finalNode.deleteNode(identifier);
            }
            return finalNode;
        case APPEARED:
            if (dataBefore.isPresent()) {
                illegalModification(ModificationType.APPEARED, ModificationType.WRITE);
            }
            if (childNodes.isEmpty()) {
                finalNode.deleteNode(identifier);
            }
            return finalNode;
        case DISAPPEARED:
            if (dataBefore.isEmpty() || childNodes.isEmpty()) {
                finalNode.deleteNode(identifier);
            }
            return finalNode;
        case SUBTREE_MODIFIED:
            if (dataBefore.isEmpty()) {
                illegalModification(ModificationType.SUBTREE_MODIFIED, ModificationType.DELETE);
            }
            if (childNodes.isEmpty()) {
                finalNode.deleteNode(identifier);
            }
            return finalNode;
        default:
            throw new IllegalStateException("Unsupported modification type " + nodeModification);
    }
}
Also used : ModificationType(org.opendaylight.yangtools.yang.data.tree.api.ModificationType) DataTreeCandidateNode(org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidateNode) PathArgument(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)

Aggregations

DataTreeCandidateNode (org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidateNode)63 Test (org.junit.Test)48 DataTreeCandidate (org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidate)36 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)23 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)15 DataTreeModificationCursor (org.opendaylight.yangtools.yang.data.tree.api.DataTreeModificationCursor)13 DataTreeModification (org.opendaylight.yangtools.yang.data.tree.api.DataTreeModification)9 PathArgument (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument)7 CursorAwareDataTreeModification (org.opendaylight.yangtools.yang.data.tree.api.CursorAwareDataTreeModification)7 CountDownLatch (java.util.concurrent.CountDownLatch)6 DOMDataTreeChangeService (org.opendaylight.mdsal.dom.api.DOMDataTreeChangeService)6 DOMDataTreeWriteTransaction (org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction)6 ArrayList (java.util.ArrayList)5 NonNull (org.eclipse.jdt.annotation.NonNull)3 ModificationType (org.opendaylight.yangtools.yang.data.tree.api.ModificationType)3 Objects.requireNonNull (java.util.Objects.requireNonNull)2 List (java.util.List)1 BindingCodecTreeNode (org.opendaylight.mdsal.binding.dom.codec.api.BindingCodecTreeNode)1 BindingDataObjectCodecTreeNode (org.opendaylight.mdsal.binding.dom.codec.api.BindingDataObjectCodecTreeNode)1 DOMDataTreeChangeListener (org.opendaylight.mdsal.dom.api.DOMDataTreeChangeListener)1