Skip to content

Commit 981f982

Browse files
d-w-moorealanking
authored andcommitted
[irods/irods#6465] py_remote now recognizes INST_NAME tag
In the second parameter of the remote execution microservice, we can now use INST_NAME to specify which rule engine plugin instance on the remote host should be used to execute the given rule text.
1 parent 0a82344 commit 981f982

2 files changed

Lines changed: 27 additions & 2 deletions

File tree

README.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,22 @@ This version of the Python Rule Engine Plugin uses the Python 2.7 interpreter.
5858

5959
# Remote Execution
6060

61-
There exists a requirement for the implementation of a different ```remote``` microservice call for every rule language. Given the possibility of a namespace collision with more than one rule language being configured simultaneously, the name of the microservice to use for the python language is ```py_remote()```.
61+
There exists a requirement for the implementation of a different `remote` microservice call for every rule language. Given the possibility of a namespace collision with more than one rule language being configured simultaneously, the name of the microservice to use for the python language is `py_remote()`. As with remote execution via the native rule engine, this microservice runs the given rule text on the remote host using `exec_rule_text`. This can be done on any iRODS host (inside or outside the local zone) where the invoking user is authenticated.
62+
63+
The microservice's signature is: `py_remote(hostname, hints, code, recovery)`.
64+
65+
Its four parameters are strings:
66+
- `hostname`. The name of the iRODS server where the code is to be executed.
67+
- `hints`. A string containing optional XML tags. Currently scanned only for the `INST_NAME` tag, and other tags - if used - will be ignored. This
68+
includes <ZONE>, since the zone (whether remote or local) is inferred from the `hostname` parameter.
69+
- `code`. The Python source code to be executed, in the form of a complete rule, i.e.: `def main(rule_args,callback,rei): ...`
70+
- `recovery`. This is currently unused.
6271

6372
For example:
6473
```
6574
def main(rule_args, callback, rei):
6675
rule_code = "def main(rule_args, callback, rei):\n print('This is a test of the Python Remote Rule Execution')"
67-
callback.py_remote('icat.example.org', '', rule_code, '')
76+
callback.py_remote('icat.example.org', '<INST_NAME>irods_rule_engine_plugin-python-instance</INST_NAME>', rule_code, '')
6877
INPUT null
6978
OUTPUT ruleExecOut
7079
```

irods_rule_engine_plugin-python.cxx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
#include <fstream>
66
#include <list>
77
#include <string>
8+
#include <vector>
9+
#include <map>
810
#include <memory>
911
#include <mutex>
1012

@@ -25,6 +27,9 @@
2527
#include "msParam.h"
2628
#include "rsExecMyRule.hpp"
2729

30+
// Can delete this in favor of #include <irods/reFuncDefs.hpp> , on resolution of irods/irods #6545:
31+
std::map<std::string, std::vector<std::string>> getTaggedValues(const char *str);
32+
2833
#include "irods_rule_engine_plugin-python.hpp"
2934

3035
#define register
@@ -98,11 +103,22 @@ static int remote_exec_msvc(
98103
META_STR_LEN,
99104
"%s", rule_text.c_str());
100105

106+
// TODO:
107+
// It is not yet known whether execCondition is actually used by rsExecMyRule or
108+
// any functions it calls. If in resolution of [irods/irods#6567] we find it is
109+
// unused, the following addKeyVal call may be unnecessary.
101110
addKeyVal(
102111
&exec_inp.condInput,
103112
"execCondition",
104113
static_cast<char*>(_pa->inOutStruct));
105114

115+
auto taggedValues = getTaggedValues(static_cast<char*>(_pa->inOutStruct));
116+
auto it = taggedValues.find("INST_NAME");
117+
if ( it != taggedValues.end() ) {
118+
addKeyVal( &exec_inp.condInput, INSTANCE_NAME_KW, it->second.front().c_str());
119+
taggedValues.erase(it);
120+
}
121+
106122
msParamArray_t *out_arr = NULL;
107123
return rsExecMyRule(
108124
_rei->rsComm,

0 commit comments

Comments
 (0)