WsWorkunits.js 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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);
  79. },
  80. WUInfo: function (params) {
  81. return ESPRequest.send("WsWorkunits", "WUInfo", params).then(function (response) {
  82. if (lang.exists("Exceptions.Exception", response)) {
  83. arrayUtil.forEach(response.Exceptions.Exception, function (item, idx) {
  84. if (item.Code === 20080) {
  85. lang.mixin(response, {
  86. WUInfoResponse: {
  87. Workunit: {
  88. Wuid: params.request.Wuid,
  89. StateID: 999,
  90. State: "deleted"
  91. }
  92. }
  93. });
  94. }
  95. });
  96. }
  97. return response;
  98. });
  99. },
  100. WUGetGraph: function (params) {
  101. return ESPRequest.send("WsWorkunits", "WUGetGraph", params);
  102. },
  103. WUResult: function (params) {
  104. return ESPRequest.send("WsWorkunits", "WUResult", params);
  105. },
  106. WUFile: function (params) {
  107. lang.mixin(params, {
  108. handleAs: "text"
  109. });
  110. return ESPRequest.send("WsWorkunits", "WUFile", params);
  111. },
  112. WUAction: function (workunits, actionType, callback) {
  113. var request = {
  114. Wuids: workunits,
  115. ActionType: actionType
  116. };
  117. ESPRequest.flattenArray(request, "Wuids", "Wuid");
  118. return ESPRequest.send("WsWorkunits", "WUAction", {
  119. request: request,
  120. load: function (response) {
  121. arrayUtil.forEach(workunits, function (item, index) {
  122. if (item.refresh) { // if action is delete then there will be no refresh
  123. item.refresh();
  124. }
  125. });
  126. if (lang.exists("WUActionResponse.ActionResults.WUActionResult", response)) {
  127. arrayUtil.forEach(response.WUActionResponse.ActionResults.WUActionResult, function (item, index) {
  128. if (item.Result.indexOf("Failed:") === 0) {
  129. dojo.publish("hpcc/brToaster", {
  130. message: "<h4>" + item.Action + " " + item.Wuid + "</h4>" + "<p>" + item.Result + "</p>",
  131. type: "error",
  132. duration: -1
  133. });
  134. }
  135. });
  136. }
  137. if (callback && callback.load) {
  138. callback.load(response);
  139. }
  140. },
  141. error: function (err) {
  142. if (callback && callback.error) {
  143. callback.error(err);
  144. }
  145. }
  146. });
  147. },
  148. // Helpers ---
  149. isComplete: function (stateID, actionEx) {
  150. switch (stateID) {
  151. case 1: //WUStateCompiled
  152. if (actionEx && actionEx == "compile") {
  153. return true;
  154. }
  155. break;
  156. case 3: //WUStateCompleted:
  157. case 4: //WUStateFailed:
  158. case 5: //WUStateArchived:
  159. case 7: //WUStateAborted:
  160. case 999: //WUStateDeleted:
  161. return true;
  162. }
  163. return false;
  164. }
  165. };
  166. });