ESPWorkunit.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  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/declare",
  19. "dojo/_base/lang",
  20. "dojo/_base/xhr",
  21. "hpcc/ESPResult",
  22. "hpcc/ESPBase"
  23. ], function (declare, lang, xhr, ESPResult, ESPBase) {
  24. return declare(ESPBase, {
  25. wuid: "",
  26. stateID: 0,
  27. state: "",
  28. text: "",
  29. resultCount: 0,
  30. results: [],
  31. graphs: [],
  32. exceptions: [],
  33. timers: [],
  34. onCreate: function () {
  35. },
  36. onUpdate: function () {
  37. },
  38. onSubmit: function () {
  39. },
  40. constructor: function (args) {
  41. declare.safeMixin(this, args);
  42. if (!this.wuid) {
  43. this.create();
  44. }
  45. },
  46. isComplete: function () {
  47. switch (this.stateID) {
  48. case '3':
  49. //WUStateCompleted:
  50. case '4':
  51. //WUStateFailed:
  52. case '5':
  53. //WUStateArchived:
  54. case '7':
  55. //WUStateAborted:
  56. return true;
  57. }
  58. return false;
  59. },
  60. monitor: function (callback) {
  61. var request = {};
  62. request['Wuid'] = this.wuid;
  63. request['rawxml_'] = "1";
  64. var context = this;
  65. xhr.post({
  66. url: this.getBaseURL() + "/WUQuery",
  67. handleAs: "xml",
  68. content: request,
  69. load: function (xmlDom) {
  70. var workunit = context.getValue(xmlDom, "ECLWorkunit");
  71. context.stateID = workunit.StateID;
  72. context.state = workunit.State;
  73. if (callback) {
  74. callback(context);
  75. }
  76. if (!context.isComplete()) {
  77. setTimeout(function () {
  78. context.monitor(callback);
  79. }, 200);
  80. }
  81. },
  82. error: function () {
  83. done = true;
  84. }
  85. });
  86. },
  87. create: function (ecl) {
  88. var request = {};
  89. request['rawxml_'] = "1";
  90. var context = this;
  91. xhr.post({
  92. url: this.getBaseURL() + "/WUCreate",
  93. handleAs: "xml",
  94. content: request,
  95. load: function (xmlDom) {
  96. context.wuid = context.getValue(xmlDom, "Wuid");
  97. context.onCreate();
  98. },
  99. error: function () {
  100. }
  101. });
  102. },
  103. update: function (ecl) {
  104. var request = {};
  105. request['Wuid'] = this.wuid;
  106. request['QueryText'] = ecl;
  107. request['rawxml_'] = "1";
  108. var context = this;
  109. xhr.post({
  110. url: this.getBaseURL() + "/WUUpdate",
  111. handleAs: "xml",
  112. content: request,
  113. load: function (xmlDom) {
  114. context.onUpdate();
  115. },
  116. error: function () {
  117. }
  118. });
  119. },
  120. submit: function (target) {
  121. var request = {};
  122. request['Wuid'] = this.wuid;
  123. request['Cluster'] = target;
  124. request['rawxml_'] = "1";
  125. var context = this;
  126. xhr.post({
  127. url: this.getBaseURL() + "/WUSubmit",
  128. handleAs: "xml",
  129. content: request,
  130. load: function (xmlDom) {
  131. context.onSubmit();
  132. },
  133. error: function () {
  134. }
  135. });
  136. },
  137. getInfo: function (args) {
  138. var request = {
  139. Wuid: this.wuid,
  140. IncludeExceptions: args.onGetExceptions ? true : false,
  141. IncludeGraphs: args.onGetGraphs ? true : false,
  142. IncludeSourceFiles: false,
  143. IncludeResults: args.onGetResults ? true : false,
  144. IncludeResultsViewNames: false,
  145. IncludeVariables: false,
  146. IncludeTimers: args.onGetTimers ? true : false,
  147. IncludeDebugValues: false,
  148. IncludeApplicationValues: false,
  149. IncludeWorkflows: false,
  150. SuppressResultSchemas: args.onGetResults ? false : true,
  151. rawxml_: true
  152. };
  153. var context = this;
  154. xhr.post({
  155. url: this.getBaseURL() + "/WUInfo",
  156. handleAs: "xml",
  157. content: request,
  158. load: function (xmlDom) {
  159. var workunit = context.getValue(xmlDom, "Workunit", ["ECLException", "ECLResult", "ECLGraph", "ECLTimer", "ECLSchemaItem"]);
  160. if (workunit.Query.Text && args.onGetText) {
  161. context.text = workunit.Query.Text;
  162. args.onGetText(context.text);
  163. }
  164. if (workunit.Exceptions && args.onGetExceptions) {
  165. context.exceptions = workunit.Exceptions;
  166. args.onGetExceptions(context.exceptions);
  167. }
  168. if (workunit.Results && args.onGetResults) {
  169. context.results = [];
  170. var results = workunit.Results;
  171. for (var i = 0; i < results.length; ++i) {
  172. context.results.push(new ESPResult(lang.mixin({ wuid: context.wuid }, results[i])));
  173. }
  174. args.onGetResults(context.results);
  175. }
  176. if (workunit.Timers && args.onGetTimers) {
  177. context.timers = workunit.Timers;
  178. args.onGetTimers(context.timers);
  179. }
  180. if (workunit.Graphs && args.onGetGraphs) {
  181. context.graphs = workunit.Graphs;
  182. args.onGetGraphs(context.graphs)
  183. }
  184. if (args.onGetAll) {
  185. args.onGetAll(workunit);
  186. }
  187. },
  188. error: function () {
  189. }
  190. });
  191. },
  192. fetchText: function (onFetchText) {
  193. if (this.text) {
  194. onFetchText(this.text);
  195. return;
  196. }
  197. this.getInfo({
  198. onGetText: onFetchText
  199. });
  200. },
  201. fetchResults: function (onFetchResults) {
  202. if (this.results && this.results.length) {
  203. onFetchResults(this.results);
  204. return;
  205. }
  206. this.getInfo({
  207. onGetResults: onFetchResults
  208. });
  209. },
  210. fetchGraphs: function (onFetchGraphs) {
  211. if (this.graphs && this.graphs.length) {
  212. onFetchGraphs(this.graphs);
  213. return;
  214. }
  215. this.getInfo({
  216. onGetGraphs: onFetchGraphs
  217. });
  218. },
  219. fetchGraphXgmml: function (idx, onFetchGraphXgmml) {
  220. var request = {};
  221. request['Wuid'] = this.wuid;
  222. request['GraphName'] = this.graphs[idx].Name;
  223. request['rawxml_'] = "1";
  224. var context = this;
  225. xhr.post({
  226. url: this.getBaseURL() + "/WUGetGraph",
  227. handleAs: "xml",
  228. content: request,
  229. load: function (xmlDom) {
  230. context.graphs[idx].xgmml = context.getValue(xmlDom, "Graph");
  231. onFetchGraphXgmml(context.graphs[idx].xgmml);
  232. },
  233. error: function () {
  234. }
  235. });
  236. }
  237. });
  238. });