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)  

rsDataObjRsync.cpp
Go to the documentation of this file.
1 #include "dataObjChksum.h"
2 #include "dataObjRsync.h"
3 #include "objMetaOpr.hpp"
4 #include "specColl.hpp"
5 #include "dataObjOpr.hpp"
6 #include "rsApiHandler.hpp"
7 #include "modDataObjMeta.h"
8 #include "getRemoteZoneResc.h"
9 #include "rsDataObjRsync.hpp"
10 #include "rsDataObjChksum.hpp"
11 #include "rsDataObjCopy.hpp"
12 
14 
15 int
16 rsDataObjRsync( rsComm_t *rsComm, dataObjInp_t *dataObjInp,
17  msParamArray_t **outParamArray ) {
18  int status;
19  char *rsyncMode;
20  char *remoteZoneOpr;
21  int remoteFlag;
23  specCollCache_t *specCollCache = NULL;
24 
25  *outParamArray = NULL;
26  if ( dataObjInp == NULL ) {
27  rodsLog( LOG_ERROR, "rsDataObjRsync error. NULL input" );
29  }
30 
31  rsyncMode = getValByKey( &dataObjInp->condInput, RSYNC_MODE_KW );
32  if ( rsyncMode == NULL ) {
34  "rsDataObjRsync: RSYNC_MODE_KW input is missing" );
36  }
37 
38  if ( strcmp( rsyncMode, LOCAL_TO_IRODS ) == 0 ) {
39  remoteZoneOpr = REMOTE_CREATE;
40  }
41  else {
42  remoteZoneOpr = REMOTE_OPEN;
43  }
44 
45  resolveLinkedPath( rsComm, dataObjInp->objPath, &specCollCache,
46  &dataObjInp->condInput );
47  if ( strcmp( rsyncMode, IRODS_TO_IRODS ) == 0 ) {
48  if ( isLocalZone( dataObjInp->objPath ) == 0 ) {
49  dataObjInp_t myDataObjInp;
50  char *destObjPath;
51  /* source in a remote zone. try dest */
52  destObjPath = getValByKey( &dataObjInp->condInput,
54  if ( destObjPath == NULL ) {
56  "rsDataObjRsync: RSYNC_DEST_PATH_KW input is missing for %s",
57  dataObjInp->objPath );
59  }
60  myDataObjInp = *dataObjInp;
61  remoteZoneOpr = REMOTE_CREATE;
62  rstrcpy( myDataObjInp.objPath, destObjPath, MAX_NAME_LEN );
63  remoteFlag = getAndConnRemoteZone( rsComm, &myDataObjInp,
64  &rodsServerHost, remoteZoneOpr );
65  }
66  else {
67  remoteFlag = getAndConnRemoteZone( rsComm, dataObjInp,
68  &rodsServerHost, remoteZoneOpr );
69  }
70  }
71  else {
72  remoteFlag = getAndConnRemoteZone( rsComm, dataObjInp, &rodsServerHost,
73  remoteZoneOpr );
74  }
75 
76  // =-=-=-=-=-=-=-
77  // determine the resource hierarchy if one is not provided
78  if ( getValByKey( &dataObjInp->condInput, RESC_HIER_STR_KW ) == NULL ) {
79  std::string hier;
81  rsComm, dataObjInp, hier );
82  if ( !ret.ok() ) {
83  std::stringstream msg;
84  msg << __FUNCTION__;
85  msg << " :: failed in irods::resolve_resource_hierarchy for [";
86  msg << dataObjInp->objPath << "]";
87  irods::log( PASSMSG( msg.str(), ret ) );
88  return ret.code();
89  }
90 
91  // =-=-=-=-=-=-=-
92  // we resolved the redirect and have a host, set the hier str for subsequent
93  // api calls, etc.
94  addKeyVal( &dataObjInp->condInput, RESC_HIER_STR_KW, hier.c_str() );
95 
96  } // if keyword
97 
98 
99 
100 
101  if ( remoteFlag < 0 ) {
102  return remoteFlag;
103  }
104  else if ( remoteFlag == REMOTE_HOST ) {
105 
106  status = _rcDataObjRsync( rodsServerHost->conn, dataObjInp,
107  outParamArray );
108  return status;
109  }
110 
111  if ( strcmp( rsyncMode, IRODS_TO_LOCAL ) == 0 ) {
112  status = rsRsyncFileToData( rsComm, dataObjInp );
113  }
114  else if ( strcmp( rsyncMode, LOCAL_TO_IRODS ) == 0 ) {
115  status = rsRsyncDataToFile( rsComm, dataObjInp );
116  }
117  else if ( strcmp( rsyncMode, IRODS_TO_IRODS ) == 0 ) {
118  status = rsRsyncDataToData( rsComm, dataObjInp );
119  }
120  else {
122  "rsDataObjRsync: rsyncMode %s not supported" );
124  }
125 
126  return status;
127 }
128 
129 int
130 rsRsyncDataToFile( rsComm_t *rsComm, dataObjInp_t *dataObjInp ) {
131  int status;
132  char *fileChksumStr = NULL;
133  char *dataObjChksumStr = NULL;
134  dataObjInfo_t *dataObjInfoHead = NULL;
135 
136  fileChksumStr = getValByKey( &dataObjInp->condInput, RSYNC_CHKSUM_KW );
137 
138  if ( fileChksumStr == NULL ) {
140  "rsRsyncDataToFile: RSYNC_CHKSUM_KW input is missing for %s",
141  dataObjInp->objPath );
143  }
144 
145  addKeyVal( &dataObjInp->condInput, ORIG_CHKSUM_KW, fileChksumStr );
146 
147  status = _rsDataObjChksum( rsComm, dataObjInp, &dataObjChksumStr,
148  &dataObjInfoHead );
149 
150  if ( status < 0 && status != CAT_NO_ACCESS_PERMISSION &&
152  /* XXXXX CAT_NO_ACCESS_PERMISSION mean the chksum was calculated but
153  * cannot be registered. But the chksum value is OK.
154  */
156  "rsRsyncDataToFile: _rsDataObjChksum of %s error. status = %d",
157  dataObjInp->objPath, status );
158  return status;
159  }
160 
161  freeAllDataObjInfo( dataObjInfoHead );
162  status = dataObjChksumStr && strcmp( dataObjChksumStr, fileChksumStr ) == 0 ?
164 
165  free( dataObjChksumStr );
166 
167  return status;
168 }
169 
170 int
171 rsRsyncFileToData( rsComm_t *rsComm, dataObjInp_t *dataObjInp ) {
172 
173  char * fileChksumStr = getValByKey( &dataObjInp->condInput, RSYNC_CHKSUM_KW );
174 
175  if ( fileChksumStr == NULL ) {
177  "rsRsyncFileToData: RSYNC_CHKSUM_KW input is missing" );
179  }
180 
181  addKeyVal( &dataObjInp->condInput, ORIG_CHKSUM_KW, fileChksumStr );
182 
183  // =-=-=-=-=-=-=-
184  // determine the resource hierarchy if one is not provided
185  if ( getValByKey( &dataObjInp->condInput, RESC_HIER_STR_KW ) == NULL ) {
186  std::string hier;
188  rsComm, dataObjInp, hier );
189  if ( !ret.ok() ) {
190  std::stringstream msg;
191  msg << __FUNCTION__;
192  msg << " :: failed in irods::resolve_resource_hierarchy for [";
193  msg << dataObjInp->objPath << "]";
194  irods::log( PASSMSG( msg.str(), ret ) );
195  return ret.code();
196  }
197 
198  // =-=-=-=-=-=-=-
199  // we resolved the redirect and have a host, set the hier str for subsequent
200  // api calls, etc.
201  addKeyVal( &dataObjInp->condInput, RESC_HIER_STR_KW, hier.c_str() );
202 
203  } // if keyword
204 
205  char *dataObjChksumStr = NULL;
206  dataObjInfo_t *dataObjInfoHead = NULL;
207  int status = _rsDataObjChksum( rsComm, dataObjInp, &dataObjChksumStr,
208  &dataObjInfoHead );
209 
210  if ( status < 0 && status != CAT_NO_ACCESS_PERMISSION &&
212  /* XXXXX CAT_NO_ACCESS_PERMISSION mean the chksum was calculated but
213  * cannot be registered. But the chksum value is OK.
214  */
216  "rsRsyncFileToData: _rsDataObjChksum of %s error. status = %d",
217  dataObjInp->objPath, status );
218  }
219 
220  freeAllDataObjInfo( dataObjInfoHead );
221  if ( dataObjChksumStr != NULL &&
222  strcmp( dataObjChksumStr, fileChksumStr ) == 0 ) {
223  free( dataObjChksumStr );
224  return 0;
225  }
226  free( dataObjChksumStr );
228 }
229 
230 int
231 rsRsyncDataToData( rsComm_t *rsComm, dataObjInp_t *dataObjInp ) {
232  int status;
233  char *srcChksumStr = NULL;
234  char *destChksumStr = NULL;
235  dataObjCopyInp_t dataObjCopyInp;
236  char *destObjPath;
237  transferStat_t *transStat = NULL;
238 
239  /* always have the FORCE flag on */
240  addKeyVal( &dataObjInp->condInput, FORCE_FLAG_KW, "" );
241 
242  destObjPath = getValByKey( &dataObjInp->condInput, RSYNC_DEST_PATH_KW );
243  if ( destObjPath == NULL ) {
245  "rsRsyncDataToData: RSYNC_DEST_PATH_KW input is missing for %s",
246  dataObjInp->objPath );
248  }
249 
250  memset( &dataObjCopyInp, 0, sizeof( dataObjCopyInp ) );
251  rstrcpy( dataObjCopyInp.srcDataObjInp.objPath, dataObjInp->objPath,
252  MAX_NAME_LEN );
253  dataObjCopyInp.srcDataObjInp.dataSize = dataObjInp->dataSize;
254  replDataObjInp( dataObjInp, &dataObjCopyInp.destDataObjInp );
255  rstrcpy( dataObjCopyInp.destDataObjInp.objPath, destObjPath,
256  MAX_NAME_LEN );
257  // we need the destination resource hierarchy to vote on the write
259 
260  /* use rsDataObjChksum because the path could in in remote zone */
261  status = rsDataObjChksum( rsComm, &dataObjCopyInp.srcDataObjInp,
262  &srcChksumStr );
263 
264  if ( status < 0 &&
265  ( status != CAT_NO_ACCESS_PERMISSION || srcChksumStr == NULL ) ) {
266  /* XXXXX CAT_NO_ACCESS_PERMISSION mean the chksum was calculated but
267  * cannot be registered. But the chksum value is OK.
268  */
270  "rsRsyncDataToData: _rsDataObjChksum error for %s, status = %d",
271  dataObjCopyInp.srcDataObjInp.objPath, status );
272  clearKeyVal( &dataObjCopyInp.srcDataObjInp.condInput );
273  return status;
274  }
275 
276  /* use rsDataObjChksum because the path could in in remote zone */
277  status = rsDataObjChksum( rsComm, &dataObjCopyInp.destDataObjInp,
278  &destChksumStr );
279 
280  if ( status < 0 && status != CAT_NO_ACCESS_PERMISSION &&
283  "rsRsyncDataToData: _rsDataObjChksum error for %s, status = %d",
284  dataObjCopyInp.destDataObjInp.objPath, status );
285  free( srcChksumStr );
286  free( destChksumStr );
287  clearKeyVal( &dataObjCopyInp.srcDataObjInp.condInput );
288  clearKeyVal( &dataObjCopyInp.destDataObjInp.condInput );
289  return status;
290  }
291 
292  if ( destChksumStr != NULL && strcmp( srcChksumStr, destChksumStr ) == 0 ) {
293  free( srcChksumStr );
294  free( destChksumStr );
295  clearKeyVal( &dataObjCopyInp.destDataObjInp.condInput );
296  clearKeyVal( &dataObjCopyInp.srcDataObjInp.condInput );
297  return 0;
298  }
299 
301  srcChksumStr );
302  status = rsDataObjCopy( rsComm, &dataObjCopyInp, &transStat );
303  free( transStat );
304  free( srcChksumStr );
305  free( destChksumStr );
306  clearKeyVal( &dataObjCopyInp.destDataObjInp.condInput );
307  clearKeyVal( &dataObjCopyInp.srcDataObjInp.condInput );
308 
309  if ( status >= 0 ) {
311  }
312  else {
313  return status;
314  }
315 }
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
IRODS_TO_IRODS
#define IRODS_TO_IRODS
Definition: rodsDef.h:126
DataObjCopyInp::srcDataObjInp
dataObjInp_t srcDataObjInp
Definition: dataObjCopy.h:26
transferStat_t
Definition: objInfo.h:291
addKeyVal
int addKeyVal(keyValPair_t *condInput, const char *keyWord, const char *value)
Definition: rcMisc.cpp:789
SYS_INTERNAL_NULL_INPUT_ERR
@ SYS_INTERNAL_NULL_INPUT_ERR
Definition: rodsErrorTable.h:92
getRemoteZoneResc.h
DataObjCopyInp
Definition: dataObjCopy.h:25
specColl.hpp
CAT_NO_ACCESS_PERMISSION
@ CAT_NO_ACCESS_PERMISSION
Definition: rodsErrorTable.h:433
modDataObjMeta.h
rodsServerHost::conn
rcComm_t * conn
Definition: rodsConnect.h:64
CHKSUM_EMPTY_IN_STRUCT_ERR
@ CHKSUM_EMPTY_IN_STRUCT_ERR
Definition: rodsErrorTable.h:580
DataObjInp::dataSize
rodsLong_t dataSize
Definition: dataObjInpOut.h:70
irods::resolve_resource_hierarchy
error resolve_resource_hierarchy(const std::string &, rsComm_t *, dataObjInp_t *, std::string &, dataObjInfo_t **_data_obj_info=0)
Definition: irods_resource_redirect.cpp:505
isLocalZone
int isLocalZone(char *zoneHint)
Definition: rodsConnect.cpp:869
rsDataObjRsync
int rsDataObjRsync(rsComm_t *rsComm, dataObjInp_t *dataObjInp, msParamArray_t **outParamArray)
Definition: rsDataObjRsync.cpp:16
rsRsyncDataToFile
int rsRsyncDataToFile(rsComm_t *rsComm, dataObjInp_t *dataObjInp)
Definition: rsDataObjRsync.cpp:130
USER_RSYNC_NO_MODE_INPUT_ERR
@ USER_RSYNC_NO_MODE_INPUT_ERR
Definition: rodsErrorTable.h:258
RSYNC_DEST_PATH_KW
#define RSYNC_DEST_PATH_KW
Definition: rodsKeyWdDef.h:57
REMOTE_HOST
#define REMOTE_HOST
Definition: rodsConnect.h:45
REMOTE_OPEN
#define REMOTE_OPEN
Definition: getRemoteZoneResc.h:5
PASSMSG
#define PASSMSG(message_, prev_error_)
Definition: irods_error.hpp:119
LOG_ERROR
#define LOG_ERROR
Definition: rodsLog.h:43
rsDataObjRsync.hpp
irods_resource_redirect.hpp
resolveLinkedPath
int resolveLinkedPath(rsComm_t *rsComm, char *objPath, specCollCache_t **specCollCache, keyValPair_t *condInput)
Definition: specColl.cpp:711
REG_CHKSUM_KW
#define REG_CHKSUM_KW
Definition: rodsKeyWdDef.h:15
irods::OPEN_OPERATION
const std::string OPEN_OPERATION("OPEN")
irods::error::code
long long code() const
Definition: irods_error.cpp:194
RESC_HIER_STR_KW
#define RESC_HIER_STR_KW
Definition: rodsKeyWdDef.h:225
freeAllDataObjInfo
int freeAllDataObjInfo(dataObjInfo_t *dataObjInfoHead)
Definition: rcMisc.cpp:561
rsRsyncFileToData
int rsRsyncFileToData(rsComm_t *rsComm, dataObjInp_t *dataObjInp)
Definition: rsDataObjRsync.cpp:171
LOCAL_TO_IRODS
#define LOCAL_TO_IRODS
Definition: rodsDef.h:124
_rcDataObjRsync
int _rcDataObjRsync(rcComm_t *conn, dataObjInp_t *dataObjInp, msParamArray_t **outParamArray)
Definition: rcDataObjRsync.cpp:221
rsDataObjCopy.hpp
SYS_SVR_TO_CLI_PUT_ACTION
#define SYS_SVR_TO_CLI_PUT_ACTION
Definition: rodsDef.h:112
REMOTE_CREATE
#define REMOTE_CREATE
Definition: getRemoteZoneResc.h:4
DataObjInp
Definition: dataObjInpOut.h:65
MAX_NAME_LEN
#define MAX_NAME_LEN
Definition: rodsDef.h:61
rsDataObjChksum.hpp
rmKeyVal
int rmKeyVal(keyValPair_t *condInput, const char *keyWord)
Definition: rcMisc.cpp:710
rsDataObjChksum
int rsDataObjChksum(rsComm_t *rsComm, dataObjInp_t *dataObjChksumInp, char **outChksum)
Definition: rsDataObjChksum.cpp:64
irods.pypyodbc.status
status
Definition: pypyodbc.py:467
RSYNC_MODE_KW
#define RSYNC_MODE_KW
Definition: rodsKeyWdDef.h:56
irods::log
void log(const error &)
Definition: irods_log.cpp:13
rsDataObjCopy
int rsDataObjCopy(rsComm_t *rsComm, dataObjCopyInp_t *dataObjCopyInp, transferStat_t **transferStat)
Definition: rsDataObjCopy.cpp:148
irods::error
Definition: irods_error.hpp:23
DataObjCopyInp::destDataObjInp
dataObjInp_t destDataObjInp
Definition: dataObjCopy.h:27
FORCE_FLAG_KW
#define FORCE_FLAG_KW
Definition: rodsKeyWdDef.h:13
ORIG_CHKSUM_KW
#define ORIG_CHKSUM_KW
Definition: rodsKeyWdDef.h:26
rodsServerHost
Definition: rodsConnect.h:62
CAT_NO_ROWS_FOUND
@ CAT_NO_ROWS_FOUND
Definition: rodsErrorTable.h:423
RSYNC_CHKSUM_KW
#define RSYNC_CHKSUM_KW
Definition: rodsKeyWdDef.h:58
IRODS_TO_LOCAL
#define IRODS_TO_LOCAL
Definition: rodsDef.h:125
SYS_RSYNC_TARGET_MODIFIED
#define SYS_RSYNC_TARGET_MODIFIED
Definition: rodsDef.h:114
_rsDataObjChksum
int _rsDataObjChksum(rsComm_t *rsComm, dataObjInp_t *dataObjInp, char **outChksumStr, dataObjInfo_t **dataObjInfoHead)
Definition: rsDataObjChksum.cpp:115
getAndConnRemoteZone
int getAndConnRemoteZone(rsComm_t *rsComm, dataObjInp_t *dataObjInp, rodsServerHost_t **rodsServerHost, char *remotZoneOpr)
Definition: rodsConnect.cpp:784
dataObjRsync.h
replDataObjInp
int replDataObjInp(dataObjInp_t *srcDataObjInp, dataObjInp_t *destDataObjInp)
Definition: rcMisc.cpp:765
rstrcpy
char * rstrcpy(char *dest, const char *src, int maxLen)
Definition: stringOpr.cpp:51
rsRsyncDataToData
int rsRsyncDataToData(rsComm_t *rsComm, dataObjInp_t *dataObjInp)
Definition: rsDataObjRsync.cpp:231
dataObjOpr.hpp
rsApiHandler.hpp
DataObjInp::condInput
keyValPair_t condInput
Definition: dataObjInpOut.h:74
MsParamArray
Definition: msParam.h:84
dataObjChksum.h
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
SYS_SVR_TO_CLI_GET_ACTION
#define SYS_SVR_TO_CLI_GET_ACTION
Definition: rodsDef.h:113
SpecCollCache
Definition: objInfo.h:102
objMetaOpr.hpp