irods  4.2.8
About: iRODS (the integrated Rule Oriented Data System) is a distributed data-management system for creating data grids, digital libraries, persistent archives, and real-time data systems.
  Fossies Dox: irods-4.2.8.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

rsExecMyRule.cpp
Go to the documentation of this file.
1 #include "execMyRule.h"
2 #include "miscServerFunct.hpp"
3 #include "rcMisc.h"
4 #include "irods_re_plugin.hpp"
5 #include "rsExecMyRule.hpp"
6 
7 extern std::unique_ptr<struct irods::global_re_plugin_mgr> irods::re_plugin_globals;
8 
10  rsComm_t* _comm,
11  execMyRuleInp_t* _exec_inp,
12  msParamArray_t** _out_arr ) {
13 
14  if ( _exec_inp == NULL ) {
16  "rsExecMyRule error. NULL input" );
18  }
19 
20  char* available_str = getValByKey(
21  &_exec_inp->condInput,
22  "available" );
23 
24  if ( available_str ) {
25  std::vector< std::string > instance_names;
26  irods::error ret = list_rule_plugin_instances( instance_names );
27 
28  if ( !ret.ok() ) {
29  irods::log( PASS( ret ) );
30  return ret.code();
31  }
32 
33  std::string ret_string = "Available rule engine plugin instances:\n";
34  for ( auto& name : instance_names ) {
35  ret_string += "\t";
36  ret_string += name;
37  ret_string += "\n";
38  }
39 
40  int i = addRErrorMsg( &_comm->rError, 0, ret_string.c_str() );
41  if (i) {
42  irods::log( ERROR( i, "addRErrorMsg failed" ) );
43  }
44  return i;
45  }
46 
47  rodsServerHost_t* rods_svr_host = nullptr;
48  int remoteFlag = resolveHost( &_exec_inp->addr, &rods_svr_host );
49 
50  if ( remoteFlag == REMOTE_HOST ) {
51  return remoteExecMyRule( _comm, _exec_inp,
52  _out_arr, rods_svr_host );
53  }
54 
55  char* inst_name_str = getValByKey(
56  &_exec_inp->condInput,
58  std::string inst_name;
59  if( inst_name_str ) {
60  inst_name = inst_name_str;
61  }
62 
63  ruleExecInfo_t rei;
64  initReiWithDataObjInp( &rei, _comm, NULL );
65  rei.condInputData = &_exec_inp->condInput;
66 
67  /* need to have a non zero inpParamArray for execMyRule to work */
68  if ( _exec_inp->inpParamArray == NULL ) {
69  _exec_inp->inpParamArray =
70  ( msParamArray_t * ) malloc( sizeof( msParamArray_t ) );
71  memset( _exec_inp->inpParamArray, 0, sizeof( msParamArray_t ) );
72  }
73  rei.msParamArray = _exec_inp->inpParamArray;
74 
76 
77  const std::string& my_rule_text = _exec_inp->myRule;
78  const std::string& out_param_desc = _exec_inp->outParamDesc;
82  irods::AUDIT_RULE> re_ctx_mgr(
83  irods::re_plugin_globals->global_re_mgr,
84  &rei);
85  irods::error err = re_ctx_mgr.exec_rule_text(
86  inst_name,
87  my_rule_text,
88  _exec_inp->inpParamArray,
89  out_param_desc);
90  if(inst_name.empty()) {
92  }
93 
94  if(!inst_name.empty() && !err.ok()) {
95  rodsLog(
96  LOG_ERROR,
97  "%s : %d, %s",
98  __FUNCTION__,
99  err.code(),
100  err.result().c_str()
101  );
102  return err.code();
103  }
104 
105  trimMsParamArray( rei.msParamArray, _exec_inp->outParamDesc );
106 
107  *_out_arr = rei.msParamArray;
108  rei.msParamArray = NULL;
109 
110  if (!inst_name.empty() && err.code() < 0 ) {
112  "rsExecMyRule : execMyRule error for %s, status = %d",
113  _exec_inp->myRule, err.code() );
114  return err.code();
115  }
116 
117  return err.code();
118 }
119 
120 int
122  msParamArray_t **_out_arr, rodsServerHost_t *rods_svr_host ) {
123  int status;
124 
125  if ( rods_svr_host == NULL ) {
127  "remoteExecMyRule: Invalid rods_svr_host" );
129  }
130 
131  if ( ( status = svrToSvrConnect( _comm, rods_svr_host ) ) < 0 ) {
132  return status;
133  }
134 
135  status = rcExecMyRule( rods_svr_host->conn, _exec_inp, _out_arr );
136 
137  return status;
138 }
rodsLog
void rodsLog(int level, const char *formatStr,...)
Definition: rodsLog.cpp:86
getValByKey
char * getValByKey(const keyValPair_t *condInput, const char *keyWord)
Definition: rcMisc.cpp:675
NULL
#define NULL
Definition: rodsDef.h:70
irods::unit
std::tuple<> unit
Definition: irods_re_plugin.hpp:736
rsComm_t
Definition: rcConnect.h:145
rcExecMyRule
int rcExecMyRule(rcComm_t *conn, execMyRuleInp_t *execMyRuleInp, msParamArray_t **outParamArray)
Definition: rcExecMyRule.cpp:36
SYS_INTERNAL_NULL_INPUT_ERR
@ SYS_INTERNAL_NULL_INPUT_ERR
Definition: rodsErrorTable.h:92
rodsServerHost::conn
rcComm_t * conn
Definition: rodsConnect.h:64
irods::rule_engine_context_manager
Definition: irods_re_plugin.hpp:522
PASS
#define PASS(prev_error_)
Definition: irods_error.hpp:118
ExecMyRuleInp::outParamDesc
char outParamDesc[256]
Definition: execMyRule.h:13
ExecMyRuleInp::condInput
keyValPair_t condInput
Definition: execMyRule.h:12
REMOTE_HOST
#define REMOTE_HOST
Definition: rodsConnect.h:45
rcMisc.h
execMyRule.h
list_rule_plugin_instances
irods::error list_rule_plugin_instances(std::vector< std::string > &_instance_names)
Definition: miscServerFunct.cpp:3181
LOG_ERROR
#define LOG_ERROR
Definition: rodsLog.h:43
generate_iadmin_commands_for_41_to_42_upgrade.name
name
Definition: generate_iadmin_commands_for_41_to_42_upgrade.py:23
irods_re_plugin.hpp
RuleExecInfo::rsComm
rsComm_t * rsComm
Definition: irods_re_structs.hpp:22
initReiWithDataObjInp
int initReiWithDataObjInp(ruleExecInfo_t *rei, rsComm_t *rsComm, dataObjInp_t *dataObjIn)
Definition: irods_re_structs.cpp:164
RuleExecInfo::condInputData
keyValPair_t * condInputData
Definition: irods_re_structs.hpp:34
ExecMyRuleInp::myRule
char myRule[(1024 *20)]
Definition: execMyRule.h:10
rsComm_t::rError
rError_t rError
Definition: rcConnect.h:158
irods::error::code
long long code() const
Definition: irods_error.cpp:194
trimMsParamArray
int trimMsParamArray(msParamArray_t *msParamArray, char *outParamDesc)
Definition: msParam.cpp:511
rsExecMyRule.hpp
remoteExecMyRule
int remoteExecMyRule(rsComm_t *_comm, execMyRuleInp_t *_exec_inp, msParamArray_t **_out_arr, rodsServerHost_t *rods_svr_host)
Definition: rsExecMyRule.cpp:121
rsExecMyRule
int rsExecMyRule(rsComm_t *_comm, execMyRuleInp_t *_exec_inp, msParamArray_t **_out_arr)
Definition: rsExecMyRule.cpp:9
SYS_INVALID_SERVER_HOST
@ SYS_INVALID_SERVER_HOST
Definition: rodsErrorTable.h:89
irods::CFG_INSTANCE_NAME_KW
const std::string CFG_INSTANCE_NAME_KW("instance_name")
irods::AUDIT_RULE
@ AUDIT_RULE
Definition: irods_re_plugin.hpp:124
addRErrorMsg
int addRErrorMsg(rError_t *myError, int status, const char *msg)
Definition: rcMisc.cpp:121
svrToSvrConnect
int svrToSvrConnect(rsComm_t *rsComm, rodsServerHost_t *rodsServerHost)
Definition: miscServerFunct.cpp:106
irods.pypyodbc.status
status
Definition: pypyodbc.py:467
irods::log
void log(const error &)
Definition: irods_log.cpp:13
LOG_NOTICE
#define LOG_NOTICE
Definition: rodsLog.h:33
ERROR
#define ERROR(code_, message_)
Definition: irods_error.hpp:117
RuleExecInfo::ruleName
char ruleName[64]
Definition: irods_re_structs.hpp:21
irods::error
Definition: irods_error.hpp:23
miscServerFunct.hpp
ExecMyRuleInp
Definition: execMyRule.h:9
RuleExecInfo::msParamArray
msParamArray_t * msParamArray
Definition: irods_re_structs.hpp:24
rodsServerHost
Definition: rodsConnect.h:62
RuleExecInfo
Definition: irods_re_structs.hpp:18
EXEC_MY_RULE_KW
#define EXEC_MY_RULE_KW
Definition: rodsKeyWdDef.h:102
rstrcpy
char * rstrcpy(char *dest, const char *src, int maxLen)
Definition: stringOpr.cpp:51
MsParamArray
Definition: msParam.h:84
ExecMyRuleInp::addr
rodsHostAddr_t addr
Definition: execMyRule.h:11
NAME_LEN
#define NAME_LEN
Definition: rodsDef.h:55
irods::error::ok
bool ok()
Definition: irods_error.cpp:258
irods::error::result
std::string result() const
Definition: irods_error.cpp:201
ExecMyRuleInp::inpParamArray
msParamArray_t * inpParamArray
Definition: execMyRule.h:14
irods::re_plugin_globals
std::unique_ptr< struct irods::global_re_plugin_mgr > re_plugin_globals
Definition: irods_re_plugin.cpp:16
freeRErrorContent
int freeRErrorContent(rError_t *myError)
Definition: rcMisc.cpp:182
resolveHost
int resolveHost(rodsHostAddr_t *addr, rodsServerHost_t **rodsServerHost)
Definition: rodsConnect.cpp:375