ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akuznet...@apache.org
Subject ignite git commit: GNITE-2347 WIP Rework demo for load metadata.
Date Wed, 13 Jan 2016 09:11:04 GMT
Repository: ignite
Updated Branches:
  refs/heads/ignite-843-rc2 ec046d339 -> 5231fc7f9


GNITE-2347 WIP Rework demo for load metadata.


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

Branch: refs/heads/ignite-843-rc2
Commit: 5231fc7f9402831bd86fdab7e5629ed3b3dcf144
Parents: ec046d3
Author: Alexey Kuznetsov <akuznetsov@apache.org>
Authored: Wed Jan 13 16:11:15 2016 +0700
Committer: Alexey Kuznetsov <akuznetsov@apache.org>
Committed: Wed Jan 13 16:11:15 2016 +0700

----------------------------------------------------------------------
 .../handlers/DatabaseMetadataExtractor.java     |   8 +-
 .../main/js/controllers/metadata-controller.js  | 158 ++++++++++++-------
 .../src/main/js/routes/metadata.js              |   3 +-
 .../js/views/configuration/metadata-load.jade   |   4 +-
 .../main/js/views/configuration/metadata.jade   |   4 +-
 5 files changed, 113 insertions(+), 64 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/5231fc7f/modules/control-center-agent/src/main/java/org/apache/ignite/agent/handlers/DatabaseMetadataExtractor.java
----------------------------------------------------------------------
diff --git a/modules/control-center-agent/src/main/java/org/apache/ignite/agent/handlers/DatabaseMetadataExtractor.java
b/modules/control-center-agent/src/main/java/org/apache/ignite/agent/handlers/DatabaseMetadataExtractor.java
index ba146e7..0498656 100644
--- a/modules/control-center-agent/src/main/java/org/apache/ignite/agent/handlers/DatabaseMetadataExtractor.java
+++ b/modules/control-center-agent/src/main/java/org/apache/ignite/agent/handlers/DatabaseMetadataExtractor.java
@@ -95,10 +95,10 @@ public class DatabaseMetadataExtractor {
 
             return schemas;
         }
-        catch (SQLException e) {
+        catch (Throwable e) {
             log.error("Failed to collect schemas", e);
 
-            throw e;
+            throw new SQLException("Failed to collect schemas", e);
         }
     }
 
@@ -124,10 +124,10 @@ public class DatabaseMetadataExtractor {
 
             return metadata;
         }
