ariatosca-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject [14/16] incubator-ariatosca git commit: Add property many-to-one relationships
Date Thu, 01 Jun 2017 14:10:30 GMT
Add property many-to-one relationships

To:
node template, node,
group template, group,
policy template, policy,
relationship template, relationship,
capability template, capability,
artifact template, artifact.


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

Branch: refs/heads/ARIA-180-convert-parameter-to-one-to-many
Commit: 3e562785ce389d2f9d748729a96115cad7f19def
Parents: b0d251f
Author: Avia Efrat <avia@gigaspaces.com>
Authored: Wed May 24 17:59:27 2017 +0300
Committer: Avia Efrat <avia@gigaspaces.com>
Committed: Thu Jun 1 12:05:17 2017 +0300

----------------------------------------------------------------------
 aria/modeling/service_common.py   | 178 +++++++++++++++++++++++++++------
 aria/modeling/service_instance.py |  58 +++++------
 aria/modeling/service_template.py |  56 +++++------
 3 files changed, 194 insertions(+), 98 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/3e562785/aria/modeling/service_common.py
----------------------------------------------------------------------
diff --git a/aria/modeling/service_common.py b/aria/modeling/service_common.py
index 1606e78..11f9d01 100644
--- a/aria/modeling/service_common.py
+++ b/aria/modeling/service_common.py
@@ -85,7 +85,6 @@ class ParameterBase(TemplateModelMixin, caching.HasCachedMethods):
 
         raise ValueError('orphaned parameter: does not have an owner: {0}'.format(self.name))
 
-
     @property
     @caching.cachedmethod
     def container(self): # pylint: disable=too-many-return-statements,too-many-branches
@@ -875,6 +874,121 @@ class PropertyBase(TemplateModelMixin, caching.HasCachedMethods):
     def value(self, value):
         self._value = value
 
+    # region foreign keys
+
+    @declared_attr
+    def node_template_fk(cls):
+        """For Property many-to-one to NodeTemplate"""
+        return relationship.foreign_key('node_template', nullable=True)
+
+    @declared_attr
+    def group_template_fk(cls):
+        """For Property many-to-one to GroupTemplate"""
+        return relationship.foreign_key('group_template', nullable=True)
+
+    @declared_attr
+    def policy_template_fk(cls):
+        """For Property many-to-one to PolicyTemplate"""
+        return relationship.foreign_key('policy_template', nullable=True)
+
+    @declared_attr
+    def relationship_template_fk(cls):
+        """For Property many-to-one to RelationshipTemplate"""
+        return relationship.foreign_key('relationship_template', nullable=True)
+
+    @declared_attr
+    def capability_template_fk(cls):
+        """For Property many-to-one to CapabilityTemplate"""
+        return relationship.foreign_key('capability_template', nullable=True)
+
+    @declared_attr
+    def artifact_template_fk(cls):
+        """For Property many-to-one to ArtifactTemplate"""
+        return relationship.foreign_key('artifact_template', nullable=True)
+
+    @declared_attr
+    def node_fk(cls):
+        """For Property many-to-one to Node"""
+        return relationship.foreign_key('node', nullable=True)
+
+    @declared_attr
+    def group_fk(cls):
+        """For Property many-to-one to Group"""
+        return relationship.foreign_key('group', nullable=True)
+
+    @declared_attr
+    def policy_fk(cls):
+        """For Property many-to-one to Policy"""
+        return relationship.foreign_key('policy', nullable=True)
+
+    @declared_attr
+    def relationship_fk(cls):
+        """For Property many-to-one to Relationship"""
+        return relationship.foreign_key('relationship', nullable=True)
+
+    @declared_attr
+    def capability_fk(cls):
+        """For Property many-to-one to Capability"""
+        return relationship.foreign_key('capability', nullable=True)
+
+    @declared_attr
+    def artifact_fk(cls):
+        """For Property many-to-one to Artifact"""
+        return relationship.foreign_key('artifact', nullable=True)
+    # endregion
+
+    # region many_to_one relationships
+
+    @declared_attr
+    def node_template(cls):
+        return relationship.many_to_one(cls, 'node_template')
+
+    @declared_attr
+    def group_template(cls):
+        return relationship.many_to_one(cls, 'group_template')
+
+    @declared_attr
+    def policy_template(cls):
+        return relationship.many_to_one(cls, 'policy_template')
+
+    @declared_attr
+    def relationship_template(cls):
+        return relationship.many_to_one(cls, 'relationship_template')
+
+    @declared_attr
+    def capability_template(cls):
+        return relationship.many_to_one(cls, 'capability_template')
+
+    @declared_attr
+    def artifact_template(cls):
+        return relationship.many_to_one(cls, 'artifact_template')
+
+    @declared_attr
+    def node(cls):
+        return relationship.many_to_one(cls, 'node')
+
+    @declared_attr
+    def group(cls):
+        return relationship.many_to_one(cls, 'group')
+
+    @declared_attr
+    def policy(cls):
+        return relationship.many_to_one(cls, 'policy')
+
+    @declared_attr
+    def relationship(cls):
+        return relationship.many_to_one(cls, 'relationship')
+
+    @declared_attr
+    def capability(cls):
+        return relationship.many_to_one(cls, 'capability')
+
+    @declared_attr
+    def artifact(cls):
+        return relationship.many_to_one(cls, 'artifact')
+
+    # endregion
+
     @property
     @caching.cachedmethod
     def owner(self):
