You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ariatosca.apache.org by av...@apache.org on 2017/04/02 13:38:48 UTC

[2/2] incubator-ariatosca git commit: Enforce Uniqueness on ServiceTemplate and Service names

Enforce Uniqueness on ServiceTemplate and Service names


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

Branch: refs/heads/ARIA-48-aria-cli
Commit: 36981a7e3e9f4d7d29ca09a471079c77708e7233
Parents: e1b174f
Author: Avia Efrat <av...@gigaspaces.com>
Authored: Sun Apr 2 16:37:51 2017 +0300
Committer: Avia Efrat <av...@gigaspaces.com>
Committed: Sun Apr 2 16:37:51 2017 +0300

----------------------------------------------------------------------
 aria/cli/commands/service_templates.py | 19 ++++++++++++++-----
 aria/cli/commands/services.py          |  7 +++++++
 aria/cli/constants.py                  |  4 ++++
 aria/modeling/models.py                |  8 ++++++--
 4 files changed, 31 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/36981a7e/aria/cli/commands/service_templates.py
----------------------------------------------------------------------
diff --git a/aria/cli/commands/service_templates.py b/aria/cli/commands/service_templates.py
index b855529..823a6e8 100644
--- a/aria/cli/commands/service_templates.py
+++ b/aria/cli/commands/service_templates.py
@@ -19,12 +19,14 @@ import json
 
 from .. import utils
 from .. import csar
-from ..cli import aria
 from .. import service_template_utils
+from ..cli import aria
+from ..constants import TWO_MODELS_WITH_THE_SAME_NAME_ERROR_TEMPLATE
 from ..table import print_data
 from ..exceptions import AriaCliError
 from ...core import Core
 from ...exceptions import AriaException
+from ...storage.exceptions import StorageError
 
 
 DESCRIPTION_LIMIT = 20
@@ -112,11 +114,18 @@ def store(service_template_path, service_template_name, model_storage, resource_
 
     service_template_path = service_template_utils.get(service_template_path)
     core = Core(model_storage, resource_storage, plugin_manager)
-    core.create_service_template(service_template_path,
-                                 os.path.dirname(service_template_path),
-                                 service_template_name)
+    try:
+        core.create_service_template(service_template_path,
+                                     os.path.dirname(service_template_path),
+                                     service_template_name)
+    except StorageError:
+        logger.info(TWO_MODELS_WITH_THE_SAME_NAME_ERROR_TEMPLATE.format(
+            model_class='service template',
+            name=service_template_name))
+        raise
 
-    logger.info('Service template stored')
+    else:
+        logger.info('Service template stored')
 
 
 @service_templates.command(name='delete',

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/36981a7e/aria/cli/commands/services.py
----------------------------------------------------------------------
diff --git a/aria/cli/commands/services.py b/aria/cli/commands/services.py
index ce1139b..ae04d7e 100644
--- a/aria/cli/commands/services.py
+++ b/aria/cli/commands/services.py
@@ -19,11 +19,13 @@ from StringIO import StringIO
 
 from . import service_templates
 from ..cli import aria, helptexts
+from ..constants import TWO_MODELS_WITH_THE_SAME_NAME_ERROR_TEMPLATE
 from ..exceptions import AriaCliError
 from ..table import print_data
 from ..utils import storage_sort_param
 from ...core import Core
 from ...exceptions import AriaException
+from ...storage.exceptions import StorageError
 
 
 SERVICE_COLUMNS = ['id', 'name', 'service_template_name', 'created_at', 'updated_at']
@@ -97,6 +99,11 @@ def create(service_template_name,
     try:
         core = Core(model_storage, resource_storage, plugin_manager)
         service = core.create_service(service_template_name, inputs, service_name)
+    except StorageError:
+        logger.info(TWO_MODELS_WITH_THE_SAME_NAME_ERROR_TEMPLATE.format(
+            model_class='service',
+            name=service_name))
+        raise
     except AriaException as e:
         logger.info(str(e))
         service_templates.print_service_template_inputs(model_storage, service_template_name)

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/36981a7e/aria/cli/constants.py
----------------------------------------------------------------------
diff --git a/aria/cli/constants.py b/aria/cli/constants.py
index 67c094d..fdd37fc 100644
--- a/aria/cli/constants.py
+++ b/aria/cli/constants.py
@@ -16,3 +16,7 @@
 
 SAMPLE_SERVICE_TEMPLATE_FILENAME = 'service_template.yaml'
 HELP_TEXT_COLUMN_BUFFER = 5
+TWO_MODELS_WITH_THE_SAME_NAME_ERROR_TEMPLATE = """
+Could not store {model_class} `{name}`
+There already a exists a {model_class} with the same name
+"""

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/36981a7e/aria/modeling/models.py
----------------------------------------------------------------------
diff --git a/aria/modeling/models.py b/aria/modeling/models.py
index a01783b..db9db07 100644
--- a/aria/modeling/models.py
+++ b/aria/modeling/models.py
@@ -26,6 +26,10 @@ from . import (
     mixins,
 )
 
+from sqlalchemy import (
+    Column,
+    Text
+)
 
 aria_declarative_base = declarative_base(cls=mixins.ModelIDMixin)
 
@@ -84,7 +88,7 @@ __all__ = (
 # region service template models
 
 class ServiceTemplate(aria_declarative_base, service_template.ServiceTemplateBase):
-    pass
+    name = Column(Text, index=True, unique=True)
 
 
 class NodeTemplate(aria_declarative_base, service_template.NodeTemplateBase):
@@ -137,7 +141,7 @@ class ArtifactTemplate(aria_declarative_base, service_template.ArtifactTemplateB
 # region service instance models
 
 class Service(aria_declarative_base, service_instance.ServiceBase):
-    pass
+    name = Column(Text, index=True, unique=True)
 
 
 class Node(aria_declarative_base, service_instance.NodeBase):