Search in sources :

Example 6 with UserMapNode

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

the class BrokerFacade method postData.

private void postData(final DOMDataTreeReadWriteTransaction rwTransaction, final LogicalDatastoreType datastore, final YangInstanceIdentifier path, final NormalizedNode payload, final EffectiveModelContext schemaContext, final String insert, final String point) {
    if (insert == null) {
        makeNormalPost(rwTransaction, datastore, path, payload, schemaContext);
        return;
    }
    final DataSchemaNode schemaNode = checkListAndOrderedType(schemaContext, path);
    checkItemDoesNotExists(rwTransaction, datastore, path);
    switch(insert) {
        case "first":
            if (schemaNode instanceof ListSchemaNode) {
                final UserMapNode readList = (UserMapNode) this.readConfigurationData(path.getParent().getParent());
                if (readList == null || readList.isEmpty()) {
                    simplePostPut(rwTransaction, datastore, path, payload, schemaContext);
                } else {
                    rwTransaction.delete(datastore, path.getParent().getParent());
                    simplePostPut(rwTransaction, datastore, path, payload, schemaContext);
                    makeNormalPost(rwTransaction, datastore, path.getParent().getParent(), readList, schemaContext);
                }
            } else {
                final UserLeafSetNode<?> readLeafList = (UserLeafSetNode<?>) readConfigurationData(path.getParent());
                if (readLeafList == null || readLeafList.isEmpty()) {
                    simplePostPut(rwTransaction, datastore, path, payload, schemaContext);
                } else {
                    rwTransaction.delete(datastore, path.getParent());
                    simplePostPut(rwTransaction, datastore, path, payload, schemaContext);
                    makeNormalPost(rwTransaction, datastore, path.getParent().getParent(), readLeafList, schemaContext);
                }
            }
            break;
        case "last":
            simplePostPut(rwTransaction, datastore, path, payload, schemaContext);
            break;
        case "before":
            if (schemaNode instanceof ListSchemaNode) {
                final UserMapNode readList = (UserMapNode) this.readConfigurationData(path.getParent().getParent());
                if (readList == null || readList.isEmpty()) {
                    simplePostPut(rwTransaction, datastore, path, payload, schemaContext);
                } else {
                    insertWithPointListPost(rwTransaction, datastore, path, payload, schemaContext, point, readList, true);
                }
            } else {
                final UserLeafSetNode<?> readLeafList = (UserLeafSetNode<?>) readConfigurationData(path.getParent());
                if (readLeafList == null || readLeafList.isEmpty()) {
                    simplePostPut(rwTransaction, datastore, path, payload, schemaContext);
                } else {
                    insertWithPointLeafListPost(rwTransaction, datastore, path, payload, schemaContext, point, readLeafList, true);
                }
            }
            break;
        case "after":
            if (schemaNode instanceof ListSchemaNode) {
                final UserMapNode readList = (UserMapNode) this.readConfigurationData(path.getParent().getParent());
                if (readList == null || readList.isEmpty()) {
                    simplePostPut(rwTransaction, datastore, path, payload, schemaContext);
                } else {
                    insertWithPointListPost(rwTransaction, datastore, path, payload, schemaContext, point, readList, false);
                }
            } else {
                final UserLeafSetNode<?> readLeafList = (UserLeafSetNode<?>) readConfigurationData(path.getParent());
                if (readLeafList == null || readLeafList.isEmpty()) {
                    simplePostPut(rwTransaction, datastore, path, payload, schemaContext);
                } else {
                    insertWithPointLeafListPost(rwTransaction, datastore, path, payload, schemaContext, point, readLeafList, false);
                }
            }
            break;
        default:
            throw new RestconfDocumentedException("Used bad value of insert parameter. Possible values are first, last, before or after, " + "but was: " + insert);
    }
}
Also used : RestconfDocumentedException(org.opendaylight.restconf.common.errors.RestconfDocumentedException) DataSchemaNode(org.opendaylight.yangtools.yang.model.api.DataSchemaNode) ListSchemaNode(org.opendaylight.yangtools.yang.model.api.ListSchemaNode) LeafListSchemaNode(org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode) UserMapNode(org.opendaylight.yangtools.yang.data.api.schema.UserMapNode) UserLeafSetNode(org.opendaylight.yangtools.yang.data.api.schema.UserLeafSetNode)

Example 7 with UserMapNode

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

the class DepthAwareNormalizedNodeWriter method wasProcessedAsCompositeNode.

