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());
}
}
}
}
}
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());
}
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());
}
}
}
}
}
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();
}
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();
}
}
Aggregations