1 #include "broker_core.h" 4 : args_(args), config_filename_(
"config.yml"), logger_(nullptr), broker_(nullptr)
26 logger_->info() <<
"Broker will now start brokering.";
27 broker_->start_brokering();
28 logger_->info() <<
"Broker will now end.";
31 void broker_core::parse_params()
33 using namespace boost::program_options;
36 options_description desc(
"Allowed options for broker");
37 desc.add_options()(
"help,h",
"Writes this help message to stderr")(
38 "config,c", value<std::string>(),
"Set default configuration of this program");
42 store(command_line_parser(args_).options(desc).
run(), vm);
44 }
catch (std::exception &e) {
45 force_exit(
"Error in loading a parameter: " + std::string(e.what()));
50 if (vm.count(
"help")) {
51 std::cerr << desc << std::endl;
55 if (vm.count(
"config")) {
56 config_filename_ = vm[
"config"].as<std::string>();
60 void broker_core::load_config()
63 YAML::Node config_yaml = YAML::LoadFile(config_filename_);
64 config_ = std::make_shared<broker_config>(config_yaml);
65 }
catch (std::exception &e) {
66 force_exit(
"Error loading config file: " + std::string(e.what()));
70 void broker_core::force_exit(std::string msg)
74 if (logger_ !=
nullptr) {
75 logger_->emerg() << msg;
77 std::cerr << msg << std::endl;
83 void broker_core::log_init()
85 auto log_conf = config_->get_log_config();
89 auto path = fs::path(log_conf.log_path);
91 if (!fs::is_directory(path)) {
92 fs::create_directories(path);
94 }
catch (fs::filesystem_error &e) {
95 std::cerr <<
"Logger: " << e.what() << std::endl;
103 std::make_shared<spdlog::sinks::rotating_file_sink_mt>((path / log_conf.log_basename).
string(),
105 log_conf.log_file_size,
106 log_conf.log_files_count,
109 spdlog::set_async_mode(1048576);
111 logger_ = std::make_shared<spdlog::logger>(
"logger", rotating_sink);
113 logger_->set_level(helpers::get_log_level(log_conf.log_level));
115 if (helpers::compare_log_levels(spdlog::level::notice, logger_->level()) > 0) {
116 logger_->emerg() <<
"--- Started ReCodEx broker ---";
118 logger_->notice() <<
"------------------------------";
119 logger_->notice() <<
" Started ReCodEx broker";
120 logger_->notice() <<
"------------------------------";
122 }
catch (spdlog::spdlog_ex &e) {
123 std::cerr <<
"Logger: " << e.what() << std::endl;
128 void broker_core::broker_init()
130 logger_->info() <<
"Initializing broker connection...";
131 workers_ = std::make_shared<worker_registry>();
132 context_ = std::make_shared<zmq::context_t>(1);
133 broker_ = std::make_shared<broker_connect>(config_, context_, workers_, logger_);
134 logger_->info() <<
"Broker connection initialized.";
137 void broker_core::curl_init()
141 logger_->info() <<
"Initializing CURL...";
142 curl_global_init(CURL_GLOBAL_DEFAULT);
143 logger_->info() <<
"CURL initialized.";
146 void broker_core::curl_fini()
149 logger_->info() <<
"Cleanup after CURL...";
150 curl_global_cleanup();
151 logger_->info() <<
"CURL cleaned.";