@@ -889,7 +1003,7 @@ class PropertyBase(TemplateModelMixin, caching.HasCachedMethods):
         for the_relationship in self.__mapper__.relationships:
             v = getattr(self, the_relationship.key)
             if v:
-                return v[0] # because we are many-to-many, the back reference will be a list
+                return v
 
         raise ValueError('orphaned property: does not have an owner: {0}'.format(self.name))
 
@@ -943,36 +1057,36 @@ class PropertyBase(TemplateModelMixin, caching.HasCachedMethods):
 
         raise ValueError('orphaned property: does not have a container: {0}'.format(self.name))
 
-    # @property
-    # @caching.cachedmethod
-    # def service(self):
-    #     """
-    #     The :class:`Service` containing this parameter, or None if not contained in a service.
-    #     """
-    #
-    #     from . import models
-    #     container = self.container
-    #     if isinstance(container, models.Service):
-    #         return container
-    #     elif hasattr(container, 'service'):
-    #         return container.service
-    #     return None
-    #
-    # @property
-    # @caching.cachedmethod
-    # def service_template(self):
-    #     """
-    #     The :class:`ServiceTemplate` containing this parameter, or None if not contained
in a
-    #     service template.
-    #     """
-    #
-    #     from . import models
-    #     container = self.container
-    #     if isinstance(container, models.ServiceTemplate):
-    #         return container
-    #     elif hasattr(container, 'service_template'):
-    #         return container.service_template
-    #     return None
+    @property
+    @caching.cachedmethod
+    def service(self):
+        """
+        The :class:`Service` containing this parameter, or None if not contained in a service.
+        """
+
+        from . import models
+        container = self.container
+        if isinstance(container, models.Service):
+            return container
+        elif hasattr(container, 'service'):
+            return container.service
+        return None
+
+    @property
+    @caching.cachedmethod
+    def service_template(self):
+        """
+        The :class:`ServiceTemplate` containing this parameter, or None if not contained
in a
+        service template.
+        """
+
+        from . import models
+        container = self.container
+        if isinstance(container, models.ServiceTemplate):
+            return container
+        elif hasattr(container, 'service_template'):
+            return container.service_template
+        return None
 
     @property
     def as_raw(self):

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/3e562785/aria/modeling/service_instance.py
----------------------------------------------------------------------
diff --git a/aria/modeling/service_instance.py b/aria/modeling/service_instance.py
index fcd7a55..e6fbc6c 100644
--- a/aria/modeling/service_instance.py
+++ b/aria/modeling/service_instance.py
@@ -465,6 +465,10 @@ class NodeBase(InstanceModelMixin):
         return relationship.one_to_many(cls, 'interface', dict_key='name')
 
     @declared_attr
+    def properties(cls):
+        return relationship.one_to_many(cls, 'property', dict_key='name')
+
+    @declared_attr
     def artifacts(cls):
         return relationship.one_to_many(cls, 'artifact', dict_key='name')
 
@@ -513,10 +517,6 @@ class NodeBase(InstanceModelMixin):
     # region many_to_many relationships
 
     @declared_attr
