Bug 967: Do not translate leaf Instance Identifiers. 11/7111/1
authorTony Tkacik <ttkacik@cisco.com>
Fri, 16 May 2014 11:02:33 +0000 (13:02 +0200)
committerTony Tkacik <ttkacik@cisco.com>
Fri, 16 May 2014 11:52:52 +0000 (13:52 +0200)
Improved extraction of Instance Identifiers from
DOM Data Change Event.

Logs in console are poluted with DeserializationException,
which fails to deserialize DOM Instance Identifier
to Binding Instance Identifier.

Added explicit check against schema context to
see if Instance Identifier is representable
in Binding Format, if not we will not report
is as part of subtree Data Change event.

Change-Id: Iaee2390fd089e0a2d66ec658aab4e7dab2a93a46
Signed-off-by: Tony Tkacik <ttkacik@cisco.com>
opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/BindingToNormalizedNodeCodec.java
opendaylight/md-sal/sal-common-impl/src/main/java/org/opendaylight/controller/md/sal/common/impl/util/compat/DataNormalizationOperation.java

index 53615ad7dedc6c7d751554fb7f28bf446b96f1ee..846f949375dabc21a112e0dc9c1268e6b04148c4 100644 (file)
@@ -142,6 +142,7 @@ public class BindingToNormalizedNodeCodec implements SchemaContextListener {
             return potential;
         }
 
+        int normalizedCount = getAugmentationCount(normalized);
         AugmentationIdentifier lastArgument = (AugmentationIdentifier) Iterables.getLast(normalized.getPath());
 
         // Here we employ small trick - Binding-aware Codec injects an pointer
@@ -153,16 +154,19 @@ public class BindingToNormalizedNodeCodec implements SchemaContextListener {
                     ImmutableList.<PathArgument> builder().addAll(normalized.getPath()).add(new NodeIdentifier(child))
                             .build());
             try {
-                if (!isChoiceOrCasePath(childPath)) {
+                if (!isNotRepresentable(childPath)) {
                     InstanceIdentifier<? extends DataObject> potentialPath = shortenToLastAugment(toBindingImpl(
                             childPath).get());
-                    return Optional.<InstanceIdentifier<? extends DataObject>> of(potentialPath);
+                    int potentialAugmentCount = getAugmentationCount(potentialPath);
+                    if(potentialAugmentCount == normalizedCount) {
+                        return Optional.<InstanceIdentifier<? extends DataObject>> of(potentialPath);
+                    }
                 }
             } catch (Exception e) {
                 LOG.trace("Unable to deserialize aug. child path for {}", childPath, e);
             }
         }
-        return toBindingImpl(normalized);
+        return Optional.absent();
     }
 
     private Optional<InstanceIdentifier<? extends DataObject>> toBindingImpl(
@@ -171,7 +175,7 @@ public class BindingToNormalizedNodeCodec implements SchemaContextListener {
         org.opendaylight.yangtools.yang.data.api.InstanceIdentifier legacyPath;
 
         try {
-            if (isChoiceOrCasePath(normalized)) {
+            if (isNotRepresentable(normalized)) {
                 return Optional.absent();
             }
             legacyPath = legacyToNormalized.toLegacy(normalized);
@@ -183,10 +187,16 @@ public class BindingToNormalizedNodeCodec implements SchemaContextListener {
         return Optional.<InstanceIdentifier<? extends DataObject>> of(bindingToLegacy.fromDataDom(legacyPath));
     }
 
-    private boolean isChoiceOrCasePath(final org.opendaylight.yangtools.yang.data.api.InstanceIdentifier normalized)
+    private boolean isNotRepresentable(final org.opendaylight.yangtools.yang.data.api.InstanceIdentifier normalized)
             throws DataNormalizationException {
         DataNormalizationOperation<?> op = findNormalizationOperation(normalized);
-        return op.isMixin() && op.getIdentifier() instanceof NodeIdentifier;
+        if( op.isMixin() && op.getIdentifier() instanceof NodeIdentifier) {
+            return true;
+        }
+        if(op.isLeaf()) {
+            return true;
+        }
+        return false;
     }
 
     private DataNormalizationOperation<?> findNormalizationOperation(
@@ -256,7 +266,7 @@ public class BindingToNormalizedNodeCodec implements SchemaContextListener {
         if (isAugmentationIdentifier(processed)) {
             return processed;
         }
-        // Here we employ small trick - DataNormalizer injecst augmentation
+        // Here we employ small trick - DataNormalizer injects augmentation
         // identifier if child is
         // also part of the path (since using a child we can safely identify
         // augmentation)
@@ -383,4 +393,25 @@ public class BindingToNormalizedNodeCodec implements SchemaContextListener {
     private boolean isAugmentationIdentifier(final org.opendaylight.yangtools.yang.data.api.InstanceIdentifier processed) {
         return Iterables.getLast(processed.getPath()) instanceof AugmentationIdentifier;
     }
+
+    private static int getAugmentationCount(final InstanceIdentifier<?> potential) {
+        int count = 0;
+        for(org.opendaylight.yangtools.yang.binding.InstanceIdentifier.PathArgument arg : potential.getPathArguments()) {
+            if(isAugmentation(arg.getType())) {
+                count++;
+            }
+
+        }
+        return count;
+    }
+
+    private static int getAugmentationCount(final org.opendaylight.yangtools.yang.data.api.InstanceIdentifier potential) {
+        int count = 0;
+        for(PathArgument arg : potential.getPath()) {
+            if(arg instanceof AugmentationIdentifier) {
+                count++;
+            }
+        }
+        return count;
+    }
 }
index 663493adcc55c92ef0dbadb0923d132b77eb2a61..f869254dcf1efa2832f792005c7f22f02d9be033 100644 (file)
@@ -83,6 +83,8 @@ public abstract class DataNormalizationOperation<T extends PathArgument> impleme
 
     public abstract NormalizedNode<?, ?> normalize(Node<?> legacyData);
 
+    public abstract boolean isLeaf();
+
     private static abstract class SimpleTypeNormalization<T extends PathArgument> extends DataNormalizationOperation<T> {
 
         protected SimpleTypeNormalization(final T identifier) {
@@ -113,6 +115,11 @@ public abstract class DataNormalizationOperation<T extends PathArgument> impleme
             return null;
         }
 
+        @Override
+        public boolean isLeaf() {
+            return true;
+        }
+
     }
 
     private static final class LeafNormalization extends SimpleTypeNormalization<NodeIdentifier> {
@@ -199,6 +206,11 @@ public abstract class DataNormalizationOperation<T extends PathArgument> impleme
             return builder.build();
         }
 
+        @Override
+        public boolean isLeaf() {
+            return false;
+        }
+
         @SuppressWarnings("rawtypes")
         protected abstract NormalizedNodeContainerBuilder createBuilder(final CompositeNode compositeNode);