X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;ds=sidebyside;f=opendaylight%2Fprotocol_plugins%2Fopenflow%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fprotocol_plugin%2Fopenflow%2Finternal%2FInventoryService.java;h=9fded15f42383a1edceb436f5c8b010909a6e03b;hb=850d5b748e96c2667bb95ce423bdb00083838619;hp=ec6ea1223e71f6103fcfef6aecb655c1108e6179;hpb=0cfc417107d5b5b1bafdd7ee1fe8e3ba052d5488;p=controller.git diff --git a/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/InventoryService.java b/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/InventoryService.java index ec6ea1223e..9fded15f42 100644 --- a/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/InventoryService.java +++ b/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/InventoryService.java @@ -8,8 +8,6 @@ package org.opendaylight.controller.protocol_plugin.openflow.internal; -import java.util.Collections; -import java.util.Date; import java.util.Dictionary; import java.util.HashMap; import java.util.HashSet; @@ -17,15 +15,15 @@ import java.util.Map; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; +import java.util.concurrent.CopyOnWriteArraySet; import org.apache.felix.dm.Component; import org.opendaylight.controller.protocol_plugin.openflow.IInventoryProvider; import org.opendaylight.controller.protocol_plugin.openflow.IInventoryShimInternalListener; import org.opendaylight.controller.protocol_plugin.openflow.core.IController; import org.opendaylight.controller.protocol_plugin.openflow.core.ISwitch; -import org.opendaylight.controller.sal.core.ConstructionException; +import org.opendaylight.controller.sal.connection.IPluginOutConnectionService; import org.opendaylight.controller.sal.core.Node; -import org.opendaylight.controller.sal.core.Node.NodeIDType; import org.opendaylight.controller.sal.core.NodeConnector; import org.opendaylight.controller.sal.core.Property; import org.opendaylight.controller.sal.core.UpdateType; @@ -47,12 +45,12 @@ public class InventoryService implements IInventoryShimInternalListener, IPluginInInventoryService, IInventoryProvider { protected static final Logger logger = LoggerFactory .getLogger(InventoryService.class); - private Set pluginOutInventoryServices = Collections - .synchronizedSet(new HashSet()); + private Set pluginOutInventoryServices; private IController controller = null; private ConcurrentMap> nodeProps; // properties are maintained in global container only private ConcurrentMap> nodeConnectorProps; // properties are maintained in global container only private boolean isDefaultContainer = false; + private String containerName = null; void setController(IController s) { this.controller = s; @@ -75,13 +73,16 @@ public class InventoryService implements IInventoryShimInternalListener, Dictionary props = c.getServiceProperties(); if (props != null) { - String containerName = (String) props.get("containerName"); - isDefaultContainer = containerName.equals(GlobalConstants.DEFAULT - .toString()); + containerName = (String) props.get("containerName"); + if (containerName != null) { + isDefaultContainer = containerName.equals(GlobalConstants.DEFAULT + .toString()); + } } nodeProps = new ConcurrentHashMap>(); nodeConnectorProps = new ConcurrentHashMap>(); + pluginOutInventoryServices = new CopyOnWriteArraySet(); } /** @@ -128,24 +129,12 @@ public class InventoryService implements IInventoryShimInternalListener, } } - protected Node OFSwitchToNode(ISwitch sw) { - Node node = null; - Object id = sw.getId(); - - try { - node = new Node(NodeIDType.OPENFLOW, id); - } catch (ConstructionException e) { - logger.error("", e); - } - - return node; - } - /** * Retrieve nodes from openflow */ @Override public ConcurrentMap> getNodeProps() { + logger.debug("getNodePros for container {}", containerName); return nodeProps; } @@ -204,31 +193,36 @@ public class InventoryService implements IInventoryShimInternalListener, } // update sal and discovery - synchronized (pluginOutInventoryServices) { - for (IPluginOutInventoryService service : pluginOutInventoryServices) { - service.updateNodeConnector(nodeConnector, type, props); - } + for (IPluginOutInventoryService service : pluginOutInventoryServices) { + service.updateNodeConnector(nodeConnector, type, props); } + } private void addNode(Node node, Set props) { - logger.trace("{} added, props: {}", node, props); if (nodeProps == null) { return; } + logger.trace("addNode: {} added, props: {} for container {}", + new Object[] { node, props, containerName }); + // update local cache - Map propMap = new HashMap(); - for (Property prop : props) { - propMap.put(prop.getName(), prop); + Map propMap = nodeProps.get(node); + if (propMap == null) { + propMap = new HashMap(); + } + + if (props != null) { + for (Property prop : props) { + propMap.put(prop.getName(), prop); + } } nodeProps.put(node, propMap); // update sal - synchronized (pluginOutInventoryServices) { - for (IPluginOutInventoryService service : pluginOutInventoryServices) { - service.updateNode(node, UpdateType.ADDED, props); - } + for (IPluginOutInventoryService service : pluginOutInventoryServices) { + service.updateNode(node, UpdateType.ADDED, props); } } @@ -251,10 +245,8 @@ public class InventoryService implements IInventoryShimInternalListener, } // update sal - synchronized (pluginOutInventoryServices) { - for (IPluginOutInventoryService service : pluginOutInventoryServices) { - service.updateNode(node, UpdateType.REMOVED, null); - } + for (IPluginOutInventoryService service : pluginOutInventoryServices) { + service.updateNode(node, UpdateType.REMOVED, null); } } @@ -279,10 +271,8 @@ public class InventoryService implements IInventoryShimInternalListener, // Update SAL if we got new properties if (!newProperties.isEmpty()) { - synchronized (pluginOutInventoryServices) { - for (IPluginOutInventoryService service : pluginOutInventoryServices) { - service.updateNode(node, UpdateType.CHANGED, newProperties); - } + for (IPluginOutInventoryService service : pluginOutInventoryServices) { + service.updateNode(node, UpdateType.CHANGED, newProperties); } } } @@ -303,5 +293,4 @@ public class InventoryService implements IInventoryShimInternalListener, break; } } - }