You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ariatosca.apache.org by mxmrlv <gi...@git.apache.org> on 2017/05/17 10:11:44 UTC

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

GitHub user mxmrlv opened a pull request:

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

    Convert runtime_properties to attributes

    

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

    $ git pull https://github.com/apache/incubator-ariatosca ARIA-258-Convert-runtime-properties-to-attributes

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

    https://github.com/apache/incubator-ariatosca/pull/133.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 #133
    
----
commit ebd1ef85cc7be8910d214bcd3fc70db1ae77743d
Author: max-orlov <ma...@gigaspaces.com>
Date:   2017-05-14T19:38:39Z

    wip

----


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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

Posted by mxmrlv <gi...@git.apache.org>.
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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

Posted by mxmrlv <gi...@git.apache.org>.
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
    +
    +
    +class _InstrumentedDict(_InstrumentedCollection, dict):
    +
    +    PYTHON_TYPE = dict
    +
    +    def _load(self, dict_=None, **kwargs):
    +        dict.__init__(
    +            self,
    +            tuple((key, self._raw_value(value)) for key, value in (dict_ or {}).items()),
    +            **kwargs)
    +
    +    def update(self, dict_=None, **kwargs):
    +        dict_ = dict_ or {}
    +        for key, value in dict_.items():
    +            self[key] = value
    +        for key, value in kwargs.items():
    +            self[key] = value
    +
    +    def __getitem__(self, key):
    +        return self._instrument(key, dict.__getitem__(self, key))
    +
    +    def values(self):
    +        return [self[key] for key in self.keys()]
    +
    +    def items(self):
    +        return [(key, self[key]) for key in self.keys()]
    +
    +    def __iter__(self):
    +        return (key for key in self.keys())
    +
    +    def _set(self, key, value):
    +        dict.__setitem__(self, key, self._raw_value(value))
    +
    +    @property
    +    def _raw(self):
    +        return dict(self)
    +
    +    def _del(self, collection, key):
    +        collection[key].clear()
    +
    +
    +class _InstrumentedList(_InstrumentedCollection, list):
    +
    +    PYTHON_TYPE = list
    +
    +    def _load(self, list_=None, **kwargs):
    +        list.__init__(self, list(item for item in list_ or []))
    +
    +    def append(self, value):
    +        self.insert(len(self), value)
    +
    +    def insert(self, index, value):
    +        list.insert(self, index, self._raw_value(value))
    +        if self._is_top_level:
    +            field = getattr(self._parent, self._field_name)
    +            field.insert(index, self._encapsulate_value(index, value))
    +        else:
    +            self._parent[self._field_name] = self
    +
    +    def __getitem__(self, key):
    +        return self._instrument(key, list.__getitem__(self, key))
    +
    +    def _set(self, key, value):
    +        list.__setitem__(self, key, value)
    +
    +    def _del(self, collection, key):
    +        del collection[key]
    +
    +    @property
    +    def _raw(self):
    +        return list(self)
    +
    +
    +class InstrumentCollection(object):
    --- End diff --
    
    consider name


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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

Posted by mxmrlv <gi...@git.apache.org>.
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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

Posted by mxmrlv <gi...@git.apache.org>.
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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

Posted by mxmrlv <gi...@git.apache.org>.
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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

Posted by mxmrlv <gi...@git.apache.org>.
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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

