ifw-daq  3.0.0-pre2
IFW Data Acquisition modules
config.hpp
Go to the documentation of this file.
1 /**
2  * @file
3  * @ingroup server
4  * @copyright ESO - European Southern Observatory
5  * @author
6  *
7  * @brief Config class header file.
8  */
9 #ifndef SERVER_CONFIG_HPP_
10 #define SERVER_CONFIG_HPP_
11 
12 #include <chrono>
13 #include <optional>
14 #include <string>
15 
16 #include <rad/config.hpp>
17 
18 #include <daq/config/manager.hpp>
19 #include <daq/dpmClient.hpp>
20 
21 namespace server {
22 
23 /**
24  * Rad configuration keys
25  */
26 const std::string KEY_CONFIG_PUB_ENDPOINT = rad::KEY_CONFIG + "pub_endpoint";
27 const std::string KEY_CONFIG_INSTRUMENT_ID = rad::KEY_CONFIG + "instrument_id";
28 const std::string KEY_CONFIG_DATAROOT = rad::KEY_CONFIG + "dataroot";
29 const std::string KEY_CONFIG_WORKSPACE = rad::KEY_CONFIG + "daq/workspace";
30 const std::string KEY_CONFIG_STALE_DAQ_ACQUIRING = rad::KEY_CONFIG + "daq/stale_acquiring_hours";
31 const std::string KEY_CONFIG_STALE_DAQ_MERGING = rad::KEY_CONFIG + "daq/stale_merging_hours";
32 
33 const std::string KEY_CONFIG_DPM_REQ_ENDPOINT = rad::KEY_CONFIG + "dpm/req_endpoint";
34 const std::string KEY_CONFIG_DPM_PUB_ENDPOINT = rad::KEY_CONFIG + "dpm/pub_endpoint";
35 const std::string KEY_CONFIG_DPM_TIMEOUT_SEC = rad::KEY_CONFIG + "dpm/timeout_sec";
36 
37 /**
38  * Default application configuration values.
39  */
40 const std::string CONFIG_DEFAULT_PROCNAME = "ocm";
41 const std::string CONFIG_DEFAULT_FILENAME = "config/daqOcmServer/config.yaml";
42 const std::string CONFIG_DEFAULT_WORKSPACE = "ocm";
43 const std::string CONFIG_DEFAULT_SCXML_FILENAME = "config/daqOcmServer/sm.xml";
44 const std::string CONFIG_DEFAULT_LOG_LEVEL = "WARN";
46 const std::string CONFIG_DEFAULT_REQ_ENDPOINT = "zpb.rr://127.0.0.1:12081/";
47 const std::string CONFIG_DEFAULT_PUB_ENDPOINT = "zpb.ps://127.0.0.1:12082/";
48 const std::string CONFIG_DEFAULT_OLDB_URI_PREFIX = "cii.oldb:/elt";
50 
51 /**
52  * Application configuration environment variables
53  */
54 const std::string CONFIG_ENVVAR_OUT_PATH = "DATAROOT";
55 
56 /**
57  * This class provide access to the command line options and
58  * the configuration parameters stored in the configuration file.
59  */
60 class Config {
61 public:
62  /**
63  * Default constructor.
64  *
65  * Initialize application configuration attributes by
66  * - first use the default constant values defined in the header
67  * - override the constant values with environment variables (if defined)
68  */
69  Config();
70 
71  Config(const Config &) = delete; //! Disable copy constructor
72  Config &operator=(const Config &) = delete; //! Disable assignment operator
73 
74  /**
75  * This method parses the command line parameters overriding
76  * the initialization done in the constructor.
77  *
78  * @param[in] argc Number of command line options.
79  * @param[in] argv Pointer to the array of command line options.
80  * @return false if the help option has been invoked, true otherwise.
81  */
82  bool ParseOptions(int argc, char *argv[]);
83 
84  /**
85  * This method load from a configuration file the application
86  * configuration overriding the initialization done in the constructor
87  * and the command line options.
88  *
89  * @param[in] filename Application configuration filename.
90  */
91  void LoadConfig(const std::string &filename = "");
92 
93  /**
94  * @return The network endpoint to send request to this application.
95  * The format is "<middleware>.<protocol>://<ipaddr>:<port>".
96  * For example: "zpb.rr://127.0.0.1:12081/"
97  */
98  const std::string &GetMsgReplierEndpoint() const;
99 
100  /**
101  * @return The network endpoint used to publish topics from this application.
102  * The format is "<middleware>.<protocol>://<ipaddr>:<port>".
103  * For example: "zpb.ps://127.0.0.1:12082/"
104  */
105  const std::string &GetPubEndpoint() const;
106 
107  /**
108  * @return The DB key prefix and port used to connect to the runtime DB.
109  */
110  const std::string &GetDbPrefix() const;
111 
112  /**
113  * @return The timeout used when communicating to the runtime DB.
114  */
115  std::chrono::seconds GetDbTimeout() const;
116 
117  /**
118  * @return The SCXML State Machine model filename used by the application.
119  */
120  const std::string &GetSmScxmlFilename() const;
121 
122  /**
123  * @return The application configuration filename.
124  */
125  const std::string &GetConfigFilename() const;
126 
127  /**
128  * @return The application process name.
129  */
130  const std::string &GetProcName() const;
131 
132  /**
133  * @return The configured log level.
134  */
135  const std::string &GetLogLevel() const;
136 
137  /**
138  * @return The log properties config filename.
139  */
140  const std::string &GetLogProperties() const;
141 
142  /**
143  * @return Workspace root (absolute path)
144  */
145  std::filesystem::path GetWorkspace() const {
146  if (m_workspace.is_relative()) {
147  return m_out_path / m_workspace;
148  }
149  return m_workspace;
150  }
152  return m_mgr;
153  }
155 
157  // We must delay initialization until logging has been configured, otherwise it spams
158  // the log.
159  std::optional<elt::configng::CiiConfigDocument> m_config;
160 
161  std::string m_proc_name;
162  std::string m_instrument_id;
163  std::string m_log_level;
164  std::string m_log_properties;
165  std::string m_config_filename;
166  std::string m_scxml_filename;
167  std::string m_db_prefix;
169  std::string m_req_endpoint;
170  std::string m_pub_endpoint;
171  std::string m_out_path;
172  std::filesystem::path m_workspace;
174  std::chrono::hours m_stale_acquiring = std::chrono::hours(14);
175  std::chrono::hours m_stale_merging = std::chrono::hours(2 * 24);
176 };
177 
178 } // namespace server
179 
180 #endif // SERVER_CONFIG_HPP_
Maintains the associativity of configuration attributes with metadata and value origin/priority.
Definition: manager.hpp:148
This class provide access to the command line options and the configuration parameters stored in the ...
Definition: config.hpp:60
const std::string & GetLogLevel() const
Definition: config.cpp:327
std::filesystem::path GetWorkspace() const
Definition: config.hpp:145
std::string m_pub_endpoint
Definition: config.hpp:170
daq::DpmClientParams m_dpm_params
Definition: config.hpp:173
Config(const Config &)=delete
std::string m_out_path
Definition: config.hpp:171
const std::string & GetSmScxmlFilename() const
Definition: config.cpp:312
std::string m_log_properties
Definition: config.hpp:164
bool ParseOptions(int argc, char *argv[])
Disable assignment operator.
Definition: config.cpp:90
Config()
Default constructor.
Definition: config.cpp:39
daq::DpmClientParams const & GetDpmClientParams() const
Definition: config.cpp:337
const std::string & GetMsgReplierEndpoint() const
Definition: config.cpp:289
const std::string & GetConfigFilename() const
Definition: config.cpp:317
int m_db_timeout_sec
Definition: config.hpp:168
void LoadConfig(const std::string &filename="")
This method load from a configuration file the application configuration overriding the initializatio...
Definition: config.cpp:166
std::chrono::seconds GetDbTimeout() const
Definition: config.cpp:308
std::string m_proc_name
Definition: config.hpp:161
daq::config::Manager & GetMgr()
Definition: config.hpp:151
std::optional< elt::configng::CiiConfigDocument > m_config
Definition: config.hpp:159
std::chrono::hours m_stale_merging
Definition: config.hpp:175
std::string m_log_level
Definition: config.hpp:163
Config & operator=(const Config &)=delete
Disable copy constructor.
std::chrono::hours m_stale_acquiring
Definition: config.hpp:174
std::string m_instrument_id
Definition: config.hpp:162
const std::string & GetLogProperties() const
Definition: config.cpp:332
std::string m_req_endpoint
Definition: config.hpp:169
std::string m_config_filename
Definition: config.hpp:165
daq::config::Manager m_mgr
Definition: config.hpp:156
std::string m_db_prefix
Definition: config.hpp:167
std::filesystem::path m_workspace
Definition: config.hpp:172
const std::string & GetProcName() const
Definition: config.cpp:322
const std::string & GetPubEndpoint() const
Definition: config.cpp:294
std::string m_scxml_filename
Definition: config.hpp:166
const std::string & GetDbPrefix() const
Definition: config.cpp:299
daq::config::Manager and associated types.
daq::DpmClient
Connection parameters for DPM.
Definition: dpmClient.hpp:74
const std::string CONFIG_DEFAULT_WORKSPACE
Definition: config.hpp:42
const std::string KEY_CONFIG_PUB_ENDPOINT
Rad configuration keys.
Definition: config.hpp:26
const std::string KEY_CONFIG_DPM_TIMEOUT_SEC
Definition: config.hpp:35
const std::string KEY_CONFIG_STALE_DAQ_ACQUIRING
Definition: config.hpp:30
const std::string CONFIG_DEFAULT_SCXML_FILENAME
Definition: config.hpp:43
const std::string KEY_CONFIG_DATAROOT
Definition: config.hpp:28
const std::string CONFIG_DEFAULT_REQ_ENDPOINT
Definition: config.hpp:46
const std::string CONFIG_DEFAULT_OLDB_URI_PREFIX
Definition: config.hpp:48
const std::string KEY_CONFIG_DPM_PUB_ENDPOINT
Definition: config.hpp:34
const std::string KEY_CONFIG_WORKSPACE
Definition: config.hpp:29
const int CONFIG_DEFAULT_DB_TIMEOUT_SEC
Definition: config.hpp:45
const std::string CONFIG_DEFAULT_PUB_ENDPOINT
Definition: config.hpp:47
const std::string CONFIG_DEFAULT_LOG_LEVEL
Definition: config.hpp:44
const std::string KEY_CONFIG_INSTRUMENT_ID
Definition: config.hpp:27
const std::string CONFIG_ENVVAR_OUT_PATH
Application configuration environment variables.
Definition: config.hpp:54
const std::string CONFIG_DEFAULT_PROCNAME
Default application configuration values.
Definition: config.hpp:40
const std::string CONFIG_DEFAULT_FILENAME
Definition: config.hpp:41
const std::string KEY_CONFIG_STALE_DAQ_MERGING
Definition: config.hpp:31
const int CONFIG_DEFAULT_OLDB_CONN_TIMEOUT
Definition: config.hpp:49
const std::string KEY_CONFIG_DPM_REQ_ENDPOINT
Definition: config.hpp:33