ariatosca-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mxm...@apache.org
Subject [1/2] incubator-ariatosca git commit: removed all unnecessary method from models into the topology package
Date Tue, 25 Jul 2017 12:34:47 GMT
Repository: incubator-ariatosca
Updated Branches:
  refs/heads/ARIA-174-Refactor-instantiation-phase a9640765a -> 4ae0e5f99


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/4ae0e5f9/aria/orchestrator/topology/template.py
----------------------------------------------------------------------
diff --git a/aria/orchestrator/topology/template.py b/aria/orchestrator/topology/template.py
index 86619a9..8b78c7a 100644
--- a/aria/orchestrator/topology/template.py
+++ b/aria/orchestrator/topology/template.py
@@ -21,30 +21,30 @@ from . import utils, common
 
 class ServiceTemplate(common._TemplateHandler):
     def dump(self, context):
-        if self._template.description is not None:
-            context.write(context.style.meta(self._template.description))
-        self._topology.dump(self._template.meta_data, context, 'Metadata')
-        for node_template in self._template.node_templates.itervalues():
+        if self._model.description is not None:
+            context.write(context.style.meta(self._model.description))
+        self._topology.dump(self._model.meta_data, context, 'Metadata')
+        for node_template in self._model.node_templates.itervalues():
             node_template.dump()
-        for group_template in self._template.group_templates.itervalues():
+        for group_template in self._model.group_templates.itervalues():
             group_template.dump()
-        for policy_template in self._template.policy_templates.itervalues():
+        for policy_template in self._model.policy_templates.itervalues():
             policy_template.dump()
-        if self._template.substitution_template is not None:
-            self._template.substitution_template.dump()
-        self._topology.dump(self._template.inputs, context, 'Inputs')
-        self._topology.dump(self._template.outputs, context, 'Outputs')
-        self._topology.dump(self._template.workflow_templates, context, 'Workflow templates')
+        if self._model.substitution_template is not None:
+            self._model.substitution_template.dump()
+        self._topology.dump(self._model.inputs, context, 'Inputs')
+        self._topology.dump(self._model.outputs, context, 'Outputs')
+        self._topology.dump(self._model.workflow_templates, context, 'Workflow templates')
 
     def coerce(self, **kwargs):
