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)  

rsBulkDataObjReg.cpp
Go to the documentation of this file.
1 
3 /* rsBulkDataObjReg.c. See bulkDataObjReg.h for a description of
4  * this API call.*/
5 
6 #include "apiHeaderAll.h"
7 #include "dataObjOpr.hpp"
8 #include "objMetaOpr.hpp"
9 #include "miscServerFunct.hpp"
11 #include "rsBulkDataObjReg.hpp"
12 #include "rsRegDataObj.hpp"
13 #include "rsModDataObjMeta.hpp"
14 
15 #include "irods_stacktrace.hpp"
16 #include "irods_file_object.hpp"
18 
19 int
20 rsBulkDataObjReg( rsComm_t *rsComm, genQueryOut_t *bulkDataObjRegInp,
21  genQueryOut_t **bulkDataObjRegOut ) {
22  sqlResult_t *objPath;
23  int status;
25 
26  if ( bulkDataObjRegInp->rowCnt <= 0 ) {
27  return 0;
28  }
29 
30  if ( ( objPath =
31  getSqlResultByInx( bulkDataObjRegInp, COL_DATA_NAME ) ) == NULL ) {
33  "rsBulkDataObjReg: getSqlResultByInx for COL_DATA_NAME failed" );
35  }
36 
37  status = getAndConnRcatHost( rsComm, MASTER_RCAT, ( const char* )objPath->value,
38  &rodsServerHost );
39  if ( status < 0 || rodsServerHost == NULL ) { // JMC cppcheck
40  return status;
41  }
42 
44  std::string svc_role;
45  irods::error ret = get_catalog_service_role(svc_role);
46  if(!ret.ok()) {
47  irods::log(PASS(ret));
48  return ret.code();
49  }
50 
51  if( irods::CFG_SERVICE_ROLE_PROVIDER == svc_role ) {
52  status = _rsBulkDataObjReg( rsComm, bulkDataObjRegInp,
53  bulkDataObjRegOut );
54  } else if( irods::CFG_SERVICE_ROLE_CONSUMER == svc_role ) {
56  } else {
57  rodsLog(
58  LOG_ERROR,
59  "role not supported [%s]",
60  svc_role.c_str() );
62  }
63  }
64  else {
65  status = rcBulkDataObjReg( rodsServerHost->conn, bulkDataObjRegInp,
66  bulkDataObjRegOut );
67  }
68 
69  return status;
70 }
71 
72 int
73 _rsBulkDataObjReg( rsComm_t *rsComm, genQueryOut_t *bulkDataObjRegInp,
74  genQueryOut_t **bulkDataObjRegOut ) {
75  std::string svc_role;
76  irods::error ret = get_catalog_service_role(svc_role);
77  if(!ret.ok()) {
78  irods::log(PASS(ret));
79  return ret.code();
80  }
81 
82  if( irods::CFG_SERVICE_ROLE_PROVIDER == svc_role ) {
83  dataObjInfo_t dataObjInfo;
84  sqlResult_t *objPath, *dataType, *dataSize, *rescName, *rescID, *filePath,
85  *dataMode, *oprType, *replNum, *chksum;
86  char *tmpObjPath, *tmpDataType, *tmpDataSize, *tmpRescName, *tmpRescID, *tmpFilePath,
87  *tmpDataMode, *tmpOprType, *tmpReplNum, *tmpChksum;
88  sqlResult_t *objId;
89  char *tmpObjId;
90  int status, i;
91 
92  if ( ( rescID =
93  getSqlResultByInx( bulkDataObjRegInp, COL_D_RESC_ID ) ) == NULL ) {
95  "rsBulkDataObjReg: getSqlResultByInx for COL_D_RESC_ID failed" );
97  }
98 
99  if ( ( objPath =
100  getSqlResultByInx( bulkDataObjRegInp, COL_DATA_NAME ) ) == NULL ) {
102  "rsBulkDataObjReg: getSqlResultByInx for COL_DATA_NAME failed" );
103  return UNMATCHED_KEY_OR_INDEX;
104  }
105 
106  if ( ( dataType =
107  getSqlResultByInx( bulkDataObjRegInp, COL_DATA_TYPE_NAME ) ) == NULL ) {
109  "rsBulkDataObjReg: getSqlResultByInx for COL_DATA_TYPE_NAME failed" );
110  return UNMATCHED_KEY_OR_INDEX;
111  }
112  if ( ( dataSize =
113  getSqlResultByInx( bulkDataObjRegInp, COL_DATA_SIZE ) ) == NULL ) {
115  "rsBulkDataObjReg: getSqlResultByInx for COL_DATA_SIZE failed" );
116  return UNMATCHED_KEY_OR_INDEX;
117  }
118 
119  if ( ( rescName =
120  getSqlResultByInx( bulkDataObjRegInp, COL_D_RESC_NAME ) ) == NULL ) {
122  "rsBulkDataObjReg: getSqlResultByInx for COL_D_RESC_NAME failed" );
123  return UNMATCHED_KEY_OR_INDEX;
124  }
125 
126  if ( ( filePath =
127  getSqlResultByInx( bulkDataObjRegInp, COL_D_DATA_PATH ) ) == NULL ) {
129  "rsBulkDataObjReg: getSqlResultByInx for COL_D_DATA_PATH failed" );
130  return UNMATCHED_KEY_OR_INDEX;
131  }
132 
133  if ( ( dataMode =
134  getSqlResultByInx( bulkDataObjRegInp, COL_DATA_MODE ) ) == NULL ) {
136  "rsBulkDataObjReg: getSqlResultByInx for COL_DATA_MODE failed" );
137  return UNMATCHED_KEY_OR_INDEX;
138  }
139 
140  if ( ( oprType =
141  getSqlResultByInx( bulkDataObjRegInp, OPR_TYPE_INX ) ) == NULL ) {
143  "rsBulkDataObjReg: getSqlResultByInx for OPR_TYPE_INX failed" );
144  return UNMATCHED_KEY_OR_INDEX;
145  }
146 
147  if ( ( replNum =
148  getSqlResultByInx( bulkDataObjRegInp, COL_DATA_REPL_NUM ) ) == NULL ) {
150  "rsBulkDataObjReg: getSqlResultByInx for COL_DATA_REPL_NUM failed" );
151  return UNMATCHED_KEY_OR_INDEX;
152  }
153 
154  chksum = getSqlResultByInx( bulkDataObjRegInp, COL_D_DATA_CHECKSUM );
155 
156  /* the output */
157  initBulkDataObjRegOut( bulkDataObjRegOut );
158  if ( ( objId =
159  getSqlResultByInx( *bulkDataObjRegOut, COL_D_DATA_ID ) ) == NULL ) {
161  "rsBulkDataObjReg: getSqlResultByInx for COL_D_DATA_ID failed" );
162  return UNMATCHED_KEY_OR_INDEX;
163  }
164 
165  ( *bulkDataObjRegOut )->rowCnt = bulkDataObjRegInp->rowCnt;
166  for ( i = 0; i < bulkDataObjRegInp->rowCnt; i++ ) {
167  tmpObjPath = &objPath->value[objPath->len * i];
168  tmpDataType = &dataType->value[dataType->len * i];
169  tmpDataSize = &dataSize->value[dataSize->len * i];
170  tmpRescName = &rescName->value[rescName->len * i];
171  tmpRescID = &rescID->value[rescID->len * i];
172  tmpFilePath = &filePath->value[filePath->len * i];
173  tmpDataMode = &dataMode->value[dataMode->len * i];
174  tmpOprType = &oprType->value[oprType->len * i];
175  tmpReplNum = &replNum->value[replNum->len * i];
176  tmpObjId = &objId->value[objId->len * i];
177 
178  bzero( &dataObjInfo, sizeof( dataObjInfo_t ) );
179  dataObjInfo.flags = NO_COMMIT_FLAG;
180  rstrcpy( dataObjInfo.objPath, tmpObjPath, MAX_NAME_LEN );
181  rstrcpy( dataObjInfo.dataType, tmpDataType, NAME_LEN );
182  dataObjInfo.dataSize = strtoll( tmpDataSize, 0, 0 );
183  rstrcpy( dataObjInfo.rescName, tmpRescName, NAME_LEN );
184 
185  dataObjInfo.rescId = strtoll(tmpRescID, 0, 0);
186  std::string resc_hier;
187  irods::error ret = resc_mgr.leaf_id_to_hier(dataObjInfo.rescId, resc_hier);
188  if( !ret.ok() ) {
189  irods::log(PASS(ret));
190  }
191  else {
192  rstrcpy( dataObjInfo.rescHier, resc_hier.c_str(), MAX_NAME_LEN );
193  }
194  rstrcpy( dataObjInfo.filePath, tmpFilePath, MAX_NAME_LEN );
195  rstrcpy( dataObjInfo.dataMode, tmpDataMode, SHORT_STR_LEN );
196  dataObjInfo.replNum = atoi( tmpReplNum );
197  if ( chksum != NULL ) {
198  tmpChksum = &chksum->value[chksum->len * i];
199  if ( strlen( tmpChksum ) > 0 ) {
200  rstrcpy( dataObjInfo.chksum, tmpChksum, NAME_LEN );
201  }
202  }
203 
204  dataObjInfo.replStatus = NEWLY_CREATED_COPY;
205  if ( strcmp( tmpOprType, REGISTER_OPR ) == 0 ) {
206  status = svrRegDataObj( rsComm, &dataObjInfo );
207  }
208  else {
209  status = modDataObjSizeMeta( rsComm, &dataObjInfo, tmpDataSize );
210  }
211  if ( status >= 0 ) {
212  snprintf( tmpObjId, NAME_LEN, "%lld", dataObjInfo.dataId );
213 
214  // =-=-=-=-=-=-=-
215  // added due to lack of notificaiton of new data object
216  // to resource hiers during operation. ticket 1753
217  irods::file_object_ptr file_obj(
218  new irods::file_object(
219  rsComm,
220  &dataObjInfo ) );
221 
222  irods::error ret = fileModified( rsComm, file_obj );
223  if ( !ret.ok() ) {
224  std::stringstream msg;
225  msg << __FUNCTION__;
226  msg << " - Failed to signal resource that the data object \"";
227  msg << dataObjInfo.objPath;
228  msg << "\" was registered";
229  ret = PASSMSG( msg.str(), ret );
230  irods::log( ret );
231  return ret.code();
232  }
233 
234  }
235  else {
237  "rsBulkDataObjReg: RegDataObj or ModDataObj failed for %s,stat=%d",
238  tmpObjPath, status );
239  chlRollback( rsComm );
240  freeGenQueryOut( bulkDataObjRegOut );
241  *bulkDataObjRegOut = NULL;
242  return status;
243  }
244  }
245  status = chlCommit( rsComm );
246 
247  if ( status < 0 ) {
249  "rsBulkDataObjReg: chlCommit failed, status = %d", status );
250  freeGenQueryOut( bulkDataObjRegOut );
251  *bulkDataObjRegOut = NULL;
252  }
253  return status;
254  } else if( irods::CFG_SERVICE_ROLE_CONSUMER == svc_role ) {
255  return SYS_NO_RCAT_SERVER_ERR;
256  } else {
257  rodsLog(
258  LOG_ERROR,
259  "role not supported [%s]",
260  svc_role.c_str() );
262  }
263 }
264 
265 int
267  char *strDataSize ) {
268  modDataObjMeta_t modDataObjMetaInp;
269  keyValPair_t regParam;
270  char tmpStr[MAX_NAME_LEN];
271  int status;
272 
273  bzero( &modDataObjMetaInp, sizeof( modDataObjMetaInp ) );
274  bzero( &regParam, sizeof( regParam ) );
275  addKeyVal( &regParam, DATA_SIZE_KW, strDataSize );
276  addKeyVal( &regParam, ALL_REPL_STATUS_KW, "" );
277  snprintf( tmpStr, MAX_NAME_LEN, "%d", ( int ) time( NULL ) );
278  addKeyVal( &regParam, DATA_MODIFY_KW, tmpStr );
279  if ( strlen( dataObjInfo->chksum ) > 0 ) {
280  addKeyVal( &regParam, CHKSUM_KW, dataObjInfo->chksum );
281  }
282  addKeyVal( &regParam, IN_PDMO_KW, "" );
283  modDataObjMetaInp.dataObjInfo = dataObjInfo;
284  modDataObjMetaInp.regParam = &regParam;
285 
286  status = _rsModDataObjMeta( rsComm, &modDataObjMetaInp );
287 
288  clearKeyVal( &regParam );
289 
290  return status;
291 }
COL_DATA_TYPE_NAME
#define COL_DATA_TYPE_NAME
Definition: rodsGenQuery.h:168
rodsLog
void rodsLog(int level, const char *formatStr,...)
Definition: rodsLog.cpp:86
NULL
#define NULL
Definition: rodsDef.h:70
rsComm_t
Definition: rcConnect.h:145
COL_DATA_REPL_NUM
#define COL_DATA_REPL_NUM
Definition: rodsGenQuery.h:166
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
SYS_SERVICE_ROLE_NOT_SUPPORTED
@ SYS_SERVICE_ROLE_NOT_SUPPORTED
Definition: rodsErrorTable.h:217
NEWLY_CREATED_COPY
#define NEWLY_CREATED_COPY
Definition: objInfo.h:115
DATA_MODIFY_KW
#define DATA_MODIFY_KW
Definition: rodsKeyWdDef.h:42
OPR_TYPE_INX
#define OPR_TYPE_INX
Definition: bulkDataObjReg.h:9
UNMATCHED_KEY_OR_INDEX
@ UNMATCHED_KEY_OR_INDEX
Definition: rodsErrorTable.h:244
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
resc_mgr
irods::resource_manager resc_mgr
Definition: irods_resource_manager.cpp:31
CHKSUM_KW
#define CHKSUM_KW
Definition: rodsKeyWdDef.h:25
DataObjInfo::dataType
char dataType[64]
Definition: objInfo.h:133
modDataObjSizeMeta
int modDataObjSizeMeta(rsComm_t *rsComm, dataObjInfo_t *dataObjInfo, char *strDataSize)
Definition: rsBulkDataObjReg.cpp:266
DataObjInfo::rescId
rodsLong_t rescId
Definition: objInfo.h:164
svrRegDataObj
int svrRegDataObj(rsComm_t *rsComm, dataObjInfo_t *dataObjInfo)
Definition: rsRegDataObj.cpp:120
DataObjInfo::rescHier
char rescHier[(1024+64)]
Definition: objInfo.h:132
DataObjInfo::replStatus
int replStatus
Definition: objInfo.h:141
LOCAL_HOST
#define LOCAL_HOST
Definition: rodsConnect.h:44
initBulkDataObjRegOut
int initBulkDataObjRegOut(genQueryOut_t **bulkDataObjRegOut)
Definition: rcMisc.cpp:3688
PASSMSG
#define PASSMSG(message_, prev_error_)
Definition: irods_error.hpp:119
DataObjInfo::filePath
char filePath[(1024+64)]
Definition: objInfo.h:137
chlCommit
int chlCommit(rsComm_t *rsComm)
Definition: icatHighLevelRoutines.cpp:1090
LOG_ERROR
#define LOG_ERROR
Definition: rodsLog.h:43
rsBulkDataObjReg.hpp
DATA_SIZE_KW
#define DATA_SIZE_KW
Definition: rodsKeyWdDef.h:24
rcBulkDataObjReg
int rcBulkDataObjReg(rcComm_t *conn, genQueryOut_t *bulkDataObjRegInp, genQueryOut_t **bulkDataObjRegOut)
Definition: rcBulkDataObjReg.cpp:24
COL_D_DATA_CHECKSUM
#define COL_D_DATA_CHECKSUM
Definition: rodsGenQuery.h:177
DataObjInfo::dataId
rodsLong_t dataId
Definition: objInfo.h:143
_rsBulkDataObjReg
int _rsBulkDataObjReg(rsComm_t *rsComm, genQueryOut_t *bulkDataObjRegInp, genQueryOut_t **bulkDataObjRegOut)
Definition: rsBulkDataObjReg.cpp:73
COL_DATA_NAME
#define COL_DATA_NAME
Definition: rodsGenQuery.h:165
DataObjInfo::flags
int flags
Definition: objInfo.h:146
irods::error::code
long long code() const
Definition: irods_error.cpp:194
COL_D_RESC_NAME
#define COL_D_RESC_NAME
Definition: rodsGenQuery.h:171
getSqlResultByInx
sqlResult_t * getSqlResultByInx(genQueryOut_t *genQueryOut, int attriInx)
Definition: rcMisc.cpp:1387
irods::CFG_SERVICE_ROLE_PROVIDER
const std::string CFG_SERVICE_ROLE_PROVIDER("provider")
REGISTER_OPR
#define REGISTER_OPR
Definition: bulkDataObjReg.h:11
MAX_NAME_LEN
#define MAX_NAME_LEN
Definition: rodsDef.h:61
chlRollback
int chlRollback(rsComm_t *rsComm)
Definition: icatHighLevelRoutines.cpp:1039
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
GenQueryOut
Definition: rodsGenQuery.h:67
DataObjInfo::replNum
int replNum
Definition: objInfo.h:140
irods.pypyodbc.status
status
Definition: pypyodbc.py:467
rsBulkDataObjReg
int rsBulkDataObjReg(rsComm_t *rsComm, genQueryOut_t *bulkDataObjRegInp, genQueryOut_t **bulkDataObjRegOut)
Definition: rsBulkDataObjReg.cpp:20
GenQueryOut::rowCnt
int rowCnt
Definition: rodsGenQuery.h:68
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
irods::error
Definition: irods_error.hpp:23
miscServerFunct.hpp
modDataObjMeta_t::dataObjInfo
dataObjInfo_t * dataObjInfo
Definition: modDataObjMeta.h:8
irods::resource_manager::leaf_id_to_hier
error leaf_id_to_hier(const rodsLong_t &, std::string &)
Definition: irods_resource_manager.cpp:1119
getAndConnRcatHost
int getAndConnRcatHost(rsComm_t *rsComm, int rcatType, const char *rcatZoneHint, rodsServerHost_t **rodsServerHost)
Definition: rodsConnect.cpp:26
DataObjInfo::chksum
char chksum[64]
Definition: objInfo.h:135
SqlResult::value
char * value
Definition: rodsGenQuery.h:64
_rsModDataObjMeta
int _rsModDataObjMeta(rsComm_t *rsComm, modDataObjMeta_t *modDataObjMetaInp)
Definition: rsModDataObjMeta.cpp:78
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
DataObjInfo::rescName
char rescName[64]
Definition: objInfo.h:131
apiHeaderAll.h
SqlResult
Definition: rodsGenQuery.h:61
irods::file_object_ptr
boost::shared_ptr< file_object > file_object_ptr
Definition: irods_file_object.hpp:145
rsModDataObjMeta.hpp
SqlResult::len
int len
Definition: rodsGenQuery.h:63
icatHighLevelRoutines.hpp
ALL_REPL_STATUS_KW
#define ALL_REPL_STATUS_KW
Definition: rodsKeyWdDef.h:33
NO_COMMIT_FLAG
#define NO_COMMIT_FLAG
Definition: objInfo.h:127
DataObjInfo::objPath
char objPath[(1024+64)]
Definition: objInfo.h:130
rsRegDataObj.hpp
SHORT_STR_LEN
#define SHORT_STR_LEN
Definition: rodsDef.h:67
rstrcpy
char * rstrcpy(char *dest, const char *src, int maxLen)
Definition: stringOpr.cpp:51
COL_D_DATA_PATH
#define COL_D_DATA_PATH
Definition: rodsGenQuery.h:172
dataObjOpr.hpp
modDataObjMeta_t
Definition: modDataObjMeta.h:7
freeGenQueryOut
int freeGenQueryOut(genQueryOut_t **genQueryOut)
Definition: rcMisc.cpp:1133
NAME_LEN
#define NAME_LEN
Definition: rodsDef.h:55
KeyValPair
Definition: objInfo.h:120
clearKeyVal
int clearKeyVal(keyValPair_t *condInput)
Definition: rcMisc.cpp:1047
irods::error::ok
bool ok()
Definition: irods_error.cpp:258
DataObjInfo
Definition: objInfo.h:129
COL_DATA_SIZE
#define COL_DATA_SIZE
Definition: rodsGenQuery.h:169
DataObjInfo::dataSize
rodsLong_t dataSize
Definition: objInfo.h:134
DataObjInfo::dataMode
char dataMode[32]
Definition: objInfo.h:148
objMetaOpr.hpp
COL_D_RESC_ID
#define COL_D_RESC_ID
Definition: rodsGenQuery.h:185
COL_D_DATA_ID
#define COL_D_DATA_ID
Definition: rodsGenQuery.h:163
COL_DATA_MODE
#define COL_DATA_MODE
Definition: rodsGenQuery.h:183