Skip to content

get_leaf_resources_string is duplicated #345

Description

@alanking

storage_tiering.cpp and data_verification_utilities.cpp both have an implementation of get_leaf_resources_string:

std::string storage_tiering::get_leaf_resources_string(
const std::string& _resource_name) {
std::string leaf_id_str;
// if the resource has no children then simply return
resource_ptr root_resc;
error err = resc_mgr.resolve(_resource_name, root_resc);
if(!err.ok()) {
THROW(err.code(), err.result());
}
std::vector<resource_manager::leaf_bundle_t> leaf_bundles =
resc_mgr.gather_leaf_bundles_for_resc(_resource_name);
for(const auto & bundle : leaf_bundles) {
for(const auto & leaf_id : bundle) {
leaf_id_str +=
"'" + boost::str(boost::format("%s") % leaf_id) + "',";
} // for
} // for
// if there is no hierarchy
if(leaf_id_str.empty()) {
rodsLong_t resc_id;
resc_mgr.hier_to_leaf_id(_resource_name, resc_id);
leaf_id_str =
"'" + boost::str(boost::format("%s") % resc_id) + "',";
}
return leaf_id_str;
} // get_leaf_resources_string

std::string get_leaf_resources_string(
const std::string& _resource_name) {
std::string leaf_id_str;
// if the resource has no children then simply return
irods::resource_ptr root_resc;
irods::error err = resc_mgr.resolve(_resource_name, root_resc);
if(!err.ok()) {
THROW(err.code(), err.result());
}
try {
std::vector<irods::resource_manager::leaf_bundle_t> leaf_bundles =
resc_mgr.gather_leaf_bundles_for_resc(_resource_name);
for(const auto & bundle : leaf_bundles) {
for(const auto & leaf_id : bundle) {
leaf_id_str +=
"'" + boost::str(boost::format("%s") % leaf_id) + "',";
} // for
} // for
}
catch( const irods::exception & _e ) {
throw;
}
// if there is no hierarchy
if(leaf_id_str.empty()) {
rodsLong_t resc_id;
resc_mgr.hier_to_leaf_id(_resource_name, resc_id);
leaf_id_str =
"'" + boost::str(boost::format("%s") % resc_id) + "',";
}
return leaf_id_str;
} // get_leaf_resources_string

They are identical apart from an extraneous try-catch block (it just re-throws and does nothing else) in one of the implementations. Let's put this in a common place and point to one implementation. Can replace some boost in here, too (see #249 and #250).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions