From 404c9d73516126e74c7b2a3aa640a63de7d50bc5 Mon Sep 17 00:00:00 2001 From: Alan King Date: Thu, 5 Dec 2024 16:03:40 -0500 Subject: [PATCH] [#178] Improve configuration value fetching --- src/configuration.cpp | 210 ++++++++++++++++++++++-------------------- 1 file changed, 109 insertions(+), 101 deletions(-) diff --git a/src/configuration.cpp b/src/configuration.cpp index 37307b9..22639ab 100644 --- a/src/configuration.cpp +++ b/src/configuration.cpp @@ -1,104 +1,112 @@ - #include "irods/private/storage_tiering/configuration.hpp" -#include -namespace irods { - storage_tiering_configuration::storage_tiering_configuration( - const std::string& _instance_name ) : - instance_name{_instance_name} { - bool success_flag = false; - - try { - const auto& rule_engines = get_server_property< - const nlohmann::json&>( - std::vector{ - KW_CFG_PLUGIN_CONFIGURATION, - KW_CFG_PLUGIN_TYPE_RULE_ENGINE}); - for ( const auto& rule_engine : rule_engines ) { - const auto& inst_name = rule_engine.at( KW_CFG_INSTANCE_NAME).get_ref(); - if ( inst_name == _instance_name ) { - if(rule_engine.count(KW_CFG_PLUGIN_SPECIFIC_CONFIGURATION) > 0) { - const auto& plugin_spec_cfg = rule_engine.at(KW_CFG_PLUGIN_SPECIFIC_CONFIGURATION); - if(plugin_spec_cfg.find("access_time_attribute") != plugin_spec_cfg.end()) { - access_time_attribute = plugin_spec_cfg.at("access_time_attribute").get(); - } - - if(plugin_spec_cfg.find("group_attribute") != plugin_spec_cfg.end()) { - group_attribute = plugin_spec_cfg.at("group_attribute").get(); - } - - if(plugin_spec_cfg.find("time_attribute") != plugin_spec_cfg.end()) { - time_attribute = plugin_spec_cfg.at("time_attribute").get(); - } - - if(plugin_spec_cfg.find("query_attribute") != plugin_spec_cfg.end()) { - query_attribute = plugin_spec_cfg.at("query_attribute").get(); - } - - if(plugin_spec_cfg.find("verification_attribute") != plugin_spec_cfg.end()) { - verification_attribute = plugin_spec_cfg.at("verification_attribute").get(); - } - - if(plugin_spec_cfg.find("data_movement_parameters_attribute") != plugin_spec_cfg.end()) { - data_movement_parameters_attribute = plugin_spec_cfg.at("data_movement_parameters_attribute").get(); - } - - if(plugin_spec_cfg.find("minimum_restage_tier") != plugin_spec_cfg.end()) { - minimum_restage_tier = plugin_spec_cfg.at("minimum_restage_tier").get(); - } - - if(plugin_spec_cfg.find("preserve_replicas") != plugin_spec_cfg.end()) { - preserve_replicas = plugin_spec_cfg.at("preserve_replicas").get(); - } - - if(plugin_spec_cfg.find("object_limit") != plugin_spec_cfg.end()) { - object_limit = plugin_spec_cfg.at("object_limit").get(); - } - - if(plugin_spec_cfg.find("default_data_movement_parameters") != plugin_spec_cfg.end()) { - default_data_movement_parameters = plugin_spec_cfg.at("default_data_movement_parameters").get(); - } - - if(plugin_spec_cfg.find("minimum_delay_time") != plugin_spec_cfg.end()) { - default_data_movement_parameters = plugin_spec_cfg.at("minimum_delay_time").get(); - } - - if(plugin_spec_cfg.find("maximum_delay_time") != plugin_spec_cfg.end()) { - default_data_movement_parameters = plugin_spec_cfg.at("maximum_delay_time").get(); - } - - if(plugin_spec_cfg.find("time_check_string") != plugin_spec_cfg.end()) { - time_check_string = plugin_spec_cfg.at("time_check_string").get(); - } - - if(plugin_spec_cfg.find("number_of_scheduling_threads") != plugin_spec_cfg.end()) { - number_of_scheduling_threads = plugin_spec_cfg.at("number_of_scheduling_threads").get(); - } - - if(plugin_spec_cfg.find(data_transfer_log_level_key) != plugin_spec_cfg.end()) { - const std::string& val = plugin_spec_cfg.at(data_transfer_log_level_key).get_ref(); - if("LOG_NOTICE" == val) { - data_transfer_log_level_value = LOG_NOTICE; - } - } - } - - success_flag = true; - } // if inst_name - } // for rule_engines - } catch ( const boost::bad_any_cast& e ) { - THROW( INVALID_ANY_CAST, e.what() ); - } catch ( const std::out_of_range& e ) { - THROW( KEY_NOT_FOUND, e.what() ); - } - - if(!success_flag) { - THROW( - SYS_INVALID_INPUT_PARAM, - boost::format("failed to find configuration for storage_tiering plugin [%s]") % - _instance_name); - } - } // ctor storage_tiering_configuration - -} // namepsace irods +#include +#include + +namespace irods +{ + storage_tiering_configuration::storage_tiering_configuration(const std::string& _instance_name) + : instance_name{_instance_name} + { + try { + const auto& rule_engines = get_server_property( + std::vector{KW_CFG_PLUGIN_CONFIGURATION, KW_CFG_PLUGIN_TYPE_RULE_ENGINE}); + + for (const auto& rule_engine : rule_engines) { + // Loop until the provided instance name is found. + if (const auto& inst_name = rule_engine.at(KW_CFG_INSTANCE_NAME).get_ref(); + inst_name != _instance_name) + { + continue; + } + + // Get the plugin-specific configuration stanza for this instance... + const auto config = rule_engine.find(KW_CFG_PLUGIN_SPECIFIC_CONFIGURATION); + if (rule_engine.end() == config) { + // If no plugin_specific_configuration is defined, use the default configuration. There is no need + // to check other configured REPs because this is the instance we were looking for - just return. + return; + } + + // Override defaults with configured values. + + if (const auto attr = config->find("access_time_attribute"); attr != config->end()) { + access_time_attribute = attr->get(); + } + + if (const auto attr = config->find("group_attribute"); attr != config->end()) { + group_attribute = attr->get(); + } + + if (const auto attr = config->find("time_attribute"); attr != config->end()) { + time_attribute = attr->get(); + } + + if (const auto attr = config->find("query_attribute"); attr != config->end()) { + query_attribute = attr->get(); + } + + if (const auto attr = config->find("verification_attribute"); attr != config->end()) { + verification_attribute = attr->get(); + } + + if (const auto attr = config->find("data_movement_parameters_attribute"); attr != config->end()) { + data_movement_parameters_attribute = attr->get(); + } + + if (const auto attr = config->find("minimum_restage_tier"); attr != config->end()) { + minimum_restage_tier = attr->get(); + } + + if (const auto attr = config->find("preserve_replicas"); attr != config->end()) { + preserve_replicas = attr->get(); + } + + if (const auto attr = config->find("object_limit"); attr != config->end()) { + object_limit = attr->get(); + } + + if (const auto attr = config->find("default_data_movement_parameters"); attr != config->end()) { + default_data_movement_parameters = attr->get(); + } + + if (const auto attr = config->find("minimum_delay_time"); attr != config->end()) { + default_data_movement_parameters = attr->get(); + } + + if (const auto attr = config->find("maximum_delay_time"); attr != config->end()) { + default_data_movement_parameters = attr->get(); + } + + if (const auto attr = config->find("time_check_string"); attr != config->end()) { + time_check_string = attr->get(); + } + + if (const auto attr = config->find("number_of_scheduling_threads"); attr != config->end()) { + number_of_scheduling_threads = attr->get(); + } + + if (const auto attr = config->find(data_transfer_log_level_key); attr != config->end()) { + const std::string& val = attr->get_ref(); + if ("LOG_NOTICE" == val) { + data_transfer_log_level_value = LOG_NOTICE; + } + } + + // Only one configuration is considered for a given instance of a REP, so just return here. + return; + } + } + catch (const boost::bad_any_cast& e) { + THROW(INVALID_ANY_CAST, e.what()); + } + catch (const std::out_of_range& e) { + THROW(KEY_NOT_FOUND, e.what()); + } + + // No valid configuration was found for the given instance name if we reach this point, which is an error. + THROW(SYS_INVALID_INPUT_PARAM, + fmt::format("Failed to find configuration for storage_tiering plugin [{}].", _instance_name)); + } // storage_tiering_configuration constructor +} //namespace irods