Ensure termination points are correctly deleted 73/29473/2
authorGabriel Robitaille-Montpetit <grmontpetit@inocybe.com>
Mon, 9 Nov 2015 23:31:53 +0000 (18:31 -0500)
committergrmontpetit <grmontpetit@inocybe.com>
Tue, 10 Nov 2015 03:19:00 +0000 (22:19 -0500)
Change-Id: I93f5bfc28d80465b84747f4f3d814a7b69be6261
Signed-off-by: Gabriel Robitaille-Montpetit <grmontpetit@inocybe.com>
impl/src/main/java/org/opendaylight/unimgr/command/EvcDeleteCommand.java
impl/src/main/java/org/opendaylight/unimgr/command/UniCreateCommand.java
impl/src/main/java/org/opendaylight/unimgr/command/UniDeleteCommand.java
impl/src/main/java/org/opendaylight/unimgr/impl/UnimgrMapper.java
impl/src/main/java/org/opendaylight/unimgr/impl/UnimgrUtils.java

index 84661b27f203e3aef6b624be83a1992842c9d3ab..3c6be93918611fce08c2cbac17a7fe05442d2ce6 100644 (file)
@@ -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<Node> sourceBridgeIid =
-                                                     sourceOvsdbNodeAugmentation
-                                                         .getManagedNodeEntry()
-                                                         .iterator()
-                                                         .next()
-                                                         .getBridgeRef()
-                                                         .getValue()
-                                                         .firstIdentifierOf(Node.class);
-                        InstanceIdentifier<Node> destinationBridgeIid =
-                                                     destinationOvsdbNodeAugmentation
-                                                         .getManagedNodeEntry()
-                                                         .iterator()
-                                                         .next()
-                                                         .getBridgeRef()
-                                                         .getValue()
-                                                         .firstIdentifierOf(Node.class);
-                        Optional<Node> optionalSourceBridgeNode = UnimgrUtils.readNode(dataBroker,
-                                                                                       LogicalDatastoreType.OPERATIONAL,
-                                                                                       sourceBridgeIid);
-                        Optional<Node>  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<Node> sourceBridgeIid = sourceOvsdbNodeAugmentation.getManagedNodeEntry()
+                                .iterator().next().getBridgeRef().getValue().firstIdentifierOf(Node.class);
+                        InstanceIdentifier<Node> destinationBridgeIid = destinationOvsdbNodeAugmentation
+                                .getManagedNodeEntry().iterator().next().getBridgeRef().getValue()
+                                .firstIdentifierOf(Node.class);
+                        CheckedFuture<Void, TransactionCommitFailedException> deleteOperNodeResult = UnimgrUtils
+                                .deleteNode(dataBroker, sourceBridgeIid, LogicalDatastoreType.CONFIGURATION);
+                        CheckedFuture<Void, TransactionCommitFailedException> 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.");
index 0ffa5d4b5687564245dcf178b211b53f44460dea..711841a4aaf6089312cb711969beb2fb87072771 100644 (file)
@@ -97,7 +97,12 @@ public class UniCreateCommand extends AbstractCreateCommand {
                     Node ovsdbNode;
                     if (optionalOvsdbNode.isPresent()) {
                         ovsdbNode = optionalOvsdbNode.get();
+                        InstanceIdentifier<Node> 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,
index ad36ec55d5cec79cf435fc77ede61f1cc9fff6f5..5e79d8fd1615594aeb12ad027b6e8dc5d4e5b645 100644 (file)
@@ -44,7 +44,7 @@ public class UniDeleteCommand extends AbstractDeleteCommand {
                 if(uniAug != null) {
                     LOG.info("Uni Augmentation present.");
                     OvsdbNodeRef ovsNdRef = uniAug.getOvsdbNodeRef();
-                    InstanceIdentifier<Node> iidNode = (InstanceIdentifier<Node>) ovsNdRef.getValue();
+                    InstanceIdentifier<Node> iidNode = ovsNdRef.getValue().firstIdentifierOf(Node.class);
                     Optional<Node> 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.");}
     }
 }
index 00d95a33798ebd32aee79a2da39fb92ce50f290e..bdc9a88b354b27bc34ed6b550c21f18a0788b0f6 100755 (executable)
@@ -71,8 +71,8 @@ public class UnimgrMapper {
         return nodePath;
     }
 
-    public static InstanceIdentifier<Node> getOvsdbBridgeNodeIid(Node ovsdbNode) {
-        OvsdbNodeAugmentation ovsdbNodeAugmentation = ovsdbNode.getAugmentation(OvsdbNodeAugmentation.class);
+    public static InstanceIdentifier<Node> getOvsdbBridgeNodeIid(Node bridgeNode) {
+        OvsdbNodeAugmentation ovsdbNodeAugmentation = bridgeNode.getAugmentation(OvsdbNodeAugmentation.class);
         InstanceIdentifier<Node> nodePath = ovsdbNodeAugmentation
                                                 .getManagedNodeEntry()
                                                 .iterator()
index ddba37f0ac733de229d31a342b4c355c89b7124e..ead901f81303575bf6e92dfd47cb3bcc77b816a4 100644 (file)
@@ -320,6 +320,23 @@ public class UnimgrUtils {
         transaction.submit();
     }
 
+    public <D extends org.opendaylight.yangtools.yang.binding.DataObject> boolean delete(
+            DataBroker dataBroker,
+            final LogicalDatastoreType store,
+            final InstanceIdentifier<D> path)  {
+        boolean result = false;
+        final WriteTransaction transaction = dataBroker.newWriteOnlyTransaction();
+        transaction.delete(store, path);
+        CheckedFuture<Void, TransactionCommitFailedException> future = transaction.submit();
+        try {
+            future.checkedGet();
+            result = true;
+        } catch (TransactionCommitFailedException e) {
+            LOG.warn("Failed to delete {} ", path, e);
+        }
+        return result;
+    }
+
     public static CheckedFuture<Void,
                                 TransactionCommitFailedException>
                                 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();