Bug 6170 + Bug 5919 - made FRS cluster-aware
[openflowplugin.git] / applications / forwardingrules-sync / src / main / java / org / opendaylight / openflowplugin / applications / frsync / util / ModificationUtil.java
1 /**
2  * Copyright (c) 2016 Cisco Systems, Inc. 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.openflowplugin.applications.frsync.util;
10
11 import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
12 import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
16
17 /**
18  * Basic {@link DataTreeModification} related tools.
19  */
20 public class ModificationUtil {
21     public static String nodeIdValue(DataTreeModification<Node> modification) {
22         final NodeId nodeId = nodeId(modification);
23
24         if (nodeId == null) {
25             return null;
26         }
27
28         return nodeId.getValue();
29     }
30
31     public static NodeId nodeId(DataTreeModification<Node> modification) {
32         final DataObjectModification<Node> rootNode = modification.getRootNode();
33         final Node dataAfter = rootNode.getDataAfter();
34
35         if (dataAfter != null) {
36             return dataAfter.getId();
37         }
38
39         final Node dataBefore = rootNode.getDataBefore();
40         if (dataBefore != null) {
41             return dataBefore.getId();
42         }
43
44         return null;
45     }
46
47     public static FlowCapableNode flowCapableNodeAfter(DataTreeModification<Node> modification) {
48         final Node dataAfter = modification.getRootNode().getDataAfter();
49         if (dataAfter == null) {
50             return null;
51         }
52         return dataAfter.getAugmentation(FlowCapableNode.class);
53     }
54 }