WsWorkunits.js 11 KB

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