1#ifndef CAPIO_CL_MONITOR_H
2#define CAPIO_CL_MONITOR_H
9#include <unordered_map>
12#include "configuration.h"
19#define HOST_NAME_MAX 1024
26static const std::string NO_HOME_NODE =
"<NONE>";
32 std::string message{};
45 [[nodiscard]]
const char *
what() const noexcept
override {
return message.c_str(); }
81 mutable std::unordered_map<std::string, std::string>
_home_nodes;
100 virtual bool isCommitted(
const std::filesystem::path &path)
const;
113 virtual void setHomeNode(
const std::filesystem::path &path)
const;
120 virtual const std::string &
getHomeNode(
const std::filesystem::path &path)
const;
135 static constexpr int MESSAGE_SIZE = (2 + PATH_MAX + PATH_MAX);
140 std::thread commit_thread, home_node_thread;
145 std::string MULTICAST_COMMIT_ADDR;
147 std::string MULTICAST_HOME_NODE_ADDR;
152 int MULTICAST_COMMIT_PORT{};
154 int MULTICAST_HOME_NODE_PORT{};
157 int MULTICAST_DELAY_MILLIS{};
162 typedef enum { SET =
'!', GET =
'?' } MESSAGE_COMMANDS;
172 static void _send_message(
const std::string &ip_addr,
int ip_port,
const std::string &path,
173 MESSAGE_COMMANDS action);
187 [[noreturn]]
static void commit_listener(std::vector<std::string> &committed_files,
188 std::mutex &lock,
const std::string &ip_addr,
203 [[noreturn]]
static void
204 home_node_listener(std::unordered_map<std::string, std::string> &home_nodes, std::mutex &lock,
205 const std::string &ip_addr,
int ip_port);
220 bool isCommitted(
const std::filesystem::path &path)
const override;
222 void setHomeNode(
const std::filesystem::path &path)
const override;
223 const std::string &
getHomeNode(
const std::filesystem::path &path)
const override;
235 typedef enum { COMMIT, HOME_NODE } CAPIO_CL_COMMIT_TOKEN_TYPES;
244 static std::filesystem::path
245 compute_capiocl_token_name(
const std::filesystem::path &path,
246 CAPIO_CL_COMMIT_TOKEN_TYPES type = COMMIT);
255 static void generate_commit_token(
const std::filesystem::path &path);
265 static void generate_home_node_token(
const std::filesystem::path &path,
266 const std::string &home_node);
279 bool isCommitted(
const std::filesystem::path &path)
const override;
281 void setHomeNode(
const std::filesystem::path &path)
const override;
282 const std::string &
getHomeNode(
const std::filesystem::path &path)
const override;
291 friend class MonitorInterface;
293 std::vector<const MonitorInterface *> interfaces;
304 [[nodiscard]]
bool isCommitted(
const std::filesystem::path &path)
const;
325 void setHomeNode(
const std::filesystem::path &path)
const;
332 [[nodiscard]] std::set<std::string>
getHomeNode(
const std::filesystem::path &path)
const;
Load configuration and store it from a CAPIO-CL TOML configuration file.
Definition configuration.h:31
bool isCommitted(const std::filesystem::path &path) const override
Check whether the given file has been committed.
FileSystemMonitor()
Construct a filesystem-based commit monitor.
~FileSystemMonitor() override=default
Destructor for FileSystemMonitor.
void setHomeNode(const std::filesystem::path &path) const override
void setCommitted(const std::filesystem::path &path) const override
Mark the given file as committed.
const std::string & getHomeNode(const std::filesystem::path &path) const override
MonitorException(const std::string &msg)
Construct a new CAPIO-CL Exception.
Definition Monitor.cpp:5
const char * what() const noexcept override
Definition monitor.h:45
Abstract interface for monitoring the commit state of files in CAPIO-CL.
Definition monitor.h:59
virtual bool isCommitted(const std::filesystem::path &path) const
Check whether the given file has been committed.
std::vector< std::string > _committed_files
List of committed file paths stored as strings.
Definition monitor.h:74
virtual void setCommitted(const std::filesystem::path &path) const
Mark the given file as committed.
virtual void setHomeNode(const std::filesystem::path &path) const
std::mutex committed_lock
Mutex protecting access to the committed file list.
Definition monitor.h:64
std::unordered_map< std::string, std::string > _home_nodes
Lookup table to get home node staring from path. Key = file path; Value = hostname of home node.
Definition monitor.h:81
virtual const std::string & getHomeNode(const std::filesystem::path &path) const
std::mutex home_node_lock
Mutex protecting access to the home nodes list.
Definition monitor.h:69
char _hostname[HOST_NAME_MAX]
hostname of the current instance
Definition monitor.h:86
virtual ~MonitorInterface()=default
Virtual destructor for safe polymorphic deletion.
Class to monitor runtime dependent information on CAPIO-CL related paths, such as commitment status a...
Definition monitor.h:289
void setHomeNode(const std::filesystem::path &path) const
Definition Monitor.cpp:22
bool isCommitted(const std::filesystem::path &path) const
Definition Monitor.cpp:9
std::set< std::string > getHomeNode(const std::filesystem::path &path) const
Definition Monitor.cpp:28
void setCommitted(std::filesystem::path path) const
Definition Monitor.cpp:14
void registerMonitorBackend(const MonitorInterface *interface)
Definition Monitor.cpp:19
const std::string & getHomeNode(const std::filesystem::path &path) const override
MulticastMonitor(const capiocl::configuration::CapioClConfiguration &config)
Construct a multicast-based monitor.
void setCommitted(const std::filesystem::path &path) const override
Mark the given file as committed.
void setHomeNode(const std::filesystem::path &path) const override
~MulticastMonitor() override
Destructor; stops listener thread and cleans resources.
bool isCommitted(const std::filesystem::path &path) const override
Check whether the given file has been committed.
Namespace containing the CAPIO-CL Monitor components.
Definition monitor.h:23