ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From anovi...@apache.org
Subject ignite git commit: IGNITE-843 Check name duplicate.
Date Tue, 16 Feb 2016 11:56:24 GMT
Repository: ignite
Updated Branches:
  refs/heads/ignite-843-rc2 a170c4e4a -> 09d6538d5


IGNITE-843 Check name duplicate.


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

Branch: refs/heads/ignite-843-rc2
Commit: 09d6538d5ecb82cae8aeb606e33261375d1d9290
Parents: a170c4e
Author: Vasiliy Sisko <vsisko@gridgain.com>
Authored: Tue Feb 16 18:56:48 2016 +0700
Committer: Andrey <anovikov@gridgain.com>
Committed: Tue Feb 16 18:56:48 2016 +0700

----------------------------------------------------------------------
 .../src/main/js/serve/routes/caches.js          | 52 +++++++++---------
 .../src/main/js/serve/routes/clusters.js        | 56 ++++++++++----------
 .../src/main/js/serve/routes/domains.js         | 54 ++++++++++---------
 .../src/main/js/serve/routes/igfs.js            | 46 ++++++++--------
 4 files changed, 107 insertions(+), 101 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/09d6538d/modules/control-center-web/src/main/js/serve/routes/caches.js
----------------------------------------------------------------------
diff --git a/modules/control-center-web/src/main/js/serve/routes/caches.js b/modules/control-center-web/src/main/js/serve/routes/caches.js
index aed7f10..17fef2d 100644
--- a/modules/control-center-web/src/main/js/serve/routes/caches.js
+++ b/modules/control-center-web/src/main/js/serve/routes/caches.js
@@ -73,32 +73,32 @@ module.exports.factory = function(_, express, mongo) {
             const domains = params.domains;
             let cacheId = params._id;
 
-            if (params._id) {
-                mongo.Cache.update({_id: cacheId}, params, {upsert: true}).exec()
-                    .then(() => mongo.Cluster.update({_id: {$in: clusters}}, {$addToSet:
{caches: cacheId}}, {multi: true}).exec())
-                    .then(() => mongo.Cluster.update({_id: {$nin: clusters}}, {$pull:
{caches: cacheId}}, {multi: true}).exec())
-                    .then(() => mongo.DomainModel.update({_id: {$in: domains}}, {$addToSet:
{caches: cacheId}}, {multi: true}).exec())
-                    .then(() => mongo.DomainModel.update({_id: {$nin: domains}}, {$pull:
{caches: cacheId}}, {multi: true}).exec())
-                    .then(() => res.send(cacheId))
-                    .catch((err) => mongo.handleError(res, err));
-            }
-            else {
-                mongo.Cache.findOne({space: params.space, name: params.name}).exec()
-                    .then((cache) => {
-                        if (cache)
-                            throw new Error('Cache with name: "' + cache.name + '" already
exist.');
-
-                        return (new mongo.Cache(params)).save();
-                    })
-                    .then((cache) => {
-                        cacheId = cache._id;
-
-                        return mongo.Cluster.update({_id: {$in: clusters}}, {$addToSet: {caches:
cacheId}}, {multi: true}).exec();
-                    })
-                    .then(() => mongo.DomainModel.update({_id: {$in: domains}}, {$addToSet:
{caches: cacheId}}, {multi: true}).exec())
-                    .then(() => res.send(cacheId))
-                    .catch((err) => mongo.handleError(res, err));
-            }
+            mongo.Cache.findOne({space: params.space, name: params.name}).exec()
+                .then((_cache) => {
+                    if (_cache && cacheId !== _cache._id.toString())
+                        return res.status(500).send('Cache with name: "' + _cache.name +
'" already exist.');
+
+                    if (cacheId) {
+                        return mongo.Cache.update({_id: cacheId}, params, {upsert: true}).exec()
+                            .then(() => mongo.Cluster.update({_id: {$in: clusters}}, {$addToSet:
{caches: cacheId}}, {multi: true}).exec())
+                            .then(() => mongo.Cluster.update({_id: {$nin: clusters}},
{$pull: {caches: cacheId}}, {multi: true}).exec())
+                            .then(() => mongo.DomainModel.update({_id: {$in: domains}},
{$addToSet: {caches: cacheId}}, {multi: true}).exec())
+                            .then(() => mongo.DomainModel.update({_id: {$nin: domains}},
{$pull: {caches: cacheId}}, {multi: true}).exec())
+                            .then(() => res.send(cacheId))
+                            .catch((err) => mongo.handleError(res, err));
+                    }
+                    else {
+                        return (new mongo.Cache(params)).save()
+                            .then((cache) => {
+                                cacheId = cache._id;
+
+                                return mongo.Cluster.update({_id: {$in: clusters}}, {$addToSet:
{caches: cacheId}}, {multi: true}).exec();
+                            })
+                            .then(() => mongo.DomainModel.update({_id: {$in: domains}},
{$addToSet: {caches: cacheId}}, {multi: true}).exec())
+                            .then(() => res.send(cacheId))
+                            .catch((err) => mongo.handleError(res, err));
+                    }
+                });
         });
 
         /**

http://git-wip-us.apache.org/repos/asf/ignite/blob/09d6538d/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 b6af923..6bbf4c0 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
@@ -83,34 +83,34 @@ module.exports.factory = function(_, express, mongo) {
             const igfss = params.igfss;
             let clusterId = params._id;
 
-            if (params._id) {
-                mongo.Cluster.update({_id: params._id}, params, {upsert: true}).exec()
-                    .then(() => mongo.Cache.update({_id: {$in: caches}}, {$addToSet: {clusters:
clusterId}}, {multi: true}).exec())
-                    .then(() => mongo.Cache.update({_id: {$nin: caches}}, {$pull: {clusters:
clusterId}}, {multi: true}).exec())
-                    .then(() => mongo.Igfs.update({_id: {$in: igfss}}, {$addToSet: {clusters:
clusterId}}, {multi: true}).exec())
-                    .then(() => mongo.Igfs.update({_id: {$nin: igfss}}, {$pull: {clusters:
clusterId}}, {multi: true}).exec())
-                    .then(() => res.send(clusterId))
-                    .catch((err) => mongo.handleError(res, err));
-            }
-            else {
-                mongo.Cluster.findOne({space: params.space, name: params.name}).exec()
-                    .then((cluster) => {
-                        if (cluster)
-                            return res.status(500).send('Cluster with name: "' + cluster.name
+ '" already exist.');
-
-                        return (new mongo.Cluster(params)).save();
-                    })
-                    .then((cluster) => {
-                        clusterId = cluster._id;
-
-                        return mongo.Cache.update({_id: {$in: caches}}, {$addToSet: {clusters:
clusterId}}, {multi: true}).exec();
-                    })
-                    .then(() => mongo.Cache.update({_id: {$nin: caches}}, {$pull: {clusters:
clusterId}}, {multi: true}).exec())
-                    .then(() => mongo.Igfs.update({_id: {$in: igfss}}, {$addToSet: {clusters:
clusterId}}, {multi: true}).exec())
-                    .then(() => mongo.Igfs.update({_id: {$nin: igfss}}, {$pull: {clusters:
clusterId}}, {multi: true}).exec())
-                    .then(() => res.send(clusterId))
-                    .catch((err) => mongo.handleError(res, err));
-            }
+            mongo.Cluster.findOne({space: params.space, name: params.name}).exec()
+                .then((_cluster) => {
+                    if (_cluster && clusterId !== _cluster._id.toString())
+                        return res.status(500).send('Cluster with name: "' + _cluster.name
+ '" already exist.');
+
+                    if (clusterId) {
+                        return mongo.Cluster.update({_id: clusterId}, params, {upsert: true}).exec()
+                            .then(() => mongo.Cache.update({_id: {$in: caches}}, {$addToSet:
{clusters: clusterId}}, {multi: true}).exec())
+                            .then(() => mongo.Cache.update({_id: {$nin: caches}}, {$pull:
{clusters: clusterId}}, {multi: true}).exec())
+                            .then(() => mongo.Igfs.update({_id: {$in: igfss}}, {$addToSet:
{clusters: clusterId}}, {multi: true}).exec())
+                            .then(() => mongo.Igfs.update({_id: {$nin: igfss}}, {$pull:
{clusters: clusterId}}, {multi: true}).exec())
+                            .then(() => res.send(clusterId))
+                            .catch((err) => mongo.handleError(res, err));
+                    }
+                    else {
+                        return (new mongo.Cluster(params)).save()
+                            .then((cluster) => {
+                                clusterId = cluster._id;
+
+                                return mongo.Cache.update({_id: {$in: caches}}, {$addToSet:
{clusters: clusterId}}, {multi: true}).exec();
+                            })
+                            .then(() => mongo.Cache.update({_id: {$nin: caches}}, {$pull:
{clusters: clusterId}}, {multi: true}).exec())
+                            .then(() => mongo.Igfs.update({_id: {$in: igfss}}, {$addToSet:
{clusters: clusterId}}, {multi: true}).exec())
+                            .then(() => mongo.Igfs.update({_id: {$nin: igfss}}, {$pull:
{clusters: clusterId}}, {multi: true}).exec())
+                            .then(() => res.send(clusterId))
+                            .catch((err) => mongo.handleError(res, err));
+                    }
+                });
         });
 
         /**

http://git-wip-us.apache.org/repos/asf/ignite/blob/09d6538d/modules/control-center-web/src/main/js/serve/routes/domains.js
----------------------------------------------------------------------
diff --git a/modules/control-center-web/src/main/js/serve/routes/domains.js b/modules/control-center-web/src/main/js/serve/routes/domains.js
index 5d4acac..6fe64b3 100644
--- a/modules/control-center-web/src/main/js/serve/routes/domains.js
+++ b/modules/control-center-web/src/main/js/serve/routes/domains.js
@@ -78,30 +78,31 @@ module.exports.factory = (_, express, mongo) => {
             const cacheStoreChanges = domain.cacheStoreChanges;
             const domainId = domain._id;
 
-            if (domainId) {
-                return mongo.DomainModel.update({_id: domain._id}, domain, {upsert: true}).exec()
-                    .then(() => mongo.Cache.update({_id: {$in: caches}}, {$addToSet: {domains:
domainId}}, {multi: true}).exec())
-                    .then(() => mongo.Cache.update({_id: {$nin: caches}}, {$pull: {domains:
domainId}}, {multi: true}).exec())
-                    .then(() => {
-                        savedDomains.push(domain);
-
-                        return _updateCacheStore(cacheStoreChanges);
-                    });
-            }
-
             return mongo.DomainModel.findOne({space: domain.space, valueType: domain.valueType}).exec()
-                .then((found) => {
-                    if (found)
-                        throw new Error('Domain model with value type: "' + found.valueType
+ '" already exist.');
-
-                    return (new mongo.DomainModel(domain)).save();
-                })
-                .then((savedDomain) => {
-                    savedDomains.push(savedDomain);
-
-                    return mongo.Cache.update({_id: {$in: caches}}, {$addToSet: {domains:
savedDomain._id}}, {multi: true}).exec();
-                })
-                .then(() => _updateCacheStore(cacheStoreChanges));
+                .then((_domain) => {
+                    if (_domain && domainId !== _domain._id.toString())
+                        throw new Error('Domain model with value type: "' + _domain.valueType
+ '" already exist.');
+
+                    if (domainId) {
+                        return mongo.DomainModel.update({_id: domain._id}, domain, {upsert:
true}).exec()
+                            .then(() => mongo.Cache.update({_id: {$in: caches}}, {$addToSet:
{domains: domainId}}, {multi: true}).exec())
+                            .then(() => mongo.Cache.update({_id: {$nin: caches}}, {$pull:
{domains: domainId}}, {multi: true}).exec())
+                            .then(() => {
+                                savedDomains.push(domain);
+
+                                return _updateCacheStore(cacheStoreChanges);
+                            });
+                    }
+                    else {
+                        return (new mongo.DomainModel(domain)).save()
+                            .then((savedDomain) => {
+                                savedDomains.push(savedDomain);
+
+                                return mongo.Cache.update({_id: {$in: caches}}, {$addToSet:
{domains: savedDomain._id}}, {multi: true}).exec();
+                            })
+                            .then(() => _updateCacheStore(cacheStoreChanges));
+                    }
+                });
         };
 
         const _save = (domains, res) => {
@@ -123,7 +124,12 @@ module.exports.factory = (_, express, mongo) => {
                                     newCache.space = domain.space;
 
                                     return (new mongo.Cache(newCache)).save()
-                                        .then((_cache) => mongo.Cluster.update({_id: {$in:
_cache.clusters}}, {$addToSet: {caches: _cache._id}}, {multi: true}).exec());
+                                        .then((_cache) => {
+                                            generatedCaches.push(_cache);
+
+                                            return mongo.Cluster.update({_id: {$in: _cache.clusters}},
{$addToSet: {caches: _cache._id}}, {multi: true}).exec()
+                                                .then(() => Promise.resolve(_cache));
+                                        });
                                 })
                                 .then((cache) => {
                                     domain.caches = [cache._id];

http://git-wip-us.apache.org/repos/asf/ignite/blob/09d6538d/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 0291728..baadfe6 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
@@ -67,29 +67,29 @@ module.exports.factory = function(_, express, mongo) {
             const clusters = params.clusters;
             let igfsId = params._id;
 
-            if (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) => mongo.handleError(res, err));
-            }
-            else {
-                mongo.Igfs.findOne({space: params.space, name: params.name}).exec()
-                    .then((igfs) => {
-                        if (igfs)
-                            throw new Error('IGFS with name: "' + params.name + '" 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}).exec();
-                    })
-                    .then(() => res.send(igfsId))
-                    .catch((err) => mongo.handleError(res, err));
-            }
+            mongo.Igfs.findOne({space: params.space, name: params.name}).exec()
+                .then((_igfs) => {
+                    if (_igfs && igfsId !== _igfs._id.toString())
+                        return res.status(500).send('IGFS with name: "' + params.name + '"
already exist.');
+
+                    if (params._id) {
+                        return 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) => mongo.handleError(res, err));
+                    }
+                    else {
+                        return (new mongo.Igfs(params)).save()
+                            .then((igfs) => {
+                                igfsId = igfs._id;
+
+                                return mongo.Cluster.update({_id: {$in: clusters}}, {$addToSet:
{igfss: igfsId}}, {multi: true}).exec();
+                            })
+                            .then(() => res.send(igfsId))
+                            .catch((err) => mongo.handleError(res, err));
+                    }
+                })
         });
 
         /**


Mime
View raw message