Repository: incubator-ariatosca Updated Branches: refs/heads/ARIA-174-Refactor-instantiation-phase 2a80b22ca -> cb4c04692 (forced update)
review 1 - fixups 2 Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/cb4c0469 Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/cb4c0469 Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/cb4c0469 Branch: refs/heads/ARIA-174-Refactor-instantiation-phase Commit: cb4c046925a6a9aa55b10b48dd5489b8aa08a1e6 Parents: a33ba12 Author: max-orlov <[email protected]> Authored: Thu Aug 3 16:07:21 2017 +0300 Committer: max-orlov <[email protected]> Committed: Thu Aug 3 16:34:29 2017 +0300 ---------------------------------------------------------------------- aria/core.py | 6 +-- aria/orchestrator/topology/common.py | 16 +++++++- aria/orchestrator/topology/instance_handler.py | 27 ++++++++----- aria/orchestrator/topology/template_handler.py | 45 ++++++++++++++------- aria/orchestrator/topology/topology.py | 1 - aria/parser/consumption/modeling.py | 1 - tests/parser/service_templates.py | 3 +- 7 files changed, 68 insertions(+), 31 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/cb4c0469/aria/core.py ---------------------------------------------------------------------- diff --git a/aria/core.py b/aria/core.py index ad099be..30ca2d6 100644 --- a/aria/core.py +++ b/aria/core.py @@ -76,16 +76,16 @@ class Core(object): with storage_session.no_autoflush: topology_ = topology.Topology(self.model_storage) service = topology_.instantiate(service_template, inputs=inputs) - topology_.coerce(service) + topology_.coerce(service, report_issues=True) topology_.validate(service) topology_.satisfy_requirements(service) - topology_.coerce(service) + topology_.coerce(service, report_issues=True) topology_.validate_capabilities(service) topology_.assign_hosts(service) topology_.configure_operations(service) - topology_.coerce(service) + topology_.coerce(service, report_issues=True) if topology_.dump_issues(): raise exceptions.InstantiationError('Failed to instantiate service template `{0}`' .format(service_template.name)) http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/cb4c0469/aria/orchestrator/topology/common.py ---------------------------------------------------------------------- diff --git a/aria/orchestrator/topology/common.py b/aria/orchestrator/topology/common.py index 7b02fd2..96ceb31 100644 --- a/aria/orchestrator/topology/common.py +++ b/aria/orchestrator/topology/common.py @@ -38,13 +38,27 @@ class HandlerBase(object): class TemplateHandlerBase(HandlerBase): + """ + Base handler for template based models + """ def instantiate(self, instance_cls): raise NotImplementedError class InstanceHandlerBase(HandlerBase): - pass + """ + Base handler for instance based models + + """ + def validate(self, **kwargs): + raise NotImplementedError + + def coerce(self, **kwargs): + raise NotImplementedError + + def dump(self, out_stream): + raise NotImplementedError class ActorHandlerBase(HandlerBase): http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/cb4c0469/aria/orchestrator/topology/instance_handler.py ---------------------------------------------------------------------- diff --git a/aria/orchestrator/topology/instance_handler.py b/aria/orchestrator/topology/instance_handler.py index 833c3a3..4e0a974 100644 --- a/aria/orchestrator/topology/instance_handler.py +++ b/aria/orchestrator/topology/instance_handler.py @@ -156,7 +156,8 @@ class Node(common.ActorHandlerBase): self._topology.dump(self._model.interfaces, out_stream, title='Interfaces') self._topology.dump(self._model.artifacts, out_stream, title='Artifacts') self._topology.dump(self._model.capabilities, out_stream, title='Capabilities') - self._topology.dump(self._model.outbound_relationships, out_stream, title='Relationships') + self._topology.dump(self._model.outbound_relationships, out_stream, + title='Relationships') def configure_operations(self): for interface in self._model.interfaces.values(): @@ -362,11 +363,12 @@ class Operation(common.ActorHandlerBase): out_stream.literal_style(self._model.implementation))) if self._model.dependencies: out_stream.write( - 'Dependencies: {0}'.format( - ', '.join((str(out_stream.literal_style(v)) for v in self._model.dependencies)))) + 'Dependencies: {0}'.format(', '.join((str(out_stream.literal_style(v)) + for v in self._model.dependencies)))) self._topology.dump(self._model.inputs, out_stream, title='Inputs') if self._model.executor is not None: - out_stream.write('Executor: {0}'.format(out_stream.literal_style(self._model.executor))) + out_stream.write('Executor: {0}'.format(out_stream.literal_style( + self._model.executor))) if self._model.max_attempts is not None: out_stream.write('Max attempts: {0}'.format(out_stream.literal_style( self._model.max_attempts))) @@ -378,7 +380,8 @@ class Operation(common.ActorHandlerBase): out_stream.literal_style(self._model.plugin.name))) self._topology.dump(self._model.configurations, out_stream, title='Configuration') if self._model.function is not None: - out_stream.write('Function: {0}'.format(out_stream.literal_style(self._model.function))) + out_stream.write('Function: {0}'.format(out_stream.literal_style( + self._model.function))) self._topology.dump(self._model.arguments, out_stream, title='Arguments') def configure_operations(self): @@ -461,7 +464,8 @@ class Relationship(common.ActorHandlerBase): else: out_stream.write('->') with out_stream.indent(): - out_stream.write('Node: {0}'.format(out_stream.node_style(self._model.target_node.name))) + out_stream.write('Node: {0}'.format(out_stream.node_style( + self._model.target_node.name))) if self._model.target_capability: out_stream.write('Capability: {0}'.format(out_stream.node_style( self._model.target_capability.name))) @@ -545,12 +549,16 @@ class Substitution(common.InstanceHandlerBase): def dump(self, out_stream): out_stream.write('Substitution:') with out_stream.indent(): - out_stream.write('Node type: {0}'.format(out_stream.type_style(self._model.node_type.name))) + out_stream.write('Node type: {0}'.format(out_stream.type_style( + self._model.node_type.name))) self._topology.dump(self._model.mappings, out_stream, title='Mappings') class SubstitutionMapping(common.InstanceHandlerBase): + def coerce(self, **kwargs): + pass + def validate(self, **_): if (self._model.capability is None) and (self._model.requirement_template is None): self._topology.report( @@ -606,7 +614,7 @@ class _Parameter(common.InstanceHandlerBase): def instantiate(self, instance_cls, **kwargs): return instance_cls( - name=self._model.name, # pylint: disable=unexpected-keyword-arg + name=self._model.name, # pylint: disable=unexpected-keyword-arg type_name=self._model.type_name, _value=self._model._value, description=self._model.description @@ -615,7 +623,7 @@ class _Parameter(common.InstanceHandlerBase): def validate(self): pass - def coerce(self, report_issues): + def coerce(self, report_issues): # pylint: disable=arguments-differ value = self._model._value if value is not None: evaluation = functions.evaluate(value, self._model, report_issues) @@ -623,6 +631,7 @@ class _Parameter(common.InstanceHandlerBase): # A final evaluation can safely replace the existing value self._model._value = evaluation.value + class Attribute(_Parameter): pass http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/cb4c0469/aria/orchestrator/topology/template_handler.py ---------------------------------------------------------------------- diff --git a/aria/orchestrator/topology/template_handler.py b/aria/orchestrator/topology/template_handler.py index 6d52e5d..8f57ace 100644 --- a/aria/orchestrator/topology/template_handler.py +++ b/aria/orchestrator/topology/template_handler.py @@ -94,8 +94,8 @@ class ServiceTemplate(common.TemplateHandlerBase): for plugin in plugins: if (plugin.name == plugin_specification.name and (plugin_specification.version is None or - versions.VersionString(plugin.package_version) >= - plugin_specification.version) + versions.VersionString(plugin.package_version) >= + plugin_specification.version) ): matching_plugins.append(plugin) plugin_specification.plugin = None @@ -151,8 +151,10 @@ class ArtifactTemplate(common.TemplateHandlerBase): if self._model.description: out_stream.write(out_stream.meta_style(self._model.description)) with out_stream.indent(): - out_stream.write('Artifact type: {0}'.format(out_stream.type_style(self._model.type_style.name))) - out_stream.write('Source path: {0}'.format(out_stream.literal_style(self._model.source_path))) + out_stream.write('Artifact type: {0}'.format(out_stream.type_style( + self._model.type_style.name))) + out_stream.write('Source path: {0}'.format(out_stream.literal_style( + self._model.source_path))) if self._model.target_path is not None: out_stream.write('Target path: {0}'.format(out_stream.literal_style( self._model.target_path))) @@ -263,7 +265,8 @@ class GroupTemplate(common.TemplateHandlerBase): with out_stream.indent(): out_stream.write('Type: {0}'.format(out_stream.type_style(self._model.type_style.name))) self._topology.dump(self._model.properties, out_stream, title='Properties') - self._topology.dump(self._model.interface_templates, out_stream, title='Interface Templates') + self._topology.dump(self._model.interface_templates, out_stream, + title='Interface Templates') if self._model.node_templates: out_stream.write('Member node templates: {0}'.format(', '.join( (str(out_stream.node_style(v.name)) for v in self._model.node_templates)))) @@ -298,9 +301,11 @@ class InterfaceTemplate(common.TemplateHandlerBase): if self._model.description: out_stream.write(out_stream.meta_style(self._model.description)) with out_stream.indent(): - out_stream.write('Interface type: {0}'.format(out_stream.type_style(self._model.type_style.name))) + out_stream.write('Interface type: {0}'.format(out_stream.type_style( + self._model.type_style.name))) self._topology.dump(self._model.inputs, out_stream, title='Inputs') - self._topology.dump(self._model.operation_templates, out_stream, title='Operation templates') + self._topology.dump(self._model.operation_templates, out_stream, + title='Operation templates') def coerce(self, **kwargs): self._coerce(self._model.inputs, @@ -425,7 +430,8 @@ class SubstitutionTemplate(common.TemplateHandlerBase): def dump(self, out_stream): out_stream.write('Substitution template:') with out_stream.indent(): - out_stream.write('Node type: {0}'.format(out_stream.type_style(self._model.node_type.name))) + out_stream.write('Node type: {0}'.format(out_stream.type_style( + self._model.node_type.name))) self._topology.dump(self._model.mappings, out_stream, title='Mappings') def coerce(self, **kwargs): @@ -450,8 +456,8 @@ class SubstitutionTemplateMapping(common.TemplateHandlerBase): out_stream.node_style(self._model.name), out_stream.node_style(node_template.name), out_stream.node_style(self._model.capability_template.name - if self._model.capability_template - else self._model.requirement_template.name))) + if self._model.capability_template + else self._model.requirement_template.name))) def coerce(self, **_): pass @@ -504,7 +510,8 @@ class RelationshipTemplate(common.TemplateHandlerBase): out_stream.write(out_stream.meta_style(self._model.description)) with out_stream.indent(): self._topology.dump(self._model.properties, out_stream, title='Properties') - self._topology.dump(self._model.interface_templates, out_stream, title='Interface Templates') + self._topology.dump(self._model.interface_templates, out_stream, + title='Interface Templates') def coerce(self, **kwargs): self._coerce(self._model.properties, self._model.interface_templates, **kwargs) @@ -534,11 +541,12 @@ class OperationTemplate(common.TemplateHandlerBase): out_stream.write('Implementation: {0}'.format( out_stream.literal_style(self._model.implementation))) if self._model.dependencies: - out_stream.write('Dependencies: {0}'.format( - ', '.join((str(out_stream.literal_style(v)) for v in self._model.dependencies)))) + out_stream.write('Dependencies: {0}'.format(', '.join( + (str(out_stream.literal_style(v)) for v in self._model.dependencies)))) self._topology.dump(self._model.inputs, out_stream, title='Inputs') if self._model.executor is not None: - out_stream.write('Executor: {0}'.format(out_stream.literal_style(self._model.executor))) + out_stream.write('Executor: {0}'.format( + out_stream.literal_style(self._model.executor))) if self._model.max_attempts is not None: out_stream.write('Max attempts: {0}'.format(out_stream.literal_style( self._model.max_attempts))) @@ -550,7 +558,8 @@ class OperationTemplate(common.TemplateHandlerBase): out_stream.literal_style(self._model.plugin_specification.name))) self._topology.dump(self._model.configurations, out_stream, title='Configuration') if self._model.function is not None: - out_stream.write('Function: {0}'.format(out_stream.literal_style(self._model.function))) + out_stream.write('Function: {0}'.format(out_stream.literal_style( + self._model.function))) def coerce(self, **kwargs): self._coerce(self._model.inputs, @@ -586,6 +595,12 @@ class OperationTemplate(common.TemplateHandlerBase): class PluginSpecification(common.TemplateHandlerBase): + def validate(self, **kwargs): + pass + + def coerce(self, **kwargs): + pass + def instantiate(self, **_): pass http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/cb4c0469/aria/orchestrator/topology/topology.py ---------------------------------------------------------------------- diff --git a/aria/orchestrator/topology/topology.py b/aria/orchestrator/topology/topology.py index b81f61d..96ee4f9 100644 --- a/aria/orchestrator/topology/topology.py +++ b/aria/orchestrator/topology/topology.py @@ -36,7 +36,6 @@ class Topology(issue.ReporterMixin): models.SubstitutionTemplate: models.Substitution, models.RelationshipTemplate: models.Relationship, models.OperationTemplate: models.Operation, - models.RequirementTemplate: None, models.SubstitutionTemplateMapping: models.SubstitutionMapping, # Common http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/cb4c0469/aria/parser/consumption/modeling.py ---------------------------------------------------------------------- diff --git a/aria/parser/consumption/modeling.py b/aria/parser/consumption/modeling.py index f27216b..221b308 100644 --- a/aria/parser/consumption/modeling.py +++ b/aria/parser/consumption/modeling.py @@ -15,7 +15,6 @@ from .consumer import Consumer, ConsumerChain from ...utils.formatting import json_dumps, yaml_dumps -from ... import exceptions class DeriveServiceTemplate(Consumer): http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/cb4c0469/tests/parser/service_templates.py ---------------------------------------------------------------------- diff --git a/tests/parser/service_templates.py b/tests/parser/service_templates.py index ec41cd2..9e8fcae 100644 --- a/tests/parser/service_templates.py +++ b/tests/parser/service_templates.py @@ -27,7 +27,6 @@ def consume_literal(literal, consumer_class_name='instance', cache=True, no_issu context = create_context(LiteralLocation(literal)) consumer, dumper = create_consumer(context, consumer_class_name) consumer.consume() - consumer.dump() if no_issues: context.validation.dump_issues() assert not context.validation.has_issues @@ -48,6 +47,7 @@ def consume_use_case(use_case_name, consumer_class_name='instance', cache=True): assert not context.validation.has_issues return context, dumper + def consume_types_use_case(use_case_name, consumer_class_name='instance', cache=True): cachedmethod.ENABLED = cache uri = get_service_template_uri('tosca-simple-1.0', 'types', use_case_name, @@ -62,6 +62,7 @@ def consume_types_use_case(use_case_name, consumer_class_name='instance', cache= assert not context.validation.has_issues return context, dumper + def consume_node_cellar(consumer_class_name='instance', cache=True): consume_test_case( get_service_template_uri('tosca-simple-1.0', 'node-cellar', 'node-cellar.yaml'),
