2 * Copyright (c) 2015 China Telecom Beijing Research Institute 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.ovsdb.hwvtepsouthbound.transact;
10 import java.util.Collection;
11 import java.util.HashMap;
14 import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
15 import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
16 import org.opendaylight.controller.md.sal.binding.api.DataObjectModification.ModificationType;
17 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
18 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
22 public class TransactUtils {
23 private static final Logger LOG = LoggerFactory.getLogger(TransactUtils.class);
25 public static Node getCreated(DataObjectModification<Node> mod) {
26 if((mod.getModificationType() == ModificationType.WRITE)
27 && (mod.getDataBefore() == null)){
28 return mod.getDataAfter();
33 public static Node getRemoved(DataObjectModification<Node> mod) {
34 if(mod.getModificationType() == ModificationType.DELETE){
35 return mod.getDataBefore();
40 public static Node getUpdated(DataObjectModification<Node> mod) {
42 switch(mod.getModificationType()) {
43 case SUBTREE_MODIFIED:
44 node = mod.getDataAfter();
47 if(mod.getDataBefore() != null) {
48 node = mod.getDataAfter();
57 public static Node getOriginal(DataObjectModification<Node> mod) {
59 switch(mod.getModificationType()) {
60 case SUBTREE_MODIFIED:
61 node = mod.getDataBefore();
64 if(mod.getDataBefore() != null) {
65 node = mod.getDataBefore();
69 node = mod.getDataBefore();
77 //TODO: change this function to be generic
78 public static Map<InstanceIdentifier<Node>, Node> extractCreatedOrUpdatedOrRemoved(
79 Collection<DataTreeModification<Node>> changes, Class<Node> class1) {
80 Map<InstanceIdentifier<Node>, Node> result = new HashMap<InstanceIdentifier<Node>, Node>();
81 for(DataTreeModification<Node> change : changes) {
82 final InstanceIdentifier<Node> key = change.getRootPath().getRootIdentifier();
83 final DataObjectModification<Node> mod = change.getRootNode();
84 Node created = getCreated(mod);
85 if (created != null) {
86 result.put(key, created);
88 Node updated = getUpdated(mod);
89 if (updated != null) {
90 result.put(key, updated);
92 Node deleted = getRemoved(mod);
93 if (deleted != null) {
94 result.put(key, deleted);
101 public static <T extends Augmentation<Node>> Map<InstanceIdentifier<? extends DataObject>, T> extractCreated(
102 Collection<DataTreeModification<Node>> changes, Class<T> class1) {
103 // TODO Auto-generated method stub
104 Map<InstanceIdentifier<?>, T> result =
105 new HashMap<InstanceIdentifier<?>, T>();
106 if(changes != null && !changes.isEmpty()) {
107 for(DataTreeModification<Node> change : changes) {
108 final InstanceIdentifier<Node> key = change.getRootPath().getRootIdentifier();
109 final DataObjectModification<Node> mod = change.getRootNode();
110 Node created = getCreated(mod);
111 if(created != null) {
112 T logicalSwitch = created.getAugmentation(class1);
113 created.getKey().getNodeId().get
115 InstanceIdentifier<?> iid = change.getRootPath().getRootIdentifier()..augmentation(class1);
116 if(logicalSwitch != null) {
117 result.put(iid, logicalSwitch);