From b67d9e8f4c04b04db541ace4797db367106c10dd Mon Sep 17 00:00:00 2001 From: Mohamed El-Serngawy Date: Tue, 3 Nov 2015 18:10:15 -0500 Subject: [PATCH] delete UNI command Change-Id: I0b531a84ab9e0ac8c7bdab9ebc0013e1039efe13 Signed-off-by: Mohamed El-Serngawy --- .../unimgr/command/UniDeleteCommand.java | 62 +++++++++++++++++-- 1 file changed, 56 insertions(+), 6 deletions(-) diff --git a/impl/src/main/java/org/opendaylight/unimgr/command/UniDeleteCommand.java b/impl/src/main/java/org/opendaylight/unimgr/command/UniDeleteCommand.java index 9aa7ab85..c0e0ed82 100644 --- a/impl/src/main/java/org/opendaylight/unimgr/command/UniDeleteCommand.java +++ b/impl/src/main/java/org/opendaylight/unimgr/command/UniDeleteCommand.java @@ -7,18 +7,27 @@ */ package org.opendaylight.unimgr.command; -import java.util.Map; import java.util.Set; import org.opendaylight.controller.md.sal.binding.api.DataBroker; +import org.opendaylight.controller.md.sal.binding.api.WriteTransaction; import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent; +import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; +import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException; +import org.opendaylight.unimgr.impl.UnimgrConstants; +import org.opendaylight.unimgr.impl.UnimgrMapper; import org.opendaylight.unimgr.impl.UnimgrUtils; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.Uni; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbNodeRef; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.UniAugmentation; +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.DataObject; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.google.common.base.Optional; +import com.google.common.util.concurrent.CheckedFuture; + public class UniDeleteCommand extends AbstractDeleteCommand { private static final Logger LOG = LoggerFactory.getLogger(UniDeleteCommand.class); @@ -31,13 +40,54 @@ public class UniDeleteCommand extends AbstractDeleteCommand { @Override public void execute() { - Map, Uni> originalUnis = UnimgrUtils.extractOriginal(changes, Uni.class); - Set> removedUnis = UnimgrUtils.extractRemoved(changes, Uni.class); + Set> removedUnis = UnimgrUtils.extractRemoved(changes, UniAugmentation.class); + Set> removedNodes = UnimgrUtils.extractRemoved(changes, Node.class); if (!removedUnis.isEmpty()) { - for (InstanceIdentifier removedUniIid: removedUnis) { - LOG.info("Received a request to remove an UNI ", removedUniIid); + for (InstanceIdentifier removedUniIid: removedUnis) { + UniAugmentation uniAug = UnimgrUtils.read(dataBroker, LogicalDatastoreType.CONFIGURATION, removedUniIid); + if(uniAug != null){ + LOG.info("Uni Augmentation present."); + OvsdbNodeRef ovsNdRef = uniAug.getOvsdbNodeRef(); + InstanceIdentifier iidNode = (InstanceIdentifier) ovsNdRef.getValue(); + Optional optNode = UnimgrUtils.readNode(dataBroker, LogicalDatastoreType.CONFIGURATION, iidNode); + if (optNode.isPresent()) { + Node ovsdbNode = optNode.get(); + InstanceIdentifier iidBridgeNode = UnimgrMapper.getOvsdbBridgeNodeIID(ovsdbNode.getNodeId(), UnimgrConstants.DEFAULT_BRIDGE_NAME); + deleteNode(iidBridgeNode); + LOG.info("Received a request to remove a UNI BridgeNode ", iidBridgeNode); + } + deleteNode(iidNode); + LOG.info("Received a request to remove an UNI ", removedUniIid); + } } } + else {LOG.info("Removed UNIs is empty.");} + + if(!removedNodes.isEmpty()) { + for(InstanceIdentifier iidNode : removedNodes) { + Optional optNode = UnimgrUtils.readNode(dataBroker, LogicalDatastoreType.CONFIGURATION, iidNode); + if (optNode.isPresent()) { + Node ovsdbNode = optNode.get(); + InstanceIdentifier iidBridgeNode = UnimgrMapper.getOvsdbBridgeNodeIID(ovsdbNode.getNodeId(), UnimgrConstants.DEFAULT_BRIDGE_NAME); + deleteNode(iidBridgeNode); + LOG.info("Received a request to remove a BridgeNode ", iidBridgeNode); + } + deleteNode(iidNode); + LOG.info("Received a request to remove a Node ", iidNode); + } + } + else {LOG.info("Removed Nodes is empty.");} } + private void deleteNode(InstanceIdentifier iidNode) { + WriteTransaction transaction = dataBroker.newWriteOnlyTransaction(); + transaction.delete(LogicalDatastoreType.OPERATIONAL, iidNode); + transaction.delete(LogicalDatastoreType.CONFIGURATION, iidNode); + CheckedFuture future = transaction.submit(); + try { + future.checkedGet(); + } catch (TransactionCommitFailedException e) { + LOG.warn("Failed to delete iidNode {} {}", e.getMessage(), iidNode); + } + } } -- 2.36.6