private boolean wasProcessedAsCompositeNode(final NormalizedNode node) throws IOException {
    boolean processedAsCompositeNode = false;
    if (node instanceof ContainerNode) {
        final ContainerNode n = (ContainerNode) node;
        writer.startContainerNode(n.getIdentifier(), childSizeHint(n.body()));
        currentDepth++;
        processedAsCompositeNode = writeChildren(n.body());
        currentDepth--;
    } else if (node instanceof MapEntryNode) {
        processedAsCompositeNode = writeMapEntryNode((MapEntryNode) node);
    } else if (node instanceof UnkeyedListEntryNode) {
        final UnkeyedListEntryNode n = (UnkeyedListEntryNode) node;
        writer.startUnkeyedListItem(n.getIdentifier(), childSizeHint(n.body()));
        currentDepth++;
        processedAsCompositeNode = writeChildren(n.body());
        currentDepth--;
    } else if (node instanceof ChoiceNode) {
        final ChoiceNode n = (ChoiceNode) node;
        writer.startChoiceNode(n.getIdentifier(), childSizeHint(n.body()));
        processedAsCompositeNode = writeChildren(n.body());
    } else if (node instanceof AugmentationNode) {
        final AugmentationNode n = (AugmentationNode) node;
        writer.startAugmentationNode(n.getIdentifier());
        processedAsCompositeNode = writeChildren(n.body());
    } else if (node instanceof UnkeyedListNode) {
        final UnkeyedListNode n = (UnkeyedListNode) node;
        writer.startUnkeyedList(n.getIdentifier(), childSizeHint(n.body()));
        processedAsCompositeNode = writeChildren(n.body());
    } else if (node instanceof UserMapNode) {
        final UserMapNode n = (UserMapNode) node;
        writer.startOrderedMapNode(n.getIdentifier(), childSizeHint(n.body()));
        processedAsCompositeNode = writeChildren(n.body());
    } else if (node instanceof MapNode) {
        final MapNode n = (MapNode) node;
        writer.startMapNode(n.getIdentifier(), childSizeHint(n.body()));
        processedAsCompositeNode = writeChildren(n.body());
    } else if (node instanceof LeafSetNode) {
        final LeafSetNode<?> n = (LeafSetNode<?>) node;
        if (node instanceof UserLeafSetNode) {
            writer.startOrderedLeafSet(n.getIdentifier(), childSizeHint(n.body()));
        } else {
            writer.startLeafSet(n.getIdentifier(), childSizeHint(n.body()));
        }
        currentDepth++;
        processedAsCompositeNode = writeChildren(n.body());
        currentDepth--;
    }
    return processedAsCompositeNode;
}
Also used : UnkeyedListEntryNode(org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListEntryNode) ChoiceNode(org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) UserMapNode(org.opendaylight.yangtools.yang.data.api.schema.UserMapNode) MapNode(org.opendaylight.yangtools.yang.data.api.schema.MapNode) UserMapNode(org.opendaylight.yangtools.yang.data.api.schema.UserMapNode) MapEntryNode(org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode) AugmentationNode(org.opendaylight.yangtools.yang.data.api.schema.AugmentationNode) UserLeafSetNode(org.opendaylight.yangtools.yang.data.api.schema.UserLeafSetNode) LeafSetNode(org.opendaylight.yangtools.yang.data.api.schema.LeafSetNode) UnkeyedListNode(org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListNode) UserLeafSetNode(org.opendaylight.yangtools.yang.data.api.schema.UserLeafSetNode)

Example 8 with UserMapNode

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

the class SerializationUtilsTest method createNormalizedNode.

