[GitHub] incubator-ariatosca pull request #194: ARIA-353 Add node template directives

2017-08-30 Thread AviaE
GitHub user AviaE opened a pull request:

https://github.com/apache/incubator-ariatosca/pull/194

ARIA-353 Add node template directives

The directives field already existed in the presentation level, but it
needed to be added to the node template model.

You can merge this pull request into a Git repository by running:

$ git pull https://github.com/apache/incubator-ariatosca 
ARIA-353-substitution-directive

Alternatively you can review and apply these changes as the patch at:

https://github.com/apache/incubator-ariatosca/pull/194.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

This closes #194


commit 969149bd98a9f2b60b98b2d0f1e64392d7c9f2da
Author: Avia Efrat <a...@gigaspaces.com>
Date:   2017-08-30T14:54:46Z

ARIA-353 Add node template directives

The directives field already existed in the presentation level, but it
needed to be added to the node template model.




---
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.
---


[GitHub] incubator-ariatosca pull request #193: ARIA-348 Validate substitution_mappin...

2017-08-20 Thread AviaE
GitHub user AviaE opened a pull request:

https://github.com/apache/incubator-ariatosca/pull/193

ARIA-348 Validate substitution_mapping field



You can merge this pull request into a Git repository by running:

$ git pull https://github.com/apache/incubator-ariatosca 
ARIA-348-validate-substitution-mapping

Alternatively you can review and apply these changes as the patch at:

https://github.com/apache/incubator-ariatosca/pull/193.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

This closes #193


commit eca048c16aee89fde53b557ce17af72de46669fc
Author: Avia Efrat <a...@gigaspaces.com>
Date:   2017-08-16T15:54:57Z

ARIA-348 Validate substitution_mapping field




---
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.
---


[GitHub] incubator-ariatosca pull request #189: ARIA-174 Refactor instantiation phase

2017-08-09 Thread AviaE
Github user AviaE commented on a diff in the pull request:

https://github.com/apache/incubator-ariatosca/pull/189#discussion_r132168198
  
--- Diff: 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
--- End diff --

a handler


---
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.
---


[GitHub] incubator-ariatosca pull request #189: ARIA-174 Refactor instantiation phase

2017-08-09 Thread AviaE
Github user AviaE commented on a diff in the pull request:

https://github.com/apache/incubator-ariatosca/pull/189#discussion_r132167947
  
--- Diff: aria/orchestrator/topology/template_handler.py ---
@@ -47,7 +47,7 @@ def coerce(self, **kwargs):
  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
--- End diff --

remove the extra whitespaces.


---
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.
---


[GitHub] incubator-ariatosca pull request #189: ARIA-174 Refactor instantiation phase

2017-08-09 Thread AviaE
Github user AviaE commented on a diff in the pull request:

https://github.com/apache/incubator-ariatosca/pull/189#discussion_r132167856
  
--- Diff: aria/core.py ---
@@ -118,8 +118,8 @@ def delete_service(self, service_id, force=False):
 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.
--- End diff --

Consumer mechanism


---
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.
---


[GitHub] incubator-ariatosca pull request #189: ARIA-174 Refactor instantiation phase

2017-08-09 Thread AviaE
Github user AviaE commented on a diff in the pull request:

https://github.com/apache/incubator-ariatosca/pull/189#discussion_r132123698
  
--- Diff: aria/modeling/utils.py ---
@@ -175,7 +175,7 @@ def init(*args, **kwargs):
 return cls
 
 
-def get_class_from_relationship(property):
+def _get_class_from_sql_relationship(property):
--- End diff --

a better name than property, which could be misleading. Maybe `field`.


---
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.
---


[GitHub] incubator-ariatosca pull request #189: ARIA-174 Refactor instantiation phase

2017-08-09 Thread AviaE
Github user AviaE commented on a diff in the pull request:

https://github.com/apache/incubator-ariatosca/pull/189#discussion_r132123290
  
--- Diff: aria/modeling/service_template.py ---
@@ -530,6 +530,43 @@ def _next_name(self):
 
 return '{name}_{index}'.format(name=self.name, 
index=self._next_index)
 
+@property
+def scaling(self):
+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 self.capability_templates.itervalues():
+if capability_template.type.role == 'scaling':
+extract_properties(capability_template.properties)
+
+# From service scaling policies
+for policy_template in 
self.service_template.policy_templates.itervalues():
+if policy_template.type.role == 'scaling':
+if policy_template.is_for_node_template(self.name):
+extract_properties(policy_template.properties)
+
+# Defaults
+default_property('min_instances', 0)
--- End diff --

should be `setdefault`


---
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.
---


[GitHub] incubator-ariatosca pull request #189: ARIA-174 Refactor instantiation phase

2017-08-09 Thread AviaE
Github user AviaE commented on a diff in the pull request:

https://github.com/apache/incubator-ariatosca/pull/189#discussion_r132127992
  
--- Diff: aria/orchestrator/topology/instance_handler.py ---
@@ -527,78 +539,82 @@ def satisfy_requirements(self):
for node in self._model.nodes.values())
 
 
-class Substitution(common._InstanceHandlerMixin):
+class Substitution(common.InstanceHandlerBase):
 def coerce(self, **kwargs):
 self._topology.coerce(self._model.mappings, **kwargs)
 
 def validate(self, **kwargs):
-self._topology.validate(self._model.mappings)
+self._topology.validate(self._model.mappings, **kwargs)
 
 def dump(self, out_stream):
 out_stream.write('Substitution:')
 with out_stream.indent():
-out_stream.write('Node type: 
{0}'.format(out_stream.type(self._model.node_type.name)))
-self._topology.dump(self._model.mappings, out_stream, 
'Mappings')
+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._InstanceHandlerMixin):
+class SubstitutionMapping(common.InstanceHandlerBase):
 
-def validate(self, **kwargs):
+def coerce(self, **kwargs):
+pass
+
+def validate(self, **_):
 if (self._model.capability is None) and 
(self._model.requirement_template is None):
 self._topology.report(
 'mapping "{0}" refers to neither capability nor a 
requirement'
 ' in node: {1}'.format(
-self._model.name, 
formatting.safe_repr(self._model.node.name)),
+self._model.name, 
formatting.safe_repr(self._model.node_style.name)),
 level=self._topology.Issue.BETWEEN_TYPES)
 
 def dump(self, out_stream):
 if self._model.capability is not None:
 out_stream.write('{0} -> {1}.{2}'.format(
-out_stream.node(self._model.name),
-out_stream.node(self._model.capability.node.name),
-out_stream.node(self._model.capability.name)))
+out_stream.node_style(self._model.name),
+
out_stream.node_style(self._model.capability.node_style.name),
+out_stream.node_style(self._model.capability.name)))
 else:
 out_stream.write('{0} -> {1}.{2}'.format(
-out_stream.node(self._model.name),
-out_stream.node(self._model.node.name),
-out_stream.node(self._model.requirement_template.name)))
+out_stream.node_style(self._model.name),
+out_stream.node_style(self._model.node_style.name),
+
out_stream.node_style(self._model.requirement_template.name)))
 
 
-class Metadata(common._InstanceHandlerMixin):
+class Metadata(common.InstanceHandlerBase):
 
 def dump(self, out_stream):
 out_stream.write('{0}: {1}'.format(
-out_stream.property(self._topology.name),
-out_stream.literal(self._topology.value)))
+out_stream.property_style(self._model.name),
+out_stream.literal_style(self._model.value)))
 
-def coerce(self):
+def coerce(self, **_):
 pass
 
-def instantiate(self, instance_cls, **kwargs):
--- End diff --

Rethink about the `**kwargs` here. Considering how it's in all the other 
`instantiate`.


---
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.
---


[GitHub] incubator-ariatosca pull request #189: ARIA-174 Refactor instantiation phase

2017-08-09 Thread AviaE
Github user AviaE commented on a diff in the pull request:

https://github.com/apache/incubator-ariatosca/pull/189#discussion_r132127314
  
--- Diff: aria/orchestrator/topology/instance_handler.py ---
@@ -527,78 +539,82 @@ def satisfy_requirements(self):
for node in self._model.nodes.values())
 
 
-class Substitution(common._InstanceHandlerMixin):
+class Substitution(common.InstanceHandlerBase):
 def coerce(self, **kwargs):
 self._topology.coerce(self._model.mappings, **kwargs)
 
 def validate(self, **kwargs):
-self._topology.validate(self._model.mappings)
+self._topology.validate(self._model.mappings, **kwargs)
 
 def dump(self, out_stream):
 out_stream.write('Substitution:')
 with out_stream.indent():
-out_stream.write('Node type: 
{0}'.format(out_stream.type(self._model.node_type.name)))
-self._topology.dump(self._model.mappings, out_stream, 
'Mappings')
+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._InstanceHandlerMixin):
+class SubstitutionMapping(common.InstanceHandlerBase):
 
-def validate(self, **kwargs):
+def coerce(self, **kwargs):
+pass
+
+def validate(self, **_):
 if (self._model.capability is None) and 
(self._model.requirement_template is None):
 self._topology.report(
 'mapping "{0}" refers to neither capability nor a 
requirement'
 ' in node: {1}'.format(
-self._model.name, 
formatting.safe_repr(self._model.node.name)),
+self._model.name, 
formatting.safe_repr(self._model.node_style.name)),
 level=self._topology.Issue.BETWEEN_TYPES)
 
 def dump(self, out_stream):
 if self._model.capability is not None:
 out_stream.write('{0} -> {1}.{2}'.format(
-out_stream.node(self._model.name),
-out_stream.node(self._model.capability.node.name),
-out_stream.node(self._model.capability.name)))
+out_stream.node_style(self._model.name),
+
out_stream.node_style(self._model.capability.node_style.name),
+out_stream.node_style(self._model.capability.name)))
 else:
 out_stream.write('{0} -> {1}.{2}'.format(
-out_stream.node(self._model.name),
-out_stream.node(self._model.node.name),
-out_stream.node(self._model.requirement_template.name)))
+out_stream.node_style(self._model.name),
+out_stream.node_style(self._model.node_style.name),
--- End diff --

Go over all the `node_style`s.


---
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.
---


[GitHub] incubator-ariatosca pull request #189: ARIA-174 Refactor instantiation phase

2017-08-09 Thread AviaE
Github user AviaE commented on a diff in the pull request:

https://github.com/apache/incubator-ariatosca/pull/189#discussion_r131950842
  
--- Diff: aria/core.py ---
@@ -117,8 +118,8 @@ def delete_service(self, service_id, force=False):
 def _parse_service_template(service_template_path):
 context = consumption.ConsumptionContext()
 context.presentation.location = UriLocation(service_template_path)
-# TODO: this is the last place which uses the consumer chains 
(since read is a proper Parser
-# todo..based consumer, it has no place in the topology package).
+# Most of the parser uses the topology package in order to 
manipulate teh models.
--- End diff --

teh


---
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.
---


[GitHub] incubator-ariatosca pull request #189: ARIA-174 Refactor instantiation phase

2017-08-09 Thread AviaE
Github user AviaE commented on a diff in the pull request:

https://github.com/apache/incubator-ariatosca/pull/189#discussion_r132127179
  
--- Diff: aria/orchestrator/topology/instance_handler.py ---
@@ -527,78 +539,82 @@ def satisfy_requirements(self):
for node in self._model.nodes.values())
 
 
-class Substitution(common._InstanceHandlerMixin):
+class Substitution(common.InstanceHandlerBase):
 def coerce(self, **kwargs):
 self._topology.coerce(self._model.mappings, **kwargs)
 
 def validate(self, **kwargs):
-self._topology.validate(self._model.mappings)
+self._topology.validate(self._model.mappings, **kwargs)
 
 def dump(self, out_stream):
 out_stream.write('Substitution:')
 with out_stream.indent():
-out_stream.write('Node type: 
{0}'.format(out_stream.type(self._model.node_type.name)))
-self._topology.dump(self._model.mappings, out_stream, 
'Mappings')
+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._InstanceHandlerMixin):
+class SubstitutionMapping(common.InstanceHandlerBase):
 
-def validate(self, **kwargs):
+def coerce(self, **kwargs):
+pass
+
+def validate(self, **_):
 if (self._model.capability is None) and 
(self._model.requirement_template is None):
 self._topology.report(
 'mapping "{0}" refers to neither capability nor a 
requirement'
 ' in node: {1}'.format(
-self._model.name, 
formatting.safe_repr(self._model.node.name)),
+self._model.name, 
formatting.safe_repr(self._model.node_style.name)),
 level=self._topology.Issue.BETWEEN_TYPES)
 
 def dump(self, out_stream):
 if self._model.capability is not None:
 out_stream.write('{0} -> {1}.{2}'.format(
-out_stream.node(self._model.name),
-out_stream.node(self._model.capability.node.name),
-out_stream.node(self._model.capability.name)))
+out_stream.node_style(self._model.name),
+
out_stream.node_style(self._model.capability.node_style.name),
--- End diff --

The second `node_style` should be just `node`.


---
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.
---


[GitHub] incubator-ariatosca pull request #189: ARIA-174 Refactor instantiation phase

2017-08-09 Thread AviaE
Github user AviaE commented on a diff in the pull request:

https://github.com/apache/incubator-ariatosca/pull/189#discussion_r132122736
  
--- Diff: aria/core.py ---
@@ -117,8 +118,8 @@ def delete_service(self, service_id, force=False):
 def _parse_service_template(service_template_path):
 context = consumption.ConsumptionContext()
 context.presentation.location = UriLocation(service_template_path)
-# TODO: this is the last place which uses the consumer chains 
(since read is a proper Parser
-# todo..based consumer, it has no place in the topology package).
+# 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.
--- End diff --

the thing is the Consumers mechanism in general, not the use of the 
ConsumerChain object.


---
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.
---


[GitHub] incubator-ariatosca pull request #189: ARIA-174 Refactor instantiation phase

2017-08-09 Thread AviaE
Github user AviaE commented on a diff in the pull request:

https://github.com/apache/incubator-ariatosca/pull/189#discussion_r132136296
  
--- Diff: aria/orchestrator/topology/template_handler.py ---
@@ -584,13 +588,20 @@ def instantiate(self, instance_cls):
 
 return operation
 
-def validate(self):
+def validate(self, **kwargs):
 self._validate(self._model.inputs,
-   self._model.configurations)
+   self._model.configurations,
+   **kwargs)
+
+
+class PluginSpecification(common.TemplateHandlerBase):
--- End diff --

Consider inheriting from `HandlerBase`, since `PluginSpecification` isn't 
exactly a template.


---
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.
---


[GitHub] incubator-ariatosca pull request #189: ARIA-174 Refactor instantiation phase

2017-08-09 Thread AviaE
Github user AviaE commented on a diff in the pull request:

https://github.com/apache/incubator-ariatosca/pull/189#discussion_r132127229
  
--- Diff: aria/orchestrator/topology/instance_handler.py ---
@@ -527,78 +539,82 @@ def satisfy_requirements(self):
for node in self._model.nodes.values())
 
 
-class Substitution(common._InstanceHandlerMixin):
+class Substitution(common.InstanceHandlerBase):
 def coerce(self, **kwargs):
 self._topology.coerce(self._model.mappings, **kwargs)
 
 def validate(self, **kwargs):
-self._topology.validate(self._model.mappings)
+self._topology.validate(self._model.mappings, **kwargs)
 
 def dump(self, out_stream):
 out_stream.write('Substitution:')
 with out_stream.indent():
-out_stream.write('Node type: 
{0}'.format(out_stream.type(self._model.node_type.name)))
-self._topology.dump(self._model.mappings, out_stream, 
'Mappings')
+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._InstanceHandlerMixin):
+class SubstitutionMapping(common.InstanceHandlerBase):
 
-def validate(self, **kwargs):
+def coerce(self, **kwargs):
+pass
+
+def validate(self, **_):
 if (self._model.capability is None) and 
(self._model.requirement_template is None):
 self._topology.report(
 'mapping "{0}" refers to neither capability nor a 
requirement'
 ' in node: {1}'.format(
-self._model.name, 
formatting.safe_repr(self._model.node.name)),
+self._model.name, 
formatting.safe_repr(self._model.node_style.name)),
--- End diff --

