Remove GENIUS UTIL references in Elanmanager Module
[netvirt.git] / elanmanager / impl / src / main / java / org / opendaylight / netvirt / elan / l2gw / ha / listeners / HwvtepNodeBaseListener.java
index d87fe75850dee38ad981886ae936d1ffff836995..75c7a9fc29a5f2f6fc7692e2597dda72ba5c5ff3 100644 (file)
@@ -8,22 +8,14 @@
 package org.opendaylight.netvirt.elan.l2gw.ha.listeners;
 
 import com.google.common.collect.ImmutableMap;
+import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
+import java.util.Objects;
 import java.util.concurrent.ExecutionException;
 import java.util.function.Function;
 import javax.annotation.PreDestroy;
-import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
-import org.opendaylight.controller.md.sal.binding.api.DataTreeChangeListener;
-import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
-import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
-import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
 import org.opendaylight.genius.datastoreutils.TaskRetryLooper;
-import org.opendaylight.genius.infra.Datastore;
-import org.opendaylight.genius.infra.ManagedNewTransactionRunner;
-import org.opendaylight.genius.infra.ManagedNewTransactionRunnerImpl;
-import org.opendaylight.genius.infra.TypedReadWriteTransaction;
 import org.opendaylight.genius.utils.hwvtep.HwvtepNodeHACache;
 import org.opendaylight.genius.utils.hwvtep.HwvtepSouthboundConstants;
 import org.opendaylight.infrautils.metrics.Labeled;
@@ -31,6 +23,15 @@ import org.opendaylight.infrautils.metrics.Meter;
 import org.opendaylight.infrautils.metrics.MetricDescriptor;
 import org.opendaylight.infrautils.metrics.MetricProvider;
 import org.opendaylight.infrautils.utils.concurrent.LoggingFutures;
+import org.opendaylight.mdsal.binding.api.DataBroker;
+import org.opendaylight.mdsal.binding.api.DataObjectModification;
+import org.opendaylight.mdsal.binding.api.DataTreeChangeListener;
+import org.opendaylight.mdsal.binding.api.DataTreeIdentifier;
+import org.opendaylight.mdsal.binding.api.DataTreeModification;
+import org.opendaylight.mdsal.binding.util.Datastore;
+import org.opendaylight.mdsal.binding.util.ManagedNewTransactionRunner;
+import org.opendaylight.mdsal.binding.util.ManagedNewTransactionRunnerImpl;
+import org.opendaylight.mdsal.binding.util.TypedReadWriteTransaction;
 import org.opendaylight.netvirt.elan.l2gw.ha.HwvtepHAUtil;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalAugmentation;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.PhysicalSwitchAugmentation;
@@ -55,7 +56,7 @@ public abstract class HwvtepNodeBaseListener<D extends Datastore>
     private static final int STARTUP_LOOP_TICK = 500;
     private static final int STARTUP_LOOP_MAX_RETRIES = 8;
 
-    private final ListenerRegistration<HwvtepNodeBaseListener> registration;
+    private ListenerRegistration<HwvtepNodeBaseListener> registration;
     private final DataBroker dataBroker;
     final ManagedNewTransactionRunner txRunner;
     private final HwvtepNodeHACache hwvtepNodeHACache;
@@ -89,11 +90,15 @@ public abstract class HwvtepNodeBaseListener<D extends Datastore>
         this.nodeModCounter = metricProvider.newMeter(
                 MetricDescriptor.builder().anchor(this).project("netvirt").module("l2gw").id("node").build(),
                 "datastore", "modification", "nodeid");
