Example #1
0
def start_workspace(id_, start_with_latest_version=False, **kwargs):
    """Start a job
    :param id_: The ID of the workspace resource
    :type id_: str
    :param start_with_latest_version: Start job with the latest revision of the project
    :type start_with_latest_version: bool

    :rtype: StatusSerializer
    """
    w = get_workspace_object(id_)
    check_workspace_permission(w, kwargs["token_info"])
    stub = get_workspaces_services_stub()

    if start_with_latest_version:
        w.spec.revision = get_latest_project_revision(w.metadata.project)
        w = stub.Update(w)

    response = stub.Start(job_pb2.ID(id=w.id))

    if response.status != 200:
        return ErrorSerializer(status=response.status,
                               title="Api Error",
                               detail=response.message), response.status

    return StatusSerializer.from_dict(util.deserialize_protobuf(response))
def retrieve_hardwaretier(id_, **kwargs):  # noqa: E501
    """Retrieve HardwareTier
    :param id_: The ID of the hardware resource
    :type id_: str

    :rtype: HardwareTierSerializer
    """
    stub = get_environments_services_stub()
    res = stub.GetHardwareTier(job_pb2.ID(id=id_))
    return HardwareTierSerializer.from_dict(util.deserialize_protobuf(res))
def status_modelapi(id_, **kwargs):
    """Get state of modelapi.
    :param id_: The ID of the modelapi resource
    :type id_: str

    :rtype: object
    """

    modelapi = get_modelapi_object(id_)
    check_modelapi_permission(modelapi, kwargs["token_info"])
    stub = get_modelapis_services_stub()
    response = stub.State(job_pb2.ID(id=id_))

    return util.deserialize_protobuf(response)
Example #4
0
def status_workspace(id_, **kwargs):
    """Get state of a workspace.
    :param id_: The ID of the workspace resource
    :type id_: str

    :rtype: Object
    """
    w = get_workspace_object(id_)
    check_workspace_permission(w, kwargs["token_info"])

    stub = get_workspaces_services_stub()
    response = stub.State(job_pb2.ID(id=id_))

    return util.deserialize_protobuf(response)
Example #5
0
def state_experiment(id_, **kwargs):
    """Get state of a experiment.

    :param id_: The ID of the experiment resource
    :type id_: str

    :rtype: dict
    """
    exp = get_experiment_object(id_)
    check_experiment_permission(exp, kwargs["token_info"])

    stub = get_experiments_services_stub()
    state = stub.State(job_pb2.ID(id=id_))

    return util.deserialize_protobuf(state)
def delete_hardwaretier(id_, **kwargs):
    """Delete HardwareTier
    :param id_: The ID of the hardware resource
    :type id_: str

    :rtype: StatusSerializer
    """
    stub = get_environments_services_stub()
    response = stub.DeleteHardwareTier(job_pb2.ID(id=id_))

    if response.status != 200:
        return ErrorSerializer(status=response.status,
                               title="Api Error",
                               detail=response.message), response.status

    return StatusSerializer.from_dict(util.deserialize_protobuf(response))
def start_modelapi(id_, **kwargs):
    """Start a job
    :param id_: The ID of the modelapi resource
    :type id_: str

    :rtype: StatusSerializer
    """
    modelapi = get_modelapi_object(id_)
    check_modelapi_permission(modelapi, kwargs["token_info"])
    stub = get_modelapis_services_stub()
    response = stub.Start(job_pb2.ID(id=id_))

    if response.status != 200:
        return ErrorSerializer(status=response.status,
                               title="Api Error",
                               detail=response.message), response.status

    return StatusSerializer.from_dict(util.deserialize_protobuf(response))
Example #8
0
def delete_workspace(id_, **kwargs):
    """Delete a workspace
    :param id_: The ID of the workspace resource
    :type id_: str

    :rtype: StatusSerializer
    """
    w = get_workspace_object(id_)
    check_workspace_permission(w, kwargs["token_info"])

    stub = get_workspaces_services_stub()
    response = stub.Delete(job_pb2.ID(id=id_))

    if response.status != 200:
        return ErrorSerializer(status=response.status,
                               title="Api Error",
                               detail=response.message), response.status

    return StatusSerializer.from_dict(util.deserialize_protobuf(response))
Example #9
0
def get_experiment_artifact(id_, path, **kwargs):  # noqa: E501
    """Download experiment artifact

    Download experiment artifact

    :param id_: The ID of the experiment resource
    :type id_: str
    :param path: File's path to download
    :type path: str

    :rtype: file
    """
    stub = get_experiments_services_stub()
    experiment = stub.Get(job_pb2.ID(id=id_))

    stub = get_projects_services_stub()
    project = stub.Retrieve(project_pb2.ID(id=experiment.metadata.project))
    if not IsProjectMember.has_object_permission(kwargs["token_info"], project):
        return ErrorSerializer(status=403,
                               title="Permission Denied",
                               detail="Doesn't have enough permissions to take this action"), 403

    mlflow_client = get_mlflow_client()

    all_experiments = [exp.experiment_id for exp in mlflow_client.list_experiments()]
    run = mlflow_client.search_runs(experiment_ids=all_experiments,
                                    filter_string="tags.`ilyde.job` = '{}'".format(experiment.id),
                                    run_view_type=ViewType.ALL)[0]

    local_dir = os.path.dirname(os.path.join(current_app.config.get("BASE_DIR"), "media", run.info.run_id, path))
    if not os.path.exists(local_dir):
        os.makedirs(local_dir, exist_ok=True)

    local_path = mlflow_client.download_artifacts(run.info.run_id, path, local_dir)
    file_type, _ = mimetypes.guess_type(local_path)
    if file_type is None:
        file_type = 'application/octet-stream'

    with open(local_path, 'rb') as f:
        response = make_response(f.read())
        response.headers.set('Content-Type', file_type)
        return response, 200
Example #10
0
def stop_experiment(id_, **kwargs):
    """Stop a running experiment.

    :param id_: The ID of the experiment resource
    :type id_: str

    :rtype: StatusSerializer
    """

    exp = get_experiment_object(id_)
    check_experiment_permission(exp, kwargs["token_info"])

    stub = get_experiments_services_stub()
    response = stub.Stop(job_pb2.ID(id=id_))

    if response.status != 200:
        return ErrorSerializer(status=response.status,
                               title="Api Error",
                               detail=response.message), response.status

    return StatusSerializer.from_dict(util.deserialize_protobuf(response))
def get_modelapi_object(modelapi_id):
    stub = get_modelapis_services_stub()
    return stub.Retrieve(job_pb2.ID(id=modelapi_id))
Example #12
0
def get_workspace_object(workspace_id):
    stub = get_workspaces_services_stub()
    return stub.Retrieve(job_pb2.ID(id=workspace_id))
Example #13
0
def get_experiment_object(experiment_id):
    stub = get_experiments_services_stub()
    return stub.Get(job_pb2.ID(id=experiment_id))