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

Add example functions section to api-server #7398

Merged
Merged
Show file tree
Hide file tree
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 Mar 19, 2025
4b49f93
introduce functions section in api server and expose ping endpoint
bisgaard-itis Mar 19, 2025
5b1b06b
fix minor issues and manual testing
bisgaard-itis Mar 19, 2025
f65dff1
Merge branch 'master' into 7348-add-dummy-functions-api
bisgaard-itis Mar 19, 2025
1a18bf2
add __init__ to functions domain
bisgaard-itis Mar 19, 2025
5004019
added functions section in api
bisgaard-itis Mar 19, 2025
a24b9e7
make pylint happy
bisgaard-itis Mar 19, 2025
e52bac8
Merge branch 'master' into 7348-add-dummy-functions-api
bisgaard-itis Mar 20, 2025
394587e
@pcrespov remove ping from oas
bisgaard-itis Mar 20, 2025
cb107a0
@sanderegg assert input @pcrespov annotate ping function
bisgaard-itis Mar 20, 2025
e29dd1b
fix relative imports
bisgaard-itis Mar 20, 2025
5d277a9
regenerate oas
bisgaard-itis Mar 20, 2025
f1050a1
add module decorator and app_setting
bisgaard-itis Mar 21, 2025
fc5fe09
Merge branch 'master' into 7348-add-dummy-functions-api
bisgaard-itis Mar 24, 2025
dcea149
Merge branch 'master' into 7348-add-dummy-functions-api
bisgaard-itis Mar 25, 2025
a27ae21
Merge branch 'master' into 7348-add-dummy-functions-api
bisgaard-itis Mar 26, 2025
1aa663e
Merge branch 'master' into 7348-add-dummy-functions-api
bisgaard-itis Mar 27, 2025
869f747
Merge branch 'master' into 7348-add-dummy-functions-api
bisgaard-itis Mar 28, 2025
d066273
fix import
bisgaard-itis Mar 28, 2025
df7b5d8
update openapi specs
bisgaard-itis Mar 28, 2025
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
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
19 changes: 19 additions & 0 deletions services/api-server/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -5848,6 +5848,25 @@
}
}
}
},
"/v0/functions/ping": {
"post": {
"tags": [
"functions"
],
"summary": "Ping",
"operationId": "ping",
"responses": {
"200": {
"description": "Successful Response",
"content": {
"application/json": {
"schema": {}
}
}
}
}
}
}
},
"components": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from .routes import credits as _credits
from .routes import (
files,
functions,
health,
licensed_items,
meta,
Expand Down Expand Up @@ -44,6 +45,7 @@ def create_router(settings: ApplicationSettings):
router.include_router(
licensed_items.router, tags=["licensed-items"], prefix="/licensed-items"
)
router.include_router(functions.router, tags=["functions"], prefix="/functions")

# NOTE: multiple-files upload is currently disabled
# Web form to upload files at http://localhost:8000/v0/upload-form-view
Expand Down
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

router = APIRouter()


@router.post("/ping")
async def ping(
wb_api_rpc: Annotated[WbApiRpcClient, Depends(get_wb_api_rpc_client)],
):
return await wb_api_rpc.ping()
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
from servicelib.rabbitmq.rpc_interfaces.resource_usage_tracker.errors import (
NotEnoughAvailableSeatsError,
)
from servicelib.rabbitmq.rpc_interfaces.webserver.functions.functions import (
ping as _ping,
)
from servicelib.rabbitmq.rpc_interfaces.webserver.licenses.licensed_items import (
checkout_licensed_item_for_wallet as _checkout_licensed_item_for_wallet,
)
Expand Down Expand Up @@ -194,6 +197,9 @@ async def release_licensed_item_for_wallet(
num_of_seats=licensed_item_checkout_get.num_of_seats,
)

async def ping(self) -> str:
return await _ping(self._client)


def setup(app: FastAPI, rabbitmq_rmp_client: RabbitMQRPCClient):
wb_api_rpc_client = WbApiRpcClient(_client=rabbitmq_rmp_client)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
""" Main application

"""
"""Main application"""

import logging
from pprint import pformat
Expand All @@ -23,6 +21,7 @@
from .email.plugin import setup_email
from .exporter.plugin import setup_exporter
from .folders.plugin import setup_folders
from .functions.plugin import setup_functions
from .garbage_collector.plugin import setup_garbage_collector
from .groups.plugin import setup_groups
from .invitations.plugin import setup_invitations
Expand Down Expand Up @@ -133,6 +132,9 @@ def create_application() -> web.Application:
# folders
setup_folders(app)

# functions
setup_functions(app)

# projects
setup_projects(app)

Expand Down
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

# 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
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)
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
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

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
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):
app.on_startup.append(_controller_rpc.register_rpc_routes_on_startup)
Loading