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)  

rsFileStageToCache.cpp
Go to the documentation of this file.
1 
3 /* rsFileStageToCache.c - server routine that handles the fileStageToCache
4  * API
5  */
6 
7 /* script generated code */
8 #include "fileStageToCache.h"
9 #include "fileOpr.hpp"
10 #include "miscServerFunct.hpp"
11 #include "dataObjOpr.hpp"
12 #include "physPath.hpp"
13 #include "rsFileStageToCache.hpp"
14 
15 // =-=-=-=-=-=-=-
16 #include "irods_log.hpp"
17 #include "irods_file_object.hpp"
19 #include "irods_stacktrace.hpp"
21 
22 int
23 rsFileStageToCache( rsComm_t *rsComm, fileStageSyncInp_t *fileStageToCacheInp ) {
25  int remoteFlag;
26  int status;
27 
28  //remoteFlag = resolveHost (&fileStageToCacheInp->addr, &rodsServerHost);
29  irods::error ret = irods::get_host_for_hier_string( fileStageToCacheInp->rescHier, remoteFlag, rodsServerHost );
30  if ( !ret.ok() ) {
31  irods::log( PASSMSG( "failed in call to irods::get_host_for_hier_string", ret ) );
32  return -1;
33  }
34 
35  if ( remoteFlag < 0 ) {
36  return remoteFlag;
37  }
38  else {
39  status = rsFileStageToCacheByHost( rsComm, fileStageToCacheInp,
41  return status;
42  }
43 }
44 
45 int
47  fileStageSyncInp_t *fileStageToCacheInp, rodsServerHost_t *rodsServerHost ) {
48  int status;
49  int remoteFlag;
50 
51  if ( rodsServerHost == NULL ) {
53  "rsFileStageToCacheByHost: Input NULL rodsServerHost" );
55  }
56 
57  remoteFlag = rodsServerHost->localFlag;
58 
59  if ( remoteFlag == LOCAL_HOST ) {
60  status = _rsFileStageToCache( rsComm, fileStageToCacheInp );
61  }
62  else if ( remoteFlag == REMOTE_HOST ) {
63  status = remoteFileStageToCache( rsComm, fileStageToCacheInp,
65  }
66  else {
67  if ( remoteFlag < 0 ) {
68  return remoteFlag;
69  }
70  else {
72  "rsFileStageToCacheByHost: resolveHost returned value %d",
73  remoteFlag );
75  }
76  }
77 
78  return status;
79 }
80 
81 int
83  fileStageSyncInp_t *fileStageToCacheInp, rodsServerHost_t *rodsServerHost ) {
84  int status;
85 
86  if ( rodsServerHost == NULL ) {
88  "remoteFileStageToCache: Invalid rodsServerHost" );
90  }
91 
92  if ( ( status = svrToSvrConnect( rsComm, rodsServerHost ) ) < 0 ) {
93  return status;
94  }
95 
96  status = rcFileStageToCache( rodsServerHost->conn, fileStageToCacheInp );
97 
98  if ( status < 0 ) {
100  "remoteFileStageToCache: rcFileStageToCache failed for %s",
101  fileStageToCacheInp->filename );
102  }
103 
104  return status;
105 }
106 
107 // =-=-=-=-=-=-=-
108 // _rsFileStageToCache - this the local version of rsFileStageToCache.
110  rsComm_t* _comm,
111  fileStageSyncInp_t* _stage_inp ) {
112 
113  // XXXX need to check resource permission and vault permission
114  // when RCAT is available
115 
116  // =-=-=-=-=-=-=-
117  // need to make this now. It will be difficult to do it with
118  // parallel I/O
119  int status = mkDirForFilePath(
120  _comm,
121  0,
122  _stage_inp->cacheFilename,
123  _stage_inp->rescHier,
124  getDefDirMode() );
125  if ( status < 0 ) {
126  rodsLog( LOG_ERROR, "mkDirForFilePath failed in _rsFileStageToCache with status %d.", status );
127  return status;
128  }
129 
130  if ( _stage_inp->objPath[0] == '\0' ) {
131  std::stringstream msg;
132  msg << __FUNCTION__;
133  msg << " - Empty logical path.";
134  irods::log( LOG_ERROR, msg.str() );
136  }
137 
138  // =-=-=-=-=-=-=-
139  // make the call to fileStageToCache via the resource plugin
140  irods::file_object_ptr file_obj(
141  new irods::file_object(
142  _comm,
143  _stage_inp->objPath,
144  _stage_inp->filename, "", 0,
145  _stage_inp->mode,
146  _stage_inp->flags ) );
147  file_obj->resc_hier( _stage_inp->rescHier );
148  file_obj->size( _stage_inp->dataSize );
149 
150  // =-=-=-=-=-=-=-
151  // pass condInput
152  file_obj->cond_input( _stage_inp->condInput );
153 
154  irods::error stage_err = fileStageToCache( _comm,
155  file_obj,
156  _stage_inp->cacheFilename );
157  // =-=-=-=-=-=-=-
158  // handle errors if any
159  if ( !stage_err.ok() ) {
160  // =-=-=-=-=-=-=-
161  // an empty dir may be there
162  if ( getErrno( stage_err.code() ) == EEXIST ) {
163 
164  // =-=-=-=-=-=-=-
165  // make the call to rmdir via the resource plugin
168  _stage_inp->cacheFilename,
169  _stage_inp->rescHier,
170  0, 0 ) );
171  coll_obj->cond_input( _stage_inp->condInput );
172  irods::error rmdir_err = fileRmdir( _comm, coll_obj );
173  if ( !rmdir_err.ok() ) {
174  std::stringstream msg;
175  msg << "fileRmdir failed for [";
176  msg << _stage_inp->cacheFilename;
177  msg << "]";
178  irods::error err = PASSMSG( msg.str(), rmdir_err );
179  irods::log( err );
180  }
181  }
182  else {
183  irods::error err = ASSERT_PASS( stage_err, "Failed for \"%s\".", _stage_inp->filename );
184  irods::log( err );
185  }
186 
187  // =-=-=-=-=-=-=-
188  // try it again? ( make the call to fileStageToCache via the resource plugin )
189  if (stage_err.code() != SYS_OPERATION_IN_PROGRESS) {
190  stage_err = fileStageToCache( _comm,
191  file_obj,
192  _stage_inp->cacheFilename );
193  }
194 
195  // =-=-=-=-=-=-=-
196  // handle errors if any
197  if ( !stage_err.ok() ) {
198  std::stringstream msg;
199  msg << "fileStageTocache for [";
200  msg << _stage_inp->filename;
201  msg << "]";
202  msg << stage_err.code();
203  irods::error err = PASSMSG( msg.str(), stage_err );
204  irods::log( err );
205  }
206 
207  } // if ! stage_err.ok
208 
209  return stage_err.code();
210 
211 } // _rsFileStageToCache
rodsLog
void rodsLog(int level, const char *formatStr,...)
Definition: rodsLog.cpp:86
fileStageSyncInp_t::mode
int mode
Definition: fileStageToCache.h:10
NULL
#define NULL
Definition: rodsDef.h:70
rsComm_t
Definition: rcConnect.h:145
getDefDirMode
int getDefDirMode()
Definition: physPath.cpp:1070
fileStageSyncInp_t::condInput
keyValPair_t condInput
Definition: fileStageToCache.h:18
SYS_INTERNAL_NULL_INPUT_ERR
@ SYS_INTERNAL_NULL_INPUT_ERR
Definition: rodsErrorTable.h:92
rodsServerHost::localFlag
int localFlag
Definition: rodsConnect.h:68
rodsServerHost::conn
rcComm_t * conn
Definition: rodsConnect.h:64
SYS_UNRECOGNIZED_REMOTE_FLAG
@ SYS_UNRECOGNIZED_REMOTE_FLAG
Definition: rodsErrorTable.h:88
irods_file_object.hpp
irods_stacktrace.hpp
fileStageSyncInp_t::rescHier
char rescHier[(1024+64)]
Definition: fileStageToCache.h:17
irods_collection_object.hpp
REMOTE_HOST
#define REMOTE_HOST
Definition: rodsConnect.h:45
irods::collection_object_ptr
boost::shared_ptr< collection_object > collection_object_ptr
Definition: irods_collection_object.hpp:85
LOCAL_HOST
#define LOCAL_HOST
Definition: rodsConnect.h:44
rsFileStageToCache.hpp
irods_resource_backport.hpp
_rsFileStageToCache
int _rsFileStageToCache(rsComm_t *_comm, fileStageSyncInp_t *_stage_inp)
Definition: rsFileStageToCache.cpp:109
PASSMSG
#define PASSMSG(message_, prev_error_)
Definition: irods_error.hpp:119
rsFileStageToCache
int rsFileStageToCache(rsComm_t *rsComm, fileStageSyncInp_t *fileStageToCacheInp)
Definition: rsFileStageToCache.cpp:23
LOG_ERROR
#define LOG_ERROR
Definition: rodsLog.h:43
fileStageToCache
irods::error fileStageToCache(rsComm_t *, irods::first_class_object_ptr, const std::string &)
Definition: fileDriver.cpp:544
SYS_INVALID_INPUT_PARAM
@ SYS_INVALID_INPUT_PARAM
Definition: rodsErrorTable.h:195
irods::error::code
long long code() const
Definition: irods_error.cpp:194
irods::get_host_for_hier_string
error get_host_for_hier_string(const std::string &, int &, rodsServerHost_t *&)
Definition: irods_resource_backport.cpp:581
fileStageSyncInp_t::filename
char filename[(1024+64)]
Definition: fileStageToCache.h:14
getErrno
int getErrno(int errCode)
Definition: rcMisc.cpp:3261
fileRmdir
irods::error fileRmdir(rsComm_t *, irods::first_class_object_ptr)
Definition: fileDriver.cpp:332
SYS_INVALID_SERVER_HOST
@ SYS_INVALID_SERVER_HOST
Definition: rodsErrorTable.h:89
ASSERT_PASS
#define ASSERT_PASS(prev_error_, format_,...)
Definition: irods_error.hpp:124
fileStageSyncInp_t::dataSize
rodsLong_t dataSize
Definition: fileStageToCache.h:12
svrToSvrConnect
int svrToSvrConnect(rsComm_t *rsComm, rodsServerHost_t *rodsServerHost)
Definition: miscServerFunct.cpp:106
irods::collection_object
Definition: irods_collection_object.hpp:14
irods.pypyodbc.status
status
Definition: pypyodbc.py:467
remoteFileStageToCache
int remoteFileStageToCache(rsComm_t *rsComm, fileStageSyncInp_t *fileStageToCacheInp, rodsServerHost_t *rodsServerHost)
Definition: rsFileStageToCache.cpp:82
physPath.hpp
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
SYS_OPERATION_IN_PROGRESS
@ SYS_OPERATION_IN_PROGRESS
Definition: rodsErrorTable.h:220
miscServerFunct.hpp
fileStageSyncInp_t::objPath
char objPath[(1024+64)]
Definition: fileStageToCache.h:16
fileStageToCache.h
irods::file_object
Definition: irods_file_object.hpp:19
fileOpr.hpp
rodsServerHost
Definition: rodsConnect.h:62
irods::file_object_ptr
boost::shared_ptr< file_object > file_object_ptr
Definition: irods_file_object.hpp:145
fileStageSyncInp_t::flags
int flags
Definition: fileStageToCache.h:11
rcFileStageToCache
int rcFileStageToCache(rcComm_t *conn, fileStageSyncInp_t *fileStageToCacheInp)
Definition: rcFileStageToCache.cpp:23
fileStageSyncInp_t
Definition: fileStageToCache.h:9
dataObjOpr.hpp
mkDirForFilePath
int mkDirForFilePath(rsComm_t *rsComm, size_t startDirLen, const std::string &filePath, const std::string &hier, int mode)
Definition: fileOpr.cpp:120
irods::error::ok
bool ok()
Definition: irods_error.cpp:258
fileStageSyncInp_t::cacheFilename
char cacheFilename[(1024+64)]
Definition: fileStageToCache.h:15
irods_log.hpp
rsFileStageToCacheByHost
int rsFileStageToCacheByHost(rsComm_t *rsComm, fileStageSyncInp_t *fileStageToCacheInp, rodsServerHost_t *rodsServerHost)
Definition: rsFileStageToCache.cpp:46