ModificationType getModificationType() { return dataCandidate.getModificationType(); }
@Override public DataObjectModification.ModificationType getModificationType() { switch(domData.getModificationType()) { case WRITE: return DataObjectModification.ModificationType.WRITE; case APPEARED: case SUBTREE_MODIFIED: return DataObjectModification.ModificationType.SUBTREE_MODIFIED; case DISAPPEARED: case DELETE: return DataObjectModification.ModificationType.DELETE; default: // TODO: Should we lie about modification type instead of exception? throw new IllegalStateException("Unsupported DOM Modification type " + domData.getModificationType()); } }
@Nonnull @Override public TreeNodeModification.ModificationType getModificationType() { switch (domData.getModificationType()) { case APPEARED: case WRITE: return TreeNodeModification.ModificationType.WRITE; case SUBTREE_MODIFIED: return TreeNodeModification.ModificationType.SUBTREE_MODIFIED; case DISAPPEARED: case DELETE: return TreeNodeModification.ModificationType.DELETE; default: // TODO: Should we lie about modification type instead of exception? throw new IllegalStateException("Unsupported DOM Modification type " + domData.getModificationType()); } }
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()); } }
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()); } }
private void validateNode(final DataTreeCandidateNode node, final LeafRefContext referencedByCtx, final LeafRefContext referencingCtx, final YangInstanceIdentifier current) { if (node.getModificationType() == ModificationType.WRITE && node.getDataAfter().isPresent()) { validateNodeData(node.getDataAfter().get(), referencedByCtx, referencingCtx, node.getModificationType(), current); return; } if (node.getModificationType() == ModificationType.DELETE && referencedByCtx != null) { validateNodeData(node.getDataBefore().get(), referencedByCtx, null, node.getModificationType(), current); return; } for (final DataTreeCandidateNode childNode : node.getChildNodes()) { if (childNode.getModificationType() != ModificationType.UNMODIFIED) { final LeafRefContext childReferencedByCtx = getReferencedByCtxChild(referencedByCtx, childNode); final LeafRefContext childReferencingCtx = getReferencingCtxChild(referencingCtx, childNode); if (childReferencedByCtx != null || childReferencingCtx != null) { validateNode(childNode, childReferencedByCtx,childReferencingCtx, current.node(childNode.getIdentifier())); } } } }
private void validateNode(final DataTreeCandidateNode node, final LeafRefContext referencedByCtx, final LeafRefContext referencingCtx, final YangInstanceIdentifier current) { if (node.getModificationType() == ModificationType.WRITE && node.getDataAfter().isPresent()) { validateNodeData(node.getDataAfter().get(), referencedByCtx, referencingCtx, node.getModificationType(), current); return; } if (node.getModificationType() == ModificationType.DELETE && referencedByCtx != null) { validateNodeData(node.getDataBefore().get(), referencedByCtx, null, node.getModificationType(), current); return; } for (final DataTreeCandidateNode childNode : node.getChildNodes()) { if (childNode.getModificationType() != ModificationType.UNMODIFIED) { final LeafRefContext childReferencedByCtx = getReferencedByCtxChild(referencedByCtx, childNode); final LeafRefContext childReferencingCtx = getReferencingCtxChild(referencingCtx, childNode); if (childReferencedByCtx != null || childReferencingCtx != null) { validateNode(childNode, childReferencedByCtx,childReferencingCtx, current.node(childNode.getIdentifier())); } } } }
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); } } } }
/** * Process a candidate tree with respect to registered listeners. * * @param candidate candidate three which needs to be processed */ protected final void processCandidateTree(@Nonnull final DataTreeCandidate candidate) { final DataTreeCandidateNode node = candidate.getRootNode(); if (node.getModificationType() == ModificationType.UNMODIFIED) { LOG.debug("Skipping unmodified candidate {}", candidate); return; } try (final RegistrationTreeSnapshot<AbstractDOMDataTreeChangeListenerRegistration<?>> snapshot = takeSnapshot()) { final List<PathArgument> toLookup = ImmutableList.copyOf(candidate.getRootPath().getPathArguments()); lookupAndNotify(toLookup, 0, snapshot.getRootNode(), candidate); } }
@Override public void onDataTreeChanged(final Collection<DataTreeCandidate> changes) { LOG.debug("Data change received for AdjRibOut {}", changes); for (final DataTreeCandidate tc : changes) { LOG.trace("Change {} type {}", tc.getRootNode(), tc.getRootNode().getModificationType()); for (final DataTreeCandidateNode child : tc.getRootNode().getChildNodes()) { processSupportedFamilyRoutes(child); } } this.session.flush(); }
/** * Process a candidate tree with respect to registered listeners. * * @param candidate candidate three which needs to be processed * @return true if at least one listener was notified or false. */ protected final boolean processCandidateTree(final @NonNull DataTreeCandidate candidate) { final DataTreeCandidateNode node = candidate.getRootNode(); if (node.getModificationType() == ModificationType.UNMODIFIED) { LOG.debug("Skipping unmodified candidate {}", candidate); return false; } try (RegistrationTreeSnapshot<AbstractDOMDataTreeChangeListenerRegistration<?>> snapshot = takeSnapshot()) { final List<PathArgument> toLookup = ImmutableList.copyOf(candidate.getRootPath().getPathArguments()); final Multimap<AbstractDOMDataTreeChangeListenerRegistration<?>, DataTreeCandidate> listenerChanges = Multimaps.newListMultimap(new IdentityHashMap<>(), ArrayList::new); lookupAndNotify(toLookup, 0, snapshot.getRootNode(), candidate, listenerChanges); for (Map.Entry<AbstractDOMDataTreeChangeListenerRegistration<?>, Collection<DataTreeCandidate>> entry: listenerChanges.asMap().entrySet()) { notifyListener(entry.getKey(), entry.getValue()); } return !listenerChanges.isEmpty(); } }
/** * Process a candidate tree with respect to registered listeners. * * @param candidate candidate three which needs to be processed */ protected final void processCandidateTree(@Nonnull final DataTreeCandidate candidate) { final DataTreeCandidateNode node = candidate.getRootNode(); if (node.getModificationType() == ModificationType.UNMODIFIED) { LOG.debug("Skipping unmodified candidate {}", candidate); return; } try (RegistrationTreeSnapshot<AbstractDOMDataTreeChangeListenerRegistration<?>> snapshot = takeSnapshot()) { lookupAndNotify(candidate.getRootPath().getPathArguments(), 0, snapshot.getRootNode(), candidate); } }
void startCommit(final SimpleShardDataTreeCohort cohort, final DataTreeCandidate candidate) { final CommitEntry entry = pendingTransactions.peek(); Preconditions.checkState(entry != null, "Attempted to start commit of %s when no transactions pending", cohort); final SimpleShardDataTreeCohort current = entry.cohort; Verify.verify(cohort.equals(current), "Attempted to commit %s while %s is pending", cohort, current); if (shard.canSkipPayload() || candidate.getRootNode().getModificationType() == ModificationType.UNMODIFIED) { LOG.debug("{}: No replication required, proceeding to finish commit", logContext); finishCommit(cohort); return; } final TransactionIdentifier txId = cohort.getIdentifier(); final Payload payload; try { payload = CommitTransactionPayload.create(txId, candidate); } catch (IOException e) { LOG.error("{}: Failed to encode transaction {} candidate {}", logContext, txId, candidate, e); pendingTransactions.poll().cohort.failedCommit(e); return; } // Once completed, we will continue via payloadReplicationComplete entry.lastAccess = shard.ticker().read(); shard.persistPayload(txId, payload); LOG.debug("{}: Transaction {} submitted to persistence", logContext, txId); }
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); } }
@Override public void onDataTreeChanged(Collection<DataTreeCandidate> changes) { for(DataTreeCandidate change: changes) { DataTreeCandidateNode changeRoot = change.getRootNode(); ModificationType type = changeRoot.getModificationType(); LOG.debug("{}: Candidate node changed: {}, {}", logId, type, change.getRootPath()); NodeIdentifierWithPredicates candidateKey = (NodeIdentifierWithPredicates) change.getRootPath().getLastPathArgument(); String candidate = candidateKey.getKeyValues().get(CANDIDATE_NAME_QNAME).toString(); YangInstanceIdentifier entityId = extractEntityPath(change.getRootPath()); if(type == ModificationType.WRITE || type == ModificationType.APPEARED) { LOG.debug("{}: Candidate {} was added for entity {}", logId, candidate, entityId); Collection<String> currentCandidates = addToCurrentCandidates(entityId, candidate); shard.tell(new CandidateAdded(entityId, candidate, new ArrayList<>(currentCandidates)), shard); } else if(type == ModificationType.DELETE || type == ModificationType.DISAPPEARED) { LOG.debug("{}: Candidate {} was removed for entity {}", logId, candidate, entityId); Collection<String> currentCandidates = removeFromCurrentCandidates(entityId, candidate); shard.tell(new CandidateRemoved(entityId, candidate, new ArrayList<>(currentCandidates)), shard); } } }
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); } }
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 notifyNode(final YangInstanceIdentifier path, final RegistrationTreeNode<AbstractDOMDataTreeChangeListenerRegistration<?>> regNode, final DataTreeCandidateNode candNode, final Multimap<AbstractDOMDataTreeChangeListenerRegistration<?>, DataTreeCandidate> listenerChanges) { if (candNode.getModificationType() == ModificationType.UNMODIFIED) { LOG.debug("Skipping unmodified candidate {}", path); return; } final Collection<AbstractDOMDataTreeChangeListenerRegistration<?>> regs = regNode.getRegistrations(); if (!regs.isEmpty()) { addToListenerChanges(regs, path, candNode, listenerChanges); } 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, listenerChanges); } for (RegistrationTreeNode<AbstractDOMDataTreeChangeListenerRegistration<?>> rc : regNode.getInexactChildren(candChild.getIdentifier())) { notifyNode(path.node(candChild.getIdentifier()), rc, candChild, listenerChanges); } } } }
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 filterOutPeerRole(final PeerId peerId, final DataTreeCandidateNode rootNode, final YangInstanceIdentifier rootPath) { final DataTreeCandidateNode roleChange = rootNode.getModifiedChild(PEER_ROLE_NID); if (roleChange != null) { if (rootNode.getModificationType() != ModificationType.DELETE) { this.cacheDisconnectedPeers.reconnected(peerId); } // Check for removal final Optional<NormalizedNode<?, ?>> maybePeerRole = roleChange.getDataAfter(); final YangInstanceIdentifier peerPath = IdentifierUtils.peerPath(rootPath); LOG.debug("Data Changed for Peer role {} path {}, dataBefore {}, dataAfter {}", roleChange.getIdentifier(), peerPath , roleChange.getDataBefore(), maybePeerRole); final PeerRole role = PeerRoleUtil.roleForChange(maybePeerRole); final SimpleRoutingPolicy srp = getSimpleRoutingPolicy(rootNode); if(SimpleRoutingPolicy.AnnounceNone == srp) { return; } this.peerPolicyTracker.peerRoleChanged(peerPath, role); } }