Repository: incubator-ariatosca
Updated Branches:
  refs/heads/ARIA-174-Refactor-instantiation-phase 0cdec5298 -> 679bc81c5


review fix 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/679bc81c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/679bc81c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/679bc81c

Branch: refs/heads/ARIA-174-Refactor-instantiation-phase
Commit: 679bc81c59d781adceb6930f203408c980cf859a
Parents: 0cdec52
Author: max-orlov <ma...@gigaspaces.com>
Authored: Wed Aug 9 14:52:34 2017 +0300
Committer: max-orlov <ma...@gigaspaces.com>
Committed: Wed Aug 9 14:52:34 2017 +0300

----------------------------------------------------------------------
 aria/core.py                                   |  6 +++---
 aria/modeling/service_template.py              | 11 ++++------
 aria/modeling/utils.py                         |  6 +++---
 aria/orchestrator/topology/common.py           |  3 +++
 aria/orchestrator/topology/instance_handler.py |  6 +++---
 aria/orchestrator/topology/template_handler.py | 16 ++++++--------
 aria/orchestrator/topology/topology.py         | 24 ++++++++++-----------
 aria/utils/console.py                          |  4 ----
 8 files changed, 35 insertions(+), 41 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/679bc81c/aria/core.py
----------------------------------------------------------------------
diff --git a/aria/core.py b/aria/core.py
index 83d5f7a..5a56cfc 100644
--- a/aria/core.py
+++ b/aria/core.py
@@ -76,7 +76,7 @@ class Core(object):
         with storage_session.no_autoflush:
             topology_ = topology.Topology()
             service = topology_.instantiate(
-                service_template, inputs=inputs, 
model_storage=self.model_storage)
+                service_template, inputs=inputs, 
model_storage=self.model_storage.plugins.list())
             topology_.coerce(service, report_issues=True)
 
             topology_.validate(service)
@@ -118,8 +118,8 @@ class Core(object):
     def _parse_service_template(service_template_path):
         context = consumption.ConsumptionContext()
         context.presentation.location = UriLocation(service_template_path)
