15 #include <boost/program_options.hpp>
16 #include <fmt/format.h>
17 #include <fmt/ostream.h>
18 #include <rad/helper.hpp>
19 #include <yaml-cpp/yaml.h>
26 : m_logger(std::move(logger)), m_mgr(&m_config, m_logger) {
45 {
"limit-merge",
"Concurrency limit: Number of merges"});
47 {
"limit-net-send",
"Concurrency limit: Number of network send tranfers."});
50 {
"limit-net-receive",
"Concurrency limit: Number of network receive transfers."});
52 std::string db_addr = rad::Helper::GetEnvVar(
"DB_HOST");
53 if (
auto root = rad::Helper::GetEnvVar(
"DATAROOT"); !root.empty()) {
60 namespace po = boost::program_options;
63 po::options_description options_desc(
"Options");
67 options_desc.add_options()
68 (
"help,h",
"Print help messages")
70 po::value<std::string>(),
73 po::value<std::string>(),
74 "Log level: ERROR, WARNING, STATE, EVENT, ACTION, INFO, DEBUG, TRACE")
76 po::value<std::string>(),
77 "Configuration filename")
79 po::value<std::string>(),
80 "In-memory DB host (ipaddr:port)")
82 po::value<std::string>(),
85 po::value<std::string>(),
86 "Publish/subscribe URI")
88 po::value<std::string>(),
89 "workspace path (relative paths are relateive to dataroot)")
91 "Disable request/reply, publish/subscribe and OLDB interfaces for standalone mode")
93 "Poll scheduler once and then exit rather than running until asked to quit (this "
94 "option also implies --no-ipc)")
97 po::variables_map options_map;
98 po::store(po::parse_command_line(argc, argv, options_desc), options_map);
99 if (options_map.count(
"help")) {
100 std::cerr << options_desc << std::endl;
103 po::notify(options_map);
105 if (options_map.count(
"config")) {
106 auto value = options_map[
"config"].as<std::string>();
110 if (options_map.count(
"log-level")) {
113 auto ll_str = options_map[
"log-level"].as<std::string>();
114 auto ll = boost::lexical_cast<LogLevel>(ll_str);
118 if (options_map.count(
"proc-name")) {
119 auto value = options_map[
"proc-name"].as<std::string>();
123 if (options_map.count(
"db-host")) {
124 auto value = options_map[
"db-host"].as<std::string>();
127 if (options_map.count(
"rr-uri")) {
128 auto value = options_map[
"rr-uri"].as<std::string>();
131 if (options_map.count(
"ps-uri")) {
132 auto value = options_map[
"ps-uri"].as<std::string>();
135 if (options_map.count(
"workspace")) {
136 auto value = options_map[
"workspace"].as<std::string>();
139 if (options_map.count(
"no-ipc")) {
142 if (options_map.count(
"poll-once")) {
147 {config::Origin::CommandLine,
"Option is implicitly set due to `--poll-once`"});
151 std::throw_with_nested(std::runtime_error(
"Failed to parse command line arguments"));
157 std::string resolved = rad::Helper::FindFile(m_config.
config_file);
158 LOG4CPLUS_INFO(m_logger,
"Loading configuration from " << resolved);
159 if (resolved.empty()) {
160 auto msg = fmt::format(
"Could not resolve config file {}", m_config.
config_file);
161 LOG4CPLUS_ERROR(m_logger, msg);
162 throw std::invalid_argument(msg);
165 auto config = YAML::LoadFile(resolved);
167 if (
auto const& node = config[
"cfg.dataroot"]; node) {
170 if (
auto const& node = config[
"cfg.workspace"]; node) {
173 if (
auto const& node = config[
"cfg.log.properties"]; node) {
176 if (
auto const& node = config[
"cfg.req.endpoint"]; node) {
179 if (
auto const& node = config[
"cfg.pub.endpoint"]; node) {
182 if (
auto const& node = config[
"cfg.bin.merge"]; node) {
185 if (
auto const& node = config[
"cfg.bin.rsync"]; node) {
190 if (
auto const& node = config[
"cfg.limit.daq"]; node) {
193 if (
auto const& node = config[
"cfg.limit.merge"]; node) {
196 if (
auto const& node = config[
"cfg.limit.net.receive"]; node) {
199 if (
auto const& node = config[
"cfg.limit.net.send"]; node) {
204 std::throw_with_nested(std::runtime_error(
205 fmt::format(
"Failed to load configuration from {}", m_config.config_file)));