Connecting to ConfD server from a managed object running erlang application

Hello all,
I am willing to run an erlang application in one of the managed objects and connect to the ConfD server running in a different host system. How do I achieve this? I also want to subscribe to the configuration changes. Please guide me through this. I would appreciate a reply at your earliest convenience. Thankx in advance.

The Erlang API is implemented in the econfd Erlang application - it is for the most part very similar to the C API. The sources for econfd can be found in the $CONFD_DIR/erlang directory in the ConfD installation, with pre-built “edoc” documentation in the $CONFD_DIR/doc/api/econfd directory. In the case of running your Erlang application on a different host than the ConfD daemon, you need to run your own Erlang VM for this.

Sure, i did go through the econfd application and had run few of the examples and also had gone through the edoc but still i didn’t really get the hang of it as the documentation is limited.
Could you please guide me on establishing a connection to the confD daemon running on differnt host from my erlang application? What all modules do i have to have in my erlang application in order to achieve this? and how can i subscribe to configurations and notifications in my erlang application?

Try the example located under $CONFD_DIR/erlang/econfd/examples/test. Quick demo:

$ cd $CONFD_DIR
$ source confdrc
$ cd erlang/econfd
$ make
...
$ cd examples/test
$ make all start
$ make estart
...

See test.erl, procs.erl, simple.erl, iid.erl for examples of different applications connecting and running using the econfd API

I have tried running that but i am getting a error as follows

TRACE CALL validate stop() --> OK
M_TEST_ORDERED(#Port<0.567>)


** test failed at test:1041
in “/home/mazhar/confd-6.6/erlang/econfd/examples/test”
** reason:
{badmatch,{error,{2,<<>>}}}
[{test,m_test_ordered,1,[{file,“test.erl”},{line,1041}]},
{test,maapi,0,[{file,“test.erl”},{line,911}]},
{test,test,2,[{file,“test.erl”},{line,99}]},
{proc_lib,init_p,3,[{file,“proc_lib.erl”},{line,232}]}]


Makefile:67: recipe for target ‘estart’ failed
make: *** [estart] Error 1

whats am i doing wrong here?

You need to debug the issue to find out what is going on… I.e:

** reason:
{badmatch,{error,{2,<<>>}}}
[{test,m_test_ordered,1,[{file,“test.erl”},{line,1041}]},

In test.erl on line 1041:
?line ok = econfd_maapi:create(M, TH, [{?CONFD_INT32(3)}|KP]),

The error code you get is “2”:
erlang/econfd/include/econfd_errors.hrl:-define( CONFD_ERR_ALREADY_EXISTS, 2).

From the C-API confd_lib_libi(3) man page:
CONFD_ERR_ALREADY_EXISTS (2)
We tried to create something which already exists.

So I believe you did a:
$ make all start
$ make estart
$ make stop start
$ make estart
And since you just restarted ConfD using “make stop start” the configuration was still there when you ran the test using “make estart” and hence the test application attempts to create a list entry that already exists.

If you want to run the test again you need to remove the *.cdb files from the confd-cdb directory or just do a “make stop clean all start” instead of just “make stop start”

I think it is fair to say that studying and running the contents of the econfd/examples/test directory in general, and the test.erl module in particular, is not an ideal way to get the hang of how the Erlang API works. The contents of examples/test is primarily intended for testing the econfd application, and while it thus does indeed cover most API functions, it is quite complex, and the relationships between the different Erlang processes it runs are not easy to follow.

I would instead recommend looking primarily at the other directories under econfd/examples, which are more along the lines of other examples in the ConfD installation, trying to illustrate specific APIs and concepts. E.g. if you are specifically interested in subscribing to configuration changes in CDB, have a look at econfd/examples/yaws. All you need to change to run with the ConfD daemon on a different host is to use the appropriate IP address instead of {127,0,0,1} (i.e. the IPv4 loopback address) - just the same as if you were running a C application.

Oh yes, I might have done that. I have tried running the application after cleaning the *.cdb files and it is working absolutely fine now. But I am still not sure what exactly is happening there. By looking at the prints I realized that we are testing the econfd application but not sure what’s going on. And also I didn’t find any README file in the $CONFD_DIR/erlang/econfd/examples/test/ directory. How do i proceed with understanding econfd application more precisely?

Sure per, i would definitely give it a try.