@SuppressWarnings({"unchecked", "rawtypes"}) static <T extends DataObject> DataTreeModification<T> create(final BindingToNormalizedNodeCodec codec, final DataTreeCandidate domChange, final LogicalDatastoreType datastoreType) { final Entry<InstanceIdentifier<?>, BindingCodecTreeNode<?>> codecCtx = codec.getSubtreeCodec(domChange.getRootPath()); return new LazyDataTreeModification(datastoreType, codecCtx.getKey(), codecCtx.getValue(), domChange); }
@Override protected synchronized void appendInitial(final State state) { // We are still starting up, so all we need to do is squash reported changes to an initial write event final DataTreeCandidate last = Iterables.getLast(state.changes); changes.clear(); final Optional<NormalizedNode<?, ?>> lastData = last.getRootNode().getDataAfter(); if (lastData.isPresent()) { changes.add(DataTreeCandidates.fromNormalizedNode(last.getRootPath(), lastData.get())); } }
private Collection<DataTreeCohortActor.CanCommit> perform(final RegistrationTreeNode<ActorRef> rootNode) { final List<PathArgument> toLookup = candidate.getRootPath().getPathArguments(); lookupAndCreateCanCommits(toLookup, 0, rootNode); return messages; } }
@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); } } }
@SuppressWarnings({"unchecked", "rawtypes"}) static <T extends DataObject> DataTreeModification<T> create(final BindingToNormalizedNodeCodec codec, final DataTreeCandidate domChange, final LogicalDatastoreType datastoreType) { final Entry<InstanceIdentifier<?>, BindingCodecTreeNode<?>> codecCtx = codec.getSubtreeCodec( domChange.getRootPath()); final DataTreeIdentifier<?> path = DataTreeIdentifier.create(datastoreType, codecCtx.getKey()); final DataObjectModification<?> modification = LazyDataObjectModification.create(codecCtx.getValue(), domChange.getRootNode()); return new LazyDataTreeModification(path, modification); }
@SuppressWarnings({ "unchecked", "rawtypes" }) private static <T extends TreeNode> DataTreeModification<T> create(final BindingToNormalizedNodeCodec codec, final DataTreeCandidate domChange, final LogicalDatastoreType datastoreType) { final Entry<InstanceIdentifier<?>, BindingTreeNodeCodec<?>> codecCtx = codec.getSubtreeCodec(domChange.getRootPath()); final DataTreeIdentifier<?> path = DataTreeIdentifier.create(datastoreType, codecCtx.getKey()); final TreeNodeModification<?> modification = LazyTreeNodeModification.create(codecCtx.getValue(), domChange.getRootNode()); return new LazyDataTreeModification(path, modification); }
/** * 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) { for(DataTreeCandidate change: changes) { DataTreeCandidateNode changeRoot = change.getRootNode(); LeafNode<?> ownerLeaf = (LeafNode<?>) changeRoot.getDataAfter().get(); LOG.debug("{}: Entity node changed: {}, {}", logId(), changeRoot.getModificationType(), change.getRootPath()); String newOwner = extractOwner(ownerLeaf); String origOwner = null; Optional<NormalizedNode<?, ?>> dataBefore = changeRoot.getDataBefore(); if(dataBefore.isPresent()) { origOwner = extractOwner((LeafNode<?>) changeRoot.getDataBefore().get()); } LOG.debug("{}: New owner: {}, Original owner: {}", logId(), newOwner, origOwner); if (!Objects.equals(origOwner, newOwner)) { boolean isOwner = localMemberName.equals(newOwner); boolean wasOwner = localMemberName.equals(origOwner); boolean hasOwner = !Strings.isNullOrEmpty(newOwner); DOMEntity entity = createEntity(change.getRootPath()); LOG.debug("{}: Calling notifyEntityOwnershipListeners: entity: {}, wasOwner: {}, isOwner: {}, hasOwner: {}", logId(), entity, wasOwner, isOwner, hasOwner); listenerSupport.notifyEntityOwnershipListeners(entity, wasOwner, isOwner, hasOwner); } } }
private Map<RouteUpdateKey, RouteEntry> update(final DOMDataWriteTransaction tx, final Collection<DataTreeCandidate> changes) { final Map<RouteUpdateKey, RouteEntry> ret = new HashMap<>(); for (final DataTreeCandidate tc : changes) { final YangInstanceIdentifier rootPath = tc.getRootPath(); final DataTreeCandidateNode rootNode = tc.getRootNode(); final PeerId peerId = IdentifierUtils.peerKeyToPeerId(rootPath); filterOutPeerRole(peerId, rootNode, rootPath); filterOutChangesToSupportedTables(peerId, rootNode); filterOutAnyChangeOutsideEffRibsIn(peerId, rootNode, ret, rootPath, tx); } return ret; }
private void lookupAndNotify(final List<PathArgument> args, final int offset, final RegistrationTreeNode<AbstractDOMDataTreeChangeListenerRegistration<?>> node, final DataTreeCandidate candidate) { if (args.size() != offset) { final PathArgument arg = args.get(offset); final RegistrationTreeNode<AbstractDOMDataTreeChangeListenerRegistration<?>> exactChild = node.getExactChild(arg); if (exactChild != null) { lookupAndNotify(args, offset + 1, exactChild, candidate); } for (RegistrationTreeNode<AbstractDOMDataTreeChangeListenerRegistration<?>> c : node.getInexactChildren(arg)) { lookupAndNotify(args, offset + 1, c, candidate); } } else { notifyNode(candidate.getRootPath(), node, candidate.getRootNode()); } }
/** * 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); } }
@Override public void onDataTreeChanged(@Nonnull Collection<DataTreeCandidate> changes) { for (DataTreeCandidate change : changes) { DataTreeCandidateNode changeRoot = change.getRootNode(); LeafNode<?> ownerLeaf = (LeafNode<?>) changeRoot.getDataAfter().get(); String entityType = entityTypeFromEntityPath(change.getRootPath()); String newOwner = extractOwner(ownerLeaf); if(!Strings.isNullOrEmpty(newOwner)) { updateStatistics(entityType, newOwner, 1); } Optional<NormalizedNode<?, ?>> dataBefore = changeRoot.getDataBefore(); if (dataBefore.isPresent()) { String origOwner = extractOwner((LeafNode<?>) changeRoot.getDataBefore().get()); if(!Strings.isNullOrEmpty(origOwner)) { updateStatistics(entityType, origOwner, -1); } } } }
private void lookupAndNotify(final List<PathArgument> args, final int offset, final RegistrationTreeNode<AbstractDOMDataTreeChangeListenerRegistration<?>> node, final DataTreeCandidate candidate) { if (args.size() != offset) { final PathArgument arg = args.get(offset); final RegistrationTreeNode<AbstractDOMDataTreeChangeListenerRegistration<?>> exactChild = node.getExactChild(arg); if (exactChild != null) { lookupAndNotify(args, offset + 1, exactChild, candidate); } for (RegistrationTreeNode<AbstractDOMDataTreeChangeListenerRegistration<?>> c : node.getInexactChildren(arg)) { lookupAndNotify(args, offset + 1, c, candidate); } } else { notifyNode(candidate.getRootPath(), node, candidate.getRootNode()); } }
private void lookupAndCreateCanCommits(final List<PathArgument> args, final int offset, final RegistrationTreeNode<ActorRef> node) { if (args.size() != offset) { final PathArgument arg = args.get(offset); final RegistrationTreeNode<ActorRef> exactChild = node.getExactChild(arg); if (exactChild != null) { lookupAndCreateCanCommits(args, offset + 1, exactChild); } for (final RegistrationTreeNode<ActorRef> c : node.getInexactChildren(arg)) { lookupAndCreateCanCommits(args, offset + 1, c); } } else { lookupAndCreateCanCommits(candidate.getRootPath(), node, candidate.getRootNode()); } }
@Override public void onDataTreeChanged(@Nonnull final Collection<DataTreeCandidate> changes) { LOG.trace("Data changed called to effective RIB. Change : {}", changes); // we have a lot of transactions created for 'nothing' because a lot of changes // are skipped, so ensure we only create one transaction when we really need it DOMDataWriteTransaction tx = null; for (final DataTreeCandidate tc : changes) { final YangInstanceIdentifier rootPath = tc.getRootPath(); final DataTreeCandidateNode root = tc.getRootNode(); for (final DataTreeCandidateNode table : root.getChildNodes()) { if (tx == null) { tx = this.chain.newWriteOnlyTransaction(); } changeDataTree(tx, rootPath, root, table); } } if (tx != null) { tx.submit(); } }
private void lookupAndNotify(final List<PathArgument> args, final int offset, final RegistrationTreeNode<AbstractDOMDataTreeChangeListenerRegistration<?>> node, final DataTreeCandidate candidate, final Multimap<AbstractDOMDataTreeChangeListenerRegistration<?>, DataTreeCandidate> listenerChanges) { if (args.size() != offset) { final PathArgument arg = args.get(offset); final RegistrationTreeNode<AbstractDOMDataTreeChangeListenerRegistration<?>> exactChild = node.getExactChild(arg); if (exactChild != null) { lookupAndNotify(args, offset + 1, exactChild, candidate, listenerChanges); } for (RegistrationTreeNode<AbstractDOMDataTreeChangeListenerRegistration<?>> c : node.getInexactChildren(arg)) { lookupAndNotify(args, offset + 1, c, candidate, listenerChanges); } } else { notifyNode(candidate.getRootPath(), node, candidate.getRootNode(), listenerChanges); } }
@Override public void onDataTreeChanged(final Collection<DataTreeCandidate> dataTreeCandidates) { for (final DataTreeCandidate dataTreeCandidate : dataTreeCandidates) { final YangInstanceIdentifier agentKey = dataTreeCandidate.getRootPath(); final DataObjectModification<AmqpUserAgent> changeDiff = null; // todo - remove null; and initialize switch (changeDiff.getModificationType()) { case WRITE: createOrReplace(agentKey, changeDiff.getDataAfter()); break; case DELETE: removeAndClose(agentKey); default: LOG.info("Unsupported change type {} for {}", changeDiff.getModificationType(), agentKey); break; } } } }
private static void applyToCursorAwareModification(final CursorAwareDataTreeModification modification, final DataTreeCandidate candidate) { final YangInstanceIdentifier candidatePath = candidate.getRootPath(); if (candidatePath.isEmpty()) { try (DataTreeModificationCursor cursor = modification.openCursor()) { DataTreeCandidateNodes.applyRootToCursor(cursor, candidate.getRootNode()); } } else { try (DataTreeModificationCursor cursor = modification.openCursor(candidatePath.getParent()).get()) { DataTreeCandidateNodes.applyRootedNodeToCursor(cursor, candidatePath, candidate.getRootNode()); } } }
private static void applyToCursorAwareModification(final CursorAwareDataTreeModification modification, final DataTreeCandidate candidate) { final YangInstanceIdentifier candidatePath = candidate.getRootPath(); if (candidatePath.isEmpty()) { try (DataTreeModificationCursor cursor = modification.openCursor()) { DataTreeCandidateNodes.applyRootToCursor(cursor, candidate.getRootNode()); } } else { try (DataTreeModificationCursor cursor = modification.openCursor(candidatePath.getParent()).get()) { DataTreeCandidateNodes.applyRootedNodeToCursor(cursor, candidatePath, candidate.getRootNode()); } } }
private DataObjectUpdates getUpdates(final DataTreeWriteContext dataTreeContext) { DataObjectUpdates updates = dataTreeContext.getUpdates(); if (updates != null) { return updates; } else { final DataTreeCandidate candidate = dataTreeContext.getCandidate(); final DataTreeCandidateNode rootNode = candidate.getRootNode(); final YangInstanceIdentifier rootPath = candidate.getRootPath(); LOG.trace("ConfigDataTree.getUpdates() rootPath={}, rootNode={}, dataBefore={}, dataAfter={}", rootPath, rootNode, rootNode.getDataBefore(), rootNode.getDataAfter()); final ModificationDiff modificationDiff = new ModificationDiff.ModificationDiffBuilder() .setCtx(schema).build(rootNode); LOG.debug("ConfigDataTree.getUpdates() diff: {}", modificationDiff); // Distinguish between updates (create + update) and deletes updates = toBindingAware(writerRegistry, modificationDiff.getUpdates()); dataTreeContext.setUpdates(updates); return updates; } }