libadc-cxx 1.0.0
Structured logging for scientific computing
Loading...
Searching...
No Matches
factory.ipp
Go to the documentation of this file.
1/* Copyright 2025 NTESS. See the top-level LICENSE.txt file for details.
2 *
3 * SPDX-License-Identifier: BSD-3-Clause
4 */
5#ifndef adc_factory_ipp
6#define adc_factory_ipp
7#include <string>
8#include <map>
9#include "boost/json/src.hpp"
10#include "adc/factory.hpp"
11
12// add a base class for common impl details like pause/resume
13// #include <adc/builder/impl/base_publisher.ipp>
14
15#define ADC_PUBLISHER_NONE_NAME "none"
17
18#define ADC_PUBLISHER_STDOUT_NAME "stdout"
20
21#define ADC_PUBLISHER_SYSLOG_NAME "syslog"
23
24#define ADC_PUBLISHER_FILE_NAME "file"
26
27#define ADC_PUBLISHER_MULTIFILE_NAME "multifile"
29
30#define ADC_PUBLISHER_CURL_NAME "curl"
32
33#define ADC_PUBLISHER_LDMS_SUBPROCESS_NAME "ldmsd_stream_publish"
35
36#define ADC_PUBLISHER_LDMS_SUBPROCESS_MESSAGE_NAME "ldms_message_publish"
38
39#define ADC_PUBLISHER_SCRIPT_NAME "script"
41
42#ifdef ADC_HAVE_LDMS
43
44#ifdef ENABLE_ADC_PUBLISHER_LIBLDMS_MSG
45#define ADC_PUBLISHER_LIBLDMS_MSG_NAME "libldms_msg"
47#endif
48
49#endif
50
51#ifdef ENABLE_ADC_PUBLISHER_LIBCURL
52#define ADC_PUBLISHER_LIBCURL_NAME "libcurl"
54#endif
55
56#if ADC_HAVE_ADIAK
57
58#define ADC_PUBLISHER_LIBADIAK_NAME "libadiak_many"
60
61#if defined(ADIAK_HAVE_JSONSTRING) && (ADIAK_HAVE_JSONSTRING==1)
62#define ADC_PUBLISHER_LIBADIAK_JSON_NAME "libadiak_json"
64#endif
65
66#endif
67
69
71
72namespace adc {
73
74void factory::init()
75{
76 if (names.size() == 0 ) {
77 // init list of uninstantiated plugin
78 names.insert( ADC_PUBLISHER_NONE_NAME );
79 names.insert( ADC_PUBLISHER_FILE_NAME );
80 names.insert( ADC_PUBLISHER_MULTIFILE_NAME );
81 names.insert( ADC_PUBLISHER_STDOUT_NAME );
82 names.insert( ADC_PUBLISHER_SYSLOG_NAME );
83 names.insert( ADC_PUBLISHER_CURL_NAME );
86 names.insert( ADC_PUBLISHER_SCRIPT_NAME );
87
88#ifdef ENABLE_ADC_PUBLISHER_LIBCURL
89 names.insert( ADC_PUBLISHER_LIBCURL_NAME );
90#endif
91
92#ifdef ENABLE_ADC_PUBLISHER_LIBLDMS_MSG
93#define ADC_PUBLISHER_LIBLDMS_MSG_NAME "libldms_msg"
94 names.insert( ADC_PUBLISHER_LIBLDMS_MSG_NAME );
95#endif
96
97#ifdef ENABLE_ADC_PUBLISHER_LIBADIAK
98 names.insert( ADC_PUBLISHER_LIBADIAK_NAME );
99#endif
100
101#ifdef ADC_PUBLISHER_LIBADIAK_JSON_NAME
102 names.insert( ADC_PUBLISHER_LIBADIAK_JSON_NAME );
103#endif
104
105 }
106 const char *env = getenv("ADC_MULTI_PUBLISHER_DEBUG");
107 if (env && !strcmp(env,"1") ) {
108 debug = 1;
109 } else {
110 debug = 0;
111 }
112
113}
114
115std::shared_ptr<multi_publisher_api> factory::get_multi_publisher()
116{
117 std::shared_ptr<multi_publisher_api> p(new multi_publisher);
118 return p;
119}
120
121std::shared_ptr<multi_publisher_api> factory::get_multi_publisher_from_env(const std::string& namelist)
122{
123 std::shared_ptr<multi_publisher_api> mp(new multi_publisher);
124 const char *env;
125 if (!namelist.size()) {
126 env = getenv("ADC_MULTI_PUBLISHER_NAMES");
127 } else {
128 env = getenv(namelist.c_str());
129 }
130 if (env) {
131 auto enames = split_string(std::string(env), ':');
132 return get_multi_publisher_from_env(enames);
133 }
134 return mp;
135}
136
137std::shared_ptr<multi_publisher_api> factory::get_multi_publisher_from_env(std::vector<std::string>& namelist)
138{
139
140 std::shared_ptr<multi_publisher_api> mp(new multi_publisher);
141 if (namelist.size() != 0) {
142 const std::map< std::string, std::string > m;
143 for (auto n : namelist) {
144 std::shared_ptr<publisher_api> p = get_publisher(n);
145 if (p) {
146 if (debug) {
147 std::cout << "multi_publisher: publisher"
148 " found named: " << n << std::endl;
149 }
150 int ec = p->config(m);
151 if (ec) {
152 if (debug) {
153 std::cout << "multi_publisher: config"
154 " failed for: " << n << std::endl;
155 }
156 continue;
157 }
158 int ei = p->initialize();
159 if (ei) {
160 if (debug) {
161 std::cout << "multi_publisher: initialize"
162 " failed for: " << n << std::endl;
163 }
164 continue;
165 }
166 mp->add(p);
167 } else {
168 if (debug) {
169 std::cout << "multi_publisher: no publisher"
170 " found named: " << n << std::endl;
171 }
172 }
173 }
174 }
175 return mp;
176}
177
178std::shared_ptr<publisher_api> factory::get_publisher( const std::string& name)
179{
180 init();
181 auto it = names.find(name);
182 if (it != names.end()) {
183 if (name == ADC_PUBLISHER_NONE_NAME ) {
184 std::shared_ptr<publisher_api> p(new none_plugin);
185 return p;
186 }
187 if (name == ADC_PUBLISHER_STDOUT_NAME ) {
188 std::shared_ptr<publisher_api> p(new stdout_plugin);
189 return p;
190 }
191 if (name == ADC_PUBLISHER_SYSLOG_NAME ) {
192 std::shared_ptr<publisher_api> p(new syslog_plugin);
193 return p;
194 }
195 if (name == ADC_PUBLISHER_FILE_NAME ) {
196 std::shared_ptr<publisher_api> p(new file_plugin);
197 return p;
198 }
199 if (name == ADC_PUBLISHER_MULTIFILE_NAME ) {
200 std::shared_ptr<publisher_api> p(new multifile_plugin);
201 return p;
202 }
203 if (name == ADC_PUBLISHER_CURL_NAME ) {
204 std::shared_ptr<publisher_api> p(new curl_plugin);
205 return p;
206 }
208 std::shared_ptr<publisher_api> p(new ldmsd_stream_publish_plugin);
209 return p;
210 }
212 std::shared_ptr<publisher_api> p(new ldms_message_publish_plugin);
213 return p;
214 }
215 if (name == ADC_PUBLISHER_SCRIPT_NAME) {
216 std::shared_ptr<publisher_api> p(new script_plugin);
217 return p;
218 }
219#ifdef ENABLE_ADC_PUBLISHER_LDMS_STREAM
220 // todo
221#endif
222#ifdef ENABLE_ADC_PUBLISHER_LIBCURL
223 // todo
224#endif
225#ifdef ENABLE_ADC_PUBLISHER_LIBADIAK
226 if (name == ADC_PUBLISHER_LIBADIAK_NAME ) {
227 std::shared_ptr<publisher_api> p(new libadiak_plugin);
228 return p;
229 }
230#endif
231 }
232 return std::shared_ptr<publisher_api>();
233}
234
235std::shared_ptr<publisher_api> factory::get_publisher(const std::string& name, const std::map<std::string, std::string>& opts)
236{
237 init();
238 auto it = names.find(name);
239 if (it != names.end()) {
240 if (name == ADC_PUBLISHER_NONE_NAME ) {
241 std::shared_ptr<publisher_api> p(new none_plugin());
242 p->config(opts);
243 return p;
244 }
245 if (name == ADC_PUBLISHER_STDOUT_NAME ) {
246 std::shared_ptr<publisher_api> p(new stdout_plugin());
247 p->config(opts);
248 return p;
249 }
250 if (name == ADC_PUBLISHER_SYSLOG_NAME ) {
251 std::shared_ptr<publisher_api> p(new syslog_plugin());
252 p->config(opts);
253 return p;
254 }
255 if (name == ADC_PUBLISHER_FILE_NAME ) {
256 std::shared_ptr<publisher_api> p(new file_plugin());
257 p->config(opts);
258 return p;
259 }
260 if (name == ADC_PUBLISHER_MULTIFILE_NAME ) {
261 std::shared_ptr<publisher_api> p(new multifile_plugin());
262 p->config(opts);
263 return p;
264 }
265 if (name == ADC_PUBLISHER_CURL_NAME ) {
266 std::shared_ptr<publisher_api> p(new curl_plugin());
267 p->config(opts);
268 return p;
269 }
271 std::shared_ptr<publisher_api> p(new ldmsd_stream_publish_plugin());
272 p->config(opts);
273 return p;
274 }
276 std::shared_ptr<publisher_api> p(new ldms_message_publish_plugin());
277 p->config(opts);
278 return p;
279 }
280 if (name == ADC_PUBLISHER_SCRIPT_NAME) {
281 std::shared_ptr<publisher_api> p(new script_plugin());
282 p->config(opts);
283 return p;
284 }
285 // TODO: ldmsd lib publisher
286 // TODO: ldms lib publisher
287 // TODO: curl lib publisher
288 }
289 return std::shared_ptr<publisher_api>();
290}
291
292// return the names of publishers available
293// there's a cleaner view solution to this in c++20, but we're assuming 17.
294const std::set<std::string>& factory::get_publisher_names()
295{
296 init();
297 return names;
298}
299
300std::shared_ptr<builder_api> factory::get_builder()
301{
302 std::shared_ptr<builder_api> b(new builder);
303 return b;
304}
305
306
307} // end adc
308#endif // adc_factory_ipp
Implementation of builder_api with optional (compile-time) support of MPI. If compiled without MPI,...
Definition builder.hpp:36
Curl utility publisher_api implementation. This plugin generates a scratch file (in-memory) and async...
Definition curl.ipp:25
const std::set< std::string > & get_publisher_names()
Definition factory.ipp:294
std::shared_ptr< publisher_api > get_publisher(const std::string &name)
Definition factory.ipp:178
std::shared_ptr< multi_publisher_api > get_multi_publisher()
Definition factory.ipp:115
std::shared_ptr< multi_publisher_api > get_multi_publisher_from_env(const std::string &env_name)
Definition factory.ipp:121
std::shared_ptr< builder_api > get_builder()
Definition factory.ipp:300
File output publisher_api implementation. This plugin generates writes each message to the configured...
Definition file.ipp:34
ldms_message_publish utility publisher_api implementation. This plugin generates a scratch file (in-m...
ldmsd_stream_publish utility publisher_api implementation. This plugin generates a scratch file (in-m...
Parallel file output publisher_api implementation. This plugin generates writes each message to the c...
Definition multifile.ipp:47
Message suppression publisher; it quietly ignores all publication requests.
Definition none.ipp:14
User script publisher plugin. The program specified by environment variable is used to asynchronously...
Definition script.ipp:26
Terminal output publisher_api implementation. This plugin sends messages to stdout synchronously....
Definition stdout.ipp:21
syslog publisher_api implementation. This plugin sends messages to syslog synchronously....
Definition syslog.ipp:46
#define ADC_PUBLISHER_SCRIPT_NAME
Definition factory.ipp:39
#define ADC_PUBLISHER_MULTIFILE_NAME
Definition factory.ipp:27
#define ADC_PUBLISHER_NONE_NAME
Definition factory.ipp:15
#define ADC_PUBLISHER_STDOUT_NAME
Definition factory.ipp:18
#define ADC_PUBLISHER_CURL_NAME
Definition factory.ipp:30
#define ADC_PUBLISHER_LDMS_SUBPROCESS_MESSAGE_NAME
Definition factory.ipp:36
#define ADC_PUBLISHER_SYSLOG_NAME
Definition factory.ipp:21
#define ADC_PUBLISHER_LDMS_SUBPROCESS_NAME
Definition factory.ipp:33
#define ADC_PUBLISHER_FILE_NAME
Definition factory.ipp:24
Definition adc.hpp:82
std::vector< std::string > split_string(const std::string &s, char delimiter)
Definition builder.ipp:473