bug-6326 Modify config, not operational version 79/42979/3
authorJosh <jhershbe@redhat.com>
Tue, 2 Aug 2016 15:15:31 +0000 (17:15 +0200)
committerJosh <jhershbe@redhat.com>
Tue, 2 Aug 2016 15:45:30 +0000 (17:45 +0200)
pull bridge from config before modifying
+ only write controllers that don't already exist

Change-Id: I6f6d2a9fa33459988da8450065714ec86eab5781
Signed-off-by: Josh <jhershbe@redhat.com>
utils/southbound-utils/src/main/java/org/opendaylight/ovsdb/utils/southbound/utils/SouthboundUtils.java

index ac470e0030cf260042cf7219b539c2abd36f7c0f..d39e23d513eb209dc20a2eaadc824364f56a9fd7 100644 (file)
@@ -581,22 +581,50 @@ public class SouthboundUtils {
     /**
      * Set the controllers of an existing bridge node
      * @param ovsdbNode where the bridge is
-     * @param bridgeNode The bridge node itself
      * @param bridgeName Name of the bridge
      * @param controllers controller strings
      * @return success if the write to md-sal was successful
      */
-    public boolean setBridgeController(Node ovsdbNode, Node bridgeNode, String bridgeName, List<String> controllers) {
+    public boolean setBridgeController(Node ovsdbNode, String bridgeName, List<String> controllers) {
         LOG.debug("setBridgeController: ovsdbNode: {}, bridgeNode: {}, controller(s): {}",
-                ovsdbNode, bridgeNode, controllers);
+                ovsdbNode, bridgeName, controllers);
+
+        InstanceIdentifier<Node> bridgeNodeIid = createInstanceIdentifier(ovsdbNode.getKey(), bridgeName);
+        Node bridgeNode = mdsalUtils.read(LogicalDatastoreType.CONFIGURATION, bridgeNodeIid);
+        if (bridgeNode == null) {
+            LOG.info("setBridgeController could not find bridge in configuration {}", bridgeNodeIid);
+            return false;
+        }
 
         OvsdbBridgeAugmentation bridgeAug = extractBridgeAugmentation(bridgeNode);
+
+        //Only add controller entries that do not already exist on this bridge
+        List<ControllerEntry> existingControllerEntries = bridgeAug.getControllerEntry();
+        List<ControllerEntry> newControllerEntries = new ArrayList<>();
+        if(existingControllerEntries != null) {
+            NEW_ENTRY_LOOP:
+            for (ControllerEntry newEntry : createControllerEntries(controllers)) {
+                for (ControllerEntry existingEntry : existingControllerEntries) {
+                    if (newEntry.getTarget().equals(existingEntry.getTarget())) {
+                        continue NEW_ENTRY_LOOP;
+                    }
+                }
+                newControllerEntries.add(newEntry);
+            }
+        } else {
+            newControllerEntries = createControllerEntries(controllers);
+        }
+
+        if(newControllerEntries.isEmpty()) {
+            return true;
+        }
+
         NodeBuilder nodeBuilder = new NodeBuilder(bridgeNode);
         OvsdbBridgeAugmentationBuilder augBuilder = new OvsdbBridgeAugmentationBuilder(bridgeAug);
-        augBuilder.setControllerEntry(createControllerEntries(controllers));
+
+        augBuilder.setControllerEntry(newControllerEntries);
         nodeBuilder.addAugmentation(OvsdbBridgeAugmentation.class, augBuilder.build());
         InstanceIdentifier<Node> bridgeIid = createInstanceIdentifier(ovsdbNode.getKey(), bridgeName);
-
         return mdsalUtils.merge(LogicalDatastoreType.CONFIGURATION, bridgeIid, nodeBuilder.build());
     }