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.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepLogicalSwitchAugmentation;
18 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
19 import org.opendaylight.yangtools.yang.binding.Augmentation;
20 import org.opendaylight.yangtools.yang.binding.DataObject;
21 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
25 public class TransactUtils {
26 private static final Logger LOG = LoggerFactory.getLogger(TransactUtils.class);
28 public static Node getCreated(DataObjectModification<Node> mod) {
29 if((mod.getModificationType() == ModificationType.WRITE)
30 && (mod.getDataBefore() == null)){
31 return mod.getDataAfter();
36 public static Node getRemoved(DataObjectModification<Node> mod) {
37 if(mod.getModificationType() == ModificationType.DELETE){
38 return mod.getDataBefore();
43 public static Node getUpdated(DataObjectModification<Node> mod) {
45 switch(mod.getModificationType()) {
46 case SUBTREE_MODIFIED:
47 node = mod.getDataAfter();
50 if(mod.getDataBefore() != null) {
51 node = mod.getDataAfter();
60 public static Node getOriginal(DataObjectModification<Node> mod) {
62 switch(mod.getModificationType()) {
63 case SUBTREE_MODIFIED:
64 node = mod.getDataBefore();
67 if(mod.getDataBefore() != null) {
68 node = mod.getDataBefore();
72 node = mod.getDataBefore();
80 public static Map<InstanceIdentifier<Node>, Node> extractCreatedOrUpdatedOrRemoved(
81 Collection<DataTreeModification<Node>> changes, Class<Node> class1) {
82 // TODO Auto-generated method stub
83 Map<InstanceIdentifier<Node>, Node> result = new HashMap<InstanceIdentifier<Node>, Node>();
84 for(DataTreeModification<Node> change : changes) {
85 final InstanceIdentifier<Node> key = change.getRootPath().getRootIdentifier();
86 final DataObjectModification<Node> mod = change.getRootNode();
87 Node created = getCreated(mod);
88 result.put(key, created);
89 Node updated = getUpdated(mod);
90 result.put(key, updated);
91 Node deleted = getRemoved(mod);
92 result.put(key, deleted);
98 public static <T extends Augmentation<Node>> Map<InstanceIdentifier<? extends DataObject>, T> extractCreated(
99 Collection<DataTreeModification<Node>> changes, Class<T> class1) {
100 // TODO Auto-generated method stub
101 Map<InstanceIdentifier<?>, T> result =
102 new HashMap<InstanceIdentifier<?>, T>();
103 if(changes != null && !changes.isEmpty()) {
104 for(DataTreeModification<Node> change : changes) {
105 final InstanceIdentifier<Node> key = change.getRootPath().getRootIdentifier();
106 final DataObjectModification<Node> mod = change.getRootNode();
107 Node created = getCreated(mod);
108 if(created != null) {
109 T logicalSwitch = created.getAugmentation(class1);
110 created.getKey().getNodeId().get
112 InstanceIdentifier<?> iid = change.getRootPath().getRootIdentifier()..augmentation(class1);
113 if(logicalSwitch != null) {
114 result.put(iid, logicalSwitch);