示例#1
0
    def create_schedule(
        self,
        db_session: Session,
        project: str,
        name: str,
        kind: schemas.ScheduleKinds,
        scheduled_object: Union[Dict, Callable],
        cron_trigger: Union[str, schemas.ScheduleCronTrigger],
        labels: Dict = None,
    ):
        if isinstance(cron_trigger, str):
            cron_trigger = schemas.ScheduleCronTrigger.from_crontab(
                cron_trigger)

        self._validate_cron_trigger(cron_trigger)

        logger.debug(
            "Creating schedule",
            project=project,
            name=name,
            kind=kind,
            scheduled_object=scheduled_object,
            cron_trigger=cron_trigger,
            labels=labels,
        )
        get_project_member().ensure_project(db_session, project)
        get_db().create_schedule(db_session, project, name, kind,
                                 scheduled_object, cron_trigger, labels)
        self._create_schedule_in_scheduler(project, name, kind,
                                           scheduled_object, cron_trigger)
示例#2
0
def delete_project(
        name: str,
        deletion_strategy: schemas.DeletionStrategy = Header(
            schemas.DeletionStrategy.default(),
            alias=schemas.HeaderNames.deletion_strategy),
        db_session: Session = Depends(deps.get_db_session),
):
    get_project_member().delete_project(db_session, name, deletion_strategy)
    return Response(status_code=HTTPStatus.NO_CONTENT.value)
示例#3
0
    def create_schedule(
        self,
        db_session: Session,
        auth_info: mlrun.api.schemas.AuthInfo,
        project: str,
        name: str,
        kind: schemas.ScheduleKinds,
        scheduled_object: Union[Dict, Callable],
        cron_trigger: Union[str, schemas.ScheduleCronTrigger],
        labels: Dict = None,
        concurrency_limit: int = config.httpdb.scheduling.
        default_concurrency_limit,
    ):
        if isinstance(cron_trigger, str):
            cron_trigger = schemas.ScheduleCronTrigger.from_crontab(
                cron_trigger)

        self._validate_cron_trigger(cron_trigger)

        logger.debug(
            "Creating schedule",
            project=project,
            name=name,
            kind=kind,
            scheduled_object=scheduled_object,
            cron_trigger=cron_trigger,
            labels=labels,
            concurrency_limit=concurrency_limit,
        )
        get_project_member().ensure_project(db_session,
                                            project,
                                            leader_session=auth_info.session)
        get_db().create_schedule(
            db_session,
            project,
            name,
            kind,
            scheduled_object,
            cron_trigger,
            concurrency_limit,
            labels,
        )
        self._create_schedule_in_scheduler(
            project,
            name,
            kind,
            scheduled_object,
            cron_trigger,
            concurrency_limit,
            auth_info,
        )
示例#4
0
def patch_project(
    project: dict,
    name: str,
    patch_mode: mlrun.api.schemas.PatchMode = fastapi.Header(
        mlrun.api.schemas.PatchMode.replace,
        alias=mlrun.api.schemas.HeaderNames.patch_mode,
    ),
    # TODO: we're in a http request context here, therefore it doesn't make sense that by default it will hold the
    #  request until the process will be completed - after UI supports waiting - change default to False
    wait_for_completion: bool = fastapi.Query(True,
                                              alias="wait-for-completion"),
    auth_verifier: mlrun.api.api.deps.AuthVerifierDep = fastapi.Depends(
        mlrun.api.api.deps.AuthVerifierDep),
    db_session: sqlalchemy.orm.Session = fastapi.Depends(
        mlrun.api.api.deps.get_db_session),
):
    project, is_running_in_background = get_project_member().patch_project(
        db_session,
        name,
        project,
        patch_mode,
        auth_verifier.auth_info.projects_role,
        auth_verifier.auth_info.session,
        wait_for_completion=wait_for_completion,
    )
    if is_running_in_background:
        return fastapi.Response(status_code=http.HTTPStatus.ACCEPTED.value)
    return project
示例#5
0
def grafana_list_projects(db_session: Session,
                          auth_info: mlrun.api.schemas.AuthInfo) -> List[str]:
    projects_output = get_project_member().list_projects(
        db_session,
        format_=ProjectsFormat.name_only,
        leader_session=auth_info.session)
    return projects_output.projects
