ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akuznet...@apache.org
Subject ignite git commit: IGNITE-843 WIP load metadata in batch
Date Thu, 17 Sep 2015 11:55:08 GMT
Repository: ignite
Updated Branches:
  refs/heads/ignite-843 5f0e912c0 -> 10202fa74


IGNITE-843 WIP load metadata in batch


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

Branch: refs/heads/ignite-843
Commit: 10202fa74f48754cc03b9c377acefd9b0eeaa04f
Parents: 5f0e912
Author: Alexey Kuznetsov <akuznetsov@apache.org>
Authored: Thu Sep 17 18:55:03 2015 +0700
Committer: Alexey Kuznetsov <akuznetsov@apache.org>
Committed: Thu Sep 17 18:55:03 2015 +0700

----------------------------------------------------------------------
 .../src/main/js/controllers/admin-controller.js |  2 +-
 .../main/js/controllers/caches-controller.js    |  6 +-
 .../main/js/controllers/clusters-controller.js  |  6 +-
 .../src/main/js/controllers/common-module.js    | 97 ++++++++------------
 .../main/js/controllers/metadata-controller.js  | 68 +++++++++-----
 .../src/main/js/controllers/sql-controller.js   |  4 +-
 .../src/main/js/routes/metadata.js              | 85 +++++++++++------
 7 files changed, 154 insertions(+), 114 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/10202fa7/modules/control-center-web/src/main/js/controllers/admin-controller.js