private static NormalizedNode createNormalizedNode() {
    final LeafSetNode<Object> leafSetNode = Builders.leafSetBuilder().withNodeIdentifier(id("leafSetNode")).withChild(createLeafSetEntry("leafSetNode", "leafSetValue1")).withChild(createLeafSetEntry("leafSetNode", "leafSetValue2")).build();
    final LeafSetNode<Object> orderedLeafSetNode = Builders.orderedLeafSetBuilder().withNodeIdentifier(id("orderedLeafSetNode")).withChild(createLeafSetEntry("orderedLeafSetNode", "value1")).withChild(createLeafSetEntry("orderedLeafSetNode", "value2")).build();
    final LeafNode<Boolean> booleanLeaf = createLeaf("booleanLeaf", true);
    final LeafNode<Byte> byteLeaf = createLeaf("byteLeaf", (byte) 0);
    final LeafNode<Short> shortLeaf = createLeaf("shortLeaf", (short) 55);
    final LeafNode<Integer> intLeaf = createLeaf("intLeaf", 11);
    final LeafNode<Long> longLeaf = createLeaf("longLeaf", 151515L);
    final LeafNode<String> stringLeaf = createLeaf("stringLeaf", "stringValue");
    final LeafNode<String> longStringLeaf = createLeaf("longStringLeaf", getLongString());
    final LeafNode<QName> qNameLeaf = createLeaf("stringLeaf", QName.create("base", "qName"));
    final LeafNode<YangInstanceIdentifier> idLeaf = createLeaf("stringLeaf", YangInstanceIdentifier.empty());
    final MapEntryNode entry1 = Builders.mapEntryBuilder().withNodeIdentifier(listId("mapNode", "key", "key1")).withChild(stringLeaf).build();
    final MapEntryNode entry2 = Builders.mapEntryBuilder().withNodeIdentifier(listId("mapNode", "key", "key2")).withChild(stringLeaf).build();
    final MapNode mapNode = Builders.mapBuilder().withNodeIdentifier(id("mapNode")).withChild(entry1).withChild(entry2).build();
    final UserMapNode orderedMapNode = Builders.orderedMapBuilder().withNodeIdentifier(id("orderedMapNode")).withChild(entry2).withChild(entry1).build();
    final UnkeyedListEntryNode unkeyedListEntry1 = Builders.unkeyedListEntryBuilder().withNodeIdentifier(id("unkeyedList")).withChild(stringLeaf).build();
    final UnkeyedListEntryNode unkeyedListEntry2 = Builders.unkeyedListEntryBuilder().withNodeIdentifier(id("unkeyedList")).withChild(stringLeaf).build();
    final UnkeyedListNode unkeyedListNode = Builders.unkeyedListBuilder().withNodeIdentifier(id("unkeyedList")).withChild(unkeyedListEntry1).withChild(unkeyedListEntry2).build();
    final ImmutableSet<QName> childNames = ImmutableSet.of(QName.create(CONTAINER_Q_NAME, "aug1"), QName.create(CONTAINER_Q_NAME, "aug1"));
    final AugmentationNode augmentationNode = Builders.augmentationBuilder().withNodeIdentifier(new YangInstanceIdentifier.AugmentationIdentifier(childNames)).withChild(createLeaf("aug1", "aug1Value")).withChild(createLeaf("aug2", "aug2Value")).build();
    final ChoiceNode choiceNode = Builders.choiceBuilder().withNodeIdentifier(id("choiceNode")).withChild(createLeaf("choiceLeaf", 12)).build();
    return Builders.containerBuilder().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(CONTAINER_Q_NAME)).withChild(booleanLeaf).withChild(byteLeaf).withChild(shortLeaf).withChild(intLeaf).withChild(longLeaf).withChild(stringLeaf).withChild(longStringLeaf).withChild(qNameLeaf).withChild(idLeaf).withChild(mapNode).withChild(orderedMapNode).withChild(unkeyedListNode).withChild(leafSetNode).withChild(orderedLeafSetNode).withChild(augmentationNode).withChild(choiceNode).build();
}
Also used : AugmentationIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier) UnkeyedListEntryNode(org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListEntryNode) MapNode(org.opendaylight.yangtools.yang.data.api.schema.MapNode) UserMapNode(org.opendaylight.yangtools.yang.data.api.schema.UserMapNode) ChoiceNode(org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode) UserMapNode(org.opendaylight.yangtools.yang.data.api.schema.UserMapNode) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) UnkeyedListNode(org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListNode) QName(org.opendaylight.yangtools.yang.common.QName) MapEntryNode(org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) AugmentationNode(org.opendaylight.yangtools.yang.data.api.schema.AugmentationNode)

Example 9 with UserMapNode

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

the class OrderedListTest method modification4.

public void modification4() throws DataValidationFailedException {
    DataTreeModification treeModification1 = inMemoryDataTree.takeSnapshot().newModification();
    DataTreeModification treeModification2 = inMemoryDataTree.takeSnapshot().newModification();
    UserMapNode parentOrderedListNode = Builders.orderedMapBuilder().withNodeIdentifier(new NodeIdentifier(parentOrderedList)).withChild(createParentOrderedListEntry("pkval1", "plfval1")).build();
    UserMapNode parentOrderedListNode2 = Builders.orderedMapBuilder().withNodeIdentifier(new NodeIdentifier(parentOrderedList)).withChild(createParentOrderedListEntry("pkval2", "plfval2")).build();
    ContainerNode parentContainerNode = Builders.containerBuilder().withNodeIdentifier(new NodeIdentifier(parentContainer)).withChild(Builders.containerBuilder().withNodeIdentifier(new NodeIdentifier(childContainer)).withChild(parentOrderedListNode).build()).build();
    ContainerNode parentContainerNode2 = Builders.containerBuilder().withNodeIdentifier(new NodeIdentifier(parentContainer)).withChild(Builders.containerBuilder().withNodeIdentifier(new NodeIdentifier(childContainer)).withChild(parentOrderedListNode2).build()).build();
    YangInstanceIdentifier path = YangInstanceIdentifier.of(parentContainer);
    treeModification1.write(path, parentContainerNode);
    treeModification2.write(path, parentContainerNode2);
    treeModification1.ready();
    treeModification2.ready();
    inMemoryDataTree.validate(treeModification1);
    inMemoryDataTree.commit(inMemoryDataTree.prepare(treeModification1));
    try {
        inMemoryDataTree.validate(treeModification2);
        fail("Exception should have been thrown.");
        inMemoryDataTree.commit(inMemoryDataTree.prepare(treeModification2));
    } catch (ConflictingModificationAppliedException ex) {
        LOG.debug("ConflictingModificationAppliedException was thrown as expected", ex);
        assertTrue(ex.getMessage().contains("Node was replaced by other transaction"));
    }
    DataTreeSnapshot snapshotAfterCommits = inMemoryDataTree.takeSnapshot();
    Optional<NormalizedNode> readNode = snapshotAfterCommits.readNode(path);
    assertTrue(readNode.isPresent());
}
Also used : DataTreeModification(org.opendaylight.yangtools.yang.data.tree.api.DataTreeModification) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) ConflictingModificationAppliedException(org.opendaylight.yangtools.yang.data.tree.api.ConflictingModificationAppliedException) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) UserMapNode(org.opendaylight.yangtools.yang.data.api.schema.UserMapNode) DataTreeSnapshot(org.opendaylight.yangtools.yang.data.tree.api.DataTreeSnapshot) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)

