Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve zeroconf discovery #710

Merged
merged 31 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
a38a77a
Use the real hostname for remote service
xuzhenbao Nov 28, 2023
0a92022
Remove uuid in the service instance name
xuzhenbao Dec 1, 2023
28e775b
Add process ID to service instance name for easier debugging
xuzhenbao Dec 5, 2023
92ce33a
Resolve ip addresses and set it to endpoint description
xuzhenbao Dec 8, 2023
0705bf5
Resolve ip addresses and set it to endpoint description
xuzhenbao Dec 8, 2023
4fdeade
Add the interval time of endpoint watcher thead loop
xuzhenbao Dec 9, 2023
f92eb6c
Add the interval time of endpoint watcher thead loop
xuzhenbao Dec 10, 2023
73308d5
Remove the service resolved timeout mechanism, it is not necessary
xuzhenbao Dec 11, 2023
89e4dbc
Add retry cnt for DNSServiceGetAddrInfo
xuzhenbao Dec 11, 2023
f5e276e
Map the config type to mDNS service subtype and improve some code
xuzhenbao Dec 12, 2023
dbc603d
Improve discovery_zeroconf and its unit test
xuzhenbao Dec 18, 2023
f6cfb5e
Refresh remote service endpoint when RSA is removed
xuzhenbao Dec 20, 2023
9266360
Add remote.configs.supported property for RSA service,and add celix.r…
xuzhenbao Dec 20, 2023
3b06116
fix bugs for discovery_zeroconf
xuzhenbao Dec 25, 2023
ddcd91b
Add zeroconf configuration type for rsa_dfi
xuzhenbao Dec 25, 2023
ea552e5
Add zeroconf configuration type for rsa_dfi
xuzhenbao Dec 25, 2023
eedf073
Rename the configurations name of rsa_shm
xuzhenbao Dec 25, 2023
11c8fdc
Rename remote service bundles
xuzhenbao Dec 25, 2023
8100c7f
Fix bugs for discovery_zeroconf
xuzhenbao Dec 28, 2023
4736691
Fix unit test failure
xuzhenbao Dec 29, 2023
4de2144
Fix unit test failure
xuzhenbao Dec 29, 2023
1aecccc
Merge branch 'master' of https://github.com/xuzhenbao/celix into impr…
xuzhenbao Jan 1, 2024
768c5c7
Merge master
xuzhenbao Jan 1, 2024
356ec2b
Add CELIX_RSA prefix for constants of rsa_spi
xuzhenbao Jan 19, 2024
21b088f
Fix code based on code review
xuzhenbao Jan 19, 2024
e95dcef
Topology Manager implement dynamic IP mechanism
xuzhenbao Feb 2, 2024
66a3f10
Improve unit test of discovery_zeroconf
xuzhenbao Feb 4, 2024
2cb9b5c
Merge branch 'master' of https://github.com/xuzhenbao/celix into impr…
xuzhenbao Feb 4, 2024
ce4dc3b
Replace OSGI_RSA_ prefix to CELIX_RSA_
xuzhenbao Feb 4, 2024
8e14b97
Remove IPV6 server for RSA_DFI, because civetweb not support IPV6 in …
xuzhenbao Feb 4, 2024
e48e5ed
Improve CURL error code handling
xuzhenbao Feb 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions bundles/remote_services/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,9 @@ if (REMOTE_SERVICE_ADMIN)
calculator
USE_CONFIG
PROPERTIES
CELIX_RSA_BIND_ON_ALL_INTERFACES=false
CELIX_RSA_DFI_DYNAMIC_IP_SUPPORT=true
RSA_PORT=19999
CELIX_RSA_INTERFACES_OF_PORT_19999=lo
)

add_celix_container(remote-services-zeroconf-client
Expand All @@ -147,7 +149,9 @@ if (REMOTE_SERVICE_ADMIN)
calculator_shell
USE_CONFIG
PROPERTIES
CELIX_RSA_BIND_ON_ALL_INTERFACES=false
CELIX_RSA_DFI_DYNAMIC_IP_SUPPORT=true
RSA_PORT=29999
CELIX_RSA_INTERFACES_OF_PORT_29999=lo
)
endif()

