00001
00002
00003
00004
00005 #include "eirods_file_object.h"
00006 #include "eirods_resource_manager.h"
00007 #include "eirods_hierarchy_parser.h"
00008 #include "eirods_log.h"
00009 #include "eirods_stacktrace.h"
00010 #include "eirods_hierarchy_parser.h"
00011 #include "eirods_resource_backport.h"
00012
00013
00014
00015 #include "miscServerFunct.h"
00016 #include "dataObjOpr.h"
00017
00018
00019
00020 #include <boost/asio/ip/host_name.hpp>
00021
00022 namespace eirods {
00023
00024
00025 file_object::file_object() :
00026 data_object(),
00027 size_(0),
00028 repl_requested_( -1 )
00029 {
00030 memset(&cond_input_, 0, sizeof(keyValPair_t));
00031 }
00032
00033
00034
00035 file_object::file_object(
00036 const file_object& _rhs ) :
00037 data_object( _rhs ) {
00038
00039
00040 comm_ = _rhs.comm_;
00041 logical_path_ = _rhs.logical_path_;
00042 data_type_ = _rhs.data_type_;
00043 file_descriptor_= _rhs.file_descriptor_;
00044 l1_desc_idx_ = _rhs.l1_desc_idx_;
00045 size_ = _rhs.size_;
00046 repl_requested_ = _rhs.repl_requested_;
00047 replicas_ = _rhs.replicas_;
00048 in_pdmo_ = _rhs.in_pdmo_;
00049 memset(&cond_input_, 0, sizeof(keyValPair_t));
00050
00051 }
00052
00053
00054
00055 file_object::file_object(
00056 rsComm_t* _c,
00057 const std::string& _logical_path,
00058 const std::string& _fn,
00059 const std::string& _resc_hier,
00060 int _fd,
00061 int _m,
00062 int _f ) :
00063 data_object(
00064 _fn,
00065 _resc_hier,
00066 _m,
00067 _f ),
00068 comm_(_c),
00069 logical_path_(_logical_path),
00070 data_type_(""),
00071 file_descriptor_(_fd),
00072 l1_desc_idx_( -1 ),
00073 size_( -1 ),
00074 repl_requested_(-1)
00075 {
00076
00077
00078 replicas_.empty();
00079 memset(&cond_input_, 0, sizeof(keyValPair_t));
00080 }
00081
00082
00083 file_object::file_object(
00084 rsComm_t* _rsComm,
00085 const dataObjInfo_t* _dataObjInfo ) {
00086 logical_path(_dataObjInfo->objPath);
00087
00088 comm_ = _rsComm;
00089 physical_path_ = _dataObjInfo->filePath;
00090 resc_hier_ = _dataObjInfo->rescHier;
00091 flags_ = _dataObjInfo->flags;
00092 repl_requested_ = _dataObjInfo->replNum;
00093 replicas_.empty();
00094
00095 memset(&cond_input_, 0, sizeof(keyValPair_t));
00096 }
00097
00098
00099
00100 file_object::~file_object() {
00101 clearKeyVal( &cond_input_ );
00102 }
00103
00104
00105
00106 file_object& file_object::operator=(
00107 const file_object& _rhs ) {
00108
00109
00110 data_object::operator=( _rhs );
00111
00112 comm_ = _rhs.comm_;
00113 logical_path_ = _rhs.logical_path_;
00114 data_type_ = _rhs.data_type_;
00115 file_descriptor_= _rhs.file_descriptor_;
00116 l1_desc_idx_ = _rhs.l1_desc_idx_;
00117 size_ = _rhs.size_;
00118 repl_requested_ = _rhs.repl_requested_;
00119 replicas_ = _rhs.replicas_;
00120 in_pdmo_ = _rhs.in_pdmo_;
00121 replKeyVal(&_rhs.cond_input_, &cond_input_);
00122
00123 return *this;
00124
00125 }
00126
00127
00128 bool file_object::operator==(
00129 const file_object& _rhs) const
00130 {
00131 bool result = true;
00132 if(this->repl_requested() != _rhs.repl_requested() ||
00133 this->logical_path() != _rhs.logical_path()) {
00134 result = false;
00135 }
00136 return result;
00137 }
00138
00139
00140
00141 error file_object::resolve(
00142 const std::string& _interface,
00143 plugin_ptr& _ptr ) {
00144
00145
00146
00147 if( RESOURCE_INTERFACE != _interface ) {
00148 std::stringstream msg;
00149 msg << "file_object does not support a [";
00150 msg << _interface;
00151 msg << "] for plugin resolution";
00152 return ERROR( SYS_INVALID_INPUT_PARAM, msg.str() );
00153 }
00154
00155 error result = SUCCESS();
00156 error ret;
00157
00158 hierarchy_parser hparse;
00159 ret = hparse.set_string(resc_hier());
00160
00161 if(!ret.ok()) {
00162 std::stringstream msg;
00163 msg << "error parsing resource hierarchy \"" << resc_hier() << "\"";
00164 result = PASSMSG(msg.str(), ret);
00165 } else {
00166 std::string resc;
00167
00168 ret = hparse.first_resc(resc);
00169 if(!ret.ok()) {
00170 std::stringstream msg;
00171 msg << __FUNCTION__ << " - ERROR getting first resource from hierarchy.";
00172 result = PASSMSG(msg.str(), ret);
00173 } else {
00174
00175 if(resc.empty() && resc_hier().empty()) {
00176
00177
00178
00179
00180 } else if(resc.empty()) {
00181 return ERROR( EIRODS_HIERARCHY_ERROR, "Hierarchy string is not empty but first resource is!");
00182 }
00183
00184 resource_ptr resc_ptr;
00185 ret = resc_mgr.resolve( resc, resc_ptr );
00186 if(!ret.ok()) {
00187 std::stringstream msg;
00188 msg << __FUNCTION__ << " - ERROR resolving resource \"" << resc << "\"";
00189 result = PASSMSG(msg.str(), ret);
00190 }
00191
00192 _ptr = boost::dynamic_pointer_cast< resource >( resc_ptr );
00193 }
00194 }
00195
00196 return result;
00197
00198 }
00199
00200
00201
00202 error file_object::get_re_vars(
00203 keyValPair_t& _kvp ) {
00204 data_object::get_re_vars( _kvp );
00205
00206 copyKeyVal( &cond_input_, &_kvp );
00207
00208 addKeyVal( &_kvp, LOGICAL_PATH_KW, logical_path_.c_str() );
00209 addKeyVal( &_kvp, DATA_TYPE_KW, data_type_.c_str() );
00210
00211 std::stringstream fd;
00212 fd << file_descriptor_;
00213 addKeyVal( &_kvp, FILE_DESCRIPTOR_KW, fd.str().c_str() );
00214
00215 std::stringstream idx;
00216 idx << l1_desc_idx_;
00217 addKeyVal( &_kvp, L1_DESC_IDX_KW, idx.str().c_str() );
00218
00219 std::stringstream sz;
00220 sz << size_;
00221 addKeyVal( &_kvp, SIZE_KW, sz.str().c_str() );
00222
00223 std::stringstream repl;
00224 repl << repl_requested_;
00225 addKeyVal( &_kvp, REPL_REQUESTED_KW, repl.str().c_str() );
00226
00227 std::stringstream pdmo;
00228 pdmo << in_pdmo_;
00229 addKeyVal( &_kvp, IN_PDMO_KW, pdmo.str().c_str() );
00230
00231 return SUCCESS();
00232
00233 }
00234
00235
00236
00237 error file_object_factory( rsComm_t* _comm,
00238 dataObjInp_t* _data_obj_inp,
00239 file_object_ptr _file_obj ) {
00240
00241
00242 char* repl_num_ptr = getValByKey( &_data_obj_inp->condInput, REPL_NUM_KW );
00243 std::string repl_num;
00244 if( repl_num_ptr ) {
00245 repl_num = repl_num_ptr;
00246 rmKeyVal( &_data_obj_inp->condInput, REPL_NUM_KW );
00247 }
00248
00249
00250
00251 dataObjInfo_t* head_ptr = 0;
00252
00253 int status = getDataObjInfoIncSpecColl ( _comm, _data_obj_inp, &head_ptr );
00254 if( status < 0 ) {
00255 status = getDataObjInfo( _comm, _data_obj_inp, &head_ptr, 0, 0 );
00256 }
00257 if( 0 == head_ptr || status < 0 ) {
00258 if( head_ptr ) {
00259 freeAllDataObjInfo( head_ptr );
00260 }
00261
00262 char* sys_error;
00263 char* rods_error = rodsErrorName(status, &sys_error);
00264 std::stringstream msg;
00265 msg << "failed in call to getDataObjInfoIncSpecColl";
00266 msg << " for [";
00267 msg << _data_obj_inp->objPath;
00268 msg << "] ";
00269 msg << rods_error << " " << sys_error;
00270 return ERROR( status, msg.str() );
00271 }
00272
00273
00274
00275 if( !repl_num.empty() ) {
00276 addKeyVal(
00277 &_data_obj_inp->condInput,
00278 REPL_NUM_KW,
00279 repl_num.c_str() );
00280 }
00281
00282
00283
00284 _file_obj->comm( _comm );
00285 _file_obj->logical_path( _data_obj_inp->objPath );
00286 _file_obj->resc_hier( head_ptr->rescHier );
00287 _file_obj->cond_input( _data_obj_inp->condInput );
00288
00289
00290
00291 if( !repl_num.empty() ) {
00292 _file_obj->repl_requested( atoi( repl_num.c_str() ) );
00293 }
00294
00295
00296 char* in_pdmo = getValByKey(&_data_obj_inp->condInput, IN_PDMO_KW);
00297 if(in_pdmo) {
00298 _file_obj->in_pdmo(in_pdmo);
00299 }
00300
00301
00302
00303
00304 dataObjInfo_t* info_ptr = head_ptr;
00305 std::vector< physical_object > objects;
00306 while( info_ptr ) {
00307 physical_object obj;
00308
00309 obj.is_dirty( info_ptr->replStatus );
00310 obj.repl_num( info_ptr->replNum );
00311 obj.map_id( info_ptr->dataMapId );
00312 obj.size( info_ptr->dataSize );
00313 obj.id( info_ptr->dataId );
00314 obj.coll_id( info_ptr->collId );
00315 obj.name( info_ptr->objPath );
00316 obj.version( info_ptr->version );
00317 obj.type_name( info_ptr->dataType );
00318 obj.resc_group_name( info_ptr->rescGroupName );
00319 obj.resc_name( info_ptr->rescName );
00320 obj.path( info_ptr->filePath );
00321 obj.owner_name( info_ptr->dataOwnerName );
00322 obj.owner_zone( info_ptr->dataOwnerZone );
00323 obj.status( info_ptr->statusString );
00324 obj.checksum( info_ptr->chksum );
00325 obj.expiry_ts( info_ptr->dataExpiry );
00326 obj.mode( info_ptr->dataMode );
00327 obj.r_comment( info_ptr->dataComments );
00328 obj.create_ts( info_ptr->dataCreate );
00329 obj.modify_ts( info_ptr->dataModify );
00330 obj.resc_hier( info_ptr->rescHier );
00331
00332 objects.push_back( obj );
00333 info_ptr = info_ptr->next;
00334
00335 }
00336
00337 _file_obj->replicas( objects );
00338
00339
00340
00341 freeAllDataObjInfo( head_ptr );
00342 return SUCCESS();
00343
00344 }
00345
00346 };
00347
00348
00349