-
Notifications
You must be signed in to change notification settings - Fork 30
Functions api ✨ 🗃️ #7539
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
Merged
Merged
Functions api ✨ 🗃️ #7539
Changes from 2 commits
Commits
Show all changes
110 commits
Select commit
Hold shift + click to select a range
1b1e8fe
Add functions api. New commit to clean up db migration
wvangeit 080e4fb
Add db migration script for functions api
wvangeit db68658
Add functions api. New commit to clean up db migration
wvangeit 0170982
Add db migration script for functions api
wvangeit acdcfd4
Add solver functions
wvangeit 8fbd814
Add default inputs to functions
wvangeit b5cf30a
Add default inputs to functions
wvangeit 4e1ac9a
Add function collections
wvangeit 9fabebf
Working project function job collection
wvangeit 3c9f819
Add db migration for job collections
wvangeit 77e0a00
Adapt for changes in solver job api
wvangeit b8722cc
Db merge heads functions draft and master rebase
wvangeit efdd470
Add tests for functions api server
wvangeit be9ac7c
Add function rpc tests
wvangeit 6a7ba23
Move function rpc test dir
wvangeit 23b36e9
Remove Nullable fields
wvangeit f956360
Merge alembic heads after rebase
wvangeit 94c44c8
Fix tests after rebase
wvangeit 61c3bbf
Add pagenation to function listing
wvangeit 9f3d968
Fix function routes
wvangeit 8619a2c
Fix function pagination api tests
wvangeit 8042578
Fix pagination of functions again
wvangeit dc39523
Restore some files from master
wvangeit 4022abb
Merge branch 'functions_draft_tests' into functions_draft
wvangeit d246bb4
Fix pylint
wvangeit 616bf69
Changes based on Mads comments wrt functions api
wvangeit 3da5899
Mention explicit exceptions in functions rpc
wvangeit ced82aa
Fix linting
wvangeit 7e74a60
Add assert checks in functions rpc interface
wvangeit c1660c6
Fix gh action tests
wvangeit d4ef130
Add types jsonschema to api-server test requirements
wvangeit 4e10cc7
Fix functions rpc assert and delete functions.py old schema
wvangeit 188b0da
Add functions api. New commit to clean up db migration
wvangeit 2feedee
Add db migration script for functions api
wvangeit f9f4a67
Add solver functions
wvangeit a5b5a76
Add default inputs to functions
wvangeit 1f24485
Add default inputs to functions
wvangeit b38daa2
Add function collections
wvangeit ef3ce7b
Working project function job collection
wvangeit 3f5ea5c
Add db migration for job collections
wvangeit 5031f89
Adapt for changes in solver job api
wvangeit 6957801
Db merge heads functions draft and master rebase
wvangeit baa5bfb
Add tests for functions api server
wvangeit c4aad00
Add function rpc tests
wvangeit b5421f2
Move function rpc test dir
wvangeit b061250
Remove Nullable fields
wvangeit e2d1da0
Merge alembic heads after rebase
wvangeit df546b3
Fix tests after rebase
wvangeit 90dc711
Add pagenation to function listing
wvangeit d8393d4
Fix function routes
wvangeit e71932a
Fix function pagination api tests
wvangeit af697f2
Fix pagination of functions again
wvangeit bede7bd
Restore some files from master
wvangeit f772f04
Fix pylint
wvangeit fae8553
Changes based on Mads comments wrt functions api
wvangeit a8fbdf1
Mention explicit exceptions in functions rpc
wvangeit b683bc5
Fix linting
wvangeit e0d186b
Add assert checks in functions rpc interface
wvangeit 9b2ff02
Fix gh action tests
wvangeit 61dcec3
Add types jsonschema to api-server test requirements
wvangeit 9b1e0a7
Fix functions rpc assert and delete functions.py old schema
wvangeit 53f7029
Merge branch 'functions_draft' of github.com:wvangeit/osparc-simcore …
wvangeit f1041e1
Changes suggested by Sylvain wrt to functions api+new function schema
wvangeit 1c22143
Refactor function db files based on SA's suggestion
wvangeit c548293
Fix db names in function repo
wvangeit 489dd92
Rename function tables primary keys
wvangeit f1e9a63
Remove pk constraints from a functions table
wvangeit df84db9
Add migration script for renaming funcapi tables
wvangeit 0c4980a
Merge branch 'master' into functions_draft
wvangeit 810a1fa
Delete db migrates for funcapi to cleanup
wvangeit 8bfaa2a
Add db migration script for functions_api
wvangeit 98fa066
Run isort on function files
wvangeit d0d9f9b
Introducing Registered functions/function jobs/collections
wvangeit 11555c1
Move function models back in function model file
wvangeit 58b57e2
Move function collections model
wvangeit 0b1e491
Fix function unit tests
wvangeit 555a5a9
First batch of changes requested by GHK for functions API
wvangeit b056d29
Update openapi specs
wvangeit 569d47b
Fix function tests
wvangeit f7bbfe6
Move rpc tests of functions to higher level
wvangeit b91196c
Move the rpc test some levels up
wvangeit 65abd18
Merge branch 'master' into functions_draft
wvangeit a55ad90
Use prefix for function api routes
wvangeit fc4ec0d
Merge branch 'master' into functions_draft
wvangeit 33f2757
Fix small lint failure
wvangeit a6d2097
Merge branch 'functions_draft' of github.com:wvangeit/osparc-simcore …
wvangeit 313aade
Move function rpc tests to webserver 04
wvangeit 48ebf8a
Merge branch 'master' into functions_draft
wvangeit 0207711
Fix import in function controller
wvangeit 983ae3d
Merge branch 'functions_draft' of github.com:wvangeit/osparc-simcore …
wvangeit 5953ba9
Add creation/modification of functions in table
wvangeit 9c7927c
Add creation/modification time to function table
wvangeit 36498e9
Add function endpoints to update title and description
wvangeit 2b54c17
Add new openapi specs for functions
wvangeit 4f3c8ff
Merge branch 'master' into functions_draft
wvangeit 8402ba0
Refactor api test to include deeper layers
wvangeit 6c3d6e9
Move api tests of functions to deeper level
wvangeit bb80d20
Small lint fixes for functions
wvangeit 0ff7180
Merge branch 'master' into functions_draft
wvangeit a472249
Lint fix
wvangeit 1942489
Refactor function tests based on pr comments
wvangeit b61d3c8
Merge branch 'master' into functions_draft
wvangeit 68d8fe5
Split function route files and solve other comments
wvangeit 5916524
Pylint fixes
wvangeit 7e4d917
Temp delete func db migration files
wvangeit 834395f
Add function db migration script
wvangeit ad08a53
Fix comments from functions PR
wvangeit 267c7a5
Rm functions db migration to create a new one
wvangeit e032e1e
Add a new function db migration script
wvangeit 605fd28
Fix latest functions PR comments
wvangeit File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
packages/models-library/src/models_library/api_schemas_api_server/functions.py
This file contains hidden or 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,44 @@ | ||
from typing import Annotated, Any, Literal, TypeAlias | ||
|
||
from models_library import projects | ||
from pydantic import BaseModel, Field | ||
|
||
FunctionID: TypeAlias = projects.ProjectID | ||
|
||
wvangeit marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
class FunctionSchema(BaseModel): | ||
schema_dict: dict[str, Any] | None # JSON Schema | ||
wvangeit marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
||
class FunctionInputSchema(FunctionSchema): ... | ||
|
||
|
||
class FunctionOutputSchema(FunctionSchema): ... | ||
|
||
|
||
class Function(BaseModel): | ||
uid: FunctionID | None = None | ||
title: str | None = None | ||
description: str | None = None | ||
input_schema: FunctionInputSchema | None = None | ||
output_schema: FunctionOutputSchema | None = None | ||
|
||
wvangeit marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# @classmethod | ||
# def compose_resource_name(cls, function_key) -> api_resources.RelativeResourceName: | ||
# return api_resources.compose_resource_name("functions", function_key) | ||
|
||
|
||
class StudyFunction(Function): | ||
function_type: Literal["study"] = "study" | ||
study_url: str | ||
|
||
|
||
class PythonCodeFunction(Function): | ||
function_type: Literal["python_code"] = "python_code" | ||
code_url: str | ||
|
||
|
||
FunctionUnion: TypeAlias = Annotated[ | ||
StudyFunction | PythonCodeFunction, | ||
Field(discriminator="function_type"), | ||
] | ||
wvangeit marked this conversation as resolved.
Show resolved
Hide resolved
|
132 changes: 132 additions & 0 deletions
132
packages/models-library/src/models_library/api_schemas_webserver/functions_wb_schema.py
This file contains hidden or 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,132 @@ | ||
from enum import Enum | ||
from typing import Annotated, Any, Literal, TypeAlias | ||
from uuid import UUID | ||
|
||
from models_library import projects | ||
from pydantic import BaseModel, Field | ||
|
||
from ..projects import ProjectID | ||
|
||
FunctionID: TypeAlias = projects.ProjectID | ||
FunctionJobID: TypeAlias = projects.ProjectID | ||
FileID: TypeAlias = UUID | ||
|
||
InputTypes: TypeAlias = FileID | float | int | bool | str | list | None | ||
|
||
|
||
class FunctionSchema(BaseModel): | ||
schema_dict: dict[str, Any] | None # JSON Schema | ||
|
||
|
||
class FunctionInputSchema(FunctionSchema): ... | ||
|
||
|
||
class FunctionOutputSchema(FunctionSchema): ... | ||
|
||
|
||
class FunctionClass(str, Enum): | ||
project = "project" | ||
python_code = "python_code" | ||
|
||
|
||
FunctionClassSpecificData: TypeAlias = dict[str, Any] | ||
FunctionJobClassSpecificData: TypeAlias = FunctionClassSpecificData | ||
|
||
|
||
# TODO, use InputTypes here, but api is throwing weird errors and asking for dict for elements # noqa: FIX002 | ||
wvangeit marked this conversation as resolved.
Show resolved
Hide resolved
|
||
FunctionInputs: TypeAlias = dict[str, Any] | None | ||
|
||
FunctionInputsList: TypeAlias = list[FunctionInputs] | ||
|
||
FunctionOutputs: TypeAlias = dict[str, Any] | None | ||
|
||
|
||
class FunctionBase(BaseModel): | ||
uid: FunctionID | None = None | ||
title: str | None = None | ||
description: str | None = None | ||
function_class: FunctionClass | ||
input_schema: FunctionInputSchema | None = None | ||
output_schema: FunctionOutputSchema | None = None | ||
|
||
|
||
class FunctionDB(BaseModel): | ||
uuid: FunctionJobID | None = None | ||
title: str | None = None | ||
description: str | None = None | ||
function_class: FunctionClass | ||
input_schema: FunctionInputSchema | None = None | ||
output_schema: FunctionOutputSchema | None = None | ||
class_specific_data: FunctionClassSpecificData | ||
|
||
|
||
class FunctionJobDB(BaseModel): | ||
uuid: FunctionJobID | None = None | ||
function_uuid: FunctionID | ||
title: str | None = None | ||
inputs: FunctionInputs | None = None | ||
outputs: FunctionOutputs | None = None | ||
class_specific_data: FunctionJobClassSpecificData | ||
function_class: FunctionClass | ||
|
||
|
||
class ProjectFunction(FunctionBase): | ||
function_class: Literal[FunctionClass.project] = FunctionClass.project | ||
project_id: ProjectID | ||
|
||
|
||
class PythonCodeFunction(FunctionBase): | ||
function_class: Literal[FunctionClass.python_code] = FunctionClass.python_code | ||
code_url: str | ||
|
||
|
||
Function: TypeAlias = Annotated[ | ||
ProjectFunction | PythonCodeFunction, | ||
Field(discriminator="function_class"), | ||
] | ||
|
||
FunctionJobCollectionID: TypeAlias = projects.ProjectID | ||
|
||
|
||
class FunctionJobBase(BaseModel): | ||
uid: FunctionJobID | None = None | ||
title: str | None = None | ||
description: str | None = None | ||
function_uid: FunctionID | ||
inputs: FunctionInputs | None = None | ||
outputs: FunctionOutputs | None = None | ||
function_class: FunctionClass | ||
wvangeit marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
||
class ProjectFunctionJob(FunctionJobBase): | ||
function_class: Literal[FunctionClass.project] = FunctionClass.project | ||
project_job_id: ProjectID | ||
|
||
|
||
class PythonCodeFunctionJob(FunctionJobBase): | ||
function_class: Literal[FunctionClass.python_code] = FunctionClass.python_code | ||
code_url: str | ||
|
||
|
||
FunctionJob: TypeAlias = Annotated[ | ||
ProjectFunctionJob | PythonCodeFunctionJob, | ||
Field(discriminator="function_class"), | ||
] | ||
|
||
|
||
class FunctionJobStatus(BaseModel): | ||
status: str | ||
|
||
|
||
class FunctionJobCollection(BaseModel): | ||
"""Model for a collection of function jobs""" | ||
|
||
id: FunctionJobCollectionID | ||
title: str | None | ||
description: str | None | ||
job_ids: list[FunctionJobID] | ||
bisgaard-itis marked this conversation as resolved.
Show resolved
Hide resolved
|
||
status: str | ||
wvangeit marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
||
class FunctionJobCollectionStatus(BaseModel): | ||
status: list[str] | ||
wvangeit marked this conversation as resolved.
Show resolved
Hide resolved
|
133 changes: 133 additions & 0 deletions
133
...base/src/simcore_postgres_database/migration/versions/93dbd49553ae_add_function_tables.py
This file contains hidden or 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,133 @@ | ||
"""Add function tables | ||
|
||
Revision ID: 93dbd49553ae | ||
Revises: cf8f743fd0b7 | ||
Create Date: 2025-04-16 09:32:48.976846+00:00 | ||
|
||
""" | ||
|
||
import sqlalchemy as sa | ||
from alembic import op | ||
from sqlalchemy.dialects import postgresql | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = "93dbd49553ae" | ||
down_revision = "cf8f743fd0b7" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.create_table( | ||
"function_job_collections", | ||
sa.Column("uuid", postgresql.UUID(as_uuid=True), nullable=False), | ||
sa.Column("name", sa.String(), nullable=True), | ||
sa.PrimaryKeyConstraint("uuid", name="function_job_collections_pk"), | ||
) | ||
op.create_index( | ||
op.f("ix_function_job_collections_uuid"), | ||
"function_job_collections", | ||
["uuid"], | ||
unique=False, | ||
) | ||
op.create_table( | ||
"functions", | ||
sa.Column("uuid", postgresql.UUID(as_uuid=True), nullable=False), | ||
sa.Column("title", sa.String(), nullable=True), | ||
sa.Column("function_class", sa.String(), nullable=True), | ||
sa.Column("description", sa.String(), nullable=True), | ||
sa.Column("input_schema", sa.JSON(), nullable=True), | ||
sa.Column("output_schema", sa.JSON(), nullable=True), | ||
sa.Column("system_tags", sa.JSON(), nullable=True), | ||
sa.Column("user_tags", sa.JSON(), nullable=True), | ||
sa.Column("class_specific_data", sa.JSON(), nullable=True), | ||
sa.PrimaryKeyConstraint("uuid", name="functions_pk"), | ||
) | ||
op.create_index(op.f("ix_functions_uuid"), "functions", ["uuid"], unique=False) | ||
op.create_table( | ||
"function_jobs", | ||
sa.Column("uuid", postgresql.UUID(as_uuid=True), nullable=False), | ||
sa.Column("title", sa.String(), nullable=True), | ||
sa.Column("function_uuid", postgresql.UUID(as_uuid=True), nullable=False), | ||
sa.Column("function_class", sa.String(), nullable=True), | ||
sa.Column("status", sa.String(), nullable=True), | ||
sa.Column("inputs", sa.JSON(), nullable=True), | ||
sa.Column("outputs", sa.JSON(), nullable=True), | ||
sa.Column("class_specific_data", sa.JSON(), nullable=True), | ||
sa.ForeignKeyConstraint( | ||
["function_uuid"], | ||
["functions.uuid"], | ||
name="fk_functions_to_function_jobs_to_function_uuid", | ||
onupdate="CASCADE", | ||
ondelete="CASCADE", | ||
), | ||
sa.PrimaryKeyConstraint("uuid", name="function_jobs_pk"), | ||
) | ||
op.create_index( | ||
op.f("ix_function_jobs_function_uuid"), | ||
"function_jobs", | ||
["function_uuid"], | ||
unique=False, | ||
) | ||
op.create_index( | ||
op.f("ix_function_jobs_uuid"), "function_jobs", ["uuid"], unique=False | ||
) | ||
op.create_table( | ||
"function_job_collections_to_function_jobs", | ||
sa.Column( | ||
"function_job_collection_uuid", postgresql.UUID(as_uuid=True), nullable=True | ||
), | ||
sa.Column("function_job_uuid", postgresql.UUID(as_uuid=True), nullable=True), | ||
sa.ForeignKeyConstraint( | ||
["function_job_collection_uuid"], | ||
["function_job_collections.uuid"], | ||
name="fk_func_job_coll_to_func_jobs_to_func_job_coll_uuid", | ||
onupdate="CASCADE", | ||
ondelete="CASCADE", | ||
), | ||
sa.ForeignKeyConstraint( | ||
["function_job_uuid"], | ||
["function_jobs.uuid"], | ||
name="fk_func_job_coll_to_func_jobs_to_func_job_uuid", | ||
onupdate="CASCADE", | ||
ondelete="CASCADE", | ||
), | ||
) | ||
op.drop_index("idx_projects_last_change_date_desc", table_name="projects") | ||
op.create_index( | ||
"idx_projects_last_change_date_desc", | ||
"projects", | ||
["last_change_date"], | ||
unique=False, | ||
postgresql_using="btree", | ||
postgresql_ops={"last_change_date": "DESC"}, | ||
) | ||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.drop_index( | ||
"idx_projects_last_change_date_desc", | ||
table_name="projects", | ||
postgresql_using="btree", | ||
postgresql_ops={"last_change_date": "DESC"}, | ||
) | ||
op.create_index( | ||
"idx_projects_last_change_date_desc", | ||
"projects", | ||
[sa.text("last_change_date DESC")], | ||
unique=False, | ||
) | ||
op.drop_table("function_job_collections_to_function_jobs") | ||
op.drop_index(op.f("ix_function_jobs_uuid"), table_name="function_jobs") | ||
op.drop_index(op.f("ix_function_jobs_function_uuid"), table_name="function_jobs") | ||
op.drop_table("function_jobs") | ||
op.drop_index(op.f("ix_functions_uuid"), table_name="functions") | ||
op.drop_table("functions") | ||
op.drop_index( | ||
op.f("ix_function_job_collections_uuid"), table_name="function_job_collections" | ||
) | ||
op.drop_table("function_job_collections") | ||
# ### end Alembic commands ### |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.