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/04 09:18:56 UTC

incubator-ariatosca git commit: Fix handling creating a service with an existing name

Repository: incubator-ariatosca
Updated Branches:
  refs/heads/ARIA-48-aria-cli b3d2e0541 -> 600a9b26c


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/600a9b26
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/600a9b26
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/600a9b26

Branch: refs/heads/ARIA-48-aria-cli
Commit: 600a9b26c1deb019e24b06210d6cceecbd0dfa36
Parents: b3d2e05
Author: Avia Efrat <av...@gigaspaces.com>
Authored: Tue Apr 4 12:18:01 2017 +0300
Committer: Avia Efrat <av...@gigaspaces.com>
Committed: Tue Apr 4 12:18:01 2017 +0300

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


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/600a9b26/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):