ariatosca-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (ARIA-262) Inconsistent node attributes behavior
Date Sun, 04 Jun 2017 16:20:05 GMT

    [ https://issues.apache.org/jira/browse/ARIA-262?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16036318#comment-16036318
] 

ASF GitHub Bot commented on ARIA-262:
-------------------------------------

Github user mxmrlv commented on a diff in the pull request:

    https://github.com/apache/incubator-ariatosca/pull/141#discussion_r120013936
  
    --- Diff: aria/storage/collection_instrumentation.py ---
    @@ -204,39 +200,106 @@ def _raw(self):
     
     class _InstrumentedModel(object):
     
    -    def __init__(self, field_name, original_model, model_storage):
    +    def __init__(self, original_model, mapi, instrumentation):
    +        """
    +        The original model
    +        :param original_model: the model to be instrumented
    +        :param mapi: the mapi for that model
    +        """
             super(_InstrumentedModel, self).__init__()
    -        self._field_name = field_name
    -        self._model_storage = model_storage
             self._original_model = original_model
    +        self._mapi = mapi
    +        self._instrumentation = instrumentation
             self._apply_instrumentation()
     
         def __getattr__(self, item):
    -        return getattr(self._original_model, item)
    +        return_value = getattr(self._original_model, item)
    +        if isinstance(return_value, self._original_model.__class__):
    +            return _create_instrumented_model(return_value, self._mapi, self._instrumentation)
    +        if isinstance(return_value, (list, dict)):
    +            return _create_wrapped_model(return_value, self._mapi, self._instrumentation)
    +        return return_value
     
         def _apply_instrumentation(self):
    +        for field in self._instrumentation:
    +            field_name = field.key
    +            field_cls = field.mapper.class_
    +            field = getattr(self._original_model, field_name)
    +
    +            # Preserve the original value. e.g. original attributes would be located
under
    +            # _attributes
    +            setattr(self, '_{0}'.format(field_name), field)
    +
    +            # set instrumented value
    +            if isinstance(field, dict):
    +                instrumentation_cls = _InstrumentedDict
    +            elif isinstance(field, list):
    +                instrumentation_cls = _InstrumentedList
    +            else:
    +                # TODO: raise proper error
    +                raise exceptions.StorageError(
    +                    "ARIA supports instrumentation for dict and list. Field {field} of
the "
    +                    "class {model} is of {type} type.".format(
    +                        field=field,
    +                        model=self._original_model,
    +                        type=type(field)))
    +
    +            instrumented_class = instrumentation_cls(seq=field,
    +                                                     parent=self._original_model,
    +                                                     mapi=self._mapi,
    +                                                     field_name=field_name,
    +                                                     field_cls=field_cls)
    +            setattr(self, field_name, instrumented_class)
    +
    +
    +class _WrappedModel(object):
    +
    +    def __init__(self, wrapped, instrumentation, **kwargs):
    +        """
    +
    +        :param instrumented_cls: The class to be instrumented
    +        :param instrumentation_cls: the instrumentation cls
    +        :param wrapped: the currently wrapped instance
    +        :param kwargs: and kwargs to te passed to the instrumented class.
    --- End diff --
    
    te


> Inconsistent node attributes behavior
> -------------------------------------
>
>                 Key: ARIA-262
>                 URL: https://issues.apache.org/jira/browse/ARIA-262
>             Project: AriaTosca
>          Issue Type: Story
>            Reporter: Maxim Orlov
>            Assignee: Maxim Orlov
>
> ARIA provides sugaring for node attributes. However this sugaring is somewhat limited,
as it sugars ctx accessed attributes. e.g. Under NodeOperationContext {{ctx.node.attributes}}
has a dict-like behavior, where the value is another object with a dict-like behavior. This
is provided by the sugaring. 
> However {{ctx.node.relationships[0].target_node.attributes}} provides a dict where the
value is of type Parameter, accessing the value of this Parameter requires {{param.value}}
This creates inconsistency with regards to access to attributes.
> There are several possible solutions:
> 1. Enable sugaring on the model level. this will effectively make the creation of Parameter
implicit, but this will be possible throughout the entire code (not only under context).
> 2. Enable sugaring by tapping to sqla events and altering the return values. 



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)

Mime
View raw message