Github user mxmrlv commented on a diff in the pull request:

    https://github.com/apache/incubator-ariatosca/pull/31#discussion_r90778697
  
    --- Diff: aria/storage/models.py ---
    @@ -148,265 +302,220 @@ def __lt__(self, other):
             return False
     
     
    -class DeploymentUpdate(Model):
    +class DeploymentModification(SQLModelBase):
         """
    -    A Model which represents a deployment update
    +    Deployment modification model representation.
         """
    -    INITIALIZING = 'initializing'
    -    SUCCESSFUL = 'successful'
    -    UPDATING = 'updating'
    -    FINALIZING = 'finalizing'
    -    EXECUTING_WORKFLOW = 'executing_workflow'
    -    FAILED = 'failed'
    +    __tablename__ = 'deployment_modifications'
     
    -    STATES = [
    -        INITIALIZING,
    -        SUCCESSFUL,
    -        UPDATING,
    -        FINALIZING,
    -        EXECUTING_WORKFLOW,
    -        FAILED,
    -    ]
    -
    -    # '{0}-{1}'.format(kwargs['deployment_id'], uuid4())
    -    id = Field(type=basestring, default=uuid_generator)
    -    deployment_id = Field(type=basestring)
    -    state = Field(type=basestring, choices=STATES, default=INITIALIZING)
    -    deployment_plan = Field()
    -    deployment_update_nodes = Field(default=None)
    -    deployment_update_node_instances = Field(default=None)
    -    deployment_update_deployment = Field(default=None)
    -    modified_entity_ids = Field(default=None)
    -    execution_id = Field(type=basestring)
    -    steps = IterPointerField(type=DeploymentUpdateStep, default=())
    -
    -
    -class Execution(Model):
    -    """
    -    A Model which represents an execution
    -    """
    +    STARTED = 'started'
    +    FINISHED = 'finished'
    +    ROLLEDBACK = 'rolledback'
     
    -    class _Validation(object):
    -
    -        @staticmethod
    -        def execution_status_transition_validation(_, value, instance):
    -            """Validation function that verifies execution status 
transitions are OK"""
    -            try:
    -                current_status = instance.status
    -            except AttributeError:
    -                return
    -            valid_transitions = 
