2 * Copyright (c) 2017 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.listeners;
10 import static org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType.CONFIGURATION;
13 import java.util.concurrent.ExecutionException;
14 import javax.inject.Inject;
15 import javax.inject.Singleton;
16 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
17 import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
18 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
19 import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
20 import org.opendaylight.netvirt.elan.l2gw.ha.HwvtepHAUtil;
21 import org.opendaylight.netvirt.elan.l2gw.ha.handlers.HAEventHandler;
22 import org.opendaylight.netvirt.elan.l2gw.ha.handlers.IHAEventHandler;
23 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
24 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
27 public class HAConfigNodeListener extends HwvtepNodeBaseListener {
28 private final IHAEventHandler haEventHandler;
31 public HAConfigNodeListener(DataBroker db, HAEventHandler haEventHandler) throws Exception {
32 super(LogicalDatastoreType.CONFIGURATION, db);
33 this.haEventHandler = haEventHandler;
37 void onPsNodeAdd(InstanceIdentifier<Node> key,
39 ReadWriteTransaction tx) throws InterruptedException, ExecutionException, ReadFailedException {
40 //copy the ps node data to children
41 String psId = haPSNode.getNodeId().getValue();
42 Set<InstanceIdentifier<Node>> childSwitchIds = HwvtepHAUtil.getPSChildrenIdsForHAPSNode(psId);
43 for (InstanceIdentifier<Node> childSwitchId : childSwitchIds) {
44 haEventHandler.copyHAPSUpdateToChild(haPSNode, null/*haOriginal*/, childSwitchId, tx);
46 LOG.trace("Handle config ps node add {}", psId);
50 void onPsNodeUpdate(InstanceIdentifier<Node> key,
53 ReadWriteTransaction tx) throws InterruptedException, ExecutionException, ReadFailedException {
54 //copy the ps node data to children
55 String psId = haPSUpdated.getNodeId().getValue();
56 Set<InstanceIdentifier<Node>> childSwitchIds = HwvtepHAUtil.getPSChildrenIdsForHAPSNode(psId);
57 for (InstanceIdentifier<Node> childSwitchId : childSwitchIds) {
58 haEventHandler.copyHAPSUpdateToChild(haPSUpdated, haPSOriginal, childSwitchId, tx);
63 void onGlobalNodeUpdate(InstanceIdentifier<Node> key,
66 ReadWriteTransaction tx)
67 throws InterruptedException, ExecutionException, ReadFailedException {
68 //copy the ha node data to children taken care of the HAListeners
70 Set<InstanceIdentifier<Node>> childNodeIds = hwvtepHACache.getChildrenForHANode(key);
71 for (InstanceIdentifier<Node> haChildNodeId : childNodeIds) {
72 haEventHandler.copyHAGlobalUpdateToChild(haUpdated, haOriginal, haChildNodeId, tx);
78 void onPsNodeDelete(InstanceIdentifier<Node> key,
80 ReadWriteTransaction tx) throws ReadFailedException {
81 //delete ps children nodes
82 String psId = deletedPsNode.getNodeId().getValue();
83 Set<InstanceIdentifier<Node>> childPsIds = HwvtepHAUtil.getPSChildrenIdsForHAPSNode(psId);
84 for (InstanceIdentifier<Node> childPsId : childPsIds) {
85 HwvtepHAUtil.deleteNodeIfPresent(tx, CONFIGURATION, childPsId);
90 void onGlobalNodeDelete(InstanceIdentifier<Node> key,
92 ReadWriteTransaction tx)
93 throws ReadFailedException, ExecutionException, InterruptedException {
95 Set<InstanceIdentifier<Node>> children = hwvtepHACache.getChildrenForHANode(key);
96 for (InstanceIdentifier<Node> childId : children) {
97 HwvtepHAUtil.deleteNodeIfPresent(tx, CONFIGURATION, childId);
99 HwvtepHAUtil.deletePSNodesOfNode(key, haNode, tx);