Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions capiocl/configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -47,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
Expand Down
22 changes: 15 additions & 7 deletions doxygen/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |

---

Expand All @@ -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"
Expand All @@ -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,
Expand All @@ -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.
37 changes: 30 additions & 7 deletions src/Engine.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <algorithm>
#include <fnmatch.h>
#include <memory>
#include <sstream>

#include "capiocl.hpp"
Expand Down Expand Up @@ -762,18 +763,40 @@ 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));
} else {
printer::print(printer::CLI_LEVEL_WARNING, "Skipping registration of MulticastMonitor");
}

try {
configuration.getParameter("monitor.filesystem.enabled", &fs_monitor_enabled);
} catch (...) {
fs_monitor_enabled = "false";
}

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<webapi::CapioClWebApiServer>(
new webapi::CapioClWebApiServer(this, address, port));
webapi_server = std::make_unique<webapi::CapioClWebApiServer>(this, address, port);
}
21 changes: 16 additions & 5 deletions src/configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
#include "capiocl/printer.h"
#include "toml++/toml.hpp"

void flatten_table(const toml::table &tbl, std::unordered_map<std::string, std::string> &map,
const std::string &prefix = "") {
void load_config_to_memory(const toml::table &tbl,
std::unordered_map<std::string, std::string> &map,
const std::string &prefix = "") {
for (const auto &[key, value] : tbl) {
std::string full_key;
if (prefix.empty()) {
Expand All @@ -16,23 +17,31 @@ void flatten_table(const toml::table &tbl, std::unordered_map<std::string, std::
}

if (value.is_table()) {
flatten_table(*value.as_table(), map, full_key);
load_config_to_memory(*value.as_table(), map, full_key);
} else {
if (value.is_string()) {
map[full_key] = value.as_string()->get();
} else if (value.is_boolean()) {
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());
}
}
}
}

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);
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) {
Expand All @@ -54,7 +63,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,
Expand Down
8 changes: 7 additions & 1 deletion src/defaults.cpp
Original file line number Diff line number Diff line change
@@ -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"};
Expand All @@ -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"};
20 changes: 20 additions & 0 deletions tests/cpp/test_configuration.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,24 @@ 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"));
}

TEST(CONFIGURATION_SUITE_NAME, testNoBackendLoadedWithExplicitNoLoadOption) {
capiocl::configuration::CapioClConfiguration config;
config.load("/tmp/capio_cl_tomls/sample3.toml");

std::string value;
config.getParameter("monitor.mcast.enabled", &value);
EXPECT_TRUE("false" == value);
value = "";

config.getParameter("monitor.filesystem.enabled", &value);
EXPECT_TRUE("false" == value);
}

#endif // CAPIO_CL_TEST_CONFIGURATION_HPP
4 changes: 4 additions & 0 deletions tests/tomls/sample1.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
[monitor.filesystem]
enabled = true

[monitor.mcast]
delay_ms = 300
enabled = true

[monitor.mcast.commit]
ip = "224.224.224.3"
Expand Down
10 changes: 10 additions & 0 deletions tests/tomls/sample2.toml
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions tests/tomls/sample3.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[monitor]
filesystem.enabled = false
mcast.enabled = false
Loading