コード例 #1
0
ファイル: httpdb.py プロジェクト: igz-us-sales/mlrun
    def get_project(self, name: str) -> schemas.Project:
        if not name:
            raise MLRunInvalidArgumentError("Name must be provided")

        path = f"projects/{name}"
        error_message = f"Failed retrieving project {name}"
        response = self.api_call("GET", path, error_message)
        return schemas.Project(**response.json())
コード例 #2
0
ファイル: httpdb.py プロジェクト: igz-us-sales/mlrun
 def store_project(
     self, name: str, project: Union[dict, mlrun.api.schemas.Project]
 ) -> mlrun.api.schemas.Project:
     path = f"projects/{name}"
     error_message = f"Failed storing project {name}"
     if isinstance(project, mlrun.api.schemas.Project):
         project = project.dict()
     response = self.api_call("PUT", path, error_message, body=json.dumps(project),)
     return schemas.Project(**response.json())
コード例 #3
0
ファイル: httpdb.py プロジェクト: igz-us-sales/mlrun
 def create_project(
     self, project: Union[dict, mlrun.api.schemas.Project]
 ) -> mlrun.api.schemas.Project:
     if isinstance(project, mlrun.api.schemas.Project):
         project = project.dict()
     error_message = f"Failed creating project {project['name']}"
     response = self.api_call(
         "POST", "projects", error_message, body=json.dumps(project),
     )
     return schemas.Project(**response.json())
コード例 #4
0
ファイル: httpdb.py プロジェクト: igz-us-sales/mlrun
 def patch_project(
     self,
     name: str,
     project: Union[dict, mlrun.api.schemas.ProjectPatch],
     patch_mode: Union[str, schemas.PatchMode] = schemas.PatchMode.replace,
 ) -> mlrun.api.schemas.Project:
     path = f"projects/{name}"
     if isinstance(patch_mode, schemas.PatchMode):
         patch_mode = patch_mode.value
     headers = {schemas.HeaderNames.patch_mode: patch_mode}
     error_message = f"Failed patching project {name}"
     if isinstance(project, mlrun.api.schemas.Project):
         project = project.dict(exclude_unset=True)
     response = self.api_call(
         "PATCH", path, error_message, body=json.dumps(project), headers=headers
     )
     return schemas.Project(**response.json())
コード例 #5
0
ファイル: test_projects.py プロジェクト: rpatil524/mlrun
def _create_resources_of_all_kinds(db: DBInterface,
                                   db_session: sqlalchemy.orm.Session,
                                   project: str):
    # add labels to project
    project_schema = schemas.Project(
        metadata=schemas.ProjectMetadata(name=project, labels={"key":
                                                               "value"}),
        spec=schemas.ProjectSpec(description="some desc"),
    )
    db.store_project(db_session, project, project_schema)

    # Create several functions with several tags
    labels = {
        "name": "value",
        "name2": "value2",
    }
    function = {
        "bla": "blabla",
        "metadata": {
            "labels": labels
        },
        "status": {
            "bla": "blabla"
        },
    }
    function_names = ["function_name_1", "function_name_2", "function_name_3"]
    function_tags = ["some_tag", "some_tag2", "some_tag3"]
    for function_name in function_names:
        for function_tag in function_tags:
            db.store_function(
                db_session,
                function,
                function_name,
                project,
                tag=function_tag,
                versioned=True,
            )

    # Create several artifacts with several tags
    artifact = {
        "bla": "blabla",
        "labels": labels,
        "status": {
            "bla": "blabla"
        },
    }
    artifact_keys = ["artifact_key_1", "artifact_key_2", "artifact_key_3"]
    artifact_uids = ["some_uid", "some_uid2", "some_uid3"]
    artifact_tags = ["some_tag", "some_tag2", "some_tag3"]
    for artifact_key in artifact_keys:
        for artifact_uid in artifact_uids:
            for artifact_tag in artifact_tags:
                for artifact_iter in range(3):
                    db.store_artifact(
                        db_session,
                        artifact_key,
                        artifact,
                        artifact_uid,
                        artifact_iter,
                        artifact_tag,
                        project,
                    )

    # Create several runs
    run = {
        "bla": "blabla",
        "metadata": {
            "labels": labels
        },
        "status": {
            "bla": "blabla"
        },
    }
    run_uids = ["some_uid", "some_uid2", "some_uid3"]
    for run_uid in run_uids:
        for run_iter in range(3):
            db.store_run(db_session, run, run_uid, project, run_iter)

    # Create several logs
    log = b"some random log"
    log_uids = ["some_uid", "some_uid2", "some_uid3"]
    for log_uid in log_uids:
        db.store_log(db_session, log_uid, project, log)

    # Create several schedule
    schedule = {
        "bla": "blabla",
        "status": {
            "bla": "blabla"
        },
    }
    schedule_cron_trigger = schemas.ScheduleCronTrigger(year=1999)
    schedule_names = ["schedule_name_1", "schedule_name_2", "schedule_name_3"]
    for schedule_name in schedule_names:
        db.create_schedule(
            db_session,
            project,
            schedule_name,
            schemas.ScheduleKinds.job,
            schedule,
            schedule_cron_trigger,
            labels,
        )

    feature_set = schemas.FeatureSet(
        metadata=schemas.ObjectMetadata(name="dummy",
                                        tag="latest",
                                        labels={"owner": "nobody"}),
        spec=schemas.FeatureSetSpec(
            entities=[
                schemas.Entity(name="ent1",
                               value_type="str",
                               labels={"label": "1"})
            ],
            features=[
                schemas.Feature(name="feat1",
                                value_type="str",
                                labels={"label": "1"})
            ],
        ),
        status={},
    )
    db.create_feature_set(db_session, project, feature_set)

    feature_vector = schemas.FeatureVector(
        metadata=schemas.ObjectMetadata(name="dummy",
                                        tag="latest",
                                        labels={"owner": "somebody"}),
        spec=schemas.ObjectSpec(),
        status=schemas.ObjectStatus(state="created"),
    )
    db.create_feature_vector(db_session, project, feature_vector)