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)  

rsRuleExecSubmit.cpp
Go to the documentation of this file.
1 #include "rodsConnect.h"
2 #include "ruleExecSubmit.h"
4 #include "rcMisc.h"
5 #include "miscServerFunct.hpp"
6 #include "rsRuleExecSubmit.hpp"
7 
8 #include "irods_log.hpp"
10 #include "irods_random.hpp"
12 
13 int
14 rsRuleExecSubmit( rsComm_t *rsComm, ruleExecSubmitInp_t *ruleExecSubmitInp,
15  char **ruleExecId ) {
17  int status;
18 
19  *ruleExecId = NULL;
20 
21  if ( ruleExecSubmitInp == NULL ||
22  ruleExecSubmitInp->packedReiAndArgBBuf == NULL ||
23  ruleExecSubmitInp->packedReiAndArgBBuf->len <= 0 ||
24  ruleExecSubmitInp->packedReiAndArgBBuf->buf == NULL ) {
26  "rsRuleExecSubmit error. NULL input" );
28  }
29 
31  if ( status < 0 ) {
32  return status;
33  }
34 
36  std::string svc_role;
37  irods::error ret = get_catalog_service_role(svc_role);
38  if(!ret.ok()) {
39  irods::log(PASS(ret));
40  return ret.code();
41  }
42 
43  if( irods::CFG_SERVICE_ROLE_PROVIDER == svc_role ) {
44  status = _rsRuleExecSubmit( rsComm, ruleExecSubmitInp );
45  if ( status >= 0 ) {
46  *ruleExecId = strdup( ruleExecSubmitInp->ruleExecId );
47  }
48  } else if( irods::CFG_SERVICE_ROLE_CONSUMER == svc_role ) {
50  "rsRuleExecSubmit error. ICAT is not configured on this host" );
52  } else {
53  rodsLog(
54  LOG_ERROR,
55  "role not supported [%s]",
56  svc_role.c_str() );
58  }
59 
60  }
61  else {
62  if ( getValByKey( &ruleExecSubmitInp->condInput, EXEC_LOCALLY_KW ) !=
63  NULL ) {
65  "rsRuleExecSubmit: reHost config error. reServer not running locally" );
66  return SYS_CONFIG_FILE_ERR;
67  }
68  else {
69  addKeyVal( &ruleExecSubmitInp->condInput, EXEC_LOCALLY_KW, "" );
70  }
71  status = rcRuleExecSubmit( rodsServerHost->conn, ruleExecSubmitInp,
72  ruleExecId );
73  }
74  if ( status < 0 ) {
76  "rsRuleExecSubmit: rcRuleExecSubmit failed, status = %d",
77  status );
78  }
79  return status;
80 }
81 
82 int
83 _rsRuleExecSubmit( rsComm_t *rsComm, ruleExecSubmitInp_t *ruleExecSubmitInp ) {
84  int reiFd;
85  int status;
86 
87  /* write the packedReiAndArgBBuf to local file */
88  while ( 1 ) {
89  status = getReiFilePath( ruleExecSubmitInp->reiFilePath,
90  ruleExecSubmitInp->userName );
91  if ( status < 0 ) {
93  "rsRuleExecSubmit: getReiFilePath failed, status = %d", status );
94  return status;
95  }
96  reiFd = open( ruleExecSubmitInp->reiFilePath, O_CREAT | O_EXCL | O_RDWR,
97  0640 );
98  if ( reiFd < 0 ) {
99  if ( errno == EEXIST ) {
100  continue;
101  }
102  else {
103  status = SYS_OPEN_REI_FILE_ERR - errno;
105  "rsRuleExecSubmit: create failed for %s, status = %d",
106  ruleExecSubmitInp->reiFilePath, status );
107  return status;
108  }
109  }
110  else {
111  break;
112  }
113  }
114 
115  status = write( reiFd, ruleExecSubmitInp->packedReiAndArgBBuf->buf,
116  ruleExecSubmitInp->packedReiAndArgBBuf->len );
117 
118  close( reiFd );
119 
120  if ( status != ruleExecSubmitInp->packedReiAndArgBBuf->len ) {
122  "rsRuleExecSubmit: write rei error.toWrite %d, %d written",
123  ruleExecSubmitInp->packedReiAndArgBBuf->len, status );
124  return SYS_COPY_LEN_ERR - errno;
125  }
126 
127  /* register the request */
128  std::string svc_role;
129  irods::error ret = get_catalog_service_role(svc_role);
130  if(!ret.ok()) {
131  irods::log(PASS(ret));
132  return ret.code();
133  }
134 
135  if( irods::CFG_SERVICE_ROLE_PROVIDER == svc_role ) {
136  status = chlRegRuleExec( rsComm, ruleExecSubmitInp );
137  if ( status < 0 ) {
139  "_rsRuleExecSubmit: chlRegRuleExec error. status = %d", status );
140  }
141  return status;
142  } else if( irods::CFG_SERVICE_ROLE_CONSUMER == svc_role ) {
144  "_rsRuleExecSubmit error. ICAT is not configured on this host" );
145  return SYS_NO_ICAT_SERVER_ERR;
146  } else {
147  rodsLog(
148  LOG_ERROR,
149  "role not supported [%s]",
150  svc_role.c_str() );
152  }
153 }
154 
155 int
156 getReiFilePath( char *reiFilePath, char *userName ) {
157  char *myUserName;
158 
159  if ( reiFilePath == NULL ) {
161  }
162 
163  if ( userName == NULL || strlen( userName ) == 0 ) {
164  myUserName = DEF_REI_USER_NAME;
165  }
166  else {
167  myUserName = userName;
168  }
169 
170  std::string rei_dir;
173  rei_dir );
174  if ( !ret.ok() ) {
175  irods::log( PASS( ret ) );
176  return ret.code();
177  }
178 
179  snprintf(
180  reiFilePath,
181  MAX_NAME_LEN,
182  "%-s/%-s.%-s.%-u",
183  rei_dir.c_str(),
185  myUserName,
186  irods::getRandom<unsigned int>() );
187 
188  return 0;
189 }
ruleExecSubmitInp_t::packedReiAndArgBBuf
bytesBuf_t * packedReiAndArgBBuf
Definition: ruleExecSubmit.h:34
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
rsRuleExecSubmit
int rsRuleExecSubmit(rsComm_t *rsComm, ruleExecSubmitInp_t *ruleExecSubmitInp, char **ruleExecId)
Definition: rsRuleExecSubmit.cpp:14
rsComm_t
Definition: rcConnect.h:145
addKeyVal
int addKeyVal(keyValPair_t *condInput, const char *keyWord, const char *value)
Definition: rcMisc.cpp:789
irods::CFG_SERVICE_ROLE_CONSUMER
const std::string CFG_SERVICE_ROLE_CONSUMER("consumer")
irods_configuration_keywords.hpp
SYS_INTERNAL_NULL_INPUT_ERR
@ SYS_INTERNAL_NULL_INPUT_ERR
Definition: rodsErrorTable.h:92
rodsServerHost::localFlag
int localFlag
Definition: rodsConnect.h:68
SYS_SERVICE_ROLE_NOT_SUPPORTED
@ SYS_SERVICE_ROLE_NOT_SUPPORTED
Definition: rodsErrorTable.h:217
BytesBuf::buf
void * buf
Definition: rodsDef.h:199
rodsServerHost::conn
rcComm_t * conn
Definition: rodsConnect.h:64
irods_get_full_path_for_config_file.hpp
PASS
#define PASS(prev_error_)
Definition: irods_error.hpp:118
SYS_NO_ICAT_SERVER_ERR
@ SYS_NO_ICAT_SERVER_ERR
Definition: rodsErrorTable.h:104
rcMisc.h
LOCAL_HOST
#define LOCAL_HOST
Definition: rodsConnect.h:44
irods::get_full_path_for_unmoved_configs
error get_full_path_for_unmoved_configs(const std::string &, std::string &)
Definition: irods_get_full_path_for_config_file.cpp:43
SYS_OPEN_REI_FILE_ERR
@ SYS_OPEN_REI_FILE_ERR
Definition: rodsErrorTable.h:109
getReiFilePath
int getReiFilePath(char *reiFilePath, char *userName)
Definition: rsRuleExecSubmit.cpp:156
LOG_ERROR
#define LOG_ERROR
Definition: rodsLog.h:43
rodsConnect.h
BytesBuf::len
int len
Definition: rodsDef.h:198
ruleExecSubmitInp_t::condInput
keyValPair_t condInput
Definition: ruleExecSubmit.h:33
EXEC_LOCALLY_KW
#define EXEC_LOCALLY_KW
Definition: rodsKeyWdDef.h:12
irods::error::code
long long code() const
Definition: irods_error.cpp:194
SYS_COPY_LEN_ERR
@ SYS_COPY_LEN_ERR
Definition: rodsErrorTable.h:95
ruleExecSubmit.h
rsRuleExecSubmit.hpp
irods::CFG_SERVICE_ROLE_PROVIDER
const std::string CFG_SERVICE_ROLE_PROVIDER("provider")
getAndConnReHost
int getAndConnReHost(rsComm_t *rsComm, rodsServerHost_t **rodsServerHost)
Definition: rodsConnect.cpp:1015
chlRegRuleExec
int chlRegRuleExec(rsComm_t *rsComm, ruleExecSubmitInp_t *ruleExecSubmitInp)
Definition: icatHighLevelRoutines.cpp:661
MAX_NAME_LEN
#define MAX_NAME_LEN
Definition: rodsDef.h:61
PACKED_REI_DIR
#define PACKED_REI_DIR
Definition: ruleExecSubmit.h:20
irods.pypyodbc.status
status
Definition: pypyodbc.py:467
rcRuleExecSubmit
int rcRuleExecSubmit(rcComm_t *conn, ruleExecSubmitInp_t *ruleExecSubmitInp, char **ruleExecId)
Definition: rcRuleExecSubmit.cpp:36
irods::log
void log(const error &)
Definition: irods_log.cpp:13
LOG_NOTICE
#define LOG_NOTICE
Definition: rodsLog.h:33
irods::error
Definition: irods_error.hpp:23
miscServerFunct.hpp
ruleExecSubmitInp_t
Definition: ruleExecSubmit.h:21
DEF_REI_USER_NAME
#define DEF_REI_USER_NAME
Definition: ruleExecSubmit.h:19
get_catalog_service_role
irods::error get_catalog_service_role(std::string &_role)
Definition: miscServerFunct.cpp:3153
rodsServerHost
Definition: rodsConnect.h:62
REI_FILE_NAME
#define REI_FILE_NAME
Definition: ruleExecSubmit.h:18
_rsRuleExecSubmit
int _rsRuleExecSubmit(rsComm_t *rsComm, ruleExecSubmitInp_t *ruleExecSubmitInp)
Definition: rsRuleExecSubmit.cpp:83
ruleExecSubmitInp_t::ruleExecId
char ruleExecId[64]
Definition: ruleExecSubmit.h:35
icatHighLevelRoutines.hpp
ruleExecSubmitInp_t::reiFilePath
char reiFilePath[(1024+64)]
Definition: ruleExecSubmit.h:23
irods_random.hpp
ruleExecSubmitInp_t::userName
char userName[64]
Definition: ruleExecSubmit.h:24
SYS_CONFIG_FILE_ERR
@ SYS_CONFIG_FILE_ERR
Definition: rodsErrorTable.h:93
irods::error::ok
bool ok()
Definition: irods_error.cpp:258
irods_log.hpp