Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(models): add service tables #241

Merged
merged 2 commits into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

The list of contributors in alphabetical order:

- [Alp Tuna](https://orcid.org/0009-0001-1915-3993)
- [Audrius Mecionis](https://orcid.org/0000-0002-3759-1663)
- [Camila Diaz](https://orcid.org/0000-0001-5543-797X)
- [Daan Rosendal](https://orcid.org/0000-0002-3447-9000)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
"""Add service tables.

Revision ID: 3d0994430da7
Revises: 2e82f33ee37d
Create Date: 2025-01-17 10:05:48.699316

"""

import sqlalchemy_utils
import sqlalchemy as sa
from alembic import op


# revision identifiers, used by Alembic.
revision = "3d0994430da7"
down_revision = "2e82f33ee37d"
branch_labels = None
depends_on = None


def upgrade():
"""Upgrade to 3d0994430da7 revision."""
op.create_table(
"service",
sa.Column("id_", sqlalchemy_utils.types.uuid.UUIDType(), nullable=False),
sa.Column("name", sa.String(length=255), nullable=True),
sa.Column("uri", sa.Text(), nullable=True),
sa.Column(
"status",
sa.Enum(
"created",
"running",
"finished",
"failed",
"deleted",
"stopped",
"queued",
"pending",
name="servicestatus",
),
nullable=False,
),
sa.Column("owner_id", sqlalchemy_utils.types.uuid.UUIDType(), nullable=True),
sa.Column("type_", sa.Enum("dask", name="servicetype"), nullable=False),
sa.ForeignKeyConstraint(
["owner_id"], ["__reana.user_.id_"], name=op.f("fk_service_owner_id_user_")
),
sa.PrimaryKeyConstraint("id_", name=op.f("pk_service")),
sa.UniqueConstraint("name", "uri", name=op.f("uq_service_name")),
schema="__reana",
)
op.create_table(
"workflow_service",
sa.Column("workflow_id", sqlalchemy_utils.types.uuid.UUIDType(), nullable=True),
sa.Column("service_id", sqlalchemy_utils.types.uuid.UUIDType(), nullable=False),
sa.ForeignKeyConstraint(
["service_id"],
["__reana.service.id_"],
name=op.f("fk_workflow_service_service_id_service"),
),
sa.ForeignKeyConstraint(
["workflow_id"],
["__reana.workflow.id_"],
name=op.f("fk_workflow_service_workflow_id_workflow"),
),
sa.PrimaryKeyConstraint("service_id", name=op.f("pk_workflow_service")),
schema="__reana",
)


def downgrade():
"""Downgrade to 2e82f33ee37d revision."""
op.drop_table("workflow_service", schema="__reana")
op.drop_table("service", schema="__reana")
sa.Enum(name="servicestatus").drop(op.get_bind())
sa.Enum(name="servicetype").drop(op.get_bind())
64 changes: 64 additions & 0 deletions reana_db/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,63 @@
return "<InteractiveSession %r>" % self.name


class WorkflowService(Base):
"""Workflow Service table."""

__tablename__ = "workflow_service"
__table_args__ = {"schema": "__reana"}

workflow_id = Column(UUIDType, ForeignKey("__reana.workflow.id_"), nullable=True)
service_id = Column(UUIDType, ForeignKey("__reana.service.id_"), primary_key=True)

def __repr__(self):
"""Workflow Service string representation."""
return f"<WorkflowService {self.service_id} {self.workflow_id}>"

Check warning on line 484 in reana_db/models.py

View check run for this annotation

Codecov / codecov/patch

reana_db/models.py#L484

Added line #L484 was not covered by tests


class ServiceStatus(CleanUpDependingOnStatusMixin, enum.Enum):
"""Enumeration of possible run statuses."""

created = 0
running = 1
finished = 2
failed = 3
deleted = 4
stopped = 5
queued = 6
pending = 7


class ServiceType(enum.Enum):
"""Enumeration of service types."""

dask = 0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this one intended to be general Dask service? I wonder about distinguishing Dask cluster from Dask dashboard, for example in case there would be more services exposed from the Dask integration. But I guess these theoretical distinctions may not be useful as of yet...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can introduce a new service type relatively easily if we need an extra field in the future. Calling the service dask_dashboard or something similar at the moment could be too specific.



class Service(Base):
"""Service table."""

__tablename__ = "service"
id_ = Column(UUIDType, primary_key=True, default=generate_uuid)
name = Column(String(255))
uri = Column(Text) # uri to access the service
status = Column(Enum(ServiceStatus), nullable=False, default=ServiceStatus.created)
owner_id = Column(UUIDType, ForeignKey("__reana.user_.id_"))
type_ = Column(
Enum(ServiceType),
nullable=False,
)

__table_args__ = (
UniqueConstraint("name", "uri"),
{"schema": "__reana"},
)

def __repr__(self):
"""Service string representation."""
return f"<Service(name={self.name}, type={self.type_}, uri={self.uri})>"

Check warning on line 527 in reana_db/models.py

View check run for this annotation

Codecov / codecov/patch

reana_db/models.py#L527

Added line #L527 was not covered by tests


class Workflow(Base, Timestamp, QuotaBase):
"""Workflow table."""

Expand Down Expand Up @@ -510,6 +567,13 @@
backref="workflow",
cascade="all, delete",
)
services = relationship(
"Service",
secondary="__reana.workflow_service",
lazy="dynamic",
backref="workflow",
cascade="all, delete",
)
retention_rules = relationship(
"WorkspaceRetentionRule", backref="workflow", lazy="dynamic"
)
Expand Down
4 changes: 2 additions & 2 deletions reana_db/version.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
#
# This file is part of REANA.
# Copyright (C) 2018, 2019, 2020, 2021, 2022, 2023, 2024 CERN.
# Copyright (C) 2018, 2019, 2020, 2021, 2022, 2023, 2024, 2025 CERN.
#
# REANA is free software; you can redistribute it and/or modify it
# under the terms of the MIT License; see LICENSE file for more details.
Expand All @@ -14,4 +14,4 @@

from __future__ import absolute_import, print_function

__version__ = "0.95.0a4"
__version__ = "0.95.0a5"

Check warning on line 17 in reana_db/version.py

View check run for this annotation

Codecov / codecov/patch

reana_db/version.py#L17

Added line #L17 was not covered by tests
Loading