-
Notifications
You must be signed in to change notification settings - Fork 32
Add example functions section to api-server
#7398
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
bisgaard-itis
merged 20 commits into
ITISFoundation:master
from
bisgaard-itis:7348-add-dummy-functions-api
Mar 28, 2025
Merged
Changes from 7 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
e4ed2fa
add dummy functions section in webserver add rpc interface
bisgaard-itis 4b49f93
introduce functions section in api server and expose ping endpoint
bisgaard-itis 5b1b06b
fix minor issues and manual testing
bisgaard-itis f65dff1
Merge branch 'master' into 7348-add-dummy-functions-api
bisgaard-itis 1a18bf2
add __init__ to functions domain
bisgaard-itis 5004019
added functions section in api
bisgaard-itis a24b9e7
make pylint happy
bisgaard-itis e52bac8
Merge branch 'master' into 7348-add-dummy-functions-api
bisgaard-itis 394587e
@pcrespov remove ping from oas
bisgaard-itis cb107a0
@sanderegg assert input @pcrespov annotate ping function
bisgaard-itis e29dd1b
fix relative imports
bisgaard-itis 5d277a9
regenerate oas
bisgaard-itis f1050a1
add module decorator and app_setting
bisgaard-itis fc5fe09
Merge branch 'master' into 7348-add-dummy-functions-api
bisgaard-itis dcea149
Merge branch 'master' into 7348-add-dummy-functions-api
bisgaard-itis a27ae21
Merge branch 'master' into 7348-add-dummy-functions-api
bisgaard-itis 1aa663e
Merge branch 'master' into 7348-add-dummy-functions-api
bisgaard-itis 869f747
Merge branch 'master' into 7348-add-dummy-functions-api
bisgaard-itis d066273
fix import
bisgaard-itis df7b5d8
update openapi specs
bisgaard-itis 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
Empty file.
21 changes: 21 additions & 0 deletions
21
...s/service-library/src/servicelib/rabbitmq/rpc_interfaces/webserver/functions/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,21 @@ | ||
| import logging | ||
|
|
||
| from models_library.api_schemas_webserver import WEBSERVER_RPC_NAMESPACE | ||
| from models_library.rabbitmq_basic_types import RPCMethodName | ||
| from pydantic import TypeAdapter | ||
| from servicelib.logging_utils import log_decorator | ||
| from servicelib.rabbitmq import RabbitMQRPCClient | ||
|
|
||
| _logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| @log_decorator(_logger, level=logging.DEBUG) | ||
| async def ping( | ||
| rabbitmq_rpc_client: RabbitMQRPCClient, | ||
| ) -> str: | ||
| result = await rabbitmq_rpc_client.request( | ||
| WEBSERVER_RPC_NAMESPACE, | ||
| TypeAdapter(RPCMethodName).validate_python("ping"), | ||
| ) | ||
| assert isinstance(result, str) # nosec | ||
| return result | ||
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
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
16 changes: 16 additions & 0 deletions
16
services/api-server/src/simcore_service_api_server/api/routes/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,16 @@ | ||
| from typing import Annotated | ||
|
|
||
| from fastapi import APIRouter, Depends | ||
| from simcore_service_api_server.api.dependencies.webserver_rpc import ( | ||
| get_wb_api_rpc_client, | ||
| ) | ||
| from simcore_service_api_server.services_rpc.wb_api_server import WbApiRpcClient | ||
|
|
||
bisgaard-itis marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| router = APIRouter() | ||
|
|
||
|
|
||
| @router.post("/ping") | ||
bisgaard-itis marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| async def ping( | ||
| wb_api_rpc: Annotated[WbApiRpcClient, Depends(get_wb_api_rpc_client)], | ||
| ): | ||
| return await wb_api_rpc.ping() | ||
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
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
Empty file.
19 changes: 19 additions & 0 deletions
19
services/web/server/src/simcore_service_webserver/functions/_controller_rpc.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,19 @@ | ||
| from aiohttp import web | ||
| from models_library.api_schemas_webserver import WEBSERVER_RPC_NAMESPACE | ||
| from servicelib.rabbitmq import RPCRouter | ||
| from simcore_service_webserver.rabbitmq import get_rabbitmq_rpc_server | ||
bisgaard-itis marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| # this is the rpc interface exposed to the api-server | ||
| # this interface should call the service layer | ||
|
|
||
| router = RPCRouter() | ||
|
|
||
|
|
||
| @router.expose() | ||
| async def ping(app) -> str: # pylint: disable=unused-argument | ||
bisgaard-itis marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return "pong from webserver" | ||
|
|
||
|
|
||
| async def register_rpc_routes_on_startup(app: web.Application): | ||
| rpc_server = get_rabbitmq_rpc_server(app) | ||
| await rpc_server.register_router(router, WEBSERVER_RPC_NAMESPACE, app) | ||
2 changes: 2 additions & 0 deletions
2
services/web/server/src/simcore_service_webserver/functions/_repo.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,2 @@ | ||
| # the repository layer. Calls directly to the db (function table) should be done here. | ||
| # see e.g. licenses/_licensed_resources_repository.py file for an example |
22 changes: 22 additions & 0 deletions
22
services/web/server/src/simcore_service_webserver/functions/_service.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,22 @@ | ||
| # This is where calls to the business logic is done. | ||
| # calls to the `projects` interface should be done here. | ||
| # calls to _repo.py should also be done here | ||
|
|
||
| from aiohttp import web | ||
| from models_library.users import UserID | ||
| from simcore_service_webserver.projects.models import ProjectDict | ||
bisgaard-itis marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| from ..projects import projects_service | ||
|
|
||
|
|
||
| # example function | ||
| async def get_project_from_function( | ||
| app: web.Application, | ||
| function_uuid: str, | ||
| user_id: UserID, | ||
| ) -> ProjectDict: | ||
|
|
||
| project = await projects_service.get_project_for_user( | ||
| app=app, project_uuid=function_uuid, user_id=user_id | ||
| ) | ||
| return project | ||
7 changes: 7 additions & 0 deletions
7
services/web/server/src/simcore_service_webserver/functions/plugin.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,7 @@ | ||
| from aiohttp import web | ||
|
|
||
| from . import _controller_rpc | ||
|
|
||
|
|
||
| def setup_functions(app: web.Application): | ||
bisgaard-itis marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| app.on_startup.append(_controller_rpc.register_rpc_routes_on_startup) | ||
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.