Mads
Multi-Agent Distributed System
Loading...
Searching...
No Matches
director_config.hpp
Go to the documentation of this file.
1/*
2 ____ _ _
3 | _ \‍(_)_ __ ___ ___| |_ ___ _ __
4 | | | | | '__/ _ \/ __| __/ _ \| '__|
5 | |_| | | | | __/ (__| || (_) | |
6 |____/|_|_| \___|\___|\__\___/|_|
7 ____ __ _
8 / ___|___ _ __ / _(_) __ _
9 | | / _ \| '_ \| |_| |/ _` |
10 | |__| (_) | | | | _| | (_| |
11 \____\___/|_| |_|_| |_|\__, |
12 |___/
13
14Pure config module for `mads up` (src/main/up.cpp): parses `director.toml` (the
15config format owned by https://github.com/mads-net/mads_director), validates
16it, expands `scale`/`${PWD}`/`${ID}` templating, and orders processes so that
17every dependency (`after`) starts before its dependents.
18
19No ZMQ, no process spawning, no `Mads::Agent` dependency here on purpose (see
20the "Parser ownership" decision in NEW_FEATURES.md's P5 section): this file is
21meant to be liftable wholesale into a future shared header, or contributed
22upstream to mads_director.
23
24Author(s): Paolo Bosetti
25*/
26#ifndef MADS_DIRECTOR_CONFIG_HPP
27#define MADS_DIRECTOR_CONFIG_HPP
28
29#include <chrono>
30#include <cstdint>
31#include <filesystem>
32#include <optional>
33#include <string>
34#include <vector>
35
36namespace Mads {
37
48std::optional<std::chrono::milliseconds> parse_duration(const std::string &text);
49
51enum class ReadyKind { Broker, Port, Log, Delay };
52
62struct ReadySpec {
64 std::string broker_uri; // ReadyKind::Broker (defaulted if not given)
65 int port = 0; // ReadyKind::Port
66 std::string log_pattern; // ReadyKind::Log (ECMAScript regex, matched
67 // against each captured stdout/stderr line)
68 std::chrono::milliseconds delay{0}; // ReadyKind::Delay
69};
70
72constexpr const char *kDefaultBrokerProbeUri = "tcp://localhost:9092";
73
79std::optional<ReadySpec> parse_ready_spec(const std::string &value,
80 std::string *out_error);
81
88 std::string name; // instance name, e.g. "api" or "api[2]" when scale>1
89 std::string base_name; // section name before scale expansion, e.g. "api"
90 std::string command; // fully expanded (${PWD}/${ID} substituted)
91 std::string workdir; // absolute, resolved against the config file's dir
92 bool enabled = true;
93 bool relaunch = false;
94 bool tty = false; // parsed for fidelity; headless mads-up ignores it
95 // The value `${ID}` expanded to: `base_instance_id + <0-based index>`,
96 // matching Director's own substitution. Plain 0-based when the section
97 // leaves `base_instance_id` at its 0 default.
98 int instance_id = 0;
99 // Resolved dependency instance names (a base process with scale>1 that
100 // another depends on via `after` expands to *all* of its instances, exactly
101 // as mads_director's ProcessManager::build_process_definitions does).
102 std::vector<std::string> after;
103 std::optional<ReadySpec> ready;
104};
105
112 std::optional<std::string> terminal; // GUI-only, ignored headless
113 double sample_rate_seconds = 2.0; // GUI-only, ignored headless
114 std::filesystem::path base_dir; // directory containing the config
115 std::vector<ProcessConfig> processes; // topologically ordered
116};
117
131 std::optional<int> base_instance_id;
132};
133
154std::optional<DirectorConfig>
155load_director_config(const std::string &path, std::string *out_error,
156 std::vector<std::string> *out_warnings = nullptr,
157 const DirectorLoadOptions &options = {});
158
159} // namespace Mads
160
161#endif // MADS_DIRECTOR_CONFIG_HPP
Definition agent.hpp:67
ReadyKind
Discriminates the four ready = "..." probe kinds.
constexpr const char * kDefaultBrokerProbeUri
Default broker settings URI probed by a bare ready = "broker".
std::optional< std::chrono::milliseconds > parse_duration(const std::string &text)
Parses a duration string like "500ms", "2s", "1.5s", "3m" into a std::chrono::milliseconds value....
std::optional< ReadySpec > parse_ready_spec(const std::string &value, std::string *out_error)
Parses a raw ready string into a ReadySpec. Exposed standalone (rather than only reachable through lo...
std::optional< DirectorConfig > load_director_config(const std::string &path, std::string *out_error, std::vector< std::string > *out_warnings=nullptr, const DirectorLoadOptions &options={})
Loads, validates, expands and orders a director.toml file.
A fully parsed, validated, expanded director.toml. processes is already in a valid topological start ...
std::vector< ProcessConfig > processes
std::optional< std::string > terminal
std::filesystem::path base_dir
Caller-supplied overrides applied while the file is expanded.
std::optional< int > base_instance_id
One process instance, after scale expansion and template substitution. This is what mads up actually ...
std::vector< std::string > after
std::optional< ReadySpec > ready
A parsed, validated ready = "..." value.
std::string log_pattern
std::chrono::milliseconds delay
std::string broker_uri