Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 2A1EF200C6C for ; Fri, 5 May 2017 11:45:16 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 28BB6160B97; Fri, 5 May 2017 09:45:16 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id E23C6160BD6 for ; Fri, 5 May 2017 11:45:13 +0200 (CEST) Received: (qmail 59416 invoked by uid 500); 5 May 2017 09:45:13 -0000 Mailing-List: contact commits-help@ignite.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ignite.apache.org Delivered-To: mailing list commits@ignite.apache.org Received: (qmail 58790 invoked by uid 99); 5 May 2017 09:45:12 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 05 May 2017 09:45:12 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 8647CE967F; Fri, 5 May 2017 09:45:12 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: sboikov@apache.org To: commits@ignite.apache.org Date: Fri, 05 May 2017 09:45:33 -0000 Message-Id: In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [22/50] [abbrv] ignite git commit: IGNITE-5143 Fixed agent watch logic. archived-at: Fri, 05 May 2017 09:45:16 -0000 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 Authored: Wed May 3 16:50:16 2017 +0700 Committer: Andrey Novikov 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',