Browse Source

HPCC-24269 Add WsWorkunits.WUQueryDetailsLightWeight

Modify the WsWorkunits.WUQueryDetails to share the code
with new WsWorkunits.WUQueryDetailsLightWeight.

Signed-off-by: wangkx <kevin.wang@lexisnexis.com>
wangkx 5 years ago
parent
commit
9db721d07b

+ 1 - 0
esp/scm/ws_workunits.ecm

@@ -88,6 +88,7 @@ ESPservice [
     ESPmethod [cache_group("ESPWsWUQS"), cache_seconds(60), resp_xsl_default("/esp/xslt/WUQuerysets.xslt")] WUQuerysets(WUQuerysetsRequest, WUQuerysetsResponse);
     ESPmethod [cache_group("ESPWsWUQS"), cache_seconds(60), resp_xsl_default("/esp/xslt/WUQuerysetQueries.xslt")] WUQuerysetDetails(WUQuerySetDetailsRequest, WUQuerySetDetailsResponse);
     ESPmethod [cache_group("ESPWsWUQS"), cache_seconds(60), resp_xsl_default("/esp/xslt/WUQueryDetails.xslt")] WUQueryDetails(WUQueryDetailsRequest, WUQueryDetailsResponse);
+    ESPmethod [cache_group("ESPWsWUQS"), cache_seconds(60), min_ver("1.78")] WUQueryDetailsLightWeight(WUQueryDetailsLightWeightRequest, WUQueryDetailsResponse);
     ESPmethod [cache_seconds(60)] WUMultiQuerysetDetails(WUMultiQuerySetDetailsRequest, WUMultiQuerySetDetailsResponse);
     ESPmethod [clear_cache_group("ESPWsWUQS"), min_ver("1.71")] WUQuerysetImport(WUQuerysetImportRequest, WUQuerysetImportResponse);
     ESPmethod [cache_group("ESPWsWUQS"), min_ver("1.71")] WUQuerysetExport(WUQuerysetExportRequest, WUQuerysetExportResponse);

+ 14 - 0
esp/scm/ws_workunits_queryset_req_resp.ecm

@@ -248,6 +248,18 @@ ESPresponse [exceptions_inline] WUQueryFilesResponse
     ESParray<ESPstruct FileUsedByQuery, File> Files;
 };
 
+ESPrequest WUQueryDetailsLightWeightRequest
+{
+    string QueryId;
+    string QuerySet;
+    bool IncludeWUDetails(false);
+    bool IncludeWUQueryFiles(false);
+    bool IncludeSuperFiles(false);
+    bool IncludeWsEclAddresses(false);
+    bool IncludeStateOnClusters(false);
+    bool CheckAllNodes(false);
+};
+
 ESPrequest WUQueryDetailsRequest
 {
     string QueryId;
@@ -256,6 +268,8 @@ ESPrequest WUQueryDetailsRequest
     bool IncludeSuperFiles(false);
     bool IncludeWsEclAddresses(false);
     [min_ver("1.57")] bool CheckAllNodes(true);
+    [min_ver("1.78")] bool IncludeWUDetails(true);
+    [min_ver("1.78")] bool IncludeWUQueryFiles(true);
 };
 
 ESPresponse [exceptions_inline] WUQueryDetailsResponse

+ 118 - 61
esp/services/ws_workunits/ws_workunitsQuerySets.cpp

@@ -1937,32 +1937,41 @@ bool CWsWorkunitsEx::onWURecreateQuery(IEspContext &context, IEspWURecreateQuery
     return true;
 }
 
