Fix bulk sync in SwitchMananger.
[controller.git] / opendaylight / protocol_plugins / openflow / src / main / java / org / opendaylight / controller / protocol_plugin / openflow / internal / InventoryService.java
index ec6ea1223e71f6103fcfef6aecb655c1108e6179..4869a9500b489ca58c1eaf72359fb8aaeb72cd12 100644 (file)
@@ -53,6 +53,7 @@ public class InventoryService implements IInventoryShimInternalListener,
     private ConcurrentMap<Node, Map<String, Property>> nodeProps; // properties are maintained in global container only
     private ConcurrentMap<NodeConnector, Map<String, Property>> nodeConnectorProps; // properties are maintained in global container only
     private boolean isDefaultContainer = false;
+    private String containerName = null;
 
     void setController(IController s) {
         this.controller = s;
@@ -75,7 +76,7 @@ public class InventoryService implements IInventoryShimInternalListener,
 
         Dictionary props = c.getServiceProperties();
         if (props != null) {
-            String containerName = (String) props.get("containerName");
+            containerName = (String) props.get("containerName");
             isDefaultContainer = containerName.equals(GlobalConstants.DEFAULT
                     .toString());
         }
@@ -146,6 +147,7 @@ public class InventoryService implements IInventoryShimInternalListener,
      */
     @Override
     public ConcurrentMap<Node, Map<String, Property>> getNodeProps() {
+        logger.debug("getNodePros for container {}", containerName);
         return nodeProps;
     }
 
@@ -212,15 +214,30 @@ public class InventoryService implements IInventoryShimInternalListener,
     }
 
     private void addNode(Node node, Set<Property> props) {
-        logger.trace("{} added, props: {}", node, props);
         if (nodeProps == null) {
             return;
         }
 
+        Set<Node> nodeSet = nodeProps.keySet();
+        if (((props == null) || props.isEmpty()) && (nodeSet != null)
+                && nodeSet.contains(node)) {
+            // node already added
+            return;
+        }
+
+        logger.trace("addNode: {} added, props: {} for container {}",
+                new Object[] { node, props, containerName });
+
         // update local cache
-        Map<String, Property> propMap = new HashMap<String, Property>();
-        for (Property prop : props) {
-            propMap.put(prop.getName(), prop);
+        Map<String, Property> propMap = nodeProps.get(node);
+        if (propMap == null) {
+            propMap = new HashMap<String, Property>();
+        }
+
+        if (props != null) {
+            for (Property prop : props) {
+                propMap.put(prop.getName(), prop);
+            }
         }
         nodeProps.put(node, propMap);