Add HwvtepNodeHACache interface 89/66789/9
authorTom Pantelis <tompantelis@gmail.com>
Thu, 28 Dec 2017 16:15:28 +0000 (11:15 -0500)
committerDavid Suárez Fuentes <david.suarez.fuentes@gmail.com>
Tue, 6 Mar 2018 14:52:36 +0000 (14:52 +0000)
This is the first in a series of patches to eliminate the
static HwvtepHACache. Added an HwvtepNodeHACache interface
which HwvtepHACache temporarily implements until netvirt
is migrated to use HwvtepNodeHACache in the next patch.
The static HwvtepHACache instance is also temporarily
advertised as the HwvtepNodeHACache service.

Change-Id: I67154a0bfa21655d1158ba81b472e6501ac1ce76
Signed-off-by: Tom Pantelis <tompantelis@gmail.com>
interfacemanager/interfacemanager-impl/src/main/java/org/opendaylight/genius/interfacemanager/listeners/HwVTEPTunnelsStateListener.java
interfacemanager/interfacemanager-impl/src/main/resources/org/opendaylight/blueprint/interfacemanager.xml
mdsalutil/mdsalutil-api/src/main/java/org/opendaylight/genius/datastoreutils/hwvtep/HwvtepAbstractDataTreeChangeListener.java
mdsalutil/mdsalutil-api/src/main/java/org/opendaylight/genius/datastoreutils/hwvtep/HwvtepClusteredDataTreeChangeListener.java
mdsalutil/mdsalutil-api/src/main/java/org/opendaylight/genius/utils/hwvtep/HwvtepHACache.java
mdsalutil/mdsalutil-api/src/main/java/org/opendaylight/genius/utils/hwvtep/HwvtepNodeHACache.java [new file with mode: 0644]
mdsalutil/mdsalutil-impl/pom.xml
mdsalutil/mdsalutil-impl/src/main/resources/org/opendaylight/blueprint/mdsalutil.xml

index 0e01199613d5808d24e5c7a28d3f2d6bdf17c2c2..03fda28273e10e54e86bf1c8378f631d9975e6f4 100644 (file)
@@ -8,12 +8,10 @@
 package org.opendaylight.genius.interfacemanager.listeners;
 
 import com.google.common.util.concurrent.ListenableFuture;
-
 import java.util.List;
 import java.util.concurrent.Callable;
 import javax.inject.Inject;
 import javax.inject.Singleton;
-
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.genius.datastoreutils.hwvtep.HwvtepAbstractDataTreeChangeListener;
@@ -25,6 +23,7 @@ import org.opendaylight.genius.interfacemanager.renderer.hwvtep.statehelpers.HwV
 import org.opendaylight.genius.interfacemanager.renderer.hwvtep.statehelpers.HwVTEPInterfaceStateUpdateHelper;
 import org.opendaylight.genius.srm.RecoverableListener;
 import org.opendaylight.genius.srm.ServiceRecoveryRegistry;
+import org.opendaylight.genius.utils.hwvtep.HwvtepNodeHACache;
 import org.opendaylight.infrautils.jobcoordinator.JobCoordinator;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.PhysicalSwitchAugmentation;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.physical._switch.attributes.Tunnels;
