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