ariatosca-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject [5/5] incubator-ariatosca git commit: Add output many-to-one relationships
Date Wed, 24 May 2017 11:54:29 GMT
Add output many-to-one relationships

To service template and service.


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

Branch: refs/heads/ARIA-180-convert-parameter-to-one-to-many
Commit: ff9dc08e62da08e2e15e3910d5638b98eac0a6d9
Parents: 6dafdf1
Author: Avia Efrat <avia@gigaspaces.com>
Authored: Wed May 24 14:53:20 2017 +0300
Committer: Avia Efrat <avia@gigaspaces.com>
Committed: Wed May 24 14:53:20 2017 +0300

----------------------------------------------------------------------
 aria/modeling/service_common.py   | 80 ++++++++++++++++++++++------------
 aria/modeling/service_instance.py |  8 ++--
 aria/modeling/service_template.py |  8 ++--
 3 files changed, 61 insertions(+), 35 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/ff9dc08e/aria/modeling/service_common.py
----------------------------------------------------------------------
diff --git a/aria/modeling/service_common.py b/aria/modeling/service_common.py
index 534e466..fec837a 100644
--- a/aria/modeling/service_common.py
+++ b/aria/modeling/service_common.py
@@ -332,36 +332,62 @@ class OutputBase(TemplateModelMixin, caching.HasCachedMethods):
 
         raise ValueError('orphaned output: 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.
-        """
+    # @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
 
-        from . import models
-        container = self.container
-        if isinstance(container, models.Service):
-            return container
-        elif hasattr(container, 'service'):
-            return container.service
-        return None
+    # region foreign keys
 
-    @property
-    @caching.cachedmethod
-    def service_template(self):
-        """
-        The :class:`ServiceTemplate` containing this parameter, or None if not contained
in a
-        service template.
-        """
+    @declared_attr
+    def service_template_fk(cls):
+        """For Output many-to-one to ServiceTemplate"""
+        return relationship.foreign_key('service_template', nullable=True)
 
-        from . import models
-        container = self.container
-        if isinstance(container, models.ServiceTemplate):
-            return container
-        elif hasattr(container, 'service_template'):
-            return container.service_template
-        return None
+    @declared_attr
+    def service_fk(cls):
+        """For Output many-to-one to Service"""
+        return relationship.foreign_key('service', nullable=True)
+
+    # endregion
+
+    # region many_to_one relationships
+
+    @declared_attr
+    def service_template(cls):
+        return relationship.many_to_one(cls, 'service_template')
+
+    @declared_attr
+    def service(cls):
+        return relationship.many_to_one(cls, 'service')
+
+    # endregion
 
     @property
     def as_raw(self):

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/ff9dc08e/aria/modeling/service_instance.py
----------------------------------------------------------------------
diff --git a/aria/modeling/service_instance.py b/aria/modeling/service_instance.py
index 64e64d3..594a531 100644
--- a/aria/modeling/service_instance.py
+++ b/aria/modeling/service_instance.py
@@ -121,6 +121,10 @@ class ServiceBase(InstanceModelMixin):
     # region one_to_many relationships
 
     @declared_attr
+    def outputs(cls):
+        return relationship.one_to_many(cls, 'output', dict_key='name')
+
+    @declared_attr
     def updates(cls):
         return relationship.one_to_many(cls, 'service_update')
 
@@ -170,10 +174,6 @@ class ServiceBase(InstanceModelMixin):
         return relationship.many_to_many(cls, 'input', dict_key='name')
 
     @declared_attr
-    def outputs(cls):
-        return relationship.many_to_many(cls, 'output', dict_key='name')
-
-    @declared_attr
     def plugins(cls):
         return relationship.many_to_many(cls, 'plugin', dict_key='name')
 

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/ff9dc08e/aria/modeling/service_template.py
----------------------------------------------------------------------
diff --git a/aria/modeling/service_template.py b/aria/modeling/service_template.py
index 8788fce..9ba352d 100644
--- a/aria/modeling/service_template.py
+++ b/aria/modeling/service_template.py
@@ -215,6 +215,10 @@ class ServiceTemplateBase(TemplateModelMixin):
         return relationship.one_to_many(cls, 'node_template', dict_key='name')
 
     @declared_attr
+    def outputs(cls):
+        return relationship.one_to_many(cls, 'output', dict_key='name')
+
+    @declared_attr
     def group_templates(cls):
         return relationship.one_to_many(cls, 'group_template', dict_key='name')
 
@@ -247,10 +251,6 @@ class ServiceTemplateBase(TemplateModelMixin):
     def inputs(cls):
         return relationship.many_to_many(cls, 'input', dict_key='name')
 
-    @declared_attr
-    def outputs(cls):
-        return relationship.many_to_many(cls, 'output', dict_key='name')
-
     # endregion
 
     @property


Mime
View raw message