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/04 10:22:17 UTC
[23/24] 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/31a0c794
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/31a0c794
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/31a0c794
Branch: refs/heads/ARIA-48-aria-cli
Commit: 31a0c794f1991342b75f018c0d071efdd128376e
Parents: 6016e14
Author: Avia Efrat <av...@gigaspaces.com>
Authored: Tue Apr 4 12:18:01 2017 +0300
Committer: Ran Ziv <ra...@gigaspaces.com>
Committed: Tue Apr 4 13:20:46 2017 +0300
----------------------------------------------------------------------
aria/core.py | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/31a0c794/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):