`node_style` should be just `node`.


---
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.
---


[GitHub] incubator-ariatosca pull request #189: ARIA-174 Refactor instantiation phase

2017-08-09 Thread AviaE
Github user AviaE commented on a diff in the pull request:

https://github.com/apache/incubator-ariatosca/pull/189#discussion_r132137184
  
--- Diff: aria/orchestrator/topology/topology.py ---
@@ -50,28 +49,33 @@ class Topology(issue.Reporter):
 models.Type: models.Type
 }
 
-def __init__(self, model_storage=None, *args, **kwargs):
-# TODO: model storage is required only for the list of plugins, 
can we get it
-# somewhere else?
+def __init__(self, *args, **kwargs):
 super(Topology, self).__init__(*args, **kwargs)
-self._model_storage = model_storage
-self._handlers = dict(self._init_handlers(instance_handler),
-  **self._init_handlers(template_handler))
+self._models_to_handlers = 
dict(self._init_handlers(instance_handler),
+
**self._init_handlers(template_handler))
 
 @staticmethod
 def _init_handlers(module_):
+"""
+Register handlers from a module to the models
--- End diff --

`from a module` --> `from a handler module`.


---
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.
---


[GitHub] incubator-ariatosca pull request #189: ARIA-174 Refactor instantiation phase

2017-08-09 Thread AviaE
Github user AviaE commented on a diff in the pull request:

https://github.com/apache/incubator-ariatosca/pull/189#discussion_r132137742
  
--- Diff: aria/orchestrator/topology/topology.py ---
@@ -50,28 +49,33 @@ class Topology(issue.Reporter):
 models.Type: models.Type
 }
 
-def __init__(self, model_storage=None, *args, **kwargs):
-# TODO: model storage is required only for the list of plugins, 
can we get it
-# somewhere else?
+def __init__(self, *args, **kwargs):
 super(Topology, self).__init__(*args, **kwargs)
-self._model_storage = model_storage
-self._handlers = dict(self._init_handlers(instance_handler),
-  **self._init_handlers(template_handler))
+self._models_to_handlers = 
dict(self._init_handlers(instance_handler),
+
**self._init_handlers(template_handler))
 
 @staticmethod
 def _init_handlers(module_):
+"""
+Register handlers from a 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
--- End diff --

modukle --> module.


---
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.
---


[GitHub] incubator-ariatosca pull request #189: ARIA-174 Refactor instantiation phase

2017-08-09 Thread AviaE
Github user AviaE commented on a diff in the pull request:

https://github.com/apache/incubator-ariatosca/pull/189#discussion_r132137988
  
--- Diff: aria/orchestrator/topology/topology.py ---
@@ -50,28 +49,33 @@ class Topology(issue.Reporter):
 models.Type: models.Type
 }
 
-def __init__(self, model_storage=None, *args, **kwargs):
-# TODO: model storage is required only for the list of plugins, 
can we get it
-# somewhere else?
+def __init__(self, *args, **kwargs):
 super(Topology, self).__init__(*args, **kwargs)
-self._model_storage = model_storage
-self._handlers = dict(self._init_handlers(instance_handler),
-  **self._init_handlers(template_handler))
+self._models_to_handlers = 
dict(self._init_handlers(instance_handler),
+
**self._init_handlers(template_handler))
 
 @staticmethod
 def _init_handlers(module_):
