You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by ak...@apache.org on 2016/02/16 16:14:34 UTC

[17/50] ignite git commit: IGNITE-843 Rework cluster remove.

IGNITE-843 Rework cluster remove.


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

Branch: refs/heads/ignite-843-rc3
Commit: d29110fb5113aa9a1aa55eccccc00c88880efba6
Parents: 053ba44
Author: AKuznetsov <ak...@gridgain.com>
Authored: Mon Feb 15 17:44:57 2016 +0700
Committer: AKuznetsov <ak...@gridgain.com>
Committed: Mon Feb 15 17:44:57 2016 +0700

----------------------------------------------------------------------
 .../src/main/js/serve/routes/clusters.js        | 26 ++++++++++++++------
 1 file changed, 18 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/d29110fb/modules/control-center-web/src/main/js/serve/routes/clusters.js
----------------------------------------------------------------------
diff --git a/modules/control-center-web/src/main/js/serve/routes/clusters.js b/modules/control-center-web/src/main/js/serve/routes/clusters.js
index 9410ffc..acfb2aa 100644
--- a/modules/control-center-web/src/main/js/serve/routes/clusters.js
+++ b/modules/control-center-web/src/main/js/serve/routes/clusters.js
@@ -137,14 +137,24 @@ module.exports.factory = function(_, express, mongo) {
          * Remove cluster by ._id.
          */
         router.post('/remove', (req, res) => {
-            mongo.Cluster.remove(req.body, (err) => {
-                if (err)
-                    return res.status(500).send(err.message);
-
-                // TODO add IGFS and caches cleanup
-
-                res.sendStatus(200);
-            });
+            const userId = req.currentUserId();
+            const clusterId = req.body;
+
+            let spacesIds = [];
+
+            mongo.Cluster.remove(clusterId)
+                .then(() => mongo.Space.find({$or: [{owner: userId}, {usedBy: {$elemMatch: {account: userId}}}]}))
+                .then((spaces) => {
+                    spacesIds = spaces.map((value) => value._id);
+
+                    return mongo.Cache.update(mongo.Cache.update({space: {$in: spacesIds}}, {$pull: {clusters: clusterId}}, {multi: true}));
+                })
+                .then(() => mongo.Cache.update(mongo.Igfs.update({space: {$in: spacesIds}}, {$pull: {clusters: clusterId}}, {multi: true})))
+                .then(() => res.sendStatus(200))
+                .catch((err) => {
+                    // TODO IGNITE-843 Send error to admin
+                    res.status(500).send(err.message);
+                });
         });
 
         /**