ConfD User Community

How to order the leafs inside a list


#1

I am using a Java API and when i am trying to construct the values for getIteratorObjectList()
which is List < ConfValue[ ] > I need to sort the elements according to the order they are contained in the YANG model.

Is there any API that I can use so as to traverse the tree in the correct order so as to assign the proper values ?

i.e. { ConfValue[element1], ConfValue[element2], …, ConfValue[last Element of the YANG list]

Thanx,


#2

Schema is available in runtime using MaapiSchemas and its nested classes, in particular CSNode. Note that before using that the application needs to load schema (Maapi.loadSchema) - this needs to be done once per application lifetime. See the javadoc documentation for more details.


#3

So there is no direct API function to get this info. I need to load the schema, get CsNodes and iterate of the the children and somehow store the “order” in our code logic.

But why do you say “… needs to load schema ( Maapi.loadSchema ) - this needs to be done once per application lifetime…”

I am referring to your statement related to “once…”. What is the problem if i reload the schema multiple times ?


#4

Direct? Well, you need a sequence of three function calls to get that data if the only thing you have is your current path. In my eyes this is direct enough, but that’s obviously a matter of opinion.

The point was that you do not need to call loadSchema more than once. It should do nothing wrong if you do it repeatedly - it just returns the previously loaded instance; see the documentation.


#5

Ok may be I was not clear enough.
confD is calling getIteratorObjectList…
In there i need to create a confValue[ ] , but they have to be in order they are defined in the YANG tree.

container myContainer {
list myList {
key name;
leaf String name;
leaf String field2;
leaf String field3
leaf String field4;
}
}

This order i am looking for. I mean how can i now that first i must add name(ConfValue) then field1(ConfValue), then field2(ConfValue) and last field3(ConfValue).

Any suggestion with concreate functions ?

Thanx,


#6

There is an example in the Javadoc for doc/api/java/com/tailf/maapi/MaapiSchemas.html that may be of help.


#7

I need actually the implementation of
MaapiSchemasUtil.printNodeInfo(offset, n);
MaapiSchemasUtil.printChildren(offset, n);

so as to store the structure internally for our purposes


#8

See conf-api-src-7.1/src/com/tailf/maapi/MaapiSchemasUtil.java from $CONFD_DIR/java/jar/conf-api-src-7.1.jar


#9

Hi,

Just a last question relative to the previous one.
After the following lines

Socket s = new Socket(“localhost”, Conf.PORT);
// Start MAAPI session for admin user, originating from localhost
Maapi maapi = new Maapi(s);
// get Maapi schema object
//MaapiSchemas are ex
s.close();

Do we have all the info for the yang tree cached and loaded in the maapi object ?
I mean any call after this e.g Maapi.getSchemas().getLoadedSchemas()
is not really accessing confd ? I mean no extra networks resources are required. Neither any connection is taking place between our application and confd !
Is this valid ?


#10

Yes, this is correct - Maapi.loadSchemas loads complete runtime schema data from confd in the first call, any further schema access uses this data and no networking is needed.