Bug 8998 - L2GW:Vlan bindings missing on reboot
[netvirt.git] / vpnservice / elanmanager / elanmanager-impl / src / main / java / org / opendaylight / netvirt / elan / l2gw / listeners / HwvtepLogicalSwitchListener.java
index 735abc408c12e0d7caf6ee9e37dca7ae70528166..586e9c93d9ee7fe9577b7062497e86c71bf596aa 100644 (file)
@@ -7,11 +7,9 @@
  */
 package org.opendaylight.netvirt.elan.l2gw.listeners;
 
-import org.opendaylight.controller.md.sal.binding.api.ClusteredDataChangeListener;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipService;
-import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker;
-import org.opendaylight.genius.datastoreutils.AsyncClusteredDataChangeListenerBase;
+import org.opendaylight.genius.datastoreutils.hwvtep.HwvtepClusteredDataTreeChangeListener;
 import org.opendaylight.genius.utils.hwvtep.HwvtepSouthboundUtils;
 import org.opendaylight.netvirt.elan.l2gw.jobs.LogicalSwitchAddedJob;
 import org.opendaylight.netvirt.elan.l2gw.utils.ElanL2GatewayMulticastUtils;
@@ -36,7 +34,7 @@ import org.slf4j.LoggerFactory;
  * @see LogicalSwitches
  */
 public class HwvtepLogicalSwitchListener extends
-    AsyncClusteredDataChangeListenerBase<LogicalSwitches, HwvtepLogicalSwitchListener> {
+        HwvtepClusteredDataTreeChangeListener<LogicalSwitches, HwvtepLogicalSwitchListener> {
 
     /** The Constant LOG. */
     private static final Logger LOG = LoggerFactory.getLogger(HwvtepLogicalSwitchListener.class);
@@ -112,28 +110,9 @@ public class HwvtepLogicalSwitchListener extends
                 new HwvtepNodeName(logicalSwitchName));
     }
 
-    /*
-     * (non-Javadoc)
-     *
-     * @see
-     * org.opendaylight.genius.datastoreutils.AsyncClusteredDataChangeListenerBase#
-     * getDataChangeListener()
-     */
-    @Override
-    protected ClusteredDataChangeListener getDataChangeListener() {
-        return HwvtepLogicalSwitchListener.this;
-    }
-
-    /*
-     * (non-Javadoc)
-     *
-     * @see
-     * org.opendaylight.genius.datastoreutils.AsyncClusteredDataChangeListenerBase#
-     * getDataChangeScope()
-     */
     @Override
-    protected AsyncDataBroker.DataChangeScope getDataChangeScope() {
-        return AsyncDataBroker.DataChangeScope.BASE;
+    protected HwvtepLogicalSwitchListener getDataTreeChangeListener() {
+        return this;
     }
 
     /*
@@ -145,7 +124,7 @@ public class HwvtepLogicalSwitchListener extends
      * org.opendaylight.yangtools.yang.binding.DataObject)
      */
     @Override
-    protected void remove(InstanceIdentifier<LogicalSwitches> identifier, LogicalSwitches deletedLogicalSwitch) {
+    protected void removed(InstanceIdentifier<LogicalSwitches> identifier, LogicalSwitches deletedLogicalSwitch) {
         LOG.trace("Received Remove DataChange Notification for identifier: {}, LogicalSwitches: {}", identifier,
                 deletedLogicalSwitch);
     }
@@ -160,27 +139,21 @@ public class HwvtepLogicalSwitchListener extends
      * org.opendaylight.yangtools.yang.binding.DataObject)
      */
     @Override
-    protected void update(InstanceIdentifier<LogicalSwitches> identifier, LogicalSwitches logicalSwitchOld,
+    protected void updated(InstanceIdentifier<LogicalSwitches> identifier, LogicalSwitches logicalSwitchOld,
             LogicalSwitches logicalSwitchNew) {
         LOG.trace("Received Update DataChange Notification for identifier: {}, LogicalSwitches old: {}, new: {}."
                 + "No Action Performed.", identifier, logicalSwitchOld, logicalSwitchNew);
     }
 
-    /*
-     * (non-Javadoc)
-     *
-     * @see
-     * org.opendaylight.genius.datastoreutils.AsyncClusteredDataChangeListenerBase#
-     * add(org.opendaylight.yangtools.yang.binding.InstanceIdentifier,
-     * org.opendaylight.yangtools.yang.binding.DataObject)
-     */
     @Override
-    protected void add(InstanceIdentifier<LogicalSwitches> identifier, LogicalSwitches logicalSwitchNew) {
+    @SuppressWarnings("checkstyle:IllegalCatch")
+    protected void added(InstanceIdentifier<LogicalSwitches> identifier, LogicalSwitches logicalSwitchNew) {
         LOG.debug("Received Add DataChange Notification for identifier: {}, LogicalSwitches: {}", identifier,
                 logicalSwitchNew);
         try {
-            L2GatewayDevice elanDevice = L2GatewayConnectionUtils.addL2DeviceToElanL2GwCache(
-                    logicalSwitchNew.getHwvtepNodeName().getValue(), l2GatewayDevice, l2GwConnId);
+            L2GatewayDevice elanDevice = L2GatewayConnectionUtils.addL2DeviceToElanL2GwCache(broker,
+                    logicalSwitchNew.getHwvtepNodeName().getValue(), elanUtils,
+                    l2GatewayDevice, l2GwConnId,physicalDevice);
 
             LogicalSwitchAddedJob logicalSwitchAddedWorker = new LogicalSwitchAddedJob(broker, elanL2GatewayUtils,
                     elanUtils, elanL2GatewayMulticastUtils, logicalSwitchName, physicalDevice, elanDevice,
@@ -188,17 +161,18 @@ public class HwvtepLogicalSwitchListener extends
             ElanClusterUtils.runOnlyInLeaderNode(entityOwnershipService, logicalSwitchAddedWorker.getJobKey() ,
                     "create vlan mappings and mcast configurations",
                     logicalSwitchAddedWorker);
-        } catch (Exception e) {
-            LOG.error("Failed to handle HwVTEPLogicalSwitch - add: {}", e);
+        } catch (RuntimeException e) {
+            LOG.error("Failed to handle HwVTEPLogicalSwitch - add for: {}", identifier, e);
         } finally {
             try {
                 // This listener is specific to handle a specific logical
                 // switch, hence closing it.
                 LOG.trace("Closing LogicalSwitches listener for node: {}, logicalSwitch: {}", nodeId.getValue(),
                         logicalSwitchName);
+                // TODO use https://git.opendaylight.org/gerrit/#/c/44145/ when merged, and remove @SuppressWarnings
                 close();
             } catch (Exception e) {
-                LOG.warn("Failed to close HwVTEPLogicalSwitchListener: {}", e);
+                LOG.warn("Failed to close HwVTEPLogicalSwitchListener", e);
             }
         }
     }