ariatosca-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mxmrlv <...@git.apache.org>
Subject [GitHub] incubator-ariatosca pull request #31: ARIA-30-SQL-based-storage-implementati...
Date Sun, 04 Dec 2016 16:12:52 GMT
Github user mxmrlv commented on a diff in the pull request:

    https://github.com/apache/incubator-ariatosca/pull/31#discussion_r90778632
  
    --- 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)
    --- End diff --
    
    consider replacing fk for id


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message