Search in sources :

Example 11 with SystemMapNode

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

the class BrokerFacade method buildCont.

private void buildCont(final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> builder, final ContainerNode result, final DataSchemaContextTree baseSchemaCtxTree, final YangInstanceIdentifier actualPath, final boolean trim) {
    for (final DataContainerChild child : result.body()) {
        final YangInstanceIdentifier path = actualPath.node(child.getIdentifier());
        final DataSchemaNode childSchema = baseSchemaCtxTree.findChild(path).orElseThrow().getDataSchemaNode();
        if (child instanceof ContainerNode) {
            final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> builderChild = SchemaAwareBuilders.containerBuilder((ContainerSchemaNode) childSchema);
            buildCont(builderChild, result, baseSchemaCtxTree, actualPath, trim);
            builder.withChild(builderChild.build());
        } else if (child instanceof MapNode) {
            final CollectionNodeBuilder<MapEntryNode, SystemMapNode> childBuilder = SchemaAwareBuilders.mapBuilder((ListSchemaNode) childSchema);
            buildList(childBuilder, (MapNode) child, baseSchemaCtxTree, path, trim, ((ListSchemaNode) childSchema).getKeyDefinition());
            builder.withChild(childBuilder.build());
        } else if (child instanceof LeafNode) {
            final Object defaultVal = ((LeafSchemaNode) childSchema).getType().getDefaultValue().orElse(null);
            final Object nodeVal = child.body();
            final NormalizedNodeBuilder<NodeIdentifier, Object, LeafNode<Object>> leafBuilder = SchemaAwareBuilders.leafBuilder((LeafSchemaNode) childSchema);
            if (trim) {
                if (defaultVal == null || !defaultVal.equals(nodeVal)) {
                    leafBuilder.withValue(child.body());
                    builder.withChild(leafBuilder.build());
                }
            } else {
                if (defaultVal != null && defaultVal.equals(nodeVal)) {
                    leafBuilder.withValue(child.body());
                    builder.withChild(leafBuilder.build());
                }
            }
        }
    }
}
Also used : DataSchemaNode(org.opendaylight.yangtools.yang.model.api.DataSchemaNode) MapNode(org.opendaylight.yangtools.yang.data.api.schema.MapNode) SystemMapNode(org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode) UserMapNode(org.opendaylight.yangtools.yang.data.api.schema.UserMapNode) LeafSchemaNode(org.opendaylight.yangtools.yang.model.api.LeafSchemaNode) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) DataContainerChild(org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) CollectionNodeBuilder(org.opendaylight.yangtools.yang.data.api.schema.builder.CollectionNodeBuilder) ListSchemaNode(org.opendaylight.yangtools.yang.model.api.ListSchemaNode) LeafListSchemaNode(org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode) LeafNode(org.opendaylight.yangtools.yang.data.api.schema.LeafNode) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)

Example 12 with SystemMapNode

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

the class NnInstanceIdentifierToXmlTest method preparNNC.

