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: add support for sessions in Renku 2.0 #133

Merged
merged 15 commits into from
Mar 14, 2024
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
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ components/renku_data_services/users/apispec.py: components/renku_data_services/
poetry run datamodel-codegen --input components/renku_data_services/users/api.spec.yaml --input-file-type openapi --output-model-type pydantic_v2.BaseModel --output components/renku_data_services/users/apispec.py --use-double-quotes --target-python-version 3.11 --collapse-root-models --field-constraints --strict-nullable --base-class renku_data_services.users.apispec_base.BaseAPISpec
components/renku_data_services/project/apispec.py: components/renku_data_services/project/api.spec.yaml
poetry run datamodel-codegen --input components/renku_data_services/project/api.spec.yaml --input-file-type openapi --output-model-type pydantic_v2.BaseModel --output components/renku_data_services/project/apispec.py --use-double-quotes --target-python-version 3.11 --collapse-root-models --field-constraints --strict-nullable --base-class renku_data_services.project.apispec_base.BaseAPISpec
components/renku_data_services/session/apispec.py: components/renku_data_services/session/api.spec.yaml
poetry run datamodel-codegen --input components/renku_data_services/session/api.spec.yaml --input-file-type openapi --output-model-type pydantic_v2.BaseModel --output components/renku_data_services/session/apispec.py --use-double-quotes --target-python-version 3.11 --collapse-root-models --field-constraints --strict-nullable --base-class renku_data_services.session.apispec_base.BaseAPISpec
components/renku_data_services/user_preferences/apispec.py: components/renku_data_services/user_preferences/api.spec.yaml
poetry run datamodel-codegen --input components/renku_data_services/user_preferences/api.spec.yaml --input-file-type openapi --output-model-type pydantic_v2.BaseModel --output components/renku_data_services/user_preferences/apispec.py --use-double-quotes --target-python-version 3.11 --collapse-root-models --field-constraints --strict-nullable --base-class renku_data_services.user_preferences.apispec_base.BaseAPISpec

Expand Down Expand Up @@ -67,7 +69,7 @@ tests:
@echo "===========================================DATA API==========================================="
DUMMY_STORES=true poetry run sanic --debug renku_data_services.data_api.main:create_app --factory & echo $$! > .tmp.pid
@sleep 10
poetry run st run http://localhost:8000/api/data/spec.json --validate-schema True --checks all --hypothesis-max-examples 20 --data-generation-method all --show-errors-tracebacks --hypothesis-suppress-health-check data_too_large --hypothesis-suppress-health-check=filter_too_much --max-response-time 140 -v --header 'Authorization: bearer {"is_admin": true}' || (cat .tmp.pid | xargs kill && exit 1)
poetry run st run http://localhost:8000/api/data/spec.json --validate-schema True --checks all --hypothesis-max-examples 20 --data-generation-method all --show-errors-tracebacks --hypothesis-suppress-health-check data_too_large --hypothesis-suppress-health-check=filter_too_much --max-response-time 180 -v --header 'Authorization: bearer {"is_admin": true}' || (cat .tmp.pid | xargs kill && exit 1)
cat .tmp.pid | xargs kill || echo "The server is already shut down"
@rm -f .tmp.pid
@echo "===========================================TEST DOWNGRADE/UPGRADE==========================================="
Expand Down
15 changes: 15 additions & 0 deletions bases/renku_data_services/data_api/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
UserResourcePoolsBP,
)
from renku_data_services.project.blueprints import ProjectsBP
from renku_data_services.session.blueprints import EnvironmentsBP, SessionLaunchersBP
from renku_data_services.storage.blueprints import StorageBP, StorageSchemaBP
from renku_data_services.user_preferences.blueprints import UserPreferencesBP
from renku_data_services.users.blueprints import KCUsersBP
Expand Down Expand Up @@ -74,6 +75,18 @@ def register_all_handlers(app: Sanic, config: Config) -> Sanic:
authenticator=config.authenticator,
user_repo=config.kc_user_repo,
)
session_environments = EnvironmentsBP(
name="session_environments",
url_prefix=url_prefix,
session_repo=config.session_repo,
authenticator=config.authenticator,
)
session_launchers = SessionLaunchersBP(
name="sessions_launchers",
url_prefix=url_prefix,
session_repo=config.session_repo,
authenticator=config.authenticator,
)
app.blueprint(
[
resource_pools.blueprint(),
Expand All @@ -87,6 +100,8 @@ def register_all_handlers(app: Sanic, config: Config) -> Sanic:
user_preferences.blueprint(),
misc.blueprint(),
project.blueprint(),
session_environments.blueprint(),
session_launchers.blueprint(),
]
)