-        self._coerce(self._template.meta_data,
-                     self._template.node_templates,
-                     self._template.group_templates,
-                     self._template.policy_templates,
-                     self._template.substitution_template,
-                     self._template.inputs,
-                     self._template.outputs,
-                     self._template.workflow_templates,
+        self._coerce(self._model.meta_data,
+                     self._model.node_templates,
+                     self._model.group_templates,
+                     self._model.policy_templates,
+                     self._model.substitution_template,
+                     self._model.inputs,
+                     self._model.outputs,
+                     self._model.workflow_templates,
                      **kwargs)
 
     def instantiate(self, instance_cls, inputs=None):
@@ -52,12 +52,12 @@ class ServiceTemplate(common._TemplateHandler):
         service = instance_cls(
             created_at=now,
             updated_at=now,
-            description=utils.deepcopy_with_locators(self._template.description),
-            service_template=self._template,
-            inputs=modeling_utils.merge_parameter_values(inputs, self._template.inputs)
+            description=utils.deepcopy_with_locators(self._model.description),
+            service_template=self._model,
+            inputs=modeling_utils.merge_parameter_values(inputs, self._model.inputs)
         )
 
-        for plugin_specification in self._template.plugin_specifications.itervalues():
+        for plugin_specification in self._model.plugin_specifications.itervalues():
             if plugin_specification.enabled and self._topology._model_storage:
                 if utils.resolve_plugin_specification(plugin_specification,
                                                       self._topology.model_storage.plugin.list()):
@@ -68,262 +68,320 @@ class ServiceTemplate(common._TemplateHandler):
                     pass
                     # self._context.validation.report('specified plugin not found: {0}'.format(
                     #     plugin_specification.name), level=validation.Issue.EXTERNAL)
-        service.meta_data = self._topology.instantiate(self._template.meta_data)
+        service.meta_data = self._topology.instantiate(self._model.meta_data)
 
-        for node_template in self._template.node_templates.itervalues():
-            for _ in range(node_template.scaling['default_instances']):
+        for node_template in self._model.node_templates.itervalues():
+            for _ in range(self._scaling(node_template)['default_instances']):
                 node = self._topology.instantiate(node_template)
                 service.nodes[node.name] = node
 
-        service.groups = self._topology.instantiate(self._template.group_templates)
-        service.policies = self._topology.instantiate(self._template.policy_templates)
-        service.workflows = self._topology.instantiate(self._template.workflow_templates)
+        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._template.substitution_template is not None:
-            service.substitution = self._topology.instantiate(self._template.substitution_template)
-            service.outputs = self._topology.instantiate(self._template.outputs)
+        if self._model.substitution_template is not None:
+            service.substitution = self._topology.instantiate(self._model.substitution_template)
+            service.outputs = self._topology.instantiate(self._model.outputs)
 
         return service
 
+    @staticmethod
+    def _scaling(node_template):
+        scaling = {}
+
+        def extract_property(properties, name):
+            if name in scaling:
+                return
+            prop = properties.get(name)
+            if (prop is not None) and (prop.type_name == 'integer') and (prop.value is not
None):
+                scaling[name] = prop.value
+
+        def extract_properties(properties):
+            extract_property(properties, 'min_instances')
+            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':
+                extract_properties(capability_template.properties)
+
+        # From service scaling policies
+        for policy_template in node_template.service_template.policy_templates.itervalues():
+            if policy_template.type.role == 'scaling':
+                if policy_template.is_for_node_template(node_template.name):
+                    extract_properties(policy_template.properties)
+
+        # Defaults
+        default_property('min_instances', 0)
+        default_property('max_instances', 1)
+        default_property('default_instances', 1)
+
+        # Validate
+        # pylint: disable=too-many-boolean-expressions
+        if (scaling['min_instances'] < 0 or
+            scaling['max_instances'] < 0 or
+            scaling['default_instances'] < 0 or
+            scaling['max_instances'] < scaling['min_instances'] or
+            scaling['default_instances'] < scaling['min_instances'] or
+            scaling['default_instances'] > scaling['max_instances']):
+            pass
+            # TODO: fix this
+            # context = ConsumptionContext.get_thread_local()
+            # context.validation.report('invalid scaling parameters for node template "{0}":
'
+                                      # 'min={1}, max={2}, default={3}'.format(
+                                      #     self.name,
+                                      #     scaling['min_instances'],
+                                      #     scaling['max_instances'],
+                                      #     scaling['default_instances']),
+                                      # level=validation.Issue.BETWEEN_TYPES)
+
+        return scaling
+
+
     def validate(self):
-        self._topology.validate(self._template.meta_data)
-        self._topology.validate(self._template.node_templates)
-        self._topology.validate(self._template.group_templates)
-        self._topology.validate(self._template.policy_templates)
-        self._topology.validate(self._template.substitution_template)
-        self._topology.validate(self._template.inputs)
-        self._topology.validate(self._template.outputs)
-        self._topology.validate(self._template.workflow_templates)
-        self._topology.validate(self._template.node_types)
-        self._topology.validate(self._template.group_types)
-        self._topology.validate(self._template.policy_types)
-        self._topology.validate(self._template.relationship_types)
-        self._topology.validate(self._template.capability_types)
-        self._topology.validate(self._template.interface_types)
-        self._topology.validate(self._template.artifact_types)
+        self._topology.validate(self._model.meta_data)
+        self._topology.validate(self._model.node_templates)
+        self._topology.validate(self._model.group_templates)
+        self._topology.validate(self._model.policy_templates)
+        self._topology.validate(self._model.substitution_template)
+        self._topology.validate(self._model.inputs)
+        self._topology.validate(self._model.outputs)
+        self._topology.validate(self._model.workflow_templates)
+        self._topology.validate(self._model.node_types)
+        self._topology.validate(self._model.group_types)
+        self._topology.validate(self._model.policy_types)
+        self._topology.validate(self._model.relationship_types)
+        self._topology.validate(self._model.capability_types)
+        self._topology.validate(self._model.interface_types)
+        self._topology.validate(self._model.artifact_types)
 
 
 class ArtifactTemplate(common._TemplateHandler):
     def dump(self, context):
-        context.write(context.style.node(self._template.name))
-        if self._template.description:
-            context.write(context.style.meta(self._template.description))
+        context.write(context.style.node(self._model.name))
+        if self._model.description:
+            context.write(context.style.meta(self._model.description))
         with context.style.indent:
-            context.write('Artifact type: {0}'.format(context.style.type(self._template.type.name)))
-            context.write('Source path: {0}'.format(context.style.literal(self._template.source_path)))
-            if self._template.target_path is not None:
-                context.write('Target path: {0}'.format(context.style.literal(self._template.target_path)))
-            if self._template.repository_url is not None:
+            context.write('Artifact type: {0}'.format(context.style.type(self._model.type.name)))
+            context.write('Source path: {0}'.format(context.style.literal(self._model.source_path)))
+            if self._model.target_path is not None:
+                context.write('Target path: {0}'.format(context.style.literal(self._model.target_path)))
+            if self._model.repository_url is not None:
                 context.write('Repository URL: {0}'.format(
-                    context.style.literal(self._template.repository_url)))
-            if self._template.repository_credential:
+                    context.style.literal(self._model.repository_url)))
+            if self._model.repository_credential:
                 context.write('Repository credential: {0}'.format(
-                    context.style.literal(self._template.repository_credential)))
-            self._topology.dump(self._template.properties, context, 'Properties')
+                    context.style.literal(self._model.repository_credential)))
+            self._topology.dump(self._model.properties, context, 'Properties')
 
     def coerce(self, **kwargs):
