workunit.hpp 77 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759
  1. /*##############################################################################
  2. HPCC SYSTEMS software Copyright (C) 2012 HPCC Systems®.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. ############################################################################## */
  13. #ifndef WORKUNIT_INCL
  14. #define WORKUNIT_INCL
  15. #ifdef WORKUNIT_EXPORTS
  16. #define WORKUNIT_API DECL_EXPORT
  17. #else
  18. #define WORKUNIT_API DECL_IMPORT
  19. #endif
  20. #define MINIMUM_SCHEDULE_PRIORITY 0
  21. #define DEFAULT_SCHEDULE_PRIORITY 50
  22. #define MAXIMUM_SCHEDULE_PRIORITY 100
  23. #include "jiface.hpp"
  24. #include "errorlist.h"
  25. #include "jtime.hpp"
  26. #include "jsocket.hpp"
  27. #include "jstats.h"
  28. #include "jutil.hpp"
  29. #include "jprop.hpp"
  30. #include "wuattr.hpp"
  31. #include <vector>
  32. #include <list>
  33. #include <utility>
  34. #include <string>
  35. #define LEGACY_GLOBAL_SCOPE "workunit"
  36. #define GLOBAL_SCOPE ""
  37. #define CHEAP_UCHAR_DEF
  38. #ifdef _WIN32
  39. typedef wchar_t UChar;
  40. #else //_WIN32
  41. typedef unsigned short UChar;
  42. #endif //_WIN32
  43. enum : unsigned
  44. {
  45. WUERR_ModifyFilterAfterFinalize = WORKUNIT_ERROR_START,
  46. WUERR_FinalizeAfterFinalize,
  47. };
  48. // error codes
  49. #define QUERRREG_ADD_NAMEDQUERY QUERYREGISTRY_ERROR_START
  50. #define QUERRREG_REMOVE_NAMEDQUERY QUERYREGISTRY_ERROR_START+1
  51. #define QUERRREG_WUID QUERYREGISTRY_ERROR_START+2
  52. #define QUERRREG_DLL QUERYREGISTRY_ERROR_START+3
  53. #define QUERRREG_SETALIAS QUERYREGISTRY_ERROR_START+4
  54. #define QUERRREG_RESOLVEALIAS QUERYREGISTRY_ERROR_START+5
  55. #define QUERRREG_REMOVEALIAS QUERYREGISTRY_ERROR_START+6
  56. #define QUERRREG_QUERY_REGISTRY QUERYREGISTRY_ERROR_START+7
  57. #define QUERRREG_SUSPEND QUERYREGISTRY_ERROR_START+8
  58. #define QUERRREG_UNSUSPEND QUERYREGISTRY_ERROR_START+9
  59. #define QUERRREG_COMMENT QUERYREGISTRY_ERROR_START+10
  60. class CDateTime;
  61. interface ISetToXmlTransformer;
  62. interface ISecManager;
  63. interface ISecUser;
  64. class StringArray;
  65. class StringBuffer;
  66. typedef unsigned __int64 __uint64;
  67. interface IQueueSwitcher : extends IInterface
  68. {
  69. virtual void * getQ(const char * qname, const char * wuid) = 0;
  70. virtual void putQ(const char * qname, const char * wuid, void * qitem) = 0;
  71. virtual bool isAuto() = 0;
  72. };
  73. //! PriorityClass
  74. //! Not sure what the real current class values are -- TBD
  75. enum WUPriorityClass
  76. {
  77. PriorityClassUnknown = 0,
  78. PriorityClassLow = 1,
  79. PriorityClassNormal = 2,
  80. PriorityClassHigh = 3,
  81. PriorityClassSize = 4
  82. };
  83. enum WUQueryType
  84. {
  85. QueryTypeUnknown = 0,
  86. QueryTypeEcl = 1,
  87. QueryTypeSql = 2,
  88. QueryTypeXml = 3,
  89. QueryTypeAttribute = 4,
  90. QueryTypeSize = 5
  91. };
  92. enum WUState
  93. {
  94. WUStateUnknown = 0,
  95. WUStateCompiled = 1,
  96. WUStateRunning = 2,
  97. WUStateCompleted = 3,
  98. WUStateFailed = 4,
  99. WUStateArchived = 5,
  100. WUStateAborting = 6,
  101. WUStateAborted = 7,
  102. WUStateBlocked = 8,
  103. WUStateSubmitted = 9,
  104. WUStateScheduled = 10,
  105. WUStateCompiling = 11,
  106. WUStateWait = 12,
  107. WUStateUploadingFiles = 13,
  108. WUStateDebugPaused = 14,
  109. WUStateDebugRunning = 15,
  110. WUStatePaused = 16,
  111. WUStateSize = 17
  112. };
  113. enum WUAction
  114. {
  115. WUActionUnknown = 0,
  116. WUActionCompile = 1,
  117. WUActionCheck = 2,
  118. WUActionRun = 3,
  119. WUActionExecuteExisting = 4,
  120. WUActionPause = 5,
  121. WUActionPauseNow = 6,
  122. WUActionResume = 7,
  123. WUActionSize = 8
  124. };
  125. enum WUResultStatus
  126. {
  127. ResultStatusUndefined = 0,
  128. ResultStatusCalculated = 1,
  129. ResultStatusSupplied = 2,
  130. ResultStatusFailed = 3,
  131. ResultStatusPartial = 4,
  132. ResultStatusSize = 5
  133. };
  134. //! IConstWUGraph
  135. enum WUGraphType
  136. {
  137. GraphTypeAny = 0,
  138. GraphTypeProgress = 1,
  139. GraphTypeEcl = 2,
  140. GraphTypeActivities = 3,
  141. GraphTypeSubProgress = 4,
  142. GraphTypeSize = 5
  143. };
  144. interface IConstWUGraphIterator;
  145. interface ICsvToRawTransformer;
  146. interface IXmlToRawTransformer;
  147. interface IPropertyTree;
  148. interface IPropertyTreeIterator;
  149. enum WUGraphState
  150. {
  151. WUGraphUnknown = 0,
  152. WUGraphComplete = 1,
  153. WUGraphRunning = 2,
  154. WUGraphFailed = 3,
  155. WUGraphPaused = 4
  156. };
  157. interface IConstWUGraphMeta : extends IInterface
  158. {
  159. virtual IStringVal & getName(IStringVal & ret) const = 0;
  160. virtual IStringVal & getLabel(IStringVal & ret) const = 0;
  161. virtual IStringVal & getTypeName(IStringVal & ret) const = 0;
  162. virtual WUGraphType getType() const = 0;
  163. virtual WUGraphState getState() const = 0;
  164. virtual unsigned getWfid() const = 0;
  165. };
  166. interface IConstWUGraph : extends IConstWUGraphMeta
  167. {
  168. virtual IStringVal & getXGMML(IStringVal & ret, bool mergeProgress) const = 0;
  169. virtual IPropertyTree * getXGMMLTree(bool mergeProgress) const = 0;
  170. virtual IPropertyTree * getXGMMLTreeRaw() const = 0;
  171. };
  172. interface IConstWUGraphIterator : extends IScmIterator
  173. {
  174. virtual IConstWUGraph & query() = 0;
  175. };
  176. interface IConstWUTimer : extends IInterface
  177. {
  178. virtual IStringVal & getName(IStringVal & ret) const = 0;
  179. virtual unsigned getCount() const = 0;
  180. virtual unsigned getDuration() const = 0;
  181. };
  182. interface IWUTimer : extends IConstWUTimer
  183. {
  184. virtual void setName(const char * str) = 0;
  185. virtual void setCount(unsigned c) = 0;
  186. virtual void setDuration(unsigned d) = 0;
  187. };
  188. interface IConstWUTimerIterator : extends IScmIterator
  189. {
  190. virtual IConstWUTimer & query() = 0;
  191. };
  192. interface IConstWUGraphMetaIterator : extends IScmIterator
  193. {
  194. virtual IConstWUGraphMeta & query() = 0;
  195. };
  196. constexpr int LibraryBaseSequence = 1000000000;
  197. //! IWUResult
  198. enum
  199. {
  200. ResultSequenceStored = -1,
  201. ResultSequencePersist = -2,
  202. ResultSequenceInternal = -3,
  203. ResultSequenceOnce = -4,
  204. };
  205. extern WORKUNIT_API bool isSpecialResultSequence(unsigned sequence);
  206. enum WUResultFormat
  207. {
  208. ResultFormatRaw = 0,
  209. ResultFormatXml = 1,
  210. ResultFormatXmlSet = 2,
  211. ResultFormatCsv = 3,
  212. ResultFormatSize = 4
  213. };
  214. interface ITypeInfo;
  215. interface IConstWUResult : extends IInterface
  216. {
  217. virtual WUResultStatus getResultStatus() const = 0;
  218. virtual IStringVal & getResultName(IStringVal & str) const = 0;
  219. virtual int getResultSequence() const = 0;
  220. virtual bool isResultScalar() const = 0;
  221. virtual IStringVal & getResultXml(IStringVal & str, bool hidePasswords) const = 0;
  222. virtual unsigned getResultFetchSize() const = 0;
  223. virtual __int64 getResultTotalRowCount() const = 0;
  224. virtual __int64 getResultRowCount() const = 0;
  225. virtual void getResultDataset(IStringVal & ecl, IStringVal & defs) const = 0;
  226. virtual IStringVal & getResultLogicalName(IStringVal & ecl) const = 0;
  227. virtual IStringVal & getResultKeyField(IStringVal & ecl) const = 0;
  228. virtual unsigned getResultRequestedRows() const = 0;
  229. virtual __int64 getResultInt() const = 0;
  230. virtual bool getResultBool() const = 0;
  231. virtual double getResultReal() const = 0;
  232. virtual IStringVal & getResultString(IStringVal & str, bool hidePasswords) const = 0;
  233. virtual IDataVal & getResultRaw(IDataVal & data, IXmlToRawTransformer * xmlTransformer, ICsvToRawTransformer * csvTransformer) const = 0;
  234. virtual IDataVal & getResultUnicode(IDataVal & data) const = 0;
  235. virtual IStringVal & getResultEclSchema(IStringVal & str) const = 0;
  236. virtual __int64 getResultRawSize(IXmlToRawTransformer * xmlTransformer, ICsvToRawTransformer * csvTransformer) const = 0;
  237. virtual IDataVal & getResultRaw(IDataVal & data, __int64 from, __int64 length, IXmlToRawTransformer * xmlTransformer, ICsvToRawTransformer * csvTransformer) const = 0;
  238. virtual IStringVal & getResultRecordSizeEntry(IStringVal & str) const = 0;
  239. virtual IStringVal & getResultTransformerEntry(IStringVal & str) const = 0;
  240. virtual __int64 getResultRowLimit() const = 0;
  241. virtual IStringVal & getResultFilename(IStringVal & str) const = 0;
  242. virtual WUResultFormat getResultFormat() const = 0;
  243. virtual unsigned getResultHash() const = 0;
  244. virtual void getResultDecimal(void * val, unsigned length, unsigned precision, bool isSigned) const = 0;
  245. virtual bool getResultIsAll() const = 0;
  246. virtual const IProperties *queryResultXmlns() = 0;
  247. virtual IStringVal &getResultFieldOpt(const char *name, IStringVal &str) const = 0;
  248. virtual void getSchema(IArrayOf<ITypeInfo> &types, StringAttrArray &names, IStringVal * eclText) const = 0;
  249. virtual void getResultWriteLocation(IStringVal & _graph, unsigned & _activityId) const = 0;
  250. };
  251. interface IWUResult : extends IConstWUResult
  252. {
  253. virtual void setResultStatus(WUResultStatus status) = 0;
  254. virtual void setResultName(const char * name) = 0;
  255. virtual void setResultSequence(unsigned seq) = 0;
  256. virtual void setResultSchemaRaw(unsigned len, const void * schema) = 0;
  257. virtual void setResultScalar(bool isScalar) = 0;
  258. virtual void setResultRaw(unsigned len, const void * data, WUResultFormat format) = 0;
  259. virtual void setResultFetchSize(unsigned rows) = 0;
  260. virtual void setResultTotalRowCount(__int64 rows) = 0;
  261. virtual void setResultRowCount(__int64 rows) = 0;
  262. virtual void setResultDataset(const char * ecl, const char * defs) = 0;
  263. virtual void setResultLogicalName(const char * logicalName) = 0;
  264. virtual void setResultKeyField(const char * name) = 0;
  265. virtual void setResultRequestedRows(unsigned rowcount) = 0;
  266. virtual void setResultInt(__int64 val) = 0;
  267. virtual void setResultBool(bool val) = 0;
  268. virtual void setResultReal(double val) = 0;
  269. virtual void setResultString(const char * val, unsigned length) = 0;
  270. virtual void setResultData(const void * val, unsigned length) = 0;
  271. virtual void setResultDecimal(const void * val, unsigned length) = 0;
  272. virtual void addResultRaw(unsigned len, const void * data, WUResultFormat format) = 0;
  273. virtual void setResultRecordSizeEntry(const char * val) = 0;
  274. virtual void setResultTransformerEntry(const char * val) = 0;
  275. virtual void setResultRowLimit(__int64 value) = 0;
  276. virtual void setResultFilename(const char * name) = 0;
  277. virtual void setResultUnicode(const void * val, unsigned length) = 0;
  278. virtual void setResultUInt(__uint64 val) = 0;
  279. virtual void setResultIsAll(bool value) = 0;
  280. virtual void setResultFormat(WUResultFormat format) = 0;
  281. virtual void setResultXML(const char * xml) = 0;
  282. virtual void setResultRow(unsigned len, const void * data) = 0;
  283. virtual void setResultXmlns(const char *prefix, const char *uri) = 0;
  284. virtual void setResultFieldOpt(const char *name, const char *value)=0;
  285. virtual void setResultWriteLocation(const char * _graph, unsigned _activityId) = 0;
  286. virtual IPropertyTree *queryPTree() = 0;
  287. };
  288. interface IConstWUResultIterator : extends IScmIterator
  289. {
  290. virtual IConstWUResult & query() = 0;
  291. };
  292. //! IWUQuery
  293. enum WUFileType
  294. {
  295. FileTypeCpp = 0,
  296. FileTypeDll = 1,
  297. FileTypeResText = 2,
  298. FileTypeHintXml = 3,
  299. FileTypeXml = 4,
  300. FileTypeLog = 5,
  301. FileTypeSize = 6
  302. };
  303. interface IConstWUAssociatedFile : extends IInterface
  304. {
  305. virtual WUFileType getType() const = 0;
  306. virtual IStringVal & getDescription(IStringVal & ret) const = 0;
  307. virtual IStringVal & getIp(IStringVal & ret) const = 0;
  308. virtual IStringVal & getName(IStringVal & ret) const = 0;
  309. virtual IStringVal & getNameTail(IStringVal & ret) const = 0;
  310. virtual unsigned getCrc() const = 0;
  311. virtual unsigned getMinActivityId() const = 0;
  312. virtual unsigned getMaxActivityId() const = 0;
  313. };
  314. interface IConstWUAssociatedFileIterator : extends IScmIterator
  315. {
  316. virtual IConstWUAssociatedFile & query() = 0;
  317. };
  318. interface IConstWUFieldUsage : extends IInterface // Defines a file (dataset or index) that contains used fields from queries
  319. {
  320. virtual const char * queryName() const = 0;
  321. };
  322. interface IConstWUFieldUsageIterator : extends IScmIterator // Iterates over files that contains used fields
  323. {
  324. virtual IConstWUFieldUsage * get() const = 0;
  325. };
  326. interface IConstWUFileUsage : extends IInterface // Defines a file (dataset or index) that contains used fields from queries
  327. {
  328. virtual const char * queryName() const = 0;
  329. virtual const char * queryType() const = 0; // used file type: "dataset" or "index"
  330. virtual unsigned getNumFields() const = 0;
  331. virtual unsigned getNumFieldsUsed() const = 0;
  332. virtual IConstWUFieldUsageIterator * getFields() const = 0;
  333. };
  334. interface IConstWUFileUsageIterator : extends IScmIterator // Iterates over files that contains used fields
  335. {
  336. virtual IConstWUFileUsage * get() const = 0;
  337. };
  338. interface IConstWUQuery : extends IInterface
  339. {
  340. virtual WUQueryType getQueryType() const = 0;
  341. virtual IStringVal & getQueryText(IStringVal & str) const = 0;
  342. virtual IStringVal & getQueryName(IStringVal & str) const = 0;
  343. virtual IStringVal & getQueryDllName(IStringVal & str) const = 0;
  344. virtual unsigned getQueryDllCrc() const = 0;
  345. virtual IStringVal & getQueryCppName(IStringVal & str) const = 0;
  346. virtual IStringVal & getQueryResTxtName(IStringVal & str) const = 0;
  347. virtual IConstWUAssociatedFile * getAssociatedFile(WUFileType type, unsigned index) const = 0;
  348. virtual IConstWUAssociatedFileIterator & getAssociatedFiles() const = 0;
  349. virtual IStringVal & getQueryShortText(IStringVal & str) const = 0;
  350. virtual IStringVal & getQueryMainDefinition(IStringVal & str) const = 0;
  351. virtual bool isArchive() const = 0;
  352. virtual bool hasArchive() const = 0;
  353. };
  354. interface IWUQuery : extends IConstWUQuery
  355. {
  356. virtual void setQueryType(WUQueryType qt) = 0;
  357. virtual void setQueryText(const char * pstr) = 0;
  358. virtual void setQueryName(const char * pstr) = 0;
  359. virtual void addAssociatedFile(WUFileType type, const char * name, const char * ip, const char * desc, unsigned crc, unsigned minActivity, unsigned maxActivity) = 0;
  360. virtual void removeAssociatedFiles() = 0;
  361. virtual void setQueryMainDefinition(const char * str) = 0;
  362. virtual void removeAssociatedFile(WUFileType type, const char * name, const char * desc) = 0;
  363. };
  364. interface IConstWUWebServicesInfo : extends IInterface
  365. {
  366. virtual IStringVal & getModuleName(IStringVal & str) const = 0;
  367. virtual IStringVal & getAttributeName(IStringVal & str) const = 0;
  368. virtual IStringVal & getDefaultName(IStringVal & str) const = 0;
  369. virtual IStringVal & getInfo(const char * name, IStringVal & str) const = 0;
  370. virtual unsigned getWebServicesCRC() const = 0;
  371. virtual IStringVal & getText(const char * name, IStringVal & str) const = 0;
  372. };
  373. interface IWUWebServicesInfo : extends IConstWUWebServicesInfo
  374. {
  375. virtual void setModuleName(const char * pstr) = 0;
  376. virtual void setAttributeName(const char * pstr) = 0;
  377. virtual void setDefaultName(const char * pstr) = 0;
  378. virtual void setInfo(const char * name, const char * info) = 0;
  379. virtual void setWebServicesCRC(unsigned crc) = 0;
  380. virtual void setText(const char * name, const char * text) = 0;
  381. };
  382. //! IWUPlugin
  383. interface IConstWUPlugin : extends IInterface
  384. {
  385. virtual IStringVal & getPluginName(IStringVal & str) const = 0;
  386. virtual IStringVal & getPluginVersion(IStringVal & str) const = 0;
  387. };
  388. interface IWUPlugin : extends IConstWUPlugin
  389. {
  390. virtual void setPluginName(const char * str) = 0;
  391. virtual void setPluginVersion(const char * str) = 0;
  392. };
  393. interface IConstWUPluginIterator : extends IScmIterator
  394. {
  395. virtual IConstWUPlugin & query() = 0;
  396. };
  397. interface IConstWULibrary : extends IInterface
  398. {
  399. virtual IStringVal & getName(IStringVal & str) const = 0;
  400. };
  401. interface IWULibrary : extends IConstWULibrary
  402. {
  403. virtual void setName(const char * str) = 0;
  404. };
  405. interface IConstWULibraryIterator : extends IScmIterator
  406. {
  407. virtual IConstWULibrary & query() = 0;
  408. };
  409. //! IWUException
  410. interface IConstWUException : extends IInterface
  411. {
  412. virtual IStringVal & getExceptionSource(IStringVal & str) const = 0;
  413. virtual IStringVal & getExceptionMessage(IStringVal & str) const = 0;
  414. virtual unsigned getExceptionCode() const = 0;
  415. virtual ErrorSeverity getSeverity() const = 0;
  416. virtual IStringVal & getTimeStamp(IStringVal & dt) const = 0;
  417. virtual IStringVal & getExceptionFileName(IStringVal & str) const = 0;
  418. virtual unsigned getExceptionLineNo() const = 0;
  419. virtual unsigned getExceptionColumn() const = 0;
  420. virtual unsigned getSequence() const = 0;
  421. virtual unsigned getActivityId() const = 0;
  422. virtual const char * queryScope() const = 0;
  423. virtual unsigned getPriority() const = 0; // For ordering within a severity - e.g. warnings about inefficiency
  424. };
  425. interface IWUException : extends IConstWUException
  426. {
  427. virtual void setExceptionSource(const char * str) = 0;
  428. virtual void setExceptionMessage(const char * str) = 0;
  429. virtual void setExceptionCode(unsigned code) = 0;
  430. virtual void setSeverity(ErrorSeverity level) = 0;
  431. virtual void setTimeStamp(const char * dt) = 0;
  432. virtual void setExceptionFileName(const char * str) = 0;
  433. virtual void setExceptionLineNo(unsigned r) = 0;
  434. virtual void setExceptionColumn(unsigned c) = 0;
  435. virtual void setActivityId(unsigned _id) = 0;
  436. virtual void setScope(const char * _scope) = 0;
  437. virtual void setPriority(unsigned _priority) = 0;
  438. };
  439. interface IConstWUExceptionIterator : extends IScmIterator
  440. {
  441. virtual IConstWUException & query() = 0;
  442. };
  443. // This enumeration is currently duplicated in workunit.hpp and environment.hpp. They must stay in sync.
  444. #ifndef ENGINE_CLUSTER_TYPE
  445. #define ENGINE_CLUSTER_TYPE
  446. enum ClusterType { NoCluster, HThorCluster, RoxieCluster, ThorLCRCluster };
  447. #endif
  448. extern WORKUNIT_API ClusterType getClusterType(const char * platform, ClusterType dft = NoCluster);
  449. extern WORKUNIT_API const char *clusterTypeString(ClusterType clusterType, bool lcrSensitive);
  450. inline bool isThorCluster(ClusterType type) { return (type == ThorLCRCluster); }
  451. //! IWorkflowItem
  452. enum WFType
  453. {
  454. WFTypeNormal = 0,
  455. WFTypeSuccess = 1,
  456. WFTypeFailure = 2,
  457. WFTypeRecovery = 3,
  458. WFTypeWait = 4,
  459. WFTypeSize = 5
  460. };
  461. enum WFMode
  462. {
  463. WFModeNormal = 0,
  464. WFModeCondition = 1,
  465. WFModeSequential = 2,
  466. WFModeParallel = 3,
  467. WFModePersist = 4,
  468. WFModeBeginWait = 5,
  469. WFModeWait = 6,
  470. WFModeOnce = 7,
  471. WFModeUnused = 8,
  472. WFModeCritical = 9,
  473. WFModeOrdered = 10,
  474. WFModeConditionExpression = 11,
  475. //Size needs to be the last mode
  476. WFModeSize = 12
  477. };
  478. enum WFState
  479. {
  480. WFStateNull = 0,
  481. WFStateReqd = 1,
  482. WFStateDone = 2,
  483. WFStateFail = 3,
  484. WFStateSkip = 4,
  485. WFStateWait = 5,
  486. WFStateBlocked = 6,
  487. WFStateSize = 7
  488. };
  489. interface IWorkflowDependencyIterator : extends IScmIterator
  490. {
  491. virtual unsigned query() const = 0;
  492. };
  493. interface IWorkflowEvent : extends IInterface
  494. {
  495. virtual const char * queryName() const = 0;
  496. virtual const char * queryText() const = 0;
  497. virtual bool matches(const char * name, const char * text) const = 0;
  498. };
  499. interface IConstWorkflowItem : extends IInterface
  500. {
  501. virtual unsigned queryWfid() const = 0;
  502. virtual bool isScheduled() const = 0;
  503. virtual bool isScheduledNow() const = 0;
  504. virtual IWorkflowEvent * getScheduleEvent() const = 0;
  505. virtual unsigned querySchedulePriority() const = 0;
  506. virtual bool hasScheduleCount() const = 0;
  507. virtual unsigned queryScheduleCount() const = 0;
  508. virtual IWorkflowDependencyIterator * getDependencies() const = 0;
  509. virtual WFType queryType() const = 0;
  510. virtual WFMode queryMode() const = 0;
  511. virtual unsigned querySuccess() const = 0;
  512. virtual unsigned queryFailure() const = 0;
  513. virtual unsigned queryRecovery() const = 0;
  514. virtual unsigned queryRetriesAllowed() const = 0;
  515. virtual unsigned queryContingencyFor() const = 0;
  516. virtual IStringVal & getPersistName(IStringVal & val) const = 0;
  517. virtual unsigned queryPersistWfid() const = 0;
  518. virtual int queryPersistCopies() const = 0; // 0 - unmangled name, < 0 - use default, > 0 - max number
  519. virtual bool queryPersistRefresh() const = 0;
  520. virtual IStringVal &getCriticalName(IStringVal & val) const = 0;
  521. virtual unsigned queryScheduleCountRemaining() const = 0;
  522. virtual WFState queryState() const = 0;
  523. virtual unsigned queryRetriesRemaining() const = 0;
  524. virtual int queryFailCode() const = 0;
  525. virtual const char * queryFailMessage() const = 0;
  526. virtual const char * queryEventName() const = 0;
  527. virtual const char * queryEventExtra() const = 0;
  528. virtual unsigned queryScheduledWfid() const = 0;
  529. virtual IStringVal & queryCluster(IStringVal & val) const = 0;
  530. virtual IStringVal & getLabel(IStringVal & val) const = 0;
  531. };
  532. inline bool isPersist(const IConstWorkflowItem & item) { return item.queryMode() == WFModePersist; }
  533. inline bool isCritical(const IConstWorkflowItem & item) { return item.queryMode() == WFModeCritical; }
  534. interface IRuntimeWorkflowItem : extends IConstWorkflowItem
  535. {
  536. virtual void setState(WFState state) = 0;
  537. virtual bool testAndDecRetries() = 0;
  538. virtual bool decAndTestScheduleCountRemaining() = 0;
  539. virtual void setFailInfo(int code, const char * message) = 0;
  540. virtual void reset() = 0;
  541. virtual void setEvent(const char * name, const char * extra) = 0;
  542. virtual void incScheduleCount() = 0;
  543. };
  544. interface IWorkflowItem : extends IRuntimeWorkflowItem
  545. {
  546. virtual void setScheduledNow() = 0;
  547. virtual void setScheduledOn(const char * name, const char * text) = 0;
  548. virtual void setSchedulePriority(unsigned priority) = 0;
  549. virtual void setScheduleCount(unsigned count) = 0;
  550. virtual void addDependency(unsigned wfid) = 0;
  551. virtual void setPersistInfo(const char * name, unsigned wfid, int maxCopies, bool refresh) = 0;
  552. virtual void setCriticalInfo(char const * name) = 0;
  553. virtual void syncRuntimeData(const IConstWorkflowItem & other) = 0;
  554. virtual void setScheduledWfid(unsigned wfid) = 0;
  555. virtual void setCluster(const char * cluster) = 0;
  556. virtual void setLabel(const char * label) = 0;
  557. };
  558. interface IConstWorkflowItemIterator : extends IScmIterator
  559. {
  560. virtual IConstWorkflowItem * query() const = 0;
  561. };
  562. interface IRuntimeWorkflowItemIterator : extends IConstWorkflowItemIterator
  563. {
  564. virtual IRuntimeWorkflowItem * get() const = 0;
  565. };
  566. interface IWorkflowItemIterator : extends IConstWorkflowItemIterator
  567. {
  568. virtual IWorkflowItem * get() const = 0;
  569. };
  570. interface IWorkflowItemArray : extends IInterface
  571. {
  572. virtual IRuntimeWorkflowItem & queryWfid(unsigned wfid) = 0;
  573. virtual unsigned count() const = 0;
  574. virtual IRuntimeWorkflowItemIterator * getSequenceIterator() = 0;
  575. virtual void addClone(const IConstWorkflowItem * other) = 0;
  576. virtual bool hasScheduling() const = 0;
  577. };
  578. enum LocalFileUploadType
  579. {
  580. UploadTypeFileSpray = 0,
  581. UploadTypeWUResult = 1,
  582. UploadTypeWUResultCsv = 2,
  583. UploadTypeWUResultXml = 3,
  584. UploadTypeSize = 4
  585. };
  586. interface IConstLocalFileUpload : extends IInterface
  587. {
  588. virtual unsigned queryID() const = 0;
  589. virtual LocalFileUploadType queryType() const = 0;
  590. virtual IStringVal & getSource(IStringVal & ret) const = 0;
  591. virtual IStringVal & getDestination(IStringVal & ret) const = 0;
  592. virtual IStringVal & getEventTag(IStringVal & ret) const = 0;
  593. };
  594. interface IConstLocalFileUploadIterator : extends IScmIterator
  595. {
  596. virtual IConstLocalFileUpload * get() = 0;
  597. };
  598. enum WUSubscribeOptions
  599. {
  600. SubscribeOptionState = 1,
  601. SubscribeOptionAbort = 2,
  602. SubscribeOptionAction = 4
  603. };
  604. interface IWorkUnitSubscriber
  605. {
  606. virtual void notify(WUSubscribeOptions flags, unsigned valueLen, const void *valueData) = 0;
  607. };
  608. interface IWorkUnitWatcher : extends IInterface
  609. {
  610. virtual void unsubscribe() = 0;
  611. };
  612. interface IWUGraphProgress;
  613. interface IPropertyTree;
  614. enum WUFileKind
  615. {
  616. WUFileStandard = 0,
  617. WUFileTemporary = 1,
  618. WUFileOwned = 2,
  619. WUFileJobOwned = 3
  620. };
  621. typedef unsigned __int64 WUGraphIDType;
  622. typedef unsigned __int64 WUNodeIDType;
  623. interface IWUGraphProgress;
  624. interface IWUGraphStats;
  625. interface IPropertyTree;
  626. interface IConstWUGraphProgress : extends IInterface
  627. {
  628. virtual IPropertyTree * getProgressTree() = 0;
  629. virtual unsigned queryFormatVersion() = 0;
  630. };
  631. interface IWUGraphStats : public IInterface
  632. {
  633. virtual IStatisticGatherer & queryStatsBuilder() = 0;
  634. };
  635. interface IConstWUTimeStamp : extends IInterface
  636. {
  637. virtual IStringVal & getApplication(IStringVal & str) const = 0;
  638. virtual IStringVal & getEvent(IStringVal & str) const = 0;
  639. virtual IStringVal & getDate(IStringVal & dt) const = 0;
  640. };
  641. interface IConstWUTimeStampIterator : extends IScmIterator
  642. {
  643. virtual IConstWUTimeStamp & query() = 0;
  644. };
  645. interface IConstWUAppValue : extends IInterface
  646. {
  647. virtual const char *queryApplication() const = 0;
  648. virtual const char *queryName() const = 0;
  649. virtual const char *queryValue() const = 0;
  650. };
  651. interface IConstWUAppValueIterator : extends IScmIterator
  652. {
  653. virtual IConstWUAppValue & query() = 0;
  654. };
  655. //More: Counts on files? optional target?
  656. /*
  657. * Statistics are used to store timestamps, time periods, counts memory usage and any other interesting statistic
  658. * which is collected as the query is built or executed.
  659. *
  660. * Each statistic has the following details:
  661. *
  662. * Creator - Which component created the statistic. This should be the name of the component instance i.e., "mythor_x_y" rather than the type ("thor").
  663. * - It can also be used to represent a subcomponent e.g., mythor:0 the master, mythor:10 means the 10th slave.
  664. * ?? Is the sub component always numeric ??
  665. *
  666. * Kind - The specific kind of the statistic - uses a global enumeration. (Engines can locally use different ranges of numbers and map them to the global enumeration).
  667. *
  668. * Measure - What kind of statistic is it? It can always be derived from the kind. The following values are supported:
  669. * time - elapsed time in nanoseconds
  670. * timestamp/when - a point in time (?to the nanosecond?)
  671. * count - a count of the number of occurrences
  672. * memory/size - a quantity of memory (or disk) measured in kb
  673. * load - measure of cpu activity (stored as 1/1000000 core)
  674. * skew - a measure of skew. 10000 = perfectly balanced, range [0..infinity]
  675. *
  676. *Optional:
  677. *
  678. * Description - Purely for display, calculated if not explicitly supplied.
  679. * Scope - Where in the execution of the task is statistic gathered? It can have multiple levels (separated by colons), and statistics for
  680. * a given level can be retrieved independently. The following scopes are supported:
  681. * "global" - the default if not specified. Globally/within a workunit.
  682. * "wfid<n>" - within workflow item <n> (is this at all useful?)
  683. * "graphn[:sg<n>[:ac<n>"]"
  684. * Possibly additional levels to allow multiple instances of an activity when used in a graph etc.
  685. *
  686. * Target - The target of the thing being monitored. E.g., a filename. ?? Is this needed? Should this be combined with scope??
  687. *
  688. * Examples:
  689. * creator(mythor),scope(),kind(TimeWall) total time spend processing in thor search ct(thor),scope(),kind(TimeWall)
  690. * creator(mythor),scope(graph1),kind(TimeWall) - total time spent processing a graph
  691. * creator(mythor),scope(graph1:sg<subid>),kind(TimeElapsed) - total time spent processing a subgraph
  692. * creator(mythor),scope(graph1:sg<n>:ac<id>),kind(TimeElapsed) - time for activity from start to stop
  693. * creator(mythor),scope(graph1:sg<n>:ac<id>),kind(TimeLocal) - time spent locally processing
  694. * creator(mythor),scope(graph1:sg<n>:ac<id>),kind(TimeWallRowRange) - time from first row to last row
  695. * creator(mythor),scope(graph1:sg<n>:ac<id>),kind(WhenFirstRow) - timestamp for first row
  696. * creator(myeclccserver@myip),scope(compile),kind(TimeWall)
  697. * creator(myeclccserver@myip),scope(compile:transform),kind(TimeWall)
  698. * creator(myeclccserver@myip),scope(compile:transform:fold),kind(TimeWall)
  699. *
  700. * Other possibilities
  701. * creator(myesp),scope(filefile::abc::def),kind(NumAccesses)
  702. *
  703. * Configuring statistic collection:
  704. * - Each engine allows the statistics being collected to be specified. You need to configure the area (time/memory/disk/), the level of detail by component and location.
  705. *
  706. * Some background notes:
  707. * - Start time and end time (time processing first and last record) is useful for detecting time skew/serial activities.
  708. * - Information is lost if you only show final skew, rather than skew over time, but storing time series data is
  709. * prohibitive so we may need to create some derived metrics.
  710. * - The engines need options to control what information is gathered.
  711. * - Need to ensure clocks are synchronized for the timestamps to be useful.
  712. *
  713. * Some typical analysis we want to perform:
  714. * - Activities that show significant skew between first (or last) record times between nodes.
  715. * - Activities where the majority of the time is being spent.
  716. *
  717. * Filtering statistics - with control over who is creating it, what is being recorded, and
  718. * [in order of importance]
  719. * - which level of creator you are interested in [summary or individual nodes, or both] (*;*:*)?
  720. * - which level of scope (interested in activities, or just by graph, or both)
  721. * - a particular kind of statistic
  722. * - A particular creator (including fixed/wildcarded sub-component)
  723. *
  724. * => Provide a class for representing a filter, which can be used to filter when recording and retrieving. Start simple and then extend.
  725. * Text representation creator(*,*:*),creatordepth(n),creatorkind(x),scopedepth(n),scopekind(xxx,yyy),scope(*:23),kind(x).
  726. *
  727. * Examples
  728. * kind(TimeElapsed),scopetype(subgraph) - subgraph timings
  729. * kind(Time*),scopedepth(1)&kind(TimeElapsed),scopedepth(2),scopetype(subgraph) - all legacy global timings.
  730. * creatortype(thor),kind(TimeElapsed),scope("") - how much time has been spent on thor? (Need to sum?)
  731. * creator(mythor),kind(TimeElapsed),scope("") - how much time has been spent on *this* thor.
  732. * kind(TimeElapsed),scope("compiled") - how much time has been spent on *this* thor.
  733. *
  734. * Need to efficiently
  735. * - Get all (simple) stats for a graph/activities (creator(*),kind(*),scope(x:*)) - display in graph, finding hotspots
  736. * - Get all stats for an activity (creator(*:*),measure(*:*),scope(x:y)) - providing details in a graph
  737. * - Merge stats from multiple components
  738. * - Merge stats from multiple runs?
  739. *
  740. * Bulk updates will tend to be for a given component and should only need minor processing (e.g. patch ids) or no processing to update/combine.
  741. * - You need to be able to filter only a certain level of statistic - e.g., times for transforms, but not details of those transforms.
  742. *
  743. * => suggest store as
  744. * stats[creatorDepth,scopeDepth][creator] { kind, scope, value, target }. sorted by (scope, target, kind)
  745. * - allows high level filtering by level
  746. * - allows combining with minor updates.
  747. * - possibly extra structure within each creator - maybe depending on the level of the scope
  748. * - need to be sub-sorted to allow efficient merging between creators (e.g. for calculating skew)
  749. * - possibly different structure when collecting [e.g., indexed by stat, or using a local stat mapping ] and storing.
  750. *
  751. * Use (local) tables to map scope->uid. Possibly implicitly defined on first occurrence, or zip the entire structure.
  752. *
  753. * The progress information should be stored compressed, with min,max child ids to avoid decompressing
  754. */
  755. // Should the statistics classes be able to be stored globally e.g., for esp and other non workunit contexts?
  756. /*
  757. * Work out how to represent all of the existing statistics
  758. *
  759. * Counts of number of skips on an index: kind(CountIndexSkips),measure(count),scope(workunit | filename | graph:activity#)
  760. * Activity start time kind(WhenStart),measure(timestamp),scope(graph:activity#),creator(mythor)
  761. * kind(WhenFirstRow),measure(timestamp),scope(graph:activity#),creator(mythor:slave#)
  762. * Number of times files accessed by esp: kind(CountFileAccess),measure(count),scope(),target(filename);
  763. * Elapsed/remaining time for sprays:
  764. */
  765. /*
  766. * Statistics and their kinds - prefixed indicates their type. Note generally the same type won't be reused for two different things.
  767. *
  768. * TimeStamps:
  769. * StWhenGraphStart - When a graph starts
  770. * StWhenFirstRow - When the first row is processed by slave activity
  771. *
  772. * Time
  773. * StTimeParseQuery
  774. * StTimeTransformQuery
  775. * StTimeTransformQuery_Fold - transformquery:fold? effectively an extra level of detail on the kind.
  776. * StTimeTransformQuery_Normalize
  777. * StTimeElapsedExecuting - Elapsed wall time between first row and last row.
  778. * StTimeExecuting - Cpu time spent executing
  779. *
  780. *
  781. * Memory
  782. * StSizeGeneratedCpp
  783. * StSizePeakMemory
  784. *
  785. * Count
  786. * StCountIndexSeeks
  787. * StCountIndexScans
  788. *
  789. * Load
  790. * StLoadWhileSorting - Average load while processing a sort?
  791. *
  792. * Skew
  793. * StSkewRecordDistribution - Skew on the records across the different nodes
  794. * StSkewExecutionTime - Skew in the execution time between activities.
  795. *
  796. */
  797. interface IConstWUScope : extends IInterface
  798. {
  799. virtual IStringVal & getScope(IStringVal & str) const = 0; // what scope is the statistic gathered over? e.g., workunit, wfid:n, graphn, graphn:m
  800. virtual StatisticScopeType getScopeType() const = 0;
  801. };
  802. interface IConstStatistic : extends IInterface
  803. {
  804. virtual IStringVal & getDescription(IStringVal & str, bool createDefault) const = 0; // Description of the statistic suitable for displaying to the user
  805. virtual IStringVal & getCreator(IStringVal & str) const = 0; // what component gathered the statistic e.g., myroxie/eclserver_12/mythor:100
  806. virtual IStringVal & getFormattedValue(IStringVal & str) const = 0; // The formatted value for display
  807. virtual StatisticMeasure getMeasure() const = 0;
  808. virtual StatisticKind getKind() const = 0;
  809. virtual StatisticCreatorType getCreatorType() const = 0;
  810. virtual unsigned __int64 getValue() const = 0;
  811. virtual unsigned __int64 getCount() const = 0;
  812. virtual unsigned __int64 getMax() const = 0;
  813. };
  814. interface IConstWUStatistic : extends IConstStatistic
  815. {
  816. virtual const char * queryScope() const = 0; // what scope is the statistic gathered over? e.g., workunit, wfid:n, graphn, graphn:m
  817. virtual StatisticScopeType getScopeType() const = 0;
  818. virtual unsigned __int64 getTimestamp() const = 0; // time the statistic was created
  819. };
  820. //---------------------------------------------------------------------------------------------------------------------
  821. /*
  822. * An interface that is provided as a callback to a scope iterator to report properties when iterating scopes
  823. */
  824. interface IWuScopeVisitor
  825. {
  826. virtual void noteStatistic(StatisticKind kind, unsigned __int64 value, IConstWUStatistic & extra) = 0;
  827. virtual void noteAttribute(WuAttr attr, const char * value) = 0;
  828. virtual void noteHint(const char * kind, const char * value) = 0;
  829. virtual void noteException(IConstWUException & exception) = 0;
  830. };
  831. class WORKUNIT_API WuScopeVisitorBase : implements IWuScopeVisitor
  832. {
  833. virtual void noteStatistic(StatisticKind kind, unsigned __int64 value, IConstWUStatistic & extra) override {}
  834. virtual void noteAttribute(WuAttr attr, const char * value) override {}
  835. virtual void noteHint(const char * kind, const char * value) override {}
  836. virtual void noteException(IConstWUException & exception) override {}
  837. };
  838. /*
  839. * Interface for an iterator that walks through the different logical elements (scopes) within a workunit
  840. */
  841. enum WuPropertyTypes : unsigned
  842. {
  843. PTnone = 0x00,
  844. PTstatistics = 0x01,
  845. PTattributes = 0x02,
  846. PThints = 0x04,
  847. PTscope = 0x08, // Just the existence of the scope is interesting
  848. PTnotes = 0x10,
  849. PTall = 0xFF,
  850. PTunknown = 0x80000000,
  851. };
  852. BITMASK_ENUM(WuPropertyTypes);
  853. enum WuScopeSourceFlags : unsigned
  854. {
  855. SSFsearchDefault = 0x0000,
  856. SSFsearchGlobalStats = 0x0001,
  857. SSFsearchGraphStats = 0x0002,
  858. SSFsearchGraph = 0x0004,
  859. SSFsearchExceptions = 0x0008,
  860. SSFsearchWorkflow = 0x0010,
  861. SSFsearchAll = 0x7fffffff,
  862. SSFunknown = 0x80000000,
  863. };
  864. BITMASK_ENUM(WuScopeSourceFlags);
  865. class WORKUNIT_API AttributeValueFilter
  866. {
  867. public:
  868. AttributeValueFilter(WuAttr _attr, const char * _value) : attr(_attr), value(_value)
  869. {
  870. }
  871. bool matches(const char * curValue) const
  872. {
  873. return !value || strsame(curValue, value);
  874. }
  875. WuAttr queryKind() const { return attr; }
  876. StringBuffer & describe(StringBuffer & out) const;
  877. protected:
  878. WuAttr attr;
  879. StringAttr value;
  880. };
  881. /* WuScopeFilter syntax:
  882. * initial match: scope[<scope-id>] | stype[<scope-type>] | id[<scope-id>] | depth[<value>| <min>,<max>]
  883. * source[global|stats|graph|exception]
  884. * stats filter: where[<stat> | <stat>(=|!=|<|>|<=|>=)value | <stat>=<min>..<max>]
  885. *
  886. * returned scopes: matched[true|false] | nested[<depth>] | include[<scope-type>]
  887. * returned information:
  888. * props[stat|attr|hint|scope]
  889. * stat[<stat-name>] | attr[<attr-name>] | hint[<hint-name>] | measure[<measure-name>]
  890. */
  891. class WORKUNIT_API WuScopeFilter
  892. {
  893. friend class CompoundStatisticsScopeIterator;
  894. public:
  895. WuScopeFilter() = default;
  896. WuScopeFilter(const char * filter);
  897. WuScopeFilter & addFilter(const char * filter);
  898. WuScopeFilter & addScope(const char * scope);
  899. WuScopeFilter & addScopeType(StatisticScopeType scopeType);
  900. WuScopeFilter & addScopeType(const char * scopeType);
  901. WuScopeFilter & addId(const char * id);
  902. WuScopeFilter & setDepth(unsigned low, unsigned high);
  903. WuScopeFilter & addSource(const char * source);
  904. WuScopeFilter & setIncludeMatch(bool value);
  905. WuScopeFilter & setIncludeNesting(unsigned depth);
  906. WuScopeFilter & setIncludeScopeType(const char * scopeType);
  907. WuScopeFilter & setMeasure(const char * measure);
  908. WuScopeFilter & addOutput(const char * prop); // Which statistics/properties/hints are required.
  909. WuScopeFilter & addOutputProperties(WuPropertyTypes prop); // stat/attr/hint/scope etc.
  910. WuScopeFilter & addOutputStatistic(StatisticKind stat);
  911. WuScopeFilter & addOutputStatistic(const char * prop);
  912. WuScopeFilter & addOutputAttribute(WuAttr attr);
  913. WuScopeFilter & addOutputAttribute(const char * prop);
  914. WuScopeFilter & addOutputHint(const char * prop);
  915. WuScopeFilter & addRequiredStat(StatisticKind statKind);
  916. WuScopeFilter & addRequiredStat(StatisticKind statKind, stat_type lowValue, stat_type highValue);
  917. WuScopeFilter & addRequiredAttr(WuAttr attr, const char * value = nullptr);
  918. void finishedFilter(); // Call once filter has been completely set up
  919. StringBuffer & describe(StringBuffer & out) const; // describe the filter - each option is preceded by a comma
  920. bool includeStatistic(StatisticKind kind) const;
  921. bool includeAttribute(WuAttr attr) const;
  922. bool includeHint(const char * kind) const;
  923. bool includeScope(const char * scope) const;
  924. ScopeCompare compareMatchScopes(const char * scope) const;
  925. const ScopeFilter & queryIterFilter() const;
  926. bool isOptimized() const { return optimized; }
  927. bool onlyIncludeScopes() const { return (properties & ~PTscope) == 0; }
  928. WuScopeSourceFlags querySources() const { return sourceFlags; }
  929. unsigned queryMinVersion() const { return minVersion; }
  930. bool outputDefined() const { return properties != PTnone; }
  931. protected:
  932. void addRequiredStat(const char * filter);
  933. void checkModifiable() { if (unlikely(optimized)) reportModifyTooLate(); }
  934. bool matchOnly(StatisticScopeType scopeType) const;
  935. void reportModifyTooLate();
  936. protected:
  937. //The following members control which scopes are matched by the iterator
  938. ScopeFilter scopeFilter; // Filter that must be matched by a scope
  939. std::vector<StatisticValueFilter> requiredStats; // The attributes that must be present for a particular scope
  940. std::vector<AttributeValueFilter> requiredAttrs;
  941. WuScopeSourceFlags sourceFlags = SSFsearchDefault; // Which sources within the workunit should be included. Default is to calculate from the properties.
  942. // Once a match has been found which scopes are returned?
  943. struct
  944. {
  945. bool matchedScope = true;
  946. unsigned nestedDepth = 0;
  947. UnsignedArray scopeTypes;
  948. } include;
  949. // For all scopes that are returned, what information is required?
  950. WuPropertyTypes properties = PTnone; // What kind of information is desired (can be used to optimize the scopes). Default is scopes (for selected sources)
  951. UnsignedArray desiredStats;
  952. UnsignedArray desiredAttrs;
  953. StringArray desiredHints;
  954. StatisticMeasure desiredMeasure = SMeasureAll;
  955. __uint64 minVersion = 0;
  956. bool preFilterScope = false;
  957. bool optimized = false;
  958. //NB: Optimize scopeFilter.hasSingleMatch() + bail out early
  959. };
  960. interface IConstWUScopeIterator : extends IScmIterator
  961. {
  962. //Allow iteration of the tree without walking through all the nodes.
  963. virtual bool nextSibling() = 0;
  964. virtual bool nextParent() = 0;
  965. //These return values are invalid after a call to next() or another call to the same function
  966. virtual const char * queryScope() const = 0;
  967. virtual StatisticScopeType getScopeType() const = 0;
  968. //Provide information about all stats, attributes and hints
  969. //whichProperties can be used to further restrict the output as a subset of the scope filter.
  970. virtual void playProperties(IWuScopeVisitor & visitor, WuPropertyTypes whichProperties = PTall) = 0;
  971. //Return true if the stat is present, if found and update the value - queryStat() wrapper is generally easier to use.
  972. virtual bool getStat(StatisticKind kind, unsigned __int64 & value) const = 0;
  973. virtual const char * queryAttribute(WuAttr attr, StringBuffer & scratchpad) const = 0; // Multiple values can be processed via the playStatistics() function
  974. virtual const char * queryHint(const char * kind) const = 0;
  975. inline unsigned __int64 queryStat(StatisticKind kind, unsigned __int64 defaultValue = 0) const
  976. {
  977. unsigned __int64 value = defaultValue;
  978. getStat(kind, value);
  979. return value;
  980. }
  981. };
  982. //---------------------------------------------------------------------------------------------------------------------
  983. //! IWorkUnit
  984. //! Provides high level access to WorkUnit "header" data.
  985. interface IWorkUnit;
  986. interface IUserDescriptor;
  987. interface IConstWorkUnitInfo : extends IInterface
  988. {
  989. virtual const char *queryWuid() const = 0;
  990. virtual const char *queryUser() const = 0;
  991. virtual const char *queryJobName() const = 0;
  992. virtual const char *queryWuScope() const = 0;
  993. virtual const char *queryClusterName() const = 0;
  994. virtual WUState getState() const = 0;
  995. virtual const char *queryStateDesc() const = 0;
  996. virtual WUAction getAction() const = 0;
  997. virtual const char *queryActionDesc() const = 0;
  998. virtual WUPriorityClass getPriority() const = 0;
  999. virtual const char *queryPriorityDesc() const = 0;
  1000. virtual int getPriorityLevel() const = 0;
  1001. virtual bool isProtected() const = 0;
  1002. virtual IJlibDateTime & getTimeScheduled(IJlibDateTime & val) const = 0;
  1003. virtual unsigned getTotalThorTime() const = 0;
  1004. virtual IConstWUAppValueIterator & getApplicationValues() const = 0;
  1005. };
  1006. interface IConstWorkUnit : extends IConstWorkUnitInfo
  1007. {
  1008. virtual bool aborting() const = 0;
  1009. virtual void forceReload() = 0;
  1010. virtual WUAction getAction() const = 0;
  1011. virtual IStringVal & getApplicationValue(const char * application, const char * propname, IStringVal & str) const = 0;
  1012. virtual int getApplicationValueInt(const char * application, const char * propname, int defVal) const = 0;
  1013. virtual bool hasWorkflow() const = 0;
  1014. virtual unsigned queryEventScheduledCount() const = 0;
  1015. virtual IPropertyTree * queryWorkflowTree() const = 0;
  1016. virtual IConstWorkflowItemIterator * getWorkflowItems() const = 0;
  1017. virtual IWorkflowItemArray * getWorkflowClone() const = 0;
  1018. virtual IConstLocalFileUploadIterator * getLocalFileUploads() const = 0;
  1019. virtual bool requiresLocalFileUpload() const = 0;
  1020. virtual bool getIsQueryService() const = 0;
  1021. virtual bool hasDebugValue(const char * propname) const = 0;
  1022. virtual IStringVal & getDebugValue(const char * propname, IStringVal & str) const = 0;
  1023. virtual int getDebugValueInt(const char * propname, int defVal) const = 0;
  1024. virtual __int64 getDebugValueInt64(const char * propname, __int64 defVal) const = 0;
  1025. virtual double getDebugValueReal(const char * propname, double defVal) const = 0;
  1026. virtual bool getDebugValueBool(const char * propname, bool defVal) const = 0;
  1027. virtual IStringIterator & getDebugValues() const = 0;
  1028. virtual IStringIterator & getDebugValues(const char * prop) const = 0;
  1029. virtual unsigned getExceptionCount() const = 0;
  1030. virtual IConstWUExceptionIterator & getExceptions() const = 0;
  1031. virtual IConstWUResult * getGlobalByName(const char * name) const = 0;
  1032. virtual IConstWUGraphMetaIterator & getGraphsMeta(WUGraphType type) const = 0;
  1033. virtual IConstWUGraphIterator & getGraphs(WUGraphType type) const = 0;
  1034. virtual IConstWUGraph * getGraph(const char * name) const = 0;
  1035. virtual IConstWUGraphProgress * getGraphProgress(const char * name) const = 0;
  1036. virtual IConstWUPlugin * getPluginByName(const char * name) const = 0;
  1037. virtual IConstWUPluginIterator & getPlugins() const = 0;
  1038. virtual IConstWULibraryIterator & getLibraries() const = 0;
  1039. virtual IConstWUQuery * getQuery() const = 0;
  1040. virtual bool getRescheduleFlag() const = 0;
  1041. virtual IConstWUResult * getResultByName(const char * name) const = 0;
  1042. virtual IConstWUResult * getResultBySequence(unsigned seq) const = 0;
  1043. // Like getResultByName, but ignores "special" results or results from libraries
  1044. virtual IConstWUResult * getQueryResultByName(const char * name) const = 0;
  1045. virtual unsigned getResultLimit() const = 0;
  1046. virtual IConstWUResultIterator & getResults() const = 0;
  1047. virtual IStringVal & getScope(IStringVal & str) const = 0;
  1048. virtual IStringVal & getWorkunitDistributedAccessToken(IStringVal & datoken) const = 0;
  1049. virtual IStringVal & getStateEx(IStringVal & str) const = 0;
  1050. virtual __int64 getAgentSession() const = 0;
  1051. virtual unsigned getAgentPID() const = 0;
  1052. virtual IConstWUResult * getTemporaryByName(const char * name) const = 0;
  1053. virtual IConstWUResultIterator & getTemporaries() const = 0;
  1054. virtual bool getRunningGraph(IStringVal & graphName, WUGraphIDType & subId) const = 0;
  1055. virtual IConstWUWebServicesInfo * getWebServicesInfo() const = 0;
  1056. virtual bool getStatistic(stat_type & value, const char * scope, StatisticKind kind) const = 0;
  1057. virtual IConstWUScopeIterator & getScopeIterator(const WuScopeFilter & filter) const = 0; // filter must currently stay alive while the iterator does.
  1058. virtual IConstWUResult * getVariableByName(const char * name) const = 0;
  1059. virtual IConstWUResultIterator & getVariables() const = 0;
  1060. virtual bool isPausing() const = 0;
  1061. virtual IWorkUnit & lock() = 0;
  1062. virtual void requestAbort() = 0;
  1063. virtual void subscribe(WUSubscribeOptions options) = 0;
  1064. virtual unsigned queryFileUsage(const char * filename) const = 0;
  1065. virtual IConstWUFileUsageIterator * getFieldUsage() const = 0;
  1066. virtual bool getFieldUsageArray(StringArray & filenames, StringArray & columnnames, const char * clusterName) const = 0;
  1067. virtual unsigned getCodeVersion() const = 0;
  1068. virtual unsigned getWuidVersion() const = 0;
  1069. virtual void getBuildVersion(IStringVal & buildVersion, IStringVal & eclVersion) const = 0;
  1070. virtual IPropertyTree * getDiskUsageStats() = 0;
  1071. virtual IPropertyTreeIterator & getFileIterator() const = 0;
  1072. virtual bool getCloneable() const = 0;
  1073. virtual IUserDescriptor * queryUserDescriptor() const = 0;
  1074. virtual IStringVal & getSnapshot(IStringVal & str) const = 0;
  1075. virtual ErrorSeverity getWarningSeverity(unsigned code, ErrorSeverity defaultSeverity) const = 0;
  1076. virtual IPropertyTreeIterator & getFilesReadIterator() const = 0;
  1077. virtual void protect(bool protectMode) = 0;
  1078. virtual IStringVal & getAllowedClusters(IStringVal & str) const = 0;
  1079. virtual int getPriorityValue() const = 0;
  1080. virtual void remoteCheckAccess(IUserDescriptor * user, bool writeaccess) const = 0;
  1081. virtual bool getAllowAutoQueueSwitch() const = 0;
  1082. virtual IConstWULibrary * getLibraryByName(const char * name) const = 0;
  1083. virtual unsigned getGraphCount() const = 0;
  1084. virtual unsigned getSourceFileCount() const = 0;
  1085. virtual unsigned getResultCount() const = 0;
  1086. virtual unsigned getVariableCount() const = 0;
  1087. virtual unsigned getApplicationValueCount() const = 0;
  1088. virtual unsigned getDebugAgentListenerPort() const = 0;
  1089. virtual IStringVal & getDebugAgentListenerIP(IStringVal & ip) const = 0;
  1090. virtual IStringVal & getXmlParams(IStringVal & params, bool hidePasswords) const = 0;
  1091. virtual const IPropertyTree * getXmlParams() const = 0;
  1092. virtual unsigned __int64 getHash() const = 0;
  1093. virtual IStringIterator *getLogs(const char *type, const char *instance=NULL) const = 0;
  1094. virtual IStringIterator *getProcesses(const char *type) const = 0;
  1095. virtual IPropertyTreeIterator* getProcesses(const char *type, const char *instance) const = 0;
  1096. // Note that these don't read/modify the workunit itself, but rather the associated progress info.
  1097. // As such they can be called without locking the workunit, and are 'const' as far as the WU is concerned.
  1098. virtual WUGraphState queryGraphState(const char *graphName) const = 0;
  1099. virtual WUGraphState queryNodeState(const char *graphName, WUGraphIDType nodeId) const = 0;
  1100. virtual void setGraphState(const char *graphName, unsigned wfid, WUGraphState state) const = 0;
  1101. virtual void setNodeState(const char *graphName, WUGraphIDType nodeId, WUGraphState state) const = 0;
  1102. virtual IWUGraphStats *updateStats(const char *graphName, StatisticCreatorType creatorType, const char * creator, unsigned _wfid, unsigned subgraph) const = 0;
  1103. virtual void clearGraphProgress() const = 0;
  1104. virtual IStringVal & getAbortBy(IStringVal & str) const = 0;
  1105. virtual unsigned __int64 getAbortTimeStamp() const = 0;
  1106. };
  1107. interface IDistributedFile;
  1108. interface IWorkUnit : extends IConstWorkUnit
  1109. {
  1110. virtual void clearExceptions(const char *source=nullptr) = 0;
  1111. virtual void commit() = 0;
  1112. virtual IWUException * createException() = 0;
  1113. virtual void addProcess(const char *type, const char *instance, unsigned pid, unsigned max, const char *pattern, bool singleLog, const char *log=nullptr) = 0;
  1114. virtual void setAction(WUAction action) = 0;
  1115. virtual void setApplicationValue(const char * application, const char * propname, const char * value, bool overwrite) = 0;
  1116. virtual void setApplicationValueInt(const char * application, const char * propname, int value, bool overwrite) = 0;
  1117. virtual void incEventScheduledCount() = 0;
  1118. virtual void setIsQueryService(bool cached) = 0;
  1119. virtual void setClusterName(const char * value) = 0;
  1120. virtual void setDebugValue(const char * propname, const char * value, bool overwrite) = 0;
  1121. virtual void setDebugValueInt(const char * propname, int value, bool overwrite) = 0;
  1122. virtual void setJobName(const char * value) = 0;
  1123. virtual void setPriority(WUPriorityClass cls) = 0;
  1124. virtual void setPriorityLevel(int level) = 0;
  1125. virtual void setRescheduleFlag(bool value) = 0;
  1126. virtual void setResultLimit(unsigned value) = 0;
  1127. virtual void setState(WUState state) = 0;
  1128. virtual void setStateEx(const char * text) = 0; // Indicates why blocked
  1129. virtual void setAgentSession(__int64 sessionId) = 0;
  1130. virtual void setStatistic(StatisticCreatorType creatorType, const char * creator, StatisticScopeType scopeType, const char * scope, StatisticKind kind, const char * optDescription, unsigned __int64 value, unsigned __int64 count, unsigned __int64 maxValue, StatsMergeAction mergeAction) = 0;
  1131. virtual void setTracingValue(const char * propname, const char * value) = 0;
  1132. virtual void setTracingValueInt(const char * propname, int value) = 0;
  1133. virtual void setTracingValueInt64(const char * propname, __int64 value) = 0;
  1134. virtual void setUser(const char * value) = 0;
  1135. virtual void setWuScope(const char * value) = 0;
  1136. virtual void setSnapshot(const char * value) = 0;
  1137. virtual void setWarningSeverity(unsigned code, ErrorSeverity severity) = 0;
  1138. virtual IWorkflowItemIterator * updateWorkflowItems() = 0;
  1139. virtual void syncRuntimeWorkflow(IWorkflowItemArray * array) = 0;
  1140. virtual IWorkflowItem * addWorkflowItem(unsigned wfid, WFType type, WFMode mode, unsigned success, unsigned failure, unsigned recovery, unsigned retriesAllowed, unsigned contingencyFor) = 0;
  1141. virtual void resetWorkflow() = 0;
  1142. virtual void schedule() = 0;
  1143. virtual void deschedule() = 0;
  1144. virtual unsigned addLocalFileUpload(LocalFileUploadType type, const char * source, const char * destination, const char * eventTag) = 0;
  1145. virtual IWUResult * updateGlobalByName(const char * name) = 0;
  1146. virtual void createGraph(const char * name, const char *label, WUGraphType type, IPropertyTree *xgmml, unsigned wfid) = 0;
  1147. virtual IWUQuery * updateQuery() = 0;
  1148. virtual IWUWebServicesInfo * updateWebServicesInfo(bool create) = 0;
  1149. virtual IWUPlugin * updatePluginByName(const char * name) = 0;
  1150. virtual IWULibrary * updateLibraryByName(const char * name) = 0;
  1151. virtual IWUResult * updateResultByName(const char * name) = 0;
  1152. virtual IWUResult * updateResultBySequence(unsigned seq) = 0;
  1153. virtual IWUResult * updateTemporaryByName(const char * name) = 0;
  1154. virtual IWUResult * updateVariableByName(const char * name) = 0;
  1155. virtual void addFile(const char * fileName, StringArray * clusters, unsigned usageCount, WUFileKind fileKind, const char * graphOwner) = 0;
  1156. virtual void releaseFile(const char * fileName) = 0;
  1157. virtual void setCodeVersion(unsigned version, const char * buildVersion, const char * eclVersion) = 0;
  1158. virtual void deleteTempFiles(const char * graph, bool deleteOwned, bool deleteJobOwned) = 0;
  1159. virtual void deleteTemporaries() = 0;
  1160. virtual void addDiskUsageStats(__int64 avgNodeUsage, unsigned minNode, __int64 minNodeUsage, unsigned maxNode, __int64 maxNodeUsage, __int64 graphId) = 0;
  1161. virtual void setCloneable(bool value) = 0;
  1162. virtual void setIsClone(bool value) = 0;
  1163. virtual void setTimeScheduled(const IJlibDateTime & val) = 0;
  1164. virtual void noteFileRead(IDistributedFile * file) = 0;
  1165. virtual void noteFieldUsage(IPropertyTree * file) = 0;
  1166. virtual void resetBeforeGeneration() = 0;
  1167. virtual bool switchThorQueue(const char * newcluster, IQueueSwitcher * qs) = 0;
  1168. virtual void setAllowedClusters(const char * value) = 0;
  1169. virtual void setAllowAutoQueueSwitch(bool val) = 0;
  1170. virtual void setLibraryInformation(const char * name, unsigned interfaceHash, unsigned definitionHash) = 0;
  1171. virtual void setDebugAgentListenerPort(unsigned port) = 0;
  1172. virtual void setDebugAgentListenerIP(const char * ip) = 0;
  1173. virtual void setXmlParams(const char *xml) = 0;
  1174. virtual void setXmlParams(IPropertyTree *tree) = 0;
  1175. virtual void setHash(unsigned __int64 hash) = 0;
  1176. virtual void setResultInt(const char * name, unsigned sequence, __int64 val) = 0;
  1177. virtual void setResultUInt(const char * name, unsigned sequence, unsigned __int64 val) = 0;
  1178. virtual void setResultReal(const char *name, unsigned sequence, double val) = 0;
  1179. virtual void setResultVarString(const char * stepname, unsigned sequence, const char *val) = 0;
  1180. virtual void setResultVarUnicode(const char * stepname, unsigned sequence, UChar const *val) = 0;
  1181. virtual void setResultString(const char * stepname, unsigned sequence, int len, const char *val) = 0;
  1182. virtual void setResultData(const char * stepname, unsigned sequence, int len, const void *val) = 0;
  1183. virtual void setResultRaw(const char * name, unsigned sequence, int len, const void *val) = 0;
  1184. virtual void setResultSet(const char * name, unsigned sequence, bool isAll, size32_t len, const void *val, ISetToXmlTransformer *) = 0;
  1185. virtual void setResultUnicode(const char * name, unsigned sequence, int len, UChar const * val) = 0;
  1186. virtual void setResultBool(const char *name, unsigned sequence, bool val) = 0;
  1187. virtual void setResultDecimal(const char *name, unsigned sequence, int len, int precision, bool isSigned, const void *val) = 0;
  1188. virtual void setResultDataset(const char * name, unsigned sequence, size32_t len, const void *val, unsigned numRows, bool extend) = 0;
  1189. virtual void import(IPropertyTree *wuTree, IPropertyTree *graphProgressTree = nullptr) = 0;
  1190. };
  1191. interface IConstWorkUnitIterator : extends IScmIterator
  1192. {
  1193. virtual IConstWorkUnitInfo & query() = 0;
  1194. };
  1195. //! IWUTimers
  1196. interface IWUTimers : extends IInterface
  1197. {
  1198. virtual void setTrigger(const IJlibDateTime & dt) = 0;
  1199. virtual IJlibDateTime & getTrigger(IJlibDateTime & dt) const = 0;
  1200. virtual void setExpiration(const IJlibDateTime & dt) = 0;
  1201. virtual IJlibDateTime & getExpiration(IJlibDateTime & dt) const = 0;
  1202. virtual void setSubmission(const IJlibDateTime & dt) = 0;
  1203. virtual IJlibDateTime & getSubmission(IJlibDateTime & dt) const = 0;
  1204. };
  1205. //! IWUFactory
  1206. //! Used to instantiate WorkUnit components.
  1207. class MemoryBuffer;
  1208. interface ILocalWorkUnit : extends IWorkUnit
  1209. {
  1210. virtual void serialize(MemoryBuffer & tgt) = 0;
  1211. virtual void deserialize(MemoryBuffer & src) = 0;
  1212. virtual IConstWorkUnit * unlock() = 0;
  1213. };
  1214. enum WUSortField
  1215. {
  1216. WUSFuser = 1,
  1217. WUSFcluster = 2,
  1218. WUSFjob = 3,
  1219. WUSFstate = 4,
  1220. WUSFpriority = 5,
  1221. WUSFwuid = 6,
  1222. WUSFwuidhigh = 7,
  1223. WUSFfileread = 8,
  1224. // WUSFroxiecluster = 9, obsolete
  1225. WUSFprotected = 10,
  1226. WUSFtotalthortime = 11,
  1227. WUSFwildwuid = 12,
  1228. WUSFecl = 13,
  1229. // WUSFcustom = 14, obsolete
  1230. WUSFappvalue=15,
  1231. WUSFfilewritten = 16,
  1232. WUSFterm = 0,
  1233. WUSFreverse = 256,
  1234. WUSFnocase = 512,
  1235. WUSFnumeric = 1024,
  1236. WUSFwild = 2048
  1237. };
  1238. extern WORKUNIT_API const char *queryFilterXPath(WUSortField field);
  1239. enum WUQueryFilterBoolean
  1240. {
  1241. WUQFSNo = 0,
  1242. WUQFSYes = 1,
  1243. WUQFSAll = 2
  1244. };
  1245. enum WUQueryFilterSuspended
  1246. {
  1247. WUQFAllQueries = 0,//all queries including Suspended and not suspended
  1248. WUQFSUSPDNo = 1,
  1249. WUQFSUSPDYes = 2,
  1250. WUQFSUSPDByUser = 3,
  1251. WUQFSUSPDByFirstNode = 4,
  1252. WUQFSUSPDByAnyNode = 5
  1253. };
  1254. enum WUQuerySortField
  1255. {
  1256. WUQSFId = 1,
  1257. WUQSFname = 2,
  1258. WUQSFwuid = 3,
  1259. WUQSFdll = 4,
  1260. WUQSFmemoryLimit = 5,
  1261. WUQSFmemoryLimitHi = 6,
  1262. WUQSFtimeLimit = 7,
  1263. WUQSFtimeLimitHi = 8,
  1264. WUQSFwarnTimeLimit = 9,
  1265. WUQSFwarnTimeLimitHi = 10,
  1266. WUQSFpriority = 11,
  1267. WUQSFpriorityHi = 12,
  1268. WUQSFQuerySet = 13,
  1269. WUQSFActivited = 14,
  1270. WUQSFSuspendedByUser = 15,
  1271. WUQSFLibrary = 16,
  1272. WUQSFPublishedBy = 17,
  1273. WUQSFSuspendedFilter = 18,
  1274. WUQSFterm = 0,
  1275. WUQSFreverse = 256,
  1276. WUQSFnocase = 512,
  1277. WUQSFnumeric = 1024,
  1278. WUQSFwild = 2048
  1279. };
  1280. typedef IIteratorOf<IPropertyTree> IConstQuerySetQueryIterator;
  1281. interface IWorkUnitFactory : extends IPluggableFactory
  1282. {
  1283. virtual IWorkUnit *createWorkUnit(const char *app, const char *scope, ISecManager *secmgr = NULL, ISecUser *secuser = NULL) = 0;
  1284. virtual void importWorkUnit(const char *zapReportFileName, const char *zapReportPassword,
  1285. const char *importDir, const char *app, const char *user, ISecManager *secMgr, ISecUser *secUser) = 0;
  1286. virtual bool deleteWorkUnit(const char *wuid, ISecManager *secmgr = NULL, ISecUser *secuser = NULL) = 0;
  1287. virtual bool deleteWorkUnitEx(const char *wuid, bool throwException, ISecManager *secmgr = NULL, ISecUser *secuser = NULL) = 0;
  1288. virtual IConstWorkUnit * openWorkUnit(const char *wuid, ISecManager *secmgr = NULL, ISecUser *secuser = NULL) = 0;
  1289. virtual IConstWorkUnitIterator * getWorkUnitsByOwner(const char * owner, ISecManager *secmgr = NULL, ISecUser *secuser = NULL) = 0;
  1290. virtual IWorkUnit * updateWorkUnit(const char * wuid, ISecManager *secmgr = NULL, ISecUser *secuser = NULL) = 0;
  1291. virtual bool restoreWorkUnit(const char *base, const char *wuid, bool restoreAssociatedFiles) = 0;
  1292. virtual int setTracingLevel(int newlevel) = 0;
  1293. virtual IWorkUnit * createNamedWorkUnit(const char * wuid, const char * app, const char * scope, ISecManager *secmgr = NULL, ISecUser *secuser = NULL) = 0;
  1294. virtual IWorkUnit * getGlobalWorkUnit(ISecManager *secmgr = NULL, ISecUser *secuser = NULL) = 0;
  1295. virtual IConstWorkUnitIterator * getWorkUnitsSorted(WUSortField sortorder, WUSortField * filters, const void * filterbuf,
  1296. unsigned startoffset, unsigned maxnum, __int64 * cachehint, unsigned *total,
  1297. ISecManager *secmgr = NULL, ISecUser *secuser = NULL) = 0;
  1298. virtual unsigned numWorkUnits() = 0;
  1299. virtual IConstWorkUnitIterator *getScheduledWorkUnits(ISecManager *secmgr = NULL, ISecUser *secuser = NULL) = 0;
  1300. virtual void descheduleAllWorkUnits(ISecManager *secmgr = NULL, ISecUser *secuser = NULL) = 0;
  1301. virtual IConstQuerySetQueryIterator * getQuerySetQueriesSorted(WUQuerySortField *sortorder, WUQuerySortField *filters, const void *filterbuf,
  1302. unsigned startoffset, unsigned maxnum, __int64 *cachehint, unsigned *total, const MapStringTo<bool> *subset, const MapStringTo<bool> *suspendedByCluster) = 0;
  1303. virtual bool isAborting(const char *wuid) const = 0;
  1304. virtual void clearAborting(const char *wuid) = 0;
  1305. virtual WUState waitForWorkUnit(const char * wuid, unsigned timeout, bool compiled, std::list<WUState> expectedStates) = 0;
  1306. virtual WUAction waitForWorkUnitAction(const char * wuid, WUAction original) = 0;
  1307. virtual unsigned validateRepository(bool fixErrors) = 0;
  1308. virtual void deleteRepository(bool recreate) = 0;
  1309. virtual void createRepository() = 0; // If not already there...
  1310. virtual const char *queryStoreType() const = 0; // Returns "Dali" or "Cassandra"
  1311. virtual StringArray &getUniqueValues(WUSortField field, const char *prefix, StringArray &result) const = 0;
  1312. virtual IWorkUnitWatcher *getWatcher(IWorkUnitSubscriber *subscriber, WUSubscribeOptions options, const char *wuid) const = 0;
  1313. };
  1314. interface IWorkflowScheduleConnection : extends IInterface
  1315. {
  1316. virtual void lock() = 0;
  1317. virtual void unlock() = 0;
  1318. virtual void setActive() = 0;
  1319. virtual void resetActive() = 0;
  1320. virtual bool queryActive() = 0;
  1321. virtual bool pull(IWorkflowItemArray * workflow) = 0;
  1322. virtual void push(const char * name, const char * text) = 0;
  1323. virtual void remove() = 0;
  1324. };
  1325. interface IExtendedWUInterface
  1326. {
  1327. virtual unsigned calculateHash(unsigned prevHash) = 0;
  1328. virtual void copyWorkUnit(IConstWorkUnit *cached, bool copyStats, bool all) = 0;
  1329. virtual bool archiveWorkUnit(const char *base,bool del,bool ignoredllerrors,bool deleteOwned,bool exportAssociatedFiles) = 0;
  1330. virtual IPropertyTree *getUnpackedTree(bool includeProgress) const = 0;
  1331. virtual IPropertyTree *queryPTree() const = 0;
  1332. };
  1333. //Do not mark this as WORKUNIT_API - all functions are inline, and it causes windows link errors
  1334. struct WorkunitUpdate : public Owned<IWorkUnit>
  1335. {
  1336. public:
  1337. inline WorkunitUpdate(IWorkUnit *wu) : Owned<IWorkUnit>(wu) { }
  1338. inline ~WorkunitUpdate() { if (get()) get()->commit(); }
  1339. };
  1340. class WORKUNIT_API WuStatisticTarget : implements IStatisticTarget
  1341. {
  1342. public:
  1343. WuStatisticTarget(IWorkUnit * _wu, const char * _defaultWho) : wu(_wu), defaultWho(_defaultWho) {}
  1344. virtual void addStatistic(StatisticScopeType scopeType, const char * scope, StatisticKind kind, char * description, unsigned __int64 value, unsigned __int64 count, unsigned __int64 maxValue, StatsMergeAction mergeAction)
  1345. {
  1346. wu->setStatistic(queryStatisticsComponentType(), queryStatisticsComponentName(), scopeType, scope, kind, description, value, count, maxValue, mergeAction);
  1347. }
  1348. protected:
  1349. Linked<IWorkUnit> wu;
  1350. const char * defaultWho;
  1351. };
  1352. typedef IWorkUnitFactory * (* WorkUnitFactoryFactory)(const IPropertyTree *);
  1353. extern WORKUNIT_API IStatisticGatherer * createGlobalStatisticGatherer(IWorkUnit * wu);
  1354. extern WORKUNIT_API WUGraphType getGraphTypeFromString(const char* type);
  1355. extern WORKUNIT_API bool getWorkUnitCreateTime(const char *wuid,CDateTime &time); // based on WUID
  1356. extern WORKUNIT_API void clientShutdownWorkUnit();
  1357. extern WORKUNIT_API IExtendedWUInterface * queryExtendedWU(IConstWorkUnit * wu);
  1358. extern WORKUNIT_API const IExtendedWUInterface * queryExtendedWU(const IConstWorkUnit * wu);
  1359. extern WORKUNIT_API StringBuffer &formatGraphTimerLabel(StringBuffer &str, const char *graphName, unsigned subGraphNum=0, unsigned __int64 subId=0);
  1360. extern WORKUNIT_API StringBuffer &formatGraphTimerScope(StringBuffer &str, unsigned wfid, const char *graphName, unsigned subGraphNum, unsigned __int64 subId);
  1361. extern WORKUNIT_API bool parseGraphTimerLabel(const char *label, StringAttr &graphName, unsigned & graphNum, unsigned &subGraphNum, unsigned &subId);
  1362. extern WORKUNIT_API bool parseGraphScope(const char *scope, StringAttr &graphName, unsigned & graphNum, unsigned &subGraphId);
  1363. extern WORKUNIT_API void addExceptionToWorkunit(IWorkUnit * wu, ErrorSeverity severity, const char * source, unsigned code, const char * text, const char * filename, unsigned lineno, unsigned column, unsigned activity);
  1364. extern WORKUNIT_API void setWorkUnitFactory(IWorkUnitFactory *_factory);
  1365. extern WORKUNIT_API IWorkUnitFactory * getWorkUnitFactory();
  1366. extern WORKUNIT_API IWorkUnitFactory * getWorkUnitFactory(ISecManager *secmgr, ISecUser *secuser);
  1367. extern WORKUNIT_API ILocalWorkUnit* createLocalWorkUnit(const char *XML);
  1368. extern WORKUNIT_API IConstWorkUnitInfo *createConstWorkUnitInfo(IPropertyTree &p);
  1369. extern WORKUNIT_API StringBuffer &exportWorkUnitToXML(const IConstWorkUnit *wu, StringBuffer &str, bool unpack, bool includeProgress, bool hidePasswords);
  1370. extern WORKUNIT_API void exportWorkUnitToXMLFile(const IConstWorkUnit *wu, const char * filename, unsigned extraXmlFlags, bool unpack, bool includeProgress, bool hidePasswords, bool splitStats);
  1371. extern WORKUNIT_API void submitWorkUnit(const char *wuid, const char *username, const char *password);
  1372. extern WORKUNIT_API void abortWorkUnit(const char *wuid);
  1373. extern WORKUNIT_API void submitWorkUnit(const char *wuid, ISecManager *secmgr, ISecUser *secuser);
  1374. extern WORKUNIT_API void abortWorkUnit(const char *wuid, ISecManager *secmgr, ISecUser *secuser);
  1375. extern WORKUNIT_API void secSubmitWorkUnit(const char *wuid, ISecManager &secmgr, ISecUser &secuser);
  1376. extern WORKUNIT_API void secAbortWorkUnit(const char *wuid, ISecManager &secmgr, ISecUser &secuser);
  1377. extern WORKUNIT_API IWUResult * updateWorkUnitResult(IWorkUnit * w, const char *name, unsigned sequence);
  1378. extern WORKUNIT_API IConstWUResult * getWorkUnitResult(IConstWorkUnit * w, const char *name, unsigned sequence);
  1379. extern WORKUNIT_API void updateSuppliedXmlParams(IWorkUnit * w);
  1380. //workunit distributed access token support
  1381. enum wuTokenStates { wuTokenValid=0, wuTokenInvalid, wuTokenWorkunitInactive };
  1382. extern WORKUNIT_API wuTokenStates verifyWorkunitDAToken(const char * ctxUser, const char * daToken);
  1383. extern WORKUNIT_API bool extractFromWorkunitDAToken(const char * token, StringBuffer * wuid, StringBuffer * user, StringBuffer * privKey);
  1384. inline bool isWorkunitDAToken(const char * distributedAccessToken)
  1385. {
  1386. //Does given token appear to be in the right format. KeyFile and signature are optional
  1387. // HPCC[u=user,w=wuid]keyFile;signature
  1388. const char * finger = distributedAccessToken;
  1389. if (finger && 0 == strncmp(finger,"HPCC[u=",7))
  1390. if ((finger = strstr(finger+7, ",w=")))
  1391. if ((finger = strchr(finger+3, ']')))
  1392. if ((finger = strchr(finger+1, ';')))
  1393. return true;
  1394. return false;
  1395. }
  1396. //returns a state code. WUStateUnknown == timeout
  1397. extern WORKUNIT_API WUState waitForWorkUnitToComplete(const char * wuid, int timeout = -1, std::list<WUState> expectedStates = {});
  1398. extern WORKUNIT_API bool waitForWorkUnitToCompile(const char * wuid, int timeout = -1);
  1399. extern WORKUNIT_API WUState secWaitForWorkUnitToComplete(const char * wuid, ISecManager &secmgr, ISecUser &secuser, int timeout = -1, std::list<WUState> expectedStates = {});
  1400. extern WORKUNIT_API bool secWaitForWorkUnitToCompile(const char * wuid, ISecManager &secmgr, ISecUser &secuser, int timeout = -1);
  1401. extern WORKUNIT_API bool secDebugWorkunit(const char * wuid, ISecManager &secmgr, ISecUser &secuser, const char *command, StringBuffer &response);
  1402. extern WORKUNIT_API WUState getWorkUnitState(const char* state);
  1403. extern WORKUNIT_API IWorkflowScheduleConnection * getWorkflowScheduleConnection(char const * wuid);
  1404. extern WORKUNIT_API const char *skipLeadingXml(const char *text);
  1405. extern WORKUNIT_API bool isArchiveQuery(const char * text);
  1406. extern WORKUNIT_API bool isQueryManifest(const char * text);
  1407. extern WORKUNIT_API IPropertyTree * resolveDefinitionInArchive(IPropertyTree * archive, const char * path);
  1408. inline bool isLibrary(IConstWorkUnit * wu) { return wu->getApplicationValueInt("LibraryModule", "interfaceHash", 0) != 0; }
  1409. extern WORKUNIT_API bool looksLikeAWuid(const char * wuid, const char firstChar);
  1410. extern WORKUNIT_API IConstWorkUnitIterator *createSecureConstWUIterator(IPropertyTreeIterator *iter, ISecManager *secmgr, ISecUser *secuser);
  1411. extern WORKUNIT_API IConstWorkUnitIterator *createSecureConstWUIterator(IConstWorkUnitIterator *iter, ISecManager *secmgr, ISecUser *secuser);
  1412. enum WUQueryActivationOptions
  1413. {
  1414. DO_NOT_ACTIVATE = 0,
  1415. MAKE_ACTIVATE= 1,
  1416. ACTIVATE_SUSPEND_PREVIOUS = 2,
  1417. ACTIVATE_DELETE_PREVIOUS = 3,
  1418. DO_NOT_ACTIVATE_LOAD_DATA_ONLY = 4,
  1419. MAKE_ACTIVATE_LOAD_DATA_ONLY = 5
  1420. };
  1421. extern WORKUNIT_API int calcPriorityValue(const IPropertyTree * p); // Calls to this should really go through the workunit interface.
  1422. extern WORKUNIT_API IPropertyTree * addNamedQuery(IPropertyTree * queryRegistry, const char * name, const char * wuid, const char * dll, bool library, const char *userid, const char *snapshot); // result not linked
  1423. extern WORKUNIT_API void removeNamedQuery(IPropertyTree * queryRegistry, const char * id);
  1424. extern WORKUNIT_API void removeWuidFromNamedQueries(IPropertyTree * queryRegistry, const char * wuid);
  1425. extern WORKUNIT_API void removeDllFromNamedQueries(IPropertyTree * queryRegistry, const char * dll);
  1426. extern WORKUNIT_API void removeAliasesFromNamedQuery(IPropertyTree * queryRegistry, const char * id);
  1427. extern WORKUNIT_API void setQueryAlias(IPropertyTree * queryRegistry, const char * name, const char * value);
  1428. extern WORKUNIT_API IPropertyTree * getQueryById(IPropertyTree * queryRegistry, const char *queryid);
  1429. extern WORKUNIT_API IPropertyTree * getQueryById(const char *queryset, const char *queryid, bool readonly);
  1430. extern WORKUNIT_API IPropertyTree * resolveQueryAlias(IPropertyTree * queryRegistry, const char * alias);
  1431. extern WORKUNIT_API IPropertyTree * resolveQueryAlias(const char *queryset, const char *alias, bool readonly);
  1432. extern WORKUNIT_API IPropertyTree * getQueryRegistry(const char * wsEclId, bool readonly);
  1433. extern WORKUNIT_API IPropertyTree * getQueryRegistryRoot();
  1434. extern WORKUNIT_API void checkAddLibrariesToQueryEntry(IPropertyTree *queryTree, IConstWULibraryIterator *libraries);
  1435. extern WORKUNIT_API void checkAddLibrariesToQueryEntry(IPropertyTree *queryTree, IConstWorkUnit *cw);
  1436. extern WORKUNIT_API void setQueryCommentForNamedQuery(IPropertyTree * queryRegistry, const char *id, const char *queryComment);
  1437. extern WORKUNIT_API void setQuerySuspendedState(IPropertyTree * queryRegistry, const char * name, bool suspend, const char *userid);
  1438. extern WORKUNIT_API IPropertyTree * addNamedPackageSet(IPropertyTree * packageRegistry, const char * name, IPropertyTree *packageInfo, bool overWrite); // result not linked
  1439. extern WORKUNIT_API void removeNamedPackage(IPropertyTree * packageRegistry, const char * id);
  1440. extern WORKUNIT_API IPropertyTree * getPackageSetRegistry(const char * wsEclId, bool readonly);
  1441. extern WORKUNIT_API void addQueryToQuerySet(IWorkUnit *workunit, IPropertyTree *queryRegistry, const char *queryName, WUQueryActivationOptions activateOption, StringBuffer &newQueryId, const char *userid);
  1442. extern WORKUNIT_API void addQueryToQuerySet(IWorkUnit *workunit, const char *querySetName, const char *queryName, WUQueryActivationOptions activateOption, StringBuffer &newQueryId, const char *userid);
  1443. extern WORKUNIT_API void activateQuery(IPropertyTree *queryRegistry, WUQueryActivationOptions activateOption, const char *queryName, const char *queryId, const char *userid);
  1444. extern WORKUNIT_API bool removeQuerySetAlias(const char *querySetName, const char *alias);
  1445. extern WORKUNIT_API void addQuerySetAlias(const char *querySetName, const char *alias, const char *id);
  1446. extern WORKUNIT_API void setSuspendQuerySetQuery(const char *querySetName, const char *id, bool suspend, const char *userid);
  1447. extern WORKUNIT_API void deleteQuerySetQuery(const char *querySetName, const char *id);
  1448. extern WORKUNIT_API const char *queryIdFromQuerySetWuid(IPropertyTree *queryRegistry, const char *wuid, const char *queryName, IStringVal &id);
  1449. extern WORKUNIT_API const char *queryIdFromQuerySetWuid(const char *querySetName, const char *wuid, const char *queryName, IStringVal &id);
  1450. extern WORKUNIT_API void removeQuerySetAliasesFromNamedQuery(const char *querySetName, const char * id);
  1451. extern WORKUNIT_API void setQueryCommentForNamedQuery(const char *querySetName, const char *id, const char *comment);
  1452. extern WORKUNIT_API void gatherLibraryNames(StringArray &names, StringArray &unresolved, IWorkUnitFactory &workunitFactory, IConstWorkUnit &cw, IPropertyTree *queryset);
  1453. //If we add any more parameters we should consider returning an object that can be updated
  1454. extern WORKUNIT_API void associateLocalFile(IWUQuery * query, WUFileType type, const char * name, const char * description, unsigned crc, unsigned minActivity=0, unsigned maxActivity=0);
  1455. interface ITimeReporter;
  1456. extern WORKUNIT_API void updateWorkunitStat(IWorkUnit * wu, StatisticScopeType scopeType, const char * scope, StatisticKind kind, const char * description, unsigned __int64 value, unsigned wfid=0);
  1457. extern WORKUNIT_API void updateWorkunitTimings(IWorkUnit * wu, ITimeReporter *timer);
  1458. extern WORKUNIT_API void updateWorkunitTimings(IWorkUnit * wu, StatisticScopeType scopeType, StatisticKind kind, ITimeReporter *timer);
  1459. extern WORKUNIT_API void aggregateStatistic(StatsAggregation & result, IConstWorkUnit * wu, const WuScopeFilter & filter, StatisticKind search);
  1460. extern WORKUNIT_API cost_type aggregateCost(const IConstWorkUnit * wu, const char *scope=nullptr, bool excludehThor=false);
  1461. extern WORKUNIT_API const char *getTargetClusterComponentName(const char *clustname, const char *processType, StringBuffer &name);
  1462. extern WORKUNIT_API void descheduleWorkunit(char const * wuid);
  1463. #if 0
  1464. void WORKUNIT_API testWorkflow();
  1465. #endif
  1466. extern WORKUNIT_API const char * getWorkunitStateStr(WUState state);
  1467. extern WORKUNIT_API const char * getWorkunitActionStr(WUAction action);
  1468. extern WORKUNIT_API WUAction getWorkunitAction(const char * actionStr);
  1469. extern WORKUNIT_API void addTimeStamp(IWorkUnit * wu, StatisticScopeType scopeType, const char * scope, StatisticKind kind, unsigned wfid=0);
  1470. extern WORKUNIT_API cost_type calculateThorCost(unsigned __int64 ms, unsigned clusterWidth);
  1471. extern WORKUNIT_API IPropertyTree * getWUGraphProgress(const char * wuid, bool readonly);
  1472. class WORKUNIT_API WorkUnitErrorReceiver : implements IErrorReceiver, public CInterface
  1473. {
  1474. public:
  1475. WorkUnitErrorReceiver(IWorkUnit * _wu, const char * _component, bool _removeTimeStamp) { wu.set(_wu); component.set(_component); removeTimeStamp = _removeTimeStamp; }
  1476. IMPLEMENT_IINTERFACE;
  1477. virtual IError * mapError(IError * error);
  1478. virtual void exportMappings(IWorkUnit * wu) const { }
  1479. virtual void report(IError*);
  1480. virtual size32_t errCount();
  1481. virtual size32_t warnCount();
  1482. private:
  1483. Owned<IWorkUnit> wu;
  1484. StringAttr component;
  1485. bool removeTimeStamp;
  1486. };
  1487. extern WORKUNIT_API void addWorkunitException(IWorkUnit * wu, IError * error, bool removeTimeStamp);
  1488. inline bool isGlobalScope(const char * scope) { return scope && (streq(scope, GLOBAL_SCOPE) || streq(scope, LEGACY_GLOBAL_SCOPE)); }
  1489. extern WORKUNIT_API bool isValidPriorityValue(const char * priority);
  1490. extern WORKUNIT_API bool isValidMemoryValue(const char * memoryUnit);
  1491. inline cost_type calcCost(cost_type ratePerHour, unsigned __int64 ms) { return ratePerHour * ms / 1000 / 3600; }
  1492. extern WORKUNIT_API void executeThorGraph(const char * graphName, IConstWorkUnit &workunit, const IPropertyTree &config);
  1493. #ifdef _CONTAINERIZED
  1494. extern WORKUNIT_API bool executeGraphOnLingeringThor(IConstWorkUnit &workunit, const char *graphName, const char *multiJobLingerQueueName);
  1495. extern WORKUNIT_API void deleteK8sJob(const char *componentName, const char *job);
  1496. extern WORKUNIT_API void waitK8sJob(const char *componentName, const char *job);
  1497. extern WORKUNIT_API void launchK8sJob(const char *componentName, const char *wuid, const char *job, const std::list<std::pair<std::string, std::string>> &extraParams={});
  1498. extern WORKUNIT_API void runK8sJob(const char *componentName, const char *wuid, const char *job, bool del=true, const std::list<std::pair<std::string, std::string>> &extraParams={});
  1499. #endif
  1500. #endif