-    def properties(cls):
-        return relationship.many_to_many(cls, 'property', dict_key='name')
-
-    @declared_attr
     def attributes(cls):
         return relationship.many_to_many(cls, 'parameter', prefix='attributes', dict_key='name')
 
@@ -758,6 +758,10 @@ class GroupBase(InstanceModelMixin):
     # region one_to_many relationships
 
     @declared_attr
+    def properties(cls):
+        return relationship.one_to_many(cls, 'property', dict_key='name')
+
+    @declared_attr
     def interfaces(cls):
         return relationship.one_to_many(cls, 'interface', dict_key='name')
 
@@ -785,10 +789,6 @@ class GroupBase(InstanceModelMixin):
     def nodes(cls):
         return relationship.many_to_many(cls, 'node')
 
-    @declared_attr
-    def properties(cls):
-        return relationship.many_to_many(cls, 'property', dict_key='name')
-
     # endregion
 
     description = Column(Text)
@@ -881,6 +881,10 @@ class PolicyBase(InstanceModelMixin):
 
     # region one_to_many relationships
 
+    @declared_attr
+    def properties(cls):
+        return relationship.one_to_many(cls, 'property', dict_key='name')
+
     # endregion
 
     # region many_to_one relationships
@@ -902,10 +906,6 @@ class PolicyBase(InstanceModelMixin):
     # region many_to_many relationships
 
     @declared_attr
-    def properties(cls):
-        return relationship.many_to_many(cls, 'property', dict_key='name')
-
-    @declared_attr
     def nodes(cls):
         return relationship.many_to_many(cls, 'node')
 
@@ -1255,6 +1255,10 @@ class RelationshipBase(InstanceModelMixin):
     def interfaces(cls):
         return relationship.one_to_many(cls, 'interface', dict_key='name')
 
+    @declared_attr
+    def properties(cls):
+        return relationship.one_to_many(cls, 'property', dict_key='name')
+
     # endregion
 
     # region many_to_one relationships
@@ -1283,14 +1287,6 @@ class RelationshipBase(InstanceModelMixin):
 
     # endregion
 
-    # region many_to_many relationships
-
-    @declared_attr
-    def properties(cls):
-        return relationship.many_to_many(cls, 'property', dict_key='name')
-
-    # endregion
-
     source_position = Column(Integer)
     target_position = Column(Integer)
 
@@ -1401,6 +1397,10 @@ class CapabilityBase(InstanceModelMixin):
 
     # region one_to_many relationships
 
+    @declared_attr
+    def properties(cls):
+        return relationship.one_to_many(cls, 'property', dict_key='name')
+
     # endregion
 
     # region many_to_one relationships
@@ -1419,14 +1419,6 @@ class CapabilityBase(InstanceModelMixin):
 
     # endregion
 
-    # region many_to_many relationships
-
-    @declared_attr
-    def properties(cls):
-        return relationship.many_to_many(cls, 'property', dict_key='name')
-
-    # endregion
-
     min_occurrences = Column(Integer, default=None)
     max_occurrences = Column(Integer, default=None)
     occurrences = Column(Integer, default=0)
@@ -1886,6 +1878,10 @@ class ArtifactBase(InstanceModelMixin):
 
     # region one_to_many relationships
 
+    @declared_attr
+    def properties(cls):
+        return relationship.one_to_many(cls, 'property', dict_key='name')
+
     # endregion
 
     # region many_to_one relationships
@@ -1902,12 +1898,6 @@ class ArtifactBase(InstanceModelMixin):
         return relationship.many_to_one(cls, 'type', back_populates=relationship.NO_BACK_POP)
     # endregion
 
-    # region many_to_many relationships
-    @declared_attr
-    def properties(cls):
-        return relationship.many_to_many(cls, 'property', dict_key='name')
-    # endregion
-
     description = Column(Text)
     source_path = Column(Text)
     target_path = Column(Text)

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/3e562785/aria/modeling/service_template.py
----------------------------------------------------------------------
diff --git a/aria/modeling/service_template.py b/aria/modeling/service_template.py
index 5739d18..9ddaae8 100644
--- a/aria/modeling/service_template.py
+++ b/aria/modeling/service_template.py
@@ -495,6 +495,10 @@ class NodeTemplateBase(TemplateModelMixin):
     def requirement_templates(cls):
         return relationship.one_to_many(cls, 'requirement_template', child_fk='node_template_fk')
 
+    @declared_attr
+    def properties(cls):
+        return relationship.one_to_many(cls, 'property', dict_key='name')
+
     # endregion
 
     # region many_to_one relationships
@@ -512,10 +516,6 @@ class NodeTemplateBase(TemplateModelMixin):
     # region many_to_many relationships
 
     @declared_attr
-    def properties(cls):
-        return relationship.many_to_many(cls, 'property', dict_key='name')
-
-    @declared_attr
     def attributes(cls):
         return relationship.many_to_many(cls, 'parameter', prefix='attributes', dict_key='name')
 
@@ -677,6 +677,10 @@ class GroupTemplateBase(TemplateModelMixin):
     def interface_templates(cls):
         return relationship.one_to_many(cls, 'interface_template', dict_key='name')
 
+    @declared_attr
+    def properties(cls):
+        return relationship.one_to_many(cls, 'property', dict_key='name')
+
     # endregion
 
     # region many_to_one relationships
@@ -697,10 +701,6 @@ class GroupTemplateBase(TemplateModelMixin):
     def node_templates(cls):
         return relationship.many_to_many(cls, 'node_template')
 
-    @declared_attr
-    def properties(cls):
-        return relationship.many_to_many(cls, 'property', dict_key='name')
-
     # endregion
 
     description = Column(Text)
@@ -804,6 +804,10 @@ class PolicyTemplateBase(TemplateModelMixin):
     def policies(cls):
         return relationship.one_to_many(cls, 'policy')
 
+    @declared_attr
+    def properties(cls):
+        return relationship.one_to_many(cls, 'property', dict_key='name')
+
     # endregion
 
     # region many_to_one relationships
@@ -828,10 +832,6 @@ class PolicyTemplateBase(TemplateModelMixin):
     def group_templates(cls):
         return relationship.many_to_many(cls, 'group_template')
 
-    @declared_attr
-    def properties(cls):
-        return relationship.many_to_many(cls, 'property', dict_key='name')
-
     # endregion
 
     description = Column(Text)
@@ -1371,6 +1371,10 @@ class RelationshipTemplateBase(TemplateModelMixin):
     def interface_templates(cls):
         return relationship.one_to_many(cls, 'interface_template', dict_key='name')
 
+    @declared_attr
+    def properties(cls):
+        return relationship.one_to_many(cls, 'property', dict_key='name')
+
     # endregion
 
     # region many_to_one relationships
@@ -1381,14 +1385,6 @@ class RelationshipTemplateBase(TemplateModelMixin):
 
     # endregion
 
-    # region many_to_many relationships
-
-    @declared_attr
-    def properties(cls):
-        return relationship.many_to_many(cls, 'property', dict_key='name')
-
-    # endregion
-
     description = Column(Text)
 
     @property
@@ -1493,6 +1489,10 @@ class CapabilityTemplateBase(TemplateModelMixin):
     def capabilities(cls):
         return relationship.one_to_many(cls, 'capability')
 
+    @declared_attr
+    def properties(cls):
+        return relationship.one_to_many(cls, 'property', dict_key='name')
+
     # endregion
 
     # region many_to_one relationships
@@ -1513,10 +1513,6 @@ class CapabilityTemplateBase(TemplateModelMixin):
     def valid_source_node_types(cls):
         return relationship.many_to_many(cls, 'type', prefix='valid_sources')
 
-    @declared_attr
-    def properties(cls):
-        return relationship.many_to_many(cls, 'property', dict_key='name')
-
     # endregion
 
     description = Column(Text)
@@ -1986,6 +1982,10 @@ class ArtifactTemplateBase(TemplateModelMixin):
     def artifacts(cls):
         return relationship.one_to_many(cls, 'artifact')
 
+    @declared_attr
+    def properties(cls):
+        return relationship.one_to_many(cls, 'property', dict_key='name')
+
     # endregion
 
     # region many_to_one relationships
@@ -2000,14 +2000,6 @@ class ArtifactTemplateBase(TemplateModelMixin):
 
     # endregion
 
-    # region many_to_many relationships
-
-    @declared_attr
-    def properties(cls):
-        return relationship.many_to_many(cls, 'property', prefix='properties', dict_key='name')
-
-    # endregion
-
     description = Column(Text)
     source_path = Column(Text)
     target_path = Column(Text)


Mime
View raw message