From 548b1042d3199c052419c1223e83dac1b5291fd4 Mon Sep 17 00:00:00 2001 From: Jake Smith Date: Mon, 23 Oct 2023 14:31:40 +0100 Subject: [PATCH] HPCC-30628 Add initNullConfiguration for CLI's without configuration Call initNullConfiguration() in tools that have no configuration, allowing them to be used in k8s in circumstances where they previously failed when underlying common code called getComponentConfig or getGlobalConfig. Signed-off-by: Jake Smith --- dali/dalidiag/dalidiag.cpp | 2 ++ dali/dalistop/dalistop.cpp | 31 ++++++++++++++++++++----------- dali/sasha/sasha.cpp | 2 ++ system/jlib/jptree.cpp | 8 ++++++++ system/jlib/jptree.hpp | 1 + 5 files changed, 33 insertions(+), 11 deletions(-) diff --git a/dali/dalidiag/dalidiag.cpp b/dali/dalidiag/dalidiag.cpp index 9fc16b59607..da15a672539 100644 --- a/dali/dalidiag/dalidiag.cpp +++ b/dali/dalidiag/dalidiag.cpp @@ -532,6 +532,8 @@ int main(int _argc, char* argv[]) } try { + initNullConfiguration(); + Owned group = createIGroup(epa); assertex(group); initClientProcess(group, DCR_DaliDiag, 0, NULL, NULL, MP_WAIT_FOREVER); diff --git a/dali/dalistop/dalistop.cpp b/dali/dalistop/dalistop.cpp index 63eda00220c..e3c74a4823a 100644 --- a/dali/dalistop/dalistop.cpp +++ b/dali/dalistop/dalistop.cpp @@ -24,6 +24,13 @@ #include "daclient.hpp" +static void usage() +{ + printf("usage: dalistop [/nowait]\n"); + printf("eg: dalistop . -- stop dali server running locally\n"); + printf(" dalistop eq0001016 -- stop dali server running remotely\n"); +} + int main(int argc, const char* argv[]) { InitModuleObjects(); @@ -34,23 +41,25 @@ int main(int argc, const char* argv[]) const char *server = nullptr; if (argc<2) { - // with no args, use port from daliconfig if present (used by init scripts) - Owned daliConfigFile = createIFile("daliconf.xml"); - if (daliConfigFile->exists()) - { - Owned daliConfig = createPTree(*daliConfigFile, ipt_caseInsensitive); - port = daliConfig->getPropInt("@port", DALI_SERVER_PORT); - server = "."; - } + if (isContainerized()) + usage(); else { - printf("usage: dalistop [/nowait]\n"); - printf("eg: dalistop . -- stop dali server running locally\n"); - printf(" dalistop eq0001016 -- stop dali server running remotely\n"); + // with no args, use port from daliconfig if present (used by init scripts) + Owned daliConfigFile = createIFile("daliconf.xml"); + if (daliConfigFile->exists()) + { + Owned daliConfig = createPTree(*daliConfigFile, ipt_caseInsensitive); + port = daliConfig->getPropInt("@port", DALI_SERVER_PORT); + server = "."; + } + else + usage(); } } else { + initNullConfiguration(); server = argv[1]; port = DALI_SERVER_PORT; } diff --git a/dali/sasha/sasha.cpp b/dali/sasha/sasha.cpp index 3f7b02de1ce..920cdaf1385 100644 --- a/dali/sasha/sasha.cpp +++ b/dali/sasha/sasha.cpp @@ -406,6 +406,8 @@ int main(int argc, char* argv[]) EnableSEHtoExceptionMapping(); Thread::setDefaultStackSize(0x10000); try { + initNullConfiguration(); + startMPServer(0); attachStandardFileLogMsgMonitor("sasha.log", NULL, MSGFIELD_STANDARD, MSGAUD_all, MSGCLS_all, TopDetail, LOGFORMAT_table, true); queryStderrLogMsgHandler()->setMessageFields(MSGFIELD_prefix); diff --git a/system/jlib/jptree.cpp b/system/jlib/jptree.cpp index e4afee9e170..a6b2391d642 100644 --- a/system/jlib/jptree.cpp +++ b/system/jlib/jptree.cpp @@ -9099,6 +9099,14 @@ void replaceComponentConfig(IPropertyTree *newComponentConfig, IPropertyTree *ne executeConfigUpdaterCallbacks(); } +void initNullConfiguration() +{ + if (componentConfiguration || globalConfiguration) + throw makeStringException(99, "Configuration has already been initialised"); + componentConfiguration.setown(createPTree()); + globalConfiguration.setown(createPTree()); +} + class CYAMLBufferReader : public CInterfaceOf { protected: diff --git a/system/jlib/jptree.hpp b/system/jlib/jptree.hpp index 32885b51ffe..b3dc69c6fdd 100644 --- a/system/jlib/jptree.hpp +++ b/system/jlib/jptree.hpp @@ -320,6 +320,7 @@ jlib_decl IPropertyTree * loadArgsIntoConfiguration(IPropertyTree *config, const jlib_decl IPropertyTree * loadConfiguration(IPropertyTree * defaultConfig, const char * * argv, const char * componentTag, const char * envPrefix, const char * legacyFilename, IPropertyTree * (mapper)(IPropertyTree *), const char *altNameAttribute=nullptr, bool monitor=true); jlib_decl IPropertyTree * loadConfiguration(const char * defaultYaml, const char * * argv, const char * componentTag, const char * envPrefix, const char * legacyFilename, IPropertyTree * (mapper)(IPropertyTree *), const char *altNameAttribute=nullptr, bool monitor=true); jlib_decl void replaceComponentConfig(IPropertyTree *newComponentConfig, IPropertyTree *newGlobalConfig); +jlib_decl void initNullConfiguration(); jlib_decl IPropertyTree * getCostsConfiguration(); //The following can only be called after loadConfiguration has been called. All components must call loadConfiguration().