def test_all_model_registry_endpoints_available(): endpoints = { handler: method for (path, handler, method) in get_endpoints() } print(endpoints) # Test that each of the handler is enabled as an endpoint with appropriate method. expected_endpoints = { "POST": [ _create_registered_model, _create_model_version, _rename_registered_model, _transition_stage ], "PATCH": [ _update_registered_model, _update_model_version, ], "DELETE": [ _delete_registered_model, _delete_registered_model, ], "GET": [ _list_registered_models, _search_model_versions, _get_latest_versions, _get_registered_model, _get_model_version, _get_model_version_download_uri, ] } # TODO: efficient mechanism to test endpoint path for method, handlers in expected_endpoints.items(): for handler in handlers: assert handler in endpoints assert endpoints[handler] == [method]
def test_get_endpoints(): endpoints = get_endpoints() create_experiment_endpoint = [ e for e in endpoints if e[1] == _create_experiment ] assert len(create_experiment_endpoint) == 4
from flask import Flask, send_from_directory from mlflow.server import handlers from mlflow.server.handlers import get_artifact_handler from mlflow.utils.process import exec_cmd BACKEND_STORE_URI_ENV_VAR = "MLFLOW_SERVER_FILE_STORE" ARTIFACT_ROOT_ENV_VAR = "MLFLOW_SERVER_ARTIFACT_ROOT" STATIC_PREFIX_ENV_VAR = "MLFLOW_STATIC_PREFIX" REL_STATIC_DIR = "js/build" app = Flask(__name__, static_folder=REL_STATIC_DIR) STATIC_DIR = os.path.join(app.root_path, REL_STATIC_DIR) for http_path, handler, methods in handlers.get_endpoints(): app.add_url_rule(http_path, handler.__name__, handler, methods=methods) def _add_static_prefix(route): prefix = os.environ.get(STATIC_PREFIX_ENV_VAR) if prefix: return prefix + route return route # Serve the "get-artifact" route. @app.route(_add_static_prefix('/get-artifact')) def serve_artifacts(): return get_artifact_handler()