ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akuznet...@apache.org
Subject incubator-ignite git commit: IGNITE-843: Link clusters an caches.
Date Tue, 18 Aug 2015 04:04:00 GMT
Repository: incubator-ignite
Updated Branches:
  refs/heads/ignite-843 cd2048eb4 -> e86538d73


IGNITE-843: Link clusters an caches.


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

Branch: refs/heads/ignite-843
Commit: e86538d738e46089d606c2b9b30bd2a56d362691
Parents: cd2048e
Author: AKuznetsov <akuznetsov@gridgain.com>
Authored: Tue Aug 18 11:04:15 2015 +0700
Committer: AKuznetsov <akuznetsov@gridgain.com>
Committed: Tue Aug 18 11:04:15 2015 +0700

----------------------------------------------------------------------
 .../main/js/controllers/caches-controller.js    |  25 ++++-
 .../main/js/controllers/clusters-controller.js  |  28 +++--
 .../src/main/js/routes/clusters.js              | 110 +++++++++++--------
 3 files changed, 106 insertions(+), 57 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e86538d7/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 ac11049..6cd0727 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
@@ -199,7 +199,28 @@ controlCenterModule.controller('cachesController', [
                             });
 
                             if (idx >= 0) {
-                                $scope.selectedItem = $scope.caches[idx];
+                                var cache = $scope.caches[idx];
+
+                                var restoredSelectedItem = angular.fromJson(sessionStorage.cacheSelectedItem);
+
+                                // Clusters not changed by user. We should take clusters
from server as they could be changed on Clusters screen.
+                                if (restoredSelectedItem && _.isEqual(restoredItem.clusters,
restoredSelectedItem.clusters)) {
+                                    restoredItem.clusters = [];
+
+                                    _.forEach(cache.clusters, function (cache) {
+                                        restoredItem.clusters.push(cache)
+                                    });
+                                }
+                                else {
+                                    // Clusters changed by user. We need to remove deleted
clusters (if any).
+                                    restoredItem.clusters = _.filter(restoredItem.clusters,
function (clusterId) {
+                                        return _.findIndex($scope.clusters, function (scopeCcluster)
{
+                                                return scopeCcluster.value == clusterId;
+                                            }) >= 0;
+                                    });
+                                }
+
+                                $scope.selectedItem = cache;
                                 $scope.backupItem = restoredItem;
                             }
                             else
