ariatosca-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mxm...@apache.org
Subject incubator-ariatosca git commit: removed one-to-many relationships
Date Mon, 30 Jan 2017 11:17:48 GMT
Repository: incubator-ariatosca
Updated Branches:
  refs/heads/ARIA-44-Merge-parser-and-storage-models 4fb361305 -> ba3ead9d0


removed one-to-many relationships


Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/ba3ead9d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/ba3ead9d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/ba3ead9d

Branch: refs/heads/ARIA-44-Merge-parser-and-storage-models
Commit: ba3ead9d05e9763c81586af865c0186d18b1df12
Parents: 4fb3613
Author: mxmrlv <mxmrlv@gmail.com>
Authored: Mon Jan 30 13:17:39 2017 +0200
Committer: mxmrlv <mxmrlv@gmail.com>
Committed: Mon Jan 30 13:17:39 2017 +0200

----------------------------------------------------------------------
 aria/storage/modeling/instance_elements.py | 118 +++++++++++++-----------
 aria/storage/modeling/structure.py         |  16 ++--
 aria/storage/modeling/template_elements.py | 114 ++++++++++++-----------
 aria/storage/modeling/utils.py             |   9 ++
 4 files changed, 144 insertions(+), 113 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/ba3ead9d/aria/storage/modeling/instance_elements.py
