Skip to content

Commit

Permalink
Merge pull request #710 from xuzhenbao/improve_zeroconf_discovery
Browse files Browse the repository at this point in the history
Improve zeroconf discovery
  • Loading branch information
xuzhenbao authored Feb 20, 2024
2 parents 6a550a4 + e48e5ed commit 0bca5ef
Show file tree
Hide file tree
Showing 93 changed files with 4,947 additions and 1,192 deletions.
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
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

0 comments on commit 0bca5ef

Please sign in to comment.