Implement NodeCacheListener to SouthboundHandler 87/16787/2
authorSam Hague <shague@redhat.com>
Wed, 18 Mar 2015 18:56:44 +0000 (14:56 -0400)
committerSam Hague <shague@redhat.com>
Wed, 18 Mar 2015 19:26:34 +0000 (19:26 +0000)
- implemented the NodeCacheLister for SouthboundHandler
- changed FlowCapableNodeDataChangeListener to use the NodeCacheManager
- modified Activator to include the interface
- moved the low frequency logs to info level, moved high-frequency to trace

Change-Id: Ie1c2a17a8e6020bbb475cf2cdbdd149862f96a2d
Signed-off-by: Sam Hague <shague@redhat.com>
openstack/net-virt-providers/src/main/java/org/opendaylight/ovsdb/openstack/netvirt/providers/openflow13/FlowCapableNodeDataChangeListener.java
openstack/net-virt/src/main/java/org/opendaylight/ovsdb/openstack/netvirt/Activator.java
openstack/net-virt/src/main/java/org/opendaylight/ovsdb/openstack/netvirt/SouthboundHandler.java

index 6efd26e99465f98daaa8cb0bae157d2927c6e035..878a0f29f87fde28dae5145acf1b9010c9b10365 100644 (file)
@@ -49,7 +49,7 @@ public class FlowCapableNodeDataChangeListener implements DataChangeListener, Au
 
     public FlowCapableNodeDataChangeListener (DataBroker dataBroker) {
         LOG.info("Registering FlowCapableNodeChangeListener");
-        registration = dataBroker.registerDataChangeListener(LogicalDatastoreType.OPERATIONAL,
+        registration = dataBroker.registerDataChangeListener(LogicalDatastoreType.CONFIGURATION,
                 createFlowCapableNodePath(), this, AsyncDataBroker.DataChangeScope.ONE);
     }
 
@@ -60,9 +60,8 @@ public class FlowCapableNodeDataChangeListener implements DataChangeListener, Au
 
     @Override
     public void onDataChanged (AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> changes) {
-        checkMemberInitialization();
-
         LOG.debug(">>>> onDataChanged: {}", changes);
+        checkMemberInitialization();
 
         for (InstanceIdentifier instanceIdentifier : changes.getRemovedPaths()) {
             DataObject originalDataObject = changes.getOriginalData().get(instanceIdentifier);
@@ -76,7 +75,7 @@ public class FlowCapableNodeDataChangeListener implements DataChangeListener, Au
         for (Map.Entry<InstanceIdentifier<?>, DataObject> created : changes.getCreatedData().entrySet()) {
             InstanceIdentifier<?> iID = created.getKey();
             String openflowId = iID.firstKeyOf(Node.class, NodeKey.class).getId().getValue();
-            LOG.debug(">>>>> created iiD: {} - first: {} - NodeKey: {}",
+            LOG.info(">>>>> created iiD: {} - first: {} - NodeKey: {}",
                     iID, iID.firstIdentifierOf(Node.class), openflowId);
             Node openFlowNode = NodeUtils.getOpenFlowNode(openflowId);
             if (nodeCache.contains(openFlowNode)) {
@@ -89,7 +88,7 @@ public class FlowCapableNodeDataChangeListener implements DataChangeListener, Au
         for (Map.Entry<InstanceIdentifier<?>, DataObject> updated : changes.getUpdatedData().entrySet()) {
             InstanceIdentifier<?> iID = updated.getKey();
             String openflowId = iID.firstKeyOf(Node.class, NodeKey.class).getId().getValue();
-            LOG.debug(">>>>> updated iiD: {} - first: {} - NodeKey: {}",
+            LOG.trace(">>>>> updated iiD: {} - first: {} - NodeKey: {}",
                     iID, iID.firstIdentifierOf(Node.class), openflowId);
             Node openFlowNode = NodeUtils.getOpenFlowNode(openflowId);
             if (nodeCache.contains(openFlowNode)) {
@@ -113,9 +112,6 @@ public class FlowCapableNodeDataChangeListener implements DataChangeListener, Au
 
         nodeCache.add(openFlowNode);
 
-        if (networkingProviderManager != null) {
-            networkingProviderManager.getProvider(openFlowNode).initializeOFFlowRules(openFlowNode);
-        }
         if (pipelineOrchestrator != null) {
             pipelineOrchestrator.enqueue(openflowId);
         }
@@ -140,10 +136,6 @@ public class FlowCapableNodeDataChangeListener implements DataChangeListener, Au
          * Obtain local ref to members, if needed. Having these local saves us from calling getGlobalInstance
          * upon every event.
          */
-        if (networkingProviderManager == null) {
-            networkingProviderManager =
-                    (NetworkingProviderManager) ServiceHelper.getGlobalInstance(NetworkingProviderManager.class, this);
-        }
         if (pipelineOrchestrator == null) {
             pipelineOrchestrator =
                     (PipelineOrchestrator) ServiceHelper.getGlobalInstance(PipelineOrchestrator.class, this);
index 3b85a200d2be5b667afe46a70d4117a80c660262..fcc2436e2d14dc4a9b965c96e2a6a3c7ec68dcca 100644 (file)
@@ -169,6 +169,7 @@ public class Activator extends DependencyActivatorBase {
 
         manager.add(createComponent()
                 .setInterface(new String[]{OvsdbInventoryListener.class.getName(),
+                                NodeCacheListener.class.getName(),
                                 AbstractHandler.class.getName()},
                         southboundHandlerProperties)
                 .setImplementation(SouthboundHandler.class)
@@ -179,7 +180,8 @@ public class Activator extends DependencyActivatorBase {
                 .add(createServiceDependency().setService(OvsdbConfigurationService.class).setRequired(true))
                 .add(createServiceDependency().setService(OvsdbConnectionService.class).setRequired(true))
                 .add(createServiceDependency().setService(EventDispatcher.class).setRequired(true))
-                .add(createServiceDependency().setService(NeutronL3Adapter.class).setRequired(true)));
+                .add(createServiceDependency().setService(NeutronL3Adapter.class).setRequired(true))
+                .add(createServiceDependency().setService(NodeCacheManager.class).setRequired(true)));
 
         Dictionary<String, Object> lbaasHandlerProperties = new Hashtable<>();
         lbaasHandlerProperties.put(Constants.EVENT_HANDLER_TYPE_PROPERTY,
index 46d2f4474b2bfd579e44c80aa7bedb8da9c3a7d3..f2aa19bfe4b66ef1402522e2a795c94506ef23d4 100644 (file)
@@ -16,6 +16,7 @@ import org.opendaylight.ovsdb.openstack.netvirt.api.Action;
 import org.opendaylight.ovsdb.openstack.netvirt.api.BridgeConfigurationManager;
 import org.opendaylight.ovsdb.openstack.netvirt.api.ConfigurationService;
 import org.opendaylight.ovsdb.openstack.netvirt.api.NetworkingProviderManager;
+import org.opendaylight.ovsdb.openstack.netvirt.api.NodeCacheListener;
 import org.opendaylight.ovsdb.openstack.netvirt.api.TenantNetworkManager;
 import org.opendaylight.ovsdb.openstack.netvirt.impl.NeutronL3Adapter;
 import org.opendaylight.ovsdb.plugin.api.OvsdbConfigurationService;
@@ -35,7 +36,8 @@ import java.util.Map;
 import java.util.Set;
 import java.util.concurrent.ConcurrentMap;
 
-public class SouthboundHandler extends AbstractHandler implements OvsdbInventoryListener {
+public class SouthboundHandler extends AbstractHandler
+        implements NodeCacheListener, OvsdbInventoryListener {
     static final Logger logger = LoggerFactory.getLogger(SouthboundHandler.class);
     //private Thread eventThread;
 
@@ -321,6 +323,7 @@ public class SouthboundHandler extends AbstractHandler implements OvsdbInventory
             return;
         }
         SouthboundEvent ev = (SouthboundEvent) abstractEvent;
+        //logger.info("processEvent: {}", ev);
         switch (ev.getType()) {
             case NODE:
                 try {
@@ -343,4 +346,21 @@ public class SouthboundHandler extends AbstractHandler implements OvsdbInventory
                 break;
         }
     }
+
+    /**
+     * Notification about an OpenFlow Node
+     *
+     * @param openFlowNode the {@link org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node Node} of interest in the notification
+     * @param action the {@link Action}
+     * @see NodeCacheListener#notifyNode
+     */
+    @Override
+    public void notifyNode (Node openFlowNode, Action action) {
+        logger.info("notifyNode: Node {} update {} from Controller's inventory Service",
+                openFlowNode, action);
+
+        if (action.equals(Action.ADD)) {
+            networkingProviderManager.getProvider(openFlowNode).initializeOFFlowRules(openFlowNode);
+        }
+    }
 }