/* * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ package org.opendaylight.ovsdb.southbound.ovsdb.transact; import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Map.Entry; import java.util.Set; import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbBridgeAugmentation; import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class TransactUtils { private static final Logger LOG = LoggerFactory.getLogger(TransactUtils.class); public static Map,OvsdbBridgeAugmentation> extractOvsdbManagedNodeCreate( AsyncDataChangeEvent, OvsdbBridgeAugmentation> changes) { return extractOvsdbManagedNode(changes.getCreatedData()); } public static Map,OvsdbBridgeAugmentation> extractOvsdbManagedNode( AsyncDataChangeEvent, OvsdbBridgeAugmentation> changes) { return extractOvsdbManagedNode(changes.getUpdatedData()); } public static Set> extractOvsdbManagedNodeRemoved(AsyncDataChangeEvent, OvsdbBridgeAugmentation> changes) { Set> result = new HashSet>(); for(InstanceIdentifier iid : changes.getRemovedPaths()) { if(iid.getTargetType().equals(OvsdbBridgeAugmentation.class)) { @SuppressWarnings("unchecked") // Actually checked above InstanceIdentifier iidn = (InstanceIdentifier)iid; result.add(iidn); } } return result; } public static Map,OvsdbBridgeAugmentation> extractOvsdbManagedNode( Map, OvsdbBridgeAugmentation> changes) { Map,OvsdbBridgeAugmentation> result = new HashMap,OvsdbBridgeAugmentation>(); for( Entry, OvsdbBridgeAugmentation> created : changes.entrySet()) { OvsdbBridgeAugmentation value = created.getValue(); Class type = created.getKey().getTargetType(); if(type.equals(OvsdbBridgeAugmentation.class)) { @SuppressWarnings("unchecked") // Actually checked above InstanceIdentifier iid = (InstanceIdentifier) created.getKey(); OvsdbBridgeAugmentation ovsdbManagedNode = (OvsdbBridgeAugmentation) value; result.put(iid, ovsdbManagedNode); } } return result; } }