00001
00002
00003
00004
00005 #include "eirods_resource_manager.h"
00006 #include "eirods_log.h"
00007 #include "eirods_string_tokenize.h"
00008 #include "eirods_stacktrace.h"
00009
00010
00011
00012 #include "getRescQuota.h"
00013 #include "eirods_children_parser.h"
00014 #include "rsGlobalExtern.h"
00015 #include "generalAdmin.h"
00016 #include "phyBundleColl.h"
00017 #include "miscServerFunct.h"
00018
00019
00020
00021 #include <iostream>
00022
00023
00024 eirods::resource_manager resc_mgr;
00025
00026 namespace eirods {
00027
00028
00029
00030 resource_manager::resource_manager() {
00031 }
00032
00033
00034
00035 resource_manager::resource_manager( const resource_manager& _rhs ) {
00036 }
00037
00038
00039
00040 resource_manager::~resource_manager( ) {
00041 }
00042
00043
00044
00045 error resource_manager::resolve( std::string _key, resource_ptr& _value ) {
00046
00047 if( _key.empty() ) {
00048 return ERROR( SYS_INVALID_INPUT_PARAM, "empty key" );
00049 }
00050
00051 if( resources_.has_entry( _key ) ) {
00052 _value = resources_[ _key ];
00053 return SUCCESS();
00054
00055 } else {
00056 std::stringstream msg;
00057 msg << "no resource found for name ["
00058 << _key << "]";
00059 return ERROR( SYS_INVALID_INPUT_PARAM, msg.str() );
00060
00061 }
00062
00063 }
00064
00065
00066
00067 error resource_manager::validate_vault_path(
00068 std::string _physical_path,
00069 rodsServerHost_t* _svr_host,
00070 std::string& _out_path ) {
00071
00072
00073 bool found = false;
00074
00075
00076
00077 if( resources_.empty() ) {
00078 return ERROR( SYS_INVALID_INPUT_PARAM, "empty resource table" );
00079 }
00080
00081
00082
00083 if( _physical_path.empty() ) {
00084 return ERROR( SYS_INVALID_INPUT_PARAM, "empty property" );
00085 }
00086
00087
00088
00089 lookup_table< resource_ptr >::iterator itr = resources_.begin();
00090 for( ; !found && itr != resources_.end(); ++itr ) {
00091
00092
00093 rodsServerHost_t* svr_host = 0;
00094 error ret = itr->second->get_property< rodsServerHost_t* >( RESOURCE_HOST, svr_host );
00095 if( !ret.ok() ) {
00096 PASS( ret );
00097 }
00098
00099
00100
00101
00102 if( svr_host != _svr_host ) {
00103 continue;
00104 }
00105
00106
00107
00108 std::string path;
00109 ret = itr->second->get_property<std::string>( RESOURCE_PATH, path );
00110
00111
00112
00113 if( ret.ok()) {
00114
00115
00116
00117 if( !path.empty() && (_physical_path.find( path ) != std::string::npos )) {
00118 found = true;
00119 _out_path = path;
00120 }
00121
00122 } else {
00123 std::stringstream msg;
00124 msg << "resource_manager::resolve_from_physical_path - ";
00125 msg << "failed to get vault parameter from resource";
00126 msg << ret.code();
00127 eirods::log( PASSMSG( msg.str(), ret ) );
00128
00129 }
00130
00131 }
00132
00133
00134
00135 if( true == found ) {
00136 return SUCCESS();
00137 } else {
00138 std::stringstream msg;
00139 msg << "failed to find resource for path [";
00140 msg << _physical_path;
00141 msg << "]";
00142 return ERROR( SYS_INVALID_INPUT_PARAM, msg.str() );
00143 }
00144
00145 }
00146
00147
00148
00149
00150 error resource_manager::init_from_catalog( rsComm_t* _comm ) {
00151
00152
00153 resources_.clear();
00154
00155
00156
00157 genQueryInp_t genQueryInp;
00158 genQueryOut_t* genQueryOut = NULL;
00159
00160 error proc_ret;
00161
00162 memset (&genQueryInp, 0, sizeof (genQueryInp));
00163
00164 addInxIval( &genQueryInp.selectInp, COL_R_RESC_ID, 1 );
00165 addInxIval( &genQueryInp.selectInp, COL_R_RESC_NAME, 1 );
00166 addInxIval( &genQueryInp.selectInp, COL_R_ZONE_NAME, 1 );
00167 addInxIval( &genQueryInp.selectInp, COL_R_TYPE_NAME, 1 );
00168 addInxIval( &genQueryInp.selectInp, COL_R_CLASS_NAME, 1 );
00169 addInxIval( &genQueryInp.selectInp, COL_R_LOC, 1 );
00170 addInxIval( &genQueryInp.selectInp, COL_R_VAULT_PATH, 1 );
00171 addInxIval( &genQueryInp.selectInp, COL_R_FREE_SPACE, 1 );
00172 addInxIval( &genQueryInp.selectInp, COL_R_RESC_INFO, 1 );
00173 addInxIval( &genQueryInp.selectInp, COL_R_RESC_COMMENT, 1 );
00174 addInxIval( &genQueryInp.selectInp, COL_R_CREATE_TIME, 1 );
00175 addInxIval( &genQueryInp.selectInp, COL_R_MODIFY_TIME, 1 );
00176 addInxIval( &genQueryInp.selectInp, COL_R_RESC_STATUS, 1 );
00177 addInxIval( &genQueryInp.selectInp, COL_R_RESC_CHILDREN, 1 );
00178 addInxIval( &genQueryInp.selectInp, COL_R_RESC_CONTEXT, 1 );
00179 addInxIval( &genQueryInp.selectInp, COL_R_RESC_PARENT, 1 );
00180 addInxIval( &genQueryInp.selectInp, COL_R_RESC_OBJCOUNT, 1 );
00181
00182 genQueryInp.maxRows = MAX_SQL_ROWS;
00183
00184
00185
00186 int continueInx = 1;
00187
00188
00189
00190 while( continueInx > 0 ) {
00191
00192
00193
00194 int status = rsGenQuery( _comm, &genQueryInp, &genQueryOut );
00195
00196
00197
00198 if( status < 0 ) {
00199 if( status != CAT_NO_ROWS_FOUND ) {
00200 rodsLog( LOG_NOTICE,"initResc: rsGenQuery error, status = %d",
00201 status );
00202 }
00203
00204 clearGenQueryInp( &genQueryInp );
00205 return ERROR( status, "genqery failed." );
00206
00207 }
00208
00209
00210
00211 proc_ret = process_init_results( genQueryOut );
00212
00213
00214
00215 if( !proc_ret.ok() ) {
00216 eirods::error log_err = PASSMSG( "init_from_catalog - process_init_results failed", proc_ret );
00217 eirods::log( log_err );
00218 freeGenQueryOut (&genQueryOut);
00219 break;
00220 } else {
00221 if( genQueryOut != NULL ) {
00222 continueInx = genQueryInp.continueInx = genQueryOut->continueInx;
00223 freeGenQueryOut( &genQueryOut );
00224 } else {
00225 continueInx = 0;
00226 }
00227
00228 }
00229
00230 }
00231
00232 clearGenQueryInp( &genQueryInp );
00233
00234
00235
00236 if( !proc_ret.ok() ) {
00237 return PASSMSG( "process_init_results failed.", proc_ret );
00238 }
00239
00240
00241
00242 proc_ret = init_child_map();
00243 if(!proc_ret.ok()) {
00244 return PASSMSG( "init_child_map failed.", proc_ret);
00245 }
00246
00247
00248
00249 error op_ret = gather_operations();
00250 if( !op_ret.ok() ) {
00251 return PASSMSG( "gather_operations failed.", op_ret);
00252 }
00253
00254
00255
00256 error spec_ret = init_local_file_system_resource();
00257 if( !spec_ret.ok() ) {
00258 return PASSMSG( "init_local_file_system_resource failed.", op_ret);
00259 }
00260
00261
00262
00263 error start_err = start_resource_plugins();
00264 if( !start_err.ok() ) {
00265 return PASSMSG( "start_resource_plugins failed.", start_err );
00266 }
00267
00268
00269
00270 return SUCCESS();
00271
00272 }
00273
00274
00275
00276 error resource_manager::shut_down_resources( ) {
00277
00278
00279 lookup_table< boost::shared_ptr< resource > >::iterator itr;
00280 for( itr = resources_.begin();
00281 itr != resources_.end();
00282 ++itr ) {
00283 itr->second->stop_operation();
00284
00285 }
00286
00287 return SUCCESS();
00288
00289 }
00290
00291
00292
00293 error resource_manager::process_init_results( genQueryOut_t* _result ) {
00294
00295
00296 if ( !_result ) {
00297 return ERROR( SYS_INVALID_INPUT_PARAM, "_result parameter is null" );
00298 }
00299
00300
00301
00302 sqlResult_t *rescId = 0, *rescName = 0, *zoneName = 0, *rescType = 0, *rescClass = 0;
00303 sqlResult_t *rescLoc = 0, *rescVaultPath = 0, *freeSpace = 0, *rescInfo = 0;
00304 sqlResult_t *rescComments = 0, *rescCreate = 0, *rescModify = 0, *rescStatus = 0;
00305 sqlResult_t *rescChildren = 0, *rescContext = 0, *rescParent = 0, *rescObjCount = 0;
00306
00307
00308
00309 if( ( rescId = getSqlResultByInx( _result, COL_R_RESC_ID ) ) == NULL ) {
00310 return ERROR( UNMATCHED_KEY_OR_INDEX,"getSqlResultByInx for COL_R_RESC_ID failed" );
00311 }
00312
00313 if( ( rescName = getSqlResultByInx( _result, COL_R_RESC_NAME ) ) == NULL ) {
00314 return ERROR( UNMATCHED_KEY_OR_INDEX, "getSqlResultByInx for COL_R_RESC_NAME failed" );
00315 }
00316
00317 if( ( zoneName = getSqlResultByInx( _result, COL_R_ZONE_NAME ) ) == NULL ) {
00318 return ERROR( UNMATCHED_KEY_OR_INDEX, "getSqlResultByInx for COL_R_ZONE_NAME failed" );
00319 }
00320
00321 if( ( rescType = getSqlResultByInx(_result, COL_R_TYPE_NAME ) ) == NULL ) {
00322 return ERROR( UNMATCHED_KEY_OR_INDEX, "getSqlResultByInx for COL_R_TYPE_NAME failed" );
00323 }
00324
00325 if( ( rescClass = getSqlResultByInx( _result, COL_R_CLASS_NAME ) ) == NULL ) {
00326 return ERROR( UNMATCHED_KEY_OR_INDEX, "getSqlResultByInx for COL_R_CLASS_NAME failed" );
00327 }
00328
00329 if( ( rescLoc = getSqlResultByInx( _result, COL_R_LOC ) ) == NULL ) {
00330 return ERROR( UNMATCHED_KEY_OR_INDEX, "getSqlResultByInx for COL_R_LOC failed" );
00331 }
00332
00333 if( ( rescVaultPath = getSqlResultByInx( _result, COL_R_VAULT_PATH ) ) == NULL ) {
00334 return ERROR( UNMATCHED_KEY_OR_INDEX, "getSqlResultByInx for COL_R_VAULT_PATH failed" );
00335 }
00336
00337 if( ( freeSpace = getSqlResultByInx( _result, COL_R_FREE_SPACE ) ) == NULL ) {
00338 return ERROR( UNMATCHED_KEY_OR_INDEX, "getSqlResultByInx for COL_R_FREE_SPACE failed" );
00339 }
00340
00341 if( ( rescInfo = getSqlResultByInx( _result, COL_R_RESC_INFO ) ) == NULL ) {
00342 return ERROR( UNMATCHED_KEY_OR_INDEX, "getSqlResultByInx for COL_R_RESC_INFO failed" );
00343 }
00344
00345 if( ( rescComments = getSqlResultByInx( _result, COL_R_RESC_COMMENT ) ) == NULL ) {
00346 return ERROR( UNMATCHED_KEY_OR_INDEX, "getSqlResultByInx for COL_R_RESC_COMMENT failed" );
00347 }
00348
00349 if( ( rescCreate = getSqlResultByInx( _result, COL_R_CREATE_TIME ) ) == NULL) {
00350 return ERROR( UNMATCHED_KEY_OR_INDEX, "getSqlResultByInx for COL_R_CREATE_TIME failed" );
00351 }
00352
00353 if( ( rescModify = getSqlResultByInx( _result, COL_R_MODIFY_TIME ) ) == NULL) {
00354 return ERROR( UNMATCHED_KEY_OR_INDEX, "getSqlResultByInx for COL_R_MODIFY_TIME failed" );
00355 }
00356
00357 if( ( rescStatus = getSqlResultByInx( _result, COL_R_RESC_STATUS ) ) == NULL) {
00358 return ERROR( UNMATCHED_KEY_OR_INDEX, "getSqlResultByInx for COL_R_RESC_STATUS failed" );
00359 }
00360
00361 if( ( rescChildren = getSqlResultByInx( _result, COL_R_RESC_CHILDREN ) ) == NULL) {
00362 return ERROR( UNMATCHED_KEY_OR_INDEX, "getSqlResultByInx for COL_R_RESC_CHILDREN failed" );
00363 }
00364
00365 if( ( rescContext = getSqlResultByInx( _result, COL_R_RESC_CONTEXT ) ) == NULL) {
00366 return ERROR( UNMATCHED_KEY_OR_INDEX, "getSqlResultByInx for COL_R_RESC_CONTEXT failed" );
00367 }
00368
00369 if( ( rescParent = getSqlResultByInx( _result, COL_R_RESC_PARENT ) ) == NULL) {
00370 return ERROR( UNMATCHED_KEY_OR_INDEX, "getSqlResultByInx for COL_R_RESC_PARENT failed" );
00371 }
00372
00373 if( ( rescObjCount = getSqlResultByInx( _result, COL_R_RESC_OBJCOUNT ) ) == NULL) {
00374 return ERROR( UNMATCHED_KEY_OR_INDEX, "getSqlResultByInx for COL_R_RESC_OBJCOUNT failed" );
00375 }
00376
00377
00378
00379 for( int i = 0; i < _result->rowCnt; ++i ) {
00380
00381
00382 std::string tmpRescId = &rescId->value[ rescId->len * i ];
00383 std::string tmpRescLoc = &rescLoc->value[ rescLoc->len * i ];
00384 std::string tmpRescName = &rescName->value[ rescName->len * i ];
00385 std::string tmpZoneName = &zoneName->value[ zoneName->len * i ];
00386 std::string tmpRescType = &rescType->value[ rescType->len * i ];
00387 std::string tmpRescInfo = &rescInfo->value[ rescInfo->len * i ];
00388 std::string tmpFreeSpace = &freeSpace->value[ freeSpace->len * i ];
00389 std::string tmpRescClass = &rescClass->value[ rescClass->len * i ];
00390 std::string tmpRescCreate = &rescCreate->value[ rescCreate->len * i ];
00391 std::string tmpRescModify = &rescModify->value[ rescModify->len * i ];
00392 std::string tmpRescStatus = &rescStatus->value[ rescStatus->len * i ];
00393 std::string tmpRescComments = &rescComments->value[ rescComments->len * i ];
00394 std::string tmpRescVaultPath = &rescVaultPath->value[ rescVaultPath->len * i ];
00395 std::string tmpRescChildren = &rescChildren->value[ rescChildren->len * i ];
00396 std::string tmpRescContext = &rescContext->value[ rescContext->len * i ];
00397 std::string tmpRescParent = &rescParent->value[ rescParent->len * i ];
00398 std::string tmpRescObjCount = &rescObjCount->value[ rescObjCount->len * i ];
00399
00400
00401
00402 resource_ptr resc;
00403 error ret = load_resource_plugin( resc, tmpRescType, tmpRescName, tmpRescContext );
00404 if( !ret.ok() ) {
00405 return PASSMSG( "Failed to load Resource Plugin", ret );
00406 }
00407
00408
00409
00410 if( tmpRescLoc != eirods::EMPTY_RESC_HOST ) {
00411 rodsHostAddr_t addr;
00412 rstrcpy( addr.hostAddr, const_cast<char*>( tmpRescLoc.c_str() ), LONG_NAME_LEN );
00413 rstrcpy( addr.zoneName, const_cast<char*>( tmpZoneName.c_str() ), NAME_LEN );
00414
00415 rodsServerHost_t* tmpRodsServerHost = 0;
00416 if( resolveHost( &addr, &tmpRodsServerHost ) < 0 ) {
00417 rodsLog( LOG_NOTICE, "procAndQueRescResult: resolveHost error for %s",
00418 addr.hostAddr );
00419 }
00420
00421 resc->set_property< rodsServerHost_t* >( RESOURCE_HOST, tmpRodsServerHost );
00422
00423 } else {
00424 resc->set_property< rodsServerHost_t* >( RESOURCE_HOST, 0 );
00425 }
00426
00427 resc->set_property<long>( RESOURCE_ID, strtoll( tmpRescId.c_str(), 0, 0 ) );
00428 resc->set_property<long>( RESOURCE_FREESPACE, strtoll( tmpFreeSpace.c_str(), 0, 0 ) );
00429 resc->set_property<long>( RESOURCE_QUOTA, RESC_QUOTA_UNINIT );
00430
00431 resc->set_property<std::string>( RESOURCE_ZONE, tmpZoneName );
00432 resc->set_property<std::string>( RESOURCE_NAME, tmpRescName );
00433 resc->set_property<std::string>( RESOURCE_LOCATION, tmpRescLoc );
00434 resc->set_property<std::string>( RESOURCE_TYPE, tmpRescType );
00435 resc->set_property<std::string>( RESOURCE_CLASS, tmpRescClass );
00436 resc->set_property<std::string>( RESOURCE_PATH, tmpRescVaultPath );
00437 resc->set_property<std::string>( RESOURCE_INFO, tmpRescInfo );
00438 resc->set_property<std::string>( RESOURCE_COMMENTS, tmpRescComments );
00439 resc->set_property<std::string>( RESOURCE_CREATE_TS, tmpRescCreate );
00440 resc->set_property<std::string>( RESOURCE_MODIFY_TS, tmpRescModify );
00441 resc->set_property<std::string>( RESOURCE_CHILDREN, tmpRescChildren );
00442 resc->set_property<std::string>( RESOURCE_PARENT, tmpRescParent );
00443 resc->set_property<std::string>( RESOURCE_CONTEXT, tmpRescContext );
00444
00445 if( tmpRescStatus == std::string( RESC_DOWN ) ) {
00446 resc->set_property<int>( RESOURCE_STATUS, INT_RESC_STATUS_DOWN );
00447 } else {
00448 resc->set_property<int>( RESOURCE_STATUS, INT_RESC_STATUS_UP );
00449 }
00450
00451
00452
00453 resources_[ tmpRescName ] = resc;
00454
00455 }
00456
00457
00458 return SUCCESS();
00459
00460 }
00461
00462
00463
00464 error resource_manager::init_from_type( std::string _type,
00465 std::string _key,
00466 std::string _inst,
00467 std::string _ctx,
00468 resource_ptr& _resc ) {
00469
00470
00471 error ret = load_resource_plugin( _resc, _type, _inst, _ctx );
00472 if( !ret.ok() ) {
00473 return PASSMSG( "Failed to load Resource Plugin", ret );
00474 }
00475
00476 resources_[ _key ] = _resc;
00477
00478 return SUCCESS();
00479
00480 }
00481
00482
00483
00484
00485 error resource_manager::init_local_file_system_resource(void) {
00486
00487
00488 resource_ptr resc;
00489 error err = init_from_type( EIRODS_LOCAL_USE_ONLY_RESOURCE_TYPE,
00490 EIRODS_LOCAL_USE_ONLY_RESOURCE,
00491 EIRODS_LOCAL_USE_ONLY_RESOURCE,
00492 "",
00493 resc );
00494
00495
00496 if( !err.ok() ) {
00497 std::stringstream msg;
00498 msg << "resource_manager::init_local_file_system_resource - failed to create resource";
00499 return PASSMSG( msg.str(), err );
00500 }
00501
00502
00503
00504 zoneInfo_t* zone_info = 0;
00505 getLocalZoneInfo( &zone_info );
00506
00507
00508
00509 char host_name[ MAX_NAME_LEN ];
00510 gethostname( host_name, MAX_NAME_LEN );
00511
00512 rodsHostAddr_t addr;
00513 rstrcpy( addr.hostAddr, host_name, LONG_NAME_LEN );
00514 rstrcpy( addr.zoneName, const_cast<char*>( zone_info->zoneName ), NAME_LEN );
00515
00516 rodsServerHost_t* tmpRodsServerHost = 0;
00517 if( resolveHost( &addr, &tmpRodsServerHost ) < 0 ) {
00518 rodsLog( LOG_NOTICE, "procAndQueRescResult: resolveHost error for %s",
00519 addr.hostAddr );
00520 }
00521
00522 resc->set_property< rodsServerHost_t* >( RESOURCE_HOST, tmpRodsServerHost );
00523
00524
00525
00526 resc->set_property<long>( RESOURCE_ID, 999 );
00527 resc->set_property<long>( RESOURCE_FREESPACE, 999 );
00528 resc->set_property<long>( RESOURCE_QUOTA, RESC_QUOTA_UNINIT );
00529
00530 resc->set_property<std::string>( RESOURCE_ZONE, zone_info->zoneName );
00531 resc->set_property<std::string>( RESOURCE_NAME, EIRODS_LOCAL_USE_ONLY_RESOURCE );
00532 resc->set_property<std::string>( RESOURCE_LOCATION, "localhost" );
00533 resc->set_property<std::string>( RESOURCE_TYPE, EIRODS_LOCAL_USE_ONLY_RESOURCE_TYPE );
00534 resc->set_property<std::string>( RESOURCE_CLASS, "cache" );
00535 resc->set_property<std::string>( RESOURCE_PATH, EIRODS_LOCAL_USE_ONLY_RESOURCE_VAULT );
00536 resc->set_property<std::string>( RESOURCE_INFO, "info" );
00537 resc->set_property<std::string>( RESOURCE_COMMENTS, "comments" );
00538 resc->set_property<std::string>( RESOURCE_CREATE_TS, "999" );
00539 resc->set_property<std::string>( RESOURCE_MODIFY_TS, "999" );
00540 resc->set_property<std::string>( RESOURCE_CHILDREN, "" );
00541 resc->set_property<std::string>( RESOURCE_PARENT, "" );
00542 resc->set_property<std::string>( RESOURCE_CONTEXT, "" );
00543 resc->set_property<int>( RESOURCE_STATUS, INT_RESC_STATUS_UP );
00544
00545
00546
00547 resources_[ EIRODS_LOCAL_USE_ONLY_RESOURCE ] = resc;
00548
00549 return SUCCESS();
00550
00551 }
00552
00553
00554
00555 error resource_manager::init_child_map(void) {
00556 error result = SUCCESS();
00557
00558
00559 lookup_table< boost::shared_ptr< resource > >::iterator it;
00560 for(it = resources_.begin(); it != resources_.end(); ++it) {
00561 resource_ptr resc = it->second;
00562
00563
00564 std::string children_string;
00565 error ret = resc->get_property<std::string>( RESOURCE_CHILDREN, children_string);
00566 if(!ret.ok()) {
00567 result = PASSMSG( "init_child_map failed.", ret);
00568 } else {
00569 std::string resc_name;
00570 error ret = resc->get_property<std::string>( RESOURCE_NAME, resc_name);
00571 if(!ret.ok()) {
00572 result = PASSMSG( "init_child_map failed.", ret);
00573 } else {
00574
00575 children_parser parser;
00576 parser.set_string(children_string);
00577 children_parser::children_map_t children_list;
00578 error ret = parser.list(children_list);
00579 if(!ret.ok()) {
00580 result = PASSMSG( "init_child_map failed.", ret);
00581 } else {
00582
00583
00584 children_parser::children_map_t::const_iterator itr;
00585 for(itr = children_list.begin(); itr != children_list.end(); ++itr) {
00586 std::string child = itr->first;
00587 std::string context = itr->second;
00588
00589
00590 lookup_table< boost::shared_ptr< resource > >::iterator child_itr = resources_.find(child);
00591 if(child_itr == resources_.end()) {
00592 std::stringstream msg;
00593 msg << "Failed to find child \"" << child << "\" in resources.";
00594 result = ERROR( SYS_INVALID_INPUT_PARAM, msg.str() );
00595 } else {
00596
00597
00598 resource_ptr child_resc = child_itr->second;
00599 error ret = resc->add_child(child, context, child_resc);
00600 if(!ret.ok()) {
00601 result = PASSMSG( "init_child_map failed.", ret);
00602 }
00603
00604
00605 child_resc->set_parent( resc );
00606 }
00607 }
00608 }
00609 }
00610 }
00611 }
00612 return result;
00613 }
00614
00615
00616
00617 void resource_manager::print_local_resources() {
00618 lookup_table< boost::shared_ptr< resource > >::iterator itr;
00619 for( itr = resources_.begin(); itr != resources_.end(); ++itr ) {
00620 std::string loc, path, name;
00621 error path_err = itr->second->get_property< std::string >( RESOURCE_PATH, path );
00622 error loc_err = itr->second->get_property< std::string >( RESOURCE_LOCATION, loc );
00623 if( path_err.ok() && loc_err.ok() && "localhost" == loc ) {
00624 rodsLog( LOG_NOTICE, " RescName: %s, VaultPath: %s\n",
00625 itr->first.c_str(), path.c_str() );
00626 }
00627
00628 }
00629
00630 }
00631
00632
00633
00634
00635 error resource_manager::gather_operations() {
00636
00637
00638 std::vector< std::string > proc_vec;
00639
00640
00641
00642 lookup_table< boost::shared_ptr< resource > >::iterator resc_itr;
00643 for( resc_itr = resources_.begin(); resc_itr != resources_.end(); ++resc_itr ) {
00644 resource_ptr& resc = resc_itr->second;
00645
00646
00647
00648 std::string name;
00649 error get_err = resc->get_property< std::string >( RESOURCE_NAME, name );
00650
00651 if( get_err.ok() ) {
00652 std::vector< std::string >::iterator itr;
00653 itr = std::find< std::vector< std::string >::iterator, std::string >( proc_vec.begin(), proc_vec.end(), name );
00654 if( proc_vec.end() != itr ) {
00655 continue;
00656 }
00657 } else {
00658 std::stringstream msg;
00659 msg << "resource_manager::gather_operations - failed to get property ";
00660 msg << "[name] for resource";
00661 return PASSMSG( msg.str(), get_err );
00662 }
00663
00664
00665
00666 vector< pdmo_type > resc_ops;
00667
00668
00669
00670 pdmo_type pdmo_op;
00671 error pdmo_err = resc->post_disconnect_maintenance_operation( pdmo_op );
00672 if( pdmo_err.ok() ) {
00673 resc_ops.push_back( pdmo_op );
00674 }
00675
00676
00677
00678 proc_vec.push_back( name );
00679
00680
00681
00682 std::string child_str;
00683 error child_err = resc->get_property< std::string >( RESOURCE_CHILDREN, child_str );
00684 if( child_err.ok() && !child_str.empty() ) {
00685 gather_operations_recursive( child_str, proc_vec, resc_ops );
00686 }
00687
00688
00689
00690 if( !resc_ops.empty() ) {
00691 maintenance_operations_.push_back( resc_ops );
00692 }
00693
00694 }
00695
00696 return SUCCESS();
00697
00698 }
00699
00700
00701
00702
00703 error resource_manager::gather_operations_recursive( const std::string& _children,
00704 std::vector< std::string >& _proc_vec,
00705 std::vector< pdmo_type >& _resc_ops ) {
00706
00707
00708 children_parser parser;
00709 parser.set_string( _children );
00710 children_parser::children_map_t children_list;
00711 error ret = parser.list( children_list );
00712 if(!ret.ok()) {
00713 return PASSMSG( "gather_operations_recursive failed.", ret);
00714 }
00715
00716
00717
00718 children_parser::children_map_t::const_iterator itr;
00719 for( itr = children_list.begin(); itr != children_list.end(); ++itr ) {
00720 std::string child = itr->first;
00721
00722
00723
00724 resource_ptr resc;
00725 error get_err = resources_.get( child, resc );
00726 if( get_err.ok() ) {
00727
00728
00729 pdmo_type pdmo_op;
00730 error pdmo_ret = resc->post_disconnect_maintenance_operation( pdmo_op );
00731 if( pdmo_ret.ok() ) {
00732 _resc_ops.push_back( pdmo_op );
00733 }
00734
00735
00736
00737 _proc_vec.push_back( child );
00738
00739 } else {
00740 std::stringstream msg;
00741 msg << "failed to get resource for key [";
00742 msg << child;
00743 msg << "]";
00744 return ERROR( SYS_INVALID_INPUT_PARAM, msg.str() );
00745 }
00746
00747 }
00748
00749
00750
00751 for( itr = children_list.begin(); itr != children_list.end(); ++itr ) {
00752 std::string child = itr->first;
00753
00754
00755
00756 resource_ptr resc;
00757 error get_err = resources_.get( child, resc );
00758 if( get_err.ok() ) {
00759 std::string child_str;
00760 error child_err = resc->get_property< std::string >( RESOURCE_CHILDREN, child_str );
00761 if( child_err.ok() && !child_str.empty() ) {
00762 error gather_err = gather_operations_recursive( child_str, _proc_vec, _resc_ops );
00763 }
00764
00765 } else {
00766 std::stringstream msg;
00767 msg << "failed to get resource for key [";
00768 msg << child;
00769 msg << "]";
00770 return ERROR( SYS_INVALID_INPUT_PARAM, msg.str() );
00771 }
00772
00773 }
00774
00775 return SUCCESS();
00776
00777 }
00778
00779
00780
00781 error resource_manager::start_resource_plugins( ) {
00782
00783
00784 lookup_table< resource_ptr >::iterator itr;
00785 for( itr = resources_.begin();
00786 itr != resources_.end();
00787 ++itr ) {
00788
00789
00790 error ret = itr->second->start_operation( );
00791 if( !ret.ok() ) {
00792 eirods::log( ret );
00793 }
00794
00795 }
00796
00797 return SUCCESS();
00798
00799 }
00800
00801
00802
00803
00804 bool resource_manager::need_maintenance_operations( ) {
00805 bool need_pdmo = false;
00806
00807
00808
00809 lookup_table< resource_ptr >::iterator itr;
00810 for( itr = resources_.begin();
00811 itr != resources_.end();
00812 ++itr ) {
00813
00814
00815 bool flg = false;
00816 itr->second->need_post_disconnect_maintenance_operation( flg );
00817 if( flg ) {
00818 need_pdmo = true;
00819 break;
00820 }
00821
00822 }
00823
00824 return need_pdmo;
00825
00826 }
00827
00828
00829
00830 int resource_manager::call_maintenance_operations( rcComm_t* _comm ) {
00831 int result = 0;
00832
00833
00834
00835 std::vector< std::vector< pdmo_type > >::iterator vec_itr;
00836 for( vec_itr = maintenance_operations_.begin();
00837 vec_itr != maintenance_operations_.end();
00838 ++vec_itr ) {
00839
00840
00841 std::vector< pdmo_type >::iterator op_itr;
00842 for( op_itr = vec_itr->begin();
00843 op_itr != vec_itr->end();
00844 ++op_itr ) {
00845
00846
00847 error ret = ((*op_itr))( _comm );
00848 if( !ret.ok() ) {
00849 log( PASSMSG( "resource_manager::call_maintenance_operations - op failed", ret ) );
00850 result = ret.code();
00851 }
00852
00853 }
00854
00855 }
00856
00857 return result;
00858 }
00859
00860 };
00861
00862
00863