示例#6
0
def get_project(
        name: str,
        db_session: Session = fastapi.Depends(deps.get_db_session),
        auth_verifier: deps.AuthVerifier = fastapi.Depends(deps.AuthVerifier),
):
    return get_project_member().get_project(db_session, name,
                                            auth_verifier.auth_info.session)
示例#7
0
文件: projects.py 项目: adiso75/mlrun
def patch_project(
        project: dict,
        name: str,
        patch_mode: schemas.PatchMode = fastapi.Header(
            schemas.PatchMode.replace, alias=schemas.HeaderNames.patch_mode),
        projects_role: typing.Optional[schemas.ProjectsRole] = fastapi.Header(
            None, alias=schemas.HeaderNames.projects_role),
        # TODO: we're in a http request context here, therefore it doesn't make sense that by default it will hold the
        #  request until the process will be completed - after UI supports waiting - change default to False
        wait_for_completion: bool = fastapi.Query(True,
                                                  alias="wait-for-completion"),
        iguazio_session: typing.Optional[str] = fastapi.Cookie(
            None, alias="session"),
        db_session: Session = fastapi.Depends(deps.get_db_session),
):
    project, is_running_in_background = get_project_member().patch_project(
        db_session,
        name,
        project,
        patch_mode,
        projects_role,
        iguazio_session,
        wait_for_completion=wait_for_completion,
    )
    if is_running_in_background:
        return fastapi.Response(status_code=HTTPStatus.ACCEPTED.value)
    return project
示例#8
0
def delete_project(
        name: str,
        deletion_strategy: schemas.DeletionStrategy = fastapi.Header(
            schemas.DeletionStrategy.default(),
            alias=schemas.HeaderNames.deletion_strategy),
        projects_role: typing.Optional[schemas.ProjectsRole] = fastapi.Header(
            None, alias=schemas.HeaderNames.projects_role),
        # TODO: we're in a http request context here, therefore it doesn't make sense that by default it will hold the
        #  request until the process will be completed - after UI supports waiting - change default to False
        wait_for_completion: bool = fastapi.Query(True,
                                                  alias="wait-for-completion"),
        auth_verifier: deps.AuthVerifier = fastapi.Depends(deps.AuthVerifier),
        db_session: Session = fastapi.Depends(deps.get_db_session),
):
    is_running_in_background = get_project_member().delete_project(
        db_session,
        name,
        deletion_strategy,
        projects_role,
        auth_verifier.auth_info.session,
        wait_for_completion=wait_for_completion,
    )
    if is_running_in_background:
        return fastapi.Response(status_code=HTTPStatus.ACCEPTED.value)
    return fastapi.Response(status_code=HTTPStatus.NO_CONTENT.value)
示例#9
0
def delete_project(
    name: str,
    deletion_strategy: mlrun.api.schemas.DeletionStrategy = fastapi.Header(
        mlrun.api.schemas.DeletionStrategy.default(),
        alias=mlrun.api.schemas.HeaderNames.deletion_strategy,
    ),
    # TODO: we're in a http request context here, therefore it doesn't make sense that by default it will hold the
    #  request until the process will be completed - after UI supports waiting - change default to False
    wait_for_completion: bool = fastapi.Query(True,
                                              alias="wait-for-completion"),
    auth_info: mlrun.api.schemas.AuthInfo = fastapi.Depends(
        mlrun.api.api.deps.authenticate_request),
    db_session: sqlalchemy.orm.Session = fastapi.Depends(
        mlrun.api.api.deps.get_db_session),
):
    is_running_in_background = get_project_member().delete_project(
        db_session,
        name,
        deletion_strategy,
        auth_info.projects_role,
        auth_info,
        wait_for_completion=wait_for_completion,
    )
    if is_running_in_background:
        return fastapi.Response(status_code=http.HTTPStatus.ACCEPTED.value)
    return fastapi.Response(status_code=http.HTTPStatus.NO_CONTENT.value)
示例#10
0
def list_projects(
        format_: schemas.Format = Query(schemas.Format.full, alias="format"),
        owner: str = None,
        labels: typing.List[str] = Query(None, alias="label"),
        state: schemas.ProjectState = None,
        db_session: Session = Depends(deps.get_db_session),
):
    return get_project_member().list_projects(db_session, owner, format_,
                                              labels, state)