Execution.VALID_TRANSITIONS.get(current_status, [])
    -            if current_status != value and value not in valid_transitions:
    -                raise ValueError('Cannot change execution status from 
{current} to {new}'.format(
    -                    current=current_status,
    -                    new=value))
    +    STATES = [STARTED, FINISHED, ROLLEDBACK]
    +    END_STATES = [FINISHED, ROLLEDBACK]
     
    -    TERMINATED = 'terminated'
    -    FAILED = 'failed'
    -    CANCELLED = 'cancelled'
    -    PENDING = 'pending'
    -    STARTED = 'started'
    -    CANCELLING = 'cancelling'
    -    STATES = (
    -        TERMINATED,
    -        FAILED,
    -        CANCELLED,
    -        PENDING,
    -        STARTED,
    -        CANCELLING,
    -    )
    -    END_STATES = [TERMINATED, FAILED, CANCELLED]
    -    ACTIVE_STATES = [state for state in STATES if state not in END_STATES]
    -    VALID_TRANSITIONS = {
    -        PENDING: [STARTED, CANCELLED],
    -        STARTED: END_STATES + [CANCELLING],
    -        CANCELLING: END_STATES
    -    }
    +    deployment_fk = foreign_key(Deployment.storage_id)
    +    _private_fields = ['deployment_fk']
    +    deployment_id = association_proxy('deployment', 'id')
     
    -    id = Field(type=basestring, default=uuid_generator)
    -    status = Field(type=basestring, choices=STATES,
    -                   
validation_func=_Validation.execution_status_transition_validation)
    -    deployment_id = Field(type=basestring)
    -    workflow_id = Field(type=basestring)
    -    blueprint_id = Field(type=basestring)
    -    created_at = Field(type=datetime, default=datetime.utcnow)
    -    started_at = Field(type=datetime, default=None)
    -    ended_at = Field(type=datetime, default=None)
    -    error = Field(type=basestring, default=None)
    -    parameters = Field()
    +    context = Column(MutableDict.as_mutable(Dict))
    +    created_at = Column(DateTime, nullable=False, index=True)
    +    ended_at = Column(DateTime, index=True)
    +    modified_nodes = Column(MutableDict.as_mutable(Dict))
    +    node_instances = Column(MutableDict.as_mutable(Dict))
    +    status = Column(Enum(*STATES, name='deployment_modification_status'))
     
    +    @declared_attr
    +    def deployment(cls):
    +        return one_to_many_relationship(cls,
    +                                        Deployment,
    +                                        cls.deployment_fk,
    +                                        backreference='modifications')
     
    -class Relationship(Model):
    +
    +class Node(SQLModelBase):
         """
    -    A Model which represents a relationship
    +    Node model representation.
         """
    -    id = Field(type=basestring, default=uuid_generator)
    -    source_id = Field(type=basestring)
    -    target_id = Field(type=basestring)
    -    source_interfaces = Field(type=dict)
    -    source_operations = Field(type=dict)
    -    target_interfaces = Field(type=dict)
    -    target_operations = Field(type=dict)
    -    type = Field(type=basestring)
    -    type_hierarchy = Field(type=list)
    -    properties = Field(type=dict)
    -
    -
    -class Node(Model):
    +    __tablename__ = 'nodes'
    +
    +    # See base class for an explanation on these properties
    +    is_id_unique = False
    +
    +    _private_fields = ['deployment_fk']
    +    deployment_fk = foreign_key(Deployment.storage_id)
    +
    +    deployment_id = association_proxy('deployment', 'id')
    +    blueprint_id = association_proxy('blueprint', 'id')
    +
    +    @declared_attr
    +    def deployment(cls):
    +        return one_to_many_relationship(cls, Deployment, cls.deployment_fk)
    +
    +    deploy_number_of_instances = Column(Integer, nullable=False)
    +    # TODO: This probably should be a foreign key, but there's no guarantee
    +    # in the code, currently, that the host will be created beforehand
    +    host_id = Column(Text)
    +    max_number_of_instances = Column(Integer, nullable=False)
    +    min_number_of_instances = Column(Integer, nullable=False)
    +    number_of_instances = Column(Integer, nullable=False)
    +    planned_number_of_instances = Column(Integer, nullable=False)
    +    plugins = Column(MutableDict.as_mutable(Dict))
    +    plugins_to_install = Column(MutableDict.as_mutable(Dict))
    +    properties = Column(MutableDict.as_mutable(Dict))
    +    operations = Column(MutableDict.as_mutable(Dict))
    +    type = Column(Text, nullable=False, index=True)
    +    type_hierarchy = Column(PickleType)
    +
    +
    +class Relationship(SQLModelBase):
         """
    -    A Model which represents a node
    +    Relationship model representation.
         """
    -    id = Field(type=basestring, default=uuid_generator)
    -    blueprint_id = Field(type=basestring)
    -    type = Field(type=basestring)
    -    type_hierarchy = Field()
    -    number_of_instances = Field(type=int)
    -    planned_number_of_instances = Field(type=int)
    -    deploy_number_of_instances = Field(type=int)
    -    host_id = Field(type=basestring, default=None)
    -    properties = Field(type=dict)
    -    operations = Field(type=dict)
    -    plugins = Field(type=list, default=())
    -    relationships = IterPointerField(type=Relationship)
    -    plugins_to_install = Field(type=list, default=())
    -    min_number_of_instances = Field(type=int)
    -    max_number_of_instances = Field(type=int)
    -
    -    def relationships_by_target(self, target_id):
    -        """
    -        Retreives all of the relationship by target.
    -        :param target_id: the node id of the target  of the relationship
    -        :yields: a relationship which target and node with the specified 
target_id
    -        """
    -        for relationship in self.relationships:
    -            if relationship.target_id == target_id:
    -                yield relationship
    -        # todo: maybe add here Exception if isn't exists (didn't yield 
