private void updateNodes(final DataTreeCandidateNode table, final PeerId peerId, final DOMDataWriteTransaction tx, final Map<RouteUpdateKey, RouteEntry> routes) { for (final DataTreeCandidateNode child : table.getChildNodes()) { LOG.debug("Modification type {}", child.getModificationType()); if ((Attributes.QNAME).equals(child.getIdentifier().getNodeType())) { if (child.getDataAfter().isPresent()) { // putting uptodate attribute in LOG.trace("Uptodate found for {}", child.getDataAfter()); tx.put(LogicalDatastoreType.OPERATIONAL, this.locRibTarget.node(child.getIdentifier()), child.getDataAfter().get()); } continue; } updateRoutesEntries(child, peerId, routes); } }
static BindingStructuralType from(final DataTreeCandidateNode domChildNode) { final Optional<NormalizedNode<?, ?>> dataBased = domChildNode.getDataAfter().or(domChildNode.getDataBefore()); if(dataBased.isPresent()) { return from(dataBased.get()); } return from(domChildNode.getIdentifier()); }
@Override public void onTablesChanged(final PeerId peerId, final DataTreeCandidateNode tablesChange) { final NodeIdentifierWithPredicates supTablesKey = RibSupportUtils.toYangKey(SupportedTables.QNAME, this.localTableKey); final DataTreeCandidateNode localTableNode = tablesChange.getModifiedChild(supTablesKey); if (localTableNode != null) { final Optional<NormalizedNode<?, ?>> dataAfter = localTableNode.getDataAfter(); processSupportedSendReceiveTables(localTableNode.getModifiedChild(SEND_RECEIVE_NID), peerId); if (dataAfter.isPresent()) { final boolean added = this.peerTables.add(peerId); if (added) { LOG.debug("Supported table {} added to peer {}", this.localTableKey, peerId); } } else { final NodeIdentifierWithPredicates value = (NodeIdentifierWithPredicates) localTableNode.getIdentifier(); this.peerTables.remove(peerId); LOG.debug("Removed tables {} from peer {}", value, peerId); } } }
boolean isMixin() { // Checking whether node is a mixin is not performed on schema, but on data since mixin is // only a NormalizedNode concept, not a schema concept return dataCandidate.getDataBefore().orElse(null) instanceof MixinNode || dataCandidate.getDataAfter().orElse(null) instanceof MixinNode; }
@Override public final Collection<DataTreeCandidateNode> changedRoutes(final DataTreeCandidateNode routes) { final DataTreeCandidateNode myRoutes = routes.getModifiedChild(this.routesContainerIdentifier); if (myRoutes == null) { return Collections.emptySet(); } final DataTreeCandidateNode routesMap = myRoutes.getModifiedChild(routeNid()); if (routesMap == null) { return Collections.emptySet(); } // Well, given the remote possibility of augmentation, we should perform a filter here, // to make sure the type matches what routeType() reports. return routesMap.getChildNodes(); }
private void filterOutAnyChangeOutsideEffRibsIn(final PeerId peerId, final DataTreeCandidateNode rootNode, final Map<RouteUpdateKey, RouteEntry> ret, final YangInstanceIdentifier rootPath, final DOMDataWriteTransaction tx) { final DataTreeCandidateNode ribIn = rootNode.getModifiedChild(EFFRIBIN_NID); if (ribIn == null) { LOG.trace("Skipping change {}", rootNode.getIdentifier()); return; } final DataTreeCandidateNode table = ribIn.getModifiedChild(TABLES_NID).getModifiedChild(this.tableKey); if (table == null) { LOG.trace("Skipping change {}", rootNode.getIdentifier()); return; } initializeTableWithExistentRoutes(table, peerId, rootPath, tx); updateNodes(table, peerId, tx, ret); }
switch (node.getModificationType()) { case DELETE: modification.delete(path); LOG.debug("Modification {} modified path {}", modification, path); NodeIterator iterator = new NodeIterator(null, path, node.getChildNodes().iterator()); do { iterator = iterator.next(modification); modification.write(path, node.getDataAfter().get()); LOG.debug("Modification {} written path {}", modification, path); break; default: throw new IllegalArgumentException("Unsupported modification " + node.getModificationType());
private void notifyNode(final YangInstanceIdentifier path, final RegistrationTreeNode<AbstractDOMDataTreeChangeListenerRegistration<?>> regNode, final DataTreeCandidateNode candNode) { if (candNode.getModificationType() == ModificationType.UNMODIFIED) { LOG.debug("Skipping unmodified candidate {}", path); return; } final Collection<AbstractDOMDataTreeChangeListenerRegistration<?>> regs = regNode.getRegistrations(); if (!regs.isEmpty()) { notifyListeners(regs, path, candNode); } for (DataTreeCandidateNode candChild : candNode.getChildNodes()) { if (candChild.getModificationType() != ModificationType.UNMODIFIED) { final RegistrationTreeNode<AbstractDOMDataTreeChangeListenerRegistration<?>> regChild = regNode.getExactChild(candChild.getIdentifier()); if (regChild != null) { notifyNode(path.node(candChild.getIdentifier()), regChild, candChild); } for (RegistrationTreeNode<AbstractDOMDataTreeChangeListenerRegistration<?>> rc : regNode.getInexactChildren(candChild.getIdentifier())) { notifyNode(path.node(candChild.getIdentifier()), rc, candChild); } } } } }
private void processSupportedSendReceiveTables(final DataTreeCandidateNode sendReceiveModChild, final PeerId peerId) { if (sendReceiveModChild != null) { if (sendReceiveModChild.getModificationType().equals(ModificationType.DELETE)) { final Optional<NormalizedNode<?, ?>> sendReceiveNode = sendReceiveModChild.getDataBefore(); if (sendReceiveNode.isPresent()) { final SendReceive sendReceiveValue = SendReceive.valueOf(BindingMapping.getClassName((String) sendReceiveNode.get().getValue())); this.peerAddPathTables.remove(peerId); LOG.debug("Supported Add BestPath table {} removed to peer {}", sendReceiveValue, peerId); } } else { final Optional<NormalizedNode<?, ?>> sendReceiveNode = sendReceiveModChild.getDataAfter(); if (sendReceiveNode.isPresent()) { final SendReceive sendReceiveValue = SendReceive.valueOf(BindingMapping.getClassName((String) sendReceiveNode.get().getValue())); this.peerAddPathTables.put(peerId, sendReceiveValue); LOG.debug("Supported Add BestPath table {} added to peer {}", sendReceiveValue, peerId); } } } }
private static LeafRefContext getReferencingCtxChild(final LeafRefContext referencingCtx, final DataTreeCandidateNode childNode) { if (referencingCtx == null) { return null; } final QName childQName = childNode.getIdentifier().getNodeType(); LeafRefContext childReferencingCtx = referencingCtx.getReferencingChildByName(childQName); if (childReferencingCtx == null) { final NormalizedNode<?, ?> data = childNode.getDataAfter().get(); if (data instanceof MapEntryNode || data instanceof UnkeyedListEntryNode) { childReferencingCtx = referencingCtx; } } return childReferencingCtx; }
public static void applyRootToCursor(final DataTreeModificationCursor cursor, final DataTreeCandidateNode node) { switch (node.getModificationType()) { case DELETE: throw new IllegalArgumentException("Can not delete root."); case WRITE: case SUBTREE_MODIFIED: AbstractNodeIterator iterator = new RootNonExitingIterator(node.getChildNodes().iterator()); do { iterator = iterator.next(cursor); } while (iterator != null); break; case UNMODIFIED: // No-op break; default: throw new IllegalArgumentException("Unsupported modification " + node.getModificationType()); } }
@Override public Collection<DataObjectModification<? extends DataObject>> getModifiedChildren() { if (childNodesCache == null) { childNodesCache = from(codec, domData.getChildNodes()); } return childNodesCache; }
private void validateChildren(final LeafRefContext rootLeafRefCtx, final Collection<DataTreeCandidateNode> children) throws LeafRefDataValidationFailedException { for (final DataTreeCandidateNode dataTreeCandidateNode : children) { if (dataTreeCandidateNode.getModificationType() != ModificationType.UNMODIFIED) { final PathArgument identifier = dataTreeCandidateNode.getIdentifier(); final QName childQName = identifier.getNodeType(); final LeafRefContext referencedByCtx = rootLeafRefCtx.getReferencedChildByName(childQName); final LeafRefContext referencingCtx = rootLeafRefCtx.getReferencingChildByName(childQName); if (referencedByCtx != null || referencingCtx != null) { validateNode(dataTreeCandidateNode, referencedByCtx, referencingCtx, YangInstanceIdentifier.create(identifier)); } } } if (!errorsMessages.isEmpty()) { final StringBuilder message = new StringBuilder(); int errCount = 0; for (final String errorMessage : errorsMessages) { message.append(errorMessage); errCount++; } throw new LeafRefDataValidationFailedException(message.toString(), errCount); } }
private void processRoute(final DOMDataWriteTransaction tx, final RIBSupport ribSupport, final AbstractImportPolicy policy, final YangInstanceIdentifier routesPath, final DataTreeCandidateNode route) { LOG.debug("Process route {}", route.getIdentifier()); final YangInstanceIdentifier routeId = ribSupport.routePath(routesPath, route.getIdentifier()); final TablesKey tablesKey = new TablesKey(ribSupport.getAfi(), ribSupport.getSafi()); switch (route.getModificationType()) { case DELETE: case DISAPPEARED: case SUBTREE_MODIFIED: case WRITE: tx.put(LogicalDatastoreType.OPERATIONAL, routeId, route.getDataAfter().get()); final ContainerNode advertisedAttrs = (ContainerNode) NormalizedNodes.findNode(route.getDataAfter(), ribSupport.routeAttributesIdentifier()).orNull(); final ContainerNode effectiveAttrs; LOG.debug("Route {} effective attributes {} towards {}", route.getIdentifier(), effectiveAttrs, routeId);
ModificationType getModificationType() { return dataCandidate.getModificationType(); }
public static void validate(final DataTreeCandidate tree, final LeafRefContext rootLeafRefCtx) throws LeafRefDataValidationFailedException { final Optional<NormalizedNode<?, ?>> root = tree.getRootNode().getDataAfter(); if (root.isPresent()) { new LeafRefValidation(root.get()).validateChildren(rootLeafRefCtx, tree.getRootNode().getChildNodes()); } }
Stream<Modification> streamChildren() { return dataCandidate.getChildNodes().stream() .map(child -> { final YangInstanceIdentifier childId = id.node(child.getIdentifier()); final Object schemaChild = schemaChild(schemaNode, child.getIdentifier()); // An augment cannot change other augment, so we do not update parent node if we are streaming // children of AugmentationSchema (otherwise we would fail to find schema for nested augmentations): if (updateParentNode) { if (schemaNode instanceof AugmentationSchemaNode) { // child nodes would not have nested augmentations, so we stop moving parentNode: return new Modification(childId, child, parentNode, schemaChild, false); } else { // update parent node: return new Modification(childId, child, schemaNode, schemaChild, true); } } return new Modification(childId, child, parentNode, schemaChild, updateParentNode); }); }
private LazyDataObjectModification(final BindingCodecTreeNode<T> codec, final DataTreeCandidateNode domData) { this.codec = Preconditions.checkNotNull(codec); this.domData = Preconditions.checkNotNull(domData); this.identifier = codec.deserializePathArgument(domData.getIdentifier()); }
com.google.common.base.Optional<NormalizedNode<?, ?>> getDataAfter() { // TODO(HONEYCOMB-192): switch to java.util.Optional when rest of ODL infra does return com.google.common.base.Optional.fromNullable(dataCandidate.getDataAfter().orElse(null)); }
private SimpleRoutingPolicy getSimpleRoutingPolicy(final DataTreeCandidateNode rootNode) { final DataTreeCandidateNode statusChange = rootNode.getModifiedChild(SIMPLE_ROUTING_POLICY_NID); if (statusChange != null) { final Optional<NormalizedNode<?, ?>> maybePeerStatus = statusChange.getDataAfter(); if (maybePeerStatus.isPresent()) { return SimpleRoutingPolicy.valueOf(BindingMapping.getClassName((String) (maybePeerStatus.get()).getValue())); } } return null; }