ariatosca-dev mailing list archives

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

To service template, service, interface template, interface, operation
template, operation, execution, task.


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

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

----------------------------------------------------------------------
 aria/modeling/orchestration.py    |   2 +-
 aria/modeling/service_changes.py  |  12 --
 aria/modeling/service_common.py   | 202 +++++++++++++++++++++++----------
 aria/modeling/service_instance.py |  37 +++---
 aria/modeling/service_template.py |  38 ++-----
 5 files changed, 167 insertions(+), 124 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/b0d251f4/aria/modeling/orchestration.py
----------------------------------------------------------------------
diff --git a/aria/modeling/orchestration.py b/aria/modeling/orchestration.py
index 3753090..0cee682 100644
--- a/aria/modeling/orchestration.py
+++ b/aria/modeling/orchestration.py
@@ -115,7 +115,7 @@ class ExecutionBase(ModelMixin):
 
     @declared_attr
     def inputs(cls):
-        return relationship.many_to_many(cls, 'input', dict_key='name')
+        return relationship.one_to_many(cls, 'input', dict_key='name')
 
     # region foreign keys
 

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/b0d251f4/aria/modeling/service_changes.py
----------------------------------------------------------------------
diff --git a/aria/modeling/service_changes.py b/aria/modeling/service_changes.py
index 1974424..f632fef 100644
--- a/aria/modeling/service_changes.py
+++ b/aria/modeling/service_changes.py
@@ -105,10 +105,6 @@ class ServiceUpdateBase(ModelMixin):
 
     # endregion
 
-    # region many_to_many relationships
-
-    # endregion
-
     def to_dict(self, suppress_error=False, **kwargs):
         dep_update_dict = super(ServiceUpdateBase, self).to_dict(suppress_error)     #pylint:
disable=no-member
         # Taking care of the fact the DeploymentSteps are _BaseModels
@@ -180,10 +176,6 @@ class ServiceUpdateStepBase(ModelMixin):
 
     # endregion
 
-    # region many_to_many relationships
-
-    # endregion
-
     def __hash__(self):
         return hash((getattr(self, self.id_column_name()), self.entity_id))
 
@@ -266,7 +258,3 @@ class ServiceModificationBase(ModelMixin):
         return relationship.many_to_one(cls, 'service', back_populates='modifications')
 
     # endregion
-
-    # region many_to_many relationships
-
-    # endregion

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/b0d251f4/aria/modeling/service_common.py
----------------------------------------------------------------------
diff --git a/aria/modeling/service_common.py b/aria/modeling/service_common.py
index 2e981a3..1606e78 100644
--- a/aria/modeling/service_common.py
+++ b/aria/modeling/service_common.py
@@ -598,6 +598,86 @@ class InputBase(TemplateModelMixin, caching.HasCachedMethods):
     def value(self, value):
         self._value = value
 