+"""
+Register handlers from a 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
--- End diff --

`key` --> `the key`, `models` --> `model's`


---
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.
---


[GitHub] incubator-ariatosca pull request #189: ARIA-174 Refactor instantiation phase

2017-08-09 Thread AviaE
Github user AviaE commented on a diff in the pull request:

https://github.com/apache/incubator-ariatosca/pull/189#discussion_r132140607
  
--- Diff: aria/utils/console.py ---
@@ -31,51 +31,51 @@
 
 
 class TopologyStylizer(object):
-def __init__(self, indentation=2):
+def __init__(self, indentation=0):
 self._str = StringIO()
 self._indentation = indentation
 
-def write(self, str_):
-puts(str_, stream=self._str)
+def write(self, string):
+self._str.write(' ' * self._indentation)
+self._str.write(string)
+self._str.write(os.linesep)
 
 @contextmanager
-def indent(self, indentation=None):
-with indent(indentation or self._indentation):
-yield
+def indent(self, indentation=2):
+self._indentation += indentation
+yield
+self._indentation -= indentation
 
 @staticmethod
-def section(value):
+def section_style(value):
--- End diff --

Is this even used?


---
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.
---


[GitHub] incubator-ariatosca pull request #189: ARIA-174 Refactor instantiation phase

2017-08-03 Thread AviaE
Github user AviaE commented on a diff in the pull request:

https://github.com/apache/incubator-ariatosca/pull/189#discussion_r131084313
  
--- Diff: aria/orchestrator/topology/instance_handler.py ---
@@ -0,0 +1,644 @@
+# 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 ... parser.modeling import context
+from ... modeling import models
+from ... utils import formatting
+from .. import execution_plugin
+from .. import decorators
+from . import common
+
+
+class Artifact(common._InstanceHandlerMixin):
+
+def coerce(self, **kwargs):
+self._topology.coerce(self._model.properties, **kwargs)
+
+def validate(self, **kwargs):
+self._topology.validate(self._model.properties)
+
+def dump(self, out_stream):
+with out_stream.indent():
+out_stream.write(out_stream.node(self._model.name))
+out_stream.write(out_stream.meta(self._model.description))
+with out_stream.indent():
+out_stream.write('Artifact type: 
{0}'.format(out_stream.type(
+self._model.type.name)))
+out_stream.write('Source path: {0}'.format(
+out_stream.literal(self._model.source_path)))
+if self._model.target_path is not None:
+out_stream.write('Target path: {0}'.format(
+out_stream.literal(self._model.target_path)))
+if self._model.repository_url is not None:
+out_stream.write('Repository URL: {0}'.format(
+out_stream.literal(self._model.repository_url)))
+if self._model.repository_credential:
+out_stream.write('Repository credential: {0}'.format(
+
out_stream.literal(self._model.repository_credential)))
+self._topology.dump(self._model.properties, out_stream, 
'Properties')
+
+
+class Capability(common._InstanceHandlerMixin):
+def coerce(self, **kwargs):
+self._topology.coerce(self._model.properties, **kwargs)
+
+def validate(self, **kwargs):
+self._topology.validate(self._model.properties)
+
+def dump(self, out_stream):
+out_stream.write(out_stream.node(self._model.name))
+with out_stream.indent():
+out_stream.write('Type: 
{0}'.format(out_stream.type(self._model.type.name)))
+out_stream.write('Occurrences: {0:d} ({1:d}{2})'.format(
+self._model.occurrences,
+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'))
+self._topology.dump(self._model.properties, out_stream, 
'Properties')
+
+
+class Group(common._OperatorHolderHandlerMixin):
+
+def coerce(self, **kwargs):
+self._coerce(self._model.properties, self._model.interfaces, 
**kwargs)
+
+def validate(self, **kwargs):
+self._validate(self._model.properties,
+   self._model.interfaces)
+
+def dump(self, out_stream):
+out_stream.write('Group: 
{0}'.format(out_stream.node(self._model.name)))
+with out_stream.indent():
+out_stream.write('Type: 
{0}'.format(out_stream.type(self._model.type.name)))
+self._topology.dump(self._model.properties, out_stream, 
'Properties')
+self._topology.dump(self._model.interfaces, out_stream, 
'Interfaces')
+if self._model.nodes:
+out_stream.write('Member nodes:')
+with out_stream.indent():
+for node in self._model.nodes:
+out_stream.write(out_stream.node(node.name))
+
+def configure_operations(self):
+for interface in self._model.interfaces.values():
 

[GitHub] incubator-ariatosca pull request #189: ARIA-174 Refactor instantiation phase

2017-08-03 Thread AviaE
Github user AviaE commented on a diff in the pull request:

https://github.com/apache/incubator-ariatosca/pull/189#discussion_r131086718
  
--- Diff: aria/orchestrator/topology/template_handler.py ---
@@ -0,0 +1,597 @@
+# 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 datetime import datetime
+
+from ...utils import formatting
+from ...modeling import utils as modeling_utils
+from . import utils, common
+
+
+class ServiceTemplate(common._TemplateHandlerMixin):
+def dump(self, out_stream):
+if self._model.description is not None:
+out_stream.write(out_stream.meta(self._model.description))
+self._topology.dump(self._model.meta_data, out_stream, 'Metadata')
+self._topology.dump(self._model.node_templates, out_stream)
+self._topology.dump(self._model.group_templates, out_stream)
+self._topology.dump(self._model.policy_templates, out_stream)
+self._topology.dump(self._model.substitution_template, out_stream)
+self._topology.dump(self._model.inputs, out_stream, 'Inputs')
+self._topology.dump(self._model.outputs, out_stream, 'Outputs')
+self._topology.dump(self._model.workflow_templates, out_stream, 
'Workflow templates')
+
+def coerce(self, **kwargs):
+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):  
 # pylint: disable=arguments-differ
+now = datetime.now()
+
+modeling_utils.validate_no_undeclared_inputs(
+declared_inputs=self._model.inputs, supplied_inputs=inputs or 
{})
+modeling_utils.validate_required_inputs_are_supplied(
+declared_inputs=self._model.inputs, supplied_inputs=inputs or 
{})
+
+service = instance_cls(
+created_at=now,
+updated_at=now,
+
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._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()):
+plugin = plugin_specification.plugin
+service.plugins[plugin.name] = plugin
+else:
+self._topology.report('specified plugin not found: 
{0}'.format(
+plugin_specification.name), 
level=self._topology.Issue.EXTERNAL)
+service.meta_data = 
self._topology.instantiate(self._model.meta_data)
+
+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._model.group_templates)
+service.policies = 
self._topology.instantiate(self._model.policy_templates)
+service.workflows = 
self._topology.instantiate(self._model.workflow_templates)
+service.substitution = 
self._topology.instantiate(self._model.substitution_template)
+service.outputs = self._topology.instantiate

[GitHub] incubator-ariatosca pull request #189: ARIA-174 Refactor instantiation phase

2017-08-03 Thread AviaE
Github user AviaE commented on a diff in the pull request:

https://github.com/apache/incubator-ariatosca/pull/189#discussion_r131095491
  
--- Diff: aria/orchestrator/topology/utils.py ---
@@ -0,0 +1,67 @@
+# 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 copy import deepcopy
+
+from ...utils.versions import VersionString
+
+
+def deepcopy_with_locators(value):
+"""
+Like :func:`deepcopy`, but also copies over locators.
+"""
+
+res = deepcopy(value)
+copy_locators(res, value)
+return res
+
+
+def copy_locators(target, source):
+"""
+Copies over ``_locator`` for all elements, recursively.
+
+Assumes that target and source have exactly the same list/dict 
structure.
+"""
+
+locator = getattr(source, '_locator', None)
+if locator is not None:
+try:
+setattr(target, '_locator', locator)
+except AttributeError:
+pass
+
+if isinstance(target, list) and isinstance(source, list):
+for i, _ in enumerate(target):
+copy_locators(target[i], source[i])
+elif isinstance(target, dict) and isinstance(source, dict):
+for k, v in target.items():
+copy_locators(v, source[k])
+
+
+def resolve_plugin_specification(plugin_specification, plugins):
--- End diff --

Maybe in the Service Template Handler.


---
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.
---


[GitHub] incubator-ariatosca pull request #189: ARIA-174 Refactor instantiation phase

2017-08-03 Thread AviaE
Github user AviaE commented on a diff in the pull request:

https://github.com/apache/incubator-ariatosca/pull/189#discussion_r131085804
  
--- Diff: aria/orchestrator/topology/template_handler.py ---
@@ -0,0 +1,597 @@
+# 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 datetime import datetime
+
+from ...utils import formatting
+from ...modeling import utils as modeling_utils
+from . import utils, common
+
+
+class ServiceTemplate(common._TemplateHandlerMixin):
+def dump(self, out_stream):
+if self._model.description is not None:
+out_stream.write(out_stream.meta(self._model.description))
+self._topology.dump(self._model.meta_data, out_stream, 'Metadata')
+self._topology.dump(self._model.node_templates, out_stream)
+self._topology.dump(self._model.group_templates, out_stream)
+self._topology.dump(self._model.policy_templates, out_stream)
+self._topology.dump(self._model.substitution_template, out_stream)
+self._topology.dump(self._model.inputs, out_stream, 'Inputs')
+self._topology.dump(self._model.outputs, out_stream, 'Outputs')
+self._topology.dump(self._model.workflow_templates, out_stream, 
'Workflow templates')
+
+def coerce(self, **kwargs):
+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):  
 # pylint: disable=arguments-differ
+now = datetime.now()
+
+modeling_utils.validate_no_undeclared_inputs(
+declared_inputs=self._model.inputs, supplied_inputs=inputs or 
{})
+modeling_utils.validate_required_inputs_are_supplied(
+declared_inputs=self._model.inputs, supplied_inputs=inputs or 
{})
+
+service = instance_cls(
+created_at=now,
+updated_at=now,
+
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._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()):
+plugin = plugin_specification.plugin
+service.plugins[plugin.name] = plugin
+else:
+self._topology.report('specified plugin not found: 
{0}'.format(
+plugin_specification.name), 
level=self._topology.Issue.EXTERNAL)
+service.meta_data = 
self._topology.instantiate(self._model.meta_data)
+
+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._model.group_templates)
+service.policies = 
self._topology.instantiate(self._model.policy_templates)
+service.workflows = 
self._topology.instantiate(self._model.workflow_templates)
+service.substitution = 
self._topology.instantiate(self._model.substitution_template)
+service.outputs = self._topology.instantiate

[GitHub] incubator-ariatosca pull request #189: ARIA-174 Refactor instantiation phase

2017-08-02 Thread AviaE
Github user AviaE commented on a diff in the pull request:

https://github.com/apache/incubator-ariatosca/pull/189#discussion_r130870769
  
--- Diff: aria/utils/console.py ---
@@ -19,19 +19,68 @@
 
 import os
 import sys
+from StringIO import StringIO
 
 from contextlib import contextmanager
 
-from .formatting import safe_str
 from ..cli import color
+from . import formatting
 
 
 _indent_string = ''
 
 
+class TopologyStylizer(object):
+def __init__(self, indentation=2):
+self._str = StringIO()
+self._indentation = indentation
+
+def write(self, str_):
+puts(str_, stream=self._str)
+
+@contextmanager
+def indent(self, indentation=None):
--- End diff --

This should only affect the calls for `write` and not the module level 
`puts`


---
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.
---


[GitHub] incubator-ariatosca pull request #189: ARIA-174 Refactor instantiation phase

2017-08-02 Thread AviaE
Github user AviaE commented on a diff in the pull request:

https://github.com/apache/incubator-ariatosca/pull/189#discussion_r130873555
  
--- Diff: extensions/aria_extension_tosca/simple_v1_0/modeling/__init__.py 
---
@@ -497,8 +497,8 @@ def get(name, default=None):
 
 
 def create_workflow_operation_template_model(context, service_template, 
policy):
-model = OperationTemplate(name=policy._name,
-  service_template=service_template)
+model = OperationTemplate(name=policy._name)
+service_template.workflow_templates[model.name] = model
--- End diff --

Add your comment as a code comment. `service_template.workflows` --> 
`service_template.workflow_templates`.
And if you think this problem is in other places also, open a Jira issue 
for it.


---
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.
---


[GitHub] incubator-ariatosca pull request #189: ARIA-174 Refactor instantiation phase

2017-08-02 Thread AviaE
Github user AviaE commented on a diff in the pull request:

https://github.com/apache/incubator-ariatosca/pull/189#discussion_r130902625
  
--- Diff: aria/orchestrator/topology/instance_handler.py ---
@@ -0,0 +1,644 @@
+# 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 ... parser.modeling import context
+from ... modeling import models
+from ... utils import formatting
+from .. import execution_plugin
+from .. import decorators
+from . import common
+
+
+class Artifact(common._InstanceHandlerMixin):
+
+def coerce(self, **kwargs):
+self._topology.coerce(self._model.properties, **kwargs)
+
+def validate(self, **kwargs):
+self._topology.validate(self._model.properties)
+
+def dump(self, out_stream):
+with out_stream.indent():
+out_stream.write(out_stream.node(self._model.name))
+out_stream.write(out_stream.meta(self._model.description))
+with out_stream.indent():
+out_stream.write('Artifact type: 
{0}'.format(out_stream.type(
+self._model.type.name)))
+out_stream.write('Source path: {0}'.format(
+out_stream.literal(self._model.source_path)))
+if self._model.target_path is not None:
+out_stream.write('Target path: {0}'.format(
+out_stream.literal(self._model.target_path)))
+if self._model.repository_url is not None:
+out_stream.write('Repository URL: {0}'.format(
+out_stream.literal(self._model.repository_url)))
+if self._model.repository_credential:
+out_stream.write('Repository credential: {0}'.format(
+
out_stream.literal(self._model.repository_credential)))
+self._topology.dump(self._model.properties, out_stream, 
'Properties')
+
+
+class Capability(common._InstanceHandlerMixin):
+def coerce(self, **kwargs):
+self._topology.coerce(self._model.properties, **kwargs)
+
+def validate(self, **kwargs):
+self._topology.validate(self._model.properties)
+
+def dump(self, out_stream):
+out_stream.write(out_stream.node(self._model.name))
+with out_stream.indent():
+out_stream.write('Type: 
{0}'.format(out_stream.type(self._model.type.name)))
+out_stream.write('Occurrences: {0:d} ({1:d}{2})'.format(
+self._model.occurrences,
+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'))
+self._topology.dump(self._model.properties, out_stream, 
'Properties')
+
+
+class Group(common._OperatorHolderHandlerMixin):
+
+def coerce(self, **kwargs):
+self._coerce(self._model.properties, self._model.interfaces, 
**kwargs)
+
+def validate(self, **kwargs):
+self._validate(self._model.properties,
+   self._model.interfaces)
+
+def dump(self, out_stream):
+out_stream.write('Group: 
{0}'.format(out_stream.node(self._model.name)))
+with out_stream.indent():
+out_stream.write('Type: 
{0}'.format(out_stream.type(self._model.type.name)))
+self._topology.dump(self._model.properties, out_stream, 
'Properties')
+self._topology.dump(self._model.interfaces, out_stream, 
'Interfaces')
+if self._model.nodes:
+out_stream.write('Member nodes:')
+with out_stream.indent():
+for node in self._model.nodes:
+out_stream.write(out_stream.node(node.name))
+
+def configure_operations(self):
+for interface in self._model.interfaces.values():
 

[GitHub] incubator-ariatosca pull request #189: ARIA-174 Refactor instantiation phase

2017-08-02 Thread AviaE
Github user AviaE commented on a diff in the pull request:

https://github.com/apache/incubator-ariatosca/pull/189#discussion_r130844628
  
--- Diff: aria/parser/consumption/modeling.py ---
@@ -105,9 +106,26 @@ def consume(self):
 self.context.validation.report('InstantiateServiceInstance 
consumer: missing service '
'template')
 return
-
-self.context.modeling.template.instantiate(None, None,
-   
inputs=dict(self.context.modeling.inputs))
+self.context.modeling.instance = self.topology.instantiate(
+self.context.modeling.template,
+inputs=dict(self.context.modeling.inputs)
+)
+ConsumerChain(
+self.context,
+(
+CoerceServiceInstanceValues,
+ValidateServiceInstance,
+SatisfyRequirements,
+CoerceServiceInstanceValues,
+ValidateCapabilities,
+FindHosts,
+ConfigureOperations,
+CoerceServiceInstanceValues
+)).consume()
+
+if self.context.validation.dump_issues():
--- End diff --

Also this part.


---
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.
---


[GitHub] incubator-ariatosca pull request #189: ARIA-174 Refactor instantiation phase

2017-08-02 Thread AviaE
Github user AviaE commented on a diff in the pull request:

https://github.com/apache/incubator-ariatosca/pull/189#discussion_r130842710
  
--- Diff: aria/parser/consumption/modeling.py ---
@@ -74,7 +75,7 @@ def dump(self):
 raw = self.context.modeling.template_as_raw
 self.context.write(json_dumps(raw, indent=indent))
 else:
-self.context.modeling.template.dump()
+self.topology.dump(self.context.modeling.template)
 
 
 class Types(Consumer):
--- End diff --

If this class is no longer needed to show ('dump') the types, consider 
deleting it.


---
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.
---


[GitHub] incubator-ariatosca pull request #189: ARIA-174 Refactor instantiation phase

2017-08-02 Thread AviaE
Github user AviaE commented on a diff in the pull request:

https://github.com/apache/incubator-ariatosca/pull/189#discussion_r130876740
  
--- Diff: tests/parser/service_templates.py ---
@@ -27,6 +27,7 @@ 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()
--- End diff --

Why was this added?


---
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.
---


[GitHub] incubator-ariatosca pull request #189: ARIA-174 Refactor instantiation phase

2017-08-02 Thread AviaE
Github user AviaE commented on a diff in the pull request:

https://github.com/apache/incubator-ariatosca/pull/189#discussion_r130829336
  
--- Diff: aria/orchestrator/topology/topology.py ---
@@ -0,0 +1,217 @@
+# 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 ...parser.validation import issue
+from ...modeling import models
+from ...utils import console
+from . import (
+template_handler,
+instance_handler,
+common
+)
+
+
+class Topology(issue.Reporter):
+
+_init_map = {
+models.ServiceTemplate: models.Service,
+models.ArtifactTemplate: models.Artifact,
+models.CapabilityTemplate: models.Capability,
+models.GroupTemplate: models.Group,
+models.InterfaceTemplate: models.Interface,
+models.NodeTemplate: models.Node,
+models.PolicyTemplate: models.Policy,
+models.SubstitutionTemplate: models.Substitution,
+models.RelationshipTemplate: models.Relationship,
+models.OperationTemplate: models.Operation,
+models.RequirementTemplate: None,
+models.SubstitutionTemplateMapping: models.SubstitutionMapping,
+
+# Common
+models.Metadata: models.Metadata,
+models.Attribute: models.Attribute,
+models.Property: models.Property,
+models.Input: models.Input,
+models.Output: models.Output,
+models.Configuration: models.Configuration,
+models.Argument: models.Argument,
+models.Type: models.Type
+}
+
+def __init__(self, model_storage=None, *args, **kwargs):
+# TODO: model storage is required only for the list of plugins, 
can we get it
+# somewhere else?
+super(Topology, self).__init__(*args, **kwargs)
+self._model_storage = model_storage
+self._handlers = dict(self._init_handlers(instance_handler),
+  **self._init_handlers(template_handler))
+
+@staticmethod
+def _init_handlers(module_):
+handlers = {}
+for attribute_name in dir(module_):
+if attribute_name.startswith('_'):
+continue
+attribute = getattr(module_, attribute_name)
+if isinstance(attribute, type) and issubclass(attribute, 
common._Handler):
+handlers[getattr(models, attribute_name)] = attribute
+return handlers
+
+def instantiate(self, model, **kwargs):
+"""
+all handlers used by instantiate should hold a tuple as value 
(handler, instnace_cls)
+:param model:
+:param kwargs:
+:return:
+"""
+if isinstance(model, dict):
+return dict((name, self.instantiate(value, **kwargs))
+for name, value in model.iteritems())
+elif isinstance(model, list):
+return list(self.instantiate(value, **kwargs) for value in 
model)
+elif model is not None:
+_handler = self._handlers.get(model.__class__)
+instance_cls = self._init_map.get(model.__class__)
+return _handler(self, model).instantiate(instance_cls, 
**kwargs)
+
+def validate(self, model, **kwargs):
+if isinstance(model, dict):
+return self.validate(model.values())
+elif isinstance(model, list):
+return all(self.validate(value) for value in model)
+elif model is not None:
+_handler = self._handlers.get(model.__class__)
+return _handler(self, model).validate(**kwargs)
+
+def dump(self, model, out_stream=None, section_name=None, **kwargs):
+out_stream = out_stream or console.TopologyStylizer()
+
+# if model is empty, no need to print out the section name
+if model and section_name:
+ 

[GitHub] incubator-ariatosca pull request #189: ARIA-174 Refactor instantiation phase

2017-08-02 Thread AviaE
Github user AviaE commented on a diff in the pull request:

https://github.com/apache/incubator-ariatosca/pull/189#discussion_r130826035
  
--- Diff: aria/orchestrator/topology/topology.py ---
@@ -0,0 +1,217 @@
+# 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 ...parser.validation import issue
+from ...modeling import models
+from ...utils import console
+from . import (
+template_handler,
+instance_handler,
+common
+)
+
+
+class Topology(issue.Reporter):
+
+_init_map = {
+models.ServiceTemplate: models.Service,
+models.ArtifactTemplate: models.Artifact,
+models.CapabilityTemplate: models.Capability,
+models.GroupTemplate: models.Group,
+models.InterfaceTemplate: models.Interface,
+models.NodeTemplate: models.Node,
+models.PolicyTemplate: models.Policy,
+models.SubstitutionTemplate: models.Substitution,
+models.RelationshipTemplate: models.Relationship,
+models.OperationTemplate: models.Operation,
+models.RequirementTemplate: None,
+models.SubstitutionTemplateMapping: models.SubstitutionMapping,
+
+# Common
+models.Metadata: models.Metadata,
+models.Attribute: models.Attribute,
+models.Property: models.Property,
+models.Input: models.Input,
+models.Output: models.Output,
+models.Configuration: models.Configuration,
+models.Argument: models.Argument,
+models.Type: models.Type
+}
+
+def __init__(self, model_storage=None, *args, **kwargs):
+# TODO: model storage is required only for the list of plugins, 
can we get it
+# somewhere else?
+super(Topology, self).__init__(*args, **kwargs)
+self._model_storage = model_storage
+self._handlers = dict(self._init_handlers(instance_handler),
+  **self._init_handlers(template_handler))
+
+@staticmethod
+def _init_handlers(module_):
+handlers = {}
+for attribute_name in dir(module_):
+if attribute_name.startswith('_'):
+continue
+attribute = getattr(module_, attribute_name)
+if isinstance(attribute, type) and issubclass(attribute, 
common._Handler):
+handlers[getattr(models, attribute_name)] = attribute
+return handlers
+
+def instantiate(self, model, **kwargs):
+"""
+all handlers used by instantiate should hold a tuple as value 
(handler, instnace_cls)
+:param model:
+:param kwargs:
+:return:
+"""
+if isinstance(model, dict):
+return dict((name, self.instantiate(value, **kwargs))
+for name, value in model.iteritems())
+elif isinstance(model, list):
+return list(self.instantiate(value, **kwargs) for value in 
model)
+elif model is not None:
+_handler = self._handlers.get(model.__class__)
+instance_cls = self._init_map.get(model.__class__)
+return _handler(self, model).instantiate(instance_cls, 
**kwargs)
+
+def validate(self, model, **kwargs):
+if isinstance(model, dict):
+return self.validate(model.values())
+elif isinstance(model, list):
+return all(self.validate(value) for value in model)
+elif model is not None:
+_handler = self._handlers.get(model.__class__)
+return _handler(self, model).validate(**kwargs)
+
+def dump(self, model, out_stream=None, section_name=None, **kwargs):
+out_stream = out_stream or console.TopologyStylizer()
+
+# if model is empty, no need to print out the section name
+if model and section_name:
+ 

[GitHub] incubator-ariatosca pull request #189: ARIA-174 Refactor instantiation phase

2017-08-02 Thread AviaE
Github user AviaE commented on a diff in the pull request:

https://github.com/apache/incubator-ariatosca/pull/189#discussion_r130858804
  
--- Diff: aria/parser/consumption/modeling.py ---
@@ -74,7 +75,7 @@ def dump(self):
 raw = self.context.modeling.template_as_raw
 self.context.write(json_dumps(raw, indent=indent))
 else:
-self.context.modeling.template.dump()
+self.topology.dump(self.context.modeling.template)
--- End diff --

should there be `context.write` here?


---
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.
---


[GitHub] incubator-ariatosca pull request #189: ARIA-174 Refactor instantiation phase

2017-08-02 Thread AviaE
Github user AviaE commented on a diff in the pull request:

https://github.com/apache/incubator-ariatosca/pull/189#discussion_r130823646
  
--- Diff: aria/orchestrator/topology/topology.py ---
@@ -0,0 +1,217 @@
+# 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 ...parser.validation import issue
+from ...modeling import models
+from ...utils import console
+from . import (
+template_handler,
+instance_handler,
+common
+)
+
+
+class Topology(issue.Reporter):
+
+_init_map = {
+models.ServiceTemplate: models.Service,
+models.ArtifactTemplate: models.Artifact,
+models.CapabilityTemplate: models.Capability,
+models.GroupTemplate: models.Group,
+models.InterfaceTemplate: models.Interface,
+models.NodeTemplate: models.Node,
+models.PolicyTemplate: models.Policy,
+models.SubstitutionTemplate: models.Substitution,
+models.RelationshipTemplate: models.Relationship,
+models.OperationTemplate: models.Operation,
+models.RequirementTemplate: None,
+models.SubstitutionTemplateMapping: models.SubstitutionMapping,
+
+# Common
+models.Metadata: models.Metadata,
+models.Attribute: models.Attribute,
+models.Property: models.Property,
+models.Input: models.Input,
+models.Output: models.Output,
+models.Configuration: models.Configuration,
+models.Argument: models.Argument,
+models.Type: models.Type
+}
+
+def __init__(self, model_storage=None, *args, **kwargs):
+# TODO: model storage is required only for the list of plugins, 
can we get it
+# somewhere else?
+super(Topology, self).__init__(*args, **kwargs)
+self._model_storage = model_storage
+self._handlers = dict(self._init_handlers(instance_handler),
+  **self._init_handlers(template_handler))
+
+@staticmethod
+def _init_handlers(module_):
+handlers = {}
+for attribute_name in dir(module_):
+if attribute_name.startswith('_'):
+continue
+attribute = getattr(module_, attribute_name)
+if isinstance(attribute, type) and issubclass(attribute, 
common._Handler):
+handlers[getattr(models, attribute_name)] = attribute
+return handlers
+
+def instantiate(self, model, **kwargs):
+"""
+all handlers used by instantiate should hold a tuple as value 
(handler, instnace_cls)
+:param model:
+:param kwargs:
+:return:
+"""
+if isinstance(model, dict):
+return dict((name, self.instantiate(value, **kwargs))
+for name, value in model.iteritems())
+elif isinstance(model, list):
+return list(self.instantiate(value, **kwargs) for value in 
model)
+elif model is not None:
+_handler = self._handlers.get(model.__class__)
+instance_cls = self._init_map.get(model.__class__)
+return _handler(self, model).instantiate(instance_cls, 
**kwargs)
+
+def validate(self, model, **kwargs):
+if isinstance(model, dict):
+return self.validate(model.values())
+elif isinstance(model, list):
+return all(self.validate(value) for value in model)
+elif model is not None:
+_handler = self._handlers.get(model.__class__)
+return _handler(self, model).validate(**kwargs)
+
+def dump(self, model, out_stream=None, section_name=None, **kwargs):
+out_stream = out_stream or console.TopologyStylizer()
+
+# if model is empty, no need to print out the section name
+if model and section_name:
+ 

[GitHub] incubator-ariatosca pull request #189: ARIA-174 Refactor instantiation phase

2017-08-02 Thread AviaE
Github user AviaE commented on a diff in the pull request:

https://github.com/apache/incubator-ariatosca/pull/189#discussion_r130871342
  
--- Diff: aria/utils/console.py ---
@@ -19,19 +19,68 @@
 
 import os
 import sys
+from StringIO import StringIO
 
 from contextlib import contextmanager
 
-from .formatting import safe_str
 from ..cli import color
+from . import formatting
 
 
 _indent_string = ''
 
 
+class TopologyStylizer(object):
+def __init__(self, indentation=2):
+self._str = StringIO()
+self._indentation = indentation
+
+def write(self, str_):
+puts(str_, stream=self._str)
+
+@contextmanager
+def indent(self, indentation=None):
+with indent(indentation or self._indentation):
+yield
+
+@staticmethod
+def section(value):
+return Colored.cyan(value, bold=True)
+
+@staticmethod
+def type(value):
+return Colored.blue(value, bold=True)
+
+@staticmethod
+def node(value):
+return Colored.red(value, bold=True)
+
+@staticmethod
+def property(value):
+return Colored.magenta(value, bold=True)
+
+@staticmethod
+def literal(value):
+return Colored.magenta(formatting.safe_repr(value))
+
+@staticmethod
+def required(value):
+return Colored.white(value)
+
+@staticmethod
+def meta(value):
+return Colored.green(value)
+
+def __repr__(self):
--- End diff --

`__repr__` should have a standard implementation.
So remove this, and just implement `__str__`.


---
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.
---


[GitHub] incubator-ariatosca pull request #189: ARIA-174 Refactor instantiation phase

2017-08-02 Thread AviaE
Github user AviaE commented on a diff in the pull request:

https://github.com/apache/incubator-ariatosca/pull/189#discussion_r130827261
  
--- Diff: aria/orchestrator/topology/topology.py ---
@@ -0,0 +1,217 @@
+# 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 ...parser.validation import issue
+from ...modeling import models
+from ...utils import console
+from . import (
+template_handler,
+instance_handler,
+common
+)
+
+
+class Topology(issue.Reporter):
+
+_init_map = {
+models.ServiceTemplate: models.Service,
+models.ArtifactTemplate: models.Artifact,
+models.CapabilityTemplate: models.Capability,
+models.GroupTemplate: models.Group,
+models.InterfaceTemplate: models.Interface,
+models.NodeTemplate: models.Node,
+models.PolicyTemplate: models.Policy,
+models.SubstitutionTemplate: models.Substitution,
+models.RelationshipTemplate: models.Relationship,
+models.OperationTemplate: models.Operation,
+models.RequirementTemplate: None,
+models.SubstitutionTemplateMapping: models.SubstitutionMapping,
+
+# Common
+models.Metadata: models.Metadata,
+models.Attribute: models.Attribute,
+models.Property: models.Property,
+models.Input: models.Input,
+models.Output: models.Output,
+models.Configuration: models.Configuration,
+models.Argument: models.Argument,
+models.Type: models.Type
+}
+
+def __init__(self, model_storage=None, *args, **kwargs):
+# TODO: model storage is required only for the list of plugins, 
can we get it
+# somewhere else?
+super(Topology, self).__init__(*args, **kwargs)
+self._model_storage = model_storage
+self._handlers = dict(self._init_handlers(instance_handler),
+  **self._init_handlers(template_handler))
+
+@staticmethod
+def _init_handlers(module_):
+handlers = {}
+for attribute_name in dir(module_):
+if attribute_name.startswith('_'):
+continue
+attribute = getattr(module_, attribute_name)
+if isinstance(attribute, type) and issubclass(attribute, 
common._Handler):
+handlers[getattr(models, attribute_name)] = attribute
+return handlers
+
+def instantiate(self, model, **kwargs):
+"""
+all handlers used by instantiate should hold a tuple as value 
(handler, instnace_cls)
+:param model:
+:param kwargs:
+:return:
+"""
+if isinstance(model, dict):
+return dict((name, self.instantiate(value, **kwargs))
+for name, value in model.iteritems())
+elif isinstance(model, list):
+return list(self.instantiate(value, **kwargs) for value in 
model)
+elif model is not None:
+_handler = self._handlers.get(model.__class__)
+instance_cls = self._init_map.get(model.__class__)
+return _handler(self, model).instantiate(instance_cls, 
**kwargs)
+
+def validate(self, model, **kwargs):
+if isinstance(model, dict):
+return self.validate(model.values())
+elif isinstance(model, list):
+return all(self.validate(value) for value in model)
+elif model is not None:
+_handler = self._handlers.get(model.__class__)
+return _handler(self, model).validate(**kwargs)
+
+def dump(self, model, out_stream=None, section_name=None, **kwargs):
+out_stream = out_stream or console.TopologyStylizer()
+
+# if model is empty, no need to print out the section name
+if model and section_name:
+ 

[GitHub] incubator-ariatosca pull request #189: ARIA-174 Refactor instantiation phase

2017-08-02 Thread AviaE
Github user AviaE commented on a diff in the pull request:

https://github.com/apache/incubator-ariatosca/pull/189#discussion_r130820499
  
--- Diff: aria/orchestrator/topology/topology.py ---
@@ -0,0 +1,217 @@
+# 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 ...parser.validation import issue
+from ...modeling import models
+from ...utils import console
+from . import (
+template_handler,
+instance_handler,
+common
+)
+
+
+class Topology(issue.Reporter):
+
+_init_map = {
+models.ServiceTemplate: models.Service,
+models.ArtifactTemplate: models.Artifact,
+models.CapabilityTemplate: models.Capability,
+models.GroupTemplate: models.Group,
+models.InterfaceTemplate: models.Interface,
+models.NodeTemplate: models.Node,
+models.PolicyTemplate: models.Policy,
+models.SubstitutionTemplate: models.Substitution,
+models.RelationshipTemplate: models.Relationship,
+models.OperationTemplate: models.Operation,
+models.RequirementTemplate: None,
+models.SubstitutionTemplateMapping: models.SubstitutionMapping,
+
+# Common
+models.Metadata: models.Metadata,
+models.Attribute: models.Attribute,
+models.Property: models.Property,
+models.Input: models.Input,
+models.Output: models.Output,
+models.Configuration: models.Configuration,
+models.Argument: models.Argument,
+models.Type: models.Type
+}
+
+def __init__(self, model_storage=None, *args, **kwargs):
+# TODO: model storage is required only for the list of plugins, 
can we get it
+# somewhere else?
+super(Topology, self).__init__(*args, **kwargs)
+self._model_storage = model_storage
+self._handlers = dict(self._init_handlers(instance_handler),
+  **self._init_handlers(template_handler))
+
+@staticmethod
+def _init_handlers(module_):
+handlers = {}
+for attribute_name in dir(module_):
+if attribute_name.startswith('_'):
+continue
+attribute = getattr(module_, attribute_name)
+if isinstance(attribute, type) and issubclass(attribute, 
common._Handler):
+handlers[getattr(models, attribute_name)] = attribute
+return handlers
+
+def instantiate(self, model, **kwargs):
+"""
+all handlers used by instantiate should hold a tuple as value 
(handler, instnace_cls)
+:param model:
+:param kwargs:
+:return:
+"""
+if isinstance(model, dict):
+return dict((name, self.instantiate(value, **kwargs))
+for name, value in model.iteritems())
+elif isinstance(model, list):
+return list(self.instantiate(value, **kwargs) for value in 
model)
+elif model is not None:
+_handler = self._handlers.get(model.__class__)
+instance_cls = self._init_map.get(model.__class__)
+return _handler(self, model).instantiate(instance_cls, 
**kwargs)
+
+def validate(self, model, **kwargs):
+if isinstance(model, dict):
+return self.validate(model.values())
--- End diff --

do you need to pass down `**kwargs`?
Check all relevant places.


---
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.
---


[GitHub] incubator-ariatosca pull request #189: ARIA-174 Refactor instantiation phase

2017-08-02 Thread AviaE
Github user AviaE commented on a diff in the pull request:

https://github.com/apache/incubator-ariatosca/pull/189#discussion_r130906157
  
--- Diff: aria/orchestrator/topology/instance_handler.py ---
@@ -0,0 +1,644 @@
+# 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 ... parser.modeling import context
+from ... modeling import models
+from ... utils import formatting
+from .. import execution_plugin
+from .. import decorators
+from . import common
+
+
+class Artifact(common._InstanceHandlerMixin):
+
+def coerce(self, **kwargs):
+self._topology.coerce(self._model.properties, **kwargs)
+
+def validate(self, **kwargs):
+self._topology.validate(self._model.properties)
+
+def dump(self, out_stream):
+with out_stream.indent():
+out_stream.write(out_stream.node(self._model.name))
+out_stream.write(out_stream.meta(self._model.description))
+with out_stream.indent():
+out_stream.write('Artifact type: 
{0}'.format(out_stream.type(
+self._model.type.name)))
+out_stream.write('Source path: {0}'.format(
+out_stream.literal(self._model.source_path)))
+if self._model.target_path is not None:
+out_stream.write('Target path: {0}'.format(
+out_stream.literal(self._model.target_path)))
+if self._model.repository_url is not None:
+out_stream.write('Repository URL: {0}'.format(
+out_stream.literal(self._model.repository_url)))
+if self._model.repository_credential:
+out_stream.write('Repository credential: {0}'.format(
+
out_stream.literal(self._model.repository_credential)))
+self._topology.dump(self._model.properties, out_stream, 
'Properties')
+
+
+class Capability(common._InstanceHandlerMixin):
+def coerce(self, **kwargs):
+self._topology.coerce(self._model.properties, **kwargs)
+
+def validate(self, **kwargs):
+self._topology.validate(self._model.properties)
+
+def dump(self, out_stream):
+out_stream.write(out_stream.node(self._model.name))
+with out_stream.indent():
+out_stream.write('Type: 
{0}'.format(out_stream.type(self._model.type.name)))
+out_stream.write('Occurrences: {0:d} ({1:d}{2})'.format(
+self._model.occurrences,
+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'))
+self._topology.dump(self._model.properties, out_stream, 
'Properties')
+
+
+class Group(common._OperatorHolderHandlerMixin):
+
+def coerce(self, **kwargs):
+self._coerce(self._model.properties, self._model.interfaces, 
**kwargs)
+
+def validate(self, **kwargs):
+self._validate(self._model.properties,
+   self._model.interfaces)
+
+def dump(self, out_stream):
+out_stream.write('Group: 
{0}'.format(out_stream.node(self._model.name)))
+with out_stream.indent():
+out_stream.write('Type: 
{0}'.format(out_stream.type(self._model.type.name)))
+self._topology.dump(self._model.properties, out_stream, 
'Properties')
+self._topology.dump(self._model.interfaces, out_stream, 
'Interfaces')
+if self._model.nodes:
+out_stream.write('Member nodes:')
+with out_stream.indent():
+for node in self._model.nodes:
+out_stream.write(out_stream.node(node.name))
+
+def configure_operations(self):
+for interface in self._model.interfaces.values():
 

[GitHub] incubator-ariatosca pull request #189: ARIA-174 Refactor instantiation phase

2017-08-02 Thread AviaE
Github user AviaE commented on a diff in the pull request:

https://github.com/apache/incubator-ariatosca/pull/189#discussion_r130824971
  
--- Diff: aria/orchestrator/topology/topology.py ---
@@ -0,0 +1,217 @@
+# 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 ...parser.validation import issue
+from ...modeling import models
+from ...utils import console
+from . import (
+template_handler,
+instance_handler,
+common
+)
+
+
+class Topology(issue.Reporter):
+
+_init_map = {
+models.ServiceTemplate: models.Service,
+models.ArtifactTemplate: models.Artifact,
+models.CapabilityTemplate: models.Capability,
+models.GroupTemplate: models.Group,
+models.InterfaceTemplate: models.Interface,
+models.NodeTemplate: models.Node,
+models.PolicyTemplate: models.Policy,
+models.SubstitutionTemplate: models.Substitution,
+models.RelationshipTemplate: models.Relationship,
+models.OperationTemplate: models.Operation,
+models.RequirementTemplate: None,
+models.SubstitutionTemplateMapping: models.SubstitutionMapping,
+
+# Common
+models.Metadata: models.Metadata,
+models.Attribute: models.Attribute,
+models.Property: models.Property,
+models.Input: models.Input,
+models.Output: models.Output,
+models.Configuration: models.Configuration,
+models.Argument: models.Argument,
+models.Type: models.Type
+}
+
+def __init__(self, model_storage=None, *args, **kwargs):
+# TODO: model storage is required only for the list of plugins, 
can we get it
+# somewhere else?
+super(Topology, self).__init__(*args, **kwargs)
+self._model_storage = model_storage
+self._handlers = dict(self._init_handlers(instance_handler),
+  **self._init_handlers(template_handler))
+
+@staticmethod
+def _init_handlers(module_):
+handlers = {}
+for attribute_name in dir(module_):
+if attribute_name.startswith('_'):
+continue
+attribute = getattr(module_, attribute_name)
+if isinstance(attribute, type) and issubclass(attribute, 
common._Handler):
+handlers[getattr(models, attribute_name)] = attribute
+return handlers
+
+def instantiate(self, model, **kwargs):
+"""
+all handlers used by instantiate should hold a tuple as value 
(handler, instnace_cls)
+:param model:
+:param kwargs:
+:return:
+"""
+if isinstance(model, dict):
+return dict((name, self.instantiate(value, **kwargs))
+for name, value in model.iteritems())
+elif isinstance(model, list):
+return list(self.instantiate(value, **kwargs) for value in 
model)
+elif model is not None:
+_handler = self._handlers.get(model.__class__)
+instance_cls = self._init_map.get(model.__class__)
+return _handler(self, model).instantiate(instance_cls, 
**kwargs)
+
+def validate(self, model, **kwargs):
+if isinstance(model, dict):
+return self.validate(model.values())
+elif isinstance(model, list):
+return all(self.validate(value) for value in model)
+elif model is not None:
+_handler = self._handlers.get(model.__class__)
+return _handler(self, model).validate(**kwargs)
+
+def dump(self, model, out_stream=None, section_name=None, **kwargs):
+out_stream = out_stream or console.TopologyStylizer()
+
+# if model is empty, no need to print out the section name
+if model and section_name:
+ 

[GitHub] incubator-ariatosca pull request #189: ARIA-174 Refactor instantiation phase

2017-08-02 Thread AviaE
Github user AviaE commented on a diff in the pull request:

https://github.com/apache/incubator-ariatosca/pull/189#discussion_r130830529
  
--- Diff: aria/orchestrator/topology/topology.py ---
@@ -0,0 +1,217 @@
+# 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 ...parser.validation import issue
+from ...modeling import models
+from ...utils import console
+from . import (
+template_handler,
+instance_handler,
+common
+)
+
+
+class Topology(issue.Reporter):
+
+_init_map = {
+models.ServiceTemplate: models.Service,
+models.ArtifactTemplate: models.Artifact,
+models.CapabilityTemplate: models.Capability,
+models.GroupTemplate: models.Group,
+models.InterfaceTemplate: models.Interface,
+models.NodeTemplate: models.Node,
+models.PolicyTemplate: models.Policy,
+models.SubstitutionTemplate: models.Substitution,
+models.RelationshipTemplate: models.Relationship,
+models.OperationTemplate: models.Operation,
+models.RequirementTemplate: None,
+models.SubstitutionTemplateMapping: models.SubstitutionMapping,
+
+# Common
+models.Metadata: models.Metadata,
+models.Attribute: models.Attribute,
+models.Property: models.Property,
+models.Input: models.Input,
+models.Output: models.Output,
+models.Configuration: models.Configuration,
+models.Argument: models.Argument,
+models.Type: models.Type
+}
+
+def __init__(self, model_storage=None, *args, **kwargs):
+# TODO: model storage is required only for the list of plugins, 
can we get it
+# somewhere else?
+super(Topology, self).__init__(*args, **kwargs)
+self._model_storage = model_storage
+self._handlers = dict(self._init_handlers(instance_handler),
+  **self._init_handlers(template_handler))
+
+@staticmethod
+def _init_handlers(module_):
+handlers = {}
+for attribute_name in dir(module_):
+if attribute_name.startswith('_'):
+continue
+attribute = getattr(module_, attribute_name)
+if isinstance(attribute, type) and issubclass(attribute, 
common._Handler):
+handlers[getattr(models, attribute_name)] = attribute
+return handlers
+
+def instantiate(self, model, **kwargs):
+"""
+all handlers used by instantiate should hold a tuple as value 
(handler, instnace_cls)
+:param model:
+:param kwargs:
+:return:
+"""
+if isinstance(model, dict):
+return dict((name, self.instantiate(value, **kwargs))
+for name, value in model.iteritems())
+elif isinstance(model, list):
+return list(self.instantiate(value, **kwargs) for value in 
model)
+elif model is not None:
+_handler = self._handlers.get(model.__class__)
+instance_cls = self._init_map.get(model.__class__)
+return _handler(self, model).instantiate(instance_cls, 
**kwargs)
+
+def validate(self, model, **kwargs):
+if isinstance(model, dict):
+return self.validate(model.values())
+elif isinstance(model, list):
+return all(self.validate(value) for value in model)
+elif model is not None:
+_handler = self._handlers.get(model.__class__)
+return _handler(self, model).validate(**kwargs)
+
+def dump(self, model, out_stream=None, section_name=None, **kwargs):
+out_stream = out_stream or console.TopologyStylizer()
+
+# if model is empty, no need to print out the section name
+if model and section_name:
+ 

[GitHub] incubator-ariatosca pull request #189: ARIA-174 Refactor instantiation phase

2017-08-02 Thread AviaE
Github user AviaE commented on a diff in the pull request:

https://github.com/apache/incubator-ariatosca/pull/189#discussion_r130828395
  
--- Diff: aria/orchestrator/topology/topology.py ---
@@ -0,0 +1,217 @@
+# 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 ...parser.validation import issue
+from ...modeling import models
+from ...utils import console
+from . import (
+template_handler,
+instance_handler,
+common
+)
+
+
+class Topology(issue.Reporter):
+
+_init_map = {
+models.ServiceTemplate: models.Service,
+models.ArtifactTemplate: models.Artifact,
+models.CapabilityTemplate: models.Capability,
+models.GroupTemplate: models.Group,
+models.InterfaceTemplate: models.Interface,
+models.NodeTemplate: models.Node,
+models.PolicyTemplate: models.Policy,
+models.SubstitutionTemplate: models.Substitution,
+models.RelationshipTemplate: models.Relationship,
+models.OperationTemplate: models.Operation,
+models.RequirementTemplate: None,
+models.SubstitutionTemplateMapping: models.SubstitutionMapping,
+
+# Common
+models.Metadata: models.Metadata,
+models.Attribute: models.Attribute,
+models.Property: models.Property,
+models.Input: models.Input,
+models.Output: models.Output,
+models.Configuration: models.Configuration,
+models.Argument: models.Argument,
+models.Type: models.Type
+}
+
+def __init__(self, model_storage=None, *args, **kwargs):
+# TODO: model storage is required only for the list of plugins, 
can we get it
+# somewhere else?
+super(Topology, self).__init__(*args, **kwargs)
+self._model_storage = model_storage
+self._handlers = dict(self._init_handlers(instance_handler),
+  **self._init_handlers(template_handler))
+
+@staticmethod
+def _init_handlers(module_):
+handlers = {}
+for attribute_name in dir(module_):
+if attribute_name.startswith('_'):
+continue
+attribute = getattr(module_, attribute_name)
+if isinstance(attribute, type) and issubclass(attribute, 
common._Handler):
+handlers[getattr(models, attribute_name)] = attribute
+return handlers
+
+def instantiate(self, model, **kwargs):
+"""
+all handlers used by instantiate should hold a tuple as value 
(handler, instnace_cls)
+:param model:
+:param kwargs:
+:return:
+"""
+if isinstance(model, dict):
+return dict((name, self.instantiate(value, **kwargs))
+for name, value in model.iteritems())
+elif isinstance(model, list):
+return list(self.instantiate(value, **kwargs) for value in 
model)
+elif model is not None:
+_handler = self._handlers.get(model.__class__)
+instance_cls = self._init_map.get(model.__class__)
+return _handler(self, model).instantiate(instance_cls, 
**kwargs)
+
+def validate(self, model, **kwargs):
+if isinstance(model, dict):
+return self.validate(model.values())
+elif isinstance(model, list):
+return all(self.validate(value) for value in model)
+elif model is not None:
+_handler = self._handlers.get(model.__class__)
+return _handler(self, model).validate(**kwargs)
+
+def dump(self, model, out_stream=None, section_name=None, **kwargs):
+out_stream = out_stream or console.TopologyStylizer()
+
+# if model is empty, no need to print out the section name
+if model and section_name:
+ 

[GitHub] incubator-ariatosca pull request #189: ARIA-174 Refactor instantiation phase

2017-08-02 Thread AviaE
Github user AviaE commented on a diff in the pull request:

https://github.com/apache/incubator-ariatosca/pull/189#discussion_r130875236
  
--- Diff: tests/instantiation/test_configuration.py ---
@@ -165,8 +165,11 @@ def test_remote(service):
 
 
 def test_reserved_arguments(broken_service_issues):
--- End diff --

I think there should be only one issue created here. The other issue, `0: 
Failed to instantiate service template `None`, which is a general failure 
message, shouldn't be modelled as an Issue.


---
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.
---


[GitHub] incubator-ariatosca pull request #189: ARIA-174 Refactor instantiation phase

2017-08-02 Thread AviaE
Github user AviaE commented on a diff in the pull request:

https://github.com/apache/incubator-ariatosca/pull/189#discussion_r130876338
  
--- Diff: tests/instantiation/test_configuration.py ---
@@ -165,8 +165,11 @@ def test_remote(service):
 
 
 def test_reserved_arguments(broken_service_issues):
--- End diff --

Removing the part that starts 
[here](https://github.com/apache/incubator-ariatosca/pull/189/files/b729f6349e8b2a5d5270ba2f4608ebbcc18ae956#diff-76248dafd82902b4219068a6e2457c55R113)
 maybe resolves this.


---
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.
---


[GitHub] incubator-ariatosca pull request #189: ARIA-174 Refactor instantiation phase

2017-08-02 Thread AviaE
Github user AviaE commented on a diff in the pull request:

https://github.com/apache/incubator-ariatosca/pull/189#discussion_r130868717
  
--- Diff: aria/utils/console.py ---
@@ -19,19 +19,68 @@
 
 import os
 import sys
+from StringIO import StringIO
 
 from contextlib import contextmanager
 
-from .formatting import safe_str
 from ..cli import color
+from . import formatting
 
 
 _indent_string = ''
 
 
+class TopologyStylizer(object):
+def __init__(self, indentation=2):
+self._str = StringIO()
+self._indentation = indentation
+
+def write(self, str_):
--- End diff --

`str_` --> `string`


---
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.
---


[GitHub] incubator-ariatosca pull request #189: ARIA-174 Refactor instantiation phase

2017-08-02 Thread AviaE
Github user AviaE commented on a diff in the pull request:

https://github.com/apache/incubator-ariatosca/pull/189#discussion_r130904352
  
--- Diff: aria/orchestrator/topology/instance_handler.py ---
@@ -0,0 +1,644 @@
+# 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 ... parser.modeling import context
+from ... modeling import models
+from ... utils import formatting
+from .. import execution_plugin
+from .. import decorators
+from . import common
+
+
+class Artifact(common._InstanceHandlerMixin):
+
+def coerce(self, **kwargs):
+self._topology.coerce(self._model.properties, **kwargs)
+
+def validate(self, **kwargs):
+self._topology.validate(self._model.properties)
+
+def dump(self, out_stream):
+with out_stream.indent():
+out_stream.write(out_stream.node(self._model.name))
+out_stream.write(out_stream.meta(self._model.description))
+with out_stream.indent():
+out_stream.write('Artifact type: 
{0}'.format(out_stream.type(
+self._model.type.name)))
+out_stream.write('Source path: {0}'.format(
+out_stream.literal(self._model.source_path)))
+if self._model.target_path is not None:
+out_stream.write('Target path: {0}'.format(
+out_stream.literal(self._model.target_path)))
+if self._model.repository_url is not None:
+out_stream.write('Repository URL: {0}'.format(
+out_stream.literal(self._model.repository_url)))
+if self._model.repository_credential:
+out_stream.write('Repository credential: {0}'.format(
+
out_stream.literal(self._model.repository_credential)))
+self._topology.dump(self._model.properties, out_stream, 
'Properties')
+
+
+class Capability(common._InstanceHandlerMixin):
+def coerce(self, **kwargs):
+self._topology.coerce(self._model.properties, **kwargs)
+
+def validate(self, **kwargs):
+self._topology.validate(self._model.properties)
+
+def dump(self, out_stream):
+out_stream.write(out_stream.node(self._model.name))
+with out_stream.indent():
+out_stream.write('Type: 
{0}'.format(out_stream.type(self._model.type.name)))
+out_stream.write('Occurrences: {0:d} ({1:d}{2})'.format(
+self._model.occurrences,
+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'))
+self._topology.dump(self._model.properties, out_stream, 
'Properties')
+
+
+class Group(common._OperatorHolderHandlerMixin):
+
+def coerce(self, **kwargs):
+self._coerce(self._model.properties, self._model.interfaces, 
**kwargs)
+
+def validate(self, **kwargs):
+self._validate(self._model.properties,
+   self._model.interfaces)
+
+def dump(self, out_stream):
+out_stream.write('Group: 
{0}'.format(out_stream.node(self._model.name)))
+with out_stream.indent():
+out_stream.write('Type: 
{0}'.format(out_stream.type(self._model.type.name)))
+self._topology.dump(self._model.properties, out_stream, 
'Properties')
+self._topology.dump(self._model.interfaces, out_stream, 
'Interfaces')
+if self._model.nodes:
+out_stream.write('Member nodes:')
+with out_stream.indent():
+for node in self._model.nodes:
+out_stream.write(out_stream.node(node.name))
+
+def configure_operations(self):
+for interface in self._model.interfaces.values():
 

[GitHub] incubator-ariatosca pull request #189: ARIA-174 Refactor instantiation phase

2017-08-02 Thread AviaE
Github user AviaE commented on a diff in the pull request:

https://github.com/apache/incubator-ariatosca/pull/189#discussion_r130868151
  
--- Diff: aria/utils/__init__.py ---
@@ -16,3 +16,50 @@
 """
 General-purpose utilities package.
 """
+
+from . import (
+archive,
+argparse,
+caching,
+collections,
+console,
+exceptions,
+file,
+formatting,
+http,
+imports,
+openclose,
+plugin,
+process,
+specification,
+threading,
+type,
+uris,
+uuid,
+validation,
+versions
+)
+
+
+__all__ = (
--- End diff --

Do you really need that `__all__`? As far as I know, it is only useful when 
you do an `import *`.


---
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.
---


[GitHub] incubator-ariatosca pull request #189: ARIA-174 Refactor instantiation phase

2017-08-02 Thread AviaE
Github user AviaE commented on a diff in the pull request:

https://github.com/apache/incubator-ariatosca/pull/189#discussion_r130879245
  
--- Diff: tests/parser/test_reqs_caps.py ---
@@ -0,0 +1,29 @@
+# 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 .service_templates import consume_test_case
+from ..helpers import get_service_template_uri
+
+
+def test_satisfy_capability_type():
+consume_reqs_caps_template('instance')
+
+
+def consume_reqs_caps_template(consumer_class_name, cache=True):
--- End diff --

`consume_reqs_caps_template1`? Or a name that explains what exactly are we 
testing here regarding reqs and caps.


---
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.
---


[GitHub] incubator-ariatosca pull request #189: ARIA-174 Refactor instantiation phase

2017-08-01 Thread AviaE
Github user AviaE commented on a diff in the pull request:

https://github.com/apache/incubator-ariatosca/pull/189#discussion_r130594613
  
--- Diff: aria/orchestrator/topology/common.py ---
@@ -0,0 +1,52 @@
+# 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.
+
+
+class _Handler(object):
+def __init__(self, topology, template):
+self._topology = topology
+self._model = template
+
+def _coerce(self, *templates, **kwargs):
+for template in templates:
+self._topology.coerce(template)
+
+def coerce(self):
+pass
+
+def validate(self, **kwargs):
+pass
+
+def _validate(self, *templates, **kwargs):
--- End diff --

maybe `_validate_collection` or `iterable`.


---
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.
---


[GitHub] incubator-ariatosca pull request #189: ARIA-174 Refactor instantiation phase

2017-08-01 Thread AviaE
Github user AviaE commented on a diff in the pull request:

https://github.com/apache/incubator-ariatosca/pull/189#discussion_r130606443
  
--- Diff: aria/orchestrator/topology/topology.py ---
@@ -0,0 +1,217 @@
+# 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 ...parser.validation import issue
+from ...modeling import models
+from ...utils import console
+from . import (
+template_handler,
+instance_handler,
+common
+)
+
+
+class Topology(issue.Reporter):
+
+_init_map = {
+models.ServiceTemplate: models.Service,
+models.ArtifactTemplate: models.Artifact,
+models.CapabilityTemplate: models.Capability,
+models.GroupTemplate: models.Group,
+models.InterfaceTemplate: models.Interface,
+models.NodeTemplate: models.Node,
+models.PolicyTemplate: models.Policy,
+models.SubstitutionTemplate: models.Substitution,
+models.RelationshipTemplate: models.Relationship,
+models.OperationTemplate: models.Operation,
+models.RequirementTemplate: None,
+models.SubstitutionTemplateMapping: models.SubstitutionMapping,
+
+# Common
+models.Metadata: models.Metadata,
+models.Attribute: models.Attribute,
+models.Property: models.Property,
+models.Input: models.Input,
+models.Output: models.Output,
+models.Configuration: models.Configuration,
+models.Argument: models.Argument,
+models.Type: models.Type
+}
+
+def __init__(self, model_storage=None, *args, **kwargs):
+# TODO: model storage is required only for the list of plugins, 
can we get it
+# somewhere else?
+super(Topology, self).__init__(*args, **kwargs)
+self._model_storage = model_storage
+self._handlers = dict(self._init_handlers(instance_handler),
+  **self._init_handlers(template_handler))
+
+@staticmethod
+def _init_handlers(module_):
+handlers = {}
+for attribute_name in dir(module_):
+if attribute_name.startswith('_'):
+continue
+attribute = getattr(module_, attribute_name)
+if isinstance(attribute, type) and issubclass(attribute, 
common._Handler):
+handlers[getattr(models, attribute_name)] = attribute
+return handlers
+
+def instantiate(self, model, **kwargs):
+"""
+all handlers used by instantiate should hold a tuple as value 
(handler, instnace_cls)
--- End diff --

