Ver código fonte

Merge pull request #8131 from wangkx/h14674

HPCC-14674 Read WU CreateTime/ModifyTime from Statistics

Reviewed-By: Gavin Halliday <gavin.halliday@lexisnexis.com>
Reviewed-By: Richard Chapman <rchapman@hpccsystems.com>
Richard Chapman 9 anos atrás
pai
commit
98021ffbb5
1 arquivos alterados com 55 adições e 5 exclusões
  1. 55 5
      plugins/workunitservices/workunitservices.ipp

+ 55 - 5
plugins/workunitservices/workunitservices.ipp

@@ -65,6 +65,42 @@ inline void varAppend(MemoryBuffer &mb,unsigned w,IPropertyTree &pt,const char *
     mb.append(sz).append(sz,s.str());
 }
 
+inline void convertTimestampToStr(unsigned __int64 timestamp, StringBuffer& timeStr, bool formatTZ)
+{
+    formatStatistic(timeStr, timestamp, SMeasureTimestampUs);
+    if (formatTZ)
+    {
+        timeStr.setCharAt(19, 'Z'); //Match with old timestamp
+        timeStr.setLength(20); //Match with old timestamp
+    }
+}
+
+inline const char* readCreateTime(IPropertyTree& pt, StringBuffer& time, bool formatTZ)
+{
+    time.clear();
+    unsigned __int64 value = pt.getPropInt64("Statistics/Statistic[@s='global'][@kind='WhenCreated']/@value", 0);
+    if (value > 0)
+        convertTimestampToStr(value, time, formatTZ);
+    return time.str();
+}
+
+inline const char* readModifyTime(IPropertyTree& pt, StringBuffer& time, bool formatTZ)
+{
+    time.clear();
+    unsigned __int64 value = 0;
+    Owned<IPropertyTreeIterator> stats = pt.getElements("Statistics/Statistic[@s='global'][@kind='WhenWorkunitModified']");
+    ForEach(*stats)
+    {
+        IPropertyTree& stat = stats->query();
+        unsigned __int64 val = stat.getPropInt64("@value", 0);
+        if (val > value)
+            value = val;
+    }
+    if (value > 0)
+        convertTimestampToStr(value, time, formatTZ);
+    return time.str();
+}
+
 inline bool serializeWUSrow(IPropertyTree &pt,MemoryBuffer &mb, bool isonline)
 {
     mb.setEndian(__LITTLE_ENDIAN);
@@ -78,13 +114,27 @@ inline bool serializeWUSrow(IPropertyTree &pt,MemoryBuffer &mb, bool isonline)
     short int prioritylevel = calcPriorityValue(&pt);
     mb.appendEndian(sizeof(prioritylevel), &prioritylevel);
 
-    const char *mod = "TimeStamps/TimeStamp[@application=\"workunit\"]/Modified";
-    const char *crt = "TimeStamps/TimeStamp[@application=\"workunit\"]/Created";
-    fixedAppend(mb,20,pt,crt);
-    if (pt.hasProp(mod))
-        fixedAppend(mb,20,pt,mod);
+    StringBuffer crtTime, modTime;
+    readModifyTime(pt, modTime, true);
+    readCreateTime(pt, crtTime, true);
+    if (crtTime.length())
+    {
+        fixedAppend(mb, 20, crtTime.str(), crtTime.length());
+        if (modTime.length())
+            fixedAppend(mb, 20, modTime.str(), modTime.length());
+        else
+            fixedAppend(mb, 20, crtTime.str(), crtTime.length());
+    }
     else
+    {
+        const char *mod = "TimeStamps/TimeStamp[@application=\"workunit\"]/Modified";
+        const char *crt = "TimeStamps/TimeStamp[@application=\"workunit\"]/Created";
         fixedAppend(mb,20,pt,crt);
+        if (pt.hasProp(mod))
+            fixedAppend(mb,20,pt,mod);
+        else
+            fixedAppend(mb,20,pt,crt);
+    }
     byte online = isonline?1:0;
     mb.append(online);
     byte prot = pt.getPropBool("@protected")?1:0;