WsWorkunits.js 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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. message: "<h4>Publish " + response.WUPublishWorkunitResponse.Wuid + "</h4>" + "<p>" + response.WUPublishWorkunitResponse.ErrorMesssage + "</p>",
  61. type: "error",
  62. duration: -1
  63. });
  64. } else {
  65. dojo.publish("hpcc/brToaster", {
  66. message: "<h4>Publish " + response.WUPublishWorkunitResponse.Wuid + "</h4>" + "<p><ul>" +
  67. "<li>Query ID: " + response.WUPublishWorkunitResponse.QueryId + "</li>" +
  68. "<li>Query Name: " + response.WUPublishWorkunitResponse.QueryName + "</li>" +
  69. "<li>Query Set: " + response.WUPublishWorkunitResponse.QuerySet + "</li>" +
  70. "</ul></p>",
  71. type: "message"
  72. });
  73. }
  74. }
  75. });
  76. },
  77. WUQuery: function (params) {
  78. return ESPRequest.send("WsWorkunits", "WUQuery", params).then(function (response) {
  79. if (lang.exists("Exceptions.Exception", response)) {
  80. arrayUtil.forEach(response.Exceptions.Exception, function (item, idx) {
  81. if (item.Code === 20081) {
  82. lang.mixin(response, {
  83. WUQueryResponse: {
  84. Workunit: {
  85. Wuid: params.request.Wuid,
  86. StateID: 999,
  87. State: "deleted"
  88. }
  89. }
  90. });
  91. }
  92. });
  93. }
  94. return response;
  95. });
  96. },
  97. WUInfo: function (params) {
  98. return ESPRequest.send("WsWorkunits", "WUInfo", params).then(function (response) {
  99. if (lang.exists("Exceptions.Exception", response)) {
  100. arrayUtil.forEach(response.Exceptions.Exception, function (item, idx) {
  101. if (item.Code === 20080) {
  102. lang.mixin(response, {
  103. WUInfoResponse: {
  104. Workunit: {
  105. Wuid: params.request.Wuid,
  106. StateID: 999,
  107. State: "deleted"
  108. }
  109. }
  110. });
  111. }
  112. });
  113. }
  114. return response;
  115. });
  116. },
  117. WUGetGraph: function (params) {
  118. return ESPRequest.send("WsWorkunits", "WUGetGraph", params);
  119. },
  120. WUResult: function (params) {
  121. return ESPRequest.send("WsWorkunits", "WUResult", params);
  122. },
  123. WUFile: function (params) {
  124. lang.mixin(params, {
  125. handleAs: "text"
  126. });
  127. return ESPRequest.send("WsWorkunits", "WUFile", params);
  128. },
  129. WUAction: function (workunits, actionType, callback) {
  130. var request = {
  131. Wuids: workunits,
  132. ActionType: actionType
  133. };
  134. ESPRequest.flattenArray(request, "Wuids", "Wuid");
  135. return ESPRequest.send("WsWorkunits", "WUAction", {
  136. request: request,
  137. load: function (response) {
  138. arrayUtil.forEach(workunits, function (item, index) {
  139. if (item.refresh) { // if action is delete then there will be no refresh
  140. item.refresh();
  141. }
  142. });
  143. if (lang.exists("WUActionResponse.ActionResults.WUActionResult", response)) {
  144. arrayUtil.forEach(response.WUActionResponse.ActionResults.WUActionResult, function (item, index) {
  145. if (item.Result.indexOf("Failed:") === 0) {
  146. dojo.publish("hpcc/brToaster", {
  147. message: "<h4>" + item.Action + " " + item.Wuid + "</h4>" + "<p>" + item.Result + "</p>",
  148. type: "error",
  149. duration: -1
  150. });
  151. }
  152. });
  153. }
  154. if (callback && callback.load) {
  155. callback.load(response);
  156. }
  157. },
  158. error: function (err) {
  159. if (callback && callback.error) {
  160. callback.error(err);
  161. }
  162. }
  163. });
  164. },
  165. // Helpers ---
  166. isComplete: function (stateID, actionEx) {
  167. switch (stateID) {
  168. case 1: //WUStateCompiled
  169. if (actionEx && actionEx == "compile") {
  170. return true;
  171. }
  172. break;
  173. case 3: //WUStateCompleted:
  174. case 4: //WUStateFailed:
  175. case 5: //WUStateArchived:
  176. case 7: //WUStateAborted:
  177. case 999: //WUStateDeleted:
  178. return true;
  179. }
  180. return false;
  181. }
  182. };
  183. });