ariatosca-dev 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 #72: Aria 105 integrate modeling
Date Sun, 05 Mar 2017 14:17:28 GMT
Github user mxmrlv commented on a diff in the pull request:

    https://github.com/apache/incubator-ariatosca/pull/72#discussion_r104309365
  
    --- Diff: aria/modeling/misc.py ---
    @@ -0,0 +1,232 @@
    +# 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 cPickle as pickle
    +import logging
    +
    +from sqlalchemy import (
    +    Column,
    +    Text,
    +    Binary
    +)
    +from sqlalchemy.ext.declarative import declared_attr
    +
    +from ..storage import exceptions
    +from ..utils import collections, formatting, console
    +from .bases import InstanceModelMixin, TemplateModelMixin
    +from . import utils
    +
    +
    +class ParameterBase(TemplateModelMixin):
    +    """
    +    Represents a typed value.
    +
    +    This class is used by both service template and service instance elements.
    +
    +    :ivar name: Name
    +    :ivar type_name: Type name
    +    :ivar value: Value
    +    :ivar description: Description
    +    """
    +
    +    __tablename__ = 'parameter'
    +
    +    name = Column(Text)
    +    type_name = Column(Text)
    +
    +    # Check: value type
    +    _value = Column(Binary, name='value')
    +    description = Column(Text)
    +
    +    @property
    +    def as_raw(self):
    +        return collections.OrderedDict((
    +            ('name', self.name),
    +            ('type_name', self.type_name),
    +            ('value', self.value),
    +            ('description', self.description)))
    +
    +    @property
    +    def value(self):
    +        if self._value is None:
    +            return None
    +        try:
    +            return pickle.loads(self._value)
    +        except BaseException:
    +            raise exceptions.StorageError('bad format for parameter of type "{0}": {1}'.format(
    +                self.type_name, self._value))
    +
    +    @value.setter
    +    def value(self, value):
    +        if value is None:
    +            self._value = None
    +        else:
    +            try:
    +                self._value = pickle.dumps(value)
    +            except (pickle.PicklingError, TypeError):
    +                logging.getLogger('aria').warn('Could not pickle parameter of type "{0}":
{1}'
    +                                               .format(self.type_name, value))
    +                self._value = pickle.dumps(str(value))
    + 
    +    def instantiate(self, context, container):
    +        from . import models
    +        return models.Parameter(name=self.name,
    +                                type_name=self.type_name,
    +                                _value=self._value,
    +                                description=self.description)
    +
    +    def coerce_values(self, context, container, report_issues):
    +        if self.value is not None:
    +            self.value = utils.coerce_value(context, container, self.value,
    +                                            report_issues)
    +
    +    def dump(self, context):
    +        if self.type_name is not None:
    +            console.puts('{0}: {1} ({2})'.format(
    +                context.style.property(self.name),
    +                context.style.literal(self.value),
    +                context.style.type(self.type_name)))
    +        else:
    +            console.puts('{0}: {1}'.format(
    +                context.style.property(self.name),
    +                context.style.literal(self.value)))
    +        if self.description:
    +            console.puts(context.style.meta(self.description))
    +
    +
    +class TypeBase(InstanceModelMixin):
    +    """
    +    Represents a type and its children.
    +    """
    +
    +    __tablename__ = 'type'
    +
    +    variant = Column(Text, nullable=False) 
    +    description = Column(Text)
    +    _role = Column(Text, name='role')
    +
    +    @declared_attr
    +    def parent(cls):
    +        return cls.relationship_to_self('parent_type_fk')
    +
    +    @declared_attr
    +    def children(cls):
    +        return cls.one_to_many_relationship_to_self('parent_type_fk')
    +
    +    # region foreign keys
    +
    +    __private_fields__ = ['parent_type_fk']
    +
    +    # Type one-to-many to Type
    +    @declared_attr
    +    def parent_type_fk(cls):
    +        return cls.foreign_key('type', nullable=True)
    +
    +    # endregion
    +    
    +    @property
    +    def role(self):
    +        def get_role(the_type):
    +            if the_type is None:
    +                return None
    +            elif the_type._role is None:
    +                return get_role(the_type.parent)
    +            return the_type._role
    +
    +        return get_role(self)
    +
    +    @role.setter
    +    def role(self, value):
    +        self._role = value
    +
    +    def is_descendant(self, base_name, name):
    --- End diff --
    
    base_name/name? the names aren't clear, nor what they represent


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