WsWorkunits.js 7.8 KB

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