-        self._topology.coerce(self._template.properties, **kwargs)
+        self._topology.coerce(self._model.properties, **kwargs)
 
     def instantiate(self, instance_cls):
         return instance_cls(
-            name=self._template.name,
-            type=self._template.type,
-            description=utils.deepcopy_with_locators(self._template.description),
-            source_path=self._template.source_path,
-            target_path=self._template.target_path,
-            repository_url=self._template.repository_url,
-            repository_credential=self._template.repository_credential,
-            artifact_template=self._template)
+            name=self._model.name,
+            type=self._model.type,
+            description=utils.deepcopy_with_locators(self._model.description),
+            source_path=self._model.source_path,
+            target_path=self._model.target_path,
+            repository_url=self._model.repository_url,
+            repository_credential=self._model.repository_credential,
+            artifact_template=self._model)
 
     def validate(self):
-        self._topology.validate(self._template.properties)
+        self._topology.validate(self._model.properties)
 
 
 class CapabilityTemplate(common._TemplateHandler):
     def dump(self, context):
-        context.write(context.style.node(self._template.name))
-        if self._template.description:
-            context.write(context.style.meta(self._template.description))
+        context.write(context.style.node(self._model.name))
+        if self._model.description:
+            context.write(context.style.meta(self._model.description))
         with context.style.indent:
-            context.write('Type: {0}'.format(context.style.type(self._template.type.name)))
+            context.write('Type: {0}'.format(context.style.type(self._model.type.name)))
             context.write(
                 'Occurrences: {0:d}{1}'.format(
-                    self._template.min_occurrences or 0,
-                    ' to {0:d}'.format(self._template.max_occurrences)
-                    if self._template.max_occurrences is not None
+                    self._model.min_occurrences or 0,
+                    ' to {0:d}'.format(self._model.max_occurrences)
+                    if self._model.max_occurrences is not None
                     else ' or more'))
-            if self._template.valid_source_node_types:
+            if self._model.valid_source_node_types:
                 context.write('Valid source node types: {0}'.format(
                     ', '.join((str(context.style.type(v.name))
-                               for v in self._template.valid_source_node_types))))
-            self._topology.dump(self._template.properties, context, 'Properties')
+                               for v in self._model.valid_source_node_types))))
+            self._topology.dump(self._model.properties, context, 'Properties')
 
     def coerce(self):
-        self._topology.coerce(self._template.properties)
+        self._topology.coerce(self._model.properties)
 
     def instantiate(self, instance_cls):
-        return instance_cls(name=self._template.name,
-                            type=self._template.type,
-                            min_occurrences=self._template.min_occurrences,
-                            max_occurrences=self._template.max_occurrences,
+        return instance_cls(name=self._model.name,
+                            type=self._model.type,
+                            min_occurrences=self._model.min_occurrences,
+                            max_occurrences=self._model.max_occurrences,
                             occurrences=0,
-                            capability_template=self._template)
+                            capability_template=self._model)
 
     def validate(self):
-        self._topology.validate(self._template.properties)
+        self._topology.validate(self._model.properties)
 
 
 class RequirementTemplate(common._TemplateHandler):
     def dump(self, context):
-        if self._template.name:
-            context.write(context.style.node(self._template.name))
+        if self._model.name:
+            context.write(context.style.node(self._model.name))
         else:
             context.write('Requirement:')
         with context.style.indent:
-            if self._template.target_node_type is not None:
+            if self._model.target_node_type is not None:
                 context.write('Target node type: {0}'.format(
-                    context.style.type(self._template.target_node_type.name)))
-            elif self._template.target_node_template is not None:
+                    context.style.type(self._model.target_node_type.name)))
+            elif self._model.target_node_template is not None:
                 context.write('Target node template: {0}'.format(
-                    context.style.node(self._template.target_node_template.name)))
-            if self._template.target_capability_type is not None:
+                    context.style.node(self._model.target_node_template.name)))
+            if self._model.target_capability_type is not None:
                 context.write('Target capability type: {0}'.format(
-                    context.style.type(self._template.target_capability_type.name)))
-            elif self._template.target_capability_name is not None:
+                    context.style.type(self._model.target_capability_type.name)))
+            elif self._model.target_capability_name is not None:
                 context.write('Target capability name: {0}'.format(
-                    context.style.node(self._template.target_capability_name)))
-            if self._template.target_node_template_constraints:
+                    context.style.node(self._model.target_capability_name)))
+            if self._model.target_node_template_constraints:
                 context.write('Target node template constraints:')
                 with context.style.indent:
-                    for constraint in self._template.target_node_template_constraints:
+                    for constraint in self._model.target_node_template_constraints:
                         context.write(context.style.literal(constraint))
-            if self._template.relationship_template:
+            if self._model.relationship_template:
                 context.write('Relationship:')
                 with context.style.indent:
-                    self._template.relationship_template.dump()
+                    self._model.relationship_template.dump()
 
     def coerce(self, **kwargs):
-        self._topology.coerce(self._template.relationship_template, **kwargs)
+        self._topology.coerce(self._model.relationship_template, **kwargs)
 
     def instantiate(self, instance_cls):
-        return instance_cls(name=self._template.name,
-                            type=self._template.type,
-                            min_occurrences=self._template.min_occurrences,
-                            max_occurrences=self._template.max_occurrences,
+        return instance_cls(name=self._model.name,
+                            type=self._model.type,
+                            min_occurrences=self._model.min_occurrences,
+                            max_occurrences=self._model.max_occurrences,
                             occurrences=0,
-                            capability_template=self._template)
+                            capability_template=self._model)
 
     def validate(self):
-        self._topology.validate(self._template.relationship_template)
+        self._topology.validate(self._model.relationship_template)
 
 
 class GroupTemplate(common._TemplateHandler):
     def dump(self, context):
-        context.write('Group template: {0}'.format(context.style.node(self._template.name)))
-        if self._template.description:
-            context.write(context.style.meta(self._template.description))
+        context.write('Group template: {0}'.format(context.style.node(self._model.name)))
+        if self._model.description:
+            context.write(context.style.meta(self._model.description))
         with context.style.indent:
-            context.write('Type: {0}'.format(context.style.type(self._template.type.name)))
-            self._topology.dump(self._template.properties, context, 'Properties')
-            self._topology.dump(self._template.interface_templates, context, 'Interface Templates')
-            if self._template.node_templates:
+            context.write('Type: {0}'.format(context.style.type(self._model.type.name)))
+            self._topology.dump(self._model.properties, context, 'Properties')
+            self._topology.dump(self._model.interface_templates, context, 'Interface Templates')
+            if self._model.node_templates:
                 context.write('Member node templates: {0}'.format(', '.join(
-                    (str(context.style.node(v.name)) for v in self._template.node_templates))))
+                    (str(context.style.node(v.name)) for v in self._model.node_templates))))
 
     def coerce(self, **kwargs):
-        self._coerce(self._template.properties,
-                     self._template.interface_templates,
+        self._coerce(self._model.properties,
+                     self._model.interface_templates,
                      **kwargs)
 
     def instantiate(self, instance_cls):
         group = instance_cls(
-            name=self._template.name,
-            type=self._template.type,
-            description=utils.deepcopy_with_locators(self._template.description),
-            group_template=self._template)
-        group.properties = self._topology.instantiate(self._template.properties)
-        group.interfaces = self._topology.instantiate(self._template.interface_templates)
-        if self._template.node_templates:
-            for node_template in self._template.node_templates:
+            name=self._model.name,
+            type=self._model.type,
+            description=utils.deepcopy_with_locators(self._model.description),
+            group_template=self._model)
+        group.properties = self._topology.instantiate(self._model.properties)
+        group.interfaces = self._topology.instantiate(self._model.interface_templates)
+        if self._model.node_templates:
+            for node_template in self._model.node_templates:
                 group.nodes += node_template.nodes
         return group
 
     def validate(self):
-        self._validate(self._template.properties,
-                       self._template.interface_templates)
+        self._validate(self._model.properties,
+                       self._model.interface_templates)
 
 
 class InterfaceTemplate(common._TemplateHandler):
     def dump(self, context):
-        context.write(context.style.node(self._template.name))
-        if self._template.description:
-            context.write(context.style.meta(self._template.description))
+        context.write(context.style.node(self._model.name))
+        if self._model.description:
+            context.write(context.style.meta(self._model.description))
         with context.style.indent:
-            context.write('Interface type: {0}'.format(context.style.type(self._template.type.name)))
-            self._topology.dump(self._template.inputs, context, 'Inputs')
-            self._topology.dump(self._template.operation_templates, context, 'Operation templates')
+            context.write('Interface type: {0}'.format(context.style.type(self._model.type.name)))
+            self._topology.dump(self._model.inputs, context, 'Inputs')
+            self._topology.dump(self._model.operation_templates, context, 'Operation templates')
 
     def coerce(self, **kwargs):
