Exemplo n.º 1
0
class WorkflowExecution(Execution):
    """Contains workflow execution information."""

    __tablename__ = 'workflow_executions_v2'

    __table_args__ = (
        sa.Index('%s_project_id' % __tablename__, 'project_id'),
        sa.Index('%s_scope' % __tablename__, 'scope'),
        sa.Index('%s_state' % __tablename__, 'state'),
        sa.Index('%s_updated_at' % __tablename__, 'updated_at'),
    )

    # Main properties.
    accepted = sa.Column(sa.Boolean(), default=False)
    input = sa.Column(st.JsonLongDictType(), nullable=True)
    output = sa.orm.deferred(sa.Column(st.JsonLongDictType(), nullable=True))
    params = sa.Column(st.JsonLongDictType())

    # TODO(rakhmerov): We need to get rid of this field at all.
    context = sa.Column(st.JsonLongDictType())
Exemplo n.º 2
0
class ActionExecution(Execution):
    """Contains action execution information."""

    __tablename__ = 'action_executions_v2'

    __table_args__ = (sa.Index('%s_project_id' % __tablename__, 'project_id'),
                      sa.Index('%s_scope' % __tablename__, 'scope'),
                      sa.Index('%s_state' % __tablename__, 'state'),
                      sa.Index('%s_updated_at' % __tablename__, 'updated_at'))

    # Main properties.
    spec = sa.Column(st.JsonMediumDictType())
    accepted = sa.Column(sa.Boolean(), default=False)
    input = sa.Column(st.JsonLongDictType(), nullable=True)
    output = sa.orm.deferred(sa.Column(st.JsonLongDictType(), nullable=True))
    last_heartbeat = sa.Column(
        sa.DateTime,
        default=lambda: utils.utc_now_sec() + datetime.timedelta(
            seconds=CONF.action_heartbeat.first_heartbeat_timeout))
    is_sync = sa.Column(sa.Boolean(), default=None, nullable=True)
Exemplo n.º 3
0
class TaskExecution(Execution):
    """Contains task runtime information."""

    __tablename__ = 'task_executions_v2'

    __table_args__ = (sa.Index('%s_project_id' % __tablename__, 'project_id'),
                      sa.Index('%s_scope' % __tablename__, 'scope'),
                      sa.Index('%s_state' % __tablename__, 'state'),
                      sa.Index('%s_updated_at' % __tablename__, 'updated_at'),
                      sa.UniqueConstraint('unique_key'))

    # Main properties.
    action_spec = sa.Column(st.JsonLongDictType())
    unique_key = sa.Column(sa.String(255), nullable=True)
    type = sa.Column(sa.String(10))
    started_at = sa.Column(sa.DateTime, nullable=True)
    finished_at = sa.Column(sa.DateTime, nullable=True)

    # Whether the task is fully processed (publishing and calculating commands
    # after it). It allows to simplify workflow controller implementations
    # significantly.
    processed = sa.Column(sa.BOOLEAN, default=False)

    # Data Flow properties.
    in_context = sa.Column(st.JsonLongDictType())
    published = sa.Column(st.JsonLongDictType())

    @property
    def executions(self):
        return (self.action_executions
                if not self.spec.get('workflow') else self.workflow_executions)

    def to_dict(self):
        d = super(TaskExecution, self).to_dict()

        utils.datetime_to_str_in_dict(d, 'started_at')
        utils.datetime_to_str_in_dict(d, 'finished_at')

        return d
Exemplo n.º 4
0
class Execution(mb.MistralSecureModelBase):
    __abstract__ = True

    # Common properties.
    id = mb.id_column()
    name = sa.Column(sa.String(255))
    description = sa.Column(sa.String(255), nullable=True)
    workflow_name = sa.Column(sa.String(255))
    workflow_namespace = sa.Column(sa.String(255))
    workflow_id = sa.Column(sa.String(80))
    state = sa.Column(sa.String(20))
    state_info = sa.Column(sa.Text(), nullable=True)
    tags = sa.Column(st.JsonListType())

    # Internal properties which can be used by engine.
    runtime_context = sa.Column(st.JsonLongDictType())
