Ejemplo n.º 1
0
def test_update_run(db: sqldb.SQLDB):
    uid = "uid83"
    run = new_run("s1", {"l1": "v1", "l2": "v2"}, x=1)
    db.store_run(run, uid)
    val = 13
    db.update_run({"x": val}, uid)
    r = db.read_run(uid)
    assert val == r["x"], "bad update"
Ejemplo n.º 2
0
def test_list_runs(db: RunDBInterface):
    if isinstance(db, FileRunDB):
        pytest.skip("FIXME")
    uid = "u183"
    run = new_run("s1", {"l1": "v1", "l2": "v2"}, uid, x=1)
    count = 5
    for iter in range(count):
        db.store_run(run, uid, iter=iter)

    runs = list(db.list_runs(uid=uid))
    assert 1 == len(runs), "iter=False"

    runs = list(db.list_runs(uid=uid, iter=True))
    assert 5 == len(runs), "iter=True"
Ejemplo n.º 3
0
def test_runs(db: RunDBInterface):
    run1 = new_run("s1", {"l1": "v1", "l2": "v2"}, x=1)
    db.store_run(run1, "uid1")
    run2 = new_run("s1", {"l2": "v2", "l3": "v3"}, x=2)
    db.store_run(run2, "uid2")
    run3 = new_run("s2", {"l3": "v3"}, x=2)
    uid3 = "uid3"
    db.store_run(run3, uid3)
    db.store_run(run3, uid3)  # should not raise

    updates = {
        "status": {"start_time": run_now(), "state": "s2"},
    }
    db.update_run(updates, uid3)

    runs = db.list_runs(labels={"l2": "v2"})
    assert 2 == len(runs), "labels length"
    assert {1, 2} == {r["x"] for r in runs}, "xs labels"

    runs = db.list_runs(state=["s1", "s2"])
    assert 3 == len(runs), "state length"

    runs = db.list_runs(state="s2")
    assert 1 == len(runs), "state length"
    run3["status"] = updates["status"]
    assert run3 == runs[0], "state run"

    db.del_run(uid3)
    with pytest.raises(mlrun.errors.MLRunNotFoundError):
        db.read_run(uid3)

    label = "l1"
    db.del_runs(labels=[label])
    for run in db.list_runs():
        assert label not in run["metadata"]["labels"], "del_runs"
Ejemplo n.º 4
0
def _create_resources_of_all_kinds(db: DBInterface,
                                   db_session: sqlalchemy.orm.Session,
                                   project: str):
    # 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)
Ejemplo n.º 5
0
def _create_resources_of_all_kinds(
    db_session: Session,
    k8s_secrets_mock: tests.api.conftest.K8sSecretsMock,
    project: str,
):
    db = mlrun.api.utils.singletons.db.get_db()
    # add labels to project
    project_schema = mlrun.api.schemas.Project(
        metadata=mlrun.api.schemas.ProjectMetadata(
            name=project, labels={"key": "value"}
        ),
        spec=mlrun.api.schemas.ProjectSpec(description="some desc"),
    )
    mlrun.api.utils.singletons.project_member.get_project_member().store_project(
        db_session, project, project_schema
    )

    # Create several functions with several tags
    labels = {
        "name": "value",
        "name2": "value2",
    }
    function = {
        "bla": "blabla",
        "metadata": {"labels": labels},
        "spec": {"asd": "asdasd"},
        "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:
            # change spec a bit so different (un-tagged) versions will be created
            for index in range(3):
                function["spec"]["index"] = index
                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):
                    artifact["iter"] = artifact_iter
                    artifact["tag"] = artifact_tag
                    artifact["uid"] = artifact_uid
                    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:
        mlrun.api.crud.Logs().store_log(log, project, log_uid)

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

    # Create several feature sets with several tags
    labels = {
        "owner": "nobody",
    }
    feature_set = mlrun.api.schemas.FeatureSet(
        metadata=mlrun.api.schemas.ObjectMetadata(
            name="dummy", tag="latest", labels=labels
        ),
        spec=mlrun.api.schemas.FeatureSetSpec(
            entities=[
                mlrun.api.schemas.Entity(
                    name="ent1", value_type="str", labels={"label": "1"}
                )
            ],
            features=[
                mlrun.api.schemas.Feature(
                    name="feat1", value_type="str", labels={"label": "1"}
                )
            ],
        ),
        status={},
    )
    feature_set_names = ["feature_set_1", "feature_set_2", "feature_set_3"]
    feature_set_tags = ["some_tag", "some_tag2", "some_tag3"]
    for feature_set_name in feature_set_names:
        for feature_set_tag in feature_set_tags:
            # change spec a bit so different (un-tagged) versions will be created
            for index in range(3):
                feature_set.metadata.name = feature_set_name
                feature_set.metadata.tag = feature_set_tag
                feature_set.spec.index = index
                db.store_feature_set(db_session, project, feature_set_name, feature_set)

    feature_vector = mlrun.api.schemas.FeatureVector(
        metadata=mlrun.api.schemas.ObjectMetadata(
            name="dummy", tag="latest", labels=labels
        ),
        spec=mlrun.api.schemas.ObjectSpec(),
        status=mlrun.api.schemas.ObjectStatus(state="created"),
    )
    feature_vector_names = ["feature_vector_1", "feature_vector_2", "feature_vector_3"]
    feature_vector_tags = ["some_tag", "some_tag2", "some_tag3"]
    for feature_vector_name in feature_vector_names:
        for feature_vector_tag in feature_vector_tags:
            # change spec a bit so different (un-tagged) versions will be created
            for index in range(3):
                feature_vector.metadata.name = feature_vector_name
                feature_vector.metadata.tag = feature_vector_tag
                feature_vector.spec.index = index
                db.store_feature_vector(
                    db_session, project, feature_vector_name, feature_vector
                )

    secrets = {f"secret_{i}": "a secret" for i in range(5)}
    k8s_secrets_mock.store_project_secrets(project, secrets)
Ejemplo n.º 6
0
def _create_resources_of_all_kinds(db_session: Session, project: str):
    db = mlrun.api.utils.singletons.db.get_db()
    # add labels to project
    project_schema = mlrun.api.schemas.Project(
        metadata=mlrun.api.schemas.ProjectMetadata(name=project,
                                                   labels={"key": "value"}),
        spec=mlrun.api.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 = mlrun.api.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,
            mlrun.api.schemas.ScheduleKinds.job,
            schedule,
            schedule_cron_trigger,
            mlrun.config.config.httpdb.scheduling.default_concurrency_limit,
            labels,
        )

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

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