This comment is not correct now.


---
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.
---


[GitHub] incubator-ariatosca pull request #189: ARIA-174 Refactor instantiation phase

2017-08-01 Thread AviaE
Github user AviaE commented on a diff in the pull request:

https://github.com/apache/incubator-ariatosca/pull/189#discussion_r130583765
  
--- Diff: aria/cli/commands/service_templates.py ---
@@ -57,7 +57,7 @@ def service_templates():
 def show(service_template_name, model_storage, mode_full, mode_types, 
format_json, format_yaml,
  logger):
 """
-Show information for a stored service template
+Show information for a stored service templates
--- End diff --

template.


---
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.
---


[GitHub] incubator-ariatosca pull request #189: ARIA-174 Refactor instantiation phase

2017-08-01 Thread AviaE
Github user AviaE commented on a diff in the pull request:

https://github.com/apache/incubator-ariatosca/pull/189#discussion_r130604096
  
--- Diff: aria/orchestrator/topology/topology.py ---
@@ -0,0 +1,217 @@
+# 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 ...parser.validation import issue
+from ...modeling import models
+from ...utils import console
+from . import (
+template_handler,
+instance_handler,
+common
+)
+
+
+class Topology(issue.Reporter):
+
+_init_map = {
+models.ServiceTemplate: models.Service,
+models.ArtifactTemplate: models.Artifact,
+models.CapabilityTemplate: models.Capability,
+models.GroupTemplate: models.Group,
+models.InterfaceTemplate: models.Interface,
+models.NodeTemplate: models.Node,
+models.PolicyTemplate: models.Policy,
+models.SubstitutionTemplate: models.Substitution,
+models.RelationshipTemplate: models.Relationship,
+models.OperationTemplate: models.Operation,
+models.RequirementTemplate: None,
+models.SubstitutionTemplateMapping: models.SubstitutionMapping,
+
+# Common
+models.Metadata: models.Metadata,
+models.Attribute: models.Attribute,
+models.Property: models.Property,
+models.Input: models.Input,
+models.Output: models.Output,
+models.Configuration: models.Configuration,
+models.Argument: models.Argument,
+models.Type: models.Type
+}
+
+def __init__(self, model_storage=None, *args, **kwargs):
+# TODO: model storage is required only for the list of plugins, 
can we get it
+# somewhere else?
+super(Topology, self).__init__(*args, **kwargs)
+self._model_storage = model_storage
+self._handlers = dict(self._init_handlers(instance_handler),
--- End diff --

maybe name it something in the likes of `models_to_handlers`.


---
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.
---


[GitHub] incubator-ariatosca pull request #189: ARIA-174 Refactor instantiation phase

2017-08-01 Thread AviaE
Github user AviaE commented on a diff in the pull request:

https://github.com/apache/incubator-ariatosca/pull/189#discussion_r130593980
  
--- Diff: aria/orchestrator/topology/common.py ---
@@ -0,0 +1,52 @@
+# 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.
+
+
+class _Handler(object):
+def __init__(self, topology, template):
+self._topology = topology
+self._model = template
+
+def _coerce(self, *templates, **kwargs):
--- End diff --

`templates` --> `models`
And everywhere else.
If it's not always a model, choose better name, not `template`.


---
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.
---


[GitHub] incubator-ariatosca pull request #189: ARIA-174 Refactor instantiation phase

2017-08-01 Thread AviaE
Github user AviaE commented on a diff in the pull request:

https://github.com/apache/incubator-ariatosca/pull/189#discussion_r130593564
  
--- Diff: aria/orchestrator/topology/__init__.py ---
@@ -0,0 +1,16 @@
+# 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 .topology import Topology
--- End diff --

Don't see the need for that.


---
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.
---


[GitHub] incubator-ariatosca pull request #189: ARIA-174 Refactor instantiation phase

2017-08-01 Thread AviaE
Github user AviaE commented on a diff in the pull request:

https://github.com/apache/incubator-ariatosca/pull/189#discussion_r130607151
  
--- Diff: aria/orchestrator/topology/topology.py ---
@@ -0,0 +1,217 @@
+# 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 ...parser.validation import issue
+from ...modeling import models
+from ...utils import console
+from . import (
+template_handler,
+instance_handler,
+common
+)
+
+
+class Topology(issue.Reporter):
+
+_init_map = {
+models.ServiceTemplate: models.Service,
+models.ArtifactTemplate: models.Artifact,
+models.CapabilityTemplate: models.Capability,
+models.GroupTemplate: models.Group,
+models.InterfaceTemplate: models.Interface,
+models.NodeTemplate: models.Node,
+models.PolicyTemplate: models.Policy,
+models.SubstitutionTemplate: models.Substitution,
+models.RelationshipTemplate: models.Relationship,
+models.OperationTemplate: models.Operation,
+models.RequirementTemplate: None,
+models.SubstitutionTemplateMapping: models.SubstitutionMapping,
+
+# Common
+models.Metadata: models.Metadata,
+models.Attribute: models.Attribute,
+models.Property: models.Property,
+models.Input: models.Input,
+models.Output: models.Output,
+models.Configuration: models.Configuration,
+models.Argument: models.Argument,
+models.Type: models.Type
+}
+
+def __init__(self, model_storage=None, *args, **kwargs):
+# TODO: model storage is required only for the list of plugins, 
can we get it
+# somewhere else?
+super(Topology, self).__init__(*args, **kwargs)
+self._model_storage = model_storage
+self._handlers = dict(self._init_handlers(instance_handler),
+  **self._init_handlers(template_handler))
+
+@staticmethod
+def _init_handlers(module_):
+handlers = {}
+for attribute_name in dir(module_):
+if attribute_name.startswith('_'):
+continue
+attribute = getattr(module_, attribute_name)
+if isinstance(attribute, type) and issubclass(attribute, 
common._Handler):
+handlers[getattr(models, attribute_name)] = attribute
+return handlers
+
+def instantiate(self, model, **kwargs):
+"""
+all handlers used by instantiate should hold a tuple as value 
(handler, instnace_cls)
+:param model:
+:param kwargs:
+:return:
+"""
+if isinstance(model, dict):
+return dict((name, self.instantiate(value, **kwargs))
+for name, value in model.iteritems())
+elif isinstance(model, list):
+return list(self.instantiate(value, **kwargs) for value in 
model)
+elif model is not None:
+_handler = self._handlers.get(model.__class__)
--- End diff --

`self._handlers[model.__class__]`
In the other also.


---
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.
---


[GitHub] incubator-ariatosca pull request #189: ARIA-174 Refactor instantiation phase

2017-08-01 Thread AviaE
Github user AviaE commented on a diff in the pull request:

https://github.com/apache/incubator-ariatosca/pull/189#discussion_r130595525
  
--- Diff: aria/orchestrator/topology/common.py ---
@@ -0,0 +1,52 @@
+# 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.
+
+
+class _Handler(object):
+def __init__(self, topology, template):
+self._topology = topology
+self._model = template
+
+def _coerce(self, *templates, **kwargs):
+for template in templates:
+self._topology.coerce(template)
+
+def coerce(self):
+pass
--- End diff --

raise `NotImplementedError`?


---
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.
---


[GitHub] incubator-ariatosca pull request #189: ARIA-174 Refactor instantiation phase

2017-08-01 Thread AviaE
Github user AviaE commented on a diff in the pull request:

https://github.com/apache/incubator-ariatosca/pull/189#discussion_r130606598
  
--- Diff: aria/orchestrator/topology/topology.py ---
@@ -0,0 +1,217 @@
+# 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 ...parser.validation import issue
+from ...modeling import models
+from ...utils import console
+from . import (
+template_handler,
+instance_handler,
+common
+)
+
+
+class Topology(issue.Reporter):
+
+_init_map = {
+models.ServiceTemplate: models.Service,
+models.ArtifactTemplate: models.Artifact,
+models.CapabilityTemplate: models.Capability,
+models.GroupTemplate: models.Group,
+models.InterfaceTemplate: models.Interface,
+models.NodeTemplate: models.Node,
+models.PolicyTemplate: models.Policy,
+models.SubstitutionTemplate: models.Substitution,
+models.RelationshipTemplate: models.Relationship,
+models.OperationTemplate: models.Operation,
+models.RequirementTemplate: None,
+models.SubstitutionTemplateMapping: models.SubstitutionMapping,
+
+# Common
+models.Metadata: models.Metadata,
+models.Attribute: models.Attribute,
+models.Property: models.Property,
+models.Input: models.Input,
+models.Output: models.Output,
+models.Configuration: models.Configuration,
+models.Argument: models.Argument,
+models.Type: models.Type
+}
+
+def __init__(self, model_storage=None, *args, **kwargs):
+# TODO: model storage is required only for the list of plugins, 
can we get it
+# somewhere else?
+super(Topology, self).__init__(*args, **kwargs)
+self._model_storage = model_storage
+self._handlers = dict(self._init_handlers(instance_handler),
+  **self._init_handlers(template_handler))
+
+@staticmethod
+def _init_handlers(module_):
--- End diff --

Maybe document by saying at least what is the return value, and why.


---
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.
---


[GitHub] incubator-ariatosca pull request #189: ARIA-174 Refactor instantiation phase

2017-08-01 Thread AviaE
Github user AviaE commented on a diff in the pull request:

https://github.com/apache/incubator-ariatosca/pull/189#discussion_r130599473
  
--- Diff: aria/orchestrator/topology/instance_handler.py ---
@@ -0,0 +1,644 @@
+# 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 ... parser.modeling import context
+from ... modeling import models
+from ... utils import formatting
+from .. import execution_plugin
+from .. import decorators
+from . import common
+
+
+class Artifact(common._InstanceHandlerMixin):
+
+def coerce(self, **kwargs):
+self._topology.coerce(self._model.properties, **kwargs)
+
+def validate(self, **kwargs):
+self._topology.validate(self._model.properties)
+
+def dump(self, out_stream):
+with out_stream.indent():
+out_stream.write(out_stream.node(self._model.name))
+out_stream.write(out_stream.meta(self._model.description))
+with out_stream.indent():
+out_stream.write('Artifact type: 
{0}'.format(out_stream.type(
+self._model.type.name)))
+out_stream.write('Source path: {0}'.format(
+out_stream.literal(self._model.source_path)))
+if self._model.target_path is not None:
+out_stream.write('Target path: {0}'.format(
+out_stream.literal(self._model.target_path)))
+if self._model.repository_url is not None:
+out_stream.write('Repository URL: {0}'.format(
+out_stream.literal(self._model.repository_url)))
+if self._model.repository_credential:
+out_stream.write('Repository credential: {0}'.format(
+
out_stream.literal(self._model.repository_credential)))
+self._topology.dump(self._model.properties, out_stream, 
'Properties')
+
+
+class Capability(common._InstanceHandlerMixin):
+def coerce(self, **kwargs):
+self._topology.coerce(self._model.properties, **kwargs)
+
+def validate(self, **kwargs):
+self._topology.validate(self._model.properties)
+
+def dump(self, out_stream):
+out_stream.write(out_stream.node(self._model.name))
+with out_stream.indent():
+out_stream.write('Type: 
{0}'.format(out_stream.type(self._model.type.name)))
+out_stream.write('Occurrences: {0:d} ({1:d}{2})'.format(
+self._model.occurrences,
+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'))
+self._topology.dump(self._model.properties, out_stream, 
'Properties')
+
+
+class Group(common._OperatorHolderHandlerMixin):
+
+def coerce(self, **kwargs):
+self._coerce(self._model.properties, self._model.interfaces, 
**kwargs)
+
+def validate(self, **kwargs):
+self._validate(self._model.properties,
+   self._model.interfaces)
+
+def dump(self, out_stream):
+out_stream.write('Group: 
{0}'.format(out_stream.node(self._model.name)))
+with out_stream.indent():
+out_stream.write('Type: 
{0}'.format(out_stream.type(self._model.type.name)))
+self._topology.dump(self._model.properties, out_stream, 
'Properties')
+self._topology.dump(self._model.interfaces, out_stream, 
'Interfaces')
+if self._model.nodes:
+out_stream.write('Member nodes:')
+with out_stream.indent():
+for node in self._model.nodes:
+out_stream.write(out_stream.node(node.name))
+
+def configure_operations(self):
+for interface in self._model.interfaces.values():
 

[GitHub] incubator-ariatosca pull request #189: ARIA-174 Refactor instantiation phase

2017-08-01 Thread AviaE
Github user AviaE commented on a diff in the pull request:

https://github.com/apache/incubator-ariatosca/pull/189#discussion_r130586353
  
--- Diff: aria/core.py ---
@@ -122,6 +118,8 @@ def delete_service(self, service_id, force=False):
 def _parse_service_template(service_template_path):
 context = consumption.ConsumptionContext()
 context.presentation.location = UriLocation(service_template_path)
+# TODO: this is the last place which uses the consumer chains 
(since read is a proper Parser
--- End diff --

this comment does not explain that you didn't change this section because 
it was not in the scope of refactoring instantiation.


---
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.
---


[GitHub] incubator-ariatosca pull request #189: ARIA-174 Refactor instantiation phase

2017-08-01 Thread AviaE
Github user AviaE commented on a diff in the pull request:

https://github.com/apache/incubator-ariatosca/pull/189#discussion_r130595794
  
--- Diff: aria/orchestrator/topology/common.py ---
@@ -0,0 +1,52 @@
+# 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.
+
+
+class _Handler(object):
+def __init__(self, topology, template):
+self._topology = topology
+self._model = template
+
+def _coerce(self, *templates, **kwargs):
+for template in templates:
+self._topology.coerce(template)
+
+def coerce(self):
+pass
+
+def validate(self, **kwargs):
+pass
+
+def _validate(self, *templates, **kwargs):
+for template in templates:
+self._topology.validate(template)
+
+def dump(self, out_stream):
+pass
+
+
+class _TemplateHandlerMixin(_Handler):
+
+def instantiate(self, instance_cls):
+raise NotImplementedError
+
+
+class _InstanceHandlerMixin(_Handler):
+pass
+
+
+class _OperatorHolderHandlerMixin(_Handler):
--- End diff --

`OperationHolderHandlerMixin`, and please think of a better word than 
`Holder`.


---
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.
---


[GitHub] incubator-ariatosca pull request #188: ARIA-324 Refactor ctx proxy access

2017-07-30 Thread AviaE
Github user AviaE commented on a diff in the pull request:

https://github.com/apache/incubator-ariatosca/pull/188#discussion_r130244198
  
--- Diff: tests/orchestrator/execution_plugin/test_ctx_proxy_server.py ---
@@ -39,26 +39,26 @@ def test_dict_prop_access_get_key(self, server):
 assert response == 'value1'
 
 def test_dict_prop_access_get_key_nested(self, server):
-response = self.request(server, 'node', 'properties', 
'prop2.nested_prop1')
+response = self.request(server, 'node', 'properties', 'prop2', 
'nested_prop1')
 assert response == 'nested_value1'
 
 def test_dict_prop_access_get_with_list_index(self, server):
-response = self.request(server, 'node', 'properties', 
'prop3[2].value')
+response = self.request(server, 'node', 'properties', 'prop3', 2, 
'value')
 assert response == 'value_2'
 
--- End diff --

Add a test for modifying a list element.


---
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.
---


[GitHub] incubator-ariatosca pull request #188: ARIA-324 Refactor ctx proxy access

2017-07-30 Thread AviaE
Github user AviaE commented on a diff in the pull request:

https://github.com/apache/incubator-ariatosca/pull/188#discussion_r130244114
  
--- Diff: aria/orchestrator/execution_plugin/ctx_proxy/server.py ---
@@ -150,43 +150,101 @@ def __exit__(self, *args, **kwargs):
 self.close()
 
 
-def _process_ctx_request(ctx, args):
+def _process_ctx_request(ctx, args): # pylint: 
disable=too-many-branches,too-many-statements
 current = ctx
-num_args = len(args)
 index = 0
+
+try:
+# TODO: should there be a way to escape "=" in case it is needed 
as real argument?
+equals_index = args.index('=')
--- End diff --

Maybe add a comment here that says that `.index` raises a `ValueError` if 
the value is not in the list. And that is why you check for `ValueError` in the 
end. It wasn't clear for @mxmrlv also.
In addition, why does all the other logic under this line is in the `try` 
if it doesn't expected to raise `ValueError`. I understand that extracting this 
part will force you to refactor the order of the statements a bit - just a 
thought =)


---
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.
---


[GitHub] incubator-ariatosca pull request #188: ARIA-324 Refactor ctx proxy access

2017-07-30 Thread AviaE
Github user AviaE commented on a diff in the pull request:

https://github.com/apache/incubator-ariatosca/pull/188#discussion_r130244178
  
--- Diff: aria/orchestrator/execution_plugin/ctx_proxy/server.py ---
@@ -150,43 +150,101 @@ def __exit__(self, *args, **kwargs):
 self.close()
 
 
-def _process_ctx_request(ctx, args):
+def _process_ctx_request(ctx, args): # pylint: 
disable=too-many-branches,too-many-statements
 current = ctx
-num_args = len(args)
 index = 0
+
+try:
+# TODO: should there be a way to escape "=" in case it is needed 
as real argument?
+equals_index = args.index('=')
+if equals_index == 0:
+raise RuntimeError('The "=" argument cannot be first')
+if equals_index != len(args) - 2:
+raise RuntimeError('The "=" argument must be penultimate')
+modifying = True
+modifying_key = args[-3]
+modifying_value = args[-1]
+args = args[:-3]
+except ValueError:
+modifying = False
+modifying_key = None
+modifying_value = None
+
+num_args = len(args)
+
 while index < num_args:
 arg = args[index]
+
+# Object attribute
 attr = _desugar_attr(current, arg)
-if attr:
+if attr is not None:
 current = getattr(current, attr)
-elif isinstance(current, collections.MutableMapping):
-key = arg
-path_dict = _PathDictAccess(current)
-if index + 1 == num_args:
-# read dict prop by path
-value = path_dict.get(key)
-current = value
-elif index + 2 == num_args:
-# set dict prop by path
-value = args[index + 1]
-path_dict.set(key, value)
-current = None
-else:
-raise RuntimeError('Illegal argument while accessing dict')
-break
+
+# List entry
+elif isinstance(current, list) and _is_int(arg):
+current = current[int(arg)]
+
+# Dict (or dict-like object) value
+elif hasattr(current, '__getitem__'):
+if modifying and (not arg in current):
+current[arg] = {}
+current = current[arg]
+
+# Call
 elif callable(current):
-kwargs = {}
-remaining_args = args[index:]
-if isinstance(remaining_args[-1], collections.MutableMapping):
-kwargs = remaining_args[-1]
-remaining_args = remaining_args[:-1]
-current = current(*remaining_args, **kwargs)
-break
+if isinstance(current, functools.partial):
+argspec = inspect.getargspec(current.func)
+# Don't count initial args fulfilled by the partial
+spec_args = argspec.args[len(current.args):]
+# Don't count keyword args fulfilled by the partial
+spec_args = tuple(a for a in spec_args if a not in 
current.keywords)
+else:
+argspec = inspect.getargspec(current)
+spec_args = argspec.args
+
+callable_kwargs = {}
+if isinstance(arg, dict):
+# If the first arg is a dict, treat it as our kwargs
+# TODO: what if the first argument really needs to be a 
dict?
+callable_kwargs = arg
+index += 1
+
+if argspec.varargs is not None:
+# Gobble the rest of the args
+callable_args = args[index:]
+else:
+# Take only what we need
+spec_args = tuple(a for a in spec_args if a not in 
callable_kwargs)
+spec_args_count = len(spec_args)
+if inspect.ismethod(current):
+# Don't count "self" argument
+spec_args_count -= 1
+callable_args = args[index:index + spec_args_count]
+# Note: we might actually have fewer args than the 
args_count, but that could be OK
+# if the user expects subsequent args to have default 
values
+
+args_count = len(callable_args)
+if args_count > 1:
+index += args_count - 1
+
+current = current(*callable_args, **callable_kwargs)
+
 else:
-raise RuntimeError('{0} cannot be processed in 
{1}'.format(arg, args))
+raise 

[GitHub] incubator-ariatosca pull request #187: ARIA-313 Fix handling the `required` ...

2017-07-27 Thread AviaE
Github user AviaE commented on a diff in the pull request:

https://github.com/apache/incubator-ariatosca/pull/187#discussion_r129910938
  
--- Diff: aria/orchestrator/workflows/api/task.py ---
@@ -137,6 +137,11 @@ def __init__(self,
 operation = 
self.actor.interfaces[self.interface_name].operations[self.operation_name]
 self.plugin = operation.plugin
 self.function = operation.function
+
+modeling_utils.validate_required_inputs_are_supplied(
+declared_inputs=operation.inputs,
+supplied_inputs=operation.arguments)
--- End diff --

After consulting with @tliron and reviewing the TOSCA spec, I came to the 
conclusion that the validation of the `required` field of inputs that belong to 
operations and interfaces (as opposed to topology template and workflow inputs) 
should be done in the parsing stage.
This reasoning follows the TOSCA spirit, where anything that is declared in 
the type and is required, must be assigned in the corresponding template.


---
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.
---


[GitHub] incubator-ariatosca pull request #187: ARIA-313 Fix handling the `required` ...

2017-07-26 Thread AviaE
GitHub user AviaE opened a pull request:

https://github.com/apache/incubator-ariatosca/pull/187

ARIA-313 Fix handling the `required` field of inputs

I split the logic of merging provided and declared input values into
three steps:

1. Validate that no undeclared inputs were provided.
2. Validate that all required inputs were provided with a value.
3. The actual merging process, which includes type checking.

You can merge this pull request into a Git repository by running:

$ git pull https://github.com/apache/incubator-ariatosca 
ARIA-313-fix-handling-the-required-field-of-inputs

Alternatively you can review and apply these changes as the patch at:

https://github.com/apache/incubator-ariatosca/pull/187.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

This closes #187


commit fd380f44888aa2b18209a831d0855547ba1634bb
Author: Avia Efrat <a...@gigaspaces.com>
Date:   2017-07-26T12:11:21Z

ARIA-313 Fix handling the `required` field of inputs

I split the logic of merging provided and declared input values into
three steps:

1. Validate that no undeclared inputs were provided.
2. Validate that all required inputs were provided with a value.
3. The actual merging process, which includes type checking.




---
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.
---


[GitHub] incubator-ariatosca pull request #152: ARIA-166 Update README file

2017-06-12 Thread AviaE
Github user AviaE commented on a diff in the pull request:

https://github.com/apache/incubator-ariatosca/pull/152#discussion_r121370660
  
--- Diff: README.md ---
@@ -4,198 +4,111 @@ ARIA
 [![Build 
Status](https://travis-ci.org/apache/incubator-ariatosca.svg?branch=master)](https://travis-ci.org/apache/incubator-ariatosca)
 [![Appveyor Build 
Status](https://ci.appveyor.com/api/projects/status/ltv89jk63ahiu306?svg=true)](https://ci.appveyor.com/project/ApacheSoftwareFoundation/incubator-ariatosca/history)
 
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
+[![PyPI 
release](https://img.shields.io/pypi/v/ariatosca.svg?style=plastic)](https://pypi.python.org/pypi/ariatosca)
+![Python 
Versions](https://img.shields.io/pypi/pyversions/ariatosca.svg?style=plastic)
+![Wheel](https://img.shields.io/pypi/wheel/ariatosca.svg?style=plastic)

+![Contributors](https://img.shields.io/github/contributors/apache/incubator-ariatosca.svg?style=plastic)
+[![Open Pull 
Requests](https://img.shields.io/github/issues-pr/apache/incubator-ariatosca.svg?style=plastic)](https://github.com/apache/incubator-ariatosca/pulls)
+[![Closed Pull 
Requests](https://img.shields.io/github/issues-pr-closed-raw/apache/incubator-ariatosca.svg?style=plastic)](https://github.com/apache/incubator-ariatosca/pulls?q=is%3Apr+is%3Aclosed)
 
 
-[ARIA](http://ariatosca.org/) is a minimal TOSCA orchestrator, as well as 
a platform for building
-TOSCA-based products. Its features can be accessed via a well-documented 
Python API.
+[ARIA](http://ariatosca.incubator.apache.org/) is a an open-source, 
lightweight, library and CLI for orchestration that open-source projects can 
consume to build TOSCA-based orchestration solutions for resources and services 
orchestration. It supports NFV and hybrid Cloud scenarios.
 
-On its own, ARIA provides built-in tools for blueprint validation and for 
creating ready-to-run
-service instances. 
+ARIA can be utilized by any organization that wants to implement 
TOSCA-based orchestration in its solutions, whether a multi-cloud enterprise 
application, or an NFV or SDN solution for multiple virtual infrastructure 
managers.
 
-ARIA adheres strictly and meticulously to the
-[TOSCA Simple Profile v1.0 cos01 
specification](http://docs.oasis-open.org/tosca/TOSCA-Simple-Profile-YAML/v1.0/cos01/TOSCA-Simple-Profile-YAML-v1.0-cos01.html),
-providing state-of-the-art validation at seven different levels:
+With ARIA, you can utilize TOSCA's cloud portability out-of-the-box, to 
test and run your applications, from template to deployment. 
 
-
-Platform errors. E.g. network, hardware, or even an internal bug in 
ARIA (let us know,
-   please!).
-Syntax and format errors. E.g. non-compliant YAML, XML, JSON.
-Field validation. E.g. assigning a string where an integer is 
expected, using a list instead of
-   a dict.
-Relationships between fields within a type. This is "grammar" as it 
applies to rules for
-setting the values of fields in relation to each other.
-Relationships between types. E.g. referring to an unknown type, 
causing a type inheritance
-loop.
-Topology. These errors happen if requirements and capabilities cannot 
be matched in order to
-   assemble a valid topology.
-External dependencies. These errors happen if requirement/capability 
matching fails due to
-external resources missing, e.g. the lack of a valid virtual machine, 
API credentials, etc.
- 
-
 
-Validation errors include a plain English message and when relevant the 
exact location (file, row,
-column) of the data the caused the error.
+Installation
+
 
-The ARIA API documentation always links to the relevant section of the 
specification, and likewise
-we provide an annotated version of the specification that links back to 
the API documentation.
+ARIA is [available on PyPI](https://pypi.python.org/pypi/ariatosca).
 
+ARIA requires Python 2.6/2.7. Python 3+ is not currently supported.
 
-Quick Start

+ARIA itself is in a `wheel` format compatible with all platforms. 
+Some dependencies, however, might require compilation (based on a given 
platform), and therefore possibly some system dependencies are required as well.
 
-You need Python 2.6 or 2.7. Python 3+ is not currently supported.
+On Ubuntu or other Debian-based systems:
 
-To install, we recommend using [pip](https://pip.pypa.io/) and a
-[virtualenv](https://virtualenv.pypa.io/en/stable/).
+   sudo apt install python-setuptools python-dev build-essential 
libssl-dev libffi-dev
 
-In Debian-based systems:
+On Archlinux:
 
-   sudo apt install python-setuptools
-   sudo -H easy_i

[GitHub] incubator-ariatosca pull request #152: ARIA-166 Update README file

2017-06-12 Thread AviaE
Github user AviaE commented on a diff in the pull request:

https://github.com/apache/incubator-ariatosca/pull/152#discussion_r121370931
  
--- Diff: README.md ---
@@ -4,198 +4,111 @@ ARIA
 [![Build 
Status](https://travis-ci.org/apache/incubator-ariatosca.svg?branch=master)](https://travis-ci.org/apache/incubator-ariatosca)
 [![Appveyor Build 
Status](https://ci.appveyor.com/api/projects/status/ltv89jk63ahiu306?svg=true)](https://ci.appveyor.com/project/ApacheSoftwareFoundation/incubator-ariatosca/history)
 
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
+[![PyPI 
release](https://img.shields.io/pypi/v/ariatosca.svg?style=plastic)](https://pypi.python.org/pypi/ariatosca)
+![Python 
Versions](https://img.shields.io/pypi/pyversions/ariatosca.svg?style=plastic)
+![Wheel](https://img.shields.io/pypi/wheel/ariatosca.svg?style=plastic)

+![Contributors](https://img.shields.io/github/contributors/apache/incubator-ariatosca.svg?style=plastic)
+[![Open Pull 
Requests](https://img.shields.io/github/issues-pr/apache/incubator-ariatosca.svg?style=plastic)](https://github.com/apache/incubator-ariatosca/pulls)
+[![Closed Pull 
Requests](https://img.shields.io/github/issues-pr-closed-raw/apache/incubator-ariatosca.svg?style=plastic)](https://github.com/apache/incubator-ariatosca/pulls?q=is%3Apr+is%3Aclosed)
 
 
-[ARIA](http://ariatosca.org/) is a minimal TOSCA orchestrator, as well as 
a platform for building
-TOSCA-based products. Its features can be accessed via a well-documented 
Python API.
+[ARIA](http://ariatosca.incubator.apache.org/) is a an open-source, 
lightweight, library and CLI for orchestration that open-source projects can 
consume to build TOSCA-based orchestration solutions for resources and services 
orchestration. It supports NFV and hybrid Cloud scenarios.
 
-On its own, ARIA provides built-in tools for blueprint validation and for 
creating ready-to-run
-service instances. 
+ARIA can be utilized by any organization that wants to implement 
TOSCA-based orchestration in its solutions, whether a multi-cloud enterprise 
application, or an NFV or SDN solution for multiple virtual infrastructure 
managers.
 
-ARIA adheres strictly and meticulously to the
-[TOSCA Simple Profile v1.0 cos01 
specification](http://docs.oasis-open.org/tosca/TOSCA-Simple-Profile-YAML/v1.0/cos01/TOSCA-Simple-Profile-YAML-v1.0-cos01.html),
-providing state-of-the-art validation at seven different levels:
+With ARIA, you can utilize TOSCA's cloud portability out-of-the-box, to 
test and run your applications, from template to deployment. 
 
-
-Platform errors. E.g. network, hardware, or even an internal bug in 
ARIA (let us know,
-   please!).
-Syntax and format errors. E.g. non-compliant YAML, XML, JSON.
-Field validation. E.g. assigning a string where an integer is 
expected, using a list instead of
-   a dict.
-Relationships between fields within a type. This is "grammar" as it 
applies to rules for
-setting the values of fields in relation to each other.
-Relationships between types. E.g. referring to an unknown type, 
causing a type inheritance
-loop.
-Topology. These errors happen if requirements and capabilities cannot 
be matched in order to
-   assemble a valid topology.
-External dependencies. These errors happen if requirement/capability 
matching fails due to
-external resources missing, e.g. the lack of a valid virtual machine, 
API credentials, etc.
- 
-
 
-Validation errors include a plain English message and when relevant the 
exact location (file, row,
-column) of the data the caused the error.
+Installation
+
 
-The ARIA API documentation always links to the relevant section of the 
specification, and likewise
-we provide an annotated version of the specification that links back to 
the API documentation.
+ARIA is [available on PyPI](https://pypi.python.org/pypi/ariatosca).
 
+ARIA requires Python 2.6/2.7. Python 3+ is not currently supported.
 
-Quick Start

+ARIA itself is in a `wheel` format compatible with all platforms. 
+Some dependencies, however, might require compilation (based on a given 
platform), and therefore possibly some system dependencies are required as well.
 
-You need Python 2.6 or 2.7. Python 3+ is not currently supported.
+On Ubuntu or other Debian-based systems:
 
-To install, we recommend using [pip](https://pip.pypa.io/) and a
-[virtualenv](https://virtualenv.pypa.io/en/stable/).
+   sudo apt install python-setuptools python-dev build-essential 
libssl-dev libffi-dev
 
-In Debian-based systems:
+On Archlinux:
 
-   sudo apt install python-setuptools
-   sudo -H easy_i

[GitHub] incubator-ariatosca pull request #147: ARIA 275 Update nfv profile to csd04

2017-06-05 Thread AviaE
GitHub user AviaE opened a pull request:

https://github.com/apache/incubator-ariatosca/pull/147

ARIA 275 Update nfv profile to csd04



You can merge this pull request into a Git repository by running:

$ git pull https://github.com/apache/incubator-ariatosca 
ARIA-275-update-NFV-profile-to-csd04

Alternatively you can review and apply these changes as the patch at:

https://github.com/apache/incubator-ariatosca/pull/147.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

This closes #147


commit 5660d5181d4db234d0c5aa79b2ff6ce965fd1a3a
Author: Avia Efrat <a...@gigaspaces.com>
Date:   2017-06-04T19:11:10Z

Fixed WD03, Rev01 (2016-7-29)

Also fixed a typo that repeated itself.

commit caa535e515c7e1e27c32be6e3341f0e3c0163284
Author: Avia Efrat <a...@gigaspaces.com>
Date:   2017-06-05T13:21:19Z

Fixed WD04, Rev02 (2016-9-6) and WD04, Rev03 (2016-11-7)

commit 7d5a157361bfe52b73141c3b3bda256dc626311e
Author: Avia Efrat <a...@gigaspaces.com>
Date:   2017-06-05T13:36:52Z

Fixed WD04, Rev04 (2016-11-14) and WD04, Rev05 (2017-1-17)

commit bd577f5935760f77b546c0bb2f4a9c436e3dc183
Author: Avia Efrat <a...@gigaspaces.com>
Date:   2017-06-05T21:30:13Z

Add tosca.nodes.nfv.VDU.Compute and tosca.nodes.nfv.VDU.VirtualStorage

commit 49373efa0361e4354f64ffd08a84adab76f73e04
Author: Avia Efrat <a...@gigaspaces.com>
Date:   2017-06-05T21:39:54Z

Add tosca.capabilites.nfv.VirtualCompute

commit fba9d3123621af808c885091dcd32dbddae6248b
Author: Avia Efrat <a...@gigaspaces.com>
Date:   2017-06-05T21:45:31Z

Remove tosca.nodes.nfv.FP, as it does not appear in csd04

commit 636244cac33590baf17edf1efa6e6b1de4f5168e
Author: Avia Efrat <a...@gigaspaces.com>
Date:   2017-06-05T21:50:47Z

Removed the virtual link (VL) node types, as they do not appear in csd04

commit 1d855472b9181a86b92aafa7ccbd899660c2a269
Author: Avia Efrat <a...@gigaspaces.com>
Date:   2017-06-05T22:05:13Z

remove two relationship types

- tosca.relationships.nfv.ForwardsTo
- tosca.relationships.nfv.VirtualLinksTo

They are not present in csd04.
The changelog at the end of csd04 states:
"Deleted NSD related content, v1.0 will only cover VNFD model."
The second relationship was a part of the NSD model.
The first relationship was a part of the VNFFGD model, which probably
also got deleted, since it is not the VNFD model.

commit d42ebb1c13fffa35e69a6b34ccd7605c267db8b3
Author: Avia Efrat <a...@gigaspaces.com>
Date:   2017-06-05T22:26:08Z

Remove two capability types

- tosca.capabilities.nfv.Forwarder
- tosca.capabilities.nfv.VirtualLinkable

They are not present in csd04.
The changelog at the end of csd04 states:
"Deleted NSD related content, v1.0 will only cover VNFD model."
The second capability was a part of the NSD model.
The first capability was a part of the VNFFGD model, which probably
also got deleted, since it is not the VNFD model.

commit ee2a16e61446ac3f61f7679181d3ef6f55b98fd9
Author: Avia Efrat <a...@gigaspaces.com>
Date:   2017-06-05T22:30:48Z

Remove tosca.groups.nfv.VNFFG

It is  not present in csd04.
The changelog at the end of csd04 states:
"Deleted NSD related content, v1.0 will only cover VNFD model."
tosca.groups.nfv.VNFFG was a part of the VNFFGD model, which probably
also got deleted, since it is not the VNFD model.




---
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.
---


[GitHub] incubator-ariatosca pull request #146: ARIA-199 Add "services outputs" CLI c...

2017-06-04 Thread AviaE
Github user AviaE commented on a diff in the pull request:

https://github.com/apache/incubator-ariatosca/pull/146#discussion_r120009954
  
--- Diff: aria/cli/commands/services.py ---
@@ -192,17 +192,17 @@ def outputs(service_name, model_storage, logger):
 """
 logger.info('Showing outputs for service {0}...'.format(service_name))
 service = model_storage.service.get_by_name(service_name)