-        final DataTreeIdentifier<Node> treeId =
-            new DataTreeIdentifier<>(Datastore.toType(datastoreType), getWildcardPath());
+        registerListener(datastoreType, dataBroker);
+    }
+
+    protected void registerListener(Class<D> dsType, DataBroker broker) throws Exception {
+        final DataTreeIdentifier<Node> treeId = DataTreeIdentifier.create(Datastore.toType(dsType),
+                getWildcardPath());
         TaskRetryLooper looper = new TaskRetryLooper(STARTUP_LOOP_TICK, STARTUP_LOOP_MAX_RETRIES);
         registration = looper.loopUntilNoException(() ->
-                dataBroker.registerDataTreeChangeListener(treeId, HwvtepNodeBaseListener.this));
+                broker.registerDataTreeChangeListener(treeId, HwvtepNodeBaseListener.this));
     }
 
     protected DataBroker getDataBroker() {
@@ -121,16 +126,16 @@ public abstract class HwvtepNodeBaseListener<D extends Datastore>
         List<Managers> up = null;
         List<Managers> be = null;
         if (updatedAugmentaion != null) {
-            up = updatedAugmentaion.getManagers();
+            up = new ArrayList<Managers>(updatedAugmentaion.nonnullManagers().values());
         }
         if (beforeAugmentaion != null) {
-            be = beforeAugmentaion.getManagers();
+            be = new ArrayList<Managers>(beforeAugmentaion.nonnullManagers().values());
         }
 
-        if (up != null && be != null && up.size() > 0 && be.size() > 0) {
+        if (up != null) {
             Managers m1 = up.get(0);
             Managers m2 = be.get(0);
-            if (!m1.equals(m2)) {
+            if (!Objects.equals(m1, m2)) {
                 LOG.trace("Manager entry updated for node {} ", updatedChildNode.getNodeId().getValue());
                 HwvtepHAUtil.addToCacheIfHAChildNode(childPath, updatedChildNode, hwvtepNodeHACache);
             }
@@ -149,7 +154,7 @@ public abstract class HwvtepNodeBaseListener<D extends Datastore>
 
     private void processUpdatedNodes(Collection<DataTreeModification<Node>> changes,
                                      TypedReadWriteTransaction<D> tx)
-            throws ReadFailedException, ExecutionException, InterruptedException {
+            throws ExecutionException, InterruptedException {
         for (DataTreeModification<Node> change : changes) {
             final InstanceIdentifier<Node> key = change.getRootPath().getRootIdentifier();
             final DataObjectModification<Node> mod = change.getRootNode();
@@ -204,7 +209,7 @@ public abstract class HwvtepNodeBaseListener<D extends Datastore>
 
     private void processDisconnectedNodes(Collection<DataTreeModification<Node>> changes,
                                           TypedReadWriteTransaction<D> tx)
-            throws InterruptedException, ExecutionException, ReadFailedException {
+            throws InterruptedException, ExecutionException {
         for (DataTreeModification<Node> change : changes) {
             final InstanceIdentifier<Node> key = change.getRootPath().getRootIdentifier();
             final DataObjectModification<Node> mod = change.getRootNode();
@@ -250,7 +255,7 @@ public abstract class HwvtepNodeBaseListener<D extends Datastore>
         }
     }
 
-    private InstanceIdentifier<Node> getWildcardPath() {
+    private static InstanceIdentifier<Node> getWildcardPath() {
         InstanceIdentifier<Node> path = InstanceIdentifier
                 .create(NetworkTopology.class)
                 .child(Topology.class, new TopologyKey(HwvtepSouthboundConstants.HWVTEP_TOPOLOGY_ID))
@@ -268,11 +273,11 @@ public abstract class HwvtepNodeBaseListener<D extends Datastore>
 
     //default methods
     void onGlobalNodeDelete(InstanceIdentifier<Node> key, Node added, TypedReadWriteTransaction<D> tx)
-        throws ReadFailedException, ExecutionException, InterruptedException {
+        throws ExecutionException, InterruptedException {
     }
 
     void onPsNodeDelete(InstanceIdentifier<Node> key, Node addedPSNode, TypedReadWriteTransaction<D> tx)
-        throws ReadFailedException, ExecutionException, InterruptedException {
+        throws ExecutionException, InterruptedException {
 
     }
 
@@ -286,14 +291,12 @@ public abstract class HwvtepNodeBaseListener<D extends Datastore>
     }
 
     void onGlobalNodeUpdate(InstanceIdentifier<Node> key, Node updated, Node original,
-                            DataObjectModification<Node> mod, TypedReadWriteTransaction<D> tx)
-            throws ReadFailedException, InterruptedException, ExecutionException {
+                            DataObjectModification<Node> mod, TypedReadWriteTransaction<D> tx) {
 
     }
 
     void onPsNodeUpdate(Node updated,
-                        DataObjectModification<Node> mod, TypedReadWriteTransaction<D> tx)
-            throws ReadFailedException, InterruptedException, ExecutionException {
+                        DataObjectModification<Node> mod, TypedReadWriteTransaction<D> tx) {
 
     }