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