From 2c0f46a6a28adeda24c424a58db08d0b8f3800f8 Mon Sep 17 00:00:00 2001 From: tempate Date: Fri, 19 Jan 2024 09:01:19 +0100 Subject: [PATCH 01/13] Validate YAML tags on parsing Signed-off-by: tempate Uncrustify Signed-off-by: tempate Include YamlValidator.cpp in tests' CMakeLists Signed-off-by: tempate Make validate_tags public Signed-off-by: tempate --- .../include/ddspipe_yaml/YamlValidator.hpp | 44 ++++ ddspipe_yaml/src/cpp/YamlReader_features.cpp | 96 ++++---- .../src/cpp/YamlReader_participants.cpp | 125 +++++++++- ddspipe_yaml/src/cpp/YamlReader_types.cpp | 216 +++++++++++++++++- ddspipe_yaml/src/cpp/YamlValidator.cpp | 54 +++++ .../unittest/entities/address/CMakeLists.txt | 1 + .../unittest/entities/guid/CMakeLists.txt | 1 + .../unittest/entities/topic/CMakeLists.txt | 1 + .../entities/transport/CMakeLists.txt | 2 + .../forwarding_routes/routes/CMakeLists.txt | 1 + .../topic_routes/CMakeLists.txt | 1 + .../yaml_reader/scalar/CMakeLists.txt | 1 + 12 files changed, 501 insertions(+), 42 deletions(-) create mode 100644 ddspipe_yaml/include/ddspipe_yaml/YamlValidator.hpp create mode 100644 ddspipe_yaml/src/cpp/YamlValidator.cpp diff --git a/ddspipe_yaml/include/ddspipe_yaml/YamlValidator.hpp b/ddspipe_yaml/include/ddspipe_yaml/YamlValidator.hpp new file mode 100644 index 00000000..600bc182 --- /dev/null +++ b/ddspipe_yaml/include/ddspipe_yaml/YamlValidator.hpp @@ -0,0 +1,44 @@ +// Copyright 2024 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. + +#pragma once + +#include +#include +#include + +namespace eprosima { +namespace ddspipe { +namespace yaml { + +// TODO +class YamlValidator +{ +public: + + //! TODO + template + static bool validate( + const Yaml& yml, + const YamlReaderVersion& version = YamlReaderVersion::LATEST); + + //! TODO + static bool validate_tags( + const Yaml& yml, + const std::set& tags); +}; + +} /* namespace yaml */ +} /* namespace ddspipe */ +} /* namespace eprosima */ diff --git a/ddspipe_yaml/src/cpp/YamlReader_features.cpp b/ddspipe_yaml/src/cpp/YamlReader_features.cpp index 28b09d8e..84c70ae7 100644 --- a/ddspipe_yaml/src/cpp/YamlReader_features.cpp +++ b/ddspipe_yaml/src/cpp/YamlReader_features.cpp @@ -30,6 +30,7 @@ #include #include +#include #include namespace eprosima { @@ -60,12 +61,27 @@ void YamlReader::fill( } } +template <> +DDSPIPE_YAML_DllAPI +bool YamlValidator::validate( + const Yaml& yml, + const YamlReaderVersion& /* version */) +{ + const std::set tags{ + XML_RAW_TAG, + XML_FILES_TAG}; + + return YamlValidator::validate_tags(yml, tags); +} + template <> DDSPIPE_YAML_DllAPI participants::XmlHandlerConfiguration YamlReader::get( const Yaml& yml, const YamlReaderVersion version) { + YamlValidator::validate(yml, version); + participants::XmlHandlerConfiguration object; fill(object, yml, version); return object; @@ -75,6 +91,19 @@ participants::XmlHandlerConfiguration YamlReader::get( * Routes Configuration * ************************/ +template <> +DDSPIPE_YAML_DllAPI +bool YamlValidator::validate( + const Yaml& yml, + const YamlReaderVersion& /* version */) +{ + const std::set tags{ + ROUTES_SRC_TAG, + ROUTES_DST_TAG}; + + return YamlValidator::validate_tags(yml, tags); +} + template <> DDSPIPE_YAML_DllAPI void YamlReader::fill( @@ -93,25 +122,20 @@ void YamlReader::fill( for (const auto& route_yml : yml) { + // The validation has to be done here since the yml object is a list with the route + YamlValidator::validate(route_yml, version); + core::types::ParticipantId src; std::set dst; // Required route source - if (is_tag_present(route_yml, ROUTES_SRC_TAG)) - { - src = get(route_yml, ROUTES_SRC_TAG, version); - if (object.routes.count(src) != 0) - { - throw eprosima::utils::ConfigurationException( - utils::Formatter() << - "Multiple routes defined for participant " << src << " : only one allowed."); - } - } - else + src = get(route_yml, ROUTES_SRC_TAG, version); + + if (object.routes.count(src) != 0) { throw eprosima::utils::ConfigurationException( utils::Formatter() << - "Source participant required under tag " << ROUTES_SRC_TAG << " in route definition."); + "Multiple routes defined for participant " << src << " : only one allowed."); } // Optional route destination(s) @@ -145,6 +169,20 @@ core::RoutesConfiguration YamlReader::get( * Topic Routes Configuration * ******************************/ +template <> +DDSPIPE_YAML_DllAPI +bool YamlValidator::validate( + const Yaml& yml, + const YamlReaderVersion& /* version */) +{ + const std::set tags{ + TOPIC_NAME_TAG, + TOPIC_TYPE_NAME_TAG, + ROUTES_TAG}; + + return YamlValidator::validate_tags(yml, tags); +} + template <> DDSPIPE_YAML_DllAPI void YamlReader::fill( @@ -163,44 +201,24 @@ void YamlReader::fill( for (const auto& topic_routes_yml : yml) { + YamlValidator::validate(topic_routes_yml, version); + // utils::Heritable topic; auto topic = utils::Heritable::make_heritable(); core::RoutesConfiguration routes; // Required topic and type names - if (!(is_tag_present(topic_routes_yml, - TOPIC_NAME_TAG) && is_tag_present(topic_routes_yml, TOPIC_TYPE_NAME_TAG))) - { - throw eprosima::utils::ConfigurationException( - utils::Formatter() << - "Topic routes require topic and type names to be defined under tags " << TOPIC_NAME_TAG << " and " << TOPIC_TYPE_NAME_TAG << - ", respectively."); - } - else - { - topic = get>(topic_routes_yml, version); - if (object.topic_routes.count(topic) != 0) - { - throw eprosima::utils::ConfigurationException( - utils::Formatter() << - "Multiple routes defined for topic " << topic << " : only one allowed."); - } - } + fill(topic.get_reference(), topic_routes_yml, version); - // Required routes - if (is_tag_present(topic_routes_yml, ROUTES_TAG)) - { - routes = get(topic_routes_yml, ROUTES_TAG, version); - } - else + if (object.topic_routes.count(topic) != 0) { throw eprosima::utils::ConfigurationException( utils::Formatter() << - "No routes found under tag " << ROUTES_TAG << " for topic " << topic << " ."); + "Multiple routes defined for topic " << topic << " : only one allowed."); } - // Insert routes - object.topic_routes[topic] = routes; + // Required route + object.topic_routes[topic] = get(topic_routes_yml, ROUTES_TAG, version); } } diff --git a/ddspipe_yaml/src/cpp/YamlReader_participants.cpp b/ddspipe_yaml/src/cpp/YamlReader_participants.cpp index 6c52ed31..e7267531 100644 --- a/ddspipe_yaml/src/cpp/YamlReader_participants.cpp +++ b/ddspipe_yaml/src/cpp/YamlReader_participants.cpp @@ -36,6 +36,7 @@ #include #include +#include #include namespace eprosima { @@ -62,12 +63,27 @@ void YamlReader::fill( object.id = get(yml, PARTICIPANT_NAME_TAG, version); } +template <> +DDSPIPE_YAML_DllAPI +bool YamlValidator::validate( + const Yaml& yml, + const YamlReaderVersion& /* version */) +{ + const std::set tags{ + PARTICIPANT_NAME_TAG, + PARTICIPANT_KIND_TAG}; + + return YamlValidator::validate_tags(yml, tags); +} + template <> DDSPIPE_YAML_DllAPI participants::ParticipantConfiguration YamlReader::get( const Yaml& yml, const YamlReaderVersion version) { + YamlValidator::validate(yml, version); + participants::ParticipantConfiguration object; fill(object, yml, version); return object; @@ -104,12 +120,30 @@ void YamlReader::fill( } } +template <> +DDSPIPE_YAML_DllAPI +bool YamlValidator::validate( + const Yaml& yml, + const YamlReaderVersion& /* version */) +{ + const std::set tags{ + PARTICIPANT_NAME_TAG, + PARTICIPANT_KIND_TAG, + ECHO_DATA_TAG, + ECHO_DISCOVERY_TAG, + ECHO_VERBOSE_TAG}; + + return YamlValidator::validate_tags(yml, tags); +} + template <> DDSPIPE_YAML_DllAPI participants::EchoParticipantConfiguration YamlReader::get( const Yaml& yml, const YamlReaderVersion version) { + YamlValidator::validate(yml, version); + participants::EchoParticipantConfiguration object; fill(object, yml, version); return object; @@ -164,16 +198,36 @@ void YamlReader::fill( // Optional Praticipant Topic QoS if (YamlReader::is_tag_present(yml, PARTICIPANT_QOS_TAG)) { - fill(object.topic_qos, get_value_in_tag(yml, PARTICIPANT_QOS_TAG), version); + object.topic_qos = get(yml, PARTICIPANT_QOS_TAG, version); } } +template <> +DDSPIPE_YAML_DllAPI +bool YamlValidator::validate( + const Yaml& yml, + const YamlReaderVersion& /* version */) +{ + const std::set tags{ + PARTICIPANT_NAME_TAG, + PARTICIPANT_KIND_TAG, + DOMAIN_ID_TAG, + WHITELIST_INTERFACES_TAG, + TRANSPORT_DESCRIPTORS_TRANSPORT_TAG, + IGNORE_PARTICIPANT_FLAGS_TAG, + PARTICIPANT_QOS_TAG}; + + return YamlValidator::validate_tags(yml, tags); +} + template <> DDSPIPE_YAML_DllAPI participants::SimpleParticipantConfiguration YamlReader::get( const Yaml& yml, const YamlReaderVersion version) { + YamlValidator::validate(yml, version); + participants::SimpleParticipantConfiguration object; fill(object, yml, version); return object; @@ -249,12 +303,36 @@ void YamlReader::fill( } } +template <> +DDSPIPE_YAML_DllAPI +bool YamlValidator::validate( + const Yaml& yml, + const YamlReaderVersion& /* version */) +{ + const std::set tags{ + PARTICIPANT_NAME_TAG, + PARTICIPANT_KIND_TAG, + DOMAIN_ID_TAG, + WHITELIST_INTERFACES_TAG, + TRANSPORT_DESCRIPTORS_TRANSPORT_TAG, + IGNORE_PARTICIPANT_FLAGS_TAG, + PARTICIPANT_QOS_TAG, + LISTENING_ADDRESSES_TAG, + CONNECTION_ADDRESSES_TAG, + TLS_TAG, + DISCOVERY_SERVER_GUID_PREFIX_TAG}; + + return YamlValidator::validate_tags(yml, tags); +} + template <> DDSPIPE_YAML_DllAPI participants::DiscoveryServerParticipantConfiguration YamlReader::get( const Yaml& yml, const YamlReaderVersion version) { + YamlValidator::validate(yml, version); + participants::DiscoveryServerParticipantConfiguration object; fill(object, yml, version); return object; @@ -310,12 +388,36 @@ void YamlReader::fill( } } +template <> +DDSPIPE_YAML_DllAPI +bool YamlValidator::validate( + const Yaml& yml, + const YamlReaderVersion& /* version */) +{ + const std::set tags{ + PARTICIPANT_NAME_TAG, + PARTICIPANT_KIND_TAG, + DOMAIN_ID_TAG, + WHITELIST_INTERFACES_TAG, + TRANSPORT_DESCRIPTORS_TRANSPORT_TAG, + IGNORE_PARTICIPANT_FLAGS_TAG, + PARTICIPANT_QOS_TAG, + LISTENING_ADDRESSES_TAG, + CONNECTION_ADDRESSES_TAG, + TLS_TAG, + IS_REPEATER_TAG}; + + return YamlValidator::validate_tags(yml, tags); +} + template <> DDSPIPE_YAML_DllAPI participants::InitialPeersParticipantConfiguration YamlReader::get( const Yaml& yml, const YamlReaderVersion version) { + YamlValidator::validate(yml, version); + participants::InitialPeersParticipantConfiguration object; fill(object, yml, version); return object; @@ -337,12 +439,33 @@ void YamlReader::fill( object.participant_profile = YamlReader::get(yml, XML_PARTICIPANT_PROFILE_TAG, version); } +template <> +DDSPIPE_YAML_DllAPI +bool YamlValidator::validate( + const Yaml& yml, + const YamlReaderVersion& /* version */) +{ + const std::set tags{ + PARTICIPANT_NAME_TAG, + PARTICIPANT_KIND_TAG, + DOMAIN_ID_TAG, + WHITELIST_INTERFACES_TAG, + TRANSPORT_DESCRIPTORS_TRANSPORT_TAG, + IGNORE_PARTICIPANT_FLAGS_TAG, + PARTICIPANT_QOS_TAG, + XML_PARTICIPANT_PROFILE_TAG}; + + return YamlValidator::validate_tags(yml, tags); +} + template <> DDSPIPE_YAML_DllAPI participants::XmlParticipantConfiguration YamlReader::get( const Yaml& yml, const YamlReaderVersion version) { + YamlValidator::validate(yml, version); + participants::XmlParticipantConfiguration object; fill(object, yml, version); return object; diff --git a/ddspipe_yaml/src/cpp/YamlReader_types.cpp b/ddspipe_yaml/src/cpp/YamlReader_types.cpp index 1d54c607..46246a37 100644 --- a/ddspipe_yaml/src/cpp/YamlReader_types.cpp +++ b/ddspipe_yaml/src/cpp/YamlReader_types.cpp @@ -41,6 +41,7 @@ #include #include +#include #include namespace eprosima { @@ -151,12 +152,28 @@ DomainId YamlReader::get( return domain; } +template <> +DDSPIPE_YAML_DllAPI +bool YamlValidator::validate( + const Yaml& yml, + const YamlReaderVersion& /* version */) +{ + const std::set tags{ + DISCOVERY_SERVER_GUID_TAG, + DISCOVERY_SERVER_ID_TAG, + DISCOVERY_SERVER_ID_ROS_TAG}; + + return YamlValidator::validate_tags(yml, tags); +} + template <> DDSPIPE_YAML_DllAPI GuidPrefix YamlReader::get( const Yaml& yml, const YamlReaderVersion /* version */) { + YamlValidator::validate(yml); + // If guid exists, use it. Non mandatory. if (is_tag_present(yml, DISCOVERY_SERVER_GUID_TAG)) { @@ -191,12 +208,31 @@ GuidPrefix YamlReader::get( } } +template <> +DDSPIPE_YAML_DllAPI +bool YamlValidator::validate
( + const Yaml& yml, + const YamlReaderVersion& /* version */) +{ + const std::set tags{ + ADDRESS_IP_VERSION_TAG, + ADDRESS_IP_TAG, + ADDRESS_DNS_TAG, + ADDRESS_PORT_TAG, + ADDRESS_EXTERNAL_PORT_TAG, + ADDRESS_TRANSPORT_TAG}; + + return YamlValidator::validate_tags(yml, tags); +} + template <> DDSPIPE_YAML_DllAPI Address YamlReader::get
( const Yaml& yml, const YamlReaderVersion version) { + YamlValidator::validate
(yml, version); + // Optional get IP version IpVersion ip_version; bool ip_version_set = is_tag_present(yml, ADDRESS_IP_VERSION_TAG); @@ -302,6 +338,74 @@ Address YamlReader::get
( } } +DiscoveryServerConnectionAddress _get_discovery_server_connection_address_v1( + const Yaml& yml, + const YamlReaderVersion version) +{ + // GuidPrefix required + GuidPrefix server_guid = YamlReader::get(yml, version); + + // Addresses required + std::set
addresses = YamlReader::get_set
(yml, COLLECTION_ADDRESSES_TAG, version); + + // Create Connection Address + return DiscoveryServerConnectionAddress(server_guid, addresses); +} + +DiscoveryServerConnectionAddress _get_discovery_server_connection_address_latest( + const Yaml& yml, + const YamlReaderVersion version) +{ + // GuidPrefix required + GuidPrefix server_guid = YamlReader::get(yml, DISCOVERY_SERVER_GUID_PREFIX_TAG, version); + + // Addresses required + std::set
addresses = YamlReader::get_set
(yml, COLLECTION_ADDRESSES_TAG, version); + + // Create Connection Address + return DiscoveryServerConnectionAddress(server_guid, addresses); +} + +template <> +DDSPIPE_YAML_DllAPI +bool YamlValidator::validate( + const Yaml& yml, + const YamlReaderVersion& version) +{ + std::set tags{ + COLLECTION_ADDRESSES_TAG}; + + switch (version) + { + case V_1_0: + break; + + default: + tags.insert(DISCOVERY_SERVER_GUID_PREFIX_TAG); + break; + } + + return YamlValidator::validate_tags(yml, tags); +} + +template <> +DDSPIPE_YAML_DllAPI +DiscoveryServerConnectionAddress YamlReader::get( + const Yaml& yml, + const YamlReaderVersion version) +{ + YamlValidator::validate(yml, version); + + switch (version) + { + case V_1_0: + return _get_discovery_server_connection_address_v1(yml, version); + + default: + return _get_discovery_server_connection_address_latest(yml, version); + } +} + template <> DDSPIPE_YAML_DllAPI void YamlReader::fill( @@ -424,6 +528,39 @@ void YamlReader::fill( } } +template <> +DDSPIPE_YAML_DllAPI +bool YamlValidator::validate( + const Yaml& yml, + const YamlReaderVersion& /* version */) +{ + const std::set tags{ + QOS_TRANSIENT_TAG, + QOS_RELIABLE_TAG, + QOS_OWNERSHIP_TAG, + QOS_PARTITION_TAG, + QOS_HISTORY_DEPTH_TAG, + QOS_KEYED_TAG, + QOS_MAX_TX_RATE_TAG, + QOS_MAX_RX_RATE_TAG, + QOS_DOWNSAMPLING_TAG}; + + return YamlValidator::validate_tags(yml, tags); +} + +template <> +DDSPIPE_YAML_DllAPI +TopicQoS YamlReader::get( + const Yaml& yml, + const YamlReaderVersion version) +{ + YamlValidator::validate(yml, version); + + TopicQoS object; + fill(object, yml, version); + return object; +} + /************************ * LOGGING CONFIGURATION * ************************/ @@ -530,12 +667,27 @@ void YamlReader::fill( object.type_name = get(yml, TOPIC_TYPE_NAME_TAG, version); } +template <> +DDSPIPE_YAML_DllAPI +bool YamlValidator::validate( + const Yaml& yml, + const YamlReaderVersion& /* version */) +{ + const std::set tags{ + TOPIC_NAME_TAG, + TOPIC_TYPE_NAME_TAG}; + + return YamlValidator::validate_tags(yml, tags); +} + template <> DDSPIPE_YAML_DllAPI DdsTopic YamlReader::get( const Yaml& yml, const YamlReaderVersion version) { + YamlValidator::validate(yml, version); + DdsTopic object; fill(object, yml, version); return object; @@ -560,16 +712,32 @@ void YamlReader::fill( // Optional QoS if (is_tag_present(yml, TOPIC_QOS_TAG)) { - fill(object.topic_qos, get_value_in_tag(yml, TOPIC_QOS_TAG), version); + object.topic_qos = get(yml, TOPIC_QOS_TAG, version); } } +template <> +DDSPIPE_YAML_DllAPI +bool YamlValidator::validate( + const Yaml& yml, + const YamlReaderVersion& /* version */) +{ + const std::set tags{ + TOPIC_NAME_TAG, + TOPIC_TYPE_NAME_TAG, + TOPIC_QOS_TAG}; + + return YamlValidator::validate_tags(yml, tags); +} + template <> DDSPIPE_YAML_DllAPI WildcardDdsFilterTopic YamlReader::get( const Yaml& yml, const YamlReaderVersion version) { + YamlValidator::validate(yml, version); + WildcardDdsFilterTopic object; fill(object, yml, version); return object; @@ -582,7 +750,10 @@ void YamlReader::fill( const Yaml& yml, const YamlReaderVersion version) { - auto manual_topic = YamlReader::get(yml, version); + // Avoid calling YamlReader::get to avoid validation at a lower level + WildcardDdsFilterTopic manual_topic; + YamlReader::fill(manual_topic, yml, version); + object.first = utils::Heritable::make_heritable(manual_topic); // Optional participants tag @@ -592,12 +763,29 @@ void YamlReader::fill( } } +template <> +DDSPIPE_YAML_DllAPI +bool YamlValidator::validate( + const Yaml& yml, + const YamlReaderVersion& /* version */) +{ + const std::set tags{ + TOPIC_NAME_TAG, + TOPIC_TYPE_NAME_TAG, + TOPIC_QOS_TAG, + TOPIC_PARTICIPANTS_TAG}; + + return YamlValidator::validate_tags(yml, tags); +} + template <> DDSPIPE_YAML_DllAPI ManualTopic YamlReader::get( const Yaml& yml, const YamlReaderVersion version) { + YamlValidator::validate(yml, version); + auto topic = utils::Heritable::make_heritable(); std::set participants; ManualTopic object = std::make_pair(topic, participants); @@ -612,6 +800,8 @@ utils::Heritable YamlReader::get( const YamlReaderVersion version) { // TODO: do not assume it is a Dds Topic + YamlValidator::validate(yml, version); + auto topic = utils::Heritable::make_heritable(); fill(topic.get_reference(), yml, version); return topic; @@ -624,6 +814,8 @@ utils::Heritable YamlReader::get( const YamlReaderVersion version) { // TODO: do not assume it is a Wildcard Topic + YamlValidator::validate(yml, version); + auto topic = utils::Heritable::make_heritable(); fill(topic.get_reference(), yml, version); return topic; @@ -709,12 +901,32 @@ void YamlReader::fill( } } +template <> +DDSPIPE_YAML_DllAPI +bool YamlValidator::validate( + const Yaml& yml, + const YamlReaderVersion& /* version */) +{ + const std::set tags{ + TLS_PRIVATE_KEY_TAG, + TLS_PASSWORD_TAG, + TLS_CA_TAG, + TLS_CERT_TAG, + TLS_SNI_HOST_TAG, + TLS_DHPARAMS_TAG, + TLS_PEER_VERIFICATION_TAG}; + + return YamlValidator::validate_tags(yml, tags); +} + template <> DDSPIPE_YAML_DllAPI TlsConfiguration YamlReader::get( const Yaml& yml, const YamlReaderVersion version) { + YamlValidator::validate(yml, version); + TlsConfiguration object; fill(object, yml, version); return object; diff --git a/ddspipe_yaml/src/cpp/YamlValidator.cpp b/ddspipe_yaml/src/cpp/YamlValidator.cpp new file mode 100644 index 00000000..ef640b08 --- /dev/null +++ b/ddspipe_yaml/src/cpp/YamlValidator.cpp @@ -0,0 +1,54 @@ +// Copyright 2024 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. + +/** + * @file YamlValidator.cpp + * + */ + +#include +#include + +namespace eprosima { +namespace ddspipe { +namespace yaml { + +bool YamlValidator::validate_tags( + const Yaml& yml, + const std::set& tags) +{ + if (!yml.IsMap() && !yml.IsNull()) + { + throw eprosima::utils::ConfigurationException( + utils::Formatter() << "The yml: <" << yml << "> is not a yaml object map."); + } + + // Check if there are any extra tags that are not in either list + for (const auto& tag_it : yml) + { + const auto& tag = tag_it.first.as(); + + if (!tags.count(tag)) + { + logWarning(DDSPIPE_YAML, "Tag <" << tag << "> is not a valid tag."); + return false; + } + } + + return true; +} + +} /* namespace yaml */ +} /* namespace ddspipe */ +} /* namespace eprosima */ diff --git a/ddspipe_yaml/test/unittest/entities/address/CMakeLists.txt b/ddspipe_yaml/test/unittest/entities/address/CMakeLists.txt index 30f991d6..7c501325 100644 --- a/ddspipe_yaml/test/unittest/entities/address/CMakeLists.txt +++ b/ddspipe_yaml/test/unittest/entities/address/CMakeLists.txt @@ -22,6 +22,7 @@ set(TEST_SOURCES ${PROJECT_SOURCE_DIR}/src/cpp/YamlReader_generic.cpp ${PROJECT_SOURCE_DIR}/src/cpp/YamlReader_participants.cpp ${PROJECT_SOURCE_DIR}/src/cpp/YamlReader_types.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/YamlValidator.cpp YamlGetEntityAddressTest.cpp ) diff --git a/ddspipe_yaml/test/unittest/entities/guid/CMakeLists.txt b/ddspipe_yaml/test/unittest/entities/guid/CMakeLists.txt index 605db8fc..9960d596 100644 --- a/ddspipe_yaml/test/unittest/entities/guid/CMakeLists.txt +++ b/ddspipe_yaml/test/unittest/entities/guid/CMakeLists.txt @@ -24,6 +24,7 @@ set(TEST_SOURCES ${PROJECT_SOURCE_DIR}/src/cpp/YamlReader_participants.cpp ${PROJECT_SOURCE_DIR}/src/cpp/YamlReader_types.cpp ${PROJECT_SOURCE_DIR}/src/cpp/YamlManager.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/YamlValidator.cpp ) diff --git a/ddspipe_yaml/test/unittest/entities/topic/CMakeLists.txt b/ddspipe_yaml/test/unittest/entities/topic/CMakeLists.txt index 373cdba5..86da44c0 100644 --- a/ddspipe_yaml/test/unittest/entities/topic/CMakeLists.txt +++ b/ddspipe_yaml/test/unittest/entities/topic/CMakeLists.txt @@ -24,6 +24,7 @@ set(TEST_SOURCES ${PROJECT_SOURCE_DIR}/src/cpp/YamlReader_participants.cpp ${PROJECT_SOURCE_DIR}/src/cpp/YamlReader_types.cpp ${PROJECT_SOURCE_DIR}/src/cpp/YamlManager.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/YamlValidator.cpp ) diff --git a/ddspipe_yaml/test/unittest/entities/transport/CMakeLists.txt b/ddspipe_yaml/test/unittest/entities/transport/CMakeLists.txt index a54dc70c..9779672d 100644 --- a/ddspipe_yaml/test/unittest/entities/transport/CMakeLists.txt +++ b/ddspipe_yaml/test/unittest/entities/transport/CMakeLists.txt @@ -24,6 +24,7 @@ set(TEST_SOURCES ${PROJECT_SOURCE_DIR}/src/cpp/YamlReader_participants.cpp ${PROJECT_SOURCE_DIR}/src/cpp/YamlReader_types.cpp ${PROJECT_SOURCE_DIR}/src/cpp/YamlManager.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/YamlValidator.cpp ) @@ -60,6 +61,7 @@ set(TEST_SOURCES ${PROJECT_SOURCE_DIR}/src/cpp/YamlReader_participants.cpp ${PROJECT_SOURCE_DIR}/src/cpp/YamlReader_types.cpp ${PROJECT_SOURCE_DIR}/src/cpp/YamlManager.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/YamlValidator.cpp ) diff --git a/ddspipe_yaml/test/unittest/yaml_reader/forwarding_routes/routes/CMakeLists.txt b/ddspipe_yaml/test/unittest/yaml_reader/forwarding_routes/routes/CMakeLists.txt index fd12f1f5..81971b78 100644 --- a/ddspipe_yaml/test/unittest/yaml_reader/forwarding_routes/routes/CMakeLists.txt +++ b/ddspipe_yaml/test/unittest/yaml_reader/forwarding_routes/routes/CMakeLists.txt @@ -23,6 +23,7 @@ set(TEST_SOURCES ${PROJECT_SOURCE_DIR}/src/cpp/YamlReader_generic.cpp ${PROJECT_SOURCE_DIR}/src/cpp/YamlReader_participants.cpp ${PROJECT_SOURCE_DIR}/src/cpp/YamlReader_types.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/YamlValidator.cpp YamlReaderRoutesTest.cpp ) diff --git a/ddspipe_yaml/test/unittest/yaml_reader/forwarding_routes/topic_routes/CMakeLists.txt b/ddspipe_yaml/test/unittest/yaml_reader/forwarding_routes/topic_routes/CMakeLists.txt index 6f1733e7..d536d0f6 100644 --- a/ddspipe_yaml/test/unittest/yaml_reader/forwarding_routes/topic_routes/CMakeLists.txt +++ b/ddspipe_yaml/test/unittest/yaml_reader/forwarding_routes/topic_routes/CMakeLists.txt @@ -23,6 +23,7 @@ set(TEST_SOURCES ${PROJECT_SOURCE_DIR}/src/cpp/YamlReader_generic.cpp ${PROJECT_SOURCE_DIR}/src/cpp/YamlReader_participants.cpp ${PROJECT_SOURCE_DIR}/src/cpp/YamlReader_types.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/YamlValidator.cpp YamlReaderTopicRoutesTest.cpp ) diff --git a/ddspipe_yaml/test/unittest/yaml_reader/scalar/CMakeLists.txt b/ddspipe_yaml/test/unittest/yaml_reader/scalar/CMakeLists.txt index 31c9731c..1fbfc973 100644 --- a/ddspipe_yaml/test/unittest/yaml_reader/scalar/CMakeLists.txt +++ b/ddspipe_yaml/test/unittest/yaml_reader/scalar/CMakeLists.txt @@ -22,6 +22,7 @@ set(TEST_SOURCES ${PROJECT_SOURCE_DIR}/src/cpp/YamlReader_generic.cpp ${PROJECT_SOURCE_DIR}/src/cpp/YamlReader_participants.cpp ${PROJECT_SOURCE_DIR}/src/cpp/YamlReader_types.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/YamlValidator.cpp YamlReaderScalarTest.cpp ) From 820a7ea16fee6e9dc79ac4f4ff86cfaa31bbcc20 Mon Sep 17 00:00:00 2001 From: tempate Date: Mon, 22 Jan 2024 11:54:59 +0100 Subject: [PATCH 02/13] Throw as many warnings as incorrect tags Signed-off-by: tempate --- ddspipe_yaml/src/cpp/YamlValidator.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ddspipe_yaml/src/cpp/YamlValidator.cpp b/ddspipe_yaml/src/cpp/YamlValidator.cpp index ef640b08..60ed3c97 100644 --- a/ddspipe_yaml/src/cpp/YamlValidator.cpp +++ b/ddspipe_yaml/src/cpp/YamlValidator.cpp @@ -35,6 +35,8 @@ bool YamlValidator::validate_tags( } // Check if there are any extra tags that are not in either list + bool has_extra_tags = false; + for (const auto& tag_it : yml) { const auto& tag = tag_it.first.as(); @@ -42,11 +44,11 @@ bool YamlValidator::validate_tags( if (!tags.count(tag)) { logWarning(DDSPIPE_YAML, "Tag <" << tag << "> is not a valid tag."); - return false; + has_extra_tags = true; } } - return true; + return !has_extra_tags; } } /* namespace yaml */ From ee2b96f0eabdfd978f3e49898d53edba0247260a Mon Sep 17 00:00:00 2001 From: tempate Date: Mon, 22 Jan 2024 15:10:06 +0100 Subject: [PATCH 03/13] Validate the Timestamp's YAML tags on parsing Signed-off-by: tempate --- ddspipe_yaml/src/cpp/YamlReader_generic.cpp | 20 +++++++++++++++++++ .../test/unittest/yaml_writer/CMakeLists.txt | 2 ++ 2 files changed, 22 insertions(+) diff --git a/ddspipe_yaml/src/cpp/YamlReader_generic.cpp b/ddspipe_yaml/src/cpp/YamlReader_generic.cpp index eabc3d4b..d0ea9a29 100644 --- a/ddspipe_yaml/src/cpp/YamlReader_generic.cpp +++ b/ddspipe_yaml/src/cpp/YamlReader_generic.cpp @@ -38,6 +38,7 @@ #include #include +#include #include namespace eprosima { @@ -290,12 +291,31 @@ std::string YamlReader::get( return get_scalar(yml); } +template <> +DDSPIPE_YAML_DllAPI +bool YamlValidator::validate( + const Yaml& yml, + const YamlReaderVersion& /* version */) +{ + const std::set tags{ + TIMESTAMP_DATETIME_FORMAT_TAG, + TIMESTAMP_LOCAL_TAG, + TIMESTAMP_DATETIME_TAG, + TIMESTAMP_MILLISECONDS_TAG, + TIMESTAMP_MICROSECONDS_TAG, + TIMESTAMP_NANOSECONDS_TAG}; + + return YamlValidator::validate_tags(yml, tags); +} + template <> DDSPIPE_YAML_DllAPI utils::Timestamp YamlReader::get( const Yaml& yml, const YamlReaderVersion version /* version */) { + YamlValidator::validate(yml, version); + utils::Timestamp ret_timestamp; std::string datetime_str; std::string datetime_format("%Y-%m-%d_%H-%M-%S"); diff --git a/ddspipe_yaml/test/unittest/yaml_writer/CMakeLists.txt b/ddspipe_yaml/test/unittest/yaml_writer/CMakeLists.txt index b245030b..ea07c24b 100644 --- a/ddspipe_yaml/test/unittest/yaml_writer/CMakeLists.txt +++ b/ddspipe_yaml/test/unittest/yaml_writer/CMakeLists.txt @@ -20,6 +20,7 @@ set(TEST_NAME YamlWriterTest) set(TEST_SOURCES ${PROJECT_SOURCE_DIR}/src/cpp/YamlReader_generic.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/YamlValidator.cpp ${PROJECT_SOURCE_DIR}/src/cpp/YamlWriter.cpp YamlWriterTest.cpp ) @@ -61,6 +62,7 @@ set(TEST_NAME YamlWriter_collections_test) set(TEST_SOURCES ${PROJECT_SOURCE_DIR}/src/cpp/YamlReader_generic.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/YamlValidator.cpp ${PROJECT_SOURCE_DIR}/src/cpp/YamlWriter.cpp YamlWriter_collections_test.cpp ) From 46fd33530bce19ab95edb410562187f9143636f6 Mon Sep 17 00:00:00 2001 From: tempate Date: Thu, 11 Apr 2024 09:17:23 +0200 Subject: [PATCH 04/13] Validate new YAML options Signed-off-by: tempate --- ddspipe_yaml/src/cpp/YamlReader_features.cpp | 33 ++++++++++- ddspipe_yaml/src/cpp/YamlReader_types.cpp | 58 ++++++++++++++++--- ddspipe_yaml/src/cpp/YamlValidator.cpp | 2 +- .../yaml_reader/monitoring/CMakeLists.txt | 1 + 4 files changed, 81 insertions(+), 13 deletions(-) diff --git a/ddspipe_yaml/src/cpp/YamlReader_features.cpp b/ddspipe_yaml/src/cpp/YamlReader_features.cpp index 84c70ae7..6c2f0538 100644 --- a/ddspipe_yaml/src/cpp/YamlReader_features.cpp +++ b/ddspipe_yaml/src/cpp/YamlReader_features.cpp @@ -233,9 +233,9 @@ core::TopicRoutesConfiguration YamlReader::get( return object; } -/************************* - * Monitor Configuration * - **************************/ +/************************** +* Monitor Configuration * +**************************/ template <> DDSPIPE_YAML_DllAPI @@ -277,6 +277,20 @@ void YamlReader::fill( } } +template <> +DDSPIPE_YAML_DllAPI +bool YamlValidator::validate( + const Yaml& yml, + const YamlReaderVersion& /* version */) +{ + const std::set tags{ + MONITOR_DOMAIN_TAG, + MONITOR_STATUS_TAG, + MONITOR_TOPICS_TAG}; + + return YamlValidator::validate_tags(yml, tags); +} + template <> DDSPIPE_YAML_DllAPI core::MonitorConfiguration YamlReader::get( @@ -308,6 +322,19 @@ void YamlReader::fill( } } +template <> +DDSPIPE_YAML_DllAPI +bool YamlValidator::validate( + const Yaml& yml, + const YamlReaderVersion& /* version */) +{ + const std::set tags{ + MONITOR_ENABLE_TAG, + MONITOR_PERIOD_TAG}; + + return YamlValidator::validate_tags(yml, tags); +} + template <> DDSPIPE_YAML_DllAPI core::MonitorProducerConfiguration YamlReader::get( diff --git a/ddspipe_yaml/src/cpp/YamlReader_types.cpp b/ddspipe_yaml/src/cpp/YamlReader_types.cpp index 46246a37..ce71fa68 100644 --- a/ddspipe_yaml/src/cpp/YamlReader_types.cpp +++ b/ddspipe_yaml/src/cpp/YamlReader_types.cpp @@ -375,14 +375,9 @@ bool YamlValidator::validate( std::set tags{ COLLECTION_ADDRESSES_TAG}; - switch (version) + if (version != V_1_0) { - case V_1_0: - break; - - default: - tags.insert(DISCOVERY_SERVER_GUID_PREFIX_TAG); - break; + tags.insert(DISCOVERY_SERVER_GUID_PREFIX_TAG); } return YamlValidator::validate_tags(yml, tags); @@ -429,12 +424,29 @@ void YamlReader::fill( } } +template <> +DDSPIPE_YAML_DllAPI +bool YamlValidator::validate( + const Yaml& yml, + const YamlReaderVersion& /* version */) +{ + const std::set tags{ + DDS_PUBLISHING_ENABLE_TAG, + DDS_PUBLISHING_DOMAIN_TAG, + DDS_PUBLISHING_TOPIC_NAME_TAG, + DDS_PUBLISHING_PUBLISH_TYPE_TAG}; + + return YamlValidator::validate_tags(yml, tags); +} + template <> DDSPIPE_YAML_DllAPI core::DdsPublishingConfiguration YamlReader::get( const Yaml& yml, const YamlReaderVersion version) { + YamlValidator::validate(yml, version); + core::DdsPublishingConfiguration object; fill(object, yml, version); return object; @@ -482,8 +494,7 @@ void YamlReader::fill( { if (get(yml, QOS_OWNERSHIP_TAG, version)) { - object.ownership_qos.set_value( - ddspipe::core::types::OwnershipQosPolicyKind::EXCLUSIVE_OWNERSHIP_QOS); + object.ownership_qos.set_value(ddspipe::core::types::OwnershipQosPolicyKind::EXCLUSIVE_OWNERSHIP_QOS); } else { @@ -588,6 +599,20 @@ void YamlReader::fill( } } +template <> +DDSPIPE_YAML_DllAPI +bool YamlValidator::validate( + const Yaml& yml, + const YamlReaderVersion& /* version */) +{ + const std::set tags{ + LOG_FILTER_ERROR_TAG, + LOG_FILTER_WARNING_TAG, + LOG_FILTER_INFO_TAG}; + + return YamlValidator::validate_tags(yml, tags); +} + template <> DDSPIPE_YAML_DllAPI utils::LogFilter YamlReader::get( @@ -638,6 +663,21 @@ void YamlReader::fill( } } +template <> +DDSPIPE_YAML_DllAPI +bool YamlValidator::validate( + const Yaml& yml, + const YamlReaderVersion& /* version */) +{ + const std::set tags{ + LOG_PUBLISH_TAG, + LOG_STDOUT_TAG, + LOG_VERBOSITY_TAG, + LOG_FILTER_TAG}; + + return YamlValidator::validate_tags(yml, tags); +} + template <> DDSPIPE_YAML_DllAPI core::DdsPipeLogConfiguration YamlReader::get( diff --git a/ddspipe_yaml/src/cpp/YamlValidator.cpp b/ddspipe_yaml/src/cpp/YamlValidator.cpp index 60ed3c97..ae237d2f 100644 --- a/ddspipe_yaml/src/cpp/YamlValidator.cpp +++ b/ddspipe_yaml/src/cpp/YamlValidator.cpp @@ -34,7 +34,7 @@ bool YamlValidator::validate_tags( utils::Formatter() << "The yml: <" << yml << "> is not a yaml object map."); } - // Check if there are any extra tags that are not in either list + // Check if there are any extra tags that are not in the list bool has_extra_tags = false; for (const auto& tag_it : yml) diff --git a/ddspipe_yaml/test/unittest/yaml_reader/monitoring/CMakeLists.txt b/ddspipe_yaml/test/unittest/yaml_reader/monitoring/CMakeLists.txt index e38c635c..683e7f14 100644 --- a/ddspipe_yaml/test/unittest/yaml_reader/monitoring/CMakeLists.txt +++ b/ddspipe_yaml/test/unittest/yaml_reader/monitoring/CMakeLists.txt @@ -23,6 +23,7 @@ set(TEST_SOURCES ${PROJECT_SOURCE_DIR}/src/cpp/YamlReader_generic.cpp ${PROJECT_SOURCE_DIR}/src/cpp/YamlReader_participants.cpp ${PROJECT_SOURCE_DIR}/src/cpp/YamlReader_types.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/YamlValidator.cpp YamlReaderMonitorTest.cpp ) From 604ba45d64760a0ff48ac12f080b285d5076ae5f Mon Sep 17 00:00:00 2001 From: tempate Date: Wed, 24 Apr 2024 12:47:37 +0200 Subject: [PATCH 05/13] Make tag-sets static Signed-off-by: tempate --- .../include/ddspipe_yaml/YamlValidator.hpp | 27 ++++++++++++++++--- ddspipe_yaml/src/cpp/YamlReader_features.cpp | 12 +++++---- ddspipe_yaml/src/cpp/YamlReader_generic.cpp | 4 ++- .../src/cpp/YamlReader_participants.cpp | 14 +++++----- ddspipe_yaml/src/cpp/YamlReader_types.cpp | 22 ++++++++------- 5 files changed, 54 insertions(+), 25 deletions(-) diff --git a/ddspipe_yaml/include/ddspipe_yaml/YamlValidator.hpp b/ddspipe_yaml/include/ddspipe_yaml/YamlValidator.hpp index 600bc182..f9230726 100644 --- a/ddspipe_yaml/include/ddspipe_yaml/YamlValidator.hpp +++ b/ddspipe_yaml/include/ddspipe_yaml/YamlValidator.hpp @@ -14,6 +14,8 @@ #pragma once +#include + #include #include #include @@ -22,18 +24,37 @@ namespace eprosima { namespace ddspipe { namespace yaml { -// TODO +/** + * @brief Yaml Validator + * + * This class is used to validate Yaml objects. + */ class YamlValidator { public: - //! TODO + /** + * @brief Validate a Yaml object against a specific version. + * + * For each type, the function should call \c validate_tags with the maximum set of tags \c yml may contain. + * + * @tparam T Type of the object to validate. + * @param yml Yaml object to validate. + * @param version Version to validate against. + */ + DDSPIPE_YAML_DllAPI template static bool validate( const Yaml& yml, const YamlReaderVersion& version = YamlReaderVersion::LATEST); - //! TODO + /** + * @brief Ensure that all the tags in \c yml are in \c tags. + * + * @param yml Yaml object to validate. + * @param tags Set of tags to validate against. + */ + DDSPIPE_YAML_DllAPI static bool validate_tags( const Yaml& yml, const std::set& tags); diff --git a/ddspipe_yaml/src/cpp/YamlReader_features.cpp b/ddspipe_yaml/src/cpp/YamlReader_features.cpp index 6c2f0538..5bc3efb9 100644 --- a/ddspipe_yaml/src/cpp/YamlReader_features.cpp +++ b/ddspipe_yaml/src/cpp/YamlReader_features.cpp @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include + #include #include @@ -67,7 +69,7 @@ bool YamlValidator::validate( const Yaml& yml, const YamlReaderVersion& /* version */) { - const std::set tags{ + static const std::set tags{ XML_RAW_TAG, XML_FILES_TAG}; @@ -97,7 +99,7 @@ bool YamlValidator::validate( const Yaml& yml, const YamlReaderVersion& /* version */) { - const std::set tags{ + static const std::set tags{ ROUTES_SRC_TAG, ROUTES_DST_TAG}; @@ -175,7 +177,7 @@ bool YamlValidator::validate( const Yaml& yml, const YamlReaderVersion& /* version */) { - const std::set tags{ + static const std::set tags{ TOPIC_NAME_TAG, TOPIC_TYPE_NAME_TAG, ROUTES_TAG}; @@ -283,7 +285,7 @@ bool YamlValidator::validate( const Yaml& yml, const YamlReaderVersion& /* version */) { - const std::set tags{ + static const std::set tags{ MONITOR_DOMAIN_TAG, MONITOR_STATUS_TAG, MONITOR_TOPICS_TAG}; @@ -328,7 +330,7 @@ bool YamlValidator::validate( const Yaml& yml, const YamlReaderVersion& /* version */) { - const std::set tags{ + static const std::set tags{ MONITOR_ENABLE_TAG, MONITOR_PERIOD_TAG}; diff --git a/ddspipe_yaml/src/cpp/YamlReader_generic.cpp b/ddspipe_yaml/src/cpp/YamlReader_generic.cpp index d0ea9a29..c667147e 100644 --- a/ddspipe_yaml/src/cpp/YamlReader_generic.cpp +++ b/ddspipe_yaml/src/cpp/YamlReader_generic.cpp @@ -17,6 +17,8 @@ * */ +#include + #include #include #include @@ -297,7 +299,7 @@ bool YamlValidator::validate( const Yaml& yml, const YamlReaderVersion& /* version */) { - const std::set tags{ + static const std::set tags{ TIMESTAMP_DATETIME_FORMAT_TAG, TIMESTAMP_LOCAL_TAG, TIMESTAMP_DATETIME_TAG, diff --git a/ddspipe_yaml/src/cpp/YamlReader_participants.cpp b/ddspipe_yaml/src/cpp/YamlReader_participants.cpp index e7267531..9ef81292 100644 --- a/ddspipe_yaml/src/cpp/YamlReader_participants.cpp +++ b/ddspipe_yaml/src/cpp/YamlReader_participants.cpp @@ -17,6 +17,8 @@ * */ +#include + #include #include @@ -69,7 +71,7 @@ bool YamlValidator::validate( const Yaml& yml, const YamlReaderVersion& /* version */) { - const std::set tags{ + static const std::set tags{ PARTICIPANT_NAME_TAG, PARTICIPANT_KIND_TAG}; @@ -126,7 +128,7 @@ bool YamlValidator::validate( const Yaml& yml, const YamlReaderVersion& /* version */) { - const std::set tags{ + static const std::set tags{ PARTICIPANT_NAME_TAG, PARTICIPANT_KIND_TAG, ECHO_DATA_TAG, @@ -208,7 +210,7 @@ bool YamlValidator::validate( const Yaml& yml, const YamlReaderVersion& /* version */) { - const std::set tags{ + static const std::set tags{ PARTICIPANT_NAME_TAG, PARTICIPANT_KIND_TAG, DOMAIN_ID_TAG, @@ -309,7 +311,7 @@ bool YamlValidator::validate tags{ + static const std::set tags{ PARTICIPANT_NAME_TAG, PARTICIPANT_KIND_TAG, DOMAIN_ID_TAG, @@ -394,7 +396,7 @@ bool YamlValidator::validate const Yaml& yml, const YamlReaderVersion& /* version */) { - const std::set tags{ + static const std::set tags{ PARTICIPANT_NAME_TAG, PARTICIPANT_KIND_TAG, DOMAIN_ID_TAG, @@ -445,7 +447,7 @@ bool YamlValidator::validate( const Yaml& yml, const YamlReaderVersion& /* version */) { - const std::set tags{ + static const std::set tags{ PARTICIPANT_NAME_TAG, PARTICIPANT_KIND_TAG, DOMAIN_ID_TAG, diff --git a/ddspipe_yaml/src/cpp/YamlReader_types.cpp b/ddspipe_yaml/src/cpp/YamlReader_types.cpp index ce71fa68..78f49649 100644 --- a/ddspipe_yaml/src/cpp/YamlReader_types.cpp +++ b/ddspipe_yaml/src/cpp/YamlReader_types.cpp @@ -17,6 +17,8 @@ * */ +#include + #include #include #include @@ -158,7 +160,7 @@ bool YamlValidator::validate( const Yaml& yml, const YamlReaderVersion& /* version */) { - const std::set tags{ + static const std::set tags{ DISCOVERY_SERVER_GUID_TAG, DISCOVERY_SERVER_ID_TAG, DISCOVERY_SERVER_ID_ROS_TAG}; @@ -214,7 +216,7 @@ bool YamlValidator::validate
( const Yaml& yml, const YamlReaderVersion& /* version */) { - const std::set tags{ + static const std::set tags{ ADDRESS_IP_VERSION_TAG, ADDRESS_IP_TAG, ADDRESS_DNS_TAG, @@ -430,7 +432,7 @@ bool YamlValidator::validate( const Yaml& yml, const YamlReaderVersion& /* version */) { - const std::set tags{ + static const std::set tags{ DDS_PUBLISHING_ENABLE_TAG, DDS_PUBLISHING_DOMAIN_TAG, DDS_PUBLISHING_TOPIC_NAME_TAG, @@ -545,7 +547,7 @@ bool YamlValidator::validate( const Yaml& yml, const YamlReaderVersion& /* version */) { - const std::set tags{ + static const std::set tags{ QOS_TRANSIENT_TAG, QOS_RELIABLE_TAG, QOS_OWNERSHIP_TAG, @@ -605,7 +607,7 @@ bool YamlValidator::validate( const Yaml& yml, const YamlReaderVersion& /* version */) { - const std::set tags{ + static const std::set tags{ LOG_FILTER_ERROR_TAG, LOG_FILTER_WARNING_TAG, LOG_FILTER_INFO_TAG}; @@ -669,7 +671,7 @@ bool YamlValidator::validate( const Yaml& yml, const YamlReaderVersion& /* version */) { - const std::set tags{ + static const std::set tags{ LOG_PUBLISH_TAG, LOG_STDOUT_TAG, LOG_VERBOSITY_TAG, @@ -713,7 +715,7 @@ bool YamlValidator::validate( const Yaml& yml, const YamlReaderVersion& /* version */) { - const std::set tags{ + static const std::set tags{ TOPIC_NAME_TAG, TOPIC_TYPE_NAME_TAG}; @@ -762,7 +764,7 @@ bool YamlValidator::validate( const Yaml& yml, const YamlReaderVersion& /* version */) { - const std::set tags{ + static const std::set tags{ TOPIC_NAME_TAG, TOPIC_TYPE_NAME_TAG, TOPIC_QOS_TAG}; @@ -809,7 +811,7 @@ bool YamlValidator::validate( const Yaml& yml, const YamlReaderVersion& /* version */) { - const std::set tags{ + static const std::set tags{ TOPIC_NAME_TAG, TOPIC_TYPE_NAME_TAG, TOPIC_QOS_TAG, @@ -947,7 +949,7 @@ bool YamlValidator::validate( const Yaml& yml, const YamlReaderVersion& /* version */) { - const std::set tags{ + static const std::set tags{ TLS_PRIVATE_KEY_TAG, TLS_PASSWORD_TAG, TLS_CA_TAG, From 89af6ef2d7c5321c1b6ea49fc5fcc0e1a1d2369f Mon Sep 17 00:00:00 2001 From: tempate Date: Wed, 24 Apr 2024 15:16:00 +0200 Subject: [PATCH 06/13] Remove unnecessary includes Signed-off-by: tempate --- ddspipe_participants/src/cpp/xml/XmlHandlerConfiguration.cpp | 2 +- ddspipe_yaml/src/cpp/YamlReader_features.cpp | 1 - ddspipe_yaml/src/cpp/YamlReader_generic.cpp | 1 - ddspipe_yaml/src/cpp/YamlReader_participants.cpp | 1 - 4 files changed, 1 insertion(+), 4 deletions(-) diff --git a/ddspipe_participants/src/cpp/xml/XmlHandlerConfiguration.cpp b/ddspipe_participants/src/cpp/xml/XmlHandlerConfiguration.cpp index a7892574..b2fa1684 100644 --- a/ddspipe_participants/src/cpp/xml/XmlHandlerConfiguration.cpp +++ b/ddspipe_participants/src/cpp/xml/XmlHandlerConfiguration.cpp @@ -30,7 +30,7 @@ bool XmlHandlerConfiguration::is_valid( { if (!utils::is_file_accessible(file.c_str(), utils::FileAccessMode::read)) { - error_msg << "File " << file << " has not exist or does not have read access. "; + error_msg << "File " << file << " does not exist or does not have read access. "; return false; } } diff --git a/ddspipe_yaml/src/cpp/YamlReader_features.cpp b/ddspipe_yaml/src/cpp/YamlReader_features.cpp index 5bc3efb9..bce69861 100644 --- a/ddspipe_yaml/src/cpp/YamlReader_features.cpp +++ b/ddspipe_yaml/src/cpp/YamlReader_features.cpp @@ -14,7 +14,6 @@ #include -#include #include #include diff --git a/ddspipe_yaml/src/cpp/YamlReader_generic.cpp b/ddspipe_yaml/src/cpp/YamlReader_generic.cpp index c667147e..2efe0ff6 100644 --- a/ddspipe_yaml/src/cpp/YamlReader_generic.cpp +++ b/ddspipe_yaml/src/cpp/YamlReader_generic.cpp @@ -19,7 +19,6 @@ #include -#include #include #include diff --git a/ddspipe_yaml/src/cpp/YamlReader_participants.cpp b/ddspipe_yaml/src/cpp/YamlReader_participants.cpp index 9ef81292..d5663aee 100644 --- a/ddspipe_yaml/src/cpp/YamlReader_participants.cpp +++ b/ddspipe_yaml/src/cpp/YamlReader_participants.cpp @@ -19,7 +19,6 @@ #include -#include #include #include From 97add3d6a6b5f1d26e07b68c574ae53a5309d964 Mon Sep 17 00:00:00 2001 From: tempate Date: Thu, 25 Apr 2024 09:37:06 +0200 Subject: [PATCH 07/13] Check if tags are repeated Signed-off-by: tempate --- .../include/ddspipe_yaml/YamlValidator.hpp | 2 +- ddspipe_yaml/src/cpp/YamlValidator.cpp | 21 ++++++++++++++----- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/ddspipe_yaml/include/ddspipe_yaml/YamlValidator.hpp b/ddspipe_yaml/include/ddspipe_yaml/YamlValidator.hpp index f9230726..9e80a26c 100644 --- a/ddspipe_yaml/include/ddspipe_yaml/YamlValidator.hpp +++ b/ddspipe_yaml/include/ddspipe_yaml/YamlValidator.hpp @@ -57,7 +57,7 @@ class YamlValidator DDSPIPE_YAML_DllAPI static bool validate_tags( const Yaml& yml, - const std::set& tags); + const std::set& valid_tags); }; } /* namespace yaml */ diff --git a/ddspipe_yaml/src/cpp/YamlValidator.cpp b/ddspipe_yaml/src/cpp/YamlValidator.cpp index ae237d2f..114e7fe1 100644 --- a/ddspipe_yaml/src/cpp/YamlValidator.cpp +++ b/ddspipe_yaml/src/cpp/YamlValidator.cpp @@ -26,7 +26,7 @@ namespace yaml { bool YamlValidator::validate_tags( const Yaml& yml, - const std::set& tags) + const std::set& valid_tags) { if (!yml.IsMap() && !yml.IsNull()) { @@ -35,20 +35,31 @@ bool YamlValidator::validate_tags( } // Check if there are any extra tags that are not in the list - bool has_extra_tags = false; + std::map tags_count; + bool is_valid = true; for (const auto& tag_it : yml) { const auto& tag = tag_it.first.as(); - if (!tags.count(tag)) + // Check if the tag is valid + if (!valid_tags.count(tag)) { logWarning(DDSPIPE_YAML, "Tag <" << tag << "> is not a valid tag."); - has_extra_tags = true; + is_valid = false; + } + + // Check if the tag is repeated + tags_count[tag]++; + + if (tags_count[tag] > 1) + { + logWarning(DDSPIPE_YAML, "Tag <" << tag << "> is repeated."); + is_valid = false; } } - return !has_extra_tags; + return is_valid; } } /* namespace yaml */ From 3a7eb77752e3134a48738acd363fc9134497c363 Mon Sep 17 00:00:00 2001 From: tempate Date: Thu, 25 Apr 2024 16:28:29 +0200 Subject: [PATCH 08/13] Log the line and column when a tag is faulty Signed-off-by: tempate --- .../include/ddspipe_yaml/YamlValidator.hpp | 13 ++++++ ddspipe_yaml/src/cpp/YamlValidator.cpp | 41 +++++++++++++++---- 2 files changed, 47 insertions(+), 7 deletions(-) diff --git a/ddspipe_yaml/include/ddspipe_yaml/YamlValidator.hpp b/ddspipe_yaml/include/ddspipe_yaml/YamlValidator.hpp index 9e80a26c..c9d906a9 100644 --- a/ddspipe_yaml/include/ddspipe_yaml/YamlValidator.hpp +++ b/ddspipe_yaml/include/ddspipe_yaml/YamlValidator.hpp @@ -58,6 +58,19 @@ class YamlValidator static bool validate_tags( const Yaml& yml, const std::set& valid_tags); + +protected: + + /** + * @brief Get the position of the yaml node in the yaml file + * + * If the position is not available, it will return "unknown position" + * + * @param yml base yaml + * @return "line X, column Y" + */ + static std::string get_position_( + const Yaml& yml); }; } /* namespace yaml */ diff --git a/ddspipe_yaml/src/cpp/YamlValidator.cpp b/ddspipe_yaml/src/cpp/YamlValidator.cpp index 114e7fe1..0d5086af 100644 --- a/ddspipe_yaml/src/cpp/YamlValidator.cpp +++ b/ddspipe_yaml/src/cpp/YamlValidator.cpp @@ -34,27 +34,28 @@ bool YamlValidator::validate_tags( utils::Formatter() << "The yml: <" << yml << "> is not a yaml object map."); } - // Check if there are any extra tags that are not in the list + // Check if there are repeated tags or extra tags that are not in valid_tags std::map tags_count; bool is_valid = true; for (const auto& tag_it : yml) { - const auto& tag = tag_it.first.as(); + const auto& tag = tag_it.first; + const auto& tag_name = tag.as(); // Check if the tag is valid - if (!valid_tags.count(tag)) + if (!valid_tags.count(tag_name)) { - logWarning(DDSPIPE_YAML, "Tag <" << tag << "> is not a valid tag."); + logWarning(DDSPIPE_YAML, "Tag <" << tag_name << "> is not a valid tag (" << get_position_(tag) << ")."); is_valid = false; } // Check if the tag is repeated - tags_count[tag]++; + tags_count[tag_name]++; - if (tags_count[tag] > 1) + if (tags_count[tag_name] > 1) { - logWarning(DDSPIPE_YAML, "Tag <" << tag << "> is repeated."); + logWarning(DDSPIPE_YAML, "Tag <" << tag_name << "> is repeated (" << get_position_(tag) << ")."); is_valid = false; } } @@ -62,6 +63,32 @@ bool YamlValidator::validate_tags( return is_valid; } +std::string YamlValidator::get_position_( + const Yaml& yml) +{ + int line; + int column; + + try + { + const auto& mark = yml.Mark(); + + if (mark.is_null()) + { + return "unknown position"; + } + + line = mark.line + 1; + column = mark.column + 1; + } + catch (const std::exception& e) + { + return "unknown position"; + } + + return "line " + std::to_string(line) + ", column " + std::to_string(column); +} + } /* namespace yaml */ } /* namespace ddspipe */ } /* namespace eprosima */ From d45a6f94514463f81c58e4e67180d97c02a316ea Mon Sep 17 00:00:00 2001 From: tempate Date: Fri, 26 Apr 2024 13:54:22 +0200 Subject: [PATCH 09/13] Fixes after tests Signed-off-by: tempate --- .../include/ddspipe_yaml/YamlReader.hpp | 24 +++- ddspipe_yaml/src/cpp/YamlReader_features.cpp | 118 +++++++++++------- ddspipe_yaml/src/cpp/YamlReader_generic.cpp | 2 - .../src/cpp/YamlReader_participants.cpp | 24 +--- ddspipe_yaml/src/cpp/YamlReader_types.cpp | 12 +- 5 files changed, 107 insertions(+), 73 deletions(-) diff --git a/ddspipe_yaml/include/ddspipe_yaml/YamlReader.hpp b/ddspipe_yaml/include/ddspipe_yaml/YamlReader.hpp index a1c65dec..b7fe47a4 100644 --- a/ddspipe_yaml/include/ddspipe_yaml/YamlReader.hpp +++ b/ddspipe_yaml/include/ddspipe_yaml/YamlReader.hpp @@ -14,6 +14,8 @@ #pragma once +#include + #include #include @@ -167,13 +169,31 @@ class const Yaml& yml, const TagType& tag); - //! TODO comment + /** + * @brief Validate \c yml and build the object \c T + * + * This method calls \c get with the default validation function. + * + * @tparam T type of the object to build + * @param yml base yaml + * @param version configuration version + */ template static T get( const Yaml& yml, const YamlReaderVersion version); - //! Get element inside \c tag + /** + * @brief Extracts the sub-yaml from the \c tag and then builds the object \c T + * + * This method calls \c get_value_in_tag to extract the sub-yaml from the \c tag and then it calls \c get to build + * and validate the object \c T. + * + * @tparam T type of the object to build + * @param yml base yaml + * @param tag key to yaml containing the object + * @param version configuration version + */ template static T get( const Yaml& yml, diff --git a/ddspipe_yaml/src/cpp/YamlReader_features.cpp b/ddspipe_yaml/src/cpp/YamlReader_features.cpp index bce69861..f576f2de 100644 --- a/ddspipe_yaml/src/cpp/YamlReader_features.cpp +++ b/ddspipe_yaml/src/cpp/YamlReader_features.cpp @@ -161,6 +161,8 @@ core::RoutesConfiguration YamlReader::get( const Yaml& yml, const YamlReaderVersion version) { + // NOTE: The validation has to be done inside the fill method since the yml object is a list with the routes + core::RoutesConfiguration object; fill(object, yml, version); return object; @@ -229,6 +231,8 @@ core::TopicRoutesConfiguration YamlReader::get( const Yaml& yml, const YamlReaderVersion version) { + // NOTE: The validation has to be done inside the fill method since the yml object is a list with the topic routes + core::TopicRoutesConfiguration object; fill(object, yml, version); return object; @@ -241,109 +245,129 @@ core::TopicRoutesConfiguration YamlReader::get( template <> DDSPIPE_YAML_DllAPI void YamlReader::fill( - core::MonitorConfiguration& object, + core::MonitorProducerConfiguration& object, const Yaml& yml, const YamlReaderVersion version) { - core::types::DomainIdType domain = 0; - - // Optional domain - if (is_tag_present(yml, MONITOR_DOMAIN_TAG)) - { - domain = get(yml, MONITOR_DOMAIN_TAG, version); - } - - ///// - // Get optional monitor status tag - if (YamlReader::is_tag_present(yml, MONITOR_STATUS_TAG)) + // Optional enable + if (is_tag_present(yml, MONITOR_ENABLE_TAG)) { - object.producers[core::STATUS_MONITOR_PRODUCER_ID] = YamlReader::get(yml, - MONITOR_STATUS_TAG, - version); - object.consumers[core::STATUS_MONITOR_PRODUCER_ID].domain = domain; - YamlReader::fill(object.consumers[core::STATUS_MONITOR_PRODUCER_ID], - get_value_in_tag(yml, MONITOR_STATUS_TAG), version); + object.enabled = get(yml, MONITOR_ENABLE_TAG, version); } - ///// - // Get optional monitor topics tag - if (YamlReader::is_tag_present(yml, MONITOR_TOPICS_TAG)) + // Optional period + if (is_tag_present(yml, MONITOR_PERIOD_TAG)) { - object.producers[core::TOPICS_MONITOR_PRODUCER_ID] = YamlReader::get(yml, - MONITOR_TOPICS_TAG, - version); - object.consumers[core::TOPICS_MONITOR_PRODUCER_ID].domain = domain; - YamlReader::fill(object.consumers[core::TOPICS_MONITOR_PRODUCER_ID], - get_value_in_tag(yml, MONITOR_TOPICS_TAG), version); + object.period = get_positive_double(yml, MONITOR_PERIOD_TAG); } } template <> DDSPIPE_YAML_DllAPI -bool YamlValidator::validate( +bool YamlValidator::validate( const Yaml& yml, const YamlReaderVersion& /* version */) { static const std::set tags{ - MONITOR_DOMAIN_TAG, - MONITOR_STATUS_TAG, - MONITOR_TOPICS_TAG}; + MONITOR_ENABLE_TAG, + MONITOR_PERIOD_TAG}; return YamlValidator::validate_tags(yml, tags); } template <> DDSPIPE_YAML_DllAPI -core::MonitorConfiguration YamlReader::get( +core::MonitorProducerConfiguration YamlReader::get( const Yaml& yml, const YamlReaderVersion version) { - core::MonitorConfiguration object; - fill(object, yml, version); + YamlValidator::validate(yml, version); + + core::MonitorProducerConfiguration object; + fill(object, yml, version); return object; } template <> DDSPIPE_YAML_DllAPI void YamlReader::fill( - core::MonitorProducerConfiguration& object, + core::MonitorConfiguration& object, const Yaml& yml, const YamlReaderVersion version) { - // Optional enable - if (is_tag_present(yml, MONITOR_ENABLE_TAG)) + core::types::DomainIdType domain = 0; + + // Optional domain + if (is_tag_present(yml, MONITOR_DOMAIN_TAG)) { - object.enabled = get(yml, MONITOR_ENABLE_TAG, version); + domain = get(yml, MONITOR_DOMAIN_TAG, version); } - // Optional period - if (is_tag_present(yml, MONITOR_PERIOD_TAG)) + static const std::set tags{ + MONITOR_ENABLE_TAG, + MONITOR_PERIOD_TAG, + DDS_PUBLISHING_ENABLE_TAG, + DDS_PUBLISHING_DOMAIN_TAG, + DDS_PUBLISHING_TOPIC_NAME_TAG, + DDS_PUBLISHING_PUBLISH_TYPE_TAG}; + + ///// + // Get optional monitor status tag + if (is_tag_present(yml, MONITOR_STATUS_TAG)) { - object.period = get_positive_double(yml, MONITOR_PERIOD_TAG); + YamlValidator::validate_tags(yml[MONITOR_STATUS_TAG], tags); + + // NOTE: Use fill instead of get to avoid throwing exceptions if tags are not present + fill(object.producers[core::STATUS_MONITOR_PRODUCER_ID], + get_value_in_tag(yml, MONITOR_STATUS_TAG), version); + + // NOTE: Set the generic domain first so it can be overwritten by the specific domain if present + object.consumers[core::STATUS_MONITOR_PRODUCER_ID].domain = domain; + fill(object.consumers[core::STATUS_MONITOR_PRODUCER_ID], + get_value_in_tag(yml, MONITOR_STATUS_TAG), version); + } + + ///// + // Get optional monitor topics tag + if (is_tag_present(yml, MONITOR_TOPICS_TAG)) + { + YamlValidator::validate_tags(yml[MONITOR_TOPICS_TAG], tags); + + // NOTE: Use fill instead of get to avoid throwing exceptions if tags are not present + fill(object.producers[core::TOPICS_MONITOR_PRODUCER_ID], + get_value_in_tag(yml, MONITOR_TOPICS_TAG), version); + + // NOTE: Set the generic domain first so it can be overwritten by the specific domain if present + object.consumers[core::TOPICS_MONITOR_PRODUCER_ID].domain = domain; + fill(object.consumers[core::TOPICS_MONITOR_PRODUCER_ID], + get_value_in_tag(yml, MONITOR_TOPICS_TAG), version); } } template <> DDSPIPE_YAML_DllAPI -bool YamlValidator::validate( +bool YamlValidator::validate( const Yaml& yml, const YamlReaderVersion& /* version */) { static const std::set tags{ - MONITOR_ENABLE_TAG, - MONITOR_PERIOD_TAG}; + MONITOR_DOMAIN_TAG, + MONITOR_STATUS_TAG, + MONITOR_TOPICS_TAG}; return YamlValidator::validate_tags(yml, tags); } template <> DDSPIPE_YAML_DllAPI -core::MonitorProducerConfiguration YamlReader::get( +core::MonitorConfiguration YamlReader::get( const Yaml& yml, const YamlReaderVersion version) { - core::MonitorProducerConfiguration object; - fill(object, yml, version); + YamlValidator::validate(yml, version); + + core::MonitorConfiguration object; + fill(object, yml, version); return object; } diff --git a/ddspipe_yaml/src/cpp/YamlReader_generic.cpp b/ddspipe_yaml/src/cpp/YamlReader_generic.cpp index 2efe0ff6..b8c7c410 100644 --- a/ddspipe_yaml/src/cpp/YamlReader_generic.cpp +++ b/ddspipe_yaml/src/cpp/YamlReader_generic.cpp @@ -25,8 +25,6 @@ #include #include #include -#include -#include #include #include diff --git a/ddspipe_yaml/src/cpp/YamlReader_participants.cpp b/ddspipe_yaml/src/cpp/YamlReader_participants.cpp index d5663aee..95fbdd82 100644 --- a/ddspipe_yaml/src/cpp/YamlReader_participants.cpp +++ b/ddspipe_yaml/src/cpp/YamlReader_participants.cpp @@ -212,11 +212,11 @@ bool YamlValidator::validate( static const std::set tags{ PARTICIPANT_NAME_TAG, PARTICIPANT_KIND_TAG, + PARTICIPANT_QOS_TAG, DOMAIN_ID_TAG, WHITELIST_INTERFACES_TAG, TRANSPORT_DESCRIPTORS_TRANSPORT_TAG, - IGNORE_PARTICIPANT_FLAGS_TAG, - PARTICIPANT_QOS_TAG}; + IGNORE_PARTICIPANT_FLAGS_TAG}; return YamlValidator::validate_tags(yml, tags); } @@ -271,10 +271,7 @@ void YamlReader::fill( // Optional TLS if (YamlReader::is_tag_present(yml, TLS_TAG)) { - YamlReader::fill( - object.tls_configuration, - YamlReader::get_value_in_tag(yml, TLS_TAG), - version); + object.tls_configuration = YamlReader::get(yml, TLS_TAG, version); } // NOTE: The only field that change regarding the version is the GuidPrefix. @@ -313,11 +310,10 @@ bool YamlValidator::validate tags{ PARTICIPANT_NAME_TAG, PARTICIPANT_KIND_TAG, - DOMAIN_ID_TAG, + PARTICIPANT_QOS_TAG, WHITELIST_INTERFACES_TAG, TRANSPORT_DESCRIPTORS_TRANSPORT_TAG, IGNORE_PARTICIPANT_FLAGS_TAG, - PARTICIPANT_QOS_TAG, LISTENING_ADDRESSES_TAG, CONNECTION_ADDRESSES_TAG, TLS_TAG, @@ -376,10 +372,7 @@ void YamlReader::fill( // Optional TLS if (YamlReader::is_tag_present(yml, TLS_TAG)) { - YamlReader::fill( - object.tls_configuration, - YamlReader::get_value_in_tag(yml, TLS_TAG), - version); + object.tls_configuration = YamlReader::get(yml, TLS_TAG, version); } // Optional Repeater @@ -398,11 +391,10 @@ bool YamlValidator::validate static const std::set tags{ PARTICIPANT_NAME_TAG, PARTICIPANT_KIND_TAG, - DOMAIN_ID_TAG, + PARTICIPANT_QOS_TAG, WHITELIST_INTERFACES_TAG, TRANSPORT_DESCRIPTORS_TRANSPORT_TAG, IGNORE_PARTICIPANT_FLAGS_TAG, - PARTICIPANT_QOS_TAG, LISTENING_ADDRESSES_TAG, CONNECTION_ADDRESSES_TAG, TLS_TAG, @@ -449,10 +441,6 @@ bool YamlValidator::validate( static const std::set tags{ PARTICIPANT_NAME_TAG, PARTICIPANT_KIND_TAG, - DOMAIN_ID_TAG, - WHITELIST_INTERFACES_TAG, - TRANSPORT_DESCRIPTORS_TRANSPORT_TAG, - IGNORE_PARTICIPANT_FLAGS_TAG, PARTICIPANT_QOS_TAG, XML_PARTICIPANT_PROFILE_TAG}; diff --git a/ddspipe_yaml/src/cpp/YamlReader_types.cpp b/ddspipe_yaml/src/cpp/YamlReader_types.cpp index 78f49649..8708b8c3 100644 --- a/ddspipe_yaml/src/cpp/YamlReader_types.cpp +++ b/ddspipe_yaml/src/cpp/YamlReader_types.cpp @@ -265,7 +265,7 @@ Address YamlReader::get
( // If neither set, get default if (ip_set && domain_name_set) { - EPROSIMA_LOG_WARNING(ddspipe_YAML, + EPROSIMA_LOG_WARNING(DDSPIPE_YAML, "Tag <" << ADDRESS_DNS_TAG << "> will not be used as <" << ADDRESS_IP_TAG << "> is set."); domain_name_set = false; } @@ -580,7 +580,7 @@ TopicQoS YamlReader::get( template <> DDSPIPE_YAML_DllAPI -void YamlReader::fill( +void YamlReader::fill( utils::LogFilter& object, const Yaml& yml, const YamlReaderVersion version) @@ -621,6 +621,8 @@ utils::LogFilter YamlReader::get( const Yaml& yml, const YamlReaderVersion version) { + YamlValidator::validate(yml, version); + utils::LogFilter object; fill(object, yml, version); return object; @@ -661,7 +663,7 @@ void YamlReader::fill( // Filter optional if (is_tag_present(yml, LOG_FILTER_TAG)) { - fill(object.filter, get_value_in_tag(yml, LOG_FILTER_TAG), version); + object.filter = get(yml, LOG_FILTER_TAG, version); } } @@ -686,6 +688,8 @@ core::DdsPipeLogConfiguration YamlReader::get( const Yaml& yml, const YamlReaderVersion version) { + YamlValidator::validate(yml, version); + core::DdsPipeLogConfiguration object; fill(object, yml, version); return object; @@ -794,7 +798,7 @@ void YamlReader::fill( { // Avoid calling YamlReader::get to avoid validation at a lower level WildcardDdsFilterTopic manual_topic; - YamlReader::fill(manual_topic, yml, version); + fill(manual_topic, yml, version); object.first = utils::Heritable::make_heritable(manual_topic); From 5086a116c21dfd6b08eb85a020f39d2bef9440b6 Mon Sep 17 00:00:00 2001 From: tempate Date: Thu, 18 Jul 2024 14:49:28 +0200 Subject: [PATCH 10/13] Apply suggestions Signed-off-by: tempate --- ddspipe_yaml/include/ddspipe_yaml/YamlReader.hpp | 2 +- ddspipe_yaml/include/ddspipe_yaml/YamlValidator.hpp | 2 +- ddspipe_yaml/src/cpp/YamlReader_generic.cpp | 4 +++- ddspipe_yaml/src/cpp/YamlReader_participants.cpp | 4 +++- ddspipe_yaml/src/cpp/YamlValidator.cpp | 2 +- 5 files changed, 9 insertions(+), 5 deletions(-) diff --git a/ddspipe_yaml/include/ddspipe_yaml/YamlReader.hpp b/ddspipe_yaml/include/ddspipe_yaml/YamlReader.hpp index b7fe47a4..8f7289c8 100644 --- a/ddspipe_yaml/include/ddspipe_yaml/YamlReader.hpp +++ b/ddspipe_yaml/include/ddspipe_yaml/YamlReader.hpp @@ -16,8 +16,8 @@ #include -#include #include +#include #include #include diff --git a/ddspipe_yaml/include/ddspipe_yaml/YamlValidator.hpp b/ddspipe_yaml/include/ddspipe_yaml/YamlValidator.hpp index c9d906a9..eb04080f 100644 --- a/ddspipe_yaml/include/ddspipe_yaml/YamlValidator.hpp +++ b/ddspipe_yaml/include/ddspipe_yaml/YamlValidator.hpp @@ -49,7 +49,7 @@ class YamlValidator const YamlReaderVersion& version = YamlReaderVersion::LATEST); /** - * @brief Ensure that all the tags in \c yml are in \c tags. + * @brief Ensure that all the tags in \c yml are unique and inside \c tags. * * @param yml Yaml object to validate. * @param tags Set of tags to validate against. diff --git a/ddspipe_yaml/src/cpp/YamlReader_generic.cpp b/ddspipe_yaml/src/cpp/YamlReader_generic.cpp index b8c7c410..c6b0ed2a 100644 --- a/ddspipe_yaml/src/cpp/YamlReader_generic.cpp +++ b/ddspipe_yaml/src/cpp/YamlReader_generic.cpp @@ -14,7 +14,6 @@ /** * @file YamlReader.cpp - * */ #include @@ -34,6 +33,9 @@ #include #include #include +#include +#include +#include #include #include diff --git a/ddspipe_yaml/src/cpp/YamlReader_participants.cpp b/ddspipe_yaml/src/cpp/YamlReader_participants.cpp index 95fbdd82..fa1f1b1d 100644 --- a/ddspipe_yaml/src/cpp/YamlReader_participants.cpp +++ b/ddspipe_yaml/src/cpp/YamlReader_participants.cpp @@ -14,7 +14,6 @@ /** * @file YamlReader.cpp - * */ #include @@ -34,6 +33,9 @@ #include #include #include +#include +#include +#include #include #include diff --git a/ddspipe_yaml/src/cpp/YamlValidator.cpp b/ddspipe_yaml/src/cpp/YamlValidator.cpp index 0d5086af..bf20a42d 100644 --- a/ddspipe_yaml/src/cpp/YamlValidator.cpp +++ b/ddspipe_yaml/src/cpp/YamlValidator.cpp @@ -14,10 +14,10 @@ /** * @file YamlValidator.cpp - * */ #include + #include namespace eprosima { From 101604bcadbe8c2b2a16836d0fcc7c3a98c8742c Mon Sep 17 00:00:00 2001 From: Lucia Echevarria Date: Thu, 19 Sep 2024 11:05:44 +0200 Subject: [PATCH 11/13] Fix changes after rebase Signed-off-by: Lucia Echevarria --- ddspipe_yaml/src/cpp/YamlReader_features.cpp | 5 +- ddspipe_yaml/src/cpp/YamlReader_generic.cpp | 6 +- .../src/cpp/YamlReader_participants.cpp | 8 +-- ddspipe_yaml/src/cpp/YamlReader_types.cpp | 66 +------------------ ddspipe_yaml/src/cpp/YamlValidator.cpp | 4 +- 5 files changed, 8 insertions(+), 81 deletions(-) diff --git a/ddspipe_yaml/src/cpp/YamlReader_features.cpp b/ddspipe_yaml/src/cpp/YamlReader_features.cpp index f576f2de..cd9c4bb6 100644 --- a/ddspipe_yaml/src/cpp/YamlReader_features.cpp +++ b/ddspipe_yaml/src/cpp/YamlReader_features.cpp @@ -238,7 +238,7 @@ core::TopicRoutesConfiguration YamlReader::get( return object; } -/************************** +/************************* * Monitor Configuration * **************************/ @@ -308,8 +308,7 @@ void YamlReader::fill( MONITOR_PERIOD_TAG, DDS_PUBLISHING_ENABLE_TAG, DDS_PUBLISHING_DOMAIN_TAG, - DDS_PUBLISHING_TOPIC_NAME_TAG, - DDS_PUBLISHING_PUBLISH_TYPE_TAG}; + DDS_PUBLISHING_TOPIC_NAME_TAG}; ///// // Get optional monitor status tag diff --git a/ddspipe_yaml/src/cpp/YamlReader_generic.cpp b/ddspipe_yaml/src/cpp/YamlReader_generic.cpp index c6b0ed2a..c7d53e21 100644 --- a/ddspipe_yaml/src/cpp/YamlReader_generic.cpp +++ b/ddspipe_yaml/src/cpp/YamlReader_generic.cpp @@ -25,16 +25,12 @@ #include #include -#include -#include - #include +#include #include #include -#include #include #include -#include #include #include diff --git a/ddspipe_yaml/src/cpp/YamlReader_participants.cpp b/ddspipe_yaml/src/cpp/YamlReader_participants.cpp index fa1f1b1d..1e843ad2 100644 --- a/ddspipe_yaml/src/cpp/YamlReader_participants.cpp +++ b/ddspipe_yaml/src/cpp/YamlReader_participants.cpp @@ -24,17 +24,13 @@ #include #include -#include -#include - #include +#include #include -#include #include -#include #include +#include #include -#include #include #include diff --git a/ddspipe_yaml/src/cpp/YamlReader_types.cpp b/ddspipe_yaml/src/cpp/YamlReader_types.cpp index 8708b8c3..c5f835cd 100644 --- a/ddspipe_yaml/src/cpp/YamlReader_types.cpp +++ b/ddspipe_yaml/src/cpp/YamlReader_types.cpp @@ -340,69 +340,6 @@ Address YamlReader::get
( } } -DiscoveryServerConnectionAddress _get_discovery_server_connection_address_v1( - const Yaml& yml, - const YamlReaderVersion version) -{ - // GuidPrefix required - GuidPrefix server_guid = YamlReader::get(yml, version); - - // Addresses required - std::set
addresses = YamlReader::get_set
(yml, COLLECTION_ADDRESSES_TAG, version); - - // Create Connection Address - return DiscoveryServerConnectionAddress(server_guid, addresses); -} - -DiscoveryServerConnectionAddress _get_discovery_server_connection_address_latest( - const Yaml& yml, - const YamlReaderVersion version) -{ - // GuidPrefix required - GuidPrefix server_guid = YamlReader::get(yml, DISCOVERY_SERVER_GUID_PREFIX_TAG, version); - - // Addresses required - std::set
addresses = YamlReader::get_set
(yml, COLLECTION_ADDRESSES_TAG, version); - - // Create Connection Address - return DiscoveryServerConnectionAddress(server_guid, addresses); -} - -template <> -DDSPIPE_YAML_DllAPI -bool YamlValidator::validate( - const Yaml& yml, - const YamlReaderVersion& version) -{ - std::set tags{ - COLLECTION_ADDRESSES_TAG}; - - if (version != V_1_0) - { - tags.insert(DISCOVERY_SERVER_GUID_PREFIX_TAG); - } - - return YamlValidator::validate_tags(yml, tags); -} - -template <> -DDSPIPE_YAML_DllAPI -DiscoveryServerConnectionAddress YamlReader::get( - const Yaml& yml, - const YamlReaderVersion version) -{ - YamlValidator::validate(yml, version); - - switch (version) - { - case V_1_0: - return _get_discovery_server_connection_address_v1(yml, version); - - default: - return _get_discovery_server_connection_address_latest(yml, version); - } -} - template <> DDSPIPE_YAML_DllAPI void YamlReader::fill( @@ -435,8 +372,7 @@ bool YamlValidator::validate( static const std::set tags{ DDS_PUBLISHING_ENABLE_TAG, DDS_PUBLISHING_DOMAIN_TAG, - DDS_PUBLISHING_TOPIC_NAME_TAG, - DDS_PUBLISHING_PUBLISH_TYPE_TAG}; + DDS_PUBLISHING_TOPIC_NAME_TAG}; return YamlValidator::validate_tags(yml, tags); } diff --git a/ddspipe_yaml/src/cpp/YamlValidator.cpp b/ddspipe_yaml/src/cpp/YamlValidator.cpp index bf20a42d..a307fbdb 100644 --- a/ddspipe_yaml/src/cpp/YamlValidator.cpp +++ b/ddspipe_yaml/src/cpp/YamlValidator.cpp @@ -46,7 +46,7 @@ bool YamlValidator::validate_tags( // Check if the tag is valid if (!valid_tags.count(tag_name)) { - logWarning(DDSPIPE_YAML, "Tag <" << tag_name << "> is not a valid tag (" << get_position_(tag) << ")."); + EPROSIMA_LOG_WARNING(DDSPIPE_YAML, "Tag <" << tag_name << "> is not a valid tag (" << get_position_(tag) << ")."); is_valid = false; } @@ -55,7 +55,7 @@ bool YamlValidator::validate_tags( if (tags_count[tag_name] > 1) { - logWarning(DDSPIPE_YAML, "Tag <" << tag_name << "> is repeated (" << get_position_(tag) << ")."); + EPROSIMA_LOG_WARNING(DDSPIPE_YAML, "Tag <" << tag_name << "> is repeated (" << get_position_(tag) << ")."); is_valid = false; } } From ebbccf3af8a35719058932699ae92815495ab7e9 Mon Sep 17 00:00:00 2001 From: Lucia Echevarria Date: Tue, 24 Sep 2024 12:06:41 +0200 Subject: [PATCH 12/13] Adapt code to new LogFilter struct Signed-off-by: Lucia Echevarria --- .../ddspipe_core/configuration/CommandlineArgs.hpp | 1 + .../src/cpp/configuration/CommandlineArgs.cpp | 6 +++--- .../logging/dds_consumer/DdsLogConsumerTest.cpp | 12 ++++++------ .../logging/std_consumer/StdLogConsumerTest.cpp | 12 ++++++------ .../status/logging/LogMonitorStatusTest.cpp | 2 +- .../topics/logging/LogMonitorTopicsTest.cpp | 2 +- .../log_configuration/YamlReaderLogConfiguration.cpp | 12 ++++++------ 7 files changed, 24 insertions(+), 23 deletions(-) diff --git a/ddspipe_core/include/ddspipe_core/configuration/CommandlineArgs.hpp b/ddspipe_core/include/ddspipe_core/configuration/CommandlineArgs.hpp index 721e6c3b..f9e12bfd 100644 --- a/ddspipe_core/include/ddspipe_core/configuration/CommandlineArgs.hpp +++ b/ddspipe_core/include/ddspipe_core/configuration/CommandlineArgs.hpp @@ -15,6 +15,7 @@ #pragma once #include +#include #include #include #include diff --git a/ddspipe_core/src/cpp/configuration/CommandlineArgs.cpp b/ddspipe_core/src/cpp/configuration/CommandlineArgs.cpp index c936f38f..2f9bb186 100644 --- a/ddspipe_core/src/cpp/configuration/CommandlineArgs.cpp +++ b/ddspipe_core/src/cpp/configuration/CommandlineArgs.cpp @@ -28,9 +28,9 @@ namespace core { CommandlineArgs::CommandlineArgs() { - log_filter[utils::VerbosityKind::Info].set_value("DDSPIPE", utils::FuzzyLevelValues::fuzzy_level_default); - log_filter[utils::VerbosityKind::Warning].set_value("DDSPIPE", utils::FuzzyLevelValues::fuzzy_level_default); - log_filter[utils::VerbosityKind::Error].set_value("", utils::FuzzyLevelValues::fuzzy_level_default); + log_filter.info.set_value("DDSPIPE", utils::FuzzyLevelValues::fuzzy_level_default); + log_filter.warning.set_value("DDSPIPE", utils::FuzzyLevelValues::fuzzy_level_default); + log_filter.error.set_value("", utils::FuzzyLevelValues::fuzzy_level_default); } bool CommandlineArgs::is_valid( diff --git a/ddspipe_core/test/unittest/logging/dds_consumer/DdsLogConsumerTest.cpp b/ddspipe_core/test/unittest/logging/dds_consumer/DdsLogConsumerTest.cpp index 86c794a4..58bd506e 100644 --- a/ddspipe_core/test/unittest/logging/dds_consumer/DdsLogConsumerTest.cpp +++ b/ddspipe_core/test/unittest/logging/dds_consumer/DdsLogConsumerTest.cpp @@ -111,9 +111,9 @@ TEST_F(DdsLogConsumerTest, publish_logs) // Filter out every log except ours log_configuration.verbosity = utils::VerbosityKind::Info; - log_configuration.filter[utils::VerbosityKind::Info].set_value("DDSPIPE_TEST"); - log_configuration.filter[utils::VerbosityKind::Warning].set_value("DDSPIPE_TEST"); - log_configuration.filter[utils::VerbosityKind::Error].set_value("DDSPIPE_TEST"); + log_configuration.filter.info.set_value("DDSPIPE_TEST"); + log_configuration.filter.warning.set_value("DDSPIPE_TEST"); + log_configuration.filter.error.set_value("DDSPIPE_TEST"); utils::Log::ClearConsumers(); utils::Log::SetVerbosity(log_configuration.verbosity); @@ -205,9 +205,9 @@ TEST_F(DdsLogConsumerTest, dont_publish_logs) // Filter out every log except ours log_configuration.verbosity = utils::VerbosityKind::Info; - log_configuration.filter[utils::VerbosityKind::Info].set_value("DDSPIPE_TEST"); - log_configuration.filter[utils::VerbosityKind::Warning].set_value("DDSPIPE_TEST"); - log_configuration.filter[utils::VerbosityKind::Error].set_value("DDSPIPE_TEST"); + log_configuration.filter.info.set_value("DDSPIPE_TEST"); + log_configuration.filter.warning.set_value("DDSPIPE_TEST"); + log_configuration.filter.error.set_value("DDSPIPE_TEST"); utils::Log::ClearConsumers(); utils::Log::SetVerbosity(log_configuration.verbosity); diff --git a/ddspipe_core/test/unittest/logging/std_consumer/StdLogConsumerTest.cpp b/ddspipe_core/test/unittest/logging/std_consumer/StdLogConsumerTest.cpp index 2f37df93..900cce0f 100644 --- a/ddspipe_core/test/unittest/logging/std_consumer/StdLogConsumerTest.cpp +++ b/ddspipe_core/test/unittest/logging/std_consumer/StdLogConsumerTest.cpp @@ -42,9 +42,9 @@ TEST(StdLogConsumerTest, print_logs) // Filter out every log except ours log_configuration.verbosity = utils::VerbosityKind::Info; - log_configuration.filter[utils::VerbosityKind::Info].set_value("DDSPIPE_TEST"); - log_configuration.filter[utils::VerbosityKind::Warning].set_value("DDSPIPE_TEST"); - log_configuration.filter[utils::VerbosityKind::Error].set_value("DDSPIPE_TEST"); + log_configuration.filter.info.set_value("DDSPIPE_TEST"); + log_configuration.filter.warning.set_value("DDSPIPE_TEST"); + log_configuration.filter.error.set_value("DDSPIPE_TEST"); utils::Log::ClearConsumers(); utils::Log::SetVerbosity(log_configuration.verbosity); @@ -102,9 +102,9 @@ TEST(StdLogConsumerTest, dont_print_logs) // Filter out every log except ours log_configuration.verbosity = utils::VerbosityKind::Info; - log_configuration.filter[utils::VerbosityKind::Info].set_value("DDSPIPE_TEST"); - log_configuration.filter[utils::VerbosityKind::Warning].set_value("DDSPIPE_TEST"); - log_configuration.filter[utils::VerbosityKind::Error].set_value("DDSPIPE_TEST"); + log_configuration.filter.info.set_value("DDSPIPE_TEST"); + log_configuration.filter.warning.set_value("DDSPIPE_TEST"); + log_configuration.filter.error.set_value("DDSPIPE_TEST"); utils::Log::ClearConsumers(); utils::Log::SetVerbosity(log_configuration.verbosity); diff --git a/ddspipe_core/test/unittest/monitoring/status/logging/LogMonitorStatusTest.cpp b/ddspipe_core/test/unittest/monitoring/status/logging/LogMonitorStatusTest.cpp index 2cf9df6b..01688dc9 100644 --- a/ddspipe_core/test/unittest/monitoring/status/logging/LogMonitorStatusTest.cpp +++ b/ddspipe_core/test/unittest/monitoring/status/logging/LogMonitorStatusTest.cpp @@ -43,7 +43,7 @@ class LogMonitorStatusTest : public testing::Test utils::BaseLogConfiguration log_conf; log_conf.verbosity = utils::VerbosityKind::Info; - log_conf.filter[utils::VerbosityKind::Info].set_value("MONITOR_DATA"); + log_conf.filter.info.set_value("MONITOR_DATA"); utils::Log::SetVerbosity(log_conf.verbosity); diff --git a/ddspipe_core/test/unittest/monitoring/topics/logging/LogMonitorTopicsTest.cpp b/ddspipe_core/test/unittest/monitoring/topics/logging/LogMonitorTopicsTest.cpp index e05d8d7e..c94a88d1 100644 --- a/ddspipe_core/test/unittest/monitoring/topics/logging/LogMonitorTopicsTest.cpp +++ b/ddspipe_core/test/unittest/monitoring/topics/logging/LogMonitorTopicsTest.cpp @@ -45,7 +45,7 @@ class LogMonitorTopicsTest : public testing::Test utils::BaseLogConfiguration log_conf; log_conf.verbosity = utils::VerbosityKind::Info; - log_conf.filter[utils::VerbosityKind::Info].set_value("MONITOR_DATA"); + log_conf.filter.info.set_value("MONITOR_DATA"); utils::Log::SetVerbosity(log_conf.verbosity); diff --git a/ddspipe_yaml/test/unittest/yaml_reader/log_configuration/YamlReaderLogConfiguration.cpp b/ddspipe_yaml/test/unittest/yaml_reader/log_configuration/YamlReaderLogConfiguration.cpp index ce172c5f..7932fef6 100644 --- a/ddspipe_yaml/test/unittest/yaml_reader/log_configuration/YamlReaderLogConfiguration.cpp +++ b/ddspipe_yaml/test/unittest/yaml_reader/log_configuration/YamlReaderLogConfiguration.cpp @@ -62,9 +62,9 @@ TEST(YamlReaderLogConfiguration, parse_correct_LogConfiguration_yaml) // Verify that the verbosity and filters are correct ASSERT_EQ(conf.verbosity.get_value(), utils::VerbosityKind::Info); - ASSERT_EQ(conf.filter.at(utils::VerbosityKind::Error).get_value(), "DDSPIPE"); - ASSERT_EQ(conf.filter.at(utils::VerbosityKind::Warning).get_value(), ""); - ASSERT_EQ(conf.filter.at(utils::VerbosityKind::Info).get_value(), "DEBUG"); + ASSERT_EQ(conf.filter.error.get_value(), "DDSPIPE"); + ASSERT_EQ(conf.filter.warning.get_value(), ""); + ASSERT_EQ(conf.filter.info.get_value(), "DEBUG"); } /** @@ -93,9 +93,9 @@ TEST(YamlReaderLogConfiguration, parse_correct_LogConfiguration_yaml_and_default ASSERT_TRUE(conf.is_valid(error_msg)); ASSERT_EQ(conf.verbosity.get_value(), utils::VerbosityKind::Warning); - ASSERT_EQ(conf.filter.at(utils::VerbosityKind::Error).get_value(), ""); - ASSERT_EQ(conf.filter.at(utils::VerbosityKind::Warning).get_value(), ""); - ASSERT_EQ(conf.filter.at(utils::VerbosityKind::Info).get_value(), "DEBUG"); + ASSERT_EQ(conf.filter.error.get_value(), ""); + ASSERT_EQ(conf.filter.warning.get_value(), ""); + ASSERT_EQ(conf.filter.info.get_value(), "DEBUG"); } /** From 2ad717f2f756d93fdc70339f68a9aae588c2e6b9 Mon Sep 17 00:00:00 2001 From: Lucia Echevarria Date: Tue, 24 Sep 2024 12:08:34 +0200 Subject: [PATCH 13/13] Apply suggested changes Signed-off-by: Lucia Echevarria --- ddspipe_yaml/src/cpp/YamlReader_features.cpp | 51 ++++++++++++--- ddspipe_yaml/src/cpp/YamlReader_generic.cpp | 64 ++++++++++--------- .../src/cpp/YamlReader_participants.cpp | 2 +- ddspipe_yaml/src/cpp/YamlReader_types.cpp | 6 +- 4 files changed, 80 insertions(+), 43 deletions(-) diff --git a/ddspipe_yaml/src/cpp/YamlReader_features.cpp b/ddspipe_yaml/src/cpp/YamlReader_features.cpp index cd9c4bb6..7447c6d9 100644 --- a/ddspipe_yaml/src/cpp/YamlReader_features.cpp +++ b/ddspipe_yaml/src/cpp/YamlReader_features.cpp @@ -130,13 +130,22 @@ void YamlReader::fill( std::set dst; // Required route source - src = get(route_yml, ROUTES_SRC_TAG, version); - - if (object.routes.count(src) != 0) + if (is_tag_present(route_yml, ROUTES_SRC_TAG)) + { + src = get(route_yml, ROUTES_SRC_TAG, version); + + if (object.routes.count(src) != 0) + { + throw eprosima::utils::ConfigurationException( + utils::Formatter() << + "Multiple routes defined for participant " << src << " : only one allowed."); + } + } + else { throw eprosima::utils::ConfigurationException( utils::Formatter() << - "Multiple routes defined for participant " << src << " : only one allowed."); + "Source participant required under tag " << ROUTES_SRC_TAG << " in route definition."); } // Optional route destination(s) @@ -206,22 +215,44 @@ void YamlReader::fill( { YamlValidator::validate(topic_routes_yml, version); - // utils::Heritable topic; auto topic = utils::Heritable::make_heritable(); core::RoutesConfiguration routes; // Required topic and type names - fill(topic.get_reference(), topic_routes_yml, version); + if (!(is_tag_present(topic_routes_yml, + TOPIC_NAME_TAG) && is_tag_present(topic_routes_yml, TOPIC_TYPE_NAME_TAG))) + { + throw eprosima::utils::ConfigurationException( + utils::Formatter() << + "Topic routes require topic and type names to be defined under tags " << TOPIC_NAME_TAG << + " and " << TOPIC_TYPE_NAME_TAG << ", respectively."); + } + else + { + topic = get>(topic_routes_yml, version); + + if (object.topic_routes.count(topic) != 0) + { + throw eprosima::utils::ConfigurationException( + utils::Formatter() << + "Multiple routes defined for topic " << topic << " : only one allowed."); + } + } - if (object.topic_routes.count(topic) != 0) + // Required routes + if (is_tag_present(topic_routes_yml, ROUTES_TAG)) + { + routes = get(topic_routes_yml, ROUTES_TAG, version); + } + else { throw eprosima::utils::ConfigurationException( utils::Formatter() << - "Multiple routes defined for topic " << topic << " : only one allowed."); + "No routes found under tag " << ROUTES_TAG << " for topic " << topic << " ."); } - // Required route - object.topic_routes[topic] = get(topic_routes_yml, ROUTES_TAG, version); + // Insert routes + object.topic_routes[topic] = routes; } } diff --git a/ddspipe_yaml/src/cpp/YamlReader_generic.cpp b/ddspipe_yaml/src/cpp/YamlReader_generic.cpp index c7d53e21..500140d2 100644 --- a/ddspipe_yaml/src/cpp/YamlReader_generic.cpp +++ b/ddspipe_yaml/src/cpp/YamlReader_generic.cpp @@ -25,11 +25,6 @@ #include #include -#include -#include -#include -#include -#include #include #include @@ -290,30 +285,11 @@ std::string YamlReader::get( template <> DDSPIPE_YAML_DllAPI -bool YamlValidator::validate( - const Yaml& yml, - const YamlReaderVersion& /* version */) -{ - static const std::set tags{ - TIMESTAMP_DATETIME_FORMAT_TAG, - TIMESTAMP_LOCAL_TAG, - TIMESTAMP_DATETIME_TAG, - TIMESTAMP_MILLISECONDS_TAG, - TIMESTAMP_MICROSECONDS_TAG, - TIMESTAMP_NANOSECONDS_TAG}; - - return YamlValidator::validate_tags(yml, tags); -} - -template <> -DDSPIPE_YAML_DllAPI -utils::Timestamp YamlReader::get( +void YamlReader::fill( + utils::Timestamp& object, const Yaml& yml, - const YamlReaderVersion version /* version */) + const YamlReaderVersion version) { - YamlValidator::validate(yml, version); - - utils::Timestamp ret_timestamp; std::string datetime_str; std::string datetime_format("%Y-%m-%d_%H-%M-%S"); bool local = true; @@ -339,7 +315,7 @@ utils::Timestamp YamlReader::get( datetime_str = get(yml, TIMESTAMP_DATETIME_TAG, version); try { - ret_timestamp = utils::string_to_timestamp(datetime_str, datetime_format, local); + object = utils::string_to_timestamp(datetime_str, datetime_format, local); } catch (const std::exception& e) { @@ -372,7 +348,37 @@ utils::Timestamp YamlReader::get( ns = std::chrono::nanoseconds(get_nonnegative_int(yml, TIMESTAMP_NANOSECONDS_TAG)); } - return std::chrono::time_point_cast(ret_timestamp + ms + us + ns); + object = std::chrono::time_point_cast(object + ms + us + ns); +} + +template <> +DDSPIPE_YAML_DllAPI +bool YamlValidator::validate( + const Yaml& yml, + const YamlReaderVersion& /* version */) +{ + static const std::set tags{ + TIMESTAMP_DATETIME_FORMAT_TAG, + TIMESTAMP_LOCAL_TAG, + TIMESTAMP_DATETIME_TAG, + TIMESTAMP_MILLISECONDS_TAG, + TIMESTAMP_MICROSECONDS_TAG, + TIMESTAMP_NANOSECONDS_TAG}; + + return YamlValidator::validate_tags(yml, tags); +} + +template <> +DDSPIPE_YAML_DllAPI +utils::Timestamp YamlReader::get( + const Yaml& yml, + const YamlReaderVersion version /* version */) +{ + YamlValidator::validate(yml, version); + + utils::Timestamp object; + fill(object, yml, version); + return object; } } /* namespace yaml */ diff --git a/ddspipe_yaml/src/cpp/YamlReader_participants.cpp b/ddspipe_yaml/src/cpp/YamlReader_participants.cpp index 1e843ad2..87deed0f 100644 --- a/ddspipe_yaml/src/cpp/YamlReader_participants.cpp +++ b/ddspipe_yaml/src/cpp/YamlReader_participants.cpp @@ -45,7 +45,7 @@ namespace yaml { using namespace eprosima::ddspipe::core::types; using namespace eprosima::ddspipe::participants::types; -/************************ +/*********************** * PARTICIPANTS * ************************/ diff --git a/ddspipe_yaml/src/cpp/YamlReader_types.cpp b/ddspipe_yaml/src/cpp/YamlReader_types.cpp index c5f835cd..f9add13e 100644 --- a/ddspipe_yaml/src/cpp/YamlReader_types.cpp +++ b/ddspipe_yaml/src/cpp/YamlReader_types.cpp @@ -523,17 +523,17 @@ void YamlReader::fill( { if (is_tag_present(yml, LOG_FILTER_ERROR_TAG)) { - object[utils::VerbosityKind::Error] = get(yml, LOG_FILTER_ERROR_TAG, version); + object.error = get(yml, LOG_FILTER_ERROR_TAG, version); } if (is_tag_present(yml, LOG_FILTER_WARNING_TAG)) { - object[utils::VerbosityKind::Warning] = get(yml, LOG_FILTER_WARNING_TAG, version); + object.warning = get(yml, LOG_FILTER_WARNING_TAG, version); } if (is_tag_present(yml, LOG_FILTER_INFO_TAG)) { - object[utils::VerbosityKind::Info] = get(yml, LOG_FILTER_INFO_TAG, version); + object.info = get(yml, LOG_FILTER_INFO_TAG, version); } }