123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274 |
- /*##############################################################################
- # HPCC SYSTEMS software Copyright (C) 2012 HPCC Systems.
- #
- # Licensed under the Apache License, Version 2.0 (the "License");
- # you may not use this file except in compliance with the License.
- # You may obtain a copy of the License at
- #
- # http://www.apache.org/licenses/LICENSE-2.0
- #
- # Unless required by applicable law or agreed to in writing, software
- # distributed under the License is distributed on an "AS IS" BASIS,
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- # See the License for the specific language governing permissions and
- # limitations under the License.
- ############################################################################## */
- define([
- "dojo/_base/declare",
- "dojo/_base/array",
- "dojo/_base/lang",
- "dojo/store/Memory",
- "dojo/store/Observable",
- "hpcc/WsSMC",
- "hpcc/ESPUtil",
- "hpcc/ESPRequest",
- "hpcc/ESPWorkunit",
- "hpcc/ESPDFUWorkunit"
- ], function (declare, arrayUtil, lang, Memory, Observable,
- WsSMC, ESPUtil, ESPRequest, ESPWorkunit, ESPDFUWorkunit) {
- var Store = declare([Memory], {
- idProperty: "__hpcc_id",
- });
- var Queue = declare([ESPUtil.Singleton, ESPUtil.Monitor], {
- constructor: function (id) {
- this.__hpcc_id = id;
- this._watched = [];
- this.children = Observable(new Memory({
- idProperty: "__hpcc_id",
- parent: this,
- data: []
- }));
- },
- pause: function () {
- return WsSMC.PauseQueue({
- request: {
- QueueName: this.QueueName
- }
- });
- },
- resume: function () {
- return WsSMC.ResumeQueue({
- request: {
- QueueName: this.QueueName
- }
- });
- },
- clear: function () {
- var context = this;
- return WsSMC.ClearQueue({
- request: {
- QueueName: this.QueueName
- }
- }).then(function (response) {
- context.clearChildren();
- return response;
- });
- },
- setPriority: function (wuid, priority) { // high, normal, low
- return WsSMC.SetJobPriority({
- request: {
- QueueName: this.QueueName,
- Wuid: wuid,
- Priority: priority
- }
- });
- },
- moveTop: function (wuid) {
- return WsSMC.MoveJobFront({
- request: {
- QueueName: this.QueueName,
- Wuid: wuid
- }
- });
- },
- moveUp: function (wuid) {
- return WsSMC.MoveJobUp({
- request: {
- QueueName: this.QueueName,
- Wuid: wuid
- }
- });
- },
- moveDown: function (wuid) {
- return WsSMC.MoveJobDown({
- request: {
- QueueName: this.QueueName,
- Wuid: wuid
- }
- });
- },
- moveBottom: function (wuid) {
- return WsSMC.MoveJobBack({
- request: {
- QueueName: this.QueueName,
- Wuid: wuid
- }
- });
- },
- canChildMoveUp: function (id) {
- return (this.getChildIndex(id) > 0);
- },
- canChildMoveDown: function (id) {
- return (this.getChildIndex(id) < this.getChildCount() - 1);
- },
- clearChildren: function () {
- this.children.setData([]);
- this.set("DisplaySize", "");
- },
- addChild: function (wu) {
- wu.set("ESPQueue", this);
- this.children.put(wu, {
- overwrite: true
- });
- if (!this._watched[wu.__hpcc_id]) {
- var context = this;
- this._watched[wu.__hpcc_id] = wu.watch("changedCount", function (name, oldValue, newValue) {
- if (oldValue !== newValue) {
- context.children.notify(wu, wu.__hpcc_id);
- }
- });
- }
- this.set("DisplaySize", this.getChildCount());
- },
- getChild: function (id) {
- return this.children.get(id);
- },
- getChildIndex: function (id) {
- return this.children.index[id];
- },
- getChildCount: function () {
- return this.children.data.length;
- },
- queryChildren: function () {
- return this.children.query();
- }
- });
- var TargetCluster = declare([Queue], {
- getDisplayName: function () {
- return this.ClusterName;
- },
- isPaused: function () {
- switch (this.ClusterStatus) {
- case 1:
- case 2:
- return true;
- }
- return false;
- },
- pause: function () {
- var context = this;
- return this.inherited(arguments).then(function (response) {
- context.updateData({
- ClusterStatus: 2
- });
- return response;
- });
- },
- resume: function () {
- var context = this;
- return this.inherited(arguments).then(function (response) {
- context.updateData({
- ClusterStatus: 0
- });
- return response;
- });
- }
- });
- var ServerJobQueue = declare([Queue], {
- getDisplayName: function () {
- return this.QueueName;
- },
- isPaused: function () {
- if (this.QueueStatus === "paused") {
- return true;
- }
- return false;
- },
- pause: function () {
- var context = this;
- return this.inherited(arguments).then(function (response) {
- context.updateData({
- QueueStatus: "paused"
- });
- return response;
- });
- },
- resume: function () {
- var context = this;
- return this.inherited(arguments).then(function (response) {
- context.updateData({
- QueueStatus: null
- });
- return response;
- });
- }
- });
- var globalQueueStore = null;
- GetGlobalQueueStore = function () {
- if (!globalQueueStore) {
- globalQueueStore = new Store();
- }
- return globalQueueStore;
- }
-
- return {
- isInstanceOfQueue: function (obj) {
- return obj.isInstanceOf(Queue);
- },
- GetTargetCluster: function (name) {
- var store = GetGlobalQueueStore();
- var id = "TargetCluster::" + name;
- var retVal = store.get(id);
- if (!retVal) {
- retVal = new TargetCluster(id);
- store.put(retVal);
- }
- return retVal;
- },
- GetServerJobQueue: function (name) {
- var store = GetGlobalQueueStore();
- var id = "ServerJobQueue::" + name;
- var retVal = store.get(id);
- if (!retVal) {
- retVal = new ServerJobQueue(id);
- store.put(retVal);
- }
- return retVal;
- }
- };
- });
|