From 38dcb13314b59a1c7d90a07eb2f3e43eb66366a0 Mon Sep 17 00:00:00 2001 From: Gabriel Robitaille-Montpetit Date: Mon, 9 Nov 2015 18:31:53 -0500 Subject: [PATCH] Ensure termination points are correctly deleted Change-Id: I93f5bfc28d80465b84747f4f3d814a7b69be6261 Signed-off-by: Gabriel Robitaille-Montpetit --- .../unimgr/command/EvcDeleteCommand.java | 71 ++++++++----------- .../unimgr/command/UniCreateCommand.java | 5 ++ .../unimgr/command/UniDeleteCommand.java | 4 +- .../unimgr/impl/UnimgrMapper.java | 4 +- .../opendaylight/unimgr/impl/UnimgrUtils.java | 18 +++++ 5 files changed, 55 insertions(+), 47 deletions(-) diff --git a/impl/src/main/java/org/opendaylight/unimgr/command/EvcDeleteCommand.java b/impl/src/main/java/org/opendaylight/unimgr/command/EvcDeleteCommand.java index 84661b27..3c6be939 100644 --- a/impl/src/main/java/org/opendaylight/unimgr/command/EvcDeleteCommand.java +++ b/impl/src/main/java/org/opendaylight/unimgr/command/EvcDeleteCommand.java @@ -13,6 +13,8 @@ import java.util.Set; import org.opendaylight.controller.md.sal.binding.api.DataBroker; 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.OvsdbNodeAugmentation; @@ -26,6 +28,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.google.common.base.Optional; +import com.google.common.util.concurrent.CheckedFuture; public class EvcDeleteCommand extends AbstractDeleteCommand { @@ -87,48 +90,32 @@ public class EvcDeleteCommand extends AbstractDeleteCommand { && optionalDestinationOvsdbNode.isPresent()) { Node sourceOvsdbNode = optionalSourceOvsdNode.get(); Node destinationOvsdbNode = optionalDestinationOvsdbNode.get(); - OvsdbNodeAugmentation sourceOvsdbNodeAugmentation = - sourceOvsdbNode.getAugmentation(OvsdbNodeAugmentation.class); - OvsdbNodeAugmentation destinationOvsdbNodeAugmentation = - destinationOvsdbNode.getAugmentation(OvsdbNodeAugmentation.class); - InstanceIdentifier sourceBridgeIid = - sourceOvsdbNodeAugmentation - .getManagedNodeEntry() - .iterator() - .next() - .getBridgeRef() - .getValue() - .firstIdentifierOf(Node.class); - InstanceIdentifier destinationBridgeIid = - destinationOvsdbNodeAugmentation - .getManagedNodeEntry() - .iterator() - .next() - .getBridgeRef() - .getValue() - .firstIdentifierOf(Node.class); - Optional optionalSourceBridgeNode = UnimgrUtils.readNode(dataBroker, - LogicalDatastoreType.OPERATIONAL, - sourceBridgeIid); - Optional optionalDestinationBridgeNode = UnimgrUtils.readNode(dataBroker, - LogicalDatastoreType.OPERATIONAL, - destinationBridgeIid); - if (optionalSourceBridgeNode.isPresent() - && optionalDestinationBridgeNode.isPresent()) { - Node sourceBridgeNode = optionalSourceBridgeNode.get(); - Node destinationBridgeNode = optionalSourceBridgeNode.get(); - TpId sourceTp = sourceBridgeNode.getTerminationPoint().iterator().next().getTpId(); - TpId destTp = destinationBridgeNode.getTerminationPoint().iterator().next().getTpId(); - InstanceIdentifier sourceTpIid = UnimgrMapper.getTerminationPointIid(sourceBridgeNode, - sourceTp); - InstanceIdentifier destinationTpIid = UnimgrMapper.getTerminationPointIid(destinationBridgeNode, - destTp); - UnimgrUtils.deleteNode(dataBroker, sourceTpIid, LogicalDatastoreType.CONFIGURATION); - UnimgrUtils.deleteNode(dataBroker, destinationTpIid, LogicalDatastoreType.CONFIGURATION); - UnimgrUtils.deleteNode(dataBroker, sourceTpIid, LogicalDatastoreType.OPERATIONAL); - UnimgrUtils.deleteNode(dataBroker, destinationTpIid, LogicalDatastoreType.OPERATIONAL); - } else { - LOG.info("Unable to retrieve the Ovsdb Bridge node source and/or destination."); + OvsdbNodeAugmentation sourceOvsdbNodeAugmentation = sourceOvsdbNode + .getAugmentation(OvsdbNodeAugmentation.class); + OvsdbNodeAugmentation destinationOvsdbNodeAugmentation = destinationOvsdbNode + .getAugmentation(OvsdbNodeAugmentation.class); + InstanceIdentifier sourceBridgeIid = sourceOvsdbNodeAugmentation.getManagedNodeEntry() + .iterator().next().getBridgeRef().getValue().firstIdentifierOf(Node.class); + InstanceIdentifier destinationBridgeIid = destinationOvsdbNodeAugmentation + .getManagedNodeEntry().iterator().next().getBridgeRef().getValue() + .firstIdentifierOf(Node.class); + CheckedFuture deleteOperNodeResult = UnimgrUtils + .deleteNode(dataBroker, sourceBridgeIid, LogicalDatastoreType.CONFIGURATION); + CheckedFuture deleteConfigNodeResult = UnimgrUtils + .deleteNode(dataBroker, destinationBridgeIid, LogicalDatastoreType.CONFIGURATION); + try { + deleteOperNodeResult.checkedGet(); + deleteConfigNodeResult.checkedGet(); + if (deleteOperNodeResult.isDone() && deleteConfigNodeResult.isDone()) { + UnimgrUtils.createBridgeNode(dataBroker, sourceOvsdbIid, + sourceUniNode.getAugmentation(UniAugmentation.class), + UnimgrConstants.DEFAULT_BRIDGE_NAME); + UnimgrUtils.createBridgeNode(dataBroker, destOvsdbIid, + destUniNode.getAugmentation(UniAugmentation.class), + UnimgrConstants.DEFAULT_BRIDGE_NAME); + } + } catch (TransactionCommitFailedException e) { + LOG.error("Unable to delete bridges."); } } else { LOG.info("Unable to retrieve the Ovsdb node source and/or destination."); diff --git a/impl/src/main/java/org/opendaylight/unimgr/command/UniCreateCommand.java b/impl/src/main/java/org/opendaylight/unimgr/command/UniCreateCommand.java index 0ffa5d4b..711841a4 100644 --- a/impl/src/main/java/org/opendaylight/unimgr/command/UniCreateCommand.java +++ b/impl/src/main/java/org/opendaylight/unimgr/command/UniCreateCommand.java @@ -97,7 +97,12 @@ public class UniCreateCommand extends AbstractCreateCommand { Node ovsdbNode; if (optionalOvsdbNode.isPresent()) { ovsdbNode = optionalOvsdbNode.get(); + InstanceIdentifier ovsdbIid = UnimgrMapper.getOvsdbNodeIid(ovsdbNode.getNodeId()); LOG.info("Retrieved the OVSDB node"); + UnimgrUtils.createBridgeNode(dataBroker, + ovsdbIid, + uni, + UnimgrConstants.DEFAULT_BRIDGE_NAME); UnimgrUtils.updateUniNode(LogicalDatastoreType.CONFIGURATION, uniKey, uni, 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 ad36ec55..5e79d8fd 100644 --- a/impl/src/main/java/org/opendaylight/unimgr/command/UniDeleteCommand.java +++ b/impl/src/main/java/org/opendaylight/unimgr/command/UniDeleteCommand.java @@ -44,7 +44,7 @@ public class UniDeleteCommand extends AbstractDeleteCommand { if(uniAug != null) { LOG.info("Uni Augmentation present."); OvsdbNodeRef ovsNdRef = uniAug.getOvsdbNodeRef(); - InstanceIdentifier iidNode = (InstanceIdentifier) ovsNdRef.getValue(); + InstanceIdentifier iidNode = ovsNdRef.getValue().firstIdentifierOf(Node.class); Optional optNode = UnimgrUtils.readNode(dataBroker, LogicalDatastoreType.OPERATIONAL, iidNode); if (optNode.isPresent()) { Node ovsdbNode = optNode.get(); @@ -52,13 +52,11 @@ public class UniDeleteCommand extends AbstractDeleteCommand { UnimgrUtils.deletePath(dataBroker, iidBridgeNode); LOG.info("Received a request to remove a UNI BridgeNode ", iidBridgeNode); } - 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.");} } } diff --git a/impl/src/main/java/org/opendaylight/unimgr/impl/UnimgrMapper.java b/impl/src/main/java/org/opendaylight/unimgr/impl/UnimgrMapper.java index 00d95a33..bdc9a88b 100755 --- a/impl/src/main/java/org/opendaylight/unimgr/impl/UnimgrMapper.java +++ b/impl/src/main/java/org/opendaylight/unimgr/impl/UnimgrMapper.java @@ -71,8 +71,8 @@ public class UnimgrMapper { return nodePath; } - public static InstanceIdentifier getOvsdbBridgeNodeIid(Node ovsdbNode) { - OvsdbNodeAugmentation ovsdbNodeAugmentation = ovsdbNode.getAugmentation(OvsdbNodeAugmentation.class); + public static InstanceIdentifier getOvsdbBridgeNodeIid(Node bridgeNode) { + OvsdbNodeAugmentation ovsdbNodeAugmentation = bridgeNode.getAugmentation(OvsdbNodeAugmentation.class); InstanceIdentifier nodePath = ovsdbNodeAugmentation .getManagedNodeEntry() .iterator() 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 ddba37f0..ead901f8 100644 --- a/impl/src/main/java/org/opendaylight/unimgr/impl/UnimgrUtils.java +++ b/impl/src/main/java/org/opendaylight/unimgr/impl/UnimgrUtils.java @@ -320,6 +320,23 @@ public class UnimgrUtils { transaction.submit(); } + public boolean delete( + DataBroker dataBroker, + final LogicalDatastoreType store, + final InstanceIdentifier path) { + boolean result = false; + final WriteTransaction transaction = dataBroker.newWriteOnlyTransaction(); + transaction.delete(store, path); + CheckedFuture future = transaction.submit(); + try { + future.checkedGet(); + result = true; + } catch (TransactionCommitFailedException e) { + LOG.warn("Failed to delete {} ", path, e); + } + return result; + } + public static CheckedFuture deleteTerminationPoint(DataBroker dataBroker, @@ -347,6 +364,7 @@ public class UnimgrUtils { deleteNode(DataBroker dataBroker, InstanceIdentifier genericNode, LogicalDatastoreType store) { + LOG.info("Received a request to delete node {}", genericNode); WriteTransaction transaction = dataBroker.newWriteOnlyTransaction(); transaction.delete(store, genericNode); return transaction.submit(); -- 2.36.6