Python Rule Engine (iRODS 4.2)

416 views
Skip to first unread message

Henrique Nogueira

unread,
Aug 1, 2016, 2:02:38 PM8/1/16
to iRODS-Chat
Good afternoon,

I have been working with the new iRODS Python Rule Engine, available for iRODS 4.2 (unstable) and what I am currently trying to achieve is to call a user defined rule (test_rule, for instance) with parameters:

In my core.py, I have:

def test_rule(rule_args, callback):
    callback.writeLine('serverLog', rule_args)
    for arg in rule_args:
        callback.writeLine('serverLog', arg)

When I run the following command:

$ irule test_rule *A=123 "null"

I got the following line on the server logs:

[TIMESTAMP] [PID] NOTICE: writeLine: inString = []       # This log entry refers to the first callback.writeLine call on my rule. It prints an empty rule_args list. 
                                                                                          # No lines are printed for the rule_args elements.

From what I have seen, the problem appears to be the lack of mapping input args to python function. Am I doing something wrong? Does this problem really exist and needs to be fixed?

Regarding my environment, I am using Ubuntu 14.04 and iRODS unstable release 4.2 (from unstable.irods.org).

Thanks!

Regards,
-Henrique

Rick Skarbez

unread,
Oct 11, 2016, 8:40:26 PM10/11/16
to irod...@googlegroups.com
Hi Henrique--

Very sorry to have not responded sooner, but we wanted to get the 4.2 and python rule engine engineering preview out first, so our answers would be accurate.

rule_args is used to pass the pluggable rule engine parameters, so when using irule, this won't contain the information that you're looking for. Strictly speaking, the input parameters listed after the rule name are considered global variables in the rule engine. The newest version of the python rule engine (available now from our github repo: https://github.com/irods/irods_rule_engine_plugin_python, and by the end of the week on unstable.irods.org) exposes those variables as a dictionary called global_vars.

So your test rule could be rewritten as

def testRule2(irods_pluggable_rule_engine_parameters, callback):
    callback.writeLine('serverLog', str(global_vars))
    for var in global_vars:
        callback.writeLine('serverLog', var + ' : ' + global_vars[var])

and then called as

$ irule -r irods_rule_engine_plugin-python-instance testRule2 *A=123 "null"

(The -r flag specifies which rule engine instance to run the rule on, in the case you have multiple rule engines configured in your server_config.json. If you leave out the -r option, iRODS will attempt to execute the rule on the first rule engine defined in the rule_engines stanza in the server_config.json file.)

This will produce the desired output:

Oct 11 20:25:50 pid:5413 NOTICE: writeLine: inString = {'': '', '*A': '123'}
Oct 11 20:25:50 pid:5413 NOTICE: writeLine: inString =  :
Oct 11 20:25:50 pid:5413 NOTICE: writeLine: inString = *A : 123

(The second line represents the "null" output variable.)

Furthermore, since all the functionality of Python is exposed, you can print to the log without using the writeLine microservice, i.e.

def testRule3(irods_pluggable_rule_engine_parameters, callback):
    print str(global_vars)
    for var in global_vars:
        print var + ' : ' + global_vars[var]

which produces the output

{'': '', '*A': '123'}
 :
*A : 123

We're very excited to have people using the Python rule engine so we can make sure that we expose all the needed behavior, so please don't hesitate to ask us any more questions, and let us know if you run into any other difficulties. Sorry again about the wait, but we hope it was worth it.

-rick







--
--
"iRODS: the Integrated Rule-Oriented Data-management System; A community driven, open source, data grid software solution" https://www.irods.org
 
iROD-Chat: http://groups.google.com/group/iROD-Chat

---
You received this message because you are subscribed to the Google Groups "iRODS-Chat" group.
To unsubscribe from this group and stop receiving emails from it, send an email to irod-chat+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages