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:29 UTC
[12/50] ignite git commit: IGNITE-843 Rework IGFS server side to
Promises.
IGNITE-843 Rework IGFS server side to Promises.
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/e2f7d427
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/e2f7d427
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/e2f7d427
Branch: refs/heads/ignite-843-rc3
Commit: e2f7d427e228989a53d86cacd858e76a591cb594
Parents: bfd0dd9
Author: Alexey Kuznetsov <ak...@apache.org>
Authored: Mon Feb 15 16:25:32 2016 +0700
Committer: Alexey Kuznetsov <ak...@apache.org>
Committed: Mon Feb 15 16:25:32 2016 +0700
----------------------------------------------------------------------
.../src/main/js/serve/routes/clusters.js | 2 +
.../src/main/js/serve/routes/igfs.js | 93 +++++++++-----------
.../src/main/js/serve/routes/profile.js | 12 +--
3 files changed, 49 insertions(+), 58 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/e2f7d427/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 98db693..9410ffc 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
@@ -141,6 +141,8 @@ module.exports.factory = function(_, express, mongo) {
if (err)
return res.status(500).send(err.message);
+ // TODO add IGFS and caches cleanup
+
res.sendStatus(200);
});
});
http://git-wip-us.apache.org/repos/asf/ignite/blob/e2f7d427/modules/control-center-web/src/main/js/serve/routes/igfs.js
----------------------------------------------------------------------
diff --git a/modules/control-center-web/src/main/js/serve/routes/igfs.js b/modules/control-center-web/src/main/js/serve/routes/igfs.js
index b10e5ac..630a75d 100644
--- a/modules/control-center-web/src/main/js/serve/routes/igfs.js
+++ b/modules/control-center-web/src/main/js/serve/routes/igfs.js
@@ -45,19 +45,12 @@ module.exports.factory = function(_, express, mongo) {
return mongo.Cluster.find({space: {$in: result.spacesIds}}, '_id name').sort('name').exec();
})
- .then(clusters => {
+ .then((clusters) => {
result.clusters = clusters;
return mongo.Igfs.find({space: {$in: result.spacesIds}}).sort('name').exec();
})
.then((igfss) => {
- _.forEach(igfss, (igfs) => {
- // Remove deleted clusters.
- igfs.clusters = _.filter(igfs.clusters, (clusterId) => {
- return _.findIndex(result.clusters, (cluster) => cluster._id.equals(clusterId)) >= 0;
- });
- });
-
res.json({
spaces: result.spaces,
clusters: result.clusters.map((cluster) => ({value: cluster._id, label: cluster.name})),
@@ -76,40 +69,37 @@ module.exports.factory = function(_, express, mongo) {
router.post('/save', (req, res) => {
const params = req.body;
const clusters = params.clusters;
+
let igfsId = params._id;
if (params._id) {
- mongo.Igfs.update({_id: igfsId}, params, {upsert: true}, (errIgfs) => {
- if (mongo.processed(errIgfs, res)) {
- mongo.Cluster.update({_id: {$in: clusters}}, {$addToSet: {igfss: igfsId}}, {multi: true}, (errClusterAdd) => {
- if (mongo.processed(errClusterAdd, res)) {
- mongo.Cluster.update({_id: {$nin: clusters}}, {$pull: {igfss: igfsId}}, {multi: true}, (errClusterPull) => {
- if (mongo.processed(errClusterPull, res))
- res.send(params._id);
- });
- }
- });
- }
- });
+ mongo.Igfs.update({_id: igfsId}, params, {upsert: true}).exec()
+ .then(() => mongo.Cluster.update({_id: {$in: clusters}}, {$addToSet: {igfss: igfsId}}, {multi: true}).exec())
+ .then(() => mongo.Cluster.update({_id: {$nin: clusters}}, {$pull: {igfss: igfsId}}, {multi: true}).exec())
+ .then(() => res.send(igfsId))
+ .catch((err) => {
+ // TODO IGNITE-843 Send error to admin
+ res.status(500).send(err.message);
+ });
}
else {
- mongo.Igfs.findOne({space: params.space, name: params.name}, (errIgfsFind, igfsFound) => {
- if (mongo.processed(errIgfsFind, res)) {
- if (igfsFound)
- return res.status(500).send('IGFS with name: "' + igfsFound.name + '" already exist.');
-
- (new mongo.Igfs(params)).save((errIgfsSave, igfs) => {
- if (mongo.processed(errIgfsSave, res)) {
- igfsId = igfs._id;
-
- mongo.Cluster.update({_id: {$in: clusters}}, {$addToSet: {igfss: igfsId}}, {multi: true}, (errCluster) => {
- if (mongo.processed(errCluster, res))
- res.send(igfsId);
- });
- }
- });
- }
- });
+ mongo.Igfs.findOne({space: params.space, name: params.name}).exec()
+ .then((_igfs) => {
+ if (_igfs)
+ throw new Error('IGFS with name: "' + _igfs + '" already exist.');
+
+ return (new mongo.Igfs(params)).save();
+ })
+ .then((igfs) => {
+ igfsId = igfs._id;
+
+ return mongo.Cluster.update({_id: {$in: clusters}}, {$addToSet: {igfss: igfsId}}, {multi: true});
+ })
+ .then(() => res.send(igfsId))
+ .catch((err) => {
+ // TODO IGNITE-843 Send error to admin
+ res.status(500).send(err.message);
+ });
}
});
@@ -127,23 +117,22 @@ module.exports.factory = function(_, express, mongo) {
* Remove all IGFSs.
*/
router.post('/remove/all', (req, res) => {
- const user_id = req.currentUserId();
+ const userId = req.currentUserId();
+ let spacesIds = [];
// Get owned space and all accessed space.
- mongo.Space.find({$or: [{owner: user_id}, {usedBy: {$elemMatch: {account: user_id}}}]}, (errSpace, spaces) => {
- if (mongo.processed(errSpace, res)) {
- const space_ids = spaces.map((value) => value._id);
-
- mongo.Igfs.remove({space: {$in: space_ids}}, (errIgfs) => {
- if (mongo.processed(errIgfs, res)) {
- mongo.Cluster.update({space: {$in: space_ids}}, {igfss: []}, {multi: true}, (errCluster) => {
- if (mongo.processed(errCluster, res))
- res.sendStatus(200);
- });
- }
- });
- }
- });
+ mongo.Space.find({$or: [{owner: userId}, {usedBy: {$elemMatch: {account: userId}}}]})
+ .then((spaces) => {
+ spacesIds = spaces.map((value) => value._id);
+
+ return mongo.Igfs.remove({space: {$in: spacesIds}});
+ })
+ .then(() => mongo.Cluster.update({space: {$in: spacesIds}}, {igfss: []}, {multi: true}))
+ .then(() => res.sendStatus(200))
+ .catch((err) => {
+ // TODO IGNITE-843 Send error to admin
+ res.status(500).send(err.message);
+ });
});
resolve(router);
http://git-wip-us.apache.org/repos/asf/ignite/blob/e2f7d427/modules/control-center-web/src/main/js/serve/routes/profile.js
----------------------------------------------------------------------
diff --git a/modules/control-center-web/src/main/js/serve/routes/profile.js b/modules/control-center-web/src/main/js/serve/routes/profile.js
index bf227a2..079b360 100644
--- a/modules/control-center-web/src/main/js/serve/routes/profile.js
+++ b/modules/control-center-web/src/main/js/serve/routes/profile.js
@@ -45,7 +45,7 @@ module.exports.factory = function(_, express, mongo) {
return new Promise((resolve, reject) => {
user.setPassword(params.password, (err, _user) => {
if (err)
- return reject(err.message);
+ return reject(err);
delete params.password;
@@ -57,14 +57,14 @@ module.exports.factory = function(_, express, mongo) {
if (!params.email || user.email === params.email)
return Promise.resolve(user);
- return new Promise((resolve, reject) => {
+ return new Promise((resolve) => {
mongo.Account.findOne({email: params.email}, (err, _user) => {
// TODO send error to admin
if (err)
- return reject('Failed to check e-mail!');
+ throw new Error('Failed to check e-mail!');
if (_user && _user._id !== user._id)
- return reject('User with this e-mail already registered!');
+ throw new Error('User with this e-mail already registered!');
resolve(user);
});
@@ -79,9 +79,9 @@ module.exports.factory = function(_, express, mongo) {
return user.save();
})
.then(() => res.sendStatus(200))
- .catch((errMsg) => {
+ .catch((err) => {
// TODO IGNITE-843 Send error to admin
- res.status(500).send(errMsg);
+ res.status(500).send(err.message);
});
});