Skip to content

Commit

Permalink
Merge pull request #751 from apache/feature/685-update-container-conf…
Browse files Browse the repository at this point in the history
…ig-properties-usage

Feature/685 update container config properties usage
  • Loading branch information
pnoltes authored Jun 11, 2024
2 parents 16579ba + 621c2be commit 58860bb
Show file tree
Hide file tree
Showing 74 changed files with 1,697 additions and 1,722 deletions.
6 changes: 5 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ limitations under the License.
- pubsub_serializer.h is removed and no longer supported. Use pubsub_message_serialization_service.h instead.
- C++11 support for dm is removed. C++14 is now the minimum required version.
- C++17 string_view support is removed from the utils and framework lib.
- Apache Celix CMake bundle functions without a celix_ prefix or infix are removed.
- Apache Celix CMake container & bundle functions without a celix_ prefix or infix are removed.
- Apache Celix CMake support for creating docker images and creating runtimes dirs is removed.
- Support and usage of "service.lang" service property is removed.
- Rename of `CELIX_FRAMEWORK_FRAMEWORK_CACHE_DIR` config property to `CELIX_FRAMEWORK_CACHE_DIR`.
Expand Down Expand Up @@ -73,6 +73,10 @@ limitations under the License.
to add service properties with the correct type.
- Celix C++ Exception are now defined in the `celix/exceptions.h` header file. The `celix/Exception.h`
and `celix/IOException.h` are removed.
- The seperator for `CELIX_AUTO_START_0` .. `CELIX_AUTO_START_6` and `CELIX_AUTO_INSTALL` is now a comma instead of a
space.
- The launcher now only has 2 public functions: `celix_launcher_launchAndWait` and `celix_launcher_triggerStop`. The
other functions are removed.

## New Features

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
CELIX_AUTO_START_1=@rsa_bundle_file@ @discovery_bundle_file@ @topology_manager_bundle_file@ @tst_bundle_file@
LOGHELPER_ENABLE_STDOUT_FALLBACK=true
CELIX_FRAMEWORK_CLEAN_CACHE_DIR_ON_CREATE=true
CELIX_FRAMEWORK_CACHE_DIR=.cacheClient

