Skip to content

Commit

Permalink
squash - 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 afbb7fd commit b291b24
Showing 1 changed file with 28 additions and 25 deletions.
53 changes: 28 additions & 25 deletions src/configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,89 +9,93 @@ 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) {
// 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;
}

if (rule_engine.count(KW_CFG_PLUGIN_SPECIFIC_CONFIGURATION) <= 0) {
success_flag = true;
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;
}

const auto& config = rule_engine.at(KW_CFG_PLUGIN_SPECIFIC_CONFIGURATION);
// Override defaults with configured values.

if (const auto attr = config.find("access_time_attribute"); attr != config.end()) {
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()) {
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()) {
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()) {
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()) {
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()) {
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()) {
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()) {
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()) {
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()) {
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()) {
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()) {
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()) {
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()) {
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()) {
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;
}
}

success_flag = true;
// Only one configuration is considered for a given instance of a REP, so just return here.
return;
}
}
catch (const boost::bad_any_cast& e) {
Expand All @@ -101,9 +105,8 @@ namespace irods
THROW(KEY_NOT_FOUND, e.what());
}

if (!success_flag) {
THROW(SYS_INVALID_INPUT_PARAM,
fmt::format("failed to find configuration for storage_tiering plugin [{}]", _instance_name));
}
// 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 b291b24

Please sign in to comment.