Prechádzať zdrojové kódy

Merge pull request #4456 from wangkx/h9304a

HPCC-9304 Add PID into Process/eclagent entries of ECL WU xml

Reviewed-By: Anthony Fishbeck <anthony.fishbeck@lexisnexis.com>
Reviewed-By: Richard Chapman <rchapman@hpccsystems.com>
Richard Chapman 12 rokov pred
rodič
commit
bacab1430b

+ 19 - 13
common/workunit/workunit.cpp

@@ -640,6 +640,7 @@ public:
     virtual unsigned __int64 getHash() const;
     virtual IStringIterator *getLogs(const char *type, const char *component) const;
     virtual IStringIterator *getProcesses(const char *type) const;
+    virtual IPropertyTreeIterator& getProcesses(const char *type, const char *instance) const;
 
     virtual bool getWuDate(unsigned & year, unsigned & month, unsigned& day);
     virtual IStringVal & getSnapshot(IStringVal & str) const;
@@ -682,7 +683,7 @@ public:
     IWUException *createException();
     void setTimeStamp(const char *name, const char *instance, const char *event);
     void addTimeStamp(const char * name, const char * instance, const char *event);
-    void addProcess(const char *type, const char *instance, const char *log);
+    void addProcess(const char *type, const char *instance, unsigned pid, const char *log);
     void setAction(WUAction action);
     void setApplicationValue(const char * application, const char * propname, const char * value, bool overwrite);
     void setApplicationValueInt(const char * application, const char * propname, int value, bool overwrite);
@@ -705,7 +706,6 @@ public:
     void setState(WUState state);
     void setStateEx(const char * text);
     void setAgentSession(__int64 sessionId);
-    void setAgentPID(unsigned pid);
     void setSecurityToken(const char *value);
     void setTimerInfo(const char * name, const char * instance, unsigned ms, unsigned count, unsigned __int64 max);
     void setTracingValue(const char * propname, const char * value);
@@ -1103,6 +1103,8 @@ public:
             { return c->getLogs(type, instance); }
     virtual IStringIterator *getProcesses(const char *type) const
             { return c->getProcesses(type); }
+    virtual IPropertyTreeIterator& getProcesses(const char *type, const char *instance) const
+            { return c->getProcesses(type, instance); }
 
     virtual void clearExceptions()
             { c->clearExceptions(); }
@@ -1114,8 +1116,8 @@ public:
             { c->setTimeStamp(name, instance, event); }
     virtual void addTimeStamp(const char * name, const char * instance, const char *event)
             { c->addTimeStamp(name, instance, event); }
-    virtual void addProcess(const char *type, const char *instance, const char *log)
-            { c->addProcess(type, instance, log); }
+    virtual void addProcess(const char *type, const char *instance, unsigned pid, const char *log)
+            { c->addProcess(type, instance, pid, log); }
     virtual void protect(bool protectMode)
             { c->protect(protectMode); }
     virtual void setBilled(bool billed)
@@ -1166,8 +1168,6 @@ public:
             { c->setStateEx(text); }
     virtual void setAgentSession(__int64 sessionId)
             { c->setAgentSession(sessionId); }
-    virtual void setAgentPID(unsigned pid)
-            { c->setAgentPID(pid); }
     virtual void setTimerInfo(const char * name, const char * instance, unsigned ms, unsigned count, unsigned __int64 max)
             { c->setTimerInfo(name, instance, ms, count, max); }
     virtual void setTracingValue(const char * propname, const char * value)
@@ -3663,12 +3663,6 @@ void CLocalWorkUnit::setAgentSession(__int64 sessionId)
     p->setPropInt64("@agentSession", sessionId);
 }
 
-void CLocalWorkUnit::setAgentPID(unsigned pid)
-{
-    CriticalBlock block(crit);
-    p->setPropInt("@agentPID", pid);
-}
-
 bool CLocalWorkUnit::aborting() const 
 {
     CriticalBlock block(crit);
@@ -4868,6 +4862,17 @@ IStringIterator *CLocalWorkUnit::getLogs(const char *type, const char *instance)
         return new CStringPTreeAttrIterator(p->getElements(xpath.str()), "@log");
 }
 
+IPropertyTreeIterator& CLocalWorkUnit::getProcesses(const char *type, const char *instance) const
+{
+    VStringBuffer xpath("Process/%s/", type);
+    if (instance)
+        xpath.append(instance);
+    else
+        xpath.append("*");
+    CriticalBlock block(crit);
+    return * p->getElements(xpath.str());
+}
+
 IStringIterator *CLocalWorkUnit::getProcesses(const char *type) const
 {
     VStringBuffer xpath("Process/%s/*", type);
@@ -4875,7 +4880,7 @@ IStringIterator *CLocalWorkUnit::getProcesses(const char *type) const
     return new CStringPTreeTagIterator(p->getElements(xpath.str()));
 }
 