-#TODO fix this section..
-outputs_def = service.outputs
-response = model_storage.service.outputs.get(service_name)
-outputs_ = StringIO()
-for output_name, output in response.outputs.iteritems():
-outputs_.write(' - "{0}":{1}'.format(output_name, os.linesep))
-description = outputs_def[output_name].get('description', '')
-outputs_.write(' Description: {0}{1}'.format(description,
- os.linesep))
-outputs_.write(' Value: {0}{1}'.format(output, os.linesep))
-logger.info(outputs_.getvalue())
+
+if service.outputs:
+outputs_ = StringIO()
+for output_name, output in service.outputs.iteritems():
+outputs_.write(' - "{0}":{1}'.format(output_name, os.linesep))
+outputs_.write(' Description: 
{0}{1}'.format(output.description,
--- End diff --

You can put `os.linesep` in the same line as `Description`, it is short 
enough, and consistent with the other lines.


---
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.
---


[GitHub] incubator-ariatosca pull request #146: ARIA-199 Add "services outputs" CLI c...

2017-06-04 Thread AviaE
Github user AviaE commented on a diff in the pull request:

https://github.com/apache/incubator-ariatosca/pull/146#discussion_r120009903
  
--- Diff: tests/mock/models.py ---
@@ -96,6 +97,9 @@ def 
create_service_with_dependencies(include_execution=False,
 if include_input:
 input = create_parameter(name='input1', value='value1')
 service.inputs = {'input1': input}
+if include_output:
--- End diff --

Now, that ARIA-180 was merged, we have a dedicated `create_input` function.
Similarly, please add a `create_output` function =)
In addition, as in `services outputs` we also print the description of the 
output, so it would be nice to add the description as a parameter to the 
`create_output` function, and to check for the existence of that printed 
description in the console output (`logger output string`).

On another note, According to the TOSCA spec, inputs also have a 
description, and the is not addressed in the current `create_input` and tests 
for `services outputs`. You have me permission [:)] to fix it in the context of 
this commit, as it is very closely related to it. If you prefer not to, it will 
be addressed in this JIRA: https://issues.apache.org/jira/browse/ARIA-192 ("Fix 
output inconsistencies in CLI").


