Merge "Separate UserManager into api and implementation bundles"
authorGiovanni Meo <gmeo@cisco.com>
Fri, 14 Jun 2013 10:19:04 +0000 (10:19 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Fri, 14 Jun 2013 10:19:04 +0000 (10:19 +0000)
opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/InventoryService.java
opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/InventoryServiceShim.java
opendaylight/switchmanager/implementation/src/main/java/org/opendaylight/controller/switchmanager/internal/SwitchManagerImpl.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);
 
index f7210a333bd870d87216128b73cffb8a8402842f..e2d77b5b73f1b1c3c73da363b2f40949319c0a0a 100644 (file)
@@ -236,6 +236,8 @@ public class InventoryServiceShim implements IContainerListener,
     @Override
     public void tagUpdated(String containerName, Node n, short oldTag,
             short newTag, UpdateType t) {
+        logger.debug("tagUpdated: {} type {} for container {}", new Object[] {
+                n, t, containerName });
     }
 
     @Override
@@ -246,6 +248,8 @@ public class InventoryServiceShim implements IContainerListener,
     @Override
     public void nodeConnectorUpdated(String containerName, NodeConnector p,
             UpdateType t) {
+        logger.debug("nodeConnectorUpdated: {} type {} for container {}",
+                new Object[] { p, t, containerName });
         if (this.containerMap == null) {
             logger.error("containerMap is NULL");
             return;
@@ -283,6 +287,7 @@ public class InventoryServiceShim implements IContainerListener,
 
         // notify InventoryService
         notifyInventoryShimInternalListener(containerName, p, t, null);
+        notifyInventoryShimInternalListener(containerName, p.getNode(), t, null);
     }
 
     private void notifyInventoryShimExternalListener(Node node,
@@ -308,7 +313,7 @@ public class InventoryServiceShim implements IContainerListener,
                     type, props);
             logger.trace(
                     "notifyInventoryShimInternalListener {} type {} for container {}",
-                    nodeConnector, type, container);
+                    new Object[] { nodeConnector, type, container });
         }
     }
 
@@ -373,6 +378,18 @@ public class InventoryServiceShim implements IContainerListener,
         notifyInventoryShimExternalListener(node, type, props);
     }
 
+    private void notifyInventoryShimInternalListener(String container,
+            Node node, UpdateType type, Set<Property> props) {
+        IInventoryShimInternalListener inventoryShimInternalListener = inventoryShimInternalListeners
+                .get(container);
+        if (inventoryShimInternalListener != null) {
+            inventoryShimInternalListener.updateNode(node, type, props);
+            logger.trace(
+                    "notifyInventoryShimInternalListener {} type {} for container {}",
+                    new Object[] { node, type, container });
+        }
+    }
+
     private void addNode(ISwitch sw) {
         Node node;
         try {
index 971213e483e567b4d4a6d0336ee613b85ceb25a8..443c7a42ab7da517fbb8df65082c36d1a220a79e 100644 (file)
@@ -820,6 +820,8 @@ CommandProvider {
 
     @Override
     public void updateNode(Node node, UpdateType type, Set<Property> props) {
+        log.debug("updateNode: {} type {} props {} for container {}",
+                new Object[] { node, type, props, containerName });
         switch (type) {
         case ADDED:
             addNode(node, props);
@@ -841,7 +843,8 @@ CommandProvider {
         Node node = nodeConnector.getNode();
         Map<String, Property> propMap = new HashMap<String, Property>();
 
-        log.trace("{} {}", nodeConnector, type);
+        log.debug("updateNodeConnector: {} type {} props {} for container {}",
+                new Object[] { nodeConnector, type, props, containerName });
 
         if (nodeConnectorProps == null) {
             return;
@@ -1335,6 +1338,8 @@ CommandProvider {
         Set<Node> nodeSet = nodeProps.keySet();
         if (nodeSet != null) {
             for (Node node : nodeSet) {
+                log.debug("getInventories: {} added for container {}",
+                        new Object[] { node, containerName });
                 addNode(node, null);
             }
         }
@@ -1384,17 +1389,17 @@ CommandProvider {
     }
 
     private void bulkUpdateService(IInventoryListener service) {
+        Map<String, Property> propMap;
+        UpdateType type = UpdateType.ADDED;
+
         for (Node node : getNodes()) {
-            service.notifyNode(node, UpdateType.ADDED, null);
+            propMap = nodeProps.get(node);
+            service.notifyNode(node, type, propMap);
         }
 
-        Map<String, Property> propMap = new HashMap<String, Property>();
-        propMap.put(State.StatePropName, new State(State.EDGE_UP));
         for (NodeConnector nodeConnector : nodeConnectorProps.keySet()) {
-            if (isNodeConnectorEnabled(nodeConnector)) {
-                service.notifyNodeConnector(nodeConnector, UpdateType.ADDED,
-                        propMap);
-            }
+            propMap = nodeConnectorProps.get(nodeConnector);
+            service.notifyNodeConnector(nodeConnector, type, propMap);
         }
     }