Bladeren bron

HPCC-12591 Add new method WsWorkunits.WUGetStats

Return a regular SCM response

Signed-off-by: wangkx <kevin.wang@lexisnexis.com>
wangkx 10 jaren geleden
bovenliggende
commit
24625b9557

+ 38 - 0
esp/scm/ws_workunits.ecm

@@ -1571,6 +1571,43 @@ ESPresponse [exceptions_inline] WUCheckFeaturesResponse
     ESPStruct DeploymentFeatures Deployment;
 };
 
+ESPStruct [nil_remove] WUStatisticItem
+{
+    string Creator;
+    string CreatorType;
+    string Scope;
+    string ScopeType;
+    string Description;
+    string TimeStamp;
+    string Measure;
+    string Kind;
+    string Value;
+    unsigned RawValue;
+    unsigned Count;
+    unsigned Max;
+};
+
+ESPrequest [nil_remove] WUGetStatsRequest
+{
+    string WUID;
+    string CreatorType;
+    string Creator;
+    string ScopeType;
+    string Scope;
+    string Kind;
+    string Measure;
+    unsigned MinScopeDepth;
+    unsigned MaxScopeDepth;
+    boolean IncludeGraphs;
+    boolean CreateDescriptions;
+};
+
+ESPresponse [exceptions_inline] WUGetStatsResponse
+{
+    string WUID;
+    ESParray<ESPstruct WUStatisticItem> Statistics;
+};
+
 ESPservice [
     version("1.54"), default_client_version("1.54"),
     noforms,exceptions_inline("./smc_xslt/exceptions.xslt"),use_method_name] WsWorkunits
@@ -1647,6 +1684,7 @@ ESPservice [
     ESPmethod WUCreateZAPInfo(WUCreateZAPInfoRequest, WUCreateZAPInfoResponse);
     ESPmethod [resp_xsl_default("/esp/xslt/WUZAPInfoForm.xslt")] WUGetZAPInfo(WUGetZAPInfoRequest, WUGetZAPInfoResponse);
     ESPmethod WUCheckFeatures(WUCheckFeaturesRequest, WUCheckFeaturesResponse);
+    ESPmethod WUGetStats(WUGetStatsRequest, WUGetStatsResponse);
 };
 
 

+ 54 - 0
esp/services/ws_workunits/ws_workunitsHelpers.cpp

@@ -1623,6 +1623,60 @@ void WsWuInfo::getResults(IEspECLWorkunit &info, unsigned flags)
     }
 }
 
