You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by an...@apache.org on 2016/03/31 09:27:40 UTC

[02/14] ignite git commit: IGNITE-2875 WIP

IGNITE-2875 WIP


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

Branch: refs/heads/ignite-2875
Commit: 2eafd827052efd4208c40415b677b968d0d734b3
Parents: f374d01
Author: Andrey <an...@gridgain.com>
Authored: Mon Mar 28 15:47:01 2016 +0700
Committer: Andrey <an...@gridgain.com>
Committed: Tue Mar 29 13:19:04 2016 +0700

----------------------------------------------------------------------
 .../js/app/services/AgentMonitor.service.js     | 31 +++++-----
 .../src/main/js/controllers/sql-controller.js   | 46 +++++++++------
 .../src/main/js/serve/agent.js                  | 60 +++++++++----------
 .../src/main/js/serve/browser.js                | 62 ++++++++++----------
 .../src/main/js/serve/routes/agent.js           |  5 +-
 .../src/main/js/serve/routes/profile.js         |  7 +--
 6 files changed, 106 insertions(+), 105 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/2eafd827/modules/control-center-web/src/main/js/app/services/AgentMonitor.service.js
----------------------------------------------------------------------
diff --git a/modules/control-center-web/src/main/js/app/services/AgentMonitor.service.js b/modules/control-center-web/src/main/js/app/services/AgentMonitor.service.js
index 590d72f..2b55030 100644
--- a/modules/control-center-web/src/main/js/app/services/AgentMonitor.service.js
+++ b/modules/control-center-web/src/main/js/app/services/AgentMonitor.service.js
@@ -80,12 +80,14 @@ class IgniteAgentMonitor {
         this._socketFactory = socketFactory;
 
         this._$q = $q;
+
+        this._$common = $common;
     }
 
     /**
      * @private
      */
