fixed some private fields

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

Branch: refs/heads/ARIA-39-Genericize-storage-models
Commit: 24b55daccceb22483ef92e89eb8365f082939ac1
Parents: c58987a
Author: mxmrlv <[email protected]>
Authored: Sun Dec 18 16:30:42 2016 +0200
Committer: mxmrlv <[email protected]>
Committed: Sun Dec 18 16:30:42 2016 +0200

----------------------------------------------------------------------
 aria/storage/base_model.py | 73 +++++++++++++++++++----------------------
 1 file changed, 33 insertions(+), 40 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/24b55dac/aria/storage/base_model.py
----------------------------------------------------------------------
diff --git a/aria/storage/base_model.py b/aria/storage/base_model.py
index 4fb23a2..1f1a80c 100644
--- a/aria/storage/base_model.py
+++ b/aria/storage/base_model.py
@@ -129,8 +129,8 @@ class ExecutionBase(ModelBase):
     """
     # Needed only for pylint. the id will be populated by sqlalcehmy and the 
proper column.
     id = None
-
     __tablename__ = 'executions'
+    _private_fields = ['deployment_fk']
 
     TERMINATED = 'terminated'
     FAILED = 'failed'
@@ -150,24 +150,21 @@ class ExecutionBase(ModelBase):
         CANCELLING: END_STATES
     }
 
-    # TODO: maintenance_mode and executions tests fail when the validation is 
on.
-    # @orm.validates('status')
-    # def validate_status(self, key, value):
-    #     """Validation function that verifies execution status transitions 
are OK"""
-    #     try:
-    #         current_status = getattr(self, key)
-    #     except AttributeError:
-    #         return
-    #     valid_transitions = 
ExecutionBase.VALID_TRANSITIONS.get(current_status, [])
-    #     if all([current_status is not None,
-    #             current_status != value,
-    #             value not in valid_transitions]):
-    #         raise ValueError('Cannot change execution status from {current} 
to {new}'.format(
-    #             current=current_status,
-    #             new=value))
-    #     return value
-
-    _private_fields = ['deployment_id', 'blueprint_id']
+    @orm.validates('status')
+    def validate_status(self, key, value):
+        """Validation function that verifies execution status transitions are 
OK"""
+        try:
+            current_status = getattr(self, key)
+        except AttributeError:
+            return
+        valid_transitions = 
ExecutionBase.VALID_TRANSITIONS.get(current_status, [])
+        if all([current_status is not None,
+                current_status != value,
+                value not in valid_transitions]):
+            raise ValueError('Cannot change execution status from {current} to 
{new}'.format(
+                current=current_status,
+                new=value))
+        return value
 
     created_at = Column(DateTime, index=True)
     started_at = Column(DateTime, nullable=True, index=True)
@@ -210,7 +207,7 @@ class DeploymentUpdateBase(ModelBase):
 
     __tablename__ = 'deployment_updates'
 
-    _private_fields = ['execution_id', 'deployment_id']
+    _private_fields = ['execution_fk', 'deployment_fk']
 
     created_at = Column(DateTime, nullable=False, index=True)
     deployment_plan = Column(Dict, nullable=False)
@@ -257,8 +254,8 @@ class DeploymentUpdateStepBase(ModelBase):
     """
     # Needed only for pylint. the id will be populated by sqlalcehmy and the 
proper column.
     id = None
-
     __tablename__ = 'deployment_update_steps'
+    _private_fields = ['deployment_update_fk']
 
     _action_types = namedtuple('ACTION_TYPES', 'ADD, REMOVE, MODIFY')
     ACTION_TYPES = _action_types(ADD='add', REMOVE='remove', MODIFY='modify')
@@ -280,7 +277,6 @@ class DeploymentUpdateStepBase(ModelBase):
         PLUGIN='plugin'
     )
 
-    _private_fields = ['deployment_update_id']
 
     action = Column(Enum(*ACTION_TYPES, name='action_type'), nullable=False)
     entity_id = Column(Text, nullable=False)
@@ -333,6 +329,7 @@ class DeploymentModificationBase(ModelBase):
     Deployment modification model representation.
     """
     __tablename__ = 'deployment_modifications'
+    _private_fields = ['deployment_fk']
 
     STARTED = 'started'
     FINISHED = 'finished'
@@ -341,8 +338,6 @@ class DeploymentModificationBase(ModelBase):
     STATES = [STARTED, FINISHED, ROLLEDBACK]
     END_STATES = [FINISHED, ROLLEDBACK]
 
-    _private_fields = ['deployment_id']
-
     context = Column(Dict)
     created_at = Column(DateTime, nullable=False, index=True)
     ended_at = Column(DateTime, index=True)
@@ -374,7 +369,7 @@ class NodeBase(ModelBase):
     # See base class for an explanation on these properties
     is_id_unique = False
 
-    _private_fields = ['blueprint_id', 'deployment_id', 'host_id']
+    _private_fields = ['blueprint_fk', 'host_fk']
 
     @declared_attr
     def host_id(cls):
@@ -465,7 +460,7 @@ class NodeInstanceBase(ModelBase):
     Node instance model representation.
     """
     __tablename__ = 'node_instances'
-    _private_fields = ['node_id', 'host_id']
+    _private_fields = ['node_fk', 'host_fk']
 
     runtime_properties = Column(Dict)
     scaling_groups = Column(List)
@@ -576,9 +571,7 @@ class TaskBase(ModelBase):
     A Model which represents an task
     """
     __tablename__ = 'tasks'
-    _private_fields = ['node_instance_id',
-                       'relationship_instance_id',
-                       'execution_id']
+    _private_fields = ['node_instance_fk', 'relationship_instance_fk', 
'execution_fk']
 
     @declared_attr
     def node_instance_fk(cls):
@@ -592,17 +585,17 @@ class TaskBase(ModelBase):
     def node_instance(cls):
         return cls.one_to_many_relationship('node_instance_fk', 'NodeInstance')
 
-    # @declared_attr
-    # def relationship_instance_fk(cls):
-    #     return cls.foreign_key('relationship_instances', nullable=True)
-    #
-    # @declared_attr
-    # def relationship_instance_id(cls):
-    #     return association_proxy('relationship_instance', 
cls.user_id_column())
-    #
-    # @declared_attr
-    # def relationship_instance(cls):
-    #     return cls.one_to_many_relationship('relationship_instance_fk', 
'RelationshipInstance')
+    @declared_attr
+    def relationship_instance_fk(cls):
+        return cls.foreign_key('relationship_instances', nullable=True)
+
+    @declared_attr
+    def relationship_instance_id(cls):
+        return association_proxy('relationship_instance', cls.user_id_column())
+
+    @declared_attr
+    def relationship_instance(cls):
+        return cls.one_to_many_relationship('relationship_instance_fk', 
'RelationshipInstance')
 
     PENDING = 'pending'
     RETRYING = 'retrying'

Reply via email to