10#include <glog/logging.h>
11#include <absl/flags/flag.h>
12#include <absl/status/status.h>
13#include <absl/status/statusor.h>
14#include "stream_backend.hpp"
15#include "file_ipc/file_ipc_configuration.hpp"
16#include "file_ipc/file_ipc_configuration_flags.hpp"
17#include "redis_ipc/redis_ipc_configuration.hpp"
18#include "redis_ipc/redis_ipc_configuration_flags.hpp"
21ABSL_DECLARE_FLAG(std::string, file_ipc_config_path);
22ABSL_DECLARE_FLAG(std::string, redis_ipc_config_path);
23ABSL_DECLARE_FLAG(
bool, save_default_file_ipc_config);
24ABSL_DECLARE_FLAG(
bool, save_default_redis_ipc_config);
26namespace presage::smartspectra::ipc {
31template<StreamBackend Backend>
49template<StreamBackend Backend>
50int SaveDefaultIpcConfig() {
52 using ConfigType =
typename Traits::ConfigType;
54 ConfigType default_config;
55 std::filesystem::path config_path = Traits::config_filename;
57 auto status = ConfigType::SaveToJson(default_config, config_path);
60 LOG(ERROR) <<
"Failed to save default " << Traits::backend_name
61 <<
" configuration: " << status.message();
62 google::ShutdownGoogleLogging();
66 std::filesystem::path absolute_path = std::filesystem::absolute(config_path);
67 LOG(INFO) <<
"Default " << Traits::backend_name <<
" configuration saved to: " << absolute_path;
68 LOG(INFO) <<
"You can now customize this file and use it with appropriate configuration flags";
69 google::ShutdownGoogleLogging();
80template<StreamBackend Backend>
81bool LoadAndPrepareIpcConfig(
82 StreamBackend backend_type,
83 typename IpcConfigTraits<Backend>::Traits::ConfigType& config
85 using Traits =
typename IpcConfigTraits<Backend>::Traits;
86 using ConfigType =
typename Traits::ConfigType;
89 if (backend_type != Backend) {
94 std::string config_path = [&]() -> std::string {
95 if constexpr (Backend == StreamBackend::kFile) {
96 return absl::GetFlag(FLAGS_file_ipc_config_path);
97 }
else if constexpr (Backend == StreamBackend::kRedis) {
98 return absl::GetFlag(FLAGS_redis_ipc_config_path);
105 if (!config_path.empty()) {
106 auto config_result = ConfigType::LoadFromJson(config_path);
107 if (!config_result.ok()) {
108 LOG(ERROR) <<
"Failed to load " << Traits::backend_name
109 <<
" configuration from " << config_path
110 <<
": " << config_result.status().message();
111 google::ShutdownGoogleLogging();
114 config = *config_result;
115 LOG(INFO) <<
"Loaded " << Traits::backend_name <<
" configuration from: " << config_path;
118 LOG(INFO) <<
"Using default " << Traits::backend_name <<
" configuration (no config file specified)";
123 if constexpr (Backend == StreamBackend::kFile) {
124 return file_ipc::ApplyFlagsToConfiguration(config);
125 }
else if constexpr (Backend == StreamBackend::kRedis) {
126 return redis_ipc::ApplyFlagsToConfiguration(config);
128 return absl::InternalError(
"Unknown backend type");
132 if (!final_config.ok()) {
133 LOG(ERROR) <<
"Failed to apply flags to " << Traits::backend_name
134 <<
" configuration: " << final_config.status().message();
135 google::ShutdownGoogleLogging();
139 config = *final_config;
140 Traits::LogFinalConfig(config);
Definition file_ipc_configuration.hpp:128
Definition handle_alternative_ipc_configurations.hpp:32
Definition redis_ipc_configuration.hpp:195