DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
group_metadata.hpp
Go to the documentation of this file.
1
10#ifndef SNBMODULES_INCLUDE_SNBMODULES_GROUP_METADATA_HPP_
11#define SNBMODULES_INCLUDE_SNBMODULES_GROUP_METADATA_HPP_
12
13#include "appfwk/cmd/Nljs.hpp"
17
18#include <filesystem>
19#include <set>
20#include <string>
21#include <utility>
22#include <vector>
23
24namespace dunedaq::snbmodules {
26{
27
28public:
29 static const std::string m_file_extension;
30
31 void generate_metadata_file(std::filesystem::path dest) override;
32 void load_metadata_from_meta_file(std::filesystem::path src) override;
33 std::string export_to_string() override;
34 void from_string(const std::string&) override;
35
40 {
42 for (const auto& transfer : get_transfers_meta()) {
43 if (transfer->get_status() > status) {
44 status = transfer->get_status();
45 }
46 }
47 return status;
48 }
49
54 GroupMetadata(std::string group_id,
55 std::string source,
56 const IPFormat& source_ip,
58 const nlohmann::json& protocol_options = nlohmann::json(),
59 const std::vector<std::shared_ptr<TransferMetadata>>& transfers_meta =
60 std::vector<std::shared_ptr<TransferMetadata>>())
61 : m_group_id(std::move(group_id))
62 , m_protocol(protocol)
63 , m_transfers_meta(transfers_meta)
64 , m_expected_files(std::set<std::string>())
65 , m_source_id(std::move(source))
66 , m_source_ip(source_ip)
67 {
68 set_protocol_options(protocol_options);
69 }
70
72 explicit GroupMetadata(const std::filesystem::path& src, bool is_path = true)
73 {
74 if (is_path) {
76 } else {
77 from_string(src.string());
78 }
79 }
80
81 virtual ~GroupMetadata() = default;
82
86 bool operator==(MetadataAbstract const& other) const override
87 {
88 auto o = dynamic_cast<const GroupMetadata&>(other);
89 return m_group_id == o.m_group_id;
90 }
91
95 bool operator<(MetadataAbstract const& other) const override
96 {
97 auto o = dynamic_cast<const GroupMetadata&>(other);
98 return m_group_id.compare(o.m_group_id);
99 }
100
101 // Setters
102 inline void set_group_id(std::string transfer_id) { m_group_id = std::move(transfer_id); }
103 inline void set_protocol(protocol_type::e_protocol_type protocol) { m_protocol = protocol; }
104 inline void set_transfers_meta(std::vector<std::shared_ptr<TransferMetadata>> files_meta)
105 {
106 m_transfers_meta = std::move(files_meta);
107 }
108 inline void set_protocol_options(nlohmann::json protocol_options)
109 {
110 m_protocol_options = std::move(protocol_options);
111 }
112 inline void set_source_id(std::string source_id) { m_source_id = std::move(source_id); }
113 inline void set_expected_files(std::set<std::string> expected_files) { m_expected_files = std::move(expected_files); }
114 TransferMetadata& add_file(std::shared_ptr<TransferMetadata> meta);
115 void add_expected_file(const std::filesystem::path& file)
116 {
117 // remove all occurences of ./ in the file path
118 std::string file_path_str = file.string();
119 std::string x = "./";
120
121 size_t pos = 0;
122 while (true) {
123 pos = file_path_str.find(x, pos);
124 if (pos == std::string::npos) {
125 break;
126 }
127
128 file_path_str.replace(pos, x.length(), "");
129 }
130
131 m_expected_files.insert(std::filesystem::absolute(file_path_str));
132 }
133
134 // Getters
135 inline std::string get_group_id() const { return m_group_id; }
137 inline std::vector<std::shared_ptr<TransferMetadata>>& get_transfers_meta() { return m_transfers_meta; }
138 inline const std::vector<std::shared_ptr<TransferMetadata>>& get_transfers_meta() const { return m_transfers_meta; }
139 TransferMetadata& get_transfer_meta_from_file_path(const std::string& file_path);
140 inline const std::set<std::string>& get_expected_files() const { return m_expected_files; }
141 inline nlohmann::json get_protocol_options() const { return m_protocol_options; }
142 inline std::string get_source_id() const { return m_source_id; }
143 inline IPFormat get_source_ip() const { return m_source_ip; }
144 std::string to_string() const;
145
146private:
148 std::string m_group_id;
149
152
154 nlohmann::json m_protocol_options;
155
157 std::vector<std::shared_ptr<TransferMetadata>> m_transfers_meta;
158
160 std::set<std::string> m_expected_files;
161
163 std::string m_source_id;
164
167};
168
169} // namespace dunedaq::snbmodules
170#endif // SNBMODULES_INCLUDE_SNBMODULES_GROUP_METADATA_HPP_
void load_metadata_from_meta_file(std::filesystem::path src) override
Load metadata file from src.
bool operator<(MetadataAbstract const &other) const override
Operator <.
std::string m_group_id
Unique identifier for the transfer.
void set_expected_files(std::set< std::string > expected_files)
protocol_type::e_protocol_type get_protocol() const
std::string export_to_string() override
Export metadata to string (json format)
std::set< std::string > m_expected_files
Set of expected files metadata to add later.
void set_transfers_meta(std::vector< std::shared_ptr< TransferMetadata > > files_meta)
const std::vector< std::shared_ptr< TransferMetadata > > & get_transfers_meta() const
void generate_metadata_file(std::filesystem::path dest) override
Generaete metadata file to dest.
status_type::e_status get_group_status() const
Return a status of the group transfer based on the status of his transfers, The highest status in pri...
void add_expected_file(const std::filesystem::path &file)
TransferMetadata & add_file(std::shared_ptr< TransferMetadata > meta)
void set_protocol(protocol_type::e_protocol_type protocol)
const std::set< std::string > & get_expected_files() const
GroupMetadata(const std::filesystem::path &src, bool is_path=true)
Load from file constructor.
TransferMetadata & get_transfer_meta_from_file_path(const std::string &file_path)
std::vector< std::shared_ptr< TransferMetadata > > m_transfers_meta
Set of files to transfer.
std::vector< std::shared_ptr< TransferMetadata > > & get_transfers_meta()
bool operator==(MetadataAbstract const &other) const override
Operator ==.
nlohmann::json m_protocol_options
Specific options for the selected protocol.
GroupMetadata(std::string group_id, std::string source, const IPFormat &source_ip, protocol_type::e_protocol_type protocol, const nlohmann::json &protocol_options=nlohmann::json(), const std::vector< std::shared_ptr< TransferMetadata > > &transfers_meta=std::vector< std::shared_ptr< TransferMetadata > >())
Constructor.
void set_source_id(std::string source_id)
nlohmann::json get_protocol_options() const
std::string m_source_id
Get source id.
static const std::string m_file_extension
void set_protocol_options(nlohmann::json protocol_options)
protocol_type::e_protocol_type m_protocol
Protocol used for the transfer, every files in the transfer must use the same protocol.
void set_group_id(std::string transfer_id)
void from_string(const std::string &) override
Import metadata from string (json format)
Class that represents an IP address and a port TODO: should be replaced by something better ?
Definition ip_format.hpp:26
Abstract class for metadata classes, they must be able to generate and load metadata files.
Monitoring thread not set
e_protocol_type
Different type of protocols available for communication.
e_status
Different type of session status Need to be sorted by priority (highest last)
@ PREPARING
waiting for the transfer to start, can be waiting to receive expected files metadata