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)  

rsStructFileExtract.cpp
Go to the documentation of this file.
1 
3 #include "structFileExtract.h"
4 #include "miscServerFunct.hpp"
5 #include "syncMountedColl.h"
7 
8 #include "dataObjOpr.hpp"
9 #include "rsGlobalExtern.hpp"
10 #include "objMetaOpr.hpp"
11 #include "resource.hpp"
12 #include "physPath.hpp"
13 
14 // =-=-=-=-=-=-=-
18 #include "irods_stacktrace.hpp"
19 
20 int
21 rsStructFileExtract( rsComm_t *rsComm, structFileOprInp_t *structFileOprInp ) {
22  //rodsServerHost_t *rodsServerHost;
23  //int remoteFlag;
24  int status;
25 
26  //remoteFlag = resolveHost (&structFileOprInp->addr, &rodsServerHost);
27  dataObjInp_t dataObjInp;
28  bzero( &dataObjInp, sizeof( dataObjInp ) );
29  rstrcpy( dataObjInp.objPath, structFileOprInp->specColl->objPath, MAX_NAME_LEN );
30 
31  // =-=-=-=-=-=-=-
32  // working on the "home zone", determine if we need to redirect to a different
33  // server in this zone for this operation. if there is a RESC_HIER_STR_KW then
34  // we know that the redirection decision has already been made
35  std::string hier;
36  int local = LOCAL_HOST;
38  if ( getValByKey( &structFileOprInp->condInput, RESC_HIER_STR_KW ) == NULL ) {
40  &dataObjInp, hier, host, local );
41  if ( !ret.ok() ) {
42  std::stringstream msg;
43  msg << "failed in irods::resource_redirect for [";
44  msg << dataObjInp.objPath << "]";
45  irods::log( PASSMSG( msg.str(), ret ) );
46  return ret.code();
47  }
48 
49  // =-=-=-=-=-=-=-
50  // we resolved the redirect and have a host, set the hier str for subsequent
51  // api calls, etc.
52  addKeyVal( &structFileOprInp->condInput, RESC_HIER_STR_KW, hier.c_str() );
53 
54  } // if keyword
55 
56 
57  if ( local == LOCAL_HOST ) {
58  status = _rsStructFileExtract( rsComm, structFileOprInp );
59  }
60  else if ( local == REMOTE_HOST ) {
61  //status = remoteStructFileExtract (rsComm, structFileOprInp, rodsServerHost);
62  status = rcStructFileExtract( host->conn, structFileOprInp );
63  }
64  else {
65  if ( local < 0 ) {
66  return local;
67  }
68  else {
70  "rsStructFileExtract: resolveHost returned unrecognized value %d",
71  local );
73  }
74  }
75 
76  return status;
77 }
78 
79 int
81  structFileOprInp_t *structFileOprInp, rodsServerHost_t *rodsServerHost ) {
82  int status;
83 
84  if ( rodsServerHost == NULL ) {
86  "remoteStructFileExtract: Invalid rodsServerHost" );
88  }
89 
90  if ( ( status = svrToSvrConnect( rsComm, rodsServerHost ) ) < 0 ) {
91  return status;
92  }
93 
94  status = rcStructFileExtract( rodsServerHost->conn, structFileOprInp );
95 
96  if ( status < 0 ) {
98  "remoteStructFileExtract: rcStructFileExtract failed for %s, status = %d",
99  structFileOprInp->specColl->collection, status );
100  }
101 
102  return status;
103 }
104 
105 // =-=-=-=-=-=-=-
106 // implemenation for local rs call for extraction
108  structFileOprInp_t* _struct_inp ) {
109  // =-=-=-=-=-=-=-
110  // pointer check
111  if ( _comm == NULL ||
112  _struct_inp == NULL ||
113  _struct_inp->specColl == NULL ) {
114  rodsLog( LOG_ERROR, "_rsStructFileExtract: NULL input" );
116  }
117 
118  // =-=-=-=-=-=-=-
119  // create dir into which to extract
120  int status = procCacheDir( _comm,
121  _struct_inp->specColl->cacheDir,
122  _struct_inp->specColl->resource,
123  _struct_inp->oprType,
124  _struct_inp->specColl->rescHier ); // JMC - backport 4657
125  if ( status < 0 ) {
126  rodsLog( LOG_ERROR, "_rsStructFileExtract - failed in call to procCacheDir status = %d", status );
127  return status;
128  }
129 
130  // =-=-=-=-=-=-=-
131  // create a structured fco and resolve a resource plugin
132  // to handle the extract process
133  irods::structured_object_ptr struct_obj(
135  ) );
136  struct_obj->spec_coll( _struct_inp->specColl );
137  struct_obj->addr( _struct_inp->addr );
138  struct_obj->flags( _struct_inp->flags );
139  struct_obj->comm( _comm );
140  struct_obj->opr_type( _struct_inp->oprType );
141  struct_obj->spec_coll_type( _struct_inp->specColl->type );
142 
143  // =-=-=-=-=-=-=-
144  // extract the data type
145  char* data_type = getValByKey( &_struct_inp->condInput, DATA_TYPE_KW );
146  if ( data_type ) {
147  struct_obj->data_type( data_type );
148  }
149 
150  // =-=-=-=-=-=-=-
151  // retrieve the resource name given the object
152  irods::plugin_ptr ptr;
153  irods::error ret_err = struct_obj->resolve( irods::RESOURCE_INTERFACE, ptr );
154  if ( !ret_err.ok() ) {
155  irods::error err = PASSMSG( "failed to resolve resource", ret_err );
156  irods::log( err );
157  return ret_err.code();
158  }
159 
160  irods::resource_ptr resc = boost::dynamic_pointer_cast< irods::resource >( ptr );
161 
162  // =-=-=-=-=-=-=-
163  // make the call to the "extract" interface
164  ret_err = resc->call( _comm, "extract", struct_obj );
165 
166  // =-=-=-=-=-=-=-
167  // pass along an error from the interface or return SUCCESS
168  if ( !ret_err.ok() ) {
169  irods::error err = PASSMSG( "failed to call 'extract'", ret_err );
170  irods::log( err );
171  return ret_err.code();
172  }
173  else {
174  return ret_err.code();
175  }
176 
177 } // _rsStructFileExtract
178 
179 int
180 procCacheDir( rsComm_t *rsComm, char *cacheDir, char *resource, int oprType, char* hier ) {
181  if ( ( oprType & PRESERVE_DIR_CONT ) == 0 ) {
182  int status = chkEmptyDir( rsComm, cacheDir, hier );
184  rodsLog( LOG_ERROR, "procCacheDir: chkEmptyDir error for %s in resc %s, status = %d",
185  cacheDir, resource, status );
186  return status;
187  }
188 
189  }
190 
191  int status = mkFileDirR( rsComm, 0, cacheDir, hier, getDefDirMode() );
192  if ( status < 0 ) {
193  rodsLog( LOG_ERROR, "mkFileDirR failed in procCacheDir with status %d", status );
194  }
195  return status;
196 }
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
rsStructFileExtract.hpp
irods::plugin_ptr
boost::shared_ptr< plugin_base > plugin_ptr
Definition: irods_first_class_object.hpp:18
_rsStructFileExtract
int _rsStructFileExtract(rsComm_t *_comm, structFileOprInp_t *_struct_inp)
Definition: rsStructFileExtract.cpp:107
NULL
#define NULL
Definition: rodsDef.h:70
rsComm_t
Definition: rcConnect.h:145
getDefDirMode
int getDefDirMode()
Definition: physPath.cpp:1070
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
rodsServerHost::conn
rcComm_t * conn
Definition: rodsConnect.h:64
rcStructFileExtract
int rcStructFileExtract(rcComm_t *conn, structFileOprInp_t *structFileOprInp)
Definition: rcStructFileExtract.cpp:23
procCacheDir
int procCacheDir(rsComm_t *rsComm, char *cacheDir, char *resource, int oprType, char *hier)
Definition: rsStructFileExtract.cpp:180
SpecColl::resource
char resource[64]
Definition: objInfo.h:83
SYS_UNRECOGNIZED_REMOTE_FLAG
@ SYS_UNRECOGNIZED_REMOTE_FLAG
Definition: rodsErrorTable.h:88
irods_stacktrace.hpp
rsStructFileExtract
int rsStructFileExtract(rsComm_t *rsComm, structFileOprInp_t *structFileOprInp)
Definition: rsStructFileExtract.cpp:21
irods::resource_ptr
boost::shared_ptr< resource > resource_ptr
Definition: irods_resource_types.hpp:11
REMOTE_HOST
#define REMOTE_HOST
Definition: rodsConnect.h:45
PRESERVE_DIR_CONT
#define PRESERVE_DIR_CONT
Definition: syncMountedColl.h:15
SpecColl::cacheDir
char cacheDir[(1024+64)]
Definition: objInfo.h:89
SpecColl::type
structFileType_t type
Definition: objInfo.h:78
LOCAL_HOST
#define LOCAL_HOST
Definition: rodsConnect.h:44
irods_resource_backport.hpp
irods::resource_redirect
error resource_redirect(const std::string &, rsComm_t *, dataObjInp_t *, std::string &, rodsServerHost_t *&, int &, dataObjInfo_t **_data_obj_info=0)
Definition: irods_resource_redirect.cpp:786
PASSMSG
#define PASSMSG(message_, prev_error_)
Definition: irods_error.hpp:119
structFileExtract.h
LOG_ERROR
#define LOG_ERROR
Definition: rodsLog.h:43
irods_resource_redirect.hpp
DATA_TYPE_KW
#define DATA_TYPE_KW
Definition: rodsKeyWdDef.h:23
chkEmptyDir
int chkEmptyDir(rsComm_t *rsComm, const std::string &cacheDir, const std::string &hier)
Definition: fileOpr.cpp:263
rsGlobalExtern.hpp
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
syncMountedColl.h
irods::RESOURCE_INTERFACE
const std::string RESOURCE_INTERFACE("irods_resource_interface")
StructFileOprInp::oprType
int oprType
Definition: structFileSync.h:10
remoteStructFileExtract
int remoteStructFileExtract(rsComm_t *rsComm, structFileOprInp_t *structFileOprInp, rodsServerHost_t *rodsServerHost)
Definition: rsStructFileExtract.cpp:80
DataObjInp
Definition: dataObjInpOut.h:65
irods::structured_object
Definition: irods_structured_object.hpp:15
MAX_NAME_LEN
#define MAX_NAME_LEN
Definition: rodsDef.h:61
SYS_INVALID_SERVER_HOST
@ SYS_INVALID_SERVER_HOST
Definition: rodsErrorTable.h:89
svrToSvrConnect
int svrToSvrConnect(rsComm_t *rsComm, rodsServerHost_t *rodsServerHost)
Definition: miscServerFunct.cpp:106
irods.pypyodbc.status
status
Definition: pypyodbc.py:467
SpecColl::rescHier
char rescHier[(1024+64)]
Definition: objInfo.h:84
physPath.hpp
irods::log
void log(const error &)
Definition: irods_log.cpp:13
irods::structured_object_ptr
boost::shared_ptr< structured_object > structured_object_ptr
Definition: irods_structured_object.hpp:107
LOG_NOTICE
#define LOG_NOTICE
Definition: rodsLog.h:33
irods::error
Definition: irods_error.hpp:23
miscServerFunct.hpp
mkFileDirR
int mkFileDirR(rsComm_t *rsComm, size_t startDirLen, const std::string &destDir, const std::string &hier, int mode)
Definition: fileOpr.cpp:147
StructFileOprInp::flags
int flags
Definition: structFileSync.h:11
SpecColl::collection
char collection[(1024+64)]
Definition: objInfo.h:79
StructFileOprInp
Definition: structFileSync.h:8
rodsServerHost
Definition: rodsConnect.h:62
SYS_DIR_IN_VAULT_NOT_EMPTY
@ SYS_DIR_IN_VAULT_NOT_EMPTY
Definition: rodsErrorTable.h:149
generate_iadmin_commands_for_41_to_42_upgrade.host
host
Definition: generate_iadmin_commands_for_41_to_42_upgrade.py:23
resource.hpp
StructFileOprInp::condInput
keyValPair_t condInput
Definition: structFileSync.h:13
StructFileOprInp::addr
rodsHostAddr_t addr
Definition: structFileSync.h:9
rstrcpy
char * rstrcpy(char *dest, const char *src, int maxLen)
Definition: stringOpr.cpp:51
irods_structured_object.hpp
dataObjOpr.hpp
irods::error::ok
bool ok()
Definition: irods_error.cpp:258
SpecColl::objPath
char objPath[(1024+64)]
Definition: objInfo.h:80
objMetaOpr.hpp
StructFileOprInp::specColl
specColl_t * specColl
Definition: structFileSync.h:12