DISCOVERY_CFG_POLL_INTERVAL=1
DISCOVERY_CFG_POLL_TIMEOUT=5
RSA_PORT=50881
DISCOVERY_CFG_SERVER_PORT=50991
DISCOVERY_CFG_POLL_ENDPOINTS=http://localhost:50992/org.apache.celix.discovery.configured
{
"CELIX_AUTO_START_1":"@rsa_bundle_file@,@discovery_bundle_file@,@topology_manager_bundle_file@,@tst_bundle_file@",
"LOGHELPER_ENABLE_STDOUT_FALLBACK":true,
"CELIX_FRAMEWORK_CLEAN_CACHE_DIR_ON_CREATE":true,
"CELIX_FRAMEWORK_CACHE_DIR":".cacheClient",
"DISCOVERY_CFG_POLL_INTERVAL":1,
"DISCOVERY_CFG_POLL_TIMEOUT":5,
"RSA_PORT":50881,
"DISCOVERY_CFG_SERVER_PORT":50991,
"DISCOVERY_CFG_POLL_ENDPOINTS":"http://localhost:50992/org.apache.celix.discovery.configured"
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,5 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you 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.

CELIX_AUTO_START_1=@rsa_bundle_file@ @calc_bundle_file@
LOGHELPER_ENABLE_STDOUT_FALLBACK=true
CELIX_FRAMEWORK_CLEAN_CACHE_DIR_ON_CREATE=true
{
"CELIX_AUTO_START_1":"@rsa_bundle_file@,@calc_bundle_file@",
"LOGHELPER_ENABLE_STDOUT_FALLBACK":true,
"CELIX_FRAMEWORK_CLEAN_CACHE_DIR_ON_CREATE":true
}
Original file line number Diff line number Diff line change
@@ -1,26 +1,11 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you 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.
CELIX_AUTO_START_1=@rsa_bundle_file@ @calc_bundle_file@ @remote_example_bundle_file@ @discovery_bundle_file@ @topology_manager_bundle_file@
LOGHELPER_ENABLE_STDOUT_FALLBACK=true
CELIX_FRAMEWORK_CLEAN_CACHE_DIR_ON_CREATE=true
CELIX_FRAMEWORK_CACHE_DIR=.cacheServer

DISCOVERY_CFG_POLL_INTERVAL=1
DISCOVERY_CFG_POLL_TIMEOUT=5
RSA_PORT=50882
DISCOVERY_CFG_SERVER_PORT=50992
DISCOVERY_CFG_POLL_ENDPOINTS=http://localhost:50991/org.apache.celix.discovery.configured
{
"CELIX_AUTO_START_1":"@rsa_bundle_file@,@calc_bundle_file@,@remote_example_bundle_file@,@discovery_bundle_file@,@topology_manager_bundle_file@",
"LOGHELPER_ENABLE_STDOUT_FALLBACK":true,
"CELIX_FRAMEWORK_CLEAN_CACHE_DIR_ON_CREATE":true,
"CELIX_FRAMEWORK_CACHE_DIR":".cacheServer",
"DISCOVERY_CFG_POLL_INTERVAL":1,
"DISCOVERY_CFG_POLL_TIMEOUT":5,
"RSA_PORT":50882,
"DISCOVERY_CFG_SERVER_PORT":50992,
"DISCOVERY_CFG_POLL_ENDPOINTS":"http://localhost:50991/org.apache.celix.discovery.configured"
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,38 +44,40 @@ typedef struct rsa_dfi_exception_test_service {
int (*func1)(void *handle);
}rsa_dfi_exception_test_service_t;

static celix_framework_t *serverFramework = NULL;
static celix_bundle_context_t *serverContext = NULL;
static celix_framework_t *serverFramework = nullptr;
static celix_bundle_context_t *serverContext = nullptr;

static celix_framework_t *clientFramework = NULL;
static celix_bundle_context_t *clientContext = NULL;
static celix_framework_t *clientFramework = nullptr;
static celix_bundle_context_t *clientContext = nullptr;

static rsa_dfi_exception_test_service_t *exceptionTestService = NULL;
static rsa_dfi_exception_test_service_t *exceptionTestService = nullptr;
static long exceptionTestSvcId = -1L;
static remote_interceptor_t *serverSvcInterceptor=NULL;
static remote_interceptor_t *clientSvcInterceptor=NULL;
static remote_interceptor_t *serverSvcInterceptor=nullptr;
static remote_interceptor_t *clientSvcInterceptor=nullptr;
static long serverSvcInterceptorSvcId = -1L;
static long clientSvcInterceptorSvcId = -1L;
static bool clientInterceptorPreProxyCallRetval=true;
static bool svcInterceptorPreExportCallRetval=true;

static void setupFm(bool useCurlShare) {
//server
celix_properties_t *serverProps = celix_properties_load("server.properties");
ASSERT_TRUE(serverProps != NULL);
celix_properties_t *serverProps = nullptr;
ASSERT_EQ(CELIX_SUCCESS, celix_properties_load("server.properties", 0, &serverProps));
ASSERT_TRUE(serverProps != nullptr);
serverFramework = celix_frameworkFactory_createFramework(serverProps);
ASSERT_TRUE(serverFramework != NULL);
ASSERT_TRUE(serverFramework != nullptr);
serverContext = celix_framework_getFrameworkContext(serverFramework);
ASSERT_TRUE(serverContext != NULL);
ASSERT_TRUE(serverContext != nullptr);

//client
celix_properties_t *clientProperties = celix_properties_load("client.properties");
celix_properties_t *clientProperties = nullptr;
ASSERT_EQ(CELIX_SUCCESS, celix_properties_load("client.properties", 0, &clientProperties));
celix_properties_setBool(clientProperties, "RSA_DFI_USE_CURL_SHARE_HANDLE", useCurlShare);
ASSERT_TRUE(clientProperties != NULL);
ASSERT_TRUE(clientProperties != nullptr);
clientFramework = celix_frameworkFactory_createFramework(clientProperties);
ASSERT_TRUE(clientFramework != NULL);
ASSERT_TRUE(clientFramework != nullptr);
clientContext = celix_framework_getFrameworkContext(clientFramework);
ASSERT_TRUE(clientContext != NULL);
ASSERT_TRUE(clientContext != nullptr);
}

static void teardownFm(void) {
Expand All @@ -92,7 +94,7 @@ typedef struct rsa_dfi_exception_test_service {
celix_properties_set(properties, CELIX_RSA_SERVICE_EXPORTED_INTERFACES, RSA_DIF_EXCEPTION_TEST_SERVICE);
celix_properties_set(properties, CELIX_RSA_SERVICE_EXPORTED_CONFIGS, "org.amdatu.remote.admin.http");
exceptionTestService = (rsa_dfi_exception_test_service_t *)calloc(1,sizeof(*exceptionTestService));
exceptionTestService->handle = NULL;
exceptionTestService->handle = nullptr;
exceptionTestService->func1 = rsaDfi_excepTestFunc1;
exceptionTestSvcId = celix_bundleContext_registerService(serverContext, exceptionTestService, RSA_DIF_EXCEPTION_TEST_SERVICE, properties);
}
Expand Down Expand Up @@ -137,7 +139,7 @@ typedef struct rsa_dfi_exception_test_service {
static void registerInterceptorService(void) {
svcInterceptorPreExportCallRetval = true;
serverSvcInterceptor = (remote_interceptor_t *)calloc(1,sizeof(*serverSvcInterceptor));
serverSvcInterceptor->handle = NULL;
serverSvcInterceptor->handle = nullptr;
serverSvcInterceptor->preProxyCall = serverServiceInterceptor_preProxyCall;
serverSvcInterceptor->postProxyCall = serverServiceInterceptor_postProxyCall;
serverSvcInterceptor->preExportCall = serverServiceInterceptor_preExportCall;
Expand All @@ -153,7 +155,7 @@ typedef struct rsa_dfi_exception_test_service {

clientInterceptorPreProxyCallRetval = true;
clientSvcInterceptor = (remote_interceptor_t *)calloc(1,sizeof(*clientSvcInterceptor));
clientSvcInterceptor->handle = NULL;
clientSvcInterceptor->handle = nullptr;
clientSvcInterceptor->preProxyCall = clientServiceInterceptor_preProxyCall;
clientSvcInterceptor->postProxyCall = clientServiceInterceptor_postProxyCall;
clientSvcInterceptor->preExportCall = clientServiceInterceptor_preExportCall;
Expand Down Expand Up @@ -472,8 +474,8 @@ class RsaDfiDynamicIpServerTestSuite : public ::testing::Test {

char calcIdStr[32] = {0};
snprintf(calcIdStr, 32, "%li", calcId);
celix_array_list_t *svcRegistrations = NULL;
auto status = serverRsaSvc->exportService(serverRsaSvc->admin, calcIdStr, NULL, &svcRegistrations);
celix_array_list_t *svcRegistrations = nullptr;
auto status = serverRsaSvc->exportService(serverRsaSvc->admin, calcIdStr, nullptr, &svcRegistrations);
ASSERT_EQ(CELIX_SUCCESS, status);
ASSERT_EQ(1, celix_arrayList_size(svcRegistrations));
export_registration_t *exportedReg = static_cast<export_registration_t*>(celix_arrayList_get(svcRegistrations, 0));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,19 @@ extern "C" {

#define TST_CONFIGURATION_TYPE "org.amdatu.remote.admin.http"

static celix_framework_t *framework = NULL;
static celix_bundle_context_t *context = NULL;
static celix_framework_t *framework = nullptr;
static celix_bundle_context_t *context = nullptr;

long calcSvcId = -1L;

static void setupFm(void) {
celix_properties_t *fwProperties = celix_properties_load("config.properties");
ASSERT_TRUE(fwProperties != NULL);
celix_properties_t *fwProperties = nullptr;
EXPECT_EQ(CELIX_SUCCESS, celix_properties_load("config.properties", 0, &fwProperties));
ASSERT_TRUE(fwProperties != nullptr);
framework = celix_frameworkFactory_createFramework(fwProperties);
ASSERT_TRUE(framework != NULL);
ASSERT_TRUE(framework != nullptr);
context = celix_framework_getFrameworkContext(framework);
ASSERT_TRUE(context != NULL);
ASSERT_TRUE(context != nullptr);


calcSvcId = celix_bundleContext_findService(context, CALCULATOR_SERVICE);
Expand Down Expand Up @@ -87,8 +88,8 @@ extern "C" {
char strSvcId[64];
snprintf(strSvcId, 64, "%li", calcSvcId);

celix_array_list_t *svcRegistration = NULL;
int rc = rsa->exportService(rsa->admin, strSvcId, NULL, &svcRegistration);
celix_array_list_t *svcRegistration = nullptr;
int rc = rsa->exportService(rsa->admin, strSvcId, nullptr, &svcRegistration);
ASSERT_EQ(CELIX_SUCCESS, rc);

ASSERT_EQ(1, celix_arrayList_size(svcRegistration));
Expand Down Expand Up @@ -155,7 +156,7 @@ extern "C" {
}

static void testBundles(void) {
celix_array_list_t* bundles = NULL;
celix_array_list_t* bundles = nullptr;

int rc = bundleContext_getBundles(context, &bundles);
ASSERT_EQ(0, rc);
Expand All @@ -165,9 +166,9 @@ extern "C" {
int size = arrayList_size(bundles);
int i;
for (i = 0; i < size; i += 1) {
celix_bundle_t *bundle = NULL;
module_pt module = NULL;
char *name = NULL;
celix_bundle_t *bundle = nullptr;
module_pt module = nullptr;
char *name = nullptr;
bundle = (celix_bundle_t *) arrayList_get(bundles, i);
bundle_getCurrentModule(bundle, &module);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "socket_ei.h"
#include "stdio_ei.h"
#include "pthread_ei.h"
#include "celix_properties_ei.h"
#include "thpool_ei.h"
#include "celix_errno.h"
#include <errno.h>
Expand Down Expand Up @@ -80,6 +81,7 @@ class RsaShmClientServerUnitTestSuite : public ::testing::Test {
celix_ei_expect_pthread_cond_timedwait(nullptr, 1, 0);
celix_ei_expect_thpool_init(nullptr, 0, nullptr);
celix_ei_expect_thpool_add_work(nullptr, 0, 0);
celix_ei_expect_celix_properties_saveToStream(nullptr, 0, CELIX_SUCCESS);
}


Expand Down Expand Up @@ -139,6 +141,44 @@ TEST_F(RsaShmClientServerUnitTestSuite, SendMsg) {
rsaShmServer_destroy(server);
}

TEST_F(RsaShmClientServerUnitTestSuite, SendMsgErrorEncodePropertiesTest) {
//Given a rsa shm server
rsa_shm_server_t *server = nullptr;
auto status = rsaShmServer_create(ctx.get(), "shm_test_server", logHelper.get(), ReceiveMsgCallback, nullptr, &server);
EXPECT_EQ(CELIX_SUCCESS, status);
EXPECT_NE(nullptr, server);

//And a rsa shm client
rsa_shm_client_manager_t *clientManager = nullptr;
status = rsaShmClientManager_create(ctx.get(), logHelper.get(), &clientManager);
EXPECT_EQ(CELIX_SUCCESS, status);
EXPECT_NE(nullptr, clientManager);

// And the client is attached to the server
long serverId = 100;//dummy id
status = rsaShmClientManager_createOrAttachClient(clientManager, "shm_test_server", serverId);
EXPECT_EQ(CELIX_SUCCESS, status);

//When an error is prepared for saveToStream
celix_ei_expect_celix_properties_saveToStream((void*)rsaShmClientManager_sendMsgTo, 0, ENOMEM);

//And a message is sent
celix_autoptr(celix_properties_t) metadata = celix_properties_create();
celix_properties_set(metadata, "CustomKey", "test");
struct iovec request = {.iov_base = (void*)"request", .iov_len = strlen("request")};
struct iovec response = {.iov_base = nullptr, .iov_len = 0};
status = rsaShmClientManager_sendMsgTo(clientManager, "shm_test_server", serverId, metadata, &request, &response);

//Then the injected error is returned
EXPECT_EQ(ENOMEM, status);

rsaShmClientManager_destroyOrDetachClient(clientManager, "shm_test_server", serverId);

rsaShmClientManager_destroy(clientManager);

rsaShmServer_destroy(server);
}

TEST_F(RsaShmClientServerUnitTestSuite, SendMsgWithNoServer) {
rsa_shm_client_manager_t *clientManager = nullptr;
auto status = rsaShmClientManager_create(ctx.get(), logHelper.get(), &clientManager);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,13 @@ celix_status_t rsaShmClientManager_sendMsgTo(rsa_shm_client_manager_t *clientMan
return CELIX_ERROR_MAKE(CELIX_FACILITY_CERRNO, errno);
}
if (metadata != NULL) {
CELIX_PROPERTIES_ITERATE(metadata, iter) {
fprintf(fp,"%s=%s\n", iter.key, iter.entry.value);
status = celix_properties_saveToStream(metadata, fp, 0);
if (status != CELIX_SUCCESS) {
fclose(fp);
celix_logHelper_error(
clientManager->logHelper, "RsaShmClient: Error encoding metadata to memory stream. %d.", status);
celix_logHelper_logTssErrors(clientManager->logHelper, CELIX_LOG_LEVEL_ERROR);
return status;
}
}
fclose(fp);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ static void rsaShmServer_terminateMsgHandling(rsa_shm_msg_control_t *ctrl) {

static void rsaShmServer_msgHandlingWork(void *data) {
assert(data != NULL);
int status = CELIX_SUCCESS;
int status = CELIX_SUCCESS;
struct rsa_shm_server_thpool_work_data *workData = data;
rsa_shm_server_t *server = workData->server;
assert(server != NULL);
Expand All @@ -179,9 +179,9 @@ static void rsaShmServer_msgHandlingWork(void *data) {

celix_properties_t *metadataProps = NULL;
if (workData->metadataSize != 0) {
metadataProps = celix_properties_loadFromString(metaDataString);
if (metadataProps == NULL) {
if (celix_properties_loadFromString(metaDataString, 0, &metadataProps) != CELIX_SUCCESS) {
celix_logHelper_warning(server->loghelper, "RsaShmServer: Parse metadata failed.");
celix_logHelper_logTssErrors(server->loghelper, CELIX_LOG_LEVEL_WARNING);
}
}

Expand Down
22 changes: 12 additions & 10 deletions bundles/remote_services/topology_manager/tms_tst/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,21 @@ add_celix_bundle_dependencies(test_tm_scoped Celix::rsa_dfi Celix::rsa_topology_

file(GENERATE
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/config.properties"
CONTENT "
CELIX_AUTO_START_1=$<TARGET_PROPERTY:Celix::rsa_dfi,BUNDLE_FILE> $<TARGET_PROPERTY:calculator,BUNDLE_FILE> $<TARGET_PROPERTY:Celix::rsa_topology_manager,BUNDLE_FILE> $<TARGET_PROPERTY:topology_manager_disc_mock_bundle,BUNDLE_FILE>
LOGHELPER_ENABLE_STDOUT_FALLBACK=true
CELIX_FRAMEWORK_CLEAN_CACHE_DIR_ON_CREATE=true
")
CONTENT "{
\"CELIX_AUTO_START_1\":\"$<TARGET_PROPERTY:Celix::rsa_dfi,BUNDLE_FILE>,$<TARGET_PROPERTY:calculator,BUNDLE_FILE>,$<TARGET_PROPERTY:Celix::rsa_topology_manager,BUNDLE_FILE>,$<TARGET_PROPERTY:topology_manager_disc_mock_bundle,BUNDLE_FILE>\",
\"LOGHELPER_ENABLE_STDOUT_FALLBACK\":true,
\"CELIX_FRAMEWORK_CLEAN_CACHE_DIR_ON_CREATE\":true,
\"CELIX_FRAMEWORK_CACHE_DIR\":\".rstm_cache\"
}")

file(GENERATE
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/config_import.properties"
CONTENT "
CELIX_AUTO_START_1=$<TARGET_PROPERTY:Celix::rsa_dfi,BUNDLE_FILE> $<TARGET_PROPERTY:calculator,BUNDLE_FILE> $<TARGET_PROPERTY:Celix::rsa_topology_manager,BUNDLE_FILE> $<TARGET_PROPERTY:topology_manager_test_bundle,BUNDLE_FILE>
LOGHELPER_ENABLE_STDOUT_FALLBACK=true
CELIX_FRAMEWORK_CLEAN_CACHE_DIR_ON_CREATE=true
")
CONTENT "{
\"CELIX_AUTO_START_1\":\"$<TARGET_PROPERTY:Celix::rsa_dfi,BUNDLE_FILE>,$<TARGET_PROPERTY:calculator,BUNDLE_FILE>,$<TARGET_PROPERTY:Celix::rsa_topology_manager,BUNDLE_FILE>,$<TARGET_PROPERTY:topology_manager_test_bundle,BUNDLE_FILE>\",
\"LOGHELPER_ENABLE_STDOUT_FALLBACK\":true,
\"CELIX_FRAMEWORK_CLEAN_CACHE_DIR_ON_CREATE\":true,
\"CELIX_FRAMEWORK_CACHE_DIR\":\".rstm_import_cache\"
}")

configure_file("scope.json" "scope.json")
configure_file("scope2.json" "scope2.json")
Expand Down
Loading

0 comments on commit 58860bb

Please sign in to comment.