ESPWorkunit.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  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. SuppressResultSchemas: args.onGetResults ? false : true,
  150. rawxml_: true
  151. };
  152. var context = this;
  153. xhr.post({
  154. url: this.getBaseURL() + "/WUInfo",
  155. handleAs: "xml",
  156. content: request,
  157. load: function (xmlDom) {
  158. var workunit = context.getValue(xmlDom, "Workunit", ["ECLException", "ECLResult", "ECLGraph", "ECLTimer", "ECLSchemaItem"]);
  159. if (workunit.Query.Text && args.onGetText) {
  160. context.text = workunit.Query.Text;
  161. args.onGetText(context.text);
  162. }
  163. if (workunit.Exceptions && args.onGetExceptions) {
  164. context.exceptions = workunit.Exceptions;
  165. args.onGetExceptions(context.exceptions);
  166. }
  167. if (workunit.Results && args.onGetResults) {
  168. context.results = [];
  169. var results = workunit.Results;
  170. for (var i = 0; i < results.length; ++i) {
  171. context.results.push(new ESPResult(lang.mixin({ wuid: context.wuid }, results[i])));
  172. }
  173. args.onGetResults(context.results);
  174. }
  175. if (workunit.Timers && args.onGetTimers) {
  176. context.timers = workunit.Timers;
  177. args.onGetTimers(context.timers);
  178. }
  179. if (workunit.Graphs && args.onGetGraphs) {
  180. context.graphs = workunit.Graphs;
  181. args.onGetGraphs(context.graphs)
  182. }
  183. if (args.onGetAll) {
  184. args.onGetAll(workunit);
  185. }
  186. },
  187. error: function () {
  188. }
  189. });
  190. },
  191. fetchText: function (onFetchText) {
  192. if (this.text) {
  193. onFetchText(this.text);
  194. return;
  195. }
  196. this.getInfo({
  197. onGetText: onFetchText
  198. });
  199. },
  200. fetchResults: function (onFetchResults) {
  201. if (this.results && this.results.length) {
  202. onFetchResults(this.results);
  203. return;
  204. }
  205. this.getInfo({
  206. onGetResults: onFetchResults
  207. });
  208. },
  209. fetchGraphs: function (onFetchGraphs) {
  210. if (this.graphs && this.graphs.length) {
  211. onFetchGraphs(this.graphs);
  212. return;
  213. }
  214. this.getInfo({
  215. onGetGraphs: onFetchGraphs
  216. });
  217. },
  218. fetchGraphXgmml: function (idx, onFetchGraphXgmml) {
  219. var request = {};
  220. request['Wuid'] = this.wuid;
  221. request['GraphName'] = this.graphs[idx].Name;
  222. request['rawxml_'] = "1";
  223. var context = this;
  224. xhr.post({
  225. url: this.getBaseURL() + "/WUGetGraph",
  226. handleAs: "xml",
  227. content: request,
  228. load: function (xmlDom) {
  229. context.graphs[idx].xgmml = context.getValue(xmlDom, "Graph");
  230. onFetchGraphXgmml(context.graphs[idx].xgmml);
  231. },
  232. error: function () {
  233. }
  234. });
  235. }
  236. });
  237. });