[GitHub] incubator-ariatosca pull request #138: ARIA-149 Enhance operation configurat...

2017-05-24 Thread tliron
Github user tliron commented on a diff in the pull request:

https://github.com/apache/incubator-ariatosca/pull/138#discussion_r118375237
  
--- Diff: aria/orchestrator/execution_plugin/instantiation.py ---
@@ -16,107 +16,132 @@
 # TODO: this module will eventually be moved to a new "aria.instantiation" 
package
 
 from ...utils.type import full_type_name
-from ...utils.collections import OrderedDict
+from ...utils.formatting import safe_repr
 from ...parser import validation
 from ...parser.consumption import ConsumptionContext
+from ...modeling.functions import Function
 
 
 def configure_operation(operation):
-configuration = OrderedDict(operation.configuration) if 
operation.configuration else {}
-
-arguments = OrderedDict()
-arguments['script_path'] = operation.implementation
-arguments['process'] = _get_process(configuration.pop('process')) \
-if 'process' in configuration else dict()
-
 host = None
 interface = operation.interface
 if interface.node is not None:
 host = interface.node.host
 elif interface.relationship is not None:
 if operation.relationship_edge is True:
 host = interface.relationship.target_node.host
-else: # either False or None
+else: # either False or None (None meaning that edge was not 
specified)
 host = interface.relationship.source_node.host
 
+_configure_common(operation)
 if host is None:
 _configure_local(operation)
 else:
-_configure_remote(operation, configuration, arguments)
+_configure_remote(operation)
+
+# Any remaining un-handled configuration parameters will become extra 
arguments, available as
+# kwargs in either "run_script_locally" or "run_script_with_ssh"
+for key, value in operation.configuration.iteritems():
+if key not in ('process', 'ssh'):
+operation.arguments[key] = value.instantiate()
 
-# Any remaining unhandled configuration values will become extra 
arguments, available as kwargs
-# in either "run_script_locally" or "run_script_with_ssh"
-arguments.update(configuration)
 
