diff --git a/docker-compose.yaml b/docker-compose.yaml index 42b73ff96..ed8369286 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -13,7 +13,7 @@ services: build: context: . dockerfile: ./gateway/Dockerfile-gateway - image: ghcr.io/biosimulators/bio-compose-server-gateway:0.0.5-dev + image: ghcr.io/biosimulators/bio-compose-server-gateway:0.0.6-dev container_name: gateway networks: - compnet diff --git a/gateway/main.py b/gateway/main.py index 3cb9f6c91..8292a3598 100644 --- a/gateway/main.py +++ b/gateway/main.py @@ -1,15 +1,13 @@ -import dataclasses import json import os import uuid -from typing import * - import dotenv -from tempfile import mkdtemp +from typing import * +# from tempfile import mkdtemp import uvicorn from fastapi import FastAPI, File, UploadFile, HTTPException, Query, APIRouter, Body -from fastapi.responses import FileResponse +# from fastapi.responses import FileResponse from pydantic import BeforeValidator from starlette.middleware.cors import CORSMiddleware @@ -19,21 +17,28 @@ # ReaddyParticleConfig, # ReaddyRun, # SmoldynRun, - DbClientResponse, # AgentParameters, - BigraphRegistryAddresses, # IncompleteJob, # JobStatus, + BigraphRegistryAddresses, + DbClientResponse, CompositionNode, CompositionSpec, CompositionRun, - OutputData + OutputData, + ValidatedComposition ) from shared.database import MongoConnector -# from shared.io import write_uploaded_file, download_file_from_bucket from shared.log_config import setup_logging from shared.utils import get_project_version -from shared.environment import ENV_PATH, DEFAULT_DB_NAME, DEFAULT_DB_TYPE, DEFAULT_JOB_COLLECTION_NAME, DEFAULT_BUCKET_NAME +from shared.environment import ( + ENV_PATH, + DEFAULT_DB_NAME, + DEFAULT_DB_TYPE, + DEFAULT_JOB_COLLECTION_NAME, + DEFAULT_BUCKET_NAME +) +# from shared.io import write_uploaded_file, download_file_from_bucket logger = setup_logging(__file__) @@ -148,7 +153,7 @@ async def get_process_bigraph_addresses() -> BigraphRegistryAddresses: @app.post( "/validate-composition", - # response_model=CompositionRun, + response_model=ValidatedComposition, tags=["Composition"], operation_id="validate-composition", summary="Validate Simulation Experiment Design specification file.", @@ -156,8 +161,7 @@ async def get_process_bigraph_addresses() -> BigraphRegistryAddresses: async def validate_composition( spec_file: UploadFile = File(..., description="Composition JSON File"), simulators: List[str] = Query(..., description="Simulator package names to use for implementation"), - duration: int = Query(..., description="Duration of simulation"), -): +) -> ValidatedComposition: from process_bigraph import Composite from bsp import app_registrar @@ -173,11 +177,12 @@ async def validate_composition( config={'state': document_data}, core=app_registrar.core ) - return {'state': composite.state} + return ValidatedComposition(state=composite.state, valid=True) except json.JSONDecodeError: raise HTTPException(status_code=400, detail="Invalid JSON format.") except Exception as e: - raise HTTPException(status_code=400, detail=str(e)) + # raise HTTPException(status_code=400, detail=str(e)) + return ValidatedComposition(state={'fail': str(e)}, valid=False) @app.post( diff --git a/gateway/spec/openapi_3_1_0_generated.yaml b/gateway/spec/openapi_3_1_0_generated.yaml index 6e8e7671e..b006e19ff 100644 --- a/gateway/spec/openapi_3_1_0_generated.yaml +++ b/gateway/spec/openapi_3_1_0_generated.yaml @@ -43,14 +43,6 @@ paths: description: Simulator package names to use for implementation title: Simulators description: Simulator package names to use for implementation - - name: duration - in: query - required: true - schema: - type: integer - description: Duration of simulation - title: Duration - description: Duration of simulation requestBody: required: true content: @@ -62,7 +54,8 @@ paths: description: Successful Response content: application/json: - schema: {} + schema: + $ref: '#/components/schemas/ValidatedComposition' '422': description: Validation Error content: @@ -267,6 +260,19 @@ components: - last_updated - results title: OutputData + ValidatedComposition: + properties: + state: + type: object + title: State + valid: + type: boolean + title: Valid + type: object + required: + - state + - valid + title: ValidatedComposition ValidationError: properties: loc: diff --git a/kustomize/overlays/compose/kustomization.yaml b/kustomize/overlays/compose/kustomization.yaml index 516e3bc25..5d1dc6ff3 100644 --- a/kustomize/overlays/compose/kustomization.yaml +++ b/kustomize/overlays/compose/kustomization.yaml @@ -8,7 +8,7 @@ images: - name: mongo newTag: 8.0-rc - name: ghcr.io/biosimulators/bio-compose-server-gateway - newTag: 0.0.5-dev + newTag: 0.0.6-dev - name: ghcr.io/biosimulators/bio-compose-server-worker newTag: 0.0.2-dev diff --git a/shared/data_model.py b/shared/data_model.py index 89d8e89d5..f3cd64340 100644 --- a/shared/data_model.py +++ b/shared/data_model.py @@ -221,3 +221,9 @@ class OutputData(BaseClass): status: str last_updated: str results: Dict + + +@dataclass +class ValidatedComposition(BaseClass): + state: Dict[str, Any] + valid: bool