[OPEN-ILS-DEV] OpenSRF 101

Dan Scott dan at coffeecode.net
Sat Oct 30 03:59:59 EDT 2010


On Fri, Oct 29, 2010 at 09:01:07PM -0400, Michael J. Giarlo wrote:
> Hi y'all,
> 
> I've been toying with the idea of using OpenSRF as an architecture for
> gluing together a suite of curation services.  Today I decided to read
> the OpenSRF 1.6.1 install doc and Dan Scott's "Easing Gently into
> OpenSRF," both of which were extraordinarily helpful.
> 
> But now I'm stumped.  I have included some narrative, log snippets,
> config file snippets, etc. in the following gist:
> 
>      http://gist.github.com/654730
> 
> In short: OpenSRF appears to be running fine, since I can utilize the
> opensrf.math.add method via srfsh, but I can't hook my own
> Python-based service into OpenSRF.
> 
> I'm convinced it's something obvious.  Any hints?  I'd be happy to
> provide more information, too.

It's not obvious, because the number of actual Python-based OpenSRF
services to my knowledge to date has been incredibly close to 0. Which
means that I, for one, am delighted and excited to try and work through
this with you.

First up: your config settings look pretty good to me. Bravo! One thing
to point out, though, is that the Python service needs to be implemented
as a module available from sys.path, and the name of the module is what
you need to specify as the content of the <implementation> element in
the application config section. So I copied osrf_reverse.py to
/usr/lib/python2.6/site-packages/. and changed
<implementation>osrf.test</implementation> to
<implementation>osrf_reverse</implementation>

Second: to start the Python service, you don't run it directly; instead,
you use the Python controller script to run it (similar to how
osrf_ctl.sh invokes opensrf-perl.pl to start the Perl services). This
controller script can be found in src/python/opensrf.py - we don't
install it into /openils/bin/ yet because nobody was using Python in
OpenSRF yet - so let's give it a shot with the following (using "-l"
assuming that we're pointing to the "<localhost>" set of services) as
the opensrf user:

opensrf.py -l -p /openils/var/run/ -f /openils/conf/opensrf_core.xml -a start_all

If you get an error that ends in:

    File "/usr/lib/python2.6/site-packages/dns/resolver.py", line 672, in
query
    raise NXDOMAIN
dns.resolver.NXDOMAIN

... this is a painful Python DNS issue that is fortunately nicely
documented in the OpenSRF README - see "dnsmasq".

Once that's out of the way, I get:

[opensrf at dbs ~]$ opensrf.py -l -p /openils/var/run/ -f
/openils/conf/opensrf_core.xml -a start_all
* starting all services for localhost 
* starting opensrf.test

(Aside - should have used the "-d" flag to daemonize it, oh well).

Now we test srfsh:

[opensrf at dbs ~]$ srfsh
srfsh# request opensrf.test opensrf.test.reverse "neckbeard"

Received Data: "d"
Received Data: "r"
Received Data: "a"
Received Data: "e"
Received Data: "b"
Received Data: "k"
Received Data: "c"
Received Data: "e"

------------------------------------
Request Completed Successfully
Request Time in seconds: 0.049928
------------------------------------

YAY! Looks like an off-by-one error on the "n" but 
otherwise that's what we want.

So... yes, the Python bindings for OpenSRF as a service implementation
language work, but I wouldn't be surprised if you found some corner
cases as you work through it. However, given an actual user of this
code, I'll be happy to put some energy into refining the packaging to
(for example) get opensrf.py installed if people choose --enable-python,
provide some more examples / test cases, put together some docs, etc.


More information about the Open-ils-dev mailing list