Posted by mxmrlv <gi...@git.apache.org>.
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
    +
    +
    +class _InstrumentedDict(_InstrumentedCollection, dict):
    +
    +    PYTHON_TYPE = dict
    +
    +    def _load(self, dict_=None, **kwargs):
    +        dict.__init__(
    +            self,
    +            tuple((key, self._raw_value(value)) for key, value in (dict_ or {}).items()),
    +            **kwargs)
    +
    +    def update(self, dict_=None, **kwargs):
    +        dict_ = dict_ or {}
    +        for key, value in dict_.items():
    +            self[key] = value
    +        for key, value in kwargs.items():
    +            self[key] = value
    +
    +    def __getitem__(self, key):
    +        return self._instrument(key, dict.__getitem__(self, key))
    +
    +    def values(self):
    +        return [self[key] for key in self.keys()]
    +
    +    def items(self):
    +        return [(key, self[key]) for key in self.keys()]
    +
    +    def __iter__(self):
    +        return (key for key in self.keys())
    +
    +    def _set(self, key, value):
    +        dict.__setitem__(self, key, self._raw_value(value))
    +
    +    @property
    +    def _raw(self):
    +        return dict(self)
    +
    +    def _del(self, collection, key):
    +        collection[key].clear()
    +
    +
    +class _InstrumentedList(_InstrumentedCollection, list):
    +
    +    PYTHON_TYPE = list
    +
    +    def _load(self, list_=None, **kwargs):
    +        list.__init__(self, list(item for item in list_ or []))
    +
    +    def append(self, value):
    +        self.insert(len(self), value)
    +
    +    def insert(self, index, value):
    +        list.insert(self, index, self._raw_value(value))
    +        if self._is_top_level:
    +            field = getattr(self._parent, self._field_name)
    +            field.insert(index, self._encapsulate_value(index, value))
    +        else:
    +            self._parent[self._field_name] = self
    +
    +    def __getitem__(self, key):
    +        return self._instrument(key, list.__getitem__(self, key))
    +
    +    def _set(self, key, value):
    +        list.__setitem__(self, key, value)
    +
    +    def _del(self, collection, key):
    +        del collection[key]
    +
    +    @property
    +    def _raw(self):
    +        return list(self)
    +
    +
    +class InstrumentCollection(object):
    +
    +    def __init__(self, field_name):
    +        super(InstrumentCollection, self).__init__()
    +        self._field_name = field_name
    +        self._actor = None
    +
    +    @property
    +    def actor(self):
    +        return self._actor
    +
    +    def __getattr__(self, item):
    +        try:
    +            return getattr(self._actor, item)
    +        except AttributeError:
    +            return super(InstrumentCollection, self).__getattribute__(item)
    +
    +    def __call__(self, func, *args, **kwargs):
    --- End diff --
    
    add some docs explaining you're returning a modified version of the actor


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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

Posted by mxmrlv <gi...@git.apache.org>.
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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

Posted by mxmrlv <gi...@git.apache.org>.
Github user mxmrlv commented on a diff in the pull request:

    https://github.com/apache/incubator-ariatosca/pull/133#discussion_r118466582
  
    --- Diff: tests/orchestrator/context/test_attribute_suggaring.py ---
    @@ -0,0 +1,253 @@
    +# 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.
    +
    +import pytest
    +
    +from aria.modeling.models import Parameter
    +from aria.orchestrator.context import common
    +
    +
    +class MockActor(object):
    +    def __init__(self):
    +        self.dict_ = {}
    +        self.list_ = []
    +
    +
    +class MockModel(object):
    +
    +    def __init__(self):
    +        self.parameter = type('MockModel', (object, ), {'model_cls': Parameter,
    +                                                        'put': lambda *args, **kwargs: None,
    +                                                        'update': lambda *args, **kwargs: None})()
    +
    +
    +class ContextSugaring(object):
    --- End diff --
    
    collection_instrumentation


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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

Posted by mxmrlv <gi...@git.apache.org>.
Github user mxmrlv commented on a diff in the pull request:

    https://github.com/apache/incubator-ariatosca/pull/133#discussion_r118466593
  
    --- 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 --
    
    test_collec_instr


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-ariatosca pull request #133: ARIA-258 Convert runtime_properties t...

Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:

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


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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

Posted by mxmrlv <gi...@git.apache.org>.
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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

Posted by mxmrlv <gi...@git.apache.org>.
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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

