NETVIRT-1630 migrate to md-sal APIs
[netvirt.git] / elanmanager / impl / src / main / java / org / opendaylight / netvirt / elan / l2gw / ha / handlers / OpNodeUpdatedHandler.java
index 468874cf33eecf5ff40670286e2764c74ef0d998..8d685026d688103fad1ed262a3abea7ba01d36c8 100644 (file)
@@ -7,9 +7,9 @@
  */
 package org.opendaylight.netvirt.elan.l2gw.ha.handlers;
 
-import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
+import org.opendaylight.genius.infra.Datastore.Operational;
+import org.opendaylight.genius.infra.TypedReadWriteTransaction;
+import org.opendaylight.mdsal.binding.api.DataObjectModification;
 import org.opendaylight.netvirt.elan.l2gw.ha.HwvtepHAUtil;
 import org.opendaylight.netvirt.elan.l2gw.ha.merge.GlobalAugmentationMerger;
 import org.opendaylight.netvirt.elan.l2gw.ha.merge.GlobalNodeMerger;
@@ -27,65 +27,40 @@ public class OpNodeUpdatedHandler {
     GlobalNodeMerger globalNodeMerger         = GlobalNodeMerger.getInstance();
     PSNodeMerger psNodeMerger             = PSNodeMerger.getInstance();
 
-    public void handle(Node updatedSrcNode, Node origSrcNode, InstanceIdentifier<Node> haPath, ReadWriteTransaction tx)
-            throws ReadFailedException {
-        if (updatedSrcNode.getAugmentation(HwvtepGlobalAugmentation.class) != null) {
-            copyChildGlobalOpUpdateToHAParent(updatedSrcNode, origSrcNode, haPath, tx);
-        } else {
-            copyChildPsOpUpdateToHAParent(updatedSrcNode, origSrcNode, haPath, tx);
-        }
-    }
-
     /**
      * Copy HA ps node update to HA child ps node of operational data tree.
      *
      * @param updatedSrcPSNode Updated HA child ps node
-     * @param origSrcPSNode Original HA ps node
      * @param haPath HA node path
+     * @param mod the data object modification
      * @param tx Transaction
-     * @throws ReadFailedException  Exception thrown if read fails
      */
     public void copyChildPsOpUpdateToHAParent(Node updatedSrcPSNode,
-                                              Node origSrcPSNode,
                                               InstanceIdentifier<Node> haPath,
-                                              ReadWriteTransaction tx) throws ReadFailedException {
+                                              DataObjectModification<Node> mod,
+                                              TypedReadWriteTransaction<Operational> tx) {
 
         InstanceIdentifier<Node> haPSPath = HwvtepHAUtil.convertPsPath(updatedSrcPSNode, haPath);
-        Node existingHAPSNode = HwvtepHAUtil.readNode(tx, LogicalDatastoreType.OPERATIONAL, haPSPath);
 
-        PhysicalSwitchAugmentation updatedSrc   = HwvtepHAUtil.getPhysicalSwitchAugmentationOfNode(updatedSrcPSNode);
-        PhysicalSwitchAugmentation origSrc      = HwvtepHAUtil.getPhysicalSwitchAugmentationOfNode(origSrcPSNode);
-        PhysicalSwitchAugmentation existingData = HwvtepHAUtil.getPhysicalSwitchAugmentationOfNode(existingHAPSNode);
-
-        psAugmentationMerger.mergeOpUpdate(existingData, updatedSrc, origSrc, haPSPath, tx);
-        psNodeMerger.mergeOpUpdate(existingHAPSNode, updatedSrcPSNode, origSrcPSNode, haPSPath, tx);
+        psAugmentationMerger.mergeOpUpdate(haPSPath,
+                mod.getModifiedAugmentation(PhysicalSwitchAugmentation.class), tx);
+        psNodeMerger.mergeOpUpdate(haPSPath, mod, tx);
     }
 
     /**
      * Copy updated data from HA node to child node of operational data tree.
      *
-     * @param updatedSrcNode Updated HA child node
-     * @param origSrcNode Original HA node
      * @param haPath HA node path
+     * @param mod the data object modification
      * @param tx Transaction
-     * @throws ReadFailedException  Exception thrown if read fails
      */
-    public void copyChildGlobalOpUpdateToHAParent(Node updatedSrcNode,
-                                                  Node origSrcNode,
-                                                  InstanceIdentifier<Node> haPath,
-                                                  ReadWriteTransaction tx) throws ReadFailedException {
-
-        Node existingDstNode = HwvtepHAUtil.readNode(tx, LogicalDatastoreType.OPERATIONAL, haPath);
-        if (existingDstNode == null) {
-            //No dst present nothing to copy
-            return;
-        }
-        HwvtepGlobalAugmentation existingData    = HwvtepHAUtil.getGlobalAugmentationOfNode(existingDstNode);
-        HwvtepGlobalAugmentation updatedSrc = HwvtepHAUtil.getGlobalAugmentationOfNode(updatedSrcNode);
-        HwvtepGlobalAugmentation origSrc    = HwvtepHAUtil.getGlobalAugmentationOfNode(origSrcNode);
+    public void copyChildGlobalOpUpdateToHAParent(InstanceIdentifier<Node> haPath,
+                                                  DataObjectModification<Node> mod,
+                                                  TypedReadWriteTransaction<Operational> tx) {
 
-        globalAugmentationMerger.mergeOpUpdate(existingData, updatedSrc, origSrc, haPath, tx);
-        globalNodeMerger.mergeOpUpdate(existingDstNode, updatedSrcNode, origSrcNode, haPath, tx);
+        globalAugmentationMerger.mergeOpUpdate(haPath,
+                mod.getModifiedAugmentation(HwvtepGlobalAugmentation.class), tx);
+        globalNodeMerger.mergeOpUpdate(haPath, mod, tx);
     }
 
 }