bug 6578 added mdsal read retry
[ovsdb.git] / hwvtepsouthbound / hwvtepsouthbound-impl / src / main / java / org / opendaylight / ovsdb / hwvtepsouthbound / transact / HwvtepOperationalState.java
1 /*
2  * Copyright (c) 2015, 2017 China Telecom Beijing Research Institute 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
9 package org.opendaylight.ovsdb.hwvtepsouthbound.transact;
10
11 import com.google.common.base.Optional;
12 import com.google.common.base.Preconditions;
13 import org.apache.commons.lang3.tuple.Pair;
14 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
15 import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
16 import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
17 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
18 import org.opendaylight.ovsdb.hwvtepsouthbound.HwvtepConnectionInstance;
19 import org.opendaylight.ovsdb.hwvtepsouthbound.HwvtepDeviceInfo;
20 import org.opendaylight.ovsdb.hwvtepsouthbound.HwvtepSouthboundUtil;
21 import org.opendaylight.ovsdb.lib.notation.UUID;
22 import org.opendaylight.ovsdb.utils.mdsal.utils.MdsalUtils;
23 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.EncapsulationTypeBase;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalAugmentation;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepNodeName;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepPhysicalLocatorAugmentation;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepPhysicalPortAugmentation;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.PhysicalSwitchAugmentation;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.Acls;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.AclsKey;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.LocalMcastMacs;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.LocalMcastMacsKey;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.LocalUcastMacs;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.LocalUcastMacsKey;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.LogicalRouters;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.LogicalRoutersKey;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.LogicalSwitches;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.LogicalSwitchesKey;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.RemoteMcastMacs;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.RemoteMcastMacsKey;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.RemoteUcastMacs;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.RemoteUcastMacsKey;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.Switches;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.physical._switch.attributes.Tunnels;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.physical._switch.attributes.TunnelsKey;
47 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
48 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint;
49 import org.opendaylight.yangtools.yang.binding.Identifiable;
50 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
51 import org.slf4j.Logger;
52 import org.slf4j.LoggerFactory;
53
54 import java.util.Collection;
55 import java.util.Collections;
56 import java.util.HashMap;
57 import java.util.List;
58 import java.util.Map;
59 import java.util.Map.Entry;
60 import java.util.Set;
61 import java.util.concurrent.ConcurrentHashMap;
62
63 //TODO: need to be optimized, get entry by iid not name
64 public class HwvtepOperationalState {
65
66     private static final Logger LOG = LoggerFactory.getLogger(HwvtepOperationalState.class);
67
68     private Map<InstanceIdentifier<Node>, Node> operationalNodes = new HashMap<>();
69     private ReadWriteTransaction transaction;
70     HashMap<InstanceIdentifier<TerminationPoint>, UUID> inflightLocators = new HashMap<>();
71     private HwvtepDeviceInfo deviceInfo;
72     private HwvtepConnectionInstance connectionInstance;
73     private Map<Class<? extends Identifiable>, Map<InstanceIdentifier, UUID>> currentTxUUIDs = new ConcurrentHashMap<>();
74     private Map<Class<? extends Identifiable>, Map<InstanceIdentifier, Boolean>> currentTxDeletedKeys = new ConcurrentHashMap<>();
75
76     /* stores the modified and deleted data for each child type of each node id
77        Map<nodeid , Pair < updated, deleted >
78        each updated/ deleted contains Map < child type, List<ChildData>>
79        child type is the child of hwvtep Global augmentation
80      */
81     private Map<InstanceIdentifier<Node>,
82             Pair<Map<Class<? extends Identifiable>, List<Identifiable>>,
83                     Map<Class<? extends Identifiable>, List<Identifiable>>>> modifiedData = new HashMap<>();
84     private boolean inReconciliation = false;
85     private final DataBroker db;
86     private final Collection<DataTreeModification<Node>> changes;
87
88     public HwvtepOperationalState(DataBroker db, HwvtepConnectionInstance connectionInstance,
89                                   Collection<DataTreeModification<Node>> changes) {
90         this.connectionInstance = connectionInstance;
91         this.deviceInfo = connectionInstance.getDeviceInfo();
92         this.db = db;
93         this.changes = changes;
94         this.transaction = db.newReadWriteTransaction();
95     }
96
97     public HwvtepOperationalState(HwvtepConnectionInstance connectionInstance) {
98         this.connectionInstance = connectionInstance;
99         this.deviceInfo = connectionInstance.getDeviceInfo();
100         this.db = connectionInstance.getDataBroker();
101         this.changes = null;
102         transaction = connectionInstance.getDataBroker().newReadWriteTransaction();
103         Optional<Node> readNode = new MdsalUtils(db).readOptional(LogicalDatastoreType.OPERATIONAL,
104                 connectionInstance.getInstanceIdentifier());
105         if (readNode.isPresent()) {
106             operationalNodes.put(connectionInstance.getInstanceIdentifier(), readNode.get());
107         }
108     }
109
110     public HwvtepOperationalState(final DataBroker db,
111                                   final HwvtepConnectionInstance connectionInstance,
112                                   final Collection<DataTreeModification<Node>> changes,
113                                   final Node globalOperNode,
114                                   final Node psNode) {
115         this(db, connectionInstance, changes);
116         operationalNodes.put(connectionInstance.getInstanceIdentifier(), globalOperNode);
117         HwvtepGlobalAugmentation globalAugmentation = globalOperNode.getAugmentation(HwvtepGlobalAugmentation.class);
118         if (globalAugmentation != null) {
119             if (!HwvtepSouthboundUtil.isEmpty(globalAugmentation.getSwitches())) {
120                 operationalNodes.put((InstanceIdentifier<Node>)
121                         globalAugmentation.getSwitches().get(0).getSwitchRef().getValue(), psNode);
122             }
123         }
124     }
125
126     public void readOperationalNodes() {
127         if (inReconciliation) {
128             return;
129         }
130         if (changes == null) {
131             LOG.warn("Could not read operational nodes for {} as changes is",
132                     connectionInstance.getNodeId().getValue());
133             return;
134         }
135         Map<InstanceIdentifier<Node>, Node> nodeCreateOrUpdate =
136                 TransactUtils.extractCreatedOrUpdatedOrRemoved(changes, Node.class);
137         if (nodeCreateOrUpdate != null) {
138             transaction = db.newReadWriteTransaction();
139             for (Entry<InstanceIdentifier<Node>, Node> entry: nodeCreateOrUpdate.entrySet()) {
140                 Optional<Node> readNode = new MdsalUtils(db).readOptional(LogicalDatastoreType.OPERATIONAL,
141                         entry.getKey());
142                 //add related globalNode or physicalSwitchNode to operationalNodes map
143                 //for example, when creating physical port, logical switch is needed
144                 //but logical switch is in HwvtepGlobalAugmentation rather than PhysicalSwitchAugmentation
145                 if (readNode.isPresent()) {
146                     operationalNodes.put(entry.getKey(), readNode.get());
147                     HwvtepGlobalAugmentation hgAugmentation = readNode.get().getAugmentation(HwvtepGlobalAugmentation.class);
148                     PhysicalSwitchAugmentation psAugmentation = readNode.get().getAugmentation(PhysicalSwitchAugmentation.class);
149                     if (hgAugmentation != null && hgAugmentation.getSwitches() != null) {
150                         for (Switches pswitch : hgAugmentation.getSwitches()) {
151                             @SuppressWarnings("unchecked")
152                             InstanceIdentifier<Node> psNodeIid = (InstanceIdentifier<Node>) pswitch.getSwitchRef().getValue();
153                             Optional<Node> psNode = new MdsalUtils(db).readOptional(LogicalDatastoreType.OPERATIONAL,
154                                     psNodeIid);
155                             if (psNode.isPresent()) {
156                                 operationalNodes.put(psNodeIid, psNode.get());
157                             }
158                         }
159                     }
160                     if (psAugmentation != null) {
161                         @SuppressWarnings("unchecked")
162                         InstanceIdentifier<Node> hgNodeIid = (InstanceIdentifier<Node>) psAugmentation.getManagedBy().getValue();
163                         Optional<Node> hgNode = new MdsalUtils(db).readOptional(
164                                 LogicalDatastoreType.OPERATIONAL, hgNodeIid);
165                         if (hgNode.isPresent()) {
166                             operationalNodes.put(hgNodeIid, hgNode.get());
167                         }
168                     }
169                 }
170             }
171         }
172     }
173
174     public Optional<Node> getGlobalNode(InstanceIdentifier<?> iid) {
175         InstanceIdentifier<Node> nodeIid = iid.firstIdentifierOf(Node.class);
176         return Optional.fromNullable(operationalNodes.get(nodeIid));
177     }
178
179     public Optional<HwvtepGlobalAugmentation> getHwvtepGlobalAugmentation(InstanceIdentifier<?> iid) {
180         Preconditions.checkNotNull(iid);
181         Optional<Node> nodeOptional = getGlobalNode(iid);
182         if (nodeOptional.isPresent()) {
183             return Optional.fromNullable(nodeOptional.get().getAugmentation(HwvtepGlobalAugmentation.class));
184         }
185         return Optional.absent();
186     }
187
188     public Optional<PhysicalSwitchAugmentation> getPhysicalSwitchAugmentation(InstanceIdentifier<?> iid) {
189         Preconditions.checkNotNull(iid);
190         Optional<Node> nodeOptional = getGlobalNode(iid);
191         if (nodeOptional.isPresent()) {
192             return Optional.fromNullable(nodeOptional.get().getAugmentation(PhysicalSwitchAugmentation.class));
193         }
194         return Optional.absent();
195     }
196
197     public Optional<List<TerminationPoint>> getTerminationPointList(InstanceIdentifier<?> iid) {
198         Preconditions.checkNotNull(iid);
199         Optional<Node> nodeOptional = getGlobalNode(iid);
200         if (nodeOptional.isPresent() && nodeOptional.get().getTerminationPoint() != null) {
201             return Optional.fromNullable(nodeOptional.get().getTerminationPoint());
202         }
203         return Optional.absent();
204     }
205
206     public Optional<LogicalSwitches> getLogicalSwitches(InstanceIdentifier<?> iid, LogicalSwitchesKey logicalSwitchesKey) {
207         Preconditions.checkNotNull(iid);
208         Optional<HwvtepGlobalAugmentation> nodeOptional = getHwvtepGlobalAugmentation(iid);
209         if (nodeOptional.isPresent()) {
210             HwvtepGlobalAugmentation hgAugmentation = nodeOptional.get();
211             List<LogicalSwitches> lswitchList = null;
212             if (hgAugmentation != null) {
213                 lswitchList = hgAugmentation.getLogicalSwitches();
214             }
215             if (lswitchList != null) {
216                 for (LogicalSwitches lswitch: lswitchList) {
217                     if (lswitch.getKey().equals(logicalSwitchesKey)) {
218                         return Optional.fromNullable(lswitch);
219                     }
220                 }
221             }
222         }
223         return Optional.absent();
224     }
225
226     public Optional<Tunnels> getTunnels(InstanceIdentifier<?> iid, TunnelsKey tunnelsKey) {
227         Preconditions.checkNotNull(iid);
228         Optional<PhysicalSwitchAugmentation> psOptional = getPhysicalSwitchAugmentation(iid);
229         if (psOptional.isPresent()) {
230             PhysicalSwitchAugmentation psAugmentation = psOptional.get();
231             List<Tunnels> tunnelList = null;
232             if (psAugmentation != null) {
233                 tunnelList = psAugmentation.getTunnels();
234             }
235             if (tunnelList != null) {
236                 for (Tunnels tunnel: tunnelList) {
237                     if (tunnel.getKey().equals(tunnelsKey)) {
238                         return Optional.fromNullable(tunnel);
239                     }
240                 }
241             }
242         }
243         return Optional.absent();
244     }
245
246     public Optional<HwvtepPhysicalPortAugmentation> getPhysicalPortAugmentation(InstanceIdentifier<?> iid,
247             HwvtepNodeName hwvtepNodeName) {
248         Preconditions.checkNotNull(iid);
249         Optional<List<TerminationPoint>> nodeOptional = getTerminationPointList(iid);
250         if (nodeOptional.isPresent()) {
251             List<TerminationPoint> tpList = nodeOptional.get();
252             for (TerminationPoint tp : tpList) {
253                 HwvtepPhysicalPortAugmentation hppAugmentation = tp.getAugmentation(HwvtepPhysicalPortAugmentation.class);
254                 if (hppAugmentation != null && hppAugmentation.getHwvtepNodeName().equals(hwvtepNodeName)) {
255                     return Optional.fromNullable(hppAugmentation);
256                 }
257             }
258         }
259         return Optional.absent();
260     }
261
262     public Optional<HwvtepPhysicalLocatorAugmentation> getPhysicalLocatorAugmentation(InstanceIdentifier<?> iid,
263             IpAddress dstIp, Class<? extends EncapsulationTypeBase> encapType) {
264         Preconditions.checkNotNull(iid);
265         Optional<List<TerminationPoint>> nodeOptional = getTerminationPointList(iid);
266         if (nodeOptional.isPresent()) {
267             List<TerminationPoint> tpList = nodeOptional.get();
268             for (TerminationPoint tp : tpList) {
269                 HwvtepPhysicalLocatorAugmentation hppAugmentation = tp.getAugmentation(HwvtepPhysicalLocatorAugmentation.class);
270                 if (hppAugmentation != null && hppAugmentation.getDstIp().equals(dstIp)
271                         && hppAugmentation.getEncapsulationType().equals(encapType)) {
272                     return Optional.fromNullable(hppAugmentation);
273                 }
274             }
275         }
276         return Optional.absent();
277     }
278
279     public Optional<LocalMcastMacs> getLocalMcastMacs(InstanceIdentifier<?> iid, LocalMcastMacsKey key) {
280         Preconditions.checkNotNull(iid);
281         Optional<HwvtepGlobalAugmentation> nodeOptional = getHwvtepGlobalAugmentation(iid);
282         if (nodeOptional.isPresent()) {
283             HwvtepGlobalAugmentation hgAugmentation = nodeOptional.get();
284             List<LocalMcastMacs> macList = null;
285             if (hgAugmentation != null) {
286                 macList = hgAugmentation.getLocalMcastMacs();
287             }
288             if (macList != null) {
289                 for (LocalMcastMacs mac: macList) {
290                     if (mac.getKey().equals(key)) {
291                         return Optional.fromNullable(mac);
292                     }
293                 }
294             }
295         }
296         return Optional.absent();
297     }
298
299     public Optional<RemoteMcastMacs> getRemoteMcastMacs(InstanceIdentifier<?> iid, RemoteMcastMacsKey key) {
300         Preconditions.checkNotNull(iid);
301         Optional<HwvtepGlobalAugmentation> nodeOptional = getHwvtepGlobalAugmentation(iid);
302         if (nodeOptional.isPresent()) {
303             HwvtepGlobalAugmentation hgAugmentation = nodeOptional.get();
304             List<RemoteMcastMacs> macList = null;
305             if (hgAugmentation != null) {
306                 macList = hgAugmentation.getRemoteMcastMacs();
307             }
308             if (macList != null) {
309                 for (RemoteMcastMacs mac: macList) {
310                     if (mac.getKey().equals(key)) {
311                         return Optional.fromNullable(mac);
312                     }
313                 }
314             }
315         }
316         return Optional.absent();
317     }
318
319     public Optional<LocalUcastMacs> getLocalUcastMacs(InstanceIdentifier<?> iid, LocalUcastMacsKey key) {
320         Preconditions.checkNotNull(iid);
321         Optional<HwvtepGlobalAugmentation> nodeOptional = getHwvtepGlobalAugmentation(iid);
322         if (nodeOptional.isPresent()) {
323             HwvtepGlobalAugmentation hgAugmentation = nodeOptional.get();
324             List<LocalUcastMacs> macList = null;
325             if (hgAugmentation != null) {
326                 macList = hgAugmentation.getLocalUcastMacs();
327             }
328             if (macList != null) {
329                 for (LocalUcastMacs mac: macList) {
330                     if (mac.getKey().equals(key)) {
331                         return Optional.fromNullable(mac);
332                     }
333                 }
334             }
335         }
336         return Optional.absent();
337     }
338
339     public Optional<RemoteUcastMacs> getRemoteUcastMacs(InstanceIdentifier<?> iid, RemoteUcastMacsKey key) {
340         Preconditions.checkNotNull(iid);
341         Optional<HwvtepGlobalAugmentation> nodeOptional = getHwvtepGlobalAugmentation(iid);
342         if (nodeOptional.isPresent()) {
343             HwvtepGlobalAugmentation hgAugmentation = nodeOptional.get();
344             List<RemoteUcastMacs> macList = null;
345             if (hgAugmentation != null) {
346                 macList = hgAugmentation.getRemoteUcastMacs();
347             }
348             if (macList != null) {
349                 for (RemoteUcastMacs mac: macList) {
350                     if (mac.getKey().equals(key)) {
351                         return Optional.fromNullable(mac);
352                     }
353                 }
354             }
355         }
356         return Optional.absent();
357     }
358
359     public Optional<LogicalRouters> getLogicalRouters(final InstanceIdentifier<?> iid,
360             final LogicalRoutersKey logicalRoutersKey) {
361         Preconditions.checkNotNull(iid);
362         Optional<HwvtepGlobalAugmentation> nodeOptional = getHwvtepGlobalAugmentation(iid);
363         if (nodeOptional.isPresent()) {
364             HwvtepGlobalAugmentation hgAugmentation = nodeOptional.get();
365             if (hgAugmentation != null && hgAugmentation.getLogicalRouters() != null) {
366                 for (LogicalRouters lrouter: hgAugmentation.getLogicalRouters()) {
367                     if (lrouter.getKey().equals(logicalRoutersKey)) {
368                         return Optional.fromNullable(lrouter);
369                     }
370                 }
371             }
372         }
373         return Optional.absent();
374     }
375
376     public Optional<HwvtepPhysicalLocatorAugmentation> getPhysicalLocatorAugmentation(InstanceIdentifier<TerminationPoint> iid) {
377         Optional<TerminationPoint> tp = new MdsalUtils(db).readOptional(LogicalDatastoreType.OPERATIONAL, iid);
378         if (tp.isPresent()) {
379             return Optional.fromNullable(tp.get().getAugmentation(HwvtepPhysicalLocatorAugmentation.class));
380         }
381         return Optional.absent();
382     }
383
384     public Optional<LogicalSwitches> getLogicalSwitches(InstanceIdentifier<LogicalSwitches> iid) {
385         Optional<LogicalSwitches> lswitch = new MdsalUtils(db).readOptional(LogicalDatastoreType.OPERATIONAL, iid);
386         return lswitch;
387     }
388
389     public Optional<Tunnels> getTunnels(InstanceIdentifier<Tunnels> iid) {
390         Optional<Tunnels> tunnels = new MdsalUtils(db).readOptional(LogicalDatastoreType.OPERATIONAL, iid);
391         return tunnels;
392     }
393
394     public Optional<Acls> getAcls(InstanceIdentifier<Acls> iid) {
395         Optional<Acls> acl = new MdsalUtils(db).readOptional(LogicalDatastoreType.OPERATIONAL, iid);
396         return acl;
397     }
398
399     public ReadWriteTransaction getReadWriteTransaction() {
400         return transaction;
401     }
402
403     public void setPhysicalLocatorInFlight(InstanceIdentifier<TerminationPoint> iid,
404                                            UUID uuid) {
405         inflightLocators.put(iid, uuid);
406     }
407
408     public UUID getPhysicalLocatorInFlight(InstanceIdentifier<TerminationPoint> iid) {
409         return inflightLocators.get(iid);
410     }
411
412     public HwvtepConnectionInstance getConnectionInstance() {
413         return connectionInstance;
414     }
415
416     public HwvtepDeviceInfo getDeviceInfo() {
417         return deviceInfo;
418     }
419
420     public void updateCurrentTxData(Class<? extends Identifiable> cls, InstanceIdentifier key, UUID uuid) {
421         HwvtepSouthboundUtil.updateData(currentTxUUIDs, cls, key, uuid);
422     }
423
424     public void updateCurrentTxDeleteData(Class<? extends Identifiable> cls, InstanceIdentifier key) {
425         HwvtepSouthboundUtil.updateData(currentTxDeletedKeys, cls, key, Boolean.TRUE);
426     }
427
428     public UUID getUUIDFromCurrentTx(Class<? extends Identifiable> cls, InstanceIdentifier key) {
429         return HwvtepSouthboundUtil.getData(currentTxUUIDs, cls, key);
430     }
431
432     public boolean isKeyPartOfCurrentTx(Class<? extends Identifiable> cls, InstanceIdentifier key) {
433         return HwvtepSouthboundUtil.containsKey(currentTxUUIDs, cls, key);
434     }
435
436     public Set<InstanceIdentifier> getDeletedKeysInCurrentTx(Class<? extends Identifiable> cls) {
437         if (currentTxDeletedKeys.containsKey(cls)) {
438             return currentTxDeletedKeys.get(cls).keySet();
439         }
440         return Collections.EMPTY_SET;
441     }
442
443     public List<? extends Identifiable> getUpdatedData(final InstanceIdentifier<Node> key,
444                                                        final Class<? extends Identifiable> cls) {
445         List<Identifiable> result = null;
446         if (modifiedData.get(key) != null && modifiedData.get(key).getLeft() != null) {
447             result = modifiedData.get(key).getLeft().get(cls);
448         }
449         if (result == null) {
450             result = Collections.EMPTY_LIST;
451         }
452         return result;
453     }
454
455     public List<? extends Identifiable> getDeletedData(final InstanceIdentifier<Node> key,
456                                                        final Class<? extends Identifiable> cls) {
457         List<Identifiable> result = null;
458         if (modifiedData.get(key) != null && modifiedData.get(key).getRight() != null) {
459             result = modifiedData.get(key).getRight().get(cls);
460         }
461         if (result == null) {
462             result = Collections.EMPTY_LIST;
463         }
464         return result;
465     }
466
467     public void setModifiedData(final Map<InstanceIdentifier<Node>,
468             Pair<Map<Class<? extends Identifiable>, List<Identifiable>>,
469                     Map<Class<? extends Identifiable>, List<Identifiable>>>> modifiedData) {
470         this.modifiedData = modifiedData;
471     }
472
473     public boolean isInReconciliation() {
474         return inReconciliation;
475     }
476
477     public void setInReconciliation(boolean inReconciliation) {
478         this.inReconciliation = inReconciliation;
479     }
480
481     public DataBroker getDataBroker() {
482         return db;
483     }
484
485
486     public void clearIntransitKeys() {
487         currentTxUUIDs.forEach( (cls, map) -> {
488             map.forEach( (iid, uuid) -> deviceInfo.clearInTransit(cls, iid));
489         });
490         currentTxDeletedKeys.forEach( (cls, map) -> {
491             map.forEach( (iid, val) -> deviceInfo.clearInTransit(cls, iid));
492         });
493         currentTxUUIDs.clear();
494         currentTxDeletedKeys.clear();
495         deviceInfo.onOperDataAvailable();
496     }
497 }