one's)
    +    __tablename__ = 'relationships'
     
    +    blueprint_id = association_proxy('blueprint', 'id')
    +    deployment_id = association_proxy('deployment', 'id')
     
    -class RelationshipInstance(Model):
    -    """
    -    A Model which represents a relationship instance
    -    """
    -    id = Field(type=basestring, default=uuid_generator)
    -    target_id = Field(type=basestring)
    -    target_name = Field(type=basestring)
    -    source_id = Field(type=basestring)
    -    source_name = Field(type=basestring)
    -    type = Field(type=basestring)
    -    relationship = PointerField(type=Relationship)
    +    _private_fields = ['source_node_fk', 'target_node_fk']
    +
    +    source_node_fk = foreign_key(Node.storage_id)
    +    target_node_fk = foreign_key(Node.storage_id)
    +
    +    @declared_attr
    +    def source_node(cls):
    +        return one_to_many_relationship(cls, Node, cls.source_node_fk, 
'outbound_relationships')
     
    +    @declared_attr
    +    def target_node(cls):
    +        return one_to_many_relationship(cls, Node, cls.target_node_fk, 
'inbound_relationships')
     
    -class NodeInstance(Model):
    +    source_interfaces = Column(MutableDict.as_mutable(Dict))
    +    source_operations = Column(MutableDict.as_mutable(Dict))
    +    target_interfaces = Column(MutableDict.as_mutable(Dict))
    +    target_operations = Column(MutableDict.as_mutable(Dict))
    +    type = Column(String)
    +    type_hierarchy = Column(PickleType)
    +    properties = Column(MutableDict.as_mutable(Dict))
    +
    +
    +class NodeInstance(SQLModelBase):
         """
    -    A Model which represents a node instance
    +    Node instance model representation.
         """
    -    # todo: add statuses
    -    UNINITIALIZED = 'uninitialized'
    -    INITIALIZING = 'initializing'
    -    CREATING = 'creating'
    -    CONFIGURING = 'configuring'
    -    STARTING = 'starting'
    -    DELETED = 'deleted'
    -    STOPPING = 'stopping'
    -    DELETING = 'deleting'
    -    STATES = (
    -        UNINITIALIZED,
    -        INITIALIZING,
    -        CREATING,
    -        CONFIGURING,
    -        STARTING,
    -        DELETED,
    -        STOPPING,
    -        DELETING
    -    )
    +    __tablename__ = 'node_instances'
     
    -    id = Field(type=basestring, default=uuid_generator)
    -    deployment_id = Field(type=basestring)
    -    runtime_properties = Field(type=dict)
    -    state = Field(type=basestring, choices=STATES, default=UNINITIALIZED)
    -    version = Field(type=(basestring, NoneType))
    -    relationship_instances = IterPointerField(type=RelationshipInstance)
    -    node = PointerField(type=Node)
    -    host_id = Field(type=basestring, default=None)
    -    scaling_groups = Field(default=())
    -
    -    def relationships_by_target(self, target_id):
    -        """
    -        Retreives all of the relationship by target.
    -        :param target_id: the instance id of the target of the relationship
    -        :yields: a relationship instance which target and node with the 
specified target_id
    -        """
    -        for relationship_instance in self.relationship_instances:
    -            if relationship_instance.target_id == target_id:
    -                yield relationship_instance
    -        # todo: maybe add here Exception if isn't exists (didn't yield 
