Search in sources :

Example 1 with DistinctNodeContainer

use of org.opendaylight.yangtools.yang.data.api.schema.DistinctNodeContainer in project yangtools by opendaylight.

the class AbstractNodeContainerModificationStrategy method applyMerge.

@Override
protected TreeNode applyMerge(final ModifiedNode modification, final TreeNode currentMeta, final Version version) {
    /*
         * The node which we are merging exists. We now need to expand any child operations implied by the value. Once
         * we do that, ModifiedNode children will look like this node were a TOUCH and we will let applyTouch() do the
         * heavy lifting of applying the children recursively (either through here or through applyWrite().
         */
    final NormalizedNode value = modification.getWrittenValue();
    Verify.verify(value instanceof DistinctNodeContainer, "Attempted to merge non-container %s", value);
    for (final NormalizedNode c : ((DistinctNodeContainer<?, ?>) value).body()) {
        final PathArgument id = c.getIdentifier();
        modification.modifyChild(id, resolveChildOperation(id), version);
    }
    return applyTouch(modification, currentMeta, version);
}
Also used : PathArgument(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) DistinctNodeContainer(org.opendaylight.yangtools.yang.data.api.schema.DistinctNodeContainer)

Example 2 with DistinctNodeContainer

use of org.opendaylight.yangtools.yang.data.api.schema.DistinctNodeContainer in project yangtools by opendaylight.

the class Bug4454Test method minMaxLeafListPass.

@Test
public void minMaxLeafListPass() throws DataValidationFailedException {
    final DataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification();
    final NodeWithValue<?> barPath = new NodeWithValue<>(MIN_MAX_LIST_QNAME, "bar");
    final NodeWithValue<?> gooPath = new NodeWithValue<>(MIN_MAX_LIST_QNAME, "goo");
    final LeafSetEntryNode<Object> barLeafSetEntry = ImmutableLeafSetEntryNodeBuilder.create().withNodeIdentifier(barPath).withValue("bar").build();
    final LeafSetEntryNode<Object> gooLeafSetEntry = ImmutableLeafSetEntryNodeBuilder.create().withNodeIdentifier(gooPath).withValue("goo").build();
    final LeafSetNode<Object> fooLeafSetNode = ImmutableLeafSetNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(MIN_MAX_LEAF_LIST_QNAME)).withChildValue("foo").build();
    modificationTree.write(MIN_MAX_LEAF_LIST_PATH, fooLeafSetNode);
    modificationTree.write(MIN_MAX_LEAF_LIST_PATH.node(barPath), barLeafSetEntry);
    modificationTree.ready();
    inMemoryDataTree.validate(modificationTree);
    final DataTreeCandidate prepare1 = inMemoryDataTree.prepare(modificationTree);
    inMemoryDataTree.commit(prepare1);
    DataTreeSnapshot test1 = inMemoryDataTree.takeSnapshot();
    DataTreeModification tempMod1 = test1.newModification();
    tempMod1.write(MIN_MAX_LEAF_LIST_PATH.node(gooPath), gooLeafSetEntry);
    tempMod1.write(MIN_MAX_LEAF_LIST_PATH.node(barPath), barLeafSetEntry);
    tempMod1.ready();
    inMemoryDataTree.validate(tempMod1);
    final DataTreeCandidate prepare2 = inMemoryDataTree.prepare(tempMod1);
    inMemoryDataTree.commit(prepare2);
    final DataTreeSnapshot snapshotAfterCommit = inMemoryDataTree.takeSnapshot();
    final Optional<NormalizedNode> masterContainer = snapshotAfterCommit.readNode(MASTER_CONTAINER_PATH);
    assertTrue(masterContainer.isPresent());
    final Optional<NormalizedNodeContainer<?>> leafList = ((DistinctNodeContainer) masterContainer.get()).findChildByArg(new NodeIdentifier(MIN_MAX_LEAF_LIST_QNAME));
    assertTrue(leafList.isPresent());
    assertEquals(3, leafList.get().size());
}
Also used : DataTreeModification(org.opendaylight.yangtools.yang.data.tree.api.DataTreeModification) DistinctNodeContainer(org.opendaylight.yangtools.yang.data.api.schema.DistinctNodeContainer) DataTreeCandidate(org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidate) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) NormalizedNodeContainer(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodeContainer) NodeWithValue(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeWithValue) DataTreeSnapshot(org.opendaylight.yangtools.yang.data.tree.api.DataTreeSnapshot) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) Test(org.junit.Test)

Example 3 with DistinctNodeContainer

use of org.opendaylight.yangtools.yang.data.api.schema.DistinctNodeContainer in project yangtools by opendaylight.

the class ModifiedNode method modifyChild.

/**
 * Returns child modification if child was modified, creates {@link ModifiedNode}
 * for child otherwise. If this node's {@link ModificationType} is {@link ModificationType#UNMODIFIED}
 * changes modification type to {@link ModificationType#SUBTREE_MODIFIED}.
 *
 * @param child child identifier, may not be null
 * @param childOper Child operation
 * @param modVersion Version allocated by the calling {@link InMemoryDataTreeModification}
 * @return {@link ModifiedNode} for specified child, with {@link #getOriginal()}
 *         containing child metadata if child was present in original data.
 */
