@Test public void testOnWrite() { when(rootNode.getModificationType()).thenReturn(DataObjectModification.ModificationType.WRITE); listener.onDataTreeChanged(changes); verify(writeTx).merge(eq(LogicalDatastoreType.CONFIGURATION), any(InstanceIdentifier.class), any(Node.class), eq(true)); }
@Override protected void onWrite(DataObjectModification<Node> rootNode, InstanceIdentifier<Node> rootIdentifier) { Node node = rootNode.getDataAfter(); OvsdbNodeAugmentation ovsdbNode = node.getAugmentation(OvsdbNodeAugmentation.class); if (ovsdbNode != null) { LOG.trace("OVSDB node created: {} \n {}", rootIdentifier, node); DataObjectModification<OpenvswitchOtherConfigs> ovsOtherConfigModification = getProviderMappingsModification(rootNode); boolean integrationBridgePresent = false; if (isProviderPortNameChanged(ovsOtherConfigModification) && ovsdbNode.getManagedNodeEntry() != null) { String newProviderPortName = getProviderPortName(ovsOtherConfigModification.getDataAfter()); LOG.debug("provider_mappings created {} on node {}", newProviderPortName, node.getNodeId().getValue()); for (ManagedNodeEntry mngdNodeEntry : ovsdbNode.getManagedNodeEntry()) { OvsdbBridgeRef bridgeRef = mngdNodeEntry.getBridgeRef(); providerPortNameByBridgeRef.put(bridgeRef, newProviderPortName); LOG.trace("Added Provider port name {} by OVSDB bridge ref {}", newProviderPortName, mngdNodeEntry.getBridgeRef()); NodeKey managedNodeKey = bridgeRef.getValue().firstKeyOf(Node.class); if (intBrSettings != null && managedNodeKey.getNodeId().getValue() .equals(intBrSettings.getName())) { integrationBridgePresent = true; } } } if (intBrSettings != null && !integrationBridgePresent) { final Node bridge = createBridge(rootIdentifier, managerToControllerEntries(ovsdbNode.getManagerEntry()), intBrSettings.getName()); InstanceIdentifier<Node> bridgeNodeIid = NeutronOvsdbIidFactory.nodeIid( rootIdentifier.firstKeyOf(Topology.class).getTopologyId(), bridge.getNodeId()); WriteTransaction writeTx = dataProvider.newWriteOnlyTransaction(); writeTx.merge(LogicalDatastoreType.CONFIGURATION, bridgeNodeIid, bridge, true); Futures.addCallback(writeTx.submit(), new FutureCallback<Void>() { @Override public void onSuccess(Void result) { LOG.info("Bridge {} written to datastore." + bridge.getNodeId().getValue()); } @Override public void onFailure(Throwable throwable) { LOG.error("Failed to write bridge {}. Message: {}" + bridge.getNodeId().getValue(), throwable.getMessage()); } }, MoreExecutors.directExecutor()); } } OvsdbBridgeAugmentation ovsdbBridge = node.getAugmentation(OvsdbBridgeAugmentation.class); if (ovsdbBridge != null) { LOG.trace("OVSDB bridge created: {} \n {}", rootIdentifier, node); Set<DataObjectModification<OvsdbTerminationPointAugmentation>> ovsdbTpModifications = getOvsdbTpModifications(rootNode); NodeId ofNodeId = buildOfNodeId(ovsdbBridge); if (!ovsdbTpModifications.isEmpty() && ofNodeId != null) { NeutronBridgeWithExtPort bridge = getBridge(rootIdentifier); bridge.ofNodeId = ofNodeId; LOG.trace("OF node {} representing OVSDB bridge {}", ofNodeId.getValue(), node.getNodeId().getValue()); } for (DataObjectModification<OvsdbTerminationPointAugmentation> ovsdbTpModification : ovsdbTpModifications) { OvsdbTerminationPointAugmentation newOvsdbTp = ovsdbTpModification.getDataAfter(); if (ovsdbBridge.getBridgeName().getValue().equals(newOvsdbTp.getName())) { LOG.trace("Termination Point {} same as Bridge {}. Not processing", newOvsdbTp.getName(), ovsdbBridge.getBridgeName().getValue()); continue; } String portName = newOvsdbTp.getName(); Long ofport = newOvsdbTp.getOfport(); if (isOfportOrNameChanged(ovsdbTpModification) && portName != null && ofport != null) { NeutronBridgeWithExtPort bridge = getBridge(rootIdentifier); bridge.ofportByName.put(ofport, portName); LOG.trace("OVSDB termination point with ofport {} and port-name {} created.", ofport, portName); if (portName.equals(providerPortNameByBridgeRef.get(new OvsdbBridgeRef(rootIdentifier)))) { NodeConnectorId ofNcId = buildOfNodeConnectorId(newOvsdbTp, ofNodeId); bridge.externalIfaces.add(ofNcId); InventoryHelper.addOfOverlayExternalPort(bridge.ofNodeId, ofNcId, dataProvider); LOG.debug("Added of-overlay external-interface {} to node {}", ofNcId.getValue(), bridge.ofNodeId); traceBridge(rootIdentifier); } } } } }
OvsdbNodeListener extends DataTreeChangeHandler<Node> { @Override protected void onWrite(DataObjectModification<Node> rootNode, InstanceIdentifier<Node> rootIdentifier) { Node node = rootNode.getDataAfter(); OvsdbNodeAugmentation ovsdbNode = node.getAugmentation(OvsdbNodeAugmentation.class); if (ovsdbNode != null) { LOG.trace("OVSDB node created: {} \n {}", rootIdentifier, node); DataObjectModification<OpenvswitchOtherConfigs> ovsOtherConfigModification = getProviderMappingsModification(rootNode); boolean integrationBridgePresent = false; if (isProviderPortNameChanged(ovsOtherConfigModification) && ovsdbNode.getManagedNodeEntry() != null) { String newProviderPortName = getProviderPortName(ovsOtherConfigModification.getDataAfter()); LOG.debug("provider_mappings created {} on node {}", newProviderPortName, node.getNodeId().getValue()); for (ManagedNodeEntry mngdNodeEntry : ovsdbNode.getManagedNodeEntry()) { OvsdbBridgeRef bridgeRef = mngdNodeEntry.getBridgeRef(); providerPortNameByBridgeRef.put(bridgeRef, newProviderPortName); LOG.trace("Added Provider port name {} by OVSDB bridge ref {}", newProviderPortName, mngdNodeEntry.getBridgeRef()); NodeKey managedNodeKey = bridgeRef.getValue().firstKeyOf(Node.class); if (intBrSettings != null && managedNodeKey.getNodeId().getValue() .equals(intBrSettings.getName())) { integrationBridgePresent = true; } } } if (intBrSettings != null && !integrationBridgePresent) { final Node bridge = createBridge(rootIdentifier, managerToControllerEntries(ovsdbNode.getManagerEntry()), intBrSettings.getName()); InstanceIdentifier<Node> bridgeNodeIid = NeutronOvsdbIidFactory.nodeIid( rootIdentifier.firstKeyOf(Topology.class).getTopologyId(), bridge.getNodeId()); WriteTransaction writeTx = dataProvider.newWriteOnlyTransaction(); writeTx.merge(LogicalDatastoreType.CONFIGURATION, bridgeNodeIid, bridge, true); Futures.addCallback(writeTx.submit(), new FutureCallback<Void>() { @Override public void onSuccess(Void result) { LOG.info("Bridge {} written to datastore." + bridge.getNodeId().getValue()); } @Override public void onFailure(Throwable throwable) { LOG.error("Failed to write bridge {}. Message: {}" + bridge.getNodeId().getValue(), throwable.getMessage()); } }, MoreExecutors.directExecutor()); } } OvsdbBridgeAugmentation ovsdbBridge = node.getAugmentation(OvsdbBridgeAugmentation.class); if (ovsdbBridge != null) { LOG.trace("OVSDB bridge created: {} \n {}", rootIdentifier, node); Set<DataObjectModification<OvsdbTerminationPointAugmentation>> ovsdbTpModifications = getOvsdbTpModifications(rootNode); NodeId ofNodeId = buildOfNodeId(ovsdbBridge); if (!ovsdbTpModifications.isEmpty() && ofNodeId != null) { NeutronBridgeWithExtPort bridge = getBridge(rootIdentifier); bridge.ofNodeId = ofNodeId; LOG.trace("OF node {} representing OVSDB bridge {}", ofNodeId.getValue(), node.getNodeId().getValue()); } for (DataObjectModification<OvsdbTerminationPointAugmentation> ovsdbTpModification : ovsdbTpModifications) { OvsdbTerminationPointAugmentation newOvsdbTp = ovsdbTpModification.getDataAfter(); if (ovsdbBridge.getBridgeName().getValue().equals(newOvsdbTp.getName())) { LOG.trace("Termination Point {} same as Bridge {}. Not processing", newOvsdbTp.getName(), ovsdbBridge.getBridgeName().getValue()); continue; } String portName = newOvsdbTp.getName(); Long ofport = newOvsdbTp.getOfport(); if (isOfportOrNameChanged(ovsdbTpModification) && portName != null && ofport != null) { NeutronBridgeWithExtPort bridge = getBridge(rootIdentifier); bridge.ofportByName.put(ofport, portName); LOG.trace("OVSDB termination point with ofport {} and port-name {} created.", ofport, portName); if (portName.equals(providerPortNameByBridgeRef.get(new OvsdbBridgeRef(rootIdentifier)))) { NodeConnectorId ofNcId = buildOfNodeConnectorId(newOvsdbTp, ofNodeId); bridge.externalIfaces.add(ofNcId); InventoryHelper.addOfOverlayExternalPort(bridge.ofNodeId, ofNcId, dataProvider); LOG.debug("Added of-overlay external-interface {} to node {}", ofNcId.getValue(), bridge.ofNodeId); traceBridge(rootIdentifier); } } } } } }
OvsdbNodeListener extends DataTreeChangeHandler<Node> { @Override protected void onWrite(DataObjectModification<Node> rootNode, InstanceIdentifier<Node> rootIdentifier) { Node node = rootNode.getDataAfter(); OvsdbNodeAugmentation ovsdbNode = node.getAugmentation(OvsdbNodeAugmentation.class); if (ovsdbNode != null) { LOG.trace("OVSDB node created: {} \n {}", rootIdentifier, node); DataObjectModification<OpenvswitchOtherConfigs> ovsOtherConfigModification = getProviderMappingsModification(rootNode); boolean integrationBridgePresent = false; if (isProviderPortNameChanged(ovsOtherConfigModification) && ovsdbNode.getManagedNodeEntry() != null) { String newProviderPortName = getProviderPortName(ovsOtherConfigModification.getDataAfter()); LOG.debug("provider_mappings created {} on node {}", newProviderPortName, node.getNodeId().getValue()); for (ManagedNodeEntry mngdNodeEntry : ovsdbNode.getManagedNodeEntry()) { OvsdbBridgeRef bridgeRef = mngdNodeEntry.getBridgeRef(); providerPortNameByBridgeRef.put(bridgeRef, newProviderPortName); LOG.trace("Added Provider port name {} by OVSDB bridge ref {}", newProviderPortName, mngdNodeEntry.getBridgeRef()); NodeKey managedNodeKey = bridgeRef.getValue().firstKeyOf(Node.class); if (intBrSettings != null && managedNodeKey.getNodeId().getValue() .equals(intBrSettings.getName())) { integrationBridgePresent = true; } } } if (intBrSettings != null && !integrationBridgePresent) { final Node bridge = createBridge(rootIdentifier, managerToControllerEntries(ovsdbNode.getManagerEntry()), intBrSettings.getName()); InstanceIdentifier<Node> bridgeNodeIid = NeutronOvsdbIidFactory.nodeIid( rootIdentifier.firstKeyOf(Topology.class).getTopologyId(), bridge.getNodeId()); WriteTransaction writeTx = dataProvider.newWriteOnlyTransaction(); writeTx.merge(LogicalDatastoreType.CONFIGURATION, bridgeNodeIid, bridge, true); Futures.addCallback(writeTx.submit(), new FutureCallback<Void>() { @Override public void onSuccess(Void result) { LOG.info("Bridge {} written to datastore." + bridge.getNodeId().getValue()); } @Override public void onFailure(Throwable throwable) { LOG.error("Failed to write bridge {}. Message: {}" + bridge.getNodeId().getValue(), throwable.getMessage()); } }, MoreExecutors.directExecutor()); } } OvsdbBridgeAugmentation ovsdbBridge = node.getAugmentation(OvsdbBridgeAugmentation.class); if (ovsdbBridge != null) { LOG.trace("OVSDB bridge created: {} \n {}", rootIdentifier, node); Set<DataObjectModification<OvsdbTerminationPointAugmentation>> ovsdbTpModifications = getOvsdbTpModifications(rootNode); NodeId ofNodeId = buildOfNodeId(ovsdbBridge); if (!ovsdbTpModifications.isEmpty() && ofNodeId != null) { NeutronBridgeWithExtPort bridge = getBridge(rootIdentifier); bridge.ofNodeId = ofNodeId; LOG.trace("OF node {} representing OVSDB bridge {}", ofNodeId.getValue(), node.getNodeId().getValue()); } for (DataObjectModification<OvsdbTerminationPointAugmentation> ovsdbTpModification : ovsdbTpModifications) { OvsdbTerminationPointAugmentation newOvsdbTp = ovsdbTpModification.getDataAfter(); if (ovsdbBridge.getBridgeName().getValue().equals(newOvsdbTp.getName())) { LOG.trace("Termination Point {} same as Bridge {}. Not processing", newOvsdbTp.getName(), ovsdbBridge.getBridgeName().getValue()); continue; } String portName = newOvsdbTp.getName(); Long ofport = newOvsdbTp.getOfport(); if (isOfportOrNameChanged(ovsdbTpModification) && portName != null && ofport != null) { NeutronBridgeWithExtPort bridge = getBridge(rootIdentifier); bridge.ofportByName.put(ofport, portName); LOG.trace("OVSDB termination point with ofport {} and port-name {} created.", ofport, portName); if (portName.equals(providerPortNameByBridgeRef.get(new OvsdbBridgeRef(rootIdentifier)))) { NodeConnectorId ofNcId = buildOfNodeConnectorId(newOvsdbTp, ofNodeId); bridge.externalIfaces.add(ofNcId); InventoryHelper.addOfOverlayExternalPort(bridge.ofNodeId, ofNcId, dataProvider); LOG.debug("Added of-overlay external-interface {} to node {}", ofNcId.getValue(), bridge.ofNodeId); traceBridge(rootIdentifier); } } } } } OvsdbNodeListener(DataBroker dataProvider, IntegrationBridgeSetting brSettings); }
OvsdbNodeListener extends DataTreeChangeHandler<Node> { @Override protected void onWrite(DataObjectModification<Node> rootNode, InstanceIdentifier<Node> rootIdentifier) { Node node = rootNode.getDataAfter(); OvsdbNodeAugmentation ovsdbNode = node.getAugmentation(OvsdbNodeAugmentation.class); if (ovsdbNode != null) { LOG.trace("OVSDB node created: {} \n {}", rootIdentifier, node); DataObjectModification<OpenvswitchOtherConfigs> ovsOtherConfigModification = getProviderMappingsModification(rootNode); boolean integrationBridgePresent = false; if (isProviderPortNameChanged(ovsOtherConfigModification) && ovsdbNode.getManagedNodeEntry() != null) { String newProviderPortName = getProviderPortName(ovsOtherConfigModification.getDataAfter()); LOG.debug("provider_mappings created {} on node {}", newProviderPortName, node.getNodeId().getValue()); for (ManagedNodeEntry mngdNodeEntry : ovsdbNode.getManagedNodeEntry()) { OvsdbBridgeRef bridgeRef = mngdNodeEntry.getBridgeRef(); providerPortNameByBridgeRef.put(bridgeRef, newProviderPortName); LOG.trace("Added Provider port name {} by OVSDB bridge ref {}", newProviderPortName, mngdNodeEntry.getBridgeRef()); NodeKey managedNodeKey = bridgeRef.getValue().firstKeyOf(Node.class); if (intBrSettings != null && managedNodeKey.getNodeId().getValue() .equals(intBrSettings.getName())) { integrationBridgePresent = true; } } } if (intBrSettings != null && !integrationBridgePresent) { final Node bridge = createBridge(rootIdentifier, managerToControllerEntries(ovsdbNode.getManagerEntry()), intBrSettings.getName()); InstanceIdentifier<Node> bridgeNodeIid = NeutronOvsdbIidFactory.nodeIid( rootIdentifier.firstKeyOf(Topology.class).getTopologyId(), bridge.getNodeId()); WriteTransaction writeTx = dataProvider.newWriteOnlyTransaction(); writeTx.merge(LogicalDatastoreType.CONFIGURATION, bridgeNodeIid, bridge, true); Futures.addCallback(writeTx.submit(), new FutureCallback<Void>() { @Override public void onSuccess(Void result) { LOG.info("Bridge {} written to datastore." + bridge.getNodeId().getValue()); } @Override public void onFailure(Throwable throwable) { LOG.error("Failed to write bridge {}. Message: {}" + bridge.getNodeId().getValue(), throwable.getMessage()); } }, MoreExecutors.directExecutor()); } } OvsdbBridgeAugmentation ovsdbBridge = node.getAugmentation(OvsdbBridgeAugmentation.class); if (ovsdbBridge != null) { LOG.trace("OVSDB bridge created: {} \n {}", rootIdentifier, node); Set<DataObjectModification<OvsdbTerminationPointAugmentation>> ovsdbTpModifications = getOvsdbTpModifications(rootNode); NodeId ofNodeId = buildOfNodeId(ovsdbBridge); if (!ovsdbTpModifications.isEmpty() && ofNodeId != null) { NeutronBridgeWithExtPort bridge = getBridge(rootIdentifier); bridge.ofNodeId = ofNodeId; LOG.trace("OF node {} representing OVSDB bridge {}", ofNodeId.getValue(), node.getNodeId().getValue()); } for (DataObjectModification<OvsdbTerminationPointAugmentation> ovsdbTpModification : ovsdbTpModifications) { OvsdbTerminationPointAugmentation newOvsdbTp = ovsdbTpModification.getDataAfter(); if (ovsdbBridge.getBridgeName().getValue().equals(newOvsdbTp.getName())) { LOG.trace("Termination Point {} same as Bridge {}. Not processing", newOvsdbTp.getName(), ovsdbBridge.getBridgeName().getValue()); continue; } String portName = newOvsdbTp.getName(); Long ofport = newOvsdbTp.getOfport(); if (isOfportOrNameChanged(ovsdbTpModification) && portName != null && ofport != null) { NeutronBridgeWithExtPort bridge = getBridge(rootIdentifier); bridge.ofportByName.put(ofport, portName); LOG.trace("OVSDB termination point with ofport {} and port-name {} created.", ofport, portName); if (portName.equals(providerPortNameByBridgeRef.get(new OvsdbBridgeRef(rootIdentifier)))) { NodeConnectorId ofNcId = buildOfNodeConnectorId(newOvsdbTp, ofNodeId); bridge.externalIfaces.add(ofNcId); InventoryHelper.addOfOverlayExternalPort(bridge.ofNodeId, ofNcId, dataProvider); LOG.debug("Added of-overlay external-interface {} to node {}", ofNcId.getValue(), bridge.ofNodeId); traceBridge(rootIdentifier); } } } } } OvsdbNodeListener(DataBroker dataProvider, IntegrationBridgeSetting brSettings);  }
OvsdbNodeListener extends DataTreeChangeHandler<Node> { @Override protected void onWrite(DataObjectModification<Node> rootNode, InstanceIdentifier<Node> rootIdentifier) { Node node = rootNode.getDataAfter(); OvsdbNodeAugmentation ovsdbNode = node.getAugmentation(OvsdbNodeAugmentation.class); if (ovsdbNode != null) { LOG.trace("OVSDB node created: {} \n {}", rootIdentifier, node); DataObjectModification<OpenvswitchOtherConfigs> ovsOtherConfigModification = getProviderMappingsModification(rootNode); boolean integrationBridgePresent = false; if (isProviderPortNameChanged(ovsOtherConfigModification) && ovsdbNode.getManagedNodeEntry() != null) { String newProviderPortName = getProviderPortName(ovsOtherConfigModification.getDataAfter()); LOG.debug("provider_mappings created {} on node {}", newProviderPortName, node.getNodeId().getValue()); for (ManagedNodeEntry mngdNodeEntry : ovsdbNode.getManagedNodeEntry()) { OvsdbBridgeRef bridgeRef = mngdNodeEntry.getBridgeRef(); providerPortNameByBridgeRef.put(bridgeRef, newProviderPortName); LOG.trace("Added Provider port name {} by OVSDB bridge ref {}", newProviderPortName, mngdNodeEntry.getBridgeRef()); NodeKey managedNodeKey = bridgeRef.getValue().firstKeyOf(Node.class); if (intBrSettings != null && managedNodeKey.getNodeId().getValue() .equals(intBrSettings.getName())) { integrationBridgePresent = true; } } } if (intBrSettings != null && !integrationBridgePresent) { final Node bridge = createBridge(rootIdentifier, managerToControllerEntries(ovsdbNode.getManagerEntry()), intBrSettings.getName()); InstanceIdentifier<Node> bridgeNodeIid = NeutronOvsdbIidFactory.nodeIid( rootIdentifier.firstKeyOf(Topology.class).getTopologyId(), bridge.getNodeId()); WriteTransaction writeTx = dataProvider.newWriteOnlyTransaction(); writeTx.merge(LogicalDatastoreType.CONFIGURATION, bridgeNodeIid, bridge, true); Futures.addCallback(writeTx.submit(), new FutureCallback<Void>() { @Override public void onSuccess(Void result) { LOG.info("Bridge {} written to datastore." + bridge.getNodeId().getValue()); } @Override public void onFailure(Throwable throwable) { LOG.error("Failed to write bridge {}. Message: {}" + bridge.getNodeId().getValue(), throwable.getMessage()); } }, MoreExecutors.directExecutor()); } } OvsdbBridgeAugmentation ovsdbBridge = node.getAugmentation(OvsdbBridgeAugmentation.class); if (ovsdbBridge != null) { LOG.trace("OVSDB bridge created: {} \n {}", rootIdentifier, node); Set<DataObjectModification<OvsdbTerminationPointAugmentation>> ovsdbTpModifications = getOvsdbTpModifications(rootNode); NodeId ofNodeId = buildOfNodeId(ovsdbBridge); if (!ovsdbTpModifications.isEmpty() && ofNodeId != null) { NeutronBridgeWithExtPort bridge = getBridge(rootIdentifier); bridge.ofNodeId = ofNodeId; LOG.trace("OF node {} representing OVSDB bridge {}", ofNodeId.getValue(), node.getNodeId().getValue()); } for (DataObjectModification<OvsdbTerminationPointAugmentation> ovsdbTpModification : ovsdbTpModifications) { OvsdbTerminationPointAugmentation newOvsdbTp = ovsdbTpModification.getDataAfter(); if (ovsdbBridge.getBridgeName().getValue().equals(newOvsdbTp.getName())) { LOG.trace("Termination Point {} same as Bridge {}. Not processing", newOvsdbTp.getName(), ovsdbBridge.getBridgeName().getValue()); continue; } String portName = newOvsdbTp.getName(); Long ofport = newOvsdbTp.getOfport(); if (isOfportOrNameChanged(ovsdbTpModification) && portName != null && ofport != null) { NeutronBridgeWithExtPort bridge = getBridge(rootIdentifier); bridge.ofportByName.put(ofport, portName); LOG.trace("OVSDB termination point with ofport {} and port-name {} created.", ofport, portName); if (portName.equals(providerPortNameByBridgeRef.get(new OvsdbBridgeRef(rootIdentifier)))) { NodeConnectorId ofNcId = buildOfNodeConnectorId(newOvsdbTp, ofNodeId); bridge.externalIfaces.add(ofNcId); InventoryHelper.addOfOverlayExternalPort(bridge.ofNodeId, ofNcId, dataProvider); LOG.debug("Added of-overlay external-interface {} to node {}", ofNcId.getValue(), bridge.ofNodeId); traceBridge(rootIdentifier); } } } } } OvsdbNodeListener(DataBroker dataProvider, IntegrationBridgeSetting brSettings);   }