X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-binding-broker%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fmd%2Fsal%2Fbinding%2Fimpl%2FBindingToNormalizedNodeCodec.java;h=3f9d5c78546af7b0f40111b745fe89c8fefc5c91;hb=b692b07e81933ff8c85a936a90a934cf778282e2;hp=53615ad7dedc6c7d751554fb7f28bf446b96f1ee;hpb=66249d6ccc367fad055a269f561860d2d96af385;p=controller.git diff --git a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/BindingToNormalizedNodeCodec.java b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/BindingToNormalizedNodeCodec.java index 53615ad7de..3f9d5c7854 100644 --- a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/BindingToNormalizedNodeCodec.java +++ b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/BindingToNormalizedNodeCodec.java @@ -142,27 +142,46 @@ 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 // to augmentation class // if child is referenced - so we will reference child and then shorten // path. + LOG.trace("Looking for candidates to match {}", normalized); for (QName child : lastArgument.getPossibleChildNames()) { org.opendaylight.yangtools.yang.data.api.InstanceIdentifier childPath = new org.opendaylight.yangtools.yang.data.api.InstanceIdentifier( ImmutableList. builder().addAll(normalized.getPath()).add(new NodeIdentifier(child)) .build()); try { - if (!isChoiceOrCasePath(childPath)) { - InstanceIdentifier potentialPath = shortenToLastAugment(toBindingImpl( - childPath).get()); - return Optional.> of(potentialPath); + if (isNotRepresentable(childPath)) { + LOG.trace("Path {} is not BI-representable, skipping it", childPath); + continue; } - } catch (Exception e) { - LOG.trace("Unable to deserialize aug. child path for {}", childPath, e); + } catch (DataNormalizationException e) { + LOG.warn("Failed to denormalize path {}, skipping it", childPath, e); + continue; + } + + Optional> baId = toBindingImpl(childPath); + if (!baId.isPresent()) { + LOG.debug("No binding-aware identifier found for path {}, skipping it", childPath); + continue; + } + + InstanceIdentifier potentialPath = shortenToLastAugment(baId.get()); + int potentialAugmentCount = getAugmentationCount(potentialPath); + if (potentialAugmentCount == normalizedCount) { + LOG.trace("Found matching path {}", potentialPath); + return Optional.> of(potentialPath); } + + LOG.trace("Skipping mis-matched potential path {}", potentialPath); } - return toBindingImpl(normalized); + + LOG.trace("Failed to find augmentation matching {}", normalized); + return Optional.absent(); } private Optional> toBindingImpl( @@ -171,7 +190,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 +202,16 @@ public class BindingToNormalizedNodeCodec implements SchemaContextListener { return Optional.> 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 +281,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) @@ -340,10 +365,8 @@ public class BindingToNormalizedNodeCodec implements SchemaContextListener { try { return ClassLoaderUtils.withClassLoader(method.getDeclaringClass().getClassLoader(), new Callable() { - - @SuppressWarnings("rawtypes") @Override - public Class call() throws Exception { + public Class call() { Type listResult = ClassLoaderUtils.getFirstGenericParameter(method .getGenericReturnType()); if (listResult instanceof Class @@ -383,4 +406,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; + } }