Skip to content

Commit

Permalink
[#178] Improve configuration value fetching
Browse files Browse the repository at this point in the history
  • Loading branch information
alanking committed Dec 10, 2024
1 parent 73e289f commit 404c9d7
Showing 1 changed file with 109 additions and 101 deletions.
210 changes: 109 additions & 101 deletions src/configuration.cpp
Original file line number Diff line number Diff line change
@@ -1,104 +1,112 @@

#include "irods/private/storage_tiering/configuration.hpp"
#include <irods/irods_server_properties.hpp>

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<std::string>{
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<const std::string&>();
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<std::string>();
}

if(plugin_spec_cfg.find("group_attribute") != plugin_spec_cfg.end()) {
group_attribute = plugin_spec_cfg.at("group_attribute").get<std::string>();
}

if(plugin_spec_cfg.find("time_attribute") != plugin_spec_cfg.end()) {
time_attribute = plugin_spec_cfg.at("time_attribute").get<std::string>();
}

if(plugin_spec_cfg.find("query_attribute") != plugin_spec_cfg.end()) {
query_attribute = plugin_spec_cfg.at("query_attribute").get<std::string>();
}

if(plugin_spec_cfg.find("verification_attribute") != plugin_spec_cfg.end()) {
verification_attribute = plugin_spec_cfg.at("verification_attribute").get<std::string>();
}

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<std::string>();
}

if(plugin_spec_cfg.find("minimum_restage_tier") != plugin_spec_cfg.end()) {
minimum_restage_tier = plugin_spec_cfg.at("minimum_restage_tier").get<std::string>();
}

if(plugin_spec_cfg.find("preserve_replicas") != plugin_spec_cfg.end()) {
preserve_replicas = plugin_spec_cfg.at("preserve_replicas").get<std::string>();
}

if(plugin_spec_cfg.find("object_limit") != plugin_spec_cfg.end()) {
object_limit = plugin_spec_cfg.at("object_limit").get<std::string>();
}

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<std::string>();
}

if(plugin_spec_cfg.find("minimum_delay_time") != plugin_spec_cfg.end()) {
default_data_movement_parameters = plugin_spec_cfg.at("minimum_delay_time").get<std::string>();
}

if(plugin_spec_cfg.find("maximum_delay_time") != plugin_spec_cfg.end()) {
default_data_movement_parameters = plugin_spec_cfg.at("maximum_delay_time").get<std::string>();
}

if(plugin_spec_cfg.find("time_check_string") != plugin_spec_cfg.end()) {
time_check_string = plugin_spec_cfg.at("time_check_string").get<std::string>();
}

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<int>();
}

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<const std::string&>();
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 <irods/irods_server_properties.hpp>

#include <fmt/format.h>

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<const nlohmann::json&>(
std::vector<std::string>{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<const std::string&>();
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<std::string>();
}

if (const auto attr = config->find("group_attribute"); attr != config->end()) {
group_attribute = attr->get<std::string>();
}

if (const auto attr = config->find("time_attribute"); attr != config->end()) {
time_attribute = attr->get<std::string>();
}

if (const auto attr = config->find("query_attribute"); attr != config->end()) {
query_attribute = attr->get<std::string>();
}

if (const auto attr = config->find("verification_attribute"); attr != config->end()) {
verification_attribute = attr->get<std::string>();
}

if (const auto attr = config->find("data_movement_parameters_attribute"); attr != config->end()) {
data_movement_parameters_attribute = attr->get<std::string>();
}

if (const auto attr = config->find("minimum_restage_tier"); attr != config->end()) {
minimum_restage_tier = attr->get<std::string>();
}

if (const auto attr = config->find("preserve_replicas"); attr != config->end()) {
preserve_replicas = attr->get<std::string>();
}

if (const auto attr = config->find("object_limit"); attr != config->end()) {
object_limit = attr->get<std::string>();
}

if (const auto attr = config->find("default_data_movement_parameters"); attr != config->end()) {
default_data_movement_parameters = attr->get<std::string>();
}

if (const auto attr = config->find("minimum_delay_time"); attr != config->end()) {
default_data_movement_parameters = attr->get<std::string>();
}

if (const auto attr = config->find("maximum_delay_time"); attr != config->end()) {
default_data_movement_parameters = attr->get<std::string>();
}

if (const auto attr = config->find("time_check_string"); attr != config->end()) {
time_check_string = attr->get<std::string>();
}

if (const auto attr = config->find("number_of_scheduling_threads"); attr != config->end()) {
number_of_scheduling_threads = attr->get<int>();
}

if (const auto attr = config->find(data_transfer_log_level_key); attr != config->end()) {
const std::string& val = attr->get_ref<const std::string&>();
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

0 comments on commit 404c9d7

Please sign in to comment.