Ejemplo n.º 1
0
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
Ejemplo n.º 2
0
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
Ejemplo n.º 3
0
async def handle_patch_deployment(project_id: str,
                                  deployment_id: str,
                                  deployment: projects.schemas.deployment.DeploymentUpdate,
                                  session: Session = Depends(session_scope)):
    """
    Handles PATCH requests to /<deployment_id>.

    Parameters
    ----------
    project_id : str
    deployment_id : str
    session : sqlalchemy.orm.session.Session

    Returns
    -------
    projects.schemas.deployment.Deployment
    """
    project_controller = ProjectController(session)
    project_controller.raise_if_project_does_not_exist(project_id)

    deployment_controller = DeploymentController(session)
    deployment = deployment_controller.update_deployment(deployment_id=deployment_id,
                                                         project_id=project_id,
                                                         deployment=deployment)
    return deployment
Ejemplo n.º 4
0
async def handle_get_deployment(
        project_id: str,
        deployment_id: str,
        session: Session = Depends(database.session_scope),
        kubeflow_userid: Optional[str] = Header(database.DB_TENANT),
):
    """
    Handles GET requests to /<deployment_id>.

    Parameters
    ----------
    project_id : str
    deployment_id : str
    session : sqlalchemy.orm.session.Session
    kubeflow_userid : fastapi.Header

    Returns
    -------
    projects.schemas.deployment.Deployment
    """
    project_controller = ProjectController(session,
                                           kubeflow_userid=kubeflow_userid)
    project_controller.raise_if_project_does_not_exist(project_id)

    deployment_controller = DeploymentController(
        session, kubeflow_userid=kubeflow_userid)
    deployment = deployment_controller.get_deployment(
        deployment_id=deployment_id)
    return deployment
Ejemplo n.º 5
0
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"},
    )
Ejemplo n.º 6
0
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
Ejemplo n.º 7
0
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
Ejemplo n.º 8
0
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
Ejemplo n.º 9
0
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
Ejemplo n.º 10
0
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
Ejemplo n.º 11
0
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
Ejemplo n.º 12
0
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
Ejemplo n.º 13
0
async def handle_post_deployments(
        project_id: str,
        deployment: projects.schemas.deployment.DeploymentCreate,
        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
    session : sqlalchemy.orm.session.Session
    kubeflow_userid : fastapi.Header

    Returns
    -------
    projects.schemas.deployment.Deployment
    """
    project_controller = ProjectController(session,
                                           kubeflow_userid=kubeflow_userid)
    project_controller.raise_if_project_does_not_exist(project_id)

    deployment_controller = DeploymentController(
        session, background_tasks, kubeflow_userid=kubeflow_userid)
    deployments = deployment_controller.create_deployment(
        project_id=project_id, deployment=deployment)
    return deployments
Ejemplo n.º 14
0
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
Ejemplo n.º 15
0
async def handle_delete_deployment(
        project_id: str,
        deployment_id: str,
        background_tasks: BackgroundTasks,
        session: Session = Depends(database.session_scope),
        kubeflow_userid: Optional[str] = Header(database.DB_TENANT),
):
    """
    Handles DELETE requests to /<deployment_id>.

    Parameters
    ----------
    project_id : str
    deployment_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, background_tasks, kubeflow_userid=kubeflow_userid)
    deployment = deployment_controller.delete_deployment(
        deployment_id=deployment_id, project_id=project_id)
    return deployment
Ejemplo n.º 16
0
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
Ejemplo n.º 17
0
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
Ejemplo n.º 18
0
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
Ejemplo n.º 19
0
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
Ejemplo n.º 20
0
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
Ejemplo n.º 21
0
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
Ejemplo n.º 22
0
async def handle_delete_deployment(project_id: str,
                                   deployment_id: str,
                                   background_tasks: BackgroundTasks,
                                   session: Session = Depends(session_scope)):
    """
    Handles DELETE requests to /<deployment_id>.

    Parameters
    ----------
    project_id : str
    deployment_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, background_tasks)
    deployment = deployment_controller.delete_deployment(deployment_id=deployment_id,
                                                         project_id=project_id)
    return deployment