Exemplo n.º 5
0
class Environment(mb.MistralSecureModelBase):
    """Contains environment variables for workflow execution."""

    __tablename__ = 'environments_v2'

    __table_args__ = (
        sa.UniqueConstraint('name', 'project_id'),
        sa.Index('%s_name' % __tablename__, 'name'),
        sa.Index('%s_project_id' % __tablename__, 'project_id'),
        sa.Index('%s_scope' % __tablename__, 'scope'),
    )

    # Main properties.
    id = mb.id_column()
    name = sa.Column(sa.String(200))
    description = sa.Column(sa.Text())
    variables = sa.Column(st.JsonLongDictType())
def upgrade():
    # Changing column types from JsonDictType to JsonLongDictType
    op.alter_column('executions_v2',
                    'runtime_context',
                    type_=st.JsonLongDictType())
    op.alter_column('executions_v2', 'input', type_=st.JsonLongDictType())
    op.alter_column('executions_v2', 'params', type_=st.JsonLongDictType())
    op.alter_column('executions_v2', 'context', type_=st.JsonLongDictType())
    op.alter_column('executions_v2',
                    'action_spec',
                    type_=st.JsonLongDictType())
    op.alter_column('executions_v2', 'published', type_=st.JsonLongDictType())
def upgrade():

    op.create_table(
        'action_executions_v2',
        sa.Column('created_at', sa.DateTime(), nullable=True),
        sa.Column('updated_at', sa.DateTime(), nullable=True),
        sa.Column('scope', sa.String(length=80), nullable=True),
        sa.Column('project_id', sa.String(length=80), nullable=True),
        sa.Column('id', sa.String(length=36), nullable=False),
        sa.Column('name', sa.String(length=255), nullable=True),
        sa.Column('description', sa.String(length=255), nullable=True),
        sa.Column('workflow_name', sa.String(length=255), nullable=True),
        sa.Column('workflow_id', sa.String(length=80), nullable=True),
        sa.Column('spec', st.JsonMediumDictType(), nullable=True),
        sa.Column('state', sa.String(length=20), nullable=True),
        sa.Column('state_info', sa.TEXT(), nullable=True),
        sa.Column('tags', st.JsonListType(), nullable=True),
        sa.Column('runtime_context', st.JsonLongDictType(), nullable=True),
        sa.Column('accepted', sa.Boolean(), nullable=True),
        sa.Column('input', st.JsonLongDictType(), nullable=True),
        sa.Column('output', st.JsonLongDictType(), nullable=True),
        sa.Column('task_execution_id', sa.String(length=36), nullable=True),

        sa.PrimaryKeyConstraint('id'),

        sa.Index(
            'action_executions_v2_project_id',
            'project_id'
        ),
        sa.Index(
            'action_executions_v2_scope',
            'scope'
        ),
        sa.Index(
            'action_executions_v2_state',
            'state'
        ),
        sa.Index(
            'action_executions_v2_updated_at',
            'updated_at'
        ),
    )

    op.create_table(
        'workflow_executions_v2',
        sa.Column('created_at', sa.DateTime(), nullable=True),
        sa.Column('updated_at', sa.DateTime(), nullable=True),
        sa.Column('scope', sa.String(length=80), nullable=True),
        sa.Column('project_id', sa.String(length=80), nullable=True),
        sa.Column('id', sa.String(length=36), nullable=False),
        sa.Column('name', sa.String(length=255), nullable=True),
        sa.Column('description', sa.String(length=255), nullable=True),
        sa.Column('workflow_name', sa.String(length=255), nullable=True),
        sa.Column('workflow_id', sa.String(length=80), nullable=True),
        sa.Column('spec', st.JsonMediumDictType(), nullable=True),
        sa.Column('state', sa.String(length=20), nullable=True),
        sa.Column('state_info', sa.TEXT(), nullable=True),
        sa.Column('tags', st.JsonListType(), nullable=True),
        sa.Column('runtime_context', st.JsonLongDictType(), nullable=True),
        sa.Column('accepted', sa.Boolean(), nullable=True),
        sa.Column('input', st.JsonLongDictType(), nullable=True),
        sa.Column('output', st.JsonLongDictType(), nullable=True),
        sa.Column('params', st.JsonLongDictType(), nullable=True),
        sa.Column('context', st.JsonLongDictType(), nullable=True),
        sa.Column('task_execution_id', sa.String(length=36), nullable=True),

        sa.PrimaryKeyConstraint('id'),

        sa.Index(
            'workflow_executions_v2_project_id',
            'project_id'
        ),
        sa.Index(
            'workflow_executions_v2_scope',
            'scope'
        ),
        sa.Index(
            'workflow_executions_v2_state',
            'state'
        ),
        sa.Index(
            'workflow_executions_v2_updated_at',
            'updated_at'
        ),
    )

    op.create_table(
        'task_executions_v2',
        sa.Column('created_at', sa.DateTime(), nullable=True),
        sa.Column('updated_at', sa.DateTime(), nullable=True),
        sa.Column('scope', sa.String(length=80), nullable=True),
        sa.Column('project_id', sa.String(length=80), nullable=True),
        sa.Column('id', sa.String(length=36), nullable=False),
        sa.Column('name', sa.String(length=255), nullable=True),
        sa.Column('description', sa.String(length=255), nullable=True),
        sa.Column('workflow_name', sa.String(length=255), nullable=True),
        sa.Column('workflow_id', sa.String(length=80), nullable=True),
        sa.Column('spec', st.JsonMediumDictType(), nullable=True),
        sa.Column('state', sa.String(length=20), nullable=True),
        sa.Column('state_info', sa.TEXT(), nullable=True),
        sa.Column('tags', st.JsonListType(), nullable=True),
        sa.Column('runtime_context', st.JsonLongDictType(), nullable=True),
        sa.Column('action_spec', st.JsonLongDictType(), nullable=True),
        sa.Column('processed', sa.Boolean(), nullable=True),
        sa.Column('in_context', st.JsonLongDictType(), nullable=True),
        sa.Column('published', st.JsonLongDictType(), nullable=True),
        sa.Column(
            'workflow_execution_id',
            sa.String(length=36),
            nullable=True
        ),

        sa.PrimaryKeyConstraint('id'),

        sa.Index(
            'task_executions_v2_project_id',
            'project_id'
        ),
        sa.Index(
            'task_executions_v2_scope',
            'scope'
        ),
        sa.Index(
            'task_executions_v2_state',
            'state'
        ),
        sa.Index(
            'task_executions_v2_updated_at',
            'updated_at'
        ),
        sa.Index(
            'task_executions_v2_workflow_execution_id',
            'workflow_execution_id'
        ),
        sa.ForeignKeyConstraint(
            ['workflow_execution_id'],
            [u'workflow_executions_v2.id'],
            ondelete='CASCADE'
        ),
    )

    # 2 foreign keys are added here because all 3 tables are dependent.
    op.create_foreign_key(
        None,
        'action_executions_v2',
        'task_executions_v2',
        ['task_execution_id'],
        ['id'],
        ondelete='CASCADE'
    )
    op.create_foreign_key(
        None,
        'workflow_executions_v2',
        'task_executions_v2',
        ['task_execution_id'],
        ['id'],
        ondelete='CASCADE'
    )

    op.alter_column(
        'workbooks_v2',
        'name',
        type_=sa.String(length=255)
    )
    op.alter_column(
        'workbooks_v2',
        'definition',
        type_=st.MediumText()
    )
    op.alter_column(
        'workbooks_v2',
        'spec',
        type_=st.JsonMediumDictType()
    )

    op.alter_column(
        'workflow_definitions_v2',
        'name',
        type_=sa.String(length=255)
    )
    op.alter_column(
        'workflow_definitions_v2',
        'definition',
        type_=st.MediumText()
    )
    op.alter_column(
        'workflow_definitions_v2',
        'spec',
        type_=st.JsonMediumDictType()
    )

    op.alter_column(
        'action_definitions_v2',
        'name',
        type_=sa.String(length=255)
    )
    op.alter_column(
        'action_definitions_v2',
        'definition',
        type_=st.MediumText()
    )
    op.alter_column(
        'action_definitions_v2',
        'spec',
        type_=st.JsonMediumDictType()
    )

    op.alter_column(
        'cron_triggers_v2',
        'workflow_name',
        type_=sa.String(length=255)
    )