@@ -48,8 +47,9 @@ public class HwVTEPTunnelsStateListener
     @Inject
     public HwVTEPTunnelsStateListener(final DataBroker dataBroker, final JobCoordinator coordinator,
                                       final InterfaceServiceRecoveryHandler interfaceServiceRecoveryHandler,
-                                      final ServiceRecoveryRegistry serviceRecoveryRegistry) {
-        super(Tunnels.class, HwVTEPTunnelsStateListener.class);
+                                      final ServiceRecoveryRegistry serviceRecoveryRegistry,
+                                      final HwvtepNodeHACache hwvtepNodeHACache) {
+        super(Tunnels.class, HwVTEPTunnelsStateListener.class, hwvtepNodeHACache);
         this.txRunner = new ManagedNewTransactionRunnerImpl(dataBroker);
         this.coordinator = coordinator;
         this.dataBroker = dataBroker;
index 7797d7a5ebf55bc38f60d3de9efbd34703398f19..2bca58836f694a770802daf0e637022b1ec735c5 100644 (file)
@@ -46,6 +46,9 @@ and is available at http://www.eclipse.org/legal/epl-v10.html
     <reference id="serviceRecoveryRegistry"
                interface="org.opendaylight.genius.srm.ServiceRecoveryRegistry"/>
 
+    <reference id="hwvtepNodeHACache"
+             interface="org.opendaylight.genius.utils.hwvtep.HwvtepNodeHACache"/>
+
     <odl:rpc-implementation ref="interfaceManagerRpcService" />
 
     <odl:clustered-app-config id="ifmConfig"
index 10cde09eb8744c12d5a9ad25928ce569a9bfd32c..a1d4c42b1009c2170ad4123e620754a3a48bfc1f 100644 (file)
@@ -10,19 +10,29 @@ package org.opendaylight.genius.datastoreutils.hwvtep;
 import org.opendaylight.controller.md.sal.binding.api.DataTreeChangeListener;
 import org.opendaylight.genius.datastoreutils.AsyncDataTreeChangeListenerBase;
 import org.opendaylight.genius.utils.hwvtep.HwvtepHACache;
+import org.opendaylight.genius.utils.hwvtep.HwvtepNodeHACache;
 import org.opendaylight.yangtools.yang.binding.DataObject;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 
 public abstract class HwvtepAbstractDataTreeChangeListener<T extends DataObject,K extends DataTreeChangeListener<T>>
         extends AsyncDataTreeChangeListenerBase<T,K> {
 
+    private final HwvtepNodeHACache hwvtepNodeHACache;
+
+    @Deprecated
     public HwvtepAbstractDataTreeChangeListener(Class<T> clazz, Class<K> eventClazz) {
-        super(clazz,eventClazz);
+        this(clazz, eventClazz, HwvtepHACache.getInstance());
+    }
+
+    public HwvtepAbstractDataTreeChangeListener(Class<T> clazz, Class<K> eventClazz,
+            HwvtepNodeHACache hwvtepNodeHACache) {
+        super(clazz, eventClazz);
+        this.hwvtepNodeHACache = hwvtepNodeHACache;
     }
 
     @Override
     protected void remove(InstanceIdentifier<T> identifier, T del) {
-        if (HwvtepHACache.getInstance().isHAEnabledDevice(identifier)) {
+        if (hwvtepNodeHACache.isHAEnabledDevice(identifier)) {
             return;
         }
         removed(identifier, del);
@@ -30,7 +40,7 @@ public abstract class HwvtepAbstractDataTreeChangeListener<T extends DataObject,
 
     @Override
     protected void update(InstanceIdentifier<T> identifier, T original, T update) {
-        if (HwvtepHACache.getInstance().isHAEnabledDevice(identifier)) {
+        if (hwvtepNodeHACache.isHAEnabledDevice(identifier)) {
             return;
         }
         updated(identifier,original,update);
@@ -38,7 +48,7 @@ public abstract class HwvtepAbstractDataTreeChangeListener<T extends DataObject,
 
     @Override
     protected void add(InstanceIdentifier<T> identifier, T add) {
-        if (HwvtepHACache.getInstance().isHAEnabledDevice(identifier)) {
+        if (hwvtepNodeHACache.isHAEnabledDevice(identifier)) {
             return;
         }
         added(identifier,add);
index 12fa49004c10cc09f9163432c9d90968a88a2567..8e379fa79f4d04f344d8647a70098aee3faba97b 100644 (file)
@@ -10,6 +10,7 @@ package org.opendaylight.genius.datastoreutils.hwvtep;
 import org.opendaylight.controller.md.sal.binding.api.ClusteredDataTreeChangeListener;
 import org.opendaylight.genius.datastoreutils.AsyncClusteredDataTreeChangeListenerBase;
 import org.opendaylight.genius.utils.hwvtep.HwvtepHACache;
+import org.opendaylight.genius.utils.hwvtep.HwvtepNodeHACache;
 import org.opendaylight.yangtools.yang.binding.DataObject;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 
@@ -17,13 +18,22 @@ public abstract class HwvtepClusteredDataTreeChangeListener<
     T extends DataObject, K extends ClusteredDataTreeChangeListener<T>>
         extends AsyncClusteredDataTreeChangeListenerBase<T, K> {
 
+    private final HwvtepNodeHACache hwvtepNodeHACache;
+
+    @Deprecated
     public HwvtepClusteredDataTreeChangeListener(Class<T> clazz, Class<K> eventClazz) {
+        this(clazz, eventClazz, HwvtepHACache.getInstance());
+    }
+
+    public HwvtepClusteredDataTreeChangeListener(Class<T> clazz, Class<K> eventClazz,
+            HwvtepNodeHACache hwvtepNodeHACache) {
         super(clazz, eventClazz);
+        this.hwvtepNodeHACache = hwvtepNodeHACache;
     }
 
     @Override
     protected void remove(InstanceIdentifier<T> identifier, T del) {
-        if (HwvtepHACache.getInstance().isHAEnabledDevice(identifier)) {
+        if (hwvtepNodeHACache.isHAEnabledDevice(identifier)) {
             return;
         }
         removed(identifier,del);
@@ -31,7 +41,7 @@ public abstract class HwvtepClusteredDataTreeChangeListener<
 
     @Override
     protected void update(InstanceIdentifier<T> identifier, T original, T update) {
-        if (HwvtepHACache.getInstance().isHAEnabledDevice(identifier)) {
+        if (hwvtepNodeHACache.isHAEnabledDevice(identifier)) {
             return;
         }
         updated(identifier,original, update);
@@ -39,7 +49,7 @@ public abstract class HwvtepClusteredDataTreeChangeListener<
 
     @Override
     protected void add(InstanceIdentifier<T> identifier, T add) {
-        if (HwvtepHACache.getInstance().isHAEnabledDevice(identifier)) {
+        if (hwvtepNodeHACache.isHAEnabledDevice(identifier)) {
             return;
         }
         added(identifier, add);
index 83bca73c72a75efed0949a7e0a8267ccea731110..c2c9ea8fdc9811cc3b92865f8e1346452515cfe2 100644 (file)
@@ -21,7 +21,8 @@ import java.util.concurrent.LinkedBlockingQueue;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 
-public class HwvtepHACache {
+@Deprecated
+public class HwvtepHACache implements HwvtepNodeHACache {
     private static final int MAX_EVENT_BUFFER_SIZE = 500000;
     private static final int EVENT_DRAIN_BUFFER_SIZE = 100000;
 
@@ -43,6 +44,7 @@ public class HwvtepHACache {
         return instance;
     }
 
+    @Override
     public synchronized void addChild(InstanceIdentifier<Node> parent, InstanceIdentifier<Node> child) {
         if (parent == null || child == null) {
             return;
@@ -55,6 +57,7 @@ public class HwvtepHACache {
         addDebugEvent(new NodeEvent.ChildAddedEvent(childNodeId));
     }
 
+    @Override
     public boolean isHAEnabledDevice(InstanceIdentifier<?> iid) {
         if (iid == null) {
             return false;
@@ -71,10 +74,12 @@ public class HwvtepHACache {
         return enabled;
     }
 
+    @Override
     public  boolean isHAParentNode(InstanceIdentifier<Node> node) {
         return parentToChildMap.containsKey(node);
     }
 
+    @Override
     public Set<InstanceIdentifier<Node>> getChildrenForHANode(InstanceIdentifier<Node> parent) {
         if (parent != null && parentToChildMap.containsKey(parent)) {
             return new HashSet<>(parentToChildMap.get(parent));
@@ -83,14 +88,17 @@ public class HwvtepHACache {
         }
     }
 
+    @Override
     public Set<InstanceIdentifier<Node>> getHAParentNodes() {
         return parentToChildMap.keySet();
     }
 
+    @Override
     public Set<InstanceIdentifier<Node>> getHAChildNodes() {
         return childToParentMap.keySet();
     }
 
+    @Override
     public InstanceIdentifier<Node> getParent(InstanceIdentifier<Node> child) {
         if (child != null) {
             return childToParentMap.get(child);
@@ -98,6 +106,11 @@ public class HwvtepHACache {
         return null;
     }
 
+    @Override
+    public void removeParent(InstanceIdentifier<Node> parent) {
+        cleanupParent(parent);
+    }
+
     public synchronized void cleanupParent(InstanceIdentifier<Node> parent) {
         if (parent == null) {
             return;
@@ -114,6 +127,7 @@ public class HwvtepHACache {
         parentToChildMap.remove(parent);
     }
 
+    @Override
     public void updateConnectedNodeStatus(InstanceIdentifier<Node> iid) {
         String nodeId = iid.firstKeyOf(Node.class).getNodeId().getValue();
         connectedNodes.put(nodeId, true);
@@ -121,6 +135,7 @@ public class HwvtepHACache {
         addDebugEvent(event);
     }
 
+    @Override
     public void updateDisconnectedNodeStatus(InstanceIdentifier<Node> iid) {
         String nodeId = iid.firstKeyOf(Node.class).getNodeId().getValue();
         connectedNodes.put(nodeId, false);
@@ -146,4 +161,9 @@ public class HwvtepHACache {
     public List<DebugEvent> getNodeEvents() {
         return ImmutableList.copyOf(debugEvents);
     }
+
+    @Override
+    public Map<String, Boolean> getNodeConnectionStatuses() {
+        return getConnectedNodes();
+    }
 }
diff --git a/mdsalutil/mdsalutil-api/src/main/java/org/opendaylight/genius/utils/hwvtep/HwvtepNodeHACache.java b/mdsalutil/mdsalutil-api/src/main/java/org/opendaylight/genius/utils/hwvtep/HwvtepNodeHACache.java
new file mode 100644 (file)
index 0000000..11c64e2
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2017 Inocybe Technologies and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.genius.utils.hwvtep;
+
+import java.util.Map;
+import java.util.Set;
+import javax.annotation.Nonnull;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+/**
+ * Caches hwvtep Node HA info.
+ *
+ * @author Thomas Pantelis
+ */
+public interface HwvtepNodeHACache {
+    void addChild(InstanceIdentifier<Node> parentId, InstanceIdentifier<Node> childId);
+
+    boolean isHAEnabledDevice(InstanceIdentifier<?> nodeId);
+
+    boolean isHAParentNode(InstanceIdentifier<Node> nodeId);
+
+    // Commented out for now - causes findbugs violation in netvirt
+    //@Nonnull
+    Set<InstanceIdentifier<Node>> getChildrenForHANode(InstanceIdentifier<Node> parentId);
+
+    @Nonnull
+    Set<InstanceIdentifier<Node>> getHAParentNodes();
+
+    @Nonnull
+    Set<InstanceIdentifier<Node>> getHAChildNodes();
+
+    InstanceIdentifier<Node> getParent(InstanceIdentifier<Node> childId);
+
+    void removeParent(InstanceIdentifier<Node> parentId);
+
+    void updateConnectedNodeStatus(InstanceIdentifier<Node> nodeId);
+
+    void updateDisconnectedNodeStatus(InstanceIdentifier<Node> nodeId);
+
+    @Nonnull
+    Map<String, Boolean> getNodeConnectionStatuses();
+}
index 5b46b6dfbc0b1a790534543603b04e099a2f16d8..0b425b9000e506b34d468e8ad00f6226038a699c 100644 (file)
@@ -119,6 +119,19 @@ and is available at http://www.eclipse.org/legal/epl-v10.html
         <groupId>org.apache.aries.blueprint</groupId>
         <artifactId>blueprint-maven-plugin</artifactId>
       </plugin>
+      <plugin>
+        <groupId>org.apache.felix</groupId>
+        <artifactId>maven-bundle-plugin</artifactId>
+        <extensions>true</extensions>
+        <configuration>
+          <instructions>
+            <Import-Package>
+                *;
+                org.opendaylight.genius.utils.hwvtep
+            </Import-Package>
+          </instructions>
+        </configuration>
+      </plugin>
     </plugins>
   </build>
 </project>
index 0494bcd147c1cc9b016c52a519f9cce1e31b8bff..ac886084243ce252738c2769a736183c4b3bea89 100644 (file)
@@ -21,4 +21,10 @@ and is available at http://www.eclipse.org/legal/epl-v10.html
                             update-strategy="none">
   </odl:clustered-app-config>
 
+  <bean id="hwvtepHACache" class="org.opendaylight.genius.utils.hwvtep.HwvtepHACache"
+      factory-method="getInstance"/>
+
+  <service ref="hwvtepHACache"
+           interface="org.opendaylight.genius.utils.hwvtep.HwvtepNodeHACache"/>
+
 </blueprint>