WsWorkunits.js 9.8 KB

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