DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
transfer_session.hpp
Go to the documentation of this file.
1
10#ifndef SNBMODULES_INCLUDE_SNBMODULES_TRANSFER_SESSION_HPP_
11#define SNBMODULES_INCLUDE_SNBMODULES_TRANSFER_SESSION_HPP_
12
15#include "snbmodules/notification_interface.hpp" // for notification data
17
18// protocols
23
24#include <fstream>
25#include <memory>
26#include <set>
27#include <string>
28#include <sys/prctl.h>
29#include <sys/wait.h>
30#include <utility>
31#include <vector>
32
33namespace dunedaq::snbmodules {
42
46{
47
48public:
52
56
60
64
68 bool operator==(TransferSession const& other) const { return m_session_id == other.m_session_id; }
69
73 bool operator<(TransferSession const& other) const { return m_session_id.compare(other.m_session_id); }
74
77
83 TransferSession(GroupMetadata transfer_options,
84 e_session_type type,
85 std::string id,
86 const IPFormat& ip,
87 std::filesystem::path work_dir,
88 std::vector<std::string> bk_conn = std::vector<std::string>(),
89 std::set<std::string> client_conn = std::set<std::string>());
90
93 virtual ~TransferSession();
94
95 // Getters
96 inline const GroupMetadata& get_transfer_options() const { return m_transfer_options; }
98 inline std::filesystem::path get_work_dir() const { return m_work_dir; }
99 inline const std::set<std::string>& get_target_clients() const { return m_target_clients; }
100 inline IPFormat get_ip() const { return m_ip; }
101 std::string get_session_id() const { return m_session_id; }
102 std::string to_string() const;
104 {
105 const std::map<e_session_type, std::string> MyEnumStrings{ { Downloader, "Downloader" }, { Uploader, "Uploader" } };
106 auto it = MyEnumStrings.find(e);
107 return it == MyEnumStrings.end() ? "Not supported" : it->second;
108 }
109
110 // Setters
111 void set_target_clients(std::set<std::string> clients) { m_target_clients = std::move(clients); }
112
113 // Interface for the transfer, TODO: add notifications : DO WE REALLY WANT THAT ?
114 void add_file(std::shared_ptr<TransferMetadata> fmeta)
115 {
116 TransferMetadata& moved_meta = get_transfer_options().add_file(std::move(fmeta));
118 }
119
120 bool pause_file(TransferMetadata& f_meta, bool is_multiple = false);
121 bool resume_file(TransferMetadata& f_meta, bool is_multiple = false);
122 bool hash_file(TransferMetadata& f_meta, bool is_multiple = false);
123 bool cancel_file(TransferMetadata& f_meta, bool is_multiple = false);
124
125 bool pause_all();
126 bool resume_all();
127 bool cancel_all();
128
131 bool start_file(TransferMetadata& f_meta);
132 bool start_all();
133
134 // Downloaders only
135 bool download_all(const std::filesystem::path& dest);
136 bool download_file(TransferMetadata& f_meta, std::filesystem::path dest, bool is_multiple = false);
137
138 // Uploaders only
139 bool upload_all();
140 bool upload_file(TransferMetadata& f_meta, bool is_multiple = false);
141
142private:
146
149 std::string m_session_id;
150
154
156 std::unique_ptr<TransferInterfaceAbstract> m_transfer_interface;
157
161
164 // std::vector<pid_t> m_threads;
165
167 std::filesystem::path m_work_dir;
168
170 std::set<std::string> m_target_clients;
171
177
182 bool send_notification_to_targets(notification_type::e_notification_type type, const std::string& data = "");
183};
184
185} // namespace dunedaq::snbmodules
186#endif // SNBMODULES_INCLUDE_SNBMODULES_TRANSFER_SESSION_HPP_
TransferMetadata & add_file(std::shared_ptr< TransferMetadata > meta)
Class that represents an IP address and a port TODO: should be replaced by something better ?
Definition ip_format.hpp:26
TransferSession class contained in a client, is a wrapper for a transfer. extend notification interfa...
bool resume_file(TransferMetadata &f_meta, bool is_multiple=false)
void set_target_clients(std::set< std::string > clients)
bool is_downloader()
Usefull to check if the session is a downloader.
virtual ~TransferSession()
Destructor Kill all threads created by the session (TODO : useless ?)
bool hash_file(TransferMetadata &f_meta, bool is_multiple=false)
bool cancel_file(TransferMetadata &f_meta, bool is_multiple=false)
bool operator==(TransferSession const &other) const
equal operator, used to compare sessions in a set (client)
IPFormat m_ip
Ip of the client TODO : useless ? the session cannot have a unique connection.
bool action_on_receive_notification(NotificationData notif) override
handle actions to be taken when a notification is received. The notification is passed as a parameter...
TransferSession(TransferSession &&)=default
GroupMetadata m_transfer_options
A session must contain a transfer matadata. The session is basically a transfer wrapper.
bool upload_file(TransferMetadata &f_meta, bool is_multiple=false)
bool send_notification_to_targets(notification_type::e_notification_type type, const std::string &data="")
Send a notification to every targets of the session, generally for the uploader.
bool operator<(TransferSession const &other) const
Operator <, used to compare sessions in a set (client)
bool download_file(TransferMetadata &f_meta, std::filesystem::path dest, bool is_multiple=false)
std::filesystem::path get_work_dir() const
e_session_type m_type
Type of session, uploader or downloader. Used to block access to some functions.
bool update_metadata_to_bookkeeper(TransferMetadata &f_meta)
std::unique_ptr< TransferInterfaceAbstract > m_transfer_interface
Abstract interface can reference to any protocol used to transfer data.
std::string m_session_id
Unique identifier of the session, used to identify the session in the client and to target notificati...
bool is_uploader()
Usefull to check if the session is a uploader.
const GroupMetadata & get_transfer_options() const
const std::set< std::string > & get_target_clients() const
std::set< std::string > m_target_clients
clients that dowload the files, only used by uploader
void add_file(std::shared_ptr< TransferMetadata > fmeta)
bool start_file(TransferMetadata &f_meta)
Start the session by downloading or uploading files depending on the type of session TODO : separate ...
TransferSession & operator=(TransferSession &&)=default
static std::string session_type_to_string(e_session_type e)
bool pause_file(TransferMetadata &f_meta, bool is_multiple=false)
std::filesystem::path m_work_dir
List of threads created by the session TODO : useless ? should be handle in client.
bool download_all(const std::filesystem::path &dest)
e_session_type
Different type of session.
@ Downloader
TransferSession used to download files from uploaders client.
@ Uploader
TransferSession used to upload files to downloaders client.
NotificationData class, represent a notification.
e_notification_type
Different type of notifications possible to send.