-return arguments
+def _configure_common(operation):
+"""
+Local and remote operations.
+"""
+
+from ...modeling.models import Parameter
+operation.arguments['script_path'] = Parameter.wrap('script_path', 
operation.implementation,
+'Relative path to 
the executable file.')
+operation.arguments['process'] = Parameter.wrap('process', 
_get_process(operation),
+'Sub-process 
configuration.')
+
 
 def _configure_local(operation):
 """
 Local operation.
 """
+
 from . import operations
-operation.implementation = '{0}.{1}'.format(operations.__name__,
-
operations.run_script_locally.__name__)
+operation.function = '{0}.{1}'.format(operations.__name__,
+  
operations.run_script_locally.__name__)
 
 
-def _configure_remote(operation, configuration, arguments):
+def _configure_remote(operation):
 """
 Remote SSH operation via Fabric.
 """
+
+from ...modeling.models import Parameter
+from . import operations
+
+ssh = _get_ssh(operation)
+
+# Defaults
 # TODO: find a way to configure these generally in the service template
 default_user = ''
 default_password = ''
-
-ssh = _get_ssh(configuration.pop('ssh')) if 'ssh' in configuration 
else {}
 if 'user' not in ssh:
 ssh['user'] = default_user
 if ('password' not in ssh) and ('key' not in ssh) and ('key_filename' 
not in ssh):
 ssh['password'] = default_password
 
-arguments['use_sudo'] = ssh.get('use_sudo', False)
-arguments['hide_output'] = ssh.get('hide_output', [])
-arguments['fabric_env'] = {}
+operation.arguments['use_sudo'] = Parameter.wrap('use_sudo', 
ssh.get('use_sudo', False),
--- End diff --

We went through the code together, this happens elsewhere.


---
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 #138: ARIA-149 Enhance operation configurat...

2017-05-24 Thread tliron
Github user tliron commented on a diff in the pull request:

https://github.com/apache/incubator-ariatosca/pull/138#discussion_r118375175
  
--- Diff: extensions/aria_extension_tosca/simple_v1_0/modeling/__init__.py 
---
@@ -384,18 +387,37 @@ def create_operation_template_model(context, 
service_template, operation):
 model.relationship_edge = True
 
 dependencies = implementation.dependencies
+configuration = OrderedDict()
 if dependencies:
 for dependency in dependencies:
 key, value = split_prefix(dependency)
 if key is not None:
-if model.configuration is None:
-model.configuration = {}
-set_nested(model.configuration, key.split('.'), value)
+# Parse as YAML
+try:
+value = yaml.load(value)
+except yaml.parser.MarkedYAMLError as e:
+context.validation.report(
+'YAML parser {0} in operation configuration: 
{1}'
+.format(e.problem, value),
+locator=implementation._locator,
+level=Issue.FIELD)
+continue
--- End diff --

Validation issues accumulate and are displayed in the end. None are 
considered fatal enough to start the parsing, but of course a single error 
means that parsing failed.


---
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 #138: ARIA-149 Enhance operation configurat...

2017-05-24 Thread tliron
Github user tliron commented on a diff in the pull request:

https://github.com/apache/incubator-ariatosca/pull/138#discussion_r118375044
  
--- Diff: 
extensions/aria_extension_tosca/simple_v1_0/modeling/parameters.py ---
@@ -71,6 +72,7 @@ def get_assigned_and_defined_property_values(context, 
presentation, field_name='
 values = OrderedDict()
 
 the_type = presentation._get_type(context)
+field_name_plural = pluralize(field_name)
--- End diff --

Previously we sent the plural as a function argument, but I optimized by 
removing it... just some code cleanup.


---
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 #138: ARIA-149 Enhance operation configurat...

2017-05-24 Thread tliron
Github user tliron commented on a diff in the pull request:

https://github.com/apache/incubator-ariatosca/pull/138#discussion_r118374974
  
--- Diff: 
tests/resources/service-templates/tosca-simple-1.0/node-cellar/node-cellar.yaml 
---
@@ -309,7 +311,7 @@ policy_types:
   client connections cleanly and shut down services. 
 derived_from: aria.Workflow
 properties:
-  implementation:
+  function:
--- End diff --

Correct, changed back.


---
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 #138: ARIA-149 Enhance operation configurat...

2017-05-24 Thread tliron
Github user tliron commented on a diff in the pull request:

https://github.com/apache/incubator-ariatosca/pull/138#discussion_r118374966
  
--- Diff: aria/modeling/exceptions.py ---
@@ -22,9 +22,9 @@ class ModelingException(AriaException):
 """
 
 
-class InputsException(ModelingException):
+class ParameterException(ModelingException):
--- End diff --

Discussed and we agreed that more general is better in this case.


---
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 #138: ARIA-149 Enhance operation configurat...

2017-05-24 Thread ran-z
Github user ran-z commented on a diff in the pull request:

https://github.com/apache/incubator-ariatosca/pull/138#discussion_r118293230
  
--- Diff: aria/modeling/service_instance.py ---
@@ -1728,34 +1732,41 @@ def operation_template(cls):
 def inputs(cls):
 return relationship.many_to_many(cls, 'parameter', 
prefix='inputs', dict_key='name')
 
+@declared_attr
+def configuration(cls):
+return relationship.many_to_many(cls, 'parameter', 
prefix='configuration', dict_key='name')
+
+@declared_attr
+def arguments(cls):
+return relationship.many_to_many(cls, 'parameter', 
prefix='arguments', dict_key='name')
+
 # endregion
 
 description = Column(Text)
 relationship_edge = Column(Boolean)
 implementation = Column(Text)
-configuration = Column(modeling_types.StrictDict(key_cls=basestring))
 dependencies = Column(modeling_types.StrictList(item_cls=basestring))
+function = Column(Text)
 executor = Column(Text)
 max_attempts = Column(Integer)
 retry_interval = Column(Integer)
 
 def configure(self):
-from . import models
-# Note: for workflows (operations attached directly to the 
service) "interface" will be None
-if (self.implementation is None) or (self.interface is None):
+if (self.implementation is None) and (self.function is None):
 return
 
-if self.plugin is None:
-arguments = 
execution_plugin.instantiation.configure_operation(self)
+if (self.plugin is None) and (self.interface is not None):
+# Default to execution plugin ("interface" is None for 
workflow operations)
+execution_plugin.instantiation.configure_operation(self)
 else:
 # In the future plugins may be able to add their own 
"configure_operation" hook that
-# can validate the configuration and otherwise return 
specially derived arguments
-arguments = self.configuration
+# can validate the configuration and otherwise create 
specially derived arguments. For
+# now, we just send all configuration parameters as arguments
+utils.instantiate_dict(self, self.arguments, 
self.configuration)
 
-# Note: the arguments will *override* operation inputs of the same 
name
-if arguments:
-for k, v in arguments.iteritems():
-self.inputs[k] = models.Parameter.wrap(k, v)
--- End diff --

:+1: 


---
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 #133: Convert runtime_properties to attribu...

2017-05-24 Thread mxmrlv
Github user mxmrlv commented on a diff in the pull request:

https://github.com/apache/incubator-ariatosca/pull/133#discussion_r118225634
  
--- Diff: aria/orchestrator/context/operation.py ---
@@ -114,6 +114,7 @@ class NodeOperationContext(BaseOperationContext):
 """
 
 @property
+@common.InstrumentCollection('attributes')
--- End diff --

check adapter / events to make this whole


---
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 #133: Convert runtime_properties to attribu...

2017-05-24 Thread mxmrlv
Github user mxmrlv commented on a diff in the pull request:

https://github.com/apache/incubator-ariatosca/pull/133#discussion_r118219623
  
--- Diff: aria/orchestrator/context/common.py ---
@@ -194,3 +194,242 @@ def _render_resource(self, resource_content, 
variables):
 variables.setdefault('ctx', self)
 resource_template = jinja2.Template(resource_content)
 return resource_template.render(variables)
+
+def _teardown_db_resources(self):
+self.model.log._session.close()
+self.model.log._engine.dispose()
+
+
+class _InstrumentedCollection(object):
+
+def __init__(self,
+ model,
+ parent,
+ field_name=None,
+ item_cls=None,
+ seq=None,
+ is_top_level=True,
+ **kwargs):
+self._model = model
+self._parent = parent
+self._field_name = field_name
+self._item_cls = item_cls
+self._is_top_level = is_top_level
+self._load(seq, **kwargs)
+
+@property
+def _raw(self):
+raise NotImplementedError
+
+def _load(self, seq, **kwargs):
+"""
+Instantiates the object from existing seq.
+
+:param seq: the original sequence to load from
+:return:
+"""
+raise NotImplementedError
+
+def _set(self, key, value):
+"""
+set the changes for the current object (not in the db)
+
+:param key:
+:param value:
+:return:
+"""
+raise NotImplementedError
+
+def _del(self, collection, key):
+raise NotImplementedError
+
+def _instrument(self, key, value):
+"""
+Instruments any collection to track changes (and ease of access)
+:param key:
+:param value:
+:return:
+"""
+if isinstance(value, _InstrumentedCollection):
+return value
+elif isinstance(value, dict):
+instrumentation_cls = _InstrumentedDict
+elif isinstance(value, list):
+instrumentation_cls = _InstrumentedList
+else:
+return value
+
+return instrumentation_cls(self._model, self, key, self._item_cls, 
value, False)
+
+def _raw_value(self, value):
+"""
+Get the raw value.
+:param value:
+:return:
+"""
+if self._is_top_level and isinstance(value, self._item_cls):
+return value.value
+return value
+
+def _encapsulate_value(self, key, value):
+"""
+Create a new item cls if needed.
+:param key:
+:param value:
+:return:
+"""
+if isinstance(value, self._item_cls):
+return value
+# If it is not wrapped
+return self._item_cls.wrap(key, value)
+
+def __setitem__(self, key, value):
+"""
+Update the values in both the local and the db locations.
+:param key:
+:param value:
+:return:
+"""
+self._set(key, value)
+if self._is_top_level:
+# We are at the top level
+field = getattr(self._parent, self._field_name)
+mapi = getattr(self._model, self._item_cls.__modelname__)
+value = self._set_field(field,
+key,
+value if key in field else 
self._encapsulate_value(key, value))
+mapi.update(value)
+else:
+# We are not at the top level
+self._set_field(self._parent, self._field_name, self)
+
+def _set_field(self, collection, key, value):
+"""
+enables updating the current change in the ancestors
+:param collection: the collection to change
+:param key: the key for the specific field
+:param value: the new value
+:return:
+"""
+if isinstance(value, _InstrumentedCollection):
+value = value._raw
+if key in collection and isinstance(collection[key], 
self._item_cls):
+if isinstance(collection[key], self.PYTHON_TYPE):
+self._del(collection, key)
+collection[key].value = value
+else:
+collection[key] = value
+return collection[key]
+
+def __copy__(self):
+return self._raw
+
+def __deepcopy__(self, *args, **kwargs):
+return self._raw
  

[GitHub] incubator-ariatosca pull request #133: Convert runtime_properties to attribu...

2017-05-24 Thread mxmrlv
Github user mxmrlv commented on a diff in the pull request:

https://github.com/apache/incubator-ariatosca/pull/133#discussion_r118229764
  
--- Diff: aria/orchestrator/context/common.py ---
@@ -194,3 +194,242 @@ def _render_resource(self, resource_content, 
variables):
 variables.setdefault('ctx', self)
 resource_template = jinja2.Template(resource_content)
 return resource_template.render(variables)
+
+def _teardown_db_resources(self):
+self.model.log._session.close()
+self.model.log._engine.dispose()
+
+
+class _InstrumentedCollection(object):
+
+def __init__(self,
+ model,
+ parent,
+ field_name=None,
+ item_cls=None,
+ seq=None,
+ is_top_level=True,
+ **kwargs):
+self._model = model
+self._parent = parent
+self._field_name = field_name
+self._item_cls = item_cls
+self._is_top_level = is_top_level
+self._load(seq, **kwargs)
+
+@property
+def _raw(self):
+raise NotImplementedError
+
+def _load(self, seq, **kwargs):
+"""
+Instantiates the object from existing seq.
+
+:param seq: the original sequence to load from
+:return:
+"""
+raise NotImplementedError
+
+def _set(self, key, value):
+"""
+set the changes for the current object (not in the db)
+
+:param key:
+:param value:
+:return:
+"""
+raise NotImplementedError
+
+def _del(self, collection, key):
+raise NotImplementedError
+
+def _instrument(self, key, value):
+"""
+Instruments any collection to track changes (and ease of access)
+:param key:
+:param value:
+:return:
+"""
+if isinstance(value, _InstrumentedCollection):
+return value
+elif isinstance(value, dict):
+instrumentation_cls = _InstrumentedDict
+elif isinstance(value, list):
+instrumentation_cls = _InstrumentedList
+else:
+return value
+
+return instrumentation_cls(self._model, self, key, self._item_cls, 
value, False)
+
+def _raw_value(self, value):
+"""
+Get the raw value.
+:param value:
+:return:
+"""
+if self._is_top_level and isinstance(value, self._item_cls):
+return value.value
+return value
+
+def _encapsulate_value(self, key, value):
+"""
+Create a new item cls if needed.
+:param key:
+:param value:
+:return:
+"""
+if isinstance(value, self._item_cls):
+return value
+# If it is not wrapped
+return self._item_cls.wrap(key, value)
+
+def __setitem__(self, key, value):
+"""
+Update the values in both the local and the db locations.
+:param key:
+:param value:
+:return:
+"""
+self._set(key, value)
+if self._is_top_level:
+# We are at the top level
+field = getattr(self._parent, self._field_name)
+mapi = getattr(self._model, self._item_cls.__modelname__)
+value = self._set_field(field,
+key,
+value if key in field else 
self._encapsulate_value(key, value))
+mapi.update(value)
+else:
+# We are not at the top level
+self._set_field(self._parent, self._field_name, self)
+
+def _set_field(self, collection, key, value):
+"""
+enables updating the current change in the ancestors
+:param collection: the collection to change
+:param key: the key for the specific field
+:param value: the new value
+:return:
+"""
+if isinstance(value, _InstrumentedCollection):
+value = value._raw
+if key in collection and isinstance(collection[key], 
self._item_cls):
+if isinstance(collection[key], self.PYTHON_TYPE):
+self._del(collection, key)
+collection[key].value = value
+else:
+collection[key] = value
+return collection[key]
+
+def __copy__(self):
+return self._raw
+
+def __deepcopy__(self, *args, **kwargs):
+return self._raw
  

[GitHub] incubator-ariatosca pull request #133: Convert runtime_properties to attribu...

2017-05-24 Thread mxmrlv
Github user mxmrlv commented on a diff in the pull request:

https://github.com/apache/incubator-ariatosca/pull/133#discussion_r118216000
  
--- Diff: aria/orchestrator/workflows/executor/process.py ---
@@ -369,32 +294,23 @@ def _main():
 operation_inputs = arguments['operation_inputs']
 context_dict = arguments['context']
 
-# This is required for the instrumentation work properly.
-# See docstring of `remove_mutable_association_listener` for further 
details
-modeling_types.remove_mutable_association_listener()
 try:
 ctx = 
context_dict['context_cls'].instantiate_from_dict(**context_dict['context'])
 except BaseException as e:
-messenger.failed(exception=e, tracked_changes=None, 
new_instances=None)
+messenger.failed(e)
 return
 
-with instrumentation.track_changes(ctx.model) as instrument:
-try:
-messenger.started()
-_patch_ctx(ctx=ctx, messenger=messenger, instrument=instrument)
-task_func = imports.load_attribute(implementation)
-aria.install_aria_extensions()
-for decorate in process_executor.decorate():
-task_func = decorate(task_func)
-task_func(ctx=ctx, **operation_inputs)
-messenger.succeeded(tracked_changes=instrument.tracked_changes,
-new_instances=instrument.new_instances)
-except BaseException as e:
-messenger.failed(exception=e,
- tracked_changes=instrument.tracked_changes,
- new_instances=instrument.new_instances)
-finally:
-instrument.expunge_session()
+try:
+messenger.started()
+task_func = imports.load_attribute(implementation)
+aria.install_aria_extensions()
+for decorate in process_executor.decorate():
+task_func = decorate(task_func)
+task_func(ctx=ctx, **operation_inputs)
+messenger.succeeded()
+except BaseException as e:
+ctx._teardown_db_resources()
--- End diff --

finally: close


---
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 #133: Convert runtime_properties to attribu...

2017-05-24 Thread mxmrlv
Github user mxmrlv commented on a diff in the pull request:

https://github.com/apache/incubator-ariatosca/pull/133#discussion_r118228729
  
--- Diff: aria/orchestrator/context/common.py ---
@@ -194,3 +194,242 @@ def _render_resource(self, resource_content, 
variables):
 variables.setdefault('ctx', self)
 resource_template = jinja2.Template(resource_content)
 return resource_template.render(variables)
+
+def _teardown_db_resources(self):
+self.model.log._session.close()
+self.model.log._engine.dispose()
+
+
+class _InstrumentedCollection(object):
+
+def __init__(self,
+ model,
+ parent,
+ field_name=None,
+ item_cls=None,
+ seq=None,
+ is_top_level=True,
+ **kwargs):
+self._model = model
+self._parent = parent
+self._field_name = field_name
+self._item_cls = item_cls
+self._is_top_level = is_top_level
+self._load(seq, **kwargs)
+
+@property
+def _raw(self):
+raise NotImplementedError
+
+def _load(self, seq, **kwargs):
+"""
+Instantiates the object from existing seq.
+
+:param seq: the original sequence to load from
+:return:
+"""
+raise NotImplementedError
+
+def _set(self, key, value):
+"""
+set the changes for the current object (not in the db)
+
+:param key:
+:param value:
+:return:
+"""
+raise NotImplementedError
+
+def _del(self, collection, key):
+raise NotImplementedError
+
+def _instrument(self, key, value):
+"""
+Instruments any collection to track changes (and ease of access)
+:param key:
+:param value:
+:return:
+"""
+if isinstance(value, _InstrumentedCollection):
+return value
+elif isinstance(value, dict):
+instrumentation_cls = _InstrumentedDict
+elif isinstance(value, list):
+instrumentation_cls = _InstrumentedList
+else:
+return value
+
+return instrumentation_cls(self._model, self, key, self._item_cls, 
value, False)
+
+def _raw_value(self, value):
--- End diff --

make static / class


---
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 #133: Convert runtime_properties to attribu...

2017-05-24 Thread mxmrlv
Github user mxmrlv commented on a diff in the pull request:

https://github.com/apache/incubator-ariatosca/pull/133#discussion_r118221530
  
--- Diff: aria/orchestrator/context/common.py ---
@@ -194,3 +194,242 @@ def _render_resource(self, resource_content, 
variables):
 variables.setdefault('ctx', self)
 resource_template = jinja2.Template(resource_content)
 return resource_template.render(variables)
+
+def _teardown_db_resources(self):
+self.model.log._session.close()
+self.model.log._engine.dispose()
+
+
+class _InstrumentedCollection(object):
+
+def __init__(self,
+ model,
+ parent,
+ field_name=None,
+ item_cls=None,
+ seq=None,
+ is_top_level=True,
+ **kwargs):
+self._model = model
+self._parent = parent
+self._field_name = field_name
+self._item_cls = item_cls
+self._is_top_level = is_top_level
+self._load(seq, **kwargs)
+
+@property
+def _raw(self):
+raise NotImplementedError
+
+def _load(self, seq, **kwargs):
+"""
+Instantiates the object from existing seq.
+
+:param seq: the original sequence to load from
+:return:
+"""
+raise NotImplementedError
+
+def _set(self, key, value):
+"""
+set the changes for the current object (not in the db)
+
+:param key:
+:param value:
+:return:
+"""
+raise NotImplementedError
+
+def _del(self, collection, key):
+raise NotImplementedError
+
+def _instrument(self, key, value):
+"""
+Instruments any collection to track changes (and ease of access)
+:param key:
+:param value:
+:return:
+"""
+if isinstance(value, _InstrumentedCollection):
+return value
+elif isinstance(value, dict):
+instrumentation_cls = _InstrumentedDict
+elif isinstance(value, list):
+instrumentation_cls = _InstrumentedList
+else:
+return value
+
+return instrumentation_cls(self._model, self, key, self._item_cls, 
value, False)
+
+def _raw_value(self, value):
+"""
+Get the raw value.
+:param value:
+:return:
+"""
+if self._is_top_level and isinstance(value, self._item_cls):
+return value.value
+return value
+
+def _encapsulate_value(self, key, value):
+"""
+Create a new item cls if needed.
+:param key:
+:param value:
+:return:
+"""
+if isinstance(value, self._item_cls):
+return value
+# If it is not wrapped
+return self._item_cls.wrap(key, value)
+
+def __setitem__(self, key, value):
+"""
+Update the values in both the local and the db locations.
+:param key:
+:param value:
+:return:
+"""
+self._set(key, value)
+if self._is_top_level:
+# We are at the top level
+field = getattr(self._parent, self._field_name)
+mapi = getattr(self._model, self._item_cls.__modelname__)
+value = self._set_field(field,
+key,
+value if key in field else 
self._encapsulate_value(key, value))
+mapi.update(value)
+else:
+# We are not at the top level
+self._set_field(self._parent, self._field_name, self)
+
+def _set_field(self, collection, key, value):
+"""
+enables updating the current change in the ancestors
+:param collection: the collection to change
+:param key: the key for the specific field
+:param value: the new value
+:return:
+"""
+if isinstance(value, _InstrumentedCollection):
+value = value._raw
+if key in collection and isinstance(collection[key], 
self._item_cls):
+if isinstance(collection[key], self.PYTHON_TYPE):
+self._del(collection, key)
+collection[key].value = value
+else:
+collection[key] = value
+return collection[key]
+
+def __copy__(self):
+return self._raw
+
+def __deepcopy__(self, *args, **kwargs):
+return self._raw
  

[GitHub] incubator-ariatosca pull request #133: Convert runtime_properties to attribu...

2017-05-24 Thread mxmrlv
Github user mxmrlv commented on a diff in the pull request:

https://github.com/apache/incubator-ariatosca/pull/133#discussion_r118229140
  
--- Diff: aria/orchestrator/context/common.py ---
@@ -194,3 +194,242 @@ def _render_resource(self, resource_content, 
variables):
 variables.setdefault('ctx', self)
 resource_template = jinja2.Template(resource_content)
 return resource_template.render(variables)
+
+def _teardown_db_resources(self):
+self.model.log._session.close()
+self.model.log._engine.dispose()
+
+
+class _InstrumentedCollection(object):
+
+def __init__(self,
+ model,
+ parent,
+ field_name=None,
+ item_cls=None,
+ seq=None,
+ is_top_level=True,
+ **kwargs):
+self._model = model
+self._parent = parent
+self._field_name = field_name
+self._item_cls = item_cls
+self._is_top_level = is_top_level
+self._load(seq, **kwargs)
+
+@property
+def _raw(self):
+raise NotImplementedError
+
+def _load(self, seq, **kwargs):
+"""
+Instantiates the object from existing seq.
+
+:param seq: the original sequence to load from
+:return:
+"""
+raise NotImplementedError
+
+def _set(self, key, value):
+"""
+set the changes for the current object (not in the db)
+
+:param key:
+:param value:
+:return:
+"""
+raise NotImplementedError
+
+def _del(self, collection, key):
+raise NotImplementedError
+
+def _instrument(self, key, value):
+"""
+Instruments any collection to track changes (and ease of access)
+:param key:
+:param value:
+:return:
+"""
+if isinstance(value, _InstrumentedCollection):
+return value
+elif isinstance(value, dict):
+instrumentation_cls = _InstrumentedDict
+elif isinstance(value, list):
+instrumentation_cls = _InstrumentedList
+else:
+return value
+
+return instrumentation_cls(self._model, self, key, self._item_cls, 
value, False)
+
+def _raw_value(self, value):
+"""
+Get the raw value.
+:param value:
+:return:
+"""
+if self._is_top_level and isinstance(value, self._item_cls):
+return value.value
+return value
+
+def _encapsulate_value(self, key, value):
+"""
+Create a new item cls if needed.
+:param key:
+:param value:
+:return:
+"""
+if isinstance(value, self._item_cls):
+return value
+# If it is not wrapped
+return self._item_cls.wrap(key, value)
+
+def __setitem__(self, key, value):
+"""
+Update the values in both the local and the db locations.
+:param key:
+:param value:
+:return:
+"""
+self._set(key, value)
+if self._is_top_level:
+# We are at the top level
+field = getattr(self._parent, self._field_name)
+mapi = getattr(self._model, self._item_cls.__modelname__)
+value = self._set_field(field,
+key,
+value if key in field else 
self._encapsulate_value(key, value))
+mapi.update(value)
+else:
+# We are not at the top level
+self._set_field(self._parent, self._field_name, self)
+
+def _set_field(self, collection, key, value):
+"""
+enables updating the current change in the ancestors
+:param collection: the collection to change
+:param key: the key for the specific field
+:param value: the new value
+:return:
+"""
+if isinstance(value, _InstrumentedCollection):
+value = value._raw
+if key in collection and isinstance(collection[key], 
self._item_cls):
+if isinstance(collection[key], self.PYTHON_TYPE):
+self._del(collection, key)
+collection[key].value = value
+else:
+collection[key] = value
+return collection[key]
+
+def __copy__(self):
+return self._raw
+
+def __deepcopy__(self, *args, **kwargs):
+return self._raw
  

[GitHub] incubator-ariatosca pull request #133: Convert runtime_properties to attribu...

2017-05-24 Thread mxmrlv
Github user mxmrlv commented on a diff in the pull request:

https://github.com/apache/incubator-ariatosca/pull/133#discussion_r118217431
  
--- Diff: tests/orchestrator/context/test_attribute_suggaring.py ---
@@ -0,0 +1,253 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
--- End diff --

omg


---
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 #133: Convert runtime_properties to attribu...

2017-05-24 Thread mxmrlv
Github user mxmrlv commented on a diff in the pull request:

https://github.com/apache/incubator-ariatosca/pull/133#discussion_r118214665
  
--- Diff: aria/orchestrator/context/common.py ---
@@ -194,3 +194,242 @@ def _render_resource(self, resource_content, 
variables):
 variables.setdefault('ctx', self)
 resource_template = jinja2.Template(resource_content)
 return resource_template.render(variables)
+
+def _teardown_db_resources(self):
--- End diff --

dont be 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 #133: Convert runtime_properties to attribu...

2017-05-24 Thread mxmrlv
Github user mxmrlv commented on a diff in the pull request:

https://github.com/apache/incubator-ariatosca/pull/133#discussion_r118222060
  
--- Diff: aria/orchestrator/context/common.py ---
@@ -194,3 +194,242 @@ def _render_resource(self, resource_content, 
variables):
 variables.setdefault('ctx', self)
 resource_template = jinja2.Template(resource_content)
 return resource_template.render(variables)
+
+def _teardown_db_resources(self):
+self.model.log._session.close()
+self.model.log._engine.dispose()
+
+
+class _InstrumentedCollection(object):
+
+def __init__(self,
+ model,
+ parent,
+ field_name=None,
+ item_cls=None,
+ seq=None,
+ is_top_level=True,
+ **kwargs):
+self._model = model
+self._parent = parent
+self._field_name = field_name
+self._item_cls = item_cls
+self._is_top_level = is_top_level
+self._load(seq, **kwargs)
+
+@property
+def _raw(self):
+raise NotImplementedError
+
+def _load(self, seq, **kwargs):
+"""
+Instantiates the object from existing seq.
+
+:param seq: the original sequence to load from
+:return:
+"""
+raise NotImplementedError
+
+def _set(self, key, value):
+"""
+set the changes for the current object (not in the db)
+
+:param key:
+:param value:
+:return:
+"""
+raise NotImplementedError
+
+def _del(self, collection, key):
+raise NotImplementedError
+
+def _instrument(self, key, value):
+"""
+Instruments any collection to track changes (and ease of access)
+:param key:
+:param value:
+:return:
+"""
+if isinstance(value, _InstrumentedCollection):
+return value
+elif isinstance(value, dict):
+instrumentation_cls = _InstrumentedDict
+elif isinstance(value, list):
+instrumentation_cls = _InstrumentedList
+else:
+return value
+
+return instrumentation_cls(self._model, self, key, self._item_cls, 
value, False)
+
+def _raw_value(self, value):
+"""
+Get the raw value.
+:param value:
+:return:
+"""
+if self._is_top_level and isinstance(value, self._item_cls):
+return value.value
+return value
+
+def _encapsulate_value(self, key, value):
+"""
+Create a new item cls if needed.
+:param key:
+:param value:
+:return:
+"""
+if isinstance(value, self._item_cls):
+return value
+# If it is not wrapped
+return self._item_cls.wrap(key, value)
+
+def __setitem__(self, key, value):
+"""
+Update the values in both the local and the db locations.
+:param key:
+:param value:
+:return:
+"""
+self._set(key, value)
+if self._is_top_level:
+# We are at the top level
+field = getattr(self._parent, self._field_name)
+mapi = getattr(self._model, self._item_cls.__modelname__)
+value = self._set_field(field,
+key,
+value if key in field else 
self._encapsulate_value(key, value))
+mapi.update(value)
+else:
+# We are not at the top level
+self._set_field(self._parent, self._field_name, self)
+
+def _set_field(self, collection, key, value):
+"""
+enables updating the current change in the ancestors
+:param collection: the collection to change
+:param key: the key for the specific field
+:param value: the new value
+:return:
+"""
+if isinstance(value, _InstrumentedCollection):
+value = value._raw
+if key in collection and isinstance(collection[key], 
self._item_cls):
+if isinstance(collection[key], self.PYTHON_TYPE):
+self._del(collection, key)
+collection[key].value = value
+else:
+collection[key] = value
+return collection[key]
+
+def __copy__(self):
+return self._raw
+
+def __deepcopy__(self, *args, **kwargs):
+return self._raw
  

[GitHub] incubator-ariatosca pull request #133: Convert runtime_properties to attribu...

2017-05-24 Thread mxmrlv
Github user mxmrlv commented on a diff in the pull request:

https://github.com/apache/incubator-ariatosca/pull/133#discussion_r118227037
  
--- Diff: aria/orchestrator/context/common.py ---
@@ -194,3 +194,242 @@ def _render_resource(self, resource_content, 
variables):
 variables.setdefault('ctx', self)
 resource_template = jinja2.Template(resource_content)
 return resource_template.render(variables)
+
+def _teardown_db_resources(self):
+self.model.log._session.close()
+self.model.log._engine.dispose()
+
+
+class _InstrumentedCollection(object):
+
+def __init__(self,
+ model,
+ parent,
+ field_name=None,
+ item_cls=None,
+ seq=None,
+ is_top_level=True,
+ **kwargs):
+self._model = model
+self._parent = parent
+self._field_name = field_name
+self._item_cls = item_cls
+self._is_top_level = is_top_level
+self._load(seq, **kwargs)
+
+@property
+def _raw(self):
+raise NotImplementedError
+
+def _load(self, seq, **kwargs):
+"""
+Instantiates the object from existing seq.
+
+:param seq: the original sequence to load from
+:return:
+"""
+raise NotImplementedError
+
+def _set(self, key, value):
+"""
+set the changes for the current object (not in the db)
+
+:param key:
+:param value:
+:return:
+"""
+raise NotImplementedError
+
+def _del(self, collection, key):
+raise NotImplementedError
+
+def _instrument(self, key, value):
+"""
+Instruments any collection to track changes (and ease of access)
+:param key:
+:param value:
+:return:
+"""
+if isinstance(value, _InstrumentedCollection):
+return value
+elif isinstance(value, dict):
+instrumentation_cls = _InstrumentedDict
+elif isinstance(value, list):
+instrumentation_cls = _InstrumentedList
+else:
+return value
+
+return instrumentation_cls(self._model, self, key, self._item_cls, 
value, False)
+
+def _raw_value(self, value):
+"""
+Get the raw value.
+:param value:
+:return:
+"""
+if self._is_top_level and isinstance(value, self._item_cls):
--- End diff --

chnage _item_cls to Parameter


---
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 #133: Convert runtime_properties to attribu...

2017-05-24 Thread mxmrlv
Github user mxmrlv commented on a diff in the pull request:

https://github.com/apache/incubator-ariatosca/pull/133#discussion_r118218187
  
--- Diff: tests/orchestrator/context/test_operation.py ---
@@ -263,7 +263,7 @@ def basic_workflow(graph, **_):
 
 
 @pytest.fixture(params=[
-(thread.ThreadExecutor, {}),
+# (thread.ThreadExecutor, {}),
--- End diff --

uncomment


---
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 #133: Convert runtime_properties to attribu...

2017-05-24 Thread mxmrlv
Github user mxmrlv commented on a diff in the pull request:

https://github.com/apache/incubator-ariatosca/pull/133#discussion_r118215013
  
--- Diff: aria/orchestrator/context/toolbelt.py ---
@@ -34,7 +34,8 @@ def host_ip(self):
 """
 assert isinstance(self._op_context, operation.NodeOperationContext)
 host = self._op_context.node.host
-return host.runtime_properties.get('ip')
+return getattr(host.attributes.get('ip'), 'value', None)
--- End diff --

split


---
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 #133: Convert runtime_properties to attribu...

2017-05-24 Thread mxmrlv
Github user mxmrlv commented on a diff in the pull request:

https://github.com/apache/incubator-ariatosca/pull/133#discussion_r118228547
  
--- Diff: aria/orchestrator/context/common.py ---
@@ -194,3 +194,242 @@ def _render_resource(self, resource_content, 
variables):
 variables.setdefault('ctx', self)
 resource_template = jinja2.Template(resource_content)
 return resource_template.render(variables)
+
+def _teardown_db_resources(self):
+self.model.log._session.close()
+self.model.log._engine.dispose()
+
+
+class _InstrumentedCollection(object):
+
+def __init__(self,
+ model,
+ parent,
+ field_name=None,
+ item_cls=None,
+ seq=None,
+ is_top_level=True,
+ **kwargs):
+self._model = model
+self._parent = parent
+self._field_name = field_name
+self._item_cls = item_cls
+self._is_top_level = is_top_level
+self._load(seq, **kwargs)
+
+@property
+def _raw(self):
+raise NotImplementedError
+
+def _load(self, seq, **kwargs):
+"""
+Instantiates the object from existing seq.
+
+:param seq: the original sequence to load from
+:return:
+"""
+raise NotImplementedError
+
+def _set(self, key, value):
+"""
+set the changes for the current object (not in the db)
+
+:param key:
+:param value:
+:return:
+"""
+raise NotImplementedError
+
+def _del(self, collection, key):
+raise NotImplementedError
+
+def _instrument(self, key, value):
+"""
+Instruments any collection to track changes (and ease of access)
+:param key:
+:param value:
+:return:
+"""
+if isinstance(value, _InstrumentedCollection):
+return value
+elif isinstance(value, dict):
+instrumentation_cls = _InstrumentedDict
+elif isinstance(value, list):
+instrumentation_cls = _InstrumentedList
+else:
+return value
+
+return instrumentation_cls(self._model, self, key, self._item_cls, 
value, False)
+
+def _raw_value(self, value):
+"""
+Get the raw value.
+:param value:
+:return:
+"""
+if self._is_top_level and isinstance(value, self._item_cls):
+return value.value
+return value
+
+def _encapsulate_value(self, key, value):
+"""
+Create a new item cls if needed.
+:param key:
+:param value:
+:return:
+"""
+if isinstance(value, self._item_cls):
+return value
+# If it is not wrapped
+return self._item_cls.wrap(key, value)
+
+def __setitem__(self, key, value):
+"""
+Update the values in both the local and the db locations.
+:param key:
+:param value:
+:return:
+"""
+self._set(key, value)
+if self._is_top_level:
+# We are at the top level
+field = getattr(self._parent, self._field_name)
+mapi = getattr(self._model, self._item_cls.__modelname__)
+value = self._set_field(field,
+key,
+value if key in field else 
self._encapsulate_value(key, value))
+mapi.update(value)
+else:
+# We are not at the top level
+self._set_field(self._parent, self._field_name, self)
+
+def _set_field(self, collection, key, value):
+"""
+enables updating the current change in the ancestors
+:param collection: the collection to change
+:param key: the key for the specific field
+:param value: the new value
+:return:
+"""
+if isinstance(value, _InstrumentedCollection):
+value = value._raw
+if key in collection and isinstance(collection[key], 
self._item_cls):
+if isinstance(collection[key], self.PYTHON_TYPE):
--- End diff --

maybe delete always if key is in collection?


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

[GitHub] incubator-ariatosca pull request #133: Convert runtime_properties to attribu...

2017-05-24 Thread mxmrlv
Github user mxmrlv commented on a diff in the pull request:

https://github.com/apache/incubator-ariatosca/pull/133#discussion_r118220697
  
--- Diff: aria/orchestrator/context/common.py ---
@@ -194,3 +194,242 @@ def _render_resource(self, resource_content, 
variables):
 variables.setdefault('ctx', self)
 resource_template = jinja2.Template(resource_content)
 return resource_template.render(variables)
+
+def _teardown_db_resources(self):
+self.model.log._session.close()
+self.model.log._engine.dispose()
+
+
+class _InstrumentedCollection(object):
+
+def __init__(self,
+ model,
+ parent,
+ field_name=None,
+ item_cls=None,
+ seq=None,
+ is_top_level=True,
+ **kwargs):
+self._model = model
+self._parent = parent
+self._field_name = field_name
+self._item_cls = item_cls
+self._is_top_level = is_top_level
+self._load(seq, **kwargs)
+
+@property
+def _raw(self):
+raise NotImplementedError
+
+def _load(self, seq, **kwargs):
+"""
+Instantiates the object from existing seq.
+
+:param seq: the original sequence to load from
+:return:
+"""
+raise NotImplementedError
+
+def _set(self, key, value):
+"""
+set the changes for the current object (not in the db)
+
+:param key:
+:param value:
+:return:
+"""
+raise NotImplementedError
+
+def _del(self, collection, key):
+raise NotImplementedError
+
+def _instrument(self, key, value):
+"""
+Instruments any collection to track changes (and ease of access)
+:param key:
+:param value:
+:return:
+"""
+if isinstance(value, _InstrumentedCollection):
+return value
+elif isinstance(value, dict):
+instrumentation_cls = _InstrumentedDict
+elif isinstance(value, list):
+instrumentation_cls = _InstrumentedList
+else:
+return value
+
+return instrumentation_cls(self._model, self, key, self._item_cls, 
value, False)
+
+def _raw_value(self, value):
+"""
+Get the raw value.
+:param value:
+:return:
+"""
+if self._is_top_level and isinstance(value, self._item_cls):
+return value.value
+return value
+
+def _encapsulate_value(self, key, value):
+"""
+Create a new item cls if needed.
+:param key:
+:param value:
+:return:
+"""
+if isinstance(value, self._item_cls):
+return value
+# If it is not wrapped
+return self._item_cls.wrap(key, value)
+
+def __setitem__(self, key, value):
+"""
+Update the values in both the local and the db locations.
+:param key:
+:param value:
+:return:
+"""
+self._set(key, value)
+if self._is_top_level:
+# We are at the top level
+field = getattr(self._parent, self._field_name)
+mapi = getattr(self._model, self._item_cls.__modelname__)
+value = self._set_field(field,
+key,
+value if key in field else 
self._encapsulate_value(key, value))
+mapi.update(value)
+else:
+# We are not at the top level
+self._set_field(self._parent, self._field_name, self)
+
+def _set_field(self, collection, key, value):
+"""
+enables updating the current change in the ancestors
+:param collection: the collection to change
+:param key: the key for the specific field
+:param value: the new value
+:return:
+"""
+if isinstance(value, _InstrumentedCollection):
+value = value._raw
+if key in collection and isinstance(collection[key], 
self._item_cls):
+if isinstance(collection[key], self.PYTHON_TYPE):
+self._del(collection, key)
+collection[key].value = value
+else:
+collection[key] = value
+return collection[key]
+
+def __copy__(self):
+return self._raw
+
+def __deepcopy__(self, *args, **kwargs):
+return self._raw
  

[GitHub] incubator-ariatosca pull request #133: Convert runtime_properties to attribu...

2017-05-24 Thread mxmrlv
Github user mxmrlv commented on a diff in the pull request:

https://github.com/apache/incubator-ariatosca/pull/133#discussion_r118221772
  
--- Diff: aria/orchestrator/context/common.py ---
@@ -194,3 +194,242 @@ def _render_resource(self, resource_content, 
variables):
 variables.setdefault('ctx', self)
 resource_template = jinja2.Template(resource_content)
 return resource_template.render(variables)
+
+def _teardown_db_resources(self):
+self.model.log._session.close()
+self.model.log._engine.dispose()
+
+
+class _InstrumentedCollection(object):
+
+def __init__(self,
+ model,
+ parent,
+ field_name=None,
+ item_cls=None,
+ seq=None,
+ is_top_level=True,
+ **kwargs):
+self._model = model
+self._parent = parent
+self._field_name = field_name
+self._item_cls = item_cls
+self._is_top_level = is_top_level
+self._load(seq, **kwargs)
+
+@property
+def _raw(self):
+raise NotImplementedError
+
+def _load(self, seq, **kwargs):
+"""
+Instantiates the object from existing seq.
+
+:param seq: the original sequence to load from
+:return:
+"""
+raise NotImplementedError
+
+def _set(self, key, value):
+"""
+set the changes for the current object (not in the db)
+
+:param key:
+:param value:
+:return:
+"""
+raise NotImplementedError
+
+def _del(self, collection, key):
+raise NotImplementedError
+
+def _instrument(self, key, value):
+"""
+Instruments any collection to track changes (and ease of access)
+:param key:
+:param value:
+:return:
+"""
+if isinstance(value, _InstrumentedCollection):
+return value
+elif isinstance(value, dict):
+instrumentation_cls = _InstrumentedDict
+elif isinstance(value, list):
+instrumentation_cls = _InstrumentedList
+else:
+return value
+
+return instrumentation_cls(self._model, self, key, self._item_cls, 
value, False)
+
+def _raw_value(self, value):
+"""
+Get the raw value.
+:param value:
+:return:
+"""
+if self._is_top_level and isinstance(value, self._item_cls):
+return value.value
+return value
+
+def _encapsulate_value(self, key, value):
+"""
+Create a new item cls if needed.
+:param key:
+:param value:
+:return:
+"""
+if isinstance(value, self._item_cls):
+return value
+# If it is not wrapped
+return self._item_cls.wrap(key, value)
+
+def __setitem__(self, key, value):
+"""
+Update the values in both the local and the db locations.
+:param key:
+:param value:
+:return:
+"""
+self._set(key, value)
+if self._is_top_level:
+# We are at the top level
+field = getattr(self._parent, self._field_name)
+mapi = getattr(self._model, self._item_cls.__modelname__)
+value = self._set_field(field,
+key,
+value if key in field else 
self._encapsulate_value(key, value))
+mapi.update(value)
+else:
+# We are not at the top level
+self._set_field(self._parent, self._field_name, self)
+
+def _set_field(self, collection, key, value):
+"""
+enables updating the current change in the ancestors
+:param collection: the collection to change
+:param key: the key for the specific field
+:param value: the new value
+:return:
+"""
+if isinstance(value, _InstrumentedCollection):
+value = value._raw
+if key in collection and isinstance(collection[key], 
self._item_cls):
+if isinstance(collection[key], self.PYTHON_TYPE):
+self._del(collection, key)
+collection[key].value = value
+else:
+collection[key] = value
+return collection[key]
+
+def __copy__(self):
+return self._raw
+
+def __deepcopy__(self, *args, **kwargs):
+return self._raw
  

[GitHub] incubator-ariatosca pull request #133: Convert runtime_properties to attribu...

2017-05-24 Thread mxmrlv
Github user mxmrlv commented on a diff in the pull request:

https://github.com/apache/incubator-ariatosca/pull/133#discussion_r118227795
  
--- Diff: aria/orchestrator/context/common.py ---
@@ -194,3 +194,242 @@ def _render_resource(self, resource_content, 
variables):
 variables.setdefault('ctx', self)
 resource_template = jinja2.Template(resource_content)
 return resource_template.render(variables)
+
+def _teardown_db_resources(self):
+self.model.log._session.close()
+self.model.log._engine.dispose()
+
+
+class _InstrumentedCollection(object):
+
+def __init__(self,
+ model,
+ parent,
+ field_name=None,
+ item_cls=None,
+ seq=None,
+ is_top_level=True,
+ **kwargs):
+self._model = model
+self._parent = parent
+self._field_name = field_name
+self._item_cls = item_cls
+self._is_top_level = is_top_level
+self._load(seq, **kwargs)
+
+@property
+def _raw(self):
+raise NotImplementedError
+
+def _load(self, seq, **kwargs):
+"""
+Instantiates the object from existing seq.
+
+:param seq: the original sequence to load from
+:return:
+"""
+raise NotImplementedError
+
+def _set(self, key, value):
+"""
+set the changes for the current object (not in the db)
+
+:param key:
+:param value:
+:return:
+"""
+raise NotImplementedError
+
+def _del(self, collection, key):
+raise NotImplementedError
+
+def _instrument(self, key, value):
+"""
+Instruments any collection to track changes (and ease of access)
+:param key:
+:param value:
+:return:
+"""
+if isinstance(value, _InstrumentedCollection):
+return value
+elif isinstance(value, dict):
+instrumentation_cls = _InstrumentedDict
+elif isinstance(value, list):
+instrumentation_cls = _InstrumentedList
+else:
+return value
+
+return instrumentation_cls(self._model, self, key, self._item_cls, 
value, False)
+
+def _raw_value(self, value):
+"""
+Get the raw value.
+:param value:
+:return:
+"""
+if self._is_top_level and isinstance(value, self._item_cls):
+return value.value
+return value
+
+def _encapsulate_value(self, key, value):
+"""
+Create a new item cls if needed.
+:param key:
+:param value:
+:return:
+"""
+if isinstance(value, self._item_cls):
+return value
+# If it is not wrapped
+return self._item_cls.wrap(key, value)
+
+def __setitem__(self, key, value):
+"""
+Update the values in both the local and the db locations.
+:param key:
+:param value:
+:return:
+"""
+self._set(key, value)
+if self._is_top_level:
+# We are at the top level
+field = getattr(self._parent, self._field_name)
+mapi = getattr(self._model, self._item_cls.__modelname__)
+value = self._set_field(field,
+key,
+value if key in field else 
self._encapsulate_value(key, value))
+mapi.update(value)
+else:
+# We are not at the top level
+self._set_field(self._parent, self._field_name, self)
+
+def _set_field(self, collection, key, value):
+"""
+enables updating the current change in the ancestors
+:param collection: the collection to change
+:param key: the key for the specific field
+:param value: the new value
+:return:
+"""
+if isinstance(value, _InstrumentedCollection):
+value = value._raw
+if key in collection and isinstance(collection[key], 
self._item_cls):
+if isinstance(collection[key], self.PYTHON_TYPE):
+self._del(collection, key)
--- End diff --

document


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

[GitHub] incubator-ariatosca pull request #133: Convert runtime_properties to attribu...

2017-05-24 Thread mxmrlv
Github user mxmrlv commented on a diff in the pull request:

https://github.com/apache/incubator-ariatosca/pull/133#discussion_r118226379
  
--- Diff: aria/orchestrator/context/common.py ---
@@ -194,3 +194,242 @@ def _render_resource(self, resource_content, 
variables):
 variables.setdefault('ctx', self)
 resource_template = jinja2.Template(resource_content)
 return resource_template.render(variables)
+
+def _teardown_db_resources(self):
+self.model.log._session.close()
+self.model.log._engine.dispose()
+
+
+class _InstrumentedCollection(object):
+
+def __init__(self,
+ model,
+ parent,
+ field_name=None,
+ item_cls=None,
+ seq=None,
+ is_top_level=True,
+ **kwargs):
+self._model = model
+self._parent = parent
+self._field_name = field_name
+self._item_cls = item_cls
+self._is_top_level = is_top_level
+self._load(seq, **kwargs)
+
+@property
+def _raw(self):
+raise NotImplementedError
+
+def _load(self, seq, **kwargs):
+"""
+Instantiates the object from existing seq.
+
+:param seq: the original sequence to load from
+:return:
+"""
+raise NotImplementedError
+
+def _set(self, key, value):
+"""
+set the changes for the current object (not in the db)
+
+:param key:
+:param value:
+:return:
+"""
+raise NotImplementedError
+
+def _del(self, collection, key):
+raise NotImplementedError
+
+def _instrument(self, key, value):
+"""
+Instruments any collection to track changes (and ease of access)
+:param key:
+:param value:
+:return:
+"""
+if isinstance(value, _InstrumentedCollection):
+return value
+elif isinstance(value, dict):
+instrumentation_cls = _InstrumentedDict
+elif isinstance(value, list):
+instrumentation_cls = _InstrumentedList
+else:
+return value
+
+return instrumentation_cls(self._model, self, key, self._item_cls, 
value, False)
+
+def _raw_value(self, value):
+"""
+Get the raw value.
+:param value:
+:return:
+"""
+if self._is_top_level and isinstance(value, self._item_cls):
+return value.value
+return value
+
+def _encapsulate_value(self, key, value):
+"""
+Create a new item cls if needed.
+:param key:
+:param value:
+:return:
+"""
+if isinstance(value, self._item_cls):
+return value
+# If it is not wrapped
+return self._item_cls.wrap(key, value)
+
+def __setitem__(self, key, value):
+"""
+Update the values in both the local and the db locations.
+:param key:
+:param value:
+:return:
+"""
+self._set(key, value)
+if self._is_top_level:
+# We are at the top level
+field = getattr(self._parent, self._field_name)
+mapi = getattr(self._model, self._item_cls.__modelname__)
+value = self._set_field(field,
+key,
+value if key in field else 
self._encapsulate_value(key, value))
+mapi.update(value)
+else:
+# We are not at the top level
+self._set_field(self._parent, self._field_name, self)
+
+def _set_field(self, collection, key, value):
+"""
+enables updating the current change in the ancestors
+:param collection: the collection to change
+:param key: the key for the specific field
+:param value: the new value
+:return:
+"""
+if isinstance(value, _InstrumentedCollection):
+value = value._raw
+if key in collection and isinstance(collection[key], 
self._item_cls):
+if isinstance(collection[key], self.PYTHON_TYPE):
+self._del(collection, key)
+collection[key].value = value
+else:
+collection[key] = value
+return collection[key]
+
+def __copy__(self):
--- End diff --

move to dict_


---
If your project is set up for it, you can reply to this email and hav

[GitHub] incubator-ariatosca pull request #133: Convert runtime_properties to attribu...

2017-05-24 Thread mxmrlv
Github user mxmrlv commented on a diff in the pull request:

https://github.com/apache/incubator-ariatosca/pull/133#discussion_r118214614
  
--- Diff: aria/orchestrator/context/common.py ---
@@ -194,3 +194,242 @@ def _render_resource(self, resource_content, 
variables):
 variables.setdefault('ctx', self)
 resource_template = jinja2.Template(resource_content)
 return resource_template.render(variables)
+
+def _teardown_db_resources(self):
--- End diff --

close


---
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 #133: Convert runtime_properties to attribu...

2017-05-24 Thread mxmrlv
Github user mxmrlv commented on a diff in the pull request:

https://github.com/apache/incubator-ariatosca/pull/133#discussion_r118221628
  
--- Diff: aria/orchestrator/context/common.py ---
@@ -194,3 +194,242 @@ def _render_resource(self, resource_content, 
variables):
 variables.setdefault('ctx', self)
 resource_template = jinja2.Template(resource_content)
 return resource_template.render(variables)
+
+def _teardown_db_resources(self):
+self.model.log._session.close()
+self.model.log._engine.dispose()
+
+
+class _InstrumentedCollection(object):
+
+def __init__(self,
+ model,
+ parent,
+ field_name=None,
+ item_cls=None,
+ seq=None,
+ is_top_level=True,
+ **kwargs):
+self._model = model
+self._parent = parent
+self._field_name = field_name
+self._item_cls = item_cls
+self._is_top_level = is_top_level
+self._load(seq, **kwargs)
+
+@property
+def _raw(self):
+raise NotImplementedError
+
+def _load(self, seq, **kwargs):
+"""
+Instantiates the object from existing seq.
+
+:param seq: the original sequence to load from
+:return:
+"""
+raise NotImplementedError
+
+def _set(self, key, value):
+"""
+set the changes for the current object (not in the db)
+
+:param key:
+:param value:
+:return:
+"""
+raise NotImplementedError
+
+def _del(self, collection, key):
+raise NotImplementedError
+
+def _instrument(self, key, value):
+"""
+Instruments any collection to track changes (and ease of access)
+:param key:
+:param value:
+:return:
+"""
+if isinstance(value, _InstrumentedCollection):
+return value
+elif isinstance(value, dict):
+instrumentation_cls = _InstrumentedDict
+elif isinstance(value, list):
+instrumentation_cls = _InstrumentedList
+else:
+return value
+
+return instrumentation_cls(self._model, self, key, self._item_cls, 
value, False)
+
+def _raw_value(self, value):
+"""
+Get the raw value.
+:param value:
+:return:
+"""
+if self._is_top_level and isinstance(value, self._item_cls):
+return value.value
+return value
+
+def _encapsulate_value(self, key, value):
+"""
+Create a new item cls if needed.
+:param key:
+:param value:
+:return:
+"""
+if isinstance(value, self._item_cls):
+return value
+# If it is not wrapped
+return self._item_cls.wrap(key, value)
+
+def __setitem__(self, key, value):
+"""
+Update the values in both the local and the db locations.
+:param key:
+:param value:
+:return:
+"""
+self._set(key, value)
+if self._is_top_level:
+# We are at the top level
+field = getattr(self._parent, self._field_name)
+mapi = getattr(self._model, self._item_cls.__modelname__)
+value = self._set_field(field,
+key,
+value if key in field else 
self._encapsulate_value(key, value))
+mapi.update(value)
+else:
+# We are not at the top level
+self._set_field(self._parent, self._field_name, self)
+
+def _set_field(self, collection, key, value):
+"""
+enables updating the current change in the ancestors
+:param collection: the collection to change
+:param key: the key for the specific field
+:param value: the new value
+:return:
+"""
+if isinstance(value, _InstrumentedCollection):
+value = value._raw
+if key in collection and isinstance(collection[key], 
self._item_cls):
+if isinstance(collection[key], self.PYTHON_TYPE):
+self._del(collection, key)
+collection[key].value = value
+else:
+collection[key] = value
+return collection[key]
+
+def __copy__(self):
+return self._raw
+
+def __deepcopy__(self, *args, **kwargs):
+return self._raw
  

[GitHub] incubator-ariatosca pull request #133: Convert runtime_properties to attribu...

2017-05-24 Thread mxmrlv
Github user mxmrlv commented on a diff in the pull request:

https://github.com/apache/incubator-ariatosca/pull/133#discussion_r118225858
  
--- Diff: aria/orchestrator/context/operation.py ---
@@ -114,6 +114,7 @@ class NodeOperationContext(BaseOperationContext):
 """
 
 @property
+@common.InstrumentCollection('attributes')
--- End diff --

otherwise fix for bash?


---
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 #133: Convert runtime_properties to attribu...

2017-05-24 Thread mxmrlv
Github user mxmrlv commented on a diff in the pull request:

https://github.com/apache/incubator-ariatosca/pull/133#discussion_r118215033
  
--- Diff: aria/orchestrator/execution_plugin/ctx_proxy/server.py ---
@@ -127,6 +127,7 @@ def _process(self, request):
 result_type = 'stop_operation'
 result = {'type': result_type, 'payload': payload}
 except Exception as e:
+self.ctx.model.log._session.rollback()
--- End diff --

remove


---
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 #137: NullPool logging messages appear duri...

2017-05-24 Thread asfgit
Github user asfgit closed the pull request at:

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


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