-        # Most of the parser uses the topology package in order to manipulate 
teh models.
-        # However, here we use the ConsumerChain, but this should change in 
the future.
+        # Most of the parser uses the topology package in order to manipulate 
the models.
+        # However, here we use the Consumer, but this should change in the 
future.
         consumption.ConsumerChain(
             context,
             (

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/679bc81c/aria/modeling/service_template.py
----------------------------------------------------------------------
diff --git a/aria/modeling/service_template.py 
b/aria/modeling/service_template.py
index aaf88db..d988d21 100644
--- a/aria/modeling/service_template.py
+++ b/aria/modeling/service_template.py
@@ -546,10 +546,6 @@ class NodeTemplateBase(TemplateModelMixin):
             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 self.capability_templates.itervalues():
             if capability_template.type.role == 'scaling':
@@ -562,12 +558,13 @@ class NodeTemplateBase(TemplateModelMixin):
                     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)
 
         return scaling
 
+
 class GroupTemplateBase(TemplateModelMixin):
     """
     Template for creating a :class:`Group` instance, which is a typed logical 
container for zero or

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/679bc81c/aria/modeling/utils.py
----------------------------------------------------------------------
diff --git a/aria/modeling/utils.py b/aria/modeling/utils.py
index 9b64598..305020b 100644
--- a/aria/modeling/utils.py
+++ b/aria/modeling/utils.py
@@ -175,7 +175,7 @@ def fix_doc(cls):
     return cls
 
 
-def _get_class_from_sql_relationship(property):
-    class_ = property._sa_adapter.owner_state.class_
-    prop_name = property._sa_adapter.attr.key
+def _get_class_from_sql_relationship(field):
+    class_ = field._sa_adapter.owner_state.class_
+    prop_name = field._sa_adapter.attr.key
     return getattr(class_, prop_name).property.mapper.class_

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/679bc81c/aria/orchestrator/topology/common.py
----------------------------------------------------------------------
diff --git a/aria/orchestrator/topology/common.py 
b/aria/orchestrator/topology/common.py
index 02926ab..5124557 100644
--- a/aria/orchestrator/topology/common.py
+++ b/aria/orchestrator/topology/common.py
@@ -62,5 +62,8 @@ class InstanceHandlerBase(HandlerBase):
 
 
 class ActorHandlerBase(HandlerBase):
+    """
+    Base handler for any model which has (or contains a field which 
references) an operation
+    """
     def configure_operations(self):
         raise NotImplementedError

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/679bc81c/aria/orchestrator/topology/instance_handler.py
----------------------------------------------------------------------
diff --git a/aria/orchestrator/topology/instance_handler.py 
b/aria/orchestrator/topology/instance_handler.py
index 31e94e4..4194de7 100644
--- a/aria/orchestrator/topology/instance_handler.py
+++ b/aria/orchestrator/topology/instance_handler.py
@@ -550,7 +550,7 @@ class Substitution(common.InstanceHandlerBase):
         out_stream.write('Substitution:')
         with out_stream.indent():
             out_stream.write('Node type: {0}'.format(out_stream.type_style(
-                self._model.node_type.name)))
+                self._model.node.name)))
             self._topology.dump(self._model.mappings, out_stream, 
title='Mappings')
 
 
@@ -571,12 +571,12 @@ class SubstitutionMapping(common.InstanceHandlerBase):
         if self._model.capability is not None:
             out_stream.write('{0} -> {1}.{2}'.format(
                 out_stream.node_style(self._model.name),
-                out_stream.node_style(self._model.capability.node_style.name),
+                out_stream.node_style(self._model.capability.node.name),
                 out_stream.node_style(self._model.capability.name)))
         else:
             out_stream.write('{0} -> {1}.{2}'.format(
                 out_stream.node_style(self._model.name),
-                out_stream.node_style(self._model.node_style.name),
+                out_stream.node_style(self._model.node.name),
                 out_stream.node_style(self._model.requirement_template.name)))
 
 

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/679bc81c/aria/orchestrator/topology/template_handler.py
----------------------------------------------------------------------
diff --git a/aria/orchestrator/topology/template_handler.py 
b/aria/orchestrator/topology/template_handler.py
index eef3a18..cc3b73d 100644
--- a/aria/orchestrator/topology/template_handler.py
+++ b/aria/orchestrator/topology/template_handler.py
@@ -47,7 +47,7 @@ class ServiceTemplate(common.TemplateHandlerBase):
                      self._model.workflow_templates,
                      **kwargs)
 
-    def instantiate(self, instance_cls, inputs=None, model_storage=None):      
                     # pylint: disable=arguments-differ
+    def instantiate(self, instance_cls, inputs=None, plugins=None):            
                     # pylint: disable=arguments-differ
         now = datetime.now()
 
         modeling_utils.validate_no_undeclared_inputs(
@@ -64,9 +64,8 @@ class ServiceTemplate(common.TemplateHandlerBase):
         )
 
         for plugin_specification in 
self._model.plugin_specifications.itervalues():
-            if plugin_specification.enabled and model_storage:
-                if self._resolve_plugin_specification(plugin_specification,
-                                                      
model_storage.plugin.list()):
+            if plugin_specification.enabled and plugins:
+                if self._resolve_plugin_specification(plugin_specification, 
plugins):
                     plugin = plugin_specification.plugin
                     service.plugins[plugin.name] = plugin
                 else:
@@ -134,7 +133,7 @@ class ServiceTemplate(common.TemplateHandlerBase):
             self._model.inputs,
             self._model.outputs,
             self._model.workflow_templates,
-            self._model.node_types,
+            self._model.node,
             self._model.group_types,
             self._model.policy_types,
             self._model.relationship_types,
@@ -431,15 +430,14 @@ class SubstitutionTemplate(common.TemplateHandlerBase):
         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)))
+                self._model.node.name)))
             self._topology.dump(self._model.mappings, out_stream, 
title='Mappings')
 
     def coerce(self, **kwargs):
         self._topology.coerce(self._model.mappings, **kwargs)
 
     def instantiate(self, instance_cls, **_):
-        return instance_cls(node_type=self._model.node_type,
-                            substitution_template=self._model)
+        return instance_cls(node_type=self._model.node, 
substitution_template=self._model)
 
     def validate(self, **kwargs):
         self._topology.validate(self._model.mappings, **kwargs)
@@ -594,7 +592,7 @@ class OperationTemplate(common.TemplateHandlerBase):
                        **kwargs)
 
 
-class PluginSpecification(common.TemplateHandlerBase):
+class PluginSpecification(common.HandlerBase):
     def validate(self, **kwargs):
         pass
 

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/679bc81c/aria/orchestrator/topology/topology.py
----------------------------------------------------------------------
diff --git a/aria/orchestrator/topology/topology.py 
b/aria/orchestrator/topology/topology.py
index 8cb220f..eeb413f 100644
--- a/aria/orchestrator/topology/topology.py
+++ b/aria/orchestrator/topology/topology.py
@@ -51,17 +51,17 @@ class Topology(issue.ReporterMixin):
 
     def __init__(self, *args, **kwargs):
         super(Topology, self).__init__(*args, **kwargs)
-        self._models_to_handlers = dict(self._init_handlers(instance_handler),
-                                        
**self._init_handlers(template_handler))
+        self._model_cls_to_handler = 
dict(self._init_handlers(instance_handler),
+                                          
**self._init_handlers(template_handler))
 
     @staticmethod
     def _init_handlers(module_):
         """
-        Register handlers from a module to the models
+        Register handlers from the handler module to the models
 
         :param module_: The module to look for handlers
-        :return: a dict where key is the models class, and the value is the 
handler class
-        associated with it from the provided modukle
+        :return: a dict where the key is the models class, and the value is 
the handler class
+        associated with it from the provided module
         """
         handlers = {}
         for attribute_name in dir(module_):
@@ -86,7 +86,7 @@ class Topology(issue.ReporterMixin):
         elif isinstance(model, list):
             return list(self.instantiate(value, **kwargs) for value in model)
         elif model is not None:
-            _handler = self._models_to_handlers[model.__class__]
+            _handler = self._model_cls_to_handler[model.__class__]
             model_instance_cls = self._init_map[model.__class__]
             return _handler(self, model).instantiate(model_instance_cls, 
**kwargs)
 
@@ -96,7 +96,7 @@ class Topology(issue.ReporterMixin):
         elif isinstance(model, list):
             return all(self.validate(value, **kwargs) for value in model)
         elif model is not None:
-            _handler = self._models_to_handlers[model.__class__]
+            _handler = self._model_cls_to_handler[model.__class__]
             return _handler(self, model).validate(**kwargs)
 
     def dump(self, model, out_stream=None, title=None, **kwargs):
@@ -118,7 +118,7 @@ class Topology(issue.ReporterMixin):
                 self.dump(value, out_stream=out_stream, **kwargs)
 
         elif model is not None:
-            _handler = self._models_to_handlers[model.__class__]
+            _handler = self._model_cls_to_handler[model.__class__]
             _handler(self, model).dump(out_stream=out_stream, **kwargs)
 
         return out_stream
@@ -156,7 +156,7 @@ class Topology(issue.ReporterMixin):
         elif isinstance(model, list):
             return all(self.coerce(value, **kwargs) for value in model)
         elif model is not None:
-            _handler = self._models_to_handlers[model.__class__]
+            _handler = self._model_cls_to_handler[model.__class__]
             return _handler(self, model).coerce(**kwargs)
 
     def dump_types(self, service_template, out_stream=None):
@@ -177,7 +177,7 @@ class Topology(issue.ReporterMixin):
         elif isinstance(model, list):
             return all(self.satisfy_requirements(value, **kwargs) for value in 
model)
         elif model is not None:
-            _handler = self._models_to_handlers[model.__class__]
+            _handler = self._model_cls_to_handler[model.__class__]
             return _handler(self, model).satisfy_requirements(**kwargs)
 
     def validate_capabilities(self, model, **kwargs):
@@ -186,7 +186,7 @@ class Topology(issue.ReporterMixin):
         elif isinstance(model, list):
             return all(self.validate_capabilities(value, **kwargs) for value 
in model)
         elif model is not None:
-            _handler = self._models_to_handlers[model.__class__]
+            _handler = self._model_cls_to_handler[model.__class__]
             return _handler(self, model).validate_capabilities(**kwargs)
 
     def _find_host(self, node):
@@ -219,5 +219,5 @@ class Topology(issue.ReporterMixin):
         elif isinstance(model, list):
             return all(self.configure_operations(value, **kwargs) for value in 
model)
         elif model is not None:
-            _handler = self._models_to_handlers[model.__class__]
+            _handler = self._model_cls_to_handler[model.__class__]
             return _handler(self, model).configure_operations(**kwargs)

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/679bc81c/aria/utils/console.py
----------------------------------------------------------------------
diff --git a/aria/utils/console.py b/aria/utils/console.py
index 0d379e1..81e8cf8 100644
--- a/aria/utils/console.py
+++ b/aria/utils/console.py
@@ -47,10 +47,6 @@ class TopologyStylizer(object):
         self._indentation -= indentation
 
     @staticmethod
-    def section_style(value):
-        return Colored.cyan(value, bold=True)
-
-    @staticmethod
     def type_style(value):
         return Colored.blue(value, bold=True)
 

Reply via email to