ESPDFUWorkunit.js 9.7 KB

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