DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
bookkeeper.hpp
Go to the documentation of this file.
1
9#ifndef SNBMODULES_INCLUDE_SNBMODULES_BOOKKEEPER_HPP_
10#define SNBMODULES_INCLUDE_SNBMODULES_BOOKKEEPER_HPP_
11
17
18// errors handling
19#include "logging/Logging.hpp"
21
22#include <algorithm>
23#include <chrono>
24#include <map>
25#include <set>
26#include <string>
27#include <utility>
28#include <vector>
29
32{
33
34public:
36 Bookkeeper(const IPFormat& listening_ip,
37 std::string bookkeeper_id,
38 std::string file_log_path = "",
39 int refresh_rate = 5,
40 std::string connection_prefix = "snbmodules",
41 int timeout_send = 10,
42 int timeout_receive = 100)
43 : NotificationInterface(std::move(connection_prefix), timeout_send, timeout_receive)
44 {
45 set_bookkeeper_id(std::move(bookkeeper_id));
46 set_ip(listening_ip);
47 m_file_log_path = std::move(file_log_path);
48 m_refresh_rate = refresh_rate;
50 }
51
54
57 bool start();
58
61 void do_work(std::atomic<bool>& running_flag);
62
64
67 void input_action(char input);
68
69 [[deprecated("Now only the uploader can create a new transfer")]] void create_new_transfer(
70 const std::string& protocol,
71 const std::string& src,
72 const std::set<std::string>& dests,
73 const std::set<std::filesystem::path>& files,
74 const nlohmann::json& protocol_options = nlohmann::json());
75
79
83 void request_update_metadata(bool force = false);
84
85 // Setters
86 inline void set_bookkeeper_id(std::string bookkeeper_id) { m_bookkeeper_id = std::move(bookkeeper_id); }
87 inline void set_ip(const IPFormat& ip) { m_ip = ip; }
88 void add_update_transfer(const std::string& client_id, const std::string& data);
89 void add_update_grp_transfer(GroupMetadata grp_transfers);
90
91 // Getters
92 inline std::string get_bookkeeper_id() const { return m_bookkeeper_id; }
93 inline IPFormat get_ip() const { return m_ip; }
94 inline std::map<std::string, GroupMetadata>& get_grp_transfers() { return m_grp_transfers; }
95 inline const std::map<std::string, GroupMetadata>& get_grp_transfers() const { return m_grp_transfers; }
96 inline std::map<std::string, std::vector<std::shared_ptr<TransferMetadata>>>& get_transfers() { return m_transfers; }
97 inline const std::map<std::string, std::vector<std::shared_ptr<TransferMetadata>>>& get_transfers() const
98 {
99 return m_transfers;
100 }
101
102private:
104 std::string m_bookkeeper_id;
105
108
110 std::map<std::string, GroupMetadata> m_grp_transfers;
111
113 std::map<std::string, std::set<std::string>> m_clients_per_grp_transfer;
114
116 std::map<std::string, std::vector<std::shared_ptr<TransferMetadata>>> m_transfers;
117
119 std::string m_file_log_path = "";
120
123
126 void request_connection_and_available_files(const std::string& client);
127
129 [[deprecated("Now only the uploader can start a transfer")]] void start_transfers(const std::string& transfer_id);
130
134 std::string get_client_name_from_session_name(const std::string& session_name) const
135 {
136 return session_name.substr(0, session_name.find("_"));
137 }
138};
139} // namespace dunedaq::snbmodules
140#endif // SNBMODULES_INCLUDE_SNBMODULES_BOOKKEEPER_HPP_
Bookkeeper(const IPFormat &listening_ip, std::string bookkeeper_id, std::string file_log_path="", int refresh_rate=5, std::string connection_prefix="snbmodules", int timeout_send=10, int timeout_receive=100)
Constructor with params.
void do_work(std::atomic< bool > &running_flag)
Start the bookkeeper thread to receive notifications.
void request_update_metadata(bool force=false)
Request the update of the metadata from every known clients to the bookkeeper. Only get from group tr...
void start_transfers(const std::string &transfer_id)
Start a new transfer.
std::map< std::string, GroupMetadata > m_grp_transfers
map of group_id -> group_transfers
void set_bookkeeper_id(std::string bookkeeper_id)
std::map< std::string, std::set< std::string > > m_clients_per_grp_transfer
map of grp_transfer_id -> clients_id
bool action_on_receive_notification(NotificationData notif) override
Action to do when receiving a notification.
bool start()
Start the bookkeeper, Only used for stand alone application.
void request_connection_and_available_files(const std::string &client)
Send a notification to a clients id or connection to get available files.
void set_ip(const IPFormat &ip)
void display_information()
Display the information of the bookkeeper either on the normal log or on a specific file depending on...
const std::map< std::string, GroupMetadata > & get_grp_transfers() const
void create_new_transfer(const std::string &protocol, const std::string &src, const std::set< std::string > &dests, const std::set< std::filesystem::path > &files, const nlohmann::json &protocol_options=nlohmann::json())
void add_update_grp_transfer(GroupMetadata grp_transfers)
std::string m_bookkeeper_id
Unique identifier for the bookkeeper.
void add_update_transfer(const std::string &client_id, const std::string &data)
std::map< std::string, GroupMetadata > & get_grp_transfers()
std::map< std::string, std::vector< std::shared_ptr< TransferMetadata > > > m_transfers
Map of files/current transfers, client_id -> set of transfers.
IPFormat m_ip
IP address of the bookkeeper.
std::string m_file_log_path
should the information pannel of transfers be displayed on the normal log or a specific file
int m_refresh_rate
Refresh rate of the information pannel of transfers in seconds.
const std::map< std::string, std::vector< std::shared_ptr< TransferMetadata > > > & get_transfers() const
std::map< std::string, std::vector< std::shared_ptr< TransferMetadata > > > & get_transfers()
std::string get_client_name_from_session_name(const std::string &session_name) const
Usefull convertion from session id to client id.
void input_action(char input)
Do action depending on the input, Used for stand alone application TODO: remake.
std::string get_bookkeeper_id() const
Class that represents an IP address and a port TODO: should be replaced by something better ?
Definition ip_format.hpp:26
NotificationData class, represent a notification.