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 CDF0E200C7D for ; Tue, 2 May 2017 00:23:57 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id CC93C160BC2; Mon, 1 May 2017 22:23:57 +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 EADAA160BC6 for ; Tue, 2 May 2017 00:23:56 +0200 (CEST) Received: (qmail 32484 invoked by uid 500); 1 May 2017 22:23:56 -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 32436 invoked by uid 99); 1 May 2017 22:23:56 -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; Mon, 01 May 2017 22:23:56 +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 BE086C1077 for ; Mon, 1 May 2017 22:23:55 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd1-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -4.222 X-Spam-Level: X-Spam-Status: No, score=-4.222 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, RCVD_IN_DNSWL_HI=-5, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RP_MATCHES_RCVD=-0.001, SPF_PASS=-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 QjHBi_XN1ijZ for ; Mon, 1 May 2017 22:23:53 +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 1731860CD8 for ; Mon, 1 May 2017 22:23:51 +0000 (UTC) Received: (qmail 32223 invoked by uid 99); 1 May 2017 22:23:51 -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; Mon, 01 May 2017 22:23:51 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 26C4CE967A; Mon, 1 May 2017 22:23:51 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: emblemparade@apache.org To: dev@ariatosca.incubator.apache.org Date: Mon, 01 May 2017 22:23:58 -0000 Message-Id: In-Reply-To: <8aa4e3e1df5b4612b57a404b496faeb6@git.apache.org> References: <8aa4e3e1df5b4612b57a404b496faeb6@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [09/13] incubator-ariatosca git commit: ARIA-158 Restore support for relationship ordering archived-at: Mon, 01 May 2017 22:23:57 -0000 ARIA-158 Restore support for relationship ordering Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/1f3e7ff4 Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/1f3e7ff4 Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/1f3e7ff4 Branch: refs/heads/ARIA-139-attributes Commit: 1f3e7ff42fefcd5dc8191e3b0eeac0460db059b0 Parents: 5bc28b6 Author: max-orlov Authored: Thu Apr 27 17:09:14 2017 +0300 Committer: max-orlov Committed: Thu Apr 27 17:20:48 2017 +0300 ---------------------------------------------------------------------- aria/modeling/relationship.py | 8 +++++--- aria/modeling/service_instance.py | 27 ++++++++++++++++++++------- tests/modeling/test_mixins.py | 7 +++++-- 3 files changed, 30 insertions(+), 12 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/1f3e7ff4/aria/modeling/relationship.py ---------------------------------------------------------------------- diff --git a/aria/modeling/relationship.py b/aria/modeling/relationship.py index e6830b8..291d08c 100644 --- a/aria/modeling/relationship.py +++ b/aria/modeling/relationship.py @@ -14,7 +14,6 @@ # limitations under the License. # pylint: disable=invalid-name, redefined-outer-name - from sqlalchemy.orm import relationship, backref from sqlalchemy.orm.collections import attribute_mapped_collection from sqlalchemy import ( @@ -161,7 +160,8 @@ def one_to_many(model_class, child_table, child_fk=None, dict_key=None, - back_populates=None): + back_populates=None, + rel_kwargs=None): """ Declare a one-to-many relationship property. The property value would be a list or dict of instances of the child table's model. @@ -186,6 +186,8 @@ def one_to_many(model_class, false to disable :type back_populates: basestring|bool """ + rel_kwargs = rel_kwargs or {} + rel_kwargs.setdefault('cascade', 'all') if back_populates is None: back_populates = model_class.__tablename__ return _relationship( @@ -194,7 +196,7 @@ def one_to_many(model_class, back_populates=back_populates, other_fk=child_fk, dict_key=dict_key, - relationship_kwargs=dict(cascade='all')) + relationship_kwargs=rel_kwargs) def many_to_one(model_class, http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/1f3e7ff4/aria/modeling/service_instance.py ---------------------------------------------------------------------- diff --git a/aria/modeling/service_instance.py b/aria/modeling/service_instance.py index 6d8f3fe..d5391ef 100644 --- a/aria/modeling/service_instance.py +++ b/aria/modeling/service_instance.py @@ -25,6 +25,7 @@ from sqlalchemy import ( from sqlalchemy import DateTime from sqlalchemy.ext.associationproxy import association_proxy from sqlalchemy.ext.declarative import declared_attr +from sqlalchemy.ext.orderinglist import ordering_list from .mixins import InstanceModelMixin from ..orchestrator import execution_plugin @@ -485,12 +486,22 @@ class NodeBase(InstanceModelMixin): @declared_attr def outbound_relationships(cls): return relationship.one_to_many( - cls, 'relationship', child_fk='source_node_fk', back_populates='source_node') + cls, 'relationship', child_fk='source_node_fk', back_populates='source_node', + rel_kwargs=dict( + order_by='Relationship.source_position', + collection_class=ordering_list('source_position', count_from=0) + ) + ) @declared_attr def inbound_relationships(cls): return relationship.one_to_many( - cls, 'relationship', child_fk='target_node_fk', back_populates='target_node') + cls, 'relationship', child_fk='target_node_fk', back_populates='target_node', + rel_kwargs=dict( + order_by='Relationship.target_position', + collection_class=ordering_list('target_position', count_from=0) + ) + ) # endregion @@ -1166,9 +1177,9 @@ class RelationshipBase(InstanceModelMixin): :vartype properties: {basestring: :class:`Parameter`} :ivar interfaces: Bundles of operations :vartype interfaces: {basestring: :class:`Interfaces`} - :ivar source_position: ?? + :ivar source_position: The position of the relationship in the outbound relationships. :vartype source_position: int - :ivar target_position: ?? + :ivar target_position: The position of the relationship in the inbound relationships. :vartype target_position: int :ivar source_node: Source node :vartype source_node: :class:`Node` @@ -1185,7 +1196,9 @@ class RelationshipBase(InstanceModelMixin): 'target_node_fk', 'target_capability_fk', 'requirement_template_fk', - 'relationship_template_fk'] + 'relationship_template_fk', + 'target_position', + 'source_position'] # region foreign keys @@ -1289,8 +1302,8 @@ class RelationshipBase(InstanceModelMixin): # endregion - source_position = Column(Integer) # ??? - target_position = Column(Integer) # ??? + source_position = Column(Integer) + target_position = Column(Integer) def configure_operations(self): for interface in self.interfaces.itervalues(): http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/1f3e7ff4/tests/modeling/test_mixins.py ---------------------------------------------------------------------- diff --git a/tests/modeling/test_mixins.py b/tests/modeling/test_mixins.py index 651f53f..cd7cadf 100644 --- a/tests/modeling/test_mixins.py +++ b/tests/modeling/test_mixins.py @@ -155,7 +155,10 @@ def test_relationship_model_ordering(context): """ assert direction in ('inbound', 'outbound') - relationships = getattr(node, direction + '_relationships') + def get_relationships(): + return getattr(node, direction + '_relationships') + + relationships = get_relationships() assert len(relationships) == 2 reversed_relationship = list(reversed(relationships)) @@ -163,7 +166,7 @@ def test_relationship_model_ordering(context): relationships[:] = reversed_relationship context.model.node.update(node) - assert relationships == reversed_relationship + assert get_relationships() == reversed_relationship flip_and_assert(source_node, 'outbound') flip_and_assert(target_node, 'inbound')