Example 10 with UserMapNode

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

the class OrderedListTest method modification3.

public void modification3() throws DataValidationFailedException {
    UserMapNode parentOrderedListNode = Builders.orderedMapBuilder().withNodeIdentifier(new NodeIdentifier(parentOrderedList)).withChild(createParentOrderedListEntry("pkval1", "plfval1")).build();
    ContainerNode parentContainerNode = Builders.containerBuilder().withNodeIdentifier(new NodeIdentifier(parentContainer)).withChild(Builders.containerBuilder().withNodeIdentifier(new NodeIdentifier(childContainer)).withChild(parentOrderedListNode).build()).build();
    YangInstanceIdentifier path1 = YangInstanceIdentifier.of(parentContainer);
    DataTreeModification treeModification = inMemoryDataTree.takeSnapshot().newModification();
    treeModification.write(path1, parentContainerNode);
    UserMapNode childOrderedListNode = Builders.orderedMapBuilder().withNodeIdentifier(new NodeIdentifier(childOrderedList)).withChild(createChildOrderedListEntry("chkval1", "chlfval1new")).build();
    YangInstanceIdentifier path2 = YangInstanceIdentifier.of(parentContainer).node(childContainer).node(parentOrderedList).node(createParentOrderedListEntryPath("pkval4")).node(childOrderedList);
    treeModification.merge(path2, childOrderedListNode);
    try {
        treeModification.ready();
        fail("Exception should have been thrown.");
        inMemoryDataTree.validate(treeModification);
        inMemoryDataTree.commit(inMemoryDataTree.prepare(treeModification));
    } catch (final IllegalArgumentException ex) {
        LOG.debug("IllegalArgumentException was thrown as expected", ex);
        assertTrue(ex.getMessage().contains("Metadata not available for modification ModifiedNode"));
    }
    DataTreeSnapshot snapshotAfterCommits = inMemoryDataTree.takeSnapshot();
    Optional<NormalizedNode> readNode = snapshotAfterCommits.readNode(path1);
    assertTrue(readNode.isPresent());
    readNode = snapshotAfterCommits.readNode(path2);
    assertFalse(readNode.isPresent());
}
Also used : DataTreeModification(org.opendaylight.yangtools.yang.data.tree.api.DataTreeModification) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) UserMapNode(org.opendaylight.yangtools.yang.data.api.schema.UserMapNode) DataTreeSnapshot(org.opendaylight.yangtools.yang.data.tree.api.DataTreeSnapshot) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)

Aggregations

UserMapNode (org.opendaylight.yangtools.yang.data.api.schema.UserMapNode)18 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)11 NodeIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier)8 MapEntryNode (org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode)8 AugmentationNode (org.opendaylight.yangtools.yang.data.api.schema.AugmentationNode)7 ChoiceNode (org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode)7 UnkeyedListEntryNode (org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListEntryNode)7 UnkeyedListNode (org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListNode)7 MapNode (org.opendaylight.yangtools.yang.data.api.schema.MapNode)6 UserLeafSetNode (org.opendaylight.yangtools.yang.data.api.schema.UserLeafSetNode)6 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)5 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)5 Test (org.junit.Test)4 QName (org.opendaylight.yangtools.yang.common.QName)4 AugmentationIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier)4 SystemMapNode (org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode)4 DataTreeModification (org.opendaylight.yangtools.yang.data.tree.api.DataTreeModification)4 DataTreeSnapshot (org.opendaylight.yangtools.yang.data.tree.api.DataTreeSnapshot)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3