private static NormalizedNodeContext preparNNC() {
    final QName cont = QName.create("instance:identifier:module", "2014-01-17", "cont");
    final QName cont1 = QName.create("instance:identifier:module", "2014-01-17", "cont1");
    final QName lst11 = QName.create("augment:module", "2014-01-17", "lst11");
    final QName lf11 = QName.create("augment:augment:module", "2014-01-17", "lf111");
    final QName lf12 = QName.create("augment:augment:module", "2014-01-17", "lf112");
    final QName keyvalue111 = QName.create("augment:module", "2014-01-17", "keyvalue111");
    final QName keyvalue112 = QName.create("augment:module", "2014-01-17", "keyvalue112");
    final YangInstanceIdentifier yII = YangInstanceIdentifier.builder().node(cont).build();
    final DataSchemaNode schemaCont = schemaContext.getDataChildByName(cont);
    final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> dataCont = SchemaAwareBuilders.containerBuilder((ContainerSchemaNode) schemaCont);
    final DataSchemaNode schemaCont1 = ((ContainerSchemaNode) schemaCont).getDataChildByName(cont1);
    final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> dataCont1 = SchemaAwareBuilders.containerBuilder((ContainerSchemaNode) schemaCont1);
    final List<DataSchemaNode> instanceLst11 = ControllerContext.findInstanceDataChildrenByName((DataNodeContainer) schemaCont1, lst11.getLocalName());
    final DataSchemaNode lst11Schema = Iterables.getFirst(instanceLst11, null);
    final CollectionNodeBuilder<MapEntryNode, SystemMapNode> dataLst11 = SchemaAwareBuilders.mapBuilder((ListSchemaNode) lst11Schema);
    final DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode> dataLst11Vaule = SchemaAwareBuilders.mapEntryBuilder((ListSchemaNode) lst11Schema);
    dataLst11Vaule.withChild(buildLeaf(lst11Schema, keyvalue111, dataLst11, "keyvalue111"));
    dataLst11Vaule.withChild(buildLeaf(lst11Schema, keyvalue112, dataLst11, "keyvalue112"));
    dataLst11Vaule.withChild(buildLeaf(lst11Schema, lf11, dataLst11, "/cont/cont1/lf12"));
    dataLst11Vaule.withChild(buildLeaf(lst11Schema, lf12, dataLst11, "lf12 value"));
    dataLst11.withChild(dataLst11Vaule.build());
    dataCont1.withChild(dataLst11.build());
    dataCont.withChild(dataCont1.build());
    return new NormalizedNodeContext(new InstanceIdentifierContext<>(yII, schemaCont, null, schemaContext), dataCont.build());
}
Also used : SystemMapNode(org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode) DataSchemaNode(org.opendaylight.yangtools.yang.model.api.DataSchemaNode) QName(org.opendaylight.yangtools.yang.common.QName) MapEntryNode(org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode) NodeIdentifierWithPredicates(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) NormalizedNodeContext(org.opendaylight.netconf.sal.rest.impl.NormalizedNodeContext) ContainerSchemaNode(org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)

Example 13 with SystemMapNode

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

the class ReadDataTransactionUtil method buildCont.

private static void buildCont(final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> builder, final ContainerNode result, final DataSchemaContextTree baseSchemaCtxTree, final YangInstanceIdentifier actualPath, final boolean trim) {
    for (final DataContainerChild child : result.body()) {
        final YangInstanceIdentifier path = actualPath.node(child.getIdentifier());
        final DataSchemaNode childSchema = baseSchemaCtxTree.findChild(path).orElseThrow().getDataSchemaNode();
        if (child instanceof ContainerNode) {
            final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> builderChild = SchemaAwareBuilders.containerBuilder((ContainerSchemaNode) childSchema);
            buildCont(builderChild, result, baseSchemaCtxTree, actualPath, trim);
            builder.withChild(builderChild.build());
        } else if (child instanceof MapNode) {
            final CollectionNodeBuilder<MapEntryNode, SystemMapNode> childBuilder = SchemaAwareBuilders.mapBuilder((ListSchemaNode) childSchema);
            buildList(childBuilder, (MapNode) child, baseSchemaCtxTree, path, trim, ((ListSchemaNode) childSchema).getKeyDefinition());
            builder.withChild(childBuilder.build());
        } else if (child instanceof LeafNode) {
            final Object defaultVal = ((LeafSchemaNode) childSchema).getType().getDefaultValue().orElse(null);
            final Object nodeVal = child.body();
            final NormalizedNodeBuilder<NodeIdentifier, Object, LeafNode<Object>> leafBuilder = SchemaAwareBuilders.leafBuilder((LeafSchemaNode) childSchema);
            if (trim) {
                if (defaultVal == null || !defaultVal.equals(nodeVal)) {
                    leafBuilder.withValue(((LeafNode<?>) child).body());
                    builder.withChild(leafBuilder.build());
                }
            } else {
                if (defaultVal != null && defaultVal.equals(nodeVal)) {
                    leafBuilder.withValue(((LeafNode<?>) child).body());
                    builder.withChild(leafBuilder.build());
                }
            }
        }
    }
}
Also used : DataSchemaNode(org.opendaylight.yangtools.yang.model.api.DataSchemaNode) MapNode(org.opendaylight.yangtools.yang.data.api.schema.MapNode) SystemMapNode(org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode) UserMapNode(org.opendaylight.yangtools.yang.data.api.schema.UserMapNode) LeafSchemaNode(org.opendaylight.yangtools.yang.model.api.LeafSchemaNode) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) DataContainerChild(org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) CollectionNodeBuilder(org.opendaylight.yangtools.yang.data.api.schema.builder.CollectionNodeBuilder) ListSchemaNode(org.opendaylight.yangtools.yang.model.api.ListSchemaNode) LeafNode(org.opendaylight.yangtools.yang.data.api.schema.LeafNode) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)

