private static NormalizedNode<?,?>[] initOuterListItems(final int outerListItemsCount, final MapNode innerList) { return Arrays.stream(OUTER_LIST_IDS).limit(outerListItemsCount) .map(id -> ImmutableNodes.mapEntryBuilder().withNodeIdentifier(id).withChild(innerList).build()) .collect(Collectors.toList()).toArray(new NormalizedNode[0]); }
private Optional<N> build(final S schema, final List<? extends DataContainerChild<?, ?>> result) { DataContainerNodeBuilder<?, N> b = getBuilder(schema); // TODO skip empty container nodes ? e.g. if container looses all its child nodes // if(result.isEmpty()) { // return Optional.absent(); // } for (DataContainerChild<?, ?> dataContainerChild : result) { b.withChild(dataContainerChild); } return Optional.of(b.build()); }
private void processDataContainerChild( final DataContainerNode<?> node, final Integer depth, final DataContainerNodeBuilder<? extends YangInstanceIdentifier.PathArgument, ? extends DataContainerNode<?>> newBuilder) { for (DataContainerChild<? extends PathArgument, ?> nodeValue : node.getValue()) { newBuilder.withChild(pruneDataAtDepth(nodeValue, depth - 1)); } }
public static List<MapEntryNode> buildOuterList(final int outerElements, final int innerElements) { List<MapEntryNode> outerList = new ArrayList<>(outerElements); for (int j = 0; j < outerElements; j++) { outerList.add(ImmutableNodes.mapEntryBuilder() .withNodeIdentifier(new NodeIdentifierWithPredicates(OuterList.QNAME, OL_ID, j)) .withChild(ImmutableNodes.leafNode(OL_ID, j)) .withChild(buildInnerList(j, innerElements)) .build()); } return outerList; }
static public List<MapEntryNode> buildOuterList(int outerElements, int innerElements) { List<MapEntryNode> outerList = new ArrayList<MapEntryNode>(outerElements); for (int j = 0; j < outerElements; j++) { outerList.add(ImmutableNodes.mapEntryBuilder() .withNodeIdentifier(new NodeIdentifierWithPredicates(OuterList.QNAME, OL_ID, j)) .withChild(ImmutableNodes.leafNode(OL_ID, j)) .withChild(buildInnerList(j, innerElements)) .build()); } return outerList; }
@VisibleForTesting MapEntryNode peerSkeleton(final NodeIdentifierWithPredicates peerKey, final String peerId) { final DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode> pb = Builders.mapEntryBuilder(); pb.withNodeIdentifier(peerKey); pb.withChild(ImmutableNodes.leafNode(PEER_ID, peerId)); pb.withChild(ImmutableNodes.leafNode(PEER_ROLE, PeerRoleUtil.roleForString(this.role))); if (this.simpleRoutingPolicy.isPresent() && this.role != PeerRole.Internal) { pb.withChild(ImmutableNodes.leafNode(SIMPLE_ROUTING_POLICY_NID, simpleRoutingPolicyString(this.simpleRoutingPolicy.get()))); } pb.withChild(ImmutableMapNodeBuilder.create().withNodeIdentifier(PEER_TABLES).build()); pb.withChild(EMPTY_ADJRIBIN); if(!isLearnNone(this.simpleRoutingPolicy)) { pb.withChild(EMPTY_EFFRIBIN); } if (!isAnnounceNone(this.simpleRoutingPolicy)) { pb.withChild(EMPTY_ADJRIBOUT); } return pb.build(); }
private NormalizedNode<?, ?> buildDataContainer(final DataContainerNodeBuilder<?, ?> builder, final NormalizedNodeMessages.Node node){ for(NormalizedNodeMessages.Node child : node.getChildList()){ builder.withChild((DataContainerChild<?, ?>) deSerialize(child)); } //TODO : Also handle attributes return builder.build(); }
static private MapNode buildInnerList(int index, int elements ) { CollectionNodeBuilder<MapEntryNode, MapNode> innerList = ImmutableNodes.mapNodeBuilder(InnerList.QNAME); final String itemStr = "Item-" + String.valueOf(index) + "-"; for( int i = 0; i < elements; i++ ) { innerList.addChild(ImmutableNodes.mapEntryBuilder() .withNodeIdentifier(new NodeIdentifierWithPredicates(InnerList.QNAME, IL_NAME, i)) .withChild(ImmutableNodes.leafNode(IL_NAME, i)) .withChild(ImmutableNodes.leafNode(IL_VALUE, itemStr + String.valueOf(i))) .build()); } return innerList.build(); }
private static MapNode buildInnerList(final int index, final int elements) { CollectionNodeBuilder<MapEntryNode, MapNode> innerList = ImmutableNodes.mapNodeBuilder(InnerList.QNAME); final String itemStr = "Item-" + String.valueOf(index) + "-"; for (int i = 0; i < elements; i++) { innerList.addChild(ImmutableNodes.mapEntryBuilder() .withNodeIdentifier(new NodeIdentifierWithPredicates(InnerList.QNAME, IL_NAME, i)) .withChild(ImmutableNodes.leafNode(IL_NAME, i)) .withChild(ImmutableNodes.leafNode(IL_VALUE, itemStr + String.valueOf(i))) .build()); } return innerList.build(); } }
void createTable(final DOMDataWriteTransaction tx) { final DataContainerNodeBuilder<YangInstanceIdentifier.NodeIdentifierWithPredicates, MapEntryNode> tb = ImmutableNodes.mapEntryBuilder(); tb.withNodeIdentifier((YangInstanceIdentifier.NodeIdentifierWithPredicates)tableId.getLastPathArgument()); tb.withChild(EMPTY_TABLE_ATTRIBUTES); // tableId is keyed, but that fact is not directly visible from YangInstanceIdentifier, see BUG-2796 final YangInstanceIdentifier.NodeIdentifierWithPredicates tableKey = (YangInstanceIdentifier.NodeIdentifierWithPredicates) tableId.getLastPathArgument(); for (final Map.Entry<QName, Object> e : tableKey.getKeyValues().entrySet()) { tb.withChild(ImmutableNodes.leafNode(e.getKey(), e.getValue())); } final ChoiceNode routes = this.tableSupport.emptyRoutes(); Verify.verifyNotNull(routes, "Null empty routes in %s", this.tableSupport); tx.put(LogicalDatastoreType.OPERATIONAL, this.tableId, tb.withChild(ImmutableChoiceNodeBuilder.create(routes).withNodeIdentifier( new NodeIdentifier(TablesUtil.BMP_ROUTES_QNAME)).build()).build()); }
@Override public void createEmptyTableStructure(final DOMDataWriteTransaction tx, final YangInstanceIdentifier tableId) { final DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode> tb = ImmutableNodes.mapEntryBuilder(); tb.withNodeIdentifier((NodeIdentifierWithPredicates)tableId.getLastPathArgument()); tb.withChild(EMPTY_TABLE_ATTRIBUTES); // tableId is keyed, but that fact is not directly visible from YangInstanceIdentifier, see BUG-2796 final NodeIdentifierWithPredicates tableKey = (NodeIdentifierWithPredicates) tableId.getLastPathArgument(); for (final Entry<QName, Object> e : tableKey.getKeyValues().entrySet()) { tb.withChild(ImmutableNodes.leafNode(e.getKey(), e.getValue())); } final ChoiceNode routes = this.ribSupport.emptyRoutes(); Verify.verifyNotNull(routes, "Null empty routes in %s", this.ribSupport); Verify.verify(Routes.QNAME.equals(routes.getNodeType()), "Empty routes have unexpected identifier %s, expected %s", routes.getNodeType(), Routes.QNAME); tx.put(LogicalDatastoreType.OPERATIONAL, tableId, tb.withChild(routes).build()); }
@Override public void apply(final DOMDataWriteTransaction tx, final YangInstanceIdentifier base, final NodeIdentifierWithPredicates routeKey, final DataContainerNode<?> route, final ContainerNode attributes) { // Build the DataContainer data final DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode> b = ImmutableNodes.mapEntryBuilder(); b.withNodeIdentifier(routeKey); route.getValue().forEach(b::withChild); // Add attributes final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> cb = Builders.containerBuilder(attributes); cb.withNodeIdentifier(routeAttributesIdentifier()); b.withChild(cb.build()); tx.put(LogicalDatastoreType.OPERATIONAL, base.node(routeKey), b.build()); } }
private MapEntryNode toMapEntryNode(TestResult testResult) { YangInstanceIdentifier testResultId = YangInstanceIdentifier.builder().node(TEST_RESULTS_QNAME).node(TEST_RESULT_QNAME).build(); // Construct results list LinkedList<LeafSetEntryNode<Object>> entryList = new LinkedList<>(); for (String result : testResult.getResults()) { LeafSetEntryNode<Object> leafSetEntryNode = ImmutableLeafSetEntryNodeBuilder.create() .withNodeIdentifier(new NodeWithValue(RESULTS_QNAME, result)) .withValue(result) .build(); entryList.add(leafSetEntryNode); } // Construct results LeafSetNode LeafSetNode<?> resultsNode = ImmutableLeafSetNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(RESULTS_QNAME)).withValue(entryList).build(); // Construct test result ContainerNode with 2 children - test-identifier leaf and results leaf-set MapEntryNode testResultNode = ImmutableNodes.mapEntryBuilder() .withNodeIdentifier(new NodeIdentifierWithPredicates(TEST_RESULT_QNAME, TEST_ID_QNAME, testResult.getTestIdentifier())) .withChild(ImmutableNodes.leafNode(TEST_ID_QNAME, testResult.getTestIdentifier())) .withChild(resultsNode) .build(); return(testResultNode); }
public static DataContainerChild<?, ?> getSourceNode(final QName datastore) { return Builders.containerBuilder().withNodeIdentifier(toId(NETCONF_SOURCE_QNAME)) .withChild( Builders.choiceBuilder().withNodeIdentifier(toId(ConfigSource.QNAME)).withChild( Builders.leafBuilder().withNodeIdentifier(toId(datastore)).build()).build() ).build(); }
public static DataContainerChild<?, ?> getTargetNode(final QName datastore) { return Builders.containerBuilder().withNodeIdentifier(toId(NETCONF_TARGET_QNAME)) .withChild( Builders.choiceBuilder().withNodeIdentifier(toId(ConfigTarget.QNAME)).withChild( Builders.leafBuilder().withNodeIdentifier(toId(datastore)).build()).build() ).build(); }
@Test public void testInnerContainerNodeWithParentPathPrunedWhenSchemaMissing() throws IOException { YangInstanceIdentifier path = YangInstanceIdentifier.builder().node(TestModel.TEST_QNAME) .node(TestModel.OUTER_LIST_QNAME).nodeWithKey(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 1) .build(); NormalizedNodePruner pruner = prunerFullSchema(path); MapNode innerList = mapNodeBuilder(TestModel.INNER_LIST_QNAME).withChild(mapEntryBuilder( TestModel.INNER_LIST_QNAME, TestModel.NAME_QNAME, "one").withChild( ImmutableNodes.containerNode(TestModel.INVALID_QNAME)).build()).build(); NormalizedNode<?, ?> input = mapEntryBuilder(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 1) .withChild(innerList).build(); NormalizedNodeWriter.forStreamWriter(pruner).write(input); NormalizedNode<?, ?> expected = mapEntryBuilder(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 1) .withChild(mapNodeBuilder(TestModel.INNER_LIST_QNAME).withChild(mapEntryBuilder( TestModel.INNER_LIST_QNAME, TestModel.NAME_QNAME, "one").build()).build()).build(); NormalizedNode<?, ?> actual = pruner.normalizedNode(); assertEquals("normalizedNode", expected, actual); }
@Test public void testInnerListNodeWithParentPathPrunedWhenSchemaMissing() throws IOException { YangInstanceIdentifier path = YangInstanceIdentifier.builder().node(TestModel.TEST_QNAME) .node(TestModel.OUTER_LIST_QNAME).nodeWithKey(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 1) .build(); NormalizedNodePruner pruner = prunerFullSchema(path); MapNode innerList = mapNodeBuilder(TestModel.INVALID_QNAME).withChild(mapEntryBuilder( TestModel.INVALID_QNAME, TestModel.NAME_QNAME, "one").withChild( ImmutableNodes.containerNode(TestModel.INNER_CONTAINER_QNAME)).build()).build(); NormalizedNode<?, ?> input = mapEntryBuilder(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 1) .withChild(innerList).build(); NormalizedNodeWriter.forStreamWriter(pruner).write(input); NormalizedNode<?, ?> expected = mapEntry(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 1); NormalizedNode<?, ?> actual = pruner.normalizedNode(); assertEquals("normalizedNode", expected, actual); }
@Test public void testLeafNodePrunedWhenHasAugmentationParentAndSchemaMissing() throws IOException { AugmentationIdentifier augId = new AugmentationIdentifier(Sets.newHashSet(TestModel.AUG_CONT_QNAME)); NormalizedNodePruner pruner = prunerFullSchema(YangInstanceIdentifier.builder() .node(TestModel.TEST_QNAME).node(TestModel.AUGMENTED_LIST_QNAME) .node(TestModel.AUGMENTED_LIST_QNAME).node(augId).build()); LeafNode<Object> child = Builders.leafBuilder().withNodeIdentifier( new NodeIdentifier(TestModel.INVALID_QNAME)).withValue("test").build(); NormalizedNode<?, ?> input = Builders.augmentationBuilder().withNodeIdentifier(augId).withChild(child).build(); NormalizedNodeWriter.forStreamWriter(pruner).write(input); NormalizedNode<?, ?> actual = pruner.normalizedNode(); assertEquals("normalizedNode", Builders.augmentationBuilder().withNodeIdentifier(augId).build(), actual); }
@Test public void testInnerListNodeWithFullPathNotPruned() throws IOException { YangInstanceIdentifier path = YangInstanceIdentifier.builder().node(TestModel.TEST_QNAME) .node(TestModel.OUTER_LIST_QNAME).nodeWithKey(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 1) .node(TestModel.INNER_LIST_QNAME).build(); NormalizedNodePruner pruner = prunerFullSchema(path); MapNode input = mapNodeBuilder(TestModel.INNER_LIST_QNAME).withChild(mapEntryBuilder( TestModel.INNER_LIST_QNAME, TestModel.NAME_QNAME, "one").withChild( ImmutableNodes.containerNode(TestModel.INNER_CONTAINER_QNAME)).build()).build(); NormalizedNodeWriter.forStreamWriter(pruner).write(input); NormalizedNode<?, ?> actual = pruner.normalizedNode(); assertEquals("normalizedNode", input, actual); }
@Test public void testInnerListNodeWithFullPathPrunedWhenSchemaMissing() throws IOException { YangInstanceIdentifier path = YangInstanceIdentifier.builder().node(TestModel.TEST_QNAME) .node(TestModel.OUTER_LIST_QNAME).nodeWithKey(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 1) .node(TestModel.INVALID_QNAME).build(); NormalizedNodePruner pruner = prunerFullSchema(path); MapNode input = mapNodeBuilder(TestModel.INVALID_QNAME).withChild(mapEntryBuilder( TestModel.INVALID_QNAME, TestModel.NAME_QNAME, "one").withChild( ImmutableNodes.containerNode(TestModel.INNER_CONTAINER_QNAME)).build()).build(); NormalizedNodeWriter.forStreamWriter(pruner).write(input); NormalizedNode<?, ?> actual = pruner.normalizedNode(); assertNull(actual); }