You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ariatosca.apache.org by ra...@apache.org on 2017/04/06 08:29:53 UTC

[27/32] incubator-ariatosca git commit: Fix handling creating a service with an existing name

Fix handling creating a service with an existing name


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

Branch: refs/heads/ARIA-48-aria-cli
Commit: b732ab76586f0ed025f9e7f6b4e6419cf3cf4dd0
Parents: 0b06960
Author: Avia Efrat <av...@gigaspaces.com>
Authored: Tue Apr 4 12:18:01 2017 +0300
Committer: Ran Ziv <ra...@gigaspaces.com>
Committed: Thu Apr 6 11:29:17 2017 +0300

----------------------------------------------------------------------
 aria/core.py | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/b732ab76/aria/core.py
----------------------------------------------------------------------
diff --git a/aria/core.py b/aria/core.py
index 1fd3cf7..057f716 100644
--- a/aria/core.py
+++ b/aria/core.py
@@ -21,6 +21,7 @@ from .parser.consumption import (
     Validate,
     ServiceTemplate)
 from .parser.loading.location import UriLocation
+from .storage import exceptions as storage_exceptions
 
 
 class Core(object):
@@ -67,6 +68,7 @@ class Core(object):
         self.resource_storage.service_template.delete(entry_id=str(service_template.id))
 
     def create_service(self, service_template_id, inputs, service_name=None):
+
         service_template = self.model_storage.service_template.get(service_template_id)
 
         # creating an empty ConsumptionContext, initiating a threadlocal context
@@ -74,8 +76,17 @@ class Core(object):
         with self.model_storage._all_api_kwargs['session'].no_autoflush:
             service = service_template.instantiate(None, inputs)
 
-        service.name = service_name or '{0}_{1}'.format(service_template.name, service.id)
+        # If the user didn't enter a name for this service, we'll want to auto generate it.
+        # But how will we ensure a unique but simple name? We'll append the services' unique id
+        # to the service_templates name. Since this service is not in the storage yet, we'll put it
+        # there, and pull out its id.
         self.model_storage.service.put(service)
+        service.name = service_name or '{0}_{1}'.format(service_template.name, service.id)
+        try:
+            self.model_storage.service.update(service)
+        except storage_exceptions.StorageError:
+            self.model_storage.service.delete(service)
+            raise
         return service
 
     def delete_service(self, service_id, force=False):