Exemplo n.º 8
0
def upgrade():
    # Changing column types from JsonDictType to JsonLongDictType
    op.alter_column('environments_v2',
                    'variables',
                    type_=st.JsonLongDictType())
Exemplo n.º 9
0
def upgrade():
    op.create_table(
        'workbooks_v2', sa.Column('created_at', sa.DateTime(), nullable=True),
        sa.Column('updated_at', sa.DateTime(), nullable=True),
        sa.Column('scope', sa.String(length=80), nullable=True),
        sa.Column('project_id', sa.String(length=80), nullable=True),
        sa.Column('id', sa.String(length=36), nullable=False),
        sa.Column('name', sa.String(length=80), nullable=True),
        sa.Column('definition', sa.Text(), nullable=True),
        sa.Column('spec', st.JsonEncoded(), nullable=True),
        sa.Column('tags', st.JsonEncoded(), nullable=True),
        sa.PrimaryKeyConstraint('id'),
        sa.UniqueConstraint('name', 'project_id'))
    op.create_table(
        'tasks', sa.Column('created_at', sa.DateTime(), nullable=True),
        sa.Column('updated_at', sa.DateTime(), nullable=True),
        sa.Column('id', sa.String(length=36), nullable=False),
        sa.Column('name', sa.String(length=80), nullable=True),
        sa.Column('requires', st.JsonEncoded(), nullable=True),
        sa.Column('workbook_name', sa.String(length=80), nullable=True),
        sa.Column('execution_id', sa.String(length=36), nullable=True),
        sa.Column('description', sa.String(length=200), nullable=True),
        sa.Column('task_spec', st.JsonEncoded(), nullable=True),
        sa.Column('action_spec', st.JsonEncoded(), nullable=True),
        sa.Column('state', sa.String(length=20), nullable=True),
        sa.Column('tags', st.JsonEncoded(), nullable=True),
        sa.Column('in_context', st.JsonEncoded(), nullable=True),
        sa.Column('parameters', st.JsonEncoded(), nullable=True),
        sa.Column('output', st.JsonEncoded(), nullable=True),
        sa.Column('task_runtime_context', st.JsonEncoded(), nullable=True),
        sa.PrimaryKeyConstraint('id'))
    op.create_table(
        'action_definitions_v2',
        sa.Column('created_at', sa.DateTime(), nullable=True),
        sa.Column('updated_at', sa.DateTime(), nullable=True),
        sa.Column('scope', sa.String(length=80), nullable=True),
        sa.Column('project_id', sa.String(length=80), nullable=True),
        sa.Column('id', sa.String(length=36), nullable=False),
        sa.Column('name', sa.String(length=80), nullable=True),
        sa.Column('definition', sa.Text(), nullable=True),
        sa.Column('spec', st.JsonEncoded(), nullable=True),
        sa.Column('tags', st.JsonEncoded(), nullable=True),
        sa.Column('description', sa.Text(), nullable=True),
        sa.Column('input', sa.Text(), nullable=True),
        sa.Column('action_class', sa.String(length=200), nullable=True),
        sa.Column('attributes', st.JsonEncoded(), nullable=True),
        sa.Column('is_system', sa.Boolean(), nullable=True),
        sa.PrimaryKeyConstraint('id'),
        sa.UniqueConstraint('name', 'project_id'))
    op.create_table(
        'workflow_definitions_v2',
        sa.Column('created_at', sa.DateTime(), nullable=True),
        sa.Column('updated_at', sa.DateTime(), nullable=True),
        sa.Column('scope', sa.String(length=80), nullable=True),
        sa.Column('project_id', sa.String(length=80), nullable=True),
        sa.Column('id', sa.String(length=36), nullable=False),
        sa.Column('name', sa.String(length=80), nullable=True),
        sa.Column('definition', sa.Text(), nullable=True),
        sa.Column('spec', st.JsonEncoded(), nullable=True),
        sa.Column('tags', st.JsonEncoded(), nullable=True),
        sa.PrimaryKeyConstraint('id'),
        sa.UniqueConstraint('name', 'project_id'))
    op.create_table(
        'executions_v2', sa.Column('created_at', sa.DateTime(), nullable=True),
        sa.Column('updated_at', sa.DateTime(), nullable=True),
        sa.Column('scope', sa.String(length=80), nullable=True),
        sa.Column('project_id', sa.String(length=80), nullable=True),
        sa.Column('type', sa.String(length=50), nullable=True),
        sa.Column('id', sa.String(length=36), nullable=False),
        sa.Column('name', sa.String(length=80), nullable=True),
        sa.Column('workflow_name', sa.String(length=80), nullable=True),
        sa.Column('spec', st.JsonEncoded(), nullable=True),
        sa.Column('state', sa.String(length=20), nullable=True),
        sa.Column('state_info', sa.String(length=1024), nullable=True),
        sa.Column('tags', st.JsonEncoded(), nullable=True),
        sa.Column('accepted', sa.Boolean(), nullable=True),
        sa.Column('input', st.JsonEncoded(), nullable=True),
        sa.Column('output', st.JsonLongDictType(), nullable=True),
        sa.Column('params', st.JsonEncoded(), nullable=True),
        sa.Column('context', st.JsonEncoded(), nullable=True),
        sa.Column('action_spec', st.JsonEncoded(), nullable=True),
        sa.Column('processed', sa.BOOLEAN(), nullable=True),
        sa.Column('in_context', st.JsonLongDictType(), nullable=True),
        sa.Column('published', st.JsonEncoded(), nullable=True),
        sa.Column('runtime_context', st.JsonEncoded(), nullable=True),
        sa.Column('task_execution_id', sa.String(length=36), nullable=True),
        sa.Column('workflow_execution_id', sa.String(length=36),
                  nullable=True),
        sa.ForeignKeyConstraint(
            ['task_execution_id'],
            ['executions_v2.id'],
        ),
        sa.ForeignKeyConstraint(
            ['workflow_execution_id'],
            ['executions_v2.id'],
        ), sa.PrimaryKeyConstraint('id'))
    op.create_table(
        'workbooks', sa.Column('created_at', sa.DateTime(), nullable=True),
        sa.Column('updated_at', sa.DateTime(), nullable=True),
        sa.Column('id', sa.String(length=36), nullable=False),
        sa.Column('name', sa.String(length=80), nullable=False),
        sa.Column('definition', sa.Text(), nullable=True),
        sa.Column('description', sa.String(length=200), nullable=True),
        sa.Column('tags', st.JsonEncoded(), nullable=True),
        sa.Column('scope', sa.String(length=80), nullable=True),
        sa.Column('project_id', sa.String(length=80), nullable=True),
        sa.Column('trust_id', sa.String(length=80), nullable=True),
        sa.PrimaryKeyConstraint('id', 'name'), sa.UniqueConstraint('name'))
    op.create_table(
        'environments_v2', sa.Column('created_at',
                                     sa.DateTime(),
                                     nullable=True),
        sa.Column('updated_at', sa.DateTime(), nullable=True),
        sa.Column('scope', sa.String(length=80), nullable=True),
        sa.Column('project_id', sa.String(length=80), nullable=True),
        sa.Column('id', sa.String(length=36), nullable=False),
        sa.Column('name', sa.String(length=200), nullable=True),
        sa.Column('description', sa.Text(), nullable=True),
        sa.Column('variables', st.JsonEncoded(), nullable=True),
        sa.PrimaryKeyConstraint('id'),
        sa.UniqueConstraint('name', 'project_id'))
    op.create_table(
        'triggers', sa.Column('created_at', sa.DateTime(), nullable=True),
        sa.Column('updated_at', sa.DateTime(), nullable=True),
        sa.Column('id', sa.String(length=36), nullable=False),
        sa.Column('name', sa.String(length=80), nullable=False),
        sa.Column('pattern', sa.String(length=20), nullable=False),
        sa.Column('next_execution_time', sa.DateTime(), nullable=False),
        sa.Column('workbook_name', sa.String(length=80), nullable=False),
        sa.PrimaryKeyConstraint('id'), sa.UniqueConstraint('name'))
    op.create_table(
        'delayed_calls_v2',
        sa.Column('created_at', sa.DateTime(), nullable=True),
        sa.Column('updated_at', sa.DateTime(), nullable=True),
        sa.Column('id', sa.String(length=36), nullable=False),
        sa.Column('factory_method_path', sa.String(length=200), nullable=True),
        sa.Column('target_method_name', sa.String(length=80), nullable=False),
        sa.Column('method_arguments', st.JsonEncoded(), nullable=True),
        sa.Column('serializers', st.JsonEncoded(), nullable=True),
        sa.Column('auth_context', st.JsonEncoded(), nullable=True),
        sa.Column('execution_time', sa.DateTime(), nullable=False),
        sa.PrimaryKeyConstraint('id'))
    op.create_table(
        'workflow_executions',
        sa.Column('created_at', sa.DateTime(), nullable=True),
        sa.Column('updated_at', sa.DateTime(), nullable=True),
        sa.Column('id', sa.String(length=36), nullable=False),
        sa.Column('workbook_name', sa.String(length=80), nullable=True),
        sa.Column('task', sa.String(length=80), nullable=True),
        sa.Column('state', sa.String(length=20), nullable=True),
        sa.Column('context', st.JsonEncoded(), nullable=True),
        sa.PrimaryKeyConstraint('id'))
    op.create_table(
        'cron_triggers_v2',
        sa.Column('created_at', sa.DateTime(), nullable=True),
        sa.Column('updated_at', sa.DateTime(), nullable=True),
        sa.Column('scope', sa.String(length=80), nullable=True),
        sa.Column('project_id', sa.String(length=80), nullable=True),
        sa.Column('id', sa.String(length=36), nullable=False),
        sa.Column('name', sa.String(length=200), nullable=True),
        sa.Column('pattern', sa.String(length=100), nullable=True),
        sa.Column('next_execution_time', sa.DateTime(), nullable=False),
        sa.Column('workflow_name', sa.String(length=80), nullable=True),
        sa.Column('remaining_executions', sa.Integer(), nullable=True),
        sa.Column('workflow_id', sa.String(length=36), nullable=True),
        sa.Column('workflow_input', st.JsonEncoded(), nullable=True),
        sa.Column('workflow_input_hash', sa.CHAR(length=64), nullable=True),
        sa.Column('trust_id', sa.String(length=80), nullable=True),
        sa.ForeignKeyConstraint(
            ['workflow_id'],
            ['workflow_definitions_v2.id'],
        ), sa.PrimaryKeyConstraint('id'),
        sa.UniqueConstraint('name', 'project_id'),
        sa.UniqueConstraint('workflow_input_hash', 'workflow_name', 'pattern',
                            'project_id'))