+void WsWuInfo::getStats(StatisticsFilter& filter, bool createDescriptions, IArrayOf<IEspWUStatisticItem>& statistics)
+{
+    Owned<IConstWUStatisticIterator> stats = &cw->getStatistics(&filter);
+    ForEach(*stats)
+    {
+        IConstWUStatistic & cur = stats->query();
+        StringBuffer xmlBuf, tsValue;
+        SCMStringBuffer curCreator, curScope, curDescription, curFormattedValue;
+
+        StatisticCreatorType curCreatorType = cur.getCreatorType();
+        StatisticScopeType curScopeType = cur.getScopeType();
+        StatisticMeasure curMeasure = cur.getMeasure();
+        StatisticKind curKind = cur.getKind();
+        unsigned __int64 value = cur.getValue();
+        unsigned __int64 count = cur.getCount();
+        unsigned __int64 max = cur.getMax();
+        unsigned __int64 ts = cur.getTimestamp();
+        cur.getCreator(curCreator);
+        cur.getScope(curScope);
+        cur.getDescription(curDescription, createDescriptions);
+        cur.getFormattedValue(curFormattedValue);
+
+        Owned<IEspWUStatisticItem> wuStatistic = createWUStatisticItem();
+
+        if (curCreatorType != SCTnone)
+            wuStatistic->setCreatorType(queryCreatorTypeName(curCreatorType));
+        if (curCreator.length())
+            wuStatistic->setCreator(curCreator.str());
+        if (curScopeType != SSTnone)
+            wuStatistic->setScopeType(queryScopeTypeName(curScopeType));
+        if (curScope.length())
+            wuStatistic->setScope(curScope.str());
+        if (curMeasure != SMeasureNone)
+            wuStatistic->setMeasure(queryMeasureName(curMeasure));
+        if (curKind != StKindNone)
+            wuStatistic->setKind(queryStatisticName(curKind));
+        wuStatistic->setRawValue(value);
+        wuStatistic->setValue(curFormattedValue.str());
+        if (count != 1)
+            wuStatistic->setCount(count);
+        if (max)
+            wuStatistic->setMax(max);
+        if (ts)
+        {
+            formatStatistic(tsValue, ts, SMeasureTimestampUs);
+            wuStatistic->setTimeStamp(tsValue.str());
+        }
+        if (curDescription.length())
+            wuStatistic->setDescription(curDescription.str());
+
+        statistics.append(*wuStatistic.getClear());
+    }
+}
+
 bool WsWuInfo::getFileSize(const char* fileName, const char* IPAddress, offset_t& fileSize)
 {
     if (!fileName || !*fileName)

+ 1 - 0
esp/services/ws_workunits/ws_workunitsHelpers.hpp

@@ -175,6 +175,7 @@ public:
     void getEclSchemaFields(IArrayOf<IEspECLSchemaItem>& schemas, IHqlExpression * expr, bool isConditional);
     bool getResultEclSchemas(IConstWUResult &r, IArrayOf<IEspECLSchemaItem>& schemas);
     void getResult(IConstWUResult &r, IArrayOf<IEspECLResult>& results, unsigned flags);
+    void getStats(StatisticsFilter& filter, bool createDescriptions, IArrayOf<IEspWUStatisticItem>& statistics);
 
     void getWorkunitEclAgentLog(const char* eclAgentInstance, const char* agentPid, MemoryBuffer& buf);
     void getWorkunitThorLog(const char *processName, MemoryBuffer& buf);

+ 49 - 0
esp/services/ws_workunits/ws_workunitsService.cpp

@@ -4250,3 +4250,52 @@ bool CWsWorkunitsEx::onWUCheckFeatures(IEspContext &context, IEspWUCheckFeatures
     resp.updateDeployment().setUseCompression(true);
     return true;
 }
+
+static const char * checkGetStatsInput(const char * s)
+{
+    //Supplying * on the command line is a pain because it needs quoting. Allow - instead.
+    if (!s || !*s)
+        return "*";
+    return s;
+}
+
+bool CWsWorkunitsEx::onWUGetStats(IEspContext &context, IEspWUGetStatsRequest &req, IEspWUGetStatsResponse &resp)
+{
+    try
+    {
+        StringBuffer wuid = req.getWUID();
+        WsWuHelpers::checkAndTrimWorkunit("WUInfo", wuid);
+
+        ensureWsWorkunitAccess(context, wuid.str(), SecAccess_Read);
+
+        const char* creatorType = checkGetStatsInput(req.getCreatorType());
+        const char* creator = checkGetStatsInput(req.getCreator());
+        const char* scopeType = checkGetStatsInput(req.getScopeType());
+        const char* scope = checkGetStatsInput(req.getScope());
+        const char* kind = checkGetStatsInput(req.getKind());
+        const char* measure = req.getMeasure();
+
+        StatisticsFilter filter(creatorType, creator, scopeType, scope, measure, kind);
+        if (!req.getMinScopeDepth_isNull() && !req.getMaxScopeDepth_isNull())
+            filter.setScopeDepth(req.getMinScopeDepth(), req.getMaxScopeDepth());
+        else if (!req.getMinScopeDepth_isNull())
+            filter.setScopeDepth(req.getMinScopeDepth());
+        if (!req.getIncludeGraphs_isNull())
+            filter.setMergeSources(req.getIncludeGraphs());
+
+        bool createDescriptions = false;
+        if (!req.getCreateDescriptions_isNull())
+            createDescriptions = req.getCreateDescriptions();
+
+        WsWuInfo winfo(context, wuid.str());
+        IArrayOf<IEspWUStatisticItem> statistics;
+        winfo.getStats(filter, createDescriptions, statistics);
+        resp.setStatistics(statistics);
+        resp.setWUID(wuid.str());
+    }
+    catch(IException* e)
+    {
+        FORWARDEXCEPTION(context, e,  ECLWATCH_INTERNAL_ERROR);
+    }
+    return true;
+}

+ 1 - 0
esp/services/ws_workunits/ws_workunitsService.hpp

@@ -254,6 +254,7 @@ public:
     bool onWUCreateZAPInfo(IEspContext &context, IEspWUCreateZAPInfoRequest &req, IEspWUCreateZAPInfoResponse &resp);
     bool onWUGetZAPInfo(IEspContext &context, IEspWUGetZAPInfoRequest &req, IEspWUGetZAPInfoResponse &resp);
     bool onWUCheckFeatures(IEspContext &context, IEspWUCheckFeaturesRequest &req, IEspWUCheckFeaturesResponse &resp);
+    bool onWUGetStats(IEspContext &context, IEspWUGetStatsRequest &req, IEspWUGetStatsResponse &resp);
 
 private:
     void addProcessLogfile(Owned<IConstWorkUnit> &cwu, WsWuInfo &winfo, const char * process, const char* path);