2018-02-25 20:28:05 +00:00
|
|
|
Multi script langyage Stream Processing Offload Agent
|
|
|
|
-----------------------------------------------------
|
2018-02-23 10:40:03 +00:00
|
|
|
|
2018-02-25 20:28:05 +00:00
|
|
|
This agent receive SPOP message and process it with script languages. The
|
|
|
|
language register callback with a message. Each callback receive the list
|
|
|
|
of arguments with types according with the language capabilities. The
|
|
|
|
callback write variables which are sent as response when the processing
|
|
|
|
is done.
|
|
|
|
|
|
|
|
|
2019-07-03 08:16:17 +00:00
|
|
|
Prerequirement
|
|
|
|
----------------
|
|
|
|
|
|
|
|
You have to install the development packages, either from the
|
|
|
|
distribution repositories or from the source.
|
|
|
|
|
MAJOR: contrib: porting spoa_server to support python3
Background:
Python 2 is no longer supported since January, 1st 2020 as per
https://www.python.org/doc/sunset-python-2/
The purpose of this change is to make the spoa_server contrib library
compatible with Python 3 to allow transition to Python 3.
Test Settings:
ps_python.py:
...
spoa.set_var_null("null", spoa.scope_txn)
spoa.set_var_boolean("boolean", spoa.scope_txn, True)
spoa.set_var_int32("int32", spoa.scope_txn, 1234)
spoa.set_var_uint32("uint32", spoa.scope_txn, 1234)
spoa.set_var_int64("int64", spoa.scope_txn, 1234)
spoa.set_var_uint64("uint64", spoa.scope_txn, 1234)
spoa.set_var_ipv4("ipv4", spoa.scope_txn, ipaddress.IPv4Address(u"127.0.0.1"))
spoa.set_var_ipv6("ipv6", spoa.scope_txn, ipaddress.IPv6Address(u"1::f"))
spoa.set_var_str("str", spoa.scope_txn, "1::f")
spoa.set_var_bin("bin", spoa.scope_txn, "1:\x01:\x42f\x63\x63")
spoa.set_var_str("python_version", spoa.scope_sess, str(sys.version_info))
...
haproxy.cfg:
...
http-request capture var(txn.verb.null),debug len 1
http-request capture var(txn.verb.boolean),debug len 1
http-request capture var(txn.verb.int32),debug len 4
http-request capture var(txn.verb.uint32),debug len 4
http-request capture var(txn.verb.int64),debug len 4
http-request capture var(txn.verb.uint64),debug len 4
http-request capture var(txn.verb.ipv4),debug len 16
http-request capture var(txn.verb.ipv6),debug len 45
http-request capture var(txn.verb.str),debug len 32
http-request capture var(txn.verb.bin),debug len 32
http-request capture var(sess.verb.python_version),debug len 100
...
Test result:
Python 3.8:
ft_public ft_public/<NOSRV> 0/-1/-1/-1/0 403 212 - - PR-- 1/1/0/0/0 0/0 {|1|1234|1234|1234|1234|127.0.0.1|1::f|1::f|1:#01:Bfcc|sys.version_info(major=3, minor=8, micro=1, releaselevel='final', serial=0)} "POST / HTTP/1.1"
Python 3.7:
ft_public ft_public/<NOSRV> 0/-1/-1/-1/0 403 212 - - PR-- 1/1/0/0/0 0/0 {|1|1234|1234|1234|1234|127.0.0.1|1::f|1::f|1:#01:Bfcc|sys.version_info(major=3, minor=7, micro=6, releaselevel='final', serial=0)} "POST / HTTP/1.1"
Python 3.6:
ft_public ft_public/<NOSRV> 0/-1/-1/-1/0 403 212 - - PR-- 1/1/0/0/0 0/0 {|1|1234|1234|1234|1234|127.0.0.1|1::f|1::f|1:#01:Bfcc|sys.version_info(major=3, minor=6, micro=10, releaselevel='final', serial=0)} "POST / HTTP/1.1"
Python 2.7:
ft_public ft_public/<NOSRV> 0/-1/-1/-1/0 403 212 - - PR-- 1/1/0/0/0 0/0 {|1|1234|1234|1234|1234|127.0.0.1|1::f|1::f|1:#01:Bfcc|sys.version_info(major=2, minor=7, micro=17, releaselevel='final', serial=0)} "POST / HTTP/1.1"
Not tested:
Python <2.7
2020-05-06 12:25:31 +00:00
|
|
|
CentOS/RHEL: sudo yum install python3-devel
|
2019-07-03 08:16:17 +00:00
|
|
|
|
MAJOR: contrib: porting spoa_server to support python3
Background:
Python 2 is no longer supported since January, 1st 2020 as per
https://www.python.org/doc/sunset-python-2/
The purpose of this change is to make the spoa_server contrib library
compatible with Python 3 to allow transition to Python 3.
Test Settings:
ps_python.py:
...
spoa.set_var_null("null", spoa.scope_txn)
spoa.set_var_boolean("boolean", spoa.scope_txn, True)
spoa.set_var_int32("int32", spoa.scope_txn, 1234)
spoa.set_var_uint32("uint32", spoa.scope_txn, 1234)
spoa.set_var_int64("int64", spoa.scope_txn, 1234)
spoa.set_var_uint64("uint64", spoa.scope_txn, 1234)
spoa.set_var_ipv4("ipv4", spoa.scope_txn, ipaddress.IPv4Address(u"127.0.0.1"))
spoa.set_var_ipv6("ipv6", spoa.scope_txn, ipaddress.IPv6Address(u"1::f"))
spoa.set_var_str("str", spoa.scope_txn, "1::f")
spoa.set_var_bin("bin", spoa.scope_txn, "1:\x01:\x42f\x63\x63")
spoa.set_var_str("python_version", spoa.scope_sess, str(sys.version_info))
...
haproxy.cfg:
...
http-request capture var(txn.verb.null),debug len 1
http-request capture var(txn.verb.boolean),debug len 1
http-request capture var(txn.verb.int32),debug len 4
http-request capture var(txn.verb.uint32),debug len 4
http-request capture var(txn.verb.int64),debug len 4
http-request capture var(txn.verb.uint64),debug len 4
http-request capture var(txn.verb.ipv4),debug len 16
http-request capture var(txn.verb.ipv6),debug len 45
http-request capture var(txn.verb.str),debug len 32
http-request capture var(txn.verb.bin),debug len 32
http-request capture var(sess.verb.python_version),debug len 100
...
Test result:
Python 3.8:
ft_public ft_public/<NOSRV> 0/-1/-1/-1/0 403 212 - - PR-- 1/1/0/0/0 0/0 {|1|1234|1234|1234|1234|127.0.0.1|1::f|1::f|1:#01:Bfcc|sys.version_info(major=3, minor=8, micro=1, releaselevel='final', serial=0)} "POST / HTTP/1.1"
Python 3.7:
ft_public ft_public/<NOSRV> 0/-1/-1/-1/0 403 212 - - PR-- 1/1/0/0/0 0/0 {|1|1234|1234|1234|1234|127.0.0.1|1::f|1::f|1:#01:Bfcc|sys.version_info(major=3, minor=7, micro=6, releaselevel='final', serial=0)} "POST / HTTP/1.1"
Python 3.6:
ft_public ft_public/<NOSRV> 0/-1/-1/-1/0 403 212 - - PR-- 1/1/0/0/0 0/0 {|1|1234|1234|1234|1234|127.0.0.1|1::f|1::f|1:#01:Bfcc|sys.version_info(major=3, minor=6, micro=10, releaselevel='final', serial=0)} "POST / HTTP/1.1"
Python 2.7:
ft_public ft_public/<NOSRV> 0/-1/-1/-1/0 403 212 - - PR-- 1/1/0/0/0 0/0 {|1|1234|1234|1234|1234|127.0.0.1|1::f|1::f|1:#01:Bfcc|sys.version_info(major=2, minor=7, micro=17, releaselevel='final', serial=0)} "POST / HTTP/1.1"
Not tested:
Python <2.7
2020-05-06 12:25:31 +00:00
|
|
|
The current minimal python version compatible with this library is 2.7.
|
|
|
|
It's recommended to use python version 3 where possible due to python 2 deprecation.
|
2019-07-03 08:16:17 +00:00
|
|
|
|
|
|
|
|
2018-02-25 20:28:05 +00:00
|
|
|
Compilation
|
|
|
|
---------------
|
|
|
|
|
2020-08-01 14:28:52 +00:00
|
|
|
The server currently supports Lua and Python. Type "make" with the options:
|
2018-02-25 20:28:05 +00:00
|
|
|
USE_LUA=1 and/or USE_PYTHON=1.
|
2018-02-23 10:40:03 +00:00
|
|
|
|
2019-07-03 08:16:17 +00:00
|
|
|
You can add LUA_INC=.. LUA_LIB=.. to the make command to set the paths to
|
|
|
|
the lua header files and lua libraries.
|
2018-02-23 10:40:03 +00:00
|
|
|
|
MAJOR: contrib: porting spoa_server to support python3
Background:
Python 2 is no longer supported since January, 1st 2020 as per
https://www.python.org/doc/sunset-python-2/
The purpose of this change is to make the spoa_server contrib library
compatible with Python 3 to allow transition to Python 3.
Test Settings:
ps_python.py:
...
spoa.set_var_null("null", spoa.scope_txn)
spoa.set_var_boolean("boolean", spoa.scope_txn, True)
spoa.set_var_int32("int32", spoa.scope_txn, 1234)
spoa.set_var_uint32("uint32", spoa.scope_txn, 1234)
spoa.set_var_int64("int64", spoa.scope_txn, 1234)
spoa.set_var_uint64("uint64", spoa.scope_txn, 1234)
spoa.set_var_ipv4("ipv4", spoa.scope_txn, ipaddress.IPv4Address(u"127.0.0.1"))
spoa.set_var_ipv6("ipv6", spoa.scope_txn, ipaddress.IPv6Address(u"1::f"))
spoa.set_var_str("str", spoa.scope_txn, "1::f")
spoa.set_var_bin("bin", spoa.scope_txn, "1:\x01:\x42f\x63\x63")
spoa.set_var_str("python_version", spoa.scope_sess, str(sys.version_info))
...
haproxy.cfg:
...
http-request capture var(txn.verb.null),debug len 1
http-request capture var(txn.verb.boolean),debug len 1
http-request capture var(txn.verb.int32),debug len 4
http-request capture var(txn.verb.uint32),debug len 4
http-request capture var(txn.verb.int64),debug len 4
http-request capture var(txn.verb.uint64),debug len 4
http-request capture var(txn.verb.ipv4),debug len 16
http-request capture var(txn.verb.ipv6),debug len 45
http-request capture var(txn.verb.str),debug len 32
http-request capture var(txn.verb.bin),debug len 32
http-request capture var(sess.verb.python_version),debug len 100
...
Test result:
Python 3.8:
ft_public ft_public/<NOSRV> 0/-1/-1/-1/0 403 212 - - PR-- 1/1/0/0/0 0/0 {|1|1234|1234|1234|1234|127.0.0.1|1::f|1::f|1:#01:Bfcc|sys.version_info(major=3, minor=8, micro=1, releaselevel='final', serial=0)} "POST / HTTP/1.1"
Python 3.7:
ft_public ft_public/<NOSRV> 0/-1/-1/-1/0 403 212 - - PR-- 1/1/0/0/0 0/0 {|1|1234|1234|1234|1234|127.0.0.1|1::f|1::f|1:#01:Bfcc|sys.version_info(major=3, minor=7, micro=6, releaselevel='final', serial=0)} "POST / HTTP/1.1"
Python 3.6:
ft_public ft_public/<NOSRV> 0/-1/-1/-1/0 403 212 - - PR-- 1/1/0/0/0 0/0 {|1|1234|1234|1234|1234|127.0.0.1|1::f|1::f|1:#01:Bfcc|sys.version_info(major=3, minor=6, micro=10, releaselevel='final', serial=0)} "POST / HTTP/1.1"
Python 2.7:
ft_public ft_public/<NOSRV> 0/-1/-1/-1/0 403 212 - - PR-- 1/1/0/0/0 0/0 {|1|1234|1234|1234|1234|127.0.0.1|1::f|1::f|1:#01:Bfcc|sys.version_info(major=2, minor=7, micro=17, releaselevel='final', serial=0)} "POST / HTTP/1.1"
Not tested:
Python <2.7
2020-05-06 12:25:31 +00:00
|
|
|
Similarly, you can add PYTHON_INC=.. PYTHON_LIB=.. to the make command to set the paths to
|
|
|
|
the python header files and python libraries.
|
|
|
|
By default, it will try to compile by detecting the default python 3 parameters.
|
|
|
|
It will fall back to python 2 if python 3 is not available.
|
|
|
|
|
2018-02-23 10:40:03 +00:00
|
|
|
Start the service
|
|
|
|
---------------------
|
|
|
|
|
|
|
|
After you have compiled it, to start the service, you just need to use "spoa"
|
|
|
|
binary:
|
|
|
|
|
|
|
|
$> ./spoa -h
|
|
|
|
Usage: ./spoa [-h] [-d] [-p <port>] [-n <num-workers>]
|
|
|
|
-h Print this message
|
|
|
|
-d Enable the debug mode
|
|
|
|
-p <port> Specify the port to listen on (default: 12345)
|
|
|
|
-n <num-workers> Specify the number of workers (default: 5)
|
2018-02-25 20:28:05 +00:00
|
|
|
-f <file> Load script according with the supported languages
|
2018-02-23 10:40:03 +00:00
|
|
|
|
2018-02-25 20:28:05 +00:00
|
|
|
The file processor is recognized using the extension. .lua or .luac for lua and
|
|
|
|
.py for python. Start example:
|
2018-02-23 10:40:03 +00:00
|
|
|
|
2018-02-25 20:28:05 +00:00
|
|
|
$> ./spoa -d -f ps_lua.lua
|
2018-02-23 10:40:03 +00:00
|
|
|
|
2019-06-11 14:08:53 +00:00
|
|
|
$> ./spoa -d -f ps_python.py
|
2018-02-23 10:40:03 +00:00
|
|
|
|
|
|
|
|
2018-02-25 20:28:05 +00:00
|
|
|
Configure
|
|
|
|
-------------
|
2018-02-23 10:40:03 +00:00
|
|
|
|
2018-02-25 20:28:05 +00:00
|
|
|
Sample configuration are join to this server:
|
2018-02-23 10:40:03 +00:00
|
|
|
|
2018-02-25 20:28:05 +00:00
|
|
|
spoa-server.conf : The HAProxy configuration file using SPOE server
|
|
|
|
spoa-server.spoe.conf : The SPOP description file used by HAProxy
|
|
|
|
ps_lua.lua : Processing Lua example
|
|
|
|
ps_python.py : Processing Python example
|
2018-02-23 10:40:03 +00:00
|
|
|
|
|
|
|
|
2018-02-25 20:28:05 +00:00
|
|
|
Considerations
|
|
|
|
------------------
|
2018-02-23 10:40:03 +00:00
|
|
|
|
2018-02-25 20:28:05 +00:00
|
|
|
This server is a beta version. It works fine, but some improvement will be
|
|
|
|
welcome:
|
2018-02-23 10:40:03 +00:00
|
|
|
|
2018-02-25 20:28:05 +00:00
|
|
|
Main process:
|
2018-02-23 10:40:03 +00:00
|
|
|
|
2018-02-25 20:28:05 +00:00
|
|
|
* Improve log management: Today the log are sent on stdout.
|
|
|
|
* Improve process management: The dead process are ignored.
|
|
|
|
* Implement systemd integration.
|
|
|
|
* Implement threads: It would be fine to implement thread working. Shared
|
|
|
|
memory is welcome for managing database connection pool and something like
|
|
|
|
that.
|
|
|
|
* Add PHP support and some other languages.
|
2018-02-23 10:40:03 +00:00
|
|
|
|
2018-02-25 20:28:05 +00:00
|
|
|
Python:
|
2018-02-23 10:40:03 +00:00
|
|
|
|
2020-03-14 12:47:28 +00:00
|
|
|
* Improve reporting: Catch python error message and report it in the right
|
2018-02-25 20:28:05 +00:00
|
|
|
place. Today the error are dumped on stdout. How using syslog for logging
|
|
|
|
stack traces ?
|
2018-02-23 10:40:03 +00:00
|
|
|
|
2018-02-25 20:28:05 +00:00
|
|
|
Maybe some other things...
|