-void CLocalWorkUnit::addProcess(const char *type, const char *instance, const char *log)
+void CLocalWorkUnit::addProcess(const char *type, const char *instance, unsigned pid, const char *log)
 {
     VStringBuffer processType("Process/%s", type);
     VStringBuffer xpath("%s/%s", processType.str(), instance);
@@ -4887,6 +4892,7 @@ void CLocalWorkUnit::addProcess(const char *type, const char *instance, const ch
         IPropertyTree *node = ensurePTree(p, processType.str());
         node = node->addPropTree(instance, createPTree());
         node->setProp("@log", log);
+        node->setPropInt("@pid", pid);
     }
 }
 

+ 2 - 2
common/workunit/workunit.hpp

@@ -923,6 +923,7 @@ interface IConstWorkUnit : extends IInterface
     virtual unsigned __int64 getHash() const = 0;
     virtual IStringIterator *getLogs(const char *type, const char *instance=NULL) const = 0;
     virtual IStringIterator *getProcesses(const char *type) const = 0;
+    virtual IPropertyTreeIterator& getProcesses(const char *type, const char *instance) const = 0;
 };
 
 
@@ -935,7 +936,7 @@ interface IWorkUnit : extends IConstWorkUnit
     virtual IWUException * createException() = 0;
     virtual void setTimeStamp(const char * name, const char * instance, const char * event) = 0;
     virtual void addTimeStamp(const char * name, const char * instance, const char * event) = 0;
-    virtual void addProcess(const char *type, const char *instance, const char *log=NULL) = 0;
+    virtual void addProcess(const char *type, const char *instance, unsigned pid, const char *log=NULL) = 0;
     virtual void setAction(WUAction action) = 0;
     virtual void setApplicationValue(const char * application, const char * propname, const char * value, bool overwrite) = 0;
     virtual void setApplicationValueInt(const char * application, const char * propname, int value, bool overwrite) = 0;
@@ -956,7 +957,6 @@ interface IWorkUnit : extends IConstWorkUnit
     virtual void setState(WUState state) = 0;
     virtual void setStateEx(const char * text) = 0;
     virtual void setAgentSession(__int64 sessionId) = 0;
-    virtual void setAgentPID(unsigned pid) = 0;
     virtual void setTimerInfo(const char * name, const char * instance, unsigned ms, unsigned count, unsigned __int64 max) = 0;
     virtual void setTracingValue(const char * propname, const char * value) = 0;
     virtual void setTracingValueInt(const char * propname, int value) = 0;

+ 1 - 2
ecl/eclagent/eclagent.cpp

@@ -1828,7 +1828,7 @@ void EclAgent::doProcess()
                 traceLevel = w->getDebugValueInt("traceLevel", 10);
             w->setTracingValue("EclAgentBuild", BUILD_TAG);
             if (agentTopology->hasProp("@name"))
-                w->addProcess("EclAgent", agentTopology->queryProp("@name"), logname.str());
+                w->addProcess("EclAgent", agentTopology->queryProp("@name"), GetCurrentProcessId(), logname.str());
 
             eclccCodeVersion = w->getCodeVersion();
             if (checkVersion && ((eclccCodeVersion > ACTIVITY_INTERFACE_VERSION) || (eclccCodeVersion < MIN_ACTIVITY_INTERFACE_VERSION)))
@@ -1837,7 +1837,6 @@ void EclAgent::doProcess()
                 throw MakeStringException(0, "Ecl agent started in 'no retry' mode for failed workunit, so failing");
             w->setState(WUStateRunning);
             w->addTimeStamp("EclAgent", GetCachedHostName(), "Started");
-            w->setAgentPID(GetCurrentProcessId());
             if (isRemoteWorkunit)
             {
                 w->setAgentSession(myProcessSession());

+ 1 - 1
ecl/eclagent/eclgraph.cpp

@@ -1690,7 +1690,7 @@ void EclAgent::updateWULogfile()
             rlf.getRemotePath(logname.clear());
 
             Owned <IWorkUnit> w = updateWorkUnit();
-            w->addProcess("EclAgent", config->queryProp("@name"), logname.str());
+            w->addProcess("EclAgent", config->queryProp("@name"), GetCurrentProcessId(), logname.str());
         }
         else
         {

+ 1 - 1
esp/eclwatch/ws_XSLT/wuidcommon.xslt

@@ -1286,7 +1286,7 @@
       </xsl:if>
       <xsl:if test="Type = 'EclAgentLog'">
         <td>
-          <a href="/WsWorkunits/WUFile/EclAgentLog?Wuid={$wuid}&amp;Name={Name}&amp;Type=EclAgentLog">
+          <a href="/WsWorkunits/WUFile/EclAgentLog?Wuid={$wuid}&amp;Name={Name}&amp;Process={PID}&amp;Type=EclAgentLog">
               eclagent.log: <xsl:value-of select="Name"/>
           </a>
         </td>

+ 1 - 0
esp/scm/ws_workunits.ecm

@@ -115,6 +115,7 @@ ESPStruct [nil_remove] ECLHelpFile
     [min_ver("1.32")] string IPAddress;
     [min_ver("1.32")] string Description;
     [min_ver("1.43")] int64 FileSize;
+    [min_ver("1.44")] unsigned PID(0);
 };
 
 //  ===========================================================================

