ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From anovi...@apache.org
Subject [13/50] [abbrv] ignite git commit: IGNITE-843 Refactoring, jsDoc.
Date Mon, 28 Mar 2016 08:47:53 GMT
IGNITE-843 Refactoring, jsDoc.


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

Branch: refs/heads/ignite-2875
Commit: b30b52b1ab8f7e50252857af97e18b0c3092b782
Parents: 2651715
Author: Andrey <anovikov@gridgain.com>
Authored: Mon Mar 21 14:27:08 2016 +0700
Committer: Andrey <anovikov@gridgain.com>
Committed: Mon Mar 21 14:27:08 2016 +0700

----------------------------------------------------------------------
 .../src/main/js/app/decorator/select.js         |  25 +-
 .../control-center-web/src/main/js/app/index.js |   1 -
 .../js/app/services/AgentMonitor.service.js     |  10 +
 .../src/main/js/controllers/sql-controller.js   |   2 +-
 modules/control-center-web/src/main/js/serve.js |  12 +-
 .../src/main/js/serve/agent.js                  | 195 +++++++-------
 .../control-center-web/src/main/js/serve/app.js |   2 +-
 .../src/main/js/serve/browser.js                | 254 +++++++++++++++++++
 .../src/main/js/serve/configure.js              |   3 +
 .../control-center-web/src/main/js/serve/io.js  | 242 ------------------
 .../src/main/js/serve/mail.js                   |   3 +
 .../src/main/js/serve/mongo.js                  |   3 +
 .../src/main/js/serve/routes/agent.js           |   2 +-
 .../src/main/js/serve/routes/profile.js         |  12 +-
 .../src/main/js/serve/settings.js               |   3 +
 15 files changed, 407 insertions(+), 362 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/b30b52b1/modules/control-center-web/src/main/js/app/decorator/select.js
----------------------------------------------------------------------
diff --git a/modules/control-center-web/src/main/js/app/decorator/select.js b/modules/control-center-web/src/main/js/app/decorator/select.js
index f232f88..13a4041 100644
--- a/modules/control-center-web/src/main/js/app/decorator/select.js
+++ b/modules/control-center-web/src/main/js/app/decorator/select.js
@@ -31,31 +31,32 @@ angular.module('mgcrea.ngStrap.select')
 
             const scope = deligate.$scope;
 
