Retain imported originals on Worker before retiring Core staging
This commit is contained in:
@@ -3,11 +3,12 @@
|
||||
import json
|
||||
|
||||
from fastapi import APIRouter, Header, HTTPException, Request
|
||||
from fastapi.responses import FileResponse
|
||||
from fastapi.responses import FileResponse, StreamingResponse
|
||||
from pydantic import BaseModel, ConfigDict
|
||||
|
||||
from k1link.simulation.ai_polygon.infrastructure_jobs import provider_identity
|
||||
from k1link.simulation.ai_polygon.urban_maps import validate_map
|
||||
from k1link.simulation.gaussian_pipeline_gateway import configured_gaussian_pipeline_gateway
|
||||
|
||||
|
||||
class AnalysisRequest(BaseModel):
|
||||
@@ -59,6 +60,25 @@ def build_infrastructure_router(jobs, maps, worlds, runs, invoke, authenticate):
|
||||
world = invoke(worlds.get, world_id)
|
||||
if world.get("storage", {}).get("kind") != "project":
|
||||
raise HTTPException(400, "Для анализа нужен исходный Gaussian-проект.")
|
||||
receipt = invoke(worlds.projects.remote_analysis_archive, world)
|
||||
if receipt is not None:
|
||||
provider = configured_gaussian_pipeline_gateway()
|
||||
if provider is None:
|
||||
raise HTTPException(503, "Исходник хранится на Worker. Подключите Worker.")
|
||||
try:
|
||||
provider.retained_source(receipt)
|
||||
except Exception:
|
||||
provider.close()
|
||||
raise
|
||||
def chunks():
|
||||
try:
|
||||
yield from provider.stream_retained_archive(receipt)
|
||||
finally:
|
||||
provider.close()
|
||||
return StreamingResponse(chunks(), media_type="application/octet-stream", headers={
|
||||
"ETag": '"' + receipt["input"]["archive"]["sha256"] + '"',
|
||||
"Content-Length": str(receipt["input"]["archive"]["byte_length"]),
|
||||
})
|
||||
path, descriptor = invoke(worlds.projects.analysis_archive, world)
|
||||
return FileResponse(
|
||||
path,
|
||||
|
||||
@@ -116,6 +116,11 @@ class SimulationProjectDocument(BaseModel):
|
||||
updated_at_utc: str
|
||||
|
||||
|
||||
class SimulationSourceRetention(BaseModel):
|
||||
model_config = ConfigDict(extra="forbid", frozen=True)
|
||||
receipt: dict[str, Any]
|
||||
|
||||
|
||||
class SimulationProjectPage(BaseModel):
|
||||
model_config = ConfigDict(extra="forbid", frozen=True)
|
||||
|
||||
@@ -138,6 +143,10 @@ def build_simulation_projects_router(
|
||||
|
||||
@router.post("/projects", response_model=SimulationProjectDocument, status_code=201)
|
||||
def create_project(request: SimulationProjectCreate) -> dict[str, Any]:
|
||||
try:
|
||||
service.require_import_worker()
|
||||
except GaussianPipelineGatewayError as exc:
|
||||
raise HTTPException(status_code=503, detail=f"Загрузка недоступна: {exc}") from exc
|
||||
try:
|
||||
return store.create(
|
||||
name=request.name,
|
||||
@@ -148,6 +157,17 @@ def build_simulation_projects_router(
|
||||
except SimulationProjectError as exc:
|
||||
raise HTTPException(status_code=400, detail=str(exc)) from exc
|
||||
|
||||
@router.post("/projects/{project_id}/source/retain", response_model=SimulationProjectDocument)
|
||||
def retain_originals(
|
||||
project_id: str, request: SimulationSourceRetention | None = None
|
||||
) -> dict[str, Any]:
|
||||
try:
|
||||
return service.retain_originals(project_id, request.receipt if request else None)
|
||||
except GaussianPipelineGatewayError as exc:
|
||||
raise HTTPException(status_code=503, detail=str(exc)) from exc
|
||||
except SimulationProjectError as exc:
|
||||
raise HTTPException(status_code=409, detail=str(exc)) from exc
|
||||
|
||||
@router.get("/projects/{project_id}", response_model=SimulationProjectDocument)
|
||||
def get_project(project_id: str) -> dict[str, Any]:
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user