ModifiedNode modifyChild(@NonNull final PathArgument child, @NonNull final ModificationApplyOperation childOper, @NonNull final Version modVersion) {
    clearSnapshot();
    if (operation == LogicalOperation.NONE) {
        updateOperationType(LogicalOperation.TOUCH);
    }
    final ModifiedNode potential = children.get(child);
    if (potential != null) {
        return potential;
    }
    final Optional<? extends TreeNode> currentMetadata = findOriginalMetadata(child, modVersion);
    final ModifiedNode newlyCreated = new ModifiedNode(child, currentMetadata, childOper.getChildPolicy());
    if (operation == LogicalOperation.MERGE && value != null) {
        /*
             * We are attempting to modify a previously-unmodified part of a MERGE node. If the
             * value contains this component, we need to materialize it as a MERGE modification.
             */
        @SuppressWarnings({ "rawtypes", "unchecked" }) final NormalizedNode childData = ((DistinctNodeContainer) value).childByArg(child);
        if (childData != null) {
            childOper.mergeIntoModifiedNode(newlyCreated, childData, modVersion);
        }
    }
    children.put(child, newlyCreated);
    return newlyCreated;
}
Also used : NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) DistinctNodeContainer(org.opendaylight.yangtools.yang.data.api.schema.DistinctNodeContainer)

Example 4 with DistinctNodeContainer

use of org.opendaylight.yangtools.yang.data.api.schema.DistinctNodeContainer in project controller by opendaylight.

the class MockDataTreeChangeListener method waitForChangeEvents.

@SuppressWarnings({ "unchecked", "rawtypes" })
public void waitForChangeEvents(final YangInstanceIdentifier... expPaths) {
    boolean done = Uninterruptibles.awaitUninterruptibly(changeLatch, 5, TimeUnit.SECONDS);
    if (!done) {
        fail(String.format("Missing change notifications. Expected: %d. Actual: %d", expChangeEventCount, expChangeEventCount - changeLatch.getCount()));
    }
    for (int i = 0; i < expPaths.length; i++) {
        final DataTreeCandidate candidate = changeList.get(i);
        final Optional<NormalizedNode> maybeDataAfter = candidate.getRootNode().getDataAfter();
        if (!maybeDataAfter.isPresent()) {
            fail(String.format("Change %d does not contain data after. Actual: %s", i + 1, candidate.getRootNode()));
        }
        final NormalizedNode dataAfter = maybeDataAfter.get();
        final Optional<YangInstanceIdentifier> relativePath = expPaths[i].relativeTo(candidate.getRootPath());
        if (!relativePath.isPresent()) {
            assertEquals(String.format("Change %d does not contain %s. Actual: %s", i + 1, expPaths[i], dataAfter), expPaths[i].getLastPathArgument(), dataAfter.getIdentifier());
        } else {
            NormalizedNode nextChild = dataAfter;
            for (PathArgument pathArg : relativePath.get().getPathArguments()) {
                boolean found = false;
                if (nextChild instanceof DistinctNodeContainer) {
                    Optional<NormalizedNode> maybeChild = ((DistinctNodeContainer) nextChild).findChildByArg(pathArg);
                    if (maybeChild.isPresent()) {
                        found = true;
                        nextChild = maybeChild.get();
                    }
                }
                if (!found) {
                    fail(String.format("Change %d does not contain %s. Actual: %s", i + 1, expPaths[i], dataAfter));
                }
            }
        }
    }
}
Also used : DataTreeCandidate(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate) PathArgument(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) DistinctNodeContainer(org.opendaylight.yangtools.yang.data.api.schema.DistinctNodeContainer)

Example 5 with DistinctNodeContainer

use of org.opendaylight.yangtools.yang.data.api.schema.DistinctNodeContainer in project yangtools by opendaylight.

the class AbstractNodeContainerModificationStrategy method verifyValueChildren.

@Override
final void verifyValueChildren(final NormalizedNode writtenValue) {
    if (verifyChildrenStructure) {
        final DistinctNodeContainer<?, ?> container = (DistinctNodeContainer<?, ?>) writtenValue;
        for (final NormalizedNode child : container.body()) {
            final ModificationApplyOperation childOp = childByArg(child.getIdentifier());
            if (childOp == null) {
                throw new SchemaValidationFailedException(String.format("Node %s is not a valid child of %s according to the schema.", child.getIdentifier(), container.getIdentifier()));
            }
            childOp.fullVerifyStructure(child);
        }
        optionalVerifyValueChildren(writtenValue);
    }
    mandatoryVerifyValueChildren(writtenValue);
}
Also used : NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) DistinctNodeContainer(org.opendaylight.yangtools.yang.data.api.schema.DistinctNodeContainer)

Aggregations

DistinctNodeContainer (org.opendaylight.yangtools.yang.data.api.schema.DistinctNodeContainer)6 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)6 PathArgument (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument)3 Test (org.junit.Test)2 List (java.util.List)1 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)1 NodeIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier)1 NodeWithValue (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeWithValue)1 NormalizedNodeContainer (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodeContainer)1 DataTreeCandidate (org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate)1 DataTreeCandidate (org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidate)1 DataTreeCandidateNode (org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidateNode)1 DataTreeModification (org.opendaylight.yangtools.yang.data.tree.api.DataTreeModification)1 DataTreeSnapshot (org.opendaylight.yangtools.yang.data.tree.api.DataTreeSnapshot)1