You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by sb...@apache.org on 2017/05/05 09:45:33 UTC

[22/50] [abbrv] ignite git commit: IGNITE-5143 Fixed agent watch logic.

IGNITE-5143 Fixed agent watch logic.


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/2436b934
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/2436b934
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/2436b934

Branch: refs/heads/ignite-5009
Commit: 2436b93411dc84c10672b86534ad23816db4c03a
Parents: 1a33948
Author: Andrey Novikov <an...@gridgain.com>
Authored: Wed May 3 16:50:16 2017 +0700
Committer: Andrey Novikov <an...@gridgain.com>
Committed: Wed May 3 16:50:16 2017 +0700

----------------------------------------------------------------------
 .../web-console/backend/app/browsersHandler.js  |  6 +-
 .../app/modules/agent/AgentManager.service.js   | 73 ++++++++++++++++----
 .../frontend/app/modules/demo/Demo.module.js    |  2 +-
 .../frontend/app/modules/sql/sql.controller.js  |  8 +--
 .../frontend/controllers/domains-controller.js  |  2 +-
 5 files changed, 69 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/2436b934/modules/web-console/backend/app/browsersHandler.js
----------------------------------------------------------------------
diff --git a/modules/web-console/backend/app/browsersHandler.js b/modules/web-console/backend/app/browsersHandler.js
index 4a03abe..66ac5f8 100644
--- a/modules/web-console/backend/app/browsersHandler.js
+++ b/modules/web-console/backend/app/browsersHandler.js
@@ -115,15 +115,15 @@ module.exports.factory = (_, socketio, configure, errors) => {
                         acc.hasDemo |= _.get(agentSock, 'demo.enabled');
 
                         if (agentSock.cluster) {
-                            acc.clusters.add({
+                            acc.clusters.push({
                                 id: agentSock.cluster.id
                             });
                         }
 
                         return acc;
-                    }, {count: 0, hasDemo: false, clusters: new Set()});
+                    }, {count: 0, hasDemo: false, clusters: []});
 
-                    stat.clusters = Array.from(stat.clusters);
+                    stat.clusters = _.uniqWith(stat.clusters, _.isEqual);
 
                     return stat;
                 })

