[MDSAL-269] Error occurs when mdsal binding v1 codec a "union" type Created: 09/Jun/17  Updated: 09/Mar/18  Resolved: 05/Mar/18

Status: Resolved
Project: mdsal
Component/s: Binding codegen, Binding V2 codegen
Affects Version/s: None
Fix Version/s: Oxygen, Nitrogen SR2

Type: Bug
Reporter: GU Min Assignee: Robert Varga
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Operating System: All
Platform: All


Attachments: File ietf-routing-types@2017-02-27.yang    
Issue Links:
Blocks
blocks MDSAL-304 Binding V2 maps identities to java.la... Resolved
Relates
relates to MDSAL-253 BindingToNormalizedNodeCodec fails to... Resolved
relates to YANGTOOLS-846 Deserialization of mpls-label union (... Resolved
relates to MDSAL-309 V1 codegen generates enum constants t... Resolved
External issue ID: 8644

 Description   

When I put data to datastore , using this ietf-routing-types@2017-02-27.yang(in the attchment), an error occurs :

testWriteLabelRangeAdd(test.org.opendaylight.bier.driver.configuration.te.label.BierTeLabelRangeConfigWriterImplTest) Time elapsed: 4.561 sec <<< ERROR!
java.lang.IllegalStateException: Unable to load codec for class org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.types.rev170227.MplsLabel
at org.opendaylight.yangtools.binding.data.codec.impl.BindingCodecContext.getCodecForBindingClass(BindingCodecContext.java:306)
at org.opendaylight.yangtools.binding.data.codec.impl.BindingCodecContext.getCodec(BindingCodecContext.java:291)
at org.opendaylight.yangtools.binding.data.codec.impl.BindingCodecContext.getCodecForBindingClass(BindingCodecContext.java:312)
at org.opendaylight.yangtools.binding.data.codec.impl.BindingCodecContext.getCodec(BindingCodecContext.java:291)
at org.opendaylight.yangtools.binding.data.codec.impl.BindingCodecContext.getCodec(BindingCodecContext.java:274)
at org.opendaylight.yangtools.binding.data.codec.impl.BindingCodecContext.getLeafNodesUsingReflection(BindingCodecContext.java:262)
at org.opendaylight.yangtools.binding.data.codec.impl.BindingCodecContext.getLeafNodes(BindingCodecContext.java:229)
at org.opendaylight.yangtools.binding.data.codec.impl.DataObjectCodecContext.<init>(DataObjectCodecContext.java:79)
at org.opendaylight.yangtools.binding.data.codec.impl.ListNodeCodecContext.<init>(ListNodeCodecContext.java:22)
at org.opendaylight.yangtools.binding.data.codec.impl.KeyedListNodeCodecContext.<init>(KeyedListNodeCodecContext.java:29)
at org.opendaylight.yangtools.binding.data.codec.impl.DataContainerCodecPrototype.createInstance(DataContainerCodecPrototype.java:129)
at org.opendaylight.yangtools.binding.data.codec.impl.DataContainerCodecPrototype.get(DataContainerCodecPrototype.java:112)
at org.opendaylight.yangtools.binding.data.codec.impl.DataObjectCodecContext.bindingPathArgumentChild(DataObjectCodecContext.java:179)
at org.opendaylight.yangtools.binding.data.codec.impl.BindingCodecContext.getCodecContextNode(BindingCodecContext.java:127)
at org.opendaylight.yangtools.binding.data.codec.impl.BindingCodecContext.newWriter(BindingCodecContext.java:104)
at org.opendaylight.yangtools.binding.data.codec.impl.BindingNormalizedNodeCodecRegistry.toNormalizedNode(BindingNormalizedNodeCodecRegistry.java:102)
at org.opendaylight.controller.md.sal.binding.impl.BindingToNormalizedNodeCodec.toNormalizedNode(BindingToNormalizedNodeCodec.java:135)
at org.opendaylight.controller.md.sal.binding.impl.AbstractWriteTransaction.merge(AbstractWriteTransaction.java:53)
at org.opendaylight.bier.driver.common.util.DataWriter.operate(DataWriter.java:94)
at org.opendaylight.bier.driver.NetconfDataOperator.write(NetconfDataOperator.java:75)
at org.opendaylight.bier.driver.configuration.te.label.BierTeLabelRangeConfigWriterImpl.writeBierTeLabelRange(BierTeLabelRangeConfigWriterImpl.java:94)
at test.org.opendaylight.bier.driver.configuration.te.label.BierTeLabelRangeConfigWriterImplTest.testWriteLabelRangeAdd(BierTeLabelRangeConfigWriterImplTest.java:96)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:283)
at org.apache.maven.surefire.junit4.JUnit4Provider.executeWithRerun(JUnit4Provider.java:173)
at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:153)
at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:128)
at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:203)
at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:155)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:103)
Caused by: java.lang.NoSuchMethodException: org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.types.rev170227.MplsLabel.getMplsLabelSpecialPurpose()
at java.lang.Class.getMethod(Class.java:1778)
at org.opendaylight.yangtools.binding.data.codec.impl.UnionTypeCodec.lambda$loader$0(UnionTypeCodec.java:33)
at org.opendaylight.yangtools.binding.data.codec.impl.UnionTypeCodec$$Lambda$66/588275830.call(Unknown Source)
at org.opendaylight.yangtools.binding.data.codec.impl.BindingCodecContext.getCodecForBindingClass(BindingCodecContext.java:304)
... 46 more



 Comments   
