From 42e27653d0873cc0cbf96d332c9ba695b0456c20 Mon Sep 17 00:00:00 2001 From: Marco Edoardo Santimaria Date: Fri, 20 Feb 2026 11:31:11 +0000 Subject: [PATCH 1/5] Added toml configuration to enable monitors --- capiocl/configuration.h | 4 ++++ src/Engine.cpp | 23 +++++++++++++++++++++-- src/configuration.cpp | 15 +++++++++++---- src/defaults.cpp | 8 +++++++- tests/tomls/sample1.toml | 4 ++++ 5 files changed, 47 insertions(+), 7 deletions(-) diff --git a/capiocl/configuration.h b/capiocl/configuration.h index 3a00cc7..58361d2 100644 --- a/capiocl/configuration.h +++ b/capiocl/configuration.h @@ -21,10 +21,14 @@ struct capiocl::configuration::defaults { static ConfigurationEntry DEFAULT_MONITOR_MCAST_PORT; /// @brief Multicast monitor delay before following operation static ConfigurationEntry DEFAULT_MONITOR_MCAST_DELAY; + /// @brief Enable multicast monitor by default + static ConfigurationEntry DEFAULT_MONITOR_MCAST_ENABLED; /// @brief Multicast monitor homenode IP static ConfigurationEntry DEFAULT_MONITOR_HOMENODE_IP; /// @brief Multicast monitor homenode PORT static ConfigurationEntry DEFAULT_MONITOR_HOMENODE_PORT; + /// @brief Enable File system monitor by default + static ConfigurationEntry DEFAULT_MONITOR_FS_ENABLED; }; /// @brief Load configuration and store it from a CAPIO-CL TOML configuration file diff --git a/src/Engine.cpp b/src/Engine.cpp index 0f0e7e2..b55b6a1 100644 --- a/src/Engine.cpp +++ b/src/Engine.cpp @@ -762,8 +762,27 @@ bool capiocl::engine::Engine::operator==(const capiocl::engine::Engine &other) c void capiocl::engine::Engine::loadConfiguration(const std::string &path) { configuration.load(path); - monitor.registerMonitorBackend(new monitor::MulticastMonitor(configuration)); - monitor.registerMonitorBackend(new monitor::FileSystemMonitor()); + std::string multicast_monitor_enabled, fs_monitor_enabled; + + try { + configuration.getParameter("monitor.mcast.enabled", &multicast_monitor_enabled); + } catch (...) { + multicast_monitor_enabled = "false"; + } + + if (multicast_monitor_enabled == "true") { + monitor.registerMonitorBackend(new monitor::MulticastMonitor(configuration)); + } + + try { + configuration.getParameter("monitor.filesystem.enabled", &fs_monitor_enabled); + } catch (...) { + fs_monitor_enabled = "false"; + } + + if (fs_monitor_enabled == "true") { + monitor.registerMonitorBackend(new monitor::FileSystemMonitor()); + } } void capiocl::engine::Engine::useDefaultConfiguration() { diff --git a/src/configuration.cpp b/src/configuration.cpp index 39d96fc..c5bfb59 100644 --- a/src/configuration.cpp +++ b/src/configuration.cpp @@ -5,8 +5,9 @@ #include "capiocl/printer.h" #include "toml++/toml.hpp" -void flatten_table(const toml::table &tbl, std::unordered_map &map, - const std::string &prefix = "") { +void load_config_to_memory(const toml::table &tbl, + std::unordered_map &map, + const std::string &prefix = "") { for (const auto &[key, value] : tbl) { std::string full_key; if (prefix.empty()) { @@ -16,10 +17,12 @@ void flatten_table(const toml::table &tbl, std::unordered_mapget(); + } else if (value.is_boolean()) { + map[full_key] = value.as_boolean()->get() ? "true" : "false"; } else { map[full_key] = std::to_string(value.as_integer()->get()); } @@ -33,6 +36,8 @@ capiocl::configuration::CapioClConfiguration::CapioClConfiguration() { this->set(defaults::DEFAULT_MONITOR_HOMENODE_IP); this->set(defaults::DEFAULT_MONITOR_HOMENODE_PORT); this->set(defaults::DEFAULT_MONITOR_MCAST_DELAY); + this->set(defaults::DEFAULT_MONITOR_FS_ENABLED); + this->set(defaults::DEFAULT_MONITOR_MCAST_ENABLED); } void capiocl::configuration::CapioClConfiguration::set(const std::string &key, std::string value) { @@ -54,7 +59,9 @@ void capiocl::configuration::CapioClConfiguration::load(const std::filesystem::p } catch (const toml::parse_error &err) { throw CapioClConfigurationException(err.what()); } - flatten_table(tbl, config); + + // copy into the local configuration the parameter from the toml config file + load_config_to_memory(tbl, config); } void capiocl::configuration::CapioClConfiguration::getParameter(const std::string &key, diff --git a/src/defaults.cpp b/src/defaults.cpp index 64d357f..b27d922 100644 --- a/src/defaults.cpp +++ b/src/defaults.cpp @@ -1,4 +1,4 @@ -#include "capiocl//configuration.h" +#include "capiocl/configuration.h" ConfigurationEntry capiocl::configuration::defaults::DEFAULT_MONITOR_MCAST_IP{ "monitor.mcast.commit.ip", "224.224.224.1"}; @@ -14,3 +14,9 @@ ConfigurationEntry capiocl::configuration::defaults::DEFAULT_MONITOR_HOMENODE_IP ConfigurationEntry capiocl::configuration::defaults::DEFAULT_MONITOR_HOMENODE_PORT{ "monitor.mcast.homenode.port", "12345"}; + +ConfigurationEntry capiocl::configuration::defaults::DEFAULT_MONITOR_MCAST_ENABLED{ + "monitor.mcast.enabled", "true"}; + +ConfigurationEntry capiocl::configuration::defaults::DEFAULT_MONITOR_FS_ENABLED{ + "monitor.filesystem.enabled", "true"}; \ No newline at end of file diff --git a/tests/tomls/sample1.toml b/tests/tomls/sample1.toml index b8e486f..6098bed 100644 --- a/tests/tomls/sample1.toml +++ b/tests/tomls/sample1.toml @@ -1,5 +1,9 @@ +[monitor.filesystem] +enabled = true + [monitor.mcast] delay_ms = 300 +enabled = true [monitor.mcast.commit] ip = "224.224.224.3" From c188011507ed830326928e0b39faeb997be35733 Mon Sep 17 00:00:00 2001 From: = <=> Date: Sat, 21 Feb 2026 12:04:29 +0000 Subject: [PATCH 2/5] tests --- src/configuration.cpp | 8 +++++++- tests/cpp/test_configuration.hpp | 8 ++++++++ tests/tomls/sample1.toml | 2 +- tests/tomls/sample2.toml | 10 ++++++++++ 4 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 tests/tomls/sample2.toml diff --git a/src/configuration.cpp b/src/configuration.cpp index c5bfb59..641f91a 100644 --- a/src/configuration.cpp +++ b/src/configuration.cpp @@ -22,7 +22,11 @@ void load_config_to_memory(const toml::table &tbl, if (value.is_string()) { map[full_key] = value.as_string()->get(); } else if (value.is_boolean()) { - map[full_key] = value.as_boolean()->get() ? "true" : "false"; + if (value.as_boolean()->get()) { + map[full_key] = "true"; + } else { + map[full_key] = "false"; + } } else { map[full_key] = std::to_string(value.as_integer()->get()); } @@ -49,6 +53,8 @@ void capiocl::configuration::CapioClConfiguration::set(const ConfigurationEntry } void capiocl::configuration::CapioClConfiguration::load(const std::filesystem::path &path) { + config.clear(); + if (path.empty()) { throw CapioClConfigurationException("Empty pathname!"); } diff --git a/tests/cpp/test_configuration.hpp b/tests/cpp/test_configuration.hpp index 18a94c6..0fd6d34 100644 --- a/tests/cpp/test_configuration.hpp +++ b/tests/cpp/test_configuration.hpp @@ -38,4 +38,12 @@ TEST(CONFIGURATION_SUITE_NAME, TestFailureParsingTOML) { capiocl::configuration::CapioClConfigurationException); } +TEST(CONFIGURATION_SUITE_NAME, testNoBackendLoaded) { + capiocl::engine::Engine engine(false); + engine.loadConfiguration("/tmp/capio_cl_tomls/sample2.toml"); + + EXPECT_FALSE(engine.isCommitted("test")); + +} + #endif // CAPIO_CL_TEST_CONFIGURATION_HPP diff --git a/tests/tomls/sample1.toml b/tests/tomls/sample1.toml index 6098bed..da25aca 100644 --- a/tests/tomls/sample1.toml +++ b/tests/tomls/sample1.toml @@ -1,5 +1,5 @@ [monitor.filesystem] -enabled = true +enabled = false [monitor.mcast] delay_ms = 300 diff --git a/tests/tomls/sample2.toml b/tests/tomls/sample2.toml new file mode 100644 index 0000000..b8e486f --- /dev/null +++ b/tests/tomls/sample2.toml @@ -0,0 +1,10 @@ +[monitor.mcast] +delay_ms = 300 + +[monitor.mcast.commit] +ip = "224.224.224.3" +port = 11223 + +[monitor.mcast.homenode] +ip = "224.224.224.4" +port = 22334 From 1754ecde42f9b8492cf46a154f76318b1edcd3f8 Mon Sep 17 00:00:00 2001 From: = <=> Date: Sat, 21 Feb 2026 12:13:00 +0000 Subject: [PATCH 3/5] tests --- capiocl/configuration.h | 8 ++++++-- src/Engine.cpp | 14 +++++++++----- src/configuration.cpp | 4 +--- tests/tomls/sample1.toml | 2 +- 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/capiocl/configuration.h b/capiocl/configuration.h index 58361d2..2c56d21 100644 --- a/capiocl/configuration.h +++ b/capiocl/configuration.h @@ -51,15 +51,19 @@ class capiocl::configuration::CapioClConfiguration { void set(const ConfigurationEntry &entry); public: - explicit CapioClConfiguration(); ~CapioClConfiguration() = default; /** - * Load a configuiration from a TOML file + * Load a configuration from a TOML file * @param path */ void load(const std::filesystem::path &path); + /** + * Load default values for the configuration + */ + void loadDefaults(); + /** * Get a string value * @param key key of option to get diff --git a/src/Engine.cpp b/src/Engine.cpp index b55b6a1..b333d1e 100644 --- a/src/Engine.cpp +++ b/src/Engine.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include "capiocl.hpp" @@ -772,6 +773,8 @@ void capiocl::engine::Engine::loadConfiguration(const std::string &path) { if (multicast_monitor_enabled == "true") { monitor.registerMonitorBackend(new monitor::MulticastMonitor(configuration)); + } else { + printer::print(printer::CLI_LEVEL_WARNING, "Skipping registration of MulticastMonitor"); } try { @@ -782,17 +785,18 @@ void capiocl::engine::Engine::loadConfiguration(const std::string &path) { if (fs_monitor_enabled == "true") { monitor.registerMonitorBackend(new monitor::FileSystemMonitor()); + } else { + printer::print(printer::CLI_LEVEL_WARNING, "Skipping registration of FileSystemMonitor"); } } void capiocl::engine::Engine::useDefaultConfiguration() { + configuration.loadDefaults(); - const auto def_config = configuration::CapioClConfiguration(); - - monitor.registerMonitorBackend(new monitor::MulticastMonitor(def_config)); + // TODO: add a vector with registered instances of backends to avoid multiple instantiations + monitor.registerMonitorBackend(new monitor::MulticastMonitor(configuration)); monitor.registerMonitorBackend(new monitor::FileSystemMonitor()); } void capiocl::engine::Engine::startApiServer(const std::string &address, const int port) { - webapi_server = std::unique_ptr( - new webapi::CapioClWebApiServer(this, address, port)); + webapi_server = std::make_unique(this, address, port); } \ No newline at end of file diff --git a/src/configuration.cpp b/src/configuration.cpp index 641f91a..abc3324 100644 --- a/src/configuration.cpp +++ b/src/configuration.cpp @@ -34,7 +34,7 @@ void load_config_to_memory(const toml::table &tbl, } } -capiocl::configuration::CapioClConfiguration::CapioClConfiguration() { +void capiocl::configuration::CapioClConfiguration::loadDefaults() { this->set(defaults::DEFAULT_MONITOR_MCAST_IP); this->set(defaults::DEFAULT_MONITOR_MCAST_PORT); this->set(defaults::DEFAULT_MONITOR_HOMENODE_IP); @@ -53,8 +53,6 @@ void capiocl::configuration::CapioClConfiguration::set(const ConfigurationEntry } void capiocl::configuration::CapioClConfiguration::load(const std::filesystem::path &path) { - config.clear(); - if (path.empty()) { throw CapioClConfigurationException("Empty pathname!"); } diff --git a/tests/tomls/sample1.toml b/tests/tomls/sample1.toml index da25aca..6098bed 100644 --- a/tests/tomls/sample1.toml +++ b/tests/tomls/sample1.toml @@ -1,5 +1,5 @@ [monitor.filesystem] -enabled = false +enabled = true [monitor.mcast] delay_ms = 300 From 5cc330a28d1ce044aee1e6be941c9462475a9b0f Mon Sep 17 00:00:00 2001 From: = <=> Date: Sat, 21 Feb 2026 12:46:52 +0000 Subject: [PATCH 4/5] tests --- tests/cpp/test_configuration.hpp | 12 ++++++++++++ tests/tomls/sample3.toml | 4 ++++ 2 files changed, 16 insertions(+) create mode 100644 tests/tomls/sample3.toml diff --git a/tests/cpp/test_configuration.hpp b/tests/cpp/test_configuration.hpp index 0fd6d34..23731ec 100644 --- a/tests/cpp/test_configuration.hpp +++ b/tests/cpp/test_configuration.hpp @@ -43,7 +43,19 @@ TEST(CONFIGURATION_SUITE_NAME, testNoBackendLoaded) { engine.loadConfiguration("/tmp/capio_cl_tomls/sample2.toml"); EXPECT_FALSE(engine.isCommitted("test")); +} + +TEST(CONFIGURATION_SUITE_NAME, testNoBackendLoadedWithExplicitNoLoadOption) { + capiocl::configuration::CapioClConfiguration config; + config.load("/tmp/capio_cl_tomls/sample3.toml"); + + std::string value; + config.getParameter("monitor.multicast.enabled", &value); + EXPECT_TRUE("false" == value); + value = ""; + config.getParameter("monitor.filesystem.enabled", &value); + EXPECT_TRUE("false" == value); } #endif // CAPIO_CL_TEST_CONFIGURATION_HPP diff --git a/tests/tomls/sample3.toml b/tests/tomls/sample3.toml new file mode 100644 index 0000000..39bd6fb --- /dev/null +++ b/tests/tomls/sample3.toml @@ -0,0 +1,4 @@ +[monitor] +filesystem.enabled = false +multicast.enabled = false + From ee0a635664795c8994e85b9e50e85e4f90421274 Mon Sep 17 00:00:00 2001 From: = <=> Date: Sat, 21 Feb 2026 13:12:00 +0000 Subject: [PATCH 5/5] documentation --- doxygen/configuration.md | 22 +++++++++++++++------- tests/cpp/test_configuration.hpp | 2 +- tests/tomls/sample3.toml | 3 +-- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/doxygen/configuration.md b/doxygen/configuration.md index 96d49a2..dd929c6 100644 --- a/doxygen/configuration.md +++ b/doxygen/configuration.md @@ -18,13 +18,15 @@ The configuration file uses a structured namespace under the top-level table `mo Available configuration parameters: -| Key | Type | Default | Description | -|----------------------------------|----------|----------------|----------------------------------------------------------------------------------------------| -| `monitor.mcast.commit.ip` | string | `224.224.224.1` | Multicast IP address used for commit messages | -| `monitor.mcast.commit.port` | integer | `12345` | UDP port for commit messages | -| `monitor.mcast.delay_ms` | integer | `300` | Artificial delay (in milliseconds) inserted before sending multicast messages. Useful for debugging or simulating slower networks. | -| `monitor.mcast.homenode.ip` | string | `224.224.224.2` | IP address of the home node for monitoring operations | -| `monitor.mcast.homenode.port` | integer | `12345` | Port associated with the home node monitoring endpoint | +| Key | Type | Default | Description | +|-------------------------------|---------|-----------------|------------------------------------------------------------------------------------------------------------------------------------| +| `monitor.filesystem.enabled` | boolean | `false` | Enable FileSystem commit monitor | +| `monitor.mcast.enabled` | boolean | `false` | Enable Multicast commit monitor | +| `monitor.mcast.commit.ip` | string | `224.224.224.1` | Multicast IP address used for commit messages | +| `monitor.mcast.commit.port` | integer | `12345` | UDP port for commit messages | +| `monitor.mcast.delay_ms` | integer | `300` | Artificial delay (in milliseconds) inserted before sending multicast messages. Useful for debugging or simulating slower networks. | +| `monitor.mcast.homenode.ip` | string | `224.224.224.2` | IP address of the home node for monitoring operations | +| `monitor.mcast.homenode.port` | integer | `12345` | Port associated with the home node monitoring endpoint | --- @@ -34,7 +36,10 @@ Below is a complete example of a `config.toml` file: # Example CAPIO-CL TOML configuration + monitor.filesystem.enabled = true + [monitor.mcast] + enabled = true # Multicast settings for commit messages commit.ip = "224.224.224.1" @@ -52,10 +57,12 @@ Below is a complete example of a `config.toml` file: ## How CAPIO-CL Uses These Settings ### `commit.ip` and `commit.port` + These fields define where CAPIO-CL sends **commit broadcast messages**. Commit messages are used for consistency coordination across distributed nodes. ### `delay_ms` + A small configurable delay may help with: - debugging message-ordering issues, @@ -65,5 +72,6 @@ A small configurable delay may help with: A value of `0` means no delay. ### `homenode.ip` and `homenode.port` + These define the **central monitoring endpoint** (the “home node”). CAPIO-CL uses this endpoint to coordinate monitoring metadata and cluster-wide communication. diff --git a/tests/cpp/test_configuration.hpp b/tests/cpp/test_configuration.hpp index 23731ec..d752e67 100644 --- a/tests/cpp/test_configuration.hpp +++ b/tests/cpp/test_configuration.hpp @@ -50,7 +50,7 @@ TEST(CONFIGURATION_SUITE_NAME, testNoBackendLoadedWithExplicitNoLoadOption) { config.load("/tmp/capio_cl_tomls/sample3.toml"); std::string value; - config.getParameter("monitor.multicast.enabled", &value); + config.getParameter("monitor.mcast.enabled", &value); EXPECT_TRUE("false" == value); value = ""; diff --git a/tests/tomls/sample3.toml b/tests/tomls/sample3.toml index 39bd6fb..ee66795 100644 --- a/tests/tomls/sample3.toml +++ b/tests/tomls/sample3.toml @@ -1,4 +1,3 @@ [monitor] filesystem.enabled = false -multicast.enabled = false - +mcast.enabled = false