Example 14 with SystemMapNode

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

the class TestModel method createFamily.

public static ContainerNode createFamily() {
    final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> familyContainerBuilder = ImmutableContainerNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(FAMILY_QNAME));
    final CollectionNodeBuilder<MapEntryNode, SystemMapNode> childrenBuilder = mapNodeBuilder().withNodeIdentifier(new NodeIdentifier(CHILDREN_QNAME));
    final DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode> firstChildBuilder = mapEntryBuilder(CHILDREN_QNAME, CHILD_NUMBER_QNAME, FIRST_CHILD_ID);
    final DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode> secondChildBuilder = mapEntryBuilder(CHILDREN_QNAME, CHILD_NUMBER_QNAME, SECOND_CHILD_ID);
    final DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode> firstGrandChildBuilder = mapEntryBuilder(GRAND_CHILDREN_QNAME, GRAND_CHILD_NUMBER_QNAME, FIRST_GRAND_CHILD_ID);
    final DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode> secondGrandChildBuilder = mapEntryBuilder(GRAND_CHILDREN_QNAME, GRAND_CHILD_NUMBER_QNAME, SECOND_GRAND_CHILD_ID);
    firstGrandChildBuilder.withChild(ImmutableNodes.leafNode(GRAND_CHILD_NUMBER_QNAME, FIRST_GRAND_CHILD_ID)).withChild(ImmutableNodes.leafNode(GRAND_CHILD_NAME_QNAME, FIRST_GRAND_CHILD_NAME));
    secondGrandChildBuilder.withChild(ImmutableNodes.leafNode(GRAND_CHILD_NUMBER_QNAME, SECOND_GRAND_CHILD_ID)).withChild(ImmutableNodes.leafNode(GRAND_CHILD_NAME_QNAME, SECOND_GRAND_CHILD_NAME));
    firstChildBuilder.withChild(ImmutableNodes.leafNode(CHILD_NUMBER_QNAME, FIRST_CHILD_ID)).withChild(ImmutableNodes.leafNode(CHILD_NAME_QNAME, FIRST_CHILD_NAME)).withChild(mapNodeBuilder(GRAND_CHILDREN_QNAME).withChild(firstGrandChildBuilder.build()).build());
    secondChildBuilder.withChild(ImmutableNodes.leafNode(CHILD_NUMBER_QNAME, SECOND_CHILD_ID)).withChild(ImmutableNodes.leafNode(CHILD_NAME_QNAME, SECOND_CHILD_NAME)).withChild(mapNodeBuilder(GRAND_CHILDREN_QNAME).withChild(firstGrandChildBuilder.build()).build());
    childrenBuilder.withChild(firstChildBuilder.build());
    childrenBuilder.withChild(secondChildBuilder.build());
    return familyContainerBuilder.withChild(childrenBuilder.build()).build();
}
Also used : SystemMapNode(org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) MapEntryNode(org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode) NodeIdentifierWithPredicates(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates)

Example 15 with SystemMapNode

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

the class DistributedDataStoreWithSegmentedJournalIntegrationTest method testManyWritesDeletes.