Posted by mxmrlv <gi...@git.apache.org>.
Github user mxmrlv commented on a diff in the pull request:

    https://github.com/apache/incubator-ariatosca/pull/133#discussion_r118509708
  
    --- Diff: aria/orchestrator/context/common.py ---
    @@ -381,33 +381,41 @@ def _raw(self):
             return list(self)
     
     
    -class InstrumentCollection(object):
    +class _InstrumentedModel(object):
     
    -    def __init__(self, field_name):
    -        super(InstrumentCollection, self).__init__()
    +    def __init__(self, field_name, original_model, model_storage):
    +        super(_InstrumentedModel, self).__init__()
             self._field_name = field_name
    -        self._actor = None
    -
    -    @property
    -    def actor(self):
    -        return self._actor
    +        self._model_storage = model_storage
    +        self._original_model = original_model
    +        self._apply_instrumentation()
     
         def __getattr__(self, item):
    -        return getattr(self._actor, item)
    -
    -    def __call__(self, func, *args, **kwargs):
    -        def _wrapper(func_self, *args, **kwargs):
    -            self._actor = func(func_self, *args, **kwargs)
    -            field = getattr(self._actor, self._field_name)
    -
    -            # Preserve the original value. e.g. original attributes would be located under
    -            # _attributes
    -            setattr(self, '_{0}'.format(self._field_name), field)
    -
    -            # set instrumented value
    -            setattr(self, self._field_name, _InstrumentedDict(func_self.model,
    -                                                              self._actor,
    -                                                              self._field_name,
    -                                                              field))
    -            return self
    -        return _wrapper
    +        return getattr(self._original_model, item)
    +
    +    def _apply_instrumentation(self):
    +
    +        field = getattr(self._original_model, self._field_name)
    +
    +        # Preserve the original value. e.g. original attributes would be located under
    +        # _attributes
    +        setattr(self, '_{0}'.format(self._field_name), field)
    +
    +        # set instrumented value
    +        setattr(self, self._field_name, _InstrumentedDict(self._model_storage,
    +                                                          self._original_model,
    +                                                          self._field_name,
    +                                                          field))
    +
    +
    +def instrument_collection(field_name, func=None):
    --- End diff --
    
    move new classes to parameter_collection_instrumentation.py


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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

Posted by mxmrlv <gi...@git.apache.org>.
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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

Posted by mxmrlv <gi...@git.apache.org>.
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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

Posted by mxmrlv <gi...@git.apache.org>.
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
    +
    +
    +class _InstrumentedDict(_InstrumentedCollection, dict):
    +
    +    PYTHON_TYPE = dict
    +
    +    def _load(self, dict_=None, **kwargs):
    +        dict.__init__(
    +            self,
    +            tuple((key, self._raw_value(value)) for key, value in (dict_ or {}).items()),
    +            **kwargs)
    +
    +    def update(self, dict_=None, **kwargs):
    +        dict_ = dict_ or {}
    +        for key, value in dict_.items():
    +            self[key] = value
    +        for key, value in kwargs.items():
    +            self[key] = value
    +
    +    def __getitem__(self, key):
    +        return self._instrument(key, dict.__getitem__(self, key))
    +
    +    def values(self):
    +        return [self[key] for key in self.keys()]
    +
    +    def items(self):
    +        return [(key, self[key]) for key in self.keys()]
    +
    +    def __iter__(self):
    +        return (key for key in self.keys())
    +
    +    def _set(self, key, value):
    +        dict.__setitem__(self, key, self._raw_value(value))
    +
    +    @property
    +    def _raw(self):
    +        return dict(self)
    +
    +    def _del(self, collection, key):
    +        collection[key].clear()
    +
    +
    +class _InstrumentedList(_InstrumentedCollection, list):
    +
    +    PYTHON_TYPE = list
    +
    +    def _load(self, list_=None, **kwargs):
    +        list.__init__(self, list(item for item in list_ or []))
    +
    +    def append(self, value):
    +        self.insert(len(self), value)
    +
    +    def insert(self, index, value):
    +        list.insert(self, index, self._raw_value(value))
    +        if self._is_top_level:
    +            field = getattr(self._parent, self._field_name)
    +            field.insert(index, self._encapsulate_value(index, value))
    +        else:
    +            self._parent[self._field_name] = self
    +
    +    def __getitem__(self, key):
    +        return self._instrument(key, list.__getitem__(self, key))
    +
    +    def _set(self, key, value):
    +        list.__setitem__(self, key, value)
    +
    +    def _del(self, collection, key):
    +        del collection[key]
    +
    +    @property
    +    def _raw(self):
    +        return list(self)
    +
    +
    +class InstrumentCollection(object):
    +
    +    def __init__(self, field_name):
    +        super(InstrumentCollection, self).__init__()
    +        self._field_name = field_name
    +        self._actor = None
    +
    +    @property
    +    def actor(self):
    +        return self._actor
    +
    +    def __getattr__(self, item):
    +        try:
    +            return getattr(self._actor, item)
    +        except AttributeError:
    +            return super(InstrumentCollection, self).__getattribute__(item)
    --- 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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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

