-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathYamlReader_configuration.cpp
More file actions
369 lines (318 loc) · 13.2 KB
/
YamlReader_configuration.cpp
File metadata and controls
369 lines (318 loc) · 13.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
// Copyright 2022 Proyectos y Sistemas de Mantenimiento SL (eProsima).
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include <set>
#include <ddspipe_participants/configuration/DiscoveryServerParticipantConfiguration.hpp>
#include <ddspipe_participants/configuration/EchoParticipantConfiguration.hpp>
#include <ddspipe_participants/configuration/InitialPeersParticipantConfiguration.hpp>
#include <ddspipe_participants/configuration/ParticipantConfiguration.hpp>
#include <ddspipe_participants/configuration/SimpleParticipantConfiguration.hpp>
#include <ddspipe_participants/configuration/XmlParticipantConfiguration.hpp>
#include <ddspipe_yaml/yaml_configuration_tags.hpp>
#include <ddspipe_yaml/Yaml.hpp>
#include <ddspipe_yaml/YamlManager.hpp>
#include <ddspipe_yaml/YamlReader.hpp>
#include <ddspipe_yaml/YamlValidator.hpp>
#include <ddspipe_core/configuration/DdsPipeConfiguration.hpp>
#include <ddspipe_core/configuration/MonitorConfiguration.hpp>
#include <ddsrouter_core/configuration/DdsRouterConfiguration.hpp>
#include <ddsrouter_yaml/YamlReaderConfiguration.hpp>
namespace eprosima {
namespace ddspipe {
namespace yaml {
template <>
bool YamlValidator::validate<core::MonitorConfiguration>(
const Yaml& yml,
const YamlReaderVersion& /* version */)
{
// The method is rewritten to provide a specific validation of the DDS Router's MonitorConfiguration:
// i.e. the DDS Router's MonitorConfiguration doesn't have a status.
static const std::set<TagType> tags{
MONITOR_DOMAIN_TAG,
MONITOR_TOPICS_TAG};
return YamlValidator::validate_tags(yml, tags);
}
template <>
void YamlReader::fill(
ddsrouter::core::SpecsConfiguration& object,
const Yaml& yml,
const YamlReaderVersion version)
{
/////
// Get optional number of threads
if (YamlReader::is_tag_present(yml, NUMBER_THREADS_TAG))
{
object.number_of_threads = YamlReader::get<unsigned int>(yml, NUMBER_THREADS_TAG, version);
}
/////
// Get optional remove unused entities tag
if (YamlReader::is_tag_present(yml, REMOVE_UNUSED_ENTITIES_TAG))
{
object.remove_unused_entities = YamlReader::get<bool>(yml, REMOVE_UNUSED_ENTITIES_TAG, version);
}
// Optional Topic QoS
if (is_tag_present(yml, SPECS_QOS_TAG))
{
object.topic_qos = YamlReader::get<core::types::TopicQoS>(yml, SPECS_QOS_TAG, version);
core::types::TopicQoS::default_topic_qos.set_value(object.topic_qos);
}
/////
// Get optional discovery trigger tag
if (YamlReader::is_tag_present(yml, DISCOVERY_TRIGGER_TAG))
{
const std::string discovery_trigger = YamlReader::get<std::string>(yml, DISCOVERY_TRIGGER_TAG, version);
std::string discovery_trigger_caps = discovery_trigger;
utils::to_uppercase(discovery_trigger_caps);
const bool ret_code = ddspipe::core::string_to_enumeration(discovery_trigger_caps, object.discovery_trigger);
if (!ret_code)
{
throw eprosima::utils::ConfigurationException(
utils::Formatter() << "The discovery-trigger " << discovery_trigger << " is not valid.");
}
}
/////
// Get optional Log Configuration
if (YamlReader::is_tag_present(yml, LOG_CONFIGURATION_TAG))
{
object.log_configuration = YamlReader::get<ddspipe::core::DdsPipeLogConfiguration>(yml, LOG_CONFIGURATION_TAG,
version);
}
/////
// Get optional monitor tag
if (YamlReader::is_tag_present(yml, MONITOR_TAG))
{
object.monitor_configuration = YamlReader::get<core::MonitorConfiguration>(yml, MONITOR_TAG, version);
}
}
template <>
bool YamlValidator::validate<ddsrouter::core::SpecsConfiguration>(
const Yaml& yml,
const YamlReaderVersion& /* version */)
{
static const std::set<TagType> tags{
NUMBER_THREADS_TAG,
REMOVE_UNUSED_ENTITIES_TAG,
SPECS_QOS_TAG,
DISCOVERY_TRIGGER_TAG,
LOG_CONFIGURATION_TAG,
MONITOR_TAG};
return YamlValidator::validate_tags(yml, tags);
}
template <>
ddsrouter::core::SpecsConfiguration YamlReader::get<ddsrouter::core::SpecsConfiguration>(
const Yaml& yml,
const YamlReaderVersion version)
{
YamlValidator::validate<ddsrouter::core::SpecsConfiguration>(yml, version);
ddsrouter::core::SpecsConfiguration object;
fill<ddsrouter::core::SpecsConfiguration>(object, yml, version);
return object;
}
template <>
ddsrouter::core::types::ParticipantKind YamlReader::get(
const Yaml& yml,
const YamlReaderVersion /* version */)
{
// Domain id required
return get_enumeration_from_builder<ddsrouter::core::types::ParticipantKind>(yml,
*ddsrouter::core::types::ParticipantKindBuilder::get_instance());
}
template <>
std::shared_ptr<participants::ParticipantConfiguration>
YamlReader::get<std::shared_ptr<participants::ParticipantConfiguration>>(
const Yaml& yml,
const YamlReaderVersion version)
{
// Kind required
ddsrouter::core::types::ParticipantKind kind = YamlReader::get<ddsrouter::core::types::ParticipantKind>(yml,
PARTICIPANT_KIND_TAG,
version);
EPROSIMA_LOG_INFO(DDSROUTER_YAML_CONFIGURATION, "Loading Participant of kind " << kind << ".");
switch (kind)
{
case ddsrouter::core::types::ParticipantKind::echo:
return std::make_shared<participants::EchoParticipantConfiguration>(
YamlReader::get<participants::EchoParticipantConfiguration>(yml, version));
case ddsrouter::core::types::ParticipantKind::simple:
return std::make_shared<participants::SimpleParticipantConfiguration>(
YamlReader::get<participants::SimpleParticipantConfiguration>(yml, version));
case ddsrouter::core::types::ParticipantKind::discovery_server:
return std::make_shared<participants::DiscoveryServerParticipantConfiguration>(
YamlReader::get<participants::DiscoveryServerParticipantConfiguration>(yml, version));
case ddsrouter::core::types::ParticipantKind::initial_peers:
return std::make_shared<participants::InitialPeersParticipantConfiguration>(
YamlReader::get<participants::InitialPeersParticipantConfiguration>(yml, version));
case ddsrouter::core::types::ParticipantKind::xml:
return std::make_shared<participants::XmlParticipantConfiguration>(
YamlReader::get<participants::XmlParticipantConfiguration>(yml, version));
default:
// Non recheable code
throw eprosima::utils::ConfigurationException(
utils::Formatter() << "Unkown or non valid Participant kind: " << kind << ".");
}
}
template <>
void YamlReader::fill(
core::DdsPipeConfiguration& object,
const Yaml& yml,
const YamlReaderVersion version)
{
/////
// Get optional allowlist
if (YamlReader::is_tag_present(yml, ALLOWLIST_TAG))
{
auto allowlist_set = YamlReader::get_set<core::types::WildcardDdsFilterTopic>(yml, ALLOWLIST_TAG, version);
for (auto const& wild_topic : allowlist_set)
{
auto new_topic = utils::Heritable<core::types::WildcardDdsFilterTopic>::make_heritable(wild_topic);
object.allowlist.insert(new_topic);
}
}
/////
// Get optional blocklist
if (YamlReader::is_tag_present(yml, BLOCKLIST_TAG))
{
auto blocklist_set = YamlReader::get_set<core::types::WildcardDdsFilterTopic>(yml, BLOCKLIST_TAG, version);
for (auto const& wild_topic : blocklist_set)
{
auto new_topic = utils::Heritable<core::types::WildcardDdsFilterTopic>::make_heritable(wild_topic);
object.blocklist.insert(new_topic);
}
}
/////
// Get optional builtin topics
if (YamlReader::is_tag_present(yml, BUILTIN_TAG))
{
object.builtin_topics = YamlReader::get_set<utils::Heritable<core::types::DistributedTopic>>(yml,
BUILTIN_TAG,
version);
}
/////
// Get optional routes
if (YamlReader::is_tag_present(yml, ROUTES_TAG))
{
object.routes = YamlReader::get<core::RoutesConfiguration>(yml, ROUTES_TAG, version);
}
/////
// Get optional topic routes
if (YamlReader::is_tag_present(yml, TOPIC_ROUTES_TAG))
{
object.topic_routes = YamlReader::get<core::TopicRoutesConfiguration>(yml, TOPIC_ROUTES_TAG, version);
}
/////
// Get optional topics
if (YamlReader::is_tag_present(yml, TOPICS_TAG))
{
const auto& manual_topics = YamlReader::get_list<core::types::ManualTopic>(yml, TOPICS_TAG, version);
object.manual_topics = std::vector<core::types::ManualTopic>(manual_topics.begin(), manual_topics.end());
}
}
template <>
core::DdsPipeConfiguration YamlReader::get<core::DdsPipeConfiguration>(
const Yaml& yml,
const YamlReaderVersion version)
{
// The DdsPipeConfiguration's fields don't correspond to a YAML section and, therefore, can't be validated.
// Instead, they are validated in the methods above (most of them in the DdsRouterConfiguration).
core::DdsPipeConfiguration object;
fill<core::DdsPipeConfiguration>(object, yml, version);
return object;
}
template <>
void YamlReader::fill(
ddsrouter::core::DdsRouterConfiguration& object,
const Yaml& yml,
const YamlReaderVersion version)
{
/////
// Get participants configurations. Required field, if get_value_in_tag fail propagate exception.
auto participants_configurations_yml = YamlReader::get_value_in_tag(yml, COLLECTION_PARTICIPANTS_TAG);
// TODO do it in a single instruction
// Check it is a list
if (!participants_configurations_yml.IsSequence())
{
throw eprosima::utils::ConfigurationException(
utils::Formatter() <<
"Participant configurations must be specified in an array under tag: " <<
COLLECTION_PARTICIPANTS_TAG);
}
for (auto conf : participants_configurations_yml)
{
ddsrouter::core::types::ParticipantKind kind =
YamlReader::get<ddsrouter::core::types::ParticipantKind>(conf, PARTICIPANT_KIND_TAG, version);
object.participants_configurations.insert(
{
kind,
YamlReader::get<std::shared_ptr<participants::ParticipantConfiguration>>(conf, version)
}
);
}
/////
// Get optional specs configuration
if (YamlReader::is_tag_present(yml, SPECS_TAG))
{
object.advanced_options = get<ddsrouter::core::SpecsConfiguration>(YamlReader::get_value_in_tag(yml,
SPECS_TAG),
version);
}
// DDS Pipe Configuration
object.ddspipe_configuration = YamlReader::get<core::DdsPipeConfiguration>(yml, version);
/* NOTE
*
* remove_unused_entities and discovery_trigger are attributes of SpecsConfiguration because they are
* under the tag specs, but since they are used in the DdsPipe, we have two choices: copying them to the
* DdsPipeConfiguration, as we are doing, or refilling the SpecsConfiguraton in the DdsPipeConfiguration fill
* and taking both attributes from there.
*/
object.ddspipe_configuration.remove_unused_entities = object.advanced_options.remove_unused_entities;
object.ddspipe_configuration.discovery_trigger = object.advanced_options.discovery_trigger;
object.ddspipe_configuration.log_configuration = object.advanced_options.log_configuration;
/////
// Get optional xml configuration
if (YamlReader::is_tag_present(yml, XML_TAG))
{
object.xml_configuration = YamlReader::get<participants::XmlHandlerConfiguration>(yml, XML_TAG, version);
}
}
template <>
DDSPIPE_YAML_DllAPI
bool YamlValidator::validate<ddsrouter::core::DdsRouterConfiguration>(
const Yaml& yml,
const YamlReaderVersion& /* version */)
{
static const std::set<TagType> tags{
VERSION_TAG,
COLLECTION_PARTICIPANTS_TAG,
XML_TAG,
ALLOWLIST_TAG,
BLOCKLIST_TAG,
BUILTIN_TAG,
ROUTES_TAG,
TOPIC_ROUTES_TAG,
TOPICS_TAG,
SPECS_TAG};
return YamlValidator::validate_tags(yml, tags);
}
template <>
ddsrouter::core::DdsRouterConfiguration YamlReader::get<ddsrouter::core::DdsRouterConfiguration>(
const Yaml& yml,
const YamlReaderVersion version)
{
YamlValidator::validate<ddsrouter::core::DdsRouterConfiguration>(yml, version);
ddsrouter::core::DdsRouterConfiguration object;
fill<ddsrouter::core::DdsRouterConfiguration>(object, yml, version);
return object;
}
} // namespace yaml
} // namespace ddspipe
} // namespace eprosima