com.google.common.base.Optional<NormalizedNode<?, ?>> getDataBefore() { // TODO(HONEYCOMB-192): switch to java.util.Optional when rest of ODL infra does return com.google.common.base.Optional.fromNullable(dataCandidate.getDataBefore().orElse(null)); }
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; }
boolean isBeforeAndAfterDifferent() { if (dataCandidate.getDataBefore().isPresent()) { return !dataCandidate.getDataBefore().get().equals(dataCandidate.getDataAfter().orElse(null)); } // considering not a modification if data after is also null return dataCandidate.getDataAfter().isPresent(); }
@Nullable @Override public T getDataBefore() { return deserialize(domData.getDataBefore()); }
@Override public T getDataBefore() { return deserialize(domData.getDataBefore()); }
@Override public T getDataBefore() { return deserialize(domData.getDataBefore()); }
private void initializeTableWithExistentRoutes(final DataTreeCandidateNode table, final PeerId peerIdOfNewPeer, final YangInstanceIdentifier rootPath, final DOMDataWriteTransaction tx) { if (!table.getDataBefore().isPresent() && this.peerPolicyTracker.isTableSupported(peerIdOfNewPeer)) { LOG.debug("Peer {} table has been created, inserting existent routes", peerIdOfNewPeer); final PeerRole newPeerRole = this.peerPolicyTracker.getRole(IdentifierUtils.peerPath(rootPath)); final PeerExportGroup peerGroup = this.peerPolicyTracker.getPeerGroup(newPeerRole); this.routeEntries.entrySet().forEach(entry -> entry.getValue().writeRoute(peerIdOfNewPeer, entry.getKey(), rootPath, peerGroup, this.localTablesKey, this.peerPolicyTracker, this.ribSupport, this.cacheDisconnectedPeers, tx)); } }
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()); }
public static BindingStructuralType from(final DataTreeCandidateNode domChildNode) { Optional<NormalizedNode<?, ?>> dataBased = domChildNode.getDataAfter(); if (!dataBased.isPresent()) { dataBased = domChildNode.getDataBefore(); } if (dataBased.isPresent()) { return from(dataBased.get()); } return from(domChildNode.getIdentifier()); }
static BindingStructuralType from(final DataTreeCandidateNode domChildNode) { Optional<NormalizedNode<?, ?>> dataBased = domChildNode.getDataAfter(); if (!dataBased.isPresent()) { dataBased = domChildNode.getDataBefore(); } if (dataBased.isPresent()) { return from(dataBased.get()); } return from(domChildNode.getIdentifier()); }
@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 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); } } } }
@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 void processRouteChange(final DataTreeCandidateNode route) { final Update update; switch (route.getModificationType()) { case UNMODIFIED: LOG.debug("Skipping unmodified route {}", route.getIdentifier()); return; case DELETE: case DISAPPEARED: // FIXME: we can batch deletions into a single batch update = withdraw((MapEntryNode) route.getDataBefore().get()); LOG.debug("Withdrawing routes {}", update); break; case APPEARED: case SUBTREE_MODIFIED: case WRITE: update = advertise((MapEntryNode) route.getDataAfter().get()); LOG.debug("Advertising routes {}", update); break; default: LOG.warn("Ignoring unhandled modification type {}", route.getModificationType()); return; } this.session.write(update); }
private void updateRoutesEntries(final DataTreeCandidateNode child, final PeerId peerId, final Map<RouteUpdateKey, RouteEntry> routes) { final UnsignedInteger routerId = RouterIds.routerIdForPeerId(peerId); final Collection<DataTreeCandidateNode> modifiedRoutes = this.ribSupport.changedRoutes(child); for (final DataTreeCandidateNode route : modifiedRoutes) { final PathArgument routeId = this.ribSupport.createRouteKeyPathArgument(route.getIdentifier()); RouteEntry entry = this.routeEntries.get(routeId); final Optional<NormalizedNode<?, ?>> maybeData = route.getDataAfter(); final Optional<NormalizedNode<?, ?>> maybeDataBefore = route.getDataBefore(); if (maybeData.isPresent()) { if (entry == null) { entry = createEntry(routeId); } entry.addRoute(routerId, this.ribSupport.extractPathId(maybeData.get()), this.attributesIdentifier, maybeData.get()); } else if (entry != null && entry.removeRoute(routerId, this.ribSupport.extractPathId(maybeDataBefore.get()))) { this.routeEntries.remove(routeId); LOG.trace("Removed route from {}", routerId); } final RouteUpdateKey routeUpdateKey = new RouteUpdateKey(peerId, routeId); LOG.debug("Updated route {} entry {}", routeId, entry); routes.put(routeUpdateKey, entry); } updateRouteCounter(); }
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; } }
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); } }
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())); } } } }
final TablesKey tablesKey = new TablesKey(ribSupport.getAfi(), ribSupport.getSafi()); LOG.debug("Process table {} type {}, dataAfter {}, dataBefore {}", childIdentifier, child .getModificationType(), childDataAfter, child.getDataBefore()); final YangInstanceIdentifier childPath = tablePath.node(childIdentifier); switch (child.getModificationType()) {