Posted by mxmrlv <gi...@git.apache.org>.
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
    +
    +
    +class _InstrumentedDict(_InstrumentedCollection, dict):
    +
    +    PYTHON_TYPE = dict
    +
    +    def _load(self, dict_=None, **kwargs):
    +        dict.__init__(
    +            self,
    +            tuple((key, self._raw_value(value)) for key, value in (dict_ or {}).items()),
    +            **kwargs)
    +
    +    def update(self, dict_=None, **kwargs):
    +        dict_ = dict_ or {}
    +        for key, value in dict_.items():
    +            self[key] = value
    +        for key, value in kwargs.items():
    +            self[key] = value
    +
    +    def __getitem__(self, key):
    +        return self._instrument(key, dict.__getitem__(self, key))
    +
    +    def values(self):
    --- End diff --
    
    remove X 3


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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

Posted by mxmrlv <gi...@git.apache.org>.
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 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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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

Posted by mxmrlv <gi...@git.apache.org>.
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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

Posted by mxmrlv <gi...@git.apache.org>.
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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

Posted by mxmrlv <gi...@git.apache.org>.
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
    +
    +
    +class _InstrumentedDict(_InstrumentedCollection, dict):
    +
    +    PYTHON_TYPE = dict
    +
    +    def _load(self, dict_=None, **kwargs):
    +        dict.__init__(
    +            self,
    +            tuple((key, self._raw_value(value)) for key, value in (dict_ or {}).items()),
    +            **kwargs)
    +
    +    def update(self, dict_=None, **kwargs):
    +        dict_ = dict_ or {}
    +        for key, value in dict_.items():
    +            self[key] = value
    +        for key, value in kwargs.items():
    +            self[key] = value
    +
    +    def __getitem__(self, key):
    +        return self._instrument(key, dict.__getitem__(self, key))
    +
    +    def values(self):
    +        return [self[key] for key in self.keys()]
    +
    +    def items(self):
    +        return [(key, self[key]) for key in self.keys()]
    +
    +    def __iter__(self):
    +        return (key for key in self.keys())
    +
    +    def _set(self, key, value):
    +        dict.__setitem__(self, key, self._raw_value(value))
    +
    +    @property
    +    def _raw(self):
    +        return dict(self)
    +
    +    def _del(self, collection, key):
    +        collection[key].clear()
    +
    +
    +class _InstrumentedList(_InstrumentedCollection, list):
    +
    +    PYTHON_TYPE = list
    +
    +    def _load(self, list_=None, **kwargs):
    +        list.__init__(self, list(item for item in list_ or []))
    +
    +    def append(self, value):
    +        self.insert(len(self), value)
    +
    +    def insert(self, index, value):
    +        list.insert(self, index, self._raw_value(value))
    +        if self._is_top_level:
    +            field = getattr(self._parent, self._field_name)
    +            field.insert(index, self._encapsulate_value(index, value))
    +        else:
    +            self._parent[self._field_name] = self
    +
    +    def __getitem__(self, key):
    +        return self._instrument(key, list.__getitem__(self, key))
    +
    +    def _set(self, key, value):
    +        list.__setitem__(self, key, value)
    +
    +    def _del(self, collection, key):
    +        del collection[key]
    +
    +    @property
    +    def _raw(self):
    +        return list(self)
    +
    +
    +class InstrumentCollection(object):
    +
    +    def __init__(self, field_name):
    +        super(InstrumentCollection, self).__init__()
    +        self._field_name = field_name
    +        self._actor = None
    +
    +    @property
    +    def actor(self):
    +        return self._actor
    +
    +    def __getattr__(self, item):
    --- End diff --
    
    consider adding setattr


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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

