private void unregisterOnTrue(boolean _true) { if (_true) { LOG.debug("Unregistering listener for path {}", iid.getRootIdentifier()); if (registeredListener != null) { registeredListener.close(); } } } }
private InstanceIdentifier<ForwardingConstruct> getFcIid(DataTreeModification<ForwardingConstruct> fcModification) { return fcModification.getRootPath().getRootIdentifier(); }
private ListenableFutureSetter(DataBroker dataProvider, SettableFuture<Void> future, DataTreeIdentifier<T> iid, ModificationType modificationForFutureSet) { this.future = Preconditions.checkNotNull(future); Preconditions.checkArgument(!future.isDone()); this.modificationForFutureSet = Preconditions.checkNotNull(modificationForFutureSet); this.iid = Preconditions.checkNotNull(iid); registeredListener = dataProvider.registerDataTreeChangeListener(iid, this); LOG.debug("Registered listener for path {}", iid.getRootIdentifier()); }
@Override public void onDataTreeChanged(Collection<DataTreeModification<T>> changes) { changes.forEach(modif -> { DataObjectModification<T> rootNode = modif.getRootNode(); ModificationType modificationType = rootNode.getModificationType(); if (modificationType == modificationForFutureSet) { LOG.debug("{} in OPER DS: {}", modificationType.name(), iid.getRootIdentifier()); unregisterOnTrue(future.set(null)); } }); }
private DOMDataTreeIdentifier toDomTreeIdentifier(final DataTreeIdentifier<?> treeId) { final YangInstanceIdentifier domPath = codec.toYangInstanceIdentifierBlocking(treeId.getRootIdentifier()); return new DOMDataTreeIdentifier(treeId.getDatastoreType(), domPath); } }
@Override public void onDataTreeChanged(@Nonnull Collection<DataTreeModification<Node>> changes) { LOG.debug("Topology Node changed. Changes {}", changes); for (DataTreeModification<Node> modification : changes) { DataObjectModification<Node> rootNode = modification.getRootNode(); Node dataAfter = rootNode.getDataAfter(); Node dataBefore = rootNode.getDataBefore(); NodeOperEvent event = new NodeOperEvent(modification.getRootPath().getRootIdentifier(), dataBefore, dataAfter); eventBus.post(event); nodeManager.syncNodes(dataAfter, dataBefore); } }
private void processRemovedNode(final DataTreeModification<FlowCapableNode> modification) { final InstanceIdentifier<FlowCapableNode> iiToNodeInInventory = modification.getRootPath().getRootIdentifier(); final NodeId nodeId = provideTopologyNodeId(iiToNodeInInventory); final InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node> iiToTopologyRemovedNode = provideIIToTopologyNode(nodeId); if (iiToTopologyRemovedNode != null) { operationProcessor.enqueueOperation(new TopologyOperation() { @Override public void applyOperation(final ReadWriteTransaction transaction) { transaction.delete(LogicalDatastoreType.OPERATIONAL, iiToTopologyRemovedNode); TopologyManagerUtil.removeAffectedLinks(nodeId, transaction, II_TO_TOPOLOGY); } }); } else { LOG.debug("Instance identifier to inventory wasn't translated to topology while deleting node."); } }
private void processAddedNode(final DataTreeModification<FlowCapableNode> modification) { final InstanceIdentifier<FlowCapableNode> iiToNodeInInventory = modification.getRootPath().getRootIdentifier(); final NodeId nodeIdInTopology = provideTopologyNodeId(iiToNodeInInventory); if (nodeIdInTopology != null) { final InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node> iiToTopologyNode = provideIIToTopologyNode(nodeIdInTopology); sendToTransactionChain(prepareTopologyNode(nodeIdInTopology, iiToNodeInInventory), iiToTopologyNode); } else { LOG.debug("Inventory node key is null. Data can't be written to topology"); } }
private void processRemovedConnector(final DataTreeModification<T> modification) { final InstanceIdentifier<T> identifier = modification.getRootPath().getRootIdentifier(); if (compareIITail(identifier, II_TO_FLOW_CAPABLE_NODE_CONNECTOR)) { InstanceIdentifier<NodeConnector> nodeConnectorInstanceId = identifier.firstIdentifierOf(NodeConnector.class); notifyNodeConnectorDisappeared(nodeConnectorInstanceId); } }
@Override public synchronized void onDataTreeChanged(final Collection<DataTreeModification<Bgp>> changes) { if (this.closed) { LOG.trace("BGP Deployer was already closed, skipping changes."); return; } for (final DataTreeModification<Bgp> dataTreeModification : changes) { final InstanceIdentifier<Bgp> rootIdentifier = dataTreeModification.getRootPath().getRootIdentifier(); final DataObjectModification<Bgp> rootNode = dataTreeModification.getRootNode(); LOG.trace("BGP configuration has changed: {}", rootNode); for (final DataObjectModification<? extends DataObject> dataObjectModification : rootNode.getModifiedChildren()) { if (dataObjectModification.getDataType().equals(Global.class)) { onGlobalChanged((DataObjectModification<Global>) dataObjectModification, rootIdentifier); } else if (dataObjectModification.getDataType().equals(Neighbors.class)) { onNeighborsChanged((DataObjectModification<Neighbors>) dataObjectModification, rootIdentifier); } } } }
@VisibleForTesting protected void routeChanged(final DataTreeModification<T> change, final ReadWriteTransaction trans) { final DataObjectModification<T> root = change.getRootNode(); switch (root.getModificationType()) { case DELETE: removeObject(trans, change.getRootPath().getRootIdentifier(), root.getDataBefore()); break; case SUBTREE_MODIFIED: case WRITE: if (root.getDataBefore() != null) { removeObject(trans, change.getRootPath().getRootIdentifier(), root.getDataBefore()); } createObject(trans, change.getRootPath().getRootIdentifier(), root.getDataAfter()); break; default: throw new IllegalArgumentException("Unhandled modification type " + root.getModificationType()); } }
private void processAddedConnector(final DataTreeModification<T> modification) { final InstanceIdentifier<T> identifier = modification.getRootPath().getRootIdentifier(); InstanceIdentifier<NodeConnector> nodeConnectorInstanceId =identifier.firstIdentifierOf(NodeConnector.class); if (compareIITail(identifier, II_TO_FLOW_CAPABLE_NODE_CONNECTOR)) { FlowCapableNodeConnector flowConnector = (FlowCapableNodeConnector) modification.getRootNode().getDataAfter(); if (!isPortDown(flowConnector)) { notifyNodeConnectorAppeared(nodeConnectorInstanceId, flowConnector); } else { iiToDownFlowCapableNodeConnectors.put(nodeConnectorInstanceId, flowConnector); } } }
private String getDpnIdFromNodeConnector(DataTreeModification<FlowCapableNodeConnector> newDataObject) { InstanceIdentifier<FlowCapableNodeConnector> key = newDataObject.getRootPath().getRootIdentifier(); NodeConnectorId nodeConnectorId = InstanceIdentifier.keyOf(key.firstIdentifierOf(NodeConnector.class)).getId(); String dpnFromNodeConnectorId = getDpnFromNodeConnectorId(nodeConnectorId); return dpnFromNodeConnectorId; }
@Override public void onDataTreeChanged(@Nonnull final Collection<DataTreeModification<EndpointForwardingTemplateBySubnet>> collection) { for (DataTreeModification<EndpointForwardingTemplateBySubnet> change : collection) { LOG.trace("received modification: {} -> {}", change.getRootPath(), change.getRootNode().getModificationType()); // update cached dao final InstanceIdentifier<EndpointForwardingTemplateBySubnet> changePath = change.getRootPath().getRootIdentifier(); final IpPrefix changeKey = changePath.firstKeyOf(EndpointForwardingTemplateBySubnet.class).getIpPrefix(); SxpListenerUtil.updateCachedDao(templateCachedDao, changeKey, change); final EndpointForwardingTemplateBySubnet epForwardingTemplate = change.getRootNode().getDataAfter(); processWithEPTemplates(epForwardingTemplate); } }
/** * Invoked when the specified data tree has been modified. * * @param changes A collection of data tree modifications. */ @Override public final void onDataTreeChanged( @Nonnull Collection<DataTreeModification<T>> changes) { TreeChangeContext<T> ctx = new TreeChangeContext<>(); C ectx = enterEvent(); try { for (DataTreeModification<T> change: changes) { ctx.setRootPath(change.getRootPath().getRootIdentifier()); handleTree(ctx, ectx, change); } } catch (RuntimeException e) { getLogger().error( "Unexpected exception in data tree change event listener.", e); } finally { exitEvent(ectx); } } }
@Override public void onDataTreeChanged(@Nonnull final Collection<DataTreeModification<MasterDatabaseBinding>> collection) { for (DataTreeModification<MasterDatabaseBinding> change : collection) { LOG.trace("received modification: {} -> {}", change.getRootPath(), change.getRootNode().getModificationType()); // update cached dao final MasterDatabaseBinding sxpMasterDBItem = change.getRootNode().getDataAfter(); if (sxpMasterDBItem == null) { //TODO: cover sgt-ip mapping removal LOG.debug("ip-sgt mapping was removed - NOOP: {}", change.getRootPath().getRootIdentifier().firstKeyOf(MasterDatabaseBinding.class)); } else { final IpPrefix ipPrefixKey = sxpMasterDBItem.getIpPrefix(); SxpListenerUtil.updateCachedDao(masterDBBindingDaoCached, ipPrefixKey, change); processWithEPTemplates(sxpMasterDBItem); } } }
@Override public void onDataTreeChanged(@Nonnull final Collection<DataTreeModification<EndpointPolicyTemplateBySgt>> collection) { for (DataTreeModification<EndpointPolicyTemplateBySgt> change : collection) { LOG.trace("received modification: {} -> {}", change.getRootPath(), change.getRootNode().getModificationType()); // update cached dao final InstanceIdentifier<EndpointPolicyTemplateBySgt> changePath = change.getRootPath().getRootIdentifier(); final Sgt changeKey = changePath.firstKeyOf(EndpointPolicyTemplateBySgt.class).getSgt(); SxpListenerUtil.updateCachedDao(templateCachedDao, changeKey, change); final EndpointPolicyTemplateBySgt epPolicyTemplate = change.getRootNode().getDataAfter(); processWithEPTemplates(epPolicyTemplate); } }
private void processAddedTerminationPoints(final DataTreeModification<FlowCapableNodeConnector> modification) { final InstanceIdentifier<FlowCapableNodeConnector> iiToNodeInInventory = modification.getRootPath().getRootIdentifier(); TpId terminationPointIdInTopology = provideTopologyTerminationPointId(iiToNodeInInventory); if (terminationPointIdInTopology != null) { InstanceIdentifier<TerminationPoint> iiToTopologyTerminationPoint = provideIIToTopologyTerminationPoint( terminationPointIdInTopology, iiToNodeInInventory); TerminationPoint point = prepareTopologyTerminationPoint(terminationPointIdInTopology, iiToNodeInInventory); sendToTransactionChain(point, iiToTopologyTerminationPoint); removeLinks(modification.getRootNode().getDataAfter(), point); } else { LOG.debug("Inventory node connector key is null. Data can't be written to topology termination point"); } }
@Override public void onDataTreeChanged(@Nonnull final Collection<DataTreeModification<FlowCapableNode>> modifications) { for (DataTreeModification modification : modifications) { if (modification.getRootNode().getModificationType() == ModificationType.WRITE) { AddFlowInputBuilder addFlowInput = new AddFlowInputBuilder(createFlow()); addFlowInput.setNode(new NodeRef(modification.getRootPath().getRootIdentifier().firstIdentifierOf(Node.class))); this.flowService.addFlow(addFlowInput.build()); } } }
@Override public void onDataTreeChanged(@Nonnull final Collection<DataTreeModification<FlowCapableNode>> modifications) { for (DataTreeModification modification : modifications) { if (modification.getRootNode().getModificationType() == ModificationType.WRITE) { SetConfigInputBuilder setConfigInputBuilder = new SetConfigInputBuilder(); setConfigInputBuilder.setFlag(SwitchConfigFlag.FRAGNORMAL.toString()); setConfigInputBuilder.setMissSearchLength(OFConstants.OFPCML_NO_BUFFER); setConfigInputBuilder.setNode(new NodeRef(modification.getRootPath().getRootIdentifier().firstIdentifierOf(Node.class))); nodeConfigService.setConfig(setConfigInputBuilder.build()); } } }