[OPEN-ILS-DEV] Problems writting python services

Vicent Mas uvemas at gmail.com
Wed Nov 30 08:04:29 EST 2011


Hi,

in my Evergreen virtual image (OpenSRF and Evergreen trunk as of
2011-03-19 on Debian Squeeze) I'm trying to write and setup a demo
OSRF service using Python but I'm having some troubles. As I've found
no specific documentation for doing it I'm following the Dan's paper
found at http://journal.code4lib.org/articles/3284 and a thread I got
using google (https://gist.github.com/654730). This is what I've done
until now:

- my Python service lives in a module named test.py which content is:

from osrf.app import Application

class Reverse(Application) :

    def reverse_text(self, request, message='') :
        i = len(message) - 1
        while i :
            request.respond(message[i])
            i = i - 1

    # Register a new method for this application
    Application.register_method(
        api_name = "opensrf.test.reverse",
        method = "reverse_text",
        argc = 1,
        stream = True
    )


# Register an instance of this class as an application
Application.register_app(Reverse())


- create the /openils/lib/python directory and put there my Python
service (module named test.py)
- export PYTHONPATH=/openils/lib/python in the .profile of the opensrf user
- add the following lines to opensrf.xml under the <apps> section

            <opensrf.test>
              <keepalive>3</keepalive>
              <stateless>1</stateless>
              <language>python</language>
              <implementation>test</implementation>
              <max_requests>100</max_requests>
              <unix_config>
                <max_requests>1000</max_requests>
                <unix_log>opensrf.test_unix.log</unix_log>
                <unix_sock>opensrf.test_unix.sock</unix_sock>
                <unix_pid>opensrf.test_unix.pid</unix_pid>
                <min_children>5</min_children>
                <max_children>15</max_children>
                <min_spare_children>2</min_spare_children>
                <max_spare_children>5</max_spare_children>
              </unix_config>
            </opensrf.test>

- add my service to opensrf_core.xml

      <!-- define the list of routers our services will register with -->
      <router>
        <!--
          This is the public router.  On this router, we only register
          applications which should be accessible to everyone on the OpenSRF
          network
        -->
        <name>router</name>
        <domain>public.localhost</domain>

        <services>
          <service>opensrf.test</service>
          <service>opensrf.math</service>
          ....

Now I restart my virtual image, add nameserver 127.0.0.1 to
/etc/resolv.conf, check that dnsmasq is running, start all services
with

$ /openils/bin/osrf_ctl.sh -l -a start_all

and restart the Apache web server. Eventually, as opensrf user I try
to access to the Python service via srfsh:

opensrf at squeeze:~$ srfsh
srfsh# introspect opensrf.test
--> opensrf.test

Received no data from server

------------------------------------
Request Time in seconds: 0.009839
------------------------------------
srfsh# exit

The srfsh log files now says:

srfsh 2011-11-30 06:35:22 [INFO:3338:osrf_system.c:628:] Bootstrapping
system with domain private.localhost, port 5222, and unixpath (none)
srfsh 2011-11-30 06:35:38 [DEBG:3338:osrf_app_session.c:486:]
opensrf.test session is stateless
srfsh 2011-11-30 06:35:38 [DEBG:3338:osrf_app_session.c:497:] Building
a new client session with id [opensrf.test]
[1322652938.572633.13226529383338]
srfsh 2011-11-30 06:35:38
[DEBG:3338:osrf_app_session.c:1044:132265292233380] AppSession in
queue_wait with timeout 0
srfsh 2011-11-30 06:35:38
[DEBG:3338:osrf_app_session.c:759:132265292233380] App Session
[opensrf.test] [1322652938.572633.13226529383338] resetting remote id
to router at private.localhost/opensrf.test
srfsh 2011-11-30 06:35:38
[INFO:3338:osrf_app_session.c:991:132265292233380] [opensrf.test] sent
171 bytes of data to router at private.localhost/opensrf.test
srfsh 2011-11-30 06:35:38
[DEBG:3338:osrf_app_session.c:994:132265292233380] Sent:
[{"__c":"osrfMessage","__p":{"threadTrace":"1","locale":"en-US","type":"REQUEST","payload":{"__c":"osrfMethod","__p":{"method":"opensrf.system.method.all","params":[]}}}}]
srfsh 2011-11-30 06:35:38
[DEBG:3338:osrf_app_session.c:714:132265292233380] Pushing [1] onto
request queue for session [opensrf.test]
[1322652938.572633.13226529383338]
srfsh 2011-11-30 06:35:38
[DEBG:3338:osrf_app_session.c:275:132265292233380] In app_request
receive with remaining time [120]
srfsh 2011-11-30 06:35:38
[DEBG:3338:osrf_app_session.c:1044:132265292233380] AppSession in
queue_wait with timeout 0
srfsh 2011-11-30 06:35:38
[INFO:3338:transport_session.c:667:132265292233380] Received <error>
message with type cancel and code 503
srfsh 2011-11-30 06:35:38 [DEBG:3338:osrf_stack.c:44:132265292233380]
Received message from transport code from
router at private.localhost/opensrf.test
srfsh 2011-11-30 06:35:38 [DEBG:3338:osrf_stack.c:87:132265292233380]
Transport handler received new message
from router at private.localhost/opensrf.test to
opensrf at private.localhost/_squeeze_1322652922.349864_3338 with body

[{"__c":"osrfMessage","__p":{"threadTrace":"1","locale":"en-US","type":"REQUEST","payload":{"__c":"osrfMethod","__p":{"method":"opensrf.system.method.all","params":[]}}}}]

srfsh 2011-11-30 06:35:38 [DEBG:3338:osrf_stack.c:123:132265292233380]
We received 1 messages from router at private.localhost/opensrf.test
srfsh 2011-11-30 06:35:38 [WARN:3338:osrf_stack.c:134:132265292233380]
 !!! Received Jabber layer error message
srfsh 2011-11-30 06:35:38 [WARN:3338:osrf_stack.c:144:132265292233380]
 * Jabber Error is for top level remote  id
[router at private.localhost/opensrf.test], no one to send my message to!
 Cutting request short...
srfsh 2011-11-30 06:35:38 [INFO:3338:osrf_stack.c:159:132265292233380]
Message processing duration 0.000373
srfsh 2011-11-30 06:35:38 [DEBG:3338:osrf_stack.c:162:132265292233380]
after msg delete
srfsh 2011-11-30 06:35:38 [ERR
:3338:osrf_app_session.c:281:132265292233380] Transport error in
recv()
srfsh 2011-11-30 06:35:38
[DEBG:3338:osrf_app_session.c:1063:132265292233380] AppSession
[opensrf.test] [1322652938.572633.13226529383338] destroying self and
deleting requests
srfsh 2011-11-30 06:35:43
[DEBG:3338:socket_bundle.c:482:132265292233380] removing socket 3


Could somebody tell me what I'm doing wrong? I'm really stuck.

TIA

Vicent

PS: sorry tfor the long post.
-- 
Share what you know, learn what you don't.


More information about the Open-ils-dev mailing list