Comment by GU Min [ 09/Jun/17 ]

Attachment ietf-routing-types@2017-02-27.yang has been added with description: yang file

Comment by Peter Kajsa [ 09/Jun/17 ]

This issue is related to binding generator and binding codecs, which are parts of mdsal project, therefore I move this bug to mdsal..

Comment by Martin Ciglan [ 12/Jun/17 ]

is this master and/or stable/carbon?

Comment by GU Min [ 12/Jun/17 ]

I use 0.11.0-SNAPSHOT

<parent>
<groupId>org.opendaylight.mdsal</groupId>
<artifactId>binding-parent</artifactId>
<version>0.11.0-SNAPSHOT</version>
<relativePath/>
</parent>

Comment by Marek Gradzki [ 27/Oct/17 ]

I have similar issue with Carbon-SR2. I noticed that
org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.types.rev170227.MplsLabel
does not have getMplsLabelSpecialPurpose getter,

but mpls-label defines it:

typedef mpls-label {
type union

{ type mpls-label-special-purpose; type mpls-label-general-use; }

This causes similar failure when we try to configure labels in Honeycoimb via restconf.

Comment by Robert Varga [ 30/Jan/18 ]

The problem is located in TypeProviderImpl.resolveExtendedSubtypeAsUnion(), where we ignore the union type as it is derived from an IdentityRef and there is no case statement to assign it.

Comment by Robert Varga [ 30/Jan/18 ]

Actually, for some reason we do not generate a type for 'typedef mpls-label-special-purpose', which means the union cannot find the type and fails to add the union member.

Comment by Robert Varga [ 30/Jan/18 ]

Oxygen: https://git.opendaylight.org/gerrit/67757

This also affects binding-v2, but that needs to be addressed separately.

Comment by Robert Varga [ 30/Jan/18 ]

LeafrefTypeDefinition was fixed previously in MDSAL-253, but that did not fix IdentityrefTypeDefinition nor binding2.

Comment by Robert Varga [ 31/Jan/18 ]

Root Cause Analysis:

This issue comes from the decision to not change generated identityref leaf method signature, which means we cannot provide typedef-mandated encapsulation of the identity reference. Hence no encapsulation is done for both identityref and leafref nodes.

While MDSAL-253 took care of the leafref special case for unions, identityref typedefs were not handled and dropped silently.

The fix makes unions aware of identityref and wires them to the leafref case, which produces expected results.

Comment by Robert Varga [ 02/Feb/18 ]

The patch actually does not fix anything. I can now see the problem, codec expects:

Caused by: java.lang.NoSuchMethodException: org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.types.rev170227.MplsLabel.getMplsLabelSpecialPurpose()
at java.lang.Class.getMethod(Class.java:1778)

while codegen generates:

    public java.lang.Class<? extends org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.types.rev170227.MplsLabelSpecialPurposeValue> getClassMplsLabelValue()

{         return _classMplsLabelValue;     }

e.g. codegen does not take the typedef into account at all, while it should for naming purposes – the method name is derived from the identity name, not the type name of the identityref. That actually should be simpler to fix (I hope).

Comment by Robert Varga [ 02/Feb/18 ]

Updated patch generates the property correctly.

Comment by Marek Gradzki [ 02/Feb/18 ]

Property generation works indeed, but now I get some run time issues during deserialization,

that look similar to YANGTOOLS-742.

Stack trace:

Caused by: java.lang.IllegalArgumentException: Failed to construct instance of class org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.types.rev170227.MplsLabel for input (urn:ietf:params:xml:ns:yang:ietf-mpls-static?revision=2017-03-10)111
    at org.opendaylight.yangtools.binding.data.codec.impl.UnionTypeCodec.deserialize(UnionTypeCodec.java:114) ~[mdsal-binding-dom-codec-0.11.2-SNAPSHOT.jar:na]
    at org.opendaylight.yangtools.binding.data.codec.impl.LeafNodeCodecContext.deserializeObject(LeafNodeCodecContext.java:199) ~[mdsal-binding-dom-codec-0.11.2-SNAPSHOT.jar:na]
    at org.opendaylight.yangtools.binding.data.codec.impl.DataObjectCodecContext.getBindingChildValue(DataObjectCodecContext.java:324) ~[mdsal-binding-dom-codec-0.11.2-SNAPSHOT.jar:na]
    at org.opendaylight.yangtools.binding.data.codec.impl.LazyDataObject.getBindingData(LazyDataObject.java:148) ~[mdsal-binding-dom-codec-0.11.2-SNAPSHOT.jar:na]
    at org.opendaylight.yangtools.binding.data.codec.impl.LazyDataObject.bindingToString(LazyDataObject.java:205) ~[mdsal-binding-dom-codec-0.11.2-SNAPSHOT.jar:na]
    at org.opendaylight.yangtools.binding.data.codec.impl.LazyDataObject.invoke(LazyDataObject.java:65) ~[mdsal-binding-dom-codec-0.11.2-SNAPSHOT.jar:na]
    at com.sun.proxy.$Proxy115.toString(Unknown Source) ~[na:na]
    at java.lang.String.valueOf(String.java:2994) ~[na:1.8.0_151]
    at java.lang.StringBuilder.append(StringBuilder.java:131) ~[na:1.8.0_151]
    at com.google.common.base.MoreObjects$ToStringHelper.toString(MoreObjects.java:350) ~[guava-22.0.jar:na]
    at org.opendaylight.yangtools.binding.data.codec.impl.LazyDataObject.bindingToString(LazyDataObject.java:210) ~[mdsal-binding-dom-codec-0.11.2-SNAPSHOT.jar:na]
    at org.opendaylight.yangtools.binding.data.codec.impl.LazyDataObject.invoke(LazyDataObject.java:65) ~[mdsal-binding-dom-codec-0.11.2-SNAPSHOT.jar:na]
    at com.sun.proxy.$Proxy112.toString(Unknown Source) ~[na:na]
    at java.lang.String.valueOf(String.java:2994) ~[na:1.8.0_151]
    at java.lang.StringBuilder.append(StringBuilder.java:131) ~[na:1.8.0_151]
    at com.google.common.base.MoreObjects$ToStringHelper.toString(MoreObjects.java:350) ~[guava-22.0.jar:na]
    at org.opendaylight.yangtools.binding.data.codec.impl.LazyDataObject.bindingToString(LazyDataObject.java:210) ~[mdsal-binding-dom-codec-0.11.2-SNAPSHOT.jar:na]
    at org.opendaylight.yangtools.binding.data.codec.impl.LazyDataObject.invoke(LazyDataObject.java:65) ~[mdsal-binding-dom-codec-0.11.2-SNAPSHOT.jar:na]
    at com.sun.proxy.$Proxy111.toString(Unknown Source) ~[na:na]
    at java.util.Formatter$FormatSpecifier.printString(Formatter.java:2886) ~[na:1.8.0_151]
    at java.util.Formatter$FormatSpecifier.print(Formatter.java:2763) ~[na:1.8.0_151]
    at java.util.Formatter.format(Formatter.java:2520) ~[na:1.8.0_151]
    at java.util.Formatter.format(Formatter.java:2455) ~[na:1.8.0_151]
    at java.lang.String.format(String.java:2940) ~[na:1.8.0_151]
    at io.fd.honeycomb.translate.write.WriteFailedException$CreateFailedException.getMsg(WriteFailedException.java:114) ~[translate-api-1.18.01.1-SNAPSHOT.jar:na]

 

 

Comment by Robert Varga [ 02/Feb/18 ]

This exception is thrown when no member codec accepts the incoming value. Enable debug on UnionValueOptionContext to see what went down. Judging from the value it should have been intercepted by mpls-label-general-use...

Please file a separate issue.

Comment by Marek Gradzki [ 05/Feb/18 ]

DOne: MDSAL-307

Generated at Wed Feb 07 20:09:18 UTC 2024 using Jira 8.20.10#820010-sha1:ace47f9899e9ee25d7157d59aa17ab06aee30d3d.