-
 bool CWsWorkunitsEx::onWUQueryDetails(IEspContext &context, IEspWUQueryDetailsRequest & req, IEspWUQueryDetailsResponse & resp)
 {
-    const char* querySet = req.getQuerySet();
-    const char* queryIdOrAlias = req.getQueryId();
-    bool  includeStateOnClusters = req.getIncludeStateOnClusters();
-    if (!querySet || !*querySet)
-        throw MakeStringException(ECLWATCH_QUERYSET_NOT_FOUND, "QuerySet not specified");
-    if (!queryIdOrAlias || !*queryIdOrAlias)
-        throw MakeStringException(ECLWATCH_QUERYID_NOT_FOUND, "QueryId not specified");
+    try
+    {
+        CWUQueryDetailsReq request(req);
+        getWUQueryDetails(context, request, resp);
+    }
+    catch(IException* e)
+    {
+        FORWARDEXCEPTION(context, e,  ECLWATCH_INTERNAL_ERROR);
+    }
+    return true;
+}
+
+void CWsWorkunitsEx::getWUQueryDetails(IEspContext &context, CWUQueryDetailsReq &req, IEspWUQueryDetailsResponse &resp)
+{
+    const char *querySet = req.getQuerySet();
+    if (isEmptyString(querySet))
+        throw makeStringException(ECLWATCH_QUERYSET_NOT_FOUND, "QuerySet not specified");
+    const char *queryIdOrAlias = req.getQueryIdOrAlias();
+    if (isEmptyString(queryIdOrAlias))
+        throw makeStringException(ECLWATCH_QUERYID_NOT_FOUND, "QueryId not specified");
 
     Owned<IPropertyTree> queryRegistry = getQueryRegistry(querySet, false);
     Owned<IPropertyTree> query = resolveQueryAlias(queryRegistry, queryIdOrAlias);
     if (!query)
-    {
-        DBGLOG("No matching Query");
-        throw MakeStringException(ECLWATCH_QUERYID_NOT_FOUND,"No matching query for given id or alias %s.", queryIdOrAlias);
-    }
+        throw makeStringExceptionV(ECLWATCH_QUERYID_NOT_FOUND, "No matching query for given id or alias %s.", queryIdOrAlias);
+
     const char* queryId = query->queryProp("@id");
     resp.setQueryId(queryId);
     resp.setQuerySet(querySet);
     PROGLOG("WUQueryDetails: QuerySet %s, query %s", querySet, queryId);
 
-    const char* queryName = query->queryProp("@name");
     const char* wuid = query->queryProp("@wuid");
-    resp.setQueryName(queryName);
+    resp.setQueryName(query->queryProp("@name"));
     resp.setWuid(wuid);
     resp.setDll(query->queryProp("@dll"));
     resp.setPublishedBy(query->queryProp("@publishedBy"));
@@ -1972,47 +1981,76 @@ bool CWsWorkunitsEx::onWUQueryDetails(IEspContext &context, IEspWUQueryDetailsRe
     double version = context.getClientVersion();
     if (version >= 1.46)
     {
-        Owned<IWorkUnitFactory> factory = getWorkUnitFactory(context.querySecManager(), context.queryUser());
-        Owned<IConstWorkUnit> cw = factory->openWorkUnit(wuid);
-        if(!cw)
-            throw MakeStringException(ECLWATCH_CANNOT_UPDATE_WORKUNIT,"Cannot open workunit %s.",wuid);
-        ensureWsWorkunitAccess(context, *cw, SecAccess_Read);
-
         if (query->hasProp("@priority"))
             resp.setPriority(getQueryPriorityName(query->getPropInt("@priority")));
         resp.setIsLibrary(query->getPropBool("@isLibrary"));
-        SCMStringBuffer s;
-        resp.setWUSnapShot(cw->getSnapshot(s).str()); //Label
 
-        stat_type whenCompiled;
-        if (cw->getStatistic(whenCompiled, "", StWhenCompiled))
-        {
-            formatStatistic(s.s.clear(), whenCompiled, StWhenCompiled);
-            resp.setCompileTime(s.str());
-        }
-
-        StringArray libUsed, graphIds;
-        Owned<IConstWULibraryIterator> libs = &cw->getLibraries();
-        ForEach(*libs)
-            libUsed.append(libs->query().getName(s).str());
-        if (libUsed.length())
-            resp.setLibrariesUsed(libUsed);
         if (version < 1.64)
         {
+            StringArray graphIds;
             unsigned numGraphIds = getGraphIdsByQueryId(querySet, queryId, graphIds);
             resp.setCountGraphs(numGraphIds);
             if (numGraphIds > 0)
                 resp.setGraphIds(graphIds);
         }
+
+        if (req.getIncludeWUDetails())
+        {
+            Owned<IWorkUnitFactory> factory = getWorkUnitFactory(context.querySecManager(), context.queryUser());
+            Owned<IConstWorkUnit> cw = factory->openWorkUnit(wuid);
+            if (!cw)
+                throw MakeStringException(ECLWATCH_CANNOT_UPDATE_WORKUNIT,"Cannot open workunit %s.",wuid);
+            ensureWsWorkunitAccess(context, *cw, SecAccess_Read);
+    
+            SCMStringBuffer s;
+            resp.setWUSnapShot(cw->getSnapshot(s).str()); //Label
+    
+            stat_type whenCompiled;
+            if (cw->getStatistic(whenCompiled, "", StWhenCompiled))
+            {
+                formatStatistic(s.s.clear(), whenCompiled, StWhenCompiled);
+                resp.setCompileTime(s.str());
+            }
+    
+            StringArray libUsed;
+            Owned<IConstWULibraryIterator> libs = &cw->getLibraries();
+            ForEach(*libs)
+                libUsed.append(libs->query().getName(s).str());
+            if (libUsed.length())
+                resp.setLibrariesUsed(libUsed);
+
+            if (version >= 1.50)
+            {
+                WsWuInfo winfo(context, cw);
+                resp.setResourceURLCount(winfo.getResourceURLCount());
+                if (version >= 1.64)
+                {
+                    IArrayOf<IEspECLTimer> timers;
+                    winfo.doGetTimers(timers); //Graph Duration
+                    if (timers.length())
+                        resp.setWUTimers(timers);
+
+                    IArrayOf<IEspECLGraph> graphs;
+                    winfo.doGetGraphs(graphs); //Graph Name, Label, Started, Finished, Type
+                    unsigned numGraphIds = graphs.length();
+                    resp.setCountGraphs(numGraphIds);
+                    if (numGraphIds > 0)
+                        resp.setWUGraphs(graphs);
+                }
+            }
+        }
     }
 
-    StringArray logicalFiles;
-    IArrayOf<IEspQuerySuperFile> superFiles;
-    getQueryFiles(context, wuid, queryId, querySet, logicalFiles, req.getIncludeSuperFiles() ? &superFiles : NULL);
-    if (logicalFiles.length())
-        resp.setLogicalFiles(logicalFiles);
-    if (superFiles.length())
-        resp.setSuperFiles(superFiles);
+    if (req.getIncludeWUQueryFiles())
+    {
+        StringArray logicalFiles;
+        IArrayOf<IEspQuerySuperFile> superFiles;
+        getQueryFiles(context, wuid, queryId, querySet, logicalFiles, req.getIncludeSuperFiles() ? &superFiles : nullptr);
+        if (logicalFiles.length())
+            resp.setLogicalFiles(logicalFiles);
+        if (superFiles.length())
+            resp.setSuperFiles(superFiles);
+    }
 
     if (version >= 1.42)
     {
@@ -2023,7 +2061,8 @@ bool CWsWorkunitsEx::onWUQueryDetails(IEspContext &context, IEspWUQueryDetailsRe
         else
             resp.setActivated(true);
     }
-    if (includeStateOnClusters && (version >= 1.43))
+    
+    if (req.getIncludeStateOnClusters() && (version >= 1.43))
     {
         StringArray queryIds;
         queryIds.append(queryId);
@@ -2036,25 +2075,7 @@ bool CWsWorkunitsEx::onWUQueryDetails(IEspContext &context, IEspWUQueryDetailsRe
             resp.setClusters(clusterStates);
         }
     }
-    if (version >= 1.50)
-    {
-        WsWuInfo winfo(context, wuid);
-        resp.setResourceURLCount(winfo.getResourceURLCount());
-        if (version >= 1.64)
-        {
-            IArrayOf<IEspECLTimer> timers;
-            winfo.doGetTimers(timers); //Graph Duration
-            if (timers.length())
-                resp.setWUTimers(timers);
 
-            IArrayOf<IEspECLGraph> graphs;
-            winfo.doGetGraphs(graphs); //Graph Name, Label, Started, Finished, Type
-            unsigned numGraphIds = graphs.length();
-            resp.setCountGraphs(numGraphIds);
-            if (numGraphIds > 0)
-                resp.setWUGraphs(graphs);
-        }
-    }
     if (req.getIncludeWsEclAddresses())
     {
         StringArray wseclAddresses;
@@ -2107,10 +2128,46 @@ bool CWsWorkunitsEx::onWUQueryDetails(IEspContext &context, IEspWUQueryDetailsRe
         }
         resp.setWsEclAddresses(wseclAddresses);
     }
+}
 
+bool CWsWorkunitsEx::onWUQueryDetailsLightWeight(IEspContext &context, IEspWUQueryDetailsLightWeightRequest & req, IEspWUQueryDetailsResponse & resp)
+{
+    try
+    {
+        CWUQueryDetailsReq request(req);
+        getWUQueryDetails(context, request, resp);
+    }
+    catch(IException* e)
+    {
+        FORWARDEXCEPTION(context, e,  ECLWATCH_INTERNAL_ERROR);
+    }
     return true;
 }
 
+CWUQueryDetailsReq::CWUQueryDetailsReq(IEspWUQueryDetailsRequest &req)
+{
+    querySet = req.getQuerySet();
+    queryIdOrAlias = req.getQueryId();
+    includeWUDetails = req.getIncludeWUDetails();
+    IncludeWUQueryFiles = req.getIncludeWUQueryFiles();
+    includeSuperFiles = req.getIncludeSuperFiles();
+    includeWsEclAddresses = req.getIncludeWsEclAddresses();
+    includeStateOnClusters = req.getIncludeStateOnClusters();
+    checkAllNodes = req.getCheckAllNodes();
+}
+
+CWUQueryDetailsReq::CWUQueryDetailsReq(IEspWUQueryDetailsLightWeightRequest &req)
+{
+    querySet = req.getQuerySet();
+    queryIdOrAlias = req.getQueryId();
+    includeWUDetails = req.getIncludeWUDetails();
+    IncludeWUQueryFiles = req.getIncludeWUQueryFiles();
+    includeSuperFiles = req.getIncludeSuperFiles();
+    includeWsEclAddresses = req.getIncludeWsEclAddresses();
+    includeStateOnClusters = req.getIncludeStateOnClusters();
+    checkAllNodes = req.getCheckAllNodes();
+}
+
 int EspQuerySuperFileCompareFunc(IInterface * const *i1, IInterface * const *i2)
 {
     if (!i1 || !*i1 || !i2 || !*i2)

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

@@ -177,6 +177,29 @@ struct WUShowScheduledFilters
         jobName(_jobName), eventName(_eventName), eventText(_eventText) {};
 };
 
+class CWUQueryDetailsReq
+{
+    StringAttr querySet, queryIdOrAlias;
+    bool includeWUDetails = false;
+    bool IncludeWUQueryFiles = false;
+    bool includeSuperFiles = false;
+    bool includeWsEclAddresses = false;
+    bool includeStateOnClusters = false;
+    bool checkAllNodes = false;
+public:
+    CWUQueryDetailsReq(IEspWUQueryDetailsRequest &req);
+    CWUQueryDetailsReq(IEspWUQueryDetailsLightWeightRequest &req);
+
+    const char *getQuerySet() const { return querySet.get(); }
+    const char *getQueryIdOrAlias() const { return queryIdOrAlias.get(); }
+    const bool getIncludeWUDetails() const { return includeWUDetails; }
+    const bool getIncludeWUQueryFiles() const { return IncludeWUQueryFiles; }
+    const bool getIncludeSuperFiles() const { return includeSuperFiles; }
+    const bool getIncludeWsEclAddresses() const { return includeWsEclAddresses; }
+    const bool getIncludeStateOnClusters() const { return includeStateOnClusters; }
+    const bool getCheckAllNodes() const { return checkAllNodes; }
+};
+
 class CWsWorkunitsEx : public CWsWorkunits
 {
 public:
@@ -223,6 +246,7 @@ public:
     bool onWUCopyQuerySet(IEspContext &context, IEspWUCopyQuerySetRequest &req, IEspWUCopyQuerySetResponse &resp);
     bool onWUCopyLogicalFiles(IEspContext &context, IEspWUCopyLogicalFilesRequest &req, IEspWUCopyLogicalFilesResponse &resp);
     bool onWUQueryDetails(IEspContext &context, IEspWUQueryDetailsRequest & req, IEspWUQueryDetailsResponse & resp);
+    bool onWUQueryDetailsLightWeight(IEspContext &context, IEspWUQueryDetailsLightWeightRequest & req, IEspWUQueryDetailsResponse & resp);
     bool onWUListQueries(IEspContext &context, IEspWUListQueriesRequest &req, IEspWUListQueriesResponse &resp);
     bool onWUListQueriesUsingFile(IEspContext &context, IEspWUListQueriesUsingFileRequest &req, IEspWUListQueriesUsingFileResponse &resp);
     bool onWUQueryFiles(IEspContext &context, IEspWUQueryFilesRequest &req, IEspWUQueryFilesResponse &resp);
@@ -369,6 +393,7 @@ private:
     IDistributedFile *lookupLogicalName(IEspContext &contcontext, const char *logicalName);
     void getSuspendedQueriesByCluster(MapStringTo<bool> &suspendedByCluster, const char *querySet, const char *queryID, bool checkAllNodes);
     void addSuspendedQueryIDs(MapStringTo<bool> &suspendedQueryIDs, IPropertyTree *queriesOnCluster, const char *target);
+    void getWUQueryDetails(IEspContext &context, CWUQueryDetailsReq &req, IEspWUQueryDetailsResponse &resp);
 
     unsigned awusCacheMinutes;
     StringBuffer queryDirectory;