+    # region foreign keys
+
+    @declared_attr
+    def service_template_fk(cls):
+        """For Input many-to-one to ServiceTemplate"""
+        return relationship.foreign_key('service_template', nullable=True)
+
+    @declared_attr
+    def service_fk(cls):
+        """For Input many-to-one to Service"""
+        return relationship.foreign_key('service', nullable=True)
+
+    @declared_attr
+    def interface_fk(cls):
+        """For Input many-to-one to Interface"""
+        return relationship.foreign_key('interface', nullable=True)
+
+    @declared_attr
+    def operation_fk(cls):
+        """For Input many-to-one to Operation"""
+        return relationship.foreign_key('operation', nullable=True)
+
+    @declared_attr
+    def interface_template_fk(cls):
+        """For Input many-to-one to InterfaceTemplate"""
+        return relationship.foreign_key('interface_template', nullable=True)
+
+    @declared_attr
+    def operation_template_fk(cls):
+        """For Input many-to-one to OperationTemplate"""
+        return relationship.foreign_key('operation_template', nullable=True)
+
+    @declared_attr
+    def execution_fk(cls):
+        """For Input many-to-one to Execution"""
+        return relationship.foreign_key('execution', nullable=True)
+
+    @declared_attr
+    def task_fk(cls):
+        """For Input many-to-one to Task"""
+        return relationship.foreign_key('task', 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')
+
+    @declared_attr
+    def interface(cls):
+        return relationship.many_to_one(cls, 'interface')
+
+    @declared_attr
+    def operation(cls):
+        return relationship.many_to_one(cls, 'operation')
+
+    @declared_attr
+    def interface_template(cls):
+        return relationship.many_to_one(cls, 'interface_template')
+
+    @declared_attr
+    def operation_template(cls):
+        return relationship.many_to_one(cls, 'operation_template')
+
+    @declared_attr
+    def execution(cls):
+        return relationship.many_to_one(cls, 'execution')
+
+    @declared_attr
+    def task(cls):
+        return relationship.many_to_one(cls, 'task')
+
+    # endregion
+
     @property
     @caching.cachedmethod
     def owner(self):
@@ -612,7 +692,7 @@ class InputBase(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 # because we are many-to-many, the back reference will be a list
 
         raise ValueError('orphaned input: does not have an owner: {0}'.format(self.name))
 
@@ -666,36 +746,36 @@ class InputBase(TemplateModelMixin, caching.HasCachedMethods):
 
         raise ValueError('orphaned input: 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):
@@ -863,36 +943,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/b0d251f4/aria/modeling/service_instance.py
----------------------------------------------------------------------
diff --git a/aria/modeling/service_instance.py b/aria/modeling/service_instance.py
index 1a162d2..fcd7a55 100644
--- a/aria/modeling/service_instance.py
+++ b/aria/modeling/service_instance.py
@@ -129,6 +129,10 @@ class ServiceBase(InstanceModelMixin):
         return relationship.one_to_many(cls, 'output', dict_key='name')
 
     @declared_attr
+    def inputs(cls):
+        return relationship.one_to_many(cls, 'input', dict_key='name')
+
+    @declared_attr
     def updates(cls):
         return relationship.one_to_many(cls, 'service_update')
 
@@ -174,10 +178,6 @@ class ServiceBase(InstanceModelMixin):
         return relationship.many_to_many(cls, 'metadata', dict_key='name')
 
     @declared_attr
-    def inputs(cls):
-        return relationship.many_to_many(cls, 'input', dict_key='name')
-
-    @declared_attr
     def plugins(cls):
         return relationship.many_to_many(cls, 'plugin', dict_key='name')
 
@@ -511,6 +511,7 @@ class NodeBase(InstanceModelMixin):
     # endregion
 
     # region many_to_many relationships
+
     @declared_attr
     def properties(cls):
         return relationship.many_to_many(cls, 'property', dict_key='name')
@@ -1014,10 +1015,6 @@ class SubstitutionBase(InstanceModelMixin):
 
     # endregion
 
-    # region many_to_many relationships
-
-    # endregion
-
     @property
     def as_raw(self):
         return collections.OrderedDict((
@@ -1122,10 +1119,6 @@ class SubstitutionMappingBase(InstanceModelMixin):
 
     # endregion
 
-    # region many_to_many relationships
-
-    # endregion
-
     @property
     def as_raw(self):
         return collections.OrderedDict((
@@ -1552,6 +1545,10 @@ class InterfaceBase(InstanceModelMixin):
     # region one_to_many relationships
 
     @declared_attr
+    def inputs(cls):
+        return relationship.one_to_many(cls, 'input', dict_key='name')
+
+    @declared_attr
     def operations(cls):
         return relationship.one_to_many(cls, 'operation', dict_key='name')
 
@@ -1581,14 +1578,6 @@ class InterfaceBase(InstanceModelMixin):
 
     # endregion
 
-    # region many_to_many relationships
-
-    @declared_attr
-    def inputs(cls):
-        return relationship.many_to_many(cls, 'input', dict_key='name')
-
-    # endregion
-
     description = Column(Text)
 
     def configure_operations(self):
@@ -1710,6 +1699,10 @@ class OperationBase(InstanceModelMixin):
 
     # region one_to_many relationships
 
+    @declared_attr
+    def inputs(cls):
+        return relationship.one_to_many(cls, 'input', dict_key='name')
+
     # endregion
 
     # region many_to_one relationships
@@ -1731,10 +1724,6 @@ class OperationBase(InstanceModelMixin):
     # region many_to_many relationships
 
     @declared_attr
-    def inputs(cls):
-        return relationship.many_to_many(cls, 'input', dict_key='name')
-
-    @declared_attr
     def configuration(cls):
         return relationship.many_to_many(cls, 'parameter', prefix='configuration', dict_key='name')
 

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/b0d251f4/aria/modeling/service_template.py
----------------------------------------------------------------------
diff --git a/aria/modeling/service_template.py b/aria/modeling/service_template.py
index fd7e80b..5739d18 100644
--- a/aria/modeling/service_template.py
+++ b/aria/modeling/service_template.py
@@ -219,6 +219,10 @@ class ServiceTemplateBase(TemplateModelMixin):
         return relationship.one_to_many(cls, 'output', dict_key='name')
 
     @declared_attr
+    def inputs(cls):
+        return relationship.one_to_many(cls, 'input', 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):
         # Warning! We cannot use the attr name "metadata" because it's used by SQLAlchemy!
         return relationship.many_to_many(cls, 'metadata', dict_key='name')
 
-    @declared_attr
-    def inputs(cls):
-        return relationship.many_to_many(cls, 'input', dict_key='name')
-
     # endregion
 
     @property
@@ -936,10 +936,6 @@ class SubstitutionTemplateBase(TemplateModelMixin):
 
     # endregion
 
-    # region many_to_many relationships
-
-    # endregion
-
     @property
     def as_raw(self):
         return collections.OrderedDict((
@@ -1051,10 +1047,6 @@ class SubstitutionTemplateMappingBase(TemplateModelMixin):
 
     # endregion
 
-    # region many_to_many relationships
-
-    # endregion
-
     @property
     def as_raw(self):
         return collections.OrderedDict((
@@ -1219,10 +1211,6 @@ class RequirementTemplateBase(TemplateModelMixin):
 
     # endregion
 
-    # region many_to_many relationships
-
-    # endregion
-
     target_capability_name = Column(Text)
     target_node_template_constraints = Column(PickleType)
 
@@ -1637,7 +1625,6 @@ class InterfaceTemplateBase(TemplateModelMixin):
                           'group_template_fk',
                           'relationship_template_fk']
 
-
     # region foreign keys
 
     @declared_attr
@@ -1662,7 +1649,6 @@ class InterfaceTemplateBase(TemplateModelMixin):
 
     # endregion
 
-
     # region association proxies
 
     # endregion
@@ -1674,6 +1660,10 @@ class InterfaceTemplateBase(TemplateModelMixin):
     # region one_to_many relationships
 
     @declared_attr
+    def inputs(cls):
+        return relationship.one_to_many(cls, 'input', dict_key='name')
+
+    @declared_attr
     def interfaces(cls):
         return relationship.one_to_many(cls, 'interface')
 
@@ -1703,14 +1693,6 @@ class InterfaceTemplateBase(TemplateModelMixin):
 
     # endregion
 
-    # region many_to_many relationships
-
-    @declared_attr
-    def inputs(cls):
-        return relationship.many_to_many(cls, 'input', dict_key='name')
-
-    # endregion
-
     description = Column(Text)
 
     @property
@@ -1833,6 +1815,10 @@ class OperationTemplateBase(TemplateModelMixin):
     # region one_to_many relationships
 
     @declared_attr
+    def inputs(cls):
+        return relationship.one_to_many(cls, 'input', dict_key='name')
+
+    @declared_attr
     def operations(cls):
         return relationship.one_to_many(cls, 'operation')
 


Mime
View raw message