diff --git a/include/fastdds_statistics_backend/types/app_names.h b/include/fastdds_statistics_backend/types/app_names.h index 7659e8d7c..540feb28b 100644 --- a/include/fastdds_statistics_backend/types/app_names.h +++ b/include/fastdds_statistics_backend/types/app_names.h @@ -19,6 +19,8 @@ #ifndef _EPROSIMA_FASTDDS_STATISTICS_BACKEND_TYPES_APP_NAMES_HPP_ #define _EPROSIMA_FASTDDS_STATISTICS_BACKEND_TYPES_APP_NAMES_HPP_ +#include + namespace eprosima { namespace statistics_backend { @@ -53,6 +55,19 @@ constexpr const char* app_id_str[] = {"UNKNOWN_APP", FASTDDS_MONITOR_APP, DDS_ROUTER_APP, SHAPES_DEMO_APP, INTEGRATION_SERVICE_APP, FASTDDS_VISUALIZER_APP, FASTDDS_SPY_APP, DDS_RECORDER_APP, DDS_REPLAYER_APP, AML_IP_APP}; +//! Conversion from string to AppId +const std::map app_id_enum = { + {FASTDDS_MONITOR_APP, AppId::FASTDDS_MONITOR}, + {DDS_ROUTER_APP, AppId::DDS_ROUTER}, + {SHAPES_DEMO_APP, AppId::SHAPES_DEMO}, + {INTEGRATION_SERVICE_APP, AppId::INTEGRATION_SERVICE}, + {FASTDDS_VISUALIZER_APP, AppId::FASTDDS_VISUALIZER}, + {FASTDDS_SPY_APP, AppId::FASTDDS_SPY}, + {DDS_RECORDER_APP, AppId::DDS_RECORDER}, + {DDS_REPLAYER_APP, AppId::DDS_REPLAYER}, + {AML_IP_APP, AppId::AML_IP} +}; + } //namespace statistics_backend } //namespace eprosima diff --git a/src/cpp/database/database.cpp b/src/cpp/database/database.cpp index bd2ae3750..ab0e91f1a 100644 --- a/src/cpp/database/database.cpp +++ b/src/cpp/database/database.cpp @@ -1823,7 +1823,7 @@ void Database::link_participant_with_process_nts( else if (participant_it->second->process) { throw BadParameter("Participant with ID " + std::to_string( - participant_id.value()) + " in already linked with a process"); + participant_id.value()) + " is already linked with a process"); } /* Get the process */ diff --git a/src/cpp/subscriber/StatisticsParticipantListener.cpp b/src/cpp/subscriber/StatisticsParticipantListener.cpp index e1cf2554d..b2e068d39 100644 --- a/src/cpp/subscriber/StatisticsParticipantListener.cpp +++ b/src/cpp/subscriber/StatisticsParticipantListener.cpp @@ -149,9 +149,6 @@ void StatisticsParticipantListener::on_participant_discovery( discovery_info.address = get_address(info.info); discovery_info.participant_name = info.info.m_participantName.to_string(); - discovery_info.app_id = AppId::UNKNOWN; - discovery_info.app_metadata = ""; - discovery_info.entity_status = StatusLevel::OK; switch (info.status) @@ -176,8 +173,8 @@ void StatisticsParticipantListener::on_participant_discovery( } } - //Get physical data from participant discovery info - auto get_physical_property_value = + //Get data from participant discovery info + auto get_property_value = [](const fastdds::dds::ParameterPropertyList_t& properties, const std::string& property_name) -> std::string { auto property = std::find_if( @@ -194,12 +191,23 @@ void StatisticsParticipantListener::on_participant_discovery( return std::string(""); }; - discovery_info.host = get_physical_property_value(info.info.m_properties, + discovery_info.host = get_property_value(info.info.m_properties, eprosima::fastdds::dds::parameter_policy_physical_data_host); - discovery_info.user = get_physical_property_value(info.info.m_properties, + discovery_info.host = discovery_info.host.empty()? "Unknown" : discovery_info.host; + + discovery_info.user = get_property_value(info.info.m_properties, eprosima::fastdds::dds::parameter_policy_physical_data_user); - discovery_info.process = get_physical_property_value(info.info.m_properties, + discovery_info.user = discovery_info.user.empty()? "Unknown" : discovery_info.user; + + discovery_info.process = get_property_value(info.info.m_properties, eprosima::fastdds::dds::parameter_policy_physical_data_process); + discovery_info.process = discovery_info.process.empty()? "Unknown" : discovery_info.process; + + std::string app_id = get_property_value(info.info.m_properties, "fastdds.application.id"); + auto it = app_id_enum.find(app_id); + discovery_info.app_id = it != app_id_enum.end()? it->second : AppId::UNKNOWN; + + discovery_info.app_metadata = get_property_value(info.info.m_properties, "fastdds.application.metadata"); entity_queue_->push(timestamp, discovery_info); diff --git a/src/cpp/subscriber/StatisticsParticipantListener.hpp b/src/cpp/subscriber/StatisticsParticipantListener.hpp index 5d914a2c6..56a5cd9d8 100644 --- a/src/cpp/subscriber/StatisticsParticipantListener.hpp +++ b/src/cpp/subscriber/StatisticsParticipantListener.hpp @@ -28,6 +28,7 @@ #include #include +#include namespace eprosima { namespace statistics_backend { diff --git a/test/unittest/StatisticsBackend/CallingUserListenersTests.cpp b/test/unittest/StatisticsBackend/CallingUserListenersTests.cpp index e4dafec3f..6c01b6d24 100644 --- a/test/unittest/StatisticsBackend/CallingUserListenersTests.cpp +++ b/test/unittest/StatisticsBackend/CallingUserListenersTests.cpp @@ -1827,6 +1827,10 @@ TEST_F(calling_user_listeners_tests_end_to_end, entity_discovery_end_to_end) participant_data.m_guid = participant_guid_; participant_data.m_participantName = participant_name_; + participant_data.m_properties.push_back(eprosima::fastdds::dds::parameter_policy_physical_data_host, "host_name"); + participant_data.m_properties.push_back(eprosima::fastdds::dds::parameter_policy_physical_data_user, "user_name"); + participant_data.m_properties.push_back(eprosima::fastdds::dds::parameter_policy_physical_data_process, "process_name"); + // The participant locator eprosima::fastrtps::rtps::Locator_t participant_locator(LOCATOR_KIND_UDPv4, 2049); participant_locator.address[12] = 127; @@ -1851,7 +1855,9 @@ TEST_F(calling_user_listeners_tests_end_to_end, entity_discovery_end_to_end) EXPECT_EQ(monitor_id_, participant->domain->id); EXPECT_EQ(participant_guid_str_, participant->guid); EXPECT_EQ(participant_name_, participant->name); - EXPECT_EQ(nullptr, participant->process); + EXPECT_NE(nullptr, participant->process); + EXPECT_NE(nullptr, participant->process->user); + EXPECT_NE(nullptr, participant->process->user->host); EXPECT_TRUE(participant->data_readers.empty()); ASSERT_EQ(1u, participant->data_writers.size()); // There is the metatraffic endpoint diff --git a/test/unittest/StatisticsBackend/IsActiveTests.cpp b/test/unittest/StatisticsBackend/IsActiveTests.cpp index 779127475..5d4c28ec2 100644 --- a/test/unittest/StatisticsBackend/IsActiveTests.cpp +++ b/test/unittest/StatisticsBackend/IsActiveTests.cpp @@ -449,6 +449,10 @@ TEST_F(is_active_tests, discover_datawriter_on_inactive_domain) data.m_guid = participant_guid_; data.m_participantName = participant->name; + data.m_properties.push_back(eprosima::fastdds::dds::parameter_policy_physical_data_host, host->name); + data.m_properties.push_back(eprosima::fastdds::dds::parameter_policy_physical_data_user, user->name); + data.m_properties.push_back(eprosima::fastdds::dds::parameter_policy_physical_data_process, process->name); + // Finish building the discovered reader info eprosima::fastrtps::rtps::ParticipantDiscoveryInfo info(data); info.status = eprosima::fastrtps::rtps::ParticipantDiscoveryInfo::DROPPED_PARTICIPANT; @@ -537,6 +541,10 @@ TEST_F(is_active_tests, discover_datawriter_on_inactive_domain) data.m_guid = participant_guid_; data.m_participantName = participant->name + "_1"; + data.m_properties.push_back(eprosima::fastdds::dds::parameter_policy_physical_data_host, host->name); + data.m_properties.push_back(eprosima::fastdds::dds::parameter_policy_physical_data_user, user->name); + data.m_properties.push_back(eprosima::fastdds::dds::parameter_policy_physical_data_process, "process1"); + // Finish building the discovered reader info eprosima::fastrtps::rtps::ParticipantDiscoveryInfo info(data); info.status = eprosima::fastrtps::rtps::ParticipantDiscoveryInfo::DISCOVERED_PARTICIPANT; @@ -548,7 +556,6 @@ TEST_F(is_active_tests, discover_datawriter_on_inactive_domain) // Link participant - process auto participant_id = db->get_entity_by_guid(EntityKind::PARTICIPANT, "01.0f.00.00.00.00.00.00.00.00.00.01|0.0.1.c1").second; - db->link_participant_with_process(participant_id, process1->id); ASSERT_TRUE(StatisticsBackendTest::is_active(host->id)); ASSERT_TRUE(StatisticsBackendTest::is_active(user->id)); @@ -621,6 +628,10 @@ TEST_F(is_active_tests, discover_datareader_on_inactive_domain) std::stringstream(participant->guid) >> participant_guid_; data.m_guid = participant_guid_; data.m_participantName = participant->name; + + data.m_properties.push_back(eprosima::fastdds::dds::parameter_policy_physical_data_host, host->name); + data.m_properties.push_back(eprosima::fastdds::dds::parameter_policy_physical_data_user, user->name); + data.m_properties.push_back(eprosima::fastdds::dds::parameter_policy_physical_data_process, process->name); // Finish building the discovered reader info eprosima::fastrtps::rtps::ParticipantDiscoveryInfo info(data); @@ -709,6 +720,10 @@ TEST_F(is_active_tests, discover_datareader_on_inactive_domain) std::stringstream("01.0f.00.00.00.00.00.00.00.00.00.01|0.0.1.c1") >> participant_guid_; data.m_guid = participant_guid_; data.m_participantName = participant->name + "_1"; + + data.m_properties.push_back(eprosima::fastdds::dds::parameter_policy_physical_data_host, host->name); + data.m_properties.push_back(eprosima::fastdds::dds::parameter_policy_physical_data_user, user->name); + data.m_properties.push_back(eprosima::fastdds::dds::parameter_policy_physical_data_process, "process1"); // Finish building the discovered reader info eprosima::fastrtps::rtps::ParticipantDiscoveryInfo info(data); @@ -721,7 +736,6 @@ TEST_F(is_active_tests, discover_datareader_on_inactive_domain) // Link participant - process auto participant_id = db->get_entity_by_guid(EntityKind::PARTICIPANT, "01.0f.00.00.00.00.00.00.00.00.00.01|0.0.1.c1").second; - db->link_participant_with_process(participant_id, process1->id); ASSERT_TRUE(StatisticsBackendTest::is_active(host->id)); ASSERT_TRUE(StatisticsBackendTest::is_active(user->id));