Github user ran-z commented on a diff in the pull request: https://github.com/apache/incubator-ariatosca/pull/97#discussion_r111371385 --- Diff: aria/core.py --- @@ -0,0 +1,117 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from . import exceptions +from .parser.consumption import ( + ConsumptionContext, + ConsumerChain, + Read, + Validate, + ServiceTemplate) +from .parser.loading.location import UriLocation +from .storage import exceptions as storage_exceptions + + +class Core(object): + + def __init__(self, + model_storage, + resource_storage, + plugin_manager): + self._model_storage = model_storage + self._resource_storage = resource_storage + self._plugin_manager = plugin_manager + + @property + def model_storage(self): + return self._model_storage + + @property + def resource_storage(self): + return self._resource_storage + + @property + def plugin_manager(self): + return self._plugin_manager + + def validate_service_template(self, service_template_path): + self._parse_service_template(service_template_path) + + def create_service_template(self, service_template_path, service_template_dir, + service_template_name): + context = self._parse_service_template(service_template_path) + service_template = context.modeling.template + service_template.name = service_template_name + self.model_storage.service_template.put(service_template) + self.resource_storage.service_template.upload( + entry_id=str(service_template.id), source=service_template_dir) + + def delete_service_template(self, service_template_id): + service_template = self.model_storage.service_template.get(service_template_id) + if service_template.services: + raise exceptions.DependentServicesError( + "Can't delete service template {0} - Service template has existing services") + + self.model_storage.service_template.delete(service_template) + 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 + ConsumptionContext() + with self.model_storage._all_api_kwargs['session'].no_autoflush: + service = service_template.instantiate(None, inputs) + + # 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) --- End diff -- use flush + put instead of put + update
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---