one's)
    +    node_fk = foreign_key(Node.storage_id)
    +    deployment_fk = foreign_key(Deployment.storage_id)
    +    _private_fields = ['node_fk', 'deployment_fk']
    +
    +    node_id = association_proxy('node', 'id')
    +    deployment_id = association_proxy('node', 'deployment_id')
    +
    +    storage_id = Column(Integer, primary_key=True, autoincrement=True)
    +    id = Column(Text, index=True)
    +
    +    # TODO: This probably should be a foreign key, but there's no guarantee
    +    # in the code, currently, that the host will be created beforehand
    +    host_id = Column(Text)
    +    runtime_properties = Column(MutableDict.as_mutable(Dict))
    +    scaling_groups = Column(MutableDict.as_mutable(Dict))
    +    state = Column(Text, nullable=False)
    +    version = Column(Integer, default=1)
     
    +    @declared_attr
    +    def node(cls):
    +        return one_to_many_relationship(cls, Node, cls.node_fk)
     
    -class DeploymentModification(Model):
    +
    +class RelationshipInstance(SQLModelBase):
         """
    -    A Model which represents a deployment modification
    +    Relationship instance model representation.
         """
    -    STARTED = 'started'
    -    FINISHED = 'finished'
    -    ROLLEDBACK = 'rolledback'
    -    END_STATES = [FINISHED, ROLLEDBACK]
    +    __tablename__ = 'relationship_instances'
    +
    +    blueprint_id = association_proxy('blueprint', 'id')
    +    deployment_id = association_proxy('deployment', 'id')
    +
    +    relationship_fk = foreign_key(Relationship.storage_id)
    +    source_node_instance_fk = foreign_key(NodeInstance.storage_id)
    +    target_node_instance_fk = foreign_key(NodeInstance.storage_id)
     
    -    id = Field(type=basestring, default=uuid_generator)
    -    deployment_id = Field(type=basestring)
    -    modified_nodes = Field(type=(dict, NoneType))
    -    added_and_related = IterPointerField(type=NodeInstance)
    -    removed_and_related = IterPointerField(type=NodeInstance)
    -    extended_and_related = IterPointerField(type=NodeInstance)
    -    reduced_and_related = IterPointerField(type=NodeInstance)
    -    # before_modification = IterPointerField(type=NodeInstance)
    -    status = Field(type=basestring, choices=(STARTED, FINISHED, 
ROLLEDBACK))
    -    created_at = Field(type=datetime)
    -    ended_at = Field(type=(datetime, NoneType))
    -    context = Field()
    -
    -
    -class ProviderContext(Model):
    +    _private_fields = ['relationship_storage_fk',
    +                       'source_node_instance_fk',
    +                       'target_node_instance_fk']
    +
    +    @declared_attr
    +    def source_node_instance(cls):
    +        return one_to_many_relationship(cls,
    +                                        NodeInstance,
    +                                        cls.source_node_instance_fk,
    +                                        'outbound_relationship_instances')
    +
    +    @declared_attr
    +    def target_node_instance(cls):
    +        return one_to_many_relationship(cls,
    +                                        NodeInstance,
    +                                        cls.target_node_instance_fk,
    +                                        'inbound_relationship_instances')
    +
    +    @declared_attr
    +    def relationship(cls):
    +        return one_to_many_relationship(cls, Relationship, 
cls.relationship_fk)
    +
    +
    +class ProviderContext(SQLModelBase):
         """
    -    A Model which represents a provider context
    +    Provider context model representation.
         """
    -    id = Field(type=basestring, default=uuid_generator)
    -    context = Field(type=dict)
    -    name = Field(type=basestring)
    +    __tablename__ = 'provider_context'
    +
    +    name = Column(Text, nullable=False)
    +    context = Column(MutableDict.as_mutable(Dict), nullable=False)
     
     
    -class Plugin(Model):
    +class Plugin(SQLModelBase):
         """
    -    A Model which represents a plugin
    +    Plugin model representation.
         """
    -    id = Field(type=basestring, default=uuid_generator)
    -    package_name = Field(type=basestring)
    -    archive_name = Field(type=basestring)
    -    package_source = Field(type=dict)
    -    package_version = Field(type=basestring)
    -    supported_platform = Field(type=basestring)
    -    distribution = Field(type=basestring)
    -    distribution_version = Field(type=basestring)
    -    distribution_release = Field(type=basestring)
    -    wheels = Field()
    -    excluded_wheels = Field()
    -    supported_py_versions = Field(type=list)
    -    uploaded_at = Field(type=datetime)
    -
    -
    -class Task(Model):
    +    __tablename__ = 'plugins'
    +
    +    storage_id = Column(Integer, primary_key=True, autoincrement=True)
    --- End diff --
    
    remvoe


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to