Ask Your Question

dataBroker how to get specified node of list from data tree

asked 2015-08-31 03:12:24 -0700

kevin5476 gravatar image

updated 2015-08-31 03:14:20 -0700

If I make a List<node> and put it in DeviceInfo</node>


  container device-info {
  leaf name {
    type string;
    config false;

  leaf description {
    type string;
    config false;

  list node {
      key "id";
      leaf id {
          type string;
      leaf description {
          type string;
} /* End container */

public void onSessionInitiated(ProviderContext session) {

    db = session.getSALService(DataBroker.class);
    notificationService = session.getSALService(NotificationProviderService.class);

    List<Node> listNode = new LinkedList<Node>();
    Node node1 = new NodeBuilder().setId("1").setDescription("this is the first node").build();
    Node node2 = new NodeBuilder().setId("2").setDescription("this is the second node").build();

    DeviceInfo operationalData = new DeviceInfoBuilder()
    .setName("Test Name")
    .setDescription("Test Desc")

    WriteTransaction tx = db.newWriteOnlyTransaction();
    InstanceIdentifier<DeviceInfo> DEVICE_IID = InstanceIdentifier.builder(DeviceInfo.class).build();

    tx.put(LogicalDatastoreType.OPERATIONAL, DEVICE_IID, operationalData);
    tx.submit();"HelloProvider Session Initiated");

How do I get the description(leaf) of the particular ID(key) ?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2015-08-31 06:27:07 -0700

Robert Varga gravatar image

updated 2015-08-31 06:28:54 -0700

Leaves are not directly addressable via InstanceIdentifier. In order to fetch them, you need to read the container in where these reside, in this case a keyed item, hence:

InstanceIdentifier<Node> id = InstanceIdentifier.create(DeviceInfo.class).child(Node.class, new NodeKey("1"));
ReadOnlyTransaction tx = db.newReadOnlyTransactio();
Node node =, id).get();
String desc = node.getDescription();
edit flag offensive delete publish link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

[hide preview]

Question Tools



Asked: 2015-08-31 03:12:24 -0700

Seen: 253 times

Last updated: Aug 31 '15