fix uni delete and merge conflict 97/29397/4
authormelserngawy <melserngawy@inocybe.com>
Fri, 6 Nov 2015 22:00:13 +0000 (17:00 -0500)
committerMohamed El-Serngawy <melserngawy@inocybe.com>
Mon, 9 Nov 2015 15:59:53 +0000 (10:59 -0500)
Change-Id: I0105dd184c66b5889848d017a47f3520424631d6
Signed-off-by: melserngawy <melserngawy@inocybe.com>
impl/src/main/java/org/opendaylight/unimgr/command/UniDeleteCommand.java
impl/src/main/java/org/opendaylight/unimgr/impl/UnimgrUtils.java

index 9d06ba27efaea441b24f841e943f4fddf9877f1e..ad36ec55d5cec79cf435fc77ede61f1cc9fff6f5 100644 (file)
@@ -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<InstanceIdentifier<UniAugmentation>> removedUnis = UnimgrUtils.extractRemoved(changes, UniAugmentation.class);
-        Set<InstanceIdentifier<Node>> removedNodes = UnimgrUtils.extractRemoved(changes, Node.class);
         if (!removedUnis.isEmpty()) {
             for (InstanceIdentifier<UniAugmentation> removedUniIid: removedUnis) {
-                UniAugmentation uniAug = UnimgrUtils.read(dataBroker, LogicalDatastoreType.CONFIGURATION, removedUniIid);
-                if(uniAug != null){
-                    LOG.trace("Uni Augmentation present.");
-                    OvsdbNodeRef ovsdbNodeRef = uniAug.getOvsdbNodeRef();
-                    InstanceIdentifier<Node> ovsdbIid = ovsdbNodeRef.getValue().firstIdentifierOf(Node.class);
-                    Optional<Node> 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<Node> iidNode = (InstanceIdentifier<Node>) ovsNdRef.getValue();
+                    Optional<Node> optNode = UnimgrUtils.readNode(dataBroker, LogicalDatastoreType.OPERATIONAL, iidNode);
                     if (optNode.isPresent()) {
                         Node ovsdbNode = optNode.get();
                         InstanceIdentifier<Node> 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<Node> iidNode : removedNodes) {
-                Optional<Node> optNode = UnimgrUtils.readNode(dataBroker, LogicalDatastoreType.CONFIGURATION, iidNode);
-                if (optNode.isPresent()) {
-                    Node ovsdbNode = optNode.get();
-                    InstanceIdentifier<Node> 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<Node> iidNode) {
-        WriteTransaction transaction = dataBroker.newWriteOnlyTransaction();
-        transaction.delete(LogicalDatastoreType.OPERATIONAL, iidNode);
-        transaction.delete(LogicalDatastoreType.CONFIGURATION, iidNode);
-        CheckedFuture<Void, TransactionCommitFailedException> future = transaction.submit();
-        try {
-            future.checkedGet();
-        } catch (TransactionCommitFailedException e) {
-            LOG.warn("Failed to delete iidNode {} {}", e.getMessage(), iidNode);
-        }
     }
 }
index e03a8ad9495c2c435065dfdbe403f22f65661f5e..ddba37f0ac733de229d31a342b4c355c89b7124e 100644 (file)
@@ -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<Void, TransactionCommitFailedException> 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<Void, TransactionCommitFailedException> future = transaction.submit();
+        try {
+            future.checkedGet();
+        } catch (TransactionCommitFailedException e) {
+            LOG.warn("Failed to delete iidNode {} {}", e.getMessage(), iid);
+        }
+    }
+
     public static <T extends DataObject> Map<InstanceIdentifier<T>,T> extract(
             Map<InstanceIdentifier<?>, DataObject> changes, Class<T> klazz) {
         Map<InstanceIdentifier<T>,T> result = new HashMap<InstanceIdentifier<T>,T>();