ESPDFUWorkunit.js 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  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/array",
  19. "dojo/_base/lang",
  20. "dojo/_base/Deferred",
  21. "dojo/data/ObjectStore",
  22. "dojo/store/util/QueryResults",
  23. "dojo/store/Observable",
  24. "hpcc/FileSpray",
  25. "hpcc/ESPUtil",
  26. "hpcc/ESPRequest",
  27. "hpcc/ESPResult"
  28. ], function (declare, arrayUtil, lang, Deferred, ObjectStore, QueryResults, Observable,
  29. FileSpray, ESPUtil, ESPRequest, ESPResult) {
  30. var Store = declare([ESPRequest.Store], {
  31. service: "FileSpray",
  32. action: "GetDFUWorkunits",
  33. responseQualifier: "GetDFUWorkunitsResponse.results.DFUWorkunit",
  34. responseTotalQualifier: "GetDFUWorkunitsResponse.NumWUs",
  35. idProperty: "ID",
  36. startProperty: "PageStartFrom",
  37. countProperty: "PageSize",
  38. _watched: [],
  39. preRequest: function (request) {
  40. switch (request.Sortby) {
  41. case "ClusterName":
  42. request.Sortby = "Cluster";
  43. break;
  44. case "JobName":
  45. request.Sortby = "Jobname";
  46. break;
  47. case "Command":
  48. request.Sortby = "Type";
  49. break;
  50. case "StateMessage":
  51. request.Sortby = "State";
  52. break;
  53. }
  54. },
  55. create: function (id) {
  56. return new Workunit({
  57. ID: id,
  58. Wuid: id
  59. });
  60. },
  61. update: function (id, item) {
  62. var storeItem = this.get(id);
  63. storeItem.updateData(item);
  64. if (!this._watched[id]) {
  65. var context = this;
  66. this._watched[id] = storeItem.watch("changedCount", function (name, oldValue, newValue) {
  67. if (oldValue !== newValue) {
  68. context.notify(storeItem, id);
  69. }
  70. });
  71. }
  72. }
  73. });
  74. var Workunit = declare([ESPUtil.Singleton, ESPUtil.Monitor], {
  75. // Asserts ---
  76. _assertHasWuid: function () {
  77. if (!this.Wuid) {
  78. throw new Error("Wuid cannot be empty.");
  79. }
  80. },
  81. // Attributes ---
  82. Wuid: "",
  83. text: "",
  84. resultCount: 0,
  85. results: [],
  86. graphs: [],
  87. exceptions: [],
  88. timers: [],
  89. _StateSetter: function (state) {
  90. this.State = state;
  91. this.set("hasCompleted", FileSpray.isComplete(this.State));
  92. },
  93. _CommandSetter: function (command) {
  94. this.Command = command;
  95. if (command in FileSpray.CommandMessages) {
  96. this.set("CommandMessage", FileSpray.CommandMessages[command]);
  97. } else {
  98. this.set("CommandMessage", "Unknown (" + command + ")");
  99. }
  100. },
  101. _SourceFormatSetter: function (format) {
  102. this.SourceFormat = format;
  103. if (format in FileSpray.FormatMessages) {
  104. this.set("SourceFormatMessage", FileSpray.FormatMessages[format]);
  105. } else {
  106. this.set("SourceFormatMessage", "Unknown (" + format + ")");
  107. }
  108. },
  109. _DestFormatSetter: function (format) {
  110. this.DestFormat = format;
  111. if (format in FileSpray.FormatMessages) {
  112. this.set("DestFormatMessage", FileSpray.FormatMessages[format]);
  113. } else {
  114. this.set("DestFormatMessage", "Unknown (" + format + ")");
  115. }
  116. },
  117. onCreate: function () {
  118. },
  119. onUpdate: function () {
  120. },
  121. onSubmit: function () {
  122. },
  123. constructor: function (args) {
  124. this.inherited(arguments);
  125. declare.safeMixin(this, args);
  126. this.wu = this;
  127. },
  128. isComplete: function () {
  129. return this.hasCompleted;
  130. },
  131. monitor: function (callback) {
  132. if (callback) {
  133. callback(this);
  134. }
  135. if (!this.hasCompleted) {
  136. var context = this;
  137. this.watch("changedCount", function (name, oldValue, newValue) {
  138. if (oldValue !== newValue && newValue) {
  139. if (callback) {
  140. callback(context);
  141. }
  142. }
  143. });
  144. }
  145. },
  146. create: function (ecl) {
  147. },
  148. update: function (request) {
  149. this._assertHasWuid();
  150. lang.mixin(request, {
  151. ID: this.Wuid
  152. });
  153. var outerRequest = {
  154. "wu.ID": request.ID,
  155. "wu.isProtected": request.isProtected,
  156. "wu.JobName": request.JobName,
  157. isProtectedOrig: this.isProtected,
  158. JobNameOrig: this.JobName
  159. };
  160. var context = this;
  161. FileSpray.UpdateDFUWorkunit({
  162. request: outerRequest,
  163. load: function (response) {
  164. context.refresh();
  165. }
  166. });
  167. },
  168. submit: function (target) {
  169. },
  170. fetchXML: function (onFetchXML) {
  171. FileSpray.DFUWUFile({
  172. request: {
  173. Wuid: this.Wuid
  174. },
  175. load: function (response) {
  176. onFetchXML(response);
  177. }
  178. });
  179. },
  180. _resubmit: function (clone, resetWorkflow, callback) {
  181. },
  182. resubmit: function (callback) {
  183. },
  184. _action: function (action, callback) {
  185. },
  186. abort: function (callback) {
  187. },
  188. doDelete: function (callback) {
  189. },
  190. refresh: function (full) {
  191. this.getInfo({
  192. onAfterSend: function () {
  193. }
  194. });
  195. },
  196. getInfo: function (args) {
  197. this._assertHasWuid();
  198. var context = this;
  199. FileSpray.GetDFUWorkunit({
  200. request: {
  201. wuid: this.Wuid
  202. },
  203. load: function (response) {
  204. if (lang.exists("GetDFUWorkunitResponse.result", response)) {
  205. context.updateData(response.GetDFUWorkunitResponse.result);
  206. if (args.onAfterSend) {
  207. args.onAfterSend(context);
  208. }
  209. }
  210. }
  211. });
  212. },
  213. getState: function () {
  214. return this.State;
  215. },
  216. getProtectedImage: function () {
  217. if (this.isProtected) {
  218. return "img/locked.png"
  219. }
  220. return "img/unlocked.png"
  221. },
  222. getStateIconClass: function () {
  223. switch (this.StateID) {
  224. case 1:
  225. return "iconWarning";
  226. case 2:
  227. return "iconSubmitted";
  228. case 3:
  229. return "iconRunning";
  230. case 4:
  231. return "iconFailed";
  232. case 5:
  233. return "iconFailed";
  234. case 6:
  235. return "iconCompleted";
  236. case 7:
  237. return "iconRunning";
  238. case 8:
  239. return "iconAborting";
  240. case 999:
  241. return "iconDeleted";
  242. }
  243. return "iconWorkunit";
  244. },
  245. getStateImage: function () {
  246. switch (this.State) {
  247. case 1:
  248. return "img/workunit_warning.png";
  249. case 2:
  250. return "img/workunit_submitted.png";
  251. case 3:
  252. return "img/workunit_running.png";
  253. case 4:
  254. return "img/workunit_failed.png";
  255. case 5:
  256. return "img/workunit_failed.png";
  257. case 6:
  258. return "img/workunit_completed.png";
  259. case 7:
  260. return "img/workunit_running.png";
  261. case 8:
  262. return "img/workunit_aborting.png";
  263. }
  264. return "img/workunit.png";
  265. }
  266. });
  267. return {
  268. Get: function (wuid) {
  269. var store = new Store();
  270. return store.get(wuid);
  271. },
  272. CreateWUQueryStore: function (options) {
  273. var store = new Store(options);
  274. store = Observable(store);
  275. return store;
  276. },
  277. CreateWUQueryObjectStore: function (options) {
  278. var objStore = new ObjectStore({
  279. objectStore: this.CreateWUQueryStore()
  280. });
  281. return objStore;
  282. }
  283. };
  284. });