ESPWorkunit.js 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. /*##############################################################################
  2. # Copyright (C) 2011 HPCC Systems.
  3. #
  4. # All rights reserved. This program is free software: you can redistribute it and/or modify
  5. # it under the terms of the GNU Affero General Public License as
  6. # published by the Free Software Foundation, either version 3 of the
  7. # License, or (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU Affero General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU Affero General Public License
  15. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. ############################################################################## */
  17. define([
  18. "dojo/_base/config",
  19. "dojo/_base/declare",
  20. "dojo/_base/xhr",
  21. "hpcc/ESPBase"
  22. ], function (baseConfig, declare, baseXhr, ESPBase) {
  23. return declare(ESPBase, {
  24. wuid: "",
  25. stateID: 0,
  26. state: "",
  27. text: "",
  28. resultCount: 0,
  29. results: [],
  30. graphNameIndex: [],
  31. graphs: [],
  32. exceptions: [],
  33. errors: [],
  34. timers: [],
  35. onCreate: function () {
  36. },
  37. onUpdate: function () {
  38. },
  39. onSubmit: function () {
  40. },
  41. onMonitor: function () {
  42. },
  43. onComplete: function () {
  44. },
  45. onGetText: function () {
  46. },
  47. onGetInfo: function () {
  48. },
  49. onGetGraph: function (name) {
  50. },
  51. constructor: function (args) {
  52. declare.safeMixin(this, args);
  53. if (!this.wuid) {
  54. this.create();
  55. }
  56. },
  57. isComplete: function () {
  58. switch (this.stateID) {
  59. case '3':
  60. //WUStateCompleted:
  61. case '4':
  62. //WUStateFailed:
  63. case '5':
  64. //WUStateArchived:
  65. case '7':
  66. //WUStateAborted:
  67. return true;
  68. }
  69. return false;
  70. },
  71. monitor: function () {
  72. var request = {};
  73. request['Wuid'] = this.wuid;
  74. request['rawxml_'] = "1";
  75. var context = this;
  76. baseXhr.post({
  77. url: this.getBaseURL() + "/WUQuery",
  78. handleAs: "xml",
  79. content: request,
  80. load: function (xmlDom) {
  81. context.stateID = context.parseKeyValue(xmlDom, "StateID");
  82. context.state = context.parseKeyValue(xmlDom, "State");
  83. context.onMonitor();
  84. if (!context.isComplete()) {
  85. setTimeout(function () {
  86. context.monitor();
  87. }, 200);
  88. }
  89. },
  90. error: function () {
  91. done = true;
  92. }
  93. });
  94. },
  95. create: function (ecl, _sync) {
  96. var request = {};
  97. request['rawxml_'] = "1";
  98. var context = this;
  99. baseXhr.post({
  100. url: this.getBaseURL() + "/WUCreate",
  101. handleAs: "xml",
  102. content: request,
  103. load: function (xmlDom) {
  104. context.wuid = context.parseKeyValue(xmlDom, "Wuid");
  105. context.onCreate();
  106. },
  107. error: function () {
  108. }
  109. });
  110. },
  111. update: function (ecl, _sync) {
  112. var request = {};
  113. request['Wuid'] = this.wuid;
  114. request['QueryText'] = ecl;
  115. request['rawxml_'] = "1";
  116. var context = this;
  117. baseXhr.post({
  118. url: this.getBaseURL() + "/WUUpdate",
  119. handleAs: "xml",
  120. content: request,
  121. sync: _sync,
  122. load: function (xmlDom) {
  123. context.onUpdate();
  124. },
  125. error: function () {
  126. }
  127. });
  128. },
  129. submit: function (target, _sync) {
  130. var request = {};
  131. request['Wuid'] = this.wuid;
  132. request['Cluster'] = target;
  133. request['rawxml_'] = "1";
  134. var context = this;
  135. baseXhr.post({
  136. url: this.getBaseURL() + "/WUSubmit",
  137. handleAs: "xml",
  138. content: request,
  139. sync: _sync,
  140. load: function (xmlDom) {
  141. context.onSubmit();
  142. context.monitor();
  143. },
  144. error: function () {
  145. }
  146. });
  147. },
  148. getInfoEx: function (_sync, func, IncludeExceptions, IncludeGraphs, IncludeSourceFiles, IncludeResults, IncludeResultsViewNames, IncludeVariables, IncludeTimers, IncludeDebugValues, IncludeApplicationValues, IncludeWorkflows, IncludeResultSchemas) {
  149. var request = {};
  150. request['Wuid'] = this.wuid;
  151. request['IncludeExceptions'] = IncludeExceptions;
  152. request['IncludeGraphs'] = IncludeGraphs;
  153. request['IncludeSourceFiles'] = IncludeSourceFiles;
  154. request['IncludeResults'] = IncludeResults;
  155. request['IncludeResultsViewNames'] = IncludeResultsViewNames;
  156. request['IncludeVariables'] = IncludeVariables;
  157. request['IncludeTimers'] = IncludeTimers;
  158. request['IncludeDebugValues'] = IncludeDebugValues;
  159. request['IncludeApplicationValues'] = IncludeApplicationValues;
  160. request['IncludeWorkflows'] = IncludeWorkflows;
  161. request['SuppressResultSchemas'] = !IncludeResultSchemas;
  162. request['rawxml_'] = "1";
  163. baseXhr.post({
  164. url: this.getBaseURL() + "/WUInfo",
  165. handleAs: "xml",
  166. content: request,
  167. sync: _sync,
  168. load: func,
  169. error: function () {
  170. }
  171. });
  172. },
  173. getText: function () {
  174. var context = this;
  175. this.getInfoEx(false, function (xmlDom) {
  176. context.text = context.parseKeyValue(xmlDom, "Text");
  177. context.onGetText();
  178. });
  179. return wu.text;
  180. },
  181. getInfo: function (_sync) {
  182. var context = this;
  183. this.getInfoEx(_sync, function (xmlDom) {
  184. context.exceptions = context.parseRows(xmlDom, "Exception");
  185. context.errors = context.parseRows(xmlDom, "ECLException");
  186. context.timers = context.parseRows(xmlDom, "ECLTimer");
  187. context.graphs = context.parseRows(xmlDom, "ECLGraph");
  188. for (var i = 0; i < context.graphs.length; ++i) {
  189. context.graphNameIndex[context.graphs[i].Name] = i;
  190. }
  191. context.results = context.parseRows(xmlDom, "ECLResult");
  192. context.onGetInfo();
  193. }, true, true, false, true, false, false, true, false, false, false, false);
  194. },
  195. getGraphs: function () {
  196. for (var i = 0; i < this.graphs.length; ++i) {
  197. this.getGraph(i);
  198. }
  199. },
  200. getGraph: function (idx, _sync) {
  201. var request = {};
  202. request['Wuid'] = this.wuid;
  203. request['GraphName'] = this.graphs[idx].Name;
  204. request['rawxml_'] = "1";
  205. var context = this;
  206. baseXhr.post({
  207. url: this.getBaseURL() + "/WUGetGraph",
  208. handleAs: "xml",
  209. content: request,
  210. sync: _sync,
  211. load: function (xmlDom) {
  212. context.graphs[idx].xgmml = context.parseKeyValue(xmlDom, "Graph");
  213. context.onGetGraph(idx);
  214. },
  215. error: function () {
  216. }
  217. });
  218. },
  219. getResults: function () {
  220. for (var i = 0; i < this.results.length; ++i) {
  221. this.getResult(i);
  222. }
  223. },
  224. getResult: function (idx, _sync) {
  225. var request = {};
  226. request['Wuid'] = this.wuid;
  227. request['Sequence'] = this.results[idx].Sequence;
  228. request['Start'] = 0;
  229. request['Count'] = 999;
  230. request['rawxml_'] = "1";
  231. var context = this;
  232. baseXhr.post({
  233. url: this.getBaseURL() + "/WUResult",
  234. handleAs: "xml",
  235. content: request,
  236. sync: _sync,
  237. load: function (xmlDom) {
  238. var name = context.parseKeyValue(xmlDom, "Name");
  239. var resultDom = xmlDom.getElementsByTagName("Result");
  240. if (resultDom.length) {
  241. context.results[idx].dataset = context.parseDataset(resultDom[0], name, "Row");
  242. }
  243. context.onGetResult(idx);
  244. },
  245. error: function () {
  246. }
  247. });
  248. },
  249. getInfoFast: function (_sync) {
  250. var request = {};
  251. request['Wuid'] = this.wuid;
  252. request['rawxml_'] = "1";
  253. var context = this;
  254. baseXhr.post({
  255. url: this.getBaseURL() + "/WUQuery",
  256. handleAs: "xml",
  257. content: request,
  258. sync: _sync,
  259. load: function (xmlDom) {
  260. context.stateID = context.parseKeyValue(xmlDom, "StateID");
  261. context.state = context.parseKeyValue(xmlDom, "State");
  262. },
  263. error: function () {
  264. done = true;
  265. }
  266. });
  267. }
  268. });
  269. });