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)  

rsObjStat.cpp
Go to the documentation of this file.
1 
3 /* rsObjStat.c
4  */
5 
6 #include "rsObjStat.hpp"
7 #include "objStat.h"
8 #include "rcMisc.h"
9 #include "genQuery.h"
10 #include "querySpecColl.h"
11 #include "objMetaOpr.hpp"
12 #include "collection.hpp"
13 #include "specColl.hpp"
14 #include "resource.hpp"
15 #include "rcGlobalExtern.h"
16 #include "rsGlobalExtern.hpp"
17 #include "dataObjClose.h"
18 #include "miscServerFunct.hpp"
20 #include "rsGenQuery.hpp"
21 
22 int
24  rsComm_t *rsComm,
25  dataObjInp_t *dataObjInp,
26  rodsObjStat_t **rodsObjStatOut ) {
27  int status;
29  specCollCache_t *specCollCache = NULL;
30  int linkCnt;
31 
32  linkCnt = resolveLinkedPath( rsComm, dataObjInp->objPath, &specCollCache,
33  NULL );
34 
35  *rodsObjStatOut = NULL;
37  rsComm,
38  SLAVE_RCAT,
39  ( const char* )dataObjInp->objPath,
40  &rodsServerHost );
41  if ( status < 0 || NULL == rodsServerHost ) { // JMC cppcheck - nullptr
42  return status;
43  }
45  std::string svc_role;
46  irods::error ret = get_catalog_service_role(svc_role);
47  if(!ret.ok()) {
48  irods::log(PASS(ret));
49  return ret.code();
50  }
51 
52  if( irods::CFG_SERVICE_ROLE_PROVIDER == svc_role ) {
53  status = _rsObjStat( rsComm, dataObjInp, rodsObjStatOut );
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  if ( isLocalZone( dataObjInp->objPath ) ) {
66  /* see if it is a sub path of a specColl cached locally. If it is,
67  * it will save time resolving it */
68  status = statPathInSpecColl( rsComm, dataObjInp->objPath, 1, rodsObjStatOut );
69 
70  if ( status >= 0 ) {
71  /* the path is in a specColl */
72  return status;
73  }
74  else if ( status != SYS_SPEC_COLL_NOT_IN_CACHE ) {
75  /* path is in the path of specColl cache but does not exist */
76  if ( linkCnt > 0 && *rodsObjStatOut != NULL ) {
77  /* a soft link - returns specColl */
78  if ( ( *rodsObjStatOut )->specColl == NULL ) {
79  replSpecColl( &specCollCache->specColl,
80  &( *rodsObjStatOut )->specColl );
81  }
82  rstrcpy( ( *rodsObjStatOut )->specColl->objPath,
83  dataObjInp->objPath, MAX_NAME_LEN );
84  }
85 
86  return status;
87  }
88  /* falls through if the path is not in a cached specColl */
89  }
90  /* not in cache, need to do a remote call */
91  status = rcObjStat( rodsServerHost->conn, dataObjInp, rodsObjStatOut );
92  if ( status >= 0 && *rodsObjStatOut != NULL && ( *rodsObjStatOut )->specColl != NULL ) {
93  /* queue it in cache */
94  queueSpecCollCacheWithObjStat( *rodsObjStatOut );
95  }
96  }
97 
98  if ( linkCnt > 0 && *rodsObjStatOut != NULL ) {
99  /* fill in (*rodsObjStatOut)->specColl if it is linked */
100  if ( ( *rodsObjStatOut )->specColl == NULL ) {
101  replSpecColl( &specCollCache->specColl,
102  &( *rodsObjStatOut )->specColl );
103  }
104  rstrcpy( ( *rodsObjStatOut )->specColl->objPath, dataObjInp->objPath, MAX_NAME_LEN );
105 
106  }
107  return status;
108 }
109 
110 int
111 _rsObjStat( rsComm_t *rsComm, dataObjInp_t *dataObjInp,
112  rodsObjStat_t **rodsObjStatOut ) {
113 
114  int status;
115  char *tmpStr;
116  specCollCache_t *specCollCache;
117 
118  /* do data first to catch data registered in spec Coll */
119  if ( ( tmpStr = getValByKey( &dataObjInp->condInput, SEL_OBJ_TYPE_KW ) ) ==
120  NULL || strcmp( tmpStr, "dataObj" ) == 0 ) {
121  status = dataObjStat( rsComm, dataObjInp, rodsObjStatOut );
122  if ( status >= 0 ) {
123  return status;
124  }
125  }
126 
127  if ( tmpStr == NULL || strcmp( tmpStr, "collection" ) == 0 ) {
128  status = collStat( rsComm, dataObjInp, rodsObjStatOut );
129  /* specColl may already been obtained from collStat */
130  if ( status >= 0 ) {
131  if ( ( *rodsObjStatOut )->specColl == NULL ) {
132  if ( getSpecCollCache( rsComm, dataObjInp->objPath, 0,
133  &specCollCache ) >= 0 ) {
134  replSpecColl( &specCollCache->specColl,
135  &( *rodsObjStatOut )->specColl );
136  }
137  }
138  return status;
139  }
140  }
141 
142  /* not normal dataObj or coll. now check specColl */
143  /* XXXX need to check a rule if it supports spec collection */
144  status = statPathInSpecColl( rsComm, dataObjInp->objPath, 0, rodsObjStatOut );
145  /* use USER_FILE_DOES_NOT_EXIST instead of OBJ_PATH_DOES_NOT_EXIST
146  * because icommand depends on it */
147  if ( status < 0 ) {
149  }
150  return status;
151 }
152 
153 int
154 dataObjStat( rsComm_t *rsComm, dataObjInp_t *dataObjInp,
155  rodsObjStat_t **rodsObjStatOut ) {
156  genQueryInp_t genQueryInp;
157  genQueryOut_t *genQueryOut = NULL;
158  int status;
159  char myColl[MAX_NAME_LEN], myData[MAX_NAME_LEN];
160  char condStr[MAX_NAME_LEN];
161  sqlResult_t *dataSize;
162  sqlResult_t *dataMode;
163  sqlResult_t *replStatus;
164  sqlResult_t *dataId;
165  sqlResult_t *chksum;
166  sqlResult_t *ownerName;
167  sqlResult_t *ownerZone;
168  sqlResult_t *createTime;
169  sqlResult_t *modifyTime;
170  sqlResult_t *rescHier;
171 
172  /* see if objPath is a dataObj */
173 
174  memset( myColl, 0, MAX_NAME_LEN );
175  memset( myData, 0, MAX_NAME_LEN );
176 
177  if ( ( status = splitPathByKey(
178  dataObjInp->objPath, myColl, MAX_NAME_LEN, myData, MAX_NAME_LEN, '/' ) ) < 0 ) {
180  }
181 
182  memset( &genQueryInp, 0, sizeof( genQueryInp ) );
183 
184  snprintf( condStr, MAX_NAME_LEN, "='%s'", myColl );
185  addInxVal( &genQueryInp.sqlCondInp, COL_COLL_NAME, condStr );
186  snprintf( condStr, MAX_NAME_LEN, "='%s'", myData );
187  addInxVal( &genQueryInp.sqlCondInp, COL_DATA_NAME, condStr );
188 
189  addInxIval( &genQueryInp.selectInp, COL_D_DATA_ID, 1 );
190  addInxIval( &genQueryInp.selectInp, COL_DATA_SIZE, 1 );
191  addInxIval( &genQueryInp.selectInp, COL_DATA_MODE, 1 );
192  addInxIval( &genQueryInp.selectInp, COL_D_REPL_STATUS, 1 );
193  addInxIval( &genQueryInp.selectInp, COL_D_DATA_CHECKSUM, 1 );
194  addInxIval( &genQueryInp.selectInp, COL_D_OWNER_NAME, 1 );
195  addInxIval( &genQueryInp.selectInp, COL_D_OWNER_ZONE, 1 );
196  addInxIval( &genQueryInp.selectInp, COL_D_CREATE_TIME, 1 );
197  addInxIval( &genQueryInp.selectInp, COL_D_MODIFY_TIME, 1 );
198  addInxIval( &genQueryInp.selectInp, COL_D_RESC_HIER, 1 );
199 
200  genQueryInp.maxRows = MAX_SQL_ROWS;
201  status = rsGenQuery( rsComm, &genQueryInp, &genQueryOut );
202 
203  clearGenQueryInp( &genQueryInp );
204 
205  if ( status >= 0 ) {
206  if ( ( dataSize = getSqlResultByInx( genQueryOut, COL_DATA_SIZE ) )
207  == NULL ) {
209  "_rsObjStat: getSqlResultByInx for COL_DATA_SIZE failed" );
210  return UNMATCHED_KEY_OR_INDEX;
211  }
212  else if ( ( dataMode = getSqlResultByInx( genQueryOut,
213  COL_DATA_MODE ) ) == NULL ) {
215  "_rsObjStat: getSqlResultByInx for COL_DATA_MODE failed" );
216  return UNMATCHED_KEY_OR_INDEX;
217  }
218  else if ( ( replStatus = getSqlResultByInx( genQueryOut,
219  COL_D_REPL_STATUS ) ) == NULL ) {
221  "_rsObjStat: getSqlResultByInx for COL_D_REPL_STATUS failed" );
222  return UNMATCHED_KEY_OR_INDEX;
223  }
224  else if ( ( dataId = getSqlResultByInx( genQueryOut,
225  COL_D_DATA_ID ) ) == NULL ) {
227  "_rsObjStat: getSqlResultByInx for COL_D_DATA_ID failed" );
228  return UNMATCHED_KEY_OR_INDEX;
229  }
230  else if ( ( chksum = getSqlResultByInx( genQueryOut,
231  COL_D_DATA_CHECKSUM ) ) == NULL ) {
233  "_rsObjStat:getSqlResultByInx for COL_D_DATA_CHECKSUM failed" );
234  return UNMATCHED_KEY_OR_INDEX;
235  }
236  else if ( ( ownerName = getSqlResultByInx( genQueryOut,
237  COL_D_OWNER_NAME ) ) == NULL ) {
239  "_rsObjStat:getSqlResultByInx for COL_D_OWNER_NAME failed" );
240  return UNMATCHED_KEY_OR_INDEX;
241  }
242  else if ( ( ownerZone = getSqlResultByInx( genQueryOut,
243  COL_D_OWNER_ZONE ) ) == NULL ) {
245  "_rsObjStat:getSqlResultByInx for COL_D_OWNER_ZONE failed" );
246  return UNMATCHED_KEY_OR_INDEX;
247  }
248  else if ( ( createTime = getSqlResultByInx( genQueryOut,
249  COL_D_CREATE_TIME ) ) == NULL ) {
251  "_rsObjStat:getSqlResultByInx for COL_D_CREATE_TIME failed" );
252  return UNMATCHED_KEY_OR_INDEX;
253  }
254  else if ( ( modifyTime = getSqlResultByInx( genQueryOut,
255  COL_D_MODIFY_TIME ) ) == NULL ) {
257  "_rsObjStat:getSqlResultByInx for COL_D_MODIFY_TIME failed" );
258  return UNMATCHED_KEY_OR_INDEX;
259  }
260  else if ( ( rescHier = getSqlResultByInx( genQueryOut,
261  COL_D_RESC_HIER ) ) == NULL ) {
263  "_rsObjStat:getSqlResultByInx for COL_D_RESC_HIER failed" );
264  return UNMATCHED_KEY_OR_INDEX;
265  }
266  else {
267  int i;
268 
269  *rodsObjStatOut = ( rodsObjStat_t * ) malloc( sizeof( rodsObjStat_t ) );
270  memset( *rodsObjStatOut, 0, sizeof( rodsObjStat_t ) );
271  ( *rodsObjStatOut )->objType = DATA_OBJ_T;
272  status = ( int )DATA_OBJ_T;
273  /* XXXXXX . dont have numCopies anymore. Replaced by dataMode
274  * (*rodsObjStatOut)->numCopies = genQueryOut->rowCnt; */
275 
276  for ( i = 0; i < genQueryOut->rowCnt; i++ ) {
277  if ( atoi( &replStatus->value[replStatus->len * i] ) > 0 ) {
278  rstrcpy( ( *rodsObjStatOut )->dataId,
279  &dataId->value[dataId->len * i], NAME_LEN );
280  ( *rodsObjStatOut )->objSize =
281  strtoll( &dataSize->value[dataSize->len * i], 0, 0 );
282  ( *rodsObjStatOut )->dataMode =
283  atoi( &dataMode->value[dataMode->len * i] );
284  rstrcpy( ( *rodsObjStatOut )->chksum,
285  &chksum->value[chksum->len * i], NAME_LEN );
286  rstrcpy( ( *rodsObjStatOut )->ownerName,
287  &ownerName->value[ownerName->len * i], NAME_LEN );
288  rstrcpy( ( *rodsObjStatOut )->ownerZone,
289  &ownerZone->value[ownerZone->len * i], NAME_LEN );
290  rstrcpy( ( *rodsObjStatOut )->createTime,
291  &createTime->value[createTime->len * i], TIME_LEN );
292  rstrcpy( ( *rodsObjStatOut )->modifyTime,
293  &modifyTime->value[modifyTime->len * i], TIME_LEN );
294  rstrcpy( ( *rodsObjStatOut )->rescHier,
295  &rescHier->value[rescHier->len * i], MAX_NAME_LEN );
296  break;
297  }
298  }
299 
300  if ( strlen( ( *rodsObjStatOut )->dataId ) == 0 ) {
301  /* just use the first one */
302  rstrcpy( ( *rodsObjStatOut )->dataId, dataId->value, NAME_LEN );
303  ( *rodsObjStatOut )->objSize = strtoll( dataSize->value, 0, 0 );
304  rstrcpy( ( *rodsObjStatOut )->chksum, chksum->value, NAME_LEN );
305  rstrcpy( ( *rodsObjStatOut )->ownerName, ownerName->value,
306  NAME_LEN );
307  rstrcpy( ( *rodsObjStatOut )->ownerZone, ownerZone->value,
308  NAME_LEN );
309  rstrcpy( ( *rodsObjStatOut )->createTime, createTime->value,
310  TIME_LEN );
311  rstrcpy( ( *rodsObjStatOut )->modifyTime, modifyTime->value,
312  TIME_LEN );
313  rstrcpy( ( *rodsObjStatOut )->rescHier, rescHier->value,
314  MAX_NAME_LEN );
315  }
316  }
317  }
318 
319  freeGenQueryOut( &genQueryOut );
320 
321  return status;
322 }
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
MAX_SQL_ROWS
#define MAX_SQL_ROWS
Definition: rodsGenQuery.h:16
NULL
#define NULL
Definition: rodsDef.h:70
rsComm_t
Definition: rcConnect.h:145
irods::CFG_SERVICE_ROLE_CONSUMER
const std::string CFG_SERVICE_ROLE_CONSUMER("consumer")
irods_configuration_keywords.hpp
COL_D_REPL_STATUS
#define COL_D_REPL_STATUS
Definition: rodsGenQuery.h:175
rodsServerHost::localFlag
int localFlag
Definition: rodsConnect.h:68
_rsObjStat
int _rsObjStat(rsComm_t *rsComm, dataObjInp_t *dataObjInp, rodsObjStat_t **rodsObjStatOut)
Definition: rsObjStat.cpp:111
SYS_SERVICE_ROLE_NOT_SUPPORTED
@ SYS_SERVICE_ROLE_NOT_SUPPORTED
Definition: rodsErrorTable.h:217
specColl.hpp
COL_D_RESC_HIER
#define COL_D_RESC_HIER
Definition: rodsGenQuery.h:184
UNMATCHED_KEY_OR_INDEX
@ UNMATCHED_KEY_OR_INDEX
Definition: rodsErrorTable.h:244
rodsServerHost::conn
rcComm_t * conn
Definition: rodsConnect.h:64
rcObjStat
int rcObjStat(rcComm_t *conn, dataObjInp_t *dataObjInp, rodsObjStat_t **rodsObjStatOut)
Definition: rcObjStat.cpp:65
objStat.h
rsObjStat
int rsObjStat(rsComm_t *rsComm, dataObjInp_t *dataObjInp, rodsObjStat_t **rodsObjStatOut)
Definition: rsObjStat.cpp:23
PASS
#define PASS(prev_error_)
Definition: irods_error.hpp:118
isLocalZone
int isLocalZone(char *zoneHint)
Definition: rodsConnect.cpp:869
getSpecCollCache
int getSpecCollCache(rsComm_t *rsComm, char *objPath, int inCachOnly, specCollCache_t **specCollCache)
Definition: specColl.cpp:255
GenQueryInp
Definition: rodsGenQuery.h:24
rcMisc.h
USER_FILE_DOES_NOT_EXIST
@ USER_FILE_DOES_NOT_EXIST
Definition: rodsErrorTable.h:241
LOCAL_HOST
#define LOCAL_HOST
Definition: rodsConnect.h:44
collStat
int collStat(rsComm_t *rsComm, dataObjInp_t *dataObjInp, rodsObjStat_t **rodsObjStatOut)
Definition: collection.cpp:271
dataObjStat
int dataObjStat(rsComm_t *rsComm, dataObjInp_t *dataObjInp, rodsObjStat_t **rodsObjStatOut)
Definition: rsObjStat.cpp:154
rcGlobalExtern.h
addInxVal
int addInxVal(inxValPair_t *inxValPair, int inx, const char *value)
Definition: rcMisc.cpp:921
LOG_ERROR
#define LOG_ERROR
Definition: rodsLog.h:43
COL_D_DATA_CHECKSUM
#define COL_D_DATA_CHECKSUM
Definition: rodsGenQuery.h:177
GenQueryInp::selectInp
inxIvalPair_t selectInp
Definition: rodsGenQuery.h:53
GenQueryInp::maxRows
int maxRows
Definition: rodsGenQuery.h:25
COL_D_OWNER_NAME
#define COL_D_OWNER_NAME
Definition: rodsGenQuery.h:173
resolveLinkedPath
int resolveLinkedPath(rsComm_t *rsComm, char *objPath, specCollCache_t **specCollCache, keyValPair_t *condInput)
Definition: specColl.cpp:711
COL_DATA_NAME
#define COL_DATA_NAME
Definition: rodsGenQuery.h:165
rsGlobalExtern.hpp
statPathInSpecColl
int statPathInSpecColl(rsComm_t *rsComm, char *objPath, int inCachOnly, rodsObjStat_t **rodsObjStatOut)
Definition: specColl.cpp:319
irods::error::code
long long code() const
Definition: irods_error.cpp:194
getSqlResultByInx
sqlResult_t * getSqlResultByInx(genQueryOut_t *genQueryOut, int attriInx)
Definition: rcMisc.cpp:1387
COL_D_MODIFY_TIME
#define COL_D_MODIFY_TIME
Definition: rodsGenQuery.h:182
TIME_LEN
#define TIME_LEN
Definition: rodsDef.h:54
irods::CFG_SERVICE_ROLE_PROVIDER
const std::string CFG_SERVICE_ROLE_PROVIDER("provider")
COL_D_CREATE_TIME
#define COL_D_CREATE_TIME
Definition: rodsGenQuery.h:181
GenQueryInp::sqlCondInp
inxValPair_t sqlCondInp
Definition: rodsGenQuery.h:56
DataObjInp
Definition: dataObjInpOut.h:65
OBJ_PATH_DOES_NOT_EXIST
@ OBJ_PATH_DOES_NOT_EXIST
Definition: rodsErrorTable.h:279
genQuery.h
MAX_NAME_LEN
#define MAX_NAME_LEN
Definition: rodsDef.h:61
addInxIval
int addInxIval(inxIvalPair_t *inxIvalPair, int inx, int value)
Definition: rcMisc.cpp:883
SYS_NO_RCAT_SERVER_ERR
@ SYS_NO_RCAT_SERVER_ERR
Definition: rodsErrorTable.h:110
GenQueryOut
Definition: rodsGenQuery.h:67
SEL_OBJ_TYPE_KW
#define SEL_OBJ_TYPE_KW
Definition: rodsKeyWdDef.h:71
querySpecColl.h
irods.pypyodbc.status
status
Definition: pypyodbc.py:467
collection.hpp
splitPathByKey
int splitPathByKey(const char *srcPath, char *dir, size_t maxDirLen, char *file, size_t maxFileLen, char key)
Definition: stringOpr.cpp:222
GenQueryOut::rowCnt
int rowCnt
Definition: rodsGenQuery.h:68
irods::log
void log(const error &)
Definition: irods_log.cpp:13
dataObjClose.h
irods::error
Definition: irods_error.hpp:23
miscServerFunct.hpp
DATA_OBJ_T
@ DATA_OBJ_T
Definition: rodsType.h:38
int
typedef int((*funcPtr)())
getAndConnRcatHost
int getAndConnRcatHost(rsComm_t *rsComm, int rcatType, const char *rcatZoneHint, rodsServerHost_t **rodsServerHost)
Definition: rodsConnect.cpp:26
SqlResult::value
char * value
Definition: rodsGenQuery.h:64
rsObjStat.hpp
COL_D_OWNER_ZONE
#define COL_D_OWNER_ZONE
Definition: rodsGenQuery.h:174
get_catalog_service_role
irods::error get_catalog_service_role(std::string &_role)
Definition: miscServerFunct.cpp:3153
rodsServerHost
Definition: rodsConnect.h:62
SqlResult
Definition: rodsGenQuery.h:61
SYS_SPEC_COLL_NOT_IN_CACHE
@ SYS_SPEC_COLL_NOT_IN_CACHE
Definition: rodsErrorTable.h:122
COL_COLL_NAME
#define COL_COLL_NAME
Definition: rodsGenQuery.h:189
resource.hpp
replSpecColl
int replSpecColl(specColl_t *inSpecColl, specColl_t **outSpecColl)
Definition: rcMisc.cpp:778
SqlResult::len
int len
Definition: rodsGenQuery.h:63
SLAVE_RCAT
#define SLAVE_RCAT
Definition: rodsDef.h:86
rodsObjStat
Definition: objStat.h:8
rsGenQuery.hpp
queueSpecCollCacheWithObjStat
int queueSpecCollCacheWithObjStat(rodsObjStat_t *rodsObjStatOut)
Definition: specColl.cpp:213
rstrcpy
char * rstrcpy(char *dest, const char *src, int maxLen)
Definition: stringOpr.cpp:51
DataObjInp::condInput
keyValPair_t condInput
Definition: dataObjInpOut.h:74
freeGenQueryOut
int freeGenQueryOut(genQueryOut_t **genQueryOut)
Definition: rcMisc.cpp:1133
NAME_LEN
#define NAME_LEN
Definition: rodsDef.h:55
irods::error::ok
bool ok()
Definition: irods_error.cpp:258
COL_DATA_SIZE
#define COL_DATA_SIZE
Definition: rodsGenQuery.h:169
clearGenQueryInp
void clearGenQueryInp(void *voidInp)
Definition: rcMisc.cpp:1118
rsGenQuery
int rsGenQuery(rsComm_t *rsComm, genQueryInp_t *genQueryInp, genQueryOut_t **genQueryOut)
Definition: rsGenQuery.cpp:604
SpecCollCache::specColl
specColl_t specColl
Definition: objInfo.h:104
SpecCollCache
Definition: objInfo.h:102
objMetaOpr.hpp
COL_D_DATA_ID
#define COL_D_DATA_ID
Definition: rodsGenQuery.h:163
COL_DATA_MODE
#define COL_DATA_MODE
Definition: rodsGenQuery.h:183