2 * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.netvirt.elan.l2gw.ha.handlers;
10 import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
11 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
12 import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
13 import org.opendaylight.netvirt.elan.l2gw.ha.HwvtepHAUtil;
14 import org.opendaylight.netvirt.elan.l2gw.ha.merge.GlobalAugmentationMerger;
15 import org.opendaylight.netvirt.elan.l2gw.ha.merge.GlobalNodeMerger;
16 import org.opendaylight.netvirt.elan.l2gw.ha.merge.PSAugmentationMerger;
17 import org.opendaylight.netvirt.elan.l2gw.ha.merge.PSNodeMerger;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalAugmentation;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.PhysicalSwitchAugmentation;
20 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
21 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
23 public class OpNodeUpdatedHandler {
25 GlobalAugmentationMerger globalAugmentationMerger = GlobalAugmentationMerger.getInstance();
26 PSAugmentationMerger psAugmentationMerger = PSAugmentationMerger.getInstance();
27 GlobalNodeMerger globalNodeMerger = GlobalNodeMerger.getInstance();
28 PSNodeMerger psNodeMerger = PSNodeMerger.getInstance();
30 public void handle(Node updatedSrcNode, Node origSrcNode, InstanceIdentifier<Node> haPath, ReadWriteTransaction tx)
31 throws ReadFailedException {
32 if (updatedSrcNode.getAugmentation(HwvtepGlobalAugmentation.class) != null) {
33 copyChildGlobalOpUpdateToHAParent(updatedSrcNode, origSrcNode, haPath, tx);
35 copyChildPsOpUpdateToHAParent(updatedSrcNode, origSrcNode, haPath, tx);
40 * Copy HA ps node update to HA child ps node of operational data tree.
42 * @param updatedSrcPSNode Updated HA child ps node
43 * @param origSrcPSNode Original HA ps node
44 * @param haPath HA node path
45 * @param tx Transaction
46 * @throws ReadFailedException Exception thrown if read fails
48 public void copyChildPsOpUpdateToHAParent(Node updatedSrcPSNode,
50 InstanceIdentifier<Node> haPath,
51 ReadWriteTransaction tx) throws ReadFailedException {
53 InstanceIdentifier<Node> haPSPath = HwvtepHAUtil.convertPsPath(updatedSrcPSNode, haPath);
54 Node existingHAPSNode = HwvtepHAUtil.readNode(tx, LogicalDatastoreType.OPERATIONAL, haPSPath);
56 PhysicalSwitchAugmentation updatedSrc = HwvtepHAUtil.getPhysicalSwitchAugmentationOfNode(updatedSrcPSNode);
57 PhysicalSwitchAugmentation origSrc = HwvtepHAUtil.getPhysicalSwitchAugmentationOfNode(origSrcPSNode);
58 PhysicalSwitchAugmentation existingData = HwvtepHAUtil.getPhysicalSwitchAugmentationOfNode(existingHAPSNode);
60 psAugmentationMerger.mergeOpUpdate(existingData, updatedSrc, origSrc, haPSPath, tx);
61 psNodeMerger.mergeOpUpdate(existingHAPSNode, updatedSrcPSNode, origSrcPSNode, haPSPath, tx);
65 * Copy updated data from HA node to child node of operational data tree.
67 * @param updatedSrcNode Updated HA child node
68 * @param origSrcNode Original HA node
69 * @param haPath HA node path
70 * @param tx Transaction
71 * @throws ReadFailedException Exception thrown if read fails
73 public void copyChildGlobalOpUpdateToHAParent(Node updatedSrcNode,
75 InstanceIdentifier<Node> haPath,
76 ReadWriteTransaction tx) throws ReadFailedException {
78 Node existingDstNode = HwvtepHAUtil.readNode(tx, LogicalDatastoreType.OPERATIONAL, haPath);
79 if (existingDstNode == null) {
80 //No dst present nothing to copy
83 HwvtepGlobalAugmentation existingData = HwvtepHAUtil.getGlobalAugmentationOfNode(existingDstNode);
84 HwvtepGlobalAugmentation updatedSrc = HwvtepHAUtil.getGlobalAugmentationOfNode(updatedSrcNode);
85 HwvtepGlobalAugmentation origSrc = HwvtepHAUtil.getGlobalAugmentationOfNode(origSrcNode);
87 globalAugmentationMerger.mergeOpUpdate(existingData, updatedSrc, origSrc, haPath, tx);
88 globalNodeMerger.mergeOpUpdate(existingDstNode, updatedSrcNode, origSrcNode, haPath, tx);