From e0da31b46cf3df192912e6514d7aa67d6545d010 Mon Sep 17 00:00:00 2001 From: wangkx Date: Mon, 6 Nov 2023 13:40:27 -0500 Subject: [PATCH] HPCC-30184 Expose WU "Process" meta info in WsWorkunits.WUInfo Revise based on review: 1. rename the getAllProcesses() to getProcessTypes(). 2. revise the code for querying process data from IPropertyTree. 3. set default values from ecm file. Signed-off-by: wangkx --- common/workunit/workunit.cpp | 9 ++++ common/workunit/workunit.hpp | 1 + common/workunit/workunit.ipp | 1 + esp/scm/ws_workunits.ecm | 2 +- esp/scm/ws_workunits_req_resp.ecm | 1 + esp/scm/ws_workunits_struct.ecm | 13 ++++++ .../ws_workunits/ws_workunitsHelpers.cpp | 46 +++++++++++++++++++ .../ws_workunits/ws_workunitsHelpers.hpp | 2 + .../ws_workunits/ws_workunitsService.cpp | 2 + 9 files changed, 76 insertions(+), 1 deletion(-) diff --git a/common/workunit/workunit.cpp b/common/workunit/workunit.cpp index 64f569e5284..0675947fb51 100644 --- a/common/workunit/workunit.cpp +++ b/common/workunit/workunit.cpp @@ -4423,6 +4423,8 @@ class CLockedWorkUnit : implements ILocalWorkUnit, implements IExtendedWUInterfa { return c->getHash(); } virtual IStringIterator *getLogs(const char *type, const char *instance) const { return c->getLogs(type, instance); } + virtual IPropertyTreeIterator *getProcessTypes() const + { return c->getProcessTypes(); } virtual IStringIterator *getProcesses(const char *type) const { return c->getProcesses(type); } virtual IPropertyTreeIterator* getProcesses(const char *type, const char *instance) const @@ -8616,6 +8618,13 @@ IStringIterator *CLocalWorkUnit::getLogs(const char *type, const char *instance) return new CStringPTreeAttrIterator(p->getElements(xpath.str()), "@log"); } +IPropertyTreeIterator* CLocalWorkUnit::getProcessTypes() const +{ + VStringBuffer xpath("Process/*"); + CriticalBlock block(crit); + return p->getElements(xpath.str()); +} + IPropertyTreeIterator* CLocalWorkUnit::getProcesses(const char *type, const char *instance) const { VStringBuffer xpath("Process/%s/", type); diff --git a/common/workunit/workunit.hpp b/common/workunit/workunit.hpp index 60c06b5a56d..02543eb5eba 100644 --- a/common/workunit/workunit.hpp +++ b/common/workunit/workunit.hpp @@ -1292,6 +1292,7 @@ interface IConstWorkUnit : extends IConstWorkUnitInfo virtual const IPropertyTree * getXmlParams() const = 0; virtual unsigned __int64 getHash() const = 0; virtual IStringIterator *getLogs(const char *type, const char *instance=NULL) const = 0; + virtual IPropertyTreeIterator *getProcessTypes() const = 0; virtual IStringIterator *getProcesses(const char *type) const = 0; virtual IPropertyTreeIterator* getProcesses(const char *type, const char *instance) const = 0; diff --git a/common/workunit/workunit.ipp b/common/workunit/workunit.ipp index 4f166ea67fb..d2d7156258d 100644 --- a/common/workunit/workunit.ipp +++ b/common/workunit/workunit.ipp @@ -267,6 +267,7 @@ public: virtual const IPropertyTree *getXmlParams() const; virtual unsigned __int64 getHash() const; virtual IStringIterator *getLogs(const char *type, const char *component) const; + virtual IPropertyTreeIterator *getProcessTypes() const; virtual IStringIterator *getProcesses(const char *type) const; virtual IPropertyTreeIterator* getProcesses(const char *type, const char *instance) const; virtual IStringVal & getSnapshot(IStringVal & str) const; diff --git a/esp/scm/ws_workunits.ecm b/esp/scm/ws_workunits.ecm index 03064b548f5..25edec054ed 100644 --- a/esp/scm/ws_workunits.ecm +++ b/esp/scm/ws_workunits.ecm @@ -25,7 +25,7 @@ EspInclude(ws_workunits_queryset_req_resp); ESPservice [ auth_feature("DEFERRED"), //This declares that the method logic handles feature level authorization - version("1.97"), default_client_version("1.97"), cache_group("ESPWsWUs"), + version("1.98"), default_client_version("1.98"), cache_group("ESPWsWUs"), noforms,exceptions_inline("./smc_xslt/exceptions.xslt"),use_method_name] WsWorkunits { ESPmethod [cache_seconds(60), resp_xsl_default("/esp/xslt/workunits.xslt")] WUQuery(WUQueryRequest, WUQueryResponse); diff --git a/esp/scm/ws_workunits_req_resp.ecm b/esp/scm/ws_workunits_req_resp.ecm index 0b8bbf28c8a..522dbc32f4d 100644 --- a/esp/scm/ws_workunits_req_resp.ecm +++ b/esp/scm/ws_workunits_req_resp.ecm @@ -357,6 +357,7 @@ ESPrequest WUInfoRequest [min_ver("1.66")] bool IncludeAllowedClusters(true); [min_ver("1.73")] bool IncludeTotalClusterTime(true); [min_ver("1.78")] bool IncludeServiceNames(false); + [min_ver("1.98")] bool IncludeProcesses(false); [min_ver("1.16")] bool SuppressResultSchemas(false); [min_ver("1.25")] string ThorSlaveIP; }; diff --git a/esp/scm/ws_workunits_struct.ecm b/esp/scm/ws_workunits_struct.ecm index fcad4bf90df..cf628ce31bc 100644 --- a/esp/scm/ws_workunits_struct.ecm +++ b/esp/scm/ws_workunits_struct.ecm @@ -339,6 +339,18 @@ ESPStruct [nil_remove] ThorLogInfo int NumberSlaves; }; +ESPStruct [nil_remove] ECLWUProcess +{ + string Name; + string Type; + string PodName; //containerized only + int InstanceNumber(1); //containerized only + string Log; //bare metal only + string PID; //bare metal only + string Pattern; //bare metal only + int Max(1); //bare metal only +}; + ESPStruct [nil_remove] ECLWorkunitLW { string Wuid; @@ -442,6 +454,7 @@ ESPStruct [nil_remove] ECLWorkunit [min_ver("1.85")] double FileAccessCost; [min_ver("1.87")] double CompileCost; [min_ver("1.91")] bool NoAccess(false); + [min_ver("1.98")] ESParray ECLWUProcessList; }; ESPStruct [nil_remove] WUECLAttribute diff --git a/esp/services/ws_workunits/ws_workunitsHelpers.cpp b/esp/services/ws_workunits/ws_workunitsHelpers.cpp index a4e91a67aa6..c0c3061432e 100644 --- a/esp/services/ws_workunits/ws_workunitsHelpers.cpp +++ b/esp/services/ws_workunits/ws_workunitsHelpers.cpp @@ -1210,6 +1210,50 @@ void WsWuInfo::getServiceNames(IEspECLWorkunit &info, unsigned long flags) info.setServiceNames(serviceNames); } +void WsWuInfo::getECLWUProcesses(IEspECLWorkunit &info, unsigned long flags) +{ + if (!(flags & WUINFO_IncludeProcesses)) + return; + + IArrayOf processList; + Owned processGroupItr = cw->getProcessTypes(); + ForEach(*processGroupItr) + { + IPropertyTree &processGroup = processGroupItr->query(); + const char *type = processGroup.queryName(); + + Owned processItr = processGroup.getElements("*"); + ForEach(*processItr) + { + IPropertyTree &process = processItr->query(); + Owned p = createECLWUProcess(); + p->setName(process.queryName()); + p->setType(type); + const char *podName = process.queryProp("@podName"); + if (!isEmptyString(podName)) + p->setPodName(podName); + unsigned instanceNum = process.getPropInt("@instanceNum", NotFound); + if (NotFound != instanceNum) + p->setInstanceNumber(instanceNum); + const char *pid = process.queryProp("@pid"); + if (!isEmptyString(pid)) + p->setPID(pid); + const char *log = process.queryProp("@log"); + if (!isEmptyString(log)) + p->setLog(log); + unsigned max = process.getPropInt("@max", NotFound); + if (NotFound != max) + p->setMax(max); + const char *pattern = process.queryProp("@pattern"); + if (!isEmptyString(pattern)) + p->setPattern(pattern); + + processList.append(*p.getClear()); + } + } + info.setECLWUProcessList(processList); +} + void WsWuInfo::getEventScheduleFlag(IEspECLWorkunit &info) { info.setEventSchedule(0); @@ -1371,6 +1415,8 @@ void WsWuInfo::getInfo(IEspECLWorkunit &info, unsigned long flags) getApplicationValues(info, flags); getWorkflow(info, flags); getServiceNames(info, flags); + if (version>=1.98) + getECLWUProcesses(info, flags); } #ifndef _CONTAINERIZED diff --git a/esp/services/ws_workunits/ws_workunitsHelpers.hpp b/esp/services/ws_workunits/ws_workunitsHelpers.hpp index 5305b0dec1a..16eca77c5b7 100644 --- a/esp/services/ws_workunits/ws_workunitsHelpers.hpp +++ b/esp/services/ws_workunits/ws_workunitsHelpers.hpp @@ -142,6 +142,7 @@ struct WsWUExceptions #define WUINFO_IncludeAllowedClusters 0x10000 #define WUINFO_IncludeTotalClusterTime 0x20000 #define WUINFO_IncludeServiceNames 0x40000 +#define WUINFO_IncludeProcesses 0x80000 #define WUINFO_All 0xFFFFFFFF static constexpr unsigned defaultMaxLogRecords = 10000; @@ -470,6 +471,7 @@ class WsWuInfo void getResult(IConstWUResult &r, IArrayOf& results, unsigned long flags); void getStats(const WuScopeFilter & filter, const StatisticsFilter& statsFilter, bool createDescriptions, IArrayOf& statistics); void getServiceNames(IEspECLWorkunit &info, unsigned long flags); + void getECLWUProcesses(IEspECLWorkunit &info, unsigned long flags); #ifndef _CONTAINERIZED void getWUProcessLogSpecs(const char* processName, const char* logSpec, const char* logDir, bool eclAgent, StringArray& logSpecs); diff --git a/esp/services/ws_workunits/ws_workunitsService.cpp b/esp/services/ws_workunits/ws_workunitsService.cpp index efd3b32d4e4..b912dc0caa9 100644 --- a/esp/services/ws_workunits/ws_workunitsService.cpp +++ b/esp/services/ws_workunits/ws_workunitsService.cpp @@ -1615,6 +1615,8 @@ bool CWsWorkunitsEx::onWUInfo(IEspContext &context, IEspWUInfoRequest &req, IEsp flags|=WUINFO_IncludeTotalClusterTime; if (req.getIncludeServiceNames()) flags|=WUINFO_IncludeServiceNames; + if (req.getIncludeProcesses()) + flags|=WUINFO_IncludeProcesses; PROGLOG("WUInfo: %s %lx", wuid.str(), flags);