async def handle_post_runs( project_id: str, deployment_id: str, background_tasks: BackgroundTasks, session: Session = Depends(database.session_scope), kubeflow_userid: Optional[str] = Header(database.DB_TENANT), ): """ Handles POST requests to /. Parameters ---------- project_id : str deployment_id : str background_tasks : fastapi.BackgroundTasks session : sqlalchemy.orm.session.Session kubeflow_userid : fastapi.Header Returns ------- str """ project_controller = ProjectController(session, kubeflow_userid=kubeflow_userid) project_controller.raise_if_project_does_not_exist(project_id) deployment_controller = DeploymentController(session) deployment_controller.raise_if_deployment_does_not_exist(deployment_id) run_controller = RunController(session) run = run_controller.create_run(deployment_id=deployment_id) return run
async def handle_list_monitorings( project_id: str, deployment_id: str, session: Session = Depends(database.session_scope), kubeflow_userid: Optional[str] = Header(database.DB_TENANT), ): """ Handles GET requests to /. Parameters ---------- project_id : str deployment_id : str session : sqlalchemy.orm.session.Session kubeflow_userid : fastapi.Header Returns ------- projects.schemas.monitoring.MonitoringList """ project_controller = ProjectController(session, kubeflow_userid=kubeflow_userid) project_controller.raise_if_project_does_not_exist(project_id) deployment_controller = DeploymentController(session) deployment_controller.raise_if_deployment_does_not_exist(deployment_id) monitoring_controller = MonitoringController(session) monitorings = monitoring_controller.list_monitorings(deployment_id=deployment_id) return monitorings
async def handle_post_responses(project_id: str, deployment_id: str, body: dict = Body(...), session: Session = Depends(session_scope)): """ Handles POST requests to /. Parameters ---------- project_id : str deployment_id : str body : fastapi.body session : sqlalchemy.orm.session.Session Returns ------- fastapi.responses.JSONResponse """ project_controller = ProjectController(session) project_controller.raise_if_project_does_not_exist(project_id) deployment_controller = DeploymentController(session) deployment_controller.raise_if_deployment_does_not_exist(deployment_id) response_controller = ResponseController(session) response_controller.create_response(project_id=project_id, deployment_id=deployment_id, body=body) return JSONResponse( status_code=200, content={"message": "OK"}, )
async def handle_list_operators(project_id: str, deployment_id: str, session: Session = Depends(session_scope)): """ Handles GET requests to /. Parameters ---------- project_id : str deployment_id : str session : sqlalchemy.orm.session.Session Returns ------- projects.schemas.operator.OperatorList """ project_controller = ProjectController(session) project_controller.raise_if_project_does_not_exist(project_id) deployment_controller = DeploymentController(session) deployment_controller.raise_if_deployment_does_not_exist(deployment_id) operator_controller = OperatorController(session) operators = operator_controller.list_operators(project_id=project_id, deployment_id=deployment_id) return operators
async def handle_patch_operator(project_id: str, deployment_id: str, operator_id: str, operator: projects.schemas.operator.OperatorUpdate, session: Session = Depends(session_scope)): """ Handles PATCH requests to /<deployment_id>/operators/<operator_id>. Parameters ---------- project_id : str deployment_id : str operator_id : str session : sqlalchemy.orm.session.Session Returns ------- projects.schemas.operator.Operator """ project_controller = ProjectController(session) project_controller.raise_if_project_does_not_exist(project_id) deployment_controller = DeploymentController(session) deployment_controller.raise_if_deployment_does_not_exist(deployment_id) operator_controller = OperatorController(session) operator = operator_controller.update_operator(operator_id=operator_id, project_id=project_id, deployment_id=deployment_id, operator=operator) return operator
async def handle_delete_monitorings(project_id: str, deployment_id: str, monitoring_id: str, session: Session = Depends(session_scope)): """ Handles DELETE requests to /<monitoring_id>. Parameters ---------- project_id : str deployment_id : str monitoring_id : str session : sqlalchemy.orm.session.Session Returns ------- projects.schemas.message.Message """ project_controller = ProjectController(session) project_controller.raise_if_project_does_not_exist(project_id) deployment_controller = DeploymentController(session) deployment_controller.raise_if_deployment_does_not_exist(deployment_id) monitoring_controller = MonitoringController(session) response = monitoring_controller.delete_monitoring( uuid=monitoring_id, project_id=project_id, deployment_id=deployment_id) return response
async def handle_list_logs( project_id: str, deployment_id: str, run_id: str, session: Session = Depends(database.session_scope), kubeflow_userid: Optional[str] = Header(database.DB_TENANT), ): """ Handles GET requests to /. Parameters ---------- project_id : str deployment_id : str run_id : str session : sqlalchemy.orm.session.Session kubeflow_userid : fastapi.Header Returns ------- str """ project_controller = ProjectController(session, kubeflow_userid=kubeflow_userid) project_controller.raise_if_project_does_not_exist(project_id) deployment_controller = DeploymentController(session) deployment_controller.raise_if_deployment_does_not_exist(deployment_id) log_controller = LogController() logs = log_controller.list_logs(project_id=project_id, deployment_id=deployment_id, run_id=run_id) return logs
async def handle_delete_monitorings( project_id: str, deployment_id: str, monitoring_id: str, session: Session = Depends(database.session_scope), kubeflow_userid: Optional[str] = Header(database.DB_TENANT), ): """ Handles DELETE requests to /<monitoring_id>. Parameters ---------- project_id : str deployment_id : str monitoring_id : str session : sqlalchemy.orm.session.Session kubeflow_userid : fastapi.Header Returns ------- projects.schemas.message.Message """ project_controller = ProjectController(session, kubeflow_userid=kubeflow_userid) project_controller.raise_if_project_does_not_exist(project_id) deployment_controller = DeploymentController(session) deployment_controller.raise_if_deployment_does_not_exist(deployment_id) monitoring_controller = MonitoringController(session) response = monitoring_controller.delete_monitoring(uuid=monitoring_id) return response
async def handle_post_monitorings( project_id: str, deployment_id: str, monitoring: projects.schemas.monitoring.MonitoringCreate, session: Session = Depends(session_scope)): """ Handles POST requests to /. Parameters ---------- project_id : str deployment_id : str monitoring : projects.schemas.monitoring.MonitoringCreate session : sqlalchemy.orm.session.Session Returns ------- projects.schemas.monitoring.Monitoring """ project_controller = ProjectController(session) project_controller.raise_if_project_does_not_exist(project_id) deployment_controller = DeploymentController(session) deployment_controller.raise_if_deployment_does_not_exist(deployment_id) monitoring_controller = MonitoringController(session) monitoring = monitoring_controller.create_monitoring( project_id=project_id, deployment_id=deployment_id, monitoring=monitoring) return monitoring
async def handle_delete_runs( project_id: str, deployment_id: str, run_id: str, session: Session = Depends(database.session_scope), kubeflow_userid: Optional[str] = Header(database.DB_TENANT), ): """ Handles DELETE requests to /<run_id>. Parameters ---------- project_id : str deployment_id : str run_id : str session : sqlalchemy.orm.session.Session kubeflow_userid : fastapi.Header Returns ------- str """ project_controller = ProjectController(session, kubeflow_userid=kubeflow_userid) project_controller.raise_if_project_does_not_exist(project_id) deployment_controller = DeploymentController(session) deployment_controller.raise_if_deployment_does_not_exist(deployment_id) run_controller = RunController(session) run = run_controller.terminate_run(deployment_id=deployment_id) return run
async def handle_post_monitorings( project_id: str, deployment_id: str, monitoring: projects.schemas.monitoring.MonitoringCreate, background_tasks: BackgroundTasks, session: Session = Depends(database.session_scope), kubeflow_userid: Optional[str] = Header(database.DB_TENANT), ): """ Handles POST requests to /. Parameters ---------- project_id : str deployment_id : str monitoring : projects.schemas.monitoring.MonitoringCreate background_tasks : fastapi.BackgroundTasks session : sqlalchemy.orm.session.Session kubeflow_userid : fastapi.Header Returns ------- projects.schemas.monitoring.Monitoring """ project_controller = ProjectController(session, kubeflow_userid=kubeflow_userid) project_controller.raise_if_project_does_not_exist(project_id) deployment_controller = DeploymentController(session) deployment_controller.raise_if_deployment_does_not_exist(deployment_id) monitoring_controller = MonitoringController(session, background_tasks) monitoring = monitoring_controller.create_monitoring( deployment_id=deployment_id, monitoring=monitoring ) return monitoring
async def handle_post_prediction(project_id: str, deployment_id: str, file: UploadFile = File(...), session: Session = Depends(session_scope)): """ Handles POST request to /. Parameters ------- project_id : str deployment_id : str session : sqlalchemy.orm.session.Session Returns ------- dict """ project_controller = ProjectController(session) project_controller.raise_if_project_does_not_exist(project_id) deployment_controller = DeploymentController(session) deployment_controller.raise_if_deployment_does_not_exist(deployment_id) prediction_controller = PredictionController(session) prediction = prediction_controller.create_prediction( project_id=project_id, deployment_id=deployment_id, file=file.file) return prediction
async def handle_get_run(session, project_id: str, deployment_id: str, run_id: str): """ Handles GET requests to /<run_id>. Parameters ---------- project_id : str deployment_id : str run_id : str session : sqlalchemy.orm.session.Session Returns ------- str """ project_controller = ProjectController(session) project_controller.raise_if_project_does_not_exist(project_id) deployment_controller = DeploymentController(session) deployment_controller.raise_if_deployment_does_not_exist(deployment_id) run_controller = RunController(session) run = run_controller.get_run(project_id=project_id, deployment_id=deployment_id, run_id=run_id) return run
async def handle_post_runs(project_id: str, deployment_id: str, background_tasks: BackgroundTasks, session: Session = Depends(session_scope)): """ Handles POST requests to /. Parameters ---------- project_id : str deployment_id : str session : sqlalchemy.orm.session.Session Returns ------- str """ project_controller = ProjectController(session) project_controller.raise_if_project_does_not_exist(project_id) deployment_controller = DeploymentController(session) deployment_controller.raise_if_deployment_does_not_exist(deployment_id) run_controller = RunController(session, background_tasks) run = run_controller.create_run(project_id=project_id, deployment_id=deployment_id) return run
async def handle_list_runs(project_id: str, deployment_id: str, session: Session = Depends(session_scope)): """ Handles GET requests to /. Parameters ---------- project_id : str deployment_id : str session : sqlalchemy.orm.session.Session Returns ------- str """ project_controller = ProjectController(session) project_controller.raise_if_project_does_not_exist(project_id) deployment_controller = DeploymentController(session) deployment_controller.raise_if_deployment_does_not_exist(deployment_id) run_controller = RunController(session) runs = run_controller.list_runs(project_id=project_id, deployment_id=deployment_id) return runs
async def handle_post_prediction( project_id: str, deployment_id: str, request: Request, background_tasks: BackgroundTasks, file: Optional[UploadFile] = File(None), session: Session = Depends(session_scope), kubeflow_userid: Optional[str] = Header("anonymous"), ): """ Handles POST request to /. Parameters ------- project_id : str deployment_id : str request : starlette.requests.Request file : starlette.datastructures.UploadFile session : sqlalchemy.orm.session.Session kubeflow_userid : fastapi.Header Returns ------- Prediction: projects.schemas.prediction.Prediction """ project_controller = ProjectController(session, kubeflow_userid=kubeflow_userid) project_controller.raise_if_project_does_not_exist(project_id) deployment_controller = DeploymentController(session) deployment_controller.raise_if_deployment_does_not_exist(deployment_id) # at this endpoint, we can accept both form-data and json as the request content-type kwargs = {} if file is not None: kwargs = {"upload_file": file} else: try: kwargs = await request.json() except JSONDecodeError: raise BadRequest( code="MissingRequiredFormDataOrJson", message="either form-data or json is required", ) prediction_controller = PredictionController(session, background_tasks) prediction = prediction_controller.create_prediction( deployment_id=deployment_id, **kwargs) return prediction
async def handle_patch_operator( project_id: str, deployment_id: str, operator_id: str, operator: projects.schemas.operator.OperatorUpdate, session: Session = Depends(database.session_scope), kubeflow_userid: Optional[str] = Header(database.DB_TENANT), ): """ Handles PATCH requests to /<deployment_id>/operators/<operator_id>. Parameters ---------- project_id : str deployment_id : str operator_id : str session : sqlalchemy.orm.session.Session kubeflow_userid : fastapi.Header Returns ------- projects.schemas.operator.Operator """ project_controller = ProjectController(session, kubeflow_userid=kubeflow_userid) project_controller.raise_if_project_does_not_exist(project_id) deployment_controller = DeploymentController(session) deployment_controller.raise_if_deployment_does_not_exist(deployment_id) operator_controller = OperatorController(session) operator = operator_controller.update_operator( operator_id=operator_id, project_id=project_id, deployment_id=deployment_id, operator=operator, ) return operator