-    _checkModal() {
+    checkModal() {
         if (this._scope.showModal && !this._scope.hasAgents)
             this._downloadAgentModal.$promise.then(this._downloadAgentModal.show);
         else if ((this._scope.hasAgents || !this._scope.showModal) && this._downloadAgentModal.$isShown)
@@ -100,7 +102,7 @@ class IgniteAgentMonitor {
             return this._$q.when();
 
         if (this._scope.hasAgents !== null)
-            this._checkModal();
+            this.checkModal();
 
         const latch = this._$q.defer();
 
@@ -122,7 +124,7 @@ class IgniteAgentMonitor {
         this._socket.on('agent:count', ({count}) => {
             this._scope.hasAgents = count > 0;
 
-            this._checkModal();
+            this.checkModal();
 
             if (this._scope.hasAgents)
                 this._scope.$broadcast('agent:connected', true);
@@ -131,7 +133,7 @@ class IgniteAgentMonitor {
         this._socket.on('disconnect', () => {
             this._scope.hasAgents = false;
 
-            this._checkModal();
+            this.checkModal();
         });
     }
 
@@ -211,6 +213,15 @@ class IgniteAgentMonitor {
     }
 
     /**
+     * @param {String} errMsg
+     */
+    showNodeError(errMsg) {
+        this._downloadAgentModal.show();
+
+        this._$common.showError(errMsg);
+    }
+
+    /**
      *
      * @param {String} event
      * @param {Object} [args]
@@ -220,16 +231,6 @@ class IgniteAgentMonitor {
     _rest(event, ...args) {
         return this._downloadAgentModal.$promise
             .then(() => this._emit(event, ...args))
-            .then((res) => {
-                this._downloadAgentModal.hide();
-
-                return res;
-            })
-            .catch((err) => {
-                this._downloadAgentModal.show();
-
-                return this._$q.reject(err);
-            });
     }
 
     /**
@@ -288,7 +289,7 @@ class IgniteAgentMonitor {
     stopWatch() {
         this._scope.showModal = false;
 
-        this._checkModal();
+        this.checkModal();
 
         this._scope.$broadcast('agent:connected', false);
     }

http://git-wip-us.apache.org/repos/asf/ignite/blob/2eafd827/modules/control-center-web/src/main/js/controllers/sql-controller.js
----------------------------------------------------------------------
diff --git a/modules/control-center-web/src/main/js/controllers/sql-controller.js b/modules/control-center-web/src/main/js/controllers/sql-controller.js
index 63dd31d..1ed3b87 100644
--- a/modules/control-center-web/src/main/js/controllers/sql-controller.js
+++ b/modules/control-center-web/src/main/js/controllers/sql-controller.js
@@ -214,8 +214,7 @@ consoleModule.controller('sqlController', [
                     this.api = api;
                 },
                 enableGridMenu: false,
-                exporterMenuCsv: false,
-                exporterMenuPdf: false,
+                enableColumnMenus: false,
                 setRows: function(rows) {
                     this.height = Math.min(rows.length, 15) * 30 + 42 + 'px';
 
@@ -257,6 +256,8 @@ consoleModule.controller('sqlController', [
         var _refreshFn = function() {
             IgniteAgentMonitor.topology($scope.demo)
                 .then(function(clusters) {
+                    IgniteAgentMonitor.checkModal();
+
                     var caches = _.flattenDeep(clusters.map(function (cluster) { return cluster.caches; }));
 
                     $scope.caches = _.sortBy(_.uniq(_.reject(caches, { mode: 'LOCAL' }), function (cache) {
@@ -265,8 +266,10 @@ consoleModule.controller('sqlController', [
 
                     _setActiveCache();
                 })
-                .catch(_handleException)
-                .finally(function() {
+                .catch(function (err) {
+                    IgniteAgentMonitor.showNodeError(err.message)
+                })
+                .finally(function () {
                     $loading.finish('loading');
                 });
         };
@@ -585,11 +588,16 @@ consoleModule.controller('sqlController', [
             return retainedCols;
         }
 
+        /**
+         * @param {Object} paragraph Query
+         * @param {{fieldsMetadata: Array, items: Array, queryId: int, last: Boolean}} res Query results.
+         * @private
+         */
         var _processQueryResult = function (paragraph, res) {
             var prevKeyCols = paragraph.chartKeyCols;
             var prevValCols = paragraph.chartValCols;
 
-            if (!_.eq(paragraph.meta, res.meta)) {
+            if (!_.eq(paragraph.meta, res.fieldsMetadata)) {
                 paragraph.meta = [];
 
                 paragraph.chartColumns = [];
@@ -600,17 +608,17 @@ consoleModule.controller('sqlController', [
                 if (!$common.isDefined(paragraph.chartValCols))
                     paragraph.chartValCols = [];
 
-                if (res.meta.length <= 2) {
-                    var _key = _.find(res.meta, {fieldName: '_KEY'});
-                    var _val = _.find(res.meta, {fieldName: '_VAL'});
+                if (res.fieldsMetadata.length <= 2) {
+                    var _key = _.find(res.fieldsMetadata, {fieldName: '_KEY'});
+                    var _val = _.find(res.fieldsMetadata, {fieldName: '_VAL'});
 
-                    paragraph.disabledSystemColumns = (res.meta.length == 2 && _key && _val) ||
-                        (res.meta.length == 1 && (_key || _val));
+                    paragraph.disabledSystemColumns = (res.fieldsMetadata.length == 2 && _key && _val) ||
+                        (res.fieldsMetadata.length == 1 && (_key || _val));
                 }
 
                 paragraph.columnFilter = _columnFilter(paragraph);
 
-                paragraph.meta = res.meta;
+                paragraph.meta = res.fieldsMetadata;
 
                 _rebuildColumns(paragraph);
             }
@@ -619,16 +627,16 @@ consoleModule.controller('sqlController', [
 
             paragraph.total = 0;
 
-            paragraph.queryId = res.queryId;
+            paragraph.queryId = res.last ? null : res.queryId;
 
             delete paragraph.errMsg;
 
             // Prepare explain results for display in table.
-            if (paragraph.queryArgs.type == "EXPLAIN" && res.rows) {
+            if (paragraph.queryArgs.type == "EXPLAIN" && res.items) {
                 paragraph.rows = [];
 
-                res.rows.forEach(function (row, i) {
-                    var line = res.rows.length - 1 == i ? row[0] : row[0] + '\n';
+                res.items.forEach(function (row, i) {
+                    var line = res.items.length - 1 == i ? row[0] : row[0] + '\n';
 
                     line.replace(/\"/g, '').split('\n').forEach(function (line) {
                         paragraph.rows.push([line]);
@@ -636,7 +644,7 @@ consoleModule.controller('sqlController', [
                 });
             }
             else
-                paragraph.rows = res.rows;
+                paragraph.rows = res.items;
 
             paragraph.gridOptions.setRows(paragraph.rows);
 
@@ -818,7 +826,7 @@ consoleModule.controller('sqlController', [
 
                     paragraph.total += paragraph.rows.length;
 
-                    paragraph.rows = res.rows;
+                    paragraph.rows = res.items;
 
                     if (paragraph.chart()) {
                         if (paragraph.result == 'pie')
@@ -827,11 +835,11 @@ consoleModule.controller('sqlController', [
                             _updateChartsWithData(paragraph, _chartDatum(paragraph));
                     }
 
-                    paragraph.gridOptions.setRows(res.rows);
+                    paragraph.gridOptions.setRows(paragraph.rows);
 
                     _showLoading(paragraph, false);
 
-                    if (res.queryId === null)
+                    if (res.last)
                         delete paragraph.queryId;
                 })
                 .catch(function (errMsg) {

http://git-wip-us.apache.org/repos/asf/ignite/blob/2eafd827/modules/control-center-web/src/main/js/serve/agent.js
----------------------------------------------------------------------
diff --git a/modules/control-center-web/src/main/js/serve/agent.js b/modules/control-center-web/src/main/js/serve/agent.js
index ce04482..d6a195d 100644
--- a/modules/control-center-web/src/main/js/serve/agent.js
+++ b/modules/control-center-web/src/main/js/serve/agent.js
@@ -24,7 +24,7 @@
  */
 module.exports = {
     implements: 'agent-manager',
-    inject: ['require(lodash)', 'require(ws)', 'require(fs)', 'require(path)', 'require(jszip)', 'require(socket.io)', 'require(apache-ignite)', 'settings', 'mongo']
+    inject: ['require(lodash)', 'require(ws)', 'require(fs)', 'require(path)', 'require(jszip)', 'require(socket.io)', 'settings', 'mongo']
 };
 
 /**
@@ -34,12 +34,11 @@ module.exports = {
  * @param path
  * @param JSZip
  * @param socketio
- * @param apacheIgnite
  * @param settings
  * @param mongo
  * @returns {AgentManager}
  */
-module.exports.factory = function(_, ws, fs, path, JSZip, socketio, apacheIgnite, settings, mongo) {
+module.exports.factory = function(_, ws, fs, path, JSZip, socketio, settings, mongo) {
     /**
      *
      */
@@ -221,20 +220,6 @@ module.exports.factory = function(_, ws, fs, path, JSZip, socketio, apacheIgnite
 
         /**
          *
-         * @param res
-         * @return {{meta: Array, rows: Array, queryId: int}}
-         * @private
-         */
-        static _onQueryResult(res) {
-            return {
-                meta: res.fieldsMetadata,
-                rows: res.items,
-                queryId: res.last ? null : res.queryId
-            }
-        }
-
-        /**
-         *
          * @param {Boolean} demo Is need run command on demo node.
          * @param {String} cacheName Cache name.
          * @param {String} query Query.
@@ -247,8 +232,7 @@ module.exports.factory = function(_, ws, fs, path, JSZip, socketio, apacheIgnite
                 .addParam('qry', query)
                 .addParam('pageSize', pageSize);
 
-            return this.executeRest(cmd)
-                .then(Agent._onQueryResult);
+            return this.executeRest(cmd);
         }
 
         /**
@@ -263,11 +247,9 @@ module.exports.factory = function(_, ws, fs, path, JSZip, socketio, apacheIgnite
                 .addParam('cacheName', cacheName)
                 .addParam('pageSize', pageSize);
 
-            return this.executeRest(cmd)
-                .then(Agent._onQueryResult);
+            return this.executeRest(cmd);
         }
 
-
         /**
          * @param {Boolean} demo Is need run command on demo node.
          * @param {int} queryId Query Id.
@@ -279,15 +261,31 @@ module.exports.factory = function(_, ws, fs, path, JSZip, socketio, apacheIgnite
                 .addParam('qryId', queryId)
                 .addParam('pageSize', pageSize);
 
-            return this.executeRest(cmd)
-                .then(Agent._onQueryResult);
+            return this.executeRest(cmd);
         }
 
         /**
-         * @returns {apacheIgnite.Ignite}
+         * @param {Boolean} demo Is need run command on demo node.
+         * @param {int} queryId Query Id.
+         * @returns {Promise}
          */
-        ignite(demo) {
-            return demo ? this._demo : this._cluster;
+        queryClose(demo, queryId) {
+            var cmd = new Command(demo, 'qrycls')
+                .addParam('qryId', queryId);
+
+            return this.executeRest(cmd);
+        }
+
+        /**
+         * @param {Boolean} demo Is need run command on demo node.
+         * @param {String} cacheName Cache name.
+         * @returns {Promise}
+         */
+        metadata(demo, cacheName) {
+            var cmd = new Command(demo, 'metadata')
+                .addParam('cacheName', cacheName);
+
+            return this.executeRest(cmd);
         }
     }
 
@@ -395,7 +393,7 @@ module.exports.factory = function(_, ws, fs, path, JSZip, socketio, apacheIgnite
             this._server = srv;
 
             /**
-             * @type {WebSocketServer}
+             * @type {socketIo.Server}
              */
             this._socket = socketio(this._server);
 
@@ -467,12 +465,12 @@ module.exports.factory = function(_, ws, fs, path, JSZip, socketio, apacheIgnite
          */
         findAgent(userId) {
             if (!this._server)
-                return Promise.reject('Agent server not started yet!');
+                throw new Error('Agent server not started yet!');
 
             const agents = this._agents[userId];
 
             if (!agents || agents.length === 0)
-                return Promise.reject('Failed to connect to agent');
+                throw new Error('Failed to connect to agent');
 
             return Promise.resolve(agents[0]);
         }
@@ -483,7 +481,7 @@ module.exports.factory = function(_, ws, fs, path, JSZip, socketio, apacheIgnite
          */
         close(userId) {
             if (!this._server)
-                throw 'Agent server not started yet!';
+                return;
 
             const agents = this._agents[userId];
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/2eafd827/modules/control-center-web/src/main/js/serve/browser.js
----------------------------------------------------------------------
diff --git a/modules/control-center-web/src/main/js/serve/browser.js b/modules/control-center-web/src/main/js/serve/browser.js
index c269d7d..678ebf9 100644
--- a/modules/control-center-web/src/main/js/serve/browser.js
+++ b/modules/control-center-web/src/main/js/serve/browser.js
@@ -24,12 +24,16 @@
  */
 module.exports = {
     implements: 'browser-manager',
-    inject: ['require(lodash)', 'require(socket.io)', 'require(apache-ignite)', 'agent-manager', 'configure']
+    inject: ['require(lodash)', 'require(socket.io)', 'agent-manager', 'configure']
 };
 
-module.exports.factory = (_, socketio, apacheIgnite, agentMgr, configure) => {
-    const SqlFieldsQuery = apacheIgnite.SqlFieldsQuery;
-    const ScanQuery = apacheIgnite.ScanQuery;
+module.exports.factory = (_, socketio, agentMgr, configure) => {
+    const _errorToJson = (err) => {
+        return {
+            message: err.message,
+            code: err.code || 1
+        }
+    };
 
     return {
         attach: (server) => {
@@ -45,7 +49,7 @@ module.exports.factory = (_, socketio, apacheIgnite, agentMgr, configure) => {
                     agentMgr.findAgent(user._id)
                         .then((agent) => agent.availableDrivers())
                         .then((drivers) => cb(null, drivers))
-                        .catch((errMsg) => cb(errMsg));
+                        .catch((err) => cb(_errorToJson(err)));
                 });
 
                 // Return schemas from database to browser.
@@ -57,7 +61,7 @@ module.exports.factory = (_, socketio, apacheIgnite, agentMgr, configure) => {
                             return agent.metadataSchemas(preset.jdbcDriverJar, preset.jdbcDriverClass, preset.jdbcUrl, jdbcInfo);
                         })
                         .then((schemas) => cb(null, schemas))
-                        .catch((errMsg) => cb(errMsg));
+                        .catch((err) => cb(_errorToJson(err)));
                 });
 
                 // Return tables from database to browser.
@@ -70,7 +74,7 @@ module.exports.factory = (_, socketio, apacheIgnite, agentMgr, configure) => {
                                 preset.schemas, preset.tablesOnly);
                         })
                         .then((tables) => cb(null, tables))
-                        .catch((errMsg) => cb(errMsg));
+                        .catch((err) => cb(_errorToJson(err)));
                 });
 
                 // Return topology command result from grid to browser.
@@ -78,19 +82,15 @@ module.exports.factory = (_, socketio, apacheIgnite, agentMgr, configure) => {
                     agentMgr.findAgent(user._id)
                         .then((agent) => agent.topology(demo, attr, mtr))
                         .then((clusters) => cb(null, clusters))
-                        .catch((err) => cb(err));
+                        .catch((err) => cb(_errorToJson(err)));
                 });
 
                 // Close query on node.
                 socket.on('node:query:close', (args, cb) => {
                     agentMgr.findAgent(user._id)
-                        .then((agent) => {
-                            const cache = agent.ignite(args.demo).cache(args.cacheName);
-
-                            return cache.__createPromise(cache._createCommand('qrycls').addParam('qryId', args.queryId));
-                        })
+                        .then((agent) => agent.queryClose(args.demo, args.queryId))
                         .then(() => cb())
-                        .catch((err) => cb(err));
+                        .catch((err) => cb(_errorToJson(err)));
                 });
 
                 // Execute query on node and return first page to browser.
@@ -103,7 +103,7 @@ module.exports.factory = (_, socketio, apacheIgnite, agentMgr, configure) => {
                             return agent.fieldsQuery(args.demo, args.cacheName, args.query, args.pageSize);
                         })
                         .then((res) => cb(null, res))
-                        .catch((err) => cb(err));
+                        .catch((err) => cb(_errorToJson(err)));
                 });
 
                 // Fetch next page for query and return result to browser.
@@ -111,7 +111,7 @@ module.exports.factory = (_, socketio, apacheIgnite, agentMgr, configure) => {
                     agentMgr.findAgent(user._id)
                         .then((agent) => agent.queryFetch(args.demo, args.queryId, args.pageSize))
                         .then((res) => cb(null, res))
-                        .catch((err) => cb(err));
+                        .catch((err) => cb(_errorToJson(err)));
                 });
 
                 // Execute query on node and return full result to browser.
@@ -121,36 +121,34 @@ module.exports.factory = (_, socketio, apacheIgnite, agentMgr, configure) => {
 
                     agentMgr.findAgent(user._id)
                         .then((agent) => {
-                            if (args.type === 'SCAN')
-                                return agent.scan(args.demo, args.cacheName, pageSize);
+                            const firstPage = args.type === 'SCAN' ? agent.scan(args.demo, args.cacheName, pageSize)
+                                : agent.fieldsQuery(args.demo, args.cacheName, args.query, pageSize);
 
-                            return agent.fieldsQuery(args.demo, args.cacheName, args.query, pageSize);
-                        })
-                        .then((res) => {
-                            const fetchResult = (fullRes) => {
-                                if (fullRes.last)
-                                    return fullRes;
+                            const fetchResult = (acc) => {
+                                if (!acc.queryId)
+                                    return acc;
 
-                                return agent.queryFetch(args.demo, args.queryId, pageSize)
+                                return agent.queryFetch(args.demo, acc.queryId, pageSize)
                                     .then((res) => {
-                                        fullRes.rows = fullRes.rows.concat(res.rows);
+                                        acc.rows = acc.rows.concat(res.rows);
 
-                                        fullRes.last = res.last;
+                                        acc.last = res.last;
 
-                                        return fetchResult(fullRes);
+                                        return fetchResult(acc);
                                     })
                             };
 
-                            return fetchResult(res);
+                            return firstPage
+                                .then(fetchResult)
                         })
                         .then((res) => cb(null, res))
-                        .catch((errMsg) => cb(errMsg));
+                        .catch((err) => cb(_errorToJson(err)));
                 });
 
                 // Return cache metadata from all nodes in grid.
                 socket.on('node:cache:metadata', (args, cb) => {
                     agentMgr.findAgent(user._id)
-                        .then((agent) => agent.ignite(args.demo).cache(args.cacheName).metadata())
+                        .then((agent) => agent.metadata(args.demo, args.cacheName))
                         .then((caches) => {
                             let types = [];
 
@@ -234,7 +232,7 @@ module.exports.factory = (_, socketio, apacheIgnite, agentMgr, configure) => {
 
                             return cb(null, types);
                         })
-                        .catch((errMsg) => cb(errMsg));
+                        .catch((err) => cb(_errorToJson(err)));
                 });
 
                 const count = agentMgr.addAgentListener(user._id, socket);

http://git-wip-us.apache.org/repos/asf/ignite/blob/2eafd827/modules/control-center-web/src/main/js/serve/routes/agent.js
----------------------------------------------------------------------
diff --git a/modules/control-center-web/src/main/js/serve/routes/agent.js b/modules/control-center-web/src/main/js/serve/routes/agent.js
index 1d46170..8fd8b75 100644
--- a/modules/control-center-web/src/main/js/serve/routes/agent.js
+++ b/modules/control-center-web/src/main/js/serve/routes/agent.js
@@ -21,20 +21,19 @@
 
 module.exports = {
     implements: 'agent-routes',
-    inject: ['require(lodash)', 'require(express)', 'require(fs)', 'require(jszip)', 'require(apache-ignite)', 'settings', 'agent-manager']
+    inject: ['require(lodash)', 'require(express)', 'require(fs)', 'require(jszip)', 'settings', 'agent-manager']
 };
 
 /**
  * @param _
  * @param express
- * @param apacheIgnite
  * @param fs
  * @param JSZip
  * @param settings
  * @param {AgentManager} agentMgr
  * @returns {Promise}
  */
-module.exports.factory = function(_, express, fs, JSZip, apacheIgnite, settings, agentMgr) {
+module.exports.factory = function(_, express, fs, JSZip, settings, agentMgr) {
     return new Promise((resolveFactory) => {
         const router = new express.Router();
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/2eafd827/modules/control-center-web/src/main/js/serve/routes/profile.js
----------------------------------------------------------------------
diff --git a/modules/control-center-web/src/main/js/serve/routes/profile.js b/modules/control-center-web/src/main/js/serve/routes/profile.js
index 13ad045..5e4278f 100644
--- a/modules/control-center-web/src/main/js/serve/routes/profile.js
+++ b/modules/control-center-web/src/main/js/serve/routes/profile.js
@@ -79,13 +79,10 @@ module.exports.factory = function(_, express, mongo, agentMgr) {
                     });
                 })
                 .then((user) => {
-                    if (!params.token || user.token !== params.token)
+                    if (params.token && user.token !== params.token)
                         agentMgr.close(user._id);
 
-                    for (const param in params) {
-                        if (params.hasOwnProperty(param))
-                            user[param] = params[param];
-                    }
+                    _.extend(user, params);
 
                     return user.save();
                 })