bug 7599 avoid mdsal read 16/51516/3
authorK.V Suneelu Verma <k.v.suneelu.verma@ericsson.com>
Tue, 7 Feb 2017 13:00:15 +0000 (18:30 +0530)
committerK.V Suneelu Verma <k.v.suneelu.verma@ericsson.com>
Wed, 15 Mar 2017 05:21:03 +0000 (10:51 +0530)
while processing the config update avoid mdsal read
maintain the instance identifier vs connectionInstance map.
Update the map upon GlobalUpdate.
Clear the map upon node disconnect event.
Use the map to identifiy the connectionInstance for the changed node.

Change-Id: I8cbb505f0e56bdc0a3f5b46104a26aa02381ad6f
Signed-off-by: K.V Suneelu Verma <k.v.suneelu.verma@ericsson.com>
hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/HwvtepConnectionInstance.java
hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/HwvtepConnectionManager.java
hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/HwvtepDataChangeListener.java
hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/HwvtepSouthboundUtil.java
hwvtepsouthbound/hwvtepsouthbound-impl/src/test/java/org/opendaylight/ovsdb/hwvtepsouthbound/DataChangeListenerTestBase.java

index 1741042b7062b14d45d51657ba7ba3cf4533d70a..c64d54803df1a17ad66bea3f2488a79667631b0f 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, 2016 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
+ * Copyright (c) 2015, 2017 Ericsson India Global Services Pvt Ltd. 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,
@@ -69,9 +69,11 @@ public class HwvtepConnectionInstance {
     private HwvtepGlobalAugmentation initialCreatedData = null;
     private HwvtepDeviceInfo deviceInfo;
     private DataBroker dataBroker;
+    private final HwvtepConnectionManager hwvtepConnectionManager;
 
-    HwvtepConnectionInstance (ConnectionInfo key, OvsdbClient client,
+    HwvtepConnectionInstance (HwvtepConnectionManager hwvtepConnectionManager, ConnectionInfo key, OvsdbClient client,
                               InstanceIdentifier<Node> iid, TransactionInvoker txInvoker, DataBroker dataBroker) {
+        this.hwvtepConnectionManager = hwvtepConnectionManager;
         this.connectionInfo = key;
         this.client = client;
         this.instanceIdentifier = iid;
@@ -255,6 +257,7 @@ public class HwvtepConnectionInstance {
 
     public void setInstanceIdentifier(InstanceIdentifier<Node> iid) {
         this.instanceIdentifier = iid;
+        hwvtepConnectionManager.putConnectionInstance(instanceIdentifier, this);
     }
 
     public Entity getConnectedEntity() {
index 9ca92a88b95fa0c1517b4ab442bff8b0d7923490..a371b8bc2172d857704e61317f712cbfe22dcf22 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
+ * Copyright (c) 2015, 2017 Ericsson India Global Services Pvt Ltd. 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,
@@ -82,6 +82,8 @@ public class HwvtepConnectionManager implements OvsdbConnectionListener, AutoClo
     private EntityOwnershipService entityOwnershipService;
     private HwvtepDeviceEntityOwnershipListener hwvtepDeviceEntityOwnershipListener;
     private final ReconciliationManager reconciliationManager;
+    private final Map<InstanceIdentifier<Node>, HwvtepConnectionInstance> nodeIidVsConnectionInstance =
+            new ConcurrentHashMap<>();
 
     public HwvtepConnectionManager(DataBroker db, TransactionInvoker txInvoker,
                     EntityOwnershipService entityOwnershipService) {
@@ -151,6 +153,7 @@ public class HwvtepConnectionManager implements OvsdbConnectionListener, AutoClo
             //Controller initiated connection can be terminated from switch side.
             //So cleanup the instance identifier cache.
             removeInstanceIdentifier(key);
+            removeConnectionInstance(hwvtepConnectionInstance.getInstanceIdentifier());
             retryConnection(hwvtepConnectionInstance.getInstanceIdentifier(),
                     hwvtepConnectionInstance.getHwvtepGlobalAugmentation(),
                     ConnectionReconciliationTriggers.ON_DISCONNECT);
@@ -213,7 +216,7 @@ public class HwvtepConnectionManager implements OvsdbConnectionListener, AutoClo
             removeConnectionInstance(key);
         }
 
-        hwvtepConnectionInstance = new HwvtepConnectionInstance(key, externalClient, getInstanceIdentifier(key),
+        hwvtepConnectionInstance = new HwvtepConnectionInstance(this, key, externalClient, getInstanceIdentifier(key),
                 txInvoker, db);
         hwvtepConnectionInstance.createTransactInvokers();
         return hwvtepConnectionInstance;
@@ -233,6 +236,18 @@ public class HwvtepConnectionManager implements OvsdbConnectionListener, AutoClo
         return clients.get(connectionInfo);
     }
 
+    public HwvtepConnectionInstance getConnectionInstanceFromNodeIid(final InstanceIdentifier<Node> nodeIid) {
+        HwvtepConnectionInstance hwvtepConnectionInstance = nodeIidVsConnectionInstance.get(nodeIid);
+        if (hwvtepConnectionInstance != null) {
+            return hwvtepConnectionInstance;
+        }
+        InstanceIdentifier<Node> globalNodeIid = HwvtepSouthboundUtil.getGlobalNodeIid(nodeIid);
+        if (globalNodeIid != null) {
+            return nodeIidVsConnectionInstance.get(globalNodeIid);
+        }
+        return null;
+    }
+
     public HwvtepConnectionInstance getConnectionInstance(Node node) {
         Preconditions.checkNotNull(node);
         HwvtepGlobalAugmentation hwvtepGlobal = node.getAugmentation(HwvtepGlobalAugmentation.class);
@@ -543,6 +558,17 @@ public class HwvtepConnectionManager implements OvsdbConnectionListener, AutoClo
         return entityConnectionMap.get(entity);
     }
 
+    void putConnectionInstance(final InstanceIdentifier<Node> nodeIid,
+                               final HwvtepConnectionInstance connectionInstance) {
+        nodeIidVsConnectionInstance.put(nodeIid, connectionInstance);
+    }
+
+    private void removeConnectionInstance(final InstanceIdentifier<Node> nodeIid) {
+         if (nodeIid != null) {
+             nodeIidVsConnectionInstance.remove(nodeIid);
+         }
+    }
+
     private class HwvtepDeviceEntityOwnershipListener implements EntityOwnershipListener {
         private HwvtepConnectionManager hcm;
         private EntityOwnershipListenerRegistration listenerRegistration;
index ec4e18ad4c2edf4d739e0125acf93d0cae12bfa9..af8fbb4fee21ba53e74d677e874303464ac12fff 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
+ * Copyright (c) 2015, 2017 Ericsson India Global Services Pvt Ltd. 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,
@@ -276,17 +276,8 @@ public class HwvtepDataChangeListener implements ClusteredDataTreeChangeListener
             final DataObjectModification<Node> mod = change.getRootNode();
             //From original node to get connection instance
             Node node = mod.getDataBefore()!=null ? mod.getDataBefore() : mod.getDataAfter();
-            HwvtepConnectionInstance connection = hcm.getConnectionInstance(node);
-            if(connection == null) {
-                //Let us try getting it from Operational DS
-                final ReadWriteTransaction transaction = db.newReadWriteTransaction();
-                InstanceIdentifier<Node> connectionIid = HwvtepSouthboundMapper.createInstanceIdentifier(node.getNodeId());
-                Optional<Node> optionalNode = HwvtepSouthboundUtil.readNode(transaction, connectionIid);
-                LOG.trace("Node in Operational DataStore for user node {} is {}", node, optionalNode);
-                if(optionalNode.isPresent()) {
-                    connection = hcm.getConnectionInstance(optionalNode.get());
-                }
-            }
+            HwvtepConnectionInstance connection = hcm.getConnectionInstanceFromNodeIid(
+                    change.getRootPath().getRootIdentifier());
             if (connection != null) {
                 if (!result.containsKey(connection)) {
                     List<DataTreeModification<Node>> tempChanges= new ArrayList<DataTreeModification<Node>>();
index 0a21cb73a0d62d81d2cd45d46274f55b439d8099..a5af62f145c30d7929e0057df8bbe10588d554cc 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
+ * Copyright (c) 2015, 2017 Ericsson India Global Services Pvt Ltd. 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,
@@ -24,7 +24,10 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hw
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.LogicalSwitches;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.RemoteMcastMacs;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.RemoteUcastMacs;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey;
 import org.opendaylight.yangtools.yang.binding.DataObject;
 import org.opendaylight.yangtools.yang.binding.Identifiable;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
@@ -200,4 +203,15 @@ public class HwvtepSouthboundUtil {
     public static boolean isEmptyMap(Map map) {
         return map == null || map.isEmpty();
     }
+
+    public static InstanceIdentifier<Node> getGlobalNodeIid(final InstanceIdentifier<Node> physicalNodeIid) {
+        String nodeId = physicalNodeIid.firstKeyOf(Node.class).getNodeId().getValue();
+        int physicalSwitchIndex = nodeId.indexOf(HwvtepSouthboundConstants.PSWITCH_URI_PREFIX);
+        if (physicalSwitchIndex > 0) {
+            nodeId = nodeId.substring(0, physicalSwitchIndex - 1);
+        } else {
+            return null;
+        }
+        return physicalNodeIid.firstIdentifierOf(Topology.class).child(Node.class , new NodeKey(new NodeId(nodeId)));
+    }
 }
index 08875c74a2adf8c38b92f79b972e42b726d7b358..5da2e45f992f70ff54d7dd65f7d55e07bee4eabe 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
+ * Copyright (c) 2016, 2017 Ericsson India Global Services Pvt Ltd. 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,
@@ -148,10 +148,14 @@ public class DataChangeListenerTestBase extends AbstractDataBrokerTest {
         field(HwvtepConnectionManager.class, "txInvoker").set(hwvtepConnectionManager, transactionInvoker);
         field(HwvtepConnectionManager.class, "entityOwnershipService").set(hwvtepConnectionManager, entityOwnershipService);
         suppress(PowerMockito.method(HwvtepConnectionManager.class, "getConnectionInstance", HwvtepPhysicalSwitchAttributes.class));
+        suppress(PowerMockito.method(HwvtepConnectionManager.class, "getConnectionInstanceFromNodeIid",
+                InstanceIdentifier.class));
         when(hwvtepConnectionManager.getConnectionInstance(Mockito.any(HwvtepPhysicalSwitchAttributes.class))).
                 thenReturn(connectionInstance);
         when(hwvtepConnectionManager.getConnectionInstance(Mockito.any(Node.class))).
                 thenReturn(connectionInstance);
+        when(hwvtepConnectionManager.getConnectionInstanceFromNodeIid(Mockito.any(InstanceIdentifier.class)))
+                .thenReturn(connectionInstance);
     }
 
     void mockConnectionInstance() throws IllegalAccessException {