-        self._coerce(self._template.inputs,
-                     self._template.operation_templates,
+        self._coerce(self._model.inputs,
+                     self._model.operation_templates,
                      **kwargs)
 
     def instantiate(self, instance_cls):
         interface = instance_cls(
-            name=self._template.name,
-            type=self._template.type,
-            description=utils.deepcopy_with_locators(self._template.description),
-            interface_template=self._template)
-        interface.inputs = self._topology.instantiate(self._template.inputs)
-        interface.operations = self._topology.instantiate(self._template.operation_templates)
+            name=self._model.name,
+            type=self._model.type,
+            description=utils.deepcopy_with_locators(self._model.description),
+            interface_template=self._model)
+        interface.inputs = self._topology.instantiate(self._model.inputs)
+        interface.operations = self._topology.instantiate(self._model.operation_templates)
         return interface
 
     def validate(self):
-        self._validate(self._template.inputs,
-                       self._template.operation_templates)
+        self._validate(self._model.inputs,
+                       self._model.operation_templates)
 
 
 class NodeTemplate(common._TemplateHandler):
     def dump(self, context):
-        context.write('Node template: {0}'.format(context.style.node(self._template.name)))
-        if self._template.description:
-            context.write(context.style.meta(self._template.description))
+        context.write('Node template: {0}'.format(context.style.node(self._model.name)))
+        if self._model.description:
+            context.write(context.style.meta(self._model.description))
         with context.style.indent:
-            context.write('Type: {0}'.format(context.style.type(self._template.type.name)))
-            self._topology.dump(self._template.properties, context, 'Properties')
-            self._topology.dump(self._template.attributes, context, 'Attributes')
-            self._topology.dump(self._template.interface_templates, context, 'Interface Templates')
-            self._topology.dump(self._template.artifact_templates, context, 'Artifact templates')
-            self._topology.dump(self._template.capability_templates, context, 'Capability
templates')
-            self._topology.dump(self._template.requirement_templates, context, 'Requirement
templates')
+            context.write('Type: {0}'.format(context.style.type(self._model.type.name)))
+            self._topology.dump(self._model.properties, context, 'Properties')
+            self._topology.dump(self._model.attributes, context, 'Attributes')
+            self._topology.dump(self._model.interface_templates, context, 'Interface Templates')
+            self._topology.dump(self._model.artifact_templates, context, 'Artifact templates')
+            self._topology.dump(self._model.capability_templates, context, 'Capability templates')
+            self._topology.dump(self._model.requirement_templates, context, 'Requirement
templates')
 
     def coerce(self, **kwargs):
-        self._coerce(self._template.properties,
-                     self._template.attributes,
-                     self._template.interface_templates,
-                     self._template.artifact_templates,
-                     self._template.capability_templates,
-                     self._template.requirement_templates,
+        self._coerce(self._model.properties,
+                     self._model.attributes,
+                     self._model.interface_templates,
+                     self._model.artifact_templates,
+                     self._model.capability_templates,
+                     self._model.requirement_templates,
                      **kwargs)
 
     def instantiate(self, instance_cls):
         node = instance_cls(
-            name=self._template._next_name,
-            type=self._template.type,
-            description=utils.deepcopy_with_locators(self._template.description),
-            node_template=self._template
+            name=self._model._next_name,
+            type=self._model.type,
+            description=utils.deepcopy_with_locators(self._model.description),
+            node_template=self._model
         )
 
-        node.properties = self._topology.instantiate(self._template.properties)
-        node.attributes = self._topology.instantiate(self._template.attributes)
-        node.interfaces = self._topology.instantiate(self._template.interface_templates)
-        node.artifacts = self._topology.instantiate(self._template.artifact_templates)
-        node.capabilities = self._topology.instantiate(self._template.capability_templates)
+        node.properties = self._topology.instantiate(self._model.properties)
+        node.attributes = self._topology.instantiate(self._model.attributes)
+        node.interfaces = self._topology.instantiate(self._model.interface_templates)
+        node.artifacts = self._topology.instantiate(self._model.artifact_templates)
+        node.capabilities = self._topology.instantiate(self._model.capability_templates)
 
         # Default attributes
         if ('tosca_name' in node.attributes) \
                 and (node.attributes['tosca_name'].type_name == 'string'):
-            node.attributes['tosca_name'].value = self._template.name
+            node.attributes['tosca_name'].value = self._model.name
         if 'tosca_id' in node.attributes \
                 and (node.attributes['tosca_id'].type_name == 'string'):
             node.attributes['tosca_id'].value = node.name
@@ -331,50 +389,50 @@ class NodeTemplate(common._TemplateHandler):
         return node
 
     def validate(self):
-        self._validate(self._template.properties,
-                       self._template.attributes,
-                       self._template.interface_templates,
-                       self._template.artifact_templates,
-                       self._template.capability_templates,
-                       self._template.requirement_templates)
+        self._validate(self._model.properties,
+                       self._model.attributes,
+                       self._model.interface_templates,
+                       self._model.artifact_templates,
+                       self._model.capability_templates,
+                       self._model.requirement_templates)
 
 
 class PolicyTemplate(common._TemplateHandler):
     def dump(self, context):
-        context.write('Policy template: {0}'.format(context.style.node(self._template.name)))
-        if self._template.description:
-            context.write(context.style.meta(self._template.description))
+        context.write('Policy template: {0}'.format(context.style.node(self._model.name)))
+        if self._model.description:
+            context.write(context.style.meta(self._model.description))
         with context.style.indent:
-            context.write('Type: {0}'.format(context.style.type(self._template.type.name)))
-            self._topology.dump(self._template.properties, context, 'Properties')
-            if self._template.node_templates:
+            context.write('Type: {0}'.format(context.style.type(self._model.type.name)))
+            self._topology.dump(self._model.properties, context, 'Properties')
+            if self._model.node_templates:
                 context.write('Target node templates: {0}'.format(', '.join(
-                    (str(context.style.node(v.name)) for v in self._template.node_templates))))
-            if self._template.group_templates:
+                    (str(context.style.node(v.name)) for v in self._model.node_templates))))
+            if self._model.group_templates:
                 context.write('Target group templates: {0}'.format(', '.join(
-                    (str(context.style.node(v.name)) for v in self._template.group_templates))))
+                    (str(context.style.node(v.name)) for v in self._model.group_templates))))
 
     def coerce(self, **kwargs):