@@ -225,6 +246,8 @@ controlCenterModule.controller('cachesController', [
 
                 $scope.selectedItem = item;
                 $scope.backupItem = angular.copy(item);
+
+                sessionStorage.cacheSelectedItem = angular.toJson(item);
             };
 
             // Add new cache.

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e86538d7/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 a128f02..ef4bff5 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
@@ -175,18 +175,24 @@ controlCenterModule.controller('clustersController', ['$scope', '$http',
'$commo
                         if (idx >= 0) {
                             var cluster = $scope.clusters[idx];
 
-                            var restoredSelectedItem = angular.fromJson(sessionStorage.clusterSelectedBackupItem);
+                            var restoredSelectedItem = angular.fromJson(sessionStorage.clusterSelectedItem);
 
-                            if (restoredSelectedItem) {
-                                // TODO
-                            }
+                            // Caches not changed by user. We should take caches from server
as they could be changed on Caches screen.
+                            if (restoredSelectedItem && _.isEqual(restoredItem.caches,
restoredSelectedItem.caches)) {
+                                restoredItem.caches = [];
 
-                            // Remove deleted caches.
-                            restoredItem.caches = _.filter(restoredItem.caches, function
(cacheId) {
-                                return _.findIndex($scope.caches, function (scopeCache) {
-                                        return scopeCache.value == cacheId;
-                                    }) >= 0;
-                            });
+                                _.forEach(cluster.caches, function (cache) {
+                                    restoredItem.caches.push(cache)
+                                });
+                            }
+                            else {
+                                // Caches changed by user. We need to remove deleted caches
(if any).
+                                restoredItem.caches = _.filter(restoredItem.caches, function
(cacheId) {
+                                    return _.findIndex($scope.caches, function (scopeCache)
{
+                                            return scopeCache.value == cacheId;
+                                        }) >= 0;
+                                });
+                            }
 
                             $scope.selectedItem = cluster;
                             $scope.backupItem = restoredItem;
@@ -215,7 +221,7 @@ controlCenterModule.controller('clustersController', ['$scope', '$http',
'$commo
             $scope.selectedItem = item;
             $scope.backupItem = angular.copy(item);
 
-            sessionStorage.slectedClusterBackupItem = angular.toJson(item);
+            sessionStorage.clusterSelectedItem = angular.toJson(item);
         };
 
         // Add new cluster.

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e86538d7/modules/control-center-web/src/main/js/routes/clusters.js
----------------------------------------------------------------------
diff --git a/modules/control-center-web/src/main/js/routes/clusters.js b/modules/control-center-web/src/main/js/routes/clusters.js
index 0bf6061..a027552 100644
--- a/modules/control-center-web/src/main/js/routes/clusters.js
+++ b/modules/control-center-web/src/main/js/routes/clusters.js
@@ -24,6 +24,16 @@ router.get('/', function (req, res) {
     res.render('configuration/clusters');
 });
 
+function _processed(err, res) {
+    if (err) {
+        res.status(500).send(err.message);
+
+        return false;
+    }
+
+    return true;
+}
+
 /**
  * Get spaces and clusters accessed for user account.
  *
@@ -35,38 +45,38 @@ router.post('/list', function (req, res) {
 
     // Get owned space and all accessed space.
     db.Space.find({$or: [{owner: user_id}, {usedBy: {$elemMatch: {account: user_id}}}]},
function (err, spaces) {
-        if (err)
-            return res.status(500).send(err.message);
-
-        var space_ids = spaces.map(function (value) {
-            return value._id;
-        });
+        if (_processed(err, res)) {
+            var space_ids = spaces.map(function (value) {
+                return value._id;
+            });
 
-        db.Cache.find({space: {$in: space_ids}}, '_id name swapEnabled', function (err, caches)
{
-            if (err)
-                return res.status(500).send(err);
-
-            // Get all clusters for spaces.
-            db.Cluster.find({space: {$in: space_ids}}).sort('name').exec(function (err, clusters)
{
-                if (err)
-                    return res.status(500).send(err.message);
-
-                // Remove deleted caches.
-                _.forEach(clusters, function (cluster) {
-                    cluster.caches = _.filter(cluster.caches, function (cacheId) {
-                        return _.findIndex(caches, function (cache) {
-                            return cache._id.equals(cacheId);
-                        }) >= 0;
+            // Get all caches for spaces.
+            db.Cache.find({space: {$in: space_ids}}, '_id name swapEnabled', function (err,
caches) {
+                if (_processed(err, res)) {
+                    // Get all clusters for spaces.
+                    db.Cluster.find({space: {$in: space_ids}}).sort('name').exec(function
(err, clusters) {
+                        if (_processed(err, res)) {
+                            // Remove deleted caches.
+                            _.forEach(clusters, function (cluster) {
+                                cluster.caches = _.filter(cluster.caches, function (cacheId)
{
+                                    return _.findIndex(caches, function (cache) {
+                                            return cache._id.equals(cacheId);
+                                        }) >= 0;
+                                });
+                            });
+
+                            res.json({
+                                spaces: spaces,
+                                caches: caches.map(function (cache) {
+                                    return {value: cache._id, label: cache.name, swapEnabled:
cache.swapEnabled};
+                                }),
+                                clusters: clusters
+                            });
+                        }
                     });
-                });
-
-                var cachesJson = caches.map(function (cache) {
-                    return {value: cache._id, label: cache.name, swapEnabled: cache.swapEnabled};
-                });
-
-                res.json({spaces: spaces, caches: cachesJson, clusters: clusters});
+                }
             });
-        });
+        }
     });
 });
 
@@ -75,28 +85,38 @@ router.post('/list', function (req, res) {
  */
 router.post('/save', function (req, res) {
     var params = req.body;
+    var clusterId = params._id;
+    var caches = params.caches;
 
     if (params._id)
         db.Cluster.update({_id: params._id}, params, {upsert: true}, function (err) {
-            if (err)
-                return res.status(500).send(err.message);
-
-            res.send(params._id);
+            if (_processed(err, res))
+                db.Cache.update({_id: {$in: caches}}, {$addToSet: {clusters: clusterId}},
{upsert: true, multi: true}, function(err) {
+                    if (_processed(err, res)) {
+                        db.Cache.update({_id: {$nin: caches}}, {$pull: {clusters: clusterId}},
{upsert: true, multi: true}, function(err) {
+                            if (_processed(err, res))
+                                res.send(params._id);
+                        });
+                    }
+                });
         });
     else {
         db.Cluster.findOne({space: params.space, name: params.name}, function (err, cluster)
{
-            if (err)
-                return res.status(500).send(err.message);
-
-            if (cluster)
-                return res.status(500).send('Cluster with name: "' + cluster.name + '" already
exist.');
-
-            (new db.Cluster(params)).save(function (err, cluster) {
-                if (err)
-                    return res.status(500).send(err.message);
-
-                res.send(cluster._id);
-            });
+            if (_processed(err, res)) {
+                if (cluster)
+                    return res.status(500).send('Cluster with name: "' + cluster.name + '"
already exist.');
+
+                (new db.Cluster(params)).save(function (err, cluster) {
+                    if (_processed(err, res)) {
+                        clusterId = cluster._id;
+
+                        db.Cache.update({_id: {$in: caches}}, {$addToSet: {clusters: clusterId}},
{upsert: true, multi: true}, function (err) {
+                            if (_processed(err, res))
+                                res.send(clusterId);
+                        });
+                    }
+                });
+            }
         });
     }
 });


Mime
View raw message