[MDSAL-17] Simplify InstanceIdentifer creation Created: 28/May/14  Updated: 13/Sep/18  Resolved: 13/Sep/18

Status: Resolved
Project: mdsal
Component/s: Binding V2 codegen
Affects Version/s: None
Fix Version/s: None

Type: Improvement
Reporter: Devin Avery Assignee: Jie Han
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Operating System: Mac OS
Platform: PC


Issue Links:
Blocks
is blocked by MDSAL-237 Milestone: Implement Binding Specific... Resolved
Relates
relates to MDSAL-308 leaf-ref to InstanceIdentifier Resolved

 Description   

Creating instance identifiers to identify particular nodes has proved cumbersome enough that most projects which have to create an instance identifier end up using helper classes.

We should look at ways to simplify the instance ID creation, possibly by providing helper or utilities.

Suggestion: Start by looking at the helper classes that have been created and consider consolidating them.



 Comments   
Comment by Tony Tkacik [ 15/Jul/14 ]

Instance IDentifier provides utilities
such as
create().

Instance Identifier allows for fluent APIs and creating child identifiers from parent ones:
NODE_ID = InstanceIdentifier.create(Nodes.class).child(Node.class,new NodeKey("foo"));
AUG_ID = NODE_ID.augmentation(NodeAugmentation.class);

Comment by Tom Pantelis [ 30/Jul/14 ]

I don't think Devin is referring to the InstanceIdentifier API but figuring out how to build correct a IID from a yang data model, i.e. what generated classes to use and how to stitch them together.

One thing is to eliminate the need for explicitly specifying augmentation, Eg instead of:

InstanceIdentifier.create(Nodes.class)
.child(Node.class,new NodeKey("foo"))
.augmentation(NodeAugmentation.class);

possibly:

InstanceIdentifier.create(Nodes.class)
.child(NodeAugmentation.class,new NodeKey("foo"));

The API could implicitly figure out that NodeAugmentation augments Node.

It would be really cool if the generated code had a static getInstanceIdentifier() method. So one could simply call NodeAugmentation.getInstanceIdentifier(NodeKey nodeKey) and let that build it for you.

At the very least, we could add helper classes for the common boilerplate stuff, eg NodeInstanceIdentifier.create(NodeKey nodeKey).

Comment by Robert Varga [ 13/Nov/15 ]

Move to MD-SAL, as it requires support from the binding spec.

Comment by Jie Han [ 05/Feb/18 ]

https://git.opendaylight.org/gerrit/67909
https://git.opendaylight.org/gerrit/67910

Comment by Robert Varga [ 28/Jun/18 ]

Problem here is that we really need that Node.class, which means we need to reflect/cache NodeAugmentation.class shape, so we know to derive the type from 'implements Augmentation<Node>. That is doable.

Getting getInstanceIdentifier() ... I am not sure that's possible with the current state of affairs – I am afraid all we can do is getPathArgument(NodeKey) due to groupings and nested lists, but the problem is that:

  • it bloats codegen classes
  • it does not really save that much code
Generated at Wed Feb 07 20:08:25 UTC 2024 using Jira 8.20.10#820010-sha1:ace47f9899e9ee25d7157d59aa17ab06aee30d3d.