Expand Down
1 change: 1 addition & 0 deletions bases/renku_data_services/data_api/main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""The entrypoint for the data service application."""

import argparse
import asyncio
from os import environ
Expand Down
17 changes: 16 additions & 1 deletion components/renku_data_services/app_config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
from renku_data_services.message_queue.interface import IMessageQueue
from renku_data_services.message_queue.redis_queue import RedisQueue
from renku_data_services.project.db import ProjectMemberRepository, ProjectRepository
from renku_data_services.session.db import SessionRepository
from renku_data_services.storage.db import StorageRepository
from renku_data_services.user_preferences.config import UserPreferencesConfig
from renku_data_services.user_preferences.db import UserPreferencesRepository
Expand Down Expand Up @@ -117,6 +118,7 @@ class Config:
_project_repo: ProjectRepository | None = field(default=None, repr=False, init=False)
_event_repo: EventRepository | None = field(default=None, repr=False, init=False)
_project_authz: IProjectAuthorizer | None = field(default=None, repr=False, init=False)
_session_repo: SessionRepository | None = field(default=None, repr=False, init=False)
_user_preferences_repo: UserPreferencesRepository | None = field(default=None, repr=False, init=False)
_kc_user_repo: KcUserRepo | None = field(default=None, repr=False, init=False)
_project_member_repo: ProjectMemberRepository | None = field(default=None, repr=False, init=False)
Expand All @@ -142,7 +144,11 @@ def __post_init__(self):
with open(spec_file, "r") as f:
projects = safe_load(f)

self.spec = merge_api_specs(crc_spec, storage_spec, user_preferences_spec, users, projects)
spec_file = Path(renku_data_services.session.__file__).resolve().parent / "api.spec.yaml"
with open(spec_file, "r") as f:
sessions = safe_load(f)

self.spec = merge_api_specs(crc_spec, storage_spec, user_preferences_spec, users, projects, sessions)

if self.default_resource_pool_file is not None:
with open(self.default_resource_pool_file, "r") as f:
Expand Down Expand Up @@ -218,6 +224,15 @@ def project_authz(self) -> IProjectAuthorizer:
)
return self._project_authz

@property
def session_repo(self) -> SessionRepository:
"""The DB adapter for sessions."""
if not self._session_repo:
self._session_repo = SessionRepository(
session_maker=self.db.async_session_maker, project_authz=self.project_authz
)
return self._session_repo

@property
def user_preferences_repo(self) -> UserPreferencesRepository:
"""The DB adapter for user preferences."""
Expand Down
2 changes: 1 addition & 1 deletion components/renku_data_services/migrations/alembic.ini
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ version_path_separator = os # Use os.pathsep. Default configuration used for ne

[common]
script_location = renku_data_services:migrations
version_locations = %(here)s/versions:%(here)s/../authz_migrations/versions:%(here)s/../crc_migrations/versions:%(here)s/../project_migrations/versions:%(here)s/../storage_migrations/versions:%(here)s/../user_preferences_migrations/versions:%(here)s/../users_migrations/versions:%(here)s/../events_migrations/versions
version_locations = %(here)s/versions:%(here)s/../authz_migrations/versions:%(here)s/../crc_migrations/versions:%(here)s/../project_migrations/versions:%(here)s/../session_migrations/versions:%(here)s/../storage_migrations/versions:%(here)s/../user_preferences_migrations/versions:%(here)s/../users_migrations/versions:%(here)s/../events_migrations/versions
version_path_separator = os

[post_write_hooks]
Expand Down
6 changes: 6 additions & 0 deletions components/renku_data_services/migrations/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ class ProjectBaseORM(MappedAsDataclass, DeclarativeBase):
metadata = MetaData(schema="projects")


class SessionBaseORM(MappedAsDataclass, DeclarativeBase):
"""Base class for all session ORM classes."""

metadata = MetaData(schema="sessions")


class UserBaseORM(MappedAsDataclass, DeclarativeBase):
"""Base class for all users ORM classes."""

Expand Down
12 changes: 8 additions & 4 deletions components/renku_data_services/migrations/env.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
"""Database migrations for Alembic."""

from logging.config import fileConfig

from alembic import context

from renku_data_services.authz.orm import BaseORM as authz
from renku_data_services.crc.orm import BaseORM as crc
from renku_data_services.message_queue.orm import BaseORM as events
from renku_data_services.migrations.utils import run_migrations
from renku_data_services.project.orm import BaseORM as project
from renku_data_services.session.orm import BaseORM as sessions
from renku_data_services.storage.orm import BaseORM as storage
from renku_data_services.user_preferences.orm import BaseORM as user_preferences
from renku_data_services.users.orm import BaseORM as users
from renku_data_services.message_queue.orm import BaseORM as events
from renku_data_services.migrations.utils import run_migrations
from alembic import context
from logging.config import fileConfig

# this is the Alembic Config object, which provides
# access to the values within the .ini file in use.
Expand All @@ -24,6 +27,7 @@
authz.metadata,
crc.metadata,
project.metadata,
sessions.metadata,
storage.metadata,
user_preferences.metadata,
users.metadata,
Expand Down
1 change: 1 addition & 0 deletions components/renku_data_services/session/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Blueprints for Sessions."""
Loading
Loading