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 org.opendaylight.controller.md.sal.binding.api.DataBroker;
15 import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
16 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
17 import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
18 import org.opendaylight.genius.utils.hwvtep.HwvtepHACache;
19 import org.opendaylight.netvirt.elan.l2gw.ha.HwvtepHAUtil;
20 import org.opendaylight.netvirt.elan.l2gw.ha.handlers.ConfigNodeUpdatedHandler;
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;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
28 public class HAConfigNodeListener extends HwvtepNodeBaseListener {
29 private static final Logger LOG = LoggerFactory.getLogger(HAConfigNodeListener.class);
31 static HwvtepHACache hwvtepHACache = HwvtepHACache.getInstance();
33 IHAEventHandler haEventHandler;
34 ConfigNodeUpdatedHandler configNodeUpdatedHandler = new ConfigNodeUpdatedHandler();
36 public HAConfigNodeListener(DataBroker db, HAEventHandler haEventHandler) throws Exception {
37 super(LogicalDatastoreType.CONFIGURATION, db);
38 this.haEventHandler = haEventHandler;
42 void onPsNodeAdd(InstanceIdentifier<Node> key,
44 ReadWriteTransaction tx) throws InterruptedException, ExecutionException, ReadFailedException {
45 //copy the ps node data to children
46 String psId = haPSNode.getNodeId().getValue();
47 Set<InstanceIdentifier<Node>> childSwitchIds = HwvtepHAUtil.getPSChildrenIdsForHAPSNode(psId);
48 for (InstanceIdentifier<Node> childSwitchId : childSwitchIds) {
49 haEventHandler.copyHAPSUpdateToChild(haPSNode, null/*haOriginal*/, childSwitchId, tx);
51 LOG.trace("Handle config ps node add {}", psId);
55 void onPsNodeUpdate(InstanceIdentifier<Node> key,
58 ReadWriteTransaction tx) throws InterruptedException, ExecutionException, ReadFailedException {
59 //copy the ps node data to children
60 String psId = haPSUpdated.getNodeId().getValue();
61 Set<InstanceIdentifier<Node>> childSwitchIds = HwvtepHAUtil.getPSChildrenIdsForHAPSNode(psId);
62 for (InstanceIdentifier<Node> childSwitchId : childSwitchIds) {
63 haEventHandler.copyHAPSUpdateToChild(haPSUpdated, haPSOriginal, childSwitchId, tx);
68 void onGlobalNodeUpdate(InstanceIdentifier<Node> key,
71 ReadWriteTransaction tx)
72 throws InterruptedException, ExecutionException, ReadFailedException {
73 //copy the ha node data to children taken care of the HAListeners
75 Set<InstanceIdentifier<Node>> childNodeIds = hwvtepHACache.getChildrenForHANode(key);
76 for (InstanceIdentifier<Node> haChildNodeId : childNodeIds) {
77 haEventHandler.copyHAGlobalUpdateToChild(haUpdated, haOriginal, haChildNodeId, tx);
83 void onPsNodeDelete(InstanceIdentifier<Node> key,
85 ReadWriteTransaction tx) throws ReadFailedException {
86 //delete ps children nodes
87 String psId = deletedPsNode.getNodeId().getValue();
88 Set<InstanceIdentifier<Node>> childPsIds = HwvtepHAUtil.getPSChildrenIdsForHAPSNode(psId);
89 for (InstanceIdentifier<Node> childPsId : childPsIds) {
90 HwvtepHAUtil.deleteNodeIfPresent(tx, CONFIGURATION, childPsId);
95 void onGlobalNodeDelete(InstanceIdentifier<Node> key,
97 ReadWriteTransaction tx)
98 throws ReadFailedException, ExecutionException, InterruptedException {
100 String deletedNodeId = key.firstKeyOf(Node.class).getNodeId().getValue();
101 Set<InstanceIdentifier<Node>> children = hwvtepHACache.getChildrenForHANode(key);
102 for (InstanceIdentifier<Node> childId : children) {
103 HwvtepHAUtil.deleteNodeIfPresent(tx, CONFIGURATION, childId);
105 HwvtepHAUtil.deletePSNodesOfNode(key, haNode, tx);