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)  

rsModDataObjMeta.cpp
Go to the documentation of this file.
1 
3 /* unregDataObj.c
4  */
5 
6 #include "rsModDataObjMeta.hpp"
7 #include "modDataObjMeta.h"
9 #include "objMetaOpr.hpp"
10 #include "dataObjOpr.hpp"
11 #include "miscServerFunct.hpp"
12 
13 #include "irods_file_object.hpp"
14 #include "irods_stacktrace.hpp"
16 
17 #include "boost/format.hpp"
18 
20  rsComm_t* rsComm,
21  modDataObjMeta_t* modDataObjMetaInp );
22 int
23 rsModDataObjMeta( rsComm_t *rsComm, modDataObjMeta_t *modDataObjMetaInp ) {
24  int status;
26  dataObjInfo_t *dataObjInfo;
27 
28  dataObjInfo = modDataObjMetaInp->dataObjInfo;
29 
31  rsComm,
33  ( const char* )dataObjInfo->objPath,
34  &rodsServerHost );
35  if ( status < 0 || NULL == rodsServerHost ) { // JMC cppcheck - nullptr
36  return status;
37  }
39  std::string svc_role;
40  irods::error ret = get_catalog_service_role(svc_role);
41  if(!ret.ok()) {
42  irods::log(PASS(ret));
43  return ret.code();
44  }
45 
46  if( irods::CFG_SERVICE_ROLE_PROVIDER == svc_role ) {
47  status = _rsModDataObjMeta( rsComm, modDataObjMetaInp );
48  } else if( irods::CFG_SERVICE_ROLE_CONSUMER == svc_role ) {
50  } else {
51  rodsLog(
52  LOG_ERROR,
53  "role not supported [%s]",
54  svc_role.c_str() );
56  }
57  }
58  else {
59  // Add IN_REPL_KW to prevent replication on the redirected server (the provider)
60  addKeyVal( modDataObjMetaInp->regParam, IN_REPL_KW, "" );
61  status = rcModDataObjMeta( rodsServerHost->conn, modDataObjMetaInp );
62  // Remove the keyword as we will want to replicate on this server (the consumer)
63  rmKeyVal(modDataObjMetaInp->regParam, IN_REPL_KW);
64  }
65 
66  if ( status >= 0 ) {
67  const auto open_type = getValByKey(modDataObjMetaInp->regParam, OPEN_TYPE_KW);
68  if (!getValByKey(modDataObjMetaInp->regParam, IN_REPL_KW) && open_type &&
69  (OPEN_FOR_WRITE_TYPE == std::atoi(open_type) || CREATE_TYPE == std::atoi(open_type))) {
70  status = _call_file_modified_for_modification( rsComm, modDataObjMetaInp );
71  }
72  }
73 
74  return status;
75 }
76 
77 int
78 _rsModDataObjMeta( rsComm_t *rsComm, modDataObjMeta_t *modDataObjMetaInp ) {
79  std::string svc_role;
80  irods::error ret = get_catalog_service_role(svc_role);
81  if(!ret.ok()) {
82  irods::log(PASS(ret));
83  return ret.code();
84  }
85 
86  if( irods::CFG_SERVICE_ROLE_PROVIDER == svc_role ) {
87  int status = 0;
88  dataObjInfo_t *dataObjInfo;
89  keyValPair_t *regParam;
90  int i;
91  ruleExecInfo_t rei2;
92 
93  memset( ( char* )&rei2, 0, sizeof( ruleExecInfo_t ) );
94  rei2.rsComm = rsComm;
95  if ( rsComm != NULL ) {
96  rei2.uoic = &rsComm->clientUser;
97  rei2.uoip = &rsComm->proxyUser;
98  }
99  rei2.doi = modDataObjMetaInp->dataObjInfo;
100  rei2.condInputData = modDataObjMetaInp->regParam;
101  regParam = modDataObjMetaInp->regParam;
102  dataObjInfo = modDataObjMetaInp->dataObjInfo;
103 
104  if ( regParam->len == 0 ) {
105  return 0;
106  }
107 
108  /* In dataObjInfo, need just dataId. But it will accept objPath too,
109  * but less efficient
110  */
111 
113  rei2.doi = dataObjInfo;
114  i = applyRule( "acPreProcForModifyDataObjMeta", NULL, &rei2, NO_SAVE_REI );
115  if ( i < 0 ) {
116  if ( rei2.status < 0 ) {
117  i = rei2.status;
118  }
119  rodsLog( LOG_ERROR, "_rsModDataObjMeta:acPreProcForModifyDataObjMeta error stat=%d", i );
120 
121  return i;
122  }
125  if ( getValByKey( regParam, ALL_KW ) != NULL ) {
126  /* all copies */
127  dataObjInfo_t *dataObjInfoHead = NULL;
128  dataObjInfo_t *tmpDataObjInfo;
129  dataObjInp_t dataObjInp;
130 
131  bzero( &dataObjInp, sizeof( dataObjInp ) );
132  rstrcpy( dataObjInp.objPath, dataObjInfo->objPath, MAX_NAME_LEN );
133  status = getDataObjInfoIncSpecColl( rsComm, &dataObjInp, &dataObjInfoHead );
134 
135  if ( status < 0 ) {
136  rodsLog( LOG_NOTICE, "%s - Failed to get data objects, status = %d", __FUNCTION__, status );
137  return status;
138  }
139  tmpDataObjInfo = dataObjInfoHead;
140  while ( tmpDataObjInfo != NULL ) {
141  if ( tmpDataObjInfo->specColl != NULL ) {
142  break;
143  }
144  status = chlModDataObjMeta( rsComm, tmpDataObjInfo, regParam );
145  if ( status < 0 ) {
147  "_rsModDataObjMeta:chlModDataObjMeta %s error stat=%d",
148  tmpDataObjInfo->objPath, status );
149  }
150  tmpDataObjInfo = tmpDataObjInfo->next;
151  }
152  freeAllDataObjInfo( dataObjInfoHead );
153  }
154  else {
155  status = chlModDataObjMeta( rsComm, dataObjInfo, regParam );
156  if ( status < 0 ) {
157  char* sys_error = NULL;
158  const char* rods_error = rodsErrorName( status, &sys_error );
159  std::stringstream msg;
160  msg << __FUNCTION__;
161  msg << " - Failed to modify the database for object \"";
162  msg << dataObjInfo->objPath;
163  msg << "\" - " << rods_error << " " << sys_error;
164  irods::error ret = ERROR( status, msg.str() );
165  irods::log( ret );
166  free( sys_error );
167  }
168  }
169 
171  if ( status >= 0 ) {
172  i = applyRule( "acPostProcForModifyDataObjMeta", NULL, &rei2, NO_SAVE_REI );
173  if ( i < 0 ) {
174  if ( rei2.status < 0 ) {
175  i = rei2.status;
176  }
178  "_rsModDataObjMeta:acPostProcForModifyDataObjMeta error stat=%d", i );
179  return i;
180  }
181  }
182  else {
183  rodsLog( LOG_NOTICE, "%s - Failed updating the database with object info.", __FUNCTION__ );
184  return status;
185  }
188  return status;
189  } else if( irods::CFG_SERVICE_ROLE_CONSUMER == svc_role ) {
190  return SYS_NO_RCAT_SERVER_ERR;
191  } else {
192  rodsLog(
193  LOG_ERROR,
194  "role not supported [%s]",
195  svc_role.c_str() );
197  }
198 
199 }
200 
202  rsComm_t* rsComm,
203  modDataObjMeta_t* modDataObjMetaInp ) {
204  int status = 0;
205  dataObjInfo_t *dataObjInfo;
206  keyValPair_t *regParam;
207  ruleExecInfo_t rei2;
208 
209  memset( ( char* )&rei2, 0, sizeof( ruleExecInfo_t ) );
210  rei2.rsComm = rsComm;
211  rei2.uoic = &rsComm->clientUser;
212  rei2.uoip = &rsComm->proxyUser;
213  rei2.doi = modDataObjMetaInp->dataObjInfo;
214  rei2.condInputData = modDataObjMetaInp->regParam;
215  regParam = modDataObjMetaInp->regParam;
216  dataObjInfo = modDataObjMetaInp->dataObjInfo;
217 
218  if ( regParam->len == 0 ) {
219  return 0;
220  }
221 
222  if ( getValByKey( regParam, ALL_KW ) != NULL ) {
223  /* all copies */
224  dataObjInfo_t *dataObjInfoHead = NULL;
225  dataObjInfo_t *tmpDataObjInfo;
226  dataObjInp_t dataObjInp;
227 
228  bzero( &dataObjInp, sizeof( dataObjInp ) );
229  rstrcpy( dataObjInp.objPath, dataObjInfo->objPath, MAX_NAME_LEN );
230  status = getDataObjInfoIncSpecColl( rsComm, &dataObjInp, &dataObjInfoHead );
231 
232  if ( status < 0 ) {
233  rodsLog( LOG_NOTICE, "%s - Failed to get data objects.", __FUNCTION__ );
234  return status;
235  }
236  tmpDataObjInfo = dataObjInfoHead;
237  while ( tmpDataObjInfo != NULL ) {
238  if ( tmpDataObjInfo->specColl != NULL ) {
239  break;
240  }
241 
242  irods::file_object_ptr file_obj(
243  new irods::file_object(
244  rsComm,
245  tmpDataObjInfo ) );
246 
247  char* admin_kw = getValByKey( regParam, ADMIN_KW );
248  if ( admin_kw != NULL ) {
249  addKeyVal( (keyValPair_t*)&file_obj->cond_input(), ADMIN_KW, "" );
250  }
251 
252  char* pdmo_kw = getValByKey( regParam, IN_PDMO_KW );
253  if ( pdmo_kw != NULL ) {
254  file_obj->in_pdmo( pdmo_kw );
255  }
256 
257  const auto open_type{getValByKey(regParam, OPEN_TYPE_KW)};
258  if (open_type) {
259  addKeyVal((keyValPair_t*)&file_obj->cond_input(), OPEN_TYPE_KW, open_type);
260  }
261 
262  irods::error ret = fileModified( rsComm, file_obj );
263  if ( !ret.ok() ) {
264  std::stringstream msg;
265  msg << __FUNCTION__;
266  msg << " - Failed to signal resource that the data object \"";
267  msg << tmpDataObjInfo->objPath;
268  msg << " was modified.";
269  ret = PASSMSG( msg.str(), ret );
270  irods::log( ret );
271  status = ret.code();
272  }
273 
274  tmpDataObjInfo = tmpDataObjInfo->next;
275  }
276  freeAllDataObjInfo( dataObjInfoHead );
277  }
278  else {
279  // Construct file_obj twice because ctor gives some info that factory does not
280  irods::file_object_ptr file_obj(new irods::file_object(rsComm, dataObjInfo));
281 
282  // Need to pass along admin keyword here to ensure replicas can be managed
283  dataObjInp_t dataObjInp{};
284  rstrcpy(dataObjInp.objPath, dataObjInfo->objPath, MAX_NAME_LEN);
285  if (getValByKey(regParam, ADMIN_KW)) {
286  addKeyVal(&dataObjInp.condInput, ADMIN_KW, "");
287  }
288 
289  // Use temporary as file_object_factory overwrites dataObjInfo pointer
290  dataObjInfo_t* tmpDataObjInfo{};
291  auto ret{file_object_factory(rsComm, &dataObjInp, file_obj, &tmpDataObjInfo)};
292  if (!ret.ok()) {
293  irods::log(ret);
294  return ret.code();
295  }
296  // Factory overwrites rescHier with the resource which holds replica 0 - put it back
297  file_obj->resc_hier(dataObjInfo->rescHier);
298 
299  if (getValByKey(regParam, ADMIN_KW)) {
300  addKeyVal((keyValPair_t*)&file_obj->cond_input(), ADMIN_KW, "");
301  }
302  const auto pdmo_kw{getValByKey(regParam, IN_PDMO_KW)};
303  if (pdmo_kw) {
304  file_obj->in_pdmo(pdmo_kw);
305  }
306  const auto open_type{getValByKey(regParam, OPEN_TYPE_KW)};
307  if (open_type) {
308  addKeyVal((keyValPair_t*)&file_obj->cond_input(), OPEN_TYPE_KW, open_type);
309  }
310  ret = fileModified(rsComm, file_obj);
311  if (!ret.ok()) {
312  irods::log(PASSMSG((boost::format(
313  "[%s] - Failed to signal the resource that the data object \"%s\"") %
314  __FUNCTION__ % dataObjInfo->objPath).str(), ret));
315  status = ret.code();
316  }
317  }
318 
319  return status;
320 }
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
DataObjInp::objPath
char objPath[(1024+64)]
Definition: dataObjInpOut.h:66
NULL
#define NULL
Definition: rodsDef.h:70
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
rodsServerHost::localFlag
int localFlag
Definition: rodsConnect.h:68
rcModDataObjMeta
int rcModDataObjMeta(rcComm_t *conn, modDataObjMeta_t *modDataObjMetaInp)
Definition: rcModDataObjMeta.cpp:23
SYS_SERVICE_ROLE_NOT_SUPPORTED
@ SYS_SERVICE_ROLE_NOT_SUPPORTED
Definition: rodsErrorTable.h:217
modDataObjMeta.h
rodsServerHost::conn
rcComm_t * conn
Definition: rodsConnect.h:64
irods_file_object.hpp
irods_stacktrace.hpp
PASS
#define PASS(prev_error_)
Definition: irods_error.hpp:118
NO_SAVE_REI
#define NO_SAVE_REI
Definition: rodsDef.h:103
DataObjInfo::rescHier
char rescHier[(1024+64)]
Definition: objInfo.h:132
LOCAL_HOST
#define LOCAL_HOST
Definition: rodsConnect.h:44
PASSMSG
#define PASSMSG(message_, prev_error_)
Definition: irods_error.hpp:119
ALL_KW
#define ALL_KW
Definition: rodsKeyWdDef.h:10
chlModDataObjMeta
int chlModDataObjMeta(rsComm_t *rsComm, dataObjInfo_t *dataObjInfo, keyValPair_t *regParam)
Definition: icatHighLevelRoutines.cpp:436
LOG_ERROR
#define LOG_ERROR
Definition: rodsLog.h:43
rodsErrorName
const char * rodsErrorName(int errorValue, char **subName)
Definition: rodsLog.cpp:373
DataObjInfo::next
struct DataObjInfo * next
Definition: objInfo.h:163
DataObjInfo::specColl
specColl_t * specColl
Definition: objInfo.h:158
CREATE_TYPE
#define CREATE_TYPE
Definition: dataObjInpOut.h:193
irods::error::code
long long code() const
Definition: irods_error.cpp:194
irods::file_object_factory
error file_object_factory(rsComm_t *, dataObjInp_t *, file_object_ptr, dataObjInfo_t **)
Definition: irods_file_object.cpp:271
rsComm_t::proxyUser
userInfo_t proxyUser
Definition: rcConnect.h:152
freeAllDataObjInfo
int freeAllDataObjInfo(dataObjInfo_t *dataObjInfoHead)
Definition: rcMisc.cpp:561
_call_file_modified_for_modification
int _call_file_modified_for_modification(rsComm_t *rsComm, modDataObjMeta_t *modDataObjMetaInp)
Definition: rsModDataObjMeta.cpp:201
getDataObjInfoIncSpecColl
int getDataObjInfoIncSpecColl(rsComm_t *rsComm, dataObjInp_t *dataObjInp, dataObjInfo_t **dataObjInfo)
Definition: dataObjOpr.cpp:1767
OPEN_TYPE_KW
#define OPEN_TYPE_KW
Definition: rodsKeyWdDef.h:95
irods::CFG_SERVICE_ROLE_PROVIDER
const std::string CFG_SERVICE_ROLE_PROVIDER("provider")
DataObjInp
Definition: dataObjInpOut.h:65
IN_REPL_KW
#define IN_REPL_KW
Definition: rodsKeyWdDef.h:230
MAX_NAME_LEN
#define MAX_NAME_LEN
Definition: rodsDef.h:61
fileModified
irods::error fileModified(rsComm_t *_comm, irods::first_class_object_ptr _object)
Definition: fileDriver.cpp:692
SYS_NO_RCAT_SERVER_ERR
@ SYS_NO_RCAT_SERVER_ERR
Definition: rodsErrorTable.h:110
rmKeyVal
int rmKeyVal(keyValPair_t *condInput, const char *keyWord)
Definition: rcMisc.cpp:710
ADMIN_KW
#define ADMIN_KW
Definition: rodsKeyWdDef.h:62
irods.pypyodbc.status
status
Definition: pypyodbc.py:467
OPEN_FOR_WRITE_TYPE
#define OPEN_FOR_WRITE_TYPE
Definition: dataObjInpOut.h:195
irods::log
void log(const error &)
Definition: irods_log.cpp:13
modDataObjMeta_t::regParam
keyValPair_t * regParam
Definition: modDataObjMeta.h:9
LOG_NOTICE
#define LOG_NOTICE
Definition: rodsLog.h:33
rsComm_t::clientUser
userInfo_t clientUser
Definition: rcConnect.h:153
ERROR
#define ERROR(code_, message_)
Definition: irods_error.hpp:117
irods::error
Definition: irods_error.hpp:23
miscServerFunct.hpp
modDataObjMeta_t::dataObjInfo
dataObjInfo_t * dataObjInfo
Definition: modDataObjMeta.h:8
getAndConnRcatHost
int getAndConnRcatHost(rsComm_t *rsComm, int rcatType, const char *rcatZoneHint, rodsServerHost_t **rodsServerHost)
Definition: rodsConnect.cpp:26
IN_PDMO_KW
#define IN_PDMO_KW
Definition: rodsKeyWdDef.h:227
MASTER_RCAT
#define MASTER_RCAT
Definition: rodsDef.h:85
get_catalog_service_role
irods::error get_catalog_service_role(std::string &_role)
Definition: miscServerFunct.cpp:3153
irods::file_object
Definition: irods_file_object.hpp:19
rodsServerHost
Definition: rodsConnect.h:62
irods::file_object_ptr
boost::shared_ptr< file_object > file_object_ptr
Definition: irods_file_object.hpp:145
RuleExecInfo
Definition: irods_re_structs.hpp:18
KeyValPair::len
int len
Definition: objInfo.h:121
rsModDataObjMeta.hpp
applyRule
int applyRule(char *inAction, msParamArray_t *inMsParamArray, ruleExecInfo_t *rei, int reiSaveFlag)
Definition: irods_re_structs.cpp:65
icatHighLevelRoutines.hpp
DataObjInfo::objPath
char objPath[(1024+64)]
Definition: objInfo.h:130
rstrcpy
char * rstrcpy(char *dest, const char *src, int maxLen)
Definition: stringOpr.cpp:51
dataObjOpr.hpp
modDataObjMeta_t
Definition: modDataObjMeta.h:7
_rsModDataObjMeta
int _rsModDataObjMeta(rsComm_t *rsComm, modDataObjMeta_t *modDataObjMetaInp)
Definition: rsModDataObjMeta.cpp:78
KeyValPair
Definition: objInfo.h:120
irods::error::ok
bool ok()
Definition: irods_error.cpp:258
DataObjInfo
Definition: objInfo.h:129
objMetaOpr.hpp
rsModDataObjMeta
int rsModDataObjMeta(rsComm_t *rsComm, modDataObjMeta_t *modDataObjMetaInp)
Definition: rsModDataObjMeta.cpp:23