-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add support for provisioning of tool models
The already known provisioning feature for read-only sessions will be extended to persistent workspace sessions. Per session, a user can request a persistent workspace session and can pass optionally one model to provision. It's not possible to provision more than one model (aka one Git repository). The provisioning takes place once. We'll not touch the provisioned workspace until the user explicently resets the provisioning. The provisioning revision and date are stored in the database. When the users reset their workspace, we'll remove the provisioning model from the database. During the next session start, the matching workspace will be re-initialized and a copy will be saved to a `.bak` directory. This feature is essential for the start-up of trainings.
- Loading branch information
1 parent
76136c0
commit 2bed1f7
Showing
97 changed files
with
5,525 additions
and
1,156 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
backend/capellacollab/alembic/versions/014438261702_add_provisioning_feature.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# SPDX-FileCopyrightText: Copyright DB InfraGO AG and contributors | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
"""Add provisioning feature | ||
Revision ID: 014438261702 | ||
Revises: 3818a5009130 | ||
Create Date: 2024-10-11 17:34:05.210906 | ||
""" | ||
import sqlalchemy as sa | ||
from alembic import op | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = "014438261702" | ||
down_revision = "3818a5009130" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade(): | ||
op.create_table( | ||
"model_provisioning", | ||
sa.Column("id", sa.Integer(), nullable=False), | ||
sa.Column("user_id", sa.Integer(), nullable=False), | ||
sa.Column("tool_model_id", sa.Integer(), nullable=False), | ||
sa.Column("revision", sa.String(), nullable=False), | ||
sa.Column("commit_hash", sa.String(), nullable=False), | ||
sa.Column("provisioned_at", sa.DateTime(), nullable=False), | ||
sa.ForeignKeyConstraint( | ||
["tool_model_id"], | ||
["models.id"], | ||
), | ||
sa.ForeignKeyConstraint( | ||
["user_id"], | ||
["users.id"], | ||
), | ||
sa.PrimaryKeyConstraint("id"), | ||
) | ||
op.create_index( | ||
op.f("ix_model_provisioning_id"), | ||
"model_provisioning", | ||
["id"], | ||
unique=False, | ||
) | ||
op.add_column( | ||
"sessions", sa.Column("provisioning_id", sa.Integer(), nullable=True) | ||
) | ||
op.create_foreign_key( | ||
None, "sessions", "model_provisioning", ["provisioning_id"], ["id"] | ||
) |
36 changes: 36 additions & 0 deletions
36
backend/capellacollab/alembic/versions/2f8449c217fa_add_project_tools_table.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# SPDX-FileCopyrightText: Copyright DB InfraGO AG and contributors | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
"""Add project tools table | ||
Revision ID: 2f8449c217fa | ||
Revises: 014438261702 | ||
Create Date: 2024-10-29 14:11:47.774679 | ||
""" | ||
import sqlalchemy as sa | ||
from alembic import op | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = "2f8449c217fa" | ||
down_revision = "014438261702" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade(): | ||
op.create_table( | ||
"project_tool_association", | ||
sa.Column("id", sa.Integer(), autoincrement=True, nullable=False), | ||
sa.Column("project_id", sa.Integer(), nullable=False), | ||
sa.Column("tool_version_id", sa.Integer(), nullable=False), | ||
sa.ForeignKeyConstraint( | ||
["project_id"], | ||
["projects.id"], | ||
), | ||
sa.ForeignKeyConstraint( | ||
["tool_version_id"], | ||
["versions.id"], | ||
), | ||
sa.PrimaryKeyConstraint("id", "project_id", "tool_version_id"), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
backend/capellacollab/projects/toolmodels/provisioning/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# SPDX-FileCopyrightText: Copyright DB InfraGO AG and contributors | ||
# SPDX-License-Identifier: Apache-2.0 |
37 changes: 37 additions & 0 deletions
37
backend/capellacollab/projects/toolmodels/provisioning/crud.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# SPDX-FileCopyrightText: Copyright DB InfraGO AG and contributors | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
import sqlalchemy as sa | ||
from sqlalchemy import orm | ||
|
||
from capellacollab.projects.toolmodels import models as toolmodels_models | ||
from capellacollab.users import models as users_models | ||
|
||
from . import models | ||
|
||
|
||
def create_model_provisioning( | ||
db: orm.Session, model: models.DatabaseModelProvisioning | ||
) -> models.DatabaseModelProvisioning: | ||
db.add(model) | ||
db.commit() | ||
return model | ||
|
||
|
||
def get_model_provisioning( | ||
db: orm.Session, | ||
tool_model: toolmodels_models.DatabaseToolModel, | ||
user: users_models.DatabaseUser, | ||
) -> models.DatabaseModelProvisioning | None: | ||
return db.execute( | ||
sa.select(models.DatabaseModelProvisioning) | ||
.where(models.DatabaseModelProvisioning.tool_model == tool_model) | ||
.where(models.DatabaseModelProvisioning.user == user) | ||
).scalar_one_or_none() | ||
|
||
|
||
def delete_model_provisioning( | ||
db: orm.Session, provisioning: models.DatabaseModelProvisioning | ||
): | ||
db.delete(provisioning) | ||
db.commit() |
26 changes: 26 additions & 0 deletions
26
backend/capellacollab/projects/toolmodels/provisioning/injectables.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# SPDX-FileCopyrightText: Copyright DB InfraGO AG and contributors | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
|
||
import fastapi | ||
from sqlalchemy import orm | ||
|
||
from capellacollab.core import database | ||
from capellacollab.users import injectables as users_injectables | ||
from capellacollab.users import models as users_models | ||
|
||
from .. import injectables as toolmodels_injectables | ||
from .. import models as toolmodels_models | ||
from . import crud, models | ||
|
||
|
||
def get_model_provisioning( | ||
model: toolmodels_models.DatabaseToolModel = fastapi.Depends( | ||
toolmodels_injectables.get_existing_capella_model | ||
), | ||
current_user: users_models.DatabaseUser = fastapi.Depends( | ||
users_injectables.get_own_user | ||
), | ||
db: orm.Session = fastapi.Depends(database.get_db), | ||
) -> models.DatabaseModelProvisioning | None: | ||
return crud.get_model_provisioning(db, tool_model=model, user=current_user) |
Oops, something went wrong.