changed getManagingNode(..) to expect augmented path. 53/17953/1
authorAmit Mandke <ammandke@cisco.com>
Wed, 8 Apr 2015 17:06:41 +0000 (10:06 -0700)
committerAmit Mandke <ammandke@cisco.com>
Wed, 8 Apr 2015 17:10:49 +0000 (10:10 -0700)
In OvsdbBridgeAttributes 'managedBy' can be path to 'OvsdbNodeAugmentation' as well.
This can happen if the attribute is set via binding aware code.

Signed-off-by: Amit Mandke <ammandke@cisco.com>
southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/SouthboundUtil.java

index 85a8f4ee5e557725c2338b5a13ab1562ba0d8e47..d98fd237798c90e5991fbfc9b706d09c0d8d53e6 100644 (file)
@@ -7,6 +7,9 @@
  */
 package org.opendaylight.ovsdb.southbound;
 
+import com.google.common.base.Optional;
+import com.google.common.base.Preconditions;
+import com.google.common.util.concurrent.CheckedFuture;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
@@ -20,10 +23,6 @@ import org.opendaylight.yangtools.yang.data.impl.codec.DeserializationException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import com.google.common.base.Optional;
-import com.google.common.base.Preconditions;
-import com.google.common.util.concurrent.CheckedFuture;
-
 public class SouthboundUtil {
 
     private static final Logger LOG = LoggerFactory.getLogger(SouthboundUtil.class);
@@ -41,15 +40,15 @@ public class SouthboundUtil {
     public static InstanceIdentifier<?> deserializeInstanceIdentifier(String iidString) {
         InstanceIdentifier<?> result = null;
         try {
-            result =  instanceIdentifierCodec.bindingDeserializer(iidString);
+            result = instanceIdentifierCodec.bindingDeserializer(iidString);
         } catch (DeserializationException e) {
-            LOG.warn("Unable to deserialize iidString",e);
+            LOG.warn("Unable to deserialize iidString", e);
         }
         return result;
     }
 
 
-    public static Optional<OvsdbNodeAugmentation> getManagingNode(DataBroker db,OvsdbBridgeAttributes mn) {
+    public static Optional<OvsdbNodeAugmentation> getManagingNode(DataBroker db, OvsdbBridgeAttributes mn) {
         Preconditions.checkNotNull(mn);
         try {
             OvsdbNodeRef ref = mn.getManagedBy();
@@ -57,25 +56,31 @@ public class SouthboundUtil {
                 ReadOnlyTransaction transaction = db.newReadOnlyTransaction();
                 @SuppressWarnings("unchecked") // Note: erasure makes this safe in combination with the typecheck below
                 InstanceIdentifier<Node> path = (InstanceIdentifier<Node>) ref.getValue();
+
                 CheckedFuture<Optional<Node>, ReadFailedException> nf = transaction.read(
                         LogicalDatastoreType.OPERATIONAL, path);
                 transaction.close();
                 Optional<Node> optional = nf.get();
-                if (optional != null && optional.isPresent() && optional.get() instanceof Node) {
-                    OvsdbNodeAugmentation ovsdbNode = optional.get().getAugmentation(OvsdbNodeAugmentation.class);
+                if (optional != null && optional.isPresent()) {
+                    OvsdbNodeAugmentation ovsdbNode = null;
+                    if (optional.get() instanceof Node) {
+                        ovsdbNode = optional.get().getAugmentation(OvsdbNodeAugmentation.class);
+                    } else if (optional.get() instanceof OvsdbNodeAugmentation) {
+                        ovsdbNode = (OvsdbNodeAugmentation) optional.get();
+                    }
                     if (ovsdbNode != null) {
                         return Optional.of(ovsdbNode);
                     } else {
                         LOG.warn("OvsdbManagedNode {} claims to be managed by {} but "
-                                + "that OvsdbNode does not exist", mn,ref.getValue());
+                                + "that OvsdbNode does not exist", mn, ref.getValue());
                         return Optional.absent();
                     }
                 } else {
-                    LOG.warn("Mysteriously got back a thing which is *not* a topology Node: {}",optional);
+                    LOG.warn("Mysteriously got back a thing which is *not* a topology Node: {}", optional);
                     return Optional.absent();
                 }
             } else {
-                LOG.warn("Cannot find client for OvsdbManagedNode without a specified ManagedBy {}",mn);
+                LOG.warn("Cannot find client for OvsdbManagedNode without a specified ManagedBy {}", mn);
                 return Optional.absent();
             }
         } catch (Exception e) {