---
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.
---


[GitHub] incubator-ariatosca pull request #142: ARIA 180 convert parameter to one to ...

2017-06-04 Thread AviaE
Github user AviaE commented on a diff in the pull request:

https://github.com/apache/incubator-ariatosca/pull/142#discussion_r119667468
  
--- Diff: aria/modeling/mixins.py ---
@@ -140,3 +144,211 @@ class TemplateModelMixin(InstanceModelMixin):
 
 def instantiate(self, container):
 raise NotImplementedError
+
+
+class ParameterMixin(TemplateModelMixin, caching.HasCachedMethods):
+"""
+Represents a typed value. The value can contain nested intrinsic 
functions.
+
+This model can be used as the ``container_holder`` argument for 
:func:`functions.evaluate`.
+
+:ivar name: Name
+:vartype name: basestring
+:ivar type_name: Type name
+:vartype type_name: basestring
+:ivar value: Value
+:ivar description: Description
+:vartype description: basestring
+"""
+
+__tablename__ = 'parameter'
+
+name = Column(Text)
+type_name = Column(Text)
+description = Column(Text)
+_value = Column(PickleType)
+
+@property
+def value(self):
+value = self._value
+if value is not None:
+evaluation = functions.evaluate(value, self)
+if evaluation is not None:
+value = evaluation.value
+return value
+
+@value.setter
+def value(self, value):
+self._value = value
+
+@property
+@caching.cachedmethod
+def owner(self):
+"""
+The sole owner of this parameter, which is another model that 
relates to it.
+
+*All* parameters should have an owner model. In case this property 
method fails to find
+it, it will raise a ValueError, which should signify an abnormal, 
orphaned parameter.
+"""
+
+# Find first non-null relationship
+for the_relationship in self.__mapper__.relationships:
+v = getattr(self, the_relationship.key)
+if v:
+return v
+
+raise ValueError('orphaned {class_name}: does not have an owner: 
{name}'.format(
+class_name=type(self).__name__, name=self.name))
+
+@property
+@caching.cachedmethod
+def container(self): # pylint: 
disable=too-many-return-statements,too-many-branches
+"""
+The logical container for this parameter, which would be another 
model: service, node,
+group, or policy (or their templates).
+
+The logical container is equivalent to the ``SELF`` keyword used 
by intrinsic functions in
+TOSCA.
+
+*All* parameters should have a container model. In case this 
property method fails to find
+it, it will raise a ValueError, which should signify an abnormal, 
orphaned parameter.
+"""
+
+from . import models
+
+container = self.owner
+
+# Extract interface from operation
+if isinstance(container, models.Operation):
+container = container.interface
+elif isinstance(container, models.OperationTemplate):
+container = container.interface_template
+
+# Extract from other models
+if isinstance(container, models.Interface):
+container = container.node or container.group or 
container.relationship
+elif isinstance(container, models.InterfaceTemplate):
+container = container.node_template or 
container.group_template \
+or container.relationship_template
+elif isinstance(container, models.Capability) or 
isinstance(container, models.Artifact):
+container = container.node
+elif isinstance(container, models.CapabilityTemplate) \
+or isinstance(container, models.ArtifactTemplate):
+container = container.node_template
+elif isinstance(container, models.Task):
+container = container.actor
+
+# Extract node from relationship
+if isinstance(container, models.Relationship):
+container = container.source_node
+elif isinstance(container, models.RelationshipTemplate):
+container = container.requirement_template.node_template
+
+if container is not None:
+return container
+
+raise ValueError('orphaned parameter: does not have a container: 
{0}'.format(self.name))
+
+@property
+@caching.cachedmethod
+def service(self):
+"""
+The :class:`Service` containing this parameter, or None if not 
contained in a 

[GitHub] incubator-ariatosca pull request #142: ARIA 180 convert parameter to one to ...

2017-06-04 Thread AviaE
Github user AviaE commented on a diff in the pull request:

https://github.com/apache/incubator-ariatosca/pull/142#discussion_r120004996
  
--- Diff: aria/modeling/mixins.py ---
@@ -140,3 +144,211 @@ class TemplateModelMixin(InstanceModelMixin):
 
 def instantiate(self, container):
 raise NotImplementedError
+
+
+class ParameterMixin(TemplateModelMixin, caching.HasCachedMethods):
+"""
+Represents a typed value. The value can contain nested intrinsic 
functions.
+
+This model can be used as the ``container_holder`` argument for 
:func:`functions.evaluate`.
+
+:ivar name: Name
+:vartype name: basestring
+:ivar type_name: Type name
+:vartype type_name: basestring
+:ivar value: Value
+:ivar description: Description
+:vartype description: basestring
+"""
+
+__tablename__ = 'parameter'
+
+name = Column(Text)
+type_name = Column(Text)
+description = Column(Text)
+_value = Column(PickleType)
+
+@property
+def value(self):
+value = self._value
+if value is not None:
+evaluation = functions.evaluate(value, self)
+if evaluation is not None:
+value = evaluation.value
+return value
+
+@value.setter
+def value(self, value):
+self._value = value
+
+@property
+@caching.cachedmethod
+def owner(self):
+"""
+The sole owner of this parameter, which is another model that 
relates to it.
+
+*All* parameters should have an owner model. In case this property 
method fails to find
+it, it will raise a ValueError, which should signify an abnormal, 
orphaned parameter.
+"""
+
+# Find first non-null relationship
+for the_relationship in self.__mapper__.relationships:
+v = getattr(self, the_relationship.key)
+if v:
+return v
+
+raise ValueError('orphaned {class_name}: does not have an owner: 
{name}'.format(
+class_name=type(self).__name__, name=self.name))
+
+@property
+@caching.cachedmethod
+def container(self): # pylint: 
disable=too-many-return-statements,too-many-branches
+"""
+The logical container for this parameter, which would be another 
model: service, node,
+group, or policy (or their templates).
+
+The logical container is equivalent to the ``SELF`` keyword used 
by intrinsic functions in
+TOSCA.
+
+*All* parameters should have a container model. In case this 
property method fails to find
+it, it will raise a ValueError, which should signify an abnormal, 
orphaned parameter.
+"""
+
+from . import models
+
+container = self.owner
+
+# Extract interface from operation
+if isinstance(container, models.Operation):
+container = container.interface
+elif isinstance(container, models.OperationTemplate):
+container = container.interface_template
+
+# Extract from other models
+if isinstance(container, models.Interface):
+container = container.node or container.group or 
container.relationship
+elif isinstance(container, models.InterfaceTemplate):
+container = container.node_template or 
container.group_template \
+or container.relationship_template
+elif isinstance(container, models.Capability) or 
isinstance(container, models.Artifact):
+container = container.node
+elif isinstance(container, models.CapabilityTemplate) \
+or isinstance(container, models.ArtifactTemplate):
+container = container.node_template
+elif isinstance(container, models.Task):
+container = container.actor
+
+# Extract node from relationship
+if isinstance(container, models.Relationship):
+container = container.source_node
+elif isinstance(container, models.RelationshipTemplate):
+container = container.requirement_template.node_template
+
+if container is not None:
+return container
+
+raise ValueError('orphaned parameter: does not have a container: 
{0}'.format(self.name))
+
+@property
+@caching.cachedmethod
+def service(self):
+"""
+The :class:`Service` containing this parameter, or None if not 
contained in a 

[GitHub] incubator-ariatosca pull request #142: ARIA 180 convert parameter to one to ...

2017-06-04 Thread AviaE
Github user AviaE commented on a diff in the pull request:

https://github.com/apache/incubator-ariatosca/pull/142#discussion_r120004728
  
--- Diff: extensions/aria_extension_tosca/simple_v1_0/modeling/__init__.py 
---
@@ -570,22 +578,23 @@ def added_all():
 container.children.append(model)
 
 
-def create_parameter_models_from_values(properties, source_properties):
+def create_parameter_models_from_values(properties, source_properties, 
model_class=None):
+
 if source_properties:
 for property_name, prop in source_properties.iteritems():
-properties[property_name] = Parameter(name=property_name, # 
pylint: disable=unexpected-keyword-arg
-  type_name=prop.type,
-  value=prop.value,
-  
description=prop.description)
+properties[property_name] = model_class(name=property_name, # 
pylint: disable=unexpected-keyword-arg
+type_name=prop.type,
+value=prop.value,
+
description=prop.description)
 
 
 def create_parameter_models_from_assignments(properties, 
source_properties):
--- End diff --

Decide if this is a general function for Parameters, or a specific function 
for Properties.


---
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.
---


[GitHub] incubator-ariatosca pull request #142: ARIA 180 convert parameter to one to ...

2017-06-01 Thread AviaE
GitHub user AviaE opened a pull request:

https://github.com/apache/incubator-ariatosca/pull/142

ARIA 180 convert parameter to one to many



You can merge this pull request into a Git repository by running:

$ git pull https://github.com/apache/incubator-ariatosca 
ARIA-180-convert-parameter-to-one-to-many

Alternatively you can review and apply these changes as the patch at:

https://github.com/apache/incubator-ariatosca/pull/142.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

This closes #142


commit 74cc94eeeb8d113994e7104477d4a7bcd78fc3d6
Author: Avia Efrat <a...@gigaspaces.com>
Date:   2017-05-21T13:28:30Z

add output model

commit 3943ad0b921001ff8f7110618975f16264e1cff0
Author: Avia Efrat <a...@gigaspaces.com>
Date:   2017-05-21T17:10:50Z

Add input model

commit fceceb7dfcb7466d7f150dd7c3962bef73758cdf
Author: Avia Efrat <a...@gigaspaces.com>
Date:   2017-05-22T09:05:30Z

Add property model

commit 05d2b2a0b162076228db334ce33e57b91790e048
Author: Avia Efrat <a...@gigaspaces.com>
Date:   2017-05-24T11:53:20Z

Add output many-to-one relationships

To service template and service.

commit b0d251f43aed556db505fbc552c94ba105345482
Author: Avia Efrat <a...@gigaspaces.com>
Date:   2017-05-24T13:16:37Z

Add input many-to-one relationships

To service template, service, interface template, interface, operation
template, operation, execution, task.

commit 3e562785ce389d2f9d748729a96115cad7f19def
Author: Avia Efrat <a...@gigaspaces.com>
Date:   2017-05-24T14:59:27Z

Add property many-to-one relationships

To:
node template, node,
group template, group,
policy template, policy,
relationship template, relationship,
capability template, capability,
artifact template, artifact.

commit 93c01b9e672f5588b0a5dfeca0e060086d19df2d
Author: Avia Efrat <a...@gigaspaces.com>
Date:   2017-05-24T22:04:11Z

Add attribute model and attribute many-to-one relationships

To node template and node.

commit fdda7573bd82154c621860826523031afa70e9f1
Author: Avia Efrat <a...@gigaspaces.com>
Date:   2017-05-25T16:40:35Z

Clean up the code

commit b7d2df00e27b911f8bda89af3af05ce2cc2b446d
Author: Avia Efrat <a...@gigaspaces.com>
Date:   2017-06-01T14:09:22Z

Add Argument and Configuration models




---
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.
---