Fix build faliures due to OFPlugin checktyle fixes
[netvirt.git] / vpnservice / elanmanager / elanmanager-impl / src / main / java / org / opendaylight / netvirt / elan / l2gw / ha / listeners / HAConfigNodeListener.java
1 /*
2  * Copyright (c) 2017 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.netvirt.elan.l2gw.ha.listeners;
9
10 import static org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType.CONFIGURATION;
11
12 import java.util.Set;
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;
25
26 @Singleton
27 public class HAConfigNodeListener extends HwvtepNodeBaseListener {
28     private final IHAEventHandler haEventHandler;
29
30     @Inject
31     public HAConfigNodeListener(DataBroker db, HAEventHandler haEventHandler) throws Exception {
32         super(LogicalDatastoreType.CONFIGURATION, db);
33         this.haEventHandler = haEventHandler;
34     }
35
36     @Override
37     void onPsNodeAdd(InstanceIdentifier<Node> key,
38                      Node haPSNode,
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);
45         }
46         LOG.trace("Handle config ps node add {}", psId);
47     }
48
49     @Override
50     void onPsNodeUpdate(InstanceIdentifier<Node> key,
51                         Node haPSUpdated,
52                         Node haPSOriginal,
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);
59         }
60     }
61
62     @Override
63     void onGlobalNodeUpdate(InstanceIdentifier<Node> key,
64                             Node haUpdated,
65                             Node haOriginal,
66                             ReadWriteTransaction tx)
67             throws InterruptedException, ExecutionException, ReadFailedException {
68         //copy the ha node data to children taken care of the HAListeners
69         /*
70         Set<InstanceIdentifier<Node>> childNodeIds = hwvtepHACache.getChildrenForHANode(key);
71         for (InstanceIdentifier<Node> haChildNodeId : childNodeIds) {
72             haEventHandler.copyHAGlobalUpdateToChild(haUpdated, haOriginal, haChildNodeId, tx);
73         }
74         */
75     }
76
77     @Override
78     void onPsNodeDelete(InstanceIdentifier<Node> key,
79                         Node deletedPsNode,
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);
86         }
87     }
88
89     @Override
90     void onGlobalNodeDelete(InstanceIdentifier<Node> key,
91                             Node haNode,
92                             ReadWriteTransaction tx)
93             throws ReadFailedException, ExecutionException, InterruptedException {
94         //delete child nodes
95         Set<InstanceIdentifier<Node>> children = hwvtepHACache.getChildrenForHANode(key);
96         for (InstanceIdentifier<Node> childId : children) {
97             HwvtepHAUtil.deleteNodeIfPresent(tx, CONFIGURATION, childId);
98         }
99         HwvtepHAUtil.deletePSNodesOfNode(key, haNode, tx);
100     }
101 }