Bulk merge of l2gw changes
[netvirt.git] / elanmanager / impl / src / main / java / org / opendaylight / netvirt / elan / l2gw / ha / handlers / HAEventHandler.java
1 /*
2  * Copyright (c) 2016 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.handlers;
9
10 import javax.inject.Inject;
11 import javax.inject.Singleton;
12 import org.opendaylight.mdsal.binding.api.DataBroker;
13 import org.opendaylight.mdsal.binding.api.DataObjectModification;
14 import org.opendaylight.mdsal.binding.util.Datastore.Configuration;
15 import org.opendaylight.mdsal.binding.util.Datastore.Operational;
16 import org.opendaylight.mdsal.binding.util.ManagedNewTransactionRunner;
17 import org.opendaylight.mdsal.binding.util.ManagedNewTransactionRunnerImpl;
18 import org.opendaylight.mdsal.binding.util.TypedReadWriteTransaction;
19 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
20 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
21
22 @Singleton
23 public class HAEventHandler implements IHAEventHandler {
24
25     private final ConfigNodeUpdatedHandler configNodeUpdatedHandler = new ConfigNodeUpdatedHandler();
26     private final OpNodeUpdatedHandler opNodeUpdatedHandler = new OpNodeUpdatedHandler();
27     private final ManagedNewTransactionRunner txRunner;
28
29     @Inject
30     public HAEventHandler(DataBroker db) {
31         this.txRunner = new ManagedNewTransactionRunnerImpl(db);
32     }
33
34     @Override
35     public void copyChildGlobalOpUpdateToHAParent(InstanceIdentifier<Node> haPath,
36                                                   DataObjectModification<Node> mod,
37                                                   TypedReadWriteTransaction<Operational> tx) {
38         if (haPath == null) {
39             return;
40         }
41         opNodeUpdatedHandler.copyChildGlobalOpUpdateToHAParent(haPath, mod, tx, txRunner);
42     }
43
44     @Override
45     public void copyChildPsOpUpdateToHAParent(Node updatedSrcPSNode,
46                                               InstanceIdentifier<Node> haPath,
47                                               DataObjectModification<Node> mod,
48                                               TypedReadWriteTransaction<Operational> tx) {
49         if (haPath == null) {
50             return;
51         }
52         opNodeUpdatedHandler.copyChildPsOpUpdateToHAParent(updatedSrcPSNode, haPath, mod, tx, txRunner);
53     }
54
55     @Override
56     public void copyHAPSUpdateToChild(InstanceIdentifier<Node> haChildNodeId,
57                                       DataObjectModification<Node> mod,
58                                       TypedReadWriteTransaction<Configuration> tx) {
59         if (haChildNodeId == null) {
60             return;
61         }
62         configNodeUpdatedHandler.copyHAPSUpdateToChild(haChildNodeId, mod, tx, txRunner);
63     }
64
65     @Override
66     public void copyHAGlobalUpdateToChild(InstanceIdentifier<Node> haChildNodeId,
67                                           DataObjectModification<Node> mod,
68                                           TypedReadWriteTransaction<Configuration> tx) {
69         if (haChildNodeId == null) {
70             return;
71         }
72         configNodeUpdatedHandler.copyHAGlobalUpdateToChild(haChildNodeId, mod, tx, txRunner);
73     }
74
75 }