+            const _valueMap = (index) => {
+                if (angular.isUndefined(scope.$matches[index]))
+                    return null;
+
+                return scope.$matches[index].value;
+            };
+
             const selectAll = (active) => {
-                var selected = [];
+                const selected = [];
 
-                scope.$apply(function () {
-                    for (var i = 0; i < scope.$matches.length; i++) {
+                scope.$apply(() => {
+                    for (let i = 0; i < scope.$matches.length; i++) {
                         if (scope.$isActive(i) === active) {
                             selected[i] = scope.$matches[i].value;
 
                             deligate.activate(i);
 
-                            controller.$setViewValue(scope.$activeIndex.map(function (index)
{
-                                if (angular.isUndefined(scope.$matches[index])) {
-                                    return null;
-                                }
-                                return scope.$matches[index].value;
-                            }));
+                            controller.$setViewValue(scope.$activeIndex.map(_valueMap));
                         }
                     }
                 });
 
                 // Emit events.
-                for (var i = 0; i < selected.length; i++) {
-                    if (selected[i]) {
+                for (let i = 0; i < selected.length; i++) {
+                    if (selected[i])
                         scope.$emit(options.prefixEvent + '.select', selected[i], i, deligate);
-                    }
                 }
             };
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/b30b52b1/modules/control-center-web/src/main/js/app/index.js
----------------------------------------------------------------------
diff --git a/modules/control-center-web/src/main/js/app/index.js b/modules/control-center-web/src/main/js/app/index.js
index 1537eb9..60a3a8b 100644
--- a/modules/control-center-web/src/main/js/app/index.js
+++ b/modules/control-center-web/src/main/js/app/index.js
@@ -20,7 +20,6 @@ import _ from 'lodash';
 import ace from 'ace';
 import angular from 'angular';
 import pdfMake from 'pdfmake';
-import io from 'socket.io-client';
 
 window._ = _;
 window.ace = ace;

http://git-wip-us.apache.org/repos/asf/ignite/blob/b30b52b1/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 cf66b61..1b661a3 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
@@ -15,6 +15,8 @@
  * limitations under the License.
  */
 
+import io from 'socket.io-client';
+
 class IgniteAgentMonitor {
     constructor(socketFactory, $root, $q, $state, $modal, $common) {
         this._scope = $root.$new();
@@ -257,6 +259,14 @@ class IgniteAgentMonitor {
     }
 
     /**
+     * @param {Object} args
+     * @returns {Promise}
+     */
+    queryGetAll(args) {
+        return this._rest('node:query:getAll', args);
+    }
+
+    /**
      * @param {Boolean} demo
      * @returns {Promise}
      */

http://git-wip-us.apache.org/repos/asf/ignite/blob/b30b52b1/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 dd712f8..35c0126 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
@@ -902,7 +902,7 @@ consoleModule.controller('sqlController', [
         };
 
         $scope.exportCsvAll = function (paragraph) {
-            IgniteAgentMonitor.query({
+            IgniteAgentMonitor.queryGetAll({
                     demo: $scope.demo,
                     type: paragraph.queryArgs.type,
                     query: paragraph.queryArgs.query,

http://git-wip-us.apache.org/repos/asf/ignite/blob/b30b52b1/modules/control-center-web/src/main/js/serve.js
----------------------------------------------------------------------
diff --git a/modules/control-center-web/src/main/js/serve.js b/modules/control-center-web/src/main/js/serve.js
index 74342a9..cba74d3 100644
--- a/modules/control-center-web/src/main/js/serve.js
+++ b/modules/control-center-web/src/main/js/serve.js
@@ -66,12 +66,12 @@ const fireUp = require('fire-up').newInjector({
     ]
 });
 
-Promise.all([fireUp('settings'), fireUp('app'), fireUp('agent'), fireUp('io')])
+Promise.all([fireUp('settings'), fireUp('app'), fireUp('agent-manager'), fireUp('browser-manager')])
     .then((values) => {
         const settings = values[0];
         const app = values[1];
-        const agent = values[2];
-        const io = values[3];
+        const agentMgr = values[2];
+        const browserMgr = values[3];
 
         // Start rest server.
         const server = settings.server.SSLOptions
@@ -82,7 +82,7 @@ Promise.all([fireUp('settings'), fireUp('app'), fireUp('agent'), fireUp('io')])
         server.on('listening', _onListening.bind(null, server.address()));
 
         app.listen(server);
-        io.listen(server);
+        browserMgr.attach(server);
 
         // Start agent server.
         const agentServer = settings.agent.SSLOptions
@@ -92,13 +92,13 @@ Promise.all([fireUp('settings'), fireUp('app'), fireUp('agent'), fireUp('io')])
         agentServer.on('error', _onError.bind(null, settings.agent.port));
         agentServer.on('listening', _onListening.bind(null, agentServer.address()));
 
-        agent.listen(agentServer);
+        agentMgr.attach(agentServer);
 
         // Used for automated test.
         if (process.send)
             process.send('running');
     }).catch((err) => {
-        console.error(error);
+        console.error(err);
 
         process.exit(1);
     });

http://git-wip-us.apache.org/repos/asf/ignite/blob/b30b52b1/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 04d7ed6..6e249f0 100644
--- a/modules/control-center-web/src/main/js/serve/agent.js
+++ b/modules/control-center-web/src/main/js/serve/agent.js
@@ -19,8 +19,11 @@
 
 // Fire me up!
 
+/**
+ * Module interaction with agents.
+ */
 module.exports = {
-    implements: 'agent',
+    implements: 'agent-manager',
     inject: ['require(lodash)', 'require(fs)', 'require(path)', 'require(jszip)', 'require(socket.io)',
'require(apache-ignite)', 'settings', 'mongo']
 };
 
@@ -81,34 +84,44 @@ module.exports.factory = function(_, fs, path, JSZip, socketio, apacheIgnite,
se
         }
     }
 
+    /**
+     * Connected agent descriptor.
+     */
     class Agent {
         /**
-         * @param {socketIo.Socket} _wsSrv
-         * @param {AgentManager} manager
+         * @param {socketIo.Socket} socket - Agent socket for interaction.
          */
-        constructor(_wsSrv, manager) {
-            const self = this;
-
-            this._manager = manager;
-
+        constructor(socket) {
             /**
+             * Agent socket for interaction.
+             *
              * @type {socketIo.Socket}
              * @private
              */
-            this._wsAgents = _wsSrv;
+            this._socket = socket;
 
-            this._wsAgents.on('disconnect', () => {
-                if (self._user)
-                    self._manager._removeAgent(self._user._id, self);
-            });
+            /**
+             * Executor for grid.
+             *
+             * @type {apacheIgnite.Ignite}
+             * @private
+             */
+            this._cluster = new apacheIgnite.Ignite(new AgentServer(this));
 
-            this._wsAgents.on('agent:auth', (msg, cb) => self._processAuth(msg, cb));
+            /**
+             * Executor for demo node.
+             *
+             * @type {apacheIgnite.Ignite}
+             * @private
+             */
+            this._demo = new apacheIgnite.Ignite(new AgentServer(this, true));
         }
 
         /**
+         * Send message to agent.
          *
-         * @param event
-         * @param data
+         * @param {String} event - Event name.
+         * @param {Object} data - Transmitted data.
          * @returns {Promise}
          */
         _exec(event, data) {
@@ -125,12 +138,33 @@ module.exports.factory = function(_, fs, path, JSZip, socketio, apacheIgnite,
se
         }
 
         /**
-         * @param {String} uri
-         * @param {Object} params
-         * @param {Boolean} demo
-         * @param {String} [method]
-         * @param {Object} [headers]
-         * @param {String} [body]
+         * Send message to agent.
+         *
+         * @this {Agent}
+         * @param {String} event Command name.
+         * @param {Object} data Command params.
+         * @param {Function} [callback] on finish
+         */
+        _emit(event, data, callback) {
+            if (!this._socket.connected) {
+                if (callback)
+                    callback('org.apache.ignite.agent.AgentException: Connection is closed');
+
+                return;
+            }
+
+            this._socket.emit(event, data, callback);
+        }
+
+        /**
+         * Execute rest request on node.
+         *
+         * @param {String} uri - REST endpoint uri.
+         * @param {Object} params - REST request parameters.
+         * @param {Boolean} demo - true if execute on demo node.
+         * @param {String} [method] - Request method GET or POST.
+         * @param {Object} [headers] - REST request headers.
+         * @param {String} [body] - REST request body
          * @param {Function} [cb] Callback. Take 3 arguments: {Number} successStatus, {String}
error,  {String} response.
          */
         executeRest(uri, params, demo, method, headers, body, cb) {
@@ -223,90 +257,38 @@ module.exports.factory = function(_, fs, path, JSZip, socketio, apacheIgnite,
se
         }
 
         /**
-         * Run http request
-         *
-         * @this {Agent}
-         * @param {String} event Command name.
-         * @param {Object} data Command params.
-         * @param {Function} [callback] on finish
-         */
-        _emit(event, data, callback) {
-            if (!this._wsAgents.connected) {
-                if (callback)
-                    callback('org.apache.ignite.agent.AgentException: Connection is closed');
-
-                return;
-            }
-
-            this._wsAgents.emit(event, data, callback);
-        }
-
-        /**
-         * Process auth request.
-         *
-         * @param {Object} data
-         * @param {Function} cb
-         * @private
-         */
-        _processAuth(data, cb) {
-            const self = this;
-
-            if (!_.isEmpty(this._manager.supportedAgents)) {
-                const ver = data.ver;
-                const bt = data.bt;
-
-                if (_.isEmpty(ver) || _.isEmpty(bt) || _.isEmpty(this._manager.supportedAgents[ver])
||
-                    this._manager.supportedAgents[ver].buildTime > bt)
-                    return cb('You are using an older version of the agent. Please reload
agent archive');
-            }
-
-            mongo.Account.findOne({token: data.token}, (err, account) => {
-                // TODO IGNITE-1379 send error to web master.
-                if (err)
-                    cb('Failed to authorize user');
-                else if (!account)
-                    cb('Invalid token, user not found');
-                else {
-                    self._user = account;
-
-                    self._manager._addAgent(account._id, self);
-
-                    self._cluster = new apacheIgnite.Ignite(new AgentServer(self));
-
-                    self._demo = new apacheIgnite.Ignite(new AgentServer(self, true));
-
-                    cb();
-                }
-            });
-        }
-
-        /**
-         * @returns {Ignite}
+         * @returns {apacheIgnite.Ignite}
          */
         ignite(demo) {
             return demo ? this._demo : this._cluster;
         }
     }
 
+    /**
+     * Connected agents manager.
+     */
     class AgentManager {
         /**
          * @constructor
          */
         constructor() {
             /**
+             * Connected agents by user id.
              * @type {Object.<ObjectId, Array.<Agent>>}
              */
             this._agents = {};
 
             /**
+             * Connected browsers by user id.
              * @type {Object.<ObjectId, Array.<Socket>>}
              */
-            this._users = {};
+            this._browsers = {};
 
             const agentArchives = fs.readdirSync(settings.agent.dists)
                 .filter((file) => path.extname(file) === '.zip');
 
             /**
+             * Supported agents distribution.
              * @type {Object.<String, String>}
              */
             this.supportedAgents = {};
@@ -360,14 +342,15 @@ module.exports.factory = function(_, fs, path, JSZip, socketio, apacheIgnite,
se
                 }
             }));
 
+            // Latest version of agent distribution.
             if (latest)
                 this.supportedAgents.latest = this.supportedAgents[latest];
         }
 
         /**
-         * @param {http.Server|https.Server} srv
+         * @param {http.Server|https.Server} srv Server instance that we want to attach agent
handler.
          */
-        listen(srv) {
+        attach(srv) {
             if (this._server)
                 throw 'Agent server already started!';
 
@@ -376,11 +359,39 @@ module.exports.factory = function(_, fs, path, JSZip, socketio, apacheIgnite,
se
             /**
              * @type {WebSocketServer}
              */
-            this._wsAgents = socketio(this._server);
+            this._socket = socketio(this._server);
 
-            const self = this;
+            this._socket.on('connection', (socket) => {
+                socket.on('agent:auth', (data, cb) => {
+                    if (!_.isEmpty(this.supportedAgents)) {
+                        const ver = data.ver;
+                        const bt = data.bt;
+
+                        if (_.isEmpty(ver) || _.isEmpty(bt) || _.isEmpty(this.supportedAgents[ver])
||
+                            this.supportedAgents[ver].buildTime > bt)
+                            return cb('You are using an older version of the agent. Please
reload agent archive');
+                    }
 
-            this._wsAgents.on('connection', (_wsSrv) => new Agent(_wsSrv, self));
+                    mongo.Account.findOne({token: data.token}, (err, account) => {
+                        // TODO IGNITE-1379 send error to web master.
+                        if (err)
+                            cb('Failed to authorize user');
+                        else if (!account)
+                            cb('Invalid token, user not found');
+                        else {
+                            const agent = new Agent(socket);
+
+                            socket.on('disconnect', () => {
+                                this._removeAgent(account._id, agent);
+                            });
+
+                            this._addAgent(account._id, agent);
+
+                            cb();
+                        }
+                    });
+                });
+            });
         }
 
         /**
@@ -389,10 +400,10 @@ module.exports.factory = function(_, fs, path, JSZip, socketio, apacheIgnite,
se
          * @returns {int} connected agent count.
          */
         addAgentListener(userId, user) {
-            let users = this._users[userId];
+            let users = this._browsers[userId];
 
             if (!users)
-                this._users[userId] = users = [];
+                this._browsers[userId] = users = [];
 
             users.push(user);
 
@@ -407,7 +418,7 @@ module.exports.factory = function(_, fs, path, JSZip, socketio, apacheIgnite,
se
          * @returns {int} connected agent count.
          */
         removeAgentListener(userId, user) {
-            const users = this._users[userId];
+            const users = this._browsers[userId];
 
             _.remove(users, (_user) => _user === user);
         }
@@ -453,7 +464,7 @@ module.exports.factory = function(_, fs, path, JSZip, socketio, apacheIgnite,
se
 
             _.remove(agents, (_agent) => _agent === agent);
 
-            const users = this._users[userId];
+            const users = this._browsers[userId];
 
             _.forEach(users, (user) => user.emit('agent:count', {count: agents.length}));
         }
@@ -470,7 +481,7 @@ module.exports.factory = function(_, fs, path, JSZip, socketio, apacheIgnite,
se
 
             agents.push(agent);
 
-            const users = this._users[userId];
+            const users = this._browsers[userId];
 
             _.forEach(users, (user) => user.emit('agent:count', {count: agents.length}));
         }

http://git-wip-us.apache.org/repos/asf/ignite/blob/b30b52b1/modules/control-center-web/src/main/js/serve/app.js
----------------------------------------------------------------------
diff --git a/modules/control-center-web/src/main/js/serve/app.js b/modules/control-center-web/src/main/js/serve/app.js
index e4b5eca..5d6b2cf 100644
--- a/modules/control-center-web/src/main/js/serve/app.js
+++ b/modules/control-center-web/src/main/js/serve/app.js
@@ -21,7 +21,7 @@
 
 module.exports = {
     implements: 'app',
-    inject: ['require(express)', 'configure', 'routes', 'io']
+    inject: ['require(express)', 'configure', 'routes']
 };
 
 module.exports.factory = function(Express, configure, routes) {

http://git-wip-us.apache.org/repos/asf/ignite/blob/b30b52b1/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
new file mode 100644
index 0000000..4470ce2
--- /dev/null
+++ b/modules/control-center-web/src/main/js/serve/browser.js
@@ -0,0 +1,254 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+
+'use strict';
+
+// Fire me up!
+
+/**
+ * Module interaction with browsers.
+ */
+module.exports = {
+    implements: 'browser-manager',
+    inject: ['require(lodash)', 'require(socket.io)', 'require(apache-ignite)', 'agent-manager',
'configure']
+};
+
+module.exports.factory = (_, socketio, apacheIgnite, agentMgr, configure) => {
+    const SqlFieldsQuery = apacheIgnite.SqlFieldsQuery;
+    const ScanQuery = apacheIgnite.ScanQuery;
+
+    return {
+        attach: (server) => {
+            const io = socketio(server);
+
+            configure.socketio(io);
+
+            io.sockets.on('connection', (socket) => {
+                const user = socket.client.request.user;
+
+                // Return available drivers to browser.
+                socket.on('schemaImport:drivers', (cb) => {
+                    agentMgr.findAgent(user._id)
+                        .then((agent) => agent.availableDrivers())
+                        .then((drivers) => cb(null, drivers))
+                        .catch((errMsg) => cb(errMsg));
+                });
+
+                // Return schemas from database to browser.
+                socket.on('schemaImport:schemas', (preset, cb) => {
+                    agentMgr.findAgent(user._id)
+                        .then((agent) => {
+                            const jdbcInfo = {user: preset.user, password: preset.password};
+
+                            return agent.metadataSchemas(preset.jdbcDriverJar, preset.jdbcDriverClass,
preset.jdbcUrl, jdbcInfo);
+                        })
+                        .then((schemas) => cb(null, schemas))
+                        .catch((errMsg) => cb(errMsg));
+                });
+
+                // Return tables from database to browser.
+                socket.on('schemaImport:tables', (preset, cb) => {
+                    agentMgr.findAgent(user._id)
+                        .then((agent) => {
+                            const jdbcInfo = {user: preset.user, password: preset.password};
+
+                            return agent.metadataTables(preset.jdbcDriverJar, preset.jdbcDriverClass,
preset.jdbcUrl, jdbcInfo,
+                                preset.schemas, preset.tablesOnly);
+                        })
+                        .then((tables) => cb(null, tables))
+                        .catch((errMsg) => cb(errMsg));
+                });
+
+                // Return topology command result from grid to browser.
+                socket.on('node:topology', (demo, attr, mtr, cb) => {
+                    agentMgr.findAgent(user._id)
+                        .then((agent) => agent.ignite(demo).cluster(attr, mtr))
+                        .then((clusters) => cb(null, clusters))
+                        .catch((errMsg) => cb(errMsg));
+                });
+
+                // 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(() => cb())
+                        .catch((errMsg) => cb(errMsg));
+                });
+
+                // Execute query on node and return first page to browser.
+                socket.on('node:query', (args, cb) => {
+                    agentMgr.findAgent(user._id)
+                        .then((agent) => {
+                            // Create sql query.
+                            const qry = args.type === 'SCAN' ? new ScanQuery() : new SqlFieldsQuery(args.query);
+
+                            // Set page size for query.
+                            qry.setPageSize(args.pageSize);
+
+                            return agent.ignite(args.demo).cache(args.cacheName).query(qry).nextPage();
+                        })
+                        .then((cursor) => cb(null, {
+                            meta: cursor.fieldsMetadata(),
+                            rows: cursor.page(),
+                            queryId: cursor.queryId()
+                        }))
+                        .catch((errMsg) => cb(errMsg));
+                });
+
+                // Fetch next page for query and return result to browser.
+                socket.on('node:query:fetch', (args, cb) => {
+                    agentMgr.findAgent(user._id)
+                        .then((agent) => {
+                            const cache = agent.ignite(args.demo).cache(args.cacheName);
+
+                            const cmd = cache._createCommand('qryfetch')
+                                .addParam('qryId', args.queryId)
+                                .addParam('pageSize', args.pageSize);
+
+                            return cache.__createPromise(cmd);
+                        })
+                        .then((page) => cb(null, {
+                            rows: page.items,
+                            last: page === null || page.last
+                        }))
+                        .catch((errMsg) => cb(errMsg));
+                });
+
+                // Execute query on node and return full result to browser.
+                socket.on('node:query:getAll', (args, cb) => {
+                    agentMgr.findAgent(user._id)
+                        .then((agent) => {
+                            // Create sql query.
+                            const qry = args.type === 'SCAN' ? new ScanQuery() : new SqlFieldsQuery(args.query);
+
+                            // Set page size for query.
+                            qry.setPageSize(1024);
+
+                            const cursor = agent.ignite(args.demo).cache(args.cacheName).query(qry);
+
+                            return cursor.getAll()
+                                .then((rows) => cb(null, {meta: cursor.fieldsMetadata(),
rows}));
+                        })
+                        .catch((errMsg) => cb(errMsg));
+                });
+
+                // 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((caches) => {
+                            let types = [];
+
+                            const _compact = (className) => {
+                                return className.replace('java.lang.', '').replace('java.util.',
'').replace('java.sql.', '');
+                            };
+
+                            const _typeMapper = (meta, typeName) => {
+                                let fields = meta.fields[typeName];
+
+                                let columns = [];
+
+                                for (const fieldName in fields) {
+                                    if (fields.hasOwnProperty(fieldName)) {
+                                        const fieldClass = _compact(fields[fieldName]);
+
+                                        columns.push({
+                                            type: 'field',
+                                            name: fieldName,
+                                            clazz: fieldClass,
+                                            system: fieldName === '_KEY' || fieldName ===
'_VAL',
+                                            cacheName: meta.cacheName,
+                                            typeName
+                                        });
+                                    }
+                                }
+
+                                const indexes = [];
+
+                                for (const index of meta.indexes[typeName]) {
+                                    fields = [];
+
+                                    for (const field of index.fields) {
+                                        fields.push({
+                                            type: 'index-field',
+                                            name: field,
+                                            order: index.descendings.indexOf(field) <
0,
+                                            unique: index.unique,
+                                            cacheName: meta.cacheName,
+                                            typeName
+                                        });
+                                    }
+
+                                    if (fields.length > 0) {
+                                        indexes.push({
+                                            type: 'index',
+                                            name: index.name,
+                                            children: fields,
+                                            cacheName: meta.cacheName,
+                                            typeName
+                                        });
+                                    }
+                                }
+
+                                columns = _.sortBy(columns, 'name');
+
+                                if (!_.isEmpty(indexes)) {
+                                    columns = columns.concat({
+                                        type: 'indexes',
+                                        name: 'Indexes',
+                                        cacheName: meta.cacheName,
+                                        typeName,
+                                        children: indexes
+                                    });
+                                }
+
+                                return {
+                                    type: 'type',
+                                    cacheName: meta.cacheName || '',
+                                    typeName,
+                                    children: columns
+                                };
+                            };
+
+                            for (const meta of caches) {
+                                const cacheTypes = meta.types.map(_typeMapper.bind(null,
meta));
+
+                                if (!_.isEmpty(cacheTypes))
+                                    types = types.concat(cacheTypes);
+                            }
+
+                            return cb(null, types);
+                        })
+                        .catch((errMsg) => cb(errMsg));
+                });
+
+                const count = agentMgr.addAgentListener(user._id, socket);
+
+                socket.emit('agent:count', {count});
+            });
+
+            // Handle browser disconnect event.
+            io.sockets.on('disconnect', (socket) =>
+                agentMgr.removeAgentListener(socket.client.request.user._id, socket)
+            );
+        }
+    };
+};

http://git-wip-us.apache.org/repos/asf/ignite/blob/b30b52b1/modules/control-center-web/src/main/js/serve/configure.js
----------------------------------------------------------------------
diff --git a/modules/control-center-web/src/main/js/serve/configure.js b/modules/control-center-web/src/main/js/serve/configure.js
index ac27751..71f7c8a 100644
--- a/modules/control-center-web/src/main/js/serve/configure.js
+++ b/modules/control-center-web/src/main/js/serve/configure.js
@@ -19,6 +19,9 @@
 
 // Fire me up!
 
+/**
+ * Module for configuration express and websocket server.
+ */
 module.exports = {
     implements: 'configure',
     inject: ['require(morgan)', 'require(cookie-parser)', 'require(body-parser)',

http://git-wip-us.apache.org/repos/asf/ignite/blob/b30b52b1/modules/control-center-web/src/main/js/serve/io.js
----------------------------------------------------------------------
diff --git a/modules/control-center-web/src/main/js/serve/io.js b/modules/control-center-web/src/main/js/serve/io.js
deleted file mode 100644
index ded00fa..0000000
--- a/modules/control-center-web/src/main/js/serve/io.js
+++ /dev/null
@@ -1,242 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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.
- */
-
-'use strict';
-
-// Fire me up!
-
-module.exports = {
-    implements: 'io',
-    inject: ['require(lodash)', 'require(socket.io)', 'require(apache-ignite)', 'agent',
'configure']
-};
-
-module.exports.factory = (_, socketio, apacheIgnite, agentMgr, configure) => {
-    const SqlFieldsQuery = apacheIgnite.SqlFieldsQuery;
-    const ScanQuery = apacheIgnite.ScanQuery;
-
-    return {
-        listen: (server) => {
-            const io = socketio(server);
-
-            configure.socketio(io);
-
-            io.sockets.on('connection', (socket) => {
-                const user = socket.client.request.user;
-
-                socket.on('schemaImport:drivers', (cb) => {
-                    agentMgr.findAgent(user._id)
-                        .then((agent) => agent.availableDrivers())
-                        .then((drivers) => cb(null, drivers))
-                        .catch((errMsg) => cb(errMsg));
-                });
-
-                socket.on('schemaImport:schemas', (preset, cb) => {
-                    agentMgr.findAgent(user._id)
-                        .then((agent) => {
-                            const jdbcInfo = {user: preset.user, password: preset.password};
-
-                            return agent.metadataSchemas(preset.jdbcDriverJar, preset.jdbcDriverClass,
preset.jdbcUrl, jdbcInfo);
-                        })
-                        .then((schemas) => cb(null, schemas))
-                        .catch((errMsg) => cb(errMsg));
-                });
-
-                socket.on('schemaImport:tables', (preset, cb) => {
-                    agentMgr.findAgent(user._id)
-                        .then((agent) => {
-                            const jdbcInfo = {user: preset.user, password: preset.password};
-
-                            return agent.metadataTables(preset.jdbcDriverJar, preset.jdbcDriverClass,
preset.jdbcUrl, jdbcInfo,
-                                preset.schemas, preset.tablesOnly);
-                        })
-                        .then((tables) => cb(null, tables))
-                        .catch((errMsg) => cb(errMsg));
-                });
-
-                socket.on('node:topology', (demo, attr, mtr, cb) => {
-                    agentMgr.findAgent(user._id)
-                        .then((agent) => agent.ignite(demo).cluster(attr, mtr))
-                        .then((clusters) => cb(null, clusters))
-                        .catch((errMsg) => cb(errMsg));
-                });
-
-                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(() => cb())
-                        .catch((errMsg) => cb(errMsg));
-                });
-
-                socket.on('node:query', (args, cb) => {
-                    agentMgr.findAgent(user._id)
-                        .then((agent) => {
-                            // Create sql query.
-                            const qry = args.type === 'SCAN' ? new ScanQuery() : new SqlFieldsQuery(args.query);
-
-                            // Set page size for query.
-                            qry.setPageSize(args.pageSize);
-
-                            return agent.ignite(args.demo).cache(args.cacheName).query(qry).nextPage();
-                        })
-                        .then((cursor) => cb(null, {
-                            meta: cursor.fieldsMetadata(),
-                            rows: cursor.page(),
-                            queryId: cursor.queryId()
-                        }))
-                        .catch((errMsg) => cb(errMsg));
-                });
-
-                socket.on('node:query:fetch', (args, cb) => {
-                    agentMgr.findAgent(user._id)
-                        .then((agent) => {
-                            const cache = agent.ignite(args.demo).cache(args.cacheName);
-
-                            const cmd = cache._createCommand('qryfetch')
-                                .addParam('qryId', args.queryId)
-                                .addParam('pageSize', args.pageSize);
-
-                            return cache.__createPromise(cmd);
-                        })
-                        .then((page) => cb(null, {
-                            rows: page.items,
-                            last: page === null || page.last
-                        }))
-                        .catch((errMsg) => cb(errMsg));
-                });
-
-                socket.on('node:query:getAll', (args, cb) => {
-                    agentMgr.findAgent(user._id)
-                        .then((agent) => {
-                            // Create sql query.
-                            const qry = args.type === 'SCAN' ? new ScanQuery() : new SqlFieldsQuery(args.query);
-
-                            // Set page size for query.
-                            qry.setPageSize(args.pageSize);
-
-                            return agent.ignite(args.demo).cache(args.cacheName).query(qry).getAll();
-                        })
-                        .then((cursor) => cb(null, {
-                            meta: cursor.fieldsMetadata(),
-                            rows: cursor.page()
-                        }))
-                        .catch((errMsg) => cb(errMsg));
-                });
-
-                socket.on('node:cache:metadata', (args, cb) => {
-                    agentMgr.findAgent(user._id)
-                        .then((agent) => agent.ignite(args.demo).cache(args.cacheName).metadata())
-                        .then((caches) => {
-                            let types = [];
-
-                            const _compact = (className) => {
-                                return className.replace('java.lang.', '').replace('java.util.',
'').replace('java.sql.', '');
-                            };
-
-                            const _typeMapper = (meta, typeName) => {
-                                let fields = meta.fields[typeName];
-
-                                let columns = [];
-
-                                for (const fieldName in fields) {
-                                    if (fields.hasOwnProperty(fieldName)) {
-                                        const fieldClass = _compact(fields[fieldName]);
-
-                                        columns.push({
-                                            type: 'field',
-                                            name: fieldName,
-                                            clazz: fieldClass,
-                                            system: fieldName === '_KEY' || fieldName ===
'_VAL',
-                                            cacheName: meta.cacheName,
-                                            typeName
-                                        });
-                                    }
-                                }
-
-                                const indexes = [];
-
-                                for (const index of meta.indexes[typeName]) {
-                                    fields = [];
-
-                                    for (const field of index.fields) {
-                                        fields.push({
-                                            type: 'index-field',
-                                            name: field,
-                                            order: index.descendings.indexOf(field) <
0,
-                                            unique: index.unique,
-                                            cacheName: meta.cacheName,
-                                            typeName
-                                        });
-                                    }
-
-                                    if (fields.length > 0) {
-                                        indexes.push({
-                                            type: 'index',
-                                            name: index.name,
-                                            children: fields,
-                                            cacheName: meta.cacheName,
-                                            typeName
-                                        });
-                                    }
-                                }
-
-                                columns = _.sortBy(columns, 'name');
-
-                                if (!_.isEmpty(indexes)) {
-                                    columns = columns.concat({
-                                        type: 'indexes',
-                                        name: 'Indexes',
-                                        cacheName: meta.cacheName,
-                                        typeName,
-                                        children: indexes
-                                    });
-                                }
-
-                                return {
-                                    type: 'type',
-                                    cacheName: meta.cacheName || '',
-                                    typeName,
-                                    children: columns
-                                };
-                            };
-
-                            for (const meta of caches) {
-                                const cacheTypes = meta.types.map(_typeMapper.bind(null,
meta));
-
-                                if (!_.isEmpty(cacheTypes))
-                                    types = types.concat(cacheTypes);
-                            }
-
-                            return cb(null, types);
-                        })
-                        .catch((errMsg) => cb(errMsg));
-                });
-
-                const count = agentMgr.addAgentListener(user._id, socket);
-
-                socket.emit('agent:count', {count});
-            });
-
-            io.sockets.on('disconnect', (socket) =>
-                agentMgr.removeAgentListener(socket.client.request.user._id, socket)
-            );
-        }
-    };
-};

http://git-wip-us.apache.org/repos/asf/ignite/blob/b30b52b1/modules/control-center-web/src/main/js/serve/mail.js
----------------------------------------------------------------------
diff --git a/modules/control-center-web/src/main/js/serve/mail.js b/modules/control-center-web/src/main/js/serve/mail.js
index 36b4fa7..2c67276 100644
--- a/modules/control-center-web/src/main/js/serve/mail.js
+++ b/modules/control-center-web/src/main/js/serve/mail.js
@@ -19,6 +19,9 @@
 
 // Fire me up!
 
+/**
+ * Module for send email.
+ */
 module.exports = {
     implements: 'mail',
     inject: ['require(nodemailer)', 'settings']

http://git-wip-us.apache.org/repos/asf/ignite/blob/b30b52b1/modules/control-center-web/src/main/js/serve/mongo.js
----------------------------------------------------------------------
diff --git a/modules/control-center-web/src/main/js/serve/mongo.js b/modules/control-center-web/src/main/js/serve/mongo.js
index 6a80b7a..67f2cba 100644
--- a/modules/control-center-web/src/main/js/serve/mongo.js
+++ b/modules/control-center-web/src/main/js/serve/mongo.js
@@ -19,6 +19,9 @@
 
 // Fire me up!
 
+/**
+ * Module mongo schema.
+ */
 module.exports = {
     implements: 'mongo',
     inject: ['require(mongoose-deep-populate)', 'require(passport-local-mongoose)', 'settings',
'ignite_modules/mongo:*']

http://git-wip-us.apache.org/repos/asf/ignite/blob/b30b52b1/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 4e123bf..1d46170 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,7 +21,7 @@
 
 module.exports = {
     implements: 'agent-routes',
-    inject: ['require(lodash)', 'require(express)', 'require(fs)', 'require(jszip)', 'require(apache-ignite)',
'settings', 'agent']
+    inject: ['require(lodash)', 'require(express)', 'require(fs)', 'require(jszip)', 'require(apache-ignite)',
'settings', 'agent-manager']
 };
 
 /**

http://git-wip-us.apache.org/repos/asf/ignite/blob/b30b52b1/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 9d24239..13ad045 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
@@ -21,18 +21,18 @@
 
 module.exports = {
     implements: 'profile-routes',
-    inject: ['require(lodash)', 'require(express)', 'mongo', 'agent']
+    inject: ['require(lodash)', 'require(express)', 'mongo', 'agent-manager']
 };
 
 /**
  *
- * @param _
- * @param express
+ * @param _ Lodash module
+ * @param express Express module
  * @param mongo
- * @param {AgentManager} agent
+ * @param {AgentManager} agentMgr
  * @returns {Promise}
  */
-module.exports.factory = function(_, express, mongo, agent) {
+module.exports.factory = function(_, express, mongo, agentMgr) {
     return new Promise((resolveFactory) => {
         const router = new express.Router();
 
@@ -80,7 +80,7 @@ module.exports.factory = function(_, express, mongo, agent) {
                 })
                 .then((user) => {
                     if (!params.token || user.token !== params.token)
-                        agent.close(user._id);
+                        agentMgr.close(user._id);
 
                     for (const param in params) {
                         if (params.hasOwnProperty(param))

http://git-wip-us.apache.org/repos/asf/ignite/blob/b30b52b1/modules/control-center-web/src/main/js/serve/settings.js
----------------------------------------------------------------------
diff --git a/modules/control-center-web/src/main/js/serve/settings.js b/modules/control-center-web/src/main/js/serve/settings.js
index eada7f7..b8a3c71 100644
--- a/modules/control-center-web/src/main/js/serve/settings.js
+++ b/modules/control-center-web/src/main/js/serve/settings.js
@@ -19,6 +19,9 @@
 
 // Fire me up!
 
+/**
+ * Module with server-side configuration.
+ */
 module.exports = {
     implements: 'settings',
     inject: ['require(nconf)', 'require(fs)']


Mime
View raw message