123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207 |
- /*##############################################################################
- # 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 _workunits = {};
- var Store = declare([Memory], {
- idProperty: "__hpcc_id",
- mayHaveChildren: function (item) {
- return (item.children && item.children.length)
- },
- getChildren: function (parent, options) {
- var store = Observable(new Memory({
- idProperty: "__hpcc_id",
- parent: parent,
- _watched: [],
- data: []
- }));
- arrayUtil.forEach(parent.children, function (item, idx) {
- var wu = item.Server === "DFUserver" ? ESPDFUWorkunit.Get(item.Wuid) : ESPWorkunit.Get(item.Wuid);
- wu.updateData(item);
- try {
- store.add(wu);
- if (!store._watched[item.Wuid]) {
- store._watched[item.Wuid] = wu.watch("changedCount", function (name, oldValue, newValue) {
- if (oldValue !== newValue) {
- store.notify(wu, item.__hpcc_id);
- }
- });
- }
- } catch (e) {
- }
- });
- return store.query();
- }
- });
- var Activity = declare([ESPUtil.Singleton, ESPUtil.Monitor], {
- // Asserts ---
- _assertHasWuid: function () {
- if (!this.Wuid) {
- throw new Error("Wuid cannot be empty.");
- }
- },
- // Attributes ---
- _StateIDSetter: function (StateID) {
- this.StateID = StateID;
- var actionEx = lang.exists("ActionEx", this) ? this.ActionEx : null;
- this.set("hasCompleted", WsWorkunits.isComplete(this.StateID, actionEx));
- },
- // --- --- ---
- constructor: function (args) {
- this.inherited(arguments);
- this.store = new Store();
- this.observableStore = new Observable(this.store)
- },
- monitor: function (callback) {
- if (callback && this.changedCount) {
- callback(this);
- }
- if (!this.hasCompleted) {
- var context = this;
- this.watch("changedCount", function (name, oldValue, newValue) {
- if (oldValue !== newValue && newValue) {
- if (callback) {
- callback(context);
- }
- }
- });
- }
- },
- getActivity: function (request) {
- var context = this;
- return WsSMC.Activity({
- request: request
- }).then(function (response) {
- if (lang.exists("ActivityResponse", response)) {
- context.updateData(response.ActivityResponse);
- var targetClusters = [];
- var targetClusterMap = {};
- context.refreshTargetClusters("HThorClusterList.TargetCluster", targetClusters, targetClusterMap);
- context.refreshTargetClusters("ThorClusterList.TargetCluster", targetClusters, targetClusterMap);
- context.refreshTargetClusters("RoxieClusterList.TargetCluster", targetClusters, targetClusterMap);
- context.refreshServerJobQueue("ServerJobQueues.ServerJobQueue", targetClusters, targetClusterMap);
- context.refreshActiveWorkunits("Running.ActiveWorkunit", targetClusters, targetClusterMap);
- context.store.setData(targetClusters);
- context.updateData({
- targetClusters: targetClusters
- });
- }
- return response;
- });
- },
- setBanner: function (bannerText) {
- this.getActivity({
- FromSubmitBtn: true,
- BannerAction: bannerText != "",
- EnableChatURL: 0,
- BannerContent: bannerText,
- BannerColor: "red",
- BannerSize: 4,
- BannerScroll: 2
- });
- },
- refreshTargetClusters: function (targetClusterStr, targetClusters, targetClusterMap) {
- if (lang.exists(targetClusterStr, this)) {
- arrayUtil.forEach(lang.getObject(targetClusterStr, false, this), function (item, idx) {
- item["__hpcc_type"] = "TargetCluster";
- item["__hpcc_id"] = item.ClusterName;
- item.children = [];
- targetClusters.push(item);
- targetClusterMap[item.ClusterName] = item;
- });
- }
- },
- refreshServerJobQueue: function (serverJobQueueStr, targetClusters, targetClusterMap) {
- if (lang.exists(serverJobQueueStr, this)) {
- arrayUtil.forEach(lang.getObject(serverJobQueueStr, false, this), function (item, idx) {
- item["__hpcc_type"] = "TargetCluster";
- item["__hpcc_id"] = item.QueueName;
- item.children = [];
- targetClusters.push(item);
- targetClusterMap[item.QueueName] = item;
- });
- }
- },
- refreshActiveWorkunits: function (activeWorkunitsStr, targetClusters, targetClusterMap) {
- if (lang.exists(activeWorkunitsStr, this)) {
- arrayUtil.forEach(lang.getObject(activeWorkunitsStr, false, this), function (item, idx) {
- item["__hpcc_id"] = item.Wuid;
- targetClusterMap[item.ClusterName ? item.ClusterName : item.QueueName].children.push(item);
- });
- }
- },
- inRefresh: false,
- refresh: function (full) {
- var context = this;
- if (this.inRefresh) {
- return;
- }
- this.inRefresh = true;
- this.getActivity({
- }).then(function (response) {
- context.inRefresh = false;
- }, function (err) {
- context.inRefresh = false;
- });
- },
- getStore: function () {
- return this.observableStore;
- }
- });
- var globalActivity = null;
- return {
- Get: function () {
- if (!globalActivity) {
- globalActivity = new Activity;
- globalActivity.startMonitor();
- globalActivity.refresh();
- }
- return globalActivity;
- },
- CreateActivityStore: function (options) {
- var store = new Store(options);
- return Observable(store);
- }
- };
- });
|