http://git-wip-us.apache.org/repos/asf/ignite/blob/2436b934/modules/web-console/frontend/app/modules/agent/AgentManager.service.js
----------------------------------------------------------------------
diff --git a/modules/web-console/frontend/app/modules/agent/AgentManager.service.js b/modules/web-console/frontend/app/modules/agent/AgentManager.service.js
index db8b493..cb77832 100644
--- a/modules/web-console/frontend/app/modules/agent/AgentManager.service.js
+++ b/modules/web-console/frontend/app/modules/agent/AgentManager.service.js
@@ -41,7 +41,7 @@ export default class IgniteAgentManager {
 
         this.clusters = [];
 
-        $root.$on('$stateChangeSuccess', _.bind(this.stopWatch, this));
+        $root.$on('$stateChangeSuccess', () => this.stopWatch());
 
         /**
          * Connection to backend.
@@ -128,20 +128,29 @@ export default class IgniteAgentManager {
     }
 
     /**
+     * @param states
      * @returns {Promise}
      */
-    awaitAgent() {
-        this.latchAwaitAgent = this.$q.defer();
+    awaitConnectionState(...states) {
+        this.latchAwaitStates = this.$q.defer();
 
         this.offAwaitAgent = this.$root.$watch(() => this.connectionState, (state) => {
-            if (state === State.CONNECTED) {
+            if (_.includes(states, state)) {
                 this.offAwaitAgent();
 
-                this.latchAwaitAgent.resolve();
+                this.latchAwaitStates.resolve();
             }
         });
 
-        return this.latchAwaitAgent.promise;
+        return this.latchAwaitStates.promise;
+    }
+
+    awaitCluster() {
+        return this.awaitConnectionState(State.CONNECTED);
+    }
+
+    awaitAgent() {
+        return this.awaitConnectionState(State.CONNECTED, State.CLUSTER_DISCONNECTED);
     }
 
     /**
@@ -149,7 +158,7 @@ export default class IgniteAgentManager {
      * @param {String} [backState]
      * @returns {Promise}
      */
-    startWatch(backText, backState) {
+    startAgentWatch(backText, backState) {
         const self = this;
 
         self.backText = backText;
@@ -163,27 +172,65 @@ export default class IgniteAgentManager {
 
         self.offStateWatch = this.$root.$watch(() => self.connectionState, (state) => {
             switch (state) {
+                case State.CONNECTED:
+                case State.CLUSTER_DISCONNECTED:
+                    this.AgentModal.hide();
+
+                    break;
+
                 case State.AGENT_DISCONNECTED:
                     this.AgentModal.agentDisconnected(self.backText, self.backState);
 
                     break;
 
-                case State.CLUSTER_DISCONNECTED:
-                    self.AgentModal.clusterDisconnected(self.backText, self.backState);
+                default:
+                    // Connection to backend is not established yet.
+            }
+        });
 
-                    break;
+        return self.awaitAgent();
+    }
+
+    /**
+     * @param {String} backText
+     * @param {String} [backState]
+     * @returns {Promise}
+     */
+    startClusterWatch(backText, backState) {
+        const self = this;
 
+        self.backText = backText;
+        self.backState = backState;
+
+        if (_.nonEmpty(self.clusters) && _.get(self.cluster, 'disconnect') === true) {
+            self.cluster = _.head(self.clusters);
+
+            self.connectionState = State.CONNECTED;
+        }
+
+        self.offStateWatch = this.$root.$watch(() => self.connectionState, (state) => {
+            switch (state) {
                 case State.CONNECTED:
                     this.AgentModal.hide();
 
                     break;
 
+                case State.AGENT_DISCONNECTED:
+                    this.AgentModal.agentDisconnected(self.backText, self.backState);
+
+                    break;
+
+                case State.CLUSTER_DISCONNECTED:
+                    self.AgentModal.clusterDisconnected(self.backText, self.backState);
+
+                    break;
+
                 default:
                     // Connection to backend is not established yet.
             }
         });
 
-        return self.awaitAgent();
+        return self.awaitCluster();
     }
 
     stopWatch() {
@@ -194,10 +241,10 @@ export default class IgniteAgentManager {
 
         this.AgentModal.hide();
 
-        if (this.latchAwaitAgent) {
+        if (this.latchAwaitStates) {
             this.offAwaitAgent();
 
-            this.latchAwaitAgent.reject('Agent watch stopped.');
+            this.latchAwaitStates.reject('Agent watch stopped.');
         }
     }
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/2436b934/modules/web-console/frontend/app/modules/demo/Demo.module.js
----------------------------------------------------------------------
diff --git a/modules/web-console/frontend/app/modules/demo/Demo.module.js b/modules/web-console/frontend/app/modules/demo/Demo.module.js
index 99ea2cb..1de45cd 100644
--- a/modules/web-console/frontend/app/modules/demo/Demo.module.js
+++ b/modules/web-console/frontend/app/modules/demo/Demo.module.js
@@ -165,7 +165,7 @@ angular
 
             return dialog.$promise
                 .then(dialog.show)
-                .then(() => Promise.race([agentMgr.awaitAgent(), closePromise.promise]))
+                .then(() => Promise.race([agentMgr.awaitCluster(), closePromise.promise]))
                 .then(() => scope.hasAgents = true);
         }
     };

http://git-wip-us.apache.org/repos/asf/ignite/blob/2436b934/modules/web-console/frontend/app/modules/sql/sql.controller.js
----------------------------------------------------------------------
diff --git a/modules/web-console/frontend/app/modules/sql/sql.controller.js b/modules/web-console/frontend/app/modules/sql/sql.controller.js
index c86ab6b..3806351 100644
--- a/modules/web-console/frontend/app/modules/sql/sql.controller.js
+++ b/modules/web-console/frontend/app/modules/sql/sql.controller.js
@@ -887,7 +887,7 @@ export default ['$rootScope', '$scope', '$http', '$q', '$timeout', '$interval',
                 .catch((err) => Messages.showError(err));
 
         const _startWatch = () =>
-            agentMgr.startWatch('Back to Configuration', 'base.configuration.clusters')
+            agentMgr.startClusterWatch('Back to Configuration', 'base.configuration.clusters')
                 .then(() => Loading.start('sqlLoading'))
                 .then(_refreshFn)
                 .then(() => Loading.finish('sqlLoading'))
@@ -1336,12 +1336,12 @@ export default ['$rootScope', '$scope', '$http', '$q', '$timeout', '$interval',
         const _executeRefresh = (paragraph) => {
             const args = paragraph.queryArgs;
 
-            agentMgr.awaitAgent()
+            agentMgr.awaitCluster()
                 .then(() => _closeOldQuery(paragraph))
                 .then(() => args.localNid || _chooseNode(args.cacheName, false))
                 .then((nid) => agentMgr.querySql(nid, args.cacheName, args.query, args.nonCollocatedJoins,
                     args.enforceJoinOrder, false, !!args.localNid, args.pageSize))
-                .then(_processQueryResult.bind(this, paragraph, false))
+                .then((res) => _processQueryResult(paragraph, false, res))
                 .catch((err) => paragraph.setError(err));
         };
 
@@ -1467,7 +1467,7 @@ export default ['$rootScope', '$scope', '$http', '$q', '$timeout', '$interval',
 
                     return agentMgr.querySql(nid, args.cacheName, args.query, false, !!paragraph.enforceJoinOrder, false, false, args.pageSize);
                 })
-                .then(_processQueryResult.bind(this, paragraph, true))
+                .then((res) => _processQueryResult(paragraph, true, res))
                 .catch((err) => {
                     paragraph.setError(err);
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/2436b934/modules/web-console/frontend/controllers/domains-controller.js
----------------------------------------------------------------------
diff --git a/modules/web-console/frontend/controllers/domains-controller.js b/modules/web-console/frontend/controllers/domains-controller.js
index 57050a0..ea5e389 100644
--- a/modules/web-console/frontend/controllers/domains-controller.js
+++ b/modules/web-console/frontend/controllers/domains-controller.js
@@ -461,7 +461,7 @@ export default ['domainsController', [
 
                 $scope.importDomain.loadingOptions = LOADING_JDBC_DRIVERS;
 
-                agentMgr.startWatch('Back to Domain models', 'import domain model from database')
+                agentMgr.startAgentWatch('Back to Domain models', 'import domain model from database')
                     .then(() => {
                         ActivitiesData.post({
                             group: 'configuration',