- Bridge bridge = entry.getValue();
- final InstanceIdentifier<Node> nodePath = getKey().toInstanceIndentifier();
- Optional<Node> node = Optional.absent();
- try {
- node = transaction.read(LogicalDatastoreType.OPERATIONAL, nodePath).checkedGet();
- } catch (final ReadFailedException e) {
- LOG.debug("Read Operational/DS for Node fail! {}", nodePath, e);
- }
- if (node.isPresent()) {
- LOG.debug("Node {} is present",node);
- NodeBuilder managedNodeBuilder = new NodeBuilder();
- InstanceIdentifier<Node> managedNodePath = SouthboundMapper.createInstanceIdentifier(getKey(),bridge);
- NodeId manageNodeId = SouthboundMapper.createManagedNodeId(managedNodePath);
- managedNodeBuilder.setNodeId(manageNodeId);
- OvsdbBridgeAugmentationBuilder ovsdbManagedNodeBuilder = new OvsdbBridgeAugmentationBuilder();
- ovsdbManagedNodeBuilder.setBridgeName(new OvsdbBridgeName(bridge.getName()));
- ovsdbManagedNodeBuilder.setBridgeUuid(new Uuid(bridge.getUuid().toString()));
- DatapathId dpid = SouthboundMapper.createDatapathId(bridge);
- if (dpid != null) {
- ovsdbManagedNodeBuilder.setDatapathId(dpid);
+ updateBridge(transaction, entry.getValue());
+ }
+ }
+
+ private void updateBridge(ReadWriteTransaction transaction,
+ Bridge bridge) {
+ final InstanceIdentifier<Node> connectionIId = getOvsdbConnectionInstance().getInstanceIdentifier();
+ Optional<Node> connection = SouthboundUtil.readNode(transaction, connectionIId);
+ if (connection.isPresent()) {
+ LOG.debug("Connection {} is present",connection);
+
+ // Update the connection node to let it know it manages this bridge
+ Node connectionNode = buildConnectionNode(bridge);
+ transaction.merge(LogicalDatastoreType.OPERATIONAL, connectionIId, connectionNode);
+
+ // Update the bridge node with whatever data we are getting
+ InstanceIdentifier<Node> bridgeIid = getInstanceIdentifier(bridge);
+ Node bridgeNode = buildBridgeNode(bridge);
+ transaction.merge(LogicalDatastoreType.OPERATIONAL, bridgeIid, bridgeNode);
+ deleteEntries(transaction, protocolEntriesToRemove(bridgeIid,bridge));
+ deleteEntries(transaction, externalIdsToRemove(bridgeIid,bridge));
+ deleteEntries(transaction, bridgeOtherConfigsToRemove(bridgeIid,bridge));
+ }
+ }
+
+ private <T extends DataObject> void deleteEntries(ReadWriteTransaction transaction,
+ List<InstanceIdentifier<T>> entryIids) {
+ for (InstanceIdentifier<T> entryIid: entryIids) {
+ transaction.delete(LogicalDatastoreType.OPERATIONAL, entryIid);
+ }
+ }
+
+ private List<InstanceIdentifier<BridgeOtherConfigs>> bridgeOtherConfigsToRemove(
+ InstanceIdentifier<Node> bridgeIid, Bridge bridge) {
+ Preconditions.checkNotNull(bridgeIid);
+ Preconditions.checkNotNull(bridge);
+ List<InstanceIdentifier<BridgeOtherConfigs>> result = new ArrayList<>();
+
+ Bridge oldBridge = oldBridgeRows.get(bridge.getUuid());
+
+ if (oldBridge != null && oldBridge.getOtherConfigColumn() != null) {
+ for (Entry<String, String> otherConfig:
+ oldBridge.getOtherConfigColumn().getData().entrySet()) {
+ if (bridge.getOtherConfigColumn() == null
+ || !bridge.getOtherConfigColumn().getData().containsKey(otherConfig.getKey())) {
+ InstanceIdentifier<BridgeOtherConfigs> iid = bridgeIid
+ .augmentation(OvsdbBridgeAugmentation.class)
+ .child(BridgeOtherConfigs.class,
+ new BridgeOtherConfigsKey(otherConfig.getKey()));
+ result.add(iid);