示例#11
0
def patch_project(
        project: schemas.ProjectPatch,
        name: str,
        patch_mode: schemas.PatchMode = Header(
            schemas.PatchMode.replace, alias=schemas.HeaderNames.patch_mode),
        db_session: Session = Depends(deps.get_db_session),
):
    return get_project_member().patch_project(db_session, name, project,
                                              patch_mode)
示例#12
0
文件: projects.py 项目: omesser/mlrun
def store_project(
        project: schemas.Project,
        name: str,
        projects_role: typing.Optional[schemas.ProjectsRole] = Header(
            None, alias=schemas.HeaderNames.projects_role),
        db_session: Session = Depends(deps.get_db_session),
):
    project, is_running_in_background = get_project_member().store_project(
        db_session, name, project, projects_role, wait_for_completion=False)
    if is_running_in_background:
        return Response(status_code=HTTPStatus.ACCEPTED.value)
    return project
示例#13
0
def list_projects(
    format_: mlrun.api.schemas.ProjectsFormat = fastapi.Query(
        mlrun.api.schemas.ProjectsFormat.full, alias="format"),
    owner: str = None,
    labels: typing.List[str] = fastapi.Query(None, alias="label"),
    state: mlrun.api.schemas.ProjectState = None,
    auth_verifier: mlrun.api.api.deps.AuthVerifierDep = fastapi.Depends(
        mlrun.api.api.deps.AuthVerifierDep),
    db_session: sqlalchemy.orm.Session = fastapi.Depends(
        mlrun.api.api.deps.get_db_session),
):
    projects_output = get_project_member().list_projects(
        db_session,
        owner,
        mlrun.api.schemas.ProjectsFormat.name_only,
        labels,
        state,
        auth_verifier.auth_info.projects_role,
        auth_verifier.auth_info.session,
    )
    allowed_project_names = projects_output.projects
    # skip permission check if it's the leader
    if not _is_request_from_leader(auth_verifier.auth_info.projects_role):
        allowed_project_names = mlrun.api.utils.clients.opa.Client(
        ).filter_projects_by_permissions(
            projects_output.projects,
            auth_verifier.auth_info,
        )
    return get_project_member().list_projects(
        db_session,
        owner,
        format_,
        labels,
        state,
        auth_verifier.auth_info.projects_role,
        auth_verifier.auth_info.session,
        allowed_project_names,
    )
示例#14
0
def get_project(
    name: str,
    db_session: sqlalchemy.orm.Session = fastapi.Depends(
        mlrun.api.api.deps.get_db_session),
    auth_verifier: mlrun.api.api.deps.AuthVerifierDep = fastapi.Depends(
        mlrun.api.api.deps.AuthVerifierDep),
):
    project = get_project_member().get_project(db_session, name,
                                               auth_verifier.auth_info.session)
    # skip permission check if it's the leader
    if not _is_request_from_leader(auth_verifier.auth_info.projects_role):
        mlrun.api.utils.clients.opa.Client().query_project_permissions(
            name,
            mlrun.api.schemas.AuthorizationAction.read,
            auth_verifier.auth_info,
        )
    return project
示例#15
0
def list_projects(
        format_: schemas.Format = fastapi.Query(schemas.Format.full,
                                                alias="format"),
        owner: str = None,
        labels: typing.List[str] = fastapi.Query(None, alias="label"),
        state: schemas.ProjectState = None,
        auth_verifier: deps.AuthVerifier = fastapi.Depends(deps.AuthVerifier),
        db_session: Session = fastapi.Depends(deps.get_db_session),
):
    return get_project_member().list_projects(
        db_session,
        owner,
        format_,
        labels,
        state,
        auth_verifier.auth_info.projects_role,
        auth_verifier.auth_info.session,
    )
示例#16
0
文件: projects.py 项目: omesser/mlrun
def delete_project(
        name: str,
        deletion_strategy: schemas.DeletionStrategy = Header(
            schemas.DeletionStrategy.default(),
            alias=schemas.HeaderNames.deletion_strategy),
        projects_role: typing.Optional[schemas.ProjectsRole] = Header(
            None, alias=schemas.HeaderNames.projects_role),
        db_session: Session = Depends(deps.get_db_session),
):
    is_running_in_background = get_project_member().delete_project(
        db_session,
        name,
        deletion_strategy,
        projects_role,
        wait_for_completion=False)
    if is_running_in_background:
        return Response(status_code=HTTPStatus.ACCEPTED.value)
    return Response(status_code=HTTPStatus.NO_CONTENT.value)