+ 18 - 8
esp/services/ws_workunits/ws_workunitsHelpers.cpp

@@ -512,12 +512,12 @@ void WsWuInfo::getHelpers(IEspECLWorkunit &info, unsigned flags)
 
         if (cw->getWuidVersion() > 0)
         {
-            Owned<IStringIterator> eclAgentLogs = cw->getLogs("EclAgent");
-            ForEach (*eclAgentLogs)
+            IPropertyTreeIterator& eclAgents = cw->getProcesses("EclAgent", NULL);
+            ForEach (eclAgents)
             {
-                SCMStringBuffer logName;
-                eclAgentLogs->str(logName);
-                if (logName.length() < 1)
+                StringBuffer logName, agentPID;
+                eclAgents.query().getProp("@log",logName);
+                if (!logName.length())
                     continue;
 
                 Owned<IEspECLHelpFile> h= createECLHelpFile("","");
@@ -528,6 +528,13 @@ void WsWuInfo::getHelpers(IEspECLWorkunit &info, unsigned flags)
                     offset_t fileSize;
                     if (getFileSize(logName.str(), NULL, fileSize))
                         h->setFileSize(fileSize);
+                    if (version >= 1.44)
+                    {
+                        if (eclAgents.query().hasProp("@pid"))
+                            h->setPID(eclAgents.query().getPropInt("@pid"));
+                        else
+                            h->setPID(cw->getAgentPID());
+                    }
                 }
                 helpers.append(*h.getLink());
             }
@@ -1671,7 +1678,7 @@ void appendIOStreamContent(MemoryBuffer &mb, IFileIOStream *ios, bool forDownloa
     }
 }
 
-void WsWuInfo::getWorkunitEclAgentLog(const char* fileName, MemoryBuffer& buf)
+void WsWuInfo::getWorkunitEclAgentLog(const char* fileName, const char* agentPid, MemoryBuffer& buf)
 {
     if(!fileName || !*fileName)
         throw MakeStringException(ECLWATCH_ECLAGENT_LOG_NOT_FOUND,"Log file not specified");
@@ -1687,8 +1694,11 @@ void WsWuInfo::getWorkunitEclAgentLog(const char* fileName, MemoryBuffer& buf)
     bool eof = false;
     bool wuidFound = false;
 
-    unsigned pid = cw->getAgentPID();
-    VStringBuffer pidstr(" %5d ", pid);
+    StringBuffer pidstr;
+    if (agentPid && *agentPid)
+        pidstr.appendf(" %s ", agentPid);
+    else
+        pidstr.appendf(" %5d ", cw->getAgentPID());
     char const * pidchars = pidstr.str();
     while(!eof)
     {

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

@@ -168,7 +168,7 @@ public:
     bool getResultEclSchemas(IConstWUResult &r, IArrayOf<IEspECLSchemaItem>& schemas);
     void getResult(IConstWUResult &r, IArrayOf<IEspECLResult>& results, unsigned flags);
 
-    void getWorkunitEclAgentLog(const char* eclAgentInstance, MemoryBuffer& buf);
+    void getWorkunitEclAgentLog(const char* eclAgentInstance, const char* agentPid, MemoryBuffer& buf);
     void getWorkunitThorLog(const char *processName, MemoryBuffer& buf);
     void getWorkunitThorSlaveLog(const char *groupName, const char *ipAddress, const char* logDate, const char* logDir, int slaveNum, MemoryBuffer& buf, bool forDownload);
     void getWorkunitResTxt(MemoryBuffer& buf);

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

@@ -2681,7 +2681,7 @@ bool CWsWorkunitsEx::onWUFile(IEspContext &context,IEspWULogFileRequest &req, IE
             }
             else if (strieq(File_EclAgentLog,req.getType()))
             {
-                winfo.getWorkunitEclAgentLog(req.getName(), mb);
+                winfo.getWorkunitEclAgentLog(req.getName(), req.getProcess(), mb);
                 openSaveFile(context, opt, "eclagent.log", HTTP_TYPE_TEXT_PLAIN, mb, resp);
             }
             else if (strieq(File_XML,req.getType()) && notEmpty(req.getName()))

+ 1 - 1
thorlcr/master/thgraphmanager.cpp

@@ -171,7 +171,7 @@ void CJobManager::updateWorkUnitLog(IWorkUnit &workunit)
     StringBuffer log, logUrl;
     logHandler->getLogName(log);
     createUNCFilename(log, logUrl, false);
-    workunit.addProcess("Thor", globals->queryProp("@name"), logUrl.str());
+    workunit.addProcess("Thor", globals->queryProp("@name"), 0, logUrl.str());
 }