Repository: incubator-ariatosca Updated Branches: refs/heads/ARIA-174-Refactor-instantiation-phase 4bdf57c7b -> fcc6b9c6e
removed singleton, added ability to extend the issue list, and fixed issue relating the cpability/requirement instantiation Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/fcc6b9c6 Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/fcc6b9c6 Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/fcc6b9c6 Branch: refs/heads/ARIA-174-Refactor-instantiation-phase Commit: fcc6b9c6e42b083dff90cf36f521eabfd5272abe Parents: 4bdf57c Author: max-orlov <[email protected]> Authored: Thu Jul 27 14:28:49 2017 +0300 Committer: max-orlov <[email protected]> Committed: Thu Jul 27 14:28:49 2017 +0300 ---------------------------------------------------------------------- aria/cli/commands/service_templates.py | 4 ++-- aria/cli/commands/services.py | 4 ++-- aria/core.py | 7 +++---- aria/orchestrator/topology/__init__.py | 3 --- aria/orchestrator/topology/instance.py | 12 ++++++++++-- aria/orchestrator/topology/template.py | 14 ++++---------- aria/parser/consumption/consumer.py | 6 +++++- aria/parser/consumption/modeling.py | 2 +- aria/parser/validation/issue.py | 4 ++++ tests/instantiation/test_configuration.py | 15 ++++++++------- 10 files changed, 39 insertions(+), 32 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/fcc6b9c6/aria/cli/commands/service_templates.py ---------------------------------------------------------------------- diff --git a/aria/cli/commands/service_templates.py b/aria/cli/commands/service_templates.py index d1a9479..6eef97a 100644 --- a/aria/cli/commands/service_templates.py +++ b/aria/cli/commands/service_templates.py @@ -73,9 +73,9 @@ def show(service_template_name, model_storage, mode_full, mode_types, format_jso elif format_yaml: console.puts(formatting.yaml_dumps(collections.prune(service_template.as_raw))) else: - logger.info(topology.handler.dump(service_template)) + logger.info(topology.Handler().dump(service_template)) elif mode_types: - logger.info(topology.handler.dump_types(service_template=service_template)) + logger.info(topology.Handler().dump_types(service_template=service_template)) else: logger.info('Showing service template {0}...'.format(service_template_name)) service_template_dict = service_template.to_dict() http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/fcc6b9c6/aria/cli/commands/services.py ---------------------------------------------------------------------- diff --git a/aria/cli/commands/services.py b/aria/cli/commands/services.py index 43faf37..93bea7f 100644 --- a/aria/cli/commands/services.py +++ b/aria/cli/commands/services.py @@ -74,9 +74,9 @@ def show(service_name, model_storage, mode_full, mode_graph, format_json, format elif format_yaml: console.puts(formatting.yaml_dumps(collections.prune(service.as_raw))) else: - logger.info(topology.handler.dump(service)) + logger.info(topology.Handler().dump(service)) elif mode_graph: - logger.info(topology.handler.dump_graph(service)) + logger.info(topology.Handler().dump_graph(service)) else: logger.info('Showing service {0}...'.format(service_name)) service_dict = service.to_dict() http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/fcc6b9c6/aria/core.py ---------------------------------------------------------------------- diff --git a/aria/core.py b/aria/core.py index 0870bac..444bcb9 100644 --- a/aria/core.py +++ b/aria/core.py @@ -87,10 +87,9 @@ class Core(object): handler.configure_operations(service) handler.coerce(service) - # TODO: fix this - # if context.validation.dump_issues(): - # raise exceptions.InstantiationError('Failed to instantiate service template `{0}`' - # .format(service_template.name)) + if handler.dump_issues(): + raise exceptions.InstantiationError('Failed to instantiate service template `{0}`' + .format(service_template.name)) storage_session.flush() # flushing so service.id would auto-populate service.name = service_name or '{0}_{1}'.format(service_template.name, service.id) http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/fcc6b9c6/aria/orchestrator/topology/__init__.py ---------------------------------------------------------------------- diff --git a/aria/orchestrator/topology/__init__.py b/aria/orchestrator/topology/__init__.py index afb7d22..1ba12aa 100644 --- a/aria/orchestrator/topology/__init__.py +++ b/aria/orchestrator/topology/__init__.py @@ -228,6 +228,3 @@ class Handler(issue.Reporter): elif model is not None: _handler = self._handlers.get(model.__class__) return _handler(self, model).configure_operations(**kwargs) - - -handler = Handler() http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/fcc6b9c6/aria/orchestrator/topology/instance.py ---------------------------------------------------------------------- diff --git a/aria/orchestrator/topology/instance.py b/aria/orchestrator/topology/instance.py index 9dea932..dc204fe 100644 --- a/aria/orchestrator/topology/instance.py +++ b/aria/orchestrator/topology/instance.py @@ -176,6 +176,15 @@ class Node(common._OperatorHolderHandlerMixin): def satisfy_requirements(self): satisfied = True for requirement_template in self._model.node_template.requirement_templates: + + # Since we try and satisfy requirements, which are node template bound, and use that + # information in the creation of the relationship, Some requirements may have been + # satisfied by a previous run on that node template. + # The entire mechanism of satisfying requirements needs to be refactored. + if any(r.requirement_template == requirement_template + for r in self._model.outbound_relationships): + return satisfied + # Find target template target_node_template, target_node_capability = self._find_target(requirement_template) if target_node_template is not None: @@ -210,8 +219,7 @@ class Node(common._OperatorHolderHandlerMixin): if target_node is not None: if requirement_template.relationship_template is not None: - from aria.orchestrator import topology - relationship_model = topology.handler.instantiate( + relationship_model = self._topology.instantiate( requirement_template.relationship_template) else: relationship_model = models.Relationship() http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/fcc6b9c6/aria/orchestrator/topology/template.py ---------------------------------------------------------------------- diff --git a/aria/orchestrator/topology/template.py b/aria/orchestrator/topology/template.py index 29a2397..51be788 100644 --- a/aria/orchestrator/topology/template.py +++ b/aria/orchestrator/topology/template.py @@ -73,9 +73,7 @@ class ServiceTemplate(common._TemplateHandlerMixin): service.groups = self._topology.instantiate(self._model.group_templates) service.policies = self._topology.instantiate(self._model.policy_templates) service.workflows = self._topology.instantiate(self._model.workflow_templates) - - if self._model.substitution_template is not None: - service.substitution = self._topology.instantiate(self._model.substitution_template) + service.substitution = self._topology.instantiate(self._model.substitution_template) service.outputs = self._topology.instantiate(self._model.outputs) return service @@ -95,10 +93,6 @@ class ServiceTemplate(common._TemplateHandlerMixin): extract_property(properties, 'max_instances') extract_property(properties, 'default_instances') - def default_property(name, value): - if name not in scaling: - scaling[name] = value - # From our scaling capabilities for capability_template in node_template.capability_templates.itervalues(): if capability_template.type.role == 'scaling': @@ -111,9 +105,9 @@ class ServiceTemplate(common._TemplateHandlerMixin): extract_properties(policy_template.properties) # Defaults - default_property('min_instances', 0) - default_property('max_instances', 1) - default_property('default_instances', 1) + scaling.setdefault('min_instances', 0) + scaling.setdefault('max_instances', 1) + scaling.setdefault('default_instances', 1) # Validate # pylint: disable=too-many-boolean-expressions http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/fcc6b9c6/aria/parser/consumption/consumer.py ---------------------------------------------------------------------- diff --git a/aria/parser/consumption/consumer.py b/aria/parser/consumption/consumer.py index 8acbf31..ea63643 100644 --- a/aria/parser/consumption/consumer.py +++ b/aria/parser/consumption/consumer.py @@ -29,7 +29,7 @@ class Consumer(object): def __init__(self, context): from aria.orchestrator import topology - self.handler = topology.handler + self.handler = topology.Handler() self.context = context def consume(self): @@ -76,6 +76,10 @@ class ConsumerChain(Consumer): handle_exception(consumer, e) else: raise e + + if consumer.handler.has_issues: + self.context.validation.extend_issues(consumer.handler.issues) + if self.context.validation.has_issues: break http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/fcc6b9c6/aria/parser/consumption/modeling.py ---------------------------------------------------------------------- diff --git a/aria/parser/consumption/modeling.py b/aria/parser/consumption/modeling.py index 828cc30..1338c03 100644 --- a/aria/parser/consumption/modeling.py +++ b/aria/parser/consumption/modeling.py @@ -123,7 +123,7 @@ class InstantiateServiceInstance(Consumer): CoerceServiceInstanceValues )).consume() - if self.handler.dump_issues(): + if self.context.validation.dump_issues(): raise exceptions.InstantiationError('Failed to instantiate service template `{0}`' .format(self.context.modeling.template.name)) http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/fcc6b9c6/aria/parser/validation/issue.py ---------------------------------------------------------------------- diff --git a/aria/parser/validation/issue.py b/aria/parser/validation/issue.py index 17e488f..11ea7f9 100644 --- a/aria/parser/validation/issue.py +++ b/aria/parser/validation/issue.py @@ -168,6 +168,10 @@ class Reporter(object): def issues_as_raw(self): return [formatting.as_raw(i) for i in self.issues] + def extend_issues(self, *issues): + with self._issues: + self._issues.extend(*issues) + def dump_issues(self): issues = self.issues if issues: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/fcc6b9c6/tests/instantiation/test_configuration.py ---------------------------------------------------------------------- diff --git a/tests/instantiation/test_configuration.py b/tests/instantiation/test_configuration.py index d4d91da..a41f0a8 100644 --- a/tests/instantiation/test_configuration.py +++ b/tests/instantiation/test_configuration.py @@ -17,7 +17,6 @@ import pytest from tests.parser.service_templates import consume_literal from aria.modeling.utils import parameters_as_values -from aria.orchestrator.topology import handler TEMPLATE = """ @@ -166,9 +165,11 @@ def test_remote(service): def test_reserved_arguments(broken_service_issues): - assert len(broken_service_issues) == 1 - assert len(handler.issues) == 1 - issue = handler.issues[0].message - assert all([issue.startswith('using reserved arguments in operation "operation": '), - 'ctx' in issue, - 'toolbelt' in issue]) + assert len(broken_service_issues) == 2 + + assert any( + all([issue.message.startswith('using reserved arguments in operation "operation": '), + 'ctx' in issue.message, + 'toolbelt' in issue.message]) + for issue in broken_service_issues + )