Exemplo n.º 10
0
class TaskExecution(Execution):
    """Contains task runtime information."""

    __tablename__ = 'task_executions_v2'

    __table_args__ = (
        sa.Index('%s_project_id' % __tablename__, 'project_id'),
        sa.Index('%s_scope' % __tablename__, 'scope'),
        sa.Index('%s_state' % __tablename__, 'state'),
        sa.Index('%s_updated_at' % __tablename__, 'updated_at'),
        sa.UniqueConstraint('unique_key')
    )

    # Main properties.
    spec = sa.orm.deferred(sa.Column(st.JsonMediumDictType()))
    action_spec = sa.Column(st.JsonLongDictType())
    unique_key = sa.Column(sa.String(255), nullable=True)
    type = sa.Column(sa.String(10))
    started_at = sa.Column(sa.DateTime, nullable=True)
    finished_at = sa.Column(sa.DateTime, nullable=True)

    # Whether the task is fully processed (publishing and calculating commands
    # after it). It allows to simplify workflow controller implementations
    # significantly.
    processed = sa.Column(sa.BOOLEAN, default=False)

    # Set to True if the completion of the task led to starting new
    # tasks.
    # The value of this property should be ignored if the task
    # is not completed.
    has_next_tasks = sa.Column(sa.Boolean, default=False)

    # The names of the next tasks.
    # [(task_name, event)]
    next_tasks = sa.Column(st.JsonListType())

    # Set to True if the task finished with an error and the error
    # is handled (e.g. with 'on-error' clause for direct workflows)
    # so that the error shouldn't bubble up to the workflow level.
    # The value of this property should be ignored if the task
    # is not completed.
    error_handled = sa.Column(sa.Boolean, default=False)

    # Data Flow properties.
    in_context = sa.Column(st.JsonLongDictType())
    published = sa.Column(st.JsonLongDictType())

    @property
    def executions(self):
        return (
            self.action_executions
            if not self.spec.get('workflow')
            else self.workflow_executions
        )

    def to_dict(self):
        d = super(TaskExecution, self).to_dict()

        utils.datetime_to_str_in_dict(d, 'started_at')
        utils.datetime_to_str_in_dict(d, 'finished_at')

        return d