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
00025 eirods::resource_manager resc_mgr;
00026
00027 namespace eirods {
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::get_root_resources(
00294 std::vector< std::string >& _list ) {
00295
00296
00297 lookup_table< boost::shared_ptr< resource > >::iterator itr;
00298 for( itr = resources_.begin();
00299 itr != resources_.end();
00300 ++itr ) {
00301 resource_ptr resc = itr->second;
00302 resource_ptr parent_ptr;
00303 error ret = itr->second->get_parent( parent_ptr );
00304 if( !ret.ok() ) {
00305 std::string resc_name;
00306 ret = resc->get_property< std::string >( RESOURCE_NAME, resc_name );
00307 if( !ret.ok() ) {
00308 return PASS( ret );
00309 }
00310
00311 _list.push_back( resc_name );
00312
00313 }
00314
00315 }
00316
00317 return SUCCESS();
00318
00319 }
00320
00321
00322
00323 error resource_manager::process_init_results( genQueryOut_t* _result ) {
00324
00325
00326 if ( !_result ) {
00327 return ERROR( SYS_INVALID_INPUT_PARAM, "_result parameter is null" );
00328 }
00329
00330
00331
00332 sqlResult_t *rescId = 0, *rescName = 0, *zoneName = 0, *rescType = 0, *rescClass = 0;
00333 sqlResult_t *rescLoc = 0, *rescVaultPath = 0, *freeSpace = 0, *rescInfo = 0;
00334 sqlResult_t *rescComments = 0, *rescCreate = 0, *rescModify = 0, *rescStatus = 0;
00335 sqlResult_t *rescChildren = 0, *rescContext = 0, *rescParent = 0, *rescObjCount = 0;
00336
00337
00338
00339 if( ( rescId = getSqlResultByInx( _result, COL_R_RESC_ID ) ) == NULL ) {
00340 return ERROR( UNMATCHED_KEY_OR_INDEX,"getSqlResultByInx for COL_R_RESC_ID failed" );
00341 }
00342
00343 if( ( rescName = getSqlResultByInx( _result, COL_R_RESC_NAME ) ) == NULL ) {
00344 return ERROR( UNMATCHED_KEY_OR_INDEX, "getSqlResultByInx for COL_R_RESC_NAME failed" );
00345 }
00346
00347 if( ( zoneName = getSqlResultByInx( _result, COL_R_ZONE_NAME ) ) == NULL ) {
00348 return ERROR( UNMATCHED_KEY_OR_INDEX, "getSqlResultByInx for COL_R_ZONE_NAME failed" );
00349 }
00350
00351 if( ( rescType = getSqlResultByInx(_result, COL_R_TYPE_NAME ) ) == NULL ) {
00352 return ERROR( UNMATCHED_KEY_OR_INDEX, "getSqlResultByInx for COL_R_TYPE_NAME failed" );
00353 }
00354
00355 if( ( rescClass = getSqlResultByInx( _result, COL_R_CLASS_NAME ) ) == NULL ) {
00356 return ERROR( UNMATCHED_KEY_OR_INDEX, "getSqlResultByInx for COL_R_CLASS_NAME failed" );
00357 }
00358
00359 if( ( rescLoc = getSqlResultByInx( _result, COL_R_LOC ) ) == NULL ) {
00360 return ERROR( UNMATCHED_KEY_OR_INDEX, "getSqlResultByInx for COL_R_LOC failed" );
00361 }
00362
00363 if( ( rescVaultPath = getSqlResultByInx( _result, COL_R_VAULT_PATH ) ) == NULL ) {
00364 return ERROR( UNMATCHED_KEY_OR_INDEX, "getSqlResultByInx for COL_R_VAULT_PATH failed" );
00365 }
00366
00367 if( ( freeSpace = getSqlResultByInx( _result, COL_R_FREE_SPACE ) ) == NULL ) {
00368 return ERROR( UNMATCHED_KEY_OR_INDEX, "getSqlResultByInx for COL_R_FREE_SPACE failed" );
00369 }
00370
00371 if( ( rescInfo = getSqlResultByInx( _result, COL_R_RESC_INFO ) ) == NULL ) {
00372 return ERROR( UNMATCHED_KEY_OR_INDEX, "getSqlResultByInx for COL_R_RESC_INFO failed" );
00373 }
00374
00375 if( ( rescComments = getSqlResultByInx( _result, COL_R_RESC_COMMENT ) ) == NULL ) {
00376 return ERROR( UNMATCHED_KEY_OR_INDEX, "getSqlResultByInx for COL_R_RESC_COMMENT failed" );
00377 }
00378
00379 if( ( rescCreate = getSqlResultByInx( _result, COL_R_CREATE_TIME ) ) == NULL) {
00380 return ERROR( UNMATCHED_KEY_OR_INDEX, "getSqlResultByInx for COL_R_CREATE_TIME failed" );
00381 }
00382
00383 if( ( rescModify = getSqlResultByInx( _result, COL_R_MODIFY_TIME ) ) == NULL) {
00384 return ERROR( UNMATCHED_KEY_OR_INDEX, "getSqlResultByInx for COL_R_MODIFY_TIME failed" );
00385 }
00386
00387 if( ( rescStatus = getSqlResultByInx( _result, COL_R_RESC_STATUS ) ) == NULL) {
00388 return ERROR( UNMATCHED_KEY_OR_INDEX, "getSqlResultByInx for COL_R_RESC_STATUS failed" );
00389 }
00390
00391 if( ( rescChildren = getSqlResultByInx( _result, COL_R_RESC_CHILDREN ) ) == NULL) {
00392 return ERROR( UNMATCHED_KEY_OR_INDEX, "getSqlResultByInx for COL_R_RESC_CHILDREN failed" );
00393 }
00394
00395 if( ( rescContext = getSqlResultByInx( _result, COL_R_RESC_CONTEXT ) ) == NULL) {
00396 return ERROR( UNMATCHED_KEY_OR_INDEX, "getSqlResultByInx for COL_R_RESC_CONTEXT failed" );
00397 }
00398
00399 if( ( rescParent = getSqlResultByInx( _result, COL_R_RESC_PARENT ) ) == NULL) {
00400 return ERROR( UNMATCHED_KEY_OR_INDEX, "getSqlResultByInx for COL_R_RESC_PARENT failed" );
00401 }
00402
00403 if( ( rescObjCount = getSqlResultByInx( _result, COL_R_RESC_OBJCOUNT ) ) == NULL) {
00404 return ERROR( UNMATCHED_KEY_OR_INDEX, "getSqlResultByInx for COL_R_RESC_OBJCOUNT failed" );
00405 }
00406
00407
00408
00409 for( int i = 0; i < _result->rowCnt; ++i ) {
00410
00411
00412 std::string tmpRescId = &rescId->value[ rescId->len * i ];
00413 std::string tmpRescLoc = &rescLoc->value[ rescLoc->len * i ];
00414 std::string tmpRescName = &rescName->value[ rescName->len * i ];
00415 std::string tmpZoneName = &zoneName->value[ zoneName->len * i ];
00416 std::string tmpRescType = &rescType->value[ rescType->len * i ];
00417 std::string tmpRescInfo = &rescInfo->value[ rescInfo->len * i ];
00418 std::string tmpFreeSpace = &freeSpace->value[ freeSpace->len * i ];
00419 std::string tmpRescClass = &rescClass->value[ rescClass->len * i ];
00420 std::string tmpRescCreate = &rescCreate->value[ rescCreate->len * i ];
00421 std::string tmpRescModify = &rescModify->value[ rescModify->len * i ];
00422 std::string tmpRescStatus = &rescStatus->value[ rescStatus->len * i ];
00423 std::string tmpRescComments = &rescComments->value[ rescComments->len * i ];
00424 std::string tmpRescVaultPath = &rescVaultPath->value[ rescVaultPath->len * i ];
00425 std::string tmpRescChildren = &rescChildren->value[ rescChildren->len * i ];
00426 std::string tmpRescContext = &rescContext->value[ rescContext->len * i ];
00427 std::string tmpRescParent = &rescParent->value[ rescParent->len * i ];
00428 std::string tmpRescObjCount = &rescObjCount->value[ rescObjCount->len * i ];
00429
00430
00431
00432 resource_ptr resc;
00433 error ret = load_resource_plugin( resc, tmpRescType, tmpRescName, tmpRescContext );
00434 if( !ret.ok() ) {
00435 return PASSMSG( "Failed to load Resource Plugin", ret );
00436 }
00437
00438
00439
00440 if( tmpRescLoc != eirods::EMPTY_RESC_HOST ) {
00441 rodsHostAddr_t addr;
00442 rstrcpy( addr.hostAddr, const_cast<char*>( tmpRescLoc.c_str() ), LONG_NAME_LEN );
00443 rstrcpy( addr.zoneName, const_cast<char*>( tmpZoneName.c_str() ), NAME_LEN );
00444
00445 rodsServerHost_t* tmpRodsServerHost = 0;
00446 if( resolveHost( &addr, &tmpRodsServerHost ) < 0 ) {
00447 rodsLog( LOG_NOTICE, "procAndQueRescResult: resolveHost error for %s",
00448 addr.hostAddr );
00449 }
00450
00451 resc->set_property< rodsServerHost_t* >( RESOURCE_HOST, tmpRodsServerHost );
00452
00453 } else {
00454 resc->set_property< rodsServerHost_t* >( RESOURCE_HOST, 0 );
00455 }
00456
00457 resc->set_property<long>( RESOURCE_ID, strtoll( tmpRescId.c_str(), 0, 0 ) );
00458 resc->set_property<long>( RESOURCE_FREESPACE, strtoll( tmpFreeSpace.c_str(), 0, 0 ) );
00459 resc->set_property<long>( RESOURCE_QUOTA, RESC_QUOTA_UNINIT );
00460
00461 resc->set_property<std::string>( RESOURCE_ZONE, tmpZoneName );
00462 resc->set_property<std::string>( RESOURCE_NAME, tmpRescName );
00463 resc->set_property<std::string>( RESOURCE_LOCATION, tmpRescLoc );
00464 resc->set_property<std::string>( RESOURCE_TYPE, tmpRescType );
00465 resc->set_property<std::string>( RESOURCE_CLASS, tmpRescClass );
00466 resc->set_property<std::string>( RESOURCE_PATH, tmpRescVaultPath );
00467 resc->set_property<std::string>( RESOURCE_INFO, tmpRescInfo );
00468 resc->set_property<std::string>( RESOURCE_COMMENTS, tmpRescComments );
00469 resc->set_property<std::string>( RESOURCE_CREATE_TS, tmpRescCreate );
00470 resc->set_property<std::string>( RESOURCE_MODIFY_TS, tmpRescModify );
00471 resc->set_property<std::string>( RESOURCE_CHILDREN, tmpRescChildren );
00472 resc->set_property<std::string>( RESOURCE_PARENT, tmpRescParent );
00473 resc->set_property<std::string>( RESOURCE_CONTEXT, tmpRescContext );
00474
00475 if( tmpRescStatus == std::string( RESC_DOWN ) ) {
00476 resc->set_property<int>( RESOURCE_STATUS, INT_RESC_STATUS_DOWN );
00477 } else {
00478 resc->set_property<int>( RESOURCE_STATUS, INT_RESC_STATUS_UP );
00479 }
00480
00481
00482
00483 resources_[ tmpRescName ] = resc;
00484
00485 }
00486
00487
00488 return SUCCESS();
00489
00490 }
00491
00492
00493
00494 error resource_manager::init_from_type( std::string _type,
00495 std::string _key,
00496 std::string _inst,
00497 std::string _ctx,
00498 resource_ptr& _resc ) {
00499
00500
00501 error ret = load_resource_plugin( _resc, _type, _inst, _ctx );
00502 if( !ret.ok() ) {
00503 return PASSMSG( "Failed to load Resource Plugin", ret );
00504 }
00505
00506 resources_[ _key ] = _resc;
00507
00508 return SUCCESS();
00509
00510 }
00511
00512
00513
00514
00515 error resource_manager::init_local_file_system_resource(void) {
00516
00517
00518 resource_ptr resc;
00519 error err = init_from_type( EIRODS_LOCAL_USE_ONLY_RESOURCE_TYPE,
00520 EIRODS_LOCAL_USE_ONLY_RESOURCE,
00521 EIRODS_LOCAL_USE_ONLY_RESOURCE,
00522 "",
00523 resc );
00524
00525
00526 if( !err.ok() ) {
00527 std::stringstream msg;
00528 msg << "resource_manager::init_local_file_system_resource - failed to create resource";
00529 return PASSMSG( msg.str(), err );
00530 }
00531
00532
00533
00534 zoneInfo_t* zone_info = 0;
00535 getLocalZoneInfo( &zone_info );
00536
00537
00538
00539 char host_name[ MAX_NAME_LEN ];
00540 gethostname( host_name, MAX_NAME_LEN );
00541
00542 rodsHostAddr_t addr;
00543 rstrcpy( addr.hostAddr, host_name, LONG_NAME_LEN );
00544 rstrcpy( addr.zoneName, const_cast<char*>( zone_info->zoneName ), NAME_LEN );
00545
00546 rodsServerHost_t* tmpRodsServerHost = 0;
00547 if( resolveHost( &addr, &tmpRodsServerHost ) < 0 ) {
00548 rodsLog( LOG_NOTICE, "procAndQueRescResult: resolveHost error for %s",
00549 addr.hostAddr );
00550 }
00551
00552 resc->set_property< rodsServerHost_t* >( RESOURCE_HOST, tmpRodsServerHost );
00553
00554
00555
00556 resc->set_property<long>( RESOURCE_ID, 999 );
00557 resc->set_property<long>( RESOURCE_FREESPACE, 999 );
00558 resc->set_property<long>( RESOURCE_QUOTA, RESC_QUOTA_UNINIT );
00559
00560 resc->set_property<std::string>( RESOURCE_ZONE, zone_info->zoneName );
00561 resc->set_property<std::string>( RESOURCE_NAME, EIRODS_LOCAL_USE_ONLY_RESOURCE );
00562 resc->set_property<std::string>( RESOURCE_LOCATION, "localhost" );
00563 resc->set_property<std::string>( RESOURCE_TYPE, EIRODS_LOCAL_USE_ONLY_RESOURCE_TYPE );
00564 resc->set_property<std::string>( RESOURCE_CLASS, "cache" );
00565 resc->set_property<std::string>( RESOURCE_PATH, EIRODS_LOCAL_USE_ONLY_RESOURCE_VAULT );
00566 resc->set_property<std::string>( RESOURCE_INFO, "info" );
00567 resc->set_property<std::string>( RESOURCE_COMMENTS, "comments" );
00568 resc->set_property<std::string>( RESOURCE_CREATE_TS, "999" );
00569 resc->set_property<std::string>( RESOURCE_MODIFY_TS, "999" );
00570 resc->set_property<std::string>( RESOURCE_CHILDREN, "" );
00571 resc->set_property<std::string>( RESOURCE_PARENT, "" );
00572 resc->set_property<std::string>( RESOURCE_CONTEXT, "" );
00573 resc->set_property<int>( RESOURCE_STATUS, INT_RESC_STATUS_UP );
00574
00575
00576
00577 resources_[ EIRODS_LOCAL_USE_ONLY_RESOURCE ] = resc;
00578
00579 return SUCCESS();
00580
00581 }
00582
00583
00584
00585 error resource_manager::init_child_map(void) {
00586 error result = SUCCESS();
00587
00588
00589 lookup_table< boost::shared_ptr< resource > >::iterator it;
00590 for(it = resources_.begin(); it != resources_.end(); ++it) {
00591 resource_ptr resc = it->second;
00592
00593
00594 std::string children_string;
00595 error ret = resc->get_property<std::string>( RESOURCE_CHILDREN, children_string);
00596 if(!ret.ok()) {
00597 result = PASSMSG( "init_child_map failed.", ret);
00598 } else {
00599 std::string resc_name;
00600 error ret = resc->get_property<std::string>( RESOURCE_NAME, resc_name);
00601 if(!ret.ok()) {
00602 result = PASSMSG( "init_child_map failed.", ret);
00603 } else {
00604
00605 children_parser parser;
00606 parser.set_string(children_string);
00607 children_parser::children_map_t children_list;
00608 error ret = parser.list(children_list);
00609 if(!ret.ok()) {
00610 result = PASSMSG( "init_child_map failed.", ret);
00611 } else {
00612
00613
00614 children_parser::children_map_t::const_iterator itr;
00615 for(itr = children_list.begin(); itr != children_list.end(); ++itr) {
00616 std::string child = itr->first;
00617 std::string context = itr->second;
00618
00619
00620 lookup_table< boost::shared_ptr< resource > >::iterator child_itr = resources_.find(child);
00621 if(child_itr == resources_.end()) {
00622 std::stringstream msg;
00623 msg << "Failed to find child \"" << child << "\" in resources.";
00624 result = ERROR( SYS_INVALID_INPUT_PARAM, msg.str() );
00625 } else {
00626
00627
00628 resource_ptr child_resc = child_itr->second;
00629 error ret = resc->add_child(child, context, child_resc);
00630 if(!ret.ok()) {
00631 result = PASSMSG( "init_child_map failed.", ret);
00632 }
00633
00634
00635 child_resc->set_parent( resc );
00636 }
00637 }
00638 }
00639 }
00640 }
00641 }
00642 return result;
00643 }
00644
00645
00646
00647 void resource_manager::print_local_resources() {
00648 lookup_table< boost::shared_ptr< resource > >::iterator itr;
00649 for( itr = resources_.begin(); itr != resources_.end(); ++itr ) {
00650 std::string loc, path, name;
00651 error path_err = itr->second->get_property< std::string >( RESOURCE_PATH, path );
00652 error loc_err = itr->second->get_property< std::string >( RESOURCE_LOCATION, loc );
00653 if( path_err.ok() && loc_err.ok() && "localhost" == loc ) {
00654 rodsLog( LOG_NOTICE, " RescName: %s, VaultPath: %s\n",
00655 itr->first.c_str(), path.c_str() );
00656 }
00657
00658 }
00659
00660 }
00661
00662
00663
00664
00665 error resource_manager::gather_operations() {
00666
00667
00668 std::vector< std::string > proc_vec;
00669
00670
00671
00672 lookup_table< boost::shared_ptr< resource > >::iterator resc_itr;
00673 for( resc_itr = resources_.begin(); resc_itr != resources_.end(); ++resc_itr ) {
00674 resource_ptr& resc = resc_itr->second;
00675
00676
00677
00678 std::string name;
00679 error get_err = resc->get_property< std::string >( RESOURCE_NAME, name );
00680
00681 if( get_err.ok() ) {
00682 std::vector< std::string >::iterator itr;
00683 itr = std::find< std::vector< std::string >::iterator, std::string >( proc_vec.begin(), proc_vec.end(), name );
00684 if( proc_vec.end() != itr ) {
00685 continue;
00686 }
00687 } else {
00688 std::stringstream msg;
00689 msg << "resource_manager::gather_operations - failed to get property ";
00690 msg << "[name] for resource";
00691 return PASSMSG( msg.str(), get_err );
00692 }
00693
00694
00695
00696 vector< pdmo_type > resc_ops;
00697
00698
00699
00700 pdmo_type pdmo_op;
00701 error pdmo_err = resc->post_disconnect_maintenance_operation( pdmo_op );
00702 if( pdmo_err.ok() ) {
00703 resc_ops.push_back( pdmo_op );
00704 }
00705
00706
00707
00708 proc_vec.push_back( name );
00709
00710
00711
00712 std::string child_str;
00713 error child_err = resc->get_property< std::string >( RESOURCE_CHILDREN, child_str );
00714 if( child_err.ok() && !child_str.empty() ) {
00715 gather_operations_recursive( child_str, proc_vec, resc_ops );
00716 }
00717
00718
00719
00720 if( !resc_ops.empty() ) {
00721 maintenance_operations_.push_back( resc_ops );
00722 }
00723
00724 }
00725
00726 return SUCCESS();
00727
00728 }
00729
00730
00731
00732
00733 error resource_manager::gather_operations_recursive( const std::string& _children,
00734 std::vector< std::string >& _proc_vec,
00735 std::vector< pdmo_type >& _resc_ops ) {
00736
00737
00738 children_parser parser;
00739 parser.set_string( _children );
00740 children_parser::children_map_t children_list;
00741 error ret = parser.list( children_list );
00742 if(!ret.ok()) {
00743 return PASSMSG( "gather_operations_recursive failed.", ret);
00744 }
00745
00746
00747
00748 children_parser::children_map_t::const_iterator itr;
00749 for( itr = children_list.begin(); itr != children_list.end(); ++itr ) {
00750 std::string child = itr->first;
00751
00752
00753
00754 resource_ptr resc;
00755 error get_err = resources_.get( child, resc );
00756 if( get_err.ok() ) {
00757
00758
00759 pdmo_type pdmo_op;
00760 error pdmo_ret = resc->post_disconnect_maintenance_operation( pdmo_op );
00761 if( pdmo_ret.ok() ) {
00762 _resc_ops.push_back( pdmo_op );
00763 }
00764
00765
00766
00767 _proc_vec.push_back( child );
00768
00769 } else {
00770 std::stringstream msg;
00771 msg << "failed to get resource for key [";
00772 msg << child;
00773 msg << "]";
00774 return ERROR( SYS_INVALID_INPUT_PARAM, msg.str() );
00775 }
00776
00777 }
00778
00779
00780
00781 for( itr = children_list.begin(); itr != children_list.end(); ++itr ) {
00782 std::string child = itr->first;
00783
00784
00785
00786 resource_ptr resc;
00787 error get_err = resources_.get( child, resc );
00788 if( get_err.ok() ) {
00789 std::string child_str;
00790 error child_err = resc->get_property< std::string >( RESOURCE_CHILDREN, child_str );
00791 if( child_err.ok() && !child_str.empty() ) {
00792 error gather_err = gather_operations_recursive( child_str, _proc_vec, _resc_ops );
00793 }
00794
00795 } else {
00796 std::stringstream msg;
00797 msg << "failed to get resource for key [";
00798 msg << child;
00799 msg << "]";
00800 return ERROR( SYS_INVALID_INPUT_PARAM, msg.str() );
00801 }
00802
00803 }
00804
00805 return SUCCESS();
00806
00807 }
00808
00809
00810
00811 error resource_manager::start_resource_plugins( ) {
00812
00813
00814 lookup_table< resource_ptr >::iterator itr;
00815 for( itr = resources_.begin();
00816 itr != resources_.end();
00817 ++itr ) {
00818
00819
00820 error ret = itr->second->start_operation( );
00821 if( !ret.ok() ) {
00822 eirods::log( ret );
00823 }
00824
00825 }
00826
00827 return SUCCESS();
00828
00829 }
00830
00831
00832
00833
00834 bool resource_manager::need_maintenance_operations( ) {
00835 bool need_pdmo = false;
00836
00837
00838
00839 lookup_table< resource_ptr >::iterator itr;
00840 for( itr = resources_.begin();
00841 itr != resources_.end();
00842 ++itr ) {
00843
00844
00845 bool flg = false;
00846 itr->second->need_post_disconnect_maintenance_operation( flg );
00847 if( flg ) {
00848 need_pdmo = true;
00849 break;
00850 }
00851
00852 }
00853
00854 return need_pdmo;
00855
00856 }
00857
00858
00859
00860 int resource_manager::call_maintenance_operations( rcComm_t* _comm ) {
00861 int result = 0;
00862
00863
00864
00865 std::vector< std::vector< pdmo_type > >::iterator vec_itr;
00866 for( vec_itr = maintenance_operations_.begin();
00867 vec_itr != maintenance_operations_.end();
00868 ++vec_itr ) {
00869
00870
00871 std::vector< pdmo_type >::iterator op_itr;
00872 for( op_itr = vec_itr->begin();
00873 op_itr != vec_itr->end();
00874 ++op_itr ) {
00875
00876
00877 error ret = ((*op_itr))( _comm );
00878 if( !ret.ok() ) {
00879 log( PASSMSG( "resource_manager::call_maintenance_operations - op failed", ret ) );
00880 result = ret.code();
00881 }
00882
00883 }
00884
00885 }
00886
00887 return result;
00888 }
00889
00890 };
00891
00892
00893