----------------------------------------------------------------------
diff --git a/aria/storage/modeling/instance_elements.py b/aria/storage/modeling/instance_elements.py
index ce6a83d..d6abeb3 100644
--- a/aria/storage/modeling/instance_elements.py
+++ b/aria/storage/modeling/instance_elements.py
@@ -37,6 +37,7 @@ from . import (
 
 # region Element instances
 
+
 class ServiceInstanceBase(structure.ModelMixin):
     __tablename__ = 'service_instance'
 
@@ -76,25 +77,6 @@ class ServiceInstanceBase(structure.ModelMixin):
         return cls.one_to_one_relationship('substitution')
     # endregion
 
-    # region one-to-many relationships
-    @declared_attr
-    def nodes(cls):
-        return cls.one_to_many_relationship('node')
-
-    @declared_attr
-    def groups(cls):
-        return cls.one_to_many_relationship('group')
-
-    @declared_attr
-    def policies(cls):
-        return cls.one_to_many_relationship('policy')
-
-    @declared_attr
-    def operations(cls):
-        return cls.one_to_many_relationship('operation')
-
-    # endregion
-
     # region many-to-one relationships
     @declared_attr
     def service_template(cls):
@@ -185,6 +167,7 @@ class OperationBase(structure.ModelMixin):
     """
     __tablename__ = 'operation'
     # region foreign_keys
+
     @declared_attr
     def service_instance_fk(cls):
         return cls.foreign_key('service_instance', nullable=True)
@@ -203,6 +186,15 @@ class OperationBase(structure.ModelMixin):
     retry_interval = Column(Integer, default=None)
     plugin = Column(Text)
     operation = Column(Boolean)
+
+    # region many-to-one relationships
+    @declared_attr
+    def service_instance(cls):
+        return cls.many_to_one_relationship('service_instance')
+
+    @declared_attr
+    def interfaces(cls):
+        return cls.many_to_one_relationship('interface')
     # region many-to-many relationships
 
     @declared_attr
@@ -280,13 +272,27 @@ class InterfaceBase(structure.ModelMixin):
     description = Column(Text)
     type_name = Column(Text)
 
-    # region one-to-many relationships
+    # region many-to-one relationships
+
+    @declared_attr
+    def node(cls):
+        return cls.many_to_one_relationship('node')
+
     @declared_attr
-    def operations(cls):
-        return cls.one_to_many_relationship('operation')
+    def relationship(cls):
+        return cls.many_to_one_relationship('relationship')
+
+    @declared_attr
+    def group(cls):
+        return cls.many_to_one_relationship('group')
+
+    # endregion
+
 
     # endregion
 
+
+
     # region many-to-many relationships
 
     @declared_attr
@@ -356,6 +362,15 @@ class CapabilityBase(structure.ModelMixin):
     max_occurrences = Column(Integer, default=None) # optional
     occurrences = Column(Integer, default=0)
 
+
+    # region many-to-one relationships
+    @declared_attr
+    def node(cls):
+        return cls.many_to_one_relationship('node')
+
+    # endregion
+
+
     # region many-to-many relationships
     @declared_attr
     def properties(cls):
@@ -439,6 +454,14 @@ class ArtifactBase(structure.ModelMixin):
     repository_url = Column(Text)
     repository_credential = Column(aria_types.StrictDict(basestring, basestring))
 
+    # region many-to-one relationships
+    @declared_attr
+    def node(cls):
+        return cls.many_to_one_relationship('node')
+
+    # endregion
+
+
     # region many-to-many relationships
 
     @declared_attr
@@ -510,6 +533,11 @@ class PolicyBase(structure.ModelMixin):
     target_node_ids = Column(aria_types.StrictList(basestring))
     target_group_ids = Column(aria_types.StrictList(basestring))
 
+    # region many-to-one relationships
+    @declared_attr
+    def service_instnce(cls):
+        return cls.many_to_one_relationship('service_instance')
+
     # region many-to-many relationships
 
     @declared_attr
@@ -578,20 +606,19 @@ class GroupPolicyBase(structure.ModelMixin):
     description = Column(Text)
     type_name = Column(Text)
 
-    # region one-to-many relationships
-
+    # region many-to-one relationships
     @declared_attr
-    def triggers(cls):
-        return cls.one_to_many_relationship('group_policy_trigger')
+    def group(cls):
+        return cls.many_to_one_relationship('group')
 
-    # endregion
+    # end region
 
     # region many-to-many relationships
     @declared_attr
     def properties(cls):
         return cls.many_to_many_relationship('parameter', table_prefix='properties')
 
-    # relationships
+    # endregion
 
     @property
     def as_raw(self):
@@ -650,6 +677,14 @@ class GroupPolicyTriggerBase(structure.ModelMixin):
     description = Column(Text)
     implementation = Column(Text)
 
+    # region many-to-one relationships
+
+    @declared_attr
+    def group_policy(cls):
+        return cls.many_to_one_relationship('group_policy')
+
+    # endregion
+
     # region many-to-many relationships
 
     @declared_attr
@@ -844,21 +879,6 @@ class NodeBase(structure.ModelMixin):
         return association_proxy('service_instance', 'service_template')
     # endregion
 
-    # region one-to-many relationships
-    @declared_attr
-    def interfaces(cls):
-        return cls.one_to_many_relationship('interface')
-
-    @declared_attr
-    def artifacts(cls):
-        return cls.one_to_many_relationship('artifact')
-
-    @declared_attr
-    def capabilities(cls):
-        return cls.one_to_many_relationship('capability')
-
-    # endregion
-
     # region many-to-one relationships
     @declared_attr
     def service_instance(cls):
@@ -1036,16 +1056,10 @@ class GroupBase(structure.ModelMixin):
     member_node_ids = Column(aria_types.StrictList(basestring))
     member_group_ids = Column(aria_types.StrictList(basestring))
 
-    # region one-to-many relationships
-    @declared_attr
-    def interfaces(cls):
-        return cls.one_to_many_relationship('interface')
-
+    # region many-to-one relationships
     @declared_attr
-    def policies(cls):
-        return cls.one_to_many_relationship('group_policy')
-
-    # endregion
+    def service_instance(cls):
+        return cls.many_to_one_relationship('service_instance')
 
     # region many-to-many relationships
     @declared_attr

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/ba3ead9d/aria/storage/modeling/structure.py
----------------------------------------------------------------------
diff --git a/aria/storage/modeling/structure.py b/aria/storage/modeling/structure.py
index 7d7a3de..ae562fb 100644
--- a/aria/storage/modeling/structure.py
+++ b/aria/storage/modeling/structure.py
@@ -37,6 +37,8 @@ from sqlalchemy import (
     Table
 )
 
+from . import utils
+
 
 class Function(object):
     """
@@ -158,15 +160,17 @@ class ModelMixin(ElementBase):
         backref_kwargs.setdefault('cascade', 'all')
 
         return relationship(lambda: cls._get_cls_by_tablename(parent_table_name),
-                            backref=backref(backreference or cls.__tablename__,
+                            backref=backref(backreference or utils.pluralize(cls.__tablename__),
                                             **backref_kwargs or {}),
                             **relationship_kwargs)
 
-    @classmethod
-    def one_to_many_relationship(cls, child_table_name, backrefernce=None):
-        return relationship(lambda: cls._get_cls_by_tablename(child_table_name),
-                            backref=backrefernce or '{0}s'.format(cls.__tablename__),
-                            lazy='dynamic')
+
+
+    # @classmethod
+    # def one_to_many_relationship(cls, child_table_name, backrefernce=None):
+    #     return relationship(lambda: cls._get_cls_by_tablename(child_table_name),
+    #                         backref=backrefernce or '{0}s'.format(cls.__tablename__),
+    #                         lazy='dynamic')
 
     @classmethod
     def relationship_to_self(cls, local_column):

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/ba3ead9d/aria/storage/modeling/template_elements.py
----------------------------------------------------------------------
diff --git a/aria/storage/modeling/template_elements.py b/aria/storage/modeling/template_elements.py
index becd45b..c382e7b 100644
--- a/aria/storage/modeling/template_elements.py
+++ b/aria/storage/modeling/template_elements.py
@@ -70,29 +70,6 @@ class ServiceTemplateBase(structure.ModelMixin):
         return cls.one_to_one_relationship('substitution_template')
     # endregion
 
-    # # region one-to-many relationships
-    @declared_attr
-    def node_templates(cls):
-        return cls.one_to_many_relationship('node_template')
-
-    @declared_attr
-    def group_templates(cls):
-        return cls.one_to_many_relationship('group_template')
-
-    @declared_attr
-    def policy_templates(cls):
-        return cls.one_to_many_relationship('policy_template')
-
-    @declared_attr
-    def operation_templates(cls):
-        """
-        Custom workflows
-        :return:
-        """
-        return cls.one_to_many_relationship('operation_template')
-
-    # endregion
-
     # region many-to-many relationships
 
     @declared_attr
@@ -210,10 +187,16 @@ class InterfaceTemplateBase(structure.ModelMixin):
     description = Column(Text)
     type_name = Column(Text)
 
-    # region one-to-many relationships
+    # region many-to-one relationship
+    @declared_attr
+    def node_template(cls):
+        return cls.many_to_one_relationship('node_template')
+
     @declared_attr
-    def operation_templates(cls):
-        return cls.one_to_many_relationship('operation_template')
+    def group_template(cls):
+        return cls.many_to_one_relationship('group_template')
+
+    # endregion
 
     # region many-to-many relationships
 
@@ -293,10 +276,16 @@ class OperationTemplateBase(structure.ModelMixin):
     plugin = Column(Text)
     operation = Column(Boolean)
 
+    # region many-to-one relationships
     @declared_attr
     def service_template(cls):
         return cls.many_to_one_relationship('service_template')
 
+    @declared_attr
+    def interface_template(cls):
+        return cls.many_to_one_relationship('interface_template')
+    # endregion
+
     # region many-to-many relationships
 
     @declared_attr
@@ -384,6 +373,12 @@ class ArtifactTemplateBase(structure.ModelMixin):
     repository_url = Column(Text)
     repository_credential = Column(aria_type.StrictDict(basestring, basestring))
 
+    # region many-to-one relationship
+    @declared_attr
+    def node_template(cls):
+        return cls.many_to_one_relationship('node_template')
+    # endregion
+
     # region many-to-many relationships
 
     @declared_attr
@@ -472,6 +467,17 @@ class PolicyTemplateBase(structure.ModelMixin):
     target_node_template_names = Column(aria_type.StrictList(basestring))
     target_group_template_names = Column(aria_type.StrictList(basestring))
 
+    # region many-to-one relationship
+    @declared_attr
+    def service_template(cls):
+        return cls.many_to_one_relationship('service_template')
+
+    @declared_attr
+    def group_template(cls):
+        return cls.many_to_one_relationship('group_template')
+
+    # endregion
+
     # region many-to-many relationships
 
     @declared_attr
@@ -551,13 +557,6 @@ class GroupPolicyTemplateBase(structure.ModelMixin):
     description = Column(Text)
     type_name = Column(Text)
 
-    # region one-to-many relationships
-    @declared_attr
-    def triggers(cls):
-        return cls.one_to_many_relationship('group_policy_trigger_template')
-
-    # end region
-
     # region many-to-many relationships
 
     @declared_attr
@@ -627,6 +626,14 @@ class GroupPolicyTriggerTemplateBase(structure.ModelMixin):
     description = Column(Text)
     implementation = Column(Text)
 
+    # region many-to-one relationship
+    @declared_attr
+    def group_policy_template(cls):
+        return cls.many_to_one_relationship('group_policy_template')
+
+    # endregion
+
+
     # region many-to-many relationships
 
     @declared_attr
@@ -820,22 +827,10 @@ class NodeTemplateBase(structure.ModelMixin):
 
     # endregion
 
-    # region one-to-many relationships
-    @declared_attr
-    def interface_templates(cls):
-        return cls.one_to_many_relationship('interface_template')
-
-    @declared_attr
-    def artifact_templates(cls):
-        return cls.one_to_many_relationship('artifact_template')
-
-    @declared_attr
-    def capability_templates(cls):
-        return cls.one_to_many_relationship('capability_template')
-
+    # region many-to-one relationship
     @declared_attr
-    def requirement_templates(cls):
-        return cls.one_to_many_relationship('requirement_template')
+    def service_template(cls):
+        return cls.many_to_one_relationship('service_template')
 
     # endregion
 
@@ -956,14 +951,10 @@ class GroupTemplateBase(structure.ModelMixin):
     member_node_template_names = Column(aria_type.StrictList(basestring))
     member_group_template_names = Column(aria_type.StrictList(basestring))
 
-    # region one-to-many relationships
+    # region many-to-one relationship
     @declared_attr
-    def interface_templates(cls):
-        return cls.one_to_many_relationship('interface_template')
-
-    @declared_attr
-    def policy_templates(cls):
-        return cls.one_to_many_relationship('policy_template')
+    def service_template(cls):
+        return cls.many_to_one_relationship('service_template')
 
     # endregion
 
@@ -1061,6 +1052,7 @@ class RequirementTemplateBase(structure.ModelMixin):
 
     # endregion
 
+
     target_node_type_name = Column(Text)
     target_node_template_name = Column(Text)
     target_node_template_constraints = Column(aria_type.StrictList(FunctionType))
@@ -1069,6 +1061,12 @@ class RequirementTemplateBase(structure.ModelMixin):
     # CHECK: ???
     relationship_template = Column(Text)  # optional
 
+    # region many-to-one relationship
+    @declared_attr
+    def node_template(cls):
+        return cls.many_to_one_relationship('node_template')
+    # endregion
+
     def instantiate(self, context, container):
         raise NotImplementedError
 
@@ -1219,6 +1217,12 @@ class CapabilityTemplateBase(structure.ModelMixin):
     # CHECK: type?
     valid_source_node_type_names = Column(Text)
 
+    # region many-to-one relationship
+    @declared_attr
+    def node_template(cls):
+        return cls.many_to_one_relationship('node_template')
+    # endregion
+
     # region many-to-many relationships
 
     @declared_attr

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/ba3ead9d/aria/storage/modeling/utils.py
----------------------------------------------------------------------
diff --git a/aria/storage/modeling/utils.py b/aria/storage/modeling/utils.py
index 22f6680..b59959c 100644
--- a/aria/storage/modeling/utils.py
+++ b/aria/storage/modeling/utils.py
@@ -120,3 +120,12 @@ def dump_interfaces(context, interfaces, name='Interfaces'):
     with context.style.indent:
         for interface in interfaces.itervalues():
             interface.dump(context)
+
+
+def pluralize(noun):
+    if noun.endswith('s'):
+        return '{0}es'.format(noun)
+    elif noun.endswith('y'):
+        return '{0}ies'.format(noun[:-1])
+    else:
+        return '{0}s'.format(noun)


Mime
View raw message