WsWorkunits.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  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/array",
  20. "dojo/_base/Deferred",
  21. "dojo/promise/all",
  22. "dojo/store/Observable",
  23. "hpcc/ESPRequest"
  24. ], function (declare, lang, arrayUtil, Deferred, all, Observable,
  25. ESPRequest) {
  26. var EventScheduleStore = declare([ESPRequest.Store], {
  27. service: "WsWorkunits",
  28. action: "WUShowScheduled",
  29. responseQualifier: "WUShowScheduledResponse.Workunits.ScheduledWU",
  30. idProperty: "Wuid"
  31. });
  32. return {
  33. States: {
  34. 0: "unknown",
  35. 1: "compiled",
  36. 2: "running",
  37. 3: "completed",
  38. 4: "aborting",
  39. 5: "aborted",
  40. 6: "blocked",
  41. 7: "submitted",
  42. 8: "wait",
  43. 9: "failed",
  44. 10: "compiling",
  45. 11: "uploading_files",
  46. 12: "debugging",
  47. 13: "debug_running",
  48. 14: "paused",
  49. 999: "deleted"
  50. },
  51. WUCreate: function (params) {
  52. return ESPRequest.send("WsWorkunits", "WUCreate", params);
  53. },
  54. WUUpdate: function (params) {
  55. ESPRequest.flattenMap(params.request, "ApplicationValues")
  56. return ESPRequest.send("WsWorkunits", "WUUpdate", params);
  57. },
  58. WUSubmit: function (params) {
  59. return ESPRequest.send("WsWorkunits", "WUSubmit", params);
  60. },
  61. WUResubmit: function (params) {
  62. return ESPRequest.send("WsWorkunits", "WUResubmit", params);
  63. },
  64. WUQueryDetails: function (params) {
  65. return ESPRequest.send("WsWorkunits", "WUQueryDetails", params);
  66. },
  67. WUGetZAPInfo: function (params) {
  68. return ESPRequest.send("WsWorkunits", "WUGetZAPInfo", params);
  69. },
  70. WUShowScheduled: function (params) {
  71. return ESPRequest.send("WsWorkunits", "WUShowScheduled", params);
  72. },
  73. WUQuerysetAliasAction: function (selection, action) {
  74. var requests = [];
  75. arrayUtil.forEach(selection, function (item, idx) {
  76. var request = {
  77. QuerySetName: item.QuerySetId,
  78. Action: action,
  79. "Aliases.QuerySetAliasActionItem.0.Name": item.Name,
  80. "Aliases.QuerySetAliasActionItem.itemcount": 1
  81. };
  82. requests.push(ESPRequest.send("WsWorkunits", "WUQuerysetAliasAction", {
  83. request: request
  84. }));
  85. });
  86. return all(requests);
  87. },
  88. WUQuerysetQueryAction: function (selection, action) {
  89. if (action === "Deactivate") {
  90. return this.WUQuerysetAliasAction(selection, action);
  91. }
  92. var requests = [];
  93. arrayUtil.forEach(selection, function (item, idx) {
  94. var request = {
  95. QuerySetName: item.QuerySetId,
  96. Action: action,
  97. "Queries.QuerySetQueryActionItem.0.QueryId": item.Id,
  98. "Queries.QuerySetQueryActionItem.itemcount": 1
  99. };
  100. requests.push(ESPRequest.send("WsWorkunits", "WUQuerysetQueryAction", {
  101. request: request
  102. }));
  103. });
  104. return all(requests);
  105. },
  106. CreateQuerySetStore: function (options) {
  107. var store = new QuerySetStore(options);
  108. return Observable(store);
  109. },
  110. WUPublishWorkunit: function (params) {
  111. return ESPRequest.send("WsWorkunits", "WUPublishWorkunit", params).then(function (response) {
  112. if (lang.exists("WUPublishWorkunitResponse", response)) {
  113. if (response.WUPublishWorkunitResponse.ErrorMesssage) {
  114. dojo.publish("hpcc/brToaster", {
  115. Severity: "Error",
  116. Source: service + "." + action,
  117. Exceptions: response.Exceptions
  118. });
  119. } else {
  120. dojo.publish("hpcc/brToaster", {
  121. Severity: "Error",
  122. Source: "WsWorkunits.WUPublishWorkunit",
  123. Exceptions: [{
  124. Source: "Query ID",
  125. Message: response.WUPublishWorkunitResponse.QueryId
  126. }, {
  127. Source: "Query Name",
  128. Message: response.WUPublishWorkunitResponse.QueryName
  129. }, {
  130. Source: "Query Set",
  131. Message: response.WUPublishWorkunitResponse.QuerySet
  132. }]
  133. });
  134. }
  135. }
  136. });
  137. },
  138. WUQuery: function (params) {
  139. return ESPRequest.send("WsWorkunits", "WUQuery", params).then(function (response) {
  140. if (lang.exists("Exceptions.Exception", response)) {
  141. arrayUtil.forEach(response.Exceptions.Exception, function (item, idx) {
  142. if (item.Code === 20081) {
  143. lang.mixin(response, {
  144. WUQueryResponse: {
  145. Workunits: {
  146. ECLWorkunit: [{
  147. Wuid: params.request.Wuid,
  148. StateID: 999,
  149. State: "deleted"
  150. }]
  151. }
  152. }
  153. });
  154. }
  155. });
  156. }
  157. return response;
  158. });
  159. },
  160. WUInfo: function (params) {
  161. return ESPRequest.send("WsWorkunits", "WUInfo", params).then(function (response) {
  162. if (lang.exists("Exceptions.Exception", response)) {
  163. arrayUtil.forEach(response.Exceptions.Exception, function (item, idx) {
  164. if (item.Code === 20080) {
  165. lang.mixin(response, {
  166. WUInfoResponse: {
  167. Workunit: {
  168. Wuid: params.request.Wuid,
  169. StateID: 999,
  170. State: "deleted"
  171. }
  172. }
  173. });
  174. }
  175. });
  176. }
  177. return response;
  178. });
  179. },
  180. WUGetGraph: function (params) {
  181. return ESPRequest.send("WsWorkunits", "WUGetGraph", params);
  182. },
  183. WUResult: function (params) {
  184. return ESPRequest.send("WsWorkunits", "WUResult", params);
  185. },
  186. WUQueryGetGraph: function (params) {
  187. return ESPRequest.send("WsWorkunits", "WUQueryGetGraph", params);
  188. },
  189. WUFile: function (params) {
  190. lang.mixin(params, {
  191. handleAs: "text"
  192. });
  193. return ESPRequest.send("WsWorkunits", "WUFile", params);
  194. },
  195. WUAction: function (workunits, actionType, callback) {
  196. var request = {
  197. Wuids: workunits,
  198. ActionType: actionType
  199. };
  200. ESPRequest.flattenArray(request, "Wuids", "Wuid");
  201. return ESPRequest.send("WsWorkunits", "WUAction", {
  202. request: request,
  203. load: function (response) {
  204. arrayUtil.forEach(workunits, function (item, index) {
  205. if (item.refresh) { // if action is delete then there will be no refresh
  206. item.refresh();
  207. }
  208. });
  209. if (lang.exists("WUActionResponse.ActionResults.WUActionResult", response)) {
  210. arrayUtil.forEach(response.WUActionResponse.ActionResults.WUActionResult, function (item, index) {
  211. if (item.Result.indexOf("Failed:") === 0) {
  212. dojo.publish("hpcc/brToaster", {
  213. Severity: "Error",
  214. Source: "WsWorkunits.WUAction",
  215. Exceptions: [{Source: item.Action + " " + item.Wuid, Message: item.Result}]
  216. });
  217. }
  218. });
  219. }
  220. if (callback && callback.load) {
  221. callback.load(response);
  222. }
  223. },
  224. error: function (err) {
  225. if (callback && callback.error) {
  226. callback.error(err);
  227. }
  228. }
  229. });
  230. },
  231. // Stub waiting for HPCC-10308
  232. visualisations: [
  233. {value: "DojoD3ScatterChart", label: "Scatter Chart"},
  234. {value: "DojoD3BarChart", label: "Bar Chart"},
  235. {value: "DojoD3PieChart", label: "Pie Chart"},
  236. {value: "DojoD3DonutChart", label: "Donut Chart"},
  237. {value: "DojoD3Choropeth", label: "Choropeth"},
  238. {value: "DojoD3CooccurrenceGraph", label: "Co-Occurrence Graph"},
  239. {value: "DojoD3ForceDirectedGraph", label: "Force Directed Graph"},
  240. {value: "DojoD3Histogram", label: "Histogram"}
  241. ],
  242. GetVisualisations: function() {
  243. var deferred = new Deferred();
  244. if (this.visualisations) {
  245. deferred.resolve(this.visualisations);
  246. }
  247. return deferred.promise;
  248. },
  249. CreateEventScheduleStore: function (options) {
  250. var store = new EventScheduleStore(options);
  251. return Observable(store);
  252. },
  253. // Helpers ---
  254. isComplete: function (stateID, actionEx) {
  255. switch (stateID) {
  256. case 1: //WUStateCompiled
  257. if (actionEx && actionEx == "compile") {
  258. return true;
  259. }
  260. break;
  261. case 3: //WUStateCompleted:
  262. case 4: //WUStateFailed:
  263. case 5: //WUStateArchived:
  264. case 7: //WUStateAborted:
  265. case 999: //WUStateDeleted:
  266. return true;
  267. }
  268. return false;
  269. }
  270. };
  271. });