-        self._topology.coerce(self._template.properties, **kwargs)
+        self._topology.coerce(self._model.properties, **kwargs)
 
     def instantiate(self, instance_cls):
         policy = instance_cls(
-            name=self._template.name,
-            type=self._template.type,
-            description=utils.deepcopy_with_locators(self._template.description),
-            policy_template=self._template)
-
-        policy.properties = self._topology.instantiate(self._template.properties)
-        if self._template.node_templates:
-            for node_template in self._template.node_templates:
+            name=self._model.name,
+            type=self._model.type,
+            description=utils.deepcopy_with_locators(self._model.description),
+            policy_template=self._model)
+
+        policy.properties = self._topology.instantiate(self._model.properties)
+        if self._model.node_templates:
+            for node_template in self._model.node_templates:
                 policy.nodes += node_template.nodes
-        if self._template.group_templates:
-            for group_template in self._template.group_templates:
+        if self._model.group_templates:
+            for group_template in self._model.group_templates:
                 policy.groups += group_template.groups
         return policy
 
     def validate(self):
-        self._topology.validate(self._template.properties)
+        self._topology.validate(self._model.properties)
 
 
 class SubstitutionTemplate(common._TemplateHandler):
@@ -382,18 +440,18 @@ class SubstitutionTemplate(common._TemplateHandler):
     def dump(self, context):
         context.write('Substitution template:')
         with context.style.indent:
-            context.write('Node type: {0}'.format(context.style.type(self._template.node_type.name)))
-            self._topology.dump(self._template.mappings, context, 'Mappings')
+            context.write('Node type: {0}'.format(context.style.type(self._model.node_type.name)))
+            self._topology.dump(self._model.mappings, context, 'Mappings')
 
     def coerce(self, **kwargs):
-        self._topology.coerce(self._template.mappings, **kwargs)
+        self._topology.coerce(self._model.mappings, **kwargs)
 
     def instantiate(self, instance_cls):
-        return instance_cls(node_type=self._template.node_type,
-                            substitution_template=self._template)
+        return instance_cls(node_type=self._model.node_type,
+                            substitution_template=self._model)
 
     def validate(self):
-        self._topology.validate(self._template.mappings)
+        self._topology.validate(self._model.mappings)
 
 
 class SubstitutionTemplateMapping(common._TemplateHandler):
@@ -415,13 +473,13 @@ class SubstitutionTemplateMapping(common._TemplateHandler):
 
     def instantiate(self, instance_cls):
         substitution_mapping = instance_cls(
-            name=self._template.name,
-            requirement_template=self._template.requirement_template)
+            name=self._model.name,
+            requirement_template=self._model.requirement_template)
 
-        if self._template.capability_template is not None:
-            node_template = self._template.capability_template.node_template
+        if self._model.capability_template is not None:
+            node_template = self._model.capability_template.node_template
         else:
-            node_template = self._template.requirement_template.node_template
+            node_template = self._model.requirement_template.node_template
         nodes = node_template.nodes
         if len(nodes) == 0:
             # TODO: manage the context report
@@ -434,10 +492,10 @@ class SubstitutionTemplateMapping(common._TemplateHandler):
         # The TOSCA spec does not provide a way to choose the node,
         # so we will just pick the first one
         substitution_mapping.node = nodes[0]
-        if self._template.capability_template:
+        if self._model.capability_template:
             for a_capability in substitution_mapping.node.capabilities.itervalues():
                 if a_capability.capability_template.name == \
-                        self._template.capability_template.name:
+                        self._model.capability_template.name:
                     substitution_mapping.capability = a_capability
 
         return substitution_mapping
@@ -445,8 +503,8 @@ class SubstitutionTemplateMapping(common._TemplateHandler):
     def validate(self):
         # context = ConsumptionContext.get_thread_local()
         if all([
-                    self._template.capability_template is None,
-                    self._template.requirement_template is None
+                    self._model.capability_template is None,
+                    self._model.requirement_template is None
         ]):
             pass
             # TODO: handle reporting
@@ -459,94 +517,94 @@ class SubstitutionTemplateMapping(common._TemplateHandler):
 
 class RelationshipTemplate(common._TemplateHandler):
     def dump(self, context):
-        if self._template.type is not None:
-            context.write('Relationship type: {0}'.format(context.style.type(self._template.type.name)))
+        if self._model.type is not None:
+            context.write('Relationship type: {0}'.format(context.style.type(self._model.type.name)))
         else:
             context.write('Relationship template: {0}'.format(
-                context.style.node(self._template.name)))
-        if self._template.description:
-            context.write(context.style.meta(self._template.description))
+                context.style.node(self._model.name)))
+        if self._model.description:
+            context.write(context.style.meta(self._model.description))
         with context.style.indent:
-            self._topology.dump(self._template.properties, context, 'Properties')
-            self._topology.dump(self._template.interface_templates, context, 'Interface Templates')
+            self._topology.dump(self._model.properties, context, 'Properties')
+            self._topology.dump(self._model.interface_templates, context, 'Interface Templates')
 
     def coerce(self, **kwargs):
-        self._coerce(self._template.properties, self._template.interface_templates, **kwargs)
+        self._coerce(self._model.properties, self._model.interface_templates, **kwargs)
 
     def instantiate(self, instance_cls):
         relationship = instance_cls(
-            name=self._template.name,
-            type=self._template.type,
-            relationship_template=self._template)
+            name=self._model.name,
+            type=self._model.type,
+            relationship_template=self._model)
 
-        relationship.properties = self._topology.instantiate(self._template.properties)
-        relationship.interfaces = self._topology.instantiate(self._template.interface_templates)
+        relationship.properties = self._topology.instantiate(self._model.properties)
+        relationship.interfaces = self._topology.instantiate(self._model.interface_templates)
         return relationship
 
     def validate(self):
         # TODO: either type or name must be set
-        self._validate(self._template.properties,
-                       self._template.interface_templates)
+        self._validate(self._model.properties,
+                       self._model.interface_templates)
 
 
 class OperationTemplate(common._TemplateHandler):
 
     def dump(self, context):
-        context.write(context.style.node(self._template.name))
-        if self._template.description:
-            context.write(context.style.meta(self._template.description))
+        context.write(context.style.node(self._model.name))
+        if self._model.description:
+            context.write(context.style.meta(self._model.description))
         with context.style.indent:
-            if self._template.implementation is not None:
+            if self._model.implementation is not None:
                 context.write('Implementation: {0}'.format(
-                    context.style.literal(self._template.implementation)))
-            if self._template.dependencies:
+                    context.style.literal(self._model.implementation)))
+            if self._model.dependencies:
                 context.write('Dependencies: {0}'.format(
-                    ', '.join((str(context.style.literal(v)) for v in self._template.dependencies))))
-            self._topology.dump(self._template.inputs, context, 'Inputs')
-            if self._template.executor is not None:
-                context.write('Executor: {0}'.format(context.style.literal(self._template.executor)))
-            if self._template.max_attempts is not None:
-                context.write('Max attempts: {0}'.format(context.style.literal(self._template.max_attempts)))
-            if self._template.retry_interval is not None:
+                    ', '.join((str(context.style.literal(v)) for v in self._model.dependencies))))
+            self._topology.dump(self._model.inputs, context, 'Inputs')
+            if self._model.executor is not None:
+                context.write('Executor: {0}'.format(context.style.literal(self._model.executor)))
+            if self._model.max_attempts is not None:
+                context.write('Max attempts: {0}'.format(context.style.literal(self._model.max_attempts)))
+            if self._model.retry_interval is not None:
                 context.write('Retry interval: {0}'.format(
-                    context.style.literal(self._template.retry_interval)))
-            if self._template.plugin_specification is not None:
+                    context.style.literal(self._model.retry_interval)))
+            if self._model.plugin_specification is not None:
                 context.write('Plugin specification: {0}'.format(
-                    context.style.literal(self._template.plugin_specification.name)))
-            self._topology.dump(self._template.configurations, context, 'Configuration')
-            if self._template.function is not None:
-                context.write('Function: {0}'.format(context.style.literal(self._template.function)))
+                    context.style.literal(self._model.plugin_specification.name)))
+            self._topology.dump(self._model.configurations, context, 'Configuration')
+            if self._model.function is not None:
+                context.write('Function: {0}'.format(context.style.literal(self._model.function)))
 
     def coerce(self, **kwargs):
