From: melserngawy Date: Fri, 6 Nov 2015 22:00:13 +0000 (-0500) Subject: fix uni delete and merge conflict X-Git-Tag: release/beryllium~36 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=7b50b2ca0a45f28afeeeee45102e2a4a14d7c159;p=unimgr.git fix uni delete and merge conflict Change-Id: I0105dd184c66b5889848d017a47f3520424631d6 Signed-off-by: melserngawy --- 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 9d06ba27..ad36ec55 100644 --- a/impl/src/main/java/org/opendaylight/unimgr/command/UniDeleteCommand.java +++ b/impl/src/main/java/org/opendaylight/unimgr/command/UniDeleteCommand.java @@ -10,10 +10,9 @@ package org.opendaylight.unimgr.command; 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.ovsdb.rev150105.OvsdbNodeRef; @@ -25,7 +24,6 @@ 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 { @@ -40,53 +38,27 @@ public class UniDeleteCommand extends AbstractDeleteCommand { @Override public void execute() { Set> removedUnis = UnimgrUtils.extractRemoved(changes, UniAugmentation.class); - Set> removedNodes = UnimgrUtils.extractRemoved(changes, Node.class); if (!removedUnis.isEmpty()) { for (InstanceIdentifier removedUniIid: removedUnis) { - UniAugmentation uniAug = UnimgrUtils.read(dataBroker, LogicalDatastoreType.CONFIGURATION, removedUniIid); - if(uniAug != null){ - LOG.trace("Uni Augmentation present."); - OvsdbNodeRef ovsdbNodeRef = uniAug.getOvsdbNodeRef(); - InstanceIdentifier ovsdbIid = ovsdbNodeRef.getValue().firstIdentifierOf(Node.class); - Optional optNode = UnimgrUtils.readNode(dataBroker, LogicalDatastoreType.CONFIGURATION, ovsdbIid); + UniAugmentation uniAug = UnimgrUtils.read(dataBroker, LogicalDatastoreType.OPERATIONAL, removedUniIid); + if(uniAug != null) { + LOG.info("Uni Augmentation present."); + OvsdbNodeRef ovsNdRef = uniAug.getOvsdbNodeRef(); + InstanceIdentifier iidNode = (InstanceIdentifier) ovsNdRef.getValue(); + Optional optNode = UnimgrUtils.readNode(dataBroker, LogicalDatastoreType.OPERATIONAL, iidNode); if (optNode.isPresent()) { Node ovsdbNode = optNode.get(); InstanceIdentifier iidBridgeNode = UnimgrMapper.getOvsdbBridgeNodeIid(ovsdbNode); - deleteNode(iidBridgeNode); + UnimgrUtils.deletePath(dataBroker, iidBridgeNode); LOG.info("Received a request to remove a UNI BridgeNode ", iidBridgeNode); } - deleteNode(ovsdbIid); + UnimgrUtils.deletePath(dataBroker, iidNode); LOG.info("Received a request to remove an UNI ", removedUniIid); + UnimgrUtils.deletePath(dataBroker, LogicalDatastoreType.OPERATIONAL, removedUniIid); } + else {LOG.info("Received Uni Augmentation is null", 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); - 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); - } } } diff --git a/impl/src/main/java/org/opendaylight/unimgr/impl/UnimgrUtils.java b/impl/src/main/java/org/opendaylight/unimgr/impl/UnimgrUtils.java index e03a8ad9..ddba37f0 100644 --- a/impl/src/main/java/org/opendaylight/unimgr/impl/UnimgrUtils.java +++ b/impl/src/main/java/org/opendaylight/unimgr/impl/UnimgrUtils.java @@ -352,6 +352,29 @@ public class UnimgrUtils { return transaction.submit(); } + public static void deletePath(DataBroker dataBroker, LogicalDatastoreType dataStoreType, InstanceIdentifier iid) { + WriteTransaction transaction = dataBroker.newWriteOnlyTransaction(); + transaction.delete(dataStoreType, iid); + CheckedFuture future = transaction.submit(); + try { + future.checkedGet(); + } catch (TransactionCommitFailedException e) { + LOG.warn("Failed to delete iidNode {} {}", e.getMessage(), iid); + } + } + + public static void deletePath(DataBroker dataBroker, InstanceIdentifier iid) { + WriteTransaction transaction = dataBroker.newWriteOnlyTransaction(); + transaction.delete(LogicalDatastoreType.OPERATIONAL, iid); + transaction.delete(LogicalDatastoreType.CONFIGURATION, iid); + CheckedFuture future = transaction.submit(); + try { + future.checkedGet(); + } catch (TransactionCommitFailedException e) { + LOG.warn("Failed to delete iidNode {} {}", e.getMessage(), iid); + } + } + public static Map,T> extract( Map, DataObject> changes, Class klazz) { Map,T> result = new HashMap,T>();