Posted by mxmrlv <gi...@git.apache.org>.
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
    +
    +
    +class _InstrumentedDict(_InstrumentedCollection, dict):
    +
    +    PYTHON_TYPE = dict
    +
    +    def _load(self, dict_=None, **kwargs):
    +        dict.__init__(
    +            self,
    +            tuple((key, self._raw_value(value)) for key, value in (dict_ or {}).items()),
    +            **kwargs)
    +
    +    def update(self, dict_=None, **kwargs):
    +        dict_ = dict_ or {}
    +        for key, value in dict_.items():
    +            self[key] = value
    +        for key, value in kwargs.items():
    +            self[key] = value
    +
    +    def __getitem__(self, key):
    +        return self._instrument(key, dict.__getitem__(self, key))
    +
    +    def values(self):
    +        return [self[key] for key in self.keys()]
    +
    +    def items(self):
    +        return [(key, self[key]) for key in self.keys()]
    +
    +    def __iter__(self):
    +        return (key for key in self.keys())
    +
    +    def _set(self, key, value):
    +        dict.__setitem__(self, key, self._raw_value(value))
    +
    +    @property
    +    def _raw(self):
    +        return dict(self)
    +
    +    def _del(self, collection, key):
    +        collection[key].clear()
    +
    +
    +class _InstrumentedList(_InstrumentedCollection, list):
    +
    +    PYTHON_TYPE = list
    +
    +    def _load(self, list_=None, **kwargs):
    +        list.__init__(self, list(item for item in list_ or []))
    +
    +    def append(self, value):
    +        self.insert(len(self), value)
    +
    +    def insert(self, index, value):
    +        list.insert(self, index, self._raw_value(value))
    +        if self._is_top_level:
    +            field = getattr(self._parent, self._field_name)
    +            field.insert(index, self._encapsulate_value(index, value))
    +        else:
    +            self._parent[self._field_name] = self
    +
    +    def __getitem__(self, key):
    +        return self._instrument(key, list.__getitem__(self, key))
    +
    +    def _set(self, key, value):
    +        list.__setitem__(self, key, value)
    +
    +    def _del(self, collection, key):
    +        del collection[key]
    +
    +    @property
    +    def _raw(self):
    +        return list(self)
    +
    +
    +class InstrumentCollection(object):
    +
    +    def __init__(self, field_name):
    +        super(InstrumentCollection, self).__init__()
    +        self._field_name = field_name
    +        self._actor = None
    --- End diff --
    
    reconsider name


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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

