2 * Copyright (c) 2014 Cisco Systems, Inc. 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.southbound.ovsdb.transact;
10 import java.util.HashMap;
11 import java.util.HashSet;
13 import java.util.Map.Entry;
16 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbBridgeAugmentation;
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.InstanceIdentifier;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
23 public class TransactUtils {
24 private static final Logger LOG = LoggerFactory.getLogger(TransactUtils.class);
26 public static Map<InstanceIdentifier<Node>,OvsdbBridgeAugmentation> extractOvsdbManagedNodeCreate(
27 AsyncDataChangeEvent<InstanceIdentifier<?>, OvsdbBridgeAugmentation> changes) {
28 return extractOvsdbManagedNode(changes.getCreatedData());
31 public static Map<InstanceIdentifier<Node>,OvsdbBridgeAugmentation> extractOvsdbManagedNode(
32 AsyncDataChangeEvent<InstanceIdentifier<?>, OvsdbBridgeAugmentation> changes) {
33 return extractOvsdbManagedNode(changes.getUpdatedData());
36 public static Set<InstanceIdentifier<Node>> extractOvsdbManagedNodeRemoved(AsyncDataChangeEvent<InstanceIdentifier<?>, OvsdbBridgeAugmentation> changes) {
37 Set<InstanceIdentifier<Node>> result = new HashSet<InstanceIdentifier<Node>>();
38 for(InstanceIdentifier<?> iid : changes.getRemovedPaths()) {
39 if(iid.getTargetType().equals(OvsdbBridgeAugmentation.class)) {
40 @SuppressWarnings("unchecked") // Actually checked above
41 InstanceIdentifier<Node> iidn = (InstanceIdentifier<Node>)iid;
49 public static Map<InstanceIdentifier<Node>,OvsdbBridgeAugmentation> extractOvsdbManagedNode(
50 Map<InstanceIdentifier<?>, OvsdbBridgeAugmentation> changes) {
51 Map<InstanceIdentifier<Node>,OvsdbBridgeAugmentation> result = new HashMap<InstanceIdentifier<Node>,OvsdbBridgeAugmentation>();
52 for( Entry<InstanceIdentifier<?>, OvsdbBridgeAugmentation> created : changes.entrySet()) {
53 OvsdbBridgeAugmentation value = created.getValue();
54 Class<?> type = created.getKey().getTargetType();
55 if(type.equals(OvsdbBridgeAugmentation.class)) {
56 @SuppressWarnings("unchecked") // Actually checked above
57 InstanceIdentifier<Node> iid = (InstanceIdentifier<Node>) created.getKey();
58 OvsdbBridgeAugmentation ovsdbManagedNode = (OvsdbBridgeAugmentation) value;
59 result.put(iid, ovsdbManagedNode);