----------------------------------------------------------------------
diff --git a/modules/control-center-web/src/main/js/controllers/admin-controller.js b/modules/control-center-web/src/main/js/controllers/admin-controller.js
index 094e5a7..5e0dc46 100644
--- a/modules/control-center-web/src/main/js/controllers/admin-controller.js
+++ b/modules/control-center-web/src/main/js/controllers/admin-controller.js
@@ -37,7 +37,7 @@ controlCenterModule.controller('adminController', ['$scope', '$window',
'$http',
     };
 
     $scope.removeUser = function (user) {
-        $confirm.show('Are you sure you want to remove user: "' + user.username + '"?').then(function
() {
+        $confirm.confirm('Are you sure you want to remove user: "' + user.username + '"?').then(function
() {
             $http.post('admin/remove', {userId: user._id}).success(
                 function () {
                     var i = _.findIndex($scope.users, function (u) {

http://git-wip-us.apache.org/repos/asf/ignite/blob/10202fa7/modules/control-center-web/src/main/js/controllers/caches-controller.js
----------------------------------------------------------------------
diff --git a/modules/control-center-web/src/main/js/controllers/caches-controller.js b/modules/control-center-web/src/main/js/controllers/caches-controller.js
index ae1b4e2..0b0516b 100644
--- a/modules/control-center-web/src/main/js/controllers/caches-controller.js
+++ b/modules/control-center-web/src/main/js/controllers/caches-controller.js
@@ -500,7 +500,7 @@ controlCenterModule.controller('cachesController', [
                 $table.tableReset();
 
                 if (validate($scope.backupItem))
-                    $copy.show($scope.backupItem.name).then(function (newName) {
+                    $copy.confirm($scope.backupItem.name).then(function (newName) {
                         var item = angular.copy($scope.backupItem);
 
                         item._id = undefined;
@@ -516,7 +516,7 @@ controlCenterModule.controller('cachesController', [
 
                 var selectedItem = $scope.selectedItem;
 
-                $confirm.show('Are you sure you want to remove cache: "' + selectedItem.name
+ '"?').then(
+                $confirm.confirm('Are you sure you want to remove cache: "' + selectedItem.name
+ '"?').then(
                     function () {
                         $scope.ui.markPristine(0);
 
@@ -552,7 +552,7 @@ controlCenterModule.controller('cachesController', [
             $scope.removeAllItems = function () {
                 $table.tableReset();
 
-                $confirm.show('Are you sure you want to remove all caches?').then(
+                $confirm.confirm('Are you sure you want to remove all caches?').then(
                     function () {
                         $scope.ui.markPristine(0);
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/10202fa7/modules/control-center-web/src/main/js/controllers/clusters-controller.js
----------------------------------------------------------------------
diff --git a/modules/control-center-web/src/main/js/controllers/clusters-controller.js b/modules/control-center-web/src/main/js/controllers/clusters-controller.js
index 0ea516f..f79b32e 100644
--- a/modules/control-center-web/src/main/js/controllers/clusters-controller.js
+++ b/modules/control-center-web/src/main/js/controllers/clusters-controller.js
@@ -422,7 +422,7 @@ controlCenterModule.controller('clustersController', ['$scope', '$controller',
'
             $table.tableReset();
 
             if (validate($scope.backupItem))
-                $copy.show($scope.backupItem.name).then(function (newName) {
+                $copy.confirm($scope.backupItem.name).then(function (newName) {
                     var item = angular.copy($scope.backupItem);
 
                     item._id = undefined;
@@ -438,7 +438,7 @@ controlCenterModule.controller('clustersController', ['$scope', '$controller',
'
 
             var selectedItem = $scope.selectedItem;
 
-            $confirm.show('Are you sure you want to remove cluster: "' + selectedItem.name
+ '"?').then(
+            $confirm.confirm('Are you sure you want to remove cluster: "' + selectedItem.name
+ '"?').then(
                 function () {
                     $scope.ui.markPristine(0);
 
@@ -474,7 +474,7 @@ controlCenterModule.controller('clustersController', ['$scope', '$controller',
'
         $scope.removeAllItems = function () {
             $table.tableReset();
 
-            $confirm.show('Are you sure you want to remove all clusters?').then(
+            $confirm.confirm('Are you sure you want to remove all clusters?').then(
                 function () {
                     $scope.ui.markPristine(0);
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/10202fa7/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 e8b974d..e5c118f 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
@@ -857,7 +857,7 @@ controlCenterModule.service('$common', [
 controlCenterModule.service('$confirm', function ($modal, $rootScope, $q) {
     var scope = $rootScope.$new();
 
-    var deferred;
+    var deferred = $q.defer();
 
     // Configure title of cancel button.
     scope.cancelTitle = 'Cancel';
@@ -870,14 +870,10 @@ controlCenterModule.service('$confirm', function ($modal, $rootScope,
$q) {
 
     var confirmModal = $modal({templateUrl: '/confirm', scope: scope, placement: 'center',
show: false});
 
-    var parentShow = confirmModal.show;
-
-    confirmModal.show = function (content) {
+    confirmModal.confirm = function (content) {
         scope.content = content || 'Confirm deletion?';
 
-        deferred = $q.defer();
-
-        parentShow();
+        confirmModal.show();
 
         return deferred.promise;
     };
@@ -886,93 +882,84 @@ controlCenterModule.service('$confirm', function ($modal, $rootScope,
$q) {
 });
 
 // Service for confirm or skip several steps.
-controlCenterModule.service('$stepConfirm', function ($timeout, $modal, $rootScope, $q) {
+controlCenterModule.service('$stepConfirm', function ($rootScope, $modal,  $q) {
     var scope = $rootScope.$new();
 
-    var deferred;
-
-    scope.ui = {forAll: false};
+    scope.ui = {batchConfirmApplyToAll: false};
 
     var contentGenerator = function () {
         return 'No content';
     };
 
-    var itemsToConfirm = [];
+    var items = [];
 
     var curIx = 0;
 
-    function nextElement(skip) {
-        itemsToConfirm[curIx].skip = skip;
-
-        curIx += 1;
+    var deferred = $q.defer();
 
-        if (curIx >= modelArray.length) {
+    function _done(cancel) {
+        if (cancel)
+            deferred.reject('cancelled');
+        else
             deferred.resolve();
 
-            stepConfirmModal.hide();
-        }
+        stepConfirmModal.hide();
+    }
+
+    function _nextElement(skip) {
+        items[curIx].skip = skip;
+
+        curIx++;
+
+        if (curIx < items.length)
+            scope.content = contentGenerator(itemsToConfirm = [curIx]);
+        else
+            _done();
     }
 
     /**
      * Generate reject event on cancel for special event processing.
      */
     scope.batchConfirmCancel = function () {
-        deferred.reject('cancelled');
-
-        stepConfirmModal.hide();
+        _done(true);
     };
 
     scope.batchConfirmSkip = function () {
-        if (scope.ui.batchConfirmAll) {
+        if (scope.ui.batchConfirmApplyToAll) {
             for (var i = curIx; i < itemsToConfirm.length; i++)
                 itemsToConfirm[i].skip = true;
 
-            deferred.resolve();
-
-            stepConfirmModal.hide();
+            _done();
         }
         else
-            nextElement(true);
+            _nextElement(true);
     };
 
     scope.batchConfirmOverwrite = function () {
-        if (scope.ui.batchConfirmAll) {
-            deferred.resolve();
-
-            stepConfirmModal.hide();
-        }
+        if (scope.ui.batchConfirmApplyToAll)
+            _done();
         else
-            nextElement(false);
+            _nextElement(false);
     };
 
     var stepConfirmModal = $modal({templateUrl: '/confirm/batch', scope: scope, placement:
'center', show: false});
 
-    var parentShow = stepConfirmModal.show;
-
     /**
      * Show confirm all dialog.
      *
      * @param confirmMessageFx Function to generate a confirm message.
-     * @param model Array of element to process by confirm.
+     * @param itemsToConfirm Array of element to process by confirm.
      */
-    stepConfirmModal.confirmAll = function (confirmMessageFx, model) {
-        contentGenerator = generator;
+    stepConfirmModal.confirm = function (confirmMessageFx, itemsToConfirm) {
+        contentGenerator = confirmMessageFx;
 
-        items = _.filter(model, function (item) {
-            return item.confirm;
-        });
+        items = itemsToConfirm;
 
-        $timeout(function () {
-            scope.content = contentGenerator(items[0]);
-        });
-
-        curIx = 0;
+        scope.content = contentGenerator(items[0]);
 
         scope.ui.batchConfirmAll = false;
 
-        deferred = $q.defer();
-
-        parentShow();
+        stepConfirmModal.show();
 
         return deferred.promise;
     };
@@ -980,11 +967,11 @@ controlCenterModule.service('$stepConfirm', function ($timeout, $modal,
$rootSco
     return stepConfirmModal;
 });
 
-// 'Save as' popup service.
+// 'Clone' popup service.
 controlCenterModule.service('$copy', function ($modal, $rootScope, $q) {
     var scope = $rootScope.$new();
 
-    var deferred;
+    var deferred = $q.defer();
 
     scope.ok = function (newName) {
         deferred.resolve(newName);
@@ -994,14 +981,10 @@ controlCenterModule.service('$copy', function ($modal, $rootScope, $q)
{
 
     var copyModal = $modal({templateUrl: '/clone', scope: scope, placement: 'center', show:
false});
 
-    var parentShow = copyModal.show;
-
-    copyModal.show = function (oldName) {
+    copyModal.confirm = function (oldName) {
         scope.newName = oldName + '(1)';
 
-        deferred = $q.defer();
-
-        parentShow();
+        copyModal.show();
 
         return deferred.promise;
     };

http://git-wip-us.apache.org/repos/asf/ignite/blob/10202fa7/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 d50cdd2..4ad7ec2 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
@@ -345,7 +345,33 @@ controlCenterModule.controller('metadataController', [
                 $loading.start('loadingMetadataFromDb');
 
                 $http.post('metadata/save/batch', batch)
-                    .success(function (saved) {
+                    .success(function (savedBatch) {
+                        var lastItem = undefined;
+                        var newItems = [];
+
+                        _.forEach(savedBatch, function (savedItem) {
+                            var idx = _.findIndex($scope.metadatas, function (meta) {
+                                return meta._id == savedItem._id;
+                            });
+
+                            if (idx >= 0)
+                                $scope.metadatas[idx] = savedItem;
+                            else
+                                newItems.push(savedItem);
+
+                            lastItem = savedItem;
+                        });
+
+                        _.forEach(newItems, function (item) {
+                            $scope.metadatas.push(item);
+                        });
+
+                        if (!lastItem && $scope.metadatas.length > 0)
+                            lastItem = $scope.metadatas[0];
+
+                        $scope.selectItem(lastItem);
+                        $scope.ui.markPristine(1);
+
                         $common.showInfo('Cache type metadata loaded from database.');
                     })
                     .error(function (errMsg) {
@@ -369,7 +395,6 @@ controlCenterModule.controller('metadataController', [
                 var batch = [];
                 var tables = [];
                 var dupCnt = 1;
-                var confirmNeeded = false;
 
                 _.forEach($scope.loadMeta.tables, function (table) {
                     if (table.use) {
@@ -459,8 +484,6 @@ controlCenterModule.controller('metadataController', [
                         };
 
                         if ($common.isDefined(metaFound)) {
-                            confirmNeeded = true;
-
                             meta = metaFound;
                             meta.confirm = true;
                         }
@@ -494,8 +517,12 @@ controlCenterModule.controller('metadataController', [
                         '</span>';
                 }
 
-                if (confirmNeeded)
-                    $stepConfirm.confirmAll(overwriteMessage, batch).then(function () {
+                var itemsToConfirm = _.filter(batch, function (item) {
+                    return item.confirm;
+                });
+
+                if (itemsToConfirm.length > 0)
+                    $stepConfirm.confirm(overwriteMessage, itemsToConfirm).then(function
() {
                         _saveBatch(batch);
                     }, function () {
                         $common.showError('Cache type metadata loading interrupted by user.');
@@ -731,7 +758,7 @@ controlCenterModule.controller('metadataController', [
             }
 
             // Save cache type metadata into database.
-            function save(item, quiet) {
+            function save(item) {
                 var qry = $common.metadataForQueryConfigured(item);
                 var str = $common.metadataForStoreConfigured(item);
 
@@ -743,25 +770,24 @@ controlCenterModule.controller('metadataController', [
                     item.kind = 'store';
 
                 $http.post('metadata/save', item)
-                    .success(function (_id) {
+                    .success(function (res) {
                         $scope.ui.markPristine(0);
 
+                        var savedMeta = res[0];
+
                         var idx = _.findIndex($scope.metadatas, function (metadata) {
-                            return metadata._id == _id;
+                            return metadata._id == savedMeta._id;
                         });
 
                         if (idx >= 0)
-                            angular.extend($scope.metadatas[idx], item);
-                        else {
-                            item._id = _id;
+                            $scope.metadatas[idx] = savedMeta;
+                        else
+                            $scope.metadatas.push(savedMeta);
 
-                            $scope.metadatas.push(item);
-                            $scope.selectItem(item);
-                            $scope.ui.markPristine(1);
-                        }
+                        $scope.selectItem(savedMeta);
+                        $scope.ui.markPristine(1);
 
-                        if (!quiet)
-                            $common.showInfo('Cache type metadata"' + item.valueType + '"
saved.');
+                        $common.showInfo('Cache type metadata"' + item.valueType + '" saved.');
                     })
                     .error(function (errMsg) {
                         $common.showError(errMsg);
@@ -783,7 +809,7 @@ controlCenterModule.controller('metadataController', [
                 $table.tableReset();
 
                 if (validate($scope.backupItem))
-                    $copy.show($scope.backupItem.valueType).then(function (newName) {
+                    $copy.confirm($scope.backupItem.valueType).then(function (newName) {
                         var item = angular.copy($scope.backupItem);
 
                         item._id = undefined;
@@ -799,7 +825,7 @@ controlCenterModule.controller('metadataController', [
 
                 var selectedItem = $scope.selectedItem;
 
-                $confirm.show('Are you sure you want to remove cache type metadata: "' +
selectedItem.valueType + '"?').then(
+                $confirm.confirm('Are you sure you want to remove cache type metadata: "'
+ selectedItem.valueType + '"?').then(
                     function () {
                         var _id = selectedItem._id;
 
@@ -834,7 +860,7 @@ controlCenterModule.controller('metadataController', [
             $scope.removeAllItems = function () {
                 $table.tableReset();
 
-                $confirm.show('Are you sure you want to remove all metadata?').then(
+                $confirm.confirm('Are you sure you want to remove all metadata?').then(
                     function () {
                         $scope.ui.markPristine(0);
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/10202fa7/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 61f3e59..2f1f5d9 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
@@ -154,7 +154,7 @@ controlCenterModule.controller('sqlController', ['$scope', '$window','$controlle
     };
 
     $scope.removeNotebook = function () {
-        $confirm.show('Are you sure you want to remove notebook: "' + $scope.notebook.name
+ '"?').then(
+        $confirm.confirm('Are you sure you want to remove notebook: "' + $scope.notebook.name
+ '"?').then(
             function () {
                 $http.post('/notebooks/remove', {_id: $scope.notebook._id})
                     .success(function () {
@@ -236,7 +236,7 @@ controlCenterModule.controller('sqlController', ['$scope', '$window','$controlle
     };
 
     $scope.removeParagraph = function(paragraph) {
-        $confirm.show('Are you sure you want to remove paragraph: "' + paragraph.name + '"?').then(
+        $confirm.confirm('Are you sure you want to remove paragraph: "' + paragraph.name
+ '"?').then(
             function () {
                 var paragraph_idx = _.findIndex($scope.notebook.paragraphs, function (item)
{
                     return paragraph == item;

http://git-wip-us.apache.org/repos/asf/ignite/blob/10202fa7/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 22e3016..78843d9 100644
--- a/modules/control-center-web/src/main/js/routes/metadata.js
+++ b/modules/control-center-web/src/main/js/routes/metadata.js
@@ -74,44 +74,75 @@ router.post('/list', function (req, res) {
     });
 });
 
-/**
- * Save metadata.
- */
-router.post('/save', function (req, res) {
-    var params = req.body;
-    var metaId = params._id;
-    var caches = params.caches;
-
-    if (req.body._id)
-        db.CacheTypeMetadata.update({_id: req.body._id}, req.body, {upsert: true}, function
(err) {
-            if (db.processed(err, res))
-                db.Cache.update({_id: {$in: caches}}, {$addToSet: {metadatas: metaId}}, {multi:
true}, function (err) {
+function _save(metas, res) {
+    var total = metas.length;
+
+    var results = [];
+
+    function saveAll() {
+        if (total > 0) {
+            total--;
+
+            var meta = metas.pop();
+            var metaId = meta._id;
+            var caches = meta.caches;
+
+            if (metaId)
+                db.CacheTypeMetadata.update({_id: meta._id}, meta, {upsert: true}, function
(err) {
                     if (db.processed(err, res))
-                        db.Cache.update({_id: {$nin: caches}}, {$pull: {metadatas: metaId}},
{multi: true}, function (err) {
+                        db.Cache.update({_id: {$in: caches}}, {$addToSet: {metadatas: metaId}},
{multi: true}, function (err) {
                             if (db.processed(err, res))
-                                res.send(params._id);
+                                db.Cache.update({_id: {$nin: caches}}, {$pull: {metadatas:
metaId}}, {multi: true}, function (err) {
+                                    if (db.processed(err, res)) {
+                                        results.push(meta);
+
+                                        saveAll();
+                                    }
+                                });
                         });
                 });
-        });
-    else {
-        db.CacheTypeMetadata.findOne({space: req.body.space, valueType: req.body.valueType},
function (err, metadata) {
-            if (db.processed(err, res)) {
-                if (metadata)
-                    return res.status(500).send('Cache type metadata with value type: "'
+ metadata.valueType + '" already exist.');
-
-                (new db.CacheTypeMetadata(req.body)).save(function (err, metadata) {
+            else {
+                db.CacheTypeMetadata.findOne({space: meta.space, valueType: meta.valueType},
function (err, metadata) {
                     if (db.processed(err, res)) {
-                        metaId = metadata._id;
+                        if (metadata)
+                            return res.status(500).send('Cache type metadata with value type:
"' + metadata.valueType + '" already exist.');
 
-                        db.Cache.update({_id: {$in: caches}}, {$addToSet: {metadatas: metaId}},
{multi: true}, function (err) {
-                            if (db.processed(err, res))
-                                res.send(metaId);
+                        (new db.CacheTypeMetadata(meta)).save(function (err, metadata) {
+                            if (db.processed(err, res)) {
+                                metaId = metadata._id;
+
+                                db.Cache.update({_id: {$in: caches}}, {$addToSet: {metadatas:
metaId}}, {multi: true}, function (err) {
+                                    if (db.processed(err, res)) {
+                                        results.push(metadata);
+
+                                        saveAll();
+                                    }
+                                });
+                            }
                         });
                     }
                 });
             }
-        });
+        }
+        else
+            res.send(results);
     }
+
+    saveAll();
+}
+
+/**
+ * Save metadata.
+ */
+router.post('/save', function (req, res) {
+    _save([req.body], res);
+});
+
+/**
+ * Batch save metadata .
+ */
+router.post('/save/batch', function (req, res) {
+    _save(req.body, res);
 });
 
 /**


Mime
View raw message