Expand Down
4 changes: 2 additions & 2 deletions bundles/remote_services/discovery_common/src/discovery.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ celix_status_t discovery_endpointListenerAdded(void* handle, service_reference_p
const char *discoveryListener = NULL;
serviceReference_getProperty(reference, "DISCOVERY", &discoveryListener);
const char *scope = NULL;
serviceReference_getProperty(reference, OSGI_ENDPOINT_LISTENER_SCOPE, &scope);
serviceReference_getProperty(reference, CELIX_RSA_ENDPOINT_LISTENER_SCOPE, &scope);

celix_autoptr(celix_filter_t) filter = celix_filter_create(scope);

Expand Down Expand Up @@ -166,7 +166,7 @@ celix_status_t discovery_informEndpointListeners(discovery_t *discovery, endpoin
endpoint_listener_t *listener = NULL;

const char* scope = NULL;
serviceReference_getProperty(reference, OSGI_ENDPOINT_LISTENER_SCOPE, &scope);
serviceReference_getProperty(reference, CELIX_RSA_ENDPOINT_LISTENER_SCOPE, &scope);

celix_autoptr(celix_filter_t) filter = celix_filter_create(scope);
bool matchResult = celix_filter_match(filter, endpoint->properties);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ celix_status_t bundleActivator_createEPLTracker(struct activator *activator, ser
discovery_endpointListenerRemoved, &customizer);

if (status == CELIX_SUCCESS) {
status = serviceTracker_create(activator->context, (char *) OSGI_ENDPOINT_LISTENER_SERVICE, customizer, tracker);
status = serviceTracker_create(activator->context, (char *) CELIX_RSA_ENDPOINT_LISTENER_SERVICE_NAME, customizer, tracker);
}

return status;
Expand Down Expand Up @@ -103,7 +103,7 @@ celix_status_t celix_bundleActivator_start(void * userData, celix_bundle_context
}

char* scope = NULL;
int rc = asprintf(&scope, "(&(%s=*)(%s=%s))", CELIX_FRAMEWORK_SERVICE_NAME, OSGI_RSA_ENDPOINT_FRAMEWORK_UUID, uuid);
int rc = asprintf(&scope, "(&(%s=*)(%s=%s))", CELIX_FRAMEWORK_SERVICE_NAME, CELIX_RSA_ENDPOINT_FRAMEWORK_UUID, uuid);
status = rc < 0 ? CELIX_ENOMEM : CELIX_SUCCESS;

celix_autoptr(celix_properties_t) props = NULL;
Expand All @@ -112,7 +112,7 @@ celix_status_t celix_bundleActivator_start(void * userData, celix_bundle_context

props = celix_properties_create();
celix_properties_set(props, "DISCOVERY", "true");
celix_properties_set(props, (char *) OSGI_ENDPOINT_LISTENER_SCOPE, scope);
celix_properties_set(props, (char *) CELIX_RSA_ENDPOINT_LISTENER_SCOPE, scope);
}

if (status == CELIX_SUCCESS) {
Expand All @@ -131,8 +131,8 @@ celix_status_t celix_bundleActivator_start(void * userData, celix_bundle_context
endpointListener->endpointAdded = discovery_endpointAdded;
endpointListener->endpointRemoved = discovery_endpointRemoved;

status = bundleContext_registerService(context, (char *) OSGI_ENDPOINT_LISTENER_SERVICE, endpointListener,
celix_steal_ptr(props), &activator->endpointListenerService);
status = bundleContext_registerService(context, (char *) CELIX_RSA_ENDPOINT_LISTENER_SERVICE_NAME, endpointListener,
celix_steal_ptr(props), &activator->endpointListenerService);

if (status == CELIX_SUCCESS) {
activator->endpointListener = endpointListener;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ static celix_status_t endpointDescriptorWriter_writeEndpoint(endpoint_descriptor
if (strcmp(CELIX_FRAMEWORK_SERVICE_NAME, (char*) iter.key) == 0) {
// objectClass *must* be represented as array of string values...
endpointDescriptorWriter_writeArrayValue(writer->writer, propertyValue);
} else if (strcmp(OSGI_RSA_ENDPOINT_SERVICE_ID, (char*) iter.key) == 0) {
} else if (strcmp(CELIX_RSA_ENDPOINT_SERVICE_ID, (char*) iter.key) == 0) {
// endpoint.service.id *must* be represented as long value...
endpointDescriptorWriter_writeTypedValue(writer->writer, VALUE_TYPE_LONG, propertyValue);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ if (RSA_DISCOVERY_CONFIGURED)
VERSION 0.9.0
SYMBOLIC_NAME "apache_celix_rsa_discovery"
NAME "Apache Celix RSA Configured Discovery"
FILENAME celix_rsa_discovery_configured
PengZheng marked this conversation as resolved.
Show resolved Hide resolved
SOURCES
src/discovery_impl.c
)
Expand Down
1 change: 1 addition & 0 deletions bundles/remote_services/discovery_etcd/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ if (RSA_DISCOVERY_ETCD)
SYMBOLIC_NAME "apache_celix_rsa_discovery_etcd"
NAME "Apache Celix RSA Discovery ETCD"
GROUP "Celix/RSA"
FILENAME celix_rsa_discovery_etcd
SOURCES
src/discovery_impl.c
src/etcd_watcher.c
Expand Down
5 changes: 4 additions & 1 deletion bundles/remote_services/discovery_zeroconf/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,16 @@ if (RSA_DISCOVERY_ZEROCONF)

add_celix_bundle(rsa_discovery_zeroconf
SYMBOLIC_NAME "apache_celix_rsa_discovery_zeroconf"
VERSION "1.0.0"
VERSION "2.0.0"
NAME "Apache Celix Multicast zeroconf service discovery"
GROUP "Celix/RSA"
FILENAME celix_rsa_discovery_zeroconf
SOURCES
${RSA_DISCOVERY_ZEROCONF_SRC}
)

celix_deprecated_utils_headers(rsa_discovery_zeroconf)
celix_deprecated_framework_headers(rsa_discovery_zeroconf)

target_link_libraries(rsa_discovery_zeroconf PRIVATE ${RSA_DISCOVERY_ZEROCONF_DEPS})

Expand All @@ -58,6 +60,7 @@ if (RSA_DISCOVERY_ZEROCONF)
if (ENABLE_TESTING)
add_library(rsa_discovery_zeroconf_cut STATIC ${RSA_DISCOVERY_ZEROCONF_SRC})
celix_deprecated_utils_headers(rsa_discovery_zeroconf_cut)
celix_deprecated_framework_headers(rsa_discovery_zeroconf_cut)
target_include_directories(rsa_discovery_zeroconf_cut PUBLIC ${CMAKE_CURRENT_LIST_DIR}/src)
target_link_libraries(rsa_discovery_zeroconf_cut PUBLIC ${RSA_DISCOVERY_ZEROCONF_DEPS})
add_subdirectory(gtest)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ if (EI_TESTS)
)

celix_deprecated_utils_headers(unit_test_discovery_zeroconf)
celix_deprecated_framework_headers(unit_test_discovery_zeroconf)

target_link_libraries(unit_test_discovery_zeroconf PRIVATE
rsa_discovery_zeroconf_cut
Expand All @@ -58,6 +59,14 @@ if (EI_TESTS)
Celix::threads_ei
Celix::eventfd_ei
Celix::bundle_ctx_ei
Celix::string_hash_map_ei
Celix::long_hash_map_ei
Celix::array_list_ei
Celix::properties_ei
Celix::utils_ei
Celix::dm_component_ei
Celix::bundle_ctx_ei
Celix::log_helper_ei
Celix::mdnsresponder_ei
Celix::malloc_ei
GTest::gtest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@

#include "discovery_zeroconf_announcer.h"
#include "discovery_zeroconf_watcher.h"
#include "celix_dm_component_ei.h"
#include "celix_bundle_context_ei.h"
#include "celix_properties_ei.h"
#include "celix_log_helper_ei.h"
#include "eventfd_ei.h"
#include "celix_framework.h"
#include "celix_framework_factory.h"
Expand All @@ -41,6 +45,13 @@ class DiscoveryZeroconfActivatorTestSuite : public ::testing::Test {

~DiscoveryZeroconfActivatorTestSuite() override {
celix_ei_expect_eventfd(nullptr, 0, 0);
celix_ei_expect_celix_bundleContext_getProperty(nullptr, 0, nullptr);
celix_ei_expect_celix_bundleContext_getDependencyManager(nullptr, 0, nullptr);
celix_ei_expect_celix_dmComponent_create(nullptr, 0, nullptr);
celix_ei_expect_celix_dmServiceDependency_create(nullptr, 0, nullptr);
celix_ei_expect_celix_properties_create(nullptr, 0, nullptr);
celix_ei_expect_celix_logHelper_create(nullptr, 0, nullptr);
celix_ei_expect_celix_properties_set(nullptr, 0, 0);
}

std::shared_ptr<celix_framework_t> fw{};
Expand Down Expand Up @@ -84,6 +95,134 @@ TEST_F(DiscoveryZeroconfActivatorTestSuite, DiscoveryZeroconfWatcherCreateFailed
status = celix_bundleActivator_start(act, ctx.get());
EXPECT_EQ(CELIX_ENOMEM, status);

status = celix_bundleActivator_destroy(act, ctx.get());
EXPECT_EQ(CELIX_SUCCESS, status);
}

TEST_F(DiscoveryZeroconfActivatorTestSuite, GetFrameworkUuidFailed) {
void *act{nullptr};
auto status = celix_bundleActivator_create(ctx.get(), &act);
EXPECT_EQ(CELIX_SUCCESS, status);

celix_ei_expect_celix_bundleContext_getProperty(CELIX_EI_UNKNOWN_CALLER, 0, nullptr);
status = celix_bundleActivator_start(act, ctx.get());
EXPECT_EQ(CELIX_BUNDLE_EXCEPTION, status);

status = celix_bundleActivator_destroy(act, ctx.get());
EXPECT_EQ(CELIX_SUCCESS, status);
}

TEST_F(DiscoveryZeroconfActivatorTestSuite, CreateLogHelperFailed) {
void *act{nullptr};
auto status = celix_bundleActivator_create(ctx.get(), &act);
EXPECT_EQ(CELIX_SUCCESS, status);

celix_ei_expect_celix_logHelper_create(CELIX_EI_UNKNOWN_CALLER, 0, nullptr);
status = celix_bundleActivator_start(act, ctx.get());
EXPECT_EQ(CELIX_ENOMEM, status);

status = celix_bundleActivator_destroy(act, ctx.get());
EXPECT_EQ(CELIX_SUCCESS, status);
}

TEST_F(DiscoveryZeroconfActivatorTestSuite, CreateAnnouncerDmComponentFailed) {
void *act{nullptr};
auto status = celix_bundleActivator_create(ctx.get(), &act);
EXPECT_EQ(CELIX_SUCCESS, status);

celix_ei_expect_celix_dmComponent_create(CELIX_EI_UNKNOWN_CALLER, 0, nullptr);
status = celix_bundleActivator_start(act, ctx.get());
EXPECT_EQ(CELIX_ENOMEM, status);

status = celix_bundleActivator_destroy(act, ctx.get());
EXPECT_EQ(CELIX_SUCCESS, status);
}

TEST_F(DiscoveryZeroconfActivatorTestSuite, CreateAnnouncerEndpointListenerPropertiesFailed) {
void *act{nullptr};
auto status = celix_bundleActivator_create(ctx.get(), &act);
EXPECT_EQ(CELIX_SUCCESS, status);

celix_ei_expect_celix_properties_create(CELIX_EI_UNKNOWN_CALLER, 0, nullptr);
status = celix_bundleActivator_start(act, ctx.get());
EXPECT_EQ(CELIX_ENOMEM, status);

status = celix_bundleActivator_destroy(act, ctx.get());
EXPECT_EQ(CELIX_SUCCESS, status);
}

TEST_F(DiscoveryZeroconfActivatorTestSuite, SetEndpointListenerSocpePropertyFailed) {
void *act{nullptr};
auto status = celix_bundleActivator_create(ctx.get(), &act);
EXPECT_EQ(CELIX_SUCCESS, status);

celix_ei_expect_celix_properties_set((void*)&celix_bundleActivator_start, 1, CELIX_ENOMEM);
status = celix_bundleActivator_start(act, ctx.get());
EXPECT_EQ(CELIX_ENOMEM, status);

status = celix_bundleActivator_destroy(act, ctx.get());
EXPECT_EQ(CELIX_SUCCESS, status);
}

TEST_F(DiscoveryZeroconfActivatorTestSuite, SetEndpointListenerInterfaceSpecificEndpointsPropertyFailed) {
void *act{nullptr};
auto status = celix_bundleActivator_create(ctx.get(), &act);
EXPECT_EQ(CELIX_SUCCESS, status);

celix_ei_expect_celix_properties_set((void*)&celix_bundleActivator_start, 1, CELIX_ENOMEM, 3);
status = celix_bundleActivator_start(act, ctx.get());
EXPECT_EQ(CELIX_ENOMEM, status);

status = celix_bundleActivator_destroy(act, ctx.get());
EXPECT_EQ(CELIX_SUCCESS, status);
}

TEST_F(DiscoveryZeroconfActivatorTestSuite, CreateWatcherDmComponentFailed) {
void *act{nullptr};
auto status = celix_bundleActivator_create(ctx.get(), &act);
EXPECT_EQ(CELIX_SUCCESS, status);

celix_ei_expect_celix_dmComponent_create(CELIX_EI_UNKNOWN_CALLER, 0, nullptr, 2);
status = celix_bundleActivator_start(act, ctx.get());
EXPECT_EQ(CELIX_ENOMEM, status);

status = celix_bundleActivator_destroy(act, ctx.get());
EXPECT_EQ(CELIX_SUCCESS, status);
}

TEST_F(DiscoveryZeroconfActivatorTestSuite, CreateEndpointListenerDependencyFailed) {
void *act{nullptr};
auto status = celix_bundleActivator_create(ctx.get(), &act);
EXPECT_EQ(CELIX_SUCCESS, status);

celix_ei_expect_celix_dmServiceDependency_create(CELIX_EI_UNKNOWN_CALLER, 0, nullptr);
status = celix_bundleActivator_start(act, ctx.get());
EXPECT_EQ(CELIX_ENOMEM, status);

status = celix_bundleActivator_destroy(act, ctx.get());
EXPECT_EQ(CELIX_SUCCESS, status);
}

TEST_F(DiscoveryZeroconfActivatorTestSuite, CreateRsaDependencyFailed) {
void *act{nullptr};
auto status = celix_bundleActivator_create(ctx.get(), &act);
EXPECT_EQ(CELIX_SUCCESS, status);

celix_ei_expect_celix_dmServiceDependency_create(CELIX_EI_UNKNOWN_CALLER, 0, nullptr, 2);
status = celix_bundleActivator_start(act, ctx.get());
EXPECT_EQ(CELIX_ENOMEM, status);

status = celix_bundleActivator_destroy(act, ctx.get());
EXPECT_EQ(CELIX_SUCCESS, status);
}

TEST_F(DiscoveryZeroconfActivatorTestSuite, GetDependencyManagerFailed) {
void *act{nullptr};
auto status = celix_bundleActivator_create(ctx.get(), &act);
EXPECT_EQ(CELIX_SUCCESS, status);
celix_ei_expect_celix_bundleContext_getDependencyManager(CELIX_EI_UNKNOWN_CALLER, 0, nullptr);
status = celix_bundleActivator_start(act, ctx.get());
EXPECT_EQ(CELIX_ENOMEM, status);
status = celix_bundleActivator_destroy(act, ctx.get());
EXPECT_EQ(CELIX_SUCCESS, status);
}
Loading
Loading