Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 2BAFE200C2E for ; Sun, 5 Mar 2017 15:17:36 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 2A39A160B6B; Sun, 5 Mar 2017 14:17:36 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 4D8CA160B65 for ; Sun, 5 Mar 2017 15:17:35 +0100 (CET) Received: (qmail 69950 invoked by uid 500); 5 Mar 2017 14:17:31 -0000 Mailing-List: contact dev-help@ariatosca.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ariatosca.incubator.apache.org Delivered-To: mailing list dev@ariatosca.incubator.apache.org Received: (qmail 69939 invoked by uid 99); 5 Mar 2017 14:17:31 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd1-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 05 Mar 2017 14:17:31 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd1-us-west.apache.org (ASF Mail Server at spamd1-us-west.apache.org) with ESMTP id CE8CFC0B16 for ; Sun, 5 Mar 2017 14:17:30 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd1-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -4.021 X-Spam-Level: X-Spam-Status: No, score=-4.021 tagged_above=-999 required=6.31 tests=[KAM_LAZY_DOMAIN_SECURITY=1, RCVD_IN_DNSWL_HI=-5, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RP_MATCHES_RCVD=-0.001] autolearn=disabled Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd1-us-west.apache.org [10.40.0.7]) (amavisd-new, port 10024) with ESMTP id OBK_s5Qt7J68 for ; Sun, 5 Mar 2017 14:17:29 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with SMTP id DA31E5F479 for ; Sun, 5 Mar 2017 14:17:28 +0000 (UTC) Received: (qmail 69830 invoked by uid 99); 5 Mar 2017 14:17:28 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 05 Mar 2017 14:17:28 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 0D6E5DFEE9; Sun, 5 Mar 2017 14:17:28 +0000 (UTC) From: mxmrlv To: dev@ariatosca.incubator.apache.org Reply-To: dev@ariatosca.incubator.apache.org References: In-Reply-To: Subject: [GitHub] incubator-ariatosca pull request #72: Aria 105 integrate modeling Content-Type: text/plain Message-Id: <20170305141728.0D6E5DFEE9@git1-us-west.apache.org> Date: Sun, 5 Mar 2017 14:17:28 +0000 (UTC) archived-at: Sun, 05 Mar 2017 14:17:36 -0000 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. ---