diff --git a/docker/build-ubi/04.install-fastdds.sh b/docker/build-ubi/04.install-fastdds.sh index 2dd0b0a2a8..56ee3c17bd 100755 --- a/docker/build-ubi/04.install-fastdds.sh +++ b/docker/build-ubi/04.install-fastdds.sh @@ -28,7 +28,6 @@ yum -y --nogpgcheck install https://dl.fedoraproject.org/pub/fedora/linux/releas # Fast-DDS mkdir /opt/Fast-DDS - # # foonathan_memory_vendor # diff --git a/scripts/configFile.sh b/scripts/configFile.sh new file mode 100755 index 0000000000..4a64569432 --- /dev/null +++ b/scripts/configFile.sh @@ -0,0 +1,86 @@ +#!/bin/bash + +# Copyright 2021 Telefonica Investigacion y Desarrollo, S.A.U +# +# This file is part of Orion Context Broker. +# +# Orion Context Broker is free software: you can redistribute it and/or +# modify it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# Orion Context Broker is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero +# General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. +# +# For those usages not covered by this license please contact with +# iot_support at tid dot es + +echo '{' +echo ' "dds": {' +echo ' "ddsmodule": {' +echo ' "dds": {' +echo ' "domain": 0,' +echo ' "allowlist": [' +echo ' {' +echo ' "name": "*"' +echo ' }' +echo ' ],' +echo ' "blocklist": [' +echo ' {' +echo ' "name": "add_blocked_topics_list_here"' +echo ' }' +echo ' ]' +echo ' },' +echo ' "topics": {' +echo ' "name": "*",' +echo ' "qos": {' +echo ' "durability": "TRANSIENT_LOCAL",' +echo ' "history-depth": 10' +echo ' }' +echo ' },' +echo ' "ddsenabler": null,' +echo ' "specs": {' +echo ' "threads": 12,' +echo ' "logging": {' +echo ' "stdout": false,' +echo ' "verbosity": "info"' +echo ' }' +echo ' }' +echo ' },' +echo ' "ngsild": {' +echo ' "topics": {' + +while [ $# != 0 ] +do + items=$1 + shift + + topic=$(echo $items | awk -F, '{ print $1 }') + eType=$(echo $items | awk -F, '{ print $2 }') + eId=$(echo $items | awk -F, '{ print $3 }') + attr=$(echo $items | awk -F, '{ print $4 }') + + if [ $# != 0 ] + then + comma=',' + else + comma='' + fi + + echo ' "'$topic'": {' + echo ' "entityType": "'$eType'",' + echo ' "entityId": "'$eId'",' + echo ' "attribute": "'$attr'"' + echo ' }'$comma +done + + +echo ' }' +echo ' }' +echo ' }' +echo '}' diff --git a/src/app/orionld/orionld.cpp b/src/app/orionld/orionld.cpp index f3929aab4d..3dc0ce9df4 100644 --- a/src/app/orionld/orionld.cpp +++ b/src/app/orionld/orionld.cpp @@ -55,7 +55,7 @@ * CLI option '--insecure'. */ #include -#include // getppid, fork, setuid, sleep, gethostname, etc. +#include // getppid, fork, setuid, sleep, gethostname, access, etc. #include // strchr #include // open #include @@ -254,11 +254,9 @@ char defaultUserContextUrl[256]; bool ddsSupport = false; char ddsSubsTopics[512]; char ddsTopicType[512]; -char ddsConfigFile[512]; -char ddsEnablerConfigFile[512]; +char configFile[512]; -#define DDSE_CONF_FILE "/tmp/DDS_ENABLER_CONFIGURATION.yaml" /* **************************************************************************** * @@ -354,8 +352,7 @@ char ddsEnablerConfigFile[512]; #define USE_DDS_DESC "turn on DDS support" #define DDS_SUBS_TOPICS_DESC "topics to subscribe to on DDS" #define DDS_TOPIC_TYPE_DESC "DDS topic type" -#define DDS_CONFIG_FILE_DESC "DDS configuration file" -#define DDS_ENABLER_CONFIG_FILE_DESC "DDS Enabler configuration file" +#define CONFIG_FILE_DESC "Path to configuration file" #define SUBORDINATE_ENDPOINT_DESC "endpoint URL for reception of notificatiopns from subordinate subscriptions (distributed subscriptions)" #define PAGE_SIZE_DESC "default page size (no of entities, subscriptions, registrations)" #define DUC_URL_DESC "URL to default user context" @@ -466,11 +463,10 @@ PaArgument paArgs[] = { "-subordinateEndpoint", &subordinateEndpoint, "SUBORDINATE_ENDPOINT", PaStr, PaOpt, _i "", PaNL, PaNL, SUBORDINATE_ENDPOINT_DESC }, { "-pageSize", &pageSize, "PAGE_SIZE", PaInt, PaOpt, 20, 1, 1000, PAGE_SIZE_DESC }, { "-dds", &ddsSupport, "DDS", PaBool, PaOpt, false, false, true, USE_DDS_DESC }, - { "-ddsSubsTopics", ddsSubsTopics, "DDS_SUBS_TOPICS", PaString, PaOpt, _i "", PaNL, PaNL, DDS_SUBS_TOPICS_DESC }, - { "-ddsTopicType", ddsTopicType, "DDS_TOPIC_TYPE", PaString, PaOpt, _i "NGSI-LD", PaNL, PaNL, DDS_TOPIC_TYPE_DESC }, - { "-ddsConfigFile", ddsConfigFile, "DDS_CONFIG_FILE", PaString, PaOpt, _i "", PaNL, PaNL, DDS_CONFIG_FILE_DESC }, - { "-ddsEnablerConfigFile", ddsEnablerConfigFile, "DDS_CONFIG_FILE_PATH", PaString, PaOpt, _i DDSE_CONF_FILE, PaNL, PaNL, DDS_ENABLER_CONFIG_FILE_DESC }, - { "-duc", defaultUserContextUrl, "DUC_URL", PaString, PaOpt, _i "", PaNL, PaNL, DUC_URL_DESC }, + { "-ddsSubsTopics", ddsSubsTopics, "DDS_SUBS_TOPICS", PaString, PaOpt, _i "", PaNL, PaNL, DDS_SUBS_TOPICS_DESC }, + { "-ddsTopicType", ddsTopicType, "DDS_TOPIC_TYPE", PaString, PaOpt, _i "NGSI-LD", PaNL, PaNL, DDS_TOPIC_TYPE_DESC }, + { "-configFile", configFile, "CONFIG_FILE", PaString, PaOpt, _i "", PaNL, PaNL, CONFIG_FILE_DESC }, + { "-duc", defaultUserContextUrl, "DUC_URL", PaString, PaOpt, _i "", PaNL, PaNL, DUC_URL_DESC }, PA_END_OF_ARGS }; @@ -1075,6 +1071,21 @@ int main(int argC, char* argV[]) paParse(paArgs, argC, (char**) argV, 1, false); + // + // Config file + // + configFileP = configFile; + if (configFile[0] == 0) + { + char* home = getenv("HOME"); + + if (home != NULL) + { + snprintf(configFile, sizeof(configFile) - 1, "%s/.orionld", home); + if (access(configFile, R_OK) != 0) + configFileP = NULL; + } + } // // Initializing the new logging library, kTrace diff --git a/src/lib/orionld/common/orionldState.cpp b/src/lib/orionld/common/orionldState.cpp index 7d95382e05..687f9e519c 100644 --- a/src/lib/orionld/common/orionldState.cpp +++ b/src/lib/orionld/common/orionldState.cpp @@ -94,6 +94,7 @@ Kjson kjson; Kjson* kjsonP; uint16_t portNo = 0; int dbNameLen; +char* configFileP = NULL; char* coreContextUrl = (char*) ORIONLD_CORE_CONTEXT_URL_DEFAULT; // v1.6, see orionld/context/orionldCoreContext.h char orionldHostName[128]; int orionldHostNameLen = -1; diff --git a/src/lib/orionld/common/orionldState.h b/src/lib/orionld/common/orionldState.h index 34fcf923da..963f0026a3 100644 --- a/src/lib/orionld/common/orionldState.h +++ b/src/lib/orionld/common/orionldState.h @@ -564,6 +564,8 @@ extern __thread OrionldConnectionState orionldState; // // Global state // +extern char configFile[512]; +extern char* configFileP; extern char* coreContextUrl; extern const char* builtinCoreContext; extern char orionldHostName[128]; @@ -638,8 +640,6 @@ extern unsigned long long outReqMsgMaxSize; // extern bool ddsSupport; // Publish/Subscriba via DDS extern char ddsTopicType[512]; -extern char ddsConfigFile[512]; -extern char ddsEnablerConfigFile[512]; diff --git a/src/lib/orionld/dds/ddsConfigTopicToAttribute.cpp b/src/lib/orionld/dds/ddsConfigTopicToAttribute.cpp index ba23ab344b..c8647f541b 100644 --- a/src/lib/orionld/dds/ddsConfigTopicToAttribute.cpp +++ b/src/lib/orionld/dds/ddsConfigTopicToAttribute.cpp @@ -56,7 +56,7 @@ char* ddsConfigTopicToAttribute(const char* topic, char** entityIdPP, char** ent if (ddsConfigTree == NULL) return NULL; // No error - it's OK to not have a DDS Config File - const char* path[3] = { "dds", "topics", NULL }; + const char* path[4] = { "dds", "ngsild", "topics", NULL }; static KjNode* topicsP = kjNavigate(ddsConfigTree, path, NULL, NULL); KjNode* topicP = kjLookup(topicsP, topic); diff --git a/src/lib/orionld/dds/ddsInit.cpp b/src/lib/orionld/dds/ddsInit.cpp index 4712ad451e..d800879064 100644 --- a/src/lib/orionld/dds/ddsInit.cpp +++ b/src/lib/orionld/dds/ddsInit.cpp @@ -35,7 +35,7 @@ extern "C" } #include "orionld/common/traceLevels.h" // kjTreeLog2 -#include "orionld/common/orionldState.h" // ddsEnablerConfigFile, ddsConfigFile +#include "orionld/common/orionldState.h" // configFile #include "orionld/kjTree/kjNavigate.h" // kjNavigate #include "orionld/dds/ddsConfigTopicToAttribute.h" // ddsConfigTopicToAttribute - for debugging only #include "orionld/dds/ddsCategoryToKlogSeverity.h" // ddsCategoryToKlogSeverity @@ -97,37 +97,35 @@ int ddsInit(Kjson* kjP, DdsOperationMode _ddsOpMode) // DDS Configuration File // errno = 0; - if ((ddsConfigFile[0] != 0) && (access(ddsConfigFile, R_OK) == 0)) - { - if (ddsConfigLoad(kjP, ddsConfigFile) != 0) - KT_X(1, "Error reading/parsing the DDS config file '%s'", ddsConfigFile); + if (ddsConfigLoad(kjP, configFileP) != 0) + KT_X(1, "Error reading/parsing the DDS config file '%s'", configFile); #if 0 - extern KjNode* ddsConfigTree; - kjTreeLog2(ddsConfigTree, "DDS Config", StDdsConfig); - KT_T(StDdsConfig, "Topics:"); - const char* path[3] = { "dds", "topics", NULL }; - KjNode* topics = kjNavigate(ddsConfigTree, path , NULL, NULL); + extern KjNode* ddsConfigTree; + kjTreeLog2(ddsConfigTree, "DDS Config", StDdsConfig); + KT_T(StDdsConfig, "Topics:"); + const char* path[4] = { "dds", "ngsild", "topics", NULL }; + KjNode* topics = kjNavigate(ddsConfigTree, path , NULL, NULL); - if (topics != NULL) + if (topics != NULL) + { + for (KjNode* topicP = topics->value.firstChildP; topicP != NULL; topicP = topicP->next) { - for (KjNode* topicP = topics->value.firstChildP; topicP != NULL; topicP = topicP->next) - { - char* entityId = (char*) "N/A"; - char* entityType = (char*) "N/A"; - char* attribute = ddsConfigTopicToAttribute(topicP->name, &entityId, &entityType); - - KT_T(StDdsConfig, "Topic: '%s':", topicP->name); - KT_T(StDdsConfig, " Attribute: '%s'", attribute); - KT_T(StDdsConfig, " Entity ID: '%s'", entityId); - KT_T(StDdsConfig, " Entity Type: '%s'", entityType); - } + char* entityId = (char*) "N/A"; + char* entityType = (char*) "N/A"; + char* attribute = ddsConfigTopicToAttribute(topicP->name, &entityId, &entityType); + + KT_T(StDdsConfig, "Topic: '%s':", topicP->name); + KT_T(StDdsConfig, " Attribute: '%s'", attribute); + KT_T(StDdsConfig, " Entity ID: '%s'", entityId); + KT_T(StDdsConfig, " Entity Type: '%s'", entityType); } -#endif } +#endif - KT_T(StDds, "Calling init_dds_enabler('%s')", ddsEnablerConfigFile); - eprosima::ddsenabler::init_dds_enabler(ddsEnablerConfigFile, ddsNotification, ddsTypeNotification, ddsLog); + KT_T(StDds, "Calling init_dds_enabler('%s')", configFile); + if (eprosima::ddsenabler::init_dds_enabler(configFile, ddsNotification, ddsTypeNotification, ddsLog) != 0) + KT_X(1, "Unable to initialize the DDS Enabler"); return 0; } diff --git a/test/functionalTest/cases/0000_cli/bool_option_with_value.test b/test/functionalTest/cases/0000_cli/bool_option_with_value.test index ea1932efc2..2207552b71 100644 --- a/test/functionalTest/cases/0000_cli/bool_option_with_value.test +++ b/test/functionalTest/cases/0000_cli/bool_option_with_value.test @@ -114,13 +114,12 @@ Usage: orionld [option '-U' (extended usage)] [option '-cSubCounters' ] [option '-distributed' (turn on distributed operation)] [option '-brokerId' ] + [option '-subordinateEndpoint' ] + [option '-pageSize' ] [option '-dds' (turn on DDS support)] [option '-ddsSubsTopics' ] [option '-ddsTopicType' ] - [option '-ddsConfigFile' ] - [option '-ddsEnablerConfigFile' ] - [option '-subordinateEndpoint' ] - [option '-pageSize' ] + [option '-configFile' ] [option '-duc' ] --TEARDOWN-- diff --git a/test/functionalTest/cases/0000_cli/command_line_options.test b/test/functionalTest/cases/0000_cli/command_line_options.test index 7ae36749ec..eabadca47c 100644 --- a/test/functionalTest/cases/0000_cli/command_line_options.test +++ b/test/functionalTest/cases/0000_cli/command_line_options.test @@ -103,13 +103,12 @@ Usage: orionld [option '-U' (extended usage)] [option '-cSubCounters' ] [option '-distributed' (turn on distributed operation)] [option '-brokerId' ] + [option '-subordinateEndpoint' ] + [option '-pageSize' ] [option '-dds' (turn on DDS support)] [option '-ddsSubsTopics' ] [option '-ddsTopicType' ] - [option '-ddsConfigFile' ] - [option '-ddsEnablerConfigFile' ] - [option '-subordinateEndpoint' ] - [option '-pageSize' ] + [option '-configFile' ] [option '-duc' ] --TEARDOWN-- diff --git a/test/functionalTest/cases/0000_dds/dds_notifications.test b/test/functionalTest/cases/0000_dds/dds_notifications.test index d822b45381..aaf60ddf36 100644 --- a/test/functionalTest/cases/0000_dds/dds_notifications.test +++ b/test/functionalTest/cases/0000_dds/dds_notifications.test @@ -24,25 +24,10 @@ the test client publishes on DDS, the broker receives DDS notifications and creates/updates the corresponding NGSI-LD entities --SHELL-INIT-- -echo '{ - "dds": { - "topics": { - "P1": { - "entityId": "urn:ngsi-ld:camera:cam1", - "entityType": "Camera", - "attribute": "shutterSpeed" - }, - "P2": { - "entityId": "urn:ngsi-ld:arm:arm1", - "entityType": "Arm", - "attribute": "armReach" - } - } - } -}' > /tmp/ddsConfig - +$REPO_HOME/scripts/configFile.sh "P1,Camera,urn:ngsi-ld:camera:cam1,shutterSpeed" "P2,Arm,urn:ngsi-ld:arm:arm1,armReach" > $HOME/.orionld +$REPO_HOME/scripts/configFile.sh "P1,Camera,urn:ngsi-ld:camera:cam1,shutterSpeed" "P2,Arm,urn:ngsi-ld:arm:arm1,armReach" > $HOME/.ftClient dbInit CB -orionldStart CB -mongocOnly -dds -ddsConfigFile /tmp/ddsConfig +orionldStart CB -mongocOnly -dds ftClientStart -t 0-5000 --SHELL-- diff --git a/test/functionalTest/cases/0000_ngsild/ngsild_ftClient_normal_notifications.test b/test/functionalTest/cases/0000_ngsild/ngsild_ftClient_normal_notifications.test index 8949d7409e..6f57359d63 100644 --- a/test/functionalTest/cases/0000_ngsild/ngsild_ftClient_normal_notifications.test +++ b/test/functionalTest/cases/0000_ngsild/ngsild_ftClient_normal_notifications.test @@ -26,6 +26,9 @@ Test of orionld version service, with branch name --SHELL-INIT-- dbInit CB orionldStart CB -mongocOnly +$REPO_HOME/scripts/configFile.sh > ~/.ftClient +chmod 777 ~/.ftClient + ftClientStart -v -t 200 mkdir -p /tmp/orion/logs/ftClient2 ftClientStart -v -t 200 --port $FT2_PORT --logDir $FT2_LOG_DIR diff --git a/test/functionalTest/ftClient/ftClient.cpp b/test/functionalTest/ftClient/ftClient.cpp index e3da18cac0..1101b162bc 100644 --- a/test/functionalTest/ftClient/ftClient.cpp +++ b/test/functionalTest/ftClient/ftClient.cpp @@ -74,7 +74,7 @@ unsigned int mhdTimeout; unsigned int mhdMaxConnections; bool distributed; long long inReqPayloadMaxSize = 64 * 1024; -char* ddsEnablerConfigFile = NULL; +char* configFile = NULL; @@ -92,6 +92,7 @@ KArg kargs[] = { "--logLevel", "-ll", KaString, &logLevel, KaOpt, 0, KA_NL, KA_NL, "log level (ERR|WARN|INFO|INFO|VERBOSE|TRACE|DEBUG" }, { "--logToScreen", "-ls", KaBool, &logToScreen, KaOpt, KFALSE, KA_NL, KA_NL, "log to screen" }, { "--fixme", "-fix", KaBool, &fixme, KaOpt, KFALSE, KA_NL, KA_NL, "FIXME messages" }, + { "--config", "-cfg", KaString, &configFile, KaOpt, NULL, KA_NL, KA_NL, "Config File" }, // // Broker options @@ -107,9 +108,6 @@ KArg kargs[] = { "--mhdTimeout", "-mtmo", KaUInt, &mhdTimeout, KaOpt, _i 2000, _i 0, KA_NL, "MHD connection timeout (in milliseconds)" }, { "--mhdConnections", "-mcon", KaUInt, &mhdMaxConnections, KaOpt, _i 512, _i 1, KA_NL, "Max number of MHD connections" }, - // DDS - { "--ddsConfig", "-ddscf", KaString, &ddsEnablerConfigFile, KaOpt, NULL, KA_NL, KA_NL, "DDS Enabler Config File" }, - KARGS_END }; @@ -252,6 +250,7 @@ int main(int argC, char* argV[]) { KArgsStatus ks; const char* progName = "ftClient"; + char configFilePath[256]; ks = kargsInit(progName, kargs, "FTCLIENT"); if (ks != KargsOk) @@ -267,6 +266,20 @@ int main(int argC, char* argV[]) exit(1); } + // Config file + if (configFile == NULL) + { + char* home = getenv("HOME"); + if (home != NULL) + { + snprintf(configFilePath, sizeof(configFilePath) - 1, "%s/.ftClient", home); + configFile = configFilePath; + } + } + + if (configFile != NULL) + configFile = strdup(configFile); + int kt = ktInit(progName, logDir, logToScreen, logLevel, traceLevels, kaBuiltinVerbose, kaBuiltinDebug, fixme); if (kt != 0) @@ -289,10 +302,8 @@ int main(int argC, char* argV[]) mhdInit(ldPort); - // temporary "hack" - if (ddsEnablerConfigFile == NULL) - ddsEnablerConfigFile = (char*) "/tmp/DDS_ENABLER_CONFIGURATION.yaml"; - eprosima::ddsenabler::init_dds_enabler(ddsEnablerConfigFile, ddsNotification, ddsTypeNotification, ddsLog); + if (eprosima::ddsenabler::init_dds_enabler(configFile, ddsNotification, ddsTypeNotification, ddsLog) != 0) + KT_X(1, "Unable to initialize the DDS Enabler"); while (1) { diff --git a/test/unittests/main_UnitTest.cpp b/test/unittests/main_UnitTest.cpp index f22e6c1e53..23f4ee4fba 100644 --- a/test/unittests/main_UnitTest.cpp +++ b/test/unittests/main_UnitTest.cpp @@ -118,6 +118,7 @@ char defaultUserContextUrl[256]; bool ddsSupport = false; char ddsSubsTopics[512]; char ddsTopicType[512]; +char configFile[512]; /* ****************************************************************************