Browse Source

HPCC-25989 Generate services globally so engines can pick up services

Change calls that access services for sasha, to pick up from
global config.

Signed-off-by: Jake Smith <jake.smith@lexisnexisrisk.com>
Jake Smith 4 years ago
parent
commit
fca98d164a

+ 2 - 0
common/thorhelper/CMakeLists.txt

@@ -81,6 +81,8 @@ set (    SRCS
          roxiehelper.ipp
          roxielmj.hpp
                  
+         hpccconfig.cpp
+         hpccconfig.hpp
     )
 
 include_directories ( 

+ 37 - 0
common/thorhelper/hpccconfig.cpp

@@ -0,0 +1,37 @@
+/*##############################################################################
+
+    HPCC SYSTEMS software Copyright (C) 2021 HPCC Systems®.
+
+    Licensed 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.
+############################################################################## */
+
+
+#include "jptree.hpp"
+#include "jstring.hpp"
+
+bool getService(StringBuffer &serviceAddress, const char *serviceName, bool failIfNotFound)
+{
+    if (!isEmptyString(serviceName))
+    {
+        VStringBuffer serviceQualifier("services[@type='%s']", serviceName);
+        Owned<IPropertyTree> serviceTree = getGlobalConfigSP()->getPropTree(serviceQualifier);
+        if (serviceTree)
+        {
+            serviceAddress.append(serviceTree->queryProp("@name")).append(':').append(serviceTree->queryProp("@port"));
+            return true;
+        }
+    }
+    if (failIfNotFound)
+        throw makeStringExceptionV(-1, "Service '%s' not found", serviceName);
+    return false;
+}

+ 30 - 0
common/thorhelper/hpccconfig.hpp

@@ -0,0 +1,30 @@
+/*##############################################################################
+
+    HPCC SYSTEMS software Copyright (C) 2021 HPCC Systems®.
+
+    Licensed 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.
+############################################################################## */
+
+#ifndef _HPCCCONFIG_HPP_
+#define _HPCCCONFIG_HPP_
+
+#ifdef THORHELPER_EXPORTS
+#define THORHELPER_API DECL_EXPORT
+#else
+#define THORHELPER_API DECL_IMPORT
+#endif
+
+extern THORHELPER_API bool getService(StringBuffer &serviceAddress, const char *serviceName, bool failIfNotFound);
+
+#endif // _HPCCCONFIG_HPP_
+

+ 1 - 1
esp/services/esdl_svc_engine/esdl_store.cpp

@@ -1247,7 +1247,7 @@ private:
     {
 #ifdef _CONTAINERIZED
         VStringBuffer xpath("services[@name='%s']", espprocname);
-        Owned<IPropertyTree> service = getComponentConfigSP()->getPropTree(xpath);
+        Owned<IPropertyTree> service = getGlobalConfigSP()->getPropTree(xpath);
         if (service)
         {
             const char *serviceType = service->queryProp("@type");

+ 2 - 2
esp/services/ws_ecl/ws_ecl_service.cpp

@@ -198,7 +198,7 @@ static void appendServerAddress(StringBuffer &s, IPropertyTree &env, IPropertyTr
 
 void initContainerRoxieTargets(MapStringToMyClass<ISmartSocketFactory> &connMap)
 {
-    Owned<IPropertyTreeIterator> services = getComponentConfigSP()->getElements("services[@type='roxie']");
+    Owned<IPropertyTreeIterator> services = getGlobalConfigSP()->getElements("services[@type='roxie']");
     ForEach(*services)
     {
         IPropertyTree &service = services->query();
@@ -374,7 +374,7 @@ static IStringIterator *getContainerTargetClusters()
         if (!isEmptyString(qName))
             ret->append_unique(qName);
     }
-    Owned<IPropertyTreeIterator> services = getComponentConfigSP()->getElements("services[@type='roxie']");
+    Owned<IPropertyTreeIterator> services = getGlobalConfigSP()->getElements("services[@type='roxie']");
     ForEach(*services)
     {
         IPropertyTree &service = services->query();

+ 1 - 1
esp/services/ws_fs/ws_fsService.cpp

@@ -762,7 +762,7 @@ bool CFileSprayEx::GetArchivedDFUWorkunits(IEspContext &context, IEspGetDFUWorku
     context.getUserID(user);
 
     SocketEndpoint ep;
-    getSashaServiceEP(ep, "sasha-dfuwu-archiver", true);
+    getSashaServiceEP(ep, "dfuwu-archiver", true);
     Owned<INode> sashaserver = createINode(ep);
 
     __int64 count=req.getPageSize();

+ 3 - 3
esp/services/ws_workunits/ws_workunitsService.cpp

@@ -112,7 +112,7 @@ void setActionResult(const char* wuid, CECLWUActions action, const char* result,
 IPropertyTree *getArchivedWorkUnitProperties(const char *wuid, bool dfuWU)
 {
     SocketEndpoint ep;
-    getSashaServiceEP(ep, "sasha-wu-archiver", true);
+    getSashaServiceEP(ep, "wu-archiver", true);
     Owned<INode> node = createINode(ep);
     if (!node)
         throw MakeStringException(ECLWATCH_INODE_NOT_FOUND, "INode not found.");
@@ -1541,7 +1541,7 @@ void getArchivedWUInfo(IEspContext &context, const char* sashaServerIP, unsigned
     if (sashaServerIP && *sashaServerIP)
         ep.set(sashaServerIP, sashaServerPort);
     else
-        getSashaServiceEP(ep, "sasha-wu-archiver", true);
+        getSashaServiceEP(ep, "wu-archiver", true);
 
     if (getWsWuInfoFromSasha(context, ep, wuid, &resp.updateWorkunit()))
     {
@@ -2441,7 +2441,7 @@ public:
         if (sashaServerIP && *sashaServerIP)
             ep.set(sashaServerIP, sashaServerPort);
         else
-            getSashaServiceEP(ep, "sasha-wu-archiver", true);
+            getSashaServiceEP(ep, "wu-archiver", true);
 
         Owned<INode> sashaserver = createINode(ep);
 

+ 1 - 1
esp/smc/SMCLib/TpCommon.cpp

@@ -82,7 +82,7 @@ extern TPWRAPPER_API IStringIterator* getContainerTargetClusters(const char* pro
     if (!isEmptyString(processType) && !strieq("roxie", processType))
         return ret.getClear();
 
-    Owned<IPropertyTreeIterator> services = getComponentConfigSP()->getElements("services[@type='roxie']");
+    Owned<IPropertyTreeIterator> services = getGlobalConfigSP()->getElements("services[@type='roxie']");
     ForEach(*services)
     {
         IPropertyTree& service = services->query();

+ 5 - 15
esp/smc/SMCLib/TpContainer.cpp

@@ -28,6 +28,7 @@
 #include "daqueue.hpp"
 #include "dautils.hpp"
 #include "dameta.hpp"
+#include "hpccconfig.hpp"
 
 static CConfigUpdateHook configUpdateHook;
 
@@ -494,7 +495,7 @@ void CTpWrapper::getAttPath(const char* Path,StringBuffer& returnStr)
 
 void CTpWrapper::getServices(double version, const char* serviceType, const char* serviceName, IArrayOf<IConstHPCCService>& services)
 {
-    Owned<IPropertyTreeIterator> itr = getComponentConfigSP()->getElements("services");
+    Owned<IPropertyTreeIterator> itr = getGlobalConfigSP()->getElements("services");
     ForEach(*itr)
     {
         IPropertyTree& service = itr->query();
@@ -689,7 +690,7 @@ extern TPWRAPPER_API IConstWUClusterInfo* getWUClusterInfoByName(const char* clu
 
 extern TPWRAPPER_API void initContainerRoxieTargets(MapStringToMyClass<ISmartSocketFactory>& connMap)
 {
-    Owned<IPropertyTreeIterator> services = getComponentConfigSP()->getElements("services[@type='roxie']");
+    Owned<IPropertyTreeIterator> services = getGlobalConfigSP()->getElements("services[@type='roxie']");
     ForEach(*services)
     {
         IPropertyTree& service = services->query();
@@ -761,21 +762,10 @@ extern TPWRAPPER_API void validateTargetName(const char* target)
         throw makeStringExceptionV(ECLWATCH_INVALID_CLUSTER_NAME, "Invalid target name: %s", target);
 }
 
+// NB: bare-metal has a different implementation in TpWrapper.cpp
 bool getSashaService(StringBuffer &serviceAddress, const char *serviceName, bool failIfNotFound)
 {
-    if (!isEmptyString(serviceName))
-    {
-        VStringBuffer serviceQualifier("services[@type='sasha'][@name='%s']", serviceName);
-        Owned<IPropertyTree> serviceTree = getComponentConfigSP()->getPropTree(serviceQualifier);
-        if (serviceTree)
-        {
-            serviceAddress.append(serviceName).append(':').append(serviceTree->queryProp("@port"));
-            return true;
-        }
-    }
-    if (failIfNotFound)
-        throw makeStringExceptionV(ECLWATCH_ARCHIVE_SERVER_NOT_FOUND, "Sasha '%s' server not found", serviceName);
-    return false;
+    return getService(serviceAddress, serviceName, failIfNotFound);
 }
 
 bool getSashaServiceEP(SocketEndpoint &serviceEndpoint, const char *service, bool failIfNotFound)

+ 2 - 2
esp/smc/SMCLib/TpWrapper.cpp

@@ -1898,7 +1898,7 @@ void CTpWrapper::getAttPath(const char* Path,StringBuffer& returnStr)
 
 void CTpWrapper::getServices(double version, const char* serviceType, const char* serviceName, IArrayOf<IConstHPCCService>& services)
 {
-    Owned<IPropertyTreeIterator> itr = getComponentConfigSP()->getElements("services");
+    Owned<IPropertyTreeIterator> itr = getGlobalConfigSP()->getElements("services");
     ForEach(*itr)
     {
         IPropertyTree& service = itr->query();
@@ -2089,7 +2089,7 @@ extern TPWRAPPER_API IConstWUClusterInfo* getWUClusterInfoByName(const char* clu
 
 extern TPWRAPPER_API void initContainerRoxieTargets(MapStringToMyClass<ISmartSocketFactory>& connMap)
 {
-    Owned<IPropertyTreeIterator> services = getComponentConfigSP()->getElements("services[@type='roxie']");
+    Owned<IPropertyTreeIterator> services = getGlobalConfigSP()->getElements("services[@type='roxie']");
     ForEach(*services)
     {
         IPropertyTree& service = services->query();

+ 8 - 6
helm/hpcc/templates/_helpers.tpl

@@ -80,10 +80,8 @@ singleNode: {{ .Values.global.singleNode | default false }}
 {{ if .Values.global.defaultEsp -}}
 defaultEsp: {{ .Values.global.defaultEsp | quote }}
 {{ end -}}
-{{ if hasPrefix "[]" (typeOf .Values.esp) -}}
-esp:
-{{ toYaml .Values.esp }}
-{{ end -}}
+services:
+{{ include "hpcc.generateConfigMapServices" . }}
 secretTimeout: {{ .Values.secrets.timeout | default 300 }}
 storage:
 {{- if hasKey $storage "hostGroups" }}
@@ -744,6 +742,7 @@ Generate list of available services
   {{- range $service := $roxie.services -}}
    {{- if ne (int $service.port) 0 -}}
 - name: {{ $service.name }}
+  class: roxie
   type: roxie
   port: {{ $service.port }}
   target: {{ $roxie.name }}
@@ -754,6 +753,7 @@ Generate list of available services
 {{- end -}}
 {{- range $esp := $.Values.esp -}}
 - name: {{ $esp.name }}
+  class: esp
   type: {{ $esp.application }}
   port: {{ $esp.servicePort }}
   {{- if hasKey $esp "tls" }}
@@ -770,7 +770,8 @@ Generate list of available services
 {{- $sasha := ($_sasha | default dict) -}}
 {{- if and (not $sasha.disabled) ($sasha.servicePort) -}}
 - name: {{ printf "sasha-%s" $sashaName }}
-  type: sasha
+  class: sasha
+  type: {{ $sashaName }}
   port: {{ $sasha.servicePort }}
 {{ end -}}
 {{ end -}}
@@ -782,7 +783,8 @@ Generate list of available services
 {{- $sasha := ($_sasha | default dict) -}}
 {{- if and (not $sasha.disabled) ($sasha.servicePort) -}}
 - name: {{ printf "sasha-%s" $sashaName }}
-  type: sasha
+  class: sasha
+  type: {{ $sashaName }}
   port: {{ $sasha.servicePort }}
 {{ end -}}
 {{ end -}}

+ 25 - 29
plugins/fileservices/fileservices.cpp

@@ -2903,50 +2903,46 @@ FILESERVICES_API void FILESERVICES_CALL fsDfuPlusExec(ICodeContext * ctx,const c
 FILESERVICES_API char * FILESERVICES_CALL fsGetEspURL(const char *username, const char *userPW)
 {
 #ifdef _CONTAINERIZED
-    Owned<IPropertyTree> compConfig = getComponentConfig();
-    const char *defaultEsp = compConfig->queryProp("@defaultEsp");
+    const IPropertyTree *match = nullptr;
+    const char *espService = getComponentConfigSP()->queryProp("@defaultEsp");
     Owned<IPropertyTree> globalConfig = getGlobalConfig();
-    if (isEmptyString(defaultEsp))
-        defaultEsp = globalConfig->queryProp("@defaultEsp");
-    if (isEmptyString(defaultEsp))
+    if (isEmptyString(espService))
+        espService = globalConfig->queryProp("@defaultEsp");
+    if (!isEmptyString(espService))
     {
-        Owned<IPropertyTreeIterator> esps = globalConfig->getElements("esp");
-        ForEach(*esps)
+        VStringBuffer service("services[@name='%s']", espService);
+        match = globalConfig->queryPropTree(service.str());
+    }
+    if (!match)
+    {
+        // Look for 'eclservices' esp service, fallback to 'eclwatch' service.
+        Owned<IPropertyTreeIterator> iter = globalConfig->getElements("services");
+        ForEach(*iter)
         {
-            const char *application = esps->query().queryProp("@application");
-            if (application)
+            const char *type = iter->query().queryProp("@type");
+            if (streq("eclservices", type))
             {
-                if (streq(application, "eclservices"))
-                {
-                    defaultEsp = esps->query().queryProp("@name");
-                    break;
-                }
-                else if (!defaultEsp && streq(application, "eclwatch"))
-                    defaultEsp = esps->query().queryProp("@name");
+                match = &iter->query();
+                break;
             }
+            else if (streq("eclwatch", type))
+                match = &iter->query();
         }
     }
-    if (!isEmptyString(defaultEsp))
+    if (match) // MORE - if not found, we could generate a warning - it implies something misconfigured!
     {
+        if (!espService)
+            espService = match->queryProp("@name");
         StringBuffer credentials;
         if (username && username[0] && userPW && userPW[0])
             credentials.setf("%s:%s@", username, userPW);
         else if (username && username[0])
             credentials.setf("%s@", username);
 
-        VStringBuffer espInfo("esp[@name='%s']", defaultEsp);
-        const char *protocol = "https";
-        unsigned port = 8010;
-        const IPropertyTree *espconfig = globalConfig->queryPropTree(espInfo);
-        if (espconfig)
-        {
-            if (!espconfig->getPropBool("@tls", true))
-                protocol = "http";
-            port = espconfig->getPropInt("@servicePort", port);
-        }
-        // MORE - if not found, we could generate a warning - it implies something misconfigured!
+        const char *protocol = match->getPropBool("@tls") ? "https" : "http";
+        unsigned port = match->getPropInt("@servicePort", 8010);
 
-        VStringBuffer espURL("mtls:%s://%s%s:%u", protocol, credentials.str(), defaultEsp, port);
+        VStringBuffer espURL("mtls:%s://%s%s:%u", protocol, credentials.str(), espService, port);
         return espURL.detach();
     }
 #else

+ 1 - 0
plugins/workunitservices/CMakeLists.txt

@@ -58,6 +58,7 @@ target_link_LIBRARies ( workunitservices
          remote 
          dalibase 
          workunit 
+         thorhelper
     )
 
 if (NOT CONTAINERIZED)

+ 8 - 4
plugins/workunitservices/workunitservices.cpp

@@ -54,6 +54,7 @@ Persists changed?
 #include "workunitservices.ipp"
 #include "environment.hpp"
 #include "seclib.hpp"
+#include "hpccconfig.hpp"
 
 #define WORKUNITSERVICES_VERSION "WORKUNITSERVICES 1.0.2"
 
@@ -178,10 +179,13 @@ namespace nsWorkunitservices {
 IPluginContext * parentCtx = NULL;
 
 
-static void getSashaNodes(SocketEndpointArray &epa)
+static void getSashaWUArchiveNodes(SocketEndpointArray &epa)
 {
 #ifdef _CONTAINERIZED
-    WARNLOG("CONTAINERIZED(getSashaNodes) not implemented");
+    StringBuffer service;
+    getService(service, "wu-archiver", true);
+    SocketEndpoint sashaep(service);
+    epa.append(sashaep);    
 #else
     Owned<IEnvironmentFactory> factory = getEnvironmentFactory(true);
     Owned<IConstEnvironment> env = factory->openEnvironment();
@@ -364,7 +368,7 @@ WORKUNITSERVICES_API void wsWorkunitList(
     MemoryBuffer mb;
     if (archived) {
         SocketEndpointArray sashaeps;
-        getSashaNodes(sashaeps);
+        getSashaWUArchiveNodes(sashaeps);
         ForEachItemIn(i,sashaeps) {
             Owned<ISashaCommand> cmd = createSashaCommand();    
             cmd->setAction(SCA_WORKUNIT_SERVICES_GET);                          
@@ -496,7 +500,7 @@ WORKUNITSERVICES_API bool wsWorkunitExists(ICodeContext *ctx, const char *wuid,
     if (archived)
     {
         SocketEndpointArray sashaeps;
-        getSashaNodes(sashaeps);
+        getSashaWUArchiveNodes(sashaeps);
         ForEachItemIn(i,sashaeps) {
             Owned<ISashaCommand> cmd = createSashaCommand();    
             cmd->setAction(SCA_LIST);