Repository: ignite
Updated Branches:
  refs/heads/ignite-843-rc1 c8655032b -> 58bc59816


IGNITE-1485 WIP ping agent before load metadata.


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

Branch: refs/heads/ignite-843-rc1
Commit: 58bc59816abd7d6837c6b9ccbec939c63a3c118a
Parents: c865503
Author: Alexey Kuznetsov <[email protected]>
Authored: Fri Oct 16 16:45:17 2015 +0700
Committer: Alexey Kuznetsov <[email protected]>
Committed: Fri Oct 16 16:45:17 2015 +0700

----------------------------------------------------------------------
 .../src/main/js/controllers/common-module.js    | 105 +++++++++++++++----
 .../main/js/controllers/metadata-controller.js  |  77 ++++++++------
 .../src/main/js/controllers/sql-controller.js   |   2 +-
 .../src/main/js/routes/agent.js                 |   6 ++
 .../js/views/configuration/metadata-load.jade   |   2 +
 .../main/js/views/templates/agent-download.jade |   3 +-
 6 files changed, 138 insertions(+), 57 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/58bc5981/modules/control-center-web/src/main/js/controllers/common-module.js
----------------------------------------------------------------------
diff --git 
a/modules/control-center-web/src/main/js/controllers/common-module.js 
b/modules/control-center-web/src/main/js/controllers/common-module.js
index edcff71..84cafad 100644
--- a/modules/control-center-web/src/main/js/controllers/common-module.js
+++ b/modules/control-center-web/src/main/js/controllers/common-module.js
@@ -1935,25 +1935,33 @@ consoleModule.controller('auth', [
 
 // Download agent controller.
 consoleModule.controller('agent-download', [
-    '$common', '$scope', '$interval', '$modal', '$window', function ($common, 
$scope, $interval, $modal, $window) {
+    '$http', '$common', '$scope', '$interval', '$modal', '$window', function 
($http, $common, $scope, $interval, $modal, $window) {
         // Pre-fetch modal dialogs.
-        var _agentDownloadModal = $modal({scope: $scope, templateUrl: 
'/agent/download', show: false});
+        var _agentDownloadModal = $modal({scope: $scope, templateUrl: 
'/agent/download', show: false, backdrop: 'static'});
+
+        _agentDownloadModal.skipDialogShowing = false;
 
         var _agentDownloadHide = _agentDownloadModal.hide;
 
+        /**
+         * Special dialog hide function.
+         */
         _agentDownloadModal.hide = function () {
-            if (_agentDownloadModal.$isShown)
-                $common.hideAlert();
+            $common.hideAlert();
 
-            if (!$scope.checkConnection)
-                $interval.cancel(_agentDownloadModal.updatePromise);
+            _agentDownloadModal.skipDialogShowing = true;
 
             _agentDownloadHide();
         };
 
+        /**
+         * Close dialog and go by specified link.
+         */
         $scope.goHome = function () {
-            if ($scope.checkConnection)
-                $window.location = '/';
+            if ($window.location == _agentDownloadModal.homeLink)
+                $window.location.reload();
+            else
+                $window.location = _agentDownloadModal.homeLink;
 
             $scope.checkConnection = false;
 
@@ -1973,37 +1981,88 @@ consoleModule.controller('agent-download', [
             document.body.removeChild(lnk);
         };
 
+        /**
+         * Base handler of exceptions on agent interaction
+         *
+         * @param errMsg Error message.
+         * @param status Error code.
+         */
         var _handleException = function (errMsg, status) {
-            if (!_agentDownloadModal.$isShown)
+            if (_agentDownloadModal.skipDialogShowing)
+                _agentDownloadModal.skipDialogShowing = false;
+            else if (!_agentDownloadModal.$isShown)
                 _agentDownloadModal.$promise.then(_agentDownloadModal.show);
 
             if (status != 503)
                 $common.showError(errMsg, 'top-right', 'body', true);
         };
 
-        $scope.awaitAgent = function (checkFn) {
-            _agentDownloadModal.checkFn = checkFn;
-
+        /**
+         * Start interval to agent listening.
+         *
+         * @param skipFirst If <code>true</code> first invoke will be missed.
+         */
+        function _startInterval(skipFirst) {
             _agentDownloadModal.updatePromise = $interval(function () {
-                checkFn(_agentDownloadModal.hide, _handleException);
+                _tryWithAgent();
             }, 5000, 0, false);
 
-            checkFn(_agentDownloadModal.hide, _handleException);
-        };
+            if (!skipFirst)
+                _tryWithAgent();
+        }
 
-        $scope.checkNodeConnection = function (checkFn) {
-            _agentDownloadModal.checkFn = checkFn;
+        /**
+         * Stop interval to agent listening.
+         */
+        function _stopInterval() {
+            $interval.cancel(_agentDownloadModal.updatePromise);
+        }
 
-            $scope.checkConnection = true;
+        /**
+         * Try to access agent and execute specified function.
+         */
+        function _tryWithAgent() {
+            $http.post('/agent/ping', undefined, {timeout: 3000})
+                .success(function () {
+                    _agentDownloadModal.skipDialogShowing = true;
 
-            _agentDownloadModal.$options.backdrop = 'static';
+                    _agentDownloadModal.hide();
 
-            _agentDownloadModal.updatePromise = $interval(function () {
-                checkFn(_agentDownloadModal.hide, _handleException);
-            }, 5000, 0, false);
+                    if (_agentDownloadModal.simpleExecution)
+                        _stopInterval();
 
-            checkFn(_agentDownloadModal.hide, _handleException);
+                    _agentDownloadModal.checkFn(_agentDownloadModal.hide, 
_handleException);
+                })
+                .error(function (errMsg, status) {
+                    _handleException(errMsg, status);
+                });
         }
+
+        /**
+         * Start listening of agent by ping.
+         *
+         * @param checkFn Function to execute by timer when agent available.
+         * @param simpleExecution When <code>true</code> checkFn will invoke 
to first success only.
+         * @param homeLink Link to move on "Back to configuration" button 
click.
+         */
+        $scope.startAgentListening = function (checkFn, simpleExecution, 
homeLink) {
+            _agentDownloadModal.skipDialogShowing = false;
+
+            _agentDownloadModal.checkFn = checkFn;
+
+            _agentDownloadModal.simpleExecution = simpleExecution;
+
+            _agentDownloadModal.homeLink = homeLink || '/';
+
+            _startInterval();
+        };
+
+        /**
+         * Stop listening of agent by ping.
+         */
+        $scope.finishAgentListening = function () {
+            _stopInterval();
+        };
     }]);
 
 // Navigation bar controller.

http://git-wip-us.apache.org/repos/asf/ignite/blob/58bc5981/modules/control-center-web/src/main/js/controllers/metadata-controller.js
----------------------------------------------------------------------
diff --git 
a/modules/control-center-web/src/main/js/controllers/metadata-controller.js 
b/modules/control-center-web/src/main/js/controllers/metadata-controller.js
index a2c7843..6c5aec6 100644
--- a/modules/control-center-web/src/main/js/controllers/metadata-controller.js
+++ b/modules/control-center-web/src/main/js/controllers/metadata-controller.js
@@ -203,7 +203,7 @@ consoleModule.controller('metadataController', [
             };
 
             $scope.selectSchema = function () {
-                if ($common.isDefined($scope.loadMeta))
+                if ($common.isDefined($scope.loadMeta) && 
$common.isDefined($scope.loadMeta.displayedSchemas))
                     $scope.loadMeta.allSchemasSelected = 
$scope.loadMeta.displayedSchemas.length > 0
                         && _.every($scope.loadMeta.displayedSchemas, 'use', 
true);
             };
@@ -217,7 +217,7 @@ consoleModule.controller('metadataController', [
             };
 
             $scope.selectTable = function () {
-                if ($common.isDefined($scope.loadMeta))
+                if ($common.isDefined($scope.loadMeta) && 
$common.isDefined($scope.loadMeta.displayedTables))
                     $scope.loadMeta.allTablesSelected = 
$scope.loadMeta.displayedTables.length > 0
                         && _.every($scope.loadMeta.displayedTables, 'use', 
true);
             };
@@ -229,6 +229,14 @@ consoleModule.controller('metadataController', [
             // Pre-fetch modal dialogs.
             var loadMetaModal = $modal({scope: $scope, templateUrl: 
'metadata/metadata-load', show: false});
 
+            var hideLoadMetadata = loadMetaModal.hide;
+
+            loadMetaModal.hide = function () {
+                $scope.finishAgentListening();
+
+                hideLoadMetadata();
+            };
+
             // Show load metadata modal.
             $scope.showLoadMetadataModal = function () {
                 $scope.loadMeta = {
@@ -241,43 +249,50 @@ consoleModule.controller('metadataController', [
                     info: 'Configure connection to database'
                 };
 
-                function getDrivers(onSuccess, onException) {
-                    // Get available JDBC drivers via agent.
-                    $http.post('/agent/drivers', undefined)
-                        .success(function (drivers) {
-                            onSuccess();
+                $scope.loadMeta.action = 'drivers';
 
-                            if (drivers && drivers.length > 0) {
-                                $scope.jdbcDriverJars = _.map(drivers, 
function (driver) {
-                                    return {value: driver.jdbcDriverJar, 
label: driver.jdbcDriverJar};
-                                });
+                loadMetaModal.show();
 
-                                jdbcDrivers = drivers;
+                $loading.start('loadingMetadataFromDb');
 
-                                $scope.preset.jdbcDriverJar = 
drivers[0].jdbcDriverJar;
+                $scope.startAgentListening(function (onSuccess, onException) {
+                    // Get available JDBC drivers via agent.
+                    if ($scope.loadMeta.action == 'drivers') {
+                        $http.post('/agent/drivers')
+                            .success(function (drivers) {
+                                onSuccess();
+
+                                if (drivers && drivers.length > 0) {
+                                    $scope.jdbcDriverJars = _.map(drivers, 
function (driver) {
+                                        return {value: driver.jdbcDriverJar, 
label: driver.jdbcDriverJar};
+                                    });
 
-                                function openLoadMetadataModal() {
-                                    loadMetaModal.$promise.then(function () {
-                                        $scope.loadMeta.action = 'connect';
-                                        $scope.loadMeta.tables = [];
+                                    jdbcDrivers = drivers;
 
-                                        loadMetaModal.show();
+                                    $scope.preset.jdbcDriverJar = 
drivers[0].jdbcDriverJar;
 
-                                        $focus('jdbcUrl');
-                                    });
-                                }
+                                    function openLoadMetadataModal() {
+                                        loadMetaModal.$promise.then(function 
() {
+                                            $scope.loadMeta.action = 'connect';
+                                            $scope.loadMeta.tables = [];
 
-                                
$common.confirmUnsavedChanges($scope.ui.isDirty(), openLoadMetadataModal);
-                            }
-                            else
-                                $common.showError('JDBC drivers not found!');
-                        })
-                        .error(function (errMsg, status) {
-                            onException(errMsg, status);
-                        });
-                }
+                                            $focus('jdbcUrl');
+                                        });
+                                    }
 
-                $scope.awaitAgent(getDrivers);
+                                    
$common.confirmUnsavedChanges($scope.ui.isDirty(), openLoadMetadataModal);
+                                }
+                                else
+                                    $common.showError('JDBC drivers not 
found!');
+                            })
+                            .error(function (errMsg, status) {
+                                onException(errMsg, status);
+                            })
+                            .finally(function () {
+                                $loading.finish('loadingMetadataFromDb');
+                            });
+                    }
+                }, true, '/configuration/metadata');
             };
 
             function _loadSchemas() {

http://git-wip-us.apache.org/repos/asf/ignite/blob/58bc5981/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 fd071f8..799962c 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
@@ -357,7 +357,7 @@ consoleModule.controller('sqlController',
             });
     }
 
-    $scope.checkNodeConnection(getTopology);
+    $scope.startAgentListening(getTopology);
 
     var _columnFilter = function(paragraph) {
         return paragraph.disabledSystemColumns || paragraph.systemColumns ? 
_allColumn : _hideColumn;

http://git-wip-us.apache.org/repos/asf/ignite/blob/58bc5981/modules/control-center-web/src/main/js/routes/agent.js
----------------------------------------------------------------------
diff --git a/modules/control-center-web/src/main/js/routes/agent.js 
b/modules/control-center-web/src/main/js/routes/agent.js
index c93feeb..7d1592f 100644
--- a/modules/control-center-web/src/main/js/routes/agent.js
+++ b/modules/control-center-web/src/main/js/routes/agent.js
@@ -247,6 +247,12 @@ router.post('/cache/metadata', function (req, res) {
     }
 });
 
+/* Ping client. */
+router.post('/ping', function (req, res) {
+    if (_client(req, res) != null)
+        res.sendStatus(200);
+});
+
 /* Get JDBC drivers list. */
 router.post('/drivers', function (req, res) {
     var client = _client(req, res);

http://git-wip-us.apache.org/repos/asf/ignite/blob/58bc5981/modules/control-center-web/src/main/js/views/configuration/metadata-load.jade
----------------------------------------------------------------------
diff --git 
a/modules/control-center-web/src/main/js/views/configuration/metadata-load.jade 
b/modules/control-center-web/src/main/js/views/configuration/metadata-load.jade
index bbae222..4712e25 100644
--- 
a/modules/control-center-web/src/main/js/views/configuration/metadata-load.jade
+++ 
b/modules/control-center-web/src/main/js/views/configuration/metadata-load.jade
@@ -25,6 +25,8 @@ mixin chk(mdl, change, tip)
             #errors-container.modal-header.header
                 button.close(ng-click='$hide()' aria-hidden='true') &times;
                 h4.modal-title Load metadata from database
+            .metadata-content(ng-show='loadMeta.action == "drivers"' 
style='margin-bottom: 60px')
+                label.labelField Loading JDBC drivers...
             .metadata-content(ng-show='loadMeta.action == "connect"' 
style='margin-bottom: 60px')
                 form.form-horizontal(name='loadForm' novalidate)
                     .settings-row(ng-repeat='field in metadataDb')

http://git-wip-us.apache.org/repos/asf/ignite/blob/58bc5981/modules/control-center-web/src/main/js/views/templates/agent-download.jade
----------------------------------------------------------------------
diff --git 
a/modules/control-center-web/src/main/js/views/templates/agent-download.jade 
b/modules/control-center-web/src/main/js/views/templates/agent-download.jade
index 47b0940..8bcda60 100644
--- a/modules/control-center-web/src/main/js/views/templates/agent-download.jade
+++ b/modules/control-center-web/src/main/js/views/templates/agent-download.jade
@@ -16,7 +16,6 @@
     .modal-dialog
         .modal-content
             #errors-container.modal-header.header
-                button.close(ng-if='!checkConnection' ng-click='$hide()') 
&times;
                 h4.modal-title Connection to Ignite Web Agent is not 
established
             .agent-download
                 p Please download and run&nbsp;
@@ -45,5 +44,5 @@
                     i.tipLabel.fa.fa-clipboard(ng-click-copy='{{user.token}}' 
bs-tooltip='' data-title='Copy security token to clipboard')
                     i.tipLabel.fa.fa-question-circle(ng-if=lines bs-tooltip='' 
data-title='The security token is used for authorization of web agent')
             .modal-footer
-                button.btn.btn-default(ng-if='checkConnection' 
ng-click='goHome()') Back to Configuration
+                button.btn.btn-default(ng-click='goHome()') Back to 
Configuration
                 button.btn.btn-primary(ng-click='downloadAgent()') Download zip

Reply via email to