ESPQueue.js 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  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/array",
  19. "dojo/_base/lang",
  20. "dojo/store/Memory",
  21. "dojo/store/Observable",
  22. "hpcc/WsSMC",
  23. "hpcc/ESPUtil",
  24. "hpcc/ESPRequest",
  25. "hpcc/ESPWorkunit",
  26. "hpcc/ESPDFUWorkunit"
  27. ], function (declare, arrayUtil, lang, Memory, Observable,
  28. WsSMC, ESPUtil, ESPRequest, ESPWorkunit, ESPDFUWorkunit) {
  29. var Store = declare([Memory], {
  30. idProperty: "__hpcc_id",
  31. });
  32. var Queue = declare([ESPUtil.Singleton, ESPUtil.Monitor], {
  33. constructor: function (id) {
  34. this.__hpcc_id = id;
  35. this._watched = [];
  36. this.children = Observable(new Memory({
  37. idProperty: "__hpcc_id",
  38. parent: this,
  39. data: []
  40. }));
  41. },
  42. pause: function () {
  43. return WsSMC.PauseQueue({
  44. request: {
  45. QueueName: this.QueueName
  46. }
  47. });
  48. },
  49. resume: function () {
  50. return WsSMC.ResumeQueue({
  51. request: {
  52. QueueName: this.QueueName
  53. }
  54. });
  55. },
  56. clear: function () {
  57. var context = this;
  58. return WsSMC.ClearQueue({
  59. request: {
  60. QueueName: this.QueueName
  61. }
  62. }).then(function (response) {
  63. context.clearChildren();
  64. return response;
  65. });
  66. },
  67. setPriority: function (wuid, priority) { // high, normal, low
  68. return WsSMC.SetJobPriority({
  69. request: {
  70. QueueName: this.QueueName,
  71. Wuid: wuid,
  72. Priority: priority
  73. }
  74. });
  75. },
  76. moveTop: function (wuid) {
  77. return WsSMC.MoveJobFront({
  78. request: {
  79. QueueName: this.QueueName,
  80. Wuid: wuid
  81. }
  82. });
  83. },
  84. moveUp: function (wuid) {
  85. return WsSMC.MoveJobUp({
  86. request: {
  87. QueueName: this.QueueName,
  88. Wuid: wuid
  89. }
  90. });
  91. },
  92. moveDown: function (wuid) {
  93. return WsSMC.MoveJobDown({
  94. request: {
  95. QueueName: this.QueueName,
  96. Wuid: wuid
  97. }
  98. });
  99. },
  100. moveBottom: function (wuid) {
  101. return WsSMC.MoveJobBack({
  102. request: {
  103. QueueName: this.QueueName,
  104. Wuid: wuid
  105. }
  106. });
  107. },
  108. canChildMoveUp: function (id) {
  109. return (this.getChildIndex(id) > 0);
  110. },
  111. canChildMoveDown: function (id) {
  112. return (this.getChildIndex(id) < this.getChildCount() - 1);
  113. },
  114. clearChildren: function () {
  115. this.children.setData([]);
  116. this.set("DisplaySize", "");
  117. },
  118. addChild: function (wu) {
  119. wu.set("ESPQueue", this);
  120. this.children.put(wu, {
  121. overwrite: true
  122. });
  123. if (!this._watched[wu.__hpcc_id]) {
  124. var context = this;
  125. this._watched[wu.__hpcc_id] = wu.watch("changedCount", function (name, oldValue, newValue) {
  126. if (oldValue !== newValue) {
  127. context.children.notify(wu, wu.__hpcc_id);
  128. }
  129. });
  130. }
  131. this.set("DisplaySize", this.getChildCount());
  132. },
  133. getChild: function (id) {
  134. return this.children.get(id);
  135. },
  136. getChildIndex: function (id) {
  137. return this.children.index[id];
  138. },
  139. getChildCount: function () {
  140. return this.children.data.length;
  141. },
  142. queryChildren: function () {
  143. return this.children.query();
  144. }
  145. });
  146. var TargetCluster = declare([Queue], {
  147. getDisplayName: function () {
  148. return this.ClusterName;
  149. },
  150. isPaused: function () {
  151. switch (this.ClusterStatus) {
  152. case 1:
  153. case 2:
  154. return true;
  155. }
  156. return false;
  157. },
  158. pause: function () {
  159. var context = this;
  160. return this.inherited(arguments).then(function (response) {
  161. context.updateData({
  162. ClusterStatus: 2
  163. });
  164. return response;
  165. });
  166. },
  167. resume: function () {
  168. var context = this;
  169. return this.inherited(arguments).then(function (response) {
  170. context.updateData({
  171. ClusterStatus: 0
  172. });
  173. return response;
  174. });
  175. }
  176. });
  177. var ServerJobQueue = declare([Queue], {
  178. getDisplayName: function () {
  179. return this.QueueName;
  180. },
  181. isPaused: function () {
  182. if (this.QueueStatus === "paused") {
  183. return true;
  184. }
  185. return false;
  186. },
  187. pause: function () {
  188. var context = this;
  189. return this.inherited(arguments).then(function (response) {
  190. context.updateData({
  191. QueueStatus: "paused"
  192. });
  193. return response;
  194. });
  195. },
  196. resume: function () {
  197. var context = this;
  198. return this.inherited(arguments).then(function (response) {
  199. context.updateData({
  200. QueueStatus: null
  201. });
  202. return response;
  203. });
  204. }
  205. });
  206. var globalQueueStore = null;
  207. GetGlobalQueueStore = function () {
  208. if (!globalQueueStore) {
  209. globalQueueStore = new Store();
  210. }
  211. return globalQueueStore;
  212. }
  213. return {
  214. isInstanceOfQueue: function (obj) {
  215. return obj.isInstanceOf(Queue);
  216. },
  217. GetTargetCluster: function (name) {
  218. var store = GetGlobalQueueStore();
  219. var id = "TargetCluster::" + name;
  220. var retVal = store.get(id);
  221. if (!retVal) {
  222. retVal = new TargetCluster(id);
  223. store.put(retVal);
  224. }
  225. return retVal;
  226. },
  227. GetServerJobQueue: function (name) {
  228. var store = GetGlobalQueueStore();
  229. var id = "ServerJobQueue::" + name;
  230. var retVal = store.get(id);
  231. if (!retVal) {
  232. retVal = new ServerJobQueue(id);
  233. store.put(retVal);
  234. }
  235. return retVal;
  236. }
  237. };
  238. });