-        self._coerce(self._template.inputs,
-                     self._template.configurations,
+        self._coerce(self._model.inputs,
+                     self._model.configurations,
                      **kwargs)
 
     def instantiate(self, instance_cls):
         operation = instance_cls(
-            name=self._template.name,
-            description=utils.deepcopy_with_locators(self._template.description),
-            relationship_edge=self._template.relationship_edge,
-            implementation=self._template.implementation,
-            dependencies=self._template.dependencies,
-            executor=self._template.executor,
-            function=self._template.function,
-            max_attempts=self._template.max_attempts,
-            retry_interval=self._template.retry_interval,
-            operation_template=self._template)
-
-        if (self._template.plugin_specification is not None and
-                self._template.plugin_specification.enabled):
-            operation.plugin = self._template.plugin_specification.plugin
-
-        operation.inputs = self._topology.instantiate(self._template.inputs)
-        operation.configurations = self._topology.instantiate(self._template.configurations)
+            name=self._model.name,
+            description=utils.deepcopy_with_locators(self._model.description),
+            relationship_edge=self._model.relationship_edge,
+            implementation=self._model.implementation,
+            dependencies=self._model.dependencies,
+            executor=self._model.executor,
+            function=self._model.function,
+            max_attempts=self._model.max_attempts,
+            retry_interval=self._model.retry_interval,
+            operation_template=self._model)
+
+        if (self._model.plugin_specification is not None and
+                self._model.plugin_specification.enabled):
+            operation.plugin = self._model.plugin_specification.plugin
+
+        operation.inputs = self._topology.instantiate(self._model.inputs)
+        operation.configurations = self._topology.instantiate(self._model.configurations)
 
         return operation
 
     def validate(self):
-        self._validate(self._template.inputs,
-                       self._template.configurations)
+        self._validate(self._model.inputs,
+                       self._model.configurations)
 
 
 class PluginSpecification(common._TemplateHandler):

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/4ae0e5f9/aria/parser/consumption/modeling.py
----------------------------------------------------------------------
diff --git a/aria/parser/consumption/modeling.py b/aria/parser/consumption/modeling.py
index 2d4f271..5774630 100644
--- a/aria/parser/consumption/modeling.py
+++ b/aria/parser/consumption/modeling.py
@@ -77,7 +77,7 @@ class ServiceTemplate(ConsumerChain):
             raw = self.context.modeling.template_as_raw
             self.context.write(json_dumps(raw, indent=indent))
         else:
-            self.context.modeling.template.dump()
+            self.handler.dump(self.context.modeling.template)
 
 
 class Types(Consumer):
@@ -155,7 +155,7 @@ class SatisfyRequirements(Consumer):
     """
 
     def consume(self):
-        self.context.modeling.instance.satisfy_requirements()
+        self.handler.satisfy_requirements(self.context.modeling.instance)
 
 
 class ValidateCapabilities(Consumer):
@@ -164,7 +164,7 @@ class ValidateCapabilities(Consumer):
     """
 
     def consume(self):
-        self.context.modeling.instance.validate_capabilities()
+        self.handler.validate_capabilities(self.context.modeling.instance)
 
 
 class FindHosts(Consumer):
@@ -173,7 +173,7 @@ class FindHosts(Consumer):
     """
 
     def consume(self):
-        self.context.modeling.instance.find_hosts()
+        self.handler.find_hosts(self.context.modeling.instance)
 
 
 class ConfigureOperations(Consumer):
@@ -182,7 +182,7 @@ class ConfigureOperations(Consumer):
     """
 
     def consume(self):
-        self.context.modeling.instance.configure_operations()
+        self.handler.configure_operations(self.context.modeling.instance)
 
 
 class ServiceInstance(ConsumerChain):



Mime
View raw message