@Test
public void testManyWritesDeletes() throws Exception {
    final IntegrationTestKit testKit = new IntegrationTestKit(getSystem(), datastoreContextBuilder);
    CollectionNodeBuilder<MapEntryNode, SystemMapNode> carMapBuilder = ImmutableNodes.mapNodeBuilder(CAR_QNAME);
    try (AbstractDataStore dataStore = testKit.setupAbstractDataStore(testParameter, "testManyWritesDeletes", "module-shards-cars-member-1.conf", true, "cars")) {
        DOMStoreTransactionChain txChain = dataStore.createTransactionChain();
        DOMStoreWriteTransaction writeTx = txChain.newWriteOnlyTransaction();
        writeTx.write(CarsModel.BASE_PATH, CarsModel.emptyContainer());
        writeTx.write(CarsModel.CAR_LIST_PATH, CarsModel.newCarMapNode());
        testKit.doCommit(writeTx.ready());
        int numCars = 20;
        for (int i = 0; i < numCars; ++i) {
            DOMStoreReadWriteTransaction rwTx = txChain.newReadWriteTransaction();
            YangInstanceIdentifier path = CarsModel.newCarPath("car" + i);
            MapEntryNode data = CarsModel.newCarEntry("car" + i, Uint64.valueOf(20000));
            rwTx.merge(path, data);
            carMapBuilder.withChild(data);
            testKit.doCommit(rwTx.ready());
            if (i % 5 == 0) {
                rwTx = txChain.newReadWriteTransaction();
                rwTx.delete(path);
                carMapBuilder.withoutChild(path.getLastPathArgument());
                testKit.doCommit(rwTx.ready());
            }
        }
        final Optional<NormalizedNode> optional = txChain.newReadOnlyTransaction().read(CarsModel.CAR_LIST_PATH).get(5, TimeUnit.SECONDS);
        assertTrue("isPresent", optional.isPresent());
        MapNode cars = carMapBuilder.build();
        assertEquals("cars not matching result", cars, optional.get());
        txChain.close();
        // wait until the journal is actually persisted, killing the datastore early results in missing entries
        Stopwatch sw = Stopwatch.createStarted();
        AtomicBoolean done = new AtomicBoolean(false);
        while (!done.get()) {
            MemberNode.verifyRaftState(dataStore, "cars", raftState -> {
                if (raftState.getLastApplied() == raftState.getLastLogIndex()) {
                    done.set(true);
                }
            });
            assertTrue("Shard did not persist all journal entries in time.", sw.elapsed(TimeUnit.SECONDS) <= 5);
            Uninterruptibles.sleepUninterruptibly(50, TimeUnit.MILLISECONDS);
        }
    }
    // test restoration from journal and verify data matches
    try (AbstractDataStore dataStore = testKit.setupAbstractDataStore(testParameter, "testManyWritesDeletes", "module-shards-cars-member-1.conf", true, "cars")) {
        DOMStoreTransactionChain txChain = dataStore.createTransactionChain();
        MapNode cars = carMapBuilder.build();
        final Optional<NormalizedNode> optional = txChain.newReadOnlyTransaction().read(CarsModel.CAR_LIST_PATH).get(5, TimeUnit.SECONDS);
        assertTrue("isPresent", optional.isPresent());
        assertEquals("restored cars do not match snapshot", cars, optional.get());
        txChain.close();
    }
}
Also used : SystemMapNode(org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode) DOMStoreWriteTransaction(org.opendaylight.mdsal.dom.spi.store.DOMStoreWriteTransaction) DOMStoreTransactionChain(org.opendaylight.mdsal.dom.spi.store.DOMStoreTransactionChain) DOMStoreReadWriteTransaction(org.opendaylight.mdsal.dom.spi.store.DOMStoreReadWriteTransaction) Stopwatch(com.google.common.base.Stopwatch) MapNode(org.opendaylight.yangtools.yang.data.api.schema.MapNode) SystemMapNode(org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode) MapEntryNode(org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) Test(org.junit.Test)

Aggregations

SystemMapNode (org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode)34 NodeIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier)23 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)21 MapEntryNode (org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode)21 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)12 Test (org.junit.Test)11 DataTreeModification (org.opendaylight.yangtools.yang.data.tree.api.DataTreeModification)9 MapNode (org.opendaylight.yangtools.yang.data.api.schema.MapNode)8 UserMapNode (org.opendaylight.yangtools.yang.data.api.schema.UserMapNode)8 DataSchemaNode (org.opendaylight.yangtools.yang.model.api.DataSchemaNode)8 NodeIdentifierWithPredicates (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates)7 ListSchemaNode (org.opendaylight.yangtools.yang.model.api.ListSchemaNode)7 LeafNode (org.opendaylight.yangtools.yang.data.api.schema.LeafNode)6 DataTreeCandidate (org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidate)6 CollectionNodeBuilder (org.opendaylight.yangtools.yang.data.api.schema.builder.CollectionNodeBuilder)5 DataTree (org.opendaylight.yangtools.yang.data.tree.api.DataTree)5 QName (org.opendaylight.yangtools.yang.common.QName)4 DataContainerChild (org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild)4 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)4 LeafListSchemaNode (org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode)4