/// =-=-=-=-=-=-=- /// @brief get the next resource shared pointer given this resources name /// as well as the object's hierarchy string irods::error get_next_child_in_hier( const std::string& _name, const std::string& _hier, irods::resource_child_map& _cmap, irods::resource_ptr& _resc ) { irods::error result = SUCCESS(); // =-=-=-=-=-=-=- // create a parser and parse the string irods::hierarchy_parser parse; irods::error err = parse.set_string( _hier ); if ( ( result = ASSERT_PASS( err, "Failed in set_string" ) ).ok() ) { // =-=-=-=-=-=-=- // get the next resource in the series std::string next; err = parse.next( _name, next ); if ( ( result = ASSERT_PASS( err, "Failed in next." ) ).ok() ) { // =-=-=-=-=-=-=- // get the next resource from the child map if ( ( result = ASSERT_ERROR( _cmap.has_entry( next ), CHILD_NOT_FOUND, "Child map missing entry: \"%s\"", next.c_str() ) ).ok() ) { // =-=-=-=-=-=-=- // assign resource _resc = _cmap[ next ].second; } } } return result; } // get_next_child_in_hier
/// =-=-=-=-=-=-=- /// @brief get the next resource shared pointer given this resources name /// as well as the object's hierarchy string irods::error get_next_child_in_hier( const std::string& _name, const std::string& _hier, irods::resource_child_map& _cmap, irods::resource_ptr& _resc ) { // =-=-=-=-=-=-=- // create a parser and parse the string irods::hierarchy_parser parse; irods::error err = parse.set_string( _hier ); if ( !err.ok() ) { std::stringstream msg; msg << "get_next_child_in_hier - failed in set_string for ["; msg << _hier << "]"; return PASSMSG( msg.str(), err ); } // =-=-=-=-=-=-=- // get the next resource in the series std::string next; err = parse.next( _name, next ); if ( !err.ok() ) { std::stringstream msg; msg << "get_next_child_in_hier - failed in next for ["; msg << _name << "] for hier [" << _hier << "]"; return PASSMSG( msg.str(), err ); } // =-=-=-=-=-=-=- // get the next resource from the child map if ( !_cmap.has_entry( next ) ) { std::stringstream msg; msg << "get_next_child_in_hier - child map missing entry ["; msg << next << "]"; return ERROR( CHILD_NOT_FOUND, msg.str() ); } // =-=-=-=-=-=-=- // assign resource _resc = _cmap[ next ].second; return SUCCESS(); } // get_next_child_in_hier
/// =-=-=-=-=-=-=- /// @brief find the next valid child resource for create operation irods::error get_next_valid_child_resource( irods::plugin_property_map& _prop_map, irods::resource_child_map& _cmap, irods::resource_ptr& _resc ) { // =-=-=-=-=-=-=- // counter and flag int child_ctr = 0; bool child_found = false; // =-=-=-=-=-=-=- // while we have not found a child and have not // exhausted all the children in the map while ( !child_found && child_ctr < _cmap.size() ) { // =-=-=-=-=-=-=- // increment child counter child_ctr++; // =-=-=-=-=-=-=- // get the next_child property std::string next_child; irods::error err = _prop_map.get< std::string >( NEXT_CHILD_PROP, next_child ); if ( !err.ok() ) { return PASSMSG( "round_robin_redirect - get property for 'next_child' failed.", err ); } // =-=-=-=-=-=-=- // get the next_child resource if ( !_cmap.has_entry( next_child ) ) { std::stringstream msg; msg << "child map has no child by name ["; msg << next_child << "]"; return PASSMSG( msg.str(), err ); } // =-=-=-=-=-=-=- // request our child resource to test it irods::resource_ptr resc = _cmap[ next_child ].second; // =-=-=-=-=-=-=- // get the resource's status int resc_status = 0; err = resc->get_property<int>( irods::RESOURCE_STATUS, resc_status ); if ( !err.ok() ) { return PASSMSG( "failed to get property", err ); } // =-=-=-=-=-=-=- // determine if the resource is up and available if ( INT_RESC_STATUS_DOWN != resc_status ) { // =-=-=-=-=-=-=- // we found a valid child, set out variable _resc = resc; child_found = true; } else { // =-=-=-=-=-=-=- // update the next_child as we do not have a valid child yet err = update_next_child_resource( _prop_map ); if ( !err.ok() ) { return PASSMSG( "update_next_child_resource failed", err ); } } } // while // =-=-=-=-=-=-=- // return appropriately if ( child_found ) { return SUCCESS(); } else { return ERROR( NO_NEXT_RESC_FOUND, "no valid child found" ); } } // get_next_valid_child_resource