Ask is moving to Stack Overflow and! Please use the "opendaylight" tag on either of these sites. This site is now in Read-Only mode


dataBroker how to put list data to the data tree

asked 2015-08-13 02:25:36 -0800

kevin5476 gravatar image

updated 2015-08-16 18:18:57 -0800

I used yang to create a container to store list data, just like as node-connector data tree.

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

If it is leaf node, I can use below

    DeviceInfo operationalData = new DeviceInfoBuilder()
        .setName("Test Name")
        .setDescription("Test Desc")
    WriteTransaction tx = dataBroker.newWriteOnlyTransaction();
    tx.put(LogicalDatastoreType.OPERATIONAL, Identifier, operationalData);

but I don't know how to put list data into the list node.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2015-08-15 06:33:58 -0800

labry gravatar image

Just make a List<node> and put it in DeviceInfo and don't forget to submit. Since submit is actually putting your data to the Data Store.</node>

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");

for complete reference refer to

You can check the result with apidoc as below. :-D image description

Have fun!


edit flag offensive delete publish link more


Thank you Justin !! It is good information for me. but I have another question, whether I could append data after the completion of the onSessionInitiated ? or I must to get the stored data first and add new one, then put into again.

kevin5476 ( 2015-08-16 18:18:25 -0800 )edit

I'm not sure if I understand your question correctly. But if you're asking me how to add more data into the Data Store. There are a lot of different ways to do it. But if you want to add more data when some RPC is called.

labry ( 2015-08-17 04:49:32 -0800 )edit

You can also do that by making another class file. Refer to this.

labry ( 2015-08-17 04:49:52 -0800 )edit

thanks for your reply ! my question is if I added two nodes into the list in onSessionInitiated, but I want to add node3 into the list in other method (ex: HelloWorldImpl), and I also need to keep node1 and node2. Now, when I .build() new one object and submit data, it will override node1 and node2.

kevin5476 ( 2015-08-18 04:30:55 -0800 )edit

Try merge instead of put in that case. tx.merge(...); tx.submit(); And search for a Java apidoc for OpenDaylight's MD-SAL for the differences. You can google it or look for my answer to somebody else here on ask. :-D

labry ( 2015-08-18 05:32:18 -0800 )edit
Login/Signup to Answer

Question Tools

1 follower


Asked: 2015-08-13 02:25:36 -0800

Seen: 281 times

Last updated: Aug 18 '15