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