示例#17
0
def store_project(
        project: schemas.Project,
        name: str,
        # TODO: we're in a http request context here, therefore it doesn't make sense that by default it will hold the
        #  request until the process will be completed - after UI supports waiting - change default to False
        wait_for_completion: bool = fastapi.Query(True,
                                                  alias="wait-for-completion"),
        auth_verifier: deps.AuthVerifier = fastapi.Depends(deps.AuthVerifier),
        db_session: Session = fastapi.Depends(deps.get_db_session),
):
    project, is_running_in_background = get_project_member().store_project(
        db_session,
        name,
        project,
        auth_verifier.auth_info.projects_role,
        auth_verifier.auth_info.session,
        wait_for_completion=wait_for_completion,
    )
    if is_running_in_background:
        return fastapi.Response(status_code=HTTPStatus.ACCEPTED.value)
    return project
示例#18
0
def create_project(
    project: mlrun.api.schemas.Project,
    response: fastapi.Response,
    # TODO: we're in a http request context here, therefore it doesn't make sense that by default it will hold the
    #  request until the process will be completed - after UI supports waiting - change default to False
    wait_for_completion: bool = fastapi.Query(True,
                                              alias="wait-for-completion"),
    auth_info: mlrun.api.schemas.AuthInfo = fastapi.Depends(
        mlrun.api.api.deps.authenticate_request),
    db_session: sqlalchemy.orm.Session = fastapi.Depends(
        mlrun.api.api.deps.get_db_session),
):
    project, is_running_in_background = get_project_member().create_project(
        db_session,
        project,
        auth_info.projects_role,
        auth_info.session,
        wait_for_completion=wait_for_completion,
    )
    if is_running_in_background:
        return fastapi.Response(status_code=http.HTTPStatus.ACCEPTED.value)
    response.status_code = http.HTTPStatus.CREATED.value
    return project
示例#19
0
async def list_project_summaries(
    owner: str = None,
    labels: typing.List[str] = fastapi.Query(None, alias="label"),
    state: mlrun.api.schemas.ProjectState = None,
    auth_info: mlrun.api.schemas.AuthInfo = fastapi.Depends(
        mlrun.api.api.deps.authenticate_request),
    db_session: sqlalchemy.orm.Session = fastapi.Depends(
        mlrun.api.api.deps.get_db_session),
):
    projects_output = await fastapi.concurrency.run_in_threadpool(
        get_project_member().list_projects,
        db_session,
        owner,
        mlrun.api.schemas.ProjectsFormat.name_only,
        labels,
        state,
        auth_info.projects_role,
        auth_info.session,
    )
    allowed_project_names = projects_output.projects
    # skip permission check if it's the leader
    if not _is_request_from_leader(auth_info.projects_role):
        allowed_project_names = await fastapi.concurrency.run_in_threadpool(
            mlrun.api.utils.auth.verifier.AuthVerifier().
            filter_projects_by_permissions,
            projects_output.projects,
            auth_info,
        )
    return await get_project_member().list_project_summaries(
        db_session,
        owner,
        labels,
        state,
        auth_info.projects_role,
        auth_info.session,
        allowed_project_names,
    )
示例#20
0
def list_projects(
        format_: schemas.Format = Query(schemas.Format.full, alias="format"),
        owner: str = None,
        db_session: Session = Depends(deps.get_db_session),
):
    return get_project_member().list_projects(db_session, owner, format_)
示例#21
0
def delete_project(
        name: str,
        db_session: Session = Depends(deps.get_db_session),
):
    get_project_member().delete_project(db_session, name)
    return Response(status_code=HTTPStatus.NO_CONTENT.value)
示例#22
0
def get_project(name: str, db_session: Session = Depends(deps.get_db_session)):
    return get_project_member().get_project(db_session, name)
示例#23
0
def store_project(
        project: schemas.Project,
        name: str,
        db_session: Session = Depends(deps.get_db_session),
):
    return get_project_member().store_project(db_session, name, project)
示例#24
0
def create_project(project: schemas.Project,
                   db_session: Session = Depends(deps.get_db_session)):
    return get_project_member().create_project(db_session, project)
示例#25
0
async def shutdown_event():
    if get_project_member():
        get_project_member().shutdown()
    cancel_all_periodic_functions()
    if get_scheduler():
        await get_scheduler().stop()