ESPWorkunit.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. /*##############################################################################
  2. # HPCC SYSTEMS software Copyright (C) 2012 HPCC Systems.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. ############################################################################## */
  16. define([
  17. "dojo/_base/declare",
  18. "dojo/_base/lang",
  19. "dojo/_base/xhr",
  20. "hpcc/ESPResult",
  21. "hpcc/ESPBase"
  22. ], function (declare, lang, xhr, ESPResult, ESPBase) {
  23. return declare(ESPBase, {
  24. wuid: "",
  25. stateID: 0,
  26. state: "",
  27. text: "",
  28. resultCount: 0,
  29. results: [],
  30. graphs: [],
  31. exceptions: [],
  32. timers: [],
  33. onCreate: function () {
  34. },
  35. onUpdate: function () {
  36. },
  37. onSubmit: function () {
  38. },
  39. constructor: function (args) {
  40. declare.safeMixin(this, args);
  41. if (!this.wuid) {
  42. this.create();
  43. }
  44. },
  45. isComplete: function () {
  46. switch (this.stateID) {
  47. case '3':
  48. //WUStateCompleted:
  49. case '4':
  50. //WUStateFailed:
  51. case '5':
  52. //WUStateArchived:
  53. case '7':
  54. //WUStateAborted:
  55. return true;
  56. }
  57. return false;
  58. },
  59. monitor: function (callback) {
  60. var request = {};
  61. request['Wuid'] = this.wuid;
  62. request['rawxml_'] = "1";
  63. var context = this;
  64. xhr.post({
  65. url: this.getBaseURL() + "/WUQuery",
  66. handleAs: "xml",
  67. content: request,
  68. load: function (xmlDom) {
  69. var workunit = context.getValue(xmlDom, "ECLWorkunit");
  70. context.stateID = workunit.StateID;
  71. context.state = workunit.State;
  72. if (callback) {
  73. callback(context);
  74. }
  75. if (!context.isComplete()) {
  76. setTimeout(function () {
  77. context.monitor(callback);
  78. }, 200);
  79. }
  80. },
  81. error: function () {
  82. done = true;
  83. }
  84. });
  85. },
  86. create: function (ecl) {
  87. var request = {};
  88. request['rawxml_'] = "1";
  89. var context = this;
  90. xhr.post({
  91. url: this.getBaseURL() + "/WUCreate",
  92. handleAs: "xml",
  93. content: request,
  94. load: function (xmlDom) {
  95. context.wuid = context.getValue(xmlDom, "Wuid");
  96. context.onCreate();
  97. },
  98. error: function () {
  99. }
  100. });
  101. },
  102. update: function (ecl) {
  103. var request = {};
  104. request['Wuid'] = this.wuid;
  105. request['QueryText'] = ecl;
  106. request['rawxml_'] = "1";
  107. var context = this;
  108. xhr.post({
  109. url: this.getBaseURL() + "/WUUpdate",
  110. handleAs: "xml",
  111. content: request,
  112. load: function (xmlDom) {
  113. context.onUpdate();
  114. },
  115. error: function () {
  116. }
  117. });
  118. },
  119. submit: function (target) {
  120. var request = {};
  121. request['Wuid'] = this.wuid;
  122. request['Cluster'] = target;
  123. request['rawxml_'] = "1";
  124. var context = this;
  125. xhr.post({
  126. url: this.getBaseURL() + "/WUSubmit",
  127. handleAs: "xml",
  128. content: request,
  129. load: function (xmlDom) {
  130. context.onSubmit();
  131. },
  132. error: function () {
  133. }
  134. });
  135. },
  136. getInfo: function (args) {
  137. var request = {
  138. Wuid: this.wuid,
  139. IncludeExceptions: args.onGetExceptions ? true : false,
  140. IncludeGraphs: args.onGetGraphs ? true : false,
  141. IncludeSourceFiles: false,
  142. IncludeResults: args.onGetResults ? true : false,
  143. IncludeResultsViewNames: false,
  144. IncludeVariables: false,
  145. IncludeTimers: args.onGetTimers ? true : false,
  146. IncludeDebugValues: false,
  147. IncludeApplicationValues: false,
  148. IncludeWorkflows: false,
  149. IncludeXmlSchemas: args.onGetResults ? true : 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. });