private Map<YangInstanceIdentifier.NodeIdentifierWithPredicates, MapEntryNode> mapEntries(MapNode mapNode) { Map<YangInstanceIdentifier.NodeIdentifierWithPredicates, MapEntryNode> mapped = Maps.newLinkedHashMap(); for (MapEntryNode mapEntryNode : mapNode.getValue()) { mapped.put(mapEntryNode.getIdentifier(), mapEntryNode); } return mapped; }
private Collection<String> getCandidateNames(MapEntryNode entity) { Collection<MapEntryNode> candidates = ((MapNode)entity.getChild(CANDIDATE_NODE_ID).get()).getValue(); Collection<String> candidateNames = new ArrayList<>(candidates.size()); for(MapEntryNode candidate: candidates) { candidateNames.add(candidate.getChild(CANDIDATE_NAME_NODE_ID).get().getValue().toString()); } return candidateNames; }
private void searchForEntities(EntityWalker walker) { Optional<NormalizedNode<?, ?>> possibleEntityTypes = getDataStore().readNode(ENTITY_TYPES_PATH); if(!possibleEntityTypes.isPresent()) { return; } for(MapEntryNode entityType: ((MapNode) possibleEntityTypes.get()).getValue()) { Optional<DataContainerChild<?, ?>> possibleEntities = entityType.getChild(ENTITY_NODE_ID); if(!possibleEntities.isPresent()) { // shouldn't happen but handle anyway continue; } for(MapEntryNode entity: ((MapNode) possibleEntities.get()).getValue()) { walker.onEntity(entityType, entity); } } }
@Override public Collection<NormalizedNodeUpdate> normalizedUpdates(@Nonnull final YangInstanceIdentifier topLevelIdentifier, @Nonnull final Map.Entry<YangInstanceIdentifier.PathArgument, DataContainerChild<? extends YangInstanceIdentifier.PathArgument, ?>> entry) { // identifier has different format : parent_node/list_node/list_node_with_key LOG.debug("Processing {} as list", topLevelIdentifier); return ((MapNode) entry.getValue()).getValue().stream() .map(mapEntryNode -> new NormalizedNodeUpdate(YangInstanceIdentifier.builder(topLevelIdentifier) .node(mapEntryNode.getNodeType()) .node(mapEntryNode.getIdentifier()).build(), mapEntryNode, null)) .collect(Collectors.toList()); } }
/** * Parse response of get(netconf-state/schemas) to find all schemas under netconf-state/schemas */ @VisibleForTesting protected static NetconfStateSchemas create(final RemoteDeviceId id, final ContainerNode schemasNode) { final Set<RemoteYangSchema> availableYangSchemas = Sets.newHashSet(); final Optional<DataContainerChild<? extends YangInstanceIdentifier.PathArgument, ?>> child = schemasNode.getChild(toId(Schema.QNAME)); Preconditions.checkState(child.isPresent(), "Unable to find list: %s in response: %s", Schema.QNAME.withoutRevision(), schemasNode); Preconditions.checkState(child.get() instanceof MapNode, "Unexpected structure for container: %s in response: %s. Expecting a list", Schema.QNAME.withoutRevision(), schemasNode); for (final MapEntryNode schemaNode : ((MapNode) child.get()).getValue()) { final Optional<RemoteYangSchema> fromCompositeNode = RemoteYangSchema.createFromNormalizedNode(id, schemaNode); if(fromCompositeNode.isPresent()) { availableYangSchemas.add(fromCompositeNode.get()); } } return new NetconfStateSchemas(availableYangSchemas); }
@Nullable Iterator<NormalizedNodeContext> iterateChildrenNamed(final DataContainerNode<?> data, final QName qname) { final NodeIdentifier arg = new NodeIdentifier(qname); final Optional<DataContainerChild<? extends @Nullable PathArgument, ?>> maybeChild = data.getChild(arg); if (!maybeChild.isPresent()) { return null; } final NormalizedNode<?, ?> child = maybeChild.get(); final Collection<? extends NormalizedNode<?, ?>> collection; // The child may be a structural node if (child instanceof MapNode) { collection = ((MapNode)child).getValue(); } else if (child instanceof LeafSetNode) { collection = ((LeafSetNode<?>)child).getValue(); } else { return Iterators.singletonIterator(createChild(child)); } return Iterators.transform(collection.iterator(), this::createChild); }
@Nullable Iterator<NormalizedNodeContext> iterateChildrenNamed(final DataContainerNode<?> data, final QName qname) { final NodeIdentifier arg = new NodeIdentifier(qname); final Optional<DataContainerChild<? extends @Nullable PathArgument, ?>> maybeChild = data.getChild(arg); if (!maybeChild.isPresent()) { return null; } final NormalizedNode<?, ?> child = maybeChild.get(); final Collection<? extends NormalizedNode<?, ?>> collection; // The child may be a structural node if (child instanceof MapNode) { collection = ((MapNode)child).getValue(); } else if (child instanceof LeafSetNode) { collection = ((LeafSetNode<?>)child).getValue(); } else { return Iterators.singletonIterator(createChild(child)); } return Iterators.transform(collection.iterator(), this::createChild); }
public NormalizedNode<?, ?> parseDataElement(final Element element, final DataSchemaNode dataSchema, final SchemaContext schemaContext) throws XMLStreamException, IOException, ParserConfigurationException, SAXException, URISyntaxException { final NormalizedNodeResult resultHolder = new NormalizedNodeResult(); final NormalizedNodeStreamWriter writer = ImmutableNormalizedNodeStreamWriter.from(resultHolder); final XmlParserStream xmlParser = XmlParserStream.create(writer, schemaContext, dataSchema); xmlParser.traverse(new DOMSource(element)); final NormalizedNode<?, ?> result = resultHolder.getResult(); if (result instanceof MapNode) { final MapNode mapNode = (MapNode) result; final MapEntryNode mapEntryNode = mapNode.getValue().iterator().next(); return mapEntryNode; } return result; }
@Override public Optional<EntityOwnershipState> getOwnershipState(final DOMEntity forEntity) { Preconditions.checkNotNull(forEntity, "forEntity cannot be null"); DataTree dataTree = getLocalEntityOwnershipShardDataTree(); if (dataTree == null) { return Optional.absent(); } Optional<NormalizedNode<?, ?>> entityNode = dataTree.takeSnapshot().readNode( entityPath(forEntity.getType(), forEntity.getIdentifier())); if (!entityNode.isPresent()) { return Optional.absent(); } // Check if there are any candidates, if there are none we do not really have ownership state final MapEntryNode entity = (MapEntryNode) entityNode.get(); final Optional<DataContainerChild<? extends PathArgument, ?>> optionalCandidates = entity.getChild(CANDIDATE_NODE_ID); final boolean hasCandidates = optionalCandidates.isPresent() && ((MapNode) optionalCandidates.get()).getValue().size() > 0; if(!hasCandidates){ return Optional.absent(); } MemberName localMemberName = context.getCurrentMemberName(); Optional<DataContainerChild<? extends PathArgument, ?>> ownerLeaf = entity.getChild(ENTITY_OWNER_NODE_ID); String owner = ownerLeaf.isPresent() ? ownerLeaf.get().getValue().toString() : null; boolean hasOwner = !Strings.isNullOrEmpty(owner); boolean isOwner = hasOwner && localMemberName.getName().equals(owner); return Optional.of(EntityOwnershipState.from(isOwner, hasOwner)); }
private void addValues(final Set<Object> values, final NormalizedNode<?, ?> node, final List<QNamePredicate> nodePredicates, final Deque<QNameWithPredicate> path, final YangInstanceIdentifier current) { if (node instanceof ValueNode) { values.add(node.getValue()); return; } if (node instanceof LeafSetNode<?>) { for (final NormalizedNode<?, ?> entry : ((LeafSetNode<?>) node).getValue()) { values.add(entry.getValue()); } return; } final QNameWithPredicate next = path.peek(); if (next == null) { return; } final PathArgument pathArgument = new NodeIdentifier(next.getQName()); if (node instanceof DataContainerNode) { processChildNode(values, (DataContainerNode<?>) node, pathArgument, next.getQNamePredicates(), path, current); } else if (node instanceof MapNode) { Stream<MapEntryNode> entries = ((MapNode) node).getValue().stream(); if (!nodePredicates.isEmpty() && current != null) { entries = entries.filter(createMapEntryPredicate(nodePredicates, current)); } entries.forEach(entry -> processChildNode(values, entry, pathArgument, next.getQNamePredicates(), path, current)); } }
private void addValues(final Set<Object> values, final NormalizedNode<?, ?> node, final List<QNamePredicate> nodePredicates, final Deque<QNameWithPredicate> path, final YangInstanceIdentifier current) { if (node instanceof ValueNode) { values.add(node.getValue()); return; } if (node instanceof LeafSetNode<?>) { for (final NormalizedNode<?, ?> entry : ((LeafSetNode<?>) node).getValue()) { values.add(entry.getValue()); } return; } final QNameWithPredicate next = path.peek(); if (next == null) { return; } final PathArgument pathArgument = new NodeIdentifier(next.getQName()); if (node instanceof DataContainerNode) { processChildNode(values, (DataContainerNode<?>) node, pathArgument, next.getQNamePredicates(), path, current); } else if (node instanceof MapNode) { Stream<MapEntryNode> entries = ((MapNode) node).getValue().stream(); if (!nodePredicates.isEmpty() && current != null) { entries = entries.filter(createMapEntryPredicate(nodePredicates, current)); } entries.forEach(entry -> processChildNode(values, entry, pathArgument, next.getQNamePredicates(), path, current)); } }
for (MapEntryNode mapEntryModification : modification.get().getValue()) {
private void validateMapNodeData(final MapNode node, final LeafRefContext referencedByCtx, final LeafRefContext referencingCtx, final ModificationType modificationType, final YangInstanceIdentifier current) { for (final MapEntryNode mapEntry : node.getValue()) { final YangInstanceIdentifier mapEntryIdentifier = current.node(mapEntry.getIdentifier()); for (final DataContainerChild<?, ?> child : mapEntry.getValue()) { if (child instanceof AugmentationNode) { validateNodeData(child, referencedByCtx, referencingCtx, modificationType, current.node( child.getIdentifier())); return; } validateChildNodeData(child, referencedByCtx, referencingCtx, modificationType, mapEntryIdentifier); } } }
private void validateMapNodeData(final MapNode node, final LeafRefContext referencedByCtx, final LeafRefContext referencingCtx, final ModificationType modificationType, final YangInstanceIdentifier current) { for (final MapEntryNode mapEntry : node.getValue()) { final YangInstanceIdentifier mapEntryIdentifier = current.node(mapEntry.getIdentifier()); for (final DataContainerChild<?, ?> child : mapEntry.getValue()) { if (child instanceof AugmentationNode) { validateNodeData(child, referencedByCtx, referencingCtx, modificationType, current.node( child.getIdentifier())); return; } validateChildNodeData(child, referencedByCtx, referencingCtx, modificationType, mapEntryIdentifier); } } }
private void processMapEntries(final NormalizedNode<?, ?> node, final Integer depth, CollectionNodeBuilder<MapEntryNode, ? extends MapNode> newOrderedMapNodeBuilder) { if (depth > 1) { for (MapEntryNode oldMapEntryNode : ((MapNode) node).getValue()) { DataContainerNodeAttrBuilder<NodeIdentifierWithPredicates, MapEntryNode> newMapEntryNodeBuilder = Builders .mapEntryBuilder().withNodeIdentifier(oldMapEntryNode.getIdentifier()); for (DataContainerChild<? extends PathArgument, ?> mapEntryNodeValue : oldMapEntryNode.getValue()) { newMapEntryNodeBuilder.withChild(pruneDataAtDepth(mapEntryNodeValue, depth - 1)); } newOrderedMapNodeBuilder.withChild(newMapEntryNodeBuilder.build()); } } }
result = Iterables.getOnlyElement(((MapNode) result).getValue());
transaction = domDataBroker.newReadWriteTransaction(); for(final MapEntryNode child : ((MapNode) payload).getValue()) { final YangInstanceIdentifier childPath = path.node(child.getIdentifier()); checkItemDoesNotExists(transaction, datastore, childPath);