ariatosca-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mxmrlv <...@git.apache.org>
Subject [GitHub] incubator-ariatosca pull request #141: ARIA-262 inconsistent node attributes...
Date Sun, 04 Jun 2017 16:19:32 GMT
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


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

Mime
View raw message