From 0e073e3c93b936416fa3b1585cd4534abaeb0f68 Mon Sep 17 00:00:00 2001 From: Marco Edoardo Santimaria Date: Tue, 9 Jun 2026 14:01:40 +0200 Subject: [PATCH 01/16] migration WIP --- CMakeLists.txt | 34 +++++++++++++----- capiocl/printer.h | 42 ---------------------- src/Engine.cpp | 74 +++++++++++++++++++------------------- src/Monitor.cpp | 6 ++-- src/Parser.cpp | 21 ++++++----- src/Serializer.cpp | 10 +++--- src/configuration.cpp | 5 +-- src/monitors/Multicast.cpp | 2 +- src/parsers/v1.1.cpp | 27 ++++++++------ src/parsers/v1.cpp | 25 +++++++------ src/serializers/v1.1.cpp | 12 ++++--- src/serializers/v1.cpp | 12 ++++--- 12 files changed, 135 insertions(+), 135 deletions(-) delete mode 100644 capiocl/printer.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 6ebe30f..c82e2aa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -57,11 +57,27 @@ FetchContent_Declare( GIT_TAG v1.8.1 ) +FetchContent_Declare( + calf + GIT_REPOSITORY https://github.com/High-Performance-IO/calf.git + GIT_TAG main +) + +# JSONCONS build flags set(JSONCONS_BUILD_TESTS OFF CACHE BOOL "" FORCE) set(JSONCONS_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE) set(JSONCONS_BUILD_FUZZERS OFF CACHE BOOL "" FORCE) -FetchContent_MakeAvailable(jsoncons tomlplusplus) +# CALF build flags +if (CMAKE_BUILD_TYPE STREQUAL "Debug") + set(CALF_LOG ON CACHE BOOL "" FORCE) +else () + set(CALF_LOG OFF CACHE BOOL "" FORCE) +endif () +set(CALF_BUILD_STL ON CACHE BOOL "" FORCE) +set(CALF_BUILD_SYSCALL OFF CACHE BOOL "" FORCE) + +FetchContent_MakeAvailable(jsoncons tomlplusplus calf) if (BUILD_PYTHON_BINDINGS) FetchContent_Declare( @@ -139,11 +155,11 @@ target_include_directories(libcapio_cl PUBLIC target_link_libraries(libcapio_cl PUBLIC) target_link_libraries(libcapio_cl PRIVATE - tomlplusplus::tomlplusplus + tomlplusplus::tomlplusplus calf::stl ) find_library(LIBANL anl) -if(LIBANL) +if (LIBANL) target_link_libraries(libcapio_cl PRIVATE ${LIBANL}) endif () @@ -202,7 +218,7 @@ if (CAPIO_CL_BUILD_TESTS) CURL::libcurl ) - if(LIBANL) + if (LIBANL) target_link_libraries(CAPIO_CL_tests PRIVATE ${LIBANL}) endif () @@ -296,11 +312,11 @@ if (ENABLE_COVERAGE_PIPELINE) COMMAND ${LCOV_BIN} --remove ${COVERAGE_INFO} - "*jsoncons*" - "/usr/include/*" - "*googletest*" - "*tests/*" - ${COVERAGE_REMOVE_PATTERNS} + "*jsoncons*" + "/usr/include/*" + "*googletest*" + "*tests/*" + ${COVERAGE_REMOVE_PATTERNS} --ignore-errors unused --ignore-errors inconsistent --output-file ${COVERAGE_INFO} diff --git a/capiocl/printer.h b/capiocl/printer.h deleted file mode 100644 index 1069bf6..0000000 --- a/capiocl/printer.h +++ /dev/null @@ -1,42 +0,0 @@ -#ifndef CAPIO_CL_PRINTER_H -#define CAPIO_CL_PRINTER_H -#include -#include - -#ifndef HOST_NAME_MAX -#define HOST_NAME_MAX 1024 -#endif - -/// @brief Namespace containing the CAPIO-CL print utilities -namespace capiocl::printer { - -/// @brief CLI print constant -constexpr char CLI_LEVEL_INFO[] = "[\033[1;32mCAPIO-CL\033[0m"; -/// @brief CLI print constant -constexpr char CLI_LEVEL_WARNING[] = "[\033[1;33mCAPIO-CL\033[0m"; -/// @brief CLI print constant -constexpr char CLI_LEVEL_ERROR[] = "[\033[1;31mCAPIO-CL\033[0m"; -/// @brief CLI print constant -constexpr char CLI_LEVEL_JSON[] = "[\033[1;34mCAPIO-CL\033[0m"; - -/** - * Print a message to standard out. Used to log messages related to the CAPIO-CL Engine - * @param message_type Type of message to print. - * @param message_line - */ -inline void print(const std::string &message_type = "", const std::string &message_line = "") { - static std::string *node_name = nullptr; - if (node_name == nullptr) { - node_name = new std::string(HOST_NAME_MAX, ' '); // LCOV_EXCL_LINE - gethostname(node_name->data(), HOST_NAME_MAX); - } - if (message_type.empty()) { - std::cout << std::endl; - } else { - std::cout << message_type << " " << node_name->c_str() << "] " << message_line << std::endl - << std::flush; - } -} -} // namespace capiocl::printer - -#endif // CAPIO_CL_PRINTER_H \ No newline at end of file diff --git a/src/Engine.cpp b/src/Engine.cpp index d6951fc..0bbdfb0 100644 --- a/src/Engine.cpp +++ b/src/Engine.cpp @@ -3,11 +3,11 @@ #include #include +#include "calf/StdOutLogger.h" #include "capiocl.hpp" #include "capiocl/configuration.h" #include "capiocl/engine.h" #include "capiocl/monitor.h" -#include "capiocl/printer.h" /// @brief Class to implement a shared mutex lock guard template class shared_lock_guard { @@ -26,47 +26,48 @@ template class shared_lock_guard { }; void capiocl::engine::Engine::print() const { - + UPDATE_CALF_CLI_CONFIG("capiocl::Engine", workflow_name); // First message - printer::print(printer::CLI_LEVEL_JSON, ""); - printer::print(printer::CLI_LEVEL_JSON, "Composition of expected CAPIO FS: "); + CALF_PRINT_COLOR(CALF_CLI_LEVEL_INFO, ""); + CALF_PRINT_COLOR(CALF_CLI_LEVEL_INFO, "Composition of expected CAPIO FS: "); // Table header lines - printer::print(printer::CLI_LEVEL_JSON, "*" + std::string(134, '=') + "*"); - - printer::print(printer::CLI_LEVEL_JSON, "|" + std::string(134, ' ') + "|"); + CALF_PRINT_COLOR(CALF_CLI_LEVEL_INFO, "*%s*", std::string(134, '=').c_str()); + CALF_PRINT_COLOR(CALF_CLI_LEVEL_INFO, "|%s|", std::string(134, ' ').c_str()); - { - std::ostringstream oss; - oss << "| Parsed configuration file for workflow: \033[1;36m" << workflow_name - << std::setw(94 - workflow_name.length()) << "\033[0m |"; - printer::print(printer::CLI_LEVEL_JSON, oss.str()); - } + CALF_PRINT_COLOR(CALF_CLI_LEVEL_INFO, + "| Parsed configuration file for workflow: \033[1;36m %s%s \033[0m |", + workflow_name.c_str(), std::string(94 - workflow_name.length(), ' ').c_str()); - printer::print(printer::CLI_LEVEL_JSON, "|" + std::string(134, ' ') + "|"); + CALF_PRINT_COLOR(CALF_CLI_LEVEL_INFO, "|%s|", std::string(134, ' ').c_str()); - std::string msg = "| File color legend: \033[48;5;034m \033[0m File stored in memory"; - msg += std::string(82, ' ') + "|"; - printer::print(printer::CLI_LEVEL_JSON, msg); + CALF_PRINT_COLOR( + CALF_CLI_LEVEL_INFO, + "| File color legend: \033[48;5;034m \033[0m File stored in memory%s|", + std::string(82, ' ').c_str()); - printer::print( - printer::CLI_LEVEL_JSON, // LCOV_EXCL_LINE - "| \033[48;5;172m \033[0m File stored on file system" + - std::string(77, ' ') + "|"); + CALF_PRINT_COLOR( + CALF_CLI_LEVEL_INFO, + "| \033[48;5;172m \033[0m File stored on file system%s|", + std::string(77, ' ').c_str()); - printer::print(printer::CLI_LEVEL_JSON, "|" + std::string(134, '=') + "|"); + CALF_PRINT_COLOR(CALF_CLI_LEVEL_INFO, "|%s|", std::string(134, ' ').c_str()); - std::string line = "|======|===================|===================|===================="; - line += "|====================|============|===========|=========|==========|"; - printer::print(printer::CLI_LEVEL_JSON, line); + CALF_PRINT_COLOR( + CALF_CLI_LEVEL_INFO, "|%s|%s|%s|%s|%s|%s|%s|%s|%s|", std::string(6, '=').c_str(), + std::string(19, '=').c_str(), std::string(19, '=').c_str(), std::string(20, '=').c_str(), + std::string(20, '=').c_str(), std::string(12, '=').c_str(), std::string(11, '=').c_str(), + std::string(9, '=').c_str(), std::string(10, '=').c_str()); - line = "| Kind | Filename | Producer step | Consumer step | "; - line += "Commit Rule | Fire Rule | Permanent | Exclude | n_files |"; - printer::print(printer::CLI_LEVEL_JSON, line); + CALF_PRINT_COLOR(CALF_CLI_LEVEL_INFO, + "| Kind | Filename | Producer step | Consumer step | " + "Commit Rule | Fire Rule | Permanent | Exclude | n_files |"); - line = "|======|===================|===================|====================|========"; - line += "============|============|===========|=========|==========|"; - printer::print(printer::CLI_LEVEL_JSON, line); + CALF_PRINT_COLOR( + CALF_CLI_LEVEL_INFO, "|%s|%s|%s|%s|%s|%s|%s|%s|%s|", std::string(6, '=').c_str(), + std::string(19, '=').c_str(), std::string(19, '=').c_str(), std::string(20, '=').c_str(), + std::string(20, '=').c_str(), std::string(12, '=').c_str(), std::string(11, '=').c_str(), + std::string(9, '=').c_str(), std::string(10, '=').c_str()); // Iterate over _locations for (auto &itm : _capio_cl_entries) { @@ -136,13 +137,13 @@ void capiocl::engine::Engine::print() const { line << std::setfill(' ') << std::setw(10) << "|" << std::setw(11) << "|"; } - printer::print(printer::CLI_LEVEL_JSON, line.str()); + CALF_PRINT_COLOR(CALF_CLI_LEVEL_INFO, "%s", line.str().c_str()); } - printer::print(printer::CLI_LEVEL_JSON, "*" + std::string(134, '~') + "*"); + CALF_PRINT_COLOR(CALF_CLI_LEVEL_INFO, "*%s*", std::string(134, '~').c_str()); } - printer::print(printer::CLI_LEVEL_JSON, ""); + CALF_PRINT_COLOR(CALF_CLI_LEVEL_INFO, ""); } capiocl::engine::Engine::Engine(const bool use_default_settings) { @@ -899,6 +900,7 @@ bool capiocl::engine::Engine::operator==(const Engine &other) const { return true; } void capiocl::engine::Engine::loadConfiguration(const std::string &path) { + UPDATE_CALF_CLI_CONFIG("capiocl::Engine", workflow_name); configuration.load(path); std::string multicast_monitor_enabled, fs_monitor_enabled; @@ -912,7 +914,7 @@ 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"); + CALF_PRINT_COLOR(CALF_CLI_LEVEL_WARNING, "Skipping registration of MulticastMonitor"); } try { @@ -924,7 +926,7 @@ 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"); + CALF_PRINT_COLOR(CALF_CLI_LEVEL_WARNING, "Skipping registration of FileSystemMonitor"); } } void capiocl::engine::Engine::useDefaultConfiguration() { diff --git a/src/Monitor.cpp b/src/Monitor.cpp index 75e9f89..c9eaa81 100644 --- a/src/Monitor.cpp +++ b/src/Monitor.cpp @@ -1,9 +1,11 @@ #include "capiocl/monitor.h" #include "capiocl.hpp" -#include "capiocl/printer.h" + +#include "calf/StdOutLogger.h" capiocl::monitor::MonitorException::MonitorException(const std::string &msg) : message(msg) { - printer::print(printer::CLI_LEVEL_ERROR, msg); + UPDATE_CALF_CLI_CONFIG("capiocl::MonitorException", ""); + CALF_PRINT_COLOR(CALF_CLI_LEVEL_ERROR, "%s", msg.c_str()); } bool capiocl::monitor::Monitor::isCommitted(const std::filesystem::path &path) const { diff --git a/src/Parser.cpp b/src/Parser.cpp index cc612ea..99802b7 100644 --- a/src/Parser.cpp +++ b/src/Parser.cpp @@ -1,13 +1,14 @@ #include #include +#include "calf/StdOutLogger.h" #include "capiocl.hpp" #include "capiocl/engine.h" #include "capiocl/parser.h" -#include "capiocl/printer.h" capiocl::parser::ParserException::ParserException(const std::string &msg) : message(msg) { - printer::print(printer::CLI_LEVEL_ERROR, msg); + UPDATE_CALF_CLI_CONFIG("capiocl::Parser", ""); + CALF_PRINT_COLOR(CALF_CLI_LEVEL_ERROR, "%s", msg.c_str()); } jsoncons::jsonschema::json_schema @@ -17,6 +18,7 @@ capiocl::parser::Parser::loadSchema(const char *data) { std::filesystem::path capiocl::parser::Parser::resolve(std::filesystem::path path, const std::filesystem::path &prefix) { + UPDATE_CALF_CLI_CONFIG("capiocl::Parser", ""); if (prefix.empty()) { return path; } @@ -25,9 +27,9 @@ std::filesystem::path capiocl::parser::Parser::resolve(std::filesystem::path pat return path; } - auto resolved = prefix / path; - const auto msg = "Path : " + path.string() + " IS RELATIVE! Resolved to: " + resolved.string(); - printer::print(printer::CLI_LEVEL_WARNING, msg); + auto resolved = prefix / path; + CALF_PRINT_COLOR(CALF_CLI_LEVEL_WARNING, "Path %s IS RELATIVE! Resolved to: %s", path.c_str(), + resolved.c_str()); return resolved; } @@ -38,7 +40,8 @@ void capiocl::parser::Parser::validate_json(const jsoncons::json &doc, const cha // throws jsoncons::jsonschema::validation_error on failure schema.validate(doc); } catch (const jsoncons::jsonschema::validation_error &e) { - printer::print(printer::CLI_LEVEL_ERROR, e.what()); + UPDATE_CALF_CLI_CONFIG("capiocl::Parser", ""); + CALF_PRINT_COLOR(CALF_CLI_LEVEL_ERROR, "%s", e.what()); throw ParserException("JSON validation failed!"); } } @@ -66,8 +69,10 @@ capiocl::engine::Engine *capiocl::parser::Parser::parse(const std::filesystem::p } file.close(); - printer::print(printer::CLI_LEVEL_INFO, - "Parsing CAPIO-CL config file for version: " + capio_cl_release); + + UPDATE_CALF_CLI_CONFIG("capiocl::Parser", ""); + CALF_PRINT_COLOR(CALF_CLI_LEVEL_INFO, "Parsing CAPIO-CL config file for version: %s", + capio_cl_release.c_str()); if (capio_cl_release == CAPIO_CL_VERSION::V1) { return available_parsers::parse_v1(source, resolve_prefix, store_only_in_memory); diff --git a/src/Serializer.cpp b/src/Serializer.cpp index 3af869e..ef22fe6 100644 --- a/src/Serializer.cpp +++ b/src/Serializer.cpp @@ -2,19 +2,20 @@ #include #include +#include "calf/StdOutLogger.h" #include "capiocl.hpp" #include "capiocl/engine.h" -#include "capiocl/printer.h" #include "capiocl/serializer.h" void capiocl::serializer::Serializer::dump(const engine::Engine &engine, const std::filesystem::path &filename, const std::string &version) { + UPDATE_CALF_CLI_CONFIG("capiocl::Serializer", engine.getWorkflowName()); if (version == CAPIO_CL_VERSION::V1) { - printer::print(printer::CLI_LEVEL_INFO, "Serializing engine with V1 specification"); + CALF_PRINT_COLOR(CALF_CLI_LEVEL_INFO, "Serializing engine with V1 specification"); available_serializers::serialize_v1(engine, filename); } else if (version == CAPIO_CL_VERSION::V1_1) { - printer::print(printer::CLI_LEVEL_INFO, "Serializing engine with V1.1 specification"); + CALF_PRINT_COLOR(CALF_CLI_LEVEL_INFO, "Serializing engine with V1.1 specification"); available_serializers::serialize_v1_1(engine, filename); } else { const auto message = "No serializer available for CAPIO-CL version: " + version; @@ -24,5 +25,6 @@ void capiocl::serializer::Serializer::dump(const engine::Engine &engine, capiocl::serializer::SerializerException::SerializerException(const std::string &msg) : message(msg) { - printer::print(printer::CLI_LEVEL_ERROR, msg); + UPDATE_CALF_CLI_CONFIG("capiocl::Serializer", ""); + CALF_PRINT_COLOR(CALF_CLI_LEVEL_ERROR, "%s", msg.c_str()); } \ No newline at end of file diff --git a/src/configuration.cpp b/src/configuration.cpp index ad62d09..e15ab08 100644 --- a/src/configuration.cpp +++ b/src/configuration.cpp @@ -2,7 +2,7 @@ #include #include "capiocl/configuration.h" -#include "capiocl/printer.h" +#include "calf/StdOutLogger.h" #include "toml++/toml.hpp" void load_config_to_memory(const toml::table &tbl, @@ -91,5 +91,6 @@ void capiocl::configuration::CapioClConfiguration::getParameter(const std::strin capiocl::configuration::CapioClConfigurationException::CapioClConfigurationException( const std::string &msg) : message(msg) { - printer::print(printer::CLI_LEVEL_ERROR, msg); + UPDATE_CALF_CLI_CONFIG("capiocl::CapioClConfigurationException", ""); + CALF_PRINT_COLOR(CALF_CLI_LEVEL_ERROR, "%s", msg.c_str()); } \ No newline at end of file diff --git a/src/monitors/Multicast.cpp b/src/monitors/Multicast.cpp index 1f82fc3..011454a 100644 --- a/src/monitors/Multicast.cpp +++ b/src/monitors/Multicast.cpp @@ -2,10 +2,10 @@ #include #include #include +#include #include "capiocl.hpp" #include "capiocl/monitor.h" -#include "capiocl/printer.h" static std::tuple outgoing_socket_multicast(const std::string &address, const int port) { diff --git a/src/parsers/v1.1.cpp b/src/parsers/v1.1.cpp index 070dc58..c2aa0a4 100644 --- a/src/parsers/v1.1.cpp +++ b/src/parsers/v1.1.cpp @@ -1,10 +1,10 @@ #include +#include "calf/StdOutLogger.h" #include "capio_cl_json_schemas.hpp" #include "capiocl.hpp" #include "capiocl/engine.h" #include "capiocl/parser.h" -#include "capiocl/printer.h" capiocl::engine::Engine * capiocl::parser::Parser::available_parsers::parse_v1_1(const std::filesystem::path &source, @@ -22,12 +22,15 @@ capiocl::parser::Parser::available_parsers::parse_v1_1(const std::filesystem::pa // ---- workflow name ---- workflow_name = doc["name"].as(); engine->setWorkflowName(workflow_name); - printer::print(printer::CLI_LEVEL_JSON, "Parsing configuration for workflow: " + workflow_name); + UPDATE_CALF_CLI_CONFIG("capiocl::Parser::parse_v1_1", workflow_name); + CALF_PRINT_COLOR(CALF_CLI_LEVEL_INFO, "Parsing configuration for workflow: %s", + workflow_name.c_str()); // ---- CAPIO-CL TOML CONFIGURATION ---- if (doc.contains("configuration")) { auto toml_config_path = doc["configuration"].as(); - printer::print(printer::CLI_LEVEL_JSON, "Using configuration file : " + toml_config_path); + CALF_PRINT_COLOR(CALF_CLI_LEVEL_INFO, "Using TOML configuration file: %s", + toml_config_path.c_str()); engine->loadConfiguration(toml_config_path); } else { engine->useDefaultConfiguration(); @@ -36,10 +39,10 @@ capiocl::parser::Parser::available_parsers::parse_v1_1(const std::filesystem::pa // ---- IO_Graph ---- for (const auto &app : doc["IO_Graph"].array_range()) { std::string app_name = app["name"].as(); - printer::print(printer::CLI_LEVEL_JSON, "Parsing config for app " + app_name); + CALF_PRINT_COLOR(CALF_CLI_LEVEL_INFO, "Parsing config for app: %s", app_name.c_str()); // ---- input_stream ---- - printer::print(printer::CLI_LEVEL_JSON, "Parsing input_stream for app " + app_name); + CALF_PRINT_COLOR(CALF_CLI_LEVEL_INFO, "Parsing input_stream for app: %s", app_name.c_str()); for (const auto &itm : app["input_stream"].array_range()) { auto file_path = resolve(itm.as(), resolve_prefix); engine->newFile(file_path); @@ -47,7 +50,8 @@ capiocl::parser::Parser::available_parsers::parse_v1_1(const std::filesystem::pa } // ---- output_stream ---- - printer::print(printer::CLI_LEVEL_JSON, "Parsing output_stream for app " + app_name); + CALF_PRINT_COLOR(CALF_CLI_LEVEL_INFO, "Parsing output_stream for app: %s", + app_name.c_str()); for (const auto &itm : app["output_stream"].array_range()) { auto file_path = resolve(itm.as(), resolve_prefix); engine->newFile(file_path); @@ -56,7 +60,8 @@ capiocl::parser::Parser::available_parsers::parse_v1_1(const std::filesystem::pa // ---- streaming ---- if (app.contains("streaming")) { - printer::print(printer::CLI_LEVEL_JSON, "Parsing streaming for app " + app_name); + CALF_PRINT_COLOR(CALF_CLI_LEVEL_INFO, "Parsing streaming section for app: %s", + app_name.c_str()); for (const auto &stream_item : app["streaming"].array_range()) { bool is_file = true; std::vector streaming_names; @@ -169,7 +174,7 @@ capiocl::parser::Parser::available_parsers::parse_v1_1(const std::filesystem::pa engine->setStoreFileInMemory(file_str); } } else { - printer::print(printer::CLI_LEVEL_INFO, "No MEM storage section found"); + CALF_PRINT_COLOR(CALF_CLI_LEVEL_WARNING, "No MEM storage section found"); } if (storage.contains("fs")) { @@ -178,15 +183,15 @@ capiocl::parser::Parser::available_parsers::parse_v1_1(const std::filesystem::pa engine->setStoreFileInFileSystem(file_str); } } else { - printer::print(printer::CLI_LEVEL_INFO, "No FS storage section found"); + CALF_PRINT_COLOR(CALF_CLI_LEVEL_WARNING, "No FS storage section found"); } } else { - printer::print(printer::CLI_LEVEL_INFO, "No storage section found"); + CALF_PRINT_COLOR(CALF_CLI_LEVEL_WARNING, "No STORAGE storage section found"); } // ---- Store only in memory ---- if (store_only_in_memory) { - printer::print(printer::CLI_LEVEL_INFO, "Storing all files in memory"); + CALF_PRINT_COLOR(CALF_CLI_LEVEL_INFO, "Storing all files in memory"); engine->setAllStoreInMemory(); } diff --git a/src/parsers/v1.cpp b/src/parsers/v1.cpp index af2e645..9cf1ea4 100644 --- a/src/parsers/v1.cpp +++ b/src/parsers/v1.cpp @@ -1,15 +1,16 @@ #include +#include "calf/StdOutLogger.h" #include "capio_cl_json_schemas.hpp" #include "capiocl.hpp" #include "capiocl/engine.h" #include "capiocl/parser.h" -#include "capiocl/printer.h" capiocl::engine::Engine * capiocl::parser::Parser::available_parsers::parse_v1(const std::filesystem::path &source, const std::filesystem::path &resolve_prefix, bool store_only_in_memory) { + std::string workflow_name = CAPIO_CL_DEFAULT_WF_NAME; auto engine = new engine::Engine(true); @@ -24,15 +25,17 @@ capiocl::parser::Parser::available_parsers::parse_v1(const std::filesystem::path // ---- workflow name ---- workflow_name = doc["name"].as(); engine->setWorkflowName(workflow_name); - printer::print(printer::CLI_LEVEL_JSON, "Parsing configuration for workflow: " + workflow_name); + UPDATE_CALF_CLI_CONFIG("capiocl::Parser::parse_v1", workflow_name); + CALF_PRINT_COLOR(CALF_CLI_LEVEL_INFO, "Parsing configuration for workflow: %s", + workflow_name.c_str()); // ---- IO_Graph ---- for (const auto &app : doc["IO_Graph"].array_range()) { std::string app_name = app["name"].as(); - printer::print(printer::CLI_LEVEL_JSON, "Parsing config for app " + app_name); + CALF_PRINT_COLOR(CALF_CLI_LEVEL_INFO, "Parsing config for app: %s", app_name.c_str()); // ---- input_stream ---- - printer::print(printer::CLI_LEVEL_JSON, "Parsing input_stream for app " + app_name); + CALF_PRINT_COLOR(CALF_CLI_LEVEL_INFO, "Parsing input_stream for app: %s", app_name.c_str()); for (const auto &itm : app["input_stream"].array_range()) { auto file_path = resolve(itm.as(), resolve_prefix); engine->newFile(file_path); @@ -40,7 +43,8 @@ capiocl::parser::Parser::available_parsers::parse_v1(const std::filesystem::path } // ---- output_stream ---- - printer::print(printer::CLI_LEVEL_JSON, "Parsing output_stream for app " + app_name); + CALF_PRINT_COLOR(CALF_CLI_LEVEL_INFO, "Parsing output_stream for app: %s", + app_name.c_str()); for (const auto &itm : app["output_stream"].array_range()) { auto file_path = resolve(itm.as(), resolve_prefix); engine->newFile(file_path); @@ -49,7 +53,8 @@ capiocl::parser::Parser::available_parsers::parse_v1(const std::filesystem::path // ---- streaming ---- if (app.contains("streaming")) { - printer::print(printer::CLI_LEVEL_JSON, "Parsing streaming for app " + app_name); + CALF_PRINT_COLOR(CALF_CLI_LEVEL_INFO, "Parsing streaming section for app: %s", + app_name.c_str()); for (const auto &stream_item : app["streaming"].array_range()) { bool is_file = true; std::vector streaming_names; @@ -162,7 +167,7 @@ capiocl::parser::Parser::available_parsers::parse_v1(const std::filesystem::path engine->setStoreFileInMemory(file_str); } } else { - printer::print(printer::CLI_LEVEL_INFO, "No MEM storage section found"); + CALF_PRINT_COLOR(CALF_CLI_LEVEL_WARNING, "No MEM storage section found"); } if (storage.contains("fs")) { @@ -171,15 +176,15 @@ capiocl::parser::Parser::available_parsers::parse_v1(const std::filesystem::path engine->setStoreFileInFileSystem(file_str); } } else { - printer::print(printer::CLI_LEVEL_INFO, "No FS storage section found"); + CALF_PRINT_COLOR(CALF_CLI_LEVEL_WARNING, "No FS storage section found"); } } else { - printer::print(printer::CLI_LEVEL_INFO, "No storage section found"); + CALF_PRINT_COLOR(CALF_CLI_LEVEL_WARNING, "No STORAGE storage section found"); } // ---- Store only in memory ---- if (store_only_in_memory) { - printer::print(printer::CLI_LEVEL_INFO, "Storing all files in memory"); + CALF_PRINT_COLOR(CALF_CLI_LEVEL_INFO, "Storing all files in memory"); engine->setAllStoreInMemory(); } diff --git a/src/serializers/v1.1.cpp b/src/serializers/v1.1.cpp index b862711..18b2415 100644 --- a/src/serializers/v1.1.cpp +++ b/src/serializers/v1.1.cpp @@ -1,12 +1,13 @@ #include +#include "calf/StdOutLogger.h" #include "capiocl.hpp" #include "capiocl/engine.h" -#include "capiocl/printer.h" #include "capiocl/serializer.h" void capiocl::serializer::Serializer::available_serializers::serialize_v1_1( const engine::Engine &engine, const std::filesystem::path &filename) { + UPDATE_CALF_CLI_CONFIG("capiocl::Serializer::serialize_v1_1", engine.getWorkflowName()); jsoncons::json doc; doc["version"] = 1.1; doc["name"] = engine.getWorkflowName(); @@ -58,9 +59,9 @@ void capiocl::serializer::Serializer::available_serializers::serialize_v1_1( const auto close_count = std::to_string(entry.commit_on_close_count); streaming_item["committed"] = entry.commit_rule + ":" + close_count; } else { - const auto msg = "Commit rule is not ON_CLOSE but close count > 0"; - printer::print(printer::CLI_LEVEL_WARNING, msg); - printer::print(printer::CLI_LEVEL_WARNING, "Setting commit rule = ON_CLOSE"); + CALF_PRINT_COLOR(CALF_CLI_LEVEL_WARNING, + "Commit rule is not ON_CLOSE but close count > 0"); + CALF_PRINT_COLOR(CALF_CLI_LEVEL_WARNING, "Setting commit rule = ON_CLOSE"); streaming_item["committed"] = std::string(commitRules::ON_CLOSE) + ":" + std::to_string(entry.commit_on_close_count); } @@ -124,5 +125,6 @@ void capiocl::serializer::Serializer::available_serializers::serialize_v1_1( } out << jsoncons::pretty_print(doc) << std::endl; - printer::print(printer::CLI_LEVEL_INFO, "Configuration serialized to " + filename.string()); + CALF_PRINT_COLOR(CALF_CLI_LEVEL_INFO, "Configuration serialized to %s", + filename.string().c_str()); } \ No newline at end of file diff --git a/src/serializers/v1.cpp b/src/serializers/v1.cpp index f43a09d..54276a3 100644 --- a/src/serializers/v1.cpp +++ b/src/serializers/v1.cpp @@ -1,12 +1,13 @@ #include +#include "calf/StdOutLogger.h" #include "capiocl.hpp" #include "capiocl/engine.h" -#include "capiocl/printer.h" #include "capiocl/serializer.h" void capiocl::serializer::Serializer::available_serializers::serialize_v1( const engine::Engine &engine, const std::filesystem::path &filename) { + UPDATE_CALF_CLI_CONFIG("capiocl::Engine", engine.getWorkflowName()); jsoncons::json doc; doc["name"] = engine.getWorkflowName(); @@ -57,9 +58,9 @@ void capiocl::serializer::Serializer::available_serializers::serialize_v1( const auto close_count = std::to_string(entry.commit_on_close_count); streaming_item["committed"] = entry.commit_rule + ":" + close_count; } else { - const auto msg = "Commit rule is not ON_CLOSE but close count > 0"; - printer::print(printer::CLI_LEVEL_WARNING, msg); - printer::print(printer::CLI_LEVEL_WARNING, "Setting commit rule = ON_CLOSE"); + CALF_PRINT_COLOR(CALF_CLI_LEVEL_WARNING, + "Commit rule is not ON_CLOSE but close count > 0"); + CALF_PRINT_COLOR(CALF_CLI_LEVEL_WARNING, "Setting commit rule = ON_CLOSE"); streaming_item["committed"] = std::string(commitRules::ON_CLOSE) + ":" + std::to_string(entry.commit_on_close_count); } @@ -123,5 +124,6 @@ void capiocl::serializer::Serializer::available_serializers::serialize_v1( } out << jsoncons::pretty_print(doc) << std::endl; - printer::print(printer::CLI_LEVEL_INFO, "Configuration serialized to " + filename.string()); + CALF_PRINT_COLOR(CALF_CLI_LEVEL_INFO, "Configuration serialized to %s", + filename.string().c_str()); } \ No newline at end of file From 01aa012a17d04d0645485ea96a33640409c5202e Mon Sep 17 00:00:00 2001 From: Marco Edoardo Santimaria Date: Tue, 9 Jun 2026 14:14:43 +0200 Subject: [PATCH 02/16] continued porting --- src/Engine.cpp | 6 +++--- src/api.cpp | 12 ++++++++---- tests/cpp/main.cpp | 1 - tests/cpp/test_exceptions.hpp | 7 +++---- tests/cpp/test_serialize_deserialize.hpp | 4 ---- 5 files changed, 14 insertions(+), 16 deletions(-) diff --git a/src/Engine.cpp b/src/Engine.cpp index 0bbdfb0..9951beb 100644 --- a/src/Engine.cpp +++ b/src/Engine.cpp @@ -28,7 +28,7 @@ template class shared_lock_guard { void capiocl::engine::Engine::print() const { UPDATE_CALF_CLI_CONFIG("capiocl::Engine", workflow_name); // First message - CALF_PRINT_COLOR(CALF_CLI_LEVEL_INFO, ""); + CALF_PRINT_COLOR(CALF_CLI_LEVEL_INFO, " "); CALF_PRINT_COLOR(CALF_CLI_LEVEL_INFO, "Composition of expected CAPIO FS: "); // Table header lines @@ -37,7 +37,7 @@ void capiocl::engine::Engine::print() const { CALF_PRINT_COLOR(CALF_CLI_LEVEL_INFO, "| Parsed configuration file for workflow: \033[1;36m %s%s \033[0m |", - workflow_name.c_str(), std::string(94 - workflow_name.length(), ' ').c_str()); + workflow_name.c_str(), std::string(86 - workflow_name.length(), ' ').c_str()); CALF_PRINT_COLOR(CALF_CLI_LEVEL_INFO, "|%s|", std::string(134, ' ').c_str()); @@ -143,7 +143,7 @@ void capiocl::engine::Engine::print() const { CALF_PRINT_COLOR(CALF_CLI_LEVEL_INFO, "*%s*", std::string(134, '~').c_str()); } - CALF_PRINT_COLOR(CALF_CLI_LEVEL_INFO, ""); + CALF_PRINT_COLOR(CALF_CLI_LEVEL_INFO, " "); } capiocl::engine::Engine::Engine(const bool use_default_settings) { diff --git a/src/api.cpp b/src/api.cpp index 6adebf9..bf82cda 100644 --- a/src/api.cpp +++ b/src/api.cpp @@ -9,9 +9,9 @@ #include #include +#include "calf/StdOutLogger.h" #include "capiocl/api.h" #include "capiocl/engine.h" -#include "capiocl/printer.h" std::mutex _setupMtx; std::condition_variable _setupCv; @@ -21,6 +21,8 @@ bool thread_ready = false; void server(const std::string &address, const int port, capiocl::engine::Engine *engine, std::atomic *terminate) { + UPDATE_CALF_CLI_CONFIG("CapioClApiServer::server", engine->getWorkflowName()); + constexpr int RECV_BUF_SIZE = 65535; const auto &wf_name = engine->getWorkflowName(); @@ -93,8 +95,8 @@ void server(const std::string &address, const int port, capiocl::engine::Engine } } catch (const jsoncons::json_exception &e) { - capiocl::printer::print(capiocl::printer::CLI_LEVEL_ERROR, - "APIServer: Received invalid json: " + std::string(e.what())); + CALF_PRINT_COLOR(CALF_CLI_LEVEL_ERROR, "APIServer: Received invalid json: %s", + e.what()); } } @@ -105,6 +107,8 @@ capiocl::api::CapioClApiServer::CapioClApiServer(engine::Engine *engine, configuration::CapioClConfiguration &config) : capiocl_configuration(config) { + UPDATE_CALF_CLI_CONFIG("CapioClApiServer::CapioClApiServer", engine->getWorkflowName()); + std::string address; int port; try { @@ -124,7 +128,7 @@ capiocl::api::CapioClApiServer::CapioClApiServer(engine::Engine *engine, std::unique_lock lock(_setupMtx); _setupCv.wait(lock, [] { return thread_ready; }); - printer::print(printer::CLI_LEVEL_INFO, "API server @ " + address + ":" + std::to_string(port)); + CALF_PRINT_COLOR(CALF_CLI_LEVEL_INFO, "API server @ %s:%d", address.c_str(), port); } capiocl::api::CapioClApiServer::~CapioClApiServer() { diff --git a/tests/cpp/main.cpp b/tests/cpp/main.cpp index 29f742f..1163cb9 100644 --- a/tests/cpp/main.cpp +++ b/tests/cpp/main.cpp @@ -18,7 +18,6 @@ template std::string demangled_name(const T &obj) { #include "capiocl/engine.h" #include "capiocl/monitor.h" #include "capiocl/parser.h" -#include "capiocl/printer.h" #include "capiocl/serializer.h" #include "test_apis.hpp" diff --git a/tests/cpp/test_exceptions.hpp b/tests/cpp/test_exceptions.hpp index 9356939..c4bcd63 100644 --- a/tests/cpp/test_exceptions.hpp +++ b/tests/cpp/test_exceptions.hpp @@ -43,8 +43,8 @@ TEST(EXCEPTION_SUITE_NAME, testFailedserializeVersion) { TEST(EXCEPTION_SUITE_NAME, testParserException) { std::filesystem::path JSON_DIR = "/tmp/capio_cl_jsons/"; - capiocl::printer::print(capiocl::printer::CLI_LEVEL_INFO, - "Loading jsons from " + JSON_DIR.string()); + + std::cout << "Loading jsons from " << JSON_DIR << std::endl; std::vector test_filenames = { "", @@ -77,8 +77,7 @@ TEST(EXCEPTION_SUITE_NAME, testParserException) { for (const auto &version : CAPIO_CL_AVAIL_VERSIONS) { for (const auto &test : test_filenames) { const auto test_file_path = test.empty() ? test : JSON_DIR / ("V" + version) / test; - capiocl::printer::print(capiocl::printer::CLI_LEVEL_WARNING, - "Testing on file " + test_file_path.string()); + std::cout << "Testing on file " << test_file_path << std::endl; EXPECT_THROW(capiocl::parser::Parser::parse(test_file_path), capiocl::parser::ParserException); diff --git a/tests/cpp/test_serialize_deserialize.hpp b/tests/cpp/test_serialize_deserialize.hpp index 8c0cd1a..96eadb2 100644 --- a/tests/cpp/test_serialize_deserialize.hpp +++ b/tests/cpp/test_serialize_deserialize.hpp @@ -48,7 +48,6 @@ TEST(SERIALIZE_DESERIALIZE_SUITE_NAME, testSerializeParseCAPIOCLV1) { auto new_engine = capiocl::parser::Parser::parse(path, resolve); EXPECT_TRUE(new_engine->getWorkflowName() == workflow_name); - capiocl::printer::print("", ""); EXPECT_TRUE(engine == *new_engine); auto new_engine1 = capiocl::parser::Parser::parse(path, resolve, true); @@ -80,7 +79,6 @@ TEST(SERIALIZE_DESERIALIZE_SUITE_NAME, testSerializeParseCAPIOCLV1NcloseNfiles) auto new_engine = capiocl::parser::Parser::parse(path, resolve); EXPECT_TRUE(new_engine->getWorkflowName() == workflow_name); - capiocl::printer::print("", ""); EXPECT_TRUE(engine == *new_engine); std::filesystem::remove(path); @@ -116,7 +114,6 @@ TEST(SERIALIZE_DESERIALIZE_SUITE_NAME, testSerializeParseCAPIOCLV1FileDeps) { auto new_engine = capiocl::parser::Parser::parse(path, resolve); EXPECT_TRUE(new_engine->getWorkflowName() == workflow_name); - capiocl::printer::print("", ""); EXPECT_TRUE(engine == *new_engine); std::filesystem::remove(path); @@ -146,7 +143,6 @@ TEST(SERIALIZE_DESERIALIZE_SUITE_NAME, testSerializeCommitOnCloseCountNoCommitRu EXPECT_TRUE(new_engine->getWorkflowName() == workflow_name); EXPECT_FALSE(engine == *new_engine); - capiocl::printer::print("", ""); engine.setCommitRule(file_1_name, capiocl::commitRules::ON_CLOSE); EXPECT_TRUE(engine == *new_engine); From 850d825fb8a8e76f350784499ad5b88a99b2c755 Mon Sep 17 00:00:00 2001 From: Marco Edoardo Santimaria Date: Tue, 9 Jun 2026 14:28:36 +0200 Subject: [PATCH 03/16] UPDATE --- CMakeLists.txt | 1 + src/Engine.cpp | 4 ++-- src/Monitor.cpp | 2 +- src/Parser.cpp | 8 ++++---- src/Serializer.cpp | 4 ++-- src/api.cpp | 4 ++-- src/configuration.cpp | 2 +- src/parsers/v1.1.cpp | 2 +- src/parsers/v1.cpp | 2 +- src/serializers/v1.1.cpp | 2 +- src/serializers/v1.cpp | 2 +- 11 files changed, 17 insertions(+), 16 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c82e2aa..3a9fb9c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -76,6 +76,7 @@ else () endif () set(CALF_BUILD_STL ON CACHE BOOL "" FORCE) set(CALF_BUILD_SYSCALL OFF CACHE BOOL "" FORCE) +set(CALF_COMPONENT_NAME "capiocl" CACHE STRING "capiocl" FORCE) FetchContent_MakeAvailable(jsoncons tomlplusplus calf) diff --git a/src/Engine.cpp b/src/Engine.cpp index 9951beb..d98bc03 100644 --- a/src/Engine.cpp +++ b/src/Engine.cpp @@ -26,7 +26,7 @@ template class shared_lock_guard { }; void capiocl::engine::Engine::print() const { - UPDATE_CALF_CLI_CONFIG("capiocl::Engine", workflow_name); + UPDATE_CALF_WORKFLOW_NAME(workflow_name); // First message CALF_PRINT_COLOR(CALF_CLI_LEVEL_INFO, " "); CALF_PRINT_COLOR(CALF_CLI_LEVEL_INFO, "Composition of expected CAPIO FS: "); @@ -900,7 +900,7 @@ bool capiocl::engine::Engine::operator==(const Engine &other) const { return true; } void capiocl::engine::Engine::loadConfiguration(const std::string &path) { - UPDATE_CALF_CLI_CONFIG("capiocl::Engine", workflow_name); + UPDATE_CALF_WORKFLOW_NAME(workflow_name); configuration.load(path); std::string multicast_monitor_enabled, fs_monitor_enabled; diff --git a/src/Monitor.cpp b/src/Monitor.cpp index c9eaa81..bfa1cb8 100644 --- a/src/Monitor.cpp +++ b/src/Monitor.cpp @@ -4,7 +4,7 @@ #include "calf/StdOutLogger.h" capiocl::monitor::MonitorException::MonitorException(const std::string &msg) : message(msg) { - UPDATE_CALF_CLI_CONFIG("capiocl::MonitorException", ""); + UPDATE_CALF_WORKFLOW_NAME(""); CALF_PRINT_COLOR(CALF_CLI_LEVEL_ERROR, "%s", msg.c_str()); } diff --git a/src/Parser.cpp b/src/Parser.cpp index 99802b7..0d80c78 100644 --- a/src/Parser.cpp +++ b/src/Parser.cpp @@ -7,7 +7,7 @@ #include "capiocl/parser.h" capiocl::parser::ParserException::ParserException(const std::string &msg) : message(msg) { - UPDATE_CALF_CLI_CONFIG("capiocl::Parser", ""); + UPDATE_CALF_WORKFLOW_NAME(""); CALF_PRINT_COLOR(CALF_CLI_LEVEL_ERROR, "%s", msg.c_str()); } @@ -18,7 +18,7 @@ capiocl::parser::Parser::loadSchema(const char *data) { std::filesystem::path capiocl::parser::Parser::resolve(std::filesystem::path path, const std::filesystem::path &prefix) { - UPDATE_CALF_CLI_CONFIG("capiocl::Parser", ""); + UPDATE_CALF_WORKFLOW_NAME(""); if (prefix.empty()) { return path; } @@ -40,7 +40,7 @@ void capiocl::parser::Parser::validate_json(const jsoncons::json &doc, const cha // throws jsoncons::jsonschema::validation_error on failure schema.validate(doc); } catch (const jsoncons::jsonschema::validation_error &e) { - UPDATE_CALF_CLI_CONFIG("capiocl::Parser", ""); + UPDATE_CALF_WORKFLOW_NAME(""); CALF_PRINT_COLOR(CALF_CLI_LEVEL_ERROR, "%s", e.what()); throw ParserException("JSON validation failed!"); } @@ -70,7 +70,7 @@ capiocl::engine::Engine *capiocl::parser::Parser::parse(const std::filesystem::p file.close(); - UPDATE_CALF_CLI_CONFIG("capiocl::Parser", ""); + UPDATE_CALF_WORKFLOW_NAME(""); CALF_PRINT_COLOR(CALF_CLI_LEVEL_INFO, "Parsing CAPIO-CL config file for version: %s", capio_cl_release.c_str()); diff --git a/src/Serializer.cpp b/src/Serializer.cpp index ef22fe6..38afd54 100644 --- a/src/Serializer.cpp +++ b/src/Serializer.cpp @@ -10,7 +10,7 @@ void capiocl::serializer::Serializer::dump(const engine::Engine &engine, const std::filesystem::path &filename, const std::string &version) { - UPDATE_CALF_CLI_CONFIG("capiocl::Serializer", engine.getWorkflowName()); + UPDATE_CALF_WORKFLOW_NAME(engine.getWorkflowName()); if (version == CAPIO_CL_VERSION::V1) { CALF_PRINT_COLOR(CALF_CLI_LEVEL_INFO, "Serializing engine with V1 specification"); available_serializers::serialize_v1(engine, filename); @@ -25,6 +25,6 @@ void capiocl::serializer::Serializer::dump(const engine::Engine &engine, capiocl::serializer::SerializerException::SerializerException(const std::string &msg) : message(msg) { - UPDATE_CALF_CLI_CONFIG("capiocl::Serializer", ""); + UPDATE_CALF_WORKFLOW_NAME(""); CALF_PRINT_COLOR(CALF_CLI_LEVEL_ERROR, "%s", msg.c_str()); } \ No newline at end of file diff --git a/src/api.cpp b/src/api.cpp index bf82cda..8c73e2c 100644 --- a/src/api.cpp +++ b/src/api.cpp @@ -21,7 +21,7 @@ bool thread_ready = false; void server(const std::string &address, const int port, capiocl::engine::Engine *engine, std::atomic *terminate) { - UPDATE_CALF_CLI_CONFIG("CapioClApiServer::server", engine->getWorkflowName()); + UPDATE_CALF_WORKFLOW_NAME(engine->getWorkflowName()); constexpr int RECV_BUF_SIZE = 65535; @@ -107,7 +107,7 @@ capiocl::api::CapioClApiServer::CapioClApiServer(engine::Engine *engine, configuration::CapioClConfiguration &config) : capiocl_configuration(config) { - UPDATE_CALF_CLI_CONFIG("CapioClApiServer::CapioClApiServer", engine->getWorkflowName()); + UPDATE_CALF_WORKFLOW_NAME(engine->getWorkflowName()); std::string address; int port; diff --git a/src/configuration.cpp b/src/configuration.cpp index e15ab08..209d064 100644 --- a/src/configuration.cpp +++ b/src/configuration.cpp @@ -91,6 +91,6 @@ void capiocl::configuration::CapioClConfiguration::getParameter(const std::strin capiocl::configuration::CapioClConfigurationException::CapioClConfigurationException( const std::string &msg) : message(msg) { - UPDATE_CALF_CLI_CONFIG("capiocl::CapioClConfigurationException", ""); + UPDATE_CALF_WORKFLOW_NAME( ""); CALF_PRINT_COLOR(CALF_CLI_LEVEL_ERROR, "%s", msg.c_str()); } \ No newline at end of file diff --git a/src/parsers/v1.1.cpp b/src/parsers/v1.1.cpp index c2aa0a4..318d512 100644 --- a/src/parsers/v1.1.cpp +++ b/src/parsers/v1.1.cpp @@ -22,7 +22,7 @@ capiocl::parser::Parser::available_parsers::parse_v1_1(const std::filesystem::pa // ---- workflow name ---- workflow_name = doc["name"].as(); engine->setWorkflowName(workflow_name); - UPDATE_CALF_CLI_CONFIG("capiocl::Parser::parse_v1_1", workflow_name); + UPDATE_CALF_WORKFLOW_NAME(workflow_name); CALF_PRINT_COLOR(CALF_CLI_LEVEL_INFO, "Parsing configuration for workflow: %s", workflow_name.c_str()); diff --git a/src/parsers/v1.cpp b/src/parsers/v1.cpp index 9cf1ea4..0f83994 100644 --- a/src/parsers/v1.cpp +++ b/src/parsers/v1.cpp @@ -25,7 +25,7 @@ capiocl::parser::Parser::available_parsers::parse_v1(const std::filesystem::path // ---- workflow name ---- workflow_name = doc["name"].as(); engine->setWorkflowName(workflow_name); - UPDATE_CALF_CLI_CONFIG("capiocl::Parser::parse_v1", workflow_name); + UPDATE_CALF_WORKFLOW_NAME(workflow_name); CALF_PRINT_COLOR(CALF_CLI_LEVEL_INFO, "Parsing configuration for workflow: %s", workflow_name.c_str()); diff --git a/src/serializers/v1.1.cpp b/src/serializers/v1.1.cpp index 18b2415..ad6fd00 100644 --- a/src/serializers/v1.1.cpp +++ b/src/serializers/v1.1.cpp @@ -7,7 +7,7 @@ void capiocl::serializer::Serializer::available_serializers::serialize_v1_1( const engine::Engine &engine, const std::filesystem::path &filename) { - UPDATE_CALF_CLI_CONFIG("capiocl::Serializer::serialize_v1_1", engine.getWorkflowName()); + UPDATE_CALF_WORKFLOW_NAME(engine.getWorkflowName()); jsoncons::json doc; doc["version"] = 1.1; doc["name"] = engine.getWorkflowName(); diff --git a/src/serializers/v1.cpp b/src/serializers/v1.cpp index 54276a3..ec76f16 100644 --- a/src/serializers/v1.cpp +++ b/src/serializers/v1.cpp @@ -7,7 +7,7 @@ void capiocl::serializer::Serializer::available_serializers::serialize_v1( const engine::Engine &engine, const std::filesystem::path &filename) { - UPDATE_CALF_CLI_CONFIG("capiocl::Engine", engine.getWorkflowName()); + UPDATE_CALF_WORKFLOW_NAME(engine.getWorkflowName()); jsoncons::json doc; doc["name"] = engine.getWorkflowName(); From 2dc504784ad2add640c278d6aca18b765d8b2250 Mon Sep 17 00:00:00 2001 From: Marco Edoardo Santimaria Date: Tue, 9 Jun 2026 14:40:03 +0200 Subject: [PATCH 04/16] format --- src/configuration.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/configuration.cpp b/src/configuration.cpp index 209d064..4d7eb35 100644 --- a/src/configuration.cpp +++ b/src/configuration.cpp @@ -1,8 +1,8 @@ #include #include -#include "capiocl/configuration.h" #include "calf/StdOutLogger.h" +#include "capiocl/configuration.h" #include "toml++/toml.hpp" void load_config_to_memory(const toml::table &tbl, @@ -91,6 +91,6 @@ void capiocl::configuration::CapioClConfiguration::getParameter(const std::strin capiocl::configuration::CapioClConfigurationException::CapioClConfigurationException( const std::string &msg) : message(msg) { - UPDATE_CALF_WORKFLOW_NAME( ""); + UPDATE_CALF_WORKFLOW_NAME(""); CALF_PRINT_COLOR(CALF_CLI_LEVEL_ERROR, "%s", msg.c_str()); } \ No newline at end of file From a67e659c59f2bf0d9705f18cd1451f537e502c66 Mon Sep 17 00:00:00 2001 From: Marco Edoardo Santimaria Date: Tue, 9 Jun 2026 16:22:25 +0200 Subject: [PATCH 05/16] Updated cmakelist --- .gitignore | 4 +++- CMakeLists.txt | 22 ++++++++++++---------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/.gitignore b/.gitignore index 194cd58..8a4f4c0 100644 --- a/.gitignore +++ b/.gitignore @@ -47,4 +47,6 @@ dist/** # debug information files *.dwo -**.DS_Store \ No newline at end of file +**.DS_Store + +*build* \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 3a9fb9c..19fef49 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -68,16 +68,6 @@ set(JSONCONS_BUILD_TESTS OFF CACHE BOOL "" FORCE) set(JSONCONS_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE) set(JSONCONS_BUILD_FUZZERS OFF CACHE BOOL "" FORCE) -# CALF build flags -if (CMAKE_BUILD_TYPE STREQUAL "Debug") - set(CALF_LOG ON CACHE BOOL "" FORCE) -else () - set(CALF_LOG OFF CACHE BOOL "" FORCE) -endif () -set(CALF_BUILD_STL ON CACHE BOOL "" FORCE) -set(CALF_BUILD_SYSCALL OFF CACHE BOOL "" FORCE) -set(CALF_COMPONENT_NAME "capiocl" CACHE STRING "capiocl" FORCE) - FetchContent_MakeAvailable(jsoncons tomlplusplus calf) if (BUILD_PYTHON_BINDINGS) @@ -146,6 +136,18 @@ set(CAPIO_CL_HEADERS capiocl.hpp) # Library target add_library(libcapio_cl STATIC ${CAPIO_SRC} ${CAPIO_CL_HEADERS}) +set(CALF_BUILD_STL ON CACHE BOOL "" FORCE) +set(CALF_BUILD_SYSCALL OFF CACHE BOOL "" FORCE) + +# CALF build flags +if (CMAKE_BUILD_TYPE STREQUAL "Debug") + set(CALF_LOG ON CACHE BOOL "" FORCE) +else () + set(CALF_LOG OFF CACHE BOOL "" FORCE) +endif () + +calf_set_component(libcapio_cl "capio-cl") + target_include_directories(libcapio_cl PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/src From 3d05ee494227eb45305bfe440d43b7f0f3f123a1 Mon Sep 17 00:00:00 2001 From: Marco Edoardo Santimaria Date: Tue, 9 Jun 2026 17:23:22 +0200 Subject: [PATCH 06/16] Updated cmakelist --- CMakeLists.txt | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 19fef49..d6d7eec 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -136,17 +136,21 @@ set(CAPIO_CL_HEADERS capiocl.hpp) # Library target add_library(libcapio_cl STATIC ${CAPIO_SRC} ${CAPIO_CL_HEADERS}) -set(CALF_BUILD_STL ON CACHE BOOL "" FORCE) -set(CALF_BUILD_SYSCALL OFF CACHE BOOL "" FORCE) +##################################### # CALF build flags +##################################### +calf_set_component(libcapio_cl "capio-cl") +calf_set_default_log_dir(libcapio_cl "./capiocl_logs") +calf_build_stl(TRUE) +calf_build_syscall(FALSE) + if (CMAKE_BUILD_TYPE STREQUAL "Debug") - set(CALF_LOG ON CACHE BOOL "" FORCE) + calf_log(ON) else () - set(CALF_LOG OFF CACHE BOOL "" FORCE) + calf_log(OFF) endif () -calf_set_component(libcapio_cl "capio-cl") target_include_directories(libcapio_cl PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} From fd27a1e73c14d6096252b9adb0947206db0cc385 Mon Sep 17 00:00:00 2001 From: Marco Edoardo Santimaria Date: Tue, 9 Jun 2026 18:19:39 +0200 Subject: [PATCH 07/16] Update --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d6d7eec..1cc8d6c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -158,12 +158,12 @@ target_include_directories(libcapio_cl PUBLIC ${jsoncons_SOURCE_DIR}/include ${CAPIOCL_JSON_SCHEMAS_DIRECTORY} ${TOMLPLUSPLUS_SOURCE_DIR}/include + ${CALF_SOURCE_DIR} ) target_link_libraries(libcapio_cl PUBLIC) target_link_libraries(libcapio_cl PRIVATE - tomlplusplus::tomlplusplus calf::stl -) + tomlplusplus::tomlplusplus ) find_library(LIBANL anl) if (LIBANL) From aec316185fc541af6ba40e91045006f9641bdfb4 Mon Sep 17 00:00:00 2001 From: Marco Edoardo Santimaria Date: Tue, 9 Jun 2026 18:43:27 +0200 Subject: [PATCH 08/16] update --- CMakeLists.txt | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1cc8d6c..3736d77 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -137,21 +137,6 @@ set(CAPIO_CL_HEADERS capiocl.hpp) add_library(libcapio_cl STATIC ${CAPIO_SRC} ${CAPIO_CL_HEADERS}) -##################################### -# CALF build flags -##################################### -calf_set_component(libcapio_cl "capio-cl") -calf_set_default_log_dir(libcapio_cl "./capiocl_logs") -calf_build_stl(TRUE) -calf_build_syscall(FALSE) - -if (CMAKE_BUILD_TYPE STREQUAL "Debug") - calf_log(ON) -else () - calf_log(OFF) -endif () - - target_include_directories(libcapio_cl PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/src @@ -163,13 +148,21 @@ target_include_directories(libcapio_cl PUBLIC target_link_libraries(libcapio_cl PUBLIC) target_link_libraries(libcapio_cl PRIVATE - tomlplusplus::tomlplusplus ) + tomlplusplus::tomlplusplus) find_library(LIBANL anl) if (LIBANL) target_link_libraries(libcapio_cl PRIVATE ${LIBANL}) endif () +##################################### +# set CALF logger component name +##################################### +calf_enable_log(libcapio_cl $,ON,OFF>) +calf_set_component(libcapio_cl "capiocl") +calf_set_default_log_dir(libcapio_cl "./capiocl_logs") +target_include_directories(libcapio_cl PRIVATE ${CALF_SOURCE_DIR}) + ##################################### # Install rules ##################################### From 464267d4f021e46f71d8d555ad9c3bd49c342a9a Mon Sep 17 00:00:00 2001 From: Marco Edoardo Santimaria Date: Wed, 10 Jun 2026 08:20:23 +0200 Subject: [PATCH 09/16] fix to rv64 tests --- .github/workflows/python-bindings.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/python-bindings.yml b/.github/workflows/python-bindings.yml index 8b1f866..e66a301 100644 --- a/.github/workflows/python-bindings.yml +++ b/.github/workflows/python-bindings.yml @@ -14,7 +14,7 @@ jobs: name: "Test Python bindings" strategy: matrix: - on: [ 'ubuntu-24.04', 'macos-15-intel', 'macos-26' ] + on: [ 'ubuntu-24.04', 'macos-15-intel', 'macos-15' ] python: [ '3.10', '3.11', '3.12', '3.13', '3.14' ] runs-on: ${{ matrix.on }} From ac06f3a814d7002d403894e34ff9347615e2563c Mon Sep 17 00:00:00 2001 From: Marco Edoardo Santimaria <39337626+marcoSanti@users.noreply.github.com> Date: Fri, 12 Jun 2026 22:25:54 +0200 Subject: [PATCH 10/16] Hunting down heap bugs --- src/Monitor.cpp | 11 ++-- src/monitors/Multicast.cpp | 104 +++++++++++++++++++------------------ 2 files changed, 59 insertions(+), 56 deletions(-) diff --git a/src/Monitor.cpp b/src/Monitor.cpp index bfa1cb8..cbde029 100644 --- a/src/Monitor.cpp +++ b/src/Monitor.cpp @@ -1,11 +1,9 @@ #include "capiocl/monitor.h" #include "capiocl.hpp" -#include "calf/StdOutLogger.h" capiocl::monitor::MonitorException::MonitorException(const std::string &msg) : message(msg) { - UPDATE_CALF_WORKFLOW_NAME(""); - CALF_PRINT_COLOR(CALF_CLI_LEVEL_ERROR, "%s", msg.c_str()); + std::cerr << msg << std::endl; } bool capiocl::monitor::Monitor::isCommitted(const std::filesystem::path &path) const { @@ -21,6 +19,7 @@ void capiocl::monitor::Monitor::setCommitted(std::filesystem::path path) const { void capiocl::monitor::Monitor::registerMonitorBackend(const MonitorInterface *interface) { interfaces.emplace_back(interface); } + void capiocl::monitor::Monitor::setHomeNode(const std::filesystem::path &path) const { std::for_each(interfaces.begin(), interfaces.end(), [&path](const auto &interface) { interface->setHomeNode(path); }); @@ -29,7 +28,7 @@ void capiocl::monitor::Monitor::setHomeNode(const std::filesystem::path &path) c std::set capiocl::monitor::Monitor::getHomeNode(const std::filesystem::path &path) const { std::set home_nodes; - for (const auto &interface : interfaces) { + for (const auto &interface: interfaces) { const auto &node = interface->getHomeNode(path); if (node == NO_HOME_NODE) { continue; @@ -40,7 +39,7 @@ capiocl::monitor::Monitor::getHomeNode(const std::filesystem::path &path) const } capiocl::monitor::Monitor::~Monitor() { - for (const auto &interface : interfaces) { + for (const auto &interface: interfaces) { delete interface; } -} \ No newline at end of file +} diff --git a/src/monitors/Multicast.cpp b/src/monitors/Multicast.cpp index 011454a..42da9bf 100644 --- a/src/monitors/Multicast.cpp +++ b/src/monitors/Multicast.cpp @@ -10,9 +10,9 @@ static std::tuple outgoing_socket_multicast(const std::string &address, const int port) { sockaddr_in addr{}; - addr.sin_family = AF_INET; + addr.sin_family = AF_INET; addr.sin_addr.s_addr = inet_addr(address.c_str()); - addr.sin_port = htons(port); + addr.sin_port = htons(port); const int transmission_socket = socket(AF_INET, SOCK_DGRAM, 0); // LCOV_EXCL_START @@ -27,16 +27,16 @@ static std::tuple outgoing_socket_multicast(const std::string static int incoming_socket_multicast(const std::string &address_ip, const int port, sockaddr_in &addr, socklen_t &addrlen) { - constexpr int loopback = 1; // enable reception of loopback messages + constexpr int loopback = 1; // enable reception of loopback messages constexpr int multi_bind = 1; // enable multiple sockets on same address - addr = {}; - addr.sin_family = AF_INET; - addr.sin_port = htons(port); + addr = {}; + addr.sin_family = AF_INET; + addr.sin_port = htons(port); addr.sin_addr.s_addr = inet_addr(address_ip.c_str()); - addrlen = sizeof(addr); + addrlen = sizeof(addr); - ip_mreq mreq = {}; + ip_mreq mreq = {}; mreq.imr_multiaddr.s_addr = inet_addr(address_ip.c_str()); mreq.imr_interface.s_addr = htonl(INADDR_ANY); @@ -82,14 +82,14 @@ void capiocl::monitor::MulticastMonitor::commit_listener(std::vector *terminate) { pthread_setcancelstate(PTHREAD_CANCEL_ASYNCHRONOUS, nullptr); sockaddr_in addr_in = {}; - socklen_t addr_len = {}; - const auto socket = incoming_socket_multicast(ip_addr, ip_port, addr_in, addr_len); - const auto addr = reinterpret_cast(&addr_in); + socklen_t addr_len = {}; + const auto socket = incoming_socket_multicast(ip_addr, ip_port, addr_in, addr_len); + const auto addr = reinterpret_cast(&addr_in); char incoming_message[MESSAGE_SIZE] = {0}; // Polling for non blocking pollfd pfd = {}; - pfd.fd = socket; + pfd.fd = socket; pfd.events = POLLIN | POLLPRI; do { @@ -108,12 +108,17 @@ void capiocl::monitor::MulticastMonitor::commit_listener(std::vector(incoming_size)); + if (msg.size() < 2) { + continue; + } + const auto path = msg.substr(2); if (const char command = incoming_message[0]; command == SET) { // Received an advert for a committed file @@ -142,10 +147,10 @@ void capiocl::monitor::MulticastMonitor::home_node_listener( gethostname(this_hostname, HOST_NAME_MAX); sockaddr_in addr_in = {}; - socklen_t addr_len = {}; - const auto socket = incoming_socket_multicast(ip_addr, ip_port, addr_in, addr_len); + socklen_t addr_len = {}; + const auto socket = incoming_socket_multicast(ip_addr, ip_port, addr_in, addr_len); - const auto addr = reinterpret_cast(&addr_in); + const auto addr = reinterpret_cast(&addr_in); char incoming_message[MESSAGE_SIZE] = {0}; do { @@ -153,7 +158,7 @@ void capiocl::monitor::MulticastMonitor::home_node_listener( // Polling for non blocking pollfd pfd = {}; - pfd.fd = socket; + pfd.fd = socket; pfd.events = POLLIN | POLLPRI; // TODO: migrate to epoll for linux and kqueue on MacOS @@ -169,12 +174,13 @@ void capiocl::monitor::MulticastMonitor::home_node_listener( } // LCOV_EXCL_START - if (recvfrom(socket, incoming_message, MESSAGE_SIZE, MSG_DONTWAIT, addr, &addr_len) < 0) { + const auto incoming_size = recvfrom(socket, incoming_message, MESSAGE_SIZE, MSG_DONTWAIT, addr, &addr_len); + if (incoming_size < 0) { continue; } // LCOV_EXCL_STOP - std::string incoming_message_str(incoming_message); + std::string incoming_message_str(incoming_message, incoming_size); std::vector tokens; size_t start = 0, end = incoming_message_str.find(' '); @@ -183,28 +189,38 @@ void capiocl::monitor::MulticastMonitor::home_node_listener( tokens.push_back(incoming_message_str.substr(start, end - start)); } start = end + 1; - end = incoming_message_str.find(' ', start); + end = incoming_message_str.find(' ', start); } if (start < incoming_message_str.length()) { tokens.push_back(incoming_message_str.substr(start)); } - const auto &path = tokens[1]; - if (tokens[0].c_str()[0] == SET) { - // Received an advert for a committed file - std::lock_guard lg(lock); + // Drop anything that isn't a well-formed message. + if (tokens.empty()) { + continue; + } + if (const char command = tokens[0].c_str()[0]; command == SET) { + if (tokens.size() < 3) { + // need "! " -> malformed message, skip + continue; + } + const auto &path = tokens[1]; const auto &home_node = tokens[2]; - home_nodes[path] = home_node; + std::lock_guard lg(lock); + home_nodes[path] = home_node; } else { // Received a query for a home node, Message begins with capiocl::Monitor::REQUEST + if (tokens.size() < 2) { + // need "? " -> malformed message, skip + continue; + } + const auto &path = tokens[1]; std::lock_guard lg(lock); - if (home_nodes.find(path) == home_nodes.end()) { continue; } - if (home_nodes[path] == this_hostname) { _send_message(ip_addr, ip_port, path + " " + this_hostname, SET); } @@ -231,31 +247,23 @@ capiocl::monitor::MulticastMonitor::MulticastMonitor( config.getParameter("monitor.mcast.delay_ms", &MULTICAST_DELAY_MILLIS); commit_thread = - std::thread(&commit_listener, std::ref(_committed_files), std::ref(committed_lock), - MULTICAST_COMMIT_ADDR, MULTICAST_COMMIT_PORT, &this->terminate); + std::thread(&commit_listener, std::ref(_committed_files), std::ref(committed_lock), + MULTICAST_COMMIT_ADDR, MULTICAST_COMMIT_PORT, &this->terminate); home_node_thread = - std::thread(&home_node_listener, std::ref(_home_nodes), std::ref(home_node_lock), - MULTICAST_HOME_NODE_ADDR, MULTICAST_HOME_NODE_PORT, &this->terminate); + std::thread(&home_node_listener, std::ref(_home_nodes), std::ref(home_node_lock), + MULTICAST_HOME_NODE_ADDR, MULTICAST_HOME_NODE_PORT, &this->terminate); gethostname(_hostname, HOST_NAME_MAX); } capiocl::monitor::MulticastMonitor::~MulticastMonitor() { - terminate = true; - - if (commit_thread.joinable()) { - commit_thread.join(); - } - if (home_node_thread.joinable()) { - home_node_thread.join(); - } + commit_thread.join(); + home_node_thread.join(); } -bool capiocl::monitor::MulticastMonitor::isCommitted(const std::filesystem::path &path) const { - - { +bool capiocl::monitor::MulticastMonitor::isCommitted(const std::filesystem::path &path) const { { const std::lock_guard lg(committed_lock); if (std::find(_committed_files.begin(), _committed_files.end(), path) != _committed_files.end()) { @@ -264,9 +272,7 @@ bool capiocl::monitor::MulticastMonitor::isCommitted(const std::filesystem::path } _send_message(MULTICAST_COMMIT_ADDR, MULTICAST_COMMIT_PORT, path, GET); - std::this_thread::sleep_for(std::chrono::milliseconds(MULTICAST_DELAY_MILLIS)); - - { + std::this_thread::sleep_for(std::chrono::milliseconds(MULTICAST_DELAY_MILLIS)); { const std::lock_guard lg(committed_lock); return std::find(_committed_files.begin(), _committed_files.end(), path) != _committed_files.end(); @@ -291,9 +297,7 @@ void capiocl::monitor::MulticastMonitor::setHomeNode(const std::filesystem::path } const std::string & -capiocl::monitor::MulticastMonitor::getHomeNode(const std::filesystem::path &path) const { - - { +capiocl::monitor::MulticastMonitor::getHomeNode(const std::filesystem::path &path) const { { const std::lock_guard lg(home_node_lock); if (const auto itm = _home_nodes.find(path); itm != _home_nodes.end()) { return itm->second; @@ -309,4 +313,4 @@ capiocl::monitor::MulticastMonitor::getHomeNode(const std::filesystem::path &pat } else { return NO_HOME_NODE; } -} \ No newline at end of file +} From 85622c0a9ac8221ab10eef76e75f3bd85456e197 Mon Sep 17 00:00:00 2001 From: Marco Edoardo Santimaria Date: Mon, 20 Jul 2026 09:34:58 +0200 Subject: [PATCH 11/16] Fixed dangling return if std::string in home node --- capiocl/monitor.h | 8 ++++---- src/Monitor.cpp | 2 +- src/monitors/FileSystem.cpp | 6 +++--- src/monitors/Interface.cpp | 5 ++--- src/monitors/Multicast.cpp | 37 ++++++++++++++++++++++++++----------- 5 files changed, 36 insertions(+), 22 deletions(-) diff --git a/capiocl/monitor.h b/capiocl/monitor.h index 662ab89..58fe829 100644 --- a/capiocl/monitor.h +++ b/capiocl/monitor.h @@ -118,7 +118,7 @@ class MonitorInterface { * @param path * @return the home node responsible for the given path */ - virtual const std::string &getHomeNode(const std::filesystem::path &path) const; + virtual std::string getHomeNode(const std::filesystem::path &path) const; }; /** @@ -229,7 +229,7 @@ class MulticastMonitor final : public MonitorInterface { bool isCommitted(const std::filesystem::path &path) const override; void setCommitted(const std::filesystem::path &path) const override; void setHomeNode(const std::filesystem::path &path) const override; - const std::string &getHomeNode(const std::filesystem::path &path) const override; + std::string getHomeNode(const std::filesystem::path &path) const override; }; /** @@ -288,7 +288,7 @@ class FileSystemMonitor final : public MonitorInterface { bool isCommitted(const std::filesystem::path &path) const override; void setCommitted(const std::filesystem::path &path) const override; void setHomeNode(const std::filesystem::path &path) const override; - const std::string &getHomeNode(const std::filesystem::path &path) const override; + std::string getHomeNode(const std::filesystem::path &path) const override; }; /** @@ -344,4 +344,4 @@ class Monitor { }; } // namespace capiocl::monitor -#endif // CAPIO_CL_MONITOR_H \ No newline at end of file +#endif // CAPIO_CL_MONITOR_H diff --git a/src/Monitor.cpp b/src/Monitor.cpp index cbde029..7985cb9 100644 --- a/src/Monitor.cpp +++ b/src/Monitor.cpp @@ -29,7 +29,7 @@ std::set capiocl::monitor::Monitor::getHomeNode(const std::filesystem::path &path) const { std::set home_nodes; for (const auto &interface: interfaces) { - const auto &node = interface->getHomeNode(path); + const auto node = interface->getHomeNode(path); if (node == NO_HOME_NODE) { continue; } diff --git a/src/monitors/FileSystem.cpp b/src/monitors/FileSystem.cpp index 7f48f12..1db4823 100644 --- a/src/monitors/FileSystem.cpp +++ b/src/monitors/FileSystem.cpp @@ -54,8 +54,8 @@ void capiocl::monitor::FileSystemMonitor::setHomeNode(const std::filesystem::pat generate_home_node_token(path, _hostname); } -const std::string & -capiocl::monitor::FileSystemMonitor::getHomeNode(const std::filesystem::path &path) const { +std::string capiocl::monitor::FileSystemMonitor::getHomeNode( + const std::filesystem::path &path) const { auto home_node_token = compute_capiocl_token_name(path, HOME_NODE); @@ -75,4 +75,4 @@ capiocl::monitor::FileSystemMonitor::getHomeNode(const std::filesystem::path &pa auto [entry, _] = _home_nodes.emplace(path, std::move(home_node)); return entry->second; -} \ No newline at end of file +} diff --git a/src/monitors/Interface.cpp b/src/monitors/Interface.cpp index 05e94dc..d8c1a19 100644 --- a/src/monitors/Interface.cpp +++ b/src/monitors/Interface.cpp @@ -18,9 +18,8 @@ void capiocl::monitor::MonitorInterface::setHomeNode(const std::filesystem::path throw MonitorException(msg); } -const std::string & -capiocl::monitor::MonitorInterface::getHomeNode(const std::filesystem::path &path) const { +std::string capiocl::monitor::MonitorInterface::getHomeNode(const std::filesystem::path &path) const { std::string msg = "Attempted to use MonitorInterface as Monitor backend to set commit for: "; msg += path.string(); throw MonitorException(msg); -} \ No newline at end of file +} diff --git a/src/monitors/Multicast.cpp b/src/monitors/Multicast.cpp index 42da9bf..9af9745 100644 --- a/src/monitors/Multicast.cpp +++ b/src/monitors/Multicast.cpp @@ -50,25 +50,33 @@ static int incoming_socket_multicast(const std::string &address_ip, const int po // Allow multiple sockets to bind to the same port if (setsockopt(_socket, SOL_SOCKET, SO_REUSEPORT, &multi_bind, sizeof(multi_bind)) < 0) { + const int error = errno; + close(_socket); throw capiocl::monitor::MonitorException(std::string("REUSEPORT failed: ") + - strerror(errno)); + strerror(error)); } // Bind to port if (bind(_socket, reinterpret_cast(&addr), addrlen) < 0) { - throw capiocl::monitor::MonitorException(std::string("bind failed: ") + strerror(errno)); + const int error = errno; + close(_socket); + throw capiocl::monitor::MonitorException(std::string("bind failed: ") + strerror(error)); } // Join multicast group if (setsockopt(_socket, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof(mreq)) < 0) { + const int error = errno; + close(_socket); throw capiocl::monitor::MonitorException(std::string("join multicast failed: ") + - strerror(errno)); + strerror(error)); } // Enable loopback if (setsockopt(_socket, IPPROTO_IP, IP_MULTICAST_LOOP, &loopback, sizeof(loopback)) < 0) { + const int error = errno; + close(_socket); throw capiocl::monitor::MonitorException(std::string("loopback failed: ") + - strerror(errno)); + strerror(error)); } // LCOV_EXCL_STOP @@ -80,10 +88,14 @@ void capiocl::monitor::MulticastMonitor::commit_listener(std::vector *terminate) { - pthread_setcancelstate(PTHREAD_CANCEL_ASYNCHRONOUS, nullptr); sockaddr_in addr_in = {}; socklen_t addr_len = {}; - const auto socket = incoming_socket_multicast(ip_addr, ip_port, addr_in, addr_len); + int socket; + try { + socket = incoming_socket_multicast(ip_addr, ip_port, addr_in, addr_len); + } catch (const MonitorException &) { + return; + } const auto addr = reinterpret_cast(&addr_in); char incoming_message[MESSAGE_SIZE] = {0}; @@ -141,14 +153,17 @@ void capiocl::monitor::MulticastMonitor::commit_listener(std::vector &home_nodes, std::mutex &lock, const std::string &ip_addr, int ip_port, const std::atomic *terminate) { - pthread_setcancelstate(PTHREAD_CANCEL_ASYNCHRONOUS, nullptr); - char this_hostname[HOST_NAME_MAX] = {}; gethostname(this_hostname, HOST_NAME_MAX); sockaddr_in addr_in = {}; socklen_t addr_len = {}; - const auto socket = incoming_socket_multicast(ip_addr, ip_port, addr_in, addr_len); + int socket; + try { + socket = incoming_socket_multicast(ip_addr, ip_port, addr_in, addr_len); + } catch (const MonitorException &) { + return; + } const auto addr = reinterpret_cast(&addr_in); char incoming_message[MESSAGE_SIZE] = {0}; @@ -296,8 +311,8 @@ void capiocl::monitor::MulticastMonitor::setHomeNode(const std::filesystem::path _home_nodes[path] = _hostname; } -const std::string & -capiocl::monitor::MulticastMonitor::getHomeNode(const std::filesystem::path &path) const { { +std::string capiocl::monitor::MulticastMonitor::getHomeNode( + const std::filesystem::path &path) const { { const std::lock_guard lg(home_node_lock); if (const auto itm = _home_nodes.find(path); itm != _home_nodes.end()) { return itm->second; From 3d4a98965e52cc59fe44165cb66a4fd51b860b88 Mon Sep 17 00:00:00 2001 From: Marco Edoardo Santimaria Date: Mon, 20 Jul 2026 09:56:52 +0200 Subject: [PATCH 12/16] test --- capiocl/monitor.h | 16 ++++++---------- src/monitors/FileSystem.cpp | 5 ++++- src/monitors/Multicast.cpp | 8 +++++--- tests/cpp/test_monitor.hpp | 14 +++++++------- 4 files changed, 22 insertions(+), 21 deletions(-) diff --git a/capiocl/monitor.h b/capiocl/monitor.h index 58fe829..3a7e74b 100644 --- a/capiocl/monitor.h +++ b/capiocl/monitor.h @@ -2,6 +2,7 @@ #define CAPIO_CL_MONITOR_H #include +#include #include #include #include @@ -12,17 +13,12 @@ #include "configuration.h" -#ifndef PATH_MAX -#define PATH_MAX 4096 -#endif - -#ifndef HOST_NAME_MAX -#define HOST_NAME_MAX 1024 -#endif - /// @brief Namespace containing the CAPIO-CL Monitor components namespace capiocl::monitor { +inline constexpr std::size_t HOSTNAME_BUFFER_SIZE = 1024; +inline constexpr std::size_t PATH_BUFFER_SIZE = 4096; + /// @brief Constant value for when a home node is not found static const std::string NO_HOME_NODE = ""; @@ -84,7 +80,7 @@ class MonitorInterface { /** * @brief hostname of the current instance */ - mutable char _hostname[HOST_NAME_MAX] = {0}; + mutable char _hostname[HOSTNAME_BUFFER_SIZE] = {0}; public: /** @@ -133,7 +129,7 @@ class MonitorInterface { */ class MulticastMonitor final : public MonitorInterface { - static constexpr int MESSAGE_SIZE = (2 + PATH_MAX + PATH_MAX); ///< Max network message size. + static constexpr int MESSAGE_SIZE = 2 + (2 * PATH_BUFFER_SIZE); ///< Max network message size. /** * @brief Background threads used to listen for commit messages and for home nodes. diff --git a/src/monitors/FileSystem.cpp b/src/monitors/FileSystem.cpp index 1db4823..d9d0b74 100644 --- a/src/monitors/FileSystem.cpp +++ b/src/monitors/FileSystem.cpp @@ -40,7 +40,10 @@ void capiocl::monitor::FileSystemMonitor::generate_commit_token(const std::files } } -capiocl::monitor::FileSystemMonitor::FileSystemMonitor() { gethostname(_hostname, HOST_NAME_MAX); } +capiocl::monitor::FileSystemMonitor::FileSystemMonitor() { + gethostname(_hostname, sizeof(_hostname)); + _hostname[sizeof(_hostname) - 1] = '\0'; +} void capiocl::monitor::FileSystemMonitor::setCommitted(const std::filesystem::path &path) const { generate_commit_token(path); diff --git a/src/monitors/Multicast.cpp b/src/monitors/Multicast.cpp index 9af9745..748c205 100644 --- a/src/monitors/Multicast.cpp +++ b/src/monitors/Multicast.cpp @@ -153,8 +153,9 @@ void capiocl::monitor::MulticastMonitor::commit_listener(std::vector &home_nodes, std::mutex &lock, const std::string &ip_addr, int ip_port, const std::atomic *terminate) { - char this_hostname[HOST_NAME_MAX] = {}; - gethostname(this_hostname, HOST_NAME_MAX); + char this_hostname[HOSTNAME_BUFFER_SIZE] = {}; + gethostname(this_hostname, sizeof(this_hostname)); + this_hostname[sizeof(this_hostname) - 1] = '\0'; sockaddr_in addr_in = {}; socklen_t addr_len = {}; @@ -269,7 +270,8 @@ capiocl::monitor::MulticastMonitor::MulticastMonitor( std::thread(&home_node_listener, std::ref(_home_nodes), std::ref(home_node_lock), MULTICAST_HOME_NODE_ADDR, MULTICAST_HOME_NODE_PORT, &this->terminate); - gethostname(_hostname, HOST_NAME_MAX); + gethostname(_hostname, sizeof(_hostname)); + _hostname[sizeof(_hostname) - 1] = '\0'; } capiocl::monitor::MulticastMonitor::~MulticastMonitor() { diff --git a/tests/cpp/test_monitor.hpp b/tests/cpp/test_monitor.hpp index 7189282..ba0f127 100644 --- a/tests/cpp/test_monitor.hpp +++ b/tests/cpp/test_monitor.hpp @@ -70,8 +70,8 @@ TEST(MONITOR_SUITE_NAME, testHomeNodeAcrossDifferentThreads) { const auto e1 = new capiocl::engine::Engine(); const auto e2 = new capiocl::engine::Engine(); - char hostname[HOST_NAME_MAX] = {}; - gethostname(hostname, HOST_NAME_MAX); + char hostname[capiocl::monitor::HOSTNAME_BUFFER_SIZE] = {}; + gethostname(hostname, sizeof(hostname)); e1->setHomeNode("test.txt"); const std::set home_nodes = e2->getHomeNode("test.txt"); @@ -87,8 +87,8 @@ TEST(MONITOR_SUITE_NAME, testHomeNodeAcrossDifferentThreads) { } TEST(MONITOR_SUITE_NAME, testHomeNodeAfterSetup) { - char hostname[HOST_NAME_MAX] = {}; - gethostname(hostname, HOST_NAME_MAX); + char hostname[capiocl::monitor::HOSTNAME_BUFFER_SIZE] = {}; + gethostname(hostname, sizeof(hostname)); const capiocl::engine::Engine e; e.setHomeNode("test.txt"); @@ -103,8 +103,8 @@ TEST(MONITOR_SUITE_NAME, testHomeNodeAfterSetup) { } TEST(MONITOR_SUITE_NAME, testHomeNodeAfterInstanceTearDown) { - char hostname[HOST_NAME_MAX] = {}; - gethostname(hostname, HOST_NAME_MAX); + char hostname[capiocl::monitor::HOSTNAME_BUFFER_SIZE] = {}; + gethostname(hostname, sizeof(hostname)); auto e1 = new capiocl::engine::Engine(); @@ -120,4 +120,4 @@ TEST(MONITOR_SUITE_NAME, testHomeNodeAfterInstanceTearDown) { EXPECT_NE(home_nodes.find(hostname), home_nodes.end()); } -#endif // CAPIO_CL_MONITOR_HPP \ No newline at end of file +#endif // CAPIO_CL_MONITOR_HPP From 13fed671eee3e2dd53047a024e427647a56d218f Mon Sep 17 00:00:00 2001 From: Marco Edoardo Santimaria Date: Mon, 20 Jul 2026 10:05:58 +0200 Subject: [PATCH 13/16] code cleanup --- capiocl/monitor.h | 5 +++- src/Monitor.cpp | 5 ++-- src/monitors/FileSystem.cpp | 4 +-- src/monitors/Interface.cpp | 3 +- src/monitors/Multicast.cpp | 57 ++++++++++++++++++++----------------- 5 files changed, 41 insertions(+), 33 deletions(-) diff --git a/capiocl/monitor.h b/capiocl/monitor.h index 3a7e74b..32bdc7b 100644 --- a/capiocl/monitor.h +++ b/capiocl/monitor.h @@ -16,8 +16,11 @@ /// @brief Namespace containing the CAPIO-CL Monitor components namespace capiocl::monitor { +/// @brief Buffer size used to store a null-terminated host name. inline constexpr std::size_t HOSTNAME_BUFFER_SIZE = 1024; -inline constexpr std::size_t PATH_BUFFER_SIZE = 4096; + +/// @brief Maximum path storage used in multicast monitor messages. +inline constexpr std::size_t PATH_BUFFER_SIZE = 4096; /// @brief Constant value for when a home node is not found static const std::string NO_HOME_NODE = ""; diff --git a/src/Monitor.cpp b/src/Monitor.cpp index 7985cb9..46155f0 100644 --- a/src/Monitor.cpp +++ b/src/Monitor.cpp @@ -1,7 +1,6 @@ #include "capiocl/monitor.h" #include "capiocl.hpp" - capiocl::monitor::MonitorException::MonitorException(const std::string &msg) : message(msg) { std::cerr << msg << std::endl; } @@ -28,7 +27,7 @@ void capiocl::monitor::Monitor::setHomeNode(const std::filesystem::path &path) c std::set capiocl::monitor::Monitor::getHomeNode(const std::filesystem::path &path) const { std::set home_nodes; - for (const auto &interface: interfaces) { + for (const auto &interface : interfaces) { const auto node = interface->getHomeNode(path); if (node == NO_HOME_NODE) { continue; @@ -39,7 +38,7 @@ capiocl::monitor::Monitor::getHomeNode(const std::filesystem::path &path) const } capiocl::monitor::Monitor::~Monitor() { - for (const auto &interface: interfaces) { + for (const auto &interface : interfaces) { delete interface; } } diff --git a/src/monitors/FileSystem.cpp b/src/monitors/FileSystem.cpp index d9d0b74..3fa3538 100644 --- a/src/monitors/FileSystem.cpp +++ b/src/monitors/FileSystem.cpp @@ -57,8 +57,8 @@ void capiocl::monitor::FileSystemMonitor::setHomeNode(const std::filesystem::pat generate_home_node_token(path, _hostname); } -std::string capiocl::monitor::FileSystemMonitor::getHomeNode( - const std::filesystem::path &path) const { +std::string +capiocl::monitor::FileSystemMonitor::getHomeNode(const std::filesystem::path &path) const { auto home_node_token = compute_capiocl_token_name(path, HOME_NODE); diff --git a/src/monitors/Interface.cpp b/src/monitors/Interface.cpp index d8c1a19..3d61988 100644 --- a/src/monitors/Interface.cpp +++ b/src/monitors/Interface.cpp @@ -18,7 +18,8 @@ void capiocl::monitor::MonitorInterface::setHomeNode(const std::filesystem::path throw MonitorException(msg); } -std::string capiocl::monitor::MonitorInterface::getHomeNode(const std::filesystem::path &path) const { +std::string +capiocl::monitor::MonitorInterface::getHomeNode(const std::filesystem::path &path) const { std::string msg = "Attempted to use MonitorInterface as Monitor backend to set commit for: "; msg += path.string(); throw MonitorException(msg); diff --git a/src/monitors/Multicast.cpp b/src/monitors/Multicast.cpp index 748c205..fb7411e 100644 --- a/src/monitors/Multicast.cpp +++ b/src/monitors/Multicast.cpp @@ -10,9 +10,9 @@ static std::tuple outgoing_socket_multicast(const std::string &address, const int port) { sockaddr_in addr{}; - addr.sin_family = AF_INET; + addr.sin_family = AF_INET; addr.sin_addr.s_addr = inet_addr(address.c_str()); - addr.sin_port = htons(port); + addr.sin_port = htons(port); const int transmission_socket = socket(AF_INET, SOCK_DGRAM, 0); // LCOV_EXCL_START @@ -27,16 +27,16 @@ static std::tuple outgoing_socket_multicast(const std::string static int incoming_socket_multicast(const std::string &address_ip, const int port, sockaddr_in &addr, socklen_t &addrlen) { - constexpr int loopback = 1; // enable reception of loopback messages + constexpr int loopback = 1; // enable reception of loopback messages constexpr int multi_bind = 1; // enable multiple sockets on same address - addr = {}; - addr.sin_family = AF_INET; - addr.sin_port = htons(port); + addr = {}; + addr.sin_family = AF_INET; + addr.sin_port = htons(port); addr.sin_addr.s_addr = inet_addr(address_ip.c_str()); - addrlen = sizeof(addr); + addrlen = sizeof(addr); - ip_mreq mreq = {}; + ip_mreq mreq = {}; mreq.imr_multiaddr.s_addr = inet_addr(address_ip.c_str()); mreq.imr_interface.s_addr = htonl(INADDR_ANY); @@ -89,19 +89,19 @@ void capiocl::monitor::MulticastMonitor::commit_listener(std::vector *terminate) { sockaddr_in addr_in = {}; - socklen_t addr_len = {}; + socklen_t addr_len = {}; int socket; try { socket = incoming_socket_multicast(ip_addr, ip_port, addr_in, addr_len); } catch (const MonitorException &) { return; } - const auto addr = reinterpret_cast(&addr_in); + const auto addr = reinterpret_cast(&addr_in); char incoming_message[MESSAGE_SIZE] = {0}; // Polling for non blocking pollfd pfd = {}; - pfd.fd = socket; + pfd.fd = socket; pfd.events = POLLIN | POLLPRI; do { @@ -120,7 +120,8 @@ void capiocl::monitor::MulticastMonitor::commit_listener(std::vector(&addr_in); + const auto addr = reinterpret_cast(&addr_in); char incoming_message[MESSAGE_SIZE] = {0}; do { @@ -174,7 +175,7 @@ void capiocl::monitor::MulticastMonitor::home_node_listener( // Polling for non blocking pollfd pfd = {}; - pfd.fd = socket; + pfd.fd = socket; pfd.events = POLLIN | POLLPRI; // TODO: migrate to epoll for linux and kqueue on MacOS @@ -190,7 +191,8 @@ void capiocl::monitor::MulticastMonitor::home_node_listener( } // LCOV_EXCL_START - const auto incoming_size = recvfrom(socket, incoming_message, MESSAGE_SIZE, MSG_DONTWAIT, addr, &addr_len); + const auto incoming_size = + recvfrom(socket, incoming_message, MESSAGE_SIZE, MSG_DONTWAIT, addr, &addr_len); if (incoming_size < 0) { continue; } @@ -205,7 +207,7 @@ void capiocl::monitor::MulticastMonitor::home_node_listener( tokens.push_back(incoming_message_str.substr(start, end - start)); } start = end + 1; - end = incoming_message_str.find(' ', start); + end = incoming_message_str.find(' ', start); } if (start < incoming_message_str.length()) { @@ -222,7 +224,7 @@ void capiocl::monitor::MulticastMonitor::home_node_listener( // need "! " -> malformed message, skip continue; } - const auto &path = tokens[1]; + const auto &path = tokens[1]; const auto &home_node = tokens[2]; std::lock_guard lg(lock); home_nodes[path] = home_node; @@ -263,12 +265,12 @@ capiocl::monitor::MulticastMonitor::MulticastMonitor( config.getParameter("monitor.mcast.delay_ms", &MULTICAST_DELAY_MILLIS); commit_thread = - std::thread(&commit_listener, std::ref(_committed_files), std::ref(committed_lock), - MULTICAST_COMMIT_ADDR, MULTICAST_COMMIT_PORT, &this->terminate); + std::thread(&commit_listener, std::ref(_committed_files), std::ref(committed_lock), + MULTICAST_COMMIT_ADDR, MULTICAST_COMMIT_PORT, &this->terminate); home_node_thread = - std::thread(&home_node_listener, std::ref(_home_nodes), std::ref(home_node_lock), - MULTICAST_HOME_NODE_ADDR, MULTICAST_HOME_NODE_PORT, &this->terminate); + std::thread(&home_node_listener, std::ref(_home_nodes), std::ref(home_node_lock), + MULTICAST_HOME_NODE_ADDR, MULTICAST_HOME_NODE_PORT, &this->terminate); gethostname(_hostname, sizeof(_hostname)); _hostname[sizeof(_hostname) - 1] = '\0'; @@ -280,7 +282,8 @@ capiocl::monitor::MulticastMonitor::~MulticastMonitor() { home_node_thread.join(); } -bool capiocl::monitor::MulticastMonitor::isCommitted(const std::filesystem::path &path) const { { +bool capiocl::monitor::MulticastMonitor::isCommitted(const std::filesystem::path &path) const { + { const std::lock_guard lg(committed_lock); if (std::find(_committed_files.begin(), _committed_files.end(), path) != _committed_files.end()) { @@ -289,7 +292,8 @@ bool capiocl::monitor::MulticastMonitor::isCommitted(const std::filesystem::path } _send_message(MULTICAST_COMMIT_ADDR, MULTICAST_COMMIT_PORT, path, GET); - std::this_thread::sleep_for(std::chrono::milliseconds(MULTICAST_DELAY_MILLIS)); { + std::this_thread::sleep_for(std::chrono::milliseconds(MULTICAST_DELAY_MILLIS)); + { const std::lock_guard lg(committed_lock); return std::find(_committed_files.begin(), _committed_files.end(), path) != _committed_files.end(); @@ -313,8 +317,9 @@ void capiocl::monitor::MulticastMonitor::setHomeNode(const std::filesystem::path _home_nodes[path] = _hostname; } -std::string capiocl::monitor::MulticastMonitor::getHomeNode( - const std::filesystem::path &path) const { { +std::string +capiocl::monitor::MulticastMonitor::getHomeNode(const std::filesystem::path &path) const { + { const std::lock_guard lg(home_node_lock); if (const auto itm = _home_nodes.find(path); itm != _home_nodes.end()) { return itm->second; From c63eea07bb2f40bca44ef855afe56b7e3467632f Mon Sep 17 00:00:00 2001 From: Marco Edoardo Santimaria Date: Mon, 20 Jul 2026 14:40:27 +0200 Subject: [PATCH 14/16] Added log events --- src/Engine.cpp | 160 ++++++++++++++++++++++++++++++++++-- src/Monitor.cpp | 12 +++ src/Parser.cpp | 25 +++++- src/Serializer.cpp | 9 +- src/api.cpp | 34 ++++++-- src/configuration.cpp | 22 +++-- src/monitors/FileSystem.cpp | 27 +++++- src/monitors/Interface.cpp | 5 ++ src/monitors/Multicast.cpp | 49 +++++++++-- src/parsers/v1.1.cpp | 6 +- src/parsers/v1.cpp | 7 +- src/serializers/v1.1.cpp | 14 +++- src/serializers/v1.cpp | 14 +++- 13 files changed, 342 insertions(+), 42 deletions(-) diff --git a/src/Engine.cpp b/src/Engine.cpp index d98bc03..7376dcd 100644 --- a/src/Engine.cpp +++ b/src/Engine.cpp @@ -4,6 +4,7 @@ #include #include "calf/StdOutLogger.h" +#include "calf/StlLogger.h" #include "capiocl.hpp" #include "capiocl/configuration.h" #include "capiocl/engine.h" @@ -13,9 +14,15 @@ template class shared_lock_guard { public: /// @brief Constructor: acquire semaphore shared - explicit shared_lock_guard(SharedMutex &m) : mutex_(m) { mutex_.lock_shared(); } + explicit shared_lock_guard(SharedMutex &m) : mutex_(m) { + START_LOG(calf_current_tid(), "call()"); + mutex_.lock_shared(); + } /// @brief Destructor: release resources - ~shared_lock_guard() { mutex_.unlock_shared(); } + ~shared_lock_guard() { + START_LOG(calf_current_tid(), "call()"); + mutex_.unlock_shared(); + } shared_lock_guard(const shared_lock_guard &) = delete; shared_lock_guard &operator=(const shared_lock_guard &) = delete; @@ -26,6 +33,7 @@ template class shared_lock_guard { }; void capiocl::engine::Engine::print() const { + START_LOG(calf_current_tid(), "call()"); UPDATE_CALF_WORKFLOW_NAME(workflow_name); // First message CALF_PRINT_COLOR(CALF_CLI_LEVEL_INFO, " "); @@ -147,14 +155,19 @@ void capiocl::engine::Engine::print() const { } capiocl::engine::Engine::Engine(const bool use_default_settings) { + START_LOG(calf_current_tid(), "call()"); node_name = std::string(1024, '\0'); gethostname(node_name.data(), node_name.size()); node_name.resize(std::strlen(node_name.c_str())); if (const char *_wf_name = std::getenv("WORKFLOW_NAME"); _wf_name != nullptr) { this->workflow_name = _wf_name; + LOG("selected workflow name=%s source=environment node=%s", workflow_name.c_str(), + node_name.c_str()); } else { this->workflow_name = CAPIO_CL_DEFAULT_WF_NAME; + LOG("selected workflow name=%s source=default node=%s", workflow_name.c_str(), + node_name.c_str()); } if (use_default_settings) { @@ -163,6 +176,7 @@ capiocl::engine::Engine::Engine(const bool use_default_settings) { } void capiocl::engine::Engine::_newFile(const std::filesystem::path &path) const { + START_LOG(calf_current_tid(), "call()"); if (path.empty()) { return; } @@ -199,6 +213,10 @@ void capiocl::engine::Engine::_newFile(const std::filesystem::path &path) const } else { entry.store_in_memory = store_all_in_memory; } + LOG("creating entry path=%s source=%s commit_rule=%s fire_rule=%s memory=%d", + path.string().c_str(), matchSize > 0 ? matchKey.c_str() : "defaults", + entry.commit_rule.c_str(), entry.fire_rule.c_str(), + static_cast(entry.store_in_memory)); _capio_cl_entries.emplace(path, std::move(entry)); this->compute_directory_entry_count(path); } @@ -206,11 +224,14 @@ void capiocl::engine::Engine::_newFile(const std::filesystem::path &path) const void capiocl::engine::Engine::compute_directory_entry_count( const std::filesystem::path &path) const { + START_LOG(calf_current_tid(), "call()"); if (const auto parent = path.parent_path(); !parent.empty()) { if (const auto &entry = _capio_cl_entries.find(parent); entry != _capio_cl_entries.end()) { if (entry->second.enable_directory_count_update) { entry->second.directory_children_count++; entry->second.is_file = false; + LOG("updated directory path=%s children=%ld", parent.string().c_str(), + entry->second.directory_children_count); } else { return; } @@ -221,6 +242,7 @@ void capiocl::engine::Engine::compute_directory_entry_count( } bool capiocl::engine::Engine::contains(const std::filesystem::path &file) const { + START_LOG(calf_current_tid(), "call()"); shared_lock_guard slg(_shared_mutex); return std::any_of(_capio_cl_entries.begin(), _capio_cl_entries.end(), [&](auto const &entry) { return fnmatch(entry.first.c_str(), file.c_str(), FNM_NOESCAPE) == 0; @@ -228,6 +250,7 @@ bool capiocl::engine::Engine::contains(const std::filesystem::path &file) const } size_t capiocl::engine::Engine::size() const { + START_LOG(calf_current_tid(), "call()"); shared_lock_guard slg(_shared_mutex); return this->_capio_cl_entries.size(); } @@ -236,8 +259,8 @@ void capiocl::engine::Engine::add(std::filesystem::path &path, std::vector &consumers, const std::string &commit_rule, const std::string &fire_rule, bool permanent, bool exclude, - std::vector &dependencies) { - + std::vector &dependencies) { + START_LOG(calf_current_tid(), "call()"); if (path.empty()) { return; } @@ -252,26 +275,34 @@ void capiocl::engine::Engine::add(std::filesystem::path &path, std::vector(entry.permanent), static_cast(entry.excluded)); } void capiocl::engine::Engine::add(const std::filesystem::path &path, const CapioCLEntry &entry) const { - + START_LOG(calf_current_tid(), "call()"); std::lock_guard lg(_shared_mutex); if (_capio_cl_entries.find(path) == _capio_cl_entries.end()) { _capio_cl_entries[path] = entry; + LOG("inserted entry path=%s", path.string().c_str()); } else { _capio_cl_entries[path] += entry; + LOG("merged entry path=%s", path.string().c_str()); } } void capiocl::engine::Engine::newFile(const std::filesystem::path &path) const { + START_LOG(calf_current_tid(), "call()"); std::lock_guard lg(_shared_mutex); this->_newFile(path); } long capiocl::engine::Engine::getDirectoryFileCount(const std::filesystem::path &path) const { - + START_LOG(calf_current_tid(), "call()"); if (path.empty()) { return 0; } @@ -287,7 +318,7 @@ long capiocl::engine::Engine::getDirectoryFileCount(const std::filesystem::path void capiocl::engine::Engine::addProducer(const std::filesystem::path &path, std::string &producer) { - + START_LOG(calf_current_tid(), "call()"); if (path.empty()) { return; } @@ -301,6 +332,8 @@ void capiocl::engine::Engine::addProducer(const std::filesystem::path &path, auto &vec = itm->second.producers; if (std::find(vec.begin(), vec.end(), producer) == vec.end()) { vec.emplace_back(producer); + LOG("added producer path=%s producer=%s count=%zu", path.string().c_str(), + producer.c_str(), vec.size()); return; } else { return; @@ -314,6 +347,7 @@ void capiocl::engine::Engine::addProducer(const std::filesystem::path &path, void capiocl::engine::Engine::addConsumer(const std::filesystem::path &path, std::string &consumer) { + START_LOG(calf_current_tid(), "call()"); if (path.empty()) { return; } @@ -325,6 +359,8 @@ void capiocl::engine::Engine::addConsumer(const std::filesystem::path &path, auto &vec = itm->second.consumers; if (std::find(vec.begin(), vec.end(), consumer) == vec.end()) { vec.emplace_back(consumer); + LOG("added consumer path=%s consumer=%s count=%zu", path.string().c_str(), + consumer.c_str(), vec.size()); } return; } @@ -336,6 +372,7 @@ void capiocl::engine::Engine::addConsumer(const std::filesystem::path &path, void capiocl::engine::Engine::addFileDependency(const std::filesystem::path &path, std::filesystem::path &file_dependency) { + START_LOG(calf_current_tid(), "call()"); if (path.empty()) { return; } @@ -346,6 +383,8 @@ void capiocl::engine::Engine::addFileDependency(const std::filesystem::path &pat auto &vec = itm->second.file_dependencies; if (std::find(vec.begin(), vec.end(), file_dependency) == vec.end()) { vec.emplace_back(file_dependency); + LOG("added dependency path=%s dependency=%s count=%zu", path.string().c_str(), + file_dependency.string().c_str(), vec.size()); } return; } @@ -357,6 +396,7 @@ void capiocl::engine::Engine::addFileDependency(const std::filesystem::path &pat void capiocl::engine::Engine::setCommitRule(const std::filesystem::path &path, const std::string &commit_rule) { + START_LOG(calf_current_tid(), "call()"); if (path.empty()) { return; } @@ -365,6 +405,10 @@ void capiocl::engine::Engine::setCommitRule(const std::filesystem::path &path, { std::lock_guard lg(_shared_mutex); if (const auto itm = _capio_cl_entries.find(path); itm != _capio_cl_entries.end()) { + if (itm->second.commit_rule != commit) { + LOG("changing commit rule path=%s old=%s new=%s", path.string().c_str(), + itm->second.commit_rule.c_str(), commit.c_str()); + } itm->second.commit_rule = commit; return; } @@ -377,6 +421,7 @@ void capiocl::engine::Engine::setCommitRule(const std::filesystem::path &path, } std::string capiocl::engine::Engine::getCommitRule(const std::filesystem::path &path) const { + START_LOG(calf_current_tid(), "call()"); if (path.empty()) { return commitRules::ON_TERMINATION; } @@ -397,6 +442,7 @@ std::string capiocl::engine::Engine::getCommitRule(const std::filesystem::path & } std::string capiocl::engine::Engine::getFireRule(const std::filesystem::path &path) const { + START_LOG(calf_current_tid(), "call()"); if (path.empty()) { return fireRules::NO_UPDATE; } @@ -418,6 +464,7 @@ std::string capiocl::engine::Engine::getFireRule(const std::filesystem::path &pa void capiocl::engine::Engine::setFireRule(const std::filesystem::path &path, const std::string &fire_rule) { + START_LOG(calf_current_tid(), "call()"); if (path.empty()) { return; } @@ -427,6 +474,10 @@ void capiocl::engine::Engine::setFireRule(const std::filesystem::path &path, { std::lock_guard lg(_shared_mutex); if (const auto itm = _capio_cl_entries.find(path); itm != _capio_cl_entries.end()) { + if (itm->second.fire_rule != fire) { + LOG("changing fire rule path=%s old=%s new=%s", path.string().c_str(), + itm->second.fire_rule.c_str(), fire.c_str()); + } itm->second.fire_rule = fire; return; } @@ -437,6 +488,7 @@ void capiocl::engine::Engine::setFireRule(const std::filesystem::path &path, } bool capiocl::engine::Engine::isFirable(const std::filesystem::path &path) const { + START_LOG(calf_current_tid(), "call()"); if (path.empty()) { return true; } @@ -456,6 +508,7 @@ bool capiocl::engine::Engine::isFirable(const std::filesystem::path &path) const } void capiocl::engine::Engine::setPermanent(const std::filesystem::path &path, bool value) { + START_LOG(calf_current_tid(), "call()"); if (path.empty()) { return; } @@ -463,6 +516,10 @@ void capiocl::engine::Engine::setPermanent(const std::filesystem::path &path, bo { std::lock_guard lg(_shared_mutex); if (const auto itm = _capio_cl_entries.find(path); itm != _capio_cl_entries.end()) { + if (itm->second.permanent != value) { + LOG("changing permanent path=%s old=%d new=%d", path.string().c_str(), + static_cast(itm->second.permanent), static_cast(value)); + } itm->second.permanent = value; return; } @@ -472,6 +529,7 @@ void capiocl::engine::Engine::setPermanent(const std::filesystem::path &path, bo } bool capiocl::engine::Engine::isPermanent(const std::filesystem::path &path) const { + START_LOG(calf_current_tid(), "call()"); if (path.empty()) { return true; } @@ -491,14 +549,18 @@ bool capiocl::engine::Engine::isPermanent(const std::filesystem::path &path) con } bool capiocl::engine::Engine::isCommitted(const std::filesystem::path &path) const { + START_LOG(calf_current_tid(), "call()"); return monitor.isCommitted(path); } void capiocl::engine::Engine::setCommitted(const std::filesystem::path &path) const { + START_LOG(calf_current_tid(), "call()"); monitor.setCommitted(path); + LOG("dispatched committed update path=%s", path.string().c_str()); } std::vector capiocl::engine::Engine::getPaths() const { + START_LOG(calf_current_tid(), "call()"); shared_lock_guard slg(_shared_mutex); std::vector paths; @@ -509,12 +571,17 @@ std::vector capiocl::engine::Engine::getPaths() const { } void capiocl::engine::Engine::setExclude(const std::filesystem::path &path, const bool value) { + START_LOG(calf_current_tid(), "call()"); if (path.empty()) { return; } { std::lock_guard lg(_shared_mutex); if (const auto itm = _capio_cl_entries.find(path); itm != _capio_cl_entries.end()) { + if (itm->second.excluded != value) { + LOG("changing excluded path=%s old=%d new=%d", path.string().c_str(), + static_cast(itm->second.excluded), static_cast(value)); + } itm->second.excluded = value; return; } @@ -524,6 +591,7 @@ void capiocl::engine::Engine::setExclude(const std::filesystem::path &path, cons } void capiocl::engine::Engine::setDirectory(const std::filesystem::path &path) { + START_LOG(calf_current_tid(), "call()"); if (path.empty()) { return; } @@ -531,6 +599,9 @@ void capiocl::engine::Engine::setDirectory(const std::filesystem::path &path) { { std::lock_guard lg(_shared_mutex); if (const auto itm = _capio_cl_entries.find(path); itm != _capio_cl_entries.end()) { + if (itm->second.is_file) { + LOG("changing entry type path=%s old=file new=directory", path.string().c_str()); + } itm->second.is_file = false; return; } @@ -540,6 +611,7 @@ void capiocl::engine::Engine::setDirectory(const std::filesystem::path &path) { } void capiocl::engine::Engine::setFile(const std::filesystem::path &path) { + START_LOG(calf_current_tid(), "call()"); if (path.empty()) { return; } @@ -547,6 +619,9 @@ void capiocl::engine::Engine::setFile(const std::filesystem::path &path) { { std::lock_guard lg(_shared_mutex); if (const auto itm = _capio_cl_entries.find(path); itm != _capio_cl_entries.end()) { + if (!itm->second.is_file) { + LOG("changing entry type path=%s old=directory new=file", path.string().c_str()); + } itm->second.is_file = true; return; } @@ -556,6 +631,7 @@ void capiocl::engine::Engine::setFile(const std::filesystem::path &path) { } bool capiocl::engine::Engine::isFile(const std::filesystem::path &path) const { + START_LOG(calf_current_tid(), "call()"); if (path.empty()) { return true; } @@ -575,6 +651,7 @@ bool capiocl::engine::Engine::isFile(const std::filesystem::path &path) const { } bool capiocl::engine::Engine::isDirectory(const std::filesystem::path &path) const { + START_LOG(calf_current_tid(), "call()"); if (path.empty()) { return true; } @@ -583,6 +660,7 @@ bool capiocl::engine::Engine::isDirectory(const std::filesystem::path &path) con void capiocl::engine::Engine::setCommitedCloseNumber(const std::filesystem::path &path, const long num) { + START_LOG(calf_current_tid(), "call()"); if (path.empty()) { return; } @@ -590,6 +668,10 @@ void capiocl::engine::Engine::setCommitedCloseNumber(const std::filesystem::path { std::lock_guard lg(_shared_mutex); if (const auto itm = _capio_cl_entries.find(path); itm != _capio_cl_entries.end()) { + if (itm->second.commit_on_close_count != num) { + LOG("changing commit-close count path=%s old=%ld new=%ld", path.string().c_str(), + itm->second.commit_on_close_count, num); + } itm->second.commit_on_close_count = num; return; } @@ -600,6 +682,7 @@ void capiocl::engine::Engine::setCommitedCloseNumber(const std::filesystem::path void capiocl::engine::Engine::setDirectoryFileCount(const std::filesystem::path &path, const long num) { + START_LOG(calf_current_tid(), "call()"); if (path.empty()) { return; } @@ -614,6 +697,8 @@ void capiocl::engine::Engine::setDirectoryFileCount(const std::filesystem::path if (const auto itm = _capio_cl_entries.find(path); itm != _capio_cl_entries.end()) { itm->second.directory_children_count = num; itm->second.enable_directory_count_update = false; + LOG("fixed directory count path=%s count=%ld automatic_updates=disabled", + path.string().c_str(), num); return; } this->_newFile(path); @@ -622,16 +707,19 @@ void capiocl::engine::Engine::setDirectoryFileCount(const std::filesystem::path } void capiocl::engine::Engine::remove(const std::filesystem::path &path) const { + START_LOG(calf_current_tid(), "call()"); std::lock_guard lg(_shared_mutex); if (const auto itm = _capio_cl_entries.find(path); itm == _capio_cl_entries.end()) { return; } _capio_cl_entries.erase(path); + LOG("removed entry path=%s", path.string().c_str()); } std::vector capiocl::engine::Engine::getConsumers(const std::filesystem::path &path) const { + START_LOG(calf_current_tid(), "call()"); std::lock_guard lg(_shared_mutex); if (const auto itm = _capio_cl_entries.find(path); itm != _capio_cl_entries.end()) { @@ -642,6 +730,7 @@ capiocl::engine::Engine::getConsumers(const std::filesystem::path &path) const { bool capiocl::engine::Engine::isConsumer(const std::filesystem::path &path, const std::string &app_name) const { + START_LOG(calf_current_tid(), "call()"); if (path.empty()) { return true; } @@ -653,6 +742,8 @@ bool capiocl::engine::Engine::isConsumer(const std::filesystem::path &path, if (fnmatch(pattern.c_str(), path.c_str(), FNM_NOESCAPE) == 0) { const auto &consumers = entry.consumers; if (std::find(consumers.begin(), consumers.end(), app_name) != consumers.end()) { + LOG("consumer matched path=%s pattern=%s application=%s", path.string().c_str(), + pattern.c_str(), app_name.c_str()); return true; } } @@ -668,6 +759,7 @@ bool capiocl::engine::Engine::isConsumer(const std::filesystem::path &path, std::vector capiocl::engine::Engine::getProducers(const std::filesystem::path &path) const { + START_LOG(calf_current_tid(), "call()"); if (path.empty()) { return {}; } @@ -689,6 +781,7 @@ capiocl::engine::Engine::getProducers(const std::filesystem::path &path) const { bool capiocl::engine::Engine::isProducer(const std::filesystem::path &path, const std::string &app_name) const { + START_LOG(calf_current_tid(), "call()"); if (path.empty()) { return true; } @@ -699,6 +792,8 @@ bool capiocl::engine::Engine::isProducer(const std::filesystem::path &path, if (fnmatch(pattern.c_str(), path.c_str(), FNM_NOESCAPE) == 0) { const auto &producers = entry.producers; if (std::find(producers.begin(), producers.end(), app_name) != producers.end()) { + LOG("producer matched path=%s pattern=%s application=%s", path.string().c_str(), + pattern.c_str(), app_name.c_str()); return true; } } @@ -714,6 +809,7 @@ bool capiocl::engine::Engine::isProducer(const std::filesystem::path &path, void capiocl::engine::Engine::setFileDeps(const std::filesystem::path &path, const std::vector &dependencies) { + START_LOG(calf_current_tid(), "call()"); if (path.empty()) { return; } @@ -731,6 +827,8 @@ void capiocl::engine::Engine::setFileDeps(const std::filesystem::path &path, if (const auto itm = _capio_cl_entries.find(path); itm != _capio_cl_entries.end()) { itm->second.file_dependencies = dependencies; + LOG("replaced dependencies path=%s count=%zu", path.string().c_str(), + dependencies.size()); return; } this->_newFile(path); @@ -739,6 +837,7 @@ void capiocl::engine::Engine::setFileDeps(const std::filesystem::path &path, } long capiocl::engine::Engine::getCommitCloseCount(const std::filesystem::path &path) const { + START_LOG(calf_current_tid(), "call()"); if (path.empty()) { return 0; } @@ -759,6 +858,7 @@ long capiocl::engine::Engine::getCommitCloseCount(const std::filesystem::path &p std::vector capiocl::engine::Engine::getCommitOnFileDependencies(const std::filesystem::path &path) const { + START_LOG(calf_current_tid(), "call()"); shared_lock_guard slg(_shared_mutex); if (const auto itm = _capio_cl_entries.find(path); itm != _capio_cl_entries.end()) { @@ -768,6 +868,7 @@ capiocl::engine::Engine::getCommitOnFileDependencies(const std::filesystem::path } void capiocl::engine::Engine::setStoreFileInMemory(const std::filesystem::path &path) { + START_LOG(calf_current_tid(), "call()"); if (path.empty()) { return; } @@ -776,6 +877,9 @@ void capiocl::engine::Engine::setStoreFileInMemory(const std::filesystem::path & std::lock_guard lg(_shared_mutex); if (const auto itm = _capio_cl_entries.find(path); itm != _capio_cl_entries.end()) { + if (!itm->second.store_in_memory) { + LOG("changing storage path=%s target=memory", path.string().c_str()); + } itm->second.store_in_memory = true; return; } @@ -785,6 +889,7 @@ void capiocl::engine::Engine::setStoreFileInMemory(const std::filesystem::path & } void capiocl::engine::Engine::setAllStoreInMemory() { + START_LOG(calf_current_tid(), "call()"); { std::lock_guard lg(_shared_mutex); this->store_all_in_memory = true; @@ -794,25 +899,35 @@ void capiocl::engine::Engine::setAllStoreInMemory() { for (const auto &path : paths) { this->setStoreFileInMemory(path); } + LOG("enabled global memory storage updated_entries=%zu", paths.size()); } void capiocl::engine::Engine::setWorkflowName(const std::string &name) { + START_LOG(calf_current_tid(), "call()"); std::lock_guard lg(_shared_mutex); + if (this->workflow_name != name) { + LOG("changing workflow name old=%s new=%s", this->workflow_name.c_str(), name.c_str()); + } this->workflow_name = name; } const std::string &capiocl::engine::Engine::getWorkflowName() const { + START_LOG(calf_current_tid(), "call()"); shared_lock_guard slg(_shared_mutex); return this->workflow_name; } void capiocl::engine::Engine::setStoreFileInFileSystem(const std::filesystem::path &path) { + START_LOG(calf_current_tid(), "call()"); if (path.empty()) { return; } { std::lock_guard lg(_shared_mutex); if (const auto itm = _capio_cl_entries.find(path); itm != _capio_cl_entries.end()) { + if (itm->second.store_in_memory) { + LOG("changing storage path=%s target=filesystem", path.string().c_str()); + } itm->second.store_in_memory = false; return; } @@ -822,6 +937,7 @@ void capiocl::engine::Engine::setStoreFileInFileSystem(const std::filesystem::pa } bool capiocl::engine::Engine::isStoredInMemory(const std::filesystem::path &path) const { + START_LOG(calf_current_tid(), "call()"); if (path.empty()) { return true; } @@ -841,6 +957,7 @@ bool capiocl::engine::Engine::isStoredInMemory(const std::filesystem::path &path } std::vector capiocl::engine::Engine::getFileToStoreInMemory() const { + START_LOG(calf_current_tid(), "call()"); std::vector files; shared_lock_guard slg(_shared_mutex); @@ -856,14 +973,18 @@ std::vector capiocl::engine::Engine::getFileToStoreInMemory() const std::set capiocl::engine::Engine::getHomeNode(const std::filesystem::path &path) const { + START_LOG(calf_current_tid(), "call()"); return monitor.getHomeNode(path); } void capiocl::engine::Engine::setHomeNode(const std::filesystem::path &path) const { + START_LOG(calf_current_tid(), "call()"); monitor.setHomeNode(path); + LOG("dispatched home-node update path=%s node=%s", path.string().c_str(), node_name.c_str()); } bool capiocl::engine::Engine::isExcluded(const std::filesystem::path &path) const { + START_LOG(calf_current_tid(), "call()"); if (path.empty()) { return true; } @@ -882,6 +1003,7 @@ bool capiocl::engine::Engine::isExcluded(const std::filesystem::path &path) cons } bool capiocl::engine::Engine::operator==(const Engine &other) const { + START_LOG(calf_current_tid(), "call()"); const auto &other_entries = other._capio_cl_entries; if (this->_capio_cl_entries.size() != other_entries.size()) { @@ -900,8 +1022,10 @@ bool capiocl::engine::Engine::operator==(const Engine &other) const { return true; } void capiocl::engine::Engine::loadConfiguration(const std::string &path) { + START_LOG(calf_current_tid(), "call()"); UPDATE_CALF_WORKFLOW_NAME(workflow_name); configuration.load(path); + LOG("loaded engine configuration path=%s", path.c_str()); std::string multicast_monitor_enabled, fs_monitor_enabled; @@ -909,11 +1033,14 @@ void capiocl::engine::Engine::loadConfiguration(const std::string &path) { configuration.getParameter("monitor.mcast.enabled", &multicast_monitor_enabled); } catch (...) { multicast_monitor_enabled = "false"; + LOG("configuration fallback key=monitor.mcast.enabled value=false"); } if (multicast_monitor_enabled == "true") { monitor.registerMonitorBackend(new monitor::MulticastMonitor(configuration)); + LOG("registered monitor backend=multicast"); } else { + LOG("skipped monitor backend=multicast reason=disabled"); CALF_PRINT_COLOR(CALF_CLI_LEVEL_WARNING, "Skipping registration of MulticastMonitor"); } @@ -921,27 +1048,35 @@ void capiocl::engine::Engine::loadConfiguration(const std::string &path) { configuration.getParameter("monitor.filesystem.enabled", &fs_monitor_enabled); } catch (...) { fs_monitor_enabled = "false"; + LOG("configuration fallback key=monitor.filesystem.enabled value=false"); } if (fs_monitor_enabled == "true") { monitor.registerMonitorBackend(new monitor::FileSystemMonitor()); + LOG("registered monitor backend=filesystem"); } else { + LOG("skipped monitor backend=filesystem reason=disabled"); CALF_PRINT_COLOR(CALF_CLI_LEVEL_WARNING, "Skipping registration of FileSystemMonitor"); } } void capiocl::engine::Engine::useDefaultConfiguration() { + START_LOG(calf_current_tid(), "call()"); configuration.loadDefaults(); // TODO: add a vector with registered instances of backends to avoid multiple instantiations monitor.registerMonitorBackend(new monitor::MulticastMonitor(configuration)); monitor.registerMonitorBackend(new monitor::FileSystemMonitor()); + LOG("loaded default configuration monitor_backends=multicast,filesystem"); } void capiocl::engine::Engine::startApiServer() { + START_LOG(calf_current_tid(), "call()"); webapi_server = std::make_unique(this, configuration); + LOG("started API server"); } capiocl::engine::CapioCLEntry capiocl::engine::CapioCLEntry::fromJson(const std::string &in) { + START_LOG(calf_current_tid(), "call()"); jsoncons::json j = jsoncons::json::parse(in); CapioCLEntry entry; @@ -972,10 +1107,14 @@ capiocl::engine::CapioCLEntry capiocl::engine::CapioCLEntry::fromJson(const std: entry.excluded = j.get_value_or("excluded", entry.excluded); entry.is_file = j.get_value_or("is_file", entry.is_file); + LOG("decoded entry producers=%zu consumers=%zu dependencies=%zu commit_rule=%s fire_rule=%s", + entry.producers.size(), entry.consumers.size(), entry.file_dependencies.size(), + entry.commit_rule.c_str(), entry.fire_rule.c_str()); return entry; } std::string capiocl::engine::CapioCLEntry::toJson() const { + START_LOG(calf_current_tid(), "call()"); jsoncons::json j; j["producers"] = producers; j["consumers"] = consumers; @@ -1000,6 +1139,7 @@ std::string capiocl::engine::CapioCLEntry::toJson() const { } capiocl::engine::CapioCLEntry &capiocl::engine::CapioCLEntry::operator+=(const CapioCLEntry &rhs) { + START_LOG(calf_current_tid(), "call()"); auto merge_vec = [](std::vector &dest, const std::vector &src) { dest.insert(dest.end(), src.begin(), src.end()); }; @@ -1026,13 +1166,14 @@ capiocl::engine::CapioCLEntry &capiocl::engine::CapioCLEntry::operator+=(const C } capiocl::engine::CapioCLEntry capiocl::engine::CapioCLEntry::operator+(const CapioCLEntry &rhs) { + START_LOG(calf_current_tid(), "call()"); CapioCLEntry result = *this; result += rhs; return result; } bool capiocl::engine::CapioCLEntry::operator==(const CapioCLEntry &other) { - + START_LOG(calf_current_tid(), "call()"); if (this->commit_rule != other.commit_rule || this->fire_rule != other.fire_rule || this->permanent != other.permanent || this->excluded != other.excluded || this->is_file != other.is_file || @@ -1082,5 +1223,6 @@ bool capiocl::engine::CapioCLEntry::operator==(const CapioCLEntry &other) { } bool capiocl::engine::CapioCLEntry::operator!=(const CapioCLEntry &other) { + START_LOG(calf_current_tid(), "call()"); return !(*this == other); -} \ No newline at end of file +} diff --git a/src/Monitor.cpp b/src/Monitor.cpp index 46155f0..c742f3a 100644 --- a/src/Monitor.cpp +++ b/src/Monitor.cpp @@ -1,31 +1,42 @@ #include "capiocl/monitor.h" +#include "calf/StlLogger.h" #include "capiocl.hpp" capiocl::monitor::MonitorException::MonitorException(const std::string &msg) : message(msg) { + START_LOG(calf_current_tid(), "call()"); + LOG("monitor error message=%s", msg.c_str()); std::cerr << msg << std::endl; } bool capiocl::monitor::Monitor::isCommitted(const std::filesystem::path &path) const { + START_LOG(calf_current_tid(), "call()"); return std::any_of(interfaces.begin(), interfaces.end(), [&path](const auto &interface) { return interface->isCommitted(path); }); } void capiocl::monitor::Monitor::setCommitted(std::filesystem::path path) const { + START_LOG(calf_current_tid(), "call()"); + LOG("setting committed path=%s backends=%zu", path.string().c_str(), interfaces.size()); std::for_each(interfaces.begin(), interfaces.end(), [&path](const auto &interface) { interface->setCommitted(path); }); } void capiocl::monitor::Monitor::registerMonitorBackend(const MonitorInterface *interface) { + START_LOG(calf_current_tid(), "call()"); interfaces.emplace_back(interface); + LOG("registered monitor backend total=%zu", interfaces.size()); } void capiocl::monitor::Monitor::setHomeNode(const std::filesystem::path &path) const { + START_LOG(calf_current_tid(), "call()"); + LOG("setting home node path=%s backends=%zu", path.string().c_str(), interfaces.size()); std::for_each(interfaces.begin(), interfaces.end(), [&path](const auto &interface) { interface->setHomeNode(path); }); } std::set capiocl::monitor::Monitor::getHomeNode(const std::filesystem::path &path) const { + START_LOG(calf_current_tid(), "call()"); std::set home_nodes; for (const auto &interface : interfaces) { const auto node = interface->getHomeNode(path); @@ -38,6 +49,7 @@ capiocl::monitor::Monitor::getHomeNode(const std::filesystem::path &path) const } capiocl::monitor::Monitor::~Monitor() { + START_LOG(calf_current_tid(), "call()"); for (const auto &interface : interfaces) { delete interface; } diff --git a/src/Parser.cpp b/src/Parser.cpp index 0d80c78..2a9d936 100644 --- a/src/Parser.cpp +++ b/src/Parser.cpp @@ -2,22 +2,26 @@ #include #include "calf/StdOutLogger.h" +#include "calf/StlLogger.h" #include "capiocl.hpp" #include "capiocl/engine.h" #include "capiocl/parser.h" capiocl::parser::ParserException::ParserException(const std::string &msg) : message(msg) { + START_LOG(calf_current_tid(), "call()"); UPDATE_CALF_WORKFLOW_NAME(""); CALF_PRINT_COLOR(CALF_CLI_LEVEL_ERROR, "%s", msg.c_str()); } jsoncons::jsonschema::json_schema capiocl::parser::Parser::loadSchema(const char *data) { + START_LOG(calf_current_tid(), "call()"); return jsoncons::jsonschema::make_json_schema(jsoncons::json::parse(data)); } std::filesystem::path capiocl::parser::Parser::resolve(std::filesystem::path path, const std::filesystem::path &prefix) { + START_LOG(calf_current_tid(), "call()"); UPDATE_CALF_WORKFLOW_NAME(""); if (prefix.empty()) { return path; @@ -35,11 +39,13 @@ std::filesystem::path capiocl::parser::Parser::resolve(std::filesystem::path pat } void capiocl::parser::Parser::validate_json(const jsoncons::json &doc, const char *str_schema) { + START_LOG(calf_current_tid(), "call()"); jsoncons::jsonschema::json_schema schema = loadSchema(str_schema); try { // throws jsoncons::jsonschema::validation_error on failure schema.validate(doc); } catch (const jsoncons::jsonschema::validation_error &e) { + LOG("JSON validation failed error=%s", e.what()); UPDATE_CALF_WORKFLOW_NAME(""); CALF_PRINT_COLOR(CALF_CLI_LEVEL_ERROR, "%s", e.what()); throw ParserException("JSON validation failed!"); @@ -48,19 +54,28 @@ void capiocl::parser::Parser::validate_json(const jsoncons::json &doc, const cha capiocl::engine::Engine *capiocl::parser::Parser::parse(const std::filesystem::path &source, const std::filesystem::path &resolve_prefix, - bool store_only_in_memory) { - + bool store_only_in_memory) { + START_LOG(calf_current_tid(), "call()"); + LOG("parse requested source=%s resolve_prefix=%s memory_only=%d", source.string().c_str(), + resolve_prefix.string().c_str(), static_cast(store_only_in_memory)); if (source.empty()) { throw ParserException("Empty source file name!"); } std::ifstream file(source); if (!file.is_open()) { + LOG("failed to open parse source=%s", source.string().c_str()); throw ParserException("Failed to open file!"); } std::string capio_cl_release; { - jsoncons::json doc = jsoncons::json::parse(file); + jsoncons::json doc; + try { + doc = jsoncons::json::parse(file); + } catch (const jsoncons::json_exception &e) { + LOG("failed to decode JSON source=%s error=%s", source.string().c_str(), e.what()); + throw; + } if (!doc.contains("version")) { capio_cl_release = CAPIO_CL_VERSION::V1; } else { @@ -79,6 +94,8 @@ capiocl::engine::Engine *capiocl::parser::Parser::parse(const std::filesystem::p } else if (capio_cl_release == CAPIO_CL_VERSION::V1_1) { return available_parsers::parse_v1_1(source, resolve_prefix, store_only_in_memory); } else { + LOG("unsupported specification version=%s source=%s", capio_cl_release.c_str(), + source.string().c_str()); throw ParserException("Invalid CAPIO-CL specification version!"); } -} \ No newline at end of file +} diff --git a/src/Serializer.cpp b/src/Serializer.cpp index 38afd54..e8d4f78 100644 --- a/src/Serializer.cpp +++ b/src/Serializer.cpp @@ -3,13 +3,15 @@ #include #include "calf/StdOutLogger.h" +#include "calf/StlLogger.h" #include "capiocl.hpp" #include "capiocl/engine.h" #include "capiocl/serializer.h" void capiocl::serializer::Serializer::dump(const engine::Engine &engine, const std::filesystem::path &filename, - const std::string &version) { + const std::string &version) { + START_LOG(calf_current_tid(), "call()"); UPDATE_CALF_WORKFLOW_NAME(engine.getWorkflowName()); if (version == CAPIO_CL_VERSION::V1) { CALF_PRINT_COLOR(CALF_CLI_LEVEL_INFO, "Serializing engine with V1 specification"); @@ -18,6 +20,8 @@ void capiocl::serializer::Serializer::dump(const engine::Engine &engine, CALF_PRINT_COLOR(CALF_CLI_LEVEL_INFO, "Serializing engine with V1.1 specification"); available_serializers::serialize_v1_1(engine, filename); } else { + LOG("serializer unavailable version=%s workflow=%s output=%s", version.c_str(), + engine.getWorkflowName().c_str(), filename.string().c_str()); const auto message = "No serializer available for CAPIO-CL version: " + version; throw SerializerException(message); } @@ -25,6 +29,7 @@ void capiocl::serializer::Serializer::dump(const engine::Engine &engine, capiocl::serializer::SerializerException::SerializerException(const std::string &msg) : message(msg) { + START_LOG(calf_current_tid(), "call()"); UPDATE_CALF_WORKFLOW_NAME(""); CALF_PRINT_COLOR(CALF_CLI_LEVEL_ERROR, "%s", msg.c_str()); -} \ No newline at end of file +} diff --git a/src/api.cpp b/src/api.cpp index 8c73e2c..a6d27ce 100644 --- a/src/api.cpp +++ b/src/api.cpp @@ -10,6 +10,7 @@ #include #include "calf/StdOutLogger.h" +#include "calf/StlLogger.h" #include "capiocl/api.h" #include "capiocl/engine.h" @@ -19,8 +20,8 @@ bool thread_ready = false; /// @brief Main WebServer thread function void server(const std::string &address, const int port, capiocl::engine::Engine *engine, - std::atomic *terminate) { - + std::atomic *terminate) { + START_LOG(calf_current_tid(), "call()"); UPDATE_CALF_WORKFLOW_NAME(engine->getWorkflowName()); constexpr int RECV_BUF_SIZE = 65535; @@ -28,21 +29,30 @@ void server(const std::string &address, const int port, capiocl::engine::Engine const auto &wf_name = engine->getWorkflowName(); int fd = socket(AF_INET, SOCK_DGRAM, 0); + if (fd < 0) { + LOG("API socket creation failed address=%s port=%d errno=%d", address.c_str(), port, errno); + } int reuse = 1; - setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof(reuse)); + if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof(reuse)) < 0) { + LOG("API socket setup failed operation=SO_REUSEADDR errno=%d", errno); + } sockaddr_in localAddr{}; localAddr.sin_family = AF_INET; localAddr.sin_port = htons(port); localAddr.sin_addr.s_addr = INADDR_ANY; - bind(fd, reinterpret_cast(&localAddr), sizeof(localAddr)); + if (bind(fd, reinterpret_cast(&localAddr), sizeof(localAddr)) < 0) { + LOG("API socket setup failed operation=bind errno=%d", errno); + } ip_mreq group{}; group.imr_multiaddr.s_addr = inet_addr(address.c_str()); group.imr_interface.s_addr = INADDR_ANY; - setsockopt(fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, &group, sizeof(group)); + if (setsockopt(fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, &group, sizeof(group)) < 0) { + LOG("API socket setup failed operation=IP_ADD_MEMBERSHIP errno=%d", errno); + } char buffer[RECV_BUF_SIZE] = {0}; sockaddr_in srcAddr{}; @@ -52,7 +62,9 @@ void server(const std::string &address, const int port, capiocl::engine::Engine timeval tv{}; tv.tv_sec = 0; tv.tv_usec = 500; - setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)); + if (setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)) < 0) { + LOG("API socket setup failed operation=SO_RCVTIMEO errno=%d", errno); + } thread_ready = true; _setupCv.notify_all(); @@ -90,23 +102,26 @@ void server(const std::string &address, const int port, capiocl::engine::Engine if (workflow_name == wf_name) { engine->add(path, rule); + LOG("applied API rule workflow=%s path=%s", workflow_name.c_str(), path.c_str()); } else { continue; } } catch (const jsoncons::json_exception &e) { + LOG("rejected invalid API JSON error=%s", e.what()); CALF_PRINT_COLOR(CALF_CLI_LEVEL_ERROR, "APIServer: Received invalid json: %s", e.what()); } } close(fd); + LOG("API server stopped address=%s port=%d", address.c_str(), port); } capiocl::api::CapioClApiServer::CapioClApiServer(engine::Engine *engine, configuration::CapioClConfiguration &config) : capiocl_configuration(config) { - + START_LOG(calf_current_tid(), "call()"); UPDATE_CALF_WORKFLOW_NAME(engine->getWorkflowName()); std::string address; @@ -115,12 +130,14 @@ capiocl::api::CapioClApiServer::CapioClApiServer(engine::Engine *engine, config.getParameter("dynamic_api.ip", &address); // GCOVR_EXCL_LINE } catch (...) { address = configuration::defaults::DEFAULT_API_MULTICAST_IP.v; + LOG("API configuration fallback key=dynamic_api.ip value=%s", address.c_str()); } try { config.getParameter("dynamic_api.port", &port); // GCOVR_EXCL_LINE } catch (...) { port = std::stoi(configuration::defaults::DEFAULT_API_MULTICAST_PORT.v); + LOG("API configuration fallback key=dynamic_api.port value=%d", port); } _webApiThread = std::thread(server, address, port, engine, &_terminate); @@ -129,9 +146,12 @@ capiocl::api::CapioClApiServer::CapioClApiServer(engine::Engine *engine, _setupCv.wait(lock, [] { return thread_ready; }); CALF_PRINT_COLOR(CALF_CLI_LEVEL_INFO, "API server @ %s:%d", address.c_str(), port); + LOG("API server thread ready address=%s port=%d", address.c_str(), port); } capiocl::api::CapioClApiServer::~CapioClApiServer() { + START_LOG(calf_current_tid(), "call()"); _terminate = true; _webApiThread.join(); + LOG("API server thread joined"); } diff --git a/src/configuration.cpp b/src/configuration.cpp index 4d7eb35..3c50af4 100644 --- a/src/configuration.cpp +++ b/src/configuration.cpp @@ -2,12 +2,14 @@ #include #include "calf/StdOutLogger.h" +#include "calf/StlLogger.h" #include "capiocl/configuration.h" #include "toml++/toml.hpp" void load_config_to_memory(const toml::table &tbl, std::unordered_map &map, - const std::string &prefix = "") { + const std::string &prefix = "") { + START_LOG(calf_current_tid(), "call()"); for (const auto &[key, value] : tbl) { std::string full_key; if (prefix.empty()) { @@ -35,6 +37,7 @@ void load_config_to_memory(const toml::table &tbl, } void capiocl::configuration::CapioClConfiguration::loadDefaults() { + START_LOG(calf_current_tid(), "call()"); this->set(defaults::DEFAULT_MONITOR_MCAST_IP); this->set(defaults::DEFAULT_MONITOR_MCAST_PORT); this->set(defaults::DEFAULT_MONITOR_HOMENODE_IP); @@ -44,17 +47,22 @@ void capiocl::configuration::CapioClConfiguration::loadDefaults() { this->set(defaults::DEFAULT_MONITOR_MCAST_ENABLED); this->set(defaults::DEFAULT_API_MULTICAST_PORT); this->set(defaults::DEFAULT_API_MULTICAST_IP); + LOG("loaded configuration defaults parameters=%zu", config.size()); } void capiocl::configuration::CapioClConfiguration::set(const std::string &key, std::string value) { + START_LOG(calf_current_tid(), "call()"); config[key] = std::move(value); } void capiocl::configuration::CapioClConfiguration::set(const ConfigurationEntry &entry) { + START_LOG(calf_current_tid(), "call()"); this->set(entry.k, entry.v); } void capiocl::configuration::CapioClConfiguration::load(const std::filesystem::path &path) { + START_LOG(calf_current_tid(), "call()"); + LOG("loading configuration path=%s", path.string().c_str()); if (path.empty()) { throw CapioClConfigurationException("Empty pathname!"); } @@ -63,16 +71,18 @@ void capiocl::configuration::CapioClConfiguration::load(const std::filesystem::p try { tbl = toml::parse_file(path.string()); } catch (const toml::parse_error &err) { + LOG("failed to parse configuration path=%s error=%s", path.string().c_str(), err.what()); throw CapioClConfigurationException(err.what()); } // copy into the local configuration the parameter from the toml config file load_config_to_memory(tbl, config); + LOG("loaded configuration path=%s parameters=%zu", path.string().c_str(), config.size()); } void capiocl::configuration::CapioClConfiguration::getParameter(const std::string &key, - int *value) const { - + int *value) const { + START_LOG(calf_current_tid(), "call()"); if (config.find(key) != config.end()) { *value = std::stoi(config.at(key)); } else { @@ -81,7 +91,8 @@ void capiocl::configuration::CapioClConfiguration::getParameter(const std::strin } void capiocl::configuration::CapioClConfiguration::getParameter(const std::string &key, - std::string *value) const { + std::string *value) const { + START_LOG(calf_current_tid(), "call()"); if (config.find(key) != config.end()) { *value = config.at(key); } else { @@ -91,6 +102,7 @@ void capiocl::configuration::CapioClConfiguration::getParameter(const std::strin capiocl::configuration::CapioClConfigurationException::CapioClConfigurationException( const std::string &msg) : message(msg) { + START_LOG(calf_current_tid(), "call()"); UPDATE_CALF_WORKFLOW_NAME(""); CALF_PRINT_COLOR(CALF_CLI_LEVEL_ERROR, "%s", msg.c_str()); -} \ No newline at end of file +} diff --git a/src/monitors/FileSystem.cpp b/src/monitors/FileSystem.cpp index 3fa3538..2294e0a 100644 --- a/src/monitors/FileSystem.cpp +++ b/src/monitors/FileSystem.cpp @@ -1,12 +1,14 @@ #include #include +#include "calf/StlLogger.h" #include "capiocl.hpp" #include "capiocl/monitor.h" std::filesystem::path capiocl::monitor::FileSystemMonitor::compute_capiocl_token_name(const std::filesystem::path &path, - CAPIO_CL_COMMIT_TOKEN_TYPES type) { + CAPIO_CL_COMMIT_TOKEN_TYPES type) { + START_LOG(calf_current_tid(), "call()"); std::string token_type; if (type == COMMIT) { @@ -22,49 +24,69 @@ capiocl::monitor::FileSystemMonitor::compute_capiocl_token_name(const std::files void capiocl::monitor::FileSystemMonitor::generate_home_node_token( const std::filesystem::path &path, const std::string &home_node) { + START_LOG(calf_current_tid(), "call()"); if (const auto token_name = compute_capiocl_token_name(path, HOME_NODE); !std::filesystem::exists(token_name)) { std::filesystem::create_directories(token_name.parent_path()); std::ofstream file(token_name); file << home_node << std::endl; + if (!file.good()) { + LOG("failed to write home-node token=%s node=%s", token_name.string().c_str(), + home_node.c_str()); + } else { + LOG("created home-node token=%s node=%s", token_name.string().c_str(), + home_node.c_str()); + } file.close(); } } void capiocl::monitor::FileSystemMonitor::generate_commit_token(const std::filesystem::path &path) { + START_LOG(calf_current_tid(), "call()"); if (const auto token_name = compute_capiocl_token_name(path, COMMIT); !std::filesystem::exists(token_name)) { std::filesystem::create_directories(token_name.parent_path()); std::ofstream file(token_name); + if (!file.good()) { + LOG("failed to create commit token=%s", token_name.string().c_str()); + } else { + LOG("created commit token=%s", token_name.string().c_str()); + } file.close(); } } capiocl::monitor::FileSystemMonitor::FileSystemMonitor() { + START_LOG(calf_current_tid(), "call()"); gethostname(_hostname, sizeof(_hostname)); _hostname[sizeof(_hostname) - 1] = '\0'; + LOG("filesystem monitor initialized hostname=%s", _hostname); } void capiocl::monitor::FileSystemMonitor::setCommitted(const std::filesystem::path &path) const { + START_LOG(calf_current_tid(), "call()"); generate_commit_token(path); } bool capiocl::monitor::FileSystemMonitor::isCommitted(const std::filesystem::path &path) const { + START_LOG(calf_current_tid(), "call()"); return std::filesystem::exists(compute_capiocl_token_name(path)); } void capiocl::monitor::FileSystemMonitor::setHomeNode(const std::filesystem::path &path) const { + START_LOG(calf_current_tid(), "call()"); generate_home_node_token(path, _hostname); } std::string capiocl::monitor::FileSystemMonitor::getHomeNode(const std::filesystem::path &path) const { - + START_LOG(calf_current_tid(), "call()"); auto home_node_token = compute_capiocl_token_name(path, HOME_NODE); std::lock_guard lg(home_node_lock); if (const auto it = _home_nodes.find(path); it != _home_nodes.end()) { + LOG("home-node cache hit path=%s node=%s", path.string().c_str(), it->second.c_str()); return it->second; } @@ -77,5 +99,6 @@ capiocl::monitor::FileSystemMonitor::getHomeNode(const std::filesystem::path &pa } auto [entry, _] = _home_nodes.emplace(path, std::move(home_node)); + LOG("resolved home node path=%s node=%s", path.string().c_str(), entry->second.c_str()); return entry->second; } diff --git a/src/monitors/Interface.cpp b/src/monitors/Interface.cpp index 3d61988..d30fdeb 100644 --- a/src/monitors/Interface.cpp +++ b/src/monitors/Interface.cpp @@ -1,18 +1,22 @@ +#include "calf/StlLogger.h" #include "capiocl.hpp" #include "capiocl/monitor.h" bool capiocl::monitor::MonitorInterface::isCommitted(const std::filesystem::path &path) const { + START_LOG(calf_current_tid(), "call()"); std::string msg = "Attempted to use MonitorInterface as Monitor backend to check commit for: "; msg += path.string(); throw MonitorException(msg); } void capiocl::monitor::MonitorInterface::setCommitted(const std::filesystem::path &path) const { + START_LOG(calf_current_tid(), "call()"); std::string msg = "Attempted to use MonitorInterface as Monitor backend to set commit for: "; msg += path.string(); throw MonitorException(msg); } void capiocl::monitor::MonitorInterface::setHomeNode(const std::filesystem::path &path) const { + START_LOG(calf_current_tid(), "call()"); std::string msg = "Attempted to use MonitorInterface as Monitor backend to set commit for: "; msg += path.string(); throw MonitorException(msg); @@ -20,6 +24,7 @@ void capiocl::monitor::MonitorInterface::setHomeNode(const std::filesystem::path std::string capiocl::monitor::MonitorInterface::getHomeNode(const std::filesystem::path &path) const { + START_LOG(calf_current_tid(), "call()"); std::string msg = "Attempted to use MonitorInterface as Monitor backend to set commit for: "; msg += path.string(); throw MonitorException(msg); diff --git a/src/monitors/Multicast.cpp b/src/monitors/Multicast.cpp index fb7411e..7280dc9 100644 --- a/src/monitors/Multicast.cpp +++ b/src/monitors/Multicast.cpp @@ -4,11 +4,13 @@ #include #include +#include "calf/StlLogger.h" #include "capiocl.hpp" #include "capiocl/monitor.h" static std::tuple outgoing_socket_multicast(const std::string &address, - const int port) { + const int port) { + START_LOG(calf_current_tid(), "call()"); sockaddr_in addr{}; addr.sin_family = AF_INET; addr.sin_addr.s_addr = inet_addr(address.c_str()); @@ -17,8 +19,11 @@ static std::tuple outgoing_socket_multicast(const std::string const int transmission_socket = socket(AF_INET, SOCK_DGRAM, 0); // LCOV_EXCL_START if (transmission_socket < 0) { + const int error = errno; + LOG("multicast socket failed direction=outgoing address=%s port=%d errno=%d", + address.c_str(), port, error); throw capiocl::monitor::MonitorException(std::string("socket() failed: ") + - strerror(errno)); + strerror(error)); } // LCOV_EXCL_STOP @@ -26,7 +31,8 @@ static std::tuple outgoing_socket_multicast(const std::string } static int incoming_socket_multicast(const std::string &address_ip, const int port, - sockaddr_in &addr, socklen_t &addrlen) { + sockaddr_in &addr, socklen_t &addrlen) { + START_LOG(calf_current_tid(), "call()"); constexpr int loopback = 1; // enable reception of loopback messages constexpr int multi_bind = 1; // enable multiple sockets on same address @@ -44,6 +50,8 @@ static int incoming_socket_multicast(const std::string &address_ip, const int po // LCOV_EXCL_START if (_socket < 0) { + LOG("multicast socket failed direction=incoming address=%s port=%d errno=%d", + address_ip.c_str(), port, errno); throw capiocl::monitor::MonitorException(std::string("socket() failed: ") + strerror(errno)); } @@ -51,6 +59,8 @@ static int incoming_socket_multicast(const std::string &address_ip, const int po // Allow multiple sockets to bind to the same port if (setsockopt(_socket, SOL_SOCKET, SO_REUSEPORT, &multi_bind, sizeof(multi_bind)) < 0) { const int error = errno; + LOG("multicast setup failed operation=SO_REUSEPORT address=%s port=%d errno=%d", + address_ip.c_str(), port, error); close(_socket); throw capiocl::monitor::MonitorException(std::string("REUSEPORT failed: ") + strerror(error)); @@ -59,6 +69,8 @@ static int incoming_socket_multicast(const std::string &address_ip, const int po // Bind to port if (bind(_socket, reinterpret_cast(&addr), addrlen) < 0) { const int error = errno; + LOG("multicast setup failed operation=bind address=%s port=%d errno=%d", + address_ip.c_str(), port, error); close(_socket); throw capiocl::monitor::MonitorException(std::string("bind failed: ") + strerror(error)); } @@ -66,6 +78,8 @@ static int incoming_socket_multicast(const std::string &address_ip, const int po // Join multicast group if (setsockopt(_socket, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof(mreq)) < 0) { const int error = errno; + LOG("multicast setup failed operation=IP_ADD_MEMBERSHIP address=%s port=%d errno=%d", + address_ip.c_str(), port, error); close(_socket); throw capiocl::monitor::MonitorException(std::string("join multicast failed: ") + strerror(error)); @@ -74,6 +88,8 @@ static int incoming_socket_multicast(const std::string &address_ip, const int po // Enable loopback if (setsockopt(_socket, IPPROTO_IP, IP_MULTICAST_LOOP, &loopback, sizeof(loopback)) < 0) { const int error = errno; + LOG("multicast setup failed operation=IP_MULTICAST_LOOP address=%s port=%d errno=%d", + address_ip.c_str(), port, error); close(_socket); throw capiocl::monitor::MonitorException(std::string("loopback failed: ") + strerror(error)); @@ -87,7 +103,8 @@ void capiocl::monitor::MulticastMonitor::commit_listener(std::vector *terminate) { + const std::atomic *terminate) { + START_LOG(calf_current_tid(), "call()"); sockaddr_in addr_in = {}; socklen_t addr_len = {}; int socket; @@ -139,6 +156,7 @@ void capiocl::monitor::MulticastMonitor::commit_listener(std::vector &home_nodes, std::mutex &lock, const std::string &ip_addr, int ip_port, const std::atomic *terminate) { + START_LOG(calf_current_tid(), "call()"); char this_hostname[HOSTNAME_BUFFER_SIZE] = {}; gethostname(this_hostname, sizeof(this_hostname)); this_hostname[sizeof(this_hostname) - 1] = '\0'; @@ -228,6 +247,7 @@ void capiocl::monitor::MulticastMonitor::home_node_listener( const auto &home_node = tokens[2]; std::lock_guard lg(lock); home_nodes[path] = home_node; + LOG("received home node path=%s node=%s", path.c_str(), home_node.c_str()); } else { // Received a query for a home node, Message begins with capiocl::Monitor::REQUEST if (tokens.size() < 2) { @@ -248,21 +268,33 @@ void capiocl::monitor::MulticastMonitor::home_node_listener( void capiocl::monitor::MulticastMonitor::_send_message(const std::string &ip_addr, const int ip_port, const std::string &path, - const MESSAGE_COMMANDS action) { + const MESSAGE_COMMANDS action) { + START_LOG(calf_current_tid(), "call()"); char message[MESSAGE_SIZE] = {0}; snprintf(message, sizeof(message), "%c %s", action, path.c_str()); auto [out_s, addr] = outgoing_socket_multicast(ip_addr, ip_port); - sendto(out_s, message, strlen(message), 0, reinterpret_cast(&addr), sizeof(addr)); + if (sendto(out_s, message, strlen(message), 0, reinterpret_cast(&addr), + sizeof(addr)) < 0) { + LOG("multicast send failed address=%s port=%d action=%c path=%s errno=%d", ip_addr.c_str(), + ip_port, action, path.c_str(), errno); + } else { + LOG("multicast message sent address=%s port=%d action=%c path=%s", ip_addr.c_str(), ip_port, + action, path.c_str()); + } close(out_s); } capiocl::monitor::MulticastMonitor::MulticastMonitor( const configuration::CapioClConfiguration &config) { + START_LOG(calf_current_tid(), "call()"); config.getParameter("monitor.mcast.commit.ip", &MULTICAST_COMMIT_ADDR); config.getParameter("monitor.mcast.commit.port", &MULTICAST_COMMIT_PORT); config.getParameter("monitor.mcast.homenode.ip", &MULTICAST_HOME_NODE_ADDR); config.getParameter("monitor.mcast.homenode.port", &MULTICAST_HOME_NODE_PORT); config.getParameter("monitor.mcast.delay_ms", &MULTICAST_DELAY_MILLIS); + LOG("multicast monitor configured commit=%s:%d home_node=%s:%d delay_ms=%d", + MULTICAST_COMMIT_ADDR.c_str(), MULTICAST_COMMIT_PORT, MULTICAST_HOME_NODE_ADDR.c_str(), + MULTICAST_HOME_NODE_PORT, MULTICAST_DELAY_MILLIS); commit_thread = std::thread(&commit_listener, std::ref(_committed_files), std::ref(committed_lock), @@ -277,12 +309,14 @@ capiocl::monitor::MulticastMonitor::MulticastMonitor( } capiocl::monitor::MulticastMonitor::~MulticastMonitor() { + START_LOG(calf_current_tid(), "call()"); terminate = true; commit_thread.join(); home_node_thread.join(); } bool capiocl::monitor::MulticastMonitor::isCommitted(const std::filesystem::path &path) const { + START_LOG(calf_current_tid(), "call()"); { const std::lock_guard lg(committed_lock); if (std::find(_committed_files.begin(), _committed_files.end(), path) != @@ -301,6 +335,7 @@ bool capiocl::monitor::MulticastMonitor::isCommitted(const std::filesystem::path } void capiocl::monitor::MulticastMonitor::setCommitted(const std::filesystem::path &path) const { + START_LOG(calf_current_tid(), "call()"); _send_message(MULTICAST_COMMIT_ADDR, MULTICAST_COMMIT_PORT, std::filesystem::path(path), SET); std::lock_guard lg(committed_lock); const auto position = std::find(_committed_files.begin(), _committed_files.end(), path); @@ -310,6 +345,7 @@ void capiocl::monitor::MulticastMonitor::setCommitted(const std::filesystem::pat } void capiocl::monitor::MulticastMonitor::setHomeNode(const std::filesystem::path &path) const { + START_LOG(calf_current_tid(), "call()"); const std::string message = path.string() + " " + _hostname; _send_message(MULTICAST_HOME_NODE_ADDR, MULTICAST_HOME_NODE_PORT, message, SET); @@ -319,6 +355,7 @@ void capiocl::monitor::MulticastMonitor::setHomeNode(const std::filesystem::path std::string capiocl::monitor::MulticastMonitor::getHomeNode(const std::filesystem::path &path) const { + START_LOG(calf_current_tid(), "call()"); { const std::lock_guard lg(home_node_lock); if (const auto itm = _home_nodes.find(path); itm != _home_nodes.end()) { diff --git a/src/parsers/v1.1.cpp b/src/parsers/v1.1.cpp index 318d512..b03093f 100644 --- a/src/parsers/v1.1.cpp +++ b/src/parsers/v1.1.cpp @@ -1,6 +1,7 @@ #include #include "calf/StdOutLogger.h" +#include "calf/StlLogger.h" #include "capio_cl_json_schemas.hpp" #include "capiocl.hpp" #include "capiocl/engine.h" @@ -10,6 +11,7 @@ capiocl::engine::Engine * capiocl::parser::Parser::available_parsers::parse_v1_1(const std::filesystem::path &source, const std::filesystem::path &resolve_prefix, bool store_only_in_memory) { + START_LOG(calf_current_tid(), "call()"); std::string workflow_name = CAPIO_CL_DEFAULT_WF_NAME; auto engine = new engine::Engine(false); @@ -195,5 +197,7 @@ capiocl::parser::Parser::available_parsers::parse_v1_1(const std::filesystem::pa engine->setAllStoreInMemory(); } + LOG("parsed v1.1 source=%s workflow=%s entries=%zu memory_only=%d", source.string().c_str(), + workflow_name.c_str(), engine->size(), static_cast(store_only_in_memory)); return engine; -} \ No newline at end of file +} diff --git a/src/parsers/v1.cpp b/src/parsers/v1.cpp index 0f83994..bc845a1 100644 --- a/src/parsers/v1.cpp +++ b/src/parsers/v1.cpp @@ -1,6 +1,7 @@ #include #include "calf/StdOutLogger.h" +#include "calf/StlLogger.h" #include "capio_cl_json_schemas.hpp" #include "capiocl.hpp" #include "capiocl/engine.h" @@ -10,7 +11,7 @@ capiocl::engine::Engine * capiocl::parser::Parser::available_parsers::parse_v1(const std::filesystem::path &source, const std::filesystem::path &resolve_prefix, bool store_only_in_memory) { - + START_LOG(calf_current_tid(), "call()"); std::string workflow_name = CAPIO_CL_DEFAULT_WF_NAME; auto engine = new engine::Engine(true); @@ -188,5 +189,7 @@ capiocl::parser::Parser::available_parsers::parse_v1(const std::filesystem::path engine->setAllStoreInMemory(); } + LOG("parsed v1 source=%s workflow=%s entries=%zu memory_only=%d", source.string().c_str(), + workflow_name.c_str(), engine->size(), static_cast(store_only_in_memory)); return engine; -} \ No newline at end of file +} diff --git a/src/serializers/v1.1.cpp b/src/serializers/v1.1.cpp index ad6fd00..677780c 100644 --- a/src/serializers/v1.1.cpp +++ b/src/serializers/v1.1.cpp @@ -1,12 +1,14 @@ #include #include "calf/StdOutLogger.h" +#include "calf/StlLogger.h" #include "capiocl.hpp" #include "capiocl/engine.h" #include "capiocl/serializer.h" void capiocl::serializer::Serializer::available_serializers::serialize_v1_1( const engine::Engine &engine, const std::filesystem::path &filename) { + START_LOG(calf_current_tid(), "call()"); UPDATE_CALF_WORKFLOW_NAME(engine.getWorkflowName()); jsoncons::json doc; doc["version"] = 1.1; @@ -121,10 +123,18 @@ void capiocl::serializer::Serializer::available_serializers::serialize_v1_1( std::ofstream out(filename); if (!out.is_open()) { + LOG("failed to open serialization output=%s", filename.string().c_str()); throw SerializerException("Failed to open output file: " + filename.string()); } out << jsoncons::pretty_print(doc) << std::endl; - + if (!out.good()) { + LOG("failed to write serialization output=%s stream_state=%d", filename.string().c_str(), + static_cast(out.rdstate())); + } else { + LOG("serialized v1.1 workflow=%s output=%s entries=%zu applications=%zu", + engine.getWorkflowName().c_str(), filename.string().c_str(), files.size(), + io_graph.size()); + } CALF_PRINT_COLOR(CALF_CLI_LEVEL_INFO, "Configuration serialized to %s", filename.string().c_str()); -} \ No newline at end of file +} diff --git a/src/serializers/v1.cpp b/src/serializers/v1.cpp index ec76f16..5151843 100644 --- a/src/serializers/v1.cpp +++ b/src/serializers/v1.cpp @@ -1,12 +1,14 @@ #include #include "calf/StdOutLogger.h" +#include "calf/StlLogger.h" #include "capiocl.hpp" #include "capiocl/engine.h" #include "capiocl/serializer.h" void capiocl::serializer::Serializer::available_serializers::serialize_v1( const engine::Engine &engine, const std::filesystem::path &filename) { + START_LOG(calf_current_tid(), "call()"); UPDATE_CALF_WORKFLOW_NAME(engine.getWorkflowName()); jsoncons::json doc; doc["name"] = engine.getWorkflowName(); @@ -120,10 +122,18 @@ void capiocl::serializer::Serializer::available_serializers::serialize_v1( std::ofstream out(filename); if (!out.is_open()) { + LOG("failed to open serialization output=%s", filename.string().c_str()); throw SerializerException("Failed to open output file: " + filename.string()); } out << jsoncons::pretty_print(doc) << std::endl; - + if (!out.good()) { + LOG("failed to write serialization output=%s stream_state=%d", filename.string().c_str(), + static_cast(out.rdstate())); + } else { + LOG("serialized v1 workflow=%s output=%s entries=%zu applications=%zu", + engine.getWorkflowName().c_str(), filename.string().c_str(), files.size(), + io_graph.size()); + } CALF_PRINT_COLOR(CALF_CLI_LEVEL_INFO, "Configuration serialized to %s", filename.string().c_str()); -} \ No newline at end of file +} From fda8996d856f008ea686cb19c509be5d7ad7ffd4 Mon Sep 17 00:00:00 2001 From: Marco Edoardo Santimaria Date: Mon, 20 Jul 2026 17:48:21 +0200 Subject: [PATCH 15/16] format --- src/Engine.cpp | 2 +- src/Parser.cpp | 2 +- src/Serializer.cpp | 2 +- src/api.cpp | 2 +- src/configuration.cpp | 6 +++--- src/monitors/FileSystem.cpp | 2 +- src/monitors/Multicast.cpp | 12 ++++++------ 7 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/Engine.cpp b/src/Engine.cpp index 7376dcd..321441d 100644 --- a/src/Engine.cpp +++ b/src/Engine.cpp @@ -259,7 +259,7 @@ void capiocl::engine::Engine::add(std::filesystem::path &path, std::vector &consumers, const std::string &commit_rule, const std::string &fire_rule, bool permanent, bool exclude, - std::vector &dependencies) { + std::vector &dependencies) { START_LOG(calf_current_tid(), "call()"); if (path.empty()) { return; diff --git a/src/Parser.cpp b/src/Parser.cpp index 2a9d936..5af41a7 100644 --- a/src/Parser.cpp +++ b/src/Parser.cpp @@ -54,7 +54,7 @@ void capiocl::parser::Parser::validate_json(const jsoncons::json &doc, const cha capiocl::engine::Engine *capiocl::parser::Parser::parse(const std::filesystem::path &source, const std::filesystem::path &resolve_prefix, - bool store_only_in_memory) { + bool store_only_in_memory) { START_LOG(calf_current_tid(), "call()"); LOG("parse requested source=%s resolve_prefix=%s memory_only=%d", source.string().c_str(), resolve_prefix.string().c_str(), static_cast(store_only_in_memory)); diff --git a/src/Serializer.cpp b/src/Serializer.cpp index e8d4f78..27698bb 100644 --- a/src/Serializer.cpp +++ b/src/Serializer.cpp @@ -10,7 +10,7 @@ void capiocl::serializer::Serializer::dump(const engine::Engine &engine, const std::filesystem::path &filename, - const std::string &version) { + const std::string &version) { START_LOG(calf_current_tid(), "call()"); UPDATE_CALF_WORKFLOW_NAME(engine.getWorkflowName()); if (version == CAPIO_CL_VERSION::V1) { diff --git a/src/api.cpp b/src/api.cpp index a6d27ce..a1cf4ed 100644 --- a/src/api.cpp +++ b/src/api.cpp @@ -20,7 +20,7 @@ bool thread_ready = false; /// @brief Main WebServer thread function void server(const std::string &address, const int port, capiocl::engine::Engine *engine, - std::atomic *terminate) { + std::atomic *terminate) { START_LOG(calf_current_tid(), "call()"); UPDATE_CALF_WORKFLOW_NAME(engine->getWorkflowName()); diff --git a/src/configuration.cpp b/src/configuration.cpp index 3c50af4..6362979 100644 --- a/src/configuration.cpp +++ b/src/configuration.cpp @@ -8,7 +8,7 @@ void load_config_to_memory(const toml::table &tbl, std::unordered_map &map, - const std::string &prefix = "") { + const std::string &prefix = "") { START_LOG(calf_current_tid(), "call()"); for (const auto &[key, value] : tbl) { std::string full_key; @@ -81,7 +81,7 @@ void capiocl::configuration::CapioClConfiguration::load(const std::filesystem::p } void capiocl::configuration::CapioClConfiguration::getParameter(const std::string &key, - int *value) const { + int *value) const { START_LOG(calf_current_tid(), "call()"); if (config.find(key) != config.end()) { *value = std::stoi(config.at(key)); @@ -91,7 +91,7 @@ void capiocl::configuration::CapioClConfiguration::getParameter(const std::strin } void capiocl::configuration::CapioClConfiguration::getParameter(const std::string &key, - std::string *value) const { + std::string *value) const { START_LOG(calf_current_tid(), "call()"); if (config.find(key) != config.end()) { *value = config.at(key); diff --git a/src/monitors/FileSystem.cpp b/src/monitors/FileSystem.cpp index 2294e0a..c58992f 100644 --- a/src/monitors/FileSystem.cpp +++ b/src/monitors/FileSystem.cpp @@ -7,7 +7,7 @@ std::filesystem::path capiocl::monitor::FileSystemMonitor::compute_capiocl_token_name(const std::filesystem::path &path, - CAPIO_CL_COMMIT_TOKEN_TYPES type) { + CAPIO_CL_COMMIT_TOKEN_TYPES type) { START_LOG(calf_current_tid(), "call()"); std::string token_type; diff --git a/src/monitors/Multicast.cpp b/src/monitors/Multicast.cpp index 7280dc9..e59f0cf 100644 --- a/src/monitors/Multicast.cpp +++ b/src/monitors/Multicast.cpp @@ -9,7 +9,7 @@ #include "capiocl/monitor.h" static std::tuple outgoing_socket_multicast(const std::string &address, - const int port) { + const int port) { START_LOG(calf_current_tid(), "call()"); sockaddr_in addr{}; addr.sin_family = AF_INET; @@ -31,7 +31,7 @@ static std::tuple outgoing_socket_multicast(const std::string } static int incoming_socket_multicast(const std::string &address_ip, const int port, - sockaddr_in &addr, socklen_t &addrlen) { + sockaddr_in &addr, socklen_t &addrlen) { START_LOG(calf_current_tid(), "call()"); constexpr int loopback = 1; // enable reception of loopback messages constexpr int multi_bind = 1; // enable multiple sockets on same address @@ -69,8 +69,8 @@ static int incoming_socket_multicast(const std::string &address_ip, const int po // Bind to port if (bind(_socket, reinterpret_cast(&addr), addrlen) < 0) { const int error = errno; - LOG("multicast setup failed operation=bind address=%s port=%d errno=%d", - address_ip.c_str(), port, error); + LOG("multicast setup failed operation=bind address=%s port=%d errno=%d", address_ip.c_str(), + port, error); close(_socket); throw capiocl::monitor::MonitorException(std::string("bind failed: ") + strerror(error)); } @@ -103,7 +103,7 @@ void capiocl::monitor::MulticastMonitor::commit_listener(std::vector *terminate) { + const std::atomic *terminate) { START_LOG(calf_current_tid(), "call()"); sockaddr_in addr_in = {}; socklen_t addr_len = {}; @@ -268,7 +268,7 @@ void capiocl::monitor::MulticastMonitor::home_node_listener( void capiocl::monitor::MulticastMonitor::_send_message(const std::string &ip_addr, const int ip_port, const std::string &path, - const MESSAGE_COMMANDS action) { + const MESSAGE_COMMANDS action) { START_LOG(calf_current_tid(), "call()"); char message[MESSAGE_SIZE] = {0}; snprintf(message, sizeof(message), "%c %s", action, path.c_str()); From 02bcbd8215d65b637267ecd432e982b5d8700d73 Mon Sep 17 00:00:00 2001 From: marcoSanti Date: Sun, 26 Jul 2026 16:28:41 +0200 Subject: [PATCH 16/16] Fixed CALF release version --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3736d77..32704c4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -60,7 +60,7 @@ FetchContent_Declare( FetchContent_Declare( calf GIT_REPOSITORY https://github.com/High-Performance-IO/calf.git - GIT_TAG main + GIT_TAG v0.1.1 ) # JSONCONS build flags