[YANGTOOLS-577] Issue in casting a anyxml leaf to anyXMLNode type Created: 26/Jan/16  Updated: 10/Apr/22  Resolved: 19/Jul/16

Status: Resolved
Project: yangtools
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug
Reporter: Ambika Prasad Tripathy Assignee: Igor Foltin
Resolution: Cannot Reproduce Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Operating System: All
Platform: All


External issue ID: 5099

 Description   

I am getting WARNING when trying to get values of datastore-contents-xml anyxml node for below notification.

Is there any modification to anyXML implementation? How to convert anyxml data to a DOMSource in current implementation?

NOTE: It was working fine during Dec time line.

The value I am getting for below notification looks
2016-01-26 15:58:47,020 | INFO | oupCloseable-5-2 | YangpushDOMNotificationListener | 247 - org.opendaylight.yang-push.yangpush-impl - 1.1.0.SNAPSHOT | Notification recieved ImmutableContainerNode{nodeIdentifier=(urn:ietf:params:xml:ns:yang:ietf-datastore-push?revision=2015-10-15)push-update, value=[ImmutableLeafNode{nodeIdentifier=(urn:ietf:params:xml:ns:yang:ietf-datastore-push?revision=2015-10-15)time-of-update, value=2011-01-04T12:30:46Z, attributes={}}, ImmutableLeafNode{nodeIdentifier=(urn:ietf:params:xml:ns:yang:ietf-datastore-push?revision=2015-10-15)subscription-id, value=201, attributes={}}, ImmutableChoiceNode{nodeIdentifier=(urn:ietf:params:xml:ns:yang:ietf-datastore-push?revision=2015-10-15)encoding, value=[ImmutableLeafNode{nodeIdentifier=(urn:ietf:params:xml:ns:yang:ietf-datastore-push?revision=2015-10-15)datastore-contents-xml, value=actMgmtEth0/0/CPU0/010.0.2.15255.255.255.0, attributes={}}]}], attributes={}}

2016-01-26 15:58:47,021 | WARN | oupCloseable-5-2 | YangpushDOMNotificationListener | 247 - org.opendaylight.yang-push.yangpush-impl - 1.1.0.SNAPSHOT | java.lang.ClassCastException: org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableLeafNodeBuilder$ImmutableLeafNode cannot be cast to org.opendaylight.yangtools.yang.data.api.schema.AnyXmlNode

Notification schema:
notification push-update {
leaf subscription-id

{ type subscription-id; mandatory true; }

leaf time-of-update

{ type yang:date-and-time; }

choice encoding {
case encode-xml

{ anyxml datastore-contents-xml; }

case encode-json {
if-feature json;
leaf datastore-contents-json

{ type datastore-contents-json; }

}
}
}

Sample code:
private void pushUpdateHandlder(DOMNotification notification) {
ContainerNode conNode = notification.getBody();
ChoiceNode valueNode = null;
AnyXmlNode anyXmlValue = null;
DOMSource domSource = null;
String sub_id = "";
String timeofeventupdate = "";
try

{ sub_id = conNode.getChild(subid).get().getValue().toString(); timeofeventupdate = conNode.getChild(timeofevent).get().getValue().toString(); valueNode = (ChoiceNode) conNode.getChild(encoding).get(); anyXmlValue = (AnyXmlNode) valueNode.getChild(contents).get(); domSource = anyXmlValue.getValue(); }

catch (Exception e)

{ LOG.warn(e.toString()); }

String notificationAsString = domSourceToString(domSource);
LOG.info("Notification recieved for sub_id :{} at : {}:\n {}", sub_id, timeofeventupdate, notificationAsString);
}



 Comments   
Comment by Tony Tkacik [ 27/Jan/16 ]

Which branch are you observing this issue?
Are you building YANGTOOls locally or downloaded from repository?

Comment by Ambika Prasad Tripathy [ 27/Jan/16 ]

I am downloading from latest repo.

Comment by Ambika Prasad Tripathy [ 11/May/16 ]

Would you link to update the release plan for the bug and work arround?

Comment by Ambika Prasad Tripathy [ 07/Jun/16 ]

for anyxml node, it is not mandatory to define a schema node. I can put any XML data inside it for which schema may not present. Why the current implementation of anyXML depends on schema?

is the schema is not there, how to get DOMSource from the ANYXML leaf node?

Comment by Igor Foltin [ 13/Jun/16 ]

Hello Ambika,

I would like to ask: How did you construct the DOMNotification object ? Which implementation did you use ?

According to the ClassCastException message, it seems like you put a LeafNode under the ChoiceNode "encoding".
You have to put an AnyXmlNode in there instead as it represents the anyxml schema node "datastore-contents-xml" from the yang schema.

Comment by Ambika Prasad Tripathy [ 13/Jun/16 ]

Hi,

my choice node is like below
choice encoding {
case encode-xml

{ anyxml datastore-contents-xml; }

The notification generated by Device and received by ODL. I am getting proper notification message from device. But when extracting "datastore-contents-xml" node contents, i am facing the issue.

br,
Ambika Prasad Tripathy

Comment by Igor Foltin [ 13/Jun/16 ]

Could you please provide more info about the exact conditions under which you ran into this problem ? I will then try to reproduce it.

Comment by Ryan Goulding [ 05/Jul/16 ]

Hi Ambika,

Have you gotten a chance to provide any more information to reproduce this issue?

Thanks,
Ryan

Comment by Ambika Prasad Tripathy [ 07/Jul/16 ]

Hi,

Sorry. I missed last notification.

If you look my model for anyxml use, i have no predefined schema assigned for the anyxml data node.

I am expecting this node to handle all different kind of data tree (any namespaces) received from device. say in first notification message i can expect interface module data tree populated in node datastore-contents-xml and in second notification message it can be QoS module data tree.

choice encoding {
case encode-xml

{ anyxml datastore-contents-xml; }

So, during design time, i have no idea which schema to assign for anyxml.

This feature was working fine post beryllium release.

br,
Ambika Prasad Tripathy

Comment by Igor Foltin [ 13/Jul/16 ]

Hi Ambika, you need to have a schema assigned just for the anyxml element itself, not for its contents.

Moreover, I still do not have enough info to reproduce the issue.

Maybe you could upload a patch with a unit test which would show how exactly does the issue occur.

Thanks,

Igor

Comment by Ryan Goulding [ 19/Jul/16 ]

Casting a leaf as anyxml is not supported. If you have further information to provide, please add a comment and we can re-open this bug.

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