-        catch (SQLException e) {
+        catch (Throwable e) {
             log.error("Failed to collect metadata", e);
 
-            throw e;
+            throw new SQLException("Failed to collect metadata", e);
         }
     }
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/5231fc7f/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 397acf5..d123c5e 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
@@ -32,6 +32,39 @@ consoleModule.controller('metadataController', function ($filter, $http,
$timeou
         $scope.ui.generateCaches = true;
         $scope.ui.generatedCachesClusters = [];
 
+        $scope.removeDemoDropdown = [{ 'text': 'Remove Demo data', 'click': 'removeDemoItems()'}];
+
+        $scope.removeDemoItems = function () {
+            $table.tableReset();
+
+            $confirm.confirm('Are you sure you want to remove all demo metadata and caches?')
+                .then(function () {
+                    $http.post('/api/v1/configuration/metadata/remove/demo')
+                        .success(function () {
+                            $common.showInfo('All demo metadata and caches have been removed');
+
+                            $http.post('/api/v1/configuration/metadata/list')
+                                .success(function (data) {
+                                    $scope.spaces = data.spaces;
+                                    $scope.clusters = data.clusters;
+                                    $scope.caches = data.caches;
+                                    $scope.metadatas = data.metadatas;
+
+                                    $scope.ui.generatedCachesClusters = [];
+
+                                    _.forEach($scope.clusters, function (cluster) {
+                                        $scope.ui.generatedCachesClusters.push(cluster.value);
+                                    });
+                                });
+
+                            $scope.selectItem(undefined, undefined);
+                        })
+                        .error(function (errMsg) {
+                            $common.showError(errMsg);
+                        });
+                });
+        };
+
         $scope.joinTip = $common.joinTip;
         $scope.getModel = $common.getModel;
         $scope.javaBuildInClasses = $common.javaBuildInClasses;
@@ -193,7 +226,26 @@ consoleModule.controller('metadataController', function ($filter, $http,
$timeou
             }
         ];
 
-        function _loadPresets () {
+        $scope.selectedPreset = {
+            db: 'unknown',
+            jdbcDriverJar: '',
+            jdbcDriverClass: '',
+            jdbcUrl: 'jdbc:[database]',
+            user: 'sa',
+            password: '',
+            tablesOnly: true
+        };
+
+        $scope.demoConnection = {
+            db: 'H2',
+            jdbcDriverClass: 'org.h2.Driver',
+            jdbcUrl: 'jdbc:h2:mem:demo-db',
+            user: 'sa',
+            password: '',
+            tablesOnly: true
+        };
+
+    function _loadPresets () {
             try {
                var restoredPresets =  JSON.parse(localStorage.dbPresets);
 
@@ -230,8 +282,17 @@ consoleModule.controller('metadataController', function ($filter, $http,
$timeou
         }
 
         $scope.$watch('ui.selectedJdbcDriverJar', function (val) {
-            if (val)
-                $scope.updateSelectedPreset(val);
+            if (val && !$scope.loadMeta.demo) {
+                var foundPreset = _findPreset(val);
+
+                var selectedPreset = $scope.selectedPreset;
+
+                selectedPreset.db = foundPreset.db;
+                selectedPreset.jdbcDriverJar = foundPreset.jdbcDriverJar;
+                selectedPreset.jdbcDriverClass = foundPreset.jdbcDriverClass;
+                selectedPreset.jdbcUrl = foundPreset.jdbcUrl;
+                selectedPreset.user = foundPreset.user;
+            }
         }, true);
 
         $scope.ui.showValid = true;
@@ -254,18 +315,6 @@ consoleModule.controller('metadataController', function ($filter, $http,
$timeou
             return result;
         }
 
-        $scope.updateSelectedPreset = function (selectedJdbcDriverJar) {
-            var foundPreset = _findPreset(selectedJdbcDriverJar);
-
-            var selectedPreset = $scope.selectedPreset;
-
-            selectedPreset.db = foundPreset.db;
-            selectedPreset.jdbcDriverJar = foundPreset.jdbcDriverJar;
-            selectedPreset.jdbcDriverClass = foundPreset.jdbcDriverClass;
-            selectedPreset.jdbcUrl = foundPreset.jdbcUrl;
-            selectedPreset.user = foundPreset.user;
-        };
-
         $scope.supportedJdbcTypes = $common.mkOptions($common.SUPPORTED_JDBC_TYPES);
 
         $scope.supportedJavaTypes = $common.mkOptions($common.javaBuildInTypes);
@@ -371,16 +420,6 @@ consoleModule.controller('metadataController', function ($filter, $http,
$timeou
                                 onSuccess();
 
                                 if (drivers && drivers.length > 0) {
-                                    $scope.selectedPreset = {
-                                        db: 'unknown',
-                                        jdbcDriverJar: '',
-                                        jdbcDriverClass: '',
-                                        jdbcUrl: 'jdbc:[database]',
-                                        user: 'sa',
-                                        password: '',
-                                        tablesOnly: true
-                                    };
-
                                     drivers = _.sortBy(drivers, 'jdbcDriverJar');
 
                                     if ($scope.loadMeta.demo) {
@@ -389,13 +428,11 @@ consoleModule.controller('metadataController', function ($filter, $http,
$timeou
                                         });
 
                                         if (_h2DrvJar) {
-                                            $scope.selectedPreset.db = 'H2';
-                                            $scope.jdbcDriverJar = _h2DrvJar.jdbcDriverJar;
-                                            $scope.jdbcDriverClass = 'org.h2.Driver';
-                                            $scope.jdbcUrl = 'jdbc:h2:mem:demo-db';
+                                            $scope.demoConnection.db = 'H2';
+                                            $scope.demoConnection.jdbcDriverJar = _h2DrvJar.jdbcDriverJar;
                                         }
                                         else
-                                            $scope.selectedPreset = null;
+                                            $scope.demoConnection.db = 'unknown';
                                     }
                                     else {
                                         drivers.forEach(function (driver) {
@@ -446,10 +483,12 @@ consoleModule.controller('metadataController', function ($filter, $http,
$timeou
         function _loadSchemas() {
             $loading.start('loadingMetadataFromDb');
 
+            var preset = $scope.loadMeta.demo ? $scope.demoConnection : $scope.selectedPreset;
+
             if (!$scope.loadMeta.demo)
-                _savePreset($scope.selectedPreset);
+                _savePreset(preset);
 
-            $http.post('/api/v1/agent/schemas', $scope.selectedPreset)
+            $http.post('/api/v1/agent/schemas', preset)
                 .success(function (schemas) {
                     $scope.loadMeta.schemas = _.map(schemas, function (schema) {
                         return {use: false, name: schema};
@@ -482,14 +521,17 @@ consoleModule.controller('metadataController', function ($filter, $http,
$timeou
             $loading.start('loadingMetadataFromDb');
 
             $scope.loadMeta.allTablesSelected = false;
-            $scope.selectedPreset.schemas = [];
+
+            var preset = $scope.loadMeta.demo ? $scope.demoConnection : $scope.selectedPreset;
+
+            preset.schemas = [];
 
             _.forEach($scope.loadMeta.schemas, function (schema) {
                 if (schema.use)
-                    $scope.selectedPreset.schemas.push(schema.name);
+                    preset.schemas.push(schema.name);
             });
 
-            $http.post('/api/v1/agent/metadata', $scope.selectedPreset)
+            $http.post('/api/v1/agent/metadata', preset)
                 .success(function (tables) {
                     tables.forEach(function (tbl) {
                         Object.defineProperty(tbl, 'label', {
@@ -730,7 +772,8 @@ consoleModule.controller('metadataController', function ($filter, $http,
$timeou
                     if ($scope.ui.generateCaches)
                         meta.newCache = {
                             name: typeName,
-                            clusters: $scope.ui.generatedCachesClusters
+                            clusters: $scope.ui.generatedCachesClusters,
+                            demo: $scope.loadMeta.demo
                         };
 
                     batch.push(meta);
@@ -809,7 +852,7 @@ consoleModule.controller('metadataController', function ($filter, $http,
$timeou
             switch ($scope.loadMeta.action) {
                 case 'connect':
                     if ($scope.loadMeta.demo)
-                        res = $common.isDefined($scope.selectedPreset);
+                        res = $common.isDefined($scope.demoConnection.db === 'H2');
 
                     break;
 
@@ -858,6 +901,26 @@ consoleModule.controller('metadataController', function ($filter, $http,
$timeou
         // When landing on the page, get metadatas and show them.
         $loading.start('loadingMetadataScreen');
 
+        function restoreSelection() {
+            var lastSelectedMetadata = angular.fromJson(sessionStorage.lastSelectedMetadata);
+
+            if (lastSelectedMetadata) {
+                var idx = _.findIndex($scope.metadatas, function (metadata) {
+                    return metadata._id === lastSelectedMetadata;
+                });
+
+                if (idx >= 0)
+                    $scope.selectItem($scope.metadatas[idx]);
+                else {
+                    sessionStorage.removeItem('lastSelectedMetadata');
+
+                    selectFirstItem();
+                }
+            }
+            else
+                selectFirstItem();
+        }
+
         $http.post('/api/v1/configuration/metadata/list')
             .success(function (data) {
                 $scope.spaces = data.spaces;
@@ -881,25 +944,8 @@ consoleModule.controller('metadataController', function ($filter, $http,
$timeou
 
                         if ($common.getQueryVariable('new'))
                             $scope.createItem($common.getQueryVariable('id'));
-                        else {
-                            var lastSelectedMetadata = angular.fromJson(sessionStorage.lastSelectedMetadata);
-
-                            if (lastSelectedMetadata) {
-                                var idx = _.findIndex($scope.metadatas, function (metadata)
{
-                                    return metadata._id === lastSelectedMetadata;
-                                });
-
-                                if (idx >= 0)
-                                    $scope.selectItem($scope.metadatas[idx]);
-                                else {
-                                    sessionStorage.removeItem('lastSelectedMetadata');
-
-                                    selectFirstItem();
-                                }
-                            }
-                            else
-                                selectFirstItem();
-                        }
+                        else
+                            restoreSelection();
 
                         $timeout(function () {
                             $scope.$apply();

http://git-wip-us.apache.org/repos/asf/ignite/blob/5231fc7f/modules/control-center-web/src/main/js/routes/metadata.js
----------------------------------------------------------------------
diff --git a/modules/control-center-web/src/main/js/routes/metadata.js b/modules/control-center-web/src/main/js/routes/metadata.js
index c8f5eba..0d11d8d 100644
--- a/modules/control-center-web/src/main/js/routes/metadata.js
+++ b/modules/control-center-web/src/main/js/routes/metadata.js
@@ -153,7 +153,8 @@ function _save(metas, res) {
                                     }
                                 },
                                 readThrough: true,
-                                writeThrough: true
+                                writeThrough: true,
+                                demo: meta.demo
                             })).save(function (err, cache) {
                                 var cacheId = cache._id;
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/5231fc7f/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 ba3dace..73edea0 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
@@ -27,14 +27,14 @@ mixin chk(mdl, change, tip)
                 h4.modal-title Load metadata from database
             .metadata-content(ng-show='loadMeta.action == "drivers"' style="margin-bottom:
256px;")
             .metadata-content(ng-show='loadMeta.action == "connect" && loadMeta.demo'
style='margin-bottom: 141px')
-                div(ng-if='selectedPreset')
+                div(ng-if='demoConnection.db == "H2"')
                     label Demo description:
                     ul
                         li In-memory H2 database server will be started inside agent
                         li Database will be populated with sample tables
                         li You could test loading metadata using this demo database
                         li Click "Next" to continue
-                div(ng-if='!selectedPreset')
+                div(ng-if='demoConnection.db != "H2"')
                     label Demo could not be started
                         ul
                             li Agent failed to resolve H2 database jar

http://git-wip-us.apache.org/repos/asf/ignite/blob/5231fc7f/modules/control-center-web/src/main/js/views/configuration/metadata.jade
----------------------------------------------------------------------
diff --git a/modules/control-center-web/src/main/js/views/configuration/metadata.jade b/modules/control-center-web/src/main/js/views/configuration/metadata.jade
index 8c07a70..1c9b7ed 100644
--- a/modules/control-center-web/src/main/js/views/configuration/metadata.jade
+++ b/modules/control-center-web/src/main/js/views/configuration/metadata.jade
@@ -67,8 +67,10 @@ include ../includes/controls
                     button.btn.btn-primary(id='new-item' ng-click='createItem()') Add metadata
                 .panel-tip-container(bs-tooltip='' data-title='Load metadata from database'
data-placement='bottom')
                     button.btn.btn-primary(ng-click='showLoadMetadataModal(false)') Load
from database
-                .panel-tip-container(bs-tooltip='' data-title='Load metadata from demo database'
data-placement='bottom')
+                .btn-group.panel-tip-container(bs-tooltip='' data-title='Load metadata from
demo database' data-placement='bottom')
                     button.btn.btn-info(ng-click='showLoadMetadataModal(true)') Load from
demo database
+                        button.btn.dropdown-toggle.btn-info(id='remove-demo-dropdown' data-toggle='dropdown'
data-container='body' bs-dropdown='removeDemoDropdown' data-placement='bottom-right')
+                            span.caret
                 +save-remove-buttons('metadata')
                 hr
             form.form-horizontal(name='ui.inputForm' ng-show='backupItem && tableVisibleRow((displayedRows
| metadatasValidation:ui.showValid:true), selectedItem)' novalidate unsaved-warning-form)


Mime
View raw message