Posted by mxmrlv <gi...@git.apache.org>.
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
    +
    +
    +class _InstrumentedDict(_InstrumentedCollection, dict):
    +
    +    PYTHON_TYPE = dict
    +
    +    def _load(self, dict_=None, **kwargs):
    +        dict.__init__(
    +            self,
    +            tuple((key, self._raw_value(value)) for key, value in (dict_ or {}).items()),
    +            **kwargs)
    +
    +    def update(self, dict_=None, **kwargs):
    +        dict_ = dict_ or {}
    +        for key, value in dict_.items():
    +            self[key] = value
    +        for key, value in kwargs.items():
    +            self[key] = value
    +
    +    def __getitem__(self, key):
    +        return self._instrument(key, dict.__getitem__(self, key))
    +
    +    def values(self):
    +        return [self[key] for key in self.keys()]
    +
    +    def items(self):
    +        return [(key, self[key]) for key in self.keys()]
    +
    +    def __iter__(self):
    +        return (key for key in self.keys())
    +
    +    def _set(self, key, value):
    +        dict.__setitem__(self, key, self._raw_value(value))
    +
    +    @property
    +    def _raw(self):
    +        return dict(self)
    +
    +    def _del(self, collection, key):
    +        collection[key].clear()
    +
    +
    +class _InstrumentedList(_InstrumentedCollection, list):
    +
    +    PYTHON_TYPE = list
    +
    +    def _load(self, list_=None, **kwargs):
    +        list.__init__(self, list(item for item in list_ or []))
    +
    +    def append(self, value):
    +        self.insert(len(self), value)
    +
    +    def insert(self, index, value):
    +        list.insert(self, index, self._raw_value(value))
    +        if self._is_top_level:
    +            field = getattr(self._parent, self._field_name)
    +            field.insert(index, self._encapsulate_value(index, value))
    +        else:
    +            self._parent[self._field_name] = self
    +
    +    def __getitem__(self, key):
    +        return self._instrument(key, list.__getitem__(self, key))
    +
    +    def _set(self, key, value):
    +        list.__setitem__(self, key, value)
    +
    +    def _del(self, collection, key):
    +        del collection[key]
    +
    +    @property
    +    def _raw(self):
    +        return list(self)
    +
    +
    +class InstrumentCollection(object):
    +
    +    def __init__(self, field_name):
    +        super(InstrumentCollection, self).__init__()
    +        self._field_name = field_name
    +        self._actor = None
    +
    +    @property
    +    def actor(self):
    +        return self._actor
    +
    +    def __getattr__(self, item):
    +        try:
    +            return getattr(self._actor, item)
    +        except AttributeError:
    +            return super(InstrumentCollection, self).__getattribute__(item)
    +
    +    def __call__(self, func, *args, **kwargs):
    +        def _wrapper(func_self, *args, **kwargs):
    +            self._actor = func(func_self, *args, **kwargs)
    +            field = getattr(self._actor, self._field_name)
    +
    +            # Preserve the original value
    --- End diff --
    
    add e.g.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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

Posted by mxmrlv <gi...@git.apache.org>.
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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

Posted by mxmrlv <gi...@git.apache.org>.
Github user mxmrlv commented on a diff in the pull request:

    https://github.com/apache/incubator-ariatosca/pull/133#discussion_r118467706
  
    --- Diff: tests/orchestrator/context/test_operation.py ---
    @@ -422,3 +484,15 @@ def get_node_id(ctx, holder_path, **_):
     def _test_plugin_workdir(ctx, filename, content):
         with open(os.path.join(ctx.plugin_workdir, filename), 'w') as f:
             f.write(content)
    +
    +
    +@operation
    +def attribute_altering_operation(ctx, dict_, **_):
    +    ctx.node.attributes.update(dict_)
    --- End diff --
    
    add set and get


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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

Posted by mxmrlv <gi...@git.apache.org>.
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
    +
    +
    +class _InstrumentedDict(_InstrumentedCollection, dict):
    +
    +    PYTHON_TYPE = dict
    +
    +    def _load(self, dict_=None, **kwargs):
    +        dict.__init__(
    +            self,
    +            tuple((key, self._raw_value(value)) for key, value in (dict_ or {}).items()),
    +            **kwargs)
    +
    +    def update(self, dict_=None, **kwargs):
    +        dict_ = dict_ or {}
    +        for key, value in dict_.items():
    +            self[key] = value
    +        for key, value in kwargs.items():
    +            self[key] = value
    +
    +    def __getitem__(self, key):
    +        return self._instrument(key, dict.__getitem__(self, key))
    +
    +    def values(self):
    +        return [self[key] for key in self.keys()]
    +
    +    def items(self):
    +        return [(key, self[key]) for key in self.keys()]
    +
    +    def __iter__(self):
    +        return (key for key in self.keys())
    +
    +    def _set(self, key, value):
    +        dict.__setitem__(self, key, self._raw_value(value))
    +
    +    @property
    +    def _raw(self):
    +        return dict(self)
    +
    +    def _del(self, collection, key):
    +        collection[key].clear()
    --- End diff --
    
    del


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---