Ask Your Question
0

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>

YANG:

  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 */

Impl.java

@Override
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();
    listNode.add(node1);
    listNode.add(node2);

    DeviceInfo operationalData = new DeviceInfoBuilder()
    .setName("Test Name")
    .setDescription("Test Desc")
    .setNode(listNode)
    .build();

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

    tx.put(LogicalDatastoreType.OPERATIONAL, DEVICE_IID, operationalData);
    tx.submit();

    LOG.info("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
1

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 = tx.read(LogicalDatastoreType.OPERATIONAL, id).get();
String desc = node.getDescription();
edit flag offensive delete publish link more
Login/Signup to Answer

Question Tools

Follow
3 followers

Stats

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

Seen: 261 times

Last updated: Aug 31 '15